? 733964-sort-current.patch
? 761556-domain-form.patch
? 785818-domain-batch.patch
? 793558-source-form.patch
Index: API.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/API.php,v
retrieving revision 1.60
diff -u -p -r1.60 API.php
--- API.php	6 Apr 2010 15:05:21 -0000	1.60
+++ API.php	17 May 2010 21:34:15 -0000
@@ -707,3 +707,32 @@ function hook_domain_settings($domain_id
     }
   }
 }
+
+/**
+ * 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: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/README.txt,v
retrieving revision 1.78
diff -u -p -r1.78 README.txt
--- README.txt	25 Apr 2010 21:58:33 -0000	1.78
+++ README.txt	17 May 2010 21:34:17 -0000
@@ -38,6 +38,8 @@ CONTENTS
 4.1.2   Site Name
 4.1.3   Domain URL Scheme
 4.2   Creating Domain Records
+4.2.1   Restricted Characters in Domains
+4.2.2   Altering Domain Name Validation
 4.3   Domain Module Behaviors
 4.3.1   New Content Settings
 4.3.2   Debugging Status
@@ -661,6 +663,40 @@ to help you debug your DNS configuration
 NOTE: Users who attempt to access an unregistered domain will be
 redirected to the primary domain automatically.
 
+----
+4.2.1  Restricted Characters in Domains
+
+When creating a domain record, you are restricted to the valid character set
+for Internet domain names.  By design, this includes only the ASCII 
+alphanumeric character set (a-z 0-9) plus the special characters dot (.)
+dash (-) and colon (:). A colon may only be followed by a port number.
+
+Domains must be lowercase. Domain matching with HTTP_HOST is not
+case-sensitive.
+
+With the advent of Internationalized Domain Names (IDNs), domain servers
+are beginning to recognize non-ASCII domain names. To enable support for
+non-ASCII domain names, you must add the following lines to the bottom
+of your settings.php file:
+
+  // Allow registration of non-ASCII domain strings.
+  $conf['domain_allow_non_ascii'] = TRUE;
+
+For background, see the following:
+
+  http://tools.ietf.org/html/rfc819
+  http://tools.ietf.org/html/rfc1035
+  http://en.wikipedia.org/wiki/Internationalized_domain_name
+  http://blog.icann.org/2010/05/idn-cctlds/
+
+----
+4.2.2   Altering Domain Name Validation
+
+If you wish to enforce special business rules for domain name validation,
+you may implement hook_domain_validate_alter() in your module.
+
+This hook will allow your module to intercept and alter any errors found
+by the normal domain validation process.  See API.php for details.
 
 ----
 4.3   Domain Module Behaviors
Index: domain.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain.admin.inc,v
retrieving revision 1.63
diff -u -p -r1.63 domain.admin.inc
--- domain.admin.inc	30 Apr 2010 17:20:58 -0000	1.63
+++ domain.admin.inc	17 May 2010 21:34:19 -0000
@@ -449,6 +449,12 @@ function domain_form($form, $form_state,
     '#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 lowercase alphanumeric characters, dashes and a colon (if using alternative ports).');
+  }
+  else {
+    $description = t('Can contain lowercase alphanumeric and ASCII characters, dashes and a colon (if using alternative ports).');
+  }
   $form['domain']['subdomain'] = array(
     '#type' => 'textfield',
     '#title' => t('Domain'),
@@ -456,7 +462,7 @@ function domain_form($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, 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',
@@ -494,12 +500,17 @@ function domain_form($form, $form_state,
  */
 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.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain.module,v
retrieving revision 1.187
diff -u -p -r1.187 domain.module
--- domain.module	4 May 2010 14:37:19 -0000	1.187
+++ domain.module	17 May 2010 21:34:22 -0000
@@ -1046,13 +1046,22 @@ function domain_valid_domain($subdomain)
   if (substr($subdomain, -1) == '.') {
     $error_list[] = t('The domain must not end with a dot (.)');
   }
-  // Check for valid characters
-  $pattern = '/^[a-z0-9\.\-:]*$/i';
-  if (!preg_match($pattern, $subdomain)) {
-    $error_list[] = t('Only alphanumeric characters, dashes, and a colon are allowed.');
+  // 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', array('items' => $error_list));
   }
 }
 
@@ -2497,12 +2506,19 @@ function domain_batch_validate($values) 
   $batch = $values['domain_batch'];
   switch ($case) {
     case 'domain_root':
+      $errors = array();
       foreach ($batch as $key => $value) {
         $subdomain = strtolower(urlencode($value));
         $check = db_query("SELECT COUNT(domain_id) FROM {domain} WHERE subdomain = :subdomain AND domain_id <> :domain_id",
           array(':subdomain' => $value, ':domain_id' => $key))->fetchField();
         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;
@@ -2511,7 +2527,7 @@ function domain_batch_validate($values) 
         $check = db_query("SELECT COUNT(domain_id) FROM {domain} WHERE sitename = :sitename AND domain_id <> :domain_id",
           array(':sitename' => $value, ':domain_id' => $key))->fetchField();
         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;
@@ -2817,3 +2833,4 @@ function domain_alter_node_query(QueryAl
     }
   }
 }
+
