From c4aa5cdb5e90ad4b420e22772797d16980232a2b Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 15 Apr 2026 18:38:55 +0000
Subject: [PATCH] =Updating custom tables to utilize CustomTable.php

---
 inc/managers/SEO/TemplateResolver.php |   79 ++++++++++++++++++++-------------------
 1 files changed, 40 insertions(+), 39 deletions(-)

diff --git a/inc/managers/SEO/TemplateResolver.php b/inc/managers/SEO/TemplateResolver.php
index 1090f9c..bae31b9 100644
--- a/inc/managers/SEO/TemplateResolver.php
+++ b/inc/managers/SEO/TemplateResolver.php
@@ -1,7 +1,8 @@
 <?php
 namespace JVBase\managers\SEO;
 
-use JVBase\meta\MetaManager;
+use JVBase\meta\Meta;
+use JVBase\registrar\Registrar;
 use WP_Post;
 use WP_Term;
 use WP_User;
@@ -25,7 +26,7 @@
 	private ?int $objectId = null;
 	private ?string $objectType = null;
 	private ?string $contentType = null;
-	private ?MetaManager $meta = null;
+	private ?Meta $meta = null;
 	private array $context = [];
 	private array $fieldDefinitions = [];
 
@@ -39,7 +40,7 @@
 		$this->contentType = $contentType;
 
 		if ($objectId && $objectType) {
-			$this->meta = new MetaManager($objectId, $objectType, $contentType);
+			$this->meta = new Meta($objectId, $objectType, $contentType);
 			$this->loadFieldDefinitions();
 		}
 
@@ -133,9 +134,9 @@
 			return $special;
 		}
 
-		// Try to get from MetaManager
+		// Try to get from Meta.php
 		if ($this->meta) {
-			$value = $this->meta->getValue($variable);
+			$value = $this->meta->get($variable);
 
 			// Auto-resolve complex field types via SchemaFieldHelpers
 			$value = $this->autoResolveField($variable, $value);
@@ -187,14 +188,14 @@
 	 */
 	private function isRelatedPostsField(string $fieldName): bool
 	{
-		if (!defined('JVB_CONTENT')) {
+		$posts = Registrar::getRegistered('post');
+		if (empty($posts)) {
 			return false;
 		}
 
-		// Check if field name matches any plural content type
-		foreach (JVB_CONTENT as $type => $config) {
-			$plural = strtolower($config['plural'] ?? '');
-			if ($plural && $fieldName === $plural) {
+		foreach ($posts as $post) {
+			$registrar = Registrar::getInstance($post);
+			if ($registrar && strtolower($registrar->getPlural()) === $fieldName){
 				return true;
 			}
 		}
@@ -209,14 +210,15 @@
 	 */
 	private function isRelatedTermsField(string $fieldName): bool
 	{
-		if (!defined('JVB_TAXONOMY')) {
+
+		$posts = Registrar::getRegistered('term');
+		if (empty($posts)) {
 			return false;
 		}
 
-		// Check if field name matches any plural taxonomy
-		foreach (JVB_TAXONOMY as $taxonomy => $config) {
-			$plural = strtolower($config['plural'] ?? '');
-			if ($plural && $fieldName === $plural) {
+		foreach ($posts as $post) {
+			$registrar = Registrar::getInstance($post);
+			if ($registrar && strtolower($registrar->getPlural()) === $fieldName){
 				return true;
 			}
 		}
@@ -277,17 +279,20 @@
 	 */
 	private function getPostTypeFromPluralName(string $pluralName): ?string
 	{
-		if (!defined('JVB_CONTENT')) {
+
+		$posts = Registrar::getRegistered('post');
+		if (empty($posts)) {
 			return null;
 		}
 
-		foreach (JVB_CONTENT as $type => $config) {
-			$plural = strtolower($config['plural'] ?? '');
-			if ($plural === $pluralName) {
-				return $type;
+		foreach ($posts as $post) {
+			$registrar = Registrar::getInstance($post);
+			if ($registrar && strtolower($registrar->getPlural()) === $pluralName){
+				return $post;
 			}
 		}
 
+
 		return null;
 	}
 
@@ -296,17 +301,18 @@
 	 */
 	private function getTaxonomyFromPluralName(string $pluralName): ?string
 	{
-		if (!defined('JVB_TAXONOMY')) {
+
+		$posts = Registrar::getRegistered('term');
+		if (empty($posts)) {
 			return null;
 		}
 
-		foreach (JVB_TAXONOMY as $taxonomy => $config) {
-			$plural = strtolower($config['plural'] ?? '');
-			if ($plural === $pluralName) {
-				return $taxonomy;
+		foreach ($posts as $post) {
+			$registrar = Registrar::getInstance($post);
+			if ($registrar && strtolower($registrar->getPlural()) === $pluralName){
+				return $post;
 			}
 		}
-
 		return null;
 	}
 
@@ -384,7 +390,7 @@
 		// Check field definitions for taxonomy or post relations
 		if (isset($this->fieldDefinitions[$relation])) {
 			$fieldDef = $this->fieldDefinitions[$relation];
-			$value = $this->meta->getValue($relation);
+			$value = $this->meta->get($relation);
 
 			if (!$value) {
 				return null;
@@ -451,7 +457,7 @@
 		// Image URL accessors for different sizes
 		if (str_ends_with($variable, '_image_url')) {
 			$field = str_replace('_image_url', '', $variable);
-			$imageId = $this->meta?->getValue($field);
+			$imageId = $this->meta?->get($field);
 			if ($imageId) {
 				return wp_get_attachment_image_url($imageId, 'full') ?: '';
 			}
@@ -501,7 +507,7 @@
 	 */
 	private function resolveLocationComponent(string $component): string
 	{
-		$location = $this->meta?->getValue('location');
+		$location = $this->meta?->get('location');
 
 		if (!is_array($location)) {
 			return '';
@@ -607,8 +613,8 @@
 		} elseif ($this->objectType === 'term' && $this->objectId) {
 			$term = get_term($this->objectId);
 			if ($term && !is_wp_error($term)) {
-				$this->context['term_name'] = $term->name;
-				$this->context['term_description'] = $term->description;
+				$this->context['term_name'] = html_entity_decode($term->name);
+				$this->context['term_description'] = wptexturize($term->description);
 				$this->context['taxonomy'] = $term->taxonomy;
 			}
 		} elseif ($this->objectType === 'user' && $this->objectId) {
@@ -650,14 +656,9 @@
 			return;
 		}
 
-		$typeKey = str_replace(BASE, '', $this->contentType);
-
-		if ($this->objectType === 'post' && defined('JVB_CONTENT')) {
-			$this->fieldDefinitions = JVB_CONTENT[$typeKey]['fields'] ?? [];
-		} elseif ($this->objectType === 'term' && defined('JVB_TAXONOMY')) {
-			$this->fieldDefinitions = JVB_TAXONOMY[$typeKey]['fields'] ?? [];
-		} elseif ($this->objectType === 'user' && defined('JVB_USER')) {
-			$this->fieldDefinitions = JVB_USER[$typeKey]['fields'] ?? [];
+		$registrar = Registrar::getInstance($this->contentType));
+		if ($registrar) {
+			$this->fieldDefinitions = $registrar->getFields();
 		}
 	}
 }

--
Gitblit v1.10.0