From 0dfe1d8afafc59c4a5559c498342668d5a58d6ef Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Thu, 23 Jul 2026 22:41:41 +0000
Subject: [PATCH] =Still working away at the Integrations overhaul

---
 inc/admin/SEOAdmin.php |   76 ++++++++++++++------------------------
 1 files changed, 28 insertions(+), 48 deletions(-)

diff --git a/inc/admin/SEOAdmin.php b/inc/admin/SEOAdmin.php
index 6c01e01..ddf9d75 100644
--- a/inc/admin/SEOAdmin.php
+++ b/inc/admin/SEOAdmin.php
@@ -1,8 +1,8 @@
 <?php
 namespace JVBase\admin;
 
+use JVBase\base\SchemaHelper;
 use JVBase\meta\Form;
-use JVBase\meta\Sanitizer;
 use JVBase\registrar\Registrar;
 use JVBase\ui\Tabs;
 
@@ -29,7 +29,7 @@
 		'JVBase\managers\SEO\render\Thing\CreativeWork\WebPage\Webpage'		=> ' - - WebPage',
 		'JVBase\managers\SEO\render\Thing\CreativeWork\WebPage\AboutPage'	=> ' - - - About Page',
 		'JVBase\managers\SEO\render\Thing\CreativeWork\WebPage\CheckoutPage'	=> ' - - - Checkout Page',
-		'JVBase\managers\SEO\render\Thing\CreativeWork\WebPage\CollectionPage'	=> ' - - - Collection Page',
+		'JVBase\inc\managers\SEO\render\Thing\CreativeWork\WebPage\CollectionPage\CollectionPage' => ' - - - Collection Page',
 		'JVBase\managers\SEO\render\Thing\CreativeWork\WebPage\ContactPage'		=> ' - - - Contact Page',
 		'JVBase\managers\SEO\render\Thing\CreativeWork\WebPage\FAQPage'			=> ' - - - FAQ Page',
 		'JVBase\managers\SEO\render\Thing\CreativeWork\WebPage\ItemPage'		=> ' - - - Item Page',
@@ -88,7 +88,9 @@
 		'sponsor',
 		'containsInPlace',
 		'containsPlace',
-		'openingHours'
+		'openingHours',
+		'id',
+		'ignore',
 	];
 
 	protected array $hints = [
@@ -106,7 +108,8 @@
 	public function __construct()
 	{
 		$this->setChecks();
-		add_filter('jvbDashboardPage', [$this, 'addDashboardSection'], 20, 2);
+		add_action(BASE.'dashboard_page_seo', [$this, 'addDashboardSection'], 10);
+
 		add_action('admin_menu', [$this, 'addAdminMenu']);
 		$this->addFormListeners();
 	}
@@ -114,7 +117,8 @@
 	protected function setChecks():void
 	{
 		$checks = [
-			'website'
+			'website',
+			'organization'
 		];
 		$this->checks = array_merge($checks, Registrar::getRegistered());
 	}
@@ -141,14 +145,9 @@
 		);
 	}
 
-	public function addDashboardSection(string $content, string $page):string
+	public function addDashboardSection():void
 	{
-		if ($page !== 'jvb-seo') {
-			return $content;
-		}
-		ob_start();
 		$this->renderAdminPage();
-		return ob_get_clean();
 	}
 
 	public function renderAdminPage(bool $outputScripts = true):void
@@ -201,8 +200,12 @@
 			$this->renderStyles();
 		}
 	}
+		private function renderStyles(): void
+		{
+			jvbInlineStyles('forms');
+		}
 
-	public function renderProperty(string $property, ?string $value, mixed $class):void
+	public function renderProperty(string $property, mixed $value, mixed $class):void
 	{
 		$method = 'get'.ucFirst($property).'FieldConfig';
 		$config = method_exists($class, $method) ? $class->$method() : $this->buildConfig($property);
@@ -248,7 +251,8 @@
 		$this->formStart('website');
 		$default = 'JVBase\managers\SEO\render\Thing\CreativeWork\WebSite';
 //		$this->renderSchemaTypeSelection($value);
-		$stored = get_option(BASE.'WebsiteSchema',apply_filters(BASE.'websiteSchema', []));
+		$stored = SchemaHelper::schema('website');
+
 		$this->renderFieldsFor($default, $stored);
 		$this->formEnd();
 		return ob_get_clean();
@@ -260,7 +264,8 @@
 		$default = apply_filters(BASE.'OrganizationSchemaType', 'JVBase\managers\SEO\render\Thing\Organization\Organization');
 		$value = get_option(BASE.'OrganizationSchemaType', $default);
 		$this->renderSchemaTypeSelection($value);
-		$stored = get_option(BASE.'OrganizationSchema',apply_filters(BASE.'OrganizationSchema', []));
+
+		$stored = SchemaHelper::schema('organization');
 		$this->renderFieldsFor($value, $stored);
 		$this->formEnd();
 		return ob_get_clean();
@@ -287,14 +292,14 @@
 	}
 	public function renderFieldsFor(string $class, array $stored):void
 	{
-		$fields = $this->getFieldsFor($class);
+		$fields = $this->getFieldsForClass($class);
 		$instance = new $class();
 		foreach ($fields as $property => $value) {
 			$this->renderProperty($property, $stored[$property]??null, $instance);
 		}
 	}
 
-	public function getFieldsFor(string $class):array
+	public function getFieldsForClass(string $class):array
 	{
 		if (!class_exists($class)) {
 			error_log('Class not found: '.$class);
@@ -331,7 +336,7 @@
 		}
 
 
-
+		$_POST['type'] = $type;
 		$result = $this->saveFields($action, $type, $_POST);
 
 
@@ -344,6 +349,7 @@
 
 	public function saveFields(string $action, string $class, array $data):array
 	{
+		$action = strtolower($action);
 		if (!in_array($action, $this->checks)) {
 			error_log('[SEOAdmin]Action is not allowed: '.$action);
 			return [
@@ -352,39 +358,13 @@
 			];
 		}
 
-		$allowed = $this->getFieldsFor($class);
-		if (empty($allowed)) {
-			return [
-				'jvb_notice'	=> 'error',
-				'jvb_message'	=> 'Could not get fields from class'
-			];
-		}
-
-		$checked = array_filter($data, function ($item) use ($allowed) {
-			return array_key_exists($item, $allowed);
-		}, ARRAY_FILTER_USE_KEY);
-
-		$stored = get_option(BASE.ucfirst($action).'Schema', []);
-		$updates = [];
-		foreach ($checked as $property => $value) {
-			$sanitized = Sanitizer::sanitize($value, $this->buildConfig($property));
-			if (!array_key_exists($property, $stored) || $stored[$property] !== $sanitized)
-			$updates[$property] = $sanitized;
-		}
-		if (!empty($updates)) {
-			$history = get_option(BASE.ucfirst($action).'SchemaHistory', []);
-			array_unshift($history, $stored);
-			if (count($history) > 5){
-				array_pop($history);
-			}
-			update_option(BASE.ucfirst($action).'SchemaHistory', $history);
-
-			$update = array_merge($stored, $updates);
-			update_option(BASE.ucfirst($action).'Schema', $update);
-		}
-		return [
+		$success = JVB()->schemaHelper()->updateSchema($action, $data);
+		return $success ? [
 			'jvb_notice'	=> 'success',
 			'jvb_message'	=> 'Saved changes successfully'
+		] : [
+			'jvb_notice'	=> 'error',
+			'jvb_message'	=> 'Something went wrong...'
 		];
 	}
 }

--
Gitblit v1.10.0