Project

General

Profile

Paste
Download (24.7 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / views / modules / node.views.inc @ d719f12f

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']['revision'] = TRUE;
417
  $data['node_revision']['table']['group']  = t('Content revision');
418
  // Support the conversion of the field body
419
  $data['node_revisions']['body']['moved to'] = array('field_revision_data', 'body-revision_id');
420

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

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

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

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

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

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

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

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

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

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

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

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

    
598
  // ----------------------------------------------------------------------
599
  // Node access table
600

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

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

    
623
  // ----------------------------------------------------------------------
624
  // History table
625

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

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

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

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

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

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

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

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

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

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

    
758
          foreach ($result as $role) {
759
            $role->safe = TRUE;
760
            $roles[$role->name] = $role;
761
          }
762
          if (!($roles['anonymous user']->safe && $roles['authenticated user']->safe)) {
763
            $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');
764
          }
765
          $filters = $display->handler->get_option('filters');
766
          foreach ($filters as $filter) {
767
            if ($filter['table'] == 'node' && ($filter['field'] == 'status' || $filter['field'] == 'status_extra')) {
768
              continue 2;
769
            }
770
          }
771
          $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');
772
        }
773
      }
774
    }
775
  }
776
  foreach ($view->display as $id => $display) {
777
    if ($display->display_plugin == 'page') {
778
      if ($display->handler->get_option('path') == 'node/%') {
779
        $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');
780
      }
781
    }
782
  }
783

    
784
  return $ret;
785
}