Config code converted to Horde_Session
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 14 Oct 2010 17:23:05 +0000 (11:23 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 15 Oct 2010 16:13:55 +0000 (10:13 -0600)
horde/admin/config/config.php
horde/admin/config/diff.php
horde/admin/config/index.php
horde/admin/config/scripts.php

index 5940d0c..7bc9535 100644 (file)
@@ -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") . '</a>', 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") . '</a>';
 }
index 20e001b..af54ed4 100644 (file)
@@ -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")) . '</a>';
             $diff = _getDiff($app);
             if ($render_type != 'inline') {
index a92317f..0d1234e 100644 (file)
@@ -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"'),
index 57c97b1..2234f2e 100644 (file)
@@ -44,7 +44,7 @@ if ($setup == 'conf' && $type == 'php') {
      * to be run at the command prompt. */
     $data = '#!/usr/bin/env php' . "\n";
     $data .= '<?php' . "\n";
-    foreach ($_SESSION['_config'] as $app => $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";