From 3baf3d2545ba6ece6b74a64c0def59bd0774cf54 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 10 Jun 2026 16:34:12 +0000
Subject: [PATCH] =Laid the groundwork for an improved DashboardManager.php setup. Have to put it aside so I can get the dang Northeh done though.

---
 inc/helpers/formatting.php |  110 +++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 70 insertions(+), 40 deletions(-)

diff --git a/inc/helpers/formatting.php b/inc/helpers/formatting.php
index 4ac5520..d294044 100644
--- a/inc/helpers/formatting.php
+++ b/inc/helpers/formatting.php
@@ -1,5 +1,9 @@
 <?php
 
+use JVBase\managers\Cache;
+use JVBase\meta\Meta;
+use JVBase\utility\Image;
+
 if (!defined('ABSPATH')) {
 	exit;
 }
@@ -37,6 +41,9 @@
 {
     $count = count($arr);
     $and = ($and) ? ' and ' : ' or ';
+	if (empty($arr)){
+		return '';
+	}
     switch ($count) {
         case '1':
             return implode(',', $arr);
@@ -65,40 +72,38 @@
 
 /**
  * @param int $ID
- * @param JVBase\meta\MetaManager|null $meta
- *
+ * @param string $type 'post', 'user', or 'term'
  * @return string
  */
-function jvbFormatRating(int $ID, JVBase\meta\MetaManager|null $meta = null):string
+function jvbFormatRating(int $ID, string $type = 'post'):string
 {
-    $cache = new JVBase\managers\CacheManager('bio-'.$ID, WEEK_IN_SECONDS);
-    $key = 'rating';
-    $cached = $cache->get($key);
-    $cached = false;
+    $cache = Cache::for('rating', WEEK_IN_SECONDS)->connect('post')->connect('taxonomy')->connect('user');
+
+    $cached = $cache->get($ID);
     if ($cached) {
         return $cached;
     }
 
-    if (!$meta) {
-        if (term_exists((int)$ID)) {
-            $type = 'term';
-        } elseif (get_post_status((int)$ID)) {
-            $type = 'post';
-        } else {
-            $type = 'user';
-        }
-        $meta = new JVBase\meta\MetaManager($ID, $type);
-    }
+	$meta = match ($type) {
+		'term' => Meta::forTerm($ID),
+		'post'	=> Meta::forPost($ID),
+		'user'	=> Meta::forUser($ID),
+		default => false
+	};
+	if (!$type) {
+		return '';
+	}
+
 
     $out = '';
-    $avg = $meta->getValue('average_rating');
+    $avg = $meta->get('average_rating');
 
-    $total = $meta->getValue('total_ratings');
+    $total = $meta->get('total_ratings');
     if ($avg !== 'none') {
         $out .= jvbFormatStarRating($avg, (int)$total);
     }
 
-    $cache->set($key, $out);
+    $cache->set($ID, $out);
     return $out;
 }
 
@@ -135,26 +140,8 @@
  */
 function jvbImageData(int $imgID):array
 {
-    $cache = new JVBase\managers\CacheManager('image_data', WEEK_IN_SECONDS);
-    $cached = $cache->get($imgID);
-    if ($cached) {
-        return $cached;
-    }
-
-    if (!wp_get_attachment_image($imgID, 'tiny')) {
-        return [];
-    }
-    $image = [
-        'tiny' => wp_get_attachment_image_src($imgID, 'tiny')[0],
-        'small' => wp_get_attachment_image_src($imgID, 'medium')[0],
-        'medium' => wp_get_attachment_image_src($imgID, 'large')[0],
-        'large' => wp_get_attachment_image_src($imgID, 'full')[0],
-        'alt'   => get_post_meta($imgID, '_wp_attachment_image_alt', true),
-		'title'	=> get_the_title($imgID),
-		'caption' => get_the_excerpt($imgID),
-    ];
-    $cache->set($imgID, $image);
-    return $image;
+	$image = new Image();
+	return $image->getImageData($imgID);
 }
 
 
@@ -193,3 +180,46 @@
 	list($dollars, $cents) = explode('.', $number);
 	return '$'.$dollars.'.<span>'.$cents.'</span>';
 }
+
+function jvbMailToLink(string $emailTo,
+					   string $subject = 'Contact from Website',
+					   string $message = '',
+					   bool $icon = true,
+					   ?string $linkText = null
+):string
+{
+	if (!is_email($emailTo)) {
+		return '';
+	}
+	$link = 'mailto:'.$emailTo.'?subject='.rawurlencode($subject);
+	if ($message !== '') {
+		$link .= '&body='.rawurlencode($message);
+	}
+	return $link;
+}
+function jvbTextLink(int $phoneNumber, string $message=''):string
+{
+	$length =strlen((string)$phoneNumber);
+	if ($length < 10 || $length > 10) {
+		return '';
+	}
+	$link = 'sms:+1'.$phoneNumber;
+	if ($message !== '') {
+		$link .= '?body='.rawurlencode($message);
+	}
+	return $link;
+}
+
+function jvbPhoneLink(int $phoneNumber):string
+{
+	$length =strlen((string)$phoneNumber);
+	if ($length < 10 || $length > 10) {
+		return '';
+	}
+	return 'tel:+1'.$phoneNumber;
+}
+
+function jvbFormatString(string $string):string
+{
+	return html_entity_decode($string);
+}

--
Gitblit v1.10.0