| 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 ratings? (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_allow_rate_own_nodes'] = array( |
| 98 |
|
'#type' => 'checkbox', |
| 99 |
|
'#title' => t('Allow users to rate their own nodes'), |
| 100 |
|
'#default_value' => variable_get('jrating_allow_rate_own_nodes', 1), |
| 101 |
|
//'#options' => array ('1' => t('Yes'), '0' => t('No')), |
| 102 |
|
'#description' => t('Should users be allowed to rate nodes they created?'), |
| 103 |
|
); |
| 104 |
|
|
| 105 |
$form['jrating_form_weight'] = array( |
$form['jrating_form_weight'] = array( |
| 106 |
'#type' => 'weight', |
'#type' => 'weight', |
| 177 |
} |
} |
| 178 |
|
|
| 179 |
function jrating_display_rating_form($content_type, $content_id, $teaser = FALSE){ |
function jrating_display_rating_form($content_type, $content_id, $teaser = FALSE){ |
| 180 |
if (jrating_display_to_user() && (!$teaser || variable_get('jrating_display_form_teaser', 0))){ |
if ((!$teaser || variable_get('jrating_display_form_teaser', 0)) && jrating_display_form_to_user($content_type, $content_id)){ |
| 181 |
$rating_form = drupal_get_form( |
$rating_form = drupal_get_form( |
| 182 |
'rating_form_' . $content_type . '_' . $content_id, |
'rating_form_' . $content_type . '_' . $content_id, |
| 183 |
array( |
array( |
| 194 |
return theme('jrating_rating_item', $content_type, $content_id, $mean_rating, $rating_form); |
return theme('jrating_rating_item', $content_type, $content_id, $mean_rating, $rating_form); |
| 195 |
} |
} |
| 196 |
|
|
| 197 |
function jrating_display_to_user(){ |
function jrating_display_form_to_user($content_type, $content_id){ |
| 198 |
|
global $user; |
| 199 |
|
// anonymous and 'display rating widget to anonymous' set |
| 200 |
|
if (!$user->uid && variable_get('jrating_display_anonymous', 1)) { |
| 201 |
|
return TRUE; |
| 202 |
|
} |
| 203 |
|
|
| 204 |
|
// signed in and allowed to rate this item |
| 205 |
|
if (jrating_allow_user_rating($content_type, $content_id)){ |
| 206 |
|
return TRUE; |
| 207 |
|
} |
| 208 |
|
return FALSE; |
| 209 |
|
} |
| 210 |
|
|
| 211 |
|
function jrating_allow_user_rating($content_type, $content_id){ |
| 212 |
global $user; |
global $user; |
| 213 |
if (user_access('rate content')) { |
if (user_access('rate content')) { |
| 214 |
return TRUE; |
if ($user->uid && $content_type == 'node' && !variable_get('jrating_allow_rate_own_nodes', 1)){ |
| 215 |
} |
$node = node_load($content_id); |
| 216 |
|
if ($node->uid == $user->uid){ |
| 217 |
if (!$user->uid) { |
return FALSE; |
| 218 |
if (variable_get('jrating_display_anonymous', 1)){ |
} |
|
return TRUE; |
|
| 219 |
} |
} |
| 220 |
|
return TRUE; |
| 221 |
} |
} |
|
|
|
| 222 |
return FALSE; |
return FALSE; |
| 223 |
} |
} |
| 224 |
|
|
| 296 |
global $user; |
global $user; |
| 297 |
$vote = new stdClass; |
$vote = new stdClass; |
| 298 |
|
|
| 299 |
if (user_access('rate content')) { |
$content_type = $form_values['content_type']; |
| 300 |
$content_type = $form_values['content_type']; |
$content_id = $form_values['content_id']; |
| 301 |
$content_id = $form_values['content_id']; |
|
| 302 |
|
if (jrating_allow_user_rating($content_type, $content_id)) { |
| 303 |
$vote->value = max(0, min(100, $form_values['rating'])); |
$vote->value = max(0, min(100, $form_values['rating'])); |
| 304 |
$vote->value_type = 'percent'; |
$vote->value_type = 'percent'; |
| 305 |
$vote->tag = 'vote'; |
$vote->tag = 'vote'; |
| 324 |
} |
} |
| 325 |
} |
} |
| 326 |
else { |
else { |
| 327 |
if (!$user->uid){ |
$response = array('error' => $user->uid ? |
| 328 |
$error = t('You need to !login to rate items', array('!login' => l(t('login or register'), 'user/login', NULL, 'destination=' . $_GET['q']))); |
t('Sorry, you haven\'t got permission to vote on this item') : |
| 329 |
} |
t('You need to !login to rate items', array('!login' => l(t('login or register'), 'user/login', NULL, 'destination=' . $_GET['q']))) |
| 330 |
else{ |
); |
|
$error = t('Sorry, you haven\'t got permission to vote on this item'); |
|
|
} |
|
|
$response = array('error' => $error); |
|
| 331 |
} |
} |
| 332 |
|
|
| 333 |
if ($_SERVER["HTTP_X_REQUESTED_WITH"] == 'XMLHttpRequest') { |
if ($_SERVER["HTTP_X_REQUESTED_WITH"] == 'XMLHttpRequest') { |