1С-Битрикс
0
Вклад в тег
<?
AddEventHandler("search", "BeforeIndex", Array("MyClass", "BeforeIndexHandler"));
class MyClass
{
private $file_abs_path = "";
function BeforeIndexHandler($arFields)
{
$io = CBXVirtualIo::GetInstance();
if($arFields["MODULE_ID"] == "main")
{
list($site_id, $file_rel_path) = explode("|", $arFields["ITEM_ID"]);
$file_doc_root = CSite::GetSiteDocRoot($site_id);
$file_abs_path = preg_replace("#[\\\\\\/]+#", "/", $file_doc_root."/".$file_rel_path);
$f = $io->GetFile($file_abs_path);
$sFile = $f->GetContents();
if(isset($sFile) && $sFile != "")
{
$replacer = new MyClass;
$replacer->file_abs_path = $file_abs_path;
$sFile = preg_replace_callback("/<\\?\\\$APPLICATION->IncludeComponent\\(\\s*\"bitrix:main.include\",(.*?)\\?>/mis", array($replacer, "replace"), $sFile);
$arFields["BODY"] = CSearch::KillTags($sFile);
}
}
return $arFields;
}
function replace($matchParams)
{
$io = CBXVirtualIo::GetInstance();
if (preg_match("/\"AREA_FILE_SUFFIX\"\\s*=>\\s*\"(.*?)\",/", $matchParams[1], $match))
{
$slash_pos = strrpos($this->file_abs_path, "/");
$sFilePath = substr($this->file_abs_path, 0, $slash_pos+1);
$sFileName = substr($this->file_abs_path, $slash_pos+1);
$sFileName = substr($sFileName, 0, strlen($sFileName)-4)."_".$match[1].".php";
$f = $io->GetFile($sFilePath.$sFileName);
return $f->GetContents();
}
return "";
}
}