You are here

function fivestar_preview_color in Fivestar 5

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

Callback function for fivestar/preview/color.

Outputs a dynamically generated star or cancel png.

1 string reference to 'fivestar_preview_color'
fivestar_menu in ./fivestar.module
Implementation of hook_menu().

File

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

Code

function fivestar_preview_color() {
  include_once drupal_get_path('module', 'fivestar') . '/fivestar_color.inc';
  $args = func_get_args();

  // Remove query string if it gets passed in as argument.
  $filename = preg_replace('/\\?.*$/', '', array_pop($args));
  $type = array_pop($args);
  $widget = array_pop($args);

  // Convert args to our color scheme.
  $color_scheme = array(
    'on1' => $args[0],
    'on2' => $args[1],
    'hover1' => $args[2],
    'hover2' => $args[3],
    'off1' => $args[4],
    'off2' => $args[5],
    'matte' => $args[6],
  );

  // Find the source location of the desired widget.
  $widgets = module_invoke_all('fivestar_widgets');
  foreach ($widgets as $key => $name) {
    if (drupal_strtolower($name) == $widget) {
      $source_directory = str_replace($widget . '.css', '', $key);
      break;
    }
  }

  // Generate the requested image and exit.
  $image = _fivestar_color_render($source_directory . str_replace('.png', '-template.png', $filename), $color_scheme, $type);
  drupal_set_header('Content-type: image/png');
  drupal_set_header("Expires: " . gmdate("D, d M Y H:i:s", time() + 300) . " GMT");
  drupal_set_header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  drupal_set_header("Cache-Control: max-age=300");
  imagepng($image);
  exit;
}