From d60db49628a9da0689acf915dd40e2ead2005f3d Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 3 Aug 2010 00:17:13 -0600 Subject: [PATCH] Use Horde_Url::redirect() --- horde/admin/perms/addchild.php | 9 ++------- horde/admin/perms/delete.php | 12 +++--------- horde/admin/perms/edit.php | 19 +++++++++---------- horde/admin/setup/config.php | 7 ++----- horde/admin/setup/index.php | 4 +--- horde/admin/setup/scripts.php | 7 +++---- horde/index.php | 9 +++++---- horde/login.php | 12 ++++-------- horde/scripts/http_login_refer.php | 6 ++++-- horde/services/changepassword.php | 8 +++----- horde/services/facebook.php | 7 ++----- horde/services/language.php | 9 +++++---- horde/services/problem.php | 4 +--- horde/services/resetpassword.php | 5 ++--- horde/services/twitter.php | 4 +--- horde/signup.php | 9 +++------ 16 files changed, 50 insertions(+), 81 deletions(-) diff --git a/horde/admin/perms/addchild.php b/horde/admin/perms/addchild.php index 728e3df56..b2af28bc4 100644 --- a/horde/admin/perms/addchild.php +++ b/horde/admin/perms/addchild.php @@ -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'); diff --git a/horde/admin/perms/delete.php b/horde/admin/perms/delete.php index 5ec3c365f..cedcc093e 100644 --- a/horde/admin/perms/delete.php +++ b/horde/admin/perms/delete.php @@ -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"); diff --git a/horde/admin/perms/edit.php b/horde/admin/perms/edit.php index d755fb0ea..10347464c 100644 --- a/horde/admin/perms/edit.php +++ b/horde/admin/perms/edit.php @@ -9,13 +9,6 @@ * @author Jan Schneider */ -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); diff --git a/horde/admin/setup/config.php b/horde/admin/setup/config.php index 1a4d351ab..408d388b7 100644 --- a/horde/admin/setup/config.php +++ b/horde/admin/setup/config.php @@ -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") . '', Horde_Util::realPath($path . '/conf.php')), 'horde.warning', array('content.raw')); diff --git a/horde/admin/setup/index.php b/horde/admin/setup/index.php index 2cacc5917..593f8e131 100644 --- a/horde/admin/setup/index.php +++ b/horde/admin/setup/index.php @@ -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. */ diff --git a/horde/admin/setup/scripts.php b/horde/admin/setup/scripts.php index a50151022..c4d22c771 100644 --- a/horde/admin/setup/scripts.php +++ b/horde/admin/setup/scripts.php @@ -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(); diff --git a/horde/index.php b/horde/index.php index fb17aefa3..1eec80a7e 100644 --- a/horde/index.php +++ b/horde/index.php @@ -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(); diff --git a/horde/login.php b/horde/login.php index 185b1bd8f..c9eb7f4e4 100644 --- a/horde/login.php +++ b/horde/login.php @@ -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