1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Pierre-Henry Soria <[email protected]> |
4
|
|
|
* @copyright (c) 2012-2017, Pierre-Henry Soria. All Rights Reserved. |
5
|
|
|
* @license GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory. |
6
|
|
|
* @package PH7 / App / System / Module / Forum / Controller |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace PH7; |
10
|
|
|
|
11
|
|
|
use PH7\Framework\Navigation\Page; |
12
|
|
|
use PH7\Framework\Security\Ban\Ban; |
13
|
|
|
use PH7\Framework\Analytics\Statistic; |
14
|
|
|
use PH7\Framework\Mvc\Router\Uri; |
15
|
|
|
use PH7\Framework\Url\Header; |
16
|
|
|
|
17
|
|
|
class ForumController extends Controller |
18
|
|
|
{ |
19
|
|
|
const TOPICS_PER_PAGE = 20; |
20
|
|
|
const FORUMS_PER_PAGE = 20; |
21
|
|
|
const POSTS_PER_PAGE = 10; |
22
|
|
|
|
23
|
|
|
private $oForumModel; |
24
|
|
|
private $oPage; |
25
|
|
|
private $sTitle; |
26
|
|
|
private $sMsg; |
27
|
|
|
private $iTotalTopics; |
28
|
|
|
|
29
|
|
|
public function __construct() |
30
|
|
|
{ |
31
|
|
|
parent::__construct(); |
32
|
|
|
|
33
|
|
|
$this->oForumModel = new ForumModel; |
34
|
|
|
$this->oPage = new Page; |
35
|
|
|
$this->view->avatarDesign = new AvatarDesignCore; // Avatar Design Class |
36
|
|
|
$this->view->member_id = $this->session->get('member_id'); |
37
|
|
|
|
38
|
|
|
// Predefined meta_keywords tags |
39
|
|
|
$this->view->meta_keywords = t('forum,discussion,dating forum,social forum,people,meet people,forums,free dating forum,free forum,community forum,social forum'); |
40
|
|
|
|
41
|
|
|
// Adding Css Style for the Layout Forum |
42
|
|
|
$this->design->addCss(PH7_LAYOUT . PH7_SYS . PH7_MOD . $this->registry->module . PH7_SH . PH7_TPL . PH7_TPL_MOD_NAME . PH7_SH . PH7_CSS, 'common.css'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function index() |
46
|
|
|
{ |
47
|
|
|
$this->view->total_pages = $this->oPage->getTotalPages( |
48
|
|
|
$this->oForumModel->totalForums(), self::FORUMS_PER_PAGE |
49
|
|
|
); |
50
|
|
|
$this->view->current_page = $this->oPage->getCurrentPage(); |
51
|
|
|
|
52
|
|
|
$oCategories = $this->oForumModel->getCategory(); |
53
|
|
|
$oForums = $this->oForumModel->getForum( |
54
|
|
|
null, |
55
|
|
|
$this->oPage->getFirstItem(), |
56
|
|
|
$this->oPage->getNbItemsPerPage() |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
if (empty($oCategories) && empty($oForums)) { |
60
|
|
|
$this->sTitle = t('No Forums found.'); |
61
|
|
|
$this->notFound(); |
62
|
|
|
} else { |
63
|
|
|
$this->view->page_title = t('Discussion Forums - %site_name%'); |
64
|
|
|
$this->view->meta_description = t('Discussion Forums, Social Network Site - %site_name%'); |
65
|
|
|
$this->view->h1_title = t('Discussion Forums, Social Network Site'); |
66
|
|
|
|
67
|
|
|
$this->view->categories = $oCategories; |
68
|
|
|
$this->view->forums = $oForums; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$this->output(); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function topic() |
75
|
|
|
{ |
76
|
|
|
$this->view->total_pages = $this->oPage->getTotalPages( |
77
|
|
|
$this->oForumModel->totalTopics(), self::TOPICS_PER_PAGE |
78
|
|
|
); |
79
|
|
|
$this->view->current_page = $this->oPage->getCurrentPage(); |
80
|
|
|
$oTopics = $this->oForumModel->getTopic( |
81
|
|
|
strstr($this->httpRequest->get('forum_name'), '-', true), |
82
|
|
|
$this->httpRequest->get('forum_id', 'int'), |
83
|
|
|
null, |
84
|
|
|
null, |
85
|
|
|
null, |
86
|
|
|
1, |
87
|
|
|
$this->oPage->getFirstItem(), |
88
|
|
|
$this->oPage->getNbItemsPerPage() |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
$this->view->forum_name = $this->httpRequest->get('forum_name'); |
92
|
|
|
$this->view->forum_id = $this->httpRequest->get('forum_id', 'int'); |
93
|
|
|
|
94
|
|
|
if (empty($oTopics)) { |
95
|
|
|
$this->sTitle = t('No Topics found.'); |
96
|
|
|
$this->notFound(); |
97
|
|
|
} else { |
98
|
|
|
$this->view->page_title = t('%0% - Forums', $this->str->upperFirst($this->httpRequest->get('forum_name'))); |
99
|
|
|
$this->view->meta_description = t('%0% - Topics - Discussion Forums', $this->httpRequest->get('forum_name')); |
100
|
|
|
$this->view->meta_keywords = t('%0%,forum,discussion,dating forum,social forum,people,meet people,forums,free dating forum', str_replace(' ', ',', $this->httpRequest->get('forum_name'))); |
101
|
|
|
$this->view->h1_title = $this->str->upperFirst($this->httpRequest->get('forum_name')); |
102
|
|
|
$this->view->topics = $oTopics; |
103
|
|
|
} |
104
|
|
|
$this->output(); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function post() |
108
|
|
|
{ |
109
|
|
|
$oPost = $this->oForumModel->getTopic( |
110
|
|
|
strstr($this->httpRequest->get('forum_name'), '-', true), |
111
|
|
|
$this->httpRequest->get('forum_id', 'int'), |
112
|
|
|
strstr($this->httpRequest->get('topic_name'), '-', true), |
113
|
|
|
$this->httpRequest->get('topic_id', 'int'), |
114
|
|
|
null, |
115
|
|
|
1, |
116
|
|
|
0, |
117
|
|
|
1 |
118
|
|
|
); |
119
|
|
|
|
120
|
|
|
$this->view->total_pages = $this->oPage->getTotalPages( |
121
|
|
|
$this->oForumModel->totalMessages( |
122
|
|
|
$this->httpRequest->get('topic_id', 'int') |
123
|
|
|
), |
124
|
|
|
self::POSTS_PER_PAGE |
125
|
|
|
); |
126
|
|
|
|
127
|
|
|
$this->view->current_page = $this->oPage->getCurrentPage(); |
128
|
|
|
$oMessages = $this->oForumModel->getMessage( |
129
|
|
|
$this->httpRequest->get('topic_id', 'int'), |
130
|
|
|
null, |
131
|
|
|
null, |
132
|
|
|
1, |
133
|
|
|
$this->oPage->getFirstItem(), |
134
|
|
|
$this->oPage->getNbItemsPerPage() |
135
|
|
|
); |
136
|
|
|
|
137
|
|
|
if (empty($oPost)) { |
138
|
|
|
$this->sTitle = t('Topic Not Found!'); |
139
|
|
|
$this->notFound(); |
140
|
|
|
} else { |
141
|
|
|
// Adding the RSS link |
142
|
|
|
$this->view->header = '<link rel="alternate" type="application/rss+xml" title="' . t('Latest Forum Posts') . '" href="' . Uri::get('xml', 'rss', 'xmlrouter', 'forum-post,' . $oPost->topicId) . '" />'; |
143
|
|
|
$this->sTitle = t('%0% | %1% - Forum', $this->str->upperFirst($this->httpRequest->get('forum_name')), $this->str->escape(Ban::filterWord($oPost->title), true)); |
144
|
|
|
$this->view->page_title = $this->sTitle; |
145
|
|
|
$this->view->meta_description = t('%0% Topics - Discussion Forums', substr($this->str->escape(Ban::filterWord($oPost->message), true), 0, 150)); |
146
|
|
|
|
147
|
|
|
// Generates beautiful meta keywords for good SEO |
148
|
|
|
$this->view->meta_keywords = t('%0%,%1%,forum,discussion,dating forum,social forum', str_replace(' ', ',', $this->httpRequest->get('forum_name')), substr(str_replace(' ', ',', Ban::filterWord($oPost->title, false)), 0, 250)); |
149
|
|
|
$this->view->h1_title = $this->sTitle; |
150
|
|
|
|
151
|
|
|
$this->view->dateTime = $this->dateTime; |
152
|
|
|
$this->view->post = $oPost; |
153
|
|
|
$this->view->messages = $oMessages; |
154
|
|
|
|
155
|
|
|
// Set Topics Views Statistics |
156
|
|
|
Statistic::setView($oPost->topicId, 'ForumsTopics'); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
$this->output(); |
|
|
|
|
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function showPostByProfile() |
163
|
|
|
{ |
164
|
|
|
$sUsername = $this->httpRequest->get('username'); |
165
|
|
|
$this->view->username = $sUsername; |
166
|
|
|
|
167
|
|
|
$iId = (new UserCoreModel)->getId(null, $sUsername); |
168
|
|
|
|
169
|
|
|
$this->iTotalTopics = $this->oForumModel->totalTopics(null, $iId); |
170
|
|
|
$this->view->total_pages = $this->oPage->getTotalPages( |
171
|
|
|
$this->iTotalTopics, self::TOPICS_PER_PAGE |
172
|
|
|
); |
173
|
|
|
$this->view->current_page = $this->oPage->getCurrentPage(); |
174
|
|
|
|
175
|
|
|
$this->view->topic_number = nt('%n% Topic:', '%n% Topics:', $this->iTotalTopics); |
176
|
|
|
|
177
|
|
|
$oTopics = $this->oForumModel->getPostByProfile( |
178
|
|
|
$iId, |
179
|
|
|
1, |
180
|
|
|
$this->oPage->getFirstItem(), |
181
|
|
|
$this->oPage->getNbItemsPerPage() |
182
|
|
|
); |
183
|
|
|
if (empty($oTopics)) { |
184
|
|
|
$this->sTitle = t("%0% doesn't have any posts yet.", $sUsername); |
185
|
|
|
$this->notFound(false); // Because the Ajax blocks profile, we can not put HTTP error code 404, so the attribute is "false" |
186
|
|
|
} else { |
187
|
|
|
$this->sTitle = t("%0%'s Forum Posts", $sUsername); |
188
|
|
|
$this->view->page_title = $this->sTitle; |
189
|
|
|
$this->view->h2_title = $this->sTitle; |
190
|
|
|
$this->view->topics = $oTopics; |
191
|
|
|
} |
192
|
|
|
$this->output(); |
|
|
|
|
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
public function search() |
196
|
|
|
{ |
197
|
|
|
$this->sTitle = t('Forum Search - Looking for a Forum Post | %site_name%'); |
198
|
|
|
$this->view->page_title = $this->sTitle; |
199
|
|
|
$this->view->meta_description = t('Topic Search - Discussion Forum - %site_name%'); |
200
|
|
|
$this->view->h2_title = $this->sTitle; |
201
|
|
|
$this->output(); |
|
|
|
|
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function result() |
205
|
|
|
{ |
206
|
|
|
$this->iTotalTopics = $this->oForumModel->search( |
207
|
|
|
$this->httpRequest->get('looking'), |
208
|
|
|
true, |
209
|
|
|
$this->httpRequest->get('order'), |
210
|
|
|
$this->httpRequest->get('sort'), |
211
|
|
|
null, |
212
|
|
|
null |
213
|
|
|
); |
214
|
|
|
$this->view->total_pages = $this->oPage->getTotalPages( |
215
|
|
|
$this->iTotalTopics, self::POSTS_PER_PAGE |
216
|
|
|
); |
217
|
|
|
|
218
|
|
|
$this->view->current_page = $this->oPage->getCurrentPage(); |
219
|
|
|
|
220
|
|
|
$oSearch = $this->oForumModel->search( |
221
|
|
|
$this->httpRequest->get('looking'), |
222
|
|
|
false, |
223
|
|
|
$this->httpRequest->get('order'), |
224
|
|
|
$this->httpRequest->get('sort'), |
225
|
|
|
$this->oPage->getFirstItem(), |
226
|
|
|
$this->oPage->getNbItemsPerPage() |
227
|
|
|
); |
228
|
|
|
|
229
|
|
|
if (empty($oSearch)) { |
230
|
|
|
$this->sTitle = t('Sorry, Your search returned no results!'); |
231
|
|
|
$this->notFound(); |
232
|
|
|
} else { |
233
|
|
|
$this->sTitle = t('Forums - Your search returned'); |
234
|
|
|
$this->view->page_title = $this->sTitle; |
235
|
|
|
$this->view->h3_title = nt('%n% Result', '%n% Results', $this->iTotalTopics); |
236
|
|
|
$this->view->meta_description = t('Search - Discussion Forum'); |
237
|
|
|
$this->view->meta_keywords = t('search,forum,forums,discussion forum'); |
238
|
|
|
$this->view->h2_title = $this->sTitle; |
239
|
|
|
$this->view->topics = $oSearch; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
$this->manualTplInclude('topic.tpl'); |
|
|
|
|
243
|
|
|
$this->output(); |
|
|
|
|
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
public function addTopic() |
247
|
|
|
{ |
248
|
|
|
$this->sTitle = t('Add a new Topic'); |
249
|
|
|
$this->view->page_title = $this->sTitle; |
250
|
|
|
$this->view->h2_title = $this->sTitle; |
251
|
|
|
$this->output(); |
|
|
|
|
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
public function editTopic() |
255
|
|
|
{ |
256
|
|
|
$this->sTitle = t('Edit Topic'); |
257
|
|
|
$this->view->page_title = $this->sTitle; |
258
|
|
|
$this->view->h2_title = $this->sTitle; |
259
|
|
|
$this->output(); |
|
|
|
|
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
public function editMessage() |
263
|
|
|
{ |
264
|
|
|
$this->sTitle = t('Edit your Message'); |
265
|
|
|
$this->view->page_title = $this->sTitle; |
266
|
|
|
$this->view->h2_title = $this->sTitle; |
267
|
|
|
$this->output(); |
|
|
|
|
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
public function reply() |
271
|
|
|
{ |
272
|
|
|
$this->sTitle = t('Reply Message'); |
273
|
|
|
$this->view->page_title = $this->sTitle; |
274
|
|
|
$this->view->h2_title = $this->sTitle; |
275
|
|
|
$this->output(); |
|
|
|
|
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
public function deleteTopic() |
279
|
|
|
{ |
280
|
|
|
$aData = explode('_', $this->httpRequest->post('id')); |
281
|
|
|
$iTopicId = (int) $aData[0]; |
282
|
|
|
$iForumId = (int) $aData[1]; |
283
|
|
|
$sForumName = (string) $aData[2]; |
284
|
|
|
|
285
|
|
|
if ($this->oForumModel->deleteTopic($this->session->get('member_id'), $iTopicId)) { |
286
|
|
|
$this->sMsg = t('Your topic has been deleted.'); |
287
|
|
|
} else { |
288
|
|
|
$this->sMsg = t('Oops! Your topic could not be deleted'); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
Header::redirect(Uri::get('forum', 'forum', 'topic', $sForumName . ',' . $iForumId), $this->sMsg); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
public function deleteMessage() |
295
|
|
|
{ |
296
|
|
|
$aData = explode('_', $this->httpRequest->post('id')); |
297
|
|
|
$iMessageId = (int) $aData[0]; |
298
|
|
|
$iTopicId = (int) $aData[1]; |
299
|
|
|
$iForumId = (int) $aData[2]; |
300
|
|
|
$sTopicTitle = (string) $aData[3]; |
301
|
|
|
$sForumName = (string) $aData[4]; |
302
|
|
|
unset($aData); |
303
|
|
|
|
304
|
|
|
if ($this->oForumModel->deleteMessage($this->session->get('member_id', 'int'), $iMessageId)) { |
305
|
|
|
$this->sMsg = t('Your message has been deleted.'); |
306
|
|
|
} else { |
307
|
|
|
$this->sMsg = t('Oops! Your message could not be deleted'); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
Header::redirect(Uri::get('forum', 'forum', 'post', $sForumName . ',' . $iForumId . ',' . $sTopicTitle . ',' . $iTopicId), |
311
|
|
|
$this->sMsg |
312
|
|
|
); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* Set a Not Found Error Message with HTTP 404 Code Status. |
317
|
|
|
* |
318
|
|
|
* @param boolean $b404Status For the Ajax blocks profile, we can not put HTTP error code 404, so the attribute must be set to "false". Default: TRUE |
319
|
|
|
* @return void |
320
|
|
|
*/ |
321
|
|
|
private function notFound($b404Status = true) |
322
|
|
|
{ |
323
|
|
|
if ($b404Status === true) { |
324
|
|
|
Framework\Http\Http::setHeadersByCode(404); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
$sErrMsg = ''; |
328
|
|
|
if ($b404Status === true) { |
329
|
|
|
$sErrMsg = '<br />' . t('Please return to the <a href="%0%">main forum page</a> or <a href="%1%">the previous page</a>.', Uri::get('forum', 'forum', 'index'), 'javascript:history.back();'); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
$this->view->page_title = $this->sTitle; |
333
|
|
|
$this->view->h2_title = $this->sTitle; |
334
|
|
|
$this->view->error = $this->sTitle . $sErrMsg; |
335
|
|
|
} |
336
|
|
|
} |
337
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.