View source
<?php
if (module_exists('views')) {
module_load_include('inc', 'vote_up_down', 'vote_up_down.views');
}
function vote_up_down_help($path, $arg) {
switch ($path) {
case 'admin/help#vote_up_down':
$output .= '<p>' . t('This module can be used to add an up/down voting widget to selected node types and comments.') . '</p>';
return $output;
}
}
function vote_up_down_perm() {
return array(
'view up/down votes',
'use vote up',
'use vote down',
'access vote up/down statistics',
'administer vote up/down',
);
}
function vote_up_down_access() {
return user_access('use vote up') || user_access('use vote down');
}
function vote_up_down_admin_settings() {
$form['vote_node_types'] = array(
'#type' => 'fieldset',
'#title' => t('Node types'),
'#description' => t('Select the node types you want to activate voting on.'),
);
$form['vote_node_types']['vote_up_down_node_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Types'),
'#default_value' => variable_get('vote_up_down_node_types', array()),
'#options' => node_get_types('names'),
);
$form['vote_widget_settings_node'] = array(
'#type' => 'fieldset',
'#title' => t('Vote widget settings for nodes'),
'#description' => t('For more control over the voting widget placement, it can be inserted directly in the theme. See the included template.php and node-storylink.tpl.php for an example. When this method is used, turn off the widget display here.'),
);
$form['vote_widget_settings_node']['vote_up_down_widget_style_node'] = array(
'#type' => 'radios',
'#title' => t('Vote widget style'),
'#default_value' => variable_get('vote_up_down_widget_style_node', 0),
'#options' => array(
0 => t('Default +1/-1 vote style'),
1 => t('Alternative +1 vote style'),
),
'#description' => t('If set to alternative style, it\'s recomended to turn off the link display of vote points.'),
);
$form['vote_widget_settings_node']['vote_up_down_widget_node'] = array(
'#type' => 'select',
'#title' => t('Vote widget display'),
'#default_value' => variable_get('vote_up_down_widget_node', 3),
'#options' => array(
0 => t('Disabled'),
1 => t('Teaser view'),
2 => t('Full-page view'),
3 => t('Teasers and full-page view'),
),
'#description' => t('When to display the vote widget for nodes?'),
);
$form['vote_widget_settings_node']['vote_up_down_link_node'] = array(
'#type' => 'select',
'#title' => t('Link display of vote points'),
'#default_value' => variable_get('vote_up_down_link_node', 3),
'#options' => array(
0 => t('Disabled'),
1 => t('Teaser view'),
2 => t('Full-page view'),
3 => t('Teasers and full-page view'),
),
'#description' => t('When to display vote points for nodes?'),
);
$form['vote_widget_settings_comment'] = array(
'#type' => 'fieldset',
'#title' => t('Vote widget settings for comments'),
'#description' => t('For more control over the voting widget placement, it can be inserted directly in the theme. See the included node-storylink.tpl.php for an example. When this method is used, turn off the widget display here.'),
);
$form['vote_widget_settings_comment']['vote_up_down_widget_style_comment'] = array(
'#type' => 'radios',
'#title' => t('Vote widget style'),
'#default_value' => variable_get('vote_up_down_widget_style_comment', 0),
'#options' => array(
0 => t('Default +1/-1 vote style'),
1 => t('Alternative +1 vote style'),
),
'#description' => t('If set to alternative style, it\'s recomended to turn off the link display of vote points.'),
);
$form['vote_widget_settings_comment']['vote_up_down_widget_comment'] = array(
'#type' => 'radios',
'#title' => t('Vote widget display'),
'#default_value' => variable_get('vote_up_down_widget_comment', 1),
'#options' => array(
0 => t('Do not display widget'),
1 => t('Display widget'),
),
);
$form['vote_widget_settings_comment']['vote_up_down_link_comment'] = array(
'#type' => 'radios',
'#title' => t('Link display of vote points'),
'#default_value' => variable_get('vote_up_down_link_comment', 1),
'#options' => array(
0 => t('Do not display link'),
1 => t('Display link'),
),
);
return system_settings_form($form);
}
function vote_up_down_admin_advanced_settings() {
$form['vote_widget_settings_advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced settings'),
);
$form['vote_widget_settings_advanced']['vote_up_down_anonymous_vote'] = array(
'#type' => 'radios',
'#title' => t('Allow anonymous voting'),
'#default_value' => variable_get('vote_up_down_anonymous_vote', 0),
'#options' => array(
0 => t('No'),
1 => t('Yes'),
),
'#description' => t('If yes, anonymous users may cast votes, restricted to one vote per day per IP address.<br />This will not work if "use vote up" & "use vote down" & "view up/down votes" permissions are not given to anonymous users.'),
);
$form['vote_widget_settings_advanced']['vote_up_down_reset_vote'] = array(
'#type' => 'radios',
'#title' => t('Allow users to reset their votes'),
'#default_value' => variable_get('vote_up_down_reset_vote', 0),
'#options' => array(
0 => t('No'),
1 => t('Yes'),
),
'#description' => t('If yes, a link will be displayed on nodes and comments that will allow users to reset their vote.'),
);
$form['vote_widget_settings_advanced']['vote_up_down_tag'] = array(
'#type' => 'textfield',
'#title' => t('Voting API tag'),
'#default_value' => variable_get('vote_up_down_tag', 'vote'),
'#description' => t('Since Vote Up/Down uses Voting API, all votes will be tagged with this term. (default: vote)<br />This tag is useful is you have deployed various modules that use Voting API. It should always be a unique value. Usually, there is NO need to change this.'),
);
return system_settings_form($form);
}
function vote_up_down_menu() {
$items = array();
$items['admin/settings/voteupdown'] = array(
'title' => 'Vote Up/Down configuration',
'description' => 'Control the functioning of Vote Up/Down.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'vote_up_down_admin_settings',
),
'access arguments' => array(
'administer vote up/down',
),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/settings/voteupdown/general'] = array(
'title' => 'General',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/settings/voteupdown/advanced'] = array(
'title' => 'Advanced',
'description' => 'Advanced configuration',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'vote_up_down_admin_advanced_settings',
),
'access arguments' => array(
'administer vote up/down',
),
'type' => MENU_LOCAL_TASK,
);
$items['vote_up_down'] = array(
'title' => 'Vote',
'page callback' => 'vote_up_down_vote',
'access callback' => 'vote_up_down_access',
'type' => MENU_CALLBACK,
);
$items['voteupdown'] = array(
'title' => 'Voting statistics',
'page callback' => 'vote_up_down_page',
'access arguments' => array(
'access vote up/down statistics',
),
);
$items['voteupdown/usersvotes'] = array(
'title' => 'Users by votes',
'page callback' => 'vote_up_down_page',
'access arguments' => array(
'access vote up/down statistics',
),
);
$items['node/%node/votes'] = array(
'title' => 'Voting details',
'page callback' => 'vote_up_down_tracker',
'page arguments' => array(
1,
),
'access callback' => 'vote_up_down_node_access',
'access arguments' => array(
1,
),
'type' => MENU_LOCAL_TASK,
);
$items['user/%user/votesupdown'] = array(
'title' => 'Your votes',
'page callback' => 'vote_up_down_user_votes',
'page arguments' => array(
1,
),
'access arguments' => array(
'access vote up/down statistics',
),
'type' => MENU_LOCAL_TASK,
);
return $items;
}
function vote_up_down_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
case 'view':
$widget = vote_up_down_widget_form($node);
if (!empty($widget)) {
$node->content['vote_up_down'] = array(
'#value' => $widget,
'#weight' => -10,
);
}
break;
}
}
function vote_up_down_preprocess_node(&$variables) {
if (user_access('view up/down votes')) {
$node = $variables['node'];
$node_type = in_array($node->type, variable_get('vote_up_down_node_types', array()), TRUE);
if ($node->nid && $node_type) {
$style = variable_get('vote_up_down_widget_style_node', 0) == 1 ? '_alt' : '';
$variables['vote_up_down'] = theme("vote_up_down_widget{$style}", $node->nid, 'node');
}
}
}
function vote_up_down_comment(&$comment, $op) {
switch ($op) {
case 'view':
if (variable_get('vote_up_down_widget_comment', 1)) {
if (user_access('view up/down votes')) {
$style = variable_get('vote_up_down_widget_style_comment', 0) == 1 ? '_alt' : '';
$comment->comment = theme("vote_up_down_widget{$style}", $comment->cid, 'comment') . $comment->comment;
}
}
break;
}
}
function vote_up_down_preprocess_comment(&$variables) {
if (user_access('view up/down votes')) {
$comment = $variables['comment'];
if ($comment->cid) {
$style = variable_get('vote_up_down_widget_style_comment', 0) == 1 ? '_alt' : '';
$variables['vote_up_down'] = theme("vote_up_down_widget{$style}", $comment->cid, 'comment');
}
}
}
function vote_up_down_link($type, $node = NULL, $teaser = FALSE) {
$links = array();
switch ($type) {
case 'node':
$node_type = in_array($node->type, variable_get('vote_up_down_node_types', array()), TRUE);
$style = variable_get('vote_up_down_widget_style_node', 0) == 1 ? '_alt' : '';
if ($node_type && user_access('view up/down votes')) {
if (variable_get('vote_up_down_reset_vote', 0) && (user_access('use vote up') || user_access('use vote down'))) {
$tag = variable_get('vote_up_down_tag', 'vote');
$criteria = array(
'content_type' => $type,
'content_id' => $node->nid,
'tag' => $tag,
);
$criteria += votingapi_current_user_identifier();
$user_vote = votingapi_select_single_vote_value($criteria);
if (!is_null($user_vote)) {
$token = drupal_get_token("vote_up_down/{$type}/{$node->nid}/0");
$links['vote_up_down_reset'] = array(
'title' => t('Reset vote'),
'href' => "vote_up_down/{$type}/{$node->nid}/0",
'attributes' => array(
'title' => t('Reset your vote.'),
),
'query' => drupal_get_destination() . '&token=' . $token,
);
}
}
if ($teaser && variable_get('vote_up_down_link_node', 0) && variable_get('vote_up_down_link_node', 0) != 2 && $style != "_alt") {
$links['vote_up_down_points'] = array(
'title' => theme('vote_up_down_points', $node->nid, $type),
'html' => TRUE,
);
}
else {
if (!$teaser && variable_get('vote_up_down_link_node', 0) > 1 && $style != "_alt") {
$links['vote_up_down_points'] = array(
'title' => theme('vote_up_down_points', $node->nid, $type),
'html' => TRUE,
);
}
}
}
break;
case 'comment':
if (variable_get('vote_up_down_reset_vote', 0) && (user_access('use vote up') || user_access('use vote down')) && (variable_get('vote_up_down_widget_comment', 0) || variable_get('vote_up_down_link_comment', 0))) {
$tag = variable_get('vote_up_down_tag', 'vote');
$criteria = array(
'content_type' => $type,
'content_id' => $node->cid,
'tag' => $tag,
);
$criteria += votingapi_current_user_identifier();
$user_vote = votingapi_select_single_vote_value($criteria);
if (!is_null($user_vote)) {
$token = drupal_get_token("vote_up_down/{$type}/{$node->cid}/0");
$links['vote_up_down_reset_c'] = array(
'title' => t('Reset vote'),
'href' => "vote_up_down/{$type}/{$node->cid}/0",
'attributes' => array(
'title' => t('Reset your vote.'),
),
'query' => drupal_get_destination() . '&token=' . $token,
);
}
}
if (variable_get('vote_up_down_link_comment', 0) && user_access('view up/down votes')) {
$links['vote_up_down_points_c'] = array(
'title' => theme('vote_up_down_points', $node->cid, $type, NULL),
'html' => TRUE,
);
}
break;
}
return $links;
}
function vote_up_down_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]['info'] = t('Who voted on this?');
return $blocks;
}
if ($op == 'view') {
$block = array();
switch ($delta) {
case 0:
if (arg(0) == 'node' & is_numeric(arg(1))) {
$node = node_load(arg(1));
if (!vote_up_down_node_access($node)) {
return;
}
$block['subject'] = t('Who voted on this?');
$nid = arg(1);
$tag = variable_get('vote_up_down_tag', 'vote');
$votes = array(
'content_id' => $nid,
'tag' => $tag,
);
$voteresults = votingapi_select_votes($votes);
$block['content'] = theme('vote_up_down_whovoted_block', $nid, $voteresults);
}
break;
}
return $block;
}
}
function vote_up_down_userpoints($op, $params = array()) {
switch ($op) {
case 'setting':
$form['vote_updown_points'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#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)'),
'#default_value' => variable_get('userpoints_vote_up_down', 0),
'#size' => 5,
'#maxlength' => 5,
);
$form['vote_updown_points']['userpoints_actions'] = array(
'#type' => 'textfield',
'#title' => t('Points for actions (requires the Actions module)'),
'#default_value' => variable_get('userpoints_actions', 0),
'#size' => 5,
'#maxlength' => 5,
);
return $form;
break;
}
}
function vote_up_down_page() {
$op = arg(1);
switch ($op) {
case 'usersvotes':
$output = vote_up_down_users_votes();
break;
default:
$items = array();
$items[] = l(t('Users by votes'), 'voteupdown/usersvotes');
$output = theme('item_list', $items);
}
return $output;
}
function vote_up_down_users_votes() {
$sql = "SELECT COUNT(v.value) AS number_votes, SUM(v.value) AS total_votes, v.uid, v.tag, u.uid, u.name FROM {votingapi_vote} v INNER JOIN {users} u on v.uid = u.uid WHERE v.tag = '%s' GROUP BY u.name";
$sql_cnt = "SELECT COUNT(DISTINCT(uid)) FROM {votingapi_vote}";
$header = array(
array(
'data' => t('User'),
'field' => 'u.name',
),
array(
'data' => t('Votes'),
'field' => 'number_votes',
'sort' => 'desc',
),
array(
'data' => t('Vote sum'),
'field' => 'total_votes',
),
);
$sql .= tablesort_sql($header);
$result = pager_query($sql, 30, 0, $sql_cnt, variable_get('vote_up_down_tag', 'vote'));
$rows = array();
while ($vote = db_fetch_object($result)) {
$rows[] = array(
theme('username', $vote),
$vote->number_votes,
$vote->total_votes,
);
}
drupal_set_title(t('Users by votes'));
$output = theme('table', $header, $rows);
$output .= theme('pager', NULL, 30, 0);
return $output;
}
function vote_up_down_tracker() {
if ($node = menu_get_object()) {
$header = array(
array(
'data' => t('User'),
),
array(
'data' => t('Vote'),
),
array(
'data' => t('Date'),
),
);
$tag = variable_get('vote_up_down_tag', 'vote');
$criteria = array(
'content_type' => 'node',
'content_id' => $node->nid,
'tag' => $tag,
);
$votes = votingapi_select_votes($criteria);
$rows = array();
foreach ($votes as $vote) {
$account = user_load(array(
'uid' => $vote['uid'],
'status' => 1,
));
$rows[] = array(
theme('username', $account),
$vote['value'],
array(
'data' => format_date($vote['timestamp'], 'small'),
'class' => 'nowrap',
),
);
}
drupal_set_title(check_plain($node->title));
$output = theme('table', $header, $rows);
$output .= theme('pager', NULL, 30);
return $output;
}
else {
drupal_not_found();
}
}
function vote_up_down_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('vote_up_down_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 {
drupal_not_found();
}
}
function vote_up_down_vote($type, $cid, $value, $tag = NULL, $ajax = FALSE, $alt = FALSE) {
if (is_numeric($cid) && is_numeric($value) && isset($_REQUEST['token']) && drupal_valid_token($_REQUEST['token'], "vote_up_down/{$type}/{$cid}/{$value}")) {
$vote = array();
if ($value > 0) {
$vote['value'] = 1;
}
else {
if ($value < 0) {
$vote['value'] = -1;
}
else {
$vote['value'] = 0;
}
}
$vote['value_type'] = 'points';
$tag = $tag ? $tag : variable_get('vote_up_down_tag', 'vote');
$vote['tag'] = $tag;
if (module_exists('userpoints')) {
global $user;
if ($type == 'node') {
$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', 'c', 'cid'), $cid));
}
$criteria = array(
'content_type' => $type,
'content_id' => $cid,
'uid' => $user->uid,
'tag' => $tag,
);
$user_vote = votingapi_select_single_vote_value($criteria);
if ($user->uid && !$user_vote && $node->uid != $user->uid && $vote['value'] != 0) {
userpoints_userpointsapi('points', variable_get('userpoints_vote_up_down', 0), $user->uid, 'Vote Up/Down points');
}
}
if ($vote['value'] == 0) {
$criteria = array(
'content_type' => $type,
'content_id' => $cid,
'tag' => $tag,
);
$criteria += votingapi_current_user_identifier();
votingapi_delete_votes(votingapi_select_votes($criteria));
votingapi_recalculate_results($type, $cid);
}
else {
$vote['content_id'] = $cid;
$vote['content_type'] = $type;
$votes = array(
0 => $vote,
);
votingapi_set_votes($votes);
}
if ($ajax) {
if ($alt == TRUE) {
print theme('vote_up_down_points_alt', $cid, $type, NULL, 'alt');
}
else {
print theme('vote_up_down_points', $cid, $type, NULL, '');
}
exit;
}
else {
drupal_goto(drupal_get_destination());
}
}
}
function template_preprocess_vote_up_down_widget(&$variables) {
global $user;
$cid = $variables['cid'];
$type = $variables['type'];
$tag = isset($variables['tag']) ? $variables['tag'] : variable_get('vote_up_down_tag', 'vote');
$variables['link1'] = '';
$variables['link2'] = '';
drupal_add_css(drupal_get_path('module', 'vote_up_down') . '/vote_up_down.css');
drupal_add_js(drupal_get_path('module', 'vote_up_down') . '/ajax_vote_up_down.js');
$variables['points'] = theme('vote_up_down_points', $cid, $type, $tag);
if ((user_access('use vote up') || user_access('use vote down')) && $user->uid || variable_get('vote_up_down_anonymous_vote', 0)) {
$criteria = array(
'content_type' => $type,
'content_id' => $cid,
'tag' => $tag,
);
$criteria += votingapi_current_user_identifier();
$user_vote = votingapi_select_single_vote_value($criteria);
if ($user_vote > 0) {
$variables['class1'] = 'vote-up-act';
$variables['class2'] = 'vote-down-inact';
}
else {
if ($user_vote < 0) {
$variables['class1'] = 'vote-up-inact';
$variables['class2'] = 'vote-down-act';
}
else {
$variables['class1'] = 'vote-up-inact';
$variables['class2'] = 'vote-down-inact';
}
}
if (user_access('use vote up')) {
$token = drupal_get_token("vote_up_down/{$type}/{$cid}/1");
$variables['title1'] = url("vote_up_down/{$type}/{$cid}/1/{$tag}/1", array(
'query' => 'token=' . $token,
));
$variables['link1'] = l('', "vote_up_down/{$type}/{$cid}/1/{$tag}", array(
'attributes' => array(
'class' => $variables['class1'],
'title' => t('Vote up'),
),
'query' => drupal_get_destination() . '&token=' . $token,
));
}
else {
$variables['class1'] = 'up-inact';
$variables['title1'] = t('You have no privileges to vote up.');
}
if (user_access('use vote down')) {
$token = drupal_get_token("vote_up_down/{$type}/{$cid}/-1");
$variables['title2'] = url("vote_up_down/{$type}/{$cid}/-1/{$tag}/-1", array(
'query' => 'token=' . $token,
));
$variables['link2'] = l('', "vote_up_down/{$type}/{$cid}/-1/{$tag}", array(
'attributes' => array(
'class' => $variables['class2'],
'title' => t('Vote down'),
),
'query' => drupal_get_destination() . '&token=' . $token,
));
}
else {
$variables['class2'] = 'down-inact';
$variables['title2'] = t('You have no privileges to vote down.');
}
}
else {
$variables['class1'] = 'up-inact';
$variables['class2'] = 'down-inact';
$variables['title1'] = t('You must login to vote!');
$variables['title2'] = t('You must login to vote!');
}
}
function template_preprocess_vote_up_down_widget_alt(&$variables) {
global $user;
$cid = $variables['cid'];
$type = $variables['type'];
$tag = isset($variables['tag']) ? $variables['tag'] : variable_get('vote_up_down_tag', 'vote');
drupal_add_css(drupal_get_path('module', 'vote_up_down') . '/vote_up_down.css');
drupal_add_js(drupal_get_path('module', 'vote_up_down') . '/ajax_vote_up_down.js');
$variables['points'] = theme('vote_up_down_points_alt', $cid, $type, $tag, 'alt');
if ((user_access('use vote up') || user_access('use vote down')) && ($user->uid || variable_get('vote_up_down_anonymous_vote', 0))) {
$criteria = array(
'content_type' => $type,
'content_id' => $cid,
'tag' => $tag,
);
$criteria += votingapi_current_user_identifier();
$user_vote = votingapi_select_single_vote_value($criteria);
if ($user_vote > 0) {
$variables['class'] = 'vote-up-act';
}
else {
$variables['class'] = 'vote-up-inact';
}
$token = drupal_get_token("vote_up_down/{$type}/{$cid}/1");
$variables['title'] = url("vote_up_down/{$type}/{$cid}/1/{$tag}/1/alt", array(
'query' => 'token=' . $token,
));
$variables['link'] = l('', "vote_up_down/{$type}/{$cid}/1/{$tag}", array(
'attributes' => array(
'class' => $variables['class'],
'title' => t('Vote up'),
),
'query' => drupal_get_destination() . '&token=' . $token,
));
}
else {
$variables['class'] = 'up-inact';
$variables['title'] = t('You must login to vote!');
}
}
function template_preprocess_vote_up_down_points(&$variables) {
$tag = isset($variables['tag']) ? $variables['tag'] : variable_get('vote_up_down_tag', 'vote');
$criteria = array(
'content_type' => $variables['type'],
'content_id' => $variables['cid'],
'value_type' => 'points',
'tag' => $tag,
'function' => 'sum',
);
$vote_result = (int) votingapi_select_single_result_value($criteria);
if ($vote_result > 0) {
$variables['class'] = 'positive';
}
else {
if ($vote_result < 0) {
$variables['class'] = 'negative';
}
else {
$variables['class'] = 'neutral';
}
}
$variables['points_labelled'] = format_plural($vote_result, '1 point', '@count points');
}
function template_preprocess_vote_up_down_points_alt(&$variables) {
$tag = isset($variables['tag']) ? $variables['tag'] : variable_get('vote_up_down_tag', 'vote');
$criteria = array(
'content_type' => $variables['type'],
'content_id' => $variables['cid'],
'value_type' => 'points',
'tag' => $tag,
'function' => 'sum',
);
$vote_result = (int) votingapi_select_single_result_value($criteria);
if ($vote_result > 0) {
$variables['class'] = 'positive';
$variables['points'] = '+' . $vote_result;
}
else {
$variables['points'] = $vote_result;
if ($vote_result < 0) {
$variables['class'] = 'negative';
}
else {
$variables['class'] = 'neutral';
}
}
$variables['label'] = format_plural($vote_result, 'point', 'points');
}
function theme_vote_up_down_whovoted_block($nid, $voteresults) {
if ($voteresults) {
$items = array();
foreach ($voteresults as $vote) {
$account = user_load(array(
'uid' => $vote['uid'],
'status' => 1,
));
$items[] = theme('username', $account) . ' (' . $vote['value'] . ')';
}
$output = theme('item_list', $items);
}
else {
$output = t('No one\'s voted yet! Why don\'t you?');
}
return $output;
}
function vote_up_down_theme() {
return array(
'vote_up_down_widget' => array(
'file' => 'vote_up_down.module',
'arguments' => array(
'cid' => NULL,
'type' => NULL,
),
'template' => 'theme/vote_up_down_widget',
),
'vote_up_down_widget_alt' => array(
'file' => 'vote_up_down.module',
'arguments' => array(
'cid' => NULL,
'type' => NULL,
),
'template' => 'theme/vote_up_down_widget_alt',
),
'vote_up_down_points' => array(
'file' => 'vote_up_down.module',
'arguments' => array(
'cid' => NULL,
'type' => NULL,
'tag' => NULL,
),
'template' => 'theme/vote_up_down_points',
),
'vote_up_down_points_alt' => array(
'file' => 'vote_up_down.module',
'arguments' => array(
'cid' => NULL,
'type' => NULL,
'tag' => NULL,
),
'template' => 'theme/vote_up_down_points_alt',
),
'vote_up_down_whovoted_block' => array(
'file' => 'vote_up_down.module',
'arguments' => array(
'nid' => NULL,
'voteresults' => NULL,
),
),
);
}
function vote_up_down_node_access($node, $perm = 'access vote up/down statistics') {
if (user_access($perm)) {
return in_array($node->type, variable_get('vote_up_down_node_types', array()), TRUE);
}
return FALSE;
}
function vote_up_down_widget_form($node) {
$teaser = $node->teaser;
$return = '';
if (user_access('view up/down votes')) {
$node_type = in_array($node->type, variable_get('vote_up_down_node_types', array()), TRUE);
if ($node_type) {
$style = variable_get('vote_up_down_widget_style_node', 0) == 1 ? '_alt' : '';
if ($teaser && variable_get('vote_up_down_widget_node', 0) && variable_get('vote_up_down_widget_node', 0) != 2) {
$return = theme("vote_up_down_widget{$style}", $node->nid, 'node');
}
else {
if (!$teaser && variable_get('vote_up_down_widget_node', 0) > 1) {
$return = theme("vote_up_down_widget{$style}", $node->nid, 'node');
}
}
}
}
return $return;
}
function vote_up_down_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'vote_up_down') . '/views',
);
}