PluginProbe
Age Gate Lite / trunk
Age Gate Lite vtrunk
trunk 0.0.1
age-gate-lite / age-gate-lite.php

age-gate-lite.php in Age Gate Lite trunk, at age-gate-lite.php

184 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Age Gate Lite
4 description: A lightweight, customisable age gate to lock content from younger audience.
5 Version: 0.0.7
6 Author: siddhu09rocks
7 Author URI: https://www.phenomcraftstudios.com/
8 License: GPL2
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly
13 }
14
15 if ( ! class_exists( 'AGE_GATE_LITE' ) ) {
16
17 load_plugin_textdomain( 'age-gate-lite', false, dirname( plugin_basename( __FILE__ ) ) . '/' );
18
19 class AGE_GATE_LITE {
20 public function __construct() {
21
22 add_action( 'wp_head', array( &$this, 'agl_functions' ), 20 );
23
24 // indicates we are running the admin
25 if ( is_admin() ) {
26 include( 'age-gate-lite-settings.php' );
27 }
28
29 }
30
31 public function agl_functions() {
32
33
34 $agl_logo_img = ( get_option('agl_logo_img') ? '<img src="'.get_option('agl_logo_img').'">' : '') ;
35 $cookie_days = ( get_option('agl_cookie_days') ? get_option('agl_cookie_days') : 'null') ;
36 $agl_primary_color = ( get_option('agl_primary_color') ? get_option('agl_primary_color') : '#ff6c2d') ;
37 $agl_title_color = ( get_option('agl_title_color') ? get_option('agl_title_color') : '#000000') ;
38 $agl_age_limit = ( get_option('agl_age_limit') ? get_option('agl_age_limit') : '18') ;
39 $agl_main_title = ( get_option('agl_main_title') ? get_option('agl_main_title') : 'Are you old enough to be here?') ;
40 $agl_description = ( get_option('agl_description') ? get_option('agl_description') : 'You must be at least '.$agl_age_limit.' to enter this site') ;
41 $agl_success_message = ( get_option('agl_custom_success_message') ? get_option('agl_custom_success_message') : '') ;
42 $agl_yes_btn_text = ( get_option('agl_yes_btn_text') ? get_option('agl_yes_btn_text') : 'Yes') ;
43 $agl_no_btn_text = ( get_option('agl_no_btn_text') ? get_option('agl_no_btn_text') : 'No') ;
44 $agl_safe_link = ( get_option('agl_safe_link') ? get_option('agl_safe_link') : 'https://google.com') ;
45
46 ?>
47 <style>
48 .agl_wrapper {position: fixed;width: 100%;height: 100%;top: 0;left: 0;z-index: 1111111111;align-items: center;background: rgba(0, 0, 0, 0.75);}
49 .agl_main {display: block;margin: 0 auto;text-align: center;background: #fff;max-width: 500px;width: 95%;padding: 30px;}
50 div#agl_form img {max-width: 300px;}
51 div#agl_form h2 {color: <?php echo $agl_title_color; ?>;}
52 .agl_buttons {display: inline-block;vertical-align: middle;padding: 10px 20px;color: <?php echo $agl_primary_color; ?>;}
53 .agl_success_message{display:none;}
54 .agl_buttons_wrp {margin: 20px auto;}
55 #agl_yes_button.agl_buttons {background: <?php echo $agl_primary_color; ?>;color: #fff !important;}
56 #agl_close_link {color: <?php echo $agl_primary_color; ?>;cursor: pointer;}
57 </style>
58 <div id="agl_wrapper" class="agl_wrapper" style="display:none;">
59 <div class="agl_main">
60 <div id="agl_form" class="agl_form">
61 <?php echo $agl_logo_img; ?>
62 <h2><?php echo $agl_main_title; ?></h2>
63 <?php echo $agl_description; ?>
64 <div class="agl_buttons_wrp">
65 <a href="javascript:void(0)" id="agl_yes_button" class="agl_buttons agl_yes_button"><?php echo $agl_yes_btn_text; ?></a>
66 <a href="<?php echo $agl_safe_link; ?>" id="agl_no_button" class="agl_buttons agl_no_button"><?php echo $agl_no_btn_text; ?></a>
67 </div>
68 </div>
69 <?php if($agl_success_message != ''){ ?>
70 <div id="agl_success_message" class="agl_success_message">
71 <?php echo do_shortcode($agl_success_message); ?>
72 <div><a id="agl_close_link" href="javascript:void(0)">continue to site</a></div>
73 </div>
74 <?php } ?>
75 </div>
76 </div>
77 <script>
78 (function() {
79
80
81
82 function close_agl(){
83 document.getElementById("agl_wrapper").style.display = "none";
84 }
85
86 function show_agl(){
87 document.getElementById("agl_wrapper").style.display = "flex";
88 }
89
90 function slide_agl_success_message(){
91 document.getElementById("agl_form").style.display = "none";
92 document.getElementById("agl_success_message").style.display = "block";
93 }
94
95 function setCookie_agl(cname,cvalue,exdays) {
96 <?php
97 if ( !get_option('agl_test_mode') ) {
98 ?>
99 var d = new Date();
100 var expires = "";
101
102 if(exdays != null ){
103 d.setTime(d.getTime() + (exdays*24*60*60*1000));
104 expires = "expires=" + d.toGMTString() + ";";
105 }
106
107 document.cookie = cname + "=" + cvalue + ";" + expires + "path=/";
108
109
110 if (window.CustomEvent && typeof window.CustomEvent === 'function') {
111 var agl_event = new CustomEvent('agl_passed');
112 } else {
113 var agl_event = document.createEvent('CustomEvent');
114 agl_event.initCustomEvent('agl_passed');
115 }
116 document.dispatchEvent(agl_event);
117
118
119 <?php
120 }
121 ?>
122 }
123 function getCookie_agl(cname) {
124 var name = cname + "=";
125 var decodedCookie = decodeURIComponent(document.cookie);
126 var ca = decodedCookie.split(';');
127 for(var i = 0; i < ca.length; i++) {
128 var c = ca[i];
129 while (c.charAt(0) == ' ') {
130 c = c.substring(1);
131 }
132 if (c.indexOf(name) == 0) {
133 return c.substring(name.length, c.length);
134 }
135 }
136 return "";
137 }
138 function checkCookie_agl() {
139 var agl_cookie=getCookie_agl("agl_cookie");
140 if (agl_cookie != "") {
141 // Cookie Exists
142 close_agl();
143 } else {
144 // No Cookie
145 show_agl()
146 }
147 }
148 checkCookie_agl();
149
150 <?php if($agl_success_message != ''){ ?>
151 document.getElementById("agl_close_link").onclick = function(){
152 close_agl()
153 }
154 <?php } ?>
155
156 document.getElementById("agl_yes_button").onclick = function(){
157 setCookie_agl("agl_cookie", '<?php echo $agl_primary_color; ?>', <?php echo $cookie_days; ?>);
158 <?php if($agl_success_message != ''){ ?>
159 slide_agl_success_message()
160 <?php } else { ?>
161 close_agl()
162 <?php } ?>
163 }
164
165 document.getElementById("agl_no_button").onclick = function(){
166 if (window.CustomEvent && typeof window.CustomEvent === 'function') {
167 var agl_event = new CustomEvent('agl_failed');
168 } else {
169 var agl_event = document.createEvent('CustomEvent');
170 agl_event.initCustomEvent('agl_failed');
171 }
172 document.dispatchEvent(agl_event);
173 }
174
175
176 })();
177 </script>
178 <?php
179 }
180 }
181
182 // finally instantiate our plugin class and add it to the set of globals
183 $GLOBALS['age-gate-lite'] = new AGE_GATE_LITE();
184 }