function vud_reset in Vote Up/Down 6.3
Same name and namespace in other branches
- 6.2 vud.module \vud_reset()
- 7.2 vud.theme.inc \vud_reset()
- 7 vud.theme.inc \vud_reset()
Function for the reset handler with Ajax support.
1 string reference to 'vud_reset'
- vud_menu in ./
vud.module - Implementation of hook_menu().
File
- ./
vud.theme.inc, line 429 - Theme functions
Code
function vud_reset($type, $content_id, $tag, $widget, $token) {
if (drupal_valid_token($token, "votereset/{$type}/{$content_id}/{$tag}/{$widget}", TRUE)) {
$criteria = array(
'content_type' => $type,
'content_id' => $content_id,
'tag' => $tag,
) + votingapi_current_user_identifier();
votingapi_delete_votes(votingapi_select_votes($criteria));
votingapi_recalculate_results($type, $content_id);
}
else {
watchdog('vud', 'Could not reset votes on @type @content_id, tag @tag and token @token', array(
'@type' => $type,
'@content_id' => $content_id,
'@tag' => $tag,
'@token' => $token,
));
drupal_set_message(t('Oops! There was an error resetting your vote!'), 'warning');
}
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
ctools_include('ajax');
$plugin = vud_widget_get($widget);
if ($function = ctools_plugin_get_function($plugin, 'ajax render')) {
$commands = $function($type, $content_id, $value, $tag, $token, $widget);
}
else {
$commands = array();
if (!empty($plugin['widget template'])) {
$commands[] = ctools_ajax_command_replace("#widget-{$type}-{$content_id}", theme('vud_widget', $content_id, $type, $tag, $widget));
}
if (!empty($plugin['votes template'])) {
$commands[] = ctools_ajax_command_replace("#votes-{$type}-{$content_id}", theme('vud_votes', $content_id, $type, $tag, $widget));
}
}
// This is the default set of commands. It can be overridden by an individual
// widget if it wants to.
ctools_ajax_render($commands);
}
else {
drupal_goto($_SERVER['HTTP_REFERER']);
}
}