Created
September 17, 2010 17:24
-
-
Save typeoneerror/584586 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//exit(); | |
// path to web assets | |
define('PATH', realpath(dirname(__FILE__))); | |
// file to output manifest to | |
define('FILE_TO_WRITE', PATH . "/cache.manifest"); | |
// directories to list | |
// the key will be used as a comment in the generated manifest | |
$dirs = array( | |
"CSS" => "/css", | |
"Javascript" => "/js", | |
"Images" => "/img", | |
); | |
// do not cache, relative to PATH | |
$ignores = array( | |
"/.htaccess", | |
"/robots.txt", | |
"/cache.manifest", // for Firefox, I think | |
"/manifest.php", // ignore the generator | |
); | |
// fallback for offline mode | |
$fallback = "/offline"; | |
ob_start(); | |
function listDirectory($dir, $relativeTo = "") | |
{ | |
$array = array(); | |
if ($handle = @opendir($dir)) | |
{ | |
while (false !== ($file = readdir($handle))) | |
{ | |
if ($file != "." && $file != ".." && $file[0] != ".") | |
{ | |
$path = "$dir/$file"; | |
if (!is_dir($path)) | |
{ | |
array_push($array, $relativeTo . $file); | |
} | |
else | |
{ | |
$ls = listDirectory($path, $relativeTo . $file . "/"); | |
$array = array_merge($array, $ls); | |
} | |
} | |
} | |
closedir($handle); | |
} | |
return $array; | |
} | |
// start output | |
echo "CACHE MANIFEST\n\n"; | |
if (!empty($fallback)) | |
{ | |
echo "FALLBACK:\n\n"; | |
echo "/ {$fallback}\n\n"; | |
} | |
if (!empty($ignores)) | |
{ | |
echo "NETWORK:\n\n"; | |
foreach ($ignores as $ignored) | |
{ | |
echo "$ignored\n"; | |
} | |
echo "\n"; | |
} | |
if (!empty($dirs)) echo "CACHE:\n\n"; | |
foreach ($dirs as $name => $dir) | |
{ | |
$ls = listDirectory(PATH . $dir); | |
echo "# {$name}\n"; | |
foreach ($ls as $cache) | |
{ | |
echo "$dir/$cache\n"; | |
} | |
echo "\n"; | |
} | |
echo "# Generated: " . date ("F d Y H:i:s.", time()) . "\n"; | |
$contents = ob_get_clean(); | |
$fp = fopen(FILE_TO_WRITE, 'w'); | |
fwrite($fp, $contents); | |
fclose($fp); | |
echo $contents; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment