/usr/share/horde/turba/lib/Driver/Share.php is in php-horde-turba 4.1.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | <?php
/**
* The Turba_Driver:: class provides a common abstracted interface to the
* various directory search drivers. It includes functions for searching,
* adding, removing, and modifying directory entries.
*
* Copyright 2009-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (ASL). If you did
* did not receive this file, see http://www.horde.org/licenses/apache.
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @author Jon Parise <jon@csh.rit.edu>
* @author Michael J. Rubinsky <mrubinsk@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/apache ASL
* @package Turba
*/
class Turba_Driver_Share extends Turba_Driver
{
/**
* Horde_Share object for this source.
*
* @var Horde_Share
*/
protected $_share;
/**
* Underlying driver object for this source.
*
* @var Turba_Driver
*/
protected $_driver;
/**
* Constructor
*
* @param string $name The source name
* @param array $params The parameter array describing the source
*
* @return Turba_Driver
*/
public function __construct($name = '', array $params = array())
{
parent::__construct($name, $params);
$this->_share = $this->_params['config']['params']['share'];
$this->_driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($this->_params['config']);
$this->_driver->setContactOwner($this->_getContactOwner());
$this->_driver->setSourceName($name);
}
/**
* Proxy to decorated base driver.
*
* @param string $method Method name.
* @param array $args Method arguments.
*
* @return mixed Method result.
*/
public function __call($method, $args)
{
return call_user_func_array(array($this->_driver, $method), $args);
}
/**
* Checks if this backend has a certain capability.
*
* @param string $capability The capability to check for.
*
* @return boolean Supported or not.
*/
public function hasCapability($capability)
{
return $this->_driver->hasCapability($capability);
}
/**
* Translates the keys of the first hash from the generalized Turba
* attributes to the driver-specific fields. The translation is based on
* the contents of $this->map.
*
* @param array $hash Hash using Turba keys.
*
* @return array Translated version of $hash.
*/
public function toDriverKeys(array $hash)
{
return $this->_driver->toDriverKeys($hash);
}
/**
* Searches the current address book for duplicate entries.
*
* Duplicates are determined by comparing email and name or last name and
* first name values.
*
* @return array A hash with the following format:
* <code>
* array('name' => array('John Doe' => Turba_List, ...), ...)
* </code>
* @throws Turba_Exception
*/
public function searchDuplicates()
{
return $this->_driver->searchDuplicates();
}
/**
* Checks if the current user has the requested permissions on this
* address book.
*
* @param integer $perm The permission to check for.
*
* @return boolean True if the user has permission, otherwise false.
*/
public function hasPermission($perm)
{
return $this->_share->hasPermission($GLOBALS['registry']->getAuth(), $perm);
}
/**
* Return the name of this address book.
*
* @string Address book name
*/
public function getName()
{
$share_parts = explode(':', $this->_share->getName());
return array_pop($share_parts);
}
/**
* Return the owner to use when searching or creating contacts in
* this address book.
*
* @return string TODO
* @throws Turba_Exception
*/
protected function _getContactOwner()
{
$params = @unserialize($this->_share->get('params'));
if (!empty($params['name'])) {
return $params['name'];
}
throw new Turba_Exception(_("Unable to find contact owner."));
}
/**
* Runs any actions after setting a new default tasklist.
*
* @param string $share The default share ID.
*/
public function setDefaultShare($share)
{
$this->_driver->setDefaultShare($share);
}
/**
* Creates an object key for a new object.
*
* @param array $attributes The attributes (in driver keys) of the
* object being added.
*
* @return string A unique ID for the new object.
*/
protected function _makeKey(array $attributes)
{
return $this->_driver->_makeKey($attributes);
}
/**
* Creates an object UID for a new object.
*
* @return string A unique ID for the new object.
*/
protected function _makeUid()
{
return $this->_driver->_makeUid();
}
/**
* Searches the address book with the given criteria and returns a
* filtered list of results. If the criteria parameter is an empty array,
* all records will be returned.
*
* @param array $criteria Array containing the search criteria.
* @param array $fields List of fields to return.
* @param array $blobFields Array of fields containing binary data.
* @param boolean $count_only Only return the count of matching entries,
* not the entries themselves.
*
* @return array Hash containing the search results.
* @throws Turba_Exception
*/
protected function _search(array $criteria, array $fields, array $blobFields = array(), $count_only = false)
{
return $this->_driver->_search($criteria, $fields, $blobFields, $count_only);
}
/**
* Reads the given data from the address book and returns the results.
*
* @param string $key The primary key field to use.
* @param mixed $ids The ids of the contacts to load.
* @param string $owner Only return contacts owned by this user.
* @param array $fields List of fields to return.
* @param array $blobFields Array of fields containing binary data.
*
* @return array Hash containing the search results.
* @throws Turba_Exception
*/
protected function _read($key, $ids, $owner, array $fields,
array $blobFields = array())
{
return $this->_driver->_read($key, $ids, $owner, $fields, $blobFields);
}
/**
* Adds the specified contact to the addressbook.
*
* @param array $attributes The attribute values of the contact.
* @param array $blob_fields TODO
*
* @throws Turba_Exception
*/
protected function _add(array $attributes, array $blob_fields = array())
{
return $this->_driver->_add($attributes, $blob_fields);
}
/**
* Returns ability of the backend to add new contacts.
*
* @return boolean Can backend add?
*/
protected function _canAdd()
{
return $this->_driver->_canAdd();
}
/**
* Deletes the specified contact from the addressbook.
*
* @param string $object_key TODO
* @param string $object_id TODO
*
* @throws Turba_Exception
*/
protected function _delete($object_key, $object_id)
{
return $this->_driver->_delete($object_key, $object_id);
}
/**
* Deletes all contacts from a specific address book.
*
* @param string $sourceName The source to remove all contacts from.
*
* @return array An array of UIDs
* @throws Turba_Exception
*/
protected function _deleteAll($sourceName = null)
{
if (is_null($sourceName)) {
$sourceName = $this->getContactOwner();
}
return $this->_driver->_deleteAll($sourceName);
}
/**
* Saves the specified object in the SQL database.
*
* @param Turba_Object $object The object to save
*
* @return string The object id, possibly updated.
* @throws Turba_Exception
*/
protected function _save(Turba_Object $object)
{
return $this->_driver->_save($object);
}
/**
* Remove all data for a specific user.
*
* @param string $user The user to remove all data for.
*/
public function removeUserData($user)
{
// Make sure we are being called by an admin.
if (!$GLOBALS['registry']->isAdmin()) {
throw new Horde_Exception_PermissionDenied(_("Permission denied"));
}
$this->_deleteAll();
$GLOBALS['injector']
->getInstance('Turba_Shares')
->removeShare($this->_share);
unset($this->_share);
}
}
|