function views_plugin_argument_validate_user::validate_argument

cis7 views_plugin_argument_validate_user.inc views_plugin_argument_validate_user::validate_argument($argument)
cle7 views_plugin_argument_validate_user.inc views_plugin_argument_validate_user::validate_argument($argument)
elmsmedia7 views_plugin_argument_validate_user.inc views_plugin_argument_validate_user::validate_argument($argument)
icor7 views_plugin_argument_validate_user.inc views_plugin_argument_validate_user::validate_argument($argument)
meedjum_blog7 views_plugin_argument_validate_user.inc views_plugin_argument_validate_user::validate_argument($argument)
mooc7 views_plugin_argument_validate_user.inc views_plugin_argument_validate_user::validate_argument($argument)

Overrides views_plugin_argument_validate::validate_argument

File

sites/all/modules/ulmus/views/modules/user/views_plugin_argument_validate_user.inc, line 70
Definition of views_plugin_argument_validate_user.

Class

views_plugin_argument_validate_user
Validate whether an argument is a valid user.

Code

function validate_argument($argument) {
  $type = $this->options['type'];
  // is_numeric() can return false positives, so we ensure it's an integer.
  // However, is_integer() will always fail, since $argument is a string.
  if (is_numeric($argument) && $argument == (int) $argument) {
    if ($type == 'uid' || $type == 'either') {
      if ($argument == $GLOBALS['user']->uid) {
        // If you assign an object to a variable in PHP, the variable
        // automatically acts as a reference, not a copy, so we use
        // clone to ensure that we don't actually mess with the
        // real global $user object.
        $account = clone $GLOBALS['user'];
      }
      $where = 'uid = :argument';
    }
  }
  else {
    if ($type == 'name' || $type == 'either') {
      $name = !empty($GLOBALS['user']->name) ? $GLOBALS['user']->name : variable_get('anonymous', t('Anonymous'));
      if ($argument == $name) {
        $account = clone $GLOBALS['user'];
      }
      $where = "name = :argument";
    }
  }

  // If we don't have a WHERE clause, the argument is invalid.
  if (empty($where)) {
    return FALSE;
  }

  if (!isset($account)) {
    $query = "SELECT uid, name FROM {users} WHERE $where";
    $account = db_query($query, array(':argument' => $argument))->fetchObject();
  }
  if (empty($account)) {
    // User not found.
    return FALSE;
  }

  // See if we're filtering users based on roles.
  if (!empty($this->options['restrict_roles']) && !empty($this->options['roles'])) {
    $roles = $this->options['roles'];
    $account->roles = array();
    $account->roles[] = $account->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID;
    $result = db_query('SELECT rid FROM {users_roles} WHERE uid = :uid', array(':uid' => $account->uid));
    foreach ($result as $role) {
      $account->roles[] = $role->rid;
    }
    if (!(bool) array_intersect($account->roles, $roles)) {
      return FALSE;
    }
  }

  $this->argument->argument = $account->uid;
  $this->argument->validated_title = check_plain(format_username($account));
  return TRUE;
}
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.