- Модуль: workflow
- Путь к файлу: ~/bitrix/modules/workflow/classes/general/workflow.php
- Класс: CAllWorkflow
- Вызов: CAllWorkflow::GetFileContent
static function GetFileContent($did, $fname, $wf_path="", $site=false)
{
$err_mess = (CAllWorkflow::err_mess())."
Function: GetFileContent
Line: ";
global $DB, $APPLICATION, $USER;
$did = intval($did);
$io = CBXVirtualIo::GetInstance();
// check if executable
if (
$USER->IsAdmin()
|| (
$io->ValidatePathString($fname)
&& !HasScriptExtension($fname)
)
)
{
if ($did>0)
{
// check if it is associated wtih document
$z = CWorkflow::GetFileByID($did, $fname);
// found one
if ($zr = $z->Fetch())
{
// get it's contents
$path = CWorkflow::GetTempDir().$zr["TEMP_FILENAME"];
if (file_exists($path))
{
return $APPLICATION->GetFileContent($path);
}
}
else
{
// lookup in database
$strSql = "SELECT FILENAME, SITE_ID FROM b_workflow_document WHERE ID='$did'";
$y = $DB->Query($strSql, false, $err_mess.__LINE__);
// found
if ($yr=$y->Fetch())
{
// get it's directory
$path = GetDirPath($yr["FILENAME"]);
// absolute path
$pathto = Rel2Abs($path, $fname);
$DOC_ROOT = CSite::GetSiteDocRoot($yr["SITE_ID"]);
$path = $DOC_ROOT.$pathto;
// give it another try
$u = CWorkflow::GetFileByID($did, $pathto);
// found
if ($ur = $u->Fetch())
{
// get it's contents
$path = CWorkflow::GetTempDir().$ur["TEMP_FILENAME"];
if (file_exists($path)) return $APPLICATION->GetFileContent($path);
}
elseif (file_exists($path)) // it is already on disk
{
// get it's contents
if($USER->CanDoFileOperation('fm_view_file', Array($yr["SITE_ID"], $pathto)))
return $APPLICATION->GetFileContent($path);
}
}
}
}
$DOC_ROOT = CSite::GetSiteDocRoot($site);
// new one
if ($wf_path <> '')
{
$pathto = Rel2Abs($wf_path, $fname);
$path = $DOC_ROOT.$pathto;
if (file_exists($path)) // it is already on disk
{
// get it's contents
if($USER->CanDoFileOperation('fm_view_file', Array($site, $pathto)))
{
$src = $APPLICATION->GetFileContent($path);
return $src;
}
}
}
// still failed to find
// get path
$path = $DOC_ROOT.$fname;
if (file_exists($path))
{
// get it's contents
if($USER->CanDoFileOperation('fm_view_file', Array($site, $fname)))
return $APPLICATION->GetFileContent($path);
}
} // it is executable
else
{
return GetMessage("FLOW_ACCESS_DENIED_PHP_VIEW");
}
}