Changeset 8379
- Timestamp:
- 03/01/2019 07:59:55 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.tv/public_html/wp-content/themes/wptv2/plugins/wordpresstv-rest/wordpresstv-rest.php
r1024 r8379 31 31 } 32 32 33 /** 34 * Handle API requests. 35 * 36 * Supported Endpoints: 37 * - /api/videos.json 38 * Accepts all WP_Query parameters, such as 'event', 'per_page', and 'paged'. 39 * - /api/events.json 40 * - /api/speakers.json 41 * - /api/languages.json 42 * - /api/tags.json 43 * - /api/categories.json 44 * All above endpoints accept 'paged'. 45 */ 33 46 function template_redirect() { 34 47 global $wp_query, $post, $wptv; … … 53 66 } 54 67 68 $response['query'] = array( 69 'results' => (int) $wp_query->found_posts, 70 'pages' => (int) $wp_query->max_num_pages, 71 ); 72 55 73 $response['videos'] = array(); 56 74 while ( have_posts() ) { … … 63 81 ob_end_clean(); 64 82 65 $response['videos'][] = array( 66 'title' => $post->post_title, 67 'permalink' => get_permalink( get_the_ID() ), 68 'thumbnail' => $thumbnail, 83 $video = array( 84 'title' => $post->post_title, 85 'permalink' => get_permalink( get_the_ID() ), 86 'thumbnail' => $thumbnail, 87 'date' => get_the_date(), 88 'description' => $post->post_excerpt, 89 'slides' => get_post_meta( $post->ID, '_wptv_slides_url', true ), 90 'speakers' => array(), 91 'event' => array(), 92 'language' => array(), 93 'tags' => array(), 94 'category' => array(), 95 'year' => false, 96 'location' => false, 97 'producer' => array(), 98 'video' => array( 99 'mp4' => array(), 100 'ogg' => array(), 101 ) 69 102 ); 103 104 foreach ( [ 'speakers', 'event', 'language', 'tags', 'category' ] as $tax ) { 105 $terms = get_the_terms( get_the_ID(), $tax ); 106 if ( ! $terms || is_wp_error( $terms ) ) { 107 continue; 108 } 109 foreach ( $terms as $t ) { 110 // Special Cases 111 if ( 'category' == $tax && $t->parent == 91093 /* Year */ ) { 112 $video['year'] = $t->name; 113 continue; 114 } elseif ( 'category' == $tax && $t->parent == 6418 /* Location */ ) { 115 $video['location'] = $t->name; 116 continue; 117 } 118 119 $video[ $tax ][] = array( 120 'slug' => $t->slug, 121 'name' => $t->name, 122 'link' => get_term_link( $t ) 123 ); 124 } 125 } 126 127 if ( $producer = get_the_terms( get_the_ID(), 'producer' ) ) { 128 $video['producer']['name'] = $producer[0]->name; 129 } 130 if ( $producer_username = get_the_terms( get_the_ID(), 'producer-username' ) ) { 131 $video['producer']['username'] = $producer_username[0]->name; 132 } 133 134 if ( function_exists( 'find_all_videopress_shortcodes' ) ) { 135 $post_videos = array_keys( find_all_videopress_shortcodes( $post->post_content ) ); 136 if ( $post_videos ) { 137 $post_video = video_get_info_by_guid( $post_videos[0] ); 138 139 // Ogg 140 if ( $link = video_highest_resolution_ogg( $post_video ) ) { 141 $video['video']['ogg']['low'] = $link; 142 } 143 144 // MP4 145 $mp4_formats = array( 'low' => 'fmt_std', 'med' => 'fmt_dvd', 'high' => 'fmt_hd' ); 146 foreach ( $mp4_formats as $mp4_field => $mp4_format ) { 147 if ( $link = video_url_by_format( $post_video, $mp4_format ) ) { 148 $video['video']['mp4'][ $mp4_field ] = $link; 149 } 150 } 151 } 152 } 153 154 $response['videos'][] = $video; 155 } 156 157 break; 158 case 'events': 159 case 'speakers': 160 case 'languages': 161 case 'tags': 162 case 'categories': 163 $taxonomies = array( 164 'events' => 'event', 165 'speakers' => 'speakers', 166 'languages' => 'language', 167 'tags' => 'post_tag', 168 'categories' => 'category', 169 ); 170 171 $taxonomy = $taxonomies[ $method ]; 172 $taxonomy_obj = get_taxonomy( $taxonomy ); 173 $total_count = wp_count_terms( $taxonomy, array( 'hide_empty ' => true ) ); 174 175 $page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; 176 $per_page = 200; 177 178 $terms = get_terms( array( 179 'taxonomy' => $taxonomy, 180 'hide_empty' => true, 181 'number' => $per_page, 182 'offset' => $per_page * ($page - 1), 183 'orderby' => 'id', 184 'order' => 'DESC', 185 ) ); 186 187 $response['query'] = array( 188 'results' => (int) $total_count, 189 'page' => $page, 190 'pages' => ceil( $total_count / $per_page ), 191 ); 192 193 $response[ $method ] = array(); 194 foreach ( $terms as $t ) { 195 $item = array( 196 'name' => $t->name, 197 'link' => get_term_link( $t ), 198 'api' => add_query_arg( $taxonomy_obj->query_var, $t->slug, home_url( '/api/videos.json') ), 199 'videos' => $t->count, 200 ); 201 202 if ( 'event' == $t->taxonomy ) { 203 $item['youtube_playlist_id'] = get_option( "term_meta_{$t->term_id}_youtube_playlist_id", '' ); 204 $item['hashtag'] = get_option( "term_meta_{$t->term_id}_hashtag", '' ); 205 } 206 207 $response[ $method ][] = $item; 70 208 } 71 209
Note: See TracChangeset
for help on using the changeset viewer.