From a24a06002081ad71a78ffeff9072725ba39cf121 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 17 Feb 2026 20:05:31 +0000
Subject: [PATCH] =minor changes, particularly around the JVB_CHILD_URL pattern

---
 inc/rest/routes/ContentRoutes.php |   88 ++++++++++++++++++++++++++++++++++++++------
 1 files changed, 76 insertions(+), 12 deletions(-)

diff --git a/inc/rest/routes/ContentRoutes.php b/inc/rest/routes/ContentRoutes.php
index 119b3a1..0b9cea6 100644
--- a/inc/rest/routes/ContentRoutes.php
+++ b/inc/rest/routes/ContentRoutes.php
@@ -76,10 +76,28 @@
 		Route::for('content')
 			->get([$this, 'getContent'])
 			->auth(PermissionHandler::combine(['user', 'nonce', ['actionNonce'=>'dash-']]))
+			->args([
+				'content' => 'string|required',
+				'status' => 'string|default:all',
+				'page' => 'integer|default:1|min:1',
+				'per_page' => 'integer|default:30|min:1|max:100',
+				'orderby' => 'string|enum:date,alphabetical|default:date',
+				'order' => 'string|enum:asc,desc|default:desc',
+				'search' => 'string',
+				'date-filter' => 'string',
+				'dateFrom' => 'string',
+				'dateTo' => 'string',
+			])
 			->rateLimit(20)
 			->post([$this, 'postContent'])
 			->auth(PermissionHandler::combine(['user', 'nonce', ['actionNonce'=>'dash-']]))
-			->rateLimit(30);
+			->rateLimit(30)
+			->args([
+				'user'	=> 'int|required',
+				'posts' => 'required',
+				'content' => 'string',
+			])
+			->register();
 	}
 
 	protected function initTimelineFields(string $content): void
@@ -151,6 +169,7 @@
 			return Response::success(['message'=>'No posts found in request']);
 		}
 
+
 		$count = count($data['posts']);
 		$operationId = $data['id'];
 		unset($data['user']);
@@ -410,6 +429,7 @@
 			return $this->formatTimeline($post);
 		}
 		$this->meta = Meta::forPost($post->ID);
+		$fields = ($fields) ? $this->meta->getAll() : [];
 		$data = [
 			'id' => $post->ID,
 			'title' => $post->post_title,
@@ -420,7 +440,7 @@
 			'alt' => get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true),
 			'icon' => $this->post_type,
 			'taxonomies' => [],
-			'fields' => ($fields) ? $this->meta->getAll() : [],
+			'fields' => $fields,
 			'images' => [],
 		];
 
@@ -455,25 +475,69 @@
 		$images = [];
 		$get = [];
 		$fields = (empty($fields)) ? $this->fields : $fields;
-		foreach ($fields as $field => $config) {
-			if ($config['type'] === 'gallery' || $config['type'] === 'image' || $field === 'post_thumbnail') {
-				$get[] = $field;
-			}
-		}
+		$get = $this->getUploadFields($fields);
+
 
 		if (!empty($get)) {
-			$allImages = $this->meta->getAll($get);
+			$actualGet = array_map(function($fieldName) {
+				return (str_contains($fieldName, ':')) ? strtok($fieldName, ':') : $fieldName;
+			}, $get);
+			$complex = array_map(function($item) {
+				return explode(':', $item);
+			},array_filter($get, function($fieldName) {
+				return str_contains($fieldName, ':');
+			}));
+
+			$allImages = $this->meta->getAll($actualGet);
 			foreach ($allImages as $k => $imgs) {
-				$temp = explode(',', $imgs);
-				foreach ($temp as $img) {
-					if (is_numeric($img) && !array_key_exists($img, $images)) {
-						$images[$img] = jvbImageData((int)$img);
+				//It's a complex field
+				if (is_array($imgs)) {
+					foreach ($imgs as $row) {
+						foreach ($row as $fName => $fValue) {
+							foreach ($complex as $c) {
+								if (in_array($k, $c)) {
+									foreach ($c as $complexField) {
+										if ($complexField === $fName) {
+											$images = $this->addImages($fValue, $images);
+										}
+									}
+								}
+							}
+						}
 					}
+				} else {
+					$images = $this->addImages($imgs, $images);
 				}
 			}
 		}
 		return $images;
 	}
+	public function addImages(string $imgs, array $images):array
+	{
+		$temp = explode(',', $imgs);
+		foreach ($temp as $img) {
+			if (is_numeric($img) && !array_key_exists($img, $images)) {
+				$images[$img] = jvbImageData((int)$img);
+			}
+		}
+		return $images;
+	}
+	public function getUploadFields($fields):array
+	{
+		$get = [];
+		foreach ($fields as $field => $config) {
+			if (in_array($config['type'], ['group', 'repeater'])) {
+				$nestedUploads = $this->getUploadFields($config['fields']);
+				foreach ($nestedUploads as $nested) {
+					$get[] = $field.':'.$nested;
+				}
+			} elseif ($config['type'] === 'upload' || $config['type'] === 'gallery' || $config['type'] === 'image' ) {
+				$get[] = $field;
+			}
+		}
+
+		return $get;
+	}
 
 	public function formatTimeline(WP_Post $post): array
 	{

--
Gitblit v1.10.0