Skip to content
Snippets Groups Projects
Commit 212f9a93 authored by Nate Lampton's avatar Nate Lampton
Browse files

Adding settings page for Fivestar, now with configurable star sets! Other...

Adding settings page for Fivestar, now with configurable star sets! Other modules may implement hook_fivestar_widgets() to add more star sets, or contribute them directly to the fivestar project.
parent b4e4b6ff
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
The Five Star voting module adds a clean, attractive voting widget to nodes in Drupal 5. It features:
* jQuery rollover effects and AJAX no-reload voting
* Customizable star sets
* Graceful degradation to an HTML rating form when JavaScript is turned off
* Per-nodetype configurability
* Support for anonymous voters
......@@ -38,20 +39,28 @@ without fear, friends -- Fivestar will continue to hum happily along.
Configuration
-------------
There is no global settings page for Fivestar. It's configuration is spread
between the content type settings page and access permissions. To configure:
The configuration for Fivestar is spread between the content type settings page,
Fivestar site settings page, and access permissions. To configure:
1) Activate voting on each content type. For example, if you want Fivestar to
1) Configure the site-wide setting for Fivestar, Administer -> Settings ->
Fivestar.
2) Activate voting on each content type. For example, if you want Fivestar to
appear on story nodes, use Administer -> Content Management ->
Content Types -> Story, and check the "Enable Five Star rating" box under
the "Five Star ratings" heading. Repeat for each content type desired.
2) Enable anonymous voting.
3) Enable anonymous voting.
If you want to allow anonymous voting, you'll need to set permissions for
that. Use Administer -> User Management -> Access Control, and check the
"rate content" and "view ratings" checkboxes for the roles you'd like.
You'll find these permission items under the "fivestar module" heading.
Contributing
------------
Have a sweet set of stars you'd like to contribute to the Fivestar module?
Post them to the Fivestar issue queue: http://drupal.org/project/issues/fivestar
Support
-------
If you experience a problem with cck_imagefield or have a problem, file a
......
......@@ -19,21 +19,21 @@ div.fivestar-widget-static .star {
height: 15px;
overflow: hidden;
text-indent: -999em;
background: url(star.gif) no-repeat 0 0px;
background: url(widgets/default/star.gif) no-repeat 0 0px;
}
div.fivestar-widget-static .star span.on {
display: block;
width: 100%;
height: 100%;
background: url(star.gif) no-repeat 0 -32px;
background: url(widgets/default/star.gif) no-repeat 0 -32px;
}
div.fivestar-widget-static .star span.off {
display: block;
width: 100%;
height: 100%;
background: url(star.gif) no-repeat 0 0px;
background: url(widgets/default/star.gif) no-repeat 0 0px;
}
/* Javascript Star Version */
......@@ -49,11 +49,11 @@ div.fivestar-widget .cancel, div.fivestar-widget .star {
text-indent: -999em;
}
div.fivestar-widget .cancel, div.fivestar-widget .cancel a {
background: url(delete.gif) no-repeat 0 -16px;
background: url(widgets/default/delete.gif) no-repeat 0 -16px;
}
div.fivestar-widget .star, div.fivestar-widget .star a {
background: url(star.gif) no-repeat 0 0px;
background: url(widgets/default/star.gif) no-repeat 0 0px;
}
div.fivestar-widget .cancel a, div.fivestar-widget .star a {
......@@ -69,4 +69,14 @@ div.fivestar-widget div.on a {
}
div.fivestar-widget div.hover a, div.rating div a:hover {
background-position: 0 -32px;
}
/* Fivestar Settings Preview */
iframe.fivestar-preview {
border: none;
width: 200px;
height: 32px;
}
div.fivestar-widgets div.form-item {
float: left;
}
\ No newline at end of file
......@@ -6,6 +6,20 @@
* A simple n-star voting widget, usable in other forms.
*/
function fivestar_help($section) {
switch ($section) {
case 'admin/settings/fivestar':
$output = t('This page is used to configure site-wide features of the fivestar module. To setup fivestar to rate content:');
$steps = array(
t('Configure site-wide settings for fivestar below.'),
t('Go to <a href="!types">admin/content/types</a> and edit the type you would like to rate.', array('!types' => url('admin/content/types'))),
t('On the settings page for the content type, a set of options is available for fivestar, where you can enabled rating for that type and set rating options.'),
);
$output .= theme('item_list', $steps, NULL, 'ol');
}
return $output;
}
/**
* Implementation of hook_menu.
* Provides a callback url where votes can be submitted by the client-side
......@@ -14,6 +28,20 @@
function fivestar_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/fivestar',
'title' => t('Fivestar'),
'callback' => 'drupal_get_form',
'callback arguments' => array('fivestar_settings'),
'type' => MENU_NORMAL_ITEM,
'access' => user_access('administer site configuration'),
);
$items[] = array(
'path' => 'fivestar/preview',
'callback' => 'fivestar_preview_page',
'type' => MENU_CALLBACK,
'access' => user_access('administer site configuration'),
);
$items[] = array(
'path' => 'fivestar/vote',
'callback' => 'fivestar_vote',
......@@ -117,6 +145,83 @@ function fivestar_form_alter($form_id, &$form) {
}
}
/**
* Callback function for admin/settings/fivestar. Display the settings form.
*/
function fivestar_settings() {
$form = array();
$form['fivestar_widget'] = array (
'#type' => 'radios',
'#title' => t('Widget display'),
'#options' => array('default' => t('Default')) + module_invoke_all('fivestar_widgets'),
'#default_value' => variable_get('fivestar_widget', 'default'),
'#description' => t('Choose a widget set to be used on your site.'),
'#attributes' => array('class' => 'fivestar-widgets clear-block'),
);
return system_settings_form($form);
}
function theme_fivestar_settings($form) {
fivestar_add_css();
drupal_set_title('Fivestar Settings');
// Default preview.
$form['fivestar_widget']['default']['#description'] = 'Default '. t('Preview') .':<br /><iframe class="fivestar-preview" scrolling="no" src="'. url('fivestar/preview') .'"></iframe>';
// Preview for each widget.
$widget_number = 0;
foreach (element_children($form['fivestar_widget']) as $widget_key) {
if ($widget_key != 'default') {
$form['fivestar_widget'][$widget_key]['#description'] = $form['fivestar_widget'][$widget_key]['#title'] .' '. t('Preview') .':<br /><iframe class="fivestar-preview" scrolling="no" src="'. url('fivestar/preview/'. $widget_number) .'"></iframe>';
$widget_number++;
}
}
return drupal_render($form);
}
/**
* Callback function for fivestar/preview. Outputs an entire page containing a
* preview of the passed in fivestar widget format.
*/
function fivestar_preview_page($widget_number = NULL) {
$widgets = module_invoke_all('fivestar_widgets');
$css_files = array_keys($widgets);
if (isset($css_files[$widget_number])) {
fivestar_add_css($css_files[$widget_number]);
}
else {
fivestar_add_css('default');
}
print theme('fivestar_preview_page');
exit;
}
function theme_fivestar_preview_page() {
$form = array();
$form['vote'] = array(
'#type' => 'fivestar',
'#stars' => 5,
'#auto_submit' => FALSE,
'#allow_clear' => TRUE,
);
$form = form_builder('upload_js', $form);
$output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
$output .= '<html xmlns="http://www.w3.org/1999/xhtml">';
$output .= '<head>';
$output .= ' <title>'. t('Fivestar Preview') .'</title>';
$output .= drupal_get_html_head();
$output .= drupal_get_css();
$output .= drupal_get_js();
$output .= ' </head>';
$output .= ' <body style="background-color: #fff; color: #000;">';
$output .= drupal_render($form);
$output .= '</body></html>';
return $output;
}
/**
* Callback function for fivestar/vote path
......@@ -266,6 +371,29 @@ function _fivestar_validate_target($type, $id) {
}
}
/**
* Implementation of hook_fivestar_widgets.
*
* This hook allows other modules to create additional custom widgets for
* the fivestar module.
*
* @return array
* An array of key => value pairs suitable for inclusion as the #options in a
* select or radios form element. Each key must be the location of a css
* file for a five star widget. Each value should be the name of the widget.
*/
function fivestar_fivestar_widgets() {
$widgets_directory = drupal_get_path('module', 'fivestar') .'/widgets';
$files = file_scan_directory($widgets_directory, '\.css$');
$widgets = array();
foreach ($files as $file) {
$widgets[$file->filename] = drupal_ucfirst($file->name);
}
return $widgets;
}
/**
* Implementation of hook_nodeapi()
*
......@@ -398,6 +526,11 @@ function fivestar_form($content_type, $content_id, $style = 'default') {
'#attributes' => array('class' => 'fivestar-submit'),
);
// Add javascript to hide the submit button.
if (strpos(drupal_get_js(), "jQuery('input.fivestar-submit').hide()") === FALSE) {
drupal_add_js("jQuery(function(){jQuery('input.fivestar-submit').hide();});", 'inline');
}
$form['#attributes']['class'] = 'fivestar-widget';
$form['#base'] = 'fivestar_form';
$form['#redirect'] = FALSE;
......@@ -445,7 +578,9 @@ function fivestar_elements() {
* values are associative arrays in the normal $options format.
*/
function theme_fivestar($element) {
drupal_add_css(drupal_get_path('module', 'fivestar') .'/theme/fivestar.css');
// Add necessary CSS.
fivestar_add_css();
$element['#children'] = '<div class="fivestar-widget container-inline">'. $element['#children'] .'</div>';
if ($element['#title'] || $element['#description']) {
if (isset($element['#description'])) {
......@@ -474,7 +609,9 @@ function theme_fivestar($element) {
*
*/
function theme_fivestar_static($rating, $stars = 5) {
drupal_add_css(drupal_get_path('module', 'fivestar') .'/theme/fivestar.css');
// Add necessary CSS.
fivestar_add_css();
$output = '';
$output .= '<div class="fivestar-widget-static clear-block">';
for ($n=1; $n <= $stars; $n++) {
......@@ -504,6 +641,23 @@ function theme_fivestar_summary($rating, $votes = 0, $stars = 5) {
return t('Average: !stars (!votes !vote_text)', array('!stars' => $stars, '!votes' => $votes, '!vote_text' => $vote_text));
}
/**
* Fetch the necessary CSS files to render the fivestar widget.
*/
function fivestar_add_css($widget_css = NULL) {
// Add fivestar CSS.
drupal_add_css(drupal_get_path('module', 'fivestar') .'/fivestar.css');
// Add widget specific CSS.
if (!isset($widget_css)) {
$widget_css = variable_get('fivestar_widget', 'default');
}
if ($widget_css != 'default') {
drupal_add_css($widget_css, 'module');
}
}
/**
* Process callback for fivestar_element -- see fivestar_element()
*/
......@@ -514,9 +668,6 @@ function fivestar_expand($element) {
drupal_add_js(drupal_get_path('module', 'fivestar') . '/jquery.rating.js');
drupal_add_js("jQuery(function(){jQuery('div.fivestar-widget').rating();});", 'inline');
}
if (strpos(drupal_get_js(), "jQuery('input.fivestar-submit').hide()") === FALSE) {
drupal_add_js("jQuery(function(){jQuery('input.fivestar-submit').hide();});", 'inline');
}
if (isset($element['#vote_count'])) {
$element['vote_count'] = array(
......
File moved
File moved
/* Static View-only Star Version */
div.fivestar-widget-static .star {
width: 17px;
height: 16px;
background: url(druplicon.gif) no-repeat 0 0px;
}
div.fivestar-widget-static .star span.on {
background: url(druplicon.gif) no-repeat 0 -32px;
}
div.fivestar-widget-static .star span.off {
background: url(druplicon.gif) no-repeat 0 0px;
}
/* Javascript Star Version */
div.fivestar-widget .cancel, div.fivestar-widget .star {
width: 17px;
height: 16px;
}
div.fivestar-widget .star, div.fivestar-widget .star a {
background: url(druplicon.gif) no-repeat 0 0px;
}
div.fivestar-widget div.on a {
background-position: 0 -16px;
}
div.fivestar-widget div.hover a, div.rating div a:hover {
background-position: 0 -32px;
}
\ No newline at end of file
File moved
File moved
File moved
/* Static View-only Star Version */
div.fivestar-widget-static .star {
width: 17px;
height: 15px;
background: url(heart.gif) no-repeat 0 0px;
}
div.fivestar-widget-static .star span.on {
background: url(heart.gif) no-repeat 0 -32px;
}
div.fivestar-widget-static .star span.off {
background: url(heart.gif) no-repeat 0 0px;
}
/* Javascript Star Version */
div.fivestar-widget .cancel, div.fivestar-widget .star {
width: 17px;
height: 15px;
}
div.fivestar-widget .cancel, div.fivestar-widget .cancel a {
background: url(heart_broken.gif) no-repeat 0 0;
}
div.fivestar-widget .star, div.fivestar-widget .star a {
background: url(heart.gif) no-repeat 0 0px;
}
div.fivestar-widget div.on a {
background-position: 0 -16px;
}
div.fivestar-widget div.hover a, div.rating div a:hover {
background-position: 0 -32px;
}
\ No newline at end of file
File moved
/* Static View-only Star Version */
div.fivestar-widget-static .star {
width: 17px;
height: 16px;
background: url(lullabot.gif) no-repeat 0 0px;
}
div.fivestar-widget-static .star span.on {
background: url(lullabot.gif) no-repeat 0 -32px;
}
div.fivestar-widget-static .star span.off {
background: url(lullabot.gif) no-repeat 0 0px;
}
/* Javascript Star Version */
div.fivestar-widget .cancel, div.fivestar-widget .star {
width: 17px;
height: 16px;
}
div.fivestar-widget .star, div.fivestar-widget .star a {
background: url(lullabot.gif) no-repeat 0 0px;
}
div.fivestar-widget div.on a {
background-position: 0 -16px;
}
div.fivestar-widget div.hover a, div.rating div a:hover {
background-position: 0 -32px;
}
\ No newline at end of file
/* Static View-only Star Version */
div.fivestar-widget-static .star {
width: 17px;
height: 15px;
background: url(small_star.png) no-repeat 0 0px;
}
div.fivestar-widget-static .star span.on {
background: url(small_star.png) no-repeat 0 -32px;
}
div.fivestar-widget-static .star span.off {
background: url(small_star.png) no-repeat 0 0px;
}
/* Javascript Star Version */
div.fivestar-widget .cancel, div.fivestar-widget .star {
width: 17px;
height: 15px;
}
div.fivestar-widget .cancel, div.fivestar-widget .cancel a {
background: url(small_delete.png) no-repeat 0 0;
}
div.fivestar-widget .star, div.fivestar-widget .star a {
background: url(small_star.png) no-repeat 0 0px;
}
div.fivestar-widget div.on a {
background-position: 0 -16px;
}
div.fivestar-widget div.hover a, div.rating div a:hover {
background-position: 0 -32px;
}
\ No newline at end of file
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment