public function IncludeFile($rel_path, $arParams = array(), $arFunctionParams = array())
{
/** @global CMain $APPLICATION */
/** @noinspection PhpUnusedLocalVariableInspection */
global $APPLICATION, $USER, $DB, $MESS, $DOCUMENT_ROOT;
if(MainApplication::getInstance()->getKernelSession()["SESS_SHOW_INCLUDE_TIME_EXEC"]=="Y" && ($USER->CanDoOperation('edit_php') || MainApplication::getInstance()->getKernelSession()["SHOW_SQL_STAT"]=="Y"))
{
$debug = new CDebugInfo();
$debug->Start();
}
elseif($APPLICATION->ShowIncludeStat)
{
$debug = new CDebugInfo();
$debug->Start();
}
else
{
$debug = null;
}
$sType = "TEMPLATE";
$bComponent = false;
if(mb_substr($rel_path, 0, 1) != "/")
{
$bComponent = true;
$path = getLocalPath("templates/".SITE_TEMPLATE_ID."/".$rel_path, BX_PERSONAL_ROOT);
if($path === false)
{
$sType = "DEFAULT";
$path = getLocalPath("templates/.default/".$rel_path, BX_PERSONAL_ROOT);
if($path === false)
{
$path = BX_PERSONAL_ROOT."/templates/".SITE_TEMPLATE_ID."/".$rel_path;
$module_id = mb_substr($rel_path, 0, mb_strpos($rel_path, "/"));
if($module_id <> '')
{
$path = "/bitrix/modules/".$module_id."/install/templates/".$rel_path;
$sType = "MODULE";
if(!file_exists($_SERVER["DOCUMENT_ROOT"].$path))
{
$sType = "TEMPLATE";
$path = BX_PERSONAL_ROOT."/templates/".SITE_TEMPLATE_ID."/".$rel_path;
}
}
}
}
}
else
{
$path = $rel_path;
}
if($arFunctionParams["WORKFLOW"] && !IsModuleInstalled("workflow"))
$arFunctionParams["WORKFLOW"] = false;
elseif($sType!="TEMPLATE" && $arFunctionParams["WORKFLOW"])
$arFunctionParams["WORKFLOW"] = false;
$bDrawIcons = (
$arFunctionParams["SHOW_BORDER"] !== false && $APPLICATION->GetShowIncludeAreas()
&& (
$USER->CanDoFileOperation('fm_edit_existent_file', array(SITE_ID, $path))
|| ($arFunctionParams["WORKFLOW"] && $USER->CanDoFileOperation('fm_edit_in_workflow', array(SITE_ID, $path)))
)
);
$iSrcLine = 0;
$sSrcFile = '';
$arIcons = array();
if($bDrawIcons)
{
$path_url = "path=".$path;
$encSiteTemplateId = urlencode(SITE_TEMPLATE_ID);
$editor = '';
$resize = 'false';
if (!in_array($arFunctionParams['MODE'], array('html', 'text', 'php')))
{
$arFunctionParams['MODE'] = $bComponent ? 'php' : 'html';
}
if ($sType != 'TEMPLATE')
{
switch ($arFunctionParams['MODE'])
{
case 'html':
$editor = "/bitrix/admin/fileman_html_edit.php?site=".SITE_ID."&";
break;
case 'text':
$editor = "/bitrix/admin/fileman_file_edit.php?site=".SITE_ID."&";
break;
case 'php':
$editor = "/bitrix/admin/fileman_file_edit.php?full_src=Y&site=".SITE_ID."&";
break;
}
$editor .= "templateID=".$encSiteTemplateId."&";
}
else
{
switch ($arFunctionParams['MODE'])
{
case 'html':
$editor = '/bitrix/admin/public_file_edit.php?site='.SITE_ID.'&bxpublic=Y&from=includefile&templateID='.$encSiteTemplateId.'&';
break;
case 'text':
$editor = '/bitrix/admin/public_file_edit.php?site='.SITE_ID.'&bxpublic=Y&from=includefile&noeditor=Y&';
$resize = 'true';
break;
case 'php':
$editor = '/bitrix/admin/public_file_edit_src.php?site='.SITE_ID.'&templateID='.$encSiteTemplateId.'&';
$resize = 'true';
break;
}
}
if($arFunctionParams["TEMPLATE"])
$arFunctionParams["TEMPLATE"] = "&template=".urlencode($arFunctionParams["TEMPLATE"]);
if($arFunctionParams["BACK_URL"])
$arFunctionParams["BACK_URL"] = "&back_url=".urlencode($arFunctionParams["BACK_URL"]);
else
$arFunctionParams["BACK_URL"] = "&back_url=".urlencode($_SERVER["REQUEST_URI"]);
if($arFunctionParams["LANG"])
$arFunctionParams["LANG"] = "&lang=".urlencode($arFunctionParams["LANG"]);
else
$arFunctionParams["LANG"] = "&lang=".LANGUAGE_ID;
$arPanelParams = array();
$bDefaultExists = false;
if($USER->CanDoOperation('edit_php') && $bComponent)
{
$bDefaultExists = true;
$arPanelParams["TOOLTIP"] = array(
'TITLE' => GetMessage("main_incl_component1"),
'TEXT' => $rel_path
);
$aTrace = MainDiagHelper::getBackTrace(1, DEBUG_BACKTRACE_IGNORE_ARGS);
$sSrcFile = $aTrace[0]["file"];
$iSrcLine = intval($aTrace[0]["line"]);
$arIcons[] = array(
'URL' => 'javascript:'.$APPLICATION->GetPopupLink(array(
'URL' => "/bitrix/admin/component_props.php?".
"path=".urlencode(CUtil::addslashes($rel_path)).
"&template_id=".urlencode(CUtil::addslashes(SITE_TEMPLATE_ID)).
"&lang=".LANGUAGE_ID.
"&src_path=".urlencode(CUtil::addslashes($sSrcFile)).
"&src_line=".$iSrcLine.
""
)),
'ICON'=>"parameters",
'TITLE'=>GetMessage("main_incl_file_comp_param"),
'DEFAULT'=>true
);
}
if($sType == "MODULE")
{
$arIcons[] = array(
'URL'=>'javascript:if(confirm(''.GetMessage("MAIN_INC_BLOCK_MODULE").''))window.location=''.$editor.'&path='.urlencode(BX_PERSONAL_ROOT.'/templates/'.SITE_TEMPLATE_ID.'/'.$rel_path).$arFunctionParams["BACK_URL"].$arFunctionParams["LANG"].'&template='.$path.'';',
'ICON'=>'copy',
'TITLE'=>str_replace("#MODE#", $arFunctionParams["MODE"], str_replace("#BLOCK_TYPE#", (!is_set($arFunctionParams, "NAME")? GetMessage("MAIN__INC_BLOCK"): $arFunctionParams["NAME"]), GetMessage("main_incl_file_edit_copy")))
);
}
elseif($sType == "DEFAULT")
{
$arIcons[] = array(
'URL'=>'javascript:if(confirm(''.GetMessage("MAIN_INC_BLOCK_COMMON").''))window.location=''.$editor.$path_url.$arFunctionParams["BACK_URL"].$arFunctionParams["LANG"].$arFunctionParams["TEMPLATE"].'';',
'ICON'=>'edit-common',
'TITLE'=>str_replace("#MODE#", $arFunctionParams["MODE"], str_replace("#BLOCK_TYPE#", (!is_set($arFunctionParams, "NAME")? GetMessage("MAIN__INC_BLOCK"): $arFunctionParams["NAME"]), GetMessage("MAIN_INC_BLOCK_EDIT")))
);
$arIcons[] = array(
'URL'=>$editor.'&path='.urlencode(BX_PERSONAL_ROOT.'/templates/'.SITE_TEMPLATE_ID.'/'.$rel_path).$arFunctionParams["BACK_URL"].$arFunctionParams["LANG"].'&template='.$path,
'ICON'=>'copy',
'TITLE'=>str_replace("#MODE#", $arFunctionParams["MODE"], str_replace("#BLOCK_TYPE#", (!is_set($arFunctionParams, "NAME")? GetMessage("MAIN__INC_BLOCK"): $arFunctionParams["NAME"]), GetMessage("MAIN_INC_BLOCK_COMMON_COPY")))
);
}
else
{
$arPanelParams["TOOLTIP"] = array(
'TITLE' => GetMessage('main_incl_file'),
'TEXT' => $path
);
$arIcons[] = array(
'URL' => 'javascript:'.$APPLICATION->GetPopupLink(
array(
'URL' => $editor.$path_url.$arFunctionParams["BACK_URL"].$arFunctionParams["LANG"].$arFunctionParams["TEMPLATE"],
"PARAMS" => array(
'width' => 770,
'height' => 470,
'resize' => $resize
)
)
),
'ICON'=>'bx-context-toolbar-edit-icon',
'TITLE'=>str_replace("#MODE#", $arFunctionParams["MODE"], str_replace("#BLOCK_TYPE#", (!is_set($arFunctionParams, "NAME")? GetMessage("MAIN__INC_BLOCK") : $arFunctionParams["NAME"]), GetMessage("MAIN_INC_ED"))),
'DEFAULT'=>!$bDefaultExists
);
if($arFunctionParams["WORKFLOW"])
{
$arIcons[] = array(
'URL'=>'/bitrix/admin/workflow_edit.php?'.$arFunctionParams["LANG"].'&fname='.urlencode($path).$arFunctionParams["TEMPLATE"].$arFunctionParams["BACK_URL"],
'ICON'=>'bx-context-toolbar-edit-icon',
'TITLE'=>str_replace("#BLOCK_TYPE#", (!is_set($arFunctionParams, "NAME")? GetMessage("MAIN__INC_BLOCK"): $arFunctionParams["NAME"]), GetMessage("MAIN_INC_ED_WF"))
);
}
}
echo $this->IncludeStringBefore();
}
$res = null;
if(is_file($_SERVER["DOCUMENT_ROOT"].$path))
{
if(is_array($arParams))
extract($arParams, EXTR_SKIP);
$res = include($_SERVER["DOCUMENT_ROOT"].$path);
}
if(MainApplication::getInstance()->getKernelSession()["SESS_SHOW_INCLUDE_TIME_EXEC"]=="Y" && ($USER->CanDoOperation('edit_php') || MainApplication::getInstance()->getKernelSession()["SHOW_SQL_STAT"]=="Y"))
echo $debug->Output($rel_path, $path);
elseif(is_object($debug))
$debug->Stop($rel_path, $path);
if($bDrawIcons)
{
$comp_id = $path;
if ($sSrcFile)
{
$comp_id .= '|'.$sSrcFile;
}
if ($iSrcLine)
{
$comp_id .= '|'.$iSrcLine;
}
$arPanelParams['COMPONENT_ID'] = md5($comp_id);
echo $this->IncludeStringAfter($arIcons, $arPanelParams);
}
return $res;
}