$hasError = false;
/* Get the share object for later deletion */
- $share = $GLOBALS['mnemo_shares']->getShare($user);
- if (is_a($share, 'PEAR_Error')) {
- Horde::logMessage($share->getMessage(), 'ERR');
- unset($share);
+ try {
+ $share = $GLOBALS['mnemo_shares']->getShare($user);
+ } catch (Horde_Share_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
+ }
+ $GLOBALS['display_notepads'] = array($user);
+ $memos = Mnemo::listMemos();
+ if ($memos instanceof PEAR_Error) {
+ $hasError = true;
+ Horde::logMessage($mnemos->getMessage(), 'ERR');
} else {
- $GLOBALS['display_notepads'] = array($user);
- $memos = Mnemo::listMemos();
- if (is_a($memos, 'PEAR_Error')) {
- $hasError = true;
- Horde::logMessage($mnemos->getMessage(), 'ERR');
- } else {
- $uids = array();
- foreach ($memos as $memo) {
- $uids[] = $memo['uid'];
- }
+ $uids = array();
+ foreach ($memos as $memo) {
+ $uids[] = $memo['uid'];
+ }
- /* ... and delete them. */
- foreach ($uids as $uid) {
- _mnemo_delete($uid);
- }
+ /* ... and delete them. */
+ foreach ($uids as $uid) {
+ _mnemo_delete($uid);
}
+ }
- /* Remove the share itself */
- if (!empty($share)) {
- $result = $GLOBALS['mnemo_shares']->removeShare($share);
- if (is_a($result, 'PEAR_Error')) {
- $hasError = true;
- Horde::logMessage($result->getMessage(), 'ERR');
- }
+ /* Remove the share itself */
+ if (!empty($share)) {
+ try {
+ $GLOBALS['mnemo_shares']->removeShare($share);
+ } catch (Horde_Share_Exception $e) {
+ $hasError = true;
+ Horde::logMessage($e->getMessage(), 'ERR');
}
+ }
- /* Get a list of all shares this user has perms to and remove the perms */
+ /* Get a list of all shares this user has perms to and remove the perms */
+ try {
$shares = $GLOBALS['mnemo_shares']->listShares($user);
- if (is_a($shares, 'PEAR_Error')) {
- $hasError = true;
- Horde::logMessage($shares, 'ERR');
- } else {
- foreach ($shares as $share) {
- $share->removeUser($user);
- }
+ foreach ($shares as $share) {
+ $share->removeUser($user);
}
+ } catch (Horde_Share_Exception $e) {
+ $hasError = true;
+ Horde::logMessage($e, 'ERR');
}
+
if ($hasError) {
return PEAR::raiseError(sprintf(_("There was an error removing notes for %s. Details have been logged."), $user));
} else {
if (!empty($this->_params['show_notepad'])) {
$owner = $memo['memolist_id'];
- $share = &$shares->getShare($owner);
- if (!is_a($share, 'PEAR_Error')) {
- $owner = $share->get('name');
- }
+ $share = $shares->getShare($owner);
+ $owner = $share->get('name');
$html .= '<td>' . htmlspecialchars($owner) . '</td>';
}
--- /dev/null
+<?php
+/**
+ * Base exception class for Mnemo.
+ *
+ * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file LICENSE for license information (ASL). If you
+ * did not receive this file, see http://www.horde.org/licenses/asl.php.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Mnemo
+ */
+class Mnemo_Exception extends Horde_Exception_Prior
+{
+}
function execute()
{
// Create new share.
- $notepad = $GLOBALS['mnemo_shares']->newShare(md5(microtime()));
- if (is_a($notepad, 'PEAR_Error')) {
- return $notepad;
+ try {
+ $notepad = $GLOBALS['mnemo_shares']->newShare(md5(microtime()));
+ } catch (Horde_Share_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
+ throw new Mnemo_Exception($e);
}
$notepad->set('name', $this->_vars->get('name'));
$notepad->set('desc', $this->_vars->get('description'));
return PEAR::raiseError(sprintf(_("Unable to delete \"%s\": %s"), $this->_notepad->get('name'), $result->getMessage()));
} else {
// Remove share and all groups/permissions.
- $result = $GLOBALS['mnemo_shares']->removeShare($this->_notepad);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
+ try {
+ $GLOBALS['mnemo_shares']->removeShare($this->_notepad);
+ } catch (Horde_Share_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
+ return;
}
}
if (count(Mnemo::listNotepads(true)) == 0) {
// If the default share doesn't exist then create it.
if (!$GLOBALS['mnemo_shares']->exists(Horde_Auth::getAuth())) {
- require_once 'Horde/Identity.php';
- $identity = &Identity::singleton();
+
+ $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getIdentity();
$name = $identity->getValue('fullname');
if (trim($name) == '') {
$name = Horde_Auth::getAuth();
}
- $notepad = &$GLOBALS['mnemo_shares']->newShare(Horde_Auth::getAuth());
- if (is_a($notepad, 'PEAR_Error')) {
+ try {
+ $notepad = $GLOBALS['mnemo_shares']->newShare(Horde_Auth::getAuth());
+ } catch (Horde_Share_Exception $e) {
return;
}
$notepad->set('name', sprintf(_("%s's Notepad"), $name));
if ($owneronly && !Horde_Auth::getAuth()) {
return array();
}
- $notepads = $GLOBALS['mnemo_shares']->listShares(Horde_Auth::getAuth(), $permission, $owneronly ? Horde_Auth::getAuth() : null, 0, 0, 'name');
- if (is_a($notepads, 'PEAR_Error')) {
- Horde::logMessage($notepads, 'ERR');
+ try {
+ $notepads = $GLOBALS['mnemo_shares']->listShares(Horde_Auth::getAuth(), $permission, $owneronly ? Horde_Auth::getAuth() : null, 0, 0, 'name');
+ } catch (Horde_Share_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
return array();
}
$ashare = $GLOBALS['mnemo_shares']->getShare($aowner);
$bshare = $GLOBALS['mnemo_shares']->getShare($bowner);
- if (!is_a($ashare, 'PEAR_Error') && $aowner != $ashare->get('owner')) {
+ if ($aowner != $ashare->get('owner')) {
$aowner = $ashare->get('name');
}
- if (!is_a($bshare, 'PEAR_Error') && $bowner != $bshare->get('owner')) {
+ if ($bowner != $bshare->get('owner')) {
$bowner = $bshare->get('name');
}
$ashare = $GLOBALS['mnemo_shares']->getShare($aowner);
$bshare = $GLOBALS['mnemo_shares']->getShare($bowner);
- if (!is_a($ashare, 'PEAR_Error') && $aowner != $ashare->get('owner')) {
+ if ($aowner != $ashare->get('owner')) {
$aowner = $ashare->get('name');
}
- if (!is_a($bshare, 'PEAR_Error') && $bowner != $bshare->get('owner')) {
+ if ($bowner != $bshare->get('owner')) {
$bowner = $bshare->get('name');
}
$memourl = Horde_Util::addParameter(
'memo.php', array('memo' => $memo['memo_id'],
'memolist' => $memo['memolist_id']));
- $share = $GLOBALS['mnemo_shares']->getShare($memo['memolist_id']);
-
- $notepad = $memo['memolist_id'];
- if (!is_a($share, 'PEAR_Error')) {
+ try {
+ $share = $GLOBALS['mnemo_shares']->getShare($memo['memolist_id']);
$notepad = $share->get('name');
+ } catch (Horde_Share_Exception $e) {
+ $notepad = $memo['memolist_id'];
}
require MNEMO_TEMPLATES . '/list/memo_summaries.inc';
{
global $notification;
- if (!is_a($memo['body'], 'PEAR_Error')) {
+ if (!($memo['body'] instanceof PEAR_Error)) {
return false;
}
if (empty($memolist_id)) {
$memolist_id = Mnemo::getDefaultNotepad();
}
- if (is_a($memolist_id, 'PEAR_Error')) {
+ if ($memolist_id instanceof PEAR_Error) {
$notification->push($memolist_id, 'horde.error');
}
$memo_id = null;
$memo_passphrase = Horde_Util::getFormData('memo_passphrase');
$memo_passphrase2 = Horde_Util::getFormData('memo_passphrase2');
- $share = $GLOBALS['mnemo_shares']->getShare($notepad_target);
- if (is_a($share, 'PEAR_Error')) {
- $notification->push(sprintf(_("Access denied saving note: %s"), $share->getMessage()), 'horde.error');
- } elseif (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+ try {
+ $share = $GLOBALS['mnemo_shares']->getShare($notepad_target);
+ } catch (Horde_Share_Exception $e) {
+ throw new Mnemo_Exception($e);
+ }
+
+ if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
$notification->push(sprintf(_("Access denied saving note to %s."), $share->get('name')), 'horde.error');
} elseif ($memo_passphrase != $memo_passphrase2) {
$notification->push(_("The passwords don't match."), 'horde.error');
/* If $memo_id is set, we're modifying an existing note. Otherwise,
* we're adding a new note with the provided attributes. */
if (!empty($memo_id) &&
- !is_a(Mnemo::getMemo($memolist_original, $memo_id), 'PEAR_Error')) {
+ !(Mnemo::getMemo($memolist_original, $memo_id) instanceof PEAR_Error)) {
$storage = &Mnemo_Driver::singleton($memolist_original);
if ($memolist_original != $notepad_target) {
/* Moving the note to another notepad. */
- $share = &$GLOBALS['mnemo_shares']->getShare($memolist_original);
- if (!is_a($share, 'PEAR_Error') &&
- $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
- $share = &$GLOBALS['mnemo_shares']->getShare($notepad_target);
- if (!is_a($share, 'PEAR_Error') &&
- $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+ try {
+ $share = $GLOBALS['mnemo_shares']->getShare($memolist_original);
+ } catch (Horde_Share_Exception $e) {
+ throw new Mnemo_Exception($e);
+ }
+ if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
+ try {
+ $share = &$GLOBALS['mnemo_shares']->getShare($notepad_target);
+ } catch (Horde_Share_Exception $e) {
+ throw new Mnemo_Exception($e);
+ }
+ if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
$result = $storage->move($memo_id, $notepad_target);
$storage = &Mnemo_Driver::singleton($notepad_target);
} else {
}
/* Check our results. */
- if (is_a($result, 'PEAR_Error')) {
+ if ($result instanceof PEAR_Error) {
$notification->push(sprintf(_("There was an error saving the note: %s"), $result->getMessage()), 'horde.warning');
} else {
$notification->push(sprintf(_("Successfully saved \"%s\"."), $memo_desc), 'horde.success');
$memolist_id = Horde_Util::getFormData('memolist');
if (!is_null($memo_id) && Mnemo::getMemo($memolist_id, $memo_id)) {
- $share = &$GLOBALS['mnemo_shares']->getShare($memolist_id);
- if (!is_a($share, 'PEAR_Error') &&
- $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
+ try {
+ $share = $GLOBALS['mnemo_shares']->getShare($memolist_id);
+ } catch (Horde_Share_Exception $e) {
+ throw new Mnemo_Exception($e);
+ }
+ if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
$storage = &Mnemo_Driver::singleton($memolist_id);
$result = $storage->delete($memo_id);
-
- if (is_a($result, 'PEAR_Error')) {
+ if ($result instanceof PEAR_Error) {
$notification->push(sprintf(_("There was an error removing the note: %s"), $result->getMessage()), 'horde.warning');
} else {
$notification->push(_("The note was deleted."), 'horde.success');
$storage = &Mnemo_Driver::singleton();
if ($uid = Horde_Util::getFormData('uid')) {
$note = $storage->getByUID($uid, $passphrase);
- if (is_a($note, 'PEAR_Error')) {
+ if ($note instanceof PEAR_Error) {
header('Location: ' . Horde::applicationUrl('list.php', true));
exit;
}
/* Get the current memo. */
$note = Mnemo::getMemo($notelist_id, $note_id, $passphrase);
}
-
-$share = &$GLOBALS['mnemo_shares']->getShare($notelist_id);
-if (is_a($share, 'PEAR_Error')) {
- $notification->push(sprintf(_("There was an error viewing this notepad: %s"), $share->getMessage()), 'horde.error');
+try {
+ $share = $GLOBALS['mnemo_shares']->getShare($notelist_id);
+} catch (Horde_Share_Exception $e) {
+ $notification->push(sprintf(_("There was an error viewing this notepad: %s"), $e->getMessage()), 'horde.error');
header('Location: ' . Horde::applicationUrl('list.php', true));
exit;
-} elseif (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
+}
+if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
$notification->push(sprintf(_("You do not have permission to view the notepad %s."), $share->get('name')), 'horde.error');
header('Location: ' . Horde::applicationUrl('list.php', true));
exit;
header('Location: ' . Horde::applicationUrl('notepads/', true));
exit;
}
-
-$notepad = $mnemo_shares->getShare($notepad_id);
-if (is_a($notepad, 'PEAR_Error')) {
- $notification->push($notepad, 'horde.error');
+try {
+ $notepad = $mnemo_shares->getShare($notepad_id);
+} catch (Horde_Share_Exception $e) {
+ $notification->push($e->getMessage(), 'horde.error');
header('Location: ' . Horde::applicationUrl('notepads/', true));
exit;
-} elseif (!Horde_Auth::getAuth() ||
- $notepad->get('owner') != Horde_Auth::getAuth()) {
+}
+if (!Horde_Auth::getAuth() || $notepad->get('owner') != Horde_Auth::getAuth()) {
$notification->push(_("You are not allowed to delete this notepad."), 'horde.error');
header('Location: ' . Horde::applicationUrl('notepads/', true));
exit;
// Execute if the form is valid (must pass with POST variables only).
if ($form->validate(new Horde_Variables($_POST))) {
$result = $form->execute();
- if (is_a($result, 'PEAR_Error')) {
+ if ($result instanceof PEAR_Error) {
$notification->push($result, 'horde.error');
} elseif ($result) {
$notification->push(sprintf(_("The notepad \"%s\" has been deleted."), $notepad->get('name')), 'horde.success');
}
$vars = Horde_Variables::getDefaultVariables();
-$notepad = $mnemo_shares->getShare($vars->get('n'));
-if (is_a($notepad, 'PEAR_Error')) {
- $notification->push($notepad, 'horde.error');
+try {
+ $notepad = $mnemo_shares->getShare($vars->get('n'));
+} catch (Horde_Share_Exception $e) {
+ $notification->push($e->getMessage(), 'horde.error');
header('Location: ' . Horde::applicationUrl('notepads/', true));
exit;
-} elseif (!Horde_Auth::getAuth() ||
- $notepad->get('owner') != Horde_Auth::getAuth()) {
+}
+if (!Horde_Auth::getAuth() ||
+ $notepad->get('owner') != Horde_Auth::getAuth()) {
+
$notification->push(_("You are not allowed to change this notepad."), 'horde.error');
header('Location: ' . Horde::applicationUrl('notepads/', true));
exit;
$memourl = Horde_Util::addParameter(
'memo.php', array('memo' => $memo['memo_id'],
'memolist' => $memo['memolist_id']));
- $share = &$GLOBALS['mnemo_shares']->getShare($memo['memolist_id']);
-
- $notepad = $memo['memolist_id'];
- if (!is_a($share, 'PEAR_Error')) {
+ try {
+ $share = $GLOBALS['mnemo_shares']->getShare($memo['memolist_id']);
$notepad = $share->get('name');
+ } catch (Horde_Share_Exception $e) {
+ $notepad = $memo['memolist_id'];
}
require MNEMO_TEMPLATES . '/list/memo_summaries.inc';
<tr>
<td>
<?php
-if (!is_a($share, 'PEAR_Error') && $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
$label = sprintf(_("Edit \"%s\""), $memo['desc']);
echo Horde::link(Horde::applicationUrl(Horde_Util::addParameter($memourl, 'actionID', 'modify_memo')), $label) .
Horde::img('edit.png', $label, '') . '</a>';
$memourl = Horde_Util::addParameter('memo.php', array('memo' => $memo_id,
'memolist' => $memolist_id));
- $share = &$GLOBALS['mnemo_shares']->getShare($memolist_id);
- if (!is_a($share, 'PEAR_Error') && $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)): ?>
+ $share = $GLOBALS['mnemo_shares']->getShare($memolist_id);
+ if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)): ?>
<span class="rightFloat"><input type="button" class="button" value="<?php echo _("Delete this note") ?>" onclick="window.location='<?php echo addslashes(Horde::applicationUrl(Horde_Util::addParameter($memourl, 'actionID', 'delete_memos'))) ?>';" /></span>
<?php endif; endif; ?>
$memourl = Horde_Util::addParameter('memo.php', array('memo' => $memo_id,
'memolist' => $memolist_id));
-$share = &$GLOBALS['mnemo_shares']->getShare($memolist_id);
+$share = $GLOBALS['mnemo_shares']->getShare($memolist_id);
?>
<div class="header">
<div class="rightFloat">
/* Get the current memo. */
$memo = Mnemo::getMemo($memolist_id, $memo_id, $passphrase);
}
-
-$share = $GLOBALS['mnemo_shares']->getShare($memolist_id);
-if (is_a($share, 'PEAR_Error')) {
- $notification->push(sprintf(_("There was an error viewing this notepad: %s"), $share->getMessage()), 'horde.error');
+try {
+ $share = $GLOBALS['mnemo_shares']->getShare($memolist_id);
+} catch (Horde_Share_Exception $e) {
+ $notification->push(sprintf(_("There was an error viewing this notepad: %s"), $e->getMessage()), 'horde.error');
header('Location: ' . Horde::applicationUrl('list.php', true));
exit;
-} elseif (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
+}
+if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
$notification->push(sprintf(_("You do not have permission to view the notepad %s."), $share->get('name')), 'horde.error');
header('Location: ' . Horde::applicationUrl('list.php', true));
exit;