exit;
}
-$addressbook = $turba_shares->getShare($addressbook_id);
-if (is_a($addressbook, 'PEAR_Error')) {
- $notification->push($addressbook, 'horde.error');
+try {
+ $addressbook = $turba_shares->getShare($addressbook_id);
+} catch (Horde_Share_Exception $e) {
+ $notification->push($e, 'horde.error');
header('Location: ' . Horde::applicationUrl('addressbooks/', true));
exit;
-} elseif (!Horde_Auth::getAuth() ||
- $addressbook->get('owner') != Horde_Auth::getAuth()) {
+}
+if (!Horde_Auth::getAuth() ||
+ $addressbook->get('owner') != Horde_Auth::getAuth()) {
+
$notification->push(_("You are not allowed to delete this addressbook."), 'horde.error');
header('Location: ' . Horde::applicationUrl('addressbooks/', true));
exit;
}
$vars = Horde_Variables::getDefaultVariables();
-$addressbook = $turba_shares->getShare($vars->get('a'));
-if (is_a($addressbook, 'PEAR_Error')) {
- $notification->push($addressbook, 'horde.error');
+try {
+ $addressbook = $turba_shares->getShare($vars->get('a'));
+} catch (Horde_Share_Exception $e) {
+ $notification->push($e->getMessage(), 'horde.error');
header('Location: ' . Horde::applicationUrl('addressbooks/', true));
exit;
-} elseif (!Horde_Auth::getAuth() ||
- $addressbook->get('owner') != Horde_Auth::getAuth()) {
+}
+if (!Horde_Auth::getAuth() ||
+ $addressbook->get('owner') != Horde_Auth::getAuth()) {
+
$notification->push(_("You are not allowed to change this addressbook."), 'horde.error');
header('Location: ' . Horde::applicationUrl('addressbooks/', true));
exit;
'addSources' => $addSources,
'cfgSources' => $cfgSources,
'attributes' => $attributes,
- 'turba_shares' => &$turba_shares,
+ 'turba_shares' => $turba_shares,
'conf' => $conf,
'source' => $default_source,
'browser' => $browser
if (!empty($_SESSION['turba']['has_share'])) {
$shares = Turba::listShares(true);
- if ($shares instanceof PEAR_Error) {
- return false;
- }
foreach ($shares as $uid => $share) {
$params = @unserialize($share->get('params'));
if (empty($params['source'])) {
$curpath = 'turba/' . $parts[0] . '/';
foreach ($addressbooks as $addressbook => $info) {
if (in_array('name', $properties)) {
- if (is_a($info, 'Horde_Share_Object')) {
+ if ($info instanceof Horde_Share_Object) {
$name = $info->get('title');
} else {
$name = $info['title'];
$cManager = new Horde_Prefs_CategoryManager();
$categories = $cManager->get();
- if (!is_a($content, 'Horde_iCalendar_vcard')) {
+ if (!($content instanceof Horde_iCalendar_vcard)) {
switch ($contentType) {
case 'array':
break;
default:
$ids = array();
foreach ($iCal->getComponents() as $c) {
- if (is_a($c, 'Horde_iCalendar_vcard')) {
+ if ($c instanceof Horde_iCalendar_vcard) {
$content = $driver->toHash($c);
$result = $driver->search($content);
if ($result instanceof PEAR_Error) {
}
}
- if (is_a($content, 'Horde_iCalendar_vcard')) {
+ if ($content instanceof Horde_iCalendar_vcard) {
$content = $driver->toHash($content);
}
}
$search = $driver->search($criteria, Turba::getPreferredSortOrder(), 'OR', array(), array(), $matchBegin);
- if (!is_a($search, 'Turba_List')) {
+ if (!($search instanceof Turba_List)) {
continue;
}
$seeninlist = array();
$members = $ob->listMembers();
$listName = $ob->getValue('name');
- if (!is_a($members, 'Turba_List')) {
+ if (!($members instanceof Turba_List)) {
continue;
}
if ($members->count() > 0) {
}
$res = $driver->search(array());
- if (!is_a($res, 'Turba_List')) {
+ if (!($res instanceof Turba_List)) {
throw new Horde_Exception(_("Search failed"));
}
}
$list = $driver->search(array('email' => $address), null, 'AND', array(), $strict ? array('email') : array());
- if (!is_a($list, 'Turba_List')) {
+ if (!($list instanceof Turba_List)) {
continue;
}
}
$res = $driver->search(array('email' => $address));
- if (is_a($res, 'Turba_List')) {
+ if ($res instanceof Turba_List) {
if ($res->count() > 1) {
continue;
}
/* Only attempt share removal if we have shares configured */
if (!empty($_SESSION['turba']['has_share'])) {
- $shares = &$GLOBALS['turba_shares']->listShares(
+ $shares = $GLOBALS['turba_shares']->listShares(
$user, Horde_Perms::EDIT, $user);
/* Look for the deleted user's default share and remove it */
}
}
- /* Get a list of all shares this user has perms to and remove the
- * perms. */
- $shares = $GLOBALS['turba_shares']->listShares($user);
- if (is_a($shares, 'PEAR_Error')) {
- Horde::logMessage($shares, 'ERR');
- }
- foreach ($shares as $share) {
- $share->removeUser($user);
+ /* Get a list of all shares this user has perms to and remove the perms. */
+ try {
+ $shares = $GLOBALS['turba_shares']->listShares($user);
+ foreach ($shares as $share) {
+ $share->removeUser($user);
+ }
+ } catch (Horde_Share_Exception $e) {
+ Horde::logMessage($e, 'ERR');
}
-
}
if ($hasError) {
*
* @param array $params The params for the share.
*
- * @return mixed The share object or PEAR_Error.
+ * @return Horde_Share The share object.
*/
- function &createShare($share_id, $params)
+ function createShare($share_id, $params)
{
// If the raw address book name is not set, use the share name
if (empty($params['params']['name'])) {
$params['params']['name'] = $share_id;
}
- $result = &Turba::createShare($share_id, $params);
- return $result;
+ return Turba::createShare($share_id, $params);
}
/**
*
* @return boolean
*/
- function checkDefaultShare(&$share, $srcconfig)
+ function checkDefaultShare($share, $srcconfig)
{
$params = @unserialize($share->get('params'));
if (!isset($params['default'])) {
*
* @return mixed The share object or PEAR_Error.
*/
- function &createShare($share_id, $params)
+ function createShare($share_id, $params)
{
if (isset($params['default']) && $params['default'] === true) {
$params['params']['name'] = $this->params['username'];
*
* @see turba/lib/Turba_Driver#checkDefaultShare($share, $srcconfig)
*/
- function checkDefaultShare(&$share, $srcConfig)
+ function checkDefaultShare($share, $srcConfig)
{
$params = @unserialize($share->get('params'));
if (!isset($params['default'])) {
*
* @return mixed The share object or PEAR_Error.
*/
- function &createShare($share_id, $params)
+ function createShare($share_id, $params)
{
if (isset($params['params']['default']) && $params['params']['default'] === true) {
$share_id = Horde_Auth::getAuth();
}
- $result = &Turba::createShare($share_id, $params);
+ $result = Turba::createShare($share_id, $params);
return $result;
}
- function checkDefaultShare(&$share, $srcConfig)
+ function checkDefaultShare($share, $srcConfig)
{
$params = @unserialize($share->get('params'));
return isset($params['default']) ? $params['default'] : false;
function _init()
{
/* Grab a reference to the share for this vbook. */
- $this->_share = &$this->_params['share'];
+ $this->_share = $this->_params['share'];
/* Load the underlying driver. */
$this->_driver = &Turba_Driver::singleton($this->_params['source']);
include TURBA_BASE . '/config/sources.php';
$driver = Turba_Driver::singleton($cfgSources[$GLOBALS['conf']['shares']['source']]);
- if (is_a($driver, 'PEAR_Error')) {
+ if ($driver instanceof PEAR_Error) {
return $driver;
}
// Address book successfully deleted from backend, remove the
// share.
- $result = $GLOBALS['turba_shares']->removeShare($this->_addressbook);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
+ try {
+ $GLOBALS['turba_shares']->removeShare($this->_addressbook);
+ } catch (Horde_Share_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
+ throw new Turba_Exception($e);
}
if (isset($_SESSION['turba']['source']) && $_SESSION['turba']['source'] == Horde_Util::getFormData('deleteshare')) {
{
global $notification;
- $shares = Turba::listShares();
-
- // Notify the user if we failed, but still return the $cfgSource array.
- if (is_a($shares, 'PEAR_Error')) {
- $notification->push($shares, 'horde.error');
+ try {
+ $shares = Turba::listShares();
+ } catch (Horde_Share_Exception $e) {
+ // Notify the user if we failed, but still return the $cfgSource array.
+ $notification->push($e->getMessage(), 'horde.error');
return $sources;
}
$params = @unserialize($shares[$name]->get('params'));
if (isset($params['type']) && $params['type'] == 'vbook') {
// We load vbooks last in case they're based on other shares.
- $params['share'] = &$shares[$name];
+ $params['share'] = $shares[$name];
$vbooks[$name] = $params;
} elseif (!empty($params['source']) &&
!empty($sources[$params['source']]['use_shares'])) {
$share = $sources[$params['source']];
$share['params']['config'] = $sources[$params['source']];
- $share['params']['config']['params']['share'] = &$shares[$name];
+ $share['params']['config']['params']['share'] = $shares[$name];
$share['params']['config']['params']['name'] = $params['name'];
$share['title'] = $shares[$name]->get('name');
$share['type'] = 'share';
if (Horde_Auth::getAuth() && empty($defaults[$source])) {
// User's default share is missing.
$driver = Turba_Driver::singleton($source);
- if (!is_a($driver, 'PEAR_Error')) {
+ if (!($driver instanceof PEAR_Error)) {
$sourceKey = md5(mt_rand());
- $share = &$driver->createShare(
- $sourceKey,
- array('params' => array('source' => $source,
- 'default' => true,
- 'name' => Horde_Auth::getAuth())));
- if (is_a($share, 'PEAR_Error')) {
- Horde::logMessage($share, 'ERR');
+ try {
+ $share = $driver->createShare(
+ $sourceKey,
+ array('params' => array('source' => $source,
+ 'default' => true,
+ 'name' => Horde_Auth::getAuth())));
+ } catch (Horde_Share_Exception $e) {
+ Horde::logMessage($e, 'ERR');
continue;
}
$source_config = $sources[$source];
- $source_config['params']['share'] = &$share;
+ $source_config['params']['share'] = $share;
$newSources[$sourceKey] = $source_config;
} else {
$notification->push($driver, 'horde.error');
*
* @param Horde_Share object The share to base config on.
*/
- function getSourceFromShare(&$share)
+ function getSourceFromShare($share)
{
// Require a fresh config file.
require TURBA_BASE . '/config/sources.php';
$params = @unserialize($share->get('params'));
$newConfig = $cfgSources[$params['source']];
$newConfig['params']['config'] = $cfgSources[$params['source']];
- $newConfig['params']['config']['params']['share'] = &$share;
+ $newConfig['params']['config']['params']['share'] = $share;
$newConfig['params']['config']['params']['name'] = $params['name'];
$newConfig['title'] = $share->get('name');
$newConfig['type'] = 'share';
return array();
}
- $sources = $GLOBALS['turba_shares']->listShares(
- Horde_Auth::getAuth(), $permission,
- $owneronly ? Horde_Auth::getAuth() : null);
- if (is_a($sources, 'PEAR_Error')) {
- Horde::logMessage($sources, 'ERR');
+ try {
+ $sources = $GLOBALS['turba_shares']->listShares(
+ Horde_Auth::getAuth(), $permission,
+ $owneronly ? Horde_Auth::getAuth() : null);
+ } catch (Horde_Share_Exception $e) {
+ Horde::logMessage($e, 'ERR');
return array();
}
return $sources;
*
* @return mixed The new share object or PEAR_Error
*/
- function &createShare($share_id, $params)
+ function createShare($share_id, $params)
{
if (!isset($params['name'])) {
/* Sensible default for empty display names */
}
/* Generate the new share. */
- $share = &$GLOBALS['turba_shares']->newShare($share_id);
- if (is_a($share, 'PEAR_Error')) {
- return $share;
- }
+ try {
+ $share = $GLOBALS['turba_shares']->newShare($share_id);
- /* Set the display name for this share. */
- $share->set('name', $name);
+ /* Set the display name for this share. */
+ $share->set('name', $name);
- /* Now any other params. */
- foreach ($params as $key => $value) {
- if (!is_scalar($value)) {
- $value = serialize($value);
+ /* Now any other params. */
+ foreach ($params as $key => $value) {
+ if (!is_scalar($value)) {
+ $value = serialize($value);
+ }
+ $share->set($key, $value);
}
- $share->set($key, $value);
- }
-
- $result = $GLOBALS['turba_shares']->addShare($share);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
-
- $result = $share->save();
- if (is_a($result, 'PEAR_Error')) {
- return $result;
+ $GLOBALS['turba_shares']->addShare($share);
+ $result = $share->save();
+ } catch (Horde_Share_Exception $e) {
+ Horde::logMessage($e->getMessage, 'ERR');
+ throw new Nag_Exception($e);
}
/* Update share_id as backends like Kolab change it to the IMAP folder
'source' => $params['source'],
'criteria' => $params['criteria'])));
- $share = Turba::createShare(md5(microtime()), $params);
- if (is_a($share, 'PEAR_Error')) {
- return $share;
+ try {
+ $share = Turba::createShare(md5(microtime()), $params);
+ } catch (Horde_Share_Exception $e) {
+ throw new Turba_Exception($e);
}
-
return $share->getName();
}