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

PHP
《PHP设计模式介绍》第十三章 适配器模式
《PHP设计模式介绍》第十四章 动态记录模式
《PHP设计模式介绍》第十五章 表数据网关模式
《PHP设计模式介绍》第十六章 数据映射模式
《PHP设计模式介绍》第十七章 MVC 模式
Zend Framework 入门——快速上手
Zend Framework 入门——多国语言支持
Zend Framework 入门——错误处理
Zend Framework 入门——页面布局
详细介绍php5编程中的异常处理
PHP5 OOP编程中的代理与异常
PHP程序的常见漏洞攻击分析
PHP.MVC的模板标签系统
PHP教程:PHP编码书写规范
PHP开发大型项目的方法:OOP思想
php使用curl模拟用户登陆
php对gb编码动态转utf-8编码的几种方法评测
php设计模式介绍之章代理模式
“在phpMyAdmin使用用户口令登陆”补充
PHP入门速成

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 190 ::
收藏到网摘: 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个积分