? 303406-domain-theme.patch
? 319876-views.patch
? 405148-domain-conf-2.patch
? 412078-d6-user.patch
? 412078-domain-user.patch
? 419012-search.patch
? 424830-domain-prefix-table.patch
? 427258-domain-form.patch
? 427258-forms.patch
Index: domain.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain.admin.inc,v
retrieving revision 1.23
diff -u -p -r1.23 domain.admin.inc
--- domain.admin.inc	25 Mar 2009 18:09:32 -0000	1.23
+++ domain.admin.inc	10 Apr 2009 13:55:58 -0000
@@ -347,120 +347,28 @@ function domain_configure_form_submit($f
     // MySQL won't let us insert row 0 into an autoincrement table.
     db_query("UPDATE {domain} SET domain_id = 0 WHERE subdomain = '%s'", $form_state['values']['domain_root']);
   }
+  // TODO: Run hook_domainupdate() on the primary domain?
 }
 
 /**
- * Create a new domain record
- */
-function domain_create() {
-  return drupal_get_form('domain_create_form');
-}
-
-/**
- * FormsAPI for creating domain records.
+ * Return an array of values suitable for both create and update sql statements
  *
- * @param $arguments
- *  An array of additional hidden key/value pairs to pass to the form.
- *  Used by child modules to control behaviors.
- *  Currently supported arguments are:
- *    'user_submitted' => TRUE
- *    Indicates that a form should not process administrative messages and paths
- *    upon form submit.  Used by the Domain User module.
- */
-function domain_create_form($form_state, $arguments = array()) {
-  $form = array();
-  // The $arguments arrray allows other modules to pass values to change the bahavior
-  // of submit and validate functions.
-  if (!empty($arguments)) {
-    $form['domain_arguments'] = array('#type' => 'value', '#value' => $arguments);
-  }
-  $form['domain'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('New domain record'),
-    '#collapsible' => TRUE
-  );
-  $form['domain']['subdomain'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Domain'),
-    '#size' => 40,
-    '#maxlength' => 80,
-    '#required' => TRUE,
-    '#description' => t('The allowed domain, using the full <em>path.example.com</em> format.  Can only contain lower-case alphanumeric characters.  Leave off the http:// and the trailing slash.')
-  );
-  $form['domain']['sitename'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Site name'),
-    '#size' => 40,
-    '#maxlength' => 80,
-    '#required' => TRUE,
-    '#description' => t('The human-readable name of this domain.')
-  );
-  $form['domain']['scheme'] = array(
-    '#type' => 'radios',
-    '#title' => t('Domain URL scheme'),
-    '#required' => TRUE,
-    '#options' => array('http' => 'http://', 'https' => 'https://'),
-    '#default_value' => 'http',
-    '#description' => t('The URL scheme for accessing this domain.')
-  );
-  $form['domain']['valid'] = array(
-    '#type' => 'radios',
-    '#title' => t('Domain status'),
-    '#required' => TRUE,
-    '#options' => array(1 => t('Active'), 0 => t('Inactive')),
-    '#default_value' => 1,
-    '#description' => t('Must be set to "Active" for users to navigate to this domain.')
-  );
-  $form['submit'] = array('#type' => 'submit', '#value' => t('Create domain record'));
-  return $form;
-}
-
-/**
- * FormsAPI for domain_create_form()
- */
-function domain_create_form_validate($form, &$form_state) {
-  // TODO: Make this a proper regex?
-  $subdomain = strtolower(urlencode($form_state['values']['subdomain']));
-  $check = 0;
-  $check = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE subdomain = '%s'", $subdomain));
-  if ($check > 0) {
-    form_set_error('subdomain', t('The domain value must be unique.'));
-  }
-  $check = 0;
-  $check = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE sitename = '%s'", $form_state['values']['sitename']));
-  if ($check > 0) {
-    form_set_error('sitename', t('The site name value must be unique.'));
-  }
-}
-
-/**
- * FormsAPI for domain_create_form()
- */
-function domain_create_form_submit($form, &$form_state) {
-  db_query("INSERT INTO {domain} (subdomain, sitename, scheme, valid) VALUES ('%s', '%s', '%s', %d)", $form_state['values']['subdomain'], $form_state['values']['sitename'], $form_state['values']['scheme'], $form_state['values']['valid']);
-  // Let other modules act.
-  $domain = domain_lookup(NULL, $form_state['values']['subdomain']);
-  module_invoke_all('domainupdate', 'create', $domain, $form_state);
-  // The user_submitted flag is needed for Domain User.
-  if (!isset($form_state['values']['domain_arguments']['user_submitted'])) {
-    drupal_set_message(t('Domain record created.'));
-    $form_state['redirect'] = 'admin/build/domain/view';
-  }
-}
-
-/**
- * Edit an existing domain record
+ * The last element on this array is ignored by the create sql because it has
+ * one fewer placeholder argument as it doesnt require a WHERE clause.
  *
- * @param $domain
- *  The $domain object created by domain_lookup().
- */
-function domain_edit($domain) {
-  if ($domain == -1) {
-    return t('Invalid page requested.');
-  }
-  // This action should be performed from the primary domain.
-  domain_check_primary();
-  return drupal_get_form('domain_edit_form', $domain);
+ * @param $form_state
+ *   From state from the submit_hook
+ * @return array
+ *   Array of domain values for insert and update sql operations
+ */
+function domain_values_from_form_state($form_state) {
+  return array(
+    'subdomain' => $form_state['values']['subdomain'],
+    'sitename'  => $form_state['values']['sitename'],
+    'scheme'    => $form_state['values']['scheme'],
+    'valid'     => $form_state['values']['valid'],
+    'domain_id' => $form_state['values']['domain_id'],
+  );
 }
 
 /**
@@ -478,9 +386,13 @@ function domain_edit($domain) {
  *    Indicates that a form should not process administrative messages and paths
  *    upon form submit.  Used by the Domain User module.
  */
-function domain_edit_form($form_state, $domain, $arguments = array()) {
-  if (empty($_POST)) {
-    domain_check_response($domain);
+function domain_form($form_state, $domain = array(), $arguments = array()) {
+  // This action should be performed from the primary domain unless overridden.
+  if (!isset($arguments['ignore_domain_status_check'])) {
+    domain_check_primary();
+    if (empty($_POST) && !empty($domain)) {
+      domain_check_response($domain);
+    }
   }
   $form = array();
   // The $arguments arrray allows other modules to pass values to change the bahavior
@@ -490,7 +402,7 @@ function domain_edit_form($form_state, $
   }
   $form['domain'] = array(
     '#type' => 'fieldset',
-    '#title' => t('Edit domain record'),
+    '#title' => t('Domain record'),
     '#collapsible' => TRUE
   );
   $form['domain_id'] = array('#type' => 'value', '#value' => $domain['domain_id']);
@@ -501,7 +413,7 @@ function domain_edit_form($form_state, $
     '#maxlength' => 80,
     '#required' => TRUE,
     '#default_value' => $domain['subdomain'],
-    '#description' => t('The allowed domain, using the full <em>path.example.com</em> format.  Can only contain lower-case alphanumeric characters.  Leave off the http:// and the trailing slash.')
+    '#description' => t('The allowed domain, using the full <em>path.example.com</em> format.  Can only contain lower-case alphanumeric characters, dashes and a colon (if using alternative ports).  Leave off the http:// and the trailing slash and do not include any paths.')
   );
   $form['domain']['sitename'] = array(
     '#type' => 'textfield',
@@ -517,7 +429,7 @@ function domain_edit_form($form_state, $
     '#title' => t('Domain URL scheme'),
     '#required' => TRUE,
     '#options' => array('http' => 'http://', 'https' => 'https://'),
-    '#default_value' => $domain['scheme'],
+    '#default_value' => !empty($domain['scheme']) ? $domain['scheme'] : 'http',
     '#description' => t('The URL scheme for accessing this domain.')
   );
   $form['domain']['valid'] = array(
@@ -525,62 +437,65 @@ function domain_edit_form($form_state, $
     '#title' => t('Domain status'),
     '#required' => TRUE,
     '#options' => array(1 => t('Active'), 0 => t('Inactive')),
-    '#default_value' => $domain['valid'],
+    '#default_value' => !empty($domain['valid']) ? $domain['valid'] : 1,
     '#description' => t('Must be set to "Active" for users to navigate to this domain.')
   );
   $form['submit'] = array('#type' => 'submit', '#value' => t('Save domain record'));
+  $form['#validate'][] = 'domain_form_validate';
+  $form['#redirect'] = array('admin/build/domain/view');
   return $form;
 }
 
 /**
- * FormsAPI for domain_edit_form()
+ * Implementation of domain_form validate hook.
  */
-function domain_edit_form_validate($form, &$form_state) {
-  // TODO: Make this a proper regex
-  $subdomain = strtolower(urlencode($form_state['values']['subdomain']));
-  $check = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE subdomain = '%s' AND domain_id <> %d", $subdomain, $form_state['values']['domain_id']));
-  if ($check) {
-    form_set_error('subdomain', t('The domain value must be unique.'));
+function domain_form_validate($form, &$form_state) {
+  $domain = strtolower($form_state['values']['subdomain']);
+  $domain_changed = (bool) strcmp($form_state['values']['subdomain'], $form['domain']['subdomain']['#default_value']);
+  if (!domain_valid_domain($domain)) {
+    form_set_error('subdomain', t('The domain value must be valid.'));
   }
-  $check2 = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE sitename = '%s' AND domain_id <> %d", $form_state['values']['sitename'], $form_state['values']['domain_id']));
-  if ($check2) {
-    form_set_error('sitename', t('The site name value must be unique.'));
+  if ($domain_changed && !domain_unique_domain($domain)) {
+    form_set_error('subdomain', t('The domain value must be unique.'));
   }
 }
 
 /**
- * FormsAPI for domain_edit_form()
+ * Implementation of domain_form submit hook.
  */
-function domain_edit_form_submit($form, &$form_state) {
-  db_query("UPDATE {domain} SET subdomain = '%s', sitename = '%s', scheme = '%s', valid = %d WHERE domain_id = %d", $form_state['values']['subdomain'], $form_state['values']['sitename'], $form_state['values']['scheme'], $form_state['values']['valid'], $form_state['values']['domain_id']);
-  // Let other modules act.
-  $domain = domain_lookup($form_state['values']['domain_id']);
-  module_invoke_all('domainupdate', 'update', $domain, $form_state);
-  // The user_submitted flag is needed for Domain User.
-  if (empty($form_state['values']['domain_arguments']['user_submitted'])) {
-    drupal_set_message(t('Domain record updated.'));
-    $form_state['redirect'] = 'admin/build/domain/view';
+function domain_form_submit($form, &$form_state) {
+  // Populate sql values used in both queries.
+  $values = domain_values_from_form_state($form_state);
+
+  // Update or create a new domain depending on presence of domain_id.
+  if ($values['domain_id']) {
+    $sql = "UPDATE {domain} SET subdomain = '%s', sitename = '%s', scheme = '%s', valid = %d WHERE domain_id = %d";
+    $action = 'update';
+    $message = t('Domain record updated.');
+  }
+  else {
+    $sql = "INSERT INTO {domain} (subdomain, sitename, scheme, valid) VALUES ('%s', '%s', '%s', %d)";
+    $action = 'create';
+    $message = t('Domain record created.');
   }
-}
 
-/**
- * Delete a domain record.
- *
- * @param $domain
- * An array containing the record from the {domain} table.
- */
-function domain_delete($domain) {
-  if ($domain == -1) {
-    return t('Invalid page requested.');
+  // Update the record.
+  db_query($sql, $values);
+
+  // Let other modules act.
+  $domain = domain_lookup(NULL, $values['subdomain']);
+  module_invoke_all('domainupdate', $action, $domain, $form_state);
+
+  // Hide the message for the Domain User module.
+  if (empty($form_state['values']['domain_arguments']['user_submitted'])) {
+    drupal_set_message($message);
   }
-  // This action should be performed from the primary domain.
-  domain_check_primary();
-  return drupal_get_form('domain_delete_form', $domain);
 
+  return $domain;
 }
 
 /**
- * FormsAPI
+ * Implementation of domain_delete_form.
  *
  * @param $form_state
  *    The current form state, passed by FormsAPI.
@@ -594,7 +509,10 @@ function domain_delete($domain) {
  *      Indicates that a form should not process administrative messages and paths
  *      upon form submit.  Used by the Domain User module.
  */
-function domain_delete_form($form_state, $domain, $argumants = array()) {
+function domain_delete_form($form_state, $domain, $arguments = array()) {
+  // This action should be performed from the primary domain.
+  domain_check_primary();
+
   $form = array();
   // The $arguments arrray allows other modules to pass values to change the bahavior
   // of submit and validate functions.
@@ -602,22 +520,29 @@ function domain_delete_form($form_state,
     $form['domain_arguments'] = array('#type' => 'value', '#value' => $arguments);
   }
   $form['domain_id'] = array('#type' => 'value', '#value' => $domain['domain_id']);
-  $form['domain'] = array('#value' => t('<p>Are you sure you wish to delete the domain record for <b>%domain</b>?</p>', array('%domain' => $domain['subdomain'])));
-  $form['cancel'] = array('#value' => '<p>'. l(t('Cancel action'), 'admin/build/domain') .'<br />');
-  $form['submit'] = array('#type' => 'submit', '#value' => t('Delete domain record'), '#suffix' => '<p>');
-  return $form;
+
+  return confirm_form(
+    $form,
+    t('Are you sure you wish to delete the domain record for <strong>%domain</strong>?', array('%domain' => $domain['subdomain'])),
+    'admin/build/domain/view',
+    NULL,
+    t('Delete domain record'),
+    'Cancel'
+    );
 }
 
 /**
- * FormsAPI for domain_delete_form()
+ * Implementation of domain_delete_form submit hook.
  */
 function domain_delete_form_submit($form, &$form_state) {
   // Run the lookup before we delete the row!
   $domain = domain_lookup($form_state['values']['domain_id']);
   db_query("DELETE FROM {domain} WHERE domain_id = %d", $form_state['values']['domain_id']);
+
   // Let other modules act.
   module_invoke_all('domainupdate', 'delete', $domain, $form_state);
-  // The user_submitted flag is needed for Domain User.
+
+  // Hide the message from the Domain User module.
   if (empty($form_state['values']['domain_arguments']['user_submitted'])) {
     drupal_set_message(t('Domain record deleted.'));
     $form_state['redirect'] = 'admin/build/domain/view';
@@ -625,23 +550,14 @@ function domain_delete_form_submit($form
 }
 
 /**
- * Advanced node-type settings
- */
-function domain_advanced() {
-  $node_types = node_get_types('names');
-  return drupal_get_form('domain_advanced_form', $node_types);
-}
-
-/**
- * FormsAPI
+ * Implementation of domain_advanced_form.
  *
  * @param $form_state
  * The current form state, passed by FormsAPI.
- * @param $node_types
- *  A list of active node types taken from node_get_types().
  */
-function domain_advanced_form($form_state, $node_types) {
+function domain_advanced_form($form_state) {
   $form = array();
+  $node_types = node_get_types('names');
   $default = variable_get('domain_behavior', DOMAIN_INSTALL_RULE);
   $form['domain_node'] = array(
     '#type' => 'fieldset',
Index: domain.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain.module,v
retrieving revision 1.104
diff -u -p -r1.104 domain.module
--- domain.module	7 Apr 2009 15:41:39 -0000	1.104
+++ domain.module	10 Apr 2009 13:56:00 -0000
@@ -99,23 +99,23 @@ function domain_menu() {
   $items['admin/build/domain'] = array(
     'title' => 'Domains',
     'access arguments' => array('administer domains'),
-    'page callback' => 'domain_configure',
+    'page callback' => 'domain_view',
     'file' => 'domain.admin.inc',
-    'description' => 'Settings for the Domain Access module.'
+    'description' => 'Settings for the Domain Access module.',
   );
-  $items['admin/build/domain/settings'] = array(
-    'title' => 'Settings',
+  $items['admin/build/domain/view'] = array(
+    'title' => 'Domain list',
     'access arguments' => array('administer domains'),
     'type' => MENU_DEFAULT_LOCAL_TASK,
-    'page callback' => 'domain_configure',
+    'page callback' => 'domain_view',
     'file' => 'domain.admin.inc',
     'weight' => -10
   );
-  $items['admin/build/domain/view'] = array(
-    'title' => 'Domain list',
+  $items['admin/build/domain/settings'] = array(
+    'title' => 'Settings',
     'access arguments' => array('administer domains'),
     'type' => MENU_LOCAL_TASK,
-    'page callback' => 'domain_view',
+    'page callback' => 'domain_configure',
     'file' => 'domain.admin.inc',
     'weight' => -8
   );
@@ -123,7 +123,8 @@ function domain_menu() {
     'title' => 'Create domain record',
     'access arguments' => array('administer domains'),
     'type' => MENU_LOCAL_TASK,
-    'page callback' => 'domain_create',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('domain_form'),
     'file' => 'domain.admin.inc',
     'weight' => -7
     );
@@ -131,7 +132,8 @@ function domain_menu() {
     'title' => 'Node settings',
     'access arguments' => array('administer domains'),
     'type' => MENU_LOCAL_TASK,
-    'page callback' => 'domain_advanced',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('domain_advanced_form'),
     'file' => 'domain.admin.inc',
     'weight' => -6
   );
@@ -172,16 +174,16 @@ function domain_menu() {
     'title' => 'Edit domain record',
     'access arguments' => array('administer domains'),
     'type' => MENU_CALLBACK,
-    'page callback' => 'domain_edit',
-    'page arguments' => array(4),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('domain_form', 4),
     'file' => 'domain.admin.inc',
   );
   $items['admin/build/domain/delete/%domain'] = array(
     'title' => 'Delete domain record',
     'access arguments' => array('administer domains'),
     'type' => MENU_CALLBACK,
-    'page callback' => 'domain_delete',
-    'page arguments' => array(4),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('domain_delete_form', 4),
     'file' => 'domain.admin.inc',
   );
   return $items;
@@ -457,12 +459,18 @@ function domain_cron() {
  * valid records.
  *
  * @param $domain_id
- * The id request for a specific domain.
+ *   The id request for a specific domain.
  * @return
- * The $domain array from domain_domainload() or -1 on failure.
+ *   TRUE on success or FALSE on failure.
  */
 function domain_load($domain_id = NULL) {
-  return domain_lookup($domain_id);
+  $domain = domain_lookup($domain_id);
+  if ($domain == -1) {
+    return FALSE;
+  }
+  else {
+    return $domain;
+  }
 }
 
 /**
@@ -605,6 +613,36 @@ function _domain_rurl_sort($a, $b) {
 }
 
 /**
+ * Validate the domain against all known valid TLDs.
+ *
+ * @param $domain
+ *   Domain to check.
+ * @return bool
+ *   TRUE if valid; FALSE if invalid.
+ */
+function domain_valid_domain($domain) {
+  // Only one colon is allowed.
+  if (substr_count($domain, ':') > 1) {
+    return FALSE;
+  }
+  $pattern = '/[a-z0-9\.\+\-:]*$/';
+  return (bool) preg_match($pattern, $domain);
+}
+
+/**
+ * Validate the domain against existing domains.
+ *
+ * @param $domain
+ *   Domain to check
+ * @return bool
+ *   TRUE if unique; FALSE if duplicate.
+ */
+function domain_unique_domain($domain) {
+  $count = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE subdomain = '%s'", $domain));
+  return !(bool) $count;
+}
+
+/**
  * Get the domains a user is assigned to.
  *
  * @param $account
@@ -974,7 +1012,7 @@ function domain_node_access_records($nod
     // And the currently active domain.
     $node->domains = array($_domain['domain_id'] => $_domain['domain_id']);
   }
-  
+
   // If the form is hidden, we are passed the 'domains_raw' variable.
   // We need to append unique values from this variable to the existing
   // stored values.  See the logic for 'view domain publshing' in domain_form_alter().
Index: domain_user/domain_user.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain_user/domain_user.module,v
retrieving revision 1.25
diff -u -p -r1.25 domain_user.module
--- domain_user/domain_user.module	7 Apr 2009 15:41:39 -0000	1.25
+++ domain_user/domain_user.module	10 Apr 2009 13:56:01 -0000
@@ -158,7 +158,7 @@ function domain_user_user($op, &$edit, &
       // TODO: Maybe we should set a message here.
       if ($domain == -1 && domain_lookup(NULL, $name .'.'. $root) == -1) {
         $create_domain = variable_get('domain_user', 0);
-        if (user_access('create personal domain')) {
+        if (user_access('create personal domain', $account)) {
           if ($create_domain == 1 && !empty($root)) {
             $form['domain_user_domain']['domain_create_user'] = array(
               '#type' => 'value',
@@ -200,12 +200,12 @@ function domain_user_user($op, &$edit, &
         $domain = domain_user_lookup($account->uid);
         if ($domain == -1) {
           // Set arguments to be passed to the form
-          $arguments = array('user_submitted' => TRUE);
+          $arguments = array('user_submitted' => TRUE, 'ignore_domain_status_check' => TRUE);
           // Include the form file.
           include_once drupal_get_path('module', 'domain') .'/domain.admin.inc';
           // Set the scheme as needed.
           $form_state['values']['domain_scheme'] = variable_get('domain_user_scheme', 'http');
-          drupal_execute('domain_create_form', $form_state, $arguments);
+          drupal_execute('domain_form', $form_state, array(), $arguments);
           $domain = domain_lookup(NULL, $form_state['values']['subdomain'], TRUE);
           if ($domain['domain_id']) {
             db_query("INSERT INTO {domain_user} (domain_id, uid) VALUES (%d, %d)", $domain['domain_id'], $account->uid);
@@ -230,7 +230,7 @@ function domain_user_user($op, &$edit, &
         }
       }
       if (isset($edit['domain_create_user']) && !user_access('create personal domain', $account)) {
-        drupal_set_message(t('Your personal URL could not be created.'));
+        drupal_set_message(t('Your personal URL could not be created. 2'));
       }
       // Throw away what we do not need.
       $edit['domain_create_user'] = NULL;
