Index: domain/API.php
===================================================================
RCS file: /cvs/drupal/contributions/modules/domain/API.php,v
retrieving revision 1.23.2.10
diff -u -p -r1.23.2.10 API.php
--- domain/API.php	10 Oct 2008 18:25:54 -0000	1.23.2.10
+++ domain/API.php	5 Jan 2009 02:56:25 -0000
@@ -478,3 +478,24 @@ function hook_domainignore() {
   // User login should always be from the current domain.
   return array('user_login');
 }
+
+/**
+ * Allows modules to alter path when rewriting URLs.
+ *
+ * This hook will fire for all paths and may be resource-intensive.
+ * Look at Domain Prefix for best practices implementation. In Domain
+ * Prefix, we only include this function if we know it is necessary.
+ *
+ * @see domain_prefix_init()
+ *
+ * @param $domain_id
+ *  The domain_id taken from {domain}.
+ * @param $path
+ *  The internal drupal path to the node.
+ *
+ * @ingroup domain_hooks
+ */
+function hook_domainpath($domain_id, &$path) {
+  // Give a normal path alias
+  $path = drupal_get_path_alias($path);
+}
Index: domain/domain.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/domain/domain.module,v
retrieving revision 1.40.2.26
diff -u -p -r1.40.2.26 domain.module
--- domain/domain.module	20 Nov 2008 23:38:41 -0000	1.40.2.26
+++ domain/domain.module	5 Jan 2009 02:56:02 -0000
@@ -593,7 +593,18 @@ function domain_get_path($domain) {
  * Determine an absolute path to the current page
  */
 function domain_get_uri($domain) {
-  $path = $domain['scheme'] .'://'. $domain['subdomain'] . request_uri();
+  $request_uri = request_uri();
+  
+  $modules = _domain_path_modules();
+  if (!empty($modules)) {
+    // If needed, let modules modify the path alias.
+    $path = $_GET['q'];
+    $alias = domain_path($domain['domain_id'], $path);
+    $request_uri = base_path() . $alias;
+  }
+  
+  $path = $domain['scheme'] .'://'. $domain['subdomain'] . $request_uri;
+  
   return $path;
 }
 
@@ -1444,3 +1455,36 @@ function domain_node_access_explain($row
   }
   return $return;
 }
+
+/**
+ * Helper function for passing hook_domainpath() by reference.
+ *
+ * @param $domain_id
+ * The domain_id taken from {domain}.
+ * @param $path
+ * The internal drupal path to the node.
+ * @return
+ * The $path, modified by reference by hook_domainpath() implementations.
+ */
+function domain_path($domain_id, $path) {
+  $modules = _domain_path_modules();
+  if (!empty($modules)) {
+    foreach ($modules as $module) {
+      // Cannot use module_invoke_all() since these are passed by reference.
+      $function = $module .'_domainpath';
+      $function($domain_id, $path, $path_language);
+    }
+  }
+  return $path;
+}
+
+/**
+ * Helper function for domain_path() checks.
+ */
+function _domain_path_modules() {
+  static $modules;
+  if (!isset($modules)) {
+    $modules = module_implements('domainpath');
+  }
+  return $modules;
+}
Index: domain/settings_custom_url.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/domain/settings_custom_url.inc,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 settings_custom_url.inc
--- domain/settings_custom_url.inc	11 Sep 2008 13:35:22 -0000	1.1.2.4
+++ domain/settings_custom_url.inc	5 Jan 2009 03:22:56 -0000
@@ -19,7 +19,7 @@ function custom_url_rewrite_outbound(&$p
   // If the domain_id is not set, then the Domain module is not active, and we cannot run this function.
   if (isset($_domain['domain_id'])) {
     // Set static variables for the node lookups, to remove redundant queries.
-    static $domain_site, $domain, $nodepaths;
+    static $domain_site, $domain, $nodepaths, $path_rewrite;
 
     // Check to see that this function is installed.
     $skip = FALSE;
@@ -98,10 +98,18 @@ function custom_url_rewrite_outbound(&$p
         // Only needed if we are not on the default source domain.
         else if ($root != -1 && $seo && $_domain['domain_id'] != $root['domain_id']) {
           $absolute = TRUE;
-            // In this case, the $base_url cannot have a trailing slash
-            $base_url = rtrim($root['path'], '/');
+          // In this case, the $base_url cannot have a trailing slash
+          $base_url = rtrim($root['path'], '/');
         }
       }
+      // We may have to implement hook_domainpath().
+      if (!isset($path_rewrite)) {
+        $path_rewrite = count(_domain_path_modules());
+      }
+      // Allow path changes, if needed.
+      if ($path_rewrite > 0 && $path != '') {
+        $path = domain_path($target_domain_id, $original_path);
+      }
     }
   }
 }
