ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
EasyPeasyICS.php
Go to the documentation of this file.
1 <?php
21 {
26  protected $calendarName;
31  protected $events = array();
32 
37  public function __construct($calendarName = "")
38  {
39  $this->calendarName = $calendarName;
40  }
41 
52  public function addEvent($start, $end, $summary = '', $description = '', $url = '', $uid = '')
53  {
54  if (empty($uid)) {
55  $uid = md5(uniqid(mt_rand(), true)) . '@EasyPeasyICS';
56  }
57  $event = array(
58  'start' => gmdate('Ymd', $start) . 'T' . gmdate('His', $start) . 'Z',
59  'end' => gmdate('Ymd', $end) . 'T' . gmdate('His', $end) . 'Z',
60  'summary' => $summary,
61  'description' => $description,
62  'url' => $url,
63  'uid' => $uid
64  );
65  $this->events[] = $event;
66  return $event;
67  }
68 
72  public function getEvents()
73  {
74  return $this->events;
75  }
76 
80  public function clearEvents()
81  {
82  $this->events = array();
83  }
84 
89  public function getName()
90  {
91  return $this->calendarName;
92  }
93 
98  public function setName($name)
99  {
100  $this->calendarName = $name;
101  }
102 
108  public function render($output = true)
109  {
110  //Add header
111  $ics = 'BEGIN:VCALENDAR
112 METHOD:PUBLISH
113 VERSION:2.0
114 X-WR-CALNAME:' . $this->calendarName . '
115 PRODID:-//hacksw/handcal//NONSGML v1.0//EN';
116 
117  //Add events
118  foreach ($this->events as $event) {
119  $ics .= '
120 BEGIN:VEVENT
121 UID:' . $event['uid'] . '
122 DTSTAMP:' . gmdate('Ymd') . 'T' . gmdate('His') . 'Z
123 DTSTART:' . $event['start'] . '
124 DTEND:' . $event['end'] . '
125 SUMMARY:' . str_replace("\n", "\\n", $event['summary']) . '
126 DESCRIPTION:' . str_replace("\n", "\\n", $event['description']) . '
127 URL;VALUE=URI:' . $event['url'] . '
128 END:VEVENT';
129  }
130 
131  //Add footer
132  $ics .= '
133 END:VCALENDAR';
134 
135  if ($output) {
136  //Output
138  //Filename needs quoting if it contains spaces
139  if (strpos($filename, ' ') !== false) {
140  $filename = '"'.$filename.'"';
141  }
142  header('Content-type: text/calendar; charset=utf-8');
143  header('Content-Disposition: inline; filename=' . $filename . '.ics');
144  echo $ics;
145  }
146  return $ics;
147  }
148 }
addEvent($start, $end, $summary='', $description='', $url='', $uid='')
Add an event to this calendar.
$end
Definition: saml1-acs.php:18
render($output=true)
Render and optionally output a vcal string.
$summary
Definition: cron.php:24
getName()
Get the name of the calendar.
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
if($format !==null) $name
Definition: metadata.php:146
Add a drawing to the header
Definition: 04printing.php:69
setName($name)
Set the name of the calendar.
Create styles array
The data for the language used.
__construct($calendarName="")
Constructor.
clearEvents()
Clear all events.
$url