Add Horde::permissionDeniedError() to provide consistent permission error handling...
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 4 Nov 2010 07:24:55 +0000 (01:24 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 4 Nov 2010 19:44:29 +0000 (13:44 -0600)
24 files changed:
agora/lib/Api.php
agora/messages/index.php
folks/templates/user/user.php
framework/Block/lib/Horde/Block/Layout/Manager.php
framework/Core/lib/Horde.php
horde/config/hooks.php.dist
imp/lib/Compose.php
imp/lib/Folder.php
ingo/filters.php
ingo/rule.php
kronolith/add.php
kronolith/data.php
kronolith/edit.php
kronolith/lib/Ajax/Application.php
kronolith/new.php
mnemo/data.php
mnemo/memo.php
nag/data.php
nag/task.php
trean/add.php
trean/data.php
turba/add.php
turba/data.php
turba/lib/View/Browse.php

index a58f41a..c64d4d2 100644 (file)
@@ -453,11 +453,8 @@ class Agora_Api extends Horde_Registry_Api
 
         /* Check post permissions. */
         if (!$messages->hasPermission(Horde_Perms::EDIT)) {
-            try {
-                return Horde::callHook('perms_denied', array('agora'));
-            } catch (Horde_Exception_HookNotSet $e) {
-                return sprintf(_("You don't have permission to post messages in forum %s."), $params['forum_id']);
-            }
+            Horde::permissionDeniedError('agora', null);
+            return PEAR::raiseError(sprintf(_("You don't have permission to post messages in forum %s."), $params['forum_id']));
         }
 
         if (isset($params['message_id'])) {
index 276df48..cf9e56a 100644 (file)
@@ -192,12 +192,8 @@ $view->rss = Horde_Util::addParameter(Horde::url('rss/messages.php', true, -1),
 
 /* Display an edit-dialogue if the thread is not locked and we can edit messages in them. */
 if (!$messages->hasPermission(Horde_Perms::EDIT)) {
-    try {
-        $message = Horde::callHook('perms_denied', array('agora'), 'horde');
-    } catch (Horde_Exception_HookNotset $e) {
-        $message = sprintf(_("You don't have permission to post messages in forum %s."), $forum['forum_name']);
-    }
-    $view->form = $message;
+    Horde::permissionDeniedError('agora', null);
+    $view->form = sprintf(_("You don't have permission to post messages in forum %s."), $forum['forum_name']);
 } elseif ($message['locked']) {
     $view->form = _("Thread locked.");
 } else {
index a98da6f..0b0b174 100644 (file)
@@ -380,11 +380,8 @@ case 'authenticated':
             $comments_reason = sprintf(_("You are on %s blacklist."), $user);
         }
     } else {
-        try {
-            $comments_reason = Horde::callHook('perms_denied', array('folks'));
-        } catch (Horde_Exception_HookNotSet $e) {
-            $comments_reason = _("Only authenticated users can post comments.");
-        }
+        Horde::permissionDeniedError('folks', null);
+        $comments_reason = _("Only authenticated users can post comments.");
     }
     break;
 
index 8460f26..bf42281 100644 (file)
@@ -238,12 +238,11 @@ class Horde_Block_Layout_Manager extends Horde_Block_Layout
                 $max_blocks = $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_blocks');
                 if (($max_blocks !== true) &&
                     ($max_blocks <= $this->count())) {
-                    try {
-                        $message = Horde::callHook('perms_denied', array('horde:max_blocks'));
-                    } catch (Horde_Exception_HookNotSet $e) {
-                        $message = htmlspecialchars(sprintf(Horde_Block_Translation::ngettext("You are not allowed to create more than %d block.", "You are not allowed to create more than %d blocks.", $max_blocks), $max_blocks));
-                    }
-                    $GLOBALS['notification']->push($message, 'horde.error', array('content.raw'));
+                    Horde::permissionDeniedError(
+                        'horde',
+                        'max_blocks',
+                        sprintf(Horde_Block_Translation::ngettext("You are not allowed to create more than %d block.", "You are not allowed to create more than %d blocks.", $max_blocks), $max_blocks)
+                    );
                     break;
                 }
 
index f2bf7f8..fea39c6 100644 (file)
@@ -2110,4 +2110,24 @@ HTML;
         return self::endBuffer();
     }
 
+    /**
+     * Process a permission denied error, running a user-defined hook if
+     * necessary.
+     *
+     * @param string $app    Application name.
+     * @param string $perm   Permission name.
+     * @param string $error  An error message to output via the notification
+     *                       system.
+     */
+    static public function permissionDeniedError($app, $perm, $error = null)
+    {
+        try {
+            self::callHook('perms_denied', array($app, $perm));
+        } catch (Horde_Exception_HookNotSet $e) {}
+
+        if (!is_null($error)) {
+            $GLOBALS['notification']->push($error, 'horde.warning');
+        }
+    }
+
 }
