-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifest.php
91 lines (75 loc) · 2.06 KB
/
manifest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
error_reporting(E_ALL);
$excludeFiles = array(
'./manifest.php',
'./debug.htaccess',
'./.htaccess',
'./ping.js',
);
$excludeDirs = array(
'./.git/',
);
$profile = 'jqtouch';
if (!empty($_GET['jqtouch'])) {
$profile = strval($_GET['jqtouch']);
}
if ($profile == 'jqtouch') {
$excludeDirs[] = './jquery.mobile/';
$excludeFiles[] = './index.jquerymobile.html';
$excludeFiles[] = './application.jquerymobile.js';
$excludeFiles[] = './application.jquerymobile.css';
$excludeFiles[] = './jquery.offline.js';
} else if ($profile == 'jquerymobile') {
$excludeDirs[] = './jqtouch/';
$excludeFiles[] = './jquery.mobevents.js';
}
$network = array(
//'http://et.kvarteret.no/endre/kvarteret_symfony_events/web/api',
'ping.js',
'*',
);
/**
* This simple script will create a manifest file for offline web apps.
* It ensures that whenever a user of this app is online, all files will be
* reloaded if this cache file changes.
* Extend $excludeFiles or $excludeDirs with files you'd not want to be cached.
* I refer to http://ofps.oreilly.com/titles/9780596805784/ch06.html for
* more advanced manifest options.
*/
function strpos_array($haystack, array $needles) {
$pos = null;
foreach ($needles as $needle) {
$pos = strpos($haystack, $needle);
if ($pos !== false) {
return $pos;
}
}
return False;
}
header('Content-Type: text/cache-manifest');
echo "CACHE MANIFEST\n";
$hashes = "";
if (!empty($network)) {
echo "CACHE:\n";
}
$dir = new RecursiveDirectoryIterator(".");
foreach(new RecursiveIteratorIterator($dir) as $file) {
if ($file->IsFile() &&
!in_array($file, $excludeFiles) &&
(strpos_array($file, $excludeDirs) === false) &&
(substr($file->getFilename(), 0, 1) != "."))
{
//echo dirname($_SERVER['PHP_SELF']) . substr($file->__toString(), 1) . "\n";
echo $file . "\n";
$hashes .= md5_file($file);
}
}
if (!empty($network)) {
echo "NETWORK:\n";
foreach ($network as $n) {
$hashes .= md5($n);
echo $n . "\n";
}
}
// print current "version"
echo "# Hash: " . md5($hashes) . "\n";