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/Options/Script.php +7 -166 trunk1.9.2 View file →
@@ -1,15 +1,12 @@
1 1 <?php
2 2 namespace Depicter\Document\Models\Options;
3 3
4 -use Averta\Core\Utility\Arr;
5 4 use Averta\WordPress\Utility\JSON;
6 -use Depicter\Document\Helper\Helper;
7 5 use Depicter\Document\Models\Document;
8 6
9 7 class Script
10 8 {
11 -
12 9 /**
13 10 * @param Document $document
14 11 *
15 12 * @return string
@@ -21,15 +18,12 @@
21 18
22 19 $attributes = [
23 20 'width' => $width,
24 21 'height' => $height,
25 - 'view' => 'basic',
26 - 'keepAspectRatio' => $document->options->general->keepAspect ?? false,
22 + 'keepAspectRatio' => isset( $document->options->general->keepAspect ) ? $document->options->general->keepAspect : false,
27 23 'preload' => isset( $document->options->loading ) ? $document->options->loading->getValue() : 0,
28 24 'layout' => $document->options->getLayout(),
29 - 'rtl' => $document->options->navigation->rtl ?? false,
30 - 'initAfterAppear' => isset( $document->options->loading ) && !empty( $document->options->loading->initAfterAppear ),
31 - 'ajaxApiUrl' => esc_url( admin_url( 'admin-ajax.php' ) )
25 + 'rtl' => isset( $document->options->navigation->rtl ) ? $document->options->navigation->rtl : false
32 26 ];
33 27
34 28 if ( $document->isBuildWithAI ) {
35 29 $attributes['disableAnimations'] = true;
@@ -34,14 +28,10 @@
34 28 if ( $document->isBuildWithAI ) {
35 29 $attributes['disableAnimations'] = true;
36 30 }
37 31
38 - if ( ! empty( $document->options->sectionTransition->type ) ) {
39 - if ( \Depicter::auth()->isPaid() ) {
40 - $attributes['view'] = $document->options->sectionTransition->type;
41 - } else {
42 - $attributes['view'] = $document->options->sectionTransition->type == 'fade' ? 'fade' : 'basic';
43 - }
32 + if( isset( $document->options->sectionTransition->type ) ){
33 + $attributes['view'] = !empty( $document->options->sectionTransition->type ) ? $document->options->sectionTransition->type : 'basic';
44 34 }
45 35
46 36 // viewOptions property
47 37 $viewOptions = [];
@@ -85,12 +75,8 @@
85 75 if( $viewOptions ){
86 76 $attributes['viewOptions'] = $viewOptions;
87 77 }
88 78
89 - if( isset( $document->options->stretch ) ){
90 - $attributes['stretch'] = $document->options->stretch ?? true;
91 - }
92 -
93 79 // slideShow property
94 80 if( ! empty( $document->options->navigation->slideshow->enable ) ){
95 81 $slideShow = [];
96 82 if( isset( $document->options->navigation->slideshow->duration ) ){
@@ -101,22 +87,13 @@
101 87 }
102 88 if( isset( $document->options->navigation->slideshow->pauseOnHover ) ){
103 89 $slideShow['pauseOnHover'] = $document->options->navigation->slideshow->pauseOnHover;
104 90 }
105 -
106 - if( isset( $document->options->navigation->slideshow->resetTimerOnBlur ) ){
107 - $slideShow['resetTimerOnBlur'] = $document->options->navigation->slideshow->resetTimerOnBlur;
108 - }
109 -
110 91 $slideShow['autostart'] = $document->options->navigation->slideshow->enable;
111 92
112 93 $attributes['slideshow'] = $slideShow;
113 94 }
114 95
115 - if( ! empty ( $document->options->navigation->nativeScrollNavigation ) ){
116 - $attributes['nativeScrollNavigation'] = $document->options->navigation->nativeScrollNavigation;
117 - }
118 -
119 96 if( !empty( $document->options->navigation->swipe->enable ) ){
120 97 if( isset( $document->options->navigation->swipe->mouseSwipe ) ){
121 98 $attributes['mouseSwipe'] = $document->options->navigation->swipe->mouseSwipe;
122 99 }
@@ -159,156 +136,20 @@
159 136 if( $navigator ){
160 137 $attributes['navigator'] = $navigator;
161 138 }
162 139
163 - $playerName = 'dpPlayer';
164 - $displayExtensionScript = $this->generateDisplayExtensionScript( $document, $playerName );
140 + $sliderName = 'slider';
165 141
166 - if ( ! empty( $displayExtensionScript ) ) {
167 - $attributes['detachBeforeInit'] = true;
168 - }
169 -
170 - if ( isset ( $document->options->navigation->autoScroll ) ) {
171 - $attributes['autoScroll'] = $document->options->navigation->autoScroll;
172 - }
173 -
174 - if ( isset( $document->options->documentTypeOptions->carousel ) ) {
175 - foreach( $document->options->documentTypeOptions->carousel as $key => $value ) {
176 - if ( $key == 'styles' ) {
177 - continue;
178 - }
179 -
180 - $attributes['carouselOptions'][ $key ] = $value;
181 - }
182 - }
183 -
184 - if ( ! empty( $document->options->navigation->deepLink->enable ) ) {
185 - $attributes['deepLink'] = $document->options->navigation->deepLink;
186 - }
187 -
188 - $attributes['useWatermark'] = \Depicter::auth()->isSubscriptionExpired();
189 -
190 - if ( $document->hasTeaser() ) {
191 - $attributes['teaser'] = [
192 - 'enabled' => true,
193 - 'placement' => $document->options->documentTypeOptions->teaser->placement,
194 - 'behavior' => $document->options->documentTypeOptions->teaser->behavior ?? "always",
195 - 'vSpace' => [
196 - 'value' => $document->options->documentTypeOptions->teaser->vSpace->value,
197 - 'unit' => $document->options->documentTypeOptions->teaser->vSpace->unit
198 - ],
199 - 'hSpace' => [
200 - 'value' => $document->options->documentTypeOptions->teaser->hSpace->value,
201 - 'unit' => $document->options->documentTypeOptions->teaser->hSpace->unit
202 - ]
203 - ];
204 - }
205 -
206 - $attributes = apply_filters( 'depicter/player/script/attributes', $attributes );
207 -
208 - $basePath = \Depicter::core()->assets()->getUrl() . '/resources/scripts/player/';
209 -
210 142 $script = "\n(window.depicterSetups = window.depicterSetups || []).push(function(){";
211 - $script .= "\n\tDepicter.basePath = '{$basePath}';";
212 - $script .= "\n\tconst $playerName = Depicter.setup('.{$document->getSelector()}',\n\t\t";
143 + $script .= "\n\tvar $sliderName = Depicter.setup('.{$document->getSelector()}',\n\t\t";
213 144
214 145 $attributesString = JSON::encode( $attributes );
215 146
216 147 $script .= "{$attributesString}\n\t);\n";
217 148
218 - $script .= $document->options->getCallbacks( $playerName );
219 -
220 - $script .= $displayExtensionScript;
221 -
222 - $script .= $this->generateCustomJSActionsScript( $document );
223 -
149 + $script .= $document->options->getCallbacks( $sliderName );
224 150 $script .= "});\n";
225 151
226 - $this->enqueueRecaptchaScript( $document );
227 -
228 152 return $script;
229 153 }
230 154
231 - /**
232 - * Generate display extension script
233 - *
234 - * @param Document $document
235 - * @param string $playerName
236 - *
237 - * @return string
238 - */
239 - public function generateDisplayExtensionScript( $document, $playerName ) {
240 -
241 - if ( ! $document->isDisplayExtension() ) {
242 - return '';
243 - }
244 - if( empty( $document->options->documentTypeOptions->displayOptions ) ){
245 - return '';
246 - }
247 - $displayOptions = $document->options->documentTypeOptions->displayOptions;
248 -
249 - unset( $displayOptions->animation );
250 - unset( $displayOptions->backdropColor );
251 - unset( $displayOptions->backdropBlur );
252 -
253 - $extensionParams = [
254 - "type" => $document->getType(),
255 - "id" => $document->getCssId(),
256 - "className" => $document->getDisplayStyleSelector(),
257 - "displayOptions" => $displayOptions
258 - ];
259 -
260 - $triggerParams = '';
261 -
262 - if ( ! \Depicter::front()->preview()->isPreview() ){
263 - $displayAgain = Helper::getDisplayAgainProperties( $document->getDocumentID() );
264 - $extensionParams = Arr::merge( $displayAgain, $extensionParams );
265 -
266 - if( $triggers = Helper::getDisplayRuleTriggers( $document->getDocumentID() ) ){
267 - $triggerParams = ",\n\t\t" . JSON::encode( $triggers );
268 - }
269 - }
270 -
271 - return "\n\tDepicter.display( $playerName, \n\t\t". JSON::encode( $extensionParams ). "{$triggerParams}\n\t);\n";
272 - }
273 -
274 - /**
275 - * Generate custom JS Actions defined by user
276 - *
277 - * @param object $document
278 - * @return string $script
279 - */
280 - public function generateCustomJSActionsScript( $document ) {
281 - $script = '';
282 - foreach ( $document->elements as $key => $element ) {
283 - if ( ! empty( $element->actions ) ) {
284 - foreach ( $element->actions as $actionKey => $action ) {
285 - if ( $action->type == 'customJS' ) {
286 - $script .= "\n\tDepicter.jsActions['" . $actionKey . "'] = function(){\n\t\t" . $action->options->value . "\n\t}\n";
287 - }
288 - }
289 - }
290 - }
291 -
292 - return $script;
293 - }
294 -
295 - /**
296 - * Undocumented function
297 - *
298 - * @param Document $document
299 - *
300 - * @return void
301 - */
302 - public function enqueueRecaptchaScript( $document ) {
303 - if ( ! $document->isRecaptchaEnabled() ) {
304 - return;
305 - }
306 -
307 - $clientKey = \Depicter::options()->get('google_recaptcha_client_key', false );
308 - $secretKey = \Depicter::options()->get('google_recaptcha_secret_key', false );
309 -
310 - if ( $clientKey && $secretKey ) {
311 - wp_enqueue_script( 'google-recaptcha', 'https://www.google.com/recaptcha/api.js?render=' . $clientKey );
312 - }
313 - }
314 155 }