diff -urp ./fivestar.module ../fivestarnew/fivestar.module
--- ./fivestar.module 2008-08-08 14:27:32.000000000 +0200
+++ ../fivestarnew/fivestar.module 2008-08-08 16:07:20.000000000 +0200
@@ -627,6 +627,8 @@ function theme_fivestar_preview_wrapper(
*
* @param type
* A content-type to log the vote to. 'node' is the most common.
+ * @param tag
+ * Multi-axis tag to allow multiple votes per node. 'vote' is the most common.
* @param cid
* A content id to log the vote to. This would be a node ID, a comment ID, etc.
* @param value
@@ -635,7 +637,7 @@ function theme_fivestar_preview_wrapper(
* An XML chunk containing the results of the vote, for use by the client-side
* javascript code.
*/
-function fivestar_vote($type, $cid, $value, $tag = 'vote') {
+function fivestar_vote($tag, $type, $cid, $value) {
_fivestar_cast_vote($type, $cid, $value, $tag);
$result = votingapi_recalculate_results($type, $cid);
@@ -672,6 +674,7 @@ function fivestar_vote($type, $cid, $val
$output .= ''. $value .'';
$output .= ''. $type .'';
$output .= ''. $cid .'';
+ $output .= ''. $tag .'';
$output .= '';
drupal_set_header("Content-Type: text/xml");
@@ -826,7 +829,7 @@ function fivestar_nodeapi(&$node, $op, $
case 'below_static':
$stars = variable_get('fivestar_stars_'. $node->type, 5);
$node->content['fivestar_widget'] = array(
- '#value' => fivestar_static('node', $node->nid, $node->type),
+ '#value' => fivestar_static('node', $node->nid, $tag, $node->type),
'#weight' => $position == 'above_static' ? -10 : 50,
);
break;
@@ -883,8 +886,8 @@ function fivestar_block($op = 'list', $d
}
}
-function fivestar_widget_form($node) {
- return drupal_get_form('fivestar_form_node_'. $node->nid, 'node', $node->nid);
+function fivestar_widget_form($node, $tag ='vote') {
+ return drupal_get_form('fivestar_form_node_'. $node->nid .'_'. $tag, 'node', $node->nid, $tag);
}
/**
@@ -895,7 +898,7 @@ function fivestar_widget_form($node) {
function fivestar_forms() {
$args = func_get_args();
if (strpos($args[0][0], 'fivestar_form') !== FALSE) {
- if ($args[0][0] == 'fivestar_form_'. $args[0][1] .'_'. $args[0][2]) {
+ if ($args[0][0] == 'fivestar_form_'. $args[0][1] .'_'. $args[0][2] .'_'. $args[0][3]) {
$forms[$args[0][0]] = array('callback' => 'fivestar_form');
return $forms;
}
@@ -907,7 +910,7 @@ function fivestar_forms() {
* Note that this is not an implementation of hook_form(). We should probably
* change the function to reflect that.
*/
-function fivestar_form($content_type, $content_id) {
+function fivestar_form($content_type, $content_id, $tag) {
global $user;
if ($content_type == 'node') {
@@ -919,10 +922,10 @@ function fivestar_form($content_type, $c
}
}
- $current_avg = votingapi_get_voting_result($content_type, $content_id, 'percent', 'vote', 'average');
- $current_count = votingapi_get_voting_result($content_type, $content_id, 'percent', 'vote', 'count');
+ $current_avg = votingapi_get_voting_result($content_type, $content_id, 'percent', $tag, 'average');
+ $current_count = votingapi_get_voting_result($content_type, $content_id, 'percent', $tag, 'count');
if ($user->uid) {
- $user_vote = votingapi_get_vote($content_type, $content_id, 'percent', 'vote', $user->uid);
+ $user_vote = votingapi_get_vote($content_type, $content_id, 'percent', $tag, $user->uid);
}
else {
// If the user is anonymous, we never bother loading their existing votes.
@@ -942,6 +945,7 @@ function fivestar_form($content_type, $c
'allow_clear' => variable_get('fivestar_unvote_'. $node->type, FALSE),
'style' => variable_get('fivestar_style_'. $node->type, 'average'),
'text' => variable_get('fivestar_text_'. $node->type, 'combo'),
+ 'tag' => $tag,
'content_type' => $content_type,
'content_id' => $content_id,
'autosubmit' => TRUE,
@@ -954,12 +958,12 @@ function fivestar_form($content_type, $c
return fivestar_custom_widget($values, $settings);
}
-function fivestar_static($content_type, $content_id, $node_type = NULL) {
+function fivestar_static($content_type, $content_id, $tag = 'vote', $node_type = NULL) {
global $user;
- $current_avg = votingapi_get_voting_result($content_type, $content_id, 'percent', 'vote', 'average');
- $current_count = votingapi_get_voting_result($content_type, $content_id, 'percent', 'vote', 'count');
- $user_vote = $user->uid ? votingapi_get_vote($content_type, $content_id, 'percent', 'vote', $user->uid) : 0;
+ $current_avg = votingapi_get_voting_result($content_type, $content_id, 'percent', $tag, 'average');
+ $current_count = votingapi_get_voting_result($content_type, $content_id, 'percent', $tag, 'count');
+ $user_vote = $user->uid ? votingapi_get_vote($content_type, $content_id, 'percent', $tag, $user->uid) : 0;
if ($content_type == 'node') {
// Content type should always be passed to avoid this node load.
@@ -1059,13 +1063,14 @@ function fivestar_custom_widget($values,
'#vote_count' => $values['count'],
'#vote_average' => $values['average'],
'#auto_submit' => isset($settings['autosubmit']) ? $settings['autosubmit'] : TRUE,
- '#auto_submit_path' => (!isset($settings['autosubmit']) || $settings['autosubmit']) ? 'fivestar/vote/'. $settings['content_type'] .'/'. $settings['content_id'] : NULL,
+ '#auto_submit_path' => (!isset($settings['autosubmit']) || $settings['autosubmit']) ? 'fivestar/vote/'. $settings['tag'] .'/'. $settings['content_type'] .'/'. $settings['content_id'] : NULL,
'#allow_clear' => $settings['allow_clear'],
'#content_id' => isset($settings['content_id']) ? $settings['content_id'] : NULL,
'#required' => isset($settings['required']) ? $settings['required'] : FALSE,
'#feedback_enable' => isset($settings['feedback_enable']) ? $settings['feedback_enable'] : TRUE,
'#labels_enable' => isset($settings['labels_enable']) ? $settings['labels_enable'] : TRUE,
'#labels' => isset($settings['labels']) ? $settings['labels'] : NULL,
+ '#tag' => isset($settings['tag']) ? $settings['tag'] : 'vote',
);
$form['destination'] = array(
@@ -1123,7 +1128,7 @@ function fivestar_custom_widget($values,
$form['vote']['#default_value'] = $values['user'];
$form['vote']['#attributes']['class'] .= ' fivestar-combo-stars';
$form['#attributes']['class'] .= ' fivestar-combo-stars';
- $static_average = theme('fivestar_static', $values['average'], $settings['stars']);
+ $static_average = theme('fivestar_static', $values['average'], $settings['stars'], $settings['tag']);
if ($settings['text'] == 'none' && !$settings['labels_enable'] && !$settings['feedback_enable']) {
$static_description = NULL;
}
@@ -1161,10 +1166,8 @@ function fivestar_custom_widget($values,
* Submit handler for the above form (non-javascript version).
*/
function fivestar_form_submit($form_id, $form_values) {
- if ($form_id == 'fivestar_form_'. $form_values['content_type'] .'_'. $form_values['content_id']) {
- // Cast the vote.
- _fivestar_cast_vote($form_values['content_type'], $form_values['content_id'], $form_values['vote']);
- votingapi_recalculate_results($form_values['content_type'], $form_values['content_id']);
+ if ($form_id == 'fivestar_form_'. $form_values['content_type'] .'_'. $form_values['content_id'] .'_'. $form_values['vote']['#tag']) {
+ _fivestar_cast_vote($form_values['content_type'], $form_values['content_id'], $form_values['vote'], $form_values['vote']['#tag']);
// Set a message that the vote was received.
if ($form_values['vote'] === '0') {
@@ -1244,8 +1247,12 @@ function theme_fivestar_widget($form) {
unset($form['vote']['#description']);
}
+ $class = 'fivestar-form';
+ $class .= '-'. (isset($form['vote']['#tag']) ? $form['tag']['#tag'] : 'vote');
+ $class .= '-'. (isset($form['content_id']['#value']) ? $form['content_id']['#value'] : 0);
+
$output = '';
- $output .= '
';
+ $output .= '
';
$output .= drupal_render($form);
$output .= '
';
return $output;
@@ -1259,17 +1266,18 @@ function theme_fivestar_widget($form) {
* 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($rating, $stars = 5) {
+function theme_fivestar_static($rating, $stars = 5, $tag = 'vote') {
// Add necessary CSS.
fivestar_add_css();
$output = '';
- $output .= '