From a9654f00c8fbc9934289d761843ddd071025013f Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Fri, 28 Aug 2026 17:20:28 +0000
Subject: [PATCH] =PHPStorm Code Inspection: fixed class reference errors (from getting rid of JVB() and replacing with direct class::getInstance; as well as general code sniffing, etc
---
inc/blocks/SummaryBlock.php | 66 +++++++++++++++++++++-----------
1 files changed, 43 insertions(+), 23 deletions(-)
diff --git a/inc/blocks/SummaryBlock.php b/inc/blocks/SummaryBlock.php
index 6fc6da2..47b2713 100644
--- a/inc/blocks/SummaryBlock.php
+++ b/inc/blocks/SummaryBlock.php
@@ -1,8 +1,7 @@
<?php
namespace JVBase\blocks;
-use JVBase\managers\CacheManager;
-use JVBase\forms\TaxonomySelector;
+use JVBase\managers\Cache;
use WP_Block;
if (!defined('ABSPATH')) {
@@ -11,20 +10,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 +37,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();
- $this->cache->clear();
- $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;
@@ -84,6 +88,11 @@
);
$this->headerExtra = ($headerExtra === '') ? '' : '<div>'.$headerExtra.'</div>';
+ $this->beforeSummary = apply_filters(
+ 'jvbBeforeSummary',
+ '',
+ $this->getType()
+ );
/**
* The HTML string that appears within the <summary> block
*/
@@ -93,6 +102,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)
@@ -109,7 +124,7 @@
ob_start();
$this->renderBlock();
$content = ob_get_clean();
- $this->cache->set($key, $content);
+ $this->cache->set(get_queried_object_id(), $content);
return $content;
}
@@ -137,6 +152,9 @@
<?php endif; ?>
</header>
<?php
+ if (!empty($this->beforeSummary)) {
+ echo $this->beforeSummary;
+ }
}
protected function renderDetails():void
@@ -147,9 +165,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 === '') {
@@ -162,7 +181,7 @@
<?php
}
?>
- </details>
+ </details></section>
<?php
}
@@ -171,7 +190,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