From de317675a8069b747cb253ba3e2b5dc394ca36ef Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sat, 18 Jul 2026 21:44:51 +0000
Subject: [PATCH] =Base Integrations mainly done - doing a test with setting up the Square integration to follow

---
 JVBase.php |  207 +++++++++++++++++++++++++++++----------------------
 1 files changed, 117 insertions(+), 90 deletions(-)

diff --git a/JVBase.php b/JVBase.php
index 255ff5f..36f94ca 100644
--- a/JVBase.php
+++ b/JVBase.php
@@ -1,56 +1,53 @@
 <?php
 namespace JVBase;
 
+use JVBase\admin\SEOAdmin;
+use JVBase\base\SchemaHelper;
+use JVBase\base\Site;
 use JVBase\blocks\CustomBlocks;
-use JVBase\integrations\BlueSky;
-use JVBase\managers\Cache;
+use JVBase\managers\AdminPages;
+use JVBase\managers\ApprovalManager;
+use JVBase\managers\Dashboard\DashboardManager;
+use JVBase\managers\DirectoryManager;
 use JVBase\managers\EmailManager;
 use JVBase\managers\ErrorHandler;
+use JVBase\managers\FavouritesManager;
 use JVBase\managers\InvitationsManager;
 use JVBase\managers\LoginManager;
 use JVBase\managers\MagicLinkManager;
+use JVBase\managers\NotificationManager;
 use JVBase\managers\queue\Queue;
-use JVBase\managers\DashboardManager;
-use JVBase\managers\DirectoryManager;
 use JVBase\managers\ReferralManager;
 use JVBase\managers\RoleManager;
-//use JVBase\managers\SchemaManager;
 use JVBase\managers\SEO\render\SchemaOutput;
-use JVBase\managers\SEO\SchemaOutputManager;
-use JVBase\admin\SEOAdmin;
-use JVBase\managers\AdminPages;
-use JVBase\managers\NotificationManager;
+use JVBase\managers\TaxonomyRelationships;
 use JVBase\managers\UserTermsManager;
 use JVBase\registrar\Registrar;
-use JVBase\rest\routes\FeedRoutes;
-use JVBase\rest\routes\FavouritesRoutes;
-use JVBase\rest\routes\IntegrationsSquareRoutes;
-use JVBase\rest\routes\IntegrationsHelcimRoutes;
-use JVBase\rest\routes\NotificationsRoutes;
+use JVBase\rest\routes\AdminRoutes;
+use JVBase\rest\routes\ApprovalRoutes;
 use JVBase\rest\routes\ContentRoutes;
-use JVBase\rest\routes\TermRoutes;
-use JVBase\rest\routes\UploadRoutes;
-//use JVBase\rest\routes\BioRoutes;
-use JVBase\rest\routes\SettingsRoutes;
-//use JVBase\rest\routes\ShopRoutes;
 use JVBase\rest\routes\ContentTermsRoutes;
-use JVBase\rest\routes\SEORoutes;
-use JVBase\rest\routes\QueueRoutes;
 use JVBase\rest\routes\ErrorRoutes;
+use JVBase\rest\routes\FavouritesRoutes;
+use JVBase\rest\routes\FeedRoutes;
 use JVBase\rest\routes\FormRoutes;
+use JVBase\rest\routes\IntegrationsHelcimRoutes;
+use JVBase\rest\routes\IntegrationsRoutes;
+use JVBase\rest\routes\IntegrationsSquareRoutes;
+use JVBase\rest\routes\Invitations;
 use JVBase\rest\routes\LoginRoutes;
 use JVBase\rest\routes\NewsRoutes;
-use JVBase\rest\routes\ReferralRoutes;
-//use JVBase\rest\routes\MagicLinkRoutes;
-use JVBase\rest\routes\ResponseRoutes;
+use JVBase\rest\routes\NotificationsRoutes;
 use JVBase\rest\routes\OptionsRoutes;
+use JVBase\rest\routes\QueueRoutes;
+use JVBase\rest\routes\ReferralRoutes;
+use JVBase\rest\routes\ResponseRoutes;
+use JVBase\rest\routes\SEORoutes;
+use JVBase\rest\routes\SettingsRoutes;
+use JVBase\rest\routes\TermRoutes;
+use JVBase\rest\routes\UploadRoutes;
 use JVBase\rest\routes\VoteRoutes;
