Jake Vanderwerf
2026-02-11 427efb903c2f23c5ddc05ce75d869fdb187d771d
inc/blocks/FeedBlock.php
@@ -1,7 +1,7 @@
<?php
namespace JVBase\blocks;
use JVBase\managers\CacheManager;
use JVBase\managers\Cache;
use JVBase\utility\Features;
use JVBase\utility\Checker;
use JVBase\forms\TaxonomySelector;
@@ -13,39 +13,22 @@
class FeedBlock
{
   protected CacheManager $cache;
   protected Cache $cache;
   protected array $config;
   protected string $path = JVB_DIR.'/build/feed';
   public function __construct()
   {
      // Initialize cache with connections
      $this->cache = CacheManager::for('feed_block', WEEK_IN_SECONDS);
      $this->cache->clear();
      // Set up cache connections for all feed content types
      $this->setupCacheConnections();
      $this->cache = Cache::for('feed_block', WEEK_IN_SECONDS);
      if (JVB_TESTING) {
         $this->cache->flush();
      }
      add_action('init', [$this, 'registerBlock']);
   }
   /**
    * Set up cache connections for feed content
    */
   protected function setupCacheConnections(): void
   {
      // Connect to all content types that show in feed
      $contentTypes = Features::getTypesWithFeature('show_feed', 'content');
      foreach ($contentTypes as $type) {
         CacheManager::for('feed_content')->connectTo('post', $type);
      }
      // Connect to all taxonomies that show in feed
      $taxonomies = Features::getTypesWithFeature('show_feed', 'taxonomy');
      foreach ($taxonomies as $tax) {
         CacheManager::for('feed_taxonomy')->connectTo('taxonomy', $tax);
      }
   }
   public function registerBlock()
   {
      register_block_type($this->path, [
@@ -129,7 +112,7 @@
      $this->config = $this->buildParams($attributes);
      return $this->cache->remember(
         $this->config,
         $this->cache->generateKey($this->config),
         function() {
            return $this->renderBlock();
         }
@@ -188,6 +171,7 @@
         echo TaxonomySelector::outputSelectorModal();
         ?>
      </section>
      <footer><button data-action="refresh" data-ignore><?=jvbIcon('arrows-clockwise')?><span>Hard Refresh</span></span></button></footer>
      <?php
      return ob_get_clean();
   }
@@ -292,8 +276,8 @@
                  <div class="selected-items-section">
                     <div class="selected-items row"></div>
                     <div class="filter-actions row">
                        <?= jvbRenderToggleTextField('match', 'Match', 'Filters', 'ALL', 'ANY', false, ['filter' => 'match']) ?>
                        <button type="button" class="clear-filters row">
                        <?= str_replace('class="toggle-text"', 'class="toggle-text" hidden', jvbRenderToggleTextField('match', 'Match', 'Filters', 'ALL', 'ANY', false, ['filter' => 'match'])) ?>
                        <button type="button" class="clear-filters row" hidden>
                           <?= jvbIcon('x') ?>
                           Clear All Filters
                        </button>
@@ -314,19 +298,45 @@
                     </label>
                     <input type="radio" id="order-date" class="btn" name="orderby" value="date" data-filter="orderby" checked>
                     <label for="order-date" title="Order by Date" class="row">
                     <label for="order-date" title="Order by Date Created" class="row">
                        <?= jvbIcon('calendar', ['title' => 'Date']) ?>
                        <span class="label">Date</span>
                        <span class="label">Date Created</span>
                     </label>
                     <input type="radio" id="order-modified" class="btn" name="orderby" value="modified" data-filter="orderby">
                     <label for="order-modified" title="Order by Date Modified" class="row">
                        <?= jvbIcon('clock-clockwise') ?>
                        <span class="label">Date Modified</span>
                     </label>
                     <?php
                        $custom = [];
                        foreach ($this->getContent() as $content) {
                           $config = JVB_CONTENT[$content]??JVB_TAXONOMY[$content]??JVB_USER[$content]??false;
                           if ($config && array_key_exists('custom_order', $config)) {
                              $custom = array_merge_recursive($custom, $config['custom_order']);
                           }
                        }
                        foreach ($custom as $slug => $conf) {
                           ?>
                           <input type="radio" id="order-<?=$slug?>" class="btn" name="orderby" value="<?=$slug?>" data-for="<?=$conf['for']?>" data-filter="orderby">
                           <label for="order-<?=$slug?>" title="<?= $conf['label']?>" class="row">
                              <?= jvbIcon($conf['icon']) ?>
                              <span class="label"><?=$conf['label']?></span>
                           </label>
                           <?php
                        }
                        $custom = implode(',', array_keys($custom));
                     ?>
                     <input type="radio" id="order-random" class="btn" name="orderby" value="random" data-filter="orderby">
                     <label for="order-random" title="Random Order" class="row">
                        <?= jvbIcon('shuffle') ?>
                        <span class="label">Random</span>
                     </label>
                  </div>
                  <div class="order-direction filter-group row start w-full" data-for-order="date,title">
                  <div class="order-direction filter-group row start w-full" data-for-order="date,modified,title<?= $custom === '' ? '' : ','.$custom?>">
                     <span class="label">ORDER:</span>
                     <input type="radio" id="order-desc" class="btn" name="order" value="desc" data-filter="order" checked>
                     <label for="order-desc" title="Sort Descending (A-Z, 1-10)" class="row">
@@ -391,7 +401,7 @@
         }
      }
      echo '<template class="feedTerm"><button class="remove-term">'.jvbIcon(jvbDefaultIcon()).'<span></span>'.jvbIcon('x').'</button></template>';
      echo '<template class="emptyState">'.apply_filters('jvbFeedEmptyState', '<div class="empty-state">
                <h3>'.jvbIcon($this->getIcon()).'NOTHING HERE'.jvbIcon($this->getIcon()).'</h3>
                <p>Try tweaking those filters a bit.</p>