You are here

function themekey_match_path in ThemeKey 7.3

Same name and namespace in other branches
  1. 6.4 themekey_base.inc \themekey_match_path()
  2. 6.2 themekey_base.inc \themekey_match_path()
  3. 6.3 themekey_base.inc \themekey_match_path()
  4. 7 themekey_base.inc \themekey_match_path()
  5. 7.2 themekey_base.inc \themekey_match_path()

Detects if a ThemeKey rule for property drupal:path matches to the current page request.

Parameters

$condition: ThemeKey rule as object:

  • property (must be "drupal:path")
  • operator
  • value

$parameters: reference to an array containing all ThemeKey properties and their values

Return value

boolean

2 calls to themekey_match_path()
themekey_get_global_parameters in ./themekey_base.inc
Assigns global parameters' values to ThemeKey properties. Therefore it calls hook_themekey_global()
themekey_match_condition in ./themekey_base.inc
Detects if a ThemeKey rule matches to the current page request.

File

./themekey_base.inc, line 81
The functions in this file are the back end of ThemeKey.

Code

function themekey_match_path($condition, &$parameters) {
  global $language;

  // don't repeat alias detection for all rules during one page request
  static $alias_uri = '';
  static $language_prefix = NULL;
  if ('drupal:path' != $condition->property) {
    return FALSE;
  }
  $get_q = themekey_get_q();
  $condition_parts = explode('/', $condition->value);
  $get_q_parts = explode('/', $get_q);
  $wildcards = themekey_match_path_parts($get_q_parts, $condition_parts);
  if (FALSE === $wildcards && module_exists('path')) {
    if (empty($alias_uri)) {

      // Derive path from request_uri.
      // drupal_parse_url() is not suitable because it lacks language prefix support.
      $offset = (variable_get('clean_url', 0) ? 0 : 3) + drupal_strlen(base_path());
      $alias_uri = drupal_substr(request_uri(), $offset);
      if (strpos($alias_uri, '?') !== FALSE) {

        // Remove query string from request uri
        $alias_uri_parts = explode('?', $alias_uri);
        $alias_uri = $alias_uri_parts[0];
      }
      if (NULL === $language_prefix) {
        if (drupal_multilingual() && LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX == variable_get('locale_language_negotiation_url_part', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX) && (array_key_exists('locale-url', variable_get('language_negotiation_language', array())) || array_key_exists('locale-url', variable_get('language_negotiation_language_content', array())))) {
          $languages = language_list('enabled');
          list($language_object, $alias_uri) = language_url_split_prefix($alias_uri, $languages[1]);
          if ($language_object) {
            $language_prefix = $language_object->prefix;
          }
          else {
            $language_prefix = FALSE;
          }
        }
        else {

          // prevent multiple checks for prefixes
          $language_prefix = FALSE;
        }
      }

      // For $alias_uri != $_GET['q'] the page was requested using an
      // aliased path, otherwise get the path alias internally
      if ($alias_uri == $get_q) {
        $lang_code = NULL;
        if (!empty($language->language) && LANGUAGE_NONE != $language->language) {
          $lang_code = $language->language;
        }
        $alias_uri = drupal_get_path_alias($get_q, $lang_code);
      }
    }
    if ($alias_uri != $get_q) {
      $wildcards = themekey_match_path_parts(explode('/', $alias_uri), $condition_parts);
      if (FALSE === $wildcards && $language_prefix) {

        // retry, because the rule might contain the path alias including the language prefix
        $wildcards = themekey_match_path_parts(explode('/', $language_prefix . '/' . $alias_uri), $condition_parts);
      }
    }
  }
  if (is_array($wildcards)) {
    $parameters['internal:temp_wildcards'] = $wildcards;
    return TRUE;
  }
  $parameters['internal:temp_wildcards'] = array();
  return FALSE;
}