PluginProbe
Page Builder: Pagelayer – Drag and Drop website builder / 1.0.0
Page Builder: Pagelayer – Drag and Drop website builder v1.0.0
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 1.0.0, at main/functions.php

1,465 lines 36.0 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 // Pagelayer live link
403 function pagelayer_livelink($id){
404 return pagelayer_shortlink($id).'&pagelayer-live=1';
405 }
406
407 // Are we in live mode ?
408 function pagelayer_is_live(){
409
410 global $post;
411
412 // Are we seeing the post ?
413 if(!isset($post) || !isset($post->ID) || empty($post->ID)){
414 return false;
415 }
416
417 // Is it the live mode ?
418 if(pagelayer_optreq('pagelayer-live')){
419 return true;
420 }
421
422 return false;
423
424 }
425
426 // Are we in live IFRAME mode ?
427 function pagelayer_is_live_iframe(){
428
429 // Are we seeing the post ?
430 if(!pagelayer_is_live()){
431 return false;
432 }
433
434 // Is it the live mode ?
435 if(pagelayer_optreq('pagelayer-iframe')){
436 return true;
437 }
438
439 return false;
440
441 }
442
443 // Can the current user edit the post ?
444 function pagelayer_user_can_edit($post = NULL){
445
446 global $wp_the_query, $current_user;
447
448 if(!isset($post) || empty($post) || $post === NULL){
449 global $post;
450 }
451
452 wp_get_current_user();
453
454 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))){
455 return true;
456 }
457
458 return false;
459
460 }
461
462 // Language sting function
463 function __pl($key){
464
465 global $pagelayer;
466
467 if(!empty($pagelayer->l[$key])){
468 return $pagelayer->l[$key];
469 }
470
471 return $key;
472
473 }
474
475 // Give the list of icon sources
476 function pagelayer_icon_sources(){
477 return array();
478 }
479
480 // Loads the shortcodes
481 function pagelayer_load_shortcodes(){
482
483 include_once(PAGELAYER_DIR.'/main/shortcode_functions.php');
484 if(defined('PAGELAYER_PREMIUM')){
485 include_once(PAGELAYER_DIR.'/main/premium_functions.php');
486 }
487 include_once(PAGELAYER_DIR.'/main/shortcodes.php');
488
489 // pQuery
490 include_once(PAGELAYER_DIR.'/lib/pquery/IQuery.php');
491 include_once(PAGELAYER_DIR.'/lib/pquery/gan_formatter.php');
492 include_once(PAGELAYER_DIR.'/lib/pquery/gan_node_html.php');
493 include_once(PAGELAYER_DIR.'/lib/pquery/gan_tokenizer.php');
494 include_once(PAGELAYER_DIR.'/lib/pquery/gan_parser_html.php');
495 include_once(PAGELAYER_DIR.'/lib/pquery/gan_selector_html.php');
496 include_once(PAGELAYER_DIR.'/lib/pquery/gan_xml2array.php');
497 include_once(PAGELAYER_DIR.'/lib/pquery/pQuery.php');
498
499 // Apply filter to load custom widgets
500 do_action('pagelayer_load_custom_widgets');
501
502 }
503
504 // Add the shortcodes to the pagelayer list
505 function pagelayer_add_shortcode($tag, $params = array()){
506
507 global $pagelayer;
508
509 // Is there a handler function ?
510 if(!empty($params['func'])){
511
512 if($tag == 'pl_row'){
513 $inner_tag = 'pl_inner_row';
514 add_shortcode($inner_tag, 'pagelayer_render_shortcode');
515 }
516
517 if($tag == 'pl_col'){
518 $inner_tag = 'pl_inner_col';
519 add_shortcode($inner_tag, 'pagelayer_render_shortcode');
520 }
521
522 add_shortcode($tag, 'pagelayer_render_shortcode');//$params['func']);
523 //unset($params['func']);
524 }
525
526 // Is there a group ?
527 if(empty($params['group'])){
528 $params['group'] = 'misc';
529 }
530
531 // Add the advanced styling group
532 $params['options'] = [
533 'ele_bg_styles' => __pl('ele_bg_styles'),
534 'ele_styles' => __pl('ele_styles'),
535 'border_styles' => __pl('border_styles'),
536 'animation_styles' => __pl('animation_styles'),
537 'responsive_styles' => __pl('responsive_styles'),
538 'custom_styles' => __pl('custom_styles'),
539 ];
540
541 // Are the settings there which hold the params ?
542 if(empty($params['settings'])){
543 $params['settings'] = [
544 'params' => $params['name'],
545 ];
546 }
547
548 // Disable the style options
549 if(!empty($params['styles'])){
550 $params['settings'] = array_merge($params['settings'], $params['styles']);
551 unset($params['styles']);
552 }
553
554 /*// The following is for testing only
555 $r = [];
556 foreach($pagelayer->styles as $k => $v){
557 foreach($v as $kk => $vv){
558 $r[$kk] = $kk;
559 }
560 }
561 //print_r($r);die();
562
563 foreach($params['settings'] as $k => $v){
564 if(empty($params[$k])) continue;
565 foreach($params[$k] as $kk => $vv){
566 if(!empty($r[$kk])){
567 echo 'Duplicate KEY '.$kk.' in Shortcode '.$tag."<br>";
568 }
569 }
570 }
571 //die();*/
572
573 // Insert the shortcode
574 $pagelayer->shortcodes[$tag] = $params;
575 $pagelayer->groups[$params['group']][] = $tag;
576
577 }
578
579 // Returns the Image values
580 function pagelayer_image($id){
581
582 global $pagelayer;
583
584 $ret = [];
585
586 // External image ?
587 if(pagelayer_is_external_img($id)){
588
589 $ret['full-url'] = $id;
590
591 // Attachment
592 }elseif(!empty($id)){
593
594 $id = (int) @$id;
595
596 $image = get_post($id);
597
598 // Is there an attachment which is an image ?
599 if(!empty($image) && $image->post_type == 'attachment' && wp_attachment_is_image($id)){
600
601 // Need to export necessary media
602 if(!empty($pagelayer->export_mode)){
603 $pagelayer->media_to_export[] = $id;
604 }
605
606 $sizes = get_intermediate_image_sizes();
607 array_unshift($sizes, 'full');
608
609 foreach($sizes as $size){
610 $src = wp_get_attachment_image_src($id, $size);
611 $ret[$size.'-url'] = $src[0];
612 }
613
614 // Title and Alt
615 $title = esc_attr($image->post_title);
616 $alt = get_post_meta($id, '_wp_attachment_image_alt', true);
617 $alt = empty($alt) ? $image->post_excerpt : $alt;
618 $alt = empty($alt) ? $image->post_title : $alt;
619 $alt = empty($alt) ? '' : trim(strip_tags($alt));
620 $link = get_attachment_link($id);
621 $caption = wp_get_attachment_caption($id);
622 $caption = !empty($caption) ? $caption : '';
623
624 $ret['alt'] = $alt;
625 $ret['title'] = $title;
626 $ret['link'] = $link;
627 $ret['caption'] = $caption;
628
629 }
630
631 }
632
633 // No image
634 if(empty($ret['full-url'])){
635 $ret['full-url'] = PAGELAYER_URL.'/images/default-image.png';
636 }
637
638 $ret['url'] = $ret['full-url'];
639
640 return $ret;
641
642 }
643
644 // Checks if the given parameter is an external link or a wp attachment id
645 function pagelayer_is_external_img($img = ''){
646
647 if(empty($img)){
648 return false;
649 }
650
651 if(preg_match('#http://#is', $img) || preg_match('#https://#is', $img) || preg_match('#^{{#is', $img)){
652 return true;
653 }
654
655 return false;
656
657 }
658
659 // Returns the attachment url
660 function pagelayer_attachment($id){
661
662 $ret = [];
663
664 // External url ?
665 if(pagelayer_is_external_img($id)){
666
667 $ret['url'] = $id;
668
669 // Attachment
670 }elseif(!empty($id)){
671
672 // Need to export necessary media
673 if(!empty($pagelayer->export_mode)){
674 $pagelayer->media_to_export[] = $id;
675 }
676
677 $ret['url'] = wp_get_attachment_url($id);
678
679 }
680
681 return $ret;
682
683 }
684
685 // Convert the regular URL of a Video to a Embed URL
686 // Todo : Check
687 function pagelayer_video_url($source){
688
689 if (!empty($source)) {
690 $source = filter_var($source, FILTER_SANITIZE_URL);
691 $source = str_replace('&amp;', '&', $source);
692 $url = parse_url($source);
693 $videoSite ='';
694
695 $youtubeRegExp = '/youtube\.com|youtu\.be/is';
696 $vimeoRegExp = '/vimeo\.com/is';
697
698 if (preg_match($youtubeRegExp, $source)) {
699 $videoSite = 'youtube';
700 } else if (preg_match($vimeoRegExp, $source)) {
701 $videoSite = 'vimeo';
702 }
703
704 switch ($videoSite) {
705 case 'youtube':
706
707 if (preg_match('/youtube\.com/is', $source)) {
708
709 if (preg_match('/watch/is', $source)) {
710 parse_str($url['query'], $parameters);
711
712 if (isset($parameters['v']) && !empty($parameters['v'])) {
713 $videoId = $parameters['v'];
714 }
715
716 } else if (preg_match('/embed/is', $url['path'])) {
717 $path = explode('/', $url['path']);
718 if (isset($path[2]) && !empty($path[2])) {
719 $videoId = $path[2];
720 }
721 }
722
723 } else if (preg_match('/youtu\.be/is', $url['host'])) {
724 $path = explode('/', $url['path']);
725
726 if (isset($path[1]) && !empty($path[1])) {
727 $videoId = $path[1];
728 }
729
730 }
731
732 return '//youtube.com/embed/'.$videoId;
733
734 break;
735 case 'vimeo':
736
737 if (preg_match('/player\.vimeo\.com/is', $url['host']) && preg_match('/video/is', $url['path'])) {
738 $path = explode('/', $url['path']);
739
740 if (isset($path[2]) && !empty($path[2])) {
741 $videoId = $path[2];
742 }
743
744 } else if (preg_match('/vimeo\.com/is', $url['host'])) {
745 $path = explode('/', $url['path']);
746
747 if (isset($path[1]) && !empty($path[1])) {
748 $videoId = $path[1];
749 }
750
751 }
752
753 return '//player.vimeo.com/video/'.$videoId;
754
755 break;
756 default:
757
758 return $source;
759
760 }
761
762 }
763 }
764
765
766 // As per the JS specification
767 function pagelayer_escapeHTML($str){
768
769 $replace = [
770 ']' => '&#93;',
771 '[' => '&#91;',
772 //'=' => '&#61;',
773 '<' => '&lt;',
774 '>' => '&gt;',
775 '"' => '&quot;',
776 //'&' => '&amp;',
777 '\'' => '&#39;'
778 ];
779
780 $str = str_replace(array_keys($replace), array_values($replace), $str);
781
782 return $str;
783 }
784
785 // As per the JS specification
786 function pagelayer_unescapeHTML($str){
787 $replace = [
788 '#93' => ']',
789 '#91' => '[',
790 //'#61' => '=',
791 'lt' => '<',
792 'gt' => '>',
793 'quot' => '"',
794 //'amp' => '&',
795 '#39' => '\''
796 ];
797
798 foreach($replace as $k => $v){
799 $str = str_replace('&'.$k.';', $v, $str);
800 }
801 return $str;
802 }
803
804 // Show promo notice on dashboard
805 function pagelayer_show_promo(){
806
807 global $pagelayer_promo_opts;
808 $opts = $pagelayer_promo_opts;
809
810 echo '<style>
811 .pagelayer_promo_button {
812 background-color: #4CAF50; /* Green */
813 border: none;
814 color: white;
815 padding: 6px 10px;
816 text-align: center;
817 text-decoration: none;
818 display: inline-block;
819 font-size: 13px;
820 margin: 4px 2px;
821 -webkit-transition-duration: 0.4s; /* Safari */
822 transition-duration: 0.4s;
823 cursor: pointer;
824 }
825 .pagelayer_promo_button:focus{
826 border: none;
827 color: white;
828 }
829 .pagelayer_promo_button1 {
830 color: white;
831 background-color: #4CAF50;
832 border:3px solid #4CAF50;
833 }
834 .pagelayer_promo_button1: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 border:3px solid #4CAF50;
838 }
839 .pagelayer_promo_button2 {
840 color: white;
841 background-color: #0085ba;
842 }
843 .pagelayer_promo_button2:hover {
844 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
845 color: white;
846 }
847 .pagelayer_promo_button3 {
848 color: white;
849 background-color: #365899;
850 }
851 .pagelayer_promo_button3:hover {
852 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
853 color: white;
854 }
855 .pagelayer_promo_button4 {
856 color: white;
857 background-color: rgb(66, 184, 221);
858 }
859 .pagelayer_promo_button4:hover {
860 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
861 color: white;
862 }
863 .pagelayer_promo-close{
864 float:right;
865 text-decoration:none;
866 margin: 5px 10px 0px 0px;
867 }
868 .pagelayer_promo-close:hover{
869 color: red;
870 }
871 </style>
872 <script type="application/javascript">
873 jQuery(document).ready(function(){
874 jQuery("#pagelayer_promo .pagelayer_promo-close").click(function(){
875 var data;
876 jQuery("#pagelayer_promo").hide();
877 // Save this preference
878 jQuery.post("'.admin_url('?pagelayer_promo=0').'", data, function(response) {
879 //alert(response);
880 });
881 });
882 });
883 </script>
884
885 <div class="notice notice-success" id="pagelayer_promo" style="min-height:90px">
886 <a class="pagelayer_promo-close" href="javascript:" aria-label="Dismiss this Notice">
887 <span class="dashicons dashicons-dismiss"></span> Dismiss
888 </a>';
889
890 if(!empty($opts['image'])){
891 echo '<a href="'.$opts['website'].'"><img src="'.$opts['image'].'" style="float:left; margin:10px 20px 10px 10px" width="67" /></a>';
892 }
893
894 echo '
895 <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>
896 <p>
897 '.(empty($opts['rating']) ? '' : '<a class="pagelayer_promo_button pagelayer_promo_button2" target="_blank" href="'.$opts['rating'].'">Rate it 5�
898 \'s</a>').'
899 '.(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>').'
900 '.(empty($opts['twitter']) ? '' : '<a class="pagelayer_promo_button pagelayer_promo_button4" target="_blank" href="'.$opts['twitter'].'"><span class="dashicons dashicons-twitter"></span> Tweet</a>').'
901 '.(empty($opts['website']) ? '' : '<a class="pagelayer_promo_button pagelayer_promo_button4" target="_blank" href="'.$opts['website'].'">Visit our website</a>').'
902 </p>
903 </div>';
904
905 }
906
907 // Are we to show a promo ?
908 function pagelayer_maybe_promo($opts){
909
910 global $pagelayer_promo_opts;
911
912 // There must be an interval
913 if(empty($opts['interval'])){
914 return false;
915 }
916
917 // Are we to show a promo
918 $opt_name = 'pagelayer_promo_time';
919 $promo_time = get_option($opt_name);
920
921 // First time access
922 if(empty($promo_time)){
923 update_option($opt_name, time() + (!empty($opts['after']) ? $opts['after'] * 86400 : 0));
924 $promo_time = get_option($opt_name);
925 }
926
927 // Is there interval elapsed
928 if(time() > $promo_time){
929 $pagelayer_promo_opts = $opts;
930 add_action('admin_notices', 'pagelayer_show_promo');
931 }
932
933 // Are we to disable the promo
934 if(isset($_GET['pagelayer_promo']) && (int)$_GET['pagelayer_promo'] == 0){
935 update_option($opt_name, time() + ($opts['interval'] * 86400));
936 die('DONE');
937 }
938
939 }
940
941 // Bread Crumbs with links
942 function pagelayer_get_breadcrumb(){
943
944 // Home page
945 $ret = '<a href="'.home_url().'" rel="nofollow">{{home}}</a>';
946
947 // Is Front page
948 if(is_front_page()){
949 return $ret;
950
951 // Is search query
952 }elseif(is_search()){
953 $ret .= '<b class="pagelayer-breadcrumb-sep" if="{{separator}}">{{separator}}</b><b class="pagelayer-breadcrumb-prefix" if="{{search_prefix}}">{{search_prefix}}</b>';
954 $ret .= '<em>';
955 $ret .= get_search_query();
956 $ret .= '</em>';
957
958 //Is category or single post
959 }elseif(is_category() || is_single()){
960
961 $ret .= '<b class="pagelayer-breadcrumb-sep" if="{{separator}}">{{separator}}</b>';
962 $categories = get_the_category();
963 $separator = ' ';
964 $output = '';
965 if(!empty($categories)){
966 $ret .= get_category_parents($categories[0], true, ' <b class="pagelayer-breadcrumb-sep" if="{{separator}}">{{separator}}</b> ');
967 }
968 if(is_single()) {
969 /* if (empty($categories)){
970 $ret .= ' <b class="pagelayer-breadcrumb-sep" if="{{separator}}">{{separator}}</b> ';
971 } */
972 $ret .= get_the_title();
973 }
974
975 // Is page
976 }elseif(is_page()){
977 $ret .= '<b class="pagelayer-breadcrumb-sep" if="{{separator}}">{{separator}}</b>';
978 $ret .= get_the_title();
979 }else{
980 $ret .= '<b class="pagelayer-breadcrumb-sep" if="{{separator}}">{{separator}}</b>';
981 $ret .= wp_title('', false );
982 }
983
984 // wooCommerce Integration left
985
986 return $ret;
987 }
988
989 // Portfolio Posts
990 function pagelayer_widget_posts($args){
991
992 $r = new \WP_Query($args);
993
994 $ret = '';
995 if ( $r->have_posts() ){
996
997 if($args['filter_by'] != 'none' && $args['post_type'] == 'post'){
998 $ret .= '<div class="pagelayer-postfolio-filter">';
999
1000 $data_filter = ( $args['filter_by'] == 'category' ? get_categories() : get_tags() );
1001
1002 if(!empty($data_filter)){
1003
1004 $ret .= '<div class="pagelayer-postfolio-btn" data-filter="all">'.__pl('All').'</div>';
1005
1006 foreach($data_filter as $filter) {
1007 $ret .= '<div class="pagelayer-postfolio-btn" data-filter="'.$filter->name.'">' . $filter->name . '</div>';
1008 }
1009
1010 }
1011
1012 $ret .= '</div>';
1013 }
1014
1015 $ret .= '<div class="pagelayer-postfolio-container">';
1016
1017 while ( $r->have_posts() ) : $r->the_post();
1018 $post_meta = ( $args['filter_by'] == 'category' ? get_the_category() : get_the_tags() );
1019 $meta_attr = '';
1020 if($post_meta){
1021
1022 $meta_array = array();
1023 foreach( $post_meta as $meta ){
1024 $meta_array[] = $meta->name;
1025 }
1026 $meta_attr .= ' data-category="'.implode(' ', $meta_array).'"';
1027 }
1028
1029 $ret .= '<div class="pagelayer-postfolio-thumb"'.(has_post_thumbnail() ? ' style="background:url('.get_the_post_thumbnail_url().')"' : ''). $meta_attr .'>';
1030 $ret .= '<a href="'.esc_url( get_permalink() ).'" rel="bookmark">';
1031 $ret .= '<div class="pagelayer-postfolio-content">';
1032 $ret .= '<h4 class="pagelayer-entry-title">'.get_the_title().'</h4>';
1033 $ret .= '</div></a></div>';
1034
1035 endwhile;
1036
1037 $ret .= '</div>';
1038
1039 }
1040
1041 return $ret;
1042 }
1043
1044 // List all available sizes of images registered on WordPress
1045 function pagelayer_image_sizes(){
1046
1047 $sizes = array();
1048 $sizes = get_intermediate_image_sizes();
1049 $ret = array();
1050 foreach($sizes as $size){
1051 $ret[$size] = __pl($size);
1052 }
1053
1054 return $ret;
1055 }
1056
1057 function pagelayer_posts($params, $args = []){
1058
1059 // If args is empty
1060 if(empty($args)){
1061 $args = array(
1062 'post_type' => $params['post_type'],
1063 'posts_per_page' => $params['posts_per_page'],
1064 'order' => $params['order']
1065 );
1066
1067 if($params['exc_length']){
1068 $exc_length = (int) $params['exc_length'];
1069 add_filter( 'excerpt_length', function($length) use($exc_length){
1070 return $exc_length;
1071 }, 999 );
1072 }
1073
1074 if($params['term']){
1075
1076 $term = explode(':', $params['term']);
1077 //pagelayer_print($term);
1078 if($term[0] == 'category'){
1079 $args['category_name'] = $term[1];
1080 }
1081 if($term[0] == 'post_tag'){
1082 $args['tag'] = $term[1];
1083 }
1084 }
1085
1086 if($params['exc_term']){
1087
1088 $term = explode(':', $params['exc_term']);
1089 //pagelayer_print($term);
1090 if($term[0] == 'category'){
1091 $args['category__not_in'] = $term[2];
1092 }
1093 if($term[0] == 'post_tag'){
1094 $args['tag__not_in'] = $term[2];
1095 }
1096 }
1097
1098 if($params['author_name']){
1099 $author_name = explode(':', $params['author_name']);
1100 $args['author_name'] = $author_name[0];
1101 }
1102
1103 if($params['exc_author']){
1104 $exc_author = explode(':', $params['exc_author']);
1105 $args['author'] = '-'.$exc_author[1];
1106 }
1107
1108 if(!empty($params['offset'])){
1109 $args['offset'] = $params['offset'];
1110 }
1111
1112 if(!empty($params['ignore_sticky'])){
1113 $args['ignore_sticky_posts'] = $params['ignore_sticky'];
1114 }
1115
1116 if(!empty($params['orderby'])){
1117 $args['orderby'] = $params['orderby'];
1118 }
1119
1120 if($params['by_period']){
1121 $date_arg = array();
1122 switch($params['by_period']){
1123 case 'last_day':
1124 $date_arg['day'] = date('j')-1;
1125 break;
1126 case 'last_week':
1127 $date_arg['week'] = date('W')-1;
1128 break;
1129 case 'last_month':
1130 $date_arg['month'] = date('n')-1;
1131 break;
1132 case 'last_year':
1133 $date_arg['year'] = date('Y')-1;
1134 break;
1135 case 'custom':
1136 $date_arg['before'] = $params['before_date'];
1137 $date_arg['after'] = $params['after_date'];
1138 break;
1139 }
1140 $args['date_query'] = array(
1141 $date_arg
1142 );
1143 }
1144 }
1145 //pagelayer_print($args);
1146
1147 $postsquery = new WP_Query($args);
1148 $data = '';
1149
1150 if(!$postsquery->have_posts()){
1151 return '<h3>Something went wrong, Please give proper inputs!</h3>';
1152 }
1153
1154 while($postsquery->have_posts()) : $postsquery->the_post();
1155 $data .= '<div class="pagelayer-wposts-col">
1156 <div class="pagelayer-wposts-post">
1157 <div class="pagelayer-wposts-featured">';
1158 $data .= '<a href="'. get_the_permalink() .'">';
1159
1160 if(isset($params['show_thumb']) && has_post_thumbnail( $postsquery->ID )){
1161 $data .= '<div class="pagelayer-wposts-thumb"'.(has_post_thumbnail() ? ' style="background:url('.get_the_post_thumbnail_url($postsquery->ID,$params['thumb_size']).')"' : '').'></div>';
1162 }
1163 /* if($params['show_thumb'] && has_post_thumbnail( $postsquery->ID )){
1164 $data .= get_the_post_thumbnail_url($postsquery->ID,$params['thumb_size']);
1165 } */
1166 $data .= '</a></div>
1167 <div class="pagelayer-wposts-content">';
1168
1169 if(isset($params['show_title'])){
1170 $data .= '<a href="'.esc_url( get_permalink() ).'" rel="bookmark"><div class="pagelayer-wposts-title">'. get_the_title().'</div></a>';
1171 }
1172
1173 $data .= '<div class="pagelayer-wposts-meta">';
1174 $sep = '';
1175 if(isset($params['meta_sep'])){
1176 $sep = '<b class="pagelayer-wposts-sep">'.$params['meta_sep'].'</b>';
1177 }
1178 if(isset($params['author'])){
1179 $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;
1180 }
1181 if(isset($params['date'])){
1182 $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;
1183 }
1184 if(isset($params['category'])){
1185 $category = get_the_category();
1186 $singlecategory = '';
1187 foreach( $category as $cat ){
1188 $singlecategory .= '<a href="' . get_tag_link( $cat->term_id ) . '">'. $cat->name .'</a>';
1189 }
1190 $data .= '<span class="pagelayer-wposts-category">' . $singlecategory . '</span>'.$sep;
1191 }
1192 if(isset($params['tags'])){
1193 $tags = get_the_tags();
1194 $singletag = '';
1195 foreach( $tags as $tag ){
1196 $singletag .= '<a href="' . get_tag_link( $tag->term_id ) . '">'. $tag->name .'</a>';
1197 }
1198 $data .= '<span class="pagelayer-wposts-tags">'.$singletag.'</span>'.$sep;
1199
1200 }
1201 if(isset($params['comments'])){
1202 $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;
1203 }
1204
1205 $data .= '</div>';
1206
1207 if(isset($params['show_content'])){
1208 $data .= '<div class="pagelayer-wposts-excerpt">';
1209 if($params['show_content'] == 'excerpt'){
1210 $data .= do_shortcode(get_the_excerpt());
1211 }elseif($params['show_content'] == 'full'){
1212 $data .= do_shortcode(get_the_content());
1213 }
1214 $data .= '</div>';
1215 }
1216
1217 if(isset($params['show_more'])){
1218 $data .= '<a class="pagelayer-wposts-more" href="'. get_the_permalink().'">'.$params['more'].'</a>';
1219 }
1220
1221 //$data .= '<div class="pagelayer-wposts-date"><p>'.get_the_date().'</p></div>';
1222 $data .= '</div></div></div>';
1223 endwhile;
1224
1225 return $data;
1226 }
1227
1228 // Get Post Revision
1229 function pagelayer_get_post_revision_by_id($postID){
1230
1231 // Insert the post revision into the database
1232 $post_revisions = array();
1233 $reviews = wp_get_post_revisions($postID);
1234
1235 foreach($reviews as $values){
1236
1237 $date_format = date_i18n('j-M @ H:i', strtotime( $values->post_modified ) );
1238 $user_meta = get_userdata($values->post_author);
1239
1240 if ( false !== strpos( $values->post_name, 'autosave' ) ) {
1241 $type = 'autosave';
1242 } else {
1243 $type = 'revision';
1244 }
1245
1246 $post_tmp_data = array(
1247 'ID' => $values->ID,
1248 'post_author_name' => $user_meta->data->display_name,
1249 'post_author_url' => get_avatar_url($values->post_author),
1250 'post_date' => $date_format,
1251 'post_date_ago' => human_time_diff(strtotime($values->post_modified), current_time( 'timestamp' )) . ' ago ',
1252 'post_type' => $type,
1253 );
1254
1255 $post_revisions[] = $post_tmp_data;
1256 }
1257
1258 return $post_revisions;
1259 }
1260
1261 // Gets author data
1262 function pagelayer_author_data($postID){
1263
1264 $authorID = get_post_field('post_author', $postID);
1265 $data['display_name'] = get_the_author_meta( 'display_name' , $authorID );
1266 $data['description'] = get_the_author_meta( 'description' , $authorID );
1267 $data['user_url'] = get_author_posts_url( $authorID , '' );
1268 $data['avatar'] = get_avatar_url( $authorID );
1269
1270 return $data;
1271 }
1272
1273 // Posts Slider
1274 function pagelayer_posts_slider($params){
1275
1276 $args = array();
1277
1278 if(isset($params['post']['post_type'])){
1279 $args['post_type'] = $params['post']['post_type'];
1280 }
1281
1282 if(isset($params['post']['category'])){
1283 $args['category_name'] = $params['post']['category'];
1284 }
1285
1286 if(isset($params['post']['tags'])){
1287 $args['tag'] = $params['post']['tags'];
1288 }
1289
1290 if(isset($params['post']['order_by'])){
1291 $args['orderby'] = $params['post']['order_by'];
1292 }
1293
1294 if(isset($params['post']['sort_order'])){
1295 $args['order'] = $params['post']['sort_order'];
1296 }
1297
1298 if(isset($params['post']['post_count'])){
1299 $args['posts_per_page'] = $params['post']['post_count'];
1300 }
1301
1302 $data = '';
1303 $postsquery = new WP_Query($args);
1304 if ( $postsquery->have_posts() ){
1305 while ( $postsquery->have_posts() ) : $postsquery->the_post();
1306 $data .= '<li class="pagelayer-posts-slider-col">
1307 <div class="pagelayer-posts-slider-post">
1308 <div class="pagelayer-posts-slider-featured-img">';
1309 $data .= '<a href="'. get_the_permalink() .'">';
1310 if(has_post_thumbnail( $postsquery->ID ) ){
1311 if($params['post']['image_size'] == "full" || $params['post']['image_size'] == "custom" ){
1312 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $postsquery->ID ), 'single-post-thumbnail' );
1313 $data .= '<img class="pagelayer-img" src="'.$image[0].'" class="pagelayer-posts-slider-img">';
1314 }else if($params['post']['image_size'] == "thumbnail"){
1315 $data .= get_the_post_thumbnail();
1316 }
1317 }
1318 $data .= '</a></div>
1319 <div class="pagelayer-posts-slider-content">';
1320 $data .= '<p class="pagelayer-posts-slider-title">'. get_the_title().'</p>';
1321 $data .= '<div class="pagelayer-posts-slider-excerpt">';
1322 if($params['post']['show_excerpt'] == "true"){
1323 if(has_excerpt()){
1324 $excerpt = get_the_excerpt();
1325 $data .= do_shortcode($excerpt);
1326 }
1327 }
1328 $data .= '</div>';
1329 $data .= '<a class="pagelayer-posts-slider-link" href="'. get_the_permalink().'">Read More</a>';
1330 $data .= '<div class="pagelayer-post-slider-date"><p>'.get_the_date().'</p></div>';
1331 $data .= '</div></div></li>';
1332 endwhile;
1333 }
1334 return $data;
1335 }
1336
1337 // Gets the site logo URLs
1338 function pagelayer_site_logo(){
1339
1340 if(get_theme_mod('custom_logo')){
1341 $logo_id = get_theme_mod('custom_logo');
1342 return pagelayer_image($logo_id);
1343 }
1344
1345 return NULL;
1346 }
1347
1348 // Create select options
1349 function pagelayer_create_sel_options( $opt_array , $selected = ''){
1350 $options = '';
1351 foreach($opt_array as $x => $val){
1352
1353 // Single item
1354 if(is_string($opt_array[$x])){
1355 $options .= pagelayer_sel_option($x, $val, $selected);
1356
1357 // Groups
1358 }else{
1359 $options .= '<optgroup label="'. $x .'">';
1360
1361 foreach($opt_array[$x] as $y => $gval){
1362 $options .= pagelayer_sel_option($y, $gval, $selected);
1363 }
1364
1365 $options .= '</optgroup>';
1366 }
1367
1368 }
1369
1370 return $options;
1371 }
1372
1373 // Create option HTML
1374 function pagelayer_sel_option($val, $lang, $selected){
1375 return '<option value="'. $val .'" '. (($val != $selected) ? '' : 'selected="selected"') .' >'. $lang .'</option>';
1376 }
1377
1378 function pagelayer_get_post_term(){
1379
1380 $args = [
1381 'taxonomy' => array('category','post_tag'),
1382 'hide_empty' => false,
1383 ];
1384
1385 $terms = get_terms( $args );
1386
1387 $ret = array();
1388 foreach ( $terms as $term ) {
1389 $ret[$term->taxonomy.':'.$term->slug.':'.$term->term_taxonomy_id] = $term->taxonomy .': '. $term->name;
1390 }
1391 //pagelayer_print($terms);die();
1392 return $ret;
1393 }
1394
1395 function pagelayer_get_post_author(){
1396
1397 $args = [
1398 'who' => 'authors',
1399 'fields' => [
1400 'ID',
1401 'display_name',
1402 'user_nicename',
1403 ]
1404 ];
1405
1406 $authors = new \WP_User_Query( $args );
1407
1408 $ret = array();
1409 foreach ( $authors->get_results() as $author ) {
1410 $ret[$author->user_nicename.':'.$author->ID] = $author->display_name;
1411 }
1412 //pagelayer_print($authors->get_results());die();
1413 return $ret;
1414 }
1415
1416 // Simply echo and dir
1417 function pagelayer_json_output(&$done){
1418
1419 echo json_encode($done);
1420 wp_die();
1421
1422 }
1423
1424 // Get the current query for render the product
1425 function pagelayer_shortcode_current_query($query_args, $atts, $type){
1426 global $wp_query;
1427
1428 if($type == 'pagelayer_current_query'){
1429
1430 if ( ! is_page( wc_get_page_id( 'shop' ) ) ) {
1431 $query_args = $wp_query->query_vars;
1432 }
1433
1434 add_action( "woocommerce_shortcode_before_{$type}_loop", function () {
1435 wc_set_loop_prop( 'is_shortcode', false );
1436 } );
1437
1438 if(!empty($atts['paginate'])){
1439 $page = get_query_var( 'paged', 1 );
1440
1441 if( 1 < $page ) {
1442 $query_args['paged'] = $page;
1443 }
1444 }
1445
1446 // Always query only IDs
1447 $query_args['fields'] = 'ids';
1448
1449 }
1450
1451 return $query_args;
1452 }
1453
1454 function pagelayer_export_content($content){
1455
1456 // Just call do_shortcode so we can get list of media files to export
1457 //do_shortcode($content);
1458
1459 $theme_url = preg_replace('/http(s?):\/\//is', '', get_stylesheet_directory_uri());
1460
1461 $content = preg_replace('/http(s?):\/\/'.preg_quote($theme_url, '/').'/is', '{{theme_url}}', $content);
1462
1463 return $content;
1464
1465 }