<?php/**
* A more flexible version of core's semi-broken theme_get_setting().
*
* The setting is obtained from the first value found in the following sources:
* - the saved values from the theme's settings form
* - the saved values from the global theme settings form
* - the default theme-specific settings defined in the theme's .info file
*
* The list above will cycle through each connected sub-theme to their parents
* when the $get parameter is set to 'cascade'. theme_get_setting() is designed
* to fall back automatically but it is broken.
*
* @see theme_get_settings()
* http://api.drupal.org/api/search/7/theme_get_setting
* @see issue: inconsistent theme data
* http://drupal.org/node/761608
*
* @param $setting_name
* The name of the setting to be retrieved.
* @param $get
* (string) Can be a theme key which will restricted the setting to a
* specific theme. Using 'cascade' will check each theme until a value is
* found with sub-themes taking precedence. This value defaults to the active
* theme.
*/functiontheme_setting($setting_name,$get=NULL) {
$cache=&drupal_static(__FUNCTION__, array());if (!isset($get)) {
$get=$GLOBALS['theme_key'];
}
if (empty($cache)) {
$themes=list_themes();$active_theme=$GLOBALS['theme_key'];$active_themes=array();while (isset($active_theme)) {
$active_themes[$active_theme] =$active_theme;$active_theme=isset($themes[$active_theme]->base_theme) ? $themes[$active_theme]->base_theme : NULL;
}
foreach ($active_themesas$theme) {
$settings=variable_get('theme_'.$theme.'_settings', array());$settings+=variable_get('theme_settings', array());$settings+=isset($themes[$theme]->info['settings']) ? $themes[$theme]->info['settings'] : array();foreach ($settingsas$setting=>$value) {
$cache["$theme:$setting"] =$value;if (!isset($cache["cascade:$setting"]) &&isset($cache["$theme:$setting"])) {
$cache["cascade:$setting"] =$cache["$theme:$setting"];
}
}
}
}
returnisset($cache["$get:$setting_name"]) ? $cache["$get:$setting_name"] : NULL;
}