1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the CCDNForum ForumBundle |
5
|
|
|
* |
6
|
|
|
* (c) CCDN (c) CodeConsortium <http://www.codeconsortium.com/> |
7
|
|
|
* |
8
|
|
|
* Available on github <http://www.github.com/codeconsortium/> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace CCDNForum\ForumBundle\Controller; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerAware; |
17
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
18
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
19
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
20
|
|
|
use Symfony\Component\EventDispatcher\Event; |
21
|
|
|
|
22
|
|
|
use CCDNForum\ForumBundle\Entity\Topic; |
23
|
|
|
use CCDNForum\ForumBundle\Entity\Post; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* |
27
|
|
|
* @category CCDNForum |
28
|
|
|
* @package ForumBundle |
29
|
|
|
* |
30
|
|
|
* @author Reece Fowell <[email protected]> |
31
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
32
|
|
|
* @version Release: 2.0 |
33
|
|
|
* @link https://github.com/codeconsortium/CCDNForumForumBundle |
34
|
|
|
* |
35
|
|
|
*/ |
36
|
|
|
class BaseController extends ContainerAware |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* |
40
|
|
|
* @var \Symfony\Bundle\FrameworkBundle\Routing\Router $router |
41
|
|
|
*/ |
42
|
|
|
private $router; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* |
46
|
|
|
* @var \Symfony\Bundle\TwigBundle\Debug\TimedTwigEngine $templating |
47
|
|
|
*/ |
48
|
|
|
private $templating; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* |
52
|
|
|
* @var \Symfony\Component\HttpFoundation\Request $request |
53
|
|
|
*/ |
54
|
|
|
protected $request; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* |
58
|
|
|
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher; |
59
|
|
|
*/ |
60
|
|
|
protected $dispatcher; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* |
64
|
|
|
* @var \Symfony\Component\Security\Core\SecurityContext $securityContext |
65
|
|
|
*/ |
66
|
|
|
private $securityContext; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* |
70
|
|
|
* @var \CCDNForum\ForumBundle\Component\Security\Authorizer $authorizer; |
71
|
|
|
*/ |
72
|
|
|
private $authorizer; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* |
76
|
|
|
* @var \CCDNForum\ForumBundle\Model\FrontModel\ForumModel $forumModel |
77
|
|
|
*/ |
78
|
|
|
private $forumModel; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* |
82
|
|
|
* @var \CCDNForum\ForumBundle\Model\FrontModel\CategoryModel $categoryModel |
83
|
|
|
*/ |
84
|
|
|
private $categoryModel; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* |
88
|
|
|
* @var \CCDNForum\ForumBundle\Model\FrontModel\BoardModel $boardModel |
89
|
|
|
*/ |
90
|
|
|
private $boardModel; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* |
94
|
|
|
* @var \CCDNForum\ForumBundle\Model\FrontModel\TopicModel $topicModel |
95
|
|
|
*/ |
96
|
|
|
private $topicModel; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* |
100
|
|
|
* @var \CCDNForum\ForumBundle\Model\FrontModel\PostModel $postModel |
101
|
|
|
*/ |
102
|
|
|
private $postModel; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* |
106
|
|
|
* @var \CCDNForum\ForumBundle\Model\FrontModel\RegistryModel $registryModel |
107
|
|
|
*/ |
108
|
|
|
private $registryModel; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* |
112
|
|
|
* @var \CCDNForum\ForumBundle\Model\FrontModel\SubscriptionModel $subscriptionModel |
113
|
|
|
*/ |
114
|
|
|
private $subscriptionModel; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* |
118
|
|
|
* @access protected |
119
|
|
|
* @return \Symfony\Bundle\FrameworkBundle\Routing\Router |
120
|
|
|
*/ |
121
|
|
|
protected function getRouter() |
122
|
|
|
{ |
123
|
|
|
if (null == $this->router) { |
124
|
|
|
$this->router = $this->container->get('router'); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return $this->router; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* |
132
|
|
|
* @access protected |
133
|
|
|
* @param string $route |
134
|
|
|
* @param Array $params |
135
|
|
|
* @return string |
136
|
|
|
*/ |
137
|
|
|
protected function path($route, $params = array()) |
138
|
|
|
{ |
139
|
|
|
return $this->getRouter()->generate($route, $params); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* |
144
|
|
|
* @access protected |
145
|
|
|
* @return \Symfony\Bundle\TwigBundle\Debug\TimedTwigEngine |
146
|
|
|
*/ |
147
|
|
|
protected function getTemplating() |
148
|
|
|
{ |
149
|
|
|
if (null == $this->templating) { |
150
|
|
|
$this->templating = $this->container->get('templating'); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
return $this->templating; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* |
158
|
|
|
* @access protected |
159
|
|
|
* @return \Symfony\Component\HttpFoundation\Request |
160
|
|
|
*/ |
161
|
|
|
protected function getRequest() |
162
|
|
|
{ |
163
|
|
|
if (null == $this->request) { |
164
|
|
|
$this->request = $this->container->get('request'); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
return $this->request; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* |
172
|
|
|
* @access protected |
173
|
|
|
* @param string $prefix |
174
|
|
|
* @return Array |
175
|
|
|
*/ |
176
|
|
|
protected function getCheckedItemIds($prefix = 'check_', $enforceNumericType = true) |
177
|
|
|
{ |
178
|
|
|
$request = $this->getRequest(); |
179
|
|
|
|
180
|
|
|
$sanitarisedIds = array(); |
181
|
|
|
|
182
|
|
|
if ($request->request->has($prefix)) { |
183
|
|
|
$itemIds = $request->request->get($prefix); |
184
|
|
|
|
185
|
|
|
foreach ($itemIds as $id => $val) { |
186
|
|
|
if ($enforceNumericType == true) { |
|
|
|
|
187
|
|
|
if (! is_numeric($id)) { |
188
|
|
|
continue; |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
$sanitarisedIds[] = $id; |
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
return $sanitarisedIds; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* |
201
|
|
|
* @access protected |
202
|
|
|
* @param string $template |
203
|
|
|
* @param Array $params |
204
|
|
|
* @param string $engine |
|
|
|
|
205
|
|
|
* @return string |
|
|
|
|
206
|
|
|
*/ |
207
|
|
|
protected function renderResponse($template, $params = array(), $engine = null) |
208
|
|
|
{ |
209
|
|
|
return $this->getTemplating()->renderResponse($template . ($engine ?: $this->getEngine()), $params); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* |
214
|
|
|
* @access protected |
215
|
|
|
* @param string $url |
216
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
217
|
|
|
*/ |
218
|
|
|
protected function redirectResponse($url) |
219
|
|
|
{ |
220
|
|
|
return new RedirectResponse($url); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* |
225
|
|
|
* @access protected |
226
|
|
|
* @param string $forumName |
227
|
|
|
* @param \CCDNForum\ForumBundle\Entity\Topic $topic |
228
|
|
|
* @param \CCDNForum\ForumBundle\Entity\Post $post |
229
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
230
|
|
|
*/ |
231
|
|
|
protected function redirectResponseForTopicOnPageFromPost($forumName, Topic $topic, Post $post) |
|
|
|
|
232
|
|
|
{ |
233
|
|
|
//$page = $this->getTopicModel()->getPageForPostOnTopic($topic, $topic->getLastPost()); // Page of the last post. |
234
|
|
|
$response = $this->redirectResponse($this->path('ccdn_forum_user_topic_show', array( |
235
|
|
|
'forumName' => $forumName, |
236
|
|
|
'topicId' => $topic->getId(), |
237
|
|
|
/*'page' => $page*/ |
238
|
|
|
)) /* . '#' . $topic->getLastPost()->getId()*/); |
239
|
|
|
|
240
|
|
|
return $response; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* |
245
|
|
|
* @access protected |
246
|
|
|
* @return string |
247
|
|
|
*/ |
248
|
|
|
protected function getEngine() |
249
|
|
|
{ |
250
|
|
|
return $this->container->getParameter('ccdn_forum_forum.template.engine'); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* |
255
|
|
|
* @access protected |
256
|
|
|
* @return \Symfony\Component\Security\Core\SecurityContext |
257
|
|
|
*/ |
258
|
|
|
protected function getSecurityContext() |
259
|
|
|
{ |
260
|
|
|
if (null == $this->securityContext) { |
261
|
|
|
$this->securityContext = $this->container->get('security.context'); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
return $this->securityContext; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* |
269
|
|
|
* @access protected |
270
|
|
|
* @return \Symfony\Component\Security\Core\User\UserInterface |
271
|
|
|
*/ |
272
|
|
|
protected function getUser() |
273
|
|
|
{ |
274
|
|
|
return $this->getSecurityContext()->getToken()->getUser(); |
|
|
|
|
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* |
279
|
|
|
* @access protected |
280
|
|
|
* @param string $role |
281
|
|
|
* @return bool |
282
|
|
|
*/ |
283
|
|
|
protected function isGranted($role) |
284
|
|
|
{ |
285
|
|
|
if (! $this->getSecurityContext()->isGranted($role)) { |
|
|
|
|
286
|
|
|
return false; |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
return true; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* |
294
|
|
|
* @access protected |
295
|
|
|
* @param string $role|boolean $role |
|
|
|
|
296
|
|
|
* @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException |
297
|
|
|
*/ |
298
|
|
|
protected function isAuthorised($role) |
299
|
|
|
{ |
300
|
|
|
if (is_bool($role)) { |
301
|
|
|
if ($role == false) { |
|
|
|
|
302
|
|
|
throw new AccessDeniedException('You do not have permission to use this resource.'); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
return true; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
if (! $this->isGranted($role)) { |
309
|
|
|
throw new AccessDeniedException('You do not have permission to use this resource.'); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
return true; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* |
317
|
|
|
* @access protected |
318
|
|
|
* @param \Object $item |
319
|
|
|
* @param string $message |
|
|
|
|
320
|
|
|
* @return bool |
321
|
|
|
* @throws Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
322
|
|
|
*/ |
323
|
|
|
protected function isFound($item, $message = null) |
324
|
|
|
{ |
325
|
|
|
if (null == $item) { |
326
|
|
|
throw new NotFoundHttpException($message ?: 'Page you are looking for could not be found!'); |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
return true; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
protected function getQuery($query, $default) |
|
|
|
|
333
|
|
|
{ |
334
|
|
|
return $this->getRequest()->query->get($query, $default); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
protected function dispatch($name, Event $event) |
338
|
|
|
{ |
339
|
|
|
if (! $this->dispatcher) { |
340
|
|
|
$this->dispatcher = $this->container->get('event_dispatcher'); |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
$this->dispatcher->dispatch($name, $event); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* |
348
|
|
|
* @access protected |
349
|
|
|
* @return \CCDNForum\ForumBundle\Component\Security\Authorizer |
350
|
|
|
*/ |
351
|
|
|
protected function getAuthorizer() |
352
|
|
|
{ |
353
|
|
|
if (null == $this->authorizer) { |
354
|
|
|
$this->authorizer = $this->container->get('ccdn_forum_forum.component.security.authorizer'); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
return $this->authorizer; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* |
362
|
|
|
* @access protected |
363
|
|
|
* @return \CCDNForum\ForumBundle\Model\FrontModel\ForumModel |
364
|
|
|
*/ |
365
|
|
|
protected function getForumModel() |
366
|
|
|
{ |
367
|
|
|
if (null == $this->forumModel) { |
368
|
|
|
$this->forumModel = $this->container->get('ccdn_forum_forum.model.forum'); |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
return $this->forumModel; |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* |
376
|
|
|
* @access protected |
377
|
|
|
* @return \CCDNForum\ForumBundle\Model\FrontModel\CategoryModel |
378
|
|
|
*/ |
379
|
|
|
protected function getCategoryModel() |
380
|
|
|
{ |
381
|
|
|
if (null == $this->categoryModel) { |
382
|
|
|
$this->categoryModel = $this->container->get('ccdn_forum_forum.model.category'); |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
return $this->categoryModel; |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* |
390
|
|
|
* @access protected |
391
|
|
|
* @return \CCDNForum\ForumBundle\Model\FrontModel\BoardModel |
392
|
|
|
*/ |
393
|
|
|
protected function getBoardModel() |
394
|
|
|
{ |
395
|
|
|
if (null == $this->boardModel) { |
396
|
|
|
$this->boardModel = $this->container->get('ccdn_forum_forum.model.board'); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
return $this->boardModel; |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* |
404
|
|
|
* @access protected |
405
|
|
|
* @return \CCDNForum\ForumBundle\Model\FrontModel\TopicModel |
406
|
|
|
*/ |
407
|
|
|
protected function getTopicModel() |
408
|
|
|
{ |
409
|
|
|
if (null == $this->topicModel) { |
410
|
|
|
$this->topicModel = $this->container->get('ccdn_forum_forum.model.topic'); |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
return $this->topicModel; |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* |
418
|
|
|
* @access protected |
419
|
|
|
* @return \CCDNForum\ForumBundle\Model\FrontModel\PostModel |
420
|
|
|
*/ |
421
|
|
|
protected function getPostModel() |
422
|
|
|
{ |
423
|
|
|
if (null == $this->postModel) { |
424
|
|
|
$this->postModel = $this->container->get('ccdn_forum_forum.model.post'); |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
return $this->postModel; |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* |
432
|
|
|
* @access protected |
433
|
|
|
* @return \CCDNForum\ForumBundle\Model\FrontModel\RegistryModel |
434
|
|
|
*/ |
435
|
|
|
protected function getRegistryModel() |
436
|
|
|
{ |
437
|
|
|
if (null == $this->registryModel) { |
438
|
|
|
$this->registryModel = $this->container->get('ccdn_forum_forum.model.registry'); |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
return $this->registryModel; |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* |
446
|
|
|
* @access protected |
447
|
|
|
* @return \CCDNForum\ForumBundle\Model\FrontModel\SubscriptionModel |
448
|
|
|
*/ |
449
|
|
|
protected function getSubscriptionModel() |
450
|
|
|
{ |
451
|
|
|
if (null == $this->subscriptionModel) { |
452
|
|
|
$this->subscriptionModel = $this->container->get('ccdn_forum_forum.model.subscription'); |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
return $this->subscriptionModel; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* |
460
|
|
|
* @access protected |
461
|
|
|
*/ |
462
|
|
|
protected function getCrumbs() |
463
|
|
|
{ |
464
|
|
|
return $this->container->get('ccdn_forum_forum.component.crumb_builder'); |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
/** |
468
|
|
|
* |
469
|
|
|
* @access protected |
470
|
|
|
* @return \CCDNForum\ForumBundle\Component\Helper\PaginationConfigHelper |
471
|
|
|
*/ |
472
|
|
|
protected function getPageHelper() |
473
|
|
|
{ |
474
|
|
|
return $this->container->get('ccdn_forum_forum.component.helper.pagination_config'); |
475
|
|
|
} |
476
|
|
|
} |
477
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.