From 48721c85ebcfa973ee81719d2467ca80e4253dc9 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Fri, 01 May 2026 17:30:03 +0000
Subject: [PATCH] =Edmonton Ink hard test begins! Real testing of the managers and reset routes will commence. So far, just ensuring our classes are all loaded correctly: Site() and its sub-classes Membership, Login, etc. Care should be taken to load conditionally on 'init', as we finish defining most settings by 'plugins_loaded' at priority 5
---
inc/managers/DashboardManager.php | 278 +++++++++++++++++++++++++------------------------------
1 files changed, 128 insertions(+), 150 deletions(-)
diff --git a/inc/managers/DashboardManager.php b/inc/managers/DashboardManager.php
index 5a25ea0..4d3c544 100644
--- a/inc/managers/DashboardManager.php
+++ b/inc/managers/DashboardManager.php
@@ -1,9 +1,10 @@
<?php
namespace JVBase\managers;
-use JVBase\forms\TaxonomySelector;use JVBase\managers\CRUD;
-use JVBase\meta\MetaManager;
-use JVBase\utility\Features;
+use JVBase\forms\TaxonomySelector;
+use JVBase\base\Site;
+use JVBase\meta\Form;
+use JVBase\registrar\Registrar;
use JVBase\ui\Navigation;
use WP_User;
@@ -29,9 +30,10 @@
if (!$this->isRegistered()) {
add_action('init', [$this, 'buildDashboard']);
}
+ $this->cache->flush();
$this->user = wp_get_current_user();
$this->role = jvbUserRole($this->user->ID);
- $this->userLink = (int)get_user_meta($this->user->ID, BASE.'link', true);
+ $this->userLink = (int)get_user_meta($this->user->ID, BASE.'profile_link', true);
$this->baseURL = get_home_url(null, '/dash');
add_action('template_redirect', [$this, 'handleRedirects']);
@@ -136,14 +138,14 @@
}
- protected function getConfig(string $page):array
+ protected function getConfig(string $page):Registrar|false
{
$pages = $this->getAllDashboardPages();
$key = array_search($page, $pages);
if ($key === false || is_numeric($key)) {
- return [];
+ return false;
}
- return Features::getConfig($key);
+ return Registrar::getInstance($key)??false;
}
/**
@@ -163,9 +165,9 @@
protected function getTitle(string $slug):string
{
- $config = $this->getConfig($slug);
- if (!empty($config)) {
- return $config['dash_title']??$config['plural'];
+ $registrar = $this->getConfig($slug);
+ if ($registrar) {
+ return $registrar->getConfig('dashboard')['title']??$registrar->getPlural();
}
return ucwords(str_replace('-', ' ', str_replace('_', ' ', $slug)));
}
@@ -289,9 +291,9 @@
protected function getDescription(string $page):string
{
- $config = $this->getConfig($page);
- if (!empty($config)) {
- $description = (array_key_exists('dash_description', $config)) ? $config['dash_description'] : '';
+ $registrar = $this->getConfig($page);
+ if ($registrar) {
+ $description = $registrar->getConfig('dashboard')['description']??'';
} else {
$description = apply_filters('jvbDashboardDescription', $page);
switch ($page) {
@@ -339,10 +341,10 @@
// Get current page/section
$page = $this->getCurrentPageTitle();
- $config = $this->getConfig($page);
- if(!empty($config)) {
- add_filter('jvbLoadingIcon', function() use ($config) {
- return $config['icon'];
+ $registrar = $this->getConfig($page);
+ if($registrar) {
+ add_filter('jvbLoadingIcon', function() use ($registrar) {
+ return $registrar->getIcon();
});
}
$integrationSlugs = array_map(function($name) {
@@ -380,6 +382,7 @@
$this->renderHeader();
// Pass to page handler
$constantSlug = $this->getConstantSlug($page);
+
echo apply_filters(
'jvbDashboardPage',
$this->renderPage($page),
@@ -396,11 +399,11 @@
// if ($page === 'integrations' || in_array($page, $integrationSlugs)) {
// // Check integration access
// if ($page === 'integrations') {
-// if (!Features::hasAnyIntegration('user', $this->role)) {
+// if (!Site::hasAnyIntegration('user', $this->role)) {
// $this->redirectToDashboard();
// }
// } else {
-// if (!Features::hasIntegration($page, 'user', $this->role)) {
+// if (!Site::hasIntegration($page, 'user', $this->role)) {
// $this->redirectToDashboard();
// }
// }
@@ -514,8 +517,8 @@
if (!is_singular(BASE.'dash') && !is_post_type_archive(BASE.'dash')) {
return;
}
- wp_enqueue_style('jvb-icons-dash');
- wp_enqueue_style('jvb-icons-forms');
+ IconsManager::for('forms')->enqueueIconStyles();
+ IconsManager::for('dash')->enqueueIconStyles();
wp_enqueue_script('jvb-form');
wp_enqueue_script('jvb-selector');
@@ -526,7 +529,7 @@
switch ($page) {
case 'notifications':
- if (Features::forSite()->has('notifications')) {
+ if (Site::has('notifications')) {
wp_enqueue_script('jvb-notification-manager');
}
break;
@@ -536,28 +539,28 @@
break;
case 'admin':
case 'dash':
- if (current_user_can('manage_options') && apply_filters('jvbAdminDashboard', '') === '') {
- wp_enqueue_script(
- 'jvb-admin',
- JVB_URL . 'assets/js/min/admin.min.js',
- [
- 'jvb-queue',
- 'jvb-loading'
- ],
- [
- 'strategy' => 'defer',
- 'in_footer' => true
- ]
- );
+// if (current_user_can('manage_options') && apply_filters('jvbAdminDashboard', '') === '') {
+// wp_enqueue_script(
+// 'jvb-admin',
+// JVB_URL . 'assets/js/min/admin.min.js',
+// [
+// 'jvb-queue',
+//// 'jvb-loading'
+// ],
+// [
+// 'strategy' => 'defer',
+// 'in_footer' => true
+// ]
+// );
- wp_localize_script(
- 'jvb-admin',
- 'jvbAdmin',
- [
- 'nonce' => wp_create_nonce('itsme')
- ]
- );
- }
+// wp_localize_script(
+// 'jvb-admin',
+// 'jvbAdmin',
+// [
+// 'nonce' => wp_create_nonce('itsme')
+// ]
+// );
+// }
break;
case 'seo':
wp_enqueue_script('jvb-schema');
@@ -566,7 +569,7 @@
wp_enqueue_script('jvb-crud');
break;
}
- if (Features::forSite()->has('favourites')) {
+ if (Site::has('favourites')) {
wp_enqueue_script('jvb-favourites');
wp_localize_script('jvb-favourites-manager', 'favouritesSettings', [
'strings' => [
@@ -582,7 +585,7 @@
wp_enqueue_script('jvb-creator');
- if (Features::forSite()->has('forum')) {
+ if (Site::has('forum')) {
wp_enqueue_script('jvb-news');
}
do_action('jvbDashScripts', $page);
@@ -618,10 +621,11 @@
return $this->cache->remember('icon_'.sanitize_title($page), function() use ($slug, $page) {
$icon = sanitize_title($page);
if (!is_numeric($slug)) {
- $config = Features::getConfig($slug);
- if (array_key_exists('icon', $config)) {
- $icon = $config['icon'];
+ $registrar =Registrar::getInstance($slug);
+ if ($registrar) {
+ return $registrar->getIcon();
}
+
}
return $icon;
});
@@ -643,7 +647,7 @@
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
- <title><?= (array_key_exists('dashboard_title', JVB_SITE)) ? JVB_SITE['dashboard_title'] : 'Dashboard | '.get_bloginfo('name') ?></title>
+ <title><?= Site::dashboardTitle()??'Dashboard | '.get_bloginfo('name') ?></title>
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php
@@ -738,9 +742,12 @@
//Content
//content types
- //Taxonomies
- $availableContent = array_filter($pages, function($page, $key) {
- return !is_numeric($key) && array_key_exists($key, JVB_CONTENT);
+ $all = array_merge(
+ Registrar::getRegistered('post'),
+ Registrar::getFeatured('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);
}, ARRAY_FILTER_USE_BOTH);
if (!empty ($availableContent)){
$content = $menu->addItem('Your Content', jvbDashIcon('book-bookmark'))
@@ -748,25 +755,30 @@
->defaultMenuClasses($menuClasses)
->defaultItemClasses($itemClasses);
foreach ($availableContent as $slug => $page) {
- $config = JVB_CONTENT[$slug];
- $item = $content->addItem($page, jvbDashIcon($config['icon']))
+ $registrar = Registrar::getInstance($slug);
+
+ $item = $content->addItem($page, $registrar->getIcon())
->url($this->baseURL.'/'.$slug);
- $taxonomies = array_filter(JVB_TAXONOMY, function ($value, $key) use ($slug) {
- return in_array($slug, $value['for_content']);
- },1);
- if (!empty ($taxonomies)) {
- //TODO: If we add a dedicated 'create item' page, remove this from the empty check
- $itemMenu = $item->submenu($slug);
- foreach ($taxonomies as $s => $config) {
- $itemMenu->addItem($config['plural'], $config['icon'])
- ->url($this->baseURL.'/'.$s);
+ if ($registrar->getType() === 'post') {
+ $taxonomies = $registrar->registrar->taxonomies;
+ if (!empty ($taxonomies)) {
+ //TODO: If we add a dedicated 'create item' page, remove this from the empty check
+ $itemMenu = $item->submenu($slug);
+ foreach ($taxonomies as $s) {
+ $taxRegistrar = Registrar::getInstance($s);
+ $itemMenu->addItem($taxRegistrar->getPlural(), $taxRegistrar->getIcon())
+ ->url($this->baseURL.'/'.$s);
+ }
}
}
+
}
}
+ //Taxonomies
+
//Settings
$settings = $menu->addItem('Settings', jvbDashIcon('faders'))
->submenu('settings')
@@ -854,7 +866,7 @@
return $content;
}
- if (Features::forSite()->has('referrals')) {
+ if (Site::has('referrals')) {
$whatever = JVB()->referrals()->getReferralWelcomeMessage($this->user->ID);
if (!empty($whatever)) {
return $whatever;
@@ -871,7 +883,7 @@
echo '<h2>What would you like to do today?</h2>';
- echo '<ul>';
+ echo '<ul class="dashboard">';
foreach ($pages as $slug => $page) {
if ($page === 'dash') {
continue;
@@ -968,7 +980,7 @@
$connection = (array_key_exists($page, $map)) ? $map[$page] : $page;
if ($connection !== 'integrations') {
- $userID = (jvbSiteHasMembership()) ? $this->user->ID : null;
+ $userID = (Site::has('has_membership')) ? $this->user->ID : null;
$integration = JVB()->connect($connection, $userID);
echo '<h1>Managing '.$integration->title.'</h1>';
@@ -1075,20 +1087,19 @@
<nav class="tabs row start" role="tablist">
<?php
$i=1;
- $content = JVB_CONTENT;
- $contentTax = array_filter(JVB_TAXONOMY, function ($tax) {
- return jvbCheck('is_content', $tax);
- });
- $taxonomies = JVB_TAXONOMY;
- foreach($contentTax as $key => $config) {
- unset($taxonomies[$key]);
+ $content = Registrar::getRegistered('post');
+ $contentTax = Registrar::getFeatured('is_content', 'term');
+ $taxonomies = Registrar::getRegistered('term');
+ foreach($contentTax as $index => $tax) {
+ unset($taxonomies[$index]);
}
$content = array_merge($content, $contentTax);
- foreach ($content as $type => $settings) {
+ foreach ($content as $type) {
+ $registrar = Registrar::getInstance($type);
$active = ($i === 1) ? ' active' : '';
?>
<button type="button" class="tab<?=$active?>" data-tab="<?=$type?>" role="tab" aria-selected="<?= ($active !== '') ? 'true' : 'false'?>">
- <h2><?=jvbDashIcon($settings['icon']??$key)?> <?= $settings['plural'] ?></h2>
+ <h2><?=jvbDashIcon($registrar->getIcon())?> <?= $registrar->getPlural() ?></h2>
</button>
<?php
$i++;
@@ -1099,8 +1110,9 @@
<option> ... Taxonomy</option>
<?php
- foreach ($taxonomies as $type => $settings) {
- echo '<option value="'.$type.'">'.$settings['plural'].'</option>';
+ foreach ($taxonomies as $type) {
+ $taxRegistrar = Registrar::getInstance($type);
+ echo '<option value="'.$type.'">'.$taxRegistrar->getPlural().'</option>';
}
?>
</select>
@@ -1124,11 +1136,10 @@
<?php
- $jvb_everything = array_merge(JVB_CONTENT, JVB_TAXONOMY);
- foreach ($jvb_everything as $type => $settings) {
- $meta = new MetaManager(null, 'form');
- $fields = jvbGetFields($type);
+
+ foreach (Registrar::getRegistered() as $type) {
+ $fields = Registrar::getFieldsFor($type);
?>
<template class="<?= $type ?>Table">
<table>
@@ -1197,7 +1208,7 @@
<?php
$config['type'] = 'text';
$config['description'] = '';
- $meta->render('form', $n, $config);
+ Form::render($n, null, $config);
?>
</td>
<?php
@@ -1212,10 +1223,9 @@
echo jvbNewModal(
'edit-modal '.$type,
'Edit '.ucfirst($type),
- $meta->renderForm('admin', [], $fields)
+ jvbRenderForm('admin', $fields)
);
}
-
return ob_get_clean();
}
@@ -1247,53 +1257,55 @@
$pages = [];
$pages[] = 'SEO';
// Add feature-dependent pages (non-config)
- if (Features::forSite()->has('referrals')) {
+ if (Site::has('referrals')) {
$pages[] = 'Referrals';
}
-
- if (Features::forMembership()->has('can_invite')) {
+ $membership = Site::membership();
+ if ($membership && $membership->has('can_invite')) {
$pages[] = 'Invites';
}
- if (Features::forMembership()->has('term_approval')) {
+ if ($membership && $membership->has('term_approval')) {
$pages[] = 'Approvals';
}
- if (Features::forMembership()->has('forum')) {
+ if ($membership && $membership->has('forum')) {
$pages[] = 'News';
}
- if (Features::forMembership()->has('member_content')) {
+ if ($membership && $membership->has('member_content')) {
$pages[] = 'Metrics';
}
- if (Features::forSite()->has('favourites')) {
+ if (Site::has('favourites')) {
$pages[] = 'Favourites';
}
- if (Features::anyContentHas('karma') || Features::anyTaxonomyHas('karma') || Features::anyUserHas('karma')) {
+ if (!empty(Registrar::getFeatured('karma'))) {
$pages[] = 'Karmic Score';
}
- if (Features::forSite()->has('notifications')) {
+ if (Site::has('notifications')) {
$pages[] = 'Notifications';
}
- if (Features::forSite()->has('support')) {
+ if (Site::has('support')) {
$pages[] = 'Support';
}
- if (Features::hasAnyIntegration()) {
+ if (Site::hasAnyIntegration()) {
$pages[] = 'Integrations';
}
// Add all content types (with config keys)
- foreach (JVB_CONTENT as $slug => $config) {
- $pages[$slug] = $config['plural'];
+ foreach (Registrar::getRegistered('post') as $slug) {
+ $registrar = Registrar::getInstance($slug);
+ $pages[$slug] = $registrar->getPlural();
}
- foreach (JVB_TAXONOMY as $slug=>$config) {
- $pages[$slug] = $config['plural'];
+ foreach (Registrar::getRegistered('term') as $slug) {
+ $registrar = Registrar::getInstance($slug);
+ $pages[$slug] = $registrar->getPlural();
}
// Allow filtering
@@ -1311,21 +1323,6 @@
return $pages;
}
- /**
- * Get pages available to a specific role
- * @param string $role The role slug (with or without BASE prefix)
- * @return array
- */
- protected function getRolePages(string $role):array
- {
- $role = jvbNoBase($role);
-
- if (!array_key_exists($role, JVB_USER)) {
- return [];
- }
-
- return Features::forUser($role)->getDashboardPages();
- }
/**
* Get pages that a specific user is allowed to access
@@ -1365,21 +1362,22 @@
//Default to Remove pages
$remove = true;
if (!is_numeric($key)) {
- $type = Features::getType($key);
+ $registrar = Registrar::getInstance($key);
+ $type = $registrar? $registrar->getType() : false;
if ($type) {
- $permission = RoleManager::getPlural($key);
+ $permission = JVB()->roles()->getPermission('edit', $key);
}
switch ($type) {
case 'content':
- if (user_can($userID, "edit_{$permission}")) {
+ if (user_can($userID, $permission)) {
$remove = false;
}
break;
case 'taxonomy':
- $config = Features::getConfig($key, 'taxonomy');
- if (array_key_exists('is_content', $config) && $config['is_content'] && (user_can($userID, "own_{$key}") || user_can($userID, "manage_{$key}"))) {
+ $registrar = Registrar::getInstance($key);
+ if ($registrar && $registrar->hasFeature('is_content') && (!empty(JVB()->roles()->getOwnedTerms($userID, $key)) || !empty(JVB()->roles()->getManagedTerms($userID, $key)))){
$remove = false;
- } else if (count(array_intersect($config['for_content'], array_keys($pages))) > 0) {
+ } else if (count(array_intersect($registrar->registrar->for, array_keys($pages))) > 0) {
$remove = false;
}
break;
@@ -1388,7 +1386,7 @@
switch ($slug) {
case 'Integrations':
foreach($roles as $role) {
- if (Features::hasAnyIntegration('user', $role)) {
+ if (Registrar::getInstance($role)->hasAnyIntegrations()) {
$remove = false;
}
}
@@ -1401,14 +1399,15 @@
}
}
if ($remove) {
- if ($canSkip || array_key_exists('invitable', $config)) {
+ //TODO: Figure out what $config was supposed to be
+ if ($canSkip || ($registrar && $registrar->hasFeature('invitable'))) {
$remove = false;
}
}
break;
case 'Approvals':
$canApprove = false;
- if (Features::forMembership()->has('term_approval')) {
+ if ($membership && $membership->has('term_approval')) {
if (array_key_exists('can_approve', JVB_MEMBERSHIP)) {
foreach ($roles as $role) {
if (in_array($role, JVB_MEMBERSHIP['can_approve'])) {
@@ -1439,20 +1438,17 @@
break;
case 'metrics':
foreach ($roles as $role) {
- if (!empty(Features::forUser($role)->getCreatableContent())) {
+ if (!empty(Registrar::getInstance($role)?->getCreatable())) {
$remove = false;
}
}
break;
case 'karmic-score':
foreach ($roles as $role) {
- $contents = Features::forUser($role)->getCreatableContent();
+ $contents = Registrar::getInstance($role)?->getCreatable();
if (!empty($contents)) {
- foreach($contents as $content) {
- if (Features::forContent($content)->has('karma')) {
- $remove = false;
- }
- }
+ $hasKarma = Registrar::getFeatured('karma');
+ $remove = empty(array_intersect($contents, $hasKarma));
}
}
break;
@@ -1498,7 +1494,7 @@
$creatable = [];
foreach ($roles as $role) {
- $roleCreatable = Features::forUser($role)->getCreatableContent();
+ $roleCreatable = Registrar::getInstance($role)?->getCreatable();
$creatable = array_merge($creatable, $roleCreatable);
}
@@ -1512,9 +1508,7 @@
*/
protected function getRolesWithDashboard():array
{
- return array_keys(array_filter(JVB_USER, function ($role) {
- return Features::forUser(array_search($role, JVB_USER))->has('has_dashboard');
- }));
+ return Registrar::getFeatured('has_dashboard', 'user');
}
/**
@@ -1534,20 +1528,4 @@
return count(array_intersect($dashboardRoles, $userRoles)) > 0;
}
- /**
- * Get the capability needed to access a content type
- * @param string $type
- * @return string
- */
- protected function getPermissionForType(string $type):string
- {
- // Check if it's a registered content type
- if (array_key_exists($type, JVB_CONTENT)) {
- $plural = JVB_CONTENT[$type]['plural'];
- return 'edit_'.$plural;
- }
-
- // Default to edit_{type}s
- return 'edit_'.$type.'s';
- }
}
--
Gitblit v1.10.0