Last active
December 17, 2015 04:18
-
-
Save rictorres/5549091 to your computer and use it in GitHub Desktop.
Function to generate appcache manifest file and to automatically update itself (using md5 hashes).
This file contains 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 | |
header('Content-Type: text/cache-manifest'); | |
header('Cache-Control: no-cache'); | |
echo "CACHE MANIFEST\n\n"; | |
$hashes = ""; | |
$blacklist = array( | |
'./appcache.php', | |
'./robots.txt', | |
'./fonts/dosis-light.eot', | |
'./404.html', | |
'./css/ie.css', | |
'./img/header-bg.png', | |
'./img/logo-fb.png', | |
'./config.php', | |
'./less/' | |
); | |
function get_parent_dir($pathname) { | |
$dir = explode('/', ltrim($pathname, "./")); | |
return "./" . $dir[0] . "/"; | |
} | |
$dir_local = new RecursiveDirectoryIterator("."); | |
foreach(new RecursiveIteratorIterator($dir_local) as $file) { | |
if ($file->IsFile() && | |
(!in_array($file, $blacklist)) && | |
(substr($file->getFilename(), 0, 1) != ".") && | |
(!in_array(get_parent_dir($file->getPathname()), $blacklist))) { | |
if ( (strpos($file, './img/app/') === FALSE) && (strpos($file, './js/files/') === FALSE) && (strpos($file, './img/gals/') === FALSE) && (strpos($file, './img/base64/') === FALSE) ) { | |
echo $file . "\n"; | |
$hashes .= md5_file($file); | |
} | |
} | |
} | |
echo "\nNETWORK:\n"; | |
echo '*' . "\n"; | |
echo "\n# ver: " . md5($hashes) . "\n"; | |
?> |
This file contains 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
CACHE MANIFEST | |
./aquarelle.php | |
./artiste.php | |
./catalogo-de-cores.php | |
./css/style.css | |
./filet.php | |
./fonts/dosis-light.svg | |
./fonts/dosis-light.ttf | |
./fonts/dosis-light.woff | |
./image.php | |
./img/bg.png | |
./img/catalogo-de-cores.jpg | |
./img/container-bg-land.jpg | |
./img/container-bg-port.jpg | |
./img/furniture.png | |
./img/home-intro-ios.png | |
./img/home-intro-showcase.png | |
./img/logo.png | |
./index.php | |
./js/app.js | |
./js/modernizr.js | |
./melange.php | |
./mosaique.php | |
./naturel.php | |
./patchwork.php | |
./porcelaine.php | |
./retro.php | |
./special.php | |
NETWORK: | |
* | |
# ver: c30cfc6602b6446c6b19e436041255e2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It needs a few improvements. For instance, ignore subdirs like ./img/app/
That's why it needs that if statement on line 34