'), $form);
$form = preg_replace('/( method=".*?")|( action=".*?")|(
)/', '', $form);
return $form;
}
function theme_fivestar_preview_wrapper($variables) {
return '
' . $variables['content'] . '
';
}
/**
* Theme function for 'default' fivestar field formatter.
*
* This themes static stars. That is, pairs of stars where neither set
* of stars is "exposed". Exposed stars are clickable and displayed in a
* form. Theming of exposed stars is handled by the form array (and calls
* the same theme functions called at the end of this function).
*/
function theme_fivestar_formatter_default($variables) {
$element = $variables['element'];
if (empty($element['#instance_settings']['stars'])) {
$element['#instance_settings']['stars'] = 5;
}
// Add CSS and JS
$path = drupal_get_path('module', 'fivestar');
drupal_add_js($path . '/js/fivestar.js');
drupal_add_css($path . '/css/fivestar.css');
$variables = array(
'rating' => $element['#rating'],
'stars' => $element['#instance_settings']['stars'],
'widget' => $element['#widget'],
);
$star_display = theme('fivestar_static', $variables);
return theme('fivestar_static_element', array('description' => $element['#description'], 'star_display' => $star_display, 'is_form' => FALSE));
}
/**
* Theme function for 'rating' fivestar field formatter.
*/
function theme_fivestar_formatter_rating($variables) {
$element = $variables['element'];
if (empty($element['#item']['average'])) {
$element['#item']['average'] = 0;
}
// Get number of stars.
$stars = (empty($element['#instance_settings']['stars'])) ? 5 : $element['#instance_settings']['stars'];
$average = $element['#item']['average'];
// Rating is X out of Y stars.
$rating = round(($average/100) * $stars, 1);
$output = $rating . '/' . $stars;
return $output;
}
/**
* Theme function for 'percentage' fivestar field formatter.
*/
function theme_fivestar_formatter_percentage($variables) {
$element = $variables['element'];
if (empty($element['#item']['average'])) {
$element['#item']['average'] = 0;
}
return round($element['#item']['average'], 1) . '%';
}
/**
* Theme the fivestar form element by adding necessary css and javascript.
*/
function theme_fivestar($variables) {
$element = $variables['element'];
return theme('form_element', array('element' => $element));
}
/**
* Theme the straight HTML version of the fivestar select list. This is used
* to remove the wrapping 'form-item' div from the select list.
*/
function theme_fivestar_select($variables) {
$element = $variables['element'];
element_set_attributes($element, array('id', 'name', 'size'));
_form_set_class($element, array('form-select'));
return '
' . form_select_options($element) . ' ';
}
/**
* Display a plain HTML view-only version of the widget with a specified rating.
*
* @param $rating
* The desired rating to display out of 100 (i.e. 80 is 4 out of 5 stars).
* @param $stars
* The total number of stars this rating is out of.
* @param $tag
* Allows multiple ratings per node.
* @return
* A themed HTML string representing the star widget.
*/
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 = '
';
return $output;
}
/**
* Display the text associated with a static star display.
*
* Note that passing in explicit data types is extremely important when using
* this function. A NULL value will exclude the value entirely from display,
* while a 0 value indicates that the text should be shown but it has no value
* yet.
*
* All ratings are from 0 to 100.
*
* @param $user_rating
* The current user's rating.
* @param $average
* The average rating.
* @param $votes
* The total number of votes.
* @param $stars
* The number of stars being displayed.
* @return
* A themed HTML string representing the star widget.
*/
function theme_fivestar_summary($variables) {
$microdata = $variables['microdata'];
extract($variables, EXTR_SKIP);
$output = '';
$div_class = '';
$average_rating_microdata = '';
$rating_count_microdata = '';
if (isset($user_rating)) {
$div_class = isset($votes) ? 'user-count' : 'user';
$user_stars = round(($user_rating * $stars) / 100, 1);
$output .= '
' . t('Your rating: !stars ', array('!stars' => $user_rating ? $user_stars : t('None'))) . ' ';
}
if (isset($user_rating) && isset($average_rating)) {
$output .= ' ';
}
if (isset($average_rating)) {
if (isset($user_rating)) {
$div_class = 'combo';
}
else {
$div_class = isset($votes) ? 'average-count' : 'average';
}
$average_stars = round(($average_rating * $stars) / 100, 1);
if (!empty($microdata['average_rating']['#attributes'])) {
$average_rating_microdata = drupal_attributes($microdata['average_rating']['#attributes']);
}
$output .= '
' . t('Average: !stars',
array('!stars' => "$average_stars ")) . ' ';
}
if (isset($votes)) {
if (!isset($user_rating) && !isset($average_rating)) {
$div_class = 'count';
}
if ($votes === 0) {
$output = '
'. t('No votes yet') .' ';
}
else {
if (!empty($microdata['rating_count']['#attributes'])) {
$rating_count_microdata = drupal_attributes($microdata['rating_count']['#attributes']);
}
// We don't directly substitute $votes (i.e. use '@count') in format_plural,
// because it has a span around it which is not translatable.
$votes_str = format_plural($votes, '!cnt vote', '!cnt votes', array(
'!cnt' => '
' . intval($votes) . ' '));
if (isset($user_rating) || isset($average_rating)) {
$output .= '
(' . $votes_str . ') ';
}
else {
$output .= '
' . $votes_str . ' ';
}
}
}
$output = '
' . $output . '
';
return $output;
}
/**
* Display a static fivestar value as stars with a title and description.
*/
function theme_fivestar_static_element($variables) {
$output = '';
if (isset($variables['is_form']) && !$variables['is_form']) {
$output .= '
';
}
else {
$output .= '
';
}
$element = array(
'#type' => 'item',
'#title' => $variables['title'],
'#description' => $variables['description'],
'#children' => $variables['star_display'],
);
$output .= theme('form_element', array('element' => $element));
$output .= '
';
return $output;
}