這個帖子 Discuz! X2 的時候寫過,升級 Discuz! X2.5 之後那個帖子基礎上再做了下修改。

當一些用户發佈帖子的時候 標題要是超過了 80 個字符超出的部分被剪切掉了,特別是一些用户發送一些英文或其他其語言的文章的時候標題説甚至會超過 180 個字符,又特別論壇編碼是 UTF-8 格式,因為一個字佔 3 個字節,所以標題最長也就 26 個漢字,很多用户想修改這個 80 個字符的限制。

想去掉這個字數限制,要從下面五個部分來修改:
一、數據庫修改;
二、修改 JS 驗證字符數文件;
三、修改模板中寫死的字符限制數;
四,修改函數驗證文件;
五,修改語言包文件。

現以把標題字符限制 80 修改為 120 為例子,描述一下修改方法:

一、數據庫修改,修改數據庫標題字段的長度為 120 字符:運行下面的 sql 語句:
(注意修改你的表的前綴)

  1. ALTER TABLE `pre_forum_post` CHANGE `subject` `subject` VARCHAR(120) NOT NULL;
  2. ALTER TABLE `pre_forum_rsscache` CHANGE `subject` `subject` char(120) NOT NULL;
  3. ALTER TABLE `pre_forum_thread` CHANGE `subject` `subject` char(120) NOT NULL;

二、修改 JS 驗證字符數:1 、找到文件 static/js/forum_post.js 的 74-80 行

  1. if(($('postsubmit').name != 'replysubmit' && !($('postsubmit').name == 'editsubmit' && !isfirstpost) && theform.subject.value == "") || !sortid && !special && trim(message) == "") {
  2.                 showError('抱歉,您尚未輸入標題或內容');
  3.                 return false;
  4.         } else if(mb_strlen(theform.subject.value) > 80) {
  5.                 showError('您的標題超過 80 個字符的限制');
  6.                 return false;
  7.         }

修改為:

  1. if(($('postsubmit').name != 'replysubmit' && !($('postsubmit').name == 'editsubmit' && !isfirstpost) && theform.subject.value == "") || !sortid && !special && trim(message) == "") {
  2.                 showError('抱歉,您尚未輸入標題或內容');
  3.                 return false;
  4.         } else if(mb_strlen(theform.subject.value) > 120) {
  5.                 showError('您的標題超過 120 個字符的限制');
  6.                 return false;
  7.         }

2 、找到文件 sitatic/js/forum.js 的 209 到 215 行代碼:

  1. if(theform.message.value == '' && theform.subject.value == '') {
  2.                 s = '抱歉,您尚未輸入標題或內容';
  3.                 theform.message.focus();
  4.         } else if(mb_strlen(theform.subject.value) > 80) {
  5.                 s = '您的標題超過 80 個字符的限制';
  6.                 theform.subject.focus();
  7.         }

修改為:

  1. if(theform.message.value == '' && theform.subject.value == '') {
  2.                 s = '抱歉,您尚未輸入標題或內容';
  3.                 theform.message.focus();
  4.         } else if(mb_strlen(theform.subject.value) > 120) {
  5.                 s = '您的標題超過 120 個字符的限制';
  6.                 theform.subject.focus();
  7.         }

三、修改模板中寫死的字符限制數:
1 、找到文件\template\default\forum\post_editor_extra.htm 的 25 到 31 行:

  1. <!--{if $_G[gp_action] != 'reply'}-->
  2. <span><input type="text" name="subject" id="subject" class="px" value="$postinfo[subject]" {if $_G[gp_action] == 'newthread'}onblur="if($('tags')){relatekw('-1','-1'{if $_G['group']['allowposttag']},function(){extraCheck(4)}{/if});doane();}"{/if} style="width: 25em" tabindex="1" /></span>
  3. <!--{else}-->
  4. <span id="subjecthide" class="z">RE: $thread[subject] [<a href="">{lang modify}</a>]</span>
  5. <span id="subjectbox" style="display:none"><input type="text" name="subject" id="subject" class="px" value="" style="width: 25em" /></span>
  6. <!--{/if}-->
  7. <span id="subjectchk"{if $_G[gp_action] == 'reply'} style="display:none"{/if}>{lang comment_message1} <strong id="checklen">80</strong> {lang comment_message2}</span>

修改為下面代碼:

  1. <!--{if $_G[gp_action] != 'reply'}-->
  2. <span><input type="text" name="subject" id="subject" class="px" value="$postinfo[subject]" {if $_G[gp_action] == 'newthread'}onblur="if($('tags')){relatekw('-1','-1'{if $_G['group']['allowposttag']},function(){extraCheck(4)}{/if});doane();}"{/if} style="width: 25em" tabindex="1" /></span>
  3. <!--{else}-->
  4. <span id="subjecthide" class="z">RE: $thread[subject] [<a href="">{lang modify}</a>]</span>
  5. <span id="subjectbox" style="display:none"><input type="text" name="subject" id="subject" class="px" value="" style="width: 25em" /></span>
  6. <!--{/if}-->
  7. <span id="subjectchk"{if $_G[gp_action] == 'reply'} style="display:none"{/if}>{lang comment_message1} <strong id="checklen">120</strong> {lang comment_message2}</span>

2 、找到文件\template\default\forum\forumdisplay_fastpost.htm31-32 行:

  1. <input type="text" id="subject" name="subject" class="px" value="" tabindex="11" style="width: 25em" />
  2. <span>{lang comment_message1} <strong id="checklen">80</strong> {lang comment_message2}</span>

修改為:

  1. <input type="text" id="subject" name="subject" class="px" value="" tabindex="11" style="width: 25em" />
  2. <span>{lang comment_message1} <strong id="checklen">120</strong> {lang comment_message2}</span>

四,修改函數驗證提示:
找到文件 source/function/function_post.php 的 346-348 行:

  1. if(dstrlen($subject) > 80) {
  2. return 'post_subject_toolong';
  3. }

修改為:

  1. if(dstrlen($subject) > 120) {
  2. return 'post_subject_toolong';
  3. }

五、找到語言包提示文字,打開 source/language/lang_messege.php 並找到 985 行改為:

  1.   'post_subject_toolong' => '抱歉,您的標題超過 120 個字符修改標題長度',

OK,你再發表帖子標題就可以是 120 個字符數了!!!