Index: vud.api.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/vud.api.php,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 vud.api.php
--- vud.api.php 6 Feb 2011 17:23:04 -0000 1.1.2.2
+++ vud.api.php 14 Feb 2011 02:45:39 -0000
@@ -12,6 +12,34 @@
define('VUD_NEWENTITY_WIDGET_MESSAGE_POSTPONED', 2);
/**
+ * Allow modules to alter access to the voting operation.
+ *
+ * @param $perm
+ * A string containing the permission required to modify the vote.
+ * @param $type
+ * A string containing the type of content being voted on.
+ * @param $content_id
+ * An integer containing the unique ID of the content being voted on.
+ * @param $value
+ * An integer containing the vote value, 1 for an up vote, -1 for a down vote.
+ * @param $tag
+ * A string containing the voting API tag.
+ * $param $account
+ * An object containing the user voting on the content, NULL for the current
+ * user.
+ *
+ * @return
+ * A boolean forcing access to the vote, pass NULL if the function should
+ * not modify the access restriction.
+ */
+function hook_vud_access($perm, $type, $content_id, $value, $tag, $account) {
+ // Denies access for all users other than user 1.
+ if ($account->uid != 1) {
+ return FALSE;
+ }
+}
+
+/**
* Modify the array of know messages.
*
* For a real implementation take a look at
Index: vud.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/vud.module,v
retrieving revision 1.9
diff -u -p -r1.9 vud.module
--- vud.module 1 Nov 2010 04:56:56 -0000 1.9
+++ vud.module 14 Feb 2011 02:45:39 -0000
@@ -78,7 +78,8 @@ function vud_menu() {
'title' => 'Vote',
'page callback' => 'vud_vote',
'page arguments' => array(1, 2, 3, 4, 5, 6),
- 'access arguments' => array('use vote up/down'),
+ 'access callback' => 'vud_access_callback',
+ 'access arguments' => array('use vote up/down', 1, 2, 3, 4),
'type' => MENU_CALLBACK,
'file' => 'vud.theme.inc',
);
@@ -87,7 +88,8 @@ function vud_menu() {
'title' => 'Reset vote',
'page callback' => 'vud_reset',
'page arguments' => array(1, 2, 3, 4),
- 'access arguments' => array('reset vote up/down votes'),
+ 'access callback' => 'vud_access_callback',
+ 'access arguments' => array('reset vote up/down votes', 1, 2, 3, 4),
'type' => MENU_CALLBACK,
);
@@ -111,6 +113,46 @@ function vud_menu() {
}
/**
+ * Access callback for votes.
+ *
+ * @param $perm
+ * A string containing the permission required to modify the vote.
+ * @param $type
+ * A string containing the type of content being voted on.
+ * @param $content_id
+ * An integer containing the unique ID of the content being voted on.
+ * @param $value
+ * An integer containing the vote value, 1 for an up vote, -1 for a down vote.
+ * @param $tag
+ * A string containing the voting API tag.
+ * $param $account
+ * An object containing the user voting on the content, NULL for the current
+ * user.
+ *
+ * @return
+ * A boolean flagging whether or not the user has access to the vote.
+ */
+function vud_access_callback($perm, $type, $content_id, $value, $tag, $account = NULL) {
+ if (NULL === $account) {
+ global $user;
+ $account = $user;
+ }
+
+ // Initializes access based on user's permission.
+ $access = user_access($perm, $account);
+
+ // Invokes hook_access(), gives modules ability to allow or disallow access.
+ $access_array = module_invoke_all('vud_access', $perm, $type, $content_id, $value, $tag, $account);
+ foreach ($access_array as $set_access) {
+ if (isset($set_access)) {
+ $access = $set_access;
+ }
+ }
+
+ return $access;
+}
+
+/**
* Implementation of hook_perm().
*/
function vud_perm() {
Index: vud_comment/vud_comment.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/vud_comment/vud_comment.module,v
retrieving revision 1.12
diff -u -p -r1.12 vud_comment.module
--- vud_comment/vud_comment.module 6 Feb 2011 04:46:01 -0000 1.12
+++ vud_comment/vud_comment.module 14 Feb 2011 02:45:39 -0000
@@ -114,8 +114,9 @@ function vud_comment_comment(&$comment,
$comment_allow = in_array($type, variable_get('vud_comment_node_types', array()), TRUE);
if ($comment_allow && user_access('use vote up/down on comments')) {
$tag = variable_get('vud_tag', 'vote');
+ $read_only = !vud_access_callback('use vote up/down', 'comment', $comment->cid, 0, $tag);
$widget = variable_get('vud_comment_widget', 'plain');
- $comment->vud_comment_widget = theme('vud_widget', $comment->cid, 'comment', $tag, $widget);
+ $comment->vud_comment_widget = theme('vud_widget', $comment->cid, 'comment', $tag, $widget, $read_only);
if (variable_get('vud_comment_widget_display', VUD_COMMENT_DISPLAY_NORMAL) == VUD_COMMENT_DISPLAY_NORMAL) {
$comment->comment = $comment->vud_comment_widget . $comment->comment;
}
Index: vud_node/vud_node.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/vud_node/vud_node.module,v
retrieving revision 1.12
diff -u -p -r1.12 vud_node.module
--- vud_node/vud_node.module 18 Aug 2010 14:25:01 -0000 1.12
+++ vud_node/vud_node.module 14 Feb 2011 02:45:40 -0000
@@ -142,10 +142,11 @@ function vud_node_nodeapi(&$node, $op, $
if (in_array($node->build_mode, $exclude_modes)) {
break;
}
- if (($can_edit=user_access('use vote up/down on nodes')) || user_access('view vote up/down count on nodes')) {
+ $tag = variable_get('vud_tag', 'vote');
+ $can_edit = (user_access('use vote up/down on nodes') && vud_access_callback('use vote up/down', 'node', $node->nid, 0, $tag));
+ if ($can_edit || user_access('view vote up/down count on nodes')) {
$node_type = in_array($node->type, variable_get('vud_node_types', array()), TRUE);
$widget_showmode = variable_get('vud_node_widget_show', VUD_NODE_DISPLAY_BOTH);
- $tag = variable_get('vud_tag', 'vote');
$widget = variable_get('vud_node_widget', 'plain');
$vote_on_teaser = (bool)variable_get('vud_node_widget_vote_on_teaser', TRUE);
$teaser = $a3;
Index: vud_term/vud_term.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/vud_term/vud_term.module,v
retrieving revision 1.6
diff -u -p -r1.6 vud_term.module
--- vud_term/vud_term.module 2 Aug 2010 05:13:53 -0000 1.6
+++ vud_term/vud_term.module 14 Feb 2011 02:45:40 -0000
@@ -107,6 +107,7 @@ function _vud_term_generate_table(&$node
foreach ($node->taxonomy as $term => $tdetails) {
$content_id = $tdetails->tid;
$tag = "n$node->nid";
+ $read_only = !vud_access_callback('use vote up/down', 'term', $content_id, 0, $tag);
$reset_token = drupal_get_token("votereset/term/$content_id/$tag");
if (variable_get('vud_term_reset', 0) && user_access('reset vote up/down votes')) {
$header = array(
@@ -119,7 +120,7 @@ function _vud_term_generate_table(&$node
$rows[] = array(
$tdetails->name,
$tdetails->description,
- theme('vud_widget', $content_id, "term", $tag, $widget),
+ theme('vud_widget', $content_id, "term", $tag, $widget, $read_only),
"". _vud_term_get_row_votes($content_id, $tag) .'',
l('Reset your vote', "votereset/term/$content_id/$tag/$reset_token"),
);
@@ -134,7 +135,7 @@ function _vud_term_generate_table(&$node
$rows[] = array(
$tdetails->name,
$tdetails->description,
- theme('vud_widget', $content_id, "term", $tag, $widget),
+ theme('vud_widget', $content_id, "term", $tag, $widget, $read_only),
"". _vud_term_get_row_votes($content_id, $tag) .'',
);
}