5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2013 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
25 public function __construct($ID, $StartDate, $EndDate, $AllDay, $TimeZoneID=NULL)
27 # generate the UID and add it to the document
30 # need to use the time zone parameter if a time zone ID is given
31 $DateParameters = is_null($TimeZoneID) ? array() : array(
"TZID" => $TimeZoneID);
35 # need to offset the end date by one day so that the range spans the
36 # entire 24 hours of the last day
37 $EndDate = date(
"Y-m-d", strtotime($EndDate)+86400);
39 $this->
AddDateProperty(
"VEVENT",
"DTSTART", $StartDate, $DateParameters);
71 # save the summary for use in generating the file name
72 $this->Summary = $Value;
92 # don't add the property if there are no categories to add
93 if (!count($Categories))
101 implode(
",", array_map(array($this,
"EscapeTextValue"), $Categories)));
111 # don't add a blank URL
128 # construct the value for the property
129 $Value = floatval($Latitude) .
";" . floatval($Longitude);
131 # add the property to the list
151 # generate a timestamp and add it
153 $this->
AddProperty(
"VEVENT",
"DTSTAMP", $Timestamp);
155 # start the iCalendar definition
156 $Document =
"BEGIN:VCALENDAR\r\n";
159 $Document .=
"CALSCALE:GREGORIAN\r\n";
160 $Document .=
"PRODID:-//Internet Scout//CWIS//EN\r\n";
161 $Document .=
"VERSION:2.0\r\n";
164 foreach ($this->Properties as $Component =>
$Properties)
166 # don't add empty components
172 # begin the component definition
173 $Document .=
"BEGIN:" . $Component .
"\r\n";
175 # add each property line
176 foreach (
$Properties as $Property => $PropertyLine)
178 $Document .= $PropertyLine;
181 # end the component definition
182 $Document .=
"END:" . $Component .
"\r\n";
185 # end the iCalendar definition
186 $Document .=
"END:VCALENDAR\r\n";
188 # return the generated document
201 return self::GenerateFileNameFromSummary($this->Summary);
214 # just use the date/time if the summary isn't given
217 return date(
"Ymd-His") .
".ics";
220 # remove any HTML from the summary
223 # replace problematic characters for most filesystems
225 array(
"/",
"?",
"<",
">",
"\\",
":",
"*",
"|",
'"',
"^"),
229 # remove whitespace at the beginning and end
232 # make sure the name isn't too long because it can cause problems for
233 # some browsers and file systems
234 $Name = substr($Name, 0, 75);
236 # return the name plus extension
237 return $Name .
".ics";
248 $HTML = strip_tags($HTML);
250 # handle a few replacements separately because they aren't handled by
251 # html_entity_decode() or are replaced by a character that isn't ideal.
252 # string to replace => replacement
262 # do the first pass of replacements
263 $HTML = str_replace(array_keys($Replace), array_values($Replace), $HTML);
265 # do the final pass of replacements and return
266 return html_entity_decode($HTML);
281 protected function AddProperty($Component, $Property, $Value, array $Parameters=array())
283 # construct the property line
286 # fold the line if necessary and add the line ending sequence
289 # add the property line to the list of properties
290 $this->Properties[$Component][$Property] = $Line;
305 protected function AddTextProperty($Component, $Property, $Value, array $Parameters=array())
307 # don't add empty properties
332 protected function AddDateProperty($Component, $Property, $Value, array $Parameters=array())
338 array(
"VALUE" =>
"DATE") + $Parameters);
369 # escape most characters
370 $Value = preg_replace(
'/([\\;,])/',
"\\\\\\1", $Value);
373 $Value = preg_replace(
'/\n/',
"\\n", $Value);
386 # concatenate the date string, ID, and host name as in the spec
389 $UID .=
"@" . gethostname();
401 return date(
"Ymd", strtotime($Date));
411 return date(
"Ymd\THis", strtotime($DateTime));
421 return gmdate(
"Ymd\THis\Z", strtotime($DateTime));
433 # start the property string off with the property name
436 # add each property parameter, if any
437 foreach ($Parameters as $Parameter => $Value)
439 $String .=
";" . $Parameter .
"=" . $Value;
442 # add the colon separator and return
443 return $String .
":";
454 # split the line into chunks
455 $FoldedString = chunk_split($String, 75, $End);
457 # chunk_split() unnecessarily adds the line ending sequence to the end
458 # of the string, so remove it
459 $FoldedString = substr($FoldedString, 0, -strlen($End));
461 return $FoldedString;
471 "VJOURNAL" => array(),
472 "VFREEBUSY" => array(),
473 "VTIMEZONE" => array(),
474 "VALARM" => array());
GenerateUID($ID, $StartDate)
Generate a full UID from an event ID and start date.
FoldString($String, $End="\r\n ")
Fold a string so that lines are never longer than 75 characters.
$Summary
The summary property for the iCalendar document.
AddCategories(array $Categories)
Add the categories property to the iCalendar document.
AddDescription($Value)
Add the description property to the iCalendar document.
GenerateFileName()
Generate a file name for the iCalendar document.
EscapeTextValue($Value)
Escape a text value for inserting into a property line.
AddTextProperty($Component, $Property, $Value, array $Parameters=array())
Add a text property to the list.
Class to generate a simple iCalendar document.
GenerateDateTimeString($DateTime)
Generate a date/time string from a date parsable by strtotime().
AddCreated($Value)
Add the created property to the iCalendar document.
static GenerateFileNameFromSummary($Summary=NULL)
Create a file name for an iCalendar document using a given summary.
$Properties
The list of components and properties.
AddSummary($Value)
Add the summary property to the iCalendar document.
__construct($ID, $StartDate, $EndDate, $AllDay, $TimeZoneID=NULL)
Construct a basic iCalendar document.
GenerateDocument()
Generate the iCalendar document based on the current list of properties.
static TransformHTMLToPlainText($HTML)
Helper method to transform an HTML string to plain text.
AddURL($Value)
Add the URL property to the iCalendar document.
AddDateProperty($Component, $Property, $Value, array $Parameters=array())
Add a date property to the list.
AddLocation($Value)
Add the location property to the iCalendar document.
GeneratePropertyString($Property, array $Parameters=array())
Generate a property string (property + parameters + ":").
AddProperty($Component, $Property, $Value, array $Parameters=array())
Add a generic property, i.e., one whose value is already in the proper form.
AddGeographicPosition($Latitude, $Longitude)
Add the geographic position property to the iCalendar document.
GenerateUTCDateTimeString($DateTime)
Generate a UTC date/time string from a date parsable by strtotime().
AddDateTimeProperty($Component, $Property, $Value, array $Parameters=array())
Add a date/time property to the list.
GenerateDateString($Date)
Generate a date string from a date parsable by strtotime().