Projet

Général

Profil

Paste
Télécharger (24,6 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / views / modules / node.views.inc @ 4543c6c7

1
<?php
2

    
3
/**
4
 * @file
5
 * Provide views data and handlers for node.module.
6
 *
7
 * @ingroup views_module_handlers
8
 */
9

    
10
/**
11
 * Implements hook_views_data().
12
 */
13
function node_views_data() {
14
  // ----------------------------------------------------------------
15
  // node table -- basic table information.
16

    
17
  // Define the base group of this table. Fields that don't
18
  // have a group defined will go into this field by default.
19
  $data['node']['table']['group'] = t('Content');
20

    
21
  // Advertise this table as a possible base table
22
  $data['node']['table']['base'] = array(
23
    'field' => 'nid',
24
    'title' => t('Content'),
25
    'weight' => -10,
26
    'access query tag' => 'node_access',
27
    'defaults' => array(
28
      'field' => 'title',
29
    ),
30
  );
31
  $data['node']['table']['entity type'] = 'node';
32

    
33
  $data['node']['table']['default_relationship'] = array(
34
    'node_revision' => array(
35
      'table' => 'node_revision',
36
      'field' => 'vid',
37
    ),
38
  );
39

    
40
  // ----------------------------------------------------------------
41
  // node table -- fields
42

    
43
  // nid
44
  $data['node']['nid'] = array(
45
    'title' => t('Nid'),
46
    'help' => t('The node ID.'), // The help that appears on the UI,
47
    // Information for displaying the nid
48
    'field' => array(
49
      'handler' => 'views_handler_field_node',
50
      'click sortable' => TRUE,
51
    ),
52
    // Information for accepting a nid as an argument
53
    'argument' => array(
54
      'handler' => 'views_handler_argument_node_nid',
55
      'name field' => 'title', // the field to display in the summary.
56
      'numeric' => TRUE,
57
      'validate type' => 'nid',
58
    ),
59
    // Information for accepting a nid as a filter
60
    'filter' => array(
61
      'handler' => 'views_handler_filter_numeric',
62
    ),
63
    // Information for sorting on a nid.
64
    'sort' => array(
65
      'handler' => 'views_handler_sort',
66
    ),
67
  );
68

    
69
  // title
70
  // This definition has more items in it than it needs to as an example.
71
  $data['node']['title'] = array(
72
    'title' => t('Title'), // The item it appears as on the UI,
73
    'help' => t('The content title.'), // The help that appears on the UI,
74
     // Information for displaying a title as a field
75
    'field' => array(
76
      'field' => 'title', // the real field. This could be left out since it is the same.
77
      'group' => t('Content'), // The group it appears in on the UI. Could be left out.
78
      'handler' => 'views_handler_field_node',
79
      'click sortable' => TRUE,
80
      'link_to_node default' => TRUE,
81
     ),
82
    'sort' => array(
83
      'handler' => 'views_handler_sort',
84
    ),
85
    // Information for accepting a title as a filter
86
    'filter' => array(
87
      'handler' => 'views_handler_filter_string',
88
    ),
89
    'argument' => array(
90
      'handler' => 'views_handler_argument_string',
91
    ),
92
  );
93

    
94
  // created field
95
  $data['node']['created'] = array(
96
    'title' => t('Post date'), // The item it appears as on the UI,
97
    'help' => t('The date the content was posted.'), // The help that appears on the UI,
98
    'field' => array(
99
      'handler' => 'views_handler_field_date',
100
      'click sortable' => TRUE,
101
    ),
102
    'sort' => array(
103
      'handler' => 'views_handler_sort_date',
104
    ),
105
    'filter' => array(
106
      'handler' => 'views_handler_filter_date',
107
    ),
108
  );
109

    
110
  // changed field
111
  $data['node']['changed'] = array(
112
    'title' => t('Updated date'), // The item it appears as on the UI,
113
    'help' => t('The date the content was last updated.'), // The help that appears on the UI,
114
    'field' => array(
115
      'handler' => 'views_handler_field_date',
116
      'click sortable' => TRUE,
117
    ),
118
    'sort' => array(
119
      'handler' => 'views_handler_sort_date',
120
    ),
121
    'filter' => array(
122
      'handler' => 'views_handler_filter_date',
123
    ),
124
  );
125

    
126
  // Content type
127
  $data['node']['type'] = array(
128
    'title' => t('Type'), // The item it appears as on the UI,
129
    'help' => t('The content type (for example, "blog entry", "forum post", "story", etc).'), // The help that appears on the UI,
130
    'field' => array(
131
      'handler' => 'views_handler_field_node_type',
132
      'click sortable' => TRUE,
133
    ),
134
    'sort' => array(
135
      'handler' => 'views_handler_sort',
136
    ),
137
    'filter' => array(
138
      'handler' => 'views_handler_filter_node_type',
139
    ),
140
    'argument' => array(
141
      'handler' => 'views_handler_argument_node_type',
142
    ),
143
  );
144

    
145
  // published status
146
  $data['node']['status'] = array(
147
    'title' => t('Published'),
148
    'help' => t('Whether or not the content is published.'),
149
    'field' => array(
150
      'handler' => 'views_handler_field_boolean',
151
      'click sortable' => TRUE,
152
      'output formats' => array(
153
        'published-notpublished' => array(t('Published'), t('Not published')),
154
      ),
155
    ),
156
    'filter' => array(
157
      'handler' => 'views_handler_filter_boolean_operator',
158
      'label' => t('Published'),
159
      'type' => 'yes-no',
160
      'use equal' => TRUE, // Use status = 1 instead of status <> 0 in WHERE statment
161
    ),
162
    'sort' => array(
163
      'handler' => 'views_handler_sort',
164
    ),
165
  );
166

    
167
  // published status + extra
168
  $data['node']['status_extra'] = array(
169
    'title' => t('Published or admin'),
170
    'help' => t('Filters out unpublished content if the current user cannot view it.'),
171
    'filter' => array(
172
      'field' => 'status',
173
      'handler' => 'views_handler_filter_node_status',
174
      'label' => t('Published or admin'),
175
    ),
176
  );
177

    
178
  // promote status
179
  $data['node']['promote'] = array(
180
    'title' => t('Promoted to front page'),
181
    'help' => t('Whether or not the content is promoted to the front page.'),
182
    'field' => array(
183
      'handler' => 'views_handler_field_boolean',
184
      'click sortable' => TRUE,
185
      'output formats' => array(
186
        'promoted-notpromoted' => array(t('Promoted'), t('Not promoted')),
187
      ),
188
    ),
189
    'filter' => array(
190
      'handler' => 'views_handler_filter_boolean_operator',
191
      'label' => t('Promoted to front page'),
192
      'type' => 'yes-no',
193
    ),
194
    'sort' => array(
195
      'handler' => 'views_handler_sort',
196
    ),
197
  );
198

    
199
  // sticky
200
  $data['node']['sticky'] = array(
201
    'title' => t('Sticky'), // The item it appears as on the UI,
202
    'help' => t('Whether or not the content is sticky.'), // The help that appears on the UI,
203
     // Information for displaying a title as a field
204
    'field' => array(
205
      'handler' => 'views_handler_field_boolean',
206
      'click sortable' => TRUE,
207
      'output formats' => array(
208
        'sticky' => array(t('Sticky'), t('Not sticky')),
209
      ),
210
    ),
211
    'filter' => array(
212
      'handler' => 'views_handler_filter_boolean_operator',
213
      'label' => t('Sticky'),
214
      'type' => 'yes-no',
215
    ),
216
    'sort' => array(
217
      'handler' => 'views_handler_sort',
218
      'help' => t('Whether or not the content is sticky. To list sticky content first, set this to descending.'),
219
    ),
220
  );
221

    
222
  // Define some fields based upon views_handler_field_entity in the entity
223
  // table so they can be re-used with other query backends.
224
  // @see views_handler_field_entity
225

    
226
  $data['views_entity_node']['table']['group'] = t('Content');
227

    
228
  $data['node']['view_node']['moved to'] = array('views_entity_node', 'view_node');
229
  $data['views_entity_node']['view_node'] = array(
230
    'field' => array(
231
      'title' => t('Link'),
232
      'help' => t('Provide a simple link to the content.'),
233
      'handler' => 'views_handler_field_node_link',
234
    ),
235
  );
236

    
237
  $data['node']['edit_node']['moved to'] = array('views_entity_node', 'edit_node');
238
  $data['views_entity_node']['edit_node'] = array(
239
    'field' => array(
240
      'title' => t('Edit link'),
241
      'help' => t('Provide a simple link to edit the content.'),
242
      'handler' => 'views_handler_field_node_link_edit',
243
    ),
244
  );
245

    
246
  $data['node']['delete_node']['moved to'] = array('views_entity_node', 'delete_node');
247
  $data['views_entity_node']['delete_node'] = array(
248
    'field' => array(
249
      'title' => t('Delete link'),
250
      'help' => t('Provide a simple link to delete the content.'),
251
      'handler' => 'views_handler_field_node_link_delete',
252
    ),
253
  );
254

    
255
  $data['node']['path'] = array(
256
    'field' => array(
257
      'title' => t('Path'),
258
      'help' => t('The aliased path to this content.'),
259
      'handler' => 'views_handler_field_node_path',
260
    ),
261
  );
262

    
263

    
264
  // Bogus fields for aliasing purposes.
265

    
266
  $data['node']['created_fulldate'] = array(
267
    'title' => t('Created date'),
268
    'help' => t('Date in the form of CCYYMMDD.'),
269
    'argument' => array(
270
      'field' => 'created',
271
      'handler' => 'views_handler_argument_node_created_fulldate',
272
    ),
273
  );
274

    
275
  $data['node']['created_year_month'] = array(
276
    'title' => t('Created year + month'),
277
    'help' => t('Date in the form of YYYYMM.'),
278
    'argument' => array(
279
      'field' => 'created',
280
      'handler' => 'views_handler_argument_node_created_year_month',
281
    ),
282
  );
283

    
284
  $data['node']['created_year'] = array(
285
    'title' => t('Created year'),
286
    'help' => t('Date in the form of YYYY.'),
287
    'argument' => array(
288
      'field' => 'created',
289
      'handler' => 'views_handler_argument_node_created_year',
290
    ),
291
  );
292

    
293
  $data['node']['created_month'] = array(
294
    'title' => t('Created month'),
295
    'help' => t('Date in the form of MM (01 - 12).'),
296
    'argument' => array(
297
      'field' => 'created',
298
      'handler' => 'views_handler_argument_node_created_month',
299
    ),
300
  );
301

    
302
  $data['node']['created_day'] = array(
303
    'title' => t('Created day'),
304
    'help' => t('Date in the form of DD (01 - 31).'),
305
    'argument' => array(
306
      'field' => 'created',
307
      'handler' => 'views_handler_argument_node_created_day',
308
    ),
309
  );
310

    
311
  $data['node']['created_week'] = array(
312
    'title' => t('Created week'),
313
    'help' => t('Date in the form of WW (01 - 53).'),
314
    'argument' => array(
315
      'field' => 'created',
316
      'handler' => 'views_handler_argument_node_created_week',
317
    ),
318
  );
319

    
320
  $data['node']['changed_fulldate'] = array(
321
    'title' => t('Updated date'),
322
    'help' => t('Date in the form of CCYYMMDD.'),
323
    'argument' => array(
324
      'field' => 'changed',
325
      'handler' => 'views_handler_argument_node_created_fulldate',
326
    ),
327
  );
328

    
329
  $data['node']['changed_year_month'] = array(
330
    'title' => t('Updated year + month'),
331
    'help' => t('Date in the form of YYYYMM.'),
332
    'argument' => array(
333
      'field' => 'changed',
334
      'handler' => 'views_handler_argument_node_created_year_month',
335
    ),
336
  );
337

    
338
  $data['node']['changed_year'] = array(
339
    'title' => t('Updated year'),
340
    'help' => t('Date in the form of YYYY.'),
341
    'argument' => array(
342
      'field' => 'changed',
343
      'handler' => 'views_handler_argument_node_created_year',
344
    ),
345
  );
346

    
347
  $data['node']['changed_month'] = array(
348
    'title' => t('Updated month'),
349
    'help' => t('Date in the form of MM (01 - 12).'),
350
    'argument' => array(
351
      'field' => 'changed',
352
      'handler' => 'views_handler_argument_node_created_month',
353
    ),
354
  );
355

    
356
  $data['node']['changed_day'] = array(
357
    'title' => t('Updated day'),
358
    'help' => t('Date in the form of DD (01 - 31).'),
359
    'argument' => array(
360
      'field' => 'changed',
361
      'handler' => 'views_handler_argument_node_created_day',
362
    ),
363
  );
364

    
365
  $data['node']['changed_week'] = array(
366
    'title' => t('Updated week'),
367
    'help' => t('Date in the form of WW (01 - 53).'),
368
    'argument' => array(
369
      'field' => 'changed',
370
      'handler' => 'views_handler_argument_node_created_week',
371
    ),
372
  );
373

    
374
  // uid field
375
  $data['node']['uid'] = array(
376
    'title' => t('Author uid'),
377
    'help' => t('The user authoring the content. If you need more fields than the uid add the content: author relationship'),
378
    'relationship' => array(
379
      'title' => t('Author'),
380
      'help' => t('Relate content to the user who created it.'),
381
      'handler' => 'views_handler_relationship',
382
      'base' => 'users',
383
      'field' => 'uid',
384
      'label' => t('author'),
385
    ),
386
    'filter' => array(
387
      'handler' => 'views_handler_filter_user_name',
388
    ),
389
    'argument' => array(
390
      'handler' => 'views_handler_argument_numeric',
391
    ),
392
    'field' => array(
393
      'handler' => 'views_handler_field_user',
394
    ),
395
  );
396

    
397
  $data['node']['uid_revision'] = array(
398
    'title' => t('User has a revision'),
399
    'help' => t('All nodes where a certain user has a revision'),
400
    'real field' => 'nid',
401
    'filter' => array(
402
      'handler' => 'views_handler_filter_node_uid_revision',
403
    ),
404
    'argument' => array(
405
      'handler' => 'views_handler_argument_node_uid_revision',
406
    ),
407
  );
408

    
409
  // ----------------------------------------------------------------------
410
  // Content revision table
411

    
412
  // Define the base group of this table. Fields that don't
413
  // have a group defined will go into this field by default.
414
  $data['node_revisions']['moved to'] = 'node_revision';
415
  $data['node_revision']['table']['entity type'] = 'node';
416
  $data['node_revision']['table']['group']  = t('Content revision');
417
  // Support the conversion of the field body
418
  $data['node_revisions']['body']['moved to'] = array('field_revision_data', 'body-revision_id');
419

    
420
  // Advertise this table as a possible base table
421
  $data['node_revision']['table']['base'] = array(
422
    'field' => 'vid',
423
    'title' => t('Content revision'),
424
    'help' => t('Content revision is a history of changes to content.'),
425
    'defaults' => array(
426
      'field' => 'title',
427
    ),
428
  );
429

    
430
  // For other base tables, explain how we join
431
  $data['node_revision']['table']['join'] = array(
432
    // Directly links to node table.
433
    'node' => array(
434
      'left_field' => 'vid',
435
      'field' => 'vid',
436
    ),
437
  );
438

    
439
  $data['node_revision']['table']['default_relationship'] = array(
440
    'node' => array(
441
      'table' => 'node',
442
      'field' => 'nid',
443
    ),
444
  );
445

    
446
  // uid field for node revision
447
  $data['node_revision']['uid'] = array(
448
    'title' => t('User'),
449
    'help' => t('Relate a content revision to the user who created the revision.'),
450
    'relationship' => array(
451
      'handler' => 'views_handler_relationship',
452
      'base' => 'users',
453
      'base field' => 'uid',
454
      'label' => t('revision user'),
455
    ),
456
  );
457

    
458
  // nid
459
  $data['node_revision']['nid'] = array(
460
    'title' => t('Nid'),
461
    // The help that appears on the UI.
462
    'help' => t('The revision NID of the content revision.'),
463
    // Information for displaying the nid.
464
    'field' => array(
465
      'click sortable' => TRUE,
466
    ),
467
    // Information for accepting a nid as an argument.
468
    'argument' => array(
469
      'handler' => 'views_handler_argument_node_nid',
470
      'click sortable' => TRUE,
471
      'numeric' => TRUE,
472
    ),
473
    // Information for accepting a nid as a filter.
474
    'filter' => array(
475
      'handler' => 'views_handler_filter_numeric',
476
    ),
477
    // Information for sorting on a nid.
478
    'sort' => array(
479
      'handler' => 'views_handler_sort',
480
    ),
481
    'relationship' => array(
482
      'handler' => 'views_handler_relationship',
483
      'base' => 'node',
484
      'base field' => 'nid',
485
      'title' => t('Content'),
486
      'label' => t('Get the actual content from a content revision.'),
487
    ),
488
  );
489

    
490
  // vid
491
  $data['node_revision']['vid'] = array(
492
    'title' => t('Vid'),
493
    // The help that appears on the UI.
494
    'help' => t('The revision ID of the content revision.'),
495
    // Information for displaying the vid.
496
    'field' => array(
497
      'click sortable' => TRUE,
498
    ),
499
    // Information for accepting a vid as an argument.
500
    'argument' => array(
501
      'handler' => 'views_handler_argument_node_vid',
502
      'click sortable' => TRUE,
503
      'numeric' => TRUE,
504
    ),
505
    // Information for accepting a vid as a filter.
506
    'filter' => array(
507
      'handler' => 'views_handler_filter_numeric',
508
    ),
509
    // Information for sorting on a vid.
510
    'sort' => array(
511
      'handler' => 'views_handler_sort',
512
    ),
513
    'relationship' => array(
514
      'handler' => 'views_handler_relationship',
515
      'base' => 'node',
516
      'base field' => 'vid',
517
      'title' => t('Content'),
518
      'label' => t('Get the actual content from a content revision.'),
519
    ),
520
  );
521

    
522
  // title
523
  $data['node_revision']['title'] = array(
524
    'title' => t('Title'), // The item it appears as on the UI,
525
    'help' => t('The content title.'), // The help that appears on the UI,
526
     // Information for displaying a title as a field
527
    'field' => array(
528
      'field' => 'title', // the real field
529
      'handler' => 'views_handler_field_node_revision',
530
      'click sortable' => TRUE,
531
     ),
532
    'sort' => array(
533
      'handler' => 'views_handler_sort',
534
    ),
535
    'filter' => array(
536
      'handler' => 'views_handler_filter_string',
537
    ),
538
    'argument' => array(
539
      'handler' => 'views_handler_argument_string',
540
    ),
541
  );
542

    
543
  // log field
544
  $data['node_revision']['log'] = array(
545
    'title' => t('Log message'), // The item it appears as on the UI,
546
    'help' => t('The log message entered when the revision was created.'), // The help that appears on the UI,
547
     // Information for displaying a title as a field
548
    'field' => array(
549
      'handler' => 'views_handler_field_xss',
550
     ),
551
    'filter' => array(
552
      'handler' => 'views_handler_filter_string',
553
    ),
554
  );
555

    
556
  // revision timestamp
557
  // changed field
558
  $data['node_revision']['timestamp'] = array(
559
    'title' => t('Updated date'), // The item it appears as on the UI,
560
    'help' => t('The date the node was last updated.'), // The help that appears on the UI,
561
    'field' => array(
562
      'handler' => 'views_handler_field_date',
563
      'click sortable' => TRUE,
564
    ),
565
    'sort' => array(
566
      'handler' => 'views_handler_sort_date',
567
    ),
568
    'filter' => array(
569
      'handler' => 'views_handler_filter_date',
570
    ),
571
  );
572

    
573
  $data['node_revision']['link_to_revision'] = array(
574
    'field' => array(
575
      'title' => t('Link'),
576
      'help' => t('Provide a simple link to the revision.'),
577
      'handler' => 'views_handler_field_node_revision_link',
578
    ),
579
  );
580

    
581
  $data['node_revision']['revert_revision'] = array(
582
    'field' => array(
583
      'title' => t('Revert link'),
584
      'help' => t('Provide a simple link to revert to the revision.'),
585
      'handler' => 'views_handler_field_node_revision_link_revert',
586
    ),
587
  );
588

    
589
  $data['node_revision']['delete_revision'] = array(
590
    'field' => array(
591
      'title' => t('Delete link'),
592
      'help' => t('Provide a simple link to delete the content revision.'),
593
      'handler' => 'views_handler_field_node_revision_link_delete',
594
    ),
595
  );
596

    
597
  // ----------------------------------------------------------------------
598
  // Node access table
599

    
600
  // Define the base group of this table. Fields that don't
601
  // have a group defined will go into this field by default.
602
  $data['node_access']['table']['group']  = t('Content access');
603

    
604
  // For other base tables, explain how we join
605
  $data['node_access']['table']['join'] = array(
606
    // Directly links to node table.
607
    'node' => array(
608
      'left_field' => 'nid',
609
      'field' => 'nid',
610
    ),
611
  );
612
  // nid field
613
  $data['node_access']['nid'] = array(
614
    'title' => t('Access'),
615
    'help' => t('Filter by access.'),
616
    'filter' => array(
617
      'handler' => 'views_handler_filter_node_access',
618
      'help' => t('Filter for content by view access. <strong>Not necessary if you are using node as your base table.</strong>'),
619
    ),
620
  );
621

    
622
  // ----------------------------------------------------------------------
623
  // History table
624

    
625
  // We're actually defining a specific instance of the table, so let's
626
  // alias it so that we can later add the real table for other purposes if we
627
  // need it.
628
  $data['history_user']['moved to'] = 'history';
629
  $data['history']['table']['group']  = t('Content');
630

    
631
  // Explain how this table joins to others.
632
  $data['history']['table']['join'] = array(
633
     // Directly links to node table.
634
    'node' => array(
635
      'table' => 'history',
636
      'left_field' => 'nid',
637
      'field' => 'nid',
638
      'extra' => array(
639
        array('field' => 'uid', 'value' => '***CURRENT_USER***', 'numeric' => TRUE),
640
      ),
641
    ),
642
  );
643

    
644
  $data['history']['timestamp'] = array(
645
    'title' => t('Has new content'),
646
    'field' => array(
647
      'handler' => 'views_handler_field_history_user_timestamp',
648
      'help' => t('Show a marker if the content is new or updated.'),
649
    ),
650
    'filter' => array(
651
      'help' => t('Show only content that is new or updated.'),
652
      'handler' => 'views_handler_filter_history_user_timestamp',
653
    ),
654
  );
655
  return $data;
656
}
657

    
658
/**
659
 * Implements hook_views_plugins().
660
 */
661
function node_views_plugins() {
662
  return array(
663
    'module' => 'views', // This just tells our themes are elsewhere.
664
    'row' => array(
665
      'node' => array(
666
        'title' => t('Content'),
667
        'help' => t('Display the content with standard node view.'),
668
        'handler' => 'views_plugin_row_node_view',
669
        'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules
670
        'base' => array('node'), // only works with 'node' as base.
671
        'uses options' => TRUE,
672
        'type' => 'normal',
673
        'help topic' => 'style-node',
674
      ),
675
      'node_rss' => array(
676
        'title' => t('Content'),
677
        'help' => t('Display the content with standard node view.'),
678
        'handler' => 'views_plugin_row_node_rss',
679
        'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules
680
        'theme' => 'views_view_row_rss',
681
        'base' => array('node'), // only works with 'node' as base.
682
        'uses options' => TRUE,
683
        'type' => 'feed',
684
        'help topic' => 'style-node-rss',
685
      ),
686
    ),
687
    'argument validator' => array(
688
      'node' => array(
689
        'title' => t('Content'),
690
        'handler' => 'views_plugin_argument_validate_node',
691
      ),
692
    ),
693
    'argument default' => array(
694
      'node' => array(
695
        'title' => t('Content ID from URL'),
696
        'handler' => 'views_plugin_argument_default_node'
697
      ),
698
    ),
699
  );
700
}
701

    
702
/**
703
 * Implements hook_preprocess_node().
704
 */
705
function node_row_node_view_preprocess_node(&$vars) {
706
  $node = $vars['node'];
707
  $options = $vars['view']->style_plugin->row_plugin->options;
708

    
709
  // Prevent the comment form from showing up if this is not a page display.
710
  if ($vars['view_mode'] == 'full' && !$vars['view']->display_handler->has_path()) {
711
    $node->comment = FALSE;
712
  }
713

    
714
  if (!$options['links']) {
715
    unset($vars['content']['links']);
716
  }
717

    
718
  if (!empty($options['comments']) && user_access('access comments') && $node->comment) {
719
    $vars['content']['comments'] = comment_node_page_additions($node);
720
  }
721
}
722

    
723
/**
724
 * Implements hook_views_query_substitutions().
725
 */
726
function node_views_query_substitutions() {
727
  return array(
728
    '***ADMINISTER_NODES***' => intval(user_access('administer nodes')),
729
    '***VIEW_OWN_UNPUBLISHED_NODES***' => intval(user_access('view own unpublished content')),
730
    '***BYPASS_NODE_ACCESS***' =>  intval(user_access('bypass node access')),
731
  );
732
}
733

    
734
/**
735
 * Implements hook_views_analyze().
736
 */
737
function node_views_analyze($view) {
738
  $ret = array();
739
  // Check for something other than the default display:
740
  if ($view->base_table == 'node') {
741
    foreach ($view->display as $id => $display) {
742
      if (empty($display->handler)) {
743
        continue;
744
      }
745
      if (!$display->handler->is_defaulted('access') || !$display->handler->is_defaulted('filters')) {
746
        // check for no access control
747
        $access = $display->handler->get_option('access');
748
        if (empty($access['type']) || $access['type'] == 'none') {
749
          $select = db_select('role', 'r');
750
          $select->innerJoin('role_permission', 'p', 'r.rid = p.rid');
751
          $result = $select->fields('r', array('name'))
752
            ->fields('p', array('permission'))
753
            ->condition('r.name', array('anonymous user', 'authenticated user'), 'IN')
754
            ->condition('p.permission', 'access content')
755
            ->execute();
756

    
757
          foreach ($result as $role) {
758
            $role->safe = TRUE;
759
            $roles[$role->name] = $role;
760
          }
761
          if (!($roles['anonymous user']->safe && $roles['authenticated user']->safe)) {
762
            $ret[] = views_ui_analysis(t('Some roles lack permission to access content, but display %display has no access control.', array('%display' => $display->display_title)), 'warning');
763
          }
764
          $filters = $display->handler->get_option('filters');
765
          foreach ($filters as $filter) {
766
            if ($filter['table'] == 'node' && ($filter['field'] == 'status' || $filter['field'] == 'status_extra')) {
767
              continue 2;
768
            }
769
          }
770
          $ret[] = views_ui_analysis(t('Display %display has no access control but does not contain a filter for published nodes.', array('%display' => $display->display_title)), 'warning');
771
        }
772
      }
773
    }
774
  }
775
  foreach ($view->display as $id => $display) {
776
    if ($display->display_plugin == 'page') {
777
      if ($display->handler->get_option('path') == 'node/%') {
778
        $ret[] = views_ui_analysis(t('Display %display has set node/% as path. This will not produce what you want. If you want to have multiple versions of the node view, use panels.', array('%display' => $display->display_title)), 'warning');
779
      }
780
    }
781
  }
782

    
783
  return $ret;
784
}