-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathTopic.php
More file actions
288 lines (233 loc) · 11.8 KB
/
Topic.php
File metadata and controls
288 lines (233 loc) · 11.8 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
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
<?php
/**
* Copyright (C) 2015-2019 FeatherBB
* based on code by (C) 2008-2015 FluxBB
* and Rickard Andersson (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
namespace FeatherBB\Controller;
use FeatherBB\Core\Error;
use FeatherBB\Core\Interfaces\ForumEnv;
use FeatherBB\Core\Interfaces\ForumSettings;
use FeatherBB\Core\Interfaces\Hooks;
use FeatherBB\Core\Interfaces\Input;
use FeatherBB\Core\Interfaces\Lang;
use FeatherBB\Core\Interfaces\Router;
use FeatherBB\Core\Interfaces\User;
use FeatherBB\Core\Interfaces\View;
use FeatherBB\Core\Track;
use FeatherBB\Core\Url;
use FeatherBB\Core\Utils;
class Topic
{
public function __construct()
{
$this->model = new \FeatherBB\Model\Topic();
Lang::load('topic');
Lang::load('misc'); // To be removed
Lang::load('post');
}
public function display($req, $res, $args)
{
if (!isset($args['page'])) {
$args['page'] = null;
}
if (!isset($args['pid'])) {
$args['pid'] = null;
}
if (!isset($args['name'])) {
$args['name'] = null;
}
Hooks::fire('controller.topic.display', $args['id'], $args['name'], $args['page'], $args['pid']);
// Antispam feature
$langAntispamQuestions = require ForumEnv::get('FEATHER_ROOT').'featherbb/lang/'.User::getPref('language').'/antispam.php';
$indexQuestions = rand(0, count($langAntispamQuestions)-1);
// Fetch some information about the topic
$curTopic = $this->model->getInfoTopic($args['id']);
// Sort out who the moderators are and if we are currently a moderator (or an admin)
$modsArray = ($curTopic['moderators'] != '') ? unserialize($curTopic['moderators']) : [];
$isAdmmod = (User::isAdmin() || (User::isAdminMod() && array_key_exists(User::get()->username, $modsArray))) ? true : false;
// Can we or can we not post replies?
$postLink = $this->model->postLink($args['id'], $curTopic['closed'], $curTopic['post_replies'], $isAdmmod);
// Add/update this topic in our list of tracked topics
if (!User::get()->is_guest) {
$trackedTopics = Track::getTrackedTopics();
$trackedTopics['topics'][$args['id']] = time();
Track::setTrackedTopics($trackedTopics);
}
// Determine the post offset (based on $_gET['p'])
$numPages = ceil(($curTopic['num_replies'] + 1) / User::getPref('disp.posts'));
$p = (!isset($args['page']) || $args['page'] <= 1 || $args['page'] > $numPages) ? 1 : intval($args['page']);
$startFrom = User::getPref('disp.posts') * ($p - 1);
$urlTopic = Url::slug($curTopic['subject']);
$urlForum = Url::slug($curTopic['forum_name']);
// Generate paging links
$pagingLinks = '<span class="pages-label">'.__('Pages').' </span>'.Url::paginate($numPages, $p, 'topic/'.$args['id'].'/'.$urlTopic.'/#');
if (ForumSettings::get('o_censoring') == '1') {
$curTopic['subject'] = Utils::censor($curTopic['subject']);
}
$quickpost = $this->model->isQuickpost($curTopic['post_replies'], $curTopic['closed'], $isAdmmod);
$subscraction = $this->model->getSubscraction(($curTopic['is_subscribed'] == User::get()->id), $args['id'], $args['name']);
View::addAsset('canonical', Router::pathFor('Topic', ['id' => $args['id'], 'name' => $urlTopic]));
if ($numPages > 1) {
if ($p > 1) {
View::addAsset('prev', Router::pathFor('Topic', ['id' => $args['id'], 'name' => $urlTopic, 'page' => intval($p-1)]));
}
if ($p < $numPages) {
View::addAsset('next', Router::pathFor('Topic', ['id' => $args['id'], 'name' => $urlTopic, 'page' => intval($p+1)]));
}
}
View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), Utils::escape($curTopic['forum_name']), Utils::escape($curTopic['subject'])],
'active_page' => 'Topic',
'page_number' => $p,
'paging_links' => $pagingLinks,
'is_indexed' => true,
'id' => $args['id'],
'pid' => $args['pid'],
'tid' => $args['id'],
'fid' => $curTopic['forum_id'],
'post_data' => $this->model->printPosts($args['id'], $startFrom, $curTopic, $isAdmmod),
'cur_topic' => $curTopic,
'subscraction' => $subscraction,
'post_link' => $postLink,
'start_from' => $startFrom,
'quickpost' => $quickpost,
'index_questions' => $indexQuestions,
'lang_antispam_questions' => $langAntispamQuestions,
'url_forum' => $urlForum,
'url_topic' => $urlTopic,
'is_admmod' => $isAdmmod,
])->addTemplate('@forum/topic')->display();
// Increment "num_views" for topic
$this->model->incrementViews($args['id']);
}
public function viewpost($req, $res, $args)
{
$args['pid'] = Hooks::fire('controller.topic.viewpost', $args['pid']);
$post = $this->model->redirectToPost($args['pid']);
$args['id'] = $post['topic_id'];
$args['page'] = $post['get_p'];
$this->display($req, $res, $args);
}
public function subscribe($req, $res, $args)
{
$args['id'] = Hooks::fire('controller.topic.subscribe', $args['id']);
$this->model->subscribe($args['id']);
return Router::redirect(Router::pathFor('Topic', ['id' => $args['id'], 'name' => $args['name']]), __('Subscribe redirect'));
}
public function unsubscribe($req, $res, $args)
{
$args['id'] = Hooks::fire('controller.topic.unsubscribe', $args['id']);
$this->model->unsubscribe($args['id']);
return Router::redirect(Router::pathFor('Topic', ['id' => $args['id'], 'name' => $args['name']]), __('Unsubscribe redirect'));
}
public function close($req, $res, $args)
{
$args['id'] = Hooks::fire('controller.topic.close', $args['id']);
$topic = $this->model->setClosed($args['id'], 1);
return Router::redirect(Router::pathFor('Topic', ['id' => $args['id'], 'name' => Url::slug($topic['subject'])]), __('Close topic redirect'));
}
public function open($req, $res, $args)
{
$args['id'] = Hooks::fire('controller.topic.open', $args['id']);
$topic = $this->model->setClosed($args['id'], 0);
return Router::redirect(Router::pathFor('Topic', ['id' => $args['id'], 'name' => Url::slug($topic['subject'])]), __('Open topic redirect'));
}
public function stick($req, $res, $args)
{
$args['id'] = Hooks::fire('controller.topic.stick', $args['id']);
$topic = $this->model->setSticky($args['id'], 1);
return Router::redirect(Router::pathFor('Topic', ['id' => $args['id'], 'name' => Url::slug($topic['subject'])]), __('Stick topic redirect'));
}
public function unstick($req, $res, $args)
{
$args['id'] = Hooks::fire('controller.topic.unstick', $args['id']);
$topic = $this->model->setSticky($args['id'], 0);
return Router::redirect(Router::pathFor('Topic', ['id' => $args['id'], 'name' => Url::slug($topic['subject'])]), __('Unstick topic redirect'));
}
// Move a single topic
public function move($req, $res, $args)
{
$args['id'] = Hooks::fire('controller.topic.move', $args['id']);
if ($newFid = Input::post('move_to_forum')) {
$this->model->moveTo($args['fid'], $newFid, $args['id']);
return Router::redirect(Router::pathFor('Topic', ['id' => $args['id'], 'name' => $args['name']]), __('Move topic redirect'));
}
// Check if there are enough forums to move the topic
if (!$this->model->checkMove()) {
throw new Error(__('Nowhere to move'), 403);
}
View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Moderate')],
'active_page' => 'moderate',
'action' => 'single',
'topics' => $args['id'],
'list_forums' => $this->model->getForumListMove($args['fid']),
]
)->addTemplate('@forum/moderate/move_topics')->display();
}
public function moderate($req, $res, $args)
{
Hooks::fire('controller.topic.moderate');
$curTopic = $this->model->getTopicInfo($args['fid'], $args['id']);
// Determine the post offset (based on $_gET['p'])
$numPages = ceil(($curTopic['num_replies'] + 1) / User::getPref('disp.posts'));
$p = (!isset($args['page']) || $args['page'] <= 1 || $args['page'] > $numPages) ? 1 : intval($args['page']);
$startFrom = User::getPref('disp.posts') * ($p - 1);
// Delete one or more posts
if (Input::post('delete_posts_comply')) {
return $this->model->deletePosts($args['id'], $args['fid']);
} elseif (Input::post('delete_posts')) {
$posts = $this->model->deletePosts($args['id'], $args['fid']);
return View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Moderate')],
'active_page' => 'moderate',
'posts' => $posts,
]
)->addTemplate('@forum/moderate/delete_posts')->display();
} elseif (Input::post('split_posts_comply')) {
return $this->model->splitPosts($args['id'], $args['fid'], $p);
} elseif (Input::post('split_posts')) {
return View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Moderate')],
'page' => $p,
'active_page' => 'moderate',
'id' => $args['id'],
'posts' => $this->model->splitPosts($args['id'], $args['fid'], $p),
'list_forums' => $this->model->getSplitForumList($args['fid']),
]
)->addTemplate('@forum/moderate/split_posts')->display();
} else {
// Show the moderate posts view
// Used to disable the Move and Delete buttons if there are no replies to this topic
$buttonStatus = ($curTopic['num_replies'] == 0) ? ' disabled="disabled"' : '';
/*if (isset($_gET['action']) && $_gET['action'] == 'all') {
User::getPref('disp.posts') = $curTopic['num_replies'] + 1;
}*/
if (ForumSettings::get('o_censoring') == '1') {
$curTopic['subject'] = Utils::censor($curTopic['subject']);
}
return View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), Utils::escape($curTopic['forum_name']), Utils::escape($curTopic['subject'])],
'page' => $p,
'active_page' => 'moderate',
'cur_topic' => $curTopic,
'url_topic' => Url::slug($curTopic['subject']),
'url_forum' => Url::slug($curTopic['forum_name']),
'fid' => $args['fid'],
'id' => $args['id'],
'paging_links' => '<span class="pages-label">' . __('Pages') . ' </span>' . Url::paginate($numPages, $p, 'topic/moderate/' . $args['id'] . '/forum/' . $args['fid'] . '/#'),
'post_data' => $this->model->moderateDisplayPosts($args['id'], $startFrom),
'button_status' => $buttonStatus,
'start_from' => $startFrom,
]
)->addTemplate('@forum/moderate/posts_view')->display();
}
}
public function action($req, $res, $args)
{
Hooks::fire('controller.topic.action');
return $this->model->handleActions($args['id'], $args['name'], $args['action']);
}
}