Ticket #3834: weather.patch
File weather.patch, 21.5 KB (added by , 17 years ago) |
---|
-
handler.php
diff -Naur weather/handler.php weather-new/handler.php
old new 14 14 /**/ 15 15 16 16 // Load the weather classes 17 require_once 'includes/objects/WeatherS ite.php';17 require_once 'includes/objects/WeatherScreen.php'; 18 18 require_once 'includes/objects/Forecast.php'; 19 19 20 // Default unit preference is not metric21 if (empty($_SESSION['weather']['siunits'])) {22 $_SESSION['weather']['siunits'] = 'NO';23 }24 25 /**26 * @global array $GLOBALS['Weather_Types']27 * @name $Weather_Types28 /**/29 global $Weather_Types;30 $Weather_Types = array();31 32 // Load the weather data33 foreach (file(modules_path.'/'.module.'/weathertypes.dat') as $line) {34 list($id, $name, $img) = explode(',', $line);35 $Weather_Types[$id] = array($img, $name);36 }37 38 20 /** 39 21 * @global array $GLOBALS['WeatherSites'] 40 22 * @name $WeatherSites 41 23 /**/ 42 global $WeatherSites; 43 $WeatherSites = array(); 44 45 // Build a list of the known weather sites, starting with the session prefs 46 if ($_SESSION['weather']['locale']) 47 $WeatherSites[$_SESSION['weather']['locale']] = new WeatherSite($_SESSION['weather']['locale'], 48 t('MythWeb Session'), 49 $_SESSION['weather']['siunits']); 50 // Pull from the database next 51 $sh = $db->query('SELECT data, hostname FROM settings WHERE value="locale"'); 52 while (list($locale, $host) = $sh->fetch_row()) { 53 // New data site 54 if (empty($WeatherSites[$locale])) { 55 $siunits = $db->query_col('SELECT data 56 FROM settings 57 WHERE value="SIUnits" AND hostname=?', 58 $host); 59 $WeatherSites[$locale] = new WeatherSite($locale, $host, $siunits); 60 } 61 // Add the hostname to sites we've already seen 62 else { 63 $WeatherSites[$locale]->hosts[] = $host; 64 } 24 global $WeatherScreens; 25 $WeatherScreens = array(); 65 26 27 // Get configured WeatherScreens from the database 28 $sh = $db->query('SELECT screen_id, draworder, container, hostname, units FROM weatherscreens'); 29 while(list($screen_id, $draworder, $container, $hostname, $units) = $sh->fetch_row()) { 30 $WeatherScreens[$draworder] = new WeatherScreen($screen_id, $container, $hostname, $units); 66 31 } 67 32 $sh->finish(); 68 33 -
includes/objects/WeatherScreen.php
diff -Naur weather/includes/objects/WeatherScreen.php weather-new/includes/objects/WeatherScreen.php
old new 1 <?php 2 /** 3 * WeatherScreen class for MythWeb's Weather module 4 * 5 * @author $Author: jripley $ 6 * @license GPL 7 * 8 * @package MythWeb 9 * subpackage Weather 10 * 11 /**/ 12 13 class WeatherScreen { 14 15 var $screen_id; 16 var $container; 17 var $host; 18 var $units; 19 20 var $data = array(); 21 22 function WeatherScreen($screen_id, $container, $hostname, $units) { 23 $this->screen_id = $screen_id; 24 $this->container = $container; 25 $this->host = $hostname; 26 $this->units = $units; 27 28 $this->getData(); 29 } 30 31 function getData() { 32 global $db; 33 $cwd = getcwd(); 34 35 // Find script file for this screen_id 36 $sh = $db->query('SELECT DISTINCT weathersourcesettings.path 37 FROM weathersourcesettings, weatherdatalayout 38 WHERE weatherdatalayout.weatherscreens_screen_id=? 39 AND weathersourcesettings_sourceid=weathersourcesettings.sourceid', $this->screen_id); 40 41 // Separate path and filename of script 42 list($script) = $sh->fetch_row(); 43 $scratch = explode("/", $script); 44 $script = array_pop($scratch); 45 $path = implode("/", $scratch); 46 47 // Find location 48 $sh = $db->query('SELECT DISTINCT location from weatherdatalayout 49 WHERE weatherscreens_screen_id='. $this->screen_id); 50 list($location) = $sh->fetch_row(); 51 52 // Execute script and gather data 53 if(chdir($path)) { 54 $unit = $this->units == 0 ? "SI" : "ENG"; 55 $command = "$script -u $unit -d $cwd/". cache_dir ." $location"; 56 $output = `./$command`; 57 } else 58 custom_error("Could not change active directory to $path.\n"); 59 60 // Change directory 61 if (! chdir($cwd)) 62 custom_error("Could not change active directory to $cwd.\n"); 63 64 // Split script output into an array 65 $scratch = preg_split("/\n/", $output); 66 foreach ($scratch as $line) { 67 list($key, $var) = preg_split("/::/", $line); 68 $output_array[$key] = trim($var); 69 } 70 71 // Query db data items 72 $sh = $db->query('SELECT weatherdatalayout.dataitem 73 FROM weatherdatalayout,weathersourcesettings 74 WHERE weatherscreens_screen_id='. $this->screen_id .' 75 AND weathersourcesettings_sourceid=weathersourcesettings.sourceid'); 76 77 while(list($dataitem) = $sh->fetch_row()) { 78 $this->data[$dataitem] = $output_array[$dataitem]; 79 } 80 } 81 } 82 83 -
init.php
diff -Naur weather/init.php weather-new/init.php
old new 21 21 ); 22 22 23 23 // First, we should check to see that MythWeather is configured. 24 $has_weather = $_SESSION['locale'] 25 ? true 26 : $db->query_col('SELECT COUNT(data) 27 FROM settings 28 WHERE value="locale"'); 24 $has_weather = $db->query_col('SELECT COUNT(screen_id) 25 FROM weatherscreens'); 29 26 30 27 31 28 -
tmpl/default/weather.18h.php
diff -Naur weather/tmpl/default/weather.18h.php weather-new/tmpl/default/weather.18h.php
old new 1 <?php 2 /** 3 * Display template for 18 Hour Forecast for the Weather module 4 * 5 * @author $Author: vitaminjoe@gmail.com$ 6 * @license GPL 7 * 8 * @package MythWeb 9 * 10 /**/ 11 ?> 12 <p class="host"><?php 13 echo t('Host') .": ". $screen->host; 14 ?></p> 15 <p class="location"><?php 16 echo $screen->data["18hrlocation"] 17 ?></p> 18 19 <div class="forecast clearfix"> 20 <h2><?php echo $screen->container ?></h2> 21 22 <?php 23 for($i=0;$i<6;$i++) { 24 ?> 25 26 <div class="daily_forecast"> 27 <h3><?php echo $screen->data["time-$i"] ?></h3> 28 <img src="<?php echo skin_url ?>img/weather/<?php echo $screen->data["18icon-$i"] ?>" class="alpha_png" /> 29 30 <div class="temps"> 31 <div class="high"> 32 <p class="temp"> 33 <?php echo $screen->data["temp-$i"] == 'NA' ? '' : $screen->data["temp-$i"] ?>°<sup><?php echo $screen->units == 0 ? 'C' : 'F' ?></sup> 34 </p> 35 </div> 36 </div> 37 </div> 38 <?php } ?> 39 </div> 40 -
tmpl/default/weather.3d.php
diff -Naur weather/tmpl/default/weather.3d.php weather-new/tmpl/default/weather.3d.php
old new 1 <?php 2 /** 3 * Display template for Six 6 Forecast for the Weather module 4 * 5 * @author $Author: vitaminjoe@gmail.com$ 6 * @license GPL 7 * 8 * @package MythWeb 9 * 10 /**/ 11 ?> 12 <p class="host"><?php 13 echo t('Host') .": ". $screen->host; 14 ?></p> 15 <p class="location"><?php 16 echo $screen->data["3dlocation"] 17 ?></p> 18 19 <div class="forecast clearfix"> 20 <h2><?php echo $screen->container ?></h2> 21 22 <?php 23 for($i=0;$i<3;$i++) { 24 ?> 25 26 <div class="daily_forecast"> 27 <h3><?php echo $screen->data["date-$i"] ?></h3> 28 <img src="<?php echo skin_url ?>img/weather/<?php echo $screen->data["icon-$i"] ?>" class="alpha_png" /> 29 30 <div class="temps"> 31 <div class="low"> 32 <p><?php echo t('Low') ?></p> 33 <p class="temp"> 34 <?php echo $screen->data["low-$i"] == 'NA' ? '' : $screen->data["low-$i"] ?>°<sup><?php echo $screen->units == 0 ? 'C' : 'F' ?></sup> 35 </p> 36 </div> 37 38 <div class="high"> 39 <p><?php echo t('High') ?></p> 40 <p class="temp"> 41 <?php echo $screen->data["high-$i"] == 'NA' ? '' : $screen->data["high-$i"] ?>°<sup><?php echo $screen->units == 0 ? 'C' : 'F' ?></sup> 42 </p> 43 </div> 44 </div> 45 </div> 46 <?php } ?> 47 </div> 48 -
tmpl/default/weather.6d.php
diff -Naur weather/tmpl/default/weather.6d.php weather-new/tmpl/default/weather.6d.php
old new 1 <?php 2 /** 3 * Display template for Six 6 Forecast for the Weather module 4 * 5 * @author $Author: vitaminjoe@gmail.com$ 6 * @license GPL 7 * 8 * @package MythWeb 9 * 10 /**/ 11 ?> 12 <p class="host"><?php 13 echo t('Host') .": ". $screen->host; 14 ?></p> 15 <p class="location"><?php 16 echo $screen->data["6dlocation"] 17 ?></p> 18 19 <div class="forecast clearfix"> 20 <h2><?php echo $screen->container ?></h2> 21 22 <?php 23 for($i=0;$i<6;$i++) { 24 ?> 25 26 <div class="daily_forecast"> 27 <h3><?php echo $screen->data["date-$i"] ?></h3> 28 <img src="<?php echo skin_url ?>img/weather/<?php echo $screen->data["icon-$i"] ?>" class="alpha_png" /> 29 30 <div class="temps"> 31 <div class="low"> 32 <p><?php echo t('Low') ?></p> 33 <p class="temp"> 34 <?php echo $screen->data["low-$i"] == 'NA' ? '' : $screen->data["low-$i"] ?>°<sup><?php echo $screen->units == 0 ? 'C' : 'F' ?></sup> 35 </p> 36 </div> 37 38 <div class="high"> 39 <p><?php echo t('High') ?></p> 40 <p class="temp"> 41 <?php echo $screen->data["high-$i"] == 'NA' ? '' : $screen->data["high-$i"] ?>°<sup><?php echo $screen->units == 0 ? 'C' : 'F' ?></sup> 42 </p> 43 </div> 44 </div> 45 </div> 46 <?php } ?> 47 </div> 48 -
tmpl/default/weather.am.php
diff -Naur weather/tmpl/default/weather.am.php weather-new/tmpl/default/weather.am.php
old new 1 <?php 2 /** 3 * Display template for Animated Maps for the Weather module 4 * 5 * @author $Author: vitaminjoe@gmail.com$ 6 * @license GPL 7 * 8 * @package MythWeb 9 * 10 /**/ 11 ?> 12 <div class="radar"> 13 <h2><?php echo $screen->data["amdesc"] ?></h2> 14 15 <div class="radar_image"><center> 16 <script type='text/javascript'> 17 <!-- 18 19 images = new Array(); 20 imageNum = 0; 21 speed = 3; 22 delay = 300; 23 <?php 24 $matches = array(); 25 $image = array_pop(split('/', $screen->data["animatedimage"])); 26 preg_match("/(.*)-\%1-(\d*)-(\d*)x(\d*)/", $image, $matches); 27 28 echo "imageTotal = ". $matches[2] .";\n"; 29 for ($i=0; $i<$matches[2]; $i++) { 30 echo "images[$i] = new Image();\n"; 31 echo "images[$i].src = \"/". cache_dir ."/". $matches[1] ."-$i\";\n"; 32 } 33 ?> 34 function nextFrame (inc) { 35 // display next frame from images array 36 imageNum += inc; 37 if (imageNum >= imageTotal) { 38 imageNum = 0; 39 } 40 41 imageCurrent = imageNum; 42 document.animation.src = images[imageCurrent].src; 43 } 44 45 function animate() { 46 // start animation loop 47 nextFrame(1); 48 } 49 50 function setDelay(i) { 51 speed = i; 52 delay = speed * 100; 53 if (delay == 0) delay = 50; 54 } 55 56 output = '<form name="animap" id="animap" action="get">' 57 output += '<b>Slower</b> ' 58 <?php 59 for ($i=6;$i>=0;$i-=1) { 60 echo "output += '<input type=\"radio\" name=\"speedRadio\" value=\"". $i. "\" onClick=\"setDelay(". $i .")\""; 61 if ($i == 3) { echo " checked"; } 62 echo ">'\n"; 63 } 64 ?> 65 66 output += ' <b>Faster</b><br>' 67 output += '<img name="animation" src="<?php echo "/". cache_dir ."/". $matches[1] ."-0" ?>" alt="Animation" onload="setTimeout(\'animate()\', delay)" />' 68 output += '</form>' 69 document.write(output); 70 71 // --> 72 </script> 73 </center> 74 </div> 75 </div> 76 -
tmpl/default/weather.cc.php
diff -Naur weather/tmpl/default/weather.cc.php weather-new/tmpl/default/weather.cc.php
old new 1 <?php 2 /** 3 * Display template for Current Conditions for the Weather module 4 * 5 * @author $Author: vitaminjoe@gmail.com$ 6 * @license GPL 7 * 8 * @package MythWeb 9 * 10 /**/ 11 ?> 12 <p class="host"><?php 13 echo t('Host') .": ". $screen->host; 14 ?></p> 15 <p class="location"><?php 16 echo $screen->data["cclocation"] 17 ?></p> 18 19 <div class="current_conditions clearfix"> 20 <h2><?php echo t($screen->container) ?></h2> 21 22 <div class="overview"> 23 <img src="<?php echo skin_url ?>img/weather/<?php echo $screen->data["weather_icon"] ?>" class="alpha_png" /> 24 <h3><?php echo $screen->data["weather"] ?></h3> 25 <p class="temp"> 26 <?php echo $screen->data["temp"] ?>°<sup><?php echo $screen->units == 0 ? 'C' : 'F' ?></sup> 27 </p> 28 </div> 29 30 <table border="0" cellspacing="0" cellpadding="0"> 31 <tr> 32 <th><?php echo t('Humidity') ?></th> 33 <td><?php echo $screen->data["relative_humidity"] ?>%</td> 34 </tr><tr> 35 <th><?php echo t('Pressure') ?></th> 36 <td><?php echo $screen->data["pressure"]; echo $screen->units == 0 ? ' mb' : ' in' ?></td> 37 </tr><tr> 38 <th><?php echo t('Wind') ?></th> 39 <td><?php echo $screen->data["wind_dir"] . t(' at ') . $screen->data["wind_spdgst"] ?></td> 40 </tr><tr> 41 <th><?php echo t('Visibility') ?></th> 42 <td><?php echo $screen->data["visibility"]; echo $screen->units == 0 ? ' km' : ' mi' ?></td> 43 </tr><tr> 44 <th><?php echo t('Wind Chill') ?></th> 45 <td><?php echo $screen->data["appt"] . '°<sup>'; echo $screen->units == 0 ? 'C' : 'F' ?></sup></td> 46 </tr><tr> 47 <td colspan="2"><?php echo $screen->data["observation_time"] ?></td> 48 </tr> 49 </table> 50 </div> 51 -
tmpl/default/weather.php
diff -Naur weather/tmpl/default/weather.php weather-new/tmpl/default/weather.php
old new 21 21 // Print the page header 22 22 require 'modules/_shared/tmpl/'.tmpl.'/header.php'; 23 23 24 // Print Information for each of the known weather sites. 25 foreach ($WeatherSites as $accid => $site) { 24 // Print Information for each of the screensa 26 25 ?> 27 26 <div class="weather_site"> 28 <p class="host"><?php29 echo tn('Host', 'Hosts', count($site->hosts)), ': ',30 implode(', ', $site->hosts);31 ?></p>32 <p class="location"><?php33 echo "$site->acid: $site->city, ",34 ($site->subdiv ? "$site->subdiv, " : ''),35 $site->country;36 ?></p>37 38 <div class="current_conditions clearfix">39 <h2><?php echo t('Current Conditions') ?>:</h2>40 41 <div class="overview">42 <img src="<?php echo skin_url ?>img/weather/<?php echo $site->ConditionImage ?>" class="alpha_png" />43 <h3><?php echo $site->ConditionText ?></h3>44 <p class="temp">45 <?php echo $site->Temperature ?>°<sup><?php echo (strcasecmp($site->use_metric, 'YES') == 0) ? 'C' : 'F' ?></sup>46 </p>47 </div>48 49 <table border="0" cellspacing="0" cellpadding="0">50 <tr>51 <th><?php echo t('Humidity') ?></th>52 <td><?php echo $site->Humidity ?>%</td>53 </tr><tr>54 <th><?php echo t('Pressure') ?></th>55 <td><?php echo $site->BarometricPressure; if($site->use_metric == "YES") echo " cm"; else echo " in" ?> </td>56 </tr><tr>57 <th><?php echo t('Wind') ?></th>58 <td><?php echo $site->WindDirection . t(' at ') . $site->WindSpeed; if($site->use_metric == "YES") echo " kph"; else echo " mph" ?></td>59 </tr><tr>60 <th><?php echo t('Visibility') ?></th>61 <td><?php echo $site->Visibility; if($site->use_metric == "YES") echo " km"; else echo " mi" ?></td>62 </tr><tr>63 <th><?php echo t('Wind Chill') ?></th>64 <td class="temp"><?php echo $site->Real.'°<sup>';65 echo (strcasecmp($site->use_metric, 'YES') == 0) ? 'C' : 'F';66 ?></sup></td>67 </tr><tr>68 <th><?php echo t('UV Index') ?></th>69 <td><?php70 echo $site->UV . " (";71 if ($site->UV < 3) echo t('UV Minimal');72 elseif ($site->UV < 6) echo t('UV Moderate');73 elseif ($site->UV < 8) echo t('UV High');74 else echo t('UV Extreme');75 ?>)</td>76 </tr>77 </table>78 </div>79 80 <div class="forecast clearfix">81 <h2><?php echo t('Forecast') ?>:</h2>82 83 27 <?php 84 for ($i=0; $i<6; $i++) { 85 $forecast = $site->Forecast[$i]; 86 if (!$forecast) 87 break; 28 foreach ($WeatherScreens as $screen) { 29 if ($screen->container == "Current Conditions") 30 require tmpl_dir.'weather.cc.php'; 31 if ($screen->container == "18 Hour Forecast") 32 require tmpl_dir.'weather.18h.php'; 33 if ($screen->container == "Three Day Forecast") 34 require tmpl_dir.'weather.3d.php'; 35 if ($screen->container == "Six Day Forecast") 36 require tmpl_dir.'weather.6d.php'; 37 if ($screen->container == "Animated Map") 38 require_once tmpl_dir.'weather.am.php'; 39 } 88 40 ?> 89 <div class="daily_forecast">90 <h3><?php91 92 $today = date("m/d/Y");93 $tomorrow = date("m/d/Y", mktime(0, 0, 0, date("m") , date("d")+1, date("Y")));94 95 switch($forecast->dayofweek) {96 case 0: $day = t('Sunday'); break;97 case 1: $day = t('Monday'); break;98 case 2: $day = t('Tuesday'); break;99 case 3: $day = t('Wednesday'); break;100 case 4: $day = t('Thursday'); break;101 case 5: $day = t('Friday'); break;102 case 6: $day = t('Saturday'); break;103 default: $day = $forecast->date; break;104 }105 106 if ($forecast->date == $today)107 echo t('Today')." ($day)";108 elseif ($forecast->date == $tomorrow)109 echo t('Tomorrow')." ($day)";110 else111 echo $day;112 113 ?></h3>114 115 <img src="<?php echo skin_url ?>img/weather/<?php echo $forecast->DescImage ?>" class="alpha_png" />116 117 <h3><?php echo $forecast->DescText ?></h3>118 119 <div class="temps">120 <div class="low">121 <p><?php echo t('Low') ?></p>122 <p class="temp">123 <?php echo $forecast->LowTemperature ?>°<sup><?php echo (strcasecmp($site->use_metric, 'YES') == 0) ? 'C' : 'F' ?></sup>124 </p>125 </div>126 <div class="high">127 <p><?php echo t('High') ?></p>128 <p class="temp">129 <?php echo $forecast->HighTemperature ?>°<sup><?php echo (strcasecmp($site->use_metric, 'YES') == 0) ? 'C' : 'F' ?></sup>130 </p>131 </div>132 </div>133 </div>134 <?php } ?>135 136 </div>137 138 <div class="radar">139 140 <h2><?php echo t('Radar') ?>:</h2>141 142 <div class="radar_image">143 <img src="<?php echo $site->RadarImage ?>" />144 </div>145 146 </div>147 148 <p class="last_updated">149 <?php echo t('Last Updated') ?>: <?php echo $site->LastUpdated ?>150 </p>151 41 </div> 42 152 43 <?php 153 }154 44 155 45 // Print the page footer 156 46 require 'modules/_shared/tmpl/'.tmpl.'/footer.php';