From 0a349c07ef83e4f341ec4f4c48ba13142bcb347c Mon Sep 17 00:00:00 2001 From: Jim Hu Date: Wed, 5 Apr 2006 04:59:20 +0000 Subject: add new rss files --- rss/index.php | 65 +++++++++------ rss/rss1.0.php | 255 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rss/rss2.0.php | 257 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rss/xml.gif | Bin 0 -> 429 bytes 4 files changed, 552 insertions(+), 25 deletions(-) create mode 100755 rss/rss1.0.php create mode 100644 rss/rss2.0.php create mode 100644 rss/xml.gif (limited to 'rss') diff --git a/rss/index.php b/rss/index.php index 6132290..8d733ca 100644 --- a/rss/index.php +++ b/rss/index.php @@ -1,11 +1,14 @@ \n"; +$xml_icon ="xml"; -if (isset($cpath) && $cpath !=''){ - $cpath_tmp = '&cpath='.$cpath; -} +$filelist = availableCalendars($username, $password, $ALL_CALENDARS_COMBINED); foreach ($filelist as $file) { // $cal_filename is the filename of the calendar without .ics // $cal is a urlencoded version of $cal_filename // $cal_displayname is $cal_filename with occurrences of "32" replaced with " " - if (substr($file, 0, 7) == 'http://' || substr($file, 0, 8) == 'https://' || substr($file, 0, 9) == 'webcal://') { - $cal_tmp = urlencode($file); + if (is_numeric(array_search($file, $cal_filelist))){ + $cal_displayname_tmp = $cal_displaynames[array_search($file,$cal_filelist)]; }else{ - $cal_tmp = getCalendarName($file); - } - $cal_displayname_tmp = $cal_displaynames[array_search($file,$cal_filelist)]; - $cal_tmp = str_replace(" ", "+", $cal_tmp); - $rss_list .= '
'.$cal_displayname_tmp.' '. $lang['l_calendar'].'
'; - $rss_list .= ''; - - $rss_list .= ''; - - $rss_list .= ''; - - $rss_list .= ''; - $rss_list .='
'.$lang['l_day'].': - '.$default_path.'/rss/rss.php?cal='.$cal_tmp.$cpath_tmp.'&rssview=day
'.$lang['l_week'].': - '.$default_path.'/rss/rss.php?cal='.$cal_tmp.$cpath_tmp.'&rssview=week
'.$lang['l_month'].': - '.$default_path.'/rss/rss.php?cal='.$cal_tmp.$cpath_tmp.'&rssview=month
'.$lang['l_year'].': - '.$default_path.'/rss/rss.php?cal='.$cal_tmp.$cpath_tmp.'&rssview=year
'; - $footer_check = $default_path.'/rss/rss.php?cal='.$default_cal.'&rssview='.$default_view; + $cal_displayname_tmp = str_replace("32", " ", str_replace(".ics",'',basename($file))); + } + $rss_list .= ''.$cal_displayname_tmp.' '. $lang['l_calendar'].''; + +/* Changed to show links without urlencode, but links valid urls */ + $rss_list .= "".$lang['l_day'].""; + $rss_list .= ''.$xml_icon.' RSS 0.91'; + $rss_list .= ''.$xml_icon.' RSS 1.0'; + $rss_list .= ''.$xml_icon.' RSS 2.0'; + + $rss_list .= "".$lang['l_week'].""; + $rss_list .= ''.$xml_icon.' RSS 0.91'; + $rss_list .= ''.$xml_icon.' RSS 1.0'; + $rss_list .= ''.$xml_icon.' RSS 2.0'; + + $rss_list .= "".$lang['l_month'].""; + $rss_list .= ''.$xml_icon.' RSS 0.91'; + $rss_list .= ''.$xml_icon.' RSS 1.0'; + $rss_list .= ''.$xml_icon.' RSS 2.0'; + + $footer_check = $default_path.'/rss/rss.php?cal%3D'.rawurlencode($file.'&cpath='.$cpath.'&rssview='.$default_view); + $validrss_check = str_replace('%', '%25', $footer_check); + $rss_list .= " \n"; + } +$rss_list .= "\n"; + + +/* End link modification */ $page = new Page(BASE.'templates/'.$template.'/rss_index.tpl'); @@ -76,6 +88,9 @@ $page->replace_tags(array( 'rss_available' => '', 'rssdisable' => '', 'rss_valid' => '', + 'rss_docinfo' => "RSS feeds can also be set up for a specified number of days before or after a given date, or between two dates. See the documentation for how to set up the URLs", +/* Replaces footer.tpl {validrss_check} with $validrss_check */ + 'validrss_check' => $validrss_check, 'show_search' => $show_search, 'l_rss_info' => $lang['l_rss_info'], 'l_rss_subhead' => $lang['l_rss_subhead'], diff --git a/rss/rss1.0.php b/rss/rss1.0.php new file mode 100755 index 0000000..deceab4 --- /dev/null +++ b/rss/rss1.0.php @@ -0,0 +1,255 @@ + $filemod) $filemod = $calinfo['mtime']; +} +$filemodtime = date("r", $filemod); + +//send relevant headers +header ("Last-Modified: $filemodtime"); +header ("ETag:\"$filemodtime\""); + +// checks the user agents headers to see if they kept track of our +// stuff, if so be nice and send back a 304 and exit. + +if ( ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $filemodtime) || ($_SERVER['HTTP_IF_NONE_MATCH'] == $filemodtime)){ + header ("HTTP/1.1 304 Not Modified"); + exit; +} + +/* Change languages to ISO 639-1 to validate RSS without changing long version in config.inc.php */ +$user_language = array ("english", "polish", "german", "french", "dutch", "italian", "japanese", "norwegian", "spanish", "swedish", "portuguese", "catalan", "traditional_chinese", "esperanto", "korean"); +$iso_language = array ("en", "pl", "de", "fr", "nl", "da", "it", "ja", "no", "es", "sv", "pt", "ca", "zh-tw", "eo", "ko"); +$rss_language = str_replace($user_language, $iso_language, $language); +/* End language modification */ + +$rss = ""."\n"; + +/* Use 1.0 and strip encoding, use rss_language */ +$rss .= ''."\n"; + +$rss .= ''."\n"; +$rss .= ''.$cal_displayname.' '.$lang['l_calendar'].' - '.$theview.''."\n"; +#$rss .= ''.$rss_language.''."\n"; + + +//generate the items +$numdays = round((strtotime($todate) - strtotime($fromdate))/(60*60*24))+1; +$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 = 1; #day counter + +$rss .= "\n\n"; +$rss_items =''; +$uid_arr = array(); + do { + $thisdate=date('Ymd', strtotime($thisdate)); + #echo "Date: $thisdate
\n"; + $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 $uid=>$val) { + #handle multiday all day events + if(!$val["event_start"]){ + if (isset($uid_arr[$uid])){ + $uid_arr[$uid] .= "+$dayofweek" ; + continue; + }else{ + $uid_arr[$uid] = "$dayofweek" ; + } + $event_start = $lang['l_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 = urlencode($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"); + /* original link, not valid url coding + $rss_link = htmlspecialchars ("$default_path/day.php?getdate=$thisdate&cal=$cal&cpath=$cpath"); + */ + /* Add %20's for spaces for the calendar links to make them valid url's */ + $urlcal = rawurlencode ("$cal"); + $rss_link = ("$default_path/day.php?getdate=$thisdate&cal=$urlcal"); + if (isset($cpath) && $cpath !=''){ + $rss_link .= "&cpath=$cpath"; + } + /* End link modification */ + $rss_description = htmlspecialchars ("$dayofweek $event_start: $description"); + + $rss .= ''."\n"; + $rss_items .= ''."\n"; + + /* Create guid, and use uid to make link unique */ + # $rss .= ''.$rss_link.$uid.''."\n"; + /* End guid modification */ + $rss_items .= ''.$rss_title.''."\n"; + $rss_items .= ''.date("Y-m-d", strtotime($thisdate)).'T'.date("h:m:s",$val["event_start"]).''."\n"; + $rss_items .= ''.date("Y-m-d", strtotime($thisdate)).'T'.date("h:m:s",$val["event_start"]).''."\n"; + + $rss_items .= ''.$rss_link.''."\n"; + $rss_items .= ''.$rss_description.''."\n"; + if (isset($val['location']) && $val['location'] !=''){ + $rss_items .= ''.$val['location']."\n"; + } + $rss_items .= ''."\n"; + $events_count++; + } + } + } + if (($events_count < 1) && ($i == $numdays)) { + $rss_items .= ''."\n"; + $rss_items .= 'No events found'."\n"; + $rss_items .= ''.htmlspecialchars ("$default_path").''."\n"; + $rss_items .= ''."\n"; + } + $thisdate++; + $i++; + } while ($i <= $numdays); + +$rss .= "
\n
\n"; +$rss .= "
\n"; +$rss .= $rss_items.'
'."\n"; + +foreach ($uid_arr as $uid=>$date_range){ + #echo "date_range:$date_range
"; + + if(strpos($date_range,"+")>0){ + #echo "+ in date_range
"; + $temp = explode("+",$date_range); + $date_range = $temp[0].'-'.array_pop($temp); + } + $rss = str_replace("$uid\n".$lang['l_all_day']."","$uid\n$date_range", $rss); + +} +header ("Content-Type: text/xml"); + +echo "$rss"; + +?> diff --git a/rss/rss2.0.php b/rss/rss2.0.php new file mode 100644 index 0000000..f009555 --- /dev/null +++ b/rss/rss2.0.php @@ -0,0 +1,257 @@ + $filemod) $filemod = $calinfo['mtime']; +} +$filemodtime = date("r", $filemod); + +//send relevant headers +header ("Last-Modified: $filemodtime"); +header ("ETag:\"$filemodtime\""); + +// checks the user agents headers to see if they kept track of our +// stuff, if so be nice and send back a 304 and exit. + +if ( ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $filemodtime) || ($_SERVER['HTTP_IF_NONE_MATCH'] == $filemodtime)) +{ +# header ("HTTP/1.1 304 Not Modified"); +# exit; +} + +/* Change languages to ISO 639-1 to validate RSS without changing long version in config.inc.php */ +$user_language = array ("english", "polish", "german", "french", "dutch", "italian", "japanese", "norwegian", "spanish", "swedish", "portuguese", "catalan", "traditional_chinese", "esperanto", "korean"); +$iso_language = array ("en", "pl", "de", "fr", "nl", "da", "it", "ja", "no", "es", "sv", "pt", "ca", "zh-tw", "eo", "ko"); +$rss_language = str_replace($user_language, $iso_language, $language); +/* End language modification */ + +$rss = ""."\n"; +#$rss .= ''."\n"; + +/* Use 2.0 and strip encoding, use rss_language */ +$rss .= ''."\n"; +$rss .= ''.$rss_language.''."\n"; + + +/* End rss 2.0 modification */ + + +//generate the items +$numdays = round((strtotime($todate) - strtotime($fromdate))/(60*60*24))+1; +$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 = 1; #day counter + +#$rss .= "\n\n"; +$uid_arr = array(); + do { + $thisdate=date('Ymd', strtotime($thisdate)); + #echo "Date: $thisdate
\n"; + $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 $uid=>$val) { + #handle multiday all day events + if(!$val["event_start"]){ + if (isset($uid_arr[$uid])){ + $uid_arr[$uid] .= "+$dayofweek" ; + continue; + }else{ + $uid_arr[$uid] = "$dayofweek" ; + } + $event_start = $lang['l_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 = urlencode($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"); + /* original link, not valid url coding + $rss_link = htmlspecialchars ("$default_path/day.php?getdate=$thisdate&cal=$cal&cpath=$cpath"); + */ + /* Add %20's for spaces for the calendar links to make them valid url's */ + $urlcal = rawurlencode ("$cal"); + $rss_link = ("$default_path/day.php?getdate=$thisdate&cal=$urlcal"); + if (isset($cpath) && $cpath !=''){ + $rss_link .= "&cpath=$cpath"; + } + /* End link modification */ + $rss_description = htmlspecialchars ("$dayofweek $event_start: $description"); + + #$rss .= ''."\n"; + $rss .= ''."\n"; + + /* Create guid, and use uid to make link unique */ + $rss .= ''.$rss_link.'&uid='.$uid.''."\n"; + /* End guid modification */ + $rss .= ''.$rss_title.''."\n"; + $rss .= ''.date("Y-m-d", strtotime($thisdate)).'T'.date("h:m:s",$val["event_start"]).''."\n"; + $rss .= ''.date("Y-m-d", strtotime($thisdate)).'T'.date("h:m:s",$val["event_start"]).''."\n"; + + $rss .= ''.$rss_link.''."\n"; + $rss .= ''.$rss_description.''."\n"; + if (isset($val['location']) && $val['location'] !=''){ + $rss .= ''.$val['location']."\n"; + } + $rss .= ''."\n"; + $events_count++; + } + } + } + if (($events_count < 1) && ($i == $numdays)) { + $rss .= ''."\n"; + $rss .= 'No events found'."\n"; + $rss .= ''.htmlspecialchars ("$default_path").''."\n"; + $rss .= ''."\n"; + } + $thisdate++; + $i++; + } while ($i <= $numdays); + +#$rss .= "
\n
\n"; +$rss .= "\n\n
\n"; + +foreach ($uid_arr as $uid=>$date_range){ + #echo "date_range:$date_range
"; + + if(strpos($date_range,"+")>0){ + #echo "+ in date_range
"; + $temp = explode("+",$date_range); + $date_range = $temp[0].'-'.array_pop($temp); + } + $rss = str_replace("$uid\n".$lang['l_all_day']."","$uid\n$date_range", $rss); + +} +header ("Content-Type: text/xml"); + +echo "$rss"; + +?> diff --git a/rss/xml.gif b/rss/xml.gif new file mode 100644 index 0000000..ecb0957 Binary files /dev/null and b/rss/xml.gif differ -- cgit v1.2.3