[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/strongarm/ -> strongarm.admin.inc (source)

   1  <?php
   2  // $Id: strongarm.admin.inc,v 1.1.2.2.2.5 2010/08/04 22:53:54 yhahn Exp $
   3  
   4  /**
   5   * Variable management strongarm form.
   6   */
   7  function strongarm_admin_form($form_state) {
   8    global $conf;
   9    $vars = strongarm_vars_load(TRUE, TRUE);
  10    $form = array('#theme' => 'strongarm_admin_form',);
  11    foreach ($vars as $name => $variable) {
  12      if ($variable->export_type & EXPORT_IN_CODE) {
  13        $default = ctools_get_default_object('variable', $name);
  14  
  15        // If variable value does not match global $conf, this value has been
  16        // hardcoded (e.g. in settings.php) and has been allowed to pass
  17        // through. It cannot be reverted.
  18        if ($conf[$name] !== $variable->value) {
  19          $storage = t('Hardcoded');
  20          $hardcoded = TRUE;
  21        }
  22        else {
  23          $storage = ($variable->value == $default->value) ? t('Default') : t('Overridden');
  24          $hardcoded = FALSE;
  25        }
  26  
  27        // If the variable is in the database and differs from its code value,
  28        // allow administrator to revert its value.
  29        if (!$hardcoded && ($variable->export_type & EXPORT_IN_DATABASE) && ($variable->value != $default->value)) {
  30          $form['revert']['#tree'] = TRUE;
  31          $form['revert'][$name] = array('#type' => 'checkbox');
  32        }
  33        $form['name'][$name] = array(
  34          '#type' => 'markup',
  35          '#value' => $name,
  36        );
  37        $form['storage'][$name] = array(
  38          '#type' => 'markup',
  39          '#value' => $storage,
  40        );
  41        $form['value'][$name] = array(
  42          '#type' => 'markup',
  43          '#value' => check_plain(_strongarm_readable($variable->value)),
  44        );
  45      }
  46    }
  47    if (!empty($form['revert'])) {
  48      $form['submit'] = array(
  49        '#type' => 'submit',
  50        '#value' => t('Reset to defaults'),
  51        '#submit' => array('strongarm_admin_revert_submit'),
  52      );
  53    }
  54    return $form;
  55  }
  56  
  57  /**
  58   * Revert form submit handler.
  59   */
  60  function strongarm_admin_revert_submit(&$form, &$form_state) {
  61    if (!empty($form_state['values']['revert'])) {
  62      foreach ($form_state['values']['revert'] as $name => $revert) {
  63        if ($revert) {
  64          variable_del($name);
  65        }
  66      }
  67      strongarm_flush_caches();
  68    }
  69  }
  70  
  71  /**
  72   * Display variables in a nicer way.
  73   */
  74  function _strongarm_readable($var) {
  75    if (is_string($var) || is_numeric($var)) {
  76      return truncate_utf8($var, 30, TRUE, TRUE);
  77    }
  78    else if (is_bool($var)) {
  79      return $var ? 'TRUE' : 'FALSE';
  80    }
  81    else if (is_array($var)) {
  82      $test = $detected = array();
  83      $test['keys'] = array_keys($var);
  84      $test['values'] = array_values($var);
  85  
  86      foreach ($test as $type => $values) {
  87        $numeric = TRUE;
  88        $sequential = 0;
  89        $boolean = TRUE;
  90        foreach ($values as $v) {
  91          $numeric = is_numeric($v) && $numeric;
  92          $sequential = is_numeric($v) && ($sequential == $v) && $sequential !== FALSE ? $sequential + 1 : FALSE;
  93          $boolean = $boolean && ($v === 0 || $v === 1 || $v === '1' || $v === '0' || $v === TRUE || $v === FALSE);
  94        }
  95        $detected[$type]['numeric'] = $numeric;
  96        $detected[$type]['sequential'] = $sequential !== FALSE;
  97        $detected[$type]['boolean'] = $boolean;
  98      }
  99  
 100      // List of things
 101      if (!empty($var) && $detected['keys']['numeric'] && $detected['keys']['sequential']) {
 102        return truncate_utf8(implode(', ', $var), 30, TRUE, TRUE);
 103      }
 104      return '-';
 105    }
 106  }
 107  
 108  /**
 109   * Theme function for the strongarm admin form.
 110   */
 111  function theme_strongarm_admin_form($form) {
 112    drupal_add_js('misc/tableselect.js');
 113    $rows = $headers = array();
 114    $headers[] = theme('table_select_header_cell');
 115    $headers[] = t('Variable');
 116    $headers[] = t('Storage');
 117    $headers[] = t('Value');
 118    foreach (element_children($form['name']) as $name) {
 119      $row = array();
 120      $row[] = isset($form['revert'][$name]) ? drupal_render($form['revert'][$name]) : '';
 121      $row[] = drupal_render($form['name'][$name]);
 122      $row[] = drupal_render($form['storage'][$name]);
 123      $row[] = drupal_render($form['value'][$name]);
 124      $rows[] = $row;
 125    }
 126    $output = theme('table', $headers, $rows);
 127    $output .= drupal_render($form);
 128    return $output;
 129  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7