Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
<?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);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment