magic_open.php
3.47 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
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: magic_open.php 29373 2012-04-09 07:55:30Z chenmengshu $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class magic_open {
var $version = '1.0';
var $name = 'open_name';
var $description = 'open_desc';
var $price = '10';
var $weight = '10';
var $targetgroupperm = true;
var $copyright = '<a href="http://www.comsenz.com" target="_blank">Comsenz Inc.</a>';
var $magic = array();
var $parameters = array();
function getsetting(&$magic) {
global $_G;
$settings = array(
'fids' => array(
'title' => 'open_forum',
'type' => 'mselect',
'value' => array(),
),
);
loadcache('forums');
$settings['fids']['value'][] = array(0, ' ');
if(empty($_G['cache']['forums'])) $_G['cache']['forums'] = array();
foreach($_G['cache']['forums'] as $fid => $forum) {
$settings['fids']['value'][] = array($fid, ($forum['type'] == 'forum' ? str_repeat(' ', 4) : ($forum['type'] == 'sub' ? str_repeat(' ', 8) : '')).$forum['name']);
}
$magic['fids'] = explode("\t", $magic['forum']);
return $settings;
}
function setsetting(&$magicnew, &$parameters) {
global $_G;
$magicnew['forum'] = is_array($parameters['fids']) && !empty($parameters['fids']) ? implode("\t",$parameters['fids']) : '';
$magicnew['expiration'] = intval($parameters['expiration']);
}
function usesubmit() {
global $_G;
if(empty($_GET['tid'])) {
showmessage(lang('magic/open', 'open_info_nonexistence'));
}
$thread = getpostinfo($_GET['tid'], 'tid', array('fid', 'authorid', 'subject'));
$this->_check($thread);
magicthreadmod($_GET['tid']);
C::t('forum_thread')->update($_GET['tid'], array('closed' => 0, 'moderated' => 1));
usemagic($this->magic['magicid'], $this->magic['num']);
updatemagiclog($this->magic['magicid'], '2', '1', '0', 0, 'tid', $_GET['tid']);
updatemagicthreadlog($_GET['tid'], $this->magic['magicid'], 'OPN');
if($thread['authorid'] != $_G['uid']) {
notification_add($thread['authorid'], 'magic', lang('magic/open', 'open_notification'), array('tid' => $_GET['tid'], 'subject' => $thread['subject'], 'magicname' => $this->magic['name']));
}
showmessage(lang('magic/open', 'open_succeed'), dreferer(), array(), array('alert' => 'right', 'showdialog' => 1, 'locationtime' => true));
}
function show() {
global $_G;
$tid = !empty($_GET['id']) ? dhtmlspecialchars($_GET['id']) : '';
if($tid) {
$thread = getpostinfo($_GET['id'], 'tid', array('fid', 'authorid'));
$this->_check($thread);
}
$this->parameters['expiration'] = $this->parameters['expiration'] ? intval($this->parameters['expiration']) : 24;
magicshowtype('top');
magicshowsetting(lang('magic/open', 'open_info', array('expiration' => $this->parameters['expiration'])), 'tid', $tid, 'text');
magicshowtype('bottom');
}
function buy() {
global $_G;
if(!empty($_GET['id'])) {
$thread = getpostinfo($_GET['id'], 'tid', array('fid', 'authorid'));
$this->_check($thread);
}
}
function _check($thread) {
if(!checkmagicperm($this->parameters['forum'], $thread['fid'])) {
showmessage(lang('magic/open', 'open_info_noperm'));
}
$member = getuserbyuid($thread['authorid']);
if(!checkmagicperm($this->parameters['targetgroups'], $member['groupid'])) {
showmessage(lang('magic/open', 'open_info_user_noperm'));
}
}
}
?>