| 30 |
'access' => user_access('administer site configuration'), |
'access' => user_access('administer site configuration'), |
| 31 |
); |
); |
| 32 |
} |
} |
|
else{ |
|
|
drupal_add_js('function rating_postsubmit(id){' . theme('jrating_postsubmit') . '}', 'inline'); // FIXME: does this break because it's inline? |
|
|
} |
|
| 33 |
|
|
| 34 |
return $items; |
return $items; |
| 35 |
} |
} |
| 46 |
*/ |
*/ |
| 47 |
function jrating_settings() { |
function jrating_settings() { |
| 48 |
$form['jrating_display_anonymous'] = array( |
$form['jrating_display_anonymous'] = array( |
| 49 |
'#type' => 'radios', |
'#type' => 'checkbox', |
| 50 |
'#title' => t('Display rating widget for anonymous users'), |
'#title' => t('Display a rating widget for anonymous users'), |
| 51 |
'#default_value' => variable_get('jrating_display_anonymous', 1), |
'#default_value' => variable_get('jrating_display_anonymous', 1), |
| 52 |
'#options' => array ('1' => t('Yes'), '0' => t('No')), |
//'#options' => array ('1' => t('Yes'), '0' => t('No')), |
| 53 |
'#description' => t('Should a rating widget be present when users aren\'t logged in?') |
'#description' => t('Should a rating widget be displayed when users aren\'t logged in?') |
| 54 |
); |
); |
| 55 |
|
|
| 56 |
$form['jrating_display_form_teaser'] = array( |
$form['jrating_display_form_teaser'] = array( |
| 57 |
'#type' => 'radios', |
'#type' => 'checkbox', |
| 58 |
'#title' => t('Display rating widget for teasers'), |
'#title' => t('Display a rating widget for node teasers'), |
| 59 |
'#default_value' => variable_get('jrating_display_form_teaser', 0), |
'#default_value' => variable_get('jrating_display_form_teaser', 0), |
| 60 |
'#options' => array ('1' => t('Yes'), '0' => t('No')), |
//'#options' => array ('1' => t('Yes'), '0' => t('No')), |
| 61 |
'#description' => t('Should a rating widget for a node be present when only a node teaser is displayed?') |
'#description' => t('Should a rating widget for a node be present when only a node teaser is displayed?') |
| 62 |
); |
); |
| 63 |
|
|
| 64 |
$form['jrating_display_mean_node'] = array( |
$form['jrating_display_mean_node'] = array( |
| 65 |
'#type' => 'radios', |
'#type' => 'checkbox', |
| 66 |
'#title' => t('Display average rating'), |
'#title' => t('Display the average rating for nodes'), |
| 67 |
'#default_value' => variable_get('jrating_display_mean_node', 1), |
'#default_value' => variable_get('jrating_display_mean_node', 1), |
| 68 |
'#options' => array ('1' => t('Yes'), '0' => t('No')), |
//'#options' => array ('1' => t('Yes'), '0' => t('No')), |
| 69 |
'#description' => t('Should the average rating for a node be displayed?') |
'#description' => t('Should the average rating for a node be displayed?') |
| 70 |
); |
); |
| 71 |
|
|
| 72 |
$form['jrating_display_mean_teaser'] = array( |
$form['jrating_display_mean_teaser'] = array( |
| 73 |
'#type' => 'radios', |
'#type' => 'checkbox', |
| 74 |
'#title' => t('Display average rating for teasers'), |
'#title' => t('Display the average rating for node teasers'), |
| 75 |
'#default_value' => variable_get('jrating_display_mean_teaser', 0), |
'#default_value' => variable_get('jrating_display_mean_teaser', 0), |
| 76 |
'#options' => array ('1' => t('Yes'), '0' => t('No')), |
//'#options' => array ('1' => t('Yes'), '0' => t('No')), |
| 77 |
'#description' => t('Should the average rating for a node be present when only a node teaser is displayed?'), |
'#description' => t('Should the average rating for a node be present when only a node teaser is displayed?'), |
| 78 |
'#disabled' => (! variable_get('jrating_display_mean', 1)) |
'#disabled' => (! variable_get('jrating_display_mean', 1)) |
| 79 |
); |
); |
| 80 |
|
|
| 81 |
$form['jrating_display_mean_comment'] = array( |
$form['jrating_display_mean_comment'] = array( |
| 82 |
'#type' => 'radios', |
'#type' => 'checkbox', |
| 83 |
'#title' => t('Display average rating for comments'), |
'#title' => t('Display the average rating for comments'), |
| 84 |
'#default_value' => variable_get('jrating_display_mean_comment', 1), |
'#default_value' => variable_get('jrating_display_mean_comment', 1), |
| 85 |
'#options' => array ('1' => t('Yes'), '0' => t('No')), |
//'#options' => array ('1' => t('Yes'), '0' => t('No')), |
| 86 |
'#description' => t('Should the average rating for a comment be displayed?'), |
'#description' => t('Should the average rating for a comment be displayed?'), |
| 87 |
); |
); |
| 88 |
|
|
| 89 |
$form['jrating_allow_changes'] = array( |
$form['jrating_allow_changes'] = array( |
| 90 |
'#type' => 'radios', |
'#type' => 'checkbox', |
| 91 |
'#title' => t('Allow users to change their votes'), |
'#title' => t('Allow users to change their ratings'), |
| 92 |
'#default_value' => variable_get('jrating_allow_changes', 1), |
'#default_value' => variable_get('jrating_allow_changes', 1), |
| 93 |
'#options' => array ('1' => t('Yes'), '0' => t('No')), |
//'#options' => array ('1' => t('Yes'), '0' => t('No')), |
| 94 |
'#description' => t('Should users be allowed to change their votes? (doesn\'t apply to anonymous users)'), |
'#description' => t('Should users be allowed to change their ratings? (doesn\'t apply to anonymous users)'), |
| 95 |
); |
); |
| 96 |
|
|
| 97 |
$form['jrating_form_weight'] = array( |
$form['jrating_form_weight'] = array( |
| 376 |
} |
} |
| 377 |
} |
} |
| 378 |
// anonymous |
// anonymous |
|
// FIXME: only do this if anonymous voting is enabled |
|
| 379 |
else{ |
else{ |
| 380 |
$hostname = $_SERVER['HTTP_X_FORWARDED_FOR'] ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; |
$hostname = $_SERVER['HTTP_X_FORWARDED_FOR'] ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; |
| 381 |
$rating = db_fetch_object(db_query("SELECT value FROM {votingapi_vote} WHERE content_type = '%s' AND content_id = %d AND value_type = 'percent' AND tag = 'vote' AND uid = 0 AND hostname = '%s' AND timestamp > %d", $content_type, $content_id, $hostname, time() - (60 * 60 * 24))); // existing vote from the same IP address within the past day |
$rating = db_fetch_object(db_query("SELECT value FROM {votingapi_vote} WHERE content_type = '%s' AND content_id = %d AND value_type = 'percent' AND tag = 'vote' AND uid = 0 AND hostname = '%s' AND timestamp > %d", $content_type, $content_id, $hostname, time() - (60 * 60 * 24))); // existing vote from the same IP address within the past day |
| 428 |
return $output; |
return $output; |
| 429 |
} |
} |
| 430 |
|
|
|
function theme_jrating_rating_item($content_type, $content_id, $mean_rating = NULL, $rating_form = NULL){ |
|
|
return sprintf( |
|
|
'<div class="rating-item">%s<div id="rating-%s-%d" class="rating"><div class="rating-intro" id="rating-intro-%s-%d"></div>%s</div></div>', |
|
|
$mean_rating, $content_type, $content_id, $content_type, $content_id, $rating_form |
|
|
); |
|
|
} |
|
|
|
|
| 431 |
function theme_jrating_static($value) { |
function theme_jrating_static($value) { |
| 432 |
return sprintf('<div class="rating"><div class="rating-stars">%s</div></div>', theme('jrating_stars', $value)); |
return sprintf('<div class="rating"><div class="rating-stars">%s</div></div>', theme('jrating_stars', $value)); |
| 433 |
} |
} |
| 458 |
function theme_jrating_average_rating($content_type, $content_id, $rating){ |
function theme_jrating_average_rating($content_type, $content_id, $rating){ |
| 459 |
$num_votes_html = sprintf('<span class="rating-num-votes-%s-%d">%s</span>', $content_type, $content_id, format_plural($rating['num_votes'], '1 vote', '@count votes')); |
$num_votes_html = sprintf('<span class="rating-num-votes-%s-%d">%s</span>', $content_type, $content_id, format_plural($rating['num_votes'], '1 vote', '@count votes')); |
| 460 |
|
|
| 461 |
return sprintf('<div class="rating" id="rating-mean-%s-%d"><div class="rating-intro"><span class="rating-intro-text">%s</span></div><div class="rating-stars" id="rating-mean-stars-%s-%d">%s</div><div class="num-votes">(%s)</div></div>', $content_type, $content_id, t('Average rating'), $content_type, $content_id, theme('jrating_stars', $rating['rating']), $num_votes_html); |
return sprintf('<div class="rating rating-mean" id="rating-mean-%s-%d"><div class="rating-intro"><span class="rating-intro-text">%s</span></div><div class="rating-stars" id="rating-mean-stars-%s-%d">%s</div><div class="num-votes">(%s)</div></div>', $content_type, $content_id, t('Average rating'), $content_type, $content_id, theme('jrating_stars', $rating['rating']), $num_votes_html); |
| 462 |
} |
} |
| 463 |
|
|
| 464 |
/** |
function theme_jrating_rating_item($content_type, $content_id, $mean_rating = NULL, $rating_form = NULL){ |
| 465 |
* Javascript function called after rating is submitted |
return sprintf( |
| 466 |
*/ |
'<div class="rating-item">%s<div id="rating-%s-%d" class="rating rating-user"><div class="rating-intro" id="rating-intro-%s-%d"></div>%s</div></div>', |
| 467 |
function theme_jrating_postsubmit(){ |
$mean_rating, $content_type, $content_id, $content_type, $content_id, $rating_form |
| 468 |
return 'return true;'; |
); |
| 469 |
} |
} |