예제 #1
0
 /**
  * @brief Gets the VCard as an OC_VObject
  * @returns The card or null if the card could not be parsed.
  */
 public static function getContactVCard($id)
 {
     $card = self::getContactObject($id);
     $vcard = OC_VObject::parse($card['carddata']);
     // Try to fix cards with missing 'N' field from pre ownCloud 4. Hot damn, this is ugly...
     if (!is_null($vcard) && !$vcard->__isset('N')) {
         $version = OCP\App::getAppVersion('contacts');
         if ($version >= 5) {
             OCP\Util::writeLog('contacts', 'OC_Contacts_App::getContactVCard. Deprecated check for missing N field', OCP\Util::DEBUG);
         }
         OCP\Util::writeLog('contacts', 'getContactVCard, Missing N field', OCP\Util::DEBUG);
         if ($vcard->__isset('FN')) {
             OCP\Util::writeLog('contacts', 'getContactVCard, found FN field: ' . $vcard->__get('FN'), OCP\Util::DEBUG);
             $n = implode(';', array_reverse(array_slice(explode(' ', $vcard->__get('FN')), 0, 2))) . ';;;';
             $vcard->setString('N', $n);
             OC_Contacts_VCard::edit($id, $vcard);
         } else {
             // Else just add an empty 'N' field :-P
             $vcard->setString('N', 'Unknown;Name;;;');
         }
     }
     if (!is_null($vcard) && !isset($vcard->REV)) {
         $rev = new DateTime('@' . $card['lastmodified']);
         $vcard->setString('REV', $rev->format(DateTime::W3C));
     }
     return $vcard;
 }
예제 #2
0
 /**
  * @brief generates the VEVENT/VTODO/VJOURNAL with UTC dates
  * @param array $event
  * @return string
  */
 private static function generateEvent($event)
 {
     $object = OC_VObject::parse($event['calendardata']);
     if (!$object) {
         return false;
     }
     $sharedAccessClassPermissions = OC_Calendar_Object::getAccessClassPermissions($object);
     if (OC_Calendar_Object::getowner($event['id']) !== OCP\User::getUser()) {
         if (!($sharedAccessClassPermissions & OCP\PERMISSION_READ)) {
             return '';
         }
     }
     $object = OC_Calendar_Object::cleanByAccessClass($event['id'], $object);
     if ($object->VEVENT) {
         $dtstart = $object->VEVENT->DTSTART;
         $start_dt = $dtstart->getDateTime();
         $dtend = OC_Calendar_Object::getDTEndFromVEvent($object->VEVENT);
         $end_dt = $dtend->getDateTime();
         if ($dtstart->getDateType() !== Sabre\VObject\Property\DateTime::DATE) {
             $start_dt->setTimezone(new DateTimeZone('UTC'));
             $end_dt->setTimezone(new DateTimeZone('UTC'));
             $object->VEVENT->setDateTime('DTSTART', $start_dt, Sabre\VObject\Property\DateTime::UTC);
             $object->VEVENT->setDateTime('DTEND', $end_dt, Sabre\VObject\Property\DateTime::UTC);
         }
         return $object->VEVENT->serialize();
     }
     if ($object->VTODO) {
         return $object->VTODO->serialize();
     }
     if ($object->VJOURNAL) {
         return $object->VJOURNAL->serialize();
     }
     return '';
 }
예제 #3
0
파일: hooks.php 프로젝트: noci2012/owncloud
 public static function getBirthdayEvents($parameters)
 {
     $name = $parameters['calendar_id'];
     if (strpos('birthday_', $name) != 0) {
         return;
     }
     $info = explode('_', $name);
     $aid = $info[1];
     OC_Contacts_App::getAddressbook($aid);
     foreach (OC_Contacts_VCard::all($aid) as $card) {
         $vcard = OC_VObject::parse($card['carddata']);
         if (!$vcard) {
             continue;
         }
         $birthday = $vcard->BDAY;
         if ($birthday) {
             $date = new DateTime($birthday);
             $vevent = new OC_VObject('VEVENT');
             $vevent->setDateTime('LAST-MODIFIED', new DateTime($vcard->REV));
             $vevent->setDateTime('DTSTART', $date, Sabre_VObject_Element_DateTime::DATE);
             $vevent->setString('DURATION', 'P1D');
             // DESCRIPTION?
             $vevent->setString('RRULE', 'FREQ=YEARLY');
             $title = str_replace('{name}', $vcard->getAsString('FN'), OC_Contacts_App::$l10n->t('{name}\'s Birthday'));
             $parameters['events'][] = array('id' => 0, 'vevent' => $vevent, 'repeating' => true, 'summary' => $title);
         }
     }
 }
