From d7dbe7fee362d587dfc334135d9581b6216a4295 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 23 Nov 2025 04:13:56 +0000
Subject: [PATCH] =Timeline block, and feed block updated. DataStore.js refactored to not block rendering

---
 jvb.php |  298 ++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 232 insertions(+), 66 deletions(-)

diff --git a/jvb.php b/jvb.php
index 9e57dd1..38dbb27 100644
--- a/jvb.php
+++ b/jvb.php
@@ -10,6 +10,7 @@
 */
 
 use JVBase\JVB;
+use JVBase\managers\IconsManager;
 use JVBase\utility\Checker;
 use JVBase\utility\Features;
 
@@ -18,14 +19,82 @@
     exit;
 }
 
+/**
+ * Track REST API errors by wrapping request execution
+ */
+add_filter('rest_pre_dispatch', function($result, $server, $request) {
+	// Store request details globally for error logging
+	$GLOBALS['jvb_rest_request'] = [
+		'route' => $request->get_route(),
+		'method' => $request->get_method(),
+		'params' => $request->get_params(),
+		'time' => microtime(true),
+	];
+
+	// Set up error handler for this request
+	set_error_handler(function($errno, $errstr, $errfile, $errline) {
+		if (!(error_reporting() & $errno)) {
+			return false;
+		}
+
+		$context = array_merge($GLOBALS['jvb_rest_request'] ?? [], [
+			'error_type' => $errno,
+			'error_message' => $errstr,
+			'file' => $errfile,
+			'line' => $errline,
+			'user_id' => get_current_user_id(),
+		]);
+
+		error_log('JVB REST Error: ' . json_encode($context));
+
+		return false; // Let PHP handle it normally too
+	});
+
+	return $result;
+}, 10, 3);
+
+add_filter('rest_post_dispatch', function($result, $server, $request) {
+	// Restore default error handler
+	restore_error_handler();
+
+	// Check for fatal errors that occurred during request
+	$error = error_get_last();
+	if ($error && in_array($error['type'], [E_ERROR, E_USER_ERROR, E_PARSE, E_COMPILE_ERROR])) {
+		$context = array_merge($GLOBALS['jvb_rest_request'] ?? [], [
+			'fatal_error' => $error,
+			'user_id' => get_current_user_id(),
+		]);
+
+		error_log('JVB REST Fatal: ' . json_encode($context));
+	}
+
+	// Clean up
+	unset($GLOBALS['jvb_rest_request']);
+
+	return $result;
+}, 10, 3);
+
+
 const JVB_LOCAL = 'northeh.test';
 
+function jvbIgnoredPostTypes():array
+{
+	return [BASE.'directory', BASE.'dash', 'attachment', 'revision', 'nav_menu_item'];
+}
 add_filter('show_admin_bar', '__return_false');
-const JVB_TESTING = false;
+const JVB_TESTING = true;
 
 const JVB_DIR = WP_PLUGIN_DIR . '/jvb';
 define('JVB_URL', plugin_dir_url(__FILE__));
 
+// Session Security
+define('JVB_SESSION_FINGERPRINT', true);
+
+// Login Security
+define('JVB_MAX_LOGIN_ATTEMPTS', 5);
+define('JVB_LOCKOUT_DURATION', 15 * MINUTE_IN_SECONDS);
+
+
 require(JVB_DIR.'/base/_setup.php');
 //error_log('###############################################');
 //error_log('Registered Base');
@@ -54,15 +123,25 @@
 global $jvb_everything;
 $jvb_everything = array_merge(JVB_CONTENT, JVB_TAXONOMY);
 
+
 require(JVB_DIR . '/inc/registry/_setup.php');
 
 require(JVB_DIR . '/activate.php');
 
 require(JVB_DIR . '/inc/helpers/all.php');
+require(JVB_DIR . '/inc/meta/_setup.php');
 require(JVB_DIR . '/inc/managers/_setup.php');
+
+function jvbIcon($name, $options = []) {
+	return IconsManager::getInstance()->getIcon($name, $options);
+}
+
+function jvbCSSIcon($name, $options = []) {
+	$style = array_key_exists('style', $options) ? $options['style'] : null;
+	return IconsManager::getInstance()->getCSSIcon($name, $style);
+}
 require(JVB_DIR . '/inc/integrations/_setup.php');
 require(JVB_DIR . '/inc/rest/_setup.php');
-require(JVB_DIR . '/inc/meta/_setup.php');
 
 add_filter( 'cron_schedules', 'jvbCronSchedules');
 function jvbCronSchedules($schedules)
@@ -96,7 +175,7 @@
 function jvbUserCheck():void
 {
     if (is_admin() && isOurPeople()) {
-        wp_redirect(get_home_url(2, '/dash'));
+        wp_redirect(get_home_url(null, '/dash'));
         exit;
     }
 }
@@ -161,7 +240,7 @@
 /**
  * Scripts
  */
-add_action('wp_enqueue_scripts', 'jvbScripts', 999);
+add_action('wp_enqueue_scripts', 'jvbScripts', 10);
 
 function jvbScripts():void
 {
@@ -173,7 +252,7 @@
         'jvb-utility',
         JVB_URL.'assets/js/min/utility.min.js',
         [],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -187,7 +266,7 @@
 			'jvb-queue',
 			'jvb-data-store'
 		],
-		'1.0.0',
+		'1.0.1',
 		[
 			'strategy'    => 'defer',
 			'in_footer'    => true,
@@ -200,20 +279,48 @@
 			'jvb-queue',
 			'jvb-data-store'
 		],
-		'1.0.0',
+		'1.0.1',
 		[
 			'strategy'    => 'defer',
 			'in_footer'    => true,
 		]
 	);
 
+	wp_register_script(
+		'jvb-settings',
+		JVB_URL.'assets/js/min/settings.min.js',
+		[
+//			'jvb-queue',
+			'jvb-utility',
+			'jvb-data-store'
+		],
+		'1.0.1',
+		[
+			'strategy'    => 'defer',
+			'in_footer'    => true,
+		]
+	);
+
+	wp_register_script(
+		'jvb-popup',
+		JVB_URL.'assets/js/min/popup.min.js',
+		[
+			'jvb-a11y'
+		],
+		'1.0.1',
+		[
+			'strategy'	=> 'defer',
+			'in_footer'	=> true
+		]
+	);
+
     //Main js image resizing, and gallery
     //TODO: lots of overlap between modals and this, utilize a11y for trapFocus,
     wp_register_script(
         'jvb-media',
         JVB_URL.'assets/js/min/media.min.js',
         [],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer' => true,
@@ -229,7 +336,7 @@
 			'jvb-modal',
 			'jvb-a11y'
 		],
-		'1.0.0',
+		'1.0.1',
 		[
 			'strategy'	=> 'defer',
 			'in_footer' => true,
@@ -254,9 +361,11 @@
         JVB_URL.'assets/js/min/gallery.min.js',
         [
 			'jvb-utility',
-			'jvb-queue'
+//			'jvb-queue',
+			'jvb-modal',
+//			'jvb-swiper',
 		],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -264,10 +373,23 @@
     );
 
 	wp_register_script(
+		'jvb-swiper',
+		JVB_URL.'assets/js/min/swiper.min.js',
+		[
+			'jvb-utility',
+		],
+		'1.0.1',
+		[
+			'strategy'    => 'defer',
+			'in_footer'    => true,
+		]
+	);
+
+	wp_register_script(
 		'jvb-integrations',
 		JVB_URL.'assets/js/min/integrations.min.js',
 		[],
-		'1.0.0',
+		'1.0.1',
 		[
 			'strategy'	=> 'defer',
 			'in_footer'	=> true
@@ -305,7 +427,7 @@
         'jvb-page-nav',
         JVB_URL.'assets/js/min/page-nav.min.js',
         [],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -317,7 +439,7 @@
         'jvb-a11y',
         JVB_URL.'assets/js/min/a11y.min.js',
         [],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -331,7 +453,7 @@
         [
 
         ],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -343,7 +465,7 @@
         'jvb-cache',
         JVB_URL.'assets/js/min/cache.min.js',
         [],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -354,7 +476,7 @@
 		'jvb-data-store',
 		JVB_URL.'assets/js/min/dataStore.min.js',
 		[],
-		'1.0.0',
+		'1.0.1',
 		[
 			'strategy'	=> 'defer',
 			'in_footer'	=> true,
@@ -368,7 +490,7 @@
         [
             'jvb-a11y'
         ],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -382,7 +504,7 @@
         [
             'jvb-a11y'
         ],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -398,8 +520,9 @@
             'jvb-error',
             'jvb-data-store',
             'jvb-utility',
+			'jvb-popup'
         ],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -418,7 +541,7 @@
             'jvb-modal',
 //            'jvb-loading'
         ],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -429,7 +552,7 @@
 		'jvb-creator',
 		JVB_URL.'assets/js/min/creator.min.js',
 		['jvb-selector'],
-		'1.0.0',
+		'1.0.1',
 		[
 			'strategy'    => 'defer',
 			'in_footer'		=> true
@@ -443,7 +566,7 @@
         [
             'jvb-selector'
         ],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -474,17 +597,49 @@
 
     //Upload Manager
     wp_register_script(
+        'jvb-handle-selection',
+        JVB_URL.'assets/js/min/handleSelection.min.js',
+        [
+			'jvb-a11y',
+            'jvb-utility',
+        ],
+        '1.0.1',
+        [
+            'strategy'    => 'defer',
+            'in_footer'    => true,
+        ]
+    );
+    wp_register_script(
+        'jvb-drag-handler',
+        JVB_URL.'assets/js/min/dragHandler.min.js',
+        [
+			'jvb-a11y',
+            'jvb-utility',
+        ],
+        '1.0.1',
+        [
+            'strategy'    => 'defer',
+            'in_footer'    => true,
+        ]
+    );
+
+    //Upload Manager
+    wp_register_script(
         'jvb-uploader',
         JVB_URL.'assets/js/min/uploader.min.js',
         [
+			'sortable-js',
 			'jvb-cache',
 			'jvb-a11y',
             'jvb-utility',
+			'jvb-handle-selection',
+			'jvb-modal',
+			'jvb-drag-handler',
 //            'jvb-loading',
             'jvb-queue',
             'jvb-notifications'
         ],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -532,7 +687,7 @@
         [
             'jvb-utility',
         ],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer' => true,
@@ -545,11 +700,14 @@
         JVB_URL.'assets/js/min/form.min.js',
         [
             'jvb-utility',
+            'jvb-tabs',
             'jvb-selector',
             'jvb-uploader',
-			'sortable-js'
+			'sortable-js',
+			'jvb-populate-form',
+			'jvb-quill',
         ],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -560,7 +718,7 @@
 		'jvb-populate-form',
 		JVB_URL.'assets/js/min/populate.min.js',
 		[],
-		'1.0.0',
+		'1.0.1',
 		[
 			'strategy'	=> 'defer',
 			'in_footer'	=> true,
@@ -572,7 +730,7 @@
 		[
 			'quill-js'
 		],
-		'1.0.0',
+		'1.0.1',
 		[
 			'strategy'	=> 'defer',
 			'in_footer'	=> true,
@@ -584,6 +742,7 @@
         JVB_URL.'assets/js/min/crud.min.js',
         [
 			'jvb-selector',
+			'jvb-settings',
             'jvb-a11y',
             'jvb-error',
             'jvb-data-store',
@@ -595,7 +754,7 @@
 			'jvb-view',
 			'jvb-modal'
         ],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -606,12 +765,14 @@
 		'jvb-view',
 		JVB_URL.'assets/js/min/view.min.js',
 		[
+			'jvb-settings',
 			'jvb-a11y',
 			'jvb-utility',
 			'jvb-data-store',
-			'jvb-error'
+			'jvb-error',
+			'jvb-populate-form'
 		],
-		'1.0.0',
+		'1.0.1',
 		[
 			'strategy'	=> 'defer',
 			'in_footer'	=> true,
@@ -627,7 +788,7 @@
             'jvb-form',
             'jvb-queue'
         ],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -643,7 +804,7 @@
             'jvb-form',
             'jvb-queue'
         ],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -664,7 +825,7 @@
             'jvb-selector',
             'jvb-post-selector',
         ],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -685,7 +846,7 @@
             'jvb-selector',
             'jvb-notifications',
         ],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -706,7 +867,7 @@
             'jvb-selector',
             'jvb-tabs',
         ],
-        '1.0.0',
+        '1.0.1',
         [
             'strategy'    => 'defer',
             'in_footer'    => true,
@@ -728,27 +889,22 @@
 		JVB_URL.'assets/js/min/navigation.min.js',
 	);
 
-
-
     add_action('wp_head', 'jvbInlineNavStyles');
 
-    wp_enqueue_script('jvb-queue');
+	if (Features::forSite()->has('dashboard')) {
+		wp_enqueue_script('jvb-queue');
+	}
+
+	wp_enqueue_script('jvb-settings');
     wp_enqueue_script('jvb-navigation');
 //    wp_enqueue_script('jvb-ui');
     wp_enqueue_script('jvb-media');
+	wp_enqueue_script('jvb-gallery');
     wp_enqueue_script('jvb-cache');
-    wp_localize_script(
-        'jvb-cache',
-        'cacheJVB',
-        [
-            'cache' => json_encode(jvbGetCache())
-        ]
-    );
 
 
 
     $userID = get_current_user_id();
-	$icons = new \JVBase\JVBIcons();
     $queue = (is_user_logged_in()) ?
         [
             'api'             => rest_url('jvb/v1/'),
@@ -757,7 +913,6 @@
             'dash'            => wp_create_nonce('dash-'.$userID),
             'favourites'    => wp_create_nonce('favourites-'.$userID),
             'notifications'    => wp_create_nonce('notifications-'.$userID),
-            'icons'            => $icons->localizeIcons(),
 			'labels'			=> jvbGetLabels(),
         ] :
         [
@@ -765,11 +920,12 @@
             'nonce'       => wp_create_nonce('wp_rest'),
             'currentUser' => false,
             'redirect'    => wp_login_url(home_url(add_query_arg(null, null))), // Current URL as redirect
-            'icons'       => $icons->localizeIcons(),
 			'labels'			=> jvbGetLabels(),
         ];
 
-    wp_localize_script('jvb-queue', 'jvbSettings', $queue);
+    wp_localize_script('jvb-utility', 'jvbSettings', $queue);
+
+
 
 	$initUserSettings = 'async function initUserItems() {
 	if (!jvbSettings.currentUser) return;
@@ -873,7 +1029,7 @@
 //        ');
 //        }
     }
-    if (is_user_logged_in()) {
+    if (is_user_logged_in() && Features::forSite()->has('notifications')) {
         wp_enqueue_script('jvb-notifications');
 
         wp_localize_script('jvb-notifications', 'notificationSettings', array(
@@ -891,6 +1047,10 @@
 
     jvbAddScriptDependency('jvb-feed-view-script', 'jvb-queue');
     jvbAddScriptDependency('jvb-feed-view-script', 'jvb-selector');
+    jvbAddScriptDependency('jvb-feed-view-script', 'jvb-data-store');
+    jvbAddScriptDependency('jvb-feed-view-script', 'jvb-cache');
+    jvbAddScriptDependency('jvb-feed-view-script', 'jvb-a11y');
+    jvbAddScriptDependency('jvb-feed-view-script', 'jvb-utility');
     jvbAddScriptDependency('jvb-feed-view-script', 'jvb-gallery');
 //    jvbAddScriptDependency('jvb-feed-view-script', 'jvb-loading');
 	jvbAddScriptDependency('jvb-forms-view-script', 'jvb-queue');
@@ -949,21 +1109,27 @@
 //add_action('wp_head', 'jvbDumpIt');
 function jvbDumpIt()
 {
-
 }
 
-//add_filter('map_meta_cap', function($caps, $cap, $user_id, $args) {
-//	error_log('Caps: '.print_r($caps, true));
-//	error_log('Cap: '.print_r($cap, true));
-//	error_log('User ID: '.print_r($user_id, true));
-//	error_log('Args: '.print_r($args, true));
-//	return $caps;
-//}, 10, 4);
+add_action('after_setup_theme', 'jvbImageSize');
+function jvbImageSize():void
+{
+	add_theme_support('post-thumbnails');
+	add_image_size( 'tiny', 50, 50, false );
+}
 
-add_action( 'doing_it_wrong_run', function( $function, $message, $version ) {
-	if ( 'map_meta_cap' === $function ) {
-		error_log( "Map Meta Cap Wrong: $message" );
-		error_log( print_r( wp_debug_backtrace_summary( null, 0, false ), true ) );
-	}
-}, 10, 3 );
 
+//
+//add_action('rest_api_init', function() {
+//	error_log('User ' . get_current_user_id() . ' can edit pages: ' . (current_user_can('edit_pages') ? 'yes' : 'no'));
+//	error_log('User roles: ' . print_r(wp_get_current_user()->roles, true));
+//});
+//
+//add_filter('rest_pre_dispatch', function($result, $server, $request) {
+//	if (strpos($request->get_route(), '/wp/v2/pages') !== false) {
+//		error_log('Pages request - User: ' . get_current_user_id());
+//		error_log('Can edit pages: ' . (current_user_can('edit_pages') ? 'yes' : 'no'));
+//		error_log('Nonce: ' . $request->get_header('X-WP-Nonce'));
+//	}
+//	return $result;
+//}, 10, 3);

--
Gitblit v1.10.0