PluginProbe
CookieAdmin – Cookie Consent Banner / 1.2.6
CookieAdmin – Cookie Consent Banner v1.2.6
1.2.6 1.2.5 1.2.4 1.2.3 1.2.2 1.2.1 1.2.0 1.1.9 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 All 26 releases
cookieadmin / includes / admin.php

admin.php in CookieAdmin – Cookie Consent Banner 1.2.6, at includes/admin.php

448 lines 17.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace CookieAdmin;
4
5 if(!defined('COOKIEADMIN_VERSION') || !defined('ABSPATH')){
6 die('Hacking Attempt');
7 }
8
9 class Admin{
10
11 static function enqueue_scripts(){
12
13 if(!is_admin()){
14 return true;
15 }
16
17 $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
18 $admin_page = basename(parse_url($request_uri, PHP_URL_PATH));
19
20 if($admin_page != 'admin.php'){
21 return true;
22 }
23
24 $current_page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
25
26 // List all page slugs where styles should be loaded
27 $plugin_pages = [
28 'cookieadmin',
29 'cookieadmin-settings',
30 'cookieadmin-scan-cookies',
31 'cookieadmin-consent',
32 'cookieadmin-consent-logs',
33 'cookieadmin-license',
34 'cookieadmin-do-not-sell',
35 'cookieadmin-dpdp'
36 ];
37
38 if(empty($current_page) || !in_array($current_page, $plugin_pages)){
39 return true;
40 }
41
42 //Consent Page CSS
43 wp_enqueue_style('cookieadmin-style', COOKIEADMIN_PLUGIN_URL . 'assets/css/cookie.css', [], COOKIEADMIN_VERSION);
44 wp_enqueue_style('cookieadmin-user-style', COOKIEADMIN_PLUGIN_URL . 'assets/css/consent.css', [], COOKIEADMIN_VERSION);
45
46 //WP Color picker
47 wp_enqueue_style('wp-color-picker');
48
49 $view = get_option('cookieadmin_law', 'cookieadmin_gdpr');
50 $policy = cookieadmin_load_policy();
51
52 if(!empty($policy) && !empty($view)){
53
54 wp_enqueue_script('cookieadmin_js', COOKIEADMIN_PLUGIN_URL . 'assets/js/cookie.js', [], COOKIEADMIN_VERSION);
55 // wp_enqueue_script('cookieadmin_js', COOKIEADMIN_PLUGIN_URL . 'assets/js/consent.js', [], COOKIEADMIN_VERSION);
56
57 $policy['set'] = $view;
58 $policy['admin_url'] = admin_url('admin-ajax.php');
59 $policy['cookieadmin_nonce'] = wp_create_nonce('cookieadmin_admin_js_nonce');
60 //cookieadmin_r_print($policy);die();
61
62 $policy['lang']['show_more'] = __('Show more', 'cookieadmin');
63 $policy['lang']['show_less'] = __('Show less', 'cookieadmin');
64 $policy['lang']['days'] = __('Day(s)', 'cookieadmin');
65 $policy['lang']['session'] = __('Session', 'cookieadmin');
66 $policy['lang']['scan_completed'] = __('Scan completed', 'cookieadmin');
67 $policy['lang']['processing'] = __('Processing...', 'cookieadmin');
68 $policy['lang']['active'] = __('Active', 'cookieadmin');
69 $policy['lang']['install_failed'] = __('Installation failed. Please try again.', 'cookieadmin');
70 $policy['lang']['error_occurred'] = __('An error occurred. Please try again.', 'cookieadmin');
71
72 wp_localize_script('cookieadmin_js', 'cookieadmin_policy', $policy);
73 }
74
75 wp_enqueue_script('cookieadmin_js_footer', COOKIEADMIN_PLUGIN_URL . 'assets/js/footer.js', [], COOKIEADMIN_VERSION);
76 wp_localize_script('cookieadmin_js_footer', 'cookieadmin_data', array('is_pro' => cookieadmin_is_pro()));
77
78 // We only need to upload icon on consent form page
79 if(!empty($_GET['page']) && $_GET['page'] == 'cookieadmin-consent'){
80 //to upload icons
81 wp_enqueue_media();
82 }
83 }
84
85 //Add Main Menu
86 static function cookieadmin_plugin_menu(){
87
88 if(!empty($_REQUEST['cookieadmin_save_settings'])){
89
90 if(!empty($_REQUEST['cookieadmin_consent_type'])){
91 \CookieAdmin\Admin\Consent::save_consent_form();
92 }else{
93 \CookieAdmin\Admin\Settings::save_settings();
94 }
95 }
96
97 $capability = 'activate_plugins';
98 $logo = defined('SITEPAD') ? 'cookieadmin_icon_20-black.svg' : 'cookieadmin_icon_20.svg';
99
100 add_menu_page(__('CookieAdmin', 'cookieadmin'), __('CookieAdmin', 'cookieadmin'), $capability, 'cookieadmin', '\CookieAdmin\Admin\Dashboard::dashboard', COOKIEADMIN_PLUGIN_URL .'assets/images/'.$logo);
101
102 add_submenu_page('cookieadmin', __('Dashboard', 'cookieadmin'), __('Dashboard', 'cookieadmin'), $capability, 'cookieadmin', '\CookieAdmin\Admin\Dashboard::dashboard');
103
104 add_submenu_page('cookieadmin', __('Consent Form', 'cookieadmin'), __('Consent Form', 'cookieadmin'), $capability, 'cookieadmin-consent', '\CookieAdmin\Admin\Consent::consent_form');
105
106 add_submenu_page('cookieadmin', __('Settings', 'cookieadmin'), __('Settings', 'cookieadmin'), $capability, 'cookieadmin-settings', '\CookieAdmin\Admin\Settings::settings');
107
108 add_submenu_page('cookieadmin', __('Scan Cookies', 'cookieadmin'), __('Scan Cookies', 'cookieadmin'), $capability, 'cookieadmin-scan-cookies', '\CookieAdmin\Admin\Scan::show_cookies');
109
110 if(defined('COOKIEADMIN_PREMIUM')){
111 add_submenu_page('cookieadmin', __('Consent Logs', 'cookieadmin'), __('Consent Logs', 'cookieadmin'), $capability, 'cookieadmin-consent-logs', '\CookieAdminPro\Admin::show_consent_logs');
112
113 // GEO Targeting
114 add_submenu_page('cookieadmin', __('Geo Targeting', 'cookieadmin'), __('Geo Targeting', 'cookieadmin'), $capability, 'cookieadmin-geo-targeting', '\CookieAdminPro\Admin\Geo::geo_admin_page');
115
116 // Do Not Sell menu
117 add_submenu_page('cookieadmin', __('Do Not Sell Requests', 'cookieadmin'), __('Do Not Sell', 'cookieadmin'), $capability, 'cookieadmin-do-not-sell', '\CookieAdminPro\Admin\DoNotSell::do_not_sell_requests');
118
119 // DPDP (India) Data Principal Requests menu
120 add_submenu_page('cookieadmin', __('DPDP Requests', 'cookieadmin'), __('DPDP Requests', 'cookieadmin'), $capability, 'cookieadmin-dpdp', '\CookieAdminPro\Admin\DPDP::dpdp_requests');
121
122 if(!defined('SITEPAD')){
123 add_submenu_page('cookieadmin', __('License', 'cookieadmin'), __('License', 'cookieadmin'), $capability, 'cookieadmin-license', '\CookieAdminPro\License::cookieadmin_show_license');
124 }
125 }else if(!defined('SITEPAD')){
126 // Go Pro link
127 add_submenu_page('cookieadmin', __('CookieAdmin Go Pro', 'cookieadmin'), __('Go Pro', 'cookieadmin'), $capability, COOKIEADMIN_PRO_URL);
128 }
129 }
130
131 // cookieadmin header
132 static function header_theme($title = 'Dashboard'){
133
134 global $cookieadmin_lang, $cookieadmin_error, $cookieadmin_msg;
135
136 self::conflict_notice();
137
138 echo '
139 <div class="cookieadmin-metabox-holder">
140 <div class="cookieadmin-header">
141 <div class="cookieadmin-header-left">
142 <div class="cookieadmin-icon">
143 <img class="cookieadmin-logo" src="'.esc_attr(COOKIEADMIN_PLUGIN_URL).'assets/images/cookieadmin-logo.png" alt="CookieAdmin Logo">
144 </div>
145 <span class="cookieadmin-header-version">v'.esc_html(COOKIEADMIN_VERSION).'</span>
146 </div>
147 <div class="cookieadmin-header-right">
148 <a href="https://cookieadmin.net/docs" class="cookieadmin-header-link" target="_blank"><span class="dashicons dashicons-book-alt"></span> ' . esc_html__('Documentation', 'cookieadmin') . '</a>
149 <span class="cookieadmin-header-separator"></span>
150 <a href="https://softaculous.deskuss.com/open.php?topicId=26" class="cookieadmin-header-link" target="_blank"><span class="dashicons dashicons-sos"></span> ' . esc_html__('Support', 'cookieadmin') . '</a>
151 </div>
152 </div>
153 <h1 class="cookieadmin-page-title">'.esc_html($title).'</h1>';
154
155 if(!empty($cookieadmin_error)){
156 echo '<div class="cookieadmin-notice"><div id="cookieadmin_message" class="error"><p>'.esc_html($cookieadmin_error).'</p></div></div>';
157 }
158
159 if(!empty($cookieadmin_msg)){
160 echo '<div class="cookieadmin-notice"><div id="cookieadmin_message" class="updated"><p>'.esc_html($cookieadmin_msg).'</p></div></div>';
161 }
162
163 echo '<div class="cookieadmin-postbox-container">';
164 }
165
166 // cookieadmin footer
167 static function footer_theme($no_twitter = 0){
168 global $cookieadmin_lang, $cookieadmin_error, $cookieadmin_msg;
169
170 echo '</div>';
171
172 if(!defined('SITEPAD')){
173 echo '<div class="cookieadmin-footer">
174 <a href="'.esc_url(COOKIEADMIN_WWW_URL).'" target="_blank">CookieAdmin</a> v'.esc_html(COOKIEADMIN_VERSION).' &middot; ' . esc_html__('Report bugs', 'cookieadmin') . ' <a href="https://softaculous.deskuss.com/open.php?topicId=26" target="_blank">'.esc_html__('here', 'cookieadmin').'</a>';
175
176 if(defined('COOKIEADMIN_PREMIUM')){
177 echo ' &middot; <a href="mailto:[email protected]">'.esc_html__('Email support', 'cookieadmin').'</a>';
178 }
179
180 echo '</div>';
181 }
182
183 echo '</div>';
184 }
185
186 static function cookieadmin_table_exists($table_name) {
187 global $wpdb;
188
189 $query = $wpdb->prepare("SHOW TABLES LIKE %s", $table_name);
190
191 return $wpdb->get_var($query) === $table_name;
192 }
193
194 static function scan_notice(){
195
196 $cookieadmin_auto_scan = get_option('cookieadmin_scan');
197 $current_page = isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : '';
198
199 if(empty($cookieadmin_auto_scan['status']) || (strpos($current_page, 'cookieadmin') !== 0)){
200 return false;
201 }
202
203 $msg = '';
204
205 if($cookieadmin_auto_scan['status'] === 2){
206
207 $count = !empty($cookieadmin_auto_scan['count']) ? $cookieadmin_auto_scan['count'] : 0;
208 /* translators: %1$s is replaced with a "string" of name of plugins, and %2$s is replaced with "string" which can be "is" or "are" based on the count of the plugin */
209 $msg = sprintf(__('<br><strong>Cookie Scan is running:</strong> %1$d Cookies found. Please wait for cookies to appear on <a href="%2$s">Scan Cookies Page</a>', 'cookieadmin'), $count, esc_url(admin_url('admin.php?page=cookieadmin-scan-cookies')));
210 }
211
212 if($cookieadmin_auto_scan['status'] === 3 && isset($cookieadmin_auto_scan['success'])){
213
214 if($cookieadmin_auto_scan['success'] === true){
215 /* translators: %1$s is replaced with a "string" of name of plugins, and %2$s is replaced with "string" which can be "is" or "are" based on the count of the plugin */
216 $msg = sprintf(__('<br><strong>Cookie Scan completed successfully:</strong> Please visit <a href="%1$s">Scan Cookies</a> to review scan results.', 'cookieadmin'), esc_url(admin_url('admin.php?page=cookieadmin-scan-cookies')));
217 }
218
219 if($cookieadmin_auto_scan['success'] === false){
220 /* translators: %1$s is replaced with a "string" of name of plugins, and %2$s is replaced with "string" which can be "is" or "are" based on the count of the plugin */
221 $msg = sprintf(__('<br><strong>Cookie Scan failed:</strong> Please <a href="%1$s">Scan Cookies</a> again for compliance. %2$s', 'cookieadmin'), esc_url(admin_url('admin.php?page=cookieadmin-scan-cookies')), esc_html(!empty($cookieadmin_auto_scan['message']) ? $cookieadmin_auto_scan['message'] : ''));
222 }
223 }
224
225 if(empty($msg)){
226 return;
227 }
228
229 // cookieadmin_logo_svg fn is Internal static SVG. if allowing user input or filters, escape it.
230 echo '
231 <div class="notice notice-info is-dismissible" id="cookieadmin-auto-scan-notice">
232 <p>'.cookieadmin_logo_svg().wp_kses_post($msg). '</p>
233 </div>';
234
235 wp_register_script('cookieadmin-scan-notice', '', ['jquery'], '', true);
236 wp_enqueue_script('cookieadmin-scan-notice');
237 wp_add_inline_script('cookieadmin-scan-notice', 'jQuery("#cookieadmin-auto-scan-notice").on("click",
238 function(e){
239
240 let target = jQuery(e.target);
241 if(!target.hasClass("notice-dismiss")){
242 return;
243 }
244
245 var data;
246
247 // Hide it
248 jQuery("#cookieadmin-auto-scan-notice").remove();
249
250 // Save this preference
251 jQuery.post("'.admin_url('admin-ajax.php?action=cookieadmin_ajax_handler&cookieadmin_act=close-notice&notice=cookieadmin-scan-notice').'&cookieadmin_security='.wp_create_nonce('cookieadmin_admin_js_nonce').'", data, function(response) {
252 });
253
254 });');
255
256 }
257 static function consent_log_purge_notice(){
258
259 $cookieadmin_consent_purge = get_option('cookieadmin_consent_purge', ['status' => 0, 'count' => 0]);
260
261 if(empty($cookieadmin_consent_purge['status'])){
262 return false;
263 }
264
265 $msg = '';
266 $count = empty($cookieadmin_consent_purge['count']) ? 0 : $cookieadmin_consent_purge['count'];
267
268 if($cookieadmin_consent_purge['status'] === 2){
269 /* translators: %1$d: number of consent logs deleted */
270 $msg = sprintf(__('<br><strong>Consent logs are being deleted :</strong> %1$d logs deleted. Please wait for deletion process to complete.', 'cookieadmin'), $count);
271 }
272
273 if($cookieadmin_consent_purge['status'] === 3){
274 if(isset($cookieadmin_consent_purge['success'])){
275 if($cookieadmin_consent_purge['success'] === true){
276 /* translators: %1$d: number of consent logs deleted */
277 $msg = sprintf(__('<br><strong>Consent logs deleted successfully:</strong> %1$d logs deleted.', 'cookieadmin'), $count);
278 }
279
280 if($cookieadmin_consent_purge['success'] === false){
281 /* translators: %1$d: number of consent logs deleted, %2$s: error message*/
282 $msg = sprintf(__('<br><strong>Consent logs deletion failed:</strong> %1$d logs deleted. Error : %2$s', 'cookieadmin'), $count, esc_html($cookieadmin_consent_purge['message']));
283 }
284 }
285 }
286
287 if(empty($msg)){
288 return;
289 }
290
291 // cookieadmin_logo_svg fn is Internal static SVG. if allowing user input or filters, escape it.
292 echo '
293 <div class="notice notice-info is-dismissible" id="cookieadmin-consent-purge-notice">
294 <p>'.cookieadmin_logo_svg().wp_kses_post($msg). '</p>
295 </div>';
296
297 wp_register_script('cookieadmin-consent-purge-notice', '', ['jquery'], '', true);
298 wp_enqueue_script('cookieadmin-consent-purge-notice');
299 wp_add_inline_script('cookieadmin-consent-purge-notice', 'jQuery("#cookieadmin-consent-purge-notice").on("click",
300 function(e){
301
302 let target = jQuery(e.target);
303 if(!target.hasClass("notice-dismiss")){
304 return;
305 }
306
307 var data;
308
309 // Hide it
310 jQuery("#cookieadmin-consent-purge-notice").remove();
311
312 // Save this preference
313 jQuery.post("'.admin_url('admin-ajax.php?action=cookieadmin_ajax_handler&cookieadmin_act=close-notice&notice=cookieadmin-consent-purge-notice').'&cookieadmin_security='.wp_create_nonce('cookieadmin_admin_js_nonce').'", data, function(response) {
314 });
315
316 });');
317
318 }
319
320 static function conflict_notice(){
321
322 $conflicting = [
323 'complianz-gdpr/complianz-gdpr.php' => 'Complianz',
324 'cookie-law-info/cookie-law-info.php' => 'CookieYes',
325 'cookiebot/cookiebot.php' => 'Cookiebot',
326 'cookie-notice/cookie-notice.php' => 'Cookie Notice',
327 'gdpr-cookie-compliance/gdpr-cookie-compliance.php' => 'GDPR Cookie Compliance',
328 'borlabs-cookie/borlabs-cookie.php' => 'Borlabs Cookie',
329 'wp-gdpr-compliance/wp-gdpr-compliance.php' => 'Cookie Information',
330 ];
331
332 if(!function_exists('is_plugin_active')){
333 require_once ABSPATH . 'wp-admin/includes/plugin.php';
334 }
335
336 $active = [];
337 foreach($conflicting as $slug => $name){
338 if(is_plugin_active($slug)){
339 $active[] = $name;
340 }
341 }
342
343 if(empty($active)){
344 return;
345 }
346
347 $names = implode(', ', $active);
348
349 echo '<div class="cookieadmin-conflict-notice">
350 <span class="dashicons dashicons-warning"></span>
351 <span>'.sprintf(__('Conflicting plugin(s) detected: <b>%s</b>. Please deactivate them to avoid issues with CookieAdmin.', 'cookieadmin'), esc_html($names)).'</span>
352 </div>';
353 }
354
355 static function close_notices(){
356
357 if(empty($_REQUEST['notice'])){
358 return;
359 }
360
361 $notice = sanitize_text_field(wp_unslash($_REQUEST['notice']));
362 $notice = str_replace('-notice', '', $notice);
363 $notice = str_replace('-', '_', $notice);
364
365 update_option($notice, array());
366 }
367
368 static function plugin_update_notice(){
369 if(defined('SOFTACULOUS_PLUGIN_UPDATE_NOTICE')){
370 return;
371 }
372
373 $to_update_plugins = apply_filters('softaculous_plugin_update_notice', []);
374
375 if(empty($to_update_plugins)){
376 return;
377 }
378
379 /* translators: %1$s is replaced with a "string" of name of plugins, and %2$s is replaced with "string" which can be "is" or "are" based on the count of the plugin */
380 $msg = sprintf(__('New versions of %1$s %2$s available. Updating ensures better performance, security, and access to the latest features.', 'cookieadmin'), '<b>'.esc_html(implode(', ', $to_update_plugins)).'</b>', (count($to_update_plugins) > 1 ? 'are' : 'is')) . ' <a class="button button-primary" href='.esc_url(admin_url('plugins.php?plugin_status=upgrade')).'>Update Now</a>';
381
382 define('SOFTACULOUS_PLUGIN_UPDATE_NOTICE', true); // To make sure other plugins don't return a Notice
383 echo '<div class="notice notice-info is-dismissible" id="cookieadmin-plugin-update-notice">
384 <p>'.wp_kses_post($msg). '</p>
385 </div>';
386
387 wp_register_script('cookieadmin-update-notice', '', ['jquery'], '', true);
388 wp_enqueue_script('cookieadmin-update-notice');
389 wp_add_inline_script('cookieadmin-update-notice', 'jQuery("#cookieadmin-plugin-update-notice").on("click", function(e){
390 let target = jQuery(e.target);
391
392 if(!target.hasClass("notice-dismiss")){
393 return;
394 }
395
396 var data;
397
398 // Hide it
399 jQuery("#cookieadmin-plugin-update-notice").hide();
400
401 // Save this preference
402 jQuery.post("'.admin_url('admin-ajax.php?action=cookieadmin_ajax_handler&cookieadmin_act=close-update-notice').'&cookieadmin_security='.wp_create_nonce('cookieadmin_admin_js_nonce').'", data, function(response) {
403 //alert(response);
404 });
405 });');
406 }
407
408 static function plugin_update_notice_filter($plugins = []){
409 $plugins['cookieadmin/cookieadmin.php'] = 'CookieAdmin';
410 return $plugins;
411 }
412
413 static function close_plugin_update_notice(){
414 $plugin_update_notice = get_option('softaculous_plugin_update_notice', []);
415 $available_update_list = get_site_transient('update_plugins');
416 $to_update_plugins = apply_filters('softaculous_plugin_update_notice', []);
417
418 if(empty($available_update_list) || empty($available_update_list->response)){
419 return;
420 }
421
422 foreach($to_update_plugins as $plugin_path => $plugin_name){
423 if(isset($available_update_list->response[$plugin_path])){
424 $plugin_update_notice[$plugin_path] = $available_update_list->response[$plugin_path]->new_version;
425 }
426 }
427
428 update_option('softaculous_plugin_update_notice', $plugin_update_notice);
429 }
430
431 static function is_feature_available($return = 0){
432
433 if(cookieadmin_is_pro()){
434 return '';
435 }
436
437 $msg = ' <a href="'.esc_url(COOKIEADMIN_PRO_URL).'" target="_blank" class="cookieadmin-pro-badge">'.esc_html__('Pro', 'cookieadmin').'</a>';
438
439 if(!empty($return)){
440 return $msg;
441 }else{
442 echo wp_kses_post($msg);
443 }
444
445 }
446 }
447
448