Blame view
sources/apps/contacts/lib/sabre/backend.php
5.12 KB
|
03e52840d
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
<?php
/**
* ownCloud - Addressbook
*
* @author Jakob Sack
* @copyright 2011 Jakob Sack mail@jakobsack.de
*
* 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/>.
*
*/
/**
* This CardDAV backend uses PDO to store addressbooks
*/
class OC_Connector_Sabre_CardDAV extends Sabre_CardDAV_Backend_Abstract {
/**
* Returns the list of addressbooks for a specific user.
*
* @param string $principaluri
* @return array
*/
public function getAddressBooksForUser($principaluri) {
$data = OCA\Contacts\Addressbook::allWherePrincipalURIIs($principaluri);
$addressbooks = array();
foreach($data as $i) {
if($i['userid'] != OCP\USER::getUser()) {
$i['uri'] = $i['uri'] . '_shared_by_' . $i['userid'];
}
$addressbooks[] = array(
'id' => $i['id'],
'uri' => $i['uri'],
'principaluri' => 'principals/'.$i['userid'],
'{DAV:}displayname' => $i['displayname'],
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description'
=> $i['description'],
'{http://calendarserver.org/ns/}getctag' => $i['ctag'],
);
}
return $addressbooks;
}
/**
* Updates an addressbook's properties
*
* See Sabre_DAV_IProperties for a description of the mutations array, as
* well as the return value.
*
* @param mixed $addressbookid
* @param array $mutations
* @see Sabre_DAV_IProperties::updateProperties
* @return bool|array
*/
public function updateAddressBook($addressbookid, array $mutations) {
$name = null;
$description = null;
foreach($mutations as $property=>$newvalue) {
switch($property) {
case '{DAV:}displayname' :
$name = $newvalue;
break;
case '{' . Sabre_CardDAV_Plugin::NS_CARDDAV
. '}addressbook-description' :
$description = $newvalue;
break;
default :
// If any unsupported values were being updated, we must
// let the entire request fail.
return false;
}
}
OCA\Contacts\Addressbook::edit($addressbookid, $name, $description);
return true;
}
/**
* Creates a new address book
*
* @param string $principaluri
* @param string $url Just the 'basename' of the url.
* @param array $properties
* @return void
*/
public function createAddressBook($principaluri, $url, array $properties) {
$displayname = null;
$description = null;
foreach($properties as $property=>$newvalue) {
switch($property) {
case '{DAV:}displayname' :
$name = $newvalue;
break;
case '{' . Sabre_CardDAV_Plugin::NS_CARDDAV
. '}addressbook-description' :
$description = $newvalue;
break;
default :
throw new Sabre_DAV_Exception_BadRequest('Unknown property: '
. $property);
}
}
OCA\Contacts\Addressbook::addFromDAVData(
$principaluri,
$url,
$name,
$description
);
}
/**
* Deletes an entire addressbook and all its contents
*
* @param int $addressbookid
* @return void
*/
public function deleteAddressBook($addressbookid) {
OCA\Contacts\Addressbook::delete($addressbookid);
}
/**
* Returns all cards for a specific addressbook id.
*
* @param mixed $addressbookid
* @return array
*/
public function getCards($addressbookid) {
$data = OCA\Contacts\VCard::all($addressbookid);
$cards = array();
foreach($data as $i) {
$cards[] = array(
'id' => $i['id'],
//'carddata' => $i['carddata'],
'size' => strlen($i['carddata']),
'etag' => '"' . md5($i['carddata']) . '"',
'uri' => urlencode($i['uri']),
'lastmodified' => $i['lastmodified'] );
}
return $cards;
}
/**
* Returns a specfic card
*
* @param mixed $addressbookid
* @param string $carduri
* @return array
*/
public function getCard($addressbookid, $carduri) {
return OCA\Contacts\VCard::findWhereDAVDataIs($addressbookid, urldecode($carduri));
}
/**
* Creates a new card
*
* @param mixed $addressbookid
* @param string $carduri
* @param string $carddata
* @return bool
*/
public function createCard($addressbookid, $carduri, $carddata) {
OCA\Contacts\VCard::addFromDAVData($addressbookid, $carduri, $carddata);
}
/**
* Updates a card
*
* @param mixed $addressbookid
* @param string $carduri
* @param string $carddata
* @return bool
*/
public function updateCard($addressbookid, $carduri, $carddata) {
return OCA\Contacts\VCard::editFromDAVData(
$addressbookid, $carduri, $carddata
);
}
/**
* Deletes a card
*
* @param mixed $addressbookid
* @param string $carduri
* @return bool
*/
public function deleteCard($addressbookid, $carduri) {
return OCA\Contacts\VCard::deleteFromDAVData($addressbookid, $carduri);
}
}
|