是这样一个过程,发帖的时候前台看到的文件是:post.php,
然后引用如下文件:
include/common.inc.php DZ通用函数库
include/post.func.php 发帖用到的函数库
include/discuzcode.func.php 解析Discuz Code用到的
接下来跟据传入的action判断引用到哪个文件继续处理
include/newthread.inc.php(新帖)
include/newreply.inc.php(回复)
include/supesite_import.inc.php(导入到supersite)
这个文件是发新帖,回复,投票都会用到的,所以它的作用就是初始化一些全局的东西,我就不全文件分析了,只分析一些与积分有关的部分。
- $postcredits = $forum['postcredits'] ? $forum['postcredits'] : $creditspolicy['post'];
- $replycredits = $forum['replycredits'] ? $forum['replycredits'] : $creditspolicy['reply'];
- $digestcredits = $forum['digestcredits'] ? $forum['digestcredits'] : $creditspolicy['digest'];
- $postattachcredits = $forum['postattachcredits'] ? $forum['postattachcredits'] : $creditspolicy['postattach'];
复制代码
这一部分的作用就是取出当前论坛的一些积分设置,和我们前面分析的数据表cdb_forumfields对应,得到会员发帖,回复等加多少分。
这个文件处理发新帖的特定请求。
- if(isset($poll)) {
- $special = 1;
- } elseif(isset($trade)) {
- $special = 2;
- } elseif(isset($reward)) {
- $special = 3;
- } elseif(isset($activity)) {
- $special = 4;
- } else {
- $special = 0;
- }
复制代码
这一部分的代码是用来判断帖子的类型的,1为投票,2为交易帖,3为悬赏,4为活动,0为普通帖。
- $price = intval($price);
- $price = $maxprice && !$special ? ($price <= $maxprice ? $price : $maxprice) : 0;
复制代码
这里是帖子价格的赋值,超过了最大的价格的处理,特殊帖子的价格处理。
- } elseif($special == 3 && $allowpostreward) {
- $rewardprice = intval($rewardprice);
- if(!$rewardprice) {
- showmessage('reward_credits_please');
- } elseif($rewardprice > 32767) {
- showmessage('reward_credits_overflow');
- } elseif($rewardprice < $minrewardprice || ($maxrewardprice > 0 && $rewardprice > $maxrewardprice)) {
- showmessage('reward_credits_between');
- } elseif(($realprice = $rewardprice + ceil($rewardprice * $creditstax)) > $_DSESSION["extcredits$creditstrans"]) {
- showmessage('reward_credits_shortage');
- }
- $price = $rewardprice;
- $db->query("UPDATE {$tablepre}members SET extcredits$creditstrans=extcredits$creditstrans-$realprice WHERE uid='$discuz_uid'");
复制代码
前面说过3表示悬赏帖子,那么当你发表成功了一个悬赏帖子后,就会相应在cdb_members表中减少相应的扩展积分,便是上面的代码的作用了。
- elseif($special == 3 && $allowpostreward) {
- $db->query("INSERT INTO {$tablepre}rewardlog (tid, authorid, netamount, dateline) VALUES ('$tid', '$discuz_uid', $realprice, '$timestamp')");
- }
复制代码
后续判断如果为悬赏帖子的话就往cdb_rewardlog(悬赏记录表)里写入一条记录。
- if($attachment) {
- $searcharray = $pregarray = $replacearray = array();
- foreach($attachments as $key => $attach) {
- $db->query("INSERT INTO {$tablepre}attachments (tid, pid, dateline, readperm, price, filename, description, filetype, filesize, attachment, downloads, isimage, uid, thumb, remote)
- VALUES ('$tid', '$pid', '$timestamp', '$attach[perm]', '$attach[price]', '$attach[name]', '$attach[description]', '$attach[type]', '$attach[size]', '$attach[attachment]', '0', '$attach[isimage]', '$attach[uid]', '$attach[thumb]', '$attach[remote]')");
- $searcharray[] = '[local]'.$localid[$key].'[/local]';
- $pregarray[] = '/\[localimg=(\d{1,3}),(\d{1,3})\]'.$localid[$key].'\[\/localimg\]/is';
- $replacearray[] = '[attach]'.$db->insert_id().'[/attach]';
- }
- $message = str_replace($searcharray, $replacearray, preg_replace($pregarray, $replacearray, $message));
- $db->query("UPDATE {$tablepre}posts SET message='$message' WHERE pid='$pid'");
- updatecredits($discuz_uid, $postattachcredits, count($attachments));
- }
复制代码
如果帖子中带有附件的话,就把附件插入cdb_attachments表,然后注意到$message这一个变量在这里用到了替换,这里的作用是图文混排。接下来往cdb_posts写一条记录,再用include/global.func.php定义到一个函数updatecredits来更新积分。
给Discuz的一个小建议:可以判断是不是postattachcredits为0,为0就可以不执行updatecredits这个函数,虽然在函数定义的时候也有判断,不过在这里判断似乎更好。
- if($modnewthreads) {
- $db->query("UPDATE {$tablepre}forums SET todayposts=todayposts+1 WHERE fid='$fid'", 'UNBUFFERED');
- $allowuseblog && $isblog && $blog ? showmessage('post_newthread_mod_blog_succeed', "blog.php?uid=$discuz_uid") :
- showmessage('post_newthread_mod_succeed', "forumdisplay.php?fid=$fid");
- } else {
- if($digest) {
- foreach($digestcredits as $id => $addcredits) {
- $postcredits[$id] = (isset($postcredits[$id]) ? $postcredits[$id] : 0) + $addcredits;
- }
- }
- updatepostcredits('+', $discuz_uid, $postcredits);
- $lastpost = "$tid\t$subject\t$timestamp\t$author";
- $db->query("UPDATE {$tablepre}forums SET lastpost='$lastpost', threads=threads+1, posts=posts+1, todayposts=todayposts+1 WHERE fid='$fid'", 'UNBUFFERED');
- if($forum['type'] == 'sub') {
- $db->query("UPDATE {$tablepre}forums SET lastpost='$lastpost' WHERE fid='$forum[fup]'", 'UNBUFFERED');
- }
- if($allowuseblog && $isblog && $blog) {
- showmessage('post_newthread_blog_succeed', "blog.php?tid=$tid");
- } else {
- showmessage('post_newthread_succeed', "viewthread.php?tid=$tid&extra=$extra");
- }
- }
复制代码
这里是最后一段代码,作用是这样的:
首先看看是不是在发新帖的时候就被加为文集
- 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个积分
欢迎光临 纳速健身 (https://nasue.com/) | Powered by Discuz! X3.4 |