4 function views_init() {
5 // hook init is called even on cached pages, but we don't want to
6 // actually do anything in that case.
7 if (!function_exists('drupal_get_path')) {
10 // Load all our module 'on behalfs'.
11 $path = drupal_get_path('module', 'views') .
'/modules';
12 $files = system_listing('views_.*\.inc$', $path, 'name', 0);
14 foreach($files as
$file) {
15 // The filename format is very specific. It must be views_MODULENAME.inc
16 $module = substr_replace($file->name
, '', 0, 6);
17 if (module_exist($module)) {
18 require_once("./$file->filename");
23 // ---------------------------------------------------------------------------
27 * Return the arguments array; construct one if we haven't already. The
28 * array is cached in a global, safely named variable so that arguments
29 * are only constructed once per run.
31 function _views_get_arguments($titles = false
) {
32 static
$views_arguments;
35 if (!$views_arguments) {
36 $data = cache_get("views_arguments:$locale");
37 $cache = unserialize($data->data
);
38 if (is_array($cache)) {
39 $views_arguments = $cache;
42 $arguments = module_invoke_all('views_arguments');
43 foreach ($arguments as
$name => $arg) {
44 if ($arg['option'] && !is_array($arg['option'])) {
45 if ($arg['option'] == 'string' || $arg['option'] == 'integer') {
46 $arg['option'] = array('#type' => 'textfield', '#size' => 10, '#maxlength' => 255);
49 $arg['option'] = array('#type' => 'select', '#options' => $arg['option']);
52 $views_arguments['base'][$name] = $arg['name'];
53 $views_arguments['title'][$name] = $arg;
55 $cache = $views_arguments;
56 cache_set("views_arguments:$locale", serialize($cache));
59 return ($titles ?
$views_arguments['base'] : $views_arguments['title']);
63 * Constructs the full table information array. Caches it into a global array
64 * so that it will only be called once per run.
66 function _views_get_tables($full = false
) {
71 $data = cache_get("views_tables:$locale");
72 $cache = unserialize($data->data
);
74 if (is_array($cache)) {
75 $views_tables = $cache;
78 $table_data = module_invoke_all('views_tables');
79 $views_tables['tables'] = $table_data;
81 foreach ($table_data as
$name => $table) {
82 if (is_array($table['filters'])) {
83 foreach ($table['filters'] as
$filter => $data) {
84 $data['table'] = $name;
85 // translate for deprecated APIs...
86 if ($data['option'] && !is_array($data['option'])) {
87 if ($data['option'] == 'string' || $data['option'] == 'integer') {
88 $data['option'] = array('#type' => 'textfield', '#size' => 10, '#maxlength' => 255);
91 $data['option'] = array('#type' => 'select', '#options' => $data['option']);
95 $data['value'] = array('#type' => 'select', '#options' => $data['list']);
96 if ($data['list-type'] != 'select') {
97 $data['value']['#multiple'] = TRUE
;
100 else if (!$data['value']) {
101 $data['value'] = array('#type' => 'textfield', '#size' => 10, '#maxlength' => 255);
103 $views_tables['filters']['titles']["$name.$filter"] = $data['name'];
104 $views_tables['filters']['base']["$name.$filter"] = $data;
107 if (is_array($table['fields'])) {
108 foreach ($table['fields'] as
$field => $data) {
109 if ($data['option'] && !is_array($data['option'])) {
110 if ($data['option'] == 'string' || $data['option'] == 'integer') {
111 $data['option'] = array('#type' => 'textfield', '#size' => 10, '#maxlength' => 255);
114 $data['option'] = array('#type' => 'select', '#options' => $data['option']);
117 $data['table'] = $name;
118 $views_tables['fields']['titles']["$name.$field"] = $data['name'];
119 $views_tables['fields']['base']["$name.$field"] = $data;
122 if (is_array($table['sorts'])) {
123 foreach ($table['sorts'] as
$field => $data) {
124 $data['table'] = $name;
125 if ($data['option'] && !is_array($data['option'])) {
126 if ($data['option'] == 'string' || $data['option'] == 'integer') {
127 $data['option'] = array('#type' => 'textfield', '#size' => 10, '#maxlength' => 255);
130 $data['option'] = array('#type' => 'select', '#options' => $data['option']);
133 $views_tables['sorts']['titles']["$name.$field"] = $data['name'];
134 $views_tables['sorts']['base']["$name.$field"] = $data;
138 cache_set("views_tables:$locale", serialize($views_tables));
141 return ($full ?
$views_tables : $views_tables['tables']);
145 * Gets the filter information; if it doesn't exist, call the function
146 * that constructs all that.
148 function _views_get_filters($titles = false
) {
149 $table_data = _views_get_tables(true
);
150 return ($titles ?
$table_data['filters']['titles'] : $table_data['filters']['base']);
154 * Gets the field information; if it doesn't exist, call the function
155 * that constructs all that.
157 function _views_get_fields($titles = false
) {
158 $table_data = _views_get_tables(true
);
159 return ($titles ?
$table_data['fields']['titles'] : $table_data['fields']['base']);
163 * Gets the sort information; if it doesn't exist, call the function
164 * that constructs all that.
166 function _views_get_sorts($titles = false
) {
167 $table_data = _views_get_tables(true
);
168 return ($titles ?
$table_data['sorts']['titles'] : $table_data['sorts']['base']);
172 * Invalidate the views cache, forcing a rebuild on the next grab of table data.
174 function views_invalidate_cache() {
175 cache_clear_all('views_', true
);
179 * Ensures that views have legitimate information; a bit more is stored on
180 * the $view object than is in the database, and this isn't necessarily
181 * set when a view is constructed externally.
183 function _views_sanitize_view(&$view) {
184 _views_check_arrays($view); // so reference works.
185 foreach ($view->field as
$i => $field) {
186 $view->field
[$i]['id'] = $view->field
[$i]['fullname'] = "$field[tablename].$field[field]";
187 $view->field
[$i]['queryname'] = "$field[tablename]_$field[field]";
190 foreach ($view->filter as
$i => $filter) {
191 $view->filter
[$i]['id'] = $view->filter
[$i]['field'] = "$filter[tablename].$filter[field]";
194 foreach ($view->exposed_filter as
$i => $exposed_filter) {
195 $view->exposed_filter
[$i]['id'] = $view->exposed_filter
[$i]['field'] = "$exposed_filter[tablename].$exposed_filter[field]";
198 foreach ($view->sort as
$i => $sort) {
199 $view->sort[$i]['id'] = $view->sort[$i]['field'] = "$sort[tablename].$sort[field]";
202 foreach ($view->argument as
$i => $argument) {
203 $view->argument
[$i]['id'] = $view->argument
[$i]['type'];
208 * Build default view information from all modules and cache it.
210 function _views_get_default_views() {
211 static
$views_default_views;
214 if (!$views_default_views) {
215 $data = cache_get("views_default_views:$locale");
216 $cache = unserialize($data->data
);
218 if (is_array($cache)) {
219 $views_default_views = $cache;
222 // We have to make sure table data is built in order to be sure about providers.
223 $tables = array_keys(_views_get_tables());
225 $views = module_invoke_all('views_default_views');
226 $views_default_views = array();
227 foreach ($views as
$i => $view) {
228 if (!is_array($view->requires
) || !array_diff($view->requires
, $tables)) {
229 _views_sanitize_view($view);
230 $views_default_views[$i] = $view;
233 cache_set("views_default_views:$locale", serialize($views_default_views));
236 return $views_default_views;
240 * Return the style plugins; construct one if we haven't already. The
241 * array is cached in a static variable so that arguments
242 * are only constructed once per run.
244 function _views_get_style_plugins($titles = false
) {
245 static
$views_style_plugins;
248 if (!$views_style_plugins) {
249 $data = cache_get("views_style_plugins:$locale");
250 $cache = unserialize($data->data
);
251 if (is_array($cache)) {
252 $views_style_plugins = $cache;
255 $arguments = module_invoke_all('views_style_plugins');
256 foreach ($arguments as
$name => $arg) {
257 $views_style_plugins['title'][$name] = $arg['name'];
258 $views_style_plugins['base'][$name] = $arg;
260 $cache = $views_style_plugins;
261 cache_set("views_style_plugins:$locale", serialize($cache));
264 return ($titles ?
$views_style_plugins['title'] : $views_style_plugins['base']);
267 // ---------------------------------------------------------------------------
271 * Implementation of hook_help()
273 function views_help($section) {
275 case
'admin/help#views':
276 case
'admin/modules#description':
277 return t('The views module creates customized views of node lists.');
282 * Implementation of hook_menu()
284 function views_menu($may_cache) {
289 // Invalidate the views cache to ensure that views data gets rebuilt.
290 // This is the best way to tell that module configuration has changed.
291 if (arg(0) == 'admin' && arg(1) == 'modules') {
292 views_invalidate_cache();
295 $result = db_query("SELECT * FROM {view_view} WHERE page = 1");
296 $views_with_inline_args = array();
298 while ($view = db_fetch_object($result)) {
300 $view->access
= ($view->access ?
explode(', ', $view->access
) : array());
302 // This happens before the next check; even if it's put off for later
304 $used[$view->name
] = true
;
306 if (strrpos($view->url
, '$arg')) {
307 $arg_result = db_query("SELECT * FROM {view_argument} WHERE vid = %d", $view->vid
);
308 while ($view->argument
[] = db_fetch_array($arg_result));
309 array_pop($view->argument
); // get rid of the NULL at the end.
310 $views_with_inline_args[$view->name
] = $view;
313 _views_create_menu_item($items, $view, $view->url
);
315 $default_views = _views_get_default_views();
316 $views_status = variable_get('views_defaults', array());
318 foreach ($default_views as
$name => $view) {
319 if ($view->page
&& !$used[$name] &&
320 ($views_status[$name] == 'enabled' || (!$view->disabled
&& $views_status[$name] != 'disabled'))) {
322 if (strrpos($view->url
, '$arg')) {
323 $views_with_inline_args[$view->name
] = $view;
327 _views_create_menu_item($items, $view, $view->url
);
330 cache_set("views_with_inline_args:$locale", serialize($views_with_inline_args));
333 $data = cache_get("views_with_inline_args:$locale");
334 $views = unserialize($data->data
);
335 if (is_array($views)) {
336 foreach ($views as
$view) {
337 // Do substitution on args.
338 $view_args = array();
339 $menu_path = array();
340 foreach (explode('/', $view->url
) as
$num => $element) {
341 if ($element == '$arg') {
342 $menu_path[] = arg($num);
343 $view_args[] = arg($num);
344 $view->args
[] = arg($num);
347 $menu_path[] = $element;
350 $path = implode('/', $menu_path);
351 _views_create_menu_item($items, $view, $path, MENU_CALLBACK
, $view_args);
359 * Helper function to add a menu item for a view.
361 function _views_create_menu_item(&$items, $view, $path, $local_task_type = MENU_NORMAL_ITEM
, $args = array()) {
362 static
$roles = NULL
;
363 if ($roles == NULL
) {
365 $roles = array_keys($user->roles
);
367 $title = views_get_title($view, 'menu');
368 $type = _views_menu_type($view);
369 if ($type == MENU_LOCAL_TASK
|| $type == MENU_DEFAULT_LOCAL_TASK
) {
370 $weight = $view->menu_tab_weight
;
372 $access = !$view->access
|| array_intersect($view->access
, $roles);
373 $items[] = _views_menu_item($path, $title, $view, $args, $access, $type, $weight);
375 if ($type == MENU_DEFAULT_LOCAL_TASK
) {
376 $items[] = _views_menu_item(dirname($path), $title, $view, $args, $access, $local_task_type, $weight);
381 * Helper function to create a menu item for a view.
383 function _views_menu_item($path, $title, $view, $args, $access, $type, $weight = NULL
) {
384 array_unshift($args, $view->name
);
385 $retval = array('path' => $path,
387 'callback' => 'views_view_page',
388 'callback arguments' => $args,
389 'access' => user_access('access content') && $access,
392 if ($weight !== NULL
) {
393 $retval['weight'] = $weight;
399 * Determine what menu type a view needs to use.
401 function _views_menu_type($view) {
403 if ($view->menu_tab_default
) {
404 $type = MENU_DEFAULT_LOCAL_TASK
;
406 else if ($view->menu_tab
) {
407 $type = MENU_LOCAL_TASK
;
410 $type = MENU_NORMAL_ITEM
;
414 $type = MENU_CALLBACK
;
420 * Implementation of hook_block()
422 function views_block($op = 'list', $delta = 0) {
425 // Grab views from the database and provide them as blocks.
426 $result = db_query("SELECT vid, block_title, page_title, name FROM {view_view} WHERE block = 1");
427 while ($view = db_fetch_object($result)) {
428 $block[$view->name
]['info'] = views_get_title($view, 'block-info');
431 $default_views = _views_get_default_views();
432 $views_status = variable_get('views_defaults', array());
434 foreach ($default_views as
$name => $view) {
435 if (!isset($block[$name]) && $view->block
&&
436 ($views_status[$name] == 'enabled' || (!$view->disabled
&& $views_status[$name] != 'disabled'))) {
437 $block[$name]['info'] = views_get_title($view, 'block');
442 else if ($op == 'view') {
443 return views_view_block($delta);
447 // ---------------------------------------------------------------------------
451 * Ensure that all the arrays in a view exist so we don't run into array
452 * operations on a non-array error.
454 function _views_check_arrays(&$view) {
455 $fields = array('field', 'sort', 'argument', 'filter', 'exposed_filter', 'access');
457 foreach($fields as
$field) {
458 if (!is_array($view->$field)) {
459 $view->$field = array();
466 * This function loads a view by name or vid; if not found in db, it looks
467 * for a default view by that name.
469 function views_get_view($view_name) {
470 $view = _views_load_view($view_name);
475 if (is_int($view_name)) {
476 return; // don't bother looking if view_name is an int!
479 $default_views = _views_get_default_views();
481 if (isset($default_views[$view_name])) {
482 return $default_views[$view_name];
487 * This views a view by page, and should only be used as a callback.
490 * The name or id of the view to load
492 * The arguments from the end of the url. Usually passed from the menu system.
497 function views_view_page() {
498 $args = func_get_args();
499 $view_name = array_shift($args);
500 $view = views_get_view($view_name);
507 $output = views_build_view('page', $view, $args, $view->use_pager
, $view->nodes_per_page
);
508 if ($output === FALSE
) {
517 * This views a view by block. Can be used as a callback or programmatically.
519 function views_view_block($vid) {
520 $view = views_get_view($vid);
522 if (!$view || !$view->block
) {
531 $roles = array_keys($user->roles
);
532 if ($view->access
&& !array_intersect($roles, $view->access
)) {
536 $content = views_build_view('block', $view, array(), false
, $view->nodes_per_block
);
538 $block['content'] = $content;
539 $block['subject'] = views_get_title($view, 'block');
548 * This builds the basic view.
550 * 'page' -- Produce output as a page, sent through theme.
551 * The only real difference between this and block is that
552 * a page uses drupal_set_title to change the page title.
553 * 'block' -- Produce output as a block, sent through theme.
554 * 'embed' -- Use this if you want to embed a view onto another page,
555 * and don't want any block or page specific things to happen to it.
556 * 'result' -- return an $info array. The array contains:
557 * query: The actual query ran.
558 * countquery: The count query that would be run if limiting was required.
559 * summary: True if an argument was missing and a summary was generated.
560 * level: What level the missing argument was at.
561 * result: Database object you can use db_fetch_object on.
562 * 'items' -- return info array as above, except instead of result,
563 * items: An array of objects containing the results of the query.
565 * The actual view object. Use views_get_view() if you only have the name or
568 * args taken from the URL. Not relevant for many views. Can be null.
570 * If set, use a pager. Set this to the pager id you want it
571 * to use if you plan on using multiple pagers on a page. To go with the
572 * default setting, set to $view->use_pager. Note that the pager element
573 * id will be decremented in order to have the IDs start at 0.
575 * Required if $use_pager is set; if $limit is set and $use_pager is
576 * not, this will be the maximum number of records returned. This is ignored
577 * if using a view set to return a random result. To go with the default
578 * setting set to $view->nodes_per_page or $view->nodes_per_block. If
579 * $use_pager is set and this field is not, you'll get a SQL error. Don't
582 * $use_pager is false, and $limit is !0, $page tells it what page to start
583 * on, in case for some reason a particular section of view is needed,
586 function views_build_view($type, &$view, $args = array(), $use_pager = false
, $limit = 0, $page = 0) {
587 // Fix a number of annoying whines when NULL is passed in..
592 $GLOBALS['current_view'] = &$view;
594 $view->build_type
= $type;
595 $view->type
= ($type == 'block' ?
$view->block_type
: $view->page_type
);
597 if ($view->view_args_php
) {
599 $result = eval($view->view_args_php
);
600 if (is_array($result)) {
606 $plugins = _views_get_style_plugins();
608 $info['query'] = $view->query
;
609 $info['countquery'] = $view->countquery
;
611 if ($plugins[$view->type
]['needs_table_header']) {
612 $view->table_header
= _views_construct_header($view, $fields);
616 $path = drupal_get_path('module', 'views');
617 require_once("./$path/views_query.inc");
619 $info = _views_build_query($view, $args);
625 // Run-time replacement so we can do cacheing
626 $replacements = module_invoke_all('views_query_substitutions', $view);
627 foreach ($replacements as
$src => $dest) {
628 $info['query'] = str_replace($src, $dest, $info['query']);
629 $info['countquery'] = str_replace($src, $dest, $info['countquery']);
631 if (is_array($info['args'])) {
632 foreach ($info['args'] as
$id => $arg) {
633 $info['args'][$id] = str_replace($src, $dest, $arg);
638 $query = db_rewrite_sql($info['query'], 'node');
641 $cquery = db_rewrite_sql($info['countquery'], 'node', 'nid', $info['rewrite_args']);
642 $result = pager_query($query, $limit, $use_pager - 1, $cquery, $info['args']);
643 $view->total_rows
= $GLOBALS['pager_total_items'][$use_pager - 1];
646 $result = ($limit ?
db_query_range($query, $info['args'], $page * $limit, $limit) : db_query($query, $info['args']));
648 $view->num_rows
= db_num_rows($result);
649 if ($type == 'result') {
650 $info['result'] = $result;
655 while ($item = db_fetch_object($result)) {
659 if ($type == 'items') {
660 $info['items'] = $items;
664 // Call a hook that'll let modules modify the view just before it is displayed.
665 foreach (module_implements('views_pre_view') as
$module) {
666 $function = $module .
'_views_pre_view';
667 $output .
= $function($view, $items);
670 $view->real_url
= views_get_url($view, $args);
672 $view->use_pager
= $use_pager;
673 $view->pager_limit
= $limit;
674 $output .
= views_theme('views_view', $view, $type, $items, $info['level'], $args);
676 // Call a hook that'll let modules modify the view just after it is displayed.
677 foreach (module_implements('views_post_view') as
$module) {
678 $function = $module .
'_views_post_view';
679 $output .
= $function($view, $items, $output);
685 // ---------------------------------------------------------------------------
689 * Easily theme any item to a view.
691 * The name of the function to call.
693 * The view being themed.
695 function views_theme() {
696 $args = func_get_args();
697 $function = array_shift($args);
700 if (!($func = theme_get_function($function .
"_" .
$view->name
))) {
701 $func = theme_get_function($function);
705 return call_user_func_array($func, $args);
710 * Easily theme any item to a field name.
711 * field name will be in the format of TABLENAME_FIELDNAME
712 * You have to understand a bit about the views data to utilize this.
715 * The name of the function to call.
717 * The field being themed.
719 function views_theme_field() {
720 $args = func_get_args();
721 $function = array_shift($args);
722 $field_name = array_shift($args);
723 $view = array_pop($args);
725 if (!($func = theme_get_function($function .
'_' .
$view->name .
'_' .
$field_name))) {
726 if (!($func = theme_get_function($function .
'_' .
$field_name))) {
727 $func = theme_get_function($function);
732 return call_user_func_array($func, $args);
737 * Figure out what timezone we're in; needed for some date manipulations.
739 function _views_get_timezone() {
741 if (variable_get('configurable_timezones', 1) && $user->uid
&& strlen($user->timezone
)) {
742 $timezone = $user->timezone
;
745 $timezone = variable_get('date_default_timezone', 0);
748 // set up the database timezone
749 if (in_array($GLOBALS['db_type'], array('mysql', 'mysqli'))) {
750 static
$already_set = false
;
752 if ($GLOBALS['db_type'] == 'mysqli' || version_compare(mysql_get_server_info(), '4.1.3', '>=')) {
753 db_query("SET @@session.time_zone = '+00:00'");
763 * Figure out what the URL of the view we're currently looking at is.
765 function views_get_url($view, $args) {
770 foreach ($args as
$arg) {
771 // This odd construct prevents us from strposing once there is no
772 // longer an $arg to replace.
773 if ($where && $where = strpos($url, '$arg')) {
774 $url = substr_replace($url, $arg, $where, 4);
786 * Figure out what the title of a view should be.
788 function views_get_title($view, $context = 'menu', $args = NULL
) {
789 if ($context == 'menu' && $view->menu_title
)
790 return $view->menu_title
;
792 if ($context == 'block-info') {
793 return $view->description ?
$view->description
: $view->name
;
796 if ($args === NULL
) {
799 // Grab the title from the highest argument we got. If there is no such
800 // title, track back until we find a title.
802 if (is_array($args)) {
803 $rargs = array_reverse(array_keys($args));
804 foreach ($rargs as
$arg_id) {
805 if ($title = $view->argument
[$arg_id]['title']) {
811 if (!$title && ($context == 'menu' || $context == 'page')) {
812 $title = $view->page_title
;
816 $title = $view->block_title
;
819 if (!$view->argument
) {
823 $arginfo = _views_get_arguments();
824 foreach ($view->argument as
$i => $arg) {
825 if (!isset($args[$i])) {
828 $argtype = $arg['type'];
829 if ($arg['wildcard'] == $args[$i] && $arg['wildcard_substitution'] != '') {
830 $title = str_replace("%" .
($i + 1), $arg['wildcard_substitution'], $title);
832 else if (function_exists($arginfo[$argtype]['handler'])) {
834 $rep = $arginfo[$argtype]['handler']('title', $args[$i], $argtype);
835 $title = str_replace("%" .
($i + 1), $rep, $title);
842 * Determine whether or not a view is cacheable. A view is not cacheable if
843 * there is some kind of user input or data required. For example, views
844 * that need to restrict to the 'current' user, or any views that require
845 * arguments or allow click-sorting are not cacheable.
847 function _views_is_cacheable(&$view) {
848 // views with arguments are immediately not cacheable.
849 if (!empty($view->argument
) || !empty($view->exposed_filter
)) {
853 $filters = _views_get_filters();
855 foreach ($view->filter as
$i => $filter) {
856 if ($filters[$filter['field']]['cacheable'] == 'no') {
861 foreach ($view->field as
$i => $field) {
862 if ($field['sortable']) {
869 // ---------------------------------------------------------------------------
870 // Database functions
873 * Provide all the fields in a view.
875 function _views_view_fields() {
876 return array('vid', 'name', 'description', 'access', 'page', 'page_title', 'page_header', 'page_header_format', 'page_footer', 'page_footer_format', 'page_empty', 'page_empty_format', 'page_type', 'use_pager', 'nodes_per_page', 'url', 'menu', 'menu_tab', 'menu_tab_default', 'menu_tab_weight', 'menu_title', 'block', 'block_title', 'block_use_page_header', 'block_header', 'block_header_format', 'block_use_page_footer', 'block_footer', 'block_footer_format', 'block_use_page_empty', 'block_empty', 'block_empty_format', 'block_type', 'nodes_per_block', 'block_more', 'url', 'breadcrumb_no_home', 'changed', 'query', 'countquery', 'view_args_php');
880 * Delete a view from the database.
882 function _views_delete_view($view) {
883 $view->vid
= intval($view->vid
);
888 db_query("DELETE FROM {view_view} where vid=%d", $view->vid
);
889 db_query("DELETE FROM {view_sort} where vid=%d", $view->vid
);
890 db_query("DELETE FROM {view_argument} where vid=%d", $view->vid
);
891 db_query("DELETE FROM {view_tablefield} where vid=%d", $view->vid
);
895 * Load a view from the database -- public version of the function.
897 function views_load_view($arg) {
898 return _views_load_view($arg);
902 * Load a view from the database.
903 * (deprecated; use views_load_view in favor of this function).
905 function _views_load_view($arg) {
906 static
$cache = array();
907 $which = is_numeric($arg) ?
'vid' : 'name';
908 if (isset($cache[$which][$arg])) {
909 return $cache[$which][$arg];
912 $where = (is_numeric($arg) ?
"v.vid = %d" : "v.name = '%s'");
913 $view = db_fetch_object(db_query("SELECT v.* FROM {view_view} v WHERE $where", $arg));
919 $view->access
= ($view->access ?
explode(', ', $view->access
) : array());
921 // load the sorting criteria too.
922 $result = db_query("SELECT * FROM {view_sort} vs WHERE vid = $view->vid ORDER BY position ASC");
924 $view->sort = array();
925 while ($sort = db_fetch_array($result)) {
926 if (substr($sort['field'], 0, 2) == 'n.') {
927 $sort['field'] = 'node' .
substr($sort['field'], 1);
929 $sort['id'] = $sort['field'];
930 $view->sort[] = $sort;
933 $result = db_query("SELECT * FROM {view_argument} WHERE vid = $view->vid ORDER BY position ASC");
935 $view->argument
= array();
936 while ($arg = db_fetch_array($result)) {
937 $arg['id'] = $arg['type'];
938 $view->argument
[] = $arg;
941 $result = db_query("SELECT * FROM {view_tablefield} WHERE vid = $view->vid ORDER BY position ASC");
943 $view->field
= array();
944 while ($arg = db_fetch_array($result)) {
945 if ($arg['tablename'] == 'n') {
946 $arg['tablename'] = 'node';
948 $arg['id'] = $arg['fullname'] = "$arg[tablename].$arg[field]";
949 $arg['queryname'] = "$arg[tablename]_$arg[field]";
950 $view->field
[] = $arg;
953 $result = db_query("SELECT * FROM {view_filter} WHERE vid = $view->vid ORDER BY position ASC");
955 $filters = _views_get_filters();
956 $view->filter
= array();
957 while ($filter = db_fetch_array($result)) {
958 if (substr($filter['field'], 0, 2) == 'n.') {
959 $filter['field'] = 'node' .
substr($filter['field'], 1);
962 if ($filter['operator'] == 'AND' ||
963 $filter['operator'] == 'OR' ||
964 $filter['operator'] == 'NOR' ||
965 $filters[$filter['field']]['value-type'] == 'array' ) {
966 if ($filter['value'] !== NULL
&& $filter['value'] !== '') {
967 $filter['value'] = explode(',', $filter['value']);
970 $filter['value'] = array();
973 $filter['id'] = $filter['field'];
974 $view->filter
[] = $filter;
977 $result = db_query("SELECT * FROM {view_exposed_filter} WHERE vid = $view->vid ORDER BY position ASC");
979 $view->exposed_filter
= array();
980 while ($arg = db_fetch_array($result)) {
981 $arg['id'] = $arg['field'];
982 $view->exposed_filter
[] = $arg;
985 $cache['vid'][$view->vid
] = $view;
986 $cache['name'][$view->name
] = $view;
992 * Save a view to the database.
994 function _views_save_view($view) {
995 _views_check_arrays($view);
998 if (_views_is_cacheable($view)) {
999 $path = drupal_get_path('module', 'views');
1000 require_once("./$path/views_query.inc");
1002 $info = _views_build_query($view);
1003 $view->query
= _views_replace_args($info['query'], $info['args']);
1004 $view->countquery
= _views_replace_args($info['countquery'], $info['args']);
1007 $view->query
= NULL
;
1008 $view->countquery
= NULL
;
1011 $view->access
= implode(', ', $view->access
);
1013 $view->changed
= time();
1014 $fields = _views_view_fields();
1017 // Prepare the query:
1018 foreach ($view as
$key => $value) {
1019 if (in_array($key, $fields)) {
1020 $q[] = db_escape_string($key) .
" = '%s'";
1025 // Update the view in the database:
1026 db_query("UPDATE {view_view} SET ".
implode(', ', $q) .
" WHERE vid = '$view->vid'", $v);
1027 db_query("DELETE from {view_sort} WHERE vid='$view->vid'");
1028 db_query("DELETE from {view_argument} WHERE vid='$view->vid'");
1029 db_query("DELETE from {view_tablefield} WHERE vid='$view->vid'");
1030 db_query("DELETE from {view_filter} WHERE vid='$view->vid'");
1031 db_query("DELETE from {view_exposed_filter} WHERE vid='$view->vid'");
1036 // This method really saves on typos, and makes it a lot easier to add fields
1038 $view->vid
= db_next_id('{view_view}_vid');
1040 // Prepare the query:
1041 foreach ($view as
$key => $value) {
1042 if (in_array((string) $key, $fields)) {
1043 $k[] = db_escape_string($key);
1045 $s[] = is_numeric($value) ?
'%d' : "'%s'";
1049 db_query("INSERT INTO {view_view} (".
implode(", ", $k) .
") VALUES (".
implode(", ", $s) .
")", $v);
1052 foreach ($view->sort as
$i => $sort) {
1053 db_query("INSERT INTO {view_sort} (vid, position, field, sortorder, options) VALUES (%d, %d, '%s', '%s', '%s')", $view->vid
, $i, $sort['field'], $sort['sortorder'], $sort['options']);
1056 foreach ($view->argument as
$i => $arg) {
1057 db_query("INSERT INTO {view_argument} (vid, type, argdefault, title, options, position, wildcard, wildcard_substitution) VALUES (%d, '%s', %d, '%s', '%s', %d, '%s', '%s')", $view->vid
, $arg['type'], $arg['argdefault'], $arg['title'], $arg['options'], $i, $arg['wildcard'], $arg['wildcard_substitution']);
1060 foreach ($view->field as
$i => $arg) {
1061 db_query("INSERT INTO {view_tablefield} (vid, tablename, field, label, handler, sortable, defaultsort, options, position) VALUES (%d, '%s', '%s', '%s', '%s', %d, '%s', '%s', %d)", $view->vid
, $arg['tablename'], $arg['field'], $arg['label'], $arg['handler'], $arg['sortable'], $arg['defaultsort'], $arg['options'], $i);
1064 foreach ($view->filter as
$i => $arg) {
1065 if (is_array($arg['value'])) {
1066 $arg['value'] = implode(',', $arg['value']);
1068 db_query("INSERT INTO {view_filter} (vid, tablename, field, value, operator, options, position) VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d)", $view->vid
, $arg['tablename'], $arg['field'], $arg['value'], $arg['operator'], $arg['options'], $i);
1071 foreach ($view->exposed_filter as
$i => $arg) {
1072 db_query("INSERT INTO {view_exposed_filter} (vid, field, label, optional, is_default, single, operator, position) VALUES (%d, '%s', '%s', %d, %d, %d, %d, %d)", $view->vid
, $arg['field'], $arg['label'], $arg['optional'], $arg['is_default'], $arg['single'], $arg['operator'], $i);
1076 // ---------------------------------------------------------------------------
1077 // Helper functions to build views and view data
1080 * Helper function to make table creation a little easier. It adds the necessary
1081 * data to a $table array and returns it.
1083 function views_new_table($table_name, $provider, $left_table, $left_field, $right_field, $extra = NULL
) {
1084 $table['name'] = $table_name;
1085 $table['provider'] = $provider;
1086 $table['join']['left']['table'] = $left_table;
1087 $table['join']['left']['field'] = $left_field;
1088 $table['join']['right']['field'] = $left_field;
1090 $table['join']['extra'] = $extra;
1096 * Helper function to make table creation a little easier. It adds the necessary
1097 * data to the $table array.
1099 function views_table_add_field(&$table, $name, $label, $help, $others = array()) {
1100 views_table_add_data($table, 'fields', $name, $label, $help, $others);
1104 * Helper function to make table creation a little easier. It adds the necessary
1105 * data to the $table array.
1107 function views_table_add_filter(&$table, $name, $label, $help, $others = array()) {
1108 views_table_add_data($table, 'filters', $name, $label, $help, $others);
1112 * Helper function to make table creation a little easier. It adds the necessary
1113 * data to the $table array.
1115 function views_table_add_sort(&$table, $name, $label, $help, $others = array()) {
1116 views_table_add_data($table, 'sorts', $name, $label, $help, $others);
1120 * Helper function to make table creation a little easier. It adds the necessary
1121 * data to the $table array.
1123 function views_table_add_data(&$table, $type, $name, $label, $help, $others = array()) {
1124 $table[$type][$name]['name'] = $label;
1125 $table[$type][$name]['help'] = $help;
1126 foreach ($others as
$key => $value) {
1127 $table[$type][$name][$key] = $value;
1132 * Create a blank view.
1134 function views_create_view($name, $description, $access = array()) {
1135 $view = new
stdClass();
1136 _views_check_arrays($view);
1138 $view->name
= $name;
1139 $view->description
= $description;
1140 $view->access
= $access;
1142 // ensure some things are numerically 0.
1143 $view->nodes_per_page
= 0;
1144 $view->nodes_per_block
= 0;
1149 * Add page info to a view.
1151 function views_view_add_page(&$view, $title, $url, $type, $pager, $nodes_per_page, $header, $header_format, $breadcrumb_no_home = FALSE
) {
1153 $view->page_title
= $title;
1155 $view->page_type
= $type;
1156 $view->use_pager
= $pager;
1157 $view->nodes_per_page
= $nodes_per_page;
1158 $view->page_header
= $header;
1159 $view->page_header_format
= $header_format;
1160 $view->breadcrumb_no_home
= $breadcrumb_no_home;
1164 * Add menu info to a view.
1166 function views_view_add_menu(&$view, $title, $tab, $tab_weight, $default_tab) {
1168 $view->menu_title
= $title;
1169 $view->menu_tab
= $tab;
1170 $view->menu_tab_weight
= $tab_weight;
1171 $view->menu_tab_default
= $default_tab;
1175 * Add block info to a view.
1177 function views_view_add_block(&$view, $title, $type, $nodes_per_block, $more, $use_page_header, $header = '', $header_format = 0) {
1178 $view->block
= TRUE
;
1179 $view->block_title
= $title;
1180 $view->block_type
= $type;
1181 $view->nodes_per_block
= $nodes_per_block;
1182 $view->block_more
= $more;
1183 $view->block_use_page_header
= $use_page_header;
1184 $view->block_header
= $header;
1185 $view->block_header_format
= $header_format;
1189 * Add field info to a view.
1191 function views_view_add_field(&$view, $table, $field, $label, $sortable = FALSE
, $default_sort = 0, $handler = '') {
1192 $view->field
[] = array(
1193 'tablename' => $table,
1196 'sortable' => $sortable,
1197 'defaultsort' => $default_sort,
1198 'handler' => $handler
1203 * Add argument info to a view.
1205 function views_view_add_argument(&$view, $type, $default, $title, $option = '') {
1206 $view->argument
[] = array(
1208 'argdefault' => $default,
1210 'options' => $option,
1215 * Add filter info to a view.
1217 function views_view_add_filter(&$view, $table, $field, $operator, $value, $option) {
1218 $view->filter
[] = array(
1219 'tablename' => $table,
1221 'operator' => $operator,
1223 'options' => $option,
1228 * Add exposed_filter info to a view.
1230 function views_view_add_exposed_filter(&$view, $table, $field, $optional, $is_default, $lock_operator, $single) {
1231 $view->exposed_filter
[] = array(
1232 'tablename' => $table,
1234 'optional' => $optional,
1235 'is_default' => $is_default,
1236 'operator' => $lock_operator,
1242 * Add sort info to a view.
1244 function views_view_add_sort(&$view, $table, $field, $order, $option) {
1245 $view->sort[] = array(
1246 'tablename' => $table,
1248 'sortorder' => $order,
1249 'options' => $option
1253 // ---------------------------------------------------------------------------
1254 // Themeable and support for themeables.
1257 * Themeable function to handle displaying a specific field.
1259 function theme_views_handle_field($fields, $field, $data) {
1260 $info = $fields[$field['fullname']];
1262 if ($field['handler'] && function_exists($field['handler'])) {
1263 return $field['handler']($info, $field, $data->$field['queryname'], $data);
1266 if ($info['handler'] && is_string($info['handler']) && function_exists($info['handler'])) {
1267 return $info['handler']($info, $field, $data->$field['queryname'], $data);
1270 return check_plain($data->$field['queryname']);
1274 * Construct a header for a table view.
1276 function _views_construct_header($view, $fields) {
1277 foreach ($view->field as
$field) {
1279 $info = $fields[$field['fullname']];
1281 $header['data'] = ($field['label'] ?
$field['label'] : $info['name']);
1283 if ($field['sortable']) {
1284 if (function_exists($info['sort_handler'])) {
1285 $header['field'] = $info['sort_handler']($field, $info);
1288 $header['field'] = $field['fullname'];
1291 if ($field['defaultsort']) {
1292 $header['sort'] = strtolower($field['defaultsort']);
1295 // Add CSS id to table cell header cell.
1296 $header['id'] = "view-field-$field[queryname]";
1297 $header['class'] = "view-cell-header";
1298 $headers[] = $header;
1303 function theme_views_display_filters($view) {
1304 $form = views_filters_form($view);
1305 return drupal_get_form("views_filters_$view->name", $form, 'views_filters');
1308 function views_filters_form($view) {
1309 $filters = _views_get_filters();
1310 foreach ($view->exposed_filter as
$count => $expose) {
1311 $id = $expose['id'];
1312 $filterinfo = $filters[$id];
1313 foreach ($view->filter as
$filter) {
1314 if ($filter['id'] == $id) {
1319 // set up the operator widget.
1320 if (!$expose['operator']) {
1321 // 'operator' is either an array or a handler
1322 $operator = $filterinfo['operator'];
1323 if (!is_array($operator) && function_exists($filterinfo['operator'])) {
1324 $operator = $filterinfo['operator']('operator', $filterinfo);
1327 $form["op$count"] = array(
1328 '#name' => "op$count", // get rid of edit[] array.
1329 '#type' => 'select',
1330 '#default_value' => $filter['operator'],
1331 '#options' => $operator,
1333 if (array_key_exists("op$count", $_GET)) {
1334 $form["op$count"]["#default_value"] = $_GET["op$count"];
1339 // set up the filter widget.
1340 $item = $filterinfo['value'];
1341 $item['#name'] = "filter$count";
1343 if (!is_array($item['#options']) && function_exists($item['#options'])) {
1344 $item['#options'] = $item['#options']('value', $filterinfo);
1346 if (!$expose['optional'] || $expose['is_default']) {
1347 $item['#default_value'] = $filter['value'];
1350 if ($expose['single']) {
1351 unset($item['#multiple']);
1353 if ($expose['optional'] && is_array($item['#options'])) {
1354 $item['#options'] = array('**ALL**' => t('<All>')) + $item['#options'];
1357 if ($item['#multiple'] && is_array($item['#options'])) {
1358 $item['#size'] = min(count($item['#options']), 8);
1361 if (array_key_exists("filter$count", $_GET)) {
1362 $item["#default_value"] = $_GET["filter$count"];
1364 $form["filter$count"] = $item;
1366 $form['#method'] = 'get';
1367 $form['#process'] = array('views_filters_process' => array());
1368 $form['view'] = array('#type' => 'value', '#value' => $view);
1369 $form['submit'] = array('#type' => 'button', '#name' => '', '#value' => t('Submit'));
1370 // clean URL get forms breaks if we don't give it a 'q'.
1371 if (!(bool
)variable_get('clean_url', '0')) {
1373 '#type' => 'hidden',
1374 '#value' => $_GET['q'],
1383 function views_filters_process($form) {
1384 unset($form['form_id']);
1387 function theme_views_filters($form) {
1388 $view = $form['view']['#value'];
1390 foreach ($view->exposed_filter as
$count => $expose) {
1391 $row[] = form_render($form["op$count"]) .
form_render($form["filter$count"]);
1392 $label[] = $expose['label'];
1394 $row[] = form_render($form['submit']);
1395 $label[] = ''; // so the column count is the same.
1397 // make the 'q' come first
1398 return form_render($form['q']) .
theme('table', $label, array($row)) .
form_render($form);
1402 * Display the nodes of a view as a list.
1404 function theme_views_view_list($view, $nodes, $type) {
1405 $fields = _views_get_fields();
1407 foreach ($nodes as
$node) {
1409 foreach ($view->field as
$field) {
1410 if ($fields[$field['id']]['visible'] !== FALSE
) {
1411 if ($field['label']) {
1412 $item .
= "<div class='view-label view-label-$field[queryname]'>" .
$field['label'] .
"</div>";
1414 $item .
= "<div class='view-field view-data-$field[queryname]'>" .
views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view) .
"</div>";
1417 $items[] = "<div class='view-item view-item-$view->name'>$item</div>\n"; // l($node->title, "node/$node->nid");
1420 return theme('item_list', $items);
1425 * Display the nodes of a view as a table.
1427 function theme_views_view_table($view, $nodes, $type) {
1428 $fields = _views_get_fields();
1430 foreach ($nodes as
$node) {
1432 foreach ($view->field as
$field) {
1433 if ($fields[$field['id']]['visible'] !== FALSE
) {
1434 $cell['data'] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
1435 $cell['class'] = "view-field view-field-$field[queryname]";
1441 return theme('table', $view->table_header
, $rows);
1445 * Display the nodes of a view as teasers.
1447 function theme_views_view_teasers($view, $nodes, $type) {
1448 return views_theme('views_view_nodes', $view, $nodes, $type, true
);
1452 * Display the nodes of a view as plain nodes.
1454 function theme_views_view_nodes($view, $nodes, $type, $teasers = false
, $links = true
) {
1455 foreach ($nodes as
$n) {
1456 $node = node_load($n->nid
);
1457 $output .
= node_view($node, $teasers, false
, $links);
1462 function views_set_breadcrumb($view) {
1463 $breadcrumb = drupal_get_breadcrumb();
1464 if ($view->breadcrumb_no_home
) {
1465 array_shift($breadcrumb);
1469 // Add a breadcrumb trail for each level of argument we're at.
1473 foreach ($view->args as
$level => $arg) {
1474 if ($view->argument
[$level]['argdefault'] != 1) {
1475 $breadcrumb[] = l(views_get_title($view, 'page', $args), $url);
1479 if ($where && $where = strpos('$arg', $url)) {
1480 $url = substr_replace($url, $arg, $where, 4);
1488 drupal_set_breadcrumb($breadcrumb);
1491 function views_get_textarea($view, $type, $textarea) {
1492 $use_page = "block_use_page_$textarea";
1493 $var = ($type != 'block' || $view->$use_page ?
'page_' : 'block_') .
$textarea;
1494 $format = $var .
'_format';
1497 return "<div class='view-$textarea view-$textarea-$view->name'>"
1498 .
check_markup($view->$var, $view->$format, false
) .
"</div>\n";
1505 function theme_views_view($view, $type, $nodes, $level = NULL
, $args = NULL
) {
1506 $num_nodes = count($nodes);
1508 if ($type == 'page') {
1509 drupal_set_title(views_get_title($view, 'page'));
1510 views_set_breadcrumb($view);
1514 $output .
= views_get_textarea($view, $type, 'header');
1517 if ($type != 'block' && $view->exposed_filter
) {
1518 $output .
= views_theme('views_display_filters', $view);
1523 if ($level !== NULL
) {
1524 $output .
= views_theme('views_summary', $view, $type, $level, $nodes, $args);
1527 $plugins = _views_get_style_plugins();
1528 $view_type = ($type == 'block') ?
$view->block_type
: $view->page_type
;
1529 $output .
= "<div class='view-content view-content-".
$view->name.
"'>".
views_theme($plugins[$view_type]['theme'], $view, $nodes, $type).
'</div>';
1531 $output .
= views_get_textarea($view, $type, 'footer');
1533 if ($type == 'block' && $view->block_more
&& $num_nodes >= $view->nodes_per_block
) {
1534 $output .
= theme('views_more', $view->real_url
);
1538 $output .
= views_get_textarea($view, $type, 'empty');
1541 if ($view->use_pager
) {
1542 $output .
= theme('pager', '', $view->pager_limit
, $view->use_pager
- 1);
1546 $output = "<div class='view view-$view->name'>$output</div>\n";
1552 * Format the 'more' link for a view. Personally I prefer [More] but I've
1553 * been convinced to go with simply 'more'.
1555 function theme_views_more($url) {
1556 return "<div class='more-link'>" .
l(t('more'), $url) .
"</div>";
1560 * Get the summary link for a view.
1562 function views_get_summary_link($argtype, $item, $base) {
1563 $arginfo = _views_get_arguments();
1564 return $arginfo[$argtype]['handler']('link', $item, $argtype, $base);
1568 * In a summary view, each entry links to a more specific entry
1569 * in that view. Construct the base of that link.
1572 function views_get_summary_link_base($argtype, $url, $level, $args) {
1573 $arginfo = _views_get_arguments();
1574 if (!function_exists($arginfo[$argtype]['handler'])) {
1579 for ($i = 0; $i < $level; $i++) {
1580 $arg .= "/$args[$i]";
1587 * Display a summary version of a view.
1589 function theme_views_summary($view, $type, $level, $nodes, $args) {
1590 foreach ($nodes as
$node) {
1591 $items[] = views_get_summary_link($view->argument
[$level]['type'], $node, $view->real_url
) .
" (" .
$node->num_nodes .
")";
1594 $output .
= theme('item_list', $items);
1600 // ---------------------------------------------------------------------------
1601 // Generic handlers. These make sense to be used in a lot of different places.
1604 * Field handlers accept the following arguments:
1606 * The array of info for that field from the global tables array.
1608 * All of the info about that field in the database.
1610 * The value of the field fetched from the database.
1612 * The rest of the data about the node fetched from the database, in case
1613 * the handler needs more than just the field.
1619 function views_handler_field_date($fieldinfo, $fielddata, $value, $data) {
1620 return format_date($value);
1624 * Format a date using small representation.
1626 function views_handler_field_date_small($fieldinfo, $fielddata, $value, $data) {
1627 return format_date($value, 'small');
1631 * Format a date using large representation.
1633 function views_handler_field_date_large($fieldinfo, $fielddata, $value, $data) {
1634 return format_date($value, 'large');
1638 * Format a date using custom representation.
1640 function views_handler_field_date_custom($fieldinfo, $fielddata, $value, $data) {
1641 return format_date($value, 'custom', $fielddata['options']);
1644 * Format a date as "X time ago".
1646 function views_handler_field_since($fieldinfo, $fielddata, $value, $data) {
1647 return format_interval(time() - $value);
1651 * Provide a list of all standard supproted date output handlers.
1653 function views_handler_field_dates() {
1655 'views_handler_field_date_small' => t('As Short Date'),
1656 'views_handler_field_date' => t('As Medium Date'),
1657 'views_handler_field_date_large' => t('As Long Date'),
1658 'views_handler_field_date_custom' => t('As Custom Date'),
1659 'views_handler_field_since' => t('As Time Ago')
1664 * Format a field as an integer.
1666 function views_handler_field_int($fieldinfo, $fielddata, $value, $data) {
1667 return intval($value);
1671 * Argument handlers take up to 4 fields, which vary based upon the operation.
1673 * The operation to perform:
1674 * 'summary': A summary view is being constructed. In this case the handler
1675 * is to add the necessary components to the query to display
1676 * the summary. It must return a $fieldinfo array with 'field'
1677 * set to the field the summary is ordered by; if this is aliased
1678 * for some reason (such as being an aggregate field) set 'fieldname'
1680 * 'sort': Set up the view to sort based upon the setting in $a2.
1681 * 'filter': Filter the view based upon the argument sent; essentially just
1682 * add the where clause here.
1683 * 'link': Provide a link from a summary view based upon the argument sent.
1684 * 'title': Provide the title of a view for substitution.
1686 * For summary, filter and link, this is the actual query object; for title this is
1687 * simply the value of the argument.
1689 * For summary, this is the type of the argument. For the others, this is the info
1690 * for the argument from the global table. (Why is this not consistent? I dunno).
1692 * For summary, this is the 'options' field from the db. For 'filter' this is
1693 * the argument received. For 'link' this is the base URL of the link. Not used
1698 // ---------------------------------------------------------------------------
1702 * There are two kinds of filter handlers here; the easy kind simply creates an
1703 * array of options. For example, for taxonomy we provide a list of all taxonomy
1704 * terms which is placed in the select box.
1706 * The other type is the 'custom' handler which is used to create a customized
1707 * WHERE clause for specialized filters.
1709 * It takes 4 parameters.
1711 * At this time it will always be 'handler'.
1713 * Information on the filter from the database, including 'options', 'value' and 'operator'.
1714 * @param $filterinfo
1715 * Information on the filter from the global table array.
1717 * The query object being worked on.
1721 * A list of and/or/nor.
1723 function views_handler_operator_andor() {
1724 return array('AND' => t('Is All Of'), 'OR' => t('Is One Of'), 'NOR' => t('Is None Of'));
1730 function views_handler_operator_or() {
1731 return array('OR' => t('Is One Of'), 'NOR' => t('Is None Of'));
1735 * A list of equal or not equal to.
1737 function views_handler_operator_eqneq() {
1738 return array('=' => t('Is Equal To'), '!=' => t('Is Not Equal To'));
1742 * A list of greater / equal / less than
1744 function views_handler_operator_gtlt() {
1745 return array('>' => t("Is Greater Than"), '>=' => t("Is Greater Than Or Equals"), '=' => t("Is Equal To"), '!=' => t("Is Not Equal To"), '<=' => t("Is Less Than Or Equals"), '<' => t("Is Less Than"));
1751 function views_handler_operator_yesno() {
1752 return array('1' => t('Yes'), '0' => t('No'));
1756 * Default Views style plugins. Implementation of hook_views_style_plugins()
1758 function views_views_style_plugins() {
1761 'name' => t('List View'),
1762 'theme' => 'views_view_list',
1763 'validate' => 'views_ui_plugin_validate_list',
1764 'needs_fields' => true
,
1767 'name' => t('Table View'),
1768 'theme' => 'views_view_table',
1769 'validate' => 'views_ui_plugin_validate_table',
1770 'needs_fields' => true
,
1771 'needs_table_header' => true
,
1774 'name' => t('Teaser List'),
1775 'theme' => 'views_view_teasers',
1778 'name' => t('Full Nodes'),
1779 'theme' => 'views_view_nodes',
1785 * A list of options to be used in LIKE queries
1787 function views_handler_operator_like() {
1788 return array('=' => t('Is Equal To'), 'contains' => t('Contains'), 'starts' => t('Starts With'), 'ends' => t('Ends With'), 'not' => t('Does Not Contain'));
1792 * Custom filter for LIKE operations
1794 function views_handler_filter_like($op, $filter, $filterinfo, &$query) {
1795 switch (trim($filter['value'])) {
1802 $table = $filterinfo['table'];
1803 $column = $filterinfo['field'];
1804 if (empty($column)) {
1805 $fieldbits = explode('.', $filter['field']);
1806 $column = $fieldbits[1];
1808 $field = "$table.$column";
1809 $query->ensure_table($table);
1811 switch ($filter['operator']) {
1813 $query->add_where("UPPER(%s) LIKE UPPER('%%%s%%')",
1814 $field, $filter['value']);
1817 $query->add_where("UPPER(%s) LIKE UPPER('%s%%')",
1818 $field, $filter['value']);
1821 $query->add_where("UPPER(%s) LIKE UPPER('%%%s')",
1822 $field, $filter['value']);
1825 $query->add_where("UPPER(%s) NOT LIKE UPPER('%%%s%%')",
1826 $field, $filter['value']);
1829 $query->add_where("UPPER(%s) = UPPER('%s')",
1830 $field, $filter['value']);
1838 * Format a field as file size.
1840 function views_handler_field_filesize($fieldinfo, $fielddata, $value, $data) {
1841 return format_size($value);
1845 * Handle a timestamp filter.
1847 function views_handler_filter_timestamp($op, $filter, $filterinfo, &$query) {
1848 $value = $filter['value'] == 'now' ?
"***CURRENT_TIME***" : strtotime($filter['value']);
1850 $table = $filterinfo['table'];
1851 $column = $filterinfo['field'];
1852 if (empty($column)) {
1853 $fieldbits = explode('.', $filter['field']);
1854 $column = $fieldbits[1];
1856 $field = "$table.$column";
1857 if ($filterinfo['from_unixtime']) {
1858 $field = "from_UNIXTIME($field)";
1860 $query->ensure_table($table);
1861 $query->add_where("%s %s %s + %d", $field, $filter['operator'], $value, $filter['options']);
1865 * Provide a form gadget for dates.
1867 function views_handler_filter_date_value_form() {
1869 '#type' => 'textfield',
1870 '#attributes' => array('class' => 'jscalendar'),
1874 * Substitute current time; this works with cached queries.
1876 function views_views_query_substitutions($view) {
1878 return array('***CURRENT_TIME***' => time());
1882 * Returns a themed view.
1884 * The name of the view.
1886 * Required if $use_pager is set; if $limit is set and $use_pager is
1887 * not, this will be the maximum number of records returned. This is ignored
1888 * if using a view set to return a random result. If $use_pager is set and
1889 * this field is not, you'll get a SQL error. Don't do that!
1891 * If set, use a pager. Set this to the pager id you want it to use if you
1892 * plan on using multiple pagers on a page. Note that the pager element id
1893 * will be decremented in order to have the IDs start at 0.
1895 * 'page' -- Produce output as a page, sent through theme.
1896 * The only real difference between this and block is that
1897 * a page uses drupal_set_title to change the page title.
1898 * 'block' -- Produce output as a block, sent through theme.
1899 * 'embed' -- Use this if you want to embed a view onto another page,
1900 * and don't want any block or page specific things to happen to it.
1902 function theme_view( $view_name, $limit = 0, $use_pager = false
, $type = 'embed' ) {
1903 if ($view = views_get_view($view_name)) {
1904 return views_build_view($type, $view, $view_args, $use_pager, $limit);