1C-Битрикс (БУС) автоматическое создание sitemap для фильтра
Архив для скачивания файлов: Скачать
Необходимо просто добавить код в init.php
function addingFilterSitemap(){
$sitemap = file_get_contents($_SERVER["DOCUMENT_ROOT"] . '/sitemap.xml');
if(strpos($sitemap,"")!==false&&strpos($sitemap,"/sitemap-filter.xml")===false){
file_put_contents($_SERVER["DOCUMENT_ROOT"] . '/sitemap.xml', str_replace('','http://testm.com/sitemap-filter.xml '.date(DATE_ATOM).' ',$sitemap));
}
return 'addingFilterSitemap();';
}
function recursiveFilter($arSect,$currentLink,$codeProp=[],$depth=0,$maxDepth=2){
$link = [];
$depth++;
if($depth<=$maxDepth){
$arParams = [
"IBLOCK_ID"=>$arSect["IBLOCK_ID"],
"SECTION_ID"=>$arSect["ID"],
"CACHE_TIME"=>1,
];
$componentClass = new CBitrixCatalogSmartFilter();
$componentClass->initComponent("bitrix:catalog.smart.filter");
$arParams = $componentClass->onPrepareComponentParams($arParams);
$componentClass->arParams = $arParams;
ob_start();
$componentClass->executeComponent();
$dontNeeded = ob_get_contents();
ob_end_clean();
$result = $componentClass->arResult["ITEMS"];
foreach($result as $item){
if(in_array($item["CODE"],$codeProp)){
continue;
}
$codeProp[]=$item["CODE"];
if(!empty($item["VALUES"])){
foreach($item["VALUES"] as $value){
if($value["ELEMENT_COUNT"]>0){
$curr = $currentLink.ToLower($item["CODE"])."-is-".$value["URL_ID"]."/";
$link[]=$curr."apply/";
$_GET["set_filter"]="y";
$_GET[$value["CONTROL_NAME"]]=$value["HTML_VALUE"];
$link = array_merge($link,recursiveFilter($arSect,$curr,$codeProp,$depth));
$_GET=[];
}
}
}
}
}
return $link;
}
function createFilterSitemap(){
CBitrixComponent::includeComponentClass("bitrix:catalog.smart.filter");
CModule::IncludeModule("iblock");
$link = [];
$html = '';
$arFilter = array('IBLOCK_ID' => 2);
$rsSect = CIBlockSection::GetList(array('left_margin' => 'asc'),$arFilter);
while ($arSect = $rsSect->GetNext())
{
$_GET=[];
$currentLink = "http://testm.com".$arSect["SECTION_PAGE_URL"]."filter/";
$link = recursiveFilter($arSect,$currentLink);
foreach($link as $lk){
$html.=''.$lk.' '.date(DATE_ATOM,strtotime($arSect["TIMESTAMP_X"])).' ';
}
}
$html.=' ';
file_put_contents($_SERVER["DOCUMENT_ROOT"] . '/sitemap-filter.xml', $html);
return "createFilterSitemap();";
}
И добавить два агента: