Skip to content

Commit

Permalink
Added compatibility for Contao 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Nov 18, 2014
1 parent 3f80c3d commit 09a7a77
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 15 deletions.
21 changes: 12 additions & 9 deletions src/MadeYourDay/Contao/Module/Slider.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function compile()

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

if (!$file->isGdImage) {
if (!$file->isGdImage && !$file->isImage) {
continue;
}

Expand Down Expand Up @@ -248,7 +248,7 @@ protected function parseSlides($objSlides)
: \FilesModel::findByUuid($slide['singleSRC'])
) &&
($fileObject = new \File($file->path, true)) &&
$fileObject->isGdImage
($fileObject->isGdImage || $fileObject->isImage)
) {
$meta = $this->getMetaData($file->meta, $objPage->language);
$slide['image'] = new \stdClass;
Expand All @@ -264,6 +264,7 @@ protected function parseSlides($objSlides)
}

if ($slide['videoURL'] && empty($slide['image'])) {
$slide['image'] = new \stdClass;
if (preg_match(
'(^
https?:// # http or https
Expand All @@ -277,17 +278,19 @@ protected function parseSlides($objSlides)
html_entity_decode($slide['videoURL']), $matches)
) {
$video = $matches[1];
$slide['image'] = new \stdClass;
$slide['image']->src = '//img.youtube.com/vi/' . $video . '/0.jpg';
$slide['image']->imgSize = '';
$slide['image']->alt = '';
}
else {
$slide['image'] = new \stdClass;
// Grey dummy image
$slide['image']->src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAJCAMAAAAM9FwAAAAAA1BMVEXGxsbd/8BlAAAAFUlEQVR42s3BAQEAAACAkP6vdiO6AgCZAAG/wrlvAAAAAElFTkSuQmCC';
$slide['image']->imgSize = '';
$slide['image']->alt = '';
}
$slide['image']->imgSize = '';
$slide['image']->alt = '';
if (version_compare(VERSION, '3.4', '>=')) {
$slide['image']->picture = array(
'img' => array('src' => $slide['image']->src, 'srcset' => $slide['image']->src),
'sources' => array(),
);
}
}

