/** * Initialise Twig * * @return void */ protected function initTemplateEngine() { $this->loader = new \Smarty(); $this->loader->muteExpectedErrors(); $this->loader->setTemplateDir($this->getTemplateDir()); $this->loader->addPluginsDir(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'SmartyPlugins'); $this->initSmartyCache(); Logger::debug("Smarty Cache: " . $this->loader->getCacheDir()); }
/** * diagnose Smarty setup * * If $errors is secified, the diagnostic report will be appended to the array, rather than being output. * * @param Smarty $smarty Smarty instance to test * @param array $errors array to push results into rather than outputting them * @return bool status, true if everything is fine, false else */ public static function testInstall(Smarty $smarty, &$errors = null) { $status = true; if ($errors === null) { echo "<PRE>\n"; echo "Smarty Installation test...\n"; echo "Testing template directory...\n"; } // test if all registered template_dir are accessible foreach ($smarty->getTemplateDir() as $template_dir) { if (!is_dir($template_dir)) { $status = false; $message = "FAILED: {$template_dir} is not a directory"; if ($errors === null) { echo $message . ".\n"; } else { $errors['template_dir'] = $message; } } elseif (!is_readable($template_dir)) { $status = false; $message = "FAILED: {$template_dir} is not readable"; if ($errors === null) { echo $message . ".\n"; } else { $errors['template_dir'] = $message; } } else { if ($errors === null) { echo "{$template_dir} is OK.\n"; } } } if ($errors === null) { echo "Testing compile directory...\n"; } // test if registered compile_dir is accessible $_compile_dir = $smarty->getCompileDir(); if (!is_dir($_compile_dir)) { $status = false; $message = "FAILED: {$_compile_dir} is not a directory"; if ($errors === null) { echo $message . ".\n"; } else { $errors['compile_dir'] = $message; } } elseif (!is_readable($_compile_dir)) { $status = false; $message = "FAILED: {$_compile_dir} is not readable"; if ($errors === null) { echo $message . ".\n"; } else { $errors['compile_dir'] = $message; } } elseif (!is_writable($_compile_dir)) { $status = false; $message = "FAILED: {$_compile_dir} is not writable"; if ($errors === null) { echo $message . ".\n"; } else { $errors['compile_dir'] = $message; } } else { if ($errors === null) { echo "{$_compile_dir} is OK.\n"; } } if ($errors === null) { echo "Testing plugins directory...\n"; } // test if all registered plugins_dir are accessible // and if core plugins directory is still registered $_core_plugins_dir = realpath(dirname(__FILE__) . '/../plugins'); $_core_plugins_available = false; foreach ($smarty->getPluginsDir() as $plugin_dir) { if (!is_dir($plugin_dir)) { $status = false; $message = "FAILED: {$plugin_dir} is not a directory"; if ($errors === null) { echo $message . ".\n"; } else { $errors['plugins_dir'] = $message; } } elseif (!is_readable($plugin_dir)) { $status = false; $message = "FAILED: {$plugin_dir} is not readable"; if ($errors === null) { echo $message . ".\n"; } else { $errors['plugins_dir'] = $message; } } elseif ($_core_plugins_dir && $_core_plugins_dir == realpath($plugin_dir)) { $_core_plugins_available = true; } else { if ($errors === null) { echo "{$plugin_dir} is OK.\n"; } } } if (!$_core_plugins_available) { $status = false; $message = "WARNING: Smarty's own libs/plugins is not available"; if ($errors === null) { echo $message . ".\n"; } elseif (!isset($errors['plugins_dir'])) { $errors['plugins_dir'] = $message; } } if ($errors === null) { echo "Testing cache directory...\n"; } $_cache_dir = $smarty->getCacheDir(); // test if all registered cache_dir is accessible if (!is_dir($_cache_dir)) { $status = false; $message = "FAILED: {$_cache_dir} is not a directory"; if ($errors === null) { echo $message . ".\n"; } else { $errors['cache_dir'] = $message; } } elseif (!is_readable($_cache_dir)) { $status = false; $message = "FAILED: {$_cache_dir} is not readable"; if ($errors === null) { echo $message . ".\n"; } else { $errors['cache_dir'] = $message; } } elseif (!is_writable($_cache_dir)) { $status = false; $message = "FAILED: {$_cache_dir} is not writable"; if ($errors === null) { echo $message . ".\n"; } else { $errors['cache_dir'] = $message; } } else { if ($errors === null) { echo "{$_cache_dir} is OK.\n"; } } if ($errors === null) { echo "Testing configs directory...\n"; } // test if all registered config_dir are accessible foreach ($smarty->getConfigDir() as $config_dir) { if (!is_dir($config_dir)) { $status = false; $message = "FAILED: {$config_dir} is not a directory"; if ($errors === null) { echo $message . ".\n"; } else { $errors['config_dir'] = $message; } } elseif (!is_readable($config_dir)) { $status = false; $message = "FAILED: {$config_dir} is not readable"; if ($errors === null) { echo $message . ".\n"; } else { $errors['config_dir'] = $message; } } else { if ($errors === null) { echo "{$config_dir} is OK.\n"; } } } if ($errors === null) { echo "Testing sysplugin files...\n"; } // test if sysplugins are available $source = SMARTY_SYSPLUGINS_DIR; if (is_dir($source)) { $expected = array("smarty_cacheresource.php" => true, "smarty_cacheresource_custom.php" => true, "smarty_cacheresource_keyvaluestore.php" => true, "smarty_config_source.php" => true, "smarty_internal_cacheresource_file.php" => true, "smarty_internal_compile_append.php" => true, "smarty_internal_compile_assign.php" => true, "smarty_internal_compile_block.php" => true, "smarty_internal_compile_break.php" => true, "smarty_internal_compile_call.php" => true, "smarty_internal_compile_capture.php" => true, "smarty_internal_compile_config_load.php" => true, "smarty_internal_compile_continue.php" => true, "smarty_internal_compile_debug.php" => true, "smarty_internal_compile_eval.php" => true, "smarty_internal_compile_extends.php" => true, "smarty_internal_compile_for.php" => true, "smarty_internal_compile_foreach.php" => true, "smarty_internal_compile_function.php" => true, "smarty_internal_compile_if.php" => true, "smarty_internal_compile_include.php" => true, "smarty_internal_compile_include_php.php" => true, "smarty_internal_compile_insert.php" => true, "smarty_internal_compile_ldelim.php" => true, "smarty_internal_compile_nocache.php" => true, "smarty_internal_compile_private_block_plugin.php" => true, "smarty_internal_compile_private_function_plugin.php" => true, "smarty_internal_compile_private_modifier.php" => true, "smarty_internal_compile_private_object_block_function.php" => true, "smarty_internal_compile_private_object_function.php" => true, "smarty_internal_compile_private_print_expression.php" => true, "smarty_internal_compile_private_registered_block.php" => true, "smarty_internal_compile_private_registered_function.php" => true, "smarty_internal_compile_private_special_variable.php" => true, "smarty_internal_compile_rdelim.php" => true, "smarty_internal_compile_section.php" => true, "smarty_internal_compile_setfilter.php" => true, "smarty_internal_compile_while.php" => true, "smarty_internal_compilebase.php" => true, "smarty_internal_config.php" => true, "smarty_internal_config_file_compiler.php" => true, "smarty_internal_configfilelexer.php" => true, "smarty_internal_configfileparser.php" => true, "smarty_internal_data.php" => true, "smarty_internal_debug.php" => true, "smarty_internal_filter_handler.php" => true, "smarty_internal_function_call_handler.php" => true, "smarty_internal_get_include_path.php" => true, "smarty_internal_nocache_insert.php" => true, "smarty_internal_parsetree.php" => true, "smarty_internal_resource_eval.php" => true, "smarty_internal_resource_extends.php" => true, "smarty_internal_resource_file.php" => true, "smarty_internal_resource_registered.php" => true, "smarty_internal_resource_stream.php" => true, "smarty_internal_resource_string.php" => true, "smarty_internal_smartytemplatecompiler.php" => true, "smarty_internal_template.php" => true, "smarty_internal_templatebase.php" => true, "smarty_internal_templatecompilerbase.php" => true, "smarty_internal_templatelexer.php" => true, "smarty_internal_templateparser.php" => true, "smarty_internal_utility.php" => true, "smarty_internal_write_file.php" => true, "smarty_resource.php" => true, "smarty_resource_custom.php" => true, "smarty_resource_recompiled.php" => true, "smarty_resource_uncompiled.php" => true, "smarty_security.php" => true); $iterator = new DirectoryIterator($source); foreach ($iterator as $file) { if (!$file->isDot()) { $filename = $file->getFilename(); if (isset($expected[$filename])) { unset($expected[$filename]); } } } if ($expected) { $status = false; $message = "FAILED: files missing from libs/sysplugins: " . join(', ', array_keys($expected)); if ($errors === null) { echo $message . ".\n"; } else { $errors['sysplugins'] = $message; } } elseif ($errors === null) { echo "... OK\n"; } } else { $status = false; $message = "FAILED: " . SMARTY_SYSPLUGINS_DIR . ' is not a directory'; if ($errors === null) { echo $message . ".\n"; } else { $errors['sysplugins_dir_constant'] = $message; } } if ($errors === null) { echo "Testing plugin files...\n"; } // test if core plugins are available $source = SMARTY_PLUGINS_DIR; if (is_dir($source)) { $expected = array("block.textformat.php" => true, "function.counter.php" => true, "function.cycle.php" => true, "function.fetch.php" => true, "function.html_checkboxes.php" => true, "function.html_image.php" => true, "function.html_options.php" => true, "function.html_radios.php" => true, "function.html_select_date.php" => true, "function.html_select_time.php" => true, "function.html_table.php" => true, "function.mailto.php" => true, "function.math.php" => true, "modifier.capitalize.php" => true, "modifier.date_format.php" => true, "modifier.debug_print_var.php" => true, "modifier.escape.php" => true, "modifier.regex_replace.php" => true, "modifier.replace.php" => true, "modifier.spacify.php" => true, "modifier.truncate.php" => true, "modifiercompiler.cat.php" => true, "modifiercompiler.count_characters.php" => true, "modifiercompiler.count_paragraphs.php" => true, "modifiercompiler.count_sentences.php" => true, "modifiercompiler.count_words.php" => true, "modifiercompiler.default.php" => true, "modifiercompiler.escape.php" => true, "modifiercompiler.from_charset.php" => true, "modifiercompiler.indent.php" => true, "modifiercompiler.lower.php" => true, "modifiercompiler.noprint.php" => true, "modifiercompiler.string_format.php" => true, "modifiercompiler.strip.php" => true, "modifiercompiler.strip_tags.php" => true, "modifiercompiler.to_charset.php" => true, "modifiercompiler.unescape.php" => true, "modifiercompiler.upper.php" => true, "modifiercompiler.wordwrap.php" => true, "outputfilter.trimwhitespace.php" => true, "shared.escape_special_chars.php" => true, "shared.literal_compiler_param.php" => true, "shared.make_timestamp.php" => true, "shared.mb_str_replace.php" => true, "shared.mb_unicode.php" => true, "shared.mb_wordwrap.php" => true, "variablefilter.htmlspecialchars.php" => true); $iterator = new DirectoryIterator($source); foreach ($iterator as $file) { if (!$file->isDot()) { $filename = $file->getFilename(); if (isset($expected[$filename])) { unset($expected[$filename]); } } } if ($expected) { $status = false; $message = "FAILED: files missing from libs/plugins: " . join(', ', array_keys($expected)); if ($errors === null) { echo $message . ".\n"; } else { $errors['plugins'] = $message; } } elseif ($errors === null) { echo "... OK\n"; } } else { $status = false; $message = "FAILED: " . SMARTY_PLUGINS_DIR . ' is not a directory'; if ($errors === null) { echo $message . ".\n"; } else { $errors['plugins_dir_constant'] = $message; } } if ($errors === null) { echo "Tests complete.\n"; echo "</PRE>\n"; } return $status; }
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time) { $_cache_id = isset($cache_id) ? preg_replace('![^\\w\\|]+!', '_', $cache_id) : null; $_compile_id = isset($compile_id) ? preg_replace('![^\\w\\|]+!', '_', $compile_id) : null; $_dir_sep = $smarty->use_sub_dirs ? '/' : '^'; $_compile_id_offset = $smarty->use_sub_dirs ? 3 : 0; $_dir = $smarty->getCacheDir(); $_dir_length = strlen($_dir); if (isset($_cache_id)) { $_cache_id_parts = explode('|', $_cache_id); $_cache_id_parts_count = count($_cache_id_parts); if ($smarty->use_sub_dirs) { foreach ($_cache_id_parts as $id_part) { $_dir .= $id_part . DS; } } } if (isset($resource_name)) { $_save_stat = $smarty->caching; $smarty->caching = true; $tpl = new $smarty->template_class($resource_name, $smarty); $smarty->caching = $_save_stat; $tpl->source; if ($smarty->allow_ambiguous_resources) { $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id; } else { $_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id; } if (isset($_templateId[150])) { $_templateId = sha1($_templateId); } unset($smarty->template_objects[$_templateId]); if ($tpl->source->exists) { $_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath)); } else { return 0; } } $_count = 0; $_time = time(); if (file_exists($_dir)) { $_cacheDirs = new RecursiveDirectoryIterator($_dir); $_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST); foreach ($_cache as $_file) { if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) { continue; } if ($_file->isDir()) { if (!$_cache->isDot()) { @rmdir($_file->getPathname()); } } else { $_parts = explode($_dir_sep, str_replace('\\', '/', substr((string) $_file, $_dir_length))); $_parts_count = count($_parts); if (isset($resource_name)) { if ($_parts[$_parts_count - 1] != $_resourcename_parts) { continue; } } if (isset($_compile_id) && (!isset($_parts[$_parts_count - 2 - $_compile_id_offset]) || $_parts[$_parts_count - 2 - $_compile_id_offset] != $_compile_id)) { continue; } if (isset($_cache_id)) { $_parts_count = isset($_compile_id) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset; if ($_parts_count < $_cache_id_parts_count) { continue; } for ($i = 0; $i < $_cache_id_parts_count; $i++) { if ($_parts[$i] != $_cache_id_parts[$i]) { continue 2; } } } if (isset($exp_time) && $_time - @filemtime($_file) < $exp_time) { continue; } $_count += @unlink((string) $_file) ? 1 : 0; } } } return $_count; }
/** * Empty cache for a specific template * * @param Smarty $smarty * @param string $resource_name template name * @param string $cache_id cache id * @param string $compile_id compile id * @param integer $exp_time expiration time (number of seconds, not timestamp) * * @return integer number of cache files deleted */ public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time) { $_cache_id = isset($cache_id) ? preg_replace('![^\\w\\|]+!', '_', $cache_id) : null; $_compile_id = isset($compile_id) ? preg_replace('![^\\w\\|]+!', '_', $compile_id) : null; $_dir_sep = $smarty->use_sub_dirs ? '/' : '^'; $_compile_id_offset = $smarty->use_sub_dirs ? 3 : 0; if (($_dir = realpath($smarty->getCacheDir())) === false) { return 0; } $_dir .= '/'; $_dir_length = strlen($_dir); if (isset($_cache_id)) { $_cache_id_parts = explode('|', $_cache_id); $_cache_id_parts_count = count($_cache_id_parts); if ($smarty->use_sub_dirs) { foreach ($_cache_id_parts as $id_part) { $_dir .= $id_part . DS; } } } if (isset($resource_name)) { $_save_stat = $smarty->caching; $smarty->caching = true; $tpl = new $smarty->template_class($resource_name, $smarty); $smarty->caching = $_save_stat; // remove from template cache $tpl->source; // have the template registered before unset() if ($smarty->allow_ambiguous_resources) { $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id; } else { $_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id; } if (isset($_templateId[150])) { $_templateId = sha1($_templateId); } unset($smarty->template_objects[$_templateId]); if ($tpl->source->exists) { $_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath)); } else { return 0; } } $_count = 0; $_time = time(); if (file_exists($_dir)) { $_cacheDirs = new RecursiveDirectoryIterator($_dir); $_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST); foreach ($_cache as $_file) { if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) { continue; } // directory ? if ($_file->isDir()) { if (!$_cache->isDot()) { // delete folder if empty @rmdir($_file->getPathname()); } } else { $_parts = explode($_dir_sep, str_replace('\\', '/', substr((string) $_file, $_dir_length))); $_parts_count = count($_parts); // check name if (isset($resource_name)) { if ($_parts[$_parts_count - 1] != $_resourcename_parts) { continue; } } // check compile id if (isset($_compile_id) && (!isset($_parts[$_parts_count - 2 - $_compile_id_offset]) || $_parts[$_parts_count - 2 - $_compile_id_offset] != $_compile_id)) { continue; } // check cache id if (isset($_cache_id)) { // count of cache id parts $_parts_count = isset($_compile_id) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset; if ($_parts_count < $_cache_id_parts_count) { continue; } for ($i = 0; $i < $_cache_id_parts_count; $i++) { if ($_parts[$i] != $_cache_id_parts[$i]) { continue 2; } } } // expired ? if (isset($exp_time)) { if ($exp_time < 0) { preg_match('#\'cache_lifetime\' =>\\s*(\\d*)#', file_get_contents($_file), $match); if ($_time < @filemtime($_file) + $match[1]) { continue; } } else { if ($_time - @filemtime($_file) < $exp_time) { continue; } } } $_count += @unlink((string) $_file) ? 1 : 0; } } } return $_count; }
/** * Empty cache for a specific template * * @param Smarty $smarty * @param string $resource_name template name * @param string $cache_id cache id * @param string $compile_id compile id * @param integer $exp_time expiration time (number of seconds, not timestamp) * * @return integer number of cache files deleted */ public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time) { $_cache_id = isset($cache_id) ? preg_replace('![^\\w\\|]+!', '_', $cache_id) : null; $_compile_id = isset($compile_id) ? preg_replace('![^\\w]+!', '_', $compile_id) : null; $_dir_sep = $smarty->use_sub_dirs ? '/' : '^'; $_compile_id_offset = $smarty->use_sub_dirs ? 3 : 0; $_dir = $smarty->getCacheDir(); if ($_dir == '/') { //We should never want to delete this! return 0; } $_dir_length = strlen($_dir); if (isset($_cache_id)) { $_cache_id_parts = explode('|', $_cache_id); $_cache_id_parts_count = count($_cache_id_parts); if ($smarty->use_sub_dirs) { foreach ($_cache_id_parts as $id_part) { $_dir .= $id_part . $smarty->ds; } } } if (isset($resource_name)) { $_save_stat = $smarty->caching; $smarty->caching = true; $tpl = new $smarty->template_class($resource_name, $smarty); $smarty->caching = $_save_stat; // remove from template cache $tpl->source; // have the template registered before unset() if ($tpl->source->exists) { $_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath)); } else { return 0; } } $_count = 0; $_time = time(); if (file_exists($_dir)) { $_cacheDirs = new RecursiveDirectoryIterator($_dir); $_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST); foreach ($_cache as $_file) { if (substr(basename($_file->getPathname()), 0, 1) == '.') { continue; } $_filepath = (string) $_file; // directory ? if ($_file->isDir()) { if (!$_cache->isDot()) { // delete folder if empty @rmdir($_file->getPathname()); } } else { // delete only php files if (substr($_filepath, -4) !== '.php') { continue; } $_parts = explode($_dir_sep, str_replace('\\', '/', substr($_filepath, $_dir_length))); $_parts_count = count($_parts); // check name if (isset($resource_name)) { if ($_parts[$_parts_count - 1] != $_resourcename_parts) { continue; } } // check compile id if (isset($_compile_id) && (!isset($_parts[$_parts_count - 2 - $_compile_id_offset]) || $_parts[$_parts_count - 2 - $_compile_id_offset] != $_compile_id)) { continue; } // check cache id if (isset($_cache_id)) { // count of cache id parts $_parts_count = isset($_compile_id) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset; if ($_parts_count < $_cache_id_parts_count) { continue; } for ($i = 0; $i < $_cache_id_parts_count; $i++) { if ($_parts[$i] != $_cache_id_parts[$i]) { continue 2; } } } // expired ? if (isset($exp_time)) { if ($exp_time < 0) { preg_match('#\'cache_lifetime\' =>\\s*(\\d*)#', file_get_contents($_file), $match); if ($_time < @filemtime($_file) + $match[1]) { continue; } } else { if ($_time - @filemtime($_file) < $exp_time) { continue; } } } $_count += @unlink($_filepath) ? 1 : 0; if (function_exists('opcache_invalidate') && strlen(ini_get("opcache.restrict_api")) < 1) { opcache_invalidate($_filepath, true); } } } } return $_count; }
/** * Empty cache for a specific template * * @param Smarty $_template template object * @param string $resource_name template name * @param string $cache_id cache id * @param string $compile_id compile id * @param integer $exp_time expiration time (number of seconds, not timestamp) * @return integer number of cache files deleted */ public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time) { $_cache_id = isset($cache_id) ? preg_replace('![^\\w\\|]+!', '_', $cache_id) : null; $_compile_id = isset($compile_id) ? preg_replace('![^\\w\\|]+!', '_', $compile_id) : null; $_dir_sep = $smarty->use_sub_dirs ? '/' : '^'; $_compile_id_offset = $smarty->use_sub_dirs ? 3 : 0; $_dir = $smarty->getCacheDir(); $_dir_length = strlen($_dir); if (isset($_cache_id)) { $_cache_id_parts = explode('|', $_cache_id); $_cache_id_parts_count = count($_cache_id_parts); if ($smarty->use_sub_dirs) { foreach ($_cache_id_parts as $id_part) { $_dir .= $id_part . DS; } } } if (isset($resource_name)) { $_save_stat = $smarty->caching; $smarty->caching = true; $tpl = new $smarty->template_class($resource_name, $smarty); $smarty->caching = $_save_stat; if ($tpl->source->exists) { $_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath)); // remove from template cache unset($smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()) . $tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]); } else { // remove from template cache unset($smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()) . $tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]); return 0; } } $_count = 0; $_time = time(); if (file_exists($_dir)) { $_cacheDirs = new RecursiveDirectoryIterator($_dir); $_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST); foreach ($_cache as $_file) { if (substr($_file->getBasename(), 0, 1) == '.' || strpos($_file, '.svn') !== false) { continue; } // directory ? if ($_file->isDir()) { if (!$_cache->isDot()) { // delete folder if empty @rmdir($_file->getPathname()); } } else { $_parts = explode($_dir_sep, str_replace('\\', '/', substr((string) $_file, $_dir_length))); $_parts_count = count($_parts); // check name if (isset($resource_name)) { if ($_parts[$_parts_count - 1] != $_resourcename_parts) { continue; } } // check compile id if (isset($_compile_id) && (!isset($_parts[$_parts_count - 2 - $_compile_id_offset]) || $_parts[$_parts_count - 2 - $_compile_id_offset] != $_compile_id)) { continue; } // check cache id if (isset($_cache_id)) { // count of cache id parts $_parts_count = isset($_compile_id) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset; if ($_parts_count < $_cache_id_parts_count) { continue; } for ($i = 0; $i < $_cache_id_parts_count; $i++) { if ($_parts[$i] != $_cache_id_parts[$i]) { continue 2; } } } // expired ? if (isset($exp_time) && $_time - @filemtime($_file) < $exp_time) { continue; } $_count += @unlink((string) $_file) ? 1 : 0; } } } return $_count; }