예제 #4
0
 /**
  * @brief generates the VEVENT with UTC dates
  * @param array $event
  * @return string
  */
 private static function generateEvent($event)
 {
     $object = OC_VObject::parse($event['calendardata']);
     if (!$object) {
         return false;
     }
     if ($object->VEVENT) {
         $dtstart = $object->VEVENT->DTSTART;
         $start_dt = $dtstart->getDateTime();
         $dtend = OC_Calendar_Object::getDTEndFromVEvent($object->VEVENT);
         $end_dt = $dtend->getDateTime();
         if ($dtstart->getDateType() !== Sabre\VObject\Property\DateTime::DATE) {
             $start_dt->setTimezone(new DateTimeZone('UTC'));
             $end_dt->setTimezone(new DateTimeZone('UTC'));
             $object->VEVENT->setDateTime('DTSTART', $start_dt, Sabre\VObject\Property\DateTime::UTC);
             $object->VEVENT->setDateTime('DTEND', $end_dt, Sabre\VObject\Property\DateTime::UTC);
         }
         return $object->VEVENT->serialize();
     }
     if ($object->VTODO) {
         return $object->VTODO->serialize();
     }
     if ($object->VJOURNAL) {
         return $object->VJOURNAL->serialize();
     }
     return '';
 }
예제 #5
0
 public static function getBirthdayEvents($parameters)
 {
     $name = $parameters['calendar_id'];
     if (strpos($name, 'birthday_') != 0) {
         return;
     }
     $info = explode('_', $name);
     $aid = $info[1];
     OC_Contacts_App::getAddressbook($aid);
     foreach (OC_Contacts_VCard::all($aid) as $card) {
         $vcard = OC_VObject::parse($card['carddata']);
         if (!$vcard) {
             continue;
         }
         $birthday = $vcard->BDAY;
         if ($birthday) {
             $date = new DateTime($birthday);
             $vevent = new OC_VObject('VEVENT');
             //$vevent->setDateTime('LAST-MODIFIED', new DateTime($vcard->REV));
             $vevent->setDateTime('DTSTART', $date, Sabre_VObject_Element_DateTime::DATE);
             $vevent->setString('DURATION', 'P1D');
             $vevent->setString('UID', substr(md5(rand() . time()), 0, 10));
             // DESCRIPTION?
             $vevent->setString('RRULE', 'FREQ=YEARLY');
             $title = str_replace('{name}', $vcard->getAsString('FN'), OC_Contacts_App::$l10n->t('{name}\'s Birthday'));
             $parameters['events'][] = array('id' => 0, 'vevent' => $vevent, 'repeating' => true, 'summary' => $title, 'calendardata' => "BEGIN:VCALENDAR\nVERSION:2.0\n" . "PRODID:ownCloud Contacts " . OCP\App::getAppVersion('contacts') . "\n" . $vevent->serialize() . "END:VCALENDAR");
         }
     }
 }
예제 #6
0
 /**
  * @brief Gets the VCard as an OC_VObject
  * @returns The card or null if the card could not be parsed.
  */
 public static function getContactVCard($id)
 {
     $card = self::getContactObject($id);
     $vcard = OC_VObject::parse($card['carddata']);
     if (!is_null($vcard) && !isset($vcard->REV)) {
         $rev = new DateTime('@' . $card['lastmodified']);
         $vcard->setString('REV', $rev->format(DateTime::W3C));
     }
     return $vcard;
 }
예제 #7
0
 public function __construct($ical)
 {
     $this->error = null;
     $this->ical = $ical;
     $this->abscount = 0;
     $this->count = 0;
     try {
         $this->calobject = OC_VObject::parse($this->ical);
     } catch (Exception $e) {
         //MISSING: write some log
         $this->error = true;
         return false;
     }
     return true;
 }
예제 #8
0
 /**
  * @brief generates the VEVENT with UTC dates
  * @param array $event
  * @return string
  */
 private static function generateEvent($event)
 {
     $object = OC_VObject::parse($event['calendardata']);
     $dtstart = $object->VEVENT->DTSTART;
     $start_dt = $dtstart->getDateTime();
     $dtend = OC_Calendar_Object::getDTEndFromVEvent($object->VEVENT);
     $end_dt = $dtend->getDateTime();
     if ($dtstart->getDateType() !== Sabre_VObject_Element_DateTime::DATE) {
         $start_dt->setTimezone(new DateTimeZone('UTC'));
         $end_dt->setTimezone(new DateTimeZone('UTC'));
         $object->VEVENT->setDateTime('DTSTART', $start_dt, Sabre_VObject_Property_DateTime::UTC);
         $object->VEVENT->setDateTime('DTEND', $end_dt, Sabre_VObject_Property_DateTime::UTC);
     }
     return $object->VEVENT->serialize();
 }
