phpBB TinyMCE integration - Trình soạn thảo cho phpBB3

Thảo luận trong 'Hỗ trợ về mã nguồn làm Forum' bắt đầu bởi vnthongtin, 4/12/13.

  1. vnthongtin

    vnthongtin Lính mới

    Tham gia ngày:
    21/11/13
    Bài viết:
    15
    Đã được thích:
    0
    Điểm thành tích:
    1
    Dao diện:
    [​IMG]
    Hướng dẫn cài đặt
    1. Tải bộ cài đặt TinyMCE 3.5.10 bên dưới về, sau đó upload thư mục tiny_mce lên hosting của bạn theo đường dẫn styles/prosilver/template/tiny_mce
    2. Mở file styles/prosilver/template/tiny_mce/plugins/bbcode/editor_plugin.js và thay thế nội dung của nó bằng:
    Mã:
     /**
    * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
    *
    * @author Moxiecode
    * @author Garak Hình ảnh và Link chỉ có thành viên mới được xem.
    * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
    */
    
    (function() {
     tinymce.create('tinymce.plugins.BBCodePlugin', {
     init : function(ed, url) {
     var t = this, dialect = ed.getParam('bbcode_dialect', 'punbb').toLowerCase();
    
     ed.onBeforeSetContent.add(function(ed, o) {
     o.content = t['_' + dialect + '_bbcode2html'](o.content);
     });
    
     ed.onPostProcess.add(function(ed, o) {
     if (o.set)
     o.content = t['_' + dialect + '_bbcode2html'](o.content);
    
     if (o.get)
     o.content = t['_' + dialect + '_html2bbcode'](o.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
     };
     },
    
     // Private methods
    
     // HTML -> BBCode in PunBB dialect
     _punbb_html2bbcode : function(s) {
     s = tinymce.trim(s);
    
     function rep(re, str) {
     s = s.replace(re, str);
     };
    
     // example: <strong> to 
     rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"Hình ảnh và Link chỉ có thành viên mới được xem.");
     rep(/<blockquote><div><cite><\/cite>(.*?)<\/div><\/blockquote>/gi,"[quote]$1[/quote]");
     rep(/<blockquote><div><cite>(.*?) wrote:<\/cite>(.*?)<\/div><\/blockquote>/gi,"[quote=\"$1\"]$2[/quote]");
     rep(/<span style=\"color: ?(.*?);\">(.*?)<\/span>/gi,"$2");
     rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"$2");
     // font size
     rep(/<span.*?style=\"font-size: (\d{2,3})%;\">(.*?)<\/span>/gi,"$2
    ");
     rep(/<span style=\"font-size: (\d{2,3})%; color: ?(.*?);\">(.*?)<\/span>/gi,"$3
    ");
     rep(/<font>(.*?)<\/font>/gi,"$1");
     // emoticons
     rep(/<img.*?src=\"images\/smilies\/icon_e_biggrin\.gif\".*?\/>/gi,":-D");
     rep(/<img.*?src=\"images\/smilies\/icon_e_smile\.gif\".*?\/>/gi,":-)");
    rep(/<img.*?src=\"images\/smilies\/icon_e_wink\.gif\".*?\/>/gi,";-)");
    rep(/<img.*?src=\"images\/smilies\/icon_e_sad\.gif\".*?\/>/gi,":-(");
    rep(/<img.*?src=\"images\/smilies\/icon_e_surprised\.gif\".*?\/>/gi,":-o");
     rep(/<img.*?src=\"images\/smilies\/icon_e_eek\.gif\".*?\/>/gi,":shock:");
     rep(/<img.*?src=\"images\/smilies\/icon_e_confused\.gif\".*?\/>/gi,":-?");
    rep(/<img.*?src=\"images\/smilies\/icon_cool\.gif\".*?\/>/gi,"8-)");
    rep(/<img.*?src=\"images\/smilies\/icon_lol\.gif\".*?\/>/gi,":lol:");
     rep(/<img.*?src=\"images\/smilies\/icon_mad\.gif\".*?\/>/gi,":-x");
     rep(/<img.*?src=\"images\/smilies\/icon_razz\.gif\".*?\/>/gi,":-p");
     rep(/<img.*?src=\"images\/smilies\/icon_redface\.gif\".*?\/>/gi,":oops:");
    rep(/<img.*?src=\"images\/smilies\/icon_cry\.gif\".*?\/>/gi,":cry:");
     rep(/<img.*?src=\"images\/smilies\/icon_evil\.gif\".*?\/>/gi,":evil:");
     rep(/<img.*?src=\"images\/smilies\/icon_twisted\.gif\".*?\/>/gi,":twisted:");
     rep(/<img.*?src=\"images\/smilies\/icon_rolleyes\.gif\".*?\/>/gi,":roll:");
     rep(/<img.*?src=\"images\/smilies\/icon_exclaim\.gif\".*?\/>/gi,":!:");
     rep(/<img.*?src=\"images\/smilies\/icon_question\.gif\".*?\/>/gi,":?:");
     rep(/<img.*?src=\"images\/smilies\/icon_arrow\.gif\".*?\/>/gi,":arrow:");
     rep(/<img.*?src=\"images\/smilies\/icon_neutral\.gif\".*?\/>/gi,":-|");
    rep(/<img.*?src=\"images\/smilies\/icon_mrgreen\.gif\".*?\/>/gi,":mrgreen:");
     rep(/<img.*?src=\"images\/smilies\/icon_e_geek\.gif\".*?\/>/gi,":geek:");
     rep(/<img.*?src=\"images\/smilies\/icon_e_ugeek\.gif\".*?\/>/gi,":ugeek:");
     // lists
     rep(/<ul[^>]*>(.*?)<\/ul>/gi,"[list]\n$1[/list]");
     rep(/<ol style="list-style-type: lower-alpha;">(.*?)<\/ol>/gi,"[list=a]\n$1[/list]");
     rep(/<ol[^>]*>(.*?)<\/ol>/gi,"[list=1]\n$1[/list]");
     rep(/<li>(.*?)<\/li>/gi,"[*]$1\n");
     rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"");
     rep(/<dl class=\"codebox\"><dt>Code: <a href=\"#\" onclick=\"selectCode(this); return false;\">Select all<\/a><\/dt><dd><code>(.*?)<br \/><\/code><\/dd><\/dl>/gi,"[code]$1
    ");
    rep(/<\/(strong|b)>/gi,"");
    rep(/<(strong|b)>/gi,"");
    rep(/<\/(em|i)>/gi,"");
    rep(/<(em|i)>/gi,"");
    rep(/<\/u>/gi,"");
    rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"$1");
    rep(/<u>/gi,"");
    rep(/<blockquote[^>]*>/gi,"
    ");
    rep(/<br \/>/gi,"\n");
    rep(/<br\/>/gi,"\n");
    rep(/<br>/gi,"\n");
    rep(/<p>/gi,"");
    rep(/<\/p>/gi,"\n");
    rep(/ /gi," ");
    rep(/"/gi,"\"");
    rep(/</gi,"<");
    rep(/>/gi,">");
    rep(/&/gi,"&");

    return s;
    },

    // BBCode -> HTML from PunBB dialect
    _punbb_bbcode2html : function(s) {
    s = tinymce.trim(s);

    function rep(re, str) {
    s = s.replace(re, str);
    };

    // example: to <strong>
    rep(/\n/gi,"<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(/\]+)\](.*?)\[\/url\]/gi,"<a href=\"$1\">$2</a>");
    rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");
    rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");
    rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<font color=\"$1\">$2</font>");
    rep(/\[code\](.*?)\[\/code\]/gi,"<dl class=\"codebox\"><dt>Code: <a href=\"#\" onclick=\"return false;\">Select all<\/a><\/dt><dd><code>$1<br \/><\/code><\/dd><\/dl> ");
    rep(/\
     

Chia sẻ trang này