PluginProbe ʕ •ᴥ•ʔ
CookieYes – Cookie Banner for Cookie Consent (Easy to setup GDPR/CCPA Compliant Cookie Notice) / 1.8.1
CookieYes – Cookie Banner for Cookie Consent (Easy to setup GDPR/CCPA Compliant Cookie Notice) v1.8.1
3.5.1 3.5.0 3.4.2 trunk 1.0.1 1.0.3 1.2 1.2.1 1.2.2 1.3 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.2.0 3.2.1 3.2.10 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.3.9.1 3.4.0 3.4.1
cookie-law-info / public / class-cookie-law-info-public.php
cookie-law-info / public Last commit date
css 6 years ago images 6 years ago js 6 years ago modules 6 years ago views 6 years ago class-cookie-law-info-public.php 6 years ago index.php 6 years ago
class-cookie-law-info-public.php
511 lines
1 <?php
2
3 /**
4 * The public-facing functionality of the plugin.
5 *
6 * @link http://cookielawinfo.com/
7 * @since 1.6.6
8 *
9 * @package Cookie_Law_Info
10 * @subpackage Cookie_Law_Info/public
11 */
12
13 /**
14 * The public-facing functionality of the plugin.
15 *
16 * Defines the plugin name, version, and two examples hooks for how to
17 * enqueue the public-facing stylesheet and JavaScript.
18 *
19 * @package Cookie_Law_Info
20 * @subpackage Cookie_Law_Info/public
21 * @author WebToffee <info@webtoffee.com>
22 */
23 class Cookie_Law_Info_Public {
24
25 /**
26 * The ID of this plugin.
27 *
28 * @since 1.6.6
29 * @access private
30 * @var string $plugin_name The ID of this plugin.
31 */
32 public $plugin_name;
33
34 /**
35 * The version of this plugin.
36 *
37 * @since 1.6.6
38 * @access private
39 * @var string $version The current version of this plugin.
40 */
41 public $version;
42
43 public $plugin_obj;
44
45 /*
46 * module list, Module folder and main file must be same as that of module name
47 * Please check the `register_modules` method for more details
48 */
49 private $modules=array(
50 'script-blocker',
51 'geo-ip',
52 'shortcode',
53 'visitor-report', //vistor report
54 );
55 public static $existing_modules=array();
56
57 /**
58 * Initialize the class and set its properties.
59 *
60 * @since 1.6.6
61 * @param string $plugin_name The name of the plugin.
62 * @param string $version The version of this plugin.
63 */
64 public function __construct( $plugin_name, $version, $plugin_obj) {
65
66 $this->plugin_name = $plugin_name;
67 $this->version = $version;
68 $this->plugin_obj = $plugin_obj;
69 register_activation_hook(CLI_PLUGIN_FILENAME,array($this,'activator'));
70 }
71 public static function get_cookie_categories()
72 {
73 $cookie_categories = array(
74 'necessary'=>__('Necessary','cookie-law-info'),
75 'non-necessary' => __('Non-necessary','cookie-law-info'),
76 );
77 return $cookie_categories;
78 }
79 public static function wt_cli_check_thirdparty_state()
80 {
81
82 $wt_cli_default_state = false;
83
84 $third_party_cookie_options = get_option('cookielawinfo_thirdparty_settings');
85 $wt_cli_default_state_field = isset($third_party_cookie_options['third_party_default_state']) ? $third_party_cookie_options['third_party_default_state'] : true;
86 $wt_cli_default_state = Cookie_Law_Info::sanitise_settings('third_party_default_state',$wt_cli_default_state_field);
87
88 return $wt_cli_default_state;
89 }
90 /**
91 * Set Default Privacy overview and Cookie Sensitivity Contents
92 *
93 * @since 1.7.7
94 */
95 public function cli_set_default_contents()
96 {
97 $privacy_settings = get_option('cookielawinfo_privacy_overview_content_settings');
98 $necessary_settings = get_option('cookielawinfo_necessary_settings');
99 $thirdparty_settings = get_option('cookielawinfo_thirdparty_settings');
100 $privacy_defaults = array(
101 'privacy_overview_content' => 'This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.','privacy_overview_title' => 'Privacy Overview'
102 );
103 $thirdparty_defaults = array(
104 'thirdparty_on_field' => true,
105 'third_party_default_state' => true,
106 'thirdparty_description'=> 'Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.',
107 'thirdparty_head_section' => '',
108 'thirdparty_body_section' => '',
109 );
110 $necessary_defaults = array('necessary_description'=>'Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.'
111 );
112 ($privacy_settings===false) ? update_option('cookielawinfo_privacy_overview_content_settings',$privacy_defaults) : false ;
113 ($necessary_settings===false) ? update_option('cookielawinfo_necessary_settings',$necessary_defaults) : false ;
114 if($thirdparty_settings===false)
115 {
116 update_option('cookielawinfo_thirdparty_settings',$thirdparty_defaults);
117 }
118 else
119 {
120 if(!isset($thirdparty_settings['thirdparty_description']))
121 {
122 $thirdparty_settings['thirdparty_description']=$thirdparty_defaults['thirdparty_description'];
123 update_option('cookielawinfo_thirdparty_settings',$thirdparty_settings);
124 }
125 }
126 }
127 public function activator()
128 {
129 $this->cli_set_default_contents();
130 }
131 /**
132 * Set Category Cookies If Empty
133 *
134 * @since 1.7.7
135 */
136 public function cli_set_category_cookies()
137 {
138 $temp = array();
139
140 $cookie_categories = self::get_cookie_categories();
141 $the_options = Cookie_Law_Info::get_settings();
142 $thirdparty_on_field = false;
143 $third_party_cookie_options = get_option('cookielawinfo_thirdparty_settings');
144 $thirdparty_on_field = isset($third_party_cookie_options['thirdparty_on_field']) ? $third_party_cookie_options['thirdparty_on_field'] : false;
145 $wt_cli_is_thirdparty_enabled = Cookie_Law_Info::sanitise_settings('thirdparty_on_field',$thirdparty_on_field);
146 $wt_non_necessary_cookie_value = 'yes';
147 if(! self::wt_cli_check_thirdparty_state())
148 {
149 $wt_non_necessary_cookie_value = 'no';
150 }
151 if ( $the_options['is_on'] == true )
152 {
153
154 foreach ($cookie_categories as $key => $value)
155 {
156 if(empty($_COOKIE["cookielawinfo-checkbox-$key"]))
157 {
158 if($key === 'non-necessary' ) {
159
160 if($wt_cli_is_thirdparty_enabled == false) {
161
162 return false;
163
164 }
165 else
166 {
167
168 @setcookie("cookielawinfo-checkbox-$key",$wt_non_necessary_cookie_value,time()+3600,'/');
169 }
170 }
171 else {
172
173 @setcookie("cookielawinfo-checkbox-$key",'yes',time()+3600,'/');
174
175 }
176
177 }
178 }
179 }
180 }
181
182 /**
183 * Register the stylesheets for the public-facing side of the site.
184 *
185 * @since 1.6.6
186 */
187 public function enqueue_styles() {
188
189 /**
190 * This function is provided for demonstration purposes only.
191 *
192 * An instance of this class should be passed to the run() function
193 * defined in Cookie_Law_Info_Loader as all of the hooks are defined
194 * in that particular class.
195 *
196 * The Cookie_Law_Info_Loader will then create the relationship
197 * between the defined hooks and the functions defined in this
198 * class.
199 */
200 $the_options = Cookie_Law_Info::get_settings();
201 if ( $the_options['is_on'] == true )
202 {
203 wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/cookie-law-info-public.css', array(), $this->version, 'all' );
204 wp_enqueue_style( $this->plugin_name.'-gdpr', plugin_dir_url( __FILE__ ) . 'css/cookie-law-info-gdpr.css', array(),$this->version, 'all' );
205 //this style will include only when shortcode is called
206 wp_register_style( $this->plugin_name.'-table', plugin_dir_url( __FILE__ ) . 'css/cookie-law-info-table.css', array(),$this->version, 'all' );
207 }
208 }
209
210 /**
211 * Register the JavaScript for the public-facing side of the site.
212 *
213 * @since 1.6.6
214 */
215 public function enqueue_scripts() {
216
217 /**
218 * This function is provided for demonstration purposes only.
219 *
220 * An instance of this class should be passed to the run() function
221 * defined in Cookie_Law_Info_Loader as all of the hooks are defined
222 * in that particular class.
223 *
224 * The Cookie_Law_Info_Loader will then create the relationship
225 * between the defined hooks and the functions defined in this
226 * class.
227 */
228 $the_options = Cookie_Law_Info::get_settings();
229 if ( $the_options['is_on'] == true )
230 {
231 $non_necessary_cookie_ids = Cookie_Law_Info::get_non_necessary_cookie_ids();
232 $cli_cookie_datas = array(
233 'nn_cookie_ids' => !empty($non_necessary_cookie_ids) ? $non_necessary_cookie_ids : array(),
234 'cookielist' => array(),
235 );
236
237 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/cookie-law-info-public.js', array( 'jquery' ),$this->version, false );
238 wp_localize_script( $this->plugin_name, 'Cli_Data', $cli_cookie_datas );
239 wp_localize_script( $this->plugin_name, 'log_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
240 }
241
242 }
243
244 /**
245 Registers modules: public+admin
246 */
247 public function common_modules()
248 {
249 foreach ($this->modules as $module) //loop through module list and include its file
250 {
251 $module_file=plugin_dir_path( __FILE__ )."modules/$module/$module.php";
252 if(file_exists($module_file))
253 {
254 self::$existing_modules[]=$module; //this is for module_exits checking
255 require_once $module_file;
256 }
257 }
258 }
259 public static function module_exists($module)
260 {
261 return in_array($module,self::$existing_modules);
262 }
263
264 public function register_custom_post_type()
265 {
266 $labels = array(
267 'name' => __('GDPR Cookie Consent','cookie-law-info'),
268 'all_items' => __('Cookie List','cookie-law-info'),
269 'singular_name' => __('Cookie','cookie-law-info'),
270 'add_new' => __('Add New','cookie-law-info'),
271 'add_new_item' => __('Add New Cookie Type','cookie-law-info'),
272 'edit_item' => __('Edit Cookie Type','cookie-law-info'),
273 'new_item' => __('New Cookie Type','cookie-law-info'),
274 'view_item' => __('View Cookie Type','cookie-law-info'),
275 'search_items' => __('Search Cookies','cookie-law-info'),
276 'not_found' => __('Nothing found','cookie-law-info'),
277 'not_found_in_trash' => __('Nothing found in Trash','cookie-law-info'),
278 'parent_item_colon' => ''
279 );
280 $args = array(
281 'labels' => $labels,
282 'public' => false,
283 'publicly_queryable' => false,
284 'exclude_from_search' => true,
285 'show_ui' => true,
286 'query_var' => true,
287 'rewrite' => true,
288 'capabilities' => array(
289 'publish_posts' => 'manage_options',
290 'edit_posts' => 'manage_options',
291 'edit_others_posts' => 'manage_options',
292 'delete_posts' => 'manage_options',
293 'delete_others_posts' => 'manage_options',
294 'read_private_posts' => 'manage_options',
295 'edit_post' => 'manage_options',
296 'delete_post' => 'manage_options',
297 'read_post' => 'manage_options',
298 ),
299 /** done editing */
300 'menu_icon' =>plugin_dir_url( __FILE__ ).'images/cli_icon.png',
301 'hierarchical' => false,
302 'menu_position' => null,
303 'supports' => array( 'title','editor' )
304 );
305 register_post_type(CLI_POST_TYPE, $args );
306 }
307
308 /** Removes leading # characters from a string */
309 public static function cookielawinfo_remove_hash( $str )
310 {
311 if( $str{0} == "#" )
312 {
313 $str = substr( $str, 1, strlen($str) );
314 }
315 else {
316 return $str;
317 }
318 return self::cookielawinfo_remove_hash( $str );
319 }
320
321 /**
322 Outputs the cookie control script in the footer
323 N.B. This script MUST be output in the footer.
324
325 This function should be attached to the wp_footer action hook.
326 */
327 public function cookielawinfo_inject_cli_script()
328 {
329 $the_options = Cookie_Law_Info::get_settings();
330 if ( $the_options['is_on'] == true )
331 {
332 // Output the HTML in the footer:
333 $message =nl2br($the_options['notify_message']);
334 $str = do_shortcode( stripslashes ( $message ) );
335 $str = __($str,'cookie-law-info');
336 $head= __($the_options['bar_heading_text'],'cookie-law-info');
337 $head= trim(stripslashes($head));
338
339 $notify_html = '<div id="' .$this->cookielawinfo_remove_hash( $the_options["notify_div_id"] ) . '">'.
340 ($head!="" ? '<h5 class="cli_messagebar_head">'.$head.'</h5>' : '')
341 .'<span>' . $str . '</span></div>';
342
343 //if($the_options['showagain_tab'] === true)
344 //{
345 $show_again=__($the_options["showagain_text"],'cookie-law-info');
346 $notify_html .= '<div id="' . $this->cookielawinfo_remove_hash( $the_options["showagain_div_id"] ) . '" style="display:none;"><span id="cookie_hdr_showagain">'.$show_again.'</span></div>';
347 //}
348 global $wp_query;
349 $current_obj = get_queried_object();
350 $post_slug ='';
351 if(is_object($current_obj))
352 {
353 if(is_category() || is_tag())
354 {
355 $post_slug =isset($current_obj->slug) ? $current_obj->slug : '';
356 }
357 elseif(is_archive())
358 {
359 $post_slug =isset($current_obj->rewrite) && isset($current_obj->rewrite['slug']) ? $current_obj->rewrite['slug'] : '';
360 }
361 else
362 {
363 if(isset($current_obj->post_name))
364 {
365 $post_slug =$current_obj->post_name;
366 }
367 }
368 }
369 $notify_html = apply_filters('cli_show_cookie_bar_only_on_selected_pages',$notify_html,$post_slug);
370 require_once plugin_dir_path( __FILE__ ).'views/cookie-law-info_bar.php';
371 }
372 }
373
374 /* Print scripts or data in the head tag on the front end. */
375 public function include_user_accepted_cookielawinfo()
376 {
377 $the_options = Cookie_Law_Info::get_settings();
378 if($the_options['is_on'] == true && !is_admin())
379 {
380 $third_party_cookie_options=get_option('cookielawinfo_thirdparty_settings');
381 if(!empty($third_party_cookie_options))
382 {
383 $thirdparty_on_field = isset($third_party_cookie_options['thirdparty_on_field']) ? $third_party_cookie_options['thirdparty_on_field'] : false;
384 $wt_cli_is_thirdparty_enabled = Cookie_Law_Info::sanitise_settings('thirdparty_on_field',$thirdparty_on_field);
385 if($wt_cli_is_thirdparty_enabled == true && isset($_COOKIE['viewed_cookie_policy']))
386 {
387 if($_COOKIE['viewed_cookie_policy']=='yes' && $_COOKIE["cookielawinfo-checkbox-non-necessary"] =='yes')
388 {
389 echo (isset($third_party_cookie_options['thirdparty_head_section'])) ? $third_party_cookie_options['thirdparty_head_section'] : '';
390 }
391 }
392 }
393 }
394 }
395
396 /* Print scripts or data in the body tag on the front end. */
397 public function include_user_accepted_cookielawinfo_in_body()
398 {
399 $the_options = Cookie_Law_Info::get_settings();
400 if($the_options['is_on'] == true && !is_admin())
401 {
402 $third_party_cookie_options=get_option('cookielawinfo_thirdparty_settings');
403 if(!empty($third_party_cookie_options))
404 {
405 $thirdparty_on_field = isset($third_party_cookie_options['thirdparty_on_field']) ? $third_party_cookie_options['thirdparty_on_field'] : false;
406 $wt_cli_is_thirdparty_enabled = Cookie_Law_Info::sanitise_settings('thirdparty_on_field',$thirdparty_on_field);
407 if($wt_cli_is_thirdparty_enabled == true && isset($_COOKIE['viewed_cookie_policy']))
408 {
409 if($_COOKIE['viewed_cookie_policy'] == 'yes' && $_COOKIE["cookielawinfo-checkbox-non-necessary"] =='yes')
410 {
411 echo (isset($third_party_cookie_options['thirdparty_body_section'])) ? $third_party_cookie_options['thirdparty_body_section'] : '';
412 }
413 }
414 }
415 }
416 }
417
418 public function other_plugin_compatibility()
419 {
420 if(!is_admin())
421 {
422 add_action('wp_head',array($this,'other_plugin_clear_cache'));
423 //cache clear===========
424 if(isset($_GET['cli_action']))
425 {
426 // Clear Litespeed cache
427 if(class_exists('LiteSpeed_Cache_API') && method_exists( 'LiteSpeed_Cache_API', 'purge_all' ))
428 {
429 LiteSpeed_Cache_API::purge_all();
430 }
431
432 // WP Super Cache
433 if(function_exists('wp_cache_clear_cache'))
434 {
435 wp_cache_clear_cache();
436 }
437
438 // W3 Total Cache
439 if(function_exists('w3tc_flush_all'))
440 {
441 w3tc_flush_all();
442 }
443
444 // Site ground
445 if(class_exists('SG_CachePress_Supercacher') && method_exists('SG_CachePress_Supercacher', 'purge_cache')) {
446 SG_CachePress_Supercacher::purge_cache(true);
447 }
448
449 // Endurance Cache
450 if(class_exists('Endurance_Page_Cache') && method_exists('Endurance_Page_Cache','purge_all'))
451 {
452 $e = new Endurance_Page_Cache;
453 $e->purge_all();
454 }
455
456 // WP Fastest Cache
457 if(isset($GLOBALS['wp_fastest_cache']) && method_exists($GLOBALS['wp_fastest_cache'],'deleteCache'))
458 {
459 $GLOBALS['wp_fastest_cache']->deleteCache(true);
460 }
461 }
462 //cache clear============
463 }
464 }
465 public function other_plugin_clear_cache()
466 {
467
468 $cli_flush_cache=2;
469 // Clear Litespeed cache
470 if(class_exists('LiteSpeed_Cache_API') && method_exists( 'LiteSpeed_Cache_API', 'purge_all' ))
471 {
472 $cli_flush_cache=1;
473 }
474
475 // WP Super Cache
476 if(function_exists('wp_cache_clear_cache'))
477 {
478 $cli_flush_cache=1;
479 }
480
481 // W3 Total Cache
482 if(function_exists('w3tc_flush_all'))
483 {
484 $cli_flush_cache=1;
485 }
486
487 // Site ground
488 if(class_exists('SG_CachePress_Supercacher') && method_exists('SG_CachePress_Supercacher', 'purge_cache')) {
489 $cli_flush_cache=1;
490 }
491
492 // Endurance Cache
493 if(class_exists('Endurance_Page_Cache') && method_exists('Endurance_Page_Cache','purge_all'))
494 {
495 $cli_flush_cache=1;
496 }
497
498 // WP Fastest Cache
499 if(isset($GLOBALS['wp_fastest_cache']) && method_exists($GLOBALS['wp_fastest_cache'],'deleteCache'))
500 {
501 $cli_flush_cache=1;
502 }
503 ?>
504 <script type="text/javascript">
505 var cli_flush_cache=<?php echo $cli_flush_cache; ?>;
506 </script>
507 <?php
508 }
509
510
511 }