v-wordpress-plugin-updater/update-api/classes/LogsHelper.php
nikolai@vontainment.com 2620afcead modified: .gitattributes
modified:   .gitignore
	modified:   LICENSE
	modified:   README.md
	modified:   update-api/classes/HomeHelper.php
	modified:   update-api/classes/LogsHelper.php
	modified:   update-api/classes/PlHelper.php
	modified:   update-api/classes/ThHelper.php
	renamed:    update-api/classes/SecurityHandler.php -> update-api/classes/UtilityHandler.php
	modified:   update-api/config.php
	modified:   update-api/lib/auth-lib.php
	modified:   update-api/lib/load-lib.php
	modified:   update-api/public/.htaccess
	modified:   update-api/public/api.php
	modified:   update-api/public/assets/css/styles.css
	modified:   update-api/public/assets/js/header-scripts.js
	modified:   update-api/public/index.php
	modified:   update-api/public/login.php
	modified:   update-api/public/robots.txt
2025-07-05 04:30:19 -04:00

68 lines
2.5 KiB
PHP

<?php
// @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
/*
* Project: Update API
* Author: Vontainment
* URL: https://vontainment.com
* File: LogsHelper.php
* Description: WordPress Update API Helper for logs display and processing
*/
class LogsHelper
{
public static function processLogFile(string $logFile): string
{
$log_file_path = LOG_DIR . "/$logFile";
$output = '';
if (file_exists($log_file_path)) {
$log_array = file($log_file_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$log_by_domain = [];
foreach ($log_array as $entry) {
list($domain, $date, $status) = explode(' ', $entry);
$log_by_domain[$domain] = [
'date' => $date,
'status' => $status,
];
}
ob_start();
echo '<div class="log-row">';
foreach ($log_by_domain as $domain => $entry) {
$date_diff = (strtotime(date('Y-m-d')) - strtotime($entry['date'])) / (60 * 60 * 24);
$classes = '';
if ($entry['status'] == 'Failed') {
$classes .= ' error';
} elseif ($entry['status'] == 'Success') {
$classes .= ' success';
}
if ($date_diff > 30) {
$classes .= ' lost';
}
$classes = trim($classes);
echo '<div class="log-sub-box' . ($classes ? " $classes" : '') . '">';
echo '<h3>' . htmlspecialchars($domain, ENT_QUOTES, 'UTF-8') . '</h3>';
if ($entry['status'] == 'Failed') {
echo '<p class="log-entry" style="color:red;">' .
htmlspecialchars($entry['date'], ENT_QUOTES, 'UTF-8') . ' ' .
htmlspecialchars($entry['status'], ENT_QUOTES, 'UTF-8') .
'</p>';
} else {
echo '<p class="log-entry" style="color:green;">' .
htmlspecialchars($entry['date'], ENT_QUOTES, 'UTF-8') . ' ' .
htmlspecialchars($entry['status'], ENT_QUOTES, 'UTF-8') .
'</p>';
}
echo '</div>';
}
echo '</div>';
$output = ob_get_contents();
ob_end_clean();
return $output;
} else {
return 'Log file not found.';
}
}
}