<?php
/**
 * <pre>
 * Invision Power Services
 * Global CCS functions
 * Last Updated: $Date: 2009-10-06 21:07:37 -0400 (Tue, 06 Oct 2009) $
 * </pre>
 *
 * @author 		$Author: bfarber $
 * @copyright	(c) 2001 - 2009 Invision Power Services, Inc.
 * @license		http://www.invisionpower.com/community/board/license.html
 * @package		IP.Content
 * @link		http://www.invisionpower.com
 * @since		1st March 2009
 * @version		$Revision: 110 $
 */
 
class cp_skin_ccsglobal extends output
{

/**
 * Prevent our main destructor being called by this class
 *
 * @access	public
 * @return	void
 */
public function __destruct()
{
}

/**
 * Get javascript lang strings
 *
 * @access	public
 * @return	void
 */
public function getJsLangs()
{
$IPBHTML = "";
//--starthtml--//

$IPBHTML .= <<<HTML
<script type='text/javascript'>
ipb.lang['js__nofilterperm']		= "{$this->lang->words['js__nofilterperm']}";
ipb.lang['js__nosearchperm']		= "{$this->lang->words['js__nosearchperm']}";
ipb.lang['js__folderempty']			= "{$this->lang->words['js__folderempty']}";
ipb.lang['js__deletefolder']		= "{$this->lang->words['js__deletefolder']}";
ipb.lang['js__foldername']			= "{$this->lang->words['js__foldername']}";
ipb.lang['js__folderexists']		= "{$this->lang->words['js__folderexists']}";
</script>
HTML;
//--endhtml--//
return $IPBHTML;
}

/**
 * Return inline CSS for the images.  Done this way to preserve
 * image paths when minify is enabled.
 *
 * @access	public
 * @return	void
 */
public function getCss()
{
$IPBHTML = "";
//--starthtml--//

$IPBHTML .= <<<HTML

.filter_box {
	background: #efefef url( {$this->settings['skin_acp_url']}/_newimages/ccs/filterbar_bg.png ) repeat-x bottom;
}

#main_content table.sortable tr th.sort.sorting {
	background: #528f6c url( {$this->settings['skin_acp_url']}/_newimages/gradient_bg.png ) repeat-x 50%;
}

#main_content table.sortable.desc tr th.sort:hover .sort_order,
#main_content table.sortable tr th.sort:hover .sort_order {
	background: url( {$this->settings['skin_acp_url']}/_newimages/ccs/sort_desc_off.png ) no-repeat right;
}

	#main_content table.sortable.asc tr th.sort:hover .sort_order {
		background: url( {$this->settings['skin_acp_url']}/_newimages/ccs/sort_asc_off.png ) no-repeat right;
	}

	#main_content table.sortable.desc tr th.sort.sorting .sort_order,
	#main_content table.sortable tr th.sort.sorting .sort_order {
		background: url( {$this->settings['skin_acp_url']}/_newimages/ccs/sort_desc_on.png ) no-repeat right;
	}
	
	#main_content table.sortable.asc tr th.sort.sorting .sort_order {
		background: url( {$this->settings['skin_acp_url']}/_newimages/ccs/sort_asc_on.png ) no-repeat right;
	}

.article_expander h4 {
	background: url( {$this->settings['skin_acp_url']}/_newimages/ccs/folder_closed.png ) no-repeat 2px 2px;
}

	.article_expander.open h4 {
		background: url( {$this->settings['skin_acp_url']}/_newimages/ccs/folder_open.png ) no-repeat 2px 2px;
	}

.date_button {
	background: url( {$this->settings['skin_acp_url']}/_newimages/icons/date.png ) no-repeat;
}

#page_manager .folder {
	background: #eff3f6 url( {$this->settings['skin_acp_url']}/_newimages/ccs/folder_closed.png ) no-repeat 10px 12px;
}

	#page_manager .folder.open {
		background: #dae2e9 url( {$this->settings['skin_acp_url']}/_newimages/ccs/folder_open.png ) no-repeat 10px 12px;
	}

	#page_search_box {
		background: #fff url( {$this->settings['skin_acp_url']}/_newimages/search_icon.png ) no-repeat 2px 3px;
	}

.icon.ccs-file {
	background-image: url( {$this->settings['skin_acp_url']}/_newimages/ccs/page.png );
}

.icon.ccs-css {
	background-image: url( {$this->settings['skin_acp_url']}/_newimages/ccs/css.png );
}

.icon.ccs-js {
	background-image: url( {$this->settings['skin_acp_url']}/_newimages/ccs/js.png );
}

HTML;
//--endhtml--//
return $IPBHTML;
}

/**
 * Return WYSIWYG HTML
 *
 * @access	public
 * @param	string		Field name
 * @param	string		Language type
 * @return	void
 */
