array( 'name' => t('Theme'), 'description' => t('Select a different theme and/or change template-specific settings. After choosing or changing the theme, first save the form and then return to set any theme-specific settings.'), ), ); } function virtual_site_theme_feature_form($context) { global $custom_theme, $conf; $themes = system_theme_data(); $options = array('' => t('(skip this feature)')); foreach ($themes as $key => $data) { if ($data->status) { $options[$key] = $data->info['name']; } } $form['theme'] = array( '#title' => t('Theme'), '#description' => t('The theme to use for this site.'), '#type' => 'select', '#options' => $options, '#default_value' => $context['theme'], ); if ($context['theme']) { // Copy default settings on first use if (!is_array($context['settings']) || !count($context['settings'])) { $context['settings'] = theme_get_settings($context['theme']); } // Handle uploads of the logo and favicon here, because system_theme_settings() will otherwise overwrite the default $directory_path = file_directory_path().'/theme'; file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path'); if ($file = file_save_upload('logo_upload', array('file_validate_is_image' => array()))) { $parts = pathinfo($file->filename); $filename = $directory_path.'/vs'.$context['sid'].'_logo.'. $parts['extension']; if (file_copy($file, $filename, FILE_EXISTS_REPLACE)) { $_POST['default_logo'] = 0; $_POST['logo_path'] = $file->filepath; $_POST['toggle_logo'] = 1; // If we don't unset the path system_theme_settings() will just redo all this and still overwrite. unset($file->filepath); } } if ($file = file_save_upload('favicon_upload')) { $parts = pathinfo($file->filename); $filename = $directory_path.'/vs'.$context['sid'].'_favicon.'. $parts['extension']; // If we don't move but copy the file, system_theme_settings() will just redo all this. if (file_copy($file, $filename, FILE_EXISTS_REPLACE)) { $_POST['default_favicon'] = 0; $_POST['favicon_path'] = $file->filepath; $_POST['toggle_favicon'] = 1; // If we don't unset the path system_theme_settings() will just redo all this and still overwrite. unset($file->filepath); } } // Temporarily relace the current settings by the ones of the virtual site. $var = 'theme_'.$context['theme'].'_settings'; $orig = $conf[$var]; $conf[$var] = $context['settings']; // Retrieve theme settings form include_once('modules/system/system.admin.inc'); $form_state = array('values' => $context); $form = array_merge($form, system_theme_settings($form_state, $context['theme'])); // Restore current settings $conf[$var] = $orig; // Unset unwanted form parts and errors unset($form['buttons'], $form['#submit'], $form['#theme']); unset($_SESSION['messages']); } return $form; } function virtual_site_theme_feature_submit($form, &$form_state) { $values = array( 'theme' => $form_state['values']['theme'], 'settings' => array(), ); if ($values['theme'] == $form['theme']['#default_value']) { $values['settings'] = $form_state['values']; unset($values['settings']['theme'],$values['settings']['var'], $values['settings']['op'], $values['settings']['submit'], $values['settings']['form_build_id'], $values['settings']['form_token'], $values['settings']['form_id']); } return $values; } function virtual_site_theme_feature($context) { global $custom_theme, $conf; if ($context['theme']) { $custom_theme = $context['theme']; } if (is_array($context['settings']) && count($context['settings'])) { $var = 'theme_'.$context['theme'].'_settings'; $conf[$var] = $context['settings']; } } ?>