<?php
/**
* parse.php: example of parsing a file using PhpiCalLib
*
* @copyright Copyright (C) 2008 Nigel Swinson, hide@address.com
* @author Nigel Swinson
* @package PhpiCalLib
* @version 1.0
*/
require_once '../icalendar.php';
// Create the object
$iCalFile = new PhpiCalLib_iCalendar();
try {
// Try to parse the file
$iCalFile->FromFile('parse.ics');
} catch (PhpiCalLib_Exception $E) {
// Perhaps catch errors and process differently?
throw $E;
}
?>
<html>
<body>
<?
$aComponents = $iCalFile->GetComponents();
printf('<p>Found %d components in <a href="parse.ics">parse.ics</a>:</p>', count($aComponents));
if (count($aComponents)) {
foreach ($aComponents as $Component) {
?>
<table>
<tr>
<td>
<pre><?
echo $Component->ToString();
//echo htmlspecialchars(file_get_contents('parse.ics'));
?>
</pre>
</td>
<td valign="top">
<?
printf("<p>%s component</p>", $Component->GetName());
if ($Component->GetType() == PHPICALLIB_COMPONENT_VEVENT) {
$aProperties = array();
// Extract it's summary
$Summary = $Component->GetProperty(PHPICALLIB_PROPERTY_SUMMARY);
if ($Summary) {
$aProperties[] = sprintf("Summary: %s", $Summary->GetTextValue());
}
// Start time
$Start = $Component->GetProperty(PHPICALLIB_PROPERTY_DTSTART);
$StartTime = $Start->ToTimeStamp();
if ($Component->AllDay()) {
$aProperties[] = sprintf("All day on: %s", gmdate("d M Y",$StartTime));
} else {
$aProperties[] = sprintf("Starting at: %s", gmdate("d M Y H:i:s",$StartTime));
}
// And description.
$Description = $Component->GetProperty(PHPICALLIB_PROPERTY_DESCRIPTION);
if ($Description) {
$aProperties[] = sprintf("Description: <blockquote>%s</blockquote>", str_replace("\n", "<br>", $Description->GetTextValue()));
}
// Echo the properties in a list.
echo "<ul><li>";
echo implode("</li>\n<li>", $aProperties);
echo "</li></ul>";
}
?>
</td>
</tr>
</table>
<?
}
}
?>
</body>
</html>