You are here

function _me_check_arg in me aliases 7

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

A Helper function to check for the 'me' alias.

Parameters

$arg: The argument to check.

$username: If TRUE, will return the username instead of the users id.

$redirect: When TRUE, anonymous users will be redirected if a path is available.

Return value

mixed The current user id if a match is found, or the given argument if no match.

3 calls to _me_check_arg()
me_me_uid_context in plugins/arguments/me_uid.inc
Discover if this argument gives us the user we crave.
me_plugin_argument_validate_me_alias::validate_argument in includes/views/handlers/me_plugin_argument_validate_me_alias.inc
Performs the actual validation.
_me_load_arguments in ./me.module
Helper function to set up arguments in meun _load callbacks.

File

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

Code

function _me_check_arg($arg, $username = FALSE, $redirect = TRUE) {
  $return = _me_is_alias($arg) ? $username ? $GLOBALS['user']->name : $GLOBALS['user']->uid : $arg;
  $redirect_path = me_variable_get('me_redirect_anonymous');
  if ($redirect && $GLOBALS['user']->uid == 0 && !empty($redirect_path)) {

    // Copied from menu_get_item(). We can't call that here as it might cause a recursion loop.
    $original_map = arg(NULL, $_GET['q']);
    $parts = array_slice($original_map, 0, MENU_MAX_PARTS);
    $ancestors = menu_get_ancestors($parts);
    if (($router_item = db_query_range('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC', 0, 1, array(
      ':ancestors' => $ancestors,
    ))
      ->fetchAssoc()) && $router_item['page_callback'] == 'me_handler') {

      // Not unsetting the destination can cause evil redirect loops.
      unset($_GET['destination'], $_REQUEST['edit']['destination']);
      drupal_goto($redirect_path);
    }
  }
  return $return;
}