You are here

function fivestar_settings in Fivestar 5

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

Callback function for admin/settings/fivestar. Display the settings form.

1 call to fivestar_settings()
fivestar_color_form_submit in ./fivestar_color.inc
Submit handler for color change form.
1 string reference to 'fivestar_settings'
fivestar_menu in ./fivestar.module
Implementation of hook_menu().

File

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

Code

function fivestar_settings() {
  $form = array();
  $form['widget'] = array(
    '#tree' => FALSE,
    '#type' => 'fieldset',
    '#title' => t('Widget display'),
    '#description' => t('Choose a widget set to be used on your site. Widgets supporting custom colors can be further customized by adjusting the color scheme.'),
    '#weight' => -2,
  );
  $widgets = module_invoke_all('fivestar_widgets');
  $classic_widgets = array();
  $color_widgets = array();
  foreach ($widgets as $path => $name) {
    $directory = dirname($path);
    $matches = file_scan_directory($directory, '-template.');
    if (empty($matches)) {
      $classic_widgets[$path] = $name;
    }
    else {
      $color_widgets[$path] = $name;
    }
  }

  // If using a color widget, set the default value to the original path.
  $default_value = variable_get('fivestar_widget', 'default');
  foreach ($color_widgets as $path => $name) {
    if (basename($path) == basename($default_value)) {
      $default_value = $path;
    }
  }
  $form['widget']['fivestar_widget'] = array(
    '#type' => 'radios',
    '#options' => array(
      'default' => t('Default'),
    ) + $classic_widgets + $color_widgets,
    '#default_value' => $default_value,
    '#attributes' => array(
      'class' => 'fivestar-widgets',
    ),
  );
  $form['widget']['fivestar_color_widget'] = array(
    '#type' => 'radios',
    '#title' => t('Custom color widgets'),
    '#options' => $color_widgets,
    '#attributes' => array(
      'class' => 'fivestar-widgets',
    ),
  );
  include_once drupal_get_path('module', 'fivestar') . '/fivestar_color.inc';
  $form['color'] = fivestar_color_form();
  $form['#validate']['fivestar_color_form_validate'] = array();
  $form['#submit']['fivestar_color_form_submit'] = array();
  $form['#submit']['fivestar_settings_submit'] = array();
  $form['fivestar_anonymous_vote_interval'] = array(
    '#type' => 'select',
    '#title' => t('Anonymous vote interval'),
    '#options' => array(
      0 => t('Immediately'),
    ) + drupal_map_assoc(array(
      300,
      900,
      1800,
      3600,
      10800,
      21600,
      32400,
      43200,
      86400,
      172800,
      345600,
      604800,
    ), 'format_interval') + array(
      -1 => t('Never'),
    ),
    '#default_value' => variable_get('fivestar_anonymous_vote_interval', 86400),
    '#description' => t('Anonymous users may add another vote after this interval. Because the same IP addresses may be used by different people, allowing the same IP to vote again several days later may yield more votes.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
    '#weight' => 45,
  );
  return $form;
}