Jake Vanderwerf
2025-11-10 627056f72e761c1386e4ab4d72207008d9330a5e
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
<?php
 
/**
 * Custom upload directory structure for edmonton.ink
 * Recreates the original directory logic with shops, artists, partners, etc.
 */
add_filter('jvb_upload_directory', 'altr_upload_directory', 10, 4);
function altr_upload_directory($path, $post_type, $user_id, $term_id)
{
    switch ($post_type) {
        case 'shop':
            // Shop directory
            return 'shops/' . $term_id;
 
        case 'partner':
            // Partner directory
            return 'partners/' . $user_id;
 
        case 'artist':
            // Artist profile directory
            return 'artists/' . $user_id;
 
        default:
            // Content directories within artist folder (tattoos, artwork, etc)
            if (!$user_id) {
                return $path; // fallback to default
            }
 
            $link = get_user_meta($user_id, BASE . 'link', true);
            $type = str_replace(BASE, '', get_post_type((int)$link));
 
            return sanitize_title($type) . '/' . $user_id . '/' . sanitize_title($post_type);
    }
}
 
/**
 * Custom filename generation for edmonton.ink
 * Recreates the original SEO-friendly filename logic
 */
add_filter('jvb_upload_filename', 'altr_filename', 10, 6);
function altr_filename($filename, $original_name, $user_data, $post_type, $user_id, $term_id)
{
    // Get artist/shop/partner details
    $post = (int)get_user_meta($user_id, BASE . 'link', true);
 
    if (!$post) {
        return $filename; // fallback to default
    }
 
    $city = jvbArtistCity($post);
 
    switch ($post_type) {
        case 'shop':
            // Shop images: {city}-best-tattoo-shop-{shop-name}
            $shop_term = get_term($term_id, BASE . 'shop');
            if (!$shop_term || is_wp_error($shop_term)) {
                return $filename;
            }
 
            return sprintf(
                '%s-best-tattoo-shop-%s-%s',
                sanitize_title($city),
                sanitize_title($shop_term->name),
                altr_get_counter($user_id, $post_type)
            );
 
        case 'artist':
            // Profile images: {city}-best-{type}-{specialties}-{name}
            $type = jvbArtistType($post);
            $specialties = altr_get_artist_top_styles($post);
 
            return sprintf(
                '%s-best-%s-%s-%s-%s',
                sanitize_title($city),
                sanitize_title($type),
                sanitize_title($specialties),
                sanitize_title($user_data->display_name),
                altr_get_counter($user_id, $post_type)
            );
 
        case 'partner':
            // Partner images: {city}-tattoo-{service-type}-{name}
            $service_type = jvb_partner_type($post);
 
            return sprintf(
                '%s-tattoo-%s-%s-%s',
                sanitize_title($city),
                sanitize_title($service_type),
                sanitize_title($user_data->display_name),
                altr_get_counter($user_id, $post_type)
            );
 
        case 'tattoo':
            // Get style and subject if available
            $style = altr_get_primary_taxonomy($post, BASE . 'style');
            $subject = altr_get_primary_taxonomy($post, BASE . 'theme');
 
            return sprintf(
                '%s-%s-%s-tattoo-by-%s-%s',
                sanitize_title($city),
                sanitize_title($style),
                sanitize_title($subject),
                sanitize_title($user_data->display_name),
                altr_get_counter($user_id, $post_type)
            );
 
        case 'artwork':
            // Get style and subject if available
            $style = altr_get_primary_taxonomy($post, BASE . 'artstyle');
            $subject = altr_get_primary_taxonomy($post, BASE . 'arttheme');
 
            return sprintf(
                '%s-%s-%s-artwork-by-%s-%s',
                sanitize_title($city),
                sanitize_title($style),
                sanitize_title($subject),
                sanitize_title($user_data->display_name),
                altr_get_counter($user_id, $post_type)
            );
 
        case 'piercing':
            // Get style if available
            $style = altr_get_primary_taxonomy($post, BASE . 'pstyle');
 
            return sprintf(
                '%s-%s-piercing-by-%s-%s',
                sanitize_title($city),
                sanitize_title($style),
                sanitize_title($user_data->display_name),
                altr_get_counter($user_id, $post_type)
            );
 
        default:
            // Content: {city}-{content_type}-by-{name}
            $content_type = $post_type;
 
            return sprintf(
                '%s-%s-by-%s-%s',
                sanitize_title($city),
                sanitize_title($content_type),
                sanitize_title($user_data->display_name),
                altr_get_counter($user_id, $post_type)
            );
    }
}
 
/**
 * Custom alt text generation for edmonton.ink
 * Recreates the original detailed alt text logic
 */
add_filter('jvb_upload_alt_text', 'altr_alt_text', 10, 7);
function altr_alt_text($alt_text, $file, $user_data, $post_id, $post_type, $user_id, $term_id)
{
    $post = get_user_meta($user_id, BASE . 'link', true);
 
    if (!$post) {
        return $alt_text; // fallback to default
    }
 
    $city = jvbArtistCity($post);
    $type = jvbArtistType($post);
 
    switch ($post_type) {
        case 'shop':
            $shop_term = get_term($term_id, BASE . 'shop');
            if (!$shop_term || is_wp_error($shop_term)) {
                return $alt_text;
            }
 
            return sprintf(
                'A photo of %s tattoo shop %s',
                $city,
                $shop_term->name
            );
 
        case 'artist':
            $specialties = altr_get_artist_top_styles($post);
 
            return sprintf(
                'A photo of %s %s %s, specializing in %s tattoos',
                $city,
                $type,
                $user_data->display_name,
                $specialties
            );
 
        case 'partner':
            $service_type = jvb_partner_type($post);
 
            return sprintf(
                'A photo of %s, providing %s in %s',
                $user_data->display_name,
                $service_type,
                $city
            );
 
        default:
            if (!$post_id) {
                return $alt_text;
            }
 
            // Get primary style
            $style = wp_get_post_terms($post_id, BASE . 'style', ['fields' => 'names']);
            $first_style = !empty($style) ? $style[0] : 'custom';
 
            // Get content type
            $content_type = $post_type;
 
            // Base alt text
            $alt = sprintf(
                'A photo of a %s %s by %s %s %s',
                $first_style,
                $content_type,
                $city,
                $type,
                $user_data->display_name
            );
 
            // Add themes for tattoos only
            if ($post_type === 'tattoo') {
                $themes = wp_get_post_terms($post_id, BASE . 'theme', [
                    'fields' => 'names',
                    'number' => 3
                ]);
 
                if (!empty($themes)) {
                    $theme_list = implode(', ', $themes);
                    $alt .= sprintf(', with %s', $theme_list);
                }
            }
 
            return $alt;
    }
}
 
/**
 * Custom image title generation for edmonton.ink
 * Recreates the original SEO-friendly title logic
 */
add_filter('jvb_upload_image_title', 'altr_image_title', 10, 7);
function altr_image_title($title, $file, $user_data, $post_id, $post_type, $user_id, $term_id)
{
    $post = get_user_meta($user_id, BASE . 'link', true);
 
    if (!$post) {
        return $title; // fallback to default
    }
 
    $city = jvbArtistCity($post);
    $type = jvbArtistType($post);
 
    switch ($post_type) {
        case 'shop':
            $shop_term = get_term($term_id, BASE . 'shop');
            if (!$shop_term || is_wp_error($shop_term)) {
                return $title;
            }
 
            return sprintf(
                '%s | %s\'s Best Tattoo Shops',
                $shop_term->name,
                $city
            );
 
        case 'artist':
            return sprintf(
                '%s | %s\'s Best %s',
                $user_data->display_name,
                $city,
                $type
            );
 
        case 'tattoo':
            if (!$post_id) {
                return $title;
            }
 
            $style = wp_get_post_terms($post_id, BASE . 'style', ['fields' => 'names']);
            $first_style = !empty($style) ? $style[0] : 'custom';
            $content_type = str_replace(BASE, '', $post_type);
 
            return sprintf(
                '%s %s by %s | %s\'s Best %s',
                $first_style,
                $content_type,
                $user_data->display_name,
                $city,
                $type
            );
 
        case 'artwork':
            if (!$post_id) {
                return $title;
            }
 
            $style = wp_get_post_terms($post_id, BASE . 'artstyle', ['fields' => 'names']);
            $first_style = !empty($style) ? $style[0] : 'custom';
            $content_type = str_replace(BASE, '', $post_type);
 
            return sprintf(
                '%s %s by %s | %s\'s Best %s',
                $first_style,
                $content_type,
                $user_data->display_name,
                $city,
                $type
            );
 
        case 'piercing':
            if (!$post_id) {
                return $title;
            }
 
            $style = wp_get_post_terms($post_id, BASE . 'pstyle', ['fields' => 'names']);
            $first_style = !empty($style) ? $style[0] : 'custom';
            $content_type = str_replace(BASE, '', $post_type);
 
            return sprintf(
                '%s %s by %s | %s\'s Best %s',
                $first_style,
                $content_type,
                $user_data->display_name,
                $city,
                $type
            );
 
        default:
            return sprintf(
                'Image by %s %s, %s',
                $city,
                $type,
                $user_data->display_name
            );
    }
}
 
