From 10cd079feec03c2e6126b9b834a3ac14b8c8c1d7 Mon Sep 17 00:00:00 2001
From: nohup <nohup@269763.no-reply.drupal.org>
Date: Wed, 22 Jun 2011 20:22:07 -0500
Subject: [PATCH] Issue #1024138 by nohup, marvil07: Namespace the user votes
 tab and move access check to access callback.

---
 vud.install |    7 ++++++
 vud.module  |   67 +++++++++++++++++++++++++++++------------------------------
 2 files changed, 40 insertions(+), 34 deletions(-)

diff --git a/vud.install b/vud.install
index 33e7545..8a34762 100644
--- a/vud.install
+++ b/vud.install
@@ -48,3 +48,10 @@ function vud_update_6200() {
 
   return $ret;
 }
+
+/**
+ * Rebuild menu for the path change on user statistics.
+ */
+function vud_update_6300() {
+  menu_rebuild();
+}
diff --git a/vud.module b/vud.module
index 8a9758e..cef2015 100644
--- a/vud.module
+++ b/vud.module
@@ -92,11 +92,12 @@ function vud_menu() {
     'type'             => MENU_CALLBACK,
   );
 
-  $items['user/%user/votes'] = array(
+  $items['user/%user/vote_up_down/votes'] = array(
     'title'            => 'Votes',
     'page callback'    => 'vud_user_votes',
     'page arguments'   => array(1),
-    'access arguments' => array('access vote up/down statistics'),
+    'access callback'  => 'vud_can_see_votes',
+    'access arguments' => array(1),
     'type'             => MENU_LOCAL_TASK,
   );
 
@@ -162,43 +163,41 @@ function vud_perm() {
   return array('use vote up/down', 'administer vote up/down', 'access vote up/down statistics', 'reset vote up/down votes');
 }
 
+
+function vud_can_see_votes($account) {
+  return user_access('access vote up/down statistics') || user_access('administer users');
+}
+
 /**
  * Menu callback; display all votes for a user.
  */
-function vud_user_votes() {
-  if ($account = user_load(array('uid' => arg(1), 'status' => 1))) {
-    if ($account->status || user_access('administer users')) {
-      $header = array(
-        array('data' => t('Node')),
-        array('data' => t('Vote')),
-        array('data' => t('Date'))
-      );
-      $sql = db_rewrite_sql("SELECT n.nid, n.title, v.value, v.timestamp FROM {node} n LEFT JOIN {votingapi_vote} v
-                             ON n.nid = v.content_id
-                             WHERE v.uid = %d AND v.tag = '%s' AND v.content_type = 'node' AND n.status = 1
-                             ORDER BY v.timestamp DESC");
-      $result = pager_query($sql, 25, 0, NULL, $account->uid, variable_get('vud_tag', 'vote'));
-      $rows = array();
-      while ($node = db_fetch_object($result)) {
-        $rows[] = array(
-          l($node->title, 'node/'. $node->nid),
-          $node->value,
-          t('!time ago', array('!time' => format_interval(time() - $node->timestamp)))
-        );
-      }
-      drupal_set_title(check_plain($account->name));
-      $output = theme('table', $header, $rows);
-      $output .= theme('pager', NULL, 25);
-
-      return $output;
-    }
-    else {
-      drupal_access_denied();
-    }
-  }
-  else {
+function vud_user_votes($account) {
+  if ($account->status != 1) {
     drupal_not_found();
   }
+  $header = array(
+    array('data' => t('Node')),
+    array('data' => t('Vote')),
+    array('data' => t('Date'))
+  );
+  $sql = db_rewrite_sql("SELECT n.nid, n.title, v.value, v.timestamp FROM {node} n LEFT JOIN {votingapi_vote} v
+    ON n.nid = v.content_id
+    WHERE v.uid = %d AND v.tag = '%s' AND v.content_type = 'node' AND n.status = 1
+    ORDER BY v.timestamp DESC");
+  $result = pager_query($sql, 25, 0, NULL, $account->uid, variable_get('vud_tag', 'vote'));
+  $rows = array();
+  while ($node = db_fetch_object($result)) {
+    $rows[] = array(
+      l($node->title, 'node/'. $node->nid),
+      $node->value,
+      t('!time ago', array('!time' => format_interval(time() - $node->timestamp)))
+    );
+  }
+  drupal_set_title(check_plain($account->name));
+  $output = theme('table', $header, $rows);
+  $output .= theme('pager', NULL, 25);
+
+  return $output;
 }
 
 /**
-- 
1.7.5.3

