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

TinyMce - work in progress

This commit is contained in:
CaMer0n
2009-10-12 06:38:01 +00:00
parent 90905603ee
commit f5b7907e00
7 changed files with 904 additions and 266 deletions

View File

@@ -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 = "<form method='post' action='".e_SELF."?mode=create'>
<fieldset id='core-release-list'>
<legend class='e-hideme'>".$this->pluginTitle."</legend>
<table cellpadding='0' cellspacing='0' class='adminlist'>".
$frm->colGroup($this->fields,$this->fieldpref).
$frm->thead($this->fields,$this->fieldpref).
"<tbody>";
if(!$sql->db_Select_gen($this->listQry))
{
$text .= "\n<tr><td colspan='".count($this->fields)."' class='center middle'>".CUSLAN_42."</td></tr>\n";
}
else
{
$row = $sql->db_getList('ALL', FALSE, FALSE);
foreach($row as $field)
{
$text .= "<tr>\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<td ".$class.">".$this->renderValue($key,$field)."</td>\n" : "";
}
$text .= "</tr>\n";
}
}
$text .= "
</tbody>
</table>
</fieldset>
</form>
";
$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 = "<input type='image' class='action edit' name='edit[{$row[$id]}]' src='".ADMIN_EDIT_ICON_PATH."' title='".LAN_EDIT."' />";
$text .= "<input type='image' class='action delete' name='delete[{$row[$id]}]' src='".ADMIN_DELETE_ICON_PATH."' title='".LAN_DELETE." [ ID: {$row[$id]} ]' />";
return $text;
}
switch($att['type'])
{
case 'url':
return "<a href='".$row[$key]."'>".$row[$key]."</a>";
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 = "
<form method='post' action='".e_SELF."?mode=create' id='dataform' enctype='multipart/form-data'>
<fieldset id='core-cpage-create-general'>
<legend class='e-hideme'>".$this->pluginTitle."</legend>
<table cellpadding='0' cellspacing='0' class='adminedit'>
<colgroup span='2'>
<col class='col-label' />
<col class='col-control' />
</colgroup>
<tbody>
<tr>
<td>Preview<div style='padding:20px'>[<a href='javascript:start_tinyMce();'>Refresh Preview</a>]
<br /><br />[<a href='#' onclick=\"tinyMCE.execCommand('mceToggleEditor',false,'content');\">Toggle WYSIWYG</a>]
</div>
</td>
<td>".$this->tinymce_preview()."</td>
</tr>";
foreach($this->fields as $key=>$att)
{
if($att['forced']!==TRUE)
{
$text .= "
<tr>
<td class='label'>".$att['title']."</td>
<td class='control'>".$this->renderElement($key,$row)."</td>
</tr>";
}
}
$text .= "
</tbody>
</table>
<div class='buttons-bar center'>";
if($id)
{
$text .= $frm->admin_button('update', LAN_UPDATE, 'update');
$text .= "<input type='hidden' name='record_id' value='".$id."' />";
}
else
{
$text .= $frm->admin_button('create', LAN_CREATE, 'create');
}
$text .= "
</div>
</fieldset>
</form>";
$ns->tablerender($this->pluginTitle." :: ".$this->createCaption,$mes->render(). $text);
}
function tinymce_buttons($curVal,$id)
{
return "<input class='tbox' style='width:97%' type='text' name='tinymce_buttons".$id."' value='".$curVal."' />\n";
}
function tinymce_preview()
{
return "<textarea id='content' class='e-wysiwyg tbox' rows='10' cols='10' name='preview' style='width:80%'> </textarea>";
}
function tinymce_plugins($curVal)
{
$fl = e107::getFile();
$curArray = explode(",",$curVal);
if($plug_array = $fl->get_dirs(e_PLUGIN."tinymce/plugins/"))
{
sort($plug_array);
}
$text = "<div style='width:80%'>";
foreach($plug_array as $mce_plg)
{
$checked = (in_array($mce_plg,$curArray)) ? "checked='checked'" : "";
$text .= "<div style='width:25%;float:left'><input type='checkbox' name='tinymce_plugins[]' value='".$mce_plg."' $checked /> $mce_plg </div>";
}
$text .= "</div>";
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 = "
<form method='post' action='".e_SELF."?".e_QUERY."'>
<fieldset id='core-cpage-options'>
<legend class='e-hideme'>".LAN_OPTIONS."</legend>
<table cellpadding='0' cellspacing='0' class='adminform'>
<colgroup span='2'>
<col class='col-label' />
<col class='col-control' />
</colgroup>
<tbody>
<tr>
<td class='label'>".CUSLAN_29."</td>
<td class='control'>
".$frm->radio_switch('listPages', $pref['listPages'])."
</td>
</tr>
<tr>
<td class='label'>".CUSLAN_30."</td>
<td class='control'>
".$frm->text('pageCookieExpire', $pref['pageCookieExpire'], 10)."
</td>
</tr>
</tbody>
</table>
<div class='buttons-bar center'>
".$frm->admin_button('saveOptions', CUSLAN_40, 'submit')."
</div>
</fieldset>
</form>
";
$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 = "
<script type='text/javascript'>
if(typeof e107Admin == 'undefined') var e107Admin = {}
/**
* OnLoad Init Control
*/
e107Admin.initRules = {
'Helper': true,
'AdminMenu': false
}
</script>
<script type='text/javascript' src='".e_FILE_ABS."jslib/core/admin.js'></script>
";
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 = "<div style='text-align:center'>
<form method='post' action='".e_SELF."'>
<fieldset id='plugin-tinymce-config'>
@@ -148,6 +656,7 @@ if($_POST['save_settings']) // is there an if $emessage? $emessage->hasMessage
</div>";
$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;
}
}*/
?>

View File

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

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Id: plugin.xml,v 1.1 2009-09-28 07:18:42 e107coders Exp $ -->
<!-- $Id: plugin.xml,v 1.2 2009-10-12 06:38:01 e107coders Exp $ -->
<e107Plugin name="TinyMce" version="1.0" compatibility="0.8" installRequired="true" >
<author name="e107 Inc." url="http://e107.org" />
<description>Wysiwyg Text-Area Replacement</description>
@@ -8,6 +8,5 @@
<link url='admin_config.php' description='Configure TinyMce' icon='images/icon_32.png' iconSmall='images/icon_16.png' primary='true' >Configure TinyMce</link>
</adminLinks>
<pluginPrefs>
<pref name="key1">val1</pref>
</pluginPrefs>
</e107Plugin>

View File

@@ -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.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");b(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");b(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");b(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");b(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");b(/<span style=\"color: ?(.*?);\">(.*?)<\/span>/gi,"[color=$1]$2[/color]");b(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[color=$1]$2[/color]");b(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi,"[size=$1]$2[/size]");b(/<font>(.*?)<\/font>/gi,"$1");b(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");b(/<span class=\"codeStyle\">(.*?)<\/span>/gi,"[code]$1[/code]");b(/<span class=\"quoteStyle\">(.*?)<\/span>/gi,"[quote]$1[/quote]");b(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]");b(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]");b(/<em class=\"codeStyle\">(.*?)<\/em>/gi,"[code][i]$1[/i][/code]");b(/<em class=\"quoteStyle\">(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]");b(/<u class=\"codeStyle\">(.*?)<\/u>/gi,"[code][u]$1[/u][/code]");b(/<u class=\"quoteStyle\">(.*?)<\/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 style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");b(/<u>/gi,"[u]");b(/<blockquote[^>]*>/gi,"[quote]");b(/<\/blockquote>/gi,"[/quote]");b(/<br \/>/gi,"\n");b(/<br\/>/gi,"\n");b(/<br>/gi,"\n");b(/<p>/gi,"");b(/<\/p>/gi,"\n");b(/&nbsp;/gi," ");b(/&quot;/gi,'"');b(/&lt;/gi,"<");b(/&gt;/gi,">");b(/&amp;/gi,"&");return a},_punbb_bbcode2html:function(a){a=tinymce.trim(a);function b(c,d){a=a.replace(c,d)}b(/\n/gi,"<br />");b(/\[b\]/gi,"<strong>");b(/\[\/b\]/gi,"</strong>");b(/\[i\]/gi,"<em>");b(/\[\/i\]/gi,"</em>");b(/\[u\]/gi,"<u>");b(/\[\/u\]/gi,"</u>");b(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,'<a href="$1">$2</a>');b(/\[url\](.*?)\[\/url\]/gi,'<a href="$1">$1</a>');b(/\[img\](.*?)\[\/img\]/gi,'<img src="$1" />');b(/\[color=(.*?)\](.*?)\[\/color\]/gi,'<font color="$1">$2</font>');b(/\[code\](.*?)\[\/code\]/gi,'<span class="codeStyle">$1</span>&nbsp;');b(/\[quote.*?\](.*?)\[\/quote\]/gi,'<span class="quoteStyle">$1</span>&nbsp;');return a}});tinymce.PluginManager.add("bbcode",tinymce.plugins.BBCodePlugin)})();

