| | |
| | | <?php |
| | | namespace JVBase\blocks; |
| | | |
| | | use JVBase\managers\CacheManager; |
| | | use JVBase\managers\Cache; |
| | | use JVBase\utility\Features; |
| | | use JVBase\utility\Checker; |
| | | use JVBase\forms\TaxonomySelector; |
| | |
| | | |
| | | 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); |
| | | // Set up cache connections for all feed content types |
| | | $this->setupCacheConnections(); |
| | | if (JVB_TESTING) { |
| | | $this->cache->clear(); |
| | | } |
| | | $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, [ |
| | |
| | | |
| | | $this->config = $this->buildParams($attributes); |
| | | return $this->cache->remember( |
| | | $this->config, |
| | | $this->cache->generateKey($this->config), |
| | | function() { |
| | | return $this->renderBlock(); |
| | | } |
| | |
| | | </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"> |