index fb63006..e56b63b 100644 (file)
@@ -619,23 +619,18 @@ class Horde_Hooks
     /**
      * Hook called if a user tries to make an action that is under permission
      * control that they don't have sufficient permissions for.  It can be
-     * used to show the user a custom message including HTML code (you have to
-     * take care about HTML escaping on your own), or to interrupt the code
-     * flow and send the user to a different page.
+     * used to show the user a custom message including HTML code (via the
+     * notification system), or to interrupt the code flow and send the user
+     * to a different page.
      *
+     * @param string $app         Horde application.
      * @param string $permission  Permission that failed.
-     *
-     * @return string  An error message.
      */
-//    public function perms_denied($permission)
+//    public function perms_denied($app, $permission)
 //    {
-//        // Example #1: Provide link to upgrade script.
-//        $app = (($pos = strpos($? $mission, ':')) === false)
-//            ? $permission
-//            : substr($permission, 0, $pos);
-//
-//        // TODO: Notification
-//        return sprintf('Permission denied. Click <a href="http://www.example.com/upgrade.php?app=%s">HERE</a> to upgrade %s.', $app, $GLOBALS['registry']->get('name'));
+//        // Example #1: Provide link to upgrade script in notification
+//        // message.
+//        $GLOBALS['notification']->push(sprintf('Permission denied. Click <a href="http://www.example.com/upgrade.php?app=%s">HERE</a> to upgrade %s.', $app, $GLOBALS['registry']->get('name')), 'horde.error', array('content.raw'));
 //    }
 
 
@@ -645,7 +640,7 @@ class Horde_Hooks
      * function will be called to dynamically include users in the group.
      *
      * @param string $groupName  TODO
-     * @param string $userName  TODO
+     * @param string $userName   TODO
      *
      * @return TODO
      */
index a9d790a..e033d46 100644 (file)
@@ -782,12 +782,8 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
             }
 
             if ($recipients > $timelimit) {
-                try {
-                    $error = Horde::callHook('perms_denied', array('imp:max_timelimit'));
-                } catch (Horde_Exception_HookNotSet $e) {
-                    $error = @htmlspecialchars(sprintf(_("You are not allowed to send messages to more than %d recipients within %d hours."), $timelimit, $GLOBALS['conf']['sentmail']['params']['limit_period']), ENT_COMPAT, 'UTF-8');
-                }
-                throw new IMP_Compose_Exception($error);
+                Horde::permissionDeniedError('imp', 'max_timelimit');
+                throw new IMP_Compose_Exception(sprintf(_("You are not allowed to send messages to more than %d recipients within %d hours."), $timelimit, $GLOBALS['conf']['sentmail']['params']['limit_period']));
             }
         }
 
@@ -967,12 +963,8 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
                     $num_recipients += count(explode(',', $recipient));
                 }
                 if ($num_recipients > $max_recipients) {
-                    try {
-                        $message = Horde::callHook('perms_denied', array('imp:max_recipients'));
-                    } catch (Horde_Exception_HookNotSet $e) {
-                        $message = @htmlspecialchars(sprintf(_("You are not allowed to send messages to more than %d recipients."), $max_recipients), ENT_COMPAT, 'UTF-8');
-                    }
-                    throw new IMP_Compose_Exception($message);
+                    Horde::permissionDeniedError('imp', 'max_recipients');
+                    throw new IMP_Compose_Exception(sprintf(_("You are not allowed to send messages to more than %d recipients."), $max_recipients));
                 }
             }
         }
