Jake Vanderwerf
2026-08-30 a58a2e7ca4700d3e23341fde767060a4c2c704a3
inc/utility/Image.php
@@ -17,18 +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->imgData->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'];
@@ -81,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);
            }
         }
@@ -185,5 +181,16 @@
   {
      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) : '';
         }
      );
   }
}