You are here

function rate_vote_ahah in Rate 7

Same name and namespace in other branches
  1. 6.2 rate.module \rate_vote_ahah()

AHAH callback for the vote buttons.

1 string reference to 'rate_vote_ahah'
rate_menu in ./rate.module
Implements hook_menu().

File

./rate.module, line 829
Rate module

Code

function rate_vote_ahah() {
  $content_type = preg_replace('/[^\\w\\-]/', '', $_GET['content_type']);
  $content_id = (int) $_GET['content_id'];
  $widget_id = (int) $_GET['widget_id'];
  $widget_mode = (int) $_GET['widget_mode'];
  $widgets = variable_get(RATE_VAR_WIDGETS, array());
  $widget = $widgets[$widget_id];

  // Process options.
  foreach ($widget->options as $option) {

    // This name must be unique for all submit buttons across the page, AHAH will fail otherwise.
    $id = "opt-{$widget_id}-{$content_type}-{$content_id}-{$option[0]}";
    $token = rate_get_token($id);
    if (isset($_GET['token']) && $_GET['token'] == $token) {
      rate_save_vote($widget, $content_type, $content_id, $option[0], TRUE);
    }
  }

  // Process arbitrary value, used for sliders.
  if (isset($_GET['value']) && $widget->value_type == 'percent') {

    // Validate the token against the general widget token (found in the widget classes).
    $id = "rate-{$widget_id}-{$content_type}-{$content_id}";
    $token = _rate_get_token($id);
    $value = (int) $_GET['value'];
    if (isset($_GET['token']) && $_GET['token'] == $token && $value >= 0 && $value <= 100) {
      rate_save_vote($widget, $content_type, $content_id, $value, TRUE);
    }
  }
  print rate_generate_widget($widget_id, $content_type, $content_id, $widget_mode, TRUE, TRUE);
  module_invoke_all('exit') & exit;
}