From 772462eeca3002a1d52508aeba485aab2b4742ad Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 03 Mar 2026 19:06:19 +0000
Subject: [PATCH] =MAJOR OVERHAUL. Likely should have made a new branch ages ago. Key changes: Registrar.php is the base for custom post types, taxonomies, and user roles. Replaces JVB_CONTENT, JVB_TAXONOMY, and JVB_USER constants, eliminates most of Features.php (except for JVB_SITE, JVB_MEMBERSHIP), and has built in sanitizing and validation via sub-classes. Also started a major overhaul of the Schema output. Created a shit ton of property traits and classes to help sanitize and ensure proper data for different schema types. Still a bunch to do, but better to be starting committing changes here on this other branch.
---
inc/managers/DirectoryManager.php | 127 +++++++++++++++++++-----------------------
1 files changed, 57 insertions(+), 70 deletions(-)
diff --git a/inc/managers/DirectoryManager.php b/inc/managers/DirectoryManager.php
index f8048b6..46f4ef8 100644
--- a/inc/managers/DirectoryManager.php
+++ b/inc/managers/DirectoryManager.php
@@ -5,9 +5,7 @@
exit;
}
-use JVBase\registry\PostTypeRegistrar;
-use JVBase\managers\Cache;
-use JVBase\utility\Features;
+use JVBase\registrar\Registrar;
use WP_Block;
use WP_Query;
@@ -37,12 +35,14 @@
$this->cache->flush();
}
+ jvb_register_do_once('buildDirectories', [$this, 'activate']);
add_action('init', [$this, 'registerDirectories']);
add_action('render_block', [$this, 'renderBlock'], 99999, 3);
}
public function registerDirectories():void
{
+
$singular = (array_key_exists('directory_label', JVB_SITE)) ? JVB_SITE['directory_label'][0] : 'Directory';
$plural = (array_key_exists('directory_label', JVB_SITE)) ? JVB_SITE['directory_label'][1] : 'Directories';
$config = [
@@ -87,25 +87,25 @@
if (!$directories) {
$directories = [];
//content
- if(Features::anyContentHas('show_directory')) {
- foreach (JVB_CONTENT as $key => $config) {
- if (Features::forContent($key)->has('show_directory')) {
- $directories[$key] = 'content';
- }
+
+ $content = Registrar::getFeatured('show_directory', 'post');
+ if(!empty($content)) {
+ foreach ($content as $key) {
+ $directories[$key] = 'content';
}
}
- if(Features::anyTaxonomyHas('show_directory')) {
- foreach (JVB_TAXONOMY as $key=>$config) {
- if (Features::forTaxonomy($key)->has('show_directory')) {
- $directories[$key] = 'taxonomy';
- }
+
+ $taxonomies = Registrar::getFeatured('show_directory', 'term');
+ if(!empty($taxonomies)) {
+ foreach ($taxonomies as $key) {
+ $directories[$key] = 'taxonomy';
}
}
- if (Features::anyUserHas('show_directory')) {
- foreach(JVB_USER as $key=>$config) {
- if (Features::forUser($key)->has('show_directory')) {
- $directories[$key] = 'user';
- }
+
+ $users = Registrar::getFeatured('show_directory', 'user');
+ if(!empty($users)) {
+ foreach ($users as $key) {
+ $directories[$key] = 'user';
}
}
@@ -113,34 +113,28 @@
}
return $directories;
}
- protected function getConfigFromType(string $type):array
- {
- if (!array_key_exists($type, $this->directories)) {
- return [];
- }
- return match ($this->directories[$type]) {
- 'content' => JVB_CONTENT[$type],
- 'taxonomy' => JVB_TAXONOMY[$type],
- 'user' => JVB_USER[$type],
- default => [],
- };
- }
-
- public static function activate()
+ public function activate():void
{
- $tmp = new self();
- $tmp->registerDirectories();
+// $tmp = new self();
+// $this->registerDirectories();
$created = [];
$directories = [];
+ $this->getDirectories();
+ foreach($this->directories as $directory => $type) {
+ $registrar = Registrar::getInstance($directory);
+ if (!$registrar){
+ error_log('Could not find registrar for making directory for '.$directory);
+ continue;
+ }
- foreach($tmp->directories as $directory => $type) {
- $config = $tmp->getConfigFromType($directory);
- $title = $tmp->directoryTitle($config);
+ $config = $registrar->getConfig('directory');
+
+ $title = $config['title'];
$excerpt = implode(' ', $config['description']??[]);
$ID = wp_insert_post([
- 'post_type' => BASE.'directory',
+ 'post_type' => BASE.'directory',
'post_title' => $title,
'post_status' => 'publish',
'post_excerpt' => $excerpt,
@@ -162,13 +156,7 @@
'extra' => $config[$directory]['directory_extra'] ??[],
];
}
- $isGrouped = match ($type) {
- 'content' => Features::forContent($directory)->has('isGrouped'),
- 'taxonomy' => Features::forTaxonomy($directory)->has('isGrouped'),
- 'user' => Features::forUser($directory)->has('isGrouped'),
- default => false,
- };
- if ($isGrouped) {
+ if ($config['isGrouped']) {
$title = $title.', but Grouped';
$slug = sanitize_title($title).'-grouped';
$excerpt = $config['groupedDescription']??'Too many options? This is grouped by type.';
@@ -237,15 +225,17 @@
'posts_per_page' => -1,
]);
foreach($all->posts as $post) {
+ $config = Registrar::getInstance($post->post_name)->getConfig('directory')??false;
+
$saved[$post->post_name] = [
'slug' => $post->post_name,
'title' => $post->post_title,
'ID' => $post->ID,
'url' => get_the_permalink($post->ID),
'page' => $post->post_title,
- 'description' => $this->getConfigFromType($post->post_name)['description']??'',
+ 'description' => ($config) ?$config['description'] :'',
'type' => get_post_meta($post->ID, self::$type,true),
- 'extra' => $this->getConfigFromType($post->post_name)['directory_extra']??[],
+ 'extra' => ($config) ?$config['directory_extra'] : [],
];
}
update_option(BASE.'directory_list', $saved);
@@ -269,16 +259,10 @@
return $this->directoryList;
}
- public static function getConfig(int $ID):array
+ public static function getConfig(int $ID):Registrar|false
{
- $type = get_post_meta($ID, self::$type, true);
$slug = get_post_meta($ID, self::$slug, true);
- return match ($type) {
- 'content' => JVB_CONTENT[$slug],
- 'taxonomy' => JVB_TAXONOMY[$slug],
- 'user' => JVB_USER[$slug],
- default => [],
- };
+ return Registrar::getInstance($slug);
}
public function letters():array
@@ -342,7 +326,7 @@
public function directories(string $search = 'all'):array
{
- $directories = $this->getDirectories();
+ $directories = $this->getDirectoryList();
if ($search === 'all') {
return $directories;
}
@@ -364,11 +348,11 @@
<p>You like lists? We\'ve got \'em!</p>
<ul class="directories">';
foreach ($this->directoryList as $slug => $directory) {
- $config = $this->getConfigFromType($slug);
+ $config = Registrar::getInstance($slug);
$aOpen = '<a href="'.$directory['url'].'" title="See our list of '.$directory['title'].'">';
$aClose = '</a>';
$cache .= '<li class="directory col start">
- '. $aOpen.jvbIcon(array_key_exists('icon', $config) ? $config['icon']:'list-dashes').$directory['title'].$aClose;
+ '. $aOpen.jvbIcon($config->getIcon() !== '' ? $config->getIcon() :'list-dashes').$directory['title'].$aClose;
if (!empty($directory['description'])) {
$cache .= '<div class="description">';
foreach ($directory['description'] as $description) {
@@ -392,8 +376,8 @@
$cache = '<nav class="directory condensed"><ul>';
foreach ($this->getDirectoryList() as $slug => $directory) {
$actualSlug = str_replace('-grouped', '', $slug);
- $config = $this->getConfigFromType($actualSlug);
- $icon = jvbIcon($config['icon']??'');
+ $config = Registrar::getInstance($actualSlug);
+ $icon = $config->getIcon() !== '' ? jvbIcon($config->getIcon()) : '';
$cache .= '<li id="'.$slug.'">
<a href="'.$directory['url'].'" class="'.$actualSlug.'">'.
$icon.$directory['title'].'
@@ -421,7 +405,8 @@
}
$type = $this->directories[$slug];
- $config = $this->getConfigFromType($slug);
+ $registrar = Registrar::getInstance($slug);
+ $config = $registrar->getConfig('directory');
$paged = isset($_GET['page']) ? max(1, (int)$_GET['page']) : 1;
@@ -429,10 +414,10 @@
return $this->cache->remember(
$cacheKey,
- function() use ($slug, $type, $config, $paged) {
- $out = '<h1>' . $this->directoryTitle($config) . '</h1>';
+ function() use ($slug, $type, $registrar, $config, $paged) {
+ $out = '<h1>' . $this->directoryTitle($registrar) . '</h1>';
$out .= '<div class="description">';
- foreach ($config[$slug]['description'] ?? [] as $p) {
+ foreach ($config['description'] ?? [] as $p) {
$out .= '<p>' . $p . '</p>';
}
$out .= '</div>';
@@ -451,13 +436,14 @@
'order' => 'ASC'
];
- if (Features::forContent($slug)->has('is_timeline')) {
+
+ if ($registrar->hasFeature('is_timeline')) {
$args['post_parent'] = 0;
}
$get = new WP_Query($args);
- $hasExtra = Features::forContent($slug)->has('directory_extra');
+ $hasExtra = $registrar->hasFeature('directory_extra');
if ($get->have_posts()) {
while ( $get->have_posts() ) {
$get->the_post();
@@ -716,9 +702,10 @@
return $content;
}
- protected function directoryTitle(array $config):string
+ protected function directoryTitle(Registrar $registrar):string
{
- return array_key_exists('directory', $config) ? $config['directory'] : $config['plural'];
+ $config = $registrar->getConfig('directory');
+ return $config['title']?: $registrar->getPlural();
}
public function referAs($plural = false):string
@@ -827,14 +814,14 @@
$slug . '_letter_page_map',
function() use ($type, $slug) {
$titles = [];
-
+ $registrar = Registrar::getInstance($slug);
switch ($type) {
case 'content':
global $wpdb;
$post_type = jvbCheckBase($slug);
$where = $wpdb->prepare("post_type = %s AND post_status = 'publish'", $post_type);
- if (Features::forContent($slug)->has('is_timeline')) {
+ if ($registrar && $registrar->hasFeature('is_timeline')) {
$where .= " AND post_parent = 0";
}
--
Gitblit v1.10.0