University of Southern California

ITS Web Services


Event Output


About simple feeds

Many of our users need a simple way to include HTML and RSS out from their own and the USC Public Events calendar. They aren’t looking for custom calendar integration in a website. To better serve these needs Web Services provides a simple feeds interface to eo2 (i.e. Events Output version 2). This feeds service currently provide two layouts of HTML as well as a general purpose RSS output. The links in the resulting HTML/RSS link back to either the USC Public Events Calendar or a generic Events calendar layout. If you need a higher degree of content control or closer sight integration then we recommend our XML or JSON api for the Events Output system.

Available formats

Current we have a number of generic feed formats available. The linked example uses the USC Public events calendar. If you replace “32” with a different calendar id then you’ll see that calendar’s events in the format requested.

  1. 2col – An HTML block with simple div tags with events paired as two columns1.
  2. arts – An HTML block surrounded by a paragraph tag. Each event is in its own div. No images, just title, link, summary, date.
  3. cal_grid – An HTML calendar grid of events with dates of events highlighted
  4. event_list – An HTML UL list of events
  5. home_cal – An HTML list of three events with the first event having a featured image if available
  6. home_list – A simple HTML list of events using div tags
  7. hp2 – A simple HTML block of divs and spans. No images, just title, summary and date.
  8. list – A variation of the HTML UL list of events
  9. list2br – Single line HTML BLOCK with events separated by BR tags, includes – title, link and date of events.
  10. list3 – A list of three events in HTML using divs for markup
  11. listbr – Single line HTML BLOCK with events separated by a signle BR tag, includes – title, link and date of events.
  12. listp – Sinple line HTML BLOCK with events separated by a P tag. Includes title, link, and date of events.
  13. rssRSS feed of events
  14. thumb_list – An HTML table of events with thumbnail images if available
  1. thumb2_list – A list of events with thumbnails using div tags

Technical notes

The eo2 feeds interface is built using the view model controller design pattern. Three core classes – model/Model.php, model/View.php, model/Controller.php; a small handful support classes – model/App.php, model/SQLDB.php, model/Transform.php; and single feeds model – model/Feeds.php. The Feeds model maps the existing calapi.php services into the simple feeds interface. The resulting content is then rendered with the appropriate view found in views/ folder (e.g. views/event_list.php, views/home_list.php, views/rss.php). The URI structure to use this simple service is ID] followed by any optional modifiers. E.g.

Like wise event_list view also works the same way E.g.

How to use it

PHP configured to allow URL includes for remote content

If your web site wants to include the upcoming three events from Theater you would use a code fragment like —

<?php

include("http://web-app.usc.edu/ws/eo2/feeds/event_list/32/category/Theater/limit/3");
?>

PHP configured to use CURL for remote content

If your web server supports URL includes. If you are using CURL with PHP to this your web page would include a fragment like —

<?php

$events_feed = 'http://web-app.usc.edu/ws/eo2/feeds/event_list/32/category/Theater/limit/3';
$request = curl_init();
curl_setopt($request, CURLOPT_URL, $events_feed);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
$events = curl_exec($request);
curl_errno($request) ? print(curl_error($request)) : "";
curl_close($request); 
print($events);

?>

Here is a variation by Tim Wright which uses on output buffer with CURL modifies some formatting with strip_tags() and returns a list of upcoming events or nothing at all if no events are available.

<?php

function displayEvents($events_location){ 
  $creq = curl_init();
  curl_setopt($creq, CURLOPT_URL, $events_location); 
  ob_start();// start the output buffer
  curl_exec($creq);// print the curl resource to the buffer
  $curlPage = ob_get_contents(); //get the contents of the buffer
  ob_end_clean(); // end buffering
  $nohtml =(strip_tags($curlPage, "&lt;a&gt;, &lt;strong&gt;"));
  $output = str_replace("&amp;nbsp;", "", $nohtml);
  if (strpos($output,'No upcoming events') === false) {
    echo '&lt;h3&gt;Upcoming Events&lt;h3&gt;';
    echo '&lt;p class="calendar-event"&gt;'.$output.'&lt;p&gt;';
  }
  if (curl_errno($creq)) { 
    print curl_error($creq); 
  } else { 
    curl_close($creq); 
  }
}
/* Calling the function: */
displayEvents('http://web-app.usc.edu/ws/eo2/feeds/event_list/32');

?>

Leveraging JSON feeds directly

This example if from Tim Wright. He needed to display a list of events WITHOUT the category of Exhibits. He took two feeds, did a diff between them then assemble an hCal representation for display.

<?php


