function getTemplateSubFolders($folder) { $templateSubFolders = array(); $files = Glob::myGlob($folder, "*"); foreach ($files as $file) { if (File::isDir($file)) { $tmp['name'] = basename($file); if ($tmp['name'] != "backups") { array_push($templateSubFolders, $tmp); } } } return $templateSubFolders; }
function render() { $config =& Config::getConfig(); $maxBackupFiles = $config->getValue("plugin_templateeditor_maxbackupfiles"); if ($maxBackupFiles == "") { $maxBackupFiles = 5; } // get a list with all the specific template files $ts = new TemplateSetStorage(); $blogId = $this->_blogInfo->getId(); $templateFolder = $ts->getTemplateFolder($this->_templateId); $templateFolder = $templateFolder . $this->_subFolderId . "/"; $backupFolder = $templateFolder . "backups/"; if (!File::exists($backupFolder)) { File::createDir($backupFolder); } if (!$this->_backupId) { $filename = $templateFolder . $this->_fileId; } else { $filename = $backupFolder . $this->_fileId . "_" . $this->_backupId; } $backupFilePattern = $this->_fileId . "_*"; $bakFiles = Glob::myGlob($backupFolder, $backupFilePattern); sort($bakFiles); $backupFiles = array(); $backupFileCount = 0; for ($i = count($bakFiles) - 1; $i >= 0; $i--) { $bakFile = $bakFiles[$i]; if ($backupFileCount < $maxBackupFiles) { $bakElements = explode("_", $bakFile); $bakId = $bakElements[count($bakElements) - 1]; $bakTime = strftime("%Y/%m/%d - %H:%M:%S", $bakId); $file['time'] = $bakTime; $file['backupId'] = basename($bakId); array_push($backupFiles, $file); $backupFileCount++; } else { File::delete($bakFile); } } $file = new MyFile($filename); $fileContent = $file->readFileContent(); $this->setValue("backupId", $this->_backupId); $this->setValue("backupFiles", $backupFiles); $this->setValue("currentTemplate", $this->_templateId); $this->setValue("currentSubFolder", $this->_subFolderId); $this->setValue("currentFile", $this->_fileId); $this->setValue("fileContent", $fileContent); parent::render(); }
/** * This function checks wether we're running a version of php at least or newer than * 4.3. If its newer, then we will use the native version of glob otherwise we will use * our own version. The order of the parameters is <b>not</b> the same as the native version * of glob, but they will be converted. The <i>flags</i> parameter is not used when * using the custom version of glob. * * @param folder The folder where would like to search for files. This function is <b>not</b> * recursive. * @param pattern The shell pattern that will match the files we are searching for. * @param flags This parameter is only used when using the native version of glob. For possible * values of this parameter, please check the glob function page. * @return Returns an array of the files that match the given pattern in the given * folder or false if there was an error. * @static */ function Glob($folder = ".", $pattern = "*", $flags = 0) { if (function_exists("glob")) { // call the native glob function with parameters $fileName = $folder; if (substr($fileName, -1) != "/") { $fileName .= "/"; } $fileName .= $pattern; return glob($fileName, $flags); } else { // call our own implementation return Glob::myGlob($folder, $pattern); } }
function getTemplateFiles($folder) { $templateFiles = array(); $files = Glob::myGlob($folder, "*"); foreach ($files as $file) { if (!File::isDir($file)) { $tmp['name'] = basename($file); $tmp['size'] = filesize($file); $tmp['isEditable'] = $this->isValidExtension($tmp['name']); $tmp['isImage'] = $this->isImage($tmp['name']); $tmp['url'] = $file; array_push($templateFiles, $tmp); } } return $templateFiles; }
/** * Goes through all the files in the folder to see if any of the files * has any of the forbidden extensions. * * @param folder The folder where files are, it will be scanned * using a glob-like function * @return Returns true if all files are ok or false otherwise. */ function checkForbiddenFiles($folder) { $config =& Config::getConfig(); $forbiddenFilesStr = $config->getValue('upload_forbidden_files'); // return true if there's nothing to do if (empty($forbiddenFilesStr) || !$forbiddenFilesStr) { return true; } // otherwise, turn the thing into an array and go through all of them foreach (explode(" ", $forbiddenFilesStr) as $file) { $files = Glob::myGlob($folder, $file); if (count($files) > 0) { return false; } } return true; }
/** * uses Glob::glob() to find files that match the given format * and compares the file names against the ones already available * * @param currentList * @param fileName */ function find($currentList, $fileName = '*') { $files = Glob::myGlob($this->_folder, $fileName); // create an empty array if we got something else other than an array so that // we can avoid some ugly error messages! if (!is_array($currentList)) { $currentList = array(); } // loop through the files... foreach ($files as $file) { // get the key for the given file $key = $this->getKeyForFile($file); if ($key != null && !in_array($key, $currentList)) { // the file is new! $this->_new[] = $key; } } // and now see which files are new and which ones have been removed, by comparing // both arrays... return true; }
/** * removes a directory, optinally in a recursive fashion * * @param dirName * @param recursive Whether to recurse through all subdirectories that * are within the given one and remove them. * @param onlyFiles If the recursive mode is enabled, setting this to 'true' will * force the method to only remove files but not folders. The directory will not be * removed but all the files included it in (and all subdirectories) will be. * @return True if successful or false otherwise * @static */ function deleteDir($dirName, $recursive = false, $onlyFiles = false) { // if the directory can't be read, then quit with an error if (!File::isReadable($dirName) || !File::exists($dirName)) { return false; } // if it's not a file, let's get out of here and transfer flow // to the right place... if (!File::isDir($dirName)) { return File::delete($dirName); } // Glob::myGlob is easier to use than Glob::glob, specially when // we're relying on the native version... This improved version // will automatically ignore things like "." and ".." for us, // making it much easier! $files = Glob::myGlob($dirName, "*"); foreach ($files as $file) { if (File::isDir($file)) { // perform a recursive call if we were allowed to do so if ($recursive) { File::deleteDir($file, $recursive, $onlyFiles); } } // File::delete can remove empty folders as well as files if (File::isReadable($file)) { File::delete($file); } } // finally, remove the top-level folder but only in case we // are supposed to! if (!$onlyFiles) { File::delete($dirName); } return true; }
/** * Removes the old captcha images that are not needed anymre *Ê@private */ function purgeOld($expireTime = CAPTCHA_DEFAULT_EXPIRATION_TIME) { include_once PLOG_CLASS_PATH . "class/misc/glob.class.php"; $files = Glob::myGlob($this->cacheFolder, "*.gif"); if ($files) { foreach ($files as $file) { $diff = time() - filectime($file); if ($diff > $expireTime) { unlink($file); } } } }
function getTemplateFiles($folder) { $config =& Config::getConfig(); $allowedExtension = $config->getValue("plugin_templateeditor_allowedextension"); if ($allowedExtension == "") { $allowedExtension = "css,inc,template,txt"; } $extensionList = explode(",", $allowedExtension); $templateFiles = array(); for ($i = 0; $i < count($extensionList); $i++) { $extension = "*." . trim($extensionList[$i]); $files = Glob::myGlob($folder, $extension); foreach ($files as $file) { $tmp['name'] = basename($file); $tmp['size'] = filesize($file); array_push($templateFiles, $tmp); } } return $templateFiles; }