From 56a9a1ccf764ff7a6af8f8a2292cb07443cb4aa7 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Thu, 28 May 2026 18:19:57 +0000
Subject: [PATCH] =New Gitbit setpu
---
inc/blocks/SummaryBlock.php | 47 +++++++++++++++++++++++++++++++++++++----------
1 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/inc/blocks/SummaryBlock.php b/inc/blocks/SummaryBlock.php
index fd55561..88aaa8c 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,26 @@
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', WEEK_IN_SECONDS);
add_action('init', [ $this, 'registerBlock' ]);
+ add_action('wp_enqueue_scripts', [$this, 'enqueueScripts']);
+ if (JVB_TESTING) {
+ $this->cache->flush();
+ }
}
public function registerBlock()
@@ -34,6 +40,11 @@
]);
}
+ public function enqueueScripts():void
+ {
+ wp_enqueue_script('jvb-page-nav');
+ }
+
protected function getConfig():string
{
return (is_tax()) ? 'tax' : 'content';
@@ -55,7 +66,7 @@
$this->config = $this->getConfig();
$key = $this->generateKey();
$cache = $this->cache->get($key);
- $cache = false;
+
if ($cache) {
return $cache;
}
@@ -66,7 +77,7 @@
);
/**
* The h1 title element, excluding the h1 tag.
- * Can include additonal html (like <small> or <b>)
+ * Can include additional html (like <small> or <b>)
*/
$this->header = apply_filters(
'jvbSummaryHeader',
@@ -83,6 +94,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 +108,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)
@@ -136,6 +158,9 @@
<?php endif; ?>
</header>
<?php
+ if (!empty($this->beforeSummary)) {
+ echo $this->beforeSummary;
+ }
}
protected function renderDetails():void
@@ -146,9 +171,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 +187,7 @@
<?php
}
?>
- </details>
+ </details></section>
<?php
}
@@ -170,7 +196,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 +205,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