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

396 lines 15.4 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
66 wp_localize_script('cookieadmin_js', 'cookieadmin_policy', $policy);
67 }
68
69 wp_enqueue_script('cookieadmin_js_footer', COOKIEADMIN_PLUGIN_URL . 'assets/js/footer.js', [], COOKIEADMIN_VERSION);
70 wp_localize_script('cookieadmin_js_footer', 'cookieadmin_data', array('is_pro' => cookieadmin_is_pro()));
71
72 // We only need to upload icon on consent form page
73 if(!empty($_GET['page']) && $_GET['page'] == 'cookieadmin-consent'){
74 //to upload icons
75 wp_enqueue_media();
76 }
77 }
78
79 //Add Main Menu
80 static function cookieadmin_plugin_menu(){
81
82 if(!empty($_REQUEST['cookieadmin_save_settings'])){
83
84 if(!empty($_REQUEST['cookieadmin_consent_type'])){
85 \CookieAdmin\Admin\Consent::save_consent_form();
86 }else{
87 \CookieAdmin\Admin\Settings::save_settings();
88 }
89 }
90
91 $capability = 'activate_plugins';
92 $logo = defined('SITEPAD') ? 'cookieadmin_icon_20-black.svg' : 'cookieadmin_icon_20.svg';
93
94 add_menu_page(__('CookieAdmin', 'cookieadmin'), __('CookieAdmin', 'cookieadmin'), $capability, 'cookieadmin', '\CookieAdmin\Admin\Dashboard::dashboard', COOKIEADMIN_PLUGIN_URL .'assets/images/'.$logo);
95
96 add_submenu_page('cookieadmin', __('Dashboard', 'cookieadmin'), __('Dashboard', 'cookieadmin'), $capability, 'cookieadmin', '\CookieAdmin\Admin\Dashboard::dashboard');
97
98 add_submenu_page('cookieadmin', __('Consent Form', 'cookieadmin'), __('Consent Form', 'cookieadmin'), $capability, 'cookieadmin-consent', '\CookieAdmin\Admin\Consent::consent_form');
99
100 add_submenu_page('cookieadmin', __('Settings', 'cookieadmin'), __('Settings', 'cookieadmin'), $capability, 'cookieadmin-settings', '\CookieAdmin\Admin\Settings::settings');
101
102 add_submenu_page('cookieadmin', __('Scan Cookies', 'cookieadmin'), __('Scan Cookies', 'cookieadmin'), $capability, 'cookieadmin-scan-cookies', '\CookieAdmin\Admin\Scan::show_cookies');
103
104 if(defined('COOKIEADMIN_PREMIUM')){
105 add_submenu_page('cookieadmin', __('Consent Logs', 'cookieadmin'), __('Consent Logs', 'cookieadmin'), $capability, 'cookieadmin-consent-logs', '\CookieAdminPro\Admin::show_consent_logs');
106
107 if(!defined('SITEPAD')){
108 add_submenu_page('cookieadmin', __('License', 'cookieadmin'), __('License', 'cookieadmin'), $capability, 'cookieadmin-license', '\CookieAdminPro\License::cookieadmin_show_license');
109 }
110 }else if(!defined('SITEPAD')){
111 // Go Pro link
112 add_submenu_page('cookieadmin', __('CookieAdmin Go Pro', 'cookieadmin'), __('Go Pro', 'cookieadmin'), $capability, COOKIEADMIN_PRO_URL);
113 }
114 }
115
116 // cookieadmin header
117 static function header_theme($title = 'Dashboard'){
118
119 global $cookieadmin_lang, $cookieadmin_error, $cookieadmin_msg;
120
121 echo '
122 <div class="cookieadmin-metabox-holder">
123 <div class="cookieadmin-header">
124 <div class="cookieadmin-header-left">
125 <div class="cookieadmin-icon">
126 <img class="cookieadmin-logo" src="'.esc_attr(COOKIEADMIN_PLUGIN_URL).'assets/images/cookieadmin-logo.png" alt="CookieAdmin Logo">
127 </div>
128 <span class="cookieadmin-header-version">v'.esc_html(COOKIEADMIN_VERSION).'</span>
129 </div>
130 <div class="cookieadmin-header-right">
131 <a href="https://cookieadmin.net/docs" class="cookieadmin-header-link" target="_blank"><span class="dashicons dashicons-book-alt"></span> ' . esc_html__('Documentation', 'cookieadmin') . '</a>
132 <span class="cookieadmin-header-separator"></span>
133 <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>
134 </div>
135 </div>
136 <h1 class="cookieadmin-page-title">'.esc_html($title).'</h1>';
137
138 if(!empty($cookieadmin_error)){
139 echo '<div class="cookieadmin-notice"><div id="cookieadmin_message" class="error"><p>'.esc_html($cookieadmin_error).'</p></div></div>';
140 }
141
142 if(!empty($cookieadmin_msg)){
143 echo '<div class="cookieadmin-notice"><div id="cookieadmin_message" class="updated"><p>'.esc_html($cookieadmin_msg).'</p></div></div>';
144 }
145
146 echo '<div class="cookieadmin-postbox-container">';
147 }
148
149 // cookieadmin footer
150 static function footer_theme($no_twitter = 0){
151 global $cookieadmin_lang, $cookieadmin_error, $cookieadmin_msg;
152
153 echo '</div>';
154
155 if(!defined('SITEPAD')){
156 echo '<div class="cookieadmin-footer">
157 <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>';
158
159 if(defined('COOKIEADMIN_PREMIUM')){
160 echo ' &middot; <a href="mailto:support@cookieadmin.net">'.esc_html__('Email support', 'cookieadmin').'</a>';
161 }
162
163 echo '</div>';
164 }
165
166 echo '</div>';
167 }
168
169 static function cookieadmin_table_exists($table_name) {
170 global $wpdb;
171
172 $query = $wpdb->prepare("SHOW TABLES LIKE %s", $table_name);
173
174 return $wpdb->get_var($query) === $table_name;
175 }
176
177 static function scan_notice(){
178
179 $cookieadmin_auto_scan = get_option('cookieadmin_scan');
180 $current_page = isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : '';
181
182 if(empty($cookieadmin_auto_scan['status']) || (strpos($current_page, 'cookieadmin') !== 0)){
183 return false;
184 }
185
186 $msg = '';
187
188 if($cookieadmin_auto_scan['status'] === 2){
189
190 $count = !empty($cookieadmin_auto_scan['count']) ? $cookieadmin_auto_scan['count'] : 0;
191 /* 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 */
192 $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')));
193 }
194
195 if($cookieadmin_auto_scan['status'] === 3 && isset($cookieadmin_auto_scan['success'])){
196
197 if($cookieadmin_auto_scan['success'] === true){
198 /* 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 */
199 $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')));
200 }
201
202 if($cookieadmin_auto_scan['success'] === false){
203 /* 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 */
204 $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'] : ''));
205 }
206 }
207
208 if(empty($msg)){
209 return;
210 }
211
212 // cookieadmin_logo_svg fn is Internal static SVG. if allowing user input or filters, escape it.
213 echo '
214 <div class="notice notice-info is-dismissible" id="cookieadmin-auto-scan-notice">
215 <p>'.cookieadmin_logo_svg().wp_kses_post($msg). '</p>
216 </div>';
217
218 wp_register_script('cookieadmin-scan-notice', '', ['jquery'], '', true);
219 wp_enqueue_script('cookieadmin-scan-notice');
220 wp_add_inline_script('cookieadmin-scan-notice', 'jQuery("#cookieadmin-auto-scan-notice").on("click",
221 function(e){
222
223 let target = jQuery(e.target);
224 if(!target.hasClass("notice-dismiss")){
225 return;
226 }
227
228 var data;
229
230 // Hide it
231 jQuery("#cookieadmin-auto-scan-notice").remove();
232
233 // Save this preference
234 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) {
235 });
236
237 });');
238
239 }
240 static function consent_log_purge_notice(){
241
242 $cookieadmin_consent_purge = get_option('cookieadmin_consent_purge', ['status' => 0, 'count' => 0]);
243
244 if(empty($cookieadmin_consent_purge['status'])){
245 return false;
246 }
247
248 $msg = '';
249 $count = empty($cookieadmin_consent_purge['count']) ? 0 : $cookieadmin_consent_purge['count'];
250
251 if($cookieadmin_consent_purge['status'] === 2){
252 /* translators: %1$d: number of consent logs deleted */
253 $msg = sprintf(__('<br><strong>Consent logs are being deleted :</strong> %1$d logs deleted. Please wait for deletion process to complete.', 'cookieadmin'), $count);
254 }
255
256 if($cookieadmin_consent_purge['status'] === 3){
257 if(isset($cookieadmin_consent_purge['success'])){
258 if($cookieadmin_consent_purge['success'] === true){
259 /* translators: %1$d: number of consent logs deleted */
260 $msg = sprintf(__('<br><strong>Consent logs deleted successfully:</strong> %1$d logs deleted.', 'cookieadmin'), $count);
261 }
262
263 if($cookieadmin_consent_purge['success'] === false){
264 /* translators: %1$d: number of consent logs deleted, %2$s: error message*/
265 $msg = sprintf(__('<br><strong>Consent logs deletion failed:</strong> %1$d logs deleted. Error : %2$s', 'cookieadmin'), $count, esc_html($cookieadmin_consent_purge['message']));
266 }
267 }
268 }
269
270 if(empty($msg)){
271 return;
272 }
273
274 // cookieadmin_logo_svg fn is Internal static SVG. if allowing user input or filters, escape it.
275 echo '
276 <div class="notice notice-info is-dismissible" id="cookieadmin-consent-purge-notice">
277 <p>'.cookieadmin_logo_svg().wp_kses_post($msg). '</p>
278 </div>';
279
280 wp_register_script('cookieadmin-consent-purge-notice', '', ['jquery'], '', true);
281 wp_enqueue_script('cookieadmin-consent-purge-notice');
282 wp_add_inline_script('cookieadmin-consent-purge-notice', 'jQuery("#cookieadmin-consent-purge-notice").on("click",
283 function(e){
284
285 let target = jQuery(e.target);
286 if(!target.hasClass("notice-dismiss")){
287 return;
288 }
289
290 var data;
291
292 // Hide it
293 jQuery("#cookieadmin-consent-purge-notice").remove();
294
295 // Save this preference
296 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) {
297 });
298
299 });');
300
301 }
302
303 static function close_notices(){
304
305 if(empty($_REQUEST['notice'])){
306 return;
307 }
308
309 $notice = sanitize_text_field(wp_unslash($_REQUEST['notice']));
310 $notice = str_replace('-notice', '', $notice);
311 $notice = str_replace('-', '_', $notice);
312
313 update_option($notice, array());
314 }
315
316 static function plugin_update_notice(){
317 if(defined('SOFTACULOUS_PLUGIN_UPDATE_NOTICE')){
318 return;
319 }
320
321 $to_update_plugins = apply_filters('softaculous_plugin_update_notice', []);
322
323 if(empty($to_update_plugins)){
324 return;
325 }
326
327 /* 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 */
328 $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>';
329
330 define('SOFTACULOUS_PLUGIN_UPDATE_NOTICE', true); // To make sure other plugins don't return a Notice
331 echo '<div class="notice notice-info is-dismissible" id="cookieadmin-plugin-update-notice">
332 <p>'.wp_kses_post($msg). '</p>
333 </div>';
334
335 wp_register_script('cookieadmin-update-notice', '', ['jquery'], '', true);
336 wp_enqueue_script('cookieadmin-update-notice');
337 wp_add_inline_script('cookieadmin-update-notice', 'jQuery("#cookieadmin-plugin-update-notice").on("click", function(e){
338 let target = jQuery(e.target);
339
340 if(!target.hasClass("notice-dismiss")){
341 return;
342 }
343
344 var data;
345
346 // Hide it
347 jQuery("#cookieadmin-plugin-update-notice").hide();
348
349 // Save this preference
350 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) {
351 //alert(response);
352 });
353 });');
354 }
355
356 static function plugin_update_notice_filter($plugins = []){
357 $plugins['cookieadmin/cookieadmin.php'] = 'CookieAdmin';
358 return $plugins;
359 }
360
361 static function close_plugin_update_notice(){
362 $plugin_update_notice = get_option('softaculous_plugin_update_notice', []);
363 $available_update_list = get_site_transient('update_plugins');
364 $to_update_plugins = apply_filters('softaculous_plugin_update_notice', []);
365
366 if(empty($available_update_list) || empty($available_update_list->response)){
367 return;
368 }
369
370 foreach($to_update_plugins as $plugin_path => $plugin_name){
371 if(isset($available_update_list->response[$plugin_path])){
372 $plugin_update_notice[$plugin_path] = $available_update_list->response[$plugin_path]->new_version;
373 }
374 }
375
376 update_option('softaculous_plugin_update_notice', $plugin_update_notice);
377 }
378
379 static function is_feature_available($return = 0){
380
381 if(cookieadmin_is_pro()){
382 return '';
383 }
384
385 $msg = ' <a href="'.esc_url(COOKIEADMIN_PRO_URL).'" target="_blank" class="cookieadmin-pro-badge">'.esc_html__('Pro', 'cookieadmin').'</a>';
386
387 if(!empty($return)){
388 return $msg;
389 }else{
390 echo wp_kses_post($msg);
391 }
392
393 }
394 }
395
396