Beispiel #1
0
 /**
  * @brief generates the output for an event which will be readable for our js
  * @param (mixed) $event - event object / array
  * @param (int) $start - DateTime object of start
  * @param (int) $end - DateTime object of end
  * @return (array) $output - readable output
  */
 public static function generateEventOutput(array $event, $start, $end, $list = false)
 {
     if (!isset($event['calendardata']) && !isset($event['vevent'])) {
         return false;
     }
     if (!isset($event['calendardata']) && isset($event['vevent'])) {
         $event['calendardata'] = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:ownCloud's Internal iCal System\n" . $event['vevent']->serialize() . "END:VCALENDAR";
     }
     try {
         $object = VObject::parse($event['calendardata']);
         if (!$object) {
             \OCP\Util::writeLog(self::$appname, __METHOD__ . ' Error parsing event: ' . print_r($event, true), \OCP\Util::DEBUG);
             return array();
         }
         $output = array();
         if ($object->name === 'VEVENT') {
             $vevent = $object;
         } elseif (isset($object->VEVENT)) {
             $vevent = $object->VEVENT;
         } else {
             \OCP\Util::writeLog(self::$appname, __METHOD__ . ' Object contains not event: ' . print_r($event, true), \OCP\Util::DEBUG);
             return $output;
         }
         $id = $event['id'];
         $SUMMARY = !is_null($vevent->SUMMARY) && $vevent->SUMMARY->getValue() != '' ? strtr($vevent->SUMMARY->getValue(), array('\\,' => ',', '\\;' => ';')) : (string) self::$l10n->t('unnamed');
         if ($event['summary'] != '') {
             $SUMMARY = $event['summary'];
         }
         if (Object::getowner($id) !== \OCP\USER::getUser()) {
             // do not show events with private or unknown access class
             // \OCP\Util::writeLog('calendar','Sharee ID: ->'.$event['calendarid'].':'.$event['summary'], \OCP\Util::DEBUG);
             if (isset($vevent->CLASS) && $vevent->CLASS->getValue() === 'CONFIDENTIAL') {
                 $SUMMARY = (string) self::$l10n->t('Busy');
             }
             if (isset($vevent->CLASS) && ($vevent->CLASS->getValue() === 'PRIVATE' || $vevent->CLASS->getValue() === '')) {
                 return $output;
             }
             $object = Object::cleanByAccessClass($id, $object);
         }
         $event['orgevent'] = '';
         if (array_key_exists('org_objid', $event) && $event['org_objid'] > 0) {
             $event['orgevent'] = array('calendarcolor' => '#000');
         }
         $event['isalarm'] = false;
         if (isset($vevent->VALARM)) {
             $event['isalarm'] = true;
         }
         $event['privat'] = false;
         if (isset($vevent->CLASS) && $vevent->CLASS->getValue() === 'PRIVATE') {
             $event['privat'] = 'private';
         }
         if (isset($vevent->CLASS) && $vevent->CLASS->getValue() === 'CONFIDENTIAL') {
             $event['privat'] = 'confidential';
         }
         $allday = $vevent->DTSTART->getValueType() == 'DATE' ? true : false;
         $last_modified = @$vevent->__get('LAST-MODIFIED');
         $calid = '';
         if (array_key_exists('calendarid', $event)) {
             $calid = $event['calendarid'];
         }
         /*
         $eventPerm = '';
         
         if (array_key_exists('permissions', $event)) {
         	$eventPerm = Calendar::permissionReader($event['permissions']);
         }
         
         $location = (!is_null($vevent -> LOCATION) && $vevent -> LOCATION -> getValue() != '') ? $vevent -> getAsString('LOCATION') : '';
         */
         $bDay = false;
         if (array_key_exists('bday', $event)) {
             $bDay = $event['bday'];
         }
         $isEventShared = false;
         if (isset($event['shared']) && $event['shared'] === 1) {
             $isEventShared = $event['shared'];
         }
         $lastmodified = $last_modified ? $last_modified->getDateTime()->format('U') : 0;
         $staticoutput = array('id' => (int) $event['id'], 'title' => $SUMMARY, 'lastmodified' => $lastmodified, 'categories' => $vevent->getAsArray('CATEGORIES'), 'calendarid' => (int) $calid, 'bday' => $bDay, 'shared' => $isEventShared, 'privat' => $event['privat'], 'isrepeating' => false, 'isalarm' => $event['isalarm'], 'orgevent' => $event['orgevent'], 'allDay' => $allday);
         if (Object::isrepeating($id) && Repeat::is_cached_inperiod($event['id'], $start, $end)) {
             $cachedinperiod = Repeat::get_inperiod($id, $start, $end);
             foreach ($cachedinperiod as $cachedevent) {
                 $dynamicoutput = array();
                 if ($allday) {
                     $start_dt = new \DateTime($cachedevent['startdate'], new \DateTimeZone('UTC'));
                     $end_dt = new \DateTime($cachedevent['enddate'], new \DateTimeZone('UTC'));
                     $dynamicoutput['start'] = $start_dt->format('Y-m-d');
                     $dynamicoutput['end'] = $end_dt->format('Y-m-d');
                     $dynamicoutput['startlist'] = $start_dt->format('Y/m/d');
                     $dynamicoutput['endlist'] = $end_dt->format('Y/m/d');
                 } else {
                     $start_dt = new \DateTime($cachedevent['startdate'], new \DateTimeZone('UTC'));
                     $end_dt = new \DateTime($cachedevent['enddate'], new \DateTimeZone('UTC'));
                     $start_dt->setTimezone(new \DateTimeZone(self::$tz));
                     $end_dt->setTimezone(new \DateTimeZone(self::$tz));
                     $dynamicoutput['start'] = $start_dt->format('Y-m-d H:i:s');
                     $dynamicoutput['end'] = $end_dt->format('Y-m-d H:i:s');
                     $dynamicoutput['startlist'] = $start_dt->format('Y/m/d H:i:s');
                     $dynamicoutput['endlist'] = $end_dt->format('Y/m/d H:i:s');
                 }
                 $dynamicoutput['isrepeating'] = true;
                 $output[] = array_merge($staticoutput, $dynamicoutput);
             }
         } else {
             if (Object::isrepeating($id) || $event['repeating'] == 1) {
                 $object->expand($start, $end);
             }
             foreach ($object->getComponents() as $singleevent) {
                 if (!$singleevent instanceof \Sabre\VObject\Component\VEvent) {
                     continue;
                 }
                 $dynamicoutput = Object::generateStartEndDate($singleevent->DTSTART, Object::getDTEndFromVEvent($singleevent), $allday, self::$tz);
                 $output[] = array_merge($staticoutput, $dynamicoutput);
             }
         }
         return $output;
     } catch (\Exception $e) {
         $uid = 'unknown';
         if (isset($event['uri'])) {
             $uid = $event['uri'];
         }
         \OCP\Util::writeLog(self::$appname, 'Event (' . $uid . ') contains invalid data!', \OCP\Util::WARN);
     }
 }