醒游网

当前位置: 首页 » 网站日记 » Discuz! 建站技巧(2):解决帖子标题80个字符的限制

Discuz! 建站技巧(2):解决帖子标题80个字符的限制

discuz!x3.3 建站有一个很烦人的问题,论坛帖子标题长度只有80个字符(指单字节),如果你像我一样使用 UTF-8 版本,一个汉字就要占用 三个字符,这意味着只能输入26个汉字左右(包括全角标点符号),这显然不太够用,  我决定将帖子标题的长度改为200个字符。

修改论坛标题字数限制,主要从下面五个部分来修改:

1、数据库修改;

2、修改JS验证字符数文件;

3、修改模板中字符数量限制;

4、修改函数验证文件;

5、修改语言包文件。

一、修改数据库标题字段的长度为200字符:

打开网站后台->站长->数据库->升级,运行下面的 SQL 语句:

ALTER TABLE `pre_forum_post` CHANGE `subject` `subject` VARCHAR(200) NOT NULL;

ALTER TABLE `pre_forum_rsscache` CHANGE `subject` `subject` char(200) NOT NULL;

ALTER TABLE `pre_forum_thread` CHANGE `subject` `subject` char(200) NOT NULL;

备注:这个SQL语句的输入框默认是没有的,需要将文件 config/config_global.php 当中的 $_config['admincp']['runquery'] 设置修改为 1才会显示出来。

你也可以直接在 phpMyAdmin 里面执行SQL语句。

注意“pre”是数据库默认前缀,每个人的数据库前缀可能不一样,需要自己修改。

二、修改JS验证字符数代码(需要修改2个JS文件):

1、找到文件 sitatic/js/forum.js 的212到218行代码:

if(theform.message.value == '' || theform.subject.value == '') {

s = '抱歉,您尚未输入标题或内容';

theform.message.focus();

} else if(mb_strlen(theform.subject.value) > 80) {

s = '您的标题超过 80 个字符的限制';

theform.subject.focus();

}

修改为:

if(theform.message.value == '' || theform.subject.value == '') {

s = '抱歉,您尚未输入标题或内容';

theform.message.focus();

} else if(mb_strlen(theform.subject.value) > 200) {

s = '您的标题超过 200 个字符的限制';

theform.subject.focus();

}

2、找到文件 static/js/forum_post.js 的75-81行

if(($('postsubmit').name != 'replysubmit' && !($('postsubmit').name == 'editsubmit' && !isfirstpost) && theform.subject.value == "") || !sortid && !special && trim(message) == "") {

showError('抱歉,您尚未输入标题或内容');

return false;

} else if(mb_strlen(theform.subject.value) > 80) {

showError('您的标题超过 80 个字符的限制');

return false;

}

修改为:

if(($('postsubmit').name != 'replysubmit' && !($('postsubmit').name == 'editsubmit' && !isfirstpost) && theform.subject.value == "") || !sortid && !special && trim(message) == "") {

showError('抱歉,您尚未输入标题或内容');

return false;

} else if(mb_strlen(theform.subject.value) > 200) {

showError('您的标题超过 200 个字符的限制');

return false;

}

三、修改模板中的字符数限制(需修改2个HTM文件):

1、找到文件 template/default/forum/forumdisplay_fastpost.htm31-32行:

<input type="text" id="subject" name="subject" class="px" value=""#0000ff">80);" tabindex="11" style="width: 25em" />

<span>{lang comment_message1} <strong id="checklen">80</strong> {lang comment_message2}</span>

修改为:

<input type="text" id="subject" name="subject" class="px" value=""#0000ff">200);" tabindex="11" style="width: 25em" />

<span>{lang comment_message1} <strong id="checklen">200</strong> {lang comment_message2}</span>

2、找到文件 template/default/forum/post_editor_extra.htm的24到32行:

<!–{if $_GET[action] != 'reply'}–>

<span><input type="text" name="subject" id="subject" class="px" value="$postinfo[subject]" {if $_GET[action] == 'newthread'}onblur="if($('tags')){relatekw('-1','-1'{if $_G['group']['allowposttag']},function(){extraCheck(4)}{/if});doane();}"{/if}#0000ff">80);" style="width: 25em" tabindex="1" /></span>

<!–{else}–>

<span id="subjecthide" class="z">RE: $thread[subject] [<a href="javascript:;"#0000ff">80);return false;">{lang modify}</a>]</span>

<span id="subjectbox" style="display:none"><input type="text" name="subject" id="subject" class="px" value=""FONT-WEIGHT: bold; COLOR: #0000ff">80);" style="width: 25em" /></span>

<!–{/if}–>

<span id="subjectchk"{if $_GET[action] == 'reply'} style="display:none"{/if}>{lang comment_message1} <strong id="checklen">80</strong> {lang comment_message2}</span>

<script type="text/javascript">strLenCalc($('subject'), 'checklen', 80)</script>

<!–{/if}–>

修改为:

<!–{if $_GET[action] != 'reply'}–>

<span><input type="text" name="subject" id="subject" class="px" value="$postinfo[subject]" {if $_GET[action] == 'newthread'}onblur="if($('tags')){relatekw('-1','-1'{if $_G['group']['allowposttag']},function(){extraCheck(4)}{/if});doane();}"{/if}#ff0000">200);" style="width: 25em" tabindex="1" /></span>

<!–{else}–>

<span id="subjecthide" class="z">RE: $thread[subject] [<a href="javascript:;"#ff0000">200);return false;">{lang modify}</a>]</span>

<span id="subjectbox" style="display:none"><input type="text" name="subject" id="subject" class="px" value=""FONT-WEIGHT: bold; COLOR: #0000ff">200);" style="width: 25em" /></span>

<!–{/if}–>

<span id="subjectchk"{if $_GET[action] == 'reply'} style="display:none"{/if}>{lang comment_message1} <strong id="checklen">200</strong> {lang comment_message2}</span>

<script type="text/javascript">strLenCalc($('subject'), 'checklen', 200)</script>

<!–{/if}–>

四、修改函数验证提示:

找到文件 source/function/function_post.php ,这里是对帖子标题长度做了限制,只需修改361-363行:

if(dstrlen($subject) > 80) {

return 'post_subject_toolong';

}

修改为:

if(dstrlen($subject) > 200) {

return 'post_subject_toolong';

}

五、修改语言包提示文字:

通过前面4步的修改,已经可以达到解决字数限制的目的,我们再修改下当会员编辑帖子标题的时候,如果超过定义的长度,系统给出的友好提示语。

找到文件 source/language/lang_messege.php 的998行:

'post_subject_toolong' => '抱歉,您的标题超过 80 个字符修改标题长度',

修改为:

'post_subject_toolong' => '抱歉,您的标题超过 200 个字符修改标题长度',

至此大功告成,完美解决帖子标题80个字符的限制。

六、修改标题输入框的长度:

如果想要修改标题输入框的长度,则只需修改文件 template/default/forum/post_editor_extra.htm 的26和29行

<span><input type="text" name="subject" id="subject" class="px" value="$postinfo[subject]" onkeyup="strLenCalc(this, 'checklen', 200);" style="width: 25em" tabindex="1" /></span>

<!–{else}–>

<span id="subjecthide" class="z">RE: $thread[subject] [<a href="javascript:;" onclick="display('subjecthide');display('subjectbox');return false;">{lang modify}</a>]</span>

<span id="subjectbox" style="display:none"><input type="text" name="subject" id="subject" class="px" value="" onkeyup="strLenCalc(this, 'checklen', 200);" style="width: 25em" /></span>

修改为

<span><input type="text" name="subject" id="subject" class="px" value="$postinfo[subject]" onkeyup="strLenCalc(this, 'checklen', 200);" style="width: 50em" tabindex="1" /></span>

<!–{else}–>

<span id="subjecthide" class="z">RE: $thread[subject] [<a href="javascript:;" onclick="display('subjecthide');display('subjectbox');return false;">{lang modify}</a>]</span>

<span id="subjectbox" style="display:none"><input type="text" name="subject" id="subject" class="px" value="" onkeyup="strLenCalc(this, 'checklen', 200);" style="width: 50em" /></span>

效果如下图,这样我们就不会为输入框遮住长标题而担忧了。

关键字:
猜你喜欢
用户评论
  1. 好早以前我做论坛的时候。好像纠结过这个问题。

  2. 以后会常来逛逛,博客很棒。

要发表评论,您必须先登录/注册
本类排行