fixed firefox width problem in listing of issues
[openemr.git] / library / core / core.write_cache_file.php
blob7429ad98a8d38f417cb9d6182ee1472e867acee7
1 <?php
2 /**
3 * Smarty plugin
4 * @package Smarty
5 * @subpackage plugins
6 */
8 /**
9 * Prepend the cache information to the cache file
10 * and write it
12 * @param string $tpl_file
13 * @param string $cache_id
14 * @param string $compile_id
15 * @param string $results
16 * @return true|null
19 // $tpl_file, $cache_id, $compile_id, $results
21 function smarty_core_write_cache_file($params, &$smarty)
24 // put timestamp in cache header
25 $smarty->_cache_info['timestamp'] = time();
26 if ($smarty->cache_lifetime > -1){
27 // expiration set
28 $smarty->_cache_info['expires'] = $smarty->_cache_info['timestamp'] + $smarty->cache_lifetime;
29 } else {
30 // cache will never expire
31 $smarty->_cache_info['expires'] = -1;
34 // collapse {nocache...}-tags
35 $params['results'] = preg_replace('!((\{nocache\:([0-9a-f]{32})#(\d+)\})'
36 .'.*'
37 .'{/nocache\:\\3#\\4\})!Us'
38 ,'\\2'
39 ,$params['results']);
40 $smarty->_cache_info['cache_serials'] = $smarty->_cache_serials;
42 // prepend the cache header info into cache file
43 $params['results'] = serialize($smarty->_cache_info)."\n".$params['results'];
45 if (!empty($smarty->cache_handler_func)) {
46 // use cache_handler function
47 call_user_func_array($smarty->cache_handler_func,
48 array('write', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], null));
49 } else {
50 // use local cache file
52 if(!@is_writable($smarty->cache_dir)) {
53 // cache_dir not writable, see if it exists
54 if(!@is_dir($smarty->cache_dir)) {
55 $smarty->trigger_error('the $cache_dir \'' . $smarty->cache_dir . '\' does not exist, or is not a directory.', E_USER_ERROR);
56 return false;
58 $smarty->trigger_error('unable to write to $cache_dir \'' . realpath($smarty->cache_dir) . '\'. Be sure $cache_dir is writable by the web server user.', E_USER_ERROR);
59 return false;
62 $_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']);
63 $_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id);
64 $_params = array('filename' => $_cache_file, 'contents' => $params['results'], 'create_dirs' => true);
65 require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php');
66 smarty_core_write_file($_params, $smarty);
67 return true;
71 /* vim: set expandtab: */