diff --git a/apps/calendar/ajax/editevent.php b/apps/calendar/ajax/editevent.php
index 46feb06849..e3c8452048 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 63c7293407..c91f136e89 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 1ef6bd3059..1430432b8a 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 6b315a3921..51fafdfeb9 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 b016469042..1e834241f6 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];
+ $vevent = $vcalendar->VEVENT;
- $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->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;
diff --git a/apps/contacts/ajax/addcard.php b/apps/contacts/ajax/addcard.php
index dd5b90651f..9d782246a0 100644
--- a/apps/contacts/ajax/addcard.php
+++ b/apps/contacts/ajax/addcard.php
@@ -23,26 +23,20 @@
// Init owncloud
require_once('../../../lib/base.php');
-$aid = $_POST['id'];
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$addressbook = OC_Contacts_Addressbook::find( $aid );
-if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your addressbook.')))); // Same here (as with the contact error). Could this error be improved?
- exit();
-}
+$aid = $_POST['id'];
+$addressbook = OC_Contacts_App::getAddressbook( $aid );
$fn = $_POST['fn'];
$values = $_POST['value'];
$parameters = $_POST['parameters'];
-$vcard = new Sabre_VObject_Component('VCARD');
-$vcard->add(new Sabre_VObject_Property('FN',$fn));
-$vcard->add(new Sabre_VObject_Property('UID',OC_Contacts_VCard::createUID()));
+$vcard = new OC_VObject('VCARD');
+$vcard->setUID();
+$vcard->setString('FN',$fn);
// Data to add ...
$add = array('TEL', 'EMAIL', 'ORG');
@@ -64,20 +58,8 @@ foreach( $add as $propname){
else{
$prop_parameters = array();
}
- OC_Contacts_VCard::addVCardProperty($vcard, $propname, $value, $prop_parameters);
+ $vcard->addProperty($propname, $value, $prop_parameters);
}
$id = OC_Contacts_VCard::add($aid,$vcard->serialize());
-$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
-$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
-
-$details = OC_Contacts_VCard::structureContact($vcard);
-$name = $details['FN'][0]['value'];
-$tmpl = new OC_Template('contacts','part.details');
-$tmpl->assign('details',$details);
-$tmpl->assign('id',$id);
-$tmpl->assign('adr_types',$adr_types);
-$tmpl->assign('phone_types',$phone_types);
-$page = $tmpl->fetchPage();
-
-OC_JSON::success(array('data' => array( 'id' => $id, 'name' => $name, 'page' => $page )));
+OC_Contacts_App::renderDetails($id, $vcard);
diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/addproperty.php
index 101cfabbe8..98877805b4 100644
--- a/apps/contacts/ajax/addproperty.php
+++ b/apps/contacts/ajax/addproperty.php
@@ -23,40 +23,20 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_POST['id'];
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$card = OC_Contacts_VCard::find( $id );
-if( $card === false ){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
- exit();
-}
-
-$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
-if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
- exit();
-}
-
-$vcard = OC_Contacts_VCard::parse($card['carddata']);
-// Check if the card is valid
-if(is_null($vcard)){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
- exit();
-}
+$id = $_POST['id'];
+$vcard = OC_Contacts_App::getContactVCard( $id );
$name = $_POST['name'];
$value = $_POST['value'];
-$parameters = isset($_POST['parameteres'])?$_POST['parameters']:array();
+$parameters = isset($_POST['parameters'])?$_POST['parameters']:array();
-$property = OC_Contacts_VCard::addVCardProperty($vcard, $name, $value, $parameters);
+$property = $vcard->addProperty($name, $value, $parameters);
$line = count($vcard->children) - 1;
-$checksum = md5($property->serialize());
OC_Contacts_VCard::edit($id,$vcard->serialize());
diff --git a/apps/contacts/ajax/deletebook.php b/apps/contacts/ajax/deletebook.php
index 238975436e..a89c00575e 100644
--- a/apps/contacts/ajax/deletebook.php
+++ b/apps/contacts/ajax/deletebook.php
@@ -23,21 +23,14 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_POST['id'];
-
-OC_Log::write('contacts','deletebook.php: '.$id,OC_Log::DEBUG);
-
$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$addressbook = OC_Contacts_Addressbook::find( $id );
-if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
- exit();
-}
+//$id = $_GET['id'];
+$id = $_POST['id'];
+$addressbook = OC_Contacts_App::getAddressbook( $id );
OC_Contacts_Addressbook::delete($id);
OC_JSON::success(array('data' => array( 'id' => $id )));
diff --git a/apps/contacts/ajax/deletecard.php b/apps/contacts/ajax/deletecard.php
index a0a6b8c3ea..e26dfd6ebf 100644
--- a/apps/contacts/ajax/deletecard.php
+++ b/apps/contacts/ajax/deletecard.php
@@ -23,25 +23,12 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_GET['id'];
-
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$card = OC_Contacts_VCard::find( $id );
-if( $card === false ){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
- exit();
-}
-
-$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
-if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
- exit();
-}
+$id = $_GET['id'];
+$card = OC_Contacts_App::getContactObject( $id );
OC_Contacts_VCard::delete($id);
OC_JSON::success(array('data' => array( 'id' => $id )));
diff --git a/apps/contacts/ajax/deleteproperty.php b/apps/contacts/ajax/deleteproperty.php
index 0a3a3c293a..f69735e61c 100644
--- a/apps/contacts/ajax/deleteproperty.php
+++ b/apps/contacts/ajax/deleteproperty.php
@@ -23,45 +23,15 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_GET['id'];
-$checksum = $_GET['checksum'];
-
-
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$card = OC_Contacts_VCard::find( $id );
-if( $card === false ){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
- exit();
-}
+$id = $_GET['id'];
+$checksum = $_GET['checksum'];
-$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
-if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
- exit();
-}
-
-$vcard = OC_Contacts_VCard::parse($card['carddata']);
-// Check if the card is valid
-if(is_null($vcard)){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
- exit();
-}
-
-$line = null;
-for($i=0;$i
+
+
+
t('Phone'); ?>
+t('Preferred').' ' : '' ?>t('Phone'); ?>
diff --git a/apps/contacts/templates/part.setpropertyform.php b/apps/contacts/templates/part.setpropertyform.php index f216a55f5e..8635d7db1c 100644 --- a/apps/contacts/templates/part.setpropertyform.php +++ b/apps/contacts/templates/part.setpropertyform.php @@ -1,7 +1,9 @@