Jake Vanderwerf
2026-01-25 b38f03c0e7218762d90fa5092696b127f24f36db
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}
/**
 * Directory List Block Render
 *
 * @package Edmonton_Ink
 */
 
function jvbRenderListBlock(array $attributes):string
{
    // Get the selected list type
    $selected_type_slug = $attributes['listType'] ?? BASE.'artist';
    $refresh_cache = $attributes['refreshCache'] ?? false;
    $types = jvbGlobalDirectoryInfo();
    $umami = new JVBase\managers\UmamiTracker();
 
    // Find the selected type in the types array
    $selected_type = null;
    foreach ($types as $type) {
        if ($type['slug'] === $selected_type_slug) {
            $selected_type = $type;
            break;
        }
    }
 
    // If no valid type was found, return an error message
    if (!$selected_type) {
        return '<p>Error: Selected list type not found.</p>';
    }
    // Buffer output
    ob_start();
 
    // Add the "More Lists" button
    echo '<a class="button" href="#directory-list">'.
         jvbIcon('plus', ['title'=>'More Lists']).' <span>More Lists</span></a>';
 
    // Get the list data
    $list = get_option(BASE.$selected_type['slug'].'_list');
    $list = false;
    // If refresh cache is enabled or list doesn't exist, regenerate it
    if ($refresh_cache || $list === false) {
        $list = array();
        if ($selected_type['type'] == 'post') {
            $get = new WP_Query(array(
                'post_type'         => $selected_type['slug'],
                'posts_per_page'    => -1,
                'orderby'           => 'title',
                'order'             => 'ASC'
            ));
            if ($get->have_posts()) {
                while ($get->have_posts()) {
                    $get->the_post();
                    $extra = false;
                    if (!empty($selected_type['links'])) {
                        $extra = [];
                        foreach ($selected_type['links'] as $item) {
                            $terms = get_the_terms(get_the_ID(), $item);
                            if ($terms && !is_wp_error($terms)) {
                                $term = $terms[0];
                                $extra[] = [
                                    'name'  => html_entity_decode($term->name),
                                    'url'   => get_term_link($term->term_id, $item),
                                    'id'    => $term->term_id,
                                    'type'  => $item,
                                ];
                            }
                        }
                    }
                    $list = jvbAlphabetizeMe(
                        $list,
                        get_the_title(),
                        get_the_permalink(),
                        get_the_ID(),
                        $extra
                    );
                }
            }
            wp_reset_postdata();
        } elseif ($selected_type['type'] == 'term') {
            $terms = get_terms(array(
                'taxonomy'      => $selected_type['slug'],
                'hide_empty'    => true,
                'orderby'       => 'name',
                'order'         => 'ASC',
            ));
            if ($terms) {
                foreach ($terms as $term) {
                    $extra = false;
                    $list = jvbAlphabetizeMe(
                        $list,
                        html_entity_decode($term->name),
                        get_term_link($term->term_id, $selected_type['slug']),
                        $term->term_id,
                        $extra
                    );
                }
            }
        }
        update_option(BASE.$selected_type['slug'].'_list', $list);
    }
 
    // Check if this is a hierarchical type
    if (array_key_exists('hierarchical', $selected_type) && $selected_type['hierarchical']) {
        echo jvbRenderThemesHierarchical();
        return ob_get_clean();
    }
    // Build the HTML output
    $out = '<section class="directory-list artists">';
    if (empty($list)) {
        $out .= '<h2>Nothing here.</h2><p>We don\'t have anything to show here yet.</p>';
    } else {
        $out .= '<nav class="letters on-this-page"><ul>';
        $nav = jvbLetters();
        $letters = array_keys($list);
        foreach ($nav as $l) {
            $aOpen = $aClose = $class = '';
            if (in_array($l, $letters)) {
                $aOpen = '<a href="#starts-with-'.$l.'">';
                $aClose = '</a>';
                $class = ' class="has"';
            }
            $out .= '<li'.$class.'>'.$aOpen.strtoupper($l).$aClose.'</li>';
        }
        $out .= '</ul></nav><ul class="list-none">';
        foreach ($list as $letter => $artists) {
            $out .= '<li id="starts-with-'.$letter.'"><h3>'.strtoupper($letter).'</h3><ul>';
            foreach ($artists as $a) {
                $extra = '';
                if ($a['extra'] !== false) {
                    $extra = '<span>';
                    foreach ($a['extra'] as $ext) {
                        $umamiType = 'click_taxonomy';
                        if ($ext['type'] == BASE.'shop') {
                            $umamiType = 'click_shop';
                        }
                        $extra .= '<a href="'.$ext['url'].'" '.
                                  $umami->attributesToString(
                                      $umami->buildAttributes(
                                          $umamiType,
                                          $selected_type['slug'],
                                          ['source_type' => 'directory']
                                      )
                                  ).'>'.$ext['name'].'</a>';
                    }
                    $extra .= '</span>';
                }
                $umamiType = 'click_profile';
                if ($selected_type['slug'] == BASE.'shop') {
                    $umamiType = 'click_shop';
                } elseif ($selected_type['type'] == 'taxonomy') {
                    $umamiType = 'click_taxonomy';
                }
 
                $out .= '<li><a href="'.$a['url'].'" title="More about '.$a['name'].'" '.
                        $umami->attributesToString(
                            $umami->buildAttributes(
                                $umamiType,
                                $selected_type['slug'],
                                ['source_type' => 'directory']
                            )
                        ).'>'.$a['name'].'</a>'.$extra.'</li>';
            }
            $out .= '</ul></li>';
        }
        $out .= '</ul>';
    }
    $out .= '</section>';
 
    echo $out;
    echo JVB()->directories()?->renderNavigation();
 
    return ob_get_clean();
}