~spreadubuntu/spreadubuntu/devel-drupal6

« back to all changes in this revision

Viewing changes to modules/views/handlers/views_handler_field.inc

  • Committer: ruben
  • Date: 2009-06-08 09:38:49 UTC
  • Revision ID: ruben@captive-20090608093849-s1qtsyctv2vwp1x1
SpreadUbuntu moving to Drupal6. Based on ubuntu-drupal theme and adding our modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
// $Id: views_handler_field.inc,v 1.14 2009/04/08 05:23:56 merlinofchaos Exp $
 
3
/**
 
4
 * @defgroup views_field_handlers Views' field handlers
 
5
 * @{
 
6
 * Handlers to tell Views how to build and display fields.
 
7
 *
 
8
 */
 
9
 
 
10
/**
 
11
 * Base field handler that has no options and renders an unformatted field.
 
12
 *
 
13
 * Definition terms:
 
14
 * - additional fields: An array of fields that should be added to the query
 
15
 *                      for some purpose. The array is in the form of:
 
16
 *                      array('identifier' => array('table' => tablename,
 
17
 *                      'field' => fieldname); as many fields as are necessary
 
18
 *                      may be in this array.
 
19
 * - click sortable: If TRUE, this field may be click sorted.
 
20
 */
 
21
class views_handler_field extends views_handler {
 
22
  var $field_alias = 'unknown';
 
23
  var $aliases = array();
 
24
 
 
25
  /**
 
26
   * Construct a new field handler.
 
27
   */
 
28
  function construct() {
 
29
    parent::construct();
 
30
 
 
31
    $this->additional_fields = array();
 
32
    if (!empty($this->definition['additional fields'])) {
 
33
      $this->additional_fields = $this->definition['additional fields'];
 
34
    }
 
35
 
 
36
    if (!isset($this->options['exclude'])) {
 
37
      $this->options['exclude'] = '';
 
38
    }
 
39
  }
 
40
 
 
41
  /**
 
42
   * Determine if this field can allow advanced rendering.
 
43
   *
 
44
   * Fields can set this to FALSE if they do not wish to allow
 
45
   * token based rewriting or link-making.
 
46
   */
 
47
  function allow_advanced_render() {
 
48
    return TRUE;
 
49
  }
 
50
 
 
51
  function init(&$view, $options) {
 
52
    parent::init($view, $options);
 
53
 
 
54
    $this->options += array(
 
55
      'exclude' => FALSE,
 
56
    );
 
57
  }
 
58
 
 
59
  /**
 
60
   * Called to add the field to a query.
 
61
   */
 
62
  function query() {
 
63
    $this->ensure_my_table();
 
64
    // Add the field.
 
65
    $this->field_alias = $this->query->add_field($this->table_alias, $this->real_field);
 
66
 
 
67
    $this->add_additional_fields();
 
68
  }
 
69
 
 
70
  /**
 
71
   * Add 'additional' fields to the query.
 
72
   *
 
73
   * @param $fields
 
74
   * An array of fields. The key is an identifier used to later find the
 
75
   * field alias used. The value is either a string in which case it's
 
76
   * assumed to be a field on this handler's table; or it's an array in the
 
77
   * form of
 
78
   * @code array('table' => $tablename, 'field' => $fieldname) @endcode
 
79
   */
 
80
  function add_additional_fields($fields = NULL) {
 
81
    if (!isset($fields)) {
 
82
      // notice check
 
83
      if (empty($this->additional_fields)) {
 
84
        return;
 
85
      }
 
86
      $fields = $this->additional_fields;
 
87
    }
 
88
    if (!empty($fields) && is_array($fields)) {
 
89
      foreach ($fields as $identifier => $info) {
 
90
        if (is_array($info)) {
 
91
          if (isset($info['table'])) {
 
92
            $table_alias = $this->query->ensure_table($info['table'], $this->relationship);
 
93
          }
 
94
          else {
 
95
            $table_alias = $this->table_alias;
 
96
          }
 
97
          $this->aliases[$identifier] = $this->query->add_field($table_alias, $info['field']);
 
98
        }
 
99
        else {
 
100
          $this->aliases[$info] = $this->query->add_field($this->table_alias, $info);
 
101
        }
 
102
      }
 
103
    }
 
104
  }
 
105
 
 
106
  /**
 
107
   * Called to determine what to tell the clicksorter.
 
108
   */
 
109
  function click_sort($order) {
 
110
    $this->query->add_orderby($this->table, $this->field, $order, $this->field_alias);
 
111
  }
 
112
 
 
113
  /**
 
114
   * Determine if this field is click sortable.
 
115
   */
 
116
  function click_sortable() {
 
117
    return !empty($this->definition['click sortable']);
 
118
  }
 
119
 
 
120
  /**
 
121
   * Get this field's label.
 
122
   */
 
123
  function label() {
 
124
    if (!isset($this->options['label'])) {
 
125
      return '';
 
126
    }
 
127
    return $this->options['label'];
 
128
  }
 
129
 
 
130
  /**
 
131
   * Return DIV or SPAN based upon the field's element type.
 
132
   */
 
133
  function element_type() {
 
134
    if (isset($this->definition['element type'])) {
 
135
      return $this->definition['element type'];
 
136
    }
 
137
 
 
138
    return 'span';
 
139
  }
 
140
 
 
141
  function option_definition() {
 
142
    $options = parent::option_definition();
 
143
 
 
144
    $options['label'] = array('default' => $this->definition['title'], 'translatable' => TRUE);
 
145
    $options['alter'] = array(
 
146
      'contains' => array(
 
147
        'alter_text' => array('default' => FALSE),
 
148
        'text' => array('default' => '', 'translatable' => TRUE),
 
149
        'make_link' => array('default' => FALSE),
 
150
        'path' => array('default' => '', 'translatable' => TRUE),
 
151
        'alt' => array('default' => '', 'translatable' => TRUE),
 
152
        'prefix' => array('default' => '', 'translatable' => TRUE),
 
153
        'suffix' => array('default' => '', 'translatable' => TRUE),
 
154
        'trim' => array('default' => FALSE),
 
155
        'max_length' => array('default' => ''),
 
156
        'word_boundary' => array('default' => TRUE),
 
157
        'ellipsis' => array('default' => TRUE),
 
158
        'strip_tags' => array('default' => FALSE),
 
159
        'html' => array('default' => FALSE),
 
160
      ),
 
161
    );
 
162
 
 
163
    return $options;
 
164
  }
 
165
 
 
166
  /**
 
167
   * Default options form that provides the label widget that all fields
 
168
   * should have.
 
169
   */
 
170
  function options_form(&$form, &$form_state) {
 
171
    $form['label'] = array(
 
172
      '#type' => 'textfield',
 
173
      '#title' => t('Label'),
 
174
      '#default_value' => isset($this->options['label']) ? $this->options['label'] : '',
 
175
      '#description' => t('The label for this field that will be displayed to end users if the style requires it.'),
 
176
    );
 
177
    $form['exclude'] = array(
 
178
      '#type' => 'checkbox',
 
179
      '#title' => t('Exclude from display'),
 
180
      '#default_value' => $this->options['exclude'],
 
181
      '#description' => t('Check this box to not display this field, but still load it in the view.  Use this option to not show a grouping field in each record, or when doing advanced theming.'),
 
182
    );
 
183
 
 
184
    if ($this->allow_advanced_render()) {
 
185
      $form['alter']['#tree'] = TRUE;
 
186
      $form['alter']['alter_text'] = array(
 
187
        '#type' => 'checkbox',
 
188
        '#title' => t('Rewrite the output of this field'),
 
189
        '#description' => t('If checked, you can alter the output of this field by specifying a string of text with replacement tokens that can use any existing field output.'),
 
190
        '#default_value' => $this->options['alter']['alter_text'],
 
191
      );
 
192
 
 
193
      $form['alter']['text'] = array(
 
194
        '#title' => t('Text'),
 
195
        '#type' => 'textarea',
 
196
        '#default_value' => $this->options['alter']['text'],
 
197
        '#description' => t('The text to display for this field. You may include HTML. You may enter data from this view as per the "Replacement patterns" below.'),
 
198
        '#process' => array('views_process_dependency'),
 
199
        '#dependency' => array(
 
200
          'edit-options-alter-alter-text' => array(1)
 
201
        ),
 
202
      );
 
203
 
 
204
      $form['alter']['make_link'] = array(
 
205
        '#type' => 'checkbox',
 
206
        '#title' => t('Output this field as a link'),
 
207
        '#description' => t('If checked, this field will be made into a link. The destination must be given below.'),
 
208
        '#default_value' => $this->options['alter']['make_link'],
 
209
      );
 
210
      $form['alter']['path'] = array(
 
211
        '#title' => t('Link path'),
 
212
        '#type' => 'textfield',
 
213
        '#default_value' => $this->options['alter']['path'],
 
214
        '#description' => t('The Drupal path or absolute URL for this link. You may enter data from this view as per the "Replacement patterns" below.'),
 
215
        '#process' => array('views_process_dependency'),
 
216
        '#dependency' => array(
 
217
          'edit-options-alter-make-link' => array(1)
 
218
        ),
 
219
      );
 
220
      $form['alter']['alt'] = array(
 
221
        '#title' => t('Alt text'),
 
222
        '#type' => 'textfield',
 
223
        '#default_value' => $this->options['alter']['alt'],
 
224
        '#description' => t('Text to place as "alt" text which most browsers display as a tooltip when hovering over the link.'),
 
225
        '#process' => array('views_process_dependency'),
 
226
        '#dependency' => array(
 
227
          'edit-options-alter-make-link' => array(1)
 
228
        ),
 
229
      );
 
230
      $form['alter']['prefix'] = array(
 
231
        '#title' => t('Prefix text'),
 
232
        '#type' => 'textfield',
 
233
        '#default_value' => $this->options['alter']['prefix'],
 
234
        '#description' => t('Any text to display before this link. You may include HTML.'),
 
235
        '#process' => array('views_process_dependency'),
 
236
        '#dependency' => array(
 
237
          'edit-options-alter-make-link' => array(1)
 
238
        ),
 
239
      );
 
240
      $form['alter']['suffix'] = array(
 
241
        '#title' => t('Suffix text'),
 
242
        '#type' => 'textfield',
 
243
        '#default_value' => $this->options['alter']['suffix'],
 
244
        '#description' => t('Any text to display after this link. You may include HTML.'),
 
245
        '#process' => array('views_process_dependency'),
 
246
        '#dependency' => array(
 
247
          'edit-options-alter-make-link' => array(1)
 
248
        ),
 
249
      );
 
250
 
 
251
      // Get a list of the available fields and arguments for token replacement.
 
252
      $options = array();
 
253
      foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) {
 
254
        $options[t('Fields')]["[$field]"] = $handler->ui_name();
 
255
        // We only use fields up to (and including) this one.
 
256
        if ($field == $this->options['id']) {
 
257
          break;
 
258
        }
 
259
      }
 
260
      $count = 0; // This lets us prepare the key as we want it printed.
 
261
      foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) {
 
262
        $options[t('Arguments')]['%' . ++$count] = $handler->ui_name();
 
263
      }
 
264
 
 
265
      // Default text.
 
266
      $output = t('<p>You must add some additional fields to this display before using this field. These fields may be marked as <em>Exclude from display</em> if you prefer. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.</p>');
 
267
      // We have some options, so make a list.
 
268
      if (!empty($options)) {
 
269
        $output = t('<p>The following substitution patterns are available for this display. Use the pattern shown on the left to display the value indicated on the right. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.</p>');
 
270
        foreach (array_keys($options) as $type) {
 
271
          if (!empty($options[$type])) {
 
272
            $items = array();
 
273
            $title = t(ucwords($type));
 
274
            foreach ($options[$type] as $key => $value) {
 
275
              $items[] = $key .' == '. $value;
 
276
            }
 
277
            $output .= theme('item_list', $items, $title);
 
278
          }
 
279
        }
 
280
      }
 
281
      // This construct uses 'hidden' and not markup because process doesn't
 
282
      // run. It also has an extra div because the dependency wants to hide
 
283
      // the parent in situations like this, so we need a second div to
 
284
      // make this work.
 
285
      $form['alter']['help'] = array(
 
286
        '#type' => 'hidden',
 
287
        '#id' => 'views-tokens-help',
 
288
        '#prefix' => '<div><fieldset id="views-tokens-help"><legend>' . t('Replacement patterns') . '</legend>' . $output . '</fieldset></div>',
 
289
        '#process' => array('views_process_dependency'),
 
290
        '#dependency' => array(
 
291
          'edit-options-alter-make-link' => array(1),
 
292
          'edit-options-alter-alter-text' => array(1),
 
293
        ),
 
294
      );
 
295
 
 
296
      $form['alter']['trim'] = array(
 
297
        '#type' => 'checkbox',
 
298
        '#title' => t('Trim this field to a maximum length'),
 
299
        '#description' => t('If checked, this field be trimmed to a maximum length in characters.'),
 
300
        '#default_value' => $this->options['alter']['trim'],
 
301
      );
 
302
 
 
303
      $form['alter']['max_length'] = array(
 
304
        '#title' => t('Maximum length'),
 
305
        '#type' => 'textfield',
 
306
        '#default_value' => $this->options['alter']['max_length'],
 
307
        '#description' => t('The maximum number of characters his field can be.'),
 
308
        '#process' => array('views_process_dependency'),
 
309
        '#dependency' => array(
 
310
          'edit-options-alter-trim' => array(1)
 
311
        ),
 
312
      );
 
313
 
 
314
      $form['alter']['word_boundary'] = array(
 
315
        '#type' => 'checkbox',
 
316
        '#title' => t('Trim only on a word boundary'),
 
317
        '#description' => t('If checked, this field be trimmed only on a word boundary. This is guaranteed to be the maximum characters stated or less. If there are no word boundaries this could trim a field to nothing.'),
 
318
        '#default_value' => $this->options['alter']['word_boundary'],
 
319
        '#process' => array('views_process_dependency'),
 
320
        '#dependency' => array(
 
321
          'edit-options-alter-trim' => array(1)
 
322
        ),
 
323
      );
 
324
 
 
325
      $form['alter']['ellipsis'] = array(
 
326
        '#type' => 'checkbox',
 
327
        '#title' => t('Add an ellipsis'),
 
328
        '#description' => t('If checked, a "..." will be added if a field was trimmed.'),
 
329
        '#default_value' => $this->options['alter']['ellipsis'],
 
330
        '#process' => array('views_process_dependency'),
 
331
        '#dependency' => array(
 
332
          'edit-options-alter-trim' => array(1)
 
333
        ),
 
334
      );
 
335
 
 
336
      $form['alter']['strip_tags'] = array(
 
337
        '#type' => 'checkbox',
 
338
        '#title' => t('Strip HTML tags'),
 
339
        '#description' => t('If checked, all HTML tags will be stripped.'),
 
340
        '#default_value' => $this->options['alter']['strip_tags'],
 
341
        '#process' => array('views_process_dependency'),
 
342
        '#dependency' => array(
 
343
          'edit-options-alter-trim' => array(1)
 
344
        ),
 
345
      );
 
346
 
 
347
      $form['alter']['html'] = array(
 
348
        '#type' => 'checkbox',
 
349
        '#title' => t('Field can contain HTML'),
 
350
        '#description' => t('If checked, HTML corrector will be run to ensure tags are properly closed after trimming.'),
 
351
        '#default_value' => $this->options['alter']['html'],
 
352
        '#process' => array('views_process_dependency'),
 
353
        '#dependency' => array(
 
354
          'edit-options-alter-trim' => array(1)
 
355
        ),
 
356
      );
 
357
    }
 
