HTTP/1.1 200 OK Date: Sat, 07 Nov 2009 13:20:13 GMT Server: Apache/2.2.13 (Unix) mod_ssl/2.2.13 OpenSSL/0.9.8b PHP/5.2.11 Last-Modified: Thu, 07 Apr 2005 20:00:25 GMT ETag: "65c0f-317-3f42e291d969c" Accept-Ranges: bytes Content-Length: 791 Connection: close Content-Type: text/plain IMSC [USC Integrated Media Systems Center]
University of Southern California


Calendar

(.*)(| />)}sU"; // betwixt the specified tags if($fullreturn) $tag_regex = "{<$tag ?(.*)(>| />)}sU"; preg_match_all($tag_regex, $text, $tag_matches, PREG_SET_ORDER); if(count($tag_matches)){ if($fullreturn){ // return the entire tag, if requested $content = $tag_matches[0][0]; } else { // otherwise, return just the content $content = $tag_matches[0][1]; } } else { return false; } return $content; } # storeParam() - extract content for an array of elements into an array of results function storeParams($paramarray,$text){ foreach($paramarray as $tag){ $PARAMS[$tag] = getParam($tag,$text); } if(count($PARAMS)){ return $PARAMS; } else { return false; } } # get Attribs() - extract attributes from a tag # (hard-coded for specific elements, since we know them) function getAttribs($text,$type){ # $attrib_regex = "{<([A-Za-z]*) ([A-Za-z]*)=\"?([^\"]*)\"?(>| />)}sU"; switch($type){ case "url": $attrib_regexURL = "{|>)}sU"; if(preg_match($attrib_regexURL,$text,$matcharray)){ return $matcharray[1]; } else { return false; } break; case "size": $attrib_regexSIZE = "{| />)}sU"; $attrib_regexCURRENT = "{current=\"?(\d*)\"?}s"; $attrib_regexMAX = "{max=\"?(\d*)\"?}s"; if(preg_match($attrib_regexSIZE,$text,$matcharray)){ if(preg_match($attrib_regexCURRENT,$matcharray[1],$attribs)){ $myattribs["current"] = $attribs[1]; } if(preg_match($attrib_regexMAX,$matcharray[1],$attribs)){ $myattribs["max"] = $attribs[1]; } return $myattribs; } else { return false; } break; } } # getItems() - loop through text and grab content from between # any instance of the specified tag function getItems($text,$tag="item"){ $tag_regex = "{<$tag>(.*)(| />)}sU"; preg_match_all($tag_regex, $text, $tag_matches, PREG_SET_ORDER); foreach($tag_matches as $mymatch){ $myarray[] = $mymatch[1]; } if(count($myarray)){ return $myarray; } else { return false; } } # convertZulu() - converts a Zulu timestamp (yyyymmddThhmmssZ) into a unix timestamp function convertZulu($timestring){ $_TIME["year"] = substr($timestring,0,4); $_TIME["month"] = substr($timestring,4,2); $_TIME["mday"] = substr($timestring,6,2); $_TIME["hour"] = substr($timestring,9,2); $_TIME["min"] = substr($timestring,11,2); $_TIME["sec"] = substr($timestring,13,2); $builddate = gmmktime("$_TIME[hour]","$_TIME[min]","$_TIME[sec]","$_TIME[month]","$_TIME[mday]","$_TIME[year]"); return $builddate; } # parseFeed() - parse a WebDev/xCal event feed, output a multi-dimensional array of values // see http://wdc.usc.edu/dtd/xcal-usc-events.dtd function parseFeed($feedurl){ $feedparams = array("title","link","description","webMaster","lastBuildDate"); $itemparams = array("uid","dtstamp","dtstart","dtend","summary","location","description","public","audience","categories"); if($fopen = fopen($feedurl,'r')){ // exists (can be opened for reading) $body = file_get_contents($feedurl,'r'); if(strlen($body) > 0){ // we got it $uptodate = false; $_TIME = false; // extract the feed's information $itempos = strpos($body,""); $channelinfo = substr($body,0,$itempos); $_RSS = storeParams($feedparams,$channelinfo); if($_RSS["description"]){ $_RSS["description"] = str_replace("","",$_RSS["description"]); } // figure out if there's any new content (inactive for now) /* if($_RSS["lastBuildDate"]){ $_RSS["lastBuildDate"] = convertZulu($_RSS["lastBuildDate"]); $builddate = mktime("$_TIME[hour]","$_TIME[min]","$_TIME[sec]","$_TIME[month]","$_TIME[mday]","$_TIME[year]"); // if($builddate < $row["updated"]) $uptodate = true; } */ if(!$uptodate){ $count = 1; // update the individual items, if needed $item_regex = "|(.*)|sU"; preg_match_all($item_regex, $body, $item_matches, PREG_SET_ORDER); foreach($item_matches as $item){ $uid = getParam("uid",$item[1]); $public = getParam("public",$item[1]); if(!$public) $public = "100"; if($uid && $public >= 90){ $_ITEMS[$count] = storeParams($itemparams,$item[1]); if($myurl = getParam("url",$item[1],1)){ $_ITEMS[$count]["url"] = getAttribs($myurl,"url"); unset($myurl); } if($mysize = getParam("size",$item[1],1)){ $_ITEMS[$count]["size"] = getAttribs($mysize,"size"); unset($mysize); } $_ITEMS[$count]["categories"] = getItems($_ITEMS[$count]["categories"]); $_ITEMS[$count]["audience"] = getItems($_ITEMS[$count]["audience"]); if($_ITEMS[$count]["dtstamp"]){ $_ITEMS[$count]["dtstamp"] = convertZulu($_ITEMS[$count]["dtstamp"]); } if($_ITEMS[$count]["dtstart"]){ $_ITEMS[$count]["dtstart"] = convertZulu($_ITEMS[$count]["dtstart"]); } if($_ITEMS[$count]["dtend"]){ $_ITEMS[$count]["dtend"] = convertZulu($_ITEMS[$count]["dtend"]); } if($_ITEMS[$count]["summary"]){ $_ITEMS[$count]["summary"] = str_replace("","",$_ITEMS[$count]["summary"]); } if($_ITEMS[$count]["description"]){ $_ITEMS[$count]["description"] = str_replace("","",$_ITEMS[$count]["description"]); $_ITEMS[$count]["description"] = html_entity_decode($_ITEMS[$count]["description"]); } } unset($uid); unset($public); $count++; } } } } // order items by start timestamp usort($_ITEMS, by_dtstart); // put channel info and event info into one big, ugly array for easy returning $return[0] = $_RSS; $return[1] = $_ITEMS; return $return; } /* DISPLAY ELEMENTS */ //check to see if a feed name has been passed in if (!isset($_GET['feed'])) { $feed = $defaultfeed; } else { $feed = $_GET['feed']; } if ($_GET['month']) { $month = $_GET['month']; $iframelink = "calendar_detail?month=" . $month; switch($month){ case 1: $curr_month="January"; break; case 2: $curr_month="February"; break; case 3: $curr_month="March"; break; case 4: $curr_month="April"; break; case 5: $curr_month="May"; break; case 6: $curr_month="June"; break; case 7: $curr_month="July"; break; case 8: $curr_month="August"; break; case 9: $curr_month="September"; break; case 10: $curr_month="October"; break; case 11: $curr_month="November"; break; case 12: $curr_month="December"; } } else { $month = date('m'); $iframelink = "calendar_detail.php"; switch($month){ case 1: $curr_month="January"; break; case 2: $curr_month="February"; break; case 3: $curr_month="March"; break; case 4: $curr_month="April"; break; case 5: $curr_month="May"; break; case 6: $curr_month="June"; break; case 7: $curr_month="July"; break; case 8: $curr_month="August"; break; case 9: $curr_month="September"; break; case 10: $curr_month="October"; break; case 11: $curr_month="November"; break; case 12: $curr_month="December"; } } if ($_GET['year']) { $year = $_GET['year']; $iframelink = $iframelink . "&year=" . $year; } $feedinfo = parseFeed($feed); // split the big, ugly array back up $channelinfo = $feedinfo[0]; $events = $feedinfo[1]; // display the feed's information echo "
"; echo "
"; echo "

Events for the month of $curr_month

"; //parse through the array foreach($events as $myevent){ //echo "month = " .$month . " date = " . date('m', $myevent["dtstart"]); if (date('m', $myevent["dtstart"]) == $month) { $url = $myevent["url"]; $date = date('M j, Y',$myevent["dtstart"]); $summary = $myevent["summary"]; echo "

$date - $summary
"; echo $myevent["description"] . "

"; } } ?>