Index: includes/path.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/path.inc,v retrieving revision 1.13 diff -u -p -r1.13 path.inc --- includes/path.inc 23 Dec 2006 22:04:52 -0000 1.13 +++ includes/path.inc 3 Jan 2007 17:04:29 -0000 @@ -54,11 +54,18 @@ function drupal_lookup_path($action, $pa $no_src = array(); } elseif ($count > 0 && $path != '') { + static $skiplist; + + // Use $skiplist to avoid retrieving the skiplist every time in subsequent calls + if (!isset($skiplist)) { + $skiplist = variable_get('path_skiplist', ''); + } + if ($action == 'alias') { if (isset($map[$path])) { return $map[$path]; } - $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path)); + $alias = drupal_path_match_patterns($path, $skiplist) ? FALSE : db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path)); $map[$path] = $alias; return $alias; } @@ -67,7 +74,10 @@ function drupal_lookup_path($action, $pa elseif ($action == 'source' && !isset($no_src[$path])) { // Look for the value $path within the cached $map if (!$src = array_search($path, $map)) { - if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $path))) { + if (drupal_path_match_patterns($path, $skiplist)) { + $map[$path] = $path; + } + elseif ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $path))) { $map[$src] = $path; } else { @@ -205,3 +215,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 path in the skiplist. + * + * @param $path + * The path to match. + * @param $patterns + * String containing patterns separated by \n, \r or \r\n. + * + * @return + * Boolean value: TRUE if the path matches a path in the skiplist, FALSE if otherwise. + */ +function drupal_path_match_patterns($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); +} \ No newline at end of file Index: modules/block/block.module =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.module,v retrieving revision 1.245 diff -u -p -r1.245 block.module --- modules/block/block.module 18 Dec 2006 21:49:39 -0000 1.245 +++ modules/block/block.module 3 Jan 2007 17:04:30 -0000 @@ -663,11 +663,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_patterns($path, $block->pages); if ($path != $_GET['q']) { - $page_match = $page_match || preg_match($regexp, $_GET['q']); + $page_match = $page_match || drupal_path_match_patterns($_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 Index: modules/path/path.module =================================================================== RCS file: /cvs/drupal/drupal/modules/path/path.module,v retrieving revision 1.104 diff -u -p -r1.104 path.module --- modules/path/path.module 18 Dec 2006 11:16:51 -0000 1.104 +++ modules/path/path.module 3 Jan 2007 17:04:31 -0000 @@ -60,6 +60,11 @@ function path_menu($may_cache) { 'callback arguments' => array('path_admin_edit'), 'access' => user_access('administer url aliases'), 'type' => MENU_LOCAL_TASK); + $items[] = array('path' => 'admin/build/path/skiplist', 'title' => t('Skiplist'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('path_admin_skiplist'), + 'access' => user_access('adminster url aliases'), + 'type' => MENU_LOCAL_TASK, 'weight' => 10); } return $items; @@ -122,6 +127,37 @@ function path_admin_delete($pid = 0) { drupal_set_message(t('The alias has been deleted.')); } +/** + * Menu callback; presents the skiplist form. + */ +function path_admin_skiplist() { + $form = array(); + $form['skiplist'] = array( + '#type' => 'textarea', + '#title' => t('Skiplist'), + '#default_value' => variable_get('path_skiplist', ''), + '#rows' => 10, + '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page."), + ); + $form['submit'] = array('#type' => 'submit', '#value' => t('Save skiplist')); + $form['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults')); + return $form; +} + +/** + * Save the updated skiplist. + **/ +function path_admin_skiplist_submit($form_id, $form_values) { + if ($form_values['op'] == t('Save skiplist')) { + variable_set('path_skiplist', $form_values['skiplist']); + drupal_set_message(t('The skiplist has been saved.')); + } + elseif ($form_values['op'] == t('Reset to defaults')) { + variable_del('path_skiplist'); + drupal_set_message(t('The skiplist has been reset.')); + } +} + /**