forked from terminal42/contao-pageimage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModulePageSlideshow.php
86 lines (64 loc) · 2.22 KB
/
ModulePageSlideshow.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* pageimage Extension for Contao Open Source CMS
*
* @copyright Copyright (c) 2018 Comolo GmbH
* @author Hendrik Obermayer <github.com/henobi>
* @license http://opensource.org/licenses/lgpl-3.0.html LGPL
* @link http://github.com/comolo/contao-pageimage
*/
class ModulePageSlideshow extends \Module
{
/**
* Template
* @var string
*/
protected $strTemplate = 'mod_page_slideshow';
public function generate()
{
if (TL_MODE == 'BE')
{
$objTemplate = new BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### PAGE SLIDESHOW ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = 'contao/main.php?do=modules&act=edit&id=' . $this->id;
return $objTemplate->parse();
}
return parent::generate();
}
protected function compile()
{
if ($this->defineRoot) {
$objPage = \PageModel::findByPk($this->rootPage);
} else {
global $objPage;
}
if (null === $objPage) {
return;
}
$arrImages = PageSlideshow::getMultiple($objPage);
if (null === $arrImages || !count($arrImages)) {
return;
}
$arrTemplateImages = [];
foreach ($arrImages as $arrImage) {
$image = [];
$arrSize = deserialize($this->imgSize);
$image['src'] = $this->getImage($arrImage['path'], $arrSize[0], $arrSize[1], $arrSize[2]);
$picture = \Picture::create($arrImage['path'], $arrSize)->getTemplateData();
$picture['alt'] = specialchars($arrImage['alt']);
$image['picture'] = $picture;
if (($imgSize = @getimagesize(TL_ROOT . '/' . rawurldecode($arrImage['src']))) !== false) {
$image['size'] = ' ' . $imgSize[3];
}
// Add to array
$arrTemplateImages[] = $image;
}
$this->Template->images = $arrTemplateImages;
// Add page information to template
global $objPage;
$this->Template->currentPage = $objPage->row();
}
}