1 頁 (共 1 頁)

phpbb 3 所見即所得editor的實現

發表於 : 2009-02-04 07:40
lbren
在開發過程中也對phpbb3的差勁程度有了新的認識,可以說代碼結構很糟糕,根本不便於mod
由於本人精力有限,mod的製作中遇到了關鍵性的兩個難題,希望有能力的朋友能加以修正。
好了,不多說了,著重介紹我的mod方法。
2009-02-03_133359.jpg
本mod引用fckeditor編輯器,請先在 http://sourceforge.net/project/download ... _2.6.4.zip 下載FCKeditor_2.6.4.zip,解壓縮後將fckeditor資料夾放入當前風格的template資料夾中。

1、打開template/posting_buttons.html 文件查找

代碼: 選擇全部

<script type="text/javascript" src="{T_TEMPLATE_PATH}/editor.js"></script>
在下增加代碼:

代碼: 選擇全部

<script type="text/javascript" src="{T_TEMPLATE_PATH}/fckeditor/fckeditor.js"></script>
2、打開template/posting_editor.html 文件查找

代碼: 選擇全部

<div id="message-box">
在下增加代碼:

代碼: 選擇全部

<script type="text/javascript">
window.onload = function()
{
var oFCKeditor = new FCKeditor( 'message' ) ;
oFCKeditor.BasePath = "{T_TEMPLATE_PATH}/fckeditor/" ;
oFCKeditor.ReplaceTextarea() ;
}
</script>
3、打開viewtopic.php 文件查找

代碼: 選擇全部

//
   $postrow = array(
      'POST_AUTHOR_FULL'      => get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
      'POST_AUTHOR_COLOUR'   => get_username_string('colour', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
      'POST_AUTHOR'         => get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
      'U_POST_AUTHOR'         => get_username_string('profile', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
在前面添加代碼

代碼: 選擇全部

$DDD = array('<','>','"','&nbsp;','&');
   $replaced = array('<','>','"','','&');
   $message = str_replace($DDD,$replaced,$message);
這時我們安裝的fckeditor所見所得編輯器就能正常發帖了。由於本人工作較忙,現在還有兩個問題沒有解決,希望有能力的朋友能夠順利完成。
1、因為fckeditor發送的是html源碼,因此預覽不能實現html解析,但因本人已將viewtopic.php 做了mod,發帖後流覽沒有發現問題;
2、系統的bbcode及附件如何正確和fckeditor相接。

解決這兩個問題後,phpbb3 就可以完美實現視覺化編輯。我也希望能和朋友相探討,請發站內信或郵件 mtme@ymail.com

Re: phpbb 3 所見即所得editor的實現

發表於 : 2009-02-05 13:21
hentaibbc
開放 HTML 給會員使用並不一定比較好。
依照您所修改的內容,script 以及 style 皆可被接受並執行。
如此您的網站很容易遭受「跨網站攻擊(CSRF attack)」,對您的會員沒有任何保障。

我會建議您開發使用 BBCode 的所見即所得功能,您可以參考使用 HotEditer 試試,網址如下:
http://ecardmax.com/index.php?step=Hoteditor

額外說明:
1. 既然是 phpBB3 的相關文章,為何要發在 phpBB2 的版面中?
2. 您是否想過您的這個 MOD 並非額外建立的模組,而是針對原本已存在的功能進行修改。在這樣的前提,本來就不易進行修改,除非您對於該功能的程式碼內容有相當程度的了解。
3. 您的修改可以不必自行寫 str_replace() 方法,phpBB3 有許多內建的 API 可以使用。

抱歉!文章鎖定!