diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 1cf557151..b9803f7e4 100755 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -3627,27 +3627,52 @@ class e107 /** * Set or Retrieve WYSIWYG active status. (replaces constant e_WYSIWYG) - * @param bool $val if null, return current value, otherwise set value to registry + * + * @param bool/string $val if null, return current value, otherwise define editor to use + * @param bool $returnEditor true = return name of active editor, false = return "false" for non wysiwyg editor, return "true" if wysiwyg editor should be used * @return bool|mixed */ - public static function wysiwyg($val=null) + public static function wysiwyg($val=null, $returnEditor=false) { - // Check the general wysiwyg setting + static $editor = 'bbcode'; + static $availEditors; + $fallbackEditor = 'bbcode'; + if (self::getPref('wysiwyg',false) != true) { - return false; - } - - if(is_null($val)) - { - return self::getRegistry('core/e107/wysiwyg'); + // wysiwyg disabled by global pref + $editor = $fallbackEditor; } else { - self::setRegistry('core/e107/wysiwyg',$val); - return true; - } - + if(!isset($availEditors)) + { + // init list of installed wysiwyg editors + $availEditors = array_keys(e107::getPlug()->getInstalledWysiwygEditors()); + } + + if(!is_null($val)) + { + // set editor if value given + $editor = empty($val) ? $fallbackEditor : ($val === 'default' ? true : $val); + } + + + // check if choosen editor is installed, + // if not, but a different editor is available use that one (e.g. tinymce4 choosen, but only simplemde available available, use simplemde) + // if no wysiwyg editor available, use fallback editor (bbcode) + if(is_bool($editor) || ($editor !== $fallbackEditor && !in_array($editor, $availEditors))) + { + $editor = count($availEditors) > 0 ? $availEditors[0] : $fallbackEditor; + } + } + // $returnEditor => false: + // false => fallback editor (bbcode) + // true => default wysiwyg editor + // $returnEditor => true: + // return name of the editor + //return $returnEditor ? $editor : ($editor === $fallbackEditor || $editor === false ? false : true); + return $returnEditor ? $editor : ($editor !== $fallbackEditor); } diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index fe63a04bc..026f1de97 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -2352,7 +2352,7 @@ class e_form } // auto-height support - +/* $bbbar = ''; $wysiwyg = null; $wysiwygClass = ' e-wysiwyg'; @@ -2368,7 +2368,8 @@ class e_form } $options['class'] = 'tbox bbarea '.($size ? ' '.$size : '').$wysiwygClass.' e-autoheight form-control'; - +*/ + $options['class'] = 'tbox bbarea '.($size ? ' '.$size : '').' e-wysiwyg e-autoheight form-control'; if (isset($options['id']) && !empty($options['id'])) { @@ -2379,8 +2380,13 @@ class e_form $help_tagid = $this->name2id($name)."--preview"; } + if (!isset($options['wysiwyg'])) + { + $options['wysiwyg'] = true; + } - if(e107::wysiwyg(true) === false || $wysiwyg === false) // bbarea loaded, so activate wysiwyg (if enabled in preferences) + //if(e107::wysiwyg(true) === false || $wysiwyg === false) // bbarea loaded, so activate wysiwyg (if enabled in preferences) + if(e107::wysiwyg($options['wysiwyg'],true) === 'bbcode') // bbarea loaded, so activate wysiwyg (if enabled in preferences) { $options['other'] = "onselect='storeCaret(this);' onclick='storeCaret(this);' onkeyup='storeCaret(this);' {$height}"; } @@ -2396,7 +2402,7 @@ class e_form
\n"; - if(e107::wysiwyg() === true && $wysiwyg !== false) + if(e107::wysiwyg() === true) // && $wysiwyg !== false) { $eParseList = e107::getConfig()->get('e_parse_list'); diff --git a/e107_handlers/plugin_class.php b/e107_handlers/plugin_class.php index c941a9ad4..788564663 100644 --- a/e107_handlers/plugin_class.php +++ b/e107_handlers/plugin_class.php @@ -127,6 +127,34 @@ class e_plugin return $this; } + public function getInstalledWysiwygEditors() + { + $result = array(); + + foreach(array_keys($this->_installed) as $k) + { + $pl = new e_plugin(); + $pl->load($k); + $keys = $pl->getKeywords(); + // check the keywords + if (is_array($keys) && in_array('wysiwyg', $keys['word'])) + { + if (in_array('default', $keys['word'])) + { + // add "default" editor to the beginning of the array + $result = array_merge(array($k => $pl->getName()), $result); + } + else + { + // add all "wysiwyg" editors to the array + $result[$k] = $pl->getName(); + } + } + + } + return $result; + } + public function getInstalled() { return $this->_installed; @@ -229,6 +257,17 @@ class e_plugin } + public function getKeywords() + { + if(!isset($this->_data[$this->_plugdir]['keywords'])) + { + return false; + } + + return $this->_data[$this->_plugdir]['keywords']; + + } + public function getDescription() { diff --git a/e107_plugins/forum/forum_admin.php b/e107_plugins/forum/forum_admin.php index 909471304..2aca1c275 100644 --- a/e107_plugins/forum/forum_admin.php +++ b/e107_plugins/forum/forum_admin.php @@ -232,12 +232,11 @@ if(!deftrue('OLD_FORUMADMIN')) $this->prefs['editor']['writeParms']['optArray']['default'] = FORLAN_217; $this->prefs['editor']['writeParms']['optArray']['bbcode'] = 'BBCode'; - //@ global pref should override plugins due to security considerations and allowance of posting html. - /* - if (e107::isInstalled('tinymce4')) + $editors = e107::getPlug()->getInstalledWysiwygEditors(); + if (!empty($editors)) { - $this->prefs['editor']['writeParms']['optArray']['tinymce4'] = 'TinyMCE'; - }*/ + $this->prefs['editor']['writeParms']['optArray'] = array_merge($this->prefs['editor']['writeParms']['optArray'], $editors); + } $this->prefs['quickreply']['writeParms']['optArray'] = array( 'default' => FORLAN_218, diff --git a/e107_plugins/forum/shortcodes/batch/post_shortcodes.php b/e107_plugins/forum/shortcodes/batch/post_shortcodes.php index 98b342f25..288d10868 100644 --- a/e107_plugins/forum/shortcodes/batch/post_shortcodes.php +++ b/e107_plugins/forum/shortcodes/batch/post_shortcodes.php @@ -179,7 +179,8 @@ class plugin_forum_post_shortcodes extends e_shortcode $editor = $this->forum->prefs->get('editor'); - $wysiwyg = ($editor === 'bbcode') ? false : null; + //$wysiwyg = ($editor === 'bbcode') ? false : null; + $wysiwyg = is_null($editor) ? 'default' : $editor; return e107::getForm()->bbarea('post',$text,'forum','_common','large', array('wysiwyg' => $wysiwyg)); diff --git a/e107_plugins/forum/shortcodes/batch/view_shortcodes.php b/e107_plugins/forum/shortcodes/batch/view_shortcodes.php index 3ead6166a..d14ba025b 100644 --- a/e107_plugins/forum/shortcodes/batch/view_shortcodes.php +++ b/e107_plugins/forum/shortcodes/batch/view_shortcodes.php @@ -1214,10 +1214,12 @@ } else { + $editor = $this->forum->prefs->get('editor'); + $editor = is_null($editor) ? 'default' : $editor; $text = "