function weather_block in Weather 5.6
Same name and namespace in other branches
- 5 weather.module \weather_block()
- 6.5 weather.module \weather_block()
Generate HTML for the weather block
@returns block HTML
Parameters
op operation from the URL:
delta offset:
File
- ./
weather.module, line 230 - Display <acronym title="METeorological Aerodrome Report">METAR</acronym> weather data from anywhere in the world
Code
function weather_block($op = 'list', $delta = 0) {
global $user;
if ($op == 'list') {
$block[0]['info'] = t('Weather: system-wide');
$block[1]['info'] = t('Weather: custom user');
$block[2]['info'] = t('Weather: location of nodes (requires Location module)');
return $block;
}
else {
if ($op == 'view') {
if ($delta == 0 and user_access('access content')) {
// show the system weather block
$block['subject'] = t('Current weather');
$block['content'] = '';
$configs_in_use = _weather_get_configs_in_use(WEATHER_SYSTEM_BLOCK);
if (count($configs_in_use) == 0) {
$configs_in_use = array(
'cid' => 1,
);
}
foreach ($configs_in_use as $index) {
$config = _weather_get_config(WEATHER_SYSTEM_BLOCK, $index['cid']);
$metar = weather_get_metar($config['icao']);
$block['content'] .= theme('weather', $config, $metar);
}
return $block;
}
else {
if ($delta == 1 and user_access('administer custom weather block')) {
// Show the user's custom weather block, if there is already
// a location configured. Otherwise, do not show the block.
$configs_in_use = _weather_get_configs_in_use($user->uid);
if (count($configs_in_use) == 0) {
return;
}
$block['subject'] = t('Current weather');
$block['content'] = '';
foreach ($configs_in_use as $index) {
$config = _weather_get_config($user->uid, $index['cid']);
$metar = weather_get_metar($config['icao']);
$block['content'] .= theme('weather', $config, $metar);
}
return $block;
}
else {
if ($delta == 2 and user_access('access content')) {
// show the node location weather block
if (arg(0) == 'node' and is_numeric(arg(1))) {
$node = node_load(arg(1));
if (isset($node->location['latitude']) and isset($node->location['longitude'])) {
$block['subject'] = t('Current weather nearby');
$block['content'] = '';
foreach ($node->locations as $location) {
$nearest_station = weather_get_icao_from_lat_lon($location['latitude'], $location['longitude']);
$config = _weather_get_config(WEATHER_DEFAULT_BLOCK, 1);
$config = array_merge($config, $nearest_station);
$config['real_name'] = $config['name'];
$metar = weather_get_metar($config['icao']);
$block['content'] .= theme('weather', $config, $metar);
}
return $block;
}
}
}
}
}
}
}
}