358
  }
 
359
 
 
360
  /**
 
361
   * Provide extra data to the administration form
 
362
   */
 
363
  function admin_summary() {
 
364
    return $this->label();
 
365
  }
 
366
 
 
367
  /**
 
368
   * Run before any fields are rendered.
 
369
   *
 
370
   * This gives the handlers some time to set up before any handler has
 
371
   * been rendered.
 
372
   *
 
373
   * @param $values
 
374
   *   An array of all objects returned from the query.
 
375
   */
 
376
  function pre_render($values) { }
 
377
 
 
378
  /**
 
379
   * Render the field.
 
380
   *
 
381
   * @param $values
 
382
   *   The values retrieved from the database.
 
383
   */
 
384
  function render($values) {
 
385
    $value = $values->{$this->field_alias};
 
386
    return check_plain($value);
 
387
  }
 
388
 
 
389
  /**
 
390
   * Render a field using advanced settings.
 
391
   *
 
392
   * This renders a field normally, then decides if render-as-link and
 
393
   * text-replacement rendering is necessary.
 
394
   */
 
395
  function advanced_render($values) {
 
396
    $this->last_render = $value = $this->render($values);
 
397
    $this->original_value = $value;
 
398
 
 
399
    if ($this->allow_advanced_render()) {
 
400
      $tokens = NULL;
 
401
      if (!empty($this->options['alter']['alter_text']) && !empty($this->options['alter']['text'])) {
 
402
        $tokens = $this->get_render_tokens();
 
403
        $value = $this->render_altered($tokens);
 
404
      }
 
405
 
 
406
      if (!empty($this->options['alter']['trim']) && !empty($this->options['alter']['max_length'])) {
 
407
        $value = $this->render_trim_text($value);
 
408
      }
 
409
 
 
410
      if (!empty($this->options['alter']['make_link']) && !empty($this->options['alter']['path'])) {
 
411
        if (!isset($tokens)) {
 
412
         $tokens = $this->get_render_tokens();
 
413
        }
 
414
        $value = $this->render_as_link($value, $tokens);
 
415
      }
 
416
 
 
417
      // This happens here so that render_as_link can get the unaltered value of
 
418
      // this field as a token rather than the altered value.
 
419
      $this->last_render = $value;
 
420
    }
 
421
 
 
422
    return $this->last_render;
 
423
  }
 
