立即註冊  找回密码

QQ登录

只需一步,快速开始

开启辅助访问 切换到宽版

東里論壇

搜索
查看: 8061|回复: 0

[使用心得] Discuz! X3.3优化修改(六)——帖子标题突破80字符的限制

[复制链接]

335

主题

486

帖子

3089

积分

管理員

Rank: 9Rank: 9Rank: 9

积分
3089
发表于 2016-1-14 12:58:52 |阅读模式
Discuz!X3.2论坛帖子标题原来限制为80字符(指单字节),而UTF-8版本一个汉字即占用三个字节,所以最多不过能输入26个汉字(包括全角标点符号)而已,这是远远不够用的。所以需要修改,我是把他改成200字符的,下面是从网上找来的修改方法。

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

一、数据库修改;
二、修改JS验证字符数文件;
三、修改模板中字符数量限制;
四、修改函数验证文件;
五、修改语言包文件。


一、修改数据库标题字段的长度为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;

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


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

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

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的74-80行

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的346-348行:

if(dstrlen($subject) > 80) {
return 'post_subject_toolong';
}

修改为:

if(dstrlen($subject) > 200) {
return 'post_subject_toolong';
}


五、修改语言包提示文字,打开 source/language/lang_message.php 找到985行:

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

修改为:

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

至此大功告成!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即註冊

本版积分规则

本版推荐主题

QQ|网站地图|小黑屋|Archiver|東里論壇 ( 粤ICP备14015598号 ) 公安备案图标粤公网安备 44512202000019号
GMT+8, 2024-4-20 10:44 , Processed in 0.120128 second(s), 58 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.