tony-landis (owner)

Revisions

gist: 33019 Download_button fork
public
Public Clone URL: git://gist.github.com/33019.git
Embed All Files: show embed
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
<?php
 
require "../includes/smarty/Smarty.class.php";
$smarty = new Smarty;
$smarty->template_dir = 'templates';
$smarty->compile_dir = 'compile';
 
$smarty->cache_dir = '/var/www/site/tmp';
$smarty->caching = true;
$smarty->force_compile = true;
$smarty->compile_id = '';
 
$smarty->cache_handler_func = 'server_rewrite_cache_handler';
function server_rewrite_cache_handler($action, &$smarty_obj, &$cache_content, $tpl_file=null, $cache_id=null, $compile_id=null, $exp_time=null)
{
$cache_file = $smarty_obj->cache_dir . '/' . $compile_id . $cache_id;
if(!is_file($cache_file)) {
$base_file = basename($cache_file);
$base_dir = dirname($cache_file);
if(!is_dir($base_dir)) mkdir($base_dir, 0777, true);
}
    switch ($action) {
        case 'read':
         if(!is_file($cache_file)) return false; else return true;
            break;
        case 'write':
         return file_put_contents($cache_file, $cache_content);
            break;
        case 'clear':
         return @unlink($cache_file);
            break;
        default:
            return false;
            break;
    }
}
 
$_p = $_REQUEST['p']; // detect the actual file path requested so I can save the cached copy with the correct path and filename
$page = ''; // my logic here to determine the correct smarty template to display
$smarty->display($page, $_p);
 
?>