From 275c0d74cd68677622a5431505c5c870c473063d Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 29 Mar 2026 21:40:15 +0000
Subject: [PATCH] =Seems to be working, huzzah! Added some changes for on-this-page nav

---
 inc/rest/routes/VoteRoutes.php |   39 +++++++++++++++++----------------------
 1 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/inc/rest/routes/VoteRoutes.php b/inc/rest/routes/VoteRoutes.php
index 1ddf49f..7f55f1d 100644
--- a/inc/rest/routes/VoteRoutes.php
+++ b/inc/rest/routes/VoteRoutes.php
@@ -2,10 +2,10 @@
 namespace JVBase\rest\routes;
 
 use JVBase\managers\CustomTable;
+use JVBase\registrar\Registrar;
 use JVBase\rest\Response;
 use JVBase\rest\Rest;
 use JVBase\rest\Route;
-use JVBase\utility\Features;
 use WP_REST_Request;
 use WP_REST_Response;
 use WP_Error;
@@ -46,7 +46,8 @@
 				'user' => 'integer',
 			])
 			->auth('user')
-			->rateLimit(30);
+			->rateLimit(30)
+			->register();
     }
 
     /**
@@ -57,7 +58,8 @@
     public function handleVote(WP_REST_Request $request):WP_REST_Response
     {
         $content = sanitize_text_field($request->get_param('content')??'');
-		if ((!Features::forContent($content)->has('karma') && !Features::forTaxonomy($content)->has('karma') && !Features::forUser($content)->has('karma'))) {
+		$registrar = Registrar::getInstance($content);
+		if (!$registrar || !$registrar->hasFeature('karma')) {
 			return Response::validationError(['message' => __('Invalid content', 'jvb')]);
 		}
 
@@ -74,12 +76,7 @@
 
         $operation = sanitize_text_field($request->get_param('id'));
 
-		$type = match(true) {
-			array_key_exists($content, JVB_CONTENT) => 'post',
-			array_key_exists($content, JVB_TAXONOMY) => 'term',
-			array_key_exists($content, JVB_USER) => 'user',
-			default => false
-		};
+		$type = Registrar::getInstance($content)->getType()??false;
 		if (!$type) {
 			return Response::validationError(['message' => __('Invalid content type', 'jvb')]);
 		}
@@ -281,22 +278,20 @@
 
 		$votes = [];
 
-		foreach (jvbGlobalKarma() as $type => $content_types) {
-			foreach ($content_types as $content_type) {
-				$table = CustomTable::for('karma_' . $content_type);
+		foreach (Registrar::getFeatured('has_karma') as $type) {
+			$table = CustomTable::for('karma_' . $type);
 
-				// Skip if table doesn't exist
-				global $wpdb;
-				if ($wpdb->get_var("SHOW TABLES LIKE '{$table->getFullTableName()}'") != $table->getFullTableName()) {
-					continue;
-				}
+			// Skip if table doesn't exist
+			global $wpdb;
+			if ($wpdb->get_var("SHOW TABLES LIKE '{$table->getFullTableName()}'") != $table->getFullTableName()) {
+				continue;
+			}
 
-				$results = $table->where(['user_id' => $user])->getResults();
+			$results = $table->where(['user_id' => $user])->getResults();
 
-				if (!empty($results)) {
-					foreach ($results as $vote) {
-						$votes[$content_type][$vote->item_id] = $vote->vote;
-					}
+			if (!empty($results)) {
+				foreach ($results as $vote) {
+					$votes[$type][$vote->item_id] = $vote->vote;
 				}
 			}
 		}

--
Gitblit v1.10.0