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
|
|
|
/** @var string */ |
32
|
|
|
private $type; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Constructor |
36
|
|
|
* |
37
|
|
|
* @param \phpbb\db\driver\driver_interface $db Database object |
38
|
|
|
* @param \blitze\content\services\types $content_types Content types object |
39
|
|
|
* @param \blitze\content\services\fields $fields Content fields object |
40
|
|
|
* @param string $phpbb_root_path Path to the phpbb includes directory. |
41
|
|
|
* @param string $php_ext php file extension |
42
|
|
|
*/ |
43
|
|
|
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) |
44
|
|
|
{ |
45
|
|
|
$this->db = $db; |
46
|
|
|
$this->content_types = $content_types; |
47
|
|
|
$this->fields = $fields; |
48
|
|
|
$this->phpbb_root_path = $phpbb_root_path; |
49
|
|
|
$this->php_ext = $php_ext; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return array |
54
|
|
|
*/ |
55
|
|
|
public static function getSubscribedEvents() |
56
|
|
|
{ |
57
|
|
|
return array( |
58
|
|
|
'core.mcp_topic_modify_post_data' => 'modify_post_data', |
59
|
|
|
'core.mcp_topic_review_modify_row' => 'modify_review_row', |
60
|
|
|
'core.mcp_view_forum_modify_sql' => 'modify_forum_sql', |
61
|
|
|
'core.mcp_queue_get_posts_for_topics_query_before' => 'modify_topic_queue_sql', |
62
|
|
|
'core.mcp_front_queue_unapproved_total_before' => 'modify_forumlist', |
63
|
|
|
'core.mcp_front_view_queue_postid_list_after' => 'modify_forumlist', |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param \phpbb\event\data $event |
69
|
|
|
* @return void |
70
|
|
|
*/ |
71
|
|
|
public function modify_post_data(\phpbb\event\data $event) |
72
|
|
|
{ |
73
|
|
|
$forum_type = $this->content_types->get_forum_type($event['rowset'][0]['forum_id']); |
74
|
|
|
$this->type = $forum_type ?: ''; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param \phpbb\event\data $event |
79
|
|
|
* @return void |
80
|
|
|
*/ |
81
|
|
|
public function modify_review_row(\phpbb\event\data $event) |
82
|
|
|
{ |
83
|
|
|
if ($this->type && $event['row']['post_id'] === $event['topic_info']['topic_first_post_id'] && ($entity = $this->content_types->get_type($this->type)) !== false) |
84
|
|
|
{ |
85
|
|
|
$this->fields->prepare_to_show($entity, array($event['topic_info']['topic_id']), $entity->get_summary_fields(), $entity->get_summary_tpl(), 'summary'); |
86
|
|
|
$users_cache = $attachments = $topic_tracking_info = $update_count = array(); |
87
|
|
|
|
88
|
|
|
$post_row = (array) $event['post_row']; |
89
|
|
|
$topic_data = $event['topic_info']; |
90
|
|
|
$post_data = array_merge($post_row, $event['row']); |
91
|
|
|
$users_cache[$post_data['poster_id']] = array(); |
92
|
|
|
|
93
|
|
|
$tpl_data = $this->fields->get_summary_template_data($this->type, $topic_data, $post_data, $users_cache, $attachments, $topic_tracking_info, $update_count); |
|
|
|
|
94
|
|
|
$content = $this->fields->build_content($tpl_data); |
95
|
|
|
|
96
|
|
|
$post_row['MESSAGE'] = isset($content['CUSTOM_DISPLAY']) ? $content['CUSTOM_DISPLAY'] : join('', $content['FIELDS']['all']); |
97
|
|
|
$event['post_row'] = $post_row; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param \phpbb\event\data $event |
103
|
|
|
* @return void |
104
|
|
|
*/ |
105
|
|
|
public function modify_forum_sql(\phpbb\event\data $event) |
106
|
|
|
{ |
107
|
|
|
$types = $this->content_types->get_forum_types(); |
108
|
|
|
|
109
|
|
|
if ($types[$event['forum_id']]) |
110
|
|
|
{ |
111
|
|
|
redirect(append_sid("{$this->phpbb_root_path}mcp.$this->php_ext")); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param \phpbb\event\data $event |
117
|
|
|
* @return void |
118
|
|
|
*/ |
119
|
|
|
public function modify_topic_queue_sql(\phpbb\event\data $event) |
120
|
|
|
{ |
121
|
|
|
$forum_list = $event['forum_list']; |
122
|
|
|
$forum_list = is_array($forum_list) ? $forum_list : array($forum_list); |
123
|
|
|
|
124
|
|
|
$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 |
125
|
|
|
FROM ' . TOPICS_TABLE . ' t |
126
|
|
|
WHERE ' . $this->db->sql_in_set('forum_id', $this->get_forum_list($forum_list)) . ' |
127
|
|
|
AND ' . $this->db->sql_in_set('topic_visibility', $event['visibility_const']) . " |
128
|
|
|
AND topic_delete_user <> 0 |
129
|
|
|
{$event['limit_time_sql']} |
130
|
|
|
ORDER BY {$event['sort_order_sql']}"; |
131
|
|
|
|
132
|
|
|
$event['sql'] = $sql; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param \phpbb\event\data $event |
137
|
|
|
* @return void |
138
|
|
|
*/ |
139
|
|
|
public function modify_forumlist(\phpbb\event\data $event) |
140
|
|
|
{ |
141
|
|
|
$event['forum_list'] = $this->get_forum_list((array) $event['forum_list']); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @param array |
146
|
|
|
* @return array |
147
|
|
|
*/ |
148
|
|
|
protected function get_forum_list(array $forum_list) |
149
|
|
|
{ |
150
|
|
|
$types = $this->content_types->get_forum_types(); |
151
|
|
|
$forum_ids = array_diff($forum_list, array_keys($types)); |
152
|
|
|
|
153
|
|
|
return sizeof($forum_ids) ? $forum_ids : array(0); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|