wpsc_dirsize()WPSCache 1.0

No Hooks.

Return

null. Nothing (null).

Usage

wpsc_dirsize( $directory, $sizes );
$directory (required)
-
$sizes (required)
-

wpsc_dirsize() code WPSCache 1.12.1

function wpsc_dirsize($directory, $sizes) {
	global $cache_max_time, $cache_path, $valid_nonce, $wp_cache_preload_on, $file_prefix;
	$now = time();

	if (is_dir($directory)) {
		if( $dh = opendir( $directory ) ) {
			while( ( $entry = readdir( $dh ) ) !== false ) {
				if ($entry != '.' && $entry != '..') {
					$sizes = wpsc_dirsize( trailingslashit( $directory ) . $entry, $sizes );
				}
			}
			closedir($dh);
		}
	} elseif ( is_file( $directory ) && strpos( $directory, 'meta-' . $file_prefix ) === false ) {
		if ( strpos( $directory, '/' . $file_prefix ) !== false ) {
			$cache_type = 'wpcache';
		} else {
			$cache_type = 'supercache';
		}
		$keep_fresh = false;
		if ( $cache_type === 'supercache' && $wp_cache_preload_on ) {
			$keep_fresh = true;
		}
		$filem = filemtime( $directory );
		if ( ! $keep_fresh && $cache_max_time > 0 && $filem + $cache_max_time <= $now ) {
			$cache_status = 'expired';
		} else {
			$cache_status = 'cached';
		}
		$sizes[ $cache_type ][ $cache_status ] += 1;
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Presumably the caller should handle it if necessary.
		if ( $valid_nonce && isset( $_GET['listfiles'] ) ) {
			$dir = str_replace( $cache_path . 'supercache/', '', dirname( $directory ) );
			$age = $now - $filem;
			if ( ! isset( $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ] ) ) {
				$sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['lower_age'] = $age;
				$sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['files']     = 1;
			} else {
				$sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['files'] += 1;
				if ( $age <= $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['lower_age'] ) {

					if ( $age < $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['lower_age'] && ! isset( $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['upper_age'] ) ) {
						$sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['upper_age'] = $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['lower_age'];
					}

					$sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['lower_age'] = $age;

				} elseif ( ! isset( $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['upper_age'] ) || $age > $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['upper_age'] ) {

					$sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['upper_age'] = $age;

				}
			}
		}
		if ( ! isset( $sizes['fsize'] ) ) {
			// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
			$sizes[ $cache_type ]['fsize'] = @filesize( $directory );
		} else {
			// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
			$sizes[ $cache_type ]['fsize'] += @filesize( $directory );
		}
	}
	return $sizes;
}