Projet

Général

Profil

Révision 5d12d676

Ajouté par Assos Assos il y a environ 6 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/views/handlers/views_handler_field.inc
2 2

  
3 3
/**
4 4
 * @file
5
 * @todo.
5
 * Definition of views_handler_field.
6 6
 */
7 7

  
8 8
/**
9 9
 * @defgroup views_field_handlers Views field handlers
10 10
 * @{
11 11
 * Handlers to tell Views how to build and display fields.
12
 *
13 12
 */
14 13

  
15 14
/**
16 15
 * Indicator of the render_text() method for rendering a single item.
17
 * (If no render_item() is present).
16
 *
17
 * If no render_item() is present.
18 18
 */
19 19
define('VIEWS_HANDLER_RENDER_TEXT_PHASE_SINGLE_ITEM', 0);
20 20

  
21 21
/**
22 22
 * Indicator of the render_text() method for rendering the whole element.
23
 * (if no render_item() method is available).
23
 *
24
 * if no render_item() method is available.
24 25
 */
25 26
define('VIEWS_HANDLER_RENDER_TEXT_PHASE_COMPLETELY', 1);
26 27

  
......
34 35
 *
35 36
 * Definition terms:
36 37
 * - additional fields: An array of fields that should be added to the query
37
 *                      for some purpose. The array is in the form of:
