• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/main.php
  • Класс: CAllMain
  • Вызов: CAllMain::GetFileAccessPermission
public function GetFileAccessPermission($path, $groups=false, $task_mode=false) // task_mode - new access mode
{
	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 = mb_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(mb_substr($path, -12) == "/.access.php")
		return (!$task_mode? 'D' : array(CTask::GetIdByLetter('D', 'main', 'file')));

	if(mb_substr($path, -10) == "/.htaccess")
		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)//till the root
	{
		$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 = mb_substr($path, $pos + 1);

			//security fix: under Windows "my." == "my"
			$Dir = TrimUnsafe($Dir);

			//parent folder
			$path = mb_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[mb_strtolower($key)] = $val;
				$PERM = $PERM_TMP;
			}

			$this->FILE_PERMISSION_CACHE[$site."|".$access_file_name] = $PERM;
		}

		//check wheather the rights are assigned to this filefolder 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)) //compatibility with group id
				{
					if(isset($dir_perm[$match[1]]))
						$perm = $dir_perm[$match[1]];
					else
						continue;
				}
				else
					continue;

				if ($task_mode)
				{
					if(mb_substr($perm, 0, 2) == 'T_')
						$tid = intval(mb_substr($perm, 2));
					elseif(($tid = CTask::GetIdByLetter($perm, 'main', 'file')) === false)
						continue;

					$arGroupTask[$group_id] = $tid;
				}
				else
				{
					if(mb_substr($perm, 0, 2) == 'T_')
					{
						$tid = intval(mb_substr($perm, 2));
						$perm = CTask::GetLetter($tid);
						if($perm == '')
							$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;
}