extensions::topfive_modify_tpl_ary()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
/**
3
 *
4
 * @package phpBB Extension - tas2580 SEO URLs
5
 * @copyright (c) 2016 tas2580 (https://tas2580.net)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace tas2580\seourls\event;
11
12
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
13
14
/**
15
 * Event listener
16
 */
17
class extensions implements EventSubscriberInterface
18
{
19
	/** @var \tas2580\seourls\event\base */
20
	protected $base;
21
22
	/**
23
	 * Constructor
24
	 *
25
	 * @param \tas2580\seourls\event\base		$base
26
	 * @access public
27
	 */
28
	public function __construct(\tas2580\seourls\event\base $base)
29
	{
30
		$this->base = $base;
31
	}
32
33
	/**
34
	 * Assign functions defined in this class to event listeners in the core
35
	 *
36
	 * @return array
37
	 * @static
38
	 * @access public
39
	 */
40
	public static function getSubscribedEvents()
41
	{
42
		return array(
43
			'rmcgirr83.topfive.sql_pull_topics_data'	=> 'topfive_sql_pull_topics_data',
44
			'rmcgirr83.topfive.modify_tpl_ary'			=> 'topfive_modify_tpl_ary',
45
			'tas2580.sitemap.modify_before_output'		=> 'sitemap_modify_before_output',
46
			'vse.similartopics.modify_topicrow'			=> 'similartopics_modify_topicrow',
47
			'paybas.recenttopics.modify_tpl_ary'		=> 'recenttopics_modify_tpl_ary'
48
		);
49
	}
50
51
	public function recenttopics_modify_tpl_ary($event)
52
	{
53
		$tpl_ary = $event['tpl_ary'];
54
		$u_view_topic = $this->base->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']);
55
		$tpl_ary['U_VIEW_TOPIC'] = append_sid($u_view_topic);
56
		$tpl_ary['U_LAST_POST'] = append_sid($this->base->generate_lastpost_link($tpl_ary['REPLIES'], $u_view_topic) . '#p' . $event['row']['topic_last_post_id']);
57
		$tpl_ary['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($event['row']['forum_id'], $event['row']['forum_name']));
58
		$tpl_ary['U_NEWEST_POST'] = $u_view_topic . '?view=unread#unread';
59
60
		$event['tpl_ary'] = $tpl_ary;
61
	}
62
63
	/**
64
	 * Rewrite URLs in tas2580 Sitemap Extension
65
	 *
66
	 * @param	object	$event	The event object
67
	 * @return	null
68
	 * @access	public
69
	 */
70
	public function sitemap_modify_before_output($event)
71
	{
72
		// Nothing to rewrite in the sitemap index
73
		if ($event['type'] == 'sitemapindex')
74
		{
75
			return;
76
		}
77
78
		$url_data =$event['url_data'] ;
79
80
		foreach ($url_data as $id => $data)
81
		{
82
			$row = $data['row'];
83
			if (isset($row['topic_id']))
84
			{
85
				$url_data[$id]['url'] = $this->base->generate_topic_link($row['forum_id'], $row['forum_name'], $row['topic_id'], $row['topic_title'],  $data['start'], true);
86
			}
87
			else if (isset($row['forum_id']))
88
			{
89
				$url_data[$id]['url'] = $this->base->generate_forum_link($row['forum_id'], $row['forum_name'], $data['start'], true);
90
			}
91
		}
92
93
		$event['url_data'] = $url_data;
94
	}
95
96
	/**
97
	 * Rewrite URLs in Similar Topics Extension
98
	 *
99
	 * @param	object	$event	The event object
100
	 * @return	null
101
	 * @access	public
102
	 */
103
	public function similartopics_modify_topicrow($event)
104
	{
105
		$this->forum_title = $event['row']['forum_name'];
106
		$this->forum_id = $event['row']['forum_id'];
107
		$this->topic_title = $event['row']['topic_title'];
108
		$this->topic_id = $event['row']['topic_id'];
109
110
		$topic_row = $event['topic_row'];
111
		$u_view_topic= $this->base->generate_topic_link($this->forum_id, $this->forum_title, $this->topic_id, $this->topic_title);
112
		$topic_row['U_VIEW_TOPIC'] = append_sid($u_view_topic);
113
		$topic_row['U_VIEW_FORUM'] = append_sid($this->base->generate_forum_link($this->forum_id, $this->forum_title));
114
		$topic_row['U_LAST_POST'] = append_sid($this->base->generate_lastpost_link($topic_row['TOPIC_REPLIES'], $u_view_topic) . '#p' . $event['row']['topic_last_post_id']);
115
		$event['topic_row'] = $topic_row;
116
	}
117
118
	/**
119
	 * Rewrite URLs in Top 5 Extension
120
	 *
121
	 * @param	object	$event	The event object
122
	 * @return	null
123
	 * @access	public
124
	 */
125
	public function topfive_sql_pull_topics_data($event)
126
	{
127
		$sql_array = $event['sql_array'];
128
		$sql_array['SELECT'] = array_merge($sql_array, array('SELECT' => 'f.forum_name'));
129
		$sql_array['LEFT_JOIN'] = array_merge($sql_array['LEFT_JOIN'], array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id'));
130
		$event['sql_array'] = $sql_array;
131
	}
132
133
	/**
134
	 * Rewrite URLs in Top 5 Extension
135
	 *
136
	 * @param	object	$event	The event object
137
	 * @return	null
138
	 * @access	public
139
	 */
140
	public function topfive_modify_tpl_ary($event)
141
	{
142
		$tpl_ary = $event['tpl_ary'];
143
		$replies = $this->base->get_count('topic_posts', $event['row'], $event['row']['forum_id']) - 1;
144
		$u_view_topic = $this->base->generate_topic_link($event['row']['forum_id'], $event['row']['forum_name'], $event['row']['topic_id'], $event['row']['topic_title']);
145
		$tpl_ary['U_TOPIC'] = append_sid($this->base->generate_lastpost_link($replies, $u_view_topic) . '#p' . $event['row']['topic_last_post_id']);
146
		$event['tpl_ary'] = $tpl_ary;
147
	}
148
}
149