Révision 3461d8cb
Ajouté par Assos Assos il y a environ 10 ans
drupal7/sites/all/modules/fivestar/fivestar.info | ||
---|---|---|
7 | 7 |
files[] = test/fivestar.base.test |
8 | 8 |
files[] = test/fivestar.field.test |
9 | 9 |
|
10 |
; Information added by Drupal.org packaging script on 2014-02-16
|
|
11 |
version = "7.x-2.0-beta1"
|
|
10 |
; Information added by Drupal.org packaging script on 2014-03-02
|
|
11 |
version = "7.x-2.0-rc1"
|
|
12 | 12 |
core = "7.x" |
13 | 13 |
project = "fivestar" |
14 |
datestamp = "1392552810"
|
|
14 |
datestamp = "1393790306"
|
|
15 | 15 |
|
drupal7/sites/all/modules/fivestar/fivestar.install | ||
---|---|---|
37 | 37 |
drupal_load('module', 'fivestar'); |
38 | 38 |
$fields = field_read_fields(array('module' => 'fivestar')); |
39 | 39 |
$tags_numeric = array_values(fivestar_get_tags()); |
40 |
|
|
40 |
|
|
41 | 41 |
foreach ($fields as $field) { |
42 | 42 |
if (is_numeric($field['settings']['axis'])) { |
43 | 43 |
$field['settings']['axis'] = $tags_numeric[$field['settings']['axis']]; |
... | ... | |
60 | 60 |
} |
61 | 61 |
} |
62 | 62 |
|
63 |
|
|
63 |
|
|
64 | 64 |
/** |
65 | 65 |
* Convert all existing fivestar/node_type settings into fields with exposed fivestar formatters |
66 | 66 |
*/ |
... | ... | |
104 | 104 |
'feedback_enable' => variable_get('fivestar_feedback_' . $var_suffix, 1), |
105 | 105 |
'style' => variable_get('fivestar_style_' . $var_suffix, 'average'), |
106 | 106 |
'text' => variable_get('fivestar_text_' . $var_suffix, 'dual'), |
107 |
'title' => variable_get('fivestar_title_' . $var_suffix, 1), |
|
107 | 108 |
); |
108 | 109 |
|
109 | 110 |
if (variable_get('fivestar_' . $var_suffix, FALSE)) { |
... | ... | |
127 | 128 |
); |
128 | 129 |
$field = field_create_field($field_values); |
129 | 130 |
} |
130 |
|
|
131 |
|
|
131 | 132 |
// Create an instance of the field in this bundle |
132 | 133 |
$instance = field_read_instance('node', $field['field_name'], $type, array('include_deleted' => TRUE)); |
133 | 134 |
if (empty($instance)) { |
134 |
$settings['allow_clear'] = $settings['unvote_enable']; |
|
135 |
$settings['style'] = $settings['star_display']; |
|
136 |
$settings['text'] = $settings['text_display']; |
|
137 |
|
|
138 | 135 |
$instance_info = array( |
139 | 136 |
'field_name' => $field['field_name'], |
140 | 137 |
'entity_type' => 'node', |
... | ... | |
160 | 157 |
'settings' => $settings, |
161 | 158 |
); |
162 | 159 |
} |
163 |
|
|
160 |
|
|
161 |
// Set the widget. |
|
162 |
$widget = variable_get('fivestar_widget' . $var_suffix, 'default'); |
|
163 |
$instance_info['widget']['settings']['widget']['fivestar_widget'] = $widget; |
|
164 |
|
|
164 | 165 |
field_create_instance($instance_info); |
165 | 166 |
} |
166 | 167 |
} |
167 | 168 |
} |
168 | 169 |
} |
169 |
|
|
170 |
|
|
170 | 171 |
// Rebuild the menu to remove the node type tag form paths |
171 | 172 |
menu_rebuild(); |
172 | 173 |
_field_info_collate_fields(TRUE); |
... | ... | |
227 | 228 |
} |
228 | 229 |
} |
229 | 230 |
} |
231 |
|
|
232 |
/** |
|
233 |
* Preserve setting after new feature preventing re-votes |
|
234 |
* @see http://drupal.org/node/356605 |
|
235 |
*/ |
|
236 |
function fivestar_update_7206() { |
|
237 |
$fields = field_read_fields(array('type' => 'fivestar')); |
|
238 |
foreach ($fields as $field) { |
|
239 |
// Iterate through the instances of the field. |
|
240 |
$instances = field_read_instances(array('field_name' => $field['field_name'])); |
|
241 |
foreach ($instances as $instance) { |
|
242 |
// The default should be to allow re-voting. |
|
243 |
$instance['settings']['allow_revote'] = TRUE; |
|
244 |
// Update the instance |
|
245 |
field_update_instance($instance); |
|
246 |
} |
|
247 |
} |
|
248 |
} |
|
249 |
|
|
250 |
/** |
|
251 |
* Preserve setting after new feature preventing own votes |
|
252 |
* @see http://drupal.org/node/189527 |
|
253 |
*/ |
|
254 |
function fivestar_update_7207() { |
|
255 |
$fields = field_read_fields(array('type' => 'fivestar')); |
|
256 |
foreach ($fields as $field) { |
|
257 |
// Iterate through the instances of the field. |
|
258 |
$instances = field_read_instances(array('field_name' => $field['field_name'])); |
|
259 |
foreach ($instances as $instance) { |
|
260 |
// The default should be to allow own votes. |
|
261 |
$instance['settings']['allow_ownvote'] = TRUE; |
|
262 |
// Update the instance |
|
263 |
field_update_instance($instance); |
|
264 |
} |
|
265 |
} |
|
266 |
} |
|
267 |
|
|
268 |
/** |
|
269 |
* Change field formatters to ensure unique. |
|
270 |
* @see http://drupal.org/node/1063754 |
|
271 |
*/ |
|
272 |
function fivestar_update_7208() { |
|
273 |
$fields = field_read_fields(array('type' => 'fivestar')); |
|
274 |
foreach ($fields as $field) { |
|
275 |
// Iterate through the instances of the field. |
|
276 |
$instances = field_read_instances(array('field_name' => $field['field_name'])); |
|
277 |
foreach ($instances as $instance) { |
|
278 |
$updated = FALSE; |
|
279 |
foreach ($instance['display'] as &$display) { |
|
280 |
if (in_array($display['type'], array('default', 'percentage', 'rating'))) { |
|
281 |
$updated = TRUE; |
|
282 |
$display['type'] = 'fivestar_formatter_' . $display['type']; |
|
283 |
} |
|
284 |
} |
|
285 |
if ($updated) { |
|
286 |
// Only trigger instance update if we actually changed anything. |
|
287 |
field_update_instance($instance); |
|
288 |
} |
|
289 |
} |
|
290 |
} |
|
291 |
} |
drupal7/sites/all/modules/fivestar/fivestar.module | ||
---|---|---|
53 | 53 |
'average_rating' => array( |
54 | 54 |
'#itemprop' => array('ratingValue'), |
55 | 55 |
), |
56 |
'rating_count' => array( |
|
57 |
'#itemprop' => array('ratingCount'), |
|
58 |
), |
|
56 | 59 |
); |
57 | 60 |
|
58 | 61 |
return $mappings; |
... | ... | |
142 | 145 |
* voting, etc... |
143 | 146 |
*/ |
144 | 147 |
|
145 |
function _fivestar_cast_vote($entity_type, $id, $value, $tag = NULL, $uid = NULL, $skip_validation = FALSE) { |
|
148 |
function _fivestar_cast_vote($entity_type, $id, $value, $tag = NULL, $uid = NULL, $skip_validation = FALSE, $vote_source = NULL) {
|
|
146 | 149 |
global $user; |
147 | 150 |
$tag = empty($tag) ? 'vote' : $tag; |
148 | 151 |
$uid = isset($uid) ? $uid : $user->uid; |
... | ... | |
159 | 162 |
// Get the user's current vote. |
160 | 163 |
$criteria = array('entity_type' => $entity_type, 'entity_id' => $id, 'tag' => $tag, 'uid' => $uid); |
161 | 164 |
// Get the unique identifier for the user (IP Address if anonymous). |
162 |
$user_criteria = votingapi_current_user_identifier(); |
|
163 |
$user_votes = votingapi_select_votes($criteria + $user_criteria); |
|
165 |
|
|
166 |
if ($vote_source != NULL) { |
|
167 |
$user_criteria = array('vote_source' => $vote_source); |
|
168 |
$limit = 1; |
|
169 |
} |
|
170 |
else { |
|
171 |
$user_criteria = votingapi_current_user_identifier(); |
|
172 |
$limit = 0; |
|
173 |
} |
|
174 |
$user_votes = votingapi_select_votes($criteria + $user_criteria, $limit); |
|
164 | 175 |
|
165 | 176 |
if ($value == 0) { |
166 | 177 |
votingapi_delete_votes($user_votes); |
... | ... | |
197 | 208 |
* - count: An array of VotingAPI results, including the count 'value'. |
198 | 209 |
* - user: An array of VotingAPI results, including the user's vote 'value'. |
199 | 210 |
*/ |
200 |
function fivestar_get_votes($entity_type, $id, $tag = 'vote', $uid = NULL) {
|
|
211 |
function fivestar_get_votes_multiple($entity_type, $ids, $tag = 'vote', $uid = NULL) {
|
|
201 | 212 |
global $user; |
202 | 213 |
|
203 | 214 |
if (!isset($uid)) { |
... | ... | |
206 | 217 |
|
207 | 218 |
$criteria = array( |
208 | 219 |
'entity_type' => $entity_type, |
209 |
'entity_id' => $id, |
|
220 |
'entity_id' => $ids,
|
|
210 | 221 |
'value_type' => 'percent', |
211 | 222 |
'tag' => $tag, |
212 | 223 |
); |
213 | 224 |
|
214 |
$votes = array( |
|
215 |
'average' => array(), |
|
216 |
'count' => array(), |
|
217 |
'user' => array(), |
|
218 |
); |
|
225 |
$votes = array(); |
|
226 |
|
|
227 |
// Initialize defaults. |
|
228 |
foreach($ids as $id) { |
|
229 |
$votes[$entity_type][$id] = array( |
|
230 |
'average' => array(), |
|
231 |
'count' => array(), |
|
232 |
'user' => array(), |
|
233 |
); |
|
234 |
} |
|
219 | 235 |
|
220 | 236 |
$results = votingapi_select_results($criteria); |
237 |
$user_votes = array(); |
|
238 |
if(!empty($results)) { |
|
239 |
foreach(votingapi_select_votes($criteria += array('uid' => $uid)) as $uv) { |
|
240 |
$user_votes[$uv['entity_type']][$uv['entity_id']] = $uv; |
|
241 |
} |
|
242 |
} |
|
243 |
|
|
221 | 244 |
foreach ($results as $result) { |
222 | 245 |
if ($result['function'] == 'average') { |
223 |
$votes['average'] = $result; |
|
246 |
$votes[$result['entity_type']][$result['entity_id']]['average'] = $result;
|
|
224 | 247 |
} |
225 | 248 |
if ($result['function'] == 'count') { |
226 |
$votes['count'] = $result; |
|
249 |
$votes[$result['entity_type']][$result['entity_id']]['count'] = $result;
|
|
227 | 250 |
} |
228 |
} |
|
229 |
if ($uid) { |
|
230 |
$user_vote = votingapi_select_votes($criteria += array('uid' => $uid)); |
|
231 |
if ($user_vote) { |
|
232 |
$votes['user'] = $user_vote[0]; |
|
233 |
$votes['user']['function'] = 'user'; |
|
234 |
} |
|
235 |
} |
|
236 |
else { |
|
237 |
// If the user is anonymous, we never bother loading their existing votes. |
|
238 |
// Not only would it be hit-or-miss, it would break page caching. Safer to always |
|
239 |
// show the 'fresh' version to anon users. |
|
240 |
$votes['user'] = array('value' => 0); |
|
251 |
if ($uid) { |
|
252 |
if (!empty($user_votes[$result['entity_type']][$result['entity_id']])) { |
|
253 |
$votes[$result['entity_type']][$result['entity_id']]['user'] = $user_votes[$result['entity_type']][$result['entity_id']]; |
|
254 |
$votes[$result['entity_type']][$result['entity_id']]['user']['function'] = 'user'; |
|
255 |
} |
|
256 |
} |
|
257 |
else { |
|
258 |
// If the user is anonymous, we never bother loading their existing votes. |
|
259 |
// Not only would it be hit-or-miss, it would break page caching. Safer to always |
|
260 |
// show the 'fresh' version to anon users. |
|
261 |
$votes[$result['entity_type']][$result['entity_id']]['user'] = array('value' => 0); |
|
262 |
} |
|
241 | 263 |
} |
242 | 264 |
|
243 | 265 |
return $votes; |
244 | 266 |
} |
245 | 267 |
|
268 |
function fivestar_get_votes($entity_type, $id, $tag = 'vote', $uid = NULL) { |
|
269 |
$multiple = fivestar_get_votes_multiple($entity_type, array($id), $tag, $uid); |
|
270 |
return $multiple[$entity_type][$id]; |
|
271 |
} |
|
272 |
|
|
246 | 273 |
/** |
247 | 274 |
* Check that an item being voted upon is a valid vote. |
248 | 275 |
* |
... | ... | |
351 | 378 |
* file for a fivestar widget. Each value should be the name of the widget. |
352 | 379 |
*/ |
353 | 380 |
function fivestar_fivestar_widgets() { |
354 |
$files = &drupal_static(__FUNCTION__); |
|
355 |
if (!isset($files)) { |
|
381 |
$widgets = &drupal_static(__FUNCTION__); |
|
382 |
if (!isset($widgets)) { |
|
383 |
$cache = cache_get(__FUNCTION__); |
|
384 |
if ($cache) { |
|
385 |
$widgets = $cache->data; |
|
386 |
} |
|
387 |
} |
|
388 |
|
|
389 |
if (!isset($widgets)) { |
|
356 | 390 |
$widgets_directory = drupal_get_path('module', 'fivestar') . '/widgets'; |
357 | 391 |
$files = file_scan_directory($widgets_directory, '/\.css$/'); |
358 |
} |
|
359 |
$widgets = array(); |
|
360 |
foreach ($files as $file) { |
|
361 |
if (strpos($file->filename, '-rtl.css') === FALSE) { |
|
362 |
$widgets[$file->uri] = drupal_ucfirst(str_replace('-color', '', $file->name)); |
|
392 |
foreach ($files as $file) { |
|
393 |
if (strpos($file->filename, '-rtl.css') === FALSE) { |
|
394 |
$widgets[$file->uri] = drupal_ucfirst(str_replace('-color', '', $file->name)); |
|
395 |
} |
|
363 | 396 |
} |
397 |
cache_set(__FUNCTION__, $widgets); |
|
364 | 398 |
} |
365 | 399 |
return $widgets; |
366 | 400 |
} |
... | ... | |
411 | 445 |
'#stars' => $settings['stars'], |
412 | 446 |
'#auto_submit' => isset($settings['autosubmit']) ? $settings['autosubmit'] : TRUE, |
413 | 447 |
'#allow_clear' => $settings['allow_clear'], |
448 |
'#allow_revote' => $settings['allow_revote'], |
|
449 |
'#allow_ownvote' => $settings['allow_ownvote'], |
|
414 | 450 |
'#required' => isset($settings['required']) ? $settings['required'] : FALSE, |
415 | 451 |
'#widget' => isset($settings['widget']) ? $settings['widget'] : array('name' => 'default', 'css' => 'default'), |
416 | 452 |
'#values' => $values, |
... | ... | |
431 | 467 |
* Submit handler for the above form (non-javascript version). |
432 | 468 |
*/ |
433 | 469 |
function fivestar_form_submit($form, &$form_state) { |
470 |
|
|
434 | 471 |
// Cast the vote. |
435 | 472 |
_fivestar_cast_vote($form_state['settings']['content_type'], $form_state['settings']['content_id'], $form_state['values']['vote'], $form_state['settings']['tag']); |
436 | 473 |
|
... | ... | |
448 | 485 |
*/ |
449 | 486 |
function fivestar_ajax_submit($form, $form_state) { |
450 | 487 |
if (!empty($form_state['settings']['content_id'])) { |
451 |
_fivestar_update_field_value($form_state['settings']['content_type'], $form_state['settings']['entity'], $form_state['settings']['field_name'], $form_state['settings']['langcode'], $form_state['values']['vote']); |
|
488 |
$entity = entity_load($form_state['settings']['entity_type'], array($form_state['settings']['entity_id'])); |
|
489 |
$entity = reset($entity); |
|
490 |
_fivestar_update_field_value($form_state['settings']['content_type'], $entity, $form_state['settings']['field_name'], $form_state['settings']['langcode'], $form_state['values']['vote']); |
|
452 | 491 |
$votes = _fivestar_cast_vote($form_state['settings']['content_type'], $form_state['settings']['content_id'], $form_state['values']['vote'], $form_state['settings']['tag']); |
453 | 492 |
} |
454 | 493 |
|
455 |
|
|
456 | 494 |
$values = array(); |
457 | 495 |
$values['user'] = isset($votes['user']['value']) ? $votes['user']['value'] : 0; |
458 | 496 |
$values['average'] = isset($votes['average']['value']) ? $votes['average']['value'] : 0; |
... | ... | |
463 | 501 |
$new_element = fivestar_expand($form['vote']); |
464 | 502 |
// Update the description. Since it doesn't account of our cast vote above. |
465 | 503 |
// TODO: Look into all this, I honestly don't like it and it's a bit weird. |
466 |
$form['vote']['vote']['#description'] = $new_element['vote']['#description'];
|
|
504 |
$form['vote']['vote']['#description'] = isset($new_element['vote']['#description']) ? $new_element['vote']['#description'] : '';
|
|
467 | 505 |
|
468 | 506 |
return array( |
469 | 507 |
'#type' => 'ajax', |
... | ... | |
486 | 524 |
'#input' => TRUE, |
487 | 525 |
'#stars' => 5, |
488 | 526 |
'#allow_clear' => FALSE, |
527 |
'#allow_revote' => FALSE, |
|
528 |
'#allow_ownvote' => FALSE, |
|
489 | 529 |
'#auto_submit' => FALSE, |
490 | 530 |
'#process' => array('fivestar_expand'), |
491 | 531 |
'#theme_wrappers' => array('form_element'), |
... | ... | |
510 | 550 |
* Process callback for fivestar_element -- see fivestar_element() |
511 | 551 |
*/ |
512 | 552 |
function fivestar_expand($element) { |
553 |
if (!_fivestar_allow_vote($element)){ |
|
554 |
$element['#input'] = FALSE; |
|
555 |
} |
|
556 |
|
|
513 | 557 |
// Add CSS and JS |
514 | 558 |
$path = drupal_get_path('module', 'fivestar'); |
515 | 559 |
$element['#attached']['js'][] = $path . '/js/fivestar.js'; |
... | ... | |
532 | 576 |
'#type' => 'select', |
533 | 577 |
'#options' => $options, |
534 | 578 |
'#required' => $element['#required'], |
535 |
'#theme' => 'fivestar_select', |
|
536 | 579 |
'#attributes' => $element['#attributes'], |
580 |
'#theme' => _fivestar_allow_vote($element) ? 'fivestar_select' : 'fivestar_static', |
|
537 | 581 |
'#default_value' => _fivestar_get_element_default_value($element), |
538 | 582 |
'#weight' => -2, |
539 | 583 |
); |
... | ... | |
582 | 626 |
)); |
583 | 627 |
$class[] = ' fivestar-combo-text'; |
584 | 628 |
break; |
629 |
case 'none': |
|
630 |
$element['vote']['#description'] = NULL; |
|
631 |
break; |
|
585 | 632 |
} |
586 | 633 |
|
587 | 634 |
switch ($settings['style']) { |
... | ... | |
897 | 944 |
'entity_type' => 'node', |
898 | 945 |
); |
899 | 946 |
} |
947 |
|
|
948 |
/** |
|
949 |
* Helper function to determine if a user can vote on content. |
|
950 |
* |
|
951 |
* @return Boolean |
|
952 |
*/ |
|
953 |
function _fivestar_allow_vote($element) { |
|
954 |
global $user; |
|
955 |
|
|
956 |
// check allowed to re-vote |
|
957 |
$can_revote = FALSE; |
|
958 |
if ($element['#allow_revote']) { |
|
959 |
$can_revote = TRUE; |
|
960 |
} |
|
961 |
else { |
|
962 |
$criteria = array( |
|
963 |
'entity_id' => isset($element['#settings']['content_id']) ? $element['#settings']['content_id'] : NULL, |
|
964 |
'entity_type' => isset($element['#settings']['content_type']) ? $element['#settings']['content_type'] : NULL, |
|
965 |
'uid' => $user->uid, |
|
966 |
); |
|
967 |
|
|
968 |
$can_revote = !votingapi_select_votes($criteria); |
|
969 |
} |
|
970 |
if (!$can_revote) { |
|
971 |
return FALSE; |
|
972 |
} |
|
973 |
// check allowed own vote |
|
974 |
if ($element['#allow_ownvote']) { |
|
975 |
return TRUE; |
|
976 |
} |
|
977 |
else { |
|
978 |
$entity_id = $element['#settings']['entity_id']; |
|
979 |
//$entity = entity_load($element['#settings']['entity_type'], array($element['#settings']['entity_id'])); |
|
980 |
$entity = entity_load($element['#settings']['entity_type'], array($entity_id)); |
|
981 |
$entity = $entity[$entity_id]; |
|
982 |
$uid1 = $entity->uid; |
|
983 |
$uid2 = $user->uid; |
|
984 |
return $entity->uid != $user->uid; |
|
985 |
} |
|
986 |
} |
drupal7/sites/all/modules/fivestar/includes/fivestar.field.inc | ||
---|---|---|
77 | 77 |
'#return_value' => 1, |
78 | 78 |
); |
79 | 79 |
|
80 |
$form['allow_revote'] = array( |
|
81 |
'#type' => 'checkbox', |
|
82 |
'#title' => t('Allow users to re-vote on already voted content.'), |
|
83 |
'#default_value' => isset($instance['settings']['allow_revote']) ? $instance['settings']['allow_revote'] : FALSE, |
|
84 |
'#return_value' => 1, |
|
85 |
); |
|
86 |
|
|
87 |
$form['allow_ownvote'] = array( |
|
88 |
'#type' => 'checkbox', |
|
89 |
'#title' => t('Allow users to vote on their own content.'), |
|
90 |
'#default_value' => isset($instance['settings']['allow_ownvote']) ? $instance['settings']['allow_ownvote'] : FALSE, |
|
91 |
'#return_value' => 1, |
|
92 |
); |
|
93 |
|
|
80 | 94 |
$options = fivestar_get_targets($field, $instance); |
81 | 95 |
$form['target'] = array( |
82 | 96 |
'#title' => t('Voting target'), |
... | ... | |
119 | 133 |
else { |
120 | 134 |
$rating = (isset($items[$delta]['rating'])) ? $items[$delta]['rating'] : 0; |
121 | 135 |
} |
122 |
$target = _fivestar_field_target($entity, $field, $instance, $item, $langcode); |
|
136 |
$target = _fivestar_field_target($entity, $field, $instance, $item, $langcode);
|
|
123 | 137 |
if (!empty($target)) { |
124 |
_fivestar_cast_vote($target['entity_type'], $target['entity_id'], $rating, $field['settings']['axis'], $entity->uid, TRUE); |
|
138 |
if ($entity_type == 'comment' && $op == 'delete') { |
|
139 |
$target['vote_source'] = $entity->hostname; |
|
140 |
} |
|
141 |
else { |
|
142 |
$target['vote_source'] = NULL; |
|
143 |
} |
|
144 |
_fivestar_cast_vote($target['entity_type'], $target['entity_id'], $rating, $field['settings']['axis'], $entity->uid, TRUE, $target['vote_source']); |
|
125 | 145 |
votingapi_recalculate_results($target['entity_type'], $target['entity_id']); |
126 | 146 |
} |
127 | 147 |
// The original callback is only called for a single updated field, but the Field API |
... | ... | |
291 | 311 |
$settings = array( |
292 | 312 |
'stars' => $instance['settings']['stars'], |
293 | 313 |
'allow_clear' => !empty($instance['settings']['allow_clear']) ? $instance['settings']['allow_clear'] : FALSE, |
314 |
'allow_revote' => !empty($instance['settings']['allow_revote']) ? $instance['settings']['allow_revote'] : FALSE, |
|
315 |
'allow_ownvote' => !empty($instance['settings']['allow_ownvote']) ? $instance['settings']['allow_ownvote'] : FALSE, |
|
294 | 316 |
'style' => 'user', |
295 | 317 |
'text' => 'none', |
296 | 318 |
'widget' => $widget, |
... | ... | |
301 | 323 |
'#title' => isset($instance['label']) ? (($i18n) ? i18n_field_translate_property($instance, 'label') : t($instance['label'])) : FALSE, |
302 | 324 |
'#stars' => isset($instance['settings']['stars']) ? $instance['settings']['stars'] : 5, |
303 | 325 |
'#allow_clear' => isset($instance['settings']['allow_clear']) ? $instance['settings']['allow_clear'] : FALSE, |
326 |
'#allow_revote' => isset($instance['settings']['allow_revote']) ? $instance['settings']['allow_revote'] : FALSE, |
|
327 |
'#allow_ownvote' => isset($instance['settings']['allow_ownvote']) ? $instance['settings']['allow_ownvote'] : FALSE, |
|
304 | 328 |
'#default_value' => isset($items[$delta]['rating']) ? $items[$delta]['rating'] : (isset($instance['default_value'][$delta]['rating']) ? $instance['default_value'][$delta]['rating'] : 0), |
305 | 329 |
'#widget' => $widget, |
306 | 330 |
'#settings' => $settings, |
... | ... | |
485 | 509 |
$settings = _fivestar_custom_widget_settings($entity_type, $instance, $display, $id, $tag, $widget); |
486 | 510 |
// Store entity and field data for later reuse. |
487 | 511 |
$settings += array( |
488 |
'entity' => $entity, |
|
512 |
'entity_id' => $id, |
|
513 |
'entity_type' => $entity_type, |
|
489 | 514 |
'field_name' => $instance['field_name'], |
490 | 515 |
'langcode' => $langcode, |
491 | 516 |
); |
... | ... | |
616 | 641 |
$settings = array( |
617 | 642 |
'stars' => (!empty($instance['settings']['stars'])) ? $instance['settings']['stars'] : 5, |
618 | 643 |
'allow_clear' => (!empty($instance['settings']['allow_clear'])) ? $instance['settings']['allow_clear'] : 0, |
644 |
'allow_revote' => (!empty($instance['settings']['allow_revote'])) ? $instance['settings']['allow_revote'] : 0, |
|
645 |
'allow_ownvote' => (!empty($instance['settings']['allow_ownvote'])) ? $instance['settings']['allow_ownvote'] : 0, |
|
619 | 646 |
'style' => $settings['style'], |
620 | 647 |
'text' => $settings['text'], |
621 | 648 |
'content_type' => $entity_type, |
... | ... | |
685 | 712 |
*/ |
686 | 713 |
function fivestar_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) { |
687 | 714 |
// TODO: Clean this function up! |
715 |
$exposed_widgets = array(); |
|
688 | 716 |
foreach ($entities as $id => $entity) { |
689 | 717 |
// Ensure the items aren't processed twice. |
690 | 718 |
if (!isset($items[$id][0]['count'])) { |
691 |
// Populating the $items[$id] array even for items with no value forces |
|
692 |
// the render system to output a widget. |
|
693 | 719 |
if ($instances[$id]['widget']['type'] == 'exposed') { |
694 |
// If the widget type is exposed then we want to look up the voting api |
|
695 |
// values. |
|
696 |
$tag = $field['settings']['axis']; |
|
697 |
$votes = fivestar_get_votes($entity_type, $id, $tag); |
|
698 |
$values['user'] = isset($votes['user']['value']) ? $votes['user']['value'] : 0; |
|
699 |
$values['average'] = isset($votes['average']['value']) ? $votes['average']['value'] : 0; |
|
700 |
$values['count'] = isset($votes['count']['value']) ? $votes['count']['value'] : 0; |
|
701 |
$items[$id] = array($values); |
|
720 |
$exposed_widgets[] = $id; |
|
702 | 721 |
} |
703 | 722 |
else { |
704 | 723 |
// If the widget type is not exposed, then the count is always 1 or 0. |
... | ... | |
716 | 735 |
$items[$id] = array($values); |
717 | 736 |
} |
718 | 737 |
} |
738 |
if(!empty($exposed_widgets)) { |
|
739 |
$votes = fivestar_get_votes_multiple($entity_type, $exposed_widgets, $field['settings']['axis']); |
|
740 |
foreach($votes[$entity_type] as $id => $vote) { |
|
741 |
// Populating the $items[$id] array even for items with no value forces |
|
742 |
// the render system to output a widget. |
|
743 |
$values['user'] = isset($vote['user']['value']) ? $vote['user']['value'] : 0; |
|
744 |
$values['average'] = isset($vote['average']['value']) ? $vote['average']['value'] : 0; |
|
745 |
$values['count'] = isset($vote['count']['value']) ? $vote['count']['value'] : 0; |
|
746 |
$items[$id] = array($values); |
|
747 |
} |
|
748 |
} |
|
719 | 749 |
} |
720 | 750 |
} |
721 | 751 |
|
... | ... | |
744 | 774 |
'type' => 'text', |
745 | 775 |
'microdata' => TRUE, |
746 | 776 |
), |
777 |
'rating_count' => array( |
|
778 |
'label' => t('Rating count'), |
|
779 |
'type' => 'text', |
|
780 |
'microdata' => TRUE, |
|
781 |
), |
|
747 | 782 |
); |
748 | 783 |
} |
749 | 784 |
|
drupal7/sites/all/modules/fivestar/includes/fivestar.theme.inc | ||
---|---|---|
30 | 30 |
'#stars' => 5, |
31 | 31 |
'#auto_submit' => FALSE, |
32 | 32 |
'#allow_clear' => TRUE, |
33 |
'#allow_revote' => TRUE, |
|
34 |
'#allow_ownvote' => TRUE, |
|
33 | 35 |
'#widget' => array( |
34 | 36 |
'name' => isset($variables['name']) ? $variables['name'] : 'default', |
35 | 37 |
'css' => isset($variables['css']) && $variables['css'] != 'default' ? $variables['css'] : FALSE, |
... | ... | |
67 | 69 |
$settings = array( |
68 | 70 |
'stars' => $stars, |
69 | 71 |
'allow_clear' => $unvote, |
72 |
'allow_revote' => $revote, |
|
73 |
'allow_ownvote' => $ownvote, |
|
70 | 74 |
'style' => $style, |
71 | 75 |
'text' => $text, |
72 | 76 |
'title' => $title, |
... | ... | |
247 | 251 |
$output = ''; |
248 | 252 |
$div_class = ''; |
249 | 253 |
$average_rating_microdata = ''; |
254 |
$rating_count_microdata = ''; |
|
250 | 255 |
if (isset($user_rating)) { |
251 | 256 |
$div_class = isset($votes) ? 'user-count' : 'user'; |
252 | 257 |
$user_stars = round(($user_rating * $stars) / 100, 1); |
... | ... | |
256 | 261 |
$output .= ' '; |
257 | 262 |
} |
258 | 263 |
if (isset($average_rating)) { |
259 |
$div_class = isset($votes) ? 'average-count' : 'average'; |
|
264 |
if (isset($user_rating)) { |
|
265 |
$div_class = 'combo'; |
|
266 |
} |
|
267 |
else { |
|
268 |
$div_class = isset($votes) ? 'average-count' : 'average'; |
|
269 |
} |
|
270 |
|
|
260 | 271 |
$average_stars = round(($average_rating * $stars) / 100, 1); |
261 | 272 |
if (!empty($microdata['average_rating']['#attributes'])) { |
262 | 273 |
$average_rating_microdata = drupal_attributes($microdata['average_rating']['#attributes']); |
... | ... | |
264 | 275 |
$output .= '<span class="average-rating">' . t('Average: !stars', |
265 | 276 |
array('!stars' => "<span $average_rating_microdata>$average_stars</span>")) . '</span>'; |
266 | 277 |
} |
267 |
if (isset($user_rating) && isset($average_rating)) { |
|
268 |
$div_class = 'combo'; |
|
269 |
} |
|
270 | 278 |
|
271 |
if (isset($votes) && !(isset($user_rating) || isset($average_rating))) { |
|
272 |
$output .= ' <span class="total-votes">' . format_plural($votes, '<span>@count</span> vote', '<span>@count</span> votes') . '</span>'; |
|
273 |
$div_class = 'count'; |
|
274 |
} |
|
275 |
elseif (isset($votes)) { |
|
276 |
$output .= ' <span class="total-votes">(' . format_plural($votes, '<span>@count</span> vote', '<span>@count</span> votes') . ')</span>'; |
|
279 |
if (isset($votes)) { |
|
280 |
if (!isset($user_rating) && !isset($average_rating)) { |
|
281 |
$div_class = 'count'; |
|
282 |
} |
|
283 |
if ($votes === 0) { |
|
284 |
$output = '<span class="empty">'. t('No votes yet') .'</span>'; |
|
285 |
} |
|
286 |
else { |
|
287 |
if (!empty($microdata['rating_count']['#attributes'])) { |
|
288 |
$rating_count_microdata = drupal_attributes($microdata['rating_count']['#attributes']); |
|
289 |
} |
|
290 |
// We don't directly substitute $votes (i.e. use '@count') in format_plural, |
|
291 |
// because it has a span around it which is not translatable. |
|
292 |
$votes_str = format_plural($votes, '!cnt vote', '!cnt votes', array( |
|
293 |
'!cnt' => '<span ' . $rating_count_microdata . '>' . intval($votes) . '</span>')); |
|
294 |
if (isset($user_rating) || isset($average_rating)) { |
|
295 |
$output .= ' <span class="total-votes">(' . $votes_str . ')</span>'; |
|
296 |
} |
|
297 |
else { |
|
298 |
$output .= ' <span class="total-votes">' . $votes_str . '</span>'; |
|
299 |
} |
|
300 |
} |
|
277 | 301 |
} |
278 | 302 |
|
279 |
if ($votes === 0) { |
|
280 |
$output = '<span class="empty">' . t('No votes yet') . '</span>'; |
|
281 |
} |
|
282 | 303 |
|
283 | 304 |
$output = '<div class="fivestar-summary fivestar-summary-' . $div_class . '">' . $output . '</div>'; |
284 | 305 |
return $output; |
drupal7/sites/all/modules/fivestar/js/fivestar.js | ||
---|---|---|
54 | 54 |
|
55 | 55 |
// Attach the new widget and hide the existing widget. |
56 | 56 |
$select.after($container).css('display', 'none'); |
57 |
|
|
58 |
// Allow other modules to modify the widget. |
|
59 |
Drupal.attachBehaviors($this); |
|
57 | 60 |
}); |
58 | 61 |
}, |
59 | 62 |
rate: function(event) { |
drupal7/sites/all/modules/fivestar/test/fivestar.field.test | ||
---|---|---|
21 | 21 |
$this->drupalLogin($this->admin_user); |
22 | 22 |
// Add an author-rated fivestar field to the test_node_type content type. |
23 | 23 |
$this->createFivestarField(array('widget_type' => 'stars')); |
24 |
// Load the instance settings so we can set allow_ownvote. |
|
25 |
$instance = field_read_instance('node', 'fivestar_test', 'test_node_type'); |
|
26 |
$instance['settings']['allow_ownvote'] = 1; |
|
27 |
field_update_instance($instance); |
|
24 | 28 |
// Save an test_node_typee node with a two-star rating. |
25 | 29 |
$edit = array( |
26 | 30 |
'title' => $this->randomString(), |
... | ... | |
52 | 56 |
// Load the instance settings so we can change certain settings. |
53 | 57 |
$instance = field_read_instance('node', 'fivestar_test', 'test_node_type'); |
54 | 58 |
|
59 |
// Lets see if visitors is able to re-vote. |
|
60 |
// §see http://drupal.org/node/356605 |
|
61 |
$instance['settings']['allow_revote'] = 1; |
|
62 |
field_update_instance($instance); |
|
63 |
$this->drupalGet('node/' . $node->nid); |
|
64 |
$result = $this->xpath("//div[contains(@class, 'field-name-fivestar-test')]//select[contains(@name,'vote')]"); |
|
65 |
$this->assertEqual(count($result), TRUE, 'Visitors can re-vote'); |
|
66 |
|
|
55 | 67 |
// Lets test to make sure the cancel option is not available if disabled. |
56 | 68 |
// @see http://drupal.org/node/1269276 |
57 | 69 |
$this->assertNoRaw(t('Cancel rating'), 'User cannot cancel his vote.'); |
drupal7/sites/all/modules/masquerade/masquerade.info | ||
---|---|---|
4 | 4 |
files[] = masquerade.test |
5 | 5 |
configure = admin/config/people/masquerade |
6 | 6 |
|
7 |
; Information added by drupal.org packaging script on 2012-11-01
|
|
8 |
version = "7.x-1.0-rc5"
|
|
7 |
; Information added by Drupal.org packaging script on 2014-03-05
|
|
8 |
version = "7.x-1.0-rc6"
|
|
9 | 9 |
core = "7.x" |
10 | 10 |
project = "masquerade" |
11 |
datestamp = "1351786623"
|
|
11 |
datestamp = "1393981725"
|
|
12 | 12 |
|
drupal7/sites/all/modules/masquerade/masquerade.install | ||
---|---|---|
177 | 177 |
function masquerade_update_7001() { |
178 | 178 |
db_update('block') |
179 | 179 |
->fields(array('cache' => DRUPAL_NO_CACHE)) |
180 |
->condition('module', 'masqurade') |
|
180 |
->condition('module', 'masquerade')
|
|
181 | 181 |
->condition('delta', 'masquerade') |
182 | 182 |
->execute(); |
183 | 183 |
} |
drupal7/sites/all/modules/masquerade/masquerade.module | ||
---|---|---|
370 | 370 |
} |
371 | 371 |
} |
372 | 372 |
|
373 |
/** |
|
374 |
* Implements hook_field_extra_fields(). |
|
375 |
*/ |
|
376 |
function masquerade_field_extra_fields() { |
|
377 |
$return['user']['user'] = array( |
|
378 |
'form' => array( |
|
379 |
'masquerade' => array( |
|
380 |
'label' => t('Masquerade'), |
|
381 |
'description' => t('User masquerade settings.'), |
|
382 |
'weight' => 50, |
|
383 |
), |
|
384 |
), |
|
385 |
'display' => array( |
|
386 |
'masquerade' => array( |
|
387 |
'label' => t('Masquerade'), |
|
388 |
'description' => t('Masquerade as user link.'), |
|
389 |
'weight' => 50, |
|
390 |
), |
|
391 |
), |
|
392 |
); |
|
393 |
|
|
394 |
return $return; |
|
395 |
} |
|
396 |
|
|
373 | 397 |
/** |
374 | 398 |
* Implements hook_user_view(). |
375 | 399 |
*/ |
... | ... | |
382 | 406 |
|
383 | 407 |
global $user; |
384 | 408 |
|
385 |
if (user_access($perm) && empty($account->masquerading) && $user->uid != $account->uid) { |
|
409 |
// Query allowed uids so the "masquerade as <user>" link can be shown or |
|
410 |
// hidden. |
|
411 |
$allowed_uids = db_query("SELECT uid_to FROM {masquerade_users} WHERE uid_from = :uid_from", array(':uid_from' => $user->uid)) |
|
412 |
->fetchCol(); |
|
413 |
|
|
414 |
if (user_access($perm) && empty($account->masquerading) && $user->uid != $account->uid && in_array($account->uid, $allowed_uids)) { |
|
386 | 415 |
$account->content['masquerade'] = array( |
387 | 416 |
'#markup' => l(t('Masquerade as !user', array('!user' => $account->name)), |
388 | 417 |
'masquerade/switch/' . $account->uid, |
389 | 418 |
array('query' => array( |
390 | 419 |
'token' => drupal_get_token('masquerade/switch/' . $account->uid)), |
391 | 420 |
'destination' => $_GET['q'], |
392 |
'attributes' => array('class' => 'masquerade-switch'),
|
|
421 |
'attributes' => array('class' => array('masquerade-switch')),
|
|
393 | 422 |
)), |
394 | 423 |
'#weight' => 10, |
395 | 424 |
); |
... | ... | |
616 | 645 |
global $user; |
617 | 646 |
//unset($form); |
618 | 647 |
$name = $form_state['values']['masquerade_user_field']; |
648 |
$allowed = FALSE; |
|
649 |
$to_uid = db_select('users', 'u') |
|
650 |
->fields('u', array('uid')) |
|
651 |
->condition('u.name', $name, '=') |
|
652 |
->execute() |
|
653 |
->fetchField(); |
|
654 |
if ($to_uid !== FALSE) { |
|
655 |
$allowed = db_select('masquerade_users', 'm') |
|
656 |
->fields('m', array('uid_to')) |
|
657 |
->condition('m.uid_to', $to_uid, '=') |
|
658 |
->condition('m.uid_from', $user->uid, '=') |
|
659 |
->execute() |
|
660 |
->fetchField(); |
|
661 |
} |
|
619 | 662 |
if (isset($_SESSION['masquerading'])) { |
620 | 663 |
form_set_error('masquerade_user_field', t('You are already masquerading. Please <a href="@unswitch">switch back</a> to your account to masquerade as another user.', array('@unswitch' => url('masquerade/unswitch', array('query' => array('token' => drupal_get_token('masquerade/unswitch'))))))); |
621 | 664 |
} |
665 |
if ($allowed === FALSE) { |
|
666 |
form_set_error('masquerade_user_field', t('You are not allowed to masquerade as the selected user.')); |
|
667 |
} |
|
668 |
|
|
622 | 669 |
if ($name != variable_get('anonymous', t('Anonymous')) && module_exists('alt_login')) { |
623 | 670 |
$alt_login = db_query("SELECT u.name FROM {users} u INNER JOIN {alt_login} al ON u.uid = al.uid WHERE al.alt_login = :alt_login", array( |
624 | 671 |
':alt_login' => $name |
625 | 672 |
))->fetchObject(); |
626 |
if ($alt_login->name) {
|
|
673 |
if (isset($alt_login->name)) {
|
|
627 | 674 |
$name = $alt_login->name; |
628 | 675 |
} |
629 | 676 |
} |
... | ... | |
840 | 887 |
':uid_as' => $user->uid, |
841 | 888 |
))->fetchField(); |
842 | 889 |
// erase record |
843 |
$conditions = db_or(); |
|
844 |
$conditions->condition('sid', session_id()); |
|
845 |
$conditions->condition('uid_as', $user->uid); |
|
846 |
$query = db_delete('masquerade'); |
|
847 |
$query->condition($conditions); |
|
848 |
$query->execute(); |
|
890 |
db_delete('masquerade') |
|
891 |
->condition('sid', session_id()) |
|
892 |
->condition('uid_as', $user->uid) |
|
893 |
->execute(); |
|
894 |
|
|
849 | 895 |
$oldname = ($user->uid == 0 ? variable_get('anonymous', t('Anonymous')) : $user->name); |
850 | 896 |
|
851 | 897 |
// Call logout hooks when switching from masquerading user. |
Formats disponibles : Unified diff
Weekly update of contrib modules