Changeset 4884
- Timestamp:
- 02/04/2017 03:26:36 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/events/1.0/index.php
r4883 r4884 40 40 $location = get_location( $location_args ); 41 41 42 $event_args = array(); 43 if ( isset( $_REQUEST['number'] ) ) { 44 $event_args['number'] = $_REQUEST['number']; 45 } 46 if ( !empty( $location['latitude'] ) ) { 47 $event_args['nearby'] = array( 48 'latitude' => $location['latitude'], 49 'longitude' => $location['longitude'], 50 ); 51 } 52 if ( !empty( $location['country'] ) ) { 53 $event_args['country'] = $location['country']; 54 } 55 56 $events = get_events( $event_args ); 42 if ( false === $location ) { 43 // No location was determined for the request. Bail with an error. 44 $events = array(); 45 $error = 'no_location_available'; 46 } else { 47 $event_args = array(); 48 if ( isset( $_REQUEST['number'] ) ) { 49 $event_args['number'] = $_REQUEST['number']; 50 } 51 if ( !empty( $location['latitude'] ) ) { 52 $event_args['nearby'] = array( 53 'latitude' => $location['latitude'], 54 'longitude' => $location['longitude'], 55 ); 56 } 57 if ( !empty( $location['country'] ) ) { 58 $event_args['country'] = $location['country']; 59 } 60 61 $events = get_events( $event_args ); 62 } 57 63 58 64 header( 'Expires: ' . gmdate( 'r', time() + $ttl ) ); 59 65 header( 'Access-Control-Allow-Origin: *' ); 60 66 header( 'Content-Type: application/json; charset=UTF-8' ); 61 echo wp_json_encode( compact( ' location', 'events', 'ttl', 'debug' ) );67 echo wp_json_encode( compact( 'error', 'location', 'events', 'ttl' ) ); 62 68 63 69 … … 102 108 if ( isset( $args['location_name'] ) ) { 103 109 $guess = guess_location_from_geonames( $args['location_name'], $args['timezone'] ?? '', $country_code ); 104 if ( $guess ) 110 if ( $guess ) { 105 111 return array( 106 112 'description' => $guess->name, … … 109 115 'country' => $guess->country, 110 116 ); 117 } 111 118 } 112 119 … … 120 127 'longitude' => $guess->ip_longitude, 121 128 'country' => $guess->country_short, 122 129 ); 123 130 } 124 131 } … … 136 143 } 137 144 138 return array( 139 'description' => 'Global', 140 'latitude' => 0, 141 'longitude' => 0, 142 ); 145 // If any of these are specified, and no localitity was guessed based on the above checks, bail with no location. 146 if ( isset( $args['location_name'] ) || isset( $args['ip'] ) || ! empty( $args['latitude'] ) || ! empty( $args['longitude'] ) ) { 147 return false; 148 } 149 150 // No specific location details. 151 return array(); 143 152 } 144 153
Note: See TracChangeset
for help on using the changeset viewer.