28 if (!is_string($path) || ($path ==
""))
32 static $pattern =
null, $tailPattern;
35 if(strncasecmp(PHP_OS,
"WIN", 3) == 0)
38 $pattern =
"'[\\\\/]+'";
39 $tailPattern =
"\0.\\/+ ";
48 $pathTmp = preg_replace($pattern,
"/", $path);
50 if (strpos($pathTmp,
"\0") !==
false)
53 if (preg_match(
"#(^|/)(\\.|\\.\\.)(/|\$)#", $pathTmp))
55 $arPathTmp = explode(
'/', $pathTmp);
56 $arPathStack = array();
57 foreach ($arPathTmp as $i => $pathPart)
59 if ($pathPart ===
'.')
62 if ($pathPart ===
"..")
64 if (array_pop($arPathStack) ===
null)
69 array_push($arPathStack, $pathPart);
72 $pathTmp = implode(
"/", $arPathStack);
75 $pathTmp = rtrim($pathTmp, $tailPattern);
77 if (mb_substr($path, 0, 1) ===
"/" && mb_substr($pathTmp, 0, 1) !==
"/")
78 $pathTmp =
"/".$pathTmp;
91 $pos = Text\UtfSafeString::getLastPosition($path,
'.');
93 return mb_substr($path, $pos + 1);
102 $p = Text\UtfSafeString::getLastPosition($path, self::DIRECTORY_SEPARATOR);
104 return mb_substr($path, $p + 1);
111 return mb_substr($path, 0, -mb_strlen(self::getName($path)) - 1);
116 if (self::$physicalEncoding ==
"")
119 if (self::$logicalEncoding ==
"")
122 if (self::$physicalEncoding == self::$logicalEncoding)
125 return Text\Encoding::convertEncoding($path, self::$logicalEncoding, self::$physicalEncoding);
130 if (self::$physicalEncoding ==
"")
133 if (self::$logicalEncoding ==
"")
136 if (self::$physicalEncoding == self::$logicalEncoding)
139 return Text\Encoding::convertEncoding($path, self::$physicalEncoding, self::$logicalEncoding);
144 if (self::$logicalEncoding ==
"")
147 if (self::$directoryIndex ==
null)
150 if (isset(self::$directoryIndex[self::getName($path)]))
153 if (
'utf-8' !== self::$logicalEncoding)
154 $path = Text\Encoding::convertEncoding($path, self::$logicalEncoding,
'utf-8');
156 return implode(
'/', array_map(
"rawurlencode", explode(
'/', $path)));
161 if (self::$physicalEncoding ==
"")
164 if (self::$directoryIndex ==
null)
167 if (isset(self::$directoryIndex[self::getName($path)]))
170 if (
'utf-8' !== self::$physicalEncoding)
171 $path = Text\Encoding::convertEncoding($path, self::$physicalEncoding,
'utf-8');
173 return implode(
'/', array_map(
"rawurlencode", explode(
'/', $path)));
178 if (self::$physicalEncoding ==
"")
181 if (self::$directoryIndex ==
null)
184 $path = implode(
'/', array_map(
"rawurldecode", explode(
'/', $path)));
186 if (
'utf-8' !== self::$physicalEncoding)
187 $path = Text\Encoding::convertEncoding($path,
'utf-8', self::$physicalEncoding);
194 if (defined(
'BX_UTF'))
196 elseif (defined(
"SITE_CHARSET") && (SITE_CHARSET <>
''))
198 elseif (defined(
"LANG_CHARSET") && (LANG_CHARSET <>
''))
200 elseif (defined(
"BX_DEFAULT_CHARSET"))
210 $physicalEncoding = defined(
"BX_FILE_SYSTEM_ENCODING") ? BX_FILE_SYSTEM_ENCODING :
"";
213 if (mb_strtoupper(mb_substr(PHP_OS, 0, 3)) ===
"WIN")
223 $numArgs = func_num_args();
228 for ($i = 0; $i < $numArgs; $i++)
230 $arg = func_get_arg($i);
238 if (!is_string($v) || $v ==
"")
243 elseif (is_string($arg))
253 foreach ($arParts as $part)
267 if (!is_string($relativePath))
269 if ($relativePath ==
"")
272 return self::combine($_SERVER[
"DOCUMENT_ROOT"], $relativePath);
277 if (!is_string($relativePath) || $relativePath ==
"")
280 $basePath = Main\SiteTable::getDocumentRoot($site);
287 if (!is_string($path))
292 if (trim($path) ==
"")
297 if (strpos($path,
"\0") !==
false)
302 if(preg_match(
"#(".self::INVALID_FILENAME_BYTES.
")#", $path))
312 if(!static::validateCommon($path))
317 return (preg_match(
"#^([a-z]:)?/([^\x01-\x1F".preg_quote(self::INVALID_FILENAME_CHARS,
"#").
"]+/?)*$#isD", $path) > 0);
322 if(!static::validateCommon($filename))
327 return (preg_match(
"#^[^\x01-\x1F".preg_quote(self::INVALID_FILENAME_CHARS,
"#").
"]+$#isD", $filename) > 0);
337 return preg_replace_callback(
338 "#([\x01-\x1F".preg_quote(self::INVALID_FILENAME_CHARS,
"#").
"]|".self::INVALID_FILENAME_BYTES.
")#",
350 return static::replaceInvalidFilename($filename,
353 return chr(rand(97, 122));
360 return (mb_substr($path, 0, 1) ===
"/") || preg_match(
"#^[a-z]:/#i", $path);
365 static $directoryIndexDefault = array(
"index.php" => 1,
"index.html" => 1,
"index.htm" => 1,
"index.phtml" => 1,
"default.html" => 1,
"index.php3" => 1);
367 $directoryIndex = Main\Config\Configuration::getValue(
"directory_index");
371 return $directoryIndexDefault;
static convertUriToPhysical($path)
static convertPhysicalToLogical($path)
static randomizeInvalidFilename($filename)
static validateCommon($path)
static getLogicalEncoding()
static convertRelativeToAbsolute($relativePath)
const DIRECTORY_SEPARATOR
static convertPhysicalToUri($path)
static getPhysicalEncoding()
static convertLogicalToPhysical($path)
static convertLogicalToUri($path)
static convertSiteRelativeToAbsolute($relativePath, $site=null)
static getDirectory($path)
const INVALID_FILENAME_BYTES
static getExtension($path)
static validateFilename($filename)
const INVALID_FILENAME_CHARS
static getDirectoryIndexArray()
static replaceInvalidFilename($filename, $callback)
const DIRECTORY_SEPARATOR_ALT