Passed
Branch master (72c87d)
by Tobias
03:18
created
event/listener.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -531,7 +531,7 @@
 block discarded – undo
531 531
 	/**
532 532
 	 * Get the topics post count or the forums post/topic count based on permissions
533 533
 	 *
534
-	 * @param $mode            string    One of topic_posts, forum_posts or forum_topics
534
+	 * @param string $mode            string    One of topic_posts, forum_posts or forum_topics
535 535
 	 * @param $data            array    Array with the topic/forum data to calculate from
536 536
 	 * @param $forum_id        int        The forum id is used for permission checks
537 537
 	 * @return int    Number of posts/topics the user can see in the topic/forum
Please login to merge, or discard this patch.
Indentation   +527 added lines, -527 removed lines patch added patch discarded remove patch
@@ -18,532 +18,532 @@
 block discarded – undo
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
-		$url = $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, $url) . '#p' . $event['row']['topic_last_post_id']);
249
-		$tpl_ary['U_VIEW_TOPIC'] = append_sid($this->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']));
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
-		$topic_row['U_VIEW_TOPIC'] = append_sid($this->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title));
271
-		$topic_row['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($this->forum_id, $this->forum_title));
272
-		$topic_row['U_LAST_POST'] = append_sid($this->generate_lastpost_link($event['topic_row']['REPLIES'], $topic_row['U_VIEW_TOPIC']) . '#p' . $event['row']['topic_last_post_id']);
273
-
274
-		$event['topic_row'] = $topic_row;
275
-	}
276
-
277
-	/**
278
-	 * Rewrite the canonical URL on viewforum.php
279
-	 *
280
-	 * @param	object	$event	The event object
281
-	 * @return	null
282
-	 * @access	public
283
-	 */
284
-	public function viewforum_get_topic_data($event)
285
-	{
286
-		$this->forum_title = $event['forum_data']['forum_name'];
287
-		$this->forum_id = $event['forum_data']['forum_id'];
288
-		$start = $this->request->variable('start', 0);
289
-		$this->template->assign_vars(array(
290
-			'U_VIEW_FORUM'	=> append_sid($this->generate_forum_link($this->forum_id, $this->forum_title, $start)),
291
-			'U_CANONICAL'		=> $this->generate_forum_link($this->forum_id, $this->forum_title, $start, true),
292
-		));
293
-	}
294
-
295
-	/**
296
-	 * Rewrite the topic URL for the headline of the topic page and the link back to forum
297
-	 *
298
-	 * @param	object	$event	The event object
299
-	 * @return	null
300
-	 * @access	public
301
-	 */
302
-	public function viewtopic_get_post_data($event)
303
-	{
304
-		$data = $event['topic_data'];
305
-		$this->template->assign_vars(array(
306
-			'U_VIEW_TOPIC'		=> append_sid($this->generate_topic_link($event['forum_id'] , $data['forum_name'], $event['topic_id'], $data['topic_title'], $event['start'])),
307
-			'U_VIEW_FORUM'	=> append_sid($this->generate_forum_link($event['forum_id'] , $data['forum_name'])),
308
-		));
309
-	}
310
-
311
-	/**
312
-	 * Assign topic data to global variables for pagination
313
-	 *
314
-	 * @param	object	$event	The event object
315
-	 * @return	null
316
-	 * @access	public
317
-	 */
318
-	public function viewtopic_assign_template_vars_before($event)
319
-	{
320
-		$this->forum_title = $event['topic_data']['forum_name'];
321
-		$this->forum_id = $event['topic_data']['forum_id'];
322
-		$this->topic_title = $event['topic_data']['topic_title'];
323
-		$this->topic_id = $event['topic_data']['topic_id'];
324
-	}
325
-
326
-	/**
327
-	 * Rewrite the canonical URL on viewtopic.php
328
-	 *
329
-	 * @param	object	$event	The event object
330
-	 * @return	null
331
-	 * @access	public
332
-	 */
333
-	public function viewtopic_modify_page_title($event)
334
-	{
335
-		$start = $this->request->variable('start', 0);
336
-		$data = $event['topic_data'];
337
-		$this->template->assign_vars(array(
338
-			'U_CANONICAL'		=> $this->generate_topic_link($data['forum_id'], $data['forum_name'], $data['topic_id'], $data['topic_title'], $start, true),
339
-		));
340
-	}
341
-
342
-	/**
343
-	 * Rewrite mini post img link
344
-	 *
345
-	 * @param	object	$event	The event object
346
-	 * @return	null
347
-	 * @access	public
348
-	 */
349
-	public function viewtopic_modify_post_row($event)
350
-	{
351
-		$row = $event['post_row'];
352
-		$start = $this->request->variable('start', 0);
353
-		$data = $event['topic_data'];
354
-		$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
-		$event['post_row'] = $row;
356
-	}
357
-
358
-	/**
359
-	 * Rewrite URLs in tas2580 Sitemap Extension
360
-	 *
361
-	 * @param	object	$event	The event object
362
-	 * @return	null
363
-	 * @access	public
364
-	 */
365
-	public function sitemap_modify_before_output($event)
366
-	{
367
-		// Nothing to rewrite in the sitemap index
368
-		if ($event['type'] == 'sitemapindex')
369
-		{
370
-			return;
371
-		}
372
-
373
-		$url_data =$event['url_data'] ;
374
-
375
-		foreach ($url_data as $id => $data)
376
-		{
377
-			$row = $data['row'];
378
-			if (isset($row['topic_id']))
379
-			{
380
-				$url_data[$id]['url'] = $this->generate_topic_link($row['forum_id'], $row['forum_name'], $row['topic_id'], $row['topic_title'],  $data['start'], true);
381
-			}
382
-			else if (isset($row['forum_id']))
383
-			{
384
-				$url_data[$id]['url'] = $this->generate_forum_link($row['forum_id'], $row['forum_name'], $data['start'], true);
385
-			}
386
-		}
387
-
388
-		$event['url_data'] = $url_data;
389
-	}
390
-
391
-	/**
392
-	 * Rewrite URLs in Similar Topics Extension
393
-	 *
394
-	 * @param	object	$event	The event object
395
-	 * @return	null
396
-	 * @access	public
397
-	 */
398
-	public function similartopics_modify_topicrow($event)
399
-	{
400
-		$this->forum_title = $event['row']['forum_name'];
401
-		$this->forum_id = $event['row']['forum_id'];
402
-		$this->topic_title = $event['row']['topic_title'];
403
-		$this->topic_id = $event['row']['topic_id'];
404
-
405
-		$topic_row = $event['topic_row'];
406
-		$u_view_topic= $this->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title);
407
-		$topic_row['U_VIEW_TOPIC'] = append_sid($u_view_topic);
408
-		$topic_row['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($this->forum_id, $this->forum_title));
409
-		$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
-		$event['topic_row'] = $topic_row;
411
-	}
412
-
413
-	/**
414
-	 * Rewrite URLs in Top 5 Extension
415
-	 *
416
-	 * @param	object	$event	The event object
417
-	 * @return	null
418
-	 * @access	public
419
-	 */
420
-	public function topfive_sql_pull_topics_data($event)
421
-	{
422
-		$sql_array = $event['sql_array'];
423
-		$sql_array['SELECT'] = array_merge($sql_array, array('SELECT' => 'f.forum_name'));
424
-		$sql_array['LEFT_JOIN'] = array_merge($sql_array['LEFT_JOIN'], array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id'));
425
-		//	$event['sql_array'] = $sql_array;
426
-	}
427
-
428
-	/**
429
-	 * Rewrite URLs in Top 5 Extension
430
-	 *
431
-	 * @param	object	$event	The event object
432
-	 * @return	null
433
-	 * @access	public
434
-	 */
435
-	public function topfive_modify_tpl_ary($event)
436
-	{
437
-		$tpl_ary = $event['tpl_ary'];
438
-		$replies = $this->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1;
439
-		$u_view_topic = $this->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']);
440
-		$tpl_ary['U_TOPIC'] = append_sid($this->generate_lastpost_link($replies, $u_view_topic) . '#p' . $event['row']['topic_last_post_id']);
441
-		$event['tpl_ary'] = $tpl_ary;
442
-	}
443
-
444
-	/**
445
-	 * Generate the SEO link for a topic
446
-	 *
447
-	 * @param	int		$forum_id		The ID of the forum
448
-	 * @param	string	$forum_name		The title of the forum
449
-	 * @param	int		$topic_id		The ID if the topic
450
-	 * @param	string	$topic_title	The title of the topic
451
-	 * @param	int		$start			Optional start parameter
452
-	 * @param	bool	$full			Return the full URL
453
-	 * @return	string	The SEO URL
454
-	 * @access private
455
-	 */
456
-	private function generate_topic_link($forum_id, $forum_name, $topic_id, $topic_title, $start = 0, $full = false)
457
-	{
458
-		if ($full)
459
-		{
460
-			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
-		}
462
-		return $this->path_helper->update_web_root_path($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
-	}
464
-
465
-	/**
466
-	 * Generate the SEO link for a forum
467
-	 *
468
-	 * @param	int		$forum_id		The ID of the forum
469
-	 * @param	string	$forum_name		The title of the forum
470
-	 * @param	int		$start			Optional start parameter
471
-	 * @param	bool	$full			Return the full URL
472
-	 * @return	string	The SEO URL
473
-	 * @access private
474
-	 */
475
-	private function generate_forum_link($forum_id, $forum_name, $start = 0, $full = false)
476
-	{
477
-		if ($full)
478
-		{
479
-			return generate_board_url() . '/' . $this->title_to_url($forum_name) . '-f' . $forum_id . '/' . ($start ? 'index-s' . $start . '.html' : '');
480
-		}
481
-		return $this->path_helper->update_web_root_path($this->phpbb_root_path . $this->title_to_url($forum_name) . '-f' . $forum_id . '/' . ($start ? 'index-s' . $start . '.html' : ''));
482
-	}
483
-
484
-	/**
485
-	 *
486
-	 * @global	type	$_SID
487
-	 * @param	int		$replies	Replays in the topic
488
-	 * @param	string	$url		URL oft the topic
489
-	 * @return	string				The URL with start included
490
-	 */
491
-	private function generate_lastpost_link($replies, $url)
492
-	{
493
-		$url = str_replace('.html', '', $url);
494
-		$per_page = ($this->config['posts_per_page'] <= 0) ? 1 : $this->config['posts_per_page'];
495
-		if (($replies + 1) > $per_page)
496
-		{
497
-			for ($j = 0; $j < $replies + 1; $j += $per_page)
498
-			{
499
-				$last_post_link = $url . '-s' . $j . '.html';
500
-			}
501
-		}
502
-		else
503
-		{
504
-			$last_post_link = $url . '.html';
505
-		}
506
-		return $last_post_link;
507
-	}
508
-
509
-	/**
510
-	 * Replace letters to use title in URL
511
-	 *
512
-	 * @param	string	$title	The title to use in the URL
513
-	 * @return	string	Title to use in URLs
514
-	 */
515
-	private function title_to_url($title)
516
-	{
517
-		$url = strtolower(censor_text(utf8_normalize_nfc(strip_tags($title))));
518
-
519
-		// Let's replace
520
-		$url_search = array(' ', 'í', 'ý', 'ß', 'ö', 'ô', 'ó', 'ò', 'ä', 'â', 'à', 'á', 'é', 'è', 'ü', 'ú', 'ù', 'ñ', 'ß', '²', '³', '@', '€', '$');
521
-		$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');
522
-		$url = str_replace($url_search, $url_replace, $url);
523
-		$url_search = array('&amp;', '&quot;', '&', '"', "'", '¸', '`', '(', ')', '[', ']', '<', '>', '{', '}', '.', ':', ',', ';', '!', '?', '+', '*', '/', '=', 'µ', '#', '~', '"', '§', '%', '|', '°', '^', '„', '“');
524
-		$url = str_replace($url_search, '-', $url);
525
-		$url = str_replace(array('----', '---', '--'), '-', $url);
526
-
527
-		$url = substr($url, 0, 50); // Max length for a title in URL
528
-		return urlencode($url);
529
-	}
530
-
531
-	/**
532
-	 * Get the topics post count or the forums post/topic count based on permissions
533
-	 *
534
-	 * @param $mode            string    One of topic_posts, forum_posts or forum_topics
535
-	 * @param $data            array    Array with the topic/forum data to calculate from
536
-	 * @param $forum_id        int        The forum id is used for permission checks
537
-	 * @return int    Number of posts/topics the user can see in the topic/forum
538
-	 */
539
-	private function get_count($mode, $data, $forum_id)
540
-	{
541
-		if (!$this->auth->acl_get('m_approve', $forum_id))
542
-		{
543
-			return (int) $data[$mode . '_approved'];
544
-		}
545
-
546
-		return (int) $data[$mode . '_approved'] + (int) $data[$mode . '_unapproved'] + (int) $data[$mode . '_softdeleted'];
547
-	}
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('&amp;', '&', 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('&amp;', '&', 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
+        $url = $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, $url) . '#p' . $event['row']['topic_last_post_id']);
249
+        $tpl_ary['U_VIEW_TOPIC'] = append_sid($this->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']));
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
+        $topic_row['U_VIEW_TOPIC'] = append_sid($this->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title));
271
+        $topic_row['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($this->forum_id, $this->forum_title));
272
+        $topic_row['U_LAST_POST'] = append_sid($this->generate_lastpost_link($event['topic_row']['REPLIES'], $topic_row['U_VIEW_TOPIC']) . '#p' . $event['row']['topic_last_post_id']);
273
+
274
+        $event['topic_row'] = $topic_row;
275
+    }
276
+
277
+    /**
278
+     * Rewrite the canonical URL on viewforum.php
279
+     *
280
+     * @param	object	$event	The event object
281
+     * @return	null
282
+     * @access	public
283
+     */
284
+    public function viewforum_get_topic_data($event)
285
+    {
286
+        $this->forum_title = $event['forum_data']['forum_name'];
287
+        $this->forum_id = $event['forum_data']['forum_id'];
288
+        $start = $this->request->variable('start', 0);
289
+        $this->template->assign_vars(array(
290
+            'U_VIEW_FORUM'	=> append_sid($this->generate_forum_link($this->forum_id, $this->forum_title, $start)),
291
+            'U_CANONICAL'		=> $this->generate_forum_link($this->forum_id, $this->forum_title, $start, true),
292
+        ));
293
+    }
294
+
295
+    /**
296
+     * Rewrite the topic URL for the headline of the topic page and the link back to forum
297
+     *
298
+     * @param	object	$event	The event object
299
+     * @return	null
300
+     * @access	public
301
+     */
302
+    public function viewtopic_get_post_data($event)
303
+    {
304
+        $data = $event['topic_data'];
305
+        $this->template->assign_vars(array(
306
+            'U_VIEW_TOPIC'		=> append_sid($this->generate_topic_link($event['forum_id'] , $data['forum_name'], $event['topic_id'], $data['topic_title'], $event['start'])),
307
+            'U_VIEW_FORUM'	=> append_sid($this->generate_forum_link($event['forum_id'] , $data['forum_name'])),
308
+        ));
309
+    }
310
+
311
+    /**
312
+     * Assign topic data to global variables for pagination
313
+     *
314
+     * @param	object	$event	The event object
315
+     * @return	null
316
+     * @access	public
317
+     */
318
+    public function viewtopic_assign_template_vars_before($event)
319
+    {
320
+        $this->forum_title = $event['topic_data']['forum_name'];
321
+        $this->forum_id = $event['topic_data']['forum_id'];
322
+        $this->topic_title = $event['topic_data']['topic_title'];
323
+        $this->topic_id = $event['topic_data']['topic_id'];
324
+    }
325
+
326
+    /**
327
+     * Rewrite the canonical URL on viewtopic.php
328
+     *
329
+     * @param	object	$event	The event object
330
+     * @return	null
331
+     * @access	public
332
+     */
333
+    public function viewtopic_modify_page_title($event)
334
+    {
335
+        $start = $this->request->variable('start', 0);
336
+        $data = $event['topic_data'];
337
+        $this->template->assign_vars(array(
338
+            'U_CANONICAL'		=> $this->generate_topic_link($data['forum_id'], $data['forum_name'], $data['topic_id'], $data['topic_title'], $start, true),
339
+        ));
340
+    }
341
+
342
+    /**
343
+     * Rewrite mini post img link
344
+     *
345
+     * @param	object	$event	The event object
346
+     * @return	null
347
+     * @access	public
348
+     */
349
+    public function viewtopic_modify_post_row($event)
350
+    {
351
+        $row = $event['post_row'];
352
+        $start = $this->request->variable('start', 0);
353
+        $data = $event['topic_data'];
354
+        $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
+        $event['post_row'] = $row;
356
+    }
357
+
358
+    /**
359
+     * Rewrite URLs in tas2580 Sitemap Extension
360
+     *
361
+     * @param	object	$event	The event object
362
+     * @return	null
363
+     * @access	public
364
+     */
365
+    public function sitemap_modify_before_output($event)
366
+    {
367
+        // Nothing to rewrite in the sitemap index
368
+        if ($event['type'] == 'sitemapindex')
369
+        {
370
+            return;
371
+        }
372
+
373
+        $url_data =$event['url_data'] ;
374
+
375
+        foreach ($url_data as $id => $data)
376
+        {
377
+            $row = $data['row'];
378
+            if (isset($row['topic_id']))
379
+            {
380
+                $url_data[$id]['url'] = $this->generate_topic_link($row['forum_id'], $row['forum_name'], $row['topic_id'], $row['topic_title'],  $data['start'], true);
381
+            }
382
+            else if (isset($row['forum_id']))
383
+            {
384
+                $url_data[$id]['url'] = $this->generate_forum_link($row['forum_id'], $row['forum_name'], $data['start'], true);
385
+            }
386
+        }
387
+
388
+        $event['url_data'] = $url_data;
389
+    }
390
+
391
+    /**
392
+     * Rewrite URLs in Similar Topics Extension
393
+     *
394
+     * @param	object	$event	The event object
395
+     * @return	null
396
+     * @access	public
397
+     */
398
+    public function similartopics_modify_topicrow($event)
399
+    {
400
+        $this->forum_title = $event['row']['forum_name'];
401
+        $this->forum_id = $event['row']['forum_id'];
402
+        $this->topic_title = $event['row']['topic_title'];
403
+        $this->topic_id = $event['row']['topic_id'];
404
+
405
+        $topic_row = $event['topic_row'];
406
+        $u_view_topic= $this->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title);
407
+        $topic_row['U_VIEW_TOPIC'] = append_sid($u_view_topic);
408
+        $topic_row['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($this->forum_id, $this->forum_title));
409
+        $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
+        $event['topic_row'] = $topic_row;
411
+    }
412
+
413
+    /**
414
+     * Rewrite URLs in Top 5 Extension
415
+     *
416
+     * @param	object	$event	The event object
417
+     * @return	null
418
+     * @access	public
419
+     */
420
+    public function topfive_sql_pull_topics_data($event)
421
+    {
422
+        $sql_array = $event['sql_array'];
423
+        $sql_array['SELECT'] = array_merge($sql_array, array('SELECT' => 'f.forum_name'));
424
+        $sql_array['LEFT_JOIN'] = array_merge($sql_array['LEFT_JOIN'], array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id'));
425
+        //	$event['sql_array'] = $sql_array;
426
+    }
427
+
428
+    /**
429
+     * Rewrite URLs in Top 5 Extension
430
+     *
431
+     * @param	object	$event	The event object
432
+     * @return	null
433
+     * @access	public
434
+     */
435
+    public function topfive_modify_tpl_ary($event)
436
+    {
437
+        $tpl_ary = $event['tpl_ary'];
438
+        $replies = $this->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1;
439
+        $u_view_topic = $this->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']);
440
+        $tpl_ary['U_TOPIC'] = append_sid($this->generate_lastpost_link($replies, $u_view_topic) . '#p' . $event['row']['topic_last_post_id']);
441
+        $event['tpl_ary'] = $tpl_ary;
442
+    }
443
+
444
+    /**
445
+     * Generate the SEO link for a topic
446
+     *
447
+     * @param	int		$forum_id		The ID of the forum
448
+     * @param	string	$forum_name		The title of the forum
449
+     * @param	int		$topic_id		The ID if the topic
450
+     * @param	string	$topic_title	The title of the topic
451
+     * @param	int		$start			Optional start parameter
452
+     * @param	bool	$full			Return the full URL
453
+     * @return	string	The SEO URL
454
+     * @access private
455
+     */
456
+    private function generate_topic_link($forum_id, $forum_name, $topic_id, $topic_title, $start = 0, $full = false)
457
+    {
458
+        if ($full)
459
+        {
460
+            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
+        }
462
+        return $this->path_helper->update_web_root_path($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
+    }
464
+
465
+    /**
466
+     * Generate the SEO link for a forum
467
+     *
468
+     * @param	int		$forum_id		The ID of the forum
469
+     * @param	string	$forum_name		The title of the forum
470
+     * @param	int		$start			Optional start parameter
471
+     * @param	bool	$full			Return the full URL
472
+     * @return	string	The SEO URL
473
+     * @access private
474
+     */
475
+    private function generate_forum_link($forum_id, $forum_name, $start = 0, $full = false)
476
+    {
477
+        if ($full)
478
+        {
479
+            return generate_board_url() . '/' . $this->title_to_url($forum_name) . '-f' . $forum_id . '/' . ($start ? 'index-s' . $start . '.html' : '');
480
+        }
481
+        return $this->path_helper->update_web_root_path($this->phpbb_root_path . $this->title_to_url($forum_name) . '-f' . $forum_id . '/' . ($start ? 'index-s' . $start . '.html' : ''));
482
+    }
483
+
484
+    /**
485
+     *
486
+     * @global	type	$_SID
487
+     * @param	int		$replies	Replays in the topic
488
+     * @param	string	$url		URL oft the topic
489
+     * @return	string				The URL with start included
490
+     */
491
+    private function generate_lastpost_link($replies, $url)
492
+    {
493
+        $url = str_replace('.html', '', $url);
494
+        $per_page = ($this->config['posts_per_page'] <= 0) ? 1 : $this->config['posts_per_page'];
495
+        if (($replies + 1) > $per_page)
496
+        {
497
+            for ($j = 0; $j < $replies + 1; $j += $per_page)
498
+            {
499
+                $last_post_link = $url . '-s' . $j . '.html';
500
+            }
501
+        }
502
+        else
503
+        {
504
+            $last_post_link = $url . '.html';
505
+        }
506
+        return $last_post_link;
507
+    }
508
+
509
+    /**
510
+     * Replace letters to use title in URL
511
+     *
512
+     * @param	string	$title	The title to use in the URL
513
+     * @return	string	Title to use in URLs
514
+     */
515
+    private function title_to_url($title)
516
+    {
517
+        $url = strtolower(censor_text(utf8_normalize_nfc(strip_tags($title))));
518
+
519
+        // Let's replace
520
+        $url_search = array(' ', 'í', 'ý', 'ß', 'ö', 'ô', 'ó', 'ò', 'ä', 'â', 'à', 'á', 'é', 'è', 'ü', 'ú', 'ù', 'ñ', 'ß', '²', '³', '@', '€', '$');
521
+        $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');
522
+        $url = str_replace($url_search, $url_replace, $url);
523
+        $url_search = array('&amp;', '&quot;', '&', '"', "'", '¸', '`', '(', ')', '[', ']', '<', '>', '{', '}', '.', ':', ',', ';', '!', '?', '+', '*', '/', '=', 'µ', '#', '~', '"', '§', '%', '|', '°', '^', '„', '“');
524
+        $url = str_replace($url_search, '-', $url);
525
+        $url = str_replace(array('----', '---', '--'), '-', $url);
526
+
527
+        $url = substr($url, 0, 50); // Max length for a title in URL
528
+        return urlencode($url);
529
+    }
530
+
531
+    /**
532
+     * Get the topics post count or the forums post/topic count based on permissions
533
+     *
534
+     * @param $mode            string    One of topic_posts, forum_posts or forum_topics
535
+     * @param $data            array    Array with the topic/forum data to calculate from
536
+     * @param $forum_id        int        The forum id is used for permission checks
537
+     * @return int    Number of posts/topics the user can see in the topic/forum
538
+     */
539
+    private function get_count($mode, $data, $forum_id)
540
+    {
541
+        if (!$this->auth->acl_get('m_approve', $forum_id))
542
+        {
543
+            return (int) $data[$mode . '_approved'];
544
+        }
545
+
546
+        return (int) $data[$mode . '_approved'] + (int) $data[$mode . '_unapproved'] + (int) $data[$mode . '_softdeleted'];
547
+    }
548 548
 
549 549
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
245 245
 		$url = $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, $url) . '#p' . $event['row']['topic_last_post_id']);
248
+		$tpl_ary['U_LAST_POST'] = append_sid($this->generate_lastpost_link($replies, $url).'#p'.$event['row']['topic_last_post_id']);
249 249
 		$tpl_ary['U_VIEW_TOPIC'] = append_sid($this->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']));
250 250
 		$tpl_ary['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($event['row']['forum_id'], $event['row']['forum_name']));
251 251
 
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 
270 270
 		$topic_row['U_VIEW_TOPIC'] = append_sid($this->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title));
271 271
 		$topic_row['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($this->forum_id, $this->forum_title));
272
-		$topic_row['U_LAST_POST'] = append_sid($this->generate_lastpost_link($event['topic_row']['REPLIES'], $topic_row['U_VIEW_TOPIC']) . '#p' . $event['row']['topic_last_post_id']);
272
+		$topic_row['U_LAST_POST'] = append_sid($this->generate_lastpost_link($event['topic_row']['REPLIES'], $topic_row['U_VIEW_TOPIC']).'#p'.$event['row']['topic_last_post_id']);
273 273
 
274 274
 		$event['topic_row'] = $topic_row;
275 275
 	}
@@ -303,8 +303,8 @@  discard block
 block discarded – undo
303 303
 	{
304 304
 		$data = $event['topic_data'];
305 305
 		$this->template->assign_vars(array(
306
-			'U_VIEW_TOPIC'		=> append_sid($this->generate_topic_link($event['forum_id'] , $data['forum_name'], $event['topic_id'], $data['topic_title'], $event['start'])),
307
-			'U_VIEW_FORUM'	=> append_sid($this->generate_forum_link($event['forum_id'] , $data['forum_name'])),
306
+			'U_VIEW_TOPIC'		=> append_sid($this->generate_topic_link($event['forum_id'], $data['forum_name'], $event['topic_id'], $data['topic_title'], $event['start'])),
307
+			'U_VIEW_FORUM'	=> append_sid($this->generate_forum_link($event['forum_id'], $data['forum_name'])),
308 308
 		));
309 309
 	}
310 310
 
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 		$row = $event['post_row'];
352 352
 		$start = $this->request->variable('start', 0);
353 353
 		$data = $event['topic_data'];
354
-		$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']);
354
+		$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 355
 		$event['post_row'] = $row;
356 356
 	}
357 357
 
@@ -370,14 +370,14 @@  discard block
 block discarded – undo
370 370
 			return;
371 371
 		}
372 372
 
373
-		$url_data =$event['url_data'] ;
373
+		$url_data = $event['url_data'];
374 374
 
375 375
 		foreach ($url_data as $id => $data)
376 376
 		{
377 377
 			$row = $data['row'];
378 378
 			if (isset($row['topic_id']))
379 379
 			{
380
-				$url_data[$id]['url'] = $this->generate_topic_link($row['forum_id'], $row['forum_name'], $row['topic_id'], $row['topic_title'],  $data['start'], true);
380
+				$url_data[$id]['url'] = $this->generate_topic_link($row['forum_id'], $row['forum_name'], $row['topic_id'], $row['topic_title'], $data['start'], true);
381 381
 			}
382 382
 			else if (isset($row['forum_id']))
383 383
 			{
@@ -403,10 +403,10 @@  discard block
 block discarded – undo
403 403
 		$this->topic_id = $event['row']['topic_id'];
404 404
 
405 405
 		$topic_row = $event['topic_row'];
406
-		$u_view_topic= $this->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title);
406
+		$u_view_topic = $this->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title);
407 407
 		$topic_row['U_VIEW_TOPIC'] = append_sid($u_view_topic);
408 408
 		$topic_row['U_VIEW_FORUM'] = append_sid($this->generate_forum_link($this->forum_id, $this->forum_title));
409
-		$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']);
409
+		$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 410
 		$event['topic_row'] = $topic_row;
411 411
 	}
