You are here

function _me_check_path in me aliases 7

Same name and namespace in other branches
  1. 8 me.module \_me_check_path()
  2. 6.2 me.module \_me_check_path()
  3. 6 me.module \_me_check_path()

Helper function to check if a path can be rewritten or not.

By this stage, the path is already rewritten, so we need to reverse the process.

Parameters

&$link: The link object to check.

1 call to _me_check_path()
me_preprocess_menu_link in ./me.module
Implementaiton of moduleName_preprocess_hook() for theme_menu_link.

File

./me.module, line 61
Provides 'me' aliases to allow users to enter 'me' in common paths instead of their user id.

Code

function _me_check_path(&$link) {

  // If the link has been rewritten, and we are not supposed to be handling this
  // path, then rewite it back to its original.
  if (isset($link['#href']) && me_variable_get('me_rewrite_link') && !_me_handle_path($link['#href'])) {
    $path_parts = explode('/', $link['#href'], MENU_MAX_PARTS);

    // The wildcarded path will either be in $link['path'], or $link['router_path'].
    $wild_parts = explode('/', isset($link['#original_link']['link_path']) ? $link['#original_link']['link_path'] : $link['#original_link']['router_path'], MENU_MAX_PARTS);

    // Go over each of the path parts and if one is equal to the me alias, make sure it is a wildcard,
    // and if so, switch it back out.
    foreach ($path_parts as $key => $val) {
      if (_me_is_alias($val) && $wild_parts[$key] == '%') {
        $path_parts[$key] = $GLOBALS['user']->uid;
      }
    }
    $link['#href'] = implode('/', $path_parts);
    $link['#original_link']['href'] = implode('/', $path_parts);
  }
}