123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <?php
- function _views_fetch_data($table = NULL, $move = TRUE, $reset = FALSE) {
- $cache = &drupal_static(__FUNCTION__ . '_cache');
- $recursion_protection = &drupal_static(__FUNCTION__ . '_recursion_protected');
- $fully_loaded = &drupal_static(__FUNCTION__ . '_fully_loaded');
- if ($reset) {
- $cache = NULL;
- $fully_loaded = FALSE;
- }
- if ($table) {
- if (!isset($cache[$table])) {
- $cid = 'views_data:' . $table;
- $data = views_cache_get($cid, TRUE);
- if (!empty($data->data)) {
- $cache[$table] = $data->data;
- }
- else {
-
- $cache = _views_fetch_data_build();
- $fully_loaded = TRUE;
- }
- }
- if (isset($cache[$table])) {
- if (isset($cache[$table]['moved to']) && $move) {
- $moved_table = $cache[$table]['moved to'];
- if (!empty($recursion_protection[$table])) {
-
- return NULL;
- }
- $recursion_protection[$table] = TRUE;
- $data = _views_fetch_data($moved_table);
- $recursion_protection = array();
- return $data;
- }
- return $cache[$table];
- }
- }
- else {
- if (!$fully_loaded) {
- $data = views_cache_get('views_data', TRUE);
- if (!empty($data->data)) {
- $cache = $data->data;
- }
- if (empty($cache)) {
- $cache = _views_fetch_data_build();
- }
- $fully_loaded = TRUE;
- }
- return $cache;
- }
-
- return array();
- }
- function _views_fetch_data_build() {
- views_include_handlers();
- $cache = module_invoke_all('views_data');
- foreach (module_implements('views_data_alter') as $module) {
- $function = $module . '_views_data_alter';
- $function($cache);
- }
- _views_data_process_entity_types($cache);
-
- views_cache_set('views_data', $cache, TRUE);
-
- foreach ($cache as $key => $data) {
- $cid = 'views_data:' . $key;
- views_cache_set($cid, $data, TRUE);
- }
- return $cache;
- }
- function _views_data_process_entity_types(&$data) {
- foreach ($data as $table_name => $table_info) {
-
- if (!empty($table_info['table']['entity type'])) {
- $entity_table = 'views_entity_' . $table_info['table']['entity type'];
- $data[$entity_table]['table']['join'][$table_name] = array(
- 'left_table' => $table_name,
- );
- $data[$entity_table]['table']['entity type'] = $table_info['table']['entity type'];
-
- if (!empty($table_info['table']['group']) && empty($data[$entity_table]['table']['group'])) {
- $data[$entity_table]['table']['group'] = $table_info['table']['group'];
- }
- }
- }
- }
- function _views_fetch_plugin_data($type = NULL, $plugin = NULL, $reset = FALSE) {
- static $cache = NULL;
- if (!isset($cache) || $reset) {
- $start = microtime(TRUE);
- views_include('plugins');
- views_include_handlers();
- $cache = views_discover_plugins();
- }
- if (!$type && !$plugin) {
- return $cache;
- }
- elseif (!$plugin) {
-
- if (isset($cache[$type])) {
- return $cache[$type];
- }
- }
- elseif (isset($cache[$type][$plugin])) {
- return $cache[$type][$plugin];
- }
-
- return array();
- }
- function views_cache_set($cid, $data, $use_language = FALSE) {
- global $language;
- if (variable_get('views_skip_cache', FALSE)) {
- return;
- }
- if ($use_language) {
- $cid .= ':' . $language->language;
- }
- cache_set($cid, $data, 'cache_views');
- }
- function views_cache_get($cid, $use_language = FALSE) {
- global $language;
- if (variable_get('views_skip_cache', FALSE)) {
- return FALSE;
- }
- if ($use_language) {
- $cid .= ':' . $language->language;
- }
- return cache_get($cid, 'cache_views');
- }
|