mirror of
https://github.com/owncloudarchive/contacts.git
synced 2025-02-07 01:54:16 +01:00
commit
ee6a694539
@ -12,23 +12,8 @@ namespace OCA\Contacts;
|
|||||||
use \OC\AppFramework\Core\API;
|
use \OC\AppFramework\Core\API;
|
||||||
|
|
||||||
//require_once __DIR__ . '/../lib/controller/pagecontroller.php';
|
//require_once __DIR__ . '/../lib/controller/pagecontroller.php';
|
||||||
\Sabre\VObject\Component::$classMap['VCARD'] = '\OCA\Contacts\VObject\VCard';
|
\Sabre\VObject\Component\VCard::$componentMap['VCARD'] = '\OCA\Contacts\VObject\VCard';
|
||||||
\Sabre\VObject\Property::$classMap['CATEGORIES'] = '\OCA\Contacts\VObject\GroupProperty';
|
\Sabre\VObject\Component\VCard::$propertyMap['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';
|
|
||||||
|
|
||||||
\OC::$server->getNavigationManager()->add(array(
|
\OC::$server->getNavigationManager()->add(array(
|
||||||
'id' => 'contacts',
|
'id' => 'contacts',
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
<name>Contacts</name>
|
<name>Contacts</name>
|
||||||
<licence>AGPL</licence>
|
<licence>AGPL</licence>
|
||||||
<author>Jakob Sack,Thomas Tanghus</author>
|
<author>Jakob Sack,Thomas Tanghus</author>
|
||||||
<require>8</require>
|
|
||||||
<description>Address book with CardDAV support.</description>
|
<description>Address book with CardDAV support.</description>
|
||||||
<standalone/>
|
<standalone/>
|
||||||
<documentation>
|
<documentation>
|
||||||
@ -14,5 +13,9 @@
|
|||||||
<contacts>appinfo/remote.php</contacts>
|
<contacts>appinfo/remote.php</contacts>
|
||||||
<carddav>appinfo/remote.php</carddav>
|
<carddav>appinfo/remote.php</carddav>
|
||||||
</remote>
|
</remote>
|
||||||
|
<dependencies>
|
||||||
|
<owncloud min-version="8" />
|
||||||
|
<php min-version="5.4" />
|
||||||
|
</dependencies>
|
||||||
<ocsid>166044</ocsid>
|
<ocsid>166044</ocsid>
|
||||||
</info>
|
</info>
|
||||||
|
@ -37,7 +37,7 @@ $RUNTIME_APPTYPES = array('authentication');
|
|||||||
OC_App::loadApps($RUNTIME_APPTYPES);
|
OC_App::loadApps($RUNTIME_APPTYPES);
|
||||||
|
|
||||||
// Backends
|
// Backends
|
||||||
$authBackend = new OC_Connector_Sabre_Auth();
|
$authBackend = new \OC\Connector\Sabre\Auth();
|
||||||
$principalBackend = new \OC\Connector\Sabre\Principal(
|
$principalBackend = new \OC\Connector\Sabre\Principal(
|
||||||
\OC::$server->getConfig(),
|
\OC::$server->getConfig(),
|
||||||
\OC::$server->getUserManager()
|
\OC::$server->getUserManager()
|
||||||
@ -50,7 +50,6 @@ if (\OCP\Config::getAppValue('contacts', 'backend_ldap', "false") === "true") {
|
|||||||
$backends[] = 'ldap';
|
$backends[] = 'ldap';
|
||||||
}
|
}
|
||||||
$carddavBackend = new OCA\Contacts\CardDAV\Backend($backends);
|
$carddavBackend = new OCA\Contacts\CardDAV\Backend($backends);
|
||||||
$requestBackend = new OC_Connector_Sabre_Request();
|
|
||||||
|
|
||||||
// Root nodes
|
// Root nodes
|
||||||
$principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend);
|
$principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend);
|
||||||
@ -66,23 +65,19 @@ $nodes = array(
|
|||||||
|
|
||||||
// Fire up server
|
// Fire up server
|
||||||
$server = new \Sabre\DAV\Server($nodes);
|
$server = new \Sabre\DAV\Server($nodes);
|
||||||
$server->httpRequest = $requestBackend;
|
$server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri());
|
||||||
$server->setBaseUri($baseuri);
|
$server->setBaseUri($baseuri);
|
||||||
// Add plugins
|
// Add plugins
|
||||||
$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud'));
|
$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud'));
|
||||||
$server->addPlugin(new OCA\Contacts\CardDAV\Plugin());
|
$server->addPlugin(new OCA\Contacts\CardDAV\Plugin());
|
||||||
$server->addPlugin(new \Sabre\DAVACL\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 \Sabre\CardDAV\VCFExportPlugin());
|
||||||
$server->addPlugin(new OC_Connector_Sabre_ExceptionLoggerPlugin('carddav'));
|
$server->addPlugin(new \OC\Connector\Sabre\ExceptionLoggerPlugin('carddav', \OC::$server->getLogger()));
|
||||||
$server->addPlugin(new \OC\Connector\Sabre\AppEnabledPlugin(
|
$server->addPlugin(new \OC\Connector\Sabre\AppEnabledPlugin(
|
||||||
'contacts',
|
'contacts',
|
||||||
OC::$server->getAppManager()
|
OC::$server->getAppManager()
|
||||||
));
|
));
|
||||||
|
|
||||||
if (defined('DEBUG') && DEBUG) {
|
|
||||||
$server->debugExceptions = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// And off we go!
|
// And off we go!
|
||||||
$server->exec();
|
$server->exec();
|
||||||
|
@ -447,17 +447,25 @@ $this->create('contacts_setpreference', 'preference/set')
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->create('contacts_index_properties', 'indexproperties/{user}/')
|
$userSession = \OC::$server->getUserSession();
|
||||||
->post()
|
$currentUid = null;
|
||||||
->action(
|
if ($userSession->getUser() != null) {
|
||||||
function($params) {
|
$currentUid = $userSession->getUser()->getUid();
|
||||||
\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');
|
if (!empty($currentUid)) {
|
||||||
\OCP\JSON::success(array('isIndexed' => true));
|
$this->create('contacts_index_properties', 'indexproperties/{user}/')
|
||||||
}
|
->post()
|
||||||
)
|
->action(
|
||||||
->requirements(array('user'))
|
function($params) {
|
||||||
->defaults(array('user' => \OCP\User::getUser()));
|
\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));
|
||||||
|
}
|
||||||
|
@ -24,7 +24,7 @@ OCP\JSON::setContentTypeHeader('text/javascript');
|
|||||||
OCP\JSON::checkLoggedIn();
|
OCP\JSON::checkLoggedIn();
|
||||||
OCP\JSON::checkAppEnabled('contacts');
|
OCP\JSON::checkAppEnabled('contacts');
|
||||||
|
|
||||||
$user = OCP\User::getUser();
|
$user = \OC::$server->getUserSession()->getUser()->getUId();
|
||||||
|
|
||||||
$groupsort = OCP\Config::getUserValue($user, 'contacts', 'groupsort', '');
|
$groupsort = OCP\Config::getUserValue($user, 'contacts', 'groupsort', '');
|
||||||
$groupsort = explode(',', $groupsort);
|
$groupsort = explode(',', $groupsort);
|
||||||
|
@ -129,7 +129,7 @@ class Addressbook extends AbstractPIMCollection {
|
|||||||
public function getOwner() {
|
public function getOwner() {
|
||||||
return isset($this->addressBookInfo['owner'])
|
return isset($this->addressBookInfo['owner'])
|
||||||
? $this->addressBookInfo['owner']
|
? $this->addressBookInfo['owner']
|
||||||
: \OCP\User::getUser();
|
: \OC::$server->getUserSession()->getUser()->getUId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -138,7 +138,7 @@ SQL;
|
|||||||
$id = $row['contactid'];
|
$id = $row['contactid'];
|
||||||
$addressbookKey = $row['addressbookid'];
|
$addressbookKey = $row['addressbookid'];
|
||||||
// Check if we are the owner of the contact
|
// 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
|
// we aren't the owner of the contact
|
||||||
try {
|
try {
|
||||||
// it is possible that the contact is shared with us
|
// it is possible that the contact is shared with us
|
||||||
|
@ -65,7 +65,7 @@ class App {
|
|||||||
$backendsTableName = '*PREFIX*addressbooks_backend',
|
$backendsTableName = '*PREFIX*addressbooks_backend',
|
||||||
$dbBackend = null
|
$dbBackend = null
|
||||||
) {
|
) {
|
||||||
$this->user = $user ? $user : \OCP\User::getUser();
|
$this->user = $user ? $user : \OC::$server->getUserSession()->getUser()->getUId();
|
||||||
$this->addressBooksTableName = $addressBooksTableName;
|
$this->addressBooksTableName = $addressBooksTableName;
|
||||||
$this->backendsTableName = $backendsTableName;
|
$this->backendsTableName = $backendsTableName;
|
||||||
$this->dbBackend = $dbBackend
|
$this->dbBackend = $dbBackend
|
||||||
|
@ -80,7 +80,7 @@ abstract class AbstractBackend {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct($userid = null) {
|
public function __construct($userid = null) {
|
||||||
$this->userid = $userid ? $userid : \OCP\User::getUser();
|
$this->userid = $userid ? $userid : \OC::$server->getUserSession()->getUser()->getUId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -245,7 +245,7 @@ class Ldap extends AbstractBackend {
|
|||||||
$userid = null,
|
$userid = null,
|
||||||
$addressBooksTableName = '*PREFIX*contacts_ldap_addressbooks'
|
$addressBooksTableName = '*PREFIX*contacts_ldap_addressbooks'
|
||||||
) {
|
) {
|
||||||
$this->userid = $userid ? $userid : \OCP\User::getUser();
|
$this->userid = $userid ? $userid : \OC::$server->getUserSession()->getUser()->getUId();
|
||||||
$this->addressbooks = array();
|
$this->addressbooks = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,20 +77,22 @@ class AddressBook extends \Sabre\CardDAV\AddressBook {
|
|||||||
$deleteprincipal = $this->getOwner();
|
$deleteprincipal = $this->getOwner();
|
||||||
$uid = $this->carddavBackend->userIDByPrincipal($this->getOwner());
|
$uid = $this->carddavBackend->userIDByPrincipal($this->getOwner());
|
||||||
|
|
||||||
|
$currentUid = \OC::$server->getUserSession()->getUser()->getUId();
|
||||||
|
|
||||||
$readWriteACL = array(
|
$readWriteACL = array(
|
||||||
array(
|
array(
|
||||||
'privilege' => '{DAV:}read',
|
'privilege' => '{DAV:}read',
|
||||||
'principal' => 'principals/' . \OCP\User::getUser(),
|
'principal' => 'principals/' . $currentUid,
|
||||||
'protected' => true,
|
'protected' => true,
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'privilege' => '{DAV:}write',
|
'privilege' => '{DAV:}write',
|
||||||
'principal' => 'principals/' . \OCP\User::getUser(),
|
'principal' => 'principals/' . $currentUid,
|
||||||
'protected' => true,
|
'protected' => true,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if($uid !== \OCP\User::getUser()) {
|
if($uid !== $currentUid) {
|
||||||
list(, $id) = explode('::', $this->addressBookInfo['id']);
|
list(, $id) = explode('::', $this->addressBookInfo['id']);
|
||||||
$sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $id);
|
$sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $id);
|
||||||
if($sharedAddressbook) {
|
if($sharedAddressbook) {
|
||||||
@ -101,16 +103,16 @@ class AddressBook extends \Sabre\CardDAV\AddressBook {
|
|||||||
return $readWriteACL;
|
return $readWriteACL;
|
||||||
}
|
}
|
||||||
if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE) {
|
if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE) {
|
||||||
$createprincipal = 'principals/' . \OCP\User::getUser();
|
$createprincipal = 'principals/' . $currentUid;
|
||||||
}
|
}
|
||||||
if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ) {
|
if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ) {
|
||||||
$readprincipal = 'principals/' . \OCP\User::getUser();
|
$readprincipal = 'principals/' . $currentUid;
|
||||||
}
|
}
|
||||||
if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE) {
|
if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE) {
|
||||||
$writeprincipal = 'principals/' . \OCP\User::getUser();
|
$writeprincipal = 'principals/' . $currentUid;
|
||||||
}
|
}
|
||||||
if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) {
|
if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) {
|
||||||
$deleteprincipal = 'principals/' . \OCP\User::getUser();
|
$deleteprincipal = 'principals/' . $currentUid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
namespace OCA\Contacts\CardDAV;
|
namespace OCA\Contacts\CardDAV;
|
||||||
|
|
||||||
use OCA\Contacts;
|
use OCA\Contacts;
|
||||||
|
use \Sabre\DAV\PropPatch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class exchanges data between SabreDav and the Address book backends.
|
* 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)) {
|
if (is_array($addressBooks)) {
|
||||||
foreach($addressBooks as $addressBook) {
|
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['uri'] = $addressBook['uri'] . '_shared_by_' . $addressBook['owner'];
|
||||||
$addressBook['displayname'] = $addressBook['displayname'];
|
$addressBook['displayname'] = $addressBook['displayname'];
|
||||||
}
|
}
|
||||||
@ -85,13 +86,15 @@ class Backend extends \Sabre\CardDAV\Backend\AbstractBackend {
|
|||||||
* well as the return value.
|
* well as the return value.
|
||||||
*
|
*
|
||||||
* @param mixed $addressbookid
|
* @param mixed $addressbookid
|
||||||
* @param array $mutations
|
* @param PropPatch $mutations
|
||||||
* @see \Sabre\DAV\IProperties::updateProperties
|
* @see \Sabre\DAV\IProperties::updateProperties
|
||||||
* @return bool|array
|
* @return bool|array
|
||||||
*/
|
*/
|
||||||
public function updateAddressBook($addressbookid, array $mutations) {
|
public function updateAddressBook($addressbookid, PropPatch $propPatch) {
|
||||||
$changes = array();
|
$changes = array();
|
||||||
|
|
||||||
|
$mutations = $propPatch->getRemainingMutations();
|
||||||
|
|
||||||
foreach($mutations as $property=>$newvalue) {
|
foreach($mutations as $property=>$newvalue) {
|
||||||
switch($property) {
|
switch($property) {
|
||||||
case '{DAV:}displayname' :
|
case '{DAV:}displayname' :
|
||||||
|
@ -68,15 +68,16 @@ class Card extends \Sabre\CardDAV\Card {
|
|||||||
$readprincipal = $this->getOwner();
|
$readprincipal = $this->getOwner();
|
||||||
$writeprincipal = $this->getOwner();
|
$writeprincipal = $this->getOwner();
|
||||||
$uid = $this->carddavBackend->userIDByPrincipal($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']);
|
list(, $id) = explode('::', $this->addressBookInfo['id']);
|
||||||
$sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $id);
|
$sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $id);
|
||||||
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ)) {
|
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ)) {
|
||||||
$readprincipal = 'principals/' . \OCP\USER::getUser();
|
$readprincipal = 'principals/' . $currentUid;
|
||||||
}
|
}
|
||||||
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE)) {
|
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE)) {
|
||||||
$writeprincipal = 'principals/' . \OCP\USER::getUser();
|
$writeprincipal = 'principals/' . $currentUid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,9 +40,10 @@ class Plugin extends \Sabre\CardDAV\Plugin {
|
|||||||
* An exception is thrown if it's not.
|
* An exception is thrown if it's not.
|
||||||
*
|
*
|
||||||
* @param resource|string $data
|
* @param resource|string $data
|
||||||
|
* @param boolean $modified whether the data was modified
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function validateVCard(&$data) {
|
protected function validateVCard(&$data, &$modified) {
|
||||||
|
|
||||||
// If it's a stream, we convert it to a string first.
|
// If it's a stream, we convert it to a string first.
|
||||||
if (is_resource($data)) {
|
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.');
|
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);
|
$vobj->validate(VCard::REPAIR|VCard::UPGRADE);
|
||||||
$data = $vobj->serialize();
|
$data = $vobj->serialize();
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,10 @@ abstract class ImportConnector {
|
|||||||
} else {
|
} else {
|
||||||
$curVal = $property->getValue();
|
$curVal = $property->getValue();
|
||||||
if ($curVal != '') {
|
if ($curVal != '') {
|
||||||
$curVal .= ',' . StringUtil::convertToUTF8($value);
|
if (!is_array($curVal)) {
|
||||||
|
$curVal = array($curVal);
|
||||||
|
}
|
||||||
|
$curVal[] = StringUtil::convertToUTF8($value);
|
||||||
} else {
|
} else {
|
||||||
$curVal = StringUtil::convertToUTF8($value);
|
$curVal = StringUtil::convertToUTF8($value);
|
||||||
}
|
}
|
||||||
@ -139,7 +142,7 @@ abstract class ImportConnector {
|
|||||||
}
|
}
|
||||||
foreach ($property->parameters as $parameter) {
|
foreach ($property->parameters as $parameter) {
|
||||||
// Filtering types
|
// Filtering types
|
||||||
if ($parameter->name == 'TYPE' && !strcmp($parameter->value, $importEntry['type'])) {
|
if ($parameter->name == 'TYPE' && !strcmp($parameter->getValue(), $importEntry['type'])) {
|
||||||
$found=0;
|
$found=0;
|
||||||
if (isset($importEntry->additional_property)) {
|
if (isset($importEntry->additional_property)) {
|
||||||
// Filtering additional properties if necessary (I know, there are a lot of inner loops, sorry)
|
// 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 not found, creating one
|
||||||
$property = \Sabre\VObject\Property::create($importEntry['property']);
|
$property = $vcard->createProperty($importEntry['property']);
|
||||||
$vcard->add($property);
|
$vcard->add($property);
|
||||||
if ($importEntry['type']!=null) {
|
if ($importEntry['type']!=null) {
|
||||||
$property->parameters[] = new \Sabre\VObject\Parameter('TYPE', ''.StringUtil::convertToUTF8($importEntry['type']));
|
$property->parameters[] = new \Sabre\VObject\Parameter('TYPE', ''.StringUtil::convertToUTF8($importEntry['type']));
|
||||||
|
@ -125,7 +125,7 @@ class ImportCsvConnector extends ImportConnector {
|
|||||||
* @return VCard, all unconverted elements are stored in X-Unknown-Element parameters
|
* @return VCard, all unconverted elements are stored in X-Unknown-Element parameters
|
||||||
*/
|
*/
|
||||||
public function convertElementToVCard($element, $title = null) {
|
public function convertElementToVCard($element, $title = null) {
|
||||||
$vcard = \Sabre\VObject\Component::create('VCARD');
|
$vcard = new \OCA\Contacts\VObject\VCard();
|
||||||
|
|
||||||
$nbElt = count($element);
|
$nbElt = count($element);
|
||||||
for ($i=0; $i < $nbElt; $i++) {
|
for ($i=0; $i < $nbElt; $i++) {
|
||||||
@ -154,7 +154,7 @@ class ImportCsvConnector extends ImportConnector {
|
|||||||
if (isset($importEntry->vcard_favourites)) {
|
if (isset($importEntry->vcard_favourites)) {
|
||||||
foreach ($importEntry->vcard_favourites as $vcardFavourite) {
|
foreach ($importEntry->vcard_favourites as $vcardFavourite) {
|
||||||
if (strcasecmp((string)$vcardFavourite, trim($oneValue)) == 0) {
|
if (strcasecmp((string)$vcardFavourite, trim($oneValue)) == 0) {
|
||||||
$property = \Sabre\VObject\Property::create("X-FAVOURITES", 'yes');
|
$property = $vcard->createProperty("X-FAVOURITES", 'yes');
|
||||||
$vcard->add($property);
|
$vcard->add($property);
|
||||||
} else {
|
} else {
|
||||||
$property = $this->getOrCreateVCardProperty($vcard, $importEntry->vcard_entry);
|
$property = $this->getOrCreateVCardProperty($vcard, $importEntry->vcard_entry);
|
||||||
@ -167,7 +167,7 @@ class ImportCsvConnector extends ImportConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (isset($element[$i]) && isset($title[$i])) {
|
} 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]));
|
$property->parameters[] = new \Sabre\VObject\Parameter('TYPE', ''.StringUtil::convertToUTF8($title[$i]));
|
||||||
$vcard->add($property);
|
$vcard->add($property);
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ class ImportLdifConnector extends ImportConnector{
|
|||||||
* @return VCard
|
* @return VCard
|
||||||
*/
|
*/
|
||||||
public function convertElementToVCard($element) {
|
public function convertElementToVCard($element) {
|
||||||
$dest = \Sabre\VObject\Component::create('VCARD');
|
$dest = new \OCA\Contacts\VObject\VCard();
|
||||||
|
|
||||||
foreach ($element as $ldifProperty) {
|
foreach ($element as $ldifProperty) {
|
||||||
$importEntry = $this->getImportEntry($ldifProperty[0]);
|
$importEntry = $this->getImportEntry($ldifProperty[0]);
|
||||||
@ -135,7 +135,7 @@ class ImportLdifConnector extends ImportConnector{
|
|||||||
$this->convertElementToProperty($oneValue, $importEntry, $dest);
|
$this->convertElementToProperty($oneValue, $importEntry, $dest);
|
||||||
}
|
}
|
||||||
} else {
|
} 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]));
|
$property->parameters[] = new \Sabre\VObject\Parameter('TYPE', ''.StringUtil::convertToUTF8($ldifProperty[0]));
|
||||||
$dest->add($property);
|
$dest->add($property);
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ class ImportLdifConnector extends ImportConnector{
|
|||||||
if (isset($importEntry->vcard_favourites)) {
|
if (isset($importEntry->vcard_favourites)) {
|
||||||
foreach ($importEntry->vcard_favourites as $vcardFavourite) {
|
foreach ($importEntry->vcard_favourites as $vcardFavourite) {
|
||||||
if (strcasecmp((string)$vcardFavourite, trim($value)) == 0) {
|
if (strcasecmp((string)$vcardFavourite, trim($value)) == 0) {
|
||||||
$property = \Sabre\VObject\Property::create("X-FAVOURITES", 'yes');
|
$property = $dest->createProperty("X-FAVOURITES", 'yes');
|
||||||
$dest->add($property);
|
$dest->add($property);
|
||||||
} else {
|
} else {
|
||||||
$property = $this->getOrCreateVCardProperty($dest, $importEntry->vcard_entry);
|
$property = $this->getOrCreateVCardProperty($dest, $importEntry->vcard_entry);
|
||||||
|
@ -111,14 +111,14 @@ class ImportVCardConnector extends ImportConnector{
|
|||||||
} catch (VObject\ParseException $error) {
|
} catch (VObject\ParseException $error) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$dest = \Sabre\VObject\Component::create('VCARD');
|
$dest = new \OCA\Contacts\VObject\VCard();
|
||||||
|
|
||||||
foreach ($source->children() as $sourceProperty) {
|
foreach ($source->children() as $sourceProperty) {
|
||||||
$importEntry = $this->getImportEntry($sourceProperty, $source);
|
$importEntry = $this->getImportEntry($sourceProperty, $source);
|
||||||
if ($importEntry) {
|
if ($importEntry) {
|
||||||
$value = $sourceProperty->value;
|
$value = $sourceProperty->getValue();
|
||||||
if (isset($importEntry['remove'])) {
|
if (isset($importEntry['remove'])) {
|
||||||
$value = str_replace($importEntry['remove'], '', $sourceProperty->value);
|
$value = str_replace($importEntry['remove'], '', $sourceProperty->getValue());
|
||||||
}
|
}
|
||||||
$values = array($value);
|
$values = array($value);
|
||||||
if (isset($importEntry['separator'])) {
|
if (isset($importEntry['separator'])) {
|
||||||
@ -129,7 +129,7 @@ class ImportVCardConnector extends ImportConnector{
|
|||||||
if (isset($importEntry->vcard_favourites)) {
|
if (isset($importEntry->vcard_favourites)) {
|
||||||
foreach ($importEntry->vcard_favourites as $vcardFavourite) {
|
foreach ($importEntry->vcard_favourites as $vcardFavourite) {
|
||||||
if (strcasecmp((string)$vcardFavourite, trim($oneValue)) == 0) {
|
if (strcasecmp((string)$vcardFavourite, trim($oneValue)) == 0) {
|
||||||
$property = \Sabre\VObject\Property::create("X-FAVOURITES", 'yes');
|
$property = $dest->createProperty("X-FAVOURITES", 'yes');
|
||||||
$dest->add($property);
|
$dest->add($property);
|
||||||
} else {
|
} else {
|
||||||
$property = $this->getOrCreateVCardProperty($dest, $importEntry->vcard_entry);
|
$property = $this->getOrCreateVCardProperty($dest, $importEntry->vcard_entry);
|
||||||
@ -138,7 +138,7 @@ class ImportVCardConnector extends ImportConnector{
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$property = $this->getOrCreateVCardProperty($dest, $importEntry->vcard_entry);
|
$property = $this->getOrCreateVCardProperty($dest, $importEntry->vcard_entry);
|
||||||
$this->updateProperty($property, $importEntry, $sourceProperty->value);
|
$this->updateProperty($property, $importEntry, $sourceProperty->getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -166,7 +166,7 @@ class ImportVCardConnector extends ImportConnector{
|
|||||||
$sourceGroupList = $vcard->select($groupEntry['property']);
|
$sourceGroupList = $vcard->select($groupEntry['property']);
|
||||||
if (count($sourceGroupList>0)) {
|
if (count($sourceGroupList>0)) {
|
||||||
foreach ($sourceGroupList as $oneSourceGroup) {
|
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++;
|
$numElt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ class LdapConnector {
|
|||||||
* @return OC_VCard
|
* @return OC_VCard
|
||||||
*/
|
*/
|
||||||
public function ldapToVCard($ldapEntry) {
|
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);
|
$vcard->REV = $this->convertDate($ldapEntry['modifytimestamp'][0])->format(\DateTime::W3C);
|
||||||
//error_log("modifytimestamp: ".$vcard->REV);
|
//error_log("modifytimestamp: ".$vcard->REV);
|
||||||
$vcard->{'X-LDAP-DN'} = base64_encode($ldapEntry['dn']);
|
$vcard->{'X-LDAP-DN'} = base64_encode($ldapEntry['dn']);
|
||||||
@ -116,9 +116,9 @@ class LdapConnector {
|
|||||||
return $property;
|
return $property;
|
||||||
}
|
}
|
||||||
foreach ($property->parameters as $parameter) {
|
foreach ($property->parameters as $parameter) {
|
||||||
//OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.' parameter '.$parameter->value.' <> '.$v_param['type'], \OCP\Util::DEBUG);
|
//OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.' parameter '.$parameter->getValue().' <> '.$v_param['type'], \OCP\Util::DEBUG);
|
||||||
if (!strcmp($parameter->value, $v_param['type'])) {
|
if (!strcmp($parameter->getValue(), $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().' found', \OCP\Util::DEBUG);
|
||||||
if ($counter==$index) {
|
if ($counter==$index) {
|
||||||
return $property;
|
return $property;
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ class LdapConnector {
|
|||||||
// Property not found, creating one
|
// Property not found, creating one
|
||||||
//OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.', create one '.$v_param['property'].';TYPE='.$v_param['type'], \OCP\Util::DEBUG);
|
//OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.', create one '.$v_param['property'].';TYPE='.$v_param['type'], \OCP\Util::DEBUG);
|
||||||
$line = count($vcard->children) - 1;
|
$line = count($vcard->children) - 1;
|
||||||
$property = \Sabre\VObject\Property::create($v_param['property']);
|
$property = $vcard->createProperty($v_param['property']);
|
||||||
$vcard->add($property);
|
$vcard->add($property);
|
||||||
if ($v_param['type']!=null) {
|
if ($v_param['type']!=null) {
|
||||||
//OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.', creating one '.$v_param['property'].';TYPE='.$v_param['type'], \OCP\Util::DEBUG);
|
//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 {
|
} else {
|
||||||
// Last, if the ldif entry has a vcard_position set, take only the value in the position index
|
// 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'])) {
|
if (isset($ldifEntry['vcard_position'])) {
|
||||||
//\OC_Log::write('ldapconnector', __METHOD__." position set ".$ldifEntry['vcard_position'], \OC_Log::DEBUG);
|
//\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']];
|
$value = $tmpValues[$ldifEntry['vcard_position']];
|
||||||
}
|
}
|
||||||
//\OC_Log::write('ldapconnector', __METHOD__.__METHOD__." entry : ".$ldifEntry['name']." - value : $value", \OC_Log::DEBUG);
|
//\OC_Log::write('ldapconnector', __METHOD__.__METHOD__." entry : ".$ldifEntry['name']." - value : $value", \OC_Log::DEBUG);
|
||||||
|
@ -57,6 +57,8 @@ class Contact extends VObject\VCard implements IPIMObject {
|
|||||||
* @param mixed $data
|
* @param mixed $data
|
||||||
*/
|
*/
|
||||||
public function __construct($parent, $backend, $data = null) {
|
public function __construct($parent, $backend, $data = null) {
|
||||||
|
parent::__construct('VCARD');
|
||||||
|
|
||||||
self::$l10n = $parent::$l10n;
|
self::$l10n = $parent::$l10n;
|
||||||
//\OCP\Util::writeLog('contacts', __METHOD__ . ' , data: ' . print_r($data, true), \OCP\Util::DEBUG);
|
//\OCP\Util::writeLog('contacts', __METHOD__ . ' , data: ' . print_r($data, true), \OCP\Util::DEBUG);
|
||||||
$this->props['parent'] = $parent;
|
$this->props['parent'] = $parent;
|
||||||
@ -313,7 +315,7 @@ class Contact extends VObject\VCard implements IPIMObject {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function retrieve() {
|
public function retrieve() {
|
||||||
if ($this->isRetrieved() || count($this->children) > 1) {
|
if ($this->isRetrieved()) {
|
||||||
//\OCP\Util::writeLog('contacts', __METHOD__. ' children', \OCP\Util::DEBUG);
|
//\OCP\Util::writeLog('contacts', __METHOD__. ' children', \OCP\Util::DEBUG);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -324,7 +326,7 @@ class Contact extends VObject\VCard implements IPIMObject {
|
|||||||
$this->add($child);
|
$this->add($child);
|
||||||
if($child->name === 'FN') {
|
if($child->name === 'FN') {
|
||||||
$this->props['displayname']
|
$this->props['displayname']
|
||||||
= strtr($child->value, array('\,' => ',', '\;' => ';', '\\\\' => '\\'));
|
= strtr($child->getValue(), array('\,' => ',', '\;' => ';', '\\\\' => '\\'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->setRetrieved(true);
|
$this->setRetrieved(true);
|
||||||
@ -374,7 +376,11 @@ class Contact extends VObject\VCard implements IPIMObject {
|
|||||||
);
|
);
|
||||||
if ($obj) {
|
if ($obj) {
|
||||||
foreach ($obj->children as $child) {
|
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->setRetrieved(true);
|
||||||
$this->setSaved(true);
|
$this->setSaved(true);
|
||||||
@ -508,7 +514,7 @@ class Contact extends VObject\VCard implements IPIMObject {
|
|||||||
*/
|
*/
|
||||||
public function setPropertyByChecksum($checksum, $name, $value, $parameters=array()) {
|
public function setPropertyByChecksum($checksum, $name, $value, $parameters=array()) {
|
||||||
if ($checksum === 'new') {
|
if ($checksum === 'new') {
|
||||||
$property = Property::create($name);
|
$property = $this->createProperty($name);
|
||||||
$this->add($property);
|
$this->add($property);
|
||||||
} else {
|
} else {
|
||||||
$property = $this->getPropertyByChecksum($checksum);
|
$property = $this->getPropertyByChecksum($checksum);
|
||||||
@ -582,7 +588,7 @@ class Contact extends VObject\VCard implements IPIMObject {
|
|||||||
case 'ORG':
|
case 'ORG':
|
||||||
$property = $this->select($name);
|
$property = $this->select($name);
|
||||||
if (count($property) === 0) {
|
if (count($property) === 0) {
|
||||||
$property = \Sabre\VObject\Property::create($name);
|
$property = $this->createProperty($name);
|
||||||
$this->add($property);
|
$this->add($property);
|
||||||
} else {
|
} else {
|
||||||
// Actually no idea why this works
|
// Actually no idea why this works
|
||||||
@ -715,7 +721,7 @@ class Contact extends VObject\VCard implements IPIMObject {
|
|||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
foreach ($ownproperties as $ownproperty) {
|
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
|
// We already have this property, so skip both loops
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
@ -728,7 +734,7 @@ class Contact extends VObject\VCard implements IPIMObject {
|
|||||||
$this->add($property);
|
$this->add($property);
|
||||||
$updated = true;
|
$updated = true;
|
||||||
} else {
|
} 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) {
|
} catch(\Exception $e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$vevent = \Sabre\VObject\Component::create('VEVENT');
|
$vcal = new \Sabre\VObject\Component\VCalendar();
|
||||||
|
$vcal->VERSION = '2.0';
|
||||||
|
$vcal->createComponent('VEVENT');
|
||||||
$vevent->add('DTSTART');
|
$vevent->add('DTSTART');
|
||||||
$vevent->DTSTART->setDateTime(
|
$vevent->DTSTART->setDateTime(
|
||||||
$date,
|
$date
|
||||||
\Sabre\VObject\Property\DateTime::DATE
|
|
||||||
);
|
);
|
||||||
|
$event->DTSTART['VALUE'] = 'date';
|
||||||
$vevent->add('DURATION', 'P1D');
|
$vevent->add('DURATION', 'P1D');
|
||||||
$vevent->{'UID'} = $this->UID;
|
$vevent->{'UID'} = $this->UID;
|
||||||
$vevent->{'RRULE'} = 'FREQ=YEARLY';
|
$vevent->{'RRULE'} = 'FREQ=YEARLY';
|
||||||
$vevent->{'SUMMARY'} = $title . ' (' . $date->format('Y') . ')';
|
$vevent->{'SUMMARY'} = $title . ' (' . $date->format('Y') . ')';
|
||||||
$vcal = \Sabre\VObject\Component::create('VCALENDAR');
|
|
||||||
$vcal->VERSION = '2.0';
|
|
||||||
$appinfo = \OCP\App::getAppInfo('contacts');
|
$appinfo = \OCP\App::getAppInfo('contacts');
|
||||||
$appversion = \OCP\App::getAppVersion('contacts');
|
$appversion = \OCP\App::getAppVersion('contacts');
|
||||||
$vcal->PRODID = '-//ownCloud//NONSGML '.$appinfo['name'].' '.$appversion.'//EN';
|
$vcal->PRODID = '-//ownCloud//NONSGML '.$appinfo['name'].' '.$appversion.'//EN';
|
||||||
|
@ -53,12 +53,13 @@ class GroupController extends Controller {
|
|||||||
$shares[$key]['length'] = count($children);
|
$shares[$key]['length'] = count($children);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$currentUid = \OC::$server->getUserSession()->getUser()->getUId();
|
||||||
$groups = array(
|
$groups = array(
|
||||||
'categories' => $tags,
|
'categories' => $tags,
|
||||||
'favorites' => $favorites,
|
'favorites' => $favorites,
|
||||||
'shared' => $shares,
|
'shared' => $shares,
|
||||||
'lastgroup' => \OCP\Config::getUserValue(\OCP\User::getUser(), 'contacts', 'lastgroup', 'all'),
|
'lastgroup' => \OCP\Config::getUserValue($currentUid, 'contacts', 'lastgroup', 'all'),
|
||||||
'sortorder' => \OCP\Config::getUserValue(\OCP\User::getUser(), 'contacts', 'groupsort', ''),
|
'sortorder' => \OCP\Config::getUserValue($currentUid, 'contacts', 'groupsort', ''),
|
||||||
);
|
);
|
||||||
|
|
||||||
return new JSONResponse($groups);
|
return new JSONResponse($groups);
|
||||||
@ -348,7 +349,7 @@ class GroupController extends Controller {
|
|||||||
* in parentheses, like "Tag (owner)".
|
* in parentheses, like "Tag (owner)".
|
||||||
*/
|
*/
|
||||||
private function displayName($tag) {
|
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'] . ' ('. $tag['owner'] . ')';
|
||||||
}
|
}
|
||||||
return $tag['name'];
|
return $tag['name'];
|
||||||
|
@ -159,7 +159,7 @@ class ImportController extends Controller {
|
|||||||
$request = $this->request;
|
$request = $this->request;
|
||||||
$response = new JSONResponse();
|
$response = new JSONResponse();
|
||||||
$params = $this->request->urlParams;
|
$params = $this->request->urlParams;
|
||||||
$app = new App(\OCP\User::getUser());
|
$app = new App(\OC::$server->getUserSession()->getUser()->getUId());
|
||||||
$addressBookId = $params['addressBookId'];
|
$addressBookId = $params['addressBookId'];
|
||||||
$format = $params['importType'];
|
$format = $params['importType'];
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class SettingsController extends Controller {
|
|||||||
$response->bailOut(App::$l10n->t('No value is given.'));
|
$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(
|
$response->setParams(array(
|
||||||
'key' => $key,
|
'key' => $key,
|
||||||
'value' => $value)
|
'value' => $value)
|
||||||
@ -52,4 +52,4 @@ class SettingsController extends Controller {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ class Addressbook implements \OCP\Share_Backend_Collection {
|
|||||||
public $app;
|
public $app;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->app = new App(\OCP\User::getUser());
|
$this->app = new App(\OC::$server->getUserSession()->getUser()->getUId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,7 +37,7 @@ class Contact implements \OCP\Share_Backend {
|
|||||||
public $backend;
|
public $backend;
|
||||||
|
|
||||||
public function __construct() {
|
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');
|
$this->backend = $this->app->getBackend('local');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ class JSONSerializer {
|
|||||||
if(!is_null($temp)) {
|
if(!is_null($temp)) {
|
||||||
// Get Apple X-ABLabels
|
// Get Apple X-ABLabels
|
||||||
if(isset($contact->{$property->group . '.X-ABLABEL'})) {
|
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'] == '_$!<Other>!$_') {
|
if($temp['label'] == '_$!<Other>!$_') {
|
||||||
$temp['label'] = Properties::$l10n->t('Other');
|
$temp['label'] = Properties::$l10n->t('Other');
|
||||||
}
|
}
|
||||||
@ -142,7 +142,7 @@ class JSONSerializer {
|
|||||||
if(!in_array($property->name, Properties::$indexProperties)) {
|
if(!in_array($property->name, Properties::$indexProperties)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$value = $property->value;
|
$value = $property->getValue();
|
||||||
if($property->name == 'ADR' || $property->name == 'N' || $property->name == 'ORG' || $property->name == 'CATEGORIES') {
|
if($property->name == 'ADR' || $property->name == 'N' || $property->name == 'ORG' || $property->name == 'CATEGORIES') {
|
||||||
$value = $property->getParts();
|
$value = $property->getParts();
|
||||||
$value = array_map('trim', $value);
|
$value = array_map('trim', $value);
|
||||||
@ -195,15 +195,15 @@ class JSONSerializer {
|
|||||||
// Faulty entries by kaddressbook
|
// Faulty entries by kaddressbook
|
||||||
// Actually TYPE=PREF is correct according to RFC 2426
|
// Actually TYPE=PREF is correct according to RFC 2426
|
||||||
// but this way is more handy in the UI. Tanghus.
|
// 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->name = 'PREF';
|
||||||
$parameter->value = '1';
|
$parameter->setValue('1');
|
||||||
}
|
}
|
||||||
// NOTE: Apparently \Sabre\VObject\Reader can't always deal with value list parameters
|
// NOTE: Apparently \Sabre\VObject\Reader can't always deal with value list parameters
|
||||||
// like TYPE=HOME,CELL,VOICE. Tanghus.
|
// like TYPE=HOME,CELL,VOICE. Tanghus.
|
||||||
// TODO: Check if parameter is has commas and split + merge if so.
|
// TODO: Check if parameter is has commas and split + merge if so.
|
||||||
if ($parameter->name == 'TYPE') {
|
if ($parameter->name == 'TYPE') {
|
||||||
$pvalue = $parameter->value;
|
$pvalue = $parameter->getValue();
|
||||||
if(is_string($pvalue) && strpos($pvalue, ',') !== false) {
|
if(is_string($pvalue) && strpos($pvalue, ',') !== false) {
|
||||||
$pvalue = array_map('trim', explode(',', $pvalue));
|
$pvalue = array_map('trim', explode(',', $pvalue));
|
||||||
}
|
}
|
||||||
@ -216,7 +216,7 @@ class JSONSerializer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$temp['parameters'][$parameter->name] = \OCP\Util::sanitizeHTML($parameter->value);
|
$temp['parameters'][$parameter->name] = \OCP\Util::sanitizeHTML($parameter->getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $temp;
|
return $temp;
|
||||||
|
@ -260,7 +260,7 @@ Class Properties {
|
|||||||
}
|
}
|
||||||
$preferred = 0;
|
$preferred = 0;
|
||||||
foreach($property->parameters as $parameter) {
|
foreach($property->parameters as $parameter) {
|
||||||
if($parameter->name == 'TYPE' && strtoupper($parameter->value) == 'PREF') {
|
if($parameter->name == 'TYPE' && strtoupper($parameter->getValue()) == 'PREF') {
|
||||||
$preferred = 1;
|
$preferred = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -268,10 +268,10 @@ Class Properties {
|
|||||||
try {
|
try {
|
||||||
$result = self::$updateindexstmt->execute(
|
$result = self::$updateindexstmt->execute(
|
||||||
array(
|
array(
|
||||||
\OCP\User::getUser(),
|
\OC::$server->getUserSession()->getUser()->getUId(),
|
||||||
$contactid,
|
$contactid,
|
||||||
$property->name,
|
$property->name,
|
||||||
substr($property->value, 0, 254),
|
substr($property->getValue(), 0, 254),
|
||||||
$preferred,
|
$preferred,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -29,7 +29,7 @@ use OC\VObject\CompoundProperty;
|
|||||||
*
|
*
|
||||||
* NOTE: Group names are case-insensitive.
|
* NOTE: Group names are case-insensitive.
|
||||||
*/
|
*/
|
||||||
class GroupProperty extends CompoundProperty {
|
class GroupProperty extends \Sabre\VObject\Property\Text {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a group.
|
* Add a group.
|
||||||
@ -117,4 +117,4 @@ class GroupProperty extends CompoundProperty {
|
|||||||
}
|
}
|
||||||
return array_search(strtolower($needle), array_map('strtolower', $haystack));
|
return array_search(strtolower($needle), array_map('strtolower', $haystack));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,82 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* ownCloud - VObject String Property
|
|
||||||
*
|
|
||||||
* This class adds escaping/unescaping of simple string properties.
|
|
||||||
*
|
|
||||||
* @author Thomas Tanghus
|
|
||||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 3 of the License, or any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* 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/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -121,22 +121,22 @@ class VCard extends VObject\Component\VCard {
|
|||||||
foreach($property->parameters as $key=>&$parameter) {
|
foreach($property->parameters as $key=>&$parameter) {
|
||||||
// Check for values without names which Sabre interprets
|
// Check for values without names which Sabre interprets
|
||||||
// as names without values.
|
// as names without values.
|
||||||
if(trim($parameter->value) === '') {
|
if(trim($parameter->getValue()) === '') {
|
||||||
$parameter->value = $parameter->name;
|
$parameter->setValue($parameter->name);
|
||||||
$parameter->name = $this->paramName($parameter->name);
|
$parameter->name = $this->paramName($parameter->name);
|
||||||
}
|
}
|
||||||
// Check out for encoded string and decode them :-[
|
// Check out for encoded string and decode them :-[
|
||||||
if(strtoupper($parameter->name) == 'ENCODING') {
|
if(strtoupper($parameter->name) == 'ENCODING') {
|
||||||
if(strtoupper($parameter->value) == 'QUOTED-PRINTABLE') {
|
if(strtoupper($parameter->getValue()) == 'QUOTED-PRINTABLE') {
|
||||||
$property->value = str_replace(
|
$property->setValue(str_replace(
|
||||||
"\r\n", "\n",
|
"\r\n", "\n",
|
||||||
VObject\StringUtil::convertToUTF8(
|
VObject\StringUtil::convertToUTF8(
|
||||||
quoted_printable_decode($property->value)
|
quoted_printable_decode($property->getValue())
|
||||||
)
|
)
|
||||||
);
|
));
|
||||||
unset($property->parameters[$key]);
|
unset($property->parameters[$key]);
|
||||||
} elseif(strtoupper($parameter->value) == 'BASE64') {
|
} elseif(strtoupper($parameter->getValue()) == 'BASE64') {
|
||||||
$parameter->value = 'b';
|
$parameter->setValue('b');
|
||||||
}
|
}
|
||||||
} elseif(strtoupper($parameter->name) == 'CHARSET') {
|
} elseif(strtoupper($parameter->name) == 'CHARSET') {
|
||||||
unset($property->parameters[$key]);
|
unset($property->parameters[$key]);
|
||||||
@ -154,12 +154,12 @@ class VCard extends VObject\Component\VCard {
|
|||||||
// Work around issue in older VObject sersions
|
// Work around issue in older VObject sersions
|
||||||
// https://github.com/fruux/sabre-vobject/issues/24
|
// https://github.com/fruux/sabre-vobject/issues/24
|
||||||
foreach($property->parameters as $key=>$parameter) {
|
foreach($property->parameters as $key=>$parameter) {
|
||||||
if(strpos($parameter->value, ',') === false) {
|
if(strpos($parameter->getValue(), ',') === false) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$values = explode(',', $parameter->value);
|
$values = explode(',', $parameter->getValue());
|
||||||
$values = array_map('trim', $values);
|
$values = array_map('trim', $values);
|
||||||
$parameter->value = array_shift($values);
|
$parameter->setValue(array_shift($values));
|
||||||
foreach($values as $value) {
|
foreach($values as $value) {
|
||||||
$property->add($parameter->name, $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...
|
if(count($slice) < 2) { // If not enought, add one more...
|
||||||
$slice[] = "";
|
$slice[] = "";
|
||||||
}
|
}
|
||||||
$this->N = implode(';', $slice).';;;';
|
$this->N = $slice;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$tmpl = new OCP\Template( 'contacts', 'settings');
|
$tmpl = new OCP\Template( 'contacts', 'settings');
|
||||||
$tmpl->assign('addressbooks', OCA\Contacts\Addressbook::all(OCP\USER::getUser()));
|
$tmpl->assign('addressbooks', OCA\Contacts\Addressbook::all(\OC::$server->getUserSession()->getUser()->getUId()));
|
||||||
|
|
||||||
$tmpl->printPage();
|
$tmpl->printPage();
|
||||||
|
@ -449,7 +449,7 @@ vendor_style('contacts', array(
|
|||||||
</li>
|
</li>
|
||||||
</div>
|
</div>
|
||||||
<div class="adr" type="text/template">
|
<div class="adr" type="text/template">
|
||||||
<li data-element="adr" data-checksum="{checksum}" data-lang="<?php p(OCP\Config::getUserValue(OCP\USER::getUser(), 'core', 'lang', 'en')); ?>" class="propertycontainer">
|
<li data-element="adr" data-checksum="{checksum}" data-lang="<?php p(OCP\Config::getUserValue(\OC::$server->getUserSession()->getUser()->getUId(), 'core', 'lang', 'en')); ?>" class="propertycontainer">
|
||||||
<span class="parameters">
|
<span class="parameters">
|
||||||
<input type="checkbox" id="adr_pref_{idx}" class="parameter tooltipped downwards" data-parameter="TYPE" name="parameters[TYPE][]" value="PREF" title="<?php p($l->t('Preferred')); ?>" />
|
<input type="checkbox" id="adr_pref_{idx}" class="parameter tooltipped downwards" data-parameter="TYPE" name="parameters[TYPE][]" value="PREF" title="<?php p($l->t('Preferred')); ?>" />
|
||||||
<select class="type parameter" data-parameter="TYPE" name="parameters[TYPE][]">
|
<select class="type parameter" data-parameter="TYPE" name="parameters[TYPE][]">
|
||||||
@ -491,7 +491,7 @@ vendor_style('contacts', array(
|
|||||||
</li>
|
</li>
|
||||||
</div>
|
</div>
|
||||||
<!--
|
<!--
|
||||||
<li data-element="adr" data-checksum="{checksum}" data-lang="<?php p(OCP\Config::getUserValue(OCP\USER::getUser(), 'core', 'lang', 'en')); ?>" class="propertycontainer">
|
<li data-element="adr" data-checksum="{checksum}" data-lang="<?php p(OCP\Config::getUserValue(\OC::$server->getUserSession()->getUser()->getUId(), 'core', 'lang', 'en')); ?>" class="propertycontainer">
|
||||||
<span class="parameters">
|
<span class="parameters">
|
||||||
<input type="checkbox" id="adr_pref_{idx}" class="parameter tooltipped downwards" data-parameter="TYPE" name="parameters[TYPE][]" value="PREF" title="<?php p($l->t('Preferred')); ?>" />
|
<input type="checkbox" id="adr_pref_{idx}" class="parameter tooltipped downwards" data-parameter="TYPE" name="parameters[TYPE][]" value="PREF" title="<?php p($l->t('Preferred')); ?>" />
|
||||||
<select class="type parameter" data-parameter="TYPE" name="parameters[TYPE][]">
|
<select class="type parameter" data-parameter="TYPE" name="parameters[TYPE][]">
|
||||||
|
@ -12,6 +12,8 @@ if(!class_exists('PHPUnit_Framework_TestCase')) {
|
|||||||
require_once('PHPUnit/Autoload.php');
|
require_once('PHPUnit/Autoload.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
include_once('lib/testcase.php');
|
||||||
|
|
||||||
//OC_App::enable('contacts');
|
//OC_App::enable('contacts');
|
||||||
|
|
||||||
OC_Hook::clear();
|
OC_Hook::clear();
|
||||||
|
@ -12,7 +12,7 @@ use Sabre\VObject\Reader;
|
|||||||
|
|
||||||
require_once __DIR__ . '/backend/mock.php';
|
require_once __DIR__ . '/backend/mock.php';
|
||||||
|
|
||||||
class AddressBookTest extends \PHPUnit_Framework_TestCase {
|
class AddressBookTest extends TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
@ -28,8 +28,7 @@ class AddressBookTest extends \PHPUnit_Framework_TestCase {
|
|||||||
protected $backend;
|
protected $backend;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
\Sabre\VObject\Component::$classMap['VCARD'] = '\OCA\Contacts\VObject\VCard';
|
|
||||||
|
|
||||||
$this->backend = new Backend\Mock('foobar');
|
$this->backend = new Backend\Mock('foobar');
|
||||||
$this->abinfo = $this->backend->getAddressBook('foo');
|
$this->abinfo = $this->backend->getAddressBook('foo');
|
||||||
@ -40,6 +39,8 @@ class AddressBookTest extends \PHPUnit_Framework_TestCase {
|
|||||||
public function tearDown() {
|
public function tearDown() {
|
||||||
unset($this->backend);
|
unset($this->backend);
|
||||||
unset($this->ab);
|
unset($this->ab);
|
||||||
|
|
||||||
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetDisplayName() {
|
public function testGetDisplayName() {
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
namespace OCA\Contacts;
|
namespace OCA\Contacts;
|
||||||
|
|
||||||
|
|
||||||
class AddressBookProviderTest extends \PHPUnit_Framework_TestCase {
|
class AddressBookProviderTest extends TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
@ -35,17 +35,15 @@ class AddressBookProviderTest extends \PHPUnit_Framework_TestCase {
|
|||||||
private $contactIds = array();
|
private $contactIds = array();
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
\Sabre\VObject\Component::$classMap['VCARD'] = '\OCA\Contacts\VObject\VCard';
|
$this->backend = new Backend\Database($this->testUser);
|
||||||
|
|
||||||
$user = uniqid('user_');
|
|
||||||
$this->backend = new Backend\Database($user);
|
|
||||||
$this->abinfo = array('displayname' => uniqid('display_'));
|
$this->abinfo = array('displayname' => uniqid('display_'));
|
||||||
$this->ab = new AddressBook($this->backend, $this->abinfo);
|
$this->ab = new AddressBook($this->backend, $this->abinfo);
|
||||||
|
|
||||||
$this->provider = new AddressbookProvider($this->ab);
|
$this->provider = new AddressbookProvider($this->ab);
|
||||||
|
|
||||||
$card = \Sabre\VObject\Component::create('VCARD');
|
$card = new \OCA\Contacts\VObject\VCard();
|
||||||
$uid = substr(md5(rand().time()), 0, 10);
|
$uid = substr(md5(rand().time()), 0, 10);
|
||||||
$card->add('UID', $uid);
|
$card->add('UID', $uid);
|
||||||
$card->add('FN', 'Max Mustermann');
|
$card->add('FN', 'Max Mustermann');
|
||||||
@ -54,21 +52,21 @@ class AddressBookProviderTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$this->contactIds[] = $id;
|
$this->contactIds[] = $id;
|
||||||
|
|
||||||
// Add extra contact
|
// Add extra contact
|
||||||
$card = \Sabre\VObject\Component::create('VCARD');
|
$card = new \OCA\Contacts\VObject\VCard();
|
||||||
$uid = substr(md5(rand().time()), 0, 10);
|
$uid = substr(md5(rand().time()), 0, 10);
|
||||||
$card->add('UID', $uid);
|
$card->add('UID', $uid);
|
||||||
$card->add('FN', 'Jan Janssens');
|
$card->add('FN', 'Jan Janssens');
|
||||||
$id = $this->ab->addChild($card);
|
$id = $this->ab->addChild($card);
|
||||||
Utils\Properties::updateIndex($id, $card);
|
Utils\Properties::updateIndex($id, $card);
|
||||||
$this->ab->deleteChild($id);
|
$this->ab->deleteChild($id);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown() {
|
public function tearDown() {
|
||||||
unset($this->backend);
|
unset($this->backend);
|
||||||
unset($this->ab);
|
unset($this->ab);
|
||||||
Utils\Properties::purgeIndexes($this->contactIds);
|
Utils\Properties::purgeIndexes($this->contactIds);
|
||||||
|
|
||||||
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSearch() {
|
public function testSearch() {
|
||||||
|
@ -12,7 +12,7 @@ use Sabre\VObject\Reader;
|
|||||||
|
|
||||||
require_once __DIR__ .'/mock.php';
|
require_once __DIR__ .'/mock.php';
|
||||||
|
|
||||||
class BackendTest extends \PHPUnit_Framework_TestCase {
|
class BackendTest extends \OCA\Contacts\TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
|
@ -17,7 +17,7 @@ class Mock extends AbstractBackend {
|
|||||||
|
|
||||||
function __construct($userid = null, $addressBooks = null, $contacts = null) {
|
function __construct($userid = null, $addressBooks = null, $contacts = null) {
|
||||||
|
|
||||||
$this->userid = $userid ? $userid : \OCP\User::getUser();
|
$this->userid = $userid ? $userid : \OC::$server->getUserSession()->getUser()->getUId();
|
||||||
$this->addressBooks = $addressBooks;
|
$this->addressBooks = $addressBooks;
|
||||||
$this->contacts = $contacts;
|
$this->contacts = $contacts;
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ use OCA\Contacts\Utils\JSONSerializer;
|
|||||||
|
|
||||||
require_once __DIR__ . '/backend/mock.php';
|
require_once __DIR__ . '/backend/mock.php';
|
||||||
|
|
||||||
class ContactTest extends \PHPUnit_Framework_TestCase {
|
class ContactTest extends TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
@ -33,7 +33,7 @@ class ContactTest extends \PHPUnit_Framework_TestCase {
|
|||||||
protected $backend;
|
protected $backend;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
$this->backend = new Backend\Mock('foobar');
|
$this->backend = new Backend\Mock('foobar');
|
||||||
$this->abinfo = $this->backend->getAddressBook('foo');
|
$this->abinfo = $this->backend->getAddressBook('foo');
|
||||||
$this->ab = new AddressBook($this->backend, $this->abinfo);
|
$this->ab = new AddressBook($this->backend, $this->abinfo);
|
||||||
@ -44,6 +44,7 @@ class ContactTest extends \PHPUnit_Framework_TestCase {
|
|||||||
unset($this->backend);
|
unset($this->backend);
|
||||||
unset($this->ab);
|
unset($this->ab);
|
||||||
unset($this->contact);
|
unset($this->contact);
|
||||||
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetDisplayName() {
|
public function testGetDisplayName() {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* See the COPYING-README file.
|
* See the COPYING-README file.
|
||||||
*/
|
*/
|
||||||
OC_App::loadApp('contacts');
|
OC_App::loadApp('contacts');
|
||||||
class Test_Contacts_Backend_Datebase extends PHPUnit_Framework_TestCase {
|
class Test_Contacts_Backend_Datebase extends \OCA\Contacts\TestCase {
|
||||||
protected static $schema_file = 'static://test_db_scheme';
|
protected static $schema_file = 'static://test_db_scheme';
|
||||||
protected static $test_prefix;
|
protected static $test_prefix;
|
||||||
protected static $backend;
|
protected static $backend;
|
||||||
|
46
tests/lib/testcase.php
Normal file
46
tests/lib/testcase.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later.
|
||||||
|
* See the COPYING-README file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\Contacts;
|
||||||
|
|
||||||
|
class TestCase extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $testUser;
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
$this->testUser = uniqid('user_');
|
||||||
|
|
||||||
|
// needed because some parts of code call "getRequest()" and "getSession()"
|
||||||
|
$session = $this->getMock('\OC\Session\Memory', array(), array(''));
|
||||||
|
$session->expects($this->any())
|
||||||
|
->method('get')
|
||||||
|
->with('user_id')
|
||||||
|
->will($this->returnValue($this->testUser));
|
||||||
|
$userObject = $this->getMock('\OCP\IUser');
|
||||||
|
$userObject->expects($this->any())
|
||||||
|
->method('getUId')
|
||||||
|
->will($this->returnValue($this->testUser));
|
||||||
|
|
||||||
|
$userSession = $this->getMockBuilder('\OC\User\Session')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$userSession->expects($this->any())
|
||||||
|
->method('getUser')
|
||||||
|
->will($this->returnValue($userObject));
|
||||||
|
$userSession->expects($this->any())
|
||||||
|
->method('getSession')
|
||||||
|
->will($this->returnValue($session));
|
||||||
|
\OC::$server->registerService('UserSession', function (\OCP\IServerContainer $c) use ($userSession){
|
||||||
|
return $userSession;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -6,12 +6,10 @@
|
|||||||
* See the COPYING-README file.
|
* See the COPYING-README file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Test_VObjects extends PHPUnit_Framework_TestCase {
|
class Test_VObjects extends \OCA\Contacts\TestCase {
|
||||||
|
|
||||||
public static function setUpBeforeClass() {
|
public static function setUpBeforeClass() {
|
||||||
\Sabre\VObject\Component::$classMap['VCARD'] = '\OCA\Contacts\VObject\VCard';
|
\Sabre\VObject\Component\VCard::$propertyMap['CATEGORIES'] = 'OCA\Contacts\VObject\GroupProperty';
|
||||||
\Sabre\VObject\Property::$classMap['CATEGORIES'] = 'OCA\Contacts\VObject\GroupProperty';
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCrappyVCard() {
|
public function testCrappyVCard() {
|
||||||
@ -47,11 +45,13 @@ class Test_VObjects extends PHPUnit_Framework_TestCase {
|
|||||||
'Friends, Family',
|
'Friends, Family',
|
||||||
);
|
);
|
||||||
|
|
||||||
$property = \Sabre\VObject\Property::create('CATEGORIES');
|
$vcard = new \OCA\Contacts\VObject\VCard();
|
||||||
|
|
||||||
|
$property = $vcard->createProperty('CATEGORIES');
|
||||||
$property->setParts($arr);
|
$property->setParts($arr);
|
||||||
|
|
||||||
// Test parsing and serializing
|
// Test parsing and serializing
|
||||||
$this->assertEquals('Home,work,Friends\, Family', $property->value);
|
$this->assertEquals('Home,work,Friends\, Family', $property->getValue());
|
||||||
$this->assertEquals('CATEGORIES:Home,work,Friends\, Family' . "\r\n", $property->serialize());
|
$this->assertEquals('CATEGORIES:Home,work,Friends\, Family' . "\r\n", $property->serialize());
|
||||||
$this->assertEquals(3, count($property->getParts()));
|
$this->assertEquals(3, count($property->getParts()));
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ class Test_VObjects extends PHPUnit_Framework_TestCase {
|
|||||||
$property->addGroup('Coworkers');
|
$property->addGroup('Coworkers');
|
||||||
$this->assertTrue($property->hasGroup('coworkers'));
|
$this->assertTrue($property->hasGroup('coworkers'));
|
||||||
$this->assertEquals(4, count($property->getParts()));
|
$this->assertEquals(4, count($property->getParts()));
|
||||||
$this->assertEquals('Home,work,Friends\, Family,Coworkers', $property->value);
|
$this->assertEquals('Home,work,Friends\, Family,Coworkers', $property->getValue());
|
||||||
|
|
||||||
// Test remove
|
// Test remove
|
||||||
$this->assertTrue($property->hasGroup('Friends, fAmIlY'));
|
$this->assertTrue($property->hasGroup('Friends, fAmIlY'));
|
||||||
@ -74,4 +74,4 @@ class Test_VObjects extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('Work', $parts[1]);
|
$this->assertEquals('Work', $parts[1]);
|
||||||
//$this->assertEquals(true, false);
|
//$this->assertEquals(true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
$CONFIG = array (
|
$CONFIG = array (
|
||||||
'loglevel' => '0',
|
'loglevel' => '1',
|
||||||
'appstoreenabled' => false,
|
'appstoreenabled' => false,
|
||||||
'apps_paths' =>
|
'apps_paths' =>
|
||||||
array (
|
array (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user