Use Horde_Url::redirect()
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 3 Aug 2010 06:17:13 +0000 (00:17 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 3 Aug 2010 06:17:13 +0000 (00:17 -0600)
16 files changed:
horde/admin/perms/addchild.php
horde/admin/perms/delete.php
horde/admin/perms/edit.php
horde/admin/setup/config.php
horde/admin/setup/index.php
horde/admin/setup/scripts.php
horde/index.php
horde/login.php
horde/scripts/http_login_refer.php
horde/services/changepassword.php
horde/services/facebook.php
horde/services/language.php
horde/services/problem.php
horde/services/resetpassword.php
horde/services/twitter.php
horde/signup.php

index 728e3df..b2af28b 100644 (file)
@@ -21,9 +21,7 @@ try {
     $permission = $perms->getPermissionById($perm_id);
 } catch (Exception $e) {
     $notification->push(_("Invalid parent permission."), 'horde.error');
-    $url = Horde::applicationUrl('admin/perms/index.php', true);
-    header('Location: ' . $url);
-    exit;
+    Horde::applicationUrl('admin/perms/index.php', true)->redirect();
 }
 
 /* Set up form. */
@@ -43,10 +41,7 @@ if ($ui->validateAddForm($info)) {
             $result = $perms->addPermission($child);
         }
         $notification->push(sprintf(_("\"%s\" was added to the permissions system."), $perms->getTitle($child->getName())), 'horde.success');
-        $url = Horde::applicationUrl('admin/perms/edit.php', true);
-        $url = Horde_Util::addParameter($url, 'perm_id', $child->getId(), false);
-        header('Location: ' . $url);
-        exit;
+        Horde::applicationUrl('admin/perms/edit.php', true)->add('perm_id', $child->getId())->redirect();
     } catch (Exception $e) {
         Horde::logMessage($e, 'ERR');
         $notification->push(sprintf(_("\"%s\" was not created: %s."), $perms->getTitle($child->getName()), $e->getMessage()), 'horde.error');
index 5ec3c36..cedcc09 100644 (file)
@@ -22,9 +22,7 @@ try {
 } catch (Exception $e) {
     /* If the permission fetched is an error return to permissions list. */
     $notification->push(_("Attempt to delete a non-existent permission."), 'horde.error');
-    $url = Horde::applicationUrl('admin/perms/index.php', true);
-    header('Location: ' . $url);
-    exit;
+    Horde::applicationUrl('admin/perms/index.php', true)->redirect();
 }
 
 /* Set up form. */
@@ -36,17 +34,13 @@ if ($confirmed = $ui->validateDeleteForm($info)) {
     try {
         $result = $perms->removePermission($permission, true);
         $notification->push(sprintf(_("Successfully deleted \"%s\"."), $perms->getTitle($permission->getName())), 'horde.success');
-        $url = Horde::applicationUrl('admin/perms/index.php', true);
-        header('Location: ' . $url);
-        exit;
+        Horde::applicationUrl('admin/perms/index.php', true)->redirect();
     } catch (Exception $e) {
         $notification->push(sprintf(_("Unable to delete \"%s\": %s."), $perms->getTitle($permission->getName()), $result->getMessage()), 'horde.error');
     }
 } elseif ($confirmed === false) {
     $notification->push(sprintf(_("Permission \"%s\" not deleted."), $perms->getTitle($permission->getName())), 'horde.success');
-    $url = Horde::applicationUrl('admin/perms/index.php', true);
-    header('Location: ' . $url);
-    exit;
+    Horde::applicationUrl('admin/perms/index.php', true)->redirect();
 }
 
 $title = _("Permissions Administration");
index d755fb0..1034746 100644 (file)
@@ -9,13 +9,6 @@
  * @author Jan Schneider <jan@horde.org>
  */
 
-function _redirect()
-{
-    $GLOBALS['notification']->push(_("Attempt to edit a non-existent permission."), 'horde.error');
-    header('Location: ' . Horde::applicationUrl('admin/perms/index.php', true));
-    exit;
-}
-
 require_once dirname(__FILE__) . '/../../lib/Application.php';
 Horde_Registry::appInit('horde', array('admin' => true));
 
@@ -26,6 +19,7 @@ $perm_id = $vars->get('perm_id');
 $category = $vars->get('category');
 
 /* See if we need to (and are supposed to) autocreate the permission. */
+$redirect = false;
 if ($category !== null) {
     try {
         $permission = $perms->getPermission($category);
@@ -80,20 +74,25 @@ if ($category !== null) {
             }
             $permission->save();
         } else {
-            _redirect();
+            $redirect = true;
         }
     } catch (Exception $e) {
-        _redirect();
+        $redirect = true;
     }
     $vars->set('perm_id', $perm_id);
 } else {
     try {
         $permission = $perms->getPermissionById($perm_id);
     } catch (Exception $e) {
-        _redirect();
+        $redirect = true;
     }
 }
 
