00001 <?php
00002
00003
00004
00005
00006
00007
00008 class WYMEditor {
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 $config = self::get_config($config);
00018
00019 $page_data->head->add_js_file('js/wymeditor/jquery.wymeditor.js');
00020 $page_data->head->add_css_file('js/wymeditor/jquery.wymeditor.css');
00021
00022 $init_plugins = array();
00023 foreach($config->plugins as $js => $init) {
00024 $page_data->head->add_js_file($js);
00025 $init_plugins[] = $init;
00026 }
00027
00028 $page_data->head->add_js_file($config->init_file);
00029
00030 $init_plugins = implode(";\n", $init_plugins);
00031 $init_plugin_func = "function _wym_init_plugins(wym) {\n$init_plugins\n}";
00032 $page_data->head->add_js_snippet($init_plugin_func, true);
00033 }
00034
00035
00036
00037
00038
00039
00040
00041
00042 public static function create_config($name, $template = self::CONFIG_DEFAULT) {
00043 $template = self::get_config($template);
00044 self::$configs[$name] = $template;
00045 HtmlText::register_editor($name, $template);
00046 return $template;
00047 }
00048
00049
00050
00051
00052
00053
00054
00055 private static function get_config($name) {
00056 $ret = Arr::get_item(self::$configs, $name, false);
00057 if ($ret === false) {
00058 $ret = new WYMEditorConfig();
00059 }
00060 return $ret;
00061 }
00062 }
00063
00064
00065
00066
00067
00068
00069
00070 class WYMEditorConfig implements IRichtTextEditor {
00071
00072
00073
00074
00075
00076 public $init_file = 'js/wymeditor/default.js';
00077
00078
00079
00080
00081
00082
00083
00084 public $plugins = array(
00085 'js/wymeditor/plugins/fullscreen/jquery.wymeditor.fullscreen.js' =>
00086 'wym.fullscreen()'
00087 );
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 public function apply(PageData $page_data, $name) {
00101 WYMEditor::enable($page_data, $this);
00102 }
00103 }