Beispiel #1
0
<?php

require_once dirname(__FILE__) . '/../anewt.lib.php';
anewt_include('calendar');
$calendar = new AnewtCalendar();
$event = new AnewtCalendarEvent('Title');
$event->date_start = AnewtDateTime::parse_string('2009-01-01 12:00');
$event->date_end = AnewtDateTime::parse_string('2009-01-01 14:00');
$event->summary = 'This is the summary';
$event->location = 'This is the location';
$event->url = 'http://example.org/foo';
$event->uid = 'abc1234567890';
$calendar->add_event($event);
$event = new AnewtCalendarEvent('Another event', AnewtDateTime::now());
$event->summary = "This is a multiline\nsummary";
$event->summary = "This is a multiline\ndescription";
$calendar->add_event($event);
$calendar->flush();
Beispiel #2
0
 /**
  * Render this calendar to a string in iCal format.
  *
  * \return
  *   String representation of this calendar
  */
 function render()
 {
     $out = array();
     $out[] = 'BEGIN:VCALENDAR';
     $out[] = 'VERSION:2.0';
     $out[] = sprintf('METHOD:%s', $this->method);
     $out[] = sprintf('PRODID:%s', $this->generator);
     $out[] = '';
     foreach ($this->events as $event) {
         $out[] = 'BEGIN:VEVENT';
         /* Generation date */
         $out[] = sprintf('DTSTAMP;VALUE=DATE:%s', AnewtDateTime::iso8601_compact(AnewtDateTime::now()));
         /* Summary and description */
         assert('!is_null($event->summary)');
         $description = $event->description;
         if (is_null($description)) {
             $description = $event->summary;
         }
         $out[] = sprintf('SUMMARY:%s', AnewtCalendar::escape_string($event->summary, false));
         $out[] = sprintf('DESCRIPTION:%s', AnewtCalendar::escape_string($description, true));
         /* Unique ID */
         $uid = $event->uid;
         if (is_null($uid)) {
             /* Generate a unique id */
             $uid = strtoupper(sprintf('%s-%s', md5($event->summary), md5(AnewtDateTime::iso8601_compact($event->date_start))));
         }
         $out[] = sprintf('UID:%s', $uid);
         /* Dates */
         assert('$event->date_start instanceof AnewtDateTimeAtom');
         $datestart_str = $event->all_day ? AnewtDateTime::iso8601_date_compact($event->date_start) : AnewtDateTime::iso8601_compact($event->date_start);
         /* With time */
         $out[] = sprintf('DTSTART;VALUE=DATE:%s', $datestart_str);
         if (!is_null($event->date_end)) {
             assert('$event->date_end instanceof AnewtDateTimeAtom');
             $date_end_str = $event->all_day ? AnewtDateTime::iso8601_date_compact($event->date_end) : AnewtDateTime::iso8601_compact($event->date_end);
             /* With time */
             $out[] = sprintf('DTEND;VALUE=DATE:%s', $date_end_str);
         }
         $out[] = sprintf('TRANSP:%s', $event->transparent ? 'TRANSPARENT' : 'OPAQUE');
         /* Misc  */
         if (!is_null($event->location)) {
             $out[] = sprintf('LOCATION:%s', $event->location);
         }
         if (!is_null($event->url)) {
             $out[] = sprintf('URL:%s', $event->url);
         }
         $out[] = 'END:VEVENT';
         $out[] = '';
     }
     $out[] = 'END:VCALENDAR';
     return implode(CRLF, $out);
 }