From 047dfa1fcf6d26d2b883ec3d95439a4ccf631133 Mon Sep 17 00:00:00 2001 From: CaMer0n Date: Tue, 10 May 2011 12:47:03 +0000 Subject: [PATCH] TinyMce bbcode plugin work --- e107_core/bbcodes/list.bb | 9 +-- .../shortcodes/batch/bbcode_shortcodes.php | 4 +- e107_handlers/e107_class.php | 17 ++++-- e107_handlers/form_handler.php | 9 ++- e107_handlers/media_class.php | 33 +++++++++++ e107_handlers/ren_help.php | 6 +- .../plugins/e107bbcode/editor_plugin.js | 59 ++++++++++++------- 7 files changed, 103 insertions(+), 34 deletions(-) diff --git a/e107_core/bbcodes/list.bb b/e107_core/bbcodes/list.bb index dde22d074..af3d4512c 100644 --- a/e107_core/bbcodes/list.bb +++ b/e107_core/bbcodes/list.bb @@ -1,7 +1,8 @@ -/* Tag: unordered list [list][*]line 1[*]line2[*]line 3[*]line 4[*]line5 etc[/list] - preferred */ -/* Tag: ordered list [list=][*]line 1[*]line2[*]line 3[*]line 4[*]line5 etc[/list] - preferred */ -/* Tag: unordered list [list]*line 1*line2*line 3*line 4*line5 etc[/list] - legacy*/ -/* Tag: ordered list [list=]*line 1*line2*line 3*line 4*line5 etc[/list] - legacy */ +//]*line 1*line2*line 3*line 4*line5 etc[/list] */ +/* Tag: unordered list [list][*]line 1[*]line2[*]line 3[*]line 4[*]line5 etc[/list] - not compatible with TinyMce */ +/* Tag: ordered list [list=][*]line 1[*]line2[*]line 3[*]line 4[*]line5 etc[/list] - not compatible with TinyMce */ /* valid list types: disc circle diff --git a/e107_core/shortcodes/batch/bbcode_shortcodes.php b/e107_core/shortcodes/batch/bbcode_shortcodes.php index dbcfac4f4..f75781904 100644 --- a/e107_core/shortcodes/batch/bbcode_shortcodes.php +++ b/e107_core/shortcodes/batch/bbcode_shortcodes.php @@ -29,7 +29,7 @@ class bbcode_shortcodes //FIXME - cachevars/getcachedvars! global $pref, $eplug_bb, $bbcode_func, $bbcode_help, $bbcode_filedir, $bbcode_imagedir, $bbcode_helpactive, $bbcode_helptag, $register_bb; - if(defsettrue('e_WYSIWYG')){ return; } + // if(defsettrue('e_WYSIWYG')){ return; } $bbcode_func = ($bbcode_func) ? $bbcode_func : "addtext"; $bbcode_help = ($bbcode_help) ? $bbcode_help : "help"; @@ -133,7 +133,7 @@ class bbcode_shortcodes function sc_bb_help($parm) { - if(defsettrue('e_WYSIWYG')) { return; } + // if(defsettrue('e_WYSIWYG')) { return; } global $bbcode_helpactive,$bbcode_helptag, $bbcode_helpsize; if($parm) $bbcode_helptag = $parm; elseif(!varset($bbcode_helptag)) $bbcode_helptag = 'helpb'; diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 010de8036..6f168444c 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -1361,7 +1361,7 @@ class e107 * @param string $method_name * @return boolean FALSE */ - public function callMethod($class_name, $method_name) + public function callMethod($class_name, $method_name, $param='') { $mes = e107::getMessage(); @@ -1371,7 +1371,7 @@ class e107 if(method_exists($obj, $method_name)) { $mes->debug('Executing '.$class_name.' :: '.$method_name.'()'); - return call_user_func(array($obj, $method_name)); + return call_user_func(array($obj, $method_name),$param); } else { @@ -2255,7 +2255,11 @@ class e107 }*/ $eSelf = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_FILENAME']; - define('e_SELF', $this->HTTP_SCHEME.'://'.$_SERVER['HTTP_HOST'].$eSelf); + if(!deftrue('e_SELF_DISABLE')) + { + define('e_SELF', $this->HTTP_SCHEME.'://'.$_SERVER['HTTP_HOST'].$eSelf); + } + // START New - request uri/url detection, XSS protection $requestUri = $requestUrl = ''; @@ -2384,7 +2388,12 @@ class e107 if ($no_cbrace) $e_QUERY = str_replace(array('{', '}', '%7B', '%7b', '%7D', '%7d'), '', rawurldecode($e_QUERY)); $e_QUERY = str_replace("&","&", self::getParser()->post_toForm($e_QUERY)); - define('e_QUERY', $e_QUERY); + + if(!deftrue("e_QUERY_DISABLE")) + { + define('e_QUERY', $e_QUERY); + } + define('e_TBQS', $_SERVER['QUERY_STRING']); $_SERVER['QUERY_STRING'] = e_QUERY; diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index 8d7bb0607..d7835bf99 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -430,16 +430,20 @@ class e_form $options = array('class' => 'tbox bbarea '.($size ? ' '.$size : '').' e-wysiwyg'); $bbbar = ''; // FIXME - see ren_help.php - if(!deftrue('e_WYSIWYG')) + // if(!deftrue('e_WYSIWYG')) { require_once(e_HANDLER."ren_help.php"); $options['other'] = "onselect='storeCaret(this);' onclick='storeCaret(this);' onkeyup='storeCaret(this);'"; $bbbar = display_help($help_tagid, $help_mod, 'addtext', 'help', $size); } - + + $toggleID = "bbcode-panel-".$help_tagid; + $tinyMceID = str_replace("_","-",$name); + $ret = "
".$this->textarea($name, $value, $rows, 50, $options, $counter)." +
{$bbbar}
@@ -1821,6 +1825,7 @@ class e_form break; case 'lanlist': + case 'language': $options = e107::getLanguage()->getLanSelectArray(); $eloptions = vartrue($parms['__options'], array()); diff --git a/e107_handlers/media_class.php b/e107_handlers/media_class.php index 1e8645307..b292c4f21 100644 --- a/e107_handlers/media_class.php +++ b/e107_handlers/media_class.php @@ -221,6 +221,39 @@ class e_media // TODO } + /** + * Return an Array of Media Categories + */ + public function getCategories() + { + $ret = array(); + e107::getDb()->db_Select_gen("SELECT * FROM #core_media_cat ORDER BY media_cat_title"); + while($row = e107::getDb()->db_Fetch(mySQL_ASSOC)) + { + $id = $row['media_cat_nick']; + $ret[$id] = $row['media_cat_title']; + } + return $ret; + } + + + + /** + * Return an array of Images in a particular category + */ + public function getImages($cat = '') + { + if(!$cat) return; + // TODO check the category is valid. + $ret = array(); + e107::getDb()->db_Select_gen("SELECT * FROM #core_media WHERE media_category = '".$cat."' ORDER BY media_name"); + while($row = e107::getDb()->db_Fetch(mySQL_ASSOC)) + { + $id = $row['media_id']; + $ret[$id] = $row; + } + return $ret; + } /** * Generate Simple Thumbnail window for image-selection diff --git a/e107_handlers/ren_help.php b/e107_handlers/ren_help.php index e36580d7f..0f32858ed 100644 --- a/e107_handlers/ren_help.php +++ b/e107_handlers/ren_help.php @@ -30,7 +30,7 @@ function ren_help($mode = 1, $addtextfunc = "addtext", $helpfunc = "help") // FIXME - full rewrite, EVERYTHING - bbcode class (php + JS), core callbacks, tooltip help, optimize function display_help($tagid="helpb", $mode = 1, $addtextfunc = "addtext", $helpfunc = "help", $helpsize = '') { - if(defsettrue('e_WYSIWYG')) { return; } + // if(defsettrue('e_WYSIWYG')) { return; } global $tp, $pref, $eplug_bb, $bbcode_func, $register_bb, $bbcode_help, $bbcode_helpactive, $bbcode_helptag, $bbcode_helpsize; $bbcode_helpsize = $helpsize; @@ -80,10 +80,12 @@ function display_help($tagid="helpb", $mode = 1, $addtextfunc = "addtext", $help $BBCODE_TEMPLATE = $temp[$mode]; } + $visible = deftrue('e_WYSIWYG') ? "style='display:none'" : ""; + if(is_readable(e_CORE."shortcodes/batch/bbcode_shortcodes.php")) { require_once(e_CORE."shortcodes/batch/bbcode_shortcodes.php"); - return $tp->parseTemplate($BBCODE_TEMPLATE); + return "
".$tp->parseTemplate($BBCODE_TEMPLATE)."
"; } else { diff --git a/e107_plugins/tinymce/plugins/e107bbcode/editor_plugin.js b/e107_plugins/tinymce/plugins/e107bbcode/editor_plugin.js index 38eff9298..e6afed8ff 100644 --- a/e107_plugins/tinymce/plugins/e107bbcode/editor_plugin.js +++ b/e107_plugins/tinymce/plugins/e107bbcode/editor_plugin.js @@ -43,10 +43,21 @@ s = s.replace(re, str); }; - + + rep(/
([\s\S]*)<\/div>/gi,"[center]$1[/center]"); // verified + + + rep(/
  • /gi,"*"); // verified + rep(/<\/li>/gi,""); // verified + rep(/
      ([\s\S]*?)<\/ul>/gim,"[list]$1[/list]\n"); // verified + rep(/
        ([\s\S]*)<\/ol>/gim,"[list=$1]$2[/list]\n"); // verified + rep(/
          ([\s\S]*?)<\/ol>/gim,"[list=decimal]$1[/list]\n"); // verified + rep(/([\s\S]*)<\/span>/gi,"[color=$1]$2[/color]"); // verified + + // example: to [b] - rep(/(.*?)<\/a>/gi,"[url=$1]$2[/url]"); + rep(/(.*?)<\/a>/gi,"[link=$1]$2[/link]"); rep(/(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]"); rep(/(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]"); rep(/(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]"); @@ -55,10 +66,11 @@ rep(/(.*?)<\/font>/gi,"[color=$1]$2[/color]"); rep(/(.*?)<\/span>/gi,"[size=$1]$2[/size]"); rep(/(.*?)<\/font>/gi,"$1"); - // rep(//gi,"[img]$1[/img]"); - // rep(/(.*?)\/>/gi,"[img style=$1]$2[/img]"); + + rep(//gi,"[img style=$1]$2[/img]"); + rep(//gi,"[img]$1[/img]"); + // rep(//gi,"[img style=$1;width:$4px; height:$5;]$2[/img]"); - rep(//gi,"[img style=$1;width:$4px; height:$5;]$2[/img]"); rep(/(.*?)<\/span>/gi,"[code]$1[/code]"); rep(/(.*?)<\/span>/gi,"[quote]$1[/quote]"); rep(/(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]"); @@ -88,12 +100,8 @@ rep(/&/gi,"&"); // e107 - rep(/
            /gi,"[list]"); - rep(/<\/ul>/gi,"[/list]"); - rep(/
              /gi,"[list=decimal]"); - rep(/<\/ol>/gi,"[/list]"); - rep(/
            1. /gi,"[*]"); - rep(/<\/li>/gi,"\n"); + + return s; }, @@ -106,28 +114,39 @@ }; // example: [b] to - rep(/\n/gi,"
              "); + + + rep(/(\[list=.*\])\\*([\s\S]*)(\[\/list])/gim,"
                $2
              "); // verified + rep(/(\[list\])\\*([\s\S]*)(\[\/list])/gim,"
                $2
              ");// verified + rep(/^ *?\*(.*)/gim,"
            2. $1
            3. "); + rep(/\[center\]([\s\S]*)\[\/center\]/gi,"
              $1
              "); // verified + rep(/\[color=(.*?)\]([\s\S]*)\[\/color\]/gi,"$2<\/span>"); // verified + + // rep(/\n/gi,"
              "); // breaks lists.. need a regex to exclude everything between [list]...[/list] + rep(/\[b\]/gi,""); rep(/\[\/b\]/gi,""); rep(/\[i\]/gi,""); rep(/\[\/i\]/gi,""); rep(/\[u\]/gi,""); rep(/\[\/u\]/gi,""); - rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"$2"); + rep(/\[link=([^\]]+)\](.*?)\[\/link\]/gi,"$2"); rep(/\[url\](.*?)\[\/url\]/gi,"$1"); + rep(/\[img.*?style=(.*?).*?\](.*?)\[\/img\]/gi,""); rep(/\[img.*?\](.*?)\[\/img\]/gi,""); - rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"$2"); + // rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"$2"); rep(/\[code\](.*?)\[\/code\]/gi,"$1 "); rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"$1 "); // e107 FIXME! - // rep("/\[list\](.+?)\[\/list\]/is", '
                $1
              '); - rep(/\[list\]/gi,"
                "); - rep(/\[\/list\]/gi,"
              "); - - rep(/\[list=decimal\]/gi,"
                "); - rep(/\[\/list\]/gi,"
              "); + + + // rep("/\[list\](.+?)\[\/list\]/is", '
                $1
              '); + + + +// return s; }