mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-08 00:47:04 +03:00
CardDAV second look :)
This commit is contained in:
parent
7648000521
commit
a46d6832d9
20 changed files with 852 additions and 468 deletions
|
|
@ -1,31 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop\SabreDAV;
|
||||
|
||||
class AuthBasic extends \Sabre\DAV\Auth\Backend\AbstractBasic
|
||||
{
|
||||
/**
|
||||
* @var \RainLoop\Providers\PersonalAddressBook
|
||||
*/
|
||||
private $oPersonalAddressBook;
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Providers\PersonalAddressBook $oPersonalAddressBook
|
||||
*/
|
||||
public function __construct($oPersonalAddressBook)
|
||||
{
|
||||
$this->oPersonalAddressBook = $oPersonalAddressBook;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sUserName
|
||||
* @param string $sPassword
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function validateUserPass($sUserName, $sPassword)
|
||||
{
|
||||
$this->currentUser = $sUserName;
|
||||
return true; // TODO
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace RainLoop\SabreDAV;
|
||||
|
||||
class AuthBasic extends \Sabre\DAV\Auth\Backend\AbstractBasic
|
||||
{
|
||||
/**
|
||||
* @var \RainLoop\Providers\PersonalAddressBook
|
||||
*/
|
||||
private $oPersonalAddressBook;
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Providers\PersonalAddressBook $oPersonalAddressBook
|
||||
*/
|
||||
public function __construct($oPersonalAddressBook)
|
||||
{
|
||||
$this->oPersonalAddressBook = $oPersonalAddressBook;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sUserName
|
||||
* @param string $sPassword
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function validateUserPass($sUserName, $sPassword)
|
||||
{
|
||||
return $sPassword === $this->oPersonalAddressBook->GetUserHashByEmail($sUserName, true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop\SabreDAV;
|
||||
|
||||
class AuthBasic extends \Sabre\DAV\Auth\Backend\AbstractDigest
|
||||
{
|
||||
/**
|
||||
* @var \RainLoop\Providers\PersonalAddressBook
|
||||
*/
|
||||
private $oPersonalAddressBook;
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Providers\PersonalAddressBook $oPersonalAddressBook
|
||||
*/
|
||||
public function __construct($oPersonalAddressBook)
|
||||
{
|
||||
$this->oPersonalAddressBook = $oPersonalAddressBook;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getDigestHash($sRealm, $sUserName)
|
||||
{
|
||||
$this->currentUser = $sUserName;
|
||||
return true; // TODO
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace RainLoop\SabreDAV;
|
||||
|
||||
class AuthDigest extends \Sabre\DAV\Auth\Backend\AbstractDigest
|
||||
{
|
||||
/**
|
||||
* @var \RainLoop\Providers\PersonalAddressBook
|
||||
*/
|
||||
private $oPersonalAddressBook;
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Providers\PersonalAddressBook $oPersonalAddressBook
|
||||
*/
|
||||
public function __construct($oPersonalAddressBook)
|
||||
{
|
||||
$this->oPersonalAddressBook = $oPersonalAddressBook;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sRealm
|
||||
* @param string $sUserName
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDigestHash($sRealm, $sUserName)
|
||||
{
|
||||
$sHash = $this->oPersonalAddressBook->GetUserHashByEmail($sUserName, true);
|
||||
if (!empty($sHash))
|
||||
{
|
||||
$this->currentUser = $sUserName;
|
||||
return \md5($sUserName.':'.$sRealm.':'.$sHash);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,278 +1,333 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop\SabreDAV;
|
||||
|
||||
class CardDAV implements \Sabre\CardDAV\Backend\BackendInterface {
|
||||
|
||||
/**
|
||||
* @var \RainLoop\Providers\PersonalAddressBook
|
||||
*/
|
||||
private $oPersonalAddressBook;
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Providers\PersonalAddressBook $oPersonalAddressBook
|
||||
*/
|
||||
public function __construct($oPersonalAddressBook)
|
||||
{
|
||||
$this->oPersonalAddressBook = $oPersonalAddressBook;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sPrincipalUri
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getEmailFromPrincipalUri($sPrincipalUri)
|
||||
{
|
||||
$sEmail = '';
|
||||
$aMatch = array();
|
||||
if (\preg_match('/\/?principals\/([^@\/]+@[^@\/]+)/i', $sPrincipalUri, $aMatch) && !empty($aMatch[1]))
|
||||
{
|
||||
$sEmail = \trim($aMatch[1]);
|
||||
}
|
||||
|
||||
return $sEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sPrincipalUri
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getCalendarID($sPrincipalUri)
|
||||
{
|
||||
$mUserId = (string) $this->oPersonalAddressBook->GetUserUidByEmail(
|
||||
$this->getEmailFromPrincipalUri($sPrincipalUri));
|
||||
|
||||
return !empty($mUserId) ? $mUserId : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of addressbooks for a specific user.
|
||||
*
|
||||
* @param string $sPrincipalUri
|
||||
* @return array
|
||||
*/
|
||||
public function getAddressBooksForUser($sPrincipalUri)
|
||||
{
|
||||
$mAddressBookID = $this->getCalendarID($sPrincipalUri);
|
||||
|
||||
$aAddressBooks = array();
|
||||
if (!empty($mAddressBookID))
|
||||
{
|
||||
$aAddressBooks[] = array(
|
||||
'id' => $mAddressBookID,
|
||||
'uri' => 'default',
|
||||
'principaluri' => $sPrincipalUri,
|
||||
'{DAV:}displayname' => 'Personal Address Book',
|
||||
'{'.\Sabre\CardDAV\Plugin::NS_CARDDAV.'}addressbook-description' => 'Personal Address Book',
|
||||
'{http://calendarserver.org/ns/}getctag' => 1,
|
||||
'{'.\Sabre\CardDAV\Plugin::NS_CARDDAV.'}supported-address-data' => new \Sabre\CardDAV\Property\SupportedAddressData()
|
||||
);
|
||||
}
|
||||
|
||||
return $aAddressBooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an addressbook's properties
|
||||
*
|
||||
* See Sabre\DAV\IProperties for a description of the mutations array, as
|
||||
* well as the return value.
|
||||
*
|
||||
* @param mixed $mAddressBookId
|
||||
* @param array $aMutations
|
||||
* @see Sabre\DAV\IProperties::updateProperties
|
||||
* @return bool|array
|
||||
*/
|
||||
public function updateAddressBook($mAddressBookId, array $aMutations)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new address book
|
||||
*
|
||||
* @param string $sPrincipalUri
|
||||
* @param string $sUrl Just the 'basename' of the url.
|
||||
* @param array $aProperties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function createAddressBook($sPrincipalUri, $sUrl, array $aProperties)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an entire addressbook and all its contents
|
||||
*
|
||||
* @param mixed $mAddressBookId
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAddressBook($mAddressBookId)
|
||||
{
|
||||
}
|
||||
|
||||
private function simpleGetCards($mAddressBookId, $sCardUri = '')
|
||||
{
|
||||
$aResult = array();
|
||||
if (!empty($mAddressBookId))
|
||||
{
|
||||
$aList = $this->oPersonalAddressBook->GetContacts($mAddressBookId, 0, 20);
|
||||
foreach ($aList as /* @var $oItem \RainLoop\Providers\PersonalAddressBook\Classes\Contact */ $oItem)
|
||||
{
|
||||
$oVCard = $oItem->ToVCardObject();
|
||||
if ('' === $sCardUri || $sCardUri === $oVCard->UID)
|
||||
{
|
||||
$aResult[] = array(
|
||||
'id' => $oItem->IdContact,
|
||||
'uri' => $oVCard->UID,
|
||||
'lastmodified' => $oItem->Changed,
|
||||
'carddata' => $oVCard->serialize()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all cards for a specific addressbook id.
|
||||
*
|
||||
* This method should return the following properties for each card:
|
||||
* * carddata - raw vcard data
|
||||
* * uri - Some unique url
|
||||
* * lastmodified - A unix timestamp
|
||||
*
|
||||
* It's recommended to also return the following properties:
|
||||
* * etag - A unique etag. This must change every time the card changes.
|
||||
* * size - The size of the card in bytes.
|
||||
*
|
||||
* If these last two properties are provided, less time will be spent
|
||||
* calculating them. If they are specified, you can also ommit carddata.
|
||||
* This may speed up certain requests, especially with large cards.
|
||||
*
|
||||
* @param mixed $mAddressbookId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCards($mAddressBookId)
|
||||
{
|
||||
return $this->simpleGetCards($mAddressBookId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a specfic card.
|
||||
*
|
||||
* The same set of properties must be returned as with getCards. The only
|
||||
* exception is that 'carddata' is absolutely required.
|
||||
*
|
||||
* @param mixed $mAddressBookId
|
||||
* @param string $sCardUri
|
||||
* @return array
|
||||
*/
|
||||
public function getCard($mAddressBookId, $sCardUri)
|
||||
{
|
||||
$aList = $this->simpleGetCards($mAddressBookId, $sCardUri);
|
||||
return 0 < count($aList) && isset($aList) ? $aList[0] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new card.
|
||||
*
|
||||
* The addressbook id will be passed as the first argument. This is the
|
||||
* same id as it is returned from the getAddressbooksForUser method.
|
||||
*
|
||||
* The cardUri is a base uri, and doesn't include the full path. The
|
||||
* cardData argument is the vcard body, and is passed as a string.
|
||||
*
|
||||
* It is possible to return an ETag from this method. This ETag is for the
|
||||
* newly created resource, and must be enclosed with double quotes (that
|
||||
* is, the string itself must contain the double quotes).
|
||||
*
|
||||
* You should only return the ETag if you store the carddata as-is. If a
|
||||
* subsequent GET request on the same card does not have the same body,
|
||||
* byte-by-byte and you did return an ETag here, clients tend to get
|
||||
* confused.
|
||||
*
|
||||
* If you don't return an ETag, you can just return null.
|
||||
*
|
||||
* @param mixed $mAddressBookId
|
||||
* @param string $sCardUri
|
||||
* @param string $sCardData
|
||||
* @return string|null
|
||||
*/
|
||||
public function createCard($mAddressBookId, $sCardUri, $sCardData)
|
||||
{
|
||||
return null;
|
||||
//
|
||||
// $stmt = $this->pdo->prepare('INSERT INTO ' . $this->cardsTableName . ' (carddata, uri, lastmodified, addressbookid) VALUES (?, ?, ?, ?)');
|
||||
//
|
||||
// $result = $stmt->execute(array($cardData, $cardUri, time(), $addressBookId));
|
||||
//
|
||||
// $stmt2 = $this->pdo->prepare('UPDATE ' . $this->addressBooksTableName . ' SET ctag = ctag + 1 WHERE id = ?');
|
||||
// $stmt2->execute(array($addressBookId));
|
||||
//
|
||||
// return '"' . md5($cardData) . '"';
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a card.
|
||||
*
|
||||
* The addressbook id will be passed as the first argument. This is the
|
||||
* same id as it is returned from the getAddressbooksForUser method.
|
||||
*
|
||||
* The cardUri is a base uri, and doesn't include the full path. The
|
||||
* cardData argument is the vcard body, and is passed as a string.
|
||||
*
|
||||
* It is possible to return an ETag from this method. This ETag should
|
||||
* match that of the updated resource, and must be enclosed with double
|
||||
* quotes (that is: the string itself must contain the actual quotes).
|
||||
*
|
||||
* You should only return the ETag if you store the carddata as-is. If a
|
||||
* subsequent GET request on the same card does not have the same body,
|
||||
* byte-by-byte and you did return an ETag here, clients tend to get
|
||||
* confused.
|
||||
*
|
||||
* If you don't return an ETag, you can just return null.
|
||||
*
|
||||
* @param mixed $mAddressBookId
|
||||
* @param string $sCardUri
|
||||
* @param string $sCardData
|
||||
* @return string|null
|
||||
*/
|
||||
public function updateCard($mAddressBookId, $sCardUri, $sCardData)
|
||||
{
|
||||
return null;
|
||||
|
||||
// $stmt = $this->pdo->prepare('UPDATE ' . $this->cardsTableName . ' SET carddata = ?, lastmodified = ? WHERE uri = ? AND addressbookid =?');
|
||||
// $stmt->execute(array($cardData, time(), $cardUri, $addressBookId));
|
||||
//
|
||||
// $stmt2 = $this->pdo->prepare('UPDATE ' . $this->addressBooksTableName . ' SET ctag = ctag + 1 WHERE id = ?');
|
||||
// $stmt2->execute(array($addressBookId));
|
||||
//
|
||||
// return '"' . md5($cardData) . '"';
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a card
|
||||
*
|
||||
* @param mixed $mAddressBookId
|
||||
* @param string $sCardUri
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteCard($mAddressBookId, $sCardUri)
|
||||
{
|
||||
return false;
|
||||
// $stmt = $this->pdo->prepare('DELETE FROM ' . $this->cardsTableName . ' WHERE addressbookid = ? AND uri = ?');
|
||||
// $stmt->execute(array($addressBookId, $cardUri));
|
||||
//
|
||||
// $stmt2 = $this->pdo->prepare('UPDATE ' . $this->addressBooksTableName . ' SET ctag = ctag + 1 WHERE id = ?');
|
||||
// $stmt2->execute(array($addressBookId));
|
||||
//
|
||||
// return $stmt->rowCount()===1;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace RainLoop\SabreDAV;
|
||||
|
||||
class CardDAV implements \Sabre\CardDAV\Backend\BackendInterface
|
||||
{
|
||||
/**
|
||||
* @var \RainLoop\Providers\PersonalAddressBook
|
||||
*/
|
||||
private $oPersonalAddressBook;
|
||||
|
||||
/**
|
||||
* @var \RainLoop\SabreDAV\AuthBasic
|
||||
*/
|
||||
private $oAuthBackend;
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Providers\PersonalAddressBook $oPersonalAddressBook
|
||||
* @param \RainLoop\SabreDAV\AuthBasic $oAuthBackend
|
||||
*/
|
||||
public function __construct($oPersonalAddressBook, &$oAuthBackend)
|
||||
{
|
||||
$this->oPersonalAddressBook = $oPersonalAddressBook;
|
||||
$this->oPersonalAddressBook->ConsiderShare(false);
|
||||
$this->oAuthBackend = $oAuthBackend;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sPrincipalUri
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getEmailFromPrincipalUri($sPrincipalUri)
|
||||
{
|
||||
$sEmail = '';
|
||||
$aMatch = array();
|
||||
if (\preg_match('/\/?principals\/([^@\/]+@[^@\/]+)/i', $sPrincipalUri, $aMatch) && !empty($aMatch[1]))
|
||||
{
|
||||
$sEmail = \trim($aMatch[1]);
|
||||
}
|
||||
|
||||
return $sEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sPrincipalUri = ''
|
||||
* @param string $mAddressBookID = ''
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getAuthEmail($sPrincipalUri = '', $mAddressBookID = '')
|
||||
{
|
||||
$sGetCurrentUser = \trim($this->oAuthBackend->getCurrentUser());
|
||||
if (0 < \strlen($sPrincipalUri) && 0 < \strlen($sGetCurrentUser) &&
|
||||
$sGetCurrentUser !== $this->getEmailFromPrincipalUri($sPrincipalUri))
|
||||
{
|
||||
$sGetCurrentUser = '';
|
||||
}
|
||||
|
||||
if (0 < \strlen((string) $mAddressBookID) && 0 < \strlen($sGetCurrentUser) &&
|
||||
(string) $mAddressBookID !== (string) $this->oPersonalAddressBook->GetUserUidByEmail($sGetCurrentUser))
|
||||
{
|
||||
$sGetCurrentUser = '';
|
||||
}
|
||||
|
||||
return $sGetCurrentUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of addressbooks for a specific user.
|
||||
*
|
||||
* @param string $sPrincipalUri
|
||||
* @return array
|
||||
*/
|
||||
public function getAddressBooksForUser($sPrincipalUri)
|
||||
{
|
||||
$aAddressBooks = array();
|
||||
|
||||
$sEmail = $this->getAuthEmail($sPrincipalUri);
|
||||
if (0 < strlen($sEmail))
|
||||
{
|
||||
$mAddressBookID = $this->oPersonalAddressBook->GetUserUidByEmail($sEmail);
|
||||
if (!empty($mAddressBookID))
|
||||
{
|
||||
$aAddressBooks[] = array(
|
||||
'id' => $mAddressBookID,
|
||||
'uri' => 'default',
|
||||
'principaluri' => $sPrincipalUri,
|
||||
'{DAV:}displayname' => 'Personal Address Book',
|
||||
'{'.\Sabre\CardDAV\Plugin::NS_CARDDAV.'}addressbook-description' => 'Personal Address Book',
|
||||
'{http://calendarserver.org/ns/}getctag' => 1,
|
||||
'{'.\Sabre\CardDAV\Plugin::NS_CARDDAV.'}supported-address-data' => new \Sabre\CardDAV\Property\SupportedAddressData()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $aAddressBooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an addressbook's properties
|
||||
*
|
||||
* See Sabre\DAV\IProperties for a description of the mutations array, as
|
||||
* well as the return value.
|
||||
*
|
||||
* @param mixed $mAddressBookId
|
||||
* @param array $aMutations
|
||||
* @see Sabre\DAV\IProperties::updateProperties
|
||||
* @return bool|array
|
||||
*/
|
||||
public function updateAddressBook($mAddressBookID, array $aMutations)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new address book
|
||||
*
|
||||
* @param string $sPrincipalUri
|
||||
* @param string $sUrl Just the 'basename' of the url.
|
||||
* @param array $aProperties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function createAddressBook($sPrincipalUri, $sUrl, array $aProperties)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an entire addressbook and all its contents
|
||||
*
|
||||
* @param mixed $mAddressBookID
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAddressBook($mAddressBookID)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all cards for a specific addressbook id.
|
||||
*
|
||||
* This method should return the following properties for each card:
|
||||
* * carddata - raw vcard data
|
||||
* * uri - Some unique url
|
||||
* * lastmodified - A unix timestamp
|
||||
*
|
||||
* It's recommended to also return the following properties:
|
||||
* * etag - A unique etag. This must change every time the card changes.
|
||||
* * size - The size of the card in bytes.
|
||||
*
|
||||
* If these last two properties are provided, less time will be spent
|
||||
* calculating them. If they are specified, you can also ommit carddata.
|
||||
* This may speed up certain requests, especially with large cards.
|
||||
*
|
||||
* @param mixed $mAddressBookID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCards($mAddressBookID)
|
||||
{
|
||||
$aResult = array();
|
||||
if (!empty($mAddressBookID))
|
||||
{
|
||||
$sEmail = $this->getAuthEmail('', $mAddressBookID);
|
||||
if (!empty($sEmail))
|
||||
{
|
||||
$aList = $this->oPersonalAddressBook->GetContacts($sEmail, 0, 500);
|
||||
foreach ($aList as /* @var $oItem \RainLoop\Providers\PersonalAddressBook\Classes\Contact */ $oItem)
|
||||
{
|
||||
if (!$oItem->ReadOnly)
|
||||
{
|
||||
$sCardData = $oItem->ToVCardObject()->serialize();
|
||||
$aResult[] = array(
|
||||
'uri' => $oItem->VCardUID(),
|
||||
'lastmodified' => $oItem->Changed,
|
||||
'etag' => \md5($sCardData),
|
||||
'size' => \strlen($sCardData)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a specfic card.
|
||||
*
|
||||
* The same set of properties must be returned as with getCards. The only
|
||||
* exception is that 'carddata' is absolutely required.
|
||||
*
|
||||
* @param mixed $mAddressBookID
|
||||
* @param string $sCardUri
|
||||
* @return array
|
||||
*/
|
||||
public function getCard($mAddressBookID, $sCardUri)
|
||||
{
|
||||
$oContact = null;
|
||||
if (!empty($mAddressBookID) && !empty($sCardUri) && '.vcf' === \substr($sCardUri, -4))
|
||||
{
|
||||
$sEmail = $this->getAuthEmail('', $mAddressBookID);
|
||||
if (!empty($sEmail))
|
||||
{
|
||||
$oContact = $this->oPersonalAddressBook->GetContactByID($sEmail, \substr($sCardUri, 0, -4), true);
|
||||
}
|
||||
}
|
||||
|
||||
if ($oContact)
|
||||
{
|
||||
$sCardData = $oContact->ToVCardObject()->serialize();
|
||||
return array(
|
||||
'uri' => $oContact->VCardUID(),
|
||||
'lastmodified' => $oContact->Changed,
|
||||
'etag' => \md5($sCardData),
|
||||
'size' => \strlen($sCardData),
|
||||
'carddata' => $sCardData
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new card.
|
||||
*
|
||||
* The addressbook id will be passed as the first argument. This is the
|
||||
* same id as it is returned from the getAddressbooksForUser method.
|
||||
*
|
||||
* The cardUri is a base uri, and doesn't include the full path. The
|
||||
* cardData argument is the vcard body, and is passed as a string.
|
||||
*
|
||||
* It is possible to return an ETag from this method. This ETag is for the
|
||||
* newly created resource, and must be enclosed with double quotes (that
|
||||
* is, the string itself must contain the double quotes).
|
||||
*
|
||||
* You should only return the ETag if you store the carddata as-is. If a
|
||||
* subsequent GET request on the same card does not have the same body,
|
||||
* byte-by-byte and you did return an ETag here, clients tend to get
|
||||
* confused.
|
||||
*
|
||||
* If you don't return an ETag, you can just return null.
|
||||
*
|
||||
* @param mixed $mAddressBookID
|
||||
* @param string $sCardUri
|
||||
* @param string $sCardData
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function createCard($mAddressBookID, $sCardUri, $sCardData)
|
||||
{
|
||||
if (!empty($mAddressBookID) && !empty($sCardUri) && '.vcf' === \substr($sCardUri, -4) && 0 < \strlen($sCardData))
|
||||
{
|
||||
$sEmail = $this->getAuthEmail('', $mAddressBookID);
|
||||
if (!empty($sEmail))
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a card.
|
||||
*
|
||||
* The addressbook id will be passed as the first argument. This is the
|
||||
* same id as it is returned from the getAddressbooksForUser method.
|
||||
*
|
||||
* The cardUri is a base uri, and doesn't include the full path. The
|
||||
* cardData argument is the vcard body, and is passed as a string.
|
||||
*
|
||||
* It is possible to return an ETag from this method. This ETag should
|
||||
* match that of the updated resource, and must be enclosed with double
|
||||
* quotes (that is: the string itself must contain the actual quotes).
|
||||
*
|
||||
* You should only return the ETag if you store the carddata as-is. If a
|
||||
* subsequent GET request on the same card does not have the same body,
|
||||
* byte-by-byte and you did return an ETag here, clients tend to get
|
||||
* confused.
|
||||
*
|
||||
* If you don't return an ETag, you can just return null.
|
||||
*
|
||||
* @param mixed $mAddressBookID
|
||||
* @param string $sCardUri
|
||||
* @param string $sCardData
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function updateCard($mAddressBookID, $sCardUri, $sCardData)
|
||||
{
|
||||
if (!empty($mAddressBookID) && !empty($sCardUri) && '.vcf' === \substr($sCardUri, -4) && 0 < \strlen($sCardData))
|
||||
{
|
||||
$sEmail = $this->getAuthEmail('', $mAddressBookID);
|
||||
if (!empty($sEmail))
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a card
|
||||
*
|
||||
* @param mixed $mAddressBookID
|
||||
* @param string $sCardUri
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteCard($mAddressBookID, $sCardUri)
|
||||
{
|
||||
$bResult = false;
|
||||
$oContact = null;
|
||||
if (!empty($mAddressBookID) && !empty($sCardUri) && '.vcf' === \substr($sCardUri, -4))
|
||||
{
|
||||
$sEmail = $this->getAuthEmail('', $mAddressBookID);
|
||||
if (!empty($sEmail))
|
||||
{
|
||||
$oContact = $this->oPersonalAddressBook->GetContactByID($sEmail, \substr($sCardUri, 0, -4), true);
|
||||
}
|
||||
}
|
||||
|
||||
if ($oContact)
|
||||
{
|
||||
$bResult = $this->oPersonalAddressBook->DeleteContacts($sEmail, array($oContact->IdContact));
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,6 @@ class Principal extends \Sabre\DAVACL\PrincipalBackend\AbstractBackend
|
|||
$sGetCurrentUser = $this->oAuthBackend->getCurrentUser();
|
||||
if ('principals/'.$sGetCurrentUser === $sPath)
|
||||
{
|
||||
// var_dump($sPath);
|
||||
return array(
|
||||
'uri' => 'principals/'.$sGetCurrentUser,
|
||||
'{DAV:}displayname' => $sGetCurrentUser,
|
||||
|
|
@ -133,7 +132,7 @@ class Principal extends \Sabre\DAVACL\PrincipalBackend\AbstractBackend
|
|||
*/
|
||||
function updatePrincipal($path, $mutations)
|
||||
{
|
||||
return array();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue