239 $this->sitemapData[
'SETTINGS'][
'FILENAME_FILES'],
245 $isCheckFinished =
false;
248 while (!$isFinished && microtime(
true) <= $timeFinish)
252 $dbRes = RuntimeTable::getList([
253 'order' => [
'ITEM_PATH' =>
'ASC'],
255 'PID' => $this->sitemapId,
263 if ($dirData = $dbRes->Fetch())
266 $this->statusMessage =
Loc::getMessage(
'SITEMAP_RUN_FILES', [
'#PATH#' => $dirData[
'ITEM_PATH']]);
267 $isCheckFinished =
false;
269 elseif (!$isCheckFinished)
272 $isCheckFinished =
true;
282 if ($this->step < Step::STEPS[Step::STEP_FILES] - 1)
290 if (!is_array($this->state[
'XML_FILES']))
292 $this->state[
'XML_FILES'] = [];
295 if ($sitemapFile->isNotEmpty())
297 if ($sitemapFile->isCurrentPartNotEmpty())
299 $sitemapFile->finish();
303 $sitemapFile->delete();
306 $xmlFiles = $sitemapFile->getNameList();
307 $directory = $sitemapFile->getPathDirectory();
308 foreach ($xmlFiles as &$xmlFile)
310 $xmlFile = $directory . $xmlFile;
312 $this->state[
'XML_FILES'] = array_unique(array_merge($this->state[
'XML_FILES'], $xmlFiles));
316 $sitemapFile->delete();
319 $this->step = Step::STEPS[Step::STEP_FILES];
321 'SITEMAP_RUN_FILE_COMPLETE',
322 [
'#FILE#' => $this->sitemapData[
'SETTINGS'][
'FILENAME_FILES']]
341 $directories = \CSeoUtils::getDirStructure(
342 $this->sitemapData[
'SETTINGS'][
'logical'] ==
'Y',
343 $this->sitemapData[
'SITE_ID'],
344 $dirData[
'ITEM_PATH']
347 foreach ($directories as $dir)
349 $dirKey =
"/" . ltrim($dir[
'DATA'][
'ABS_PATH'],
"/");
351 if ($dir[
'TYPE'] ==
'F')
354 !isset($this->sitemapData[
'SETTINGS'][
'FILE'][$dirKey])
355 || $this->sitemapData[
'SETTINGS'][
'FILE'][$dirKey] ==
'Y'
358 if (preg_match($this->sitemapData[
'SETTINGS'][
'FILE_MASK_REGEXP'], $dir[
'FILE']))
360 $f =
new IO\File($dir[
'DATA'][
'PATH'], $this->sitemapData[
'SITE_ID']);
361 $sitemapFile->addFileEntry($f);
367 if (!isset($this->sitemapData[
'SETTINGS'][
'DIR'][$dirKey])
368 || $this->sitemapData[
'SETTINGS'][
'DIR'][$dirKey] ==
'Y')
370 $processedDirs[] = $dirKey;
377 $len = mb_strlen($dirData[
'ITEM_PATH']);
378 if (!empty($this->sitemapData[
'SETTINGS'][
'DIR']))
380 foreach ($this->sitemapData[
'SETTINGS'][
'DIR'] as $dirKey => $checked)
384 if (strncmp($dirData[
'ITEM_PATH'], $dirKey, $len) === 0)
386 $processedDirs[] = $dirKey;
392 if (!empty($this->sitemapData[
'SETTINGS'][
'FILE']))
394 foreach ($this->sitemapData[
'SETTINGS'][
'FILE'] as $dirKey => $checked)
398 if (strncmp($dirData[
'ITEM_PATH'], $dirKey, $len) === 0)
400 $fileName = IO\Path::combine(
401 SiteTable::getDocumentRoot($this->sitemapData[
'SITE_ID']),
405 if (!is_dir($fileName))
407 $f =
new IO\File($fileName, $this->sitemapData[
'SITE_ID']);
411 && preg_match($this->sitemapData[
'SETTINGS'][
'FILE_MASK_REGEXP'], $f->getName())
414 $sitemapFile->addFileEntry($f);
423 if (count($processedDirs) > 0)
425 foreach ($processedDirs as $dirKey)
429 'ITEM_PATH' => $dirKey,
434 RuntimeTable::add($runtimeData);
438 RuntimeTable::update($dirData[
'ID'], [
448 if (Loader::includeModule(
'iblock'))
450 $arIBlockList = $this->sitemapData[
'SETTINGS'][
'IBLOCK_ACTIVE'];
451 if (is_array($arIBlockList) && count($arIBlockList) > 0)
454 $dbIBlock = \CIBlock::GetList([], [
'ID' => array_keys($arIBlockList)]);
455 while ($arIBlock = $dbIBlock->Fetch())
457 $arIBlocks[$arIBlock[
'ID']] = $arIBlock;
460 foreach ($arIBlockList as $iblockId => $iblockActive)
462 if ($iblockActive !==
'Y' || !array_key_exists($iblockId, $arIBlocks))
464 unset($arIBlockList[$iblockId]);
469 'PID' => $this->sitemapId,
471 'ITEM_ID' => $iblockId,
479 $this->state[
'LEFT_MARGIN'] = 0;
480 $this->state[
'IBLOCK_LASTMOD'] = 0;
482 $this->state[
'IBLOCK'] = [];
483 $this->state[
'IBLOCK_MAP'] = [];
485 if (count($arIBlockList) <= 0)
487 $this->step = Step::STEPS[Step::STEP_IBLOCK];
492 $this->step = Step::STEPS[Step::STEP_IBLOCK_INDEX];
505 $bCheckFinished =
false;
506 $runtimeIblock =
false;
507 $currentIBlock =
false;
511 $dbOldIblockResult =
null;
512 $dbIblockResult =
null;
514 if (isset($_SESSION[
"SEO_SITEMAP_" . $this->sitemapId]))
517 unset($_SESSION[
"SEO_SITEMAP_" . $this->sitemapId]);
520 while (!$isFinished && microtime(
true) <= $timeFinish && Loader::includeModule(
'iblock'))
524 $dbRes = RuntimeTable::getList([
525 'order' => [
'ID' =>
'ASC'],
527 'PID' => $this->sitemapId,
533 $runtimeIblock = $dbRes->fetch();
537 $iblockId = intval($runtimeIblock[
'ITEM_ID']);
539 $dbIBlock = \CIBlock::GetByID($iblockId);
540 $currentIBlock = $dbIBlock->Fetch();
544 RuntimeTable::update($runtimeIblock[
'ID'], [
548 $this->state[
'LEFT_MARGIN'] = 0;
549 $this->state[
'IBLOCK_LASTMOD'] = 0;
550 $this->state[
'LAST_ELEMENT_ID'] = 0;
551 unset($this->state[
'CURRENT_SECTION']);
554 'SITEMAP_RUN_IBLOCK_NAME',
555 [
'#IBLOCK_NAME#' => $currentIBlock[
'NAME']]
560 if ($currentIBlock[
'LIST_PAGE_URL'] ==
'')
562 $this->sitemapData[
'SETTINGS'][
'IBLOCK_LIST'][$iblockId] =
'N';
564 if ($currentIBlock[
'SECTION_PAGE_URL'] ==
'')
566 $this->sitemapData[
'SETTINGS'][
'IBLOCK_SECTION'][$iblockId] =
'N';
568 if ($currentIBlock[
'DETAIL_PAGE_URL'] ==
'')
570 $this->sitemapData[
'SETTINGS'][
'IBLOCK_ELEMENT'][$iblockId] =
'N';
573 $this->state[
'IBLOCK_LASTMOD'] =
574 max($this->state[
'IBLOCK_LASTMOD'], MakeTimeStamp($currentIBlock[
'TIMESTAMP_X']));
576 if ($this->state[
'LEFT_MARGIN'] <= 0 && $this->sitemapData[
'SETTINGS'][
'IBLOCK_ELEMENT'][$iblockId] !=
'N')
578 $this->state[
'CURRENT_SECTION'] = 0;
581 $fileName = str_replace(
582 [
'#IBLOCK_ID#',
'#IBLOCK_CODE#',
'#IBLOCK_XML_ID#'],
583 [$iblockId, $currentIBlock[
'CODE'], $currentIBlock[
'XML_ID']],
584 $this->sitemapData[
'SETTINGS'][
'FILENAME_IBLOCK']
597 if (!$runtimeIblock || !$sitemapFile)
601 elseif (is_array($currentIBlock))
603 if ($dbIblockResult ==
null)
605 if (isset($this->state[
'CURRENT_SECTION']))
607 $dbIblockResult = \CIBlockElement::GetList(
610 'IBLOCK_ID' => $iblockId,
612 'SECTION_ID' => intval($this->state[
'CURRENT_SECTION']),
613 '>ID' => intval($this->state[
'LAST_ELEMENT_ID']),
614 'SITE_ID' => $this->sitemapData[
'SITE_ID'],
615 "ACTIVE_DATE" =>
"Y",
618 [
'nTopCount' => 1000],
619 [
'ID',
'TIMESTAMP_X',
'DETAIL_PAGE_URL']
624 $this->state[
'LAST_ELEMENT_ID'] = 0;
625 $dbIblockResult = \CIBlockSection::GetList(
626 [
'LEFT_MARGIN' =>
'ASC'],
628 'IBLOCK_ID' => $iblockId,
629 'GLOBAL_ACTIVE' =>
'Y',
630 '>LEFT_BORDER' => intval($this->state[
'LEFT_MARGIN']),
633 [
'ID',
'TIMESTAMP_X',
'SECTION_PAGE_URL',
'LEFT_MARGIN',
'IBLOCK_SECTION_ID'],
639 if (isset($this->state[
'CURRENT_SECTION']))
641 $arElement = $dbIblockResult->fetch();
645 if (!is_array($this->state[
'IBLOCK_MAP'][$iblockId]))
647 $this->state[
'IBLOCK_MAP'][$iblockId] = [];
650 if (!array_key_exists($arElement[
'ID'], $this->state[
'IBLOCK_MAP'][$iblockId]))
652 $arElement[
'LANG_DIR'] = $this->sitemapData[
'SITE'][
'DIR'];
654 $bCheckFinished =
false;
655 $elementLastmod = MakeTimeStamp($arElement[
'TIMESTAMP_X']);
656 $this->state[
'IBLOCK_LASTMOD'] = max($this->state[
'IBLOCK_LASTMOD'], $elementLastmod);
657 $this->state[
'LAST_ELEMENT_ID'] = $arElement[
'ID'];
659 $this->state[
'IBLOCK'][$iblockId][
'E']++;
660 $this->state[
'IBLOCK_MAP'][$iblockId][$arElement[
"ID"]] = 1;
664 Source\Iblock::prepareUrlToReplace(
665 $arElement[
'DETAIL_PAGE_URL'],
666 $this->sitemapData[
'SITE_ID']
668 $url = \CIBlock::ReplaceDetailUrl($url, $arElement,
false,
"E");
670 $sitemapFile->addIBlockEntry($url, $elementLastmod);
673 elseif (!$bCheckFinished)
675 $bCheckFinished =
true;
676 $dbIblockResult =
null;
680 $bCheckFinished =
false;
681 unset($this->state[
'CURRENT_SECTION']);
682 $this->state[
'LAST_ELEMENT_ID'] = 0;
684 $dbIblockResult =
null;
685 if ($dbOldIblockResult)
687 $dbIblockResult = $dbOldIblockResult;
688 $dbOldIblockResult =
null;
694 $arSection = $dbIblockResult->fetch();
698 $bCheckFinished =
false;
699 $sectionLastmod = MakeTimeStamp($arSection[
'TIMESTAMP_X']);
700 $this->state[
'LEFT_MARGIN'] = $arSection[
'LEFT_MARGIN'];
701 $this->state[
'IBLOCK_LASTMOD'] = max($this->state[
'IBLOCK_LASTMOD'], $sectionLastmod);
704 $bActiveElement =
false;
706 if (isset($this->sitemapData[
'SETTINGS'][
'IBLOCK_SECTION_SECTION'][$iblockId][$arSection[
'ID']]))
709 $this->sitemapData[
'SETTINGS'][
'IBLOCK_SECTION_SECTION'][$iblockId][$arSection[
'ID']] ==
'Y';
711 $this->sitemapData[
'SETTINGS'][
'IBLOCK_SECTION_ELEMENT'][$iblockId][$arSection[
'ID']] ==
'Y';
713 elseif ($arSection[
'IBLOCK_SECTION_ID'] > 0)
715 $dbRes = RuntimeTable::getList([
717 'PID' => $this->sitemapId,
719 'ITEM_ID' => $arSection[
'IBLOCK_SECTION_ID'],
722 'select' => [
'ACTIVE',
'ACTIVE_ELEMENT'],
726 $parentSection = $dbRes->fetch();
735 $bActive = $this->sitemapData[
'SETTINGS'][
'IBLOCK_SECTION'][$iblockId] ==
'Y';
736 $bActiveElement = $this->sitemapData[
'SETTINGS'][
'IBLOCK_ELEMENT'][$iblockId] ==
'Y';
741 'ITEM_ID' => $arSection[
'ID'],
750 $this->state[
'IBLOCK'][$iblockId][
'S']++;
752 $arSection[
'LANG_DIR'] = $this->sitemapData[
'SITE'][
'DIR'];
756 Source\Iblock::prepareUrlToReplace(
757 $arSection[
'SECTION_PAGE_URL'],
758 $this->sitemapData[
'SITE_ID']
760 $url = \CIBlock::ReplaceDetailUrl($url, $arSection,
false,
"S");
762 $sitemapFile->addIBlockEntry($url, $sectionLastmod);
765 RuntimeTable::add($arRuntimeData);
769 $this->state[
'CURRENT_SECTION'] = $arSection[
'ID'];
770 $this->state[
'LAST_ELEMENT_ID'] = 0;
772 $dbOldIblockResult = $dbIblockResult;
773 $dbIblockResult =
null;
776 elseif (!$bCheckFinished)
778 unset($this->state[
'CURRENT_SECTION']);
779 $bCheckFinished =
true;
780 $dbIblockResult =
null;
784 $bCheckFinished =
false;
787 RuntimeTable::update($runtimeIblock[
'ID'], [
791 if ($this->sitemapData[
'SETTINGS'][
'IBLOCK_LIST'][$iblockId] ==
'Y'
792 && $currentIBlock[
'LIST_PAGE_URL']
795 $this->state[
'IBLOCK'][$iblockId][
'I']++;
797 $currentIBlock[
'IBLOCK_ID'] = $currentIBlock[
'ID'];
798 $currentIBlock[
'LANG_DIR'] = $this->sitemapData[
'SITE'][
'DIR'];
802 Source\Iblock::prepareUrlToReplace(
803 $currentIBlock[
'LIST_PAGE_URL'],
804 $this->sitemapData[
'SITE_ID']
806 $url = \CIBlock::ReplaceDetailUrl($url, $currentIBlock,
false,
"");
808 $sitemapFile->addIBlockEntry($url, $this->state[
'IBLOCK_LASTMOD']);
811 if ($sitemapFile->isNotEmpty())
813 if ($sitemapFile->isCurrentPartNotEmpty())
815 $sitemapFile->finish();
819 $sitemapFile->delete();
822 if (!is_array($this->state[
'XML_FILES']))
824 $this->state[
'XML_FILES'] = [];
827 $xmlFiles = $sitemapFile->getNameList();
828 $directory = $sitemapFile->getPathDirectory();
829 foreach ($xmlFiles as &$xmlFile)
830 $xmlFile = $directory . $xmlFile;
831 $this->state[
'XML_FILES'] = array_unique(array_merge($this->state[
'XML_FILES'], $xmlFiles));
835 $sitemapFile->delete();
838 $runtimeIblock =
false;
839 $this->state[
'LEFT_MARGIN'] = 0;
840 $this->state[
'IBLOCK_LASTMOD'] = 0;
841 unset($this->state[
'CURRENT_SECTION']);
842 $this->state[
'LAST_ELEMENT_ID'] = 0;
847 if ($this->step < Step::STEPS[Step::STEP_IBLOCK] - 1)
854 $this->step = Step::STEPS[Step::STEP_IBLOCK];
866 if (!empty($this->sitemapData[
'SETTINGS'][
'FORUM_ACTIVE']))
868 foreach ($this->sitemapData[
'SETTINGS'][
'FORUM_ACTIVE'] as $forumId => $active)
872 $forumList[$forumId] =
"Y";
876 if (count($forumList) > 0 && Loader::includeModule(
'forum'))
879 $db_res = \CForumNew::GetListEx(
882 '@ID' => array_keys($forumList),
884 "SITE_ID" => $this->sitemapData[
'SITE_ID'],
888 while ($res = $db_res->Fetch())
890 $arForums[$res[
'ID']] = $res;
892 $forumList = array_intersect_key($arForums, $forumList);
894 foreach ($forumList as $id => $forum)
897 'PID' => $this->sitemapId,
909 $this->state[
'FORUM_CURRENT_TOPIC'] = 0;
911 if (count($forumList) <= 0)
913 $this->step = Step::STEPS[Step::STEP_FORUM];
918 $this->step = Step::STEPS[Step::STEP_FORUM_INDEX];
931 $runtimeForum =
false;
932 $currentForum =
null;
935 $dbTopicResult =
null;
938 while (!$isFinished && microtime(
true) <= $timeFinish && \CModule::IncludeModule(
"forum"))
942 $dbRes = RuntimeTable::getList([
943 'order' => [
'ID' =>
'ASC'],
945 'PID' => $this->sitemapId,
951 $runtimeForum = $dbRes->fetch();
955 $forumId = intval($runtimeForum[
'ITEM_ID']);
957 $db_res = \CForumNew::GetListEx(
962 "SITE_ID" => $this->sitemapData[
'SITE_ID'],
966 $currentForum = $db_res->Fetch();
969 RuntimeTable::update($runtimeForum[
'ID'], [
973 'SITEMAP_RUN_FORUM_NAME',
974 [
'#FORUM_NAME#' => $currentForum[
'NAME']]
979 $fileName = str_replace(
'#FORUM_ID#', $forumId, $this->sitemapData[
'SETTINGS'][
'FILENAME_FORUM']);
985 if (!$runtimeForum || !$sitemapFile)
989 elseif (is_array($currentForum))
992 array_key_exists($forumId, $this->sitemapData[
'SETTINGS'][
'FORUM_TOPIC'])
993 && $this->sitemapData[
'SETTINGS'][
'FORUM_TOPIC'][$forumId] ==
"Y"
997 if ($dbTopicResult ==
null)
999 $dbTopicResult = \CForumTopic::GetList(
1000 [
"LAST_POST_DATE" =>
"DESC"],
1003 "FORUM_ID" => $forumId,
1007 $this->state[
'FORUM_CURRENT_TOPIC'] > 0
1008 ? [
">ID" => $this->state[
"FORUM_CURRENT_TOPIC"]]
1014 [
'nTopCount' => 100]
1017 if (($arTopic = $dbTopicResult->fetch()) && $arTopic)
1019 $this->state[
"FORUM_CURRENT_TOPIC"] = $arTopic[
"ID"];
1020 $url = \CForumNew::PreparePath2Message(
1021 $currentForum[
"PATH2FORUM_MESSAGE"],
1023 "FORUM_ID" => $currentForum[
"ID"],
1024 "TOPIC_ID" => $arTopic[
"ID"],
1025 "TITLE_SEO" => $arTopic[
"TITLE_SEO"],
1026 "MESSAGE_ID" =>
"s",
1027 "SOCNET_GROUP_ID" => $arTopic[
"SOCNET_GROUP_ID"],
1028 "OWNER_ID" => $arTopic[
"OWNER_ID"],
1029 "PARAM1" => $arTopic[
"PARAM1"],
1030 "PARAM2" => $arTopic[
"PARAM2"],
1033 $sitemapFile->addIBlockEntry($url, MakeTimeStamp($arTopic[
'LAST_POST_DATE']));
1038 $url = \CForumNew::PreparePath2Message(
1039 $currentForum[
"PATH2FORUM_MESSAGE"],
1041 "FORUM_ID" => $currentForum[
"ID"],
1042 "TOPIC_ID" => $currentForum[
"TID"],
1043 "TITLE_SEO" => $currentForum[
"TITLE_SEO"],
1044 "MESSAGE_ID" =>
"s",
1045 "SOCNET_GROUP_ID" => $currentForum[
"SOCNET_GROUP_ID"],
1046 "OWNER_ID" => $currentForum[
"OWNER_ID"],
1047 "PARAM1" => $currentForum[
"PARAM1"],
1048 "PARAM2" => $currentForum[
"PARAM2"],
1051 $sitemapFile->addIBlockEntry($url, MakeTimeStamp($currentForum[
'LAST_POST_DATE']));
1053 if (empty($arTopic))
1055 RuntimeTable::update($runtimeForum[
'ID'], [
1059 if ($sitemapFile->isNotEmpty())
1061 if ($sitemapFile->isCurrentPartNotEmpty())
1063 $sitemapFile->finish();
1067 $sitemapFile->delete();
1070 if (!is_array($this->state[
'XML_FILES']))
1072 $this->state[
'XML_FILES'] = [];
1075 $xmlFiles = $sitemapFile->getNameList();
1076 $directory = $sitemapFile->getPathDirectory();
1077 foreach ($xmlFiles as &$xmlFile)
1079 $xmlFile = $directory . $xmlFile;
1081 $this->state[
'XML_FILES'] = array_unique(array_merge($this->state[
'XML_FILES'], $xmlFiles));
1085 $sitemapFile->delete();
1088 $runtimeForum =
false;
1089 $dbTopicResult =
null;
1090 $this->state[
'FORUM_CURRENT_TOPIC'] = 0;
1094 if ($this->step < Step::STEPS[Step::STEP_FORUM] - 1)
1101 $this->step = Step::STEPS[Step::STEP_FORUM];