[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/strongarm/ -> strongarm.module (source)

   1  <?php
   2  // $Id: strongarm.module,v 1.1.2.6.2.17 2010/08/05 14:43:24 yhahn Exp $
   3  
   4  /**
   5   * Implementation of hook_init().
   6   */
   7  function strongarm_init() {
   8    strongarm_set_conf();
   9  
  10    // This is a workaround for the very early check of the 'site_frontpage'
  11    // variable in the Drupal bootstrap process. The workaround re-runs
  12    // drupal_init_path() to ensure the strongarm'ed version of
  13    // 'site_frontpage' is used. Note that this may be too late if other modules
  14    // weighted even lower than strongarm (which is a superlightweight -1000)
  15    // rely on $_GET['q'] or 'site_frontpage' in hook_init().
  16    $_GET['q'] = isset($_REQUEST['q']) ? strongarm_language_strip($_REQUEST['q']) : NULL;
  17    drupal_init_path();
  18  }
  19  
  20  /**
  21   * Retrieve variable configuration from the cache.
  22   */
  23  function strongarm_set_conf($reset = FALSE) {
  24    $varcache = cache_get('variables', 'cache');
  25    $cache = cache_get('strongarm', 'cache');
  26    // The > comparison here is cautious but ensures that the strongarm cache
  27    // actually was populated after the variable cache. It is possible with
  28    // >= for the var cache to be populated again during the same stale second.
  29    if (!$reset && ($cache && $varcache && $cache->created > $varcache->created)) {
  30      $var_conf = $cache->data;
  31    }
  32    else {
  33      $var_conf = array();
  34      foreach (strongarm_vars_load(FALSE, TRUE) as $var) {
  35        $var_conf[$var->name] = $var->value;
  36      }
  37      cache_set('strongarm', $var_conf);
  38    }
  39    global $conf;
  40  
  41    // Store the original variable values. This allows additional calls to
  42    // strongarm_set_conf() to properly set Strongarm values.
  43    static $original_conf;
  44    if (!isset($original_conf)) {
  45      $original_conf = $conf;
  46    }
  47  
  48    $conf = array_merge($var_conf, $original_conf);
  49  }
  50  
  51  /**
  52   * Remove the language prefix for a given path.
  53   * Strongarm implements this itself as language_initialize() directly affects
  54   * $_GET['q'] and cannot be reused.
  55   */
  56  function strongarm_language_strip($path) {
  57    // Configured presentation language mode.
  58    $mode = variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE);
  59  
  60    // Get a list of enabled languages.
  61    $languages = language_list('enabled');
  62    $languages = $languages[1];
  63  
  64    if (in_array($mode, array(LANGUAGE_NEGOTIATION_PATH_DEFAULT, LANGUAGE_NEGOTIATION_PATH))) {
  65      $args = explode('/', $path);
  66      $prefix = array_shift($args);
  67      // Search prefix within enabled languages.
  68      foreach ($languages as $language) {
  69        if (!empty($language->prefix) && $language->prefix == $prefix) {
  70          return implode('/', $args);
  71        }
  72      }
  73    }
  74    return $path;
  75  }
  76  
  77  /**
  78   * Implementation of hook_menu().
  79   */
  80  function strongarm_menu() {
  81    $items = array();
  82    $items['admin/settings/strongarm'] = array(
  83      'title' => 'Strongarm',
  84      'description' => 'Manage Drupal variable settings that have been strongarmed.',
  85      'page callback' => 'drupal_get_form',
  86      'page arguments' => array('strongarm_admin_form'),
  87      'access callback' => 'user_access',
  88      'access arguments' => array('administer site configuration'),
  89      'file' => 'strongarm.admin.inc',
  90      'type' => MENU_NORMAL_ITEM,
  91    );
  92    return $items;
  93  }
  94  
  95  /**
  96   * Implementation of hook_form_alter() for system_module form.
  97   * Clear strongarm & variable caches on modules page.
  98   */
  99  function strongarm_form_system_module_alter(&$form, &$form_state) {
 100    strongarm_flush_caches();
 101  }
 102  
 103  /**
 104   * Implementation of hook_theme().
 105   */
 106  function strongarm_theme() {
 107    return array(
 108      'strongarm_admin_form' => array(
 109        'arguments' => array(),
 110        'file' => 'strongarm.admin.inc',
 111        'path' => drupal_get_path('module', 'strongarm'),
 112      ),
 113    );
 114  }
 115  
 116  /**
 117   * Implementation of hook_flush_caches().
 118   */
 119  function strongarm_flush_caches() {
 120    cache_clear_all('variables', 'cache');
 121    cache_clear_all('strongarm', 'cache');
 122  }
 123  
 124  /**
 125   * Implementation of hook_schema_alter().
 126   * Makes the variables table usable by ctools' export.inc.
 127   */
 128  function strongarm_schema_alter(&$schema) {
 129    $schema['variable']['export'] = array(
 130      'key' => 'name',
 131      'identifier' => 'strongarm',
 132      'default hook' => 'strongarm',
 133      'api' => array(
 134        'owner' => 'strongarm',
 135        'api' => 'strongarm',
 136        'minimum_version' => 1,
 137        'current_version' => 1,
 138      ),
 139    );
 140    $schema['variable']['fields']['value']['serialize'] = TRUE;
 141  }
 142  
 143  /**
 144   * Implementation hook_help().
 145   */
 146  function strongarm_help($path, $arg) {
 147    switch ($path) {
 148      case 'admin/help#strongarm':
 149        $output = file_get_contents(drupal_get_path('module', 'strongarm') .'/README.txt');
 150        return module_exists('markdown') ? filter_xss_admin(module_invoke('markdown', 'filter', 'process', 0, -1, $output)) : '<pre>'. check_plain($output) .'</pre>';
 151      case 'admin/settings/strongarm':
 152        return '<p>'. t("Strongarm lets site builders manage default variable settings. All the default values provided by Strongarm are listed on this page. Any overridden value can be reverted to its default by selecting its checkbox and clicking 'Reset to defaults'.") .'</p>';
 153    }
 154  }
 155  
 156  /**
 157   * Load all variables (DB and Strongarmed).
 158   */
 159  function strongarm_vars_load($sorted = TRUE, $reset = FALSE) {
 160    ctools_include('export');
 161    static $vars;
 162  
 163    // Ensure that the schema cache is not stale when trying to load.
 164    $schema = drupal_get_schema('variable');
 165    if (!isset($schema['export']) || $reset) {
 166      ctools_export_load_object_reset('variable');
 167      drupal_get_schema('variable', TRUE);
 168    }
 169  
 170    // Load vars.
 171    if (!isset($vars) || $reset) {
 172      $vars = ctools_export_load_object('variable');
 173      if ($sorted) {
 174        ksort($vars);
 175      }
 176    }
 177    return $vars;
 178  }
 179  
 180  /**
 181   * Implementation of hook_features_revert().
 182   */
 183  if (!function_exists('variable_features_revert')) {
 184    function variable_features_revert($module) {
 185      ctools_component_features_revert('variable', $module);
 186      cache_clear_all('variables', 'cache');
 187    }
 188  }
 189  
 190  /**
 191   * Implementation of hook_features_pipe_alter() for node component.
 192   * Add node type variables on behalf of core modules.
 193   */
 194  function strongarm_features_pipe_node_alter(&$pipe, $data, $export, $module_name) {
 195    if (!empty($data)) {
 196      $variables = array(
 197        'comment',
 198        'comment_anonymous',
 199        'comment_controls',
 200        'comment_default_mode',
 201        'comment_default_order',
 202        'comment_default_per_page',
 203        'comment_form_location',
 204        'comment_preview',
 205        'comment_subject_field',
 206        'language_content_type',
 207        'node_options',
 208        'upload',
 209      );
 210      foreach ($data as $node_type) {
 211        foreach ($variables as $variable_name) {
 212          $pipe['variable'][] = "{$variable_name}_{$node_type}";
 213        }
 214      }
 215    }
 216  }


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