AbstractRenderable.php
3.88 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
namespace Nextend\SmartSlider3\Renderable;
use Nextend\Framework\Font\FontParser;
use Nextend\Framework\Font\FontRenderer;
use Nextend\Framework\Style\StyleParser;
use Nextend\Framework\Style\StyleRenderer;
use Nextend\SmartSlider3\Slider\FeatureManager;
abstract class AbstractRenderable {
public $isAdmin = false;
public $less = array();
public $css = array();
public $cssDevice = array(
'all' => array(),
'desktoplandscape' => array(),
'desktopportrait' => array(),
'tabletlandscape' => array(),
'tabletportrait' => array(),
'mobilelandscape' => array(),
'mobileportrait' => array(),
);
public $elementId = '';
public $fontSize = 16;
protected $images = array();
private $fontCache = array();
private $styleCache = array();
public $initCallbacks = array();
public $addedScriptResources = array();
/**
* @var FeatureManager
*/
public $features;
public function addLess($file, $context) {
$this->less[$file] = $context;
}
public function addCSS($css) {
$this->css[] = $css;
}
public function addDeviceCSS($device, $css) {
$this->cssDevice[$device][] = $css;
}
public function getSelector() {
return 'div#' . $this->elementId . ' ';
}
private function _addFontCache($font, $mode, $pre, $fontSize) {
$cacheKey = md5($font . $mode . $pre . $fontSize);
if (!isset($this->fontCache[$cacheKey])) {
$fontData = FontRenderer::render($font, $mode, $pre, $fontSize);
if ($fontData) {
$this->addCSS($fontData[1]);
$this->fontCache[$cacheKey] = $fontData[0];
} else {
$this->fontCache[$cacheKey] = '';
}
}
return $this->fontCache[$cacheKey];
}
public function addFont($font, $mode, $pre = null) {
$font = FontParser::parse($font);
if ($this->isAdmin) {
$fontData = FontRenderer::render($font, $mode, $pre == null ? $this->getSelector() : $pre, $this->fontSize);
if ($fontData) {
$this->addCSS($fontData[1]);
return $fontData[0];
}
return '';
}
return $this->_addFontCache($font, $mode, $pre == null ? $this->getSelector() : $pre, $this->fontSize);
}
private function _addStyleCache($style, $mode, $pre) {
$cacheKey = md5($style . $mode . $pre);
if (!isset($this->styleCache[$cacheKey])) {
$styleData = StyleRenderer::render($style, $mode, $pre);
if ($styleData) {
$this->addCSS($styleData[1]);
$this->styleCache[$cacheKey] = $styleData[0];
} else {
$this->styleCache[$cacheKey] = '';
}
}
return $this->styleCache[$cacheKey];
}
public function addStyle($style, $mode, $pre = null) {
$style = StyleParser::parse($style);
if ($this->isAdmin) {
$styleData = StyleRenderer::render($style, $mode, $pre == null ? $this->getSelector() : $pre);
if ($styleData) {
$this->addCSS($styleData[1]);
return $styleData[0];
}
return '';
}
return $this->_addStyleCache($style, $mode, $pre == null ? $this->getSelector() : $pre);
}
public function addScript($script, $name = false) {
if ($name !== false) {
$this->addedScriptResources[] = $name;
}
$this->initCallbacks[] = $script;
}
public function isScriptAdded($name) {
return in_array($name, $this->addedScriptResources);
}
public function addImage($imageUrl) {
$this->images[] = $imageUrl;
}
public function getImages() {
return $this->images;
}
public abstract function render();
}