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 +107 -9 1.2.01.9.2 View file →
@@ -3,19 +3,20 @@
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;
11 -use Depicter\Document\Models\Traits\HasDocumentIdTrait;
12 +use Depicter\Document\Models\Traits\UnPublishedNoticeTrait;
12 13 use Depicter\Html\Html;
13 14 use Depicter\Services\StyleGeneratorService;
14 15
15 16 class Document implements HydratableInterface
16 17 {
17 - use HasDocumentIdTrait;
18 + use UnPublishedNoticeTrait;
18 19
19 20
20 21 /**
21 22 * @var array
@@ -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 */
@@ -94,8 +100,22 @@
94 100 */
95 101 private $fontLink;
96 102
97 103 /**
104 + * Extra document args
105 + *
106 + * @var array
107 + */
108 + private $args = [];
109 +
110 + /**
111 + * Check if document is ai generated or not
112 + *
113 + * @var boolean
114 + */
115 + public $isBuildWithAI = false;
116 +
117 + /**
98 118 * Extract values for this class
99 119 *
100 120 * @return array
101 121 */
@@ -150,8 +170,9 @@
150 170 'id' => $this->getCssId(),
151 171 'class' => $this->getClassNames()
152 172 ]);
153 173
174 + $this->renderNotice();
154 175 $this->renderLoadingSymbol();
155 176 $this->renderForegroundElements();
156 177 $this->renderSectionsAndElements();
157 178 $this->collectAndSetFontsData();
@@ -161,8 +182,18 @@
161 182 return $this->html . $this->getInitScriptTag();
162 183 }
163 184
164 185 /**
186 + * Render markup for possible notices
187 + *
188 + * @return void
189 + */
190 + protected function renderNotice(){
191 + $notice = $this->getUnpublishedChangesNotice();
192 + $this->html->nest( "\n" . $notice );
193 + }
194 +
195 + /**
165 196 * Render markup for loading symbols
166 197 */
167 198 protected function renderLoadingSymbol() {
168 199 if ( empty( $this->options->loading ) ) {
@@ -225,15 +256,25 @@
225 256
226 257 /**
227 258 * Collects fonts and generates a link for loading document fonts
228 259 */
229 - protected function collectAndSetFontsData()
230 - {
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 +
231 272 foreach ( $this->sections as $section ) {
232 273 // this method adds element fonts to documentFonts service
233 274 $section->collectElementFonts();
234 275 }
235 - $this->fontLink = \Depicter::app()->documentFonts()->getFontsLink( $this->getDocumentID() );
276 + $this->fontLink = \Depicter::documentFonts()->getFontsLink( $this->getDocumentID() );
236 277 }
237 278
238 279 /**
239 280 * Render document custom styles
@@ -248,10 +289,9 @@
248 289 $this->stylesList[ '.'. $this->getSelector() ] = [];
249 290 }
250 291
251 292 $documentStyles = [
252 - '.'. $this->getStyleSelector() => $this->options->getStyles(),
253 - '.'. $this->getStyleSelector( true ) . ':not(.depicter-ready)' => $this->options->getBeforeInitStyles(), // styles to prevent FOUC. It should not have depicter-revert class in selector
293 + '.'. $this->getStyleSelector() . ' .depicter-section' => $this->options->getSectionGeneralStyles(),
254 294 '.'. $this->getStyleSelector() . ' .depicter-layers-wrapper' => $this->options->getLayersWrapperStyles()
255 295 ];
256 296 // prepend document styles at the beginning of the styles
257 297 $this->stylesList = $documentStyles + $this->stylesList;
@@ -256,8 +296,16 @@
256 296 // prepend document styles at the beginning of the styles
257 297 $this->stylesList = $documentStyles + $this->stylesList;
258 298
259 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;
260 308 }
261 309
262 310 /**
263 311 * Retrieves StyleGeneratorService
@@ -301,8 +349,19 @@
301 349 return $this->styleGenerator( ['forceRegenerateStyles' => $forceRegenerateStyles] )->getCss( $forceRegenerateStyles = false );
302 350 }
303 351
304 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 + /**
305 364 * Retrieves generated css wrapper in a style tag
306 365 *
307 366 * @param bool $forceRegenerateStyles Whether regenerate styles or not
308 367 *
@@ -406,9 +465,9 @@
406 465 public function getCustomCssFiles( $fileKeysToInclude = 'all' )
407 466 {
408 467 $documentCustomStyles = [];
409 468
410 - if( in_array( $fileKeysToInclude, ['all', '*']) ){
469 + if( is_string( $fileKeysToInclude ) && in_array( $fileKeysToInclude, [ 'all', '*'] ) ){
411 470 $fileKeysToInclude = ['google-font', 'custom'];
412 471 }
413 472
414 473 if( in_array('google-font', $fileKeysToInclude) && $fontLink = $this->getFontsLink() ){
@@ -414,9 +473,9 @@
414 473 if( in_array('google-font', $fileKeysToInclude) && $fontLink = $this->getFontsLink() ){
415 474 $documentCustomStyles[ "depicter-{$this->getDocumentID()}-google-font" ] = $fontLink;
416 475 }
417 476 if( in_array('custom', $fileKeysToInclude) && $customCssFileUrl = $this->getCssFileUrl() ){
418 - $documentCustomStyles[ "depicter-{$this->getDocumentID()}-custom" ] = $customCssFileUrl;
477 + $documentCustomStyles[ "depicter--{$this->getDocumentID()}-custom" ] = $customCssFileUrl;
419 478 }
420 479
421 480 return $documentCustomStyles;
422 481 }
@@ -570,8 +629,47 @@
570 629 */
571 630 public function getSectionsCount()
572 631 {
573 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;
574 672 }
575 673
576 674 /**
577 675 * Get init script