1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package sitemaker |
5
|
|
|
* @copyright (c) 2013 Daniel A. (blitze) |
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace blitze\content\event; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
13
|
|
|
|
14
|
|
|
class viewtopic implements EventSubscriberInterface |
15
|
|
|
{ |
16
|
|
|
/* @var \phpbb\controller\helper */ |
17
|
|
|
protected $helper; |
18
|
|
|
|
19
|
|
|
/** @var \phpbb\request\request_interface */ |
20
|
|
|
protected $request; |
21
|
|
|
|
22
|
|
|
/* @var \blitze\content\services\types */ |
23
|
|
|
protected $content_types; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Constructor |
27
|
|
|
* |
28
|
|
|
* @param \phpbb\controller\helper $helper Helper object |
29
|
|
|
* @param \phpbb\request\request_interface $request Request object |
30
|
|
|
* @param \blitze\content\services\types $content_types Content types object |
31
|
|
|
*/ |
32
|
|
|
public function __construct(\phpbb\controller\helper $helper, \phpbb\request\request_interface $request, \blitze\content\services\types $content_types) |
33
|
|
|
{ |
34
|
|
|
$this->helper = $helper; |
35
|
|
|
$this->request = $request; |
36
|
|
|
$this->content_types = $content_types; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
|
|
public static function getSubscribedEvents() |
43
|
|
|
{ |
44
|
|
|
return array( |
45
|
|
|
'core.viewforum_get_topic_data' => 'viewforum_redirect', |
46
|
|
|
'core.viewtopic_assign_template_vars_before' => 'viewtopic_redirect', |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param \phpbb\event\data $event |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
public function viewforum_redirect(\phpbb\event\data $event) |
55
|
|
|
{ |
56
|
|
|
if ($type = $this->content_types->get_forum_type($event['forum_data']['forum_id'])) |
57
|
|
|
{ |
58
|
|
|
redirect($this->helper->route('blitze_content_type', array( |
59
|
|
|
'type' => $type, |
60
|
|
|
))); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param \phpbb\event\data $event |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function viewtopic_redirect(\phpbb\event\data $event) |
69
|
|
|
{ |
70
|
|
|
if (($type = $this->content_types->get_forum_type($event['forum_id'])) && !$this->request->is_set_post('update')) |
71
|
|
|
{ |
72
|
|
|
$topic_url = $this->helper->route('blitze_content_show', array( |
73
|
|
|
'type' => $type, |
74
|
|
|
'topic_id' => $event['topic_id'], |
75
|
|
|
'slug' => $event['topic_data']['topic_slug'] |
76
|
|
|
)); |
77
|
|
|
|
78
|
|
|
$post_id = $event['post_id']; |
79
|
|
|
if ($post_id && $post_id != $event['topic_data']['topic_first_post_id']) |
80
|
|
|
{ |
81
|
|
|
$topic_url .= "?p=$post_id#p$post_id"; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
redirect($topic_url); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|