Extracting the next 7 days from phpiCalendar to simple HTML

A Tech article with View Comments posted 1 July 2006.

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.

  1. Install phpiCalendar and get it working properly.
  2. 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'];
    }
    
  3. In phpiCalendar “rss/rss.php” add this code right below the block for processing SINGLE DAY requests.
  4. $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);
    }
    
  5. 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
  6. Install MagpieRSS to a reasonable location.
  7. 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.
  8. <?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>";
    ?>
    
  9. Enjoy!

Footnotes

  1. $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" []
  2. $events_week < 1) && ($i == 6 []

View Comments to “Extracting the next 7 days from phpiCalendar to simple HTML”

  1. Ted,
    I need some help. You are one of the only people on the net that knows how to do this. Right now I am using Xoops and using a calendar module that is phpicalendar module. I am trying to get the rss feed to work and then use this trick to get the next 7 days and next 30 days events listed on the front page. You seem to know alot more about this than i do. I would be happy to pay you for your time.

    Matt

    PS. The site is for my church and is very much in the concept phase at this point.(resurrection lutheran) http://rlchome.org

  2. Matt -

    I’m not sure how useful this article would be – it’s for the 2.0beta release of phpicalendar. Nevertheless, I’ll contact you by email about seeing if we can’t get it working.

  3. Waller Alexander says:

    Hi!
    I did that without modifying rss.php!
    Maybe it helps someone?!
    $today = date(“Ymd”,time() + (86400 * 14));
    $rss = fetch_rss(“http://www.url/cal/rss/rss1.0.php?rssview=range&to=$today”);

    That shows the events in the next 14 days.

  4. You’re right – it looks like this has gotten much easier with more recent versions of phpicalendar. There is good documentation for the feature here.

Leave a Reply

blog comments powered by Disqus