function test_Minify_Cache_File() { $data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8 $id = 'Minify_test_cache_noLock'; $prefix = 'Minify_Cache_File : '; $cache = new Minify_Cache_File(); echo "NOTE: Minify_Cache_File : path is set to: '" . $cache->getPath() . "'.\n"; assertTrue(true === $cache->store($id, $data), $prefix . 'store'); assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize'); assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid'); ob_start(); $cache->display($id); $displayed = ob_get_contents(); ob_end_clean(); assertTrue($data === $displayed, $prefix . 'display'); assertTrue($data === $cache->fetch($id), $prefix . 'fetch'); // test with locks $id = 'Minify_test_cache_withLock'; $cache = new Minify_Cache_File('', true); assertTrue(true === $cache->store($id, $data), $prefix . 'store w/ lock'); assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize'); assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid'); ob_start(); $cache->display($id); $displayed = ob_get_contents(); ob_end_clean(); assertTrue($data === $displayed, $prefix . 'display w/ lock'); assertTrue($data === $cache->fetch($id), $prefix . 'fetch w/ lock'); }
function test_Minify_Cache_File() { global $minifyCachePath; $data = str_repeat(md5(time()), 160); $id = 'Minify_test_cache_noLock'; $prefix = 'Minify_Cache_File : '; $cache = new Minify_Cache_File($minifyCachePath); assertTrue(true === $cache->store($id, $data), $prefix . 'store'); assertTrue(strlen($data) === $cache->getSize($id), $prefix . 'getSize'); assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid'); ob_start(); $cache->display($id); $displayed = ob_get_contents(); ob_end_clean(); assertTrue($data === $displayed, $prefix . 'display'); assertTrue($data === $cache->fetch($id), $prefix . 'fetch'); // test with locks $id = 'Minify_test_cache_withLock'; $cache = new Minify_Cache_File($minifyCachePath, true); assertTrue(true === $cache->store($id, $data), $prefix . 'store w/ lock'); assertTrue(strlen($data) === $cache->getSize($id), $prefix . 'getSize'); assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid'); ob_start(); $cache->display($id); $displayed = ob_get_contents(); ob_end_clean(); assertTrue($data === $displayed, $prefix . 'display w/ lock'); assertTrue($data === $cache->fetch($id), $prefix . 'fetch w/ lock'); }
static function getCache($file) { $cache = new Minify_Cache_File(); $dir = dirname($file); $cache_path = $cache->getPath() . "/{$dir}"; // FIX: create the dir if not available if (!is_dir($cache_path)) { mkdir($cache_path, 0775, true); } // check if the file is less than an hour old return $cache->isValid($file, time("now") - 3600) ? $cache->fetch($file) : false; }
function isStatic($file) { // FIX: Bail out if this is the root if ($file == WEB_FOLDER) { return false; } // FIX: clean webfolder from path before comparing $file = preg_replace('#^' . addslashes(WEB_FOLDER) . '#', '', $file); $root = rtrim($_SERVER['DOCUMENT_ROOT'], "/") . "/"; // check in the document root if (file_exists($root . $file)) { $target = $root . $file; return $target; } // check in the app public folders if (defined("APP")) { if (file_exists(APP . "public/" . $file)) { $target = APP . "public/" . $file; return $target; } if (is_dir(APP . "plugins/") && ($handle = opendir(APP . "plugins/"))) { while (false !== ($plugin = readdir($handle))) { if ($plugin == '.' || $plugin == '..') { continue; } if (is_dir(APP . "plugins/" . $plugin) && file_exists(APP . "plugins/" . $plugin . "/public/" . $file)) { $target = APP . "plugins/" . $plugin . "/public/" . $file; return $target; } } } } //check the cache (less than an hour old) $cache = new Minify_Cache_File(); //if( $cache->isValid($file, time("now")-3600) ) return $cache->tmp() ."/". $file; if ($cache->isValid("/{$_SERVER['HTTP_HOST']}/{$file}", 0)) { return $cache->tmp() . "/{$_SERVER['HTTP_HOST']}/" . $file; } // check in the base public folders if (defined("BASE")) { if (file_exists(BASE . "public/" . $file)) { $target = BASE . "public/" . $file; return $target; } $target = realpath(BASE . "../public/" . $file); if (file_exists($target)) { return $target; } if (is_dir(BASE . "plugins/") && ($handle = opendir(BASE . "plugins/"))) { while (false !== ($plugin = readdir($handle))) { if ($plugin == '.' || $plugin == '..') { continue; } if (is_dir(BASE . "plugins/" . $plugin) && file_exists(BASE . "plugins/" . $plugin . "/public/" . $file)) { $target = BASE . "plugins/" . $plugin . "/public/" . $file; return $target; } } } } // check in the plugins directory if (defined("PLUGINS")) { $files = glob(PLUGINS . "*/public/{$file}"); if ($files && count($files) > 0) { // arbitrary pick the first file - should have a comparison mechanism in place $target = $files[0]; return $target; } } # 110 looking into web root for plugins if (is_dir(SITE_ROOT . "/plugins")) { $files = glob(SITE_ROOT . "/plugins/*/public/{$file}"); if ($files && count($files) > 0) { // arbitrary pick the first file - should have a comparison mechanism in place $target = $files[0]; return $target; } } // return false if there are no results return false; }