查看: 82|回复: 0

[Discuz教程] Discuz! 建站技巧-解决帖子标题80个字符的限制

[复制链接]

1569

主题

6

回帖

1万

积分

管理员

Rank: 9

积分
13770
发表于 2023-11-16 11:06:43 | 显示全部楼层 |阅读模式
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]" style="width: 25em" tabindex="1" /></span>
<!–{else}–>
<span id="subjecthide" class="z">RE: $thread[subject] [<a href="javascript:;">{lang modify}</a>]</span>
<span id="subjectbox" style="display:none"><input type="text" name="subject" id="subject" class="px" value="" style="width: 25em" /></span>

修改为

<span><input type="text" name="subject" id="subject" class="px" value="$postinfo[subject]" style="width: 50em" tabindex="1" /></span>
<!–{else}–>
<span id="subjecthide" class="z">RE: $thread[subject] [<a href="javascript:;">{lang modify}</a>]</span>
<span id="subjectbox" style="display:none"><input type="text" name="subject" id="subject" class="px" value="" style="width: 50em" /></span>



混沌资源社区- 论坛版权- 免责声明
1、本主题所有言论和图片纯属会员个人意见,与本站立场无关
2、本站的所有内容都不保证其准确性,有效性,完整性,时间性,凡因本站内容引起误导等因素而造成的损失本站不承担连带责任。
3、本站所有主题由该帖子作者发表,该帖子作者与本站享有帖子相关版权
4、其他单位或个人使用、转载或引用本文时必须同时征得该帖子作者和本站的同意
5、本站发布的所有资源(包括动漫作品.文字.图片.FLASH.动画及各种软件工具)只为本地单机测试用途,请勿用于商业途径或非法使用,否则后果自负!请下载后24小时内删除!
6、本站管理员和版主有权不事先通知发贴者而删除本文
7、如您认为本文内容侵犯了您的权益,请与我们联系!我们将及时予与删除并致以最深的歉意!同时本站保留全部修改、解释、更新本声明的权利
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表