Making WordPress.org


Ignore:
Timestamp:
12/14/2017 11:45:18 PM (9 years ago)
Author:
iandunn
Message:

Events: Apply coding standards.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/events/1.0/index.php

    r6275 r6276  
    3232         */
    3333        define( 'THROTTLE_STICKY_WORDCAMPS', false );
    34         define( 'THROTTLE_GEONAMES',    0 );
    35         define( 'THROTTLE_IP2LOCATION', 0 );
    36 
    37         defined( 'DAY_IN_SECONDS' ) or define( 'DAY_IN_SECONDS', 60 * 60 * 24 );
     34        define( 'THROTTLE_GEONAMES',         0 );
     35        define( 'THROTTLE_IP2LOCATION',      0 );
     36
     37        defined( 'DAY_IN_SECONDS'  ) or define( 'DAY_IN_SECONDS', 60 * 60 * 24 );
    3838        defined( 'WEEK_IN_SECONDS' ) or define( 'WEEK_IN_SECONDS', 7 * DAY_IN_SECONDS );
    3939
     
    5959 */
    6060function bootstrap() {
    61         $base_dir = dirname( dirname(__DIR__ ) );
     61        $base_dir = dirname( dirname( __DIR__ ) );
    6262
    6363        require( $base_dir . '/init.php' );
     
    8080        // If a precise location is known, use a GET request. The values here should come from the `location` key of the result of a POST request.
    8181        if ( isset( $_GET['latitude'] ) ) {
    82                 $location_args['latitude'] = $_GET['latitude'];
     82                $location_args['latitude']  = $_GET['latitude'];
    8383                $location_args['longitude'] = $_GET['longitude'];
    8484        }
     
    113113                 */
    114114                $public_ip = filter_var(
    115                     $_REQUEST['ip'],
    116                     FILTER_VALIDATE_IP,
    117                     FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
     115                        $_REQUEST['ip'],
     116                        FILTER_VALIDATE_IP,
     117                        FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
    118118                );
    119119
     
    153153                if ( ! empty( $location['latitude'] ) ) {
    154154                        $event_args['nearby'] = array(
    155                                 'latitude' => $location['latitude'],
     155                                'latitude'  => $location['latitude'],
    156156                                'longitude' => $location['longitude'],
    157157                        );
     
    362362        if ( false === $long_ip || ! isset( $from, $where ) ) {
    363363                wp_cache_set( $cache_key, '__NOT_FOUND__', $cache_group, $cache_life );
     364
    364365                return false;
    365366        }
     
    377378        if ( ! $row || '-' == $row->country_short ) {
    378379                wp_cache_set( $cache_key, '__NOT_FOUND__', $cache_group, $cache_life );
     380
    379381                return false;
    380382        }
     
    476478
    477479                $country_code = get_country_code_from_locale( $args['locale'] ?? '' );
    478                 $guess = guess_location_from_city( $args['location_name'], $args['timezone'] ?? '', $country_code );
     480                $guess        = guess_location_from_city( $args['location_name'], $args['timezone'] ?? '', $country_code );
    479481
    480482                if ( $guess ) {
    481483                        $location = array(
    482484                                'description' => $guess->name,
    483                                 'latitude' => $guess->latitude,
    484                                 'longitude' => $guess->longitude,
    485                                 'country' => $guess->country,
     485                                'latitude'    => $guess->latitude,
     486                                'longitude'   => $guess->longitude,
     487                                'country'     => $guess->country,
    486488                        );
    487489                } else {
     
    596598        if ( ! $country && $location_word_count >= 2 ) {
    597599                // Catch input like "Vancouver Canada"
    598                 $country_id   = $location_name_parts[ $location_word_count - 1 ];
    599                 $country      = get_country_from_name( $country_id );
     600                $country_id = $location_name_parts[ $location_word_count - 1 ];
     601                $country    = get_country_from_name( $country_id );
    600602        }
    601603
     
    684686
    685687        $wheres = array();
    686         if ( !empty( $args['type'] ) && in_array( $args['type'], array( 'meetup', 'wordcamp' ) ) ) {
    687                 $wheres[] = '`type` = %s';
     688        if ( ! empty( $args['type'] ) && in_array( $args['type'], array( 'meetup', 'wordcamp' ) ) ) {
     689                $wheres[]     = '`type` = %s';
    688690                $sql_values[] = $args['type'];
    689691        }
    690692
    691693        // If we want nearby events, create a WHERE based on a bounded box of lat/long co-ordinates.
    692         if ( !empty( $args['nearby'] ) ) {
     694        if ( ! empty( $args['nearby'] ) ) {
    693695                $nearby_where = array();
    694696
    695697                foreach ( $event_distances as $type => $distance ) {
    696                         if ( !empty( $args['type'] ) && $type != $args['type'] ) {
     698                        if ( ! empty( $args['type'] ) && $type != $args['type'] ) {
    697699                                continue;
    698700                        }
    699                         $bounded_box = get_bounded_coordinates( $args['nearby']['latitude'], $args['nearby']['longitude'], $distance );
     701
     702                        $bounded_box    = get_bounded_coordinates( $args['nearby']['latitude'], $args['nearby']['longitude'], $distance );
    700703                        $nearby_where[] = '( `type` = %s AND `latitude` BETWEEN %f AND %f AND `longitude` BETWEEN %f AND %f )';
    701                         $sql_values[] = $type;
    702                         $sql_values[] = $bounded_box['latitude']['min'];
    703                         $sql_values[] = $bounded_box['latitude']['max'];
    704                         $sql_values[] = $bounded_box['longitude']['min'];
    705                         $sql_values[] = $bounded_box['longitude']['max'];
     704                        $sql_values[]   = $type;
     705                        $sql_values[]   = $bounded_box['latitude']['min'];
     706                        $sql_values[]   = $bounded_box['latitude']['max'];
     707                        $sql_values[]   = $bounded_box['longitude']['min'];
     708                        $sql_values[]   = $bounded_box['longitude']['max'];
    706709                }
    707710                // Build the nearby where as a OR as different event types have different distances.
     
    710713
    711714        // Allow queries for limiting to specific countries.
    712         if ( !empty( $args['country'] ) && preg_match( '![a-z]{2}!i', $args['country'] ) ) {
    713                 $wheres[] = '`country` = %s';
     715        if ( ! empty( $args['country'] ) && preg_match( '![a-z]{2}!i', $args['country'] ) ) {
     716                $wheres[]     = '`country` = %s';
    714717                $sql_values[] = $args['country'];
    715718        }
     
    724727        // Limit
    725728        if ( isset( $args['number'] ) ) {
    726                 $sql_limits = 'LIMIT %d';
     729                $sql_limits   = 'LIMIT %d';
    727730                $sql_values[] = $args['number'];
    728731        }
     
    758761        foreach ( $raw_events as $event ) {
    759762                $events[] = array(
    760                         'type'  => $event->type,
    761                         'title' => $event->title,
    762                         'url'   => $event->url,
    763                         'meetup' => $event->meetup,
     763                        'type'       => $event->type,
     764                        'title'      => $event->title,
     765                        'url'        => $event->url,
     766                        'meetup'     => $event->meetup,
    764767                        'meetup_url' => $event->meetup_url,
    765                         'date' => $event->date_utc, // TODO: DB stores a local date, not UTC.
    766                         'location' => array(
    767                                 'location' => $event->location,
    768                                 'country' => $event->country,
    769                                 'latitude' => (float) $event->latitude,
     768                        'date'       => $event->date_utc, // TODO: DB stores a local date, not UTC.
     769                        'location'   => array(
     770                                'location'  => $event->location,
     771                                'country'   => $event->country,
     772                                'latitude'  => (float) $event->latitude,
    770773                                'longitude' => (float) $event->longitude,
    771774                        )
     
    775778        wp_cache_set( $cache_key, $events, $cache_group, $cache_life );
    776779
    777         return $events; 
     780        return $events;
    778781}
    779782
     
    858861        if ( ! empty( $request_args['nearby'] ) ) {
    859862                $bounded_box = get_bounded_coordinates( $request_args['nearby']['latitude'], $request_args['nearby']['longitude'], $distance );
    860                 $where[]  = '( `latitude` BETWEEN %f AND %f AND `longitude` BETWEEN %f AND %f )';
    861                 $values[] = $bounded_box['latitude']['min'];
    862                 $values[] = $bounded_box['latitude']['max'];
    863                 $values[] = $bounded_box['longitude']['min'];
    864                 $values[] = $bounded_box['longitude']['max'];
     863                $where[]     = '( `latitude` BETWEEN %f AND %f AND `longitude` BETWEEN %f AND %f )';
     864                $values[]    = $bounded_box['latitude']['min'];
     865                $values[]    = $bounded_box['latitude']['max'];
     866                $values[]    = $bounded_box['longitude']['min'];
     867                $values[]    = $bounded_box['longitude']['max'];
    865868        }
    866869
     
    904907 */
    905908function add_regional_wordcamps( $local_events, $user_agent ) {
    906         $time = time();
     909        $time               = time();
    907910        $regional_wordcamps = array();
    908911
     
    968971 * @param float $lon            The longitude of the location.
    969972 * @param int   $distance_in_km The distance of the bounded box, in KM.
     973 *
    970974 * @return array of bounded box.
    971975 */
     
    974978
    975979        $angular_distance = $distance_in_km / 6371; // 6371 = radius of the earth in KM.
    976         $lat = deg2rad( $lat );
    977         $lon = deg2rad( $lon );
     980        $lat              = deg2rad( $lat );
     981        $lon              = deg2rad( $lon );
    978982
    979983        $earth_min_lat = -1.5707963267949; // = deg2rad(  -90 ) = -PI/2
     
    986990        $minimum_lon = $maximum_lon = 0;
    987991
    988         // Ensure that we're not within a pole-area of the world, weirdness will ensure.
     992        // Ensure that we're not within a pole-area of the world, weirdness will ensue.
    989993        if ( $minimum_lat > $earth_min_lat && $maximum_lat < $earth_max_lat ) {
    990 
    991                 $lon_delta = asin( sin( $angular_distance ) / cos( $lat ) );
    992 
     994                $lon_delta   = asin( sin( $angular_distance ) / cos( $lat ) );
    993995                $minimum_lon = $lon - $lon_delta;
     996                $maximum_lon = $lon + $lon_delta;
     997
    994998                if ( $minimum_lon < $earth_min_lon ) {
    995999                        $minimum_lon += 2 * pi();
    9961000                }
    9971001
    998                 $maximum_lon = $lon + $lon_delta;
    9991002                if ( $maximum_lon > $earth_max_lon ) {
    10001003                        $maximum_lon -= 2 * pi();
    10011004                }
    1002 
    10031005        } else {
    10041006                // Use a much simpler range in polar regions.
Note: See TracChangeset for help on using the changeset viewer.