- Timestamp:
- 04/07/2017 05:20:45 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/events/1.0/index.php
r5168 r5275 2 2 3 3 namespace Dotorg\API\Events; 4 use stdClass; 4 5 5 6 /** … … 169 170 } 170 171 172 /** 173 * Look for the given location in the Geonames database 174 * 175 * @param string $location_name 176 * @param string $timezone 177 * @param string $country 178 * 179 * @return stdClass|null 180 */ 171 181 function guess_location_from_geonames( $location_name, $timezone, $country ) { 172 182 global $wpdb; … … 175 185 // And we sort by population desc, assuming that the biggest matching location is the most likely one. 176 186 177 // Strip quotes from the search query and enclose it in double quotes, to force an exact literal search 178 $location_name = '"' . strtr( $location_name, [ '"' => '', "'" => '' ] ) . '"'; 179 $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM geoname WHERE MATCH(name,asciiname,alternatenames) AGAINST(%s IN BOOLEAN MODE) ORDER BY FIELD(%s, country) DESC, FIELD(%s, timezone) DESC, population DESC LIMIT 1", $location_name, $country, $timezone ) ); 187 // Strip all quotes from the search query, and then enclose it in double quotes, to force an exact literal search 188 $quoted_location_name = sprintf( 189 '"%s"', 190 strtr( $location_name, [ '"' => '', "'" => '' ] ) 191 ); 192 193 $row = $wpdb->get_row( $wpdb->prepare( " 194 SELECT * 195 FROM geoname 196 WHERE 197 MATCH( name, asciiname, alternatenames ) 198 AGAINST( %s IN BOOLEAN MODE ) 199 ORDER BY 200 FIELD( %s, country ) DESC, 201 FIELD( %s, timezone ) DESC, 202 population DESC 203 LIMIT 1", 204 $quoted_location_name, 205 $country, 206 $timezone 207 ) ); 180 208 181 209 return $row;
Note: See TracChangeset
for help on using the changeset viewer.