- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/main.php
- Класс: CAllMain
- Вызов: CAllMain::GetFileAccessPermissionByUser
public function GetFileAccessPermissionByUser($intUserID, $path, $groups=false, $task_mode=false) // task_mode - new access mode
{
$intUserIDTmp = intval($intUserID);
if ($intUserIDTmp.'|' != $intUserID.'|')
return (!$task_mode? 'D' : array(CTask::GetIdByLetter('D', 'main', 'file')));
$intUserID = $intUserIDTmp;
if ($groups === false)
{
$groups = CUser::GetUserGroup($intUserID);
foreach ($groups as $key=>$val)
$groups[$key] = "G".$val;
}
elseif (is_array($groups) && !empty($groups))
{
$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);
$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')));
}
$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();
$groups[] = "*";
while (true)
{
$path = rtrim($path, " ");
$path = rtrim($path, "/");
if ($path == '')
{
$access_file_name="/.access.php";
$Dir = "/";
}
else
{
$pos = mb_strrpos($path, "/");
if ($pos === false)
break;
$Dir = mb_substr($path, $pos + 1);
$Dir = TrimUnsafe($Dir);
$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();
if ($io->FileExists($DOC_ROOT.$access_file_name))
include($io->GetPhysicalName($DOC_ROOT.$access_file_name));
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;
}
if ($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)) //compatibility with group id
$perm = $dir_perm[mb_substr($group_id, 1)];
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;
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;
}