| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- function make_taxonomy_endpoint_for( $terms ) {
- $type_slugs = [];
- foreach ($terms as $type_slug) {
- array_push($type_slugs, $type_slug->slug);
- }
- return $type_slugs;
- }
-
-
- function default_post_format( $item, $include_content ) {
- $filtered = [];
- $filtered[id] = $item->ID;
- $filtered[slug] = $item->post_name;
- $filtered[type] = $item->post_type;
- $filtered[title] = $item->post_title;
- $filtered[excerpt] = $item->post_excerpt;
- $filtered[date] = $item->post_date;
-
- if($include_content) {
- $content = $item->post_content;
- $content = apply_filters('the_content', $content);
- $filtered[content] = wp_specialchars_decode($content);
- }
-
- if(!$filtered[excerpt]) {
- $excerpt = get_the_excerpt($item);
- $filtered[excerpt] = wp_specialchars_decode($excerpt);
- }
-
- $filtered[featured] = get_the_post_thumbnail_url($item);
- if(!$filtered[featured]) {
- $thumbnailId = get_post_meta( $item->ID, '_thumbnail_id', true );
- $filtered[featured] = get_post($thumbnailId)->guid;
- }
-
- $filtered[thumb] = get_the_post_thumbnail_url($item, 'medium');
- if(!$filtered[thumb]) {
- $thumbnailId = get_post_meta( $item->ID, '_thumbnail_id', true );
- $filtered[thumb] = get_post($thumbnailId)->guid;
- }
-
- $filtered[hero] = get_post_meta( $item->ID, 'hero_header', true );
-
- // Materials + type endpoints
- $posts_with_type = ['artist', 'exhibition', 'event', 'short', 'technique', 'guide', 'object', 'publication' ];
- if( in_array($item->post_type, $posts_with_type) ) {
- $filtered[materials] = make_taxonomy_endpoint_for(get_the_terms( $item, 'material'));
- $filtered[subtypes] = make_taxonomy_endpoint_for(get_the_terms( $item, $item->post_type . '_type' ));
- }
-
- // Custom fields endpoint
- if($item->post_type === 'episode' && $include_content) $filtered[credits] = get_post_meta( $item->ID, 'credits', true );
-
- if($item->post_type === 'artist') $filtered[sortname] = get_post_meta( $item->ID, 'artist-sort-name', true );
-
- $posts_with_date = ['exhibition', 'event'];
- if( in_array($item->post_type, $posts_with_date) ) {
- $key_prefix = $item->post_type;
- $key_suffix = 'time';
- // Exhibition meta key is very old so we change it back to exhibit
- if($item->post_type == 'exhibition') {
- $key_prefix = 'exhibit';
- $key_suffix = 'date';
- }
- $filtered[start] = get_post_meta($item->ID, $key_prefix . '-start-' . $key_suffix, true);
- $filtered[end] = get_post_meta($item->ID, $key_prefix . '-end-' . $key_suffix, true);
- $filtered[current] = time() <= (int)$filtered[end] && time() >= (int)$filtered[start];
- }
-
- // Post categories and tags (store just the slugs)
- if($item->post_type === 'post') {
- $filtered[categories] = make_taxonomy_endpoint_for(get_the_terms( $item, 'category' ));
- // $filtered[tags] = make_taxonomy_endpoint_for(get_the_terms( $item, 'post_tag' ));
- }
-
- if($item->related_episode) {
- $filtered[related_episode] = strtolower($item->related_episode);
- }
-
- return $filtered;
- }
-
- function minimal_post_format( $item ) {
- $filtered = [];
- $filtered[id] = $item->ID;
- $filtered[slug] = $item->post_name;
- $filtered[type] = $item->post_type;
- $filtered[title] = $item->post_title;
-
- $filtered[thumb] = get_the_post_thumbnail_url($item, 'medium');
- if(!$filtered[thumb]) {
- $thumbnailId = get_post_meta( $item->ID, '_thumbnail_id', true );
- $filtered[thumb] = get_post($thumbnailId)->guid;
- }
-
- // Always include a small excerpt for artists
- // because they appear on the episode page
- $posts_with_excerpt = ['artist'];
- if( in_array($item->post_type, $posts_with_excerpt) ) {
- $excerpt = get_the_excerpt($item);
- $filtered[excerpt] = wp_specialchars_decode($excerpt);
- }
-
- // Always include a date for date based
- $posts_with_date = ['exhbition', 'event'];
- if( in_array($item->post_type, $posts_with_date) ) {
- $filtered[start] = get_post_meta($item->ID, $item->post_type . '-start-time', true);
- $filtered[end] = get_post_meta($item->ID, $item->post_type . '-end-time', true);
- $filtered[current] = time() <= (int)$filtered[end] && time() >= (int)$filtered[start];
- }
-
- return $filtered;
- }
-
- ?>
|