38
 *                      array('identifier' => array('table' => tablename,
39
 *                      'field' => fieldname); as many fields as are necessary
40
 *                      may be in this array.
38
 *   for some purpose. The array is in the form of:
39
 *   array(
40
 *     'identifier' => array(
41
 *       'table' => tablename,
42
 *       'field' => fieldname,
43
 *     )
44
 *   );
45
 *   with as many fields as are necessary may be in this array.
41 46
 * - click sortable: If TRUE, this field may be click sorted.
42 47
 *
43 48
 * @ingroup views_field_handlers
44 49
 */
45 50
class views_handler_field extends views_handler {
46
  var $field_alias = 'unknown';
47
  var $aliases = array();
51

  
52
  /**
53
   *
54
   */
55
  public $field_alias = 'unknown';
56

  
57
  /**
58
   *
59
   */
60
  public $aliases = array();
48 61

  
49 62
  /**
50 63
   * The field value prior to any rewriting.
......
58 71
   * Stores additional fields which get's added to the query.
59 72
   * The generated aliases are stored in $aliases.
60 73
   */
61
  var $additional_fields = array();
74
  public $additional_fields = array();
62 75

  
63 76
  /**
64 77
   * Construct a new field handler.
65 78
   */
66
  function construct() {
79
  public function construct() {
67 80
    parent::construct();
68 81

  
69 82
    $this->additional_fields = array();
......
79 92
  /**
80 93
   * Determine if this field can allow advanced rendering.
81 94
   *
82
   * Fields can set this to FALSE if they do not wish to allow
83
   * token based rewriting or link-making.
95
   * Fields can set this to FALSE if they do not wish to allow token based
96
   * rewriting or link-making.
84 97
   */
85
  function allow_advanced_render() {
98
  public function allow_advanced_render() {
86 99
    return TRUE;
87 100
  }
88 101

  
89
  function init(&$view, &$options) {
102
  /**
103
   * {@inheritdoc}
104
   */
105
  public function init(&$view, &$options) {
90 106
    parent::init($view, $options);
91 107
  }
92 108

  
93 109
  /**
94 110
   * Called to add the field to a query.
95 111
   */
96
  function query() {
112
  public function query() {
97 113
    $this->ensure_my_table();
98 114
    // Add the field.
99 115
    $params = $this->options['group_type'] != 'group' ? array('function' => $this->options['group_type']) : array();
......
105 121
  /**
106 122
   * Add 'additional' fields to the query.
107 123
   *
108
   * @param $fields
109
   * An array of fields. The key is an identifier used to later find the
110
   * field alias used. The value is either a string in which case it's
111
   * assumed to be a field on this handler's table; or it's an array in the
112
   * form of
113
   * @code array('table' => $tablename, 'field' => $fieldname) @endcode
124
   * @param array $fields
125
   *   An array of fields. The key is an identifier used to later find the field
126
   *   alias used. The value is either a string in which case it's assumed to be
127
   *   a field on this handler's table; or it's an array in the form of
128
   *   @code array('table' => $tablename, 'field' => $fieldname) @endcode
114 129
   */
115
  function add_additional_fields($fields = NULL) {
130
  public function add_additional_fields($fields = NULL) {
116 131
    if (!isset($fields)) {
117
      // notice check
132
      // Notice check.
118 133
      if (empty($this->additional_fields)) {
119 134
        return;
120 135
      }
......
139 154
          }
140 155

  
141 156
          if (empty($table_alias)) {
142
            debug(t('Handler @handler tried to add additional_field @identifier but @table could not be added!', array('@handler' => $this->definition['handler'], '@identifier' => $identifier, '@table' => $info['table'])));
157
            $t_args = array(
158
              '@handler' => $this->definition['handler'],
159
              '@identifier' => $identifier,
160
              '@table' => $info['table'],
161
            );
162
            debug(t('Handler @handler tried to add additional_field @identifier but @table could not be added!', $t_args));
143 163
            $this->aliases[$identifier] = 'broken';
144 164
            continue;
145 165
          }
......
162 182
  /**
163 183
   * Called to determine what to tell the clicksorter.
164 184
   */
165
  function click_sort($order) {
185
  public function click_sort($order) {
166 186
    if (isset($this->field_alias)) {
167 187
      // Since fields should always have themselves already added, just
168 188
      // add a sort on the field.
......
174 194
  /**
175 195
   * Determine if this field is click sortable.
176 196
   */
177
  function click_sortable() {
197
  public function click_sortable() {
178 198
    return !empty($this->definition['click sortable']);
179 199
  }
180 200

  
181 201
  /**
182 202
   * Get this field's label.
183 203
   */
184
  function label() {
204
  public function label() {
185 205
    if (!isset($this->options['label'])) {
186 206
      return '';
187 207
    }
......
191 211
  /**
192 212
   * Return an HTML element based upon the field's element type.
193 213
   */
194
  function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
214
  public function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
195 215
    if ($none_supported) {
196 216
      if ($this->options['element_type'] === '0') {
197 217
        return '';
......
219 239
  /**
220 240
   * Return an HTML element for the label based upon the field's element type.
221 241
   */
222
  function element_label_type($none_supported = FALSE, $default_empty = FALSE) {
242
  public function element_label_type($none_supported = FALSE, $default_empty = FALSE) {
223 243
    if ($none_supported) {
224 244
      if ($this->options['element_label_type'] === '0') {
225 245
        return '';
......
239 259
  /**
240 260
   * Return an HTML element for the wrapper based upon the field's element type.
241 261
   */
242
  function element_wrapper_type($none_supported = FALSE, $default_empty = FALSE) {
262
  public function element_wrapper_type($none_supported = FALSE, $default_empty = FALSE) {
243 263
    if ($none_supported) {
244 264
      if ($this->options['element_wrapper_type'] === '0') {
245 265
        return 0;
......
259 279
  /**
260 280
   * Provide a list of elements valid for field HTML.
261 281
   *
262
   * This function can be overridden by fields that want more or fewer
263
   * elements available, though this seems like it would be an incredibly
264
   * rare occurence.
282
   * This function can be overridden by fields that want more or fewer elements
283
   * available, though this seems like it would be an incredibly rare occurence.
265 284
   */
266
  function get_elements() {
285
  public function get_elements() {
267 286
    static $elements = NULL;
268 287
    if (!isset($elements)) {
269 288
      $elements = variable_get('views_field_rewrite_elements', array(
......
289 308
  /**
290 309
   * Return the class of the field.
291 310
   */
292
  function element_classes($row_index = NULL) {
311
  public function element_classes($row_index = NULL) {
293 312
    $classes = explode(' ', $this->options['element_class']);
294 313
    foreach ($classes as &$class) {
295 314
      $class = $this->tokenize_value($class, $row_index);
......
304 323
   * This function actually figures out which field was last and uses its
305 324
   * tokens so they will all be available.
306 325
   */
307
  function tokenize_value($value, $row_index = NULL) {
326
  public function tokenize_value($value, $row_index = NULL) {
308 327
    if (strpos($value, '[') !== FALSE || strpos($value, '!') !== FALSE || strpos($value, '%') !== FALSE) {
309 328
      $fake_item = array(
310 329
        'alter_text' => TRUE,
311 330
        'text' => $value,
312 331
      );
313 332

  
314
      // Use isset() because empty() will trigger on 0 and 0 is
315
      // the first row.
333
      // Use isset() because empty() will trigger on 0 and 0 is the first row.
316 334
      if (isset($row_index) && isset($this->view->style_plugin->render_tokens[$row_index])) {
317 335
        $tokens = $this->view->style_plugin->render_tokens[$row_index];
318 336
      }
......
339 357
  /**
340 358
   * Return the class of the field's label.
341 359
   */
342
  function element_label_classes($row_index = NULL) {
360
  public function element_label_classes($row_index = NULL) {
343 361
    $classes = explode(' ', $this->options['element_label_class']);
344 362
    foreach ($classes as &$class) {
345 363
      $class = $this->tokenize_value($class, $row_index);
......
351 369
  /**
352 370
   * Return the class of the field's wrapper.
353 371
   */
354
  function element_wrapper_classes($row_index = NULL) {
372
  public function element_wrapper_classes($row_index = NULL) {
355 373
    $classes = explode(' ', $this->options['element_wrapper_class']);
356 374
    foreach ($classes as &$class) {
357 375
      $class = $this->tokenize_value($class, $row_index);
......
366 384
   * This api exists so that other modules can easy set the values of the field
367 385
   * without having the need to change the render method as well.
368 386
   *
369
   * @param $values
387
   * @param object $values
370 388
   *   An object containing all retrieved values.
371
   * @param $field
389
   * @param string $field
372 390
   *   Optional name of the field where the value is stored.
373 391
   */
374
  function get_value($values, $field = NULL) {
392
  public function get_value($values, $field = NULL) {
375 393
    $alias = isset($field) ? $this->aliases[$field] : $this->field_alias;
376 394
    if (isset($values->{$alias})) {
377 395
      return $values->{$alias};
......
383 401
   * by in the style settings.
384 402
   *
385 403
   * @return bool
386
   *  TRUE if this field handler is groupable, otherwise FALSE.
404
   *   TRUE if this field handler is groupable, otherwise FALSE.
387 405
   */
388
  function use_string_group_by() {
406
  public function use_string_group_by() {
389 407
    return TRUE;
390 408
  }
391 409

  
392
  function option_definition() {
410
  /**
411
   * {@inheritdoc}
412
   */
413
  public function option_definition() {
393 414
    $options = parent::option_definition();
394 415

  
395 416
    $options['label'] = array('default' => $this->definition['title'], 'translatable' => TRUE);
......
447 468
  /**
448 469
   * Performs some cleanup tasks on the options array before saving it.
449 470
   */
450
  function options_submit(&$form, &$form_state) {
471
  public function options_submit(&$form, &$form_state) {
451 472
    $options = &$form_state['values']['options'];
452
    $types = array('element_type', 'element_label_type', 'element_wrapper_type');
453
    $classes = array_combine(array('element_class', 'element_label_class', 'element_wrapper_class'), $types);
473
    $types = array(
474
      'element_type',
475
      'element_label_type',
476
      'element_wrapper_type',
477
    );
478
    $base_types = array(
479
      'element_class',
480
      'element_label_class',
481
      'element_wrapper_class',
482
    );
483
    $classes = array_combine($base_types, $types);
454 484

  
455 485
    foreach ($types as $type) {
456 486
      if (!$options[$type . '_enable']) {
......
471 501
  }
472 502

  
473 503
  /**
474
   * Default options form that provides the label widget that all fields
475
   * should have.
504
   * Default options form provides the label widget that all fields should have.
476 505
   */
477
  function options_form(&$form, &$form_state) {
506
  public function options_form(&$form, &$form_state) {
478 507
    parent::options_form($form, $form_state);
479 508

  
480 509
    $label = $this->label();
......
581 610
      '#type' => 'checkbox',
582 611
      '#title' => t('Create a CSS class'),
583 612
      '#dependency' => array(
584
        'edit-options-element-label-type-enable' => array(1)
613
        'edit-options-element-label-type-enable' => array(1),
585 614
      ),
586 615
      '#default_value' => !empty($this->options['element_label_class']) || (string) $this->options['element_label_class'] == '0',
587 616
      '#fieldset' => 'style_settings',
......
703 732
        '#title' => t('Replace spaces with dashes'),
704 733
        '#default_value' => $this->options['alter']['replace_spaces'],
705 734
        '#dependency' => array(
706
          'edit-options-alter-make-link' => array(1)
735
          'edit-options-alter-make-link' => array(1),
707 736
        ),
708 737
      );
709 738
      $form['alter']['external'] = array(
......
722 751
        '#dependency' => array(
723 752
          'edit-options-alter-make-link' => array(1),
724 753
        ),
725
       '#options' => array(
754
        '#options' => array(
726 755
          'none' => t('No transform'),
727 756
          'upper' => t('Upper case'),
728 757
          'lower' => t('Lower case'),
......
796 825
          break;
797 826
        }
798 827
      }
799
      $count = 0; // This lets us prepare the key as we want it printed.
828
      // This lets us prepare the key as we want it printed.
829
      $count = 0;
800 830
      foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) {
801 831
        $options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->ui_name()));
802 832
        $options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name()));
......
819 849
            $output .= theme('item_list',
820 850
              array(
821 851
                'items' => $items,
822
                'type' => $type
852
                'type' => $type,
823 853
              ));
824 854
          }
825 855
        }
826 856
      }
827 857
      // This construct uses 'hidden' and not markup because process doesn't
828
      // run. It also has an extra div because the dependency wants to hide
829
      // the parent in situations like this, so we need a second div to
830
      // make this work.
858
      // run. It also has an extra div because the dependency wants to hide the
859
      // parent in situations like this, so we need a second div to make this
860
      // work.
831 861
      $form['alter']['help'] = array(
832 862
        '#type' => 'fieldset',
833 863
        '#title' => t('Replacement patterns'),
......
997 1027
  /**
998 1028
   * Provide extra data to the administration form
999 1029
   */
1000
  function admin_summary() {
1030
  public function admin_summary() {
1001 1031
    return $this->label();
1002 1032
  }
1003 1033

  
1004 1034
  /**
1005 1035
   * Run before any fields are rendered.
1006 1036
   *
1007
   * This gives the handlers some time to set up before any handler has
1008
   * been rendered.
1037
   * This gives the handlers some time to set up before any handler has been
1038
   * rendered.
1009 1039
   *
1010
   * @param $values
1040
   * @param array $values
1011 1041
   *   An array of all objects returned from the query.
1012 1042
   */
1013
  function pre_render(&$values) { }
1043
  public function pre_render(&$values) {
1044
  }
1014 1045

  
1015 1046
  /**
1016 1047
   * Render the field.
1017 1048
   *
1018
   * @param $values
1049
   * @param array $values
1019 1050
   *   The values retrieved from the database.
1020 1051
   */
1021
  function render($values) {
1052
  public function render($values) {
1022 1053
    $value = $this->get_value($values);
1023 1054
    return $this->sanitize_value($value);
1024 1055
  }
......
1029 1060
   * This renders a field normally, then decides if render-as-link and
1030 1061
   * text-replacement rendering is necessary.
1031 1062
   */
1032
  function advanced_render($values) {
1063
  public function advanced_render($values) {
1033 1064
    if ($this->allow_advanced_render() && method_exists($this, 'render_item')) {
1034 1065
      $raw_items = $this->get_items($values);
1035 1066
      // If there are no items, set the original value to NULL.
......
1094 1125
  /**
1095 1126
   * Checks if a field value is empty.
1096 1127
   *
1097
   * @param $value
1128
   * @param mixed $value
1098 1129
   *   The field value.
1099 1130
   * @param bool $empty_zero
1100 1131
   *   Whether or not this field is configured to consider 0 as empty.
......
1102 1133
   *   Whether or not to use empty() to check the value.
1103 1134
   *
1104 1135
   * @return bool
1105
   * TRUE if the value is considered empty, FALSE otherwise.
1136
   *   TRUE if the value is considered empty, FALSE otherwise.
1106 1137
   */
1107
  function is_value_empty($value, $empty_zero, $no_skip_empty = TRUE) {
1138
  public function is_value_empty($value, $empty_zero, $no_skip_empty = TRUE) {
1108 1139
    if (!isset($value)) {
1109 1140
      $empty = TRUE;
1110 1141
    }
......
1124 1155
   * This is separated out as some fields may render lists, and this allows
1125 1156
   * each item to be handled individually.
1126 1157
   */
1127
  function render_text($alter) {
1158
  public function render_text($alter) {
1128 1159
    $value = $this->last_render;
1129 1160

  
1130 1161
    if (!empty($alter['alter_text']) && $alter['text'] !== '') {
......
1139 1170
    // Check if there should be no further rewrite for empty values.
1140 1171
    $no_rewrite_for_empty = $this->options['hide_alter_empty'] && $this->is_value_empty($this->original_value, $this->options['empty_zero']);
1141 1172

  
1142
    // Check whether the value is empty and return nothing, so the field isn't rendered.
1143
    // First check whether the field should be hidden if the value(hide_alter_empty = TRUE) /the rewrite is empty (hide_alter_empty = FALSE).
1144
    // For numeric values you can specify whether "0"/0 should be empty.
1173
    // Check whether the value is empty and return nothing, so the field isn't
1174
    // rendered. First check whether the field should be hidden if the
1175
    // value(hide_alter_empty = TRUE) /the rewrite is empty (hide_alter_empty =
1176
    // FALSE). For numeric values you can specify whether "0"/0 should be empty.
1145 1177
    if ((($this->options['hide_empty'] && empty($value))
1146 1178
        || ($alter['phase'] != VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY && $no_rewrite_for_empty))
1147 1179
      && $this->is_value_empty($value, $this->options['empty_zero'], FALSE)) {
......
1169 1201
        $more_link_path = $this->options['alter']['more_link_path'];
1170 1202
        $more_link_path = strip_tags(decode_entities(strtr($more_link_path, $tokens)));
1171 1203

  
1172
        // Take sure that paths which was runned through url() does work as well.
1204
        // Take sure that paths which was runned through url() does work as
1205
        // well.
1173 1206
        $base_path = base_path();
1174 1207
        // Checks whether the path starts with the base_path.
1175 1208
        if (strpos($more_link_path, $base_path) === 0) {
......
1189 1222

  
1190 1223
    if (!empty($alter['make_link']) && !empty($alter['path'])) {
1191 1224
      if (!isset($tokens)) {
1192
       $tokens = $this->get_render_tokens($alter);
1225
        $tokens = $this->get_render_tokens($alter);
1193 1226
      }
1194 1227
      $value = $this->render_as_link($alter, $value, $tokens);
1195 1228
    }
......
1200 1233
  /**
1201 1234
   * Render this field as altered text, from a fieldset set by the user.
1202 1235
   */
1203
  function render_altered($alter, $tokens) {
1236
  public function render_altered($alter, $tokens) {
1204 1237
    // Filter this right away as our substitutions are already sanitized.
1205 1238
    $value = filter_xss_admin($alter['text']);
1206 1239
    $value = strtr($value, $tokens);
......
1211 1244
  /**
1212 1245
   * Trim the field down to the specified length.
1213 1246
   */
1214
  function render_trim_text($alter, $value) {
1247
  public function render_trim_text($alter, $value) {
1215 1248
    if (!empty($alter['strip_tags'])) {
1216 1249
      // NOTE: It's possible that some external fields might override the
1217
      // element type so if someone from, say, CCK runs into a bug here,
1218
      // this may be why =)
1250
      // element type so if someone from, say, CCK runs into a bug here, this
1251
      // may be why =)
1219 1252
      $this->definition['element type'] = 'span';
1220 1253
    }
1221 1254
    return views_trim_text($alter, $value);
1222 1255
  }
1223 1256

  
1224 1257
  /**
1225
   * Render this field as a link, with the info from a fieldset set by
1226
   * the user.
1258
   * Render this field as a link, with info from a fieldset set by the user.
1227 1259
   */
1228
  function render_as_link($alter, $text, $tokens) {
1260
  public function render_as_link($alter, $text, $tokens) {
1229 1261
    $value = '';
1230 1262

  
1231 1263
    if (!empty($alter['prefix'])) {
......
1243 1275

  
1244 1276
    // strip_tags() removes <front>, so check whether its different to front.
1245 1277
    if ($path != '<front>') {
1246
      // Use strip tags as there should never be HTML in the path.
1247
      // However, we need to preserve special characters like " that
1248
      // were removed by check_plain().
1278
      // Use strip tags as there should never be HTML in the path. However, we
1279
      // need to preserve special characters like " that were removed by
1280
      // check_plain().
1249 1281
      $path = strip_tags(decode_entities(strtr($path, $tokens)));
1250 1282

  
1251 1283
      if (!empty($alter['path_case']) && $alter['path_case'] != 'none') {
......
1266 1298
    }
1267 1299

  
1268 1300
    // If the path is empty do not build a link around the given text and return
1269
    // it as is.
1270
    // http://www.example.com URLs will not have a $url['path'], so check host as well.
1301
    // it as is. http://www.example.com URLs will not have a $url['path'], so
1302
    // check host as well.
1271 1303
    if (empty($url['path']) && empty($url['host']) && empty($url['fragment'])) {
1272 1304
      return $text;
1273 1305
    }
1274 1306

  
1275 1307
    // If no scheme is provided in the $path, assign the default 'http://'.
1276
    // This allows a url of 'www.example.com' to be converted to 'http://www.example.com'.
1277
    // Only do this on for external URLs.
1278
    if ($alter['external']){
1308
    // This allows a url of 'www.example.com' to be converted to
1309
    // 'http://www.example.com'. Only do this on for external URLs.
1310
    if ($alter['external']) {
1279 1311
      if (!isset($url['scheme'])) {
1280 1312
        // There is no scheme, add the default 'http://' to the $path.
1281 1313
        $path = "http://$path";
......
1320 1352
      $options['attributes']['rel'] = $rel;
1321 1353
    }
1322 1354

  
1323
    $target = check_plain(trim(strtr($alter['target'],$tokens)));
1355
    $target = check_plain(trim(strtr($alter['target'], $tokens)));
1324 1356
    if (!empty($target)) {
1325 1357
      $options['attributes']['target'] = $target;
1326 1358
    }
1327 1359

  
1328
    // Allow the addition of arbitrary attributes to links. Additional attributes
1329
    // currently can only be altered in preprocessors and not within the UI.
1360
    // Allow the addition of arbitrary attributes to links. Additional
1361
    // attributes currently can only be altered in preprocessors and not within
1362
    // the UI.
1330 1363
    if (isset($alter['link_attributes']) && is_array($alter['link_attributes'])) {
1331 1364
      foreach ($alter['link_attributes'] as $key => $attribute) {
1332 1365
        if (!isset($options['attributes'][$key])) {
......
1375 1408
  /**
1376 1409
   * Get the 'render' tokens to use for advanced rendering.
1377 1410
   *
1378
   * This runs through all of the fields and arguments that
1379
   * are available and gets their values. This will then be
1380
   * used in one giant str_replace().
1411
   * This runs through all of the fields and arguments that are available and
1412
   * gets their values. This will then be used in one giant str_replace().
1381 1413
   */
1382
  function get_render_tokens($item) {
1414
  public function get_render_tokens($item) {
1383 1415
    $tokens = array();
1384 1416
    if (!empty($this->view->build_info['substitutions'])) {
1385 1417
      $tokens = $this->view->build_info['substitutions'];
......
1391 1423
        $tokens[$token] = '';
1392 1424
      }
1393 1425

  
1394
      // Use strip tags as there should never be HTML in the path.
1395
      // However, we need to preserve special characters like " that
1396
      // were removed by check_plain().
1426
      // Use strip tags as there should never be HTML in the path. However, we
1427
      // need to preserve special characters like " that were removed by
1428
      // check_plain().
1397 1429
      $tokens['!' . $count] = isset($this->view->args[$count - 1]) ? strip_tags(decode_entities($this->view->args[$count - 1])) : '';
1398 1430
    }
1399 1431

  
......
1450 1482
   *     '%bar_b_c' => 'value'
1451 1483
   *   );
1452 1484
   *
1453
   * @param $array
1485
   * @param array $array
1454 1486
   *   An array of values.
1455
   *
1456
   * @param $parent_keys
1487
   * @param array $parent_keys
1457 1488
   *   An array of parent keys. This will represent the array depth.
1458 1489
   *
1459
   * @return
1460
   *   An array of available tokens, with nested keys representative of the array structure.
1490
   * @return array
1491
   *   An array of available tokens, with nested keys representative of the
1492
   *   array structure.
1461 1493
   */
1462
  function get_token_values_recursive(array $array, array $parent_keys = array()) {
1494
  public function get_token_values_recursive(array $array, array $parent_keys = array()) {
1463 1495
    $tokens = array();
1464 1496

  
1465 1497
    foreach ($array as $param => $val) {
1466 1498
      if (is_array($val)) {
1467
         // Copy parent_keys array, so we don't afect other elements of this iteration.
1468
         $child_parent_keys = $parent_keys;
1469
         $child_parent_keys[] = $param;
1470
         // Get the child tokens.
1471
         $child_tokens = $this->get_token_values_recursive($val, $child_parent_keys);
1472
         // Add them to the current tokens array.
1473
         $tokens += $child_tokens;
1499
        // Copy parent_keys array, so we don't afect other elements of this
1500
        // iteration.
1501
        $child_parent_keys = $parent_keys;
1502
        $child_parent_keys[] = $param;
1503
        // Get the child tokens.
1504
        $child_tokens = $this->get_token_values_recursive($val, $child_parent_keys);
1505
        // Add them to the current tokens array.
1506
        $tokens += $child_tokens;
1474 1507
      }
1475 1508
      else {
1476 1509
        // Create a token key based on array element structure.
......
1485 1518
  /**
1486 1519
   * Add any special tokens this field might use for itself.
1487 1520
   *
1488
   * This method is intended to be overridden by items that generate
1489
   * fields as a list. For example, the field that displays all terms
1490
   * on a node might have tokens for the tid and the term.
1521
   * This method is intended to be overridden by items that generate fields as a
1522
   * list. For example, the field that displays all terms on a node might have
1523
   * tokens for the tid and the term.
1491 1524
   *
1492
   * By convention, tokens should follow the format of [token-subtoken]
1493
   * where token is the field ID and subtoken is the field. If the
1494
   * field ID is terms, then the tokens might be [terms-tid] and [terms-name].
1525
   * By convention, tokens should follow the format of [token-subtoken] where
1526
   * token is the field ID and subtoken is the field. If the field ID is terms,
1527
   * then the tokens might be [terms-tid] and [terms-name].
1495 1528
   */
1496
  function add_self_tokens(&$tokens, $item) { }
1529
  public function add_self_tokens(&$tokens, $item) {
1530
  }
1497 1531

  
1498 1532
  /**
1499 1533
   * Document any special tokens this field might use for itself.
1500 1534
   *
1501 1535
   * @see add_self_tokens()
1502 1536
   */
1503
  function document_self_tokens(&$tokens) { }
1537
  public function document_self_tokens(&$tokens) {
1538
  }
1504 1539

  
1505 1540
  /**
1506
   * Call out to the theme() function, which probably just calls render() but
1507
   * allows sites to override output fairly easily.
1541
   * Call out to the theme() function.
1542
   *
1543
   * It probably just calls render() but allows sites to override output fairly
1544
   * easily.
1508 1545
   */
1509
  function theme($values) {
1546
  public function theme($values) {
1510 1547
    return theme($this->theme_functions(),
1511 1548
      array(
1512 1549
        'view' => $this->view,
1513 1550
        'field' => $this,
1514
        'row' => $values
1551
        'row' => $values,
1515 1552
      ));
1516 1553
  }
1517 1554

  
1518
  function theme_functions() {
1555
  /**
1556
   * Build a list of suitable theme functions for this view.
1557
   */
1558
  public function theme_functions() {
1519 1559
    $themes = array();
1520 1560
    $hook = 'views_view_field';
1521 1561

  
1522 1562
    $display = $this->view->display[$this->view->current_display];
1523 1563

  
1524 1564
    if (!empty($display)) {
1525
      $themes[] = $hook . '__' . $this->view->name  . '__' . $display->id . '__' . $this->options['id'];
1526
      $themes[] = $hook . '__' . $this->view->name  . '__' . $display->id;
1565
      $themes[] = $hook . '__' . $this->view->name . '__' . $display->id . '__' . $this->options['id'];
1566
      $themes[] = $hook . '__' . $this->view->name . '__' . $display->id;
1527 1567
      $themes[] = $hook . '__' . $display->id . '__' . $this->options['id'];
1528 1568
      $themes[] = $hook . '__' . $display->id;
1529 1569
      if ($display->id != $display->display_plugin) {
1530
        $themes[] = $hook . '__' . $this->view->name  . '__' . $display->display_plugin . '__' . $this->options['id'];
1531
        $themes[] = $hook . '__' . $this->view->name  . '__' . $display->display_plugin;
1570
        $themes[] = $hook . '__' . $this->view->name . '__' . $display->display_plugin . '__' . $this->options['id'];
1571
        $themes[] = $hook . '__' . $this->view->name . '__' . $display->display_plugin;
1532 1572
        $themes[] = $hook . '__' . $display->display_plugin . '__' . $this->options['id'];
1533 1573
        $themes[] = $hook . '__' . $display->display_plugin;
1534 1574
      }
......
1541 1581
    return $themes;
1542 1582
  }
1543 1583

  
1544
  function ui_name($short = FALSE) {
1584
  /**
1585
   * {@inheritdoc}
1586
   */
1587
  public function ui_name($short = FALSE) {
1545 1588
    return $this->get_field(parent::ui_name($short));
1546 1589
  }
1590

  
1547 1591
}
1548 1592

  
1549 1593
/**
......
1552 1596
 * @ingroup views_field_handlers
1553 1597
 */
1554 1598
class views_handler_field_broken extends views_handler_field {
1555
  function ui_name($short = FALSE) {
1599

  
1600
  /**
1601
   * {@inheritdoc}
1602
   */
1603
  public function ui_name($short = FALSE) {
1556 1604
    return t('Broken/missing handler');
1557 1605
  }
1558 1606

  
1559
  function ensure_my_table() { /* No table to ensure! */ }
1560
  function query($group_by = FALSE) { /* No query to run */ }
1561
  function options_form(&$form, &$form_state) {
1607
  /**
1608
   * {@inheritdoc}
1609
   */
1610
  public function ensure_my_table() {
1611
    // No table to ensure!
1612
  }
1613

  
1614
  /**
1615
   * {@inheritdoc}
1616
   */
1617
  public function query($group_by = FALSE) {
1618
    // No query to run.
1619
  }
1620

  
1621
  /**
1622
   * {@inheritdoc}
1623
   */
1624
  public function options_form(&$form, &$form_state) {
1562 1625
    $form['markup'] = array(
1563 1626
      '#markup' => '<div class="form-item description">' . t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.') . '</div>',
1564 1627
    );
1565 1628
  }
1566 1629

  
1567 1630
  /**
1568
   * Determine if the handler is considered 'broken'
1631
   * {@inheritdoc}
1569 1632
   */
1570
  function broken() { return TRUE; }
1633
  public function broken() {
1634
    return TRUE;
1635
  }
1636

  
1571 1637
}
1572 1638

  
1573 1639
/**
......
1576 1642
 * @ingroup views_field_handlers
1577 1643
 */
1578 1644
class views_handler_field_file_size extends views_handler_field {
1579
  function option_definition() {
1645

  
1646
  /**
1647
   * {@inheritdoc}
1648
   */
1649
  public function option_definition() {
1580 1650
    $options = parent::option_definition();
1581 1651

  
1582 1652
    $options['file_size_display'] = array('default' => 'formatted');
......
1584 1654
    return $options;
1585 1655
  }
1586 1656

  
1587
  function options_form(&$form, &$form_state) {
1657
  /**
1658
   * {@inheritdoc}
1659
   */
1660
  public function options_form(&$form, &$form_state) {
1588 1661
    parent::options_form($form, $form_state);
1589 1662
    $form['file_size_display'] = array(
1590 1663
      '#title' => t('File size display'),
......
1596 1669
    );
1597 1670
  }
1598 1671

  
1599
  function render($values) {
1672
  /**
1673
   * {@inheritdoc}
1674
   */
1675
  public function render($values) {
1600 1676
    $value = $this->get_value($values);
1601 1677
    if ($value) {
1602 1678
      switch ($this->options['file_size_display']) {
......
1611 1687
      return '';
1612 1688
    }
1613 1689
  }
1690

  
1614 1691
}
1615 1692

  
1616 1693
/**
......
1619 1696
 * @ingroup views_field_handlers
1620 1697
 */
1621 1698
class views_handler_field_xss extends views_handler_field {
1622
  function render($values) {
1699

  
1700
  /**
1701
   * {@inheritdoc}
1702
   */
1703
  public function render($values) {
1623 1704
    $value = $this->get_value($values);
1624 1705
    return $this->sanitize_value($value, 'xss');
1625 1706
  }
1707

  
1626 1708
}
1627 1709

  
1628 1710
/**

Formats disponibles : Unified diff