? aliasing.patch ? generate-content.php ? pathalias.patch ? includes/null.patch ? modules/cck ? modules/devel ? sites/dharmapop.com ? sites/metta.godhead.net Index: database/database.mysql =================================================================== RCS file: /cvs/drupal/drupal/database/database.mysql,v retrieving revision 1.185 diff -U3 -r1.185 database.mysql --- database/database.mysql 8 May 2005 19:11:31 -0000 1.185 +++ database/database.mysql 9 May 2005 04:08:53 -0000 @@ -484,7 +484,8 @@ src varchar(128) NOT NULL default '', dst varchar(128) NOT NULL default '', PRIMARY KEY (pid), - UNIQUE KEY dst (dst) + UNIQUE KEY dst (dst), + KEY src (src) ) TYPE=MyISAM; -- Index: database/database.pgsql =================================================================== RCS file: /cvs/drupal/drupal/database/database.pgsql,v retrieving revision 1.122 diff -U3 -r1.122 database.pgsql --- database/database.pgsql 8 May 2005 19:11:31 -0000 1.122 +++ database/database.pgsql 9 May 2005 04:08:53 -0000 @@ -499,6 +499,7 @@ PRIMARY KEY (pid) ); CREATE INDEX url_alias_dst_idx ON url_alias(dst); +CREATE INDEX url_alias_src_idx ON url_alias(src); -- -- Table structure for permission -- Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.46 diff -U3 -r1.46 bootstrap.inc --- includes/bootstrap.inc 12 Apr 2005 16:55:11 -0000 1.46 +++ includes/bootstrap.inc 9 May 2005 04:08:53 -0000 @@ -405,30 +405,46 @@ /** * Return an array mapping path aliases to their internal Drupal paths. */ -function drupal_get_path_map($action = '') { - static $map = NULL; +function drupal_get_path_map($action = '', $path = '') { + static $map = array(); if ($action == 'rebuild') { - $map = NULL; + $map = array(); } - - if (is_null($map)) { - $map = array(); // Make $map non-null in case no aliases are defined. - $result = db_query('SELECT * FROM {url_alias}'); - while ($data = db_fetch_object($result)) { + elseif ($action == 'src') { + if ($alias = array_search($path, $map)) { + return $alias; + } + elseif ($data = db_fetch_object(db_query("SELECT * FROM {url_alias} WHERE src = '%s'", $path))) { + $map[$data->dst] = $data->src; + return $data->dst; + } + else { + $map[$path] = $path; + } + } + elseif ($action == 'alias') { + if ($map[$path]) { + return $map[$path]; + } + elseif ($data = db_fetch_object(db_query("SELECT * FROM {url_alias} WHERE dst = '%s'", $path))) { $map[$data->dst] = $data->src; + return $data->src; + } + else { + $map[$path] = $path; } } - return $map; + return FALSE; } /** * Given an internal Drupal path, return the alias set by the administrator. */ function drupal_get_path_alias($path) { - if (($map = drupal_get_path_map()) && ($newpath = array_search($path, $map))) { - return $newpath; + if ($alias = drupal_get_path_map('src', $path)) { + return $alias; } elseif (function_exists('conf_url_rewrite')) { return conf_url_rewrite($path, 'outgoing'); Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.440 diff -U3 -r1.440 common.inc --- includes/common.inc 7 May 2005 01:48:06 -0000 1.440 +++ includes/common.inc 9 May 2005 04:08:54 -0000 @@ -90,8 +90,8 @@ * Given a path alias, return the internal path it represents. */ function drupal_get_normal_path($path) { - if (($map = drupal_get_path_map()) && isset($map[$path])) { - return $map[$path]; + if ($src = drupal_get_path_map('alias', $path)) { + return $src; } elseif (function_exists('conf_url_rewrite')) { return conf_url_rewrite($path, 'incoming'); @@ -1531,7 +1531,7 @@ * An HTML string ready for insertion in a tag. */ function drupal_attributes($attributes = array()) { - if ($attributes) { + if (is_array($attributes)) { $t = array(); foreach ($attributes as $key => $value) { $t[] = $key .'="'. check_plain($value) .'"'; Index: modules/path.module =================================================================== RCS file: /cvs/drupal/drupal/modules/path.module,v retrieving revision 1.57 diff -U3 -r1.57 path.module --- modules/path.module 24 Apr 2005 16:34:34 -0000 1.57 +++ modules/path.module 9 May 2005 04:08:55 -0000 @@ -132,11 +132,9 @@ function path_set_alias($path = NULL, $alias = NULL, $pid = NULL) { if ($path && !$alias) { db_query("DELETE FROM {url_alias} WHERE src = '%s'", $path); - drupal_rebuild_path_map(); } else if (!$path && $alias) { db_query("DELETE FROM {url_alias} WHERE dst = '%s'", $alias); - drupal_rebuild_path_map(); } else if ($path && $alias) { $path_count = db_result(db_query("SELECT COUNT(src) FROM {url_alias} WHERE src = '%s'", $path)); @@ -145,7 +143,6 @@ // We have an insert: if ($path_count == 0 && $alias_count == 0) { db_query("INSERT INTO {url_alias} (src, dst) VALUES ('%s', '%s')", $path, $alias); - drupal_rebuild_path_map(); } else if ($path_count >= 1 && $alias_count == 0) { if ($pid) { @@ -154,11 +151,9 @@ else { db_query("INSERT INTO {url_alias} (src, dst) VALUES ('%s', '%s')", $path, $alias); } - drupal_rebuild_path_map(); } else if ($path_count == 0 && $alias_count == 1) { db_query("UPDATE {url_alias} SET src = '%s' WHERE dst = '%s'", $path, $alias); - drupal_rebuild_path_map(); } else if ($path_count == 1 && $alias_count == 1) { // This will delete the path that alias was originally pointing to: