Projet

Général

Profil

Paste
Télécharger (18,8 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / views / includes / plugins.inc @ a5572547

1
<?php
2

    
3
/**
4
 * @file
5
 * Built in plugins for Views output handling.
6
 */
7

    
8
// @todo: Remove this once update.php can use the registry
9
views_include('base');
10

    
11
/**
12
 * Implements hook_views_plugins().
13
 */
14
function views_views_plugins() {
15
  $js_path = drupal_get_path('module', 'ctools') . '/js';
16
  $plugins = array(
17
    // display, style, row, argument default, argument validator and access.
18
    'display' => array(
19
      // Default settings for all display plugins.
20
      'default' => array(
21
        'title' => t('Master'),
22
        'help' => t('Default settings for this view.'),
23
        'handler' => 'views_plugin_display_default',
24
        'theme' => 'views_view',
25
        'no ui' => TRUE,
26
        'no remove' => TRUE,
27
        'js' => array('misc/form.js', 'misc/collapse.js', 'misc/textarea.js', 'misc/tabledrag.js', 'misc/autocomplete.js', "$js_path/dependent.js"),
28
        'use ajax' => TRUE,
29
        'use pager' => TRUE,
30
        'use more' => TRUE,
31
        'accept attachments' => TRUE,
32
        'help topic' => 'display-default',
33
      ),
34
      'page' => array(
35
        'title' => t('Page'),
36
        'help' => t('Display the view as a page, with a URL and menu links.'),
37
        'handler' => 'views_plugin_display_page',
38
        'theme' => 'views_view',
39
        'uses hook menu' => TRUE,
40
        'contextual links locations' => array('page'),
41
        'use ajax' => TRUE,
42
        'use pager' => TRUE,
43
        'use more' => TRUE,
44
        'accept attachments' => TRUE,
45
        'admin' => t('Page'),
46
        'help topic' => 'display-page',
47
      ),
48
      'block' => array(
49
        'title' => t('Block'),
50
        'help' => t('Display the view as a block.'),
51
        'handler' => 'views_plugin_display_block',
52
        'theme' => 'views_view',
53
        'uses hook block' => TRUE,
54
        'contextual links locations' => array('block'),
55
        'use ajax' => TRUE,
56
        'use pager' => TRUE,
57
        'use more' => TRUE,
58
        'accept attachments' => TRUE,
59
        'admin' => t('Block'),
60
        'help topic' => 'display-block',
61
      ),
62
      'attachment' => array(
63
        'title' => t('Attachment'),
64
        'help' => t('Attachments added to other displays to achieve multiple views in the same view.'),
65
        'handler' => 'views_plugin_display_attachment',
66
        'theme' => 'views_view',
67
        'contextual links locations' => array(),
68
        'use ajax' => TRUE,
69
        'use pager' => FALSE,
70
        'use more' => TRUE,
71
        'accept attachments' => FALSE,
72
        'help topic' => 'display-attachment',
73
      ),
74
      'feed' => array(
75
        'title' => t('Feed'),
76
        'help' => t('Display the view as a feed, such as an RSS feed.'),
77
        'handler' => 'views_plugin_display_feed',
78
        'uses hook menu' => TRUE,
79
        'use ajax' => FALSE,
80
        'use pager' => FALSE,
81
        'accept attachments' => FALSE,
82
        'admin' => t('Feed'),
83
        'help topic' => 'display-feed',
84
      ),
85
      'embed' => array(
86
        'title' => t('Embed'),
87
        'help' => t('Provide a display which can be embedded using the views api.'),
88
        'handler' => 'views_plugin_display_embed',
89
        'theme' => 'views_view',
90
        'uses hook menu' => FALSE,
91
        'use ajax' => TRUE,
92
        'use pager' => TRUE,
93
        'accept attachments' => FALSE,
94
        'admin' => t('Embed'),
95
        'no ui' => !variable_get('views_ui_display_embed', FALSE),
96
      ),
97
    ),
98
    'display_extender' => array(
99
      // Default settings for all display_extender plugins.
100
      'default' => array(
101
        'title' => t('Empty display extender'),
102
        'help' => t('Default settings for this view.'),
103
        'handler' => 'views_plugin_display_extender',
104
        // You can force the plugin to be enabled
105
        'enabled' => FALSE,
106
        'no ui' => TRUE,
107
      ),
108
    ),
109
    'style' => array(
110
      // Default settings for all style plugins.
111
      'default' => array(
112
        'title' => t('Unformatted list'),
113
        'help' => t('Displays rows one after another.'),
114
        'handler' => 'views_plugin_style_default',
115
        'theme' => 'views_view_unformatted',
116
        'uses row plugin' => TRUE,
117
        'uses row class' => TRUE,
118
        'uses grouping' => TRUE,
119
        'uses options' => TRUE,
120
        'type' => 'normal',
121
        'help topic' => 'style-unformatted',
122
      ),
123
      'list' => array(
124
        'title' => t('HTML list'),
125
        'help' => t('Displays rows as an HTML list.'),
126
        'handler' => 'views_plugin_style_list',
127
        'theme' => 'views_view_list',
128
        'uses row plugin' => TRUE,
129
        'uses row class' => TRUE,
130
        'uses options' => TRUE,
131
        'type' => 'normal',
132
        'help topic' => 'style-list',
133
      ),
134
      'grid' => array(
135
        'title' => t('Grid'),
136
        'help' => t('Displays rows in a grid.'),
137
        'handler' => 'views_plugin_style_grid',
138
        'theme' => 'views_view_grid',
139
        'uses fields' => FALSE,
140
        'uses row plugin' => TRUE,
141
        'uses row class' => TRUE,
142
        'uses options' => TRUE,
143
        'type' => 'normal',
144
        'help topic' => 'style-grid',
145
      ),
146
      'table' => array(
147
        'title' => t('Table'),
148
        'help' => t('Displays rows in a table.'),
149
        'handler' => 'views_plugin_style_table',
150
        'theme' => 'views_view_table',
151
        'uses row plugin' => FALSE,
152
        'uses row class' => TRUE,
153
        'uses fields' => TRUE,
154
        'uses options' => TRUE,
155
        'type' => 'normal',
156
        'help topic' => 'style-table',
157
      ),
158
      'default_summary' => array(
159
        'title' => t('List'),
160
        'help' => t('Displays the default summary as a list.'),
161
        'handler' => 'views_plugin_style_summary',
162
        'theme' => 'views_view_summary',
163
        'type' => 'summary', // only shows up as a summary style
164
        'uses options' => TRUE,
165
        'help topic' => 'style-summary',
166
      ),
167
      'unformatted_summary' => array(
168
        'title' => t('Unformatted'),
169
        'help' => t('Displays the summary unformatted, with option for one after another or inline.'),
170
        'handler' => 'views_plugin_style_summary_unformatted',
171
        'theme' => 'views_view_summary_unformatted',
172
        'type' => 'summary', // only shows up as a summary style
173
        'uses options' => TRUE,
174
        'help topic' => 'style-summary-unformatted',
175
      ),
176
      'rss' => array(
177
        'title' => t('RSS Feed'),
178
        'help' => t('Generates an RSS feed from a view.'),
179
        'handler' => 'views_plugin_style_rss',
180
        'theme' => 'views_view_rss',
181
        'uses row plugin' => TRUE,
182
        'uses options' => TRUE,
183
        'type' => 'feed',
184
        'help topic' => 'style-rss',
185
      ),
186
    ),
187
    'row' => array(
188
      'fields' => array(
189
        'title' => t('Fields'),
190
        'help' => t('Displays the fields with an optional template.'),
191
        'handler' => 'views_plugin_row_fields',
192
        'theme' => 'views_view_fields',
193
        'uses fields' => TRUE,
194
        'uses options' => TRUE,
195
        'type' => 'normal',
196
        'help topic' => 'style-row-fields',
197
      ),
198
      'rss_fields' => array(
199
        'title' => t('Fields'),
200
        'help' => t('Display fields as RSS items.'),
201
        'handler' => 'views_plugin_row_rss_fields',
202
        'theme' => 'views_view_row_rss',
203
        'uses fields' => TRUE,
204
        'uses options' => TRUE,
205
        'type' => 'feed',
206
        'help topic' => 'style-row-fields',
207
      ),
208
    ),
209
    'argument default' => array(
210
      'parent' => array(
211
        'no ui' => TRUE,
212
        'handler' => 'views_plugin_argument_default',
213
        'parent' => '',
214
      ),
215
      'fixed' => array(
216
        'title' => t('Fixed value'),
217
        'handler' => 'views_plugin_argument_default_fixed',
218
      ),
219
      'php' => array(
220
        'title' => t('PHP Code'),
221
        'handler' => 'views_plugin_argument_default_php',
222
      ),
223
      'raw' => array(
224
        'title' => t('Raw value from URL'),
225
        'handler' => 'views_plugin_argument_default_raw',
226
      ),
227
    ),
228
    'argument validator' => array(
229
      'php' => array(
230
        'title' => t('PHP Code'),
231
        'handler' => 'views_plugin_argument_validate_php',
232
      ),
233
      'numeric' => array(
234
        'title' => t('Numeric'),
235
        'handler' => 'views_plugin_argument_validate_numeric',
236
      ),
237
    ),
238
    'access' => array(
239
      'none' => array(
240
        'title' => t('None'),
241
        'help' => t('Will be available to all users.'),
242
        'handler' => 'views_plugin_access_none',
243
        'help topic' => 'access-none',
244
      ),
245
      'role' => array(
246
        'title' => t('Role'),
247
        'help' => t('Access will be granted to users with any of the specified roles.'),
248
        'handler' => 'views_plugin_access_role',
249
        'uses options' => TRUE,
250
        'help topic' => 'access-role',
251
      ),
252
      'perm' => array(
253
        'title' => t('Permission'),
254
        'help' => t('Access will be granted to users with the specified permission string.'),
255
        'handler' => 'views_plugin_access_perm',
256
        'uses options' => TRUE,
257
        'help topic' => 'access-perm',
258
      ),
259
    ),
260
    'query' => array(
261
      'parent' => array(
262
        'no ui' => TRUE,
263
        'handler' => 'views_plugin_query',
264
        'parent' => '',
265
      ),
266
      'views_query' => array(
267
        'title' => t('SQL Query'),
268
        'help' => t('Query will be generated and run using the Drupal database API.'),
269
        'handler' => 'views_plugin_query_default'
270
      ),
271
    ),
272
    'cache' => array(
273
      'parent' => array(
274
        'no ui' => TRUE,
275
        'handler' => 'views_plugin_cache',
276
        'parent' => '',
277
      ),
278
      'none' => array(
279
        'title' => t('None'),
280
        'help' => t('No caching of Views data.'),
281
        'handler' => 'views_plugin_cache_none',
282
        'help topic' => 'cache-none',
283
      ),
284
      'time' => array(
285
        'title' => t('Time-based'),
286
        'help' => t('Simple time-based caching of data.'),
287
        'handler' => 'views_plugin_cache_time',
288
        'uses options' => TRUE,
289
        'help topic' => 'cache-time',
290
      ),
291
    ),
292
    'exposed_form' => array(
293
      'parent' => array(
294
        'no ui' => TRUE,
295
        'handler' => 'views_plugin_exposed_form',
296
        'parent' => '',
297
      ),
298
      'basic' => array(
299
        'title' => t('Basic'),
300
        'help' => t('Basic exposed form'),
301
        'handler' => 'views_plugin_exposed_form_basic',
302
        'uses options' => TRUE,
303
        'help topic' => 'exposed-form-basic',
304
      ),
305
      'input_required' => array(
306
        'title' => t('Input required'),
307
        'help' => t('An exposed form that only renders a view if the form contains user input.'),
308
        'handler' => 'views_plugin_exposed_form_input_required',
309
        'uses options' => TRUE,
310
        'help topic' => 'exposed-form-input-required',
311
      ),
312
    ),
313
    'pager' => array(
314
      'parent' => array(
315
        'no ui' => TRUE,
316
        'handler' => 'views_plugin_pager',
317
        'parent' => '',
318
      ),
319
      'none' => array(
320
        'title' => t('Display all items'),
321
        'help' => t("Display all items that this view might find"),
322
        'handler' => 'views_plugin_pager_none',
323
        'help topic' => 'pager-none',
324
        'uses options' => TRUE,
325
        'type' => 'basic',
326
      ),
327
      'some' => array(
328
        'title' => t('Display a specified number of items'),
329
        'help' => t('Display a limited number items that this view might find.'),
330
        'handler' => 'views_plugin_pager_some',
331
        'help topic' => 'pager-some',
332
        'uses options' => TRUE,
333
        'type' => 'basic',
334
      ),
335
      'full' => array(
336
        'title' => t('Paged output, full pager'),
337
        'short title' => t('Full'),
338
        'help' => t('Paged output, full Drupal style'),
339
        'handler' => 'views_plugin_pager_full',
340
        'help topic' => 'pager-full',
341
        'uses options' => TRUE,
342
      ),
343
      'mini' => array(
344
        'title' => t('Paged output, mini pager'),
345
        'short title' => t('Mini'),
346
        'help' => t('Use the mini pager output.'),
347
        'handler' => 'views_plugin_pager_mini',
348
        'help topic' => 'pager-mini',
349
        'uses options' => TRUE,
350
        'parent' => 'full',
351
      ),
352
    ),
353
    'localization' => array(
354
      'parent' => array(
355
        'no ui' => TRUE,
356
        'handler' => 'views_plugin_localization',
357
        'parent' => '',
358
      ),
359
     'none' => array(
360
        'title' => t('None'),
361
        'help' => t('Do not pass admin strings for translation.'),
362
        'handler' => 'views_plugin_localization_none',
363
        'help topic' => 'localization-none',
364
      ),
365
      'core' => array(
366
        'title' => t('Core'),
367
        'help' => t("Use Drupal core t() function. Not recommended, as it doesn't support updates to existing strings."),
368
        'handler' => 'views_plugin_localization_core',
369
        'help topic' => 'localization-core',
370
      ),
371
    ),
372
  );
373
  // Add a help message pointing to the i18views module if it is not present.
374
  if (!module_exists('i18nviews')) {
375
    $plugins['localization']['core']['help'] .= ' ' . t('If you need to translate Views labels into other languages, consider installing the <a href="!path">Internationalization</a> package\'s Views translation module.', array('!path' => url('http://drupal.org/project/i18n', array('absolute' => TRUE))));
376
  }
377

    
378
  if (module_invoke('ctools', 'api_version', '1.3')) {
379
    $plugins['style']['jump_menu_summary'] = array(
380
      'title' => t('Jump menu'),
381
      'help' => t('Puts all of the results into a select box and allows the user to go to a different page based upon the results.'),
382
      'handler' => 'views_plugin_style_summary_jump_menu',
383
      'theme' => 'views_view_summary_jump_menu',
384
      'type' => 'summary', // only shows up as a summary style
385
      'uses options' => TRUE,
386
      'help topic' => 'style-summary-jump-menu',
387
    );
388
    $plugins['style']['jump_menu'] = array(
389
      'title' => t('Jump menu'),
390
      'help' => t('Puts all of the results into a select box and allows the user to go to a different page based upon the results.'),
391
      'handler' => 'views_plugin_style_jump_menu',
392
      'theme' => 'views_view_jump_menu',
393
      'uses row plugin' => TRUE,
394
      'uses fields' => TRUE,
395
      'uses options' => TRUE,
396
      'type' => 'normal',
397
      'help topic' => 'style-jump-menu',
398
    );
399
  }
400

    
401
  return $plugins;
402
}
403

    
404
/**
405
 * Builds and return a list of all plugins available in the system.
406
 *
407
 * @return Nested array of plugins, grouped by type.
408
 */
409
function views_discover_plugins() {
410
  $cache = array('display' => array(), 'style' => array(), 'row' => array(), 'argument default' => array(), 'argument validator' => array(), 'access' => array(), 'cache' => array(), 'exposed_form' => array());
411
  // Get plugins from all mdoules.
412
  foreach (module_implements('views_plugins') as $module) {
413
    $function = $module . '_views_plugins';
414
    $result = $function();
415
    if (!is_array($result)) {
416
      continue;
417
    }
418

    
419
    $module_dir = isset($result['module']) ? $result['module'] : $module;
420
    // Setup automatic path/file finding for theme registration
421
    if ($module_dir == 'views') {
422
      $theme_path = drupal_get_path('module', $module_dir) . '/theme';
423
      $theme_file = 'theme.inc';
424
      $path = drupal_get_path('module', $module_dir) . '/plugins';
425
    }
426
    else {
427
      $theme_path = $path = drupal_get_path('module', $module_dir);
428
      $theme_file = "$module.views.inc";
429
    }
430

    
431
    foreach ($result as $type => $info) {
432
      if ($type == 'module') {
433
        continue;
434
      }
435
      foreach ($info as $plugin => $def) {
436
        $def['module'] = $module_dir;
437
        if (!isset($def['theme path'])) {
438
          $def['theme path'] = $theme_path;
439
        }
440
        if (!isset($def['theme file'])) {
441
          $def['theme file'] = $theme_file;
442
        }
443
        if (!isset($def['path'])) {
444
          $def['path'] = $path;
445
        }
446
        if (!isset($def['file'])) {
447
          $def['file'] = $def['handler'] . '.inc';
448
        }
449
        if (!isset($def['parent'])) {
450
          $def['parent'] = 'parent';
451
        }
452
        // Set the internal name to be able to read it out later.
453
        $def['name'] = $plugin;
454

    
455
        // merge the new data in
456
        $cache[$type][$plugin] = $def;
457
      }
458
    }
459
  }
460

    
461
  // Let other modules modify the plugins.
462
  drupal_alter('views_plugins', $cache);
463
  return $cache;
464
}
465

    
466
/**
467
 * Abstract base class to provide interface common to all plugins.
468
 */
469
class views_plugin extends views_object {
470
  /**
471
   * The top object of a view.
472
   *
473
   * @var view
474
   */
475
  var $view = NULL;
476

    
477
  /**
478
   * The current used views display.
479
   *
480
   * @var views_display
481
   */
482
  var $display = NULL;
483

    
484
  /**
485
   * The plugin type of this plugin, for example style or query.
486
   */
487
  var $plugin_type = NULL;
488

    
489
  /**
490
   * The plugin name of this plugin, for example table or full.
491
   */
492
  var $plugin_name = NULL;
493

    
494
  /**
495
   * Init will be called after construct, when the plugin is attached to a
496
   * view and a display.
497
   */
498

    
499
  /**
500
   * Provide a form to edit options for this plugin.
501
   */
502
  function options_form(&$form, &$form_state) {
503
    // Some form elements belong in a fieldset for presentation, but can't
504
    // be moved into one because of the form_state['values'] hierarchy. Those
505
    // elements can add a #fieldset => 'fieldset_name' property, and they'll
506
    // be moved to their fieldset during pre_render.
507
    $form['#pre_render'][] = 'views_ui_pre_render_add_fieldset_markup';
508
  }
509

    
510
  /**
511
   * Validate the options form.
512
   */
513
  function options_validate(&$form, &$form_state) { }
514

    
515
  /**
516
   * Handle any special handling on the validate form.
517
   */
518
  function options_submit(&$form, &$form_state) { }
519

    
520
  /**
521
   * Add anything to the query that we might need to.
522
   */
523
  function query() { }
524

    
525
  /**
526
   * Provide a full list of possible theme templates used by this style.
527
   */
528
  function theme_functions() {
529
    return views_theme_functions($this->definition['theme'], $this->view, $this->display);
530
  }
531

    
532
  /**
533
   * Provide a list of additional theme functions for the theme information page
534
   */
535
  function additional_theme_functions() {
536
    $funcs = array();
537
    if (!empty($this->definition['additional themes'])) {
538
      foreach ($this->definition['additional themes'] as $theme => $type) {
539
        $funcs[] = views_theme_functions($theme, $this->view, $this->display);
540
      }
541
    }
542
    return $funcs;
543
  }
544

    
545
  /**
546
   * Validate that the plugin is correct and can be saved.
547
   *
548
   * @return
549
   *   An array of error strings to tell the user what is wrong with this
550
   *   plugin.
551
   */
552
  function validate() { return array(); }
553

    
554
  /**
555
   * Returns the summary of the settings in the display.
556
   */
557
  function summary_title() {
558
    return t('Settings');
559
  }
560
  /**
561
   * Return the human readable name of the display.
562
   *
563
   * This appears on the ui beside each plugin and beside the settings link.
564
   */
565
  function plugin_title() {
566
    if (isset($this->definition['short title'])) {
567
      return check_plain($this->definition['short title']);
568
    }
569
    return check_plain($this->definition['title']);
570
  }
571
}
572

    
573
/**
574
 * Get enabled display extenders.
575
 */
576
function views_get_enabled_display_extenders() {
577
  $enabled = array_filter(variable_get('views_display_extenders', array()));
578
  $options = views_fetch_plugin_names('display_extender');
579
  foreach ($options as $name => $plugin) {
580
    $enabled[$name] = $name;
581
  }
582

    
583
  return $enabled;
584
}