Making WordPress.org

Changeset 5491


Ignore:
Timestamp:
05/16/2017 09:08:27 PM (9 years ago)
Author:
iandunn
Message:

Events: Replace IP geolocated data with venue location data

See #2823

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  
    126126
    127127                $events = get_events( $event_args );
     128
     129                if ( isset( $location['internal'] ) && $location['internal'] ) {
     130                        $location = rebuild_location_from_event_source( $events );
     131                }
    128132        }
    129133
     
    353357 * Determine a location for the given IPv4 address
    354358 *
     359 * NOTE: The location that is found here cannot be returned to the client.
     360 *       See `rebuild_location_from_geonames()`.
     361 *
    355362 * @todo - Add support for IPv6 addresses. Otherwise, this will quickly lose effectiveness. As of March 2017, IPv6
    356363 *         adoption is at 16% globally and rising relatively fast. Some countries are as high as 30%.
     
    385392
    386393        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 */
     414function 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;
    387425}
    388426
     
    496534                                'longitude'   => $guess->ip_longitude,
    497535                                'country'     => $guess->country_short,
     536                                'internal'    => true, // this location cannot be shared publicly, see `rebuild_location_from_geonames()`
    498537                        );
    499538                }
     
    698737                        $bounded_box = get_bounded_coordinates( $args['nearby']['latitude'], $args['nearby']['longitude'], $distance );
    699738                        $nearby_where[] = '( `type` = %s AND `latitude` BETWEEN %f AND %f AND `longitude` BETWEEN %f AND %f )';
    700                         $sql_values[] = $type;                 
     739                        $sql_values[] = $type;
    701740                        $sql_values[] = $bounded_box['latitude']['min'];
    702741                        $sql_values[] = $bounded_box['latitude']['max'];
  • sites/trunk/api.wordpress.org/public_html/events/1.0/tests/test-index.php

    r5490 r5491  
    718718                                'longitude'   => '31.054',
    719719                                'country'     => 'ZW',
     720                                'internal'    => true,
    720721                        ),
    721722                ),
     
    728729                                'longitude'   => '35.945',
    729730                                'country'     => 'JO',
     731                                'internal'    => true,
    730732                        ),
    731733                ),
     
    738740                                'longitude'   => '-5.900',
    739741                                'country'     => 'GB',
     742                                'internal'    => true,
    740743                        ),
    741744                ),
     
    748751                                'longitude'   => '-99.033',
    749752                                'country'     => 'MX',
     753                                'internal'    => true,
    750754                        ),
    751755                ),
     
    758762                                'longitude'   => '174.767',
    759763                                'country'     => 'NZ',
     764                                'internal'    => true,
    760765                        ),
    761766                ),
     
    768773                                'longitude'   => '-77.028',
    769774                                'country'     => 'PE',
     775                                'internal'    => true,
    770776                        ),
    771777                ),
Note: See TracChangeset for help on using the changeset viewer.