412 412
 
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 		$tpl_ary = $event['tpl_ary'];
438 438
 		$replies = $this->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1;
439 439
 		$u_view_topic = $this->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']);
440
-		$tpl_ary['U_TOPIC'] = append_sid($this->generate_lastpost_link($replies, $u_view_topic) . '#p' . $event['row']['topic_last_post_id']);
440
+		$tpl_ary['U_TOPIC'] = append_sid($this->generate_lastpost_link($replies, $u_view_topic).'#p'.$event['row']['topic_last_post_id']);
441 441
 		$event['tpl_ary'] = $tpl_ary;
442 442
 	}
443 443
 
@@ -457,9 +457,9 @@  discard block
 block discarded – undo
457 457
 	{
458 458
 		if ($full)
459 459
 		{
460
-			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';
460
+			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 461
 		}
462
-		return $this->path_helper->update_web_root_path($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');
462
+		return $this->path_helper->update_web_root_path($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 463
 	}
464 464
 
465 465
 	/**
@@ -476,9 +476,9 @@  discard block
 block discarded – undo
476 476
 	{
477 477
 		if ($full)
478 478
 		{
479
-			return generate_board_url() . '/' . $this->title_to_url($forum_name) . '-f' . $forum_id . '/' . ($start ? 'index-s' . $start . '.html' : '');
479
+			return generate_board_url().'/'.$this->title_to_url($forum_name).'-f'.$forum_id.'/'.($start ? 'index-s'.$start.'.html' : '');
480 480
 		}
481
-		return $this->path_helper->update_web_root_path($this->phpbb_root_path . $this->title_to_url($forum_name) . '-f' . $forum_id . '/' . ($start ? 'index-s' . $start . '.html' : ''));
481
+		return $this->path_helper->update_web_root_path($this->phpbb_root_path.$this->title_to_url($forum_name).'-f'.$forum_id.'/'.($start ? 'index-s'.$start.'.html' : ''));
482 482
 	}
483 483
 
484 484
 	/**
@@ -496,12 +496,12 @@  discard block
 block discarded – undo
496 496
 		{
497 497
 			for ($j = 0; $j < $replies + 1; $j += $per_page)
498 498
 			{
499
-				$last_post_link = $url . '-s' . $j . '.html';
499
+				$last_post_link = $url.'-s'.$j.'.html';
500 500
 			}
501 501
 		}
502 502
 		else
503 503
 		{
504
-			$last_post_link = $url . '.html';
504
+			$last_post_link = $url.'.html';
505 505
 		}
506 506
 		return $last_post_link;
507 507
 	}
@@ -540,10 +540,10 @@  discard block
 block discarded – undo
540 540
 	{
541 541
 		if (!$this->auth->acl_get('m_approve', $forum_id))
542 542
 		{
543
-			return (int) $data[$mode . '_approved'];
543
+			return (int) $data[$mode.'_approved'];
544 544
 		}
545 545
 
546
-		return (int) $data[$mode . '_approved'] + (int) $data[$mode . '_unapproved'] + (int) $data[$mode . '_softdeleted'];
546
+		return (int) $data[$mode.'_approved'] + (int) $data[$mode.'_unapproved'] + (int) $data[$mode.'_softdeleted'];
547 547
 	}
548 548
 
549 549
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -225,8 +225,7 @@  discard block
 block discarded – undo
225 225
 		if (!empty($this->topic_title))
226 226
 		{
227 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))
228
+		} else if (!empty($this->forum_title))
230 229
 		{
231 230
 			$event['generate_page_link_override'] = append_sid($this->generate_forum_link($this->forum_id, $this->forum_title, $start));
232 231
 		}
@@ -378,8 +377,7 @@  discard block
 block discarded – undo
378 377
 			if (isset($row['topic_id']))
379 378
 			{
380 379
 				$url_data[$id]['url'] = $this->generate_topic_link($row['forum_id'], $row['forum_name'], $row['topic_id'], $row['topic_title'],  $data['start'], true);
381
-			}
382
-			else if (isset($row['forum_id']))
380
+			} else if (isset($row['forum_id']))
383 381
 			{
384 382
 				$url_data[$id]['url'] = $this->generate_forum_link($row['forum_id'], $row['forum_name'], $data['start'], true);
385 383
 			}
@@ -498,8 +496,7 @@  discard block
 block discarded – undo
498 496
 			{
499 497
 				$last_post_link = $url . '-s' . $j . '.html';
500 498
 			}
501
-		}
502
-		else
499
+		} else
503 500
 		{
504 501
 			$last_post_link = $url . '.html';
505 502
 		}
Please login to merge, or discard this patch.