From 18e7e415339ccc9adf8ade562f93abef606da16d Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 26 Aug 2026 22:24:18 +0000
Subject: [PATCH] =Cache::connects throughout codebase refactored

---
 inc/blocks/SummaryBlock.php |   68 ++++++++++++++++++++++-----------
 1 files changed, 45 insertions(+), 23 deletions(-)

diff --git a/inc/blocks/SummaryBlock.php b/inc/blocks/SummaryBlock.php
index 7e92262..9ea9fd8 100644
--- a/inc/blocks/SummaryBlock.php
+++ b/inc/blocks/SummaryBlock.php
@@ -1,7 +1,7 @@
 <?php
 namespace JVBase\blocks;
 
-use JVBase\managers\CacheManager;
+use JVBase\managers\Cache;
 use JVBase\forms\TaxonomySelector;
 use WP_Block;
 
@@ -11,20 +11,24 @@
 
 class SummaryBlock
 {
-    protected CacheManager $cache;
+    protected Cache $cache;
     protected string $config;
     protected string $type;
     protected string $path = JVB_DIR . '/build/summary';
     protected string $image;
     protected string $header;
     protected string $headerExtra;
+	protected bool $isOpen = false;
+    protected string $beforeSummary;
     protected string $detailsTitle;
     protected array $details;
 
     public function __construct()
     {
-        $this->cache = CacheManager::for('summary_block', WEEK_IN_SECONDS);
+        $this->cache = Cache::for('summary_block', 'post', WEEK_IN_SECONDS);
         add_action('init', [ $this, 'registerBlock' ]);
+		add_action('wp_enqueue_scripts', [$this, 'enqueueScripts']);
+
     }
 
     public function registerBlock()
@@ -34,28 +38,30 @@
         ]);
     }
 
+	public function enqueueScripts():void
+	{
+		wp_enqueue_script('jvb-page-nav');
+	}
+
     protected function getConfig():string
     {
         return (is_tax()) ? 'tax' : 'content';
     }
 
-    protected function generateKey():string
-    {
-        $obj = get_queried_object();
-        return match (true) {
-            is_tax() => jvbNoBase($obj->taxonomy) . $obj->term_id,
-            is_a($obj, 'WP_Post_type') => jvbNoBase($obj->name),
-            is_a($obj, 'WP_User') => jvbUserRole($obj->ID),
-            default => jvbNoBase($obj->post_type) . $obj->ID,
-        };
-    }
-
     public function render(array $attributes, string $content, WP_Block $block)
     {
         $this->config = $this->getConfig();
-        $key = $this->generateKey();
-        $cache = $this->cache->get($key);
-        $cache = false;
+
+		if (is_tax()) {
+			$this->cache = Cache::for('summary_tax', 'term', WEEK_IN_SECONDS);
+		} elseif (is_author()) {
+			$this->cache = Cache::for('summary_auth', 'user', WEEK_IN_SECONDS);
+		} else {
+			$this->cache = Cache::for('summary_post', 'post', WEEK_IN_SECONDS);
+		}
+
+        $cache = $this->cache->get(get_queried_object_id());
+
         if ($cache) {
             return $cache;
         }
@@ -83,6 +89,11 @@
         );
         $this->headerExtra = ($headerExtra === '') ? '' : '<div>'.$headerExtra.'</div>';
 
+		$this->beforeSummary = apply_filters(
+			'jvbBeforeSummary',
+			'',
+			$this->getType()
+		);
         /**
          * The HTML string that appears within the <summary> block
          */
@@ -92,6 +103,12 @@
             $this->getType()
         );
 
+		$this->isOpen = apply_filters(
+			'jvbSummaryIsOpen',
+			false,
+			$this->getType()
+		);
+
         /**
          * The content of the <details> block.
          * This should return either an empty array for no information (so no details block)
@@ -108,7 +125,7 @@
         ob_start();
         $this->renderBlock();
         $content = ob_get_clean();
-        $this->cache->set($key, $content);
+        $this->cache->set(get_queried_object_id(), $content);
         return $content;
     }
 
@@ -136,6 +153,9 @@
             <?php endif; ?>
         </header>
         <?php
+		if (!empty($this->beforeSummary)) {
+			echo $this->beforeSummary;
+		}
     }
 
     protected function renderDetails():void
@@ -146,9 +166,10 @@
         if (empty($details)) {
             return;
         }
+		$open = $this->isOpen ? ' open' : '';
         ?>
-        <details class="info">
-            <summary class="row btw"><?= $this->detailsTitle ?></summary>
+        <section><details class="info"<?=$open?>>
+            <summary class="row x-btw"><?= $this->detailsTitle ?></summary>
             <?php
             foreach ($this->details as $key => $details) {
                 if ($details === '') {
@@ -161,7 +182,7 @@
             <?php
             }
             ?>
-        </details>
+        </details></section>
         <?php
     }
 
@@ -170,7 +191,8 @@
         if (empty($this->details)) {
             return;
         }
-        echo jvbOnThisPage(array_keys($this->details));
+		$IDs = apply_filters('jvbSummaryOnThisPage', array_keys($this->details), $this->getType());
+        echo jvbOnThisPage($IDs);
     }
 
     protected function getType():string
@@ -178,7 +200,7 @@
         if (empty($this->type)) {
             $this->type = match (true) {
                 is_tax()                => jvbNoBase(get_queried_object()->taxonomy),
-                is_post_type_archive()  => jvbNoBase(get_post_type()),
+                is_post_type_archive()  => jvbNoBase(get_queried_object()->name),
                 default                 => jvbNoBase(get_queried_object()->post_type),
             };
         }

--
Gitblit v1.10.0