-
Notifications
You must be signed in to change notification settings - Fork 1
/
getSkinnyTiddlers.php
executable file
·76 lines (44 loc) · 1.03 KB
/
getSkinnyTiddlers.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
<?php
$mrtime = 0;
$output = '[ ' ;
$list = glob("*.tid");
$reqMSince = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
$reqMSince = (isset($reqMSince) ? strtotime($reqMSince) : NULL);
$files = array();
foreach (glob("*.tid") as $filename) {
if (!isset($reqMSince) || ($reqMSince < filemtime($filename)))
{
$files[] = $filename;
}
}
$k = count($files);
foreach ($files as $filename) {
$fsize = filesize($filename);
$contents = '';
if ($fsize > 0) {
$handle = fopen($filename, "r");
$contents = fread($handle, $fsize);
fclose($handle);
}
$time = filemtime($filename);
if ($time > $mrtime) {
$mrtime = $time;
}
$jsonC = json_decode($contents, true);
unset($jsonC['text']);
$output = $output.json_encode($jsonC);
if ($k > 1) {
$output = $output.',
';
$k = $k - 1;
}
}
if (isset($reqMSince) && $reqMSince >= $mrtime)
{
header('HTTP/1.0 304 Not Modified');
exit;
}
header('Cache-Control: no-cache, must-revalidate');
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $mrtime).' GMT');
echo $output.' ]';
?>