PluginProbe
Page Builder: Pagelayer – Drag and Drop website builder / 0.9.4
Page Builder: Pagelayer – Drag and Drop website builder v0.9.4
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 0.9.4, at main/shortcode_functions.php

1,265 lines 32.4 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 tag ?
28 function pagelayer_render_shortcode($atts, $content = '', $tag = ''){
29
30 global $pagelayer;
31
32 $_tag = $class = $tag;
33 $final_tag = $tag;
34
35 // Check if the tag is inner row and col then change it to row and col tag
36 if($tag == 'pl_inner_row'){
37 $tag = 'pl_row';
38 }elseif($tag == 'pl_inner_col'){
39 $tag = 'pl_col';
40 $final_tag = $tag;
41 }
42
43 // Clear the pagelayer tags
44 if(substr($tag, 0, 3) == 'pl_'){
45 $_tag = str_replace('pl_', '', $final_tag);
46 $class = 'pagelayer-'.$_tag;
47 }
48
49 // Is there any function ?
50 $func = @$pagelayer->shortcodes[$tag]['func'];
51
52 // Create the element array. NOTE : This is similar to the JS el and is temporary
53 $el = [];
54 $el['atts'] = $atts;
55 $el['oAtts'] = $atts;
56 $el['id'] = pagelayer_RandomString(16);
57 $el['tmp'] = [];
58 $el['tag'] = $final_tag;
59 $el['content'] = $content;
60 $el['selector'] = '[pagelayer-id="'.$el['id'].'"]';
61
62 $innerHTML = @$pagelayer->shortcodes[$tag]['innerHTML'];
63 if(!empty($innerHTML) && !empty($content)){
64 $el['oAtts'][$innerHTML] = $content;
65 $el['atts'][$innerHTML] = $content;
66 }
67
68 // The default class
69 $el['classes'][] = $class;
70
71 //pagelayer_print($el);
72
73 // Lets create the CSS, Classes, Attr. Also clean the dependent atts
74 foreach($pagelayer->tabs as $tab){
75
76 if(empty($pagelayer->shortcodes[$tag][$tab])){
77 continue;
78 }
79
80 foreach($pagelayer->shortcodes[$tag][$tab] as $section => $Lsection){
81
82 $props = empty($pagelayer->shortcodes[$tag][$section]) ? @$pagelayer->styles[$section] : @$pagelayer->shortcodes[$tag][$section];
83
84 //echo $tab.' - '.$section.' - <br>';
85
86 if(empty($props)){
87 continue;
88 }
89
90 foreach($props as $prop => $param){
91
92 //echo $tab.' - '.$section.' - '.$prop.'<br>';
93
94 // No value set
95 if(empty($el['atts'][$prop]) && empty($el['atts'][$prop.'_tablet']) && empty($el['atts'][$prop.'_mobile'])){
96 continue;
97 }
98
99 // Clean the not required atts
100 if(!empty($param['req'])){
101
102 $set = true;
103
104 foreach($param['req'] as $rk => $reqval){
105 $except = $rk{0} == '!' ? true : false;
106 $rk = $except ? substr($rk, 1) : $rk;
107 $val = @$el['atts'][$rk];
108
109 //echo $prop.' - '.$rk.' : '.$reqval.' == '.$val.'<br>';
110
111 // The value should not be there
112 if($except){
113
114 if(!is_array($reqval) && $reqval == $val){
115 $set = false;
116 break;
117 }
118
119 // Its an array and a value is found, then dont show
120 if(is_array($reqval) && in_array($val, $reqval)){
121 $set = false;
122 break;
123 }
124
125 // The value must be equal
126 }else{
127
128 if(!is_array($reqval) && $reqval != $val){
129 $set = false;
130 break;
131 }
132
133 // Its an array and no value is found, then dont show
134 if(is_array($reqval) && !in_array($val, $reqval)){
135 $set = false;
136 break;
137 }
138 }
139
140 }
141
142 // Unset as we dont need
143 if(empty($set)){
144 unset($el['atts'][$prop]);
145 unset($el['atts'][$prop.'_tablet']);
146 unset($el['atts'][$prop.'_mobile']);
147 }
148
149 }
150
151 // We could have unset the value above, so we need to check again if the value is there
152 if(empty($el['atts'][$prop]) && empty($el['atts'][$prop.'_tablet']) && empty($el['atts'][$prop.'_mobile'])){
153 continue;
154 }
155
156 // Handle the edit fields
157 if(!empty($param['edit'])){
158 $el['edit'][$prop] = $param['edit'];
159 }
160
161 // Load any attachment values
162 if(in_array($param['type'], ['image', 'video', 'audio', 'media'])){
163
164 $attachment = ($param['type'] == 'image') ? pagelayer_image($el['atts'][$prop]) : pagelayer_attachment($el['atts'][$prop]);
165
166 if(!empty($attachment)){
167 foreach($attachment as $k => $v){
168 $el['tmp'][$prop.'-'.$k] = $v;
169 }
170 }
171
172 }
173
174 // Handle the AddClasses
175 if(!empty($param['addClass']) && !empty($el['atts'][$prop])){
176
177 // Convert to an array
178 if(!is_array($param['addClass'])){
179 $param['addClass'] = array($param['addClass']);
180 }
181
182 // Loop through
183 foreach($param['addClass'] as $k => $v){
184 $k = str_replace('{{element}}', '', $k);
185 $el['classes'][] = [trim($k) => str_replace('{{val}}', $el['atts'][$prop], $v)];
186 }
187
188 }
189
190 // Handle the AddClasses
191 if(!empty($param['addAttr']) && !empty($el['atts'][$prop])){
192
193 // Convert to an array
194 if(!is_array($param['addAttr'])){
195 $param['addAttr'] = array($param['addAttr']);
196 }
197
198 // Loop through
199 foreach($param['addAttr'] as $k => $v){
200 $k = str_replace('{{element}}', '', $k);
201 $el['attr'][] = [trim($k) => $v];
202 }
203
204 }
205
206 // Handle the CSS
207 if(!empty($param['css'])){
208 //echo $prop.'<br>';
209 // Convert to an array
210 if(!is_array($param['css'])){
211 $param['css'] = array($param['css']);
212 }
213
214 $modes = [
215 'desktop' => '',
216 'tablet' => '_tablet',
217 'mobile' => '_mobile'
218 ];
219
220 // Loop the modes and check for values
221 foreach($modes as $mk => $mv){
222
223 $M_prop = $prop.$mv;
224
225 // Any value ?
226 if(empty($el['atts'][$M_prop])){
227 continue;
228 }
229
230 // Loop through
231 foreach($param['css'] as $k => $v){
232
233 // Make the selector
234 $selector = (!is_numeric($k) ? str_replace('{{element}}', $el['selector'], $k) : $el['selector']);
235
236 $ender = '';
237
238 if($mk == 'tablet'){
239 $selector = '@media (max-width: 768px) and (min-width: 361px){'.$selector;
240 $ender = '}';
241 }
242
243 if($mk == 'mobile'){
244 $selector = '@media (max-width: 360px){'.$selector;
245 $ender = '}';
246 }
247
248 // Make the CSS
249 $el['css'][] = $selector.'{'.pagelayer_css_render($v, $el['atts'][$M_prop], @$param['sep']).'}'.$ender;
250 }
251
252 }
253
254 }
255
256 if($param['type'] == 'typography'){
257 $val = explode(',', $el['atts'][$prop]);
258
259 if(!empty($val[0]) && !in_array($val[0], $pagelayer->runtime_fonts)){
260 $pagelayer->runtime_fonts[] = $val[0];
261 //pagelayer_print($pagelayer->runtime_fonts);
262 }
263 }
264
265 }
266
267 }
268
269 }
270
271 //@pagelayer_print($el['css']);
272
273 // Is there a function of the tag ?
274 if(function_exists($func)){
275 call_user_func_array($func, array(&$el));
276 }
277
278 // Create the default atts and tmp atts
279 if(pagelayer_is_live()){
280 pagelayer_create_sc($el);
281 }
282
283 $div = '<div pagelayer-id="'.$el['id'].'">
284 <style pagelayer-style-id="'.$el['id'].'"></style>';
285
286 $is_group = !empty($pagelayer->shortcodes[$tag]['params']['elements']) ? true : false;
287
288 // If there is an HTML AND you are not a GROUP, then make use of it, or append the real content
289 if(!empty($pagelayer->shortcodes[$tag]['html'])){
290
291 // Create the HTML object
292 $node = pQuery::parseStr($pagelayer->shortcodes[$tag]['html']);
293
294 // Remove the if-ext
295 foreach($node('[if-ext]') as $v){
296 $reqvar = pagelayer_var($v->attr('if-ext'));
297 $v->removeAttr('if-ext');
298
299 // Is the element there ?
300 if(empty($el['atts'][$reqvar])){
301 $v->after($v->html());
302 $v->remove();
303 }
304 }
305
306 // Remove the if
307 foreach($node('[if]') as $v){
308 $reqvar = pagelayer_var($v->attr('if'));
309 $v->removeAttr('if');
310
311 // Is the element there ?
312 if(empty($el['atts'][$reqvar])){
313 $v->remove();
314 }
315 }
316
317 //die($node->html());
318
319 // Do we have a holder ? Mainly for groups
320 if(!empty($pagelayer->shortcodes[$tag]['holder'])){
321 $node->query($pagelayer->shortcodes[$tag]['holder'])->html('{{pagelayer_do_shortcode}}');
322 $do_shortcode = 1;
323 }
324
325 $html = pagelayer_parse_vars($node->html(), $el);
326
327 // Append to the DIV
328 $div .= $html;
329
330 // Is it a widget ?
331 }elseif(!empty($pagelayer->shortcodes[$tag]['widget'])){
332
333 $class = $pagelayer->shortcodes[$tag]['widget'];
334 $instance = [];
335
336 // Is there any existing data ?
337 if(!empty($el['atts']['widget_data'])){
338 $json = trim($el['atts']['widget_data']);
339 $json = json_decode($json, true);
340 //pagelayer_print($json);die();
341 if(!empty($json)){
342 $instance = $json;
343 }
344 }
345
346 ob_start();
347 the_widget($class, $instance, array('widget_id'=>'arbitrary-instance-'.$el['id'],
348 'before_widget' => '',
349 'after_widget' => '',
350 'before_title' => '',
351 'after_title' => ''
352 ));
353
354 $div .= ob_get_contents();
355 ob_end_clean();
356
357 }else{
358 $div .= '{{pagelayer_do_shortcode}}';
359 $do_shortcode = 1;
360 }
361
362 // End the tag
363 $div .= '</div>';
364
365 // Add classes and attributes
366 if(!empty($el['classes']) || !empty($el['attr'])){
367
368 // Create the HTML object
369 $node = pQuery::parseStr($div);
370
371 // Add the editable values
372 if(!empty($el['edit'])){
373
374 foreach($el['edit'] as $k => $v){
375 $node->query($v)->attr('pagelayer-editable', $k);
376 }
377
378 }
379
380 // Add the classes
381 if(!empty($el['classes'])){
382
383 //pagelayer_print($el['classes']);
384
385 foreach($el['classes'] as $k => $v){
386
387 if(!is_array($v)){
388 $v = [$v];
389 }
390
391 foreach($v as $kk => $vv){
392 //echo $kk.' - '.$vv."\n";
393 if(is_numeric($kk)){
394 $node->query($el['selector'])->addClass($vv);
395 }else{
396 $node->query($kk)->addClass($vv);
397 }
398
399 }
400
401 }
402
403 //echo $node->html();
404 //die();
405
406 }
407
408 // Add the attributes
409 if(!empty($el['attr'])){
410
411 //pagelayer_print($el['attr']);
412
413 foreach($el['attr'] as $k => $v){
414
415 if(!is_array($v)){
416 $v = [$v];
417 }
418
419 foreach($v as $kk => $vv){
420
421 $att = explode('=', $vv, 2);
422 $att[1] = pagelayer_parse_vars($att[1], $el);
423 $att[1] = trim($att[1], '"');
424
425 if(is_numeric($kk)){
426 $node->query($el['selector'])->attr($att[0], $att[1]);
427 }else{
428 $node->query($kk)->attr($att[0], $att[1]);
429 }
430
431 }
432
433 }
434
435 }
436
437 $div = $node->html();
438 //die($div);
439
440 }
441
442 // Add the CSS if any or remove it
443 $style = '';
444 if(!empty($el['css'])){
445
446 $style = '<style pagelayer-style-id="'.$el['id'].'">
447 '.implode("\n", pagelayer_parse_vars($el['css'], $el)).'
448 </style>';
449
450 }
451
452 $div = str_replace('<style pagelayer-style-id="'.$el['id'].'"></style>', $style, $div);
453
454 // Is there an inner content which requires a SHORTCODE ?
455 if(!empty($do_shortcode)){
456 $div = str_replace('{{pagelayer_do_shortcode}}', do_shortcode($el['content']), $div);
457 }
458
459 return $div;
460
461 }
462
463 // Creates the shortcode and returns a base64 encoded files
464 function pagelayer_create_sc(&$el){
465
466 $a = $tmp = array();
467
468 if(!empty($el['oAtts'])){
469
470 foreach($el['oAtts'] as $k => $v){
471 $el['attr'][] = 'pagelayer-a-'.$k.'="'.$v.'"';
472 }
473
474 }
475
476 // Tmp atts
477 if(!empty($el['tmp'])){
478
479 foreach($el['tmp'] as $k => $v){
480 $el['attr'][] = 'pagelayer-tmp-'.$k.'="'.$v.'"';
481 }
482
483 }
484
485 // Add the tag
486 $el['attr'][] = 'pagelayer-tag="'.$el['tag'].'"';
487
488 // Make it a PageLayer element for editing
489 $el['classes'][] = 'pagelayer-ele';
490
491 }
492
493 // Converts {{val}} to val
494 function pagelayer_var($var){
495 return substr($var, 2, -2);
496 }
497
498 // Parse the variables
499 function pagelayer_parse_vars($str, &$el){
500
501 //pagelayer_print($el);
502 if(is_array($el['tmp'])){
503 foreach($el['tmp'] as $k => $v){
504 $str = str_replace('{{{'.$k.'}}}', $el['tmp'][$k], $str);
505 }
506 }
507
508 if(is_array($el['atts'])){
509 foreach($el['atts'] as $k => $v){
510 $str = str_replace('{{'.$k.'}}', $el['atts'][$k], $str);
511 }
512 }
513
514 return $str;
515 }
516
517 // Make the rule
518 function pagelayer_css_render($rule, $val, $sep = ','){
519
520 // Seperator
521 $sep = empty($sep) ? ',' : $sep;
522
523 // Replace the val
524 $rule = str_replace('{{val}}', $val, $rule);
525
526 // If there is an array
527 if(preg_match('/\{val\[\d/is', $rule)){
528 $val = explode($sep, $val);
529 foreach($val as $k => $v){
530 $rule = str_replace('{{val['.$k.']}}', $v, $rule);
531 }
532 }
533
534 return $rule;
535
536 }
537
538 // ROW Handler
539 function pagelayer_sc_row(&$el){
540 pagelayer_bg_video($el);
541
542 if(!empty($el['atts']['row_shape_type_top'])){
543 $path_top = PAGELAYER_DIR.'/images/shapes/'.$el['atts']['row_shape_type_top'].'-top.svg';
544 $el['atts']['svg_top'] = file_get_contents($path_top);
545 }
546
547 if(!empty($el['atts']['row_shape_type_bottom'])){
548 $path_bottom = PAGELAYER_DIR.'/images/shapes/'.$el['atts']['row_shape_type_bottom'].'-bottom.svg';
549 $el['atts']['svg_bottom'] = file_get_contents($path_bottom);
550 }
551 }
552
553 // Column Handler
554 function pagelayer_sc_col(&$el){
555
556 // Add the default col class
557 $el['classes'][] = 'pagelayer-col';
558
559 //return do_shortcode($el['content']);
560
561 pagelayer_bg_video($el);
562
563 }
564
565 // Just for BG handling
566 function pagelayer_bg_video(&$el){
567
568 if(empty($el['tmp']['bg_video_src-url'])){
569 return false;
570 }
571
572 // Get the video URL for the iframe
573 $iframe_src = pagelayer_video_url($el['tmp']['bg_video_src-url']);
574
575 $source = filter_var($el['tmp']['bg_video_src-url'], FILTER_SANITIZE_URL);
576 $source = str_replace('&amp;', '&', $source);
577 $url = parse_url($source);
578
579 $youtubeRegExp = '/youtube\.com|youtu\.be/is';
580 $vimeoRegExp = '/vimeo\.com/is';
581
582 if (!empty($source)) {
583
584 if (preg_match($youtubeRegExp, $source)) {
585 if (preg_match('/youtube\.com/is', $source)) {
586
587 if (preg_match('/watch/is', $source)) {
588 parse_str($url['query'], $parameters);
589
590 if (isset($parameters['v']) && !empty($parameters['v'])) {
591 $videoId = $parameters['v'];
592 }
593
594 } else if (preg_match('/embed/is', $url['path'])) {
595 $path = explode('/', $url['path']);
596 if (isset($path[2]) && !empty($path[2])) {
597 $videoId = $path[2];
598 }
599 }
600
601 } else if (preg_match('/youtu\.be/is', $url['host'])) {
602 $path = explode('/', $url['path']);
603
604 if (isset($path[1]) && !empty($path[1])) {
605 $videoId = $path[1];
606 }
607
608 }
609
610 $el['atts']['vid_src'] = '<iframe src="'.$iframe_src.'?autoplay=1&controls=0&showinfo=0&rel=0&loop=1&autohide=1&playlist='.$videoId.'" allowfullscreen="1" webkitallowfullscreen="1" mozallowfullscreen="1" frameborder="0"></iframe>';
611
612 } else if (preg_match($vimeoRegExp, $source)) {
613
614 $el['atts']['vid_src'] = '<iframe src="'.$iframe_src.'?background=1&autoplay=1&loop=1&byline=0&title=0" allowfullscreen="1" webkitallowfullscreen="1" mozallowfullscreen="1" frameborder="0"></iframe>';
615
616 }else{
617
618 $el['atts']['vid_src'] = '<video autoplay loop>'.
619 '<source src="'.$iframe_src.'" type="video/mp4">'.
620 '</video>';
621
622 }
623 }
624 }
625
626 // Heading
627 function pagelayer_sc_heading($atts, $content = '', $tag = ''){
628 //return '<div '.pagelayer_create_sc($tag, $atts, 'pagelayer-text').'>'.$content.'</div>';
629 }
630
631 // Text
632 function pagelayer_sc_text($atts, $content = '', $tag = ''){
633 //return '<div '.pagelayer_create_sc($tag, $atts, 'pagelayer-text').'>'.$content.'</div>';
634 }
635
636 // Rich Text Handler
637 function pagelayer_sc_code($atts, $content = '', $tag = ''){
638 //return '<div '.pagelayer_create_sc($tag, $atts, 'pagelayer-text').'>'.$content.'</div>';
639 }
640
641 // List Handler
642 function pagelayer_sc_list($atts, $content = '', $tag = ''){
643 return;
644 $items = [];
645 $list = $list_type = $icon_type = $icon_color = $text_color = $ul = $ol = $type = '';
646 $i_item = '';
647 if($atts['items']){
648 $items = preg_split('/\r\n|\r|\n/', ($atts['items']));
649 }
650
651 $list_type = $atts['list_type'];
652 $ul = array('circle', 'disc', 'square', 'armenian', 'georgian');
653 $ol = array('decimal', 'decimal-leading-zero', 'lower-latin', 'lower-roman', 'lower-greek', 'upper-latin', 'upper-roman');
654
655 $icon_type = $atts['icon'];
656 $icon_color = $atts['icon_color'];
657 $text_color = $atts['text_color'];
658
659 if(in_array($list_type, $ul)){
660
661 $type = 'ul';
662 }
663
664 if(in_array($list_type, $ol)){
665 $type = 'ol';
666 }
667
668 if($list_type == 'icon'){
669 $type = 'ul';
670 $i_item = '<i class="'.$icon_type .'" style="color:'. $icon_color .'"></i>';
671 }
672 if($list_type == 'none'){
673 $type = 'undefined';
674 }
675
676 $list = '<'. $type .' class="pagelayer-list-item">';
677
678 foreach($items as $x){
679 $list .= '<li class="pagelayer-list-'.$list_type.'" >'. $i_item .'<span style="color:'. $text_color .'">'.$x.'</span></li>';
680
681 }
682
683 $list .= '</'. $type .'>';
684
685
686 return '<div '.pagelayer_create_sc($tag, $atts, 'pagelayer-list').'>'.$list.'</div>';
687 }
688
689 // Image Handler
690 function pagelayer_sc_image(&$el){
691
692 // Decide the image URL
693 $el['atts']['func_id'] = @$el['tmp']['id-'.$el['atts']['id-size'].'-url'];
694 $el['atts']['func_id'] = empty($el['atts']['func_id']) ? @$el['tmp']['id-full-url'] : $el['atts']['func_id'];
695
696 // What is the link ?
697 if(!empty($el['atts']['link_type'])){
698
699 // Custom url
700 if($el['atts']['link_type'] == 'custom_url'){
701 $el['atts']['func_link'] = $el['atts']['link'];
702 }
703
704 // Link to the media file itself
705 if($el['atts']['link_type'] == 'media_file'){
706 $el['atts']['func_link'] = $el['atts']['func_id'];
707 }
708
709 // Lightbox
710 if($el['atts']['link_type'] == 'lightbox'){
711 $el['atts']['func_link'] = $el['atts']['func_id'];
712 }
713
714 }
715
716 //pagelayer_print($el);
717
718 }
719
720 // Image Slider Handler
721 function pagelayer_sc_image_slider(&$el){
722
723 $ids = explode(',', $el['atts']['ids']);
724 $urls = [];
725 $all_urls = [];
726 $final_urls = [];
727 $ul = [];
728 $size = $el['atts']['size'];
729
730 // Make the image URL
731 foreach($ids as $k => $v){
732
733 $image = pagelayer_image($v);
734
735 $final_urls[$v] = empty($image[$size.'-url']) ? @$image['full-url'] : $image[$size.'-url'];
736
737 $urls['i'.$v] = @$image['full-url'];
738
739 foreach($image as $kk => $vv){
740 $si = strstr($kk, '-url', true);
741 if(!empty($si)){
742 $all_urls['i'.$v][$si] = $vv;
743 }
744 }
745
746 $li = '<li class="pagelayer-slider-item">';
747
748 // Any Link ?
749 if(!empty($el['atts']['link_type'])){
750 $link = ($el['atts']['link_type'] == 'media_file' ? $final_urls[$v] : @$el['atts']['link']);
751 $li .= '<a href="'.$link.'">';
752 }
753
754 // The Image
755 $li .= '<img src="'.$final_urls[$v].'">';
756
757 if(!empty($el['atts']['link_type'])){
758 $li .= '</a>';
759 }
760
761 $li .= '</li>';
762
763 $ul[] = $li;
764
765 }
766
767 //pagelayer_print($urls);
768 //pagelayer_print($final_urls);
769 //pagelayer_print($all_urls);
770
771 // Make the TMP vars
772 if(!empty($urls)){
773 $el['tmp']['ids-urls'] = json_encode($urls);
774 $el['tmp']['ids-all-urls'] = json_encode($all_urls);
775 $el['atts']['ul'] = implode('', $ul);
776
777 // Which arrows to show
778 if(in_array(@$el['atts']['controls'], ['arrows', 'none'])){
779 $el['attr'][] = ['.pagelayer-image-slider-ul' => 'data-pager="false"'];
780 }
781
782 if(in_array(@$el['atts']['controls'], ['pager', 'none'])){
783 $el['attr'][] = ['.pagelayer-image-slider-ul' => 'data-controls="false"'];
784 }
785 }
786
787 };
788
789 //Grid Gallery Handler
790 function pagelayer_sc_grid_gallery(&$el){
791
792 $ids = explode(',', $el['atts']['ids']);
793 $urls = [];
794 $all_urls = [];
795 $final_urls = [];
796 $ul = [];
797 $size = $el['atts']['size'];
798 $i = 0;
799 $col = $el['atts']['columns'];
800 $gallery_rand = 'gallery-id-'.floor((rand() * 100) + 1);
801
802 $ul[] = '<ul class="pagelayer-grid-gallery-ul">';
803 // Make the image URL
804 foreach($ids as $k => $v){
805
806 $image = pagelayer_image($v);
807
808 $final_urls[$v] = empty($image[$size.'-url']) ? @$image['full-url'] : $image[$size.'-url'];
809
810 $urls['i'.$v] = @$image['full-url'];
811 $links['i'.$v] = @$image['link'];
812 $titles['i'.$v] = @$image['title'];
813 $captions['i'.$v] = @$image['caption'];
814
815 foreach($image as $kk => $vv){
816 $si = strstr($kk, '-url', true);
817 if(!empty($si)){
818 $all_urls['i'.$v][$si] = $vv;
819 }
820 }
821
822 if(($i % $col) == 0 && $i != 0 ){
823 $ul[] = '</ul><ul class="pagelayer-grid-gallery-ul">';
824 }
825
826 $li = '<li class="pagelayer-gallery-item" >';
827
828 if(empty($el['atts']['link_to'])){
829 $li .= '<div>';
830 }
831
832 // Any Link ?
833 if(!empty($el['atts']['link_to']) && $el['atts']['link_to'] == 'media_file'){
834 $link = ($el['atts']['link_to'] == 'media_file' ? $final_urls[$v] : @$el['atts']['link']);
835 $li .= '<a href="'.$link.'" class="pagelayer-ele-link">';
836 }
837
838 // Any Link ?
839 if(!empty($el['atts']['link_to']) && $el['atts']['link_to'] == 'attachment' ){
840 $link = $image['link'];
841 $li .= '<a href="'.$link.'" class="pagelayer-ele-link">';
842 }
843
844 if(!empty($el['atts']['link_to']) && $el['atts']['link_to'] == 'lightbox'){
845 $li .= '<a href="'.$image['full-url'].'" data-lightbox-gallery="'.$gallery_rand.'" alt="'.$image['alt'].'" class="pagelayer-ele-link" pagelayer-grid-gallery-type="'.$el['atts']['link_to'].'">';
846 }
847 // The Image
848 $li .= '<img src="'.$final_urls[$v].'" title="'.$image['title'].'" alt="'.$image['alt'].'">';
849
850 if(!empty($el['atts']['caption'])){
851 $li .= '<span class="pagelayer-grid-gallery-caption">'.$image['caption'].'</span>';
852 }
853
854 if(!empty($el['atts']['link_to'])){
855 $li .= '</a>';
856 }
857
858 if(empty($el['atts']['link_to'])){
859 $li .= '</div>';
860 }
861
862 $li .= '</li>';
863
864 $ul[] = $li;
865 $i++;
866 }
867
868 $ul[] = '</ul>';
869
870 //pagelayer_print($urls);
871 //pagelayer_print($final_urls);
872 //pagelayer_print($all_urls);
873
874 // Make the TMP vars
875 if(!empty($urls)){
876 $el['tmp']['ids-urls'] = json_encode($urls);
877 $el['tmp']['ids-all-urls'] = json_encode($all_urls);
878 $el['tmp']['ids-all-links'] = json_encode($links);
879 $el['tmp']['ids-all-titles'] = json_encode($titles);
880 $el['tmp']['ids-all-captions'] = json_encode($captions);
881 $el['atts']['ul'] = implode('', $ul);
882 $el['tmp']['gallery-random-id'] = $gallery_rand;
883
884 }
885 }
886
887 // Image Handler
888 function pagelayer_sc_audio(&$el){
889
890 return;
891
892 $el['atts']['a_url'] = '';
893
894 if ($el['atts']['source'] == 'external'){
895 $el['atts']['a_url'] = $el['atts']['url'];
896 }
897
898 if ($el['atts']['source'] == 'library'){
899
900 $el['atts']['a_url'] = wp_get_attachment_url($el['atts']['id']);
901 }
902 if(!empty($el['atts']['a_url'])){
903
904 $filename=$el['atts']['a_url'];
905
906 //Get the file extension
907
908 $extension = pathinfo($filename, PATHINFO_EXTENSION);
909
910
911 //Create source tag according to audio file
912 switch($extension){
913
914 default:
915 case 'mp3':
916 $el['atts']['a_type'] = 'audio/mpeg';
917 break;
918
919 case 'ogg':
920 $el['atts']['a_type']= 'audio/ogg';
921 break;
922
923 case 'wav':
924 $el['atts']['a_type'] = 'audio/wav';
925 break;
926 }
927 }
928
929 if(!empty($el['atts']['a_url']) && !empty($el['atts']['a_type'])){
930 $el['attr'][]= ['source' => 'src="{{a_url}}'];
931 $el['attr'][]= ['source' => 'type="{{a_type}}'];
932 }
933
934 }
935
936 // Social Share Handler
937 function pagelayer_sc_share(&$el){
938
939 $labelList = array(
940 'Facebook' => array(
941 'icons' => array('facebook', 'facebook-official', 'facebook-square'),
942 'url' => 'https://www.facebook.com/sharer/sharer.php?u='
943 ),
944 'Twitter' => array(
945 'icons' => array('twitter', 'twitter-square'),
946 'url' => 'https://twitter.com/share?url='
947 ),
948 'Google+' => array(
949 'icons' => array('google-plus', 'google-plus-square'),
950 'url' => 'https://plus.google.com/share?url='
951 ),
952 'Instagram' => array(
953 'icons' => array('instagram'),
954 'url' => ''
955 ),
956 'Linkedin' => array(
957 'icons' => array('linkedin', 'linkedin-square'),
958 'url' => 'https://www.linkedin.com/shareArticle?url='
959 ),
960 'pinterest' => array(
961 'icons' => array('pinterest', 'pinterest-p', 'pinterest-square'),
962 'url' => '//www.pinterest.com/pin/create/button/?url='
963 ),
964 'Reddit' => array(
965 'icons' => array('reddit-alien', 'reddit-square', 'reddit'),
966 'url' => 'https://reddit.com/submit?url='
967 ),
968 'Skype' => array(
969 'icons' => array('skype'),
970 'url' => ''
971 ),
972 'Stumbleupon' => array(
973 'icons' => array('stumbleupon'),
974 'url' => 'https://www.stumbleupon.com/submit?url='
975 ),
976 'Telegram' => array(
977 'icons' => array('telegram'),
978 'url' => 'https://t.me/share/url?url='
979 ),
980 'Tumblr' => array(
981 'icons' => array('tumblr', 'tumblr-square'),
982 'url' => 'https://www.tumblr.com/share/link?url='
983 ),
984 'VK' => array(
985 'icons' => array('vk'),
986 'url' => 'http://vk.com/share.php?url='
987 ),
988 'Weibo' => array(
989 'icons' => array('weibo'),
990 'url' => 'http://service.weibo.com/share/share.php?url='
991 ),
992 'WhatsApp' => array(
993 'icons' => array('whatsapp'),
994 'url' => 'whatsapp://send?text='
995 ),
996 'WordPress' => array(
997 'icons' => array('wordpress'),
998 'url' => 'https://wordpress.com/press-this.php?u='
999 ),
1000 'Xing' => array(
1001 'icons' => array('xing', 'xing-square'),
1002 'url' => 'https://www.xing.com/spi/shares/new?url='
1003 ),
1004 'Delicious' => array(
1005 'icons' => array('delicious'),
1006 'url' => 'https://delicious.com/save?v=5&noui&jump=close&url='
1007 ),
1008 'Dribbble' => array(
1009 'icons' => array('dribbble'),
1010 'url' => ''
1011 )
1012 );
1013
1014 if(!empty($el['atts']['text'])){
1015 $el['atts']['icon_label'] = $el['atts']['text'];
1016 }else{
1017 foreach($labelList as $key => $val){
1018 if(in_array($el['atts']['icon'], $val['icons'])){
1019 $el['atts']['icon_label'] = $key;
1020 break;
1021 }
1022 }
1023 }
1024
1025 foreach($labelList as $key => $val){
1026 if(in_array($el['atts']['icon'], $val['icons'])){
1027 $el['atts']['social_url'] = $val['url'].$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];;
1028 break;
1029 }
1030 }
1031 }
1032
1033 // Posts Grid
1034 function pagelayer_sc_wp_posts_grid($atts, $content = '', $tag = ''){
1035
1036 $args = array(
1037 'numberposts' => -1,
1038 'post_type' => 'post',
1039 'post_status' => array('publish', 'pending', 'draft', 'future', 'private', 'inherit', 'trash')
1040 );
1041 $all_posts = get_posts($args);
1042
1043 $html = '<div '.pagelayer_create_sc($tag, $atts, 'pagelayer-posts-grid').'>';
1044
1045 //pagelayer_print($all_posts);
1046 foreach($all_posts as $pk => $pv){
1047 $post_link = get_permalink($pv->ID);
1048 $html .= '<div>
1049 <h2><a href="'.$post_link.'">'.$pv->post_title.'</a></h2>
1050 <p>'.date('F jS, Y', strtotime($pv->post_date)).' | Published by <a href="'.site_url('author/'.get_the_author_meta('user_login', $pv->post_author)).'">'.get_the_author_meta('display_name', $pv->post_author).'</a></p>
1051 <p>'.do_shortcode($pv->post_content).'</p>
1052 <p><a href="'.$post_link.'">Read More</a></p>
1053 </div>';
1054 }
1055
1056 $html .= '</div>';
1057
1058 return $html;
1059 }
1060
1061 // Video Handler
1062 function pagelayer_sc_video(&$el){
1063
1064 $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'];
1065 $el['atts']['video_overlay_image-url'] = empty($el['atts']['video_overlay_image-url']) ? $el['atts']['video_overlay_image'] : $el['atts']['video_overlay_image-url'];
1066
1067 // Get the video URL for the iframe
1068 $el['atts']['vid_src'] = pagelayer_video_url($el['tmp']['src-url']);
1069
1070 if($el['atts']['autoplay'] == "true"){
1071 $el['atts']['vid_src'] .="?&autoplay=1";
1072 }else{
1073 $el['atts']['vid_src'] .="?&autoplay=0";
1074 }
1075
1076 if($el['atts']['mute'] == "true"){
1077 $el['atts']['vid_src'] .="&mute=1";
1078 }else{
1079 $el['atts']['vid_src'] .="&mute=0";
1080 }
1081
1082 if($el['atts']['loop'] == "true"){
1083 $el['atts']['vid_src'] .="&loop=1";
1084 }else{
1085 $el['atts']['vid_src'] .="&loop=0";
1086 }
1087
1088 $el['tmp']['ele_id'] = $el['id'];
1089
1090 }
1091
1092 // Video slider items Handler
1093 function pagelayer_sc_video_slider(&$el){
1094
1095 $pager = (!empty($el['atts']['slider_pager']))? 'true': 'false';
1096 $loop = (!empty($el['atts']['slider_loop']))? 'true': 'false';
1097 $autoplay = (!empty($el['atts']['autoplay']) || !($el['atts']['autoplay']))? 'true' : 'false';
1098 $slideshow_speed = intval($el['atts']['slideshow_speed']);
1099 $slideshow_start = intval($el['atts']['slideshow_start']);
1100
1101 echo "<script type='text/javascript'>
1102 jQuery(document).ready(function(){
1103 jQuery('".$el['selector']." .pagelayer-video-slider-holder').slippry({
1104 elements: 'div.pagelayer-video',
1105 auto: ".$autoplay.",
1106 speed: ".$slideshow_speed.",
1107 transition: '".$el['atts']['slider_transition']."',
1108 preload: '".$el['atts']['slider_preload']."',
1109 pager: ".$pager.",
1110 start : ".$slideshow_start.",
1111 loop : ".$loop.",
1112
1113 });
1114 });
1115 </script>";
1116 }
1117
1118 // Splash Handler
1119 function pagelayer_sc_splash(&$el){
1120
1121 $delay = intval($el['atts']['delay']);
1122 echo '<script type="text/javascript">
1123 jQuery(document).ready(function(){
1124 if("'.$el['atts']['display'].'" == "once"){
1125
1126 if (!sessionStorage.isVisited) {
1127 sessionStorage.isVisited = "true";
1128 jQuery("[pagelayer-id='.$el['id'].'] .pagelayer-splash-container").delay('.$delay.').fadeIn();
1129 }
1130 }else{
1131 jQuery("[pagelayer-id='.$el['id'].'] .pagelayer-splash-container").delay('.$delay.').fadeIn();
1132 }
1133
1134 jQuery("[pagelayer-id='.$el['id'].'] .pagelayer-splash-close").on("click", function(){
1135 jQuery("[pagelayer-id='.$el['id'].'] .pagelayer-splash-container").fadeOut();
1136 });
1137 });
1138 </script>';
1139
1140 }
1141
1142 // Shortcodes Handler
1143 function pagelayer_sc_shortcodes(&$el){
1144 $el['tmp']['shortcode'] = do_shortcode($el['atts']['data']);
1145 }
1146
1147 // Shortcodes Handler
1148 function pagelayer_sc_wp_widgets(&$el){
1149
1150 global $wp_registered_sidebars;
1151
1152 $data = '';
1153 foreach($wp_registered_sidebars as $v){
1154 if($el['atts']['sidebar'] == $v['id']){
1155 ob_start();
1156 dynamic_sidebar($v['id']);
1157 $data = ob_get_clean();
1158 }
1159 }
1160
1161 $el['tmp']['data'] = $data;
1162 }
1163
1164 // Testimonial Handler
1165 function pagelayer_sc_testimonial(&$el){
1166
1167 $el['atts']['func_image'] = @$el['tmp']['avatar-'.$el['atts']['custom_size'].'-url'];
1168 $el['atts']['func_image'] = empty($el['atts']['func_image']) ? @$el['tmp']['avatar-full-url'] : $el['atts']['func_image'];
1169
1170 if(!empty($image)){
1171 foreach($image as $k => $v){
1172 $el['tmp']['avatar-'.$k] = $v;
1173 }
1174 }
1175
1176 }
1177
1178 // Service Handler
1179 function pagelayer_sc_service(&$el){
1180
1181 if(!empty($el['atts']['service_image'])){
1182 $el['atts']['func_image'] = @$el['tmp']['service_image-'.$el['atts']['service_image_size'].'-url'];
1183 $el['atts']['func_image'] = empty($el['atts']['func_image']) ? @$el['tmp']['service_image-full-url'] : $el['atts']['func_image'];
1184 }
1185 }
1186
1187 /*pagelayer_print($atts);
1188 pagelayer_print($content);
1189 die();*/
1190
1191 /////////////////////////////////////
1192 // Miscellaneous Shortcode Functions
1193 /////////////////////////////////////
1194
1195 // The font family list
1196 function pagelayer_font_family(){
1197 return array(
1198 'arial' => 'Arial',
1199 'terminal' => 'Terminal'
1200 );
1201 }
1202
1203 // Supported Icons
1204 function pagelayer_icon_class_list(){
1205 return array();
1206 }
1207
1208 // The types of Posts
1209 function pagelayer_post_types($page = false){
1210
1211 // Get the types
1212 $args = array('public' => TRUE);
1213 $types = get_post_types($args, 'objects');
1214
1215 // Unset Page if not required
1216 if($page == false){
1217 unset($types['page']);
1218 }
1219
1220 // Remove Attachment types !
1221 unset($types['attachment']);
1222
1223 foreach($types as $name => $type){
1224 $return[$name] = $type->labels->singular_name;
1225 }
1226
1227 return $return;
1228 }
1229
1230 // Get Taxonomies
1231 function pagelayer_tax_list($item, $page = false){
1232
1233 // Get types
1234 $types = pagelayer_post_types($page);
1235
1236 // Loop thru
1237 foreach($types as $slug => $label){
1238
1239 // Get the items
1240 $items = get_object_taxonomies($slug, 'objects');
1241
1242 foreach($items as $name => $v) {
1243 if(!isset($taxonomies[$name])){
1244 $taxonomies[$name] = array('label' => $v->labels->singular_name, 'posttypes' => array($label));
1245 }else{
1246 $taxonomies[$name]['posttypes'][] = $label;
1247 }
1248 }
1249 }
1250
1251 // Make it simple
1252 foreach($taxonomies as $k => $v){
1253 $taxonomies[$k] = $v['label'].' ('.implode(', ', $v['posttypes']).')';
1254 }
1255
1256 $pos = array_search($item, array_keys($taxonomies));
1257 if(!empty($pos)) {
1258 $cut = array_splice($taxonomies, $pos, 1);
1259 $taxonomies = $cut + $taxonomies;
1260 }
1261
1262 return $taxonomies;
1263 }
1264
1265