You are here

function theme_fivestar_static in Fivestar 5

Same name and namespace in other branches
  1. 6.2 fivestar.module \theme_fivestar_static()
  2. 6 fivestar.module \theme_fivestar_static()
  3. 7.2 includes/fivestar.theme.inc \theme_fivestar_static()

Display a plain HTML VIEW ONLY version of the widget with the specified rating

Parameters

$rating: The desired rating to display out of 100 (i.e. 80 is 4 out of 5 stars)

$stars: The total number of stars this rating is out of

$tag: Allows multiple ratings per node

Return value

A themed HTML string representing the star widget

5 theme calls to theme_fivestar_static()
fivestar_comment in ./fivestar_comment.module
Implementation of hook_comment().
fivestar_custom_widget in ./fivestar.module
fivestar_field_formatter in ./fivestar_field.inc
Implementation of hook_field_formatter().
fivestar_static in ./fivestar.module
fivestar_views_value_display_handler in ./fivestar.module

File

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

Code

function theme_fivestar_static($rating, $stars = 5, $tag = 'vote') {
  $output = '';
  $output .= '<div class="fivestar-widget-static fivestar-widget-static-' . $tag . ' fivestar-widget-static-' . $stars . ' clear-block">';
  $numeric_rating = $rating / (100 / $stars);
  for ($n = 1; $n <= $stars; $n++) {
    $star_value = ceil(100 / $stars * $n);
    $prev_star_value = ceil(100 / $stars * ($n - 1));
    $zebra = $n % 2 == 0 ? 'even' : 'odd';
    $first = $n == 1 ? ' star-first' : '';
    $last = $n == $stars ? ' star-last' : '';
    $output .= '<div class="star star-' . $n . ' star-' . $zebra . $first . $last . '">';
    if ($rating < $star_value && $rating > $prev_star_value) {
      $percent = ($rating - $prev_star_value) / ($star_value - $prev_star_value) * 100;
      $output .= '<span class="on" style="width: ' . $percent . '%">';
    }
    elseif ($rating >= $star_value) {
      $output .= '<span class="on">';
    }
    else {
      $output .= '<span class="off">';
    }
    if ($n == 1) {
      $output .= $numeric_rating;
    }
    $output .= '</span></div>';
  }
  $output .= '</div>';
  return $output;
}