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