예제 #1
0
	/**
	 * 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, '/');
	}
예제 #2
0
 function Fetch()
 {
     static $index = false;
     $r = parent::Fetch();
     if ($r) {
         if (strlen($r["SITE_URL"]) > 0) {
             $r["URL"] = $r["SITE_URL"];
         }
         if (substr($r["URL"], 0, 1) == "=") {
             foreach ($this->m_events as $arEvent) {
                 $r["URL"] = ExecuteModuleEventEx($arEvent, array($r));
             }
         }
         $r["URL"] = str_replace(array("#LANG#", "#SITE_DIR#", "#SERVER_NAME#"), array($r["DIR"], $r["DIR"], $r["SERVER_NAME"]), $r["URL"]);
         $r["URL"] = preg_replace("'(?<!:)/+'s", "/", $r["URL"]);
         if (defined("BX_DISABLE_INDEX_PAGE") && BX_DISABLE_INDEX_PAGE) {
             if (!$index) {
                 $index = "#/(" . str_replace(" ", "|", preg_quote(implode(" ", GetDirIndexArray()), "#")) . ")\$#";
             }
             $r["URL"] = preg_replace($index, "/", $r["URL"]);
         }
         //Remove anchor otherwise Google will ignore this link
         $p = strpos($r["URL"], "#");
         if ($p !== false) {
             $r["URL"] = substr($r["URL"], 0, $p);
         }
     }
     return $r;
 }
예제 #3
0
파일: tools.php 프로젝트: nProfessor/Mytb
function GetDirIndex($path, $strDirIndex=false)
{
	$doc_root = ($_SERVER["DOCUMENT_ROOT"] <> ''? $_SERVER["DOCUMENT_ROOT"] : $GLOBALS["DOCUMENT_ROOT"]);
	$dir = GetDirPath($path);
	$arrDirIndex = GetDirIndexArray($strDirIndex);
	if(is_array($arrDirIndex) && !empty($arrDirIndex))
	{
		foreach($arrDirIndex as $page_index)
			if(file_exists($doc_root.$dir.$page_index))
				return $page_index;
	}
	return "index.php";
}
예제 #4
0
 function GetTreeRecursive($PARENT_PATH, $level, $max_depth, $get_description = false)
 {
     global $arrMainMenu, $arrChildMenu, $arrSearchPath, $APPLICATION, $USER;
     static $arIndexes = false;
     if ($arIndexes === false) {
         $arIndexes = GetDirIndexArray();
     }
     $i = 0;
     $arrMenu = $level == 0 ? $arrMainMenu : $arrChildMenu;
     $map = array();
     if (is_array($arrMenu) && count($arrMenu) > 0) {
         foreach ($arrMenu as $mmenu) {
             $menu_file = "." . trim($mmenu) . ".menu.php";
             $menu_file_ext = "." . trim($mmenu) . ".menu_ext.php";
             $aMenuLinks = array();
             if (file_exists($PARENT_PATH . $menu_file)) {
                 include $PARENT_PATH . $menu_file;
                 $bExists = true;
             }
             if (file_exists($PARENT_PATH . $menu_file_ext)) {
                 include $PARENT_PATH . $menu_file_ext;
                 $bExists = true;
             }
             if ($bExists && is_array($aMenuLinks)) {
                 foreach ($aMenuLinks as $aMenu) {
                     if (strlen($aMenu[0]) <= 0) {
                         continue;
                     }
                     if (count($aMenu) > 4) {
                         $CONDITION = $aMenu[4];
                         if (strlen($CONDITION) > 0 && !eval("return " . $CONDITION . ";")) {
                             continue;
                         }
                     }
                     $search_child = false;
                     $search_path = '';
                     if (strlen($aMenu[1]) > 0) {
                         if (preg_match("'^(([A-Za-z]+://)|mailto:|javascript:)'i", $aMenu[1])) {
                             $full_path = $aMenu[1];
                         } else {
                             $full_path = trim(Rel2Abs(substr($PARENT_PATH, strlen($_SERVER["DOCUMENT_ROOT"])), $aMenu[1]));
                             $slash_pos = strrpos($full_path, "/");
                             if ($slash_pos !== false) {
                                 $page = substr($full_path, $slash_pos + 1);
                                 if (($pos = strpos($page, '?')) !== false) {
                                     $page = substr($page, 0, $pos);
                                 }
                                 if ($page == '' || $page == 'index.php' || in_array($page, $arIndexes)) {
                                     $search_path = substr($full_path, 0, $slash_pos + 1);
                                     $search_child = true;
                                 }
                             }
                         }
                     } else {
                         $full_path = $PARENT_PATH;
                     }
                     if (strlen($full_path) > 0) {
                         $FILE_ACCESS = preg_match("'^(([A-Za-z]+://)|mailto:|javascript:)'i", $full_path) ? "R" : $APPLICATION->GetFileAccessPermission($full_path);
                         if ($FILE_ACCESS != "D" && $aMenu[3]["SEPARATOR"] != "Y") {
                             $is_dir = $search_child && is_dir($_SERVER["DOCUMENT_ROOT"] . $search_path) ? "Y" : "N";
                             if ($is_dir == "Y") {
                                 $search_child &= $level < $max_depth;
                                 $search_child &= !in_array($search_path, $arrSearchPath);
                             } else {
                                 $search_child = false;
                             }
                             $ar = array();
                             $ar["LEVEL"] = $level;
                             if (isset($aMenu[3]["DEPTH_LEVEL"]) && $aMenu[3]["DEPTH_LEVEL"] > 1) {
                                 $ar["LEVEL"] += $aMenu[3]["DEPTH_LEVEL"] - 1;
                             }
                             if ($ar["LEVEL"] > $max_depth) {
                                 continue;
                             }
                             $ar["ID"] = md5($full_path . $ar["COUNTER"]);
                             $ar["IS_DIR"] = is_dir($_SERVER["DOCUMENT_ROOT"] . $full_path) ? "Y" : "N";
                             $ar["NAME"] = $aMenu[0];
                             $ar["PATH"] = $PARENT_PATH;
                             $ar["FULL_PATH"] = $full_path;
                             $ar["SEARCH_PATH"] = $search_path;
                             $ar["DESCRIPTION"] = "";
                             if ($get_description && $ar["IS_DIR"] == "Y") {
                                 if (file_exists($_SERVER["DOCUMENT_ROOT"] . $full_path . ".section.php")) {
                                     $arDirProperties = array();
                                     include $_SERVER["DOCUMENT_ROOT"] . $full_path . ".section.php";
                                     if ($arDirProperties["description"] != '') {
                                         $ar["DESCRIPTION"] = $arDirProperties["description"];
                                     }
                                 }
                             }
                             if ($search_child) {
                                 $arrSearchPath[] = $search_path;
                                 $ar["CHILDREN"] = GetTreeRecursive($_SERVER["DOCUMENT_ROOT"] . $ar["SEARCH_PATH"], $level + 1, $max_depth, $get_description);
                             }
                             $map[] = $ar;
                         }
                     }
                 }
             }
         }
     }
     return $map;
 }