Projet

Général

Profil

Révision 4853591f

Ajouté par Assos Assos il y a plus de 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/fivestar/fivestar.api.php
63 63
}
64 64

  
65 65
/**
66
 * Implementation of hook_fivestar_access().
66
 * Implementation of hook_fivestar_target_info().
67 67
 *
68 68
 * @param $field
69 69
 *   The field structure for the operation.
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-01
11
version = "7.x-2.0-alpha3"
10
; Information added by Drupal.org packaging script on 2014-02-16
11
version = "7.x-2.0-beta1"
12 12
core = "7.x"
13 13
project = "fivestar"
14
datestamp = "1391276007"
14
datestamp = "1392552810"
15 15

  
drupal7/sites/all/modules/fivestar/fivestar.install
38 38
  $fields = field_read_fields(array('module' => 'fivestar'));
39 39
  $tags_numeric = array_values(fivestar_get_tags());
40 40
  
41
  foreach($fields as $field) {
41
  foreach ($fields as $field) {
42 42
    if (is_numeric($field['settings']['axis'])) {
43 43
      $field['settings']['axis'] = $tags_numeric[$field['settings']['axis']];
44 44
    }
......
51 51
function fivestar_update_7202() {
52 52
  $fields = field_read_fields(array('module' => 'fivestar'));
53 53

  
54
  foreach($fields as $field) {
54
  foreach ($fields as $field) {
55 55
    $instances = field_read_instances(array('field_name' => $field['field_name']));
56
    foreach($instances as $instance) {
56
    foreach ($instances as $instance) {
57 57
      $instance['settings'] = $field['settings'];
58 58
      field_update_instance($instance);
59 59
    }
......
77 77
  $tags_exploded = explode(',', $tags_txt);
78 78

  
79 79
  $tags = array();
80
  $got_vote = false;
80
  $got_vote = FALSE;
81 81
  foreach ($tags_exploded as $tag) {
82 82
    $tag_trimmed = trim($tag);
83 83
    if ($tag_trimmed) {
84 84
      $tags[] = $tag_trimmed;
85 85
      if ($tag_trimmed == 'vote') {
86
        $got_vote = true;
86
        $got_vote = TRUE;
87 87
      }
88 88
    }
89 89
  }
......
93 93
  }
94 94
  $tags;
95 95

  
96
  foreach($tags as $tag) {
96
  foreach ($tags as $tag) {
97 97
    $suffix = '';
98
    foreach($types as $type) {
98
    foreach ($types as $type) {
99 99
      $var_suffix = $type . ($tag == 'vote' ? '' : '_' . $tag);
100 100

  
101 101
      $settings = array(
102 102
        'stars' => variable_get('fivestar_stars_' . $var_suffix, 6),
103 103
        'allow_clear' => variable_get('fivestar_unvote_' . $var_suffix, 0),
104
        'feedback_enable' => variable_get('fivestar_feedback_'. $var_suffix, 1),
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 107
      );
......
112 112
        $field = field_read_field($field_name . $suffix, array('include_deleted' => TRUE));
113 113

  
114 114
        $i = 0;
115
        while(!empty($field) && $field['type'] != 'fivestar') {
115
        while (!empty($field) && $field['type'] != 'fivestar') {
116 116
          $suffix = '_' . $i;
117 117
          $field = field_read_field($field_name . $suffix, array('include_deleted' => TRUE));
118 118
          $i++;
......
178 178
 */