424
 
 
425
  /**
 
426
   * Render this field as altered text, from a fieldset set by the user.
 
427
   */
 
428
  function render_altered($tokens) {
 
429
    // Filter this right away as our substitutions are already sanitized.
 
430
    $value = filter_xss_admin($this->options['alter']['text']);
 
431
    $value = strtr($value, $tokens);
 
432
 
 
433
    return $value;
 
434
  }
 
435
 
 
436
  /**
 
437
   * Trim the field down to the specified length.
 
438
   */
 
439
  function render_trim_text($value) {
 
440
    if (!empty($this->options['alter']['strip_tags'])) {
 
441
      $value = strip_tags($value);
 
442
      // NOTE: It's possible that some external fields might override the
 
443
      // element type so if someone from, say, CCK runs into a bug here,
 
444
      // this may be why =)
 
445
      $this->definition['element type'] = 'span';
 
446
    }
 
447
 
 
448
    if (drupal_strlen($value) <= $this->options['alter']['max_length']) {
 
449
      return $value;
 
450
    }
 
451
 
 
452
    $value = drupal_substr($value, 0, $this->options['alter']['max_length']);
 
453
 
 
454
    if (!empty($this->options['alter']['word_boundary'])) {
 
455
      if (preg_match ("/(.*)\b.+/us", $value, $matches)) {
 
456
        // Remove scraps of HTML entities from the end of a strings
 
457
        $value = preg_replace('/(?:<(?!.+>)|&(?!.+;))/us', '', $matches[1]);
 
458
        // Strip spare space at the end.
 
459
        $value = rtrim($value);
 
460
      }
 
461
    }
 
462
 
 
463
    if (!empty($this->options['alter']['ellipsis'])) {
 
464
      $value .= '...';
 
465
    }
 
466
 
 
467
    if (!empty($this->options['alter']['html'])) {
 
468
      $value = _filter_htmlcorrector($value);
 
469
    }
 
470
 
 
471
    return $value;
 
472
  }
 
