Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

X2千斤顶道具代码作用分析

[复制链接]
vinsonwang 发表于 2011-3-14 11:04:08 | 显示全部楼层 |阅读模式
*************************************************
** 本教程基于版本:Discuz! X 2.0 **
*************************************************
X2中新增道具“千斤顶”,顾名思义,对帖子起到提升作用的,可以将主题顶起一段时间,重复使用可延长帖子被顶起的时间。这对论坛帖子的关注度方面,做了很友好的改善,下面分析一下道具“千斤顶”对帖子起到提升作用的代码部分。
X2中,道具都各自封装为一个类,道具“千斤顶”被封装在 source\class\magic\magic_jack.php 中。那么,千斤顶道具是怎么实主题提升的呢?具体见代码:
  1. function usesubmit() {
  2.                 global $_G;
  3.                 if(empty($_G['gp_tid'])) {
  4.                         showmessage(lang('magic/jack', 'jack_info_nonexistence'));
  5.                 }

  6.                 $thread = getpostinfo($_G['gp_tid'], 'tid', array('fid', 'authorid', 'subject', 'lastpost'));
  7.                 $this->_check($thread['fid']);
  8.                 magicthreadmod($_G['gp_tid']);

  9.                 $this->parameters['expiration'] = $this->parameters['expiration'] ? intval($this->parameters['expiration']) : 1;
  10.                 $magicnum = intval($_G['gp_magicnum']);
  11.                 if(empty($magicnum) || $magicnum > $this->magic['num']) {
  12.                         showmessage(lang('magic/jack', 'jack_num_not_enough'));
  13.                 }
  14.                 $expiration = ($thread['lastpost'] > TIMESTAMP ? $thread['lastpost'] : TIMESTAMP) + $this->parameters['expiration'] * $magicnum * 3600;
  15.                 DB::query("UPDATE ".DB::table('forum_thread')." SET lastpost='$expiration' WHERE tid='$_G[gp_tid]'");

  16.                 usemagic($this->magic['magicid'], $this->magic['num'], $magicnum);
  17.                 updatemagiclog($this->magic['magicid'], '2', $magicnum, '0', 0, 'tid', $_G['gp_tid']);

  18.                 if($thread['authorid'] != $_G['uid']) {
  19.                         notification_add($thread['authorid'], 'magic', lang('magic/jack', 'jack_notification'), array('tid' => $_G['gp_tid'], 'subject' => $thread['subject'], 'magicname' => $this->magic['name']));
  20.                 }
  21.                 showmessage(lang('magic/jack', 'jack_succeed'), dreferer(), array(), array('showdialog' => 1, 'locationtime' => true));
  22.         }
复制代码
函数 usesubmit() 即是起到关键作用的一个环节,首先 global $_G 引进全局变量,接着判断 $_G['gp_tid'] 是否为空,如果为空,即没有选择相应主题帖实施道具,getpostinfo 这个是获取对象主题的相关信息,_check 是检查这个版块是否允许使用“千斤顶”道具,magicthreadmod 是查看此帖是否已被版主操作,否则禁止使用该道具。magicnum 是查看道具数量是否够用,$expiration 查看当前主题的 lastpost 是否大过当前时间戳,如果是,则不变,如果不是,则 $expiration 乘以道具个数在乘以 3600 秒,update 进数据库表,if($thread['authorid'] != $_G['uid']) 这个就是看此道具是否为主题作者使用的,如果不是,则对原作者做通知,最后showmessage函数提示设置主题成功,并刷新,跳转。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-6-26 19:49 , Processed in 0.090916 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

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