Edit File by line
/home/zeestwma/ceyloniy.../wp-conte.../plugins/cookiead.../includes
File: admin.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace CookieAdminPro;
[2] Fix | Delete
[3] Fix | Delete
if(!defined('COOKIEADMIN_PRO_VERSION') || !defined('ABSPATH')){
[4] Fix | Delete
die('Hacking Attempt');
[5] Fix | Delete
}
[6] Fix | Delete
[7] Fix | Delete
class Admin{
[8] Fix | Delete
[9] Fix | Delete
static function enqueue_scripts(){
[10] Fix | Delete
[11] Fix | Delete
$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
[12] Fix | Delete
[13] Fix | Delete
$is_admin_page = basename(parse_url($request_uri, PHP_URL_PATH));
[14] Fix | Delete
[15] Fix | Delete
$current_page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
[16] Fix | Delete
[17] Fix | Delete
if(!is_admin() || empty($current_page) || !in_array($current_page, array('cookieadmin-consent-logs')) || $is_admin_page != 'admin.php'){
[18] Fix | Delete
return false;
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
// Add condition to load only on our settings page
[22] Fix | Delete
//Consent Page Css
[23] Fix | Delete
wp_enqueue_style('cookieadmin-pro-style', COOKIEADMIN_PRO_PLUGIN_URL . 'assets/css/cookie.css', [], COOKIEADMIN_PRO_VERSION);
[24] Fix | Delete
[25] Fix | Delete
wp_enqueue_script('cookieadmin_pro_js', COOKIEADMIN_PRO_PLUGIN_URL . 'assets/js/cookie.js', [], COOKIEADMIN_PRO_VERSION);
[26] Fix | Delete
[27] Fix | Delete
$policy['admin_url'] = admin_url('admin-ajax.php');
[28] Fix | Delete
$policy['cookieadmin_nonce'] = wp_create_nonce('cookieadmin_pro_admin_js_nonce');
[29] Fix | Delete
//cookieadmin_r_print($policy);die();
[30] Fix | Delete
[31] Fix | Delete
wp_localize_script('cookieadmin_pro_js', 'cookieadmin_pro_policy', $policy);
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
//Add Main Menu
[35] Fix | Delete
static function plugin_menu(){
[36] Fix | Delete
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
static function show_settings($title = 'CookieAdmin Pro'){
[40] Fix | Delete
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
static function cookieadmin_pro_table_exists($table_name) {
[44] Fix | Delete
global $wpdb;
[45] Fix | Delete
[46] Fix | Delete
$query = $wpdb->prepare("SHOW TABLES LIKE %s", $table_name);
[47] Fix | Delete
[48] Fix | Delete
return $wpdb->get_var($query) === $table_name;
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
static function show_consent_logs(){
[52] Fix | Delete
[53] Fix | Delete
global $cookieadmin_lang, $cookieadmin_error, $cookieadmin_msg;
[54] Fix | Delete
[55] Fix | Delete
\CookieAdmin\Admin::header_theme(__('Consent Logs', 'cookieadmin'));
[56] Fix | Delete
[57] Fix | Delete
$log_data = \CookieAdminPro\Admin::get_consent_logs();
[58] Fix | Delete
$consent_logs = (!empty($log_data['logs']) ? $log_data['logs'] : array());
[59] Fix | Delete
[60] Fix | Delete
echo '
[61] Fix | Delete
[62] Fix | Delete
<div class="cookieadmin_pro_consent-wrap" style="max-width: 85vw;">
[63] Fix | Delete
<form action="" method="post">
[64] Fix | Delete
[65] Fix | Delete
<div class="cookieadmin_consent-contents">
[66] Fix | Delete
<div class="cookieadmin_consent">
[67] Fix | Delete
[68] Fix | Delete
<div class="contents cookieadmin_manager">
[69] Fix | Delete
[70] Fix | Delete
<div class="cookieadmin-setting cookieadmin-manager-consent-logs">
[71] Fix | Delete
<label class="cookieadmin-title"></label>
[72] Fix | Delete
<div class="cookieadmin-setting-contents cookieadmin-consent-logs">
[73] Fix | Delete
<input type="button" class="cookieadmin-btn cookieadmin-btn-primary cookieadmin-consent-logs-export" value="'.esc_html__('Export CSV', 'cookieadmin').'">
[74] Fix | Delete
</div>
[75] Fix | Delete
[76] Fix | Delete
<div class="cookieadmin-manager-scan-result">
[77] Fix | Delete
<table class="cookieadmin-table cookieadmin-consent-logs-result">
[78] Fix | Delete
<thead>
[79] Fix | Delete
<tr>
[80] Fix | Delete
<th width="30%">'.esc_html__('Consent Id', 'cookieadmin').'</th>
[81] Fix | Delete
<th width="20%">'.esc_html__('Status', 'cookieadmin').'</th>
[82] Fix | Delete
<th>'.esc_html__('Country', 'cookieadmin').'</th>
[83] Fix | Delete
<th>'.esc_html__('User IP (Anonymized)', 'cookieadmin').'</th>
[84] Fix | Delete
<th>'.esc_html__('Time', 'cookieadmin').'</th>
[85] Fix | Delete
</tr>
[86] Fix | Delete
</thead>
[87] Fix | Delete
<tbody>';
[88] Fix | Delete
[89] Fix | Delete
if(!empty($consent_logs)){
[90] Fix | Delete
foreach ($consent_logs as $log){
[91] Fix | Delete
[92] Fix | Delete
$status_badge = 'warning';
[93] Fix | Delete
if(strtolower($log['consent_status_raw']) == 'accept'){
[94] Fix | Delete
$status_badge = 'success';
[95] Fix | Delete
}elseif(strtolower($log['consent_status_raw']) == 'reject'){
[96] Fix | Delete
$status_badge = 'danger';
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
echo '
[100] Fix | Delete
<tr>
[101] Fix | Delete
<td>'.esc_html($log['consent_id']).'</td>
[102] Fix | Delete
<td><span class="cookieadmin-badge cookieadmin-'.esc_attr($status_badge).'">'.esc_html($log['consent_status']).'</span></td>
[103] Fix | Delete
<td>'.(!empty($log['country']) ? esc_html($log['country']) : '—').'</td>
[104] Fix | Delete
<td>'.esc_html($log['user_ip']).'</td>
[105] Fix | Delete
<td>'.esc_html($log['consent_time']).'</td>
[106] Fix | Delete
</tr>';
[107] Fix | Delete
}
[108] Fix | Delete
}else{
[109] Fix | Delete
echo '
[110] Fix | Delete
<tr>
[111] Fix | Delete
<td colspan="4">'.esc_html__('No consent logs recorded yet!', 'cookieadmin').'</td>
[112] Fix | Delete
</tr>';
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
echo '
[116] Fix | Delete
</tbody>
[117] Fix | Delete
</table>
[118] Fix | Delete
</div>';
[119] Fix | Delete
[120] Fix | Delete
if(!empty($consent_logs)){
[121] Fix | Delete
echo '
[122] Fix | Delete
<div class="cookieadmin-consent-logs-pagination" style="text-align:right;">
[123] Fix | Delete
'.esc_html__('Displaying', 'cookieadmin').' <span class="displaying-num">'.esc_html($log_data['min_items'].' - '.$log_data['max_items']).'</span> '.esc_html__('of', 'cookieadmin').' <span class="max-num">'.esc_html($log_data['total_logs']).'</span> '.esc_html__('item(s)', 'cookieadmin').'
[124] Fix | Delete
&nbsp;
[125] Fix | Delete
<!-- First Page Consent logs -->
[126] Fix | Delete
<a class="first-page cookieadmin-logs-paginate" id="cookieadmin-first-consent-logs" href="javascript:void(0)">
[127] Fix | Delete
<span aria-hidden="true">«</span>
[128] Fix | Delete
</a>
[129] Fix | Delete
&nbsp;
[130] Fix | Delete
<!-- Previous Page Consent logs -->
[131] Fix | Delete
<a class="prev-page cookieadmin-logs-paginate" id="cookieadmin-previous-consent-logs" href="javascript:void(0)">
[132] Fix | Delete
<span aria-hidden="true">‹</span>
[133] Fix | Delete
</a>
[134] Fix | Delete
&nbsp;
[135] Fix | Delete
<!-- Current Page logs -->
[136] Fix | Delete
<span class="paging-input">
[137] Fix | Delete
<label for="current-page-selector" class="screen-reader-text">Current Page</label>
[138] Fix | Delete
<input class="current-page" id="current-page-selector" name="current-page-selector" value="'.(!empty($log_data['current_page']) ? esc_attr($log_data['current_page']) : '').'" size="3" aria-describedby="table-paging" type="text" style="text-align: center;">
[139] Fix | Delete
<span class="tablenav-paging-text"> of
[140] Fix | Delete
<span class="total-pages">'.esc_html($log_data['total_pages']).'</span>
[141] Fix | Delete
</span>
[142] Fix | Delete
</span>
[143] Fix | Delete
&nbsp;
[144] Fix | Delete
<!-- Next Page Consent Logs -->
[145] Fix | Delete
<a class="next-page cookieadmin-logs-paginate" id="cookieadmin-next-consent-logs" href="javascript:void(0)">
[146] Fix | Delete
<span aria-hidden="true">›</span>
[147] Fix | Delete
</a>
[148] Fix | Delete
&nbsp;
[149] Fix | Delete
<!-- Last Page Consent logs -->
[150] Fix | Delete
<a class="last-page cookieadmin-logs-paginate"
[151] Fix | Delete
id="cookieadmin-last-consent-logs" href="javascript:void(0)">
[152] Fix | Delete
<span aria-hidden="true">»</span>
[153] Fix | Delete
</a>
[154] Fix | Delete
&nbsp;
[155] Fix | Delete
</div>';
[156] Fix | Delete
}
[157] Fix | Delete
echo '
[158] Fix | Delete
</div>
[159] Fix | Delete
</div>
[160] Fix | Delete
</div>';
[161] Fix | Delete
[162] Fix | Delete
wp_nonce_field('cookieadmin_pro_admin_nonce', 'cookieadmin_pro_security');
[163] Fix | Delete
[164] Fix | Delete
echo '<br/>
[165] Fix | Delete
<br/>
[166] Fix | Delete
</div>
[167] Fix | Delete
</form>
[168] Fix | Delete
</div>';
[169] Fix | Delete
[170] Fix | Delete
\CookieAdmin\Admin::footer_theme();
[171] Fix | Delete
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
//Load Consent logs data from the database
[175] Fix | Delete
static function get_consent_logs(){
[176] Fix | Delete
[177] Fix | Delete
global $wpdb;
[178] Fix | Delete
[179] Fix | Delete
if($_POST && count($_POST) > 0){
[180] Fix | Delete
$nonce_slug = (wp_doing_ajax() ? 'cookieadmin_pro_admin_js_nonce' : 'cookieadmin_pro_admin_nonce');
[181] Fix | Delete
check_admin_referer($nonce_slug, 'cookieadmin_pro_security');
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
if(!current_user_can('administrator')){
[185] Fix | Delete
wp_send_json_error(array('message' => 'Sorry, but you do not have permissions to perform this action'));
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
$num_items = 0;
[189] Fix | Delete
$table_name = esc_sql($wpdb->prefix . 'cookieadmin_consents');
[190] Fix | Delete
$current_page = isset($_POST['current_page']) ? intval($_POST['current_page']) : 1;
[191] Fix | Delete
[192] Fix | Delete
if (!\CookieAdminPro\Admin::cookieadmin_pro_table_exists($table_name)) {
[193] Fix | Delete
// wp_send_json_error(['message' => 'Table does not exist']);
[194] Fix | Delete
return array();
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
// Get total number of logs
[198] Fix | Delete
$total_consent_logs = (int) $wpdb->get_var("SELECT COUNT(*) FROM $table_name");
[199] Fix | Delete
$logs_per_page = 25;
[200] Fix | Delete
[201] Fix | Delete
// Calculate max pages
[202] Fix | Delete
$max_page = ceil($total_consent_logs / $logs_per_page);
[203] Fix | Delete
[204] Fix | Delete
// Ensure current page is within valid range
[205] Fix | Delete
if ($current_page > $max_page) {
[206] Fix | Delete
$current_page = $max_page;
[207] Fix | Delete
} elseif ($current_page < 1) {
[208] Fix | Delete
$current_page = 1;
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
// Calculate pagination offset
[212] Fix | Delete
$offset = ($current_page - 1) * $logs_per_page;
[213] Fix | Delete
[214] Fix | Delete
// Fetch paginated logs
[215] Fix | Delete
$consent_logs = $wpdb->get_results(
[216] Fix | Delete
$wpdb->prepare(
[217] Fix | Delete
"SELECT * FROM $table_name ORDER BY id DESC LIMIT %d OFFSET %d",
[218] Fix | Delete
$logs_per_page,
[219] Fix | Delete
$offset
[220] Fix | Delete
),
[221] Fix | Delete
ARRAY_A
[222] Fix | Delete
);
[223] Fix | Delete
[224] Fix | Delete
if(!empty($consent_logs)){
[225] Fix | Delete
[226] Fix | Delete
foreach($consent_logs as $lk => $log){
[227] Fix | Delete
[228] Fix | Delete
if(!empty($log['consent_status'])){
[229] Fix | Delete
$_consent_status = json_decode($log['consent_status'], true)[0];
[230] Fix | Delete
[231] Fix | Delete
if($_consent_status == 'accept'){
[232] Fix | Delete
$consent_logs[$lk]['consent_status_raw'] = 'accept';
[233] Fix | Delete
$consent_logs[$lk]['consent_status'] = __('Accepted', 'cookieadmin');
[234] Fix | Delete
}elseif($_consent_status == 'reject'){
[235] Fix | Delete
$consent_logs[$lk]['consent_status_raw'] = 'reject';
[236] Fix | Delete
$consent_logs[$lk]['consent_status'] = __('Rejected', 'cookieadmin');
[237] Fix | Delete
}else{
[238] Fix | Delete
$consent_logs[$lk]['consent_status_raw'] = 'partially_accepted';
[239] Fix | Delete
$consent_logs[$lk]['consent_status'] = __('Partially Accepted', 'cookieadmin');
[240] Fix | Delete
}
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
if(!empty($log['consent_time'])){
[244] Fix | Delete
$consent_logs[$lk]['consent_time'] = cookieadmin_pro_human_readable_time($log['consent_time']);
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
if(!empty($log['user_ip'])){
[248] Fix | Delete
$consent_logs[$lk]['user_ip'] = inet_ntop($log['user_ip']);
[249] Fix | Delete
}
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
$num_items = count($consent_logs);
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
$min_items = $offset + 1;
[256] Fix | Delete
$max_items = $min_items + ($num_items - 1);
[257] Fix | Delete
[258] Fix | Delete
$return = [
[259] Fix | Delete
'logs' => $consent_logs,
[260] Fix | Delete
'total_logs' => $total_consent_logs,
[261] Fix | Delete
'logs_per_page' => $logs_per_page,
[262] Fix | Delete
'current_page' => $current_page,
[263] Fix | Delete
'total_pages' => $max_page,
[264] Fix | Delete
'min_items' => $min_items,
[265] Fix | Delete
'max_items' => $max_items
[266] Fix | Delete
];
[267] Fix | Delete
[268] Fix | Delete
// Return logs as JSON response
[269] Fix | Delete
if (defined('DOING_AJAX') && DOING_AJAX) {
[270] Fix | Delete
wp_send_json_success($return);
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
// Return paginated data
[274] Fix | Delete
return $return;
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
// Export Consent Logs from the Database
[278] Fix | Delete
static function export_logs() {
[279] Fix | Delete
global $wpdb;
[280] Fix | Delete
[281] Fix | Delete
$cookieadmin_export_type = !empty($_REQUEST['cookieadmin_export_type']) ? sanitize_text_field(wp_unslash($_REQUEST['cookieadmin_export_type'])) : '';
[282] Fix | Delete
[283] Fix | Delete
if(!empty($cookieadmin_export_type)){
[284] Fix | Delete
if($cookieadmin_export_type == 'consent_logs'){
[285] Fix | Delete
[286] Fix | Delete
$table_name = esc_sql($wpdb->prefix . 'cookieadmin_consents');
[287] Fix | Delete
[288] Fix | Delete
//First will check if the table in the database exists or not?
[289] Fix | Delete
if(!self::cookieadmin_pro_table_exists($table_name)){
[290] Fix | Delete
wp_send_json_error(['message' => 'Table does not exists']);
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
$logs = $wpdb->get_results("SELECT * FROM $table_name ORDER BY id DESC", ARRAY_A);
[294] Fix | Delete
$filename = 'cookieadmin-consent-logs';
[295] Fix | Delete
}
[296] Fix | Delete
}
[297] Fix | Delete
[298] Fix | Delete
if(empty($logs)){
[299] Fix | Delete
echo -1;
[300] Fix | Delete
echo esc_html__('No data to export', 'cookieadmin');
[301] Fix | Delete
wp_die();
[302] Fix | Delete
}
[303] Fix | Delete
[304] Fix | Delete
header('Content-Type: text/csv; charset=utf-8');
[305] Fix | Delete
header('Content-Disposition: attachment; filename='.$filename.'.csv');
[306] Fix | Delete
[307] Fix | Delete
$allowed_fields = array('consent_id' => 'Consent Id', 'consent_status' => 'Consent Status', 'country' => 'Country', 'user_ip' => 'User IP (Anonymized)', 'consent_time' => 'Consent Time');
[308] Fix | Delete
[309] Fix | Delete
$file = fopen("php://output","w");
[310] Fix | Delete
[311] Fix | Delete
fputcsv($file, array_values($allowed_fields));
[312] Fix | Delete
[313] Fix | Delete
foreach($logs as $ik => $log){
[314] Fix | Delete
[315] Fix | Delete
if(!empty($log['consent_status'])){
[316] Fix | Delete
$_consent_status = json_decode($log['consent_status'], true)[0];
[317] Fix | Delete
if($_consent_status == 'accept'){
[318] Fix | Delete
$log['consent_status'] = __('Accepted', 'cookieadmin');
[319] Fix | Delete
}elseif($_consent_status == 'reject'){
[320] Fix | Delete
$log['consent_status'] = __('Rejected', 'cookieadmin');
[321] Fix | Delete
}else{
[322] Fix | Delete
$log['consent_status'] = __('Partially Accepted', 'cookieadmin');
[323] Fix | Delete
}
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
if(!empty($log['consent_time'])){
[327] Fix | Delete
$log['consent_time'] = wp_date('M j Y g:i A T', $log['consent_time']);
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
if(!empty($log['user_ip'])){
[331] Fix | Delete
$log['user_ip'] = inet_ntop($log['user_ip']);
[332] Fix | Delete
}
[333] Fix | Delete
[334] Fix | Delete
$log['country'] = (!empty($log['country']) ? $log['country'] : '—');
[335] Fix | Delete
[336] Fix | Delete
$row = array();
[337] Fix | Delete
foreach($allowed_fields as $ak => $av){
[338] Fix | Delete
$row[$ak] = $log[$ak];
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
fputcsv($file, $row);
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
fclose($file);
[345] Fix | Delete
[346] Fix | Delete
wp_die();
[347] Fix | Delete
[348] Fix | Delete
}
[349] Fix | Delete
[350] Fix | Delete
function version_notice(){
[351] Fix | Delete
[352] Fix | Delete
$type = '';
[353] Fix | Delete
if(!empty($_REQUEST['type'])){
[354] Fix | Delete
$type = sanitize_text_field(wp_unslash($_REQUEST['type']));
[355] Fix | Delete
}
[356] Fix | Delete
[357] Fix | Delete
if(empty($type)){
[358] Fix | Delete
wp_send_json_error(__('Unknow version difference type', 'cookieadmin'));
[359] Fix | Delete
}
[360] Fix | Delete
[361] Fix | Delete
update_option('cookieadmin_version_'. $type .'_nag', time() + WEEK_IN_SECONDS);
[362] Fix | Delete
wp_send_json_success();
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
function dismiss_expired_licenses(){
[366] Fix | Delete
[367] Fix | Delete
update_option('softaculous_expired_licenses', time());
[368] Fix | Delete
wp_send_json_success();
[369] Fix | Delete
}
[370] Fix | Delete
[371] Fix | Delete
}
[372] Fix | Delete
[373] Fix | Delete
[374] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function