You are here

function _themekey_match_paths in ThemeKey 6

Function _themekey_match_paths().

1 call to _themekey_match_paths()
themekey_init in ./themekey.module
Implementation of hook_init().

File

./themekey_base.inc, line 69

Code

function _themekey_match_paths($path) {
  static $global_parameters = NULL;

  //
  if (!isset($global_parameters)) {
    $global_parameters = module_invoke_all('themekey_global');
  }

  //
  $parts = explode('/', $path, MENU_MAX_PARTS);
  list($ancestors, $placeholders) = _themekey_get_path_ancestors($parts);

  //
  $result = db_query('SELECT * FROM {themekey_paths} WHERE path IN (' . implode(',', $placeholders) . ') ORDER BY fit DESC, weight DESC, custom DESC', $ancestors);
  while ($item = db_fetch_array($result)) {
    $parameters = $global_parameters;
    $conditions = unserialize($item['conditions']);

    //
    $wildcards = unserialize($item['wildcards']);
    foreach ($wildcards as $index => $wildcard) {
      $parameters[$wildcard] = arg($index, $path);
    }

    //
    if (!_themekey_match_conditions($conditions, $parameters)) {
      continue;
    }

    //
    $callbacks = unserialize($item['callbacks']);
    if (count($callbacks)) {
      foreach ($callbacks as $callback) {
        $callback($item, $parameters);
      }
    }

    //
    if (!$item['theme']) {
      $item['theme'] = _themekey_match_properties($parameters);
    }
    return $item['theme'];
  }
  return _themekey_match_properties($global_parameters);
}