/*display all non-exhibits via JSON*/
function events_today(){ $all_url = ‘http://web-app.usc.edu/ws/eo2/json/156/list/today’; $exhibit_url = ‘http://web-app.usc.edu/ws/eo2/json/156/list/today/category/exhibits’; $request = curl_init(); curl_setopt($request, CURLOPT_URL, $all_url); curl_setopt($request, CURLOPT_RETURNTRANSFER, true); $all_today = curl_exec($request); curl_errno($request) ? print(curl_error($request)) : “”; curl_setopt($request, CURLOPT_URL, $exhibit_url); curl_setopt($request, CURLOPT_RETURNTRANSFER, true); $exhibit_today = curl_exec($request); curl_errno($request) ? print(curl_error($request)) : “”; curl_close($request); $all_events = json_decode($all_today,true); unset($all_events[‘request’]); $exhibit_events = json_decode($exhibit_today,true); unset($exhibit_events[‘request’]); unset($exhibit_events[‘category’]); // Get the id’s for the exhibit events $exhibit_ids = array(); foreach ($exhibit_events as $event) { $exhibit_ids[] = $event[‘id’]; } // loop and skip exhibits foreach($all_events as $event) { $eventtitle = strtolower(str_replace(’ ‘, ‘-’, $event[‘title’])); if (isset($event[‘id’]) && in_array($event[‘id’],$exhibit_ids) === false) { echo ‘<ul class=“vevent” id=”’.$eventtitle.’”>’ . “\n”; echo ‘<li class=“img”><img src=“http://web-app.usc.edu/ecal/’.$event[‘image_thumb’].’” alt=”“/>’ . “\n”; echo ‘<li class=“summary”><a href=“http://web-app.usc.edu/ws/eo2/calendar/156/event/’.$event[‘id’].’” class=“url”>’.$event[‘title’].’</a></li>’ . “\n”; echo ‘<li class=“dtstart”>’.$event[‘spoken’].’</li>’ . “\n”; echo ‘<li class=“location”>’.$event[‘location’].’</li>’ . “\n”; echo ‘<li class=“description”>’.$event[‘summary’].’ <a href=“http://web-app.usc.edu/ws/eo2/calendar/156/event/’.$event[‘id’].’” class=“url”>read more</a></li>’ . “\n”; echo “</ul>” . “\n”; } }
}

/*display any JSON event feed in hCal format*/
function events_feed($events_feed){ $request = curl_init(); curl_setopt($request, CURLOPT_URL, $events_feed); curl_setopt($request, CURLOPT_RETURNTRANSFER, true); $exhibits = curl_exec($request); curl_errno($request) ? print(curl_error($request)) : “”; curl_close($request); $output_data = json_decode($exhibits,true); unset($output_data[‘request’]); unset($output_data[‘category’]); foreach($output_data as $exhibit) { $eventtitle = strtolower(str_replace(’ ‘, ‘-’, $exhibit[‘title’])); echo ‘<ul class=“vevent” id=”’.$eventtitle.’”>’ . “\n”; echo ‘<li class=“img”><img src=“http://web-app.usc.edu/ecal/’.$exhibit[‘image_thumb’].’” alt=”“/>’ . “\n”; echo ‘<li class=“summary”><a href=“http://web-app.usc.edu/ws/eo2/calendar/156/event/’.$exhibit[‘id’].’” class=“url”>’.$exhibit[‘title’].’</a></li>’ . “\n”; echo ‘<li class=“dtstart”>’.$exhibit[‘spoken’].’</li>’ . “\n”; echo ‘<li class=“location”>’.$exhibit[‘location’].’</li>’ . “\n”; echo ‘<li class=“description”>’.$exhibit[‘summary’].’ <a href=“http://web-app.usc.edu/ws/eo2/calendar/156/event/’.$exhibit[‘id’].’” class=“url”>read more</a></li>’ . “\n”; echo “</ul>” . “\n”; }
}

/*display upcoming calendar events, if there are any to display*/
function displayEvents($events_location){ $creq = curl_init(); curl_setopt($creq, CURLOPT_URL, $events_location); ob_start();// start the output buffer curl_exec($creq);// print the curl resource to the buffer $curlPage = ob_get_contents(); //get the contents of the buffer ob_end_clean(); // end buffering $nohtml =(strip_tags($curlPage, “<a>, <strong>”)); $output = str_replace(” ”, “”, $nohtml); if (strpos($output,‘No upcoming events’) === false) { echo ‘<h3>Upcoming Events</h3>’; echo ‘<p class=“calendar-event”>’.$output.’</p>’; } if (curl_errno($creq)) { print curl_error($creq); } else { curl_close($creq); }
}

?>

1 Format ported from the old Lambda calendar design