From ccf5e61a075c35d24befc175994b5cb8957ca322 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 26 Aug 2026 21:45:53 +0000
Subject: [PATCH] =Extra JVB() calls replaced, minor tweaks

---
 inc/utility/Image.php |   56 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 48 insertions(+), 8 deletions(-)

diff --git a/inc/utility/Image.php b/inc/utility/Image.php
index 83b95e7..23e2844 100644
--- a/inc/utility/Image.php
+++ b/inc/utility/Image.php
@@ -17,17 +17,14 @@
 
 	public function __construct()
 	{
-		$this->cache = Cache::for('images')->connect('post');
-		$this->imgData = Cache::for('imageData')->connect('post');
-		if (JVB_TESTING) {
-			$this->cache->flush();
-		}
+		$this->cache = Cache::for('images', 'post');
+		$this->imgData = Cache::for('imageData', 'post');
 	}
 
 	public function formatImage(int $ID, string $start = 'tiny', string $replace = 'large', bool $addLink = true, ?string $postSlug = null):string
 	{
 		$return = $this->cache->remember(
-			$this->cache->generateKey(['ID' => $ID, 'start' => $start, 'replace' => $replace]),
+			['ID' => $ID, 'start' => $start, 'replace' => $replace],
 			function() use ($ID, $start, $replace) {
 				// Define size order for progressive enhancement
 				$sizeOrder = ['tiny', 'directory-preview', 'thumbnail', 'medium', 'large', 'full'];
@@ -80,7 +77,7 @@
 					$postSlug = jvbNoBase($tax->taxonomy);
 				}elseif (is_post_type_archive()) {
 					$obj = get_queried_object();
-					$postSlug = jvbNoBase($obj->post_type);
+					$postSlug = jvbNoBase($obj->name);
 				}
 
 			}
@@ -95,7 +92,7 @@
 				$postSlug,
 				$postSlug,
 				$imgSlug,
-				$full[0]
+				$full[0]??''
 			);
 
 			// Add gallery attributes to img tag
@@ -153,4 +150,47 @@
 			}
 		);
 	}
+
+	public static function getData(int $imgID):array
+	{
+		return (new Image)->getImageData($imgID);
+	}
+
+	public static function gallery(string $ids, ?string $type = null):string
+	{
+		$ids = explode(',', $ids);
+		$inner = implode('', array_map(function ($ID) {
+			$caption = wp_get_attachment_caption($ID);
+			if (!empty($caption)) {
+				$caption = sprintf('<figcaption>%s</figcaption', $caption);
+			}
+			return sprintf(
+				'<li><figure>%s%s</figure></li>',
+				self::image($ID),
+				$caption
+			);
+		}, $ids));
+		return sprintf(
+			'<ul class="gallery%s">%s</ul>',
+			$type? ' '.$type : '',
+			$inner
+		);
+	}
+
+	public static function image(int $id, string $start = 'tiny', string $replace = 'large', bool $addLink = true, ?string $postSlug = null):string
+	{
+		return (new Image)->formatImage($id, $start, $replace, $addLink, $postSlug);
+	}
+	public static function SVG(string $slug):string
+	{
+		$cache = Cache::for('svgs');
+
+		return $cache->remember(
+			$slug,
+			function() use ($slug) {
+				$filename = JVB_CHILD_DIR.'/assets/icons/'.$slug.'.svg';
+				return file_exists($filename) ? file_get_contents($filename) : '';
+			}
+		);
+	}
 }

--
Gitblit v1.10.0