function theme_fivestar_static in Fivestar 6
Same name and namespace in other branches
- 5 fivestar.module \theme_fivestar_static()
- 6.2 fivestar.module \theme_fivestar_static()
- 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
6 theme calls to theme_fivestar_static()
- fivestar_comment in ./
fivestar_comment.module - Implementation of hook_comment().
- fivestar_custom_widget in ./
fivestar.module - fivestar_static in ./
fivestar.module - fivestar_views_value_display_handler in ./
fivestar.module - VotingAPI Views formatter for displaying static stars.
- fivestar_views_widget_handler in ./
fivestar.module - Generic VotingAPI Views formatter for displaying rating widget.
File
- ./
fivestar.module, line 1400 - 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">';
if (empty($stars)) {
$stars = 5;
}
$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;
}