Created
August 10, 2015 21:15
-
-
Save rveitch/f52f5f177c3ebf572eaf to your computer and use it in GitHub Desktop.
Bison Media JSON Feed Template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * JSON Feed Template for displaying JSON Posts feed. | |
| * | |
| */ | |
| $callback = trim(esc_html(get_query_var('callback'))); | |
| $charset = get_option('charset'); | |
| query_posts( array( 'post_type' => 'live_video' ) ); | |
| if ( have_posts() ) { | |
| global $wp_query; | |
| $query_array = $wp_query->query; | |
| // Make sure query args are always in the same order | |
| ksort( $query_array ); | |
| $json = array(); | |
| while ( have_posts() ) { | |
| the_post(); | |
| $id = (int) $post->ID; | |
| $alert = get_post_meta($id, 'alert', true); //Push Notification Text | |
| //Start Time | |
| $start_time_value = get_post_meta($id, 'start-time', true); | |
| $str_start_time = strtotime($start_time_value); | |
| $start_time = gmdate('Y-m-d H:i:s', $str_start_time); | |
| //End Time | |
| $end_time_value = get_post_meta($id, 'end-time', true); | |
| $str_end_time = strtotime($end_time_value); | |
| $end_time = gmdate('Y-m-d H:i:s', $str_end_time); | |
| //Current Time | |
| date_default_timezone_set("America/Chicago"); | |
| $current_time = date( 'Y-m-d H:i:s', current_time( 'timestamp', 0 ) ); | |
| $str_current_time = strtotime( $current_time ) - 18000; //convert to UTC timestamp minus 5 hour difference in seconds | |
| //Duration | |
| $event_duration = human_time_diff( $str_start_time, $str_end_time ); | |
| //Event Status | |
| if ( $str_start_time < $str_current_time and $str_end_time > $str_current_time ) { | |
| $time_compare = 'Event is in progress.'; | |
| } elseif ( $str_start_time > $str_current_time and $str_end_time > $str_current_time ) { | |
| $time_compare = 'Event is upcoming.'; | |
| } elseif ( $str_current_time > $str_start_time and $str_current_time > $str_end_time ) { | |
| $time_compare = 'Event is over.'; | |
| } else { | |
| $time_compare = 'Error comparing times.'; | |
| } | |
| //IsLive? | |
| if ( $str_start_time < $str_current_time and $str_end_time > $str_current_time ) { | |
| $islive = 1; | |
| } else { | |
| $islive = 0; | |
| } | |
| //JSON ARRAY | |
| $single = array( | |
| 'id' => $id , | |
| 'event' => get_the_title() , | |
| 'post-date' => get_the_date('Y-m-d H:i:s','','',false) , | |
| 'alert' => $alert , | |
| 'start-time' => $start_time , | |
| //'start-timestamp' => $str_start_time , | |
| 'end-time' => $end_time , | |
| //'end-timestamp' => $str_end_time , | |
| 'current-time' => $current_time , | |
| //'current-timestamp' => $str_current_time , | |
| 'event-duration' => $event_duration , | |
| 'event-status' => $time_compare , | |
| 'live' => $islive, | |
| ); | |
| //$custom_field_keys = get_post_custom_keys(); | |
| //foreach ( $custom_field_keys as $key => $value ) { | |
| // $valuet = trim($value); | |
| // if ( '_' == $valuet{0} ) | |
| // continue; | |
| // $single[$value] = get_post_meta($id, $value, true); | |
| // } //End Custom Field Keys | |
| $json[] = $single; //begin json feed | |
| } | |
| $json = json_encode($json); | |
| nocache_headers(); | |
| if (!empty($callback)) { | |
| header("Content-Type: application/x-javascript; charset={$charset}"); | |
| echo "{$callback}({$json});"; | |
| } else { | |
| header("Content-Type: application/json; charset={$charset}"); | |
| echo $json; | |
| } | |
| } else { | |
| status_header('404'); | |
| wp_die("404 Not Found"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment