diff --git a/alias/hosting_alias.drush.inc b/alias/hosting_alias.drush.inc index af4a473..441cd17 100644 --- a/alias/hosting_alias.drush.inc +++ b/alias/hosting_alias.drush.inc @@ -6,6 +6,7 @@ function drush_hosting_alias_pre_hosting_task() { $task =& drush_get_context('HOSTING_TASK'); if (($task->ref->type == 'site') && (in_array($task->task_type, array('install', 'verify', 'migrate')))) { $task->options['aliases'] = implode(",", hosting_alias_get_aliases($task->ref)); + $task->options['redirection'] = db_result(db_query("SELECT redirection FROM {hosting_site_alias} WHERE vid=%d", $task->ref->vid)); } } } diff --git a/alias/hosting_alias.install b/alias/hosting_alias.install index 4ee1361..062cb71 100644 --- a/alias/hosting_alias.install +++ b/alias/hosting_alias.install @@ -28,6 +28,12 @@ function hosting_alias_schema() { 'not null' => TRUE, 'default' => 0, ), + 'redirection' => array( + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), ), 'indexes' => array( 'vid' => array('vid'), @@ -58,3 +64,12 @@ function hosting_alias_update_1() { return $ret; } +/** + * Add the redirection field + */ +function hosting_alias_update_2() { + $ret = array(); + db_add_field($ret, 'hosting_site_alias', 'redirection', array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny')); + return $ret; +} + diff --git a/alias/hosting_alias.module b/alias/hosting_alias.module index c97f83f..947cc8a 100644 --- a/alias/hosting_alias.module +++ b/alias/hosting_alias.module @@ -44,6 +44,12 @@ function hosting_alias_form_alter(&$form, $form_state, $form_id) { '#description' => t('Your site can also be accessed through these domain names. This field requires each domain alias to be on its own line'), '#default_value' => implode("\n", (array) $form['#node']->aliases) ); + $form['redirection'] = array( + '#type' => 'checkbox', + '#title' => t('Redirection'), + '#description' => t('Aliases will all be redirected to the main domain if this is checked. Otherwise, all aliases will be accessible transparently.'), + '#default_value' => isset($form['#node']->redirection) ? $form['#node']->redirection : variable_get('hosting_alias_redirection', FALSE), + ); } } } @@ -82,13 +88,13 @@ function hosting_alias_insert($node) { if (is_array($aliases)) { foreach ($aliases as $alias) { if (($alias = trim($alias)) && !in_array($alias, $automatic)) { - db_query("INSERT INTO {hosting_site_alias} (vid, nid, alias, automatic) VALUES (%d, %d, '%s', %d)", $node->vid, $node->nid, $alias, HOSTING_ALIAS_CUSTOM); + db_query("INSERT INTO {hosting_site_alias} (vid, nid, alias, automatic, redirection) VALUES (%d, %d, '%s', %d, %d)", $node->vid, $node->nid, $alias, HOSTING_ALIAS_CUSTOM, $node->redirection); } } } if (sizeof($automatic)) { foreach ($automatic as $alias) { - db_query("INSERT INTO {hosting_site_alias} (vid, nid, alias, automatic) VALUES (%d, %d, '%s', %d)", $node->vid, $node->nid, $alias, HOSTING_ALIAS_AUTOMATIC); + db_query("INSERT INTO {hosting_site_alias} (vid, nid, alias, automatic, redirection) VALUES (%d, %d, '%s', %d, %d)", $node->vid, $node->nid, $alias, HOSTING_ALIAS_AUTOMATIC, $node->redirection); } } } @@ -140,6 +146,11 @@ function hosting_alias_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { } break; case 'load': + // XXX: this returns only the first redirection status. it + // works since they are all set to the same in hook_insert(), + // but we should return an associative alias => redirection + // array instead + $additions['redirection'] = db_result(db_query("SELECT redirection FROM {hosting_site_alias} WHERE vid=%d", $node->vid)); // Only retrieves custom aliases, as they are all that can be modified. $additions['aliases'] = hosting_alias_get_aliases($node, HOSTING_ALIAS_CUSTOM); return $additions; @@ -157,6 +168,13 @@ function hosting_alias_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { '#value' => implode(', ', $links), '#weight' => 10, ); + $redirection = db_result(db_query("SELECT redirection FROM {hosting_site_alias} WHERE vid=%d", $node->vid)); + $node->content['info']['redirection'] = array( + '#type' => 'item', + '#title' => t('Redirection'), + '#value' => $redirection['redirection'] ? t('Yes') : t('No'), + '#weight' => 10, + ); } break; } @@ -192,6 +210,12 @@ function hosting_alias_settings() { '#description' => t('If a domain name starts with www., automatically create an alias for domain.com?'), '#default_value' => variable_get('hosting_alias_automatic_no_www', FALSE) ); + $form['hosting_alias_redirection'] = array( + '#type' => 'checkbox', + '#title' => t('Use redirects instead of aliases by default'), + '#description' => t('By default, the aliasing system generates aliases in the webserver configuration and creates symlinks in the sites/ directory, point site aliases to the primary domain. The aliasing system can also redirect instead of aliasing, which means all site aliases will redirect the user to the primary domain instead of delivering the primary domain under a symlinked site alias. Note that this setting can be controlled per site. Setting this option here will make redirection the default behavior for site aliases.'), + '#default_value' => variable_get('hosting_alias_redirection', FALSE) + ); return system_settings_form($form); }