public static function onBeforeHTMLEditorScriptRuns() { $asset = Asset::getInstance(); $asset->addJs('/bitrix/js/newkaliningrad.typografru/typograf.js'); $messages = Loc::loadLanguageFile(Path::normalize(__FILE__)); $asset->addString(sprintf('<script>BX.message(%s)</script>', Json::encode($messages, JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE))); }
function acrit_exportpro() { require __DIR__ . '/version.php'; $path = str_replace("\\", "/", __FILE__); $path = substr($path, 0, strlen($path) - strlen("/index.php")); include $path . "/version.php"; if (is_array($arModuleVersion) && array_key_exists("VERSION", $arModuleVersion)) { $this->MODULE_VERSION = $arModuleVersion["VERSION"]; $this->MODULE_VERSION_DATE = $arModuleVersion["VERSION_DATE"]; } $this->MODULE_NAME = GetMessage('ACRIT_EXPORTPRO_MODULE_NAME'); $this->MODULE_DESCRIPTION = GetMessage('ACRIT_EXPORTPRO_MODULE_DESC'); $this->PARTNER_NAME = GetMessage("ACRIT_EXPORTPRO_PARTNER_NAME"); $this->PARTNER_URI = GetMessage("ACRIT_EXPORTPRO_PARTNER_URI"); $app = \Bitrix\Main\Application::getInstance(); $dbSite = \Bitrix\Main\SiteTable::getList(); while ($arSite = $dbSite->Fetch()) { if (!$arSite['DOC_ROOT']) { $this->siteArray[$arSite['LID']] = $app->getDocumentRoot() . $arSite['DIR']; } else { $this->siteArray[$arSite['LID']] = $arSite['DOC_ROOT']; } $this->siteArray[$arSite['LID']] = \Bitrix\Main\IO\Path::normalize($this->siteArray[$arSite['LID']]); } }
public static function showTab($div, $iblockElementInfo) { $engineList = array(); if (Option::get('main', 'vendor', '') == '1c_bitrix') { $engineList[] = array("DIV" => "yandex_direct", "TAB" => Loc::getMessage("SEO_ADV_YANDEX_DIRECT"), "TITLE" => Loc::getMessage("SEO_ADV_YANDEX_DIRECT_TITLE"), "HANDLER" => IO\Path::combine(Application::getDocumentRoot(), BX_ROOT, "/modules/seo/admin/tab/seo_search_yandex_direct.php")); } if (count($engineList) > 0) { $engineTabControl = new \CAdminViewTabControl("engineTabControl", $engineList); ?> <tr> <td colspan="2"> <?php $engineTabControl->begin(); foreach ($engineList as $engineTab) { $engineTabControl->beginNextTab(); $file = new IO\File($engineTab["HANDLER"]); if ($file->isExists()) { require $file->getPath(); } } $engineTabControl->end(); ?> </td> </tr> <?php } }
private function isRequestedUriExists() { /** @var $request HttpRequest */ $request = $this->getContext()->getRequest(); $absUrl = IO\Path::convertRelativeToAbsolute($request->getRequestedPage()); return IO\File::isFileExists($absUrl); }
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; }
function seoSitemapGetFilesData($PID, $arSitemap, $arCurrentDir, $sitemapFile) { global $NS; $arDirList = array(); if ($arCurrentDir['ACTIVE'] == SitemapRuntimeTable::ACTIVE) { $list = \CSeoUtils::getDirStructure($arSitemap['SETTINGS']['logical'] == 'Y', $arSitemap['SITE_ID'], $arCurrentDir['ITEM_PATH']); foreach ($list as $dir) { $dirKey = "/" . ltrim($dir['DATA']['ABS_PATH'], "/"); if ($dir['TYPE'] == 'F') { if (!isset($arSitemap['SETTINGS']['FILE'][$dirKey]) || $arSitemap['SETTINGS']['FILE'][$dirKey] == 'Y') { if (preg_match($arSitemap['SETTINGS']['FILE_MASK_REGEXP'], $dir['FILE'])) { $f = new IO\File($dir['DATA']['PATH'], $arSitemap['SITE_ID']); $sitemapFile->addFileEntry($f); $NS['files_count']++; } } } else { if (!isset($arSitemap['SETTINGS']['DIR'][$dirKey]) || $arSitemap['SETTINGS']['DIR'][$dirKey] == 'Y') { $arDirList[] = $dirKey; } } } } else { $len = strlen($arCurrentDir['ITEM_PATH']); if (!empty($arSitemap['SETTINGS']['DIR'])) { foreach ($arSitemap['SETTINGS']['DIR'] as $dirKey => $checked) { if ($checked == 'Y') { if (strncmp($arCurrentDir['ITEM_PATH'], $dirKey, $len) === 0) { $arDirList[] = $dirKey; } } } } if (!empty($arSitemap['SETTINGS']['FILE'])) { foreach ($arSitemap['SETTINGS']['FILE'] as $dirKey => $checked) { if ($checked == 'Y') { if (strncmp($arCurrentDir['ITEM_PATH'], $dirKey, $len) === 0) { $fileName = IO\Path::combine(SiteTable::getDocumentRoot($arSitemap['SITE_ID']), $dirKey); if (!is_dir($fileName)) { $f = new IO\File($fileName, $arSitemap['SITE_ID']); if ($f->isExists() && !$f->isSystem() && preg_match($arSitemap['SETTINGS']['FILE_MASK_REGEXP'], $f->getName())) { $sitemapFile->addFileEntry($f); $NS['files_count']++; } } } } } } } if (count($arDirList) > 0) { foreach ($arDirList as $dirKey) { $arRuntimeData = array('PID' => $PID, 'ITEM_PATH' => $dirKey, 'PROCESSED' => SitemapRuntimeTable::UNPROCESSED, 'ACTIVE' => SitemapRuntimeTable::ACTIVE, 'ITEM_TYPE' => SitemapRuntimeTable::ITEM_TYPE_DIR); SitemapRuntimeTable::add($arRuntimeData); } } SitemapRuntimeTable::update($arCurrentDir['ID'], array('PROCESSED' => SitemapRuntimeTable::PROCESSED)); }
public function finish() { foreach ($this->partList as $key => $partName) { $f = new File(Path::combine($this->getDirectoryName(), $partName)); $f->rename(str_replace($this->getPrefix(), '', $f->getPath())); $this->partList[$key] = $f->getName(); } if ($this->isCurrentPartNotEmpty()) { $this->addFooter(); $this->rename(str_replace($this->getPrefix(), '', $this->getPath())); } }
/** * 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 = \Bitrix\Main\Context::getCurrent()->getLanguage(); } if (!isset(self::$messages[$language])) { self::$messages[$language] = array(); } //first time call only for lang if (self::$customMessages === null) { self::$customMessages = self::loadCustomMessages($language); } $file = Path::normalize($file); static $dirCache = array(); //let's find language folder $langDir = $fileName = ""; $filePath = $file; while (($slashPos = strrpos($filePath, "/")) !== false) { $filePath = substr($filePath, 0, $slashPos); if (!isset($dirCache[$filePath])) { $dirCache[$filePath] = $isDir = is_dir($filePath . "/lang"); } else { $isDir = $dirCache[$filePath]; } if ($isDir) { $langDir = $filePath . "/lang"; $fileName = substr($file, $slashPos); 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; }
public function rename($newPath) { $newPathNormalized = Path::normalize($newPath); $success = true; if ($this->isExists()) { $success = rename($this->getPhysicalPath(), Path::convertLogicalToPhysical($newPathNormalized)); } if ($success) { $this->originalPath = $newPath; $this->path = $newPathNormalized; $this->pathPhysical = null; } return $success; }
public static function getCurrentTemplateId($siteId) { $cacheFlags = Config\Configuration::getValue("cache_flags"); $ttl = isset($cacheFlags["site_template"]) ? $cacheFlags["site_template"] : 0; $connection = Application::getConnection(); $sqlHelper = $connection->getSqlHelper(); $field = $connection->getType() === "mysql" ? "`CONDITION`" : "CONDITION"; $path2templates = IO\Path::combine(Application::getDocumentRoot(), Application::getPersonalRoot(), "templates"); if ($ttl === false) { $sql = "\n\t\t\t\tSELECT " . $field . ", TEMPLATE\n\t\t\t\tFROM b_site_template\n\t\t\t\tWHERE SITE_ID = '" . $sqlHelper->forSql($siteId) . "'\n\t\t\t\tORDER BY IF(LENGTH(" . $field . ") > 0, 1, 2), SORT\n\t\t\t\t"; $recordset = $connection->query($sql); while ($record = $recordset->fetch()) { $condition = trim($record["CONDITION"]); if ($condition != '' && !@eval("return " . $condition . ";")) { continue; } if (IO\Directory::isDirectoryExists($path2templates . "/" . $record["TEMPLATE"])) { return $record["TEMPLATE"]; } } } else { $managedCache = Application::getInstance()->getManagedCache(); if ($managedCache->read($ttl, "b_site_template")) { $arSiteTemplateBySite = $managedCache->get("b_site_template"); } else { $arSiteTemplateBySite = array(); $sql = "\n\t\t\t\t\tSELECT " . $field . ", TEMPLATE, SITE_ID\n\t\t\t\t\tFROM b_site_template\n\t\t\t\t\tWHERE SITE_ID = '" . $sqlHelper->forSql($siteId) . "'\n\t\t\t\t\tORDER BY SITE_ID, IF(LENGTH(" . $field . ") > 0, 1, 2), SORT\n\t\t\t\t\t"; $recordset = $connection->query($sql); while ($record = $recordset->fetch()) { $arSiteTemplateBySite[$record['SITE_ID']][] = $record; } $managedCache->set("b_site_template", $arSiteTemplateBySite); } if (is_array($arSiteTemplateBySite[$siteId])) { foreach ($arSiteTemplateBySite[$siteId] as $record) { $condition = trim($record["CONDITION"]); if ($condition != '' && !@eval("return " . $condition . ";")) { continue; } if (IO\Directory::isDirectoryExists($path2templates . "/" . $record["TEMPLATE"])) { return $record["TEMPLATE"]; } } } } return ".default"; }
public function convertToPath() { if ($this->uriType != UriType::RELATIVE) { $path = $this->parse(UriPart::PATH); } else { $path = $this->uri; $p = strpos($path, "?"); if ($p !== false) { $path = substr($path, 0, $p); } } if (substr($path, -1, 1) === "/") { $path = self::addDirectoryIndex($path); } $path = IO\Path::normalize($path); return $path; }
public static function getSrcWithResize($file = array(), $size = array()) { $file1 = \CFile::ResizeImageGet($file["ID"], $size, BX_RESIZE_IMAGE_PROPORTIONAL, false); $src = $file1['src']; if ($file['HANDLER_ID'] > 0) { $src = "/" . \COption::GetOptionString("main", "upload_dir", "upload") . "/" . $file["SUBDIR"] . "/" . $file["FILE_NAME"]; $path = $_SERVER["DOCUMENT_ROOT"] . $src; if (!(is_file($path) && file_exists($path))) { $sign = new Signer(); $s = $sign->sign($file["ID"] . "x" . $size["width"] . "x" . $size["height"], self::$salt); $src = \COption::GetOptionString("main.fileinput", "entryPointUrl", "/bitrix/tools/upload.php") . "?" . http_build_query(array("action" => "uncloud", "mode" => "resize", "file" => $file["ID"], "width" => $size["width"], "height" => $size["height"], "signature" => $s)); } } else { $src = \Bitrix\Main\IO\Path::convertLogicalToUri($src); } return $src; }
function renderExceptionMessage(\Exception $exception, $debug = false) { if ($debug) { echo ExceptionHandlerFormatter::format($exception, true); } else { $p = Main\IO\Path::convertRelativeToAbsolute("/error.php"); if (Main\IO\File::isFileExists($p)) { include $p; } else { $context = Main\Application::getInstance(); if ($context) { echo Main\Localization\Loc::getMessage("eho_render_exception_message"); } else { echo "A error occurred during execution of this script. You can turn on extended error reporting in .settings.php file."; } } } }
public static function getDocumentRoot($siteId = null) { if ($siteId === null) { $context = Application::getInstance()->getContext(); $siteId = $context->getSite(); } if (!isset(self::$documentRootCache[$siteId])) { $ar = SiteTable::getRow(array("filter" => array("LID" => $siteId))); if ($ar && ($docRoot = $ar["DOC_ROOT"]) && strlen($docRoot) > 0) { if (!IO\Path::isAbsolute($docRoot)) { $docRoot = IO\Path::combine(Application::getDocumentRoot(), $docRoot); } self::$documentRootCache[$siteId] = $docRoot; } else { self::$documentRootCache[$siteId] = Application::getDocumentRoot(); } } return self::$documentRootCache[$siteId]; }
public function convertToPath() { if ($this->uriType != UriType::RELATIVE) { $path = $this->parse(UriPart::PATH); } else { $path = $this->uri; $p = strpos($path, "?"); if ($p !== false) { $path = substr($path, 0, $p); } } if (substr($path, -1, 1) === "/") { $path = self::addDirectoryIndex($path); } $path = IO\Path::normalize($path); if (IO\Path::validate($path)) { return $path; } throw new \Bitrix\Main\SystemException("Uri is not valid"); }
<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } use Bitrix\Main\Localization\Loc; use Bitrix\Main\IO\Path; use Bitrix\Sale\Order; require_once Path::combine(__DIR__, "functions.php"); Loc::loadLanguageFile(Path::combine(__DIR__, "statuses.php")); $success = isset($_POST['bill_id']) && isset($_POST['amount']) && isset($_POST['ccy']) && isset($_POST['status']) && isset($_POST['error']) && isset($_POST['user']) && isset($_POST['comment']) && isset($_POST['prv_name']) && isset($_POST['command']); if (!$success) { qiwiWalletXmlResponse(QIWI_WALLET_ERROR_CODE_NONE); } if (!isset($GLOBALS["SALE_INPUT_PARAMS"])) { $GLOBALS["SALE_INPUT_PARAMS"] = array(); } $authType = CSalePaySystemAction::GetParamValue("AUTHORIZATION"); if ($authType == "OPEN") { $login = CSalePaySystemAction::GetParamValue("SHOP_ID"); $password = CSalePaySystemAction::GetParamValue("NOTICE_PASSWORD"); if (!qiwiWalletCheckAuth($login, $password)) { qiwiWalletXmlResponse(QIWI_WALLET_ERROR_CODE_AUTH); } } else { $key = CSalePaySystemAction::GetParamValue("API_PASSWORD"); if (isset($_SERVER['HTTP_X_API_SIGNATURE']) && strlen($key) > 0) { $key = CSalePaySystemAction::GetParamValue("API_PASSWORD"); $params = $_POST; ksort($params); $check = base64_encode(sha1($key, implode("|", array_values($params))));
private static function checkPath($path) { static $searchMasksCache = false; if (is_array($searchMasksCache)) { $arExc = $searchMasksCache["exc"]; $arInc = $searchMasksCache["inc"]; } else { $arExc = array(); $arInc = array(); $inc = Config\Option::get("main", "urlrewrite_include_mask", "*.php"); $inc = str_replace("'", "\\'", str_replace("*", ".*?", str_replace("?", ".", str_replace(".", "\\.", str_replace("\\", "/", $inc))))); $arIncTmp = explode(";", $inc); foreach ($arIncTmp as $preg_mask) { if (strlen(trim($preg_mask)) > 0) { $arInc[] = "'^" . trim($preg_mask) . "\$'"; } } $exc = Config\Option::get("main", "urlrewrite_exclude_mask", "/bitrix/*;"); $exc = str_replace("'", "\\'", str_replace("*", ".*?", str_replace("?", ".", str_replace(".", "\\.", str_replace("\\", "/", $exc))))); $arExcTmp = explode(";", $exc); foreach ($arExcTmp as $preg_mask) { if (strlen(trim($preg_mask)) > 0) { $arExc[] = "'^" . trim($preg_mask) . "\$'"; } } $searchMasksCache = array("exc" => $arExc, "inc" => $arInc); } $file = IO\Path::getName($path); if (substr($file, 0, 1) === ".") { return 0; } foreach ($arExc as $preg_mask) { if (preg_match($preg_mask, $path)) { return false; } } foreach ($arInc as $preg_mask) { if (preg_match($preg_mask, $path)) { return true; } } return false; }
/** * 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; }
function seo_getDir($bLogical, $site_id, $dir, $depth, $checked, $arChecked = array()) { if (!is_array($arChecked)) { $arChecked = array(); } $arDirs = \CSeoUtils::getDirStructure($bLogical, $site_id, $dir); if (count($arDirs) > 0) { foreach ($arDirs as $arDir) { $d = Main\IO\Path::combine($dir, $arDir['FILE']); $bChecked = $arChecked[$d] === 'Y' || $checked && $arChecked[$d] !== 'N'; $d = Converter::getHtmlConverter()->encode($d); $r = RandString(8); $varName = $arDir['TYPE'] == 'D' ? 'DIR' : 'FILE'; ?> <div class="sitemap-dir-item"> <?php if ($arDir['TYPE'] == 'D') { ?> <span onclick="loadDir(<?php echo $bLogical ? 'true' : 'false'; ?> , this, '<?php echo CUtil::JSEscape($d); ?> ', '<?php echo $r; ?> ', '<?php echo $depth + 1; ?> ', BX('DIR_<?php echo $d; ?> ').checked)" class="sitemap-tree-icon"></span><?php } ?> <span class="sitemap-dir-item-text"> <input type="hidden" name="<?php echo $varName; ?> [<?php echo $d; ?> ]" value="N" /> <input type="checkbox" name="<?php echo $varName; ?> [<?php echo $d; ?> ]" id="DIR_<?php echo $d; ?> "<?php echo $bChecked ? ' checked="checked"' : ''; ?> value="Y" onclick="checkAll('<?php echo $r; ?> ', this.checked);" /> <label for="DIR_<?php echo $d; ?> "><?php echo Converter::getHtmlConverter()->encode($arDir['NAME'] . ($bLogical ? ' (' . $arDir['FILE'] . ')' : '')); ?> </label> </span> <div id="subdirs_<?php echo $r; ?> " class="sitemap-dir-item-children"></div> </div> <?php } } else { echo $space . Loc::getMessage('SEO_SITEMAP_NO_DIRS_FOUND'); } }
private function transferUri($url) { $url = IO\Path::normalize($url); $urlTmp = trim($url, " \t\n\r\v\\/"); if (empty($urlTmp)) { throw new ArgumentNullException("url"); } $ext = IO\Path::getExtension($url); if (strtolower($ext) != "php") { throw new SystemException("Only php files are allowable for url rewriting"); } $arUrl = explode("/", $url); $rootDirName = ""; while (!empty($arUrl) && ($rootDirName = array_shift($arUrl)) === "") { } $rootDirName = strtolower(str_replace(".", "", $rootDirName)); if (in_array($rootDirName, array("bitrix", "local", "upload"))) { throw new SystemException(sprintf("Can not use path '%s' for url rewriting", $url)); } if (!IO\Path::validate($url)) { throw new SystemException(sprintf("Path '%s' is not valid", $url)); } $absUrl = IO\Path::convertRelativeToAbsolute($url); if (!IO\File::isFileExists($absUrl)) { throw new SystemException(sprintf("Path '%s' is not found", $url)); } $absUrlPhysical = IO\Path::convertLogicalToPhysical($absUrl); global $APPLICATION, $USER, $DB; include_once $absUrlPhysical; die; }
protected static function normalize($path) { if (substr($path, -1, 1) === "/") { $path .= "index.php"; } $path = IO\Path::normalize($path); return $path; }
protected static function handleFileByPath($hash, &$file) { $key = "default"; if (self::resizePicture($file["files"][$key], array("method" => "resample"))) { clearstatcache(); $file["files"][$key]["wasChangedOnServer"] = true; $file["files"][$key]["size"] = filesize($file["files"][$key]["tmp_name"]); $file["files"][$key]["sizeFormatted"] = \CFile::FormatSize($file["files"][$key]["size"]); } $docRoot = \CBXVirtualIo::GetInstance()->CombinePath($_SERVER["DOCUMENT_ROOT"]); $file["path"] = \CBXVirtualIo::GetInstance()->GetFile($file["files"][$key]["tmp_name"])->GetPathWithName(); if (strpos($file["path"], $docRoot) === 0) { $file["path"] = str_replace("//", "/", "/" . substr($file["path"], strlen($docRoot))); } $file["files"][$key]["url"] = $file["files"][$key]["tmp_url"] = \Bitrix\Main\IO\Path::convertPhysicalToUri($file["path"]); $file["type"] = $file["files"][$key]["type"]; return true; }
public function __construct($siteId) { $this->siteId = $siteId; $this->documentRoot = SiteTable::getDocumentRoot($this->siteId); parent::__construct(IO\Path::combine($this->documentRoot, self::ROBOTS_FILE_NAME)); }
/** * Gets lang messages * @return array */ public function getLangMessages() { return Loc::loadLanguageFile(Path::normalize(__FILE__)); }
/** * 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; }
$res = $engine->addSite($arDomain['DOMAIN'], $arDomain['SITE_DIR']); $res['_domain'] = $arDomain['DOMAIN']; break; case 'top-queries': $res = $engine->getQueriesFeed($arDomain['DOMAIN'], $arDomain['SITE_DIR']); break; case 'site_verify': $res = array('error' => array('message' => 'Unknown domain')); if (is_array($arDomain)) { $arFeeds = $engine->getFeeds(); if (isset($arFeeds[$arDomain['DOMAIN']]) && is_array($arFeeds[$arDomain['DOMAIN']])) { if ($arFeeds[$arDomain['DOMAIN']]['verification'] != 'VERIFIED') { $uin = $engine->verifySite($arDomain['DOMAIN'], false); if ($uin) { $filename = "yandex_" . $uin . ".html"; $path = Path::combine(strlen($arDomain['SITE_DOC_ROOT']) > 0 ? $arDomain['SITE_DOC_ROOT'] : $_SERVER['DOCUMENT_ROOT'], $arDomain['SITE_DIR'], $filename); $obFile = new \Bitrix\Main\IO\File($path); $obFile->putContents('<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body>Verification: ' . $uin . '</body></html>'); $res = $engine->verifySite($arDomain['DOMAIN'], true); //$obFile->delete(); } } } $res['_domain'] = $arDomain['DOMAIN']; } else { $res = array('error' => 'No domain'); } break; case 'original_text': $textContent = $_POST['original_text']; $res = $engine->addOriginalText($textContent, $arDomain['DOMAIN'], $arDomain['SITE_DIR']);
/** * Repacks exported document from Google.Drive, which has wrong order files in archive to show preview * in Google.Viewer. In Google.Viewer document should have file '[Content_Types].xml' on first position in archive. * @param FileData $fileData * @return FileData * @throws IO\FileNotFoundException * @throws IO\InvalidPathException * @internal */ public function repackDocument(FileData $fileData) { if (!extension_loaded('zip')) { return null; } if (!TypeFile::isDocument($fileData->getName())) { return null; } $file = new IO\File($fileData->getSrc()); if (!$file->isExists() || $file->getSize() > 15 * 1024 * 1024) { return null; } unset($file); $ds = DIRECTORY_SEPARATOR; $targetDir = \CTempFile::getDirectoryName(2, 'disk_repack' . $ds . md5(uniqid('di', true))); checkDirPath($targetDir); $targetDir = IO\Path::normalize($targetDir) . $ds; $zipOrigin = new \ZipArchive(); if (!$zipOrigin->open($fileData->getSrc())) { return null; } if ($zipOrigin->getNameIndex(0) === '[Content_Types].xml') { $zipOrigin->close(); return null; } if (!$zipOrigin->extractTo($targetDir)) { $zipOrigin->close(); return null; } $zipOrigin->close(); unset($zipOrigin); if (is_dir($targetDir) !== true) { return null; } $newName = md5(uniqid('di', true)); $newFilepath = $targetDir . '..' . $ds . $newName; $repackedZip = new \ZipArchive(); if (!$repackedZip->open($newFilepath, \ZipArchive::CREATE)) { return null; } $source = realpath($targetDir); $repackedZip->addFile($source . $ds . '[Content_Types].xml', '[Content_Types].xml'); $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST); foreach ($files as $file) { if ($file->getBasename() === '[Content_Types].xml') { continue; } $file = str_replace('\\', '/', $file); $file = realpath($file); if (is_dir($file) === true) { $repackedZip->addEmptyDir(str_replace('\\', '/', str_replace($source . $ds, '', $file . $ds))); } elseif (is_file($file) === true) { $repackedZip->addFile($file, str_replace('\\', '/', str_replace($source . $ds, '', $file))); } } $repackedZip->close(); $newFileData = new FileData(); $newFileData->setSrc($newFilepath); return $newFileData; }
/** * Returns file relative path for URL. * * @param File $f File object. * * @return string */ protected function getFileUrl(File $f) { static $indexNames; if(!is_array($indexNames)) { $indexNames = GetDirIndexArray(); } $path = '/'; if (substr($this->path, 0, strlen($this->documentRoot)) === $this->documentRoot) { $path = '/'.substr($f->getPath(), strlen($this->documentRoot)); } $path = Path::convertLogicalToUri($path); $path = in_array($f->getName(), $indexNames) ? str_replace('/'.$f->getName(), '/', $path) : $path; return '/'.ltrim($path, '/'); }
private static function loadTriggers($moduleId) { static $triggersCache = array(); if (isset($triggersCache[$moduleId])) { return; } if (!IO\Path::validateFilename($moduleId)) { throw new Main\ArgumentOutOfRangeException("moduleId"); } $triggersCache[$moduleId] = true; $path = IO\Path::convertRelativeToAbsolute("/bitrix/modules/" . $moduleId . "/option_triggers.php"); if (!IO\File::isFileExists($path)) { return; } include IO\Path::convertLogicalToPhysical($path); }