mirror of
https://github.com/smarty-php/smarty.git
synced 2026-04-29 18:23:24 +02:00
- bugfix Smarty version was not filled in header comment of compiled and cached files
- optimization replace internal Smarty::$ds property by DIRECTORY_SEPARATOR (reverted from commit 1e787d08f1)
This commit is contained in:
@@ -35,12 +35,13 @@ class Smarty_Internal_Method_ClearCompiledTemplate
|
||||
{
|
||||
// clear template objects cache
|
||||
$smarty->_clearTemplateCache();
|
||||
|
||||
$_compile_dir = $smarty->getCompileDir();
|
||||
if ($_compile_dir === '/') { //We should never want to delete this!
|
||||
if ($_compile_dir == '/') { //We should never want to delete this!
|
||||
return 0;
|
||||
}
|
||||
$_compile_id = isset($compile_id) ? preg_replace('![^\w]+!', '_', $compile_id) : null;
|
||||
$_dir_sep = $smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^';
|
||||
$_dir_sep = $smarty->use_sub_dirs ? $smarty->ds : '^';
|
||||
if (isset($resource_name)) {
|
||||
$_save_stat = $smarty->caching;
|
||||
$smarty->caching = false;
|
||||
@@ -48,7 +49,7 @@ class Smarty_Internal_Method_ClearCompiledTemplate
|
||||
$tpl = $smarty->createTemplate($resource_name);
|
||||
$smarty->caching = $_save_stat;
|
||||
if (!$tpl->source->handler->uncompiled && !$tpl->source->handler->recompiled && $tpl->source->exists) {
|
||||
$_resource_part_1 = basename(str_replace('^', DIRECTORY_SEPARATOR, $tpl->compiled->filepath));
|
||||
$_resource_part_1 = basename(str_replace('^', $smarty->ds, $tpl->compiled->filepath));
|
||||
$_resource_part_1_length = strlen($_resource_part_1);
|
||||
} else {
|
||||
return 0;
|
||||
@@ -74,10 +75,10 @@ class Smarty_Internal_Method_ClearCompiledTemplate
|
||||
}
|
||||
$_compile = new RecursiveIteratorIterator($_compileDirs, RecursiveIteratorIterator::CHILD_FIRST);
|
||||
foreach ($_compile as $_file) {
|
||||
if (substr(basename($_file->getPathname()), 0, 1) === '.') {
|
||||
if (substr(basename($_file->getPathname()), 0, 1) == '.') {
|
||||
continue;
|
||||
}
|
||||
$_filepath = (string)$_file;
|
||||
$_filepath = (string) $_file;
|
||||
if ($_file->isDir()) {
|
||||
if (!$_compile->isDot()) {
|
||||
// delete folder if empty
|
||||
@@ -85,22 +86,19 @@ class Smarty_Internal_Method_ClearCompiledTemplate
|
||||
}
|
||||
} else {
|
||||
// delete only php files
|
||||
if (substr($_filepath, -4) !== '.php') {
|
||||
if (substr($_filepath, - 4) !== '.php') {
|
||||
continue;
|
||||
}
|
||||
$unlink = false;
|
||||
if ((!isset($_compile_id) || (isset($_filepath[ $_compile_id_part_length ]) && $a =
|
||||
!strncmp($_filepath, $_compile_id_part, $_compile_id_part_length))) &&
|
||||
(!isset($resource_name) || (isset($_filepath[ $_resource_part_1_length ]) &&
|
||||
substr_compare($_filepath,
|
||||
$_resource_part_1,
|
||||
-$_resource_part_1_length,
|
||||
$_resource_part_1_length) ===
|
||||
substr_compare($_filepath, $_resource_part_1,
|
||||
- $_resource_part_1_length, $_resource_part_1_length) ==
|
||||
0) || (isset($_filepath[ $_resource_part_2_length ]) &&
|
||||
substr_compare($_filepath,
|
||||
$_resource_part_2,
|
||||
-$_resource_part_2_length,
|
||||
$_resource_part_2_length) === 0))
|
||||
substr_compare($_filepath, $_resource_part_2,
|
||||
- $_resource_part_2_length,
|
||||
$_resource_part_2_length) == 0))
|
||||
) {
|
||||
if (isset($exp_time)) {
|
||||
if (is_file($_filepath) && time() - @filemtime($_filepath) >= $exp_time) {
|
||||
@@ -110,13 +108,14 @@ class Smarty_Internal_Method_ClearCompiledTemplate
|
||||
$unlink = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($unlink && is_file($_filepath) && @unlink($_filepath)) {
|
||||
$_count++;
|
||||
$_count ++;
|
||||
if (function_exists('opcache_invalidate')
|
||||
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
|
||||
) {
|
||||
opcache_invalidate($_filepath, true);
|
||||
} else if (function_exists('apc_delete_file')) {
|
||||
} elseif (function_exists('apc_delete_file')) {
|
||||
apc_delete_file($_filepath);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user