+if ($redirect) {
+    $notification->push(_("Attempt to edit a non-existent permission."), 'horde.error');
+    Horde::applicationUrl('admin/perms/index.php', true)->redirect();
+}
+
 $ui = new Horde_Core_Perms_Ui($perms);
 $ui->setVars($vars);
 $ui->setupEditForm($permission);
index 1a4d351..408d388 100644 (file)
@@ -22,9 +22,7 @@ $title = sprintf(_("%s Setup"), $appname);
 
 if (empty($app) || !in_array($app, $registry->listAllApps())) {
     $notification->push(_("Invalid application."), 'horde.error');
-    $url = Horde::applicationUrl('admin/setup/index.php', true);
-    header('Location: ' . $url);
-    exit;
+    Horde::applicationUrl('admin/setup/index.php', true)->redirect();
 }
 
 $vars = Horde_Variables::getDefaultVariables();
@@ -61,8 +59,7 @@ if (Horde_Util::getFormData('submitbutton') == _("Revert Configuration")) {
         fclose($fp);
         $notification->push(sprintf(_("Successfully wrote %s"), Horde_Util::realPath($path . '/conf.php')), 'horde.success');
         $registry->clearCache();
-        header('Location: ' . Horde::applicationUrl('admin/setup/index.php', true));
-        exit;
+        Horde::applicationUrl('admin/setup/index.php', true)->redirect();
     } else {
         /* Cannot write. */
         $notification->push(sprintf(_("Could not save the configuration file %s. You can either use one of the options to save the code back on %s or copy manually the code below to %s."), Horde_Util::realPath($path . '/conf.php'), Horde::link(Horde::url('index.php') . '#update', _("Setup")) . _("Setup") . '</a>', Horde_Util::realPath($path . '/conf.php')), 'horde.warning', array('content.raw'));
index 2cacc59..593f8e1 100644 (file)
@@ -196,9 +196,7 @@ if (!empty($_SESSION['_config'])) {
         $upload = _uploadFTP($info);
         if ($upload) {
             $notification->push(_("Uploaded all application setup files to the server."), 'horde.success');
-            $url = Horde::applicationUrl('admin/setup/index.php', true);
-            header('Location: ' . $url);
-            exit;
+            Horde::applicationUrl('admin/setup/index.php', true)->redirect();
         }
     }
     /* Render the form. */
index a501510..c4d22c7 100644 (file)
@@ -33,9 +33,7 @@ if ($clean == 'tmp') {
         $notification->push(sprintf(_("Could not delete setup upgrade script \"%s\"."), Horde_Util::realPath($path)), 'horde.error');
     }
     $registry->clearCache();
-    $url = Horde::applicationUrl('admin/setup/index.php', true);
-    header('Location: ' . $url);
-    exit;
+    Horde::applicationUrl('admin/setup/index.php', true)->redirect();
 }
 
 $data = '';
@@ -96,4 +94,5 @@ if ($fp = @fopen($tmp_dir . '/' . $filename, 'w')) {
 } else {
     $notification->push(sprintf(_("Could not save setup upgrade script to: \"%s\"."), $path), 'horde.error');
 }
-header('Location: ' . Horde::applicationUrl('admin/setup/index.php', true));
+
+Horde::applicationUrl('admin/setup/index.php', true)->redirect();
index fb17aef..1eec80a 100644 (file)
@@ -47,7 +47,9 @@ if (!empty($main_page)) {
     }
 }
 
