Passed
Push — master ( 8e84d0...0b6a6a )
by Tobias
43s
created
event/listener.php 2 patches
Indentation   +408 added lines, -408 removed lines patch added patch discarded remove patch
@@ -16,412 +16,412 @@
 block discarded – undo
16 16
  */
17 17
 class listener implements EventSubscriberInterface
18 18
 {
19
-	/** @var \tas2580\seourls\event\base */
20
-	protected $base;
21
-
22
-	/** @var \phpbb\template\template */
23
-	protected $template;
24
-
25
-	/** @var \phpbb\request\request */
26
-	protected $request;
27
-
28
-	/** @var \phpbb\path_helper */
29
-	protected $path_helper;
30
-
31
-	/** @var string phpbb_root_path */
32
-	protected $phpbb_root_path;
33
-
34
-	/** @var string php_ext */
35
-	protected $php_ext;
36
-
37
-	/**
38
-	 * Constructor
39
-	 *
40
-	 * @param \tas2580\seourls\event\base	$base
41
-	 * @param \phpbb\template\template		$template				Template object
42
-	 * @param \phpbb\request\request		$request				Request object
43
-	 * @param \phpbb\path_helper			$path_helper			Controller helper object
44
-	 * @param string						$phpbb_root_path		phpbb_root_path
45
-	 * @param string						$php_ext				php_ext
46
-	 * @access public
47
-	 */
48
-	public function __construct(\tas2580\seourls\event\base $base, \phpbb\template\template $template, \phpbb\request\request $request, \phpbb\path_helper $path_helper, $phpbb_root_path, $php_ext)
49
-	{
50
-		$this->base = $base;
51
-		$this->template = $template;
52
-		$this->request = $request;
53
-		$this->path_helper = $path_helper;
54
-		$this->phpbb_root_path = $phpbb_root_path;
55
-		$this->php_ext = $php_ext;
56
-
57
-		$this->in_viewtopic = false;
58
-	}
59
-
60
-	/**
61
-	 * Assign functions defined in this class to event listeners in the core
62
-	 *
63
-	 * @return array
64
-	 * @static
65
-	 * @access public
66
-	 */
67
-	public static function getSubscribedEvents()
68
-	{
69
-		return array(
70
-			'core.append_sid'										=> 'append_sid',
71
-			'core.display_forums_modify_sql'						=> 'display_forums_modify_sql',
72
-			'core.display_forums_modify_template_vars'				=> 'display_forums_modify_template_vars',
73
-			'core.display_forums_modify_forum_rows'					=> 'display_forums_modify_forum_rows',
74
-			'core.display_forums_modify_category_template_vars'		=> 'display_forums_modify_category_template_vars',
75
-			'core.generate_forum_nav'								=> 'generate_forum_nav',
76
-			'core.make_jumpbox_modify_tpl_ary'						=> 'make_jumpbox_modify_tpl_ary',				// Not in phpBB
77
-			'core.memberlist_view_profile'							=> 'memberlist_view_profile',
78
-			'core.pagination_generate_page_link'					=> 'pagination_generate_page_link',
79
-			'core.search_modify_tpl_ary'							=> 'search_modify_tpl_ary',
80
-			'core.viewforum_modify_topicrow'						=> 'viewforum_modify_topicrow',
81
-			'core.viewforum_get_topic_data'							=> 'viewforum_get_topic_data',
82
-			'core.viewtopic_assign_template_vars_before'			=> 'viewtopic_assign_template_vars_before',
83
-			'core.viewtopic_before_f_read_check'					=> 'viewtopic_before_f_read_check',
84
-			'core.viewtopic_modify_page_title'						=> 'viewtopic_modify_page_title',
85
-			'core.viewtopic_modify_post_row'						=> 'viewtopic_modify_post_row',
86
-			'core.viewtopic_get_post_data'							=> 'viewtopic_get_post_data',
87
-		);
88
-	}
89
-
90
-	/**
91
-	 * Correct the path of $viewtopic_url
92
-	 *
93
-	 * @param	object	$event	The event object
94
-	 * @return	null
95
-	 * @access	public
96
-	 */
97
-	public function append_sid($event)
98
-	{
99
-		if ($this->in_viewtopic && preg_match('#./../viewtopic.' . $this->php_ext  . '#', $event['url']))
100
-		{
101
-			$url = '../viewtopic.' . $this->php_ext ;
102
-			$event['url'] = $url;
103
-		}
104
-		if (isset($event['params']['redirect']))
105
-		{
106
-			$params = $event['params'];
107
-			$params['redirect'] = str_replace('..', '.', $event['params']['redirect']);
108
-			$event['params'] = $params;
109
-		}
110
-	}
111
-
112
-	/**
113
-	 * Get informations for the last post from Database
114
-	 *
115
-	 * @param	object	$event	The event object
116
-	 * @return	null
117
-	 * @access	public
118
-	 */
119
-	public function display_forums_modify_sql($event)
120
-	{
121
-		$sql_array = $event['sql_ary'];
122
-		$sql_array['LEFT_JOIN'][] = array(
123
-			'FROM' => array(TOPICS_TABLE => 't'),
124
-			'ON' => "f.forum_last_post_id = t.topic_last_post_id"
125
-		);
126
-		$sql_array['SELECT'] .= ', t.topic_title, t.topic_id, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted';
127
-		$event['sql_ary'] = $sql_array;
128
-	}
129
-
130
-	/**
131
-	 * Store informations for the last post in forum_rows array
132
-	 *
133
-	 * @param	object	$event	The event object
134
-	 * @return	null
135
-	 * @access	public
136
-	 */
137
-	public function display_forums_modify_forum_rows($event)
138
-	{
139
-		$forum_rows = $event['forum_rows'];
140
-		if ($event['row']['forum_last_post_time'] == $forum_rows[$event['parent_id']]['forum_last_post_time'])
141
-		{
142
-			$forum_rows[$event['parent_id']]['forum_name_last_post'] =$event['row']['forum_name'];
143
-			$forum_rows[$event['parent_id']]['topic_id_last_post'] =$event['row']['topic_id'];
144
-			$forum_rows[$event['parent_id']]['topic_title_last_post'] =$event['row']['topic_title'];
145
-			$event['forum_rows'] = $forum_rows;
146
-		}
147
-	}
148
-
149
-	/**
150
-	 * Rewrite links to forums and subforums in forum index
151
-	 * also correct the path of the forum images if we are in a forum
152
-	 *
153
-	 * @param	object	$event	The event object
154
-	 * @return	null
155
-	 * @access	public
156
-	 */
157
-	public function display_forums_modify_template_vars($event)
158
-	{
159
-		$subforums_row = $event['subforums_row'];
160
-		$forum_row = $event['forum_row'];
161
-
162
-		// Rewrite URLs of sub forums
163
-		foreach ($subforums_row as $i => $subforum)
164
-		{
165
-			// A little bit a dirty way, but there is no better solution
166
-			$query = str_replace('&', '&', parse_url($subforum['U_SUBFORUM'], PHP_URL_QUERY));
167
-			parse_str($query, $id);
168
-			$subforums_row[$i]['U_SUBFORUM'] = append_sid($this->base->generate_forum_link($id['f'], $subforum['SUBFORUM_NAME']));
169
-		}
170
-
171
-		// Update the image source in forums
172
-		$img = $this->path_helper->update_web_root_path($forum_row['FORUM_IMAGE_SRC']);
173
-		$forum_row['FORUM_IMAGE'] = preg_replace('#img src=\"(.*)\" alt#', 'img src="' . $img . '" alt', $forum_row['FORUM_IMAGE']);
174
-
175
-		// Rewrite links to topics, posts and forums
176
-		$replies = $this->base->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1;
177
-		$url = $this->base->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']);
178
-		$forum_row['U_LAST_POST'] = append_sid($this->base->generate_lastpost_link($replies, $url) . '#p' . $event['row']['forum_last_post_id']);
179
-		$forum_row['U_VIEWFORUM'] = append_sid($this->base->generate_forum_link($forum_row['FORUM_ID'], $forum_row['FORUM_NAME']));
180
-		$forum_row['U_NEWEST_POST'] = $url . '?view=unread#unread';
181
-
182
-		$event['subforums_row'] = $subforums_row;
183
-		$event['forum_row'] = $forum_row;
184
-	}
185
-
186
-	/**
187
-	 * Rewrite the categorie links
188
-	 *
189
-	 * @param	object	$event	The event object
190
-	 * @return	null
191
-	 * @access	public
192
-	 */
193
-	public function display_forums_modify_category_template_vars($event)
194
-	{
195
-		$cat_row = $event['cat_row'];
196
-		$row = $event['row'];
197
-		$cat_row['U_VIEWFORUM'] = append_sid($this->base->generate_forum_link($row['forum_id'], $row['forum_name']));
198
-		$event['cat_row'] = $cat_row;
199
-	}
200
-
201
-	/**
202
-	 * Rewrite links in breadcrumbs
203
-	 *
204
-	 * @param	object	$event	The event object
205
-	 * @return	null
206
-	 * @access	public
207
-	 */
208
-	public function generate_forum_nav($event)
209
-	{
210
-		$forum_data = $event['forum_data'];
211
-		$navlinks = $event['navlinks'];
212
-		$navlinks_parents = $event['navlinks_parents'];
213
-
214
-		foreach ($navlinks_parents as $id => $data)
215
-		{
216
-			$navlinks_parents[$id]['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($data['FORUM_ID'] , $data['FORUM_NAME']));
217
-		}
218
-
219
-		$navlinks['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($forum_data['forum_id'], $forum_data['forum_name']));
220
-		$event['navlinks'] = $navlinks;
221
-		$event['navlinks_parents'] = $navlinks_parents;
222
-	}
223
-
224
-	// Not in phpBB
225
-	public function make_jumpbox_modify_tpl_ary($event)
226
-	{
227
-		$tpl_ary = $event['tpl_ary'];
228
-		$row = $event['row'];
229
-		foreach ($tpl_ary as $id => $data)
230
-		{
231
-			$tpl_ary[$id]['LINK']	 = append_sid($this->base->generate_forum_link($row['forum_id'], $row['forum_name']));
232
-		}
233
-
234
-		$event['tpl_ary'] = $tpl_ary;
235
-	}
236
-
237
-	/**
238
-	 * Rewrite links to most active forum and topic on profile page
239
-	 *
240
-	 * @param	object	$event	The event object
241
-	 * @return	null
242
-	 * @access	public
243
-	 */
244
-	public function memberlist_view_profile($event)
245
-	{
246
-		$data = $event['member'];
247
-		$this->template->assign_vars(array(
248
-			'U_ACTIVE_FORUM' => $this->base->generate_forum_link($data['active_f_row']['forum_id'], $data['active_f_row']['forum_name'], 0, true),
249
-			'U_ACTIVE_TOPIC' => $this->base->generate_topic_link($data['active_f_row']['forum_id'], $data['active_f_row']['forum_name'], $data['active_t_row']['topic_id'], $data['active_t_row']['topic_title'], 0, true),
250
-		));
251
-	}
252
-
253
-	/**
254
-	 * Rewrite pagination links
255
-	 *
256
-	 * @param	object	$event	The event object
257
-	 * @return	null
258
-	 * @access	public
259
-	 */
260
-	public function pagination_generate_page_link($event)
261
-	{
262
-		if(!is_string($event['base_url']))
263
-		{
264
-			return;
265
-		}
266
-		// If we have a sort key we do not rewrite the URL
267
-		$query = str_replace('&', '&', parse_url($event['base_url'], PHP_URL_QUERY));
268
-		parse_str($query, $param);
269
-		if (isset($param['sd']) || isset($param['sk']) || isset($param['st']))
270
-		{
271
-			return;
272
-		}
273
-
274
-		$start = (($event['on_page'] - 1) * $event['per_page']);
275
-		if (!empty($this->topic_data) && isset($param['f']) && isset($param['t']))
276
-		{
277
-			$event['generate_page_link_override'] = append_sid($this->base->generate_topic_link($this->topic_data['forum_id'], $this->topic_data['forum_name'], $this->topic_data['topic_id'], $this->topic_data['topic_title'], $start));
278
-		}
279
-		else if (!empty($this->forum_data) && isset($param['f']))
280
-		{
281
-			$event['generate_page_link_override'] = append_sid($this->base->generate_forum_link($this->forum_data['forum_id'], $this->forum_data['forum_name'], $start));
282
-		}
283
-	}
284
-
285
-	/**
286
-	 * Rewrite links in the search result
287
-	 *
288
-	 * @param	object	$event	The event object
289
-	 * @return	null
290
-	 * @access	public
291
-	 */
292
-	public function search_modify_tpl_ary($event)
293
-	{
294
-		$replies = $this->base->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1;
295
-		$u_view_topic = $this->base->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']);
296
-
297
-		$tpl_ary = $event['tpl_ary'];
298
-		$tpl_ary['U_LAST_POST'] = append_sid($this->base->generate_lastpost_link($replies, $u_view_topic) . '#p' . $event['row']['topic_last_post_id']);
299
-		$tpl_ary['U_VIEW_TOPIC'] = append_sid($u_view_topic);
300
-		$tpl_ary['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($event['row']['forum_id'], $event['row']['forum_name']));
301
-		$tpl_ary['U_NEWEST_POST'] = $u_view_topic . '?view=unread#unread';
302
-
303
-		$event['tpl_ary'] = $tpl_ary;
304
-	}
305
-
306
-	/**
307
-	 * Rewrite links to topics in forum view
308
-	 *
309
-	 * @param	object	$event	The event object
310
-	 * @return	null
311
-	 * @access	public
312
-	 */
313
-	public function viewforum_modify_topicrow($event)
314
-	{
315
-		// assign to be used in pagination_generate_page_link
316
-		$this->topic_data = array(
317
-			'forum_id' => $event['topic_row']['FORUM_ID'],
318
-			'forum_name' => $event['topic_row']['FORUM_NAME'],
319
-			'topic_id' => $event['topic_row']['TOPIC_ID'],
320
-			'topic_title' => $event['topic_row']['TOPIC_TITLE']
321
-		);
322
-
323
-		$topic_row = $event['topic_row'];
324
-
325
-		$u_view_topic = $this->base->generate_topic_link($topic_row['FORUM_ID'], $topic_row['FORUM_NAME'], $topic_row['TOPIC_ID'], $topic_row['TOPIC_TITLE']);
326
-		$topic_row['U_VIEW_TOPIC'] = append_sid($u_view_topic);
327
-		$topic_row['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($topic_row['FORUM_ID'], $topic_row['FORUM_NAME']));
328
-		$topic_row['U_LAST_POST'] = append_sid($this->base->generate_lastpost_link($event['topic_row']['REPLIES'], $u_view_topic) . '#p' . $event['row']['topic_last_post_id']);
329
-		$topic_row['U_NEWEST_POST'] = $u_view_topic . '?view=unread#unread';
330
-
331
-		$event['topic_row'] = $topic_row;
332
-	}
333
-
334
-	/**
335
-	 * Rewrite the canonical URL on viewforum.php
336
-	 *
337
-	 * @param	object	$event	The event object
338
-	 * @return	null
339
-	 * @access	public
340
-	 */
341
-	public function viewforum_get_topic_data($event)
342
-	{
343
-		// assign to be used in pagination_generate_page_link
344
-		$this->forum_data = array(
345
-			'forum_id' => $event['forum_data']['forum_id'],
346
-			'forum_name' => $event['forum_data']['forum_name']
347
-		);
348
-
349
-		$start = $this->request->variable('start', 0);
350
-		$this->template->assign_vars(array(
351
-			'U_VIEW_FORUM'		=> append_sid($this->base->generate_forum_link($event['forum_data']['forum_id'], $event['forum_data']['forum_name'], $start)),
352
-			'U_CANONICAL'		=> $this->base->generate_forum_link($event['forum_data']['forum_id'], $event['forum_data']['forum_name'], $start, true),
353
-		));
354
-	}
355
-
356
-	/**
357
-	 * Rewrite the topic URL for the headline of the topic page and the link back to forum
358
-	 *
359
-	 * @param	object	$event	The event object
360
-	 * @return	null
361
-	 * @access	public
362
-	 */
363
-	public function viewtopic_get_post_data($event)
364
-	{
365
-		$data = $event['topic_data'];
366
-		$this->template->assign_vars(array(
367
-			'U_VIEW_TOPIC'		=> append_sid($this->base->generate_topic_link($event['forum_id'] , $data['forum_name'], $event['topic_id'], $data['topic_title'], $event['start'])),
368
-			'U_VIEW_FORUM'		=> append_sid($this->base->generate_forum_link($event['forum_id'] , $data['forum_name'])),
369
-			'S_POLL_ACTION'		=> append_sid($this->base->generate_topic_link($event['forum_id'] , $data['forum_name'], $event['topic_id'], $data['topic_title'], $event['start'])),
370
-		));
371
-	}
372
-
373
-	/**
374
-	 * Assign topic data to global variables for pagination
375
-	 *
376
-	 * @param	object	$event	The event object
377
-	 * @return	null
378
-	 * @access	public
379
-	 */
380
-	public function viewtopic_assign_template_vars_before($event)
381
-	{
382
-		// assign to be used in pagination_generate_page_link
383
-		$this->topic_data = array(
384
-			'forum_id' => $event['topic_data']['forum_id'],
385
-			'forum_name' => $event['topic_data']['forum_name'],
386
-			'topic_id' => $event['topic_data']['topic_id'],
387
-			'topic_title' => $event['topic_data']['topic_title']
388
-		);
389
-	}
390
-
391
-	public function viewtopic_before_f_read_check()
392
-	{
393
-		$this->in_viewtopic = true;
394
-	}
395
-
396
-	/**
397
-	 * Rewrite the canonical URL on viewtopic.php
398
-	 *
399
-	 * @param	object	$event	The event object
400
-	 * @return	null
401
-	 * @access	public
402
-	 */
403
-	public function viewtopic_modify_page_title($event)
404
-	{
405
-		$start = $this->request->variable('start', 0);
406
-		$data = $event['topic_data'];
407
-		$this->template->assign_vars(array(
408
-			'U_CANONICAL'		=> $this->base->generate_topic_link($data['forum_id'], $data['forum_name'], $data['topic_id'], $data['topic_title'], $start, true),
409
-		));
410
-	}
411
-
412
-	/**
413
-	 * Rewrite mini post img link
414
-	 *
415
-	 * @param	object	$event	The event object
416
-	 * @return	null
417
-	 * @access	public
418
-	 */
419
-	public function viewtopic_modify_post_row($event)
420
-	{
421
-		$row = $event['post_row'];
422
-		$start = $this->request->variable('start', 0);
423
-		$data = $event['topic_data'];
424
-		$row['U_MINI_POST'] = append_sid($this->base->generate_topic_link($data['forum_id'], $data['forum_name'], $data['topic_id'], $data['topic_title'], $start) . '#p' . $event['row']['post_id']);
425
-		$event['post_row'] = $row;
426
-	}
19
+    /** @var \tas2580\seourls\event\base */
20
+    protected $base;
21
+
22
+    /** @var \phpbb\template\template */
23
+    protected $template;
24
+
25
+    /** @var \phpbb\request\request */
26
+    protected $request;
27
+
28
+    /** @var \phpbb\path_helper */
29
+    protected $path_helper;
30
+
31
+    /** @var string phpbb_root_path */
32
+    protected $phpbb_root_path;
33
+
34
+    /** @var string php_ext */
35
+    protected $php_ext;
36
+
37
+    /**
38
+     * Constructor
39
+     *
40
+     * @param \tas2580\seourls\event\base	$base
41
+     * @param \phpbb\template\template		$template				Template object
42
+     * @param \phpbb\request\request		$request				Request object
43
+     * @param \phpbb\path_helper			$path_helper			Controller helper object
44
+     * @param string						$phpbb_root_path		phpbb_root_path
45
+     * @param string						$php_ext				php_ext
46
+     * @access public
47
+     */
48
+    public function __construct(\tas2580\seourls\event\base $base, \phpbb\template\template $template, \phpbb\request\request $request, \phpbb\path_helper $path_helper, $phpbb_root_path, $php_ext)
49
+    {
50
+        $this->base = $base;
51
+        $this->template = $template;
52
+        $this->request = $request;
53
+        $this->path_helper = $path_helper;
54
+        $this->phpbb_root_path = $phpbb_root_path;
55
+        $this->php_ext = $php_ext;
56
+
57
+        $this->in_viewtopic = false;
58
+    }
59
+
60
+    /**
61
+     * Assign functions defined in this class to event listeners in the core
62
+     *
63
+     * @return array
64
+     * @static
65
+     * @access public
66
+     */
67
+    public static function getSubscribedEvents()
68
+    {
69
+        return array(
70
+            'core.append_sid'										=> 'append_sid',
71
+            'core.display_forums_modify_sql'						=> 'display_forums_modify_sql',
72
+            'core.display_forums_modify_template_vars'				=> 'display_forums_modify_template_vars',
73
+            'core.display_forums_modify_forum_rows'					=> 'display_forums_modify_forum_rows',
74
+            'core.display_forums_modify_category_template_vars'		=> 'display_forums_modify_category_template_vars',
75
+            'core.generate_forum_nav'								=> 'generate_forum_nav',
76
+            'core.make_jumpbox_modify_tpl_ary'						=> 'make_jumpbox_modify_tpl_ary',				// Not in phpBB
77
+            'core.memberlist_view_profile'							=> 'memberlist_view_profile',
78
+            'core.pagination_generate_page_link'					=> 'pagination_generate_page_link',
79
+            'core.search_modify_tpl_ary'							=> 'search_modify_tpl_ary',
80
+            'core.viewforum_modify_topicrow'						=> 'viewforum_modify_topicrow',
81
+            'core.viewforum_get_topic_data'							=> 'viewforum_get_topic_data',
82
+            'core.viewtopic_assign_template_vars_before'			=> 'viewtopic_assign_template_vars_before',
83
+            'core.viewtopic_before_f_read_check'					=> 'viewtopic_before_f_read_check',
84
+            'core.viewtopic_modify_page_title'						=> 'viewtopic_modify_page_title',
85
+            'core.viewtopic_modify_post_row'						=> 'viewtopic_modify_post_row',
86
+            'core.viewtopic_get_post_data'							=> 'viewtopic_get_post_data',
87
+        );
88
+    }
89
+
90
+    /**
91
+     * Correct the path of $viewtopic_url
92
+     *
93
+     * @param	object	$event	The event object
94
+     * @return	null
95
+     * @access	public
96
+     */
97
+    public function append_sid($event)
98
+    {
99
+        if ($this->in_viewtopic && preg_match('#./../viewtopic.' . $this->php_ext  . '#', $event['url']))
100
+        {
101
+            $url = '../viewtopic.' . $this->php_ext ;
102
+            $event['url'] = $url;
103
+        }
104
+        if (isset($event['params']['redirect']))
105
+        {
106
+            $params = $event['params'];
107
+            $params['redirect'] = str_replace('..', '.', $event['params']['redirect']);
108
+            $event['params'] = $params;
109
+        }
110
+    }
111
+
112
+    /**
113
+     * Get informations for the last post from Database
114
+     *
115
+     * @param	object	$event	The event object
116
+     * @return	null
117
+     * @access	public
118
+     */
119
+    public function display_forums_modify_sql($event)
120
+    {
121
+        $sql_array = $event['sql_ary'];
122
+        $sql_array['LEFT_JOIN'][] = array(
123
+            'FROM' => array(TOPICS_TABLE => 't'),
124
+            'ON' => "f.forum_last_post_id = t.topic_last_post_id"
125
+        );
126
+        $sql_array['SELECT'] .= ', t.topic_title, t.topic_id, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted';
127
+        $event['sql_ary'] = $sql_array;
128
+    }
129
+
130
+    /**
131
+     * Store informations for the last post in forum_rows array
132
+     *
133
+     * @param	object	$event	The event object
134
+     * @return	null
135
+     * @access	public
136
+     */
137
+    public function display_forums_modify_forum_rows($event)
138
+    {
139
+        $forum_rows = $event['forum_rows'];
140
+        if ($event['row']['forum_last_post_time'] == $forum_rows[$event['parent_id']]['forum_last_post_time'])
141
+        {
142
+            $forum_rows[$event['parent_id']]['forum_name_last_post'] =$event['row']['forum_name'];
143
+            $forum_rows[$event['parent_id']]['topic_id_last_post'] =$event['row']['topic_id'];
144
+            $forum_rows[$event['parent_id']]['topic_title_last_post'] =$event['row']['topic_title'];
145
+            $event['forum_rows'] = $forum_rows;
146
+        }
147
+    }
148
+
149
+    /**
150
+     * Rewrite links to forums and subforums in forum index
151
+     * also correct the path of the forum images if we are in a forum
152
+     *
153
+     * @param	object	$event	The event object
154
+     * @return	null
155
+     * @access	public
156
+     */
157
+    public function display_forums_modify_template_vars($event)
158
+    {
159
+        $subforums_row = $event['subforums_row'];
160
+        $forum_row = $event['forum_row'];
161
+
162
+        // Rewrite URLs of sub forums
163
+        foreach ($subforums_row as $i => $subforum)
164
+        {
165
+            // A little bit a dirty way, but there is no better solution
166
+            $query = str_replace('&', '&', parse_url($subforum['U_SUBFORUM'], PHP_URL_QUERY));
167
+            parse_str($query, $id);
168
+            $subforums_row[$i]['U_SUBFORUM'] = append_sid($this->base->generate_forum_link($id['f'], $subforum['SUBFORUM_NAME']));
169
+        }
170
+
171
+        // Update the image source in forums
172
+        $img = $this->path_helper->update_web_root_path($forum_row['FORUM_IMAGE_SRC']);
173
+        $forum_row['FORUM_IMAGE'] = preg_replace('#img src=\"(.*)\" alt#', 'img src="' . $img . '" alt', $forum_row['FORUM_IMAGE']);
174
+
175
+        // Rewrite links to topics, posts and forums
176
+        $replies = $this->base->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1;
177
+        $url = $this->base->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']);
178
+        $forum_row['U_LAST_POST'] = append_sid($this->base->generate_lastpost_link($replies, $url) . '#p' . $event['row']['forum_last_post_id']);
179
+        $forum_row['U_VIEWFORUM'] = append_sid($this->base->generate_forum_link($forum_row['FORUM_ID'], $forum_row['FORUM_NAME']));
180
+        $forum_row['U_NEWEST_POST'] = $url . '?view=unread#unread';
181
+
182
+        $event['subforums_row'] = $subforums_row;
183
+        $event['forum_row'] = $forum_row;
184
+    }
185
+
186
+    /**
187
+     * Rewrite the categorie links
188
+     *
189
+     * @param	object	$event	The event object
190
+     * @return	null
191
+     * @access	public
192
+     */
193
+    public function display_forums_modify_category_template_vars($event)
194
+    {
195
+        $cat_row = $event['cat_row'];
196
+        $row = $event['row'];
197
+        $cat_row['U_VIEWFORUM'] = append_sid($this->base->generate_forum_link($row['forum_id'], $row['forum_name']));
198
+        $event['cat_row'] = $cat_row;
199
+    }
200
+
201
+    /**
202
+     * Rewrite links in breadcrumbs
203
+     *
204
+     * @param	object	$event	The event object
205
+     * @return	null
206
+     * @access	public
207
+     */
208
+    public function generate_forum_nav($event)
209
+    {
210
+        $forum_data = $event['forum_data'];
211
+        $navlinks = $event['navlinks'];
212
+        $navlinks_parents = $event['navlinks_parents'];
213
+
214
+        foreach ($navlinks_parents as $id => $data)
215
+        {
216
+            $navlinks_parents[$id]['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($data['FORUM_ID'] , $data['FORUM_NAME']));
217
+        }
218
+
219
+        $navlinks['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($forum_data['forum_id'], $forum_data['forum_name']));
220
+        $event['navlinks'] = $navlinks;
221
+        $event['navlinks_parents'] = $navlinks_parents;
222
+    }
223
+
224
+    // Not in phpBB
225
+    public function make_jumpbox_modify_tpl_ary($event)
226
+    {
227
+        $tpl_ary = $event['tpl_ary'];
228
+        $row = $event['row'];
229
+        foreach ($tpl_ary as $id => $data)
230
+        {
231
+            $tpl_ary[$id]['LINK']	 = append_sid($this->base->generate_forum_link($row['forum_id'], $row['forum_name']));
232
+        }
233
+
234
+        $event['tpl_ary'] = $tpl_ary;
235
+    }
236
+
237
+    /**
238
+     * Rewrite links to most active forum and topic on profile page
239
+     *
240
+     * @param	object	$event	The event object
241
+     * @return	null
242
+     * @access	public
243
+     */
244
+    public function memberlist_view_profile($event)
245
+    {
246
+        $data = $event['member'];
247
+        $this->template->assign_vars(array(
248
+            'U_ACTIVE_FORUM' => $this->base->generate_forum_link($data['active_f_row']['forum_id'], $data['active_f_row']['forum_name'], 0, true),
249
+            'U_ACTIVE_TOPIC' => $this->base->generate_topic_link($data['active_f_row']['forum_id'], $data['active_f_row']['forum_name'], $data['active_t_row']['topic_id'], $data['active_t_row']['topic_title'], 0, true),
250
+        ));
251
+    }
252
+
253
+    /**
254
+     * Rewrite pagination links
255
+     *
256
+     * @param	object	$event	The event object
257
+     * @return	null
258
+     * @access	public
259
+     */
260
+    public function pagination_generate_page_link($event)
261
+    {
262
+        if(!is_string($event['base_url']))
263
+        {
264
+            return;
265
+        }
266
+        // If we have a sort key we do not rewrite the URL
267
+        $query = str_replace('&', '&', parse_url($event['base_url'], PHP_URL_QUERY));
268
+        parse_str($query, $param);
269
+        if (isset($param['sd']) || isset($param['sk']) || isset($param['st']))
270
+        {
271
+            return;
272
+        }
273
+
274
+        $start = (($event['on_page'] - 1) * $event['per_page']);
275
+        if (!empty($this->topic_data) && isset($param['f']) && isset($param['t']))
276
+        {
277
+            $event['generate_page_link_override'] = append_sid($this->base->generate_topic_link($this->topic_data['forum_id'], $this->topic_data['forum_name'], $this->topic_data['topic_id'], $this->topic_data['topic_title'], $start));
278
+        }
279
+        else if (!empty($this->forum_data) && isset($param['f']))
280
+        {
281
+            $event['generate_page_link_override'] = append_sid($this->base->generate_forum_link($this->forum_data['forum_id'], $this->forum_data['forum_name'], $start));
282
+        }
283
+    }
284
+
285
+    /**
286
+     * Rewrite links in the search result
287
+     *
288
+     * @param	object	$event	The event object
289
+     * @return	null
290
+     * @access	public
291
+     */
292
+    public function search_modify_tpl_ary($event)
293
+    {
294
+        $replies = $this->base->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1;
295
+        $u_view_topic = $this->base->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']);
296
+
297
+        $tpl_ary = $event['tpl_ary'];
298
+        $tpl_ary['U_LAST_POST'] = append_sid($this->base->generate_lastpost_link($replies, $u_view_topic) . '#p' . $event['row']['topic_last_post_id']);
299
+        $tpl_ary['U_VIEW_TOPIC'] = append_sid($u_view_topic);
300
+        $tpl_ary['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($event['row']['forum_id'], $event['row']['forum_name']));
301
+        $tpl_ary['U_NEWEST_POST'] = $u_view_topic . '?view=unread#unread';
302
+
303
+        $event['tpl_ary'] = $tpl_ary;
304
+    }
305
+
306
+    /**
307
+     * Rewrite links to topics in forum view
308
+     *
309
+     * @param	object	$event	The event object
310
+     * @return	null
311
+     * @access	public
312
+     */
313
+    public function viewforum_modify_topicrow($event)
314
+    {
315
+        // assign to be used in pagination_generate_page_link
316
+        $this->topic_data = array(
317
+            'forum_id' => $event['topic_row']['FORUM_ID'],
318
+            'forum_name' => $event['topic_row']['FORUM_NAME'],
319
+            'topic_id' => $event['topic_row']['TOPIC_ID'],
320
+            'topic_title' => $event['topic_row']['TOPIC_TITLE']
321
+        );
322
+
323
+        $topic_row = $event['topic_row'];
324
+
325
+        $u_view_topic = $this->base->generate_topic_link($topic_row['FORUM_ID'], $topic_row['FORUM_NAME'], $topic_row['TOPIC_ID'], $topic_row['TOPIC_TITLE']);
326
+        $topic_row['U_VIEW_TOPIC'] = append_sid($u_view_topic);
327
+        $topic_row['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($topic_row['FORUM_ID'], $topic_row['FORUM_NAME']));
328
+        $topic_row['U_LAST_POST'] = append_sid($this->base->generate_lastpost_link($event['topic_row']['REPLIES'], $u_view_topic) . '#p' . $event['row']['topic_last_post_id']);
329
+        $topic_row['U_NEWEST_POST'] = $u_view_topic . '?view=unread#unread';
330
+
331
+        $event['topic_row'] = $topic_row;
332
+    }
333
+
334
+    /**
335
+     * Rewrite the canonical URL on viewforum.php
336
+     *
337
+     * @param	object	$event	The event object
338
+     * @return	null
339
+     * @access	public
340
+     */
341
+    public function viewforum_get_topic_data($event)
342
+    {
343
+        // assign to be used in pagination_generate_page_link
344
+        $this->forum_data = array(
345
+            'forum_id' => $event['forum_data']['forum_id'],
346
+            'forum_name' => $event['forum_data']['forum_name']
347
+        );
348
+
349
+        $start = $this->request->variable('start', 0);
350
+        $this->template->assign_vars(array(
351
+            'U_VIEW_FORUM'		=> append_sid($this->base->generate_forum_link($event['forum_data']['forum_id'], $event['forum_data']['forum_name'], $start)),
352
+            'U_CANONICAL'		=> $this->base->generate_forum_link($event['forum_data']['forum_id'], $event['forum_data']['forum_name'], $start, true),
353
+        ));
354
+    }
355
+
356
+    /**
357
+     * Rewrite the topic URL for the headline of the topic page and the link back to forum
358
+     *
359
+     * @param	object	$event	The event object
360
+     * @return	null
361
+     * @access	public
362
+     */
363
+    public function viewtopic_get_post_data($event)
364
+    {
365
+        $data = $event['topic_data'];
366
+        $this->template->assign_vars(array(
367
+            'U_VIEW_TOPIC'		=> append_sid($this->base->generate_topic_link($event['forum_id'] , $data['forum_name'], $event['topic_id'], $data['topic_title'], $event['start'])),
368
+            'U_VIEW_FORUM'		=> append_sid($this->base->generate_forum_link($event['forum_id'] , $data['forum_name'])),
369
+            'S_POLL_ACTION'		=> append_sid($this->base->generate_topic_link($event['forum_id'] , $data['forum_name'], $event['topic_id'], $data['topic_title'], $event['start'])),
370
+        ));
371
+    }
372
+
373
+    /**
374
+     * Assign topic data to global variables for pagination
375
+     *
376
+     * @param	object	$event	The event object
377
+     * @return	null
378
+     * @access	public
379
+     */
380
+    public function viewtopic_assign_template_vars_before($event)
381
+    {
382
+        // assign to be used in pagination_generate_page_link
383
+        $this->topic_data = array(
384
+            'forum_id' => $event['topic_data']['forum_id'],
385
+            'forum_name' => $event['topic_data']['forum_name'],
386
+            'topic_id' => $event['topic_data']['topic_id'],
387
+            'topic_title' => $event['topic_data']['topic_title']
388
+        );
389
+    }
390
+
391
+    public function viewtopic_before_f_read_check()
392
+    {
393
+        $this->in_viewtopic = true;
394
+    }
395
+
396
+    /**
397
+     * Rewrite the canonical URL on viewtopic.php
398
+     *
399
+     * @param	object	$event	The event object
400
+     * @return	null
401
+     * @access	public
402
+     */
403
+    public function viewtopic_modify_page_title($event)
404
+    {
405
+        $start = $this->request->variable('start', 0);
406
+        $data = $event['topic_data'];
407
+        $this->template->assign_vars(array(
408
+            'U_CANONICAL'		=> $this->base->generate_topic_link($data['forum_id'], $data['forum_name'], $data['topic_id'], $data['topic_title'], $start, true),
409
+        ));
410
+    }
411
+
412
+    /**
413
+     * Rewrite mini post img link
414
+     *
415
+     * @param	object	$event	The event object
416
+     * @return	null
417
+     * @access	public
418
+     */
419
+    public function viewtopic_modify_post_row($event)
420
+    {
421
+        $row = $event['post_row'];
422
+        $start = $this->request->variable('start', 0);
423
+        $data = $event['topic_data'];
424
+        $row['U_MINI_POST'] = append_sid($this->base->generate_topic_link($data['forum_id'], $data['forum_name'], $data['topic_id'], $data['topic_title'], $start) . '#p' . $event['row']['post_id']);
425
+        $event['post_row'] = $row;
426
+    }
427 427
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 			'core.display_forums_modify_forum_rows'					=> 'display_forums_modify_forum_rows',
74 74
 			'core.display_forums_modify_category_template_vars'		=> 'display_forums_modify_category_template_vars',
75 75
 			'core.generate_forum_nav'								=> 'generate_forum_nav',
76
-			'core.make_jumpbox_modify_tpl_ary'						=> 'make_jumpbox_modify_tpl_ary',				// Not in phpBB
76
+			'core.make_jumpbox_modify_tpl_ary'						=> 'make_jumpbox_modify_tpl_ary', // Not in phpBB
77 77
 			'core.memberlist_view_profile'							=> 'memberlist_view_profile',
78 78
 			'core.pagination_generate_page_link'					=> 'pagination_generate_page_link',
79 79
 			'core.search_modify_tpl_ary'							=> 'search_modify_tpl_ary',
@@ -96,9 +96,9 @@  discard block
 block discarded – undo
96 96
 	 */
97 97
 	public function append_sid($event)
98 98
 	{
99
-		if ($this->in_viewtopic && preg_match('#./../viewtopic.' . $this->php_ext  . '#', $event['url']))
99
+		if ($this->in_viewtopic && preg_match('#./../viewtopic.'.$this->php_ext.'#', $event['url']))
100 100
 		{
101
-			$url = '../viewtopic.' . $this->php_ext ;
101
+			$url = '../viewtopic.'.$this->php_ext;
102 102
 			$event['url'] = $url;
103 103
 		}
104 104
 		if (isset($event['params']['redirect']))
@@ -139,9 +139,9 @@  discard block
 block discarded – undo
139 139
 		$forum_rows = $event['forum_rows'];
140 140
 		if ($event['row']['forum_last_post_time'] == $forum_rows[$event['parent_id']]['forum_last_post_time'])
141 141
 		{
142
-			$forum_rows[$event['parent_id']]['forum_name_last_post'] =$event['row']['forum_name'];
143
-			$forum_rows[$event['parent_id']]['topic_id_last_post'] =$event['row']['topic_id'];
144
-			$forum_rows[$event['parent_id']]['topic_title_last_post'] =$event['row']['topic_title'];
142
+			$forum_rows[$event['parent_id']]['forum_name_last_post'] = $event['row']['forum_name'];
143
+			$forum_rows[$event['parent_id']]['topic_id_last_post'] = $event['row']['topic_id'];
144
+			$forum_rows[$event['parent_id']]['topic_title_last_post'] = $event['row']['topic_title'];
145 145
 			$event['forum_rows'] = $forum_rows;
146 146
 		}
147 147
 	}
@@ -170,14 +170,14 @@  discard block
 block discarded – undo
170 170
 
171 171
 		// Update the image source in forums
172 172
 		$img = $this->path_helper->update_web_root_path($forum_row['FORUM_IMAGE_SRC']);
173
-		$forum_row['FORUM_IMAGE'] = preg_replace('#img src=\"(.*)\" alt#', 'img src="' . $img . '" alt', $forum_row['FORUM_IMAGE']);
173
+		$forum_row['FORUM_IMAGE'] = preg_replace('#img src=\"(.*)\" alt#', 'img src="'.$img.'" alt', $forum_row['FORUM_IMAGE']);
174 174
 
175 175
 		// Rewrite links to topics, posts and forums
176 176
 		$replies = $this->base->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1;
177 177
 		$url = $this->base->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']);
178
-		$forum_row['U_LAST_POST'] = append_sid($this->base->generate_lastpost_link($replies, $url) . '#p' . $event['row']['forum_last_post_id']);
178
+		$forum_row['U_LAST_POST'] = append_sid($this->base->generate_lastpost_link($replies, $url).'#p'.$event['row']['forum_last_post_id']);
179 179
 		$forum_row['U_VIEWFORUM'] = append_sid($this->base->generate_forum_link($forum_row['FORUM_ID'], $forum_row['FORUM_NAME']));
180
-		$forum_row['U_NEWEST_POST'] = $url . '?view=unread#unread';
180
+		$forum_row['U_NEWEST_POST'] = $url.'?view=unread#unread';
181 181
 
182 182
 		$event['subforums_row'] = $subforums_row;
183 183
 		$event['forum_row'] = $forum_row;
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 
214 214
 		foreach ($navlinks_parents as $id => $data)
215 215
 		{
216
-			$navlinks_parents[$id]['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($data['FORUM_ID'] , $data['FORUM_NAME']));
216
+			$navlinks_parents[$id]['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($data['FORUM_ID'], $data['FORUM_NAME']));
217 217
 		}
218 218
 
219 219
 		$navlinks['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($forum_data['forum_id'], $forum_data['forum_name']));
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 		$row = $event['row'];
229 229
 		foreach ($tpl_ary as $id => $data)
230 230
 		{
231
-			$tpl_ary[$id]['LINK']	 = append_sid($this->base->generate_forum_link($row['forum_id'], $row['forum_name']));
231
+			$tpl_ary[$id]['LINK'] = append_sid($this->base->generate_forum_link($row['forum_id'], $row['forum_name']));
232 232
 		}
233 233
 
234 234
 		$event['tpl_ary'] = $tpl_ary;
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	 */
260 260
 	public function pagination_generate_page_link($event)
261 261
 	{
262
-		if(!is_string($event['base_url']))
262
+		if (!is_string($event['base_url']))
263 263
 		{
264 264
 			return;
265 265
 		}
@@ -295,10 +295,10 @@  discard block
 block discarded – undo
295 295
 		$u_view_topic = $this->base->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']);
296 296
 
297 297
 		$tpl_ary = $event['tpl_ary'];
298
-		$tpl_ary['U_LAST_POST'] = append_sid($this->base->generate_lastpost_link($replies, $u_view_topic) . '#p' . $event['row']['topic_last_post_id']);
298
+		$tpl_ary['U_LAST_POST'] = append_sid($this->base->generate_lastpost_link($replies, $u_view_topic).'#p'.$event['row']['topic_last_post_id']);
299 299
 		$tpl_ary['U_VIEW_TOPIC'] = append_sid($u_view_topic);
300 300
 		$tpl_ary['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($event['row']['forum_id'], $event['row']['forum_name']));
301
-		$tpl_ary['U_NEWEST_POST'] = $u_view_topic . '?view=unread#unread';
301
+		$tpl_ary['U_NEWEST_POST'] = $u_view_topic.'?view=unread#unread';
302 302
 
303 303
 		$event['tpl_ary'] = $tpl_ary;
304 304
 	}
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
 		$u_view_topic = $this->base->generate_topic_link($topic_row['FORUM_ID'], $topic_row['FORUM_NAME'], $topic_row['TOPIC_ID'], $topic_row['TOPIC_TITLE']);
326 326
 		$topic_row['U_VIEW_TOPIC'] = append_sid($u_view_topic);
327 327
 		$topic_row['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($topic_row['FORUM_ID'], $topic_row['FORUM_NAME']));
328
-		$topic_row['U_LAST_POST'] = append_sid($this->base->generate_lastpost_link($event['topic_row']['REPLIES'], $u_view_topic) . '#p' . $event['row']['topic_last_post_id']);
329
-		$topic_row['U_NEWEST_POST'] = $u_view_topic . '?view=unread#unread';
328
+		$topic_row['U_LAST_POST'] = append_sid($this->base->generate_lastpost_link($event['topic_row']['REPLIES'], $u_view_topic).'#p'.$event['row']['topic_last_post_id']);
329
+		$topic_row['U_NEWEST_POST'] = $u_view_topic.'?view=unread#unread';
330 330
 
331 331
 		$event['topic_row'] = $topic_row;
332 332
 	}
@@ -364,9 +364,9 @@  discard block
 block discarded – undo
364 364
 	{
365 365
 		$data = $event['topic_data'];
366 366
 		$this->template->assign_vars(array(
367
-			'U_VIEW_TOPIC'		=> append_sid($this->base->generate_topic_link($event['forum_id'] , $data['forum_name'], $event['topic_id'], $data['topic_title'], $event['start'])),
368
-			'U_VIEW_FORUM'		=> append_sid($this->base->generate_forum_link($event['forum_id'] , $data['forum_name'])),
369
-			'S_POLL_ACTION'		=> append_sid($this->base->generate_topic_link($event['forum_id'] , $data['forum_name'], $event['topic_id'], $data['topic_title'], $event['start'])),
367
+			'U_VIEW_TOPIC'		=> append_sid($this->base->generate_topic_link($event['forum_id'], $data['forum_name'], $event['topic_id'], $data['topic_title'], $event['start'])),
368
+			'U_VIEW_FORUM'		=> append_sid($this->base->generate_forum_link($event['forum_id'], $data['forum_name'])),
369
+			'S_POLL_ACTION'		=> append_sid($this->base->generate_topic_link($event['forum_id'], $data['forum_name'], $event['topic_id'], $data['topic_title'], $event['start'])),
370 370
 		));
371 371
 	}
372 372
 
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 		$row = $event['post_row'];
422 422
 		$start = $this->request->variable('start', 0);
423 423
 		$data = $event['topic_data'];
424
-		$row['U_MINI_POST'] = append_sid($this->base->generate_topic_link($data['forum_id'], $data['forum_name'], $data['topic_id'], $data['topic_title'], $start) . '#p' . $event['row']['post_id']);
424
+		$row['U_MINI_POST'] = append_sid($this->base->generate_topic_link($data['forum_id'], $data['forum_name'], $data['topic_id'], $data['topic_title'], $start).'#p'.$event['row']['post_id']);
425 425
 		$event['post_row'] = $row;
426 426
 	}
427 427
 }
Please login to merge, or discard this patch.