Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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(); ********THIS IS LINE 120 CAUSING THE ERROR**********
- foreach ($xml->entry as $entry){
- $ns_gd = $entry->children('http://schemas.google.com/g/2005');
- //Do some niceness to the description
- //Make any URLs used in the description clickable
- $description = preg_replace('"\b(http://\S+)"', '<a href="$1">$1</a>', $entry->content);
- // Make email addresses in the description clickable
- $description = preg_replace("`([-_a-z0-9]+(\.[-_a-z0-9]+)*@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]{2,6})`i","<a href=\"mailto:\\1\" title=\"mailto:\\1\">\\1</a>", $description);
- if ($debug_mode) { echo "<P>Here's the next item's start time... GCal says ".$ns_gd->when->attributes()->startTime." PHP says ".date("g.ia -Z",strtotime($ns_gd->when->attributes()->startTime))."</p>"; }
- // These are the dates we'll display
- $gCalDate = date($dateformat, strtotime($ns_gd->when->attributes()->startTime));
- $gCalDateStart = date($dateformat, strtotime($ns_gd->when->attributes()->startTime));
- $gCalDateEnd = date($dateformat, strtotime($ns_gd->when->attributes()->endTime));
- $gCalStartTime = date($timeformat, strtotime($ns_gd->when->attributes()->startTime));
- $gCalEndTime = date($timeformat, strtotime($ns_gd->when->attributes()->endTime));
- // Now, let's run it through some str_replaces, and store it with the date for easy sorting later
- $temp_event=$event_display;
- $temp_dateheader=$event_dateheader;
- $temp_event=str_replace("###TITLE###",$entry->title,$temp_event);
- $temp_event=str_replace("###DESCRIPTION###",$description,$temp_event);
- if ($gCalDateStart!=$gCalDateEnd) {
- //This starts and ends on a different date, so show the dates
- $temp_event=str_replace("###DATESTART###",$gCalDateStart,$temp_event);
- $temp_event=str_replace("###DATEEND###",$gCalDateEnd,$temp_event);
- } else {
- $temp_event=str_replace("###DATESTART###",'',$temp_event);
- $temp_event=str_replace("###DATEEND###",'',$temp_event);
- }
- $temp_event=str_replace("###DATE###",$gCalDate,$temp_event);
- $temp_dateheader=str_replace("###DATE###",$gCalDate,$temp_dateheader);
- $temp_event=str_replace("###FROM###",$gCalStartTime,$temp_event);
- $temp_event=str_replace("###UNTIL###",$gCalEndTime,$temp_event);
- $temp_event=str_replace("###WHERE###",$ns_gd->where->attributes()->valueString,$temp_event);
- $temp_event=str_replace("###LINK###",$entry->link->attributes()->href,$temp_event);
- $temp_event=str_replace("###MAPLINK###","http://maps.google.com/?q=".urlencode($ns_gd->where->attributes()->valueString),$temp_event);
- // Accept and translate HTML
- $temp_event=str_replace("<","<",$temp_event);
- $temp_event=str_replace(">",">",$temp_event);
- $temp_event=str_replace(""","\"",$temp_event);
- if (($items_to_show>0 AND $items_shown<$items_to_show)) {
- if ($GroupByDate) {if ($gCalDate!=$old_date) { echo $temp_dateheader; $old_date=$gCalDate;}}
- echo $temp_event;
- $items_shown++;
- }
- }
- if (!$items_shown) { echo $event_error; }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement