forked from XoopsModules25x/newbb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopicmanager.php
381 lines (361 loc) · 18.6 KB
/
topicmanager.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<?php
use Xmf\Request;
use XoopsModules\Newbb;
//
// ------------------------------------------------------------------------ //
// XOOPS - PHP Content Management System //
// Copyright (c) 2000-2016 XOOPS.org //
// <https://xoops.org/> //
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
// Author: phppp (D.J., [email protected]) //
// URL: https://xoops.org //
// Project: Article Project //
// ------------------------------------------------------------------------ //
require_once __DIR__ . '/header.php';
if (Request::getString('submit', '', 'POST')) {
foreach (['forum', 'newforum', 'newtopic'] as $getint) {
${$getint} = Request::getInt($getint, 0, 'POST'); // (int)(@$_POST[$getint]);
}
foreach (['topic_id'] as $getint) {
${$getint} = Request::getInt($getint, 0, 'POST'); // (int)(@$_POST[$getint]);
}
if (!is_array($topic_id)) {
$topic_id = [$topic_id];
}
} else {
foreach (['forum', 'topic_id'] as $getint) {
${$getint} = Request::getInt($getint, 0, 'GET'); // (int)(@$_GET[$getint]);
}
}
if (empty($topic_id)) {
$redirect = empty($forum_id) ? 'index.php' : 'viewforum.php?forum={$forum}';
$redirect = XOOPS_URL . '/modules/newbb/' . $redirect;
redirect_header($redirect, 2, _MD_NEWBB_ERRORTOPIC);
}
///** @var Newbb\TopicHandler $topicHandler */
//$topicHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Topic');
///** @var Newbb\ForumHandler $forumHandler */
//$forumHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Forum');
if (!$forum) {
/** @var Newbb\Topic $topicObject */
$topicObject = $topicHandler->get((int)$topic_id);
if (is_object($topicObject)) {
$forum = $topicObject->getVar('forum_id');
} else {
$redirect = XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $topic_id;
redirect_header($redirect, 2, _MD_NEWBB_FORUMNOEXIST);
}
unset($topicObject);
}
if ($GLOBALS['xoopsModuleConfig']['wol_enabled']) {
// /** @var Newbb\OnlineHandler $onlineHandler */
// $onlineHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Online');
$onlineHandler->init($forum);
}
// irmtfan add restore to viewtopic
$action_array = [
'merge',
'delete',
'restore',
'move',
'lock',
'unlock',
'sticky',
'unsticky',
'digest',
'undigest',
];
foreach ($action_array as $_action) {
$action[$_action] = [
'name' => $_action,
'desc' => constant(mb_strtoupper("_MD_NEWBB_DESC_{$_action}")),
'submit' => constant(mb_strtoupper("_MD_NEWBB_{$_action}")),
'sql' => "topic_{$_action}=1",
'msg' => constant(mb_strtoupper("_MD_NEWBB_TOPIC{$_action}")),
];
}
$action['lock']['sql'] = 'topic_status = 1';
$action['unlock']['sql'] = 'topic_status = 0';
$action['unsticky']['sql'] = 'topic_sticky = 0';
$action['undigest']['sql'] = 'topic_digest = 0';
$action['digest']['sql'] = 'topic_digest = 1, digest_time = ' . time();
// Disable cache
$GLOBALS['xoopsConfig']['module_cache'][$xoopsModule->getVar('mid')] = 0;
// irmtfan include header.php after defining $xoopsOption['template_main']
require_once $GLOBALS['xoops']->path('header.php');
if (Request::getString('submit', '', 'POST')) {
$mode = Request::getString('mode', '', 'POST'); // $_POST['mode'];
if ('delete' === $mode) {
foreach ($topic_id as $tid) {
$topicObject = $topicHandler->get($tid);
$topicHandler->delete($topicObject, false);
// irmtfan - sync topic after delete
$topicHandler->synchronization($topicObject);
$forumHandler->synchronization($forum);
//$topicObject->loadFilters("delete");
//sync($topic_id, "topic");
//xoops_notification_deletebyitem ($xoopsModule->getVar('mid'), 'thread', $topic_id);
}
// irmtfan full URL
echo $action[$mode]['msg'] . "<p><a href='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/viewforum.php?forum=$forum'>" . _MD_NEWBB_RETURNTOTHEFORUM . "</a></p><p><a href='index.php'>" . _MD_NEWBB_RETURNFORUMINDEX . '</a></p>';
} elseif ('restore' === $mode) {
//$topicHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Topic');
$forums = [];
$topicsObject = $topicHandler->getAll(new \Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN'));
foreach (array_keys($topicsObject) as $id) {
$topicObject = $topicsObject[$id];
$topicHandler->approve($topicObject);
$topicHandler->synchronization($topicObject);
$forums[$topicObject->getVar('forum_id')] = 1;
}
//irmtfan remove - no need to approve posts manually - see class/post.php approve function
$criteria_forum = new \Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN');
$forumsObject = $forumHandler->getAll($criteria_forum);
foreach (array_keys($forumsObject) as $id) {
$forumHandler->synchronization($forumsObject[$id]);
}
unset($topicsObject, $forumsObject);
// irmtfan add restore to viewtopic
$restoretopic_id = $topicObject->getVar('topic_id');
// irmtfan / missing in URL
echo $action[$mode]['msg']
. "<p><a href='"
. XOOPS_URL
. '/modules/'
. $xoopsModule->getVar('dirname')
. "/viewtopic.php?topic_id=$restoretopic_id'>"
. _MD_NEWBB_VIEWTHETOPIC
. '</a></p>'
. "<p><a href='"
. XOOPS_URL
. '/modules/'
. $xoopsModule->getVar('dirname')
. "/viewforum.php?forum=$forum'>"
. _MD_NEWBB_RETURNTOTHEFORUM
. '</a></p>'
. "<p><a href='index.php'>"
. _MD_NEWBB_RETURNFORUMINDEX
. '</a></p>';
} elseif ('merge' === $mode) {
// /** @var PostHandler $postHandler */
// $postHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Post');
// /** @var Newbb\RateHandler $rateHandler */
// $rateHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Rate');
foreach ($topic_id as $tid) {
$topicObject = $topicHandler->get($tid);
$newtopicObject = $topicHandler->get($newtopic);
/* return false if destination topic is not existing */
// irmtfan bug fix: the old topic will be deleted if user input a not exist new topic
if (!is_object($newtopicObject)) {
$redirect = XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $tid;
redirect_header($redirect, 2, _MD_NEWBB_ERRORTOPIC);
}
$criteria_topic = new \Criteria('topic_id', $tid);
$criteria = new \CriteriaCompo($criteria_topic);
$criteria->add(new \Criteria('pid', 0));
// irmtfan OR change to this for less query?:
// $postHandler->updateAll("pid", $newtopicObject->getVar("topic_last_post_id"), $criteria, true);
$postHandler->updateAll('pid', $topicHandler->getTopPostId($newtopic), $criteria, true);
$postHandler->updateAll('topic_id', $newtopic, $criteria_topic, true);
// irmtfan update vote data instead of deleting them
$rateHandler->updateAll('topic_id', $newtopic, $criteria_topic, true);
$topic_views = $topicObject->getVar('topic_views') + $newtopicObject->getVar('topic_views');
// irmtfan better method to update topic_views in new topic
//$criteria_newtopic = new \Criteria('topic_id', $newtopic);
//$topicHandler->updateAll('topic_views', $topic_views, $criteria_newtopic, true);
$newtopicObject->setVar('topic_views', $topic_views);
// START irmtfan poll_module and rewrite the method
// irmtfan only move poll in old topic to new topic if new topic has not a poll
$poll_id = $topicObject->getVar('poll_id');
if ($poll_id > 0 && (0 == $newtopicObject->getVar('poll_id'))) {
$newtopicObject->setVar('topic_haspoll', 1);
$newtopicObject->setVar('poll_id', $poll_id);
$poll_id = 0; // set to not delete the poll
$topicObject->setVar('topic_haspoll', 0); // set to not delete the poll
$topicObject->setVar('poll_id', 0); // set to not delete the poll
}
//update and sync newtopic after merge
//$topicHandler->insert($newtopicObject, true);
$topicHandler->synchronization($newtopicObject); // very important: only use object
//sync newforum after merge
$newforum = $newtopicObject->getVar('forum_id');
$forumHandler->synchronization($newforum);
//hardcode remove force to delete old topic from database
//$topicHandler->delete($topicObject,true); // cannot use this
$topicHandler->deleteAll($criteria_topic, true); // $force = true
//delete poll if old topic had a poll
$topicObject->deletePoll($poll_id);
//sync forum after delete old topic
$forumHandler->synchronization($forum);
// END irmtfan poll_module and rewrite the method
}
echo $action[$mode]['msg']
. // irmtfan full URL
"<p><a href='"
. XOOPS_URL
. '/modules/'
. $xoopsModule->getVar('dirname')
. "/viewtopic.php?topic_id=$newtopic'>"
. _MD_NEWBB_VIEWTHETOPIC
. '</a></p>'
. "<p><a href='"
. XOOPS_URL
. '/modules/'
. $xoopsModule->getVar('dirname')
. "/viewforum.php?forum=$forum'>"
. _MD_NEWBB_RETURNTOTHEFORUM
. '</a></p>'
. "<p><a href='"
. XOOPS_URL
. '/modules/'
. $xoopsModule->getVar('dirname')
. "/index.php'>"
. _MD_NEWBB_RETURNFORUMINDEX
. '</a></p>';
} elseif ('move' === $mode) {
if ($newforum > 0) {
$topic_id = $topic_id[0];
$topicObject = $topicHandler->get($topic_id);
$topicObject->loadFilters('update');
$topicObject->setVar('forum_id', $newforum, true);
$topicHandler->insert($topicObject, true);
$topicObject->loadFilters('update');
$sql = sprintf('UPDATE "%s" SET forum_id = "%u" WHERE topic_id = "%u"', $GLOBALS['xoopsDB']->prefix('newbb_posts'), $newforum, $topic_id);
if (!$r = $GLOBALS['xoopsDB']->query($sql)) {
return false;
}
$forumHandler->synchronization($forum);
$forumHandler->synchronization($newforum);
// irmtfan full URL
echo $action[$mode]['msg']
. "<p><a href='"
. XOOPS_URL
. '/modules/'
. $xoopsModule->getVar('dirname')
. "/viewtopic.php?topic_id=$topic_id&forum=$newforum'>"
. _MD_NEWBB_GOTONEWFORUM
. "</a></p><p><a href='"
. XOOPS_URL
. "/modules/newbb/index.php'>"
. _MD_NEWBB_RETURNFORUMINDEX
. '</a></p>';
} else {
// irmtfan - issue with javascript:history.go(-1)
redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERRORFORUM);
}
} else {
$topic_id = $topic_id[0];
$forum = $topicHandler->get($topic_id, 'forum_id');
$forum_new = !empty($newtopic) ? $topicHandler->get($newtopic, 'forum_id') : 0;
if (!$forumHandler->getPermission($forum, 'moderate')
|| (!empty($forum_new)
&& !$forumHandler->getPermission($forum_new, 'reply')) // The forum for the topic to be merged to
|| (!empty($newforum) && !$forumHandler->getPermission($newforum, 'post')) // The forum to be moved to
) {
redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?forum=$forum&topic_id=$topic_id", 2, _NOPERM);
}
if (!empty($action[$mode]['sql'])) {
$sql = sprintf('UPDATE `%s` SET ' . $action[$mode]['sql'] . ' WHERE topic_id = %u', $GLOBALS['xoopsDB']->prefix('newbb_topics'), $topic_id);
if (!$r = $GLOBALS['xoopsDB']->query($sql)) {
redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?forum=$forum&topic_id=$topic_id&order=$order&viewmode=$viewmode", 2, _MD_NEWBB_ERROR_BACK . '<br>sql: ' . $sql);
}
} else {
redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?forum=$forum&topic_id=$topic_id", 2, _MD_NEWBB_ERROR_BACK);
}
if ('digest' === $mode && $GLOBALS['xoopsDB']->getAffectedRows()) {
$topicObject = $topicHandler->get($topic_id);
// /** @var Newbb\StatsHandler $statsHandler */
// $statsHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Stats');
$statsHandler->update($topicObject->getVar('forum_id'), 'digest');
// /** @var Newbb\UserstatsHandler $userstatsHandler */
// $userstatsHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Userstats');
if ($user_stat = $userstatsHandler->get($topicObject->getVar('topic_poster'))) {
$z = $user_stat->getVar('user_digests') + 1;
$user_stat->setVar('user_digests', (int)$z);
$userstatsHandler->insert($user_stat);
}
}
// irmtfan full URL
echo $action[$mode]['msg']
. "<p><a href='"
. XOOPS_URL
. '/modules/'
. $xoopsModule->getVar('dirname')
. "/viewtopic.php?topic_id=$topic_id&forum=$forum'>"
. _MD_NEWBB_VIEWTHETOPIC
. "</a></p><p><a href='"
. XOOPS_URL
. "/modules/newbb/viewforum.php?forum=$forum'>"
. _MD_NEWBB_RETURNFORUMINDEX
. '</a></p>';
}
} else { // No submit
$mode = Request::getString('mode', '', 'GET'); //$_GET['mode'];
echo "<form action='" . Request::getString('PHP_SELF', '', 'SERVER') . "' method='post'>";
echo "<table border='0' cellpadding='1' cellspacing='0' align='center' width='95%'>";
echo "<tr><td class='bg2'>";
echo "<table border='0' cellpadding='1' cellspacing='1' width='100%'>";
echo "<tr class='bg3' align='left'>";
echo "<td colspan='2' align='center'>" . $action[$mode]['desc'] . '</td></tr>';
if ('move' === $mode) {
echo '<tr><td class="bg3">' . _MD_NEWBB_MOVETOPICTO . '</td><td class="bg1">';
$box = '<select name="newforum" size="1">';
// /** @var Newbb\CategoryHandler $categoryHandler */
// $categoryHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Category');
$categories = $categoryHandler->getByPermission('access');
$forums = $forumHandler->getForumsByCategory(array_keys($categories), 'post', false);
if (count($categories) > 0 && count($forums) > 0) {
foreach (array_keys($forums) as $key) {
/** @var Newbb\Category[] $categories */
$box .= "<option value='-1'>[" . $categories[$key]->getVar('cat_title') . ']</option>';
foreach ($forums[$key] as $forumid => $_forum) {
$box .= "<option value='" . $forumid . "'>-- " . $_forum['title'] . '</option>';
if (!isset($_forum['sub'])) {
continue;
}
foreach (array_keys($_forum['sub']) as $fid) {
$box .= "<option value='" . $fid . "'>---- " . $_forum['sub'][$fid]['title'] . '</option>';
}
}
}
} else {
$box .= "<option value='-1'>" . _MD_NEWBB_NOFORUMINDB . '</option>';
}
unset($forums, $categories);
echo $box;
echo '</select></td></tr>';
}
if ('merge' === $mode) {
echo '<tr><td class="bg3">' . _MD_NEWBB_MERGETOPICTO . '</td><td class="bg1">';
echo _MD_NEWBB_TOPIC . " ID-$topic_id -> ID: <input name='newtopic' value='' >";
echo '</td></tr>';
}
echo '<tr class="bg3"><td colspan="2" align="center">';
echo "<input type='hidden' name='mode' value='" . $action[$mode]['name'] . "' >";
echo "<input type='hidden' name='topic_id' value='" . $topic_id . "' >";
echo "<input type='hidden' name='forum' value='" . $forum . "' >";
echo "<input type='submit' name='submit' value='" . $action[$mode]['submit'] . "' >";
echo '</td></tr></form></table></td></tr></table>';
}
// irmtfan move to footer.php
require_once __DIR__ . '/footer.php';
require_once $GLOBALS['xoops']->path('footer.php');