php wcf-util-FileUtil类(方法)实例源码

下面列出了php wcf-util-FileUtil 类(方法)源码代码实例,从而了解它的用法。

作者:nick-stroh    项目:WC   
/**
  * Calls all init functions of the WCF class.
  */
 public function __construct()
 {
     // add autoload directory
     self::$autoloadDirectories['wcf'] = WCF_DIR . 'lib/';
     // define tmp directory
     if (!defined('TMP_DIR')) {
         define('TMP_DIR', FileUtil::getTempFolder());
     }
     // register additional autoloaders
     require_once WCF_DIR . 'lib/system/api/phpline/phpline.phar';
     require_once WCF_DIR . 'lib/system/api/zend/Loader/StandardAutoloader.php';
     $zendLoader = new ZendLoader(array(ZendLoader::AUTOREGISTER_ZF => true));
     $zendLoader->register();
     $argv = new ArgvParser(array('packageID=i' => ''));
     $argv->setOption(ArgvParser::CONFIG_FREEFORM_FLAGS, true);
     $argv->parse();
     define('PACKAGE_ID', $argv->packageID ?: 1);
     // disable benchmark
     define('ENABLE_BENCHMARK', 0);
     // start initialization
     $this->initDB();
     $this->loadOptions();
     $this->initSession();
     $this->initLanguage();
     $this->initTPL();
     $this->initCoreObjects();
     $this->initApplications();
     // the destructor registered in core.functions.php will only call the destructor of the parent class
     register_shutdown_function(array('wcf\\system\\CLIWCF', 'destruct'));
     $this->initArgv();
     $this->initPHPLine();
     $this->initAuth();
     $this->checkForUpdates();
     $this->initCommands();
 }

作者:0xLeo    项目:WC   
/**
	 * @see	wcf\system\package\plugin\IPackageInstallationPlugin::uninstall()
	 */
	public function uninstall() {
		// create ACP-templates list
		$templates = array();
		
		// get ACP-templates from log
		$sql = "SELECT	*
			FROM	wcf".WCF_N."_acp_template
			WHERE	packageID = ?";
		$statement = WCF::getDB()->prepareStatement($sql);
		$statement->execute(array($this->installation->getPackageID()));
		while ($row = $statement->fetchArray()) {
			// store acp template with suffix (_$packageID)
			$templates[] = 'acp/templates/'.$row['templateName'].'.tpl';
		}
		
		if (!empty($templates)) {
			// delete template files
			$packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR.$this->installation->getPackage()->packageDir));
			$deleteEmptyDirectories = $this->installation->getPackage()->isApplication;
			$this->installation->deleteFiles($packageDir, $templates, false, $deleteEmptyDirectories);
			
			// delete log entries
			parent::uninstall();
		}
	}

作者:knz    项目:Firebal   
/**
  * @see	\wcf\form\IForm::validate()
  */
 public function validate()
 {
     parent::validate();
     // check if file is uploaded or linked
     if (!empty($this->file['tmp_name'])) {
         $this->backup = $this->file['tmp_name'];
     } else {
         if ($this->fileLink != '') {
             //check if file is external url
             if (FileUtil::isURL($this->fileLink)) {
                 try {
                     //download file
                     $this->backup = FileUtil::downloadFileFromHttp($this->fileLink, 'cms_backup');
                 } catch (SystemException $e) {
                     //download failed
                     throw new UserInputException('fileLink', 'downloadFailed');
                 }
             } else {
                 //file not found
                 if (!file_exists($this->fileLink)) {
                     throw new UserInputException('fileLink', 'notFound');
                 } else {
                     $this->backup = $this->fileLink;
                 }
             }
         } else {
             throw new UserInputException('file', 'empty');
         }
     }
 }

作者:Gribori    项目:de.incendium.cms.filebas   
/**
  * Handles uploaded files.
  */
 public function upload()
 {
     // save files
     $files = $this->parameters['__files']->getFiles();
     $file = $files[0];
     try {
         if (!$file->getValidationErrorType()) {
             $data = array('userID' => WCF::getUser()->userID ?: null, 'filename' => $file->getFilename(), 'fileType' => $file->getMimeType(), 'fileHash' => sha1_file($file->getLocation()), 'filesize' => $file->getFilesize(), 'uploadTime' => TIME_NOW);
             // save file
             $upload = FileUploadEditor::create($data);
             // move uploaded file
             if (@copy($file->getLocation(), $upload->getLocation())) {
                 @unlink($file->getLocation());
                 // return result
                 return array('uploadID' => $upload->uploadID, 'filename' => $upload->filename, 'filesize' => $upload->filesize, 'formattedFilesize' => FileUtil::formatFilesize($upload->filesize));
             } else {
                 // moving failed; delete file
                 $editor = new FileUploadEditor($upload);
                 $editor->delete();
                 throw new UserInputException('fileUpload', 'uploadFailed');
             }
         }
     } catch (UserInputException $e) {
         $file->setValidationErrorType($e->getType());
     }
     return array('errorType' => $file->getValidationErrorType());
 }

