task_promotion.php
1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: task_promotion.php 24735 2011-10-10 02:45:39Z svn_project_zhangjie $
 */
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
class task_promotion {
	var $version = '1.0';
	var $name = 'promotion_name';
	var $description = 'promotion_desc';
	var $copyright = '<a href="http://www.comsenz.com" target="_blank">Comsenz Inc.</a>';
	var $icon = '';
	var $period = '';
	var $periodtype = 0;
	var $conditions = array(
		'num' => array(
			'title' => 'promotion_complete_var_iplimit',
			'type' => 'text',
			'value' => '',
			'default' => 100,
			'sort' => 'complete',
		),
	);
	function preprocess($task) {
		global $_G;
		$promotions = C::t('forum_promotion')->count_by_uid($_G['uid']);
		C::t('forum_spacecache')->insert(array(
			'uid' => $_G['uid'],
			'variable' => 'promotion'.$task['taskid'],
			'value' => $promotions,
			'expiration' => $_G['timestamp'],
		), false, true);
	}
	function csc($task = array()) {
		global $_G;
		$promotion = C::t('forum_spacecache')->fetch($_G['uid'], 'promotion'.$task['taskid']);
		$promotion = $promotion['value'];
		$num = C::t('forum_promotion')->count_by_uid($_G['uid']) - $promotion;
		$numlimit = C::t('common_taskvar')->get_value_by_taskid($task['taskid'], 'num');
		if($num && $num >= $numlimit) {
			return TRUE;
		} else {
			return array('csc' => $num > 0 && $numlimit ? sprintf("%01.2f", $num / $numlimit * 100) : 0, 'remaintime' => 0);
		}
	}
	function sufprocess($task) {
		global $_G;
		C::t('forum_spacecache')->delete($_G['uid'], 'promotion'.$task['taskid']);
	}
}
?>