From 884c50def8d438ce7edd830848638071d7b1dd0e Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 14 Oct 2010 11:23:05 -0600 Subject: [PATCH] Config code converted to Horde_Session --- horde/admin/config/config.php | 5 +++-- horde/admin/config/diff.php | 19 +++++++++---------- horde/admin/config/index.php | 6 +++--- horde/admin/config/scripts.php | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/horde/admin/config/config.php b/horde/admin/config/config.php index 5940d0c91..7bc95356a 100644 --- a/horde/admin/config/config.php +++ b/horde/admin/config/config.php @@ -63,8 +63,9 @@ if (Horde_Util::getFormData('submitbutton') == _("Revert Configuration")) { } 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('admin/config/index.php') . '#update', _("Configuration")) . _("Configuration") . '', Horde_Util::realPath($path . '/conf.php')), 'horde.warning', array('content.raw')); + /* Save to session. */ - $_SESSION['_config'][$app] = $php; + $session['horde:config/' . $app] = $php; } } elseif ($form->isSubmitted()) { $notification->push(_("There was an error in the configuration form. Perhaps you left out a required field."), 'horde.error'); @@ -75,7 +76,7 @@ $template = $injector->createInstance('Horde_Template'); $template->set('php', htmlspecialchars($php), true); /* Create the link for the diff popup only if stored in session. */ $diff_link = ''; -if (!empty($_SESSION['_config'][$app])) { +if (isset($session['horde:config/' . $app])) { $url = Horde::url('admin/config/diff.php', true)->add('app', $app); $diff_link = Horde::link('#', '', '', '', Horde::popupJs($url, array('height' => 480, 'width' => 640, 'urlencode' => true)) . 'return false;') . _("show differences") . ''; } diff --git a/horde/admin/config/diff.php b/horde/admin/config/diff.php index 20e001b5c..af54ed401 100644 --- a/horde/admin/config/diff.php +++ b/horde/admin/config/diff.php @@ -22,7 +22,7 @@ $renderer = new $class(); */ function _getDiff($app) { - global $renderer, $registry; + global $registry, $renderer, $session; /* Read the existing configuration. */ $current_config = ''; @@ -31,18 +31,17 @@ function _getDiff($app) /* Calculate the differences. */ $diff = new Text_Diff(explode("\n", $current_config), - explode("\n", $_SESSION['_config'][$app])); + explode("\n", $session['horde:config/' . $app])); $diff = $renderer->render($diff); - if (!empty($diff)) { - return $diff; - } else { - return _("No change."); - } + + return empty($diff) + ? _("No change.") + : $diff; } $diffs = array(); /* Only bother to do anything if there is any config. */ -if (!empty($_SESSION['_config'])) { +if ($config = $session['horde:config/']) { /* Set up the toggle button for inline/unified. */ $url = Horde::url('admin/config/diff.php')->add('render', ($render_type == 'inline') ? 'unified' : 'inline'); @@ -58,8 +57,8 @@ if (!empty($_SESSION['_config'])) { 'toggle_renderer' => $toggle_renderer); } else { /* List all the apps with generated configuration. */ - ksort($_SESSION['_config']); - foreach ($_SESSION['_config'] as $app => $config) { + ksort($config); + foreach ($config as $app => $config) { $toggle_renderer = Horde::link($url . '#' . $app) . (($render_type == 'inline') ? _("unified") : _("inline")) . ''; $diff = _getDiff($app); if ($render_type != 'inline') { diff --git a/horde/admin/config/index.php b/horde/admin/config/index.php index a92317f54..0d1234e8e 100644 --- a/horde/admin/config/index.php +++ b/horde/admin/config/index.php @@ -30,7 +30,7 @@ function _uploadFTP($params) /* Loop through the config and write to FTP. */ $no_errors = true; - foreach ($_SESSION['_config'] as $app => $config) { + foreach ($session['horde:config/'] as $app => $config) { $path = $registry->get('fileroot', $app) . '/config'; /* Try to back up the current conf.php. */ if ($vfs->exists($path, 'conf.php')) { @@ -45,7 +45,7 @@ function _uploadFTP($params) try { $vfs->writeData($path, 'conf.php', $config); $notification->push(sprintf(_("Successfully wrote %s"), Horde_Util::realPath($path . '/conf.php')), 'horde.success'); - unset($_SESSION['_config'][$app]); + unset($session['horde:config/' . $app]); } catch (VFS_Exception $e) { $no_errors = false; $notification->push(sprintf(_("Could not write configuration for \"%s\": %s"), $app, $e->getMessage()), 'horde.error'); @@ -168,7 +168,7 @@ Horde_Array::arraySort($apps, 'sort'); /* Set up any actions that may be offered. */ $actions = array(); $ftpform = ''; -if (!empty($_SESSION['_config'])) { +if ($session['horde:config/']) { $url = Horde::url('admin/config/diff.php'); $action = _("Show differences between currently saved and the newly generated configuration."); $actions[] = array('icon' => Horde::img('search.png', '', 'align="middle"'), diff --git a/horde/admin/config/scripts.php b/horde/admin/config/scripts.php index 57c97b1a9..2234f2e33 100644 --- a/horde/admin/config/scripts.php +++ b/horde/admin/config/scripts.php @@ -44,7 +44,7 @@ if ($setup == 'conf' && $type == 'php') { * to be run at the command prompt. */ $data = '#!/usr/bin/env php' . "\n"; $data .= ' $php) { + foreach ($session['horde:config/'] as $app => $php) { $path = $registry->get('fileroot', $app) . '/config'; /* Add code to save backup. */ $data .= 'if (file_exists(\'' . $path . '/conf.php\')) {' . "\n"; -- 2.11.0