作者:joshuarueswe    项目:de.voolia.new   
/**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     $returnValues = $this->objectAction->getReturnValues();
     // create folder for pictures of this category
     FileUtil::makePath(NEWS_DIR . 'images/news/' . $returnValues['returnValues']->categoryID . '/');
 }

作者:0xLeo    项目:WC   
/**
	 * Calls all init functions of the WCF and the WCFACP class. 
	 */
	public function __construct() {
		// add autoload directory
		self::$autoloadDirectories['wcf'] = WCF_DIR . 'lib/';
		
		// define tmp directory
		if (!defined('TMP_DIR')) define('TMP_DIR', FileUtil::getTempFolder());
		
		// start initialization
		$this->initMagicQuotes();
		$this->initDB();
		$this->loadOptions();
		$this->initPackage();
		$this->initSession();
		$this->initLanguage();
		$this->initTPL();
		$this->initCronjobs();
		$this->initCoreObjects();
		
		// prevent application loading during setup
		if (PACKAGE_ID) {
			$this->initApplications();
		}
		
		$this->initBlacklist();
		$this->initAuth();
	}

作者:ZerGabrie    项目:WC   
/**
  * @see wcf\system\ICronjob::execute()
  */
 public function execute(Cronjob $cronjob)
 {
     $filename = FileUtil::downloadFileFromHttp('http://www.woltlab.com/spiderlist/spiderlist.xml', 'spiders');
     $xml = new XML();
     $xml->load($filename);
     $xpath = $xml->xpath();
     // fetch spiders
     $spiders = $xpath->query('/spiderlist/spider');
     if (count($spiders)) {
         // delete old entries
         $sql = "DELETE FROM wcf" . WCF_N . "_spider";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute();
         $statementParameters = array();
         foreach ($spiders as $spider) {
             $identifier = StringUtil::toLowerCase($spider->getAttribute('ident'));
             $name = $xpath->query('name', $spider)->item(0);
             $info = $xpath->query('info', $spider)->item(0);
             $statementParameters[$identifier] = array('spiderIdentifier' => $identifier, 'spiderName' => $name->nodeValue, 'spiderURL' => $info ? $info->nodeValue : '');
         }
         if (!empty($statementParameters)) {
             $sql = "INSERT INTO\twcf" . WCF_N . "_spider\n\t\t\t\t\t\t\t(spiderIdentifier, spiderName, spiderURL)\n\t\t\t\t\tVALUES\t\t(?, ?, ?)";
             $statement = WCF::getDB()->prepareStatement($sql);
             foreach ($statementParameters as $parameters) {
                 $statement->execute(array($parameters['spiderIdentifier'], $parameters['spiderName'], $parameters['spiderURL']));
             }
         }
         // clear spider cache
         CacheHandler::getInstance()->clear(WCF_DIR . 'cache', 'cache.spiders.php');
     }
     // delete tmp file
     @unlink($filename);
 }

作者:nick-stroh    项目:WC   
/**
  * @see	\wcf\system\option\IOptionType::getData()
  */
 public function getData(Option $option, $newValue)
 {
     $this->createUploadHandler($option);
     if ($this->uploadHandlers[$option->optionName] === null) {
         return '';
     }
     $files = $this->uploadHandlers[$option->optionName]->getFiles();
     $file = reset($files);
     // check if file has been uploaded
     if (!$file->getFilename()) {
         // if checkbox is checked, remove file
         if ($newValue) {
             @unlink($option->optionValue);
             return '';
         }
         // use old value
         return $option->optionValue;
     } else {
         if ($option->optionValue) {
             // delete old file first
             @unlink($option->optionValue);
         }
     }
     // determine location the file will be stored at
     $package = PackageCache::getInstance()->getPackage($option->packageID);
     $fileLocation = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $package->packageDir)) . $option->filelocation . '.' . $file->getFileExtension();
     // save file
     move_uploaded_file($file->getLocation(), $fileLocation);
     // return file location as the value to store in the database
     return $fileLocation;
 }

