Making WordPress.org

Changeset 10271


Ignore:
Timestamp:
09/16/2020 06:17:05 PM (4 years ago)
Author:
iandunn
Message:

Events: Apply coding standards.

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

    r10270 r10271  
    101101    $base_dir = dirname( dirname( __DIR__ ) );
    102102
    103     require( $base_dir . '/init.php' );
    104     require( $base_dir . '/includes/hyperdb/bb-10-hyper-db.php' );
    105     include( $base_dir . '/includes/wp-json-encode.php' );
     103    require $base_dir . '/init.php';
     104    require $base_dir . '/includes/hyperdb/bb-10-hyper-db.php';
     105    include $base_dir . '/includes/wp-json-encode.php';
    106106
    107107    if ( ! defined( 'RUNNING_TESTS' ) || ! RUNNING_TESTS ) {
    108         include( $base_dir . '/includes/object-cache.php' );
     108        include $base_dir . '/includes/object-cache.php';
    109109    }
    110110}
     
    125125
    126126    if ( isset( $_GET['country'] ) ) {
    127         $location_args['country'] = $_GET['country'];
     127        $location_args['country']             = $_GET['country'];
    128128        $location_args['restrict_by_country'] = true;
    129129    }
     
    346346
    347347    // Exact match
    348     $query = "
     348    $query = '
    349349        SELECT name, latitude, longitude, country
    350350        FROM geoname_summary
     
    355355            population DESC,
    356356            BINARY LOWER( %s ) = BINARY LOWER( name ) DESC
    357         LIMIT 1";
     357        LIMIT 1';
    358358
    359359    $prepared_query = $wpdb->prepare( $query, $location_name, $country, $timezone, $location_name );
     
    366366    // Wildcard match
    367367    if ( ! $row && $wildcard && 'ASCII' !== mb_detect_encoding( $location_name ) ) {
    368         $query = "
     368        $query = '
    369369            SELECT name, latitude, longitude, country
    370370            FROM geoname_summary
     
    375375                population DESC,
    376376                BINARY LOWER( %s ) = BINARY LOWER( LEFT( name, %d ) ) DESC
    377             LIMIT 1";
     377            LIMIT 1';
    378378
    379379        $prepared_query = $wpdb->prepare( $query, $wpdb->esc_like( $location_name ) . '%', $country, $timezone, $location_name, mb_strlen( $location_name ) );
     
    432432        $from    = 'ip2location';
    433433        $where   = 'ip_to >= %d';
    434     } else if ( filter_var( $dotted_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 ) ) {
     434    } elseif ( filter_var( $dotted_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 ) ) {
    435435        $long_ip = _ip2long_v6( $dotted_ip );
    436436        $from    = 'ipv62location';
    437         $where   = "ip_to >= CAST( %s AS DECIMAL( 39, 0 ) )";
     437        $where   = 'ip_to >= CAST( %s AS DECIMAL( 39, 0 ) )';
    438438    }
    439439
     
    496496
    497497    while ( $bits >= 0 ) {
    498         $bin = sprintf( "%08b", ( ord( $int[ $bits ] ) ) );
     498        $bin = sprintf( '%08b', ( ord( $int[ $bits ] ) ) );
    499499
    500500        if ( $ipv6long ) {
     
    541541            'description' => false,
    542542            'latitude'    => $args['latitude'],
    543             'longitude'   => $args['longitude']
     543            'longitude'   => $args['longitude'],
    544544        );
    545545    }
     
    685685            $location_name_parts[ $location_word_count - 1 ]
    686686        );
    687         $country = get_country_from_name( $country_name );
     687        $country      = get_country_from_name( $country_name );
    688688    }
    689689
     
    696696            $location_name_parts[ $location_word_count - 1 ]
    697697        );
    698         $country = get_country_from_name( $country_name );
     698        $country      = get_country_from_name( $country_name );
    699699    }
    700700
     
    783783         * in the future if that's desired. If we do that, the Codex documentation should be updated.
    784784         */
    785         "( `meetup_url` IS NULL OR `meetup_url` <> 'https://www.meetup.com/learn-wordpress-discussions/' ) "
     785        "( `meetup_url` IS NULL OR `meetup_url` <> 'https://www.meetup.com/learn-wordpress-discussions/' ) ",
    786786    );
    787787
     
    881881            'end_unix_timestamp'    => strtotime( $event->end_date ) - $event->date_utc_offset,
    882882
    883 
    884883            'location'   => array(
    885884                // Capitalize it for use in presentation contexts, like the Events Widget.
     
    888887                'latitude'  => (float) $event->latitude,
    889888                'longitude' => (float) $event->longitude,
    890             )
     889            ),
    891890        );
    892891    }
     
    10061005            `date_utc` <= %s
    10071006        ORDER BY `date_utc` ASC
    1008         LIMIT 1"
    1009     ;
     1007        LIMIT 1";
    10101008
    10111009    $values[] = gmdate( 'Y-m-d', time() - DAY_IN_SECONDS );
     
    13171315        'wp15', '15 year', '15 ano', '15 año', '15 candeline', 'wordt 15',
    13181316        'anniversary', 'aniversário', 'aniversario', 'birthday', 'cumpleaños',
    1319         'Tanti auguri'
     1317        'Tanti auguri',
    13201318    );
    13211319
     
    13881386                    'latitude'  => (float) $raw_camp->latitude,
    13891387                    'longitude' => (float) $raw_camp->longitude,
    1390                 )
     1388                ),
    13911389            );
    13921390
     
    14681466                    'latitude'  => (float) $raw_discussion_group->latitude,
    14691467                    'longitude' => (float) $raw_discussion_group->longitude,
    1470                 )
     1468                ),
    14711469            );
    14721470        }
     
    15681566        'latitude' => array(
    15691567            'min' => rad2deg( $minimum_lat ),
    1570             'max' => rad2deg( $maximum_lat )
     1568            'max' => rad2deg( $maximum_lat ),
    15711569        ),
    15721570        'longitude' => array(
    15731571            'min' => rad2deg( $minimum_lon ),
    1574             'max' => rad2deg( $maximum_lon )
    1575         )
     1572            'max' => rad2deg( $maximum_lon ),
     1573        ),
    15761574    );
    15771575}
  • sites/trunk/api.wordpress.org/public_html/events/1.0/tests/test-index.php

    r10250 r10271  
    1616    define( 'SAVEQUERIES',   true );
    1717
    18     require_once( dirname( __DIR__ ) . '/index.php' );
    19 
    20     $tests_failed = 0;
     18    require_once dirname( __DIR__ ) . '/index.php';
     19
     20    $tests_failed  = 0;
    2121    $tests_failed += test_get_location();
    2222    $tests_failed += test_get_events();
     
    2929    $tests_failed += test_remove_duplicate_events();
    3030
    31     $query_count  = count( $wpdb->queries );
    32     $query_time   = array_sum( array_column( $wpdb->queries, 1 ) );
     31    $query_count = count( $wpdb->queries );
     32    $query_time  = array_sum( array_column( $wpdb->queries, 1 ) );
    3333
    3434    printf(
     
    184184        ),
    185185
    186 
    187186        /*
    188187         * A location couldn't be found
     
    191190            'input' => array(
    192191                'location_name' => 'Rivendell',
    193                 'ip'            => '127.0.0.1'
     192                'ip'            => '127.0.0.1',
    194193            ),
    195194            'expected' => false,
     
    354353        'city-with-diacritics-in-query' => array(
    355354            'input' => array(
    356                 'location_name' => "Doña Ana",
     355                'location_name' => 'Doña Ana',
    357356                'locale'        => 'en_US',
    358357                'timezone'      => 'America/Denver',
    359358            ),
    360359            'expected' => array(
    361                 'description' => "doña ana",
     360                'description' => 'doña ana',
    362361                'latitude'    => '32.390',
    363362                'longitude'   => '-106.814',
     
    368367        'city-with-diacritics-in-formal-name-but-not-in-query' => array(
    369368            'input' => array(
    370                 'location_name' => "Dona Ana",
     369                'location_name' => 'Dona Ana',
    371370                'locale'        => 'en_US',
    372371                'timezone'      => 'America/Denver',
    373372            ),
    374373            'expected' => array(
    375                 'description' => "dona ana",
     374                'description' => 'dona ana',
    376375                'latitude'    => '32.390',
    377376                'longitude'   => '-106.814',
     
    382381        'city-with-period-in-query' => array(
    383382            'input' => array(
    384                 'location_name' => "St. Louis",
     383                'location_name' => 'St. Louis',
    385384                'locale'        => 'en_US',
    386385                'timezone'      => 'America/Chicago',
    387386            ),
    388387            'expected' => array(
    389                 'description' => "st. louis",
     388                'description' => 'st. louis',
    390389                'latitude'    => '38.627',
    391390                'longitude'   => '-90.198',
     
    396395        'city-with-period-in-formal-name-but-not-in-query' => array(
    397396            'input' => array(
    398                 'location_name' => "St Louis",
     397                'location_name' => 'St Louis',
    399398                'locale'        => 'en_US',
    400399                'timezone'      => 'America/Chicago',
    401400            ),
    402401            'expected' => array(
    403                 'description' => "st louis",
     402                'description' => 'st louis',
    404403                'latitude'    => '38.627',
    405404                'longitude'   => '-90.198',
     
    14961495    $duplicate_events = array(
    14971496        // Each of these represents an event; extraneous fields have been removed for readability.
    1498         array (
     1497        array(
    14991498            'url' => 'https://2020.us.wordcamp.org/',
    15001499        ),
    15011500
    1502         array (
     1501        array(
    15031502            'url' => 'https://2020.detroit.wordcamp.org/',
    15041503        ),
     
    15071506            // Intentionally missing the trailing slash, to account for inconsistencies in data.
    15081507            'url' => 'https://2020.us.wordcamp.org',
    1509         )
     1508        ),
    15101509    );
    15111510
     
    15131512
    15141513    $expected_result = array(
    1515         array (
     1514        array(
    15161515            'url' => 'https://2020.us.wordcamp.org',
    15171516        ),
    15181517
    1519         array (
     1518        array(
    15201519            'url' => 'https://2020.detroit.wordcamp.org/',
    15211520        ),
    15221521    );
    15231522
    1524     $actual_result   = remove_duplicate_events( $duplicate_events );
    1525     $passed          = $expected_result === $actual_result;
     1523    $actual_result = remove_duplicate_events( $duplicate_events );
     1524    $passed        = $expected_result === $actual_result;
    15261525
    15271526    output_results( 'remove duplicate events', $passed, $expected_result, $actual_result );
Note: See TracChangeset for help on using the changeset viewer.