Skip to content

Commit

Permalink
Update Contao to version 4.13 and 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Aug 7, 2022
1 parent ee3fe89 commit dca0b07
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 142 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"source":"https://github.com/madeyourday/contao-rocksolid-slider"
},
"require":{
"php":">=7.2",
"contao/core-bundle":"^4.9"
"php":">=7.4",
"contao/core-bundle":"^4.13 || ^5.0"
},
"require-dev": {
"contao/manager-plugin": "^2.0"
Expand Down
10 changes: 7 additions & 3 deletions src/Model/ContentModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@

namespace MadeYourDay\RockSolidSlider\Model;

use Contao\ContentModel as ContaoContentModel;
use Contao\Model\Collection;
use Contao\System;

/**
* Content Model Extension
*
* @author Martin Auswöger <[email protected]>
*/
class ContentModel extends \ContentModel
class ContentModel extends ContaoContentModel
{
/**
* Find all published content elements by their parent IDs and parent table
Expand All @@ -22,15 +26,15 @@ class ContentModel extends \ContentModel
* @param string $parentTable The parent table name
* @param array $options An optional options array
*
* @return \Model\Collection|null A collection of models or null if there are no content elements
* @return Collection|null A collection of models or null if there are no content elements
*/
public static function findPublishedByPidsAndTable(array $parentIds, $parentTable, array $options = array())
{
$table = static::$strTable;

$columns = array("$table.pid IN(" . implode(',', array_map('intval', $parentIds)) . ") AND ptable=?");

if (!BE_USER_LOGGED_IN) {
if (!System::getContainer()->get('contao.security.token_checker')->isPreviewMode()) {
$columns[] = "$table.invisible=''";
}

Expand Down
10 changes: 7 additions & 3 deletions src/Model/SlideModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@

namespace MadeYourDay\RockSolidSlider\Model;

use Contao\Date;
use Contao\Model;
use Contao\System;

/**
* Slider Model
*
* @author Martin Auswöger <[email protected]>
*/
class SlideModel extends \Model
class SlideModel extends Model
{
/**
* @var string Table name
Expand All @@ -34,8 +38,8 @@ public static function findPublishedByPid($id, $limit = 0, array $options = arra
$table = static::$strTable;
$columns = array("$table.pid=?");

if (!empty($options['ignoreFePreview']) || !BE_USER_LOGGED_IN) {
$time = \Date::floorToMinute();
if (!empty($options['ignoreFePreview']) || !System::getContainer()->get('contao.security.token_checker')->isPreviewMode()) {
$time = Date::floorToMinute();
$columns[] = "($table.start='' OR $table.start<$time) AND ($table.stop='' OR $table.stop>$time) AND $table.published=1";
}

Expand Down
4 changes: 3 additions & 1 deletion src/Model/SliderModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

namespace MadeYourDay\RockSolidSlider\Model;

use Contao\Model;

/**
* Slider Model
*
* @author Martin Auswöger <[email protected]>
*/
class SliderModel extends \Model
class SliderModel extends Model
{
/**
* @var string Table name
Expand Down
92 changes: 38 additions & 54 deletions src/Module/Slider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,25 @@

namespace MadeYourDay\RockSolidSlider\Module;

use Contao\BackendTemplate;
use Contao\File;
use Contao\FilesModel;
use Contao\Model\Collection;
use Contao\Module;
use Contao\ModuleModel;
use Contao\StringUtil;
use Contao\System;
use MadeYourDay\RockSolidSlider\Model\SlideModel;
use MadeYourDay\RockSolidSlider\Model\SliderModel;
use MadeYourDay\RockSolidSlider\Model\ContentModel;
use Symfony\Component\HttpFoundation\Request;

/**
* Slider Frontend Module
*
* @author Martin Auswöger <[email protected]>
*/
class Slider extends \Module
class Slider extends Module
{
/**
* @var string Template
Expand All @@ -30,19 +39,19 @@ class Slider extends \Module
public function generate()
{
// Display a wildcard in the back end
if (TL_MODE === 'BE') {
$template = new \BackendTemplate('be_wildcard');
if (System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest(System::getContainer()->get('request_stack')->getCurrentRequest() ?? Request::create(''))) {
$template = new BackendTemplate('be_wildcard');

$template->wildcard = '### ROCKSOLID SLIDER ###';
$template->title = $this->name;
$template->id = $this->id;
$template->link = $this->name;
$template->href = 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $this->id;
$template->href = 'contao?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $this->id;

if ($this->objModel->rsts_id && ($slider = SliderModel::findByPk($this->objModel->rsts_id)) !== null) {
$template->id = $slider->id;
$template->link = $slider->name;
$template->href = 'contao/main.php?do=rocksolid_slider&amp;table=tl_rocksolid_slide&amp;id=' . $slider->id;
$template->href = 'contao?do=rocksolid_slider&amp;table=tl_rocksolid_slide&amp;id=' . $slider->id;
}

return $template->parse();
Expand All @@ -51,7 +60,7 @@ public function generate()
if (
$this->rsts_import_settings
&& $this->rsts_import_settings_from
&& ($settingsModule = \ModuleModel::findByPk($this->rsts_import_settings_from))
&& ($settingsModule = ModuleModel::findByPk($this->rsts_import_settings_from))
) {
$this->objModel->imgSize = $settingsModule->imgSize;
$this->objModel->fullsize = $settingsModule->fullsize;
Expand All @@ -78,7 +87,7 @@ public function generate()
}
else if ($this->rsts_content_type === 'rsts_images' || !$this->rsts_id) {

$this->multiSRC = deserialize($this->multiSRC);
$this->multiSRC = StringUtil::deserialize($this->multiSRC);
if (!is_array($this->multiSRC) || !count($this->multiSRC)) {
// Return if there are no images
return '';
Expand All @@ -95,18 +104,17 @@ public function generate()
}

if ($this->slider->type === 'image') {
$this->multiSRC = deserialize($this->slider->multiSRC);
$this->orderSRC = $this->slider->orderSRC;
$this->multiSRC = StringUtil::deserialize($this->slider->multiSRC);
}

}

$this->files = \FilesModel::findMultipleByUuids($this->multiSRC);
$this->files = FilesModel::findMultipleByUuids($this->multiSRC);

if (
$this->rsts_import_settings
&& $this->rsts_import_settings_from
&& ($settingsModule = \ModuleModel::findByPk($this->rsts_import_settings_from))
&& ($settingsModule = ModuleModel::findByPk($this->rsts_import_settings_from))
) {
$exclude = array('rsts_import_settings', 'rsts_import_settings_from', 'rsts_content_type', 'rsts_id');
$include = array('imgSize', 'fullsize');
Expand All @@ -118,7 +126,7 @@ public function generate()
$this->arrData[$key] = $value;
}
}
$settingsCssId = \StringUtil::deserialize($settingsModule->cssID, true);
$settingsCssId = StringUtil::deserialize($settingsModule->cssID, true);
if (!empty($settingsCssId[1])) {
$this->arrData['cssID'][1] = (
empty($this->arrData['cssID'][1]) ? '' : $this->arrData['cssID'][1] . ' '
Expand Down Expand Up @@ -153,7 +161,7 @@ protected function compile()
$filesExpaned[] = $files->current();
}
else {
$subFiles = \FilesModel::findByPid($files->uuid);
$subFiles = FilesModel::findByPid($files->uuid);
while ($subFiles && $subFiles->next()) {
if ($subFiles->type === 'file'){
$filesExpaned[] = $subFiles->current();
Expand All @@ -165,11 +173,11 @@ protected function compile()
foreach ($filesExpaned as $files) {

// Continue if the files has been processed or does not exist
if (isset($images[$files->path]) || ! file_exists(TL_ROOT . '/' . $files->path)) {
if (isset($images[$files->path]) || ! file_exists(System::getContainer()->getParameter('kernel.project_dir') . '/' . $files->path)) {
continue;
}

$file = new \File($files->path, true);
$file = new File($files->path, true);

if (!$file->isGdImage && !$file->isImage) {
continue;
Expand All @@ -193,36 +201,12 @@ protected function compile()

}

if ($this->orderSRC) {
// Turn the order string into an array and remove all values
$order = deserialize($this->orderSRC);
if (!$order || !is_array($order)) {
$order = array();
}
$order = array_flip($order);
$order = array_map(function(){}, $order);

// Move the matching elements to their position in $order
foreach ($images as $k => $v) {
if (array_key_exists($v['uuid'], $order)) {
$order[$v['uuid']] = $v;
unset($images[$k]);
}
}

$order = array_merge($order, array_values($images));

// Remove empty (unreplaced) entries
$images = array_filter($order);
unset($order);
}

$images = array_values($images);

foreach ($images as $key => $image) {
$newImage = new \stdClass();
$image['size'] = isset($this->imgSize) ? $this->imgSize : $this->size;
$this->addImageToTemplate($newImage, $image, null, substr(md5('mod_rocksolid_slider_' . $this->id), 0, 6), \FilesModel::findByPk($image['id']));
$this->addImageToTemplate($newImage, $image, null, substr(md5('mod_rocksolid_slider_' . $this->id), 0, 6), FilesModel::findByPk($image['id']));
if ($this->rsts_navType === 'thumbs') {
$newImage->thumb = new \stdClass;
$image['size'] = $this->rsts_thumbs_imgSize;
Expand Down Expand Up @@ -402,15 +386,15 @@ protected function compile()
$GLOBALS['TL_JAVASCRIPT'][] = $assetsDir . '/js/rocksolid-slider.min.js|static';
$GLOBALS['TL_CSS'][] = $assetsDir . '/css/rocksolid-slider.min.css||static';
$skinPath = $assetsDir . '/css/' . (empty($this->arrData['rsts_skin']) ? 'default' : $this->arrData['rsts_skin']) . '-skin.min.css';
if (file_exists(\System::getContainer()->getParameter('contao.web_dir') . '/' . $skinPath)) {
if (file_exists(System::getContainer()->getParameter('contao.web_dir') . '/' . $skinPath)) {
$GLOBALS['TL_CSS'][] = $skinPath . '||static';
}
}

/**
* Parse slides
*
* @param \Model\Collection $objSlides slides retrieved from the database
* @param Collection $objSlides slides retrieved from the database
* @return array parsed slides
*/
protected function parseSlides($objSlides)
Expand All @@ -437,8 +421,8 @@ protected function parseSlides($objSlides)
if (
in_array($slide['type'], array('image', 'video')) &&
trim($slide['singleSRC']) &&
($file = \FilesModel::findByUuid($slide['singleSRC'])) &&
($fileObject = new \File($file->path, true)) &&
($file = FilesModel::findByUuid($slide['singleSRC'])) &&
($fileObject = new File($file->path, true)) &&
($fileObject->isGdImage || $fileObject->isImage)
) {
$meta = $this->getMetaData($file->meta, $objPage->language);
Expand Down Expand Up @@ -491,8 +475,8 @@ protected function parseSlides($objSlides)
}

if ($slide['type'] === 'video' && $slide['videos']) {
$videoFiles = deserialize($slide['videos'], true);
$videoFiles = \FilesModel::findMultipleByUuids($videoFiles);
$videoFiles = StringUtil::deserialize($slide['videos'], true);
$videoFiles = FilesModel::findMultipleByUuids($videoFiles);
$videos = array();
foreach ($videoFiles as $file) {
$videos[] = $file;
Expand All @@ -505,8 +489,8 @@ protected function parseSlides($objSlides)

if (
trim($slide['backgroundImage']) &&
($file = \FilesModel::findByUuid($slide['backgroundImage'])) &&
($fileObject = new \File($file->path, true)) &&
($file = FilesModel::findByUuid($slide['backgroundImage'])) &&
($fileObject = new File($file->path, true)) &&
($fileObject->isGdImage || $fileObject->isImage)
) {
$meta = $this->getMetaData($file->meta, $objPage->language);
Expand All @@ -527,8 +511,8 @@ protected function parseSlides($objSlides)
}

if ($slide['backgroundVideos']) {
$videoFiles = deserialize($slide['backgroundVideos'], true);
$videoFiles = \FilesModel::findMultipleByUuids($videoFiles);
$videoFiles = StringUtil::deserialize($slide['backgroundVideos'], true);
$videoFiles = FilesModel::findMultipleByUuids($videoFiles);
$videos = array();
foreach ($videoFiles as $file) {
$videos[] = $file;
Expand All @@ -540,8 +524,8 @@ protected function parseSlides($objSlides)
$slide['thumb'] = new \stdClass;
if (
trim($slide['thumbImage']) &&
($file = \FilesModel::findByUuid($slide['thumbImage'])) &&
($fileObject = new \File($file->path, true)) &&
($file = FilesModel::findByUuid($slide['thumbImage'])) &&
($fileObject = new File($file->path, true)) &&
($fileObject->isGdImage || $fileObject->isImage)
) {
$this->addImageToTemplate($slide['thumb'], array(
Expand All @@ -554,8 +538,8 @@ protected function parseSlides($objSlides)
elseif (
in_array($slide['type'], array('image', 'video')) &&
trim($slide['singleSRC']) &&
($file = \FilesModel::findByUuid($slide['singleSRC'])) &&
($fileObject = new \File($file->path, true)) &&
($file = FilesModel::findByUuid($slide['singleSRC'])) &&
($fileObject = new File($file->path, true)) &&
($fileObject->isGdImage || $fileObject->isImage)
) {
$this->addImageToTemplate($slide['thumb'], array(
Expand Down
7 changes: 5 additions & 2 deletions src/Module/SliderEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@

namespace MadeYourDay\RockSolidSlider\Module;

use Contao\ModuleEventlist;
use Contao\StringUtil;

/**
* Slider Events Module
*
* @author Martin Auswöger <[email protected]>
*/
class SliderEvents extends \ModuleEventlist
class SliderEvents extends ModuleEventlist
{
const TEMPLATE_SEPARATOR = '<!-- %%%___||| RockSolid Slider Event |||___%%% -->';

Expand All @@ -24,7 +27,7 @@ class SliderEvents extends \ModuleEventlist
*/
public function getEventItems()
{
$this->cal_calendar = $this->sortOutProtected(deserialize($this->cal_calendar, true));
$this->cal_calendar = $this->sortOutProtected(StringUtil::deserialize($this->cal_calendar, true));

// Return if there are no calendars
if (!is_array($this->cal_calendar) || empty($this->cal_calendar))
Expand Down
7 changes: 5 additions & 2 deletions src/Module/SliderNews.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@

namespace MadeYourDay\RockSolidSlider\Module;

use Contao\ModuleNewsList;
use Contao\StringUtil;

/**
* Slider News Module
*
* @author Martin Auswöger <[email protected]>
*/
class SliderNews extends \ModuleNewsList
class SliderNews extends ModuleNewsList
{
/**
* Get an array of news articles (HTML output) generated by Contao\ModuleNewsList
Expand All @@ -22,7 +25,7 @@ class SliderNews extends \ModuleNewsList
*/
public function getNewsArticles()
{
$this->news_archives = $this->sortOutProtected(deserialize($this->news_archives));
$this->news_archives = $this->sortOutProtected(StringUtil::deserialize($this->news_archives));

// Return if there are no archives
if (!is_array($this->news_archives) || !count($this->news_archives)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'icon' => 'bundles/rocksolidslider/img/icon.png',
);

array_insert($GLOBALS['FE_MOD'], 2, array(
Contao\ArrayUtil::arrayInsert($GLOBALS['FE_MOD'], 2, array(
'miscellaneous' => array(
'rocksolid_slider' => 'MadeYourDay\\RockSolidSlider\\Module\\Slider',
)
Expand Down
Loading

0 comments on commit dca0b07

Please sign in to comment.