作者:0xLeo    项目:WC   
/**
	 * @see	wcf\system\package\plugin\IPackageInstallationPlugin::install()
	 */
	public function install() {
		parent::install();
		
		// get installation path of package
		$sql = "SELECT	packageDir
			FROM	wcf".WCF_N."_package
			WHERE	packageID = ?";
		$statement = WCF::getDB()->prepareStatement($sql);
		$statement->execute(array($this->installation->getPackageID()));
		$packageDir = $statement->fetchArray();
		$packageDir = $packageDir['packageDir'];
		
		// get relative path of script
		$path = FileUtil::getRealPath(WCF_DIR.$packageDir);
		
		// reset WCF cache
		CacheHandler::getInstance()->flushAll();
		
		// run script
		$this->run($path.$this->instruction['value']);
		
		// delete script
		if (@unlink($path.$this->instruction['value'])) {
			// delete file log entry
			$sql = "DELETE FROM	wcf".WCF_N."_package_installation_file_log
				WHERE		packageID = ?
						AND filename = ?";
			$statement = WCF::getDB()->prepareStatement($sql);
			$statement->execute(array(
				$this->installation->getPackageID(),
				$this->instruction['value']
			));
		}
	}

作者:nick-stroh    项目:WC   
/**
  * @see	\wcf\system\package\plugin\IPackageInstallationPlugin::install()
  */
 public function install()
 {
     parent::install();
     $abbreviation = 'wcf';
     $path = '';
     if (isset($this->instruction['attributes']['application'])) {
         $abbreviation = $this->instruction['attributes']['application'];
     } else {
         if ($this->installation->getPackage()->isApplication) {
             $path = FileUtil::getRealPath(WCF_DIR . $this->installation->getPackage()->packageDir);
         }
     }
     if (empty($path)) {
         $dirConstant = strtoupper($abbreviation) . '_DIR';
         if (!defined($dirConstant)) {
             throw new SystemException("Cannot execute script-PIP, abbreviation '" . $abbreviation . "' is unknown");
         }
         $path = constant($dirConstant);
     }
     // reset WCF cache
     CacheHandler::getInstance()->flushAll();
     // run script
     $this->run($path . $this->instruction['value']);
     // delete script
     if (@unlink($path . $this->instruction['value'])) {
         // delete file log entry
         $sql = "DELETE FROM\twcf" . WCF_N . "_package_installation_file_log\n\t\t\t\tWHERE\t\tpackageID = ?\n\t\t\t\t\t\tAND filename = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($this->installation->getPackageID(), $this->instruction['value']));
     }
 }

作者:nick-stroh    项目:WC   
/**
  * @see	\wcf\system\importer\IImporter::import()
  */
 public function import($oldID, array $data, array $additionalData = array())
 {
     // check file location
     if (!@file_exists($additionalData['fileLocation'])) {
         return 0;
     }
     // get image size
     $imageData = @getimagesize($additionalData['fileLocation']);
     if ($imageData === false) {
         return 0;
     }
     $data['width'] = $imageData[0];
     $data['height'] = $imageData[1];
     // check min size
     if ($data['width'] < 48 || $data['height'] < 48) {
         return 0;
     }
     // check image type
     if ($imageData[2] != IMAGETYPE_GIF && $imageData[2] != IMAGETYPE_JPEG && $imageData[2] != IMAGETYPE_PNG) {
         return 0;
     }
     // get file hash
     if (empty($data['fileHash'])) {
         $data['fileHash'] = sha1_file($additionalData['fileLocation']);
     }
     // get user id
     $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
     if (!$data['userID']) {
         return 0;
     }
     // save avatar
     $avatar = UserAvatarEditor::create($data);
     // check avatar directory
     // and create subdirectory if necessary
     $dir = dirname($avatar->getLocation());
     if (!@file_exists($dir)) {
         FileUtil::makePath($dir, 0777);
     }
     // copy file
     try {
         if (!copy($additionalData['fileLocation'], $avatar->getLocation())) {
             throw new SystemException();
         }
         // create thumbnails
         $action = new UserAvatarAction(array($avatar), 'generateThumbnails');
         $action->executeAction();
         // update owner
         $sql = "UPDATE\twcf" . WCF_N . "_user\n\t\t\t\tSET\tavatarID = ?\n\t\t\t\tWHERE\tuserID = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($avatar->avatarID, $data['userID']));
         return $avatar->avatarID;
     } catch (SystemException $e) {
         // copy failed; delete avatar
         $editor = new UserAvatarEditor($avatar);
         $editor->delete();
     }
     return 0;
 }

