As I understand it the path sandbox/modx/weather/31.png is the orignal path in the weather.txt file. I did try to change path manually and then ftp to my server but the path is overwritten by the snippet file when I hit refresh, indicating that all permissions are set correctly at least.
The problem is that somewhere in the snippet is a wrong configuration somewhere that is writing an invalid path to the weather.txt file and the outputting it. The result is that all the statistical information is correct. It’s only the icon path that comes out incorrectly.
I did replace the icons with another icon set, which are stored in the same folder as requested in the snippet install instructions. I gave the icons the same filename and ending so that in theory there shouldn’t be any problems. I also tried it with the orginal icons (the one from weather.com) but I still got the same error.
I will copy paste all the snippet file as I have it on my server. If you see any mis-configuration, then please let me know. All help is greatly appreciated.
The path to $wxIcons is exactly as the orginal path:
$wxIcons = 'assets/snippets/WeatherX/graphics'; // Path to Weather Icons
the template below the snippet call is as follows:
[!weather?&zipcode=`DAXX0009`&units=`metric`&provider=`blah`&clock=`12`!]
<div>
<img src="[+wxIcon+]"><br />
<p>Temp: [+wxTemp+]</p>
</div>
I use the call {{weather}} to call for the snippet.
The WeatherX.inc.php that is located in the include folder (can be found in version 1.02) is as follows:
<?php
//********Helper Functions*************
////This takes two parallel arrays and sets the placeholders with them.
function setPlaceholders ($array1, $array2) {
$i = 0;
foreach ($array1 as $v) {
global $modx;
$modx->setPlaceholder($array1[$i], $array2[$i]);
$i++;
}
return;
}
////Find the string in the middle of two points
function get_middle($source, $beginning, $ending, $init_pos) {
$beginning_pos = strpos($source, $beginning, $init_pos);
$middle_pos = $beginning_pos + strlen($beginning);
$ending_pos = strpos($source, $ending, $beginning_pos + 1);
$middle = substr($source, $middle_pos, $ending_pos - $middle_pos);
return $middle;
}
////Parse XML
function parseXML ($file) {
if (function_exists('curl_init')) {
$ch = curl_init($file); /// initialize a cURL session
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec ($ch);
curl_close ($ch);
if (!is_string($data) || !strlen($data)) {
return FALSE;
}
} else {
$fp = fopen($file,'r');
while(!feof($fp)){
$data = $data . fread($fp, 1024);
}
fclose($fp);
}
$xml_parser = xml_parser_create();
xml_parse_into_struct( $xml_parser, $data, $vals, $index );
xml_parser_free( $xml_parser );
return $vals;
}
function setIconDay ($conditions, $offSet, $nightTime) {
if ($offSet >= $nightTime){
if ($conditions == 'Overcast') {
$icon = 26;
} elseif ($conditions == 'Clear') {
$icon = 31;
}elseif ($conditions == 'Scattered Clouds') {
$icon = 29;
}elseif ($conditions == 'Mostly Cloudy') {
$icon = 27;
}elseif ($conditions == 'Heavy Rain') {
$icon = 45;
} elseif ($conditions == 'Light Rain') {
$icon = 45;
} else {
$icon = 99;
}
} else {
if ($conditions == 'Overcast') {
$icon = 26;
} elseif ($conditions == 'Clear') {
$icon = 32;
}elseif ($conditions == 'Scattered Clouds') {
$icon = 34;
}elseif ($conditions == 'Mostly Cloudy') {
$icon = 28;
}elseif ($conditions == 'Heavy Rain') {
$icon = 32;
} elseif ($conditions == 'Light Rain') {
$icon = 11;
} else {
$icon = 99;
}
}
return $icon;
}
function writeToFile ($wxUpdateFile, $wxWrittenInfo) {
// Let's make sure the file exists and is writable first.
if (is_writable($wxUpdateFile)) {
if (!$handle = fopen($wxUpdateFile, 'w')) {
exit;
}
// Write content to our opened file.
if (fwrite($handle, $wxWrittenInfo) === FALSE) {
exit;
}
fclose($handle);
}
return;
}
?>
and finally the code for the snippet is as follows:
<?php
// Resource Name: WeatherX
// Author: Jesse Rochman
// Forum Alias: jesster444
// Version: 1.0
// Compatible with .95Beta5
// Released: 11/8/2006
// Created from Nick Schaffner's WEATHER.COM XML PARSER
// Template Placeholders: wxIcon, wxSunr, wxSuns, wxWindSpeed, wxWindir, wxTemp, wxConditions, wxDate
//Require the included helper functions
require_once($modx->config['base_path'] . 'assets/snippets/WeatherX/include/WeatherX.inc.php');
//////// Some Constants
$wxUrl = 'http://xoap.weather.com/weather/local/'; // URL to xoap.weather
$wxUPDATE_CONSTANT = 600; //This is how often the weather will be updated. DON'T CHANGE!
$wxNow = time(); //This allows us to see if we need to update variables
$wxWunderUrl = 'http://rss.wunderground.com/auto/rss_full/';
//////// Set Varibles Below
$wxZipcode = 'DAXX0009'; // Zipcode
$wxUnits = 'english'; // Set to 'english' or 'metric' (Celsius & KMH)
$dateFormat = 'l, F jS Y g:i'; // check http://us2.php.net/date
///////Set only if using Weather.com
$partner = 'xxxxxxxxx'; // Partner ID
$license = 'xxxxxxxxxxxxxxxx'; // License Key
$wxIcons = 'assets/snippets/WeatherX/graphics'; // Path to Weather Icons
$wxClock = 12; // Set to '12' or '24' hour format
$wxUpdateFile = $modx->config['base_path'] . 'assets/snippets/WeatherX/weather.txt'; //location of Text File
/////Set all the placeholders so you can output the format in a template or chunk!
//Parameter overrides
if (isset($zipcode)) {
$wxZipcode = $zipcode;
}
if (isset($clock)) {
$wxClock = $clock;
}
if (isset($units)) {
$wxUnits = $units;
}
if (!isset($provider)) {
$provider = 'wunder';
}
if (!isset($offSet)) {
$offSet = 0 + date('G');
} else {
$offSet = $offSet + date('G');
}
if (!isset($nightTime)) $nightTime = 19;
/////Read the file and establish all the output variables (For Weather.com)
$handle = fopen($wxUpdateFile, 'r');
$contents = fread($handle, filesize($wxUpdateFile));
fclose($handle);
$contents = explode('|', $contents);
if ($provider != 'wunder') {
$wxLastUpdate = $contents[0] + $wxUPDATE_CONSTANT;
$wxIcon = $contents[1];
$sunr = $contents[2];
$suns = $contents[3];
$date = $contents[4];
$s = $contents[5];
$conditions = $contents[6];
$tmp = $contents[7];
$windir = $contents[8];
$r = $contents[9];
$hmid = $contents[10];
$flik = $contents[11];
$arr1 = array('wxFeelsLike','wxHumidity','wxPressure','wxIcon','wxSunr','wxSuns','wxDate','wxWindSpeed','wxConditions','wxTemp','wxWindDir');
$arr2 = array($flik,$hmid,$r,$wxIcon,$sunr,$suns,$date,$s,$conditions,$tmp,$windir);
setPlaceholders($arr1, $arr2);
//Check to see if we need to update the variables otherwise we are done.
if ($wxLastUpdate < $wxNow) {
//////// Parse XML
$file = $wxUrl . $wxZipcode . '?cc=*&&prod=xoap&par=' . $wxPartner. '&key=' . $wxLicense;
$vals = parseXML($file);
if ($vals) {
$t = true;
foreach ($vals as $key => $i) {
if ($vals[$key]['value'] != false) {
if ($vals[$key]['tag'] == 'VIS') break;
if ($vals[$key]['tag'] != 'T') {
$temp = strtolower($vals[$key]['tag']);
$$temp = $vals[$key]['value'];
} elseif ($t == true) {
if ($vals[$key]['level'] == 3) $conditions = $vals[$key]['value'];
else { $windir = $vals[$key]['value']; $t = false;}
}
}
}
//////// Make sense of the varibles
$sunr = str_replace (' ','',$sunr);
$suns = str_replace (' ','',$suns);
$date = date($dateFormat);
$hmid .= '%';
if ($wxUnits == 'metric') { // Set Metric
$tmp = round((($tmp - 32)/9) * 5).'°C';
$flik = round((($flik - 32)/9) * 5).'°C';
$s = round($s * 1.609).'km/h';
$r .= round(($r * 3386.388640341)/100). 'hPa';
} else {
$tmp .= '°F';
$flik .= '°F';
$s .= 'mph';
$r .= 'in';
}
if ($wxClock == 24) {
$sunr = date('H:i',strtotime($sunr));
$suns = date('H:i',strtotime($suns));
}
if ($s == 'calm') $wind = 'Calm';
$wxIcon = $modx->config['base_url'] . $wxIcons . '/' . $icon . '.png';
$wxWrittenInfo = $wxNow . '|' . $wxIcon . '|' . $sunr . '|' .$suns . '|' . $date . '|' . $s . '|' . $conditions . '|' . $tmp . '|' . $windir . '|' . $r . '|'. $hmid . '|' . $flik;
writeToFile($wxUpdateFile,$wxWrittenInfo);
}
}
} else {
$wxLastUpdate = $contents[0] + $wxUPDATE_CONSTANT;
$tmp = $contents[1];
$humidity = $contents[2];
$pressure = $contents[3];
$conditions = $contents[4];
$windir = $contents[5];
$s = $contents[6];
$date = $contents[7];
$wxIcon = $contents[8];
$arr1 = array('wxIcon','wxHumidity','wxPressure','wxWindSpeed','wxConditions','wxTemp','wxWindDir','wxDate');
$arr2 = array($wxIcon,$humidity,$pressure,$s,$conditions,$tmp,$windir,$date);
setPlaceholders($arr1, $arr2);
//Parse XML
$file = $wxWunderUrl . $wxZipcode . '?units=' . $wxUnits;
$vals = parseXML($file);
if ($vals) {
foreach ($vals as $key => $i) {
if ($vals[$key]['tag'] == 'DESCRIPTION' && $vals[$key]['level'] == 4) {
$temp = $vals[$key]['value'];
$tmp = trim(get_middle($temp, 'Temperature:', '|',0));
$humidity = trim(get_middle($temp, 'Humidity:', '|',12));
$pressure = trim(get_middle($temp, 'Pressure:', '|',21));
$conditions = trim(get_middle($temp, 'Conditions:', '|',30));
$windir = trim(get_middle($temp, 'Wind Direction:', '|',41));
$s = trim(substr($temp, strpos($temp,'Wind Speed')+11));
$date = date($dateFormat);
$icon = setIconDay($conditions, $offSet, $nightTime);
$wxIcon = $modx->config['base_url'] . $wxIcons . '/' . $icon . '.png';
$wxWrittenInfo = $wxNow.'|'.$tmp.'|'.$humidity.'|'.$pressure.'|'.$conditions.'|'.$windir.'|'.$s.'|'.$date.'|'. $wxIcon;
writeToFile($wxUpdateFile,$wxWrittenInfo);
return '';
}
}
}
}
?>
All help would be greatly appreciated
/Jon Hnefill