aiautotool_logall = get_option('aiautotool_logall', array()); } public function set_log($log_type, $data) { $time = current_time('mysql'); if (!isset($this->aiautotool_logall[$log_type])) { $this->aiautotool_logall[$log_type] = array(); } $this->aiautotool_logall[$log_type][] = array( 'time' => $time, 'data' => $data, ); update_option('aiautotool_logall', $this->aiautotool_logall); } public function get_log($log_type = '') { if (empty($log_type)) { return $this->aiautotool_logall; } if (isset($this->aiautotool_logall[$log_type])) { return $this->aiautotool_logall[$log_type]; } return array(); } private function sort_logs_by_time($logs) { // Sử dụng array_multisort để sắp xếp mảng theo thời gian giảm dần array_multisort(array_column($logs, 'time'), SORT_DESC, $logs); return $logs; } private function display_table($data) { if (!is_object($data)) { return ''; // Nếu không phải là đối tượng, trả về chuỗi trống } $table_html = '
'; // Duyệt qua thuộc tính của đối tượng và thêm vào table foreach ($data as $key => $value) { $key_label = '' . esc_html($key) . ''; if($key == 'post_id'){ $permalink = get_permalink($value); $value_html = '' . esc_html($value) . ' '; } else if($key == 'post_title'){ $value_html = '' . esc_html($value) . ''; } else { $value_html = '' . esc_html($value) . ''; } $table_html .= '
'; $table_html .= $key_label . ': ' . $value_html; $table_html .= '
'; } $table_html .= '
'; return $table_html; } public function show_log($log_type) { // Lấy mảng log_type tương ứng $logs = $this->get_log($log_type); $logs = $this->sort_logs_by_time($logs); // Hiển thị bảng log echo ''; echo ''; echo ''; // Hiển thị từng dòng log if (empty($logs)) { echo ''; } else { foreach ($logs as $log) { echo ''; echo ''; echo ''; echo ''; } } echo '
TimeData
'; echo esc_html__('No logs available', 'ai-auto-tool'); echo '
' . esc_html($log['time']) . '' . $this->display_table((Object)$log['data']) . '
'; } }