16 public static function tidy(
string $path): string
18 $modifier = Translate\Config::isUtfMode() ?
'u' :
'';
20 return \preg_replace(
"#[\\\\\\/]+#".$modifier, self::DIRECTORY_SEPARATOR, $path);
30 public static function secure(
string $path): string
32 $modifier = Translate\Config::isUtfMode() ?
'u' :
'';
34 return \preg_replace(
"#\.\.+[\/\\\]+#i".$modifier,
'', $path);
45 public static function isLangDir(
string $path,
bool $additionalCheck =
false): bool
47 $modifier = Translate\Config::isUtfMode() ?
'u' :
'';
48 if (\preg_match(
"#/lang/([^/]*?)(/|\$)#".$modifier, $path, $match))
50 foreach (Translate\IGNORE_LANG_NAMES as $check)
52 if (\mb_strpos($path,
'/lang/'.$match[1].
'/'.$check.
'/') !==
false)
59 $arr = \explode(self::DIRECTORY_SEPARATOR, $path);
60 $langKey = \array_search(
'lang', $arr) + 1;
62 return \array_key_exists($langKey, $arr) && $arr[$langKey] <>
'';
80 $arr = \explode(self::DIRECTORY_SEPARATOR, $path);
81 $pos = \array_search(
'lang', $arr);
82 if ($pos !==
false && !empty($arr[$pos + 1]))
84 return $arr[$pos + 1];
98 public static function replaceLangId(
string $path,
string $langId): string
100 $modifier = Translate\Config::isUtfMode() ?
'u' :
'';
102 return \preg_replace(
"#^(.*?/lang/)([^/]*?)(/|$)#".$modifier,
"\\1$langId\\3", $path);
114 public static function removeLangId(
string $path, ?array $langs =
null): string
116 static $defLangs = [];
119 if (empty($defLangs))
121 $defLangs = \array_unique(\array_merge(
122 Translate\Config::getDefaultLanguages(),
123 Translate\Config::getEnabledLanguages()
128 $arr = \explode(self::DIRECTORY_SEPARATOR, $path);
129 if (\in_array(
'lang', $arr))
131 $langKey = \array_search(
'lang', $arr) + 1;
132 if (\in_array($arr[$langKey], $langs))
134 unset($arr[$langKey]);
136 $path = \implode(self::DIRECTORY_SEPARATOR, $arr);
151 public static function addLangId(
string $path,
string $langId, ?array $langs =
null): string
153 $pathTemp = self::removeLangId($path, $langs);
155 $arr = \explode(
'/', $pathTemp);
156 if (\in_array(
'lang', $arr))
167 $path = \implode(
'/', $arr1);
183 $path = \rtrim($path, self::DIRECTORY_SEPARATOR);
191 if (!\file_exists($path))
193 return \mkdir($path, \BX_DIR_PERMISSIONS,
true);
196 return \is_dir($path);
206 public static function isPhpFile(
string $path,
bool $checkExistence =
false): bool
208 return $checkExistence
209 ? (\mb_substr($path, -4) ===
'.php') && \is_file($path)
210 : (\mb_substr($path, -4) ===
'.php');
static replaceLangId(string $path, string $langId)
static secure(string $path)
static tidy(string $path)
static isLangDir(string $path, bool $additionalCheck=false)
static extractLangId(string $path)
static isPhpFile(string $path, bool $checkExistence=false)
static checkCreatePath(string $path)
static addLangId(string $path, string $langId, ?array $langs=null)
static removeLangId(string $path, ?array $langs=null)