get_status(); // pagination script wp_enqueue_script( 'cookie-notice-admin-pagination', COOKIE_NOTICE_URL . '/assets/pagination/pagination.min.js', [ 'jquery' ], $cn->defaults['version'] ); wp_enqueue_style( 'cookie-notice-admin-pagination', COOKIE_NOTICE_URL . '/assets/pagination/pagination.css', [], $cn->defaults['version'] ); } /** * Get consent by date via AJAX request. * * @return void */ public function get_consent_logs_by_date() { // valid nonce? if ( ! check_ajax_referer( 'cn-get-consent-logs', 'nonce' ) ) wp_send_json_error(); // check data if ( ! isset( $_POST['action'], $_POST['date'], $_POST['nonce'] ) ) wp_send_json_error(); // check capability if ( ! current_user_can( apply_filters( 'cn_manage_cookie_notice_cap', 'manage_options' ) ) ) wp_send_json_error(); // sanitize date $date = preg_replace( '[^\d-]', '', $_POST['date'] ); // get datetime $dt = DateTime::createFromFormat( 'Y-m-d', $date ); // valid date? if ( $dt && $dt->format( 'Y-m-d' ) === $date ) { $data = Cookie_Notice()->welcome_api->get_consent_logs_by_date( $date ); if ( is_array( $data ) ) wp_send_json_success( $this->get_consent_logs_table( $data ) ); else wp_send_json_error( $data ); } wp_send_json_error(); } /** * Get single row template. * * @return string */ public function get_consent_logs_table( $data ) { $html = ' '; // no data? if ( empty( $data ) ) { $html .= ' '; } else { // set current timezone $current_timezone = new DateTimeZone( Cookie_Notice()->dashboard->timezone_string() ); foreach ( $data as $no => $consent_log ) { $categories = []; if ( $consent_log->ev_essential ) $categories[] = esc_html__( 'Basic Operations', 'cookie-notice' ); if ( $consent_log->ev_functional ) $categories[] = esc_html__( 'Content Personalization', 'cookie-notice' ); if ( $consent_log->ev_analytics ) $categories[] = esc_html__( 'Site Optimization', 'cookie-notice' ); if ( $consent_log->ev_marketing ) $categories[] = esc_html__( 'Ad Personalization', 'cookie-notice' ); // get current date $timestamp = new DateTime( $consent_log->timestamp ); $timestamp->setTimezone( $current_timezone ); // get deuration in days $duration = (int) $consent_log->ev_eventdetails_expiry; if ( $duration === 30 ) $duration = __( '1 month', 'cookie-notice' ); elseif ( $duration === 90 ) $duration = __( '3 months', 'cookie-notice' ); elseif ( $duration === 182 ) $duration = __( '6 months', 'cookie-notice' ); elseif ( $duration === 365 ) $duration = __( '1 year', 'cookie-notice' ); elseif ( $duration === 730 ) $duration = __( '2 years', 'cookie-notice' ); // explode ip address $ip_chunks = explode( '.', $consent_log->rj_ip ); // replace 3rd octet $ip_chunks[2] = preg_replace( '/\d/', 'x', $ip_chunks[2] ); // replace 4th octet $ip_chunks[3] = preg_replace( '/\d/', 'x', $ip_chunks[3] ); $html .= ' 9 ? ' style="display: none"' : '' ) . '> '; } } $html .= ' '; return $html; } /** * Get single row template. * * @return string */ public function get_single_row_template() { return ' '; } /** * Get error template. * * @return string */ public function get_error_template() { return '

' . esc_html__( 'We were unable to download consent logs due to an error. Please try again later.', 'cookie-notice' ) . '

'; } }