public function getRequestedPageDirectory() { if ($this->requestedFileDirectory != null) { return $this->requestedFileDirectory; } $requestedFile = $this->getRequestedPage(); return $this->requestedFileDirectory = IO\Path::getDirectory($requestedFile); }
public function getRequestedPageDirectory() { if ($this->requestedPageDirectory === null) { $requestedPage = $this->getRequestedPage(); $this->requestedPageDirectory = IO\Path::getDirectory($requestedPage); } return $this->requestedPageDirectory; }
/** * Loads language messages for specified file * * @param string $file * @param string $language * @return array */ public static function loadLanguageFile($file, $language = null) { if ($language === null) { $language = self::getCurrentLang(); } if (!isset(self::$messages[$language])) { self::$messages[$language] = array(); } //first time call only for lang if (self::$customMessages === null) { self::$customMessages = self::loadCustomMessages($language); } $path = Path::getDirectory($file); static $langDirCache = array(); if (isset($langDirCache[$path])) { $langDir = $langDirCache[$path]; $fileName = substr($file, strlen($langDir) - 5); } else { //let's find language folder $langDir = $fileName = ""; $filePath = $file; while (($slashPos = strrpos($filePath, "/")) !== false) { $filePath = substr($filePath, 0, $slashPos); $langPath = $filePath . "/lang"; if (is_dir($langPath)) { $langDir = $langPath; $fileName = substr($file, $slashPos); $langDirCache[$path] = $langDir; break; } } } $mess = array(); if ($langDir != "") { //load messages for default lang first $defaultLang = self::getDefaultLang($language); if ($defaultLang != $language) { $langFile = $langDir . "/" . $defaultLang . $fileName; if (file_exists($langFile)) { $mess = self::includeFile($langFile); } } //then load messages for specified lang $langFile = $langDir . "/" . $language . $fileName; if (file_exists($langFile)) { $mess = array_merge($mess, self::includeFile($langFile)); } foreach ($mess as $key => $val) { self::$messages[$language][$key] = $val; } } return $mess; }
private static function includeLangFiles($file, $language) { static $langDirCache = array(); $path = Path::getDirectory($file); if (isset($langDirCache[$path])) { $langDir = $langDirCache[$path]; $fileName = substr($file, strlen($langDir) - 5); } else { //let's find language folder $langDir = $fileName = ""; $filePath = $file; while (($slashPos = strrpos($filePath, "/")) !== false) { $filePath = substr($filePath, 0, $slashPos); $langPath = $filePath . "/lang"; if (is_dir($langPath)) { $langDir = $langPath; $fileName = substr($file, $slashPos); $langDirCache[$path] = $langDir; break; } } } $mess = array(); if ($langDir != "") { //load messages for default lang first $defaultLang = self::getDefaultLang($language); if ($defaultLang != $language) { $langFile = $langDir . "/" . $defaultLang . $fileName; if (file_exists($langFile)) { $mess = self::includeFile($langFile); } } //then load messages for specified lang $langFile = $langDir . "/" . $language . $fileName; if (file_exists($langFile)) { $mess = array_merge($mess, self::includeFile($langFile)); } } return $mess; }
/** * Downloads and saves a file. * * @param string $url URI to download * @param string $filePath Absolute file path * @return bool */ public function download($url, $filePath) { $dir = IO\Path::getDirectory($filePath); IO\Directory::createDirectory($dir); $file = new IO\File($filePath); $handler = $file->open("w+"); if ($handler !== false) { $this->setOutputStream($handler); $res = $this->query(self::HTTP_GET, $url); fclose($handler); return $res; } return false; }
/** * Replace path to includes in css * @param $content * @param $path * @return mixed */ public static function fixCssIncludes($content, $path) { $path = IO\Path::getDirectory($path); $content = preg_replace_callback('#([;\\s:]*(?:url|@import)\\s*\\(\\s*)(\'|"|)(.+?)(\\2)\\s*\\)#si', create_function('$matches', 'return $matches[1].Bitrix\\Main\\Page\\Asset::replaceUrlCSS($matches[3], $matches[2], "' . addslashes($path) . '").")";'), $content); $content = preg_replace_callback('#(\\s*@import\\s*)([\'"])([^\'"]+)(\\2)#si', create_function('$matches', 'return $matches[1].Bitrix\\Main\\Page\\Asset::replaceUrlCSS($matches[3], $matches[2],"' . addslashes($path) . '");'), $content); return $content; }
/** * Generates source map content * @param $fileName * @param $content * @return string */ private static function generateSourceMap($fileName, $content) { $files = self::getFilesInfo($content); $sections = ""; foreach ($files as $file) { if (!isset($file["map"]) || strlen($file["map"]) < 1) { continue; } $filePath = Main\Loader::getDocumentRoot() . $file["map"]; if (file_exists($filePath) && ($content = file_get_contents($filePath)) !== false) { if ($sections !== "") { $sections .= ","; } $dirPath = IO\Path::getDirectory($file["source"]); $sourceName = IO\Path::getName($file["source"]); $minName = IO\Path::getName($file["min"]); $sourceMap = str_replace(array($sourceName, $minName), array($dirPath . "/" . $sourceName, $dirPath . "/" . $minName), $content); $sections .= '{"offset": { "line": ' . $file["line"] . ', "column": 0 }, "map": ' . $sourceMap . '}'; } } return '{"version":3, "file":"' . $fileName . '", "sections": [' . $sections . ']}'; }
public function getDirectoryName() { return Path::getDirectory($this->path); }