@@ -18,533 +18,533 @@ |
||
18 | 18 | class listener implements EventSubscriberInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** @var \phpbb\auth\auth */ |
|
22 | - protected $auth; |
|
23 | - |
|
24 | - /** @var \phpbb\config\config */ |
|
25 | - protected $config; |
|
26 | - |
|
27 | - /** @var \phpbb\template\template */ |
|
28 | - protected $template; |
|
29 | - |
|
30 | - /** @var \phpbb\request\request */ |
|
31 | - protected $request; |
|
32 | - |
|
33 | - /** @var \phpbb\user */ |
|
34 | - protected $user; |
|
35 | - |
|
36 | - /** @var \phpbb\path_helper */ |
|
37 | - protected $path_helper; |
|
38 | - |
|
39 | - /** @var string phpbb_root_path */ |
|
40 | - protected $phpbb_root_path; |
|
41 | - |
|
42 | - /** |
|
43 | - * Constructor |
|
44 | - * |
|
45 | - * @param \phpbb\auth\auth auth Authentication object |
|
46 | - * @param \phpbb\config\config $config Config Object |
|
47 | - * @param \phpbb\template\template $template Template object |
|
48 | - * @param \phpbb\request\request $request Request object |
|
49 | - * @param \phpbb\user $user User Object |
|
50 | - * @param \phpbb\path_helper $path_helper Controller helper object |
|
51 | - * @param string $phpbb_root_path phpbb_root_path |
|
52 | - * @access public |
|
53 | - */ |
|
54 | - public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\template\template $template, \phpbb\request\request $request, \phpbb\user $user, \phpbb\path_helper $path_helper, $phpbb_root_path) |
|
55 | - { |
|
56 | - $this->auth = $auth; |
|
57 | - $this->config = $config; |
|
58 | - $this->template = $template; |
|
59 | - $this->request = $request; |
|
60 | - $this->user = $user; |
|
61 | - $this->path_helper = $path_helper; |
|
62 | - $this->phpbb_root_path = $phpbb_root_path; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Assign functions defined in this class to event listeners in the core |
|
67 | - * |
|
68 | - * @return array |
|
69 | - * @static |
|
70 | - * @access public |
|
71 | - */ |
|
72 | - static public function getSubscribedEvents() |
|
73 | - { |
|
74 | - return array( |
|
75 | - 'core.display_forums_modify_sql' => 'display_forums_modify_sql', |
|
76 | - 'core.display_forums_modify_template_vars' => 'display_forums_modify_template_vars', |
|
77 | - 'core.display_forums_modify_forum_rows' => 'display_forums_modify_forum_rows', |
|
78 | - 'core.display_forums_modify_sql' => 'display_forums_modify_sql', |
|
79 | - 'core.generate_forum_nav' => 'generate_forum_nav', |
|
80 | - 'core.make_jumpbox_modify_tpl_ary' => 'make_jumpbox_modify_tpl_ary', // Not in phpBB |
|
81 | - 'core.pagination_generate_page_link' => 'pagination_generate_page_link', |
|
82 | - 'core.search_modify_tpl_ary' => 'search_modify_tpl_ary', |
|
83 | - 'core.viewforum_modify_topicrow' => 'viewforum_modify_topicrow', |
|
84 | - 'core.viewforum_get_topic_data' => 'viewforum_get_topic_data', |
|
85 | - 'core.viewtopic_assign_template_vars_before' => 'viewtopic_assign_template_vars_before', |
|
86 | - 'core.viewtopic_modify_page_title' => 'viewtopic_modify_page_title', |
|
87 | - 'core.viewtopic_modify_post_row' => 'viewtopic_modify_post_row', |
|
88 | - 'core.viewtopic_get_post_data' => 'viewtopic_get_post_data', |
|
89 | - |
|
90 | - // Rewrite other Extensions |
|
91 | - 'rmcgirr83.topfive.sql_pull_topics_data' => 'topfive_sql_pull_topics_data', |
|
92 | - 'rmcgirr83.topfive.modify_tpl_ary' => 'topfive_modify_tpl_ary', |
|
93 | - 'tas2580.sitemap_modify_before_output' => 'sitemap_modify_before_output', |
|
94 | - 'vse.similartopics.modify_topicrow' => 'similartopics_modify_topicrow', |
|
95 | - ); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Get informations for the last post from Database |
|
100 | - * |
|
101 | - * @param object $event The event object |
|
102 | - * @return null |
|
103 | - * @access public |
|
104 | - */ |
|
105 | - public function display_forums_modify_sql($event) |
|
106 | - { |
|
107 | - $sql_array = $event['sql_ary']; |
|
108 | - $sql_array['LEFT_JOIN'][] = array( |
|
109 | - 'FROM' => array(TOPICS_TABLE => 't'), |
|
110 | - 'ON' => "f.forum_last_post_id = t.topic_last_post_id" |
|
111 | - ); |
|
112 | - $sql_array['SELECT'] .= ', t.topic_title, t.topic_id, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted'; |
|
113 | - $event['sql_ary'] = $sql_array; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Store informations for the last post in forum_rows array |
|
118 | - * |
|
119 | - * @param object $event The event object |
|
120 | - * @return null |
|
121 | - * @access public |
|
122 | - */ |
|
123 | - public function display_forums_modify_forum_rows($event) |
|
124 | - { |
|
125 | - $forum_rows = $event['forum_rows']; |
|
126 | - if ($event['row']['forum_last_post_time'] == $forum_rows[$event['parent_id']]['forum_last_post_time']) |
|
127 | - { |
|
128 | - $forum_rows[$event['parent_id']]['forum_name_last_post'] =$event['row']['forum_name']; |
|
129 | - $forum_rows[$event['parent_id']]['topic_id_last_post'] =$event['row']['topic_id']; |
|
130 | - $forum_rows[$event['parent_id']]['topic_title_last_post'] =$event['row']['topic_title']; |
|
131 | - $event['forum_rows'] = $forum_rows; |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Rewrite links to forums and subforums in forum index |
|
137 | - * also correct the path of the forum images if we are in a forum |
|
138 | - * |
|
139 | - * @param object $event The event object |
|
140 | - * @return null |
|
141 | - * @access public |
|
142 | - */ |
|
143 | - public function display_forums_modify_template_vars($event) |
|
144 | - { |
|
145 | - // Rewrite URLs of sub forums |
|
146 | - $subforums_row = $event['subforums_row']; |
|
147 | - foreach ($subforums_row as $i => $subforum) |
|
148 | - { |
|
149 | - // A little bit a dirty way, but there is no better solution |
|
150 | - $query = str_replace('&', '&', parse_url($subforum['U_SUBFORUM'], PHP_URL_QUERY)); |
|
151 | - parse_str($query, $id); |
|
152 | - $subforums_row[$i]['U_SUBFORUM'] = append_sid($this->generate_forum_link($id['f'], $subforum['SUBFORUM_NAME'])); |
|
153 | - } |
|
154 | - $event['subforums_row'] = $subforums_row; |
|
155 | - |
|
156 | - $forum_row = $event['forum_row']; |
|
157 | - |
|
158 | - // Update the image source in forums |
|
159 | - $img = $this->path_helper->update_web_root_path($forum_row['FORUM_IMAGE_SRC']); |
|
160 | - $forum_row['FORUM_IMAGE'] = preg_replace('#img src=\"(.*)\" alt#', 'img src="' . $img . '" alt', $forum_row['FORUM_IMAGE']); |
|
161 | - |
|
162 | - // Rewrite links to topics, posts and forums |
|
163 | - $replies = $this->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1; |
|
164 | - $url = $this->generate_topic_link($event['row']['forum_id_last_post'], $event['row']['forum_name_last_post'], $event['row']['topic_id_last_post'], $event['row']['topic_title_last_post']); |
|
165 | - $forum_row['U_LAST_POST'] = append_sid($this->generate_lastpost_link($replies, $url) . '#p' . $event['row']['forum_last_post_id']); |
|
166 | - $forum_row['U_VIEWFORUM'] = append_sid($this->generate_forum_link($forum_row['FORUM_ID'], $forum_row['FORUM_NAME'])); |
|
167 | - $event['forum_row'] = $forum_row; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Rewrite links in breadcrumbs |
|
172 | - * |
|
173 | - * @param object $event The event object |
|
174 | - * @return null |
|
175 | - * @access public |
|
176 | - */ |
|
177 | - public function generate_forum_nav($event) |
|
178 | - { |
|
179 | - $forum_data = $event['forum_data']; |
|
180 | - $navlinks = $event['navlinks']; |
|
181 | - $navlinks_parents = $event['navlinks_parents']; |
|
182 | - |
|
183 | - foreach ($navlinks_parents as $id => $data) |
|
184 | - { |
|
185 | - $navlinks_parents[$id]['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($data['FORUM_ID'] , $data['FORUM_NAME'])); |
|
186 | - } |
|
187 | - |
|
188 | - $navlinks['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($forum_data['forum_id'], $forum_data['forum_name'])); |
|
189 | - $event['navlinks'] = $navlinks; |
|
190 | - $event['navlinks_parents'] = $navlinks_parents; |
|
191 | - } |
|
192 | - |
|
193 | - // Not in phpBB |
|
194 | - public function make_jumpbox_modify_tpl_ary($event) |
|
195 | - { |
|
196 | - $tpl_ary = $event['tpl_ary']; |
|
197 | - $row = $event['row']; |
|
198 | - foreach ($tpl_ary as $id => $data) |
|
199 | - { |
|
200 | - |
|
201 | - $tpl_ary[$id]['LINK'] = append_sid($this->generate_forum_link($row['forum_id'], $row['forum_name'])); |
|
202 | - } |
|
203 | - |
|
204 | - $event['tpl_ary'] = $tpl_ary; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Rewrite pagination links |
|
209 | - * |
|
210 | - * @param object $event The event object |
|
211 | - * @return null |
|
212 | - * @access public |
|
213 | - */ |
|
214 | - public function pagination_generate_page_link($event) |
|
215 | - { |
|
216 | - // If we have a sort key we do not rewrite the URL |
|
217 | - $query = str_replace('&', '&', parse_url($event['base_url'], PHP_URL_QUERY)); |
|
218 | - parse_str($query, $param); |
|
219 | - if (isset($param['sd']) || isset($param['sk']) || isset($param['st'])) |
|
220 | - { |
|
221 | - return; |
|
222 | - } |
|
223 | - |
|
224 | - $start = (($event['on_page'] - 1) * $event['per_page']); |
|
225 | - if (!empty($this->topic_title)) |
|
226 | - { |
|
227 | - $event['generate_page_link_override'] = append_sid($this->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title, $start)); |
|
228 | - } |
|
229 | - else if (!empty($this->forum_title)) |
|
230 | - { |
|
231 | - $event['generate_page_link_override'] = append_sid($this->generate_forum_link($this->forum_id, $this->forum_title, $start)); |
|
232 | - } |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Rewrite links in the search result |
|
237 | - * |
|
238 | - * @param object $event The event object |
|
239 | - * @return null |
|
240 | - * @access public |
|
241 | - */ |
|
242 | - public function search_modify_tpl_ary($event) |
|
243 | - { |
|
244 | - $replies = $this->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1; |
|
245 | - $u_view_topic = $this->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']); |
|
246 | - |
|
247 | - $tpl_ary = $event['tpl_ary']; |
|
248 | - $tpl_ary['U_LAST_POST'] = append_sid($this->generate_lastpost_link($replies, $u_view_topic) . '#p' . $event['row']['topic_last_post_id']); |
|
249 | - $tpl_ary['U_VIEW_TOPIC'] = append_sid($u_view_topic); |
|
250 | - $tpl_ary['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($event['row']['forum_id'], $event['row']['forum_name'])); |
|
251 | - |
|
252 | - $event['tpl_ary'] = $tpl_ary; |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Rewrite links to topics in forum view |
|
257 | - * |
|
258 | - * @param object $event The event object |
|
259 | - * @return null |
|
260 | - * @access public |
|
261 | - */ |
|
262 | - public function viewforum_modify_topicrow($event) |
|
263 | - { |
|
264 | - $topic_row = $event['topic_row']; |
|
265 | - $this->forum_title = $topic_row['FORUM_NAME']; |
|
266 | - $this->forum_id = $topic_row['FORUM_ID']; |
|
267 | - $this->topic_title = $topic_row['TOPIC_TITLE']; |
|
268 | - $this->topic_id = $topic_row['TOPIC_ID']; |
|
269 | - |
|
270 | - $u_view_topic = $this->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title); |
|
271 | - $topic_row['U_VIEW_TOPIC'] = append_sid($u_view_topic); |
|
272 | - $topic_row['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($this->forum_id, $this->forum_title)); |
|
273 | - $topic_row['U_LAST_POST'] = append_sid($this->generate_lastpost_link($event['topic_row']['REPLIES'], $u_view_topic) . '#p' . $event['row']['topic_last_post_id']); |
|
274 | - |
|
275 | - $event['topic_row'] = $topic_row; |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Rewrite the canonical URL on viewforum.php |
|
280 | - * |
|
281 | - * @param object $event The event object |
|
282 | - * @return null |
|
283 | - * @access public |
|
284 | - */ |
|
285 | - public function viewforum_get_topic_data($event) |
|
286 | - { |
|
287 | - $this->forum_title = $event['forum_data']['forum_name']; |
|
288 | - $this->forum_id = $event['forum_data']['forum_id']; |
|
289 | - $start = $this->request->variable('start', 0); |
|
290 | - $this->template->assign_vars(array( |
|
291 | - 'U_VIEW_FORUM' => append_sid($this->generate_forum_link($this->forum_id, $this->forum_title, $start)), |
|
292 | - 'U_CANONICAL' => $this->generate_forum_link($this->forum_id, $this->forum_title, $start, true), |
|
293 | - )); |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * Rewrite the topic URL for the headline of the topic page and the link back to forum |
|
298 | - * |
|
299 | - * @param object $event The event object |
|
300 | - * @return null |
|
301 | - * @access public |
|
302 | - */ |
|
303 | - public function viewtopic_get_post_data($event) |
|
304 | - { |
|
305 | - $data = $event['topic_data']; |
|
306 | - $this->template->assign_vars(array( |
|
307 | - 'U_VIEW_TOPIC' => append_sid($this->generate_topic_link($event['forum_id'] , $data['forum_name'], $event['topic_id'], $data['topic_title'], $event['start'])), |
|
308 | - 'U_VIEW_FORUM' => append_sid($this->generate_forum_link($event['forum_id'] , $data['forum_name'])), |
|
309 | - )); |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Assign topic data to global variables for pagination |
|
314 | - * |
|
315 | - * @param object $event The event object |
|
316 | - * @return null |
|
317 | - * @access public |
|
318 | - */ |
|
319 | - public function viewtopic_assign_template_vars_before($event) |
|
320 | - { |
|
321 | - $this->forum_title = $event['topic_data']['forum_name']; |
|
322 | - $this->forum_id = $event['topic_data']['forum_id']; |
|
323 | - $this->topic_title = $event['topic_data']['topic_title']; |
|
324 | - $this->topic_id = $event['topic_data']['topic_id']; |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Rewrite the canonical URL on viewtopic.php |
|
329 | - * |
|
330 | - * @param object $event The event object |
|
331 | - * @return null |
|
332 | - * @access public |
|
333 | - */ |
|
334 | - public function viewtopic_modify_page_title($event) |
|
335 | - { |
|
336 | - $start = $this->request->variable('start', 0); |
|
337 | - $data = $event['topic_data']; |
|
338 | - $this->template->assign_vars(array( |
|
339 | - 'U_CANONICAL' => $this->generate_topic_link($data['forum_id'], $data['forum_name'], $data['topic_id'], $data['topic_title'], $start, true), |
|
340 | - )); |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Rewrite mini post img link |
|
345 | - * |
|
346 | - * @param object $event The event object |
|
347 | - * @return null |
|
348 | - * @access public |
|
349 | - */ |
|
350 | - public function viewtopic_modify_post_row($event) |
|
351 | - { |
|
352 | - $row = $event['post_row']; |
|
353 | - $start = $this->request->variable('start', 0); |
|
354 | - $data = $event['topic_data']; |
|
355 | - $row['U_MINI_POST'] = append_sid($this->generate_topic_link($data['forum_id'], $data['forum_name'], $data['topic_id'], $data['topic_title'], $start) . '#p' . $event['row']['post_id']); |
|
356 | - $event['post_row'] = $row; |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Rewrite URLs in tas2580 Sitemap Extension |
|
361 | - * |
|
362 | - * @param object $event The event object |
|
363 | - * @return null |
|
364 | - * @access public |
|
365 | - */ |
|
366 | - public function sitemap_modify_before_output($event) |
|
367 | - { |
|
368 | - // Nothing to rewrite in the sitemap index |
|
369 | - if ($event['type'] == 'sitemapindex') |
|
370 | - { |
|
371 | - return; |
|
372 | - } |
|
373 | - |
|
374 | - $url_data =$event['url_data'] ; |
|
375 | - |
|
376 | - foreach ($url_data as $id => $data) |
|
377 | - { |
|
378 | - $row = $data['row']; |
|
379 | - if (isset($row['topic_id'])) |
|
380 | - { |
|
381 | - $url_data[$id]['url'] = $this->generate_topic_link($row['forum_id'], $row['forum_name'], $row['topic_id'], $row['topic_title'], $data['start'], true); |
|
382 | - } |
|
383 | - else if (isset($row['forum_id'])) |
|
384 | - { |
|
385 | - $url_data[$id]['url'] = $this->generate_forum_link($row['forum_id'], $row['forum_name'], $data['start'], true); |
|
386 | - } |
|
387 | - } |
|
388 | - |
|
389 | - $event['url_data'] = $url_data; |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
393 | - * Rewrite URLs in Similar Topics Extension |
|
394 | - * |
|
395 | - * @param object $event The event object |
|
396 | - * @return null |
|
397 | - * @access public |
|
398 | - */ |
|
399 | - public function similartopics_modify_topicrow($event) |
|
400 | - { |
|
401 | - $this->forum_title = $event['row']['forum_name']; |
|
402 | - $this->forum_id = $event['row']['forum_id']; |
|
403 | - $this->topic_title = $event['row']['topic_title']; |
|
404 | - $this->topic_id = $event['row']['topic_id']; |
|
405 | - |
|
406 | - $topic_row = $event['topic_row']; |
|
407 | - $u_view_topic= $this->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title); |
|
408 | - $topic_row['U_VIEW_TOPIC'] = append_sid($u_view_topic); |
|
409 | - $topic_row['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($this->forum_id, $this->forum_title)); |
|
410 | - $topic_row['U_LAST_POST'] = append_sid($this->generate_lastpost_link($topic_row['TOPIC_REPLIES'], $u_view_topic) . '#p' . $event['row']['topic_last_post_id']); |
|
411 | - $event['topic_row'] = $topic_row; |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * Rewrite URLs in Top 5 Extension |
|
416 | - * |
|
417 | - * @param object $event The event object |
|
418 | - * @return null |
|
419 | - * @access public |
|
420 | - */ |
|
421 | - public function topfive_sql_pull_topics_data($event) |
|
422 | - { |
|
423 | - $sql_array = $event['sql_array']; |
|
424 | - $sql_array['SELECT'] = array_merge($sql_array, array('SELECT' => 'f.forum_name')); |
|
425 | - $sql_array['LEFT_JOIN'] = array_merge($sql_array['LEFT_JOIN'], array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id')); |
|
426 | - // $event['sql_array'] = $sql_array; |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * Rewrite URLs in Top 5 Extension |
|
431 | - * |
|
432 | - * @param object $event The event object |
|
433 | - * @return null |
|
434 | - * @access public |
|
435 | - */ |
|
436 | - public function topfive_modify_tpl_ary($event) |
|
437 | - { |
|
438 | - $tpl_ary = $event['tpl_ary']; |
|
439 | - $replies = $this->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1; |
|
440 | - $u_view_topic = $this->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']); |
|
441 | - $tpl_ary['U_TOPIC'] = append_sid($this->generate_lastpost_link($replies, $u_view_topic) . '#p' . $event['row']['topic_last_post_id']); |
|
442 | - $event['tpl_ary'] = $tpl_ary; |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * Generate the SEO link for a topic |
|
447 | - * |
|
448 | - * @param int $forum_id The ID of the forum |
|
449 | - * @param string $forum_name The title of the forum |
|
450 | - * @param int $topic_id The ID if the topic |
|
451 | - * @param string $topic_title The title of the topic |
|
452 | - * @param int $start Optional start parameter |
|
453 | - * @param bool $full Return the full URL |
|
454 | - * @return string The SEO URL |
|
455 | - * @access private |
|
456 | - */ |
|
457 | - private function generate_topic_link($forum_id, $forum_name, $topic_id, $topic_title, $start = 0, $full = false) |
|
458 | - { |
|
459 | - if ($full) |
|
460 | - { |
|
461 | - return generate_board_url() . '/' . $this->title_to_url($forum_name) . '-f' . $forum_id . '/' . $this->title_to_url($topic_title) . '-t' . $topic_id . ($start ? '-s' . $start : '') . '.html'; |
|
462 | - } |
|
463 | - return $this->phpbb_root_path . $this->title_to_url($forum_name) . '-f' . $forum_id . '/' . $this->title_to_url($topic_title) . '-t' . $topic_id . ($start ? '-s' . $start : '') . '.html'; |
|
464 | - } |
|
465 | - |
|
466 | - /** |
|
467 | - * Generate the SEO link for a forum |
|
468 | - * |
|
469 | - * @param int $forum_id The ID of the forum |
|
470 | - * @param string $forum_name The title of the forum |
|
471 | - * @param int $start Optional start parameter |
|
472 | - * @param bool $full Return the full URL |
|
473 | - * @return string The SEO URL |
|
474 | - * @access private |
|
475 | - */ |
|
476 | - private function generate_forum_link($forum_id, $forum_name, $start = 0, $full = false) |
|
477 | - { |
|
478 | - if ($full) |
|
479 | - { |
|
480 | - return generate_board_url() . '/' . $this->title_to_url($forum_name) . '-f' . $forum_id . '/' . ($start ? 'index-s' . $start . '.html' : ''); |
|
481 | - } |
|
482 | - return $this->phpbb_root_path . $this->title_to_url($forum_name) . '-f' . $forum_id . '/' . ($start ? 'index-s' . $start . '.html' : ''); |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * |
|
487 | - * @global type $_SID |
|
488 | - * @param int $replies Replays in the topic |
|
489 | - * @param string $url URL oft the topic |
|
490 | - * @return string The URL with start included |
|
491 | - */ |
|
492 | - private function generate_lastpost_link($replies, $url) |
|
493 | - { |
|
494 | - $url = str_replace('.html', '', $url); |
|
495 | - $per_page = ($this->config['posts_per_page'] <= 0) ? 1 : $this->config['posts_per_page']; |
|
496 | - if (($replies + 1) > $per_page) |
|
497 | - { |
|
498 | - for ($j = 0; $j < $replies + 1; $j += $per_page) |
|
499 | - { |
|
500 | - $last_post_link = $url . '-s' . $j . '.html'; |
|
501 | - } |
|
502 | - } |
|
503 | - else |
|
504 | - { |
|
505 | - $last_post_link = $url . '.html'; |
|
506 | - } |
|
507 | - return $last_post_link; |
|
508 | - } |
|
509 | - |
|
510 | - /** |
|
511 | - * Replace letters to use title in URL |
|
512 | - * |
|
513 | - * @param string $title The title to use in the URL |
|
514 | - * @return string Title to use in URLs |
|
515 | - */ |
|
516 | - public static function title_to_url($title) |
|
517 | - { |
|
518 | - $url = strtolower(censor_text(utf8_normalize_nfc(strip_tags($title)))); |
|
519 | - |
|
520 | - // Let's replace |
|
521 | - $url_search = array(' ', 'í', 'ý', 'ß', 'ö', 'ô', 'ó', 'ò', 'ä', 'â', 'à', 'á', 'é', 'è', 'ü', 'ú', 'ù', 'ñ', 'ß', '²', '³', '@', '€', '$'); |
|
522 | - $url_replace = array('-', 'i', 'y', 's', 'oe', 'o', 'o', 'o', 'ae', 'a', 'a', 'a', 'e', 'e', 'ue', 'u', 'u', 'n', 'ss', '2', '3', 'at', 'eur', 'usd'); |
|
523 | - $url = str_replace($url_search, $url_replace, $url); |
|
524 | - $url_search = array('&', '"', '&', '"', "'", '¸', '`', '(', ')', '[', ']', '<', '>', '{', '}', '.', ':', ',', ';', '!', '?', '+', '*', '/', '=', 'µ', '#', '~', '"', '§', '%', '|', '°', '^', '„', '“'); |
|
525 | - $url = str_replace($url_search, '-', $url); |
|
526 | - $url = str_replace(array('----', '---', '--'), '-', $url); |
|
527 | - |
|
528 | - $url = substr($url, 0, 50); // Max length for a title in URL |
|
529 | - return urlencode($url); |
|
530 | - } |
|
531 | - |
|
532 | - /** |
|
533 | - * Get the topics post count or the forums post/topic count based on permissions |
|
534 | - * |
|
535 | - * @param $mode string One of topic_posts, forum_posts or forum_topics |
|
536 | - * @param $data array Array with the topic/forum data to calculate from |
|
537 | - * @param $forum_id int The forum id is used for permission checks |
|
538 | - * @return int Number of posts/topics the user can see in the topic/forum |
|
539 | - */ |
|
540 | - private function get_count($mode, $data, $forum_id) |
|
541 | - { |
|
542 | - if (!$this->auth->acl_get('m_approve', $forum_id)) |
|
543 | - { |
|
544 | - return (int) $data[$mode . '_approved']; |
|
545 | - } |
|
546 | - |
|
547 | - return (int) $data[$mode . '_approved'] + (int) $data[$mode . '_unapproved'] + (int) $data[$mode . '_softdeleted']; |
|
548 | - } |
|
21 | + /** @var \phpbb\auth\auth */ |
|
22 | + protected $auth; |
|
23 | + |
|
24 | + /** @var \phpbb\config\config */ |
|
25 | + protected $config; |
|
26 | + |
|
27 | + /** @var \phpbb\template\template */ |
|
28 | + protected $template; |
|
29 | + |
|
30 | + /** @var \phpbb\request\request */ |
|
31 | + protected $request; |
|
32 | + |
|
33 | + /** @var \phpbb\user */ |
|
34 | + protected $user; |
|
35 | + |
|
36 | + /** @var \phpbb\path_helper */ |
|
37 | + protected $path_helper; |
|
38 | + |
|
39 | + /** @var string phpbb_root_path */ |
|
40 | + protected $phpbb_root_path; |
|
41 | + |
|
42 | + /** |
|
43 | + * Constructor |
|
44 | + * |
|
45 | + * @param \phpbb\auth\auth auth Authentication object |
|
46 | + * @param \phpbb\config\config $config Config Object |
|
47 | + * @param \phpbb\template\template $template Template object |
|
48 | + * @param \phpbb\request\request $request Request object |
|
49 | + * @param \phpbb\user $user User Object |
|
50 | + * @param \phpbb\path_helper $path_helper Controller helper object |
|
51 | + * @param string $phpbb_root_path phpbb_root_path |
|
52 | + * @access public |
|
53 | + */ |
|
54 | + public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\template\template $template, \phpbb\request\request $request, \phpbb\user $user, \phpbb\path_helper $path_helper, $phpbb_root_path) |
|
55 | + { |
|
56 | + $this->auth = $auth; |
|
57 | + $this->config = $config; |
|
58 | + $this->template = $template; |
|
59 | + $this->request = $request; |
|
60 | + $this->user = $user; |
|
61 | + $this->path_helper = $path_helper; |
|
62 | + $this->phpbb_root_path = $phpbb_root_path; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Assign functions defined in this class to event listeners in the core |
|
67 | + * |
|
68 | + * @return array |
|
69 | + * @static |
|
70 | + * @access public |
|
71 | + */ |
|
72 | + static public function getSubscribedEvents() |
|
73 | + { |
|
74 | + return array( |
|
75 | + 'core.display_forums_modify_sql' => 'display_forums_modify_sql', |
|
76 | + 'core.display_forums_modify_template_vars' => 'display_forums_modify_template_vars', |
|
77 | + 'core.display_forums_modify_forum_rows' => 'display_forums_modify_forum_rows', |
|
78 | + 'core.display_forums_modify_sql' => 'display_forums_modify_sql', |
|
79 | + 'core.generate_forum_nav' => 'generate_forum_nav', |
|
80 | + 'core.make_jumpbox_modify_tpl_ary' => 'make_jumpbox_modify_tpl_ary', // Not in phpBB |
|
81 | + 'core.pagination_generate_page_link' => 'pagination_generate_page_link', |
|
82 | + 'core.search_modify_tpl_ary' => 'search_modify_tpl_ary', |
|
83 | + 'core.viewforum_modify_topicrow' => 'viewforum_modify_topicrow', |
|
84 | + 'core.viewforum_get_topic_data' => 'viewforum_get_topic_data', |
|
85 | + 'core.viewtopic_assign_template_vars_before' => 'viewtopic_assign_template_vars_before', |
|
86 | + 'core.viewtopic_modify_page_title' => 'viewtopic_modify_page_title', |
|
87 | + 'core.viewtopic_modify_post_row' => 'viewtopic_modify_post_row', |
|
88 | + 'core.viewtopic_get_post_data' => 'viewtopic_get_post_data', |
|
89 | + |
|
90 | + // Rewrite other Extensions |
|
91 | + 'rmcgirr83.topfive.sql_pull_topics_data' => 'topfive_sql_pull_topics_data', |
|
92 | + 'rmcgirr83.topfive.modify_tpl_ary' => 'topfive_modify_tpl_ary', |
|
93 | + 'tas2580.sitemap_modify_before_output' => 'sitemap_modify_before_output', |
|
94 | + 'vse.similartopics.modify_topicrow' => 'similartopics_modify_topicrow', |
|
95 | + ); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Get informations for the last post from Database |
|
100 | + * |
|
101 | + * @param object $event The event object |
|
102 | + * @return null |
|
103 | + * @access public |
|
104 | + */ |
|
105 | + public function display_forums_modify_sql($event) |
|
106 | + { |
|
107 | + $sql_array = $event['sql_ary']; |
|
108 | + $sql_array['LEFT_JOIN'][] = array( |
|
109 | + 'FROM' => array(TOPICS_TABLE => 't'), |
|
110 | + 'ON' => "f.forum_last_post_id = t.topic_last_post_id" |
|
111 | + ); |
|
112 | + $sql_array['SELECT'] .= ', t.topic_title, t.topic_id, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted'; |
|
113 | + $event['sql_ary'] = $sql_array; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Store informations for the last post in forum_rows array |
|
118 | + * |
|
119 | + * @param object $event The event object |
|
120 | + * @return null |
|
121 | + * @access public |
|
122 | + */ |
|
123 | + public function display_forums_modify_forum_rows($event) |
|
124 | + { |
|
125 | + $forum_rows = $event['forum_rows']; |
|
126 | + if ($event['row']['forum_last_post_time'] == $forum_rows[$event['parent_id']]['forum_last_post_time']) |
|
127 | + { |
|
128 | + $forum_rows[$event['parent_id']]['forum_name_last_post'] =$event['row']['forum_name']; |
|
129 | + $forum_rows[$event['parent_id']]['topic_id_last_post'] =$event['row']['topic_id']; |
|
130 | + $forum_rows[$event['parent_id']]['topic_title_last_post'] =$event['row']['topic_title']; |
|
131 | + $event['forum_rows'] = $forum_rows; |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Rewrite links to forums and subforums in forum index |
|
137 | + * also correct the path of the forum images if we are in a forum |
|
138 | + * |
|
139 | + * @param object $event The event object |
|
140 | + * @return null |
|
141 | + * @access public |
|
142 | + */ |
|
143 | + public function display_forums_modify_template_vars($event) |
|
144 | + { |
|
145 | + // Rewrite URLs of sub forums |
|
146 | + $subforums_row = $event['subforums_row']; |
|
147 | + foreach ($subforums_row as $i => $subforum) |
|
148 | + { |
|
149 | + // A little bit a dirty way, but there is no better solution |
|
150 | + $query = str_replace('&', '&', parse_url($subforum['U_SUBFORUM'], PHP_URL_QUERY)); |
|
151 | + parse_str($query, $id); |
|
152 | + $subforums_row[$i]['U_SUBFORUM'] = append_sid($this->generate_forum_link($id['f'], $subforum['SUBFORUM_NAME'])); |
|
153 | + } |
|
154 | + $event['subforums_row'] = $subforums_row; |
|
155 | + |
|
156 | + $forum_row = $event['forum_row']; |
|
157 | + |
|
158 | + // Update the image source in forums |
|
159 | + $img = $this->path_helper->update_web_root_path($forum_row['FORUM_IMAGE_SRC']); |
|
160 | + $forum_row['FORUM_IMAGE'] = preg_replace('#img src=\"(.*)\" alt#', 'img src="' . $img . '" alt', $forum_row['FORUM_IMAGE']); |
|
161 | + |
|
162 | + // Rewrite links to topics, posts and forums |
|
163 | + $replies = $this->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1; |
|
164 | + $url = $this->generate_topic_link($event['row']['forum_id_last_post'], $event['row']['forum_name_last_post'], $event['row']['topic_id_last_post'], $event['row']['topic_title_last_post']); |
|
165 | + $forum_row['U_LAST_POST'] = append_sid($this->generate_lastpost_link($replies, $url) . '#p' . $event['row']['forum_last_post_id']); |
|
166 | + $forum_row['U_VIEWFORUM'] = append_sid($this->generate_forum_link($forum_row['FORUM_ID'], $forum_row['FORUM_NAME'])); |
|
167 | + $event['forum_row'] = $forum_row; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Rewrite links in breadcrumbs |
|
172 | + * |
|
173 | + * @param object $event The event object |
|
174 | + * @return null |
|
175 | + * @access public |
|
176 | + */ |
|
177 | + public function generate_forum_nav($event) |
|
178 | + { |
|
179 | + $forum_data = $event['forum_data']; |
|
180 | + $navlinks = $event['navlinks']; |
|
181 | + $navlinks_parents = $event['navlinks_parents']; |
|
182 | + |
|
183 | + foreach ($navlinks_parents as $id => $data) |
|
184 | + { |
|
185 | + $navlinks_parents[$id]['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($data['FORUM_ID'] , $data['FORUM_NAME'])); |
|
186 | + } |
|
187 | + |
|
188 | + $navlinks['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($forum_data['forum_id'], $forum_data['forum_name'])); |
|
189 | + $event['navlinks'] = $navlinks; |
|
190 | + $event['navlinks_parents'] = $navlinks_parents; |
|
191 | + } |
|
192 | + |
|
193 | + // Not in phpBB |
|
194 | + public function make_jumpbox_modify_tpl_ary($event) |
|
195 | + { |
|
196 | + $tpl_ary = $event['tpl_ary']; |
|
197 | + $row = $event['row']; |
|
198 | + foreach ($tpl_ary as $id => $data) |
|
199 | + { |
|
200 | + |
|
201 | + $tpl_ary[$id]['LINK'] = append_sid($this->generate_forum_link($row['forum_id'], $row['forum_name'])); |
|
202 | + } |
|
203 | + |
|
204 | + $event['tpl_ary'] = $tpl_ary; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Rewrite pagination links |
|
209 | + * |
|
210 | + * @param object $event The event object |
|
211 | + * @return null |
|
212 | + * @access public |
|
213 | + */ |
|
214 | + public function pagination_generate_page_link($event) |
|
215 | + { |
|
216 | + // If we have a sort key we do not rewrite the URL |
|
217 | + $query = str_replace('&', '&', parse_url($event['base_url'], PHP_URL_QUERY)); |
|
218 | + parse_str($query, $param); |
|
219 | + if (isset($param['sd']) || isset($param['sk']) || isset($param['st'])) |
|
220 | + { |
|
221 | + return; |
|
222 | + } |
|
223 | + |
|
224 | + $start = (($event['on_page'] - 1) * $event['per_page']); |
|
225 | + if (!empty($this->topic_title)) |
|
226 | + { |
|
227 | + $event['generate_page_link_override'] = append_sid($this->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title, $start)); |
|
228 | + } |
|
229 | + else if (!empty($this->forum_title)) |
|
230 | + { |
|
231 | + $event['generate_page_link_override'] = append_sid($this->generate_forum_link($this->forum_id, $this->forum_title, $start)); |
|
232 | + } |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Rewrite links in the search result |
|
237 | + * |
|
238 | + * @param object $event The event object |
|
239 | + * @return null |
|
240 | + * @access public |
|
241 | + */ |
|
242 | + public function search_modify_tpl_ary($event) |
|
243 | + { |
|
244 | + $replies = $this->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1; |
|
245 | + $u_view_topic = $this->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']); |
|
246 | + |
|
247 | + $tpl_ary = $event['tpl_ary']; |
|
248 | + $tpl_ary['U_LAST_POST'] = append_sid($this->generate_lastpost_link($replies, $u_view_topic) . '#p' . $event['row']['topic_last_post_id']); |
|
249 | + $tpl_ary['U_VIEW_TOPIC'] = append_sid($u_view_topic); |
|
250 | + $tpl_ary['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($event['row']['forum_id'], $event['row']['forum_name'])); |
|
251 | + |
|
252 | + $event['tpl_ary'] = $tpl_ary; |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Rewrite links to topics in forum view |
|
257 | + * |
|
258 | + * @param object $event The event object |
|
259 | + * @return null |
|
260 | + * @access public |
|
261 | + */ |
|
262 | + public function viewforum_modify_topicrow($event) |
|
263 | + { |
|
264 | + $topic_row = $event['topic_row']; |
|
265 | + $this->forum_title = $topic_row['FORUM_NAME']; |
|
266 | + $this->forum_id = $topic_row['FORUM_ID']; |
|
267 | + $this->topic_title = $topic_row['TOPIC_TITLE']; |
|
268 | + $this->topic_id = $topic_row['TOPIC_ID']; |
|
269 | + |
|
270 | + $u_view_topic = $this->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title); |
|
271 | + $topic_row['U_VIEW_TOPIC'] = append_sid($u_view_topic); |
|
272 | + $topic_row['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($this->forum_id, $this->forum_title)); |
|
273 | + $topic_row['U_LAST_POST'] = append_sid($this->generate_lastpost_link($event['topic_row']['REPLIES'], $u_view_topic) . '#p' . $event['row']['topic_last_post_id']); |
|
274 | + |
|
275 | + $event['topic_row'] = $topic_row; |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Rewrite the canonical URL on viewforum.php |
|
280 | + * |
|
281 | + * @param object $event The event object |
|
282 | + * @return null |
|
283 | + * @access public |
|
284 | + */ |
|
285 | + public function viewforum_get_topic_data($event) |
|
286 | + { |
|
287 | + $this->forum_title = $event['forum_data']['forum_name']; |
|
288 | + $this->forum_id = $event['forum_data']['forum_id']; |
|
289 | + $start = $this->request->variable('start', 0); |
|
290 | + $this->template->assign_vars(array( |
|
291 | + 'U_VIEW_FORUM' => append_sid($this->generate_forum_link($this->forum_id, $this->forum_title, $start)), |
|
292 | + 'U_CANONICAL' => $this->generate_forum_link($this->forum_id, $this->forum_title, $start, true), |
|
293 | + )); |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * Rewrite the topic URL for the headline of the topic page and the link back to forum |
|
298 | + * |
|
299 | + * @param object $event The event object |
|
300 | + * @return null |
|
301 | + * @access public |
|
302 | + */ |
|
303 | + public function viewtopic_get_post_data($event) |
|
304 | + { |
|
305 | + $data = $event['topic_data']; |
|
306 | + $this->template->assign_vars(array( |
|
307 | + 'U_VIEW_TOPIC' => append_sid($this->generate_topic_link($event['forum_id'] , $data['forum_name'], $event['topic_id'], $data['topic_title'], $event['start'])), |
|
308 | + 'U_VIEW_FORUM' => append_sid($this->generate_forum_link($event['forum_id'] , $data['forum_name'])), |
|
309 | + )); |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * Assign topic data to global variables for pagination |
|
314 | + * |
|
315 | + * @param object $event The event object |
|
316 | + * @return null |
|
317 | + * @access public |
|
318 | + */ |
|
319 | + public function viewtopic_assign_template_vars_before($event) |
|
320 | + { |
|
321 | + $this->forum_title = $event['topic_data']['forum_name']; |
|
322 | + $this->forum_id = $event['topic_data']['forum_id']; |
|
323 | + $this->topic_title = $event['topic_data']['topic_title']; |
|
324 | + $this->topic_id = $event['topic_data']['topic_id']; |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Rewrite the canonical URL on viewtopic.php |
|
329 | + * |
|
330 | + * @param object $event The event object |
|
331 | + * @return null |
|
332 | + * @access public |
|
333 | + */ |
|
334 | + public function viewtopic_modify_page_title($event) |
|
335 | + { |
|
336 | + $start = $this->request->variable('start', 0); |
|
337 | + $data = $event['topic_data']; |
|
338 | + $this->template->assign_vars(array( |
|
339 | + 'U_CANONICAL' => $this->generate_topic_link($data['forum_id'], $data['forum_name'], $data['topic_id'], $data['topic_title'], $start, true), |
|
340 | + )); |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * Rewrite mini post img link |
|
345 | + * |
|
346 | + * @param object $event The event object |
|
347 | + * @return null |
|
348 | + * @access public |
|
349 | + */ |
|
350 | + public function viewtopic_modify_post_row($event) |
|
351 | + { |
|
352 | + $row = $event['post_row']; |
|
353 | + $start = $this->request->variable('start', 0); |
|
354 | + $data = $event['topic_data']; |
|
355 | + $row['U_MINI_POST'] = append_sid($this->generate_topic_link($data['forum_id'], $data['forum_name'], $data['topic_id'], $data['topic_title'], $start) . '#p' . $event['row']['post_id']); |
|
356 | + $event['post_row'] = $row; |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Rewrite URLs in tas2580 Sitemap Extension |
|
361 | + * |
|
362 | + * @param object $event The event object |
|
363 | + * @return null |
|
364 | + * @access public |
|
365 | + */ |
|
366 | + public function sitemap_modify_before_output($event) |
|
367 | + { |
|
368 | + // Nothing to rewrite in the sitemap index |
|
369 | + if ($event['type'] == 'sitemapindex') |
|
370 | + { |
|
371 | + return; |
|
372 | + } |
|
373 | + |
|
374 | + $url_data =$event['url_data'] ; |
|
375 | + |
|
376 | + foreach ($url_data as $id => $data) |
|
377 | + { |
|
378 | + $row = $data['row']; |
|
379 | + if (isset($row['topic_id'])) |
|
380 | + { |
|
381 | + $url_data[$id]['url'] = $this->generate_topic_link($row['forum_id'], $row['forum_name'], $row['topic_id'], $row['topic_title'], $data['start'], true); |
|
382 | + } |
|
383 | + else if (isset($row['forum_id'])) |
|
384 | + { |
|
385 | + $url_data[$id]['url'] = $this->generate_forum_link($row['forum_id'], $row['forum_name'], $data['start'], true); |
|
386 | + } |
|
387 | + } |
|
388 | + |
|
389 | + $event['url_data'] = $url_data; |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | + * Rewrite URLs in Similar Topics Extension |
|
394 | + * |
|
395 | + * @param object $event The event object |
|
396 | + * @return null |
|
397 | + * @access public |
|
398 | + */ |
|
399 | + public function similartopics_modify_topicrow($event) |
|
400 | + { |
|
401 | + $this->forum_title = $event['row']['forum_name']; |
|
402 | + $this->forum_id = $event['row']['forum_id']; |
|
403 | + $this->topic_title = $event['row']['topic_title']; |
|
404 | + $this->topic_id = $event['row']['topic_id']; |
|
405 | + |
|
406 | + $topic_row = $event['topic_row']; |
|
407 | + $u_view_topic= $this->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title); |
|
408 | + $topic_row['U_VIEW_TOPIC'] = append_sid($u_view_topic); |
|
409 | + $topic_row['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($this->forum_id, $this->forum_title)); |
|
410 | + $topic_row['U_LAST_POST'] = append_sid($this->generate_lastpost_link($topic_row['TOPIC_REPLIES'], $u_view_topic) . '#p' . $event['row']['topic_last_post_id']); |
|
411 | + $event['topic_row'] = $topic_row; |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * Rewrite URLs in Top 5 Extension |
|
416 | + * |
|
417 | + * @param object $event The event object |
|
418 | + * @return null |
|
419 | + * @access public |
|
420 | + */ |
|
421 | + public function topfive_sql_pull_topics_data($event) |
|
422 | + { |
|
423 | + $sql_array = $event['sql_array']; |
|
424 | + $sql_array['SELECT'] = array_merge($sql_array, array('SELECT' => 'f.forum_name')); |
|
425 | + $sql_array['LEFT_JOIN'] = array_merge($sql_array['LEFT_JOIN'], array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id')); |
|
426 | + // $event['sql_array'] = $sql_array; |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * Rewrite URLs in Top 5 Extension |
|
431 | + * |
|
432 | + * @param object $event The event object |
|
433 | + * @return null |
|
434 | + * @access public |
|
435 | + */ |
|
436 | + public function topfive_modify_tpl_ary($event) |
|
437 | + { |
|
438 | + $tpl_ary = $event['tpl_ary']; |
|
439 | + $replies = $this->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1; |
|
440 | + $u_view_topic = $this->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']); |
|
441 | + $tpl_ary['U_TOPIC'] = append_sid($this->generate_lastpost_link($replies, $u_view_topic) . '#p' . $event['row']['topic_last_post_id']); |
|
442 | + $event['tpl_ary'] = $tpl_ary; |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * Generate the SEO link for a topic |
|
447 | + * |
|
448 | + * @param int $forum_id The ID of the forum |
|
449 | + * @param string $forum_name The title of the forum |
|
450 | + * @param int $topic_id The ID if the topic |
|
451 | + * @param string $topic_title The title of the topic |
|
452 | + * @param int $start Optional start parameter |
|
453 | + * @param bool $full Return the full URL |
|
454 | + * @return string The SEO URL |
|
455 | + * @access private |
|
456 | + */ |
|
457 | + private function generate_topic_link($forum_id, $forum_name, $topic_id, $topic_title, $start = 0, $full = false) |
|
458 | + { |
|
459 | + if ($full) |
|
460 | + { |
|
461 | + return generate_board_url() . '/' . $this->title_to_url($forum_name) . '-f' . $forum_id . '/' . $this->title_to_url($topic_title) . '-t' . $topic_id . ($start ? '-s' . $start : '') . '.html'; |
|
462 | + } |
|
463 | + return $this->phpbb_root_path . $this->title_to_url($forum_name) . '-f' . $forum_id . '/' . $this->title_to_url($topic_title) . '-t' . $topic_id . ($start ? '-s' . $start : '') . '.html'; |
|
464 | + } |
|
465 | + |
|
466 | + /** |
|
467 | + * Generate the SEO link for a forum |
|
468 | + * |
|
469 | + * @param int $forum_id The ID of the forum |
|
470 | + * @param string $forum_name The title of the forum |
|
471 | + * @param int $start Optional start parameter |
|
472 | + * @param bool $full Return the full URL |
|
473 | + * @return string The SEO URL |
|
474 | + * @access private |
|
475 | + */ |
|
476 | + private function generate_forum_link($forum_id, $forum_name, $start = 0, $full = false) |
|
477 | + { |
|
478 | + if ($full) |
|
479 | + { |
|
480 | + return generate_board_url() . '/' . $this->title_to_url($forum_name) . '-f' . $forum_id . '/' . ($start ? 'index-s' . $start . '.html' : ''); |
|
481 | + } |
|
482 | + return $this->phpbb_root_path . $this->title_to_url($forum_name) . '-f' . $forum_id . '/' . ($start ? 'index-s' . $start . '.html' : ''); |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * |
|
487 | + * @global type $_SID |
|
488 | + * @param int $replies Replays in the topic |
|
489 | + * @param string $url URL oft the topic |
|
490 | + * @return string The URL with start included |
|
491 | + */ |
|
492 | + private function generate_lastpost_link($replies, $url) |
|
493 | + { |
|
494 | + $url = str_replace('.html', '', $url); |
|
495 | + $per_page = ($this->config['posts_per_page'] <= 0) ? 1 : $this->config['posts_per_page']; |
|
496 | + if (($replies + 1) > $per_page) |
|
497 | + { |
|
498 | + for ($j = 0; $j < $replies + 1; $j += $per_page) |
|
499 | + { |
|
500 | + $last_post_link = $url . '-s' . $j . '.html'; |
|
501 | + } |
|
502 | + } |
|
503 | + else |
|
504 | + { |
|
505 | + $last_post_link = $url . '.html'; |
|
506 | + } |
|
507 | + return $last_post_link; |
|
508 | + } |
|
509 | + |
|
510 | + /** |
|
511 | + * Replace letters to use title in URL |
|
512 | + * |
|
513 | + * @param string $title The title to use in the URL |
|
514 | + * @return string Title to use in URLs |
|
515 | + */ |
|
516 | + public static function title_to_url($title) |
|
517 | + { |
|
518 | + $url = strtolower(censor_text(utf8_normalize_nfc(strip_tags($title)))); |
|
519 | + |
|
520 | + // Let's replace |
|
521 | + $url_search = array(' ', 'í', 'ý', 'ß', 'ö', 'ô', 'ó', 'ò', 'ä', 'â', 'à', 'á', 'é', 'è', 'ü', 'ú', 'ù', 'ñ', 'ß', '²', '³', '@', '€', '$'); |
|
522 | + $url_replace = array('-', 'i', 'y', 's', 'oe', 'o', 'o', 'o', 'ae', 'a', 'a', 'a', 'e', 'e', 'ue', 'u', 'u', 'n', 'ss', '2', '3', 'at', 'eur', 'usd'); |
|
523 | + $url = str_replace($url_search, $url_replace, $url); |
|
524 | + $url_search = array('&', '"', '&', '"', "'", '¸', '`', '(', ')', '[', ']', '<', '>', '{', '}', '.', ':', ',', ';', '!', '?', '+', '*', '/', '=', 'µ', '#', '~', '"', '§', '%', '|', '°', '^', '„', '“'); |
|
525 | + $url = str_replace($url_search, '-', $url); |
|
526 | + $url = str_replace(array('----', '---', '--'), '-', $url); |
|
527 | + |
|
528 | + $url = substr($url, 0, 50); // Max length for a title in URL |
|
529 | + return urlencode($url); |
|
530 | + } |
|
531 | + |
|
532 | + /** |
|
533 | + * Get the topics post count or the forums post/topic count based on permissions |
|
534 | + * |
|
535 | + * @param $mode string One of topic_posts, forum_posts or forum_topics |
|
536 | + * @param $data array Array with the topic/forum data to calculate from |
|
537 | + * @param $forum_id int The forum id is used for permission checks |
|
538 | + * @return int Number of posts/topics the user can see in the topic/forum |
|
539 | + */ |
|
540 | + private function get_count($mode, $data, $forum_id) |
|
541 | + { |
|
542 | + if (!$this->auth->acl_get('m_approve', $forum_id)) |
|
543 | + { |
|
544 | + return (int) $data[$mode . '_approved']; |
|
545 | + } |
|
546 | + |
|
547 | + return (int) $data[$mode . '_approved'] + (int) $data[$mode . '_unapproved'] + (int) $data[$mode . '_softdeleted']; |
|
548 | + } |
|
549 | 549 | |
550 | 550 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | 'core.display_forums_modify_forum_rows' => 'display_forums_modify_forum_rows', |
78 | 78 | 'core.display_forums_modify_sql' => 'display_forums_modify_sql', |
79 | 79 | 'core.generate_forum_nav' => 'generate_forum_nav', |
80 | - 'core.make_jumpbox_modify_tpl_ary' => 'make_jumpbox_modify_tpl_ary', // Not in phpBB |
|
80 | + 'core.make_jumpbox_modify_tpl_ary' => 'make_jumpbox_modify_tpl_ary', // Not in phpBB |
|
81 | 81 | 'core.pagination_generate_page_link' => 'pagination_generate_page_link', |
82 | 82 | 'core.search_modify_tpl_ary' => 'search_modify_tpl_ary', |
83 | 83 | 'core.viewforum_modify_topicrow' => 'viewforum_modify_topicrow', |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | $forum_rows = $event['forum_rows']; |
126 | 126 | if ($event['row']['forum_last_post_time'] == $forum_rows[$event['parent_id']]['forum_last_post_time']) |
127 | 127 | { |
128 | - $forum_rows[$event['parent_id']]['forum_name_last_post'] =$event['row']['forum_name']; |
|
129 | - $forum_rows[$event['parent_id']]['topic_id_last_post'] =$event['row']['topic_id']; |
|
130 | - $forum_rows[$event['parent_id']]['topic_title_last_post'] =$event['row']['topic_title']; |
|
128 | + $forum_rows[$event['parent_id']]['forum_name_last_post'] = $event['row']['forum_name']; |
|
129 | + $forum_rows[$event['parent_id']]['topic_id_last_post'] = $event['row']['topic_id']; |
|
130 | + $forum_rows[$event['parent_id']]['topic_title_last_post'] = $event['row']['topic_title']; |
|
131 | 131 | $event['forum_rows'] = $forum_rows; |
132 | 132 | } |
133 | 133 | } |
@@ -157,12 +157,12 @@ discard block |
||
157 | 157 | |
158 | 158 | // Update the image source in forums |
159 | 159 | $img = $this->path_helper->update_web_root_path($forum_row['FORUM_IMAGE_SRC']); |
160 | - $forum_row['FORUM_IMAGE'] = preg_replace('#img src=\"(.*)\" alt#', 'img src="' . $img . '" alt', $forum_row['FORUM_IMAGE']); |
|
160 | + $forum_row['FORUM_IMAGE'] = preg_replace('#img src=\"(.*)\" alt#', 'img src="'.$img.'" alt', $forum_row['FORUM_IMAGE']); |
|
161 | 161 | |
162 | 162 | // Rewrite links to topics, posts and forums |
163 | 163 | $replies = $this->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1; |
164 | 164 | $url = $this->generate_topic_link($event['row']['forum_id_last_post'], $event['row']['forum_name_last_post'], $event['row']['topic_id_last_post'], $event['row']['topic_title_last_post']); |
165 | - $forum_row['U_LAST_POST'] = append_sid($this->generate_lastpost_link($replies, $url) . '#p' . $event['row']['forum_last_post_id']); |
|
165 | + $forum_row['U_LAST_POST'] = append_sid($this->generate_lastpost_link($replies, $url).'#p'.$event['row']['forum_last_post_id']); |
|
166 | 166 | $forum_row['U_VIEWFORUM'] = append_sid($this->generate_forum_link($forum_row['FORUM_ID'], $forum_row['FORUM_NAME'])); |
167 | 167 | $event['forum_row'] = $forum_row; |
168 | 168 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | |
183 | 183 | foreach ($navlinks_parents as $id => $data) |
184 | 184 | { |
185 | - $navlinks_parents[$id]['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($data['FORUM_ID'] , $data['FORUM_NAME'])); |
|
185 | + $navlinks_parents[$id]['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($data['FORUM_ID'], $data['FORUM_NAME'])); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | $navlinks['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($forum_data['forum_id'], $forum_data['forum_name'])); |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | foreach ($tpl_ary as $id => $data) |
199 | 199 | { |
200 | 200 | |
201 | - $tpl_ary[$id]['LINK'] = append_sid($this->generate_forum_link($row['forum_id'], $row['forum_name'])); |
|
201 | + $tpl_ary[$id]['LINK'] = append_sid($this->generate_forum_link($row['forum_id'], $row['forum_name'])); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | $event['tpl_ary'] = $tpl_ary; |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | $u_view_topic = $this->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']); |
246 | 246 | |
247 | 247 | $tpl_ary = $event['tpl_ary']; |
248 | - $tpl_ary['U_LAST_POST'] = append_sid($this->generate_lastpost_link($replies, $u_view_topic) . '#p' . $event['row']['topic_last_post_id']); |
|
248 | + $tpl_ary['U_LAST_POST'] = append_sid($this->generate_lastpost_link($replies, $u_view_topic).'#p'.$event['row']['topic_last_post_id']); |
|
249 | 249 | $tpl_ary['U_VIEW_TOPIC'] = append_sid($u_view_topic); |
250 | 250 | $tpl_ary['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($event['row']['forum_id'], $event['row']['forum_name'])); |
251 | 251 | |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | $u_view_topic = $this->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title); |
271 | 271 | $topic_row['U_VIEW_TOPIC'] = append_sid($u_view_topic); |
272 | 272 | $topic_row['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($this->forum_id, $this->forum_title)); |
273 | - $topic_row['U_LAST_POST'] = append_sid($this->generate_lastpost_link($event['topic_row']['REPLIES'], $u_view_topic) . '#p' . $event['row']['topic_last_post_id']); |
|
273 | + $topic_row['U_LAST_POST'] = append_sid($this->generate_lastpost_link($event['topic_row']['REPLIES'], $u_view_topic).'#p'.$event['row']['topic_last_post_id']); |
|
274 | 274 | |
275 | 275 | $event['topic_row'] = $topic_row; |
276 | 276 | } |
@@ -304,8 +304,8 @@ discard block |
||
304 | 304 | { |
305 | 305 | $data = $event['topic_data']; |
306 | 306 | $this->template->assign_vars(array( |
307 | - 'U_VIEW_TOPIC' => append_sid($this->generate_topic_link($event['forum_id'] , $data['forum_name'], $event['topic_id'], $data['topic_title'], $event['start'])), |
|
308 | - 'U_VIEW_FORUM' => append_sid($this->generate_forum_link($event['forum_id'] , $data['forum_name'])), |
|
307 | + 'U_VIEW_TOPIC' => append_sid($this->generate_topic_link($event['forum_id'], $data['forum_name'], $event['topic_id'], $data['topic_title'], $event['start'])), |
|
308 | + 'U_VIEW_FORUM' => append_sid($this->generate_forum_link($event['forum_id'], $data['forum_name'])), |
|
309 | 309 | )); |
310 | 310 | } |
311 | 311 | |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | $row = $event['post_row']; |
353 | 353 | $start = $this->request->variable('start', 0); |
354 | 354 | $data = $event['topic_data']; |
355 | - $row['U_MINI_POST'] = append_sid($this->generate_topic_link($data['forum_id'], $data['forum_name'], $data['topic_id'], $data['topic_title'], $start) . '#p' . $event['row']['post_id']); |
|
355 | + $row['U_MINI_POST'] = append_sid($this->generate_topic_link($data['forum_id'], $data['forum_name'], $data['topic_id'], $data['topic_title'], $start).'#p'.$event['row']['post_id']); |
|
356 | 356 | $event['post_row'] = $row; |
357 | 357 | } |
358 | 358 | |
@@ -371,14 +371,14 @@ discard block |
||
371 | 371 | return; |
372 | 372 | } |
373 | 373 | |
374 | - $url_data =$event['url_data'] ; |
|
374 | + $url_data = $event['url_data']; |
|
375 | 375 | |
376 | 376 | foreach ($url_data as $id => $data) |
377 | 377 | { |
378 | 378 | $row = $data['row']; |
379 | 379 | if (isset($row['topic_id'])) |
380 | 380 | { |
381 | - $url_data[$id]['url'] = $this->generate_topic_link($row['forum_id'], $row['forum_name'], $row['topic_id'], $row['topic_title'], $data['start'], true); |
|
381 | + $url_data[$id]['url'] = $this->generate_topic_link($row['forum_id'], $row['forum_name'], $row['topic_id'], $row['topic_title'], $data['start'], true); |
|
382 | 382 | } |
383 | 383 | else if (isset($row['forum_id'])) |
384 | 384 | { |
@@ -404,10 +404,10 @@ discard block |
||
404 | 404 | $this->topic_id = $event['row']['topic_id']; |
405 | 405 | |
406 | 406 | $topic_row = $event['topic_row']; |
407 | - $u_view_topic= $this->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title); |
|
407 | + $u_view_topic = $this->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title); |
|
408 | 408 | $topic_row['U_VIEW_TOPIC'] = append_sid($u_view_topic); |
409 | 409 | $topic_row['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($this->forum_id, $this->forum_title)); |
410 | - $topic_row['U_LAST_POST'] = append_sid($this->generate_lastpost_link($topic_row['TOPIC_REPLIES'], $u_view_topic) . '#p' . $event['row']['topic_last_post_id']); |
|
410 | + $topic_row['U_LAST_POST'] = append_sid($this->generate_lastpost_link($topic_row['TOPIC_REPLIES'], $u_view_topic).'#p'.$event['row']['topic_last_post_id']); |
|
411 | 411 | $event['topic_row'] = $topic_row; |
412 | 412 | } |
413 | 413 | |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | $tpl_ary = $event['tpl_ary']; |
439 | 439 | $replies = $this->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1; |
440 | 440 | $u_view_topic = $this->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']); |
441 | - $tpl_ary['U_TOPIC'] = append_sid($this->generate_lastpost_link($replies, $u_view_topic) . '#p' . $event['row']['topic_last_post_id']); |
|
441 | + $tpl_ary['U_TOPIC'] = append_sid($this->generate_lastpost_link($replies, $u_view_topic).'#p'.$event['row']['topic_last_post_id']); |
|
442 | 442 | $event['tpl_ary'] = $tpl_ary; |
443 | 443 | } |
444 | 444 | |
@@ -458,9 +458,9 @@ discard block |
||
458 | 458 | { |
459 | 459 | if ($full) |
460 | 460 | { |
461 | - return generate_board_url() . '/' . $this->title_to_url($forum_name) . '-f' . $forum_id . '/' . $this->title_to_url($topic_title) . '-t' . $topic_id . ($start ? '-s' . $start : '') . '.html'; |
|
461 | + return generate_board_url().'/'.$this->title_to_url($forum_name).'-f'.$forum_id.'/'.$this->title_to_url($topic_title).'-t'.$topic_id.($start ? '-s'.$start : '').'.html'; |
|
462 | 462 | } |
463 | - return $this->phpbb_root_path . $this->title_to_url($forum_name) . '-f' . $forum_id . '/' . $this->title_to_url($topic_title) . '-t' . $topic_id . ($start ? '-s' . $start : '') . '.html'; |
|
463 | + return $this->phpbb_root_path.$this->title_to_url($forum_name).'-f'.$forum_id.'/'.$this->title_to_url($topic_title).'-t'.$topic_id.($start ? '-s'.$start : '').'.html'; |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | /** |
@@ -477,9 +477,9 @@ discard block |
||
477 | 477 | { |
478 | 478 | if ($full) |
479 | 479 | { |
480 | - return generate_board_url() . '/' . $this->title_to_url($forum_name) . '-f' . $forum_id . '/' . ($start ? 'index-s' . $start . '.html' : ''); |
|
480 | + return generate_board_url().'/'.$this->title_to_url($forum_name).'-f'.$forum_id.'/'.($start ? 'index-s'.$start.'.html' : ''); |
|
481 | 481 | } |
482 | - return $this->phpbb_root_path . $this->title_to_url($forum_name) . '-f' . $forum_id . '/' . ($start ? 'index-s' . $start . '.html' : ''); |
|
482 | + return $this->phpbb_root_path.$this->title_to_url($forum_name).'-f'.$forum_id.'/'.($start ? 'index-s'.$start.'.html' : ''); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
@@ -497,12 +497,12 @@ discard block |
||
497 | 497 | { |
498 | 498 | for ($j = 0; $j < $replies + 1; $j += $per_page) |
499 | 499 | { |
500 | - $last_post_link = $url . '-s' . $j . '.html'; |
|
500 | + $last_post_link = $url.'-s'.$j.'.html'; |
|
501 | 501 | } |
502 | 502 | } |
503 | 503 | else |
504 | 504 | { |
505 | - $last_post_link = $url . '.html'; |
|
505 | + $last_post_link = $url.'.html'; |
|
506 | 506 | } |
507 | 507 | return $last_post_link; |
508 | 508 | } |
@@ -541,10 +541,10 @@ discard block |
||
541 | 541 | { |
542 | 542 | if (!$this->auth->acl_get('m_approve', $forum_id)) |
543 | 543 | { |
544 | - return (int) $data[$mode . '_approved']; |
|
544 | + return (int) $data[$mode.'_approved']; |
|
545 | 545 | } |
546 | 546 | |
547 | - return (int) $data[$mode . '_approved'] + (int) $data[$mode . '_unapproved'] + (int) $data[$mode . '_softdeleted']; |
|
547 | + return (int) $data[$mode.'_approved'] + (int) $data[$mode.'_unapproved'] + (int) $data[$mode.'_softdeleted']; |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | } |