Skip to content

Commit

Permalink
Bulk commit, fixes of deprecated functions and libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipSec committed Mar 4, 2024
1 parent 9fde5ad commit df0a7dd
Show file tree
Hide file tree
Showing 40 changed files with 280 additions and 134 deletions.
15 changes: 12 additions & 3 deletions classes/ContentHeadlineTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/

namespace Contao;
use Contao\System;
use Symfony\Component\HttpFoundation\Request;

class ContentHeadlineTags extends \ContentHeadline
{
Expand All @@ -18,8 +20,15 @@ class ContentHeadlineTags extends \ContentHeadline
*/
public function generate()
{
if (TL_MODE == 'FE') if ($this->tagsonly) if (!strlen(\TagHelper::decode(\Input::get('tag')))) return;
return parent::generate();
$isFrontend = System::getContainer()->get('contao.routing.scope_matcher')->isFrontendRequest(System::getContainer()->get('request_stack')->getCurrentRequest() ?? Request::create(''));
if ($isFrontend) {
if ($this->tagsonly) {
if (!strlen(\TagHelper::decode(\Input::get('tag')))) {
return;
}
}
}

return parent::generate();
}
}

11 changes: 6 additions & 5 deletions classes/TagField.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace Contao;
use Contao\StringUtil;

/**
* Contao Open Source CMS - tags extension
Expand Down Expand Up @@ -28,7 +29,7 @@ protected function saveTags($value)
$this->import('Database');
$this->Database->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?")
->execute($this->table, $this->activeRecord->id);
$tags = array_filter(trimsplit(",", $value), 'strlen');
$tags = array_filter(StringUtil::trimsplit(",", $value), 'strlen');
foreach ($tags as $tag)
{
$this->Database->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")
Expand Down Expand Up @@ -70,7 +71,7 @@ public function __set($strKey, $varValue)
$this->strTagTable = $varValue;
break;
case 'value':
$this->varValue = implode(",", array_filter(trimsplit(",", $varValue), 'strlen'));
$this->varValue = implode(",", array_filter(StringUtil::trimsplit(",", $varValue), 'strlen'));
break;
case 'maxtags':
$this->intMaxTags = $varValue;
Expand Down Expand Up @@ -129,7 +130,7 @@ public function generate()
$this->strName,
$this->strId,
(strlen($this->strClass) ? ' ' . $this->strClass : ''),
specialchars($value),
StringUtil::specialchars($value),
$this->getAttributes());
}

Expand All @@ -138,8 +139,8 @@ public function generate()
*/
public function validate()
{
$varInput = $this->validator(deserialize($this->getPost($this->strName)));
$this->saveTags(implode(",", array_filter(trimsplit(",", $varInput), 'strlen')));
$varInput = $this->validator(StringUtil::deserialize($this->getPost($this->strName)));
$this->saveTags(implode(",", array_filter(StringUtil::trimsplit(",", $varInput), 'strlen')));
parent::validate();
}
}
16 changes: 9 additions & 7 deletions classes/TagFieldMemberFrontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/

namespace Contao;
use Contao\StringUtil;
use Contao\ArrayUtil;

