Changeset 10271
- Timestamp:
- 09/16/2020 06:17:05 PM (5 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
r10270 r10271 101 101 $base_dir = dirname( dirname( __DIR__ ) ); 102 102 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'; 106 106 107 107 if ( ! defined( 'RUNNING_TESTS' ) || ! RUNNING_TESTS ) { 108 include ( $base_dir . '/includes/object-cache.php' );108 include $base_dir . '/includes/object-cache.php'; 109 109 } 110 110 } … … 125 125 126 126 if ( isset( $_GET['country'] ) ) { 127 $location_args['country'] = $_GET['country'];127 $location_args['country'] = $_GET['country']; 128 128 $location_args['restrict_by_country'] = true; 129 129 } … … 346 346 347 347 // Exact match 348 $query = "348 $query = ' 349 349 SELECT name, latitude, longitude, country 350 350 FROM geoname_summary … … 355 355 population DESC, 356 356 BINARY LOWER( %s ) = BINARY LOWER( name ) DESC 357 LIMIT 1 ";357 LIMIT 1'; 358 358 359 359 $prepared_query = $wpdb->prepare( $query, $location_name, $country, $timezone, $location_name ); … … 366 366 // Wildcard match 367 367 if ( ! $row && $wildcard && 'ASCII' !== mb_detect_encoding( $location_name ) ) { 368 $query = "368 $query = ' 369 369 SELECT name, latitude, longitude, country 370 370 FROM geoname_summary … … 375 375 population DESC, 376 376 BINARY LOWER( %s ) = BINARY LOWER( LEFT( name, %d ) ) DESC 377 LIMIT 1 ";377 LIMIT 1'; 378 378 379 379 $prepared_query = $wpdb->prepare( $query, $wpdb->esc_like( $location_name ) . '%', $country, $timezone, $location_name, mb_strlen( $location_name ) ); … … 432 432 $from = 'ip2location'; 433 433 $where = 'ip_to >= %d'; 434 } else 434 } elseif ( filter_var( $dotted_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 ) ) { 435 435 $long_ip = _ip2long_v6( $dotted_ip ); 436 436 $from = 'ipv62location'; 437 $where = "ip_to >= CAST( %s AS DECIMAL( 39, 0 ) )";437 $where = 'ip_to >= CAST( %s AS DECIMAL( 39, 0 ) )'; 438 438 } 439 439 … … 496 496 497 497 while ( $bits >= 0 ) { 498 $bin = sprintf( "%08b", ( ord( $int[ $bits ] ) ) );498 $bin = sprintf( '%08b', ( ord( $int[ $bits ] ) ) ); 499 499 500 500 if ( $ipv6long ) { … … 541 541 'description' => false, 542 542 'latitude' => $args['latitude'], 543 'longitude' => $args['longitude'] 543 'longitude' => $args['longitude'], 544 544 ); 545 545 } … … 685 685 $location_name_parts[ $location_word_count - 1 ] 686 686 ); 687 $country = get_country_from_name( $country_name );687 $country = get_country_from_name( $country_name ); 688 688 } 689 689 … … 696 696 $location_name_parts[ $location_word_count - 1 ] 697 697 ); 698 $country = get_country_from_name( $country_name );698 $country = get_country_from_name( $country_name ); 699 699 } 700 700 … … 783 783 * in the future if that's desired. If we do that, the Codex documentation should be updated. 784 784 */ 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/' ) ", 786 786 ); 787 787 … … 881 881 'end_unix_timestamp' => strtotime( $event->end_date ) - $event->date_utc_offset, 882 882 883 884 883 'location' => array( 885 884 // Capitalize it for use in presentation contexts, like the Events Widget. … … 888 887 'latitude' => (float) $event->latitude, 889 888 'longitude' => (float) $event->longitude, 890 ) 889 ), 891 890 ); 892 891 } … … 1006 1005 `date_utc` <= %s 1007 1006 ORDER BY `date_utc` ASC 1008 LIMIT 1" 1009 ; 1007 LIMIT 1"; 1010 1008 1011 1009 $values[] = gmdate( 'Y-m-d', time() - DAY_IN_SECONDS ); … … 1317 1315 'wp15', '15 year', '15 ano', '15 año', '15 candeline', 'wordt 15', 1318 1316 'anniversary', 'aniversário', 'aniversario', 'birthday', 'cumpleaños', 1319 'Tanti auguri' 1317 'Tanti auguri', 1320 1318 ); 1321 1319 … … 1388 1386 'latitude' => (float) $raw_camp->latitude, 1389 1387 'longitude' => (float) $raw_camp->longitude, 1390 ) 1388 ), 1391 1389 ); 1392 1390 … … 1468 1466 'latitude' => (float) $raw_discussion_group->latitude, 1469 1467 'longitude' => (float) $raw_discussion_group->longitude, 1470 ) 1468 ), 1471 1469 ); 1472 1470 } … … 1568 1566 'latitude' => array( 1569 1567 'min' => rad2deg( $minimum_lat ), 1570 'max' => rad2deg( $maximum_lat ) 1568 'max' => rad2deg( $maximum_lat ), 1571 1569 ), 1572 1570 'longitude' => array( 1573 1571 'min' => rad2deg( $minimum_lon ), 1574 'max' => rad2deg( $maximum_lon ) 1575 ) 1572 'max' => rad2deg( $maximum_lon ), 1573 ), 1576 1574 ); 1577 1575 } -
sites/trunk/api.wordpress.org/public_html/events/1.0/tests/test-index.php
r10250 r10271 16 16 define( 'SAVEQUERIES', true ); 17 17 18 require_once ( dirname( __DIR__ ) . '/index.php' );19 20 $tests_failed = 0;18 require_once dirname( __DIR__ ) . '/index.php'; 19 20 $tests_failed = 0; 21 21 $tests_failed += test_get_location(); 22 22 $tests_failed += test_get_events(); … … 29 29 $tests_failed += test_remove_duplicate_events(); 30 30 31 $query_count 32 $query_time 31 $query_count = count( $wpdb->queries ); 32 $query_time = array_sum( array_column( $wpdb->queries, 1 ) ); 33 33 34 34 printf( … … 184 184 ), 185 185 186 187 186 /* 188 187 * A location couldn't be found … … 191 190 'input' => array( 192 191 'location_name' => 'Rivendell', 193 'ip' => '127.0.0.1' 192 'ip' => '127.0.0.1', 194 193 ), 195 194 'expected' => false, … … 354 353 'city-with-diacritics-in-query' => array( 355 354 'input' => array( 356 'location_name' => "Doña Ana",355 'location_name' => 'Doña Ana', 357 356 'locale' => 'en_US', 358 357 'timezone' => 'America/Denver', 359 358 ), 360 359 'expected' => array( 361 'description' => "doña ana",360 'description' => 'doña ana', 362 361 'latitude' => '32.390', 363 362 'longitude' => '-106.814', … … 368 367 'city-with-diacritics-in-formal-name-but-not-in-query' => array( 369 368 'input' => array( 370 'location_name' => "Dona Ana",369 'location_name' => 'Dona Ana', 371 370 'locale' => 'en_US', 372 371 'timezone' => 'America/Denver', 373 372 ), 374 373 'expected' => array( 375 'description' => "dona ana",374 'description' => 'dona ana', 376 375 'latitude' => '32.390', 377 376 'longitude' => '-106.814', … … 382 381 'city-with-period-in-query' => array( 383 382 'input' => array( 384 'location_name' => "St. Louis",383 'location_name' => 'St. Louis', 385 384 'locale' => 'en_US', 386 385 'timezone' => 'America/Chicago', 387 386 ), 388 387 'expected' => array( 389 'description' => "st. louis",388 'description' => 'st. louis', 390 389 'latitude' => '38.627', 391 390 'longitude' => '-90.198', … … 396 395 'city-with-period-in-formal-name-but-not-in-query' => array( 397 396 'input' => array( 398 'location_name' => "St Louis",397 'location_name' => 'St Louis', 399 398 'locale' => 'en_US', 400 399 'timezone' => 'America/Chicago', 401 400 ), 402 401 'expected' => array( 403 'description' => "st louis",402 'description' => 'st louis', 404 403 'latitude' => '38.627', 405 404 'longitude' => '-90.198', … … 1496 1495 $duplicate_events = array( 1497 1496 // Each of these represents an event; extraneous fields have been removed for readability. 1498 array 1497 array( 1499 1498 'url' => 'https://2020.us.wordcamp.org/', 1500 1499 ), 1501 1500 1502 array 1501 array( 1503 1502 'url' => 'https://2020.detroit.wordcamp.org/', 1504 1503 ), … … 1507 1506 // Intentionally missing the trailing slash, to account for inconsistencies in data. 1508 1507 'url' => 'https://2020.us.wordcamp.org', 1509 ) 1508 ), 1510 1509 ); 1511 1510 … … 1513 1512 1514 1513 $expected_result = array( 1515 array 1514 array( 1516 1515 'url' => 'https://2020.us.wordcamp.org', 1517 1516 ), 1518 1517 1519 array 1518 array( 1520 1519 'url' => 'https://2020.detroit.wordcamp.org/', 1521 1520 ), 1522 1521 ); 1523 1522 1524 $actual_result 1525 $passed 1523 $actual_result = remove_duplicate_events( $duplicate_events ); 1524 $passed = $expected_result === $actual_result; 1526 1525 1527 1526 output_results( 'remove duplicate events', $passed, $expected_result, $actual_result );
Note: See TracChangeset
for help on using the changeset viewer.