Source of “manifest-php.txt”.
48 lines, 1.8 KBytes.   Last modified 8:15 pm, 23rd April 2014 PDT.
1 <?php // Emacs settings: -*- mode: Fundamental; tab-width: 4; -*- 2 3 //////////////////////////////////////////////////////////////////////////// 4 // // 5 // Support for HTML5 manifest creation // 6 // // 7 // Copyright (c) 2005-2014, Andrew Birrell // 8 // // 9 //////////////////////////////////////////////////////////////////////////// 10 11 $manifest_urls = array(); 12 $manifest_namesAndTimes = array(); 13 14 function manifest_add($url, $file = false) { 15 // Add an entry to the manifest. If "url" is not false, it is included 16 // in the to-be-cached section of the manifest. If "file" is false, 17 // the URL is used as the file name instead. If the resulting file name 18 // exists, its name and mtime are accumulated into "namesAndTimes". A 19 // hash of "namesAndTimes" is included in the output, so that the 20 // manifest changes whenever the files change. 21 // 22 global $manifest_urls, $manifest_namesAndTimes; 23 if ($url) $manifest_urls[] = $url; 24 if (!$file) $file = $url; 25 if (file_exists($file)) { 26 $manifest_namesAndTimes[] = $file; 27 $manifest_namesAndTimes[] = filemtime($file); 28 } 29 } 30 31 function manifest_finish() { 32 // Write the manifest to stdout. 33 // 34 // Leaves stdout at the "NETWORK" section of the manifest, letting 35 // the caller add URL's that will be accessed over the network. 36 // 37 global $manifest_urls, $manifest_namesAndTimes; 38 header("Content-type: text/cache-manifest"); 39 echo "CACHE MANIFEST\n"; 40 echo "# Version " . 41 hash("sha256", implode("\n", $manifest_namesAndTimes)) . "\n"; 42 foreach ($manifest_urls as $value) { 43 echo $value . "\n"; 44 } 45 echo "\nNETWORK:\n"; 46 } 47 48 ?>
End of listing