I'd like to add some custom php code to views header and empty text. The view works perfectly, header and empty text and all, while logged in as admin, but it doesn't show up at all for anonymous users.

Moreover, and more seriously, if I add custom PHP code in headers, anonymous users can't even see summaries, which instead they do fine if I use filtered HTML in headers.

It's as if having PHP code enabled in headers or empty text somehow "deleted" the view output.

I do not have any type of node access module enabled and, again, if I disable PHP filter in header and empty text the view works perfectly for anonymous users. As such, I do not think it's an access problem.

The permission to use PHP filter is granted only to admins, but this should not impact the visibility of the view: if an admin posts nodes with PHP code and filters, anonymous users can see and access the node fine.

Here's the export of my test view, but the bug can be reproduced in any view by choosing PHP filter in header and empty text.

$view = new view;
$view->name = 'test';
$view->description = 'PHP in header or empty text';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'title' => array(
    'label' => 'Title',
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'vid' => array(
    'default_action' => 'summary asc',
    'style_plugin' => 'default_summary',
    'style_options' => array(
      'count' => 0,
      'override' => 0,
      'items_per_page' => '25',
    ),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'summary asc',
    'id' => 'vid',
    'table' => 'vocabulary',
    'field' => 'vid',
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'webform' => 0,
      'simplenews' => 0,
      'book' => 0,
      'page' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '184' => 0,
      '183' => 0,
      '185' => 0,
      '48' => 0,
      '2' => 0,
      '49' => 0,
      '50' => 0,
      '186' => 0,
      '51' => 0,
      '187' => 0,
      '52' => 0,
      '188' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_php' => '',
  ),
  'tid' => array(
    'default_action' => 'empty',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'empty',
    'break_phrase' => 0,
    'add_table' => 0,
    'require_value' => 0,
    'reduce_duplicates' => 0,
    'set_breadcrumb' => 1,
    'id' => 'tid',
    'table' => 'term_node',
    'field' => 'tid',
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'webform' => 0,
      'simplenews' => 0,
      'book' => 0,
      'page' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '184' => 0,
      '183' => 0,
      '185' => 0,
      '48' => 0,
      '2' => 0,
      '49' => 0,
      '50' => 0,
      '186' => 0,
      '51' => 0,
      '187' => 0,
      '52' => 0,
      '188' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_php' => '',
  ),
));
$handler->override_option('filters', array(
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'page' => 'page',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
  'vid' => array(
    'operator' => 'in',
    'value' => array(
      '49' => 49,
      '50' => 50,
      '51' => 51,
      '52' => 52,
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'vid',
    'table' => 'term_data',
    'field' => 'vid',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('header', '<h2>Header</h2>
<p>This test at least should always show up! Instead it\'s not always shown!</p>

<?php

echo "This should show for everybody!";

?>');
$handler->override_option('header_format', '3');
$handler->override_option('header_empty', 1);
$handler->override_option('empty', '<h2>Empty text</h2>
<p>This test at least should always show up! Instead it\'s not always shown!</p>

<?php

echo "This should show for everybody!";

?>');
$handler->override_option('empty_format', '3');
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'test_view');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'weight' => 0,
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'weight' => 0,
));

Comments

merlinofchaos’s picture

Status: Active » Closed (duplicate)