summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-10-24 05:13:44 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-10-24 05:13:44 +0000
commitcd7b8f099996c46a58b354ae262852d222306e74 (patch)
tree1e7725d67472a1c203ce418f90e2fb48716efd37 /includes
parentdec6514c3b2d889c3a9fb19731e49e83d554392c (diff)
downloadbrdo-cd7b8f099996c46a58b354ae262852d222306e74.tar.gz
brdo-cd7b8f099996c46a58b354ae262852d222306e74.tar.bz2
#320331 by Dave Reid, dww, John Morahan, cwgordon7, moshe weitzman, c960657, and smoothify: Turn custom_url_rewrite_inbound() and custom_url_rewrite_outbound() into hooks.
Diffstat (limited to 'includes')
-rw-r--r--includes/bootstrap.inc14
-rw-r--r--includes/common.inc28
-rw-r--r--includes/language.inc41
-rw-r--r--includes/path.inc25
4 files changed, 31 insertions, 77 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index b4f683840..8cc52c69e 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -127,15 +127,10 @@ define('DRUPAL_BOOTSTRAP_PAGE_HEADER', 5);
define('DRUPAL_BOOTSTRAP_LANGUAGE', 6);
/**
- * Eighth bootstrap phase: set $_GET['q'] to Drupal path of request.
- */
-define('DRUPAL_BOOTSTRAP_PATH', 7);
-
-/**
* Final bootstrap phase: Drupal is fully loaded; validate and fix
* input data.
*/
-define('DRUPAL_BOOTSTRAP_FULL', 8);
+define('DRUPAL_BOOTSTRAP_FULL', 7);
/**
* Role ID for anonymous users; should match what's in the "role" table.
@@ -1405,7 +1400,6 @@ function drupal_bootstrap($phase = NULL, $new_phase = TRUE) {
DRUPAL_BOOTSTRAP_SESSION,
DRUPAL_BOOTSTRAP_PAGE_HEADER,
DRUPAL_BOOTSTRAP_LANGUAGE,
- DRUPAL_BOOTSTRAP_PATH,
DRUPAL_BOOTSTRAP_FULL,
));
$completed_phase = &drupal_static(__FUNCTION__ . '_completed_phase', -1);
@@ -1541,12 +1535,6 @@ function _drupal_bootstrap($phase) {
drupal_language_initialize();
break;
- case DRUPAL_BOOTSTRAP_PATH:
- require_once DRUPAL_ROOT . '/includes/path.inc';
- // Initialize $_GET['q'] prior to loading modules and invoking hook_init().
- drupal_path_initialize();
- break;
-
case DRUPAL_BOOTSTRAP_FULL:
require_once DRUPAL_ROOT . '/includes/common.inc';
_drupal_bootstrap_full();
diff --git a/includes/common.inc b/includes/common.inc
index aa0a08a9c..90be49c5a 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -2379,6 +2379,7 @@ function url($path = NULL, array $options = array()) {
'https' => FALSE,
'prefix' => ''
);
+
if (!isset($options['external'])) {
// Return an external link if $path contains an allowed absolute URL.
// Only call the slow filter_xss_bad_protocol if $path contains a ':' before
@@ -2387,10 +2388,12 @@ function url($path = NULL, array $options = array()) {
$options['external'] = ($colonpos !== FALSE && !preg_match('![/?#]!', substr($path, 0, $colonpos)) && filter_xss_bad_protocol($path, FALSE) == check_plain($path));
}
- // May need language dependent rewriting if language.inc is present.
- if (function_exists('language_url_rewrite')) {
- language_url_rewrite($path, $options);
- }
+ // Preserve the original path before altering or aliasing.
+ $original_path = $path;
+
+ // Allow other modules to alter the outbound URL and options.
+ drupal_alter('url_outbound', $path, $options, $original_path);
+
if ($options['fragment']) {
$options['fragment'] = '#' . $options['fragment'];
}
@@ -2439,21 +2442,16 @@ function url($path = NULL, array $options = array()) {
}
}
- // Preserve the original path before aliasing.
- $original_path = $path;
-
// The special path '<front>' links to the default front page.
if ($path == '<front>') {
$path = '';
}
elseif (!empty($path) && !$options['alias']) {
$language = isset($options['language']) && isset($options['language']->language) ? $options['language']->language : '';
- $path = drupal_get_path_alias($path, $language);
- }
-
- if (function_exists('custom_url_rewrite_outbound')) {
- // Modules may alter outbound links by reference.
- custom_url_rewrite_outbound($path, $options, $original_path);
+ $alias = drupal_get_path_alias($original_path, $language);
+ if ($alias != $original_path) {
+ $path = $alias;
+ }
}
$base = $options['absolute'] ? $options['base_url'] . '/' : base_path();
@@ -4223,6 +4221,7 @@ function _drupal_bootstrap_full() {
return;
}
$called = 1;
+ require_once DRUPAL_ROOT . '/includes/path.inc';
require_once DRUPAL_ROOT . '/includes/theme.inc';
require_once DRUPAL_ROOT . '/includes/pager.inc';
require_once DRUPAL_ROOT . '/includes/menu.inc';
@@ -4256,6 +4255,8 @@ function _drupal_bootstrap_full() {
ini_set('log_errors', 1);
ini_set('error_log', file_directory_path() . '/error.log');
}
+ // Initialize $_GET['q'] prior to invoking hook_init().
+ drupal_path_initialize();
// Set a custom theme for the current page, if there is one. We need to run
// this before invoking hook_init(), since any modules which initialize the
// theme system will prevent a custom theme from being correctly set later.
@@ -6115,4 +6116,3 @@ function drupal_get_updaters() {
}
return $updaters;
}
-
diff --git a/includes/language.inc b/includes/language.inc
index 77b8146be..bb4802df5 100644
--- a/includes/language.inc
+++ b/includes/language.inc
@@ -325,47 +325,6 @@ function language_from_default() {
}
/**
- * Rewrite URLs allowing modules to hook in.
- *
- * @param $path
- * The path to rewrite.
- * @param $options
- * An associative array of additional options as in url().
- */
-function language_url_rewrite(&$path, &$options) {
- // Only modify relative (insite) URLs.
- if (!$options['external']) {
- static $callbacks;
-
- if (!isset($callbacks)) {
- $callbacks = array();
-
- foreach (language_types_configurable() as $type) {
- // Get url rewriter callbacks only from enabled language providers.
- $negotiation = variable_get("language_negotiation_$type", array());
-
- foreach ($negotiation as $id => $provider) {
- if (isset($provider['file'])) {
- require_once DRUPAL_ROOT . '/' . $provider['file'];
- }
-
- // Avoid duplicate callback entries.
- if (isset($provider['callbacks']['url_rewrite'])) {
- $callbacks[$provider['callbacks']['url_rewrite']] = NULL;
- }
- }
- }
-
- $callbacks = array_keys($callbacks);
- }
-
- foreach ($callbacks as $callback) {
- $callback($path, $options);
- }
- }
-}
-
-/**
* Split the given path into prefix and actual path.
*
* Parse the given path and return the language object identified by the
diff --git a/includes/path.inc b/includes/path.inc
index f1542323e..19d52df38 100644
--- a/includes/path.inc
+++ b/includes/path.inc
@@ -6,8 +6,8 @@
* Functions to handle paths in Drupal, including path aliasing.
*
* These functions are not loaded for cached pages, but modules that need
- * to use them in hook_init() or hook exit() can make them available, by
- * executing "drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH);".
+ * to use them in hook_boot() or hook exit() can make them available, by
+ * executing "drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);".
*/
/**
@@ -204,15 +204,22 @@ function drupal_get_path_alias($path = NULL, $path_language = '') {
* internal path was found.
*/
function drupal_get_normal_path($path, $path_language = '') {
- $result = $path;
+ $original_path = $path;
+
+ // Lookup the path alias first.
if ($source = drupal_lookup_path('source', $path, $path_language)) {
- $result = $source;
+ $path = $source;
}
- if (function_exists('custom_url_rewrite_inbound')) {
- // Modules may alter the inbound request path by reference.
- custom_url_rewrite_inbound($result, $path, $path_language);
+
+ // Allow other modules to alter the inbound URL. We cannot use drupal_alter()
+ // here because we need to run hook_url_inbound_alter() in the reverse order
+ // of hook_url_outbound_alter().
+ foreach (array_reverse(module_implements('url_inbound_alter')) as $module) {
+ $function = $module . '_url_inbound_alter';
+ $function($path, $original_path, $path_language);
}
- return $result;
+
+ return $path;
}
/**
@@ -347,7 +354,7 @@ function drupal_match_path($path, $patterns) {
* This function is not available in hook_boot() so use $_GET['q'] instead.
* However, be careful when doing that because in the case of Example #3
* $_GET['q'] will contain "path/alias". If "node/306" is needed, calling
- * drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH) makes this function available.
+ * drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL) makes this function available.
*
* @return
* The current Drupal URL path.