作者:0xLeo    项目:WC   
/**
	 * Assigns a list of applications to a group and computes cookie domain and path.
	 */
	public function rebuild() {
		if (empty($this->objects)) {
			$this->readObjects();
		}
		
		$sql = "UPDATE	wcf".WCF_N."_application
			SET	cookieDomain = ?,
				cookiePath = ?
			WHERE	packageID = ?";
		$statement = WCF::getDB()->prepareStatement($sql);
		
		// calculate cookie path
		$domains = array();
		foreach ($this->objects as $application) {
			if (!isset($domains[$application->domainName])) {
				$domains[$application->domainName] = array();
			}
			
			$domains[$application->domainName][$application->packageID] = explode('/', FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash($application->domainPath)));
		}
		
		WCF::getDB()->beginTransaction();
		foreach ($domains as $domainName => $data) {
			$path = null;
			foreach ($data as $domainPath) {
				if ($path === null) {
					$path = $domainPath;
				}
				else {
					foreach ($path as $i => $part) {
						if (!isset($domainPath[$i]) || $domainPath[$i] != $part) {
							// remove all following elements including current one
							foreach ($path as $j => $innerPart) {
								if ($j >= $i) {
									unset($path[$j]);
								}
							}
							
							// skip to next domain
							continue 2;
						}
					}
				}
			}
			
			$path = FileUtil::addLeadingSlash(FileUtil::addTrailingSlash(implode('/', $path)));
			
			foreach (array_keys($data) as $packageID) {
				$statement->execute(array(
					$domainName,
					$path,
					$packageID
				));
			}
		}
		WCF::getDB()->commitTransaction();
	}

作者:knz    项目:Firebal   
/**
  * @see	\cms\system\content\type\IContentType::validate()
  */
 public function validate($data)
 {
     if (!isset($data['video'])) {
         throw new UserInputException('data[video]');
     }
     if (!FileUtil::isURL($data['video'])) {
         throw new UserInputException('data[video]', 'notValid');
     }
 }

作者:0xLeo    项目:WC   
/**
	 * Removes files matching given pattern.
	 * 
	 * @param	string		$pattern
	 */
	protected function removeFiles($pattern) {
		$directory = FileUtil::unifyDirSeperator(WCF_DIR.'cache/');
		$pattern = str_replace('*', '.*', str_replace('.', '\.', $pattern));
		
		DirectoryUtil::getInstance($directory)->executeCallback(new Callback(function ($filename) {
			if (!@touch($filename, 1)) {
				@unlink($filename);
			}
		}), new Regex('^'.$directory.$pattern.'$', Regex::CASE_INSENSITIVE));
	}

作者:ZerGabrie    项目:WC   
/**
  * Creates a new UploadHandler object.
  * 
  * @param	array<mixed>	$rawFileData
  */
 protected function __construct(array $rawFileData)
 {
     if (is_array($rawFileData['name'])) {
         // multiple uploads
         for ($i = 0, $l = count($rawFileData['name']); $i < $l; $i++) {
             $this->files[] = new UploadFile($rawFileData['name'][$i], $rawFileData['tmp_name'][$i], $rawFileData['size'][$i], $rawFileData['error'][$i], FileUtil::getMimeType($rawFileData['tmp_name'][$i]) ?: $rawFileData['type'][$i]);
         }
     } else {
         $this->files[] = new UploadFile($rawFileData['name'], $rawFileData['tmp_name'], $rawFileData['size'], $rawFileData['error'], FileUtil::getMimeType($rawFileData['tmp_name']) ?: $rawFileData['type']);
     }
 }

作者:ZerGabrie    项目:WC   
/**
  * @see	wcf\system\cache\source\ICacheSource::clear()
  */
 public function clear($directory, $filepattern)
 {
     $pattern = preg_quote(FileUtil::addTrailingSlash($directory), '%') . str_replace('*', '.*', str_replace('.', '\\.', $filepattern));
     $apcinfo = apc_cache_info('user');
     $cacheList = $apcinfo['cache_list'];
     foreach ($cacheList as $cache) {
         if (preg_match('%^' . $pattern . '$%i', $cache['info'])) {
             apc_delete($cache['info']);
         }
     }
 }

