From 8bd3b59f30531dd575ad19d023e2c1793ed24bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helmut=20Schottm=C3=BCller?= Date: Tue, 19 Nov 2024 08:58:13 +0100 Subject: [PATCH] Various Contao 5 fixes --- src/ContaoManager/Plugin.php | 5 +- src/InsertTag/TagsUsedInsertTag.php | 2 +- src/Resources/contao/classes/TagList.php | 24 ++++----- .../contao/classes/TagListMembers.php | 21 +++++--- src/Resources/contao/config/config.php | 50 ++++++++----------- .../contao/dca/tl_calendar_events.php | 8 +-- .../contao/modules/ModuleEventlistTags.php | 7 +++ .../modules/ModuleTagListByCategory.php | 10 ++-- .../modules/ModuleTaggedArticleList.php | 26 +++++++--- 9 files changed, 81 insertions(+), 72 deletions(-) diff --git a/src/ContaoManager/Plugin.php b/src/ContaoManager/Plugin.php index 8170302..9eba864 100644 --- a/src/ContaoManager/Plugin.php +++ b/src/ContaoManager/Plugin.php @@ -35,10 +35,7 @@ public function getBundles(ParserInterface $parser): array { return [ BundleConfig::create(HschottmTagsBundle::class) - ->setLoadAfter([ContaoCoreBundle::class]) - ->setLoadAfter([ContaoNewsBundle::class]) - ->setLoadAfter([ContaoCalendarBundle::class]) - ->setLoadAfter([ContaoFaqBundle::class]) + ->setLoadAfter([ContaoCoreBundle::class, ContaoNewsBundle::class, ContaoCalendarBundle::class, ContaoFaqBundle::class]) ->setReplace(['tags']), ]; } diff --git a/src/InsertTag/TagsUsedInsertTag.php b/src/InsertTag/TagsUsedInsertTag.php index 8e2d7aa..77a969c 100644 --- a/src/InsertTag/TagsUsedInsertTag.php +++ b/src/InsertTag/TagsUsedInsertTag.php @@ -23,7 +23,7 @@ public function __invoke(ResolvedInsertTag $insertTag): InsertTagResult $relatedlist = (strlen(TagHelper::decode(Input::get('related')))) ? preg_split("/,/", TagHelper::decode(Input::get('related'))) : array(); if (strlen(TagHelper::decode(Input::get('tag')))) { - $headlinetags = array_merge($headlinetags, array($this->Input->get('tag'))); + $headlinetags = array_merge($headlinetags, array(Input::get('tag'))); if (count($relatedlist)) { $headlinetags = array_merge($headlinetags, $relatedlist); diff --git a/src/Resources/contao/classes/TagList.php b/src/Resources/contao/classes/TagList.php index a43c915..3e51ba4 100644 --- a/src/Resources/contao/classes/TagList.php +++ b/src/Resources/contao/classes/TagList.php @@ -63,11 +63,11 @@ public function getRelatedTagList($for_tags, $blnExcludeUnpublishedItems = true) { if ($blnExcludeUnpublishedItems && Database::getInstance()->fieldExists('published', $strTable)) { - $arrTableSql[] = "SELECT DISTINCT tid FROM $tagtable, $strTable WHERE (from_table='$strTable' AND tid=$strTable.id AND published='1') AND $tagfield = ?"; + $arrTableSql[] = "SELECT DISTINCT tid FROM $tagtable, $strTable WHERE (from_table='$strTable' AND tid=$strTable.id AND published='1') AND $tagfield = '?'"; } else { - $arrTableSql[] = "SELECT DISTINCT tid FROM $tagtable WHERE from_table='$strTable' AND $tagfield = ?"; + $arrTableSql[] = "SELECT DISTINCT tid FROM $tagtable WHERE from_table='$strTable' AND $tagfield = '?'"; } } @@ -75,14 +75,12 @@ public function getRelatedTagList($for_tags, $blnExcludeUnpublishedItems = true) for ($i = 0; $i < count($for_tags); $i++) { $arrSql = array(); - $values = array(); foreach ($arrTableSql as $sql) { - $arrSql[] = $sql; - $values[] = $for_tags[$i]; + $arrSql[] = str_replace("?", $for_tags[$i], $sql); } $arr = Database::getInstance()->prepare(implode(" UNION ", $arrSql)) - ->execute($values) + ->execute() ->fetchEach('tid'); if ($i == 0) { @@ -129,10 +127,10 @@ public function getRelatedTagList($for_tags, $blnExcludeUnpublishedItems = true) $values = array(); for ($i = 0; $i < count($this->forTable); $i++) { - \array_push($keys, 'from_table = ?'); + \array_push($keys, "from_table = '" . $this->forTable[$i] . "'"); } $objTags = Database::getInstance()->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); + ->execute(); } else { @@ -162,10 +160,10 @@ public function getRelatedTagList($for_tags, $blnExcludeUnpublishedItems = true) $values = array(); for ($i = 0; $i < count($this->forTable); $i++) { - \array_push($keys, 'from_table = ?'); + \array_push($keys, "from_table = '" . $this->forTable[$i] . "'"); } $count = count(Database::getInstance()->prepare("SELECT tid FROM $tagtable WHERE $tagfield = ? AND (" . implode(" OR ", $keys) . ") AND tid IN (" . implode(",", $ids) . ")") - ->execute(array_merge(array($objTags->tag), $this->forTable)) + ->execute($objTags->tag) ->fetchAllAssoc()); } else @@ -226,16 +224,16 @@ public function getTagList($blnExcludeUnpublishedItems = true) { if ($blnExcludeUnpublishedItems && Database::getInstance()->fieldExists('published', $strTable)) { - $arrSql[] = "SELECT $tagfield, from_table, COUNT($tagfield) AS count FROM $tagtable, $strTable WHERE (from_table='$strTable' AND tid=$strTable.id AND published='1') GROUP BY $tagfield"; + $arrSql[] = "SELECT $tagfield, COUNT($tagfield) AS count FROM $tagtable, $strTable WHERE (from_table='$strTable' AND tid=$strTable.id AND published='1') GROUP BY $tagfield"; } else { - $arrSql[] = "SELECT $tagfield, from_table, COUNT($tagfield) AS count FROM $tagtable WHERE from_table='$strTable' GROUP BY $tagfield"; + $arrSql[] = "SELECT $tagfield, COUNT($tagfield) AS count FROM $tagtable WHERE from_table='$strTable' GROUP BY $tagfield"; } } if (count($arrSql) > 1) { - $sql = "SELECT $tagfield AS tag, from_table, SUM(count) AS count FROM (" . implode(" UNION ", $arrSql). ") temp GROUP BY tag"; + $sql = "SELECT $tagfield AS tag, SUM(count) AS count FROM (" . implode(" UNION ", $arrSql). ") temp GROUP BY tag"; } else { diff --git a/src/Resources/contao/classes/TagListMembers.php b/src/Resources/contao/classes/TagListMembers.php index 9930bec..b589033 100644 --- a/src/Resources/contao/classes/TagListMembers.php +++ b/src/Resources/contao/classes/TagListMembers.php @@ -10,6 +10,10 @@ namespace Hschottm\TagsBundle; + use Contao\Database; + use Contao\System; + use Contao\StringUtil; + /** * Class TagListMembers * @@ -79,11 +83,11 @@ public function getRelatedTagList($for_tags, $blnExcludeUnpublishedItems = true) public function getTagList($blnExcludeUnpublishedItems = true) { - if (count($this->arrCloudTags) == 0) - { +// if (count($this->arrCloudTags) == 0) +// { if (count($this->arrMembergroups) > 0) { - $objTags = Database::getInstance()->prepare("SELECT tag, COUNT(tag) as count, tl_member.groups FROM tl_tag, tl_member WHERE tl_tag.tid = tl_member.id AND from_table = ? GROUP BY tag ORDER BY tag ASC") + $objTags = Database::getInstance()->prepare("SELECT tag, COUNT(tag) as count FROM tl_tag, tl_member WHERE tl_tag.tid = tl_member.id AND from_table = ? GROUP BY tag ORDER BY tag ASC") ->execute('tl_member'); $list = ""; $tags = array(); @@ -91,18 +95,19 @@ public function getTagList($blnExcludeUnpublishedItems = true) { while ($objTags->next()) { - if ($this->isMemberOf($objTags->groups)) - { + //if ($this->isMemberOf($objTags->groups)) + //{ \array_push($tags, array('tag_name' => $objTags->tag, 'tag_count' => $objTags->count)); - } + //} } } + if (count($tags)) { $this->arrCloudTags = $this->cloud_tags($tags); } } - } +// } return $this->arrCloudTags; } @@ -113,7 +118,7 @@ public function getTagList($blnExcludeUnpublishedItems = true) */ protected function isMemberOf($taggroups) { - $groups = \Contao\StringUtil::deserialize($taggroups); + $groups = StringUtil::deserialize($taggroups); // No groups assigned if (!is_array($groups) || count($groups) < 1) diff --git a/src/Resources/contao/config/config.php b/src/Resources/contao/config/config.php index 5b8feca..ec6220d 100644 --- a/src/Resources/contao/config/config.php +++ b/src/Resources/contao/config/config.php @@ -69,47 +69,37 @@ $GLOBALS['TL_CTE']['texts']['headline'] = Hschottm\TagsBundle\ContentHeadlineTags::class; $GLOBALS['TL_CTE']['media']['gallery'] = Hschottm\TagsBundle\ContentGalleryTags::class; +// previously css and js have been added only to the backend +/* if (System::getContainer()->get('contao.routing.scope_matcher') ->isBackendRequest(System::getContainer()->get('request_stack')->getCurrentRequest() ?? Request::create('')) ) { - /** - * CSS files - */ - - if (isset($GLOBALS['TL_CSS']) && \is_array($GLOBALS['TL_CSS'])) - { - \Contao\ArrayUtil::arrayInsert($GLOBALS['TL_CSS'], 1, 'bundles/hschottmtags/css/tag.css'); - } - else - { - $GLOBALS['TL_CSS'] = array('bundles/hschottmtags/css/tag.css'); - } - - /** - * JavaScript files - */ - if (isset($GLOBALS['TL_JAVASCRIPT']) && \is_array($GLOBALS['TL_JAVASCRIPT'])) - { - \Contao\ArrayUtil::arrayInsert($GLOBALS['TL_JAVASCRIPT'], 1, 'bundles/hschottmtags/js/tag.js'); - } - else - { - $GLOBALS['TL_JAVASCRIPT'] = array('bundles/hschottmtags/js/tag.js'); - } } +*/ + +/** + * CSS files + */ +$GLOBALS['TL_CSS'][] = 'bundles/hschottmtags/css/tag.css'; + +/** + * JavaScript files + */ +$GLOBALS['TL_JAVASCRIPT'][] = 'bundles/hschottmtags/js/tag.js'; + /** * Hooks */ -//$GLOBALS['TL_HOOKS']['reviseTable'][] = array(Hschottm\TagsBundle\TagHelper::class, 'deleteIncompleteRecords'); -//$GLOBALS['TL_HOOKS']['reviseTable'][] = array(Hschottm\TagsBundle\TagHelper::class, 'deleteUnusedTagsForTable'); -//$GLOBALS['TL_HOOKS']['replaceInsertTags'][] = array(Hschottm\TagsBundle\TagHelper::class, 'replaceTagInsertTags'); -//$GLOBALS['TL_HOOKS']['parseArticles'][] = array(Hschottm\TagsBundle\TagHelper::class, 'parseArticlesHook'); -//$GLOBALS['TL_HOOKS']['compileArticle'][] = array(Hschottm\TagsBundle\TagHelper::class, 'compileArticleHook'); +//$GLOBALS['TL_HOOKS']['reviseTable'][] = array(Hschottm\TagsBundle\TagHelper::class, 'deleteIncompleteRecords'); -> see ReviseTableListener +//$GLOBALS['TL_HOOKS']['reviseTable'][] = array(Hschottm\TagsBundle\TagHelper::class, 'deleteUnusedTagsForTable'); -> see ReviseTableListener +//$GLOBALS['TL_HOOKS']['replaceInsertTags'][] = array(Hschottm\TagsBundle\TagHelper::class, 'replaceTagInsertTags'); -> see InsertTag namespace +//$GLOBALS['TL_HOOKS']['parseArticles'][] = array(Hschottm\TagsBundle\TagHelper::class, 'parseArticlesHook'); -> see ParseArticlesListener +//$GLOBALS['TL_HOOKS']['compileArticle'][] = array(Hschottm\TagsBundle\TagHelper::class, 'compileArticleHook'); -> see CompileArticleListener // for contao-memberlist -//$GLOBALS['TL_HOOKS']['setMemberlistOptions'][] = array(Hschottm\TagsBundle\TagMemberHelper::class, 'setMemberlistOptions'); +//$GLOBALS['TL_HOOKS']['setMemberlistOptions'][] = array(Hschottm\TagsBundle\TagMemberHelper::class, 'setMemberlistOptions'); -> TBD, extension is no longer working with Contao 5 /** diff --git a/src/Resources/contao/dca/tl_calendar_events.php b/src/Resources/contao/dca/tl_calendar_events.php index 213aa9a..6c3f954 100644 --- a/src/Resources/contao/dca/tl_calendar_events.php +++ b/src/Resources/contao/dca/tl_calendar_events.php @@ -3,6 +3,7 @@ use Contao\Backend; use Contao\DataContainer; use Contao\Database; +use Contao\StringUtil; /** * Contao Open Source CMS - tags extension @@ -12,8 +13,8 @@ * @license LGPL-3.0+ */ - if (array_key_exists('tl_calendar_events', $GLOBALS['TL_DCA'])) - { + +if (array_key_exists('tl_calendar_events', $GLOBALS['TL_DCA'])) { /* if (is_array($GLOBALS['TL_DCA']['tl_calendar_events']['config']['onload_callback'])) @@ -28,12 +29,11 @@ } */ - /** * Change tl_calendar_events palettes */ if (isset($GLOBALS['TL_CONFIG']['disabledTagObjects'])) { - $disabledObjects = \Contao\StringUtil::deserialize($GLOBALS['TL_CONFIG']['disabledTagObjects'], true); + $disabledObjects = StringUtil::deserialize($GLOBALS['TL_CONFIG']['disabledTagObjects'], true); } else { $disabledObjects = array(); } diff --git a/src/Resources/contao/modules/ModuleEventlistTags.php b/src/Resources/contao/modules/ModuleEventlistTags.php index b1bdc0c..df3e680 100644 --- a/src/Resources/contao/modules/ModuleEventlistTags.php +++ b/src/Resources/contao/modules/ModuleEventlistTags.php @@ -4,8 +4,15 @@ use Contao\ModuleEventlist; use Contao\CoreBundle\Exception\PageNotFoundException; +use Contao\CoreBundle\Exception\OutOfBoundsException; use Contao\Database; use Contao\Input; +use Contao\Date; +use Contao\FilesModel; +use Contao\FrontendTemplate; +use Contao\StringUtil; +use Contao\Events; +use Contao\CalendarEventsModel; /** * Contao Open Source CMS - tags extension diff --git a/src/Resources/contao/modules/ModuleTagListByCategory.php b/src/Resources/contao/modules/ModuleTagListByCategory.php index 844c7fb..ac3cf17 100644 --- a/src/Resources/contao/modules/ModuleTagListByCategory.php +++ b/src/Resources/contao/modules/ModuleTagListByCategory.php @@ -70,7 +70,7 @@ protected function compile() $marks = array(); foreach ($this->sourcetables as $table) { - \array_push($marks, '?'); + \array_push($marks, $table); } foreach ($alltags as $tag) { @@ -78,8 +78,8 @@ protected function compile() { if (count($tagids)) { - $found = Database::getInstance()->prepare("SELECT tid, from_table FROM tl_tag WHERE from_table IN (" . implode(',', $marks) . ") AND tag = ? AND tid IN (" . implode(",",$tagids) . ")") - ->execute(array_merge($this->sourcetables, array($tag))) + $found = Database::getInstance()->prepare("SELECT tid, from_table FROM tl_tag WHERE from_table IN ('" . implode("', '", $marks) . "')" . " AND tag = ? AND tid IN (" . implode(",",$tagids) . ")") + ->execute($tag) ->fetchAllAssoc(); foreach ($found as $data) { @@ -90,8 +90,8 @@ protected function compile() } else if ($first) { - $found = Database::getInstance()->prepare("SELECT tid, from_table FROM tl_tag WHERE from_table IN (" . implode(',', $marks) . ") AND tag = ?") - ->execute(array_merge($this->sourcetables, array($tag))) + $found = Database::getInstance()->prepare("SELECT tid, from_table FROM tl_tag WHERE from_table IN ('" . implode("', '", $marks) . "')" . " AND tag = ?") + ->execute($tag) ->fetchAllAssoc(); foreach ($found as $data) { diff --git a/src/Resources/contao/modules/ModuleTaggedArticleList.php b/src/Resources/contao/modules/ModuleTaggedArticleList.php index 134469e..85bf18c 100644 --- a/src/Resources/contao/modules/ModuleTaggedArticleList.php +++ b/src/Resources/contao/modules/ModuleTaggedArticleList.php @@ -5,9 +5,14 @@ use Contao\Database; use Contao\System; use Contao\Module; +use Contao\Environment; use Contao\BackendTemplate; +use Contao\FrontendTemplate; use Contao\Input; use Contao\StringUtil; +use Contao\PageModel; +use Contao\CoreBundle\Routing\ContentUrlGenerator; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; /** * @copyright Helmut Schottmüller 2009-2024 @@ -157,16 +162,20 @@ protected function getArticlesForPages() $objArticles->cssID = StringUtil::deserialize($objArticles->cssID, true); // ??? $alias = strlen($objArticles->alias) ? $objArticles->alias : $objArticles->title; $objArticles->startDate = (intval($objArticles->start) > 0) ? $this->parseDate($GLOBALS['TL_CONFIG']['datimFormat'], intval($objArticles->start)) : ''; - $objArticles->teaser = $this->replaceInsertTags($objArticles->teaser); + $teaser = $objArticles->teaser; + if (isset($teaser)) { + $insertTagParser = System::getContainer()->get('contao.insert_tag.parser'); + $teaser = $insertTagParser->replace($teaser); + } if (!empty($format)) { if ($format == 'xhtml') { - $objArticles->teaser = StringUtil::toXhtml($objArticles->teaser); + $objArticles->teaser = StringUtil::toXhtml($teaser); } else { - $objArticles->teaser = StringUtil::toHtml5($objArticles->teaser); + $objArticles->teaser = StringUtil::toHtml5($teaser); } } @@ -204,7 +213,7 @@ protected function compile() $articles = array(); $id = $objPage->id; - $this->Template->request = $this->Environment->request; + $this->Template->request = Environment::get('request'); $time = time(); @@ -260,16 +269,19 @@ protected function compile() if (count($pageArr) == 0) { $items = ''; - if (strlen($this->Input->get('items'))) + if (strlen(Input::get('items'))) { - $items = '/items/' . $this->Input->get('items'); + $items = '/items/' . Input::get('items'); } $pageArr = $objPage->row(); } $tags = $this->getTags($arrArticle['id']); + //$contentUrlGenerator = System::getContainer()->get('contao.routing.content_url_generator'); foreach ($tags as $id => $tag) { - $strUrl = ampersand($this->generateFrontendUrl($pageArr, $items . '/tag/' . TagHelper::encode($tag))); + //$pageModel = PageModel::findPublishedByIdOrAlias("48"); + //$strUrl = StringUtil::ampersand($pageModel->getFrontendUrl('/tag/' . TagHelper::encode($tag['tag_name']))); + $strUrl = '{{article_url::' . $arrArticle['id'] . '}}'; $tags[$id] = '' . StringUtil::specialchars($tag) . ''; } $objTemplate->tags = $tags;