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

815 lines 18.8 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 add_shortcode($tag, 'pagelayer_render_shortcode');//$params['func']);
504 //unset($params['func']);
505 }
506
507 // Is there a group ?
508 if(empty($params['group'])){
509 $params['group'] = 'misc';
510 }
511
512 // Add the advanced styling group
513 $params['options'] = [
514 'ele_bg_styles' => __pl('ele_bg_styles'),
515 'ele_styles' => __pl('ele_styles'),
516 'border_styles' => __pl('border_styles'),
517 'animation_styles' => __pl('animation_styles'),
518 'responsive_styles' => __pl('responsive_styles'),
519 'custom_styles' => __pl('custom_styles'),
520 ];
521
522 // Are the settings there which hold the params ?
523 if(empty($params['settings'])){
524 $params['settings'] = [
525 'params' => $params['name'],
526 ];
527 }
528
529 // Disable the style options
530 if(!empty($params['styles'])){
531 $params['settings'] = array_merge($params['settings'], $params['styles']);
532 unset($params['styles']);
533 }
534
535 // Insert the shortcode
536 $pagelayer->shortcodes[$tag] = $params;
537 $pagelayer->groups[$params['group']][] = $tag;
538
539 }
540
541 // Returns the Image values
542 function pagelayer_image($id){
543
544 $ret = [];
545
546 // External image ?
547 if(pagelayer_is_external_img($id)){
548
549 $ret['full-url'] = $id;
550
551 // Attachment
552 }elseif(!empty($id)){
553
554 $id = (int) @$id;
555
556 $image = get_post($id);
557
558 // Is there an attachment which is an image ?
559 if(!empty($image) && $image->post_type == 'attachment' && wp_attachment_is_image($id)){
560
561 $sizes = get_intermediate_image_sizes();
562 array_unshift($sizes, 'full');
563
564 foreach($sizes as $size){
565 $src = wp_get_attachment_image_src($id, $size);
566 $ret[$size.'-url'] = $src[0];
567 }
568
569 // Title and Alt
570 $title = esc_attr($image->post_title);
571 $alt = get_post_meta($id, '_wp_attachment_image_alt', true);
572 $alt = empty($alt) ? $image->post_excerpt : $alt;
573 $alt = empty($alt) ? $image->post_title : $alt;
574 $alt = empty($alt) ? '' : trim(strip_tags($alt));
575 $link = get_attachment_link($id);
576 $caption = wp_get_attachment_caption($id);
577 $caption = !empty($caption) ? $caption : '';
578
579 $ret['alt'] = $alt;
580 $ret['title'] = $title;
581 $ret['link'] = $link;
582 $ret['caption'] = $caption;
583
584 }
585
586 }
587
588 // No image
589 if(empty($ret['full-url'])){
590 $ret['full-url'] = PAGELAYER_URL.'/images/default-image.png';
591 }
592
593 $ret['url'] = $ret['full-url'];
594
595 return $ret;
596
597 }
598
599 // Checks if the given parameter is an external link or a wp attachment id
600 function pagelayer_is_external_img($img = ''){
601
602 if(empty($img)){
603 return false;
604 }
605
606 if(preg_match('#http://#is', $img) || preg_match('#https://#is', $img) || preg_match('#^{{#is', $img)){
607 return true;
608 }
609
610 return false;
611
612 }
613
614 // Returns the attachment url
615 function pagelayer_attachment($id){
616
617 $ret = [];
618
619 // External url ?
620 if(pagelayer_is_external_img($id)){
621
622 $ret['url'] = $id;
623
624 // Attachment
625 }elseif(!empty($id)){
626
627 $ret['url'] = wp_get_attachment_url($id);
628
629 }
630
631 return $ret;
632
633 }
634
635 // Convert the regular URL of a Video to a Embed URL
636 // Todo : Check
637 function pagelayer_video_url($source){
638
639 if (!empty($source)) {
640 $source = filter_var($source, FILTER_SANITIZE_URL);
641 $source = str_replace('&amp;', '&', $source);
642 $url = parse_url($source);
643
644 $youtubeRegExp = '/youtube\.com|youtu\.be/is';
645 $vimeoRegExp = '/vimeo\.com/is';
646
647 if (preg_match($youtubeRegExp, $source)) {
648 $videoSite = 'youtube';
649 } else if (preg_match($vimeoRegExp, $source)) {
650 $videoSite = 'vimeo';
651 }
652
653 switch ($videoSite) {
654 case 'youtube':
655
656 if (preg_match('/youtube\.com/is', $source)) {
657
658 if (preg_match('/watch/is', $source)) {
659 parse_str($url['query'], $parameters);
660
661 if (isset($parameters['v']) && !empty($parameters['v'])) {
662 $videoId = $parameters['v'];
663 }
664
665 } else if (preg_match('/embed/is', $url['path'])) {
666 $path = explode('/', $url['path']);
667 if (isset($path[2]) && !empty($path[2])) {
668 $videoId = $path[2];
669 }
670 }
671
672 } else if (preg_match('/youtu\.be/is', $url['host'])) {
673 $path = explode('/', $url['path']);
674
675 if (isset($path[1]) && !empty($path[1])) {
676 $videoId = $path[1];
677 }
678
679 }
680
681 return '//youtube.com/embed/'.$videoId;
682
683 break;
684 case 'vimeo':
685
686 if (preg_match('/player\.vimeo\.com/is', $url['host']) && preg_match('/video/is', $url['path'])) {
687 $path = explode('/', $url['path']);
688
689 if (isset($path[2]) && !empty($path[2])) {
690 $videoId = $path[2];
691 }
692
693 } else if (preg_match('/vimeo\.com/is', $url['host'])) {
694 $path = explode('/', $url['path']);
695
696 if (isset($path[1]) && !empty($path[1])) {
697 $videoId = $path[1];
698 }
699
700 }
701
702 return '//player.vimeo.com/video/'.$videoId;
703
704 break;
705 default:
706
707 return $source;
708
709 }
710
711 }
712 }
713
714
715 // As per the JS specification
716 function pagelayer_escapeHTML($str){
717
718 $replace = [
719 ']' => '&#93;',
720 '[' => '&#91;',
721 //'=' => '&#61;',
722 '<' => '&lt;',
723 '>' => '&gt;',
724 '"' => '&quot;',
725 //'&' => '&amp;',
726 '\'' => '&#39;'
727 ];
728
729 $str = str_replace(array_keys($replace), array_values($replace), $str);
730
731 return $str;
732 }
733
734 // As per the JS specification
735 function pagelayer_unescapeHTML($str){
736 $replace = [
737 '#93' => ']',
738 '#91' => '[',
739 //'#61' => '=',
740 'lt' => '<',
741 'gt' => '>',
742 'quot' => '"',
743 //'amp' => '&',
744 '#39' => '\''
745 ];
746
747 foreach($replace as $k => $v){
748 $str = str_replace('&'.$k.';', $v, $str);
749 }
750 return $str;
751 }
752
753 // Show promo notice on dashboard
754 function pagelayer_show_promo(){
755
756 global $pagelayer_promo_opts;
757 $opts = $pagelayer_promo_opts;
758
759 echo '
760 <div class="notice notice-success" id="pagelayer_promo" style="min-height:90px">
761 <a class="pagelayer_promo-close" href="javascript:" aria-label="Dismiss this Notice">
762 <span class="dashicons dashicons-dismiss"></span> Dismiss
763 </a>';
764
765 if(!empty($opts['image'])){
766 echo '<a href="'.$opts['website'].'"><img src="'.$opts['image'].'" style="float:left; margin:10px 20px 10px 10px" width="67" /></a>';
767 }
768
769 echo '
770 <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>
771 <p>
772 '.(empty($opts['rating']) ? '' : '<a class="pagelayer_promo_button pagelayer_promo_button2" target="_blank" href="'.$opts['rating'].'">Rate it 5�
773 \'s</a>').'
774 '.(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>').'
775 '.(empty($opts['twitter']) ? '' : '<a class="pagelayer_promo_button pagelayer_promo_button4" target="_blank" href="'.$opts['twitter'].'"><span class="dashicons dashicons-twitter"></span> Tweet</a>').'
776 '.(empty($opts['website']) ? '' : '<a class="pagelayer_promo_button pagelayer_promo_button4" target="_blank" href="'.$opts['website'].'">Visit our website</a>').'
777 </p>
778 </div>';
779
780 }
781
782 // Are we to show a promo ?
783 function pagelayer_maybe_promo($opts){
784
785 global $pagelayer_promo_opts;
786
787 // There must be an interval
788 if(empty($opts['interval'])){
789 return false;
790 }
791
792 // Are we to show a promo
793 $opt_name = 'pagelayer_promo_time';
794 $promo_time = get_option($opt_name);
795
796 // First time access
797 if(empty($promo_time)){
798 update_option($opt_name, time() + (!empty($opts['after']) ? $opts['after'] * 86400 : 0));
799 $promo_time = get_option($opt_name);
800 }
801
802 // Is there interval elapsed
803 if(time() > $promo_time){
804 $pagelayer_promo_opts = $opts;
805 add_action('admin_notices', 'pagelayer_show_promo');
806 }
807
808 // Are we to disable the promo
809 if(isset($_GET['pagelayer_promo']) && (int)$_GET['pagelayer_promo'] == 0){
810 update_option($opt_name, time() + ($opts['interval'] * 86400));
811 die('DONE');
812 }
813
814 }
815