| | |
| | | use JVBase\forms\TaxonomySelector; |
| | | use JVBase\ui\CRUDSkeleton; |
| | | use WP_Block; |
| | | use WP_Query; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | | exit; |
| | |
| | | |
| | | protected array $content = []; |
| | | protected array $taxonomies = []; |
| | | protected ?string $context = null; |
| | | protected ?int $contextID = null; |
| | | |
| | | protected bool $isGallery = false; |
| | | |
| | | public function __construct() |
| | |
| | | $classes = ''; |
| | | |
| | | return sprintf( |
| | | '<section class="feed-block%s" data-content="%s"%s> |
| | | '<section class="feed-block%s" data-content="%s"%s%s%s> |
| | | %s%s%s%s%s |
| | | <footer>%s</footer> |
| | | </section>', |
| | | $classes, |
| | | $this->getContent(), |
| | | $this->isGallery ? ' data-gallery' : '', |
| | | is_null($this->context) ? '' : ' data-context="'.$this->context.'"', |
| | | is_null($this->contextID) ? '' : ' data-context-id="'.$this->contextID.'"', |
| | | $this->renderFiltersAndControls(), |
| | | $this->renderGrid(), |
| | | $this->renderTemplates(), |
| | |
| | | global $post; |
| | | $author = $post->post_author; |
| | | $role = jvbUserRole($author); |
| | | |
| | | $this->context = jvbNoBase($role); |
| | | $this->contextID = $author; |
| | | $registrar = Registrar::getInstance($role); |
| | | if (!$registrar) { |
| | | return; |
| | |
| | | return; |
| | | } elseif (is_tax()) { |
| | | $obj = get_queried_object(); |
| | | $this->context = jvbNoBase($obj->taxonomy); |
| | | $this->contextID = $obj->term_id; |
| | | $registrar = Registrar::getInstance($obj->taxonomy); |
| | | if (!$registrar) { |
| | | return; |
| | |
| | | protected function renderFiltersAndControls():string |
| | | { |
| | | return sprintf( |
| | | '<details class="all-filters col top left" data-ignore open> |
| | | '<details class="all-filters col top left" data-ignore> |
| | | <summary>Filters %s</summary> |
| | | %s%s%s%s%s |
| | | </details> |
| | |
| | | } |
| | | protected function renderContentLabels():string |
| | | { |
| | | $inside = ''; |
| | | if (count($this->content) === 1) { |
| | | return ''; |
| | | } |
| | | foreach ($this->content as $i => $type) { |
| | | $active = $i === 0 ? ' class="active"' : ''; |
| | | $inside .= sprintf( |
| | | '<li id="filter-%s"%s>%s</li>', |
| | | $type, |
| | | $active, |
| | | Registrar::getInstance($type)->getPlural()??'' |
| | | ); |
| | | } |
| | | return sprintf( |
| | | '<ul class="filter-label">%s</ul>', |
| | | $inside |
| | | '<span class="label">Showing: <span class="current">%s</span></span>', |
| | | $this->content[0]??'' |
| | | ); |
| | | |
| | | } |
| | | protected function renderContent():string |
| | | { |
| | |
| | | if (count($this->content) === 1) { |
| | | return empty($favourites) |
| | | ? sprintf( |
| | | '<input type="hidden" name="content" value="%s">', |
| | | '<input type="hidden" data-filter="content" name="content" value="%s">', |
| | | implode(',', $this->content) |
| | | ) |
| | | : sprintf( |
| | |
| | | } |
| | | $i = 0; |
| | | $content = implode('', array_map(function($type) use (&$i) { |
| | | $i++; |
| | | $registrar = Registrar::getInstance($type); |
| | | |
| | | $args = [ |
| | | 'post_type' => $registrar->getBased(), |
| | | 'posts_per_page' => 1, |
| | | 'fields' => 'ids', |
| | | ]; |
| | | if (!is_null($this->context)) { |
| | | |
| | | $context = Registrar::getInstance($this->context); |
| | | switch ($context->getType()) { |
| | | case 'term': |
| | | $args['tax_query'] = []; |
| | | $args['tax_query'][] = [ |
| | | 'taxonomy' => $context->getBased(), |
| | | 'terms' => $this->contextID |
| | | ]; |
| | | break; |
| | | case 'user': |
| | | $args['author'] = $this->contextID; |
| | | break; |
| | | } |
| | | } |
| | | $check = new WP_Query($args); |
| | | $hasPosts = !empty($check->posts); |
| | | |
| | | $disabled = !$hasPosts; |
| | | $checked = $i === 0 && $hasPosts; |
| | | if ($hasPosts) { |
| | | $i++; |
| | | } |
| | | return sprintf( |
| | | '<input type="radio" |
| | | id="filter-%s" |
| | | class="btn" |
| | | name="content" |
| | | data-filter="content" |
| | | value="%s"%s> |
| | | <label for="filter-%s" title="Show %s">%s<span class="screen-reader-text">%s</span></label>', |
| | | data-label="%s" |
| | | value="%s"%s%s> |
| | | <label for="filter-%s" title="Show %s">%s<span class="label">%s</span></label>', |
| | | $type, |
| | | $registrar->getSingular(), |
| | | $type, |
| | | $i === 0 ? ' checked' : '', |
| | | $checked ? ' checked' : '', |
| | | $disabled ? ' disabled' : '', |
| | | $type, |
| | | $registrar->getPlural(), |
| | | $registrar->getSingular(), |
| | | jvbIcon($registrar->getIcon()), |
| | | $registrar->getPlural() |
| | | $registrar->getSingular() |
| | | ); |
| | | }, $this->content)); |
| | | |
| | |
| | | }, $this->taxonomies))); |
| | | return sprintf( |
| | | '<div class="taxonomies row left"> |
| | | <div class="row top nowrap"> |
| | | <span class="label">Filter By:</span> |
| | | <div class="row left">%s</div> |
| | | <div class="row top wrap"> |
| | | <span class="label">Filter By:</span> |
| | | %s |
| | | </div> |
| | | <div class="selected-items-section"> |
| | | <div class="selected-items row left"></div> |
| | |
| | | ); |
| | | |
| | | return sprintf( |
| | | '<div class="ordering row left nowrap">%s%s</div>', |
| | | '<div class="ordering row top left nowrap">%s%s</div>', |
| | | $orderby, |
| | | $order |
| | | ); |