theme_get_setting
- Versions
- 4.6 – 6
theme_get_setting($setting_name,$refresh= FALSE)- 7
theme_get_setting($setting_name, $theme = NULL)
Retrieve a setting for the current theme or for a given theme.
The final setting is arrived at by merging the default settings, the custom theme settings defined in the theme's .info file, the site-wide settings, and the settings defined for the specific theme. If an empty string is given for $key, only the site-wide theme defaults are retrieved.
The default values for each setting is defined in this function. To add new settings, add their default values here, and then add form elements to system_theme_settings() in system.admin.inc.
Parameters
$setting_name The name of the setting to be retrieved.
$theme The name of a given theme; defaults to the current theme.
Return value
The value of the requested setting, NULL if the setting does not exist.
Code
includes/theme.inc, line 1135
<?php
function theme_get_setting($setting_name, $theme = NULL) {
$cache = &drupal_static(__FUNCTION__, array());
// If no key is given, use the current theme if we can determine it.
if (is_null($theme)) {
$theme = !empty($GLOBALS['theme_key']) ? $GLOBALS['theme_key'] : '';
}
if (empty($cache[$theme])) {
// Set the default settings.
$cache[$theme] = array(
'default_logo' => 1,
'logo_path' => '',
'default_favicon' => 1,
'favicon_path' => '',
// Use the IANA-registered MIME type for ICO files as default.
'favicon_mimetype' => 'image/vnd.microsoft.icon',
'main_menu' => 1,
'secondary_menu' => 1,
'toggle_logo' => 1,
'toggle_favicon' => 1,
'toggle_name' => 1,
'toggle_slogan' => 1,
'toggle_node_user_picture' => 1,
'toggle_comment_user_picture' => 1,
'toggle_comment_user_verification' => 1,
'toggle_main_menu' => 1,
'toggle_secondary_menu' => 1,
);
// Get the default values for the custom settings from the .info file.
if ($theme) {
$themes = list_themes();
$theme_object = $themes[$theme];
// Create a list which includes the current theme and all its base themes.
if (isset($theme_object->base_themes)) {
$theme_keys = array_keys($theme_object->base_themes);
$theme_keys[] = $theme;
}
else {
$theme_keys = array($theme);
}
foreach ($theme_keys as $theme_key) {
if (!empty($themes[$theme_key]->info['settings'])) {
$cache[$theme] = array_merge($cache[$theme], $themes[$theme_key]->info['settings']);
}
}
}
// Get the saved global settings from the database.
$cache[$theme] = array_merge($cache[$theme], variable_get('theme_settings', array()));
if ($theme) {
// Get the saved theme settings from the database.
$cache[$theme] = array_merge($cache[$theme], variable_get('theme_' . $theme . '_settings', array()));
// Generate the path to the logo image.
if ($cache[$theme]['toggle_logo']) {
if ($cache[$theme]['default_logo']) {
$cache[$theme]['logo'] = file_create_url(dirname($theme_object->filename) . '/logo.png');
}
elseif ($cache[$theme]['logo_path']) {
$cache[$theme]['logo'] = file_create_url($cache[$theme]['logo_path']);
}
}
// Generate the path to the favicon.
if ($cache[$theme]['toggle_favicon']) {
if ($cache[$theme]['default_favicon']) {
if (file_exists($favicon = dirname($theme_object->filename) . '/favicon.ico')) {
$cache[$theme]['favicon'] = file_create_url($favicon);
}
else {
$cache[$theme]['favicon'] = file_create_url('misc/favicon.ico');
}
}
elseif ($cache[$theme]['favicon_path']) {
$cache[$theme]['favicon'] = file_create_url($cache[$theme]['favicon_path']);
}
else {
$cache[$theme]['toggle_favicon'] = FALSE;
}
}
}
}
return isset($cache[$theme][$setting_name]) ? $cache[$theme][$setting_name] : NULL;
}
?>Login or register to post comments 