1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02:00

Merge pull request #3333 from SimSync/wysiwyg2

A new approach to choose wysiwyg editor
This commit is contained in:
Cameron
2018-08-02 14:07:54 -07:00
committed by GitHub
8 changed files with 102 additions and 25 deletions

View File

@@ -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);
}

View File

@@ -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
<div class='field-spacer'><!-- --></div>\n";
if(e107::wysiwyg() === true && $wysiwyg !== false)
if(e107::wysiwyg() === true) // && $wysiwyg !== false)
{
$eParseList = e107::getConfig()->get('e_parse_list');

View File

@@ -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()
{

View File

@@ -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,

View File

@@ -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));

View File

@@ -1214,10 +1214,12 @@
}
else
{
$editor = $this->forum->prefs->get('editor');
$editor = is_null($editor) ? 'default' : $editor;
$text = "
<form action='" . $url . "' method='post'>
<div class='form-group'>" .
e107::getForm()->bbarea('post','','forum', '_common', 'small', array('id' => 'forum-quickreply-text')) .
e107::getForm()->bbarea('post','','forum', '_common', 'small', array('id' => 'forum-quickreply-text', 'wysiwyg' => $editor)) .
"</div>
<div class='center text-center form-group'>
<input type='submit' data-token='" . e_TOKEN . "' data-forum-insert='" . $ajaxInsert . "' data-forum-post='" . $this->var['thread_forum_id'] . "' data-forum-thread='" . $this->var['thread_id'] . "' data-forum-action='quickreply' name='reply' value='" . LAN_FORUM_2006 . "' class='btn btn-success button' />

View File

@@ -13,7 +13,7 @@ if (!defined('e107_INIT')) { exit; }
$pref = e107::getPref();
if((e107::wysiwyg() === true && check_class($pref['post_html'])) || strpos(e_SELF,"tinymce4/admin_config.php") )
if((e107::wysiwyg(null, true) === 'tinymce4' && check_class($pref['post_html'])) || strpos(e_SELF,"tinymce4/admin_config.php") )
{
if(e_PAGE != 'image.php')
{

View File

@@ -3,6 +3,11 @@
<author name="e107 Inc." url="http://e107.org" />
<description>TinyMce4 CDN version</description>
<category>misc</category>
<keywords>
<word>default</word>
<word>editor</word>
<word>wysiwyg</word>
</keywords>
<adminLinks>
<link url='admin_config.php' description='Configure' icon='images/icon_32.png' iconSmall='images/icon_16.png' primary='true' >Configure</link>
</adminLinks>