PluginProbe
Depicter — Popup & Slider Builder / 1.6.2
Depicter — Popup & Slider Builder v1.6.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Document / Models / Element.php

Element.php in Depicter — Popup & Slider Builder 1.6.2, at app/src/Document/Models/Element.php

484 lines 10.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Document\Models;
3
4 use Averta\Core\Utility\Arr;
5 use Depicter\Document\CSS\Breakpoints;
6 use Depicter\Document\CSS\Selector;
7 use Depicter\Document\Helper\Helper;
8 use Depicter\Document\Models\Traits\HasDataSheetTrait;
9 use Depicter\Document\Models\Traits\HasDocumentIdTrait;
10 use Depicter\Editor\Models\Common\Size;
11 use Depicter\Editor\Models\Common\Styles;
12 use Depicter\Html\Html;
13
14 class Element
15 {
16 use HasDocumentIdTrait;
17 use HasDataSheetTrait;
18
19 /**
20 * @var string
21 */
22 public $id;
23
24 /**
25 * @var string
26 */
27 public $name;
28
29 /**
30 * @var string
31 */
32 public $type;
33
34 /**
35 * @var string
36 */
37 public $section;
38
39 /**
40 * @var array|null
41 */
42 public $hideOnSections = [];
43
44 /**
45 * @var string
46 */
47 public $parent;
48
49 /**
50 * @var \Depicter\Document\Models\Common\Position\States
51 */
52 public $position;
53
54 /**
55 * @var bool
56 */
57 public $wrap;
58
59 /**
60 * @var bool
61 */
62 public $locked = false;
63
64 /**
65 * @var object
66 */
67 public $visible = true;
68
69 /**
70 * @var bool|null
71 */
72 public $keepAspectRatio;
73
74 /**
75 * @var array|null
76 */
77 public $children;
78
79 /**
80 * @var array
81 */
82 public $childrenObjects = [];
83
84 /**
85 * @var \Depicter\Document\Models\Common\Size\States|null
86 */
87 public $size;
88
89 /**
90 * @var \Depicter\Document\Models\Common\Styles|null
91 */
92 public $styles;
93
94 /**
95 * @var object|null
96 */
97 public $options;
98
99 /**
100 * @var \Depicter\Document\Models\Common\Animation|null
101 */
102 public $animation;
103
104 /**
105 * @var \Depicter\Document\Models\Common\Parallax|null
106 */
107 public $parallax;
108
109 /**
110 * @var array|null
111 */
112 public $actions;
113
114 /**
115 * @var int
116 */
117 public $depth;
118
119 /**
120 * @var array
121 */
122 public $devices;
123
124 /**
125 * Selector and CSS list
126 *
127 * @var array
128 */
129 protected $selectorCssList = [];
130
131 /**
132 * Instance of Element type or base Element class
133 *
134 * @var Element
135 */
136 protected $alias;
137
138 /**
139 * @var object|null
140 */
141 public $cropData;
142
143 /**
144 * @var \Depicter\Document\Models\Common\ResponsiveScale|null
145 */
146 public $responsiveScale;
147
148 /**
149 * @var string
150 */
151 protected $markup;
152
153
154
155 /**
156 * Element constructor.
157 */
158 public function __construct() {
159 $this->devices = Breakpoints::names();
160 }
161
162 /**
163 * get element number
164 *
165 * @return string
166 */
167 public function getID() {
168 return Helper::getElementIdFromSlug( $this->id );
169 }
170
171 /**
172 * get element slug
173 *
174 * @return string
175 */
176 public function getSlug() {
177 return $this->id;
178 }
179
180 /**
181 * Get element name
182 *
183 * @return string
184 */
185 public function getName() {
186 return $this->name ? $this->name : $this->id;
187 }
188
189 /**
190 * Get section ID number
191 *
192 * @return int
193 */
194 public function getSectionID() {
195 return Helper::getSectionIdFromSlug( $this->section );
196 }
197
198 /**
199 * Return child elements IDs for group type element
200 * @return array|null
201 */
202 public function getElementIds() {
203 return $this->children;
204 }
205
206 /**
207 * Sets belonging elements for group type element
208 *
209 * @param array $elementObjects
210 */
211 public function setElementObjects( $elementObjects )
212 {
213 $this->childrenObjects = $elementObjects;
214 }
215
216 /**
217 * Prepare class for rendering markup
218 *
219 * @return Element
220 * @throws \JsonMapper_Exception
221 */
222 public function prepare() {
223 return $this->alias();
224 }
225
226 /**
227 * Check if unique element class exist then render element through that class
228 *
229 * @return Element
230 * @throws \JsonMapper_Exception
231 */
232 public function alias(){
233 if( $this->alias ){
234 return $this->alias;
235 }
236
237 $className = '\\Depicter\\Document\\Models\\Elements\\' . ucfirst( $this->type );
238 if ( class_exists( $className ) ) {
239 $mapper = new \JsonMapper();
240 $this->alias = $mapper->map( $this, new $className() );
241 // pass the document ID to new class too
242 $this->alias->setDocumentID( $this->getDocumentID() );
243
244 return $this->alias;
245 }
246
247 return $this;
248 }
249
250 public function render() {}
251
252 public function getClassNames() {
253 $classes = [];
254
255 $classes[] = Selector::prefixify('element');
256 $classes[] = Selector::prefixify('layer');
257
258 $classes[] = $this->getSelector();
259 $classes[] = $this->getDataSheetClassName();
260
261 if( $this->options->className ?? 0 ){
262 $classes[] = $this->options->className;
263 }
264
265 if ( isset( $this->visible->default ) && $this->visible->default === false ) {
266 $classes[] = 'depicter-hide-on-desktop ';
267 }
268
269 if ( isset( $this->visible->tablet ) && $this->visible->tablet === false ) {
270 $classes[] = 'depicter-hide-on-tablet ';
271 }
272
273 if ( isset( $this->visible->mobile ) && $this->visible->mobile === false ) {
274 $classes[] = 'depicter-hide-on-mobile ';
275 }
276
277 return trim( implode(' ', $classes ) );
278 }
279
280 /**
281 * Get default data attributes
282 *
283 * @return array
284 * @throws \JsonMapper_Exception
285 */
286 public function getDefaultAttributes() {
287 $dataAttrs = [
288 'id' => $this->getCssID(),
289 'class' => $this->getClassNames(),
290 'data-type' => $this->type,
291 'data-wrap' => !!$this->wrap ? "true" : "false",
292 'data-name' => $this->getName()
293 ];
294
295 if( ! empty( $this->position->getOffset("default" ) ) ){
296 $dataAttrs['data-offset'] = $this->position->getOffset("default" );
297 }
298 if( ! empty( $this->position->getOffset("tablet" ) ) ){
299 $dataAttrs['data-tablet-offset'] = $this->position->getOffset("tablet" );
300 }
301 if( ! empty( $this->position->getOffset("mobile" ) ) ){
302 $dataAttrs['data-mobile-offset'] = $this->position->getOffset("mobile" );
303 }
304
305 if( $this->hideOnSections && $hideOnSections = Helper::getInvisibleSectionsCssIdList( $this->hideOnSections, $this->getDocumentID() ) ){
306 $dataAttrs['data-hide-on-sections'] = $hideOnSections;
307 }
308
309 if ( $actions = Helper::getActions( $this->actions ) ) {
310 $dataAttrs['data-actions'] = $actions;
311 }
312 if ( $this->animation && false !== $animationData = $this->animation->getAnimationAttrs() ) {
313 $dataAttrs = Arr::merge( $dataAttrs, $animationData );
314 }
315
316 if ( $this->parallax && false !== $parallaxData = $this->parallax->getParallaxAttrs() ) {
317 $dataAttrs = Arr::merge( $dataAttrs, $parallaxData );
318 }
319
320 if( ! empty( $this->size ) ){
321 $dataAttrs['data-width' ] = implode( ',', $this->size->getResponsiveSizes( 'width' , true ) );
322 $dataAttrs['data-height'] = implode( ',', $this->size->getResponsiveSizes( 'height', true ) );
323 }
324
325 $dataAttrs['data-responsive-scale' ] = ! empty( $this->responsiveScale ) ? implode( ',', $this->responsiveScale->getResponsiveSizes() ) : 'true,,';
326
327 if( ! empty( $this->prepare()->styles->hover ) && $hoverOffDevices = $this->prepare()->styles->hover->getDisabledDeviceList() ){
328 $dataAttrs['data-hover-off' ] = implode( ',', $hoverOffDevices );
329 }
330
331 if ( ! empty( $this->prepare()->styles->blendingMode ) ) {
332 $dataAttrs['data-frame-class'] = $this->getSelector() . '-frame' ;
333 }
334
335 return $dataAttrs;
336 }
337
338 /**
339 * Get section CSS ID for data sheet if dataSource is assigned
340 *
341 * @return string
342 */
343 public function getDataSheetClassName() {
344 if( $this->getDataSheetID() ){
345 return $this->getCssID();
346 }
347 return '';
348 }
349
350 /**
351 * Check if element has link
352 * @return false|\TypeRocket\Html\Html
353 */
354 public function getLinkTag() {
355 if ( !empty( $this->options->url->path ) ) {
356 $urlPath = $this->maybeReplaceDataSheetTags( $this->options->url->path );
357 $urlArgs = isset( $this->options->url->openInNewTab ) && empty( $this->options->url->openInNewTab ) ? [] : ['target' => '_blank'];
358 return Html::a( '', $urlPath, $urlArgs );
359 }
360
361 return false;
362 }
363
364 /**
365 * Retrieves list of fonts used in typography options
366 *
367 * @return array
368 * @throws \JsonMapper_Exception
369 */
370 public function getFontsList()
371 {
372 $fontsList = ! empty( $this->prepare()->styles ) ? $this->prepare()->styles->getFontsList() : [];
373 \Depicter::app()->documentFonts()->addFonts( $this->getDocumentID(), $fontsList, 'google' );
374
375 return $fontsList;
376 }
377
378 /**
379 * Retrieves the content of element
380 *
381 * @return string
382 */
383 protected function getContent(){
384 return $this->options->content ?? '';
385 }
386
387 /**
388 * Get element CSS ID
389 *
390 * @return string
391 */
392 public function getCssID() {
393 $cssID = Selector::getFullSelectorPath( $this->getDocumentID(), null, $this->getID() );
394 if( $dataSheetId = $this->getDataSheetID() ){
395 $cssID .= "-{$dataSheetId}";
396 }
397
398 return $cssID;
399 }
400
401 /**
402 * Get element selector
403 *
404 * @return string
405 */
406 public function getSelector() {
407 return Selector::getUniqueSelector( $this->getDocumentID(), $this->getSectionID(), $this->getID(), Selector::ELEMENT_PREFIX );
408 }
409
410 /**
411 * Get element style selector
412 *
413 * @return string
414 */
415 public function getStyleSelector() {
416 return Selector::PREFIX_CSS . " ." . $this->getSelector();
417 }
418
419 /**
420 * Get element frame selector
421 *
422 * @return string
423 */
424 public function getFrameStyleSelector() {
425 return Selector::PREFIX_CSS . ' .' . $this->getSelector() . '-frame';
426 }
427
428 /**
429 * Get list of selector and CSS for element
430 *
431 * @return array
432 * @throws \JsonMapper_Exception
433 */
434 public function getSelectorAndCssList(){
435
436 if( ! empty( $this->prepare()->styles ) ){
437 $this->selectorCssList[ '.' . $this->getStyleSelector() ] = $this->prepare()->styles->getGeneralCss('normal');
438
439 $transitionCss = $this->prepare()->styles->getTransitionCss();
440 $hoverCss = $this->prepare()->styles->getGeneralCss('hover');
441 $transitionCss['hover'] = $hoverCss['hover'];
442
443 $this->selectorCssList[ '.' . $this->getStyleSelector() . ':not(.depicter-hover-off)' ] = $transitionCss;
444
445 if ( !empty( $this->prepare()->styles->blendingMode ) ) {
446 $this->selectorCssList[ '.' . $this->getFrameStyleSelector() ] = $this->prepare()->styles->getBlendingModeStyle();
447 }
448 }
449
450 if ( $this->getCustomStyles() ) {
451 $this->selectorCssList[ '.' . $this->getStyleSelector() ]['customStyle'] = $this->getCustomStyles();
452 }
453
454 return $this->selectorCssList;
455 }
456
457 /**
458 * Retrieves custom styles of document
459 *
460 * @return string
461 */
462 protected function getCustomStyles(){
463 if ( ! is_null( $this->options ) && ! empty( $this->options->customStyle ) ) {
464 $customStyles = $this->options->customStyle;
465 // replace "selector" with unique selector of section
466 return str_replace('selector', '.'.$this->getStyleSelector(), $customStyles );
467 }
468 return '';
469 }
470
471 /**
472 * Get markup for preloading media urls
473 *
474 * @return string
475 */
476 public function getPreloadTags(){
477 if( method_exists( $this, 'getPreloadMarkup' ) ){
478 return $this->getPreloadMarkup();
479 }
480 return '';
481 }
482
483 }
484