本文整理汇总了PHP中wcf\util\FileUtil::unifyDirSeperator方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil::unifyDirSeperator方法的具体用法?PHP FileUtil::unifyDirSeperator怎么用?PHP FileUtil::unifyDirSeperator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wcf\util\FileUtil
的用法示例。
在下文中一共展示了FileUtil::unifyDirSeperator方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: removeFiles
/**
* 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));
}
示例2: uninstall
/**
* Uninstalls the files of this package.
*/
public function uninstall()
{
// get absolute package dir
$packageDir = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator(realpath(WCF_DIR . $this->installation->getPackage()->packageDir)));
// create file list
$files = array();
// get files from log
$sql = "SELECT\t*\n\t\t\tFROM\twcf" . WCF_N . "_package_installation_file_log\n\t\t\tWHERE \tpackageID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($this->installation->getPackageID()));
while ($row = $statement->fetchArray()) {
$files[] = $row['filename'];
}
if (count($files) > 0) {
// delete files
$this->installation->deleteFiles($packageDir, $files);
// delete log entries
parent::uninstall();
}
}
示例3: promptPackageDir
/**
* Prompts for a text input for package directory (applies for applications only)
*
* @return wcf\system\form\FormDocument
*/
protected function promptPackageDir() {
if (!PackageInstallationFormManager::findForm($this->queue, 'packageDir')) {
$container = new GroupFormElementContainer();
$packageDir = new TextInputFormElement($container);
$packageDir->setName('packageDir');
$packageDir->setLabel(WCF::getLanguage()->get('wcf.acp.package.packageDir.input'));
$path = RouteHandler::getPath(array('wcf', 'acp'));
$defaultPath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator($_SERVER['DOCUMENT_ROOT'] . $path));
$packageDir->setValue($defaultPath);
$container->appendChild($packageDir);
$document = new FormDocument('packageDir');
$document->appendContainer($container);
PackageInstallationFormManager::registerForm($this->queue, $document);
return $document;
}
else {
$document = PackageInstallationFormManager::getForm($this->queue, 'packageDir');
$document->handleRequest();
$packageDir = $document->getValue('packageDir');
if ($packageDir !== null) {
// validate package dir
if (file_exists(FileUtil::addTrailingSlash($packageDir) . 'global.php')) {
$document->setError('packageDir', WCF::getLanguage()->get('wcf.acp.package.packageDir.notAvailable'));
return $document;
}
// set package dir
$packageEditor = new PackageEditor($this->getPackage());
$packageEditor->update(array(
'packageDir' => FileUtil::getRelativePath(WCF_DIR, $packageDir)
));
// parse domain path
$domainPath = FileUtil::getRelativePath(FileUtil::unifyDirSeperator($_SERVER['DOCUMENT_ROOT']), FileUtil::unifyDirSeperator($packageDir));
// work-around for applications installed in document root
if ($domainPath == './') {
$domainPath = '';
}
$domainPath = FileUtil::addLeadingSlash(FileUtil::addTrailingSlash($domainPath));
// update application path
$application = new Application($this->getPackage()->packageID);
$applicationEditor = new ApplicationEditor($application);
$applicationEditor->update(array(
'domainPath' => $domainPath,
'cookiePath' => $domainPath
));
// create directory and set permissions
@mkdir($packageDir, 0777, true);
@chmod($packageDir, 0777);
}
return null;
}
}
示例4: redirect
/**
* Redirects the user agent.
*
* @param string $location
* @param boolean $prependDir
* @param boolean $sendStatusCode
*/
public static function redirect($location, $prependDir = true, $sendStatusCode = false)
{
if ($prependDir) {
// remove path info from request URI
$requestURI = WCF::getSession()->requestURI;
if (($pos = strpos($requestURI, '.php')) !== false) {
$requestURI = substr($requestURI, 0, $pos + 4);
}
$location = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator(dirname($requestURI))) . $location;
}
//if ($sendStatusCode) @header('HTTP/1.0 301 Moved Permanently');
if ($sendStatusCode) {
@header('HTTP/1.1 307 Temporary Redirect');
}
header('Location: ' . $location);
}
示例5: getRequestURI
/**
* Returns the request uri of the active request.
*
* @return string
*/
public static function getRequestURI() {
$REQUEST_URI = '';
$appendQueryString = true;
if (!empty($_SERVER['ORIG_PATH_INFO']) && strpos($_SERVER['ORIG_PATH_INFO'], '.php') !== false) {
$REQUEST_URI = $_SERVER['ORIG_PATH_INFO'];
}
else if (!empty($_SERVER['ORIG_SCRIPT_NAME'])) {
$REQUEST_URI = $_SERVER['ORIG_SCRIPT_NAME'];
}
else if (!empty($_SERVER['SCRIPT_NAME']) && (isset($_SERVER['PATH_INFO']) && !empty($_SERVER['PATH_INFO']))) {
$REQUEST_URI = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
}
else if (isset($_SERVER['REQUEST_URI']) && !empty($_SERVER['REQUEST_URI'])) {
$REQUEST_URI = $_SERVER['REQUEST_URI'];
$appendQueryString = false;
}
else if (!empty($_SERVER['PHP_SELF'])) {
$REQUEST_URI = $_SERVER['PHP_SELF'];
}
else if (!empty($_SERVER['PATH_INFO'])) {
$REQUEST_URI = $_SERVER['PATH_INFO'];
}
if ($appendQueryString && !empty($_SERVER['QUERY_STRING'])) {
$REQUEST_URI .= '?'.$_SERVER['QUERY_STRING'];
}
// fix encoding
if (!StringUtil::isASCII($REQUEST_URI) && !StringUtil::isUTF8($REQUEST_URI)) {
$REQUEST_URI = StringUtil::convertEncoding('ISO-8859-1', 'UTF-8', $REQUEST_URI);
}
return StringUtil::substring(FileUtil::unifyDirSeperator($REQUEST_URI), 0, 255);
}
示例6: scanFileObjects
/**
* Fills the list of available files, with DirectoryIterator object as value
*/
protected function scanFileObjects()
{
// value is cached
if (!empty($this->fileObjects)) {
return;
}
if ($this->recursive) {
$it = new \RecursiveIteratorIterator($this->obj, \RecursiveIteratorIterator::CHILD_FIRST);
foreach ($it as $filename => $obj) {
// ignore . and ..
if ($it->isDot()) {
continue;
}
$this->fileObjects[FileUtil::unifyDirSeperator($filename)] = $obj;
}
} else {
foreach ($this->obj as $obj) {
// ignore . and ..
if ($this->obj->isDot()) {
continue;
}
$this->fileObjects[FileUtil::unifyDirSeperator($obj->getFilename())] = $obj;
}
}
// add the directory itself
$this->fileObjects[$this->directory] = new \SPLFileInfo($this->directory);
}
示例7: export
//.........这里部分代码省略.........
// append templates to tar
// get templates
$sql = "SELECT template.*, package.package, package.packageDir
FROM wcf".WCF_N."_template template
LEFT JOIN wcf".WCF_N."_package package
ON (package.packageID = template.packageID)
WHERE template.templateGroupID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($this->templateGroupID));
while ($row = $statement->fetchArray()) {
$packageDir = 'com.woltlab.wcf';
if (!empty($row['packageDir'])) $packageDir = $row['package'];
$filename = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $row['packageDir'] . 'templates/' . $templateGroup->templateGroupFolderName)) . $row['templateName'] . '.tpl';
$templatesTar->add($filename, $packageDir, dirname($filename));
}
// append templates tar to style tar
$templatesTar->create();
$styleTar->add($templatesTarName, 'templates.tar', $templatesTarName);
@unlink($templatesTarName);
}
if ($images && ($this->imagePath && $this->imagePath != 'images/')) {
// create images tar
$imagesTarName = FileUtil::getTemporaryFilename('images_', '.tar');
$imagesTar = new TarWriter($imagesTarName);
@chmod($imagesTarName, 0777);
// append images to tar
$path = FileUtil::addTrailingSlash(WCF_DIR.$this->imagePath);
if (file_exists($path) && is_dir($path)) {
$handle = opendir($path);
$regEx = new Regex('\.(jpg|jpeg|gif|png|svg)$', Regex::CASE_INSENSITIVE);
while (($file = readdir($handle)) !== false) {
if (is_file($path.$file) && $regEx->match($file)) {
$imagesTar->add($path.$file, '', $path);
}
}
}
// append images tar to style tar
$imagesTar->create();
$styleTar->add($imagesTarName, 'images.tar', $imagesTarName);
@unlink($imagesTarName);
}
// output file content
$styleTar->create();
// export as style package
if (empty($packageName)) {
readfile($styleTarName);
}
else {
// export as package
// create package tar
$packageTarName = FileUtil::getTemporaryFilename('package_', '.tar.gz');
$packageTar = new TarWriter($packageTarName, true);
// append style tar
$styleTarName = FileUtil::unifyDirSeperator($styleTarName);
$packageTar->add($styleTarName, '', FileUtil::addTrailingSlash(dirname($styleTarName)));
// create package.xml
$xml->beginDocument('package', 'http://www.woltlab.com', 'http://www.woltlab.com/XSD/maelstrom/package.xsd', array('name' => $packageName));
$xml->startElement('packageinformation');
$xml->writeElement('packagename', $this->styleName);
// description
foreach ($styleDescriptions as $languageCode => $value) {
$xml->writeElement('packagedescription', $value, array('language' => $languageCode));
}
$xml->writeElement('version', $this->styleVersion);
$xml->writeElement('date', $this->styleDate);
$xml->endElement();
$xml->startElement('authorinformation');
$xml->writeElement('author', $this->authorName);
if ($this->authorURL) $xml->writeElement('authorurl', $this->authorURL);
$xml->endElement();
$xml->startElement('instructions', array('type' => 'install'));
$xml->writeElement('instruction', basename($styleTarName), array('type' => 'style'));
$xml->endElement();
// append package info file to package tar
$packageTar->addString(PackageArchive::INFO_FILE, $xml->endDocument());
$packageTar->create();
readfile($packageTarName);
@unlink($packageTarName);
}
@unlink($styleTarName);
}
示例8: validate
/**
* @see wcf\form\IForm::validate()
*/
public function validate() {
parent::validate();
if (empty($this->authorName)) {
throw new UserInputException('authorName');
}
// validate date
if (empty($this->styleDate)) {
throw new UserInputException('styleDate');
}
else {
try {
DateUtil::validateDate($this->styleDate);
}
catch (SystemException $e) {
throw new UserInputException('styleDate', 'notValid');
}
}
if (empty($this->styleName)) {
throw new UserInputException('styleName');
}
// validate version
if (empty($this->styleVersion)) {
throw new UserInputException('styleVersion');
}
else if (!Package::isValidVersion($this->styleVersion)) {
throw new UserInputException('styleVersion', 'notValid');
}
// validate style description
if (!I18nHandler::getInstance()->validateValue('styleDescription', true, true)) {
throw new UserInputException('styleDescription');
}
// validate template group id
if ($this->templateGroupID) {
if (!isset($this->availableTemplateGroups[$this->templateGroupID])) {
throw new UserInputException('templateGroupID');
}
}
// ensure image path is below WCF_DIR/images/
if ($this->imagePath) {
$relativePath = FileUtil::unifyDirSeperator(FileUtil::getRelativePath(WCF_DIR.'images/', WCF_DIR.$this->imagePath));
if (strpos($relativePath, '../') !== false) {
throw new UserInputException('imagePath', 'notValid');
}
}
if (!empty($this->variables['overrideLess'])) {
$this->parseOverrides();
}
}
示例9: getInstalledFiles
/**
* Scans the given dir for installed files.
*
* @param string $dir
*/
protected function getInstalledFiles($dir)
{
if ($files = glob($dir . '*')) {
foreach ($files as $file) {
if (is_dir($file)) {
$this->getInstalledFiles(FileUtil::addTrailingSlash($file));
} else {
self::$installedFiles[] = FileUtil::unifyDirSeperator($file);
}
}
}
}
示例10: readData
/**
* @see wcf\page\IPage::readData()
*/
public function readData() {
parent::readData();
// init cache data
$this->cacheData = array(
'source' => get_class(CacheHandler::getInstance()->getCacheSource()),
'version' => '',
'size' => 0,
'files' => 0
);
switch ($this->cacheData['source']) {
case 'wcf\system\cache\source\DiskCacheSource':
// set version
$this->cacheData['version'] = WCF_VERSION;
// get package dirs
$sql = "SELECT packageDir
FROM wcf".WCF_N."_package
WHERE isApplication = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array(1));
while ($row = $statement->fetchArray()) {
$packageDir = FileUtil::getRealPath(WCF_DIR.$row['packageDir']);
$this->readCacheFiles('data', $packageDir.'cache');
}
break;
case 'wcf\system\cache\source\MemcachedCacheSource':
// set version
$this->cacheData['version'] = WCF_VERSION;
// get package dirs
$sql = "SELECT packageDir
FROM wcf".WCF_N."_package
WHERE isApplication = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array(1));
while ($row = $statement->fetchArray()) {
$packageDir = FileUtil::getRealPath(WCF_DIR.$row['packageDir']);
$this->readCacheFiles('data', $packageDir.'cache');
}
break;
case 'wcf\system\cache\source\ApcCacheSource':
// set version
$this->cacheData['version'] = phpversion('apc');
// get package dirs
$sql = "SELECT packageDir, packageName
FROM wcf".WCF_N."_package
WHERE isApplication = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array(1));
$packageNames = array();
while ($row = $statement->fetchArray()) {
$packagePath = FileUtil::getRealPath(WCF_DIR.$row['packageDir']).'cache/';
$packageNames[$packagePath] = $row['packageName'];
}
$apcinfo = apc_cache_info('user');
$cacheList = $apcinfo['cache_list'];
foreach ($cacheList as $cache) {
$cachePath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator(dirname($cache['info'])));
if (isset($packageNames[$cachePath])) {
// Use the packageName + the instance number, because pathes could confuse the administrator.
// He could think this is a file cache. If instanceName would be unique, we could use it instead.
$packageName = $packageNames[$cachePath];
if (!isset($this->caches['data'])) {
$this->caches['data'] = array();
}
if (!isset($this->caches['data'][$packageName])) {
$this->caches['data'][$packageName] = array();
}
// get additional cache information
$this->caches['data'][$packageName][] = array(
'filename' => basename($cache['info'], '.php'),
'filesize' => $cache['mem_size'],
'mtime' => $cache['mtime'],
);
$this->cacheData['files']++;
$this->cacheData['size'] += $cache['mem_size'];
}
}
break;
case 'wcf\system\cache\source\NoCacheSource':
$this->cacheData['version'] = WCF_VERSION;
$this->cacheData['files'] = $this->cacheData['size'] = 0;
break;
}
$this->readCacheFiles('language', FileUtil::unifyDirSeperator(WCF_DIR.'language'));
$this->readCacheFiles('template', FileUtil::unifyDirSeperator(WCF_DIR.'templates/compiled'), new Regex('\.meta\.php$'));
//.........这里部分代码省略.........
示例11: addFile
/**
* Adds a file to the tar archive.
*
* @param string $filename
* @param string $addDir
* @param string $removeDir
* @return boolean result
*/
protected function addFile($filename, $addDir, $removeDir) {
$filename = FileUtil::unifyDirSeperator($filename);
$storedFilename = $filename;
if (!empty($removeDir)) $storedFilename = StringUtil::replaceIgnoreCase($removeDir, '', $filename);
if (!empty($addDir)) $storedFilename = $addDir . $storedFilename;
if (is_file($filename)) {
// open file
$file = new File($filename, 'rb');
// write header
if (!$this->writeFileHeader($filename, $storedFilename)) {
return false;
}
// write file content
while (($buffer = $file->read(512)) != '') {
$this->file->write(pack('a512', $buffer));
}
// close file
$file->close();
}
else {
// only directory header
if (!$this->writeFileHeader($filename, $storedFilename)) {
return false;
}
}
return true;
}
示例12: readData
/**
* @see wcf\page\IPage::readData()
*/
public function readData()
{
parent::readData();
// init cache data
$this->cacheData = array('source' => get_class(CacheHandler::getInstance()->getCacheSource()), 'version' => '', 'size' => 0, 'files' => 0);
$_this = $this;
$readFileCache = function ($cacheDir, Regex $ignore = null) use($_this) {
$_this->caches[$cacheDir] = array();
// get files in cache directory
try {
$directoryUtil = DirectoryUtil::getInstance($cacheDir);
} catch (SystemException $e) {
return;
}
$files = $directoryUtil->getFileObjects(SORT_ASC, new Regex('\\.php$'));
// get additional file information
if (is_array($files)) {
foreach ($files as $file) {
if ($ignore !== null) {
if ($ignore->match($file)) {
continue;
}
}
$_this->caches[$cacheDir][] = array('filename' => $file->getBasename(), 'filesize' => $file->getSize(), 'mtime' => $file->getMtime(), 'perm' => substr(sprintf('%o', $file->getPerms()), -3), 'writable' => $file->isWritable());
$_this->cacheData['files']++;
$_this->cacheData['size'] += $file->getSize();
}
}
};
// filesystem cache
if ($this->cacheData['source'] == 'wcf\\system\\cache\\source\\DiskCacheSource') {
// set version
$this->cacheData['version'] = WCF_VERSION;
$conditions = new PreparedStatementConditionBuilder();
$conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies()));
$conditions->add("isApplication = ?", array(1));
// get package dirs
$sql = "SELECT\tpackageDir\n\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t" . $conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
while ($row = $statement->fetchArray()) {
$packageDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']);
$readFileCache($packageDir . 'cache');
}
} else {
if ($this->cacheData['source'] == 'wcf\\system\\cache\\source\\MemcacheCacheSource') {
// get version
$this->cacheData['version'] = MemcacheAdapter::getInstance()->getMemcache()->getVersion();
// get stats
$stats = MemcacheAdapter::getInstance()->getMemcache()->getStats();
$this->cacheData['files'] = $stats['curr_items'];
$this->cacheData['size'] = $stats['bytes'];
} else {
if ($this->cacheData['source'] == 'wcf\\system\\cache\\source\\ApcCacheSource') {
// set version
$this->cacheData['version'] = phpversion('apc');
$conditions = new PreparedStatementConditionBuilder();
$conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies()));
$conditions->add("isApplication = ?", array(1));
// get package dirs
$sql = "SELECT\tpackageDir, packageName, instanceNo\n\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t" . $conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
$packageNames = array();
while ($row = $statement->fetchArray()) {
$packagePath = FileUtil::getRealPath(WCF_DIR . $row['packageDir']) . 'cache/';
$packageNames[$packagePath] = $row['packageName'] . ' #' . $row['instanceNo'];
}
$apcinfo = apc_cache_info('user');
$cacheList = $apcinfo['cache_list'];
foreach ($cacheList as $cache) {
$cachePath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator(dirname($cache['info'])));
if (isset($packageNames[$cachePath])) {
// Use the packageName + the instance number, because pathes could confuse the administrator.
// He could think this is a file cache. If instanceName would be unique, we could use it instead.
$packageName = $packageNames[$cachePath];
if (!isset($this->caches[$packageName])) {
$this->caches[$packageName] = array();
}
// get additional cache information
$this->caches[$packageName][] = array('filename' => basename($cache['info'], '.php'), 'filesize' => $cache['mem_size'], 'mtime' => $cache['mtime']);
$this->cacheData['files']++;
$this->cacheData['size'] += $cache['mem_size'];
}
}
} else {
if ($this->cacheData['source'] == 'wcf\\system\\cache\\source\\NoCacheSource') {
$this->cacheData['version'] = WCF_VERSION;
$this->cacheData['files'] = $this->cacheData['size'] = 0;
}
}
}
}
$readFileCache(WCF_DIR . 'language');
$readFileCache(WCF_DIR . 'templates/compiled', new Regex('\\.meta\\.php$'));
$readFileCache(WCF_DIR . 'acp/templates/compiled', new Regex('\\.meta\\.php$'));
}
示例13: clear
/**
* @see wcf\system\cache\source\ICacheSource::clear()
*/
public function clear($directory, $filepattern)
{
// unify parameters
$directory = FileUtil::unifyDirSeperator($directory);
$filepattern = FileUtil::unifyDirSeperator($filepattern);
$filepattern = str_replace('*', '.*', str_replace('.', '\\.', $filepattern));
if (substr($directory, -1) != '/') {
$directory .= '/';
}
DirectoryUtil::getInstance($directory)->executeCallback(new Callback(function ($filename) {
if (!@touch($filename, 1)) {
@unlink($filename);
}
}), new Regex('^' . $directory . $filepattern . '$', Regex::CASE_INSENSITIVE));
}
示例14: getIconFiles
protected static function getIconFiles($path, $extension = 'svg')
{
$files = array();
if (is_dir($path)) {
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
foreach ($iterator as $file) {
if (preg_match('/\\.' . $extension . '$/', $file->getFilename())) {
$files[] = FileUtil::unifyDirSeperator($file->getPathname());
}
}
}
return $files;
}