本文整理汇总了PHP中FileUtil::getRelativePath方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil::getRelativePath方法的具体用法?PHP FileUtil::getRelativePath怎么用?PHP FileUtil::getRelativePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileUtil
的用法示例。
在下文中一共展示了FileUtil::getRelativePath方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getResources
/**
* Returns a list of WCFSetup resources.
*
* @return array<array>
*/
protected function getResources()
{
$cache = $this->getCache('wcfSetupResource', 'WcfSetupResource');
$resources = array(array('label' => '', 'path' => ''));
$sourceList = new SourceList();
$sourceList->sqlConditions = "source.sourceID IN (" . implode(',', WCF::getUser()->getAccessibleSourceIDs()) . ")";
$sourceList->sqlLimit = 0;
$sourceList->readObjects();
foreach ($sourceList->getObjects() as $source) {
if (!isset($cache[$source->sourceID])) {
continue;
}
foreach ($cache[$source->sourceID] as $resource) {
$resources[] = array('label' => $source->name . ' :: ' . FileUtil::getRelativePath($source->sourceDirectory, $resource), 'path' => $resource);
}
}
return $resources;
}
示例2: getData
/**
* @see CacheBuilder::getData()
*/
public function getData($cacheResource)
{
list($cache, $packageID, $styleID) = explode('-', $cacheResource['cache']);
$data = array();
// get active package
require_once WCF_DIR . 'lib/acp/package/Package.class.php';
$activePackage = new Package($packageID);
$activePackageDir = FileUtil::getRealPath(WCF_DIR . $activePackage->getDir());
// get package dirs
$packageDirs = array();
$sql = "SELECT\t\tDISTINCT packageDir\r\n\t\t\tFROM\t\twcf" . WCF_N . "_package_dependency dependency\r\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\r\n\t\t\tON\t\t(package.packageID = dependency.dependency)\r\n\t\t\tWHERE\t\tdependency.packageID = " . $packageID . "\r\n\t\t\t\t\tAND packageDir <> ''\r\n\t\t\tORDER BY\tpriority DESC";
$result = WCF::getDB()->sendQuery($sql);
while ($row = WCF::getDB()->fetchArray($result)) {
$packageDirs[] = FileUtil::getRealPath(WCF_DIR . $row['packageDir']);
}
$packageDirs[] = WCF_DIR;
// get style icon path
$iconDirs = array();
$sql = "SELECT\tvariableValue\r\n\t\t\tFROM\twcf" . WCF_N . "_style_variable\r\n\t\t\tWHERE\tstyleID = " . $styleID . "\r\n\t\t\t\tAND variableName = 'global.icons.location'";
$row = WCF::getDB()->getFirstRow($sql);
if (!empty($row['variableValue'])) {
$iconDirs[] = FileUtil::addTrailingSlash($row['variableValue']);
}
if (!in_array('icon/', $iconDirs)) {
$iconDirs[] = 'icon/';
}
// get icons
foreach ($packageDirs as $packageDir) {
$relativePackageDir = $activePackageDir != $packageDir ? FileUtil::getRelativePath($activePackageDir, $packageDir) : '';
foreach ($iconDirs as $iconDir) {
$path = FileUtil::addTrailingSlash($packageDir . $iconDir);
$icons = self::getIconFiles($path);
foreach ($icons as $icon) {
$icon = str_replace($path, '', $icon);
if (!isset($data[$icon])) {
$data[$icon] = $relativePackageDir . $iconDir . $icon;
}
}
}
}
return $data;
}
示例3: promptPackageDir
/**
* Prompts for installation directory.
*
* @return string package dir
*/
protected function promptPackageDir()
{
$packageDir = $errorField = $errorType = '';
if (isset($_POST['send'])) {
if (isset($_POST['packageDir'])) {
$packageDir = StringUtil::trim($_POST['packageDir']);
}
// error handling
try {
$dir = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator($packageDir));
// package can not be installed into the wcf directory
if (FileUtil::unifyDirSeperator(WCF_DIR) == $dir) {
throw new UserInputException('packageDir', 'wcfDirLocked');
}
// this package is a standalone package and needs its own package directory
$relativePackageDir = FileUtil::getRelativePath(WCF_DIR, $dir);
$sql = "SELECT \tCOUNT(*) AS count\n\t\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t\tWHERE\tpackageDir = '" . escapeString($relativePackageDir) . "'";
$alreadyInstalled = WCF::getDB()->getFirstRow($sql);
if ($alreadyInstalled['count'] > 0) {
throw new UserInputException('packageDir', 'alreadyInstalled');
}
// check writing property
if (@file_exists($dir) && !@is_writable($dir)) {
throw new UserInputException('packageDir', 'notWritable');
}
return $relativePackageDir;
} catch (UserInputException $e) {
$errorField = $e->getField();
$errorType = $e->getType();
}
} else {
// make default dir
//$packageNameParts = explode('.', $this->installation->getPackage()->getPackage());
//$packageDir = FileUtil::getRealPath(WCF_DIR.'../'.$packageNameParts[count($packageNameParts) - 1]);
$packageDir = FileUtil::getRealPath(WCF_DIR . '../');
}
// domain
$domainName = '';
if (!empty($_SERVER['SERVER_NAME'])) {
$domainName = 'http://' . $_SERVER['SERVER_NAME'];
}
// port
if (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) {
$domainName .= ':' . $_SERVER['SERVER_PORT'];
}
// wcf url
$wcfUrl = '';
if (!empty($_SERVER['REQUEST_URI'])) {
$wcfUrl = FileUtil::removeTrailingSlash(FileUtil::getRealPath(FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash(dirname($_SERVER['REQUEST_URI']))) . '/' . RELATIVE_WCF_DIR));
}
WCF::getTPL()->assign(array('packageDir' => $packageDir, 'errorField' => $errorField, 'errorType' => $errorType, 'domainName' => $domainName, 'wcfUrl' => $wcfUrl, 'wcfDir' => FileUtil::unifyDirSeperator(WCF_DIR)));
WCF::getTPL()->display('packageInstallationPromptPackageDir');
exit;
}
示例4: getWCFDir
/**
* Gets the selected wcf dir from request.
*/
protected static function getWCFDir()
{
if (isset($_REQUEST['wcfDir']) && $_REQUEST['wcfDir'] != '') {
self::$wcfDir = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator($_REQUEST['wcfDir']));
if (@file_exists(self::$wcfDir)) {
define('RELATIVE_WCF_DIR', FileUtil::getRelativePath(INSTALL_SCRIPT_DIR, self::$wcfDir));
}
}
define('WCF_DIR', self::$wcfDir);
}
示例5: getRelativePath
protected static function getRelativePath($baseSourceID, $targetSourceID, $path)
{
$basePath = self::$sources[$baseSourceID]->sourceDirectory;
$targetPath = FileUtil::getRealPath(FileUtil::addTrailingSlash(self::$sources[$targetSourceID]->sourceDirectory) . $path);
$relativePath = FileUtil::getRelativePath($basePath, $targetPath);
return FileUtil::getRealPath($relativePath);
}
示例6: fetchPackage
/**
* Reads a package.
*
* @param string $packageHash
* @param string $packageName
* @param string $minVersion
*/
protected function fetchPackage($packageHash, $packageName, $minVersion = '')
{
// try to find requested package
if (!isset($this->cachedPackages['packages'][$packageHash])) {
$this->errors[$packageHash] = array('message' => 'notFound', 'packageName' => $packageName);
return;
}
$cachedPackage = $this->cachedPackages['packages'][$packageHash];
if (!empty($minVersion)) {
if (version_compare($minVersion, $cachedPackage['version'], '>')) {
$this->errors[$packageHash] = array('message' => 'insufficientVersion', 'packageName' => $packageName);
return;
}
}
// ignore duplicate entries
if (isset($this->packages[$packageName]['directories'][$cachedPackage['directory']])) {
return;
}
// add current package
$this->packages[$packageName]['hash'] = $packageHash;
if (isset($cachedPackage['source'])) {
$directory = FileUtil::getRelativePath($this->source->sourceDirectory, $cachedPackage['source']->sourceDirectory);
$directoryShown = $cachedPackage['source']->name . ' :: ' . str_replace($directory, '', $cachedPackage['directory']);
} else {
$directoryShown = $this->source->name . '::' . $cachedPackage['directory'];
}
$this->packages[$packageName]['directories'][$cachedPackage['directory']] = array('directoryShown' => $directoryShown, 'version' => $cachedPackage['version']);
$this->fetchDependencies($packageHash);
}
示例7: writeConfigFile
/**
* Writes the config.inc.php for a standalone application.
*
* @param integer $packageID
*/
public static function writeConfigFile($packageID)
{
$package = new Package($packageID);
$packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $package->getDir()));
$file = new File($packageDir . PackageInstallation::CONFIG_FILE);
$file->write("<?php\n");
$currentPrefix = strtoupper($package->getAbbreviation());
// get dependencies (only standalones)
$sql = "SELECT\t\tpackage.*, IF(package.packageID = " . $packageID . ", 1, 0) AS sortOrder\n\t\t\tFROM\t\twcf" . WCF_N . "_package_dependency package_dependency\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\tON\t\t(package.packageID = package_dependency.dependency)\n\t\t\tWHERE\t\tpackage_dependency.packageID = " . $packageID . "\n\t\t\t\t\tAND package.standalone = 1\n\t\t\t\t\tAND package.packageDir <> ''\n\t\t\tORDER BY\tsortOrder DESC,\n\t\t\t\t\tpackage_dependency.priority DESC";
$result = WCF::getDB()->sendQuery($sql);
while ($row = WCF::getDB()->fetchArray($result)) {
$dependency = new Package(null, $row);
$dependencyDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $dependency->getDir()));
$prefix = strtoupper($dependency->getAbbreviation());
$file->write("// " . $dependency->getPackage() . " vars\n");
$file->write("// " . strtolower($prefix) . "\n");
$file->write("if (!defined('" . $prefix . "_DIR')) define('" . $prefix . "_DIR', " . ($dependency->getPackageID() == $package->getPackageID() ? "dirname(__FILE__).'/'" : "'" . $dependencyDir . "'") . ");\n");
$file->write("if (!defined('RELATIVE_" . $prefix . "_DIR')) define('RELATIVE_" . $prefix . "_DIR', " . ($dependency->getPackageID() == $package->getPackageID() ? "''" : "RELATIVE_" . $currentPrefix . "_DIR.'" . FileUtil::getRelativePath($packageDir, $dependencyDir) . "'") . ");\n");
$file->write("if (!defined('" . $prefix . "_N')) define('" . $prefix . "_N', '" . WCF_N . "_" . $dependency->getInstanceNo() . "');\n");
$file->write("\$packageDirs[] = " . $prefix . "_DIR;\n");
$file->write("\n");
}
// write general information
$file->write("// general info\n");
$file->write("if (!defined('RELATIVE_WCF_DIR'))\tdefine('RELATIVE_WCF_DIR', RELATIVE_" . $currentPrefix . "_DIR.'" . FileUtil::getRelativePath($packageDir, WCF_DIR) . "');\n");
$file->write("if (!defined('PACKAGE_ID')) define('PACKAGE_ID', " . $package->getPackageID() . ");\n");
$file->write("if (!defined('PACKAGE_NAME')) define('PACKAGE_NAME', '" . str_replace("'", "\\'", $package->getName()) . "');\n");
$file->write("if (!defined('PACKAGE_VERSION')) define('PACKAGE_VERSION', '" . $package->getVersion() . "');\n");
// write end
$file->write("?>");
$file->close();
}