You are here

function purl_get_normal_path in Persistent URL 7

Same name and namespace in other branches
  1. 6 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
Implements hook_init(). Checks for any valid persistent urls in request string and fire callback appropriately
purl_url_inbound_alter in ./purl.module
Implements hook_url_alter_inbound(). Rewrites an incoming drupal path (&$path) removing PURL modifiers.

File

./purl.module, line 194

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) {
          $processor
            ->adjust($value, $element, $adjusted[$q]);
        }
        $cache[$q][$method] = $elements;
      }
    }

    // Now that the path has been fully rewritten, check to see if there is
    // an available path alias.
    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 at the end of all this the adjusted query string is empty, use the
  // site frontpage.
  if (!empty($q)) {
    return !empty($adjusted[$q]) ? $adjusted[$q] : variable_get('site_frontpage', 'node');
  }

  // If the actual requested string was empty, we need to leave it alone.
  return $adjusted[$q];
}