| | |
| | | <?php |
| | | namespace JVBase\managers\SEO; |
| | | |
| | | use JVBase\managers\CacheManager; |
| | | use JVBase\managers\Cache; |
| | | use JVBase\utility\Features; |
| | | use WP_Post; |
| | | use WP_Term; |
| | |
| | | */ |
| | | class BreadcrumbManager |
| | | { |
| | | private CacheManager $cache; |
| | | private Cache $cache; |
| | | private static ?self $instance = null; |
| | | |
| | | private function __construct() |
| | | { |
| | | $this->cache = CacheManager::for('breadcrumbs', MONTH_IN_SECONDS)->connectTo('all'); |
| | | // $this->cache->clear(); |
| | | $this->cache = Cache::for('breadcrumbs', MONTH_IN_SECONDS)->connect('post')->connect('taxonomy')->connect('user'); |
| | | if (JVB_TESTING) { |
| | | $this->cache->flush(); |
| | | } |
| | | } |
| | | |
| | | public static function getInstance(): self |
| | |
| | | break; |
| | | } |
| | | |
| | | $crumbs = $this->cache->get($key); |
| | | if ($crumbs !== false) { |
| | | return $crumbs; |
| | | } |
| | | |
| | | $crumbs = $this->buildCrumbs(); |
| | | $crumbs = apply_filters('jvbBreadcrumbs',$crumbs); |
| | | $this->cache->set($key, $crumbs); |
| | | |
| | | return $crumbs; |
| | | return $this->cache->remember( |
| | | $key, |
| | | function() { |
| | | $crumbs = $this->buildCrumbs(); |
| | | return apply_filters('jvbBreadcrumbs',$crumbs); |
| | | } |
| | | ); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | // Add term hierarchy |
| | | $crumbs = array_merge($crumbs, $this->buildTermHierarchy($term)); |
| | | |
| | | return $crumbs; |
| | | return array_merge($crumbs, $this->buildTermHierarchy($term)); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | if (Features::forSite()->has('is_directory') && $name === 'directory') { |
| | | $crumbs[] = [ |
| | | 'name' => 'Directory', |
| | | 'name' => JVB()->directories()->referAs(true), |
| | | 'url' => get_post_type_archive_link($type) |
| | | ]; |
| | | } elseif ((is_post_type_archive() || !Features::forContent($name)->has('show_directory')) && array_key_exists($name, JVB_CONTENT)) { |
| | |
| | | { |
| | | $url = get_term_link($term->term_id); |
| | | array_unshift($crumbs, [ |
| | | 'name' => $term->name, |
| | | 'name' => html_entity_decode($term->name), |
| | | 'url' => $url, |
| | | 'id' => $term->term_id, |
| | | ]); |
| | |
| | | public function invalidateCache(?int $objectId = null): void |
| | | { |
| | | if ($objectId) { |
| | | $this->cache->delete($objectId); |
| | | $this->cache->forget($objectId); |
| | | } else { |
| | | $this->cache->clear(); |
| | | $this->cache->flush(); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | $crumbs[] = [ |
| | | 'name' => $term->name, |
| | | 'name' => html_entity_decode($term->name), |
| | | 'url' => get_term_link($term, $taxonomy) |
| | | ]; |
| | | } |