You are here

function theme_fivestar_preview_widget in Fivestar 6

Same name and namespace in other branches
  1. 8 includes/fivestar.theme.inc \theme_fivestar_preview_widget()
  2. 5 fivestar.module \theme_fivestar_preview_widget()
  3. 6.2 includes/fivestar.admin.inc \theme_fivestar_preview_widget()
  4. 7.2 includes/fivestar.theme.inc \theme_fivestar_preview_widget()
1 theme call to theme_fivestar_preview_widget()
theme_fivestar_settings in ./fivestar.module

File

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

Code

function theme_fivestar_preview_widget($css_file) {
  static $default_css_added = FALSE;

  // Add the default CSS to the page to ensure the defaults take precedence.
  if (!$default_css_added) {
    $css = file_get_contents(drupal_get_path('module', 'fivestar') . '/css/fivestar.css');

    // Prepend the classes with the unique widget div.
    $css = preg_replace('/((div)?\\.fivestar-widget)/', 'div.fivestar-widgets $1', $css);

    // Update relative URLs with absolute locations.
    $css = preg_replace('/url\\(\\.\\.\\/(.*?)\\)/', 'url(' . base_path() . drupal_get_path('module', 'fivestar') . '/$1)', $css);
    fivestar_add_inline_css('default', $css);
    $default_css_added = TRUE;
  }

  // Add widget specific CSS to the page.
  $widget_name = str_replace('.css', '', basename($css_file));
  $widget_path = dirname($css_file);
  if ($widget_name != 'default') {
    $css = file_get_contents($css_file);

    // Prepend the classes with the unique widget div.
    $css = preg_replace('/((div)?\\.fivestar-widget)/', 'div#fivestar-preview-' . $widget_name . ' $1', $css);

    // Update relative URLs with absolute locations.
    $css = preg_replace('/url\\((.*?)\\)/', 'url(' . base_path() . $widget_path . '/$1)', $css);
    fivestar_add_inline_css($widget_name, $css);
  }
  $form = array();
  $form_state = array();
  $form['vote'] = array(
    '#type' => 'fivestar',
    '#stars' => 5,
    '#auto_submit' => FALSE,
    '#allow_clear' => TRUE,
  );
  $form = form_builder('fivestar_preview', $form, $form_state);
  $output = '<div class="fivestar-star-preview" id="fivestar-preview-' . $widget_name . '">';
  $output .= drupal_render($form);
  $output .= '</div>';
  return $output;
}