forked from XoopsModules25x/newbb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.topic.php
179 lines (167 loc) · 8.86 KB
/
action.topic.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
<?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';
$forum_id = XoopsRequest::getInt('forum_id', 0, 'POST');
$topic_id = XoopsRequest::getArray('topic_id', null, 'POST');
$op = XoopsRequest::getCmd('op', '', 'POST');
$op = in_array($op, array('approve', 'delete', 'restore', 'move'), true) ? $op : '';
if (0 === count($topic_id) || 0 === count($op)) {
// irmtfan - issue with javascript:history.go(-1)
redirect_header($_SERVER['HTTP_REFERER'], 2, _MD_NORIGHTTOACCESS);
}
$topic_id = array_values($topic_id);
$topicHandler = xoops_getModuleHandler('topic', 'newbb');
$forumHandler = xoops_getModuleHandler('forum', 'newbb');
$isadmin = newbb_isAdmin($forum_id);
if (!$isadmin) {
redirect_header(XOOPS_URL . '/index.php', 2, _MD_NORIGHTTOACCESS);
}
switch ($op) {
case 'restore':
$forums = array();
$topics_obj = $topicHandler->getAll(new Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN'));
foreach (array_keys($topics_obj) as $id) {
$topic_obj =& $topics_obj[$id];
$topicHandler->approve($topic_obj);
$topicHandler->synchronization($topic_obj);
$forums[$topic_obj->getVar('forum_id')] = 1;
}
$criteria_forum = new Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN');
$forums_obj = $forumHandler->getAll($criteria_forum);
foreach (array_keys($forums_obj) as $id) {
$forumHandler->synchronization($forums_obj[$id]);
}
unset($topics_obj, $forums_obj);
break;
case 'approve':
$forums = array();
$topics_obj = $topicHandler->getAll(new Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN'));
foreach (array_keys($topics_obj) as $id) {
$topic_obj =& $topics_obj[$id];
$topicHandler->approve($topic_obj);
$topicHandler->synchronization($topic_obj);
$forums[$topic_obj->getVar('forum_id')] = 1;
}
$criteria_forum = new Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN');
$forums_obj = $forumHandler->getAll($criteria_forum);
foreach (array_keys($forums_obj) as $id) {
$forumHandler->synchronization($forums_obj[$id]);
}
if (empty($GLOBALS['xoopsModuleConfig']['notification_enabled'])) {
break;
}
include_once __DIR__ . '/include/notification.inc.php';
$notificationHandler = xoops_getHandler('notification');
foreach (array_keys($topics_obj) as $id) {
$topic_obj =& $topics_obj[$id];
$tags = array();
$tags['THREAD_NAME'] = $topic_obj->getVar('topic_title');
$tags['THREAD_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?topic_id=' . $id . '&forum=' . $topic_obj->getVar('forum_id');
$tags['FORUM_NAME'] = $forums_obj[$topic_obj->getVar('forum_id')]->getVar('forum_name');
$tags['FORUM_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewforum.php?forum=' . $topic_obj->getVar('forum_id');
$notificationHandler->triggerEvent('global', 0, 'new_thread', $tags);
$notificationHandler->triggerEvent('forum', $topic_obj->getVar('forum_id'), 'new_thread', $tags);
$post_obj = $topicHandler->getTopPost($id);
$tags['POST_URL'] = $tags['THREAD_URL'] . '#forumpost' . $post_obj->getVar('post_id');
$notificationHandler->triggerEvent('thread', $id, 'new_post', $tags);
$notificationHandler->triggerEvent('forum', $topic_obj->getVar('forum_id'), 'new_post', $tags);
$notificationHandler->triggerEvent('global', 0, 'new_post', $tags);
$tags['POST_CONTENT'] = $post_obj->getVar('post_text');
$tags['POST_NAME'] = $post_obj->getVar('subject');
$notificationHandler->triggerEvent('global', 0, 'new_fullpost', $tags);
$notificationHandler->triggerEvent('forum', $topic_obj->getVar('forum_id'), 'new_fullpost', $tags);
unset($post_obj);
}
unset($topics_obj, $forums_obj);
break;
case 'delete':
$forums = array();
$topics_obj = $topicHandler->getAll(new Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN'));
foreach (array_keys($topics_obj) as $id) {
$topic_obj =& $topics_obj[$id];
// irmtfan should be set to false to not delete topic from database
$topicHandler->delete($topic_obj, false);
$topicHandler->synchronization($topic_obj);
$forums[$topic_obj->getVar('forum_id')] = 1;
}
$criteria_forum = new Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN');
$forums_obj = $forumHandler->getAll($criteria_forum);
foreach (array_keys($forums_obj) as $id) {
$forumHandler->synchronization($forums_obj[$id]);
}
unset($topics_obj, $forums_obj);
break;
case 'move':
if (XoopsRequest::getInt('newforum', 0, 'POST')
&& XoopsRequest::getInt('newforum', 0, 'POST') !== $forum_id
&& $forumHandler->getPermission(XoopsRequest::getInt('newforum', 0, 'POST'), 'post')
) {
$criteria = new Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN');
$postHandler = xoops_getModuleHandler('post', 'newbb');
$postHandler->updateAll('forum_id', XoopsRequest::getInt('newforum', 0, 'POST'), $criteria, true);
$topicHandler->updateAll('forum_id', XoopsRequest::getInt('newforum', 0, 'POST'), $criteria, true);
$forumHandler->synchronization(XoopsRequest::getInt('newforum', 0, 'POST'));
$forumHandler->synchronization($forum_id);
} else {
include $GLOBALS['xoops']->path('header.php');
$categoryHandler = xoops_getModuleHandler('category', 'newbb');
$categories = $categoryHandler->getByPermission('access');
$forums = $forumHandler->getForumsByCategory(array_keys($categories), 'post', false);
$box = '<select name="newforum" size="1">';
if (count($categories) > 0 && count($forums) > 0) {
foreach (array_keys($forums) as $key) {
$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_NOFORUMINDB . '</option>';
}
$box .= '</select>';
unset($forums, $categories);
echo "<form action='" . XoopsRequest::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><td class="bg3">' . _MD_MOVETOPICTO . '</td><td class="bg1">';
echo $box;
echo '</td></tr>';
echo '<tr class="bg3"><td colspan="2" align="center">';
echo "<input type='hidden' name='op' value='move' />";
echo "<input type='hidden' name='forum_id' value='{$forum_id}' />";
foreach ($topic_id as $id) {
echo "<input type='hidden' name='topic_id[]' value='" . $id . "' />";
}
echo "<input type='submit' name='submit' value='" . _SUBMIT . "' />";
echo '</td></tr></table></td></tr></table>';
echo '</form>';
include $GLOBALS['xoops']->path('footer.php');
exit();
}
break;
}
$statsHandler = xoops_getModuleHandler('stats', 'newbb');
$statsHandler->reset();
if (empty($forum_id)) {
redirect_header(XOOPS_URL . '/modules/newbb/list.topic.php', 2, _MD_DBUPDATED);
} else {
redirect_header(XOOPS_URL . '/modules/newbb/viewforum.php?forum=$forum_id', 2, _MD_DBUPDATED);
}
// irmtfan move to footer.php
include_once __DIR__ . '/footer.php';
include $GLOBALS['xoops']->path('footer.php');