function plus1_vote in Plus 1 6.2
Same name and namespace in other branches
- 6 plus1.module \plus1_vote()
- 7 plus1.module \plus1_vote()
Page callback.
Parameters
$nid: A node ID.
$ajax: Equal to 'json' when the function is called by jQuery. Submits the vote request and refreshes the page without JavaScript. Otherwise, it submits the vote request and returns JSON to be parsed by jQuery.
5 string references to 'plus1_vote'
- plus1_link in ./
plus1.module - Implementation of hook_link().
- plus1_menu in ./
plus1.module - Implements hook_menu().
- plus1_settings in ./
plus1.admin.inc - Menu callback to configure module settings.
- plus1_update_6200 in ./
plus1.install - Upgrade to using VotingAPI 2.
- theme_plus1_widget in ./
plus1.module - Theme for the voting widget.
File
- ./
plus1.module, line 89 - A simple +1 voting widget module.
Code
function plus1_vote($nid) {
global $user;
$json = isset($_GET['json']) ? 'json' : NULL;
// TRUE means to not worry about anonymous users.
if (!drupal_valid_token($_GET['token'], $nid, TRUE)) {
watchdog('Plus1', 'Voting form error: Invalid token.');
return drupal_access_denied();
}
$node = node_load($nid);
if (plus1_vote_access('create', $node, $user)) {
$criteria = array(
array(
'content_id' => $nid,
'value_type' => 'points',
'value' => 1,
'tag' => PLUS1_VOTE_TAG,
),
);
votingapi_set_votes($criteria);
$criteria = array(
'content_id' => $nid,
'function' => 'sum',
'tag' => PLUS1_VOTE_TAG,
);
$results = votingapi_select_results($criteria);
if ($json == 'json') {
// This print statement will return results to jQuery's request.
print drupal_json(array(
'score' => $results[0]['value'],
'voted' => check_plain(variable_get('plus1_you_voted', t('You voted'))),
));
}
else {
// Go to the full node view.
if ($after_vote = variable_get('plus1_after_vote_text', 'Thank you for your vote.')) {
drupal_set_message(t($after_vote));
}
// $path = "node/$nid";
// if (isset($_REQUEST['destination'])) {
// $path = $_REQUEST['destination'];
// }
drupal_goto("node/{$nid}");
}
}
}