array( 'name' => t('Common'), 'description' => t('Set common settings for your virtual site, like the primary and secondary menu and language.'), ), ); } function virtual_site_common_feature_form($context) { $form['settings'] = array( '#tree' => TRUE, ); // Primary and secondary menu $menu_options = menu_get_menus(); $primary = isset($context['menu_primary_links_source']) ? $context['menu_primary_links_source'] : variable_get('menu_primary_links_source', 'primary-links'); $primary_options = array_merge($menu_options, array('' => t('No primary links'))); $form['settings']['menu_primary_links_source'] = array( '#type' => 'select', '#title' => t('Source for the primary links'), '#default_value' => $primary, '#options' => $primary_options, '#description' => t('Select what should be displayed as the primary links.'), ); $secondary = isset($context['menu_secondary_links_source']) ? $context['menu_secondary_links_source'] : variable_get('menu_secondary_links_source', 'secondary-links'); $secondary_options = array_merge($menu_options, array('' => t('No secondary links'))); $form['settings']['menu_secondary_links_source'] = array( '#type' => 'select', '#title' => t('Source for the secondary links'), '#default_value' => $secondary, '#options' => $secondary_options, '#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.'), ); // Language $languages = language_list('enabled'); $languages = $languages[1]; foreach ($languages as $code => $language) { $options[$code] = check_plain($language->name); } $form['settings']['language'] = array( '#type' => 'select', '#title' => t('Language'), '#default_value' => isset($context['language']) ? $context['language'] : language_default('language'), '#options' => $options, '#description' => t('Select in what (enabled) language the site should be presented.'), ); // Base URL $form['settings']['base'] = array( '#type' => 'textfield', '#title' => t('Base URL'), '#default_value' => isset($context['base']) ? $context['base'] : '', '#description' => t('Force a certain base URL. For example force http://example.com for all visitors coming in on http://www.example.com. Of course it would be logical to make sure that this virtual site responds to both, otherwise it would just be a cheap redirection.'), ); $form['#validate'][] = 'virtual_site_common_feature_validate'; return $form; } function virtual_site_common_feature_validate($form, &$form_state) { if (!empty($form_state['values']['settings']['base'])) { $url_parts = parse_url($form_state['values']['settings']['base']); if (!is_array($url_parts) || !$url_parts['host']) { form_set_error('base', t('Base URL is malformed.')); } else { $url = ''; $url .= $url_parts['scheme'] ? $url_parts['scheme'] : 'http'; $url .= '://'.$url_parts['host']; $url .= (substr($url_parts['path'], -1) == '/') ? substr($url_parts['path'], 0, strlen($url_parts['path']) - 1) : $url_parts['path']; form_set_value($form['settings']['base'], $url, $form_state); } } } function virtual_site_common_feature_submit($form, &$form_state) { return $form_state['values']['settings']; } function virtual_site_common_feature($context) { global $conf, $language, $base_url; if (is_array($context) && count($context)) { // Base URL if ($context['base'] && $base_url != $context['base']) { header("HTTP/1.1 301 Moved Permanently"); header("Location: ".$context['base'].$_SERVER['REQUEST_URI']); header("Connection: close"); exit; } // Settings by variable $conf = array_merge($conf, $context); // Language $languages = language_list('enabled'); $languages = $languages[1]; if (isset($languages[$context['language']])) { $language = $languages[$context['language']]; } } } ?>