| | |
| | | <?php |
| | | namespace JVBase\blocks; |
| | | |
| | | use JVBase\managers\CacheManager; |
| | | use JVBase\managers\Cache; |
| | | use JVBase\forms\TaxonomySelector; |
| | | use WP_Block; |
| | | |
| | |
| | | |
| | | class SummaryBlock |
| | | { |
| | | protected CacheManager $cache; |
| | | protected Cache $cache; |
| | | protected string $config; |
| | | protected string $type; |
| | | protected string $path = JVB_DIR . '/build/summary'; |
| | |
| | | |
| | | public function __construct() |
| | | { |
| | | $this->cache = CacheManager::for('summary_block', WEEK_IN_SECONDS); |
| | | $this->cache = Cache::for('summary_block', WEEK_IN_SECONDS); |
| | | add_action('init', [ $this, 'registerBlock' ]); |
| | | if (JVB_TESTING) { |
| | | $this->cache->flush(); |
| | | } |
| | | } |
| | | |
| | | public function registerBlock() |
| | |
| | | $this->config = $this->getConfig(); |
| | | $key = $this->generateKey(); |
| | | $cache = $this->cache->get($key); |
| | | |
| | | if ($cache) { |
| | | return $cache; |
| | | } |
| | |
| | | |
| | | protected function renderHeader():void |
| | | { |
| | | ob_start(); |
| | | ?> |
| | | <header id="top"> |
| | | <?php if ($this->image !== ''): ?> |
| | |
| | | <?php endif; ?> |
| | | </header> |
| | | <?php |
| | | $out = ob_get_clean(); |
| | | |
| | | |
| | | echo apply_filters( |
| | | 'jvbSummaryHeaderOutput', |
| | | $out, |
| | | $this->header, |
| | | $this->headerExtra |
| | | ); |
| | | } |
| | | |
| | | protected function renderDetails():void |
| | |
| | | if (empty($this->type)) { |
| | | $this->type = match (true) { |
| | | is_tax() => jvbNoBase(get_queried_object()->taxonomy), |
| | | is_post_type_archive() => jvbNoBase(get_post_type()), |
| | | is_post_type_archive() => jvbNoBase(get_queried_object()->name), |
| | | default => jvbNoBase(get_queried_object()->post_type), |
| | | }; |
| | | } |