Advertisement
reelrootsryan

Untitled

Feb 18th, 2014
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.32 KB | None | 0 0
  1. if ($use_cache) {
  2.         ////////
  3.         //Cache
  4.         //
  5.        
  6.         $cache_time = 3600*12; // 12 hours
  7.         $cache_file = $_SERVER['DOCUMENT_ROOT'].'/gcal.xml'; //xml file saved on server
  8.        
  9.         if ($debug_mode) {echo "<P>Your cache is saved at ".$cache_file."</P>";}
  10.        
  11.         $timedif = @(time() - filemtime($cache_file));
  12.  
  13.         $xml = "";
  14.         if (file_exists($cache_file) && $timedif < $cache_time) {
  15.                 if ($debug_mode) {echo "<P>I'll use the cache.</P>";}
  16.                 $str = file_get_contents($cache_file);
  17.                 $xml = simplexml_load_string($str);
  18.         } else { //not here
  19.                 if ($debug_mode) {echo "<P>I don't have any valid cached copy.</P>";}
  20.                 $xml = simplexml_load_file($calendar_xml_address); //come here
  21.                 if ($f = fopen($cache_file, 'w')) { //save info
  22.                         $str = $xml->asXML();
  23.                         fwrite ($f, $str, strlen($str));
  24.                         fclose($f);
  25.                         if ($debug_mode) {echo "<P>Cache saved :)</P>";}
  26.                 } else { echo "<P>Can't write to the cache.</P>"; }
  27.         }
  28.        
  29.         //done!
  30. } else {
  31.     $xml = simplexml_load_file($calendar_xml_address);
  32. }
  33.  
  34. if ($debug_mode) {echo "<P>Successfully got the GCal feed.</p>";}
  35.  
  36. $items_shown=0;
  37. $old_date="";
  38. $xml->asXML(); ********THIS IS LINE 120 CAUSING THE ERROR**********
  39.  
  40. foreach ($xml->entry as $entry){
  41.     $ns_gd = $entry->children('http://schemas.google.com/g/2005');
  42.  
  43.     //Do some niceness to the description
  44.     //Make any URLs used in the description clickable
  45.     $description = preg_replace('"\b(http://\S+)"', '<a href="$1">$1</a>', $entry->content);
  46.  
  47.     // Make email addresses in the description clickable
  48.     $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);
  49.  
  50.     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>"; }
  51.  
  52.     // These are the dates we'll display
  53.     $gCalDate = date($dateformat, strtotime($ns_gd->when->attributes()->startTime));
  54.     $gCalDateStart = date($dateformat, strtotime($ns_gd->when->attributes()->startTime));
  55.     $gCalDateEnd = date($dateformat, strtotime($ns_gd->when->attributes()->endTime));
  56.     $gCalStartTime = date($timeformat, strtotime($ns_gd->when->attributes()->startTime));
  57.     $gCalEndTime = date($timeformat, strtotime($ns_gd->when->attributes()->endTime));
  58.                    
  59.     // Now, let's run it through some str_replaces, and store it with the date for easy sorting later
  60.     $temp_event=$event_display;
  61.     $temp_dateheader=$event_dateheader;
  62.     $temp_event=str_replace("###TITLE###",$entry->title,$temp_event);
  63.     $temp_event=str_replace("###DESCRIPTION###",$description,$temp_event);
  64.  
  65.     if ($gCalDateStart!=$gCalDateEnd) {
  66.     //This starts and ends on a different date, so show the dates
  67.     $temp_event=str_replace("###DATESTART###",$gCalDateStart,$temp_event);
  68.     $temp_event=str_replace("###DATEEND###",$gCalDateEnd,$temp_event);
  69.     } else {
  70.     $temp_event=str_replace("###DATESTART###",'',$temp_event);
  71.     $temp_event=str_replace("###DATEEND###",'',$temp_event);
  72.     }
  73.  
  74.     $temp_event=str_replace("###DATE###",$gCalDate,$temp_event);
  75.     $temp_dateheader=str_replace("###DATE###",$gCalDate,$temp_dateheader);
  76.     $temp_event=str_replace("###FROM###",$gCalStartTime,$temp_event);
  77.     $temp_event=str_replace("###UNTIL###",$gCalEndTime,$temp_event);
  78.     $temp_event=str_replace("###WHERE###",$ns_gd->where->attributes()->valueString,$temp_event);
  79.     $temp_event=str_replace("###LINK###",$entry->link->attributes()->href,$temp_event);
  80.     $temp_event=str_replace("###MAPLINK###","http://maps.google.com/?q=".urlencode($ns_gd->where->attributes()->valueString),$temp_event);
  81.     // Accept and translate HTML
  82.     $temp_event=str_replace("&lt;","<",$temp_event);
  83.     $temp_event=str_replace("&gt;",">",$temp_event);
  84.     $temp_event=str_replace("&quot;","\"",$temp_event);
  85.                    
  86.     if (($items_to_show>0 AND $items_shown<$items_to_show)) {
  87.                 if ($GroupByDate) {if ($gCalDate!=$old_date) { echo $temp_dateheader; $old_date=$gCalDate;}}
  88.         echo $temp_event;
  89.         $items_shown++;
  90.     }
  91. }
  92.  
  93. if (!$items_shown) { echo $event_error; }
  94. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement