| 1 |
<?php
|
| 2 |
// $Id: vote_up_down.module,v 1.23 2008/10/02 13:17:13 lut4rp Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* vote_up_down is a module that adds a widget for +1/-1 votes on nodes.
|
| 7 |
* It depends upon Voting API.
|
| 8 |
* It's based upon "simplevote.module".
|
| 9 |
*/
|
| 10 |
|
| 11 |
// if (module_exists('views')) {
|
| 12 |
// module_load_include('inc', 'vote_up_down', 'ote_up_down_views');
|
| 13 |
// }
|
| 14 |
|
| 15 |
if (module_exists('actions')) {
|
| 16 |
module_load_include('inc', 'vote_up_down', 'vote_up_down_actions');
|
| 17 |
}
|
| 18 |
|
| 19 |
/**
|
| 20 |
* Implementation of hook_help().
|
| 21 |
*/
|
| 22 |
function vote_up_down_help($path, $arg) {
|
| 23 |
switch ($path) {
|
| 24 |
case 'admin/help#vote_up_down':
|
| 25 |
return t('<p>This module is used to add a up/down voting widget to selected node types. (Part of Vote up/down package)</p>');
|
| 26 |
}
|
| 27 |
}
|
| 28 |
|
| 29 |
/**
|
| 30 |
* Implementation of hook_perm().
|
| 31 |
*/
|
| 32 |
function vote_up_down_perm() {
|
| 33 |
return array('view up/down votes', 'use vote up/down', 'access vote up/down statistics', 'administer vote up/down');
|
| 34 |
}
|
| 35 |
|
| 36 |
/**
|
| 37 |
* Implementation of hook_settings().
|
| 38 |
*/
|
| 39 |
function vote_up_down_admin_settings() {
|
| 40 |
|
| 41 |
$form['vote_node_types'] = array(
|
| 42 |
'#type' => 'fieldset',
|
| 43 |
'#title' => t('Node types'),
|
| 44 |
'#description' => t('Set the node types you want to activate voting on.'),
|
| 45 |
'#collapsible' => TRUE,
|
| 46 |
);
|
| 47 |
$form['vote_node_types']['vote_up_down_node_types'] = array(
|
| 48 |
'#type' => 'checkboxes',
|
| 49 |
'#title' => t('Types'),
|
| 50 |
'#default_value' => variable_get('vote_up_down_node_types', array()),
|
| 51 |
'#options' => node_get_types('names'),
|
| 52 |
);
|
| 53 |
|
| 54 |
$form['vote_widget_settings_node'] = array(
|
| 55 |
'#type' => 'fieldset',
|
| 56 |
'#title' => t('Vote widget settings for nodes'),
|
| 57 |
'#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.'),
|
| 58 |
'#collapsible' => TRUE,
|
| 59 |
'#collapsed' => TRUE,
|
| 60 |
);
|
| 61 |
$form['vote_widget_settings_node']['vote_up_down_widget_style_node'] = array(
|
| 62 |
'#type' => 'radios',
|
| 63 |
'#title' => t('Vote widget style'),
|
| 64 |
'#default_value' => variable_get('vote_up_down_widget_style_node', 0),
|
| 65 |
'#options' => array(0 => t('Default +1/-1 vote style'), 1 => t('Alternative +1 vote style')),
|
| 66 |
'#description' => t('If set to alternative style it\'s recomended to turn off the link display of vote points.'),
|
| 67 |
);
|
| 68 |
$form['vote_widget_settings_node']['vote_up_down_widget_node'] = array(
|
| 69 |
'#type' => 'select',
|
| 70 |
'#title' => t('Vote widget display'),
|
| 71 |
'#default_value' => variable_get('vote_up_down_widget_node', 3),
|
| 72 |
'#options' => array(0 => t('Disabled'), 1 => t('Teaser view'), 2 => t('Full-page view'), 3 => t('Teasers and full-page view')),
|
| 73 |
'#description' => t('When to display the vote widget for nodes.'),
|
| 74 |
);
|
| 75 |
$form['vote_widget_settings_node']['vote_up_down_link_node'] = array(
|
| 76 |
'#type' => 'select',
|
| 77 |
'#title' => t('Link display of vote points'),
|
| 78 |
'#default_value' => variable_get('vote_up_down_link_node', 3),
|
| 79 |
'#options' => array(0 => t('Disabled'), 1 => t('Teaser view'), 2 => t('Full-page view'), 3 => t('Teasers and full-page view')),
|
| 80 |
'#description' => t('When to display vote points for nodes.'),
|
| 81 |
);
|
| 82 |
|
| 83 |
$form['vote_widget_settings_comment'] = array(
|
| 84 |
'#type' => 'fieldset',
|
| 85 |
'#title' => t('Vote widget settings for comments'),
|
| 86 |
'#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 metod is used turn off the widget display here.'),
|
| 87 |
'#collapsible' => TRUE,
|
| 88 |
'#collapsed' => TRUE,
|
| 89 |
);
|
| 90 |
$form['vote_widget_settings_comment']['vote_up_down_widget_style_comment'] = array(
|
| 91 |
'#type' => 'radios',
|
| 92 |
'#title' => t('Vote widget style'),
|
| 93 |
'#default_value' => variable_get('vote_up_down_widget_style_comment', 0),
|
| 94 |
'#options' => array(0 => t('Default +1/-1 vote style'), 1 => t('Alternative +1 vote style')),
|
| 95 |
'#description' => t('If set to alternative style it\'s recomended to turn off the link display of vote points.'),
|
| 96 |
);
|
| 97 |
$form['vote_widget_settings_comment']['vote_up_down_widget_comment'] = array(
|
| 98 |
'#type' => 'radios',
|
| 99 |
'#title' => t('Vote widget display'),
|
| 100 |
'#default_value' => variable_get('vote_up_down_widget_comment', 1),
|
| 101 |
'#options' => array(0 => t('Do not display widget'), 1 => t('Display widget')),
|
| 102 |
);
|
| 103 |
$form['vote_widget_settings_comment']['vote_up_down_link_comment'] = array(
|
| 104 |
'#type' => 'radios',
|
| 105 |
'#title' => t('Link display of vote points'),
|
| 106 |
'#default_value' => variable_get('vote_up_down_link_comment', 1),
|
| 107 |
'#options' => array(0 => t('Do not display link'), 1 => t('Display link')),
|
| 108 |
);
|
| 109 |
|
| 110 |
$form['vote_widget_settings_advanced'] = array(
|
| 111 |
'#type' => 'fieldset',
|
| 112 |
'#title' => t('Advanced settings'),
|
| 113 |
'#collapsible' => TRUE,
|
| 114 |
'#collapsed' => TRUE,
|
| 115 |
);
|
| 116 |
$form['vote_widget_settings_advanced']['vote_up_down_tag'] = array(
|
| 117 |
'#type' => 'textfield',
|
| 118 |
'#title' => t('Vote tag'),
|
| 119 |
'#default_value' => variable_get('vote_up_down_tag', 'vote'),
|
| 120 |
'#description' => t('All votes from the Vote up/down module will be tagged with this term. Using a unique value here may be useful when you deploy various voting modules that all use the Voting API. (Default: vote)'),
|
| 121 |
);
|
| 122 |
$form['vote_widget_settings_advanced']['vote_up_down_anonymous_vote'] = array(
|
| 123 |
'#type' => 'radios',
|
| 124 |
'#title' => t('Allow anonymous voting'),
|
| 125 |
'#default_value' => variable_get('vote_up_down_anonymous_vote', 0),
|
| 126 |
'#options' => array(0 => t('No'), 1 => t('Yes')),
|
| 127 |
'#description' => t('If yes anonymous users may cast votes, restricted to one vote per day and IP address.'),
|
| 128 |
);
|
| 129 |
$form['vote_widget_settings_advanced']['vote_up_down_reset_vote'] = array(
|
| 130 |
'#type' => 'radios',
|
| 131 |
'#title' => t('Allow users to reset their votes'),
|
| 132 |
'#default_value' => variable_get('vote_up_down_reset_vote', 0),
|
| 133 |
'#options' => array(0 => t('No'), 1 => t('Yes')),
|
| 134 |
'#description' => t('If yes a link will be displayd on nodes and commets that will reset the users votes on that node/comment.'),
|
| 135 |
);
|
| 136 |
|
| 137 |
return system_settings_form($form);
|
| 138 |
}
|
| 139 |
|
| 140 |
/**
|
| 141 |
* Implementation of hook_menu().
|
| 142 |
*/
|
| 143 |
function vote_up_down_menu() {
|
| 144 |
$items = array();
|
| 145 |
|
| 146 |
$items['admin/settings/voteupdown'] = array(
|
| 147 |
'title' => 'Vote up/down',
|
| 148 |
'description' => 'Control the functions of Vote up/down.',
|
| 149 |
'page callback' => 'drupal_get_form',
|
| 150 |
'page arguments' => array('vote_up_down_admin_settings'),
|
| 151 |
'access arguments' => array('administer vote up/down'),
|
| 152 |
'type' => MENU_NORMAL_ITEM
|
| 153 |
);
|
| 154 |
|
| 155 |
$items['vote_up_down'] = array(
|
| 156 |
'title' => 'Vote on content',
|
| 157 |
'page callback' => 'vote_up_down_vote',
|
| 158 |
'access arguments' => array('use vote up/down'),
|
| 159 |
'type' => MENU_CALLBACK
|
| 160 |
);
|
| 161 |
|
| 162 |
$items['voteupdown'] = array(
|
| 163 |
'title' => 'Vote up/down',
|
| 164 |
'description' => 'Vote up/down vote summaries.',
|
| 165 |
'page callback' => 'vote_up_down_page',
|
| 166 |
'access arguments' => array('access vote up/down statistics'),
|
| 167 |
);
|
| 168 |
|
| 169 |
$items['voteupdown/usersvotes'] = array(
|
| 170 |
'title' => 'Users by votes',
|
| 171 |
'page callback' => 'vote_up_down_page',
|
| 172 |
'access arguments' => array('access vote up/down statistics'),
|
| 173 |
);
|
| 174 |
|
| 175 |
if (arg(0) == 'node' && is_numeric(arg(1))) {
|
| 176 |
$node = node_load(arg(1));
|
| 177 |
$vote_access = (user_access('access vote up/down statistics') && in_array($node->type, variable_get('vote_up_down_node_types', array()), TRUE));
|
| 178 |
$items['node/'.'%'.'/votesupdown'] = array(
|
| 179 |
'title' => 'Votes',
|
| 180 |
'page callback' => 'vote_up_down_tracker',
|
| 181 |
'access arguments' => $vote_access,
|
| 182 |
'weight' => 5,
|
| 183 |
'type' => MENU_LOCAL_TASK
|
| 184 |
);
|
| 185 |
}
|
| 186 |
|
| 187 |
|
| 188 |
if (arg(0) == 'user' && is_numeric(arg(1))) {
|
| 189 |
$items['user/'.'%'.'/votesupdown'] = array(
|
| 190 |
'title' => 'Votes',
|
| 191 |
'page callback' => 'vote_up_down_user_votes',
|
| 192 |
'access arguments' => array('access vote up/down statistics'),
|
| 193 |
'weight' => 5,
|
| 194 |
'type' => MENU_LOCAL_TASK
|
| 195 |
);
|
| 196 |
}
|
| 197 |
|
| 198 |
drupal_add_css(drupal_get_path('module', 'vote_up_down') .'/vote_up_down.css');
|
| 199 |
drupal_add_js(drupal_get_path('module', 'vote_up_down') .'/ajax_vote_up_down.js');
|
| 200 |
|
| 201 |
return $items;
|
| 202 |
}
|
| 203 |
|
| 204 |
/**
|
| 205 |
* Implementation of hook_nodeapi().
|
| 206 |
*/
|
| 207 |
function vote_up_down_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
|
| 208 |
switch ($op) {
|
| 209 |
case 'view':
|
| 210 |
$node_type = in_array($node->type, variable_get('vote_up_down_node_types', array()), TRUE);
|
| 211 |
if ($node_type) {
|
| 212 |
$style = variable_get('vote_up_down_widget_style_node', 0) == 1 ? '_alt' : '';
|
| 213 |
if ($teaser && variable_get('vote_up_down_widget_node', 0) && variable_get('vote_up_down_widget_node', 0) != 2) {
|
| 214 |
$node->content['vote_up_down'] = array(
|
| 215 |
'#value' => theme("vote_up_down_widget$style", $node->nid, 'node'),
|
| 216 |
'#weight' => -10,
|
| 217 |
);
|
| 218 |
}
|
| 219 |
else if (!$teaser && variable_get('vote_up_down_widget_node', 0) > 1) {
|
| 220 |
$node->content['vote_up_down'] = array(
|
| 221 |
'#value' => theme("vote_up_down_widget$style", $node->nid, 'node'),
|
| 222 |
'#weight' => -10,
|
| 223 |
);
|
| 224 |
}
|
| 225 |
}
|
| 226 |
break;
|
| 227 |
}
|
| 228 |
}
|
| 229 |
|
| 230 |
/**
|
| 231 |
* Implementation of hook_comment().
|
| 232 |
*/
|
| 233 |
function vote_up_down_comment(&$comment, $op) {
|
| 234 |
switch ($op) {
|
| 235 |
case 'view':
|
| 236 |
if (variable_get('vote_up_down_widget_comment', 1)) {
|
| 237 |
$style = variable_get('vote_up_down_widget_style_comment', 0) == 1 ? '_alt' : '';
|
| 238 |
$comment->comment = theme("vote_up_down_widget$style", $comment->cid, 'comment') . $comment->comment;
|
| 239 |
}
|
| 240 |
break;
|
| 241 |
}
|
| 242 |
}
|
| 243 |
|
| 244 |
/**
|
| 245 |
* Implementation of hook_link().
|
| 246 |
*/
|
| 247 |
function vote_up_down_link($type, $node = NULL, $teaser = FALSE) {
|
| 248 |
$links = array();
|
| 249 |
switch ($type) {
|
| 250 |
case 'node':
|
| 251 |
$node_type = in_array($node->type, variable_get('vote_up_down_node_types', array()), TRUE);
|
| 252 |
if ($node_type && user_access('view up/down votes')) {
|
| 253 |
if (variable_get('vote_up_down_reset_vote', 0) && user_access('use vote up/down')) {
|
| 254 |
$links['vote_up_down_reset'] = array(
|
| 255 |
'title' => t('Reset vote'),
|
| 256 |
'href' => "vote_up_down/$type/$node->nid/0",
|
| 257 |
'attributes' => array('title' => t('Reset your vote.')),
|
| 258 |
'query' => drupal_get_destination()
|
| 259 |
);
|
| 260 |
}
|
| 261 |
if ($teaser && variable_get('vote_up_down_link_node', 0) && variable_get('vote_up_down_link_node', 0) != 2) {
|
| 262 |
$links['vote_up_down_points'] = theme('vote_up_down_points', $node->nid, $type, TRUE);
|
| 263 |
}
|
| 264 |
else if (!$teaser && variable_get('vote_up_down_link_node', 0) > 1) {
|
| 265 |
$links['vote_up_down_points'] = theme('vote_up_down_points', $node->nid, $type, TRUE);
|
| 266 |
}
|
| 267 |
}
|
| 268 |
break;
|
| 269 |
case 'comment':
|
| 270 |
if (variable_get('vote_up_down_reset_vote', 0) && user_access('use vote up/down') && variable_get('vote_up_down_widget_comment', 0)) {
|
| 271 |
$links['vote_up_down_reset_c'] = array(
|
| 272 |
'title' => t('Reset vote'),
|
| 273 |
'href' => "vote_up_down/$type/$node->cid/0",
|
| 274 |
'attributes' => array('title' => t('Reset your vote.')),
|
| 275 |
'query' => drupal_get_destination()
|
| 276 |
);
|
| 277 |
}
|
| 278 |
if (variable_get('vote_up_down_link_comment', 0) && user_access('view up/down votes')) {
|
| 279 |
$links['vote_up_down_points_c'] = theme('vote_up_down_points', $node->cid, $type, TRUE);
|
| 280 |
}
|
| 281 |
break;
|
| 282 |
}
|
| 283 |
|
| 284 |
return $links;
|
| 285 |
}
|
| 286 |
|
| 287 |
/**
|
| 288 |
* Implementation of hook_block().
|
| 289 |
*/
|
| 290 |
function vote_up_down_block($op = 'list', $delta = 0) {
|
| 291 |
if ($op == 'list') {
|
| 292 |
$blocks[0]['info'] = t('Who voted on it');
|
| 293 |
$blocks[1]['info'] = t('Details');
|
| 294 |
return $blocks;
|
| 295 |
}
|
| 296 |
else if ($op == 'view') {
|
| 297 |
if (user_access('access content')) {
|
| 298 |
switch ($delta) {
|
| 299 |
case 0:
|
| 300 |
if (arg(0) == 'node' & is_numeric(arg(1))) {
|
| 301 |
$title = t('Who voted on it');
|
| 302 |
$nid = arg(1);
|
| 303 |
$items = array();
|
| 304 |
$votes = votingapi_get_content_votes('node', $nid);
|
| 305 |
foreach ($votes as $vote) {
|
| 306 |
$account = user_load(array('uid' => $vote[0]->uid, 'status' => 1));
|
| 307 |
$items[] = theme('username', $account) .' ('. $vote[0]->value .')';
|
| 308 |
}
|
| 309 |
$output = theme('item_list', $items);
|
| 310 |
}
|
| 311 |
break;
|
| 312 |
|
| 313 |
case 1:
|
| 314 |
if (arg(0) == 'node' & is_numeric(arg(1))) {
|
| 315 |
$title = t('Details');
|
| 316 |
$items = array();
|
| 317 |
$votes = votingapi_get_content_votes('node', $node->nid);
|
| 318 |
$output = theme('item_list', $items);
|
| 319 |
}
|
| 320 |
break;
|
| 321 |
}
|
| 322 |
|
| 323 |
$block['subject'] = $title;
|
| 324 |
$block['content'] = $output;
|
| 325 |
|
| 326 |
return $block;
|
| 327 |
}
|
| 328 |
}
|
| 329 |
}
|
| 330 |
|
| 331 |
/**
|
| 332 |
* Implementation of hook_userpoints().
|
| 333 |
*/
|
| 334 |
function vote_up_down_userpoints($op, $points = 0, $uid = 0, $event = NULL, $description = NULL) {
|
| 335 |
switch ($op) {
|
| 336 |
case 'setting':
|
| 337 |
$form['vote_updown_points'] = array(
|
| 338 |
'#type' => 'fieldset',
|
| 339 |
'#collapsible' => TRUE,
|
| 340 |
'#collapsed' => TRUE,
|
| 341 |
'#title' => t('Vote up/down points'),
|
| 342 |
);
|
| 343 |
|
| 344 |
$form['vote_updown_points']['userpoints_vote_up_down'] = array(
|
| 345 |
'#type' => 'textfield',
|
| 346 |
'#title' => t('Points for voting on a node (requires the Vote up/down module)'),
|
| 347 |
'#default_value' => variable_get('userpoints_vote_up_down', 0),
|
| 348 |
'#size' => 5,
|
| 349 |
'#maxlength' => 5,
|
| 350 |
);
|
| 351 |
$form['vote_updown_points']['userpoints_actions'] = array(
|
| 352 |
'#type' => 'textfield',
|
| 353 |
'#title' => t('Points for actions (requires the Actions module)'),
|
| 354 |
'#default_value' => variable_get('userpoints_actions', 0),
|
| 355 |
'#size' => 5,
|
| 356 |
'#maxlength' => 5,
|
| 357 |
);
|
| 358 |
|
| 359 |
return $form;
|
| 360 |
break;
|
| 361 |
}
|
| 362 |
}
|
| 363 |
|
| 364 |
/*
|
| 365 |
* Menu callback; Handles voteupdown and subpages.
|
| 366 |
*/
|
| 367 |
function vote_up_down_page() {
|
| 368 |
$op = arg(1);
|
| 369 |
|
| 370 |
switch ($op) {
|
| 371 |
case 'usersvotes':
|
| 372 |
$output = vote_up_down_users_votes();
|
| 373 |
break;
|
| 374 |
default:
|
| 375 |
$items = array();
|
| 376 |
$items[] = l(t('Users by votes'), 'voteupdown/usersvotes');
|
| 377 |
$output = theme('item_list', $items, t('Vote up/down statistics'));
|
| 378 |
}
|
| 379 |
|
| 380 |
return $output;
|
| 381 |
}
|
| 382 |
|
| 383 |
/*
|
| 384 |
* Users votes page for the vote_up_down data
|
| 385 |
*/
|
| 386 |
function vote_up_down_users_votes() {
|
| 387 |
$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";
|
| 388 |
$sql_cnt = "SELECT COUNT(DISTINCT(uid)) FROM {votingapi_vote}";
|
| 389 |
$header = array(
|
| 390 |
array('data' => t('User'), 'field' => 'u.name'),
|
| 391 |
array('data' => t('Votes'), 'field' => 'number_votes', 'sort' => 'desc'),
|
| 392 |
array('data' => t('Vote sum'), 'field' => 'total_votes'),
|
| 393 |
);
|
| 394 |
$sql .= tablesort_sql($header);
|
| 395 |
$result = pager_query($sql, 30, 0, $sql_cnt, variable_get('vote_up_down_tag', 'vote'));
|
| 396 |
while ($vote = db_fetch_object($result)) {
|
| 397 |
$rows[] = array(
|
| 398 |
theme('username', $vote),
|
| 399 |
$vote->number_votes,
|
| 400 |
$vote->total_votes
|
| 401 |
);
|
| 402 |
}
|
| 403 |
drupal_set_title(t('Users by votes'));
|
| 404 |
$output = theme('table', $header, $rows);
|
| 405 |
$output .= theme('pager', NULL, 30, 0);
|
| 406 |
|
| 407 |
return $output;
|
| 408 |
}
|
| 409 |
|
| 410 |
/*
|
| 411 |
* Menu callback; display all votes for a node.
|
| 412 |
*/
|
| 413 |
function vote_up_down_tracker() {
|
| 414 |
if ($node = node_load(arg(1))) {
|
| 415 |
$header = array(
|
| 416 |
array('data' => t('User')),
|
| 417 |
array('data' => t('Vote')),
|
| 418 |
array('data' => t('Date'))
|
| 419 |
);
|
| 420 |
$votes = votingapi_get_content_votes('node', $node->nid);
|
| 421 |
foreach ($votes as $vote) {
|
| 422 |
$account = user_load(array('uid' => $vote[0]->uid, 'status' => 1));
|
| 423 |
$rows[] = array(
|
| 424 |
theme('username', $account),
|
| 425 |
$vote[0]->value,
|
| 426 |
array('data' => format_date($vote[0]->timestamp, 'small'), 'class' => 'nowrap')
|
| 427 |
);
|
| 428 |
}
|
| 429 |
drupal_set_title(check_plain($node->title));
|
| 430 |
$output = theme('table', $header, $rows);
|
| 431 |
$output .= theme('pager', NULL, 30);
|
| 432 |
|
| 433 |
return $output;
|
| 434 |
}
|
| 435 |
else {
|
| 436 |
drupal_not_found();
|
| 437 |
}
|
| 438 |
}
|
| 439 |
|
| 440 |
/*
|
| 441 |
* Menu callback; display all votes for a user.
|
| 442 |
*/
|
| 443 |
function vote_up_down_user_votes() {
|
| 444 |
if ($account = user_load(array('uid' => arg(1), 'status' => 1))) {
|
| 445 |
if ($account->status || user_access('administer users')) {
|
| 446 |
$header = array(
|
| 447 |
array('data' => t('Node')),
|
| 448 |
array('data' => t('Vote')),
|
| 449 |
array('data' => t('Date'))
|
| 450 |
);
|
| 451 |
$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");
|
| 452 |
$result = pager_query($sql, 25, 0, NULL, $account->uid, variable_get('vote_up_down_tag', 'vote'));
|
| 453 |
while ($node = db_fetch_object($result)) {
|
| 454 |
$rows[] = array(
|
| 455 |
l($node->title, 'node/'. $node->nid),
|
| 456 |
$node->value,
|
| 457 |
t('!time ago', array('!time' => format_interval(time() - $node->timestamp)))
|
| 458 |
);
|
| 459 |
}
|
| 460 |
drupal_set_title(check_plain($account->name));
|
| 461 |
$output = theme('table', $header, $rows);
|
| 462 |
$output .= theme('pager', NULL, 25);
|
| 463 |
|
| 464 |
return $output;
|
| 465 |
}
|
| 466 |
else {
|
| 467 |
drupal_access_denied();
|
| 468 |
}
|
| 469 |
}
|
| 470 |
else {
|
| 471 |
drupal_not_found();
|
| 472 |
}
|
| 473 |
}
|
| 474 |
|
| 475 |
/**
|
| 476 |
* An voting get handler with AJAX support
|
| 477 |
*/
|
| 478 |
function vote_up_down_vote($type, $cid, $value, $ajax = FALSE, $alt = FALSE) {
|
| 479 |
if (is_numeric($cid) && is_numeric($value)) {
|
| 480 |
|
| 481 |
// Sanity-check the incoming values.
|
| 482 |
if ($value > 0) {
|
| 483 |
$vote->value = 1;
|
| 484 |
}
|
| 485 |
else if ($value < 0) {
|
| 486 |
$vote->value = -1;
|
| 487 |
}
|
| 488 |
else {
|
| 489 |
$vote->value = 0;
|
| 490 |
}
|
| 491 |
|
| 492 |
$vote->value_type = 'points';
|
| 493 |
$vote->tag = variable_get('vote_up_down_tag', 'vote');
|
| 494 |
|
| 495 |
// Userpoints integration.
|
| 496 |
if (module_exists('userpoints')) {
|
| 497 |
global $user;
|
| 498 |
if ($type == 'node') {
|
| 499 |
$node = db_fetch_object(db_query(db_rewrite_sql('SELECT n.uid FROM {node} n WHERE n.nid = %d'), $cid));
|
| 500 |
}
|
| 501 |
else {
|
| 502 |
$node = db_fetch_object(db_query(db_rewrite_sql('SELECT c.uid FROM {comments} c WHERE c.cid = %d'), $cid));
|
| 503 |
}
|
| 504 |
$user_vote = votingapi_get_user_votes($type, $cid, $user->uid);
|
| 505 |
if ($user->uid && !$user_vote && ($node->uid != $user->uid) && ($vote->value != 0)) {
|
| 506 |
userpoints_userpointsapi('points', variable_get('userpoints_vote_up_down', 0), $user->uid, 'Vote up/down points');
|
| 507 |
}
|
| 508 |
}
|
| 509 |
|
| 510 |
// Do the voting via voting api.
|
| 511 |
if ($uid = _vote_up_down_get_uid()) {
|
| 512 |
if ($vote->value == 0) {
|
| 513 |
votingapi_unset_vote($type, $cid, $uid);
|
| 514 |
}
|
| 515 |
else {
|
| 516 |
votingapi_set_vote($type, $cid, $vote, $uid);
|
| 517 |
}
|
| 518 |
}
|
| 519 |
|
| 520 |
if ($ajax) {
|
| 521 |
$style = ($alt == TRUE ? '_alt' : '');
|
| 522 |
print theme("vote_up_down_points$style", $cid, $type);
|
| 523 |
exit();
|
| 524 |
}
|
| 525 |
else {
|
| 526 |
drupal_goto(drupal_get_destination());
|
| 527 |
}
|
| 528 |
}
|
| 529 |
}
|
| 530 |
|
| 531 |
function theme_vote_up_down_widget($cid, $type) {
|
| 532 |
global $user;
|
| 533 |
|
| 534 |
if (user_access('view up/down votes')) {
|
| 535 |
|
| 536 |
$output = '<div class="vote-up-down-widget">';
|
| 537 |
|
| 538 |
if (user_access('use vote up/down') && ($user->uid || variable_get('vote_up_down_anonymous_vote', 0))) {
|
| 539 |
$user_vote = votingapi_get_user_votes($type, $cid, _vote_up_down_get_uid());
|
| 540 |
|
| 541 |
if ($user_vote[0]->value > 0) {
|
| 542 |
$class = 'vote-up-act';
|
| 543 |
$class2 = 'vote-down-inact';
|
| 544 |
}
|
| 545 |
else if ($user_vote[0]->value < 0) {
|
| 546 |
$class = 'vote-up-inact';
|
| 547 |
$class2 = 'vote-down-act';
|
| 548 |
}
|
| 549 |
else {
|
| 550 |
$class = 'vote-up-inact';
|
| 551 |
$class2 = 'vote-down-inact';
|
| 552 |
}
|
| 553 |
|
| 554 |
$output .= '<span id="vote_up_'. $type .'_'. $cid .'" class="'. $class .'" title="'. url("vote_up_down/$type/$cid/1/1") .'">'. /* TODO
|
| 555 |
Please manually fix the parameters on the l() or url() function on the next line.
|
| 556 |
Typically, this was not changed because of a function call inside an array call like
|
| 557 |
array('title' => t('View user profile.')).*/
|
| 558 |
l('', "vote_up_down/$type/$cid/1", array('class' => $class, 'title' => t('Vote up')), drupal_get_destination(), NULL, FALSE, TRUE) .'</span>';
|
| 559 |
$output .= '<span id="vote_down_'. $type .'_'. $cid .'" class="'. $class2 .'" title="'. url("vote_up_down/$type/$cid/-1/1") .'">'. /* TODO
|
| 560 |
Please manually fix the parameters on the l() or url() function on the next line.
|
| 561 |
Typically, this was not changed because of a function call inside an array call like
|
| 562 |
array('title' => t('View user profile.')).*/
|
| 563 |
l('', "vote_up_down/$type/$cid/-1", array('class' => $class2, 'title' => t('Vote down')), drupal_get_destination(), NULL, FALSE, TRUE) .'</span>';
|
| 564 |
}
|
| 565 |
else {
|
| 566 |
$output .= '<span class="up-inact" title="'. t('You must login to vote.') .'"></span>';
|
| 567 |
$output .= '<span class="down-inact" title="'. t('You must login to vote.') .'"></span>';
|
| 568 |
}
|
| 569 |
|
| 570 |
$output .= '</div>';
|
| 571 |
|
| 572 |
return $output;
|
| 573 |
}
|
| 574 |
}
|
| 575 |
|
| 576 |
function theme_vote_up_down_widget_alt($cid, $type) {
|
| 577 |
global $user;
|
| 578 |
|
| 579 |
if (user_access('view up/down votes')) {
|
| 580 |
|
| 581 |
$output = '<div class="vote-up-down-widget-alt">';
|
| 582 |
$output .= theme('vote_up_down_points_alt', $cid, $type);
|
| 583 |
|
| 584 |
if (user_access('use vote up/down') && ($user->uid || variable_get('vote_up_down_anonymous_vote', 0))) {
|
| 585 |
$user_vote = votingapi_get_user_votes($type, $cid, _vote_up_down_get_uid());
|
| 586 |
|
| 587 |
if ($user_vote[0]->value > 0) {
|
| 588 |
$class = 'vote-up-act';
|
| 589 |
}
|
| 590 |
else {
|
| 591 |
$class = 'vote-up-inact';
|
| 592 |
}
|
| 593 |
|
| 594 |
$output .= '<span id="vote_up_'. $type .'_'. $cid .'" class="'. $class .'" title="'. url("vote_up_down/$type/$cid/1/1/1") .'">'. /* TODO
|
| 595 |
Please manually fix the parameters on the l() or url() function on the next line.
|
| 596 |
Typically, this was not changed because of a function call inside an array call like
|
| 597 |
array('title' => t('View user profile.')).*/
|
| 598 |
l('', "vote_up_down/$type/$cid/1", array('class' => $class, 'title' => t('Vote')), drupal_get_destination(), NULL, FALSE, TRUE) .'</span>';
|
| 599 |
|
| 600 |
}
|
| 601 |
else {
|
| 602 |
$output .= '<span class="up-inact" title="'. t('You must login to vote.') .'"></span>';
|
| 603 |
}
|
| 604 |
|
| 605 |
$output .= '</div>';
|
| 606 |
|
| 607 |
return $output;
|
| 608 |
}
|
| 609 |
}
|
| 610 |
|
| 611 |
function theme_vote_up_down_points($cid, $type, $nodelink = FALSE) {
|
| 612 |
$vote_result = votingapi_get_voting_result($type, $cid, 'points', variable_get('vote_up_down_tag', 'vote'), 'sum');
|
| 613 |
if ($nodelink) {
|
| 614 |
if ($vote_result) {
|
| 615 |
$output = array(
|
| 616 |
'title' => '<span id="vote_points_'. $type .'_'. $cid .'" class="vote-points">'. format_plural($vote_result->value, '1 point', '@count points') .'</span>',
|
| 617 |
'html' => TRUE
|
| 618 |
);
|
| 619 |
}
|
| 620 |
else {
|
| 621 |
$output = array(
|
| 622 |
'title' => '<span id="vote_points_'. $type .'_'. $cid .'" class="vote-points">'. t('0 points') .'</span>',
|
| 623 |
'html' => TRUE
|
| 624 |
);
|
| 625 |
}
|
| 626 |
}
|
| 627 |
else {
|
| 628 |
if ($vote_result) {
|
| 629 |
$output = '<span id="vote_points_'. $type .'_'. $cid .'" class="vote-points">'. format_plural($vote_result->value, '1 point', '@count points') .'</span>';
|
| 630 |
}
|
| 631 |
else {
|
| 632 |
$output = '<span id="vote_points_'. $type .'_'. $cid .'" class="vote-points">'. t('0 points') .'</span>';
|
| 633 |
}
|
| 634 |
}
|
| 635 |
|
| 636 |
return $output;
|
| 637 |
}
|
| 638 |
|
| 639 |
function theme_vote_up_down_points_alt($cid, $type) {
|
| 640 |
$vote_result = votingapi_get_voting_result($type, $cid, 'points', variable_get('vote_up_down_tag', 'vote'), 'sum');
|
| 641 |
if ($vote_result) {
|
| 642 |
$output = '<div id="vote_points_'. $type .'_'. $cid .'" class="vote-points">'. $vote_result->value;
|
| 643 |
}
|
| 644 |
else {
|
| 645 |
$output = '<div id="vote_points_'. $type .'_'. $cid .'" class="vote-points">0';
|
| 646 |
}
|
| 647 |
|
| 648 |
$output .= '<div class="vote-points-label">'. format_plural($vote_result->value, 'point', 'points') .'</div></div>';
|
| 649 |
|
| 650 |
return $output;
|
| 651 |
}
|
| 652 |
|
| 653 |
/**
|
| 654 |
* Get a uid for anonymous vs. registered voting
|
| 655 |
*/
|
| 656 |
function _vote_up_down_get_uid() {
|
| 657 |
global $user;
|
| 658 |
|
| 659 |
if ($user->uid) {
|
| 660 |
$uid = $user->uid;
|
| 661 |
}
|
| 662 |
else if (variable_get('vote_up_down_anonymous_vote', 0)) {
|
| 663 |
// Fake uid for anonymous users.
|
| 664 |
// If the IP is valid turn it into a integer and add the number of the current day.
|
| 665 |
// The current day is what limit anonymous voting to one vote per day and IP address.
|
| 666 |
$hostname = (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : ip_address();
|
| 667 |
if ($long = ip2long($hostname)) {
|
| 668 |
$uid = abs($long) + date('z');
|
| 669 |
}
|
| 670 |
}
|
| 671 |
else {
|
| 672 |
$uid = NULL;
|
| 673 |
}
|
| 674 |
|
| 675 |
return $uid;
|
| 676 |
}
|