Projet

Général

Profil

Révision d50a36e0

Ajouté par Assos Assos il y a presque 4 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/fivestar/includes/fivestar.theme.inc
2 2

  
3 3
/**
4 4
 * @file
5
 * Provides the theming functions for fivestar
5
 * Provides the theming functions for fivestar.
6 6
 */
7 7

  
8 8
/**
......
38 38
    ),
39 39
  );
40 40

  
41
  // Attach necessary JS settings
41
  // Attach necessary JS settings.
42 42
  $settings = array(
43 43
    'titleUser' => t('Your rating') . ': ',
44 44
    'titleAverage' => t('Average') . ': ',
......
59 59
  return $output;
60 60
}
61 61

  
62
/**
63
 *
64
 */
62 65
function theme_fivestar_preview($variables) {
63 66
  extract($variables, EXTR_SKIP);
64 67
  $values = array(
......
88 91
  return $form;
89 92
}
90 93

  
94
/**
95
 *
96
 */
91 97
function theme_fivestar_preview_wrapper($variables) {
92 98
  return '<div class="fivestar-preview fivestar-preview-' . $variables['type'] . '">' . $variables['content'] . '</div>';
93 99
}
......
106 112
    $element['#instance_settings']['stars'] = 5;
107 113
  }
108 114

  
109
  // Add CSS and JS
115
  // Add CSS and JS.
110 116
  $path = drupal_get_path('module', 'fivestar');
111 117
  drupal_add_js($path . '/js/fivestar.js');
112 118
  drupal_add_css($path . '/css/fivestar.css');
......
133 139
  $stars = (empty($element['#instance_settings']['stars'])) ? 5 : $element['#instance_settings']['stars'];
134 140
  $average = $element['#item']['average'];
135 141
  // Rating is X out of Y stars.
136
  $rating = round(($average/100) * $stars, 1);
142
  $rating = round(($average / 100) * $stars, 1);
137 143
  $output = $rating . '/' . $stars;
138 144

  
139 145
  return $output;
......
171 177
  _form_set_class($element, array('form-select'));
172 178
  return '<select' . drupal_attributes($element['#attributes']) . '>' . form_select_options($element) . '</select>';
173 179
}
180

  
174 181
/**
175 182
 * Display a plain HTML view-only version of the widget with a specified rating.
176 183
 *
......
180 187
 *   The total number of stars this rating is out of.
181 188
 * @param $tag
182 189
 *   Allows multiple ratings per node.
190
 *
183 191
 * @return
184 192
 *   A themed HTML string representing the star widget.
185 193
 */
186 194
function theme_fivestar_static($variables) {
187
  $rating  = $variables['rating'];
195
  $rating = $variables['rating'];
188 196
  $stars = $variables['stars'];
189 197
  $tag = $variables['tag'];
190 198
  $widget = $variables['widget'];
......
199 207
  if (empty($stars)) {
200 208
    $stars = 5;
201 209
  }
202
  $numeric_rating = $rating/(100/$stars);
203
  for ($n=1; $n <= $stars; $n++) {
204
    $star_value = ceil((100/$stars) * $n);
205
    $prev_star_value = ceil((100/$stars) * ($n-1));
210
  $numeric_rating = $rating / (100 / $stars);
211
  for ($n = 1; $n <= $stars; $n++) {
212
    $star_value = ceil((100 / $stars) * $n);
213
    $prev_star_value = ceil((100 / $stars) * ($n - 1));
206 214
    $zebra = ($n % 2 == 0) ? 'even' : 'odd';
207 215
    $first = $n == 1 ? ' star-first' : '';
208 216
    $last = $n == $stars ? ' star-last' : '';
......
217 225
    else {
218 226
      $output .= '<span class="off">';
219 227
    }
220
    if ($n == 1)$output .= $numeric_rating;
228
    if ($n == 1) {
229
      $output .= $numeric_rating;
230
    }
221 231
    $output .= '</span></div>';
222 232
  }
223 233
  $output .= '</div></div>';
......
242 252
 *   The total number of votes.
243 253
 * @param $stars
244 254
 *   The number of stars being displayed.
255
 *
245 256
 * @return
246 257
 *   A themed HTML string representing the star widget.
247 258
 */
......
281 292
      $div_class = 'count';
282 293
    }
283 294
    if ($votes === 0) {
284
      $output = '<span class="empty">'. t('No votes yet') .'</span>';
295
      $output = '<span class="empty">' . t('No votes yet') . '</span>';
285 296
    }
286 297
    else {
287 298
      if (!empty($microdata['rating_count']['#attributes'])) {
288 299
        $rating_count_microdata = drupal_attributes($microdata['rating_count']['#attributes']);
289 300
      }
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.
301
      // We don't directly substitute $votes (i.e. use '@count') in
302
      // format_plural(), because it has a span around it which is not
303
      // translatable.
292 304
      $votes_str = format_plural($votes, '!cnt vote', '!cnt votes', array(
293
        '!cnt' => '<span ' . $rating_count_microdata . '>' . intval($votes) . '</span>'));
305
        '!cnt' => '<span ' . $rating_count_microdata . '>' . intval($votes) . '</span>',
306
      ));
294 307
      if (isset($user_rating) || isset($average_rating)) {
295 308
        $output .= ' <span class="total-votes">(' . $votes_str . ')</span>';
296 309
      }
......
300 313
    }
301 314
  }
302 315

  
303

  
304 316
  $output = '<div class="fivestar-summary fivestar-summary-' . $div_class . '">' . $output . '</div>';
305 317
  return $output;
306 318
}

Formats disponibles : Unified diff