public function weather_es_citPro::cities in Weather_es 7
Same name and namespace in other branches
- 6.3 weather_es.inc \weather_es_citPro::cities()
Parameters
drupal_http_request $result:
1 call to weather_es_citPro::cities()
File
- ./
weather_es.inc, line 177 - Classes to get the weather information from AEMET
Class
- weather_es_citPro
- Class that gets the cities of a province
Code
public function cities($result) {
switch ($result->code) {
case '301':
case '302':
case '307':
$result = drupal_http_request('http://www.aemet.es' . $result->redirect_url);
case '200':
case '304':
// Get the table
preg_match('/<select.+localidades_selector.+select>/sU', $result->data, $captured);
// Pass it to a string
$data_string = implode(" ", $captured);
$length = strlen($data_string);
$position = strpos($data_string, "select>");
$data_string = substr($data_string, 0, $position - $length);
$clean_string = preg_replace('/[ \\f\\r\\t\\n]+/', ' ', $data_string);
preg_match_all('/<option.+option>/sU', $clean_string, $captured_option);
break;
default:
$this->xerror_message = t('fsockopen fail to open AEMET.');
}
// The first code is [0] => ... so it's no useful
for ($i = 1; $i < sizeof($captured_option[0]); $i++) {
preg_match('/id[0-9]{5}/', $captured_option[0][$i], $cit_cod);
$cit_cod = substr($cit_cod[0], 2, self::$cit_cod_len);
preg_match('/>.+</', $captured_option[0][$i], $cit_nam);
$cit_nam_lon = strlen($cit_nam[0]);
$this->xcities[$cit_cod] = drupal_convert_to_utf8(substr($cit_nam[0], 1, $cit_nam_lon - 2), 'ISO-8859-15');
}
unset($result);
}