Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Publish.php conflicts with XML parser.
UPDATED BELOW – Please help.
Hello all,
I’m using a small php script to parse weather.com XML feed.
It works great when it’s on it’s own, but when include it on any TXP pages, it doesn’t work properly.
To be more specific…it processes everything in the script properly, until it gets to a foreach about half way thru.
By process of elimination, I’ve narrowed it down to a conflict with something in publish.php (or one of the files it includes).
Here’s a link to everything working
UPDATE
Set production status to debugging and a bunch of errors like these:
Notice: Undefined index: length in /home/mysite/public_html/seniortimes/weather/weather_new.php on line 12
Notice: Undefined variable: xml in /home/mysite/public_html/seniortimes/weather/weather_new.php on line 24
Notice: Use of undefined constant dnam – assumed ‘dnam’ in /home/mysite/public_html/seniortimes/weather/weather_new.php on line 43
Notice: Use of undefined constant value – assumed ‘value’ in /home/mysite/public_html/seniortimes/weather/weather_new.php on line 43
Do these make any sense to anyone?
Any help/guidance/suggestions would be much appreciated.
End Update
I’m posting the PHP below.
any help would Be MUCH appreciated!
<? if(empty($loc_id))
$loc_id="32606";
$partner_ID = "nnn--hidden-on-forum"; // partner ID
$license_key = "nnn--hidden-on-forum"; // weather channel license key
$units = "s"; // m for metric (C) // s for standard (F)
$length="3"; // the amount of days for forecast (max. 10)
$image_size = "32x32"; // the size of the forecast images (32x32 or 64x64 or 128x128)
$length = $_REQUEST['length'];
if (!($length >= 1 And $length <= 10)) $length = 3;
$forecast_url ="http://xoap.weather.com/weather/local/$loc_id?cc=*&dayf=$length&prod=xoap&par=$partner_ID&key=$license_key&unit=$units";
$checkurl = $forecast_url;
$xml_url = md5($checkurl);
$ttl = 60*60;
$cachefilename = "/home/myhome/public_directory/mysite/weather/cache/$xml_url";
if (file_exists($cachefilename) && (time() - $ttl < filemtime($cachefilename))) {
$url = $cachefilename;
$fp = fopen($url,"r");
while (!feof ($fp))
$xml .= fgets($fp, 4096);
fclose ($fp);
}else{
$url = $forecast_url;
$fp = fopen($url,"r");
while (!feof ($fp))
$xml .= fgets($fp, 4096);
fclose ($fp);
$fw = fopen($cachefilename, 'w');
fwrite($fw, $xml);
fclose($fw);
}
$parser = xml_parser_create( );
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parse_into_struct($parser,$xml,$values,$index);
xml_parser_free($parser);
$city = htmlspecialchars($values[$index[dnam][0]][value]);
$unit_temp = $values[$index[ut][0]][value];
$unit_speed = $values[$index[us][0]][value];
$unit_precip = $values[$index[up][0]][value];
$unit_pressure = $values[$index[ur][0]][value];
$sunrise = $values[$index[sunr][0]][value];
$sunset = $values[$index[suns][0]][value];
$timezone = $values[$index[tzone][0]][value];
$last_update = $values[$index[lsup][0]][value];
$curr_temp = $values[$index[tmp][0]][value];
$curr_flik = $values[$index[flik][0]][value];
$conditions = $values[$index[t][0]][value];
$curr_icon = $values[$index[icon][0]][value];
$counter = 0;
$row_counter = 2;
$day_precip = $counter * 2;
$xml="";
?>
<div id="weather">
<b>Today's Forecast For 32606</b>
<div id="weather_conditions">
<div id="weather_icon_lg"><a href="/weatherlocation/32606"><img src="/weather/weathericons/<? echo"$curr_icon"; ?>.png" alt="" width="50px" height="50px" /></a></div>
<div class="weather_temp_hi">HIGH<br/><b><? if ($values[$index[hi][$counter]][value] =="N/A") echo "NA"; else echo $values[$index[hi][$counter]][value] . "°"; ?></b></div>
<div class="weather_temp_lo">LOW<br/><b><? echo $values[$index[low][$counter]][value] . "°"; ?></b></div>
</div>
<? foreach ($index[day] as $day){
if ($values[$day][attributes][t] != ""){
$img_day = ($counter + 1) * 2;
?>
<div class="weather_3day">
<div class="date"><? echo $values[$day][attributes][t];?><br /> <? echo $values[$day][attributes][dt]; ?></div>
<div class="conditions"><div class="image"><img align="middle" border="0" src="/weather/weathericons/32x32/<? echo $values[$index[icon][$img_day]][value]; ?>.png" alt="" /></div></div>
<div class="temp_sm_hi"><? echo $values[$index[hi][$counter]][value] . "° "; ?></div>
<div class="temp_sm_lo"><? echo $values[$index[low][$counter]][value] . "° "; ?></div>
</div>
<?
$counter++;
$row_counter++;
}
}
?>
Last edited by renobird (2007-10-25 20:49:55)
Offline
#2 2007-10-26 02:23:40
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Publish.php conflicts with XML parser.
I don’t know the problem, but try sticking the whole thing within a function, and/or turn it into a Txp plugin.
Offline
Re: Publish.php conflicts with XML parser.
Mary Wrote
bq.but try sticking the whole thing within a function, and/or turn it into a Txp plugin
Thank You. I’ll try the function first.
I’ve never made a plugin…maybe this is the push I need to figure it out.
- )
—
Tom
Offline
Pages: 1