You are here

function _me_check_arg in me aliases 6.2

Same name and namespace in other branches
  1. 8 me.module \_me_check_arg()
  2. 6 me.module \_me_check_arg()
  3. 7 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_argument_uid_context in plugins/me_uid.inc
Discover if this argument gives us the user we crave.
me_plugin_argument_validate_me_alias::validate_argument in includes/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 478
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);
    list($ancestors, $placeholders) = menu_get_ancestors($parts);
    if (($router_item = db_fetch_array(db_query_range('SELECT * FROM {menu_router} WHERE path IN (' . implode(',', $placeholders) . ') ORDER BY fit DESC', $ancestors, 0, 1))) && $router_item['page_callback'] == 'me_handler') {

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