From 58e8ae0759ccfa97c478ccae4e0778bdce70966f Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Thu, 22 Jan 2026 22:40:02 +0000
Subject: [PATCH] =DirectoryManager.php updates, some javascript tweaks for CRUD.js, and minor style changes

---
 inc/rest/RestRouteManager.php |   48 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 47 insertions(+), 1 deletions(-)

diff --git a/inc/rest/RestRouteManager.php b/inc/rest/RestRouteManager.php
index 3d9b2a4..37db58e 100644
--- a/inc/rest/RestRouteManager.php
+++ b/inc/rest/RestRouteManager.php
@@ -1,6 +1,8 @@
 <?php
 namespace JVBase\rest;
 
+use DateTime;
+use DateTimeZone;
 use JVBase\JVB;
 use JVBase\rest\RateLimiter;
 use JVBase\managers\OperationQueue;
@@ -128,6 +130,32 @@
 		return true;
 	}
 
+	/**
+	 * Convert MySQL datetime to ISO 8601 timestamp with proper timezone
+	 */
+	public function formatTimestamp(?string $mysql_datetime): ?string
+	{
+		if (empty($mysql_datetime)) {
+			return null;
+		}
+
+		try {
+			// Get WordPress timezone - dates are stored in this timezone
+			$wp_timezone = wp_timezone();
+
+			// Parse the datetime in WordPress timezone
+			$date = new DateTime($mysql_datetime, $wp_timezone);
+
+			// Convert to UTC for API consistency
+			$date->setTimezone(new DateTimeZone('UTC'));
+
+			// Return ISO 8601 format
+			return $date->format('c');
+		} catch (Exception $e) {
+			return null;
+		}
+	}
+
 	protected function checkContent(string $content, bool $bool = false):string|bool
 	{
 		$result = JVB_CONTENT[$content]??JVB_TAXONOMY[$content]??JVB_USER[$content]??'';
@@ -316,7 +344,12 @@
                     $args['orderby'] = 'meta_value_num';
                     break;
                 default:
-                    $args['orderby'] = 'date';
+					if ($this->isTimeline($args, $data)) {
+						$args['meta_key'] = BASE . 'latest_date';
+						$args['orderby'] = 'meta_value_num';
+					}else {
+						$args['orderby'] = 'date';
+					}
             }
         }
 		$order = (array_key_exists('order', $data)) ? strtoupper($data['order']) : 'DESC';
@@ -325,6 +358,17 @@
         return $args;
     }
 
+	protected function isTimeline($args, $data):bool
+	{
+		$post_types = is_array($args['post_type']) ? $args['post_type'] : [$args['post_type']];
+		foreach ($post_types as $type) {
+			if (Features::forContent($type)->has('is_timeline')) {
+				return true;
+			}
+		}
+		return false;
+	}
+
     protected function applyDateFilters(array $args, array $data):array
     {
         if (!array_key_exists('date-filter', $data) && !array_key_exists('dateFrom', $data)) {
@@ -541,6 +585,7 @@
 	protected function error(string $message, string $code, int $status = 400, ?string $field = null): WP_REST_Response
 	{
 		$data = [
+			'success'	=> false,
 			'message' => $message,
 			'code' => $code
 		];
@@ -556,6 +601,7 @@
 	 */
 	protected function success(array $data, int $status = 200): WP_REST_Response
 	{
+		$data['success'] = true;
 		return new WP_REST_Response($data, $status);
 	}
 

--
Gitblit v1.10.0