-use JVBase\rest\routes\Invitations;
-use JVBase\rest\routes\ApprovalRoutes;
-use JVBase\rest\routes\AdminRoutes;
-use JVBase\rest\routes\IntegrationsRoutes;
-use JVBase\utility\Features;
-use JVBase\base\SchemaHelper;
+use UserRoutes;
 
 if (!defined('ABSPATH')) {
 	exit;
@@ -68,16 +65,16 @@
 	protected CustomBlocks $customBlocks;
 
 	protected array $serviceMap = [
-		'maps' => 'JVBase\integrations\GoogleMaps',
-		'square' => 'JVBase\integrations\Square',
-		'facebook' => 'JVBase\integrations\Facebook',
-		'helcim' => 'JVBase\integrations\Helcim',
-		'instagram' => 'JVBase\integrations\Instagram',
-		'bluesky' => 'JVBase\integrations\BlueSky',
-		'gmb' => 'JVBase\integrations\GoogleMyBusiness',
-		'cloudflare' => 'JVBase\integrations\Cloudflare',
-		'umami' => 'JVBase\integrations\Umami',
-		'postmark' => 'JVBase\integrations\PostMark',
+		'maps' => 'JVBase\integrations\services\GoogleMaps',
+		'square' => 'JVBase\integrations\services\Square',
+		'facebook' => 'JVBase\integrations\services\Facebook',
+		'helcim' => 'JVBase\integrations\services\Helcim',
+		'instagram' => 'JVBase\integrations\services\Instagram',
+		'bluesky' => 'JVBase\integrations\services\BlueSky',
+		'gmb' => 'JVBase\integrations\services\GoogleMyBusiness',
+		'cloudflare' => 'JVBase\integrations\services\Cloudflare',
+		'umami' => 'JVBase\integrations\services\Umami',
+		'postmark' => 'JVBase\integrations\services\PostMark',
 	];
 
 	public static function getInstance(): JVB
@@ -89,7 +86,7 @@
 	}
 
 
