hosting_subdirs.module in Hosting 6.2
Same filename and directory in other branches
Allow sites to be installed in subdirectories.
File
subdirs/hosting_subdirs.moduleView source
<?php
/**
* @file
* Allow sites to be installed in subdirectories.
*/
/**
* Implements hook_form_alter().
*/
function hosting_subdirs_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'site_node_form') {
$form['aliases_wrapper']['#description'] .= 'Note: If the site is using a subdirectory, there should be at least one special alias with subdirectory path (e.g., example.com/foo) below. <strong>Note that subdomain (foo) and subdirectory name (foo) must be identical</strong>. Redirection to this alias will also work, if enabled. This is useful if you do not want the site to be accessible from its subdomain (e.g., foo.example.com). You can also add more standard aliases (e.g., bar.example.com, green.example.com).';
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function hosting_subdirs_form_site_node_form_alter(&$form, &$form_state) {
$form['title']['#description'] = 'Hint: To create a site using a subdirectory, name it using a subdomain (e.g., foo.example.com), and then enter an alias below for the desired subdirectory (e.g., example.com/foo). <strong>Note that subdomain (foo) and subdirectory name (foo) must be identical</strong>. If you plan to use also the root domain (e.g., example.com), you must create a site with the root domain *before* adding sites in its subdirectories. Note: Once the first site in a subdirectory is created and the parent site also exists, the parent site must be re-verified (just once) to turn on the web server configuration for the first (and any future) sites in its subdirectory. All sites sharing the same parent URL can use any profile, in any platform, and can be freely migrated, cloned, etc.';
}
/**
* Implementation of hook_nodeapi().
*/
function hosting_subdirs_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($node->type == 'site') {
switch ($op) {
case 'validate':
$aliases = $node->aliases;
$subdirs = array();
foreach ($aliases as $alias) {
// If we're adding a subdirectory alias, it can't begin with '/'.
if (@strpos($alias, '/', 1)) {
$subdirs[$alias] = explode('/', $alias, 2);
hosting_alias_validate_subdir($node, $alias);
// We only support one level of subdirectories, for now.
if (@strpos($subdirs[$alias][1], '/')) {
form_set_error('aliases', t('Multi-level subdirectories are not currently supported. Check the subdirectory for <em>@alias</em>, which is set to <em>@subdir</em>.', array(
'@alias' => $alias,
'@subdir' => $subdirs[$alias][1],
)));
}
}
else {
// No subdirectory in use, so validate normally.
hosting_alias_validate_alias($node, $alias);
}
}
break;
}
}
}
Functions
Name | Description |
---|---|
hosting_subdirs_form_alter | Implements hook_form_alter(). |
hosting_subdirs_form_site_node_form_alter | Implements hook_form_FORM_ID_alter(). |
hosting_subdirs_nodeapi | Implementation of hook_nodeapi(). |