You are here

function fivestar_preview in Fivestar 5

Same name and namespace in other branches
  1. 6.2 includes/fivestar.admin.inc \fivestar_preview()
  2. 6 fivestar.module \fivestar_preview()

Callback function for fivestar/preview/node. Outputs a JSON page containing a Fivestar preview of a node rating widget.

2 string references to 'fivestar_preview'
fivestar_menu in ./fivestar.module
Implementation of hook_menu().
theme_fivestar_preview_widget in ./fivestar.module

File

./fivestar.module, line 579
A simple n-star voting widget, usable in other forms.

Code

function fivestar_preview() {

  // Perform a few basic security checks.
  $style = check_plain($_POST['style']);
  $text = check_plain($_POST['text']);
  $stars = (int) $_POST['stars'];
  $unvote = (bool) $_POST['unvote'];
  $title = (bool) $_POST['title'];
  $feedback_enable = (bool) $_POST['feedback'];
  $labels_enable = (bool) $_POST['labels_enable'];
  $labels = (array) $_POST['labels'];
  foreach ($labels as $key => $label) {
    $labels[$key] = filter_xss_admin($label);
  }
  $output = theme('fivestar_preview', $style, $text, $stars, $unvote, $title ? NULL : FALSE, $feedback_enable, $labels_enable, $labels);
  drupal_set_header('Content-Type: text/javascript; charset=utf-8');
  print drupal_to_js(array(
    'status' => TRUE,
    'data' => $output,
  ));
}