function CheckCacheFiles_Rec($strDir) { global $iGoodNum, $iOldNum, $iEmptyDirNum, $dLog; if ($handle = @opendir($strDir)) { while (($file = readdir($handle)) !== false) { if ($file == "." || $file == "..") continue; if (is_dir($strDir."/".$file)) { CheckCacheFiles_Rec($strDir."/".$file); } elseif (is_file($strDir."/".$file)) { $ext = ""; $ext_pos = bxstrrpos($file, "."); if ($ext_pos!==false) $ext = substr($file, $ext_pos + 1); $bCacheExp = False; if ($ext=="html") $bCacheExp = CPageCache::IsCacheExpired($strDir."/".$file); elseif ($ext=="php") $bCacheExp = CPHPCache::IsCacheExpired($strDir."/".$file); if ($bCacheExp) { $iOldNum++; @unlink($strDir."/".$file); } else { $iGoodNum++; } } } @closedir($handle); } clearstatcache(); $bEmptyFolder = True; if ($handle = @opendir($strDir)) { while (($file = readdir($handle)) !== false) { if ($file == "." || $file == "..") continue; $bEmptyFolder = False; break; } } if ($bEmptyFolder) { $iEmptyDirNum++; @rmdir($strDir); } }
$this->__component->__menu_values = $result; if ($arParams["SHOW_NAVIGATION"] != "N") { // text from main CMain::InitPathVars($site, $path); $DOC_ROOT = CSite::GetSiteDocRoot($site); $path = $GLOBALS["APPLICATION"]->GetCurDir(); $arChain = array(); while (true) { $path = rtrim($path, "/"); $chain_file_name = $DOC_ROOT . $path . "/.section.php"; if (file_exists($chain_file_name)) { $sSectionName = ""; include $chain_file_name; if (strlen($sSectionName) > 0) { $arChain[] = array("TITLE" => $sSectionName, "LINK" => $path . "/"); } } if ($path . '/' == SITE_DIR) { break; } if (strlen($path) <= 0) { break; } $pos = bxstrrpos($path, "/"); if ($pos === false) { break; } $path = substr($path, 0, $pos + 1); } $GLOBALS["APPLICATION"]->IncludeComponent("bitrix:breadcrumb", "webdav", array("START_FROM" => count($arChain) + $this->__component->__count_chain_item - 1, "PATH" => "", "SITE_ID" => "", "STR_TITLE" => $arParams["STR_TITLE"]), $component, array("HIDE_ICONS" => "Y")); }
/** * Unpack values from string (something like rsplit). * Simple example for separator ".": * <code> * // Unpack all values: * unpack('test.all.values', 0) -> ['test', 'all', 'values'] * * // Unpack 2 values (by default). First element containing the rest of string. * unpack('test.all.values') -> ['test.all', 'values'] * * // Exception if separator is missing * unpack('test.all values', 3) -> throws BadSignatureException * </code> * * @param string $value String for unpacking. * @param int $limit If $limit === 0 - unpack all values, default - 2. * @return array * @throws BadSignatureException */ protected function unpack($value, $limit = 2) { // Some kind of optimization if ($limit === 0) { if (strpos($value, $this->separator) === false) { throw new BadSignatureException('Separator not found in value'); } return explode($this->separator, $value); } $result = array(); while (--$limit > 0) { $pos = bxstrrpos($value, $this->separator); if ($pos === false) { throw new BadSignatureException('Separator not found in value'); } $result[] = \CUtil::binSubstr($value, $pos + 1); $value = \CUtil::binSubstr($value, 0, $pos); } $result[] = $value; return array_reverse($result); }
function __SearchTemplate($customTemplatePath = "") { $this->__file = ""; $this->__fileAlt = ""; $this->__folder = ""; $this->__hasCSS = null; $this->__hasJS = null; $arFolders = array(); $relativePath = $this->__component->GetRelativePath(); $parentRelativePath = ""; $parentTemplateName = ""; $parentComponent =& $this->__component->GetParent(); $defSiteTemplate = $this->__siteTemplate == ".default"; if ($parentComponent && $parentComponent->GetTemplate()) { $parentRelativePath = $parentComponent->GetRelativePath(); $parentTemplateName = $parentComponent->GetTemplate()->GetName(); if (!$defSiteTemplate) { $arFolders[] = array("path" => "/local/templates/" . $this->__siteTemplate . "/components" . $parentRelativePath . "/" . $parentTemplateName . $relativePath, "in_theme" => true); } $arFolders[] = array("path" => "/local/templates/.default/components" . $parentRelativePath . "/" . $parentTemplateName . $relativePath, "in_theme" => true, "site_template" => ".default"); $arFolders[] = array("path" => "/local/components" . $parentRelativePath . "/templates/" . $parentTemplateName . $relativePath, "in_theme" => true, "site_template" => ""); } if (!$defSiteTemplate) { $arFolders[] = array("path" => "/local/templates/" . $this->__siteTemplate . "/components" . $relativePath); } $arFolders[] = array("path" => "/local/templates/.default/components" . $relativePath, "site_template" => ".default"); $arFolders[] = array("path" => "/local/components" . $relativePath . "/templates", "site_template" => ""); if ($parentComponent) { if (!$defSiteTemplate) { $arFolders[] = array("path" => BX_PERSONAL_ROOT . "/templates/" . $this->__siteTemplate . "/components" . $parentRelativePath . "/" . $parentTemplateName . $relativePath, "in_theme" => true); } $arFolders[] = array("path" => BX_PERSONAL_ROOT . "/templates/.default/components" . $parentRelativePath . "/" . $parentTemplateName . $relativePath, "in_theme" => true, "site_template" => ".default"); $arFolders[] = array("path" => "/bitrix/components" . $parentRelativePath . "/templates/" . $parentTemplateName . $relativePath, "in_theme" => true, "site_template" => ""); } if (!$defSiteTemplate) { $arFolders[] = array("path" => BX_PERSONAL_ROOT . "/templates/" . $this->__siteTemplate . "/components" . $relativePath); } $arFolders[] = array("path" => BX_PERSONAL_ROOT . "/templates/.default/components" . $relativePath, "site_template" => ".default"); $arFolders[] = array("path" => "/bitrix/components" . $relativePath . "/templates", "site_template" => ""); if (strlen($customTemplatePath) > 0 && ($templatePageFile = $this->__SearchTemplateFile($customTemplatePath, $this->__page))) { $this->__fileAlt = $customTemplatePath . "/" . $templatePageFile; foreach ($arFolders as $folder) { if (is_dir($_SERVER["DOCUMENT_ROOT"] . $folder["path"] . "/" . $this->__name)) { $this->__file = $folder["path"] . "/" . $this->__name . "/" . $templatePageFile; $this->__folder = $folder["path"] . "/" . $this->__name; } if (strlen($this->__file) > 0) { if (isset($folder["site_template"])) { $this->__siteTemplate = $folder["site_template"]; } if (isset($folder["in_theme"]) && $folder["in_theme"] === true) { $this->__templateInTheme = true; } else { $this->__templateInTheme = false; } break; } } return strlen($this->__file) > 0; } static $cache = array(); $cache_id = $relativePath . "|" . $this->__siteTemplate . "|" . $parentRelativePath . "|" . $parentTemplateName . "|" . $this->__page . "|" . $this->__name; if (!isset($cache[$cache_id])) { foreach ($arFolders as $folder) { $fname = $folder["path"] . "/" . $this->__name; if (file_exists($_SERVER["DOCUMENT_ROOT"] . $fname)) { if (is_dir($_SERVER["DOCUMENT_ROOT"] . $fname)) { if ($templatePageFile = $this->__SearchTemplateFile($fname, $this->__page)) { $this->__file = $fname . "/" . $templatePageFile; $this->__folder = $fname; $this->__hasCSS = file_exists($_SERVER["DOCUMENT_ROOT"] . $fname . "/style.css"); $this->__hasJS = file_exists($_SERVER["DOCUMENT_ROOT"] . $fname . "/script.js"); } } elseif (is_file($_SERVER["DOCUMENT_ROOT"] . $fname)) { $this->__file = $fname; if (strpos($this->__name, "/") !== false) { $this->__folder = $folder["path"] . "/" . substr($this->__name, 0, bxstrrpos($this->__name, "/")); } } } else { if ($templatePageFile = $this->__SearchTemplateFile($folder["path"], $this->__name)) { $this->__file = $folder["path"] . "/" . $templatePageFile; } } if ($this->__file != "") { if (isset($folder["site_template"])) { $this->__siteTemplate = $folder["site_template"]; } if (isset($folder["in_theme"]) && $folder["in_theme"] === true) { $this->__templateInTheme = true; } else { $this->__templateInTheme = false; } break; } } $cache[$cache_id] = array($this->__folder, $this->__file, $this->__siteTemplate, $this->__templateInTheme, $this->__hasCSS, $this->__hasJS); } else { $this->__folder = $cache[$cache_id][0]; $this->__file = $cache[$cache_id][1]; $this->__siteTemplate = $cache[$cache_id][2]; $this->__templateInTheme = $cache[$cache_id][3]; $this->__hasCSS = $cache[$cache_id][4]; $this->__hasJS = $cache[$cache_id][5]; } return $this->__file != ""; }
function GetContentType($path, $bPhysicalName = false) { $io = CBXVirtualIo::GetInstance(); $pathX = $bPhysicalName ? $path : $io->GetPhysicalName($path); if (function_exists("mime_content_type")) { $type = mime_content_type($pathX); } else { $type = ""; } if (strlen($type) <= 0 && function_exists("image_type_to_mime_type")) { $arTmp = CFile::GetImageSize($pathX, true); $type = $arTmp["mime"]; } if (strlen($type) <= 0) { $arTypes = array("jpeg" => "image/jpeg", "jpe" => "image/jpeg", "jpg" => "image/jpeg", "png" => "image/png", "gif" => "image/gif", "bmp" => "image/bmp"); $type = $arTypes[strtolower(substr($pathX, bxstrrpos($pathX, ".") + 1))]; } return $type; }
function GetFileName($path) { $path = TrimUnsafe($path); $path = str_replace("\\", "/", $path); $path = rtrim($path, "/"); $p = bxstrrpos($path, "/"); if($p !== false) return substr($path, $p+1); return $path; }
function FetchFileAccessPerm($path) { CMain::InitPathVars($site, $path); $DOC_ROOT = CSite::GetSiteDocRoot($site); $result = false; if (($p = bxstrrpos($path, "/")) === false) { return $result; } $path_file = substr($path, $p + 1); $path_dir = substr($path, 0, $p); $io = CBXVirtualIo::GetInstance(); if (!$io->FileExists($DOC_ROOT . $path_dir . "/.access.php")) { return $result; } include $io->GetPhysicalName($DOC_ROOT . $path_dir . "/.access.php"); $result = array(); foreach ($PERM as $file => $arPerm) { if ($file == $path_file) { foreach ($arPerm as $group => $perm) { $result[] = array('permFile' => $DOC_ROOT . $path_dir . "/.access.php", 'file' => $file, 'group' => $group, 'perm' => $perm); } } } return $result; }
function CopyFileAccessPermission($path_from, $path_to, $bOverWrite = false) { CMain::InitPathVars($site_from, $path_from); $DOC_ROOT_FROM = CSite::GetSiteDocRoot($site_from); CMain::InitPathVars($site_to, $path_to); //upper .access.php if (($p = bxstrrpos($path_from, "/")) !== false) { $path_from_file = substr($path_from, $p + 1); $path_from_dir = substr($path_from, 0, $p); } else { return false; } $PERM = array(); $io = CBXVirtualIo::GetInstance(); if (!$io->FileExists($DOC_ROOT_FROM . $path_from_dir . "/.access.php")) { return true; } include $io->GetPhysicalName($DOC_ROOT_FROM . $path_from_dir . "/.access.php"); $FILE_PERM = $PERM[$path_from_file]; if (count($FILE_PERM) > 0) { return $this->SetFileAccessPermission(array($site_to, $path_to), $FILE_PERM, $bOverWrite); } return true; }
function __SearchTemplate($customTemplatePath = "") { $this->__file = ""; $this->__fileAlt = ""; $this->__folder = ""; $arFolders = array(); $relativePath = $this->__component->GetRelativePath(); $parentComponent = & $this->__component->GetParent(); if ($parentComponent) { $parentRelativePath = $parentComponent->GetRelativePath(); $parentTemplate = & $parentComponent->GetTemplate(); $parentTemplateName = $parentTemplate->GetName(); $arFolders[] = BX_PERSONAL_ROOT."/templates/".$this->__siteTemplate."/components".$parentRelativePath."/".$parentTemplateName.$relativePath; $arFolders[] = BX_PERSONAL_ROOT."/templates/.default/components".$parentRelativePath."/".$parentTemplateName.$relativePath; $arFolders[] = "/bitrix/components".$parentRelativePath."/templates/".$parentTemplateName.$relativePath; } $arFolders[] = BX_PERSONAL_ROOT."/templates/".$this->__siteTemplate."/components".$relativePath; $arFolders[] = BX_PERSONAL_ROOT."/templates/.default/components".$relativePath; $arFolders[] = "/bitrix/components".$relativePath."/templates"; if (strlen($customTemplatePath) > 0 && $templatePageFile = $this->__SearchTemplateFile($customTemplatePath, $this->__page)) { $this->__fileAlt = $customTemplatePath."/".$templatePageFile; for ($i = 0, $cnt = count($arFolders); $i < $cnt; $i++) { if (file_exists($_SERVER["DOCUMENT_ROOT"].$arFolders[$i]."/".$this->__name) && is_dir($_SERVER["DOCUMENT_ROOT"].$arFolders[$i]."/".$this->__name)) { $this->__file = $arFolders[$i]."/".$this->__name."/".$templatePageFile; $this->__folder = $arFolders[$i]."/".$this->__name; } if (StrLen($this->__file) > 0) { if ($i == 0 || $i == 3) $this->__siteTemplate = $this->__siteTemplate; elseif ($i == 1 || $i == 4) $this->__siteTemplate = ".default"; else $this->__siteTemplate = ""; if ($parentComponent && $i < 3) $this->__templateInTheme = True; else $this->__templateInTheme = False; break; } } return (strlen($this->__file) > 0); } for ($i = 0, $cnt = count($arFolders); $i < $cnt; $i++) { if (file_exists($_SERVER["DOCUMENT_ROOT"].$arFolders[$i]."/".$this->__name)) { if (is_dir($_SERVER["DOCUMENT_ROOT"].$arFolders[$i]."/".$this->__name)) { if ($templatePageFile = $this->__SearchTemplateFile($arFolders[$i]."/".$this->__name, $this->__page)) { $this->__file = $arFolders[$i]."/".$this->__name."/".$templatePageFile; $this->__folder = $arFolders[$i]."/".$this->__name; } } elseif (is_file($_SERVER["DOCUMENT_ROOT"].$arFolders[$i]."/".$this->__name)) { $this->__file = $arFolders[$i]."/".$this->__name; if (StrPos($this->__name, "/") !== False) $this->__folder = $arFolders[$i]."/".SubStr($this->__name, 0, bxstrrpos($this->__name, "/")); } } else { if ($templatePageFile = $this->__SearchTemplateFile($arFolders[$i], $this->__name)) $this->__file = $arFolders[$i]."/".$templatePageFile; } if (StrLen($this->__file) > 0) { if ($i == 0 || $i == 3) $this->__siteTemplate = $this->__siteTemplate; elseif ($i == 1 || $i == 4) $this->__siteTemplate = ".default"; else $this->__siteTemplate = ""; if ($parentComponent && $i < 3) $this->__templateInTheme = True; else $this->__templateInTheme = False; break; } } return (StrLen($this->__file) > 0); }
CHTTP::SetStatus("403 Forbidden"); die("Index file is not found."); } } else { CHTTP::SetStatus("404 Not Found"); die("File is not found."); } } if (strtolower(substr($requestUriAbsolute, -4)) == ".php") { include $io->GetPhysicalName($requestUriAbsolute); } else { $f = $io->GetFile($requestUriAbsolute); $fsize = $f->GetFileSize(); $fModTime = $f->GetModificationTime(); $arTypes = array("jpeg" => "image/jpeg", "jpe" => "image/jpeg", "jpg" => "image/jpeg", "png" => "image/png", "gif" => "image/gif", "bmp" => "image/bmp"); $ext = strtolower(substr($requestUriAbsolute, bxstrrpos($requestUriAbsolute, ".") + 1)); if (isset($arTypes[$ext])) { header("Content-Type: " . $arTypes[$ext]); } else { $name = $io->ExtractNameFromPath($requestUri); header("Content-Type: application/force-download; name=\"" . $name . "\""); header("Content-Disposition: attachment; filename=\"" . $name . "\""); } header("Content-Transfer-Encoding: binary"); header("Content-Length: " . $fsize); header("Expires: 0"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); header("Last-Modified: " . gmdate('D, d M Y H:i:s \\G\\M\\T', $fModTime)); $f->ReadFile(); }
public static function CopyDirFiles($path_from, $path_to, $ReWrite = True, $Recursive = False) { if (strpos($path_to . "/", $path_from . "/") === 0 || realpath($path_to) === realpath($path_from)) { return false; } if (is_dir($path_from)) { CheckDirPath($path_to . "/"); } elseif (is_file($path_from)) { $p = bxstrrpos($path_to, "/"); $path_to_dir = substr($path_to, 0, $p); CheckDirPath($path_to_dir . "/"); if (file_exists($path_to) && !$ReWrite) { return False; } @copy($path_from, $path_to); if (is_file($path_to)) { @chmod($path_to, BX_FILE_PERMISSIONS); } return True; } else { return True; } if ($handle = @opendir($path_from)) { while (($file = readdir($handle)) !== false) { if ($file == "." || $file == "..") { continue; } // skip files with non-safe names if (!CLearnHelper::IsBaseFilenameSafe($file)) { continue; } if (is_dir($path_from . "/" . $file) && $Recursive) { self::CopyDirFiles($path_from . "/" . $file, $path_to . "/" . $file, $ReWrite, $Recursive); } elseif (is_file($path_from . "/" . $file)) { if (file_exists($path_to . "/" . $file) && !$ReWrite) { continue; } @copy($path_from . "/" . $file, $path_to . "/" . $file); @chmod($path_to . "/" . $file, BX_FILE_PERMISSIONS); } } @closedir($handle); return true; } return false; }
/** * <p>Определяет <a href="https://dev.1c-bitrix.ru/learning/course/index.php?COURSE_ID=43&LESSON_ID=2819" >права доступа к файлу или каталогу</a>. Возвращает символ обозначающий то или иное право: </p> <ul> <li> <b>D</b> - доступ запрещён </li> <li> <b>R</b> - чтение (право просмотра содержимого файла) </li> <li> <b>U</b> - документооборот (право на редактирование файла в режиме документооборота) </li> <li> <b>W</b> - запись (право на прямое редактирование) </li> <li> <b>X</b> - полный доступ (право на прямое редактирование файла и право на изменение прав доступа на данных файл) </li> </ul> <p> Динамичный метод.</p> * * * @param mixed $path Путь к файлу или папке относительно корня. В случае многосайтовой * версии, если корневой каталог у сайтов разный, то в данном * параметре необходимо передавать массив вида:<pre>array("ID сайта", "Путь * к файлу или папке относительно корня")</pre> * * @param array $groups Массив ID групп пользователей, для которых необходимо определить * права доступа. Если false, то определять группу прав для текущего * пользователя.<br>Необязателен. По умолчанию - <i>false</i>. * * @param task_mod $e = false Необходим для работы с пользовательскими уровнями доступа. По * умолчанию - <i>false</i>. * * @return string * * <h4>Example</h4> * <pre> * <? * if (<b>$APPLICATION->GetFileAccessPermission</b>("/ru/index.php") <= "D") * ShowError("Доступ к файлу запрещён."); * ?> * </pre> * * * <h4>See Also</h4> * <ul> <li> <a href="https://dev.1c-bitrix.ru/learning/course/index.php?COURSE_ID=43&LESSON_ID=2819" >Права * доступа</a> </li> <li> <a * href="http://dev.1c-bitrix.ru/api_help/main/reference/cmain/setfileaccesspermission.php">CMain::SetFileAccessPermission</a> * </li> <li> <a * href="http://dev.1c-bitrix.ru/api_help/main/reference/cmain/copyfileaccesspermission.php">CMain::CopyFileAccessPermission</a> * </li> <li> <a * href="http://dev.1c-bitrix.ru/api_help/main/reference/cmain/removefileaccesspermission.php">CMain::RemoveFileAccessPermission</a> * </li> </ul> <a name="examples"></a> * * * @static * @link http://dev.1c-bitrix.ru/api_help/main/reference/cmain/getfileaccesspermission.php * @author Bitrix */ public function GetFileAccessPermission($path, $groups = false, $task_mode = false) { global $USER; if ($groups === false) { if (!is_object($USER)) { $groups = array('G2'); } else { $groups = $USER->GetAccessCodes(); } } elseif (is_array($groups) && !empty($groups)) { //compatibility with user groups id $bNumbers = preg_match('/^[0-9]+$/', $groups[0]); if ($bNumbers) { foreach ($groups as $key => $val) { $groups[$key] = "G" . $val; } } } CMain::InitPathVars($site, $path); $DOC_ROOT = CSite::GetSiteDocRoot($site); //windows files are case-insensitive $bWin = strncasecmp(PHP_OS, "WIN", 3) == 0; if ($bWin) { $path = strtolower($path); } if (trim($path, "/") != "") { $path = Rel2Abs("/", $path); if ($path == "") { return !$task_mode ? 'D' : array(CTask::GetIdByLetter('D', 'main', 'file')); } } if (COption::GetOptionString("main", "controller_member", "N") == "Y" && COption::GetOptionString("main", "~controller_limited_admin", "N") == "Y") { $bAdminM = is_object($USER) ? $USER->IsAdmin() : false; } else { $bAdminM = in_array("G1", $groups); } if ($bAdminM) { return !$task_mode ? 'X' : array(CTask::GetIdByLetter('X', 'main', 'file')); } if (substr($path, -12) == "/.access.php" && !$bAdminM) { return !$task_mode ? 'D' : array(CTask::GetIdByLetter('D', 'main', 'file')); } if (substr($path, -10) == "/.htaccess" && !$bAdminM) { return !$task_mode ? 'D' : array(CTask::GetIdByLetter('D', 'main', 'file')); } $max_perm = "D"; $arGroupTask = array(); $io = CBXVirtualIo::GetInstance(); //in the group list * === "any group" $groups[] = "*"; while (true) { $path = rtrim($path, ""); $path = rtrim($path, "/"); if ($path == '') { $access_file_name = "/.access.php"; $Dir = "/"; } else { //file or folder $pos = bxstrrpos($path, "/"); if ($pos === false) { break; } $Dir = substr($path, $pos + 1); //security fix: under Windows "my." == "my" $Dir = TrimUnsafe($Dir); //parent folder $path = substr($path, 0, $pos + 1); $access_file_name = $path . ".access.php"; } if (array_key_exists($site . "|" . $access_file_name, $this->FILE_PERMISSION_CACHE)) { $PERM = $this->FILE_PERMISSION_CACHE[$site . "|" . $access_file_name]; } else { $PERM = array(); //file with rights array if ($io->FileExists($DOC_ROOT . $access_file_name)) { include $io->GetPhysicalName($DOC_ROOT . $access_file_name); } //windows files are case-insensitive if ($bWin && !empty($PERM)) { $PERM_TMP = array(); foreach ($PERM as $key => $val) { $PERM_TMP[strtolower($key)] = $val; } $PERM = $PERM_TMP; } $this->FILE_PERMISSION_CACHE[$site . "|" . $access_file_name] = $PERM; } //check wheather the rights are assigned to this file\folder for these groups if (isset($PERM[$Dir]) && is_array($PERM[$Dir])) { $dir_perm = $PERM[$Dir]; foreach ($groups as $key => $group_id) { if (isset($dir_perm[$group_id])) { $perm = $dir_perm[$group_id]; } elseif (preg_match('/^G([0-9]+)$/', $group_id, $match)) { if (isset($dir_perm[$match[1]])) { $perm = $dir_perm[$match[1]]; } else { continue; } } else { continue; } if ($task_mode) { if (substr($perm, 0, 2) == 'T_') { $tid = intval(substr($perm, 2)); } elseif (($tid = CTask::GetIdByLetter($perm, 'main', 'file')) === false) { continue; } $arGroupTask[$group_id] = $tid; } else { if (substr($perm, 0, 2) == 'T_') { $tid = intval(substr($perm, 2)); $perm = CTask::GetLetter($tid); if (strlen($perm) == 0) { $perm = 'D'; } } if ($max_perm == "" || $perm > $max_perm) { $max_perm = $perm; if ($perm == "W") { break 2; } } } if ($group_id == "*") { break 2; } //delete the groip from the list, we have rights alredy for it unset($groups[$key]); if (count($groups) == 1 && in_array("*", $groups)) { break 2; } } if (count($groups) <= 1) { break; } } if ($path == '') { break; } } if ($task_mode) { $arTasks = array_unique(array_values($arGroupTask)); if (empty($arTasks)) { return array(CTask::GetIdByLetter('D', 'main', 'file')); } sort($arTasks); return $arTasks; } else { return $max_perm; } }
function GetContentType($path, $bPhysicalName = false) { if ($bPhysicalName) { $pathX = $path; } else { $io = CBXVirtualIo::GetInstance(); $pathX = $io->GetPhysicalName($path); } if (function_exists("mime_content_type")) { $type = mime_content_type($pathX); } else { $type = ""; } if ($type == "" && function_exists("image_type_to_mime_type")) { $arTmp = CFile::GetImageSize($pathX, true); $type = $arTmp["mime"]; } if ($type == "") { static $arTypes = array("jpeg" => "image/jpeg", "jpe" => "image/jpeg", "jpg" => "image/jpeg", "png" => "image/png", "gif" => "image/gif", "bmp" => "image/bmp", "xla" => "application/vnd.ms-excel", "xlb" => "application/vnd.ms-excel", "xlc" => "application/vnd.ms-excel", "xll" => "application/vnd.ms-excel", "xlm" => "application/vnd.ms-excel", "xls" => "application/vnd.ms-excel", "xlsx" => "application/vnd.ms-excel", "xlt" => "application/vnd.ms-excel", "xlw" => "application/vnd.ms-excel", "dbf" => "application/vnd.ms-excel", "csv" => "application/vnd.ms-excel", "doc" => "application/msword", "docx" => "application/msword", "dot" => "application/msword", "rtf" => "application/msword", "rar" => "application/x-rar-compressed", "zip" => "application/zip"); $type = $arTypes[strtolower(substr($pathX, bxstrrpos($pathX, ".") + 1))]; } if ($type == "") { $type = "application/octet-stream"; } return $type; }
if($_SERVER["REQUEST_METHOD"]=="POST" && $_POST["action"]=="import" && $isAdmin && check_freetrix_sessid()) { $ID = $_POST["ID"]; if(!is_uploaded_file($_FILES["tpath_file"]["tmp_name"])) { $strError .= GetMessage("MAIN_TEMPLATE_LOAD_ERR_LOAD"); } else { if(strlen($ID)<=0) { $ID = basename($_FILES['tpath_file']['name']); if($p = bxstrrpos($ID, ".gz")) $ID = substr($ID, 0, $p); if($p = bxstrrpos($ID, ".tar")) $ID = substr($ID, 0, $p); $ID = str_replace("\\", "", $ID); $ID = str_replace("/", "", $ID); } if(strlen($ID)<=0) { $strError .= GetMessage("MAIN_TEMPLATE_LOAD_ERR_ID"); } else { if(file_exists($_SERVER["DOCUMENT_ROOT"].FX_PERSONAL_ROOT."/templates/".$ID)) { $strError .= str_replace("#TEMPLATE_NAME#", $ID, GetMessage("MAIN_TEMPLATE_LOAD_ERR_EX")); }
function __SearchTemplate($customTemplatePath = "") { $this->__file = ""; $this->__fileAlt = ""; $this->__folder = ""; $this->__hasCSS = null; $this->__hasJS = null; $arFolders = array(); $relativePath = $this->__component->GetRelativePath(); $parentComponent =& $this->__component->GetParent(); if ($parentComponent) { $parentRelativePath = $parentComponent->GetRelativePath(); $parentTemplateName = $parentComponent->GetTemplate()->GetName(); $arFolders[] = BX_PERSONAL_ROOT . "/templates/" . $this->__siteTemplate . "/components" . $parentRelativePath . "/" . $parentTemplateName . $relativePath; $arFolders[] = BX_PERSONAL_ROOT . "/templates/.default/components" . $parentRelativePath . "/" . $parentTemplateName . $relativePath; $arFolders[] = "/bitrix/components" . $parentRelativePath . "/templates/" . $parentTemplateName . $relativePath; } else { $parentRelativePath = ""; $parentTemplateName = ""; } $arFolders[] = BX_PERSONAL_ROOT . "/templates/" . $this->__siteTemplate . "/components" . $relativePath; $arFolders[] = BX_PERSONAL_ROOT . "/templates/.default/components" . $relativePath; $arFolders[] = "/bitrix/components" . $relativePath . "/templates"; if (strlen($customTemplatePath) > 0 && ($templatePageFile = $this->__SearchTemplateFile($customTemplatePath, $this->__page))) { $this->__fileAlt = $customTemplatePath . "/" . $templatePageFile; for ($i = 0, $cnt = count($arFolders); $i < $cnt; $i++) { if (file_exists($_SERVER["DOCUMENT_ROOT"] . $arFolders[$i] . "/" . $this->__name) && is_dir($_SERVER["DOCUMENT_ROOT"] . $arFolders[$i] . "/" . $this->__name)) { $this->__file = $arFolders[$i] . "/" . $this->__name . "/" . $templatePageFile; $this->__folder = $arFolders[$i] . "/" . $this->__name; } if (StrLen($this->__file) > 0) { if ($i == 0 || $i == 3) { } elseif ($i == 1 || $i == 4) { $this->__siteTemplate = ".default"; } else { $this->__siteTemplate = ""; } if ($parentComponent && $i < 3) { $this->__templateInTheme = true; } else { $this->__templateInTheme = false; } break; } } return strlen($this->__file) > 0; } static $cache; $cache_id = $relativePath . "|" . $this->__siteTemplate . "|" . $parentRelativePath . "|" . $parentTemplateName . "|" . $this->__page . "|" . $this->__name; if (!isset($cache)) { $cache = array(); } if (!isset($cache[$cache_id])) { $i = 0; foreach ($arFolders as $folder) { $fname = $folder . "/" . $this->__name; if (file_exists($_SERVER["DOCUMENT_ROOT"] . $fname)) { if (is_dir($_SERVER["DOCUMENT_ROOT"] . $fname)) { if ($templatePageFile = $this->__SearchTemplateFile($fname, $this->__page)) { $this->__file = $fname . "/" . $templatePageFile; $this->__folder = $fname; $this->__hasCSS = file_exists($_SERVER["DOCUMENT_ROOT"] . $fname . "/style.css"); $this->__hasJS = file_exists($_SERVER["DOCUMENT_ROOT"] . $fname . "/script.js"); } } elseif (is_file($_SERVER["DOCUMENT_ROOT"] . $fname)) { $this->__file = $fname; if (StrPos($this->__name, "/") !== false) { $this->__folder = $folder . "/" . SubStr($this->__name, 0, bxstrrpos($this->__name, "/")); } } } else { if ($templatePageFile = $this->__SearchTemplateFile($folder, $this->__name)) { $this->__file = $folder . "/" . $templatePageFile; } } if ($this->__file != "") { if ($i == 0 || $i == 3) { } elseif ($i == 1 || $i == 4) { $this->__siteTemplate = ".default"; } else { $this->__siteTemplate = ""; } if ($parentComponent && $i < 3) { $this->__templateInTheme = true; } else { $this->__templateInTheme = false; } break; } $i++; } $cache[$cache_id] = array($this->__folder, $this->__file, $this->__siteTemplate, $this->__templateInTheme, $this->__hasCSS, $this->__hasJS); } else { $this->__folder = $cache[$cache_id][0]; $this->__file = $cache[$cache_id][1]; $this->__siteTemplate = $cache[$cache_id][2]; $this->__templateInTheme = $cache[$cache_id][3]; $this->__hasCSS = $cache[$cache_id][4]; $this->__hasJS = $cache[$cache_id][5]; } return $this->__file != ""; }
function GetDirList($path, &$arDirs, &$arFiles, $arFilter = array(), $sort = array(), $type = "DF", $bLogical = false, $task_mode = false) { global $USER, $APPLICATION; CMain::InitPathVars($site, $path); $DOC_ROOT = CSite::GetSiteDocRoot($site); $arDirs = array(); $arFiles = array(); $exts = strtolower($arFilter["EXTENSIONS"]); $arexts = explode(",", $exts); if (isset($arFilter["TYPE"])) { $type = strtoupper($arFilter["TYPE"]); } $io = CBXVirtualIo::GetInstance(); $path = $io->CombinePath("/", $path); $abs_path = $io->CombinePath($DOC_ROOT, $path); if (!$io->DirectoryExists($abs_path)) { return false; } $date_format = CDatabase::DateFormatToPHP(CLang::GetDateFormat("FULL")); $tzOffset = CTimeZone::GetOffset(); $dir = $io->GetDirectory($abs_path); $arChildren = $dir->GetChildren(); foreach ($arChildren as $child) { $arFile = array(); if (($type == "F" || $type == "") && $child->IsDirectory()) { continue; } if (($type == "D" || $type == "") && !$child->IsDirectory()) { continue; } $file = $child->GetName(); if ($bLogical) { if ($child->IsDirectory()) { $sSectionName = ""; $fsn = $io->CombinePath($abs_path, $file, ".section.php"); if (!$io->FileExists($fsn)) { continue; } include $io->GetPhysicalName($fsn); $arFile["LOGIC_NAME"] = $sSectionName; } else { if (CFileMan::GetFileTypeEx($file) != "php") { continue; } if ($file == '.section.php') { continue; } if (!preg_match('/^\\.(.*)?\\.menu\\.(php|html|php3|php4|php5|php6|phtml)$/', $file, $regs)) { $f = $io->GetFile($abs_path . "/" . $file); $filesrc = $f->GetContents(); $title = PHPParser::getPageTitle($filesrc); if ($title === false) { continue; } $arFile["LOGIC_NAME"] = $title; } } } $arFile["PATH"] = $abs_path . "/" . $file; $arFile["ABS_PATH"] = $path . "/" . $file; $arFile["NAME"] = $file; $arPerm = $APPLICATION->GetFileAccessPermission(array($site, $path . "/" . $file), $USER->GetUserGroupArray(), $task_mode); if ($task_mode) { $arFile["PERMISSION"] = $arPerm[0]; if (count($arPerm[1]) > 0) { $arFile["PERMISSION_EX"] = $arPerm[1]; } } else { $arFile["PERMISSION"] = $arPerm; } $arFile["TIMESTAMP"] = $child->GetModificationTime() + $tzOffset; $arFile["DATE"] = date($date_format, $arFile["TIMESTAMP"]); if (isset($arFilter["TIMESTAMP_1"]) && strtotime($arFile["DATE"]) < strtotime($arFilter["TIMESTAMP_1"])) { continue; } if (isset($arFilter["TIMESTAMP_2"]) && strtotime($arFile["DATE"]) > strtotime($arFilter["TIMESTAMP_2"])) { continue; } if (is_set($arFilter, "MIN_PERMISSION") && $arFile["PERMISSION"] < $arFilter["MIN_PERMISSION"] && !$task_mode) { continue; } if (!$child->IsDirectory() && $arFile["PERMISSION"] <= "R" && !$task_mode) { continue; } if ($bLogical) { if (strlen($arFilter["NAME"]) > 0 && strpos($arFile["LOGIC_NAME"], $arFilter["NAME"]) === false) { continue; } } else { if (strlen($arFilter["NAME"]) > 0 && strpos($arFile["NAME"], $arFilter["NAME"]) === false) { continue; } } //if(strlen($arFilter["NAME"])>0 && strpos($arFile["NAME"], $arFilter["NAME"])===false) // continue; if (substr($arFile["ABS_PATH"], 0, strlen(BX_ROOT . "/modules")) == BX_ROOT . "/modules" && !$USER->CanDoOperation('edit_php') && !$task_mode) { continue; } if ($arFile["PERMISSION"] == "U" && !$task_mode) { $ftype = GetFileType($arFile["NAME"]); if ($ftype != "SOURCE" && $ftype != "IMAGE" && $ftype != "UNKNOWN") { continue; } if (substr($arFile["NAME"], 0, 1) == ".") { continue; } } if ($child->IsDirectory()) { $arFile["SIZE"] = 0; $arFile["TYPE"] = "D"; $arDirs[] = $arFile; } else { if ($exts != "") { if (!in_array(strtolower(substr($file, bxstrrpos($file, ".") + 1)), $arexts)) { continue; } } $arFile["TYPE"] = "F"; $arFile["SIZE"] = $child->GetFileSize(); $arFiles[] = $arFile; } } if (is_array($sort) && count($sort) > 0) { $by = key($sort); $order = strtolower($sort[$by]); $by = strtolower($by); if ($order != "desc") { $order = "asc"; } if ($by != "size" && $by != "timestamp") { $by = "name"; } usort($arDirs, array("_FilesCmp", "cmp_" . $by . "_" . $order)); usort($arFiles, array("_FilesCmp", "cmp_" . $by . "_" . $order)); } return null; }