domain_theme.module
<?php
function domain_theme_init() {
global $_domain, $custom_theme;
if (empty($custom_theme)) {
$theme = domain_theme_lookup($_domain['domain_id']);
}
else {
$theme = domain_theme_lookup($_domain['domain_id'], $custom_theme);
}
if ($theme != -1) {
if (empty($custom_theme)) {
$custom_theme = $theme['theme'];
}
domain_theme_set_variables($theme);
}
}
function domain_theme_set_variables($theme) {
global $conf;
if (!empty($theme['settings'])) {
$settings = domain_unserialize($theme['settings']);
$conf['theme_'. $theme['theme'] .'_settings'] = $settings;
$vars = array('palette', 'stylesheets', 'logo', 'files', 'screenshot');
$palette_var = 'color_'. $theme['theme'] .'_palette';
if (!isset($settings[$palette_var])) {
if (isset($settings['palette'])) {
$conf[$palette_var] = $settings['palette'];
}
}
else {
foreach ($vars as $variable) {
$name = 'color_'. $theme['theme'] .'_'. $variable;
if (isset($settings[$name])) {
$conf[$name] = $settings[$name];
}
}
}
}
}
function domain_theme_menu() {
$items = array();
$items['admin/build/domain/theme/%domain'] = array(
'title' => 'Domain theme settings',
'type' => MENU_CALLBACK,
'access arguments' => array('administer domains'),
'page callback' => 'domain_theme_page',
'page arguments' => array(4),
'file' => 'domain_theme.admin.inc',
);
$items['admin/build/domain/theme-reset/%domain'] = array(
'title' => 'Domain theme settings',
'type' => MENU_CALLBACK,
'access arguments' => array('administer domains'),
'page callback' => 'domain_theme_reset',
'page arguments' => array(4),
'file' => 'domain_theme.admin.inc',
);
$items['admin/build/domain/theme/%/%domain/theme-settings'] = array(
'title' => 'Configure domain theme settings',
'type' => MENU_CALLBACK,
'access arguments' => array('administer domains'),
'page callback' => 'domain_theme_settings',
'page arguments' => array(4, 5),
'file' => 'domain_theme.admin.inc',
);
return $items;
}
function domain_theme_theme() {
$themes = array(
'domain_theme_reset' => array(
'arguments' => array('domain' => array()),
),
);
return $themes;
}
function domain_theme_lookup($domain_id, $theme = NULL, $reset = FALSE) {
if (!is_null($theme)) {
$return = db_fetch_array(db_query("SELECT domain_id, theme, settings, status FROM {domain_theme} WHERE domain_id = %d AND theme= '%s'", $domain_id, $theme));
}
else {
$return = db_fetch_array(db_query("SELECT domain_id, theme, settings, status FROM {domain_theme} WHERE domain_id = %d AND status = 1", $domain_id));
}
if (empty($return)) {
$return = -1;
}
return $return;
}
function domain_theme_domainlinks($domain) {
if ($domain['domain_id'] > 0) {
$links[] = array(
'title' => t('theme'),
'path' => 'admin/build/domain/theme/'. $domain['domain_id']
);
return $links;
}
return FALSE;
}
function domain_theme_domainform(&$form) {
$module_weight = variable_get('domain_theme_weight', 0);
db_query("UPDATE {system} SET weight = %d WHERE name = 'domain_theme' AND type = 'module'", $module_weight);
$form['domain_theme'] = array(
'#type' => 'fieldset',
'#title' => t('Theme settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE
);
$options = drupal_map_assoc(array(-100, -25, -10, -5, -1, 0, 1, 5, 10, 25, 100));
$form['domain_theme']['domain_theme_weight'] = array(
'#type' => 'select',
'#title' => t('Domain Theme execution order'),
'#options' => $options,
'#default_value' => $module_weight,
'#description' => t('If you use other modules that allow custom user or group themes, you may experience conflicts
with the Domain Theme module. Use this setting to vary the execution order of the Domain Theme module. Lower
(negative) values will execute earlier in the Drupal page building process.')
);
}
function domain_theme_domainbatch() {
$batch = array();
$batch['domain_theme'] = array(
'#form' => array(
'#title' => t('Reset themes'),
'#type' => 'checkbox',
'#options' => array(0 => 1, 1 => t('Reset')),
'#description' => t('Delete custom theme settings for this domain.'),
),
'#domain_action' => 'domain_delete',
'#system_default' => 0,
'#meta_description' => t('Delete custom theme settings for domains as supplied by Domain Theme.'),
'#table' => 'domain_theme',
'#weight' => -10,
);
$themes = list_themes();
$options = array();
foreach ($themes as $theme) {
if ($theme->status == 1) {
$options[$theme->name] = $theme->name;
}
}
$batch['site_theme'] = array(
'#form' => array(
'#title' => t('Theme settings'),
'#type' => 'select',
'#options' => $options,
'#description' => t('Select the theme for this domain.'),
),
'#domain_action' => 'custom',
'#lookup' => 'domain_theme_lookup',
'#submit' => 'domain_theme_batch',
'#system_default' => variable_get('theme_default', 'garland'),
'#variable' => 'theme_default',
'#meta_description' => t('Change the themes for all domains.'),
'#data_type' => 'string',
'#update_all' => TRUE,
'#weight' => -9,
);
foreach ($batch as $key => $value) {
$batch[$key]['#module'] = t('Domain Theme');
}
return $batch;
}
function domain_theme_batch($values) {
foreach ($values['domain_batch'] as $key => $value) {
if ($key > 0) {
db_query("UPDATE {domain_theme} SET status = 0 WHERE domain_id = %d", $key);
$data = db_fetch_array(db_query("SELECT theme FROM {domain_theme} WHERE theme = '%s' AND domain_id = %d", $value, $key));
if (isset($data['theme'])) {
db_query("UPDATE {domain_theme} SET status = 1 WHERE theme = '%s' AND domain_id = %d", $value, $key);
}
else {
db_query("INSERT INTO {domain_theme} (domain_id, theme, status) VALUES (%d, '%s', 1)", $key, $value);
}
}
else {
variable_set('theme_default', $value);
}
}
}
function domain_theme_domainwarnings() {
$forms = array(
'system_themes_form',
'system_theme_settings',
);
$return = array();
foreach ($forms as $form) {
$return[$form] = 'admin/build/domain/theme/%domain_id';
}
return $return;
}
function domain_theme_get_color_path($path) {
return current(array_slice(array_reverse(explode('/', $path)), 1, 1));
}