| @@ -16,376 +16,376 @@ | ||
| 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 = '../viewtopic.' . $this->php_ext ; | |
| 103 | - $event['url'] = $url; | |
| 104 | - } | |
| 105 | - if (isset($event['params']['redirect'])) | |
| 106 | -		{ | |
| 107 | - $params = $event['params']; | |
| 108 | -			$params['redirect'] = str_replace('..', '.', $event['params']['redirect']); | |
| 109 | - $event['params'] = $params; | |
| 110 | - } | |
| 111 | - } | |
| 112 | - | |
| 113 | - /** | |
| 114 | - * Get informations for the last post from Database | |
| 115 | - * | |
| 116 | - * @param object $event The event object | |
| 117 | - * @return null | |
| 118 | - * @access public | |
| 119 | - */ | |
| 120 | - public function display_forums_modify_sql($event) | |
| 121 | -	{ | |
| 122 | - $sql_array = $event['sql_ary']; | |
| 123 | - $sql_array['LEFT_JOIN'][] = array( | |
| 124 | - 'FROM' => array(TOPICS_TABLE => 't'), | |
| 125 | - 'ON' => "f.forum_last_post_id = t.topic_last_post_id" | |
| 126 | - ); | |
| 127 | - $sql_array['SELECT'] .= ', t.topic_title, t.topic_id, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted'; | |
| 128 | - $event['sql_ary'] = $sql_array; | |
| 129 | - } | |
| 130 | - | |
| 131 | - /** | |
| 132 | - * Store informations for the last post in forum_rows array | |
| 133 | - * | |
| 134 | - * @param object $event The event object | |
| 135 | - * @return null | |
| 136 | - * @access public | |
| 137 | - */ | |
| 138 | - public function display_forums_modify_forum_rows($event) | |
| 139 | -	{ | |
| 140 | - $forum_rows = $event['forum_rows']; | |
| 141 | - if ($event['row']['forum_last_post_time'] == $forum_rows[$event['parent_id']]['forum_last_post_time']) | |
| 142 | -		{ | |
| 143 | - $forum_rows[$event['parent_id']]['forum_name_last_post'] =$event['row']['forum_name']; | |
| 144 | - $forum_rows[$event['parent_id']]['topic_id_last_post'] =$event['row']['topic_id']; | |
| 145 | - $forum_rows[$event['parent_id']]['topic_title_last_post'] =$event['row']['topic_title']; | |
| 146 | - $event['forum_rows'] = $forum_rows; | |
| 147 | - } | |
| 148 | - } | |
| 149 | - | |
| 150 | - /** | |
| 151 | - * Rewrite links to forums and subforums in forum index | |
| 152 | - * also correct the path of the forum images if we are in a forum | |
| 153 | - * | |
| 154 | - * @param object $event The event object | |
| 155 | - * @return null | |
| 156 | - * @access public | |
| 157 | - */ | |
| 158 | - public function display_forums_modify_template_vars($event) | |
| 159 | -	{ | |
| 160 | - $subforums_row = $event['subforums_row']; | |
| 161 | - $forum_row = $event['forum_row']; | |
| 162 | - | |
| 163 | - // Rewrite URLs of sub forums | |
| 164 | - foreach ($subforums_row as $i => $subforum) | |
| 165 | -		{ | |
| 166 | - // A little bit a dirty way, but there is no better solution | |
| 167 | -			$query = str_replace('&', '&', parse_url($subforum['U_SUBFORUM'], PHP_URL_QUERY)); | |
| 168 | - parse_str($query, $id); | |
| 169 | - $subforums_row[$i]['U_SUBFORUM'] = append_sid($this->base->generate_forum_link($id['f'], $subforum['SUBFORUM_NAME'])); | |
| 170 | - } | |
| 171 | - | |
| 172 | - // Update the image source in forums | |
| 173 | - $img = $this->path_helper->update_web_root_path($forum_row['FORUM_IMAGE_SRC']); | |
| 174 | -		$forum_row['FORUM_IMAGE'] = preg_replace('#img src=\"(.*)\" alt#', 'img src="' . $img . '" alt', $forum_row['FORUM_IMAGE']); | |
| 175 | - | |
| 176 | - // Rewrite links to topics, posts and forums | |
| 177 | -		$replies = $this->base->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1; | |
| 178 | - $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']); | |
| 179 | - $forum_row['U_LAST_POST'] = append_sid($this->base->generate_lastpost_link($replies, $url) . '#p' . $event['row']['forum_last_post_id']); | |
| 180 | - $forum_row['U_VIEWFORUM'] = append_sid($this->base->generate_forum_link($forum_row['FORUM_ID'], $forum_row['FORUM_NAME'])); | |
| 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 pagination links | |
| 239 | - * | |
| 240 | - * @param object $event The event object | |
| 241 | - * @return null | |
| 242 | - * @access public | |
| 243 | - */ | |
| 244 | - public function pagination_generate_page_link($event) | |
| 245 | -	{ | |
| 246 | - // If we have a sort key we do not rewrite the URL | |
| 247 | -		$query = str_replace('&', '&', parse_url($event['base_url'], PHP_URL_QUERY)); | |
| 248 | - parse_str($query, $param); | |
| 249 | - if (isset($param['sd']) || isset($param['sk']) || isset($param['st'])) | |
| 250 | -		{ | |
| 251 | - return; | |
| 252 | - } | |
| 253 | - | |
| 254 | - $start = (($event['on_page'] - 1) * $event['per_page']); | |
| 255 | - if (!empty($this->topic_title)) | |
| 256 | -		{ | |
| 257 | - $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)); | |
| 258 | - } | |
| 259 | - else if (!empty($this->forum_title)) | |
| 260 | -		{ | |
| 261 | - $event['generate_page_link_override'] = append_sid($this->base->generate_forum_link($this->forum_id, $this->forum_title, $start)); | |
| 262 | - } | |
| 263 | - } | |
| 264 | - | |
| 265 | - /** | |
| 266 | - * Rewrite links in the search result | |
| 267 | - * | |
| 268 | - * @param object $event The event object | |
| 269 | - * @return null | |
| 270 | - * @access public | |
| 271 | - */ | |
| 272 | - public function search_modify_tpl_ary($event) | |
| 273 | -	{ | |
| 274 | -		$replies = $this->base->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1; | |
| 275 | - $u_view_topic = $this->base->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']); | |
| 276 | - | |
| 277 | - $tpl_ary = $event['tpl_ary']; | |
| 278 | - $tpl_ary['U_LAST_POST'] = append_sid($this->base->generate_lastpost_link($replies, $u_view_topic) . '#p' . $event['row']['topic_last_post_id']); | |
| 279 | - $tpl_ary['U_VIEW_TOPIC'] = append_sid($u_view_topic); | |
| 280 | - $tpl_ary['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($event['row']['forum_id'], $event['row']['forum_name'])); | |
| 281 | - | |
| 282 | - $event['tpl_ary'] = $tpl_ary; | |
| 283 | - } | |
| 284 | - | |
| 285 | - /** | |
| 286 | - * Rewrite links to topics in forum view | |
| 287 | - * | |
| 288 | - * @param object $event The event object | |
| 289 | - * @return null | |
| 290 | - * @access public | |
| 291 | - */ | |
| 292 | - public function viewforum_modify_topicrow($event) | |
| 293 | -	{ | |
| 294 | - $topic_row = $event['topic_row']; | |
| 295 | - $this->forum_title = $topic_row['FORUM_NAME']; | |
| 296 | - $this->forum_id = $topic_row['FORUM_ID']; | |
| 297 | - $this->topic_title = $topic_row['TOPIC_TITLE']; | |
| 298 | - $this->topic_id = $topic_row['TOPIC_ID']; | |
| 299 | - | |
| 300 | - $u_view_topic = $this->base->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title); | |
| 301 | - $topic_row['U_VIEW_TOPIC'] = append_sid($u_view_topic); | |
| 302 | - $topic_row['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($this->forum_id, $this->forum_title)); | |
| 303 | - $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']); | |
| 304 | - | |
| 305 | - $event['topic_row'] = $topic_row; | |
| 306 | - } | |
| 307 | - | |
| 308 | - /** | |
| 309 | - * Rewrite the canonical URL on viewforum.php | |
| 310 | - * | |
| 311 | - * @param object $event The event object | |
| 312 | - * @return null | |
| 313 | - * @access public | |
| 314 | - */ | |
| 315 | - public function viewforum_get_topic_data($event) | |
| 316 | -	{ | |
| 317 | -		$start = $this->request->variable('start', 0); | |
| 318 | - $this->template->assign_vars(array( | |
| 319 | - 'U_VIEW_FORUM' => append_sid($this->base->generate_forum_link($event['forum_data']['forum_id'], $event['forum_data']['forum_name'], $start)), | |
| 320 | - 'U_CANONICAL' => $this->base->generate_forum_link($event['forum_data']['forum_id'], $event['forum_data']['forum_name'], $start, true), | |
| 321 | - )); | |
| 322 | - } | |
| 323 | - | |
| 324 | - /** | |
| 325 | - * Rewrite the topic URL for the headline of the topic page and the link back to forum | |
| 326 | - * | |
| 327 | - * @param object $event The event object | |
| 328 | - * @return null | |
| 329 | - * @access public | |
| 330 | - */ | |
| 331 | - public function viewtopic_get_post_data($event) | |
| 332 | -	{ | |
| 333 | - $data = $event['topic_data']; | |
| 334 | - $this->template->assign_vars(array( | |
| 335 | - 'U_VIEW_TOPIC' => append_sid($this->base->generate_topic_link($event['forum_id'] , $data['forum_name'], $event['topic_id'], $data['topic_title'], $event['start'])), | |
| 336 | - 'U_VIEW_FORUM' => append_sid($this->base->generate_forum_link($event['forum_id'] , $data['forum_name'])), | |
| 337 | - )); | |
| 338 | - } | |
| 339 | - | |
| 340 | - /** | |
| 341 | - * Assign topic data to global variables for pagination | |
| 342 | - * | |
| 343 | - * @param object $event The event object | |
| 344 | - * @return null | |
| 345 | - * @access public | |
| 346 | - */ | |
| 347 | - public function viewtopic_assign_template_vars_before($event) | |
| 348 | -	{ | |
| 349 | - $this->forum_title = $event['topic_data']['forum_name']; | |
| 350 | - $this->forum_id = $event['topic_data']['forum_id']; | |
| 351 | - $this->topic_title = $event['topic_data']['topic_title']; | |
| 352 | - $this->topic_id = $event['topic_data']['topic_id']; | |
| 353 | - } | |
| 354 | - | |
| 355 | - public function viewtopic_before_f_read_check() | |
| 356 | -	{ | |
| 357 | - $this->in_viewtopic = true; | |
| 358 | - } | |
| 359 | - | |
| 360 | - /** | |
| 361 | - * Rewrite the canonical URL on viewtopic.php | |
| 362 | - * | |
| 363 | - * @param object $event The event object | |
| 364 | - * @return null | |
| 365 | - * @access public | |
| 366 | - */ | |
| 367 | - public function viewtopic_modify_page_title($event) | |
| 368 | -	{ | |
| 369 | -		$start = $this->request->variable('start', 0); | |
| 370 | - $data = $event['topic_data']; | |
| 371 | - $this->template->assign_vars(array( | |
| 372 | - 'U_CANONICAL' => $this->base->generate_topic_link($data['forum_id'], $data['forum_name'], $data['topic_id'], $data['topic_title'], $start, true), | |
| 373 | - )); | |
| 374 | - } | |
| 375 | - | |
| 376 | - /** | |
| 377 | - * Rewrite mini post img link | |
| 378 | - * | |
| 379 | - * @param object $event The event object | |
| 380 | - * @return null | |
| 381 | - * @access public | |
| 382 | - */ | |
| 383 | - public function viewtopic_modify_post_row($event) | |
| 384 | -	{ | |
| 385 | - $row = $event['post_row']; | |
| 386 | -		$start = $this->request->variable('start', 0); | |
| 387 | - $data = $event['topic_data']; | |
| 388 | - $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']); | |
| 389 | - $event['post_row'] = $row; | |
| 390 | - } | |
| 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 = '../viewtopic.' . $this->php_ext ; | |
| 103 | + $event['url'] = $url; | |
| 104 | + } | |
| 105 | + if (isset($event['params']['redirect'])) | |
| 106 | +        { | |
| 107 | + $params = $event['params']; | |
| 108 | +            $params['redirect'] = str_replace('..', '.', $event['params']['redirect']); | |
| 109 | + $event['params'] = $params; | |
| 110 | + } | |
| 111 | + } | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * Get informations for the last post from Database | |
| 115 | + * | |
| 116 | + * @param object $event The event object | |
| 117 | + * @return null | |
| 118 | + * @access public | |
| 119 | + */ | |
| 120 | + public function display_forums_modify_sql($event) | |
| 121 | +    { | |
| 122 | + $sql_array = $event['sql_ary']; | |
| 123 | + $sql_array['LEFT_JOIN'][] = array( | |
| 124 | + 'FROM' => array(TOPICS_TABLE => 't'), | |
| 125 | + 'ON' => "f.forum_last_post_id = t.topic_last_post_id" | |
| 126 | + ); | |
| 127 | + $sql_array['SELECT'] .= ', t.topic_title, t.topic_id, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted'; | |
| 128 | + $event['sql_ary'] = $sql_array; | |
| 129 | + } | |
| 130 | + | |
| 131 | + /** | |
| 132 | + * Store informations for the last post in forum_rows array | |
| 133 | + * | |
| 134 | + * @param object $event The event object | |
| 135 | + * @return null | |
| 136 | + * @access public | |
| 137 | + */ | |
| 138 | + public function display_forums_modify_forum_rows($event) | |
| 139 | +    { | |
| 140 | + $forum_rows = $event['forum_rows']; | |
| 141 | + if ($event['row']['forum_last_post_time'] == $forum_rows[$event['parent_id']]['forum_last_post_time']) | |
| 142 | +        { | |
| 143 | + $forum_rows[$event['parent_id']]['forum_name_last_post'] =$event['row']['forum_name']; | |
| 144 | + $forum_rows[$event['parent_id']]['topic_id_last_post'] =$event['row']['topic_id']; | |
| 145 | + $forum_rows[$event['parent_id']]['topic_title_last_post'] =$event['row']['topic_title']; | |
| 146 | + $event['forum_rows'] = $forum_rows; | |
| 147 | + } | |
| 148 | + } | |
| 149 | + | |
| 150 | + /** | |
| 151 | + * Rewrite links to forums and subforums in forum index | |
| 152 | + * also correct the path of the forum images if we are in a forum | |
| 153 | + * | |
| 154 | + * @param object $event The event object | |
| 155 | + * @return null | |
| 156 | + * @access public | |
| 157 | + */ | |
| 158 | + public function display_forums_modify_template_vars($event) | |
| 159 | +    { | |
| 160 | + $subforums_row = $event['subforums_row']; | |
| 161 | + $forum_row = $event['forum_row']; | |
| 162 | + | |
| 163 | + // Rewrite URLs of sub forums | |
| 164 | + foreach ($subforums_row as $i => $subforum) | |
| 165 | +        { | |
| 166 | + // A little bit a dirty way, but there is no better solution | |
| 167 | +            $query = str_replace('&', '&', parse_url($subforum['U_SUBFORUM'], PHP_URL_QUERY)); | |
| 168 | + parse_str($query, $id); | |
| 169 | + $subforums_row[$i]['U_SUBFORUM'] = append_sid($this->base->generate_forum_link($id['f'], $subforum['SUBFORUM_NAME'])); | |
| 170 | + } | |
| 171 | + | |
| 172 | + // Update the image source in forums | |
| 173 | + $img = $this->path_helper->update_web_root_path($forum_row['FORUM_IMAGE_SRC']); | |
| 174 | +        $forum_row['FORUM_IMAGE'] = preg_replace('#img src=\"(.*)\" alt#', 'img src="' . $img . '" alt', $forum_row['FORUM_IMAGE']); | |
| 175 | + | |
| 176 | + // Rewrite links to topics, posts and forums | |
| 177 | +        $replies = $this->base->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1; | |
| 178 | + $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']); | |
| 179 | + $forum_row['U_LAST_POST'] = append_sid($this->base->generate_lastpost_link($replies, $url) . '#p' . $event['row']['forum_last_post_id']); | |
| 180 | + $forum_row['U_VIEWFORUM'] = append_sid($this->base->generate_forum_link($forum_row['FORUM_ID'], $forum_row['FORUM_NAME'])); | |
| 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 pagination links | |
| 239 | + * | |
| 240 | + * @param object $event The event object | |
| 241 | + * @return null | |
| 242 | + * @access public | |
| 243 | + */ | |
| 244 | + public function pagination_generate_page_link($event) | |
| 245 | +    { | |
| 246 | + // If we have a sort key we do not rewrite the URL | |
| 247 | +        $query = str_replace('&', '&', parse_url($event['base_url'], PHP_URL_QUERY)); | |
| 248 | + parse_str($query, $param); | |
| 249 | + if (isset($param['sd']) || isset($param['sk']) || isset($param['st'])) | |
| 250 | +        { | |
| 251 | + return; | |
| 252 | + } | |
| 253 | + | |
| 254 | + $start = (($event['on_page'] - 1) * $event['per_page']); | |
| 255 | + if (!empty($this->topic_title)) | |
| 256 | +        { | |
| 257 | + $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)); | |
| 258 | + } | |
| 259 | + else if (!empty($this->forum_title)) | |
| 260 | +        { | |
| 261 | + $event['generate_page_link_override'] = append_sid($this->base->generate_forum_link($this->forum_id, $this->forum_title, $start)); | |
| 262 | + } | |
| 263 | + } | |
| 264 | + | |
| 265 | + /** | |
| 266 | + * Rewrite links in the search result | |
| 267 | + * | |
| 268 | + * @param object $event The event object | |
| 269 | + * @return null | |
| 270 | + * @access public | |
| 271 | + */ | |
| 272 | + public function search_modify_tpl_ary($event) | |
| 273 | +    { | |
| 274 | +        $replies = $this->base->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1; | |
| 275 | + $u_view_topic = $this->base->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']); | |
| 276 | + | |
| 277 | + $tpl_ary = $event['tpl_ary']; | |
| 278 | + $tpl_ary['U_LAST_POST'] = append_sid($this->base->generate_lastpost_link($replies, $u_view_topic) . '#p' . $event['row']['topic_last_post_id']); | |
| 279 | + $tpl_ary['U_VIEW_TOPIC'] = append_sid($u_view_topic); | |
| 280 | + $tpl_ary['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($event['row']['forum_id'], $event['row']['forum_name'])); | |
| 281 | + | |
| 282 | + $event['tpl_ary'] = $tpl_ary; | |
| 283 | + } | |
| 284 | + | |
| 285 | + /** | |
| 286 | + * Rewrite links to topics in forum view | |
| 287 | + * | |
| 288 | + * @param object $event The event object | |
| 289 | + * @return null | |
| 290 | + * @access public | |
| 291 | + */ | |
| 292 | + public function viewforum_modify_topicrow($event) | |
| 293 | +    { | |
| 294 | + $topic_row = $event['topic_row']; | |
| 295 | + $this->forum_title = $topic_row['FORUM_NAME']; | |
| 296 | + $this->forum_id = $topic_row['FORUM_ID']; | |
| 297 | + $this->topic_title = $topic_row['TOPIC_TITLE']; | |
| 298 | + $this->topic_id = $topic_row['TOPIC_ID']; | |
| 299 | + | |
| 300 | + $u_view_topic = $this->base->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title); | |
| 301 | + $topic_row['U_VIEW_TOPIC'] = append_sid($u_view_topic); | |
| 302 | + $topic_row['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($this->forum_id, $this->forum_title)); | |
| 303 | + $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']); | |
| 304 | + | |
| 305 | + $event['topic_row'] = $topic_row; | |
| 306 | + } | |
| 307 | + | |
| 308 | + /** | |
| 309 | + * Rewrite the canonical URL on viewforum.php | |
| 310 | + * | |
| 311 | + * @param object $event The event object | |
| 312 | + * @return null | |
| 313 | + * @access public | |
| 314 | + */ | |
| 315 | + public function viewforum_get_topic_data($event) | |
| 316 | +    { | |
| 317 | +        $start = $this->request->variable('start', 0); | |
| 318 | + $this->template->assign_vars(array( | |
| 319 | + 'U_VIEW_FORUM' => append_sid($this->base->generate_forum_link($event['forum_data']['forum_id'], $event['forum_data']['forum_name'], $start)), | |
| 320 | + 'U_CANONICAL' => $this->base->generate_forum_link($event['forum_data']['forum_id'], $event['forum_data']['forum_name'], $start, true), | |
| 321 | + )); | |
| 322 | + } | |
| 323 | + | |
| 324 | + /** | |
| 325 | + * Rewrite the topic URL for the headline of the topic page and the link back to forum | |
| 326 | + * | |
| 327 | + * @param object $event The event object | |
| 328 | + * @return null | |
| 329 | + * @access public | |
| 330 | + */ | |
| 331 | + public function viewtopic_get_post_data($event) | |
| 332 | +    { | |
| 333 | + $data = $event['topic_data']; | |
| 334 | + $this->template->assign_vars(array( | |
| 335 | + 'U_VIEW_TOPIC' => append_sid($this->base->generate_topic_link($event['forum_id'] , $data['forum_name'], $event['topic_id'], $data['topic_title'], $event['start'])), | |
| 336 | + 'U_VIEW_FORUM' => append_sid($this->base->generate_forum_link($event['forum_id'] , $data['forum_name'])), | |
| 337 | + )); | |
| 338 | + } | |
| 339 | + | |
| 340 | + /** | |
| 341 | + * Assign topic data to global variables for pagination | |
| 342 | + * | |
| 343 | + * @param object $event The event object | |
| 344 | + * @return null | |
| 345 | + * @access public | |
| 346 | + */ | |
| 347 | + public function viewtopic_assign_template_vars_before($event) | |
| 348 | +    { | |
| 349 | + $this->forum_title = $event['topic_data']['forum_name']; | |
| 350 | + $this->forum_id = $event['topic_data']['forum_id']; | |
| 351 | + $this->topic_title = $event['topic_data']['topic_title']; | |
| 352 | + $this->topic_id = $event['topic_data']['topic_id']; | |
| 353 | + } | |
| 354 | + | |
| 355 | + public function viewtopic_before_f_read_check() | |
| 356 | +    { | |
| 357 | + $this->in_viewtopic = true; | |
| 358 | + } | |
| 359 | + | |
| 360 | + /** | |
| 361 | + * Rewrite the canonical URL on viewtopic.php | |
| 362 | + * | |
| 363 | + * @param object $event The event object | |
| 364 | + * @return null | |
| 365 | + * @access public | |
| 366 | + */ | |
| 367 | + public function viewtopic_modify_page_title($event) | |
| 368 | +    { | |
| 369 | +        $start = $this->request->variable('start', 0); | |
| 370 | + $data = $event['topic_data']; | |
| 371 | + $this->template->assign_vars(array( | |
| 372 | + 'U_CANONICAL' => $this->base->generate_topic_link($data['forum_id'], $data['forum_name'], $data['topic_id'], $data['topic_title'], $start, true), | |
| 373 | + )); | |
| 374 | + } | |
| 375 | + | |
| 376 | + /** | |
| 377 | + * Rewrite mini post img link | |
| 378 | + * | |
| 379 | + * @param object $event The event object | |
| 380 | + * @return null | |
| 381 | + * @access public | |
| 382 | + */ | |
| 383 | + public function viewtopic_modify_post_row($event) | |
| 384 | +    { | |
| 385 | + $row = $event['post_row']; | |
| 386 | +        $start = $this->request->variable('start', 0); | |
| 387 | + $data = $event['topic_data']; | |
| 388 | + $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']); | |
| 389 | + $event['post_row'] = $row; | |
| 390 | + } | |
| 391 | 391 | } | 
| 392 | 392 | \ No newline at end of file |