PluginProbe
Depicter — Popup & Slider Builder / 1.9.2
Depicter — Popup & Slider Builder v1.9.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
← All changes | app/src/Document/Models/Document.php +85 -6 1.3.51.9.2 View file →
@@ -3,8 +3,9 @@
3 3
4 4
5 5 use Averta\Core\Hydrate\HydratableInterface;
6 6 use Averta\Core\Utility\Arr;
7 +use Averta\Core\Utility\Data;
7 8 use Averta\WordPress\Utility\Sanitize;
8 9 use Depicter\Document\CSS\Selector;
9 10 use Depicter\Document\Models\Options\Loading;
10 11 use Depicter\Document\Models\Options\Script;
@@ -52,8 +53,13 @@
52 53 */
53 54 public $meta;
54 55
55 56 /**
57 + * @var array
58 + */
59 + public $env = [];
60 +
61 + /**
56 62 * Start from which section
57 63 *
58 64 * @var int
59 65 */
@@ -101,8 +107,15 @@
101 107 */
102 108 private $args = [];
103 109
104 110 /**
111 + * Check if document is ai generated or not
112 + *
113 + * @var boolean
114 + */
115 + public $isBuildWithAI = false;
116 +
117 + /**
105 118 * Extract values for this class
106 119 *
107 120 * @return array
108 121 */
@@ -243,15 +256,25 @@
243 256
244 257 /**
245 258 * Collects fonts and generates a link for loading document fonts
246 259 */
247 - protected function collectAndSetFontsData()
248 - {
260 + protected function collectAndSetFontsData(){
261 + if( !empty( $this->env['additionalFonts'] ) ){
262 + // convert to array recursively
263 + $this->env['additionalFonts'] = Data::cast( $this->env['additionalFonts'], 'array' );
264 +
265 + if( is_array( $this->env['additionalFonts'] ) ){
266 + foreach( $this->env['additionalFonts'] as $localFontName => $localFontInfo ){
267 + \Depicter::documentFonts()->addLocalFont( $this->getDocumentID(), $localFontName, $localFontInfo['variants'] );
268 + }
269 + }
270 + }
271 +
249 272 foreach ( $this->sections as $section ) {
250 273 // this method adds element fonts to documentFonts service
251 274 $section->collectElementFonts();
252 275 }
253 - $this->fontLink = \Depicter::app()->documentFonts()->getFontsLink( $this->getDocumentID() );
276 + $this->fontLink = \Depicter::documentFonts()->getFontsLink( $this->getDocumentID() );
254 277 }
255 278
256 279 /**
257 280 * Render document custom styles
@@ -266,11 +289,9 @@
266 289 $this->stylesList[ '.'. $this->getSelector() ] = [];
267 290 }
268 291
269 292 $documentStyles = [
270 - '.'. $this->getStyleSelector() => $this->options->getStyles(),
271 293 '.'. $this->getStyleSelector() . ' .depicter-section' => $this->options->getSectionGeneralStyles(),
272 - '.'. $this->getStyleSelector( true ) . ':not(.depicter-ready)' => $this->options->getBeforeInitStyles(), // styles to prevent FOUC. It should not have depicter-revert class in selector
273 294 '.'. $this->getStyleSelector() . ' .depicter-layers-wrapper' => $this->options->getLayersWrapperStyles()
274 295 ];
275 296 // prepend document styles at the beginning of the styles
276 297 $this->stylesList = $documentStyles + $this->stylesList;
@@ -275,8 +296,16 @@
275 296 // prepend document styles at the beginning of the styles
276 297 $this->stylesList = $documentStyles + $this->stylesList;
277 298
278 299 $this->stylesList[ '.'. $this->getStyleSelector() ]['customStyle'] = $this->getCustomStyles();
300 +
301 + // add before init styles separately to style list as well
302 + $this->stylesList[ '.'. $this->getStyleSelector() ]['beforeInitStyle'] = [
303 + '.'. $this->getStyleSelector() => $this->options->getStyles(),
304 + '.'. $this->getStyleSelector( true ) . ':not(.depicter-ready)' => $this->options->getBeforeInitStyles(), // styles to prevent FOUC. It should not have depicter-revert class in selector
305 + ];
306 +
307 + return $this->stylesList;
279 308 }
280 309
281 310 /**
282 311 * Retrieves StyleGeneratorService
@@ -320,8 +349,19 @@
320 349 return $this->styleGenerator( ['forceRegenerateStyles' => $forceRegenerateStyles] )->getCss( $forceRegenerateStyles = false );
321 350 }
322 351
323 352 /**
353 + * Retrieves before init CSS
354 + *
355 + * @param bool $forceRegenerateStyles Whether regenerate before init styles or not
356 + *
357 + * @return string css styles
358 + */
359 + public function getBeforeInitCssAndTag( $forceRegenerateStyles = false ){
360 + return $this->styleGenerator( ['forceRegenerateStyles' => $forceRegenerateStyles] )->getBeforeInitCssAndTag( $forceRegenerateStyles = false );
361 + }
362 +
363 + /**
324 364 * Retrieves generated css wrapper in a style tag
325 365 *
326 366 * @param bool $forceRegenerateStyles Whether regenerate styles or not
327 367 *
@@ -433,9 +473,9 @@
433 473 if( in_array('google-font', $fileKeysToInclude) && $fontLink = $this->getFontsLink() ){
434 474 $documentCustomStyles[ "depicter-{$this->getDocumentID()}-google-font" ] = $fontLink;
435 475 }
436 476 if( in_array('custom', $fileKeysToInclude) && $customCssFileUrl = $this->getCssFileUrl() ){
437 - $documentCustomStyles[ "depicter-{$this->getDocumentID()}-custom" ] = $customCssFileUrl;
477 + $documentCustomStyles[ "depicter--{$this->getDocumentID()}-custom" ] = $customCssFileUrl;
438 478 }
439 479
440 480 return $documentCustomStyles;
441 481 }
@@ -589,8 +629,47 @@
589 629 */
590 630 public function getSectionsCount()
591 631 {
592 632 return is_array( $this->sectionsList ) ? count( $this->sectionsList ) : 0;
633 + }
634 +
635 + /**
636 + * Gel list of section objects
637 + *
638 + * @return Section[]
639 + */
640 + public function getSections()
641 + {
642 + return $this->sections ?? [];
643 + }
644 +
645 + /**
646 + * Get a section object by section ID
647 + *
648 + * @param string $sectionId The section ID
649 + *
650 + * @return Section|null
651 + */
652 + public function getSectionById( $sectionId )
653 + {
654 + return $this->sections[ $sectionId ] ?? null;
655 + }
656 +
657 + /**
658 + * Get a section by section number. starts from 1
659 + *
660 + * @param int $sectionNumber The section number
661 + *
662 + * @return Section|null
663 + */
664 + public function getSectionNth( $sectionNumber )
665 + {
666 + if( ! $this->getSections() ){
667 + return null;
668 + }
669 +
670 + $sectionIndex = $sectionNumber > 0 ? $sectionNumber - 1 : 1;
671 + return array_values( $this->getSections() )[ $sectionIndex ] ?? null;
593 672 }
594 673
595 674 /**
596 675 * Get init script