Example #1
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);
 }
Example #2
0
 /**
  * Return a string representing this event.
  *
  * \return
  *   String with iCalender data.
  */
 function to_ical()
 {
     $r = array();
     $r[] = 'BEGIN:VEVENT';
     /* Generation date */
     $r[] = sprintf('DTSTAMP;VALUE=DATE:%s', AnewtDateTime::iso8601_compact(AnewtDateTime::now()));
     /* Summary */
     $r[] = sprintf('SUMMARY:%s', $this->get('summary'));
     /* Description */
     if (!$this->is_set('description')) {
         $this->set('description', $this->get('summary'));
     }
     $r[] = sprintf('DESCRIPTION:%s', $this->get('description'));
     /* Unique ID */
     if (!$this->is_set('uid')) {
         /* Generate a unique id */
         $uid = strtoupper(sprintf('%s-%s', md5($this->get('summary')), md5(AnewtDateTime::iso8601_compact($this->get('datestart')))));
         $this->set('uid', $uid);
     }
     $r[] = sprintf('UID:%s', $this->get('uid'));
     /* All day event? */
     $all_day = $this->get('all-day');
     assert('is_bool($all_day)');
     /* Start date */
     $datestart = $this->get('datestart');
     $datestart_str = $all_day ? AnewtDateTime::iso8601_date_compact($datestart) : AnewtDateTime::iso8601_compact($datestart);
     /* with time */
     $r[] = sprintf('DTSTART;VALUE=DATE:%s', $datestart_str);
     /* End date */
     if ($this->is_set('dateend')) {
         $dateend = $this->get('dateend');
         assert('$dateend instanceof AnewtDateTimeAtom');
         $dateend_str = $all_day ? AnewtDateTime::iso8601_date_compact($dateend) : AnewtDateTime::iso8601_compact($dateend);
         /* with time */
         $r[] = sprintf('DTEND;VALUE=DATE:%s', $dateend_str);
     }
     /* Transparency */
     $transparent = $this->getdefault('transparent', false);
     assert('is_bool($transparent)');
     $r[] = sprintf('TRANSP:%s', $transparent ? 'TRANSPARENT' : 'OPAQUE');
     /* Location  */
     if ($this->is_set('location')) {
         $r[] = sprintf('LOCATION:%s', $this->get('location'));
     }
     /* URL  */
     if ($this->is_set('url')) {
         $r[] = sprintf('URL:%s', $this->get('url'));
     }
     $r[] = 'END:VEVENT';
     $r[] = '';
     return implode("\r\n", $r);
 }