public function getWysiwyg( $fieldname, $language='html' )
{
	switch( $this->settings['ccs_template_type'] )
	{
		case 'tinymce':
			return $this->wysiwyg__tinymce( $fieldname, $language );
		break;
		
		case 'ckeditor':
			return $this->wysiwyg__ckeditor( $fieldname, $language );
		break;
		
		case 'codepress':
			return $this->wysiwyg__codepress( $fieldname, $language );
		break;
		
		case 'editarea':
			return $this->wysiwyg__editarea( $fieldname, $language );
		break;
	}
	
	return '';
}

/**
 * TinyMCE template editing
 *
 * @access	public
 * @param	string		Fieldname
 * @param	string		Language type
 * @return	HTML
 */
public function wysiwyg__tinymce( $fieldname, $language='html' )
{
$IPBHTML = "";
//--starthtml--//

$IPBHTML .= <<<HTML
<script type="text/javascript" src="{$this->settings['skin_app_url']}/editors/tinymce/tiny_mce.js"></script>
<script type="text/javascript">
	var tinyMCEConfigs = {
		mode : "exact",
		elements: "{$fieldname}",
		theme : "advanced",
		width: '100%',
		oninit : "postInitWork",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount",
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "save,newdocument,help,cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,code",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,advhr,|,ltr,rtl,|,cleanup,fullscreen",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true
	};
	
	tinyMCE.init( tinyMCEConfigs );
	
	function postInitWork()
	{
		if( $('page_content_tbl') )
		{
			//$('page_content_tbl').setStyle('width: 100%');
		}
	}
	
	function resizeEditor()
	{
		tinyMCEConfigs.width = '70%';
		tinyMCE.settings = tinyMCEConfigs;
		tinyMCE.execCommand( 'mceRemoveControl', true, "{$fieldname}" );
		tinyMCE.execCommand( 'mceAddControl', true, "{$fieldname}" );
	}
	
	function restoreResizeEditor()
	{
		tinyMCEConfigs.width = '100%';
		tinyMCE.settings = tinyMCEConfigs;
		tinyMCE.execCommand( 'mceRemoveControl', true, "{$fieldname}" );
		tinyMCE.execCommand( 'mceAddControl', true, "{$fieldname}" );
	}
</script>
HTML;
//--endhtml--//
return $IPBHTML;
}

/**
 * CKEditor template editing
 *
 * @access	public
 * @param	string		Fieldname
 * @param	string		Language type
 * @return	HTML
 */
public function wysiwyg__ckeditor( $fieldname, $language='html' )
{
$IPBHTML = "";
//--starthtml--//

$IPBHTML .= <<<HTML
<script type="text/javascript" src="{$this->settings['skin_app_url']}/editors/ckeditor/ckeditor.js"></script>
<script type="text/javascript">
	document.observe("dom:loaded", function(){
		CKEDITOR.replace( '{$fieldname}' );
	});
</script>
HTML;
//--endhtml--//
return $IPBHTML;
}

/**
 * CodePress template editing
 *
 * @access	public
 * @param	string		Fieldname
 * @param	string		Language type
 * @return	HTML
 */
public function wysiwyg__codepress( $fieldname, $language='html' )
{
$IPBHTML = "";
//--starthtml--//

$IPBHTML .= <<<HTML
<script type="text/javascript" src="{$this->settings['skin_app_url']}/editors/codepress/codepress.js"></script>
<script type="text/javascript">
	document.observe("dom:loaded", function(){
		$$('textarea').each( function(textarea)
		{
			if( textarea.name == '{$fieldname}' )
			{
				textarea.addClassName("{$language}");
				textarea.addClassName("codepress");
				textarea.addClassName("codepress");
			}
		});
		
		$$('form').each( function(form) {
			form.observe( 'submit', function(e) {
				$$('textarea').each( function(textarea)
				{
					if( textarea.hasClassName('codepress') )
					{
						var textareaid	= $(textarea).id.replace( /_cp$/, '' );
						eval( textareaid + ".toggleEditor();" );
					}
				});
			});
		});
	});
</script>
HTML;
//--endhtml--//
return $IPBHTML;
}

/**
 * EditArea template editing
 *
 * @access	public
 * @param	string		Fieldname
 * @param	string		Language type
 * @return	HTML
 */
public function wysiwyg__editarea( $fieldname, $language='html' )
{
$IPBHTML = "";
//--starthtml--//

$IPBHTML .= <<<HTML
<script type="text/javascript" src="{$this->settings['skin_app_url']}/editors/editarea/edit_area_full.js"></script>
<script type="text/javascript">
	editAreaLoader.init({
		id: "{$fieldname}"	// id of the textarea to transform		
		,start_highlight: true	// if start with highlight
		,allow_resize: "both"
		,allow_toggle: true
		,word_wrap: false
		,language: "en"
		,syntax: "{$language}"	
	});
</script>
HTML;
//--endhtml--//
return $IPBHTML;
}

}