* @package MCMS\HTML\JScript\Editor */ class CKEditor extends \Mammut\StrictObject { const VERSION = '4.5.9'; const MODE_HTML = 'html'; const MODE_BBCODE = 'bbcode'; protected $mode = self::MODE_HTML; protected $cssFile = NULL; protected $customConfig = NULL; protected $browserFile = NULL; protected $browserImage = NULL; protected $browserFlash = NULL; protected $fontAwesome = true; protected $bootstrapAddons = false; protected $skin = 'office2013'; protected $viewSrcBtn = true; public function __construct() { // workaround till a better solution is found if (defined('CKEDITOR_SKIN')) $this->skin = CKEDITOR_SKIN; } protected function getBaseUrl() { return _COMURL_.'/mcms/jscript/ckeditor/_js_/'.self::VERSION.'/'; } /** * List all installed skins * @return array a list of skin names */ public static function getSkins() { $folder = __DIR__.__DS__.'_js_'.__DS__.self::VERSION.__DS__.'skins'; $search = scandir($folder); $result = array(); foreach ($search as $s) { if ($s[0] != '.' && is_dir($folder.__DS__.$s)) $result[] = $s; } return $result; } public function getMode() { return $this->mode; } public function setMode($mode) { $this->mode = $mode; } public function getSkin() { return $this->skin; } public function setSkin($skin) { $this->skin = $skin; } public function getCustomConfig() { return $this->customConfig; } public function setCustomConfig($customConfig) { $this->customConfig = $customConfig; } public function getCssFile() { return $this->cssFile; } public function setCssFile($cssFile) { $this->cssFile = $cssFile; } public function getFileBrowser() { return $this->browserFile; } public function setFileBrowser($url) { $this->browserFile = $url; } public function getFileBrowserImage() { return $this->browserImage; } public function setFileBrowserImage($url) { $this->browserImage = $url; } public function getFileBrowserFlash() { return $this->browserFlash; } public function setFileBrowserFlash($url) { $this->browserFlash = $url; } public static function generateSelectCallBack($ident) { return ' ' . "\n"; } public function generate($id, $name, $content = '') { $config = array(); $config[] = 'skin: \''.$this->skin.'\''; if (!empty($this->browserFile)) $config[] = 'filebrowserBrowseUrl: \''.$this->browserFile.'\''; if (!empty($this->browserImage)) $config[] = 'filebrowserImageBrowseUrl: \''.$this->browserImage.'\''; if (!empty($this->browserFlash)) $config[] = 'filebrowserFlashBrowseUrl: \''.$this->browserFlash.'\''; if ($this->mode == self::MODE_BBCODE) { $config[] = 'extraPlugins: \'bbcode,wordcount\''; $config[] = "toolbar: [ [ 'Bold', 'Italic', 'Underline', '-', 'RemoveFormat' ], [ 'Cut', 'Copy', 'Paste', 'PasteText', '-', 'Undo', 'Redo' ], [ 'Find', 'Replace', '-', 'SelectAll'], [ 'Link', 'Unlink' ] ".($this->viewSrcBtn ? ",[ 'Source']" : '')." ]"; } else { $config[] = 'extraPlugins: \'div,divarea,tableresize,tabletools,lineutils,wordcount,widget'.($this->fontAwesome ? ',fontawesome' : '').($this->bootstrapAddons ? ',glyphicons,widgetbootstrap,widgettemplatemenu' : '').'\''; $config[] = 'smiley_path: \''._LAYOUTURL_.'/_system_/images/emoicons/\''; $config[] = 'allowedContent: true'; $config[] = "toolbar: [ ".($this->viewSrcBtn ? "['Source', '-']," : '')." [". /*'Save', 'NewPage',*/ "'Preview', 'Print'". /*, '-', 'Templates' */ "], [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo'], [ 'Find','Replace', '-', 'SelectAll'". /*, '-', 'Scayt'*/ "], [ 'Image','Flash','Table','HorizontalRule','Smiley', 'SpecialChar',".($this->fontAwesome ? '\'FontAwesome\',' : '').($this->bootstrapAddons ? '\'Glyphicons\',\'WidgetTemplateMenu\',' : '')."'PageBreak'". /*,'Iframe'*/ "], ". /* [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ], */ "[ 'Maximize', 'ShowBlocks' ], '/', [ 'Styles', 'Format', 'Font', 'FontSize' ], [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ], [ 'TextColor', 'BGColor' ], [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock' /*, '-', 'BidiLtr', 'BidiRtl', 'Language'*/ ], [ 'Link', 'Unlink', 'Anchor' ]"./*, '/', /*[ '-' ], [ 'About' ]*/" ]"; } if (isset($this->customConfig)) $config[] = 'customConfig: \''.$this->customConfig.'\''; if (isset($this->cssFile)) $config[] = 'contentsCss: \''.$this->cssFile.'\''; $html = '\n"; $html .= "\n"; return [ 'html' => $html, 'js_import' => [ JQUERY_JS_LIB, $this->getBaseUrl().'ckeditor.js', $this->getBaseUrl().'adapters/jquery.js' ] ]; } }