Commit 481fe698 authored by Marco Villegas's avatar Marco Villegas
Browse files

Issue #847846 by mansspams, marvil07, jaydub, monotaga: Provide 'Reset your...

Issue #847846 by mansspams, marvil07, jaydub, monotaga: Provide 'Reset your vote' link on the widget.
parent 094e6221
Loading
Loading
Loading
Loading
+9 −0
Changes for vud.install: 9 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -57,3 +57,12 @@ function vud_update_6300() {
  menu_rebuild();
  return $ret;
}

/**
 * Rebuild menu for 'votereset/%/%/%/%/%'.
 */
function vud_update_6301() {
  $result = array();
  menu_rebuild();
  return $result;
}
+3 −27
Changes for vud.module: 3 added lines, 27 removed lines.
Original line number Diff line number Diff line
@@ -83,13 +83,14 @@ 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 callback'  => 'vud_access_callback',
    'access arguments' => array('reset vote up/down votes', 1, 2, 3, 4),
    'type'             => MENU_CALLBACK,
    'file'             => 'vud.theme.inc',
  );

  $items['user/%user/vote_up_down/votes'] = array(
@@ -200,31 +201,6 @@ function vud_user_votes($account) {
  return $output;
}

/**
 * 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.
 */
+63 −0
Changes for vud.theme.inc: 63 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -135,6 +135,9 @@ 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',
    'reset_long_text' => t('Reset your vote'),
    'reset_short_text' => t('(reset)'),
  );

  global $user;
@@ -159,18 +162,24 @@ 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';
  }

  $variables['show_reset'] = ($variables['class_reset'] == 'reset-active') && vud_access_callback('reset vote up/down votes', $type, $content_id, NULL, $variables['tag']);

  $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 +222,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 +230,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);

@@ -406,3 +422,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']);
  }
}
+2 −2
Changes for vud_comment/vud_comment.module: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -186,10 +186,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,
          );
+2 −2
Changes for vud_node/vud_node.module: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -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,
          );
Loading