evoleasing-public/local/regions_sitemap_generation.php
2023-02-03 13:44:26 +03:00

81 lines
3.3 KiB
PHP

<?
define('STOP_STATISTICS', true);
define('NO_KEEP_STATISTIC', 'Y');
define('NO_AGENT_STATISTIC', 'Y');
define('DisableEventsCheck', true);
define('BX_SECURITY_SHOW_MESSAGE', true);
define('NOT_CHECK_PERMISSIONS', true);
$_SERVER['DOCUMENT_ROOT'] = dirname(__DIR__, 1);
require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php');
CModule::IncludeModule('iblock');
/* sitemap regions file start -------------------------------------------------------------*/
$sitemap_regions = [];
$sitemap_brands = [];
//IBLOCK_ID_CITIES
$sitemap_all_cities_search_res = CIBlockElement::GetList( [ "NAME" => "ASC" ], [ "IBLOCK_ID" => IBLOCK_ID_CITIES, ], false, false, [ "CODE", ] );
while($sitemap_all_cities_search_ob = $sitemap_all_cities_search_res->GetNextElement())
{
$city = $sitemap_all_cities_search_ob->GetFields();
$sitemap_regions[] = $city['CODE'];
}
$sitemap_all_brands_search_res = CIBlockElement::GetList( [ "NAME" => "ASC" ], [ "IBLOCK_ID" => IBLOCK_ID_BRANDS, ], false, false, [ "CODE", "PROPERTY_UID" ] );
while($sitemap_all_brands_search_ob = $sitemap_all_brands_search_res->GetNextElement())
{
$brand = $sitemap_all_brands_search_ob->GetFields();
$brand['MODELS'] = [];
$sitemap_brands[$brand['PROPERTY_UID_VALUE']] = $brand;
}
$sitemap_all_models_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_MODELS, "PROPERTY_PROMO_VALUE" => "Да" ], false, false, [ "CODE", "PROPERTY_BRAND_UID"] );
while($sitemap_all_models_search_ob = $sitemap_all_models_search_res->GetNextElement())
{
$model = $sitemap_all_models_search_ob->GetFields();
$model['PROPERTIES'] = $sitemap_all_models_search_ob->GetProperties();
array_push($sitemap_brands[$model['PROPERTY_BRAND_UID_VALUE']]['MODELS'], $model);
}
$url = "https://".SITE_SERVER_NAME."/regions";
$lastmod = date(DATE_W3C);
$sitemap_regions_string = "<?xml version='1.0' encoding='UTF-8'?>\n<urlset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
$sitemap_regions_string .= "<url><loc>".$url."/"."</loc><lastmod>".$lastmod."</lastmod></url>"."\n";
foreach($sitemap_regions AS $city)
{
$sitemap_regions_string .= "<url><loc>".$url."/".$city."/"."</loc><lastmod>".$lastmod."</lastmod></url>"."\n";
foreach($sitemap_brands AS $brand)
{
$sitemap_regions_string .= "<url><loc>".$url."/".$city."/".$brand['CODE']."/"."</loc><lastmod>".$lastmod."</lastmod></url>"."\n";
foreach($brand['MODELS'] AS $model)
{
$sitemap_regions_string .= "<url><loc>".$url."/".$city."/".$brand['CODE']."/".$model['CODE']."/"."</loc><lastmod>".$lastmod."</lastmod></url>"."\n";
}
}
}
$sitemap_regions_string .= "</urlset>"."\n";
file_put_contents("/home/bitrix/www/sitemap-regions.xml", $sitemap_regions_string);
$chunk = "<sitemap><loc>https://www.evoleasing.ru/sitemap-regions.xml</loc><lastmod>".date(DATE_W3C)."</lastmod></sitemap></sitemapindex>";
$sitemap_index = file_get_contents("/home/bitrix/www/sitemap.xml");
$sitemap_index = str_replace(">", ">\n", $sitemap_index);
$sitemap_index = str_replace("</sitemapindex>", $chunk, $sitemap_index);
$sitemap_index = str_replace("\n", "", $sitemap_index);
file_put_contents("/home/bitrix/www/sitemap.xml", $sitemap_index);
/* sitemap regions file end -------------------------------------------------------------*/
die();
?>