473
 
 
474
  /**
 
475
   * Render this field as a link, with the info from a fieldset set by
 
476
   * the user.
 
477
   */
 
478
  function render_as_link($text, $tokens) {
 
479
    // $path will be run through check_url() by l() so we do not need to
 
480
    // sanitize it ourselves.
 
481
    $path = $this->options['alter']['path'];
 
482
 
 
483
    // Use strip tags as there should never be HTML in the path.
 
484
    $path = strip_tags(strtr($path, $tokens));
 
485
 
 
486
    $alt = $this->options['alter']['alt'];
 
487
    $alt = strtr($alt, $tokens);
 
488
 
 
489
    $value = '';
 
490
 
 
491
    if (!empty($this->options['alter']['prefix'])) {
 
492
      $value .= filter_xss_admin($this->options['alter']['prefix']);
 
493
    }
 
494
 
 
495
    $options = array(
 
496
      'html' => 'true',
 
497
    );
 
498
 
 
499
    if ($alt) {
 
500
      $options['attributes']['title'] = $alt;
 
501
      $options['attributes']['alt'] = $alt;
 
502
    }
 
503
 
 
504
    // These can only be set internally at this time.
 
505
    if (isset($this->options['alter']['query'])) {
 
506
      $options['query'] = $this->options['alter']['query'];
 
507
    }
 
508
    if (isset($this->options['alter']['fragment'])) {
 
509
      $options['fragment'] = $this->options['alter']['fragment'];
 
510
    }
 
511
 
 
512
    $value .= l($text, $path, $options);
 
513
 
 
514
    if (!empty($this->options['alter']['suffix'])) {
 
515
      $value .= filter_xss_admin($this->options['alter']['suffix']);
 
516
    }
 
517
 
 
518
    return $value;
 
519
  }
 