179 179
function fivestar_update_7204() {
180 180
  $fields = field_read_fields(array('type' => 'fivestar'));
181
  foreach($fields as $field) {
181
  foreach ($fields as $field) {
182 182
    // Iterate through the instances of the field.
183 183
    $instances = field_read_instances(array('field_name' => $field['field_name']));
184
    foreach($instances as $instance) {
184
    foreach ($instances as $instance) {
185 185
      // The default should be to not allow clearing.
186 186
      $instance['settings']['allow_clear'] = FALSE;
187 187
      // Check each of the displays on the field instance an convert the formatter
188 188
      // from fivestar_formatter_exposed_stars to fivestar_formatter_default.
189
      foreach($instance['display'] as $key => $display) {
189
      foreach ($instance['display'] as $key => $display) {
190 190
        if ($display['type'] == 'fivestar_formatter_exposed_stars') {
191 191
          // Convert the formatter and set the exposed settings.
192 192
          $instance['display'][$key]['type'] == 'fivestar_formatter_default';
......
214 214
 */
215 215
function fivestar_update_7205() {
216 216
  $fields = field_read_fields(array('type' => 'fivestar'));
217
  foreach($fields as $field) {
217
  foreach ($fields as $field) {
218 218
    // Iterate through the instances of the field.
219 219
    $instances = field_read_instances(array('field_name' => $field['field_name']));
220
    foreach($instances as $instance) {
220
    foreach ($instances as $instance) {
221 221
      // If the widget type is select, lets change it.
222 222
      if ($instance['widget']['type'] == 'select') {
223 223
        $instance['widget']['type'] = 'fivestar_select';
drupal7/sites/all/modules/fivestar/fivestar.module
35 35
    'type'              => MENU_NORMAL_ITEM,
36 36
    'file'              => 'includes/fivestar.admin.inc',
37 37
  );
38
  $items['fivestar/preview/color'] = array(
39
    'page callback'     => 'fivestar_preview_color',
40
    'access callback'   => 'user_access',
41
    'access arguments'  => array('administer site configuration'),
42
    'type'              => MENU_CALLBACK,
43
    'file'              => 'includes/fivestar.color.inc',
44
  );
45 38

  
46 39
  return $items;
47 40
}
......
178 171
    }
179 172

  
180 173
    // Moving the calculationg after saving/deleting the vote but before getting the votes.
181
    votingapi_recalculate_results($entity_type, $id);    
174
    votingapi_recalculate_results($entity_type, $id);
182 175
    return fivestar_get_votes($entity_type, $id, $tag, $uid);
183 176
  }
184 177
}
......
306 299
function fivestar_fivestar_access($entity_type, $id, $tag, $uid) {
307 300
  // Check to see if there is a field instance on this entity.
308 301
  $fields = field_read_fields(array('module' => 'fivestar'));
309
  foreach($fields as $field) {
302
  foreach ($fields as $field) {
310 303
    if ($field['settings']['axis'] == $tag) {
311 304
      $params = array(
312 305
        'entity_type' => $entity_type,
313 306
        'field_name' => $field['field_name'],
314 307
      );
315 308
      $instance = field_read_instances($params);
316
      if(!empty($instance)) {
309
      if (!empty($instance)) {
317 310
        return TRUE;
318 311
      }
319 312
    }
320 313
  }
321 314
}
322 315

  
316
/**
317
 * Implementation of hook_form_comment_form_alter().
318
 *
319
 * This hook removes the parent node, together with the fivestar field, from
320
 * the comment preview page. If this is left in, when the user presses the
321
 * "Save" button after the preview page has been displayed, the fivestar widget
322
 * gets the input rather than the comment; the user's input is lost. Based on a
323
 * suggestion by ChristianAdamski in issue 1289832-3.
324
 */
325
function fivestar_form_comment_form_alter(&$form, &$form_state, $form_id) {
326
  $is_fivestar = FALSE;
327
  if (isset($form['comment_output_below'])) {
328
    foreach($form['comment_output_below'] as $key => $value) {
329
      if (is_array($value) && !empty($value['#field_type'])) {
330
        if ($value['#field_type'] =='fivestar') {
331
          $is_fivestar = TRUE;
332
          $fivestar_key = $key;
333
        }
334
      }
335
    }
336
  }
337
  if ($is_fivestar) {
338
    unset($form['comment_output_below'][$fivestar_key]);
339
  }
340
}
341

  
323 342
/**
324 343
 * Implementation of hook_fivestar_widgets().
325 344
 *
......
334 353
function fivestar_fivestar_widgets() {
335 354
  $files = &drupal_static(__FUNCTION__);
336 355
  if (!isset($files)) {
337
    $widgets_directory = drupal_get_path('module', 'fivestar') .'/widgets';
356
    $widgets_directory = drupal_get_path('module', 'fivestar') . '/widgets';
338 357
    $files = file_scan_directory($widgets_directory, '/\.css$/');
339 358
  }
340 359
  $widgets = array();
......
396 415
    '#widget' => isset($settings['widget']) ? $settings['widget'] : array('name' => 'default', 'css' => 'default'),
397 416
    '#values' => $values,
398 417
    '#settings' => $settings,
418
    '#description' => $settings['description'],
399 419
  );
400 420

  
401 421
  $form['fivestar_submit'] = array(
......
427 447
 * AJAX submit handler for fivestar_custom_widget
428 448
 */
429 449
function fivestar_ajax_submit($form, $form_state) {
430
  _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']);
431
  $votes = _fivestar_cast_vote($form_state['settings']['content_type'], $form_state['settings']['content_id'], $form_state['values']['vote'], $form_state['settings']['tag']);
450
  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']);
452
    $votes = _fivestar_cast_vote($form_state['settings']['content_type'], $form_state['settings']['content_id'], $form_state['values']['vote'], $form_state['settings']['tag']);
453
  }
454

  
432 455

  
433 456
  $values = array();
434 457
  $values['user'] = isset($votes['user']['value']) ? $votes['user']['value'] : 0;
......
510 533
    '#options' => $options,
511 534
    '#required' => $element['#required'],
512 535
    '#theme' => 'fivestar_select',
536
    '#attributes' => $element['#attributes'],
513 537
    '#default_value' => _fivestar_get_element_default_value($element),
514 538
    '#weight' => -2,
515 539
  );
......
568 592
      $class[] = 'fivestar-user-stars';
569 593
      break;
570 594
    case 'smart':
571
      $class[] = 'fivestar-smart-stars '. ($values['user'] ? 'fivestar-user-stars' : 'fivestar-average-stars');
595
      $class[] = 'fivestar-smart-stars ' . ($values['user'] ? 'fivestar-user-stars' : 'fivestar-average-stars');
572 596
      break;
573 597
    case 'dual':
574 598
      $class[] = 'fivestar-combo-stars';
......
688 712
 */
689 713
function fivestar_validate($element, &$form_state) {
690 714
  if ($element['#required'] && (empty($element['#value']) || $element['#value'] == '-')) {
691
    form_error($element, t('!name field is required.', array('!name' => $element['#title'])));
715
    form_error($element, t('@name field is required.', array('@name' => $element['#title'])));
692 716
  }
693 717
}
694 718

  
......
711 735
  $tags_exploded = explode(',', $tags_txt);
712 736

  
713 737
  $tags = array();
714
  $got_vote = false;
738
  $got_vote = FALSE;
715 739
  foreach ($tags_exploded as $tag) {
716 740
    $tag_trimmed = trim($tag);
717 741
    if ($tag_trimmed) {
718 742
      $tags[$tag_trimmed] = $tag_trimmed;
719 743
      if ($tag_trimmed == 'vote') {
720
        $got_vote = true;
744
        $got_vote = TRUE;
721 745
      }
722 746
    }
723 747
  }
......
771 795
    }
772 796
  }
773 797

  
798
  // Add entityreference support.
799
  if (module_exists('entityreference')) {
800
    $field_names = array_keys(field_read_fields(array('module' => 'entityreference')));
801
    if (!empty($field_names)) {
802
      $field_instances = field_read_instances(array('entity_type' => $entity_type, 'bundle' => $bundle, 'field_name' => $field_names));
803
      if (!empty($field_instances)) {
804
        foreach ($field_instances as $field_instance) {
805
          $options[$field_instance['field_name']] = array(
806
            'title' => t('Entity reference: @field', array('@field' => $field_instance['field_name'])),
807
            'callback' => '_fivestar_target_entityreference'
808
          );
809
        }
810
      }
811
    }
812
  }
813

  
814
  // Add user reference support.
815
  if (module_exists('user_reference')) {
816
    $field_names = array_keys(field_read_fields(array('module' => 'user_reference')));
817
    if (!empty($field_names)) {
818
      $field_instances = field_read_instances(array('entity_type' => $entity_type, 'bundle' => $bundle, 'field_name' => $field_names));
819
      if (!empty($field_instances)) {
820
        foreach ($field_instances as $field_instance) {
821
          $options[$field_instance['field_name']] = array(
822
            'title' => t('User reference: @field', array('@field' => $field_instance['field_name'])),
823
            'callback' => '_fivestar_target_user_reference'
824
          );
825
        }
826
      }
827
    }
828
  }
829

  
774 830
  // Add comment module support.
775 831
  if ($instance['entity_type'] == 'comment') {
776 832
    $options['parent_node'] = array(
......
784 840

  
785 841
/**
786 842
 *
787
 * @return (array) array('entity_type', 'entity_id')
843
 * @return array
844
 *   array('entity_type', 'entity_id').
788 845
 */
789 846
function _fivestar_target_node_reference($entity, $field, $instance, $langcode) {
790 847
  $target = array();
......
798 855
  return $target;
799 856
}
800 857

  
858
/**
859
 * @return (array) array('entity_type', 'entity_id')
860
 */
861
function _fivestar_target_entityreference($entity, $field, $instance, $langcode) {
862
  $target = array();
863

  
864
  $entityreference = $instance['settings']['target'];
865

  
866
  // Retrieve entity settings for the referenced field.
867
  $field_info = field_info_field($entityreference);
868

  
869
  if (isset($entity->{$entityreference}[$langcode][0]) && isset($entity->{$entityreference}[$langcode][0]['target_id']) && is_numeric($entity->{$entityreference}[$langcode][0]['target_id'])) {
870
    $target['entity_id'] = $entity->{$entityreference}[$langcode][0]['target_id'];
871
    $target['entity_type'] = $field_info['settings']['target_type'];
872
  }
873

  
874
  return $target;
875
}
876

  
877
/**
878
 *
879
 * @return array
880
 *   array('entity_type', 'entity_id').
881
 */
882
function _fivestar_target_user_reference($entity, $field, $instance, $langcode) {
883
  $target = array();
884

  
885
  $user_reference = $instance['settings']['target'];
886
  if (isset($entity->{$user_reference}[$langcode][0]) && is_numeric($entity->{$user_reference}[$langcode][0]['uid'])) {
887
    $target['entity_id'] = $entity->{$user_reference}[$langcode][0]['uid'];
888
    $target['entity_type'] = 'user';
889
  }
890

  
891
  return $target;
892
}
893

  
801 894
function _fivestar_target_comment_parent_node($entity, $field, $instance, $langcode) {
802 895
  return array(
803 896
    'entity_id' => $entity->nid,
drupal7/sites/all/modules/fivestar/includes/fivestar.field.inc
62 62
function fivestar_field_instance_settings_form($field, $instance) {
63 63
  $form = array();
64 64

  
65
  $widget_title = ($instance['widget']['type'] == 'select') ? t('Number of options') : t('Number of stars');
65 66
  $form['stars'] = array(
66 67
    '#type' => 'select',
67
    '#title' => $instance['widget']['type'] == 'select' ? t('Number of options') : t('Number of stars'),
68
    '#title' => check_plain($widget_title),
68 69
    '#options' => drupal_map_assoc(range(1, 10)),
69 70
    '#default_value' => isset($instance['settings']['stars']) ? $instance['settings']['stars'] : 5,
70 71
  );
71
  
72

  
72 73
  $form['allow_clear'] = array(
73 74
    '#type' => 'checkbox',
74 75
    '#title' => t('Allow users to cancel their ratings.'),
......
85 86
    '#description' => t('The voting target will make the value of this field cast a vote on another node. Use node reference fields module to create advanced reviews. Use the Parent Node Target when using fivestar with comments. More information available on the <a href="http://drupal.org/handbook/modules/fivestar">Fivestar handbook page</a>.'),
86 87
    '#access' => (count($options) > 1 && $instance['widget']['type'] != 'exposed'),
87 88
  );
88
  
89

  
89 90
  return $form;
90 91
}
91 92

  
......
123 124
      _fivestar_cast_vote($target['entity_type'], $target['entity_id'], $rating, $field['settings']['axis'], $entity->uid, TRUE);
124 125
      votingapi_recalculate_results($target['entity_type'], $target['entity_id']);
125 126
    }
127
    // The original callback is only called for a single updated field, but the Field API
128
    // then updates all fields of the entity. For an update, the Field API first deletes
129
    // the equivalent row in the database and then adds a new row based on the
130
    // information in $items here. If there are multiple Fivestar fields on an entity, the
131
    // one being updated is handled ok ('rating' having already been set to the new value),
132
    // but other Fivestar fields are set to NULL as 'rating' isn't set - not what an update
133
    // would be expected to do. So set 'rating' for all of the Fivestar fields from the
134
    // existing user data in $items. This preserves the user vote thru Field API's
135
    // delete/re-insert process.
136
    if (!isset($items[$delta]['rating'])) {
137
      $items[$delta]['rating'] = $items[$delta]['user'];
138
    }
126 139
  }
127 140
}
128 141

  
......
131 144
 */
132 145
function _fivestar_field_target($entity, $field, $instance, $item, $langcode) {
133 146
  if ($instance['widget']['type'] == 'exposed') {
134
    return null;
147
    return NULL;
135 148
  }
136 149
  if (isset($instance['settings']['target'])) {
137 150
    $target = fivestar_get_targets($field, $instance, $instance['settings']['target'], $entity, $langcode);
......
152 165
 */
153 166
function _fivestar_update_field_value($entity_type, $entity, $field_name, $langcode, $value) {
154 167
  $entity->{$field_name}[$langcode][0]['rating'] = $value;
168
  $entity->original = isset($entity->original) ? $entity->original : NULL;
155 169
  field_attach_presave($entity_type, $entity);
156 170
  field_attach_update($entity_type, $entity);
157 171
}
......
223 237
}
224 238

  
225 239
function fivestar_previews_expand($element) {
226
  
240

  
227 241
  foreach (element_children($element) as $css) {
228 242
    $vars = array(
229 243
      'css' => $css,
......
231 245
    );
232 246
    $element[$css]['#description'] = theme('fivestar_preview_widget', $vars);
233 247
  }
234
  
248

  
235 249
  return $element;
236 250
}
237 251

  
......
240 254
 */
241 255
function fivestar_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
242 256
  $element['#tree'] = TRUE;
243

  
257
  $i18n = function_exists('i18n_field_translate_property');
244 258
  if ($instance['widget']['type'] == 'fivestar_select' || ($instance['widget']['type'] == 'stars' && isset($form['#title']) && $form['#title'] == 'Default value')) {
245 259
    $options = array(0 => t('No stars'));
246 260
    if (empty($instance['settings']['stars'])) {
247 261
      $instance['settings']['stars'] = 5;
248 262
    }
249
    for($i = 1; $i <= $instance['settings']['stars']; $i++) {
263
    for ($i = 1; $i <= $instance['settings']['stars']; $i++) {
250 264
      $percentage = ceil($i * 100 / $instance['settings']['stars']);
251 265
      $options[$percentage] = format_plural($i, '1 star', '@count stars');
252 266
    }
253 267
    $element['rating'] = array(
254 268
      '#type' => 'select',
255
      '#title' => isset($instance['label']) ? $instance['label'] : FALSE,
269
      '#title' => isset($instance['label']) ? (($i18n) ? i18n_field_translate_property($instance, 'label') : t($instance['label'])) : FALSE,
256 270
      '#options' => $options,
257 271
      '#default_value' => isset($items[$delta]['rating']) ? $items[$delta]['rating'] : NULL,
258
      '#description' => isset($instance['description']) ? $instance['description'] : FALSE,
272
      '#description' => isset($instance['description']) ? (($i18n) ? i18n_field_translate_property($instance, 'description') : t($instance['description'])) : FALSE,
259 273
      '#required' => isset($instance['required']) ? $instance['required'] : FALSE,
260 274
    );
261 275
  }
......
281 295
      'text' => 'none',
282 296
      'widget' => $widget,
283 297
    );
284
    
298

  
285 299
    $element['rating'] = array(
286 300
      '#type'=> 'fivestar',
287
      '#title' => isset($instance['label']) ? $instance['label'] : FALSE,
301
      '#title' => isset($instance['label']) ? (($i18n) ? i18n_field_translate_property($instance, 'label') : t($instance['label'])) : FALSE,
288 302
      '#stars' => isset($instance['settings']['stars']) ? $instance['settings']['stars'] : 5,
289 303
      '#allow_clear' => isset($instance['settings']['allow_clear']) ? $instance['settings']['allow_clear'] : FALSE,
290 304
      '#default_value' => isset($items[$delta]['rating']) ? $items[$delta]['rating'] : (isset($instance['default_value'][$delta]['rating']) ? $instance['default_value'][$delta]['rating'] : 0),
291 305
      '#widget' => $widget,
292 306
      '#settings' => $settings,
293 307
      '#values' => $values,
294
      '#description' => isset($instance['description']) ? $instance['description'] : FALSE,
308
      '#description' => isset($instance['description']) ? (($i18n) ? i18n_field_translate_property($instance, 'description') : t($instance['description'])) : FALSE,
295 309
      '#required' => isset($instance['required']) ? $instance['required'] : FALSE,
296 310
    );
297 311
  }
......
336 350
function fivestar_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
337 351
  $display = $instance['display'][$view_mode];
338 352
  $settings = $display['settings'];
339
  
353

  
340 354
  if ($display['type'] != 'fivestar_formatter_default') {
341 355
    return;
342 356
  }
......
352 366
  );
353 367

  
354 368
  $widgets = module_invoke_all('fivestar_widgets');
355
  
369

  
356 370
  $element['widget']['fivestar_widget'] = array(
357 371
    '#type' => 'radios',
358 372
    '#options' => array('default' => t('Default')) + $widgets,
......
363 377
  );
364 378

  
365 379
  if ($instance['widget']['type'] == 'exposed') {
366
    // Removed entity_get_info here and simplified the text. This is not saved
367
    // to used here and is honestly not need it. See http://drupal.org/node/1268972
368 380
    $element['expose'] = array(
369 381
      '#type' => 'checkbox',
370
      '#title' => t('Expose this Fivestar field for voting on the @type type.'),
382
      '#title' => t('Allow voting on the entity.'),
371 383
      '#default_value' => $settings['expose'],
372 384
      '#return_value' => 1
373 385
    );
......
421 433
      '@text' => strtolower($settings['text'])));
422 434
    return $summary;
423 435
  }
424
  
436

  
425 437
  $summary = t("Style: @widget, Stars display: @style, Text display: @text", array(
426 438
    '@widget' => isset($widgets[$settings['widget']['fivestar_widget']]) ? $widgets[$settings['widget']['fivestar_widget']] : t('default'),
427 439
    '@style' => strtolower($settings['style']),
......
614 626
    'labels_enable' => FALSE,
615 627
    'labels' => array(),
616 628
    'widget' => $widget,
629
    'description' => $instance['description'],
617 630
  );
618 631

  
619 632
  return $settings;
......
652 665
      // (which is the same as nothing).
653 666
      $fivestar_widget = 'default';
654 667
    }
655
    else if ($type == 'stars') {
668
    elseif ($type == 'stars') {
656 669
      // Stars rated while editing, that is, $type = stars,
657 670
      // falls back on whatever the user selected to be displayed on node/add and node/%/edit
658 671
      $fivestar_widget = $instance['widget']['settings']['widget']['fivestar_widget'];
......
668 681
}
669 682

  
670 683
/**
671
 * Implements hook_field_prepare_view()
684
 * Implements hook_field_prepare_view().
672 685
 */
673 686
function fivestar_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
674 687
  // TODO: Clean this function up!
675 688
  foreach ($entities as $id => $entity) {
676
    // Populating the $items[$id] array even for items with no value forces
677
    // the render system to output a widget.
678
    if ($instances[$id]['widget']['type'] == 'exposed') {
679
      // If the widget type is exposed then we want to look up the voting api values.
680
      $tag = $field['settings']['axis'];
681
      $votes = fivestar_get_votes($entity_type, $id, $tag);
682
      $values['user'] = isset($votes['user']['value']) ? $votes['user']['value'] : 0;
683
      $values['average'] = isset($votes['average']['value']) ? $votes['average']['value'] : 0;
684
      $values['count'] = isset($votes['count']['value']) ? $votes['count']['value'] : 0;
685
      $items[$id] = array($values);
686
    }
687
    else {
688
      // If the widget type is not exposed, then the count is always 1 or 0.
689
      // The count is pointless to display.
690
      if (!empty($items[$id][0]['rating'])) {
691
        $values['count'] = 1;
692
        $values['user'] = $items[$id][0]['rating'];
693
        $values['average'] = $items[$id][0]['rating'];
689
    // Ensure the items aren't processed twice.
690
    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
      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);
694 702
      }
695 703
      else {
696
        $values['count'] = 0;
697
        $values['user'] = 0;
698
        $values['average'] = 0;
704
        // If the widget type is not exposed, then the count is always 1 or 0.
705
        // The count is pointless to display.
706
        if (!empty($items[$id][0]['rating'])) {
707
          $values['count'] = 1;
708
          $values['user'] = $items[$id][0]['rating'];
709
          $values['average'] = $items[$id][0]['rating'];
710
        }
711
        else {
712
          $values['count'] = 0;
713
          $values['user'] = 0;
714
          $values['average'] = 0;
715
        }
716
        $items[$id] = array($values);
699 717
      }
700
      $items[$id] = array($values);
701 718
    }
702 719
  }
703 720
}
drupal7/sites/all/modules/fivestar/includes/fivestar.migrate.inc
1
<?php
2
/**
3
 * @file
4
 * Base integration with the Migrate API class.
5
 */
6

  
7
/**
8
 * Implements hook_migrate_api().
9
 */
10
function fivestar_migrate_api() {
11
  $api = array(
12
    'api' => 2,
13
    'field handlers' => array('MigrateFivestarFieldHandler'),
14
  );
15
  return $api;
16
}
17

  
18
/**
19
 * Custom extended MigrateFieldHandler class for FiveStar module.
20
 */
21
class MigrateFivestarFieldHandler extends MigrateFieldHandler {
22

  
23
  public function __construct() {
24
    $this->registerTypes(array('fivestar'));
25
  }
26

  
27
  public function fields($type, $parent_field, $migration = NULL) {
28
    $fields = array(
29
      'target' => t('Ratings: The target of the rating.'),
30
    );
31
    return $fields;
32
  }
33

  
34
  public function prepare($entity, array $field_info, array $instance, array $values) {
35
    $arguments = array();
36
    if (isset($values['arguments'])) {
37
      $arguments = array_filter($values['arguments']);
38
      unset($values['arguments']);
39
    }
40
    $language = $this->getFieldLanguage($entity, $field_info, $arguments);
41

  
42
    // Setup the standard Field API array for saving.
43
    foreach (array_values($values) as $delta => $value) {
44
      $return[$language][$delta] = array('rating' => $value) + array_intersect_key($arguments, $field_info['columns']);
45
    }
46

  
47
    return isset($return) ? $return : NULL;
48
  }
49
}
drupal7/sites/all/modules/fivestar/includes/fivestar.theme.inc
38 38

  
39 39
  // Attach necessary JS settings
40 40
  $settings = array(
41
    'titleUser' => t('Your rating') .': ',
42
    'titleAverage' => t('Average') .': ',
41
    'titleUser' => t('Your rating') . ': ',
42
    'titleAverage' => t('Average') . ': ',
43 43
    'feedbackSavingVote' => t('Saving your vote...'),
44 44
    'feedbackVoteSaved' => t('Your vote has been saved.'),
45 45
    'feedbackDeletingVote' => t('Deleting your vote...'),
......
85 85
}
86 86

  
87 87
function theme_fivestar_preview_wrapper($variables) {
88
  return '<div class="fivestar-preview fivestar-preview-'. $variables['type'] .'">'. $variables['content'] .'</div>';
88
  return '<div class="fivestar-preview fivestar-preview-' . $variables['type'] . '">' . $variables['content'] . '</div>';
89 89
}
90 90

  
91 91
/**
......
184 184
  $stars = $variables['stars'];
185 185
  $tag = $variables['tag'];
186 186
  $widget = $variables['widget'];
187
  if($widget['name'] != 'default') {
187
  if ($widget['name'] != 'default') {
188
    $path = drupal_get_path('module', 'fivestar');
189
    drupal_add_css($path . '/css/fivestar.css');
188 190
    drupal_add_css($widget['css']);
189 191
  }
190 192

  
191 193
  $output = '<div class="fivestar-' . $widget['name'] . '">';
192
  $output .= '<div class="fivestar-widget-static fivestar-widget-static-'. $tag .' fivestar-widget-static-'. $stars . ' clearfix">';
194
  $output .= '<div class="fivestar-widget-static fivestar-widget-static-' . $tag . ' fivestar-widget-static-' . $stars . ' clearfix">';
193 195
  if (empty($stars)) {
194 196
    $stars = 5;
195 197
  }
......
200 202
    $zebra = ($n % 2 == 0) ? 'even' : 'odd';
201 203
    $first = $n == 1 ? ' star-first' : '';
202 204
    $last = $n == $stars ? ' star-last' : '';
203
    $output .= '<div class="star star-'. $n .' star-'. $zebra . $first . $last .'">';
205
    $output .= '<div class="star star-' . $n . ' star-' . $zebra . $first . $last . '">';
204 206
    if ($rating < $star_value && $rating > $prev_star_value) {
205 207
      $percent = (($rating - $prev_star_value) / ($star_value - $prev_star_value)) * 100;
206
      $output .= '<span class="on" style="width: '. $percent .'%">';
208
      $output .= '<span class="on" style="width: ' . $percent . '%">';
207 209
    }
208 210
    elseif ($rating >= $star_value) {
209 211
      $output .= '<span class="on">';
......
248 250
  if (isset($user_rating)) {
249 251
    $div_class = isset($votes) ? 'user-count' : 'user';
250 252
    $user_stars = round(($user_rating * $stars) / 100, 1);
251
    $output .= '<span class="user-rating">'. t('Your rating: <span>!stars</span>', array('!stars' => $user_rating ? $user_stars : t('None'))) .'</span>';
253
    $output .= '<span class="user-rating">' . t('Your rating: <span>!stars</span>', array('!stars' => $user_rating ? $user_stars : t('None'))) . '</span>';
252 254
  }
253 255
  if (isset($user_rating) && isset($average_rating)) {
254 256
    $output .= ' ';
......
259 261
    if (!empty($microdata['average_rating']['#attributes'])) {
260 262
      $average_rating_microdata = drupal_attributes($microdata['average_rating']['#attributes']);
261 263
    }
262
    $output .= '<span class="average-rating">'. t('Average: <span !microdata>!stars</span>', array('!stars' => $average_stars, '!microdata' => $average_rating_microdata)) .'</span>';
264
    $output .= '<span class="average-rating">' . t('Average: !stars',
265
      array('!stars' => "<span $average_rating_microdata>$average_stars</span>")) . '</span>';
263 266
  }
264 267
  if (isset($user_rating) && isset($average_rating)) {
265 268
    $div_class = 'combo';
266 269
  }
267 270

  
268 271
  if (isset($votes) && !(isset($user_rating) || isset($average_rating))) {
269
    $output .= ' <span class="total-votes">'. format_plural($votes, '<span>@count</span> vote', '<span>@count</span> votes') .'</span>';
272
    $output .= ' <span class="total-votes">' . format_plural($votes, '<span>@count</span> vote', '<span>@count</span> votes') . '</span>';
270 273
    $div_class = 'count';
271 274
  }
272 275
  elseif (isset($votes)) {
273
    $output .= ' <span class="total-votes">('. format_plural($votes, '<span>@count</span> vote', '<span>@count</span> votes') .')</span>';
276
    $output .= ' <span class="total-votes">(' . format_plural($votes, '<span>@count</span> vote', '<span>@count</span> votes') . ')</span>';
274 277
  }
275 278

  
276 279
  if ($votes === 0) {
277
    $output = '<span class="empty">'. t('No votes yet') .'</span>';
280
    $output = '<span class="empty">' . t('No votes yet') . '</span>';
278 281
  }
279 282

  
280
  $output = '<div class="fivestar-summary fivestar-summary-'. $div_class . '">'. $output .'</div>';
283
  $output = '<div class="fivestar-summary fivestar-summary-' . $div_class . '">' . $output . '</div>';
281 284
  return $output;
282 285
}
283 286

  
drupal7/sites/all/modules/fivestar/js/fivestar.ajax.js
1
/**
2
 * @file
3
 *
4
 * Fivestar AJAX for updating fivestar widgets.
5
 */
6

  
1 7
/**
2 8
 * Create a degradeable star rating interface out of a simple form structure.
3 9
 */
drupal7/sites/all/modules/fivestar/js/fivestar.js
1
/**
2
 * @file
3
 *
4
 * Fivestar JavaScript behaviors integration.
5
 */
6

  
1 7
/**
2 8
 * Create a degradeable star rating interface out of a simple form structure.
3 9
 *
......
8 14

  
9 15
Drupal.behaviors.fivestar = {
10 16
  attach: function (context) {
11
    $('div.fivestar-form-item').once('fivestar', function() {
17
    $(context).find('div.fivestar-form-item').once('fivestar', function() {
12 18
      var $this = $(this);
13 19
      var $container = $('<div class="fivestar-widget clearfix"></div>');
14 20
      var $select = $('select', $this);
......
36 42
        }
37 43
      });
38 44

  
39
      $container.find('.star:lt(' + index + ')').addClass('on');
45
      if (index != -1) {
46
        $container.find('.star').slice(0, index).addClass('on');
47
      }
40 48
      $container.addClass('fivestar-widget-' + ($options.length));
41 49
      $container.find('a')
42 50
        .bind('click', $this, Drupal.behaviors.fivestar.rate)
......
53 61
    var $widget = event.data;
54 62
    var value = this.hash.replace('#', '');
55 63
    $('select', $widget).val(value).change();
56
    var $this_star = $this.closest('.star');
64
    var $this_star = (value == 0) ? $this.parent().parent().find('.star') : $this.closest('.star');
57 65
    $this_star.prevAll('.star').andSelf().addClass('on');
58 66
    $this_star.nextAll('.star').removeClass('on');
67
    if(value==0){
68
      $this_star.removeClass('on');
69
    }
70

  
59 71
    event.preventDefault();
60 72
  },
61 73
  hover: function(event) {

Formats disponibles : Unified diff