diff --git a/includes/cache.inc b/includes/cache.inc index 2323ad4..38d50ad 100644 @@ -60,6 +61,30 @@ function _views_fetch_data($table = NULL) { } /** + * Scan all modules for default views and rebuild the default views cache. + * + * @return + * For PHP > 5.0, returns an ArrayObject. For PHP < 5.0 + * returns an array of all default views. + */ +function _views_discover_default_views($reset = FALSE) { + static $php5; + + // ArrayObject 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/cache.php5'); + } + else { + module_load_include('inc', 'views', 'includes/cache.php4'); + } + return _views_default_views_cache($reset = FALSE); +} + +/** * Fetch the plugin data from cache. */ function _views_fetch_plugin_data($type = NULL, $plugin = NULL) { @@ -90,67 +115,6 @@ function _views_fetch_plugin_data($type = NULL, $plugin = NULL) { return array(); } -/** - * Scan all modules for default views and rebuild the default views cache. - * - * @return An associative array of all known default views. - */ -function _views_discover_default_views() { - static $cache = NULL; - - if (!isset($cache)) { - $index = views_cache_get('views_default_views_index', TRUE); - - // Retrieve each cached default view - if (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); - - // 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); - } - } - } - - return $cache; -} /** * Set a cached item in the views cache.