$path = drupal_get_path('module', 'views');
require_once "./$path/theme/theme.inc";
- // Some quasi clever array merging here.
+ // Some quasi clever array merging here.
$base = array(
'file' => 'theme.inc',
'path' => "$path/theme",
$arguments = array(
'display' => array('view' => NULL),
'style' => array('view' => NULL, 'options' => NULL, 'rows' => NULL, 'title' => NULL),
- 'row' => array('view' => NULL, 'options' => NULL, 'row' => NULL),
+ 'row' => array('view' => NULL, 'options' => NULL, 'row' => NULL, 'field_alias' => NULL),
);
// Default view themes
'path' => $def['theme path'],
'arguments' => $arguments[$type],
);
+
+ $include = './' . $def['theme path'] . '/' . $def['theme file'];
+ if (file_exists($include)) {
+ require_once $include;
+ }
+
if (!function_exists('theme_' . $def['theme'])) {
$hooks[$def['theme']]['template'] = views_css_safe($def['theme']);
}
'path' => $def['theme path'],
'arguments' => $arguments[$theme_type],
);
+
if (!function_exists('theme_' . $theme)) {
$hooks[$theme]['template'] = views_css_safe($theme);
}
$hooks['views_more'] = $base + array(
'template' => 'views-more',
'pattern' => 'views_more__',
- 'arguments' => array('more_url' => NULL),
+ 'arguments' => array('more_url' => NULL, 'link_text' => 'more'),
);
return $hooks;
}
* The 'modules/node.views.inc' file is a better place for this, but
* we haven't got a chance to load that file before Drupal builds the
* node portion of the theme registry.
- *
- * @todo Remove this in Drupal 7, as it has a code registry.
*/
function views_preprocess_node(&$vars) {
// The 'view' attribute of the node is added in template_preprocess_views_view_row_node()
if (!empty($vars['node']->view) && !empty($vars['node']->view->name)) {
+ $vars['view'] = &$vars['node']->view;
$vars['template_files'][] = 'node-view-' . $vars['node']->view->name;
if(!empty($vars['node']->view->current_display)) {
- $vars['template_files'][] = 'node-view-' . $vars['node']->view->name . '-'. $vars['node']->view->current_display;
+ $vars['template_files'][] = 'node-view-' . $vars['node']->view->name . '-' . $vars['node']->view->current_display;
+ }
+ }
+}
+
+/**
+ * A theme preprocess function to automatically allow view-based node
+ * templates if called from a view.
+ */
+function views_preprocess_comment(&$vars) {
+ // The 'view' attribute of the node is added in template_preprocess_views_view_row_comment()
+ if (!empty($vars['node']->view) && !empty($vars['node']->view->name)) {
+ $vars['view'] = &$vars['node']->view;
+ $vars['template_files'][] = 'comment-view-' . $vars['node']->view->name;
+ if(!empty($vars['node']->view->current_display)) {
+ $vars['template_files'][] = 'comment-view-' . $vars['node']->view->name . '-' . $vars['node']->view->current_display;
}
}
}
/*
* Implementation of hook_perm()
*/
-function views_ui_perm() {
- return array('access all views');
+function views_perm() {
+ return array('access all views', 'administer views');
}
/**
$items['views/ajax'] = array(
'title' => 'Views',
'page callback' => 'views_ajax',
- 'access callback' => 'user_access',
- 'access arguments' => array('access content'),
+ 'access callback' => TRUE,
'description' => 'Ajax callback for view loading.',
'file' => 'includes/ajax.inc',
'type' => MENU_CALLBACK,
// of possible display IDs instead of a single ID.
$callbacks[$path]['page arguments'][1] = (array)$callbacks[$path]['page arguments'][1];
$callbacks[$path]['page arguments'][1][] = $display_id;
-// $callbacks[$path]['access arguments'][0][1] = (array)$callbacks[$path]['access arguments'][0][1];
-// $callbacks[$path]['access arguments'][0][1][] = $display_id;
$callbacks[$path]['access arguments'][] = $item['access arguments'][0];
$callbacks[$path]['load arguments'][1] = (array)$callbacks[$path]['load arguments'][1];
$callbacks[$path]['load arguments'][1][] = $display_id;
$ids = array_keys($view->argument);
$indexes = array();
- $path = explode('/', $view->get_url());
+ $path = explode('/', $view->get_path());
+
foreach ($path as $id => $piece) {
if ($piece == '%' && !empty($ids)) {
$indexes[$id] = array_shift($ids);
switch ($op) {
case 'list':
$items = array();
- $views = views_get_applicable_views('uses hook block');
- foreach ($views as $data) {
- list($view, $display_id) = $data;
- $result = $view->execute_hook_block($display_id);
- if (is_array($result)) {
- $items = array_merge($items, $result);
+ $views = views_get_all_views();
+ foreach ($views as $view) {
+ // disabled views get nothing.
+ if (!empty($view->disabled)) {
+ continue;
+ }
+
+ $view->init_display();
+ foreach ($view->display as $display_id => $display) {
+
+ if (isset($display->handler) && !empty($display->handler->definition['uses hook block'])) {
+ $result = $display->handler->execute_hook_block();
+ if (is_array($result)) {
+ $items = array_merge($items, $result);
+ }
+ }
+
+ if (isset($display->handler) && $display->handler->get_option('exposed_block')) {
+ $result = $display->handler->get_special_blocks();
+ if (is_array($result)) {
+ $items = array_merge($items, $result);
+ }
+ }
}
}
variable_set('views_block_hashes', $hashes);
// Save memory: Destroy those views.
- foreach ($views as $data) {
- list($view, $display_id) = $data;
+ foreach ($views as $view) {
$view->destroy();
}
return $items;
case 'view':
- $start = microtime();
+ $start = views_microtime();
// if this is 32, this should be an md5 hash.
if (strlen($delta) == 32) {
$hashes = variable_get('views_block_hashes', array());
}
}
+ // This indicates it's a special one.
+ if (substr($delta, 0, 1) == '-') {
+ list($nothing, $type, $name, $display_id) = explode('-', $delta);
+ // Put the - back on.
+ $type = '-' . $type;
+ if ($view = views_get_view($name)) {
+ if ($view->access($display_id)) {
+ $view->set_display($display_id);
+ if (isset($view->display_handler)) {
+ $output = $view->display_handler->view_special_blocks($type);
+ $view->destroy();
+ return $output;
+ }
+ }
+ $view->destroy();
+ }
+ }
+
list($name, $display_id) = explode('-', $delta);
// Load the view
if ($view = views_get_view($name)) {
if ($view->access($display_id)) {
$output = $view->execute_display($display_id);
- vpr("Block $view->name execute time: " . (microtime() - $start) * 1000 . "ms");
+ vpr("Block $view->name execute time: " . (views_microtime() - $start) * 1000 . "ms");
$view->destroy();
return $output;
}
+ $view->destroy();
}
break;
}
* Implementation of hook_flush_caches().
*/
function views_flush_caches() {
- return array('cache_views');
+ return array('cache_views', 'cache_views_data');
}
/**
* Load views files on behalf of modules.
*/
function views_module_include($file) {
- $views_path = drupal_get_path('module', 'views') . '/modules';
foreach (views_get_module_apis() as $module => $info) {
if (file_exists("./$info[path]/$module.$file")) {
require_once "./$info[path]/$module.$file";
* Include views .css files.
*/
function views_add_css($file) {
- drupal_add_css(drupal_get_path('module', 'views') . "/css/$file.css");
+ // We set preprocess to FALSE because we are adding the files conditionally,
+ // and we don't want to generate duplicate cache files.
+ // TODO: at some point investigate adding some files unconditionally and
+ // allowing preprocess.
+ drupal_add_css(drupal_get_path('module', 'views') . "/css/$file.css", 'module', 'all', FALSE);
}
/**
/**
* Return an array of all views as fully loaded $view objects.
+ *
+ * @param $reset
+ * If TRUE, reset the static cache forcing views to be reloaded.
*/
-function views_get_all_views() {
+function views_get_all_views($reset = FALSE) {
static $views = array();
- if (empty($views)) {
+ if (empty($views) || $reset) {
+ $views = array();
+
// First, get all applicable views.
views_include('view');
$views = view::load_views();
else {
$output = var_export($message, TRUE);
}
- drupal_set_content(variable_get('views_devel_region', 'footer'), '<pre>' . $output . '</pre>');
+ if (variable_get('views_devel_region', 'footer') != 'watchdog') {
+ drupal_set_content(variable_get('views_devel_region', 'footer'), '<pre>' . $output . '</pre>');
+ }
+ else {
+ watchdog('views_logging', '<pre>' . $output . '</pre>');
+ }
}
}
* Be sure that $view and $display are references.
*/
function views_exposed_form(&$form_state) {
+ // Don't show the form when batch operations are in progress.
+ $batch =& batch_get();
+ if (!empty($batch)) {
+ return array(
+ // Set the theme callback to be nothing to avoid errors in template_preprocess_views_exposed_form().
+ '#theme' => '',
+ );
+ }
+
// Make sure that we validate because this form might be submitted
// multiple times per page.
$form_state['must_validate'] = TRUE;
// Let form plugins know this is for exposed widgets.
$form_state['exposed'] = TRUE;
+ // Check if the form was already created
+ if ($cache = views_exposed_form_cache($view->name, $view->current_display)) {
+ return $cache;
+ }
$form['#info'] = array();
'#name' => '', // prevent from showing up in $_GET.
'#type' => 'submit',
'#value' => t('Apply'),
+ '#id' => form_clean_id('edit-submit-' . $view->name),
);
$form['#action'] = url($view->get_url());
$form['#theme'] = views_theme_functions('views_exposed_form', $view, $display);
+ $form['#id'] = views_css_safe('views_exposed_form-' . check_plain($view->name) . '-' . check_plain($display->id));
+// $form['#attributes']['class'] = array('views-exposed-form');
// If using AJAX, we need the form plugin.
if ($view->use_ajax) {
drupal_add_js('misc/jquery.form.js');
}
views_add_js('dependent');
+
+ // Save the form
+ views_exposed_form_cache($view->name, $view->current_display, $form);
+
return $form;
}
}
}
+/**
+ * Save the Views exposed form for later use.
+ *
+ * @param $views_name
+ * String. The views name.
+ * @param $display_name
+ * String. The current view display name.
+ * @param $form_output
+ * Array (optional). The form structure. Only needed when inserting the value.
+ * @return
+ * Array. The form structure, if any. Otherwise, return FALSE.
+ */
+function views_exposed_form_cache($views_name, $display_name, $form_output = NULL) {
+ static $views_exposed;
+
+ // Save the form output
+ if (!empty($form_output)) {
+ $views_exposed[$views_name][$display_name] = $form_output;
+ return;
+ }
+
+ // Return the form output, if any
+ return empty($views_exposed[$views_name][$display_name]) ? FALSE : $views_exposed[$views_name][$display_name];
+}
+
// ------------------------------------------------------------------
// Misc helpers
function views_views_query_substitutions($view) {
global $language;
return array(
+ '***CURRENT_VERSION***' => VERSION,
'***CURRENT_TIME***' => time(),
'***CURRENT_LANGUAGE***' => $language->language,
+ '***DEFAULT_LANGUAGE***' => language_default('language'),
'***NO_LANGUAGE***' => '',
);
}
}
$view = views_get_view($name);
- if (!$view) {
+ if (!$view || !$view->access($display_id)) {
return;
}
/**
* Export a field.
*/
-function views_var_export($var, $prefix = '') {
+function views_var_export($var, $prefix = '', $init = TRUE) {
if (is_array($var)) {
if (empty($var)) {
$output = 'array()';
else {
$output = "array(\n";
foreach ($var as $key => $value) {
- $output .= " '$key' => " . views_var_export($value, ' ') . ",\n";
+ $output .= " '$key' => " . views_var_export($value, ' ', FALSE) . ",\n";
}
$output .= ')';
}
else if (is_bool($var)) {
$output = $var ? 'TRUE' : 'FALSE';
}
+ else if (is_string($var) && strpos($var, "\n") !== FALSE) {
+ // Replace line breaks in strings with a token for replacement
+ // at the very end. This protects multi-line strings from
+ // unintentional indentation.
+ $var = str_replace("\n", "***BREAK***", $var);
+ $output = var_export($var, TRUE);
+ }
else {
$output = var_export($var, TRUE);
}
$output = str_replace("\n", "\n$prefix", $output);
}
+ if ($init) {
+ $output = str_replace("***BREAK***", "\n", $output);
+ }
+
return $output;
}
if ($op == 'export') {
$code = "/**\n";
- $code .= " * Implementation of hook_default_view_views().\n";
+ $code .= " * Implementation of hook_views_default_views().\n";
$code .= " */\n";
$code .= "function " . $name . "_views_default_views() {\n";
foreach ($views as $view => $truth) {
+ $code .= " /*\n";
+ $code .= " * View ". var_export($all_views[$view]->name, TRUE) ."\n";
+ $code .= " */\n";
$code .= $all_views[$view]->export(' ');
$code .= ' $views[$view->name] = $view;' . "\n\n";
}
return $code;
}
}
+
+/**
+ * Microtime helper function to return a float time value (php4 & php5 safe).
+ */
+function views_microtime() {
+ list($usec, $sec) = explode(' ', microtime());
+ return (float)$sec + (float)$usec;
+}