Changeset 5491
- Timestamp:
- 05/16/2017 09:08:27 PM (8 years ago)
- Location:
- sites/trunk/api.wordpress.org/public_html/events/1.0
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/events/1.0/index.php
r5487 r5491 126 126 127 127 $events = get_events( $event_args ); 128 129 if ( isset( $location['internal'] ) && $location['internal'] ) { 130 $location = rebuild_location_from_event_source( $events ); 131 } 128 132 } 129 133 … … 353 357 * Determine a location for the given IPv4 address 354 358 * 359 * NOTE: The location that is found here cannot be returned to the client. 360 * See `rebuild_location_from_geonames()`. 361 * 355 362 * @todo - Add support for IPv6 addresses. Otherwise, this will quickly lose effectiveness. As of March 2017, IPv6 356 363 * adoption is at 16% globally and rising relatively fast. Some countries are as high as 30%. … … 385 392 386 393 return $row; 394 } 395 396 /** 397 * Rebuild the location given to the client from the event source data 398 * 399 * We cannot publicly expose location data that we retrieve from the `ip2location` database, because that would 400 * violate their licensing terms. We can only use the information internally, for the purposes of completing the 401 * program's business logic (determining nearby events). 402 * 403 * Once we have nearby events, though, we can take advantage of the data that's available in the `wporg_events` table. 404 * That table contains the locations details for the event's venue, which was sourced from the respective APIs 405 * (WordCamp.org, Meetup.com, etc). We can return the venue's location data without violating any terms. 406 * 407 * See https://meta.trac.wordpress.org/ticket/2823#comment:15 408 * See https://meta.trac.wordpress.org/ticket/2823#comment:21 409 * 410 * @param array $events 411 * 412 * @return array 413 */ 414 function rebuild_location_from_event_source( $events ) { 415 $location = array(); 416 417 foreach ( $events as $event ) { 418 if ( ! empty( $event['location']['location'] ) && ! empty( $event['location']['latitude'] ) ) { 419 $location = $event['location']; 420 break; 421 } 422 } 423 424 return $location; 387 425 } 388 426 … … 496 534 'longitude' => $guess->ip_longitude, 497 535 'country' => $guess->country_short, 536 'internal' => true, // this location cannot be shared publicly, see `rebuild_location_from_geonames()` 498 537 ); 499 538 } … … 698 737 $bounded_box = get_bounded_coordinates( $args['nearby']['latitude'], $args['nearby']['longitude'], $distance ); 699 738 $nearby_where[] = '( `type` = %s AND `latitude` BETWEEN %f AND %f AND `longitude` BETWEEN %f AND %f )'; 700 $sql_values[] = $type; 739 $sql_values[] = $type; 701 740 $sql_values[] = $bounded_box['latitude']['min']; 702 741 $sql_values[] = $bounded_box['latitude']['max']; -
sites/trunk/api.wordpress.org/public_html/events/1.0/tests/test-index.php
r5490 r5491 718 718 'longitude' => '31.054', 719 719 'country' => 'ZW', 720 'internal' => true, 720 721 ), 721 722 ), … … 728 729 'longitude' => '35.945', 729 730 'country' => 'JO', 731 'internal' => true, 730 732 ), 731 733 ), … … 738 740 'longitude' => '-5.900', 739 741 'country' => 'GB', 742 'internal' => true, 740 743 ), 741 744 ), … … 748 751 'longitude' => '-99.033', 749 752 'country' => 'MX', 753 'internal' => true, 750 754 ), 751 755 ), … … 758 762 'longitude' => '174.767', 759 763 'country' => 'NZ', 764 'internal' => true, 760 765 ), 761 766 ), … … 768 773 'longitude' => '-77.028', 769 774 'country' => 'PE', 775 'internal' => true, 770 776 ), 771 777 ),
Note: See TracChangeset
for help on using the changeset viewer.