diff --git a/classes/CalendarTags.php b/classes/CalendarTags.php
index 0e8023a..6c4a89a 100644
--- a/classes/CalendarTags.php
+++ b/classes/CalendarTags.php
@@ -63,7 +63,7 @@ private function getTagsForTableAndId($table, $id, $url = false)
}
else
{
- $strUrl = $objPage->getFrontendUrl('/articles/' . ((!$GLOBALS['TL_CONFIG']['disableAlias'] && strlen($objEvent->aAlias)) ? $objEvent->aAlias : $objEvent->aId));
+ $strUrl = \TagHelper::getPageObj()->getFrontendUrl('/articles/' . ((!$GLOBALS['TL_CONFIG']['disableAlias'] && strlen($objEvent->aAlias)) ? $objEvent->aAlias : $objEvent->aId));
}
break;
}
diff --git a/classes/TagHelper.php b/classes/TagHelper.php
index e0b78ef..ad6b410 100644
--- a/classes/TagHelper.php
+++ b/classes/TagHelper.php
@@ -21,6 +21,19 @@ public function __construct()
$this->import('Database');
}
+ public static function getPageObj($jumpTo = null)
+ {
+ global $objPage;
+ if(!empty($jumpTo))
+ {
+ return (new PageModel())->findPublishedById($jumpTo);
+ }
+ else
+ {
+ return $objPage;
+ }
+ }
+
public function encode($tag)
{
return str_replace('/', 'x2F', $tag);
@@ -334,24 +347,12 @@ public function parseArticlesHook($objTemplate, $row)
$objTemplate->showTags = $news_showtags;
if ($news_showtags)
{
- $pageArr = array();
- if (strlen($news_jumpto))
- {
- $objFoundPage = $this->Database->prepare("SELECT id, alias FROM tl_page WHERE id=?")
- ->limit(1)
- ->execute($news_jumpto);
- $pageArr = ($objFoundPage->numRows) ? $objFoundPage->fetchAssoc() : array();
- }
- if (count($pageArr) == 0)
- {
- global $objPage;
- $pageArr = $objPage->row();
- }
+ $pageObj = self::getPageObj($news_jumpto);
$tags = $this->getTags($row['id'], 'tl_news');
$taglist = array();
foreach ($tags as $id => $tag)
{
- $strUrl = ampersand($objPage->getFrontendUrl($items . '/tag/' . \TagHelper::encode($tag)));
+ $strUrl = ampersand($pageObj->getFrontendUrl($items . '/tag/' . \TagHelper::encode($tag)));
$tags[$id] = '' . StringUtil::specialchars($tag) . '';
$taglist[$id] = array(
'url' => $tags[$id],
@@ -367,24 +368,12 @@ public function parseArticlesHook($objTemplate, $row)
public function getTagsAndTaglistForIdAndTable($id, $table, $jumpto)
{
- $pageArr = array();
- if (strlen($jumpto))
- {
- $objFoundPage = $this->Database->prepare("SELECT id, alias FROM tl_page WHERE id=?")
- ->limit(1)
- ->execute($jumpto);
- $pageArr = ($objFoundPage->numRows) ? $objFoundPage->fetchAssoc() : array();
- }
- if (count($pageArr) == 0)
- {
- global $objPage;
- $pageArr = $objPage->row();
- }
+ $pageObj = self::getPageObj($jumpto);
$tags = $this->getTags($id, $table);
$taglist = array();
foreach ($tags as $id => $tag)
{
- $strUrl = ampersand($objPage->getFrontendUrl($items . '/tag/' . \TagHelper::encode($tag)));
+ $strUrl = ampersand($pageObj->getFrontendUrl($items . '/tag/' . \TagHelper::encode($tag)));
if (strlen(\Environment::get('queryString'))) $strUrl .= "?" . \Environment::get('queryString');
$tags[$id] = '' . StringUtil::specialchars($tag) . '';
$taglist[$id] = array(
diff --git a/classes/TagList.php b/classes/TagList.php
index 2f91773..5875477 100644
--- a/classes/TagList.php
+++ b/classes/TagList.php
@@ -2,6 +2,8 @@
namespace Contao;
+use Patchwork\Utf8;
+
/**
* Contao Open Source CMS - tags extension
*
@@ -337,12 +339,12 @@ protected function cloud_tags($tags)
*/
protected function getTagNameClass($tag)
{
- return str_replace('"', '', str_replace(' ', '_', $tag));
+ return Utf8::toAscii(StringUtil::standardize($tag));
}
public static function _getTagNameClass($tag)
{
- return str_replace('"', '', str_replace(' ', '_', $tag));
+ return Utf8::toAscii(StringUtil::standardize($tag));
}
protected function getRelevantPages($page_id)
diff --git a/composer.json b/composer.json
index 16ead01..db9134b 100644
--- a/composer.json
+++ b/composer.json
@@ -13,6 +13,7 @@
"require":{
"php":">=5.3",
"contao/core-bundle": "~4.8.0",
+ "patchwork/utf8": "^1.3",
"contao-community-alliance/composer-plugin": "~3.0"
},
"extra":{
diff --git a/modules/ModuleTagCloud.php b/modules/ModuleTagCloud.php
index b9dccf5..e718132 100644
--- a/modules/ModuleTagCloud.php
+++ b/modules/ModuleTagCloud.php
@@ -91,15 +91,11 @@ protected function compile()
*/
protected function showTags()
{
+ global $objPage;
$this->loadLanguageFile('tl_module');
$strUrl = ampersand(\Environment::get('request'));
// Get target page
- $objPageObject = $this->Database->prepare("SELECT id, alias FROM tl_page WHERE id=?")
- ->limit(1)
- ->execute($this->tag_jumpTo);
- global $objPage;
- $default = ($objPage != null) ? $objPage->row() : array();
- $pageArr = ($objPageObject->numRows) ? $objPageObject->fetchAssoc() : $default;
+ $pageObj = \TagHelper::getPageObj($this->tag_jumpTo);
$strParams = '';
if ($this->keep_url_params)
@@ -109,7 +105,7 @@ protected function showTags()
foreach ($this->arrTags as $idx => $tag)
{
- if (count($pageArr))
+ if (!empty($pageObj))
{
$strUrl = ampersand($objPage->getFrontendUrl('/tag/' . \TagHelper::encode($tag['tag_name'])));
if (strlen($strParams))
@@ -144,7 +140,6 @@ protected function showTags()
}
if ($this->checkForContentElementOnPage)
{
- global $objPage;
// get articles on page
$arrArticles = $this->Database->prepare("SELECT id FROM tl_article WHERE pid = ?")
->execute($objPage->id)->fetchEach('id');
@@ -164,10 +159,10 @@ protected function showTags()
$relatedlist = (strlen(\TagHelper::decode(\Input::get('related')))) ? preg_split("/,/", \TagHelper::decode(\Input::get('related'))) : array();
foreach ($this->arrRelated as $idx => $tag)
{
- if (count($pageArr))
+ if (!empty($pageObj))
{
$allrelated = array_merge($relatedlist, array($tag['tag_name']));
- $strUrl = ampersand($objPage->getFrontendUrl('/tag/' . \TagHelper::encode(\TagHelper::decode(\Input::get('tag'))) . '/related/' . \TagHelper::encode(join($allrelated, ','))));
+ $strUrl = ampersand($pageObj->getFrontendUrl('/tag/' . \TagHelper::encode(\TagHelper::decode(\Input::get('tag'))) . '/related/' . \TagHelper::encode(join($allrelated, ','))));
}
$this->arrRelated[$idx]['tag_url'] = $strUrl;
}
@@ -198,26 +193,23 @@ protected function showTags()
$this->Template->lngEmpty = $GLOBALS['TL_LANG']['tl_module']['tag_clear_tags'];
}
$GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/tags/assets/tagcloud.js';
- if (count($pageArr))
+ if (!empty($pageObj))
{
$this->Template->topten = $this->tag_topten;
if ($this->tag_topten)
{
foreach ($this->arrTopTenTags as $idx => $tag)
{
- if (count($pageArr))
+ $strUrl = ampersand($pageObj->getFrontendUrl('/tag/' . \TagHelper::encode($tag['tag_name'])));
+ if (strlen($strParams))
{
- $strUrl = ampersand($objPage->getFrontendUrl('/tag/' . \TagHelper::encode($tag['tag_name'])));
- if (strlen($strParams))
+ if (strpos($strUrl, '?') !== false)
+ {
+ $strUrl .= '&' . $strParams;
+ }
+ else
{
- if (strpos($strUrl, '?') !== false)
- {
- $strUrl .= '&' . $strParams;
- }
- else
- {
- $strUrl .= '?' . $strParams;
- }
+ $strUrl .= '?' . $strParams;
}
}
$this->arrTopTenTags[$idx]['tag_url'] = $strUrl;
diff --git a/modules/ModuleTagContentList.php b/modules/ModuleTagContentList.php
index 476392f..5cfffbf 100644
--- a/modules/ModuleTagContentList.php
+++ b/modules/ModuleTagContentList.php
@@ -86,11 +86,11 @@ protected function getArticlesForTagSource($sourcetable)
{
if ($this->linktoarticles)
{ // link to articles
- $articles[] = array('content' => '' . $objArticle->title . '', 'tags' => $taglist, 'data' => $objArticle->row());
+ $articles[] = array('content' => '' . $objArticle->title . '', 'tags' => $taglist, 'data' => $objArticle->row());
}
else
{ // link to pages
- $articles[] = array('content' => '' . $objArticle->title . '', 'tags' => $taglist, 'data' => $objArticle->row());
+ $articles[] = array('content' => '' . $objArticle->title . '', 'tags' => $taglist, 'data' => $objArticle->row());
}
}
}
diff --git a/modules/ModuleTagScope.php b/modules/ModuleTagScope.php
index c15caed..dc0eaf8 100644
--- a/modules/ModuleTagScope.php
+++ b/modules/ModuleTagScope.php
@@ -63,10 +63,7 @@ protected function compile()
$this->Template->lngTags = (strlen($this->clear_text)) ? $this->clear_text : $GLOBALS['TL_LANG']['tl_module']['tags'];
$this->Template->jumpTo = $this->jumpTo;
$this->Template->arrTags = $this->arrTags;
- $objPageObject = $this->Database->prepare("SELECT id, alias FROM tl_page WHERE id=?")
- ->limit(1)
- ->execute($this->tag_jumpTo);
- $pageArr = ($objPageObject->numRows) ? $objPageObject->fetchAssoc() : array();
+ $pageObj = \TagHelper::getPageObj($this->tag_jumpTo);
$strParams = '';
if ($this->keep_url_params)
{
@@ -75,9 +72,9 @@ protected function compile()
$tagurls = array();
foreach ($this->arrTags as $idx => $tag)
{
- if (count($pageArr))
+ if (!empty($pageObj))
{
- $strUrl = ampersand($objPage->getFrontendUrl('/tag/' . \TagHelper::encode($tag)));
+ $strUrl = ampersand($pageObj->getFrontendUrl('/tag/' . \TagHelper::encode($tag)));
if (strlen($strParams))
{
if (strpos($strUrl, '?') !== false)
@@ -93,7 +90,7 @@ protected function compile()
}
}
$this->Template->tag_urls = $tagurls;
- $strEmptyUrl = ampersand($objPage->getFrontendUrl());
+ $strEmptyUrl = ampersand($pageObj->getFrontendUrl());
if (strlen($strParams))
{
if (strpos($strEmptyUrl, '?') !== false)
@@ -131,7 +128,7 @@ protected function compile()
$related = array_slice($newarr, 1);
$tagpath .= '/related/' . join($related, ',');
}
- $strUrl = ampersand($objPage->getFrontendUrl($tagpath));
+ $strUrl = ampersand($pageObj->getFrontendUrl($tagpath));
if (strlen($strParams))
{
if (strpos($strUrl, '?') !== false)