Skip to content

Commit

Permalink
Various Contao 5 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hschottm committed Nov 19, 2024
1 parent 049741c commit 8bd3b59
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 72 deletions.
5 changes: 1 addition & 4 deletions src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/InsertTag/TagsUsedInsertTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 11 additions & 13 deletions src/Resources/contao/classes/TagList.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,24 @@ 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 = '?'";
}
}

$ids = array();
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)
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down
21 changes: 13 additions & 8 deletions src/Resources/contao/classes/TagListMembers.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

namespace Hschottm\TagsBundle;

use Contao\Database;
use Contao\System;
use Contao\StringUtil;

/**
* Class TagListMembers
*
Expand Down Expand Up @@ -79,30 +83,31 @@ 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();
if ($objTags->numRows)
{
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;
}

Expand All @@ -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)
Expand Down
50 changes: 20 additions & 30 deletions src/Resources/contao/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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


/**
Expand Down
8 changes: 4 additions & 4 deletions src/Resources/contao/dca/tl_calendar_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Contao\Backend;
use Contao\DataContainer;
use Contao\Database;
use Contao\StringUtil;

/**
* Contao Open Source CMS - tags extension
Expand All @@ -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']))
Expand All @@ -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();
}
Expand Down
7 changes: 7 additions & 0 deletions src/Resources/contao/modules/ModuleEventlistTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/Resources/contao/modules/ModuleTagListByCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ protected function compile()
$marks = array();
foreach ($this->sourcetables as $table)
{
\array_push($marks, '?');
\array_push($marks, $table);
}
foreach ($alltags as $tag)
{
if (strlen(trim($tag)))
{
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)
{
Expand All @@ -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)
{
Expand Down
26 changes: 19 additions & 7 deletions src/Resources/contao/modules/ModuleTaggedArticleList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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] = '<a href="' . $strUrl . '">' . StringUtil::specialchars($tag) . '</a>';
}
$objTemplate->tags = $tags;
Expand Down

0 comments on commit 8bd3b59

Please sign in to comment.