changed git call from https to git readonly
[atutor.git] / mods / phpdoc2 / PhpDocumentor / phpDocumentor / Smarty-2.6.0 / libs / core / core.write_cache_file.php
1 <?php\r
2 /**\r
3  * Smarty plugin\r
4  * @package Smarty\r
5  * @subpackage plugins\r
6  */\r
7 \r
8 /**\r
9  * Prepend the cache information to the cache file\r
10  * and write it\r
11  *\r
12  * @param string $tpl_file\r
13  * @param string $cache_id\r
14  * @param string $compile_id\r
15  * @param string $results\r
16  * @return true|null\r
17  */\r
18 \r
19  // $tpl_file, $cache_id, $compile_id, $results\r
20 \r
21 function smarty_core_write_cache_file($params, &$smarty)\r
22 {\r
23 \r
24     // put timestamp in cache header\r
25     $smarty->_cache_info['timestamp'] = time();\r
26     if ($smarty->cache_lifetime > -1){\r
27         // expiration set\r
28         $smarty->_cache_info['expires'] = $smarty->_cache_info['timestamp'] + $smarty->cache_lifetime;\r
29     } else {\r
30         // cache will never expire\r
31         $smarty->_cache_info['expires'] = -1;\r
32     }\r
33 \r
34     // collapse {nocache...}-tags\r
35     $params['results'] = preg_replace('!((\{nocache\:([0-9a-f]{32})#(\d+)\})'\r
36                                       .'.*'\r
37                                       .'{/nocache\:\\3#\\4\})!Us'\r
38                                       ,'\\2'\r
39                                       ,$params['results']);\r
40     $smarty->_cache_info['cache_serials'] = $smarty->_cache_serials;\r
41 \r
42     // prepend the cache header info into cache file\r
43     $params['results'] = serialize($smarty->_cache_info)."\n".$params['results'];\r
44 \r
45     if (!empty($smarty->cache_handler_func)) {\r
46         // use cache_handler function\r
47         call_user_func_array($smarty->cache_handler_func,\r
48                              array('write', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], null));\r
49     } else {\r
50         // use local cache file\r
51 \r
52         if(!@is_writable($smarty->cache_dir)) {\r
53             // cache_dir not writable, see if it exists\r
54             if(!@is_dir($smarty->cache_dir)) {\r
55                 $smarty->trigger_error('the $cache_dir \'' . $smarty->cache_dir . '\' does not exist, or is not a directory.', E_USER_ERROR);\r
56                 return false;\r
57             }\r
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);\r
59             return false;\r
60         }\r
61 \r
62         $_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']);\r
63         $_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id);\r
64         $_params = array('filename' => $_cache_file, 'contents' => $params['results'], 'create_dirs' => true);\r
65         require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php');\r
66         smarty_core_write_file($_params, $smarty);\r
67         return true;\r
68     }\r
69 }\r
70 \r
71 /* vim: set expandtab: */\r
72 \r
73 ?>\r