diff --git a/includes/cache.inc b/includes/cache.inc index 590592d..129a998 100644 --- a/includes/cache.inc +++ b/includes/cache.inc @@ -93,63 +93,25 @@ function _views_fetch_plugin_data($type = NULL, $plugin = NULL, $reset = FALSE) /** * Scan all modules for default views and rebuild the default views cache. * - * @return An associative array of all known default views. + * @return + * For PHP > 5.0, returns a class implementing ArrayAccess. For PHP < 5.0 + * returns an array of all default views. */ function _views_discover_default_views($reset = FALSE) { - static $cache = NULL; - - if (!isset($cache) || $reset) { - $index = views_cache_get('views_default_views_index', TRUE); - - // Retrieve each cached default view - if (!$reset && isset($index->data) && is_array($index->data)) { - $cache = array(); - foreach ($index->data as $view_name) { - $data = views_cache_get('views_default:' . $view_name, TRUE); - if (isset($data->data) && is_object($data->data)) { - $cache[$view_name] = $data->data; - } - } - } - // If missing index, rebuild the cache - else { - views_include_default_views(); - $cache = array(); - - foreach (module_implements('views_default_views') as $module) { - $results = call_user_func($module . "_views_default_views"); - if (!empty($results) && is_array($results)) { - foreach($results as $name => $view) { - // Only views with a sufficiently high api version are eligible. - if (!empty($view->api_version) && $view->api_version >= 2) { - // Do not cache dead handlers. - $view->destroy(); - if (!isset($cache[$name])) { - $cache[$name] = $view; - } - else { - watchdog('view', "View name '@name' is already taken", array('@name' => $name), WATCHDOG_ERROR); - } - } - } - } - } - - // Allow modules to modify default views before they are cached. - drupal_alter('views_default_views', $cache); + static $php5; - // Cache the index - $index = array_keys($cache); - views_cache_set('views_default_views_index', $index, TRUE); - - // Cache each view - foreach ($cache as $name => $view) { - views_cache_set('views_default:' . $name, $view, TRUE); - } - } + // ArrayAccess is not available in PHP < 5.0. Therefore this function + // supports separate code paths depending on version. + if (!isset($php5)) { + $php5 = version_compare(PHP_VERSION, '5.0', '>='); } - - return $cache; + if ($php5) { + module_load_include('inc', 'views', 'includes/php5'); + } + else { + module_load_include('inc', 'views', 'includes/php4'); + } + return _views_default_views_cache($reset); } /** diff --git a/views.module b/views.module index 04b52ad..a22a37b 100644 --- a/views.module +++ b/views.module @@ -957,7 +957,7 @@ function views_get_localization_plugin() { * @return * A view object or NULL if it is not available. */ -function &views_get_default_view($view_name, $reset = FALSE) { +function views_get_default_view($view_name, $reset = FALSE) { $null = NULL; // Attempt to load individually cached view from cache. @@ -1066,36 +1066,20 @@ function views_get_applicable_views($type) { * If TRUE, reset the static cache forcing views to be reloaded. */ function views_get_all_views($reset = FALSE) { - static $views = array(); - - if (empty($views) || $reset) { - $views = array(); - - // First, get all applicable views. - views_include('view'); - $views = view::load_views(); - - // Get all default views. - $status = variable_get('views_defaults', array()); - - foreach (views_discover_default_views($reset) as $view) { - // Determine if default view is enabled or disabled. - if (isset($status[$view->name])) { - $view->disabled = $status[$view->name]; - } - - // If overridden, also say so. - if (!empty($views[$view->name])) { - $views[$view->name]->type = t('Overridden'); - } - else { - $view->type = t('Default'); - $views[$view->name] = $view; - } - } + static $php5; + // ArrayAccess is not available in PHP < 5.0. Therefore this function + // supports separate code paths depending on version. + if (!isset($php5)) { + $php5 = version_compare(PHP_VERSION, '5.0', '>='); + } + if ($php5) { + module_load_include('inc', 'views', 'includes/php5'); + } + else { + module_load_include('inc', 'views', 'includes/php4'); } - return $views; + return _views_get_all_views(); } /**