function purl_get_normal_path in Persistent URL 6
Same name and namespace in other branches
- 7 purl.module \purl_get_normal_path()
Process a query string into its respective processors and modifiers and return the adjusted query string. If true, the $activate argument is used to call provider callbacks for a given query string. All values are static cached for a given query string so that request adjustment and provider activation can be separated into distinct steps.
2 calls to purl_get_normal_path()
- purl_init in ./
purl.module - Implementation of hook_init() Checks for any valid persistent urls in request string and fire callback appropriately
- purl_url_inbound_alter in ./
purl.module - Implementation of hook_url_alter_inbound(). Rewrites an incoming drupal path (&$result) removing PURL modifiers.
File
- ./
purl.module, line 201
Code
function purl_get_normal_path($q, $activate = FALSE, $reset = FALSE) {
static $cache = array();
static $adjusted = array();
if (!isset($cache[$q]) || $reset) {
$cache[$q] = array();
$adjusted[$q] = $q;
// Detect all modifiers, parse them into their respective provider values,
// and allow processors to adjust the query string.
foreach (array_keys(_purl_options()) as $method) {
$processor = purl_get_processor($method);
// Pass the requested Drupal query string for modifier detection.
// Processors that don't use/affect the query string can access
// the $_REQUEST or $_GET objects directly.
$value = $processor
->detect($adjusted[$q]);
$elements = purl_parse($processor, $value);
// Allow adjustment of page request globals.
if (is_array($elements)) {
foreach ($elements as $element) {
$js['purl'][$element->provider] = $element->value;
$processor
->adjust($value, $element, $adjusted[$q]);
}
$cache[$q][$method] = $elements;
}
}
// js purl settings
drupal_add_js($js, 'setting');
// Now that the path has been fully rewritten, check to see if there is
// an available path alias.
// Set empty adjusted[q] to homepage before looking up the source path.
if (empty($adjusted[$q])) {
$adjusted[$q] = variable_get('site_frontpage', 'node');
}
if ($src = drupal_lookup_path('source', $adjusted[$q])) {
$adjusted[$q] = $src;
}
}
// If the activate flag has been thrown, activate provider callbacks.
if ($activate) {
foreach ($cache[$q] as $method => $elements) {
foreach ($elements as $element) {
purl_active()
->add($method, $element)
->set($element);
}
}
}
// If the actual requested string was empty, we need to leave it alone.
return $adjusted[$q];
}