1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-30 17:50:12 +02:00

Initial commit of the highly experimental TinyMce4 CDN plugin.

This commit is contained in:
Cameron
2014-05-20 16:53:06 -07:00
parent 6829586be2
commit 771d7e5168
15 changed files with 1957 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{#example_dlg.title}</title>
<script type="text/javascript" src="../../tiny_mce_popup.js"></script>
<script type="text/javascript" src="js/dialog.js"></script>
</head>
<body>
<form onsubmit="ExampleDialog.insert();return false;" action="#">
<p>Here is a example dialog.</p>
<p>Selected text: <input id="someval" name="someval" type="text" class="text" /></p>
<p>Custom arg: <input id="somearg" name="somearg" type="text" class="text" /></p>
<div class="mceActionPanel">
<input type="button" id="insert" name="insert" value="{#insert}" onclick="ExampleDialog.insert();" />
<input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />
</div>
</form>
</body>
</html>

View File

@@ -0,0 +1,489 @@
<?php
define("e_ADMIN_AREA", true);
require_once("../../../../class2.php");
//e107::lan('core','admin',TRUE);
define("e_IFRAME",true);
//require_once(e_ADMIN."auth.php");
if(!USER || check_class($pref['post_html']) == FALSE){
exit;
}
e107::css('inline',"
.selectEmote { display:inline-block; cursor:pointer;margin:3px }
body { text-align:center }
.area {
margin-top:-1px; padding:20px;
}
span.badge { cursor: pointer }
span.label { cursor: pointer }
ul.glyphicons { list-style:none; margin-left:0px; font-size:120%}
ul.glyphicons li { float:left; cursor:pointer; width:190px; padding:5px; }
a, li { outline: 0; }
");
e107::js('tinymce','tiny_mce_popup.js');
e107::js('inline',"
$(document).ready(function()
{
$('#insertButton').click(function () {
var buttonType = $('input:radio[name=buttonType]:checked').val();
var buttonSize = $('input:radio[name=buttonSize]:checked').val();
var buttonText = $('#buttonText').val();
var buttonUrl = $('#buttonUrl').val();
var buttonClass = (buttonType != '') ? 'btn-'+buttonType : '';
var html = '<a class=\"btn ' + buttonClass + ' ' + buttonSize + '\" href=\"' + buttonUrl + '\" >' + buttonText + '</a> ';
// alert(html);
tinyMCEPopup.editor.execCommand('mceInsertContent', false, html);
tinyMCEPopup.close();
});
$('span.label, span.badge').click(function () {
var cls = $(this).attr('class');
var html = '<span class=\"' + cls + '\">' + $(this).text() + '</span>&nbsp;';
tinyMCEPopup.editor.execCommand('mceInsertContent', false, html);
tinyMCEPopup.close();
});
$('ul.glyphicons li, #glyph-save').click(function () {
var color = $('#glyph-color').val();
var custom = $('#glyph-custom').val();
var cls = (custom != '') ? custom : $(this).find('i').attr('class');
var html = '<i class=\"' + cls + '\"></i>&nbsp;';
// alert(html);
tinyMCEPopup.editor.execCommand('mceInsertContent', false, html);
tinyMCEPopup.close();
});
$('#bbcodeInsert').click(function ()
{
s = $('#bbcodeValue').val();
s = s.trim(s);
var html = $.ajax({
type: 'POST',
url: './parser.php',
data: { content: s, mode: 'tohtml' },
async : false,
dataType: 'html',
success: function(html) {
return html;
}
}).responseText;
html = '<bbcode alt=\"'+encodeURIComponent(s)+'\">' + html + '</bbcode> ' ;
tinyMCEPopup.editor.execCommand('mceInsertContent', false, html);
tinyMCEPopup.close();
});
$('a.bbcodeSelect').click(function () {
var html = $(this).html();
$('#bbcodeValue').val(html);
});
$('#e-cancel').click(function () {
tinyMCEPopup.close();
});
});
",'jquery');
class e_bootstrap
{
private $styleClasses = array(''=>'Default', 'primary'=>"Primary", 'success'=>"Success", 'info'=>"Info", 'warning'=>"Warning",'danger'=>"Danger",'inverse'=>"Inverse");
function init()
{
$ns = e107::getRender();
if(e_QUERY == 'bbcode')
{
echo $this->bbcodeForm();
return;
}
$text = "<div class='alert alert-warning'>Warning: These will only work if you have a bootstrap-based theme installed</div>";
$text .= '
<ul class="nav nav-tabs">';
$text .= '<li class="active" ><a href="#mbuttons" data-toggle="tab">Buttons</a></li>';
$text .= '<li><a href="#badges" data-toggle="tab">Labels &amp; Badges</a></li>';
$text .= '<li><a href="#glyphs" data-toggle="tab">Glyphicons</a></li>';
$text .= '</ul>';
$text .= '<div class="tab-content">';
$text .= '<div class="tab-pane active left" id="mbuttons">'.$this->buttonForm().'</div>';
$text .= '<div class="tab-pane left" id="badges">'.$this->badgeForm().'</div>';
$text .= '<div class="tab-pane left" id="glyphs">'.$this->glyphicons().'</div>';
$text .= '</div>';
echo $text;
}
function buttonForm()
{
$frm = e107::getForm();
$buttonSizes = array(''=>'Default', 'btn-mini'=>"Mini", 'btn-small'=>"Small", 'btn-large' => "Large");
$buttonTypes = $this->styleClasses;
$butSelect = "";
$butSelect .= "<div class='form-inline' style='padding:5px'>";
foreach($buttonTypes as $type=>$diz)
{
$label = '<button class="btn btn-'.$type.'" >'.$diz.'</button>';
$butSelect .= $frm->radio('buttonType', $type, false, array('label'=>$label));
}
$butSelect .= "</div>";
$butSize = "<div class='form-inline' style='padding:5px'>";
foreach($buttonSizes as $size=>$label)
{
$selected = ($size == '') ? true : false;
$butSize .= $frm->radio('buttonSize', $size, $selected, array('label'=>$label));
}
$butSize .= "</div>";
$text = "
<table class='table area'>
<tr>
<td>Button Style</td>
<td>".$butSelect."</td>
</tr>
<tr>
<td>Button Size</td>
<td><p>".$butSize."</p></td>
</tr>
<tr>
<td>Button Text</td>
<td><p>".$frm->text('buttonText',$value,50)."</p></td>
</tr>
<tr>
<td>Button Url</td>
<td><p>".$frm->text('buttonUrl','',255,'size=xxlarge')."</p></td>
</tr>
</table>
<div class='center'>". $frm->admin_button('insertButton','save','other',"Insert") ."
<button class='btn ' id='e-cancel'>".LAN_CANCEL."</button>
</div>";
return $text;
}
function badgeForm()
{
unset($this->styleClasses['primary']);
foreach($this->styleClasses as $key=>$type)
{
$classLabel = ($key != '') ? " label-".$key : "";
$classBadge = ($key != '') ? " badge-".$key : "";
$text .= '<div class="area"><span class="label'.$classLabel.'">'.$type.'</span>&nbsp;';
$text .= '<span class="badge'.$classBadge.'">'.$type.'</span>';
$text .= "</div>";
}
return $text;
}
function bbcodeForm()
{
$list = e107::getPref('bbcode_list');
$text .= "
<h4>e107 Bbcodes</h4>
<div class='well'>
<table class='table table-striped'>
<tr><th>Plugin</th>
<th>Bbcode</th>
</tr>
";
foreach($list as $plugin=>$val)
{
$text .= "<tr><td>".$plugin."</td>
<td>";
foreach($val as $bb=>$v)
{
$text .= "<a href='#' class='bbcodeSelect' style='cursor:pointer'>[".$bb."][/".$bb."]</a>";
}
$text .= "</td>
</tr>";
}
$text .= "</table>
</div>";
$frm = e107::getForm();
$text .= $frm->text('bbcodeValue','',false,'size=xlarge');
$text .= $frm->button('bbcodeInsert','go','other','Insert');
return $text;
}
function glyphicons()
{
$icons = array(
"icon-glass",
"icon-music",
"icon-search",
"icon-envelope",
"icon-heart",
"icon-star",
"icon-star-empty",
"icon-user",
"icon-film",
"icon-th-large",
"icon-th",
"icon-th-list",
"icon-ok",
"icon-remove",
"icon-zoom-in",
"icon-zoom-out",
"icon-off",
"icon-signal",
"icon-cog",
"icon-trash",
"icon-home",
"icon-file",
"icon-time",
"icon-road",
"icon-download-alt",
"icon-download",
"icon-upload",
"icon-inbox",
"icon-play-circle",
"icon-repeat",
"icon-refresh",
"icon-list-alt",
"icon-lock",
"icon-flag",
"icon-headphones",
"icon-volume-off",
"icon-volume-down",
"icon-volume-up",
"icon-qrcode",
"icon-barcode",
"icon-tag",
"icon-tags",
"icon-book",
"icon-bookmark",
"icon-print",
"icon-camera",
"icon-font",
"icon-bold",
"icon-italic",
"icon-text-height",
"icon-text-width",
"icon-align-left",
"icon-align-center",
"icon-align-right",
"icon-align-justify",
"icon-list",
"icon-indent-left",
"icon-indent-right",
"icon-facetime-video",
"icon-picture",
"icon-pencil",
"icon-map-marker",
"icon-adjust",
"icon-tint",
"icon-edit",
"icon-share",
"icon-check",
"icon-move",
"icon-step-backward",
"icon-fast-backward",
"icon-backward",
"icon-play",
"icon-pause",
"icon-stop",
"icon-forward",
"icon-fast-forward",
"icon-step-forward",
"icon-eject",
"icon-chevron-left",
"icon-chevron-right",
"icon-plus-sign",
"icon-minus-sign",
"icon-remove-sign",
"icon-ok-sign",
"icon-question-sign",
"icon-info-sign",
"icon-screenshot",
"icon-remove-circle",
"icon-ok-circle",
"icon-ban-circle",
"icon-arrow-left",
"icon-arrow-right",
"icon-arrow-up",
"icon-arrow-down",
"icon-share-alt",
"icon-resize-full",
"icon-resize-small",
"icon-plus",
"icon-minus",
"icon-asterisk",
"icon-exclamation-sign",
"icon-gift",
"icon-leaf",
"icon-fire",
"icon-eye-open",
"icon-eye-close",
"icon-warning-sign",
"icon-plane",
"icon-calendar",
"icon-random",
"icon-comment",
"icon-magnet",
"icon-chevron-up",
"icon-chevron-down",
"icon-retweet",
"icon-shopping-cart",
"icon-folder-close",
"icon-folder-open",
"icon-resize-vertical",
"icon-resize-horizontal",
"icon-hdd",
"icon-bullhorn",
"icon-bell",
"icon-certificate",
"icon-thumbs-up",
"icon-thumbs-down",
"icon-hand-right",
"icon-hand-left",
"icon-hand-up",
"icon-hand-down",
"icon-circle-arrow-right",
"icon-circle-arrow-left",
"icon-circle-arrow-up",
"icon-circle-arrow-down",
"icon-globe",
"icon-wrench",
"icon-tasks",
"icon-filter",
"icon-briefcase",
"icon-fullscreen"
);
$frm = e107::getForm();
$sel = array(''=>'Dark Gray','icon-white'=>'White');
$text .= "<div class='area'>";
$text .= "<div class='inline-form'>Color: ".$frm->select('glyph-color',$sel)." Custom: ".$frm->text('glyph-custom','').$frm->button('glyph-save','Go')."</div>";
$text .= "<ul class='glyphicons well clearfix'>";
$inverse = (e107::getPref('admincss') == "admin_dark.css") ? " icon-white" : "";
foreach($icons as $ic)
{
$text .= '<li><i class="'.$ic.$inverse.'"></i> '.$ic.'</li>';
$text .= "\n";
}
$text .= "</ul>";
$text .= "</div>";
return $text;
}
}
require_once(e_ADMIN."auth.php");
//e107::lan('core','admin',TRUE);
$bootObj = new e_bootstrap;
$bootObj->init();
require_once(e_ADMIN."footer.php");
exit;
//
?>

View File

@@ -0,0 +1,323 @@
/**
* $Id$
*
* @author Moxiecode
* @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
*/
(function() {
tinymce.create('tinymce.plugins.e107BBCodePlugin', {
init : function(ed, url) {
// Bootstrap
ed.addCommand('mceBoot', function() {
ed.windowManager.open({
file : url + '/dialog.php',
width : 900 , // + parseInt(ed.getLang('e107bbcode.delta_width', 0)),
height : 450, // + parseInt(ed.getLang('e107bbcode.delta_height', 0)),
inline : 1
}, {
plugin_url : url, // Plugin absolute URL
some_custom_arg : 'custom arg' // Custom argument
});
});
// Register button
ed.addButton('bootstrap', {
title : 'Insert Bootstrap Elements',
cmd : 'mceBoot',
image : url + '/img/bootstrap.png'
});
// e107 Bbcode
ed.addCommand('mcee107', function() {
ed.windowManager.open({
file : url + '/dialog.php?bbcode',
width : 900 , // + parseInt(ed.getLang('e107bbcode.delta_width', 0)),
height : 450, // + parseInt(ed.getLang('e107bbcode.delta_height', 0)),
inline : 1
}, {
plugin_url : url, // Plugin absolute URL
some_custom_arg : 'custom arg' // Custom argument
});
});
// Register button
ed.addButton('e107bbcode', {
title : 'Insert e107 Bbcode',
cmd : 'mcee107',
image : url + '/img/bbcode.png'
});
// Add a node change handler, selects the button in the UI when a image is selected
// ed.onNodeChange.add(function(ed, cm, n) {
// cm.setActive('example', n.nodeName == 'IMG');
// });
// ------------
var t = this, dialect = ed.getParam('bbcode_dialect', 'e107').toLowerCase();
ed.onBeforeSetContent.add(function(ed, o) {
o.content = t['_' + dialect + '_bbcode2html'](o.content,url);
});
ed.onPostProcess.add(function(ed, o) {
if (o.set)
o.content = t['_' + dialect + '_bbcode2html'](o.content,url);
if (o.get)
o.content = t['_' + dialect + '_html2bbcode'](o.content,url);
});
},
getInfo : function() {
return {
longname : 'e107 BBCode Plugin',
author : 'Moxiecode Systems AB - Modified by e107 Inc',
authorurl : 'http://e107.org',
infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',
version : tinymce.majorVersion + "." + tinymce.minorVersion
};
},
// Private methods
// HTML -> BBCode in PunBB dialect
_e107_html2bbcode : function(s,url) {
s = tinymce.trim(s);
var p = $.ajax({
type: "POST",
url: url + "/parser.php",
data: { content: s, mode: 'tobbcode' },
async : false,
dataType: "html",
success: function(html) {
return html;
}
}).responseText;
return p;
function rep(re, str) {
s = s.replace(re, str);
};
// return s;
rep(/<table(.*)>/gim, "[table]");
rep(/<\/table>/gim, "[/table]");
rep(/<td>/gim, "[td]");
rep(/<\/td>/gim, "[/td]");
rep(/<tr>/gim, "[tr]");
rep(/<\/tr>/gim, "[/tr]");
rep(/<tbody>/gim, "[tbody]");
rep(/<\/tbody>/gim, "[/tbody]");
rep(/<div style="text-align: center;">([\s\S]*)<\/div>/gi,"[center]$1[/center]"); // verified
rep(/<li>/gi, "[*]"); // verified
rep(/<\/li>/gi, ""); // verified
rep(/<ul>([\s\S]*?)<\/ul>\n/gim, "[list]$1[/list]"); // verified
rep(/<ol .* style=\'list-style-type:\s*([\w]*).*\'>([\s\S]*)<\/ol>/gim,"[list=$1]$2[/list]\n"); // verified
rep(/<ol>([\s\S]*?)<\/ol>/gim,"[list=decimal]$1[/list]\n"); // verified
rep(/<span style="color: (#?.*?);">([\s\S]*)<\/span>/gi,"[color=$1]$2[/color]"); // verified
rep(/<h2>/gim, "[h]"); // verified
rep(/<\/h2>/gim, "[/h]"); // verified
// example: <strong> to [b]
rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[link=$1]$2[/link]");
rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
rep(/<span style=\"color: ?(.*?);\">(.*?)<\/span>/gi,"[color=$1]$2[/color]");
rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[color=$1]$2[/color]");
rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi,"[size=$1]$2[/size]");
rep(/<font>(.*?)<\/font>/gi,"$1");
// rep(/<img.*?style=\"(.*?)\".*?src=\"(.*?)\".*?\/>/gi,"[img style=$1]$2[/img]");
// New Image Handler // verified
// rep(/<img(?:\s*)?(?:style="(.*)")?\s?(?:src="([^;"]*)")(?:\s*)?(?:width="([\d]*)")?\s*(?:height="([\d]*)")?(?:\s*)?(?:alt="(\S*)")? (?:\s*)?\/>/gi,"[img style=$1;width:$4px;height:$5px]$2[/img]" );
//rep(/<img(?:\s*)?(?:style="(.*)")?\s?(?:src="([\S ]*)")(?:\s*)?(?:alt="(\S*)")?(?:\s*)?(?:width="([\d]*)")?\s*(?:height="([\d]*)")?(?:\s*)?\/>/gi,"[img style=$1;width:$4px;height:$5px]$2[/img]" )
rep(/<img(?:\s*)?(?:style="([^"]*)")?\s?(?:src="([^"]*)")(?:\s*)?(?:alt="(\S*)")?(?:\s*)?(?:width="([\d]*)")?\s*(?:height="([\d]*)")?(?:\s*)?\/>/gm,"[img style=width:$4px;height:$5px;$1]$2[/img]" );
rep(/;width:px;height:px/gi, ""); // Img cleanup.
// rep(/<img\s*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");
rep(/<blockquote[^>]*>/gi,"[blockquote]");
rep(/<\/blockquote>/gi,"[/blockquote]");
rep(/<code[^>]*>/gi,"[code]");
rep(/<\/code>/gi,"[/code]");
// rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi,"[code]$1[/code]");
// rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi,"[quote]$1[/quote]");
// rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]");
// rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]");
// rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi,"[code][i]$1[/i][/code]");
// rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]");
// rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi,"[code][u]$1[/u][/code]");
// rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi,"[quote][u]$1[/u][/quote]");
rep(/<\/(strong|b)>/gi,"[/b]");
rep(/<(strong|b)>/gi,"[b]");
rep(/<\/(em|i)>/gi,"[/i]");
rep(/<(em|i)>/gi,"[i]");
rep(/<\/u>/gi,"[/u]");
rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");
rep(/<u>/gi,"[u]");
// Compromise - but BC issues for sure.
// rep(/<br \/>/gi,"[br]");
// rep(/<br\/>/gi,"[br]");
// rep(/<br>/gi,"[br]");
rep(/<br \/>/gi,"\n");
rep(/<br\/>/gi,"\n");
rep(/<br>/gi,"\n");
rep(/<p>/gi,"");
rep(/<\/p>/gi,"\n");
rep(/&nbsp;/gi," ");
rep(/&quot;/gi,"\"");
rep(/&lt;/gi,"<");
rep(/&gt;/gi,">");
rep(/&amp;/gi,"&");
// e107
return s;
},
// BBCode -> HTML from PunBB dialect
_e107_bbcode2html : function(s,url) {
s = tinymce.trim(s);
var p = $.ajax({
type: "POST",
url: url + "/parser.php",
data: { content: s, mode: 'tohtml' },
async : false,
dataType: "html",
success: function(html) {
return html;
}
}).responseText;
return p;
return s;
function rep(re, str) {
s = s.replace(re, str);
};
// example: [b] to <strong>
// rep(/<ul>(\r|\n)?/gim, "<ul>"); // remove line-breaks
// rep(/<\/li>(\r|\n)?/gim, "</li>"); // remove line-breaks
// rep(/<\/ul>(\r|\n)?/gim, "</ul>"); // remove line-breaks
rep(/\[table]/gim, "<table>");
rep(/\[\/table]/gim, "</table>");
rep(/\[td]/gim, "<td>");
rep(/\[\/td]/gim, "</td>");
rep(/\[tr]/gim, "<tr>");
rep(/\[\/tr]/gim, "</tr>");
rep(/\[tbody]/gim, "<tbody>");
rep(/\[\/tbody]/gim, "</tbody>");
rep(/\[h]/gim, "<h2>"); // verified
rep(/\[\/h]/gim, "</h2>"); // verified
rep(/\[list](?:\n)/gim, "<ul>\n"); // verified
// rep(/\[list]/gim, "<ul>"); // verified
rep(/\[\/list](?:\n)?/gim, "</ul>\n"); // verified
rep(/^ *?(?:\*|\[\*\])([^\*[]*)/gm,"<li>$1</li>\n");
// return s;
// rep(/(\[list=.*\])\\*([\s\S]*)(\[\/list])(\n|\r)/gim,"<ol>$2</ol>"); // verified
// rep(/(\[list\])\\*([\s\S]*)(\[\/list])(\n|\r)?/gim,"<ul>$2</ul>");// verified
rep(/\[center\]([\s\S]*)\[\/center\]/gi,"<div style=\"text-align:center\">$1</div>"); // verified
rep(/\[color=(.*?)\]([\s\S]*)\[\/color\]/gi,"<span style=\"color: $1;\">$2<\/span>"); // verified
// rep(/\[br]/gi,"<br />"); // compromise
rep(/\[blockquote\]/gi,"<blockquote>");
rep(/\[\/blockquote\]/gi,"</blockquote>");
rep(/\[code\]/gi,"<code>");
rep(/\[\/code\]/gi,"</code>");
//rep( /(?<!(\[list]))\r|\n/gim,"<br />" )
rep(/\[b\]/gi,"<strong>");
rep(/\[\/b\]/gi,"</strong>");
rep(/\[i\]/gi,"<em>");
rep(/\[\/i\]/gi,"</em>");
rep(/\[u\]/gi,"<u>");
rep(/\[\/u\]/gi,"</u>");
rep(/\[link=([^\]]+)\](.*?)\[\/link\]/gi,"<a href=\"$1\">$2</a>");
rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");
// rep(/\[img.*?style=(.*?).*?\](.*?)\[\/img\]/gi,"<img style=\"$1\" src=\"$2\" />");
// When Width and Height are present:
rep(/\[img\s*?style=(?:width:(\d*)px;height:(\d*)px;)([^\]]*)]([\s\S]*?)\[\/img]/gm, "<img style=\"$3\" src=\"$4\" alt=\"\" width=\"$1\" height=\"$2\" />");
// No width/height but style is present
rep(/\[img\s*?style=([^\]]*)]([\s\S]*?)\[\/img]/gi,"<img style=\"$1\" src=\"$2\" />");
rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");
// rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<font color=\"$1\">$2</font>");
// rep(/\[code\](.*?)\[\/code\]/gi,"<span class=\"codeStyle\">$1</span>&nbsp;");
// rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<span class=\"quoteStyle\">$1</span>&nbsp;");
// rep(/<br \/>/gm, "<br />\n");
rep(/(\r|\n)$/gim,"<br />");
// rep(/(\r|\n)/gim,"<br />\n"); // this will break bullets.
// e107 FIXME!
// rep("/\[list\](.+?)\[\/list\]/is", '<ul class="listbullet">$1</ul>');
//
return s;
}
});
// Register plugin
tinymce.PluginManager.add('e107bbcode', tinymce.plugins.e107BBCodePlugin);
})();

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -0,0 +1,13 @@
<?php
require_once("../../../../class2.php");
$types = array('img','video','glyph');
$bbcode = in_array(e_QUERY,$types) ? e_QUERY : 'img';
header("Location: ".e_ADMIN_ABS.'image.php?mode=main&action=dialog&for='.$_SESSION['media_category'].'&tagid=&iframe=1&bbcode='.$bbcode, true);
exit;
?>

View File

@@ -0,0 +1,145 @@
<?php
/*
* e107 website system
*
* Copyright (C) e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* $URL: https://e107.svn.sourceforge.net/svnroot/e107/trunk/e107_0.8/e107_handlers/bbcode_handler.php $
* $Id: bbcode_handler.php 12778 2012-06-02 08:12:16Z e107coders $
*/
require_once("../../../../class2.php");
/**
* Two Modes supported below going to and from the Tinymce wysiwyg editor.
* 1) When the post_html pref is active - raw html is used in the editor and wrapped in [html] [/html] bbcodes in the background.
* 2) When the post_html pref is disabled - bbcodes are used in the background and converted to html for the editor.
* Tested extensively over 24 hours with Images - check with Cameron first if issues arise.
* TODO Test Lines breaks and out html tags.
* TODO Check with html5 tags active.
*/
if($_POST['mode'] == 'tohtml')
{
// XXX @Cam possible fix - convert to BB first, see news admin AJAX request/response values for reference why
$content = stripslashes($_POST['content']);
// $content = e107::getBB()->htmltoBBcode($content); //XXX This breaks inserted images from media-manager. :/
e107::getBB()->setClass($_SESSION['media_category']);
if(check_class($pref['post_html'])) // raw HTML within [html] tags.
{
if(strstr($content,"[html]") === false) // BC - convert old BB code text to html.
{
e107::getBB()->clearClass();
$content = str_replace('\r\n',"<br />",$content);
$content = nl2br($content, true);
$content = $tp->toHtml($content, true);
}
$content = str_replace("{e_BASE}","",$content); // We want {e_BASE} in the final data going to the DB, but not the editor.
$srch = array("<!-- bbcode-html-start -->","<!-- bbcode-html-end -->","[html]","[/html]");
$content = str_replace($srch,"",$content);
$content = e107::getBB()->parseBBCodes($content); // parse the <bbcode> tag so we see the HTML equivalent while editing!
echo $content;
}
else // bbcode Mode.
{
// XXX @Cam this breaks new lines, currently we use \n instead [br]
//echo $tp->toHtml(str_replace("\n","",$content), true);
$content = str_replace("{e_BASE}",e_HTTP, $content); // We want {e_BASE} in the final data going to the DB, but not the editor.
$content = $tp->toHtml($content, true);
$content = str_replace(e_MEDIA_IMAGE,"{e_MEDIA_IMAGE}",$content);
echo $content;
}
e107::getBB()->clearClass();
}
if($_POST['mode'] == 'tobbcode')
{
// echo $_POST['content'];
$content = stripslashes($_POST['content']);
if(check_class($pref['post_html'])) // Plain HTML mode.
{
$srch = array('src="'.e_HTTP.'thumb.php?','src="/{e_MEDIA_IMAGE}');
$repl = array('src="{e_BASE}thumb.php?','src="{e_BASE}thumb.php?src=e_MEDIA_IMAGE/');
$content = str_replace($srch, $repl, $content);
// resize the thumbnail to match wysiwyg width/height.
// $psrch = '/<img[^>]*src="{e_BASE}thumb.php\?src=([\S]*)w=([\d]*)&amp;h=([\d]*)"(.*)width="([\d]*)" height="([\d]*)"/i';
// $prepl = '<img src="{e_BASE}thumb.php?src=$1w=$5&amp;h=$6"$4width="$5" height="$6" ';
// $content = preg_replace($psrch, $prepl, $content);
$content = updateImg($content);
$content = $tp->parseBBTags($content,true); // replace html with bbcode equivalent
echo ($content) ? "[html]".$content."[/html]" : ""; // Add the tags before saving to DB.
}
else // bbcode Mode. //XXX Disabled at the moment in tinymce/e_meta.php - post_html is required to activate.
{
// [img width=400]/e107_2.0/thumb.php?src={e_MEDIA_IMAGE}2012-12/e107org_white_stripe.png&w=400&h=0[/img]
// $content = str_replace("{e_BASE}","", $content); // We want {e_BASE} in the final data going to the DB, but not the editor.
echo e107::getBB()->htmltoBBcode($content); // not reliable enough yet.
}
}
/**
* Rebuld <img> tags with modified thumbnail size.
*/
function updateImg($text)
{
$arr = e107::getParser()->getTags($text,'img');
$srch = array("?","&");
$repl = array("\?","&amp;");
foreach($arr['img'] as $img)
{
$regexp = '#(<img[^>]*src="'.str_replace($srch, $repl, $img['src']).'"[^>]*>)#';
$width = vartrue($img['width']) ? ' width="'.$img['width'].'"' : '';
$height = vartrue($img['height']) ? ' height="'.$img['height'].'"' : '';
$style = vartrue($img['style']) ? ' style="'.$img['style'].'"' : '';
$class = vartrue($img['class']) ? ' class="'.$img['class'].'"' : '';
$alt = vartrue($img['alt']) ? ' alt="'.$img['alt'].'"' : '';
list($url,$qry) = explode("?",$img['src']);
parse_str($qry,$qr);
$qr['w'] = $img['width'];
$qr['h'] = $img['height'];
$src = $url."?".urldecode(http_build_query($qr));
$replacement = '<img'.$class.$style.' src="'.$src.'"'.$width.$height.$alt.' />';
$text = preg_replace($regexp, $replacement, $text);
}
return $text;
}
?>

View File

@@ -0,0 +1,180 @@
/**
* plugin.js
*
* Copyright, Moxiecode Systems AB
* Released under LGPL License.
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
*/
/*global tinymce:true */
(function() {
tinymce.create('tinymce.plugins.e107Plugin', {
init : function(ed,url) {
var t = this, dialect = ed.getParam('bbcode_dialect', 'e107').toLowerCase();
ed.on('beforeSetContent', function(e) {
e.content = t['_' + dialect + '_bbcode2html'](e.content, url);
});
ed.on('postProcess', function(e) {
if (e.set) {
e.content = t['_' + dialect + '_bbcode2html'](e.content, url);
}
if (e.get) {
e.content = t['_' + dialect + '_html2bbcode'](e.content, url);
}
});
// Emoticons
ed.addButton('e107-emotes', {
text: 'Media Manager',
icon: 'emoticons',
onclick: function() {
// Open window
ed.windowManager.open({
title: 'Example plugin',
body: [
{type: 'textbox', name: 'title', label: 'Title'}
],
onsubmit: function(e) {
// Insert content when the window form is submitted
ed.insertContent('Title: ' + e.data.title);
}
});
}
});
// Media Manager Button
ed.addButton('e107-image', {
text: '',
title: 'Insert Media-Manager Image',
icon: 'image',
onclick: function() {
ed.windowManager.open({
title: 'Media Manager',
url: url + '/mediamanager.php?image',
width: 1050,
height: 650
});
}
});
// Media Manager Button
ed.addButton('e107-video', {
text: '',
title: 'Insert Media-Manager Video',
icon: 'media',
resizable : 'no',
inline : 'yes',
close_previous : 'no',
onclick: function() {
ed.windowManager.open({
title: 'Media Manager',
url: url + '/mediamanager.php?video',
width: 1050,
height: 650
});
}
});
ed.addButton('e107-glyph', {
text: '',
title: 'Insert Media-Manager Glyph',
icon: 'charmap',
onclick: function() {
ed.windowManager.open({
title: 'Media Manager',
url: url + '/mediamanager.php?glyph',
width: 1050,
height: 650
});
}
});
},
getInfo: function() {
return {
longname: 'e107 Parser Plugin',
author: 'Moxiecode Systems AB',
authorurl: 'http://www.tinymce.com',
infourl: 'http://www.tinymce.com/wiki.php/Plugin:bbcode'
};
},
// Private methods
// HTML -> BBCode in PunBB dialect
_e107_html2bbcode : function(s, url) {
s = tinymce.trim(s);
// return s;
var p = $.ajax({
type: "POST",
url: url + "/parser.php",
data: { content: s, mode: 'tobbcode' },
async : false,
dataType: "html",
success: function(html) {
return html;
}
}).responseText;
return p;
},
// BBCode -> HTML from PunBB dialect
_e107_bbcode2html : function(s, url) {
s = tinymce.trim(s);
// return s;
var p = $.ajax({
type: "POST",
url: url + "/parser.php",
data: { content: s, mode: 'tohtml' },
async : false,
dataType: "html",
success: function(html) {
return html;
}
}).responseText;
return p;
}
});
// Register plugin
tinymce.PluginManager.add('e107', tinymce.plugins.e107Plugin);
})();