| | |
| | | <?php |
| | | namespace JVBase\rest; |
| | | |
| | | use JVBase\Instance; |
| | | use JVBase\integrations\services\Cloudflare; |
| | | use JVBase\managers\Cache; |
| | | use JVBase\managers\Errors; |
| | | use JVBase\meta\Meta; |
| | | use JVBase\registrar\Registrar; |
| | | use JVBase\base\Site; |
| | | use JVBase\rest\routes\TermRoutes; |
| | | use WP_REST_Request; |
| | | use WP_REST_Response; |
| | | use Exception; |
| | |
| | | protected string $namespace = 'jvb/v1'; |
| | | protected ?Cache $cache = null; |
| | | protected string $cacheName = ''; |
| | | protected int $cacheTtl = 3600; |
| | | protected int $cacheTtl = HOUR_IN_SECONDS; |
| | | protected static ?string $action; |
| | | |
| | | public function __construct() |
| | |
| | | /** |
| | | * Convert MySQL datetime to ISO 8601 timestamp |
| | | */ |
| | | protected function formatTimestamp(?string $mysqlDatetime): ?string |
| | | public function formatTimestamp(?string $mysqlDatetime): ?string |
| | | { |
| | | return Response::formatTimestamp($mysqlDatetime); |
| | | } |
| | |
| | | */ |
| | | protected function verifyTurnstile(string $token): bool |
| | | { |
| | | if (!Site::hasIntegration('cloudflare') || !JVB()->connect('cloudflare')->isSetUp()) { |
| | | if (!Site::hasIntegration('cloudflare') || !Cloudflare::getInstance()->isSetUp()) { |
| | | return true; |
| | | } |
| | | |
| | | return !empty($token) && JVB()->connect('cloudflare')->verifyTurnstile($token); |
| | | return !empty($token) && Cloudflare::getInstance()->verifyTurnstile($token); |
| | | } |
| | | |
| | | /** |
| | |
| | | ]); |
| | | |
| | | try { |
| | | JVB()->error()->log('security_audit', $event, $context, 'info'); |
| | | Errors::getInstance()->log('security_audit', $event, $context, 'info'); |
| | | } catch (Exception $e) { |
| | | error_log("Security Audit: {$event} - " . json_encode($context)); |
| | | } |
| | |
| | | protected function logError(string $message, array $context = [], string $severity = 'error'): void |
| | | { |
| | | try { |
| | | JVB()->error()->log(static::class, $message, $context, $severity); |
| | | Errors::getInstance()->log(static::class, $message, $context, $severity); |
| | | } catch (Exception $e) { |
| | | error_log(static::class . " Error: {$message} - " . json_encode($context)); |
| | | } |
| | |
| | | 'name' => $term->name, |
| | | 'slug' => $term->slug, |
| | | 'parent' => $term->parent, |
| | | 'path' => JVB()->routes('term')->getTermPath($term->term_id, $term->name, $taxonomy), |
| | | 'path' => TermRoutes::getInstance()->getTermPath($term->term_id, $term->name, $taxonomy), |
| | | 'taxonomy' => jvbNoBase($term->taxonomy), |
| | | 'count' => $term->count, |
| | | ]; |