system_theme_settings
modules/system/system.module, строка 1917
- Версии
- 5
system_theme_settings($key = '')
- 6
system_theme_settings(&$form_state, $key = '')
Menu callback; display theme configuration for entire site and individual themes.
Код
<?php
function system_theme_settings($key = '') {
$directory_path = file_directory_path();
file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
// Default settings are defined in theme_get_settings() in includes/theme.inc
if ($key) {
$settings = theme_get_settings($key);
$var = str_replace('/', '_', 'theme_'. $key .'_settings');
$themes = system_theme_data();
$features = function_exists($themes[$key]->prefix .'_features') ? call_user_func($themes[$key]->prefix .'_features') : array();
}
else {
$settings = theme_get_settings('');
$var = 'theme_settings';
}
$form['var'] = array('#type' => 'hidden', '#value' => $var);
// Check for a new uploaded logo, and use that instead.
if ($file = file_check_upload('logo_upload')) {
if ($info = image_get_info($file->filepath)) {
$parts = pathinfo($file->filename);
$filename = ($key) ? str_replace('/', '_', $key) .'_logo.'. $parts['extension'] : 'logo.'. $parts['extension'];
if ($file = file_save_upload('logo_upload', $filename, 1)) {
$_POST['default_logo'] = 0;
$_POST['logo_path'] = $file->filepath;
$_POST['toggle_logo'] = 1;
}
}
else {
form_set_error('file_upload', t('Only JPEG, PNG and GIF images are allowed to be used as logos.'));
}
}
// Check for a new uploaded favicon, and use that instead.
if ($file = file_check_upload('favicon_upload')) {
$parts = pathinfo($file->filename);
$filename = ($key) ? str_replace('/', '_', $key) .'_favicon.'. $parts['extension'] : 'favicon.'. $parts['extension'];
if ($file = file_save_upload('favicon_upload', $filename, 1)) {
$_POST['default_favicon'] = 0;
$_POST['favicon_path'] = $file->filepath;
$_POST['toggle_favicon'] = 1;
}
}
// Toggle settings
$toggles = array(
'toggle_logo' => t('Logo'),
'toggle_name' => t('Site name'),
'toggle_slogan' => t('Site slogan'),
'toggle_mission' => t('Mission statement'),
'toggle_node_user_picture' => t('User pictures in posts'),
'toggle_comment_user_picture' => t('User pictures in comments'),
'toggle_search' => t('Search box'),
'toggle_favicon' => t('Shortcut icon')
);
// Some features are not always available
$disabled = array();
if (!variable_get('user_pictures', 0)) {
$disabled['toggle_node_user_picture'] = TRUE;
$disabled['toggle_comment_user_picture'] = TRUE;
}
if (!module_exists('search')) {
$disabled['toggle_search'] = TRUE;
}
$form['theme_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Toggle display'),
'#description' => t('Enable or disable the display of certain page elements.'),
);
foreach ($toggles as $name => $title) {
if ((!$key) || in_array($name, $features)) {
// disable search box if search.module is disabled
$form['theme_settings'][$name] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => $settings[$name]);
if (isset($disabled[$name])) {
$form['theme_settings'][$name]['#disabled'] = TRUE;
}
}
}
// System wide only settings.
if (!$key) {
// Create neat 2-column layout for the toggles
$form['theme_settings'] += array(
'#prefix' => '<div class="theme-settings-left">',
'#suffix' => '</div>',
);
// Toggle node display.
$node_types = node_get_types('names');
if ($node_types) {
$form['node_info'] = array(
'#type' => 'fieldset',
'#title' => t('Display post information on'),
'#description' => t('Enable or disable the <em>submitted by Username on date</em> text when displaying posts of the following type.'),
'#prefix' => '<div class="theme-settings-right">',
'#suffix' => '</div>',
);
foreach ($node_types as $type => $name) {
$form['node_info']["toggle_node_info_$type"] = array('#type' => 'checkbox', '#title' => check_plain($name), '#default_value' => $settings["toggle_node_info_$type"]);
}
}
}
// Logo settings
if ((!$key) || in_array('toggle_logo', $features)) {
$form['logo'] = array(
'#type' => 'fieldset',
'#title' => t('Logo image settings'),
'#description' => t('If toggled on, the following logo will be displayed.'),
'#attributes' => array('class' => 'theme-settings-bottom'),
);
$form['logo']["default_logo"] = array(
'#type' => 'checkbox',
'#title' => t('Use the default logo'),
'#default_value' => $settings['default_logo'],
'#tree' => FALSE,
'#description' => t('Check here if you want the theme to use the logo supplied with it.')
);
$form['logo']['logo_path'] = array(
'#type' => 'textfield',
'#title' => t('Path to custom logo'),
'#default_value' => $settings['logo_path'],
'#description' => t('The path to the file you would like to use as your logo file instead of the default logo.'));
$form['logo']['logo_upload'] = array(
'#type' => 'file',
'#title' => t('Upload logo image'),
'#maxlength' => 40,
'#description' => t("If you don't have direct file access to the server, use this field to upload your logo.")
);
}
// Icon settings
if ((!$key) || in_array('toggle_favicon', $features)) {
$form['favicon'] = array(
'#type' => 'fieldset',
'#title' => t('Shortcut icon settings'),
'#description' => t("Your shortcut icon or 'favicon' is displayed in the address bar and bookmarks of most browsers.")
);
$form['favicon']['default_favicon'] = array(
'#type' => 'checkbox',
'#title' => t('Use the default shortcut icon.'),
'#default_value' => $settings['default_favicon'],
'#description' => t('Check here if you want the theme to use the default shortcut icon.')
);
$form['favicon']['favicon_path'] = array(
'#type' => 'textfield',
'#title' => t('Path to custom icon'),
'#default_value' => $settings['favicon_path'],
'#description' => t('The path to the image file you would like to use as your custom shortcut icon.')
);
$form['favicon']['favicon_upload'] = array(
'#type' => 'file',
'#title' => t('Upload icon image'),
'#description' => t("If you don't have direct file access to the server, use this field to upload your shortcut icon.")
);
}
if ($key) {
// Template-specific settings
$function = $themes[$key]->prefix .'_settings';
if (function_exists($function)) {
if ($themes[$key]->template) {
// file is a template or a style of a template
$form['specific'] = array('#type' => 'fieldset', '#title' => t('Engine-specific settings'), '#description' => t('These settings only exist for all the templates and styles based on the %engine theme engine.', array('%engine' => $themes[$key]->prefix)));
}
else {
// file is a theme or a style of a theme
$form['specific'] = array('#type' => 'fieldset', '#title' => t('Theme-specific settings'), '#description' => t('These settings only exist for the %theme theme and all the styles based on it.', array('%theme' => $themes[$key]->prefix)));
}
$group = $function();
$form['specific'] = array_merge($form['specific'], (is_array($group) ? $group : array()));
}
}
$form['#attributes'] = array('enctype' => 'multipart/form-data');
return system_settings_form($form);
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии