|
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 mcp_topic implements EventSubscriberInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var \phpbb\db\driver\driver_interface */ |
|
17
|
|
|
protected $db; |
|
18
|
|
|
|
|
19
|
|
|
/* @var \blitze\content\services\types */ |
|
20
|
|
|
protected $content_types; |
|
21
|
|
|
|
|
22
|
|
|
/* @var \blitze\content\services\fields */ |
|
23
|
|
|
protected $fields; |
|
24
|
|
|
|
|
25
|
|
|
/** @var string */ |
|
26
|
|
|
protected $phpbb_root_path; |
|
27
|
|
|
|
|
28
|
|
|
/** @var string */ |
|
29
|
|
|
protected $php_ext; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Constructor |
|
33
|
|
|
* |
|
34
|
|
|
* @param \phpbb\db\driver\driver_interface $db Database object |
|
35
|
|
|
* @param \blitze\content\services\types $content_types Content types object |
|
36
|
|
|
* @param \blitze\content\services\fields $fields Content fields object |
|
37
|
|
|
* @param string $phpbb_root_path Path to the phpbb includes directory. |
|
38
|
|
|
* @param string $php_ext php file extension |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct(\phpbb\db\driver\driver_interface $db, \blitze\content\services\types $content_types, \blitze\content\services\fields $fields, $phpbb_root_path, $php_ext) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->db = $db; |
|
43
|
|
|
$this->content_types = $content_types; |
|
44
|
|
|
$this->fields = $fields; |
|
45
|
|
|
$this->phpbb_root_path = $phpbb_root_path; |
|
46
|
|
|
$this->php_ext = $php_ext; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return array |
|
51
|
|
|
*/ |
|
52
|
|
|
static public function getSubscribedEvents() |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
return array( |
|
55
|
|
|
'core.mcp_topic_modify_post_data' => 'modify_post_data', |
|
56
|
|
|
'core.mcp_topic_review_modify_row' => 'modify_review_row', |
|
57
|
|
|
'core.mcp_view_forum_modify_sql' => 'modify_forum_sql', |
|
58
|
|
|
'core.mcp_queue_get_posts_for_topics_query_before' => 'modify_topic_queue_sql', |
|
59
|
|
|
'core.mcp_front_queue_unapproved_total_before' => 'modify_forumlist', |
|
60
|
|
|
'core.mcp_front_view_queue_postid_list_after' => 'modify_forumlist', |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param \phpbb\event\data $event |
|
66
|
|
|
* @return void |
|
67
|
|
|
*/ |
|
68
|
|
|
public function modify_post_data(\phpbb\event\data $event) |
|
69
|
|
|
{ |
|
70
|
|
|
// We use $event['rowset'][0]['forum_id'] instead of $event['forum_id'] because forum_id is not guaranteed |
|
|
|
|
|
|
71
|
|
|
// as it is only retrieved from url parameters on topic view but links from pagination does not include forumid |
|
72
|
|
|
$this->type = $this->content_types->get_forum_type($event['rowset'][0]['forum_id']); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param \phpbb\event\data $event |
|
77
|
|
|
* @return void |
|
78
|
|
|
*/ |
|
79
|
|
|
public function modify_review_row(\phpbb\event\data $event) |
|
80
|
|
|
{ |
|
81
|
|
|
if ($event['row']['post_id'] === $event['topic_info']['topic_first_post_id'] && $this->type) |
|
82
|
|
|
{ |
|
83
|
|
|
$entity = $this->content_types->get_type($this->type); |
|
84
|
|
|
$this->fields->prepare_to_show($this->type, 'summary', $entity->get_summary_tags(), $entity->get_content_fields(), $entity->get_summary_tpl()); |
|
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
$post_row = $event['post_row']; |
|
87
|
|
|
$content = $this->fields->build_content($post_row); |
|
88
|
|
|
$post_row['MESSAGE'] = isset($content['SEQ_DISPLAY']) ? $content['SEQ_DISPLAY'] : $content['CUSTOM_DISPLAY']; |
|
89
|
|
|
|
|
90
|
|
|
$event['post_row'] = $post_row; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param \phpbb\event\data $event |
|
96
|
|
|
* @return void |
|
97
|
|
|
*/ |
|
98
|
|
|
public function modify_forum_sql(\phpbb\event\data $event) |
|
99
|
|
|
{ |
|
100
|
|
|
$types = $this->content_types->get_forum_types(); |
|
101
|
|
|
|
|
102
|
|
|
if ($types[$event['forum_id']]) |
|
103
|
|
|
{ |
|
104
|
|
|
redirect(append_sid("{$this->phpbb_root_path}mcp.$this->php_ext")); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @param \phpbb\event\data $event |
|
110
|
|
|
* @return void |
|
111
|
|
|
*/ |
|
112
|
|
|
public function modify_topic_queue_sql(\phpbb\event\data $event) |
|
113
|
|
|
{ |
|
114
|
|
|
$forum_list = $event['forum_list']; |
|
115
|
|
|
$forum_list = is_array($forum_list) ? $forum_list : array($forum_list); |
|
116
|
|
|
|
|
117
|
|
|
$sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, t.topic_title AS post_subject, t.topic_time AS post_time, t.topic_poster AS poster_id, t.topic_first_post_id AS post_id, t.topic_attachment AS post_attachment, t.topic_first_poster_name AS username, t.topic_first_poster_colour AS user_colour |
|
118
|
|
|
FROM ' . TOPICS_TABLE . ' t |
|
119
|
|
|
WHERE ' . $this->db->sql_in_set('forum_id', $this->get_forum_list($forum_list)) . ' |
|
120
|
|
|
AND ' . $this->db->sql_in_set('topic_visibility', $event['visibility_const']) . " |
|
121
|
|
|
AND topic_delete_user <> 0 |
|
122
|
|
|
{$event['limit_time_sql']} |
|
123
|
|
|
ORDER BY {$event['sort_order_sql']}"; |
|
124
|
|
|
|
|
125
|
|
|
$event['sql'] = $sql; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param \phpbb\event\data $event |
|
130
|
|
|
* @return void |
|
131
|
|
|
*/ |
|
132
|
|
|
public function modify_forumlist(\phpbb\event\data $event) |
|
133
|
|
|
{ |
|
134
|
|
|
$event['forum_list'] = $this->get_forum_list($event['forum_list']); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param array |
|
139
|
|
|
* @return array |
|
140
|
|
|
*/ |
|
141
|
|
|
protected function get_forum_list(array $forum_list) |
|
142
|
|
|
{ |
|
143
|
|
|
$types = $this->content_types->get_forum_types(); |
|
144
|
|
|
$forum_ids = array_diff($forum_list, array_keys($types)); |
|
145
|
|
|
|
|
146
|
|
|
return sizeof($forum_ids) ? $forum_ids : array(0); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|