if (empty($errors)) { $arSitemapSettings = SitemapTable::prepareSettings(array('FILE_MASK' => trim($_REQUEST['FILE_MASK']), 'ROBOTS' => $_REQUEST['ROBOTS'] == 'N' ? 'N' : 'Y', 'logical' => $_REQUEST['log'] == 'N' ? 'N' : 'Y', 'DIR' => $_REQUEST['DIR'], 'FILE' => $_REQUEST['FILE'], 'PROTO' => $_REQUEST['PROTO'], 'DOMAIN' => $_REQUEST['DOMAIN'], 'FILENAME_INDEX' => $fileNameIndex, 'FILENAME_FILES' => $fileNameFiles, 'FILENAME_IBLOCK' => $fileNameIblock, 'FILENAME_FORUM' => $fileNameForum, 'IBLOCK_ACTIVE' => $_REQUEST['IBLOCK_ACTIVE'], 'IBLOCK_LIST' => $_REQUEST['IBLOCK_LIST'], 'IBLOCK_SECTION' => $_REQUEST['IBLOCK_SECTION'], 'IBLOCK_ELEMENT' => $_REQUEST['IBLOCK_ELEMENT'], 'IBLOCK_SECTION_SECTION' => $_REQUEST['IBLOCK_SECTION_SECTION'], 'IBLOCK_SECTION_ELEMENT' => $_REQUEST['IBLOCK_SECTION_ELEMENT'], 'FORUM_ACTIVE' => $_REQUEST['FORUM_ACTIVE'], 'FORUM_TOPIC' => $_REQUEST['FORUM_TOPIC'])); $arSiteMapFields = array('NAME' => trim($_REQUEST['NAME']), 'ACTIVE' => $_REQUEST['ACTIVE'] == 'N' ? 'N' : 'Y', 'SITE_ID' => $SITE_ID, 'SETTINGS' => serialize($arSitemapSettings)); if ($ID > 0) { $result = SitemapTable::update($ID, $arSiteMapFields); } else { $result = SitemapTable::add($arSiteMapFields); $ID = $result->getId(); } if ($result->isSuccess()) { $arSitemapIblock = array(); SitemapIblockTable::clearBySitemap($ID); if (is_array($_REQUEST['IBLOCK_AUTO'])) { foreach ($_REQUEST['IBLOCK_AUTO'] as $iblockId => $auto) { if ($auto === 'Y') { $result = SitemapIblockTable::add(array('SITEMAP_ID' => $ID, 'IBLOCK_ID' => intval($iblockId))); } } } SitemapForumTable::clearBySitemap($ID); if (is_array($_REQUEST['FORUM_AUTO'])) { foreach ($_REQUEST['FORUM_AUTO'] as $forumId => $auto) { if ($auto === 'Y') { $result = SitemapForumTable::add($ID, $forumId); } } } if ($_REQUEST["save"] != '') { LocalRedirect(BX_ROOT . "/admin/seo_sitemap.php?lang=" . LANGUAGE_ID); } elseif ($_REQUEST["save_and_add"] != '') { LocalRedirect(BX_ROOT . "/admin/seo_sitemap.php?lang=" . LANGUAGE_ID . "&run=" . $ID . "&" . bitrix_sessid_get());
protected static function actionAdd($name, $arFields) { if ($name == 'ADDELEMENT') { if (!self::checkElement($arFields)) { return; } // we don't have the GLOBAL_ACTIVE flag in $arFields so we should check it manually if (is_array($arFields['IBLOCK_SECTION']) && count($arFields['IBLOCK_SECTION']) > 0) { $arNewSections = array(); $arFilter = array('ID' => $arFields['IBLOCK_SECTION'], 'IBLOCK_ID' => $arFields['IBLOCK_ID'], 'GLOBAL_ACTIVE' => 'Y'); $dbRes = \CIBlockSection::getList(array(), $arFilter, false, array('ID')); while ($ar = $dbRes->fetch()) { $arNewSections[] = $ar['ID']; } if (count($arNewSections) <= 0) { // element is added to inactive sections return; } $arFields['IBLOCK_SECTION'] = $arNewSections; } } elseif ($name == 'ADDSECTION') { $dbRes = \CIBlockSection::getList(array(), array('ID' => $arFields['ID'], 'GLOBAL_ACTIVE' => 'Y'), false, array('ID')); if (!$dbRes->fetch()) { // section is added to inactive branch return; } } $arSitemaps = SitemapIblockTable::getByIblock($arFields, $name == 'ADDSECTION' ? SitemapIblockTable::TYPE_SECTION : SitemapIblockTable::TYPE_ELEMENT); $arFields['TIMESTAMP_X'] = ConvertTimeStamp(false, "FULL"); if (isset($arFields['IBLOCK_SECTION']) && is_array($arFields['IBLOCK_SECTION']) && count($arFields['IBLOCK_SECTION']) > 0) { $arFields['IBLOCK_SECTION_ID'] = min($arFields['IBLOCK_SECTION']); } if (count($arSitemaps) > 0) { $arSiteDirs = array(); $dbSite = SiteTable::getList(array('select' => array('LID', 'DIR'))); while ($arSite = $dbSite->fetch()) { $arSiteDirs[$arSite['LID']] = $arSite['DIR']; } foreach ($arSitemaps as $arSitemap) { $arFields['LANG_DIR'] = $arSiteDirs[$arSitemap['SITE_ID']]; $rule = array('url' => $name == 'ADDSECTION' ? \CIBlock::replaceDetailUrl($arSitemaps[0]['SECTION_PAGE_URL'], $arFields, false, "S") : \CIBlock::replaceDetailUrl($arSitemaps[0]['DETAIL_PAGE_URL'], $arFields, false, "E"), 'lastmod' => MakeTimeStamp($arFields['TIMESTAMP_X'])); $fileName = str_replace(array('#IBLOCK_ID#', '#IBLOCK_CODE#', '#IBLOCK_XML_ID#'), array($arFields['IBLOCK_ID'], $arSitemap['IBLOCK_CODE'], $arSitemap['IBLOCK_XML_ID']), $arSitemap['SITEMAP_FILE_IBLOCK']); $sitemapFile = new SitemapFile($fileName, $arSitemap); $sitemapFile->appendIblockEntry($rule['url'], $rule['lastmod']); $sitemapIndex = new SitemapIndex($arSitemap['SITEMAP_FILE'], $arSitemap); $sitemapIndex->appendIndexEntry($sitemapFile); if ($arSitemap['ROBOTS'] == 'Y') { $robotsFile = new RobotsFile($arSitemap['SITE_ID']); $robotsFile->addRule(array(RobotsFile::SITEMAP_RULE, $sitemapIndex->getUrl())); } } } }