/[drupal]/contributions/modules/virtual_site/virtual_site_theme.module
ViewVC logotype

Contents of /contributions/modules/virtual_site/virtual_site_theme.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Sat Mar 8 16:46:38 2008 UTC (20 months, 3 weeks ago) by fokke
Branch: MAIN
CVS Tags: DRUPAL-6--1-1, DRUPAL-6--1-2, DRUPAL-6--1-3, HEAD
Changes since 1.3: +1 -5 lines
File MIME type: text/x-php
*** empty log message ***
1 <?php
2 // $Id: virtual_site_theme.module,v 1.2 2008/03/05 15:09:45 fokke Exp $
3
4 /**
5 * Implementation of hook_feature_info().
6 */
7 function virtual_site_theme_feature_info() {
8 return array(
9 'virtual_site_theme_feature' => array(
10 'name' => t('Theme'),
11 '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.'),
12 ),
13 );
14 }
15
16 function virtual_site_theme_feature_form($context) {
17 global $custom_theme, $conf;
18
19 $themes = system_theme_data();
20 $options = array('' => t('(skip this feature)'));
21
22 foreach ($themes as $key => $data) {
23
24 if ($data->status) {
25 $options[$key] = $data->info['name'];
26 }
27 }
28
29 $form['theme'] = array(
30 '#title' => t('Theme'),
31 '#description' => t('The theme to use for this site.'),
32 '#type' => 'select',
33 '#options' => $options,
34 '#default_value' => $context['theme'],
35 );
36
37 if ($context['theme']) {
38
39 // Copy default settings on first use
40 if (!is_array($context['settings']) || !count($context['settings'])) {
41 $context['settings'] = theme_get_settings($context['theme']);
42 }
43
44 // Handle uploads of the logo and favicon here, because system_theme_settings() will otherwise overwrite the default
45 $directory_path = file_directory_path().'/theme';
46 file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
47
48 if ($file = file_save_upload('logo_upload', array('file_validate_is_image' => array()))) {
49 $parts = pathinfo($file->filename);
50 $filename = $directory_path.'/vs'.$context['sid'].'_logo.'. $parts['extension'];
51
52 if (file_copy($file, $filename, FILE_EXISTS_REPLACE)) {
53 $_POST['default_logo'] = 0;
54 $_POST['logo_path'] = $file->filepath;
55 $_POST['toggle_logo'] = 1;
56
57 // If we don't unset the path system_theme_settings() will just redo all this and still overwrite.
58 unset($file->filepath);
59 }
60 }
61
62 if ($file = file_save_upload('favicon_upload')) {
63 $parts = pathinfo($file->filename);
64 $filename = $directory_path.'/vs'.$context['sid'].'_favicon.'. $parts['extension'];
65
66 // If we don't move but copy the file, system_theme_settings() will just redo all this.
67 if (file_copy($file, $filename, FILE_EXISTS_REPLACE)) {
68 $_POST['default_favicon'] = 0;
69 $_POST['favicon_path'] = $file->filepath;
70 $_POST['toggle_favicon'] = 1;
71
72 // If we don't unset the path system_theme_settings() will just redo all this and still overwrite.
73 unset($file->filepath);
74 }
75 }
76
77 // Temporarily relace the current settings by the ones of the virtual site.
78 $var = 'theme_'.$context['theme'].'_settings';
79 $orig = $conf[$var];
80 $conf[$var] = $context['settings'];
81
82 // Retrieve theme settings form
83 include_once('modules/system/system.admin.inc');
84 $form_state = array('values' => $context);
85 $form = array_merge($form, system_theme_settings($form_state, $context['theme']));
86
87 // Restore current settings
88 $conf[$var] = $orig;
89
90 // Unset unwanted form parts and errors
91 unset($form['buttons'], $form['#submit'], $form['#theme']);
92 unset($_SESSION['messages']);
93 }
94
95 return $form;
96 }
97
98 function virtual_site_theme_feature_submit($form, &$form_state) {
99 $values = array(
100 'theme' => $form_state['values']['theme'],
101 'settings' => array(),
102 );
103
104 if ($values['theme'] == $form['theme']['#default_value']) {
105 $values['settings'] = $form_state['values'];
106 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']);
107 }
108
109 return $values;
110 }
111
112 function virtual_site_theme_feature($context) {
113 global $custom_theme, $conf;
114
115 if ($context['theme']) {
116 $custom_theme = $context['theme'];
117 }
118
119 if (is_array($context['settings']) && count($context['settings'])) {
120 $var = 'theme_'.$context['theme'].'_settings';
121 $conf[$var] = $context['settings'];
122 }
123 }
124
125 ?>

  ViewVC Help
Powered by ViewVC 1.1.2