echo | Discuz! | 2011 年 8 月 10 日
tools工具语言包的处理

//模板语言包处理 避免没有生产关于语言包缓存的时候英文
if(!file_exists('./data/plugindata/tools.lang.php')){
	require DISCUZ_ROOT.'./data/plugindata/tools.lang.'.CHARSET.'.php';
} else {
	require DISCUZ_ROOT.'./data/plugindata/tools.lang.php';
}
foreach($scriptlang['tools'] as $key => $value){
	$key = 'toolss_'.$key;
	$$key = $value;
}
foreach($templatelang['tools'] as $key => $value){
	$key = 'tools_'.$key;
	$$key = $value;
}
//模板语言包处理 end

echo | Discuz! | 2011 年 8 月 9 日
tag太多,导致发帖报错

昨天在为一个用户排查发帖报错时遇到如下错误:

Discuz! Database Error The database has encountered a problem. Need Help? Error messages:
[Type] 查询语句错误     [1062] Duplicate entry '65535' for key 1
[Query] INSERT INTO common_tag (tagname, status) VALUES ('通话时间', '0')
Program messages:
[Line: 0060]forum.php(require)
[Line: 0362]source/module/forum/forum_post.php(require_once)
[Line: 0621]source/include/post/post_editpost.php(modthreadtag)
 [Line: 0841]source/function/function_forum.php(DB::query)

去看了一下,原来是tags过多,自动增长的id超出了mysql默认的最大值,这里只要找到pre_common_tag表中,tagid的类型由smallint改为mediumint类型,长度/值改为8.增大一下默认的tag个数。

当然一般的网站可能不会有这么多的站,像手机站这种tag比较多的站点注意一下这个问题!

echo | Discuz! |
在上传文件之后安装之前校验文件的工具

<?php

if(!$discuzfiles = @file('./source/admincp/discuzfiles.md5')) {
	echo "source\admincp\discuzfiles.md5文件不存在,请上传!";
}
$md5data = array();
checkfiles('./', '', 0);
checkfiles('config/', '', 1, 'config_global.php,config_ucenter.php');
checkfiles('data/', '\.xml', 0);
checkfiles('data/avatar/', '\.htm', 0);
checkfiles('data/cache/', '\.htm', 0);
checkfiles('data/ipdata/', '\.htm|\.dat', 0);
checkfiles('data/template/', '\.htm', 0);
checkfiles('data/threadcache/', '\.htm', 0);
checkfiles('template/', '');
checkfiles('api/', '');
checkfiles('source/', '', 1, 'discuzfiles.md5,plugin');
checkfiles('static/', '');
checkfiles('archiver/', '');
checkfiles('uc_client/', '\.php|\.htm', 0);
checkfiles('uc_client/data/', '\.htm');
checkfiles('uc_client/control/', '\.php|\.htm');
checkfiles('uc_client/model/', '\.php|\.htm');
checkfiles('uc_client/lib/', '\.php|\.htm');
checkfiles('uc_server/', '\.php|\.htm|\.txt|\.xml', 0);
checkfiles('uc_server/data/', '\.htm');
checkfiles('uc_server/api/', '\.php|\.htm');
checkfiles('uc_server/control/', '\.php|\.htm|\.md5');
checkfiles('uc_server/model/', '\.php|\.htm');
checkfiles('uc_server/lib/', '\.php|\.htm');
checkfiles('uc_server/plugin/', '\.php|\.htm|\.xml');
checkfiles('uc_server/upgrade/', '\.php');
checkfiles('uc_server/images/', '\..+?');
checkfiles('uc_server/js/', '\.js|\.htm');
checkfiles('uc_server/release/', '\.php');
checkfiles('uc_server/view/', '\.php|\.htm');

foreach($discuzfiles as $line) {
	$file = trim(substr($line, 34));
	$md5datanew[$file] = substr($line, 0, 32);
	if($md5datanew[$file] != $md5data[$file]) {
		$modifylist[$file] = $md5data[$file];
	}
	$md5datanew[$file] = $md5data[$file];
}