/**
* Class TagFieldFrontend
Expand All @@ -18,7 +20,7 @@
* @author Helmut Schottmüller <https://github.com/hschottm/tags_members>
* @package Controller
*/
class TagFieldMemberFrontend extends \FormTextField
class TagFieldMemberFrontend extends \FormText
{
protected $blnSubmitInput = true;
protected $strTagTable = "";
Expand All @@ -37,7 +39,7 @@ protected function saveTags($value)
$this->import('Database');
$this->Database->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?")
->execute('tl_member', $this->User->id);
$tags = array_filter(trimsplit(",", $value), 'strlen');
$tags = array_filter(StringUtil::trimsplit(",", $value), 'strlen');
foreach ($tags as $tag)
{
$this->Database->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")
Expand Down Expand Up @@ -75,7 +77,7 @@ public function __set($strKey, $varValue)
$this->strTagTable = $varValue;
break;
case 'value':
$this->varValue = implode(",", array_filter(trimsplit(",", $varValue), 'strlen'));
$this->varValue = implode(",", array_filter(StringUtil::trimsplit(",", $varValue), 'strlen'));
break;
case 'maxtags':
$this->intMaxTags = $varValue;
Expand Down Expand Up @@ -123,7 +125,7 @@ public function generate()
*/
if (is_array($GLOBALS['TL_JAVASCRIPT']))
{
array_insert($GLOBALS['TL_JAVASCRIPT'], 1, 'system/modules/tags/assets/tag.js');
ArrayUtil::arrayInsert($GLOBALS['TL_JAVASCRIPT'], 1, 'system/modules/tags/assets/tag.js');
}
else
{
Expand All @@ -147,7 +149,7 @@ public function generate()
$this->strId,
($this->hideInput ? ' password' : ''),
(($this->strClass != '') ? ' ' . $this->strClass : ''),
specialchars($this->value),
StringUtil::specialchars($this->value),
$this->getAttributes(),
$this->strTagEnding) . $this->addSubmit();
}
Expand All @@ -157,8 +159,8 @@ public function generate()
*/
public function validate()
{
$varInput = $this->validator(deserialize($this->getPost($this->strName)));
$this->saveTags(implode(",", array_filter(trimsplit(",", $varInput), 'strlen')));
$varInput = $this->validator(StringUtil::deserialize($this->getPost($this->strName)));
$this->saveTags(implode(",", array_filter(StringUtil::trimsplit(",", $varInput), 'strlen')));
parent::validate();
}
}
1 change: 1 addition & 0 deletions classes/TagHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace Contao;
use Contao\StringUtil;

/**
* Contao Open Source CMS - tags extension
Expand Down
20 changes: 11 additions & 9 deletions classes/TagList.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

namespace Contao;

use Contao\System;
use Symfony\Component\HttpFoundation\Request;
use Contao\StringUtil;
/**
* Contao Open Source CMS - tags extension
*
Expand Down Expand Up @@ -36,8 +38,8 @@ public function getRelatedTagList($for_tags, $blnExcludeUnpublishedItems = true)

$tagtable = (strlen($this->strTagTable)) ? $this->strTagTable : "tl_tag";
$tagfield = (strlen($this->strTagField)) ? $this->strTagField : "tag";

if (TL_MODE == 'BE')
$isBackend = System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest(System::getContainer ()->get('request_stack')->getCurrentRequest() ?? Request::create(''));
if ($isBackend)
{
$blnExcludeUnpublishedItems = false;
}
Expand Down Expand Up @@ -197,8 +199,8 @@ public function getTagList($blnExcludeUnpublishedItems = true)
{
$tagtable = (strlen($this->strTagTable)) ? $this->strTagTable : "tl_tag";
$tagfield = (strlen($this->strTagField)) ? $this->strTagField : "tag";

if (TL_MODE == 'BE')
$isBackend = System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest(System::getContainer ()->get('request_stack')->getCurrentRequest() ?? Request::create(''));
if ($isBackend)
{
$blnExcludeUnpublishedItems = false;
}
Expand Down Expand Up @@ -365,17 +367,17 @@ protected function getArticlesForPages()
if (count($this->arrPages))
{
$time = time();

$hasBackendUser = System::getContainer()->get('contao.security.token_checker')->hasBackendUser();
// Get published articles
$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")
$objArticles = $this->Database->prepare("SELECT id, title, alias, inColumn, cssID FROM tl_article WHERE inColumn = ? AND pid IN (" . $pids . ") " . (!$hasBackendUser ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND published=1" : "") . " ORDER BY sorting")
->execute($this->inColumn, $time, $time);
}
else
{
$objArticles = $this->Database->prepare("SELECT id, title, alias, inColumn, cssID FROM tl_article WHERE pid IN (" . $pids . ") " . (!BE_USER_LOGGED_IN ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND published=1" : "") . " ORDER BY sorting")
$objArticles = $this->Database->prepare("SELECT id, title, alias, inColumn, cssID FROM tl_article WHERE pid IN (" . $pids . ") " . (!$hasBackendUser ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND published=1" : "") . " ORDER BY sorting")
->execute($time, $time);
}
if ($objArticles->numRows < 1)
Expand All @@ -391,7 +393,7 @@ protected function getArticlesForPages()
continue;
}

$cssID = deserialize($objArticles->cssID, true);
$cssID = StringUtil::deserialize($objArticles->cssID, true);
$alias = strlen($objArticles->alias) ? $objArticles->alias : $objArticles->title;

array_push($this->arrArticles, $objArticles->id);
Expand Down
16 changes: 11 additions & 5 deletions classes/TagListArticles.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace Contao;
use Contao\System;
use Symfony\Component\HttpFoundation\Request;

/**
* Class TagListArticles
Expand All @@ -20,16 +22,18 @@ public function getRelatedTagList($for_tags, $blnExcludeUnpublishedItems = true)
{
if (!is_array($for_tags)) return array();
if (!count($this->arrArticles)) return array();
$isBackend = System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest(System::getContainer ()->get('request_stack')->getCurrentRequest() ?? Request::create(''));
$hasBackendUser = System::getContainer()->get('contao.security.token_checker')->hasBackendUser();

if (TL_MODE == 'BE')
if ($isBackend)
{
$blnExcludeUnpublishedItems = false;
}

$ids = array();
for ($i = 0; $i < count($for_tags); $i++)
{
$arr = $this->Database->prepare("SELECT DISTINCT tl_tag.tid FROM tl_tag, tl_article WHERE tl_tag.tid = tl_article.id AND from_table = ? AND tl_tag.tid IN (" . implode(',', $this->arrArticles) . ") AND tag = ?" . (!BE_USER_LOGGED_IN ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND published=1" : "") . " ORDER BY tl_tag.tid ASC")
$arr = $this->Database->prepare("SELECT DISTINCT tl_tag.tid FROM tl_tag, tl_article WHERE tl_tag.tid = tl_article.id AND from_table = ? AND tl_tag.tid IN (" . implode(',', $this->arrArticles) . ") AND tag = ?" . (!$hasBackendUser ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND published=1" : "") . " ORDER BY tl_tag.tid ASC")
->execute(array('tl_article', $for_tags[$i], time(), time()))
->fetchEach('tid');
if ($i == 0)
Expand All @@ -45,7 +49,8 @@ public function getRelatedTagList($for_tags, $blnExcludeUnpublishedItems = true)
$arrCloudTags = array();
if (count($ids))
{
$objTags = $this->Database->prepare("SELECT tag, COUNT(tag) as count FROM tl_tag, tl_article WHERE tl_tag.tid = tl_article.id AND from_table = ?" . (!BE_USER_LOGGED_IN ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND published=1" : "") . " AND tl_tag.tid IN (" . implode(",", $ids) . ") GROUP BY tag ORDER BY tag ASC")
$hasBackendUser = System::getContainer()->get('contao.security.token_checker')->hasBackendUser();
$objTags = $this->Database->prepare("SELECT tag, COUNT(tag) as count FROM tl_tag, tl_article WHERE tl_tag.tid = tl_article.id AND from_table = ?" . (!$hasBackendUser ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND published=1" : "") . " AND tl_tag.tid IN (" . implode(",", $ids) . ") GROUP BY tag ORDER BY tag ASC")
->execute('tl_article', time(), time());
$list = "";
$tags = array();
Expand All @@ -55,7 +60,7 @@ public function getRelatedTagList($for_tags, $blnExcludeUnpublishedItems = true)
{
if (!in_array($objTags->tag, $for_tags))
{
$count = count($this->Database->prepare("SELECT tl_tag.tid FROM tl_tag, tl_article WHERE tl_tag.tid = tl_article.id AND tag = ?" . (!BE_USER_LOGGED_IN ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND published=1" : "") . " AND from_table = ? AND tl_tag.tid IN (" . implode(",", $ids) . ")")
$count = count($this->Database->prepare("SELECT tl_tag.tid FROM tl_tag, tl_article WHERE tl_tag.tid = tl_article.id AND tag = ?" . (!$hasBackendUser ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND published=1" : "") . " AND from_table = ? AND tl_tag.tid IN (" . implode(",", $ids) . ")")
->execute($objTags->tag, time(), time(), 'tl_article')
->fetchAllAssoc());
array_push($tags, array('tag_name' => $objTags->tag, 'tag_count' => $count));
Expand All @@ -72,11 +77,12 @@ public function getRelatedTagList($for_tags, $blnExcludeUnpublishedItems = true)

public function getTagList($blnExcludeUnpublishedItems = true)
{
$hasBackendUser = System::getContainer()->get('contao.security.token_checker')->hasBackendUser();
if (count($this->arrCloudTags) == 0)
{
if (count($this->arrArticles))
{
$objTags = $this->Database->prepare("SELECT tag, COUNT(tag) as count FROM tl_tag, tl_article WHERE tl_tag.tid = tl_article.id AND from_table = ?" . (!BE_USER_LOGGED_IN ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND published=1" : "") . " AND tl_tag.tid IN (" . implode(',', $this->arrArticles) . ") GROUP BY tag ORDER BY tag ASC")
$objTags = $this->Database->prepare("SELECT tag, COUNT(tag) as count FROM tl_tag, tl_article WHERE tl_tag.tid = tl_article.id AND from_table = ?" . (!$hasBackendUser ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND published=1" : "") . " AND tl_tag.tid IN (" . implode(',', $this->arrArticles) . ") GROUP BY tag ORDER BY tag ASC")
->execute('tl_article', time(), time());
$list = "";
$tags = array();
Expand Down
20 changes: 13 additions & 7 deletions classes/TagListContentElements.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace Contao;
use Contao\System;
use Symfony\Component\HttpFoundation\Request;

/**
* Class TagListContentElements
Expand All @@ -18,18 +20,20 @@ class TagListContentElements extends TagList

public function getRelatedTagList($for_tags, $blnExcludeUnpublishedItems = true)
{
$isBackend = System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest(System::getContainer ()->get('request_stack')->getCurrentRequest() ?? Request::create(''));
if (!is_array($for_tags)) return array();
if (!count($this->arrContentElements)) return array();

if (TL_MODE == 'BE')
if ($isBackend)
{
$blnExcludeUnpublishedItems = false;
}
$hasBackendUser = System::getContainer()->get('contao.security.token_checker')->hasBackendUser();

$ids = array();
for ($i = 0; $i < count($for_tags); $i++)
{
$arr = $this->Database->prepare("SELECT DISTINCT tl_tag.tid FROM tl_tag, tl_content WHERE tl_tag.tid = tl_content.id AND from_table = ? AND tl_tag.tid IN (" . implode(',', $this->arrContentElements) . ") AND tag = ?" . (!BE_USER_LOGGED_IN ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND invisible<>1" : "") . " ORDER BY tl_tag.tid ASC")
$arr = $this->Database->prepare("SELECT DISTINCT tl_tag.tid FROM tl_tag, tl_content WHERE tl_tag.tid = tl_content.id AND from_table = ? AND tl_tag.tid IN (" . implode(',', $this->arrContentElements) . ") AND tag = ?" . (!$hasBackendUser ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND invisible<>1" : "") . " ORDER BY tl_tag.tid ASC")
->execute(array('tl_content', $for_tags[$i], time(), time()))
->fetchEach('tid');
if ($i == 0)
Expand All @@ -45,7 +49,7 @@ public function getRelatedTagList($for_tags, $blnExcludeUnpublishedItems = true)
$arrCloudTags = array();
if (count($ids))
{
$objTags = $this->Database->prepare("SELECT tag, COUNT(tag) as count FROM tl_tag, tl_content WHERE tl_tag.tid = tl_content.id AND from_table = ?" . (!BE_USER_LOGGED_IN ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND invisible<>1" : "") . " AND tl_tag.tid IN (" . implode(",", $ids) . ") GROUP BY tag ORDER BY tag ASC")
$objTags = $this->Database->prepare("SELECT tag, COUNT(tag) as count FROM tl_tag, tl_content WHERE tl_tag.tid = tl_content.id AND from_table = ?" . (!$hasBackendUser ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND invisible<>1" : "") . " AND tl_tag.tid IN (" . implode(",", $ids) . ") GROUP BY tag ORDER BY tag ASC")
->execute('tl_content', time(), time());
$list = "";
$tags = array();
Expand All @@ -55,7 +59,7 @@ public function getRelatedTagList($for_tags, $blnExcludeUnpublishedItems = true)
{
if (!in_array($objTags->tag, $for_tags))
{
$count = count($this->Database->prepare("SELECT tl_tag.tid FROM tl_tag, tl_content WHERE tl_tag.tid = tl_content.id AND tag = ?" . (!BE_USER_LOGGED_IN ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND invisible<>1" : "") . " AND from_table = ? AND tl_tag.tid IN (" . implode(",", $ids) . ")")
$count = count($this->Database->prepare("SELECT tl_tag.tid FROM tl_tag, tl_content WHERE tl_tag.tid = tl_content.id AND tag = ?" . (!$hasBackendUser ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND invisible<>1" : "") . " AND from_table = ? AND tl_tag.tid IN (" . implode(",", $ids) . ")")
->execute($objTags->tag, 'tl_content', time(), time())
->fetchAllAssoc());
array_push($tags, array('tag_name' => $objTags->tag, 'tag_count' => $count));
Expand All @@ -72,11 +76,12 @@ public function getRelatedTagList($for_tags, $blnExcludeUnpublishedItems = true)

public function getTagList($blnExcludeUnpublishedItems = true)
{
$hasBackendUser = System::getContainer()->get('contao.security.token_checker')->hasBackendUser();
if (count($this->arrCloudTags) == 0)
{
if (count($this->arrContentElements))
{
$objTags = $this->Database->prepare("SELECT tag, COUNT(tag) as count FROM tl_tag, tl_content WHERE tl_tag.tid = tl_content.id AND from_table = ?" . (!BE_USER_LOGGED_IN ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND invisible<>1" : "") . " AND tl_tag.tid IN (" . implode(',', $this->arrContentElements) . ") GROUP BY tag ORDER BY tag ASC")
$objTags = $this->Database->prepare("SELECT tag, COUNT(tag) as count FROM tl_tag, tl_content WHERE tl_tag.tid = tl_content.id AND from_table = ?" . (!$hasBackendUser ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND invisible<>1" : "") . " AND tl_tag.tid IN (" . implode(',', $this->arrContentElements) . ") GROUP BY tag ORDER BY tag ASC")
->execute('tl_content', time(), time());
$list = "";
$tags = array();
Expand Down Expand Up @@ -112,13 +117,14 @@ protected function getRelevantPages($page_id)

protected function getContentElementsForPages()
{
$hasBackendUser = System::getContainer()->get('contao.security.token_checker')->hasBackendUser();
$this->arrContentElements = array();
if (count($this->arrPages))
{
$time = time();
$arrArticles = $this->Database->prepare("SELECT id FROM tl_article WHERE pid IN (" . implode(',', $this->arrPages) . ") " . (!BE_USER_LOGGED_IN ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND published=1" : "") . " ORDER BY sorting")
$arrArticles = $this->Database->prepare("SELECT id FROM tl_article WHERE pid IN (" . implode(',', $this->arrPages) . ") " . (!$hasBackendUser ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND published=1" : "") . " ORDER BY sorting")
->execute($time, $time)->fetchEach('id');
$this->arrContentElements = $this->Database->prepare("SELECT id FROM tl_content WHERE pid IN (" . implode(',', $arrArticles) . ") " . (!BE_USER_LOGGED_IN ? " AND invisible<>1" : "") . " ORDER BY sorting")
$this->arrContentElements = $this->Database->prepare("SELECT id FROM tl_content WHERE pid IN (" . implode(',', $arrArticles) . ") " . (!$hasBackendUser ? " AND invisible<>1" : "") . " ORDER BY sorting")
->execute()->fetchEach('id');
}
}
Expand Down
Loading

0 comments on commit df0a7dd

Please sign in to comment.