CMS  Version 3.9
i_calendar_manager.inc
Go to the documentation of this file.
1 <?php
23 class iCalendarData extends DataItem
24 {
25  var $fields = array(
26  "begin_calendar" => String,
27  "prodid" => String,
28  "version" => String,
29  "method" => String,
30  "begin_timezone" => String,
31  "tzid" => String,
32  "begin_standard" => String,
33  "standard_start" => String,
34  "standard_offset" => String,
35  "standard_dst_offset" => String,
36  "standard_rrule" => String,
37  "standard_name" => String,
38  "end_standard" => String,
39  "begin_daylight" => String,
40  "daylight_start" => String,
41  "daylight_offset" => String,
42  "daylight_dst_offset" => String,
43  "daylight_rrule" => String,
44  "daylight_name" => String,
45  "end_daylight" => String,
46  "end_timezone" => String,
47  "begin_event" => String,
48  "organizer" => String,
49  "attendee" => String,
50  "dtstart" => String,
51  "dtend" => String,
52  "location" => String,
53  "transp" => String,
54  "event_status" => String,
55  "display_status" => String,
56  "uid" => String,
57  "sequence" => Number,
58  "dtstamp" => String,
59  "last_modified" => String,
60  "description" => HTML,
61  "summary" => String,
62  "priority" => Number,
63  "class" => String,
64  "end_event" => String,
65  "end_calendar" => String,
66  );
67 
68  var $fieldAliases = array(
69  "begin_calendar" => "BEGIN",
70  "begin_event" => "BEGIN",
71  "event_status" => "STATUS",
72  "display_status" => "X-MICROSOFT-CDO-INTENDEDSTATUS",
73  "last_modified" => "LAST-MODIFIED",
74  "end_event" => "END",
75  "end_calendar" => "END",
76 
77  "begin_timezone" => "BEGIN",
78 
79  "begin_standard" => "BEGIN",
80  "standard_start" => "DTSTART",
81  "standard_offset" => "TZOFFSETFROM",
82  "standard_dst_offset" => "TZOFFSETTO",
83  "standard_rrule" => "RRULE",
84  "standard_name" => "TZNAME",
85  "end_standard" => "END",
86 
87  "begin_daylight" => "BEGIN",
88  "daylight_start" => "DTSTART",
89  "daylight_offset" => "TZOFFSETFROM",
90  "daylight_dst_offset" => "TZOFFSETTO",
91  "daylight_rrule" => "RRULE",
92  "daylight_name" => "TZNAME",
93  "end_daylight" => "END",
94 
95  "end_timezone" => "END",
96  );
97 
98  function __construct()
99  {
100  $this->primary_key = "icalendar_uid";
101  $this->table = "icalendar";
102 
103  $this->DataItem(func_get_args());
104  }
105 }
106 
107 
127 {
128  var $replyTo;
130  var $mailTo;
132  var $rsvp = true;
134  var $required = false;
135  var $invitees = array();
136  var $data;
137  var $aliases = array();
138 
158  function __construct($id, $start, $end, $title, $description = "", $location = "", $sequence_id = 0, $timeZone = null)
159  {
160  global $config;
161 
162  $this->data = new iCalendarData();
163  $this->data->set("summary", $title);
164  $this->data->set("description", $description);
165  $this->data->set("location", $location);
166 
167  // The uid must be globally unique thus is includes the http_host
168  // and the event id.
169  $uid = $id . $config["http_host"];
170  $this->data->set("uid", $uid);
171 
172  $this->data->set("sequence", $sequence_id);
173 
174  $this->data->set("dtstart", $start);
175  $this->data->set("dtend", $end);
176 
177  $today = new DateTime(now());
178  $this->data->set("dtstamp", $today->format('Ymd\THis'));
179 
180  $this->data->filter = new ExclusionFilter("last_modified", "standard_rrule", "daylight_rrule");
181  // is last modified needed?
182  //$this->data->last_modified = $today;
183 
184  $this->data->set("priority", 5);
185  $this->data->set("class", "PUBLIC");
186 
187  $this->data->set("begin_calendar", "VCALENDAR");
188  $this->data->set("prodid", "-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN");
189  $this->data->set("version", "2.0");
190  $this->data->set("begin_event", "VEVENT");
191  $this->data->set("transp", "OPAQUE");
192  $this->data->set("display_status", "BUSY");
193  $this->data->set("end_event", "VEVENT");
194  $this->data->set("end_calendar", "VCALENDAR");
195  $this->data->set("method", "REQUEST");
196  $this->data->set("event_status", "CONFIRMED");
197 
198  $this->setEventDates($start, $end, $timeZone);
199 
200  $this->setAliases();
201  }
202 
203  function setAliases()
204  {
205  $aliases = $this->data->getFieldAliases();
206  // Read in default alias definitions from DataItem
207  if ($aliases)
208  {
209  foreach($aliases as $field => $alias)
210  {
211  $this->aliases[$field] = $alias;
212  }
213  }
214  }
215 
221  function setEventDates($start, $end, $timeZone)
222  {
223  $startObj = new DateTime($start);
224  $endObj = new DateTime($end);
225 
226  if($this->isAllDay($start) && $this->isAllDay($end))
227  {
228  $start_value = ";VALUE=DATE:" . $startObj->format("Ymd");
229  $end_value = ";VALUE=DATE:" . $endObj->format("Ymd");
230  }
231  else
232  {
233  $start_value = $startObj->format('Ymd\THis');
234  $end_value = $endObj->format('Ymd\THis');
235  }
236 
237  if($timeZone)
238  {
239  $this->setTimeZone($timeZone, $start_value);
240  $this->data->set("dtstart", ";TZID=" . $timeZone->time_zone_name . ":". $start_value);
241  $this->data->set("dtend", ";TZID=" . $timeZone->time_zone_name . ":". $end_value);
242  }
243  else
244  {
245  $this->excludeTimeZoneFields();
246  $this->data->set("dtstart", $start_value);
247  $this->data->set("dtend", $end_value);
248  }
249  }
250 
259  function setTimeZone($timeZone, $start_value)
260  {
261  $this->data->set("begin_timezone", "VTIMEZONE");
262  $this->data->set("begin_standard", "STANDARD");
263  $this->data->set("end_standard", "STANDARD");
264  $this->data->set("begin_daylight", "DAYLIGHT");
265  $this->data->set("end_daylight", "DAYLIGHT");
266  $this->data->set("end_timezone", "VTIMEZONE");
267 
268  $this->data->set("tzid", $timeZone->get("time_zone_name"));
269 
270  $standard_offset = $this->formatTimeZoneHours($timeZone->standard_offset);
271  $daylight_offset = $this->formatTimeZoneHours($timeZone->daylight_offset);
272 
273  $this->data->set("standard_name", "EST");
274  $this->data->set("daylight_name", "EDT");
275  $this->data->set("standard_offset", $standard_offset);
276  $this->data->set("standard_dst_offset", $daylight_offset);
277  $this->data->set("daylight_offset", $daylight_offset);
278  $this->data->set("daylight_dst_offset", $standard_offset);
279 
280  $this->data->set("standard_start", $start_value);
281  $this->data->set("daylight_start", $start_value);
282  }
283 
298  {
299  $neg = false;
300  if($offset < 0)
301  {
302  $neg = true;
303  $offset = abs($offset);
304  }
305 
306  $hour = $offset;
307  $min = "00";
308  if(!is_int($offset))
309  {
310  $hour = floor($offset);
311  $min = "30";
312  }
313 
314  $out = str_pad($hour, 2, STR_PAD_LEFT) . $min;
315 
316  if($neg)
317  {
318  $out = "-" . $out;
319  }
320 
321  return $out;
322  }
323 
329  {
330  $filter = $this->data->getFilter();
331  if(!$filter)
332  {
333  $filter = new ExclusionFilter();
334  }
335 
336  $fields = $this->data->getFields();
337  $tz_field = false;
338  foreach($fields as $name => $type)
339  {
340  if($name == "begin_timezone")
341  {
342  $tz_field = true;
343  }
344  if($tz_field)
345  {
346  $filter->excludeField($name);
347  }
348  if($name == "end_timezone")
349  {
350  $tz_field = false;
351  }
352  }
353  }
354 
355  function isAllDay($date)
356  {
357  if(preg_match("/00:00:00$/", $date))
358  {
359  return true;
360  }
361 
362  return false;
363  }
364 
366  {
367  //ATTACH;FMTTYPE=image/jpeg:http://domain.com/images/bastille.jpg
368  }
369 
371  {
372  $this->replyTo = $replyTo;
373  $this->replyToName = $replyToName;
374  }
375 
383  {
384  $this->mailTo = $mailTo;;
385  }
386 
388  {
389  $this->attendeeName = $name;
390  }
391 
402  function formatOrganizer()
403  {
404  if($this->replyToName)
405  {
406  $organizer .= ";CN={$this->replyToName}";
407  }
408 
409  $organizer .= ":MAILTO:{$this->replyTo}";
410 
411  return $organizer;
412  }
413 
423  function formatAttendee()
424  {
425  if($this->required)
426  {
427  $attendee .= ";ROLE=REQ-PARTICIPANT";
428  }
429 
430  if($this->attendeeStatus)
431  {
432  $attendee .= ";PARTSTAT={$this->attendeeStatus}";
433  }
434 
435  if($this->rsvp)
436  {
437  $attendee .= ";RSVP=true";
438  }
439 
440  if($this->attendeeName)
441  {
442  $attendee .= ";CN={$this->attendeeName}";
443  }
444 
445  $attendee .= ":MAILTO:{$this->mailTo}";
446 
447  return $attendee;
448  }
449 
484  function format()
485  {
486  $this->data->organizer = $this->formatOrganizer();
487  $this->data->attendee = $this->formatAttendee();
488 
489  $filter = $this->data->getFilter();
490  $fields = $this->data->getFields();
491  foreach (array_keys($fields) as $field)
492  {
493  if ($field != $pk && !($filter && $filter->isExcluded($field)))
494  {
495  $label = strtoupper($field);
496  if(array_key_exists($field, $this->aliases))
497  {
498  $label = $this->aliases[$field];
499  }
500 
501  $value = $this->data->$field;
502  if(!preg_match("/^;|:/", $value))
503  {
504  $value = ":". $value;
505  }
506  $properties[] = $label . $value;
507  }
508  }
509 
510  $out = "\r\n";
511  $out .= implode("\n", $properties);
512  $out .= "\r\n";
513 
514  return $out;
515  }
516 }?>
$out
Definition: page.inc:66
if(! $page) $path
Definition: page.inc:57
$filter
Definition: update.inc:44
$name
Definition: upload.inc:54
Dummy datamodel to helper manage the calendar data values.
Note: we may wish to add someting like this to description:
$required
ROLE=REQ-PARTICIPANT if required to attend.
$rsvp
organizer wants reply
$attendeeStatus
PARSTAT=TENTATIVE, PARSTAT=NEEDS-ACTION.
$replyTo
organizer email set in EmailHandler
$aliases
field aliases or labels
formatOrganizer()
We wait until final formatting of the iCalendar data to set the organizer properties because values c...
setEventDates($start, $end, $timeZone)
For all day events: DTSTART;VALUE=DATE:20100101 DTEND;VALUE=DATE:20100101.
formatAttendee()
Given all the settings applied to vars, build the ATTENDEE property to be used in the calendar invita...
setOrganizer($replyTo, $replyToName="")
$invitees
optionally show others invited to event
format()
Given the icalendar data values and the var settings, format the iCalendar data into a list of proper...
$replyToName
organizer name set in EmailHandler
$mailTo
Attendee email address.
excludeTimeZoneFields()
If no time zone provided, exclude all fields between begin_timezone through end_timezone.
__construct($id, $start, $end, $title, $description="", $location="", $sequence_id=0, $timeZone=null)
The iCalendarManager obj is typically instantiated through the EventHandler for an event.
setAttendee($mailTo)
Called from EmailHandler to set the attendee email address.
$attendeeName
optionally include display name of recipient
setTimeZone($timeZone, $start_value)
If time zone is not provided, exlcude the time zone fields so they are not included in the output.
formatTimeZoneHours($offset)
Given the numeric time zone value (pos or neg), convert to hour format for iCalendar such as "-0700".
$date
Definition: event_list.inc:51
global $config
Definition: import.inc:4