PluginProbe
Page Builder: Pagelayer – Drag and Drop website builder / 0.9.6
Page Builder: Pagelayer – Drag and Drop website builder v0.9.6
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.6, at main/functions.php

932 lines 21.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 //////////////////////////////////////////////////////////////
4 //===========================================================
5 // class.php
6 //===========================================================
7 // PAGELAYER
8 // Inspired by the DESIRE to be the BEST OF ALL
9 // ----------------------------------------------------------
10 // Started by: Pulkit Gupta
11 // Date: 23rd Jan 2017
12 // Time: 23:00 hrs
13 // Site: http://pagelayer.com/wordpress (PAGELAYER)
14 // ----------------------------------------------------------
15 // Please Read the Terms of use at http://pagelayer.com/tos
16 // ----------------------------------------------------------
17 //===========================================================
18 // (c)Pagelayer Team
19 //===========================================================
20 //////////////////////////////////////////////////////////////
21
22 // Are we being accessed directly ?
23 if(!defined('PAGELAYER_VERSION')) {
24 exit('Hacking Attempt !');
25 }
26
27 // 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 include_once(PAGELAYER_DIR.'/main/shortcodes.php');
480
481 // pQuery
482 include_once(PAGELAYER_DIR.'/lib/pquery/IQuery.php');
483 include_once(PAGELAYER_DIR.'/lib/pquery/gan_formatter.php');
484 include_once(PAGELAYER_DIR.'/lib/pquery/gan_node_html.php');
485 include_once(PAGELAYER_DIR.'/lib/pquery/gan_tokenizer.php');
486 include_once(PAGELAYER_DIR.'/lib/pquery/gan_parser_html.php');
487 include_once(PAGELAYER_DIR.'/lib/pquery/gan_selector_html.php');
488 include_once(PAGELAYER_DIR.'/lib/pquery/gan_xml2array.php');
489 include_once(PAGELAYER_DIR.'/lib/pquery/pQuery.php');
490
491 // Apply filter to load custom widgets
492 do_action('pagelayer_load_custom_widgets');
493
494 }
495
496 // Add the shortcodes to the pagelayer list
497 function pagelayer_add_shortcode($tag, $params = array()){
498
499 global $pagelayer;
500
501 // Is there a handler function ?
502 if(!empty($params['func'])){
503
504 if($tag == 'pl_row'){
505 $inner_tag = 'pl_inner_row';
506 add_shortcode($inner_tag, 'pagelayer_render_shortcode');
507 }
508
509 if($tag == 'pl_col'){
510 $inner_tag = 'pl_inner_col';
511 add_shortcode($inner_tag, 'pagelayer_render_shortcode');
512 }
513
514 add_shortcode($tag, 'pagelayer_render_shortcode');//$params['func']);
515 //unset($params['func']);
516 }
517
518 // Is there a group ?
519 if(empty($params['group'])){
520 $params['group'] = 'misc';
521 }
522
523 // Add the advanced styling group
524 $params['options'] = [
525 'ele_bg_styles' => __pl('ele_bg_styles'),
526 'ele_styles' => __pl('ele_styles'),
527 'border_styles' => __pl('border_styles'),
528 'animation_styles' => __pl('animation_styles'),
529 'responsive_styles' => __pl('responsive_styles'),
530 'custom_styles' => __pl('custom_styles'),
531 ];
532
533 // Are the settings there which hold the params ?
534 if(empty($params['settings'])){
535 $params['settings'] = [
536 'params' => $params['name'],
537 ];
538 }
539
540 // Disable the style options
541 if(!empty($params['styles'])){
542 $params['settings'] = array_merge($params['settings'], $params['styles']);
543 unset($params['styles']);
544 }
545
546 // Insert the shortcode
547 $pagelayer->shortcodes[$tag] = $params;
548 $pagelayer->groups[$params['group']][] = $tag;
549
550 }
551
552 // Returns the Image values
553 function pagelayer_image($id){
554
555 $ret = [];
556
557 // External image ?
558 if(pagelayer_is_external_img($id)){
559
560 $ret['full-url'] = $id;
561
562 // Attachment
563 }elseif(!empty($id)){
564
565 $id = (int) @$id;
566
567 $image = get_post($id);
568
569 // Is there an attachment which is an image ?
570 if(!empty($image) && $image->post_type == 'attachment' && wp_attachment_is_image($id)){
571
572 $sizes = get_intermediate_image_sizes();
573 array_unshift($sizes, 'full');
574
575 foreach($sizes as $size){
576 $src = wp_get_attachment_image_src($id, $size);
577 $ret[$size.'-url'] = $src[0];
578 }
579
580 // Title and Alt
581 $title = esc_attr($image->post_title);
582 $alt = get_post_meta($id, '_wp_attachment_image_alt', true);
583 $alt = empty($alt) ? $image->post_excerpt : $alt;
584 $alt = empty($alt) ? $image->post_title : $alt;
585 $alt = empty($alt) ? '' : trim(strip_tags($alt));
586 $link = get_attachment_link($id);
587 $caption = wp_get_attachment_caption($id);
588 $caption = !empty($caption) ? $caption : '';
589
590 $ret['alt'] = $alt;
591 $ret['title'] = $title;
592 $ret['link'] = $link;
593 $ret['caption'] = $caption;
594
595 }
596
597 }
598
599 // No image
600 if(empty($ret['full-url'])){
601 $ret['full-url'] = PAGELAYER_URL.'/images/default-image.png';
602 }
603
604 $ret['url'] = $ret['full-url'];
605
606 return $ret;
607
608 }
609
610 // Checks if the given parameter is an external link or a wp attachment id
611 function pagelayer_is_external_img($img = ''){
612
613 if(empty($img)){
614 return false;
615 }
616
617 if(preg_match('#http://#is', $img) || preg_match('#https://#is', $img) || preg_match('#^{{#is', $img)){
618 return true;
619 }
620
621 return false;
622
623 }
624
625 // Returns the attachment url
626 function pagelayer_attachment($id){
627
628 $ret = [];
629
630 // External url ?
631 if(pagelayer_is_external_img($id)){
632
633 $ret['url'] = $id;
634
635 // Attachment
636 }elseif(!empty($id)){
637
638 $ret['url'] = wp_get_attachment_url($id);
639
640 }
641
642 return $ret;
643
644 }
645
646 // Convert the regular URL of a Video to a Embed URL
647 // Todo : Check
648 function pagelayer_video_url($source){
649
650 if (!empty($source)) {
651 $source = filter_var($source, FILTER_SANITIZE_URL);
652 $source = str_replace('&amp;', '&', $source);
653 $url = parse_url($source);
654
655 $youtubeRegExp = '/youtube\.com|youtu\.be/is';
656 $vimeoRegExp = '/vimeo\.com/is';
657
658 if (preg_match($youtubeRegExp, $source)) {
659 $videoSite = 'youtube';
660 } else if (preg_match($vimeoRegExp, $source)) {
661 $videoSite = 'vimeo';
662 }
663
664 switch ($videoSite) {
665 case 'youtube':
666
667 if (preg_match('/youtube\.com/is', $source)) {
668
669 if (preg_match('/watch/is', $source)) {
670 parse_str($url['query'], $parameters);
671
672 if (isset($parameters['v']) && !empty($parameters['v'])) {
673 $videoId = $parameters['v'];
674 }
675
676 } else if (preg_match('/embed/is', $url['path'])) {
677 $path = explode('/', $url['path']);
678 if (isset($path[2]) && !empty($path[2])) {
679 $videoId = $path[2];
680 }
681 }
682
683 } else if (preg_match('/youtu\.be/is', $url['host'])) {
684 $path = explode('/', $url['path']);
685
686 if (isset($path[1]) && !empty($path[1])) {
687 $videoId = $path[1];
688 }
689
690 }
691
692 return '//youtube.com/embed/'.$videoId;
693
694 break;
695 case 'vimeo':
696
697 if (preg_match('/player\.vimeo\.com/is', $url['host']) && preg_match('/video/is', $url['path'])) {
698 $path = explode('/', $url['path']);
699
700 if (isset($path[2]) && !empty($path[2])) {
701 $videoId = $path[2];
702 }
703
704 } else if (preg_match('/vimeo\.com/is', $url['host'])) {
705 $path = explode('/', $url['path']);
706
707 if (isset($path[1]) && !empty($path[1])) {
708 $videoId = $path[1];
709 }
710
711 }
712
713 return '//player.vimeo.com/video/'.$videoId;
714
715 break;
716 default:
717
718 return $source;
719
720 }
721
722 }
723 }
724
725
726 // As per the JS specification
727 function pagelayer_escapeHTML($str){
728
729 $replace = [
730 ']' => '&#93;',
731 '[' => '&#91;',
732 //'=' => '&#61;',
733 '<' => '&lt;',
734 '>' => '&gt;',
735 '"' => '&quot;',
736 //'&' => '&amp;',
737 '\'' => '&#39;'
738 ];
739
740 $str = str_replace(array_keys($replace), array_values($replace), $str);
741
742 return $str;
743 }
744
745 // As per the JS specification
746 function pagelayer_unescapeHTML($str){
747 $replace = [
748 '#93' => ']',
749 '#91' => '[',
750 //'#61' => '=',
751 'lt' => '<',
752 'gt' => '>',
753 'quot' => '"',
754 //'amp' => '&',
755 '#39' => '\''
756 ];
757
758 foreach($replace as $k => $v){
759 $str = str_replace('&'.$k.';', $v, $str);
760 }
761 return $str;
762 }
763
764 // Show promo notice on dashboard
765 function pagelayer_show_promo(){
766
767 global $pagelayer_promo_opts;
768 $opts = $pagelayer_promo_opts;
769
770 echo '<style>
771 .pagelayer_promo_button {
772 background-color: #4CAF50; /* Green */
773 border: none;
774 color: white;
775 padding: 6px 10px;
776 text-align: center;
777 text-decoration: none;
778 display: inline-block;
779 font-size: 13px;
780 margin: 4px 2px;
781 -webkit-transition-duration: 0.4s; /* Safari */
782 transition-duration: 0.4s;
783 cursor: pointer;
784 }
785 .pagelayer_promo_button:focus{
786 border: none;
787 color: white;
788 }
789 .pagelayer_promo_button1 {
790 color: white;
791 background-color: #4CAF50;
792 border:3px solid #4CAF50;
793 }
794 .pagelayer_promo_button1:hover {
795 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
796 color: white;
797 border:3px solid #4CAF50;
798 }
799 .pagelayer_promo_button2 {
800 color: white;
801 background-color: #0085ba;
802 }
803 .pagelayer_promo_button2:hover {
804 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
805 color: white;
806 }
807 .pagelayer_promo_button3 {
808 color: white;
809 background-color: #365899;
810 }
811 .pagelayer_promo_button3:hover {
812 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
813 color: white;
814 }
815 .pagelayer_promo_button4 {
816 color: white;
817 background-color: rgb(66, 184, 221);
818 }
819 .pagelayer_promo_button4:hover {
820 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
821 color: white;
822 }
823 .pagelayer_promo-close{
824 float:right;
825 text-decoration:none;
826 margin: 5px 10px 0px 0px;
827 }
828 .pagelayer_promo-close:hover{
829 color: red;
830 }
831 </style>
832 <script type="application/javascript">
833 jQuery(document).ready(function(){
834 jQuery("#pagelayer_promo .pagelayer_promo-close").click(function(){
835 var data;
836 jQuery("#pagelayer_promo").hide();
837 // Save this preference
838 jQuery.post("'.admin_url('?pagelayer_promo=0').'", data, function(response) {
839 //alert(response);
840 });
841 });
842 });
843 </script>
844
845 <div class="notice notice-success" id="pagelayer_promo" style="min-height:90px">
846 <a class="pagelayer_promo-close" href="javascript:" aria-label="Dismiss this Notice">
847 <span class="dashicons dashicons-dismiss"></span> Dismiss
848 </a>';
849
850 if(!empty($opts['image'])){
851 echo '<a href="'.$opts['website'].'"><img src="'.$opts['image'].'" style="float:left; margin:10px 20px 10px 10px" width="67" /></a>';
852 }
853
854 echo '
855 <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>
856 <p>
857 '.(empty($opts['rating']) ? '' : '<a class="pagelayer_promo_button pagelayer_promo_button2" target="_blank" href="'.$opts['rating'].'">Rate it 5�
858 \'s</a>').'
859 '.(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>').'
860 '.(empty($opts['twitter']) ? '' : '<a class="pagelayer_promo_button pagelayer_promo_button4" target="_blank" href="'.$opts['twitter'].'"><span class="dashicons dashicons-twitter"></span> Tweet</a>').'
861 '.(empty($opts['website']) ? '' : '<a class="pagelayer_promo_button pagelayer_promo_button4" target="_blank" href="'.$opts['website'].'">Visit our website</a>').'
862 </p>
863 </div>';
864
865 }
866
867 // Are we to show a promo ?
868 function pagelayer_maybe_promo($opts){
869
870 global $pagelayer_promo_opts;
871
872 // There must be an interval
873 if(empty($opts['interval'])){
874 return false;
875 }
876
877 // Are we to show a promo
878 $opt_name = 'pagelayer_promo_time';
879 $promo_time = get_option($opt_name);
880
881 // First time access
882 if(empty($promo_time)){
883 update_option($opt_name, time() + (!empty($opts['after']) ? $opts['after'] * 86400 : 0));
884 $promo_time = get_option($opt_name);
885 }
886
887 // Is there interval elapsed
888 if(time() > $promo_time){
889 $pagelayer_promo_opts = $opts;
890 add_action('admin_notices', 'pagelayer_show_promo');
891 }
892
893 // Are we to disable the promo
894 if(isset($_GET['pagelayer_promo']) && (int)$_GET['pagelayer_promo'] == 0){
895 update_option($opt_name, time() + ($opts['interval'] * 86400));
896 die('DONE');
897 }
898
899 }
900
901 // Get Post Revision
902 function pagelayer_get_post_revision_by_id($postID){
903
904 // Insert the post revision into the database
905 $post_revisions = array();
906 $reviews = wp_get_post_revisions($postID);
907
908 foreach($reviews as $values){
909
910 $date_format = date_i18n('j-M @ H:i', strtotime( $values->post_modified ) );
911 $user_meta = get_userdata($values->post_author);
912
913 if ( false !== strpos( $values->post_name, 'autosave' ) ) {
914 $type = 'autosave';
915 } else {
916 $type = 'revision';
917 }
918
919 $post_tmp_data = array(
920 'ID' => $values->ID,
921 'post_author_name' => $user_meta->data->display_name,
922 'post_author_url' => get_avatar_url($values->post_author),
923 'post_date' => $date_format,
924 'post_date_ago' => human_time_diff(strtotime($values->post_modified), current_time( 'timestamp' )) . ' ago ',
925 'post_type' => $type,
926 );
927
928 $post_revisions[] = $post_tmp_data;
929 }
930
931 return $post_revisions;
932 }