/**
 * Helper Functions
 * These recreate the helper functions from the original UploadManager
 */
 
/**
 * Get the next file counter for edmonton.ink style counters
 */
function altr_get_counter($user_id, $post_type)
{
    // Get counter key for this post type
    $counter_key = BASE . str_replace(BASE, '', $post_type) . '_counter';
 
    // Get current counter value, default to 0
    $counter = (int)get_user_meta($user_id, $counter_key, true) ?: 0;
 
    // Increment counter
    $counter++;
 
    // Update counter in user meta
    update_user_meta($user_id, $counter_key, $counter);
 
    // Return formatted counter
    return sprintf('%08d', $counter);
}
 
/**
 * Get artist's top styles for filename generation
 */
function altr_get_artist_top_styles($post_id)
{
    if (!function_exists('JVBase\\meta\\MetaManager')) {
        // Fallback if MetaManager not available
        $styles = wp_get_post_terms($post_id, BASE . 'style', array('fields' => 'names'));
        if (is_wp_error($styles) || empty($styles)) {
            return 'custom-tattoos';
        }
        return implode('-', array_slice($styles, 0, 2));
    }
 
    $styles = wp_get_post_terms($post_id, BASE . 'style', array('fields' => 'names'));
    if (is_wp_error($styles) || empty($styles)) {
        return 'custom-tattoos';
    }
 
    // Get top highlighted styles first
    $meta = new JVBase\meta\MetaManager($post_id, 'post');
    $highlighted = explode(',', $meta->getValue('top_style')) ?: array();
 
    if (!empty($highlighted)) {
        $style_names = array();
        foreach ($highlighted as $style_id) {
            $term = get_term((int)$style_id, BASE . 'style');
            if ($term && !is_wp_error($term)) {
                $style_names[] = $term->name;
            }
        }
        if (!empty($style_names)) {
            return implode('-', array_slice($style_names, 0, 2));
        }
    }
 
    // Fallback to first two styles
    return implode('-', array_slice($styles, 0, 2));
}
 
/**
 * Get primary taxonomy term for content
 */
function altr_get_primary_taxonomy($post_id, $taxonomy)
{
    $terms = wp_get_post_terms($post_id, $taxonomy, array('fields' => 'names'));
    if (is_wp_error($terms) || empty($terms)) {
        return $taxonomy === BASE . 'style' ? 'custom' : 'tattoo';
    }
    return $terms[0];
}
 
/**
 * Get partner type (placeholder - implement based on your edmonton.ink logic)
 * This function was referenced in the original but not provided
 */
function altr_partner_type($post_id)
{
    // Implement based on your edmonton.ink logic
    // This might look at a taxonomy or meta field
    $terms = wp_get_post_terms($post_id, BASE . 'partner_type', array('fields' => 'names'));
    if (is_wp_error($terms) || empty($terms)) {
        return 'service';
    }
    return $terms[0];
}
 
/**
 * Optional: Add action to schedule cleanup (from original code)
 * Uncomment if you want the original cleanup functionality
 */
/*
add_action('init', function() {
    if (!wp_next_scheduled('jvb_cleanup_original_uploads')) {
        wp_schedule_event(time(), 'daily', 'jvb_cleanup_original_uploads');
    }
});
 
add_action('jvb_cleanup_original_uploads', function() {
    // You could instantiate your upload manager here and call cleanup
    // Or implement the cleanup logic directly
});
*/