예제 #9
0
 function search($query)
 {
     $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser(), true);
     if (count($calendars) == 0 || !OCP\App::isEnabled('calendar')) {
         //return false;
     }
     $results = array();
     $searchquery = array();
     if (substr_count($query, ' ') > 0) {
         $searchquery = explode(' ', $query);
     } else {
         $searchquery[] = $query;
     }
     $user_timezone = OC_Calendar_App::getTimezone();
     $l = new OC_l10n('calendar');
     foreach ($calendars as $calendar) {
         $objects = OC_Calendar_Object::all($calendar['id']);
         foreach ($objects as $object) {
             if ($object['objecttype'] != 'VEVENT') {
                 continue;
             }
             if (substr_count(strtolower($object['summary']), strtolower($query)) > 0) {
                 $calendardata = OC_VObject::parse($object['calendardata']);
                 $vevent = $calendardata->VEVENT;
                 $dtstart = $vevent->DTSTART;
                 $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
                 $start_dt = $dtstart->getDateTime();
                 $start_dt->setTimezone(new DateTimeZone($user_timezone));
                 $end_dt = $dtend->getDateTime();
                 $end_dt->setTimezone(new DateTimeZone($user_timezone));
                 if ($dtstart->getDateType() == Sabre\VObject\Property\DateTime::DATE) {
                     $end_dt->modify('-1 sec');
                     if ($start_dt->format('d.m.Y') != $end_dt->format('d.m.Y')) {
                         $info = $l->t('Date') . ': ' . $start_dt->format('d.m.Y') . ' - ' . $end_dt->format('d.m.Y');
                     } else {
                         $info = $l->t('Date') . ': ' . $start_dt->format('d.m.Y');
                     }
                 } else {
                     $info = $l->t('Date') . ': ' . $start_dt->format('d.m.y H:i') . ' - ' . $end_dt->format('d.m.y H:i');
                 }
                 $link = OCP\Util::linkTo('calendar', 'index.php') . '?showevent=' . urlencode($object['id']);
                 $results[] = new OC_Search_Result($object['summary'], $info, $link, (string) $l->t('Cal.'));
                 //$name,$text,$link,$type
             }
         }
     }
     return $results;
 }
예제 #10
0
 /**
  * Returns a list of ACE's for this node.
  *
  * Each ACE has the following properties:
  *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
  *     currently the only supported privileges
  *   * 'principal', a url to the principal who owns the node
  *   * 'protected' (optional), indicating that this ACE is not allowed to
  *      be updated.
  *
  * @return array
  */
 public function getACL()
 {
     $readprincipal = $this->getOwner();
     $writeprincipal = $this->getOwner();
     $uid = OC_Calendar_Calendar::extractUserID($this->getOwner());
     if ($uid != OCP\USER::getUser()) {
         $object = OC_VObject::parse($this->objectData['calendardata']);
         $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $this->calendarInfo['id']);
         $sharedAccessClassPermissions = OC_Calendar_App::getAccessClassPermissions($object->VEVENT->CLASS->value);
         if ($sharedCalendar && $sharedCalendar['permissions'] & OCP\PERMISSION_READ && $sharedAccessClassPermissions & OCP\PERMISSION_READ) {
             $readprincipal = 'principals/' . OCP\USER::getUser();
         }
         if ($sharedCalendar && $sharedCalendar['permissions'] & OCP\PERMISSION_UPDATE && $sharedAccessClassPermissions & OCP\PERMISSION_UPDATE) {
             $writeprincipal = 'principals/' . OCP\USER::getUser();
         }
     }
     return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-read', 'protected' => true));
 }
예제 #11
0
 /**
  * @brief generates the VEVENT/VTODO/VJOURNAL with UTC dates
  * @param array $event
  * @return string
  */
 private static function generateEvent($event)
 {
     $object = OC_VObject::parse($event['calendardata']);
     if (!$object) {
         return false;
     }
     $sharedAccessClassPermissions = OC_Calendar_Object::getAccessClassPermissions($object);
     if (OC_Calendar_Object::getowner($event['id']) !== OCP\User::getUser()) {
         if (!($sharedAccessClassPermissions & OCP\PERMISSION_READ)) {
             return '';
         }
     }
     $object = OC_Calendar_Object::cleanByAccessClass($event['id'], $object);
     if ($object->VEVENT) {
         return $object->VEVENT->serialize();
     }
     if ($object->VTODO) {
         return $object->VTODO->serialize();
     }
     if ($object->VJOURNAL) {
         return $object->VJOURNAL->serialize();
     }
     return '';
 }
예제 #12
0
 /**
  * Constructor
  *
  * @param array $data
  * @return \OCA\Calendar\Search\Event
  */
 public function __construct(array $data = null)
 {
     // set default properties
     $this->id = $data['id'];
     $this->name = $data['summary'];
     $this->link = \OCP\Util::linkTo('calendar', 'index.php') . '?showevent=' . urlencode($data['id']);
     // do calendar-specific setup
     $l = new \OC_l10n('calendar');
     $calendar_data = \OC_VObject::parse($data['calendardata']);
     $vevent = $calendar_data->VEVENT;
     // get start time
     $dtstart = $vevent->DTSTART;
     $start_dt = $dtstart->getDateTime();
     $start_dt->setTimezone($this->getUserTimezone());
     $this->start_time = $start_dt->format('r');
     // get end time
     $dtend = \OC_Calendar_Object::getDTEndFromVEvent($vevent);
     $end_dt = $dtend->getDateTime();
     $end_dt->setTimezone($this->getUserTimezone());
     $this->end_time = $end_dt->format('r');
     // create text description
     if ($dtstart->getDateType() == \Sabre\VObject\Property\DateTime::DATE) {
         $end_dt->modify('-1 sec');
         if ($start_dt->format('d.m.Y') != $end_dt->format('d.m.Y')) {
             $this->text = $l->t('Date') . ': ' . $start_dt->format('d.m.Y') . ' - ' . $end_dt->format('d.m.Y');
         } else {
             $this->text = $l->t('Date') . ': ' . $start_dt->format('d.m.Y');
         }
     } else {
         $this->text = $l->t('Date') . ': ' . $start_dt->format('d.m.y H:i') . ' - ' . $end_dt->format('d.m.y H:i');
     }
     // set last modified time
     $this->modified = date('r', $data['lastmodified']);
     // set repeating property
     $this->repeating = (bool) $data['repeating'];
 }
