-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
94 lines (75 loc) · 2.91 KB
/
index.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
92
93
94
<?php
$LICENSE = <<<TAG
This software is licensed under the Apache 2 license, quoted below.
Copyright 2012 Venkatesan Sundramurthy <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
TAG;
echo print_r($_COOKIE);
function getDateString($cid) {
$date = new DateTime();
if (!hasCookieSet($cid)) {
return $date->format('Y-m-d H:i:sP') . ' : ' . RandomString();
} else {
return "";
}
};
function RandomString() {
$characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$randstring = '';
for ($i = 0; $i < 10000; $i++) {
$randstring .= $characters[rand(0, strlen($characters))];
}
return $randstring;
};
function cacheState($cid, $set) { return hasCookieSet($cid) ? "1" : "0"; };
function hasCookieSet($cid) { return !isset($_COOKIE[$cid]) ? false : true; };
echo <<<TAG
<html>
<head>
</head>
<body>
TAG;
echo '<div cid="100" cache="' . cacheState("100") . '" class="header">' . getDateString("100") . '</div>';
for ($i= 0; $i < 2; $i++) {
echo '<div cid="101" cache="' . cacheState("101") . '" class="dynamic">' . getDateString("101") . '</div>';
echo '<div cid="103" cache="' . cacheState("103") . '" class="dynamic">' . getDateString("103") . '</div>';
echo '<div cid="105" cache="' . cacheState("105") . '" class="dynamic">' . getDateString("105") . '</div>';
echo '<div cid="107" cache="' . cacheState("107") . '" class="dynamic">' . getDateString("107") . '</div>';
echo '<div cid="109" cache="' . cacheState("109") . '" class="dynamic">' . getDateString("109") . '</div>';
}
echo '<div cid="110" cache="' . cacheState("110") . '" class="footer">' .getDateString("110") . '</div>';
echo <<<TAG
<script src="http://code.jquery.com/jquery-1.8.3.min.js" type="text/javascript"></script>
<script>
function setCookie(c_name, value, minutes) {
var date = new Date();
date.setTime(date.getTime() + (minutes * 60 * 1000));
var c_value=escape(value) + ((minutes==null) ? "" : "; expires="+date.toUTCString());
document.cookie = c_name + "=" + c_value;
};
$(document).ready(function() {
$('div[cid]').each(function(item) {
key = $(this).attr('cid');
if ($(this).attr('cache') == "0") {
html = $(this).html();
localStorage.setItem(key, html);
setCookie(key, 'true', 1);
} else {
//alert('set from cache');
html = localStorage.getItem(key);
$(this).html(html);
}
});
});
</script>
TAG;
echo '</body></html>';
?>