function template_preprocess_weather_es in Weather_es 7
Same name and namespace in other branches
- 6.3 weather_es.module \template_preprocess_weather_es()
- 6.2 weather_es.module \template_preprocess_weather_es()
Preprocess and sanitaze the data
@author jmsirvent
File
- ./
weather_es.module, line 548
Code
function template_preprocess_weather_es(&$vars) {
// We've added weather_es.js in the weather_es.info -> hole site
// drupal_add_js(drupal_get_path('module', 'weather_es') . '/js/weather_es.js');
// Day0 and day1 have information every 6h
// Day2 and day3 every 12h
// Day4, day5 and day6 every 24h
// Wrap the result in an array because the tpl
$vars['obj']['date'] = array(
filter_xss($vars['obj']['date']),
);
if (in_array('sky', $vars['inf_typ'])) {
if ($vars['inf_amo'] == 're') {
if ($vars['day'] < 4) {
$am = $vars['obj']['sky']['00-12'];
$pm = $vars['obj']['sky']['12-24'];
$vars['obj']['sky'] = NULL;
foreach ($am as $text => $img_num) {
/*
* <img src="<?php print $image_path .$img; ?>.png" title="<?php print $txt; ?>" alt="<?php print $txt; ?>"/>
* That isn't correct in all urls...http://drupal7.local --> ok; http://drupal7.local/user/1/weather_es --> nok
*/
$img = theme('image', array(
'path' => drupal_get_path('module', 'weather_es') . '/images/' . $img_num . '.png',
'alt' => $text,
'title' => $text,
));
$am[filter_xss($text)] = $img;
}
foreach ($pm as $text => $img_num) {
$img = theme('image', array(
'path' => drupal_get_path('module', 'weather_es') . '/images/' . $img_num . '.png',
'alt' => $text,
'title' => $text,
));
$pm[filter_xss($text)] = $img;
}
$vars['obj']['sky']['am'] = $am;
$vars['obj']['sky']['pm'] = $pm;
}
else {
$allDay = $vars['obj']['sky']['00-24'];
$vars['obj']['sky'] = NULL;
foreach ($allDay as $text => $img_num) {
$img = theme('image', array(
'path' => drupal_get_path('module', 'weather_es') . '/images/' . $img_num . '.png',
'alt' => $text,
'title' => $text,
));
$allDay[filter_xss($text)] = $img;
}
$vars['obj']['sky']['day'] = $allDay;
}
}
elseif ($vars['inf_amo'] == 'fu') {
// TODO
}
}
else {
unset($vars['obj']['sky']);
}
if (in_array('rain', $vars['inf_typ'])) {
if ($vars['inf_amo'] == 're') {
if ($vars['day'] < 4) {
$am = $vars['obj']['rain']['00-12'];
$pm = $vars['obj']['rain']['12-24'];
$vars['obj']['rain'] = NULL;
$vars['obj']['rain']['am'] = filter_xss($am);
$vars['obj']['rain']['pm'] = filter_xss($pm);
}
else {
$allDay = $vars['obj']['rain']['00-24'];
$vars['obj']['rain'] = NULL;
$vars['obj']['rain']['day'] = filter_xss($allDay);
}
}
elseif ($vars['inf_amo'] == 'fu') {
// TODO
}
}
else {
unset($vars['obj']['rain']);
}
if (in_array('temperature', $vars['inf_typ'])) {
$min = $vars['obj']['temp']['minima'];
$max = $vars['obj']['temp']['maxima'];
$vars['obj']['temp'] = NULL;
$vars['obj']['temp']['min'] = filter_xss($min);
$vars['obj']['temp']['max'] = filter_xss($max);
}
else {
unset($vars['obj']['temp']);
}
if (in_array('chill', $vars['inf_typ'])) {
$min = $vars['obj']['chill']['minima'];
$max = $vars['obj']['chill']['maxima'];
$vars['obj']['chill'] = NULL;
$vars['obj']['chill']['min'] = filter_xss($min);
$vars['obj']['chill']['max'] = filter_xss($max);
}
else {
unset($vars['obj']['chill']);
}
if (in_array('snow', $vars['inf_typ'])) {
if ($vars['inf_amo'] == 're') {
if ($vars['day'] < 4) {
$am = strlen($vars['obj']['snow']['00-12']) != 0 ? $vars['obj']['snow']['00-12'] : 'na';
$pm = strlen($vars['obj']['snow']['12-24']) != 0 ? $vars['obj']['snow']['12-24'] : 'na';
$vars['obj']['snow'] = NULL;
$vars['obj']['snow']['am'] = filter_xss($am);
$vars['obj']['snow']['pm'] = filter_xss($pm);
}
else {
$allDay = strlen($vars['obj']['snow']['00-24']) != 0 ? $vars['obj']['snow']['00-24'] : 'na';
$vars['obj']['snow'] = NULL;
$vars['obj']['snow']['day'] = filter_xss($allDay);
}
}
elseif ($vars['inf_amo'] == 'fu') {
// TODO
}
}
else {
unset($vars['obj']['snow']);
}
if (in_array('wind', $vars['inf_typ'])) {
if ($vars['inf_amo'] == 're') {
if ($vars['day'] < 4) {
$am = $vars['obj']['wind']['00-12'];
$pm = $vars['obj']['wind']['12-24'];
$vars['obj']['wind'] = NULL;
foreach ($am as $dir => $spd) {
$am[filter_xss($dir)] = filter_xss($spd);
}
foreach ($pm as $dir => $spd) {
$pm[filter_xss($dir)] = filter_xss($spd);
}
$vars['obj']['wind']['am'] = $am;
$vars['obj']['wind']['pm'] = $pm;
}
else {
$allDay = $vars['obj']['wind']['00-24'];
$vars['obj']['wind'] = NULL;
foreach ($allDay as $dir => $spd) {
$allDay[filter_xss($dir)] = filter_xss($spd);
}
$vars['obj']['wind']['day'] = $allDay;
}
}
elseif ($vars['inf_amo'] == 'fu') {
// TODO
}
}
else {
unset($vars['obj']['wind']);
}
if (in_array('gust', $vars['inf_typ'])) {
if ($vars['inf_amo'] == 're') {
if ($vars['day'] < 4) {
$am = strlen($vars['obj']['gust']['00-12']) != 0 ? $vars['obj']['gust']['00-12'] : 'na';
$pm = strlen($vars['obj']['gust']['12-24']) != 0 ? $vars['obj']['gust']['12-24'] : 'na';
$vars['obj']['gust'] = NULL;
$vars['obj']['gust']['am'] = filter_xss($am);
$vars['obj']['gust']['pm'] = filter_xss($pm);
}
else {
$allDay = strlen($vars['obj']['gust']['00-24']) != 0 ? $vars['obj']['gust']['00-24'] : 'na';
$vars['obj']['gust'] = NULL;
$vars['obj']['gust']['day'] = filter_xss($allDay);
}
}
elseif ($vars['inf_amo'] == 'fu') {
// TODO
}
}
else {
unset($vars['obj']['gust']);
}
if (in_array('humidity', $vars['inf_typ'])) {
$min = $vars['obj']['hum']['minima'];
$max = $vars['obj']['hum']['maxima'];
$vars['obj']['hum'] = NULL;
$vars['obj']['hum']['min'] = filter_xss($min);
$vars['obj']['hum']['max'] = filter_xss($max);
}
else {
unset($vars['obj']['hum']);
}
if (in_array('uv', $vars['inf_typ'])) {
// Wrap the result in an array because the tpl
$vars['obj']['uv'] = strlen($vars['obj']['uv'] != 0) ? array(
filter_xss($vars['obj']['uv']),
) : array(
'na',
);
}
else {
unset($vars['obj']['uv']);
}
}