-	public function __construct()
+	private function __construct()
 	{
 		$this->customBlocks = new CustomBlocks();
 		$this->managers = [
@@ -104,10 +101,19 @@
 			'seo'		=> new SchemaOutput(),
 			'schemaHelper' => new SchemaHelper(),
 //			'uploads'	=> new UploadManager(),
-			'userTerms' => new UserTermsManager(),
+//			'userTerms' => new UserTermsManager(),
 			'email' 	=> new EmailManager(),
+//			'terms'		=> new TaxonomyRelationships(),
 		];
 
+        if (Site::has('feed_block')) {
+            $this->managers['terms'] = new TaxonomyRelationships();
+        }
+
+        if (Site::hasAll(['dashboard', 'membership', 'feed_block'])) {
+            $this->managers['userTerms'] = new UserTermsManager();
+        }
+
 		$this->routes = [
 			'login' => new LoginRoutes(),
 			'integrations' => new IntegrationsRoutes(),
@@ -115,45 +121,47 @@
 			'queue' => new QueueRoutes(),
 			'settings' => new SettingsRoutes(),
 			'upload' => new UploadRoutes(),
-			'forms' => new FormRoutes()
+			'forms' => new FormRoutes(),
+			'user'	=> new UserRoutes()
 		];
 
-		if (Features::forSite()->has('magicLink')) {
+		if (Site::has('magic_link')) {
 //			$this->routes['magicLink'] = new MagicLinkRoutes();
 			$this->managers['magicLink'] = new MagicLinkManager();
 		}
-		if (Features::forSite()->has('referrals')) {
+		if (Site::has('referrals')) {
 			$this->managers['referral'] = new ReferralManager();
 			$this->routes['referral'] = new ReferralRoutes();
 		}
 
-		if (Features::forSite()->has('dashboard')) {
-			$this->managers['dash'] = new DashboardManager();
-		}
 
-		if (Features::hasIntegration('square')) {
+		if (Site::hasIntegration('square')) {
 			$this->routes['square'] = new IntegrationsSquareRoutes();
 		}
-		if (Features::hasIntegration('helcim')) {
+		if (Site::hasIntegration('helcim')) {
 			$this->routes['helcim'] = new IntegrationsHelcimRoutes();
 		}
 
-		if (Features::forSite()->has('feed_block')) {
+		if (Site::has('feed_block')) {
 			$this->routes['feed'] = new FeedRoutes();
 		}
-		if (Features::forMembership()->has('notifications')) {
+        $membership = Site::membership();
+		if ($membership && $membership->has('notifications')) {
 			$this->managers['notifications'] = new NotificationManager();
 			$this->routes['notifications'] = new NotificationsRoutes();
 		}
-		if (Features::forSite()->has('feed_block') || Features::forSite()->has('dashboard')) {
+		if (!empty(Registrar::withFeature('approve_new'))) {
+			$this->managers['approvals'] = new ApprovalManager();
+		}
+		if (Site::has('feed_block') || Site::has('dashboard')) {
 			$this->routes['term'] = new TermRoutes();
 		}
 
-		if (Features::forSite()->has('is_directory')) {
+		if (Site::has('is_directory')) {
 			$this->managers['directory'] = new DirectoryManager();
 		}
 
-		if (Features::forSite()->has('dashboard')) {
+		if (Site::has('dashboard')) {
 			$this->routes['error'] = new ErrorRoutes();
             $this->routes['admin']  = new AdminRoutes();
 			$this->routes['content'] = new ContentRoutes();
@@ -163,31 +171,37 @@
 			$this->routes['options'] = new OptionsRoutes();
 		}
 
-		if (Features::forSite()->has('favourites')) {
+		if (Site::has('favourites')) {
+			$this->managers['favourites'] = new FavouritesManager();
 			$this->routes['favourites'] = new FavouritesRoutes();
 		}
 
-		if (Features::forMembership()->has('forum')) {
+		if ($membership && $membership->has('forum')) {
 			$this->routes['news'] = new NewsRoutes();
 		}
-		if (Features::forMembership()->has('invitable')) {
+		if ($membership && $membership->has('invitable')) {
 			$this->managers['invitations'] = new InvitationsManager();
 		}
-		if (!empty(Registrar::getFeatured('has_responses'))) {
+		if (!empty(Registrar::withFeature('has_responses'))) {
 			$this->routes['comments'] = new ResponseRoutes();
 		}
-		if (!empty(Registrar::getFeatured('karma'))) {
+		if (!empty(Registrar::withFeature('karma'))) {
 			$this->routes['vote'] = new VoteRoutes();
 		}
-		if (!empty(Registrar::getFeatured('karma'))
-			|| Features::forMembership()->has('member_verified') ||
-			Features::forMembership()->has('term_approval')) {
+		if (!empty(Registrar::withFeature('karma'))
+			|| ($membership && $membership->has('member_verified')) ||
+            ($membership && $membership->has('term_approval'))) {
 			$this->routes['approvals'] = new ApprovalRoutes();
 		}
-		if (Features::forMembership()->has('can_invite')) {
+		if ($membership && $membership->has('can_invite')) {
 			$this->routes['invites'] = new Invitations();
 		}
 
+
+		if (Site::has('dashboard')) {
+			$this->managers['dash'] = new DashboardManager();
+		}
+
 		$this->setupIntegrations();
 
 		add_action('wp_footer', [$this, 'additionalActions']);
@@ -199,17 +213,9 @@
 
 	protected function setupIntegrations(): void
 	{
-		if (array_key_exists('integrations', JVB_SITE)) {
-			foreach (JVB_SITE['integrations'] as $service => $use) {
-				if (!$use) {
-					continue;
-				}
-				if (array_key_exists($service, $this->serviceMap)) {
-					$this->integrations[$service] = new $this->serviceMap[$service]();
-				}
-
-			}
-		}
+        foreach(array_keys(Site::getIntegrations()) as $integration) {
+            $this->integrations[$integration] = $this->serviceMap[$integration]::getInstance();
+        }
 	}
 
 	public function registeredContent(): array
@@ -217,6 +223,11 @@
 		return array_merge(array_keys($this->content), array_keys($this->taxonomies));
 	}
 
+	public function favourites(): FavouritesManager|false
+	{
+		return $this->managers['favourites'] ?? false;
+	}
+
 	public function dashboard(): DashboardManager|false
 	{
 		return $this->managers['dash'] ?? false;
@@ -285,23 +296,29 @@
 
 	public function connect(string $service, ?int $userID = null): mixed
 	{
-		if ($userID) {
-			if (!$this->userCanConnect($service, $userID)) {
-				return null;
-			}
-
-			if (!array_key_exists($service, $this->integrations)) {
-				return null;
-			}
-			return new $this->serviceMap[$service]($userID);
+//		if ($userID) {
+//			if (!$this->userCanConnect($service, $userID)) {
+//				return null;
+//			}
+//
+//			if (!array_key_exists($service, $this->integrations)) {
+//				return null;
+//			}
+//
+//			return $this->serviceMap[$service]::getInstance($userID);
+//		}
+		$instance = $this->integrations[$service]??null;
+		if ($instance) {
+			$instance->switchUser($userID);
 		}
-		return (array_key_exists($service, $this->integrations)) ? $this->integrations[$service] : null;
+		return $instance;
 	}
 
 	public function userCanConnect(string $service, int $userID): bool
 	{
-		$allowed = JVB_USER[jvbUserRole($userID)]['integrations'] ?? [];
-		return user_can($userID, 'manage_options') || in_array($service, $allowed);
+		$role = jvbUserRole($userID);
+		$registrar = Registrar::getInstance($role);
+		return user_can($userID, 'manage_options') || $registrar->hasIntegration($service);
 	}
 
 	public function getAvailableServices(bool $keys = true): array
@@ -362,12 +379,12 @@
 
 		if (!empty ($buttons)) {
 			?>
-			<section class="additional-actions">
+			<section class="main-actions">
 				<div class="buttons col">
-					<?= implode($buttons); ?>
+					<?= implode('', $buttons); ?>
 				</div>
 				<div class="actions">
-					<?= implode($contents); ?>
+					<?= implode('', $contents); ?>
 				</div>
 			</section>
 			<?php
@@ -387,4 +404,14 @@
 	{
 		return $this->managers['schemaHelper'];
 	}
+
+	public function termRelationships():TaxonomyRelationships
+	{
+		return $this->managers['terms'];
+	}
+
+	public function approvals ():ApprovalManager|false
+	{
+		return $this->managers['approvals']??false;
+	}
 }

--
Gitblit v1.10.0