<?PHP

/**
* fckEditor class
*/
class Editor{
	/**
	* calling ckeditor texteditor
	* @param Int $width=950
	* @param Int $height=425
	* @param String $name = 'fckeditor'
	* @param String $content
	* @param Array $config=array() - ckeditor config
	* @return ckeditor html
	*/
	function ckeditor($width=950, $height=425, $name = 'fckeditor', $content, $config=array()){

		include_once _RootFolder.'/core/classes/ckeditor/ckeditor.php';

		echo '<script type="text/javascript">';
		echo '//<![CDATA['."\n";
		echo 'if(window.CKEDITOR){';
		echo 'if (CKEDITOR.instances["'.$name.'"]) { CKEDITOR.remove(CKEDITOR.instances["'.$name.'"]);}';
		echo '}';
		echo "\n".'//]]>';
		echo '</script>';

		$CKEditor = new CKEditor();
		$CKEditor->returnOutput = true;
		$CKEditor->basePath = _RootUrl.'/core/classes/ckeditor/';
		$CKEditor->config['width'] = $width;
		$CKEditor->config['height'] = $height;
		$CKEditor->textareaAttributes = array("cols" => 80, "rows" => 10);
		$config['autoParagraph'] = false;

		return $CKEditor->editor($name, $content, $config);
	}

	function ckeditor_source($width=950, $height=425, $name = 'fckeditor', $content, $config=array()){

		preg_match_all('/\{\[TEXT=(.*?)\]\}/s', $content, $matches);
		$config['toolbar'] = array(
			array('Bold','Italic','Underline','Strike','-',
				  'Subscript','Superscript','-',
				  'NumberedList','BulletedList','-',
				  'Outdent','Indent','Blockquote','-',
				  'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-',
				  'Link','Unlink','Anchor','-',
				  'Image','Flash','Table','HorizontalRule','SpecialChar'
				  ),
			'/',
			array('Format','Font','FontSize','-',
				  'TextColor','BGColor','-',
				'Source')
		);

		if(!empty($matches[1])){

			$ret = '';

			foreach($matches[1] as $k => $v){

				$ret .= $this->ckeditor($width, 150, $name.'['.$k.']', $v, $config);
			}
			return $ret;
		}
		else{

			return $this->ckeditor($width, $height, $name, $content, $config);
		}
	}
}


?>
