View source
<?php
define('STRONGARM_PATTERN_PREFIX', 0);
define('STRONGARM_PATTERN_SUFFIX', 1);
define('STRONGARM_MODE_STRONG', 0);
define('STRONGARM_MODE_WEAK', 1);
function strongarm_boot() {
$var_conf = strongarm_get_conf(FALSE);
strongarm_set_conf($var_conf);
}
function strongarm_init() {
$var_conf = strongarm_get_conf();
strongarm_set_conf($var_conf);
if ($_GET['q'] != 'admin/settings/strongarm' && variable_get('strongarm_mode', STRONGARM_MODE_STRONG) == STRONGARM_MODE_WEAK) {
$overridden = strongarm_overridden_vars();
if (arg(0) == 'admin' && !empty($overridden) && user_access('administer site configuration') && variable_get('strongarm_show_messages', TRUE)) {
drupal_set_message(t('The following variables have overridden values: !vars. Manage these variables on the !strongarm_page.', array(
'!vars' => implode(', ', $overridden),
'!strongarm_page' => l(t('Strongarm admin page'), 'admin/settings/strongarm'),
)), 'warning', FALSE);
}
}
}
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) {
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 {
$var_conf[$name] = $value;
}
}
else {
$var_conf[$name] = $value;
}
}
}
cache_set('strongarm', $var_conf);
}
}
return $var_conf;
}
function strongarm_set_conf($var_conf = array()) {
if (!empty($var_conf)) {
global $conf;
foreach ($var_conf as $k => $v) {
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;
}
}
}
}
function strongarm_overridden_vars($set = '') {
static $overridden = array();
if (!empty($set)) {
$overridden[$set] = $set;
}
return $overridden;
}
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;
}
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_messages', TRUE)) {
drupal_set_message(t('The highlighted fields 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);
if (user_access('administer site configuration')) {
drupal_set_message(t('You can change locked-in settings by switching to "Allow variable overrides" on the !admin_page.', array(
'!admin_page' => l(t('Strongarm admin page'), 'admin/settings/strongarm'),
)), 'warning', FALSE);
}
}
}
if ($form_id == 'system_module') {
strongarm_flush_caches();
}
}
function strongarm_theme() {
return array(
'strongarm_admin_form' => array(),
);
}
function strongarm_flush_caches() {
cache_clear_all('variables', 'cache');
cache_clear_all('strongarm', 'cache');
}