Changeset 6818
- Timestamp:
- 03/01/2018 09:13:34 PM (8 years ago)
- Location:
- sites/trunk/api.wordpress.org/public_html/events/1.0
- Files:
-
- 2 edited
-
index.php (modified) (4 diffs)
-
tests/test-index.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/events/1.0/index.php
r6816 r6818 282 282 283 283 // Exact match 284 $ row = $wpdb->get_row( $wpdb->prepare("284 $query = " 285 285 SELECT name, latitude, longitude, country 286 286 FROM geoname_summary … … 290 290 FIELD( %s, timezone ) DESC, 291 291 population DESC 292 LIMIT 1", 293 $location_name, 294 $country, 295 $timezone 296 ) ); 292 LIMIT 1"; 293 294 $prepared_query = $wpdb->prepare( $query, $location_name, $country, $timezone ); 295 $db_handle = $wpdb->db_connect( $prepared_query ); 296 297 $wpdb->set_charset( $db_handle, 'utf8' ); // The content in this table requires a UTF8 connection. 298 $row = $wpdb->get_row( $prepared_query ); 299 $wpdb->set_charset( $db_handle, 'latin1' ); // Revert to the default charset to avoid affecting other queries. 297 300 298 301 // Wildcard match 299 302 if ( ! $row && $wildcard && 'ASCII' !== mb_detect_encoding( $location_name ) ) { 300 $ row = $wpdb->get_row( $wpdb->prepare("303 $query = " 301 304 SELECT name, latitude, longitude, country 302 305 FROM geoname_summary … … 306 309 FIELD( %s, timezone ) DESC, 307 310 population DESC 308 LIMIT 1", 309 $wpdb->esc_like( $location_name ) . '%', 310 $country, 311 $timezone 312 ) ); 311 LIMIT 1"; 312 313 $prepared_query = $wpdb->prepare( $query, $wpdb->esc_like( $location_name ) . '%', $country, $timezone ); 314 $db_handle = $wpdb->db_connect( $prepared_query ); 315 316 $wpdb->set_charset( $db_handle, 'utf8' ); // The content in this table requires a UTF8 connection. 317 $row = $wpdb->get_row( $prepared_query ); 318 $wpdb->set_charset( $db_handle, 'latin1' ); // Revert to the default charset to avoid affecting other queries. 313 319 } 314 320 … … 319 325 // $row->name .= ', ' . $row->state; 320 326 // } 327 328 // Strip off null bytes 329 // @todo Modify geoname script to to this instead? 330 if ( ! empty( $row->name ) ) { 331 $row->name = trim( $row->name ); 332 } 321 333 322 334 return $row; -
sites/trunk/api.wordpress.org/public_html/events/1.0/tests/test-index.php
r6817 r6818 190 190 ), 191 191 'expected' => array( 192 'description' => 'na irobi',192 'description' => 'naíróbí', 193 193 'latitude' => '-1.283', 194 194 'longitude' => '36.817', … … 204 204 ), 205 205 'expected' => array( 206 'description' => 't okyo',206 'description' => 'tōkyō', 207 207 'latitude' => '35.690', 208 208 'longitude' => '139.692', … … 218 218 ), 219 219 'expected' => array( 220 'description' => 'berl in',220 'description' => 'berlín', 221 221 'latitude' => '52.524', 222 222 'longitude' => '13.411', … … 348 348 ), 349 349 'expected' => array( 350 'description' => "do na ana",350 'description' => "doña ana", 351 351 'latitude' => '32.390', 352 352 'longitude' => '-106.814', … … 397 397 ), 398 398 'expected' => array( 399 'description' => 'yaound é',399 'description' => 'yaounde', 400 400 'latitude' => '3.867', 401 401 'longitude' => '11.517', … … 567 567 ), 568 568 'expected' => array( 569 'description' => 'ciudad de m éxico',569 'description' => 'ciudad de mexico', 570 570 'latitude' => '19.428', 571 571 'longitude' => '-99.128', … … 595 595 ), 596 596 'expected' => array( 597 'description' => 'bogot á',597 'description' => 'bogota', 598 598 'latitude' => '4.610', 599 599 'longitude' => '-74.082', … … 628 628 ), 629 629 'expected' => array( 630 'description' => 's ão paulo',630 'description' => 'sao', 631 631 'latitude' => '-23.548', 632 632 'longitude' => '-46.636',
Note: See TracChangeset
for help on using the changeset viewer.