index 10b947e..5d8c5de 100644 (file)
@@ -107,24 +107,23 @@ class IMP_Folder
      */
     public function create($folder, $subscribe)
     {
-        global $conf, $notification;
+        global $conf, $injector, $notification;
 
         /* Check permissions. */
-        if (!$GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('create_folders')) {
-            try {
-                $message = Horde::callHook('perms_denied', array('imp:create_folders'));
-            } catch (Horde_Exception_HookNotSet $e) {
-                $message = @htmlspecialchars(_("You are not allowed to create folders."), ENT_COMPAT, 'UTF-8');
-            }
-            $notification->push($message, 'horde.error', array('content.raw'));
+        $perms = $injector->getInstance('Horde_Perms');
+        if (!$perms->hasAppPermission('create_folders')) {
+            Horde::permissionDeniedError(
+                'imp',
+                'create_folders',
+                _("You are not allowed to create folders.")
+            );
             return false;
-        } elseif (!$GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_folders')) {
-            try {
-                $message = Horde::callHook('perms_denied', array('imp:max_folders'));
-            } catch (Horde_Exception_HookNotSet $e) {
-                $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d folders."), $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_folders', array('opts' => array('value' => true)))), ENT_COMPAT, 'UTF-8');
-            }
-            $notification->push($message, 'horde.error', array('content.raw'));
+        } elseif (!$perms->hasAppPermission('max_folders')) {
+            Horde::permissionDeniedError(
+                'imp',
+                'max_folders',
+                sprintf(_("You are not allowed to create more than %d folders."), $perms->hasAppPermission('max_folders', array('opts' => array('value' => true))))
+            );
             return false;
         }
 
index 54a0e28..2a8305c 100644 (file)
@@ -59,21 +59,19 @@ case 'rule_enable':
 
     case 'rule_copy':
         if (!$perms->hasAppPermission('allow_rules')) {
-            try {
-                $message = Horde::callHook('perms_denied', array('ingo:allow_rules'));
-            } catch (Horde_Exception_HookNotSet $e) {
-                $message = htmlspecialchars(_("You are not allowed to create or edit custom rules."));
-            }
-            $notification->push($message, 'horde.error', array('content.raw'));
+            Horde::permissionDeniedError(
+                'ingo',
+                'allow_rules',
+                _("You are not allowed to create or edit custom rules.")
+            );
             break 2;
         } elseif ($perms->hasAppPermission('max_rules') !== true &&
                   $perms->hasAppPermission('max_rules') <= count($filters->getFilterList())) {
-            try {
-                $message = Horde::callHook('perms_denied', array('ingo:max_rules'));
-            } catch (Horde_Exception_HookNotSet $e) {
-                $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d rules."), $perms->hasAppPermission('max_rules')));
-            }
-            $notification->push($message, 'horde.error', array('content.raw'));
+            Horde::permissionDeniedError(
+                'ingo',
+                'max_rules',
+                sprintf(_("You are not allowed to create more than %d rules."), $perms->hasAppPermission('max_rules'))
+            );
             break 2;
         } else {
             $tmp = $filters->getFilter($vars->rulenumber);
index 5c3d34b..75d1509 100644 (file)
@@ -17,12 +17,11 @@ Horde_Registry::appInit('ingo');
 /* Check rule permissions. */
 $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
 if (!$perms->hasAppPermission('allow_rules')) {
-    try {
-        $message = Horde::callHook('perms_denied', array('ingo:allow_rules'));
-    } catch (Horde_Exception_HookNotSet $e) {
-        $message = htmlspecialchars(_("You are not allowed to create or edit custom rules."));
-    }
-    $notification->push($message, 'horde.error', array('content.raw'));
+    Horde::permissionDeniedError(
+        'ingo',
+        'allow_rules',
+        _("You are not allowed to create or edit custom rules.")
+    );
     Horde::url('filters.php', true)->redirect();
 }
 
@@ -166,12 +165,11 @@ default:
     if (!isset($vars->edit)) {
         if ($perms->hasAppPermission('max_rules') !== true &&
             $perms->hasAppPermission('max_rules') <= count($filters->getFilterList())) {
-            try {
-                $message = Horde::callHook('perms_denied', array('ingo:max_rules'));
-            } catch (Horde_Exception_HookNotSet $e) {
-                $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d rules."), $perms->hasAppPermission('max_rules')));
-            }
-            $notification->push($message, 'horde.error', array('content.raw'));
+            Horde::permissionDeniedError(
+                'ingo',
+                'max_rules',
+                sprintf(_("You are not allowed to create more than %d rules."), $perms->hasAppPermission('max_rules'))
+            );
             header('Location: ' . Horde::url('filters.php', true));
             exit;
         }
index 41907c6..33b6841 100644 (file)
@@ -51,12 +51,11 @@ do {
         $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
         if ($perms->hasAppPermission('max_events') !== true &&
             $perms->hasAppPermission('max_events') <= Kronolith::countEvents()) {
-            try {
-                $message = Horde::callHook('perms_denied', array('kronolith:max_events'));
-            } catch (Horde_Exception_HookNotSet $e) {
-                $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events')));
-            }
-            $GLOBALS['notification']->push($message, 'horde.error', array('content.raw'));
+            Horde::permissionDeniedError(
+                'kronolith',
+                'max_events',
+                sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events'))
+            );
             break;
         }
 
index 2bdb25e..d4e24b5 100644 (file)
@@ -43,12 +43,11 @@ $templates = array(
 $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
 if ($perms->hasAppPermission('max_events') !== true &&
     $perms->hasAppPermission('max_events') <= Kronolith::countEvents()) {
-    try {
-        $message = Horde::callHook('perms_denied', array('kronolith:max_events'));
-    } catch (Horde_Exception_HookNotSet $e) {
-        $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events')));
-    }
-    $notification->push($message, 'horde.warning', array('content.raw'));
+    Horde::permissionDeniedError(
+        'kronolith',
+        'max_events',
+        sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events'))
+    );
     $templates[Horde_Data::IMPORT_FILE] = array(KRONOLITH_TEMPLATES . '/data/export.inc');
 } else {
     $templates[Horde_Data::IMPORT_FILE] = array(KRONOLITH_TEMPLATES . '/data/import.inc', KRONOLITH_TEMPLATES . '/data/export.inc');
@@ -260,12 +259,11 @@ if (is_array($next_step)) {
     $recurrences = array();
     foreach ($next_step as $row) {
         if ($max_events !== true && $num_events >= $max_events) {
-            try {
-                $message = Horde::callHook('perms_denied', array('kronolith:max_events'));
-            } catch (Horde_Exception_HookNotSet $e) {
-                $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events')));
-            }
-            $notification->push($message, 'horde.error', array('content.raw'));
+            Horde::permissionDeniedError(
+                'kronolith',
+                'max_events',
+                sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events'))
+            );
             break;
         }
         try {
index cf3f2f0..170efa6 100644 (file)
@@ -28,12 +28,11 @@ function _check_max()
     $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
     if ($perms->hasAppPermission('max_events') !== true &&
         $perms->hasAppPermission('max_events') <= Kronolith::countEvents()) {
-        try {
-            $message = Horde::callHook('perms_denied', array('kronolith:max_events'));
-        } catch (Horde_Exception_HookNotSet $e) {
-            $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events')));
-        }
-        $GLOBALS['notification']->push($message, 'horde.error', array('content.raw'));
+        Horde::permissionDeniedError(
+            'kronolith',
+            'max_events',
+            sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events'))
+        );
         return false;
     }
     return true;
index 263aa84..84f1aca 100644 (file)
@@ -97,12 +97,11 @@ class Kronolith_Ajax_Application extends Horde_Core_Ajax_Application
             $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
             if ($perms->hasAppPermission('max_events') !== true &&
                 $perms->hasAppPermission('max_events') <= Kronolith::countEvents()) {
-                try {
-                    $message = Horde::callHook('perms_denied', array('kronolith:max_events'));
-                } catch (Horde_Exception_HookNotSet $e) {
-                    $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events')));
-                }
-                $GLOBALS['notification']->push($message, 'horde.error', array('content.raw'));
+                Horde::permissionDeniedError(
+                    'kronolith',
+                    'max_events',
+                    sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events'))
+                );
                 return $result;
             }
         }
index d9deb16..80ff1f7 100644 (file)
@@ -23,12 +23,11 @@ $url = Horde::url($prefs->getValue('defaultview') . '.php', true)
 $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
 if ($perms->hasAppPermission('max_events') !== true &&
     $perms->hasAppPermission('max_events') <= Kronolith::countEvents()) {
-    try {
-        $message = Horde::callHook('perms_denied', array('kronolith:max_events'));
-    } catch (Horde_Exception_HookNotSet $e) {
-        $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events')));
-    }
-    $notification->push($message, 'horde.error', array('content.raw'));
+    Horde::permissionDeniedError(
+        'kronolith',
+        'max_events',
+        sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events'))
+    );
     $url->redirect();
 }
 
index 46ad375..156c283 100644 (file)
@@ -34,12 +34,11 @@ $templates = array(
 );
 if ($GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_notes') !== true &&
     $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_notes') <= Mnemo::countMemos()) {
-    try {
-        $message = Horde::callHook('perms_denied', array('mnemo:max_notes'));
-    } catch (Horde_Exception_HookNotSet $e) {
-        $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d notes."), $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_notes')));
-    }
-    $notification->push($message, 'horde.warning', array('content.raw'));
+    Horde::permissionDeniedError(
+        'mnemo',
+        'max_notes',
+        sprintf(_("You are not allowed to create more than %d notes."), $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_notes'))
+    );
     $templates[Horde_Data::IMPORT_FILE] = array(MNEMO_TEMPLATES . '/data/export.inc');
 } else {
     $templates[Horde_Data::IMPORT_FILE] = array(MNEMO_TEMPLATES . '/data/import.inc', MNEMO_TEMPLATES . '/data/export.inc');
@@ -122,12 +121,11 @@ if (is_array($next_step)) {
     $num_memos = Mnemo::countMemos();
     foreach ($next_step as $row) {
         if ($max_memos !== true && $num_memos >= $max_memos) {
-            try {
-                $message = Horde::callHook('perms_denied', array('mnemo:max_notes'));
-            } catch (Horde_Exception_HookNotSet $e) {
-                $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d notes."), $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_notes')));
-            }
-            $notification->push($message, 'horde.error', array('content.raw'));
+            Horde::permissionDeniedError(
+                'mnemo',
+                'max_notes',
+                sprintf(_("You are not allowed to create more than %d notes."), $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_notes'))
+            );
             break;
         }
 
index 1fe27c9..3ea0b8a 100644 (file)
@@ -72,13 +72,11 @@ case 'add_memo':
     /* Check permissions. */
     if ($injector->getInstance('Horde_Perms')->hasAppPermission('max_notes') !== true &&
         $injector->getInstance('Horde_Perms')->hasAppPermission('max_notes') <= Mnemo::countMemos()) {
-
-        try {
-            $message = Horde::callHook('perms_denied', array('mnemo:max_notes'));
-        } catch (Horde_Exception_HookNotSet $e) {
-            $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d notes."), $injector->getInstance('Horde_Perms')->hasAppPermission('max_notes')));
-        }
-        $notification->push($message, 'horde.error', array('content.raw'));
+        Horde::permissionDeniedError(
+            'mnemo',
+            'max_notes',
+            sprintf(_("You are not allowed to create more than %d notes."), $injector->getInstance('Horde_Perms')->hasAppPermission('max_notes'))
+        );
         Horde::url('list.php', true)->redirect();
     }
     /* Set up the note attributes. */
index c0da90e..57bb5d2 100644 (file)
@@ -38,12 +38,11 @@ $templates = array(
 $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
 if ($perms->hasAppPermission('max_tasks') !== true &&
     $perms->hasAppPermission('max_tasks') <= Nag::countTasks()) {
-    try {
-        $message = Horde::callHook('perms_denied', array('nag:max_tasks'));
-    } catch (Horde_Exception_HookNotSet $e) {
-        $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d tasks."), $perms->hasAppPermission('max_tasks')));
-    }
-    $notification->push($message, 'horde.warning', array('content.raw'));
+    Horde::permissionDeniedError(
+        'nag',
+        'max_tasks',
+        sprintf(_("You are not allowed to create more than %d tasks."), $perms->hasAppPermission('max_tasks'))
+    );
     $templates[Horde_Data::IMPORT_FILE] = array(NAG_TEMPLATES . '/data/export.inc');
 } else {
     $templates[Horde_Data::IMPORT_FILE] = array(NAG_TEMPLATES . '/data/import.inc', NAG_TEMPLATES . '/data/export.inc');
@@ -166,12 +165,11 @@ if (is_array($next_step)) {
     $result = null;
     foreach ($next_step as $row) {
         if ($max_tasks !== true && $num_tasks >= $max_tasks) {
-            try {
-                $message = Horde::callHook('perms_denied', array('nag:max_tasks'));
-            } catch (Horde_Exception_HookNotSet $e) {
-                $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d tasks."), $perms->hasAppPermission('max_tasks')));
-            }
-            $notification->push($message, 'horde.error', array('content.raw'));
+            Horde::permissionDeniedError(
+                'nag',
+                'max_tasks',
+                sprintf(_("You are not allowed to create more than %d tasks."), $perms->hasAppPermission('max_tasks'))
+            );
             break;
         }
 
index f744430..ed77ba0 100644 (file)
@@ -68,12 +68,11 @@ case 'add_task':
     $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
     if ($perms->hasAppPermission('max_tasks') !== true &&
         $perms->hasAppPermission('max_tasks') <= Nag::countTasks()) {
-        try {
-            $message = Horde::callHook('perms_denied', array('nag:max_tasks'));
-        } catch (Horde_Exception_HookNotSet $e) {
-            $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d tasks."), $perms->hasAppPermission('max_tasks')));
-        }
-        $notification->push($message, 'horde.error', array('content.raw'));
+        Horde::permissionDeniedError(
+            'nag',
+            'max_tasks',
+            sprintf(_("You are not allowed to create more than %d tasks."), $perms->hasAppPermission('max_tasks'))
+        );
         Horde::url('list.php', true)->redirect();
     }
 
index 2b94210..a76459e 100644 (file)
@@ -20,12 +20,11 @@ case 'add_bookmark':
     /* Check permissions. */
     if (Trean::hasPermission('max_bookmarks') !== true &&
         Trean::hasPermission('max_bookmarks') <= $trean_shares->countBookmarks()) {
-        try {
-            $message = Horde::callHook('perms_denied', array('trean:max_bookmarks'));
-        } catch (Horde_Exception_HookNotSet $e) {
-            $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d bookmarks."), Trean::hasPermission('max_bookmarks')));
-        }
-        $notification->push($message, 'horde.error', array('content.raw'));
+        Horde::permissionDeniedError(
+            'trean',
+            'max_bookmarks',
+            sprintf(_("You are not allowed to create more than %d bookmarks."), Trean::hasPermission('max_bookmarks'))
+        );
         Horde::url('browse.php', true)->redirect();
     }
 
@@ -84,12 +83,11 @@ case 'add_folder':
     /* Check permissions. */
     if (Trean::hasPermission('max_folders') !== true &&
         Trean::hasPermission('max_folders') <= Trean::countFolders()) {
-        try {
-            $message = Horde::callHook('perms_denied', array('trean:max_folders'));
-        } catch (Horde_Exception_HookNotSet $e) {
-            $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d folders."), Trean::hasPermission('max_folders')));
-        }
-        $notification->push($message, 'horde.error', array('content.raw'));
+        Horde::permissionDeniedError(
+            'trean',
+            'max_folders',
+            sprintf(_("You are not allowed to create more than %d folders."), Trean::hasPermission('max_folders'))
+        );
         Horde::url('browse.php', true)
             ->add('f', $parent_id)
             ->redirect();
index 0ba672f..2f07dff 100644 (file)
@@ -53,22 +53,20 @@ Horde_Registry::appInit('trean');
 $folders_exceeded = Trean::hasPermission('max_folders') !== true &&
 Trean::hasPermission('max_folders') <= Trean::countFolders();
 if ($folders_exceeded) {
-    try {
-        $message = Horde::callHook('perms_denied', array('trean:max_folders'));
-    } catch (Horde_Exception_HookNotSet $e) {
-        $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d folders."), Trean::hasPermission('max_folders')));
-    }
-    $notification->push($message, 'horde.warning', array('content.raw'));
+    Horde::permissionDeniedError(
+        'trean',
+        'max_folders',
+        sprintf(_("You are not allowed to create more than %d folders."), Trean::hasPermission('max_folders'))
+    );
 }
 $bookmarks_exceeded = Trean::hasPermission('max_bookmarks') !== true &&
 Trean::hasPermission('max_bookmarks') <= $trean_shares->countBookmarks();
 if ($bookmarks_exceeded) {
-    try {
-        $message = Horde::callHook('perms_denied', array('trean:max_bookmarks'),);
-    } catch (Horde_Exception_HookNotSet $e) {
-        $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d bookmarks."), Trean::hasPermission('max_bookmarks')));
-    }
-    $notification->push($message, 'horde.warning', array('content.raw'));
+    Horde::permissionDeniedError(
+        'trean',
+        'max_bookmarks',
+        sprintf(_("You are not allowed to create more than %d bookmarks."), Trean::hasPermission('max_bookmarks'))
+    );
 }
 
 switch (Horde_Util::getFormData('actionID')) {
@@ -106,12 +104,11 @@ case 'import':
                 continue;
             }
             if ($max_folders !== true && $num_folders >= $max_folders) {
-                try {
-                    $message = Horde::callHook('perms_denied', array('trean:max_folders'));
-                } catch (Horde_Exception_HookNotSet $e) {
-                    $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d folders."), Trean::hasPermission('max_folders')));
-                }
-                $notification->push($message, 'horde.error', array('content.raw'));
+                Horde::permissionDeniedError(
+                    'trean',
+                    'max_folders',
+                    sprintf(_("You are not allowed to create more than %d folders."), Trean::hasPermission('max_folders'))
+                );
                 $stop_folders = true;
                 continue;
             }
@@ -132,12 +129,11 @@ case 'import':
                              $line, $temp)) {
             /* A bookmark. */
             if ($max_bookmarks !== true && $num_bookmarks >= $max_bookmarks) {
-                try {
-                    $message = Horde::callHook('perms_denied', array('trean:max_bookmarks'));
-                } catch (Horde_Exception_HookNotSet $e) {
-                    $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d bookmarks."), Trean::hasPermission('max_bookmarks')));
-                }
-                $notification->push($message, 'horde.error', array('content.raw'));
+                Horde::permissionDeniedError(
+                    'trean',
+                    'max_bookmarks',
+                    sprintf(_("You are not allowed to create more than %d bookmarks."), Trean::hasPermission('max_bookmarks'))
+                );
                 $stop_bookmarks = true;
                 break;
             }
index ada57a7..9df85e4 100644 (file)
@@ -45,12 +45,11 @@ if ($source) {
         $max_contacts = Turba::getExtendedPermission($driver, 'max_contacts');
         if ($max_contacts !== true &&
             $max_contacts <= count($driver)) {
-            try {
-                $message = Horde::callHook('perms_denied', array('turba:max_contacts'));
-            } catch (Horde_Exception_HookNotSet $e) {
-                $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $cfgSources[$source]['title']));
-            }
-            $notification->push($message, 'horde.error', array('content.raw'));
+            Horde::permissionDeniedError(
+                'turba',
+                'max_contacts',
+                sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $cfgSources[$source]['title'])
+            );
             $url = $url
                 ? Horde::url($url, true)
                 : Horde::url('index.php', true);
index d483dff..f1ccaa2 100644 (file)
@@ -346,12 +346,11 @@ case Horde_Data::IMPORT_FILE:
     $max_contacts = Turba::getExtendedPermission($driver, 'max_contacts');
     if ($max_contacts !== true &&
         $max_contacts <= count($driver)) {
-        try {
-            $message = Horde::callHook('perms_denied', array('turba:max_contacts'));
-        } catch (Horde_Exception_HookNotSet $e) {
-            $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $driver->title));
-        }
-        $notification->push($message, 'horde.error', array('content.raw'));
+        Horde::permissionDeniedError(
+            'turba',
+            'max_contacts',
+            sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $driver->title)
+        );
         $error = true;
         break;
     }
index edd048a..ecb4763 100644 (file)
@@ -148,14 +148,13 @@ class Turba_View_Browse {
                 }
 
                 $max_contacts = Turba::getExtendedPermission($targetDriver, 'max_contacts');
-                if ($max_contacts !== true
-                    && $max_contacts <= count($targetDriver)) {
-                    try {
-                        $message = Horde::callHook('perms_denied', array('turba:max_contacts'));
-                    } catch (Horde_Exception_HookNotSet $e) {
-                        $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $cfgSources[$targetSource]['title']));
-                    }
-                    $notification->push($message, 'horde.error', array('content.raw'));
+                if ($max_contacts !== true &&
+                    $max_contacts <= count($targetDriver)) {
+                    Horde::permissionDeniedError(
+                        'turba',
+                        'max_contacts',
+                        sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $cfgSources[$targetSource]['title'])
+                    );
                     break;
                 }
 
@@ -302,12 +301,11 @@ class Turba_View_Browse {
                     $max_contacts = Turba::getExtendedPermission($driver, 'max_contacts');
                     if ($max_contacts !== true &&
                         $max_contacts <= count($driver)) {
-                        try {
-                            $message = Horde::callHook('perms_denied', array('turba:max_contacts'));
-                        } catch (Horde_Exception $e) {
-                            $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $cfgSources[$source]['title']));
-                        }
-                        $notification->push($message, 'horde.error', array('content.raw'));
+                        Horde::permissionDeniedError(
+                            'turba',
+                            'max_contacts',
+                            sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $cfgSources[$source]['title'])
+                        );
                         break;
                     }