forked from XoopsModules25x/newbb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.post.php
227 lines (209 loc) · 9.87 KB
/
action.post.php
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php
/**
* NewBB 4.3x, the forum module for XOOPS project
*
* @copyright XOOPS Project (http://xoops.org)
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @author Taiwen Jiang (phppp or D.J.) <[email protected]>
* @since 4.00
* @package module::newbb
*/
include_once __DIR__ . '/header.php';
$topic_id = XoopsRequest::getInt('topic_id', 0, 'POST');
$post_id = XoopsRequest::getArray('post_id', XoopsRequest::getArray('post_id', 0, 'POST'), 'GET');
$uid = XoopsRequest::getInt('uid', 0, 'GET');
$op = XoopsRequest::getCmd('op', XoopsRequest::getCmd('op', '', 'POST'), 'GET');
$op = in_array($op, array('approve', 'delete', 'restore', 'split'), true) ? $op : '';
$mode = XoopsRequest::getInt('mode', 1, 'GET');
if (0 === count($post_id) || 0 === count($op)) {
// irmtfan - issue with javascript:history.go(-1)
redirect_header($_SERVER['HTTP_REFERER'], 2, _MD_NORIGHTTOACCESS);
}
$postHandler = xoops_getModuleHandler('post', 'newbb');
$topicHandler = xoops_getModuleHandler('topic', 'newbb');
$forumHandler = xoops_getModuleHandler('forum', 'newbb');
if (empty($topic_id)) {
$forum_obj = null;
} else {
$topic_obj = $topicHandler->get($topic_id);
$forum_id = $topic_obj->getVar('forum_id');
$forum_obj = $forumHandler->get($forum_id);
}
$isadmin = newbb_isAdmin($forum_obj);
if (!$isadmin) {
redirect_header(XOOPS_URL . '/index.php', 2, _MD_NORIGHTTOACCESS);
}
switch ($op) {
case 'restore':
$post_id = array_values($post_id);
sort($post_id);
$topics = array();
$forums = array();
foreach ($post_id as $post) {
$post_obj = $postHandler->get($post);
if ($post_obj->getVar('topic_id') < 1) {
continue;
}
$postHandler->approve($post_obj, true);
$topics[$post_obj->getVar('topic_id')] = 1;
$forums[$post_obj->getVar('forum_id')] = 1;
unset($post_obj);
}
foreach (array_keys($topics) as $topic) {
$topicHandler->synchronization($topic);
}
foreach (array_keys($forums) as $forum) {
$forumHandler->synchronization($forum);
}
break;
case 'approve':
$post_id = array_values($post_id);
sort($post_id);
$topics = array();
$forums = array();
$criteria = new Criteria('post_id', '(' . implode(',', $post_id) . ')', 'IN');
$posts_obj =& $postHandler->getObjects($criteria, true);
foreach ($post_id as $post) {
$post_obj = $posts_obj[$post];
if (!empty($topic_id) && $topic_id !== $post_obj->getVar('topic_id')) {
continue;
}
$postHandler->approve($post_obj);
$topics[$post_obj->getVar('topic_id')] = $post;
$forums[$post_obj->getVar('forum_id')] = 1;
}
foreach (array_keys($topics) as $topic) {
$topicHandler->synchronization($topic);
}
foreach (array_keys($forums) as $forum) {
$forumHandler->synchronization($forum);
}
if (empty($GLOBALS['xoopsModuleConfig']['notification_enabled'])) {
break;
}
$criteria_topic = new Criteria('topic_id', '(' . implode(',', array_keys($topics)) . ')', 'IN');
$topic_list = $topicHandler->getList($criteria_topic, true);
$criteria_forum = new Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN');
$forum_list = $forumHandler->getList($criteria_forum);
include_once __DIR__ . '/include/notification.inc.php';
$notificationHandler = xoops_getHandler('notification');
foreach ($post_id as $post) {
$tags = array();
$tags['THREAD_NAME'] = $topic_list[$posts_obj[$post]->getVar('topic_id')];
$tags['THREAD_URL'] = XOOPS_URL
. '/modules/'
. $xoopsModule->getVar('dirname')
. '/viewtopic.php?topic_id='
. $posts_obj[$post]->getVar('topic_id')
. '&forum='
. $posts_obj[$post]->getVar('forum_id');
$tags['FORUM_NAME'] = $forum_list[$posts_obj[$post]->getVar('forum_id')];
$tags['FORUM_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewforum.php?forum=' . $posts_obj[$post]->getVar('forum_id');
$tags['POST_URL'] = $tags['THREAD_URL'] . '#forumpost' . $post;
$notificationHandler->triggerEvent('thread', $posts_obj[$post]->getVar('topic_id'), 'new_post', $tags);
$notificationHandler->triggerEvent('forum', $posts_obj[$post]->getVar('forum_id'), 'new_post', $tags);
$notificationHandler->triggerEvent('global', 0, 'new_post', $tags);
$tags['POST_CONTENT'] = $posts_obj[$post]->getVar('post_text');
$tags['POST_NAME'] = $posts_obj[$post]->getVar('subject');
$notificationHandler->triggerEvent('global', 0, 'new_fullpost', $tags);
$notificationHandler->triggerEvent('forum', $posts_obj[$post]->getVar('forum_id'), 'new_fullpost', $tags);
}
break;
case 'delete':
$post_id = array_values($post_id);
rsort($post_id);
$topics = array();
$forums = array();
foreach ($post_id as $post) {
$post_obj = $postHandler->get($post);
if (!empty($topic_id) && $topic_id !== $post_obj->getVar('topic_id')) {
continue;
}
$topics[$post_obj->getVar('topic_id')] = 1;
$forums[$post_obj->getVar('forum_id')] = 1;
$postHandler->delete($post_obj, true);
unset($post_obj);
}
foreach (array_keys($topics) as $topic) {
$topicHandler->synchronization($topic);
}
foreach (array_keys($forums) as $forum) {
$forumHandler->synchronization($forum);
}
break;
case 'split':
$post_obj =& $postHandler->get($post_id);
if (0 === count($post_id) || $post_obj->isTopic()) {
break;
}
$topic_id = $post_obj->getVar('topic_id');
$newtopic = $topicHandler->create();
$newtopic->setVar('topic_title', $post_obj->getVar('subject'), true);
$newtopic->setVar('topic_poster', $post_obj->getVar('uid'), true);
$newtopic->setVar('forum_id', $post_obj->getVar('forum_id'), true);
$newtopic->setVar('topic_time', $post_obj->getVar('post_time'), true);
$newtopic->setVar('poster_name', $post_obj->getVar('poster_name'), true);
$newtopic->setVar('approved', 1, true);
$topicHandler->insert($newtopic, true);
$new_topic_id = $newtopic->getVar('topic_id');
$pid = $post_obj->getVar('pid');
$post_obj->setVar('topic_id', $new_topic_id, true);
$post_obj->setVar('pid', 0, true);
$postHandler->insert($post_obj);
/* split a single post */
if ($mode === 1) {
$criteria = new CriteriaCompo(new Criteria('topic_id', $topic_id));
$criteria->add(new Criteria('pid', $post_id));
$postHandler->updateAll('pid', $pid, $criteria, true);
/* split a post and its children posts */
} elseif ($mode === 2) {
include_once $GLOBALS['xoops']->path('class/xoopstree.php');
$mytree = new XoopsTree($GLOBALS['xoopsDB']->prefix('bb_posts'), 'post_id', 'pid');
$posts = $mytree->getAllChildId($post_id);
if (count($posts) > 0) {
$criteria = new Criteria('post_id', '(' . implode(',', $posts) . ')', 'IN');
$postHandler->updateAll('topic_id', $new_topic_id, $criteria, true);
}
/* split a post and all posts coming after */
} elseif ($mode === 3) {
$criteria = new CriteriaCompo(new Criteria('topic_id', $topic_id));
$criteria->add(new Criteria('post_id', $post_id, '>'));
$postHandler->updateAll('topic_id', $new_topic_id, $criteria, true);
unset($criteria);
$criteria = new CriteriaCompo(new Criteria('topic_id', $new_topic_id));
$criteria->add(new Criteria('post_id', $post_id, '>'));
$postHandler->identifierName = 'pid';
$posts = $postHandler->getList($criteria);
unset($criteria);
$post_update = array();
foreach ($posts as $postid => $pid) {
// if (!in_array($pid, array_keys($posts))) {
if (!array_key_exists($pid, $posts)) {
$post_update[] = $pid;
}
if (!array_key_exists($pid, $posts)) {
$post_update2[] = $pid;
}
}
if (count($post_update)) {
$criteria = new Criteria('post_id', '(' . implode(',', $post_update) . ')', 'IN');
$postHandler->updateAll('pid', $post_id, $criteria, true);
}
}
$forum_id = $post_obj->getVar('forum_id');
$topicHandler->synchronization($topic_id);
$topicHandler->synchronization($new_topic_id);
$sql = sprintf('UPDATE %s SET forum_topics = forum_topics+1 WHERE forum_id = %u', $GLOBALS['xoopsDB']->prefix('bb_forums'), $forum_id);
$result = $GLOBALS['xoopsDB']->queryF($sql);
break;
}
if (!empty($topic_id)) {
redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id=$topic_id", 2, _MD_DBUPDATED);
} elseif (!empty($forum_id)) {
redirect_header(XOOPS_URL . "/modules/newbb/viewforum.php?forum=$forum_id", 2, _MD_DBUPDATED);
} else {
redirect_header(XOOPS_URL . "/modules/newbb/viewpost.php?uid=$uid", 2, _MD_DBUPDATED);
}
// irmtfan move to footer.php
include_once __DIR__ . '/footer.php';
include $GLOBALS['xoops']->path('footer.php');