Kyberia v2.0
[mirrors/Kyberia-bloodline.git] / inc / smarty / core / core.write_cache_file.php
1 <?php
2 /**
3 * Smarty plugin
4 * @package Smarty
5 * @subpackage plugins
6 */
7
8 /**
9 * Prepend the cache information to the cache file
10 * and write it
11 *
12 * @param string $tpl_file
13 * @param string $cache_id
14 * @param string $compile_id
15 * @param string $results
16 * @return true|null
17 */
18
19 // $tpl_file, $cache_id, $compile_id, $results
20
21 function smarty_core_write_cache_file($params, &$smarty)
22 {
23
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;
32 }
33
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;
41
42 // prepend the cache header info into cache file
43 $params['results'] = serialize($smarty->_cache_info)."\n".$params['results'];
44
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']));
49 } else {
50 // use local cache file
51
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;
57 }
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;
60 }
61
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;
68 }
69 }
70
71 /* vim: set expandtab: */
72
73 ?>
This page took 0.316649 seconds and 4 git commands to generate.