Expand All @@ -298,7 +301,7 @@ protected function parseSlides($objSlides)
: \FilesModel::findByUuid($slide['backgroundImage'])
) &&
($fileObject = new \File($file->path, true)) &&
$fileObject->isGdImage
($fileObject->isGdImage || $fileObject->isImage)
) {
$meta = $this->getMetaData($file->meta, $objPage->language);
$slide['backgroundImage'] = new \stdClass;
Expand Down
26 changes: 23 additions & 3 deletions templates/rsts_default.html5
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
<?php foreach ($this->images as $image): ?>

<div data-rsts-type="image">
<img src="<?php echo $image->src ?>"<?php echo $image->imgSize ?> alt="<?php echo $image->alt ?>">
<?php if (version_compare(VERSION, '3.4', '<')): ?>
<img src="<?php echo $image->src ?>"<?php echo $image->imgSize ?> alt="<?php echo $image->alt ?>">
<?php else: ?>
<?php $this->insert('picture_default', $image->picture) ?>
<?php endif ?>
<?php if ($image->href): ?>
<a href="<?php echo $image->href ?>"><?php echo $GLOBALS['TL_LANG']['MSC']['more'] ?></a>
<?php endif ?>
Expand Down Expand Up @@ -46,12 +50,28 @@
<?php if (! empty($slide['videoURL'])): ?>

<div data-rsts-type="video" data-rsts-video="<?php echo $slide['videoURL'] ?>" <?php echo $attributes ?>>
<img src="<?php echo $slide['image']->src ?>" alt="<?php echo $slide['image']->alt ?>" <?php echo $imageAttributes ?>>
<?php if (version_compare(VERSION, '3.4', '<')): ?>
<img src="<?php echo $slide['image']->src ?>"<?php echo $slide['image']->imgSize ?> alt="<?php echo $slide['image']->alt ?>" <?php echo $imageAttributes ?>>
<?php else: ?>
<?php
ob_start();
$this->insert('picture_default', $slide['image']->picture);
echo preg_replace('(<img\\s)i', '<img ' . $imageAttributes . ' ', ob_get_clean());
?>
<?php endif ?>

<?php elseif (! empty($slide['image'])): ?>

<div data-rsts-type="image" <?php echo $attributes ?>>
<img src="<?php echo $slide['image']->src ?>"<?php echo $slide['image']->imgSize ?> alt="<?php echo $slide['image']->alt ?>" <?php echo $imageAttributes ?>>
<?php if (version_compare(VERSION, '3.4', '<')): ?>
<img src="<?php echo $slide['image']->src ?>"<?php echo $slide['image']->imgSize ?> alt="<?php echo $slide['image']->alt ?>" <?php echo $imageAttributes ?>>
<?php else: ?>
<?php
ob_start();
$this->insert('picture_default', $slide['image']->picture);
echo preg_replace('(<img\\s)i', '<img ' . $imageAttributes . ' ', ob_get_clean());
?>
<?php endif ?>
<?php if ($slide['image']->href): ?>
<a class="rsts-details" href="<?php echo $slide['image']->href ?>"><?php echo $GLOBALS['TL_LANG']['MSC']['more'] ?></a>
<?php endif ?>
Expand Down
26 changes: 23 additions & 3 deletions templates/rsts_default.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
<?php foreach ($this->images as $image): ?>

<div data-rsts-type="image">
<img src="<?php echo $image->src ?>"<?php echo $image->imgSize ?> alt="<?php echo $image->alt ?>" />
<?php if (version_compare(VERSION, '3.4', '<')): ?>
<img src="<?php echo $image->src ?>"<?php echo $image->imgSize ?> alt="<?php echo $image->alt ?>" />
<?php else: ?>
<?php $this->insert('picture_default', $image->picture) ?>
<?php endif ?>
<?php if ($image->href): ?>
<a href="<?php echo $image->href ?>"><?php echo $GLOBALS['TL_LANG']['MSC']['more'] ?></a>
<?php endif ?>
Expand Down Expand Up @@ -46,12 +50,28 @@
<?php if (! empty($slide['videoURL'])): ?>

<div data-rsts-type="video" data-rsts-video="<?php echo $slide['videoURL'] ?>" <?php echo $attributes ?>>
<img src="<?php echo $slide['image']->src ?>" alt="<?php echo $slide['image']->alt ?>" <?php echo $imageAttributes ?> />
<?php if (version_compare(VERSION, '3.4', '<')): ?>
<img src="<?php echo $slide['image']->src ?>"<?php echo $slide['image']->imgSize ?> alt="<?php echo $slide['image']->alt ?>" <?php echo $imageAttributes ?> />
<?php else: ?>
<?php
ob_start();
$this->insert('picture_default', $slide['image']->picture);
echo preg_replace('(<img\\s)i', '<img ' . $imageAttributes . ' ', ob_get_clean());
?>
<?php endif ?>

<?php elseif (! empty($slide['image'])): ?>

<div data-rsts-type="image" <?php echo $attributes ?>>
<img src="<?php echo $slide['image']->src ?>"<?php echo $slide['image']->imgSize ?> alt="<?php echo $slide['image']->alt ?>" <?php echo $imageAttributes ?> />
<?php if (version_compare(VERSION, '3.4', '<')): ?>
<img src="<?php echo $slide['image']->src ?>"<?php echo $slide['image']->imgSize ?> alt="<?php echo $slide['image']->alt ?>" <?php echo $imageAttributes ?> />
<?php else: ?>
<?php
ob_start();
$this->insert('picture_default', $slide['image']->picture);
echo preg_replace('(<img\\s)i', '<img ' . $imageAttributes . ' ', ob_get_clean());
?>
<?php endif ?>
<?php if ($slide['image']->href): ?>
<a class="rsts-details" href="<?php echo $slide['image']->href ?>"><?php echo $GLOBALS['TL_LANG']['MSC']['more'] ?></a>
<?php endif ?>
Expand Down

0 comments on commit 09a7a77

Please sign in to comment.