/** * $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(//gim, "[table]"); rep(/<\/table>/gim, "[/table]"); rep(//gim, "[td]"); rep(/<\/td>/gim, "[/td]"); rep(//gim, "[tr]"); rep(/<\/tr>/gim, "[/tr]"); rep(//gim, "[tbody]"); rep(/<\/tbody>/gim, "[/tbody]"); rep(/
([\s\S]*)<\/div>/gi,"[center]$1[/center]"); // verified rep(/
  • /gi, "[*]"); // verified rep(/<\/li>/gi, ""); // verified rep(/
      ([\s\S]*?)<\/ul>\n/gim, "[list]$1[/list]"); // 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 rep(/

          /gim, "[h]"); // verified rep(/<\/h2>/gim, "[/h]"); // verified // example: to [b] 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]"); rep(/(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]"); rep(/(.*?)<\/span>/gi,"[color=$1]$2[/color]"); rep(/(.*?)<\/font>/gi,"[color=$1]$2[/color]"); rep(/(.*?)<\/span>/gi,"[size=$1]$2[/size]"); rep(/(.*?)<\/font>/gi,"$1"); // rep(//gi,"[img style=$1]$2[/img]"); // New Image Handler // verified // rep(//gi,"[img style=$1;width:$4px;height:$5px]$2[/img]" ); //rep(//gi,"[img style=$1;width:$4px;height:$5px]$2[/img]" ) rep(//gm,"[img style=width:$4px;height:$5px;$1]$2[/img]" ); rep(/;width:px;height:px/gi, ""); // Img cleanup. // rep(//gi,"[img]$1[/img]"); rep(/]*>/gi,"[blockquote]"); rep(/<\/blockquote>/gi,"[/blockquote]"); rep(/]*>/gi,"[code]"); rep(/<\/code>/gi,"[/code]"); // rep(/(.*?)<\/span>/gi,"[code]$1[/code]"); // rep(/(.*?)<\/span>/gi,"[quote]$1[/quote]"); // rep(/(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]"); // rep(/(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]"); // rep(/(.*?)<\/em>/gi,"[code][i]$1[/i][/code]"); // rep(/(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]"); // rep(/(.*?)<\/u>/gi,"[code][u]$1[/u][/code]"); // rep(/(.*?)<\/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>/gi,"[u]$1[/u]"); rep(//gi,"[u]"); // Compromise - but BC issues for sure. // rep(/
          /gi,"[br]"); // rep(//gi,"[br]"); // rep(/
          /gi,"[br]"); rep(/
          /gi,"\n"); rep(//gi,"\n"); rep(/
          /gi,"\n"); rep(/

          /gi,""); rep(/<\/p>/gi,"\n"); rep(/ /gi," "); rep(/"/gi,"\""); rep(/</gi,"<"); rep(/>/gi,">"); rep(/&/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 // rep(/

            (\r|\n)?/gim, "
              "); // remove line-breaks // rep(/<\/li>(\r|\n)?/gim, ""); // remove line-breaks // rep(/<\/ul>(\r|\n)?/gim, "
            "); // remove line-breaks rep(/\[table]/gim, ""); rep(/\[\/table]/gim, "
            "); rep(/\[td]/gim, ""); rep(/\[\/td]/gim, ""); rep(/\[tr]/gim, ""); rep(/\[\/tr]/gim, ""); rep(/\[tbody]/gim, ""); rep(/\[\/tbody]/gim, ""); rep(/\[h]/gim, "

            "); // verified rep(/\[\/h]/gim, "

            "); // verified rep(/\[list](?:\n)/gim, "
              \n"); // verified // rep(/\[list]/gim, "
                "); // verified rep(/\[\/list](?:\n)?/gim, "
              \n"); // verified rep(/^ *?(?:\*|\[\*\])([^\*[]*)/gm,"
            • $1
            • \n"); // return s; // rep(/(\[list=.*\])\\*([\s\S]*)(\[\/list])(\n|\r)/gim,"
                $2
              "); // verified // rep(/(\[list\])\\*([\s\S]*)(\[\/list])(\n|\r)?/gim,"
                $2
              ");// verified rep(/\[center\]([\s\S]*)\[\/center\]/gi,"
              $1
              "); // verified rep(/\[color=(.*?)\]([\s\S]*)\[\/color\]/gi,"$2<\/span>"); // verified // rep(/\[br]/gi,"
              "); // compromise rep(/\[blockquote\]/gi,"
              "); rep(/\[\/blockquote\]/gi,"
              "); rep(/\[code\]/gi,""); rep(/\[\/code\]/gi,""); //rep( /(?" ) rep(/\[b\]/gi,""); rep(/\[\/b\]/gi,""); rep(/\[i\]/gi,""); rep(/\[\/i\]/gi,""); rep(/\[u\]/gi,""); rep(/\[\/u\]/gi,""); rep(/\[link=([^\]]+)\](.*?)\[\/link\]/gi,"$2"); rep(/\[url\](.*?)\[\/url\]/gi,"$1"); // rep(/\[img.*?style=(.*?).*?\](.*?)\[\/img\]/gi,""); // When Width and Height are present: rep(/\[img\s*?style=(?:width:(\d*)px;height:(\d*)px;)([^\]]*)]([\s\S]*?)\[\/img]/gm, "\"\""); // No width/height but style is present rep(/\[img\s*?style=([^\]]*)]([\s\S]*?)\[\/img]/gi,""); rep(/\[img\](.*?)\[\/img\]/gi,""); // rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"$2"); // rep(/\[code\](.*?)\[\/code\]/gi,"$1 "); // rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"$1 "); // rep(/
              /gm, "
              \n"); rep(/(\r|\n)$/gim,"
              "); // rep(/(\r|\n)/gim,"
              \n"); // this will break bullets. // e107 FIXME! // rep("/\[list\](.+?)\[\/list\]/is", '
                $1
              '); // return s; } }); // Register plugin tinymce.PluginManager.add('e107bbcode', tinymce.plugins.e107BBCodePlugin); })();