Changeset 4881
- Timestamp:
- 02/04/2017 10:56:31 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/events/1.0/index.php
r4878 r4881 55 55 $events = get_events( $event_args ); 56 56 57 header( 'Expires: ' . gmdate( 'r', time() + $ttl ) ); 58 header( 'Access-Control-Allow-Origin: *' ); 57 59 header( 'Content-Type: application/json; charset=UTF-8' ); 58 60 echo wp_json_encode( compact( 'location', 'events', 'ttl', 'debug' ) ); 61 59 62 60 63 function guess_location_from_geonames( $location_name, $timezone, $country ) { … … 83 86 if ( isset( $args['country'] ) ) { 84 87 return array( 85 // TODO include a 'description' key of the country name?86 88 'country' => $args['country'], 87 89 ); … … 118 120 } 119 121 120 if ( !empty( $args['latitude'] ) && ! empty( $args['longitude'] ) ) { 122 if ( 123 ! empty( $args['latitude'] ) && is_numeric( $args['latitude'] ) && 124 ! empty( $args['longitude'] ) && is_numeric( $args['longitude'] ) 125 ) { 121 126 // TODO: Ensure that the data here is rounded to city-level and return the name of the city/region. 122 127 return array( … … 145 150 146 151 $cache_key = 'events:' . md5( serialize( $args ) ); 147 /*if ( false !== ( $data = wp_cache_get( $cache_key, $cache_group ) ) ) {152 if ( false !== ( $data = wp_cache_get( $cache_key, $cache_group ) ) ) { 148 153 return $data; 149 } */154 } 150 155 151 156 $wheres = array(); … … 180 185 181 186 // Allow queries for limiting to specific countries. 182 if ( !empty( $args['country'] ) ) {187 if ( !empty( $args['country'] ) && preg_match( '![a-z]{2}!i', $args['country'] ) ) { 183 188 $wheres[] = '`country` = %s'; 184 // TODO: Maybe: Sanitize to 2-character country code?185 189 $sql_values[] = $args['country']; 186 190 } … … 188 192 // Just show upcoming events 189 193 $wheres[] = '`date_utc` >= %s'; 190 $sql_values[] = gmdate( 'Y-m-d' ); 194 // Dates are in local-time not UTC, so the API output will contain events that have already happened in some parts of the world. 195 // TODO update this when the UTC dates are stored. 196 $sql_values[] = gmdate( 'Y-m-d', time() - ( 24 * 60 * 60 ) ); 191 197 192 198 // Limit … … 232 238 } 233 239 234 //wp_cache_set( $cache_key, $events, $cache_group, $cache_life );240 wp_cache_set( $cache_key, $events, $cache_group, $cache_life ); 235 241 return $events; 236 242 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)