summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules/comment/views_handler_filter_comment_user_uid.inc23
-rw-r--r--modules/user/views_plugin_argument_validate_user.inc90
-rw-r--r--theme/theme.inc15
3 files changed, 126 insertions, 2 deletions
diff --git a/modules/comment/views_handler_filter_comment_user_uid.inc b/modules/comment/views_handler_filter_comment_user_uid.inc
new file mode 100644
index 0000000..bc88a60
--- /dev/null
+++ b/modules/comment/views_handler_filter_comment_user_uid.inc
@@ -0,0 +1,23 @@
+<?php
+// $Id$
+
+/**
+ * Filter handler to accept a user id to check for nodes that user posted or
+ * commented on.
+ */
+class views_handler_filter_comment_user_uid extends views_handler_filter_user_name {
+ function query() {
+ $this->ensure_my_table();
+ $replace = array_fill(0, sizeof($this->value), '%d');
+ $condition = $this->operator . ' (' . implode(", ", $replace) . ')';
+
+ // We include the WHERE condition twice in the query, so we need two
+ // copies of these argument values.
+ $args = array_values($this->value);
+ $args = array_merge($args, $args);
+
+ $this->query->add_where($this->options['group'], "$this->table_alias.uid " . $condition . " OR
+ (SELECT COUNT(*) FROM {comments} c WHERE c.uid " . $condition . " AND c.nid = $this->table_alias.nid)",
+ $args);
+ }
+}
diff --git a/modules/user/views_plugin_argument_validate_user.inc b/modules/user/views_plugin_argument_validate_user.inc
new file mode 100644
index 0000000..e82d413
--- /dev/null
+++ b/modules/user/views_plugin_argument_validate_user.inc
@@ -0,0 +1,90 @@
+<?php
+// $Id$
+
+/**
+ * Validate whether an argument is a valid user.
+ *
+ * This supports either numeric arguments (UID) or strings (username) and
+ * converts either one into the user's UID. This validator also sets the
+ * argument's title to the username.
+ */
+class views_plugin_argument_validate_user extends views_plugin_argument_validate {
+ function validate_form(&$form, &$form_state) {
+ $form['user_argument_type'] = array(
+ '#type' => 'radios',
+ '#title' => t('Type of user argument to allow'),
+ '#options' => array(
+ 'uid' => t('Only allow numeric UIDs'),
+ 'name' => t('Only allow string usernames'),
+ 'either' => t('Allow both numeric UIDs and string usernames'),
+ ),
+ '#default_value' => $this->argument->options['user_argument_type'],
+ );
+
+ $form['restrict_user_roles'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Restrict user based on role'),
+ '#default_value' => !empty($this->argument->options['restrict_user_roles']),
+ );
+
+ $form['user_roles'] = array(
+ '#type' => 'select',
+ '#multiple' => TRUE,
+ '#title' => t('Restrict to the selected roles'),
+ '#options' => user_roles(TRUE),
+ '#default_value' => $this->argument->options['user_roles'],
+ '#description' => t('If no roles are selected, users from any role will be allowed.'),
+ '#process' => array('views_process_dependency'),
+ '#dependency' => array(
+ 'edit-options-restrict-user-roles' => array(1),
+ ),
+ );
+ }
+
+ function validate_argument($argument) {
+ $type = $this->argument->options['user_argument_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') {
+ $where = 'uid = %d';
+ }
+ }
+ else {
+ if ($type == 'name' || $type == 'either') {
+ $where = "name = '%s'";
+ }
+ }
+
+ // If we don't have a WHERE clause, the argument is invalid.
+ if (empty($where)) {
+ return FALSE;
+ }
+
+ $query = "SELECT uid, name FROM {users} WHERE $where";
+ $account = db_fetch_object(db_query($query, $argument));
+ if (empty($account)) {
+ // User not found.
+ return FALSE;
+ }
+
+ // See if we're filtering users based on roles.
+ if (!empty($this->argument->options['restrict_user_roles']) && !empty($this->argument->options['user_roles'])) {
+ $roles = $this->argument->options['user_roles'];
+ $acccont->roles = array();
+ $account->roles[] = $account->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID;
+ $result = db_query('SELECT rid FROM {users_roles} WHERE uid = %d', $account->uid);
+ while ($role = db_fetch_object($result)) {
+ $account->roles[] = $role->rid;
+ }
+ if (!(bool)array_intersect($account->roles, $roles)) {
+ return FALSE;
+ }
+ }
+
+ $this->argument->argument = $account->uid;
+ $this->argument->validated_title = check_plain($account->name);
+ return TRUE;
+ }
+}
+
diff --git a/theme/theme.inc b/theme/theme.inc
index e755d4f..a78fb9b 100644
--- a/theme/theme.inc
+++ b/theme/theme.inc
@@ -164,10 +164,12 @@ function template_preprocess_views_view_fields(&$vars) {
$inline = FALSE;
$vars['fields'] = array(); // ensure it's at least an empty array.
foreach ($view->field as $id => $field) {
+ // render this even if set to exclude so it can be used elsewhere.
+ $field_output = $view->field[$id]->theme($vars['row']);
if (empty($field->options['exclude'])) {
$object = new stdClass();
- $object->content = $view->field[$id]->theme($vars['row']);
+ $object->content = $field_output;
if (isset($view->field[$id]->field_alias) && isset($vars['row']->{$view->field[$id]->field_alias})) {
$object->raw = $vars['row']->{$view->field[$id]->field_alias};
}
@@ -293,6 +295,15 @@ function template_preprocess_views_view_table(&$vars) {
$query = '&' . $query;
}
+ // Fields must be rendered in order as of Views 2.3, so we will pre-render
+ // everything.
+ $renders = array();
+ foreach ($result as $count => $row) {
+ foreach ($view->field as $id => $field) {
+ $renders[$count][$id] = $view->field[$id]->theme($row);
+ }
+ }
+
foreach ($columns as $field => $column) {
// render the header labels
if ($field == $column && empty($fields[$field]->options['exclude'])) {
@@ -331,7 +342,7 @@ function template_preprocess_views_view_table(&$vars) {
// Render each field into its appropriate column.
foreach ($result as $num => $row) {
if (!empty($fields[$field]) && empty($fields[$field]->options['exclude'])) {
- $field_output = $fields[$field]->theme($row);
+ $field_output = $renders[$num][$field];
// Don't bother with separators and stuff if the field does not show up.
if (!isset($field_output) && isset($vars['rows'][$num][$column])) {