Skip to content

Commit 0d6cbe0

Browse files
author
Tomasz Narloch
committed
Code style, remove useless code, feature: first Itemid for tags view, second Itemid for default tag view
1 parent 2cf1a9f commit 0d6cbe0

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

components/com_tags/helpers/route.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public static function getTagRoute($id)
9696
}
9797
else
9898
{
99-
$needles = array('tags' => array(0));
99+
$needles = array('tags' => array(1, 0));
100+
100101
if ($item = self::_findItem($needles))
101102
{
102103
$link .= '&Itemid=' . $item;
@@ -107,6 +108,29 @@ public static function getTagRoute($id)
107108
return $link;
108109
}
109110

111+
/**
112+
* Tries to load the router for the tags view.
113+
*
114+
* @return string URL link to pass to JRoute
115+
*
116+
* @since 3.7
117+
*/
118+
public static function getTagsRoute()
119+
{
120+
$needles = array(
121+
'tags' => array(0)
122+
);
123+
124+
$link = 'index.php?option=com_tags&view=tags';
125+
126+
if ($item = self::_findItem($needles))
127+
{
128+
$link .= '&Itemid=' . $item;
129+
}
130+
131+
return $link;
132+
}
133+
110134
/**
111135
* Find Item static function
112136
*

components/com_tags/router.php

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
defined('_JEXEC') or die;
1111

12+
use Joomla\Utilities\ArrayHelper;
13+
1214
/**
1315
* Routing class from com_tags
1416
*
@@ -47,7 +49,7 @@ public function build(&$query)
4749

4850
if (is_array($mId))
4951
{
50-
JArrayHelper::toInteger($mId);
52+
ArrayHelper::toInteger($mId);
5153
}
5254

5355
$view = '';
@@ -101,8 +103,8 @@ public function build(&$query)
101103
for ($i = 0; $i < $total; $i++)
102104
{
103105
$segments[$i] = str_replace(':', '-', $segments[$i]);
106+
$position = strpos($segments[$i], '-');
104107

105-
$position = strpos($segments[$i], '-');
106108
if ($position)
107109
{
108110
// Remove id from segment
@@ -160,15 +162,14 @@ public function parse(&$segments)
160162
*
161163
* @return string The segment with founded id
162164
*
163-
* @since 3.6.1
165+
* @since 3.7
164166
*/
165167
protected function fixSegment($segment)
166168
{
167169
$db = JFactory::getDbo();
168170

169-
// Find or confirm tag id
170-
$parts = explode(':', $segment, 2);
171-
$alias = implode('-', $parts);
171+
// Try to find tag id
172+
$alias = str_replace(':', '-', $segment);
172173

173174
$query = $db->getQuery(true)
174175
->select('id')
@@ -177,23 +178,6 @@ protected function fixSegment($segment)
177178

178179
$id = $db->setQuery($query)->loadResult();
179180

180-
if (!$id && ctype_digit($parts[0]))
181-
{
182-
// Alias contains id prefix - old way B/C
183-
$alias = $parts[1];
184-
185-
$query->clear('where')
186-
->where($db->quoteName('alias') . " = " . $db->quote($alias));
187-
188-
$id = $db->setQuery($query)->loadResult();
189-
190-
if ($parts[0] !== $id)
191-
{
192-
// Id with incorrect alias
193-
return $segment;
194-
}
195-
}
196-
197181
if ($id)
198182
{
199183
$segment = "$id:$alias";

0 commit comments

Comments
 (0)