5 * Primarily Drupal hooks and global API functions to manipulate views.
7 * This is the main module file for Views. The main entry points into
8 * this module are views_page() and views_block(), where it handles
9 * incoming page and block requests.
13 * Advertise the current views api version
15 function views_api_version() {
20 * Implementation of hook_theme(). Register views theming functions.
22 function views_theme() {
23 $path = drupal_get_path('module', 'views');
24 require_once
"./$path/theme/theme.inc";
26 // Some quasi clever array merging here.
28 'file' => 'theme.inc',
29 'path' => "$path/theme",
32 // Our extra version of pager from pager.inc
33 $hooks['views_mini_pager'] = $base + array(
34 'arguments' => array('tags' => array(), 'limit' => 10, 'element' => 0, 'parameters' => array()),
35 'pattern' => 'views_mini_pager__',
39 'display' => array('view' => NULL
),
40 'style' => array('view' => NULL
, 'options' => NULL
, 'rows' => NULL
, 'title' => NULL
),
41 'row' => array('view' => NULL
, 'options' => NULL
, 'row' => NULL
),
44 // Default view themes
45 $hooks['views_view_field'] = $base + array(
46 'pattern' => 'views_view_field__',
47 'arguments' => array('view' => NULL
, 'field' => NULL
, 'row' => NULL
),
50 $plugins = views_fetch_plugin_data();
52 // Register theme functions for all style plugins
53 foreach ($plugins as
$type => $info) {
54 foreach ($info as
$plugin => $def) {
55 if (isset($def['theme'])) {
56 $hooks[$def['theme']] = array(
57 'pattern' => $def['theme'] .
'__',
58 'file' => $def['theme file'],
59 'path' => $def['theme path'],
60 'arguments' => $arguments[$type],
62 if (!function_exists('theme_' .
$def['theme'])) {
63 $hooks[$def['theme']]['template'] = views_css_safe($def['theme']);
66 if (isset($def['additional themes'])) {
67 foreach ($def['additional themes'] as
$theme => $theme_type) {
68 if (empty($theme_type)) {
73 $hooks[$theme] = array(
74 'pattern' => $theme .
'__',
75 'file' => $def['theme file'],
76 'path' => $def['theme path'],
77 'arguments' => $arguments[$theme_type],
79 if (!function_exists('theme_' .
$theme)) {
80 $hooks[$theme]['template'] = views_css_safe($theme);
87 $hooks['views_exposed_form'] = $base + array(
88 'template' => 'views-exposed-form',
89 'pattern' => 'views_exposed_form__',
90 'arguments' => array('form' => NULL
),
93 $hooks['views_more'] = $base + array(
94 'template' => 'views-more',
95 'pattern' => 'views_more__',
96 'arguments' => array('more_url' => NULL
),
102 * A theme preprocess function to automatically allow view-based node
103 * templates if called from a view.
105 * The 'modules/node.views.inc' file is a better place for this, but
106 * we haven't got a chance to load that file before Drupal builds the
107 * node portion of the theme registry.
109 * @todo Remove this in Drupal 7, as it has a code registry.
111 function views_preprocess_node(&$vars) {
112 // The 'view' attribute of the node is added in template_preprocess_views_view_row_node()
113 if (!empty($vars['node']->view
) && !empty($vars['node']->view
->name
)) {
114 $vars['template_files'][] = 'node-view-' .
$vars['node']->view
->name
;
115 if(!empty($vars['node']->view
->current_display
)) {
116 $vars['template_files'][] = 'node-view-' .
$vars['node']->view
->name .
'-'.
$vars['node']->view
->current_display
;
122 * Implementation of hook_perm()
124 function views_ui_perm() {
125 return array('access all views');
129 * Implementation of hook_menu().
131 function views_menu() {
132 // Any event which causes a menu_rebuild could potentially mean that the
133 // Views data is updated -- module changes, profile changes, etc.
134 views_invalidate_cache();
136 $items['views/ajax'] = array(
138 'page callback' => 'views_ajax',
139 'access callback' => 'user_access',
140 'access arguments' => array('access content'),
141 'description' => 'Ajax callback for view loading.',
142 'file' => 'includes/ajax.inc',
143 'type' => MENU_CALLBACK
,
145 // Path is not admin/build/views due to menu complications with the wildcards from
146 // the generic ajax callback.
147 $items['admin/views/ajax/autocomplete/user'] = array(
148 'page callback' => 'views_ajax_autocomplete_user',
149 'access callback' => 'user_access',
150 'access arguments' => array('access content'),
151 'file' => 'includes/ajax.inc',
152 'type' => MENU_CALLBACK
,
158 * Implementation of hook_menu_alter().
160 function views_menu_alter(&$callbacks) {
161 $our_paths = array();
162 $views = views_get_applicable_views('uses hook menu');
163 foreach ($views as
$data) {
164 list($view, $display_id) = $data;
165 $result = $view->execute_hook_menu($display_id);
166 if (is_array($result)) {
167 // The menu system doesn't support having two otherwise
168 // identical paths with different placeholders. So we
169 // want to remove the existing items from the menu whose
170 // paths would conflict with ours.
172 // First, we must find any existing menu items that may
173 // conflict. We use a regular expression because we don't
174 // know what placeholders they might use. Note that we
175 // first construct the regex itself by replacing %views_arg
176 // in the display path, then we use this constructed regex
177 // (which will be something like '#^(foo/%[^/]*/bar)$#') to
178 // search through the existing paths.
179 $regex = '#^(' .
preg_replace('#%views_arg#', '%[^/]*', implode('|', array_keys($result))) .
')$#';
180 $matches = preg_grep($regex, array_keys($callbacks));
182 // Remove any conflicting items that were found.
183 foreach ($matches as
$path) {
184 // Don't remove the paths we just added!
185 if (!isset($our_paths[$path])) {
186 unset($callbacks[$path]);
189 foreach ($result as
$path => $item) {
190 if (!isset($callbacks[$path])) {
191 // Add a new item, possibly replacing (and thus effectively
192 // overriding) one that we removed above.
193 $callbacks[$path] = $item;
196 // This item already exists, so it must be one that we added.
197 // We change the various callback arguments to pass an array
198 // of possible display IDs instead of a single ID.
199 $callbacks[$path]['page arguments'][1] = (array)$callbacks[$path]['page arguments'][1];
200 $callbacks[$path]['page arguments'][1][] = $display_id;
201 $callbacks[$path]['access arguments'][] = $item['access arguments'][0];
202 $callbacks[$path]['load arguments'][1] = (array)$callbacks[$path]['load arguments'][1];
203 $callbacks[$path]['load arguments'][1][] = $display_id;
205 $our_paths[$path] = TRUE
;
210 // Save memory: Destroy those views.
211 foreach ($views as
$data) {
212 list($view, $display_id) = $data;
218 * Helper function for menu loading. This will automatically be
219 * called in order to 'load' a views argument; primarily it
220 * will be used to perform validation.
223 * The actual value passed.
225 * The name of the view. This needs to be specified in the 'load function'
228 * The menu argument index. This counts from 1.
230 function views_arg_load($value, $name, $display_id, $index) {
231 if ($view = views_get_view($name)) {
232 $view->set_display($display_id);
233 $view->init_handlers();
235 $ids = array_keys($view->argument
);
238 $path = explode('/', $view->get_path());
240 foreach ($path as
$id => $piece) {
241 if ($piece == '%' && !empty($ids)) {
242 $indexes[$id] = array_shift($ids);
246 if (isset($indexes[$index])) {
247 if (isset($view->argument
[$indexes[$index]])) {
248 $arg = $view->argument
[$indexes[$index]]->validate_argument($value) ?
$value : FALSE
;
258 * Page callback entry point; requires a view and a display id, then
259 * passes control to the display handler.
261 function views_page() {
262 $args = func_get_args();
263 $name = array_shift($args);
264 $display_id = array_shift($args);
267 if ($view = views_get_view($name)) {
268 return $view->execute_display($display_id, $args);
271 // Fallback; if we get here no view was found or handler was not valid.
272 return drupal_not_found();
276 * Implementation of hook_block
278 function views_block($op = 'list', $delta = 0, $edit = array()) {
282 $views = views_get_all_views();
283 foreach ($views as
$view) {
284 $view->init_display();
285 foreach ($view->display as
$display_id => $display) {
287 if (isset($display->handler
) && !empty($display->handler
->definition
['uses hook block'])) {
288 $result = $display->handler
->execute_hook_block();
289 if (is_array($result)) {
290 $items = array_merge($items, $result);
294 if (isset($display->handler
) && $display->handler
->get_option('exposed_block')) {
295 $result = $display->handler
->get_special_blocks();
296 if (is_array($result)) {
297 $items = array_merge($items, $result);
303 // block.module has a delta length limit of 32, but our deltas can
304 // unfortunately be longer because view names can be 32 and display IDs
305 // can also be 32. So for very long deltas, change to md5 hashes.
308 // get the keys because we're modifying the array and we don't want to
309 // confuse PHP too much.
310 $keys = array_keys($items);
311 foreach ($keys as
$delta) {
312 if (strlen($delta) >= 32) {
314 $hashes[$hash] = $delta;
315 $items[$hash] = $items[$delta];
316 unset($items[$delta]);
320 variable_set('views_block_hashes', $hashes);
321 // Save memory: Destroy those views.
322 foreach ($views as
$view) {
328 $start = microtime();
329 // if this is 32, this should be an md5 hash.
330 if (strlen($delta) == 32) {
331 $hashes = variable_get('views_block_hashes', array());
332 if (!empty($hashes[$delta])) {
333 $delta = $hashes[$delta];
337 // This indicates it's a special one.
338 if (substr($delta, 0, 1) == '-') {
339 list($nothing, $type, $name, $display_id) = explode('-', $delta);
340 // Put the - back on.
342 if ($view = views_get_view($name)) {
343 if ($view->access($display_id)) {
344 $view->set_display($display_id);
345 if (isset($view->display_handler
)) {
346 $output = $view->display_handler
->view_special_blocks($type);
355 list($name, $display_id) = explode('-', $delta);
357 if ($view = views_get_view($name)) {
358 if ($view->access($display_id)) {
359 $output = $view->execute_display($display_id);
360 vpr("Block $view->name execute time: " .
(microtime() - $start) * 1000 .
"ms");
371 * Implementation of hook_flush_caches().
373 function views_flush_caches() {
374 return array('cache_views');
378 * Invalidate the views cache, forcing a rebuild on the next grab of table data.
380 function views_invalidate_cache() {
381 cache_clear_all('*', 'cache_views', true
);
385 * Determine if the logged in user has access to a view.
387 * This function should only be called from a menu hook or some other
388 * embedded source. Each argument is the result of a call to
389 * views_plugin_access::get_access_callback() which is then used
390 * to determine if that display is accessible. If *any* argument
391 * is accessible, then the view is accessible.
393 function views_access() {
394 if (user_access('access all views')) {
398 $args = func_get_args();
399 foreach ($args as
$arg) {
404 if (!is_array($arg)) {
408 list($callback, $arguments) = $arg;
409 if (function_exists($callback) && call_user_func_array($callback, $arguments)) {
418 * Access callback to determine if the logged in user has any of the
421 * This must be in views.module as it is called by menu access callback
422 * and can be called often.
424 function views_check_roles($rids) {
426 $roles = array_keys($user->roles
);
427 $roles[] = $user->uid ? DRUPAL_AUTHENTICATED_RID
: DRUPAL_ANONYMOUS_RID
;
428 return array_intersect(array_filter($rids), $roles);
430 // ------------------------------------------------------------------
431 // Functions to help identify views that are running or ran
434 * Set the current 'page view' that is being displayed so that it is easy
435 * for other modules or the theme to identify.
437 function &views_set_page_view($view = NULL
) {
438 static
$cache = NULL
;
447 * Find out what, if any, page view is currently in use. Please note that
448 * this returns a reference, so be careful! You can unintentionally modify the
451 function &views_get_page_view() {
452 return views_set_page_view();
456 * Set the current 'current view' that is being built/rendered so that it is
457 * easy for other modules or items in drupal_eval to identify
459 function &views_set_current_view($view = NULL
) {
460 static
$cache = NULL
;
469 * Find out what, if any, current view is currently in use. Please note that
470 * this returns a reference, so be careful! You can unintentionally modify the
473 function &views_get_current_view() {
474 return views_set_current_view();
477 // ------------------------------------------------------------------
478 // Include file helpers
481 * Include views .inc files as necessary.
483 function views_include($file) {
484 static
$used = array();
485 if (!isset($used[$file])) {
486 require_once
'./' .
drupal_get_path('module', 'views') .
"/includes/$file.inc";
493 * Load views files on behalf of modules.
495 function views_module_include($file) {
496 $views_path = drupal_get_path('module', 'views') .
'/modules';
497 foreach (views_get_module_apis() as
$module => $info) {
498 if (file_exists("./$info[path]/$module.$file")) {
499 require_once
"./$info[path]/$module.$file";
505 * Get a list of modules that support the current views API.
507 function views_get_module_apis() {
508 static
$cache = NULL
;
509 if (!isset($cache)) {
511 foreach (module_implements('views_api') as
$module) {
512 $function = $module .
'_views_api';
514 if (isset($info['api']) && $info['api'] == 2.000) {
515 if (!isset($info['path'])) {
516 $info['path'] = drupal_get_path('module', $module);
518 $cache[$module] = $info;
527 * Include views .css files.
529 function views_add_css($file) {
530 drupal_add_css(drupal_get_path('module', 'views') .
"/css/$file.css");
534 * Include views .js files.
536 function views_add_js($file) {
537 // If javascript has been disabled by the user, never add js files.
538 if (variable_get('views_no_javascript', FALSE
)) {
544 drupal_add_js(drupal_get_path('module', 'views') .
"/js/base.js");
547 drupal_add_js(drupal_get_path('module', 'views') .
"/js/$file.js");
551 * Load views files on behalf of modules.
553 function views_include_handlers() {
554 static
$finished = FALSE
;
555 // Ensure this only gets run once.
560 views_include('base');
561 views_include('handlers');
562 views_include('cache');
563 views_include('plugins');
564 _views_include_handlers();
569 * Load default views files on behalf of modules.
571 function views_include_default_views() {
572 static
$finished = FALSE
;
573 // Ensure this only gets run once.
578 // Default views hooks may be in the normal handler file,
579 // or in a separate views_default file at the discretion of
580 // the module author.
581 views_include_handlers();
583 _views_include_default_views();
587 // -----------------------------------------------------------------------
588 // Views handler functions
591 * Fetch a handler from the data cache.
594 * The name of the table this handler is from.
596 * The name of the field this handler is from.
598 * The type of handler. i.e, sort, field, argument, filter, relationship
601 * An instance of a handler object. May be views_handler_broken.
603 function views_get_handler($table, $field, $key) {
604 $data = views_fetch_data($table);
605 if (isset($data[$field][$key])) {
606 // Set up a default handler:
607 if (empty($data[$field][$key]['handler'])) {
608 $data[$field][$key]['handler'] = 'views_handler_' .
$key;
610 return _views_prepare_handler($data[$field][$key], $data, $field);
612 // DEBUG -- identify missing handlers
613 vpr("Missing handler: $table $field $key");
615 'title' => t('Broken handler @table.@field', array('@table' => $table, '@field' => $field)),
616 'handler' => 'views_handler_' .
$key .
'_broken',
620 return _views_create_handler($broken);
624 * Fetch Views' data from the cache
626 function views_fetch_data($table = NULL
) {
627 views_include('cache');
628 return _views_fetch_data($table);
631 // -----------------------------------------------------------------------
632 // Views plugin functions
635 * Fetch the plugin data from cache.
637 function views_fetch_plugin_data($type = NULL
, $plugin = NULL
) {
638 views_include('cache');
639 return _views_fetch_plugin_data($type, $plugin);
643 * Get a handler for a plugin
645 function views_get_plugin($type, $plugin) {
646 $definition = views_fetch_plugin_data($type, $plugin);
647 if (!empty($definition)) {
648 return _views_create_handler($definition, $type);
652 // -----------------------------------------------------------------------
653 // Views database functions
656 * Get a view from the default views defined by modules.
658 * Default views are cached per-language. This function will rescan the
659 * default_views hook if necessary.
662 * The name of the view to load.
664 * A view object or NULL if it is not available.
666 function &views_get_default_view($view_name) {
668 $cache = views_discover_default_views();
670 if (isset($cache[$view_name])) {
671 return $cache[$view_name];
677 * Create an empty view to work with.
680 * A fully formed, empty $view object. This object must be populated before
681 * it can be successfully saved.
683 function views_new_view() {
684 views_include('view');
687 $view->add_display('default');
693 * Scan all modules for default views and rebuild the default views cache.
695 * @return An associative array of all known default views.
697 function views_discover_default_views() {
698 static
$cache = array();
701 views_include('cache');
702 $cache = _views_discover_default_views();
708 * Return a list of all views and display IDs that have a particular
709 * setting in their display's plugin settings.
714 * array($view, $display_id),
715 * array($view, $display_id),
719 function views_get_applicable_views($type) {
720 // @todo: Use a smarter flagging system so that we don't have to
721 // load every view for this.
723 $views = views_get_all_views();
725 foreach ($views as
$view) {
726 // Skip disabled views.
727 if (!empty($view->disabled
)) {
731 if (empty($view->display
)) {
732 // Skip this view as it is broken.
733 vsm(t("Skipping broken view @view", array('@view' => $view->name
)));
737 // Loop on array keys because something seems to muck with $view->display
739 foreach (array_keys($view->display
) as
$id) {
740 $plugin = views_fetch_plugin_data('display', $view->display
[$id]->display_plugin
);
741 if (!empty($plugin[$type])) {
742 // This view uses hook menu. Clone it so that different handlers
743 // don't trip over each other, and add it to the list.
744 $v = $view->clone_view();
745 if ($v->set_display($id)) {
746 $result[] = array($v, $id);
748 // In PHP 4.4.7 and presumably earlier, if we do not unset $v
749 // here, we will find that it actually overwrites references
750 // possibly due to shallow copying issues.
759 * Return an array of all views as fully loaded $view objects.
761 function views_get_all_views() {
762 static
$views = array();
765 // First, get all applicable views.
766 views_include('view');
767 $views = view
::load_views();
769 // Get all default views.
770 $status = variable_get('views_defaults', array());
772 foreach (views_discover_default_views() as
$view) {
773 // Determine if default view is enabled or disabled.
774 if (isset($status[$view->name
])) {
775 $view->disabled
= $status[$view->name
];
778 // If overridden, also say so.
779 if (!empty($views[$view->name
])) {
780 $views[$view->name
]->type
= t('Overridden');
783 $view->type
= t('Default');
784 $views[$view->name
] = $view;
793 * Get a view from the database or from default views.
795 * This function is just a static wrapper around views::load(). This function
796 * isn't called 'views_load()' primarily because it might get a view
797 * from the default views which aren't technically loaded from the database.
800 * The name of the view.
802 * If TRUE, reset this entry in the load cache.
804 * A reference to the $view object. Use $reset if you're sure you want
807 function views_get_view($name, $reset = FALSE
) {
808 views_include('view');
809 $view = view
::load($name, $reset);
810 $default_view = views_get_default_view($name);
812 if (empty($view) && empty($default_view)) {
815 elseif (empty($view) && !empty($default_view)) {
816 $default_view->type
= t('Default');
817 return $default_view->clone_view();
819 elseif (!empty($view) && !empty($default_view)) {
820 $view->type
= t('Overridden');
823 return $view->clone_view();
827 // ------------------------------------------------------------------
828 // Views debug helper functions
831 * Provide debug output for Views. This relies on devel.module
833 function views_debug($message) {
834 if (module_exists('devel') && variable_get('views_devel_output', FALSE
) && user_access('access devel information')) {
835 if (is_string($message)) {
839 $output = var_export($message, TRUE
);
841 drupal_set_content(variable_get('views_devel_region', 'footer'), '<pre>' .
$output .
'</pre>');
846 * Shortcut to views_debug()
848 function vpr($message) {
849 views_debug($message);
855 function vsm($message) {
856 if (module_exists('devel')) {
861 function views_trace() {
863 foreach (debug_backtrace() as
$item) {
864 if (!empty($item['file']) && !in_array($item['function'], array('vsm_trace', 'vpr_trace', 'views_trace'))) {
865 $message .
= basename($item['file']) .
": " .
(empty($item['class']) ?
'' : ($item['class'] .
'->')) .
"$item[function] line $item[line]" .
"\n";
871 function vsm_trace() {
875 function vpr_trace() {
879 // ------------------------------------------------------------------
880 // Exposed widgets form
883 * Form builder for the exposed widgets form.
885 * Be sure that $view and $display are references.
887 function views_exposed_form(&$form_state) {
888 // Make sure that we validate because this form might be submitted
889 // multiple times per page.
890 $form_state['must_validate'] = TRUE
;
891 $view = &$form_state['view'];
892 $display = &$form_state['display'];
894 $form_state['input'] = $view->get_exposed_input();
896 // Let form plugins know this is for exposed widgets.
897 $form_state['exposed'] = TRUE
;
899 $form['#info'] = array();
901 if (!variable_get('clean_url', FALSE
)) {
904 '#value' => $view->get_url(),
908 // Go through each filter and let it generate its info.
909 foreach ($view->filter as
$id => $filter) {
910 $view->filter
[$id]->exposed_form($form, $form_state);
911 if ($info = $view->filter
[$id]->exposed_info()) {
912 $form['#info']['filter-' .
$id] = $info;
916 // @todo deal with exposed sorts
918 $form['submit'] = array(
919 '#name' => '', // prevent from showing up in $_GET.
921 '#value' => t('Apply'),
924 $form['#action'] = url($view->get_url());
925 $form['#theme'] = views_theme_functions('views_exposed_form', $view, $display);
926 $form['#id'] = views_css_safe('views_exposed_form-' .
check_plain($view->name
) .
'-' .
check_plain($display->id
));
927 // $form['#attributes']['class'] = array('views-exposed-form');
929 // If using AJAX, we need the form plugin.
930 if ($view->use_ajax
) {
931 drupal_add_js('misc/jquery.form.js');
933 views_add_js('dependent');
938 * Validate handler for exposed filters
940 function views_exposed_form_validate(&$form, &$form_state) {
941 foreach (array('field', 'filter') as
$type) {
942 $handlers = &$form_state['view']->$type;
943 foreach ($handlers as
$key => $handler) {
944 $handlers[$key]->exposed_validate($form, $form_state);
950 * Submit handler for exposed filters
952 function views_exposed_form_submit(&$form, &$form_state) {
953 foreach (array('field', 'filter') as
$type) {
954 $handlers = &$form_state['view']->$type;
955 foreach ($handlers as
$key => $info) {
956 $handlers[$key]->exposed_submit($form, $form_state);
959 $form_state['view']->exposed_data
= $form_state['values'];
960 $form_state['view']->exposed_raw_input
= array();
962 foreach ($form_state['values'] as
$key => $value) {
963 if (!in_array($key, array('q', 'submit', 'form_build_id', 'form_id', 'form_token', ''))) {
964 $form_state['view']->exposed_raw_input
[$key] = $value;
969 // ------------------------------------------------------------------
973 * Build a list of theme function names for use most everywhere.
975 function views_theme_functions($hook, $view, $display = NULL
) {
976 require_once
'./' .
drupal_get_path('module', 'views') .
"/theme/theme.inc";
977 return _views_theme_functions($hook, $view, $display);
981 * Views' replacement for drupal_get_form so that we can do more with
984 * Items that can be set on the form_state include:
985 * - input: The source of input. If unset this will be $_POST.
986 * - no_redirect: Absolutely do not redirect the form even if instructed
988 * - rerender: If no_redirect is set and the form was successfully submitted,
989 * rerender the form. Otherwise it will just return.
992 function drupal_build_form($form_id, &$form_state) {
993 views_include('form');
994 return _drupal_build_form($form_id, $form_state);
998 * Substitute current time; this works with cached queries.
1000 function views_views_query_substitutions($view) {
1003 '***CURRENT_TIME***' => time(),
1004 '***CURRENT_LANGUAGE***' => $language->language
,
1005 '***DEFAULT_LANGUAGE***' => language_default('language'),
1006 '***NO_LANGUAGE***' => '',
1011 * Embed a view using a PHP snippet.
1013 * This function is meant to be called from PHP snippets, should one wish to
1014 * embed a view in a node or something. It's meant to provide the simplest
1015 * solution and doesn't really offer a lot of options, but breaking the function
1016 * apart is pretty easy, and this provides a worthwhile guide to doing so.
1018 * Note that this function does NOT display the title of the view. If you want
1019 * to do that, you will need to do what this function does manually, by
1020 * loading the view, getting the preview and then getting $view->get_title().
1023 * The name of the view to embed.
1024 * @param $display_id
1025 * The display id to embed. If unsure, use 'default', as it will always be
1026 * valid. But things like 'page' or 'block' should work here.
1028 * Any additional parameters will be passed as arguments.
1030 function views_embed_view($name, $display_id = 'default') {
1031 $args = func_get_args();
1032 array_shift($args); // remove $name
1034 array_shift($args); // remove $display_id
1037 $view = views_get_view($name);
1042 return $view->preview($display_id, $args);
1048 function views_var_export($var, $prefix = '') {
1049 if (is_array($var)) {
1051 $output = 'array()';
1054 $output = "array(\n";
1055 foreach ($var as
$key => $value) {
1056 $output .
= " '$key' => " .
views_var_export($value, ' ') .
",\n";
1061 else if (is_bool($var)) {
1062 $output = $var ?
'TRUE' : 'FALSE';
1065 $output = var_export($var, TRUE
);
1069 $output = str_replace("\n", "\n$prefix", $output);
1076 * Prepare the specified string for use as a CSS identifier.
1078 function views_css_safe($string) {
1079 return str_replace('_', '-', $string);
1083 * Implementation of hook_views_exportables().
1085 function views_views_exportables($op = 'list', $views = NULL
, $name = 'foo') {
1086 $all_views = views_get_all_views();
1087 if ($op == 'list') {
1089 foreach ($all_views as
$name => $view) {
1090 // in list, $views is a list of tags.
1091 if (empty($views) || in_array($view->tag
, $views)) {
1092 $return[$name] = array(
1093 'name' => check_plain($name),
1094 'desc' => check_plain($view->description
),
1095 'tag' => check_plain($view->tag
)
1102 if ($op == 'export') {
1104 $code .
= " * Implementation of hook_views_default_views().\n";
1106 $code .
= "function " .
$name .
"_views_default_views() {\n";
1107 foreach ($views as
$view => $truth) {
1108 $code .
= $all_views[$view]->export(' ');
1109 $code .
= ' $views[$view->name] = $view;' .
"\n\n";
1111 $code .
= " return \$views;\n";