Révision d50a36e0
Ajouté par Assos Assos il y a presque 4 ans
drupal7/sites/all/modules/fivestar/fivestar.module | ||
---|---|---|
8 | 8 |
include_once dirname(__FILE__) . '/includes/fivestar.field.inc'; |
9 | 9 |
|
10 | 10 |
/** |
11 |
* Implementation of hook_help().
|
|
11 |
* Implements hook_help().
|
|
12 | 12 |
*/ |
13 | 13 |
function fivestar_help($path, $arg) { |
14 |
$output = ''; |
|
15 | 14 |
switch ($path) { |
15 |
|
|
16 | 16 |
case 'admin/config/content/fivestar': |
17 | 17 |
$output = t('This page is used to configure site-wide features of the Fivestar module.'); |
18 |
break; |
|
18 |
return $output; |
|
19 |
|
|
20 |
case 'admin/help#fivestar': |
|
21 |
$output = ''; |
|
22 |
$output .= '<h3>' . t('About') . '</h3>'; |
|
23 |
$output .= '<p>' . t('The <a href="@fivestar">Fivestar</a> voting module is a very simple rating module that provides the possibility to rate items with stars or similar items. This gives you the possibilities to rate various items or even to create online forms for evaluations and assessments with different questions to be answered. |
|
24 |
For more information, see the online documentation for the <a href="@doco">Fivestar module</a>.', |
|
25 |
array( |
|
26 |
'@fivestar' => 'http://drupal.org/project/fivestar', |
|
27 |
'@doco' => 'https://drupal.org/handbook/modules/fivestar', |
|
28 |
)) . '</p>'; |
|
29 |
$output .= '<h3>' . t('Uses') . '</h3>'; |
|
30 |
$output .= '<dl>'; |
|
31 |
$output .= '<dt>' . t('General') . '</dt>'; |
|
32 |
$output .= '<dd>' . t('The Fivestar module can be used to easily rate various types of content on your website. These ratings can be used on the content itself or even from the comments of that piece of content.') . '</dd>'; |
|
33 |
$output .= '<dt>' . t('Basic Concepts and Features') . '</dt>'; |
|
34 |
$output .= '<dd>' . t('Fivestar is an excellent voting widget first made available for use on Drupal 5 websites. The D5 module included the ability to create a voting widget for nodes. With Drupal 6 came the ability to add comments. And with Drupal 7, the web developer was given the ability to create the voting widget with any entity.') . '</dd>'; |
|
35 |
$output .= '<dt>' . t('Advanced Use Cases') . '</dt>'; |
|
36 |
$output .= '<dd>' . t('There are many excellent resources online describing the many Fivestar features, such as the excellent article <a href="@features">"In-Depth features of Drupal Fivestar" </a>.', |
|
37 |
array( |
|
38 |
'@features' => 'https://www.greengeeks.com/kb/3233/drupal-fivestar/', |
|
39 |
)) . '</dd>'; |
|
40 |
$output .= '</dl>'; |
|
41 |
return $output; |
|
19 | 42 |
} |
20 |
return $output; |
|
21 | 43 |
} |
22 | 44 |
|
23 | 45 |
/** |
24 |
* Implementation of hook_menu().
|
|
46 |
* Implements hook_menu().
|
|
25 | 47 |
*/ |
26 | 48 |
function fivestar_menu() { |
27 | 49 |
$items = array(); |
... | ... | |
45 | 67 |
function fivestar_microdata_suggestions() { |
46 | 68 |
$mappings = array(); |
47 | 69 |
|
48 |
// Add the review mapping for Schema.org |
|
70 |
// Add the review mapping for Schema.org.
|
|
49 | 71 |
$mappings['fields']['fivestar']['schema.org'] = array( |
50 | 72 |
'#itemprop' => array('aggregateRating'), |
51 | 73 |
'#is_item' => TRUE, |
... | ... | |
62 | 84 |
} |
63 | 85 |
|
64 | 86 |
/** |
65 |
* Implementation of hook_permission().
|
|
87 |
* Implements hook_permission().
|
|
66 | 88 |
* |
67 | 89 |
* Exposes permissions for rating content. |
68 | 90 |
*/ |
... | ... | |
75 | 97 |
} |
76 | 98 |
|
77 | 99 |
/** |
78 |
* Implementation of hook_theme().
|
|
100 |
* Implements hook_theme().
|
|
79 | 101 |
*/ |
80 | 102 |
function fivestar_theme() { |
81 | 103 |
return array( |
... | ... | |
136 | 158 |
); |
137 | 159 |
} |
138 | 160 |
|
161 |
/** |
|
162 |
* Implements hook_views_api(). |
|
163 |
*/ |
|
164 |
function fivestar_views_api() { |
|
165 |
return array( |
|
166 |
'api' => 3, |
|
167 |
'path' => drupal_get_path('module', 'fivestar') . '/includes', |
|
168 |
); |
|
169 |
} |
|
170 |
|
|
171 |
/** |
|
172 |
* |
|
173 |
*/ |
|
139 | 174 |
function _fivestar_variables() { |
140 | 175 |
return array('fivestar', 'fivestar_unvote', 'fivestar_style', 'fivestar_stars', 'fivestar_comment', 'fivestar_position', 'fivestar_position_teaser', 'fivestar_labels_enable', 'fivestar_labels', 'fivestar_text', 'fivestar_title', 'fivestar_feedback'); |
141 | 176 |
} |
... | ... | |
144 | 179 |
* Internal function to handle vote casting, flood control, XSS, IP based |
145 | 180 |
* voting, etc... |
146 | 181 |
*/ |
147 |
|
|
148 | 182 |
function _fivestar_cast_vote($entity_type, $id, $value, $tag = NULL, $uid = NULL, $skip_validation = FALSE, $vote_source = NULL) { |
149 | 183 |
global $user; |
150 | 184 |
$tag = empty($tag) ? 'vote' : $tag; |
... | ... | |
162 | 196 |
// Get the user's current vote. |
163 | 197 |
$criteria = array('entity_type' => $entity_type, 'entity_id' => $id, 'tag' => $tag, 'uid' => $uid); |
164 | 198 |
// Get the unique identifier for the user (IP Address if anonymous). |
165 |
|
|
166 | 199 |
if ($vote_source != NULL) { |
167 | 200 |
$user_criteria = array('vote_source' => $vote_source); |
168 | 201 |
$limit = 1; |
... | ... | |
181 | 214 |
votingapi_set_votes($votes); |
182 | 215 |
} |
183 | 216 |
|
184 |
// Moving the calculationg after saving/deleting the vote but before getting the votes. |
|
217 |
// Moving the calculation after saving/deleting the vote but before |
|
218 |
// getting the votes. |
|
185 | 219 |
votingapi_recalculate_results($entity_type, $id); |
186 | 220 |
return fivestar_get_votes($entity_type, $id, $tag, $uid); |
187 | 221 |
} |
... | ... | |
202 | 236 |
* The VotingAPI tag for which to retrieve votes. |
203 | 237 |
* @param $uid |
204 | 238 |
* Optional. A user ID for which to retrieve votes. |
239 |
* |
|
205 | 240 |
* @return |
206 | 241 |
* An array of the following keys: |
207 | 242 |
* - average: An array of VotingAPI results, including the average 'value'. |
... | ... | |
225 | 260 |
$votes = array(); |
226 | 261 |
|
227 | 262 |
// Initialize defaults. |
228 |
foreach($ids as $id) { |
|
263 |
foreach ($ids as $id) {
|
|
229 | 264 |
$votes[$entity_type][$id] = array( |
230 | 265 |
'average' => array(), |
231 | 266 |
'count' => array(), |
... | ... | |
235 | 270 |
|
236 | 271 |
$results = votingapi_select_results($criteria); |
237 | 272 |
$user_votes = array(); |
238 |
if(!empty($results)) { |
|
239 |
foreach(votingapi_select_votes($criteria += array('uid' => $uid)) as $uv) { |
|
273 |
if (!empty($results)) {
|
|
274 |
foreach (votingapi_select_votes($criteria += array('uid' => $uid)) as $uv) {
|
|
240 | 275 |
$user_votes[$uv['entity_type']][$uv['entity_id']] = $uv; |
241 | 276 |
} |
242 | 277 |
} |
... | ... | |
248 | 283 |
if ($result['function'] == 'count') { |
249 | 284 |
$votes[$result['entity_type']][$result['entity_id']]['count'] = $result; |
250 | 285 |
} |
251 |
if ($uid) {
|
|
252 |
if (!empty($user_votes[$result['entity_type']][$result['entity_id']])) {
|
|
286 |
if ($uid) {
|
|
287 |
if (!empty($user_votes[$result['entity_type']][$result['entity_id']])) {
|
|
253 | 288 |
$votes[$result['entity_type']][$result['entity_id']]['user'] = $user_votes[$result['entity_type']][$result['entity_id']]; |
254 | 289 |
$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.
|
|
290 |
}
|
|
291 |
}
|
|
292 |
else {
|
|
293 |
// If the user is anonymous, we never bother loading their existing votes.
|
|
294 |
// Not only would it be hit-or-miss, it would break page caching. Safer to
|
|
295 |
// always show the 'fresh' version to anon users.
|
|
261 | 296 |
$votes[$result['entity_type']][$result['entity_id']]['user'] = array('value' => 0); |
262 |
}
|
|
297 |
}
|
|
263 | 298 |
} |
264 | 299 |
|
265 | 300 |
return $votes; |
266 | 301 |
} |
267 | 302 |
|
303 |
/** |
|
304 |
* |
|
305 |
*/ |
|
268 | 306 |
function fivestar_get_votes($entity_type, $id, $tag = 'vote', $uid = NULL) { |
269 | 307 |
$multiple = fivestar_get_votes_multiple($entity_type, array($id), $tag, $uid); |
270 | 308 |
return $multiple[$entity_type][$id]; |
... | ... | |
282 | 320 |
* @param $uid |
283 | 321 |
* The user trying to cast the vote. |
284 | 322 |
* |
285 |
* @return boolean
|
|
323 |
* @return bool |
|
286 | 324 |
*/ |
287 | 325 |
function fivestar_validate_target($entity_type, $id, $tag, $uid = NULL) { |
288 | 326 |
if (!isset($uid)) { |
... | ... | |
301 | 339 |
} |
302 | 340 |
|
303 | 341 |
/** |
304 |
* Implementation of hook_fivestar_access().
|
|
342 |
* Implements hook_fivestar_access().
|
|
305 | 343 |
* |
306 | 344 |
* This hook is called before every vote is cast through Fivestar. It allows |
307 | 345 |
* modules to allow voting on any type of entity, such as nodes, users, or |
... | ... | |
316 | 354 |
* @param $uid |
317 | 355 |
* The user ID trying to cast the vote. |
318 | 356 |
* |
319 |
* @return boolean or NULL
|
|
357 |
* @return bool|NULL
|
|
320 | 358 |
* Returns TRUE if voting is supported on this object. |
321 | 359 |
* Returns NULL if voting is not supported on this object by this module. |
322 | 360 |
* If needing to absolutely deny all voting on this object, regardless |
... | ... | |
341 | 379 |
} |
342 | 380 |
|
343 | 381 |
/** |
344 |
* Implementation of hook_form_comment_form_alter().
|
|
382 |
* Implements hook_form_comment_form_alter().
|
|
345 | 383 |
* |
346 | 384 |
* This hook removes the parent node, together with the fivestar field, from |
347 | 385 |
* the comment preview page. If this is left in, when the user presses the |
... | ... | |
352 | 390 |
function fivestar_form_comment_form_alter(&$form, &$form_state, $form_id) { |
353 | 391 |
$fivestar_field_keys = array(); |
354 | 392 |
if (isset($form['comment_output_below'])) { |
355 |
foreach($form['comment_output_below'] as $key => $value) { |
|
393 |
foreach ($form['comment_output_below'] as $key => $value) {
|
|
356 | 394 |
if (is_array($value) && !empty($value['#field_type']) && $value['#field_type'] == 'fivestar') { |
357 | 395 |
$fivestar_field_keys[] = $key; |
358 | 396 |
} |
... | ... | |
366 | 404 |
} |
367 | 405 |
|
368 | 406 |
/** |
369 |
* Implementation of hook_fivestar_widgets().
|
|
407 |
* Implements hook_fivestar_widgets().
|
|
370 | 408 |
* |
371 | 409 |
* This hook allows other modules to create additional custom widgets for |
372 | 410 |
* the fivestar module. |
... | ... | |
432 | 470 |
function fivestar_custom_widget($form, &$form_state, $values, $settings) { |
433 | 471 |
$form = array( |
434 | 472 |
'#attributes' => array( |
435 |
'class' => array('fivestar-widget') |
|
473 |
'class' => array('fivestar-widget'),
|
|
436 | 474 |
), |
437 | 475 |
); |
438 | 476 |
$form['#submit'][] = 'fivestar_form_submit'; |
... | ... | |
500 | 538 |
} |
501 | 539 |
|
502 | 540 |
/** |
503 |
* AJAX submit handler for fivestar_custom_widget |
|
541 |
* AJAX submit handler for fivestar_custom_widget.
|
|
504 | 542 |
*/ |
505 | 543 |
function fivestar_ajax_submit($form, $form_state) { |
506 | 544 |
if (!empty($form_state['settings']['content_id'])) { |
507 | 545 |
$entity = entity_load($form_state['settings']['entity_type'], array($form_state['settings']['entity_id'])); |
508 | 546 |
$entity = reset($entity); |
509 | 547 |
_fivestar_update_field_value($form_state['settings']['content_type'], $entity, $form_state['settings']['field_name'], $form_state['settings']['langcode'], $form_state['values']['vote']); |
510 |
$votes = _fivestar_cast_vote($form_state['settings']['content_type'], $form_state['settings']['content_id'], $form_state['values']['vote'], $form_state['settings']['tag']);
|
|
548 |
$votes = _fivestar_cast_vote($form_state['settings']['entity_type'], $form_state['settings']['content_id'], $form_state['values']['vote'], $form_state['settings']['tag']);
|
|
511 | 549 |
} |
512 | 550 |
|
513 | 551 |
$values = array(); |
... | ... | |
517 | 555 |
|
518 | 556 |
// We need to process the 'fivestar' element with the new values. |
519 | 557 |
$form['vote']['#values'] = $values; |
520 |
// Also need to pass on form_state and the complete form, just like form_builder() does. |
|
558 |
// Also need to pass on form_state and the complete form, |
|
559 |
// just like form_builder() does. |
|
521 | 560 |
$new_element = fivestar_expand($form['vote'], $form_state, $form_state['complete form']); |
522 | 561 |
// Update the description. Since it doesn't account of our cast vote above. |
523 |
// TODO: Look into all this, I honestly don't like it and it's a bit weird.
|
|
562 |
// @todo Look into all this, I honestly don't like it and it's a bit weird.
|
|
524 | 563 |
$form['vote']['vote']['#description'] = isset($new_element['vote']['#description']) ? $new_element['vote']['#description'] : ''; |
525 |
|
|
564 |
if (!$form['vote']['#allow_revote'] && !$form['vote']['#allow_clear']) { |
|
565 |
$form['vote'] = $new_element; |
|
566 |
} |
|
526 | 567 |
return array( |
527 | 568 |
'#type' => 'ajax', |
528 | 569 |
'#commands' => array( |
... | ... | |
535 | 576 |
} |
536 | 577 |
|
537 | 578 |
/** |
538 |
* Implementation of hook_elements().
|
|
579 |
* Implements hook_elements().
|
|
539 | 580 |
* |
540 |
* Defines 'fivestar' form element type |
|
581 |
* Defines 'fivestar' form element type.
|
|
541 | 582 |
*/ |
542 | 583 |
function fivestar_element_info() { |
543 | 584 |
$type['fivestar'] = array( |
... | ... | |
570 | 611 |
* Process callback for fivestar_element -- see fivestar_element() |
571 | 612 |
*/ |
572 | 613 |
function fivestar_expand($element, $form_state, $complete_form) { |
573 |
if (!_fivestar_allow_vote($element)){ |
|
614 |
if (!_fivestar_allow_vote($element)) {
|
|
574 | 615 |
$element['#input'] = FALSE; |
575 | 616 |
} |
576 | 617 |
|
577 |
// Add CSS and JS |
|
618 |
// Add CSS and JS.
|
|
578 | 619 |
$path = drupal_get_path('module', 'fivestar'); |
579 | 620 |
$element['#attached']['js'][] = $path . '/js/fivestar.js'; |
580 | 621 |
$element['#attached']['css'][] = $path . '/css/fivestar.css'; |
... | ... | |
582 | 623 |
$values = $element['#values']; |
583 | 624 |
$class[] = 'clearfix'; |
584 | 625 |
|
585 |
$title = 'it';
|
|
626 |
$title = t('it');
|
|
586 | 627 |
if (isset($element['#settings']['entity_id']) && isset($element['#settings']['entity_type'])) { |
587 | 628 |
$entity_id = $element['#settings']['entity_id']; |
588 | 629 |
$entity = entity_load($element['#settings']['entity_type'], array($entity_id)); |
589 | 630 |
$entity = $entity[$entity_id]; |
590 |
$title = $entity->title; |
|
591 |
} elseif (isset($complete_form['#node'])) { |
|
631 |
if (isset($entity->title)) { |
|
632 |
$title = $entity->title; |
|
633 |
} |
|
634 |
} |
|
635 |
elseif (isset($complete_form['#node'])) { |
|
592 | 636 |
$title = $complete_form['#node']->title; |
593 | 637 |
} |
594 | 638 |
$options = array('-' => t('Select rating')); |
595 | 639 |
for ($i = 1; $i <= $element['#stars']; $i++) { |
596 |
$this_value = ceil($i * 100/$element['#stars']);
|
|
640 |
$this_value = ceil($i * 100 / $element['#stars']);
|
|
597 | 641 |
$options[$this_value] = t('Give @title @star/@count', array('@title' => $title, '@star' => $i, '@count' => $element['#stars'])); |
598 | 642 |
} |
599 | 643 |
// Display clear button only if enabled. |
... | ... | |
625 | 669 |
)); |
626 | 670 |
$class[] = 'fivestar-user-text'; |
627 | 671 |
break; |
672 |
|
|
628 | 673 |
case 'average': |
629 | 674 |
$element['vote']['#description'] = $settings['style'] == 'dual' ? NULL : theme('fivestar_summary', array( |
630 | 675 |
'average_rating' => $values['average'], |
... | ... | |
634 | 679 |
)); |
635 | 680 |
$class[] = 'fivestar-average-text'; |
636 | 681 |
break; |
682 |
|
|
637 | 683 |
case 'smart': |
638 | 684 |
$element['vote']['#description'] = ($settings['style'] == 'dual' && !$values['user']) ? NULL : theme('fivestar_summary', array( |
639 | 685 |
'user_rating' => $values['user'], |
... | ... | |
645 | 691 |
$class[] = 'fivestar-smart-text'; |
646 | 692 |
$class[] = $values['user'] ? 'fivestar-user-text' : 'fivestar-average-text'; |
647 | 693 |
break; |
694 |
|
|
648 | 695 |
case 'dual': |
649 | 696 |
$element['vote']['#description'] = theme('fivestar_summary', array( |
650 | 697 |
'user_rating' => $values['user'], |
... | ... | |
655 | 702 |
)); |
656 | 703 |
$class[] = ' fivestar-combo-text'; |
657 | 704 |
break; |
705 |
|
|
658 | 706 |
case 'none': |
659 | 707 |
$element['vote']['#description'] = NULL; |
660 | 708 |
break; |
... | ... | |
664 | 712 |
case 'average': |
665 | 713 |
$class[] = 'fivestar-average-stars'; |
666 | 714 |
break; |
715 |
|
|
667 | 716 |
case 'user': |
668 | 717 |
$class[] = 'fivestar-user-stars'; |
669 | 718 |
break; |
719 |
|
|
670 | 720 |
case 'smart': |
671 | 721 |
$class[] = 'fivestar-smart-stars ' . ($values['user'] ? 'fivestar-user-stars' : 'fivestar-average-stars'); |
672 | 722 |
break; |
723 |
|
|
673 | 724 |
case 'dual': |
674 | 725 |
$class[] = 'fivestar-combo-stars'; |
675 | 726 |
$static_average = theme('fivestar_static', array( |
... | ... | |
744 | 795 |
* |
745 | 796 |
* @param $element |
746 | 797 |
* The fivestar element |
798 |
* |
|
747 | 799 |
* @return |
748 | 800 |
* The default value for the element. |
749 | 801 |
*/ |
... | ... | |
756 | 808 |
case 'average': |
757 | 809 |
$default_value = $element['#values']['average']; |
758 | 810 |
break; |
811 |
|
|
759 | 812 |
case 'user': |
760 | 813 |
$default_value = $element['#values']['user']; |
761 | 814 |
break; |
815 |
|
|
762 | 816 |
case 'smart': |
763 | 817 |
$default_value = (!empty($element['#values']['user']) ? $element['#values']['user'] : $element['#values']['average']); |
764 | 818 |
break; |
819 |
|
|
765 | 820 |
case 'dual': |
766 | 821 |
$default_value = $element['#values']['user']; |
767 | 822 |
break; |
823 |
|
|
768 | 824 |
default: |
769 | 825 |
$default_value = $element['#values']['average']; |
770 | 826 |
} |
771 | 827 |
} |
772 | 828 |
|
773 | 829 |
for ($i = 0; $i <= $element['#stars']; $i++) { |
774 |
$this_value = ceil($i * 100/$element['#stars']);
|
|
775 |
$next_value = ceil(($i+1) * 100/$element['#stars']);
|
|
830 |
$this_value = ceil($i * 100 / $element['#stars']);
|
|
831 |
$next_value = ceil(($i + 1) * 100 / $element['#stars']);
|
|
776 | 832 |
|
777 | 833 |
// Round up the default value to the next exact star value if needed. |
778 | 834 |
if ($this_value < $default_value && $next_value > $default_value) { |
... | ... | |
793 | 849 |
} |
794 | 850 |
|
795 | 851 |
/** |
796 |
* Implementation of hook_votingapi_metadata_alter().
|
|
852 |
* Implements hook_votingapi_metadata_alter().
|
|
797 | 853 |
*/ |
798 | 854 |
function fivestar_votingapi_metadata_alter(&$data) { |
799 | 855 |
foreach (fivestar_get_tags() as $tag) { |
... | ... | |
806 | 862 |
} |
807 | 863 |
} |
808 | 864 |
|
865 |
/** |
|
866 |
* |
|
867 |
*/ |
|
809 | 868 |
function fivestar_get_tags() { |
810 | 869 |
$tags_txt = variable_get('fivestar_tags', 'vote'); |
811 | 870 |
$tags_exploded = explode(',', $tags_txt); |
... | ... | |
828 | 887 |
return $tags; |
829 | 888 |
} |
830 | 889 |
|
890 |
/** |
|
891 |
* |
|
892 |
*/ |
|
831 | 893 |
function fivestar_get_targets($field, $instance, $key = FALSE, $entity = FALSE, $langcode = LANGUAGE_NONE) { |
832 | 894 |
$options = array(); |
833 | 895 |
$targets = module_invoke_all('fivestar_target_info', $field, $instance); |
... | ... | |
864 | 926 |
foreach ($field_instances as $field_instance) { |
865 | 927 |
$options[$field_instance['field_name']] = array( |
866 | 928 |
'title' => t('Node reference: @field', array('@field' => $field_instance['field_name'])), |
867 |
'callback' => '_fivestar_target_node_reference' |
|
929 |
'callback' => '_fivestar_target_node_reference',
|
|
868 | 930 |
); |
869 | 931 |
} |
870 | 932 |
} |
... | ... | |
880 | 942 |
foreach ($field_instances as $field_instance) { |
881 | 943 |
$options[$field_instance['field_name']] = array( |
882 | 944 |
'title' => t('Entity reference: @field', array('@field' => $field_instance['field_name'])), |
883 |
'callback' => '_fivestar_target_entityreference' |
|
945 |
'callback' => '_fivestar_target_entityreference',
|
|
884 | 946 |
); |
885 | 947 |
} |
886 | 948 |
} |
... | ... | |
896 | 958 |
foreach ($field_instances as $field_instance) { |
897 | 959 |
$options[$field_instance['field_name']] = array( |
898 | 960 |
'title' => t('User reference: @field', array('@field' => $field_instance['field_name'])), |
899 |
'callback' => '_fivestar_target_user_reference' |
|
961 |
'callback' => '_fivestar_target_user_reference',
|
|
900 | 962 |
); |
901 | 963 |
} |
902 | 964 |
} |
... | ... | |
907 | 969 |
if ($instance['entity_type'] == 'comment') { |
908 | 970 |
$options['parent_node'] = array( |
909 | 971 |
'title' => t('Parent Node'), |
910 |
'callback' => '_fivestar_target_comment_parent_node' |
|
972 |
'callback' => '_fivestar_target_comment_parent_node',
|
|
911 | 973 |
); |
912 | 974 |
} |
913 | 975 |
|
... | ... | |
967 | 1029 |
return $target; |
968 | 1030 |
} |
969 | 1031 |
|
1032 |
/** |
|
1033 |
* |
|
1034 |
*/ |
|
970 | 1035 |
function _fivestar_target_comment_parent_node($entity, $field, $instance, $langcode) { |
971 | 1036 |
return array( |
972 | 1037 |
'entity_id' => $entity->nid, |
... | ... | |
977 | 1042 |
/** |
978 | 1043 |
* Helper function to determine if a user can vote on content. |
979 | 1044 |
* |
980 |
* @return Boolean
|
|
1045 |
* @return bool
|
|
981 | 1046 |
*/ |
982 | 1047 |
function _fivestar_allow_vote($element) { |
983 | 1048 |
global $user; |
... | ... | |
991 | 1056 |
$criteria = array( |
992 | 1057 |
'entity_id' => isset($element['#settings']['content_id']) ? $element['#settings']['content_id'] : NULL, |
993 | 1058 |
'entity_type' => isset($element['#settings']['content_type']) ? $element['#settings']['content_type'] : NULL, |
1059 |
'tag' => isset($element['#settings']['tag']) ? $element['#settings']['tag'] : NULL, |
|
994 | 1060 |
'uid' => $user->uid, |
995 | 1061 |
); |
996 | 1062 |
|
997 |
$can_revote = !votingapi_select_votes($criteria); |
|
1063 |
$can_revote = !votingapi_select_votes($criteria);
|
|
998 | 1064 |
} |
999 | 1065 |
if (!$can_revote) { |
1000 | 1066 |
return FALSE; |
... | ... | |
1014 | 1080 |
$uid2 = $user->uid; |
1015 | 1081 |
return $entity->uid != $user->uid; |
1016 | 1082 |
} |
1083 |
|
|
1084 |
/** |
|
1085 |
* Implements hook_ctools_content_subtype_alter() |
|
1086 |
*/ |
|
1087 |
function fivestar_ctools_content_subtype_alter(&$subtype, &$plugin) { |
|
1088 |
if ($plugin['name'] == 'entity_field' && isset($subtype['subtype_id'])) { |
|
1089 |
list($entity_type, $field_name) = explode(':', $subtype['subtype_id'], 2); |
|
1090 |
$field = field_info_field($field_name); |
|
1091 |
if ($field['type'] == 'fivestar') { |
|
1092 |
$subtype['render callback'] = 'fivestar_fivestar_field_content_type_render'; |
|
1093 |
} |
|
1094 |
} |
|
1095 |
} |
|
1096 |
|
|
1097 |
/** |
|
1098 |
* Render the custom content type. |
|
1099 |
*/ |
|
1100 |
function fivestar_fivestar_field_content_type_render($subtype, $conf, $panel_args, $context) { |
|
1101 |
if (empty($context) || empty($context->data)) { |
|
1102 |
return; |
|
1103 |
} |
|
1104 |
|
|
1105 |
// Get a shortcut to the entity. |
|
1106 |
$entity = $context->data; |
|
1107 |
list($entity_type, $field_name) = explode(':', $subtype, 2); |
|
1108 |
|
|
1109 |
// Load the entity type's information for this field. |
|
1110 |
$ids = entity_extract_ids($entity_type, $entity); |
|
1111 |
$field = field_info_instance($entity_type, $field_name, $ids[2]); |
|
1112 |
|
|
1113 |
// Do not render if the entity type does not have this field. |
|
1114 |
if (empty($field)) { |
|
1115 |
return; |
|
1116 |
} |
|
1117 |
$language = field_language($entity_type, $entity, $field_name); |
|
1118 |
|
|
1119 |
if (empty($conf['label']) || $conf['label'] == 'title') { |
|
1120 |
$label = 'hidden'; |
|
1121 |
$conf['label'] = 'title'; |
|
1122 |
} |
|
1123 |
else { |
|
1124 |
$label = $conf['label']; |
|
1125 |
} |
|
1126 |
|
|
1127 |
$field_settings = array( |
|
1128 |
'label' => $label, |
|
1129 |
'type' => $conf['formatter'], |
|
1130 |
// Pass all entity field panes settings to field display settings. |
|
1131 |
'pane_settings' => $conf, |
|
1132 |
); |
|
1133 |
|
|
1134 |
// Get the field output, and the title. |
|
1135 |
if (!empty($conf['formatter_settings'])) { |
|
1136 |
$field_settings['settings'] = $conf['formatter_settings']; |
|
1137 |
} |
|
1138 |
|
|
1139 |
$all_values = field_get_items($entity_type, $entity, $field_name, $language); |
|
1140 |
|
|
1141 |
if (!$all_values) { |
|
1142 |
$all_values = array(); |
|
1143 |
} |
|
1144 |
|
|
1145 |
// Reverse values. |
|
1146 |
if (isset($conf['delta_reversed']) && $conf['delta_reversed']) { |
|
1147 |
$all_values = array_reverse($all_values, TRUE); |
|
1148 |
} |
|
1149 |
|
|
1150 |
if (isset($conf['delta_limit'])) { |
|
1151 |
$offset = intval($conf['delta_offset']); |
|
1152 |
$limit = !empty($conf['delta_limit']) ? $conf['delta_limit'] : NULL; |
|
1153 |
$all_values = array_slice($all_values, $offset, $limit, TRUE); |
|
1154 |
} |
|
1155 |
|
|
1156 |
$clone = clone $entity; |
|
1157 |
$clone->{$field_name}[$language] = $all_values; |
|
1158 |
$field_output = field_view_field($entity_type, $clone, $field_name, $field_settings, $language); |
|
1159 |
|
|
1160 |
if (!empty($field_output) && !empty($conf['override_title'])) { |
|
1161 |
$field_output['#title'] = filter_xss_admin($conf['override_title_text']); |
|
1162 |
} |
|
1163 |
|
|
1164 |
// Build the content type block. |
|
1165 |
$block = new stdClass(); |
|
1166 |
$block->module = 'entity_field'; |
|
1167 |
if ($conf['label'] == 'title' && isset($field_output['#title'])) { |
|
1168 |
$block->title = $field_output['#title']; |
|
1169 |
} |
|
1170 |
|
|
1171 |
$block->content = $field_output; |
|
1172 |
$block->delta = $ids[0]; |
|
1173 |
|
|
1174 |
return $block; |
|
1175 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules