use wcf\system\package\PackageDependencyHandler;
use wcf\system\WCF;
use wcf\util\XML;
+use wcf\util\DirectoryUtil;
/**
* Provides functions to edit languages.
* @param string $category
* @param string $packageID
*/
- public static function deleteLanguageFiles($languageID = '*', $category = '*', $packageID = '*') {
- $files = @glob(WCF_DIR."language/".$packageID."_".$languageID."_".$category.".php");
- if (is_array($files)) {
- foreach ($files as $filename) {
- @unlink($filename);
- }
- }
+ public static function deleteLanguageFiles($languageID = '.*', $category = '.*', $packageID = '.*') {
+ if ($category != '.*') $category = preg_quote($category, '~');
+ if ($languageID != '.*') $languageID = intval($languageID);
+ if ($packageID != '.*') $packageID = intval($packageID);
+
+ DirectoryUtil::getInstance(WCF_DIR.'language/')->deletePattern('~'.$packageID.'_'.$languageID.'_'.$category.'\.php$~');
}
/**
*/
public function deleteCompiledTemplates() {
// templates
- $filenames = glob(WCF_DIR.'templates/compiled/*_'.$this->languageID.'_*.php');
- if ($filenames) foreach ($filenames as $filename) @unlink($filename);
-
+ DirectoryUtil::getInstance(WCF_DIR.'templates/compiled/')->deletePattern('~.*_'.$this->languageID.'_.*\.php$~');
// acp templates
- $filenames = glob(WCF_DIR.'acp/templates/compiled/*_'.$this->languageID.'_*.php');
- if ($filenames) foreach ($filenames as $filename) @unlink($filename);
+ DirectoryUtil::getInstance(WCF_DIR.'acp/templates/compiled/')->deletePattern('~.*_'.$this->languageID.'_.*\.php$~');
}
/**
use wcf\system\io\File;
use wcf\system\WCF;
use wcf\util\FileUtil;
+use wcf\util\DirectoryUtil;
/**
* DiskCacheSource is an implementation of CacheSource that stores the cache as simple files in the file system.
*/
public function clear($directory, $filepattern, $forceDelete = false) {
$filepattern = str_replace('*', '.*', str_replace('.', '\.', $filepattern));
- $directory = FileUtil::addTrailingSlash($directory);
-
- if (@file_exists($directory)) {
- $dirh = opendir($directory);
- while ($filename = readdir($dirh)) {
- if ($filename != '.' && $filename != '..' && preg_match('%^'.$filepattern.'$%i', $filename)) {
- if ($forceDelete || !@touch($directory.$filename, 1)) {
- @unlink($directory.$filename);
- }
- }
- }
- closedir($dirh);
+ if (substr($directory, -1) != '/') {
+ $directory .= '/';
}
+
+ DirectoryUtil::getInstance($directory)->executeCallback(function ($filename) use ($forceDelete) {
+ if ($forceDelete || !@touch($filename, 1)) {
+ @unlink($filename);
+ }
+ }, '%^'.$directory.$filepattern.'$%i');
}
/**
while ($row = $statement->fetchArray()) {
$packageDir = FileUtil::getRealPath(WCF_DIR.$row['packageDir']);
$cacheDir = $packageDir.'cache';
- if (file_exists($cacheDir)) {
- // get files in cache directory
- $files = glob($cacheDir.'/*.php');
- if (is_array($files)) {
- foreach ($files as $file) {
- @unlink($file);
- }
- }
- }
+ DirectoryUtil::getInstance($cacheDir)->deletePattern('~.*\.php$');
}
}
}
use wcf\system\SingletonFactory;
use wcf\util\HeaderUtil;
use wcf\util\StringUtil;
+use wcf\util\DirectoryUtil;
/**
* TemplateEngine loads and displays template.
*/
public static function deleteCompiledTemplates($compileDir = '') {
if (empty($compileDir)) $compileDir = WCF_DIR.'templates/compiled/';
-
+
// delete compiled templates
- $matches = glob($compileDir . '*_*_*.php');
- if (is_array($matches)) {
- foreach ($matches as $match) @unlink($match);
- }
+ DirectoryUtil::getInstance($compileDir)->deletePattern('~.*_.*_.*\.php$');
}
/**