View File

@@ -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 <EFBFBD> 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(/&lt;/gi,"<");
rep(/&gt;/gi,">");
rep(/&amp;/gi,"&");
// e107
rep(/<ul>/gi,"[list]");
rep(/<\/ul>/gi,"[/list]");
rep(/<ol>/gi,"[list=decimal]");
rep(/<\/ol>/gi,"[/list]");
rep(/<li>/gi,"[*]");
rep(/<\/li>/gi,"\n");
return s;
},
@@ -108,10 +115,19 @@
rep(/\[code\](.*?)\[\/code\]/gi,"<span class=\"codeStyle\">$1</span>&nbsp;");
rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<span class=\"quoteStyle\">$1</span>&nbsp;");
// e107 FIXME!
rep(/\[list\]/gi,"<ul>");
rep(/\[\/list\]/gi,"</ul>");
rep(/\[list=decimal\]/gi,"<ol>");
rep(/\[\/list\]/gi,"</ol>");
return s;
}
});
// Register plugin
tinymce.PluginManager.add('bbcode', tinymce.plugins.BBCodePlugin);
tinymce.PluginManager.add('e107bbcode', tinymce.plugins.e107BBCodePlugin);
})();

View File

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

View File

@@ -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 = "<script type='text/javascript' src='".e_PLUGIN_ABS."tinymce/tiny_mce_gzip.js'></script>
<script type='text/javascript'>
tinyMCE_GZ.init({
plugins : '".implode(",",$tinymce_plugins)."',
themes : 'advanced',
languages : '".$tinylang[$lang]."',
disk_cache : false,
debug : false
});
</script>
";
}
else
{*/
$text = "<script type='text/javascript' src='".e_PLUGIN_ABS."tinymce/tiny_mce.js'></script>\n";
//}
$text .= "<script type='text/javascript'>\n
function start_tinyMce() {
//<![CDATA[
tinyMCE.init({
language : '".$tinylang[$lang]."',
mode : 'textareas',
editor_selector : 'e-wysiwyg',
editor_deselector : 'e-wysiwyg-off',
theme : 'advanced',
plugins : '".implode(",",$tinymce_plugins)."'\n";
$this->getConfig($config);
global $pref,$HANDLERS_DIRECTORY,$PLUGINS_DIRECTORY,$IMAGES_DIRECTORY;
/*
$text .= ",theme_advanced_buttons1 : 'fontsizeselect,separator,bold,italic,underline,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,outdent, indent,separator, forecolor,cut,copy,paste'";
$text .= ",theme_advanced_buttons2 : 'tablecontrols,separator,undo,redo,separator,link,unlink";
$text .= ($pref['smiley_activate']) ? ",emoticons" : "";
$text .= ",charmap,iespell,media";
$text .= (ADMIN) ? ",ibrowser," : ",image";
$text .= (ADMIN) ? ",code" : "";
$text .= "'"; // end of buttons 2
$text .= ",theme_advanced_buttons3 : ''";
*/
$text .= ",
theme_advanced_buttons1 : '".$tinyMcePrefs['theme_advanced_buttons1']."',
theme_advanced_buttons2 : '".$tinyMcePrefs['theme_advanced_buttons2']."',
theme_advanced_buttons3 : '".$tinyMcePrefs['theme_advanced_buttons3']."',
theme_advanced_buttons4 : '".$tinyMcePrefs['theme_advanced_buttons4']."',
theme_advanced_toolbar_location : \"bottom\",
theme_advanced_toolbar_align : \"left\",
theme_advanced_statusbar_location : \"bottom\",
theme_advanced_resizing : true\n";
$text .= ",extended_valid_elements : ''\n";
$text .= ",invalid_elements: 'p,font,align,script,applet,iframe'\n";
$text .= ",auto_cleanup_word: true\n";
$text .= ",convert_fonts_to_spans : true\n";
$text .= ",trim_span_elements: true\n";
$text .= ",inline_styles: true\n";
$text .= ",debug: false\n";
$text .= ",force_br_newlines: true\n";
$text .= ",forced_root_block : ''\n";
$text .= ",force_p_newlines: false\n";
$text .= ",entity_encoding: \"raw\" \n";
$text .= ",convert_fonts_to_styles: true\n";
$text .= ",remove_script_host : true\n";
$text .= ",relative_urls: true\n";
$text .= ",document_base_url: '".SITEURL."'\n";
$text .= ",theme_advanced_styles: 'border=border;fborder=fborder;tbox=tbox;caption=caption;fcaption=fcaption;forumheader=forumheader;forumheader3=forumheader3'\n";
// $text .= ",popup_css: '".THEME."style.css'\n";
$text .= ",verify_css_classes : false\n";
$text .= ",cleanup_callback : \"tinymce_html_bbcode_control\" \n";
$text .= (ADMIN) ? "\n, external_link_list_url: '../".e_PLUGIN_ABS."tiny_mce/filelist.php'\n" : "";
if($tinyMcePrefs['customjs'])
{
$text .= "\n,
// Start Custom TinyMce JS -----
".$pref['tinymce']['customjs']."
// End Custom TinyMce JS ---
";
}
$text .= "
}
);
}
start_tinyMce();
function tinymce_html_bbcode_control(type, source) {
";
if(in_array("bbcode",$tinyMcePrefs['plugins']))
/*
if(strstr(varset($_SERVER["HTTP_ACCEPT_ENCODING"],""), "gzip") && (ini_get("zlib.output_compression") == false) && file_exists(e_PLUGIN."tinymce/tiny_mce_gzip.php"))
{
// $text .= " return source; ";
//unset($tinymce_plugins[7]); // 'zoom' causes an error with the gzip version.
$text = "<script type='text/javascript' src='".e_PLUGIN_ABS."tinymce/tiny_mce_gzip.js'></script>
<script type='text/javascript'>
tinyMCE_GZ.init({
plugins : '".implode(",",$tinymce_plugins)."',
themes : 'advanced',
languages : '".$tinylang[$lang]."',
disk_cache : false,
debug : false
});
</script>
";
}
else
{*/
$text = "<script type='text/javascript' src='".e_PLUGIN_ABS."tinymce/tiny_mce.js'></script>\n";
//}
$text .= "<script type='text/javascript'>\n";
$text .= $this->tinyMce_config();
$text .= "\t\t start_tinyMce(); \n
function tinymce_html_bbcode_control(type, source) {
switch (type) {
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(/<strong>/gi,'[b]');
source = source.replace(/<\/em>/gi,'[/i]');
source = source.replace(/<em>/gi,'[i]');
source = source.replace(/<\/u>/gi,'[/u]');
source = source.replace(/<u>/gi,'[u]');
source = source.replace(/<\/strong>/gi,'[/b]');
source = source.replace(/<img/gi,'[img');
source = source.replace(/<\/strong>/gi,'[/b]');
source = source.replace(/<a href=\"(.*?)\"(.*?)>(.*?)<\/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,'<strong>');
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 triggerSave()
{
tinyMCE.triggerSave();
}
</script>\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()
{
//<![CDATA[
tinyMCE.init({ \n\n";
foreach($this->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(/<strong>/gi,'[b]');
source = source.replace(/<\/em>/gi,'[/i]');
source = source.replace(/<em>/gi,'[i]');
source = source.replace(/<\/u>/gi,'[/u]');
source = source.replace(/<u>/gi,'[u]');
source = source.replace(/<\/strong>/gi,'[/b]');
source = source.replace(/<img/gi,'[img');
source = source.replace(/<\/strong>/gi,'[/b]');
source = source.replace(/<a href=\"(.*?)\"(.*?)>(.*?)<\/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,'<strong>');
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();
}
</script>\n
";
return $text;
}
?>
?>