class view {
var $base_table = 'node';
var $base_field = 'nid';
var $name = "";
var $description;
var $tag;
var $human_name;
var $core;
var $api_version;
var $disabled;
var $type;
var $module;
var $storage;
var $built = FALSE;
var $executed = FALSE;
var $editing = FALSE;
var $args = array();
var $build_info = array();
var $use_ajax = FALSE;
var $result = array();
var $current_page = NULL;
var $items_per_page = NULL;
var $offset = NULL;
var $total_rows = NULL;
var $attachment_before = '';
var $attachment_after = '';
var $exposed_data = array();
var $exposed_input = array();
var $exposed_raw_input = array();
var $old_view = array();
var $parent_views = array();
var $is_attachment = NULL;
var $current_display;
var $query = NULL;
var $display_handler;
var $display;
var $style_plugin;
var $style_options;
var $row_index;
var $override_url = NULL;
var $override_path = NULL;
var $base_database = NULL;
var $field;
var $argument;
var $sort;
var $filter;
var $relationship;
var $header;
var $footer;
var $empty;
function __construct($view_data = NULL) {
$this->display = array();
if ($view_data) {
foreach ($view_data as $key => $value) {
$this->$key = $value;
}
if (isset($view_data['module'])) {
$this->module = $view_data['module'];
if (empty($view_data['storage']) || $view_data['storage'] == VIEWS_STORAGE_DEFAULT) {
$this->type = t('Default');
$this->storage = VIEWS_STORAGE_DEFAULT;
}
else {
$this->type = t('Overridden');
$this->storage = VIEWS_STORAGE_OVERRIDE;
}
}
else {
$this->type = t('Normal');
$this->storage = VIEWS_STORAGE_NORMAL;
}
foreach ($this->display as $display_id => $display) {
$this->display[$display_id] = new views_display($display['display_plugin'], $display_id, $display['display_title'], $display['display_options']);
}
}
}
function update() {
$this->base_table = views_move_table($this->base_table);
}
function display_objects() {
return array('argument', 'field', 'sort', 'filter', 'relationship', 'header', 'footer', 'empty');
}
function set_arguments($args) {
$this->args = $args;
}
function set_current_page($page) {
$this->current_page = $page;
if (!empty($this->query->pager)) {
return $this->query->pager->set_current_page($page);
}
}
function get_current_page() {
if (!empty($this->query->pager)) {
return $this->query->pager->get_current_page();
}
if (isset($this->current_page)) {
return $this->current_page;
}
}
function get_items_per_page() {
if (!empty($this->query->pager)) {
return $this->query->pager->get_items_per_page();
}
if (isset($this->items_per_page)) {
return $this->items_per_page;
}
}
function set_items_per_page($items_per_page) {
$this->items_per_page = $items_per_page;
if (!empty($this->query->pager)) {
$this->query->pager->set_items_per_page($items_per_page);
}
}
function get_offset() {
if (!empty($this->query->pager)) {
return $this->query->pager->get_offset();
}
if (isset($this->offset)) {
return $this->offset;
}
}
function set_offset($offset) {
$this->offset = $offset;
if (!empty($this->query->pager)) {
$this->query->pager->set_offset($offset);
}
}
function use_pager() {
if (!empty($this->query->pager)) {
return $this->query->pager->use_pager();
}
}
function set_use_ajax($use_ajax) {
$this->use_ajax = $use_ajax;
}
function set_exposed_input($filters) {
$this->exposed_input = $filters;
}
function get_exposed_input() {
if (empty($this->exposed_input)) {
$this->exposed_input = $_GET;
foreach (array('page', 'q') as $key) {
if (isset($this->exposed_input[$key])) {
unset($this->exposed_input[$key]);
}
}
$display_id = ($this->display_handler->is_defaulted('filters')) ? 'default' : $this->current_display;
if (empty($this->exposed_input) && !empty($_SESSION['views'][$this->name][$display_id])) {
$this->exposed_input = $_SESSION['views'][$this->name][$display_id];
}
}
return $this->exposed_input;
}
function init_display($reset = FALSE) {
if (isset($this->current_display)) {
return TRUE;
}
foreach (array_keys($this->display) as $id) {
if (!empty($this->display[$id]->handler)) {
$this->display[$id] = clone $this->display[$id];
unset($this->display[$id]->handler);
}
$this->display[$id]->handler = views_get_plugin('display', $this->display[$id]->display_plugin);
if (!empty($this->display[$id]->handler)) {
$this->display[$id]->handler->localization_keys = array($id);
$this->display[$id]->handler->init($this, $this->display[$id]);
if ($id != 'default') {
$this->display[$id]->handler->default_display = &$this->display['default']->handler;
}
}
}
$this->current_display = 'default';
$this->display_handler = &$this->display['default']->handler;
return TRUE;
}
function choose_display($displays) {
if (!is_array($displays)) {
return $displays;
}
$this->init_display();
foreach ($displays as $display_id) {
if ($this->display[$display_id]->handler->access()) {
return $display_id;
}
}
return 'default';
}
function set_display($display_id = NULL) {
if (empty($this->current_display)) {
$this->init_display();
if (empty($display_id)) {
$display_id = 'default';
}
}
$display_id = $this->choose_display($display_id);
if (empty($display_id)) {
return FALSE;
}
if (empty($this->display[$display_id])) {
$display_id = 'default';
if (empty($this->display[$display_id])) {
watchdog('views', 'set_display() called with invalid display id @display.', array('@display' => $display_id));
return FALSE;
}
}
$this->current_display = $display_id;
if (empty($this->display[$display_id]->handler)) {
return FALSE;
}
$this->display_handler = &$this->display[$display_id]->handler;
return TRUE;
}
function init_style() {
if (isset($this->style_plugin)) {
return is_object($this->style_plugin);
}
if (!isset($this->plugin_name)) {
$this->plugin_name = $this->display_handler->get_option('style_plugin');
$this->style_options = $this->display_handler->get_option('style_options');
}
$this->style_plugin = views_get_plugin('style', $this->plugin_name);
if (empty($this->style_plugin)) {
return FALSE;
}
$this->style_plugin->init($this, $this->display[$this->current_display], $this->style_options);
return TRUE;
}
function fix_missing_relationships() {
if (isset($this->relationships_fixed)) {
return;
}
$this->relationships_fixed = TRUE;
$base_tables = array(
$this->base_table => TRUE,
'#global' => TRUE,
);
foreach ($this->display_handler->get_option('relationships') as $id => $options) {
$options['table'] = views_move_table($options['table']);
$data = views_fetch_data($options['table'], FALSE);
if (isset($data[$options['field']]['relationship']['base'])) {
$base_tables[$data[$options['field']]['relationship']['base']] = TRUE;
}
}
$base_tables = array_keys($base_tables);
$missing_base_tables = array();
$types = views_object_types();
foreach ($types as $key => $info) {
foreach ($this->display_handler->get_option($info['plural']) as $id => $options) {
$options['table'] = views_move_table($options['table']);
$data = views_fetch_data($options['table'], FALSE);
$valid_bases = array($options['table']);
if (isset($data['table']['join'])) {
$valid_bases = array_merge($valid_bases, array_keys($data['table']['join']));
}
if (!array_intersect($valid_bases, $base_tables)) {
$missing_base_tables[$options['table']][] = array('type' => $key, 'id' => $id);
}
}
}
if (!empty($missing_base_tables)) {
$this->display_handler->handlers = array();
$this->relationships_changed = TRUE;
$this->changed = TRUE;
foreach ($missing_base_tables as $table => $handlers) {
$data = views_fetch_data($table);
$relationship = NULL;
if (isset($data['table']['default_relationship'][$this->base_table])) {
$info = $data['table']['default_relationship'][$this->base_table];
$relationship_options = isset($info['options']) ? $info['options'] : array();
$relationship = $this->add_item($this->current_display, 'relationship', $info['table'], $info['field'], $relationship_options);
}
foreach ($handlers as $handler) {
$options = $this->display_handler->get_option($types[$handler['type']]['plural']);
if ($relationship) {
$options[$handler['id']]['relationship'] = $relationship;
}
else {
unset($options[$handler['id']]);
}
$this->display_handler->set_option($types[$handler['type']]['plural'], $options);
}
}
}
}
function init_handlers() {
if (empty($this->inited)) {
$this->fix_missing_relationships();
foreach (views_object_types() as $key => $info) {
$this->_init_handler($key, $info);
}
$this->inited = TRUE;
}
}
function init_pager() {
if (empty($this->query->pager)) {
$this->query->pager = $this->display_handler->get_plugin('pager');
if ($this->query->pager->use_pager()) {
$this->query->pager->set_current_page($this->current_page);
}
if (isset($this->items_per_page)) {
$this->query->pager->set_items_per_page($this->items_per_page);
}
if (isset($this->offset)) {
$this->query->pager->set_offset($this->offset);
}
}
}
function get_base_tables() {
$base_tables = array(
$this->base_table => TRUE,
'#global' => TRUE,
);
foreach ($this->display_handler->get_handlers('relationship') as $handler) {
$base_tables[$handler->definition['base']] = TRUE;
}
return $base_tables;
}
function _pre_query() {
foreach (views_object_types() as $key => $info) {
$handlers = &$this->$key;
$position = 0;
foreach ($handlers as $id => $handler) {
$handlers[$id]->position = $position;
$handlers[$id]->pre_query();
$position++;
}
}
}
function _post_execute() {
foreach (views_object_types() as $key => $info) {
$handlers = &$this->$key;
foreach ($handlers as $id => $handler) {
$handlers[$id]->post_execute($this->result);
}
}
}
function _init_handler($key, $info) {
$this->$key = $this->display_handler->get_handlers($key);
$handlers = &$this->$key;
foreach ($handlers as $id => $handler) {
if (!$handler->access()) {
unset($handlers[$id]);
}
}
}
function _build_arguments() {
if (empty($this->argument)) {
return TRUE;
}
$position = -1;
$title = $this->display_handler->get_option('title');
$this->build_info['breadcrumb'] = array();
$breadcrumb_args = array();
$substitutions = array();
$status = TRUE;
foreach ($this->argument as $id => $arg) {
$position++;
$argument = &$this->argument[$id];
if ($argument->broken()) {
continue;
}
$argument->set_relationship();
$arg = isset($this->args[$position]) ? $this->args[$position] : NULL;
$argument->position = $position;
if (isset($arg) || $argument->has_default_argument()) {
if (!isset($arg)) {
$arg = $argument->get_default_argument();
if (isset($arg)) {
$this->args[$position] = $arg;
}
$argument->is_default = TRUE;
}
if (!$argument->set_argument($arg)) {
$status = $argument->validate_fail($arg);
break;
}
if ($argument->is_exception()) {
$arg_title = $argument->exception_title();
}
else {
$arg_title = $argument->get_title();
$argument->query($this->display_handler->use_group_by());
}
$substitutions['%' . ($position + 1)] = $arg_title;
$substitutions['!' . ($position + 1)] = strip_tags(decode_entities($arg));
if ($this->display_handler->uses_breadcrumb() && $argument->uses_breadcrumb()) {
$path = $this->get_url($breadcrumb_args);
if (strpos($path, '%') === FALSE) {
if (!empty($argument->options['breadcrumb_enable']) && !empty($argument->options['breadcrumb'])) {
$breadcrumb = $argument->options['breadcrumb'];
}
else {
$breadcrumb = $title;
}
$this->build_info['breadcrumb'][$path] = str_replace(array_keys($substitutions), $substitutions, $breadcrumb);
}
}
$argument->set_breadcrumb($this->build_info['breadcrumb']);
if (!empty($argument->options['title_enable']) && !empty($argument->options['title'])) {
$title = $argument->options['title'];
}
$breadcrumb_args[] = $arg;
}
else {
$status = $argument->default_action();
break;
}
unset($argument);
}
if (!empty($title)) {
$this->build_info['title'] = $title;
}
$this->build_info['substitutions'] = $substitutions;
return $status;
}
function init_query() {
if (!empty($this->query)) {
$class = get_class($this->query);
if ($class && $class != 'stdClass') {
return TRUE;
}
}
$views_data = views_fetch_data($this->base_table);
$this->base_field = !empty($views_data['table']['base']['field']) ? $views_data['table']['base']['field'] : '';
if (!empty($views_data['table']['base']['database'])) {
$this->base_database = $views_data['table']['base']['database'];
}
$query_options = $this->display_handler->get_option('query');
$plugin = !empty($views_data['table']['base']['query class']) ? $views_data['table']['base']['query class'] : 'views_query';
$this->query = views_get_plugin('query', $plugin);
if (empty($this->query)) {
return FALSE;
}
$this->query->init($this->base_table, $this->base_field, $query_options['options']);
return TRUE;
}
function build($display_id = NULL) {
if (!empty($this->built)) {
return;
}
if (empty($this->current_display) || $display_id) {
if (!$this->set_display($display_id)) {
return FALSE;
}
}
foreach (module_implements('views_pre_build') as $module) {
$function = $module . '_views_pre_build';
$function($this);
}
$start = microtime(TRUE);
$this->build_info = array(
'query' => '',
'count_query' => '',
'query_args' => array(),
);
$this->init_query();
$this->init_handlers();
$this->_pre_query();
if ($this->display_handler->uses_exposed()) {
$exposed_form = $this->display_handler->get_plugin('exposed_form');
$errors_before = form_set_error();
$this->exposed_widgets = $exposed_form->render_exposed_form();
$errors_after = form_set_error();
$exposed_errors = count($errors_after) > count($errors_before);
if ($exposed_errors || !empty($this->build_info['abort'])) {
$this->built = TRUE;
$this->executed = TRUE;
return empty($this->build_info['fail']);
}
}
$this->_build('relationship');
if (!empty($this->filter)) {
$filter_groups = $this->display_handler->get_option('filter_groups');
if ($filter_groups) {
$this->query->set_group_operator($filter_groups['operator']);
foreach ($filter_groups['groups'] as $id => $operator) {
$this->query->set_where_group($operator, $id);
}
}
}
$this->_build('filter');
$this->build_sort = TRUE;
if (!$this->_build_arguments()) {
$this->build_time = microtime(TRUE) - $start;
$this->attach_displays();
return $this->built;
}
if (!$this->init_style()) {
$this->build_info['fail'] = TRUE;
return FALSE;
}
if ($this->style_plugin->uses_fields()) {
$this->_build('field');
}
if (!empty($this->build_sort)) {
if ($this->style_plugin->build_sort()) {
$this->_build('sort');
}
$this->style_plugin->build_sort_post();
}
$this->_build('header');
$this->_build('footer');
$this->_build('empty');
$this->display_handler->query($this->display_handler->use_group_by());
$this->style_plugin->query($this->display_handler->use_group_by());
if (isset($exposed_form)) {
$exposed_form->query();
}
if (config_get('views.settings', 'sql_signature')) {
$this->query->add_signature($this);
}
$this->query->alter($this);
if (empty($this->built)) {
$this->query->build($this);
}
$this->built = TRUE;
$this->build_time = microtime(TRUE) - $start;
$this->attach_displays();
foreach (module_implements('views_post_build') as $module) {
$function = $module . '_views_post_build';
$function($this);
}
return TRUE;
}
function _build($key) {
$handlers = &$this->$key;
foreach ($handlers as $id => $data) {
if (!empty($handlers[$id]) && is_object($handlers[$id])) {
$multiple_exposed_input = array(0 => NULL);
if ($handlers[$id]->multiple_exposed_input()) {
$multiple_exposed_input = $handlers[$id]->group_multiple_exposed_input($this->exposed_data);
}
foreach ($multiple_exposed_input as $group_id) {
if (!empty($this->exposed_data)) {
$converted = FALSE;
if ($handlers[$id]->is_a_group()) {
$converted = $handlers[$id]->convert_exposed_input($this->exposed_data, $group_id);
$handlers[$id]->store_group_input($this->exposed_data, $converted);
if (!$converted) {
continue;
}
}
$rc = $handlers[$id]->accept_exposed_input($this->exposed_data);
$handlers[$id]->store_exposed_input($this->exposed_data, $rc);
if (!$rc) {
continue;
}
}
$handlers[$id]->set_relationship();
$handlers[$id]->query($this->display_handler->use_group_by());
}
}
}
}
function execute($display_id = NULL) {
if (empty($this->built)) {
if (!$this->build($display_id)) {
return FALSE;
}
}
if (!empty($this->executed)) {
return TRUE;
}
if (!$this->display[$this->current_display]->handler->get_option('enabled') && empty($this->live_preview)) {
$this->build_info['fail'] = TRUE;
return FALSE;
}
foreach (module_implements('views_pre_execute') as $module) {
$function = $module . '_views_pre_execute';
$function($this);
}
if (!empty($this->live_preview)) {
$cache = FALSE;
}
else {
$cache = $this->display_handler->get_plugin('cache');
}
if ($cache && $cache->cache_get('results')) {
if ($this->query->pager->use_pager() || !empty($this->get_total_rows)) {
$this->query->pager->total_items = $this->total_rows;
$this->query->pager->update_page_info();
}
}
else {
$this->query->execute($this);
$this->result = array_values($this->result);
$this->_post_execute();
if ($cache) {
$cache->cache_set('results');
}
}
foreach (module_implements('views_post_execute') as $module) {
$function = $module . '_views_post_execute';
$function($this);
}
$this->executed = TRUE;
}
function render($display_id = NULL) {
$this->execute($display_id);
$show_additional_queries = config_get('views.settings', 'show_additional_queries');
if (!empty($this->build_info['fail'])) {
return;
}
if (!empty($this->build_info['denied'])) {
return;
}
backdrop_theme_initialize();
$start = microtime(TRUE);
if (!empty($this->live_preview) && $show_additional_queries) {
$this->start_query_capture();
}
$exposed_form = $this->display_handler->get_plugin('exposed_form');
$exposed_form->pre_render($this->result);
if (!empty($this->live_preview)) {
$cache = FALSE;
}
else {
$cache = $this->display_handler->get_plugin('cache');
}
if ($cache && $cache->cache_get('output')) {
}
else {
if ($cache) {
$cache->cache_start();
}
if (!empty($this->query->pager)) {
$this->query->pager->pre_render($this->result);
}
$this->init_style();
if ($this->style_plugin->uses_fields()) {
foreach ($this->field as $id => $handler) {
if (!empty($this->field[$id])) {
$this->field[$id]->pre_render($this->result);
}
}
}
$this->style_plugin->pre_render($this->result);
foreach (module_implements('views_pre_render') as $module) {
$function = $module . '_views_pre_render';
$function($this);
}
foreach ($GLOBALS['base_theme_info'] as $base) {
$function = $base->name . '_views_pre_render';
if (function_exists($function)) {
$function($this);
}
}
$function = $GLOBALS['theme'] . '_views_pre_render';
if (function_exists($function)) {
$function($this);
}
$this->display_handler->output = $this->display_handler->render();
if ($cache) {
$cache->cache_set('output');
}
}
$this->render_time = microtime(TRUE) - $start;
$exposed_form->post_render($this->display_handler->output);
if ($cache) {
$cache->post_render($this->display_handler->output);
}
foreach (module_implements('views_post_render') as $module) {
$function = $module . '_views_post_render';
$function($this, $this->display_handler->output, $cache);
}
foreach ($GLOBALS['base_theme_info'] as $base) {
$function = $base->name . '_views_post_render';
if (function_exists($function)) {
$function($this);
}
}
$function = $GLOBALS['theme'] . '_views_post_render';
if (function_exists($function)) {
$function($this, $this->display_handler->output, $cache);
}
if (!empty($this->live_preview) && $show_additional_queries) {
$this->end_query_capture();
}
return $this->display_handler->output;
}
function render_field($field, $row) {
if (isset($this->field[$field]) && isset($this->result[$row])) {
return $this->field[$field]->advanced_render($this->result[$row]);
}
}
function execute_display($display_id = NULL, $args = array()) {
if (empty($this->current_display) || $this->current_display != $this->choose_display($display_id)) {
if (!$this->set_display($display_id)) {
return FALSE;
}
}
$this->pre_execute($args);
$output = $this->display_handler->execute();
$this->post_execute();
return $output;
}
function preview($display_id = NULL, $args = array()) {
if (empty($this->current_display) || ((!empty($display_id)) && $this->current_display != $display_id)) {
if (!$this->set_display($display_id)) {
return FALSE;
}
}
$this->preview = TRUE;
$this->pre_execute($args);
$output = $this->display_handler->preview();
$this->post_execute();
return $output;
}
function pre_execute($args = array()) {
$this->old_view[] = views_get_current_view();
views_set_current_view($this);
$display_id = $this->current_display;
if ($args) {
$this->set_arguments($args);
}
foreach (module_implements('views_pre_view') as $module) {
$function = $module . '_views_pre_view';
$function($this, $display_id, $this->args);
}
$this->dom_id = !empty($this->dom_id) ? $this->dom_id : md5($this->name . REQUEST_TIME . rand());
$this->display_handler->pre_execute();
}
function post_execute() {
if ($this->old_view) {
$old_view = array_pop($this->old_view);
}
views_set_current_view(isset($old_view) ? $old_view : FALSE);
}
function attach_displays() {
if (!empty($this->is_attachment)) {
return;
}
if (!$this->display_handler->accept_attachments()) {
return;
}
$this->is_attachment = TRUE;
foreach ($this->display as $id => $display) {
if (!empty($this->display[$id]->handler)) {
$this->display[$id]->handler->attach_to($this->current_display);
}
}
$this->is_attachment = FALSE;
}
function execute_hook_menu($display_id = NULL, &$callbacks = array()) {
if (!$this->set_display($display_id)) {
return FALSE;
}
if (isset($this->display_handler)) {
return $this->display_handler->execute_hook_menu($callbacks);
}
}
function execute_hook_block_list($display_id = NULL) {
if (!$this->set_display($display_id)) {
return FALSE;
}
if (isset($this->display_handler)) {
return $this->display_handler->execute_hook_block_list();
}
}
function access($displays = NULL, $account = NULL) {
if (!empty($this->disabled)) {
return FALSE;
}
if (!isset($this->current_display)) {
$this->init_display();
}
if (!$account) {
$account = $GLOBALS['user'];
}
$displays = (array) $displays;
foreach ($displays as $display_id) {
if (!empty($this->display[$display_id]->handler)) {
if ($this->display[$display_id]->handler->access($account)) {
return TRUE;
}
}
}
return FALSE;
}
function get_title() {
if (empty($this->display_handler)) {
if (!$this->set_display('default')) {
return FALSE;
}
}
if (!empty($this->build_info['title'])) {
$title = $this->build_info['title'];
}
else {
$title = $this->display_handler->get_option('title');
}
if ($this->init_style()) {
$title = $this->style_plugin->tokenize_value($title, 0);
}
return $title;
}
function set_title($title) {
$this->build_info['title'] = $title;
return TRUE;
}
function get_human_name() {
if (!empty($this->human_name)) {
$human_name = $this->human_name;
}
else {
$human_name = $this->name;
}
return $human_name;
}
function build_title() {
$this->init_display();
if (empty($this->built)) {
$this->init_query();
}
$this->init_handlers();
$this->_build_arguments();
}
function get_url($args = NULL, $path = NULL) {
if (!empty($this->override_url)) {
return $this->override_url;
}
if (!isset($path)) {
$path = $this->get_path();
}
if (!isset($args)) {
$args = $this->args;
$position = 0;
if (!empty($this->argument)) {
foreach ($this->argument as $argument_id => $argument) {
if (!empty($argument->is_default) && !empty($argument->options['default_argument_skip_url'])) {
unset($args[$position]);
}
$position++;
}
}
}
if (empty($path) || (empty($args) && strpos($path, '%') === FALSE)) {
return $path;
}
$pieces = array();
$argument_keys = isset($this->argument) ? array_keys($this->argument) : array();
$id = current($argument_keys);
foreach (explode('/', $path) as $piece) {
if ($piece != '%') {
$pieces[] = $piece;
}
else {
if (empty($args)) {
if ($id && !empty($this->argument[$id]->options['exception']['value'])) {
$pieces[] = $this->argument[$id]->options['exception']['value'];
}
else {
$pieces[] = '*'; }
}
else {
$pieces[] = array_shift($args);
}
if ($id) {
$id = next($argument_keys);
}
}
}
if (!empty($args)) {
$pieces = array_merge($pieces, $args);
}
return implode('/', $pieces);
}
function get_path() {
if (!empty($this->override_path)) {
return $this->override_path;
}
if (empty($this->display_handler)) {
if (!$this->set_display('default')) {
return FALSE;
}
}
return $this->display_handler->get_path();
}
function get_breadcrumb($set = FALSE) {
$base = TRUE;
$breadcrumb = array();
if (!empty($this->build_info['breadcrumb'])) {
foreach ($this->build_info['breadcrumb'] as $path => $title) {
if ($path == config_get('system.core', 'site_frontpage')) {
$base = FALSE;
$title = t('Home');
}
if ($title) {
$breadcrumb[] = l($title, $path, array('html' => TRUE));
}
}
if ($set) {
if ($base) {
$breadcrumb = array_merge(backdrop_get_breadcrumb(), $breadcrumb);
}
backdrop_set_breadcrumb($breadcrumb);
}
}
return $breadcrumb;
}
function is_cacheable() {
return $this->is_cacheable;
}
function start_query_capture() {
global $conf, $queries;
if (empty($conf['dev_query'])) {
$this->fix_dev_query = TRUE;
$conf['dev_query'] = TRUE;
}
$this->last_query_key = NULL;
if (!empty($queries)) {
$keys = array_keys($queries);
$this->last_query_key = array_pop($keys);
}
}
function end_query_capture() {
global $conf, $queries;
if (!empty($this->fix_dev_query)) {
$conf['dev_query'] = FALSE;
}
$temp = $queries;
if (isset($this->last_query_key)) {
foreach ($queries as $id => $query) {
if ($id == $this->last_query_key) {
break;
}
unset($temp[$id]);
}
}
$this->additional_queries = $temp;
}
function save() {
$config_data = array(
'name' => $this->name,
'description' => $this->description,
);
if ($this->module) {
$config_data['module'] = $this->module;
$config_data['storage'] = VIEWS_STORAGE_OVERRIDE;
}
$config_data += array(
'tag' => $this->tag,
'disabled' => (boolean) $this->disabled,
'base_table' => $this->base_table,
'human_name' => $this->human_name,
'core' => $this->core,
'display' => array(),
);
foreach ($this->display as $display) {
$display_config_data = array(
'display_title' => $display->display_title,
'display_plugin' => $display->display_plugin,
'display_options' => $display->display_options,
);
$config_data['display'][$display->id] = $display_config_data;
}
if (property_exists($this, 'locked')) {
unset($this->locked);
}
config('views.view.' . $this->name)->setData($config_data)->save();
$this->save_locale_strings();
views_invalidate_cache();
}
function delete($clear = TRUE) {
config('views.view.' . $this->name)->delete();
cache('views')->deletePrefix('views_query:' . $this->name);
if ($clear) {
views_invalidate_cache();
}
}
function revert($clear = TRUE) {
config('views.view.' . $this->name)->delete();
config_install_default_config($this->module, 'views.view.' . $this->name);
cache('views')->deletePrefix('views_query:' . $this->name);
if ($clear) {
views_invalidate_cache();
}
}
function clone_view() {
$clone = clone($this);
$keys = array('current_display', 'display_handler', 'build_info', 'built', 'executed', 'attachment_before', 'attachment_after', 'field', 'argument', 'filter', 'sort', 'relationship', 'header', 'footer', 'empty', 'query', 'inited', 'style_plugin', 'plugin_name', 'exposed_data', 'exposed_input', 'exposed_widgets', 'many_to_one_tables', 'feed_icon');
foreach ($keys as $key) {
if (isset($clone->$key)) {
unset($clone->$key);
}
}
$clone->built = $clone->executed = FALSE;
$clone->build_info = array();
$clone->attachment_before = '';
$clone->attachment_after = '';
$clone->result = array();
$displays = array();
foreach ($clone->display as $id => $display) {
$displays[$id] = clone $display;
if (isset($displays[$id]->handler)) {
unset($displays[$id]->handler);
}
}
$clone->display = $displays;
return $clone;
}
function destroy() {
foreach (array_keys($this->display) as $display_id) {
if (isset($this->display[$display_id]->handler)) {
$this->display[$display_id]->handler->destroy();
unset($this->display[$display_id]->handler);
}
}
foreach (views_object_types() as $type => $info) {
if (isset($this->$type)) {
$handlers = &$this->$type;
foreach ($handlers as $id => $item) {
$handlers[$id]->destroy();
}
unset($handlers);
}
}
if (isset($this->style_plugin)) {
$this->style_plugin->destroy();
unset($this->style_plugin);
}
if (isset($this->display_handler)) {
unset($this->display_handler);
}
if (isset($this->current_display)) {
unset($this->current_display);
}
if (isset($this->query)) {
unset($this->query);
}
$keys = array('current_display', 'display_handler', 'build_info', 'built', 'executed', 'attachment_before', 'attachment_after', 'field', 'argument', 'filter', 'sort', 'relationship', 'header', 'footer', 'empty', 'query', 'result', 'inited', 'style_plugin', 'plugin_name', 'exposed_data', 'exposed_input', 'many_to_one_tables');
foreach ($keys as $key) {
if (isset($this->$key)) {
unset($this->$key);
}
}
$keys = array('items_per_page', 'offset', 'current_page');
foreach ($keys as $key) {
if (isset($this->$key)) {
$this->$key = NULL;
}
}
$this->built = $this->executed = FALSE;
$this->build_info = array();
$this->attachment_before = '';
$this->attachment_after = '';
}
function validate() {
$this->init_display();
$errors = array();
$this->display_errors = NULL;
$current_display = $this->current_display;
foreach ($this->display as $id => $display) {
if ($display->handler) {
if (!empty($display->deleted)) {
continue;
}
$result = $this->display[$id]->handler->validate();
if (!empty($result) && is_array($result)) {
$errors = array_merge($errors, $result);
$this->display_errors[$id] = TRUE;
}
}
}
$this->set_display($current_display);
return $errors ? $errors : TRUE;
}
public function init_localization() {
if (!isset($this->localization_plugin->translate)) {
$this->localization_plugin = views_get_plugin('localization', views_get_localization_plugin());
if (empty($this->localization_plugin)) {
$this->localization_plugin = views_get_plugin('localization', 'none');
if (is_null($this->localization_plugin)) {
return FALSE;
}
}
$this->localization_plugin->init($this);
}
return $this->localization_plugin->translate;
}
function is_translatable() {
return (!isset($this->type) || in_array($this->type, array(t('Normal'), t('Overridden')))) ? TRUE : FALSE;
}
public function save_locale_strings() {
$this->process_locale_strings('save');
}
public function delete_locale_strings() {
$this->process_locale_strings('delete');
}
public function process_locale_strings($op) {
if ($this->is_translatable() && $this->init_display() && $this->init_localization()) {
$this->localization_plugin->process_locale_strings($op);
}
}
function add_display($type = 'page', $title = NULL, $id = NULL) {
if (empty($type)) {
return FALSE;
}
$plugin = views_fetch_plugin_data('display', $type);
if (empty($plugin)) {
$plugin['title'] = t('Broken');
}
if (empty($id)) {
$id = $this->generate_display_id($type);
if ($id !== 'default') {
preg_match("/[0-9]+/", $id, $count);
$count = $count[0];
}
else {
$count = '';
}
if (empty($title)) {
if ($count > 1) {
$title = $plugin['title'] . ' ' . $count;
}
else {
$title = $plugin['title'];
}
}
}
$display = new views_display($type, $id, $title);
$this->display[$id] = $display;
return $id;
}
function generate_display_id($type) {
if ($type == 'default') {
return 'default';
}
$id = $type . '_1';
$count = 1;
while (!empty($this->display[$id])) {
$id = $type . '_' . ++$count;
}
return $id;
}
public static function generate_item_id($requested_id, $existing_items) {
$count = 0;
$id = $requested_id;
while (!empty($existing_items[$id])) {
$id = $requested_id . '_' . ++$count;
}
return $id;
}
function &new_display($type = 'page', $title = NULL, $id = NULL) {
$id = $this->add_display($type, $title, $id);
$this->display[$id]->handler = views_get_plugin('display', $this->display[$id]->display_plugin);
if (empty($this->display[$id]->handler)) {
$this->display[$id]->handler = views_get_plugin('display', 'default');
}
if (!empty($this->display[$id]->handler)) {
$this->display[$id]->handler->init($this, $this->display[$id]);
if ($id != 'default') {
$this->display[$id]->handler->default_display = &$this->display['default']->handler;
}
}
return $this->display[$id]->handler;
}
function add_item($display_id, $type, $table, $field, $options = array(), $id = NULL) {
$types = views_object_types();
$this->set_display($display_id);
$fields = $this->display[$display_id]->handler->get_option($types[$type]['plural']);
if (empty($id)) {
$id = $this->generate_item_id($field, $fields);
}
$new_item = array(
'id' => $id,
'table' => $table,
'field' => $field,
) + $options;
if (!empty($types[$type]['type'])) {
$handler_type = $types[$type]['type'];
}
else {
$handler_type = $type;
}
$handler = views_get_handler($table, $field, $handler_type);
$fields[$id] = $new_item;
$this->display[$display_id]->handler->set_option($types[$type]['plural'], $fields);
return $id;
}
function get_items($type, $display_id = NULL) {
$this->set_display($display_id);
if (!isset($display_id)) {
$display_id = $this->current_display;
}
$types = views_object_types();
return $this->display[$display_id]->handler->get_option($types[$type]['plural']);
}
function get_item($display_id, $type, $id) {
$types = views_object_types();
$this->set_display($display_id);
$fields = $this->display[$display_id]->handler->get_option($types[$type]['plural']);
return isset($fields[$id]) ? $fields[$id] : NULL;
}
function set_item($display_id, $type, $id, $item) {
$types = views_object_types();
$this->set_display($display_id);
$fields = $this->display[$display_id]->handler->get_option($types[$type]['plural']);
if (isset($item)) {
$fields[$id] = $item;
}
else {
unset($fields[$id]);
}
$this->display[$display_id]->handler->set_option($types[$type]['plural'], $fields);
}
function set_item_option($display_id, $type, $id, $option, $value) {
$item = $this->get_item($display_id, $type, $id);
$item[$option] = $value;
$this->set_item($display_id, $type, $id, $item);
}
}