From f5b7907e0094c52c9bf26f9a7b3dc13744c7387c Mon Sep 17 00:00:00 2001 From: CaMer0n Date: Mon, 12 Oct 2009 06:38:01 +0000 Subject: [PATCH] TinyMce - work in progress --- e107_plugins/tinymce/admin_config.php | 539 ++++++++++++++++- e107_plugins/tinymce/e_meta.php | 15 +- e107_plugins/tinymce/plugin.xml | 3 +- .../tinymce/plugins/bbcode/editor_plugin.js | 1 - .../editor_plugin.js} | 30 +- e107_plugins/tinymce/tinymce_sql.php | 21 + e107_plugins/tinymce/wysiwyg.php | 561 ++++++++++-------- 7 files changed, 904 insertions(+), 266 deletions(-) delete mode 100644 e107_plugins/tinymce/plugins/bbcode/editor_plugin.js rename e107_plugins/tinymce/plugins/{bbcode/editor_plugin_src.js => e107bbcode/editor_plugin.js} (84%) create mode 100644 e107_plugins/tinymce/tinymce_sql.php diff --git a/e107_plugins/tinymce/admin_config.php b/e107_plugins/tinymce/admin_config.php index c011f03de..bad5dcff0 100644 --- a/e107_plugins/tinymce/admin_config.php +++ b/e107_plugins/tinymce/admin_config.php @@ -9,8 +9,8 @@ * Plugin Administration - gsitemap * * $Source: /cvs_backup/e107_0.8/e107_plugins/tinymce/admin_config.php,v $ - * $Revision: 1.7 $ - * $Date: 2009-09-22 18:28:49 $ + * $Revision: 1.8 $ + * $Date: 2009-10-12 06:38:01 $ * $Author: e107coders $ * */ @@ -21,13 +21,525 @@ if(!getperms("P") || !plugInstalled('tinymce')) exit(); } + + + + +require_once(e_HANDLER."form_handler.php"); +require_once (e_HANDLER.'message_handler.php'); + +$frm = new e_form(true); + +$ef = new tinymce; //TODO save prefs to separate config row. // List all forms of access, and allow the user to choose between simple/advanced or 'custom' settings. +if(varset($_POST['update']) || varset($_POST['create'])) +{ + $id = intval($_POST['record_id']); + $ef->submitPage($id); +} + +if(varset($_POST['delete'])) +{ + $id = key($_POST['delete']); + $ef->deleteRecord($id); + $_GET['mode'] = "list"; +} + +if(isset($_POST['edit']) || $id) // define after db changes and before header loads. +{ + $id = (isset($_POST['edit'])) ? key($_POST['edit']) : $id; + define("TINYMCE_CONFIG",$id); +} +else +{ + define("TINYMCE_CONFIG",FALSE); +} + + +require_once(e_ADMIN."auth.php"); + +if(varset($_GET['mode'])=='create') +{ + $id = varset($_POST['edit']) ? key($_POST['edit']) : ""; + if($_POST['record_id']) + { + $id = $_POST['record_id']; + } + $ef->createRecord($id); +} +else +{ + $ef->listRecords(); +} + +if(isset($_POST['submit-e-columns'])) +{ + $user_pref['admin_release_columns'] = $_POST['e-columns']; + save_prefs('user'); +} + + +require_once(e_ADMIN."footer.php"); + + + +class tinymce +{ + var $fields; + var $fieldpref; + var $listQry; + var $table; + var $primary; + + + function __construct() + { + + $this->fields = array( + 'tinymce_id' => array('title'=> ID, 'width'=>'5%', 'forced'=> TRUE, 'primary'=>TRUE), + 'tinymce_name' => array('title'=> 'name', 'width'=>'auto','type'=>'text'), + 'tinymce_userclass' => array('title'=> 'class', 'type' => 'array', 'method'=>'tinymce_class', 'width' => 'auto'), + 'tinymce_plugins' => array('title'=> 'plugins', 'type' => 'array', 'method'=>'tinymce_plugins', 'width' => 'auto'), + 'tinymce_buttons1' => array('title'=> 'buttons1', 'type' => 'text', 'method'=>'tinymce_buttons', 'methodparms'=>1, 'width' => 'auto'), + 'tinymce_buttons2' => array('title'=> 'buttons2', 'type' => 'text', 'method'=>'tinymce_buttons', 'methodparms'=>2, 'width' => 'auto'), + 'tinymce_buttons3' => array('title'=> 'buttons3', 'type' => 'text', 'method'=>'tinymce_buttons', 'methodparms'=>3, 'width' => 'auto', 'thclass' => 'left first'), + 'tinymce_buttons4' => array('title'=> 'buttons4', 'type' => 'text', 'method'=>'tinymce_buttons', 'methodparms'=>4, 'width' => 'auto', 'thclass' => 'left first'), + 'tinymce_custom' => array('title'=> 'custom', 'type' => 'text', 'width' => 'auto'), + 'tinymce_prefs' => array('title'=> 'prefs', 'type' => 'text', 'width' => '10%', 'thclass' => 'center' ), + 'options' => array('title'=> LAN_OPTIONS, 'forced'=>TRUE, 'width' => '10%', 'thclass' => 'center last') + ); + + $this->fieldpref = (varset($user_pref['admin_tinymce_columns'])) ? $user_pref['admin_tinymce_columns'] : array_keys($this->fields); + $this->table = "tinymce"; + $this->listQry = "SELECT * FROM #tinymce ORDER BY tinymce_id"; + $this->editQry = "SELECT * FROM #tinymce WHERE tinymce_id = {ID}"; + $this->primary = "tinymce_id"; + $this->pluginTitle = "Tinymce"; + + $this->listCaption = "Tinymce Configs"; + $this->createCaption = LAN_CREATE."/".LAN_EDIT; + + } + + +// -------------------------------------------------------------------------- + /** + * Generic DB Record Listing Function. + * @param object $mode [optional] + * @return + */ + function listRecords($mode=FALSE) + { + $ns = e107::getRender(); + $sql = e107::getDb(); + $frm = e107::getForm(); + + + global $pref; + + $emessage = eMessage::getInstance(); + + $text = "
+
+ ".$this->pluginTitle." + ". + $frm->colGroup($this->fields,$this->fieldpref). + $frm->thead($this->fields,$this->fieldpref). + + ""; + + + if(!$sql->db_Select_gen($this->listQry)) + { + $text .= "\n\n"; + } + else + { + $row = $sql->db_getList('ALL', FALSE, FALSE); + + foreach($row as $field) + { + $text .= "\n"; + foreach($this->fields as $key=>$att) + { + $class = vartrue($this->fields[$key]['thclass']) ? "class='".$this->fields[$key]['thclass']."'" : ""; + $text .= (in_array($key,$this->fieldpref) || $att['forced']==TRUE) ? "\t\n" : ""; + } + $text .= "\n"; + } + } + + $text .= " + +
".CUSLAN_42."
".$this->renderValue($key,$field)."
+
+
+ "; + + $ns->tablerender($this->pluginTitle." :: ".$this->listCaption, $emessage->render().$text); + } + + /** + * Render Field value (listing page) + * @param object $key + * @param object $row + * @return + */ + function renderValue($key,$row) + { + $att = $this->fields[$key]; + + if($key == "options") + { + $id = $this->primary; + $text = ""; + $text .= ""; + return $text; + } + + switch($att['type']) + { + case 'url': + return "".$row[$key].""; + break; + + default: + return $row[$key]; + break; + } + return $row[$key] .$att['type']; + } + + /** + * Render Form Element (edit page) + * @param object $key + * @param object $row + * @return + */ + function renderElement($key,$row) + { + global $frm; + $att = $this->fields[$key]; + $value = $row[$key]; + + if($att['method']) + { + $meth = $att['method']; + if(isset($att['methodparms'])) + { + return $this->$meth($value,$att['methodparms']); + } + return $this->$meth($value); + } + + + return $frm->text($key, $row[$key], 50); + + } + + + + function createRecord($id=FALSE) + { + global $frm, $e_userclass, $e_event; + + $tp = e107::getParser(); + $ns = e107::getRender(); + $sql = e107::getDb(); + $mes = eMessage::getInstance(); + + if($id) + { + $query = str_replace("{ID}",$id,$this->editQry); + $sql->db_Select_gen($query); + $row = $sql->db_Fetch(MYSQL_ASSOC); + } + else + { + $row = array(); + } + + $text = " +
+
+ ".$this->pluginTitle." + + + + + + + + + + "; + + + + foreach($this->fields as $key=>$att) + { + if($att['forced']!==TRUE) + { + $text .= " + + + + "; + } + + } + + $text .= " + +
Preview + ".$this->tinymce_preview()."
".$att['title']."".$this->renderElement($key,$row)."
+
"; + + if($id) + { + $text .= $frm->admin_button('update', LAN_UPDATE, 'update'); + $text .= ""; + } + else + { + $text .= $frm->admin_button('create', LAN_CREATE, 'create'); + } + + $text .= " +
+
+
"; + + $ns->tablerender($this->pluginTitle." :: ".$this->createCaption,$mes->render(). $text); + } + + + function tinymce_buttons($curVal,$id) + { + return "\n"; + } + + + function tinymce_preview() + { + return ""; + + } + + function tinymce_plugins($curVal) + { + $fl = e107::getFile(); + + $curArray = explode(",",$curVal); + + if($plug_array = $fl->get_dirs(e_PLUGIN."tinymce/plugins/")) + { + sort($plug_array); + } + + $text = "
"; + + foreach($plug_array as $mce_plg) + { + $checked = (in_array($mce_plg,$curArray)) ? "checked='checked'" : ""; + $text .= "
$mce_plg
"; + } + + $text .= "
"; + return $text; + } + + + function tinymce_class($curVal) + { + $frm = e107::getForm(); + // $cur = explode(",",$curVal); + $uc_options = "guest,member,admin,main,classes"; + return $frm->uc_checkbox('tinymce_userclass', $curVal, $uc_options); + } + + + + /** + * Generic Save DB Record Function. + * @param object $id [optional] + * @return + */ + function submitPage($id=FALSE) + { + global $sql, $tp, $e107cache, $admin_log, $e_event; + $emessage = eMessage::getInstance(); + + $insert_array = array(); + + foreach($this->fields as $key=>$att) + { + if($att['forced']!=TRUE) + { + $insert_array[$key] = $_POST[$key]; + } + + if($att['type']=='array') + { + $insert_array[$key] = implode(",",$_POST[$key]); + } + } + + if($id) + { + $insert_array['WHERE'] = $this->primary." = ".$id; + $status = $sql->db_Update($this->table,$insert_array) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED; + $message = LAN_UPDATED; + + } + else + { + $status = $sql->db_Insert($this->table,$insert_array) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED; + $message = LAN_CREATED; + } + + + $emessage->add($message, $status); + } + + function deleteRecord($id) + { + if(!$id || !$this->primary || !$this->table) + { + return; + } + + $emessage = eMessage::getInstance(); + $sql = e107::getDb(); + + $query = $this->primary." = ".$id; + $status = $sql->db_Delete($this->table,$query) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED; + $message = LAN_DELETED; + $emessage->add($message, $status); + } + + function optionsPage() + { + global $e107, $pref, $frm, $emessage; + + if(!isset($pref['pageCookieExpire'])) $pref['pageCookieExpire'] = 84600; + + //XXX Lan - Options + $text = " +
+
+ ".LAN_OPTIONS." + + + + + + + + + + + + + + + + +
".CUSLAN_29." + ".$frm->radio_switch('listPages', $pref['listPages'])." +
".CUSLAN_30." + ".$frm->text('pageCookieExpire', $pref['pageCookieExpire'], 10)." +
+
+ ".$frm->admin_button('saveOptions', CUSLAN_40, 'submit')." +
+
+
+ "; + + $e107->ns->tablerender(LAN_OPTIONS, $emessage->render().$text); + } + + + function saveSettings() + { + global $pref, $admin_log, $emessage; + $temp['listPages'] = $_POST['listPages']; + $temp['pageCookieExpire'] = $_POST['pageCookieExpire']; + if ($admin_log->logArrayDiffs($temp, $pref, 'CPAGE_04')) + { + save_prefs(); // Only save if changes + $emessage->add(CUSLAN_45, E_MESSAGE_SUCCESS); + } + else + { + $emessage->add(CUSLAN_46); + } + } + + + function show_options($action) + { + $action = varset($_GET['mode'],'list'); + + $var['list']['text'] = $this->listCaption; + $var['list']['link'] = e_SELF."?mode=list"; + $var['list']['perm'] = "0"; + + $var['create']['text'] = $this->createCaption; + $var['create']['link'] = e_SELF."?mode=create"; + $var['create']['perm'] = 0; + +/* + $var['options']['text'] = LAN_OPTIONS; + $var['options']['link'] = e_SELF."?options"; + $var['options']['perm'] = "0";*/ + + e_admin_menu($this->pluginTitle, $action, $var); + } +} + +function admin_config_adminmenu() +{ + global $ef; + global $action; + $ef->show_options($action); +} + +/** + * Handle page DOM within the page header + * + * @return string JS source + */ +function headerjs() +{ + require_once(e_HANDLER.'js_helper.php'); + $ret = " + + + "; + + return $ret; +} + + + -require_once (e_HANDLER.'message_handler.php'); -$emessage = &eMessage::getInstance(); if($_POST['save_settings']) // Needs to be saved before e_meta.php is loaded by auth.php. { @@ -44,7 +556,6 @@ if($_POST['save_settings']) // Needs to be saved before e_meta.php is loaded b $tpref = e107::getPlugConfig('tinymce')->getPref(); -require_once(e_ADMIN."auth.php"); if($_POST['save_settings']) // is there an if $emessage? $emessage->hasMessage doesn't return TRUE. @@ -54,14 +565,6 @@ if($_POST['save_settings']) // is there an if $emessage? $emessage->hasMessage } - require_once(e_HANDLER."file_class.php"); - $fl = new e_file; - - if($plug_array = $fl->get_dirs(e_PLUGIN."tinymce/plugins/")) - { - sort($plug_array); - } - if(!$tpref['theme_advanced_buttons1']) { $tpref['theme_advanced_buttons1'] = "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect"; @@ -83,7 +586,12 @@ if($_POST['save_settings']) // is there an if $emessage? $emessage->hasMessage } +function edit_theme() +{ + $ns = e107::getRender(); + + $text = "
@@ -148,6 +656,7 @@ if($_POST['save_settings']) // is there an if $emessage? $emessage->hasMessage
"; $ns -> tablerender("TinyMCE Configuration", $text); +} @@ -155,7 +664,7 @@ if($_POST['save_settings']) // is there an if $emessage? $emessage->hasMessage require_once(e_ADMIN."footer.php"); - +/* function headerjs() { require_once(e_HANDLER.'js_helper.php'); @@ -168,6 +677,6 @@ function headerjs() "; // return $ret; -} +}*/ ?> \ No newline at end of file diff --git a/e107_plugins/tinymce/e_meta.php b/e107_plugins/tinymce/e_meta.php index 9b904efec..f097f54d3 100644 --- a/e107_plugins/tinymce/e_meta.php +++ b/e107_plugins/tinymce/e_meta.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/tinymce/e_meta.php,v $ -| $Revision: 1.5 $ -| $Date: 2009-09-22 18:28:49 $ +| $Revision: 1.6 $ +| $Date: 2009-10-12 06:38:01 $ | $Author: e107coders $ +----------------------------------------------------------------------------+ */ @@ -22,7 +22,16 @@ if (!defined('e107_INIT')) { exit; } if(e_WYSIWYG || strpos(e_SELF,"tinymce/admin_config.php")) { require_once(e_PLUGIN."tinymce/wysiwyg.php"); - echo wysiwyg(); + if(deftrue('TINYMCE_CONFIG')) + { + $wy = new wysiwyg(TINYMCE_CONFIG); + } + else + { + $wy = new wysiwyg(); + } + + $wy -> render(); } diff --git a/e107_plugins/tinymce/plugin.xml b/e107_plugins/tinymce/plugin.xml index c1b32c9be..b7b4d0298 100644 --- a/e107_plugins/tinymce/plugin.xml +++ b/e107_plugins/tinymce/plugin.xml @@ -1,5 +1,5 @@ - + Wysiwyg Text-Area Replacement @@ -8,6 +8,5 @@ Configure TinyMce - val1 \ No newline at end of file diff --git a/e107_plugins/tinymce/plugins/bbcode/editor_plugin.js b/e107_plugins/tinymce/plugins/bbcode/editor_plugin.js deleted file mode 100644 index 930fdff0a..000000000 --- a/e107_plugins/tinymce/plugins/bbcode/editor_plugin.js +++ /dev/null @@ -1 +0,0 @@ -(function(){tinymce.create("tinymce.plugins.BBCodePlugin",{init:function(a,b){var d=this,c=a.getParam("bbcode_dialect","punbb").toLowerCase();a.onBeforeSetContent.add(function(e,f){f.content=d["_"+c+"_bbcode2html"](f.content)});a.onPostProcess.add(function(e,f){if(f.set){f.content=d["_"+c+"_bbcode2html"](f.content)}if(f.get){f.content=d["_"+c+"_html2bbcode"](f.content)}})},getInfo:function(){return{longname:"BBCode Plugin",author:"Moxiecode Systems AB",authorurl:"http://tinymce.moxiecode.com",infourl:"http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode",version:tinymce.majorVersion+"."+tinymce.minorVersion}},_punbb_html2bbcode:function(a){a=tinymce.trim(a);function b(c,d){a=a.replace(c,d)}b(/(.*?)<\/a>/gi,"[url=$1]$2[/url]");b(/(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");b(/(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");b(/(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");b(/(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");b(/(.*?)<\/span>/gi,"[color=$1]$2[/color]");b(/(.*?)<\/font>/gi,"[color=$1]$2[/color]");b(/(.*?)<\/span>/gi,"[size=$1]$2[/size]");b(/(.*?)<\/font>/gi,"$1");b(//gi,"[img]$1[/img]");b(/(.*?)<\/span>/gi,"[code]$1[/code]");b(/(.*?)<\/span>/gi,"[quote]$1[/quote]");b(/(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]");b(/(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]");b(/(.*?)<\/em>/gi,"[code][i]$1[/i][/code]");b(/(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]");b(/(.*?)<\/u>/gi,"[code][u]$1[/u][/code]");b(/(.*?)<\/u>/gi,"[quote][u]$1[/u][/quote]");b(/<\/(strong|b)>/gi,"[/b]");b(/<(strong|b)>/gi,"[b]");b(/<\/(em|i)>/gi,"[/i]");b(/<(em|i)>/gi,"[i]");b(/<\/u>/gi,"[/u]");b(/(.*?)<\/span>/gi,"[u]$1[/u]");b(//gi,"[u]");b(/]*>/gi,"[quote]");b(/<\/blockquote>/gi,"[/quote]");b(/
/gi,"\n");b(//gi,"\n");b(/
/gi,"\n");b(/

/gi,"");b(/<\/p>/gi,"\n");b(/ /gi," ");b(/"/gi,'"');b(/</gi,"<");b(/>/gi,">");b(/&/gi,"&");return a},_punbb_bbcode2html:function(a){a=tinymce.trim(a);function b(c,d){a=a.replace(c,d)}b(/\n/gi,"
");b(/\[b\]/gi,"");b(/\[\/b\]/gi,"");b(/\[i\]/gi,"");b(/\[\/i\]/gi,"");b(/\[u\]/gi,"");b(/\[\/u\]/gi,"");b(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,'$2');b(/\[url\](.*?)\[\/url\]/gi,'$1');b(/\[img\](.*?)\[\/img\]/gi,'');b(/\[color=(.*?)\](.*?)\[\/color\]/gi,'$2');b(/\[code\](.*?)\[\/code\]/gi,'$1 ');b(/\[quote.*?\](.*?)\[\/quote\]/gi,'$1 ');return a}});tinymce.PluginManager.add("bbcode",tinymce.plugins.BBCodePlugin)})(); \ No newline at end of file diff --git a/e107_plugins/tinymce/plugins/bbcode/editor_plugin_src.js b/e107_plugins/tinymce/plugins/e107bbcode/editor_plugin.js similarity index 84% rename from e107_plugins/tinymce/plugins/bbcode/editor_plugin_src.js rename to e107_plugins/tinymce/plugins/e107bbcode/editor_plugin.js index afcd1de5d..0787a1d8a 100644 --- a/e107_plugins/tinymce/plugins/bbcode/editor_plugin_src.js +++ b/e107_plugins/tinymce/plugins/e107bbcode/editor_plugin.js @@ -1,12 +1,12 @@ /** - * $Id: editor_plugin_src.js,v 1.2 2009-10-02 18:18:24 e107coders Exp $ + * $Id: editor_plugin.js,v 1.1 2009-10-12 06:38:01 e107coders Exp $ * * @author Moxiecode - * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. + * @copyright Copyright � 2004-2008, Moxiecode Systems AB, All rights reserved. */ (function() { - tinymce.create('tinymce.plugins.BBCodePlugin', { + tinymce.create('tinymce.plugins.e107BBCodePlugin', { init : function(ed, url) { var t = this, dialect = ed.getParam('bbcode_dialect', 'punbb').toLowerCase(); @@ -25,8 +25,8 @@ getInfo : function() { return { - longname : 'BBCode Plugin', - author : 'Moxiecode Systems AB', + longname : 'e107 BBCode Plugin', + author : 'Moxiecode Systems AB - Modified by e107 Inc', authorurl : 'http://tinymce.moxiecode.com', infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode', version : tinymce.majorVersion + "." + tinymce.minorVersion @@ -81,7 +81,14 @@ rep(/</gi,"<"); rep(/>/gi,">"); 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; }, @@ -108,10 +115,19 @@ rep(/\[code\](.*?)\[\/code\]/gi,"$1 "); rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"$1 "); + // e107 FIXME! + + rep(/\[list\]/gi,"
        "); + rep(/\[\/list\]/gi,"
      "); + + rep(/\[list=decimal\]/gi,"
        "); + rep(/\[\/list\]/gi,"
      "); + + return s; } }); // Register plugin - tinymce.PluginManager.add('bbcode', tinymce.plugins.BBCodePlugin); + tinymce.PluginManager.add('e107bbcode', tinymce.plugins.e107BBCodePlugin); })(); \ No newline at end of file diff --git a/e107_plugins/tinymce/tinymce_sql.php b/e107_plugins/tinymce/tinymce_sql.php new file mode 100644 index 000000000..6f49dde91 --- /dev/null +++ b/e107_plugins/tinymce/tinymce_sql.php @@ -0,0 +1,21 @@ +CREATE TABLE tinymce ( + `tinymce_id` int(5) NOT NULL AUTO_INCREMENT, + `tinymce_userclass` varchar(255) NOT NULL, + `tinymce_plugins` text NOT NULL, + `tinymce_buttons1` varchar(255) NOT NULL, + `tinymce_buttons2` varchar(255) NOT NULL, + `tinymce_buttons3` varchar(255) NOT NULL, + `tinymce_buttons4` varchar(255) NOT NULL, + `tinymce_custom` text NOT NULL, + `tinymce_prefs` text NOT NULL, + PRIMARY KEY (`tinymce_id`) +) TYPE=MyISAM; + +INSERT INTO tinymce ( +`tinymce_id`, `tinymce_name`, `tinymce_userclass`, `tinymce_plugins`, `tinymce_buttons1`, `tinymce_buttons2`, `tinymce_buttons3`, `tinymce_buttons4`, `tinymce_custom`, `tinymce_prefs`) VALUES +(1, 'Simple Users', '252', 'e107bbcode,emoticons', 'bold, italic, underline, undo, redo, link, unlink, image, forecolor, bullist, numlist, outdent, indent, emoticons', '', '', '', '', ''), +(2, 'Members', '253', 'e107bbcode,emoticons,table', 'bold, italic, underline, undo, redo, link, unlink, image, forecolor, removeformat, table, bullist, numlist, outdent, indent, emoticons', '', '', '', '', ''), +(3, 'Administrators', '254', 'contextmenu,e107bbcode,emoticons,ibrowser,iespell,paste,table,xhtmlxtras', 'bold, italic, underline, undo, redo, link, unlink, image, forecolor, removeformat, table, bullist, numlist, outdent, indent, cleanup, code, emoticons', '', '', '', '', ''), +(4, 'Main Admin', '250', 'advhr,advlink,autoresize,compat2x,contextmenu,directionality,emoticons,ibrowser,paste,table,visualchars,wordcount,xhtmlxtras,zoom', 'bold, italic, underline, undo, redo, link, unlink, ibrowser, forecolor, removeformat, table, bullist, numlist, outdent, indent, cleanup, code, emoticons', '', '', '', '', '' +); + diff --git a/e107_plugins/tinymce/wysiwyg.php b/e107_plugins/tinymce/wysiwyg.php index c2664977d..b1f62f59f 100644 --- a/e107_plugins/tinymce/wysiwyg.php +++ b/e107_plugins/tinymce/wysiwyg.php @@ -4,258 +4,343 @@ | e107 website system - Tiny MCE controller file. | | $Source: /cvs_backup/e107_0.8/e107_plugins/tinymce/wysiwyg.php,v $ -| $Revision: 1.16 $ -| $Date: 2009-10-02 18:50:59 $ +| $Revision: 1.17 $ +| $Date: 2009-10-12 06:38:01 $ | $Author: e107coders $ +----------------------------------------------------------------------------+ */ -function wysiwyg($formids) -{ - $tinyMcePrefs = e107::getPlugConfig('tinymce')->getPref(); +class wysiwyg +{ + var $js; + var $config = array(); -global $pref,$HANDLERS_DIRECTORY,$PLUGINS_DIRECTORY,$IMAGES_DIRECTORY; - -$lang = e_LANGUAGE; -$tinylang = array( - "Arabic" => "ar", - "Danish" => "da", - "Dutch" => "nl", - "English" => "en", - "Farsi" => "fa", - "French" => "fr", - "German" => "de", - "Greek" => "el", - "Hebrew" => " ", - "Hungarian" => "hu", - "Italian" => "it", - "Japanese" => "ja", - "Korean" => "ko", - "Norwegian" => "nb", - "Polish" => "pl", - "Russian" => "ru", - "Slovak" => "sk", - "Spanish" => "es", - "Swedish" => "sv" -); - -if(!$tinylang[$lang]) -{ - $tinylang[$lang] = "en"; -} - -$admin_only = array("ibrowser","code"); - -foreach($tinyMcePrefs['plugins'] as $val) -{ - if(in_array($val,$admin_only) && !ADMIN) + + function wysiwyg($config=FALSE) { - continue; - } - - if(!$pref['smiley_activate'] && ($val=="emoticons")) - { - continue; - } - - $tinymce_plugins[] = $val; -} - - - -/* -if(strstr(varset($_SERVER["HTTP_ACCEPT_ENCODING"],""), "gzip") && (ini_get("zlib.output_compression") == false) && file_exists(e_PLUGIN."tinymce/tiny_mce_gzip.php")) -{ - //unset($tinymce_plugins[7]); // 'zoom' causes an error with the gzip version. - $text = " - - - "; -} -else -{*/ - $text = "\n"; -//} - - - -$text .= " + + + "; + } + else + {*/ + $text = "\n"; + //} + + + + $text .= "\n + "; + + $this->js = $text; + + } + + function tinymce_lang() + { + $lang = e_LANGUAGE; + $tinylang = array( + "Arabic" => "ar", + "Danish" => "da", + "Dutch" => "nl", + "English" => "en", + "Farsi" => "fa", + "French" => "fr", + "German" => "de", + "Greek" => "el", + "Hebrew" => " ", + "Hungarian" => "hu", + "Italian" => "it", + "Japanese" => "ja", + "Korean" => "ko", + "Norwegian" => "nb", + "Polish" => "pl", + "Russian" => "ru", + "Slovak" => "sk", + "Spanish" => "es", + "Swedish" => "sv" + ); + + if(!$tinylang[$lang]) + { + $tinylang[$lang] = "en"; + } + + return $tinylang[$lang]; + } + + + function tinyMce_config() + { + $text .= " + + function start_tinyMce() + { + //config as $key=>$val) + { + $text .= "\t\t ".$key." : '".$val."',\n"; + } + + if($tinyMcePrefs['customjs']) + { + $text .= "\n, + + // Start Custom TinyMce JS ----- + + ".$pref['tinymce']['customjs']." + + // End Custom TinyMce JS --- + + "; + + } + + $text .= " + }); + } - $text .= " +"; + + return $text; + } + + + + function getConfig($config=FALSE) + { + $sql = e107::getDb(); + + if($config) + { + $query = "SELECT * FROM #tinymce WHERE tinymce_id = ".$config." LIMIT 1"; + } + else + { + $query = "SELECT * FROM #tinymce WHERE tinymce_userclass REGEXP '".e_CLASS_REGEXP."' AND NOT (tinymce_userclass REGEXP '(^|,)(".str_replace(",", "|", e_UC_NOBODY).")(,|$)') ORDER BY tinymce_userclass DESC LIMIT 1"; + } + + $sql -> db_Select_gen($query); + $config = $sql->db_Fetch(); + + //TODO Cache! + + $plug_array = explode(",",$config['tinymce_plugins']); + + + $this->config = array( + 'language' => $this->tinymce_lang(), + 'mode' => 'textareas', + 'editor_selector' => 'e-wysiwyg', + 'editor_deselector' => 'e-wysiwyg-off', + 'theme' => 'advanced', + 'plugins' => $this->filter_plugins($config['tinymce_plugins']) + ); + + $this->config += array( + + 'theme_advanced_buttons1' => $config['tinymce_buttons1'], + 'theme_advanced_buttons2' => $config['tinymce_buttons2'], + 'theme_advanced_buttons3' => $config['tinymce_buttons3'], + 'theme_advanced_buttons4' => $config['tinymce_buttons4'], + 'theme_advanced_toolbar_location' => 'bottom', + 'theme_advanced_toolbar_align' => 'center', + // 'theme_advanced_statusbar_location' => 'bottom', + 'theme_advanced_resizing' => 'true', + 'extended_valid_elements' => '', + 'invalid_elements' => 'p,font,align,script,applet,iframe', + 'auto_cleanup_word' => 'true', + 'convert_fonts_to_spans' => 'true', + 'trim_span_elements' => 'true', + 'inline_styles' => 'true', + 'debug' => 'false', + 'force_br_newlines' => 'true', + 'forced_root_block' => '', + 'force_p_newlines' => 'false', + 'entity_encoding' => 'raw', + 'convert_fonts_to_styles' => 'true', + 'remove_script_host' => 'true', + 'relative_urls' => 'true', + 'document_base_url' => SITEURL, + 'theme_advanced_styles' => 'border=border;fborder=fborder;tbox=tbox;caption=caption;fcaption=fcaption;forumheader=forumheader;forumheader3=forumheader3', + 'verify_css_classes' => 'false' - switch (type) { + ); + + if(!in_array('e107bbcode',$plug_array)) + { + $this->config['cleanup_callback'] = 'tinymce_html_bbcode_control'; + } + + + if($paste_plugin) + { + $this->config += array( + + 'remove_linebreaks' => 'false', // remove line break stripping by tinyMCE so that we can read the HTML + 'paste_create_paragraphs' => 'false', // for paste plugin - double linefeeds are converted to paragraph elements + 'paste_create_linebreaks' => 'false', // for paste plugin - single linefeeds are converted to hard line break elements + 'paste_use_dialog' => 'true', // for paste plugin - Mozilla and MSIE will present a paste dialog if true + 'paste_auto_cleanup_on_paste' => 'true', // for paste plugin - word paste will be executed when the user copy/paste content + 'paste_convert_middot_lists' => 'false', // for paste plugin - middot lists are converted into UL lists + 'paste_unindented_list_class' => 'unindentedList', // for paste plugin - specify what class to assign to the UL list of middot cl's + 'paste_convert_headers_to_strong' => 'true', // for paste plugin - converts H1-6 elements to strong elements on paste + 'paste_insert_word_content_callback' => 'convertWord', // for paste plugin - This callback is executed when the user pastes word content + 'auto_cleanup_word' => 'false' // auto clean pastes from Word + ); + } + + + if(ADMIN) + { + $this->config['external_link_list_url'] = e_PLUGIN_ABS."tiny_mce/filelist.php"; + } + - case 'get_from_editor': - // Convert HTML to e107-BBcode - source = source.replace(/target=\"_blank\"/, 'rel=\"external\"'); - source = source.replace(/^\s*|\s*$/g,''); - if(source != '') - { - source = '[html]\\n' + source + '\\n[/html]'; -/* - source = source.replace(/<\/strong>/gi,'[/b]'); - source = source.replace(//gi,'[b]'); - source = source.replace(/<\/em>/gi,'[/i]'); - source = source.replace(//gi,'[i]'); - source = source.replace(/<\/u>/gi,'[/u]'); - source = source.replace(//gi,'[u]'); - source = source.replace(/<\/strong>/gi,'[/b]'); - source = source.replace(//gi,'[/b]'); - source = source.replace(/(.*?)<\/a>/gi,'[link=$1 $2]$3[/link]'); -*/ - - } - - // Convert e107 paths. - source = source.replace(/\"".str_replace("/","\/",$IMAGES_DIRECTORY)."/g,'\"{e_IMAGE}'); - source = source.replace(/\"".str_replace("/","\/",$PLUGINS_DIRECTORY)."/g,'\"{e_PLUGIN}'); - source = source.replace(/\'".str_replace("/","\/",$IMAGES_DIRECTORY)."/g,'\'{e_IMAGE}'); - source = source.replace(/\'".str_replace("/","\/",$PLUGINS_DIRECTORY)."/g,'\'{e_PLUGIN}'); - - break; - - case 'insert_to_editor': - // Convert e107-BBcode to HTML - source = source.replace(/rel=\"external\"/, 'target=\"_blank\"'); - - html_bbcode_check = source.slice(0,6); - - if (html_bbcode_check == '[html]') { - source = source.slice(6); - } - - html_bbcode_check = source.slice(-7); - - if (html_bbcode_check == '[/html]') { - source = source.slice(0, -7); - } -/* - source = source.replace(/\[b\]/gi,''); - source = source.replace(/\[\/b\]/gi,'<\/strong>'); -*/ - source = source.replace(/\{e_IMAGE\}/gi,'".$IMAGES_DIRECTORY."'); - source = source.replace(/\{e_PLUGIN\}/gi,'".$PLUGINS_DIRECTORY."'); - - break; - } - - return source; + + } + + + function filter_plugins($plugs) + { + + $smile_pref = e107::getConfig()->getPref('smiley_activate'); + + $admin_only = array("ibrowser","code"); + + $plug_array = explode(",",$plugs); + + foreach($plug_array as $val) + { + if(in_array($val,$admin_only) && !ADMIN) + { + continue; + } + + if(!$smile_pref && ($val=="emoticons")) + { + continue; + } + + $tinymce_plugins[] = $val; + } + + return implode(",",$tinymce_plugins); + } + + + function render() + { + echo $this->js; + } } - // ]]> -function triggerSave() -{ - tinyMCE.triggerSave(); -} - - - - -\n -"; - -return $text; - -} - - -?> +?> \ No newline at end of file