diff --git vud.install vud.install index aecc18e..d9ec01c 100644 --- vud.install +++ vud.install @@ -49,3 +49,12 @@ function vud_update_6200() { return $ret; } + +/** + * Rebuild menu for 'votereset/%/%/%/%/%'. + */ +function vud_update_6300() { + $result = array(); + menu_rebuild(); + return $result; +} diff --git vud.module vud.module index 7535294..b4489bf 100644 --- vud.module +++ vud.module @@ -83,12 +83,13 @@ function vud_menu() { 'file' => 'vud.theme.inc', ); - $items['votereset/%/%/%/%'] = array( + $items['votereset/%/%/%/%/%'] = array( 'title' => 'Reset vote', 'page callback' => 'vud_reset', - 'page arguments' => array(1, 2, 3, 4), + 'page arguments' => array(1, 2, 3, 4, 5), 'access arguments' => array('reset vote up/down votes'), 'type' => MENU_CALLBACK, + 'file' => 'vud.theme.inc', ); $items['user/%user/votes'] = array( @@ -157,31 +158,6 @@ function vud_user_votes() { } /** - * Callback to reset votes on an object. - */ -function vud_reset($type, $content_id, $tag, $token) { - if (drupal_valid_token($token, "votereset/$type/$content_id/$tag", TRUE)) { - $uid = votingapi_current_user_identifier(); - $criteria = array( - 'content_type' => $type, - 'content_id' => $content_id, - 'tag' => $tag, - ); - $fullc = $criteria + $uid; - votingapi_delete_votes(votingapi_select_votes($fullc)); - votingapi_recalculate_results($type, $content_id); - - drupal_goto($_SERVER['HTTP_REFERER']); - } - else { - watchdog('vud', - 'Could not reset votes on @type @content_id, with value @value, tag @tag and token @token', - array('@type' => $type, '@content_id' => $content_id, '@value' => $value, '@tag' => $tag, '@token' => $token)); - drupal_set_message(t("Oops! There was an error in resetting your vote!", 'warning')); - } -} - -/** * Menu callback; show widget message. */ function vud_denied_vote($js = FALSE, $code=VUD_WIDGET_MESSAGE_ERROR) { diff --git vud.theme.inc vud.theme.inc index 1d1559d..5c30964 100644 --- vud.theme.inc +++ vud.theme.inc @@ -136,6 +136,7 @@ function vud_widget_proxy($content_id, $type, $tag, $widget_theme, $readonly=NUL 'id' => 'widget-' . $type . '-' . $content_id, 'link_class_up' => 'vud-link-up', 'link_class_down' => 'vud-link-down', + 'link_class_reset' => 'vud-link-reset', ); global $user; @@ -159,18 +160,22 @@ function vud_widget_proxy($content_id, $type, $tag, $widget_theme, $readonly=NUL if ($user_vote > 0) { $variables['class_up'] = 'up-active'; $variables['class_down'] = 'down-inactive'; + $variables['class_reset'] = 'reset-active'; } elseif ($user_vote < 0) { $variables['class_up'] = 'up-inactive'; $variables['class_down'] = 'down-active'; + $variables['class_reset'] = 'reset-active'; } else { $variables['class_up'] = 'up-inactive'; $variables['class_down'] = 'down-inactive'; + $variables['class_reset'] = 'reset-inactive'; } $token_up = drupal_get_token("vote/$type/$content_id/1/$tag/$widget_theme"); $token_down = drupal_get_token("vote/$type/$content_id/-1/$tag/$widget_theme"); + $token_reset = drupal_get_token("votereset/$type/$content_id/$tag/$widget_theme"); $result_criteria = array( 'content_type' => $type, @@ -213,6 +218,7 @@ function vud_widget_proxy($content_id, $type, $tag, $widget_theme, $readonly=NUL $variables['readonly'] = $readonly; $link_up = url("vote/$type/$content_id/1/$tag/$widget_theme/$token_up"); $link_down = url("vote/$type/$content_id/-1/$tag/$widget_theme/$token_down"); + $link_reset = url("votereset/$type/$content_id/$tag/$widget_theme/$token_reset"); $message_on_deny = variable_get('vud_message_on_deny', FALSE); $variables['show_links'] = !$readonly || $message_on_deny; $variables['show_up_as_link'] = $variables['show_links'] && ($user_vote <= 0); @@ -220,27 +226,33 @@ function vud_widget_proxy($content_id, $type, $tag, $widget_theme, $readonly=NUL if ($readonly) { $variables['link_class_up'] .= ' denied'; $variables['link_class_down'] .= ' denied'; + $variables['link_class_reset'] .= ' denied'; if ($message_on_deny) { ctools_include('modal'); ctools_modal_add_js(); $variables['link_class_up'] .= ' ctools-use-modal'; $variables['link_class_down'] .= ' ctools-use-modal'; + $variables['link_class_reset'] .= ' ctools-use-modal'; $link_up = url(sprintf('vud/nojs/denied/%d', $widget_message_code)); $link_down = url(sprintf('vud/nojs/denied/%d', $widget_message_code)); + $link_reset = url(sprintf('vud/nojs/denied/%d', $widget_message_code)); } else { // no vote access, so avoid show the link at template $link_up = '#'; $link_down = '#'; + $link_reset = '#'; } } else { $variables['link_class_up'] .= ' ctools-use-ajax'; $variables['link_class_down'] .= ' ctools-use-ajax'; + $variables['link_class_reset'] .= ' ctools-use-ajax'; } $variables['link_up'] = $link_up; $variables['link_down'] = $link_down; + $variables['link_reset'] = $link_reset; $template_file = vud_pseudo_theming($type, 'widget', $plugin, $variables); @@ -405,3 +417,50 @@ function vud_vote($type, $content_id, $value, $tag, $widget, $token) { drupal_goto($_SERVER['HTTP_REFERER']); } } + +/** + * Function for the reset handler with Ajax support. + */ +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']); + } +} diff --git vud_comment/vud_comment.module vud_comment/vud_comment.module index 792629a..0f89219 100644 --- vud_comment/vud_comment.module +++ vud_comment/vud_comment.module @@ -183,10 +183,10 @@ function vud_comment_link($type, $object, $teaser = FALSE) { $criteria += votingapi_current_user_identifier(); $user_vote = votingapi_select_single_vote_value($criteria); if (!is_null($user_vote)) { - $reset_token = drupal_get_token("votereset/comment/$comment->cid/$tag"); + $reset_token = drupal_get_token("votereset/comment/$comment->cid/$tag/$widget_theme"); $links['vud_comment_votes_reset_link'] = array( 'title' => t('Reset your vote'), - 'href' => "votereset/comment/$comment->cid/$tag/$reset_token", + 'href' => "votereset/comment/$comment->cid/$tag/$widget_theme/$reset_token", 'attributes' => array('rel' => 'nofollow'), 'html' => TRUE, ); diff --git vud_node/vud_node.module vud_node/vud_node.module index 21e7050..be8a328 100644 --- vud_node/vud_node.module +++ vud_node/vud_node.module @@ -294,10 +294,10 @@ function vud_node_link($type, $object, $teaser = FALSE) { $criteria += votingapi_current_user_identifier(); $user_vote = votingapi_select_single_vote_value($criteria); if (!is_null($user_vote)) { - $reset_token = drupal_get_token("votereset/node/$node->nid/$tag"); + $reset_token = drupal_get_token("votereset/node/$node->nid/$tag/$widget_theme"); $links['vud_node_votes_reset_link'] = array( 'title' => t('Reset your vote'), - 'href' => "votereset/node/$node->nid/$tag/$reset_token", + 'href' => "votereset/node/$node->nid/$tag/$widget_theme/$reset_token", 'attributes' => array('rel' => 'nofollow'), 'html' => TRUE, ); diff --git vud_term/vud_term.module vud_term/vud_term.module index 3e52b36..ad5b34f 100644 --- vud_term/vud_term.module +++ vud_term/vud_term.module @@ -107,7 +107,7 @@ function _vud_term_generate_table(&$node) { foreach ($node->taxonomy as $term => $tdetails) { $content_id = $tdetails->tid; $tag = "n$node->nid"; - $reset_token = drupal_get_token("votereset/term/$content_id/$tag"); + $reset_token = drupal_get_token("votereset/term/$content_id/$tag/$widget"); if (variable_get('vud_term_reset', 0) && user_access('reset vote up/down votes')) { $header = array( array('data' => t('Term')), @@ -121,7 +121,7 @@ function _vud_term_generate_table(&$node) { $tdetails->description, theme('vud_widget', $content_id, "term", $tag, $widget), "". _vud_term_get_row_votes($content_id, $tag) .'', - l('Reset your vote', "votereset/term/$content_id/$tag/$reset_token"), + l('Reset your vote', "votereset/term/$content_id/$tag/$widget/$reset_token"), ); } else {