From 9853c72b020f4092663db5a61389b472a7ea4441 Mon Sep 17 00:00:00 2001 From: Jim Hu Date: Sun, 13 Feb 2005 17:48:50 +0000 Subject: changes to rss.php to allow feeding a range of dates, and to use a single XML generation routine for all feeds. XML generation needs work, but it works for me. --- rss/rss.php | 244 ++++++++++++++++++++++++++++-------------------------------- 1 file changed, 112 insertions(+), 132 deletions(-) (limited to 'rss') diff --git a/rss/rss.php b/rss/rss.php index 5d1c4b3..4bd457c 100644 --- a/rss/rss.php +++ b/rss/rss.php @@ -1,36 +1,84 @@ "; + $theview = $_GET['days']." days from ".date('n/d/Y',strtotime($fromdate)); + break; + case 'daysto': + $todate = $getdate; + $fromdate = $getdate - $_GET['days']; + #print "from:$fromdate to: $todate
"; + $theview = $_GET['days']." days before ".date('n/d/Y',strtotime($todate)); + break; + case 'range': + $fromdate = $_GET['from']; + $todate = $_GET['to']; + $theview = date('n/d/Y',strtotime($fromdate)).'-'.date('n/d/Y',strtotime($todate)); + break; + default: + #default to week + $fromdate = dateOfWeek($getdate, $week_start_day); + $todate = $fromdate + 6; + $theview = $lang['l_week']." of ".date('n/d/Y',strtotime($fromdate)); + +} +//Set calendar or calendar directory name for feed +//Note that this depends on other modifications I've made to +//allow phpicalendar to use calendar subdirectories - see bbs + $cal_displayname = str_replace("32", " ", $cal); -$events_week = 0; -$view_path = $default_path.$rss_view.'.php'; +if ($cal == $ALL_CALENDARS_COMBINED) { + $temp = explode("/",$calendar_path); + $cal_displayname = str_replace("32"," ",ucfirst(array_pop($temp))); +} + +$events_count = 0; // calculate a value for Last Modified and ETag -$cal = urldecode($cal); -$filemod = @filemtime("$calendar_path/$cal.ics"); -$filemodtime = @date("r", $filemod); +if ($cal == $ALL_CALENDARS_COMBINED) { + $filemod = filemtime("$calendar_path"); +}else{ + $filemod = filemtime("$calendar_path/$cal.ics"); +} +$filemodtime = date("r", $filemod); //send relevant headers header ("Last-Modified: $filemodtime"); @@ -45,143 +93,75 @@ if ( ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $filemodtime) || ($_SERVER['HTTP_IF_ exit; } -if ($rssview == "day") { - $theview = $lang['l_day']; -} elseif ($rssview == "week") { - $theview = $lang['l_week']; -} elseif ($rssview == "month") { - $theview = $lang['l_month']; -} - - +//If client needs new feed - make the header $rss = ""."\n"; $rss .= ''."\n"; $rss .= ''."\n"; $rss .= ''."\n"; $rss .= ''.$cal_displayname.' - '.$theview.''."\n"; -$rss .= ''.htmlspecialchars ($view_path).''."\n"; +$rss .= ''.htmlspecialchars ("$default_path").''."\n"; $rss .= ''.$cal_displayname.' '.$lang['l_calendar'].' - '.$theview.''."\n"; $rss .= ''.$rss_language.''."\n"; -$rss .= 'Copyright 2004, '.htmlspecialchars ("$default_path").''."\n"; +$rss .= 'Copyright '.date(Y).', '.htmlspecialchars ("$default_path").''."\n"; +//generate the items +$numdays = $todate - $fromdate; +$thisdate = $fromdate; # start at beginning of date range, + # note that usage of $thisdate is different from distribution + # I use it as a date, dist uses it as a time +$i = 0; #day counter -if ($rssview == 'day') { - if (isset($master_array[($getdate)]) && sizeof($master_array[($getdate)]) > 0) { - foreach ($master_array[("$getdate")] as $event_times) { + do { + $dayofweek = localizeDate ("%a %b %e %Y", strtotime($thisdate)); + if (isset($master_array[($thisdate)]) && sizeof($master_array[($thisdate)]) > 0) { + foreach ($master_array[("$thisdate")] as $event_times) { foreach ($event_times as $val) { - $event_start = @$val["event_start"]; - $event_start = date ($timeFormat, @strtotime ("$event_start")); + if(!$val["event_start"]){ + $event_start = "all day"; + }else{ + $event_start = @$val["event_start"]; + $event_start = date ($timeFormat, @strtotime ("$event_start")); + } $event_text = stripslashes(urldecode($val["event_text"])); $event_text = strip_tags($event_text, ''); - $event_text = word_wrap($event_text, 21, $tomorrows_events_lines); - $description = stripslashes(urldecode($val["description"])); - $description = strip_tags($description, ''); - $rss_title = htmlspecialchars ("$event_start $event_text"); - $rss_link = htmlspecialchars ("$default_path/day.php?getdate=$getdate&cal=$cal"); - $rss_description = htmlspecialchars ("$description"); + $event_text = str_replace("& ","&", $event_text); + #uncomment for shorter event text with ... + # $event_text = word_wrap($event_text, 21, $tomorrows_events_lines); + $description = stripslashes(urldecode($val["description"])); + $description = strip_tags($description, ''); + $rss_title = htmlspecialchars ("$dayofweek: $event_text"); + $rss_link = htmlspecialchars ("$default_path/day.php?getdate=$getdate&cal=$cal&cpath=$cpath"); + $rss_description = htmlspecialchars ("$dayofweek $event_start: $description"); + $rss .= ''."\n"; + $rss .= ''.$event_start.''."\n"; $rss .= ''.$rss_title.''."\n"; + + $rss .= ''.$dayofweek.''."\n"; + $rss .= ''.$event_text.''."\n"; + $rss .= ''.$description.''."\n"; + $rss .= ''.$val["description"].''."\n"; + $rss .= ''.$val['attendee'].''."\n"; + $rss .= ''.$val['organizer'].''."\n"; + $rss .= ''.$val['status'].''."\n"; + $rss .= ''.$rss_link.''."\n"; $rss .= ''.$rss_description.''."\n"; + $rss .= ''.$val['location'].''; $rss .= ''."\n"; - $events_week++; + $events_count++; } } } - if ($events_week < 1) { + if (($events_count < 1) && ($i == $numdays)) { $rss .= ''."\n"; - $rss .= ''.$lang['l_no_events_day'].''."\n"; + $rss .= 'No events found'."\n"; $rss .= ''.htmlspecialchars ("$default_path").''."\n"; $rss .= ''."\n"; } -} - -$thisdate = $start_week_time; -$i = 0; -if ($rssview == "week") { - do { - $getdate = date("Ymd", $thisdate); - $dayofweek = strtotime ($getdate); - $dayofweek = localizeDate ($dateFormat_day, $dayofweek); - if (isset($master_array[($getdate)]) && sizeof($master_array[($getdate)]) > 0) { - foreach ($master_array[("$getdate")] as $event_times) { - foreach ($event_times as $val) { - $event_start = @$val["event_start"]; - $event_start = date ($timeFormat, @strtotime ("$event_start")); - $event_text = stripslashes(urldecode($val["event_text"])); - $event_text = strip_tags($event_text, ''); - $event_text = word_wrap($event_text, 21, $tomorrows_events_lines); - $description = stripslashes(urldecode($val["description"])); - $description = strip_tags($description, ''); - $rss_title = htmlspecialchars ("$dayofweek: $event_text"); - $rss_link = htmlspecialchars ("$default_path/day.php?getdate=$getdate&cal=$cal"); - $rss_description = htmlspecialchars ("$dayofweek $event_start: $event_text - $description"); - $rss .= ''."\n"; - $rss .= ''.$rss_title.''."\n"; - $rss .= ''.$rss_link.''."\n"; - $rss .= ''.$rss_description.''."\n"; - $rss .= ''."\n"; - $events_week++; - } - } - } - if (($events_week < 1) && ($i == 6)) { - $rss .= ''."\n"; - $rss .= ''.$lang['l_no_events_week'].''."\n"; - $rss .= ''.htmlspecialchars ("$default_path").''."\n"; - $rss .= ''."\n"; - } - $thisdate = ($thisdate + (25 * 60 * 60)); + $thisdate++; $i++; - } while ($i < 7); -} - -if ($rssview == "month") { - foreach($master_array as $key => $new_val2) { - - // Pull out only this months - ereg ("([0-9]{6})([0-9]{2})", $key, $regs); - if ($regs[1] == $parse_month) { - $getdate = $key; - $dayofmonth = strtotime ($getdate); - $dayofmonth = localizeDate ($dateFormat_day, $dayofmonth); - - // Pull out each day - foreach ($new_val2 as $new_val) { - - // Pull out each time - foreach ($new_val as $new_key2 => $val) { - if ($val["event_text"]) { - $event_start = @$val["event_start"]; - $event_start = date ($timeFormat, @strtotime ("$event_start")); - $event_text = stripslashes(urldecode($val["event_text"])); - $event_text = strip_tags($event_text, ''); - $event_text = word_wrap($event_text, 21, $tomorrows_events_lines); - $description = stripslashes(urldecode($val["description"])); - $description = strip_tags($description, ''); - $rss_title = htmlspecialchars ("$dayofmonth: $event_text"); - $rss_link = htmlspecialchars ("$default_path/day.php?getdate=$getdate&cal=$cal"); - $rss_description = htmlspecialchars ("$dayofmonth $event_start: $event_text - $description"); - $rss .= ''."\n"; - $rss .= ''.$rss_title.''."\n"; - $rss .= ''.$rss_link.''."\n"; - $rss .= ''.$rss_description.''."\n"; - $rss .= ''."\n"; - $events_week++; - } - - if ($events_week < 1) { - $rss .= ''."\n"; - $rss .= ''.$lang['no_events_month'].''."\n"; - $rss .= ''.htmlspecialchars ("$default_path").''."\n"; - $rss .= ''."\n"; - } - } - } - } - } -} - + } while ($i <= $numdays); $rss .= ''."\n"; $rss .= ''."\n"; -- cgit v1.2.3