1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| $aSmartyCacheLifetime = array('home' => 0,
'checkout' => 0,
'details' => -1,
'index' => -1,
'recover_password' => -1,
'results' => 3600,
'search_form' => -1,
'search' => 0,
'shopping_cart' => 0,
'standalone_results' => 0,
'thumbnails' => -1,
'thumbnail' => -1,
'user_controls' => -1,
'wishlist_email' => -1,
'wishlists' => 600,
'wishlist' => 600,);
$aSmartyCacheIdCallback = array('details' => 'cacheid_template',
'results' => '/[0-9]{1,9}/',
'thumbnail' => 0,
'wishlist' => '/[0-9]{1,12}/',);
$aSmartyCacheIdCallback['thumbnail'] = $aSmartyCacheIdCallback['details'];
require_once 'smarty/Smarty.class.php';
class Smarty_Site extends Smarty {
function Smarty_Site()
{
/* [...] */
}
public function smartInclude($params, &$smarty) {
global $aSmartyCacheLifetime, $aSmartyCacheIdCallback;
if(empty($params['file'])) {
return '';
}
$file = str_replace('.tpl', '', $params['file']);
if (isset($aSmartyCacheLifetime[$file])&&empty($params['lifetime'])) {
$params['lifetime'] = $aSmartyCacheLifetime[$file];
}
$smarty->caching = 2;
$smarty->cache_lifetime = $params['lifetime'];
$action = (isset($aSmartyCacheIdCallback[$file]))
? $aSmartyCacheIdCallback[$file] : false;
if(empty($params['id'])||!$action) {
return $smarty->fetch($file.'.tpl');
} elseif (@preg_match($action, $params['id'])) {
return $smarty->fetch($file.'.tpl', $params['id']);
} elseif (function_exists($action)) {
return $smarty->fetch($file.'.tpl',
$action($params['id']));
} else {
return 'Invalid : $aSmartyCacheIdCallback['.$file.']';
}
}
}
function cacheid_template($id_tm) {
global $TM_Cart, $TM_Wishlist;
$id_cache = (isset($TM_Wishlist->aWishlist[$id_tm])) ? 'y' : 'n';
$id_cache .= (isset($TM_Cart->aCart[$id_tm])) ? 'y' : 'n';
$id_cache .= $id_tm;
return $id_cache;
}
/* [...] */
$oSmarty->register_function('smart_include', array(&$oSmarty, 'smartInclude')); |
Partager