作者:ZerGabrie    项目:WC   
/**
  * Creates a new ActiveStyle object.
  * 
  * @param	Style	$object
  */
 public function __construct(Style $object)
 {
     parent::__construct($object);
     // calculate page logo path
     if (!empty($this->object->data['variables']['page.logo.image']) && !FileUtil::isURL($this->object->data['variables']['page.logo.image']) && StringUtil::substring($this->object->data['variables']['page.logo.image'], 0, 1) !== '/') {
         $this->object->data['variables']['page.logo.image'] = RELATIVE_WCF_DIR . $this->object->data['variables']['page.logo.image'];
     }
     // load icon cache
     $cacheName = 'icon-' . PACKAGE_ID . '-' . $this->styleID;
     CacheHandler::getInstance()->addResource($cacheName, WCF_DIR . 'cache/cache.' . $cacheName . '.php', 'wcf\\system\\cache\\builder\\IconCacheBuilder');
     $this->iconCache = CacheHandler::getInstance()->get($cacheName);
 }

作者:nick-stroh    项目:WC   
/**
  * Assigns a list of applications to a group and computes cookie domain and path.
  */
 public function rebuild()
 {
     if (empty($this->objects)) {
         $this->readObjects();
     }
     $sql = "UPDATE\twcf" . WCF_N . "_application\n\t\t\tSET\tcookieDomain = ?,\n\t\t\t\tcookiePath = ?\n\t\t\tWHERE\tpackageID = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     // calculate cookie path
     $domains = array();
     $regex = new Regex(':[0-9]+');
     foreach ($this->objects as $application) {
         $domainName = $application->domainName;
         if (StringUtil::endsWith($regex->replace($domainName, ''), $application->cookieDomain)) {
             $domainName = $application->cookieDomain;
         }
         if (!isset($domains[$domainName])) {
             $domains[$domainName] = array();
         }
         $domains[$domainName][$application->packageID] = explode('/', FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash($application->domainPath)));
     }
     WCF::getDB()->beginTransaction();
     foreach ($domains as $domainName => $data) {
         $path = null;
         foreach ($data as $domainPath) {
             if ($path === null) {
                 $path = $domainPath;
             } else {
                 foreach ($path as $i => $part) {
                     if (!isset($domainPath[$i]) || $domainPath[$i] != $part) {
                         // remove all following elements including current one
                         foreach ($path as $j => $innerPart) {
                             if ($j >= $i) {
                                 unset($path[$j]);
                             }
                         }
                         // skip to next domain
                         continue 2;
                     }
                 }
             }
         }
         $path = FileUtil::addLeadingSlash(FileUtil::addTrailingSlash(implode('/', $path)));
         foreach (array_keys($data) as $packageID) {
             $statement->execute(array($domainName, $path, $packageID));
         }
     }
     WCF::getDB()->commitTransaction();
     // rebuild templates
     LanguageFactory::getInstance()->deleteLanguageCache();
     // reset application cache
     ApplicationCacheBuilder::getInstance()->reset();
 }

作者:ZerGabrie    项目:WC   
/**
  * Deletes the folders of this template group.
  */
 public function deleteFolders()
 {
     // default template dir
     $folders = array(WCF_DIR . 'templates/' . $this->templateGroupFolderName);
     // get package dirs
     $sql = "SELECT\tpackageDir\n\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\tWHERE\tpackageDir <> ''";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute();
     while ($row = $statement->fetchArray()) {
         $packageDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']);
         DirectoryUtil::getInstance($packageDir . 'templates/' . $this->templateGroupFolderName)->deleteAll();
     }
 }

作者:nick-stroh    项目:WC   
/**
  * Writes the given e-mail in a log file.
  * 
  * @param	Mail	$mail
  */
 public function sendMail(Mail $mail)
 {
     if ($this->log === null) {
         $logFilePath = '';
         if (MAIL_DEBUG_LOGFILE_PATH) {
             $logFilePath = FileUtil::addTrailingSlash(MAIL_DEBUG_LOGFILE_PATH);
         } else {
             $logFilePath = WCF_DIR . 'log/';
         }
         $this->log = new File($logFilePath . 'mail.log', 'ab');
     }
     $this->log->write($this->printMail($mail));
 }


问题


面经


文章

微信
公众号

扫码关注公众号