Révision 5d12d676
Ajouté par Assos Assos il y a environ 6 ans
drupal7/sites/all/modules/views/views.module | ||
---|---|---|
36 | 36 |
} |
37 | 37 |
|
38 | 38 |
/** |
39 |
* Advertise the current views api version |
|
39 |
* Advertise the current views api version.
|
|
40 | 40 |
*/ |
41 | 41 |
function views_api_version() { |
42 | 42 |
return '3.0'; |
... | ... | |
81 | 81 |
} |
82 | 82 |
|
83 | 83 |
/** |
84 |
* Implement hook_theme(). Register views theming functions. |
|
84 |
* Implements hook_theme(). |
|
85 |
* |
|
86 |
* Register views theming functions. |
|
85 | 87 |
*/ |
86 | 88 |
function views_theme($existing, $type, $theme, $path) { |
87 | 89 |
$path = drupal_get_path('module', 'views'); |
... | ... | |
93 | 95 |
'path' => $path . '/theme', |
94 | 96 |
); |
95 | 97 |
|
96 |
// Our extra version of pager from pager.inc |
|
98 |
// Our extra version of pager from pager.inc.
|
|
97 | 99 |
$hooks['views_mini_pager'] = $base + array( |
98 |
'variables' => array('tags' => array(), 'element' => 0, 'parameters' => array()), |
|
100 |
'variables' => array( |
|
101 |
'tags' => array(), |
|
102 |
'element' => 0, |
|
103 |
'parameters' => array(), |
|
104 |
), |
|
99 | 105 |
'pattern' => 'views_mini_pager__', |
100 | 106 |
); |
101 | 107 |
|
... | ... | |
104 | 110 |
// $view is an object but the core contextual_preprocess() function only |
105 | 111 |
// attaches contextual links when the primary theme argument is an array. |
106 | 112 |
'display' => array('view_array' => array(), 'view' => NULL), |
107 |
'style' => array('view' => NULL, 'options' => NULL, 'rows' => NULL, 'title' => NULL), |
|
108 |
'row' => array('view' => NULL, 'options' => NULL, 'row' => NULL, 'field_alias' => NULL), |
|
113 |
'style' => array( |
|
114 |
'view' => NULL, |
|
115 |
'options' => NULL, |
|
116 |
'rows' => NULL, |
|
117 |
'title' => NULL, |
|
118 |
), |
|
119 |
'row' => array( |
|
120 |
'view' => NULL, |
|
121 |
'options' => NULL, |
|
122 |
'row' => NULL, |
|
123 |
'field_alias' => NULL, |
|
124 |
), |
|
109 | 125 |
'exposed_form' => array('view' => NULL, 'options' => NULL), |
110 | 126 |
'pager' => array( |
111 |
'view' => NULL, 'options' => NULL, |
|
112 |
'tags' => array(), 'quantity' => 10, 'element' => 0, 'parameters' => array() |
|
127 |
'view' => NULL, |
|
128 |
'options' => NULL, |
|
129 |
'tags' => array(), |
|
130 |
'quantity' => 10, |
|
131 |
'element' => 0, |
|
132 |
'parameters' => array(), |
|
113 | 133 |
), |
114 | 134 |
); |
115 | 135 |
|
116 |
// Default view themes |
|
136 |
// Default view themes.
|
|
117 | 137 |
$hooks['views_view_field'] = $base + array( |
118 | 138 |
'pattern' => 'views_view_field__', |
119 | 139 |
'variables' => array('view' => NULL, 'field' => NULL, 'row' => NULL), |
120 | 140 |
); |
121 | 141 |
$hooks['views_view_grouping'] = $base + array( |
122 | 142 |
'pattern' => 'views_view_grouping__', |
123 |
'variables' => array('view' => NULL, 'grouping' => NULL, 'grouping_level' => NULL, 'rows' => NULL, 'title' => NULL), |
|
143 |
'variables' => array( |
|
144 |
'view' => NULL, |
|
145 |
'grouping' => NULL, |
|
146 |
'grouping_level' => NULL, |
|
147 |
'rows' => NULL, |
|
148 |
'title' => NULL, |
|
149 |
), |
|
124 | 150 |
); |
125 | 151 |
|
126 | 152 |
$plugins = views_fetch_plugin_data(); |
127 | 153 |
|
128 |
// Register theme functions for all style plugins |
|
154 |
// Register theme functions for all style plugins.
|
|
129 | 155 |
foreach ($plugins as $type => $info) { |
130 | 156 |
foreach ($info as $plugin => $def) { |
131 | 157 |
if (isset($def['theme']) && (!isset($def['register theme']) || !empty($def['register theme']))) { |
... | ... | |
180 | 206 |
$hooks['views_more'] = $base + array( |
181 | 207 |
'template' => 'views-more', |
182 | 208 |
'pattern' => 'views_more__', |
183 |
'variables' => array('more_url' => NULL, 'link_text' => 'more', 'view' => NULL), |
|
209 |
'variables' => array( |
|
210 |
'more_url' => NULL, |
|
211 |
'link_text' => 'more', |
|
212 |
'view' => NULL, |
|
213 |
), |
|
184 | 214 |
); |
185 | 215 |
|
186 | 216 |
// Add theme suggestions which are part of modules. |
... | ... | |
195 | 225 |
/** |
196 | 226 |
* Scans a directory of a module for template files. |
197 | 227 |
* |
198 |
* @param $cache |
|
228 |
* @param array $cache
|
|
199 | 229 |
* The existing cache of theme hooks to test against. |
200 |
* @param $path |
|
230 |
* @param string $path
|
|
201 | 231 |
* The path to search. |
202 | 232 |
* |
203 | 233 |
* @see drupal_find_theme_templates() |
204 | 234 |
*/ |
205 | 235 |
function _views_find_module_templates($cache, $path) { |
206 | 236 |
$templates = array(); |
207 |
$regex = '/' . '\.tpl\.php' . '$' . '/';
|
|
237 |
$regex = '/\.tpl\.php$/';
|
|
208 | 238 |
|
209 | 239 |
// Because drupal_system_listing works the way it does, we check for real |
210 | 240 |
// templates separately from checking for patterns. |
... | ... | |
242 | 272 |
// for the purposes of searching. |
243 | 273 |
$pattern = strtr($info['pattern'], '_', '-'); |
244 | 274 |
|
245 |
$matches = preg_grep('/^'. $pattern .'/', $patterns);
|
|
275 |
$matches = preg_grep('/^' . $pattern . '/', $patterns);
|
|
246 | 276 |
if ($matches) { |
247 | 277 |
foreach ($matches as $match) { |
248 | 278 |
$file = substr($match, 0, strpos($match, '.')); |
249 |
// Put the underscores back in for the hook name and register this pattern. |
|
279 |
// Put the underscores back in for the hook name and register this |
|
280 |
// pattern. |
|
250 | 281 |
$templates[strtr($file, '-', '_')] = array( |
251 | 282 |
'template' => $file, |
252 | 283 |
'path' => dirname($files[$match]->uri), |
... | ... | |
315 | 346 |
} |
316 | 347 |
|
317 | 348 |
/** |
349 |
* Preprocess a node. |
|
350 |
* |
|
318 | 351 |
* A theme preprocess function to automatically allow view-based node |
319 | 352 |
* templates if called from a view. |
320 | 353 |
* |
... | ... | |
330 | 363 |
if (!empty($vars['node']->view->current_display)) { |
331 | 364 |
$vars['theme_hook_suggestions'][] = 'node__view__' . $vars['node']->view->name . '__' . $vars['node']->view->current_display; |
332 | 365 |
|
333 |
// If a node is being rendered in a view, and the view does not have a path,
|
|
334 |
// prevent drupal from accidentally setting the $page variable:
|
|
366 |
// If a node is being rendered in a view, and the view does not have a |
|
367 |
// path, prevent drupal from accidentally setting the $page variable.
|
|
335 | 368 |
if ($vars['page'] && $vars['view_mode'] == 'full' && !$vars['view']->display_handler->has_path()) { |
336 | 369 |
$vars['page'] = FALSE; |
337 | 370 |
} |
... | ... | |
345 | 378 |
} |
346 | 379 |
|
347 | 380 |
/** |
381 |
* Preprocess a comment. |
|
382 |
* |
|
348 | 383 |
* A theme preprocess function to automatically allow view-based node |
349 | 384 |
* templates if called from a view. |
350 | 385 |
*/ |
351 | 386 |
function views_preprocess_comment(&$vars) { |
352 |
// The 'view' attribute of the node is added in template_preprocess_views_view_row_comment() |
|
387 |
// The 'view' attribute of the node is added in |
|
388 |
// template_preprocess_views_view_row_comment(). |
|
353 | 389 |
if (!empty($vars['node']->view) && !empty($vars['node']->view->name)) { |
354 | 390 |
$vars['view'] = &$vars['node']->view; |
355 | 391 |
$vars['theme_hook_suggestions'][] = 'comment__view__' . $vars['node']->view->name; |
... | ... | |
360 | 396 |
} |
361 | 397 |
|
362 | 398 |
/** |
363 |
* Implement hook_permission(). |
|
399 |
* Implements hook_permission().
|
|
364 | 400 |
*/ |
365 | 401 |
function views_permission() { |
366 | 402 |
return array( |
... | ... | |
378 | 414 |
} |
379 | 415 |
|
380 | 416 |
/** |
381 |
* Implement hook_menu(). |
|
417 |
* Implements hook_menu().
|
|
382 | 418 |
*/ |
383 | 419 |
function views_menu() { |
384 | 420 |
$items = array(); |
... | ... | |
392 | 428 |
'type' => MENU_CALLBACK, |
393 | 429 |
'file' => 'includes/ajax.inc', |
394 | 430 |
); |
395 |
// Path is not admin/structure/views due to menu complications with the wildcards from
|
|
396 |
// the generic ajax callback. |
|
431 |
// Path is not admin/structure/views due to menu complications with the |
|
432 |
// wildcards from the generic ajax callback.
|
|
397 | 433 |
$items['admin/views/ajax/autocomplete/user'] = array( |
398 | 434 |
'page callback' => 'views_ajax_autocomplete_user', |
399 | 435 |
'theme callback' => 'ajax_base_page_theme', |
... | ... | |
416 | 452 |
} |
417 | 453 |
|
418 | 454 |
/** |
419 |
* Implement hook_menu_alter(). |
|
455 |
* Implements hook_menu_alter().
|
|
420 | 456 |
*/ |
421 | 457 |
function views_menu_alter(&$callbacks) { |
422 | 458 |
$our_paths = array(); |
... | ... | |
425 | 461 |
list($view, $display_id) = $data; |
426 | 462 |
$result = $view->execute_hook_menu($display_id, $callbacks); |
427 | 463 |
if (is_array($result)) { |
428 |
// The menu system doesn't support having two otherwise |
|
429 |
// identical paths with different placeholders. So we |
|
430 |
// want to remove the existing items from the menu whose |
|
431 |
// paths would conflict with ours. |
|
432 |
|
|
433 |
// First, we must find any existing menu items that may |
|
434 |
// conflict. We use a regular expression because we don't |
|
435 |
// know what placeholders they might use. Note that we |
|
436 |
// first construct the regex itself by replacing %views_arg |
|
437 |
// in the display path, then we use this constructed regex |
|
438 |
// (which will be something like '#^(foo/%[^/]*/bar)$#') to |
|
439 |
// search through the existing paths. |
|
464 |
// The menu system doesn't support having two otherwise identical paths |
|
465 |
// with different placeholders. So we want to remove the existing items |
|
466 |
// from the menu whose paths would conflict with ours. First, we must find |
|
467 |
// any existing menu items that may conflict. We use a regular expression |
|
468 |
// because we don't know what placeholders they might use. Note that we |
|
469 |
// first construct the regex itself by replacing %views_arg in the display |
|
470 |
// path, then we use this constructed regex (which will be something like |
|
471 |
// '#^(foo/%[^/]*/bar)$#') to search through the existing paths. |
|
440 | 472 |
$regex = '#^(' . preg_replace('#%views_arg#', '%[^/]*', implode('|', array_keys($result))) . ')$#'; |
441 | 473 |
$matches = preg_grep($regex, array_keys($callbacks)); |
442 | 474 |
|
... | ... | |
457 | 489 |
// This item already exists, so it must be one that we added. |
458 | 490 |
// We change the various callback arguments to pass an array |
459 | 491 |
// of possible display IDs instead of a single ID. |
460 |
$callbacks[$path]['page arguments'][1] = (array)$callbacks[$path]['page arguments'][1]; |
|
492 |
$callbacks[$path]['page arguments'][1] = (array) $callbacks[$path]['page arguments'][1];
|
|
461 | 493 |
$callbacks[$path]['page arguments'][1][] = $display_id; |
462 | 494 |
$callbacks[$path]['access arguments'][] = $item['access arguments'][0]; |
463 |
$callbacks[$path]['load arguments'][1] = (array)$callbacks[$path]['load arguments'][1]; |
|
495 |
$callbacks[$path]['load arguments'][1] = (array) $callbacks[$path]['load arguments'][1];
|
|
464 | 496 |
$callbacks[$path]['load arguments'][1][] = $display_id; |
465 | 497 |
} |
466 | 498 |
$our_paths[$path] = TRUE; |
... | ... | |
476 | 508 |
} |
477 | 509 |
|
478 | 510 |
/** |
511 |
* Load a views argument. |
|
512 |
* |
|
479 | 513 |
* Helper function for menu loading. This will automatically be |
480 | 514 |
* called in order to 'load' a views argument; primarily it |
481 | 515 |
* will be used to perform validation. |
482 | 516 |
* |
483 |
* @param $value |
|
517 |
* @param string $value
|
|
484 | 518 |
* The actual value passed. |
485 |
* @param $name |
|
519 |
* @param string $name
|
|
486 | 520 |
* The name of the view. This needs to be specified in the 'load function' |
487 | 521 |
* of the menu entry. |
488 |
* @param $display_id |
|
522 |
* @param string $display_id
|
|
489 | 523 |
* The display id that will be loaded for this menu item. |
490 |
* @param $index |
|
524 |
* @param int $index
|
|
491 | 525 |
* The menu argument index. This counts from 1. |
492 | 526 |
*/ |
493 | 527 |
function views_arg_load($value, $name, $display_id, $index) { |
494 |
static $views = array(); |
|
528 |
static $views = array();
|
|
495 | 529 |
|
496 | 530 |
$display_ids = is_array($display_id) ? $display_id : array($display_id); |
497 | 531 |
$display_id = reset($display_ids); |
... | ... | |
547 | 581 |
/** |
548 | 582 |
* Page callback: Displays a page view, given a name and display id. |
549 | 583 |
* |
550 |
* @param $name |
|
584 |
* @param string $name
|
|
551 | 585 |
* The name of a view. |
552 |
* @param $display_id |
|
586 |
* @param string $display_id
|
|
553 | 587 |
* The display id of a view. |
554 | 588 |
* |
555 |
* @return |
|
589 |
* @return string|int
|
|
556 | 590 |
* Either the HTML of a fully-executed view, or MENU_NOT_FOUND. |
557 | 591 |
*/ |
558 | 592 |
function views_page($name, $display_id) { |
... | ... | |
616 | 650 |
} |
617 | 651 |
|
618 | 652 |
/** |
619 |
* Implements hook_preprocess_HOOK() for page.tpl.php. |
|
620 |
*/ |
|
653 |
* Implements hook_preprocess_HOOK() for page.tpl.php.
|
|
654 |
*/
|
|
621 | 655 |
function views_preprocess_page(&$variables) { |
622 | 656 |
// If the page contains a view as its main content, contextual links may have |
623 | 657 |
// been attached to the page as a whole; for example, by views_page_alter(). |
... | ... | |
649 | 683 |
} |
650 | 684 |
|
651 | 685 |
/** |
652 |
* Implement hook_block_info(). |
|
686 |
* Implements hook_block_info().
|
|
653 | 687 |
*/ |
654 | 688 |
function views_block_info() { |
655 | 689 |
// Try to avoid instantiating all the views just to get the blocks info. |
... | ... | |
662 | 696 |
$items = array(); |
663 | 697 |
$views = views_get_all_views(); |
664 | 698 |
foreach ($views as $view) { |
665 |
// disabled views get nothing.
|
|
699 |
// Disabled views get nothing.
|
|
666 | 700 |
if (!empty($view->disabled)) { |
667 | 701 |
continue; |
668 | 702 |
} |
... | ... | |
691 | 725 |
// can also be 32. So for very long deltas, change to md5 hashes. |
692 | 726 |
$hashes = array(); |
693 | 727 |
|
694 |
// get the keys because we're modifying the array and we don't want to
|
|
728 |
// Get the keys because we're modifying the array and we don't want to
|
|
695 | 729 |
// confuse PHP too much. |
696 | 730 |
$keys = array_keys($items); |
697 | 731 |
foreach ($keys as $delta) { |
... | ... | |
719 | 753 |
} |
720 | 754 |
|
721 | 755 |
/** |
722 |
* Implement hook_block_view(). |
|
756 |
* Implements hook_block_view().
|
|
723 | 757 |
*/ |
724 | 758 |
function views_block_view($delta) { |
725 |
$start = microtime(TRUE); |
|
726 |
// if this is 32, this should be an md5 hash. |
|
759 |
// If this is 32, this should be an md5 hash. |
|
727 | 760 |
if (strlen($delta) == 32) { |
728 | 761 |
$hashes = variable_get('views_block_hashes', array()); |
729 | 762 |
if (!empty($hashes[$delta])) { |
... | ... | |
758 | 791 |
return; |
759 | 792 |
} |
760 | 793 |
list($name, $display_id) = $explode; |
761 |
// Load the view |
|
794 |
// Load the view.
|
|
762 | 795 |
if ($view = views_get_view($name)) { |
763 | 796 |
if ($view->access($display_id)) { |
764 | 797 |
$output = $view->execute_display($display_id); |
... | ... | |
775 | 808 |
/** |
776 | 809 |
* Converts Views block content to a renderable array with contextual links. |
777 | 810 |
* |
778 |
* @param $block |
|
811 |
* @param array $block
|
|
779 | 812 |
* An array representing the block, with the same structure as the return |
780 | 813 |
* value of hook_block_view(). This will be modified so as to force |
781 | 814 |
* $block['content'] to be a renderable array, containing the optional |
782 | 815 |
* '#contextual_links' property (if there are any contextual links associated |
783 | 816 |
* with the block). |
784 |
* @param $view |
|
817 |
* @param object $view
|
|
785 | 818 |
* The view that was used to generate the block content. |
786 |
* @param $display_id |
|
819 |
* @param string $display_id
|
|
787 | 820 |
* The ID of the display within the view that was used to generate the block |
788 | 821 |
* content. |
789 |
* @param $block_type |
|
822 |
* @param string $block_type
|
|
790 | 823 |
* The type of the block. If it's block it's a regular views display, |
791 | 824 |
* but 'special_block_-exp' exist as well. |
792 | 825 |
*/ |
... | ... | |
833 | 866 |
* later on (for example, alter hooks which run later during the same page |
834 | 867 |
* request). |
835 | 868 |
* |
836 |
* @param $render_element |
|
869 |
* @param array $render_element
|
|
837 | 870 |
* The renderable array to which contextual links will be added. This array |
838 | 871 |
* should be suitable for passing in to drupal_render() and will normally |
839 | 872 |
* contain a representation of the view display whose contextual links are |
840 | 873 |
* being requested. |
841 |
* @param $location |
|
874 |
* @param string $location
|
|
842 | 875 |
* The location in which the calling function intends to render the view and |
843 | 876 |
* its contextual links. The core system supports three options for this |
844 | 877 |
* parameter: |
... | ... | |
858 | 891 |
* declare, via the 'contextual links locations' array key, which view |
859 | 892 |
* displays support having their contextual links rendered in the location |
860 | 893 |
* you have defined. |
861 |
* @param $view |
|
894 |
* @param object $view
|
|
862 | 895 |
* The view whose contextual links will be added. |
863 |
* @param $display_id |
|
896 |
* @param string $display_id
|
|
864 | 897 |
* The ID of the display within $view whose contextual links will be added. |
865 | 898 |
* |
866 | 899 |
* @see hook_views_plugins() |
... | ... | |
878 | 911 |
$plugin = views_fetch_plugin_data('display', $view->display[$display_id]->display_plugin); |
879 | 912 |
// If contextual links locations are not set, provide a sane default. (To |
880 | 913 |
// avoid displaying any contextual links at all, a display plugin can still |
881 |
// set 'contextual links locations' to, e.g., an empty array.)
|
|
914 |
// set 'contextual links locations' to, e.g., an empty array).
|
|
882 | 915 |
$plugin += array('contextual links locations' => array('view')); |
883 | 916 |
// On exposed_forms blocks contextual links should always be visible. |
884 | 917 |
$plugin['contextual links locations'][] = 'special_block_-exp'; |
... | ... | |
920 | 953 |
/** |
921 | 954 |
* Returns an array of language names. |
922 | 955 |
* |
923 |
* This is a one to one copy of locale_language_list because we can't rely on enabled locale module. |
|
956 |
* This is a one to one copy of locale_language_list because we can't rely on |
|
957 |
* enabled locale module. |
|
924 | 958 |
* |
925 |
* @param $field |
|
926 |
* 'name' => names in current language, localized
|
|
927 |
* 'native' => native names
|
|
928 |
* @param $all |
|
929 |
* Boolean to return all languages or only enabled ones |
|
959 |
* @param string $field
|
|
960 |
* Either 'name' for localized names in current language or 'native' for
|
|
961 |
* native names.
|
|
962 |
* @param bool $all
|
|
963 |
* Boolean to return all languages or only enabled ones.
|
|
930 | 964 |
* |
931 | 965 |
* @see locale_language_list() |
932 | 966 |
*/ |
... | ... | |
953 | 987 |
} |
954 | 988 |
|
955 | 989 |
/** |
956 |
* Implements hook_field_create_instance. |
|
990 |
* Implements hook_field_create_instance().
|
|
957 | 991 |
*/ |
958 | 992 |
function views_field_create_instance($instance) { |
959 | 993 |
cache_clear_all('*', 'cache_views', TRUE); |
... | ... | |
961 | 995 |
} |
962 | 996 |
|
963 | 997 |
/** |
964 |
* Implements hook_field_update_instance. |
|
998 |
* Implements hook_field_update_instance().
|
|
965 | 999 |
*/ |
966 | 1000 |
function views_field_update_instance($instance, $prior_instance) { |
967 | 1001 |
cache_clear_all('*', 'cache_views', TRUE); |
... | ... | |
969 | 1003 |
} |
970 | 1004 |
|
971 | 1005 |
/** |
972 |
* Implements hook_field_delete_instance. |
|
1006 |
* Implements hook_field_delete_instance().
|
|
973 | 1007 |
*/ |
974 | 1008 |
function views_field_delete_instance($instance) { |
975 | 1009 |
cache_clear_all('*', 'cache_views', TRUE); |
... | ... | |
1065 | 1099 |
|
1066 | 1100 |
/** |
1067 | 1101 |
* Access callback for the views_plugin_access_role access plugin. |
1068 |
|
|
1102 |
* |
|
1069 | 1103 |
* Determine if the specified user has access to a view on the basis of any of |
1070 | 1104 |
* the requested roles. If the $account argument is omitted, the current user |
1071 | 1105 |
* is used. |
... | ... | |
1077 | 1111 |
$roles[] = $account->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID; |
1078 | 1112 |
return user_access('access all views', $account) || array_intersect(array_filter($rids), $roles); |
1079 | 1113 |
} |
1080 |
// ------------------------------------------------------------------ |
|
1081 |
// Functions to help identify views that are running or ran |
|
1082 | 1114 |
|
1083 | 1115 |
/** |
1116 |
* Set page view. |
|
1117 |
* |
|
1084 | 1118 |
* Set the current 'page view' that is being displayed so that it is easy |
1085 | 1119 |
* for other modules or the theme to identify. |
1086 | 1120 |
*/ |
... | ... | |
1094 | 1128 |
} |
1095 | 1129 |
|
1096 | 1130 |
/** |
1131 |
* Get page view. |
|
1132 |
* |
|
1097 | 1133 |
* Find out what, if any, page view is currently in use. Please note that |
1098 | 1134 |
* this returns a reference, so be careful! You can unintentionally modify the |
1099 | 1135 |
* $view object. |
... | ... | |
1106 | 1142 |
} |
1107 | 1143 |
|
1108 | 1144 |
/** |
1145 |
* Set current view. |
|
1146 |
* |
|
1109 | 1147 |
* Set the current 'current view' that is being built/rendered so that it is |
1110 |
* easy for other modules or items in drupal_eval to identify |
|
1148 |
* easy for other modules or items in drupal_eval to identify.
|
|
1111 | 1149 |
* |
1112 | 1150 |
* @return view |
1151 |
* The current view. |
|
1113 | 1152 |
*/ |
1114 | 1153 |
function &views_set_current_view($view = NULL) { |
1115 | 1154 |
static $cache = NULL; |
... | ... | |
1121 | 1160 |
} |
1122 | 1161 |
|
1123 | 1162 |
/** |
1163 |
* Get current view. |
|
1164 |
* |
|
1124 | 1165 |
* Find out what, if any, current view is currently in use. Please note that |
1125 | 1166 |
* this returns a reference, so be careful! You can unintentionally modify the |
1126 | 1167 |
* $view object. |
1127 | 1168 |
* |
1128 | 1169 |
* @return view |
1170 |
* The current view. |
|
1129 | 1171 |
*/ |
1130 | 1172 |
function &views_get_current_view() { |
1131 | 1173 |
return views_set_current_view(); |
1132 | 1174 |
} |
1133 | 1175 |
|
1134 |
// ------------------------------------------------------------------ |
|
1135 |
// Include file helpers |
|
1136 |
|
|
1137 | 1176 |
/** |
1138 | 1177 |
* Include views .inc files as necessary. |
1139 | 1178 |
*/ |
1140 | 1179 |
function views_include($file) { |
1141 |
ctools_include($file, 'views'); |
|
1180 |
static $views_path; |
|
1181 |
if (!isset($views_path)) { |
|
1182 |
$views_path = DRUPAL_ROOT . '/' . drupal_get_path('module', 'views'); |
|
1183 |
} |
|
1184 |
include_once $views_path . '/includes/' . $file . '.inc'; |
|
1142 | 1185 |
} |
1143 | 1186 |
|
1144 | 1187 |
/** |
... | ... | |
1175 | 1218 |
function views_add_css($file) { |
1176 | 1219 |
// We set preprocess to FALSE because we are adding the files conditionally, |
1177 | 1220 |
// and we don't want to generate duplicate cache files. |
1178 |
// TODO: at some point investigate adding some files unconditionally and
|
|
1221 |
// @todo at some point investigate adding some files unconditionally and
|
|
1179 | 1222 |
// allowing preprocess. |
1180 | 1223 |
drupal_add_css(drupal_get_path('module', 'views') . "/css/$file.css", array('preprocess' => FALSE)); |
1181 | 1224 |
} |
... | ... | |
1219 | 1262 |
$finished = TRUE; |
1220 | 1263 |
} |
1221 | 1264 |
|
1222 |
// ----------------------------------------------------------------------- |
|
1223 |
// Views handler functions |
|
1224 |
|
|
1225 | 1265 |
/** |
1226 | 1266 |
* Fetch a handler from the data cache. |
1227 | 1267 |
* |
1228 |
* @param $table |
|
1268 |
* @param string $table
|
|
1229 | 1269 |
* The name of the table this handler is from. |
1230 |
* @param $field |
|
1270 |
* @param string $field
|
|
1231 | 1271 |
* The name of the field this handler is from. |
1232 |
* @param $key |
|
1233 |
* The type of handler. i.e, sort, field, argument, filter, relationship |
|
1234 |
* @param $override |
|
1235 |
* Override the actual handler object with this class. Used for |
|
1236 |
* aggregation when the handler is redirected to the aggregation |
|
1237 |
* handler. |
|
1272 |
* @param string $key |
|
1273 |
* The type of handler. i.e, sort, field, argument, filter, relationship. |
|
1274 |
* @param mixed $override |
|
1275 |
* Override the actual handler object with this class. Used for aggregation |
|
1276 |
* when the handler is redirected to the aggregation handler. |
|
1238 | 1277 |
* |
1239 | 1278 |
* @return views_handler |
1240 | 1279 |
* An instance of a handler object. May be views_handler_broken. |
... | ... | |
1246 | 1285 |
$handler = NULL; |
1247 | 1286 |
views_include('handlers'); |
1248 | 1287 |
|
1249 |
// Support old views_data entries conversion. |
|
1250 |
|
|
1251 | 1288 |
// Support conversion on table level. |
1252 | 1289 |
if (isset($data['moved to'])) { |
1253 | 1290 |
$moved = array($data['moved to'], $field); |
... | ... | |
1265 | 1302 |
if (!empty($moved)) { |
1266 | 1303 |
list($moved_table, $moved_field) = $moved; |
1267 | 1304 |
if (!empty($recursion_protection[$moved_table][$moved_field])) { |
1268 |
// recursion detected!
|
|
1305 |
// Recursion detected!
|
|
1269 | 1306 |
return NULL; |
1270 | 1307 |
} |
1271 | 1308 |
|
... | ... | |
1273 | 1310 |
$handler = views_get_handler($moved_table, $moved_field, $key, $override); |
1274 | 1311 |
$recursion_protection = array(); |
1275 | 1312 |
if ($handler) { |
1276 |
// store these values so we know what we were originally called.
|
|
1313 |
// Store these values so we know what we were originally called.
|
|
1277 | 1314 |
$handler->original_table = $table; |
1278 | 1315 |
$handler->original_field = $field; |
1279 | 1316 |
if (empty($handler->actual_table)) { |
... | ... | |
1284 | 1321 |
return $handler; |
1285 | 1322 |
} |
1286 | 1323 |
|
1287 |
// Set up a default handler:
|
|
1324 |
// Set up a default handler.
|
|
1288 | 1325 |
if (empty($data[$field][$key]['handler'])) { |
1289 | 1326 |
$data[$field][$key]['handler'] = 'views_handler_' . $key; |
1290 | 1327 |
} |
... | ... | |
1300 | 1337 |
return $handler; |
1301 | 1338 |
} |
1302 | 1339 |
|
1303 |
// DEBUG -- identify missing handlers |
|
1304 |
vpr("Missing handler: @table @field @key", array('@table' => $table, '@field' => $field, '@key' => $key)); |
|
1340 |
// DEBUG -- identify missing handlers. |
|
1341 |
$placeholders = array('@table' => $table, '@field' => $field, '@key' => $key); |
|
1342 |
vpr("Missing handler: @table @field @key", $placeholders); |
|
1305 | 1343 |
$broken = array( |
1306 | 1344 |
'title' => t('Broken handler @table.@field', array('@table' => $table, '@field' => $field)), |
1307 | 1345 |
'handler' => 'views_handler_' . $key . '_broken', |
... | ... | |
1312 | 1350 |
} |
1313 | 1351 |
|
1314 | 1352 |
/** |
1315 |
* Fetch Views' data from the cache |
|
1353 |
* Fetch Views' data from the cache.
|
|
1316 | 1354 |
*/ |
1317 | 1355 |
function views_fetch_data($table = NULL, $move = TRUE, $reset = FALSE) { |
1318 | 1356 |
views_include('cache'); |
1319 | 1357 |
return _views_fetch_data($table, $move, $reset); |
1320 | 1358 |
} |
1321 | 1359 |
|
1322 |
// ----------------------------------------------------------------------- |
|
1323 |
// Views plugin functions |
|
1324 |
|
|
1325 | 1360 |
/** |
1326 | 1361 |
* Fetch the plugin data from cache. |
1327 | 1362 |
*/ |
... | ... | |
1331 | 1366 |
} |
1332 | 1367 |
|
1333 | 1368 |
/** |
1334 |
* Fetch a list of all base tables available |
|
1369 |
* Fetch a list of all base tables available.
|
|
1335 | 1370 |
* |
1336 |
* @param $type |
|
1337 |
* Either 'display', 'style' or 'row' |
|
1338 |
* @param $key |
|
1339 |
* For style plugins, this is an optional type to restrict to. May be 'normal',
|
|
1340 |
* 'summary', 'feed' or others based on the needs of the display. |
|
1341 |
* @param $base |
|
1371 |
* @param string $type
|
|
1372 |
* Either 'display', 'style' or 'row'.
|
|
1373 |
* @param string $key
|
|
1374 |
* For style plugins, this is an optional type to restrict to. May be |
|
1375 |
* 'normal', 'summary', 'feed' or others based on the needs of the display.
|
|
1376 |
* @param array $base
|
|
1342 | 1377 |
* An array of possible base tables. |
1343 | 1378 |
* |
1344 |
* @return |
|
1379 |
* @return array
|
|
1345 | 1380 |
* A keyed array of in the form of 'base_table' => 'Description'. |
1346 | 1381 |
*/ |
1347 | 1382 |
function views_fetch_plugin_names($type, $key = NULL, $base = array()) { |
... | ... | |
1363 | 1398 |
asort($plugins[$type]); |
1364 | 1399 |
return $plugins[$type]; |
1365 | 1400 |
} |
1366 |
// fall-through |
|
1401 |
|
|
1402 |
// Fall-through. |
|
1367 | 1403 |
return array(); |
1368 | 1404 |
} |
1369 | 1405 |
|
1370 | 1406 |
/** |
1371 |
* Get a handler for a plugin |
|
1407 |
* Get a handler for a plugin.
|
|
1372 | 1408 |
* |
1373 | 1409 |
* @return views_plugin |
1374 |
* |
|
1375 |
* The created plugin object. |
|
1410 |
* The created plugin object. |
|
1376 | 1411 |
*/ |
1377 | 1412 |
function views_get_plugin($type, $plugin, $reset = FALSE) { |
1378 | 1413 |
views_include('handlers'); |
... | ... | |
1385 | 1420 |
/** |
1386 | 1421 |
* Load the current enabled localization plugin. |
1387 | 1422 |
* |
1388 |
* @return The name of the localization plugin. |
|
1423 |
* @return string |
|
1424 |
* The name of the localization plugin. |
|
1389 | 1425 |
*/ |
1390 | 1426 |
function views_get_localization_plugin() { |
1391 | 1427 |
$plugin = variable_get('views_localization_plugin', ''); |
... | ... | |
1402 | 1438 |
return $plugin; |
1403 | 1439 |
} |
1404 | 1440 |
|
1405 |
// ----------------------------------------------------------------------- |
|
1406 |
// Views database functions |
|
1407 |
|
|
1408 | 1441 |
/** |
1409 | 1442 |
* Get all view templates. |
1410 | 1443 |
* |
... | ... | |
1445 | 1478 |
} |
1446 | 1479 |
|
1447 | 1480 |
/** |
1448 |
* Return a list of all views and display IDs that have a particular |
|
1449 |
* setting in their display's plugin settings. |
|
1481 |
* Get applicable views. |
|
1450 | 1482 |
* |
1451 |
* @return |
|
1452 |
* @code |
|
1453 |
* array( |
|
1454 |
* array($view, $display_id), |
|
1455 |
* array($view, $display_id), |
|
1456 |
* ); |
|
1457 |
* @endcode |
|
1483 |
* Return a list of all views and display IDs that have a particular setting in |
|
1484 |
* their display's plugin settings. |
|
1485 |
* |
|
1486 |
* @return array |
|
1487 |
* An array with the following structure. |
|
1488 |
* array( |
|
1489 |
* array($view, $display_id), |
|
1490 |
* array($view, $display_id), |
|
1491 |
* ); |
|
1458 | 1492 |
*/ |
1459 | 1493 |
function views_get_applicable_views($type) { |
1460 |
// @todo: Use a smarter flagging system so that we don't have to
|
|
1494 |
// @todo Use a smarter flagging system so that we don't have to |
|
1461 | 1495 |
// load every view for this. |
1462 | 1496 |
$result = array(); |
1463 | 1497 |
$views = views_get_all_views(); |
... | ... | |
1498 | 1532 |
/** |
1499 | 1533 |
* Return an array of all views as fully loaded $view objects. |
1500 | 1534 |
* |
1501 |
* @param $reset |
|
1535 |
* @param bool $reset
|
|
1502 | 1536 |
* If TRUE, reset the static cache forcing views to be reloaded. |
1503 | 1537 |
*/ |
1504 | 1538 |
function views_get_all_views($reset = FALSE) { |
... | ... | |
1523 | 1557 |
} |
1524 | 1558 |
|
1525 | 1559 |
/** |
1560 |
* Get options array. |
|
1561 |
* |
|
1526 | 1562 |
* Return an array of view as options array, that can be used by select, |
1527 | 1563 |
* checkboxes and radios as #options. |
1528 | 1564 |
* |
1529 | 1565 |
* @param bool $views_only |
1530 |
* If TRUE, only return views, not displays. |
|
1566 |
* If TRUE, only return views, not displays.
|
|
1531 | 1567 |
* @param string $filter |
1532 |
* Filters the views on status. Can either be 'all' (default), 'enabled' or |
|
1533 |
* 'disabled'
|
|
1534 |
* @param mixed $exclude_view
|
|
1535 |
* view or current display to exclude
|
|
1536 |
* either a |
|
1537 |
* - views object (containing $exclude_view->name and $exclude_view->current_display)
|
|
1538 |
* - views name as string: e.g. my_view |
|
1539 |
* - views name and display id (separated by ':'): e.g. my_view:default
|
|
1568 |
* Filters the views on status. Can either be 'all' (default), 'enabled' or
|
|
1569 |
* 'disabled'.
|
|
1570 |
* @param mixed $exclude_view |
|
1571 |
* View or current display to exclude
|
|
1572 |
* either a
|
|
1573 |
* - views object (containing name and current_display)
|
|
1574 |
* - views name as string: e.g. my_view
|
|
1575 |
* - views name and display id (separated by ':'): e.g. my_view:default.
|
|
1540 | 1576 |
* @param bool $optgroup |
1541 |
* If TRUE, returns an array with optgroups for each view (will be ignored for |
|
1542 |
* $views_only = TRUE). Can be used by select
|
|
1577 |
* If TRUE, returns an array with optgroups for each view (will be ignored for
|
|
1578 |
* $views_only = TRUE). Can be used by select.
|
|
1543 | 1579 |
* @param bool $sort |
1544 |
* If TRUE, the list of views is sorted ascending. |
|
1580 |
* If TRUE, the list of views is sorted ascending.
|
|
1545 | 1581 |
* |
1546 | 1582 |
* @return array |
1547 |
* an associative array for use in select.
|
|
1548 |
* - key: view name and display id separated by ':', or the view name only |
|
1583 |
* An associative array for use in select.
|
|
1584 |
* - key: view name and display id separated by ':', or the view name only
|
|
1549 | 1585 |
*/ |
1550 | 1586 |
function views_get_views_as_options($views_only = FALSE, $filter = 'all', $exclude_view = NULL, $optgroup = FALSE, $sort = FALSE) { |
1551 | 1587 |
|
... | ... | |
1557 | 1593 |
$func = "views_get_{$filter}_views"; |
1558 | 1594 |
$views = $func(); |
1559 | 1595 |
break; |
1596 |
|
|
1560 | 1597 |
default: |
1561 | 1598 |
return array(); |
1562 | 1599 |
} |
... | ... | |
1621 | 1658 |
* isn't called 'views_load()' primarily because it might get a view |
1622 | 1659 |
* from the default views which aren't technically loaded from the database. |
1623 | 1660 |
* |
1624 |
* @param $name |
|
1661 |
* @param string $name
|
|
1625 | 1662 |
* The name of the view. |
1626 |
* @param $reset |
|
1663 |
* @param bool $reset
|
|
1627 | 1664 |
* If TRUE, reset this entry in the load cache. |
1665 |
* |
|
1628 | 1666 |
* @return view |
1629 | 1667 |
* A reference to the $view object. Use $reset if you're sure you want |
1630 | 1668 |
* a fresh one. |
... | ... | |
1730 | 1768 |
views_invalidate_cache(); |
1731 | 1769 |
} |
1732 | 1770 |
|
1733 |
// ------------------------------------------------------------------ |
|
1734 |
// Views debug helper functions |
|
1735 |
|
|
1736 | 1771 |
/** |
1737 | 1772 |
* Provide debug output for Views. |
1738 | 1773 |
* |
1739 | 1774 |
* This relies on devel.module |
1740 | 1775 |
* or on the debug() function if you use a simpletest. |
1741 | 1776 |
* |
1742 |
* @param $message |
|
1777 |
* @param mixed $message
|
|
1743 | 1778 |
* The message/variable which should be debugged. |
1744 | 1779 |
* This either could be |
1745 | 1780 |
* * an array/object which is converted to pretty output |
1746 |
* * a translation source string which is used together with the parameter placeholders.
|
|
1747 |
* |
|
1748 |
* @param $placeholder
|
|
1781 |
* * a translation source string which is used together with the parameter |
|
1782 |
* placeholders.
|
|
1783 |
* @param array $placeholders
|
|
1749 | 1784 |
* The placeholders which are used for the translation source string. |
1750 | 1785 |
*/ |
1751 | 1786 |
function views_debug($message, $placeholders = array()) { |
... | ... | |
1758 | 1793 |
$output = $message; |
1759 | 1794 |
watchdog('views_logging', $output, $placeholders); |
1760 | 1795 |
} |
1761 |
else if ($devel_region == 'drupal_debug') {
|
|
1796 |
elseif ($devel_region == 'drupal_debug') { |
|
1762 | 1797 |
$output = empty($output) ? t($message, $placeholders) : $output; |
1763 | 1798 |
dd($output); |
1764 | 1799 |
} |
... | ... | |
1774 | 1809 |
} |
1775 | 1810 |
|
1776 | 1811 |
/** |
1777 |
* Shortcut to views_debug() |
|
1812 |
* Shortcut to views_debug().
|
|
1778 | 1813 |
*/ |
1779 | 1814 |
function vpr($message, $placeholders = array()) { |
1780 | 1815 |
views_debug($message, $placeholders); |
1781 | 1816 |
} |
1782 | 1817 |
|
1783 | 1818 |
/** |
1784 |
* Debug messages |
|
1819 |
* Debug messages.
|
|
1785 | 1820 |
*/ |
1786 | 1821 |
function vsm($message) { |
1787 | 1822 |
if (module_exists('devel')) { |
... | ... | |
1792 | 1827 |
function views_trace() { |
1793 | 1828 |
$message = ''; |
1794 | 1829 |
foreach (debug_backtrace() as $item) { |
1795 |
if (!empty($item['file']) && !in_array($item['function'], array('vsm_trace', 'vpr_trace', 'views_trace'))) { |
|
1830 |
$traces = array('vsm_trace', 'vpr_trace', 'views_trace'); |
|
1831 |
if (!empty($item['file']) && !in_array($item['function'], $traces)) { |
|
1796 | 1832 |
$message .= basename($item['file']) . ": " . (empty($item['class']) ? '' : ($item['class'] . '->')) . "$item[function] line $item[line]" . "\n"; |
1797 | 1833 |
} |
1798 | 1834 |
} |
... | ... | |
1807 | 1843 |
dpr(views_trace()); |
1808 | 1844 |
} |
1809 | 1845 |
|
1810 |
// ------------------------------------------------------------------ |
|
1811 |
// Views form (View with form elements) |
|
1812 |
|
|
1813 | 1846 |
/** |
1847 |
* Determine whether the view has form elements. |
|
1848 |
* |
|
1814 | 1849 |
* Returns TRUE if the passed-in view contains handlers with views form |
1815 | 1850 |
* implementations, FALSE otherwise. |
1816 | 1851 |
*/ |
... | ... | |
1832 | 1867 |
|
1833 | 1868 |
/** |
1834 | 1869 |
* This is the entry function. Just gets the form for the current step. |
1870 |
* |
|
1835 | 1871 |
* The form is always assumed to be multistep, even if it has only one |
1836 | 1872 |
* step (the default 'views_form_views_form' step). That way it is actually |
1837 | 1873 |
* possible for modules to have a multistep form if they need to. |
... | ... | |
1859 | 1895 |
|
1860 | 1896 |
/** |
1861 | 1897 |
* Callback for the main step of a Views form. |
1898 |
* |
|
1862 | 1899 |
* Invoked by views_form(). |
1863 | 1900 |
*/ |
1864 | 1901 |
function views_form_views_form($form, &$form_state, $view, $output) { |
... | ... | |
1948 | 1985 |
|
1949 | 1986 |
/** |
1950 | 1987 |
* Validate handler for the first step of the views form. |
1988 |
* |
|
1951 | 1989 |
* Calls any existing views_form_validate functions located |
1952 | 1990 |
* on the views fields. |
1953 | 1991 |
*/ |
... | ... | |
1973 | 2011 |
|
1974 | 2012 |
/** |
1975 | 2013 |
* Submit handler for the first step of the views form. |
2014 |
* |
|
1976 | 2015 |
* Calls any existing views_form_submit functions located |
1977 | 2016 |
* on the views fields. |
1978 | 2017 |
*/ |
... | ... | |
1996 | 2035 |
} |
1997 | 2036 |
} |
1998 | 2037 |
|
1999 |
// ------------------------------------------------------------------ |
|
2000 |
// Exposed widgets form |
|
2001 |
|
|
2002 | 2038 |
/** |
2003 | 2039 |
* Form builder for the exposed widgets form. |
2004 | 2040 |
* |
... | ... | |
2008 | 2044 |
// Don't show the form when batch operations are in progress. |
2009 | 2045 |
if ($batch = batch_get() && isset($batch['current_set'])) { |
2010 | 2046 |
return array( |
2011 |
// Set the theme callback to be nothing to avoid errors in template_preprocess_views_exposed_form(). |
|
2047 |
// Set the theme callback to be nothing to avoid errors in |
|
2048 |
// template_preprocess_views_exposed_form(). |
|
2012 | 2049 |
'#theme' => '', |
2013 | 2050 |
); |
2014 | 2051 |
} |
... | ... | |
2023 | 2060 |
|
2024 | 2061 |
// Let form plugins know this is for exposed widgets. |
2025 | 2062 |
$form_state['exposed'] = TRUE; |
2026 |
// Check if the form was already created |
|
2063 |
// Check if the form was already created.
|
|
2027 | 2064 |
if ($cache = views_exposed_form_cache($view->name, $view->current_display)) { |
2028 | 2065 |
return $cache; |
2029 | 2066 |
} |
... | ... | |
2060 | 2097 |
} |
2061 | 2098 |
} |
2062 | 2099 |
|
2100 |
// Form submit, #name is an empty string to prevent showing up in $_GET. |
|
2063 | 2101 |
$form['submit'] = array( |
2064 |
'#name' => '', // prevent from showing up in $_GET.
|
|
2102 |
'#name' => '', |
|
2065 | 2103 |
'#type' => 'submit', |
2066 | 2104 |
'#value' => t('Apply'), |
2067 | 2105 |
'#id' => drupal_html_id('edit-submit-' . $view->name), |
... | ... | |
2070 | 2108 |
$form['#action'] = url($view->display_handler->get_url()); |
2071 | 2109 |
$form['#theme'] = views_theme_functions('views_exposed_form', $view, $display); |
2072 | 2110 |
$form['#id'] = drupal_clean_css_identifier('views_exposed_form-' . check_plain($view->name) . '-' . check_plain($display->id)); |
2073 |
// $form['#attributes']['class'] = array('views-exposed-form'); |
|
2074 | 2111 |
|
2075 | 2112 |
// If using AJAX, we need the form plugin. |
2076 | 2113 |
if ($view->use_ajax) { |
... | ... | |
2081 | 2118 |
$exposed_form_plugin = $form_state['exposed_form_plugin']; |
2082 | 2119 |
$exposed_form_plugin->exposed_form_alter($form, $form_state); |
2083 | 2120 |
|
2084 |
// Save the form |
|
2121 |
// Save the form.
|
|
2085 | 2122 |
views_exposed_form_cache($view->name, $view->current_display, $form); |
2086 | 2123 |
|
2087 | 2124 |
return $form; |
2088 | 2125 |
} |
2089 | 2126 |
|
2090 | 2127 |
/** |
2091 |
* Implement hook_form_alter for the exposed form.
|
|
2128 |
* Implements hook_form_alter() for views_exposed_form().
|
|
2092 | 2129 |
* |
2093 | 2130 |
* Since the exposed form is a GET form, we don't want it to send a wide |
2094 | 2131 |
* variety of information. |
... | ... | |
2100 | 2137 |
} |
2101 | 2138 |
|
2102 | 2139 |
/** |
2103 |
* Validate handler for exposed filters |
|
2140 |
* Validate handler for exposed filters.
|
|
2104 | 2141 |
*/ |
2105 | 2142 |
function views_exposed_form_validate(&$form, &$form_state) { |
2106 | 2143 |
foreach (array('field', 'filter') as $type) { |
... | ... | |
2114 | 2151 |
} |
2115 | 2152 |
|
2116 | 2153 |
/** |
2117 |
* Submit handler for exposed filters |
|
2154 |
* Submit handler for exposed filters.
|
|
2118 | 2155 |
*/ |
2119 | 2156 |
function views_exposed_form_submit(&$form, &$form_state) { |
2120 | 2157 |
foreach (array('field', 'filter') as $type) { |
... | ... | |
2126 | 2163 |
$form_state['view']->exposed_data = $form_state['values']; |
2127 | 2164 |
$form_state['view']->exposed_raw_input = array(); |
2128 | 2165 |
|
2129 |
|
|
2130 |
$exclude = array('q', 'submit', 'form_build_id', 'form_id', 'form_token', 'exposed_form_plugin', '', 'reset'); |
|
2166 |
$exclude = array( |
|
2167 |
'q', |
|
2168 |
'submit', |
|
2169 |
'form_build_id', |
|
2170 |
'form_id', |
|
2171 |
'form_token', |
|
2172 |
'exposed_form_plugin', |
|
2173 |
'', |
|
2174 |
'reset', |
|
2175 |
); |
|
2131 | 2176 |
$exposed_form_plugin = $form_state['exposed_form_plugin']; |
2132 | 2177 |
$exposed_form_plugin->exposed_form_submit($form, $form_state, $exclude); |
2133 | 2178 |
|
... | ... | |
2141 | 2186 |
/** |
2142 | 2187 |
* Save the Views exposed form for later use. |
2143 | 2188 |
* |
2144 |
* @param $views_name |
|
2145 |
* String. The views name. |
|
2146 |
* @param $display_name |
|
2147 |
* String. The current view display name. |
|
2148 |
* @param $form_output |
|
2149 |
* Array (optional). The form structure. Only needed when inserting the value. |
|
2150 |
* @return |
|
2189 |
* @param string $views_name |
|
2190 |
* The views name. |
|
2191 |
* @param string $display_name |
|
2192 |
* The current view display name. |
|
2193 |
* @param array $form_output |
|
2194 |
* An optional form structure. Only needed when inserting the value. |
|
2195 |
* |
|
2196 |
* @return array|bool |
|
2151 | 2197 |
* Array. The form structure, if any. Otherwise, return FALSE. |
2152 | 2198 |
*/ |
2153 | 2199 |
function views_exposed_form_cache($views_name, $display_name, $form_output = NULL) { |
... | ... | |
2155 | 2201 |
// be cleared between each test. |
2156 | 2202 |
$views_exposed = &drupal_static(__FUNCTION__); |
2157 | 2203 |
|
2158 |
// Save the form output |
|
2204 |
// Save the form output.
|
|
2159 | 2205 |
if (!empty($form_output)) { |
2160 | 2206 |
$views_exposed[$views_name][$display_name] = $form_output; |
2161 |
return; |
|
2162 | 2207 |
} |
2163 | 2208 |
|
2164 |
// Return the form output, if any |
|
2209 |
// Return the form output, if any.
|
|
2165 | 2210 |
return empty($views_exposed[$views_name][$display_name]) ? FALSE : $views_exposed[$views_name][$display_name]; |
2166 | 2211 |
} |
2167 | 2212 |
|
2168 |
// ------------------------------------------------------------------ |
|
2169 |
// Misc helpers |
|
2170 |
|
|
2171 | 2213 |
/** |
2172 | 2214 |
* Build a list of theme function names for use most everywhere. |
2173 | 2215 |
*/ |
... | ... | |
2252 | 2294 |
* to do that, you will need to do what this function does manually, by |
2253 | 2295 |
* loading the view, getting the preview and then getting $view->get_title(). |
2254 | 2296 |
* |
2255 |
* @param $name |
|
2297 |
* @param string $name
|
|
2256 | 2298 |
* The name of the view to embed. |
2257 |
* @param $display_id |
|
2299 |
* @param string $display_id
|
|
2258 | 2300 |
* The display id to embed. If unsure, use 'default', as it will always be |
2259 | 2301 |
* valid. But things like 'page' or 'block' should work here. |
2260 | 2302 |
* @param ... |
... | ... | |
2262 | 2304 |
*/ |
2263 | 2305 |
function views_embed_view($name, $display_id = 'default') { |
2264 | 2306 |
$args = func_get_args(); |
2265 |
array_shift($args); // remove $name |
|
2307 |
// Remove $name. |
|
2308 |
array_shift($args); |
|
2266 | 2309 |
if (count($args)) { |
2267 |
array_shift($args); // remove $display_id |
|
2310 |
// Remove $display_id. |
|
2311 |
array_shift($args); |
|
2268 | 2312 |
} |
2269 | 2313 |
|
2270 | 2314 |
$view = views_get_view($name); |
... | ... | |
2289 | 2333 |
* Everything after #views-tab- is the display ID, e.g. page_1. |
2290 | 2334 |
* @param ... |
2291 | 2335 |
* Any additional parameters will be passed as arguments. |
2336 |
* |
|
2292 | 2337 |
* @return array |
2293 | 2338 |
* An array containing an object for each view item. |
2294 | 2339 |
*/ |
2295 | 2340 |
function views_get_view_result($name, $display_id = NULL) { |
2296 | 2341 |
$args = func_get_args(); |
2297 |
array_shift($args); // remove $name |
|
2342 |
// Remove $name. |
|
2343 |
array_shift($args); |
|
2298 | 2344 |
if (count($args)) { |
2299 |
array_shift($args); // remove $display_id |
|
2345 |
// Remove $display_id. |
|
2346 |
array_shift($args); |
|
2300 | 2347 |
} |
2301 | 2348 |
|
2302 | 2349 |
$view = views_get_view($name); |
... | ... | |
2361 | 2408 |
} |
2362 | 2409 |
|
2363 | 2410 |
/** |
2364 |
* Prepare a string for use as a valid CSS identifier (element, class or ID name). |
|
2365 |
* This function is similar to a core version but with more sane filter values. |
|
2411 |
* Prepare a string for use as a valid CSS identifier. |
|
2366 | 2412 |
* |
2413 |
* This function is similar to a core version but with more sane filter values. |
|
2367 | 2414 |
* http://www.w3.org/TR/CSS21/syndata.html#characters shows the syntax for valid |
2368 |
* CSS identifiers (including element names, classes, and IDs in selectors.)
|
|
2415 |
* CSS identifiers (including element names, classes, and IDs in selectors).
|
|
2369 | 2416 |
* |
2370 |
* @param $identifier |
|
2417 |
* @param string $identifier
|
|
2371 | 2418 |
* The identifier to clean. |
2372 |
* @param $filter |
|
2419 |
* @param array $filter
|
|
2373 | 2420 |
* An array of string replacements to use on the identifier. |
2374 |
* @return |
|
2421 |
* |
|
2422 |
* @return string |
|
2375 | 2423 |
* The cleaned identifier. |
2376 | 2424 |
* |
2377 | 2425 |
* @see drupal_clean_css_identifier() |
2378 | 2426 |
*/ |
2379 |
function views_clean_css_identifier($identifier, $filter = array(' ' => '-', '/' => '-', '[' => '-', ']' => '')) { |
|
2427 |
function views_clean_css_identifier($identifier, $filter = array( |
|
2428 |
' ' => '-', |
|
2429 |
'/' => '-', |
|
2430 |
'[' => '-', |
|
2431 |
']' => '', |
|
2432 |
)) { |
|
2380 | 2433 |
// By default, we filter using Drupal's coding standards. |
2381 | 2434 |
$identifier = strtr($identifier, $filter); |
2382 | 2435 |
|
... | ... | |
2394 | 2447 |
} |
2395 | 2448 |
|
2396 | 2449 |
/** |
2397 |
* Implement hook_views_exportables(). |
|
2450 |
* Implements hook_views_exportables().
|
|
2398 | 2451 |
*/ |
2399 | 2452 |
function views_views_exportables($op = 'list', $views = NULL, $name = 'foo') { |
2400 | 2453 |
$all_views = views_get_all_views(); |
2401 | 2454 |
if ($op == 'list') { |
2402 | 2455 |
|
2403 | 2456 |
foreach ($all_views as $name => $view) { |
2404 |
// in list, $views is a list of tags.
|
|
2457 |
// In list, $views is a list of tags.
|
|
2405 | 2458 |
if (empty($views) || in_array($view->tag, $views)) { |
2406 | 2459 |
$return[$name] = array( |
2407 | 2460 |
'name' => check_plain($name), |
2408 | 2461 |
'desc' => check_plain($view->description), |
2409 |
'tag' => check_plain($view->tag) |
|
2462 |
'tag' => check_plain($view->tag),
|
|
2410 | 2463 |
); |
2411 | 2464 |
} |
2412 | 2465 |
} |
... | ... | |
2433 | 2486 |
} |
2434 | 2487 |
|
2435 | 2488 |
/** |
2436 |
* #process callback to see if we need to check_plain() the options.
|
|
2489 |
* Process callback to see if we need to check_plain() the options.
|
|
2437 | 2490 |
* |
2438 | 2491 |
* Since FAPI is inconsistent, the #options are sanitized for you in all cases |
2439 | 2492 |
* _except_ checkboxes. We have form elements that are sometimes 'select' and |
... | ... | |
2451 | 2504 |
/** |
2452 | 2505 |
* Trim the field down to the specified length. |
2453 | 2506 |
* |
2454 |
* @param $alter |
|
2507 |
* @param array $alter
|
|
2455 | 2508 |
* - max_length: Maximum length of the string, the rest gets truncated. |
2456 | 2509 |
* - word_boundary: Trim only on a word boundary. |
2457 | 2510 |
* - ellipsis: Show an ellipsis (...) at the end of the trimmed string. |
2458 | 2511 |
* - html: Take sure that the html is correct. |
2459 |
* |
|
2460 |
* @param $value |
|
2512 |
* @param string $value |
|
2461 | 2513 |
* The string which should be trimmed. |
2462 | 2514 |
*/ |
2463 | 2515 |
function views_trim_text($alter, $value) { |
2464 | 2516 |
if (drupal_strlen($value) > $alter['max_length']) { |
2465 | 2517 |
$value = drupal_substr($value, 0, $alter['max_length']); |
2466 |
// TODO: replace this with cleanstring of ctools
|
|
2518 |
// @todo Replace this with cleanstring of CTools.
|
|
2467 | 2519 |
if (!empty($alter['word_boundary'])) { |
2468 | 2520 |
$regex = "(.*)\b.+"; |
2469 | 2521 |
if (function_exists('mb_ereg')) { |
... | ... | |
2477 | 2529 |
$value = $matches[1]; |
2478 | 2530 |
} |
2479 | 2531 |
} |
2480 |
// Remove scraps of HTML entities from the end of a strings |
|
2532 |
// Remove scraps of HTML entities from the end of a strings.
|
|
2481 | 2533 |
$value = rtrim(preg_replace('/(?:<(?!.+>)|&(?!.+;)).*$/us', '', $value)); |
2482 | 2534 |
|
2483 | 2535 |
if (!empty($alter['ellipsis'])) { |
... | ... | |
2500 | 2552 |
$keys = array_keys($array); |
2501 | 2553 |
rsort($keys); |
2502 | 2554 |
foreach ($keys as $key) { |
2503 |
$array[$key+1] = $array[$key];
|
|
2555 |
$array[$key + 1] = $array[$key];
|
|
2504 | 2556 |
unset($array[$key]); |
2505 | 2557 |
} |
2506 | 2558 |
asort($array); |
... | ... | |
2508 | 2560 |
} |
2509 | 2561 |
|
2510 | 2562 |
/** |
2511 |
* Report to CTools that we use hook_views_api instead of hook_ctools_plugin_api() |
|
2563 |
* Implements hook_ctools_plugin_api_hook_name(). |
|
2564 |
* |
|
2565 |
* Report to CTools that we use hook_views_api instead of |
|
2566 |
* hook_ctools_plugin_api(). |
|
2512 | 2567 |
*/ |
2513 | 2568 |
function views_ctools_plugin_api_hook_name() { |
2514 | 2569 |
return 'views_api'; |
2515 | 2570 |
} |
2516 | 2571 |
|
2517 |
// Declare API compatibility on behalf of core modules: |
|
2518 |
|
|
2519 | 2572 |
/** |
2520 | 2573 |
* Implements hook_views_api(). |
2521 | 2574 |
* |
... | ... | |
2523 | 2576 |
*/ |
2524 | 2577 |
function views_views_api() { |
2525 | 2578 |
return array( |
2526 |
// in your modules do *not* use views_api_version()!!!
|
|
2579 |
// In your modules do *not* use views_api_version()!!!
|
|
2527 | 2580 |
'api' => views_api_version(), |
2528 | 2581 |
'path' => drupal_get_path('module', 'views') . '/modules', |
2529 | 2582 |
); |
2530 | 2583 |
} |
2531 | 2584 |
|
2532 | 2585 |
if (!function_exists('aggregator_views_api')) { |
2533 |
function aggregator_views_api() { return views_views_api(); } |
|
2586 |
/** |
|
2587 |
* Provide Views integration for the Aggregator module. |
|
2588 |
*/ |
|
2589 |
function aggregator_views_api() { |
|
2590 |
return views_views_api(); |
|
2591 |
} |
|
2534 | 2592 |
} |
2535 | 2593 |
|
2536 | 2594 |
if (!function_exists('book_views_api')) { |
2537 |
function book_views_api() { return views_views_api(); } |
|
2595 |
/** |
|
2596 |
* Provide Views integration for the Book module. |
|
2597 |
*/ |
|
2598 |
function book_views_api() { |
|
2599 |
return views_views_api(); |
|
2600 |
} |
|
2538 | 2601 |
} |
2539 | 2602 |
|
2540 | 2603 |
if (!function_exists('comment_views_api')) { |
2541 |
function comment_views_api() { return views_views_api(); } |
|
2604 |
/** |
|
2605 |
* Provide Views integration for the Comment module. |
|
2606 |
*/ |
|
2607 |
function comment_views_api() { |
|
2608 |
return views_views_api(); |
|
2609 |
} |
|
2542 | 2610 |
} |
2543 | 2611 |
|
2544 | 2612 |
if (!function_exists('field_views_api')) { |
2545 |
function field_views_api() { return views_views_api(); } |
|
2613 |
/** |
|
2614 |
* Provide Views integration for the Field module. |
|
2615 |
*/ |
|
2616 |
function field_views_api() { |
|
2617 |
return views_views_api(); |
|
2618 |
} |
|
2546 | 2619 |
} |
2547 | 2620 |
|
2548 | 2621 |
if (!function_exists('file_views_api')) { |
2549 |
function file_views_api() { return views_views_api(); } |
|
2622 |
/** |
|
2623 |
* Provide Views integration for the File module. |
|
2624 |
*/ |
|
2625 |
function file_views_api() { |
|
2626 |
return views_views_api(); |
|
2627 |
} |
|
2550 | 2628 |
} |
2551 | 2629 |
|
2552 | 2630 |
if (!function_exists('filter_views_api')) { |
2553 |
function filter_views_api() { return views_views_api(); } |
|
2631 |
/** |
|
2632 |
* Provide Views integration for the Filter module. |
|
2633 |
*/ |
|
2634 |
function filter_views_api() { |
|
2635 |
return views_views_api(); |
|
2636 |
} |
|
2554 | 2637 |
} |
2555 | 2638 |
|
2556 | 2639 |
if (!function_exists('image_views_api')) { |
2557 |
function image_views_api() { return views_views_api(); } |
|
2640 |
/** |
|
2641 |
* Provide Views integration for the Image module. |
|
2642 |
*/ |
|
2643 |
function image_views_api() { |
|
2644 |
return views_views_api(); |
|
2645 |
} |
|
2558 | 2646 |
} |
2559 | 2647 |
|
2560 | 2648 |
if (!function_exists('locale_views_api')) { |
2561 |
function locale_views_api() { return views_views_api(); } |
|
2649 |
/** |
|
2650 |
* Provide Views integration for the Locale module. |
|
2651 |
*/ |
|
2652 |
function locale_views_api() { |
|
2653 |
return views_views_api(); |
|
2654 |
} |
|
2562 | 2655 |
} |
2563 | 2656 |
|
2564 | 2657 |
if (!function_exists('node_views_api')) { |
2565 |
function node_views_api() { return views_views_api(); } |
|
2658 |
/** |
|
2659 |
* Provide Views integration for the Node module. |
|
2660 |
*/ |
|
2661 |
function node_views_api() { |
|
2662 |
return views_views_api(); |
|
2663 |
} |
|
2566 | 2664 |
} |
2567 | 2665 |
|
2568 | 2666 |
if (!function_exists('poll_views_api')) { |
2569 |
function poll_views_api() { return views_views_api(); } |
|
2667 |
/** |
|
2668 |
* Provide Views integration for the Poll module. |
|
2669 |
*/ |
|
2670 |
function poll_views_api() { |
|
2671 |
return views_views_api(); |
|
2672 |
} |
|
2570 | 2673 |
} |
2571 | 2674 |
|
2572 | 2675 |
if (!function_exists('profile_views_api')) { |
2573 |
function profile_views_api() { return views_views_api(); } |
|
2676 |
/** |
|
2677 |
* Provide Views integration for the Profile module. |
|
2678 |
*/ |
|
2679 |
function profile_views_api() { |
|
2680 |
return views_views_api(); |
|
2681 |
} |
|
2574 | 2682 |
} |
2575 | 2683 |
|
2576 | 2684 |
if (!function_exists('search_views_api')) { |
2577 |
function search_views_api() { return views_views_api(); } |
|
2685 |
/** |
|
2686 |
* Provide Views integration for the Search module. |
|
2687 |
*/ |
|
2688 |
function search_views_api() { |
|
2689 |
return views_views_api(); |
|
2690 |
} |
|
2578 | 2691 |
} |
2579 | 2692 |
|
2580 | 2693 |
if (!function_exists('statistics_views_api')) { |
2581 |
function statistics_views_api() { return views_views_api(); } |
|
2694 |
/** |
|
2695 |
* Provide Views integration for the Statistics module. |
|
2696 |
*/ |
|
2697 |
function statistics_views_api() { |
|
2698 |
return views_views_api(); |
|
2699 |
} |
|
2582 | 2700 |
} |
2583 | 2701 |
|
2584 | 2702 |
if (!function_exists('system_views_api')) { |
2585 |
function system_views_api() { return views_views_api(); } |
|
2703 |
/** |
|
2704 |
* Provide Views integration for the System module. |
|
2705 |
*/ |
|
2706 |
function system_views_api() { |
|
2707 |
return views_views_api(); |
|
2708 |
} |
|
2586 | 2709 |
} |
2587 | 2710 |
|
2588 | 2711 |
if (!function_exists('tracker_views_api')) { |
2589 |
function tracker_views_api() { return views_views_api(); } |
|
2712 |
/** |
|
2713 |
* Provide Views integration for the Tracker module. |
|
2714 |
*/ |
|
2715 |
function tracker_views_api() { |
|
2716 |
return views_views_api(); |
|
2717 |
} |
|
2590 | 2718 |
} |
2591 | 2719 |
|
2592 | 2720 |
if (!function_exists('taxonomy_views_api')) { |
2593 |
function taxonomy_views_api() { return views_views_api(); } |
|
2721 |
/** |
|
2722 |
* Provide Views integration for the Taxonomy module. |
|
2723 |
*/ |
|
2724 |
function taxonomy_views_api() { |
|
2725 |
return views_views_api(); |
|
2726 |
} |
|
2594 | 2727 |
} |
2595 | 2728 |
|
2596 | 2729 |
if (!function_exists('translation_views_api')) { |
2597 |
function translation_views_api() { return views_views_api(); } |
|
2730 |
/** |
|
2731 |
* Provide Views integration for the Translation module. |
|
2732 |
*/ |
|
2733 |
function translation_views_api() { |
|
2734 |
return views_views_api(); |
|
2735 |
} |
|
2598 | 2736 |
} |
2599 | 2737 |
|
2600 | 2738 |
if (!function_exists('user_views_api')) { |
2601 |
function user_views_api() { return views_views_api(); } |
|
2739 |
/** |
|
2740 |
* Provide Views integration for the User module. |
|
2741 |
*/ |
|
2742 |
function user_views_api() { |
|
2743 |
return views_views_api(); |
|
2744 |
} |
|
2602 | 2745 |
} |
2603 | 2746 |
|
2604 | 2747 |
if (!function_exists('contact_views_api')) { |
2605 |
function contact_views_api() { return views_views_api(); } |
|
2748 |
/** |
|
2749 |
* Provide Views integration for the Contact module. |
|
2750 |
*/ |
|
2751 |
function contact_views_api() { |
|
2752 |
return views_views_api(); |
|
2753 |
} |
|
2606 | 2754 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules