[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/admin/setup/ -> diff.php (source)

   1  <?php
   2  /**
   3   * Script to show the differences between the currently saved and the newly
   4   * generated configuration.
   5   *
   6   * $Horde: horde/admin/setup/diff.php,v 1.4.10.5 2006/05/23 02:13:42 selsky Exp $
   7   *
   8   * Copyright 2004-2006 The Horde Project (http://www.horde.org/)
   9   *
  10   * See the enclosed file COPYING for license information (LGPL).  If you
  11   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  12   */
  13  
  14  define('HORDE_BASE', dirname(__FILE__) . '/../..');
  15  require_once  HORDE_BASE . '/lib/base.php';
  16  require_once 'Horde/Form.php';
  17  require_once 'Horde/Config.php';
  18  require_once 'Horde/Template.php';
  19  include_once 'Text/Diff.php';
  20  include_once 'Text/Diff/Renderer.php';
  21  
  22  if (!Auth::isAdmin()) {
  23      Horde::fatal('Forbidden.', __FILE__, __LINE__);
  24  }
  25  
  26  /* Set up the diff renderer. */
  27  $render_type = Util::getFormData('render', 'inline');
  28  include_once 'Text/Diff/Renderer/' . $render_type . '.php';
  29  $class = 'Text_Diff_Renderer_' . $render_type;
  30  $renderer = &new $class();
  31  
  32  /**
  33   * Private function to render the differences for a specific app.
  34   */
  35  function _getDiff($app)
  36  {
  37      global $renderer, $registry;
  38  
  39      /* Read the existing configuration. */
  40      $current_config = '';
  41      $path = $registry->get('fileroot', $app) . '/config';
  42      $current_config = @file_get_contents($path . '/conf.php');
  43  
  44      /* Calculate the differences. */
  45      $diff = &new Text_Diff(explode("\n", $current_config),
  46                             explode("\n", $_SESSION['_config'][$app]));
  47      $diff = $renderer->render($diff);
  48      if (!empty($diff)) {
  49          return $diff;
  50      } else {
  51          return _("No change.");
  52      }
  53  }
  54  
  55  $diffs = array();
  56  /* Only bother to do anything if there is any config. */
  57  if (!empty($_SESSION['_config'])) {
  58      /* Set up the toggle button for inline/unified. */
  59      $url = Horde::applicationUrl('admin/setup/diff.php');
  60      $url = Util::addParameter($url, 'render', ($render_type == 'inline') ? 'unified' : 'inline');
  61  
  62      if ($app = Util::getFormData('app')) {
  63          /* Handle a single app request. */
  64          $toggle_renderer = Horde::link($url . '#' . $app) . (($render_type == 'inline') ? _("unified") : _("inline")) . '</a>';
  65          $diff = _getDiff($app);
  66          if ($render_type != 'inline') {
  67              $diff = htmlspecialchars($diff);
  68          }
  69          $diffs[] = array('app'  => $app,
  70                           'diff' => $diff,
  71                           'toggle_renderer' => $toggle_renderer);
  72      } else {
  73          /* List all the apps with generated configuration. */
  74          ksort($_SESSION['_config']);
  75          foreach ($_SESSION['_config'] as $app => $config) {
  76              $toggle_renderer = Horde::link($url . '#' . $app) . (($render_type == 'inline') ? _("unified") : _("inline")) . '</a>';
  77              $diff = _getDiff($app);
  78              if ($render_type != 'inline') {
  79                  $diff = htmlspecialchars($diff);
  80              }
  81              $diffs[] = array('app'  => $app,
  82                               'diff' => $diff,
  83                               'toggle_renderer' => $toggle_renderer);
  84          }
  85      }
  86  }
  87  
  88  /* Set up the template. */
  89  $template = &new Horde_Template();
  90  $template->setOption('gettext', true);
  91  $template->set('diffs', $diffs, true);
  92  
  93  $title = _("Configuration Differences");
  94  require  HORDE_TEMPLATES . '/common-header.inc';
  95  echo $template->fetch(HORDE_TEMPLATES . '/admin/setup/diff.html');
  96  require  HORDE_TEMPLATES . '/common-footer.inc';


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7