function weather_block in Weather 6.5
Same name and namespace in other branches
- 5.6 weather.module \weather_block()
- 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 222 - 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: custom user');
$block[1]['info'] = t('Weather: location of nodes (requires Location or Node Map module)');
$current_blocks = _weather_get_blocks_in_use();
if (!empty($current_blocks)) {
foreach ($current_blocks as $block_id) {
// $block_id is at least 1, so make sure the delta is at least 2
$block[SYSTEM_BLOCK_DELTA_START + $block_id - 1]['info'] = t('Weather: system-wide !number', array(
'!number' => $block_id,
));
}
}
return $block;
}
else {
if ($op == 'view') {
if ($delta == 0 and weather_custom_block_access()) {
// 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_theming', $config, $metar);
}
return $block;
}
else {
if ($delta == 1 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));
$block['content'] = '';
// This checks the location module
if (isset($node->locations)) {
// Iterate through all available locations and check
// for lat/long information. If there is no information,
// the location module return 0.0/0.0 instead of NULL values
foreach ($node->locations as $location) {
if ($location['latitude'] != 0 or $location['longitude'] != 0) {
$nearest_station = weather_get_icao_from_lat_lon($location['latitude'], $location['longitude']);
$config = _weather_get_config(0, 1);
$config = array_merge($config, $nearest_station);
$config['real_name'] = $config['name'];
$metar = weather_get_metar($config['icao']);
$block['content'] .= theme('weather_theming', $config, $metar);
}
}
}
// Handle CCK location fields
// First, determine all names of location fields
$sql = "SELECT field_name FROM {content_node_field} WHERE type='location'";
$result = db_query($sql);
// Cycle through all found field names.
while ($field_name = db_result($result)) {
// Iterate through all available locations and check
// for lat/long information. If there is no information,
// the location module return 0.0/0.0 instead of NULL values
foreach ($node->{$field_name} as $location) {
if ($location['latitude'] != 0 or $location['longitude'] != 0) {
$nearest_station = weather_get_icao_from_lat_lon($location['latitude'], $location['longitude']);
$config = _weather_get_config(0, 1);
$config = array_merge($config, $nearest_station);
$config['real_name'] = $config['name'];
$metar = weather_get_metar($config['icao']);
$block['content'] .= theme('weather_theming', $config, $metar);
}
}
}
// Handle nodemap module
if (isset($node->nodemap_latitude_field) and isset($node->nodemap_longitude_field) and ($node->nodemap_latitude_field != 0 or $node->nodemap_longitude_field != 0)) {
$nearest_station = weather_get_icao_from_lat_lon($node->nodemap_latitude_field, $node->nodemap_longitude_field);
$config = _weather_get_config(0, 1);
$config = array_merge($config, $nearest_station);
$config['real_name'] = $config['name'];
$metar = weather_get_metar($config['icao']);
$block['content'] .= theme('weather_theming', $config, $metar);
}
// Do not show block if no lat/long information has been found
if ($block['content'] != '') {
$block['subject'] = t('Current weather nearby');
return $block;
}
}
}
else {
if ($delta >= SYSTEM_BLOCK_DELTA_START and user_access('access content')) {
// show a system-wide weather block
$system_block_id = SYSTEM_BLOCK_DELTA_START - $delta - 1;
$block['subject'] = t('Current weather');
$block['content'] = '';
$configs_in_use = _weather_get_configs_in_use($system_block_id);
if (count($configs_in_use) == 0) {
$configs_in_use[] = array(
'cid' => 1,
);
}
foreach ($configs_in_use as $index) {
$config = _weather_get_config($system_block_id, $index['cid']);
$metar = weather_get_metar($config['icao']);
$block['content'] .= theme('weather_theming', $config, $metar);
}
return $block;
}
}
}
}
}
}