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/blocks/SummaryBlock.php |   63 ++++++++++++++++++++-----------
 1 files changed, 41 insertions(+), 22 deletions(-)

diff --git a/inc/blocks/SummaryBlock.php b/inc/blocks/SummaryBlock.php
index c236a7c..9ea9fd8 100644
--- a/inc/blocks/SummaryBlock.php
+++ b/inc/blocks/SummaryBlock.php
@@ -18,16 +18,17 @@
     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 = Cache::for('summary_block', WEEK_IN_SECONDS);
+        $this->cache = Cache::for('summary_block', 'post', WEEK_IN_SECONDS);
         add_action('init', [ $this, 'registerBlock' ]);
-		if (JVB_TESTING) {
-			$this->cache->flush();
-		}
+		add_action('wp_enqueue_scripts', [$this, 'enqueueScripts']);
+
     }
 
     public function registerBlock()
@@ -37,27 +38,29 @@
         ]);
     }
 
+	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);
+
+		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;
@@ -86,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
          */
@@ -95,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)
@@ -111,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;
     }
 
@@ -139,6 +153,9 @@
             <?php endif; ?>
         </header>
         <?php
+		if (!empty($this->beforeSummary)) {
+			echo $this->beforeSummary;
+		}
     }
 
     protected function renderDetails():void
@@ -149,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 === '') {
@@ -164,7 +182,7 @@
             <?php
             }
             ?>
-        </details>
+        </details></section>
         <?php
     }
 
@@ -173,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

--
Gitblit v1.10.0