if ($arr['tempHigh'] != '') { $foundFirst = 'day'; $arrDay[] = langtransstr('Today'); } else { $foundFirst = 'night'; $arrDay[] = langtransstr('Tonight'); } } else { if ($arr['tempHigh'] != '') { $arrDay[] = $dayText; } else { $arrDay[] = langtransstr(date('l', $arr['timestamp'] - 12 * 60 * 60)) . '<br />' . langtransstr('night'); } } $notUsed = $iconUrl = $iconOut = $iconUrlOut = ''; wsChangeIcon('hwa', $arr['iconL'], $iconOut, $arr['iconUrlL'], $iconUrlOut, $notUsed); $arrIcon[] = $iconUrlOut; $arrDesc[] = langtransstr($arr['weatherDescL']); $arrTemp[] = $arr['tempLowNU'] . $arr['tempHighNU']; $arrRain[] = $arr['rainNUL']; if (isset($arr['rainChance'])) { $arrCoR[] = $arr['rainChance']; } else { $arrCoR[] = '-'; } if (isset($arr['thunderChance']) && $arr['thunderChance'] != 0) { $arrCoT[] = $arr['thunderChance']; $thunder = true; } else { $arrCoT[] = '-'; }
// images are differtent for night and day. CHECK if you made a copy of daytime only images (f.i.there is only one 4.png, make a copy 4n.pg) $unixTime = $arr['timeFrom']; $forecast[$id]['period'] = langtransstr(date('l', $unixTime)) . ' ' . date('j', $unixTime) . ' ' . langtransstr(date('F', $unixTime)) . ' ' . date('Y', $unixTime); $forecast[$id]['time'] = date('H', $unixTime) . '-' . date('H', $arr['timeTo']); $forecastTxt = langtransstr($arr['weatherDesc']); $forecast[$id]['condition'] = str_replace(' ', '<br />', $forecastTxt); if (strlen($arr['icon']) == 1) { $icon = '0' . $arr['icon'] . $imgstr; } else { $icon = $arr['icon'] . $imgstr; } $notUsed = ''; $iconOut = ''; $iconUrlOut = ''; $iconUrl = 'wsIcons/yrno_icons/' . $icon . '.png'; wsChangeIcon('yrno', $icon, $iconOut, $iconUrl, $iconUrlOut, $notUsed); $forecast[$id]['icon'] = '<img alt=" " title="icon ' . $forecastTxt . '" src="' . $iconUrlOut . '" width="26px" />'; $forecast[$id]['tempNU'] = $arr['tempNU']; $forecast[$id]['rainNU'] = $arr['rainNU']; $forecast[$id]['baroNU'] = $arr['baroNU']; $forecast[$id]['windDir'] = langtransstr($arr['windDir']); $forecast[$id]['windNU'] = $arr['windSpeedNU']; $id++; } echo '<div class="textbox center" style="">Yr.no 7 ' . langtransstr('day forecast for') . ' ' . $SITE['organ'] . ':</div> <div class="textbox"> <table class="genericTable"> <tr class="small"> <td> </td><td> </td><td>' . $SITE['uomTemp'] . '</td><td> </td><td>' . $SITE['uomWind'] . '</td><td>' . $SITE['uomRain'] . '</td><td>' . $SITE['uomBaro'] . '</td> </tr>' . PHP_EOL; $period = '';
public function getWeatherData($prov = '', $site = '') { global $SITE, $_REQUEST, $myPageEC, $validWarningTypes, $validWarningPriorities, $pageName; #---------------------------------------------------------------------------------------------- # clean user input #---------------------------------------------------------------------------------------------- $this->apiUrlpart[1] = $prov = trim($prov); $this->apiUrlpart[3] = $site = trim($site); $my_lang = substr(trim($SITE['lang']), 0, 1); if ($my_lang != 'f') { $my_lang = 'e'; } $this->apiUrlpart[5] = $my_lang; #---------------------------------------------------------------------------------------------- # combine everything into required url # http://dd.meteo.gc.ca/citypage_weather/xml/ON/s0000710_e.xml #---------------------------------------------------------------------------------------------- $this->weatherApiUrl = ''; $end = count($this->apiUrlpart); for ($i = 0; $i < $end; $i++) { $this->weatherApiUrl .= $this->apiUrlpart[$i]; } #---------------------------------------------------------------------------------------------- # try loading data from cache #---------------------------------------------------------------------------------------------- if ($this->enableCache && !empty($this->cache)) { $this->cache = $SITE['cacheDir']; $uoms = $SITE['uomTemp'] . '_' . $SITE['uomWind'] . '_' . $SITE['uomBaro'] . '_' . $SITE['uomRain'] . '_' . $SITE['uomSnow'] . '_' . $SITE['uomDistance']; $from = array('°', '/', ' '); $to = ''; $uoms = str_replace($from, $to, $uoms); $fileName = 'ecweatherxml_' . $prov . '_' . $site . '_' . $my_lang . '_' . $uoms; $this->cacheFile = $this->cache . $fileName . '.arr'; if (isset($_REQUEST['force']) && strtolower($_REQUEST['force']) == 'ec') { $returnArray = ''; ws_message('<!-- ' . $this->script_name . ' (' . __LINE__ . '): cache skipped as force was used -->'); } else { ws_message('<!-- ' . $this->script_name . ' (' . __LINE__ . '): try to load ' . $this->cacheFile . ' from cache -->'); $returnArray = $this->loadFromCache(); // load from cache returns data only when its data is valid } if (!empty($returnArray)) { return $returnArray; // if data is in cache and valid return data to calling program } // eo valid data, return to calling program } // eo check cache #---------------------------------------------------------------------------------------------- if ($this->makeRequest() == false) { ws_message('<!-- ' . $this->script_name . ' (' . __LINE__ . '): no good date loaded, back to calling script -->'); return false; } $xml = new SimpleXMLElement($this->rawData); // load xml from url and process # echo '<pre>'.PHP_EOL; # print_r ($xml); # exit; $returnArray = array(); $saveIcon = $SITE['ecIconsOwn']; $SITE['ecIconsOwn'] = false; $utcDiff = date('Z'); // to help to correct utc differences $time = strtotime((string) $xml->forecastGroup->dateTime[1]->timeStamp); $returnArray['information']['province'] = $prov; $returnArray['information']['cityCode'] = $site; $returnArray['information']['language'] = $my_lang; $returnArray['information']['fileTimeStamp'] = $time; $returnArray['information']['fileTime'] = date('c', $time); $returnArray['information']['updated'] = date($SITE['dateLongFormat'], $time) . ' ' . date($SITE['timeOnlyFormat'], $time); $returnArray['information']['location'] = $this->utf8_text((string) $xml->location->region); $returnArray['information']['uomWindSpeed'] = 'km/h'; $returnArray['information']['uomPrecipRain'] = 'mm'; $returnArray['information']['uomPrecipSnow'] = 'cm'; /* <regionalNormals> <textSummary>Low zero. High 10.</textSummary> <temperature unitType="metric" units="C" class="high">10</temperature> <temperature unitType="metric" units="C" class="low">0</temperature> </regionalNormals> */ $returnArray['information']['normalTempText'] = (string) $xml->forecastGroup->regionalNormals->textSummary; $returnArray['information']['normalTempMin'] = (string) $xml->forecastGroup->regionalNormals->temperature[1]; $returnArray['information']['normalTempMax'] = (string) $xml->forecastGroup->regionalNormals->temperature[0]; /*<almanac> <temperature class="extremeMax" period="2011-2014" unitType="metric" units="C" year="2011">22.2</temperature> <temperature class="extremeMin" period="2011-2014" unitType="metric" units="C" year="2014">-2.3</temperature> <temperature class="normalMin" unitType="metric" units="C"/> <temperature class="normalMean" unitType="metric" units="C"/> <precipitation class="extremeRainfall" period="-" unitType="metric" units="mm" year=""/> <precipitation class="extremeSnowfall" period="-" unitType="metric" units="cm" year=""/> <precipitation class="extremePrecipitation" period="2011-2014" unitType="metric" units="mm" year="2013">3.5</precipitation> <precipitation class="extremeSnowOnGround" period="-" unitType="metric" units="cm" year=""/> <pop units="%"/> </almanac>*/ $returnArray['information']['extremeMax'] = (string) $xml->almanac->extremeMax; $returnArray['information']['extremeMin'] = (string) $xml->almanac->extremeMin; #-------------------------------------------------------------------------------------------------- # get alerts info #-------------------------------------------------------------------------------------------------- /* <warnings url="http://weather.gc.ca/warnings/report_e.html?bc42"> <event type="warning" priority="low" description="WIND WARNING IN EFFECT"> . . . <dateTime nam . . . </event> */ $returnArray['warnings']['url'] = (string) $xml->warnings['url']; $maxType = -1; $maxPrio = -1; $n = -1; $searchRain = array('SNOW', 'RAIN'); $searchThunder = array('THUNDER'); # for ($i = 0; $i < count($xml->warnings->event); $i++) { $type = (string) $xml->warnings->event[$i]['type']; if ($type == 'ended') { continue; } else { $n++; } $returnArray['warnings']['event'][$n]['type'] = $type; if (isset($validWarningTypes[$type]) && $maxType < $validWarningTypes[$type]) { $maxType = $validWarningTypes[$type]; } $priority = (string) $xml->warnings->event[$i]['priority']; $returnArray['warnings']['event'][$n]['priority'] = $priority; if (isset($validWarningPriorities[$priority]) && $maxPrio < $validWarningPriorities[$priority]) { $maxPrio = $validWarningPriorities[$priority]; } $stringDesc = $this->utf8_text((string) $xml->warnings->event[$i]['description']); $returnArray['warnings']['event'][$n]['description'] = $stringDesc; $stringDesc = $stringDesc; for ($p = 0; $p < count($searchRain); $p++) { $needle = $searchRain[$p]; $pos = strpos(' ' . $stringDesc, $needle); if ($pos > 1) { $returnArray['warnings']['warnrain'] = true; $returnArray['warnings']['raintype'] = $needle; } } for ($p = 0; $p < count($searchThunder); $p++) { $pos = strpos(' ' . $stringDesc, $searchThunder[$p]); if ($pos > 1) { $returnArray['warnings']['warnthunder'] = true; break; } } } $returnArray['warnings']['maxType'] = $maxType; $returnArray['warnings']['maxPrio'] = $maxPrio; #-------------------------------------------------------------------------------------------------- # get forecast info #-------------------------------------------------------------------------------------------------- $endLayouts = count($xml->forecastGroup->forecast); if ($endLayouts == 0) { echo '<h3> ' . $myPageEC . ' - invalid xml file - program halted </h3>'; exit; } # echo "forecast retrieved: $endLayouts".PHP_EOL;; for ($nLayouts = 0; $nLayouts < $endLayouts; $nLayouts++) { $forecast = $xml->forecastGroup->forecast[$nLayouts]; # echo "forecast $nLayouts".PHP_EOL; # print_r ($forecast); /* <period textForecastName="Today">Friday</period>*/ $returnArray['forecast'][$nLayouts]['period'] = $this->utf8_text((string) $forecast->period); $returnArray['forecast'][$nLayouts]['daypart'] = $this->utf8_text((string) $forecast->period['textForecastName']); /* <textSummary>Rain ending this morning then cloudy with 60 percent chance of showers. High 13.</textSummary>*/ $returnArray['forecast'][$nLayouts]['forecastText'] = $this->utf8_text((string) $forecast->textSummary); /* <cloudPrecip> <textSummary>Rain ending this morning then cloudy with 60 percent chance of showers.</textSummary> </cloudPrecip>*/ $returnArray['forecast'][$nLayouts]['cloudText'] = $this->utf8_text((string) $forecast->cloudPrecip->textSummary); /*<abbreviatedForecast> <iconCode format="gif">12</iconCode> <pop units="%">60</pop> <textSummary>Chance of showers</textSummary> </abbreviatedForecast>*/ $returnArray['forecast'][$nLayouts]['iconText'] = $this->utf8_text((string) $forecast->abbreviatedForecast->textSummary); $icon = (string) $forecast->abbreviatedForecast->iconCode; $returnArray['forecast'][$nLayouts]['iconNumber'] = $icon; $iconOut = $none = $icon; $save = $ret = wsChangeIcon('ec', $icon, $iconOut, $none, $none); $returnArray['forecast'][$nLayouts]['defaultIcon'] = $iconOut; $returnArray['forecast'][$nLayouts]['PoP'] = (string) $forecast->abbreviatedForecast->pop; /*<temperatures> <textSummary>Low 12. High 17.</textSummary> <temperature unitType="metric" units="C" class="high">17</temperature> <temperature unitType="metric" units="C" class="low">12</temperature> </temperatures>*/ $returnArray['forecast'][$nLayouts]['tempText'] = $this->utf8_text((string) $forecast->temperatures->textSummary); for ($n = 0; $n < count($forecast->temperatures->temperature); $n++) { $key = (string) $forecast->temperatures->temperature[$n]['class']; $returnArray['forecast'][$nLayouts]['temp'][$key] = (string) $forecast->temperatures->temperature[$n] . $SITE['uomTemp']; } /* <winds> <textSummary>Wind southeast 20 km/h becoming south 40 to 60 late in the afternoon then becoming west 40 to 60.</textSummary> <wind index="1" rank="minor"> <speed unitType="metric" units="km/h">10</speed> <gust unitType="metric" units="km/h">00</gust> <direction>SE</direction> <bearing units="degrees">14</bearing> </wind> <wind index="2" rank="major"> <speed unitType="metric" units="km/h">20</speed> <gust unitType="metric" units="km/h">00</gust> <direction>SE</direction> <bearing units="degrees">14</bearing> </wind> . . . </winds>*/ if (!isset($forecast->winds->textSummary)) { $returnArray['forecast'][$nLayouts]['windsText'] = ''; } else { $returnArray['forecast'][$nLayouts]['windsText'] = $this->utf8_text((string) $forecast->winds->textSummary); for ($n = 0; $n < count($forecast->winds->wind); $n++) { $index = $forecast->winds->wind[$n]['index']; $returnArray['forecast'][$nLayouts]['winds'][$n]['rank'] = (string) $forecast->winds->wind[$n]['rank']; $returnArray['forecast'][$nLayouts]['winds'][$n]['speed'] = (string) $forecast->winds->wind[$n]->speed; $returnArray['forecast'][$nLayouts]['winds'][$n]['gust'] = (string) $forecast->winds->wind[$n]->gust; $returnArray['forecast'][$nLayouts]['winds'][$n]['dir'] = (string) $forecast->winds->wind[$n]->direction; $returnArray['forecast'][$nLayouts]['winds'][$n]['deg'] = (string) $forecast->winds->wind[$n]->bearing; } } /* <precipitation> <textSummary>Amount 50 mm near the North Shore.</textSummary> <precipType start="12" end="25">rain</precipType> <accumulation> <name>rain</name> <amount unitType="metric" units="mm">5</amount> </accumulation> </precipitation> */ if (!isset($forecast->precipitation)) { $returnArray['forecast'][$nLayouts]['precipText'] = ''; } else { $returnArray['forecast'][$nLayouts]['precipText'] = $this->utf8_text((string) $forecast->precipitation->textSummary); for ($n = 0; $n < count($forecast->precipitation->precipType); $n++) { // 0? - ?? $returnArray['forecast'][$nLayouts]['precipType'][$n] = (string) $forecast->precipitation->precipType[$n]; } for ($n = 0; $n < count($forecast->precipitation->accumulation); $n++) { // 0 - 4 $returnArray['forecast'][$nLayouts]['precipName'][$n] = (string) $forecast->precipitation->accumulation[$n]->name; $returnArray['forecast'][$nLayouts]['precipAmount'][$n] = (string) $forecast->precipitation->accumulation[$n]->amount; } } /* <visibility> <otherVisib cause="other"> <textSummary>Fog patches dissipating this morning.</textSummary> </otherVisib> </visibility> */ if (!isset($forecast->visibility->otherVisib)) { $returnArray['forecast'][$nLayouts]['visibOtherText'] = ''; } else { $returnArray['forecast'][$nLayouts]['visibOtherText'] = $this->utf8_text((string) $forecast->visibility->otherVisib->textSummary); $returnArray['forecast'][$nLayouts]['visibOtherCause'] = (string) $forecast->visibility->otherVisib['cause']; } if (!isset($forecast->visibility->windVisib)) { $returnArray['forecast'][$nLayouts]['visibWindText'] = ''; } else { $returnArray['forecast'][$nLayouts]['visibWindText'] = $this->utf8_text((string) $forecast->visibility->windVisib->textSummary); $returnArray['forecast'][$nLayouts]['visibWindCause'] = (string) $forecast->visibility->windVisib['cause']; } /* <uv category="moderate"> <index>5</index> <textSummary>UV index 5 or moderate.</textSummary> </uv> */ if (!isset($forecast->UV)) { $returnArray['forecast'][$nLayouts]['UvText'] = ''; } else { $returnArray['forecast'][$nLayouts]['UVindex'] = (string) $forecast->uv->index; $returnArray['forecast'][$nLayouts]['UvCategory'] = (string) $forecast->uv['category']; $returnArray['forecast'][$nLayouts]['UvText'] = $this->utf8_text((string) $forecast->uv->textSummary); } /* <relativeHumidity units="%">65</relativeHumidity> */ $returnArray['forecast'][$nLayouts]['humidity'] = (string) $forecast->relativeHumidity; /* <snowlevel><textSummary>????</textSummary></snowlevel> */ if (!isset($forecast->snowlevel)) { $returnArray['forecast'][$nLayouts]['snowlevelText'] = ''; } else { $returnArray['forecast'][$nLayouts]['snowlevelText'] = $this->utf8_text((string) $forecast->snowlevel->textSummary); } /* <frost><textSummary>????</textSummary></frost> */ if (!isset($forecast->snowlevel)) { $returnArray['forecast'][$nLayouts]['frostText'] = ''; } else { $returnArray['forecast'][$nLayouts]['frostText'] = $this->utf8_text((string) $forecast->frost->textSummary); } /* <comfort><textSummary>cool.</textSummary></comfort> */ if (!isset($forecast->comfort)) { $returnArray['forecast'][$nLayouts]['comfortText'] = ''; } else { $returnArray['forecast'][$nLayouts]['comfortText'] = $this->utf8_text((string) $forecast->comfort->textSummary); } # print_r ($returnArray['forecast'][$nLayouts]); } // eof layouts # exit; $SITE['ecIconsOwn'] = $saveIcon; $ret = $this->writeToCache($returnArray); return $returnArray; }
function myIconTxt($array = '') { if (!is_array($array)) { return '<td>' . langtransstr('Icon') . '</td>'; } $iconOut = $iconUrlIn = $iconUrlOut = $headerClass = ''; $icon = wsChangeIcon('noaa', $array['icon'], $iconOut, $iconUrlIn, $iconUrlOut, $headerClass); $icon = wsChangeIcon('wxsim', $iconOut, $iconOut, $iconUrlIn, $iconUrlOut, $headerClass); $tekst = '<td><img class="imgCCN" src="' . $iconUrlOut . '" alt=""/></td>'; $tip = '<td colspan="2">' . $tekst . '</td>'; return array($tekst, $tip); }
foreach ($my_yahoos as $key => $arr) { $hahooID = $arr['hahooID']; $result = $weather->getWeatherData($hahooID); #echo '<pre>'; var_dump($result['ccn'][1]); exit; if (!$result) { unset($my_yahoos[$key]); continue; } # {echo '<br />false for : '.$key; continue;} else {echo '<br />true for : '.$key;} $count_yahoo++; $my_yahoos[$key]['found'] = true; $my_yahoos[$key]['temp'] = round($result['ccn'][1]['tempNU'], 0); $notUsed = ''; $iconOut = ''; $iconUrlOut = ''; wsChangeIcon('yahoo', $result['ccn'][1]['icon'], $iconOut, $result['ccn'][1]['iconUrl'], $iconUrlOut, $notUsed); $my_yahoos[$key]['iconurl'] = $iconUrlOut; $my_yahoos[$key]['desc'] = langtransstr($result['ccn'][1]['text']); if ($count_yahoo >= $max_cities) { break; } #echo '<pre>'; var_dump($my_yahoos[$key ]); exit; } $seconds_yahoo = microtime(true) - $start_yahoo; ws_message('<!-- <!-- dash_yahoo.php (' . __LINE__ . '): loading ' . $count_yahoo . ' ccn using yahoo in ' . $seconds_yahoo . ' seconds -->'); if ($count_yahoo == 0) { return; } #echo '<pre>'; var_dump($my_yahoos); exit; echo '<div class="blockDiv"> <h3 class="blockHead">', langtransstr('The weather in interesting cities nearby') . '</h3>' . PHP_EOL;
#--------------------------------------------------------------------------- # load icon translate if necessary include_once 'wsIconUrl.php'; #--------------------------------------------------------------------------- #process each forecast $id = '1'; foreach ($returnArray['forecast'] as $arr) { if ($arr['windDir'] != 'windDir') { // skip first row with headers $forecast[$id]['period'] = langtransstr(date('l', $arr['date'])) . ' ' . date('j ', $arr['date']) . langtransstr(date('M', $arr['date'])); $forecastTxt = langtransstr($arr['weatherDesc']); $forecast[$id]['condition'] = str_replace(' ', '<br />', $forecastTxt); $notUsed = ''; $iconOut = ''; $iconUrlOut = ''; wsChangeIcon('world', $arr['weatherCode'], $iconOut, $arr['iconUrl'], $iconUrlOut, $notUsed); $forecast[$id]['iconUrl'] = '<img alt="icon ' . $arr['weatherDesc'] . '" src="' . $iconUrlOut . '" style="height: 45px; margin: 0px; padding: 0px;"/>'; if ($arr['tempLow'] < 0) { $forecast[$id]['tempLow'] = '<span style="color: red;">' . $arr['tempLow'] . '</span>'; } else { $forecast[$id]['tempLow'] = $arr['tempLow']; } if ($arr['tempHigh'] < 0) { $forecast[$id]['tempHigh'] = '<span style="color: red;">' . $arr['tempHigh'] . '</span>'; } else { $forecast[$id]['tempHigh'] = $arr['tempHigh']; } $forecast[$id]['rain'] = $arr['rain']; $forecast[$id]['wind'] = $arr['wind'] . '<br />' . langtransstr('from the ') . ' ' . langtransstr($arr['windDir']); $id++; }
$style = 'style="height: 43px;"'; } else { $style = 'style="height: 20px;"'; } $id = '1'; foreach ($yahooArray['forecast'] as $arr) { if ($arr['timestamp'] == 'timestamp') { continue; } $unixTime = $arr['timestamp']; $forecast[$id]['period'] = langtransstr(date('l', $unixTime)) . ' ' . date('j', $unixTime) . ' ' . langtransstr(date('F', $unixTime)); $forecast[$id]['condition'] = yahooSplit($arr['condition']); $notUsed = ''; $iconOut = ''; $iconUrlOut = ''; wsChangeIcon('yahoo', $arr['icon'], $iconOut, $arr['iconUrl'], $iconUrlOut, $notUsed); $forecast[$id]['iconUrl'] = '<img alt="icon ' . $arr['condition'] . '" src="' . $iconUrlOut . '" ' . $style . '/>'; $forecast[$id]['tempLow'] = $arr['tempLow']; $forecast[$id]['tempHigh'] = $arr['tempHigh']; $id++; } #------------------------------------------------------------------------------- # now we are going to print the data to the screen #------------------------------------------------------------------------------- if ($SITE['fctOrg'] != 'yahoo') { echo '<div class="blockDiv">' . PHP_EOL; } $rowcolor = 0; if (isset($_REQUEST['city'])) { $area_yahoo = $yahooArray['request_info'][0]['city']; } else {
} if (isset($mtr['covers_max']) && $mtr['covers_max'] != '') { $text = $mtr['covers_max']; if (trim($text) == 'Clear' && $dayNight != 'nighttime') { $text = 'Sunny'; } $text = langtransstr($mtr['covers_max']); $long_text .= $extra . $text; } $condDesc = $long_text; $icon = $mtr['max-icon']; if ($dayNight == 'nighttime') { $icon .= 'n'; } $iconNrPr = $icon; wsChangeIcon('default', $icon, $icon, '', $ccnIconUrl); $ccnIconNr = $iconNrPr; $headerClass = wsHeaderLookup('default', $iconNrPr); # added for calgary $ws['myMetarVisib'] = $ws['visibility_prefix'] = $ws['visibility_sm'] = ''; if (isset($mtr['visibility_prefix'])) { $ws['myMetarVisib'] = langtransstr($mtr['visibility_prefix']) . ' '; $ws['visibility_prefix'] = $mtr['visibility_prefix']; } if (isset($mtr['visibility_sm'])) { $ws['myMetarVisib'] .= $mtr['visibility_sm']; $ws['visibility_sm'] = $mtr['visibility_sm']; } # end added for calgary break; }