Jake Vanderwerf
2026-01-01 de699440ff94e9c0d8e8b5201ee93179c085bf60
inc/rest/routes/FeedRoutes.php
@@ -32,17 +32,17 @@
      $this->cache_name = 'feed';
      $this->cache_ttl = 86400;
      parent::__construct();
      $this->cache->clear();
   }
   public function init():void
   {
      $this->cache->clear();
      $this->checker = Checker::getInstance();
      if (jvbSiteUsesUmami()) {
         $this->tracker = JVB()->connect('umami');
      }
      $this->cache->clear();
      $this->setupCacheConnections();
   }
@@ -111,9 +111,9 @@
      if (!$post || is_wp_error($post)) {
         return [];
      }
      return $cache->remember($postID,
         function() use ($postID, $type, $metaType, $post, $skip) {
//
//    return $cache->remember($postID,
//       function() use ($postID, $type, $metaType, $post, $skip) {
            $config = null;
            switch ($metaType) {
               case 'post':
@@ -150,10 +150,10 @@
               return $field['type'] === 'taxonomy';
            });
            foreach ($temp as $key => $config) {
               if (array_key_exists($key, $out) && $out[$key] !== '') {
                  $IDs = array_map('absint', explode(',', $out[$key]));
               if (array_key_exists($key, $out['fields']) && $out['fields'][$key] !== '') {
                  $IDs = array_map('absint', explode(',', $out['fields'][$key]));
                  $data = [];
                  $icon = JVB_TAXONOMY[$config['taxonomy']]['icon']??'triangle';
                  $icon = JVB_TAXONOMY[$config['taxonomy']]['icon']??jvbDefaultIcon();
                  foreach ($IDs as $ID) {
                     $term = get_term($ID, jvbCheckBase($config['taxonomy']));
                     if ($term && !is_wp_error($term)) {
@@ -179,9 +179,10 @@
            $temp = array_filter($fields, function($field) {
               return in_array($field['type'], [ 'upload', 'image', 'gallery']);
            });
            foreach ($temp as $key => $config) {
               if (array_key_exists($key, $out) && $out[$key] !== '') {
                  $IDs = array_map('absint', explode(',',$out[$key]));
               if (array_key_exists($key, $out['fields']) && $out['fields'][$key] !== '') {
                  $IDs = array_map('absint', explode(',',$out['fields'][$key]));
                  foreach ($IDs as $ID) {
                     $imgIDs[$ID] = jvbImageData($ID);
                  }
@@ -191,7 +192,7 @@
            $out['id'] = $postID;
            $out['content'] = $type;
            $out['icon'] = $config['icon']??'triangle';
            $out['icon'] = $config['icon']??jvbDefaultIcon();
            if ($this->tracker) {
               $args = ($metaType === 'post') ? ['owner_id' => $post->post_author] : [];
@@ -214,12 +215,14 @@
                  $out['url'] = get_the_permalink($postID);
                  break;
            }
            return $out;
         }
      );
//          return $out;
//       }
//    );
      return $out;
   }
   protected function initTimelineFields(string $content):void
   {
      $content = jvbNoBase($content);
@@ -270,7 +273,7 @@
         $images[$f['post_thumbnail']] = jvbImageData((int) $f['post_thumbnail']);
      }
      $item['fields']['order'] = $subFields;
      $item['fields']['timeline'] = $subFields;
      $item['images'] = $item['images'] + $images;
      return $item;
@@ -336,7 +339,6 @@
   protected function buildRequestArgs(WP_REST_Request $request): array
   {
      $data = $request->get_params();
      error_log('Feed Request: ' . print_r($data, true));
      $args = [
         'post_type' => (array_key_exists($data['content'], $this->buildFeedTypesConfig())) ?
            BASE . $data['content'] :
@@ -362,7 +364,6 @@
      $args = $this->applyDateFilters($args, $data);
      $args = $this->applyFavouritesFilter($args, $data);
      error_log('Final Args: '.print_r($args, true));
      return $args;
   }
@@ -438,9 +439,6 @@
      // Fetch and format items
      $items = $this->fetchFeedItems($args);
      error_log('Feed Got items: ' .print_r($items, true));
      $ttl = (str_contains($args['orderby'], 'RAND')) ? 1800 : $this->cache_ttl;
      $this->cache->set($key, $items, $ttl);
@@ -536,7 +534,6 @@
    */
   protected function processHighlightedItem(array $items, array $data): array
   {
      error_log('Data passed to processHighlightedItem:' . print_r($data, true));
      if (empty($data['highlight'] ?? null)) {
         return $items;
      }
@@ -627,7 +624,6 @@
      if (!array_key_exists('favourites', $filters)) {
         return $args;
      }
      error_log('Proceeding to check for favourites:');
      global $wpdb;
      // Get post types for the current filter
@@ -637,7 +633,6 @@
      $favourites_table = $wpdb->prefix . BASE . 'favourites';
      $placeholders = implode(',', array_fill(0, count($post_types), '%s'));
      error_log('CurrentUser ID: ' . print_r(get_current_user_id(), true));
      $favourited_ids = $wpdb->get_col($wpdb->prepare(
         "SELECT target_id FROM {$favourites_table}
            WHERE user_id = %d AND type IN ($placeholders)",