Index: settings_custom_url.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/domain/settings_custom_url.inc,v
retrieving revision 1.7
diff -u -r1.7 settings_custom_url.inc
--- settings_custom_url.inc	6 Jul 2008 21:16:39 -0000	1.7
+++ settings_custom_url.inc	2 Sep 2008 06:18:34 -0000
@@ -93,6 +93,9 @@
             if (isset($source)) {
               $seo = FALSE;
             }
+            if (function_exists('domain_prefix_get_path_alias')) {
+              $path = domain_prefix_get_path_alias($domain[$nid]['domain_id'], $original_path, isset($options['language']) ? $options['language']->language : '');
+            }
           }
         }
         // If strict SEO rules are enabled, we set "all affiliate" links to the root domain.
@@ -101,8 +104,80 @@
           $options['absolute'] = TRUE;
           // In this case, the $base_url cannot have a trailing slash
           $options['base_url'] = rtrim($root['path'], '/');
+          if (function_exists('domain_prefix_get_path_alias')) {
+            $path = domain_prefix_get_path_alias($root['domain_id'], $original_path, isset($options['language']) ? $options['language']->language : '');
+          }
         }
       }
     }
   }
 }
+
+/**
+ * Given an internal Drupal path, return the alias set by the administrator.
+ *
+ * @param $domain_id
+ * The domain_id taken from {domain}.
+ * @param $path
+ * The path to investigate for corresponding aliases or system URLs. 
+ * @param $path_language
+ * An optional language code to look up the path in.
+ */
+function domain_prefix_get_path_alias($domain_id, $path, $path_language = '') {
+  $result = $path;
+  if ($alias = domain_prefix_lookup_path($domain_id, $path, $path_language)) {
+    $result = $alias;
+  }
+  return $result;
+}
+
+/**
+ * Given a Drupal system URL return one of its aliases if such a one exists. Otherwise, return FALSE. 
+ *
+ * @param $domain_id
+ * The domain_id taken from {domain}.
+ * @param $path
+ * The path to investigate for corresponding aliases or system URLs.
+ * @param $path_language
+ * An optional language code to look up the path in.
+ */
+function domain_prefix_lookup_path($domain_id, $path = '', $path_language = '') {
+  global $language;
+
+  // $map[$domain_id] keys are Drupal paths and the values are the corresponding aliases
+  static $map = array(), $count = array(), $status = array();
+  $tablename = 'url_alias';
+
+  $path_language = $path_language ? $path_language : $language->language;
+
+  if (!isset($status[$domain_id])) {
+    $status[$domain_id] = db_result(db_query("SELECT status FROM {domain_prefix} WHERE domain_id = %d AND tablename = '%s'", $domain_id, $tablename));
+
+    // Table creation sequence has not run for this domain or the domain is primary domain.
+    if (!$status[$domain_id]) {
+      $status[$domain_id] = DOMAIN_PREFIX_IGNORE;
+    }
+  }
+
+  // If the url_alias table is prefixed, get the prefixed table name.
+  if ($status[$domain_id] > DOMAIN_PREFIX_IGNORE) {
+    $tablename = 'domain_'. $domain_id .'_'. $tablename;
+  }
+
+  // Use $count[$domain_id] to avoid looking up paths in subsequent calls if there simply are no aliases
+  if (!isset($count[$domain_id])) {
+    $count[$domain_id] = db_result(db_query('SELECT COUNT(pid) FROM {%s}', $tablename));
+  }
+  
+  if ($count[$domain_id] > 0 && $path != '') {
+    if (isset($map[$domain_id][$path_language][$path])) {
+      return $map[$domain_id][$path_language][$path];
+    } else {
+      $alias = db_result(db_query("SELECT dst FROM {%s} WHERE src = '%s'", $tablename, $path));
+      $map[$domain_id][$path_language][$path] = $alias;
+      return $alias;
+    }
+  }
+
+  return FALSE;
+}

