-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather.module
56 lines (44 loc) · 2.02 KB
/
weather.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
function weather_menu() {
$items = array();
$items['weather-weather'] = array(
'title' => 'Weather Feed',
'page callback' => 'weather_weather',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
function weather_weather(){
$ch = curl_init("http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=New%20Orleans,LA");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$str = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXMLElement($str);
$str = "";
$str .= "<div class=icon><img src='" . base_path() . drupal_get_path('module', "weather") . "/images/" . $xml->txt_forecast->forecastday[0]->icon . ".png' /></div>";
$str .= "<div class=summary>" . $xml->txt_forecast->forecastday[0]->fcttext . "</div>";
$str .= "<div class=temp>" . $xml->simpleforecast->forecastday[0]->high->fahrenheit . "° / " . $xml->simpleforecast->forecastday[0]->low->fahrenheit . "°</div>";
return $str;
}
function weather_block($op='list', $delta=0, $edit=array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Pullen Weather');
return $blocks;
case 'view':
$ch = curl_init("http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=New%20Orleans,LA");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$str = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXMLElement($str);
$str = "";
$str .= "<div class=\"icon\"><img alt=\"Current Weather Conditions\" src='" . base_path() . drupal_get_path('module', "weather") . "/images/" . $xml->txt_forecast->forecastday[0]->icon . ".png' /></div>";
$str .= "<div class=\"temp\">" . $xml->simpleforecast->forecastday[0]->high->fahrenheit . "° / " . $xml->simpleforecast->forecastday[0]->low->fahrenheit . "°</div>";
$str .= "<div class=\"summary\">" . $xml->txt_forecast->forecastday[0]->fcttext . "</div>";
$blocks['subject'] = t('Current Weather Conditions');
$blocks['content'] = $str;
return $blocks;
}
}
?>