Welcome!

Thanks for visiting. If you found this information interesting or useful (or you think I'm dead wrong about something) I'd like to invite you to leave a comment on this post. You can also subscribe to my RSS feed or sign up for email updates on the right-hand side of the page.

If you Digg what you StumbleUpon, find my writing del.icio.us, or are one of the Technorati, you know what to do:

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.

  1. Install phpiCalendar and get it working properly.
  2. In phpiCalendar “rss/rss.php” change this:
    if ($rssview == "day") {
      $theview = $lang['l_day'];
    } elseif (($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")) {
      $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++;
            }
          }
        }
        if (($events_week < 1) && ($i == 6)) {
          $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!

Related posts:

  1. Two simple ways to recover photos from a broken SD card I just got back from a 18 day trip to...
  2. Dynamic CSS/JS/HTML in Template Toolkit wrappers I’ve been asked about this a few times on #tt,...
  3. Podcasts from Ravi Zacharias Jennifer and I participated in a small group at Truman...
  4. Simple flashcards using JQuery I wanted to create some flashcards for my Jesus and...

4 Responses to “Extracting the next 7 days from phpiCalendar to simple HTML


  • Matt Register
    October 11th, 2006 11:29
    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

  • Ted Carnahan
    October 11th, 2006 17:16
    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.

  • Waller Alexander
    October 12th, 2006 10:31
    3

    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.

  • Ted Carnahan
    October 12th, 2006 20:50
    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