Jake Vanderwerf
2026-08-26 ccf5e61a075c35d24befc175994b5cb8957ca322
inc/rest/routes/NewsRoutes.php
@@ -1,6 +1,7 @@
<?php
namespace JVBase\rest\routes;
use JVBase\Instance;
use JVBase\rest\PermissionHandler;
use JVBase\rest\Rest;
use JVBase\meta\Meta;
@@ -17,6 +18,7 @@
class NewsRoutes extends Rest
{
   use Instance;
    protected int $per_page;
    protected bool|object $manager = false;
    public function __construct()
@@ -52,7 +54,6 @@
         ->rateLimit(20)
         ->post([$this, 'handleNewsOperation'])
         ->args([
            'user' => 'integer|required',
            'id' => 'string|required',
            'post_title' => 'string|required',
            'post_excerpt' => 'string',
@@ -60,13 +61,15 @@
            'type' => 'integer',
         ])
         ->auth(PermissionHandler::combine(['user','nonce',['actionNonce'=>'dash-']]))
         ->rateLimit(30);
         ->rateLimit(30)
         ->register();
      Route::for(Route::pattern('news/{id}'))
         ->get([$this, 'getNewsItem'])
         ->arg('id', 'integer|required')
         ->auth(PermissionHandler::combine(['user','nonce', ['actionNonce'=>'dash-']]))
         ->rateLimit(30);
         ->rateLimit(30)
         ->register();
    }
    /**
@@ -76,9 +79,9 @@
     */
    public function handleNewsOperation(WP_REST_Request $request):WP_REST_Response
    {
        $queue = JVB()->queue();
        $queue = Queue::getInstance();
        $data = $request->get_params();
        $user = absint($data['user']);
        $user = get_current_user_id();
        $operationID = sanitize_text_field($data['id']);
        unset($data['user']);
@@ -105,8 +108,8 @@
    public function getNews(WP_REST_Request $request):WP_REST_Response
    {
        $args = $this->buildQueryArgs($request);
        $key = $this->cache->generateKey($args);
        $cache = $this->cache->get($key);
        $cache = $this->cache->get($args);
        if ($cache) {
             return $this->success($cache);
        }
@@ -122,7 +125,7 @@
            'total_pages'   => $query->max_num_pages
        ];
        $this->cache->set($key, $results);
        $this->cache->set($args, $results);
        return $this->success($results);
    }
@@ -196,7 +199,7 @@
    {
        if (array_key_exists('orderby', $data) && $data['orderby'] === 'random') {
            // Handle random ordering
            $current_seed = jvbGetRandomSeed();
            $current_seed = floor(time() / 1800);
            $args['orderby'] = 'RAND(' . $current_seed . ')';
            unset($args['order']);
        } else {
@@ -322,7 +325,7 @@
        $artist = jvbContentFromUser($post->post_author);
        $upvotes = (int) get_post_meta($post->ID, BASE.'upvotes', true);
        $downvotes = (int) get_post_meta($post->ID, BASE.'downvotes', true);
        $comments = JVB()->routes('comments')->getItemResponse($post->ID, BASE.'news');
        $comments = ResponseRoutes::getInstance()->getItemResponse($post->ID, ['post_type' => BASE.'news']);
        return [
            'id'            => $post->ID,