Index: API.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/API.php,v
retrieving revision 1.51.2.4
diff -u -r1.51.2.4 API.php
--- API.php	2 Mar 2010 20:38:24 -0000	1.51.2.4
+++ API.php	12 May 2010 00:27:23 -0000
@@ -785,3 +785,32 @@
     }
   }
 }
+
+/**
+ * Alter the validation step of a domain record.
+ *
+ * This hook allows modules to change or extend how domain validation
+ * happens. Most useful for international domains or other special cases
+ * where a site wants to restrict domain creation is some manner.
+ *
+ * NOTE: This does not apply to Domain Alias records.
+ *
+ * @param &$error_list
+ *   The list of current vaidation errors. Modify this value by reference.
+ *   If you return an empty array or NULL, the domain is considered valid.
+ * @param $subdomain
+ *   The HTTP_HOST string value being validated, such as one.example.com.
+ *   Note that this is checked for uniqueness separately. This value is not
+ *   modifiable.
+ * @return
+ *   No return value. Modify $error_list by reference. Return an empty array
+ *   or NULL to validate this domain.
+ *
+ * @see domain_valid_domain()
+ */
+function hook_domain_validate_alter(&$error_list, $subdomain) {
+  // Only allow TLDs to be .org for our site.
+  if (substr($subdomain, -4) != '.org') {
+    $error_list[] = t('Only .org domains may be registered.');
+  }
+}
Index: domain.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain.admin.inc,v
retrieving revision 1.41.2.7
diff -u -r1.41.2.7 domain.admin.inc
--- domain.admin.inc	7 May 2010 18:31:35 -0000	1.41.2.7
+++ domain.admin.inc	12 May 2010 00:35:16 -0000
@@ -457,6 +457,12 @@
     '#collapsible' => TRUE
   );
   $form['domain_id'] = array('#type' => 'value', '#value' => $domain['domain_id']);
+  if (!variable_get('domain_allow_non_ascii', FALSE)) {
+    $description = t('Can only contain lower-case alphanumeric characters, dashes and a colon (if using alternative ports).');
+  }
+  else {
+    $description = t('Can contain lower-case alphanumeric and ASCII characters, dashes and a colon (if using alternative ports).');
+  }
   $form['domain']['subdomain'] = array(
     '#type' => 'textfield',
     '#title' => t('Domain'),
@@ -464,7 +470,7 @@
     '#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, dashes and a colon (if using alternative ports).  Leave off the http:// and the trailing slash and do not include any paths.')
+    '#description' => t('The allowed domain, using the full <em>path.example.com</em> format. Leave off the http:// and the trailing slash and do not include any paths.') . ' ' . $description
   );
   $form['domain']['sitename'] = array(
     '#type' => 'textfield',
@@ -502,12 +508,17 @@
  */
 function domain_form_validate($form, &$form_state) {
   $subdomain = $form_state['values']['subdomain'];
+  $error_list = array();
   $domain_changed = (bool) strcmp($form_state['values']['subdomain'], $form['domain']['subdomain']['#default_value']);
-  if ($domain_changed) {
-    $error_list = domain_validate($subdomain);
-    foreach ($error_list as $error) {
-      form_set_error('subdomain', $error);
-    }
+  if ($domain_changed && !domain_unique_domain($subdomain)) {
+    $error_list[] = t('The domain value must be unique.');
+  }
+  $error = domain_valid_domain($subdomain);
+  if (!empty($error)) {
+    $error_list[] = $error;
+  }
+  foreach ($error_list as $error) {
+    form_set_error('subdomain', $error);
   }
 }
 
Index: domain.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain.install,v
retrieving revision 1.25.2.1
diff -u -r1.25.2.1 domain.install
--- domain.install	27 Apr 2010 23:02:40 -0000	1.25.2.1
+++ domain.install	12 May 2010 00:27:23 -0000
@@ -223,3 +223,23 @@
   $ret[] = update_sql("DELETE FROM {domain_editor} WHERE uid NOT IN (SELECT u.uid FROM {users} u)");
   return $ret;
 }
+
+/**
+ * Remove UPPERCASE from domain records.
+ *
+ * @link http://drupal.org/node/785818
+ */
+function domain_update_6206() {
+  $ret = array();
+  $result = db_query("SELECT domain_id, subdomain FROM {domain}");
+  while ($domain = db_fetch_array($result)) {
+    $string = drupal_strtolower($domain['subdomain']);
+    if ($string != $domain['subdomain']) {
+      db_query("UPDATE {domain} SET subdomain = '%s' WHERE domain_id = %d", $string, $domain['domain_id']);
+      if ($domain['domain_id'] == 0) {
+        variable_set('domain_root', $string);
+      }
+    }
+  }
+  return $ret;
+}
Index: domain.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain.module,v
retrieving revision 1.134.2.24
diff -u -r1.134.2.24 domain.module
--- domain.module	7 May 2010 18:31:35 -0000	1.134.2.24
+++ domain.module	12 May 2010 00:27:23 -0000
@@ -948,13 +948,22 @@
   if (substr($subdomain, -1) == '.') {
     $error_list[] = t('The domain must not end with a dot (.)');
   }
-  // Check for valid characters
+  // Check for valid characters, unless using non-ASCII domains.
+  if (!variable_get('domain_allow_non_ascii', FALSE)) {
   $pattern = '/^[a-z0-9\.\-:]*$/i';
   if (!preg_match($pattern, $subdomain)) {
     $error_list[] = t('Only alphanumeric characters, dashes, and a colon are allowed.');
   }
+  }
+  // Check for lower case.
+  if ($subdomain != drupal_strtolower($subdomain)) {
+    $error_list[] = t('Only lower-case characters are allowed.');
+  }
+  // Allow modules to alter this behavior.
+  drupal_alter('domain_validate', $error_list, $subdomain);
+  // Return the errors, if any.
   if (!empty($error_list)) {
-    return t('The domain string is invalid:') . theme('item_list', $error_list);
+    return t('The domain string is invalid for %subdomain:', array('%subdomain' => $subdomain)) . theme('item_list', $error_list);
   }
 }
 
@@ -2353,11 +2362,18 @@
   $batch = $values['domain_batch'];
   switch ($case) {
     case 'domain_root':
+      $errors = array();
       foreach ($batch as $key => $value) {
         $subdomain = strtolower(urlencode($value));
         $check = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE subdomain = '%s' AND domain_id <> %d", $value, $key));
         if ($check > 0 || ($key > 0 && $value == variable_get('domain_root', ''))) {
-          form_set_error('domain_batch', t('Each domain value must be unique.'));
+          form_set_error('domain_batch]['. $key, t('Each domain value must be unique.'));
+        }
+        else {
+          $error = domain_valid_domain($value);
+          if (!empty($error)) {
+            form_set_error('domain_batch]['. $key, $error);
+      }
         }
       }
       break;
@@ -2365,7 +2381,7 @@
       foreach ($batch as $key => $value) {
         $check = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE sitename = '%s' AND domain_id <> %d", $value, $key));
         if ($check > 0 || ($key > 0 && $value == variable_get('domain_sitename', 'Drupal'))) {
-          form_set_error('domain_batch', t('Each site name value must be unique.'));
+          form_set_error('domain_batch]['. $key, t('Each site name value must be unique.'));
         }
       }
       break;
@@ -2627,3 +2643,4 @@
   );
   return $return;
 }
+

