PluginProbe
Page Builder: Pagelayer – Drag and Drop website builder / 0.9.7
Page Builder: Pagelayer – Drag and Drop website builder v0.9.7
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 / functions.php

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

1,435 lines 35.3 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 // Get the client IP
28 function _pagelayer_getip(){
29 if(isset($_SERVER["REMOTE_ADDR"])){
30 return $_SERVER["REMOTE_ADDR"];
31 }elseif(isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
32 return $_SERVER["HTTP_X_FORWARDED_FOR"];
33 }elseif(isset($_SERVER["HTTP_CLIENT_IP"])){
34 return $_SERVER["HTTP_CLIENT_IP"];
35 }
36 }
37
38 // Get the client IP
39 function pagelayer_getip(){
40
41 global $pagelayer;
42
43 // Just so that we have something
44 $ip = _pagelayer_getip();
45
46 $pagelayer['ip_method'] = (int) @$pagelayer['ip_method'];
47
48 if(isset($_SERVER["REMOTE_ADDR"])){
49 $ip = $_SERVER["REMOTE_ADDR"];
50 }
51
52 if(isset($_SERVER["HTTP_X_FORWARDED_FOR"]) && @$pagelayer['ip_method'] == 1){
53 $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
54 }
55
56 if(isset($_SERVER["HTTP_CLIENT_IP"]) && @$pagelayer['ip_method'] == 2){
57 $ip = $_SERVER["HTTP_CLIENT_IP"];
58 }
59
60 // Hacking fix for X-Forwarded-For
61 if(!pagelayer_valid_ip($ip)){
62 return '';
63 }
64
65 return $ip;
66
67 }
68
69 // Execute a select query and return an array
70 function pagelayer_selectquery($query, $array = 0){
71 global $wpdb;
72
73 $result = $wpdb->get_results($query, 'ARRAY_A');
74
75 if(empty($array)){
76 return current($result);
77 }else{
78 return $result;
79 }
80 }
81
82 // Check if an IP is valid
83 function pagelayer_valid_ip($ip){
84
85 // IPv6
86 if(pagelayer_valid_ipv6($ip)){
87 return true;
88 }
89
90 // IPv4
91 if(!ip2long($ip)){
92 return false;
93 }
94
95 return true;
96 }
97
98 function pagelayer_valid_ipv6($ip){
99
100 $pattern = '/^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/';
101
102 if(!preg_match($pattern, $ip)){
103 return false;
104 }
105
106 return true;
107
108 }
109
110 // Check if a field is posted via POST else return default value
111 function pagelayer_optpost($name, $default = ''){
112
113 if(!empty($_POST[$name])){
114 return pagelayer_inputsec(pagelayer_htmlizer(trim($_POST[$name])));
115 }
116
117 return $default;
118 }
119
120 // Check if a field is posted via GET else return default value
121 function pagelayer_optget($name, $default = ''){
122
123 if(!empty($_GET[$name])){
124 return pagelayer_inputsec(pagelayer_htmlizer(trim($_GET[$name])));
125 }
126
127 return $default;
128 }
129
130 // Check if a field is posted via GET or POST else return default value
131 function pagelayer_optreq($name, $default = ''){
132
133 if(!empty($_REQUEST[$name])){
134 return pagelayer_inputsec(pagelayer_htmlizer(trim($_REQUEST[$name])));
135 }
136
137 return $default;
138 }
139
140 // For filling in posted values
141 function pagelayer_POSTval($name, $default = ''){
142
143 return (!empty($_POST) ? (!isset($_POST[$name]) ? '' : $_POST[$name]) : $default);
144
145 }
146
147 function pagelayer_POSTchecked($name, $default = false){
148
149 return (!empty($_POST) ? (isset($_POST[$name]) ? 'checked="checked"' : '') : (!empty($default) ? 'checked="checked"' : ''));
150
151 }
152
153 function pagelayer_POSTselect($name, $value, $default = false){
154
155 if(empty($_POST)){
156 if(!empty($default)){
157 return 'selected="selected"';
158 }
159 }else{
160 if(isset($_POST[$name])){
161 if(trim($_POST[$name]) == $value){
162 return 'selected="selected"';
163 }
164 }
165 }
166
167 }
168
169 function pagelayer_inputsec($string){
170
171 if(!get_magic_quotes_gpc()){
172
173 $string = addslashes($string);
174
175 }else{
176
177 $string = stripslashes($string);
178 $string = addslashes($string);
179
180 }
181
182 // This is to replace ` which can cause the command to be executed in exec()
183 $string = str_replace('`', '\`', $string);
184
185 return $string;
186
187 }
188
189 function pagelayer_htmlizer($string){
190
191 $string = htmlentities($string, ENT_QUOTES, 'UTF-8');
192
193 preg_match_all('/(&amp;#(\d{1,7}|x[0-9a-fA-F]{1,6});)/', $string, $matches);//r_print($matches);
194
195 foreach($matches[1] as $mk => $mv){
196 $tmp_m = pagelayer_entity_check($matches[2][$mk]);
197 $string = str_replace($matches[1][$mk], $tmp_m, $string);
198 }
199
200 return $string;
201
202 }
203
204 function pagelayer_entity_check($string){
205
206 //Convert Hexadecimal to Decimal
207 $num = ((substr($string, 0, 1) === 'x') ? hexdec(substr($string, 1)) : (int) $string);
208
209 //Squares and Spaces - return nothing
210 $string = (($num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num < 0x20) ? '' : '&#'.$num.';');
211
212 return $string;
213
214 }
215
216 // Check if a checkbox is selected
217 function pagelayer_is_checked($post){
218
219 if(!empty($_POST[$post])){
220 return true;
221 }
222 return false;
223 }
224
225 // Reoort an error
226 function pagelayer_report_error($error = array()){
227
228 if(empty($error)){
229 return true;
230 }
231
232 $error_string = '<b>Please fix the below error(s) :</b> <br />';
233
234 foreach($error as $ek => $ev){
235 $error_string .= '* '.$ev.'<br />';
236 }
237
238 echo '<div id="message" class="error"><p>'
239 . __pl($error_string)
240 . '</p></div>';
241 }
242
243 // Report a notice
244 function pagelayer_report_notice($notice = array()){
245
246 global $wp_version;
247
248 if(empty($notice)){
249 return true;
250 }
251
252 // Which class do we have to use ?
253 if(version_compare($wp_version, '3.8', '<')){
254 $notice_class = 'updated';
255 }else{
256 $notice_class = 'updated';
257 }
258
259 $notice_string = '<b>Please check the below notice(s) :</b> <br />';
260
261 foreach($notice as $ek => $ev){
262 $notice_string .= '* '.$ev.'<br />';
263 }
264
265 echo '<div id="message" class="'.$notice_class.'"><p>'
266 . __pl($notice_string)
267 . '</p></div>';
268 }
269
270 // Convert an objext to array
271 function pagelayer_objectToArray($d){
272
273 if(is_object($d)){
274 $d = get_object_vars($d);
275 }
276
277 if(is_array($d)){
278 return array_map(__FUNCTION__, $d); // recursive
279 }elseif(is_object($d)){
280 return pagelayer_objectToArray($d);
281 }else{
282 return $d;
283 }
284 }
285
286 // Sanitize variables
287 function pagelayer_sanitize_variables($variables = array()){
288
289 if(is_array($variables)){
290 foreach($variables as $k => $v){
291 $variables[$k] = trim($v);
292 $variables[$k] = escapeshellcmd($v);
293 }
294 }else{
295 $variables = escapeshellcmd(trim($variables));
296 }
297
298 return $variables;
299 }
300
301 // Is multisite ?
302 function pagelayer_is_multisite() {
303
304 if(function_exists('get_site_option') && function_exists('is_multisite') && is_multisite()){
305 return true;
306 }
307
308 return false;
309 }
310
311 // Generate a random string
312 function pagelayer_RandomString($length = 10){
313 $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
314 $charactersLength = strlen($characters);
315 $randomString = '';
316 for($i = 0; $i < $length; $i++){
317 $randomString .= $characters[rand(0, $charactersLength - 1)];
318 }
319 return $randomString;
320 }
321
322 function pagelayer_print($array){
323
324 echo '<pre>';
325 print_r($array);
326 echo '</pre>';
327
328 }
329
330 function pagelayer_cleanpath($path){
331 $path = str_replace('\\\\', '/', $path);
332 $path = str_replace('\\', '/', $path);
333 $path = str_replace('//', '/', $path);
334 return rtrim($path, '/');
335 }
336
337 // Returns the Numeric Value of results Per Page
338 function pagelayer_get_page($get = 'page', $resperpage = 50){
339
340 $resperpage = (!empty($_REQUEST['reslen']) && is_numeric($_REQUEST['reslen']) ? (int) pagelayer_optreq('reslen') : $resperpage);
341
342 if(pagelayer_optget($get)){
343 $pg = (int) pagelayer_optget($get);
344 $pg = $pg - 1;
345 $page = ($pg * $resperpage);
346 $page = ($page <= 0 ? 0 : $page);
347 }else{
348 $page = 0;
349 }
350 return $page;
351 }
352
353 // Are we editing from the Admin panel ?
354 function pagelayer_is_editing($force = false){
355
356 global $post, $pagelayer;
357
358 if(!empty($force)){
359 return true;
360 }
361
362 if(!is_admin()){
363 return false;
364 }
365
366 $current_file = basename($_SERVER['PHP_SELF']);
367
368 $type = get_post_type();
369 //echo $type;return false;
370 //$page = pagelayer_optreq('page');
371
372 // Are we in the live editor mode OR is this a post which is supported
373 if((pagelayer_supported_type($type) && in_array($current_file, array('post.php', 'post-new.php'))) || pagelayer_is_live()){
374 return true;
375 }else{
376 return false;
377 }
378
379 }
380
381 // Is the given post type editable by us ?
382 function pagelayer_supported_type($type){
383
384 global $pagelayer;
385
386 $type = trim($type);
387
388 if(in_array($type, $pagelayer->settings['post_types'])){
389 return true;
390 }
391
392 return false;
393
394 }
395
396 function pagelayer_shortlink($id){
397 $link = wp_get_shortlink($id);
398 $link .= substr_count($link, '?') > 0 ? '' : '?';
399 return $link;
400 }
401
402 // Are we in live mode ?
403 function pagelayer_is_live(){
404
405 global $post;
406
407 // Are we seeing the post ?
408 if(!isset($post) || !isset($post->ID) || empty($post->ID)){
409 return false;
410 }
411
412 // Is it the live mode ?
413 if(pagelayer_optreq('pagelayer-live')){
414 return true;
415 }
416
417 return false;
418
419 }
420
421 // Are we in live IFRAME mode ?
422 function pagelayer_is_live_iframe(){
423
424 // Are we seeing the post ?
425 if(!pagelayer_is_live()){
426 return false;
427 }
428
429 // Is it the live mode ?
430 if(pagelayer_optreq('pagelayer-iframe')){
431 return true;
432 }
433
434 return false;
435
436 }
437
438 // Can the current user edit the post ?
439 function pagelayer_user_can_edit($post = NULL){
440
441 global $wp_the_query, $current_user;
442
443 if(!isset($post) || empty($post) || $post === NULL){
444 global $post;
445 }
446
447 wp_get_current_user();
448
449 if(isset($post) && is_object($post) && isset($post->ID) && isset($post->post_author) && isset($current_user) && is_object($current_user) && isset($current_user->ID) && (current_user_can('edit_others_posts', $post->ID) || ($post->post_author == $current_user->ID))){
450 return true;
451 }
452
453 return false;
454
455 }
456
457 // Language sting function
458 function __pl($key){
459
460 global $pagelayer;
461
462 if(!empty($pagelayer->l[$key])){
463 return $pagelayer->l[$key];
464 }
465
466 return $key;
467
468 }
469
470 // Give the list of icon sources
471 function pagelayer_icon_sources(){
472 return array();
473 }
474
475 // Loads the shortcodes
476 function pagelayer_load_shortcodes(){
477
478 include_once(PAGELAYER_DIR.'/main/shortcode_functions.php');
479 if(defined('PAGELAYER_PREMIUM')){
480 include_once(PAGELAYER_DIR.'/main/premium_functions.php');
481 }
482 include_once(PAGELAYER_DIR.'/main/shortcodes.php');
483
484 // pQuery
485 include_once(PAGELAYER_DIR.'/lib/pquery/IQuery.php');
486 include_once(PAGELAYER_DIR.'/lib/pquery/gan_formatter.php');
487 include_once(PAGELAYER_DIR.'/lib/pquery/gan_node_html.php');
488 include_once(PAGELAYER_DIR.'/lib/pquery/gan_tokenizer.php');
489 include_once(PAGELAYER_DIR.'/lib/pquery/gan_parser_html.php');
490 include_once(PAGELAYER_DIR.'/lib/pquery/gan_selector_html.php');
491 include_once(PAGELAYER_DIR.'/lib/pquery/gan_xml2array.php');
492 include_once(PAGELAYER_DIR.'/lib/pquery/pQuery.php');
493
494 // Apply filter to load custom widgets
495 do_action('pagelayer_load_custom_widgets');
496
497 }
498
499 // Add the shortcodes to the pagelayer list
500 function pagelayer_add_shortcode($tag, $params = array()){
501
502 global $pagelayer;
503
504 // Is there a handler function ?
505 if(!empty($params['func'])){
506
507 if($tag == 'pl_row'){
508 $inner_tag = 'pl_inner_row';
509 add_shortcode($inner_tag, 'pagelayer_render_shortcode');
510 }
511
512 if($tag == 'pl_col'){
513 $inner_tag = 'pl_inner_col';
514 add_shortcode($inner_tag, 'pagelayer_render_shortcode');
515 }
516
517 add_shortcode($tag, 'pagelayer_render_shortcode');//$params['func']);
518 //unset($params['func']);
519 }
520
521 // Is there a group ?
522 if(empty($params['group'])){
523 $params['group'] = 'misc';
524 }
525
526 // Add the advanced styling group
527 $params['options'] = [
528 'ele_bg_styles' => __pl('ele_bg_styles'),
529 'ele_styles' => __pl('ele_styles'),
530 'border_styles' => __pl('border_styles'),
531 'animation_styles' => __pl('animation_styles'),
532 'responsive_styles' => __pl('responsive_styles'),
533 'custom_styles' => __pl('custom_styles'),
534 ];
535
536 // Are the settings there which hold the params ?
537 if(empty($params['settings'])){
538 $params['settings'] = [
539 'params' => $params['name'],
540 ];
541 }
542
543 // Disable the style options
544 if(!empty($params['styles'])){
545 $params['settings'] = array_merge($params['settings'], $params['styles']);
546 unset($params['styles']);
547 }
548
549 /*// The following is for testing only
550 $r = [];
551 foreach($pagelayer->styles as $k => $v){
552 foreach($v as $kk => $vv){
553 $r[$kk] = $kk;
554 }
555 }
556 //print_r($r);die();
557
558 foreach($params['settings'] as $k => $v){
559 if(empty($params[$k])) continue;
560 foreach($params[$k] as $kk => $vv){
561 if(!empty($r[$kk])){
562 echo 'Duplicate KEY '.$kk.' in Shortcode '.$tag."<br>";
563 }
564 }
565 }
566 //die();*/
567
568 // Insert the shortcode
569 $pagelayer->shortcodes[$tag] = $params;
570 $pagelayer->groups[$params['group']][] = $tag;
571
572 }
573
574 // Returns the Image values
575 function pagelayer_image($id){
576
577 $ret = [];
578
579 // External image ?
580 if(pagelayer_is_external_img($id)){
581
582 $ret['full-url'] = $id;
583
584 // Attachment
585 }elseif(!empty($id)){
586
587 $id = (int) @$id;
588
589 $image = get_post($id);
590
591 // Is there an attachment which is an image ?
592 if(!empty($image) && $image->post_type == 'attachment' && wp_attachment_is_image($id)){
593
594 $sizes = get_intermediate_image_sizes();
595 array_unshift($sizes, 'full');
596
597 foreach($sizes as $size){
598 $src = wp_get_attachment_image_src($id, $size);
599 $ret[$size.'-url'] = $src[0];
600 }
601
602 // Title and Alt
603 $title = esc_attr($image->post_title);
604 $alt = get_post_meta($id, '_wp_attachment_image_alt', true);
605 $alt = empty($alt) ? $image->post_excerpt : $alt;
606 $alt = empty($alt) ? $image->post_title : $alt;
607 $alt = empty($alt) ? '' : trim(strip_tags($alt));
608 $link = get_attachment_link($id);
609 $caption = wp_get_attachment_caption($id);
610 $caption = !empty($caption) ? $caption : '';
611
612 $ret['alt'] = $alt;
613 $ret['title'] = $title;
614 $ret['link'] = $link;
615 $ret['caption'] = $caption;
616
617 }
618
619 }
620
621 // No image
622 if(empty($ret['full-url'])){
623 $ret['full-url'] = PAGELAYER_URL.'/images/default-image.png';
624 }
625
626 $ret['url'] = $ret['full-url'];
627
628 return $ret;
629
630 }
631
632 // Checks if the given parameter is an external link or a wp attachment id
633 function pagelayer_is_external_img($img = ''){
634
635 if(empty($img)){
636 return false;
637 }
638
639 if(preg_match('#http://#is', $img) || preg_match('#https://#is', $img) || preg_match('#^{{#is', $img)){
640 return true;
641 }
642
643 return false;
644
645 }
646
647 // Returns the attachment url
648 function pagelayer_attachment($id){
649
650 $ret = [];
651
652 // External url ?
653 if(pagelayer_is_external_img($id)){
654
655 $ret['url'] = $id;
656
657 // Attachment
658 }elseif(!empty($id)){
659
660 $ret['url'] = wp_get_attachment_url($id);
661
662 }
663
664 return $ret;
665
666 }
667
668 // Convert the regular URL of a Video to a Embed URL
669 // Todo : Check
670 function pagelayer_video_url($source){
671
672 if (!empty($source)) {
673 $source = filter_var($source, FILTER_SANITIZE_URL);
674 $source = str_replace('&amp;', '&', $source);
675 $url = parse_url($source);
676 $videoSite ='';
677
678 $youtubeRegExp = '/youtube\.com|youtu\.be/is';
679 $vimeoRegExp = '/vimeo\.com/is';
680
681 if (preg_match($youtubeRegExp, $source)) {
682 $videoSite = 'youtube';
683 } else if (preg_match($vimeoRegExp, $source)) {
684 $videoSite = 'vimeo';
685 }
686
687 switch ($videoSite) {
688 case 'youtube':
689
690 if (preg_match('/youtube\.com/is', $source)) {
691
692 if (preg_match('/watch/is', $source)) {
693 parse_str($url['query'], $parameters);
694
695 if (isset($parameters['v']) && !empty($parameters['v'])) {
696 $videoId = $parameters['v'];
697 }
698
699 } else if (preg_match('/embed/is', $url['path'])) {
700 $path = explode('/', $url['path']);
701 if (isset($path[2]) && !empty($path[2])) {
702 $videoId = $path[2];
703 }
704 }
705
706 } else if (preg_match('/youtu\.be/is', $url['host'])) {
707 $path = explode('/', $url['path']);
708
709 if (isset($path[1]) && !empty($path[1])) {
710 $videoId = $path[1];
711 }
712
713 }
714
715 return '//youtube.com/embed/'.$videoId;
716
717 break;
718 case 'vimeo':
719
720 if (preg_match('/player\.vimeo\.com/is', $url['host']) && preg_match('/video/is', $url['path'])) {
721 $path = explode('/', $url['path']);
722
723 if (isset($path[2]) && !empty($path[2])) {
724 $videoId = $path[2];
725 }
726
727 } else if (preg_match('/vimeo\.com/is', $url['host'])) {
728 $path = explode('/', $url['path']);
729
730 if (isset($path[1]) && !empty($path[1])) {
731 $videoId = $path[1];
732 }
733
734 }
735
736 return '//player.vimeo.com/video/'.$videoId;
737
738 break;
739 default:
740
741 return $source;
742
743 }
744
745 }
746 }
747
748
749 // As per the JS specification
750 function pagelayer_escapeHTML($str){
751
752 $replace = [
753 ']' => '&#93;',
754 '[' => '&#91;',
755 //'=' => '&#61;',
756 '<' => '&lt;',
757 '>' => '&gt;',
758 '"' => '&quot;',
759 //'&' => '&amp;',
760 '\'' => '&#39;'
761 ];
762
763 $str = str_replace(array_keys($replace), array_values($replace), $str);
764
765 return $str;
766 }
767
768 // As per the JS specification
769 function pagelayer_unescapeHTML($str){
770 $replace = [
771 '#93' => ']',
772 '#91' => '[',
773 //'#61' => '=',
774 'lt' => '<',
775 'gt' => '>',
776 'quot' => '"',
777 //'amp' => '&',
778 '#39' => '\''
779 ];
780
781 foreach($replace as $k => $v){
782 $str = str_replace('&'.$k.';', $v, $str);
783 }
784 return $str;
785 }
786
787 // Show promo notice on dashboard
788 function pagelayer_show_promo(){
789
790 global $pagelayer_promo_opts;
791 $opts = $pagelayer_promo_opts;
792
793 echo '<style>
794 .pagelayer_promo_button {
795 background-color: #4CAF50; /* Green */
796 border: none;
797 color: white;
798 padding: 6px 10px;
799 text-align: center;
800 text-decoration: none;
801 display: inline-block;
802 font-size: 13px;
803 margin: 4px 2px;
804 -webkit-transition-duration: 0.4s; /* Safari */
805 transition-duration: 0.4s;
806 cursor: pointer;
807 }
808 .pagelayer_promo_button:focus{
809 border: none;
810 color: white;
811 }
812 .pagelayer_promo_button1 {
813 color: white;
814 background-color: #4CAF50;
815 border:3px solid #4CAF50;
816 }
817 .pagelayer_promo_button1:hover {
818 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
819 color: white;
820 border:3px solid #4CAF50;
821 }
822 .pagelayer_promo_button2 {
823 color: white;
824 background-color: #0085ba;
825 }
826 .pagelayer_promo_button2:hover {
827 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
828 color: white;
829 }
830 .pagelayer_promo_button3 {
831 color: white;
832 background-color: #365899;
833 }
834 .pagelayer_promo_button3:hover {
835 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
836 color: white;
837 }
838 .pagelayer_promo_button4 {
839 color: white;
840 background-color: rgb(66, 184, 221);
841 }
842 .pagelayer_promo_button4:hover {
843 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
844 color: white;
845 }
846 .pagelayer_promo-close{
847 float:right;
848 text-decoration:none;
849 margin: 5px 10px 0px 0px;
850 }
851 .pagelayer_promo-close:hover{
852 color: red;
853 }
854 </style>
855 <script type="application/javascript">
856 jQuery(document).ready(function(){
857 jQuery("#pagelayer_promo .pagelayer_promo-close").click(function(){
858 var data;
859 jQuery("#pagelayer_promo").hide();
860 // Save this preference
861 jQuery.post("'.admin_url('?pagelayer_promo=0').'", data, function(response) {
862 //alert(response);
863 });
864 });
865 });
866 </script>
867
868 <div class="notice notice-success" id="pagelayer_promo" style="min-height:90px">
869 <a class="pagelayer_promo-close" href="javascript:" aria-label="Dismiss this Notice">
870 <span class="dashicons dashicons-dismiss"></span> Dismiss
871 </a>';
872
873 if(!empty($opts['image'])){
874 echo '<a href="'.$opts['website'].'"><img src="'.$opts['image'].'" style="float:left; margin:10px 20px 10px 10px" width="67" /></a>';
875 }
876
877 echo '
878 <p style="font-size:13px">We are glad you like <a href="'.$opts['website'].'"><b>PageLayer</b></a> and have been using it since the past few days. It is time to take the next step !</p>
879 <p>
880 '.(empty($opts['rating']) ? '' : '<a class="pagelayer_promo_button pagelayer_promo_button2" target="_blank" href="'.$opts['rating'].'">Rate it 5�
881 \'s</a>').'
882 '.(empty($opts['facebook']) ? '' : '<a class="pagelayer_promo_button pagelayer_promo_button3" target="_blank" href="'.$opts['facebook'].'"><span class="dashicons dashicons-thumbs-up"></span> Facebook</a>').'
883 '.(empty($opts['twitter']) ? '' : '<a class="pagelayer_promo_button pagelayer_promo_button4" target="_blank" href="'.$opts['twitter'].'"><span class="dashicons dashicons-twitter"></span> Tweet</a>').'
884 '.(empty($opts['website']) ? '' : '<a class="pagelayer_promo_button pagelayer_promo_button4" target="_blank" href="'.$opts['website'].'">Visit our website</a>').'
885 </p>
886 </div>';
887
888 }
889
890 // Are we to show a promo ?
891 function pagelayer_maybe_promo($opts){
892
893 global $pagelayer_promo_opts;
894
895 // There must be an interval
896 if(empty($opts['interval'])){
897 return false;
898 }
899
900 // Are we to show a promo
901 $opt_name = 'pagelayer_promo_time';
902 $promo_time = get_option($opt_name);
903
904 // First time access
905 if(empty($promo_time)){
906 update_option($opt_name, time() + (!empty($opts['after']) ? $opts['after'] * 86400 : 0));
907 $promo_time = get_option($opt_name);
908 }
909
910 // Is there interval elapsed
911 if(time() > $promo_time){
912 $pagelayer_promo_opts = $opts;
913 add_action('admin_notices', 'pagelayer_show_promo');
914 }
915
916 // Are we to disable the promo
917 if(isset($_GET['pagelayer_promo']) && (int)$_GET['pagelayer_promo'] == 0){
918 update_option($opt_name, time() + ($opts['interval'] * 86400));
919 die('DONE');
920 }
921
922 }
923
924 // Bread Crumbs with links
925 function pagelayer_get_breadcrumb(){
926
927 // Home page
928 $ret = '<a href="'.home_url().'" rel="nofollow">{{home}}</a>';
929
930 // Is Front page
931 if(is_front_page()){
932 return $ret;
933
934 // Is search query
935 }elseif(is_search()){
936 $ret .= '<b class="pagelayer-breadcrumb-sep" if="{{separator}}">{{separator}}</b><b class="pagelayer-breadcrumb-prefix" if="{{search_prefix}}">{{search_prefix}}</b>';
937 $ret .= '<em>';
938 $ret .= get_search_query();
939 $ret .= '</em>';
940
941 //Is category or single post
942 }elseif(is_category() || is_single()){
943
944 $ret .= '<b class="pagelayer-breadcrumb-sep" if="{{separator}}">{{separator}}</b>';
945 $categories = get_the_category();
946 $separator = ' ';
947 $output = '';
948 if(!empty($categories)){
949 $ret .= get_category_parents($categories[0], true, ' <b class="pagelayer-breadcrumb-sep" if="{{separator}}">{{separator}}</b> ');
950 }
951 if(is_single()) {
952 /* if (empty($categories)){
953 $ret .= ' <b class="pagelayer-breadcrumb-sep" if="{{separator}}">{{separator}}</b> ';
954 } */
955 $ret .= get_the_title();
956 }
957
958 // Is page
959 }elseif(is_page()){
960 $ret .= '<b class="pagelayer-breadcrumb-sep" if="{{separator}}">{{separator}}</b>';
961 $ret .= get_the_title();
962 }else{
963 $ret .= '<b class="pagelayer-breadcrumb-sep" if="{{separator}}">{{separator}}</b>';
964 $ret .= wp_title('', false );
965 }
966
967 // wooCommerce Integration left
968
969 return $ret;
970 }
971
972 // Portfolio Posts
973 function pagelayer_widget_posts($args){
974
975 $r = new \WP_Query($args);
976
977 $ret = '';
978 if ( $r->have_posts() ){
979
980 if($args['filter_by'] != 'none' && $args['post_type'] == 'post'){
981 $ret .= '<div class="pagelayer-postfolio-filter">';
982
983 $data_filter = ( $args['filter_by'] == 'category' ? get_categories() : get_tags() );
984
985 if(!empty($data_filter)){
986
987 $ret .= '<div class="pagelayer-postfolio-btn" data-filter="all">'.__pl('All').'</div>';
988
989 foreach($data_filter as $filter) {
990 $ret .= '<div class="pagelayer-postfolio-btn" data-filter="'.$filter->name.'">' . $filter->name . '</div>';
991 }
992
993 }
994
995 $ret .= '</div>';
996 }
997
998 $ret .= '<div class="pagelayer-postfolio-container">';
999
1000 while ( $r->have_posts() ) : $r->the_post();
1001 $post_meta = ( $args['filter_by'] == 'category' ? get_the_category() : get_the_tags() );
1002 $meta_attr = '';
1003 if($post_meta){
1004
1005 $meta_array = array();
1006 foreach( $post_meta as $meta ){
1007 $meta_array[] = $meta->name;
1008 }
1009 $meta_attr .= ' data-category="'.implode(' ', $meta_array).'"';
1010 }
1011
1012 $ret .= '<div class="pagelayer-postfolio-thumb"'.(has_post_thumbnail() ? ' style="background:url('.get_the_post_thumbnail_url().')"' : ''). $meta_attr .'>';
1013 $ret .= '<a href="'.esc_url( get_permalink() ).'" rel="bookmark">';
1014 $ret .= '<div class="pagelayer-postfolio-content">';
1015 $ret .= '<h4 class="pagelayer-entry-title">'.get_the_title().'</h4>';
1016 $ret .= '</div></a></div>';
1017
1018 endwhile;
1019
1020 $ret .= '</div>';
1021
1022 }
1023
1024 return $ret;
1025 }
1026
1027 // List all available sizes of images registered on WordPress
1028 function pagelayer_image_sizes(){
1029
1030 $sizes = array();
1031 $sizes = get_intermediate_image_sizes();
1032 $ret = array();
1033 foreach($sizes as $size){
1034 $ret[$size] = __pl($size);
1035 }
1036
1037 return $ret;
1038 }
1039
1040 function pagelayer_posts($params, $args = []){
1041
1042 // If args is empty
1043 if(empty($args)){
1044 $args = array(
1045 'post_type' => $params['post_type'],
1046 'posts_per_page' => $params['posts_per_page'],
1047 'order' => $params['order']
1048 );
1049
1050 if($params['exc_length']){
1051 $exc_length = (int) $params['exc_length'];
1052 add_filter( 'excerpt_length', function($length) use($exc_length){
1053 return $exc_length;
1054 }, 999 );
1055 }
1056
1057 if($params['term']){
1058
1059 $term = explode(':', $params['term']);
1060 //pagelayer_print($term);
1061 if($term[0] == 'category'){
1062 $args['category_name'] = $term[1];
1063 }
1064 if($term[0] == 'post_tag'){
1065 $args['tag'] = $term[1];
1066 }
1067 }
1068
1069 if($params['exc_term']){
1070
1071 $term = explode(':', $params['exc_term']);
1072 //pagelayer_print($term);
1073 if($term[0] == 'category'){
1074 $args['category__not_in'] = $term[2];
1075 }
1076 if($term[0] == 'post_tag'){
1077 $args['tag__not_in'] = $term[2];
1078 }
1079 }
1080
1081 if($params['author_name']){
1082 $author_name = explode(':', $params['author_name']);
1083 $args['author_name'] = $author_name[0];
1084 }
1085
1086 if($params['exc_author']){
1087 $exc_author = explode(':', $params['exc_author']);
1088 $args['author'] = '-'.$exc_author[1];
1089 }
1090
1091 if(!empty($params['offset'])){
1092 $args['offset'] = $params['offset'];
1093 }
1094
1095 if(!empty($params['ignore_sticky'])){
1096 $args['ignore_sticky_posts'] = $params['ignore_sticky'];
1097 }
1098
1099 if(!empty($params['orderby'])){
1100 $args['orderby'] = $params['orderby'];
1101 }
1102
1103 if($params['by_period']){
1104 $date_arg = array();
1105 switch($params['by_period']){
1106 case 'last_day':
1107 $date_arg['day'] = date('j')-1;
1108 break;
1109 case 'last_week':
1110 $date_arg['week'] = date('W')-1;
1111 break;
1112 case 'last_month':
1113 $date_arg['month'] = date('n')-1;
1114 break;
1115 case 'last_year':
1116 $date_arg['year'] = date('Y')-1;
1117 break;
1118 case 'custom':
1119 $date_arg['before'] = $params['before_date'];
1120 $date_arg['after'] = $params['after_date'];
1121 break;
1122 }
1123 $args['date_query'] = array(
1124 $date_arg
1125 );
1126 }
1127 }
1128 //pagelayer_print($args);
1129
1130 $postsquery = new WP_Query($args);
1131 $data = '';
1132
1133 if(!$postsquery->have_posts()){
1134 return '<h3>Something went wrong, Please give proper inputs!</h3>';
1135 }
1136
1137 while($postsquery->have_posts()) : $postsquery->the_post();
1138 $data .= '<div class="pagelayer-wposts-col">
1139 <div class="pagelayer-wposts-post">
1140 <div class="pagelayer-wposts-featured">';
1141 $data .= '<a href="'. get_the_permalink() .'">';
1142
1143 if(isset($params['show_thumb']) && has_post_thumbnail( $postsquery->ID )){
1144 $data .= '<div class="pagelayer-wposts-thumb"'.(has_post_thumbnail() ? ' style="background:url('.get_the_post_thumbnail_url($postsquery->ID,$params['thumb_size']).')"' : '').'></div>';
1145 }
1146 /* if($params['show_thumb'] && has_post_thumbnail( $postsquery->ID )){
1147 $data .= get_the_post_thumbnail_url($postsquery->ID,$params['thumb_size']);
1148 } */
1149 $data .= '</a></div>
1150 <div class="pagelayer-wposts-content">';
1151
1152 if(isset($params['show_title'])){
1153 $data .= '<a href="'.esc_url( get_permalink() ).'" rel="bookmark"><div class="pagelayer-wposts-title">'. get_the_title().'</div></a>';
1154 }
1155
1156 $data .= '<div class="pagelayer-wposts-meta">';
1157 $sep = '';
1158 if(isset($params['meta_sep'])){
1159 $sep = '<b class="pagelayer-wposts-sep">'.$params['meta_sep'].'</b>';
1160 }
1161 if(isset($params['author'])){
1162 $data .= '<span class="pagelayer-wposts-author">By <a class="pagelayer-wposts-author-url" href="'.esc_url(get_author_posts_url(get_the_author_meta('ID'))).'">'.esc_html(get_the_author()).'</a></span>'.$sep;
1163 }
1164 if(isset($params['date'])){
1165 $data .= '<span class="pagelayer-wposts-date"><time class="pagelayer-wposts-entry-date published updated" datetime="'.get_the_date('c').'"><span class="date-d">'.get_the_date('j').'</span><span class="date-my">'.get_the_date('M, y').'</span></time></span>'.$sep;
1166 }
1167 if(isset($params['category'])){
1168 $category = get_the_category();
1169 $singlecategory = '';
1170 foreach( $category as $cat ){
1171 $singlecategory .= '<a href="' . get_tag_link( $cat->term_id ) . '">'. $cat->name .'</a>';
1172 }
1173 $data .= '<span class="pagelayer-wposts-category">' . $singlecategory . '</span>'.$sep;
1174 }
1175 if(isset($params['tags'])){
1176 $tags = get_the_tags();
1177 $singletag = '';
1178 foreach( $tags as $tag ){
1179 $singletag .= '<a href="' . get_tag_link( $tag->term_id ) . '">'. $tag->name .'</a>';
1180 }
1181 $data .= '<span class="pagelayer-wposts-tags">'.$singletag.'</span>'.$sep;
1182
1183 }
1184 if(isset($params['comments'])){
1185 $data .= '<span class="pagelayer-wposts-comments"><i class="far fa-comment" /><a href="' . esc_url( get_permalink() ) . '">' . esc_html(get_comments_number()) . '</a></span>'.$sep;
1186 }
1187
1188 $data .= '</div>';
1189
1190 if(isset($params['show_content'])){
1191 $data .= '<div class="pagelayer-wposts-excerpt">';
1192 if($params['show_content'] == 'excerpt'){
1193 $data .= do_shortcode(get_the_excerpt());
1194 }elseif($params['show_content'] == 'full'){
1195 $data .= do_shortcode(get_the_content());
1196 }
1197 $data .= '</div>';
1198 }
1199
1200 if(isset($params['show_more'])){
1201 $data .= '<a class="pagelayer-wposts-more" href="'. get_the_permalink().'">'.$params['more'].'</a>';
1202 }
1203
1204 //$data .= '<div class="pagelayer-wposts-date"><p>'.get_the_date().'</p></div>';
1205 $data .= '</div></div></div>';
1206 endwhile;
1207
1208 return $data;
1209 }
1210
1211 // Get Post Revision
1212 function pagelayer_get_post_revision_by_id($postID){
1213
1214 // Insert the post revision into the database
1215 $post_revisions = array();
1216 $reviews = wp_get_post_revisions($postID);
1217
1218 foreach($reviews as $values){
1219
1220 $date_format = date_i18n('j-M @ H:i', strtotime( $values->post_modified ) );
1221 $user_meta = get_userdata($values->post_author);
1222
1223 if ( false !== strpos( $values->post_name, 'autosave' ) ) {
1224 $type = 'autosave';
1225 } else {
1226 $type = 'revision';
1227 }
1228
1229 $post_tmp_data = array(
1230 'ID' => $values->ID,
1231 'post_author_name' => $user_meta->data->display_name,
1232 'post_author_url' => get_avatar_url($values->post_author),
1233 'post_date' => $date_format,
1234 'post_date_ago' => human_time_diff(strtotime($values->post_modified), current_time( 'timestamp' )) . ' ago ',
1235 'post_type' => $type,
1236 );
1237
1238 $post_revisions[] = $post_tmp_data;
1239 }
1240
1241 return $post_revisions;
1242 }
1243
1244 // Gets author data
1245 function pagelayer_author_data($postID){
1246
1247 $authorID = get_post_field('post_author', $postID);
1248 $data['display_name'] = get_the_author_meta( 'display_name' , $authorID );
1249 $data['description'] = get_the_author_meta( 'description' , $authorID );
1250 $data['user_url'] = get_author_posts_url( $authorID , '' );
1251 $data['avatar'] = get_avatar_url( $authorID );
1252
1253 return $data;
1254 }
1255
1256 // Posts Slider
1257 function pagelayer_posts_slider($params){
1258
1259 $args = array();
1260
1261 if(isset($params['post']['post_type'])){
1262 $args['post_type'] = $params['post']['post_type'];
1263 }
1264
1265 if(isset($params['post']['category'])){
1266 $args['category_name'] = $params['post']['category'];
1267 }
1268
1269 if(isset($params['post']['tags'])){
1270 $args['tag'] = $params['post']['tags'];
1271 }
1272
1273 if(isset($params['post']['order_by'])){
1274 $args['orderby'] = $params['post']['order_by'];
1275 }
1276
1277 if(isset($params['post']['sort_order'])){
1278 $args['order'] = $params['post']['sort_order'];
1279 }
1280
1281 if(isset($params['post']['post_count'])){
1282 $args['posts_per_page'] = $params['post']['post_count'];
1283 }
1284
1285 $data = '';
1286 $postsquery = new WP_Query($args);
1287 if ( $postsquery->have_posts() ){
1288 while ( $postsquery->have_posts() ) : $postsquery->the_post();
1289 $data .= '<li class="pagelayer-posts-slider-col">
1290 <div class="pagelayer-posts-slider-post">
1291 <div class="pagelayer-posts-slider-featured-img">';
1292 $data .= '<a href="'. get_the_permalink() .'">';
1293 if(has_post_thumbnail( $postsquery->ID ) ){
1294 if($params['post']['image_size'] == "full" || $params['post']['image_size'] == "custom" ){
1295 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $postsquery->ID ), 'single-post-thumbnail' );
1296 $data .= '<img class="pagelayer-img" src="'.$image[0].'" class="pagelayer-posts-slider-img">';
1297 }else if($params['post']['image_size'] == "thumbnail"){
1298 $data .= get_the_post_thumbnail();
1299 }
1300 }
1301 $data .= '</a></div>
1302 <div class="pagelayer-posts-slider-content">';
1303 $data .= '<p class="pagelayer-posts-slider-title">'. get_the_title().'</p>';
1304 $data .= '<div class="pagelayer-posts-slider-excerpt">';
1305 if($params['post']['show_excerpt'] == "true"){
1306 if(has_excerpt()){
1307 $excerpt = get_the_excerpt();
1308 $data .= do_shortcode($excerpt);
1309 }
1310 }
1311 $data .= '</div>';
1312 $data .= '<a class="pagelayer-posts-slider-link" href="'. get_the_permalink().'">Read More</a>';
1313 $data .= '<div class="pagelayer-post-slider-date"><p>'.get_the_date().'</p></div>';
1314 $data .= '</div></div></li>';
1315 endwhile;
1316 }
1317 return $data;
1318 }
1319
1320 // Gets the site logo URLs
1321 function pagelayer_site_logo(){
1322
1323 if(get_theme_mod('custom_logo')){
1324 $logo_id = get_theme_mod('custom_logo');
1325 return pagelayer_image($logo_id);
1326 }
1327
1328 return NULL;
1329 }
1330
1331 // Create select options
1332 function pagelayer_create_sel_options( $opt_array , $selected = ''){
1333 $options = '';
1334 foreach($opt_array as $x => $val){
1335
1336 // Single item
1337 if(is_string($opt_array[$x])){
1338 $options .= pagelayer_sel_option($x, $val, $selected);
1339
1340 // Groups
1341 }else{
1342 $options .= '<optgroup label="'. $x .'">';
1343
1344 foreach($opt_array[$x] as $y => $gval){
1345 $options .= pagelayer_sel_option($y, $gval, $selected);
1346 }
1347
1348 $options .= '</optgroup>';
1349 }
1350
1351 }
1352
1353 return $options;
1354 }
1355
1356 // Create option HTML
1357 function pagelayer_sel_option($val, $lang, $selected){
1358 return '<option value="'. $val .'" '. (($val != $selected) ? '' : 'selected="selected"') .' >'. $lang .'</option>';
1359 }
1360
1361 function pagelayer_get_post_term(){
1362
1363 $args = [
1364 'taxonomy' => array('category','post_tag'),
1365 'hide_empty' => false,
1366 ];
1367
1368 $terms = get_terms( $args );
1369
1370 $ret = array();
1371 foreach ( $terms as $term ) {
1372 $ret[$term->taxonomy.':'.$term->slug.':'.$term->term_taxonomy_id] = $term->taxonomy .': '. $term->name;
1373 }
1374 //pagelayer_print($terms);die();
1375 return $ret;
1376 }
1377
1378 function pagelayer_get_post_author(){
1379
1380 $args = [
1381 'who' => 'authors',
1382 'fields' => [
1383 'ID',
1384 'display_name',
1385 'user_nicename',
1386 ]
1387 ];
1388
1389 $authors = new \WP_User_Query( $args );
1390
1391 $ret = array();
1392 foreach ( $authors->get_results() as $author ) {
1393 $ret[$author->user_nicename.':'.$author->ID] = $author->display_name;
1394 }
1395 //pagelayer_print($authors->get_results());die();
1396 return $ret;
1397 }
1398
1399 // Simply echo and dir
1400 function pagelayer_json_output(&$done){
1401
1402 echo json_encode($done);
1403 wp_die();
1404
1405 }
1406
1407 // Get the current query for render the product
1408 function pagelayer_shortcode_current_query_query($query_args, $atts, $type){
1409 global $wp_query;
1410
1411 if($type == 'pagelayer_current_query'){
1412
1413 if ( ! is_page( wc_get_page_id( 'shop' ) ) ) {
1414 $query_args = $wp_query->query_vars;
1415 }
1416
1417 add_action( "woocommerce_shortcode_before_{$type}_loop", function () {
1418 wc_set_loop_prop( 'is_shortcode', false );
1419 } );
1420
1421 if(!empty($atts['paginate'])){
1422 $page = get_query_var( 'paged', 1 );
1423
1424 if( 1 < $page ) {
1425 $query_args['paged'] = $page;
1426 }
1427 }
1428
1429 // Always query only IDs
1430 $query_args['fields'] = 'ids';
1431
1432 }
1433
1434 return $query_args;
1435 }