public static function __callStatic($name, $arguments) { $name = ToUpper($name); switch ($name) { case 'ADDELEMENT': case 'ADDSECTION': if ($arguments[0]["ID"] > 0 && $arguments[0]['IBLOCK_ID'] > 0 && (!isset($arguments[0]['ACTIVE']) || $arguments[0]['ACTIVE'] == 'Y')) { // we recieve array reference here $arFields = array(); foreach ($arguments[0] as $key => $value) { $arFields[$key] = $value; } self::actionAdd($name, $arFields); } break; case 'BEFOREDELETEELEMENT': case 'BEFOREDELETESECTION': case 'BEFOREUPDATEELEMENT': case 'BEFOREUPDATESECTION': $ID = $arguments[0]; if (is_array($ID)) { $ID = $ID['ID']; } if ($ID > 0) { $bElement = $name == 'BEFOREDELETEELEMENT' || $name == 'BEFOREUPDATEELEMENT'; $dbFields = $bElement ? \CIBlockElement::getByID($ID) : \CIBlockSection::getByID($ID); $arFields = $dbFields->getNext(); if ($arFields) { if ($bElement && !self::checkElement($arFields)) { return; } $arSitemaps = SitemapIblockTable::getByIblock($arFields, $bElement ? SitemapIblockTable::TYPE_ELEMENT : SitemapIblockTable::TYPE_SECTION); if (count($arSitemaps) > 0) { self::$arBeforeActions[$name][intval($bElement)][$ID] = array('URL' => $bElement ? $arFields['~DETAIL_PAGE_URL'] : $arFields['~SECTION_PAGE_URL'], 'FIELDS' => $arFields, 'SITEMAPS' => $arSitemaps); } } } break; case 'DELETEELEMENT': case 'DELETESECTION': case 'UPDATEELEMENT': case 'UPDATESECTION': $arFields = $arguments[0]; $bElement = $name == 'DELETEELEMENT' || $name == 'UPDATEELEMENT'; if (is_array($arFields) && $arFields['ID'] > 0 && isset(self::$arBeforeActions['BEFORE' . $name][intval($bElement)][$arFields['ID']])) { if ($name == 'DELETEELEMENT' || $name == 'DELETESECTION') { self::actionDelete(self::$arBeforeActions['BEFORE' . $name][intval($bElement)][$arFields['ID']]); } else { self::actionUpdate(self::$arBeforeActions['BEFORE' . $name][intval($bElement)][$arFields['ID']], $bElement); } } break; } }
/** * Processes actions on IBlock element or section update * * @param array $data Data got from SitemapIblockTable::getByIblock() + element/section data + prev link data got from event handler. * @param bool $element Element or section. */ protected static function actionUpdate($data, $element) { $fields = $data['FIELDS']; foreach ($data['SITEMAPS'] as $sitemap) { $fileName = str_replace(array('#IBLOCK_ID#', '#IBLOCK_CODE#', '#IBLOCK_XML_ID#'), array($fields['IBLOCK_ID'], $sitemap['IBLOCK_CODE'], $sitemap['IBLOCK_XML_ID']), $sitemap['SITEMAP_FILE_IBLOCK']); if ($element) { $dbRes = \CIBlockElement::getByID($fields["ID"]); } else { $dbRes = \CIBlockSection::getByID($fields["ID"]); } $newFields = $dbRes->fetch(); $rule = array('url' => $element ? \CIBlock::replaceDetailUrl($sitemap['DETAIL_PAGE_URL'], $newFields, false, "E") : \CIBlock::replaceDetailUrl($sitemap['SECTION_PAGE_URL'], $newFields, false, "S"), 'lastmod' => MakeTimeStamp($fields['TIMESTAMP_X'])); $sitemapFile = new SitemapFile($fileName, $sitemap); $sitemapFile->removeEntry($data['URL']); if ($newFields["ACTIVE"] !== "N") { $sitemapFile->appendIblockEntry($rule['url'], $rule['lastmod']); } $sitemapIndex = new SitemapIndex($sitemap['SITEMAP_FILE'], $sitemap); $sitemapIndex->appendIndexEntry($sitemapFile); if ($sitemap['ROBOTS'] == 'Y') { $robotsFile = new RobotsFile($sitemap['SITE_ID']); $robotsFile->addRule(array(RobotsFile::SITEMAP_RULE, $sitemapIndex->getUrl())); } unset($sitemapFile); unset($sitemapIndex); unset($robotsFile); } }