Index: domain/domain_prefix/domain_prefix.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/domain/domain_prefix/domain_prefix.module,v
retrieving revision 1.12.2.3
diff -u -p -r1.12.2.3 domain_prefix.module
--- domain/domain_prefix/domain_prefix.module	4 Jul 2008 19:21:01 -0000	1.12.2.3
+++ domain/domain_prefix/domain_prefix.module	5 Jan 2009 05:17:45 -0000
@@ -26,6 +26,18 @@ define(DOMAIN_PREFIX_DROP, 8);
 define(DOMAIN_PREFIX_UPDATE, 16);
 
 /**
+ * Implements hook_init().
+ *
+ * Check for prefixes of the url_alias table, and if present add hook_domainprefix().
+ */
+function domain_prefix_init() {
+  $count = db_result(db_query("SELECT COUNT(*) FROM {domain_prefix} WHERE status > 1 AND tablename = 'url_alias'"));
+  if (!empty($count)) {
+    include 'domain_prefix.path.inc';
+  }
+}
+
+/**
  * Implements hook_menu()
  */
 function domain_prefix_menu($may_cache) {
@@ -454,17 +466,7 @@ function domain_prefix_form($domain_id, 
  *   The name of the table being acted upon.
  */
 function domain_prefix_table_exists($prefix, $table) {
-  global $db_type;
-  $string = db_escape_table($prefix . $table);
-  switch ($db_type) {
-    case 'pgsql':
-      $query = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name = '{%s}'";
-      break;
-    default:
-      $query = "SHOW TABLES LIKE '{%s}'";
-      break;
-  }
-  return db_num_rows(db_query($query, $string));
+  return db_table_exists($prefix . $table);
 }
 
 /**
Index: domain/domain_prefix/domain_prefix.path.inc
===================================================================
RCS file: domain/domain_prefix/domain_prefix.path.inc
diff -N domain/domain_prefix/domain_prefix.path.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ domain/domain_prefix/domain_prefix.path.inc	5 Jan 2009 05:06:15 -0000
@@ -0,0 +1,54 @@
+<?php
+// $Id
+
+/**
+ * @file
+ * Implements hook_domainpath().
+ * This is a resource-intensive function, so we only include it
+ * if an alias of the {url_alias} table is present.
+ */
+
+/**
+ * Implements hook_domainpath().
+ */
+function domain_prefix_domainpath($domain_id, &$path) {
+  global $_domain;
+  // $map[$domain_id] keys are Drupal paths and the values are the corresponding aliases
+  static $map = array(), $count = array(), $status = array(), $tablename = array();
+
+  // If the alias is for the current domain, do nothing.
+  if ($domain_id == $_domain['domain_id']) {
+    $path = drupal_get_path_alias($path);
+    return;
+  }
+
+  // The default domain does not use a prefix.
+  if ($domain_id == 0 && !isset($status[0])) {
+    $status[0] = db_table_exists('url_alias');
+    $tablename[0] = 'url_alias';
+  }
+
+  // Check to see if table prefixing has been done for the {url_alias} table.
+  if (!isset($status[$domain_id])) {
+    $prefix = domain_prefix_string($domain_id);
+    $status[$domain_id] = domain_prefix_table_exists($prefix, 'url_alias');
+    $tablename[$domain_id] = $prefix .'url_alias';
+  }
+
+  if (!$status[$domain_id]) {
+    return;
+  }
+
+  // Use $count[$domain_id] to avoid looking up paths in subsequent calls if there are no aliases
+  if (!isset($count[$domain_id])) {
+    $count[$domain_id] = db_result(db_query('SELECT COUNT(pid) FROM {%s}', $tablename[$domain_id]));
+  }
+  
+  if ($count[$domain_id] > 0) {
+    if (!isset($map[$domain_id][$path])) {
+      $alias = db_result(db_query("SELECT dst FROM {%s} WHERE src = '%s'", $tablename[$domain_id], $path));
+      $map[$domain_id][$path] = $alias ? $alias : $path;
+    }
+    $path = $map[$domain_id][$path];
+  }
+}
