### Eclipse Workspace Patch 1.0 #P vote_up_down Index: vote_up_down.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/vote_up_down.module,v retrieving revision 1.20 diff -u -r1.20 vote_up_down.module --- vote_up_down.module 19 Nov 2007 07:32:27 -0000 1.20 +++ vote_up_down.module 16 Jan 2008 23:25:13 -0000 @@ -1,5 +1,5 @@ type, variable_get('vote_up_down_node_types', array()), TRUE); if ($node_type && user_access('view up-down vote')) { - if (variable_get('vote_up_down_reset_vote', 0) && user_access('use up-down vote')) { + if (variable_get('vote_up_down_reset_vote', 0) && user_access('use up-down vote') && vote_up_down_hasvoted('node', $node->nid, $user->uid)) { $links['vote_up_down_reset'] = array( 'title' => t('Reset vote'), 'href' => "vote_up_down/$type/$node->nid/0", @@ -271,7 +272,7 @@ } break; case 'comment': - if (variable_get('vote_up_down_reset_vote', 0) && user_access('use up-down vote') && variable_get('vote_up_down_widget_comment', 0)) { + if (variable_get('vote_up_down_reset_vote', 0) && user_access('use up-down vote') && vote_up_down_hasvoted('comment', $node->cid, $user->uid) && (variable_get('vote_up_down_widget_comment', 0) || variable_get('vote_up_down_link_comment', 0))) { $links['vote_up_down_reset_c'] = array( 'title' => t('Reset vote'), 'href' => "vote_up_down/$type/$node->cid/0", @@ -289,50 +290,6 @@ } /** - * Implementation of hook_block(). - */ -function vote_up_down_block($op = 'list', $delta = 0) { - if ($op == 'list') { - $blocks[0]['info'] = t('Who voted on it'); - $blocks[1]['info'] = t('Details'); - return $blocks; - } - else if ($op == 'view') { - if (user_access('access content')) { - switch ($delta) { - case 0: - if (arg(0) == 'node' & is_numeric(arg(1))) { - $title = t('Who voted on it'); - $nid = arg(1); - $items = array(); - $votes = votingapi_get_content_votes('node', $nid); - foreach ($votes as $vote) { - $account = user_load(array('uid' => $vote[0]->uid, 'status' => 1)); - $items[] = theme('username', $account) .' ('. $vote[0]->value .')'; - } - $output = theme('item_list', $items); - } - break; - - case 1: - if (arg(0) == 'node' & is_numeric(arg(1))) { - $title = t('Details'); - $items = array(); - $votes = votingapi_get_content_votes('node', $node->nid); - $output = theme('item_list', $items); - } - break; - } - - $block['subject'] = $title; - $block['content'] = $output; - - return $block; - } - } -} - -/** * Implementation of hook_userpoints(). */ function vote_up_down_userpoints($op, $points = 0, $uid = 0, $event = NULL, $description = NULL) { @@ -344,7 +301,7 @@ '#collapsed' => TRUE, '#title' => t('Vote up/down points'), ); - + $form['vote_updown_points']['userpoints_vote_up_down'] = array( '#type' => 'textfield', '#title' => t('Points for voting on a node (requires the Vote up/down module)'), @@ -359,7 +316,7 @@ '#size' => 5, '#maxlength' => 5, ); - + return $form; break; } @@ -503,7 +460,7 @@ $node = db_fetch_object(db_query(db_rewrite_sql('SELECT n.uid FROM {node} n WHERE n.nid = %d'), $cid)); } else { - $node = db_fetch_object(db_query(db_rewrite_sql('SELECT c.uid FROM {comments} c WHERE c.cid = %d'), $cid)); + $node = db_fetch_object(db_query(db_rewrite_sql('SELECT c.uid FROM {comments} c WHERE c.cid = %d', 'c', 'cid'), $cid)); } $user_vote = votingapi_get_user_votes($type, $cid, $user->uid); if ($user->uid && !$user_vote && ($node->uid != $user->uid) && ($vote->value != 0)) { @@ -555,8 +512,8 @@ $class2 = 'vote-down-inact'; } - $output .= ''. l('', "vote_up_down/$type/$cid/1", array('class' => $class, 'title' => t('Vote up')), drupal_get_destination(), NULL, FALSE, TRUE) .''; - $output .= ''. l('', "vote_up_down/$type/$cid/-1", array('class' => $class2, 'title' => t('Vote down')), drupal_get_destination(), NULL, FALSE, TRUE) .''; + $output .= ''. l('', "vote_up_down/$type/$cid/1", array('class' => $class, 'title' => t('Vote up')), drupal_get_destination(), NULL, FALSE, TRUE) .''; + $output .= ''. l('', "vote_up_down/$type/$cid/-1", array('class' => $class2, 'title' => t('Vote down')), drupal_get_destination(), NULL, FALSE, TRUE) .''; } else { $output .= ''; @@ -587,7 +544,7 @@ $class = 'vote-up-inact'; } - $output .= ''. l('', "vote_up_down/$type/$cid/1", array('class' => $class, 'title' => t('Vote')), drupal_get_destination(), NULL, FALSE, TRUE) .''; + $output .= ''. l('', "vote_up_down/$type/$cid/1", array('class' => $class, 'title' => t('Vote')), drupal_get_destination(), NULL, FALSE, TRUE) .''; } else { @@ -605,23 +562,23 @@ if ($nodelink) { if ($vote_result) { $output = array( - 'title' => ''. format_plural($vote_result->value, '1 point', '@count points') .'', + 'title' => ''. format_plural($vote_result->value, '1 point', '@count points') .'', 'html' => TRUE ); } else { $output = array( - 'title' => ''. t('0 points') .'', + 'title' => ''. t('0 points') .'', 'html' => TRUE ); } } else { if ($vote_result) { - $output = ''. format_plural($vote_result->value, '1 point', '@count points') .''; + $output = ''. format_plural($vote_result->value, '1 point', '@count points') .''; } else { - $output = ''. t('0 points') .''; + $output = ''. t('0 points') .''; } } @@ -631,10 +588,10 @@ function theme_vote_up_down_points_alt($cid, $type) { $vote_result = votingapi_get_voting_result($type, $cid, 'points', variable_get('vote_up_down_tag', 'vote'), 'sum'); if ($vote_result) { - $output = '
'. $vote_result->value; + $output = '
'. $vote_result->value; } else { - $output = '
0'; + $output = '
0'; } $output .= '
'. format_plural($vote_result->value, 'point', 'points') .'
'; @@ -666,3 +623,8 @@ return $uid; } + + +function vote_up_down_hasvoted($type = 'node', $content_id, $uid) { + return (db_fetch_object(db_query("SELECT uid FROM {votingapi_vote} WHERE content_type = '%s' AND content_id = %d AND uid = %d", $type, $content_id, $uid))); +} \ No newline at end of file