-if (!$main_page) {
+if ($main_page) {
+    $main_page = new Horde_Url($main_page);
+} else {
     /* Always redirect to login page if there is no incoming URL and nobody
      * is authenticated. */
     if (!$registry->getAuth()) {
@@ -58,7 +60,7 @@ if (!$main_page) {
         if (!empty($initial_app) &&
             ($initial_app != 'horde') &&
             $registry->hasPermission($initial_app)) {
-            $main_page = Horde::url($initial_app, true) . '/';
+            $main_page = Horde::url($initial_app, true);
         } else {
             /* Next, try the initial horde page if it is something other than
              * index.php or login.php, since that would lead to inifinite
@@ -76,5 +78,4 @@ if (!$main_page) {
     }
 }
 
-header('Location: ' . $main_page);
-exit;
+$main_page->redirect();
index 185b1bd..c9eb7f4 100644 (file)
@@ -163,8 +163,7 @@ if ($error_reason) {
         if (!isset($_COOKIE[session_name()])) {
             $logout_url->add(session_name(), session_id());
         }
-        header('Location: ' . _addAnchor($logout_url, 'url', $vars, $url_anchor));
-        exit;
+        _addAnchor($logout_url, 'url', $vars, $url_anchor)->redirect();
     }
 
     $registry->setupSessionHandler();
@@ -212,8 +211,7 @@ if ($error_reason) {
                     $change_url->add('return_to', $horde_login_url);
                 }
 
-                header('Location: ' . $change_url->setRaw(true));
-                exit;
+                $change_url->redirect();
             }
         }
 
@@ -241,8 +239,7 @@ if ($is_auth) {
         exit;
     } elseif ($url_in &&
               $registry->isAuthenticated(array('app' => $vars->app))) {
-        header('Location: ' . _addAnchor($url_in, 'param', null, $url_anchor));
-        exit;
+        _addAnchor($url_in, 'param', null, $url_anchor)->redirect();
     }
 }
 
@@ -270,8 +267,7 @@ if (!empty($conf['auth']['alternate_login'])) {
     if (!$found) {
         $url->add('url', $anchor);
     }
-    header('Location: ' . _addAnchor($url, 'url', $vars, $url_anchor));
-    exit;
+    _addAnchor($url, 'url', $vars, $url_anchor)->redirect();
 }
 
 /* Build the <select> widget containing the available languages. */
index 6d1f301..ce6f47a 100644 (file)
@@ -25,7 +25,9 @@ if (empty($_SERVER['PHP_AUTH_USER']) ||
 }
 
 if ($url = Horde_Util::getFormData('url')) {
-    header('Location: ' . $url);
+    $url = new Horde_Url($url);
 } else {
-    header('Location: ' . Horde::applicationUrl('login.php'));
+    $url = Horde::applicationUrl('login.php');
 }
+
+$url->redirect();
index 4ad4317..26564ab 100644 (file)
@@ -15,8 +15,7 @@ Horde_Registry::appInit('horde', array('nologintasks' => true));
 $auth = $injector->getInstance('Horde_Auth')->getAuth();
 if (!$auth->hasCapability('update')) {
     $notification->push(_("Changing your password is not supported with the current configuration.  Contact your administrator."), 'horde.error');
-    header('Location: ' . Horde::getServiceLink('login')->add('url', Horde_Util::getFormData('url'))->setRaw(true));
-    exit;
+    Horde::getServiceLink('login')->add('url', Horde_Util::getFormData('url'))->redirect();
 }
 
 $vars = Horde_Variables::getDefaultVariables();
@@ -54,11 +53,10 @@ if ($vars->exists('formname')) {
 
                 $index_url = Horde::applicationUrl('index.php', true);
                 if (!empty($info['return_to'])) {
-                    $index_url = Horde_Util::addParameter($index_url, array('url' => $info['return_to']));
+                    $index_url->add('url', $info['return_to']);
                 }
 
-                header('Location: ' . $index_url);
-                exit;
+                $index_url->redirect();
             } catch (Horde_Auth_Exception $e) {
                 $notification->push(sprintf(_("Error updating password: %s"), $e->getMessage()), 'horde.error');
             }
index c3cb59e..28ff76c 100644 (file)
@@ -16,8 +16,7 @@ Horde_Registry::appInit('horde');
 try {
     $facebook = $GLOBALS['injector']->getInstance('Horde_Service_Facebook');
 } catch (Horde_Exception $e) {
-    $horde_url = Horde::url($registry->get('webroot', 'horde') . '/index.php');
-    header('Location: ' . $horde_url);
+    Horde::url($registry->get('webroot', 'horde') . '/index.php')->redirect();
 }
 
 /* See why we are here. */
@@ -37,10 +36,8 @@ if ($token = Horde_Util::getFormData('auth_token')) {
         $uid = $facebook->auth->getUser();
         $prefs->setValue('facebook', serialize(array('uid' => $uid, 'sid' => $sid)));
         $notification->push(_("Succesfully connected your Facebook account."), 'horde.success');
-        $url = Horde::url('services/prefs.php', true)->add(array('group' => 'facebook', 'app'  => 'horde'));
-        header('Location: ' . $url);
+        Horde::url('services/prefs.php', true)->add(array('group' => 'facebook', 'app'  => 'horde'))->redirect();
     }
-
 } else {
 
     /* We are here for an Action request */
index 0158e9d..aa9cd81 100644 (file)
@@ -26,7 +26,8 @@ foreach ($registry->listAPIs() as $api) {
 
 /* Redirect to the url or login page if none given. */
 $url = Horde_Util::getFormData('url');
-if (empty($url)) {
-    $url = Horde::applicationUrl('index.php', true);
-}
-header('Location: ' . $url);
+$url = empty($url)
+    ? Horde::applicationUrl('index.php', true)
+    : $url;
+
+$url->redirect();
index e2b2db1..aa8a960 100644 (file)
@@ -11,9 +11,7 @@
 /* Send the browser back to the correct page. */
 function _returnToPage()
 {
-    $url = Horde_Util::getFormData('return_url', Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/login.php', true));
-    header('Location: ' . str_replace('&amp;', '&', $url));
-    exit;
+    (new Horde_Url(Horde_Util::getFormData('return_url', Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/login.php', true))))->redirect();
 }
 
 require_once dirname(__FILE__) . '/../lib/Application.php';
index e40c385..3ee7d5e 100644 (file)
@@ -15,8 +15,7 @@ Horde_Registry::appInit('horde', array('authentication' => 'none'));
 $auth = $injector->getInstance('Horde_Auth')->getAuth();
 if (!$auth->hasCapability('resetpassword')) {
     $notification->push(_("Cannot reset password automatically, contact your administrator."), 'horde.error');
-    header('Location: ' . Horde::getServiceLink('login')->add('url', Horde_Util::getFormData('url'))->setRaw(true));
-    exit;
+    Horde::getServiceLink('login')->add('url', Horde_Util::getFormData('url'))->redirect();
 }
 
 $vars = Horde_Variables::getDefaultVariables();
@@ -81,7 +80,7 @@ if ($can_validate && $form->validate($vars)) {
         try {
             $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
             $notification->push(_("Your password has been reset, check your email and log in with your new password."), 'horde.success');
-            header('Location: ' . Horde::getServiceLink('login')->add('url', $info['url'])->setRaw(true));
+            Horde::getServiceLink('login')->add('url', $info['url'])->redirect();
             exit;
         } catch (Horde_Exception $e) {
             Horde::logMessage($e, 'ERR');
index 9723f62..cda42c7 100644 (file)
@@ -13,9 +13,7 @@ require_once dirname(__FILE__) . '/../lib/Application.php';
 Horde_Registry::appInit('horde');
 
 if (empty($conf['twitter']['enabled'])) {
-    $horde_url = Horde::url($registry->get('webroot', 'horde') . '/index.php');
-    header('Location: ' . $horde_url);
-    exit;
+    Horde::url($registry->get('webroot', 'horde') . '/index.php')->redirect();
 }
 
 $twitter = $GLOBALS['injector']->getInstance('Horde_Service_Twitter');
index 88b9c7d..1941edb 100644 (file)
@@ -17,8 +17,7 @@ $auth = $injector->getInstance('Horde_Auth')->getAuth();
 if ($conf['signup']['allow'] !== true ||
     !$auth->hasCapability('add')) {
     $notification->push(_("User Registration has been disabled for this site."), 'horde.error');
-    header('Location: ' . Horde::getServiceLink('login')->setRaw(true));
-    exit;
+    Horde::getServiceLink('login')->redirect();
 }
 
 try {
@@ -26,8 +25,7 @@ try {
 } catch (Horde_Exception $e) {
     Horde::logMessage($e, 'ERR');
     $notification->push(_("User Registration is not properly configured for this site."), 'horde.error');
-    header('Location: ' . Horde::getServiceLink('login')->setRaw(true));
-    exit;
+    Horde::getServiceLink('login')->redirect();
 }
 
 $vars = Horde_Variables::getDefaultVariables();
@@ -61,8 +59,7 @@ if ($formsignup->validate()) {
             $notification->push(sprintf(_("There was a problem adding \"%s\" to the system: %s"), $info['user_name'], $e->getMessage()), 'horde.error');
         } else {
             $notification->push($success_message, 'horde.success');
-            header('Location: ' . Horde::getServiceLink('login')->add('url', $info['url'])->setRaw(true));
-            exit;
+            Horde::getServiceLink('login')->add('url', $info['url'])->redirect();
         }
     }
 }