function theme_fivestar_static in Fivestar 7.2
Same name and namespace in other branches
- 5 fivestar.module \theme_fivestar_static()
- 6.2 fivestar.module \theme_fivestar_static()
- 6 fivestar.module \theme_fivestar_static()
Display a plain HTML view-only version of the widget with a 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.
2 theme calls to theme_fivestar_static()
- fivestar_expand in ./
fivestar.module - Process callback for fivestar_element -- see fivestar_element()
- theme_fivestar_formatter_default in includes/
fivestar.theme.inc - Theme function for 'default' fivestar field formatter.
File
- includes/
fivestar.theme.inc, line 194 - Provides the theming functions for fivestar.
Code
function theme_fivestar_static($variables) {
$rating = $variables['rating'];
$stars = $variables['stars'];
$tag = $variables['tag'];
$widget = $variables['widget'];
if ($widget['name'] != 'default') {
$path = drupal_get_path('module', 'fivestar');
drupal_add_css($path . '/css/fivestar.css');
drupal_add_css($widget['css']);
}
$output = '<div class="fivestar-' . $widget['name'] . '">';
$output .= '<div class="fivestar-widget-static fivestar-widget-static-' . $tag . ' fivestar-widget-static-' . $stars . ' clearfix">';
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></div>';
return $output;
}