implode(', ', $overridden), '!strongarm_page' => l(t('Strongarm admin page'), 'admin/settings/strongarm'))), 'warning', FALSE); } } } /** * Retrieve variable configuration from the cache. */ function strongarm_get_conf($bootstrapped = TRUE, $reset = FALSE) { static $var_conf; if (!isset($var_conf) || $reset) { if (!$reset) { $cache = cache_get('strongarm', 'cache'); $var_conf = $cache ? $cache->data : NULL; } if (!isset($var_conf) && $bootstrapped) { // We don't use module_invoke_all() here since // array_merge_recursive() can alter the desired structure of // some variables. foreach (module_implements('strongarm') as $module) { $module_conf = module_invoke($module, 'strongarm'); foreach ($module_conf as $name => $value) { if (isset($var_conf[$name])) { if (is_array($value)) { $var_conf[$name] = array_merge($var_conf[$name], $value); } else { // Blow the earlier one away $var_conf[$name] = $value; } } else { $var_conf[$name] = $value; } } } cache_set('strongarm', $var_conf); } } return $var_conf; } /** * Sets the global configuration. When in Weakarm mode, will log any * values that have been overridden and leave their conf values alone. */ function strongarm_set_conf($var_conf = array()) { if (!empty($var_conf)) { global $conf; foreach ($var_conf as $k => $v) { // The variable is overridden -- let it be, but log the override if we are in Weakarm mode. if ((variable_get('strongarm_mode', STRONGARM_MODE_STRONG) == STRONGARM_MODE_WEAK) && isset($conf[$k]) && $conf[$k] != $v) { strongarm_overridden_vars($k); } else { $conf[$k] = $v; } } } } /** * Log overridden values. */ function strongarm_overridden_vars($set = '') { static $overridden = array(); if (!empty($set)) { $overridden[$set] = $set; } return $overridden; } /** * Implementation of hook_menu(). */ function strongarm_menu() { $items = array(); $items['admin/settings/strongarm'] = array( 'title' => 'Strongarm', 'description' => 'Manage Drupal variable settings that have been strongarmed.', 'page callback' => 'strongarm_admin_page', 'access callback' => 'user_access', 'access arguments' => array('administer site configuration'), 'file' => 'strongarm.admin.inc', 'type' => MENU_NORMAL_ITEM, ); return $items; } /** * Implementation of hook_form_alter(). */ function strongarm_form_alter(&$form, &$form_state, $form_id) { $pattern = ''; $position = STRONGARM_PATTERN_PREFIX; if (!empty($form['#submit']) && is_array($form['#submit']) && in_array('system_settings_form_submit', $form['#submit'])) { $lockdown = TRUE; } else if ($form_id == 'node_type_form') { $lockdown = TRUE; $pattern = $form['#node_type']->type; $position = STRONGARM_PATTERN_SUFFIX; } else if (arg(0) === 'admin' && $form_id != 'strongarm_admin_form') { $lockdown = TRUE; } if (!empty($lockdown) && variable_get('strongarm_mode', STRONGARM_MODE_STRONG) == STRONGARM_MODE_STRONG) { module_load_include('inc', 'strongarm', 'strongarm.admin'); drupal_add_css(drupal_get_path('module', 'strongarm') .'/strongarm.css'); if (_strongarm_lockdown($form, $pattern, $position) && variable_get('strongarm_show_message', TRUE)) { drupal_set_message(t('The hilighted fields below may need to retain their current values for your site to operate properly. Settings may be disabled or reverted automatically if they are not compatible with one or more of your site\'s modules.'), 'warning', FALSE); } } // Clear strongarm & variable caches on modules page. if ($form_id == 'system_module') { strongarm_flush_caches(); } } /** * Implementation of hook_theme(). */ function strongarm_theme() { return array( 'strongarm_admin_form' => array(), ); } /** * Implementation of hook_flush_caches(). */ function strongarm_flush_caches() { cache_clear_all('variables', 'cache'); cache_clear_all('strongarm', 'cache'); }