-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaction.post.php
More file actions
262 lines (243 loc) · 8.7 KB
/
action.post.php
File metadata and controls
262 lines (243 loc) · 8.7 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
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
<?php
/**
* iForum - a bulletin Board (Forum) for ImpressCMS
*
* Based upon CBB 3.08
*
* @copyright http://www.xoops.org/ The XOOPS Project
* @copyright http://xoopsforge.com The XOOPS FORGE Project
* @copyright http://xoops.org.cn The XOOPS CHINESE Project
* @copyright XOOPS_copyrights.txt
* @copyright readme.txt
* @copyright http://www.impresscms.org/ The ImpressCMS Project
* @license GNU General Public License (GPL)
* a copy of the GNU license is enclosed.
* ----------------------------------------------------------------------------------------------------------
* @package CBB - XOOPS Community Bulletin Board
* @since 3.08
* @author phppp
* ----------------------------------------------------------------------------------------------------------
* iForum - a bulletin Board (Forum) for ImpressCMS
* @since 1.00
* @author modified by stranger
* @version $Id$
*/
include 'header.php';
$topic_id = isset($_POST['topic_id']) ? (int)$_POST['topic_id'] :
0;
$post_id = !empty($_GET['post_id']) ? (int)$_GET['post_id'] :
0;
$post_id = !empty($_POST['post_id']) ? $_POST['post_id'] :
$post_id;
$uid = !empty($_POST['uid']) ? $_POST['uid'] :
0;
$op = !empty($_GET['op']) ? $_GET['op'] :
(!empty($_POST['op']) ? $_POST['op']:"");
$op = in_array($op, array("approve", "delete", "restore", "split"))? $op :
"";
$mode = !empty($_GET['mode']) ? (int)$_GET['mode'] :
1;
if (empty($post_id) || empty($op))
{
redirect_header("javascript:history.go(-1);", 2, _MD_NORIGHTTOACCESS);
exit();
}
$post_handler = icms_getmodulehandler('post', basename(__DIR__), 'iforum' );
$topic_handler = icms_getmodulehandler('topic', basename(__DIR__), 'iforum' );
$forum_handler = icms_getmodulehandler('forum', basename(__DIR__), 'iforum' );
if (empty($topic_id))
{
$viewtopic_forum = null;
}
else
{
$forumtopic = $topic_handler->get($topic_id);
$forum_id = $forumtopic->getVar('forum_id');
$viewtopic_forum = $forum_handler->get($forum_id);
}
$isadmin = iforum_isAdmin($viewtopic_forum);
if (!$isadmin)
{
redirect_header("index.php", 2, _MD_NORIGHTTOACCESS);
exit();
}
switch($op)
{
case "restore":
$post_id = array_values($post_id);
sort($post_id);
$topics = array();
$forums = array();
foreach($post_id as $post)
{
$post_obj = $post_handler->get($post);
if (!empty($topic_id) && $topic_id != $post_obj->getVar("topic_id")) continue;
$post_handler->approve($post_obj);
$topics[$post_obj->getVar("topic_id")] = 1;
$forums[$post_obj->getVar("forum_id")] = 1;
unset($post_obj);
}
foreach(array_keys($topics) as $topic)
{
$topic_handler->synchronization($topic);
}
foreach(array_keys($forums) as $forum)
{
$forum_handler->synchronization($forum);
}
break;
case "approve":
$post_id = array_values($post_id);
sort($post_id);
$topics = array();
$forums = array();
$criteria = new icms_db_criteria_Item("post_id", "(".implode(",", $post_id).")", "IN");
$posts_obj = $post_handler->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;
$post_handler->approve($post_obj);
$topics[$post_obj->getVar("topic_id")] = $post;
$forums[$post_obj->getVar("forum_id")] = 1;
}
foreach(array_keys($topics) as $topic)
{
$topic_handler->synchronization($topic);
}
foreach(array_keys($forums) as $forum)
{
$forum_handler->synchronization($forum);
}
if (empty(icms::$module->config['notification_enabled'])) break;
$criteria_topic = new icms_db_criteria_Item("topic_id", "(".implode(",", array_keys($topics)).")", "IN");
$topic_list = $topic_handler->getList($criteria_topic, true);
$criteria_forum = new icms_db_criteria_Item("forum_id", "(".implode(",", array_keys($forums)).")", "IN");
$forum_list = $forum_handler->getList($criteria_forum);
include_once 'include/notification.inc.php';
$notification_handler = icms::handler('icms_data_notification');
foreach($post_id as $post)
{
$tags = array();
$tags['THREAD_NAME'] = $topic_list[$posts_obj[$post]->getVar("topic_id")];
$tags['THREAD_URL'] = ICMS_URL . '/modules/' . icms::$module->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'] = ICMS_URL . '/modules/' . icms::$module->getVar('dirname') . '/viewforum.php?forum=' . $posts_obj[$post]->getVar('forum_id');
$tags['POST_URL'] = $tags['THREAD_URL'].'#forumpost' . $post;
$notification_handler->triggerEvent('thread', $posts_obj[$post]->getVar("topic_id"), 'new_post', $tags);
$notification_handler->triggerEvent('forum', $posts_obj[$post]->getVar('forum_id'), 'new_post', $tags);
$notification_handler->triggerEvent('global', 0, 'new_post', $tags);
$tags['POST_CONTENT'] = $posts_obj[$post]->getVar("post_text");
$tags['POST_NAME'] = $posts_obj[$post]->getVar("subject");
$notification_handler->triggerEvent('global', 0, 'new_fullpost', $tags);
$notification_handler->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 = $post_handler->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;
$post_handler->delete($post_obj);
unset($post_obj);
}
foreach(array_keys($topics) as $topic)
{
$topic_handler->synchronization($topic);
}
foreach(array_keys($forums) as $forum)
{
$forum_handler->synchronization($forum);
}
break;
case "split":
$post_obj = $post_handler->get($post_id);
if (empty($post_id) || $post_obj->isTopic())
{
break;
}
$topic_id = $post_obj->getVar("topic_id");
$newtopic = $topic_handler->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);
$topic_handler->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);
$post_handler->insert($post_obj);
/* split a single post */
if ($mode == 1)
{
$criteria = new icms_db_criteria_Compo(new icms_db_criteria_Item("topic_id", $topic_id));
$criteria->add(new icms_db_criteria_Item('pid', $post_id));
$post_handler->updateAll("pid", $pid, $criteria, true);
/* split a post and its children posts */
}
elseif($mode == 2)
{
include_once(ICMS_ROOT_PATH . "/class/xoopstree.php");
$mytree = new XoopsTree(icms::$xoopsDB->prefix("bb_posts"), "post_id", "pid");
$posts = $mytree->getAllChildId($post_id);
if (count($posts) > 0)
{
$criteria = new icms_db_criteria_Item('post_id', "(".implode(",", $posts).")", "IN");
$post_handler->updateAll("topic_id", $new_topic_id, $criteria, true);
}
/* split a post and all posts coming after */
}
elseif($mode == 3)
{
$criteria = new icms_db_criteria_Compo(new icms_db_criteria_Item("topic_id", $topic_id));
$criteria->add(new icms_db_criteria_Item('post_id', $post_id, ">"));
$post_handler->updateAll("topic_id", $new_topic_id, $criteria, true);
unset($criteria);
$criteria = new icms_db_criteria_Compo(new icms_db_criteria_Item("topic_id", $new_topic_id));
$criteria->add(new icms_db_criteria_Item('post_id', $post_id, ">"));
$post_handler->identifierName = "pid";
$posts = $post_handler->getList($criteria);
unset($criteria);
$post_update = array();
foreach($posts as $postid => $pid)
{
if (!in_array($pid, array_keys($posts)))
{
$post_update[] = $pid;
}
}
if (count($post_update))
{
$criteria = new icms_db_criteria_Item('post_id', "(".implode(",", $post_update).")", "IN");
$post_handler->updateAll("pid", $post_id, $criteria, true);
}
}
$forum_id = $post_obj->getVar("forum_id");
$topic_handler->synchronization($topic_id);
$topic_handler->synchronization($new_topic_id);
$sql = sprintf("UPDATE %s SET forum_topics = forum_topics+1 WHERE forum_id = %u", icms::$xoopsDB->prefix("bb_forums"), $forum_id);
$result = icms::$xoopsDB->queryF($sql);
break;
}
if (!empty($topic_id))
{
redirect_header("viewtopic.php?topic_id=$topic_id", 2, _MD_DBUPDATED);
}
elseif(!empty($forum_id))
{
redirect_header("viewforum.php?forum=$forum_id", 2, _MD_DBUPDATED);
}
else
{
redirect_header("viewpost.php?uid=$uid", 2, _MD_DBUPDATED);
}
include ICMS_ROOT_PATH.'/footer.php';