Clean-room copy of the reusable engines from comiida, with all instance data, secrets, dependencies, and build output excluded: - app/ Astro theme skeleton (no comiida blog posts; hero image -> placeholder) - api/ SeedProject PHP framework (no vendor/.env/config.php) - content-pipeline/ engine only (scripts/admin/prompts; empty runtime state) - astroagent.config.json + app/.astroagent/skills Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SYHWLHihq3v9nxNwoPCKSn
72 lines
3.3 KiB
PHP
72 lines
3.3 KiB
PHP
<?php
|
|
|
|
|
|
class Logger {
|
|
|
|
/*
|
|
* Log Information to Database
|
|
* Auto-populates: host, method, useragent, device_type, browser, os, ipaddress, location.
|
|
* Callers may pass controller/action explicitly.
|
|
*/
|
|
public static function Entry($logData) {
|
|
$ua = $_SERVER['HTTP_USER_AGENT'] ?? '';
|
|
$parsed = self::parseUserAgent($ua);
|
|
|
|
$logData['location'] = $logData['location'] ?? 'na';
|
|
$logData['ipaddress'] = $logData['ipaddress'] ?: ($_SERVER['REMOTE_ADDR'] ?? '');
|
|
$logData['host'] = $_SERVER['HTTP_ORIGIN'] ?? $_SERVER['HTTP_HOST'] ?? '';
|
|
$logData['method'] = $logData['method'] ?? ($_SERVER['REQUEST_METHOD'] ?? '');
|
|
$logData['useragent'] = $logData['useragent'] ?? substr($ua, 0, 512);
|
|
$logData['device_type'] = $logData['device_type'] ?? $parsed['device_type'];
|
|
$logData['browser'] = $logData['browser'] ?? $parsed['browser'];
|
|
$logData['os'] = $logData['os'] ?? $parsed['os'];
|
|
// controller/action passed explicitly by caller
|
|
|
|
return \Db::insert('sp_activitylog', $logData);
|
|
}
|
|
|
|
/*
|
|
* Parse a User-Agent string into device_type, browser, os.
|
|
*/
|
|
private static function parseUserAgent(string $ua): array {
|
|
$u = strtolower($ua);
|
|
|
|
// Device type
|
|
if (preg_match('/tablet|ipad|kindle|playbook|silk|(android(?!.*mobile))/i', $ua)) {
|
|
$device_type = 'tablet';
|
|
} elseif (preg_match('/mobile|iphone|ipod|android.*mobile|blackberry|opera mini|iemobile/i', $ua)) {
|
|
$device_type = 'mobile';
|
|
} else {
|
|
$device_type = 'desktop';
|
|
}
|
|
|
|
// Browser (order matters — Edge/Opera before Chrome/Safari)
|
|
if (str_contains($u, 'edg/') || str_contains($u, 'edge/')) $browser = 'Edge';
|
|
elseif (str_contains($u, 'opr/') || str_contains($u, 'opera')) $browser = 'Opera';
|
|
elseif (str_contains($u, 'chrome') && !str_contains($u, 'chromium')) $browser = 'Chrome';
|
|
elseif (str_contains($u, 'firefox') || str_contains($u, 'fxios')) $browser = 'Firefox';
|
|
elseif (str_contains($u, 'safari') && !str_contains($u, 'chrome')) $browser = 'Safari';
|
|
elseif (str_contains($u, 'msie') || str_contains($u, 'trident')) $browser = 'IE';
|
|
else $browser = 'Other';
|
|
|
|
// OS
|
|
if (str_contains($u, 'iphone') || str_contains($u, 'ipod')) $os = 'iOS';
|
|
elseif (str_contains($u, 'ipad')) $os = 'iPadOS';
|
|
elseif (str_contains($u, 'android')) $os = 'Android';
|
|
elseif (str_contains($u, 'windows')) $os = 'Windows';
|
|
elseif (str_contains($u, 'macintosh') || str_contains($u, 'mac os x')) $os = 'macOS';
|
|
elseif (str_contains($u, 'cros')) $os = 'ChromeOS';
|
|
elseif (str_contains($u, 'linux')) $os = 'Linux';
|
|
else $os = 'Other';
|
|
|
|
return compact('device_type', 'browser', 'os');
|
|
}
|
|
|
|
/*
|
|
* Log Information to a File
|
|
*/
|
|
public static function LogtoFile($string){
|
|
error_log($string, 0);
|
|
}
|
|
|
|
} // End Class
|