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 \blitze\content\services\types */ |
20
|
|
|
protected $content_types; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Constructor |
24
|
|
|
* |
25
|
|
|
* @param \phpbb\controller\helper $helper Helper object |
26
|
|
|
* @param \blitze\content\services\types $content_types Content types object |
27
|
|
|
*/ |
28
|
|
|
public function __construct(\phpbb\controller\helper $helper, \blitze\content\services\types $content_types) |
29
|
|
|
{ |
30
|
|
|
$this->helper = $helper; |
31
|
|
|
$this->content_types = $content_types; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
|
|
static public function getSubscribedEvents() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
return array( |
40
|
|
|
'core.viewforum_get_topic_data' => 'viewforum_redirect', |
41
|
|
|
'core.viewtopic_assign_template_vars_before' => 'viewtopic_redirect', |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param \phpbb\event\data $event |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
|
|
public function viewforum_redirect(\phpbb\event\data $event) |
50
|
|
|
{ |
51
|
|
|
if ($type = $this->content_types->get_forum_type($event['forum_data']['forum_id'])) |
52
|
|
|
{ |
53
|
|
|
redirect($this->helper->route('blitze_content_index', array( |
54
|
|
|
'type' => $type, |
55
|
|
|
))); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param \phpbb\event\data $event |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
|
public function viewtopic_redirect(\phpbb\event\data $event) |
64
|
|
|
{ |
65
|
|
|
if ($type = $this->content_types->get_forum_type($event['forum_id'])) |
66
|
|
|
{ |
67
|
|
|
$topic_url = $this->helper->route('blitze_content_show', array( |
68
|
|
|
'type' => $type, |
69
|
|
|
'topic_id' => $event['topic_id'], |
70
|
|
|
'slug' => $event['topic_data']['topic_slug'] |
71
|
|
|
)); |
72
|
|
|
|
73
|
|
|
$post_id = $event['post_id']; |
74
|
|
|
if ($event['topic_data']['topic_first_post_id'] != $event['post_id']) |
75
|
|
|
{ |
76
|
|
|
$topic_url .= "?p=$post_id#p$post_id"; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
redirect($topic_url); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|