00001 <?php
00002
00003
00004
00005
00006
00007
00008 class CLEditor {
00009 const CONFIG_DEFAULT = 'default';
00010
00011 private static $configs = array();
00012
00013
00014
00015
00016 public static function enable(PageData $page_data, $config = self::CONFIG_DEFAULT) {
00017 if (!$config instanceof CLEditorConfig) {
00018 $config = self::get_config($config);
00019 }
00020
00021 if ($config->lang) {
00022 $page_data->head->add_js_file('js/cleditor/lang/jquery.cleditor.' . strtolower($config->lang) . '.js');
00023 }
00024 $page_data->head->add_js_file('js/cleditor/jquery.cleditor.js');
00025 $page_data->head->add_css_file('js/cleditor/jquery.cleditor.css');
00026 foreach($config->plugins as $p) {
00027 $page_data->head->add_js_file($p);
00028 }
00029 $page_data->head->add_js_file($config->init_file);
00030 }
00031
00032
00033
00034
00035
00036
00037
00038
00039 public static function create_config($name, $template = self::CONFIG_DEFAULT) {
00040 $template = self::get_config($template);
00041 self::$configs[$name] = $template;
00042 HtmlText::register_editor($name, $template);
00043 return $template;
00044 }
00045
00046
00047
00048
00049
00050
00051
00052 private static function get_config($name) {
00053 $ret = Arr::get_item(self::$configs, $name, false);
00054 if ($ret === false) {
00055 $ret = new CLEditorConfig();
00056 }
00057 return $ret;
00058 }
00059
00060
00061
00062
00063
00064
00065 public static function get_all_configs() {
00066 return self::$configs;
00067 }
00068 }
00069
00070
00071
00072
00073
00074
00075
00076 class CLEditorConfig implements IRichtTextEditor {
00077
00078
00079
00080
00081
00082 public $init_file = 'js/cleditor/default.js';
00083
00084 public $plugins = array();
00085 public $lang = '';
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 public function apply(PageData $page_data, $name) {
00098 CLEditor::enable($page_data, $this);
00099 }
00100 }