diff --git a/modules/node/views_plugin_argument_validate_node.inc b/modules/node/views_plugin_argument_validate_node.inc index 018965d..85d1526 100644 --- a/modules/node/views_plugin_argument_validate_node.inc +++ b/modules/node/views_plugin_argument_validate_node.inc @@ -73,8 +73,9 @@ class views_plugin_argument_validate_node extends views_plugin_argument_validate } function validate_argument($argument) { - $types = $this->options['types']; + $argument = str_replace(' ', '', $argument); + $types = $this->options['types']; switch ($this->options['nid_type']) { case 'nid': if (!is_numeric($argument)) { @@ -107,7 +108,6 @@ class views_plugin_argument_validate_node extends views_plugin_argument_validate if ($nids->value == array(-1)) { return FALSE; } - $test = drupal_map_assoc($nids->value); $titles = array(); @@ -127,6 +127,7 @@ class views_plugin_argument_validate_node extends views_plugin_argument_validate unset($test[$node->nid]); } + $this->argument->argument = $argument; $this->argument->validated_title = implode($nids->operator == 'or' ? ' + ' : ', ', $titles); // If this is not empty, we did not find a nid. return empty($test); diff --git a/modules/user/views_plugin_argument_validate_user.inc b/modules/user/views_plugin_argument_validate_user.inc index b727094..aa6d1de 100644 --- a/modules/user/views_plugin_argument_validate_user.inc +++ b/modules/user/views_plugin_argument_validate_user.inc @@ -16,6 +16,7 @@ class views_plugin_argument_validate_user extends views_plugin_argument_validate function option_definition() { $options = parent::option_definition(); $options['type'] = array('default' => 'uid'); + $options['multiple_values'] = array('default' => FALSE, 'bool' => TRUE); $options['restrict_roles'] = array('default' => FALSE, 'bool' => TRUE); $options['roles'] = array('default' => array()); @@ -34,6 +35,12 @@ class views_plugin_argument_validate_user extends views_plugin_argument_validate '#default_value' => $this->options['type'], ); + $form['multiple_values'] = array( + '#type' => 'checkbox', + '#title' => t('Allow multiple values separated by , or +'), + '#default_value' => $this->options['multiple_values'], + ); + $form['restrict_roles'] = array( '#type' => 'checkbox', '#title' => t('Restrict user based on role'), @@ -62,47 +69,81 @@ class views_plugin_argument_validate_user extends views_plugin_argument_validate function convert_options(&$options) { if (!isset($options['type']) && isset($this->argument->options['validate_user_argument_type'])) { $options['type'] = $this->argument->options['validate_user_argument_type']; + $options['multiple_values'] = $this->argument->options['validate_multiple_values']; $options['restrict_roles'] = $this->argument->options['validate_user_restrict_roles']; $options['roles'] = $this->argument->options['validate_user_roles']; } } function validate_argument($argument) { + $argument = str_replace(' ', '', $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"; - } - } + $arguments = array(); + + if($this->options['multiple_values'] == TRUE){ + if(strstr($argument, ',') !== FALSE){ + $arguments = explode(',', $argument); + } + if(strstr($argument, '+') !== FALSE){ + $arguments = explode('+', $argument); + } + } + + if(empty($arguments)){ + $arguments[] = $argument; + } + + $accounts = array(); + $where = array(); + + foreach($arguments as $argument){ + // 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') { + $where['uids'][] = $argument; + } + } + else { + if ($type == 'name' || $type == 'either') { + $where['names'][] = '\''.$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(isset($where['uids'])){ + $uid_string = '('.implode(',', $where['uids']).')'; + if(isset($where['names'])){ + $where_uids = 'uid in '.$uid_string; + } + else{ + $where_string = 'uid in '.$uid_string; + } + } + if(isset($where['names'])){ + $name_string = '('.implode(',', $where['names']).')'; + if(isset($where['uids'])){ + $where_names = 'name in '.$name_string; + } + else{ + $where_string = 'name in '.$name_string; + } + } + if(!isset($where_string)){ + $where_string = $where_uids.' OR '.$where_names; + } + + if (isset($where_string)) { + $query = "SELECT uid, name FROM {users} WHERE $where_string"; + $accounts = db_query($query)->fetchAll(); } - if (empty($account)) { + if (empty($accounts)) { // User not found. return FALSE; } @@ -110,19 +151,29 @@ class views_plugin_argument_validate_user extends views_plugin_argument_validate // 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; - } + foreach($accounts as $account){ + $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)); + $account_uids = array(); + $account_names = array(); + + foreach($accounts as $account){ + $account_uids[] = $account->uid; + $account_names[] = check_plain(format_username($account)); + } + + $this->argument->argument = implode(',', $account_uids); + $this->argument->validated_title = implode(',', $account_names); return TRUE; }