]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/Smarty/internals/core.read_cache_file.php
Release 6.5.0
[Github/sugarcrm.git] / include / Smarty / internals / core.read_cache_file.php
1 <?php
2
3 /*
4
5 Modification information for LGPL compliance
6
7 r56990 - 2010-06-16 13:05:36 -0700 (Wed, 16 Jun 2010) - kjing - snapshot "Mango" svn branch to a new one for GitHub sync
8
9 r56989 - 2010-06-16 13:01:33 -0700 (Wed, 16 Jun 2010) - kjing - defunt "Mango" svn dev branch before github cutover
10
11 r55980 - 2010-04-19 13:31:28 -0700 (Mon, 19 Apr 2010) - kjing - create Mango (6.1) based on windex
12
13 r51719 - 2009-10-22 10:18:00 -0700 (Thu, 22 Oct 2009) - mitani - Converted to Build 3  tags and updated the build system 
14
15 r51634 - 2009-10-19 13:32:22 -0700 (Mon, 19 Oct 2009) - mitani - Windex is the branch for Sugar Sales 1.0 development
16
17 r50375 - 2009-08-24 18:07:43 -0700 (Mon, 24 Aug 2009) - dwong - branch kobe2 from tokyo r50372
18
19 r42807 - 2008-12-29 11:16:59 -0800 (Mon, 29 Dec 2008) - dwong - Branch from trunk/sugarcrm r42806 to branches/tokyo/sugarcrm
20
21 r8230 - 2005-10-03 17:47:19 -0700 (Mon, 03 Oct 2005) - majed - Added Sugar_Smarty to the code tree.
22
23
24 */
25
26
27 /**
28  * Smarty plugin
29  * @package Smarty
30  * @subpackage plugins
31  */
32
33 /**
34  * read a cache file, determine if it needs to be
35  * regenerated or not
36  *
37  * @param string $tpl_file
38  * @param string $cache_id
39  * @param string $compile_id
40  * @param string $results
41  * @return boolean
42  */
43
44 //  $tpl_file, $cache_id, $compile_id, &$results
45
46 function smarty_core_read_cache_file(&$params, &$smarty)
47 {
48     static  $content_cache = array();
49
50     if ($smarty->force_compile) {
51         // force compile enabled, always regenerate
52         return false;
53     }
54
55     if (isset($content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']])) {
56         list($params['results'], $smarty->_cache_info) = $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']];
57         return true;
58     }
59
60     if (!empty($smarty->cache_handler_func)) {
61         // use cache_handler function
62         call_user_func_array($smarty->cache_handler_func,
63                              array('read', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], null));
64     } else {
65         // use local cache file
66         $_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']);
67         $_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id);
68         $params['results'] = $smarty->_read_file($_cache_file);
69     }
70
71     if (empty($params['results'])) {
72         // nothing to parse (error?), regenerate cache
73         return false;
74     }
75
76     $_contents = $params['results'];
77     $_info_start = strpos($_contents, "\n") + 1;
78     $_info_len = (int)substr($_contents, 0, $_info_start - 1);
79     $_cache_info = unserialize(substr($_contents, $_info_start, $_info_len));
80     $params['results'] = substr($_contents, $_info_start + $_info_len);
81
82     if ($smarty->caching == 2 && isset ($_cache_info['expires'])){
83         // caching by expiration time
84         if ($_cache_info['expires'] > -1 && (time() > $_cache_info['expires'])) {
85             // cache expired, regenerate
86             return false;
87         }
88     } else {
89         // caching by lifetime
90         if ($smarty->cache_lifetime > -1 && (time() - $_cache_info['timestamp'] > $smarty->cache_lifetime)) {
91             // cache expired, regenerate
92             return false;
93         }
94     }
95
96     if ($smarty->compile_check) {
97         $_params = array('get_source' => false, 'quiet'=>true);
98         foreach (array_keys($_cache_info['template']) as $_template_dep) {
99             $_params['resource_name'] = $_template_dep;
100             if (!$smarty->_fetch_resource_info($_params) || $_cache_info['timestamp'] < $_params['resource_timestamp']) {
101                 // template file has changed, regenerate cache
102                 return false;
103             }
104         }
105
106         if (isset($_cache_info['config'])) {
107             $_params = array('resource_base_path' => $smarty->config_dir, 'get_source' => false, 'quiet'=>true);
108             foreach (array_keys($_cache_info['config']) as $_config_dep) {
109                 $_params['resource_name'] = $_config_dep;
110                 if (!$smarty->_fetch_resource_info($_params) || $_cache_info['timestamp'] < $_params['resource_timestamp']) {
111                     // config file has changed, regenerate cache
112                     return false;
113                 }
114             }
115         }
116     }
117
118     $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']] = array($params['results'], $_cache_info);
119
120     $smarty->_cache_info = $_cache_info;
121     return true;
122 }
123
124 /* vim: set expandtab: */
125
126 ?>