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

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

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


Revision 1.6 - (show annotations) (download) (as text)
Thu Mar 20 11:00:27 2008 UTC (20 months, 1 week ago) by fokke
Branch: MAIN
CVS Tags: DRUPAL-6--1-3, HEAD
Changes since 1.5: +4 -4 lines
File MIME type: text/x-php
- Fixed force base URL (did not work well with subdomains)
- Fixed features to only be called when they are set
- Fixed that frontpage settings was not enforced at all
1 <?php
2 // $Id: virtual_site_common.module,v 1.5 2008/03/19 18:43:27 fokke Exp $
3
4 /**
5 * Implementation of hook_feature_info().
6 */
7 function virtual_site_common_feature_info() {
8 return array(
9 'virtual_site_common_feature' => array(
10 'name' => t('Common'),
11 'description' => t('Set common settings for your virtual site, like the primary and secondary menu and language.'),
12 ),
13 );
14 }
15
16 function virtual_site_common_feature_form($context) {
17
18 $form['settings'] = array(
19 '#tree' => TRUE,
20 );
21
22 // Primary and secondary menu
23 $menu_options = menu_get_menus();
24 $primary = isset($context['menu_primary_links_source']) ? $context['menu_primary_links_source'] : variable_get('menu_primary_links_source', 'primary-links');
25 $primary_options = array_merge($menu_options, array('' => t('No primary links')));
26 $form['settings']['menu_primary_links_source'] = array(
27 '#type' => 'select',
28 '#title' => t('Source for the primary links'),
29 '#default_value' => $primary,
30 '#options' => $primary_options,
31 '#description' => t('Select what should be displayed as the primary links.'),
32 );
33 $secondary = isset($context['menu_secondary_links_source']) ? $context['menu_secondary_links_source'] : variable_get('menu_secondary_links_source', 'secondary-links');
34 $secondary_options = array_merge($menu_options, array('' => t('No secondary links')));
35 $form['settings']['menu_secondary_links_source'] = array(
36 '#type' => 'select',
37 '#title' => t('Source for the secondary links'),
38 '#default_value' => $secondary,
39 '#options' => $secondary_options,
40 '#description' => t('Select what should be displayed as the secondary links. You can choose the same menu for secondary links as for primary links. If you do this, the children of the active primary menu link will be displayed as secondary links.'),
41 );
42
43 // Language
44 $languages = language_list('enabled');
45 $languages = $languages[1];
46
47 foreach ($languages as $code => $language) {
48 $options[$code] = check_plain($language->name);
49 }
50
51 $form['settings']['language'] = array(
52 '#type' => 'select',
53 '#title' => t('Language'),
54 '#default_value' => isset($context['language']) ? $context['language'] : language_default('language'),
55 '#options' => $options,
56 '#description' => t('Select in what (enabled) language the site should be presented.'),
57 );
58
59 // Base URL
60 $form['settings']['base'] = array(
61 '#type' => 'textfield',
62 '#title' => t('Base URL'),
63 '#default_value' => isset($context['base']) ? $context['base'] : '',
64 '#description' => t('Force a certain base URL. For example force <code>http://example.com</code> for all visitors coming in on <code>http://www.example.com</code>. Of course it would be logical to make sure that this virtual site responds to both, otherwise it would just be a cheap redirection.'),
65 );
66
67 $form['#validate'][] = 'virtual_site_common_feature_validate';
68
69 return $form;
70 }
71
72 function virtual_site_common_feature_validate($form, &$form_state) {
73
74 if (!empty($form_state['values']['settings']['base'])) {
75 $url_parts = parse_url($form_state['values']['settings']['base']);
76
77 if (!is_array($url_parts) || !$url_parts['host']) {
78 form_set_error('base', t('Base URL is malformed.'));
79
80 } else {
81 $url = '';
82
83 $url .= $url_parts['scheme'] ? $url_parts['scheme'] : 'http';
84 $url .= '://'.$url_parts['host'];
85 $url .= (substr($url_parts['path'], -1) == '/') ? substr($url_parts['path'], 0, strlen($url_parts['path']) - 1) : $url_parts['path'];
86
87 form_set_value($form['settings']['base'], $url, $form_state);
88 }
89 }
90 }
91
92 function virtual_site_common_feature_submit($form, &$form_state) {
93 return $form_state['values']['settings'];
94 }
95
96 function virtual_site_common_feature($context) {
97 global $conf, $language, $base_url;
98
99 if (is_array($context) && count($context)) {
100
101 // Base URL
102 if ($context['base'] && $base_url != $context['base']) {
103 header("HTTP/1.1 301 Moved Permanently");
104 header("Location: ".$context['base'].$_SERVER['REQUEST_URI']);
105 header("Connection: close");
106 exit;
107 }
108
109 // Settings by variable
110 $conf = array_merge($conf, $context);
111
112 // Language
113 $languages = language_list('enabled');
114 $languages = $languages[1];
115
116 if (isset($languages[$context['language']])) {
117 $language = $languages[$context['language']];
118 }
119 }
120 }
121
122 ?>

  ViewVC Help
Powered by ViewVC 1.1.2