From 0b5fb1bfc77019c440d22e113dcf5c60a40d171f Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 16 Feb 2015 18:42:41 +0100 Subject: [PATCH] Fix to make it compatible with Sabre 2.1 Also fixed unit tests so they run but some still fail - Added IUserSession mock - Replaced OCP::getUser() with IUserSession usage to make the mock work - Added base class for test cases --- appinfo/app.php | 19 +----- appinfo/info.xml | 5 +- appinfo/remote.php | 11 +--- appinfo/routes.php | 34 +++++++---- js/config.php | 2 +- lib/addressbook.php | 2 +- lib/addressbookprovider.php | 2 +- lib/app.php | 2 +- lib/backend/abstractbackend.php | 2 +- lib/backend/ldap.php | 2 +- lib/carddav/addressbook.php | 16 ++--- lib/carddav/backend.php | 9 ++- lib/carddav/card.php | 7 ++- lib/carddav/plugin.php | 4 +- lib/connector/importconnector.php | 9 ++- lib/connector/importcsvconnector.php | 6 +- lib/connector/importldifconnector.php | 6 +- lib/connector/importvcardconnector.php | 12 ++-- lib/connector/ldapconnector.php | 14 ++--- lib/contact.php | 30 ++++++---- lib/controller/groupcontroller.php | 7 ++- lib/controller/importcontroller.php | 2 +- lib/controller/settingscontroller.php | 4 +- lib/share/addressbook.php | 2 +- lib/share/contact.php | 2 +- lib/utils/jsonserializer.php | 12 ++-- lib/utils/properties.php | 6 +- lib/vobject/groupproperty.php | 4 +- lib/vobject/stringproperty.php | 82 -------------------------- lib/vobject/vcard.php | 24 ++++---- settings.php | 2 +- templates/contacts.php | 4 +- tests/bootstrap.php | 2 + tests/lib/addressbook_test.php | 7 ++- tests/lib/addressbookprovider_test.php | 16 +++-- tests/lib/backend/backend_test.php | 2 +- tests/lib/backend/mock.php | 2 +- tests/lib/contact_test.php | 5 +- tests/lib/contacts_app.php | 2 +- tests/lib/testcase.php | 46 +++++++++++++++ tests/lib/vobject_test.php | 16 ++--- tests/preseed-config.php | 2 +- 42 files changed, 210 insertions(+), 235 deletions(-) delete mode 100644 lib/vobject/stringproperty.php create mode 100644 tests/lib/testcase.php diff --git a/appinfo/app.php b/appinfo/app.php index 1af289e2..6468e797 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -12,23 +12,8 @@ namespace OCA\Contacts; use \OC\AppFramework\Core\API; //require_once __DIR__ . '/../lib/controller/pagecontroller.php'; -\Sabre\VObject\Component::$classMap['VCARD'] = '\OCA\Contacts\VObject\VCard'; -\Sabre\VObject\Property::$classMap['CATEGORIES'] = '\OCA\Contacts\VObject\GroupProperty'; -\Sabre\VObject\Property::$classMap['FN'] = '\OC\VObject\StringProperty'; -\Sabre\VObject\Property::$classMap['TITLE'] = '\OC\VObject\StringProperty'; -\Sabre\VObject\Property::$classMap['ROLE'] = '\OC\VObject\StringProperty'; -\Sabre\VObject\Property::$classMap['NOTE'] = '\OC\VObject\StringProperty'; -\Sabre\VObject\Property::$classMap['NICKNAME'] = '\OC\VObject\StringProperty'; -\Sabre\VObject\Property::$classMap['EMAIL'] = '\OC\VObject\StringProperty'; -\Sabre\VObject\Property::$classMap['TEL'] = '\OC\VObject\StringProperty'; -\Sabre\VObject\Property::$classMap['IMPP'] = '\OC\VObject\StringProperty'; -\Sabre\VObject\Property::$classMap['URL'] = '\OC\VObject\StringProperty'; -\Sabre\VObject\Property::$classMap['LABEL'] = '\OC\VObject\StringProperty'; -\Sabre\VObject\Property::$classMap['X-EVOLUTION-FILE-AS'] = '\OC\VObject\StringProperty'; -\Sabre\VObject\Property::$classMap['N'] = '\OC\VObject\CompoundProperty'; -\Sabre\VObject\Property::$classMap['ADR'] = '\OC\VObject\CompoundProperty'; -\Sabre\VObject\Property::$classMap['GEO'] = '\OC\VObject\CompoundProperty'; -\Sabre\VObject\Property::$classMap['ORG'] = '\OC\VObject\CompoundProperty'; +\Sabre\VObject\Component\VCard::$componentMap['VCARD'] = '\OCA\Contacts\VObject\VCard'; +\Sabre\VObject\Component\VCard::$propertyMap['CATEGORIES'] = '\OCA\Contacts\VObject\GroupProperty'; \OC::$server->getNavigationManager()->add(array( 'id' => 'contacts', diff --git a/appinfo/info.xml b/appinfo/info.xml index 9f798faa..e441eaef 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -4,7 +4,6 @@ Contacts AGPL Jakob Sack,Thomas Tanghus - 8 Address book with CardDAV support. @@ -14,5 +13,9 @@ appinfo/remote.php appinfo/remote.php + + + + 166044 diff --git a/appinfo/remote.php b/appinfo/remote.php index 20b50d26..0277e2a3 100644 --- a/appinfo/remote.php +++ b/appinfo/remote.php @@ -37,7 +37,7 @@ $RUNTIME_APPTYPES = array('authentication'); OC_App::loadApps($RUNTIME_APPTYPES); // Backends -$authBackend = new OC_Connector_Sabre_Auth(); +$authBackend = new \OC\Connector\Sabre\Auth(); $principalBackend = new \OC\Connector\Sabre\Principal( \OC::$server->getConfig(), \OC::$server->getUserManager() @@ -50,7 +50,6 @@ if (\OCP\Config::getAppValue('contacts', 'backend_ldap', "false") === "true") { $backends[] = 'ldap'; } $carddavBackend = new OCA\Contacts\CardDAV\Backend($backends); -$requestBackend = new OC_Connector_Sabre_Request(); // Root nodes $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend); @@ -66,23 +65,19 @@ $nodes = array( // Fire up server $server = new \Sabre\DAV\Server($nodes); -$server->httpRequest = $requestBackend; +$server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri()); $server->setBaseUri($baseuri); // Add plugins $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud')); $server->addPlugin(new OCA\Contacts\CardDAV\Plugin()); $server->addPlugin(new \Sabre\DAVACL\Plugin()); -$server->addPlugin(new \Sabre\DAV\Browser\Plugin(false)); // Show something in the Browser, but no upload $server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin()); -$server->addPlugin(new OC_Connector_Sabre_ExceptionLoggerPlugin('carddav')); +$server->addPlugin(new \OC\Connector\Sabre\ExceptionLoggerPlugin('carddav')); $server->addPlugin(new \OC\Connector\Sabre\AppEnabledPlugin( 'contacts', OC::$server->getAppManager() )); -if (defined('DEBUG') && DEBUG) { - $server->debugExceptions = true; -} // And off we go! $server->exec(); diff --git a/appinfo/routes.php b/appinfo/routes.php index 07f4f05e..77963503 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -447,17 +447,25 @@ $this->create('contacts_setpreference', 'preference/set') } ); -$this->create('contacts_index_properties', 'indexproperties/{user}/') - ->post() - ->action( - function($params) { - \OC::$server->getSession()->close(); - // TODO: Add BackgroundJob for this. - \OCP\Util::emitHook('OCA\Contacts', 'indexProperties', array()); +$userSession = \OC::$server->getUserSession(); +$currentUid = null; +if ($userSession->getUser() != null) { + $currentUid = $userSession->getUser()->getUid(); +} - \OCP\Config::setUserValue($params['user'], 'contacts', 'contacts_properties_indexed', 'yes'); - \OCP\JSON::success(array('isIndexed' => true)); - } - ) - ->requirements(array('user')) - ->defaults(array('user' => \OCP\User::getUser())); +if (!empty($currentUid)) { + $this->create('contacts_index_properties', 'indexproperties/{user}/') + ->post() + ->action( + function($params) { + \OC::$server->getSession()->close(); + // TODO: Add BackgroundJob for this. + \OCP\Util::emitHook('OCA\Contacts', 'indexProperties', array()); + + \OCP\Config::setUserValue($params['user'], 'contacts', 'contacts_properties_indexed', 'yes'); + \OCP\JSON::success(array('isIndexed' => true)); + } + ) + ->requirements(array('user')) + ->defaults(array('user' => $currentUid)); +} diff --git a/js/config.php b/js/config.php index 730bdb68..7d25cc65 100644 --- a/js/config.php +++ b/js/config.php @@ -24,7 +24,7 @@ OCP\JSON::setContentTypeHeader('text/javascript'); OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); -$user = OCP\User::getUser(); +$user = \OC::$server->getUserSession()->getUser()->getUId(); $groupsort = OCP\Config::getUserValue($user, 'contacts', 'groupsort', ''); $groupsort = explode(',', $groupsort); diff --git a/lib/addressbook.php b/lib/addressbook.php index 8600f83a..a402edfe 100644 --- a/lib/addressbook.php +++ b/lib/addressbook.php @@ -129,7 +129,7 @@ class Addressbook extends AbstractPIMCollection { public function getOwner() { return isset($this->addressBookInfo['owner']) ? $this->addressBookInfo['owner'] - : \OCP\User::getUser(); + : \OC::$server->getUserSession()->getUser()->getUId(); } /** diff --git a/lib/addressbookprovider.php b/lib/addressbookprovider.php index 82a67d97..be5b2a0b 100644 --- a/lib/addressbookprovider.php +++ b/lib/addressbookprovider.php @@ -138,7 +138,7 @@ SQL; $id = $row['contactid']; $addressbookKey = $row['addressbookid']; // Check if we are the owner of the contact - if ($row['userid'] !== \OCP\User::getUser()) { + if ($row['userid'] !== \OC::$server->getUserSession()->getUser()->getUId()) { // we aren't the owner of the contact try { // it is possible that the contact is shared with us diff --git a/lib/app.php b/lib/app.php index 2314ac7b..71981bde 100644 --- a/lib/app.php +++ b/lib/app.php @@ -65,7 +65,7 @@ class App { $backendsTableName = '*PREFIX*addressbooks_backend', $dbBackend = null ) { - $this->user = $user ? $user : \OCP\User::getUser(); + $this->user = $user ? $user : \OC::$server->getUserSession()->getUser()->getUId(); $this->addressBooksTableName = $addressBooksTableName; $this->backendsTableName = $backendsTableName; $this->dbBackend = $dbBackend diff --git a/lib/backend/abstractbackend.php b/lib/backend/abstractbackend.php index c3a79587..d8cb914a 100644 --- a/lib/backend/abstractbackend.php +++ b/lib/backend/abstractbackend.php @@ -80,7 +80,7 @@ abstract class AbstractBackend { * */ public function __construct($userid = null) { - $this->userid = $userid ? $userid : \OCP\User::getUser(); + $this->userid = $userid ? $userid : \OC::$server->getUserSession()->getUser()->getUId(); } /** diff --git a/lib/backend/ldap.php b/lib/backend/ldap.php index 5d06edfc..66f5bd34 100644 --- a/lib/backend/ldap.php +++ b/lib/backend/ldap.php @@ -245,7 +245,7 @@ class Ldap extends AbstractBackend { $userid = null, $addressBooksTableName = '*PREFIX*contacts_ldap_addressbooks' ) { - $this->userid = $userid ? $userid : \OCP\User::getUser(); + $this->userid = $userid ? $userid : \OC::$server->getUserSession()->getUser()->getUId(); $this->addressbooks = array(); } diff --git a/lib/carddav/addressbook.php b/lib/carddav/addressbook.php index d167bf1b..1467b56b 100644 --- a/lib/carddav/addressbook.php +++ b/lib/carddav/addressbook.php @@ -77,20 +77,22 @@ class AddressBook extends \Sabre\CardDAV\AddressBook { $deleteprincipal = $this->getOwner(); $uid = $this->carddavBackend->userIDByPrincipal($this->getOwner()); + $currentUid = \OC::$server->getUserSession()->getUser()->getUId(); + $readWriteACL = array( array( 'privilege' => '{DAV:}read', - 'principal' => 'principals/' . \OCP\User::getUser(), + 'principal' => 'principals/' . $currentUid, 'protected' => true, ), array( 'privilege' => '{DAV:}write', - 'principal' => 'principals/' . \OCP\User::getUser(), + 'principal' => 'principals/' . $currentUid, 'protected' => true, ), ); - if($uid !== \OCP\User::getUser()) { + if($uid !== $currentUid) { list(, $id) = explode('::', $this->addressBookInfo['id']); $sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $id); if($sharedAddressbook) { @@ -101,16 +103,16 @@ class AddressBook extends \Sabre\CardDAV\AddressBook { return $readWriteACL; } if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE) { - $createprincipal = 'principals/' . \OCP\User::getUser(); + $createprincipal = 'principals/' . $currentUid; } if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ) { - $readprincipal = 'principals/' . \OCP\User::getUser(); + $readprincipal = 'principals/' . $currentUid; } if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE) { - $writeprincipal = 'principals/' . \OCP\User::getUser(); + $writeprincipal = 'principals/' . $currentUid; } if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) { - $deleteprincipal = 'principals/' . \OCP\User::getUser(); + $deleteprincipal = 'principals/' . $currentUid; } } } else { diff --git a/lib/carddav/backend.php b/lib/carddav/backend.php index 71e5675b..a3fc5d32 100644 --- a/lib/carddav/backend.php +++ b/lib/carddav/backend.php @@ -25,6 +25,7 @@ namespace OCA\Contacts\CardDAV; use OCA\Contacts; +use \Sabre\DAV\PropPatch; /** * This class exchanges data between SabreDav and the Address book backends. @@ -55,7 +56,7 @@ class Backend extends \Sabre\CardDAV\Backend\AbstractBackend { if (is_array($addressBooks)) { foreach($addressBooks as $addressBook) { - if($addressBook['owner'] != \OCP\USER::getUser()) { + if($addressBook['owner'] != \OC::$server->getUserSession()->getUser()->getUId()) { $addressBook['uri'] = $addressBook['uri'] . '_shared_by_' . $addressBook['owner']; $addressBook['displayname'] = $addressBook['displayname']; } @@ -85,13 +86,15 @@ class Backend extends \Sabre\CardDAV\Backend\AbstractBackend { * well as the return value. * * @param mixed $addressbookid - * @param array $mutations + * @param PropPatch $mutations * @see \Sabre\DAV\IProperties::updateProperties * @return bool|array */ - public function updateAddressBook($addressbookid, array $mutations) { + public function updateAddressBook($addressbookid, PropPatch $propPatch) { $changes = array(); + $mutations = $propPatch->getRemainingMutations(); + foreach($mutations as $property=>$newvalue) { switch($property) { case '{DAV:}displayname' : diff --git a/lib/carddav/card.php b/lib/carddav/card.php index 003434f3..ae828781 100644 --- a/lib/carddav/card.php +++ b/lib/carddav/card.php @@ -68,15 +68,16 @@ class Card extends \Sabre\CardDAV\Card { $readprincipal = $this->getOwner(); $writeprincipal = $this->getOwner(); $uid = $this->carddavBackend->userIDByPrincipal($this->getOwner()); + $currentUid = \OC::$server->getUserSession()->getUser()->getUId(); - if($uid != \OCP\USER::getUser()) { + if($uid != $currentUid) { list(, $id) = explode('::', $this->addressBookInfo['id']); $sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $id); if ($sharedAddressbook && ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ)) { - $readprincipal = 'principals/' . \OCP\USER::getUser(); + $readprincipal = 'principals/' . $currentUid; } if ($sharedAddressbook && ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE)) { - $writeprincipal = 'principals/' . \OCP\USER::getUser(); + $writeprincipal = 'principals/' . $currentUid; } } diff --git a/lib/carddav/plugin.php b/lib/carddav/plugin.php index 4cd4b4e0..aecc9b4a 100644 --- a/lib/carddav/plugin.php +++ b/lib/carddav/plugin.php @@ -40,9 +40,10 @@ class Plugin extends \Sabre\CardDAV\Plugin { * An exception is thrown if it's not. * * @param resource|string $data + * @param boolean $modified whether the data was modified * @return void */ - protected function validateVCard(&$data) { + protected function validateVCard(&$data, &$modified) { // If it's a stream, we convert it to a string first. if (is_resource($data)) { @@ -61,6 +62,7 @@ class Plugin extends \Sabre\CardDAV\Plugin { throw new \Sabre\DAV\Exception\UnsupportedMediaType('This collection can only support vcard objects.'); } + $modified = true; // FIXME: set to false if neither repair nor upgrade was done $vobj->validate(VCard::REPAIR|VCard::UPGRADE); $data = $vobj->serialize(); } diff --git a/lib/connector/importconnector.php b/lib/connector/importconnector.php index 3b3e8df6..c2dc9f21 100644 --- a/lib/connector/importconnector.php +++ b/lib/connector/importconnector.php @@ -90,7 +90,10 @@ abstract class ImportConnector { } else { $curVal = $property->getValue(); if ($curVal != '') { - $curVal .= ',' . StringUtil::convertToUTF8($value); + if (!is_array($curVal)) { + $curVal = array($curVal); + } + $curVal[] = StringUtil::convertToUTF8($value); } else { $curVal = StringUtil::convertToUTF8($value); } @@ -139,7 +142,7 @@ abstract class ImportConnector { } foreach ($property->parameters as $parameter) { // Filtering types - if ($parameter->name == 'TYPE' && !strcmp($parameter->value, $importEntry['type'])) { + if ($parameter->name == 'TYPE' && !strcmp($parameter->getValue(), $importEntry['type'])) { $found=0; if (isset($importEntry->additional_property)) { // Filtering additional properties if necessary (I know, there are a lot of inner loops, sorry) @@ -162,7 +165,7 @@ abstract class ImportConnector { } // Property not found, creating one - $property = \Sabre\VObject\Property::create($importEntry['property']); + $property = $vcard->createProperty($importEntry['property']); $vcard->add($property); if ($importEntry['type']!=null) { $property->parameters[] = new \Sabre\VObject\Parameter('TYPE', ''.StringUtil::convertToUTF8($importEntry['type'])); diff --git a/lib/connector/importcsvconnector.php b/lib/connector/importcsvconnector.php index d5f74deb..4739e4ad 100644 --- a/lib/connector/importcsvconnector.php +++ b/lib/connector/importcsvconnector.php @@ -125,7 +125,7 @@ class ImportCsvConnector extends ImportConnector { * @return VCard, all unconverted elements are stored in X-Unknown-Element parameters */ public function convertElementToVCard($element, $title = null) { - $vcard = \Sabre\VObject\Component::create('VCARD'); + $vcard = new \OCA\Contacts\VObject\VCard(); $nbElt = count($element); for ($i=0; $i < $nbElt; $i++) { @@ -154,7 +154,7 @@ class ImportCsvConnector extends ImportConnector { if (isset($importEntry->vcard_favourites)) { foreach ($importEntry->vcard_favourites as $vcardFavourite) { if (strcasecmp((string)$vcardFavourite, trim($oneValue)) == 0) { - $property = \Sabre\VObject\Property::create("X-FAVOURITES", 'yes'); + $property = $vcard->createProperty("X-FAVOURITES", 'yes'); $vcard->add($property); } else { $property = $this->getOrCreateVCardProperty($vcard, $importEntry->vcard_entry); @@ -167,7 +167,7 @@ class ImportCsvConnector extends ImportConnector { } } } else if (isset($element[$i]) && isset($title[$i])) { - $property = \Sabre\VObject\Property::create("X-Unknown-Element", StringUtil::convertToUTF8($element[$i])); + $property = $vcard->createProperty("X-Unknown-Element", StringUtil::convertToUTF8($element[$i])); $property->parameters[] = new \Sabre\VObject\Parameter('TYPE', ''.StringUtil::convertToUTF8($title[$i])); $vcard->add($property); } diff --git a/lib/connector/importldifconnector.php b/lib/connector/importldifconnector.php index ec5b31a2..717901a5 100644 --- a/lib/connector/importldifconnector.php +++ b/lib/connector/importldifconnector.php @@ -117,7 +117,7 @@ class ImportLdifConnector extends ImportConnector{ * @return VCard */ public function convertElementToVCard($element) { - $dest = \Sabre\VObject\Component::create('VCARD'); + $dest = new \OCA\Contacts\VObject\VCard(); foreach ($element as $ldifProperty) { $importEntry = $this->getImportEntry($ldifProperty[0]); @@ -135,7 +135,7 @@ class ImportLdifConnector extends ImportConnector{ $this->convertElementToProperty($oneValue, $importEntry, $dest); } } else { - $property = \Sabre\VObject\Property::create("X-Unknown-Element", ''.StringUtil::convertToUTF8($ldifProperty[1])); + $property = $dest->createProperty("X-Unknown-Element", ''.StringUtil::convertToUTF8($ldifProperty[1])); $property->parameters[] = new \Sabre\VObject\Parameter('TYPE', ''.StringUtil::convertToUTF8($ldifProperty[0])); $dest->add($property); } @@ -156,7 +156,7 @@ class ImportLdifConnector extends ImportConnector{ if (isset($importEntry->vcard_favourites)) { foreach ($importEntry->vcard_favourites as $vcardFavourite) { if (strcasecmp((string)$vcardFavourite, trim($value)) == 0) { - $property = \Sabre\VObject\Property::create("X-FAVOURITES", 'yes'); + $property = $dest->createProperty("X-FAVOURITES", 'yes'); $dest->add($property); } else { $property = $this->getOrCreateVCardProperty($dest, $importEntry->vcard_entry); diff --git a/lib/connector/importvcardconnector.php b/lib/connector/importvcardconnector.php index fb37b5bc..961ddb45 100644 --- a/lib/connector/importvcardconnector.php +++ b/lib/connector/importvcardconnector.php @@ -111,14 +111,14 @@ class ImportVCardConnector extends ImportConnector{ } catch (VObject\ParseException $error) { return false; } - $dest = \Sabre\VObject\Component::create('VCARD'); + $dest = new \OCA\Contacts\VObject\VCard(); foreach ($source->children() as $sourceProperty) { $importEntry = $this->getImportEntry($sourceProperty, $source); if ($importEntry) { - $value = $sourceProperty->value; + $value = $sourceProperty->getValue(); if (isset($importEntry['remove'])) { - $value = str_replace($importEntry['remove'], '', $sourceProperty->value); + $value = str_replace($importEntry['remove'], '', $sourceProperty->getValue()); } $values = array($value); if (isset($importEntry['separator'])) { @@ -129,7 +129,7 @@ class ImportVCardConnector extends ImportConnector{ if (isset($importEntry->vcard_favourites)) { foreach ($importEntry->vcard_favourites as $vcardFavourite) { if (strcasecmp((string)$vcardFavourite, trim($oneValue)) == 0) { - $property = \Sabre\VObject\Property::create("X-FAVOURITES", 'yes'); + $property = $dest->createProperty("X-FAVOURITES", 'yes'); $dest->add($property); } else { $property = $this->getOrCreateVCardProperty($dest, $importEntry->vcard_entry); @@ -138,7 +138,7 @@ class ImportVCardConnector extends ImportConnector{ } } else { $property = $this->getOrCreateVCardProperty($dest, $importEntry->vcard_entry); - $this->updateProperty($property, $importEntry, $sourceProperty->value); + $this->updateProperty($property, $importEntry, $sourceProperty->getValue()); } } } else { @@ -166,7 +166,7 @@ class ImportVCardConnector extends ImportConnector{ $sourceGroupList = $vcard->select($groupEntry['property']); if (count($sourceGroupList>0)) { foreach ($sourceGroupList as $oneSourceGroup) { - if ($oneSourceGroup->value == $groupEntry['value'] && isset($oneSourceGroup->group) && isset($property->group) && $oneSourceGroup->group == $property->group) { + if ($oneSourceGroup->getValue() == $groupEntry['value'] && isset($oneSourceGroup->group) && isset($property->group) && $oneSourceGroup->group == $property->group) { $numElt++; } } diff --git a/lib/connector/ldapconnector.php b/lib/connector/ldapconnector.php index 1b1cbf47..8256bc93 100644 --- a/lib/connector/ldapconnector.php +++ b/lib/connector/ldapconnector.php @@ -49,7 +49,7 @@ class LdapConnector { * @return OC_VCard */ public function ldapToVCard($ldapEntry) { - $vcard = \Sabre\VObject\Component::create('VCARD'); + $vcard = new \OCA\Contacts\VObject\VCard(); $vcard->REV = $this->convertDate($ldapEntry['modifytimestamp'][0])->format(\DateTime::W3C); //error_log("modifytimestamp: ".$vcard->REV); $vcard->{'X-LDAP-DN'} = base64_encode($ldapEntry['dn']); @@ -116,9 +116,9 @@ class LdapConnector { return $property; } foreach ($property->parameters as $parameter) { - //OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.' parameter '.$parameter->value.' <> '.$v_param['type'], \OCP\Util::DEBUG); - if (!strcmp($parameter->value, $v_param['type'])) { - //OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.' parameter '.$parameter->value.' found', \OCP\Util::DEBUG); + //OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.' parameter '.$parameter->getValue().' <> '.$v_param['type'], \OCP\Util::DEBUG); + if (!strcmp($parameter->getValue(), $v_param['type'])) { + //OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.' parameter '.$parameter->getValue().' found', \OCP\Util::DEBUG); if ($counter==$index) { return $property; } @@ -130,7 +130,7 @@ class LdapConnector { // Property not found, creating one //OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.', create one '.$v_param['property'].';TYPE='.$v_param['type'], \OCP\Util::DEBUG); $line = count($vcard->children) - 1; - $property = \Sabre\VObject\Property::create($v_param['property']); + $property = $vcard->createProperty($v_param['property']); $vcard->add($property); if ($v_param['type']!=null) { //OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.', creating one '.$v_param['property'].';TYPE='.$v_param['type'], \OCP\Util::DEBUG); @@ -284,10 +284,10 @@ class LdapConnector { } } else { // Last, if the ldif entry has a vcard_position set, take only the value in the position index - $value = $property->value; + $value = $property->getValue(); if (isset($ldifEntry['vcard_position'])) { //\OC_Log::write('ldapconnector', __METHOD__." position set ".$ldifEntry['vcard_position'], \OC_Log::DEBUG); - $tmpValues = explode(";", $property->value); + $tmpValues = explode(";", $property->getValue()); $value = $tmpValues[$ldifEntry['vcard_position']]; } //\OC_Log::write('ldapconnector', __METHOD__.__METHOD__." entry : ".$ldifEntry['name']." - value : $value", \OC_Log::DEBUG); diff --git a/lib/contact.php b/lib/contact.php index b7a2e710..7d649e90 100644 --- a/lib/contact.php +++ b/lib/contact.php @@ -57,6 +57,8 @@ class Contact extends VObject\VCard implements IPIMObject { * @param mixed $data */ public function __construct($parent, $backend, $data = null) { + parent::__construct('VCARD'); + self::$l10n = $parent::$l10n; //\OCP\Util::writeLog('contacts', __METHOD__ . ' , data: ' . print_r($data, true), \OCP\Util::DEBUG); $this->props['parent'] = $parent; @@ -313,7 +315,7 @@ class Contact extends VObject\VCard implements IPIMObject { * @return bool */ public function retrieve() { - if ($this->isRetrieved() || count($this->children) > 1) { + if ($this->isRetrieved()) { //\OCP\Util::writeLog('contacts', __METHOD__. ' children', \OCP\Util::DEBUG); return true; } else { @@ -324,7 +326,7 @@ class Contact extends VObject\VCard implements IPIMObject { $this->add($child); if($child->name === 'FN') { $this->props['displayname'] - = strtr($child->value, array('\,' => ',', '\;' => ';', '\\\\' => '\\')); + = strtr($child->getValue(), array('\,' => ',', '\;' => ';', '\\\\' => '\\')); } } $this->setRetrieved(true); @@ -374,7 +376,11 @@ class Contact extends VObject\VCard implements IPIMObject { ); if ($obj) { foreach ($obj->children as $child) { - $this->add($child); + if($child->name === 'VERSION' || $child->name === 'PRODID') { + parent::__set($child->name, $child); + } else { + $this->add($child); + } } $this->setRetrieved(true); $this->setSaved(true); @@ -508,7 +514,7 @@ class Contact extends VObject\VCard implements IPIMObject { */ public function setPropertyByChecksum($checksum, $name, $value, $parameters=array()) { if ($checksum === 'new') { - $property = Property::create($name); + $property = $this->createProperty($name); $this->add($property); } else { $property = $this->getPropertyByChecksum($checksum); @@ -582,7 +588,7 @@ class Contact extends VObject\VCard implements IPIMObject { case 'ORG': $property = $this->select($name); if (count($property) === 0) { - $property = \Sabre\VObject\Property::create($name); + $property = $this->createProperty($name); $this->add($property); } else { // Actually no idea why this works @@ -715,7 +721,7 @@ class Contact extends VObject\VCard implements IPIMObject { continue; } else { foreach ($ownproperties as $ownproperty) { - if (strtolower($property->value) === strtolower($ownproperty->value)) { + if (strtolower($property->getValue()) === strtolower($ownproperty->getValue())) { // We already have this property, so skip both loops continue 2; } @@ -728,7 +734,7 @@ class Contact extends VObject\VCard implements IPIMObject { $this->add($property); $updated = true; } else { - $this->setPropertyByName($property->name, $property->value, $property->parameters); + $this->setPropertyByName($property->name, $property->getValue(), $property->parameters); } } } @@ -819,18 +825,18 @@ class Contact extends VObject\VCard implements IPIMObject { } catch(\Exception $e) { return; } - $vevent = \Sabre\VObject\Component::create('VEVENT'); + $vcal = new \Sabre\VObject\Component\VCalendar(); + $vcal->VERSION = '2.0'; + $vcal->createComponent('VEVENT'); $vevent->add('DTSTART'); $vevent->DTSTART->setDateTime( - $date, - \Sabre\VObject\Property\DateTime::DATE + $date ); + $event->DTSTART['VALUE'] = 'date'; $vevent->add('DURATION', 'P1D'); $vevent->{'UID'} = $this->UID; $vevent->{'RRULE'} = 'FREQ=YEARLY'; $vevent->{'SUMMARY'} = $title . ' (' . $date->format('Y') . ')'; - $vcal = \Sabre\VObject\Component::create('VCALENDAR'); - $vcal->VERSION = '2.0'; $appinfo = \OCP\App::getAppInfo('contacts'); $appversion = \OCP\App::getAppVersion('contacts'); $vcal->PRODID = '-//ownCloud//NONSGML '.$appinfo['name'].' '.$appversion.'//EN'; diff --git a/lib/controller/groupcontroller.php b/lib/controller/groupcontroller.php index 5d352320..f0c72c37 100644 --- a/lib/controller/groupcontroller.php +++ b/lib/controller/groupcontroller.php @@ -53,12 +53,13 @@ class GroupController extends Controller { $shares[$key]['length'] = count($children); } + $currentUid = \OC::$server->getUserSession()->getUser()->getUId(); $groups = array( 'categories' => $tags, 'favorites' => $favorites, 'shared' => $shares, - 'lastgroup' => \OCP\Config::getUserValue(\OCP\User::getUser(), 'contacts', 'lastgroup', 'all'), - 'sortorder' => \OCP\Config::getUserValue(\OCP\User::getUser(), 'contacts', 'groupsort', ''), + 'lastgroup' => \OCP\Config::getUserValue($currentUid, 'contacts', 'lastgroup', 'all'), + 'sortorder' => \OCP\Config::getUserValue($currentUid, 'contacts', 'groupsort', ''), ); return new JSONResponse($groups); @@ -348,7 +349,7 @@ class GroupController extends Controller { * in parentheses, like "Tag (owner)". */ private function displayName($tag) { - if ($tag['owner'] != \OCP\User::getUser()) { + if ($tag['owner'] != \OC::$server->getUserSession()->getUser()->getUId()) { return $tag['name'] . ' ('. $tag['owner'] . ')'; } return $tag['name']; diff --git a/lib/controller/importcontroller.php b/lib/controller/importcontroller.php index 721f8be6..268982ab 100644 --- a/lib/controller/importcontroller.php +++ b/lib/controller/importcontroller.php @@ -159,7 +159,7 @@ class ImportController extends Controller { $request = $this->request; $response = new JSONResponse(); $params = $this->request->urlParams; - $app = new App(\OCP\User::getUser()); + $app = new App(\OC::$server->getUserSession()->getUser()->getUId()); $addressBookId = $params['addressBookId']; $format = $params['importType']; diff --git a/lib/controller/settingscontroller.php b/lib/controller/settingscontroller.php index 8ec325dd..8dd2f367 100644 --- a/lib/controller/settingscontroller.php +++ b/lib/controller/settingscontroller.php @@ -40,7 +40,7 @@ class SettingsController extends Controller { $response->bailOut(App::$l10n->t('No value is given.')); } - if(\OCP\Config::setUserValue(\OCP\User::getUser(), 'contacts', $key, $value)) { + if(\OCP\Config::setUserValue(\OC::$server->getUserSession()->getUser()->getUId(), 'contacts', $key, $value)) { $response->setParams(array( 'key' => $key, 'value' => $value) @@ -52,4 +52,4 @@ class SettingsController extends Controller { ); } } -} \ No newline at end of file +} diff --git a/lib/share/addressbook.php b/lib/share/addressbook.php index 59c26229..7fc567e2 100644 --- a/lib/share/addressbook.php +++ b/lib/share/addressbook.php @@ -22,7 +22,7 @@ class Addressbook implements \OCP\Share_Backend_Collection { public $app; public function __construct() { - $this->app = new App(\OCP\User::getUser()); + $this->app = new App(\OC::$server->getUserSession()->getUser()->getUId()); } /** diff --git a/lib/share/contact.php b/lib/share/contact.php index 136e1974..bf7e7000 100644 --- a/lib/share/contact.php +++ b/lib/share/contact.php @@ -37,7 +37,7 @@ class Contact implements \OCP\Share_Backend { public $backend; public function __construct() { - $this->app = new App(\OCP\User::getUser()); + $this->app = new App(\OC::$server->getUserSession()->getUser()->getUId()); $this->backend = $this->app->getBackend('local'); } diff --git a/lib/utils/jsonserializer.php b/lib/utils/jsonserializer.php index 84e33a78..7f5bd6dd 100644 --- a/lib/utils/jsonserializer.php +++ b/lib/utils/jsonserializer.php @@ -106,7 +106,7 @@ class JSONSerializer { if(!is_null($temp)) { // Get Apple X-ABLabels if(isset($contact->{$property->group . '.X-ABLABEL'})) { - $temp['label'] = $contact->{$property->group . '.X-ABLABEL'}->value; + $temp['label'] = $contact->{$property->group . '.X-ABLABEL'}->getValue(); if($temp['label'] == '_$!!$_') { $temp['label'] = Properties::$l10n->t('Other'); } @@ -142,7 +142,7 @@ class JSONSerializer { if(!in_array($property->name, Properties::$indexProperties)) { return; } - $value = $property->value; + $value = $property->getValue(); if($property->name == 'ADR' || $property->name == 'N' || $property->name == 'ORG' || $property->name == 'CATEGORIES') { $value = $property->getParts(); $value = array_map('trim', $value); @@ -195,15 +195,15 @@ class JSONSerializer { // Faulty entries by kaddressbook // Actually TYPE=PREF is correct according to RFC 2426 // but this way is more handy in the UI. Tanghus. - if($parameter->name == 'TYPE' && strtoupper($parameter->value) == 'PREF') { + if($parameter->name == 'TYPE' && strtoupper($parameter->getValue()) == 'PREF') { $parameter->name = 'PREF'; - $parameter->value = '1'; + $parameter->setValue('1'); } // NOTE: Apparently \Sabre\VObject\Reader can't always deal with value list parameters // like TYPE=HOME,CELL,VOICE. Tanghus. // TODO: Check if parameter is has commas and split + merge if so. if ($parameter->name == 'TYPE') { - $pvalue = $parameter->value; + $pvalue = $parameter->getValue(); if(is_string($pvalue) && strpos($pvalue, ',') !== false) { $pvalue = array_map('trim', explode(',', $pvalue)); } @@ -216,7 +216,7 @@ class JSONSerializer { } } else{ - $temp['parameters'][$parameter->name] = \OCP\Util::sanitizeHTML($parameter->value); + $temp['parameters'][$parameter->name] = \OCP\Util::sanitizeHTML($parameter->getValue()); } } return $temp; diff --git a/lib/utils/properties.php b/lib/utils/properties.php index 89cb3dd7..40f6d73a 100644 --- a/lib/utils/properties.php +++ b/lib/utils/properties.php @@ -260,7 +260,7 @@ Class Properties { } $preferred = 0; foreach($property->parameters as $parameter) { - if($parameter->name == 'TYPE' && strtoupper($parameter->value) == 'PREF') { + if($parameter->name == 'TYPE' && strtoupper($parameter->getValue()) == 'PREF') { $preferred = 1; break; } @@ -268,10 +268,10 @@ Class Properties { try { $result = self::$updateindexstmt->execute( array( - \OCP\User::getUser(), + \OC::$server->getUserSession()->getUser()->getUId(), $contactid, $property->name, - substr($property->value, 0, 254), + substr($property->getValue(), 0, 254), $preferred, ) ); diff --git a/lib/vobject/groupproperty.php b/lib/vobject/groupproperty.php index 9b8617a1..1a4265f4 100644 --- a/lib/vobject/groupproperty.php +++ b/lib/vobject/groupproperty.php @@ -29,7 +29,7 @@ use OC\VObject\CompoundProperty; * * NOTE: Group names are case-insensitive. */ -class GroupProperty extends CompoundProperty { +class GroupProperty extends \Sabre\VObject\Property\Text { /** * Add a group. @@ -117,4 +117,4 @@ class GroupProperty extends CompoundProperty { } return array_search(strtolower($needle), array_map('strtolower', $haystack)); } -} \ No newline at end of file +} diff --git a/lib/vobject/stringproperty.php b/lib/vobject/stringproperty.php deleted file mode 100644 index 013f8d77..00000000 --- a/lib/vobject/stringproperty.php +++ /dev/null @@ -1,82 +0,0 @@ -. - * - */ - -namespace OCA\Contacts\VObject; - -use Sabre\VObject; - -/** - * This class overrides \Sabre\VObject\Property::serialize() to properly - * escape commas and semi-colons in string properties. -*/ -class StringProperty extends VObject\Property { - - /** - * Turns the object back into a serialized clob. - * - * @return string - */ - public function serialize() { - - $str = $this->name; - if ($this->group) { - $str = $this->group . '.' . $this->name; - } - - foreach($this->parameters as $param) { - $str.=';' . $param->serialize(); - } - - $src = array( - '\\', - "\n", - ';', - ',', - ); - $out = array( - '\\\\', - '\n', - '\;', - '\,', - ); - $value = strtr($this->value, array('\,' => ',', '\;' => ';', '\\\\' => '\\')); - $str.=':' . str_replace($src, $out, $value); - - $out = ''; - while(strlen($str) > 0) { - if (strlen($str) > 75) { - $out .= mb_strcut($str, 0, 75, 'utf-8') . "\r\n"; - $str = ' ' . mb_strcut($str, 75, strlen($str), 'utf-8'); - } else { - $out .= $str . "\r\n"; - $str = ''; - break; - } - } - - return $out; - - } - -} \ No newline at end of file diff --git a/lib/vobject/vcard.php b/lib/vobject/vcard.php index fb429d06..bedb56c5 100644 --- a/lib/vobject/vcard.php +++ b/lib/vobject/vcard.php @@ -121,22 +121,22 @@ class VCard extends VObject\Component\VCard { foreach($property->parameters as $key=>&$parameter) { // Check for values without names which Sabre interprets // as names without values. - if(trim($parameter->value) === '') { - $parameter->value = $parameter->name; + if(trim($parameter->getValue()) === '') { + $parameter->setValue($parameter->name); $parameter->name = $this->paramName($parameter->name); } // Check out for encoded string and decode them :-[ if(strtoupper($parameter->name) == 'ENCODING') { - if(strtoupper($parameter->value) == 'QUOTED-PRINTABLE') { - $property->value = str_replace( + if(strtoupper($parameter->getValue()) == 'QUOTED-PRINTABLE') { + $property->setValue(str_replace( "\r\n", "\n", VObject\StringUtil::convertToUTF8( - quoted_printable_decode($property->value) + quoted_printable_decode($property->getValue()) ) - ); + )); unset($property->parameters[$key]); - } elseif(strtoupper($parameter->value) == 'BASE64') { - $parameter->value = 'b'; + } elseif(strtoupper($parameter->getValue()) == 'BASE64') { + $parameter->setValue('b'); } } elseif(strtoupper($parameter->name) == 'CHARSET') { unset($property->parameters[$key]); @@ -154,12 +154,12 @@ class VCard extends VObject\Component\VCard { // Work around issue in older VObject sersions // https://github.com/fruux/sabre-vobject/issues/24 foreach($property->parameters as $key=>$parameter) { - if(strpos($parameter->value, ',') === false) { + if(strpos($parameter->getValue(), ',') === false) { continue; } - $values = explode(',', $parameter->value); + $values = explode(',', $parameter->getValue()); $values = array_map('trim', $values); - $parameter->value = array_shift($values); + $parameter->setValue(array_shift($values)); foreach($values as $value) { $property->add($parameter->name, $value); } @@ -305,7 +305,7 @@ class VCard extends VObject\Component\VCard { if(count($slice) < 2) { // If not enought, add one more... $slice[] = ""; } - $this->N = implode(';', $slice).';;;'; + $this->N = $slice; } } diff --git a/settings.php b/settings.php index fa70992f..102ab190 100644 --- a/settings.php +++ b/settings.php @@ -1,6 +1,6 @@ assign('addressbooks', OCA\Contacts\Addressbook::all(OCP\USER::getUser())); +$tmpl->assign('addressbooks', OCA\Contacts\Addressbook::all(\OC::$server->getUserSession()->getUser()->getUId())); $tmpl->printPage(); diff --git a/templates/contacts.php b/templates/contacts.php index 00c188ba..6c117168 100644 --- a/templates/contacts.php +++ b/templates/contacts.php @@ -449,7 +449,7 @@ vendor_style('contacts', array(
-
  • +