520
 
 
521
  /**
 
522
   * Get the 'render' tokens to use for advanced rendering.
 
523
   *
 
524
   * This runs through all of the fields and arguments that
 
525
   * are available and gets their values. This will then be
 
526
   * used in one giant str_replace().
 
527
   */
 
528
  function get_render_tokens() {
 
529
    $tokens = array();
 
530
    if (!empty($this->view->build_info['substitutions'])) {
 
531
      $tokens = $this->view->build_info['substitutions'];
 
532
    }
 
533
    $count = 0;
 
534
    foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) {
 
535
      $token = '%' . ++$count;
 
536
      if (!isset($tokens[$token])) {
 
537
        $tokens[$token] = '';
 
538
      }
 
539
    }
 
540
 
 
541
    // Now add replacements for our fields.
 
542
    $options = array();
 
543
    foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) {
 
544
      if (isset($handler->last_render)) {
 
545
        $tokens["[$field]"] = $handler->last_render;
 
546
      }
 
547
      else {
 
548
        $tokens["[$field]"] = '';
 
549
      }
 
550
      // We only use fields up to (and including) this one.
 
551
      if ($field == $this->options['id']) {
 
552
        break;
 
553
      }
 
554
    }
 
555
 
 
556
    return $tokens;
 
557
  }
 
