· 4 years ago · May 11, 2021, 10:22 AM
1<?php
2/**
3 * Cookie_Law_Info_Cookie_Scaner class file.
4 */
5
6if ( ! defined( 'ABSPATH' ) ) {
7 exit;
8}
9/**
10 * Main class for handling the cookie scanner functions
11 *
12 * @version 1.9.6
13 */
14class Cookie_Law_Info_Cookie_Scaner extends Cookie_Law_Info_Cookieyes {
15
16
17 /**
18 * Table name for the san history table.
19 *
20 * @var string
21 */
22 public $scan_table = 'cli_cookie_scan';
23 /**
24 * Table name for the san URLs table.
25 *
26 * @var string
27 */
28 public $url_table = 'cli_cookie_scan_url';
29 /**
30 * Table name for the scanned cookies table.
31 *
32 * @var string
33 */
34 public $cookies_table = 'cli_cookie_scan_cookies';
35 /**
36 * Table name for the sannec cookie category table.
37 *
38 * @var string
39 */
40 public $category_table = 'cli_cookie_scan_categories';
41 /**
42 * Table name for the san history table.
43 *
44 * @var string
45 */
46 public $status_labels;
47 /**
48 * To keep the scan history or not
49 *
50 * @var boolean
51 */
52 public $not_keep_records = true;
53 /**
54 * Initialize the scanner
55 */
56
57 public function __construct() {
58 $this->status_labels = array(
59 0 => '',
60 1 => __( 'Incomplete', 'cookie-law-info' ),
61 2 => __( 'Completed', 'cookie-law-info' ),
62 3 => __( 'Stopped', 'cookie-law-info' ),
63 4 => __( 'Failed', 'cookie-law-info' ),
64 );
65 add_action( 'admin_menu', array( $this, 'add_admin_pages' ), 5 );
66 add_action( 'wt_cli_cookie_scanner_body', array( $this, 'scanner_notices' ) );
67 add_action( 'init', array( $this, 'init' ) );
68 add_action( 'admin_init', array( $this, 'export_result' ) );
69 add_filter( 'wt_cli_cookie_scan_status', array( $this, 'check_scan_status' ) );
70 register_activation_hook( CLI_PLUGIN_FILENAME, array( $this, 'activator' ) );
71 add_action('wt_cli_initialize_plugin', array( $this, 'activator' ) );
72 add_action(
73 'rest_api_init',
74 function () {
75 register_rest_route(
76 'cookieyes/v1',
77 '/fetch_results',
78 array(
79 'methods' => 'POST',
80 'callback' => array( $this, 'fetch_scan_result' ),
81 'permission_callback' => '__return_true',
82 )
83 );
84 }
85 );
86 }
87 /**
88 * Include AJAX handler class
89 *
90 * @return void
91 */
92 public function init() {
93 include plugin_dir_path( __FILE__ ) . 'classes/class-cookie-law-info-cookie-scanner-ajax.php';
94
95 }
96 /**
97 * Plugin activation hook
98 *
99 * @return void
100 */
101 public function activator() {
102 global $wpdb;
103 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
104
105 if ( is_multisite() ) {
106 $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.NotPrepared
107 foreach ( $blog_ids as $blog_id ) {
108 switch_to_blog( $blog_id );
109 $this->install_tables();
110 restore_current_blog();
111 }
112 } else {
113 $this->install_tables();
114 }
115 }
116 /**
117 * Check whether table exist or not
118 *
119 * @param string $table_name table name.
120 * @return bool
121 */
122 public function table_exists( $table_name ) {
123 global $wpdb;
124
125 $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
126
127 if ( $wpdb->get_var( $query ) === $table_name ) {
128 return true;
129 }
130 return false;
131 }
132 /**
133 * Install necessary tables
134 *
135 * @return void
136 */
137 public function install_tables() {
138 global $wpdb;
139
140 $charset_collate = $wpdb->get_charset_collate();
141
142 $table_name = $wpdb->prefix . $this->scan_table;
143
144 if ( false === $this->table_exists( $table_name ) ) {
145 $create_table_sql = "CREATE TABLE `$table_name`(
146 `id_cli_cookie_scan` INT NOT NULL AUTO_INCREMENT,
147 `status` INT NOT NULL DEFAULT '0',
148 `created_at` INT NOT NULL DEFAULT '0',
149 `total_url` INT NOT NULL DEFAULT '0',
150 `total_cookies` INT NOT NULL DEFAULT '0',
151 `current_action` VARCHAR(50) NOT NULL,
152 `current_offset` INT NOT NULL DEFAULT '0',
153 PRIMARY KEY(`id_cli_cookie_scan`)
154 ) $charset_collate;";
155
156 dbDelta( $create_table_sql );
157 }
158
159 // Creates a table to store all the URLs.
160 $table_name = $wpdb->prefix . $this->url_table;
161
162 if ( false === $this->table_exists( $table_name ) ) {
163 $create_table_sql = "CREATE TABLE `$table_name`(
164 `id_cli_cookie_scan_url` INT NOT NULL AUTO_INCREMENT,
165 `id_cli_cookie_scan` INT NOT NULL DEFAULT '0',
166 `url` TEXT NOT NULL,
167 `scanned` INT NOT NULL DEFAULT '0',
168 `total_cookies` INT NOT NULL DEFAULT '0',
169 PRIMARY KEY(`id_cli_cookie_scan_url`)
170 ) $charset_collate;";
171
172 dbDelta( $create_table_sql );
173 }
174
175 // Creates a table to store all the categories of cookies.
176 $table_name = $wpdb->prefix . $this->category_table;
177
178 if ( false === $this->table_exists( $table_name ) ) {
179 $create_table_sql = "CREATE TABLE `$table_name`(
180 `id_cli_cookie_category` INT NOT NULL AUTO_INCREMENT,
181 `cli_cookie_category_name` VARCHAR(100) NOT NULL,
182 `cli_cookie_category_description` TEXT NULL,
183 PRIMARY KEY(`id_cli_cookie_category`),
184 UNIQUE `cookie` (`cli_cookie_category_name`)
185 )";
186 $this->insert_scanner_tables( $create_table_sql, $charset_collate );
187 }
188
189 // Creates a table to store all the scanned cookies.
190 $table_name = $wpdb->prefix . $this->cookies_table;
191
192 if ( false === $this->table_exists( $table_name ) ) {
193 $create_table_sql = "CREATE TABLE `$table_name`(
194 `id_cli_cookie_scan_cookies` INT NOT NULL AUTO_INCREMENT,
195 `id_cli_cookie_scan` INT NOT NULL DEFAULT '0',
196 `id_cli_cookie_scan_url` INT NOT NULL DEFAULT '0',
197 `cookie_id` VARCHAR(255) NOT NULL,
198 `expiry` VARCHAR(255) NOT NULL,
199 `type` VARCHAR(255) NOT NULL,
200 `category` VARCHAR(255) NOT NULL,
201 `category_id` INT NOT NULL,
202 `description` TEXT NULL DEFAULT '',
203 PRIMARY KEY(`id_cli_cookie_scan_cookies`),
204 UNIQUE `cookie` (`id_cli_cookie_scan`, `cookie_id`)
205 )";
206
207 $this->insert_scanner_tables( $create_table_sql, $charset_collate );
208 }
209 $this->update_tables();
210 }
211 /**
212 * Add foreign key constraint to cookie table
213 *
214 * @return void
215 */
216 private function update_tables() {
217 global $wpdb;
218
219 $cookies_table = $wpdb->prefix . $this->cookies_table;
220 $category_table = $wpdb->prefix . $this->category_table;
221
222 $wpdb->query( "ALTER TABLE `$cookies_table` ADD CONSTRAINT FOREIGN KEY (`category_id`) REFERENCES `$category_table` (`id_cli_cookie_category`)" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.NotPrepared
223 }
224 /**
225 * Recursice function to insert sanner tables no matter what error has occured
226 *
227 * @param string $sql sql query.
228 * @param string $prop property value.
229 * @param integer $status current status fail or success.
230 * @return boolean
231 */
232 private function insert_scanner_tables( $sql, $prop = '', $status = 0 ) {
233
234 global $wpdb;
235 dbDelta( $sql . ' ' . $prop );
236 if ( $wpdb->last_error ) {
237 $status++;
238 if ( 1 === $status ) {
239 $prop = '';
240 } elseif ( 2 === $status ) {
241 $prop = 'ENGINE = MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci';
242 } else {
243 return true;
244 }
245 $this->insert_scanner_tables( $sql, $prop, $status );
246 } else {
247 return true;
248 }
249 }
250 /**
251 * Add cookie scanner submenu
252 *
253 * @return void
254 */
255 public function add_admin_pages() {
256 add_submenu_page(
257 'edit.php?post_type=' . CLI_POST_TYPE,
258 __( 'Cookie Scanner', 'cookie-law-info' ),
259 __( 'Cookie Scanner', 'cookie-law-info' ),
260 'manage_options',
261 'cookie-law-info-cookie-scaner',
262 array( $this, 'cookie_scaner_page' )
263 );
264 }
265 /**
266 * Check if all the tables are inserted
267 *
268 * @return bool
269 */
270 protected function check_tables() {
271 global $wpdb;
272
273 $scanner_tables = array(
274 $this->scan_table,
275 $this->url_table,
276 $this->cookies_table,
277 $this->category_table,
278
279 );
280 foreach ( $scanner_tables as $table ) {
281 $table_name = $wpdb->prefix . $table;
282 $search_query = "SHOW TABLES LIKE '%" . $table_name . "%'";
283 if ( ! $wpdb->get_results( $search_query, ARRAY_N ) ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.NotPrepared
284 return false;
285 }
286 }
287 return true;
288 }
289 /**
290 * Main admin page of the cookie scanner,
291 *
292 * @return void
293 */
294 public function cookie_scaner_page() {
295
296 if ( ! current_user_can( 'manage_options' ) ) {
297 wp_die( esc_html( __( 'You do not have sufficient permission to perform this operation', 'cookie-law-info' ) ) );
298 }
299 if ( 'cookielawinfo_page_cookie-law-info-cookie-scaner' === get_current_screen()->id ) {
300 $scan_page_url = admin_url( 'edit.php?post_type=' . CLI_POST_TYPE . '&page=cookie-law-info-cookie-scaner' );
301 $export_page_url = $scan_page_url . '&cli_scan_export=';
302
303 $scan_results = $this->get_last_scan_result();
304
305 include plugin_dir_path( __FILE__ ) . 'views/settings.php';
306
307 $params = array(
308 'nonces' => array(
309 'cli_cookie_scaner' => wp_create_nonce( 'cli_cookie_scaner' ),
310 ),
311 'ajax_url' => admin_url( 'admin-ajax.php' ),
312 'scan_status' => ( $this->check_scan_status() === 1 ? true : false ),
313 'loading_gif' => plugin_dir_url( __FILE__ ) . 'assets/images/loading.gif',
314 'labels' => array(
315 'scanned' => __( 'Scanned', 'cookie-law-info' ),
316 'finished' => __( 'Scanning completed.', 'cookie-law-info' ),
317 'import_finished' => __( 'Added to cookie list.', 'cookie-law-info' ),
318 'finding' => __( 'Finding pages...', 'cookie-law-info' ),
319 'scanning' => __( 'Scanning pages...', 'cookie-law-info' ),
320 'error' => __( 'Error', 'cookie-law-info' ),
321 'stop' => __( 'Stop', 'cookie-law-info' ),
322 'scan_again' => __( 'Scan again', 'cookie-law-info' ),
323 'export' => __( 'Download cookies as CSV', 'cookie-law-info' ),
324 'import' => __( 'Add to cookie list', 'cookie-law-info' ),
325 'view_result' => __( 'View scan result', 'cookie-law-info' ),
326 'import_options' => __( 'Import options', 'cookie-law-info' ),
327 'replace_old' => __( 'Replace old', 'cookie-law-info' ),
328 'merge' => __( 'Merge', 'cookie-law-info' ),
329 'recommended' => __( 'Recommended', 'cookie-law-info' ),
330 'append' => __( 'Append', 'cookie-law-info' ),
331 'not_recommended' => __( 'Not recommended', 'cookie-law-info' ),
332 'cancel' => __( 'Cancel', 'cookie-law-info' ),
333 'start_import' => __( 'Start import', 'cookie-law-info' ),
334 'importing' => __( 'Importing....', 'cookie-law-info' ),
335 'refreshing' => __( 'Refreshing....', 'cookie-law-info' ),
336 'reload_page' => __( 'Error !!! Please reload the page to see cookie list.', 'cookie-law-info' ),
337 'stoping' => __( 'Stopping...', 'cookie-law-info' ),
338 'scanning_stopped' => __( 'Scanning stopped.', 'cookie-law-info' ),
339 'ru_sure' => __( 'Are you sure?', 'cookie-law-info' ),
340 'success' => __( 'Success', 'cookie-law-info' ),
341 'thankyou' => __( 'Thank you', 'cookie-law-info' ),
342 'checking_api' => __( 'Checking API', 'cookie-law-info' ),
343 'sending' => __( 'Sending...', 'cookie-law-info' ),
344 'total_urls_scanned' => __( 'Total URLs scanned', 'cookie-law-info' ),
345 'total_cookies_found' => __( 'Total Cookies found', 'cookie-law-info' ),
346 'page_fetch_error' => __( 'Could not fetch the URLs, please try again', 'cookie-law-info' ),
347 'abort' => __( 'Aborting the scan...', 'cookie-law-info' ),
348 'abort_failed' => __( 'Could not abort the scan, please try again', 'cookie-law-info' ),
349 ),
350 );
351 wp_enqueue_script( 'cookielawinfo_cookie_scaner', plugin_dir_url( __FILE__ ) . 'assets/js/cookie-scaner.js', array(), CLI_VERSION, true );
352 wp_localize_script( 'cookielawinfo_cookie_scaner', 'cookielawinfo_cookie_scaner', $params );
353 }
354 }
355 /**
356 * Insert a new scan entry to the scanner table
357 *
358 * @param array $data_arr Array of data.
359 * @param int $scan_id scan ID.
360 * @return bool
361 */
362 protected function update_scan_entry( $data_arr, $scan_id ) {
363 global $wpdb;
364 $scan_table = $wpdb->prefix . $this->scan_table;
365 if ( $wpdb->update( $scan_table, $data_arr, array( 'id_cli_cookie_scan' => $scan_id ) ) ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.NotPrepared
366 return true;
367 } else {
368 return false;
369 }
370 }
371 /**
372 * Insert the URL's
373 *
374 * @param int $scan_id scan ID.
375 * @param string $permalink Permalink of a page or post.
376 * @return void
377 */
378 protected function insert_url( $scan_id, $permalink ) {
379 global $wpdb;
380 $url_table = $wpdb->prefix . $this->url_table;
381 $data_arr = array(
382 'id_cli_cookie_scan' => $scan_id,
383 'url' => $permalink,
384 'scanned' => 0,
385 'total_cookies' => 0,
386 );
387 $wpdb->insert( $url_table, $data_arr );
388 }
389
390 /**
391 * Get current scan status text
392 *
393 * @param [type] $status current status of the scan.
394 * @return string
395 */
396 public function get_scan_status_text( $status ) {
397 return isset( $this->status_labels[ $status ] ) ? $this->status_labels[ $status ] : __( 'Unknown', 'cookie-law-info' );
398 }
399 /**
400 * Return the last scan results
401 *
402 * @return array
403 */
404 protected function get_last_scan() {
405 global $wpdb;
406 $scan_table = $wpdb->prefix . $this->scan_table;
407 $data = array();
408 if ( true === $this->table_exists( $scan_table ) ) {
409 $sql = "SELECT * FROM `$scan_table` ORDER BY id_cli_cookie_scan DESC LIMIT 1";
410 $data = $wpdb->get_row( $sql, ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.NotPrepared
411 }
412 return $data;
413 }
414 /**
415 * Return the current scan status progress, failed , or success.
416 *
417 * @return integer
418 */
419 public function check_scan_status() {
420 $last_scan = $this->get_last_scan();
421 $status = ( isset( $last_scan['status'] ) ? $last_scan['status'] : 0 );
422 if ( $this->get_cookieyes_status() === 0 || $this->get_cookieyes_status() === false ) {
423 $status = 0;
424 }
425 return intval( $status );
426 }
427 /**
428 * Display a notice if not connected to CookieYes
429 *
430 * @param boolean $existing if existing customer return different notice.
431 * @return string
432 */
433 public function get_cookieyes_scan_notice( $existing = false ) {
434
435 $ckyes_link = 'https://www.cookieyes.com/';
436 $ckyes_privacy_policy = 'https://www.cookieyes.com/privacy-policy';
437 $ckyes_terms_conditions = 'https://www.cookieyes.com/terms-and-conditions/';
438
439 $notice = '<p>' . __( 'Scan your website with CookieYes, our scanning solution for high-speed, accurate cookie scanning', 'cookie-law-info' ) . '</p>';
440 $notice = '<p style="font-weight:500;">' . sprintf(
441 wp_kses(
442 __( 'Clicking “Connect & scan” will let you connect with a free <a href="%s" target="_blank">CookieYes</a> account and initiate scanning of your website for cookies. These cookies along with their description will be listed under the cookie declaration popup. By continuing, you agree to CookieYes\'s <a href="%1$s" target="_blank">Privacy Policy</a> & <a href="%2$s" target="_blank">Terms of service</a>.', 'cookie-law-info' ),
443 array(
444 'a' => array(
445 'href' => array(),
446 'target' => array(),
447 ),
448 )
449 ),
450 esc_url( $ckyes_link ),
451 esc_url( $ckyes_privacy_policy ),
452 esc_url( $ckyes_terms_conditions )
453 ) . '</p>';
454
455 $notice = Cookie_Law_Info_Admin::wt_cli_admin_notice( 'info', $notice );
456 if ( false === $existing ) { // Existing user so show this notice.
457 $notice .= '<div class="wt-cli-cookie-scanner-actions"><a id="wt-cli-ckyes-connect-scan" class="button-primary">' . __( 'Connect & scan', 'cookie-law-info' ) . '</a></div>';
458 }
459 return $notice;
460 }
461 /**
462 * Get last scan info
463 *
464 * @return string
465 */
466 public function get_last_scan_info() {
467
468 $last_scan = $this->get_last_scan();
469
470 $scan_notice = $this->get_scan_default_html();
471 $show_results = false;
472
473 if ( $last_scan ) {
474 $scan_status = intval( ( isset( $last_scan['status'] ) ? $last_scan['status'] : 0 ) );
475 if ( 2 === $scan_status ) {
476 $scan_notice = $this->get_scan_success_html( $last_scan );
477 $show_results = true;
478 } elseif ( 3 === $scan_status ) {
479 $scan_notice = $this->get_scan_abort_html( $last_scan );
480 } elseif ( 4 === $scan_status ) {
481 $scan_notice = $this->get_scan_failed_html( $last_scan );
482 }
483 }
484 $notice = '<div class="wt-cli-cookie-scan-container">';
485 $notice .= '<div class="wt-cli-cookie-scanner-actions">' . apply_filters( 'wt_cli_ckyes_account_widget', '' ) . '</div>';
486 $notice .= $scan_notice;
487 $notice .= '</div>';
488 $notice .= '<div class="wt-cli-cookie-scanner-actions">' . $this->get_scan_btn() . '</div>';
489 if( true === $show_results ) {
490 $notice .= $this->get_scan_result_table();
491 }
492 return $notice;
493
494 }
495 /**
496 * Default HTML content if no scanning has performed
497 *
498 * @return string
499 */
500 public function get_scan_default_html() {
501 $message = '<p>' . __( 'You haven\'t performed a site scan yet.', 'cookie-law-info' ) . '</p>';
502 return Cookie_Law_Info_Admin::wt_cli_admin_notice( 'info', $message );
503 }
504 /**
505 * Scan success HTML
506 *
507 * @param [type] $scan_data scan data.
508 * @return string
509 */
510 public function get_scan_success_html( $scan_data ) {
511
512 $message = '';
513 $result_page = admin_url( 'edit.php?post_type=' . CLI_POST_TYPE . '&page=cookie-law-info-cookie-scaner&scan_result' );
514 $last_scan_date = ( isset( $scan_data['created_at'] ) ? $scan_data['created_at'] : '' );
515
516 if ( ! empty( ( $last_scan_date ) ) ) {
517 $last_scan_date = date( 'F j, Y g:i a T', $last_scan_date );
518 }
519
520 $last_scan_text = sprintf( wp_kses( __( 'Last scan: %1$s', 'cookie-law-info' ), array( 'a' => array( 'href' => array() ) ) ), $last_scan_date );
521 $message = '<div class="wt-cli-scan-status"><p><b>' . __( 'Scan complete', 'cookie-law-info' ) . '</b></p></div>';
522 $message .= '<div class="wt-cli-scan-date"><p style="color: #80827f;">' . $last_scan_text . '</p></div>';
523
524 return Cookie_Law_Info_Admin::wt_cli_admin_notice( 'success', $message, true );
525
526 }
527 /**
528 * Scan failed HTML
529 *
530 * @param array $scan_data scan result.
531 * @return string
532 */
533 public function get_scan_failed_html( $scan_data ) {
534
535 $last_scan_date = ( isset( $scan_data['created_at'] ) ? $scan_data['created_at'] : '' );
536
537 if ( ! empty( ( $last_scan_date ) ) ) {
538 $last_scan_date = date( 'F j, Y g:i a T', $last_scan_date );
539 }
540
541 $message = '<div class="wt-cli-scan-status"><p><b>' . __( 'Scan failed', 'cookie-law-info' ) . '</b></p></div>';
542 $message .= '<div class="wt-cli-scan-date"><p style="color: #80827f;">' . __( 'Last scan:', 'cookie-law-info' ) . ' ' . $last_scan_date . '</p></div>';
543
544 return Cookie_Law_Info_Admin::wt_cli_admin_notice( 'warning', $message, true );
545 }
546 /**
547 * Scan abort HTML
548 *
549 * @param array $scan_data scan result.
550 * @return string
551 */
552 public function get_scan_abort_html( $scan_data ) {
553 $last_scan_date = ( isset( $scan_data['created_at'] ) ? $scan_data['created_at'] : '' );
554
555 if ( ! empty( ( $last_scan_date ) ) ) {
556 $last_scan_date = date( 'F j, Y g:i a T', $last_scan_date );
557 }
558
559 $message = '<div class="wt-cli-scan-status"><p><b>' . __( 'Scan aborted', 'cookie-law-info' ) . '</b></p></div>';
560 $message .= '<div class="wt-cli-scan-date"><p style="color: #80827f;">' . __( 'Last scan:', 'cookie-law-info' ) . ' ' . $last_scan_date . '</p></div>';
561 return Cookie_Law_Info_Admin::wt_cli_admin_notice( 'alert', $message, true );
562 }
563 /**
564 * Scan progress HTML.
565 *
566 * @return string
567 */
568 public function get_scan_progress_html() {
569
570 $last_scan = $this->get_last_scan();
571 $total_urls = ( isset( $last_scan['total_url'] ) ? $last_scan['total_url'] : 0 );
572 $last_scan_timestamp = ( isset( $last_scan['created_at'] ) ? $last_scan['created_at'] : '' );
573 $scan_estimate_in_seconds = $this->get_ckyes_scan_estimate();
574 $scan_estimate = date( 'H:i:s', $scan_estimate_in_seconds );
575 $last_scan_date = '';
576 if ( ! empty( ( $last_scan_timestamp ) ) ) {
577 $last_scan_date = date( 'F j, Y g:i a T', $last_scan_timestamp );
578 }
579 // $offset_time = ( $scan_estimate_in_seconds > HOUR_IN_SECONDS ) ? $scan_estimate_in_seconds : HOUR_IN_SECONDS;
580 // $show_abort = ( time() > ( intval( $last_scan_timestamp ) + intval( $offset_time ) ) ) ? true : false;
581
582 $html = '<div class="wt-cli-scan-status-container" style="">
583 <div class="wt-cli-row">
584 <div class="wt-cli-col-5">
585 <div class="wt-cli-row">
586 <div class="wt-cli-col-5">
587 <div class="wt-cli-scan-status-bar" style="display:flex;align-items:center; color: #2fab10;">
588 <span class="wt-cli-status-icon wt-cli-status-success"></span><span style="margin-left:10px">' . __( 'Scan initiated...', 'cookie-law-info' ) . '</span>
589 </div>
590 </div>
591 <div class="wt-cli-col-7"><a id="wt-cli-cookie-scan-abort" href="#">' . __( 'Abort scan', 'cookie-law-info' ) . '</a></div>
592 </div>
593 </div>
594 </div>
595 </div>
596 <div class="wt-scan-status-info">
597 <div class="wt-cli-row">
598 <div class="wt-cli-col-5">
599 <div class="wt-scan-status-info-item">
600 <div class="wt-cli-row">
601 <div class="wt-cli-col-5">
602 <b>' . __( 'Scan started at', 'cookie-law-info' ) . ':</b>
603 </div>
604 <div class="wt-cli-col-7">' . $last_scan_date . '</div>
605 </div>
606 </div>
607 <div class="wt-scan-status-info-item">
608 <div class="wt-cli-row">
609 <div class="wt-cli-col-5">
610 <b>' . __( 'Total URLs', 'cookie-law-info' ) . ':</b>
611 </div>
612 <div class="wt-cli-col-7">' . $total_urls . '</div>
613 </div>
614 </div>
615 <div class="wt-scan-status-info-item">
616 <div class="wt-cli-row">
617 <div class="wt-cli-col-5">
618 <b>' . __( 'Total estimated time (Approx)', 'cookie-law-info' ) . ':</b>
619 </div>
620 <div class="wt-cli-col-7">' . $scan_estimate . '</div>
621 </div>
622 </div>
623 </div>
624 </div>
625 </div>
626 <div class="wt-cli-notice wt-cli-info">' . __( 'Your website is currently being scanned for cookies. This might take from a few minutes to a few hours, depending on your website speed and the number of pages to be scanned.', 'cookie-law-info' ) .
627
628 '</br><b>' . __( 'Once the scanning is complete, we will notify you by email.', 'cookie-law-info' ) . '</b></div>
629 ';
630 return $html;
631 }
632 /**
633 * Scanner notices
634 *
635 * @param boolean $return check whether to return or print the content.
636 * @return string
637 */
638 public function scanner_notices( $return = false ) {
639
640 $notice = '';
641 $cookies_table = '';
642 $html = '';
643
644 if ( ! $this->check_tables() ) {
645 $notice = $this->get_table_missing_notice();
646 } elseif ( $this->check_if_local_server() === true ) {
647 $message = __( 'Unable to load cookie scanner. Scanning will not work on local servers', 'cookie-law-info' );
648 $notice = Cookie_Law_Info_Admin::wt_cli_admin_notice( 'warning', $message );
649 } elseif ( Cookie_Law_Info_Cookies::get_instance()->check_if_old_category_table() === true ) {
650 $notice = $this->cookies_scan_features();
651 } else {
652 if ( $this->get_cookieyes_status() === false ) {
653
654 $last_scan = $this->get_last_scan();
655 if ( $last_scan ) {
656 $notice = $this->get_cookieyes_scan_notice( true ); // Existing customer so there should be no connect button.
657 $notice .= $this->get_last_scan_info();
658 } else {
659 $notice = $this->get_cookieyes_scan_notice();
660 $notice .= $this->cookies_scan_features();
661 }
662 } else {
663 if ( $this->check_scan_status() === 1 ) {
664 $notice = $this->get_scan_progress_html();
665 } else {
666 $notice = $this->get_last_scan_info();
667 }
668 }
669 }
670 $html = $notice;
671
672 if ( true === $return ) {
673 return $html;
674 } else {
675 echo $html; // phpcs:ignore WordPress.Security.EscapeOutput
676
677 }
678 }
679 /**
680 * Table missing notice.
681 *
682 * @return string
683 */
684 public function get_table_missing_notice() {
685
686 $message = __( 'To scan cookies following tables should be present on your database, please check if tables do exist on your database. If not exist please try to deactivate and activate the plugin again.', 'cookie-law-info' );
687 $message .= '<ul>';
688 $message .= '<li>{$wpdb->prefix}cli_cookie_scan</li>';
689 $message .= '<li>{$wpdb->prefix}cli_cookie_scan_url</li>';
690 $message .= '<li>{$wpdb->prefix}cli_cookie_scan_cookies</li>';
691 $message .= '<li>{$wpdb->prefix}cli_cookie_scan_categories</li>';
692 $message .= '</ul>';
693
694 $notice = Cookie_Law_Info_Admin::wt_cli_admin_notice( 'warning', $message );
695 return $notice;
696
697 }
698 /**
699 * Detect whether the server is hosted locally or not
700 *
701 * @return bool
702 */
703 public function check_if_local_server() {
704 $localhost_arr = array(
705 '127.0.0.1',
706 '::1',
707 );
708 if ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
709 $ip_address = sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) );
710 } else {
711 $ip_address = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
712 }
713 $ip_address = apply_filters('wt_cli_change_ip_address', $ip_address );
714 if ( in_array( $ip_address, $localhost_arr, true ) ) {
715 return true;
716 }
717 return false;
718 }
719 /**
720 * Return current cookies present on the cookie posts
721 *
722 * @access public
723 * @return array
724 */
725 public static function get_cookie_list() {
726 $cookies = array();
727
728 $args = array(
729 'numberposts' => -1,
730 'post_type' => CLI_POST_TYPE,
731 'orderby' => 'ID',
732 'order' => 'DESC',
733 );
734
735 $posts = get_posts( $args );
736 if ( isset( $posts ) && is_array( $posts ) && count( $posts ) > 0 ) {
737 foreach ( $posts as $post ) {
738
739 $post_meta = get_post_custom( $post->ID );
740 $term_list = wp_get_post_terms( $post->ID, 'cookielawinfo-category', array( 'fields' => 'names' ) );
741 $category = isset( $term_list[0] ) ? $term_list[0] : '';
742
743 $cookie_data = array(
744
745 'id' => $post->post_title,
746 'type' => isset( $post_meta['_cli_cookie_type'][0] ) ? $post_meta['_cli_cookie_type'][0] : '',
747 'expiry' => isset( $post_meta['_cli_cookie_duration'][0] ) ? $post_meta['_cli_cookie_duration'][0] : '',
748 'category' => $category,
749 'description' => $post->post_content,
750 );
751 $cookies[] = $cookie_data;
752 }
753 }
754
755 return $cookies;
756 }
757 /**
758 * Return the last scan results
759 *
760 * @return array
761 */
762 public function get_last_scan_result() {
763
764 $last_scan = $this->get_last_scan();
765 $scan_results = array();
766
767 if ( $last_scan && isset( $last_scan['id_cli_cookie_scan'] ) ) {
768 $scan_results = $this->get_scan_results_by_id( $last_scan['id_cli_cookie_scan'] );
769 }
770
771 return $scan_results;
772 }
773 /**
774 * Return last scan history
775 *
776 * @param [type] $id Scan ID.
777 * @return array
778 */
779 public function get_scan_history( $id ) {
780 global $wpdb;
781 $scan_table = $wpdb->prefix . $this->scan_table;
782 $sql = "SELECT * FROM `$scan_table` WHERE id_cli_cookie_scan='$id'";
783 return $wpdb->get_row( $sql, ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.NotPrepared
784 }
785 /**
786 * Retuns scan results by ID
787 *
788 * @param [type] $id scan ID.
789 * @return array
790 */
791 public function get_scan_results_by_id( $id ) {
792
793 $data = array();
794 $scan_info = $this->get_scan_history( $id );
795 $scan_urls = $this->get_scan_urls( $id );
796 $scan_cookies = $this->get_scan_cookies( $id );
797 $data['scan_id'] = $id;
798 $data['date'] = isset( $scan_info['created_at'] ) ? $scan_info['created_at'] : '';
799 $data['status'] = isset( $scan_info['status'] ) ? $scan_info['status'] : '';
800
801 $data['urls'] = isset( $scan_urls['urls'] ) ? $scan_urls['urls'] : '';
802 $data['total_urls'] = isset( $scan_urls['total'] ) ? $scan_urls['total'] : '';
803
804 $data['cookies'] = isset( $scan_cookies['cookies'] ) ? $this->process_cookies( $scan_cookies['cookies'] ) : '';
805 $data['total_cookies'] = isset( $scan_cookies['total'] ) ? $scan_cookies['total'] : '';
806
807 return $data;
808 }
809 /**
810 * Process cookies and re order by description.
811 *
812 * @param array $raw_cookie_data raw cookie data.
813 * @return array
814 */
815 public function process_cookies( $raw_cookie_data ) {
816 $cookies = array();
817 $cookie_has_description = array();
818 $cookie_has_no_description = array();
819 $count = 0;
820 foreach ( $raw_cookie_data as $key => $data ) {
821 $cookie_data = array(
822
823 'id' => isset( $data['cookie_id'] ) ? $data['cookie_id'] : '',
824 'type' => isset( $data['type'] ) ? $data['type'] : '',
825 'expiry' => isset( $data['expiry'] ) ? $data['expiry'] : '',
826 'category' => isset( $data['category'] ) ? $data['category'] : '',
827 'description' => isset( $data['description'] ) ? $data['description'] : '',
828 );
829 if ( '' === $cookie_data['description'] || 'No description' === $cookie_data['description'] ) {
830 $cookie_has_no_description[ $count ] = $cookie_data;
831 } else {
832 $cookie_has_description[ $count ] = $cookie_data;
833 }
834 $count ++;
835 }
836 $cookies = $cookie_has_description + $cookie_has_no_description;
837 return $cookies;
838 }
839 /**
840 * Return the scanner URLs
841 *
842 * @param [type] $scan_id scan ID.
843 * @param integer $offset Offset number.
844 * @param integer $limit page limit if pagination is used.
845 * @return array
846 */
847 public function get_scan_urls( $scan_id, $offset = 0, $limit = 100 ) {
848 global $wpdb;
849 $out = array(
850 'total' => 0,
851 'data' => array(),
852 );
853
854 $url_table = $wpdb->prefix . $this->url_table;
855 $count_sql = "SELECT COUNT(id_cli_cookie_scan_url) AS ttnum FROM $url_table WHERE id_cli_cookie_scan='$scan_id'";
856
857 $count_arr = $wpdb->get_row( $count_sql, ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.NotPrepared
858
859 if ( $count_arr ) {
860 $out['total'] = $count_arr['ttnum'];
861 }
862
863 $sql = "SELECT * FROM $url_table WHERE id_cli_cookie_scan='$scan_id' ORDER BY id_cli_cookie_scan_url ASC LIMIT $offset,$limit";
864
865 $data_arr = $wpdb->get_results( $sql, ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.NotPrepared
866 if ( $data_arr ) {
867 $out['urls'] = $data_arr;
868 }
869 return $out;
870 }
871 /**
872 * Return the identified cookies after the scanning
873 *
874 * @param [type] $scan_id scan ID.
875 * @param integer $offset offset number.
876 * @param integer $limit page limit if pagination is used.
877 * @return array
878 */
879 public function get_scan_cookies( $scan_id, $offset = 0, $limit = 100 ) {
880 global $wpdb;
881 $out = array(
882 'total' => 0,
883 'cookies' => array(),
884 );
885
886 $cookies_table = $wpdb->prefix . $this->cookies_table;
887 $url_table = $wpdb->prefix . $this->url_table;
888 $category_table = $wpdb->prefix . $this->category_table;
889
890 $count_sql = "SELECT COUNT(id_cli_cookie_scan_cookies) AS ttnum FROM $cookies_table WHERE id_cli_cookie_scan='$scan_id'";
891 $count_arr = $wpdb->get_row( $count_sql, ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.NotPrepared
892
893 if ( $count_arr ) {
894 $out['total'] = $count_arr['ttnum'];
895 }
896
897 $sql = "SELECT * FROM $cookies_table INNER JOIN $category_table ON $cookies_table.category_id = $category_table.id_cli_cookie_category INNER JOIN $url_table ON $cookies_table.id_cli_cookie_scan_url = $url_table.id_cli_cookie_scan_url WHERE $cookies_table.id_cli_cookie_scan='$scan_id' ORDER BY id_cli_cookie_scan_cookies ASC" . ( $limit > 0 ? " LIMIT $offset,$limit" : '' );
898 $cookies = $wpdb->get_results( $sql, ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.NotPrepared
899
900 if ( $cookies ) {
901 $out['cookies'] = $cookies;
902 }
903 return $out;
904 }
905 /**
906 * Return HTML table structure for listing cookies
907 *
908 * @param [type] $cookies The cookie list.
909 * @return string
910 */
911 public function create_cookies_table( $cookies ) {
912
913 $count = 1;
914 $html = '<table class="wt-cli-table">';
915 $html .= '<thead>';
916 $html .= '<th style="width: 6%;">' . __( 'Sl.No:', 'cookie-law-info' ) . '</th>';
917 $html .= '<th>' . __( 'Cookie Name', 'cookie-law-info' ) . '</th>';
918 $html .= '<th style="width:15%;" >' . __( 'Duration', 'cookie-law-info' ) . '</th>';
919 $html .= '<th style="width:15%;" >' . __( 'Category', 'cookie-law-info' ) . '</th>';
920 $html .= '<th style="width:40%;" >' . __( 'Description', 'cookie-law-info' ) . '</th>';
921 $html .= '</thead>';
922 $html .= '<tbody>';
923
924 if ( isset( $cookies ) && is_array( $cookies ) && count( $cookies ) > 0 ) :
925 foreach ( $cookies as $cookie ) :
926 $html .= '<tr>';
927 $html .= '<td>' . $count . '</td>';
928 $html .= '<td>' . $cookie['id'] . '</td>';
929 $html .= '<td>' . $cookie['expiry'] . '</td>';
930 $html .= '<td>' . $cookie['category'] . '</td>';
931 $html .= '<td>' . $cookie['description'] . '</td>';
932 $html .= '</tr>';
933 $count ++;
934 endforeach;
935 else :
936 $html .= '<tr><td class="colspanchange" colspan="5" style="text-align:center" >' . __( 'Your cookie list is empty', 'cookie-law-info' ) . '</td></tr>';
937 endif;
938
939 $html .= '</tbody>';
940 $html .= '</table>';
941
942 return $html;
943 }
944 /**
945 * Get the last scan ID
946 *
947 * @return int
948 */
949 public function get_last_scan_id() {
950 $last_scan = $this->get_last_scan();
951 $scan_id = ( isset( $last_scan['id_cli_cookie_scan'] ) ? $last_scan['id_cli_cookie_scan'] : false );
952 return $scan_id;
953 }
954 /**
955 * Insert a new scan entry to the table
956 *
957 * @param integer $total_url Total URL count.
958 * @return int
959 */
960 protected function create_scan_entry( $total_url = 0 ) {
961 global $wpdb;
962
963 // we are not planning to keep records of old scans.
964 if ( $this->not_keep_records ) {
965 $this->flush_scan_records();
966 }
967
968 $scan_table = $wpdb->prefix . $this->scan_table;
969 $data_arr = array(
970 'created_at' => time(),
971 'total_url' => $total_url,
972 'total_cookies' => 0,
973 'current_action' => 'get_pages',
974 'status' => 1,
975 );
976 update_option( 'CLI_BYPASS', 1 );
977 if ( $wpdb->insert( $scan_table, $data_arr ) ) {
978 return $wpdb->insert_id;
979 } else {
980 return '0';
981 }
982 }
983 /**
984 * Delete all the scan records
985 *
986 * @return void
987 */
988 public function flush_scan_records() {
989 global $wpdb;
990 $table_name = $wpdb->prefix . $this->scan_table;
991 $wpdb->query( "TRUNCATE TABLE $table_name" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.NotPrepared
992 $table_name = $wpdb->prefix . $this->url_table;
993 $wpdb->query( "TRUNCATE TABLE $table_name" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.NotPrepared
994 $table_name = $wpdb->prefix . $this->cookies_table;
995 $wpdb->query( "TRUNCATE TABLE $table_name" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.NotPrepared
996 }
997 /**
998 * Fetch the current scan result
999 *
1000 * @param array $request Request object.
1001 * @return void
1002 */
1003 public function fetch_scan_result( $request ) {
1004
1005 if ( isset( $request ) && is_object( $request ) ) {
1006 $request_body = $request->get_body();
1007 if ( ! empty( $request_body ) ) {
1008 if ( is_wp_error( $this->save_cookie_data( json_decode( $request_body, true ) ) ) ) {
1009 wp_send_json_error( __( 'Token mismatch', 'cookie-law-info' ) );
1010 }
1011 wp_send_json_success( __( 'Successfully inserted', 'cookie-law-info' ) );
1012 }
1013 }
1014 wp_send_json_error( __( 'Failed to insert', 'cookie-law-info' ) );
1015 }
1016 /**
1017 * Save cookie data to cookies table
1018 *
1019 * @param array $cookie_data Array of data.
1020 * @return void
1021 */
1022 public function save_cookie_data( $cookie_data ) {
1023
1024 global $wpdb;
1025 $url_table = $wpdb->prefix . $this->url_table;
1026 $scan_id = $this->get_last_scan_id();
1027 $scan_urls = array();
1028
1029 if ( $cookie_data ) {
1030 if ( $scan_id !== false ) {
1031
1032 $sql = "SELECT id_cli_cookie_scan_url,url FROM `$url_table` WHERE id_cli_cookie_scan=$scan_id ORDER BY id_cli_cookie_scan_url ASC";
1033 $urls = $wpdb->get_results( $sql, ARRAY_A );
1034 foreach ( $urls as $url_data ) {
1035 $scan_urls[ $url_data['url'] ] = $url_data['id_cli_cookie_scan_url'];
1036 }
1037 $scan_data = ( isset( $cookie_data['scan_result'] ) ? json_decode( $cookie_data['scan_result'], true ) : array() );
1038 $scan_result_token = ( isset( $cookie_data['scan_result_token'] ) ? $cookie_data['scan_result_token'] : array() );
1039
1040 if ( $this->validate_scan_instance( $scan_result_token ) === false ) {
1041 return new WP_Error( 'invalid', __( 'Invalid scan token', 'cookie-law-info' ) );
1042 }
1043 $this->insert_categories( $scan_data );
1044 foreach ( $scan_data as $key => $data ) {
1045 $cookies = ( isset( $data['cookies'] ) ? $data['cookies'] : '' );
1046 $category = ( isset( $data['category'] ) ? $data['category'] : '' );
1047 $this->insert_cookies( $scan_id, $scan_urls, $cookies, $category );
1048 }
1049 }
1050 }
1051 $this->finish_scan( $scan_id );
1052 }
1053 /**
1054 * Validate the scan instance sent to the CookieYes for scanning purposes
1055 *
1056 * @param string $instance Created instance ID.
1057 * @return bool
1058 */
1059 public function validate_scan_instance( $instance ) {
1060 $last_instance = $this->get_ckyes_scan_instance();
1061 if ( $instance === $last_instance ) {
1062 return true;
1063 }
1064 return false;
1065 }
1066 /**
1067 * Finish the scan
1068 *
1069 * @param int $scan_id Scan ID.
1070 * @return void
1071 */
1072 public function finish_scan( $scan_id ) {
1073 $scan_data = array(
1074 'current_action' => 'scan_pages',
1075 'current_offset' => -1,
1076 'status' => 2,
1077 );
1078 $this->set_ckyes_scan_status( 2 );
1079 $this->update_scan_entry( $scan_data, $scan_id );
1080 $this->reset_scan_token();
1081 }
1082 /**
1083 * Insert all the cookie categories.
1084 *
1085 * @param array $categories Array of cookie categories.
1086 * @return void
1087 */
1088 protected function insert_categories( $categories ) {
1089 global $wpdb;
1090 $cat_table = $wpdb->prefix . $this->category_table;
1091 $cat_arr = array();
1092 $cat_sql = "INSERT IGNORE INTO `$cat_table` (`cli_cookie_category_name`,`cli_cookie_category_description`) VALUES ";
1093
1094 foreach ( $categories as $id => $category_data ) {
1095 $category = ( isset( $category_data['category'] ) ? sanitize_text_field( $category_data['category'] ) : '' );
1096 $description = ( isset( $category_data['category_desc'] ) ? addslashes( sanitize_textarea_field( $category_data['category_desc'] ) ) : '' );
1097
1098 if ( ! empty( $category ) ) {
1099 $cat_arr[] = "('$category','$description')";
1100 }
1101 }
1102 $cat_sql = $cat_sql . implode( ',', $cat_arr );
1103 if ( ! empty( $cat_arr ) ) {
1104 $wpdb->query( $cat_sql );
1105 }
1106 }
1107 /**
1108 * Insert the scanned Cookies to the corresponding table
1109 *
1110 * @param int $scan_id scan Id.
1111 * @param array $urls scanned URLs.
1112 * @param array $cookie_data scanned cookies.
1113 * @param string $category category.
1114 * @return void
1115 */
1116 protected function insert_cookies( $scan_id, $urls, $cookie_data, $category ) {
1117 global $wpdb;
1118 $cookie_table = $wpdb->prefix . $this->cookies_table;
1119 $category_table = $wpdb->prefix . $this->category_table;
1120
1121 $sql = "INSERT IGNORE INTO `$cookie_table` (`id_cli_cookie_scan`,`id_cli_cookie_scan_url`,`cookie_id`,`expiry`,`type`,`category`,`category_id`,`description`) VALUES ";
1122
1123 $sql_arr = array();
1124
1125 foreach ( $cookie_data as $cookies ) {
1126 $cookie_id = isset( $cookies['cookie_id'] ) ? esc_sql( sanitize_text_field( $cookies['cookie_id'] ) ) : '';
1127 $description = isset( $cookies['description'] ) ? esc_sql( sanitize_textarea_field( $cookies['description'] ) ) : '';
1128 $expiry = isset( $cookies['duration'] ) ? esc_sql( sanitize_text_field( $cookies['duration'] ) ) : '';
1129 $type = isset( $cookies['type'] ) ? esc_sql( sanitize_text_field( $cookies['type'] ) ) : '';
1130
1131 $url_id = ( isset( $cookies['frist_found_url'] ) ? $cookies['frist_found_url'] : '' );
1132 $url_id = ( isset( $urls[ $url_id ] ) ? $urls[ $url_id ] : 1 );
1133 $category_id = $wpdb->get_var( "SELECT `id_cli_cookie_category` FROM `$category_table` WHERE `cli_cookie_category_name` = '$category'" );
1134 $sql_arr[] = "('$scan_id','$url_id','$cookie_id','$expiry','$type','$category','$category_id','$description')";
1135 }
1136 $sql = $sql . implode( ',', $sql_arr );
1137 $wpdb->query( $sql );
1138 }
1139 /**
1140 * List the cookie scan features
1141 *
1142 * @return string
1143 */
1144 public function cookies_scan_features() {
1145 $html = '';
1146 $html .= '<div class="wt-cli-cookie-scan-features">';
1147 $html .= '<h3>' . __( 'Why scan your website for cookies?', 'cookie-law-info' ) . '</h3>';
1148 $html .= '<p>' . __( 'Your website needs to obtain prior consent from your users before setting any cookies other than those required for the proper functioning of your website. Therefore, you need to identify and keep track of all the cookies used on your website.', 'cookie-law-info' ) . '</p>';
1149 $html .= '<p>' . __( 'Our cookie scanning solution lets you:', 'cookie-law-info' ) . '</p>';
1150 $html .= '<ul class="wt-cli-cookie-scan-feature-list">';
1151 $html .= '<li>' . __( 'Discover the first-party and third-party cookies that are being used on your website ( Limited upto 100 pages ).', 'cookie-law-info' ) . '</li>';
1152 $html .= '<li>' . __( 'Identify what personal data they collect and what are the other purposes they serve.', 'cookie-law-info' ) . '</li>';
1153 $html .= '<li>' . __( 'Determine whether you need to comply with the data protection laws governing cookies. Eg:- EU’s GDPR, ePrivacy Directive (EU Cookie Law), California’s CCPA, etc.', 'cookie-law-info' ) . '</li>';
1154 $html .= '</ul>';
1155 // $html .= '<a href="#" class="wt-cli-cookie-scan-preview-modal">' . __( 'Click here to preview sample cookie declaration', 'cookie-law-info' ) . '</a>';
1156 $html .= '<div class="wt-cli-modal" id="wt-cli-ckyes-modal-settings-preview">';
1157 $html .= '<span class="wt-cli-modal-js-close">×</span>';
1158 $html .= '<div class="wt-cli-modal-body">';
1159 $html .= '<img src="' . plugin_dir_url( __FILE__ ) . 'assets/images/screenshot-1.png">';
1160 $html .= '</div></div>';
1161 $html .= '<div class="wt-cli-cookie-scan-preview-image"><img style="width:318.5px;" src="' . plugin_dir_url( __FILE__ ) . 'assets/images/screenshot-1.png"></div>';
1162 $html .= '</div>';
1163 return '<div class="wt-cli-cookie-scan-features-section">' . Cookie_Law_Info_Admin::wt_cli_admin_notice( 'success', $html ) . '</div>';
1164 }
1165 /**
1166 * Export handler
1167 *
1168 * @return void
1169 */
1170 public function export_result() {
1171 if ( isset( $_GET['cli_scan_export'] ) && (int) $_GET['cli_scan_export'] > 0 && check_admin_referer( 'cli_cookie_scaner', 'cli_cookie_scaner' ) && current_user_can( 'manage_options' ) ) {
1172 include plugin_dir_path( __FILE__ ) . 'classes/class-cookie-law-info-cookie-scanner-export.php';
1173
1174 $cookie_serve_export = new Cookie_Law_Info_Cookie_Export();
1175 $cookie_serve_export->do_export( wp_unslash( $_GET['cli_scan_export'] ), $this ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1176
1177 exit();
1178 }
1179 }
1180 public function get_scan_result_table() {
1181
1182 ob_start();
1183 $scan_results = $this->get_last_scan_result();
1184 $cookie_list_page = admin_url( 'edit.php?post_type=' . CLI_POST_TYPE );
1185 $scan_status = intval( ( isset( $scan_results['status'] ) ? $scan_results['status'] : 0 ) );
1186 $scan_page_url = admin_url( 'edit.php?post_type=' . CLI_POST_TYPE . '&page=cookie-law-info-cookie-scaner' );
1187
1188 if ( 2 === $scan_status ) {
1189 include plugin_dir_path( __FILE__ ) . 'views/scan-results.php';
1190 }
1191 $html = ob_get_contents();
1192 ob_end_clean();
1193 return $html;
1194 }
1195 public function get_scan_btn( $strict = false ) {
1196
1197 $last_scan = $this->get_last_scan();
1198 $scan_btn_id = 'wt-cli-ckyes-scan';
1199 $scan_btn_text = __( 'Scan website for cookies', 'cookie-law-info' );
1200 $scan_status = intval( ( isset( $last_scan['status'] ) ? $last_scan['status'] : 0 ) );
1201 $show_btn = true;
1202
1203 $scan_status = intval( ( isset( $last_scan['status'] ) ? $last_scan['status'] : 0 ) );
1204 if ( 2 === $scan_status ) {
1205 $show_btn = false;
1206 }
1207 if ( true === $strict ) {
1208 $scan_btn_text = __( 'Scan again', 'cookie-law-info' );
1209 $show_btn = true; // Override the existing settings.
1210 }
1211 if ( $this->get_cookieyes_status() === 0 || $this->get_cookieyes_status() === false ) { // Disconnected with Cookieyes after registering account.
1212 $scan_btn_id = 'wt-cli-ckyes-connect-scan';
1213 $scan_btn_text = __( 'Connect & scan', 'cookie-law-info' );
1214 $show_btn = true;
1215 if ( true === $strict ) {
1216 $show_btn = false;
1217 }
1218 } else if( $this->get_cookieyes_status() === 2 ) {
1219 $show_btn = true;
1220 }
1221
1222 return ( true === $show_btn ? '<a id="' . $scan_btn_id . '" class="button-primary pull-right">' . $scan_btn_text . '</a>' : '' );
1223
1224 }
1225}
1226new Cookie_Law_Info_Cookie_Scaner();
1227