Move some session code from Horde:: to Horde_Registry::.
$errApps = array();
foreach ($GLOBALS['registry']->listApps(array('notoolbar', 'hidden', 'active', 'admin')) as $app) {
- if ($GLOBALS['registry']->hasMethod('removeUserData', $app) &&
- is_a($result = $GLOBALS['registry']->callByPackage($app, 'removeUserData', array($userId)), 'PEAR_Error')) {
- Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+ try {
+ $GLOBALS['registry']->callByPackage($app, 'removeUserData', array($userId));
+ } catch (Horde_Exception $e) {
+ Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
$errApps[] = $app;
}
}
throw new Horde_Exception($this->_params['app'] . ' does not provide an authenticate() method.');
}
- if (!$GLOBALS['registry']->callByPackage($this->_params['app'], 'authenticate', array('userId' => $userId, 'credentials' => $credentials, 'params' => $this->_params))) {
+ try {
+ if (!$GLOBALS['registry']->callByPackage($this->_params['app'], 'authenticate', array('userId' => $userId, 'credentials' => $credentials, 'params' => $this->_params))) {
+ throw new Horde_Exception('', Horde_Auth::REASON_BADLOGIN);
+ }
+ } catch (Horde_Exception $e) {
throw new Horde_Exception('', Horde_Auth::REASON_BADLOGIN);
}
public function removeUser($userId)
{
if ($this->hasCapability('remove')) {
- $res = $GLOBALS['registry']->callByPackage($this->_params['app'], 'removeUser', array($userId));
- if (is_a($res, 'PEAR_Error')) {
- throw new Horde_Exception($result);
- }
-
+ $GLOBALS['registry']->callByPackage($this->_params['app'], 'removeUser', array($userId));
Horde_Auth::removeUserData($userId);
} else {
parent::removeUser($userId);
}
/**
- * Destroys any existing session on login and make sure to use a new
- * session ID, to avoid session fixation issues. Should be called before
- * checking a login.
- */
- static public function getCleanSession()
- {
- // Make sure to force a completely new session ID and clear all
- // session data.
- session_regenerate_id(true);
- session_unset();
-
- /* Reset cookie timeouts, if necessary. */
- if (!empty($GLOBALS['conf']['session']['timeout'])) {
- $app = $GLOBALS['registry']->getApp();
- if (Horde_Secret::clearKey($app)) {
- Horde_Secret::setKey($app);
- }
- Horde_Secret::setKey('auth');
- }
- }
-
- /**
* Aborts with a fatal error, displaying debug information to the user.
*
* @param mixed $error Either a string or an object with a getMessage()
}
/**
- * Sets a custom session handler up, if there is one.
- * If the global variable 'session_cache_limiter' is defined, its value
- * will override the cache limiter setting found in the configuration
- * file.
- *
- * The custom session handler object will be contained in the global
- * 'horde_sessionhandler' variable.
- */
- static public function setupSessionHandler()
- {
- global $conf;
-
- ini_set('url_rewriter.tags', 0);
- if (!empty($conf['session']['use_only_cookies'])) {
- ini_set('session.use_only_cookies', 1);
- if (!empty($conf['cookie']['domain']) &&
- strpos($conf['server']['name'], '.') === false) {
- self::fatal('Session cookies will not work without a FQDN and with a non-empty cookie domain. Either use a fully qualified domain name like "http://www.example.com" instead of "http://example" only, or set the cookie domain in the Horde configuration to an empty value, or enable non-cookie (url-based) sessions in the Horde configuration.', __FILE__, __LINE__);
- }
- }
-
- session_set_cookie_params($conf['session']['timeout'],
- $conf['cookie']['path'], $conf['cookie']['domain'], $conf['use_ssl'] == 1 ? 1 : 0);
- session_cache_limiter(Horde_Util::nonInputVar('session_cache_limiter', $conf['session']['cache_limiter']));
- session_name(urlencode($conf['session']['name']));
-
- $type = !empty($conf['sessionhandler']['type']) ? $conf['sessionhandler']['type'] : 'none';
- if ($type == 'external') {
- $calls = $conf['sessionhandler']['params'];
- session_set_save_handler($calls['open'],
- $calls['close'],
- $calls['read'],
- $calls['write'],
- $calls['destroy'],
- $calls['gc']);
- } elseif ($type != 'none') {
- try {
- $sh = &Horde_SessionHandler::singleton($conf['sessionhandler']['type'], array_merge(self::getDriverConfig('sessionhandler', $conf['sessionhandler']['type']), array('memcache' => !empty($conf['sessionhandler']['memcache']))));
- ini_set('session.save_handler', 'user');
- session_set_save_handler(array(&$sh, 'open'),
- array(&$sh, 'close'),
- array(&$sh, 'read'),
- array(&$sh, 'write'),
- array(&$sh, 'destroy'),
- array(&$sh, 'gc'));
- $GLOBALS['horde_sessionhandler'] = $sh;
- } catch (Horde_Exception $e) {
- self::fatal(new Horde_Exception('Horde is unable to correctly start the custom session handler.'), __FILE__, __LINE__, false);
- }
- }
- }
-
- /**
* Returns an un-used access key from the label given.
*
* @param string $label The label to choose an access key from.
$f = array();
if ($GLOBALS['registry']->hasMethod('clients/getClientSource')) {
$addressbook = $GLOBALS['registry']->call('clients/getClientSource');
- $fields = $GLOBALS['registry']->call('clients/clientFields', array($addressbook));
- if ($fields instanceof PEAR_Error) {
- $fields = $GLOBALS['registry']->call('clients/fields', array($addressbook));
- }
- if (!$fields instanceof PEAR_Error) {
- foreach ($fields as $field) {
- $f[$field['name']] = $field['label'];
+ try {
+ $fields = $GLOBALS['registry']->call('clients/clientFields', array($addressbook));
+ } catch (Horde_Exception $e) {
+ try {
+ $fields = $GLOBALS['registry']->call('clients/fields', array($addressbook));
+ } catch (Horde_Exception $e) {
+ $fields = array();
}
}
+
+ foreach ($fields as $field) {
+ $f[$field['name']] = $field['label'];
+ }
}
return $f;
case 'list-contact-sources':
- $res = $GLOBALS['registry']->call('contacts/sources');
- return $res;
+ try {
+ return $GLOBALS['registry']->call('contacts/sources');
+ } catch (Horde_Exception $e) {}
+ break;
}
return array();
if (isset($conf['menu']['apps']) && is_array($conf['menu']['apps'])) {
foreach ($conf['menu']['apps'] as $app) {
if ($registry->get('status', $app) != 'inactive' && $registry->hasPermission($app, PERMS_SHOW)) {
- $url = $registry->getInitialPage($app);
- if (!is_a($url, 'PEAR_Error')) {
- $this->add(Horde::url($url), $registry->get('name', $app), $registry->get('icon', $app), '');
- }
+ try {
+ $this->add(Horde::url($registry->getInitialPage($app)), $registry->get('name', $app), $registry->get('icon', $app), '');
+ } catch (Horde_Exception $e) {}
}
}
}
* @param integer $session_flags Any session flags.
*
* @return Horde_Registry The Horde_Registry instance.
+ * @thros Horde_Exception
*/
static public function singleton($session_flags = 0)
{
SESSION_NONE. */
$_SESSION = array();
} else {
- Horde::setupSessionHandler();
+ $this->setupSessionHandler();
$old_error = error_reporting(0);
session_start();
if ($session_flags & self::SESSION_READONLY) {
session_write_close();
}
error_reporting($old_error);
-
- if (!isset($_SESSION['_registry'])) {
- $_SESSION['_registry'] = array();
- }
}
/* Initialize the localization routines and variables. We can't use
}
/* Create the global Perms object. */
+ // TODO: Remove(?)
$GLOBALS['perms'] = Perms::singleton();
-
- /* Attach javascript notification listener. */
- $notification = Horde_Notification::singleton();
- $notification->attach('javascript');
}
/**
/* Read the registry configuration files. */
require HORDE_BASE . '/config/registry.php';
$files = glob(HORDE_BASE . '/config/registry.d/*.php');
- if ($files) {
- foreach ($files as $r) {
- include $r;
- }
+ foreach ($files as $r) {
+ include $r;
}
if ($vhost) {
* @param string $method The method to call.
* @param array $args Arguments to the method.
*
- * @return TODO
- * Returns PEAR_Error on error.
+ * @return mixed TODO
+ * @throws Horde_Exception
*/
public function call($method, $args = array())
{
} elseif (!empty($this->_cache['interfaces'][$interface])) {
$app = $this->_cache['interfaces'][$interface];
} else {
- return PEAR::raiseError('The method "' . $method . '" is not defined in the Horde Registry.');
+ throw new Horde_Exception('The method "' . $method . '" is not defined in the Horde Registry.');
}
return $this->callByPackage($app, $call, $args);
* @param string $call The method to call.
* @param array $args Arguments to the method.
*
- * @return TODO
- * Returns PEAR_Error on error.
+ * @return mixed TODO
+ * @throws Horde_Exception
*/
public function callByPackage($app, $call, $args = array())
{
* $app's services and included the API file, so we don't try
* to do it again explicitly in this method. */
if (!$this->hasMethod($call, $app)) {
- return PEAR::raiseError(sprintf('The method "%s" is not defined in the API for %s.', $call, $app));
+ throw new Horde_Exception(sprintf('The method "%s" is not defined in the API for %s.', $call, $app));
}
/* Load the API now. */
/* Make sure that the function actually exists. */
$function = '_' . $app . '_' . str_replace('/', '_', $call);
if (!function_exists($function)) {
- return PEAR::raiseError('The function implementing ' . $call . ' (' . $function . ') is not defined in ' . $app . '\'s API.');
+ throw new Horde_Exception('The function implementing ' . $call . ' (' . $function . ') is not defined in ' . $app . '\'s API.');
}
$checkPerms = isset($this->_cache['api'][$app][$call]['checkperms'])
* including any files which might do it for us. Return an
* error immediately if pushApp() fails. */
$pushed = $this->pushApp($app, $checkPerms);
- if (is_a($pushed, 'PEAR_Error')) {
- return $pushed;
- }
$res = call_user_func_array($function, $args);
* @param array $args Arguments to the method.
* @param mixed $extra Extra, non-standard arguments to the method.
*
- * @return TODO
- * Returns PEAR_Error on error.
+ * @return mixed TODO
+ * @throws Horde_Exception
*/
public function link($method, $args = array(), $extra = '')
{
} elseif (!empty($this->_cache['interfaces'][$interface])) {
$app = $this->_cache['interfaces'][$interface];
} else {
- return PEAR::raiseError('The method "' . $method . '" is not defined in the Horde Registry.');
+ throw new Horde_Exception('The method "' . $method . '" is not defined in the Horde Registry.');
}
return $this->linkByPackage($app, $call, $args, $extra);
* @param array $args Arguments to the method.
* @param mixed $extra Extra, non-standard arguments to the method.
*
- * @return TODO
- * Returns PEAR_Error on error.
+ * @return mixed TODO
+ * @throws Horde_Exception
*/
public function linkByPackage($app, $call, $args = array(), $extra = '')
{
* services and included the API file, so we don't try to do
* it it again explicitly in this method. */
if (!$this->hasMethod($call, $app)) {
- return PEAR::raiseError('The method "' . $call . '" is not defined in ' . $app . '\'s API.');
+ throw new Horde_Exception('The method "' . $call . '" is not defined in ' . $app . '\'s API.');
}
/* Make sure the link is defined. */
$this->_loadApiCache();
if (empty($this->_cache['api'][$app][$call]['link'])) {
- return PEAR::raiseError('The link ' . $call . ' is not defined in ' . $app . '\'s API.');
+ throw new Horde_Exception('The link ' . $call . ' is not defined in ' . $app . '\'s API.');
}
/* Initial link value. */
* @param string $path The application string.
* @param string $app The application being called.
*
- * @return TODO
- * Returns PEAR_Error on error.
+ * @return string The application file path.
+ * @throws Horde_Exception
*/
public function applicationFilePath($path, $app = null)
{
}
if (!isset($this->applications[$app])) {
- return PEAR::raiseError(sprintf(_("\"%s\" is not configured in the Horde Registry."), $app));
+ throw new Horde_Exception(sprintf(_("\"%s\" is not configured in the Horde Registry."), $app));
}
return str_replace('%application%', $this->applications[$app]['fileroot'], $path);
* @param string $path The application string.
* @param string $app The application being called.
*
- * @return TODO
- * Returns PEAR_Error on error.
+ * @return string The application web path.
*/
public function applicationWebPath($path, $app = null)
{
* - To anyone who is allowed by an explicit ACL on $app. */
if ($checkPerms && !$this->hasPermission($app)) {
Horde::logMessage(sprintf('%s does not have READ permission for %s', Horde_Auth::getAuth() ? 'User ' . Horde_Auth::getAuth() : 'Guest user', $app), __FILE__, __LINE__, PEAR_LOG_DEBUG);
- return PEAR::raiseError(sprintf(_('%s is not authorised for %s.'), Horde_Auth::getAuth() ? 'User ' . Horde_Auth::getAuth() : 'Guest user', $this->applications[$app]['name']), 'permission_denied');
+ throw new Horde_Exception(sprintf(_('%s is not authorised for %s.'), Horde_Auth::getAuth() ? 'User ' . Horde_Auth::getAuth() : 'Guest user', $this->applications[$app]['name']), 'permission_denied');
}
/* Set up autoload paths for the current application. This needs to
* them into the global $conf variable.
*
* @param string $app The name of the application.
- *
- * @throws Horde_Exception
*/
public function importConfig($app)
{
if (!Horde_Auth::getAuth()) {
$GLOBALS['prefs'] = Prefs::factory('session', $app, '', '', null, false);
} else {
- if (!isset($GLOBALS['prefs']) || $GLOBALS['prefs']->getUser() != Horde_Auth::getAuth()) {
- $GLOBALS['prefs'] = Prefs::factory($GLOBALS['conf']['prefs']['driver'], $app,
- Horde_Auth::getAuth(), Horde_Auth::getCredential('password'));
+ if (!isset($GLOBALS['prefs']) ||
+ ($GLOBALS['prefs']->getUser() != Horde_Auth::getAuth())) {
+ $GLOBALS['prefs'] = Prefs::factory($GLOBALS['conf']['prefs']['driver'], $app, Horde_Auth::getAuth(), Horde_Auth::getCredential('password'));
} else {
$GLOBALS['prefs']->retrieve($app);
}
* @param string $app The name of the application.
*
* @return string URL pointing to the inital page of the application.
- * Returns PEAR_Error on error.
+ * @throws Horde_Exception
*/
public function getInitialPage($app = null)
{
$app = $this->getApp();
}
- return isset($this->applications[$app])
- ? $this->applications[$app]['webroot'] . '/' . (isset($this->applications[$app]['initial_page']) ? $this->applications[$app]['initial_page'] : '')
- : PEAR::raiseError(sprintf(_("\"%s\" is not configured in the Horde Registry."), $app));
+ if (isset($this->applications[$app])) {
+ return $this->applications[$app]['webroot'] . '/' . (isset($this->applications[$app]['initial_page']) ? $this->applications[$app]['initial_page'] : '');
+ }
+
+ throw new Horde_Exception(sprintf(_("\"%s\" is not configured in the Horde Registry."), $app));
}
/**
return $id;
} elseif (isset($_SESSION['_registry']['md5'][$name])) {
return $id . '|' . $_SESSION['_registry']['md5'][$name];
- } else {
- return false;
+ }
+
+ return false;
+ }
+
+ /**
+ * Sets a custom session handler up, if there is one.
+ * If the global variable 'session_cache_limiter' is defined, its value
+ * will override the cache limiter setting found in the configuration
+ * file.
+ *
+ * The custom session handler object will be contained in the global
+ * 'horde_sessionhandler' variable.
+ */
+ public function setupSessionHandler()
+ {
+ global $conf;
+
+ ini_set('url_rewriter.tags', 0);
+ if (!empty($conf['session']['use_only_cookies'])) {
+ ini_set('session.use_only_cookies', 1);
+ if (!empty($conf['cookie']['domain']) &&
+ strpos($conf['server']['name'], '.') === false) {
+ Horde::fatal('Session cookies will not work without a FQDN and with a non-empty cookie domain. Either use a fully qualified domain name like "http://www.example.com" instead of "http://example" only, or set the cookie domain in the Horde configuration to an empty value, or enable non-cookie (url-based) sessions in the Horde configuration.', __FILE__, __LINE__);
+ }
+ }
+
+ session_set_cookie_params($conf['session']['timeout'],
+ $conf['cookie']['path'], $conf['cookie']['domain'], $conf['use_ssl'] == 1 ? 1 : 0);
+ session_cache_limiter(Horde_Util::nonInputVar('session_cache_limiter', $conf['session']['cache_limiter']));
+ session_name(urlencode($conf['session']['name']));
+
+ $type = empty($conf['sessionhandler']['type'])
+ ? 'none'
+ : $conf['sessionhandler']['type'];
+
+ if ($type == 'external') {
+ $calls = $conf['sessionhandler']['params'];
+ session_set_save_handler($calls['open'],
+ $calls['close'],
+ $calls['read'],
+ $calls['write'],
+ $calls['destroy'],
+ $calls['gc']);
+ } elseif ($type != 'none') {
+ try {
+ $sh = Horde_SessionHandler::singleton($conf['sessionhandler']['type'], array_merge(Horde::getDriverConfig('sessionhandler', $conf['sessionhandler']['type']), array('memcache' => !empty($conf['sessionhandler']['memcache']))));
+ ini_set('session.save_handler', 'user');
+ session_set_save_handler(array(&$sh, 'open'),
+ array(&$sh, 'close'),
+ array(&$sh, 'read'),
+ array(&$sh, 'write'),
+ array(&$sh, 'destroy'),
+ array(&$sh, 'gc'));
+ $GLOBALS['horde_sessionhandler'] = $sh;
+ } catch (Horde_Exception $e) {
+ Horde::fatal(new Horde_Exception('Horde is unable to correctly start the custom session handler.'), __FILE__, __LINE__, false);
+ }
+ }
+ }
+
+ /**
+ * Destroys any existing session on login and make sure to use a new
+ * session ID, to avoid session fixation issues. Should be called before
+ * checking a login.
+ */
+ public function getCleanSession()
+ {
+ // Make sure to force a completely new session ID and clear all
+ // session data.
+ session_regenerate_id(true);
+ session_unset();
+
+ /* Reset cookie timeouts, if necessary. */
+ if (!empty($GLOBALS['conf']['session']['timeout'])) {
+ $app = $this->getApp();
+ if (Horde_Secret::clearKey($app)) {
+ Horde_Secret::setKey($app);
+ }
+ Horde_Secret::setKey('auth');
}
}
/**
* TODO
+ *
+ * @throws Horde_Exception
*/
public function __call($method, $args)
{
$source = Horde_Util::getFormData('source');
$count = 0;
foreach ($iCal->getComponents() as $c) {
- if (is_a($c, 'Horde_iCalendar_vcard')) {
- $contacts = $registry->call('contacts/import',
- array($c, null, $source));
- if (is_a($contacts, 'PEAR_Error')) {
- $notification->push(
- _("There was an error importing the contact data:") . ' '
- . $contacts->getMessage(),
- 'horde.error');
- continue;
+ if ($c instanceof Horde_iCalendar_vcard) {
+ try {
+ $contacts = $registry->call('contacts/import', array($c, null, $source));
+ ++$count;
+ } catch (Horde_Exception $e) {
+ $notification->push(_("There was an error importing the contact data:") . ' ' . $e->getMessage(), 'horde.error');
}
- $count++;
}
}
$notification->push(sprintf(ngettext(
}
// Call the method.
- $result = $GLOBALS['registry']->call($method, $params);
- if (is_a($result, 'PEAR_Error')) {
- return $this->_raiseError($result, $request);
+ try {
+ $result = $GLOBALS['registry']->call($method, $params);
+ } catch (Horde_Exception $e) {
+ return $this->_raiseError($e, $request);
}
// Return result.
$content .= fgets($options['stream']);
}
- $result = $GLOBALS['registry']->callByPackage($pieces[0], 'put', array('path' => $path, 'content' => $content, 'type' => $options['content_type']));
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- if ($result->getCode()) {
- return $this->_checkHTTPCode($result->getCode())
- . ' ' . $result->getMessage();
- } else {
- return '500 Internal Server Error. Check server logs';
+ try {
+ $GLOBALS['registry']->callByPackage($pieces[0], 'put', array('path' => $path, 'content' => $content, 'type' => $options['content_type']));
+ } catch (Horde_Exception $e) {
+ Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
+ if ($e->getCode()) {
+ return $this->_checkHTTPCode($e->getCode()) . ' ' . $result->getMessage();
}
+
+ return '500 Internal Server Error. Check server logs';
}
return true;
$path = $options['path'];
$pieces = explode('/', trim($this->path, '/'), 2);
- if (count($pieces) == 2) {
- $app = $pieces[0];
- $path = $pieces[1];
+ if (count($pieces) != 2) {
+ Horde::logMessage(sprintf(_("Error deleting from path %s; must be [app]/[path]", $options['path'])), __FILE__, __LINE__, PEAR_LOG_INFO);
+ return '403 Must supply a resource within the application to delete.';
+ }
- // TODO: Support HTTP/1.1 If-Match on ETag here
+ $app = $pieces[0];
+ $path = $pieces[1];
- // Delete access is checked in each app.
- $result = $GLOBALS['registry']->callByPackage($app, 'path_delete', array($path));
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_INFO);
- if ($result->getCode()) {
- return $this->_checkHTTPCode($result->getCode())
- . ' ' . $result->getMessage();
- } else {
- return '500 Internal Server Error. Check server logs';
- }
+ // TODO: Support HTTP/1.1 If-Match on ETag here
+
+ // Delete access is checked in each app.
+ try {
+ $GLOBALS['registry']->callByPackage($app, 'path_delete', array($path));
+ } catch (Horde_Exception $e) {
+ Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_INFO);
+ if ($e->getCode()) {
+ return $this->_checkHTTPCode($e->getCode()) . ' ' . $e->getMessage();
}
- return '204 No Content';
- } else {
- Horde::logMessage(sprintf(_("Error deleting from path %s; must be [app]/[path]", $options['path'])), __FILE__, __LINE__, PEAR_LOG_INFO);
- return '403 Must supply a resource within the application to delete.';
+
+ return '500 Internal Server Error. Check server logs';
}
+
+ return '204 No Content';
}
/**
// Take the module name from the path
$pieces = explode('/', $path, 2);
- if (count($pieces) == 2) {
- // Send the request to the application
- $result = $GLOBALS['registry']->callByPackage($pieces[0], 'mkcol', array('path' => $path));
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- if ($result->getCode()) {
- return $this->_checkHTTPCode($result->getCode())
- . ' ' . $result->getMessage();
- } else {
- return '500 Internal Server Error. Check server logs';
- }
- }
- } else {
+ if (count($pieces) != 2) {
Horde::logMessage(sprintf(_("Unable to create directory %s; must be [app]/[path]"), $path), __FILE__, __LINE__, PEAR_LOG_INFO);
return '403 Must specify a resource within an application. MKCOL disallowed at top level.';
}
+ // Send the request to the application
+ try {
+ $GLOBALS['registry']->callByPackage($pieces[0], 'mkcol', array('path' => $path));
+ } catch (Horde_Exception $e) {
+ Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+ if ($e->getCode()) {
+ return $this->_checkHTTPCode($e->getCode()) . ' ' . $e->getMessage();
+ }
+
+ return '500 Internal Server Error. Check server logs';
+ }
+
return '200 OK';
}
// Take the module name from the path
$sourcePieces = explode('/', $path, 2);
- if (count($sourcePieces) == 2) {
- $destPieces = explode('/', $options['dest'], 2);
- if (!(count($destPieces) == 2) || $sourcesPieces[0] != $destPieces[0]) {
- return '400 Can not move across applications.';
- }
- // Send the request to the module
- $result = $GLOBALS['registry']->callByPackage($sourcePieces[0], 'move', array('path' => $path, 'dest' => $options['dest']));
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- if ($result->getCode()) {
- return $this->_checkHTTPCode($result->getCode())
- . ' ' . $result->getMessage();
- } else {
- return '500 Internal Server Error. Check server logs';
- }
- }
- } else {
+ if (count($sourcePieces) != 2) {
Horde::logMessage(sprintf(_("Unable to rename %s; must be [app]/[path] and within the same application."), $path), __FILE__, __LINE__, PEAR_LOG_INFO);
return '403 Must specify a resource within an application. MOVE disallowed at top level.';
}
+ $destPieces = explode('/', $options['dest'], 2);
+ if (!(count($destPieces) == 2) || $sourcesPieces[0] != $destPieces[0]) {
+ return '400 Can not move across applications.';
+ }
+
+ // Send the request to the module
+ try {
+ $GLOBALS['registry']->callByPackage($sourcePieces[0], 'move', array('path' => $path, 'dest' => $options['dest']));
+ } catch (Horde_Exception $e) {
+ Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
+ if ($e->getCode()) {
+ return $this->_checkHTTPCode($e->getCode()) . ' ' . $e->getMessage();
+ }
+
+ return '500 Internal Server Error. Check server logs';
+ }
+
return '200 OK';
}
// Make sure the applications each only return one level
$options['depth'] = 0;
}
- $results = $registry->callByPackage($app, 'browse', array('path' => '/', 'depth' => $options['depth']));
+
+ try {
+ $results = $registry->callByPackage($app, 'browse', array('path' => '/', 'depth' => $options['depth']));
+ } catch (Horde_Exception $e) {
+ continue;
+ }
+
$options['depth'] = $origdepth;
foreach ($results as $itemPath => $item) {
}
}
}
-Horde::logMessage(print_r($list, true), __FILE__, __LINE__, PEAR_LOG_ERR);
return $list;
} else {
$path = trim($path, '/');
$pieces = explode('/', $path);
- $items = $registry->callByPackage($pieces[0], 'browse', array('path' => $path, 'depth' => $options['depth']));
+
+ try {
+ $items = $registry->callByPackage($pieces[0], 'browse', array('path' => $path, 'depth' => $options['depth']));
+ } catch (Horde_Exception $e) {
+ Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
+ return $e;
+ }
+
if ($items === false) {
// File not found
return $items;
}
- if (is_a($items, 'PEAR_Error')) {
- Horde::logMessage($items, __FILE__, __LINE__, PEAR_LOG_ERR);
- return $items;
- }
if (empty($items)) {
// No content exists at this level.
return array();
return 'Method "' . $method . '" is not defined';
}
- $result = $registry->call($method, $params);
- if (is_a($result, 'PEAR_Error')) {
- $result = array('faultCode' => (int)$result->getCode(),
- 'faultString' => $result->getMessage());
+ try {
+ $result = $registry->call($method, $params);
+ } catch (Horde_Exception $e) {
+ $result = array('faultCode' => (int)$e->getCode(),
+ 'faultString' => $e->getMessage());
}
return $result;
}
parse_str($args, $extra);
- $url = $GLOBALS['registry']->call('mail/compose',
- array(array('to' => $email),
- $extra));
- if (is_a($url, 'PEAR_Error')) {
+ try {
+ $url = $GLOBALS['registry']->call('mail/compose',
+ array(array('to' => $email),
+ $extra));
+ } catch (Horde_Exception $e) {
$url = 'mailto:' . urlencode($email);
}