ItemImageFrontend.php
2.45 KB
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
<?php
namespace Nextend\SmartSlider3\Renderable\Item\Image;
use Nextend\Framework\Parser\Common;
use Nextend\Framework\View\Html;
use Nextend\SmartSlider3\Renderable\Item\AbstractItemFrontend;
class ItemImageFrontend extends AbstractItemFrontend {
public function render() {
return $this->getHtml();
}
public function renderAdminTemplate() {
return $this->getHtml();
}
private function getHtml() {
$owner = $this->layer->getOwner();
$styles = array();
$linkStyles = array();
$size = (array)Common::parse($this->data->get('size', ''));
for ($i = 0; $i < 2; $i++) {
if (is_numeric($size[$i])) {
$size[$i] = $size[$i] . 'px';
}
}
if (!empty($size[0]) && $size[0] != 'auto') {
$styles[] = 'width:' . $size[0];
if ($this->hasLink() && substr($size[0], -1) == '%') {
$linkStyles[] = 'width:100%';
}
if (empty($size[1]) || $size[1] == 'auto') {
$styles[] = 'height:auto';
}
}
if (!empty($size[1]) && $size[1] != 'auto') {
if (empty($size[0]) || $size[0] == 'auto') {
$styles[] = 'width:auto';
}
$styles[] = 'height:' . $size[1];
}
$imageUrl = $this->data->get('image', '');
if (empty($imageUrl)) {
return '';
}
$image = $owner->fill($this->data->get('image', ''));
$imageAttributes = array(
"id" => $this->id,
"alt" => htmlspecialchars($owner->fill($this->data->get('alt', ''))),
"class" => $owner->fill($this->data->get('cssclass', ''))
);
if (!empty($styles)) {
$imageAttributes['style'] = implode(';', $styles);
}
$linkAttributes = array();
if (!empty($linkStyles)) {
$linkAttributes['style'] = implode(';', $linkStyles);
}
$title = htmlspecialchars($owner->fill($this->data->get('title', '')));
if (!empty($title)) {
$imageAttributes['title'] = $title;
}
$html = $owner->renderImage($this, $image, $imageAttributes);
$style = $owner->addStyle($this->data->get('style'), 'heading');
return Html::tag("div", array(
"class" => $style . ' n2-ss-item-image-content n2-ss-item-content n2-ow-all'
), $this->getLink($html, $linkAttributes));
}
}