You are here

function context_prefix_parse in Context 5

Parses a query string of various types (url, domain, etc.) and returns an array of any found prefixes and their respective providers/id values.

3 calls to context_prefix_parse()
context_prefix_unprefix in context_prefix/context_prefix.module
Removes any prefixes from a query string. For path prefixes only.
context_prefix_url_rewrite in context_prefix/context_prefix.module
Rewrites path with current context and removes context if searching for source path
_context_prefix_init in context_prefix/context_prefix.module
Helper function to initialize, parse + set prefixed contexts.

File

context_prefix/context_prefix.module, line 229

Code

function context_prefix_parse($method = CONTEXT_PREFIX_PATH, $q) {
  static $cache;
  if (!isset($cache[$method][$q])) {
    $valid_prefixes = context_prefix_prefixes($method);

    // Parse the provided query string and provide an array of any prefixes found
    switch ($method) {
      case CONTEXT_PREFIX_PATH:
      case CONTEXT_PREFIX_PAIR:
        $parsed = array();
        $args = explode('/', $q);
        $arg = $args[0];
        while (isset($valid_prefixes[$arg])) {
          $parsed[$arg] = $valid_prefixes[$arg];
          array_shift($args);
          if ($method == CONTEXT_PREFIX_PAIR) {
            $parsed[$arg]['id'] = array_shift($args);
          }
          $arg = $args[0];
          if (in_array($arg, $parsed)) {
            break;
          }
        }
        $cache[$method][$q] = $parsed;
        break;
      case CONTEXT_PREFIX_DOMAIN:
        $parsed = array();
        if (isset($valid_prefixes[$q])) {
          $parsed[$q] = $valid_prefixes[$q];
        }
        $cache[$method][$q] = $parsed;
        break;
    }
  }
  return $cache[$method][$q];
}