Track Horde_Share changes.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 19 May 2010 22:42:20 +0000 (18:42 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 19 May 2010 22:42:20 +0000 (18:42 -0400)
Still *alot* of H3 cruft in Mnemo...got some of it as I saw it while
going through for share changes, but still a lot to do.

16 files changed:
mnemo/lib/Api.php
mnemo/lib/Block/summary.php
mnemo/lib/Exception.php [new file with mode: 0644]
mnemo/lib/Forms/CreateNotepad.php
mnemo/lib/Forms/DeleteNotepad.php
mnemo/lib/Mnemo.php
mnemo/list.php
mnemo/memo.php
mnemo/note/pdf.php
mnemo/notepads/delete.php
mnemo/notepads/edit.php
mnemo/notes/index.php
mnemo/templates/list/memo_summaries.inc
mnemo/templates/memo/memo.inc
mnemo/templates/view/memo.inc
mnemo/view.php

index 25d14ae..b428f82 100644 (file)
@@ -35,49 +35,50 @@ class Mnemo_Api extends Horde_Registry_Api {
         $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 {
index 5d46cb2..f9fd7f7 100644 (file)
@@ -85,10 +85,8 @@ class Horde_Block_Mnemo_summary extends Horde_Block {
 
             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>';
             }
 
diff --git a/mnemo/lib/Exception.php b/mnemo/lib/Exception.php
new file mode 100644 (file)
index 0000000..dd5adcd
--- /dev/null
@@ -0,0 +1,15 @@
+<?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
+{
+}
index 4d24286..79e164b 100644 (file)
@@ -39,9 +39,11 @@ class Mnemo_CreateNotepadForm extends Horde_Form {
     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'));
index 8b98093..a2c8e80 100644 (file)
@@ -61,9 +61,11 @@ class Mnemo_DeleteNotepadForm extends Horde_Form {
             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;
             }
         }
 
@@ -71,14 +73,15 @@ class Mnemo_DeleteNotepadForm extends Horde_Form {
         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));
index 760aa83..e6abb03 100644 (file)
@@ -173,9 +173,10 @@ class Mnemo {
         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();
         }
 
@@ -301,10 +302,10 @@ class Mnemo {
         $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');
         }
 
@@ -328,10 +329,10 @@ class Mnemo {
         $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');
         }
 
index 7acda20..814636d 100644 (file)
@@ -91,11 +91,11 @@ if (count($memos)) {
         $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';
index e3e50b2..cbc49d9 100644 (file)
@@ -19,7 +19,7 @@ function showPassphrase($memo)
 {
     global $notification;
 
-    if (!is_a($memo['body'], 'PEAR_Error')) {
+    if (!($memo['body'] instanceof PEAR_Error)) {
         return false;
     }
 
@@ -85,7 +85,7 @@ case 'add_memo':
     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;
@@ -129,10 +129,13 @@ case 'save_memo':
     $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');
@@ -165,16 +168,22 @@ case 'save_memo':
         /* 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 {
@@ -206,7 +215,7 @@ case 'save_memo':
         }
 
         /* 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');
@@ -223,13 +232,15 @@ case 'delete_memos':
     $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');
index 54ea73c..c721bbe 100644 (file)
@@ -20,7 +20,7 @@ $passphrase = Horde_Util::getFormData('memo_passphrase');
 $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;
     }
@@ -40,13 +40,14 @@ if ($uid = Horde_Util::getFormData('uid')) {
     /* 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;
index 08d594d..71249f9 100644 (file)
@@ -27,14 +27,14 @@ if ($notepad_id == Horde_Auth::getAuth()) {
     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;
@@ -45,7 +45,7 @@ $form = new Mnemo_DeleteNotepadForm($vars, $notepad);
 // 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');
index ddf5012..eef01e9 100644 (file)
@@ -21,13 +21,16 @@ if (!Horde_Auth::getAuth()) {
 }
 
 $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;
index 934c750..7d01021 100644 (file)
@@ -66,11 +66,11 @@ if (count($memos)) {
         $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';
index 727ec3c..e9350b0 100644 (file)
@@ -1,7 +1,7 @@
  <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>';
index c9fa292..b597160 100644 (file)
@@ -6,8 +6,8 @@ if ($memo_id):
     $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; ?>
 
index e439cd2..761b907 100644 (file)
@@ -2,7 +2,7 @@
 $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">
index e7a4249..4ee5609 100644 (file)
@@ -38,13 +38,14 @@ if ($uid = Horde_Util::getFormData('uid')) {
     /* 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;