PluginProbe
CookieAdmin – Cookie Consent Banner / 1.2.1
CookieAdmin – Cookie Consent Banner v1.2.1
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 1.1.8
cookieadmin / includes / admin.php

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

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