Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
2.04% |
1 / 49 |
|
8.33% |
1 / 12 |
CRAP | |
0.00% |
0 / 1 |
report_post | |
2.04% |
1 / 49 |
|
8.33% |
1 / 12 |
198.24 | |
0.00% |
0 / 1 |
get_type | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
get_style_class | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
find_users_for_notification | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
get_email_template | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_email_template_variables | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
get_url | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_title | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
get_reference | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
get_reason | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |||
get_avatar | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
users_to_query | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
create_insert_array | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | namespace phpbb\notification\type; |
15 | |
16 | /** |
17 | * Reported post notifications class |
18 | * This class handles notifications for reported posts |
19 | */ |
20 | class report_post extends \phpbb\notification\type\post_in_queue |
21 | { |
22 | /** |
23 | * Get notification type name |
24 | * |
25 | * @return string |
26 | */ |
27 | public function get_type() |
28 | { |
29 | return 'notification.type.report_post'; |
30 | } |
31 | |
32 | /** |
33 | * Get the CSS style class of the notification |
34 | * |
35 | * @return string |
36 | */ |
37 | public function get_style_class() |
38 | { |
39 | return 'notification-reported'; |
40 | } |
41 | |
42 | /** |
43 | * Language key used to output the text |
44 | * |
45 | * @var string |
46 | */ |
47 | protected $language_key = 'NOTIFICATION_REPORT_POST'; |
48 | |
49 | /** |
50 | * Inherit notification read status from post. |
51 | * |
52 | * @var bool |
53 | */ |
54 | protected $inherit_read_status = false; |
55 | |
56 | /** |
57 | * Permission to check for (in find_users_for_notification) |
58 | * |
59 | * @var string Permission name |
60 | */ |
61 | protected $permission = 'm_report'; |
62 | |
63 | /** |
64 | * Notification option data (for outputting to the user) |
65 | * |
66 | * @var bool|array False if the service should use it's default data |
67 | * Array of data (including keys 'id' and 'lang') |
68 | */ |
69 | public static $notification_option = array( |
70 | 'id' => 'notification.type.report', |
71 | 'lang' => 'NOTIFICATION_TYPE_REPORT', |
72 | 'group' => 'NOTIFICATION_GROUP_MODERATION', |
73 | ); |
74 | |
75 | /** |
76 | * Find the users who want to receive notifications |
77 | * |
78 | * @param array $type_data Data from the post |
79 | * @param array $options Options for finding users for notification |
80 | * |
81 | * @return array |
82 | */ |
83 | public function find_users_for_notification($type_data, $options = array()) |
84 | { |
85 | $notify_users = parent::find_users_for_notification($type_data, $options); |
86 | |
87 | // never notify reporter |
88 | unset($notify_users[$this->user->data['user_id']]); |
89 | |
90 | return $notify_users; |
91 | } |
92 | |
93 | /** |
94 | * {@inheritdoc} |
95 | */ |
96 | public function get_email_template() |
97 | { |
98 | return 'report_post'; |
99 | } |
100 | |
101 | /** |
102 | * Get email template variables |
103 | * |
104 | * @return array |
105 | */ |
106 | public function get_email_template_variables() |
107 | { |
108 | $board_url = generate_board_url(); |
109 | |
110 | return array( |
111 | 'POST_SUBJECT' => html_entity_decode(censor_text($this->get_data('post_subject')), ENT_COMPAT), |
112 | 'TOPIC_TITLE' => html_entity_decode(censor_text($this->get_data('topic_title')), ENT_COMPAT), |
113 | |
114 | 'U_VIEW_REPORT' => "{$board_url}/mcp.{$this->php_ext}?p={$this->item_id}&i=reports&mode=report_details#reports", |
115 | 'U_VIEW_POST' => "{$board_url}/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", |
116 | 'U_NEWEST_POST' => "{$board_url}/viewtopic.{$this->php_ext}?t={$this->item_parent_id}&view=unread#unread", |
117 | 'U_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?t={$this->item_parent_id}", |
118 | 'U_VIEW_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?t={$this->item_parent_id}", |
119 | 'U_FORUM' => "{$board_url}/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}", |
120 | ); |
121 | } |
122 | |
123 | /** |
124 | * Get the url to this item |
125 | * |
126 | * @return string URL |
127 | */ |
128 | public function get_url() |
129 | { |
130 | return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "p={$this->item_id}&i=reports&mode=report_details#reports"); |
131 | } |
132 | |
133 | /** |
134 | * Get the HTML formatted title of this notification |
135 | * |
136 | * @return string |
137 | */ |
138 | public function get_title() |
139 | { |
140 | $this->language->add_lang('mcp'); |
141 | |
142 | $username = $this->user_loader->get_username($this->get_data('reporter_id'), 'no_profile'); |
143 | |
144 | return $this->language->lang( |
145 | $this->language_key, |
146 | $username |
147 | ); |
148 | } |
149 | |
150 | /** |
151 | * Get the HTML formatted reference of the notification |
152 | * |
153 | * @return string |
154 | */ |
155 | public function get_reference() |
156 | { |
157 | return $this->language->lang( |
158 | 'NOTIFICATION_REFERENCE', |
159 | censor_text($this->get_data('post_subject')) |
160 | ); |
161 | } |
162 | |
163 | /** |
164 | * Get the reason for the notification |
165 | * |
166 | * @return string |
167 | */ |
168 | public function get_reason() |
169 | { |
170 | if ($this->get_data('report_text')) |
171 | { |
172 | return $this->language->lang( |
173 | 'NOTIFICATION_REASON', |
174 | $this->get_data('report_text') |
175 | ); |
176 | } |
177 | |
178 | if ($this->language->is_set($this->get_data('reason_title'))) |
179 | { |
180 | return $this->language->lang( |
181 | 'NOTIFICATION_REASON', |
182 | $this->language->lang($this->get_data('reason_title')) |
183 | ); |
184 | } |
185 | |
186 | return $this->language->lang( |
187 | 'NOTIFICATION_REASON', |
188 | $this->get_data('reason_description') |
189 | ); |
190 | } |
191 | |
192 | /** |
193 | * Get the user's avatar |
194 | */ |
195 | public function get_avatar() |
196 | { |
197 | return $this->user_loader->get_avatar($this->get_data('reporter_id'), false, true); |
198 | } |
199 | |
200 | /** |
201 | * Users needed to query before this notification can be displayed |
202 | * |
203 | * @return array Array of user_ids |
204 | */ |
205 | public function users_to_query() |
206 | { |
207 | return array($this->get_data('reporter_id')); |
208 | } |
209 | |
210 | /** |
211 | * {@inheritdoc} |
212 | */ |
213 | public function create_insert_array($type_data, $pre_create_data = array()) |
214 | { |
215 | $this->set_data('reporter_id', $this->user->data['user_id']); |
216 | $this->set_data('reason_title', strtoupper($type_data['reason_title'])); |
217 | $this->set_data('reason_description', $type_data['reason_description']); |
218 | $this->set_data('report_text', $type_data['report_text']); |
219 | |
220 | parent::create_insert_array($type_data, $pre_create_data); |
221 | } |
222 | } |