? 319876-views.patch
? 412078-d6-user.patch
? 412078-domain-user.patch
? 419012-search.patch
? 424830-domain-prefix-table.patch
? 427258-domain-validate.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	8 Apr 2009 14:20:22 -0000
@@ -412,24 +412,21 @@ function domain_create_form($form_state,
     '#description' => t('Must be set to "Active" for users to navigate to this domain.')
   );
   $form['submit'] = array('#type' => 'submit', '#value' => t('Create domain record'));
+  $form['#validate'][] = 'domain_form_validate';
   return $form;
 }
 
 /**
- * FormsAPI for domain_create_form()
+ * FormsAPI for domain_{create/edit}_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.'));
+function domain_form_validate($form, &$form_state) {
+  $domain = strtolower(urlencode($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.'));
   }
-  $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.'));
+  if ($domain_changed && !domain_unique_domain($domain)) {
+    form_set_error('subdomain', t('The domain value must be unique.'));
   }
 }
 
@@ -529,28 +526,13 @@ function domain_edit_form($form_state, $
     '#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';
   return $form;
 }
 
 /**
  * FormsAPI for domain_edit_form()
  */
-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.'));
-  }
-  $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.'));
-  }
-}
-
-/**
- * FormsAPI for domain_edit_form()
- */
 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.
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	8 Apr 2009 14:20:24 -0000
@@ -605,6 +605,32 @@ 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) {
+  $pattern = '/^([a-z0-9]([-a-z0-9]*[a-z0-9])?\.)+((a[cdefgilmnoqrstuwxz]|aero|arpa)|(b[abdefghijmnorstvwyz]|biz)|(c[acdfghiklmnorsuvxyz]|cat|com|coop)|d[ejkmoz]|(e[ceghrstu]|edu)|f[ijkmor]|(g[abdefghilmnpqrstuwy]|gov)|h[kmnrtu]|(i[delmnoqrst]|info|int)|(j[emop]|jobs)|k[eghimnprwyz]|l[abcikrstuvy]|(m[acdghklmnopqrstuvwxyz]|mil|mobi|museum)|(n[acefgilopruz]|name|net)|(om|org)|(p[aefghklmnrstwy]|pro)|qa|r[eouw]|s[abcdeghijklmnortvyz]|(t[cdfghjklmnoprtvwz]|travel)|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw])$/i';
+  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
