Jake Vanderwerf
2026-03-03 772462eeca3002a1d52508aeba485aab2b4742ad
src/feed/render.php
@@ -2,251 +2,3 @@
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}
/**
 * Feed block render callback
 *
 * @param array    $attributes Block attributes.
 * @param string   $content    Block content.
 * @param WP_Block $block      Block instance.
 * @return string  Rendered block type output.
 */
function jvbRenderFeedBlock($attributes, $content = '', $block = null)
{
    ob_start();
    // Get block settings
    global $jvb_taxonomy_for;
    global $jvb_everything;
    $context = '';
    $taxonomies = [];
    foreach ($jvb_taxonomy_for as $tax => $for) {
        if (array_intersect($for, $attributes['contentTypes'])) {
            $taxonomies[] = $tax;
        }
    }
    $settings = [
        'content'         => $attributes['contentTypes'][0] ?? 'tattoo',
        'contentTypes'    => $attributes['contentTypes'],
        'taxonomies'      => $taxonomies,
        'defaultOrder'    => $attributes['defaultOrder'],
        'itemsPerPage'    => $attributes['itemsPerPage'],
    ];
    $isGallery = false;
    if ($attributes['inheritQuery']) {
        $obj = get_queried_object();
        $taxonomies = $contentTypes = [];
        if (is_singular()) {
            switch ($obj->post_type) {
                case BASE.'artist':
                case BASE.'partner':
                    $contentTypes = jvbGetUserContentTypes(get_the_ID());
                    break;
            }
            if ($obj->post_type == BASE.'artist') {
                $isGallery = true;
                $context = 'artist';
                $name = get_post_meta($obj->id, 'jvb_first_name', true);
                $feed_data['title'] = ($name== '') ? $obj->post_title : $name;
            } elseif ($obj->post_type == BASE.'partner') {
                $context = 'partner';
                $feed_data['title'] = 'Offers:';
            }
            $type = 'post';
        } elseif (is_tax('jvb_shop')) {
            $context = 'shop';
            $feed_data['title'] = 'At the Shop:';
            $contentTypes = [
                'artist',
                'tattoo',
                'piercing',
//                'event'
            ];
            $type = 'term';
        } elseif (is_tax()) {
            $context = str_replace(BASE, '', $obj->taxonomy);
            foreach ($jvb_taxonomy_for as $tax => $for) {
                if ($context === $tax) {
                    $contentTypes = $for['types'];
                }
            }
            $type = 'term';
            $context = 'taxonomy:'.$context;
        }
        jvbDump($settings);
        jvbDump($contentTypes);
        if (empty($contentTypes)) {
            return;
        }
        foreach ($contentTypes as $index => $type) {
            $contentTypes[$index] = str_replace(BASE, '', $type);
        }
        foreach ($jvb_taxonomy_for as $tax => $for) {
            if (array_intersect($for, $contentTypes)) {
                $taxonomies[] = $tax;
            }
        }
        $feed_data = [
            'content'        => $contentTypes[0],
            'contentTypes'     => $contentTypes,
            'taxonomies'    => $taxonomies,
            'context'        => $context,
        ];
        if ($isGallery) {
            $feed_data['isGallery'] = true;
        }
        $settings = array_merge($settings, $feed_data);
        $title = !array_key_exists('title', $settings) ? '' : '<h2 id="work">'.$feed_data['title'].'</h2>';
    } else {
        $title = $attributes['title'] ? "<h2>{$attributes['title']}</h2>" : '';
    }
    $many = count($settings['contentTypes']) > 1;
    $work = is_singular(BASE.'artist') ? ' id="work"' : '';
    $source = get_queried_object_id();
    global $jvb_feed;
    if (empty($settings['contentTypes'])) {
        return;
    }
    ?>
    <section <?= $work ?> class="feed-block"
        data-source="<?= get_queried_object_id(); ?>"<?= ($context !== '') ? '
        data-context="'.$context.'"' : ''    ?><?= ($isGallery) ? ' data-gallery="true"' : ''?>>
        <?= $title ?>
        <form class="feed-filters">
            <?= (!$many) ? '' : '<details>' ?>
            <?php if ($many) : ?>
            <summary class="row btw">
                <div class="type-filter label">
                    <span>SHOW:</span>
                </div>
                <?php
                foreach ($settings['contentTypes'] as $i => $type) :
                    $checked = $i === 0 ? ' checked' : '';
                    $label = $jvb_everything[$type]['plural'];
                    ?>
                    <div class="type-filter">
                        <input type="radio"
                               id="filter-<?= esc_attr($type) ?>"
                               class="btn"
                               name="content"
                               value="<?= esc_attr($type) ?>"
                            <?= $checked ?>>
                        <label for="filter-<?= esc_attr($type) ?>" title="Show <?= $label ?>">
                            <?= jvbIcon($type, ['title'=> $label]) ?>
                            <span class="label"><?= $label ?></span>
                        </label>
                    </div>
                <?php endforeach; ?>
            <?php endif; ?>
            <?php if (is_user_logged_in()) : ?>
                <div class="type-filter favourites-toggle">
                    <input type="checkbox" id="favourites_only" class="btn" name="favourites_only">
                    <label for="favourites_only" title="Show Favourites">
                        <?= jvbIcon('heart', ['title'    =>'Favourites']) ?>
                        <span class="label">Favourites</span>
                    </label>
                </div>
            <?php endif; ?>
            <?php if ($many) {
                echo '</summary>';
            } ?>
            <div class="filters">
                <div class="filter-group">
                    <div class="type-filter label">
                        <span>FILTER:</span>
                    </div>
                    <?php foreach ($jvb_taxonomy_for as $tax => $items) :
                        $label = $jvb_everything[$tax]['plural'];
                        $hidden = !in_array($tax, $settings['taxonomies']) ? ' hidden' : '';
                        $tax = new JVBase\Forms\TaxonomySelector(
                            $tax,
                            BASE.$tax,
                            [
                                'label' => $label,
                                'types' => $items,
                                'hidden'=> $hidden
                            ]
                        );
                        echo  $tax->renderFeed();
                    endforeach; ?>
                </div>
                    <div class="selected-items-section">
                        <div class="selected-items"></div>
                        <div class="filter-actions">
                            <?= jvbRenderToggleTextField('match', 'Match', 'Filters', 'ALL', 'ANY', true) ?>
                            <button type="button" class="clear-filters row" hidden>
                                <?= jvbIcon('close', ['title'    => 'Clear']) ?>
                                Clear All Filters
                            </button>
                        </div>
                    </div>
                </div>
                <div class="order-options">
                    <div class="order-by">
                        <span class="type-filter label">ORDER:</span>
                        <div class="radio-group-label">
                            <input type="radio" id="order-title" class="btn" name="orderby" value="title" data-for="artist,shop" hidden>
                            <label for="order-title" title="Order by Name">
                                <?= jvbIcon('alphabetical') ?>
                                <span class="label">Name</span>
                            </label>
                            <input type="radio" id="order-date" class="btn" name="orderby" value="date" checked>
                            <label for="order-date" title="Order by Date">
                                <?= jvbIcon('calendar', ['title'=>'Date']) ?>
                                <span class="label">Date</span>
                            </label>
                            <input type="radio" id="order-random" class="btn" name="orderby" value="random">
                            <label for="order-random" title="Random Order">
                                <?= jvbIcon('random') ?>
                                <span class="label">Random</span>
                            </label>
                        </div>
                    </div>
                    <div class="order-direction radio-group-label" data-for-order="date,title">
                        <input type="radio" id="order-desc" class="btn" name="order" value="desc" checked>
                        <label for="order-desc" title="Newest First">
                            <?= jvbIcon('desc') ?>
                        </label>
                        <input type="radio" id="order-asc" class="btn" name="order" value="asc">
                        <label for="order-asc" title="Oldest First">
                            <?= jvbIcon('asc') ?>
                        </label>
                    </div>
                </div>
                <?= (!$many) ? '' : '</details>' ?>
        </form>
        <div class="feed-grid"></div>
    </section>
    <?= jvbGetFeedItemTemplate(); ?>
    <?= jvbGetFeedArtistTemplate(); ?>
    <?php
    return ob_get_clean();
}