Skip to content

Commit

Permalink
Added fixes for Contao 4.9
Browse files Browse the repository at this point in the history
  • Loading branch information
hschottm committed Jun 1, 2022
1 parent a8029bf commit f5f2ba6
Show file tree
Hide file tree
Showing 38 changed files with 465 additions and 530 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ During the validation in the save process the tags module automatically saves th
| Key | Value | Description |
| ---------- |-------------| -----|
| table | Source table `string` | Name of the source table of the tag data. Default is the name of the actual DCA data container. |
| isTag | true/false `boolean` | If true (default) the tags will be saved in a separate tag table (tl_tags). If false, the content of the tag field will be saved in the associated database field of the data container. In this case you'll need more than a char(1) database field. |
| isTag | Count `integer` | The maximum number of tags that should be shown above the input field. This may be helpful if you have a large number of tags. If the maximum number is lower than the number of all tags, the component takes the tags with the most selections first and hides tags which are used rarely. |
| maxtags | Count `integer` | The maximum number of tags that should be shown above the input field. This may be helpful if you have a large number of tags. If the maximum number is lower than the number of all tags, the component takes the tags with the most selections first and hides tags which are used rarely. |


15 changes: 4 additions & 11 deletions classes/TagField.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class TagField extends \TextField
{
protected $blnSubmitInput = FALSE;
protected $blnSubmitInput = true;
protected $strTagTable = "";
protected $intMaxTags = 0;

Expand All @@ -23,7 +23,7 @@ class TagField extends \TextField
*/
protected function saveTags($value)
{
if (!$this->blnSubmitInput)
if ($this->blnSubmitInput)
{
$this->import('Database');
$this->Database->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?")
Expand Down Expand Up @@ -66,9 +66,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
case 'isTag':
$this->blnSubmitInput = !$varValue;
break;
case 'table':
$this->strTagTable = $varValue;
break;
Expand All @@ -94,14 +91,11 @@ public function __get($strKey)
{
switch ($strKey)
{
case 'isTag':
return !$this->blnSubmitInput;
break;
case 'table':
return strlen($this->strTagTable) ? $this->strTagTable : $this->strTable;
break;
case 'value':
return $this->varValue;
return '';
break;
case 'maxtags':
return $this->intMaxTags;
Expand Down Expand Up @@ -130,7 +124,7 @@ public function generate()
$list .= '</li> ';
}
$list .= '</ul></div>';
$value = (!$this->blnSubmitInput) ? $this->readTags() : $this->varValue;
$value = $this->readTags();
return $list.sprintf('<input type="text" name="%s" id="ctrl_%s" class="tl_text%s" value="%s"%s onfocus="Backend.getScrollOffset();" />',
$this->strName,
$this->strId,
Expand All @@ -149,4 +143,3 @@ public function validate()
parent::validate();
}
}

12 changes: 3 additions & 9 deletions classes/TagFieldMemberFrontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class TagFieldMemberFrontend extends \FormTextField
{
protected $blnSubmitInput = FALSE;
protected $blnSubmitInput = true;
protected $strTagTable = "";
protected $intMaxTags = 0;

Expand All @@ -31,7 +31,7 @@ class TagFieldMemberFrontend extends \FormTextField
*/
protected function saveTags($value)
{
if (!$this->blnSubmitInput)
if ($this->blnSubmitInput)
{
$this->import('FrontendUser', 'User');
$this->import('Database');
Expand Down Expand Up @@ -71,9 +71,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
case 'isTag':
$this->blnSubmitInput = !$varValue;
break;
case 'table':
$this->strTagTable = $varValue;
break;
Expand All @@ -99,9 +96,6 @@ public function __get($strKey)
{
switch ($strKey)
{
case 'isTag':
return !$this->blnSubmitInput;
break;
case 'table':
return strlen($this->strTagTable) ? $this->strTagTable : $this->strTable;
break;
Expand Down Expand Up @@ -146,7 +140,7 @@ public function generate()
$list .= '</li> ';
}
$list .= '</ul></div>';
$value = (!$this->blnSubmitInput) ? $this->readTags() : $this->varValue;
$value = $this->readTags();
return sprintf($list.'<input type="%s" name="%s" id="ctrl_%s" class="text%s%s" value="%s"%s%s',
$this->type,
$this->strName,
Expand Down
80 changes: 27 additions & 53 deletions classes/TagHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

class TagHelper extends \Backend
{
public static $config = array();

/**
* Load the database object
*/
Expand All @@ -34,12 +36,12 @@ public static function getPageObj($jumpTo = null)
}
}

public function encode($tag)
public static function encode($tag)
{
return str_replace('/', 'x2F', $tag);
}

public function decode($tag)
public static function decode($tag)
{
return str_replace('x2F', '/', $tag);
}
Expand Down Expand Up @@ -89,7 +91,7 @@ public static function getSavedURLParams($objInput)
}
if (count($arrParams))
{
$strParams = join($arrParams, '&');
$strParams = implode('&', $arrParams);
}
return $strParams;
}
Expand Down Expand Up @@ -123,7 +125,7 @@ public function deleteIncompleteRecords($table, $new_records, $parent_table, $ch
->fetchEach('tid');
if (count($ids))
{
$this->Database->prepare("DELETE FROM tl_tag WHERE tid IN (" . join($ids, ",") . ") AND from_table = ?")
$this->Database->prepare("DELETE FROM tl_tag WHERE tid IN (" . implode(",", $ids) . ") AND from_table = ?")
->execute($table);
}
}
Expand Down Expand Up @@ -181,16 +183,13 @@ private function getTagsForTableAndId($table, $id, $url = false, $max_tags = 0,
}
if (strlen($target))
{
$pageArr = array();
$objFoundPage = $this->Database->prepare("SELECT id, alias FROM tl_page WHERE id=? OR alias=?")
->limit(1)
->execute(array($target, $target));
$pageArr = ($objFoundPage->numRows) ? $objFoundPage->fetchAssoc() : array();
if (count($pageArr))
$pageObj = new PageModel();
$pageObj = $pageObj::findPublishedByIdOrAlias($target);
if (!empty($pageObj))
{
foreach ($arrTags as $idx => $tag)
{
$arrTags[$idx]['url'] = ampersand($objPage->getFrontendUrl('/tag/' . $tag['tag']));
$arrTags[$idx]['url'] = StringUtil::ampersand($pageObj->getFrontendUrl('/tag/' . $tag['tag']));
}
}
}
Expand All @@ -208,11 +207,13 @@ private function getTagsForTableAndId($table, $id, $url = false, $max_tags = 0,
}
else
{
$pageObj = self::getPageObj($objArticle->tags_jumpto);
foreach ($arrTags as $idx => $tag)
{
$arrTags[$idx]['url'] = $objPage->getFrontendUrl('/articles/' . ((!$GLOBALS['TL_CONFIG']['disableAlias'] && strlen($objArticle->aAlias)) ? $objArticle->aAlias : $objArticle->aId));
$arrTags[$idx]['url'] = $pageObj->getFrontendUrl('/articles/' . ((!$GLOBALS['TL_CONFIG']['disableAlias'] && strlen($objArticle->aAlias)) ? $objArticle->aAlias : $objArticle->aId));
}
$objTemplate->url = $objPage->getFrontendUrl('/articles/' . ((!$GLOBALS['TL_CONFIG']['disableAlias'] && strlen($objArticle->aAlias)) ? $objArticle->aAlias : $objArticle->aId));
// Whats up here?
$objTemplate->url = $pageObj->getFrontendUrl('/articles/' . ((!$GLOBALS['TL_CONFIG']['disableAlias'] && strlen($objArticle->aAlias)) ? $objArticle->aAlias : $objArticle->aId));
}
break;
}
Expand Down Expand Up @@ -281,7 +282,7 @@ public function compileArticleHook($objTemplate, $arrDate, $moduleArticle)
$objTemplate->show_tags = $moduleArticle->tags_showtags;
if ($moduleArticle->tags_showtags)
{
$objTemplate->tags = $this->getTagsForArticle($moduleArticle, $moduleArticle->tags_max_tags, $moduleArticle->tags_relevance, $moduleArticlehis->tags_jumpto);
$objTemplate->tags = $this->getTagsForArticle($moduleArticle, $moduleArticle->tags_max_tags, $moduleArticle->tags_relevance, $moduleArticle->tags_jumpto);
}
}

Expand Down Expand Up @@ -329,7 +330,7 @@ private function getTagsForArticle($moduleArticle, $max_tags = 0, $relevance = 0
{
foreach ($arrTags as $idx => $tag)
{
$arrTags[$idx]['url'] = ampersand($objPage->getFrontendUrl('/tag/' . \TagHelper::encode($tag['tag'])));
$arrTags[$idx]['url'] = StringUtil::ampersand($objPage->getFrontendUrl('/tag/' . \TagHelper::encode($tag['tag'])));
}
}
}
Expand All @@ -340,32 +341,31 @@ private function getTagsForArticle($moduleArticle, $max_tags = 0, $relevance = 0
public function parseArticlesHook($objTemplate, $row)
{
global $objPage;
$this->import('Session');
$news_showtags = $this->Session->get('news_showtags');
$news_jumpto = $this->Session->get('news_jumpto');
$tag_named_class = $this->Session->get('news_tag_named_class');
$objTemplate->showTags = $news_showtags;
$news_showtags = static::$config['news_showtags'];
$news_jumpto = static::$config['news_jumpto'];
$tag_named_class = static::$config['news_tag_named_class'];
if ($news_showtags)
{
$pageObj = self::getPageObj($news_jumpto);
$tags = $this->getTags($row['id'], 'tl_news');
$taglist = array();
foreach ($tags as $id => $tag)
{
$strUrl = ampersand($pageObj->getFrontendUrl($items . '/tag/' . \TagHelper::encode($tag)));
$strUrl = StringUtil::ampersand($pageObj->getFrontendUrl('/tag/' . \TagHelper::encode($tag)));
$tags[$id] = '<a href="' . $strUrl . '">' . StringUtil::specialchars($tag) . '</a>';
$taglist[$id] = array(
'url' => $tags[$id],
'tag' => $tag,
'class' => TagList::_getTagNameClass($tag)
);
}
$objTemplate->showTags = 1;
$objTemplate->showTagClass = $tag_named_class;
$objTemplate->tags = $tags;
$objTemplate->taglist = $taglist;
}
}

public function getTagsAndTaglistForIdAndTable($id, $table, $jumpto)
{
$pageObj = self::getPageObj($jumpto);
Expand All @@ -374,7 +374,7 @@ public function getTagsAndTaglistForIdAndTable($id, $table, $jumpto)
$taglist = array();
foreach ($tags as $id => $tag)
{
$strUrl = ampersand($pageObj->getFrontendUrl($items . '/tag/' . \TagHelper::encode($tag)));
$strUrl = StringUtil::ampersand($pageObj->getFrontendUrl('/tag/' . \TagHelper::encode($tag)));
if (strlen(\Environment::get('queryString'))) $strUrl .= "?" . \Environment::get('queryString');
$tags[$id] = '<a href="' . $strUrl . '">' . StringUtil::specialchars($tag) . '</a>';
$taglist[$id] = array(
Expand All @@ -394,43 +394,17 @@ public function getTagsAndTaglistForIdAndTable($id, $table, $jumpto)
*/
public function generateEventFeed()
{
$session = $this->Session->get('calendar_feed_updater');

if (!is_array($session) || count($session) < 1)
{
return;
}

$this->import('CalendarTags');

foreach ($session as $id)
{
$this->CalendarTags->generateFeedsByCalendar($id);
}

$this->Session->set('calendar_feed_updater', null);
//$this->import('CalendarTags');
//$this->CalendarTags->generateFeedsByCalendar($id);
}

/**
* Check for modified news feeds and update the XML files if necessary
*/
public function generateNewsFeed()
{
$session = $this->Session->get('news_feed_updater');

if (!is_array($session) || count($session) < 1)
{
return;
}

$this->import('NewsTags');

foreach ($session as $id)
{
$this->NewsTags->generateFeedsByArchive($id);
}

$this->Session->set('news_feed_updater', null);
//$this->import('NewsTags');
//$this->NewsTags->generateFeedsByArchive($id);
}
}

20 changes: 9 additions & 11 deletions classes/TagList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Contao;

use Patchwork\Utf8;

/**
* Contao Open Source CMS - tags extension
*
Expand Down Expand Up @@ -129,19 +127,19 @@ public function getRelatedTagList($for_tags, $blnExcludeUnpublishedItems = true)
{
array_push($keys, 'from_table = ?');
}
$objTags = $this->Database->prepare("SELECT $tagfield, COUNT($tagfield) as count FROM $tagtable WHERE (" . join($keys, " OR ") . ") AND tid IN (" . join($ids, ",") . ") GROUP BY $tagfield ORDER BY $tagfield ASC")
$objTags = $this->Database->prepare("SELECT $tagfield, COUNT($tagfield) as count FROM $tagtable WHERE (" . implode(" OR ", $keys) . ") AND tid IN (" . implode(",", $ids) . ") GROUP BY $tagfield ORDER BY $tagfield ASC")
->execute($this->forTable);
}
else
{
if (strlen($this->forTable))
{
$objTags = $this->Database->prepare("SELECT $tagfield, COUNT($tagfield) as count FROM $tagtable WHERE from_table = ? AND tid IN (" . join($ids, ",") . ") GROUP BY $tagfield ORDER BY $tagfield ASC")
$objTags = $this->Database->prepare("SELECT $tagfield, COUNT($tagfield) as count FROM $tagtable WHERE from_table = ? AND tid IN (" . implode(",", $ids) . ") GROUP BY $tagfield ORDER BY $tagfield ASC")
->execute($this->forTable);
}
else
{
$objTags = $this->Database->prepare("SELECT $tagfield, COUNT($tagfield) as count FROM $tagtable WHERE tid IN (" . join($ids, ",") . ") GROUP BY $tagfield ORDER BY $tagfield ASC")
$objTags = $this->Database->prepare("SELECT $tagfield, COUNT($tagfield) as count FROM $tagtable WHERE tid IN (" . implode(",", $ids) . ") GROUP BY $tagfield ORDER BY $tagfield ASC")
->execute();
}
}
Expand All @@ -162,21 +160,21 @@ public function getRelatedTagList($for_tags, $blnExcludeUnpublishedItems = true)
{
array_push($keys, 'from_table = ?');
}
$count = count($this->Database->prepare("SELECT tid FROM $tagtable WHERE $tagfield = ? AND (" . join($keys, " OR ") . ") AND tid IN (" . join($ids, ",") . ")")
$count = count($this->Database->prepare("SELECT tid FROM $tagtable WHERE $tagfield = ? AND (" . implode(" OR ", $keys) . ") AND tid IN (" . implode(",", $ids) . ")")
->execute(array_merge(array($objTags->tag), $this->forTable))
->fetchAllAssoc());
}
else
{
if (strlen($this->forTable))
{
$count = count($this->Database->prepare("SELECT tid FROM $tagtable WHERE $tagfield = ? AND from_table = ? AND tid IN (" . join($ids, ",") . ")")
$count = count($this->Database->prepare("SELECT tid FROM $tagtable WHERE $tagfield = ? AND from_table = ? AND tid IN (" . implode(",", $ids) . ")")
->execute($objTags->tag, $this->forTable)
->fetchAllAssoc());
}
else
{
$count = count($this->Database->prepare("SELECT $tagfield, COUNT($tagfield) as count FROM $tagtable WHERE $tagfield = ? AND tid IN (" . join($ids, ",") . ")")
$count = count($this->Database->prepare("SELECT $tagfield, COUNT($tagfield) as count FROM $tagtable WHERE $tagfield = ? AND tid IN (" . implode(",", $ids) . ")")
->execute($objTags->tag)
->fetchAllAssoc());
}
Expand Down Expand Up @@ -339,12 +337,12 @@ protected function cloud_tags($tags)
*/
protected function getTagNameClass($tag)
{
return Utf8::toAscii(StringUtil::standardize($tag));
return StringUtil::convertEncoding(StringUtil::standardize($tag), "ASCII");
}

public static function _getTagNameClass($tag)
{
return Utf8::toAscii(StringUtil::standardize($tag));
return StringUtil::convertEncoding(StringUtil::standardize($tag), "ASCII");
}

protected function getRelevantPages($page_id)
Expand All @@ -369,7 +367,7 @@ protected function getArticlesForPages()
$time = time();

// Get published articles
$pids = join($this->arrPages, ",");
$pids = implode(",", $this->arrPages);
if (strlen($this->inColumn))
{
$objArticles = $this->Database->prepare("SELECT id, title, alias, inColumn, cssID FROM tl_article WHERE inColumn = ? AND pid IN (" . $pids . ") " . (!BE_USER_LOGGED_IN ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND published=1" : "") . " ORDER BY sorting")
Expand Down
Loading

0 comments on commit f5f2ba6

Please sign in to comment.