예제 #13
0
 public function __construct($ical)
 {
     $this->error = null;
     $this->ical = $ical;
     $this->abscount = 0;
     $this->count = 0;
     //fix for multiple subcalendars
     if (substr_count($ical, 'BEGIN:VCALENDAR') > 1) {
         $ical = substr_replace($ical, '**##++FancyReplacementForFirstOccurrenceOfTheSearchPattern++##**', 0, 15);
         $ical = str_replace('BEGIN:VCALENDAR', '', $ical);
         $ical = str_replace('END:VCALENDAR', '', $ical);
         $ical = substr_replace($ical, 'BEGIN:VCALENDAR', 0, 64);
         $ical .= "\n" . 'END:VCALENDAR';
         $this->ical = $ical;
     }
     try {
         $this->calobject = OC_VObject::parse($this->ical);
     } catch (Exception $e) {
         //MISSING: write some log
         $this->error = true;
         return false;
     }
     return true;
 }
예제 #14
0
 /**
  * Returns information from a single calendar object, based on it's object
  * uri.
  *
  * The returned array must have the same keys as getCalendarObjects. The
  * 'calendardata' object is required here though, while it's not required
  * for getCalendarObjects.
  *
  * @param string $calendarId
  * @param string $objectUri
  * @return array
  */
 public function getCalendarObject($calendarId, $objectUri)
 {
     if ($calendarId === 'contact_birthdays') {
         $objectUri = substr($objectUri, 0, strlen($objectUri) - 4);
         $objectUriArray = explode('::', $objectUri);
         if (count($objectUriArray) === 3) {
             $app = new \OCA\Contacts\App();
             list($backend, $addressBookId, $contactId) = $objectUriArray;
             $contact = $app->getContact($backend, $addressBookId, $contactId);
             $vevent = $contact->getBirthdayEvent();
             if (is_null($vevent)) {
                 return false;
             }
             return $this->OCAddETag(array('id' => 0, 'calendarid' => 'contact_birthdays', 'uri' => $contact->getBackend()->name . '::' . $contact->getParent()->getId() . '::' . $contact->getId() . '.ics', 'lastmodified' => $contact->lastModified(), 'calendardata' => $vevent->serialize()));
         }
     }
     $data = OC_Calendar_Object::findWhereDAVDataIs($calendarId, $objectUri);
     if (is_array($data)) {
         $data = $this->OCAddETag($data);
         $object = OC_VObject::parse($data['calendardata']);
         if (!$object) {
             return false;
         }
         $object = OC_Calendar_Object::cleanByAccessClass($data['id'], $object);
         $data['calendardata'] = $object->serialize();
     }
     return $data;
 }
예제 #15
0
        }
    }
    $importready[] = $start . $nl . $content . $nl . $end;
}
writeProgress('70');
if (count($parts) == 1) {
    $importready = array($file);
}
$imported = 0;
$failed = 0;
if (!count($importready) > 0) {
    OCP\JSON::error(array('message' => 'No contacts to import in .' . $_POST['file'] . ' Please check if the file is corrupted.'));
    exit;
}
foreach ($importready as $import) {
    $card = OC_VObject::parse($import);
    if (!$card) {
        $failed += 1;
        OCP\Util::writeLog('contacts', 'Import: skipping card. Error parsing VCard: ' . $import, OCP\Util::ERROR);
        continue;
        // Ditch cards that can't be parsed by Sabre.
    }
    $imported += 1;
    OC_Contacts_VCard::add($id, $card);
}
//done the import
writeProgress('100');
sleep(3);
if (is_writable('import_tmp/')) {
    unlink($progressfile);
}
예제 #16
0
 /**
  * @brief edits an object with the data provided by sabredav
  * @param integer $id calendar id
  * @param string $uri   the uri of the object
  * @param string $data  object
  * @return boolean
  */
 public static function editFromDAVData($cid, $uri, $data)
 {
     $oldobject = self::findWhereDAVDataIs($cid, $uri);
     $calendar = OC_Calendar_Calendar::find($cid);
     if ($calendar['userid'] != OCP\User::getUser()) {
         $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id);
         if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\Share::PERMISSION_UPDATE)) {
             throw new Sabre_DAV_Exception_Forbidden(OC_Calendar_App::$l10n->t('You do not have the permissions to edit this event.'));
         }
     }
     $object = OC_VObject::parse($data);
     list($type, $startdate, $enddate, $summary, $repeating, $uid) = self::extractData($object);
     $stmt = OCP\DB::prepare('UPDATE `*PREFIX*calendar_objects` SET `objecttype`=?,`startdate`=?,`enddate`=?,`repeating`=?,`summary`=?,`calendardata`=?,`lastmodified`= ? WHERE `id` = ?');
     $stmt->execute(array($type, $startdate, $enddate, $repeating, $summary, $data, time(), $oldobject['id']));
     OC_Calendar_Calendar::touchCalendar($oldobject['calendarid']);
     OCP\Util::emitHook('OC_Calendar', 'editEvent', $oldobject['id']);
     return true;
 }
예제 #17
0
 /**
  * Returns information from a single calendar object, based on it's object
  * uri.
  *
  * The returned array must have the same keys as getCalendarObjects. The
  * 'calendardata' object is required here though, while it's not required
  * for getCalendarObjects.
  *
  * @param string $calendarId
  * @param string $objectUri
  * @return array
  */
 public function getCalendarObject($calendarId, $objectUri)
 {
     $data = OC_Calendar_Object::findWhereDAVDataIs($calendarId, $objectUri);
     if (is_array($data)) {
         $object = OC_VObject::parse($data['calendardata']);
         $object = OC_Calendar_Object::cleanByAccessClass($data['id'], $object);
         $data['calendardata'] = $object->serialize();
         $data = $this->OCAddETag($data);
     }
     return $data;
 }
예제 #18
0
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
if (!OCP\User::isLoggedIn()) {
    die('<script type="text/javascript">document.location = oc_webroot;</script>');
}
OCP\JSON::checkAppEnabled('calendar');
$id = $_POST['id'];
$data = OC_Calendar_App::getEventObject($id, false, false);
if (!$data) {
    OCP\JSON::error(array('data' => array('message' => OC_Calendar_App::$l10n->t('Wrong calendar'))));
    exit;
}
$permissions = OC_Calendar_App::getPermissions($id, OC_Calendar_App::EVENT);
$object = OC_VObject::parse($data['calendardata']);
$vevent = $object->VEVENT;
$dtstart = $vevent->DTSTART;
$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
switch ($dtstart->getDateType()) {
    case Sabre_VObject_Property_DateTime::UTC:
        $timeOffset = $_SESSION['timezone'] * 60;
        $newDT = $dtstart->getDateTime();
        $newDT->add(new DateInterval("PT" . $timeOffset . "M"));
        $dtstart->setDateTime($newDT);
        $newDT = $dtend->getDateTime();
        $newDT->add(new DateInterval("PT" . $timeOffset . "M"));
        $dtend->setDateTime($newDT);
    case Sabre_VObject_Property_DateTime::LOCALTZ:
    case Sabre_VObject_Property_DateTime::LOCAL:
        $startdate = $dtstart->getDateTime()->format('d-m-Y');
예제 #19
0
 /**
  * @brief Delete categories from the db and from all the vobject supplied
  * @param $names An array of categories to delete
  * @param $objects An array of arrays with [id,vobject] (as text) pairs suitable for updating the apps object table.
  */
 public function delete($names, array &$objects = null)
 {
     if (!is_array($names)) {
         $names = array($names);
     }
     OC_Log::write('core', 'OC_VCategories::delete, before: ' . print_r($this->categories, true), OC_Log::DEBUG);
     foreach ($names as $name) {
         OC_Log::write('core', 'OC_VCategories::delete: ' . $name, OC_Log::DEBUG);
         if ($this->hasCategory($name)) {
             //OC_Log::write('core','OC_VCategories::delete: '.$name.' got it', OC_Log::DEBUG);
             unset($this->categories[$this->array_searchi($name, $this->categories)]);
         }
     }
     $this->save();
     OC_Log::write('core', 'OC_VCategories::delete, after: ' . print_r($this->categories, true), OC_Log::DEBUG);
     if (!is_null($objects)) {
         foreach ($objects as $key => &$value) {
             $vobject = OC_VObject::parse($value[1]);
             if (!is_null($vobject)) {
                 $categories = $vobject->getAsArray('CATEGORIES');
                 //OC_Log::write('core','OC_VCategories::delete, before: '.$key.': '.print_r($categories, true), OC_Log::DEBUG);
                 foreach ($names as $name) {
                     $idx = $this->array_searchi($name, $categories);
                     //OC_Log::write('core','OC_VCategories::delete, loop: '.$name.', '.print_r($idx, true), OC_Log::DEBUG);
                     if ($idx !== false) {
                         OC_Log::write('core', 'OC_VCategories::delete, unsetting: ' . $categories[$this->array_searchi($name, $categories)], OC_Log::DEBUG);
                         unset($categories[$this->array_searchi($name, $categories)]);
                         //unset($categories[$idx]);
                     }
                 }
                 //OC_Log::write('core','OC_VCategories::delete, after: '.$key.': '.print_r($categories, true), OC_Log::DEBUG);
                 $vobject->setString('CATEGORIES', implode(',', $categories));
                 $value[1] = $vobject->serialize();
                 $objects[$key] = $value;
             } else {
                 OC_Log::write('core', 'OC_VCategories::delete, unable to parse. ID: ' . $value[0] . ', ' . substr($value[1], 0, 50) . '(...)', OC_Log::DEBUG);
             }
         }
     }
 }
예제 #20
0
}
//import the contacts
writeProgress('70');
$imported = 0;
$failed = 0;
if (!count($parts) > 0) {
    OCP\JSON::error(array('data' => array('message' => 'No contacts to import in ' . $_POST['file'] . '. Please check if the file is corrupted.', 'file' => $_POST['file'])));
    if (isset($_POST['fstype']) && $_POST['fstype'] == 'OC_FilesystemView') {
        if (!$view->unlink('/imports/' . $_POST['file'])) {
            OCP\Util::writeLog('contacts', 'Import: Error unlinking OC_FilesystemView ' . '/' . $_POST['file'], OCP\Util::ERROR);
        }
    }
    exit;
}
foreach ($parts as $part) {
    $card = OC_VObject::parse($part);
    if (!$card) {
        $failed += 1;
        OCP\Util::writeLog('contacts', 'Import: skipping card. Error parsing VCard: ' . $part, OCP\Util::ERROR);
        continue;
        // Ditch cards that can't be parsed by Sabre.
    }
    try {
        OC_Contacts_VCard::add($id, $card);
        $imported += 1;
    } catch (Exception $e) {
        OCP\Util::writeLog('contacts', 'Error importing vcard: ' . $e->getMessage() . $nl . $card, OCP\Util::ERROR);
        $failed += 1;
    }
}
//done the import
예제 #21
0
 /**
  * @brief Delete categories from the db and from all the vobject supplied
  * @param $names An array of categories to delete
  * @param $objects An array of arrays with [id,vobject] (as text) pairs suitable for updating the apps object table.
  */
 public function delete($names, array &$objects = null)
 {
     if (!is_array($names)) {
         $names = array($names);
     }
     OC_Log::write('core', __METHOD__ . ', before: ' . print_r($this->categories, true), OC_Log::DEBUG);
     foreach ($names as $name) {
         $id = null;
         OC_Log::write('core', __METHOD__ . ', ' . $name, OC_Log::DEBUG);
         if ($this->hasCategory($name)) {
             $id = $this->array_searchi($name, $this->categories);
             unset($this->categories[$id]);
         }
         try {
             $stmt = OCP\DB::prepare('DELETE FROM `' . self::CATEGORY_TABLE . '` WHERE ' . '`uid` = ? AND `type` = ? AND `category` = ?');
             $result = $stmt->execute(array($this->user, $this->type, $name));
             if (OC_DB::isError($result)) {
                 OC_Log::write('core', __METHOD__ . 'DB error: ' . OC_DB::getErrorMessage($result), OC_Log::ERROR);
             }
         } catch (Exception $e) {
             OCP\Util::writeLog('core', __METHOD__ . ', exception: ' . $e->getMessage(), OCP\Util::ERROR);
         }
         if (!is_null($id) && $id !== false) {
             try {
                 $sql = 'DELETE FROM `' . self::RELATION_TABLE . '` ' . 'WHERE `categoryid` = ?';
                 $stmt = OCP\DB::prepare($sql);
                 $result = $stmt->execute(array($id));
                 if (OC_DB::isError($result)) {
                     OC_Log::write('core', __METHOD__ . 'DB error: ' . OC_DB::getErrorMessage($result), OC_Log::ERROR);
                 }
             } catch (Exception $e) {
                 OCP\Util::writeLog('core', __METHOD__ . ', exception: ' . $e->getMessage(), OCP\Util::ERROR);
                 return false;
             }
         }
     }
     OC_Log::write('core', __METHOD__ . ', after: ' . print_r($this->categories, true), OC_Log::DEBUG);
     if (!is_null($objects)) {
         foreach ($objects as $key => &$value) {
             $vobject = OC_VObject::parse($value[1]);
             if (!is_null($vobject)) {
                 $object = null;
                 $componentname = '';
                 if (isset($vobject->VEVENT)) {
                     $object = $vobject->VEVENT;
                     $componentname = 'VEVENT';
                 } else {
                     if (isset($vobject->VTODO)) {
                         $object = $vobject->VTODO;
                         $componentname = 'VTODO';
                     } else {
                         if (isset($vobject->VJOURNAL)) {
                             $object = $vobject->VJOURNAL;
                             $componentname = 'VJOURNAL';
                         } else {
                             $object = $vobject;
                         }
                     }
                 }
                 $categories = $object->getAsArray('CATEGORIES');
                 foreach ($names as $name) {
                     $idx = $this->array_searchi($name, $categories);
                     if ($idx !== false) {
                         OC_Log::write('core', __METHOD__ . ', unsetting: ' . $categories[$this->array_searchi($name, $categories)], OC_Log::DEBUG);
                         unset($categories[$this->array_searchi($name, $categories)]);
                     }
                 }
                 $object->setString('CATEGORIES', implode(',', $categories));
                 if ($vobject !== $object) {
                     $vobject[$componentname] = $object;
                 }
                 $value[1] = $vobject->serialize();
                 $objects[$key] = $value;
             } else {
                 OC_Log::write('core', __METHOD__ . ', unable to parse. ID: ' . $value[0] . ', ' . substr($value[1], 0, 50) . '(...)', OC_Log::DEBUG);
             }
         }
     }
 }
예제 #22
0
파일: vcard.php 프로젝트: noci2012/owncloud
 /**
  * @brief edits a card with the data provided by sabredav
  * @param integer $id Addressbook id
  * @param string $uri   the uri of the card
  * @param string $data  vCard file
  * @return boolean
  */
 public static function editFromDAVData($aid, $uri, $data)
 {
     $oldcard = self::findWhereDAVDataIs($aid, $uri);
     $card = OC_VObject::parse($data);
     if (!$card) {
         OCP\Util::writeLog('contacts', __METHOD__ . ', Unable to parse VCARD, uri: ' . $uri, OCP\Util::ERROR);
         return false;
     }
     try {
         self::edit($oldcard['id'], $card);
         return true;
     } catch (Exception $e) {
         OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage() . ', ' . OCP\USER::getUser(), OCP\Util::ERROR);
         OCP\Util::writeLog('contacts', __METHOD__ . ', uri' . $uri, OCP\Util::DEBUG);
         return false;
     }
 }
예제 #23
0
 /**
  * @brief deletes an object
  * @param integer $id id of object
  * @return boolean
  */
 public static function delete($id)
 {
     $oldobject = self::find($id);
     $calid = self::getCalendarid($id);
     $calendar = OC_Calendar_Calendar::find($calid);
     $oldvobject = OC_VObject::parse($oldobject['calendardata']);
     if ($calendar['userid'] != OCP\User::getUser()) {
         $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $calid);
         $sharedAccessClassPermissions = OC_Calendar_Object::getAccessClassPermissions($oldvobject);
         if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_DELETE) || !($sharedAccessClassPermissions & OCP\PERMISSION_DELETE)) {
             throw new Exception(OC_Calendar_App::$l10n->t('You do not have the permissions to delete this event.'));
         }
     }
     $stmt = OCP\DB::prepare('DELETE FROM `*PREFIX*clndr_objects` WHERE `id` = ?');
     $stmt->execute(array($id));
     OC_Calendar_Calendar::touchCalendar($oldobject['calendarid']);
     OCP\Share::unshareAll('event', $id);
     OCP\Util::emitHook('OC_Calendar', 'deleteEvent', $id);
     return true;
 }
