PluginProbe
CookieAdmin – Cookie Consent Banner / 1.2.0
CookieAdmin – Cookie Consent Banner v1.2.0
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.0, at includes/admin.php

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