PluginProbe
Page Builder: Pagelayer – Drag and Drop website builder / 2.1.8
Page Builder: Pagelayer – Drag and Drop website builder v2.1.8
2.2.1 2.2.0 2.1.9 2.1.8 2.1.7 2.1.6 2.1.5 2.1.4 2.1.3 trunk 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5 0.9.6 0.9.7 0.9.8 0.9.9 1.0.0 1.0.2 1.0.3 1.0.4 1.0.5 All 129 releases
pagelayer / main / shortcode_functions.php

shortcode_functions.php in Page Builder: Pagelayer – Drag and Drop website builder 2.1.8, at main/shortcode_functions.php

1,850 lines 52.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 //////////////////////////////////////////////////////////////
4 //===========================================================
5 // class.php
6 //===========================================================
7 // PAGELAYER
8 // Inspired by the DESIRE to be the BEST OF ALL
9 // ----------------------------------------------------------
10 // Started by: Pulkit Gupta
11 // Date: 23rd Jan 2017
12 // Time: 23:00 hrs
13 // Site: http://pagelayer.com/wordpress (PAGELAYER)
14 // ----------------------------------------------------------
15 // Please Read the Terms of use at http://pagelayer.com/tos
16 // ----------------------------------------------------------
17 //===========================================================
18 // (c)Pagelayer Team
19 //===========================================================
20 //////////////////////////////////////////////////////////////
21
22 // Are we being accessed directly ?
23 if(!defined('PAGELAYER_VERSION')) {
24 exit('Hacking Attempt !');
25 }
26
27 // Is there a block ?
28 function pagelayer_render_blocks($pre_render, $parsed_block){
29
30 global $pagelayer;
31
32 if(empty($parsed_block)){
33 return $pre_render;
34 }
35
36 $block_name = $parsed_block['blockName'];
37 $tag = '';
38 $content = $parsed_block['innerHTML'];
39 $inner_blocks = array(
40 'blocks' => $parsed_block['innerBlocks'],
41 'content' => $parsed_block['innerContent']
42 );
43 $atts = $parsed_block['attrs'];
44 $atts['is_not_sc'] = 1;
45
46 if ( is_string( $block_name ) && 0 === strpos( $block_name, 'pagelayer/' ) ) {
47 $tag = substr( $block_name, 10 );
48 }
49
50 $allowed_tags = ['pl_inner_row', 'pl_inner_col'];
51
52 if( (empty($tag) || !array_key_exists($tag, $pagelayer->shortcodes) ) && ! in_array( $tag, $allowed_tags) ){
53 return $pre_render;
54 }
55
56 return pagelayer_render_shortcode($atts, $content, $tag, $inner_blocks);
57 }
58
59 // Is there a tag ?
60 function pagelayer_render_shortcode($atts, $content = '', $tag = '', $inner_blocks = array()){
61
62 global $pagelayer;
63
64 $is_block = 0;
65 $el = [];
66
67 // Is block ?
68 if(!empty($atts['is_not_sc'])){
69 $is_block = 1;
70 unset($atts['is_not_sc']);
71 }
72
73 $_tag = $class = $tag;
74 $final_tag = $tag;
75
76 // Check if the tag is inner row and col then change it to row and col tag
77 if($tag == 'pl_inner_row'){
78 $tag = 'pl_row';
79 }elseif($tag == 'pl_inner_col'){
80 $tag = 'pl_col';
81 $final_tag = $tag;
82 }
83
84 // Clear the pagelayer tags
85 if(substr($tag, 0, 3) == 'pl_'){
86 $_tag = str_replace('pl_', '', $final_tag);
87 $class = 'pagelayer-'.$_tag;
88 }
89
90 if(empty($atts)){
91 $atts = array();
92 }else{
93 $atts = (array) $atts;
94 }
95
96 // If global - > Get the post and replace $atts
97 if(!empty($atts['global_id'])){
98
99 if(!empty($pagelayer->global_widgets[$atts['global_id']])){
100 $content = $pagelayer->global_widgets[$atts['global_id']]['$'];
101 return pagelayer_change_id($content);
102 }
103
104 if(!empty($pagelayer->global_sections[$atts['global_id']])){
105 $content = $pagelayer->global_sections[$atts['global_id']]['$'];
106 return pagelayer_change_id($content);
107 }
108
109 // Set the global id as attr
110 $el['attr'][] = 'pagelayer-global-id="'.$atts['global_id'].'"';
111 }
112
113 // Is there any function ?
114 $func = pagelayer_isset($pagelayer->shortcodes[$tag], 'func');
115
116 // If not, we will search for a default func if prefix of tag is pl_
117 if(empty($func) && substr($tag, 0, 3) == 'pl_'){
118 $func = 'pagelayer_sc_'.substr($tag, 3);
119 }
120
121 // UnescapeHTML for the attributes, Fix for old shortcode method
122 if(empty($is_block)){
123 $atts = array_map('pagelayer_unescapeHTML', $atts);
124 }
125
126 // Create the element array. NOTE : This is similar to the JS el and is temporary
127 $el['atts'] = $atts;
128 $el['oAtts'] = $atts;
129 $el['id'] = !empty($atts['pagelayer-id']) ? $atts['pagelayer-id'] : pagelayer_create_id();
130 $el['tmp'] = [];
131 $el['tag'] = $final_tag;
132 $el['content'] = $content;
133 $el['inner_blocks'] = $inner_blocks;
134 $el['selector'] = '[pagelayer-id="'.$el['id'].'"]';
135 $el['cssSel'] = '.p-'.$el['id'];
136 $el['wrap'] = '[pagelayer-wrap-id="'.$el['id'].'"]';
137
138 // Remove pagelayer-id from attr
139 if( !empty($atts['pagelayer-id']) ){
140 unset($el['atts']['pagelayer-id']);
141 unset($el['oAtts']['pagelayer-id']);
142 }
143
144 $innerHTML = pagelayer_isset($pagelayer->shortcodes[$tag], 'innerHTML');
145 if(!empty($innerHTML) && !empty($content)){
146 $el['oAtts'][$innerHTML] = $content;
147 $el['atts'][$innerHTML] = $content;
148 }
149
150 // The default class
151 $el['classes'][] = 'p-'.$el['id'];
152 $el['classes'][] = $class;
153
154 // Register hook to filter $el
155 $el = apply_filters('pagelayer_do_shortcode_el', $el);
156
157 //pagelayer_print($el);
158
159 // Lets create the CSS, Classes, Attr. Also clean the dependent atts
160 foreach($pagelayer->tabs as $tab){
161
162 if(empty($pagelayer->shortcodes[$tag][$tab])){
163 continue;
164 }
165
166 foreach($pagelayer->shortcodes[$tag][$tab] as $section => $Lsection){
167
168 $props = empty($pagelayer->shortcodes[$tag][$section]) ? @$pagelayer->styles[$section] : @$pagelayer->shortcodes[$tag][$section];
169
170 //echo $tab.' - '.$section.' - <br>';
171
172 if(empty($props)){
173 continue;
174 }
175
176 foreach($props as $prop => $param){
177
178 //echo $tab.' - '.$section.' - '.$prop.'<br>';
179
180 // Handle the edit fields
181 if(!empty($param['edit'])){
182 $el['edit'][$prop] = $param['edit'];
183 }
184
185 // No value set
186 if(empty($el['atts'][$prop]) && empty($el['atts'][$prop.'_tablet']) && empty($el['atts'][$prop.'_mobile'])){
187 continue;
188 }
189
190 // Clean the not required atts
191 if(!empty($param['req'])){
192
193 $set = true;
194
195 foreach($param['req'] as $rk => $reqval){
196 $except = $rk[0] == '!' ? true : false;
197 $rk = $except ? substr($rk, 1) : $rk;
198 $val = pagelayer_isset($el['atts'], $rk);
199
200 //echo $prop.' - '.$rk.' : '.$reqval.' == '.$val.'<br>';
201
202 // The value should not be there
203 if($except){
204
205 if(!is_array($reqval) && $reqval == $val){
206 $set = false;
207 break;
208 }
209
210 // Its an array and a value is found, then dont show
211 if(is_array($reqval) && in_array($val, $reqval)){
212 $set = false;
213 break;
214 }
215
216 // The value must be equal
217 }else{
218
219 if(!is_array($reqval) && $reqval != $val){
220 $set = false;
221 break;
222 }
223
224 // Its an array and no value is found, then dont show
225 if(is_array($reqval) && !in_array($val, $reqval)){
226 $set = false;
227 break;
228 }
229 }
230
231 }
232
233 // Unset as we dont need
234 if(empty($set)){
235 unset($el['atts'][$prop]);
236 unset($el['atts'][$prop.'_tablet']);
237 unset($el['atts'][$prop.'_mobile']);
238 unset($el['tmp'][$prop]);
239 unset($el['tmp'][$prop.'_tablet']);
240 unset($el['tmp'][$prop.'_mobile']);
241 }
242
243 }
244
245 // We could have unset the value above, so we need to check again if the value is there
246 if(empty($el['atts'][$prop]) && empty($el['atts'][$prop.'_tablet']) && empty($el['atts'][$prop.'_mobile'])){
247 continue;
248 }
249
250 // Load any attachment values - This should go on top in the newer version @TODO
251 if( pagelayer_is_comment_mode() && !empty($param['edit']) && !(isset($param['ai']) && $param['ai'] === false) && !empty($el['atts'][$prop])){
252 $el['atts'][$prop] = $el['oAtts'][$prop] = !empty($el['atts']['comment_atts'][$prop]) ? $el['atts']['comment_atts'][$prop] : $el['atts'][$prop];
253 }
254
255 // Any image are skipped
256 if( pagelayer_is_comment_mode() && $param['type'] == 'image' && isset($el['atts']['comment_atts'][$prop])){
257 $el['atts'][$prop.'_ai'] = $el['oAtts'][$prop.'_ai'] = $el['atts']['comment_atts'][$prop];
258 }
259
260 if(in_array($param['type'], ['image', 'video', 'audio', 'media'])){
261
262 $attachment = ($param['type'] == 'image') ? pagelayer_image(@$el['atts'][$prop]) : pagelayer_attachment(@$el['atts'][$prop]);
263
264 if(!empty($attachment)){
265 foreach($attachment as $k => $v){
266 $el['tmp'][$prop.'-'.$k] = $v;
267 }
268 }
269
270 }
271
272 // Load any attachment values - This should go on top in the newer version @TODO
273 if($param['type'] == 'multi_image'){
274
275 $img_ids = pagelayer_maybe_explode(',', $el['atts'][$prop]);
276 $img_urls = [];
277
278 // Make the image URL
279 foreach($img_ids as $k => $v){
280 $image = pagelayer_image($v);
281 $img_urls['i'.$v] = @$image['url'];
282 }
283
284 $el['tmp'][$prop.'-urls'] = json_encode($img_urls);
285 }
286
287 // Backward compatibility of row
288 if($el['tag'] == 'pl_row' && $prop == 'content_pos' && !empty($el['atts'][$prop])){
289 if($el['atts'][$prop] == 'baseline'){
290 $el['atts'][$prop] = $el['oAtts'][$prop] = 'flex-start';
291 }else if($el['atts'][$prop] == 'end'){
292 $el['atts'][$prop] = $el['oAtts'][$prop] = 'flex-end';
293 }
294 }
295
296 // Backward compatibility of Icons
297 if($param['type'] == 'icon' && !empty($el['atts'][$prop]) && !preg_match('/\s/', $el['atts'][$prop])){
298 $el['atts'][$prop] = $el['oAtts'][$prop] = 'fa fa-'.$el['atts'][$prop];
299 }
300
301 // Backward compatibility of Box Shadow
302 if($param['type'] == 'box_shadow' && !empty($el['atts'][$prop])){
303 $shadow_atts = pagelayer_maybe_explode(',', $el['atts'][$prop]);
304 if(count($shadow_atts) == 4){
305 $shadow_atts[] = '0';
306 $shadow_atts[] = '';
307 $el['atts'][$prop] = $el['oAtts'][$prop] = $shadow_atts;
308 }
309 }
310
311 // Backward compatibility of units. And also for the default set value if it is numeric
312 if(!empty($param['units']) && isset($el['atts'][$prop]) && is_numeric($el['atts'][$prop])){
313 $el['atts'][$prop] = $el['oAtts'][$prop] = $el['atts'][$prop].$param['units'][0];
314 }
315
316 // Load permalink values
317 if($param['type'] == 'link'){
318
319 $link = $el['atts'][$prop];
320
321 if( is_array($el['atts'][$prop]) ){
322
323 // Link is required for check IF and IF-EXT in html
324 if(!isset($el['atts'][$prop]['link']) || strlen(trim($el['atts'][$prop]['link'])) < 1){
325 $link = '';
326 unset($el['atts'][$prop]);
327 continue;
328 }
329
330 $link = $el['atts'][$prop]['link'];
331
332 if(!empty($el['atts'][$prop]['target'])){
333 $el['attr'][][$param['selector']] = 'target="_blank"';
334 }
335
336 if(!empty($el['atts'][$prop]['rel'])){
337 $el['attr'][][$param['selector']] = 'rel="nofollow"';
338 }
339
340 if(!empty($el['atts'][$prop]['attrs'])){
341
342 $atts_ar = pagelayer_string_to_attributes($el['atts'][$prop]['attrs']);
343
344 if(!empty($atts_ar)){
345 foreach($atts_ar as $att => $value){
346 $el['attr'][][$param['selector']] = $att.'="'.esc_attr($value).'"';
347 }
348 }
349 }
350 }
351
352 $el['tmp'][$prop] = esc_url(pagelayer_permalink($link));
353 }
354
355 // Handle the AddClasses
356 if(!empty($param['addClass']) && !empty($el['atts'][$prop])){
357
358 // Convert to an array
359 if(!is_array($param['addClass'])){
360 $param['addClass'] = array($param['addClass']);
361 }
362
363 // Loop through
364 foreach($param['addClass'] as $k => $v){
365 $k = str_replace('{{element}}', '', $k);
366 $el['classes'][] = [trim($k) => str_replace('{{val}}', $el['atts'][$prop], $v)];
367 }
368
369 }
370
371 // Handle the AddAttributes
372 if(!empty($param['addAttr']) && !empty($el['atts'][$prop])){
373
374 // Convert to an array
375 if(!is_array($param['addAttr'])){
376 $param['addAttr'] = array($param['addAttr']);
377 }
378
379 // Loop through
380 foreach($param['addAttr'] as $k => $v){
381 $k = str_replace('{{element}}', '', $k);
382 $el['attr'][] = [trim($k) => $v];
383 }
384
385 }
386
387 $modes = [
388 'desktop' => '',
389 'tablet' => '_tablet',
390 'mobile' => '_mobile'
391 ];
392
393 $global_typo = ($param['type'] == 'typography') ? pagelayer_is_global_typo(@$el['atts'][$prop]) : '';
394
395 // Handle the CSS
396 if(!empty($param['css'])){
397 //echo $prop.'<br>';
398 // Convert to an array
399 if(!is_array($param['css'])){
400 $param['css'] = array($param['css']);
401 }
402
403 // Loop the modes and check for values
404 foreach($modes as $mk => $mv){
405
406 $M_prop = $prop.$mv;
407
408 $prop_val = pagelayer_isset($el['atts'], $M_prop);
409
410 // If is global font
411 if( $param['type'] == 'typography' && (!empty($prop_val) || !empty($global_typo)) ){
412 $prop_val = pagelayer_parse_typo($prop_val, $global_typo, $mk);
413 }
414
415 // Any value ?
416 if(empty($prop_val)){
417 continue;
418 }
419
420 // Global color handler
421 if($param['type'] == 'color'){
422 $prop_val = pagelayer_parse_color($prop_val);
423 }
424
425 // If there is global gradient color
426 if($param['type'] == 'gradient'){
427
428 $prop_val = pagelayer_maybe_explode(',', $prop_val);
429
430 foreach($prop_val as $grad_key => $grad_val){
431
432 if($grad_val[0] != '$'){
433 continue;
434 }
435
436 $prop_val[$grad_key] = pagelayer_parse_color($grad_val);
437
438 }
439
440 }
441
442 // Loop through
443 foreach($param['css'] as $k => $v){
444
445 // Make the selector
446 $selector = (!is_numeric($k) ? $k : $el['cssSel']);
447 $selector = pagelayer_parse_el_vars($selector, $el);
448
449 if($mk == 'tablet'){
450 $selector = '|pl_tablet|'.$selector;
451 }
452
453 if($mk == 'mobile'){
454 $selector = '|pl_mobile|'.$selector;
455 }
456
457 // Make the CSS
458 if(!empty($selector)){
459 $el['css'][$selector][] = rtrim( trim( pagelayer_css_render($v, $prop_val, pagelayer_isset($param, 'sep')) ), ';' );
460 }else{
461 $el['css'][][] = pagelayer_parse_el_vars($el['atts'][$M_prop],$el);
462 }
463 }
464
465 }
466
467 }
468
469 $font_cache = '';
470 // Loop the modes and check for values
471 foreach($modes as $mk => $mv){
472
473 $M_prop = $prop.$mv;
474
475 if($param['type'] == 'typography' && !empty($el['atts'][$M_prop])){
476
477 $prop_val = pagelayer_parse_typo($el['atts'][$M_prop], $global_typo, $mk);
478
479 $val = pagelayer_maybe_explode(',', $prop_val);
480
481 //For backward comaptibility
482 if($mk == 'desktop'){
483 $font_cache = $val[0];
484 }
485
486 $val[0] = empty($val[0]) ? $font_cache : $val[0];
487
488 if(!empty($val[0])){
489 pagelayer_load_font_family($val[0], pagelayer_isset($val, 3), pagelayer_isset($val, 2));
490
491 //pagelayer_print($pagelayer->runtime_fonts);
492 }
493 }
494
495 if($prop == 'font_family' && !empty($el['atts'][$M_prop])){
496 $val = $el['atts'][$M_prop];
497 if(!empty($val)){
498 pagelayer_load_font_family($val, pagelayer_isset($el['atts'], 'font_weight'.$mv), pagelayer_isset($el['atts'], 'font_style'.$mv));
499 }
500 }
501 }
502 }
503
504 }
505
506 }
507
508 //@pagelayer_print($el['css']);
509
510 // Is there a function of the tag ?
511 if(function_exists($func)){
512 call_user_func_array($func, array(&$el));
513 }
514
515 // Create the default atts and tmp atts
516 if(pagelayer_is_live()){
517 pagelayer_create_sc($el, $is_block);
518 }
519
520 $div = '<div pagelayer-id="'.$el['id'].'">
521 <style pagelayer-style-id="'.$el['id'].'"></style>';
522
523 $is_group = !empty($pagelayer->shortcodes[$tag]['has_group']) ? true : false;
524
525 // If there is an HTML AND you are not a GROUP, then make use of it, or append the real content
526 if(!empty($pagelayer->shortcodes[$tag]['html'])){
527
528 // Create the HTML object
529 $node = pagelayerQuery::parseStr($pagelayer->shortcodes[$tag]['html']);
530
531 // Remove the if-ext
532 foreach($node('[if-ext]') as $v){
533 $reqvar = pagelayer_var($v->attr('if-ext'));
534 $v->removeAttr('if-ext');
535
536 // Is the element there ?
537 if(empty($el['atts'][$reqvar])){
538 $ext_html = $v->html();
539 if(strlen($ext_html) > 0){
540 $v->after($ext_html);
541 }
542 $v->remove();
543 }
544 }
545
546 // Remove the if
547 foreach($node('[if]') as $v){
548 $reqvar = pagelayer_var($v->attr('if'));
549 $v->removeAttr('if');
550
551 // Is the element there ?
552 if(empty($el['atts'][$reqvar])){
553 $v->remove();
554 }
555 }
556
557 //die($node->html());
558
559 // Do we have a holder ? Mainly for groups
560 if(!empty($pagelayer->shortcodes[$tag]['holder'])){
561 $node->query($pagelayer->shortcodes[$tag]['holder'])->html('{{pagelayer_do_shortcode}}');
562 $do_shortcode = 1;
563 }
564
565 $html = pagelayer_parse_vars($node->html(), $el);
566
567 // Append to the DIV
568 $div .= $html;
569
570 // Is it a widget ?
571 }elseif(!empty($pagelayer->shortcodes[$tag]['widget'])){
572
573 $class = $pagelayer->shortcodes[$tag]['widget'];
574 $instance = [];
575
576 // Is there any existing data ?
577 if(!empty($el['atts']['widget_data'])){
578 $json = trim($el['atts']['widget_data']);
579 $json = json_decode($json, true);
580 //pagelayer_print($json);die();
581 if(!empty($json)){
582 $instance = $json;
583 }
584 }
585
586 ob_start();
587 the_widget($class, $instance, array('widget_id'=>'arbitrary-instance-'.$el['id'],
588 'before_widget' => '',
589 'after_widget' => '',
590 'before_title' => '',
591 'after_title' => ''
592 ));
593
594 $div .= ob_get_contents();
595 ob_end_clean();
596
597 }else{
598 $div .= '{{pagelayer_do_shortcode}}';
599 $do_shortcode = 1;
600 }
601
602 // End the tag
603 $div .= '</div>';
604
605 // Add classes and attributes
606 if(!empty($el['classes']) || !empty($el['attr']) || !empty($el['atts']['ele_attributes'])){
607
608 // Create the HTML object
609 $node = pagelayerQuery::parseStr($div);
610
611 // Add the editable values
612 if(!empty($el['edit']) && pagelayer_is_live()){
613
614 foreach($el['edit'] as $k => $v){
615 $node->query($v)->attr('pagelayer-editable', $k);
616 }
617
618 }
619
620 // Add the post data editable
621 if(pagelayer_is_live() && !empty($pagelayer->shortcodes[$tag]['edit_props']) && is_array($pagelayer->shortcodes[$tag]['edit_props'])){
622
623 $edit_props = $pagelayer->shortcodes[$tag]['edit_props'];
624
625 foreach($edit_props as $k => $v){
626 $node->query($k)->attr('pagelayer-props-editable', $v);
627 }
628
629 }
630
631 // Add the classes
632 if(!empty($el['classes'])){
633
634 //pagelayer_print($el['classes']);
635
636 foreach($el['classes'] as $k => $v){
637
638 if(!is_array($v)){
639 $v = [$v];
640 }
641
642 foreach($v as $kk => $vv){
643 //echo $kk.' - '.$vv."\n";
644 if(is_numeric($kk)){
645 $node->query($el['selector'])->addClass($vv);
646 }else{
647 $node->query($kk)->addClass($vv);
648 }
649
650 }
651
652 }
653
654 //echo $node->html();
655 //die();
656
657 }
658
659 // Add the attributes
660 if(!empty($el['attr'])){
661
662 //pagelayer_print($el['attr']);
663
664 foreach($el['attr'] as $k => $v){
665
666 if(!is_array($v)){
667 $v = [$v];
668 }
669
670 foreach($v as $kk => $vv){
671
672 $att = explode('=', $vv, 2);
673 $att[1] = pagelayer_parse_vars($att[1], $el);
674 $att[1] = trim($att[1], '"');
675
676 if(is_numeric($kk)){
677 $node->query($el['selector'])->attr($att[0], $att[1]);
678 }else{
679 $node->query($kk)->attr($att[0], $att[1]);
680 }
681
682 }
683
684 }
685
686 }
687
688 // Adding Custom Attributes
689 if(!empty($el['atts']['ele_attributes'])){
690
691 $val = pagelayer_string_to_attributes($el['atts']['ele_attributes']);
692 if(!empty($val)){
693 foreach($val as $att => $value ){
694 // Defense in depth at the sink: never emit on* event-handler attributes
695 if(pagelayer_should_show_xss_warning() && preg_match('/^on/i', $att)){
696 continue;
697 }
698
699 $node->query($el['selector'])->attr($att, esc_attr($value));
700 }
701 }
702
703 }
704
705 // Get font family form inline style
706 foreach($node->query('[style]') as $snode){
707 $ss = $snode->attr('style');
708
709 if(strpos($ss, 'font-family') === false){
710 continue;
711 }
712
713 $ss = explode(';', html_entity_decode($snode->attr('style')));
714 foreach($ss as $sss){
715
716 if(strpos($sss, 'font-family') === false){
717 continue;
718 }
719
720 $ff = explode(':', $sss);
721 $val = trim( trim($ff[1]), '"' );
722 $fw = array('100', '100i', '200', '200i', '300', '300i', '400', '400i', '500', '500i', '600', '600i', '700', '700i', '800', '800i', '900', '900i');
723
724 foreach($fw as $ww){
725 $pagelayer->runtime_fonts[$val][$ww] = $ww;
726 }
727 }
728 }
729
730 $div = $node->html();
731 //die($div);
732
733 }
734
735 // Add the CSS if any or remove it
736 $style = '';
737 if(!empty($el['css'])){
738
739 $screen_style = array('tablet' => '', 'mobile' => '');
740 $style = '<style pagelayer-style-id="'.$el['id'].'">';
741 foreach($el['css'] as $ck => $cv){
742 preg_match('/\|pl_(mobile|tablet)\|/is', $ck, $screen_matches);
743 $ck = str_replace(['|pl_mobile|', '|pl_tablet|'], '', $ck);
744 $media = pagelayer_isset($screen_matches, 1);
745
746 $merge_css = implode(';', $cv);
747 $combine_css = (!is_numeric($ck) ? $ck.'{'.$merge_css.'}' : $merge_css ).PHP_EOL;
748
749 // Mobile or tablet ?
750 if(!empty($media)){
751 $screen_style[$media] .= $combine_css;
752 continue;
753 }
754
755 $style .= $combine_css;
756 }
757
758 if(!empty($screen_style['tablet'])){
759 $style .= '@media (max-width: '.$pagelayer->settings['tablet_breakpoint'].'px) and (min-width: '.($pagelayer->settings['mobile_breakpoint'] + 1).'px){'.$screen_style['tablet'].'}'.PHP_EOL;
760 }
761
762 if(!empty($screen_style['mobile'])){
763 $style .= '@media (max-width: '.$pagelayer->settings['mobile_breakpoint'].'px){'.$screen_style['mobile'].'}'.PHP_EOL;
764 }
765
766 $style .= '</style>';
767 $style = pagelayer_parse_vars($style, $el);
768
769 if(!empty($pagelayer->shortcodes[$tag]['overide_css_selector'])){
770 $overide_css_selector = pagelayer_parse_el_vars($pagelayer->shortcodes[$tag]['overide_css_selector'], $el);
771 $style = str_replace($el['cssSel'], $overide_css_selector, $style);
772 $style = str_replace($el['wrap'], $overide_css_selector, $style);
773 }
774
775 $style = pagelayer_unescapeHTML($style);
776 }
777
778 $div = str_replace('<style pagelayer-style-id="'.$el['id'].'"></style>', $style, $div);
779
780 // Is there an inner content which requires a SHORTCODE ?
781 if(!empty($do_shortcode)){
782
783 $inner_content = pagelayer_render_inner_content($el);
784
785 $div = str_replace('{{pagelayer_do_shortcode}}', $inner_content, $div);
786 }
787
788 // Sanitize the content
789 $div = apply_filters( 'pagelayer_sanitize_do_shortcode', $div );
790
791 return $div;
792
793 }
794
795 // Render inner content
796 function pagelayer_render_inner_content(&$el){
797
798 $inner_content = '';
799
800 // Is block code?
801 if( !empty($el['inner_blocks']) ){
802
803 $index = 0;
804
805 foreach ( $el['inner_blocks']['content'] as $chunk ) {
806 if ( is_string( $chunk ) ) {
807
808 // If any string in Column the conver this is text widget in pagelayer live
809 if(!empty(trim($chunk)) && pagelayer_is_live() && $el['tag'] == 'pl_col'){
810 $parsed_block['blockName'] = 'pagelayer/pl_text';
811 $parsed_block['innerHTML'] = $chunk;
812 $parsed_block['attrs'] = [];
813 $inner_content .= render_block($parsed_block);
814 continue;
815 }
816
817 $inner_content .= $chunk;
818 continue;
819 }
820
821 $inner_block = $el['inner_blocks']['blocks'][ $index ];
822 $inner_content .= render_block($inner_block);
823 ++$index;
824 }
825 }else{
826 $inner_content .= do_shortcode($el['content']);
827 }
828
829 return $inner_content;
830 }
831
832 // Change pagelayer id in html
833 function pagelayer_change_id($content){
834 global $pagelayer;
835
836 preg_match_all('/pagelayer-id="(.*?)"/', $content, $matches);
837 $matches = array_unique($matches[1]);
838
839 foreach($matches as $val){
840 $id = pagelayer_create_id();
841 $content = str_replace($val, $id, $content);
842 }
843
844 return $content;
845 }
846
847 // Creates the shortcode and returns a base64 encoded files
848 function pagelayer_create_sc(&$el, $is_block = 0){
849
850 global $pagelayer;
851
852 $a = $tmp = array();
853
854 $pagelayer->data_attr[$el['id']] = ['attr' => $el['oAtts'], 'tmp' => $el['tmp']];
855
856 /*if(!empty($el['oAtts'])){
857
858 foreach($el['oAtts'] as $k => $v){
859 $v = str_replace('&', '&amp;', $v);
860 if($is_block){
861 $v = pagelayer_escapeHTML($v);
862 }
863 $el['attr'][] = 'pagelayer-a-'.$k.'="'.$v.'"';
864 }
865
866 }
867
868 // Tmp atts
869 if(!empty($el['tmp'])){
870
871 foreach($el['tmp'] as $k => $v){
872 $v = str_replace('&', '&amp;', $v);
873 if($is_block){
874 $v = pagelayer_escapeHTML($v);
875 }
876 $el['attr'][] = 'pagelayer-tmp-'.$k.'="'.$v.'"';
877 }
878
879 }*/
880
881 // Add the tag
882 $el['attr'][] = 'pagelayer-tag="'.$el['tag'].'"';
883
884 // Make it a Pagelayer element for editing
885 $el['classes'][] = 'pagelayer-ele';
886
887 }
888
889 // Converts {{val}} to val
890 function pagelayer_var($var){
891 return substr($var, 2, -2);
892 }
893
894 // Is the given global color
895 function pagelayer_is_global_typo($value){
896 global $pagelayer;
897
898 $typo_key = '';
899
900 // Backward compatibility
901 if(is_string($value) && $value[0] == '$'){
902 $typo_key = substr($value, 1);
903 }
904
905 if(is_array($value) && isset($value['global-font'])){
906 $typo_key = $value['global-font'];
907 }
908
909 // If global color not exist
910 if(!empty($typo_key)){
911 $typo_key = isset($pagelayer->global_fonts[$typo_key]) ? $typo_key : 'primary';
912 }
913
914 return $typo_key;
915
916 }
917
918 // Parse typography and handle Backward compatibility
919 function pagelayer_parse_typo($value, $desk_global = '', $mk = 'desktop'){
920 global $pagelayer;
921
922 $value = empty($value)? [] : $value;
923
924 // Backward compatibility for comma seperated val
925 if(!is_array($value) && $value[0] != '$'){
926 return $value;
927 }
928
929 $val = ['','','','','','','','','','',''];
930 $global_typo = pagelayer_is_global_typo($value);
931 $_desk_global = false;
932
933 if( empty($global_typo) ){
934 $global_typo = $desk_global;
935 $_desk_global = true;
936 }
937
938 // Apply global typo
939 foreach($pagelayer->typo_props as $typo => $typo_key){
940
941 // Backspace compatibility for normal array and if is set global in '$' format like $primary
942 if(is_array($value) && !empty($value[$typo])){
943 $val[$typo] = $value[$typo];
944 }
945
946 if(!empty($value[$typo_key])){
947 $val[$typo] = $value[$typo_key];
948 }
949
950 if(!empty($val[$typo]) || empty($global_typo)){
951 continue;
952 }
953
954 $global_val = $pagelayer->global_fonts[$global_typo]['value'];
955
956 if( empty($global_val[$typo_key]) || (is_array($global_val[$typo_key]) && empty($global_val[$typo_key][$mk])) || (!is_array($global_val[$typo_key]) && !empty($_desk_global) && $mk != 'desktop') ){
957 continue;
958 }
959
960 $val[$typo] = 'var(--pagelayer-font-'.$global_typo.'-'.$typo_key.')';
961 }
962
963 return $val;
964 }
965
966 // Parse color for global color
967 function pagelayer_parse_color($value, $var = true){
968 global $pagelayer;
969
970 // Global color handler
971 if($value[0] != '$' ){
972 return $value;
973 }
974
975 $gkey = substr($value, 1);
976 $gkey = isset($pagelayer->global_colors[$gkey]) ? $gkey : 'primary';
977
978 if(empty($var)){
979 return @$pagelayer->global_colors[$gkey]['value'];
980 }
981
982 return 'var(--pagelayer-color-'.$gkey.')';
983 }
984
985 // Replace the variables
986 function pagelayer_parse_el_vars($str, &$el){
987
988 global $pagelayer, $post;
989
990 // if is 404 then @$post->ID
991 if(!empty( $pagelayer->rendering_template_id ) && @$post->ID != $pagelayer->rendering_template_id){
992 $is_editable = false;
993 }else{
994 $is_editable = true;
995 }
996
997 $str = str_replace('{{element}}', $el['cssSel'], $str);
998 $is_live = pagelayer_is_live();
999 if(!empty($is_live) && $is_editable){
1000 $str = str_replace('{{wrap}}', $el['wrap'], $str);
1001 }else{
1002 $str = str_replace('{{wrap}}', $el['cssSel'], $str);
1003 }
1004 $str = str_replace('{{ele_id}}', $el['id'], $str);
1005
1006 return $str;
1007
1008 }
1009
1010 // Parse the variables
1011 function pagelayer_parse_vars($str, &$el){
1012
1013 if(empty($str)){
1014 return $str;
1015 }
1016
1017 //pagelayer_print($el);
1018 if(!empty($el['tmp']) && is_array($el['tmp'])){
1019 foreach($el['tmp'] as $k => $v){
1020 $str = str_replace('{{{'.$k.'}}}', pagelayer_maybe_implode($el['tmp'][$k]), $str);
1021 }
1022 }
1023
1024 if(is_array($el['atts'])){
1025 foreach($el['atts'] as $k => $v){
1026 $str = str_replace('{{'.$k.'}}', pagelayer_maybe_implode($el['atts'][$k]), $str);
1027 }
1028 }
1029
1030 return $str;
1031 }
1032
1033 // Make the rule
1034 function pagelayer_css_render($rule, $val, $sep = ','){
1035
1036 // Seperator
1037 $sep = empty($sep) ? ',' : $sep;
1038
1039 if(is_array($val)){
1040 $val = implode($sep, $val);
1041 }
1042
1043 // Replace the val
1044 $rule = pagelayer_css_val_replace('{{val}}', pagelayer_hex8_to_rgba($val), $rule);
1045
1046 // If there is an array
1047 if(preg_match('/\{val\[\d/is', $rule)){
1048 $val = explode($sep, $val);
1049 foreach($val as $k => $v){
1050 $rule = pagelayer_css_val_replace('{{val['.$k.']}}', pagelayer_hex8_to_rgba($v), $rule);
1051 }
1052 }
1053
1054 return $rule;
1055 }
1056
1057 // Make the rule
1058 function pagelayer_css_val_replace($val, $v, $rule){
1059
1060 // If value has css var then we remove units
1061 if(strripos($v, 'var(') !== false){
1062 $pattern = '/'.preg_quote($val, '/').'?[^\s|;]+/is';
1063 $rule = preg_replace($pattern, $v, $rule);
1064 return $rule;
1065 }
1066
1067 $rule = str_replace($val, $v, $rule);
1068 return $rule;
1069 }
1070
1071 // Post Property Handler
1072 function pagelayer_sc_post_props(&$el){
1073
1074 global $post;
1075
1076 if(empty($post)){
1077 return;
1078 }
1079
1080 $el['oAtts']['post_title'] = $post->post_title;
1081 $el['oAtts']['post_name'] = $post->post_name;
1082 $el['oAtts']['post_excerpt'] = $post->post_excerpt;
1083 $el['oAtts']['post_status'] = (empty($post->post_password)) ? $post->post_status : 'pass_protected';
1084 $el['oAtts']['post_password'] = $post->post_password;
1085 $el['oAtts']['featured_image'] = get_post_thumbnail_id($post);
1086 $el['oAtts']['comment_status'] = ($post->comment_status == 'open') ? 'true' : '';
1087 $el['oAtts']['ping_status'] = ($post->ping_status == 'open') ? 'true' : '';
1088 $el['oAtts']['post_date'] = $post->post_date;
1089 $el['oAtts']['post_sticky'] = is_sticky($post->ID) ? 'true' : '';
1090 $el['oAtts']['post_parent'] = $post->post_parent;
1091 $el['oAtts']['menu_order'] = $post->menu_order;
1092 $el['oAtts']['post_author'] = $post->post_author;
1093 $el['oAtts']['post_category'] = '';
1094 $el['oAtts']['post_tags'] = '';
1095
1096 $tag_name = pagelayer_post_type_tag($post->post_type);
1097 if(!empty($tag_name)){
1098 $postTags = wp_get_post_terms( $post->ID, $tag_name );
1099 $el['oAtts']['post_tags'] = array_column((array)$postTags, 'name');
1100 }
1101
1102 $cat_name = pagelayer_post_type_category($post->post_type);
1103 if(!empty($cat_name)){
1104 $category = get_the_terms( $post->ID, $cat_name );
1105 $el['oAtts']['post_category'] = array_column((array)$category, 'term_id');
1106 }
1107
1108 // Load featured image details
1109 if(!empty($el['oAtts']['featured_image'])){
1110
1111 $attachment = pagelayer_image($el['oAtts']['featured_image']);
1112
1113 if(!empty($attachment)){
1114 foreach($attachment as $k => $v){
1115 $el['tmp']['featured_image-'.$k] = $v;
1116 }
1117 }
1118
1119 }
1120
1121 }
1122
1123 // ROW Handler
1124 function pagelayer_sc_row(&$el){
1125
1126 pagelayer_bg_video($el);
1127
1128 if(!empty($el['atts']['row_shape_type_top'])){
1129 $path_top = PAGELAYER_DIR.'/images/shapes/'.$el['atts']['row_shape_type_top'].'-top.svg';
1130 $el['atts']['svg_top'] = file_get_contents($path_top);
1131 }
1132
1133 if(!empty($el['atts']['row_shape_type_bottom'])){
1134 $path_bottom = PAGELAYER_DIR.'/images/shapes/'.$el['atts']['row_shape_type_bottom'].'-bottom.svg';
1135 $el['atts']['svg_bottom'] = file_get_contents($path_bottom);
1136 }
1137
1138 // Row background slider
1139 if(!empty($el['atts']['bg_slider'])){
1140 $ids = pagelayer_maybe_explode(',', $el['atts']['bg_slider']);
1141 $urls = [];
1142 $el['atts']['slider'] = '';
1143
1144 // Make the image URL
1145 foreach($ids as $k => $v){
1146
1147 $image = pagelayer_image($v);
1148 $urls['i'.$v] = @$image['url'];
1149
1150 $el['atts']['slider'] .= '<div class="pagelayer-bgimg-slide" style="background-image:url(\''.$image['url'].'\')"></div>';
1151
1152 }
1153
1154 if(!empty($urls)){
1155 $el['tmp']['bg_slider-urls'] = json_encode($urls);
1156 }
1157
1158 }
1159
1160 // Row background parallax image.
1161 if(!empty($el['atts']['parallax_img'])){
1162 $img_size = @$el['tmp']['parallax_img-'.$el['atts']['parallax_id_size'].'-url'];
1163 $el['atts']['parallax_img_src'] = empty($img_size) ? @$el['tmp']['parallax_img-url'] : $img_size;
1164 }
1165
1166 }
1167
1168 // Column Handler
1169 function pagelayer_sc_col(&$el){
1170
1171 // Add the default col class
1172 $el['classes'][] = 'pagelayer-col';
1173
1174 //return do_shortcode($el['content']);
1175
1176 pagelayer_bg_video($el);
1177
1178 // Column background slider
1179 if(!empty($el['atts']['bg_slider'])){
1180 $ids = pagelayer_maybe_explode(',', $el['atts']['bg_slider']);
1181 $urls = [];
1182 $el['atts']['slider'] = '';
1183
1184 // Make the image URL
1185 foreach($ids as $k => $v){
1186
1187 $image = pagelayer_image($v);
1188 $urls['i'.$v] = @$image['url'];
1189
1190 $el['atts']['slider'] .= '<div class="pagelayer-bgimg-slide" style="background-image:url(\''.$image['url'].'\')"></div>';
1191
1192 }
1193
1194 if(!empty($urls)){
1195 $el['tmp']['bg_slider-urls'] = json_encode($urls);
1196 }
1197
1198 }
1199
1200 // Col background parallax image.
1201 if(!empty($el['atts']['parallax_img'])){
1202 $img_size = @$el['tmp']['parallax_img-'.$el['atts']['parallax_id_size'].'-url'];
1203 $el['atts']['parallax_img_src'] = empty($img_size) ? @$el['tmp']['parallax_img-url'] : $img_size;
1204 }
1205
1206 }
1207
1208 // Just for BG handling
1209 function pagelayer_bg_video(&$el){
1210
1211 if(empty($el['tmp']['bg_video_src-url'])){
1212 return false;
1213 }
1214
1215 // Get the video URL for the iframe
1216 $iframe_atts = pagelayer_video_url($el['tmp']['bg_video_src-url'], true);
1217
1218 $source = esc_url( $el['tmp']['bg_video_src-url'] );
1219 $source = str_replace('&amp;', '&', $source);
1220 $url = parse_url($source);
1221
1222 $iframe_atts['src'] .= substr_count($iframe_atts['src'], '?') > 0 ? '' : '?';
1223
1224 if(!empty($el['atts']['mute'])){
1225 $iframe_atts['src'] .= "&mute=1";
1226 $el['atts']['mute'] = " muted ";
1227 }else{
1228 $iframe_atts['src'] .= "&mute=0";
1229 $el['atts']['mute'] = "";
1230 }
1231
1232 if(empty($el['atts']['stop_loop'])){
1233 $iframe_atts['src'] .= "&loop=1";
1234 $el['atts']['stop_loop'] = " loop ";
1235 }else{
1236 $iframe_atts['src'] .= "&loop=0";
1237 $el['atts']['stop_loop'] = "";
1238 }
1239
1240 if (!empty($source)) {
1241
1242 if ($iframe_atts['type'] == 'youtube') {
1243
1244 $settings = ' data-loop="'.( !empty($el['atts']['stop_loop']) ? 1 : 0 ).'" data-mute="'.( !empty($el['atts']['mute']) ? 1 : 0 ).'" data-videoid = "'.( $iframe_atts['id'] ).'"';
1245
1246 $el['atts']['vid_src'] = '<div class = "pagelayer-youtube-video" '. $settings .'></div>';
1247
1248 } else if ($iframe_atts['type'] == 'vimeo') {
1249
1250 $el['atts']['vid_src'] = '<iframe src="'.$iframe_atts['src'].'&background=1&autoplay=1&byline=0&title=0" allowfullscreen="1" webkitallowfullscreen="1" mozallowfullscreen="1" frameborder="0"></iframe>';
1251
1252 }else{
1253
1254 $el['atts']['vid_src'] = '<video autoplay playsinline '.$el['atts']['mute'].$el['atts']['stop_loop'].'>'.
1255 '<source src="'.$iframe_atts['src'].'" type="video/mp4">'.
1256 '</video>';
1257
1258 }
1259 }
1260 }
1261
1262 // Heading Handler
1263 function pagelayer_sc_heading(&$el){
1264 //Backward compatibility for new link props
1265 pagelayer_add_link_backward($el, array('rel' => '', 'selector' => '.pagelayer-link-sel'));
1266 }
1267
1268 // Heading Handler
1269 function pagelayer_sc_icon(&$el){
1270 //Backward compatibility for new link props
1271 pagelayer_add_link_backward($el, array('rel' => '', 'selector' => '.pagelayer-ele-link'));
1272 }
1273
1274 // Heading Handler
1275 function pagelayer_sc_badge(&$el){
1276 //Backward compatibility for new link props
1277 pagelayer_add_link_backward($el, array(
1278 'link' => 'badge_url',
1279 'rel' => '',
1280 'target' => 'badge_target',
1281 'selector' => '.pagelayer-ele-link'
1282 ));
1283 }
1284
1285 // Heading Handler
1286 function pagelayer_sc_btn(&$el){
1287 //Backward compatibility for new link props
1288 pagelayer_add_link_backward($el, array('selector' => '.pagelayer-btn-holder'));
1289 }
1290
1291 // Image Handler
1292 function pagelayer_sc_social(&$el){
1293
1294 //Backward compatibility for new link props
1295 pagelayer_add_link_backward($el, array(
1296 'link' => 'social_url',
1297 'rel' => '',
1298 'selector' => '.pagelayer-ele-link'
1299 ));
1300
1301 if(empty($el['atts']['icon'])) return;
1302 $icon = explode(' fa-', $el['atts']['icon']);
1303 $el['classes'][] = ['.pagelayer-icon-holder' => 'pagelayer-'.$icon[1]];
1304 }
1305
1306 // Image Handler
1307 function pagelayer_sc_image(&$el){
1308
1309 // Decide the image URL
1310 $el['atts']['func_id'] = @$el['tmp']['id-'.$el['atts']['id-size'].'-url'];
1311 $el['atts']['func_id'] = empty($el['atts']['func_id']) ? @$el['tmp']['id-url'] : $el['atts']['func_id'];
1312 $el['atts']['pagelayer-srcset'] = $el['atts']['func_id'].', '.$el['atts']['func_id'].' 1x, ';
1313
1314 $image_atts = array(
1315 'name' => 'id',
1316 'size' => 'id-size'
1317 );
1318
1319 pagelayer_get_img_srcset($el, $image_atts);
1320
1321 // What is the link ?
1322 if(!empty($el['atts']['link_type'])){
1323
1324 // Custom url
1325 if($el['atts']['link_type'] == 'custom_url'){
1326
1327 // Backward compatibility for new link props
1328 pagelayer_add_link_backward($el, array( 'rel' => '', 'selector' => '.pagelayer-ele-link'));
1329
1330 $el['atts']['func_link'] = @$el['tmp']['link'];
1331 }
1332
1333 // Link to the media file itself
1334 if($el['atts']['link_type'] == 'media_file'){
1335 $el['atts']['func_link'] = $el['atts']['func_id'];
1336 }
1337
1338 // Lightbox
1339 if($el['atts']['link_type'] == 'lightbox'){
1340 $el['atts']['func_link'] = $el['atts']['func_id'];
1341 }
1342
1343 }
1344
1345 //pagelayer_print($el);
1346
1347 }
1348
1349 // Image Slider Handler
1350 function pagelayer_sc_image_slider(&$el){
1351
1352 // Backward compatibility for new link props
1353 if( !empty($el['atts']['link_type']) && $el['atts']['link_type'] == 'custom_url' ){
1354 pagelayer_add_link_backward($el, array( 'rel' => '', 'selector' => '.pagelayer-link-sel'));
1355 }
1356
1357 if(empty($el['atts']['ids'])){
1358 $el['atts']['ids'] = '';
1359 }
1360
1361 $ids = pagelayer_maybe_explode(',', $el['atts']['ids']);
1362 $urls = [];
1363 $all_urls = [];
1364 $final_urls = [];
1365 $ul = [];
1366 $size = $el['atts']['size'];
1367
1368 // Make the image URL
1369 foreach($ids as $k => $v){
1370
1371 $image = pagelayer_image($v);
1372
1373 $final_urls[$v] = empty($image[$size.'-url']) ? @$image['url'] : $image[$size.'-url'];
1374
1375 $urls['i'.$v] = @$image['url'];
1376
1377 foreach($image as $kk => $vv){
1378 $si = strstr($kk, '-url', true);
1379 if(!empty($si)){
1380 $all_urls['i'.$v][$si] = $vv;
1381 }
1382 }
1383
1384 $li = '<li class="pagelayer-slider-item">';
1385
1386 // Any Link ?
1387 if(!empty($el['atts']['link_type'])){
1388 $link = ($el['atts']['link_type'] == 'media_file' ? (!empty($image['url']) ? $image['url'] : $final_urls[$v]) : @$el['tmp']['link']);
1389 $li .= '<a href="'.$link.'" class="pagelayer-link-sel">';
1390 }
1391
1392 // The Image
1393 $li .= '<img class="pagelayer-img" src="'.$final_urls[$v].'" title="'.$image['title'].'" alt="'.$image['alt'].'">';
1394
1395 if(!empty($el['atts']['link_type'])){
1396 $li .= '</a>';
1397 }
1398
1399 $li .= '</li>';
1400
1401 $ul[] = $li;
1402
1403 }
1404
1405 //pagelayer_print($urls);
1406 //pagelayer_print($final_urls);
1407 //pagelayer_print($all_urls);
1408
1409 // Make the TMP vars
1410 if(!empty($urls)){
1411 $el['tmp']['ids-urls'] = json_encode($urls);
1412 $el['tmp']['ids-all-urls'] = json_encode($all_urls);
1413 $el['atts']['ul'] = implode('', $ul);
1414
1415 // Which arrows to show
1416 if(in_array(@$el['atts']['controls'], ['arrows', 'none'])){
1417 $el['attr'][] = ['.pagelayer-image-slider-ul' => 'data-pager="false"'];
1418 }
1419
1420 if(in_array(@$el['atts']['controls'], ['pager', 'none'])){
1421 $el['attr'][] = ['.pagelayer-image-slider-ul' => 'data-controls="false"'];
1422 }
1423 }
1424
1425 };
1426
1427 //Grid Gallery Handler
1428 function pagelayer_sc_grid_gallery(&$el){
1429
1430 if(empty($el['atts']['ids'])){
1431 $el['atts']['ids'] = '';
1432 }
1433
1434 $ids = pagelayer_maybe_explode(',', $el['atts']['ids']);
1435 $urls = [];
1436 $all_urls = [];
1437 $final_urls = [];
1438 $ul = [];
1439 $pagin = '<li class="pagelayer-grid-page-item active">1</li>';
1440 $size = $el['atts']['size'];
1441 $i = 0;
1442 $j = 1;
1443 $img_Page = $el['atts']['images_no'];
1444 $gallery_rand = 'gallery-id-'.floor((rand() * 100) + 1);
1445
1446 $ul[] = '<ul class="pagelayer-grid-gallery-ul">';
1447 // Make the image URL
1448 foreach($ids as $k => $v){
1449
1450 $image = pagelayer_image($v);
1451
1452 $final_urls[$v] = empty($image[$size.'-url']) ? @$image['url'] : $image[$size.'-url'];
1453
1454 $urls['i'.$v] = @$image['url'];
1455 $links['i'.$v] = @$image['link'];
1456 $titles['i'.$v] = @$image['title'];
1457 $captions['i'.$v] = @$image['caption'];
1458
1459 foreach($image as $kk => $vv){
1460 $si = strstr($kk, '-url', true);
1461 if(!empty($si)){
1462 $all_urls['i'.$v][$si] = $vv;
1463 }
1464 }
1465
1466 if($img_Page != 0 && ($i % $img_Page) == 0 && $i != 0 ){
1467 $ul[] = '</ul><ul class="pagelayer-grid-gallery-ul">';
1468 $j++;
1469 $pagin .= '<li class="pagelayer-grid-page-item">'.$j.'</li>';
1470 }
1471
1472 $li = '<li class="pagelayer-gallery-item" >';
1473
1474 if(empty($el['atts']['link_to'])){
1475 $li .= '<div>';
1476 }
1477
1478 // Any Link ?
1479 if(!empty($el['atts']['link_to']) && $el['atts']['link_to'] == 'media_file'){
1480 $link = ($el['atts']['link_to'] == 'media_file' ? $final_urls[$v] : @$el['atts']['link']);
1481 $li .= '<a href="'.$link.'" class="pagelayer-ele-link">';
1482 }
1483
1484 // Any Link ?
1485 if(!empty($el['atts']['link_to']) && $el['atts']['link_to'] == 'attachment' ){
1486 $link = $image['link'];
1487 $li .= '<a href="'.$link.'" class="pagelayer-ele-link">';
1488 }
1489
1490 if(!empty($el['atts']['link_to']) && $el['atts']['link_to'] == 'lightbox'){
1491 $li .= '<a href="'.$image['url'].'" data-lightbox-gallery="'.$gallery_rand.'" alt="'.$image['alt'].'" class="pagelayer-ele-link" pagelayer-grid-gallery-type="'.$el['atts']['link_to'].'">';
1492 }
1493 // The Image
1494 $li .= '<img class="pagelayer-img" src="'.$final_urls[$v].'" title="'.$image['title'].'" alt="'.$image['alt'].'">';
1495
1496 if(!empty($el['atts']['caption'])){
1497 $li .= '<span class="pagelayer-grid-gallery-caption">'.$image['caption'].'</span>';
1498 }
1499
1500 if(!empty($el['atts']['link_to'])){
1501 $li .= '</a>';
1502 }
1503
1504 if(empty($el['atts']['link_to'])){
1505 $li .= '</div>';
1506 }
1507
1508 $li .= '</li>';
1509
1510 $ul[] = $li;
1511 $i++;
1512 }
1513
1514 $ul[] = '</ul>';
1515
1516 $pagiComplete[] = '<div class="pagelayer-grid-gallery-pagination"><ul class="pagelayer-grid-page-ul">'.'<li class="pagelayer-grid-page-item">&laquo;</li>'.$pagin.'<li class="pagelayer-grid-page-item">&raquo;</li>'.'</ul></div>';
1517 //pagelayer_print($urls);
1518 //pagelayer_print($final_urls);
1519 //pagelayer_print($all_urls);
1520
1521 // Make the TMP vars
1522 if(!empty($urls)){
1523 $el['tmp']['ids-urls'] = json_encode($urls);
1524 $el['tmp']['ids-all-urls'] = json_encode($all_urls);
1525 $el['tmp']['ids-all-links'] = json_encode($links);
1526 $el['tmp']['ids-all-titles'] = json_encode($titles);
1527 $el['tmp']['ids-all-captions'] = json_encode($captions);
1528 $el['atts']['ul'] = implode('', $ul);
1529 $el['atts']['pagin'] = ($j>1) ? implode('', $pagiComplete) : '';
1530 $el['tmp']['gallery-random-id'] = $gallery_rand;
1531
1532 }
1533 }
1534
1535 // Testimonial Handler
1536 function pagelayer_sc_testimonial(&$el){
1537
1538 if(empty($el['atts']['avatar']) || !empty($el['tmp']['avatar-no-image-set'])){
1539 $el['atts']['avatar'] = '';
1540 }
1541
1542 $custom_size = empty($el['atts']['custom_size']) ? '' : @$el['tmp']['avatar-'.$el['atts']['custom_size'].'-url'];
1543 $el['atts']['func_image'] = empty($custom_size) ? @$el['tmp']['avatar-url'] : $custom_size;
1544
1545 }
1546
1547 // Video Handler
1548 function pagelayer_sc_video(&$el){
1549
1550 $el['atts']['custom_size'] = empty($el['atts']['custom_size']) ? '' : $el['atts']['custom_size'];
1551 $el['tmp']['video_overlay_image-url'] = empty($el['tmp']['video_overlay_image-url']) ? '' : $el['tmp']['video_overlay_image-url'];
1552 $el['atts']['video_overlay_image'] = empty($el['atts']['video_overlay_image']) ? '' : $el['atts']['video_overlay_image'];
1553
1554 $el['atts']['video_overlay_image-url'] = empty($el['tmp']['video_overlay_image-'.$el['atts']['custom_size'].'-url']) ? $el['tmp']['video_overlay_image-url'] : $el['tmp']['video_overlay_image-'.$el['atts']['custom_size'].'-url'];
1555 $el['atts']['video_overlay_image-url'] = empty($el['atts']['video_overlay_image-url']) ? $el['atts']['video_overlay_image'] : $el['atts']['video_overlay_image-url'];
1556
1557 // Get the video URL for the iframe
1558 $vid_atts = pagelayer_video_url($el['tmp']['src-url'], true);
1559
1560 $vid_atts['src'] .= substr_count($vid_atts['src'], '?') > 0 ? '' : '?';
1561
1562 $vid_atts['src'] .= !empty($el['atts']['autoplay']) ? '&autoplay=1' : '&autoplay=0' ;
1563
1564 $mute = !empty($el['atts']['mute']) ? 1 : 0;
1565 $vid_atts['src'] .='&'.($vid_atts['type'] == 'vimeo' ? 'muted' : 'mute').'='.$mute;
1566
1567 $vid_atts['src'] .= !empty($el['atts']['loop']) == 'true' ? '&loop=1' : '&loop=0' ;
1568
1569 $el['atts']['vid_src'] = $vid_atts['src'].($vid_atts['type'] == 'youtube' ? '&playlist='.$vid_atts['id'] : '');
1570
1571 $el['tmp']['ele_id'] = $el['id'];
1572
1573 }
1574
1575 // Shortcodes Handler
1576 function pagelayer_sc_shortcodes(&$el){
1577 $is_live = pagelayer_is_live();
1578 if(empty($is_live)){
1579 $el['tmp']['shortcode'] = pagelayer_the_content($el['atts']['data']);
1580 }
1581 }
1582
1583 // Missing Handler
1584 function pagelayer_sc_missing(&$el){
1585 if(pagelayer_is_live()){
1586 $el['tmp']['missing_msg'] = __('The pagelayer doesn’t support this content. You can leave this block intact or remove it completely.');
1587 }
1588 }
1589
1590 // Shortcodes Handler
1591 function pagelayer_sc_wp_widgets(&$el){
1592
1593 global $wp_registered_sidebars;
1594
1595 $data = '';
1596 foreach($wp_registered_sidebars as $v){
1597 if($el['atts']['sidebar'] == $v['id']){
1598 ob_start();
1599 dynamic_sidebar($v['id']);
1600 $data = ob_get_clean();
1601 }
1602 }
1603
1604 $el['tmp']['data'] = $data;
1605 }
1606
1607 // Service Handler
1608 function pagelayer_sc_service(&$el){
1609
1610 //Backward compatibility for new link props
1611 pagelayer_add_link_backward($el, array(
1612 'link' => 'box_url',
1613 'rel' => '',
1614 'target' => 'box_target',
1615 'selector' => '.pagelayer-box-link'
1616 ));
1617
1618 //Backward compatibility for new link props
1619 pagelayer_add_link_backward($el, array(
1620 'link' => 'heading_url',
1621 'rel' => '',
1622 'target' => 'heading_target',
1623 'selector' => '.pagelayer-service-heading-link'
1624 ));
1625
1626 //Backward compatibility for new link props
1627 pagelayer_add_link_backward($el, array(
1628 'link' => 'service_button_url',
1629 'rel' => '',
1630 'target' => 'service_button_target',
1631 'selector' => '.pagelayer-service-btn'
1632 ));
1633
1634 if(!empty($el['atts']['service_image'])){
1635
1636 // Decide the image URL
1637 $el['atts']['func_image'] = @$el['tmp']['service_image-'.$el['atts']['service_image_size'].'-url'];
1638 $el['atts']['func_image'] = empty($el['atts']['func_image']) ? @$el['tmp']['service_image-url'] : $el['atts']['func_image'];
1639 $el['atts']['pagelayer-srcset'] = $el['atts']['func_image'].', '.$el['atts']['func_image'].' 1x, ';
1640
1641 $image_atts = array(
1642 'name' => 'service_image',
1643 'size' => 'service_image_size'
1644 );
1645
1646 pagelayer_get_img_srcset($el, $image_atts);
1647
1648 }
1649 }
1650
1651 // Icon box Handler
1652 function pagelayer_sc_iconbox(&$el){
1653
1654 //Backward compatibility for new link props
1655 pagelayer_add_link_backward($el, array(
1656 'link' => 'box_url',
1657 'rel' => '',
1658 'target' => 'box_target',
1659 'selector' => '.pagelayer-box-link'
1660 ));
1661
1662 //Backward compatibility for new link props
1663 pagelayer_add_link_backward($el, array(
1664 'link' => 'heading_url',
1665 'rel' => '',
1666 'target' => 'heading_target',
1667 'selector' => '.pagelayer-service-heading-link',
1668 ));
1669
1670 }
1671
1672 // Anchor Handler
1673 function pagelayer_sc_anchor(&$el){
1674 $el['atts']['title'] = empty($el['atts']['title']) ? '' : esc_attr(sanitize_html_class( $el['atts']['title']));
1675 }
1676
1677 function pagelayer_sc_google_maps(&$el){
1678
1679 $el['atts']['show_v2'] = true;
1680
1681 if(empty($el['atts']['api_version'])){
1682 $el['atts']['src_code'] = '';
1683 return;
1684 }
1685
1686 $el['atts']['show_v2'] = false;
1687 $api_key = @$el['atts']['api_key'];
1688
1689 $gmaps_api = get_option('pagelayer-gmaps-api-key');
1690
1691 if( empty($api_key) && !empty($gmaps_api) ){
1692 $api_key = $gmaps_api;
1693 }
1694
1695 if($el['atts']['map_modes'] == 'view'){
1696 $el['atts']['center'] = empty($el['atts']['center']) ? '-33.8569,151.2152' : $el['atts']['center'];
1697 }
1698
1699 $src_code = (empty($el['atts']['center']) ? '' : '&center='.$el['atts']['center']).($el['atts']['map_modes'] == 'streetview' ? '' : '&maptype='.$el['atts']['map_type'].'&zoom='.$el['atts']['zoom']);
1700
1701 switch($el['atts']['map_modes']){
1702 case 'place':
1703 $src_code .= '&q='.(empty($el['atts']['address']) ? 'New York, New York, USA' : urlencode($el['atts']['address']) );
1704 break;
1705
1706 case 'directions':
1707 $src_code .= '&origin='.(empty($el['atts']['direction_origin']) ? 'Oslow Norway' : urlencode($el['atts']['direction_origin']) );
1708 $src_code .= '&destination='.(empty($el['atts']['direction_destination']) ? 'Telemark Norway' : urlencode($el['atts']['direction_destination']) );
1709 $src_code .= (empty($el['atts']['direction_waypoints']) ? '' : '&waypoints='.join('|', explode(' ', trim($el['atts']['direction_waypoints']))) );
1710 $src_code .= (empty($el['atts']['direction_modes']) ? '' : '&mode='.$el['atts']['direction_modes'] );
1711 $src_code .= (empty($el['atts']['direction_avoid']) ? '' : '&avoid='.join('|', explode(',', $el['atts']['direction_avoid'])) );
1712 $src_code .= (empty($el['atts']['direction_units']) ? '' : '&units='.$el['atts']['direction_units'] );
1713 break;
1714
1715 case 'streetview':
1716 $src_code .= '&pano='.(empty($el['atts']['streetview_pano']) ? 'eTnPNGoy4bxR9LpjjfFuOw' : $el['atts']['streetview_pano'] );
1717 $src_code .= '&location='.(empty($el['atts']['streetview_location']) ? '46.414382,10.013988' : $el['atts']['streetview_location'] );
1718 $src_code .= (empty($el['atts']['streetview_heading']) ? '' : '&heading='.$el['atts']['streetview_heading'] );
1719 $src_code .= (empty($el['atts']['streetview_pitch']) ? '' : '&pitch='.$el['atts']['streetview_pitch'] );
1720 $src_code .= (empty($el['atts']['streetview_fov']) ? '' : '&fov='.$el['atts']['streetview_fov'] );
1721 break;
1722
1723 case 'search':
1724 $src_code .= '&q='.(empty($el['atts']['search_term']) ? 'Record stores in Seattle' : urlencode($el['atts']['search_term']) );
1725 break;
1726
1727 }
1728
1729 $src_iframe = 'https://www.google.com/maps/embed/v1/'.$el['atts']['map_modes'].'?key='.$api_key.$src_code;
1730
1731 $el['atts']['src_code'] = '<iframe width="600" height="450" style="border:0" loading="lazy" allowfullscreen src="'.$src_iframe.'"></iframe>';
1732
1733 }
1734
1735 /*pagelayer_print($atts);
1736 pagelayer_print($content);
1737 die();*/
1738
1739 /////////////////////////////////////
1740 // Miscellaneous Shortcode Functions
1741 /////////////////////////////////////
1742
1743 // The font family list
1744 function pagelayer_font_family(){
1745 return array(
1746 'arial' => 'Arial',
1747 'terminal' => 'Terminal'
1748 );
1749 }
1750
1751 // Supported Icons
1752 function pagelayer_icon_class_list(){
1753 return array();
1754 }
1755
1756 // Function to convert string into set of attributes and their corresponding values.
1757 function pagelayer_string_to_attributes($val){
1758
1759 $final_att = [];
1760 $semi_arr = explode(';', $val);
1761
1762 foreach($semi_arr as $att){
1763
1764 $attrs = preg_split("/=/", trim($att), 2);
1765
1766 if(empty($attrs[0]) || !preg_match("/^[a-z_]+[\w:.-]*$/i", $attrs[0]) ){
1767 continue;
1768 }
1769
1770 if(!isset( $attrs[1])){
1771 $final_att[$attrs[0]] = '';
1772 continue;
1773 }
1774
1775 $final_att[$attrs[0]] = $attrs[1];
1776 }
1777
1778 return $final_att;
1779
1780 }
1781
1782 // Retina image setting attribute.
1783 function pagelayer_get_img_srcset(&$el, $image_atts){
1784
1785 // Check if retina images is set
1786 if(isset($el['tmp'][$image_atts['name'].'-retina-url']) && strpos($el['tmp'][$image_atts['name'].'-retina-url'],'default-image') == false){
1787 $retina_image = @$el['tmp'][$image_atts['name'].'-retina-'.$el['atts'][$image_atts['size']].'-url'];
1788 $retina_image = empty($retina_image) ? @$el['tmp'][$image_atts['name'].'-retina-url'] : $retina_image;
1789 $el['atts']['pagelayer-srcset'] .= $retina_image.' 2x, ';
1790 }
1791
1792 // Check if retina mobile images is set
1793 if(isset($el['tmp'][$image_atts['name'].'-retina-mobile-url']) && strpos($el['tmp'][$image_atts['name'].'-retina-mobile-url'],'default-image') == false){
1794 $retina_image_mobile = @$el['tmp'][$image_atts['name'].'-retina-mobile-'.$el['atts'][$image_atts['size']].'-url'];
1795 $retina_image_mobile = empty($retina_image_mobile) ? @$el['tmp'][$image_atts['name'].'-retina-mobile-url'] : $retina_image_mobile;
1796 $el['atts']['pagelayer-srcset'] .= $retina_image_mobile.' 3x';
1797 }
1798 }
1799
1800 // Backward compatibility of target and rel attrs for link
1801 function pagelayer_add_link_backward(&$el, $atts = array()){
1802 global $pagelayer;
1803
1804 $defaults = array(
1805 'link' => 'link',
1806 'target' => 'target',
1807 'rel' => 'rel',
1808 'selector' => 0,
1809 );
1810
1811 $_atts = wp_parse_args( $atts, $defaults );
1812
1813 if(empty($el['atts'][$_atts['link']])){
1814 return;
1815 }
1816
1817 $link = array();
1818
1819 if(!empty($_atts['target']) && !empty($el['atts'][$_atts['target']]) ){
1820 $link['target'] = true;
1821 unset($el['oAtts'][$_atts['target']]);
1822 }
1823
1824 if(!empty($_atts['rel']) && !empty($el['atts'][$_atts['rel']]) ){
1825 $link['attrs'] = 'rel='.$el['atts'][$_atts['rel']];
1826 unset($el['oAtts'][$_atts['rel']]);
1827 }
1828
1829 if(empty($link)){
1830 return;
1831 }
1832
1833 // Set Attributes for backward compatibility
1834 if(!empty($link['target'])){
1835 $el['attr'][][$_atts['selector']] = 'target="_blank"';
1836 }
1837
1838 // Set Attributes for backward compatibility
1839 if(!empty($link['attrs']) ){
1840 $el['attr'][][$_atts['selector']] = $link['attrs'];
1841 }
1842
1843 if(!is_array($el['atts'][$_atts['link']])){
1844 $link['link'] = @$el['atts'][$_atts['link']];
1845 }
1846
1847 $el['oAtts'][$_atts['link']] = $link;
1848 $el['atts'][$_atts['link']] = $link;
1849 }
1850