Monday, August 19, 2013

simpleXML error with google calendar feed with pdo on server

simpleXML error with google calendar feed with pdo on server

i am using some php to grab a google feed with simpleXML to display on my
site. it works fine staged on my test server (no PDO). I installed it live
on my site and it worked. Then i needed to update my CMS which needed
either PDO or Mysqli and my host installed the PDO extensions. after that
it no longer worked. here is the error message:
: Call to a member function asXML() on a non-object in
/home/cactusta/public_html/calendar.php on line 121
here is the relevant part of the script that i am using:
// Your private feed - which you get by right-clicking the 'xml'
button in the 'Private Address' section of 'Calendar Details'.
if (!isset($calendarfeed)) {$calendarfeed = "myfeed.com/public/basic"; }
// Date format you want your details to appear
$dateformat="j F Y"; // 10 March 2009 - see http://www.php.net/date
for details
$timeformat="g.ia"; // 12.15am
// The timezone that your user/venue is in (i.e. the time you're
entering stuff in Google Calendar.)
http://www.php.net/manual/en/timezones.php has a full list
date_default_timezone_set('Europe/London');
// How you want each thing to display.
// By default, this contains all the bits you can grab. You can put
###DATE### in here too if you want to, and disable the 'group by date'
below.
$event_display="<P><B>###TITLE###</b> - from ###FROM###
###DATESTART### until ###UNTIL### ###DATEEND### (<a
href='###LINK###'>add this</a>)<BR>###WHERE### (<a
href='###MAPLINK###'>map</a>)<br>###DESCRIPTION###</p>";
// What happens if there's nothing to display
$event_error="<P>There are no events to display.</p>";
// The separate date header is here
$event_dateheader="<P><B>###DATE###</b></P>";
$GroupByDate=true;
// Change the above to 'false' if you don't want to group this by dates.
// ...and how many you want to display (leave at 999 for everything)
$items_to_show=999;
// ...and here's where you tell it to use a cache.
// Your PHP will need to be able to write to a file called "gcal.xml"
in your root. Create this file by SSH'ing into your box and typing
these three commands...
// > touch gcal.xml
// > chmod 666 gcal.xml
// > touch -t 01101200 gcal.xml
// If you don't need this, or this is all a bit complex, change this
to 'false'
$use_cache=true;
// And finally, change this to 'true' to see lots of fancy debug code
$debug_mode=false;
//
//End of configuration block
/////////
if ($debug_mode) {error_reporting (E_ALL); ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL); echo "<P>Debug mode is on. Hello
there.<BR>Your server thinks the time is ".date(DATE_RFC822)."</p>";}
// Form the XML address.
$calendar_xml_address =
str_replace("/basic","/full?singleevents=true&futureevents=true&max-results".$items_to_show."&orderby=starttime&sortorder=a",$calendarfeed);
//This goes and gets future events in your feed.
if ($debug_mode) {
echo "<P>We're going to go and grab <a
href='$calendar_xml_address'>this feed</a>.<P>";}
if ($use_cache) {
////////
//Cache
//
$cache_time = 3600*12; // 12 hours
$cache_file = $_SERVER['DOCUMENT_ROOT'].'/gcal.xml'; //xml
file saved on server
if ($debug_mode) {echo "<P>Your cache is saved at
".$cache_file."</P>";}
$timedif = @(time() - filemtime($cache_file));
$xml = "";
if (file_exists($cache_file) && $timedif < $cache_time) {
if ($debug_mode) {echo "<P>I'll use the cache.</P>";}
$str = file_get_contents($cache_file);
$xml = simplexml_load_string($str);
} else { //not here
if ($debug_mode) {echo "<P>I don't have any valid
cached copy.</P>";}
$xml = simplexml_load_file($calendar_xml_address);
//come here
if ($f = fopen($cache_file, 'w')) { //save info
$str = $xml->asXML();
fwrite ($f, $str, strlen($str));
fclose($f);
if ($debug_mode) {echo "<P>Cache saved :)</P>";}
} else { echo "<P>Can't write to the cache.</P>"; }
}
//done!
} else {
$xml = simplexml_load_file($calendar_xml_address);
}
if ($debug_mode) {echo "<P>Successfully got the GCal feed.</p>";}
$items_shown=0;
$old_date="";
$xml->asXML();

No comments:

Post a Comment