forked from terminal42/contao-pageimage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModulePageImage.php
90 lines (67 loc) · 2.29 KB
/
ModulePageImage.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
87
88
89
90
<?php
/**
* pageimage Extension for Contao Open Source CMS
*
* @copyright Copyright (c) 2009-2014, terminal42 gmbh
* @author terminal42 gmbh <[email protected]>
* @license http://opensource.org/licenses/lgpl-3.0.html LGPL
* @link http://github.com/terminal42/contao-pageimage
*/
class ModulePageImage extends Module
{
/**
* Template
* @var string
*/
protected $strTemplate = 'mod_pageimage';
public function generate()
{
if (TL_MODE == 'BE')
{
$objTemplate = new BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### PAGE IMAGE ###';
$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();
}
$strBuffer = parent::generate();
if ($this->Template->src == '') {
return '';
}
return $strBuffer;
}
protected function compile()
{
if ($this->defineRoot) {
$objPage = \PageModel::findByPk($this->rootPage);
} else {
global $objPage;
}
if (null === $objPage) {
return;
}
$intOffset = (int) $this->levelOffset;
// Random image
if ($this->randomPageImage) {
$intOffset = -1;
}
$arrImage = PageImage::getOne($objPage, $intOffset, (bool) $this->inheritPageImage);
if (null === $arrImage) {
return;
}
$arrSize = deserialize($this->imgSize);
$arrImage['src'] = $this->getImage($arrImage['path'], $arrSize[0], $arrSize[1], $arrSize[2]);
$this->Template->setData($arrImage);
$picture = \Picture::create($arrImage['path'], $arrSize)->getTemplateData();
$picture['alt'] = specialchars($arrImage['alt']);
$this->Template->picture = $picture;
if (($imgSize = @getimagesize(TL_ROOT . '/' . rawurldecode($arrImage['src']))) !== false) {
$this->Template->size = ' ' . $imgSize[3];
}
// Add page information to template
global $objPage;
$this->Template->currentPage = $objPage->row();
}
}