Index: includes/path.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/path.inc,v retrieving revision 1.16 diff -u -F^f -r1.16 path.inc --- includes/path.inc 18 Jun 2007 06:59:11 -0000 1.16 +++ includes/path.inc 28 Jun 2007 20:26:04 -0000 @@ -1,6 +1,10 @@ language; - // Use $count to avoid looking up paths in subsequent calls if there simply are no aliases + // Use $count to avoid looking up paths in subsequent calls if there simply are no aliases. if (!isset($count)) { $count = db_result(db_query('SELECT COUNT(pid) FROM {url_alias}')); } @@ -60,19 +64,50 @@ function drupal_lookup_path($action, $pa $no_src = array(); } elseif ($count > 0 && $path != '') { + static $optimization_type, $list; + + // Check if we should use the blacklist, the whitelist, or no optimization. + if (!isset($optimization_type)) { + $optimization_type = variable_get('path_optimization_type', PATH_OPTIMIZATION_BLACKLIST); + $list = variable_get('path_optimization_list', "admin* +*/add +*/edit +*/outline +*/revisions +*/track +book +comment/* +filter* +logout +poll +profile +tracker* +user +user/register +user/login"); + } + if ($action == 'alias') { if (isset($map[$path_language][$path])) { return $map[$path_language][$path]; } - // Get the most fitting result falling back with alias without language - $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language)); + // Get the most fitting result falling back with alias without language. + $query = "SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC"; + // In any of these cases, the path will be looked up, otherwise the + // alias will be set to FALSE: + // - optimization_type is PATH_OPTIMIZATION_NONE + // - optimization_type is PATH_OPTIMIZATION_BLACKLIST and the path + // that is being looked up did not match a path in the blacklist + // - optimization_type is PATH_OPTIMIZATION_WHITELIST and the path + // that is being looked up did match a path in the whitelist + $alias = ($optimization_type == PATH_OPTIMIZATION_NONE || drupal_path_match($path, $list) == $optimization_type) ? db_result(db_query($query, $path, $path_language)) : FALSE; $map[$path_language][$path] = $alias; return $alias; } // Check $no_src for this $path in case we've already determined that there - // isn't a path that has this alias + // isn't a path that has this alias. elseif ($action == 'source' && !isset($no_src[$path_language][$path])) { - // Look for the value $path within the cached $map + // Look for the value $path within the cached $map. $src = ''; if (!isset($map[$path_language]) || !($src = array_search($path, $map[$path_language]))) { // Get the most fitting result falling back with alias without language @@ -220,3 +255,23 @@ function drupal_is_front_page() { // we can check it against the 'site_frontpage' variable. return $_GET['q'] == drupal_get_normal_path(variable_get('site_frontpage', 'node')); } + +/** + * Check if a path matches a set of patterns. + * + * @param $path + * The path to match. + * @param $patterns + * String containing a set of patterns separated by \n, \r or \r\n. + * + * @return + * Boolean value: TRUE if the path matches a pattern, FALSE if otherwise. + */ +function drupal_path_match($path, $patterns) { + static $regexps; + + if (!isset($regexps[$patterns])) { + $regexps[$patterns] = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($patterns, '/')) .')$/'; + } + return preg_match($regexps[$patterns], $path); +} Index: modules/block/block.module =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.module,v retrieving revision 1.267 diff -u -F^f -r1.267 block.module --- modules/block/block.module 28 Jun 2007 00:39:47 -0000 1.267 +++ modules/block/block.module 28 Jun 2007 20:26:05 -0000 @@ -705,11 +705,10 @@ function block_list($region) { if ($block->pages) { if ($block->visibility < 2) { $path = drupal_get_path_alias($_GET['q']); - $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($block->pages, '/')) .')$/'; // Compare with the internal and path alias (if any). - $page_match = preg_match($regexp, $path); + $page_match = drupal_path_match($path, $block->pages); if ($path != $_GET['q']) { - $page_match = $page_match || preg_match($regexp, $_GET['q']); + $page_match = $page_match || drupal_path_match($_GET['q'], $block->pages); } // When $block->visibility has a value of 0, the block is displayed on // all pages except those listed in $block->pages. When set to 1, it