diff options
author | Thomas Tanghus <thomas@tanghus.net> | 2011-12-09 15:25:26 +0100 |
---|---|---|
committer | Thomas Tanghus <thomas@tanghus.net> | 2011-12-09 15:25:26 +0100 |
commit | 7aa8eb3427679366905840b80a69e36344a5632d (patch) | |
tree | 347a2100ad445620ed21b17f9faa90fe0edb3874 /apps/calendar | |
parent | b3661adf028570f6158dfd5092ecb1398d5be0df (diff) | |
parent | eeaf539a4414e3081b6f6652167363a3221a1973 (diff) | |
download | nextcloud-server-7aa8eb3427679366905840b80a69e36344a5632d.tar.gz nextcloud-server-7aa8eb3427679366905840b80a69e36344a5632d.zip |
Merge git://gitorious.org/owncloud/owncloud into tanghus_remote_backup
Conflicts:
apps/contacts/ajax/deletebook.php
apps/contacts/index.php
Diffstat (limited to 'apps/calendar')
-rw-r--r-- | apps/calendar/ajax/editevent.php | 2 | ||||
-rw-r--r-- | apps/calendar/ajax/editeventform.php | 16 | ||||
-rw-r--r-- | apps/calendar/ajax/events.php | 2 | ||||
-rw-r--r-- | apps/calendar/ajax/moveevent.php | 12 | ||||
-rw-r--r-- | apps/calendar/lib/object.php | 77 |
5 files changed, 33 insertions, 76 deletions
diff --git a/apps/calendar/ajax/editevent.php b/apps/calendar/ajax/editevent.php index 46feb068499..e3c84520481 100644 --- a/apps/calendar/ajax/editevent.php +++ b/apps/calendar/ajax/editevent.php @@ -34,7 +34,7 @@ if($errarr){ OC_JSON::error(); exit; } - $vcalendar = OC_Calendar_Object::parse($data['calendardata']); + $vcalendar = OC_VObject::parse($data['calendardata']); $last_modified = $vcalendar->VEVENT->__get('LAST-MODIFIED'); if($last_modified && $_POST['lastmodified'] != $last_modified->getDateTime()->format('U')){ diff --git a/apps/calendar/ajax/editeventform.php b/apps/calendar/ajax/editeventform.php index 63c72934079..c91f136e898 100644 --- a/apps/calendar/ajax/editeventform.php +++ b/apps/calendar/ajax/editeventform.php @@ -26,7 +26,7 @@ if($calendar['userid'] != OC_User::getUser()){ echo $l10n->t('Wrong calendar'); exit; } -$object = OC_Calendar_Object::parse($data['calendardata']); +$object = OC_VObject::parse($data['calendardata']); $vevent = $object->VEVENT; $dtstart = $vevent->DTSTART; $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); @@ -49,20 +49,16 @@ switch($dtstart->getDateType()) { break; } -$summary = isset($vevent->SUMMARY) ? $vevent->SUMMARY->value : ''; -$location = isset($vevent->LOCATION) ? $vevent->LOCATION->value : ''; -$categories = array(); -if (isset($vevent->CATEGORIES)){ - $categories = explode(',', $vevent->CATEGORIES->value); - $categories = array_map('trim', $categories); -} +$summary = $vevent->getAsString('SUMMARY'); +$location = $vevent->getAsString('LOCATION'); +$categories = $vevent->getAsArray('CATEGORIES'); +$repeat = $vevent->getAsString('CATEGORY'); +$description = $vevent->getAsString('DESCRIPTION'); foreach($categories as $category){ if (!in_array($category, $category_options)){ array_unshift($category_options, $category); } } -$repeat = isset($vevent->CATEGORY) ? $vevent->CATEGORY->value : ''; -$description = isset($vevent->DESCRIPTION) ? $vevent->DESCRIPTION->value : ''; $last_modified = $vevent->__get('LAST-MODIFIED'); if ($last_modified){ $lastmodified = $last_modified->getDateTime()->format('U'); diff --git a/apps/calendar/ajax/events.php b/apps/calendar/ajax/events.php index 1ef6bd30594..1430432b8a3 100644 --- a/apps/calendar/ajax/events.php +++ b/apps/calendar/ajax/events.php @@ -33,7 +33,7 @@ $events = OC_Calendar_Object::allInPeriod($_GET['calendar_id'], $start, $end); $user_timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get()); $return = array(); foreach($events as $event){ - $object = OC_Calendar_Object::parse($event['calendardata']); + $object = OC_VObject::parse($event['calendardata']); $vevent = $object->VEVENT; $dtstart = $vevent->DTSTART; $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); diff --git a/apps/calendar/ajax/moveevent.php b/apps/calendar/ajax/moveevent.php index 6b315a39213..51fafdfeb97 100644 --- a/apps/calendar/ajax/moveevent.php +++ b/apps/calendar/ajax/moveevent.php @@ -22,7 +22,7 @@ $delta = new DateInterval('P0D'); $delta->d = $_POST['dayDelta']; $delta->i = $_POST['minuteDelta']; -$vcalendar = OC_Calendar_Object::parse($data['calendardata']); +$vcalendar = OC_VObject::parse($data['calendardata']); $vevent = $vcalendar->VEVENT; $last_modified = $vevent->__get('LAST-MODIFIED'); @@ -46,14 +46,8 @@ $dtstart->setDateTime($dtstart->getDateTime()->add($delta), $start_type); $dtend->setDateTime($dtend->getDateTime()->add($delta), $end_type); unset($vevent->DURATION); -$now = new DateTime(); -$last_modified = new Sabre_VObject_Element_DateTime('LAST-MODIFIED'); -$last_modified->setDateTime($now, Sabre_VObject_Element_DateTime::UTC); -$vevent->__set('LAST-MODIFIED', $last_modified); - -$dtstamp = new Sabre_VObject_Element_DateTime('DTSTAMP'); -$dtstamp->setDateTime($now, Sabre_VObject_Element_DateTime::UTC); -$vevent->DTSTAMP = $dtstamp; +$vevent->setDateTime('LAST-MODIFIED', 'now', Sabre_VObject_Element_DateTime::UTC); +$vevent->setDateTime('DTSTAMP', 'now', Sabre_VObject_Element_DateTime::UTC); $result = OC_Calendar_Object::edit($id, $vcalendar->serialize()); OC_JSON::success(array('lastmodified'=>(int)$now->format('U'))); diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php index b0164690429..1e834241f63 100644 --- a/apps/calendar/lib/object.php +++ b/apps/calendar/lib/object.php @@ -92,7 +92,7 @@ class OC_Calendar_Object{ * @return insertid */ public static function add($id,$data){ - $object = self::parse($data); + $object = OC_VObject::parse($data); list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object); if(is_null($uid)){ @@ -119,7 +119,7 @@ class OC_Calendar_Object{ * @return insertid */ public static function addFromDAVData($id,$uri,$data){ - $object = self::parse($data); + $object = OC_VObject::parse($data); list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object); $stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*calendar_objects (calendarid,objecttype,startdate,enddate,repeating,summary,calendardata,uri,lastmodified) VALUES(?,?,?,?,?,?,?,?,?)' ); @@ -139,7 +139,7 @@ class OC_Calendar_Object{ public static function edit($id, $data){ $oldobject = self::find($id); - $object = self::parse($data); + $object = OC_VObject::parse($data); list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object); $stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_objects SET objecttype=?,startdate=?,enddate=?,repeating=?,summary=?,calendardata=?, lastmodified = ? WHERE id = ?' ); @@ -160,7 +160,7 @@ class OC_Calendar_Object{ public static function editFromDAVData($cid,$uri,$data){ $oldobject = self::findWhereDAVDataIs($cid,$uri); - $object = self::parse($data); + $object = OC_VObject::parse($data); list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object); $stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_objects SET objecttype=?,startdate=?,enddate=?,repeating=?,summary=?,calendardata=?, lastmodified = ? WHERE id = ?' ); @@ -228,7 +228,7 @@ class OC_Calendar_Object{ // Child to use $children = 0; $use = null; - foreach($object->children as &$property){ + foreach($object->children as $property){ if($property->name == 'VEVENT'){ $children++; $thisone = true; @@ -259,12 +259,12 @@ class OC_Calendar_Object{ // one VTODO per object) break; } - } unset($property); + } // find the data if(!is_null($use)){ $return[0] = $use->name; - foreach($use->children as &$property){ + foreach($use->children as $property){ if($property->name == 'DTSTART'){ $return[1] = self::getUTCforMDB($property->getDateTime()); } @@ -280,7 +280,7 @@ class OC_Calendar_Object{ elseif($property->name == 'UID'){ $return[5] = $property->value; } - } unset($property); + } } // More than one child means reoccuring! @@ -302,21 +302,6 @@ class OC_Calendar_Object{ return date('Y-m-d H:i', $datetime->format('U') - $datetime->getOffset()); } - /** - * @brief Parses the VObject - * @param string VObject as string - * @returns Sabre_VObject or null - */ - public static function parse($data){ - try { - Sabre_VObject_Reader::$elementMap['LAST-MODIFIED'] = 'Sabre_VObject_Element_DateTime'; - $calendar = Sabre_VObject_Reader::read($data); - return $calendar; - } catch (Exception $e) { - return null; - } - } - public static function getDTEndFromVEvent($vevent) { if ($vevent->DTEND) { @@ -458,22 +443,16 @@ class OC_Calendar_Object{ public static function createVCalendarFromRequest($request) { - $vcalendar = new Sabre_VObject_Component('VCALENDAR'); + $vcalendar = new OC_VObject('VCALENDAR'); $vcalendar->add('PRODID', 'ownCloud Calendar'); $vcalendar->add('VERSION', '2.0'); - $now = new DateTime(); - - $vevent = new Sabre_VObject_Component('VEVENT'); + $vevent = new OC_VObject('VEVENT'); $vcalendar->add($vevent); - $created = new Sabre_VObject_Element_DateTime('CREATED'); - $created->setDateTime($now, Sabre_VObject_Element_DateTime::UTC); - $vevent->add($created); - - $uid = self::createUID(); - $vevent->add('UID',$uid); + $vevent->setDateTime('CREATED', 'now', Sabre_VObject_Element_DateTime::UTC); + $vevent->setUID(); return self::updateVCalendarFromRequest($request, $vcalendar); } @@ -509,43 +488,31 @@ class OC_Calendar_Object{ }*/ $repeat = "false"; - $now = new DateTime(); - $vevent = $vcalendar->VEVENT[0]; - - $last_modified = new Sabre_VObject_Element_DateTime('LAST-MODIFIED'); - $last_modified->setDateTime($now, Sabre_VObject_Element_DateTime::UTC); - $vevent->__set('LAST-MODIFIED', $last_modified); - - $dtstamp = new Sabre_VObject_Element_DateTime('DTSTAMP'); - $dtstamp->setDateTime($now, Sabre_VObject_Element_DateTime::UTC); - $vevent->DTSTAMP = $dtstamp; + $vevent = $vcalendar->VEVENT; - $vevent->SUMMARY = $title; + $vevent->setDateTime('LAST-MODIFIED', 'now', Sabre_VObject_Element_DateTime::UTC); + $vevent->setDateTime('DTSTAMP', 'now', Sabre_VObject_Element_DateTime::UTC); + $vevent->setString('SUMMARY', $title); $dtstart = new Sabre_VObject_Element_DateTime('DTSTART'); $dtend = new Sabre_VObject_Element_DateTime('DTEND'); if($allday){ $start = new DateTime($from); $end = new DateTime($to.' +1 day'); - $dtstart->setDateTime($start, Sabre_VObject_Element_DateTime::DATE); - $dtend->setDateTime($end, Sabre_VObject_Element_DateTime::DATE); + $vevent->setDateTime('DTSTART', $start, Sabre_VObject_Element_DateTime::DATE); + $vevent->setDateTime('DTEND', $end, Sabre_VObject_Element_DateTime::DATE); }else{ $timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get()); $timezone = new DateTimeZone($timezone); $start = new DateTime($from.' '.$fromtime, $timezone); $end = new DateTime($to.' '.$totime, $timezone); - $dtstart->setDateTime($start, Sabre_VObject_Element_DateTime::LOCALTZ); - $dtend->setDateTime($end, Sabre_VObject_Element_DateTime::LOCALTZ); + $vevent->setDateTime('DTSTART', $start, Sabre_VObject_Element_DateTime::LOCALTZ); + $vevent->setDateTime('DTEND', $end, Sabre_VObject_Element_DateTime::LOCALTZ); } - $vevent->DTSTART = $dtstart; - $vevent->DTEND = $dtend; unset($vevent->DURATION); - if($location != ""){ - $vevent->LOCATION = $location; - }else{ - unset($vevent->LOCATION); - } + + $vevent->setString('LOCATION', $location); if($description != ""){ $vevent->DESCRIPTION = $description; |