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/CustomBlocks.php | 113 ++++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 80 insertions(+), 33 deletions(-)
diff --git a/inc/blocks/CustomBlocks.php b/inc/blocks/CustomBlocks.php
index 0817591..123b707 100644
--- a/inc/blocks/CustomBlocks.php
+++ b/inc/blocks/CustomBlocks.php
@@ -1,14 +1,12 @@
<?php
namespace JVBase\blocks;
-use DateTime;
use DOMDocument;
+use JVBase\Instance;
use JVBase\managers\Cache;
-use JVBase\managers\LoginManager;
+use JVBase\managers\Login;
use JVBase\managers\SEO\BreadcrumbManager;
-use JVBase\managers\SEO\render\Thing\CreativeWork\MediaObject\VideoObject;
use JVBase\utility\Image;
-use JVBase\utility\Video;
use WP_Block;
use WP_Query;
@@ -18,24 +16,24 @@
class CustomBlocks
{
+ use Instance;
protected Cache $cache;
protected static ?WP_Query $currentLoop = null;
protected static ?int $currentQueryId = null;
protected static array $counters = [];
protected static ?WP_Query $originalQuery = null;
- protected array $ignore = ['align','alt','area','aspectRatio','backgroundColor','borderColor','buttonText','buttonPosition','buttonUseIcon','categories','className','columns','contentPosition','customOverlayColor','dimRatio','displayAsDropdown','displayAuthor','displayFeaturedImage','displayPostContent','displayPostContentRadio','displayPostDate','excerptLength','featuredImageAlign','fontSize','gradient','hasFixedLayout','hasParallax','height','iconColor','iconColorValue','iconColorValue','iconBackgroundColor','iconBackgroundColorValue','id','imageFill','isDark','isLink','isObjectPosition','isRepeated','isSearchFieldHidden','isStackedOnMobile','isUserOverlayColor','kind','label','largestFontSize','layout','lightbox','linkDestination','linkTo','level','mediaId','mediaLink','mediaPosition','mediaSizeSlug','mediaType','mediaWidth','metadata','minHeight','minHeightUnit','opacity','opensInNewTab','order','orderBy','ordered','overlayColor','overlayMenu','placeholder','postLayout','postsToShow','query', 'queryId','ref','rel','scale','shouldSyncIcon','showContent','showEmpty','showHierarchy','showLabel','showLabels','showOnlyTopLevel','showPostCounts','showTagCounts','size','sizeSlug','slug','smallestFontSize','tagName','taxonomy','term','textAlign','textColor','theme','title','type','url','useFeaturedImage','verticalAlignment','width','widthUnit',];
+ protected array $ignore = ['align','alt','area','aspectRatio','backgroundColor','borderColor','buttonText','buttonPosition','buttonUseIcon','categories','className','columns','contentPosition','customOverlayColor','datetime','dimRatio','displayAsDropdown','displayAuthor','displayFeaturedImage','displayPostContent','displayPostContentRadio','displayPostDate','excerptLength','featuredImageAlign','fontSize','gradient','hasFixedLayout','hasParallax','height','iconColor','iconColorValue','iconColorValue','iconBackgroundColor','iconBackgroundColorValue','id','imageFill','isDark','isLink','isObjectPosition','isRepeated','isSearchFieldHidden','isStackedOnMobile','isUserOverlayColor','kind','label','largestFontSize','layout','lightbox','linkDestination','linkTo','level','mediaId','mediaLink','mediaPosition','mediaSizeSlug','mediaType','mediaWidth','metadata','minHeight','minHeightUnit','opacity','opensInNewTab','order','orderBy','ordered','overlayColor','overlayMenu','placeholder','postLayout','postsToShow','query', 'queryId','ref','rel','scale','shouldSyncIcon','showContent','showEmpty','showHierarchy','showLabel','showLabels','showOnlyTopLevel','showPostCounts','showTagCounts','size','sizeSlug','slug','smallestFontSize','tagName','taxonomy','term','textAlign','textColor','theme','title','type','url','useFeaturedImage','verticalAlignment','width','widthUnit',];
//For custom style output for nested links, etc
protected static array $pendingStyles = [];
protected static array $pendingClass = [];
protected static bool $renderGallery = false;
- public function __construct()
+ private function __construct()
{
- $this->cache = Cache::for('blocks', WEEK_IN_SECONDS);
- $this->cache->connect('post')->connect('taxonomy');
- $this->cache->flush();
+// $this->cache = Cache::for('blocks', null,WEEK_IN_SECONDS);
+
add_filter('pre_render_block', [$this, 'prerender'], 10, 3);
add_filter('render_block', [$this, 'render'], 10, 2);
@@ -88,10 +86,34 @@
'label' => __('With Logo', 'jvb')
]
);
+ register_block_style(
+ 'core/gallery',
+ [
+ 'name' =>'hexagon',
+ 'label' => __('Hexagonal', 'jvb')
+ ]
+ );
+ register_block_style(
+ 'core/gallery',
+ [
+ 'name' =>'diamond',
+ 'label' => __('Diamond', 'jvb')
+ ]
+ );
+ register_block_style(
+ 'core/gallery',
+ [
+ 'name' =>'cut',
+ 'label' => __('Cut Corners', 'jvb')
+ ]
+ );
}
protected function checkMethods(?string $content, array $block, ?WP_Block $parent = null, bool $isPrerender = false):?string
{
$blockName = $this->sanitizeBlockName($block);
+ if (str_starts_with($blockName, 'woocommerce')) {
+ return $content;
+ }
$base = ($isPrerender) ? 'prerender_' : 'render_';
$method = $base.$blockName;
@@ -103,7 +125,7 @@
$content = $this->$method($block, $content, $parent);
return $isPrerender ? $this->maybeOutputCustomStyles().$content : $content;
} elseif (JVB_TESTING && !empty($blockName)) {
- if (!in_array($block['blockName'], $this->getIgnore($isPrerender))) {
+ if (!str_starts_with($block['blockName'],'jvb/') && !in_array($block['blockName'], $this->getIgnore($isPrerender))) {
jvbDump('No method found for '.print_r($block['blockName'], true));
}
}
@@ -114,8 +136,18 @@
//Ignore for both
$base = [
'core/null',
+ 'core/pattern',
'core/list-item',
- 'jvb/drawer-menu'
+ 'core/post-content',
+ 'jvb/drawer-menu',
+ 'jvb/summary',
+ 'jvb/feed',
+ 'jvb/forms',
+ 'jvb/gmbreviews',
+ 'jvb/timeline',
+ 'jvb/video',
+ 'jvb/faq',
+ 'jvb/glossary'
];
if ($isPrerender) {
$base = array_merge($base, [
@@ -136,19 +168,25 @@
}
public function prerender(?string $content, array $block, ?WP_Block $parent = null):?string
{
- $result = $this->checkMethods($content, $block, $parent, true);
- return $result;
+ return $this->checkMethods($content, $block, $parent, true);
}
public function render(string $content, array $block):string
{
- if ($block['blockName'] === 'jvb/feed') {
- // Enqueue the feed block script (it will automatically load dependencies)
- $this->localize_feedblock();
+ switch ($block['blockName']) {
+ case 'jvb/feed':
+ $this->localize_feedblock();
+ break;
+ case 'jvb/forms':
+ wp_enqueue_style('jvb-form');
+ break;
+ case 'jvb/timeline':
+ wp_enqueue_script('jvb-gallery');
+ add_action('wp_footer', 'jvbRenderGallery');
+ break;
}
- if ($block['blockName'] === 'jvb/forms') {
- wp_enqueue_style('jvb-form');
- }
+
+
return $this->checkMethods($content, $block);
}
@@ -515,7 +553,7 @@
}
if (array_key_exists('focalPoint', $attrs)) {
$attrs['isObjectPosition'] = true;
- $style = $this->getFocalPointStyle($attrs['focalPoint'], $attrs);
+ $style = implode(';',$this->getFocalPointStyle($attrs['focalPoint'], $attrs));
$style .= ';object-fit:none;';
$imgLink = str_replace('<img', sprintf(
'<img style="%s"',
@@ -733,7 +771,11 @@
'<table%s',
$this->getClassesAndStyles($attrs)
), $table);
- $caption = str_replace(strtok($parts[1], '>'), '<figcaption', $parts[1]);
+ $caption = '';
+ if (array_key_exists(1, $parts)) {
+ $caption = str_replace(strtok($parts[1], '>'), '<figcaption', $parts[1]);
+ }
+
return sprintf(
'<figure%s>%s%s</figure>',
@@ -779,8 +821,8 @@
}
if (array_key_exists('displayLoginAsForm', $attrs) && $attrs['displayLoginAsForm']) {
- LoginManager::getInstance()->setAction($action);
- return LoginManager::getInstance()->renderLoginForm($action, $redirect, '<h2>Login</h2>');
+ Login::getInstance()->setAction($action);
+ return Login::getInstance()->renderLoginForm($action, $redirect, '<h2>Login</h2>');
}
@@ -1362,9 +1404,6 @@
if (!static::$currentLoop) {
- if (JVB_TESTING) {
- jvbDump('No loop stored');
- }
return $content;
}
if (static::$currentLoop->have_posts()) {
@@ -1377,6 +1416,7 @@
);
}
}
+
return sprintf(
'<ul%s>%s</ul>',
$this->getClassesAndStyles($block['attrs']??[], ['loop']),
@@ -1498,7 +1538,9 @@
protected function buildQueryArgs(array $attrs): array
{
$queryID = $attrs['queryId'] ?? null;
- $args = [];
+ $args = [
+ 'post_status' => 'publish',
+ ];
foreach (($attrs['query'] ?? []) as $key => $value) {
if (empty($value)) continue;
switch ($key) {
@@ -1897,9 +1939,7 @@
);
}
- if (JVB_TESTING) {
- jvbDump('Could not create template part block for '.$block['blockName']);
- }
+
return $content;
// $isHeaderTemplate = (
@@ -2746,6 +2786,9 @@
);
}
return $classes;
+ case 'anchor':
+ //TODO: What's this doing?
+ return '';
default:
if (JVB_TESTING && !is_admin() &&!in_array($key, $this->ignore)) {
// TESTING
@@ -2786,8 +2829,9 @@
$type = 'row';
$isRow = true;
+
//Determine type
- if ((array_key_exists('type', $value) && !in_array($value['type'], ['flex', 'grid'])) ||
+ if ((array_key_exists('type', $value) && !in_array($value['type'], ['flex', 'grid', 'default'])) ||
(array_key_exists('orientation', $value) && $value['orientation'] === 'vertical')) {
$type = 'col';
$isRow = false;
@@ -3107,7 +3151,9 @@
break;
}
return $this->getColorStyle($value, $type);
-
+ case 'anchor':
+ //TODO: What should we do here?
+ break;
// Any other attributes that need direct styling
default:
if (JVB_TESTING && !is_admin() && !in_array($key, $this->ignore)) {
@@ -3137,7 +3183,7 @@
break;
default:
if (JVB_TESTING) {
- jvbDump($value, 'No preset found for size: '.print_r($value, true));
+ error_log('No preset found for size: '.print_r($value, true));
}
}
}
@@ -3422,6 +3468,7 @@
break;
case 'textAlign':
$styles['text-align'] = $value;
+ break;
default:
if (JVB_TESTING) {
jvbDump($value,'[getTypographyStyle] No property set for '.$property.': ');
--
Gitblit v1.10.0