Skip to content

Commit

Permalink
Add language to generate URL for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Narloch committed Apr 25, 2017
1 parent 77d7ae5 commit 65bee28
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 36 deletions.
34 changes: 19 additions & 15 deletions components/com_tags/helpers/route.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,39 +70,43 @@ public static function getItemRoute($contentItemId, $contentItemAlias, $contentC
/**
* Tries to load the router for the component and calls it. Otherwise calls getRoute.
*
* @param integer $id The ID of the tag
* @param integer $id The ID of the tag.
* @param string $language The language code of the tag.
*
* @return string URL link to pass to JRoute
*
* @since 3.1
*/
public static function getTagRoute($id)
public static function getTagRoute($id, $language = null)
{
$needles = array(
'tag' => array((int) $id)
'tag' => array((int) $id),
);

if ($id < 1)
// Create the link
$link = 'index.php?option=com_tags&view=tag&id=' . $id;

if ($language && $language != "*" && JLanguageMultilang::isEnabled())
{
$link .= '&lang=' . $language;
$needles['language'] = $language;
}

if ($item = self::_findItem($needles))
{
$link = '';
$link .= '&Itemid=' . $item;
}
else
{
$link = 'index.php?option=com_tags&view=tag&id=' . $id;
unset($needles['tag']);

// Try to find a menu item for list of tags.
$needles['tags'] = array(1, 0);

if ($item = self::_findItem($needles))
{
$link .= '&Itemid=' . $item;
}
else
{
$needles = array('tags' => array(1, 0));

if ($item = self::_findItem($needles))
{
$link .= '&Itemid=' . $item;
}
}
}

return $link;
Expand Down
17 changes: 14 additions & 3 deletions components/com_tags/views/tag/view.feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,20 @@ class TagsViewTag extends JViewLegacy
*/
public function display($tpl = null)
{
$app = JFactory::getApplication();
$document = JFactory::getDocument();
$document->link = JRoute::_(TagsHelperRoute::getTagRoute($app->input->getInt('id')));
$app = JFactory::getApplication();
$document = JFactory::getDocument();

// Get the tag data.
$item = $this->get('Item');

$slug = function ($tag)
{
return $tag->id . ':' . $tag->alias;
};

$id = implode(',', array_map($slug, $item));

$document->link = JRoute::_(TagsHelperRoute::getTagRoute($id, $item[0]->language));

$app->input->set('limit', $app->get('feed_limit'));
$siteEmail = $app->get('mailfrom');
Expand Down
2 changes: 1 addition & 1 deletion components/com_tags/views/tags/tmpl/default_items.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<?php if ((!empty($item->access)) && in_array($item->access, $this->user->getAuthorisedViewLevels())) : ?>
<li class="cat-list-row<?php echo $i % 2; ?>" >
<h3>
<a href="<?php echo JRoute::_(TagsHelperRoute::getTagRoute($item->id . '-' . $item->alias)); ?>">
<a href="<?php echo JRoute::_(TagsHelperRoute::getTagRoute($item->id . ':' . $item->alias, $item->language)); ?>">
<?php echo $this->escape($item->title); ?>
</a>
</h3>
Expand Down
2 changes: 1 addition & 1 deletion layouts/joomla/content/tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<?php $tagParams = new Registry($tag->params); ?>
<?php $link_class = $tagParams->get('tag_link_class', 'label label-info'); ?>
<li class="tag-<?php echo $tag->tag_id; ?> tag-list<?php echo $i; ?>" itemprop="keywords">
<a href="<?php echo JRoute::_(TagsHelperRoute::getTagRoute($tag->tag_id . '-' . $tag->alias)); ?>" class="<?php echo $link_class; ?>">
<a href="<?php echo JRoute::_(TagsHelperRoute::getTagRoute($tag->tag_id . ':' . $tag->alias, $tag->language)); ?>" class="<?php echo $link_class; ?>">
<?php echo $this->escape($tag->title); ?>
</a>
</li>
Expand Down
18 changes: 6 additions & 12 deletions modules/mod_tags_popular/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,14 @@ public static function getList(&$params)
$nullDate = $db->quote($db->getNullDate());

$query = $db->getQuery(true)
->select(
array(
'MAX(' . $db->quoteName('tag_id') . ') AS tag_id',
' COUNT(*) AS count', 'MAX(t.title) AS title',
'MAX(' . $db->quoteName('t.access') . ') AS access',
'MAX(' . $db->quoteName('t.alias') . ') AS alias',
'MAX(' . $db->quoteName('t.params') . ') AS params',
)
)
->group($db->quoteName(array('tag_id', 'title', 'access', 'alias')))
->select($db->quoteName(array('m.tag_id', 't.title', 't.access', 't.alias', 't.language')))
->select('COUNT(*) AS ' . $db->quoteName('count'))
->group($db->quoteName(array('m.tag_id', 't.title', 't.access', 't.alias', 't.language')))
->from($db->quoteName('#__contentitem_tag_map', 'm'))
->where($db->quoteName('t.access') . ' IN (' . $groups . ')');

// Only return published tags
$query->where($db->quoteName('t.published') . ' = 1 ');
$query->where($db->quoteName('t.published') . ' = 1');

// Optionally filter on language
$language = JComponentHelper::getParams('com_tags')->get('tag_list_language_filter', 'all');
Expand All @@ -73,7 +66,7 @@ public static function getList(&$params)
$query->where($db->quoteName('tag_date') . ' > ' . $query->dateAdd($nowDate, '-1', strtoupper($timeframe)));
}

$query->join('INNER', $db->quoteName('#__tags', 't') . ' ON ' . $db->quoteName('tag_id') . ' = t.id')
$query->join('INNER', $db->quoteName('#__tags', 't') . ' ON ' . $db->quoteName('m.tag_id') . ' = t.id')
->join('INNER', $db->qn('#__ucm_content', 'c') . ' ON ' . $db->qn('m.core_content_id') . ' = ' . $db->qn('c.core_content_id'));

$query->where($db->quoteName('m.type_alias') . ' = ' . $db->quoteName('c.core_type_alias'));
Expand Down Expand Up @@ -107,6 +100,7 @@ public static function getList(&$params)
'a.title',
'a.access',
'a.alias',
'a.language',
)
)
->from('(' . (string) $query . ') AS a')
Expand Down
2 changes: 1 addition & 1 deletion modules/mod_tags_popular/tmpl/cloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
endif;
?>
<span class="tag">
<a class="tag-name" style="font-size: <?php echo $fontsize . 'em'; ?>" href="<?php echo JRoute::_(TagsHelperRoute::getTagRoute($item->tag_id . '-' . $item->alias)); ?>">
<a class="tag-name" style="font-size: <?php echo $fontsize . 'em'; ?>" href="<?php echo JRoute::_(TagsHelperRoute::getTagRoute($item->tag_id . ':' . $item->alias, $item->language)); ?>">
<?php echo htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8'); ?></a>
<?php if ($display_count) : ?>
<span class="tag-count badge badge-info"><?php echo $item->count; ?></span>
Expand Down
2 changes: 1 addition & 1 deletion modules/mod_tags_popular/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ul>
<?php foreach ($list as $item) : ?>
<li>
<a href="<?php echo JRoute::_(TagsHelperRoute::getTagRoute($item->tag_id . '-' . $item->alias)); ?>">
<a href="<?php echo JRoute::_(TagsHelperRoute::getTagRoute($item->tag_id . ':' . $item->alias, $item->language)); ?>">
<?php echo htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8'); ?></a>
<?php if ($display_count) : ?>
<span class="tag-count badge badge-info"><?php echo $item->count; ?></span>
Expand Down
2 changes: 1 addition & 1 deletion plugins/finder/tags/tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ protected function index(FinderIndexerResult $item, $format = 'html')

// Build the necessary route and path information.
$item->url = $this->getUrl($item->id, $this->extension, $this->layout);
$item->route = TagsHelperRoute::getTagRoute($item->slug);
$item->route = TagsHelperRoute::getTagRoute($item->slug, $item->language);
$item->path = FinderIndexerHelper::getContentPath($item->route);

// Get the menu title if it exists.
Expand Down
2 changes: 1 addition & 1 deletion plugins/search/tags/tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = nu

foreach ($rows as $key => $row)
{
$rows[$key]->href = TagsHelperRoute::getTagRoute($row->id);
$rows[$key]->href = TagsHelperRoute::getTagRoute($row->id . ':' . $row->alias, $row->language);
$rows[$key]->text = ($row->description != '' ? $row->description : $row->title);
$rows[$key]->text .= $row->note;
$rows[$key]->section = $section;
Expand Down

0 comments on commit 65bee28

Please sign in to comment.