$dellist = @array_diff_assoc($md5datanew, $md5data);
$modifylist = array_diff_assoc($modifylist, $dellist);
$num = count($dellist);
echo "<div style='float:left;'><h2>检查完毕,缺少".$num."个文件:</h2><br />";
foreach ($dellist as $names => $v) {	
	echo "<b>".$names."</b><br />";
}
if($names){
	echo "<br /><br />请上传上述文件,以确保站点正常运行!<br /><br /><br /></div>";
}
echo "<div style='float:left;margin-left:50px;'><h2>以下文件可能没有上传完整!</h2><br />";
foreach($modifylist as $lose => $vs){
	echo "<b>".$lose."</b><br />";
}
echo "<br /><br />请检查FTP工具或网络状况是否正常,然后重新上传这些文件。</div>";
function checkfiles($currentdir, $ext = '', $sub = 1, $skip = '') {
	global $md5data;
	$path = realpath('./');
	$dir = @opendir($path."/".$currentdir);
	$exts = '/('.$ext.')$/i';
	$skips = explode(',', $skip);

	while($entry = @readdir($dir)) {
		$file = $currentdir.$entry;
		if($entry != '.' && $entry != '..' && (($ext && preg_match($exts, $entry) || !$ext) || $sub && is_dir($file)) && !in_array($entry, $skips)) {
			if($sub && is_dir($file)) {
				checkfiles($file.'/', $ext, $sub, $skip);
			} else {
				if(is_dir($file)) {
					$md5data[$file] = md5($file);
				} else {
					$md5data[$file] = md5_file($file);
				}
			}
		}
	}
}
adds
?>
这个脚本保存后可以在上传文件之后安装之前校验文件。

echo | Discuz! | 2011 年 8 月 7 日
tools工具融合搬家向导模块

2011-07-27更新的tools工具包,融合进了“搬家向导”模块。该模块针对当前论坛诸多站长面临的问题—-论坛搬家,数据库迁移而推出,向导本身并不具体操作什么,只是按步骤提示站长,下一步要干什么了,必要时对一些步骤进行了检测,具体的操作,还是需要站长自己安装向导来完成。网站搬家,数据库迁移是经营网站经常遇见的情况,就是在搬家的过程中,往往会出现各种问题。

网站搬家简单来说就是数据的迁移,包括数据库,程序文件、附件等,移到新服务器中去,独立服务器由于权限大,数据库及文件打包就可以拷贝,唯独虚拟主机空间要稍微复杂点,因为他的数据库备份恢复依赖于安装,要安装好后,才能操作备份、恢复。 继续阅读 »

echo | Discuz! | 2011 年 8 月 5 日
接收或取消主题回帖提醒的功能分析

在Discuz!之前一系列版中,一直有个功能,叫关注此主题,一有回复,就会通知这些关注此主题的人,以短消息的方式。在Discuz!X系列中,只有主题的作者才有这个功能,接收或取消回复提醒。现在分析一下Discuz!X系列的这个功能,如果站长有兴趣,还可以依照这个思路去自己动手修改一番,未尝不可。

首先我们看看在模版中的代码:

<!--{if $thread['authorid'] == $_G['uid']}-->
        <span class="pipe">|</span>
	    <!--{if $replynotice == 1}-->
	            <a id="replynotice" href="forum.php?mod=misc&action=replynotice&op=ignore&tid=$_G[tid]" status="1" onclick="ajaxmenu(this, 3000, 0, 0, '43', function () {replyNotice();});return false;">{lang ignore_replynotice}</a>
	    <!--{else}-->
	            <a id="replynotice" href="forum.php?mod=misc&action=replynotice&op=receive&tid=$_G[tid]" status="0" onclick="ajaxmenu(this, 3000, 0, 0, '43', function () {replyNotice();});return false;">{lang receive_replynotice}</a>
            <!--{/if}-->
<!--{/if}-->

继续阅读 »

echo | Discuz! |
Discuz!强制上传头像后失败的原因分析

强制上传头像往往会作为站长防灌水和引导用户完善资料的手段,之前有部分站长提出自己的网站设置强制上传头像无效,上传头像后,依然提示需要上传。现在对这部分功能做一下分析,看看问题出在哪。

在后台,全局防灌水基本设置中,可以开启“强制新用户上传头像”,开启后,setting表中need_avatar字段的值变为“1”。这时新注册的用户如果需要进行发帖回复等操作,没进行头像上传的,应该会提示上传头像。例如进行发帖操作,会调用forum_post.php文件中的cknewuser();函数对用户进行验证,cknewuser();在function_core.php中定义,其中大约3160行有对头像的验证,我们看看验证的条件:

if($_G['setting']['need_avatar'] &&
 empty($ckuser['avatarstatus'])) {

if(empty($return)) showmessage('no_privilege_avatar', '', array(), array('return' => true));

$result
 = false;

}

继续阅读 »