From 3baf3d2545ba6ece6b74a64c0def59bd0774cf54 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 10 Jun 2026 16:34:12 +0000
Subject: [PATCH] =Laid the groundwork for an improved DashboardManager.php setup. Have to put it aside so I can get the dang Northeh done though.
---
inc/registrar/config/seo/Resolver.php | 61 ++++++++++++++++++++++++------
1 files changed, 49 insertions(+), 12 deletions(-)
diff --git a/inc/registrar/config/seo/Resolver.php b/inc/registrar/config/seo/Resolver.php
index 3cf1271..172e1c5 100644
--- a/inc/registrar/config/seo/Resolver.php
+++ b/inc/registrar/config/seo/Resolver.php
@@ -4,6 +4,7 @@
use JVBase\managers\Cache;
use JVBase\managers\SEO\render\Thing\CreativeWork\MediaObject\ImageObject;
use JVBase\managers\SEO\render\Thing\Intangible\Quantity\Distance;
+use JVBase\managers\SEO\render\Thing\Intangible\StructuredValue\QuantitativeValue;
use JVBase\meta\Meta;
use JVBase\registrar\Registrar;
@@ -14,7 +15,7 @@
class Resolver {
protected static ?Meta $meta;
- public static function resolve(string $template, ?Meta $meta): string
+ public static function resolve(string $template, ?Meta $meta): string|array|\JVBase\managers\SEO\render\Thing\Thing
{
if (!$meta) {
if (is_singular()){
@@ -24,6 +25,11 @@
}
}
self::$meta = $meta;
+
+ if (preg_match('/^\{\{([^}]+)}}$/', trim($template), $matches)) {
+ return self::resolveVariable($matches[1], $meta);
+ }
+
return preg_replace_callback(
'/\{\{([^}]+)}}/',
fn($matches) => self::resolveVariable($matches[1], $meta),
@@ -33,14 +39,27 @@
protected static function resolveVariable(string $variable, ?Meta $meta = null): mixed
{
$variable = trim($variable);
+
switch ($variable) {
case 'CREATOR':
return JVB()->seo()->getCreator();
+ case 'name':
+ if (!$meta && is_post_type_archive()) {
+ $obj = get_queried_object();
+
+ $registrar = Registrar::getInstance($obj->name);
+ return $registrar ? $registrar->getPlural() : $obj->label;
+ }
break;
}
- if (str_contains($variable, '.')) {
+
+ if (str_contains($variable, '.') && $meta) {
return self::resolveRelation($variable, $meta);
}
+ $function = BASE.'resolve_'.$variable;
+ if (function_exists($function)) {
+ return $function($variable, $meta);
+ }
if ($meta && $variable === 'post_permalink') {
return get_the_permalink($meta->id());
}
@@ -55,6 +74,7 @@
if ($variable === 'post_content') {
return self::resolvePostContent($variable, $meta);
}
+
return match($config['type']) {
'upload', 'image', 'gallery' => self::resolveImage($variable, $meta),
'selector', 'taxonomy', 'user', 'post' => self::resolveObject($variable, $meta),
@@ -83,10 +103,12 @@
if (!$meta) {
return'';
}
+
$ID = $meta->get($relation);
- if (!$ID || $ID === '') {
+ if (empty($ID)) {
return '';
}
+ $IDs = explode(',',$ID);
// 2) Create new Meta for that relation
$config = $meta->config($relation);
if (!$config) {
@@ -106,9 +128,15 @@
error_log('[SEO]Meta Resolver. Could not find type for relation: '.$relation.': '.$field);
return '';
}
- $newMeta = new Meta($ID, $type);
+
+ $results = [];
+ foreach ($IDs as $ID) {
+ $newMeta = new Meta((int)$ID, $type);
+
// 3) Pass to resolver
- return self::resolve($field, $newMeta);
+ $results[] = self::resolveVariable($field, $newMeta);
+ }
+ return jvbCommaList($results);
}
protected static function resolvePostContent(string $variable, ?Meta $meta):string{
@@ -153,8 +181,8 @@
}
$ignore = ['description', 'name'];
- if (!in_array($property, $ignore)) {
- error_log('[SEO]Resolver - No method found for '.$property.' with value: '.print_r($value, true).'. Defaulting to base Resolver');
+ if (JVB_TESTING && !in_array($property, $ignore)) {
+// error_log('[SEO]Resolver - No method found for '.$property.' with value: '.print_r($value, true).'. Defaulting to base Resolver');
}
@@ -181,6 +209,12 @@
if (!$imgID || $imgID === '') {
return null;
}
+
+ return self::imgIDToSchema($imgID);
+
+ }
+ public static function imgIDToSchema(int $imgID):ImageObject|null
+ {
$img = wp_get_attachment_image_src($imgID,'full');
if (!$img) {
return null;
@@ -194,11 +228,15 @@
function () use ($imgID, $img) {
$imageObject = new ImageObject();
$imageObject->setContentUrl($img[0]);
- $width = new Distance();
- $width->setName($img[1].' px');
+ $width = new QuantitativeValue();
+ $width->showID(false);
+ $width->setValue($img[1]);
+ $width->setUnitText('px');
$imageObject->setWidth($width);
- $height = new Distance();
- $height->setName($img[2].' px');
+ $height = new QuantitativeValue();
+ $height->showID(false);
+ $height->setValue($img[2]);
+ $height->setUnitText('px');
$imageObject->setHeight($height);
$image_path = get_attached_file($imgID);
@@ -219,7 +257,6 @@
return $imageObject;
}
);
-
}
public static function resolveCreator(string $type, mixed $value, mixed $schema, ?Meta $meta):mixed
--
Gitblit v1.10.0