<?php
  if (! defined("\x41\x42\x53\x50\x41\x54\x48")) { exit;  } class UniPixelLog { private $log_table; private $log_count_table; public function __construct() { global $wpdb; $this->log_table = $wpdb->prefix . "\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x65\x76\x65\x6E\x74\x5F\x6C\x6F\x67"; $this->log_count_table = $wpdb->prefix . "\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x6C\x6F\x67\x5F\x63\x6F\x75\x6E\x74"; } public function insert_log($platform_id, $element_ref, $event_trigger, $event_name, $response_message, $sent_data, $method = null, $party = null, $event_order = null) { if (!function_exists("\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x73\x68\x6F\x75\x6C\x64\x5F\x64\x62\x73\x74\x6F\x72\x65\x5F\x65\x76\x65\x6E\x74") || !unipixel_should_dbstore_event($event_name)) { return; } global $wpdb; $platform_name = unipixel_get_platform_name($platform_id);      if (is_string($sent_data)) { $sent_data = json_decode($sent_data, true); } if (is_array($sent_data) && isset($sent_data["\x62\x6F\x64\x79"])) { $raw = $sent_data["\x62\x6F\x64\x79"]; $decoded = json_decode(stripslashes($raw), true); if ($decoded !== null) { $sent_data["\x62\x6F\x64\x79"] = $decoded; } else { $sent_data["\x62\x6F\x64\x79"] = stripslashes($raw); } } if (is_array($sent_data)) { $sent_data = json_encode( $sent_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); }   $log_data = [ 'platform_id' => $platform_id, 'platform_name' => $platform_name, 'element_ref' => $element_ref, 'event_trigger' => $event_trigger, 'event_name' => $event_name, 'response_message' => $response_message, 'sent_data' => $sent_data, ]; $log_format = [ "\x25\x64", "\x25\x73", "\x25\x73", "\x25\x73", "\x25\x73", "\x25\x73", "\x25\x73" ];  if (!is_null($method)) { $log_data["\x6D\x65\x74\x68\x6F\x64"] = $method; $log_format[] = '%s'; } if (!is_null($party)) { $log_data["\x70\x61\x72\x74\x79"] = $party; $log_format[] = '%s'; } if (!is_null($event_order)) { $log_data["\x65\x76\x65\x6E\x74\x5F\x6F\x72\x64\x65\x72"] = $event_order; $log_format[] = '%s'; }  $wpdb->insert($this->log_table, $log_data, $log_format);  $query = $wpdb->prepare( "UPDATE %i SET count = count + 1 WHERE id = %d", $this->log_count_table, 1 ); $wpdb->query($query);  $logTriggerDeleteQty = 50000; $logMinKeepQty = 40000; $logToDeleteQty = 10000; $query = $wpdb->prepare( "SELECT count FROM %i WHERE id = %d", $this->log_count_table, 1 ); $current_count = $wpdb->get_var($query); if ($current_count >= $logTriggerDeleteQty) { $this->cleanup_logs($logMinKeepQty, $logToDeleteQty); } } private function cleanup_logs($logMinKeepQty, $logToDeleteQty) { global $wpdb;   $query = $wpdb->prepare( "SELECT id FROM %i ORDER BY log_time ASC LIMIT %d", $this->log_table, $logToDeleteQty );  $logs_to_delete = $wpdb->get_col($query);  if (!empty($logs_to_delete)) { $placeholders = implode("\x2C", array_fill(0, count($logs_to_delete), "\x25\x64"));  $query = $wpdb->prepare( "DELETE FROM %i WHERE id IN ($placeholders)", $this->log_table, $logs_to_delete );  $wpdb->query($query);   $query = $wpdb->prepare( "SELECT COUNT(*) FROM %i", $this->log_table );  $remaining_logs = $wpdb->get_var($query); $new_count = $remaining_logs > $logMinKeepQty ? $remaining_logs - $logMinKeepQty : 0; $query = $wpdb->prepare(  "UPDATE %i SET count = %d WHERE id = %d", $this->log_count_table, $new_count, 1 );  $wpdb->query($query); } } } 