task_member.php
4.38 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: task_member.php 26595 2011-12-16 03:50:07Z svn_project_zhangjie $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class task_member {
var $version = '1.0';
var $name = 'member_name';
var $description = 'member_desc';
var $copyright = '<a href="http://www.comsenz.com" target="_blank">Comsenz Inc.</a>';
var $icon = '';
var $period = '';
var $periodtype = 0;
var $conditions = array(
'act' => array(
'title' => 'member_complete_var_act',
'type' => 'mradio',
'value' => array(
array('favorite', 'member_complete_var_act_favorite'),
array('magic', 'member_complete_var_act_magic'),
array('userapp', 'member_complete_var_act_userapp'),
),
'default' => 'favorite',
'sort' => 'complete',
),
'num' => array(
'title' => 'member_complete_var_num',
'type' => 'text',
'value' => '',
'sort' => 'complete',
),
'time' => array(
'title' => 'member_complete_var_time',
'type' => 'text',
'value' => '',
'sort' => 'complete',
)
);
function preprocess($task) {
global $_G;
$act = C::t('common_taskvar')->get_value_by_taskid($task['taskid'], 'act');
if($act == 'favorite') {
$value = C::t('home_favorite')->count_by_uid_idtype($_G['uid'], 'tid');
C::t('forum_spacecache')->insert(array(
'uid' => $_G['uid'],
'variable' => 'favorite'.$task['taskid'],
'value' => $value,
'expiration' => $_G['timestamp'],
), false, true);
} elseif($act == 'userapp') {
$num = C::t('home_userapp')->count_by_uid($_G['uid']);
C::t('forum_spacecache')->insert(array(
'uid' => $_G['uid'],
'variable' => 'userapp'.$task['taskid'],
'value' => $num,
'expiration' => $_G['timestamp'],
), false, true);
}
}
function csc($task = array()) {
global $_G;
$taskvars = array('num' => 0);
$num = 0;
foreach(C::t('common_taskvar')->fetch_all_by_taskid($task['taskid']) as $taskvar) {
if($taskvar['value']) {
$taskvars[$taskvar['variable']] = $taskvar['value'];
}
}
$taskvars['time'] = floatval($taskvars['time']);
if($taskvars['act'] == 'favorite') {
$favorite = C::t('forum_spacecache')->fetch($_G['uid'], 'favorite'.$task['taskid']);
$favorite = $favorite['value'];
$num = C::t('home_favorite')->count_by_uid_idtype($_G['uid'], 'tid') - $favorite;
} elseif($taskvars['act'] == 'magic') {
$maxtime = $taskvars['time'] ? $task['applytime']+3600*$taskvars['time'] : 0;
$num = C::t('common_magiclog')->count_by_action_uid_dateline(2, $_G['uid'], $task['applytime'], $maxtime);
} elseif($taskvars['act'] == 'userapp') {
$userapp = C::t('forum_spacecache')->fetch($_G['uid'], 'userapp'.$task['taskid']);
$userapp = $userapp['value'];
$num = C::t('home_userapp')->count_by_uid($_G['uid']) - $userapp;
}
if($num && $num >= $taskvars['num']) {
if($taskvars['act'] == 'favorite' || $taskvars['act'] == 'userapp') {
C::t('forum_spacecache')->delete($_G['uid'], $taskvars['act'].$task['taskid']);
}
return TRUE;
} elseif($taskvars['time'] && TIMESTAMP >= $task['applytime'] + 3600 * $taskvars['time'] && (!$num || $num < $taskvars['num'])) {
return FALSE;
} else {
return array('csc' => $num > 0 && $taskvars['num'] ? sprintf("%01.2f", $num / $taskvars['num'] * 100) : 0, 'remaintime' => $taskvars['time'] ? $task['applytime'] + $taskvars['time'] * 3600 - TIMESTAMP : 0);
}
}
function view($task, $taskvars) {
$return = lang('task/member', 'task_complete_time_start');
if($taskvars['complete']['time']) {
$return .= lang('task/member', 'task_complete_time_limit', array('value' => $taskvars['complete']['time']['value']));
}
$taskvars['complete']['num']['value'] = intval($taskvars['complete']['num']['value']);
if($taskvars['complete']['act']['value'] == 'favorite') {
$return .= lang('task/member', 'task_complete_act_favorite', array('value' => $taskvars['complete']['num']['value']));
} elseif($taskvars['complete']['act']['value'] == 'userapp') {
$return .= lang('task/member', 'task_complete_act_userapp', array('value' => $taskvars['complete']['num']['value']));
} else {
$return .= lang('task/member', 'task_complete_act_magic', array('value' => $taskvars['complete']['num']['value']));
}
return $return;
}
}
?>