-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.php
More file actions
executable file
·63 lines (50 loc) · 1.49 KB
/
cache.php
File metadata and controls
executable file
·63 lines (50 loc) · 1.49 KB
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
<?php
//cache features are under construction
//code needs review
error_debug('including cache.php', __file__, __line__);
function cache_clear($match=false) {
global $_josh;
if ($files = file_folder(DIRECTORY_WRITE . '/caches/')) {
foreach ($files as $f) {
if ($match) {
//delete only certain files
} else {
//delete everything
file_delete($f['path_name']);
}
}
}
}
function cache_end() {
global $_josh;
//stop buffering
$contents = ob_get_contents();
ob_end_clean();
//echo contents
echo $contents;
//write the cache file
file_put($_josh['cache'], $contents);
//unset the filename variable because we don't need it anymore
unset($_josh['cache']);
}
function cache_start($filename=false) {
global $_josh;
//determine what filename we should use--defaults to path_query
if (!$filename) $filename = $_josh['request']['path_query'];
//strip front slash for easier matching later
$filename = format_text_starts('/', $filename);
//append user id (if set) as query argument
if ($userID = user()) $filename .= ((stristr('?', $filename)) ? '?' : '&') . 'user_id=' . $userID;
//finalize
$filename = DIRECTORY_WRITE . '/caches/' . urlencode($filename) . '.html';
if (file_check($filename)) {
//get cache file
echo file_get($filename);
return false; //meaning you don't need to continue processing, because i've got a cache here
} else {
//or create cache file
$_josh['cache'] = $filename;
ob_start();
return true; //meaning you do need to process
}
}