558
 
 
559
  /**
 
560
   * Call out to the theme() function, which probably just calls render() but
 
561
   * allows sites to override output fairly easily.
 
562
   */
 
563
  function theme($values) {
 
564
    return theme($this->theme_functions(), $this->view, $this, $values);
 
565
  }
 
566
 
 
567
  function theme_functions() {
 
568
    $themes = array();
 
569
    $hook = 'views_view_field';
 
570
 
 
571
    $display = $this->view->display[$this->view->current_display];
 
572
 
 
573
    if (!empty($display)) {
 
574
      $themes[] = $hook . '__' . $this->view->name  . '__' . $display->id . '__' . $this->options['id'];
 
575
      $themes[] = $hook . '__' . $this->view->name  . '__' . $display->id;
 
576
      $themes[] = $hook . '__' . $display->id . '__' . $this->options['id'];
 
577
      $themes[] = $hook . '__' . $display->id;
 
578
      if ($display->id != $display->display_plugin) {
 
579
        $themes[] = $hook . '__' . $this->view->name  . '__' . $display->display_plugin . '__' . $this->options['id'];
 
580
        $themes[] = $hook . '__' . $this->view->name  . '__' . $display->display_plugin;
 
581
        $themes[] = $hook . '__' . $display->display_plugin . '__' . $this->options['id'];
 
582
        $themes[] = $hook . '__' . $display->display_plugin;
 
583
      }
 
584
    }
 
585
    $themes[] = $hook . '__' . $this->view->name . '__' . $this->options['id'];
 
586
    $themes[] = $hook . '__' . $this->view->name;
 
587
    $themes[] = $hook . '__' . $this->options['id'];
 
588
    $themes[] = $hook;
 
589
 
 
590
    return $themes;
 
591
  }
 
592
}
 
593
 
 
594
/**
 
595
 * A special handler to take the place of missing or broken handlers.
 
596
 */
 
597
class views_handler_field_broken extends views_handler_field {
 
598
  function ui_name() {
 
599
    return t('Broken/missing handler');
 
600
  }
 
601
 
 
602
  function ensure_my_table() { /* No table to ensure! */ }
 
603
  function query() { /* No query to run */ }
 
604
  function options_form(&$form, &$form_state) {
 
605
    $form['markup'] = array(
 
606
      '#prefix' => '<div class="form-item description">',
 
607
      '#value' => 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.'),
 
608
    );
 
609
  }
 
610
 
 
611
  /**
 
612
   * Determine if the handler is considered 'broken'
 
613
   */
 
614
  function broken() { return TRUE; }
 
615
}
 
616
 
 
617
/**
 
618
 * Render a numeric value as a size.
 
619
 */
 
620
class views_handler_field_file_size extends views_handler_field {
 
621
  function render($values) {
 
622
    if ($values->{$this->field_alias}) {
 
623
      return format_size($values->{$this->field_alias});
 
624
    }
 
625
    else {
 
626
      return '';
 
627
    }
 
628
  }
 
629
}
 
630
 
 
631
/**
 
632
 * A handler to run a field through simple XSS filtering
 
633
 */
 
634
class views_handler_field_xss extends views_handler_field {
 
635
  function render($values) {
 
636
    $value = $values->{$this->field_alias};
 
637
    return filter_xss($value);
 
638
  }
 
639
}
 
640
 
 
641
/**
 
642
 * @}
 
643
 */
 
644