Extracting the next 7 days from phpiCalendar to simple HTML
Edit: Newer versions of phpiCalendar give you this feature without the hackery. See the comments for this post.
You’ll need a working installation of PHP (duh), phpiCalendar 2.0beta (or newer), and MagpieRSS If you get errors about re-defining functions, comment out the “require_once” line below, (for instance if you’ve already installed it as part of your Wordpress installation) you’ve already got MagpieRSS.
- Install phpiCalendar and get it working properly.
- In phpiCalendar “rss/rss.php” change this:
if ($rssview == "day") { $theview = $lang['l_day']; } elseif1 { $theview = $lang['l_week']; } elseif ($rssview == "month") { $theview = $lang['l_month']; } - In phpiCalendar “rss/rss.php” add this code right below the block for processing SINGLE DAY requests.
- Browse to {your phpiCalendar installation}/index.php and get the URL for your WEEKLY events. Change the last part of the URL (should be “rssview=week”) to “rssview=calweek”. Mine looks like this:
http://saintandrewslutheran.org/calendar/rss/rss.php?cal=Public&rssview=calweek
- Install MagpieRSS to a reasonable location.
- Include the below code in your site. Be sure to set the correct require_once path (if you didn’t just throw MagpieRSS in the default folder like I did) and to change the URL in the call to fetch_rss to YOUR RSS feed.
- Enjoy!
$thisdate = time();
$i = 0;
if ($rssview == "calweek") {
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, '<b><i><u>');
$event_text = word_wrap($event_text, 21, $tomorrows_events_lines);
$description = stripslashes(urldecode($val["description"]));
$description = strip_tags($description, '<b><i><u>');
$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 .= '<item>'."\n";
$rss .= '<title>'.$rss_title.'</title>'."\n";
$rss .= '<link>'.$rss_link.'</link>'."\n";
$rss .= '<description>'.$rss_description.'</description>'."\n";
$rss .= '</item>'."\n";
$events_week++;
}
}
}
if2 {
$rss .= '<item>'."\n";
$rss .= '<title>'.$lang['l_no_events_week'].'</title>'."\n";
$rss .= '<link>'.htmlspecialchars ("$default_path").'</link>'."\n";
$rss .= '</item>'."\n";
}
$thisdate = ($thisdate + (25 * 60 * 60));
$i++;
} while ($i < 7);
}
<?php
require_once('magpierss/rss_fetch.inc');
$rss =
fetch_rss("http://saintandrewslutheran.org/calendar/rss/rss.php?cal=Public&rssview=calweek");
echo "<p>The next 7 days' calendar items:</p>";
$inUL = false;
$oldDate = '';
foreach($rss->items as $item) {
$href = $item['link'];
$title = $item['title'];
if(stristr($title, 'PRIVATE')) { continue; }
$date = substr($title, 0, strpos($title, ':'));
$cleantitle = substr($title, strpos($title, ':')+1);
if ($oldDate != $date) {
if ($inUL) {
echo "</ul>";
}
echo "<p>$date</p><ul>";
$inUL = true;
$oldDate = $date;
}
echo "<li><a href=$href>$cleantitle</a></li>";
}
echo "</ul>";
?>
- $rssview == "week") {
$theview = $lang['l_week'];
} elseif ($rssview == "month") {
$theview = $lang['l_month'];
}
to this:
if ($rssview == "day") { $theview = $lang['l_day']; } elseif (($rssview == "week") || ($rssview == "calweek" [↩] - $events_week < 1) && ($i == 6 [↩]
You might also enjoy:
« Previous Article: Wedding and Honeymoon Photos
Next Article: Getting started in a new format »
- Ted Carnahan
- Waller Alexander
- Ted Carnahan
- Matt Register


