jrobinsonc
5/5/2013 - 3:52 PM

AppCache generator #php #appcache

AppCache generator #php #appcache

<?php

function get_dir($dir)
{
    $files = array();
    $exclude = array('.', '..', 'appcache.php', '.git', '.gitignore', 'nbproject', 'TODO', 'README.md', 'cache.manifest');
    
    foreach (scandir($dir) as $item)
    {
        if (in_array($item, $exclude)) continue;
        
        //---------------------------------------------------
        $item_full = realpath("{$dir}/{$item}");

        if (is_file($item_full))
        {
            $files[] = $item_full;
        }
        elseif (is_dir($item_full))
        {
            $files = array_merge($files, get_dir($item_full));
        }
    }
    
    return $files;
}


$dir = __DIR__;

$h = fopen("{$dir}/cache.manifest", 'w');

fwrite($h, 'CACHE MANIFEST' . "\n\n");
fwrite($h, '# Time: '. date('r') . "\n\n");
fwrite($h, 'CACHE:' . "\n");

foreach(get_dir($dir) as $item)
{
    $item = ltrim(str_replace('\\', '/', str_replace($dir, '', $item)), '/');

    fwrite($h, $item . "\n");
}

fwrite($h, "\n" . 'NETWORK:' . "\n");
fwrite($h, '*');

fclose($h);