This commit is contained in:
merelendor 2022-12-07 22:05:25 +03:00
commit 533f824463
2 changed files with 1140 additions and 62 deletions

View File

@ -1,5 +1,4 @@
<? <?
//$_SERVER["DOCUMENT_ROOT"] = __DIR__;
define('STOP_STATISTICS', true); define('STOP_STATISTICS', true);
define('NO_KEEP_STATISTIC', 'Y'); define('NO_KEEP_STATISTIC', 'Y');
define('NO_AGENT_STATISTIC', 'Y'); define('NO_AGENT_STATISTIC', 'Y');
@ -11,67 +10,58 @@ $_SERVER['DOCUMENT_ROOT'] = dirname(__DIR__, 1);
require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php'); require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php');
CModule::IncludeModule('iblock'); CModule::IncludeModule('iblock');
$catalog = []; $sitemap_catalog = [];
$all_brands_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_BRANDS, ], false, false, [ "CODE", "PROPERTY_UID" ] ); $sitemap_all_brands_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_BRANDS, ], false, false, [ "CODE", "PROPERTY_UID" ] );
while($all_brands_search_ob = $all_brands_search_res->GetNextElement()) while($sitemap_all_brands_search_ob = $sitemap_all_brands_search_res->GetNextElement())
{ {
$brand = $all_brands_search_ob->GetFields(); $brand = $sitemap_all_brands_search_ob->GetFields();
$brand['MODELS'] = []; $brand['MODELS'] = [];
$catalog[$brand['PROPERTY_UID_VALUE']] = $brand; $sitemap_catalog[$brand['PROPERTY_UID_VALUE']] = $brand;
} }
$all_models_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_MODELS, ], false, false, [ "CODE", "PROPERTY_BRAND_UID"] ); $sitemap_all_models_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_MODELS, ], false, false, [ "CODE", "PROPERTY_BRAND_UID"] );
while($all_models_search_ob = $all_models_search_res->GetNextElement()) while($sitemap_all_models_search_ob = $sitemap_all_models_search_res->GetNextElement())
{ {
$model = $all_models_search_ob->GetFields(); $model = $sitemap_all_models_search_ob->GetFields();
$model['PROPERTIES'] = $all_models_search_ob->GetProperties(); $model['PROPERTIES'] = $sitemap_all_models_search_ob->GetProperties();
array_push($catalog[$model['PROPERTY_BRAND_UID_VALUE']]['MODELS'], $model); array_push($sitemap_catalog[$model['PROPERTY_BRAND_UID_VALUE']]['MODELS'], $model);
//print_r($model);
//array_push( $bitrix_existed_models, $model_search['PROPERTIES']['UID']['VALUE'] );
} }
//print_r($catalog);
//7f7534ad-5382-469c-8e40-f77267fb5644
$url = "https://".SITE_SERVER_NAME."/catalog"; $url = "https://".SITE_SERVER_NAME."/catalog";
$lastmod = date(DATE_W3C); $lastmod = date(DATE_W3C);
$strBegin = "<?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_catalog_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";
foreach($catalog AS $brand) foreach($sitemap_catalog AS $brand)
{ {
$strBegin .= "<url><loc>".$url."/".$brand['CODE']."/"."</loc><lastmod>".$lastmod."</lastmod></url>"."\n"; $sitemap_catalog_string .= "<url><loc>".$url."/".$brand['CODE']."/"."</loc><lastmod>".$lastmod."</lastmod></url>"."\n";
foreach($brand['MODELS'] AS $model) foreach($brand['MODELS'] AS $model)
{ {
$strBegin .= "<url><loc>".$url."/".$brand['CODE']."/".$model['CODE']."/"."</loc><lastmod>".$lastmod."</lastmod></url>"."\n"; $sitemap_catalog_string .= "<url><loc>".$url."/".$brand['CODE']."/".$model['CODE']."/"."</loc><lastmod>".$lastmod."</lastmod></url>"."\n";
} }
} }
$car_search_res = CIBlockElement::GetList( [ "NAME" => "ASC" ], [ "IBLOCK_ID" => IBLOCK_ID_CATALOG_CARS_NEW, ], false, [], [] ); $sitemap_car_search_res = CIBlockElement::GetList( [ "NAME" => "ASC" ], [ "IBLOCK_ID" => IBLOCK_ID_CATALOG_CARS_NEW, ], false, [], [] );
while($car_search_ob = $car_search_res->GetNextElement()) while($sitemap_car_search_ob = $sitemap_car_search_res->GetNextElement())
{ {
$car_existed = $car_search_ob->GetFields(); $car_existed = $sitemap_car_search_ob->GetFields();
$strBegin .= "<url><loc>https://".SITE_SERVER_NAME.$car_existed['DETAIL_PAGE_URL']."</loc><lastmod>".$lastmod."</lastmod></url>"."\n"; $sitemap_catalog_string .= "<url><loc>https://".SITE_SERVER_NAME.$car_existed['DETAIL_PAGE_URL']."</loc><lastmod>".$lastmod."</lastmod></url>"."\n";
} }
$strBegin .= "</urlset>"."\n"; $sitemap_catalog_string .= "</urlset>"."\n";
file_put_contents("../sitemap-catalog.xml", $strBegin); file_put_contents("/home/bitrix/www/sitemap-catalog.xml", $sitemap_catalog_string);
//print $strBegin;
$chunk = "<sitemap><loc>https://www.evoleasing.ru/sitemap-catalog.xml</loc><lastmod>".date(DATE_W3C)."</lastmod></sitemap></sitemapindex>"; $chunk = "<sitemap><loc>https://www.evoleasing.ru/sitemap-catalog.xml</loc><lastmod>".date(DATE_W3C)."</lastmod></sitemap></sitemapindex>";
$sitemap_index = file_get_contents("../sitemap.xml"); $sitemap_index = file_get_contents("/home/bitrix/www/sitemap.xml");
$sitemap_index = str_replace(">", ">\n", $sitemap_index); $sitemap_index = str_replace(">", ">\n", $sitemap_index);
$sitemap_index = str_replace("</sitemapindex>", $chunk, $sitemap_index); $sitemap_index = str_replace("</sitemapindex>", $chunk, $sitemap_index);
$sitemap_index = str_replace("\n", "", $sitemap_index); $sitemap_index = str_replace("\n", "", $sitemap_index);
file_put_contents("../sitemap.xml", $sitemap_index); file_put_contents("/home/bitrix/www/sitemap.xml", $sitemap_index);
die(); die();

File diff suppressed because it is too large Load Diff