/** * @return array | null */ private function _getSavedData() { if (!$this->_file->isExists()) { return array(); } return \WS\Migrations\jsonToArray($this->_file->getContents()); }
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 } }
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)); }
/** * Returns array with cache statistics data. * Returns an empty array in case of disabled html cache. * * @return array */ public function readStatistic() { $result = array(); if ($this->statFile && $this->statFile->isExists()) { $fileValues = explode(",", $this->statFile->getContents()); $result = array("HITS" => intval($fileValues[0]), "MISSES" => intval($fileValues[1]), "QUOTA" => intval($fileValues[2]), "POSTS" => intval($fileValues[3]), "FILE_SIZE" => doubleval($fileValues[4])); } return $result; }
/** * Returns urlrewrite array * * @param string $site Site ID. * @return array */ private static function getRewriteRules($site) { $docRoot = rtrim(\Bitrix\Main\SiteTable::getDocumentRoot($site), '/'); $rewriteRules = array(); $arUrlRewrite =& $rewriteRules; $rewriteFile = new IO\File($docRoot . '/urlrewrite.php'); if ($rewriteFile->isExists()) { include $rewriteFile->getPath(); } return $rewriteRules; }
protected static function prepareDataToInsertFromFileArray(array $fileData, array $data, ErrorCollection $errorCollection) { list($relativePath, $absolutePath) = self::generatePath(); $file = new IO\File($fileData['tmp_name']); if (!$file->isExists()) { $errorCollection->addOne(new Error('Could not find file', self::ERROR_EXISTS_FILE)); return null; } if (!$file->rename($absolutePath)) { $errorCollection->addOne(new Error('Could not move file', self::ERROR_MOVE_FILE)); return null; } //now you can set CREATED_BY $data = array_intersect_key($data, array('CREATED_BY' => true)); return array_merge(array('TOKEN' => bx_basename($relativePath), 'FILENAME' => $fileData['name'], 'PATH' => $relativePath, 'BUCKET_ID' => '', 'SIZE' => '', 'IS_CLOUD' => '', 'WIDTH' => empty($fileData['width']) ? '' : $fileData['width'], 'HEIGHT' => empty($fileData['height']) ? '' : $fileData['height']), $data); }
private function createMap() { $mapFilePath = Application::getDocumentRoot() . "/bitrix/modules/mobileapp/maps/config.php"; $file = new File($mapFilePath); if (!$file->isExists()) { throw new SystemException("The map file '" . $mapFilePath . "' doesn't exists!", 100); } $map = (include $mapFilePath); if (!is_array($map)) { throw new SystemException("The map file does exist but has some broken structure.", 101); } self::$configMap = $map; self::$configMap["groups"] = array(); $groupTypes = array(ParameterType::GROUP, ParameterType::GROUP_BACKGROUND, ParameterType::GROUP_BACKGROUND_LIGHT); foreach ($map["types"] as $paramName => $intType) { if (in_array($intType, $groupTypes)) { self::$configMap["groups"][] = $paramName; } } }
/** * Adds new file entry to the current sitemap * * @param File $f File to add. * * @return void * @throws \Bitrix\Main\IO\FileNotFoundException */ public function addFileEntry(File $f) { if($f->isExists() && !$f->isSystem()) { $this->addEntry(array( 'XML_LOC' => $this->settings['PROTOCOL'].'://'.\CBXPunycode::toASCII($this->settings['DOMAIN'], $e = null).$this->getFileUrl($f), 'XML_LASTMOD' => date('c', $f->getModificationTime()), )); } }
<?php /** Bitrix Framework * Bitrix vars * @global CUser $USER * @global CMain $APPLICATION */ use Bitrix\Main\IO\File; require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_before.php"; if ($USER->IsAdmin()) { $server = isset($_REQUEST['SERVER']) ? trim($_REQUEST['SERVER']) : false; $param = isset($_REQUEST['PARAM']) ? trim($_REQUEST['PARAM']) : false; $period = isset($_REQUEST['PERIOD']) ? trim($_REQUEST['PERIOD']) : false; if ($server && $period && $param) { $pathToImages = "/var/lib/munin"; $path = $pathToImages . '/' . $server . '/' . $server . '/' . $param . '-' . $period . '.png'; $f = new File($path); if ($f->isExists()) { header("Content-type: image/png"); echo $f->getContents(); } } } die;
$bCanEdit = false; } //need fm_lpa for every .php file, even with no php code inside if ($bCanEdit && !$USER->CanDoOperation('edit_php') && in_array(GetFileExtension($currentFilePath), GetScriptFileExt()) && !$USER->CanDoFileOperation('fm_lpa', array(SITE_ID, $currentFilePath))) { $bCanEdit = false; } if ($bCanEdit && IsModuleInstalled("fileman") && !($USER->CanDoOperation("fileman_admin_files") && $USER->CanDoOperation("fileman_edit_existent_files"))) { $bCanEdit = false; } if ($bCanEdit) { echo $APPLICATION->IncludeStringBefore(); $BX_GLOBAL_AREA_EDIT_ICON = true; } } } define("START_EXEC_PROLOG_AFTER_2", microtime()); $GLOBALS["BX_STATE"] = "WA"; $APPLICATION->RestartWorkarea(true); //magically replacing the current file with another one $event = new Main\Event("main", "OnFileRewrite", array("path" => Main\Context::getCurrent()->getRequest()->getScriptFile())); $event->send(); foreach ($event->getResults() as $evenResult) { if (($result = $evenResult->getParameters()) != '') { $file = new Main\IO\File($_SERVER["DOCUMENT_ROOT"] . $result); if ($file->isExists()) { //only the first result matters include $file->getPhysicalPath(); die; } } }
/** * 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; }
private function appendContentNonCloud($fileContent, $startRange, $endRange, $fileSize) { $file = new IO\File($this->getAbsolutePath()); if (!$file->isExists()) { $this->errorCollection->addOne(new Error('Could not find file', static::ERROR_EXISTS_FILE)); return false; } if ($file->putContents($fileContent, $file::APPEND) === false) { $this->errorCollection->addOne(new Error('Could not put contents to file', static::ERROR_PUT_CONTENTS)); return false; } return true; }
public function isCacheExpired($path) { $file = new IO\File($path); if (!$file->isExists()) { return true; } if (!$file instanceof IO\IFileStream) { return true; } $dfile = $file->open("r"); $str_tmp = fread($dfile, 150); fclose($dfile); if (preg_match("/dateexpire\\s*=\\s*'([\\d]+)'/im", $str_tmp, $arTmp) || preg_match("/^BX\\d{12}(\\d{12})/", $str_tmp, $arTmp) || preg_match("/^(\\d{12})/", $str_tmp, $arTmp)) { if (strlen($arTmp[1]) <= 0 || doubleval($arTmp[1]) < mktime()) { return true; } } return false; }
/** * @param string $path This variable is the path to the file for the installation process. * @param null $siteId This variable is the id current site. * @throws Main\ArgumentNullException * @throws Main\IO\FileNotFoundException */ public static function installProcess($path, $siteId = null) { if (empty($path)) { throw new Main\ArgumentNullException("path"); } if (!Main\Loader::includeModule("bizproc")) { return; } $path = Main\Loader::getDocumentRoot() . $path; $iblockType = static::getIBlockType(); $db = \CIBlockType::GetList(array(), array("=ID" => $iblockType)); $res = $db->Fetch(); if (!$res) { static::createIBlockType(); } $file = new Main\IO\File($path); if ($file->isExists() && $file->getExtension() == "prc") { static::import($iblockType, $file->getContents(), $siteId); } }