private static function removeStaleDiskCacheItems() { if (__CA_CACHE_BACKEND__ != 'file') { return false; } // the other backends *should* honor the TTL we pass $vs_cache_base_dir = defined('__CA_CACHE_FILEPATH__') ? __CA_CACHE_FILEPATH__ : __CA_APP_DIR__ . DIRECTORY_SEPARATOR . 'tmp'; $vs_cache_dir = $vs_cache_base_dir . DIRECTORY_SEPARATOR . __CA_APP_NAME__ . 'Cache'; $va_list = caGetDirectoryContentsAsList($vs_cache_dir); foreach ($va_list as $vs_file) { $r = @fopen($vs_file, "r"); if (!is_resource($r)) { continue; } // skip if for some reason the file couldn't be opened if (false !== ($vs_line = fgets($r))) { $vn_lifetime = (int) $vs_line; if ($vn_lifetime !== 0 && $vn_lifetime < time()) { fclose($r); @unlink($vs_file); } } } $va_dir_list = caGetSubDirectoryList($vs_cache_dir); // note we're explicitly reversing the array here so that // the order is /foo/bar/foobar, then /foo/bar and then /foo // that way we don't need recursion because we just work our way up the directory tree foreach (array_reverse($va_dir_list) as $vs_dir => $vn_c) { if (caDirectoryIsEmpty($vs_dir)) { @rmdir($vs_dir); } } return true; }
public function __construct(&$po_request, &$po_response, $pa_view_paths = null) { global $allowed_universes; parent::__construct($po_request, $po_response, $pa_view_paths); if (!$this->request->user->canDoAction('can_use_statistics_viewer_plugin')) { $this->response->setRedirect($this->request->config->get('error_display_url') . '/n/3000?r=' . urlencode($this->request->getFullUrlPath())); return; } $this->opo_config = Configuration::load(__CA_APP_DIR__ . '/plugins/statisticsViewer/conf/statisticsViewer.conf'); // Get directory list $va_file_list = caGetDirectoryContentsAsList(__CA_APP_DIR__ . "/plugins/statisticsViewer/" . $this->opo_config->get('XmlStatisticsRootDirectory'), false, false); $va_dir_list_with_file_counts = caGetSubDirectoryList($this->opo_config->get('importRootDirectory'), true, false); $this->opa_statistics_xml_files = array(); $this->opa_statistics = array(); if (is_array($allowed_universes = $this->opo_config->getAssoc('AvailableUniversesForStats'))) { // if the conf variable AvailableUniversesFor stats is defined //echo "here."; } $this->get_statistics_listing($va_file_list, $allowed_universes); }
/** * Returns a list of directories from all directories under $dir as an array of directory paths with associated file counts. * * @param string $dir The path to the directory you wish to get the contents list for * @param bool $pb_include_root Optional. By default caGetSubDirectoryList() omits the root directory ($dir) and any files in it. Set this to true to include the root directory if it contains files. * @param bool $pb_include_hidden_files Optional. By default caGetSubDirectoryList() does not consider hidden files (files starting with a '.') when calculating file counts. Set this to true to include hidden files in counts. Note that the special UNIX '.' and '..' directory entries are *never* counted as files. * @return array An array with directory paths as keys and file counts as values. The array is sorted alphabetically. */ function &caGetSubDirectoryList($dir, $pb_include_root = false, $pb_include_hidden_files = false) { $va_dir_list = array(); if (substr($dir, -1, 1) == "/") { $dir = substr($dir, 0, strlen($dir) - 1); } if ($pb_include_root) { $va_dir_list[$dir] = 0; } $vn_file_count = 0; if ($handle = @opendir($dir)) { while (false !== ($item = readdir($handle))) { if ($item != "." && $item != ".." && ($pb_include_hidden_files || !$pb_include_hidden_files && $item[0] !== '.')) { if (is_dir("{$dir}/{$item}")) { $va_dir_list = array_merge($va_dir_list, caGetSubDirectoryList("{$dir}/{$item}", true, $pb_include_hidden_files)); } else { $vn_file_count++; } } } closedir($handle); } if ($pb_include_root) { $va_dir_list[$dir] = $vn_file_count; } ksort($va_dir_list); return $va_dir_list; }