From 3d25ad7de4fdbb3eba2cde2a62422e6be5d79a0a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 25 Aug 2026 22:57:22 +0000
Subject: [PATCH] =It's been a minute. I went through the Routes and associated Managers and ensured they played together well. Reworked the Cache.php, and I think I caught all the references. Moving away from JVBase() root class, to individuall classes that are Instanced. Double checked for the ABSPATH check in every file, and added index.php to every directory that didn't already have it. Also still working on the MenuBlock to work with WooCommerce for now for Northeh
---
inc/managers/DashboardManager.php | 53 ++++++++++++++++++++++++++++++++---------------------
1 files changed, 32 insertions(+), 21 deletions(-)
diff --git a/inc/managers/DashboardManager.php b/inc/managers/DashboardManager.php
index 878f2a7..35cad18 100644
--- a/inc/managers/DashboardManager.php
+++ b/inc/managers/DashboardManager.php
@@ -3,7 +3,7 @@
use JetBrains\PhpStorm\NoReturn;use JVBase\forms\TaxonomySelector;
use JVBase\base\Site;
-use JVBase\meta\Form;
+use JVBase\integrations\ServiceMap;use JVBase\meta\Form;
use JVBase\registrar\Registrar;
use JVBase\ui\Navigation;
use WP_Error;use WP_Query;use WP_User;
@@ -17,6 +17,8 @@
*/
class DashboardManager
{
+ use ServiceMap;
+
protected WP_User $user;
protected Cache $cache;
protected string $role;
@@ -25,7 +27,7 @@
public function __construct()
{
- $this->cache = Cache::for('dashboard', WEEK_IN_SECONDS)->connect('user')->user();
+ $this->cache = Cache::for('dashboard', WEEK_IN_SECONDS)->user();
if (JVB_TESTING) {
$this->cache->flush();
}
@@ -49,7 +51,6 @@
}
public function excludeDashboard(array $IDs):array {
- $this->cache->flush();
$exclude = $this->cache->remember(
'dashboardIDs',
function() {
@@ -218,7 +219,7 @@
$page = $this->getCurrentPageTitle();
// Check if page exists in allowed pages
$allowedPages = $this->getUserAllowedPages();
-
+ error_log('Allowed pages: '.print_r($allowedPages, true));
if (!in_array($page, $allowedPages)) {
error_log("User not allowed to access page: {$page}");
$this->redirectToDashboard();
@@ -297,11 +298,10 @@
*/
protected function buildIntegrationPages(int $parentID):void
{
- $integrations = JVB()->getAvailableServices(false);
-
- foreach ($integrations as $name => $integration) {
+ $integrations = $this->getAvailableServices();
+ foreach ($integrations as $service) {
+ $integration = $this->getService($service);
$title = $integration->getTitle();
-
$slug = sanitize_title($title);
$this->createDashboardPage($slug, $title, $parentID);
}
@@ -360,7 +360,7 @@
}
$integrationSlugs = array_map(function($name) {
return sanitize_title(str_replace('_', '-', $name));
- }, array_keys(JVB()->getAvailableServices(false)));
+ }, array_keys($this->getAvailableServices()));
// Check if this is an integration subpage
if (in_array($page, $integrationSlugs)) {
@@ -747,7 +747,7 @@
Registrar::withFeature('is_content', 'term')
);
$availableContent = array_filter($pages, function($page, $key) use($all) {
- return !is_numeric($key) && in_array($key, $all) && JVB()->roles()->checkRole($this->user, $key);
+ return !is_numeric($key) && in_array($key, $all) && Roles::getInstance()()->checkRole($this->user, $key);
}, ARRAY_FILTER_USE_BOTH);
if (!empty ($availableContent)){
$content = $menu->addItem('Your Content', jvbDashIcon('book-bookmark'))
@@ -865,12 +865,13 @@
public function renderIndex(string $content, string $page):string
{
+ jvbDump($page);
if ($page !== '' && $page !== 'dash') {
return $content;
}
if (Site::has('referrals')) {
- $whatever = JVB()->referrals()->getReferralWelcomeMessage($this->user->ID);
+ $whatever = Referrals::getInstance()->getReferralWelcomeMessage($this->user->ID);
if (!empty($whatever)) {
return $whatever;
}
@@ -932,18 +933,19 @@
protected function getIntegrationsMenu():string
{
- $integrations = JVB()->getAvailableServices(false);
+ $integrations = $this->getAvailableServices();
$out = '';
if (!empty($integrations)) {
$out = '<nav class="integrations"><ul>';
$url = get_home_url(null, '/dash/integrations/');
$out .= '<li><a href="'.$url.'">'.jvbDashIcon('plugs-connected').'Integrations</a></li>';
- foreach ($integrations as $name=> $integration) {
- if (!JVB()->userCanConnect($name, $this->user->ID) || !$integration->hasDefaults()) {
+ foreach ($integrations as $service) {
+ $integration = $this->getService($service);
+ if (method_exists($integration, 'userCanConnect') && !$integration->userCanConnect($this->user->ID)) {
continue;
}
- $link = sanitize_title(str_replace('_', '-',$name));
+ $link = sanitize_title(str_replace('_', '-',$service));
$out .= '<li><a href="'.$url.$link.'">'.jvbDashIcon($integration->icon).$integration->getTitle().'</a></li>';
}
$out .= '</ul></nav>';
@@ -970,15 +972,19 @@
?>
<section class="item-grid integrations">
<?php
- $all = JVB()->getAvailableServices();
- foreach ($all as $name) {
+
+ foreach ($this->getAvailableServices() as $name) {
if (current_user_can('manage_options')) {
$userID = null;
} else {
$userID = $this->user->ID;
}
-
- JVB()->connect($name, $userID)->renderConnection();
+ $integration = $this->getService($name);
+ if (method_exists($integration, 'determineUser')
+ && method_exists($integration, 'renderConnection')) {
+ $integration->determineUser();
+ $integration->renderConnection();
+ }
}
?>
</section>
@@ -1203,6 +1209,7 @@
echo jvbNewModal(
'edit-modal '.$type,
+ 'edit-modal',
'Edit '.ucfirst($type),
jvbRenderForm('admin', $fields)
);
@@ -1321,12 +1328,14 @@
}
if (!$user || !$this->userHasDashboardAccess($user)) {
+ error_log('No Dashboard Access');
return [];
}
$pages = $this->cache->get($userID);
+ $pages = false;
if ($pages === false || JVB_TESTING) {
if (user_can($userID, 'manage_options')) {
// Admin gets all pages as flat array
@@ -1339,6 +1348,7 @@
$pages = $this->getAllDashboardPages();
$canSkip = user_can($userID, 'skip_moderation');
+ jvbDump($pages, 'All Pages');
foreach($pages as $key => $slug) {
//Default to Remove pages
$remove = true;
@@ -1347,7 +1357,7 @@
$membership = Site::membership();
$type = $registrar? $registrar->getType() : false;
if ($type) {
- $permission = JVB()->roles()->getPermission('edit', $key);
+ $permission = Roles::getInstance()()->getPermission('edit', $key);
}
switch ($type) {
case 'content':
@@ -1357,7 +1367,7 @@
break;
case 'taxonomy':
$registrar = Registrar::getInstance($key);
- if ($registrar && $registrar->hasFeature('is_content') && (!empty(JVB()->roles()->getOwnedTerms($userID, $key)) || !empty(JVB()->roles()->getManagedTerms($userID, $key)))){
+ if ($registrar && $registrar->hasFeature('is_content') && (!empty(Roles::getInstance()()->getOwnedTerms($userID, $key)) || !empty(Roles::getInstance()()->getManagedTerms($userID, $key)))){
$remove = false;
} else if (count(array_intersect($registrar->registrar->for, array_keys($pages))) > 0) {
$remove = false;
@@ -1434,6 +1444,7 @@
}
}
break;
+ case 'Account':
case 'dash':
case 'Referrals':
case 'favourites':
--
Gitblit v1.10.0