예제 #24
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)
 {
     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 = OC_VObject::parse($event['calendardata']);
         if (!$object) {
             \OCP\Util::writeLog('calendar', __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('calendar', __METHOD__ . ' Object contains not event: ' . print_r($event, true), \OCP\Util::DEBUG);
             return $output;
         }
         $id = $event['id'];
         if (OC_Calendar_Object::getowner($id) !== OCP\USER::getUser()) {
             // do not show events with private or unknown access class
             if (isset($vevent->CLASS) && ($vevent->CLASS->value === 'PRIVATE' || $vevent->CLASS->value === '')) {
                 return $output;
             }
             $object = OC_Calendar_Object::cleanByAccessClass($id, $object);
         }
         $allday = $vevent->DTSTART->getDateType() == Sabre\VObject\Property\DateTime::DATE ? true : false;
         $last_modified = @$vevent->__get('LAST-MODIFIED');
         $lastmodified = $last_modified ? $last_modified->getDateTime()->format('U') : 0;
         $staticoutput = array('id' => (int) $event['id'], 'title' => !is_null($vevent->SUMMARY) && $vevent->SUMMARY->value != '' ? strtr($vevent->SUMMARY->value, array('\\,' => ',', '\\;' => ';')) : self::$l10n->t('unnamed'), 'description' => isset($vevent->DESCRIPTION) ? strtr($vevent->DESCRIPTION->value, array('\\,' => ',', '\\;' => ';')) : '', 'lastmodified' => $lastmodified, 'allDay' => $allday);
         if (OC_Calendar_Object::isrepeating($id) && OC_Calendar_Repeat::is_cached_inperiod($event['id'], $start, $end)) {
             $cachedinperiod = OC_Calendar_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');
                 } 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');
                 }
                 $output[] = array_merge($staticoutput, $dynamicoutput);
             }
         } else {
             if (OC_Calendar_Object::isrepeating($id) || $event['repeating'] == 1) {
                 $object->expand($start, $end);
             }
             foreach ($object->getComponents() as $singleevent) {
                 if (!$singleevent instanceof Sabre\VObject\Component\VEvent) {
                     continue;
                 }
                 $dynamicoutput = OC_Calendar_Object::generateStartEndDate($singleevent->DTSTART, OC_Calendar_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('calendar', 'Event (' . $uid . ') contains invalid data: ' . $e->getMessage(), \OCP\Util::WARN);
     }
 }
예제 #25
0
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
/**
 * @brief Index vCard properties for easier searching
 */
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
require_once 'loghandler.php';
$addressbooks = OCA\Contacts\Addressbook::all(OCP\USER::getUser());
$ids = array();
foreach ($addressbooks as $addressbook) {
    $ids[] = $addressbook['id'];
}
$user = OCP\User::getUser();
session_write_close();
$start = 0;
$batchsize = 10;
while ($contacts = OCA\Contacts\VCard::all($ids, $start, $batchsize)) {
    OCP\Util::writeLog('contacts', 'Indexing contacts: ' . $batchsize . ' starting from ' . $start, OCP\Util::DEBUG);
    foreach ($contacts as $contact) {
        $vcard = OC_VObject::parse($contact['carddata']);
        OCA\Contacts\App::updateDBProperties($contact['id'], $vcard);
    }
    $start += $batchsize;
}
OCP\Config::setUserValue($user, 'contacts', 'contacts_indexed', 'yes');
예제 #26
0
 public static function parseVTODO($data)
 {
     $object = \OC_VObject::parse($data);
     $vtodo = $object->VTODO;
     return $vtodo;
 }
예제 #27
0
 /**
  * Return the start time and end time of a calendar object in Unix time
  *
  * @param array $calendarObject must contain a VEVENT
  * @return array [start, end] in Unix time
  */
 private function getDateRange($calendarObject)
 {
     $calendarData = \OC_VObject::parse($calendarObject['calendardata']);
     // set start
     $start = $calendarData->VEVENT->DTSTART->getDateTime();
     $start->setTimezone(Event::getUserTimezone());
     // set end
     $end = \OC_Calendar_Object::getDTEndFromVEvent($calendarData->VEVENT)->getDateTime();
     $end->setTimezone(Event::getUserTimezone());
     // return
     return array($start->getTimestamp(), $end->getTimestamp());
 }
예제 #28
0
 $comments = $vtodo->COMMENT;
 if ($comments) {
     foreach ($comments as $com) {
         $idx = 0;
         foreach ($children as $i => &$property) {
             if ($property->name == 'COMMENT' && $property['ID']->value == (int) $com['ID']->value) {
                 unset($vtodo->children[$idx]);
             }
             $idx += 1;
         }
         $vtodo->addProperty('COMMENT', $com->value, array('X-OC-ID' => (int) $com['ID']->value, 'X-OC-USERID' => $com['USERID']->value, 'X-OC-DATE-TIME' => $com['DATE-TIME']->value));
         OCP\Util::emitHook('OC_Calendar', 'editEvent', $taskId);
     }
     $data = $vcalendar->serialize();
     $oldobject = \OC_Calendar_Object::find($taskId);
     $object = \OC_VObject::parse($data);
     $type = 'VTODO';
     $startdate = null;
     $enddate = null;
     $summary = '';
     $repeating = 0;
     $uid = null;
     foreach ($object->children as $property) {
         if ($property->name == 'VTODO') {
             foreach ($property->children as &$element) {
                 if ($element->name == 'SUMMARY') {
                     $summary = $element->value;
                 } elseif ($element->name == 'UID') {
                     $uid = $element->value;
                 }
             }
예제 #29
0
파일: vcard.php 프로젝트: noci2012/owncloud
 /**
  * @brief edits a card with the data provided by sabredav
  * @param integer $id Addressbook id
  * @param string $uri   the uri of the card
  * @param string $data  vCard file
  * @return boolean
  */
 public static function editFromDAVData($aid, $uri, $data)
 {
     $oldcard = self::findWhereDAVDataIs($aid, $uri);
     $card = OC_VObject::parse($data);
     if (!$card) {
         OCP\Util::writeLog('contacts', 'OC_Contacts_VCard::editFromDAVData. Unable to parse VCARD, uri: ' . $uri, OCP\Util::ERROR);
         return false;
     }
     return self::edit($oldcard['id'], $card);
 }
예제 #30
0
 /**
  * @brief generates the cache the first time
  * @param (int) id - id of the event
  * @return (bool)
  */
 public static function generate($id)
 {
     $event = OC_Calendar_Object::find($id);
     if ($event['repeating'] == 0) {
         return false;
     }
     $object = OC_VObject::parse($event['calendardata']);
     $start = new DateTime('01-01-' . date('Y') . ' 00:00:00', new DateTimeZone('UTC'));
     $start->modify('-5 years');
     $end = new DateTime('31-12-' . date('Y') . ' 23:59:59', new DateTimeZone('UTC'));
     $end->modify('+5 years');
     $object->expand($start, $end);
     foreach ($object->getComponents() as $vevent) {
         if (!$vevent instanceof Sabre\VObject\Component\VEvent) {
             continue;
         }
         $startenddate = OC_Calendar_Object::generateStartEndDate($vevent->DTSTART, OC_Calendar_Object::getDTEndFromVEvent($vevent), $vevent->DTSTART->getDateType() == Sabre\VObject\Property\DateTime::DATE ? true : false, 'UTC');
         $stmt = OCP\DB::prepare('INSERT INTO `*PREFIX*calendar_repeat` (`eventid`,`calid`,`startdate`,`enddate`) VALUES(?,?,?,?)');
         $stmt->execute(array($id, OC_Calendar_Object::getCalendarid($id), $startenddate['start'], $startenddate['end']));
     }
     return true;
 }