当前位置: 首页 > 图文教程 > 网络编程 > PHP > DISCUZ架构:积分系统代码分析三

PHP
MySQL手册版本 5.0.20-MySQL优化(四) (1)(3)
MySQL手册版本 5.0.20-MySQL优化(四) (1)(2)
Navicat MySQL图形客户端mac新版发布
MySQL手册版本 5.0.20-MySQL优化(四) (1)
MySQL手册版本 5.0.20-MySQL优化(二) (1)(4)
MySQL手册版本 5.0.20-MySQL优化(二) (1)(3)
MySQL手册版本 5.0.20-MySQL优化(二) (1)(2)
MySQL手册版本 5.0.20-MySQL优化(二) (1)
经验总结:mysql 的一些基本应用
如何在Windows上配置并整合PHP和MySQL(1)
如何在Windows上配置并整合PHP和MySQL(2)
程序员最容易犯的五个PHP数据库问题及解释
如何利用MySQL加密函数保护Web网站敏感数据
SQL Server日志文件总结及充满处理方式
用Apache Geronimo创建并部署blog和wiki 模块
对SQL数据库定期进行收缩 减小日志存储压力
从4.0到5.1 为什么MySQL却被冠名"玩具数据库"
在数据库中 如何进行分类分组并总计SQL信息
深入浅出举例应用 SQL数据库使用系列
实例:用触发器生成数据库表的数据操作日志

PHP 中的 DISCUZ架构:积分系统代码分析三


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 137 ::
收藏到网摘: n/a

3.下载附件积分增减

这一部分主要用到的就是attachment.php这个文件了,下面就来分析这个文件中与积分中有关系的代码:

以下为引用的内容:
if(!$isimage) {
        $forum['getattachcredits'] = $forum['getattachcredits'] ? unserialize($forum['getattachcredits']) : array();
        $getattachcredits = $forum['getattachcredits'] ? $forum['getattachcredits'] : $creditspolicy['getattach'];
        updatecredits($discuz_uid, $getattachcredits, -1);
}

这一段的意思是:当一个附件不是图像的时候,取出该论坛对于下载附件的积分设置,比方说是-5分,那么就调用updatecredits(global.func中定义)这个函数更新一下积分。

P.S.:相关函数分析:

updatepostcredits函数,定义于./include/post.func.php

以下为引用的内容:
function updatepostcredits($operator, $uidarray, $creditsarray) {
        global $db, $tablepre, $discuz_uid, $timestamp;

 

        $membersarray = $postsarray = array();
        foreach((is_array($uidarray) ? $uidarray : array($uidarray)) as $id) {
                $membersarray[intval(trim($id))]++;
        }
        foreach($membersarray as $uid => $posts) {
                $postsarray[$posts][] = $uid;
        }
        $lastpostadd = $uidarray == $discuz_uid ? ", lastpost='$timestamp'" : '';
        $creditsadd1 = '';
        if(is_array($creditsarray)) {
                foreach($creditsarray as $id => $addcredits) {
                        $creditsadd1 .= ", extcredits$id=extcredits$id$operator$addcredits*\$posts";
                }
        }
        foreach($postsarray as $posts => $uidarray) {
                $uids = implode(',', $uidarray);
                eval("\$creditsadd2 = \"$creditsadd1\";");
                $db->query("UPDATE {$tablepre}members SET posts=posts+('$operator$posts') $lastpostadd $creditsadd2 WHERE uid IN ($uids)", 'UNBUFFERED');
        }
}

可以看到这个函数有三个传入参数,$operator表示加还是减,$uidarray表示会员的id数组,$creditsarray表示要加减的积分数组。调用方法如:
以下为引用的内容:

updatepostcredits('+', 1, 1);

表示给uid为1的会员加1个积分