242 $name = ToUpper($name);
249 $arguments[0][
"ID"] > 0
250 && $arguments[0][
'IBLOCK_ID'] > 0
252 !isset($arguments[0][
'ACTIVE'])
253 || $arguments[0][
'ACTIVE'] ==
'Y'
259 foreach($arguments[0] as $key => $value)
261 $fields[$key] = $value;
264 if(!isset($fields[
'EXTERNAL_ID']) && isset($fields[
'XML_ID']))
266 $fields[
'EXTERNAL_ID'] = $fields[
'XML_ID'];
273 case 'BEFOREDELETEELEMENT':
274 case 'BEFOREDELETESECTION':
275 case 'BEFOREUPDATEELEMENT':
276 case 'BEFOREUPDATESECTION':
283 $element = $name ==
'BEFOREDELETEELEMENT' || $name ==
'BEFOREUPDATEELEMENT';
286 ? \CIBlockElement::getByID($ID)
287 : \CIBlockSection::getByID($ID);
289 $fields = $dbFields->getNext();
292 if($element && !self::checkElement($fields))
302 if (count($sitemaps) > 0)
306 $dbIblock = \CIBlock::GetByID($fields[
'IBLOCK_ID']);
307 $iblock = $dbIblock->GetNext();
309 ? $iblock[
'~DETAIL_PAGE_URL']
310 : $iblock[
'~SECTION_PAGE_URL'];
312 $url = \CIBlock::replaceDetailUrl($url, $fields,
false, $element ?
'E' :
'S');
314 self::$beforeActions[$name][intval($element)][$ID] = array(
317 'SITEMAPS' => $sitemaps,
324 case 'DELETEELEMENT':
325 case 'DELETESECTION':
326 case 'UPDATEELEMENT':
327 case 'UPDATESECTION':
329 $fields = $arguments[0];
330 $element = $name ==
'DELETEELEMENT' || $name ==
'UPDATEELEMENT';
335 && isset(self::$beforeActions[
'BEFORE'.$name][intval($element)][$fields[
'ID']])
338 if($fields[
'RESULT'] !==
false)
340 if($name ==
'DELETEELEMENT' || $name ==
'DELETESECTION')
342 self::actionDelete(self::$beforeActions[
'BEFORE'.$name][intval($element)][$fields[
'ID']]);
346 self::actionUpdate(self::$beforeActions[
'BEFORE'.$name][intval($element)][$fields[
'ID']], $element);
350 unset(self::$beforeActions[
'BEFORE'.$name][intval($element)][$fields[
'ID']]);
394 $fields = $data[
'FIELDS'];
395 $siteDirs = self::createSiteDirs();
397 foreach ($data[
'SITEMAPS'] as $sitemap)
399 $fileName = str_replace(
400 array(
'#IBLOCK_ID#',
'#IBLOCK_CODE#',
'#IBLOCK_XML_ID#'),
401 array($fields[
'IBLOCK_ID'], $sitemap[
'IBLOCK_CODE'], $sitemap[
'IBLOCK_XML_ID']),
402 $sitemap[
'SITEMAP_FILE_IBLOCK']
406 $dbRes = \CIBlockElement::getByID($fields[
"ID"]);
408 $dbRes = \CIBlockSection::getByID($fields[
"ID"]);
410 $newFields = $dbRes->fetch();
412 $sitemapFile =
new SitemapFile($fileName, $sitemap);
415 $fileName = $sitemapFile->removeEntry($data[
'URL']);
418 $sitemapRuntimeId = $sitemap[
'SITE_ID'] .
'-' . uniqid();
419 $sitemapRuntimeId .= isset($fields[
'ID']) ?
'-' . $fields[
'ID'] .
'-' :
'';
420 $sitemapRuntimeFile =
new SitemapRuntime($sitemapRuntimeId, $fileName, $sitemap);
423 if(self::checkActivity($element, $newFields))
425 $newFields[
'LANG_DIR'] = $siteDirs[$sitemap[
'SITE_ID']];
428 $date = date(
'd.m.Y H:i:s');
430 $url = $element ? $sitemap[
'DETAIL_PAGE_URL'] : $sitemap[
'SECTION_PAGE_URL'];
431 $urlType = $element ?
'E' :
'S';
435 'url' => \CIBlock::replaceDetailUrl($url, $newFields,
false, $urlType),
436 'lastmod' => MakeTimeStamp($date),
439 $sitemapRuntimeFile->setOriginalFile($sitemapFile);
440 $sitemapRuntimeFile->appendIblockEntry($rule[
'url'], $rule[
'lastmod']);
445 if ($sitemapRuntimeFile->isNotEmpty() && $sitemapRuntimeFile->isCurrentPartNotEmpty())
446 $sitemapRuntimeFile->finish();
448 $sitemapRuntimeFile->delete();
450 $sitemapIndex =
new SitemapIndex($sitemap[
'SITEMAP_FILE'], $sitemap);
451 $sitemapIndex->appendIndexEntry($sitemapFile);
453 if ($sitemap[
'ROBOTS'] ==
'Y')
455 $robotsFile =
new RobotsFile($sitemap[
'SITE_ID']);
456 $robotsFile->addRule(
495 if($name ==
'ADDELEMENT')
497 if(!self::checkElement($fields))
503 if(is_array($fields[
'IBLOCK_SECTION']) && count($fields[
'IBLOCK_SECTION']) > 0)
505 $newSections = array();
507 'ID' => $fields[
'IBLOCK_SECTION'],
508 'IBLOCK_ID' => $fields[
'IBLOCK_ID'],
509 'GLOBAL_ACTIVE' =>
'Y'
512 $dbRes = \CIBlockSection::getList(array(), $filter,
false, array(
'ID',
'IBLOCK_TYPE_ID',
'IBLOCK_CODE'));
513 while ($ar = $dbRes->fetch())
515 $newSections[] = $ar[
'ID'];
516 $iblockTypeId = $ar[
'IBLOCK_TYPE_ID'] ? $ar[
'IBLOCK_TYPE_ID'] :
null;
517 $iblockCode = $ar[
'IBLOCK_CODE'] ? $ar[
'IBLOCK_CODE'] :
null;
520 if(count($newSections) <= 0)
526 $fields[
'IBLOCK_SECTION'] = $newSections;
529 elseif($name ==
'ADDSECTION')
531 $dbRes = \CIBlockSection::getList(
533 array(
'ID' => $fields[
'ID'],
'GLOBAL_ACTIVE' =>
'Y'),
535 array(
'ID',
'IBLOCK_TYPE_ID',
'IBLOCK_CODE')
538 $inactiveBranch =
true;
539 while ($ar = $dbRes->fetch())
541 $iblockTypeId = $ar[
'IBLOCK_TYPE_ID'] ? $ar[
'IBLOCK_TYPE_ID'] :
null;
542 $iblockCode = $ar[
'IBLOCK_CODE'] ? $ar[
'IBLOCK_CODE'] :
null;
543 $inactiveBranch =
false;
553 $fields[
'IBLOCK_TYPE_ID'] = $iblockTypeId;
554 $fields[
'IBLOCK_CODE'] = $iblockCode;
561 $fields[
'TIMESTAMP_X'] = ConvertTimeStamp(
false,
"FULL");
563 if(isset($fields[
'IBLOCK_SECTION']) && is_array($fields[
'IBLOCK_SECTION']) && count($fields[
'IBLOCK_SECTION']) > 0)
565 $fields[
'IBLOCK_SECTION_ID'] = min($fields[
'IBLOCK_SECTION']);
568 if(count($sitemaps) > 0)
570 $siteDirs = self::createSiteDirs();
572 foreach ($sitemaps as $sitemap)
574 $fileName = str_replace(
575 array(
'#IBLOCK_ID#',
'#IBLOCK_CODE#',
'#IBLOCK_XML_ID#'),
576 array($fields[
'IBLOCK_ID'], $sitemap[
'IBLOCK_CODE'], $sitemap[
'IBLOCK_XML_ID']),
577 $sitemap[
'SITEMAP_FILE_IBLOCK']
580 $sitemapFile =
new SitemapFile($fileName, $sitemap);
583 $sitemapRuntimeId = $sitemap[
'SITE_ID'] .
'-' . uniqid();
584 $sitemapRuntimeId .= isset($fields[
'ID']) ?
'-' . $fields[
'ID'] .
'-' :
'';
585 $sitemapRuntimeFile =
new SitemapRuntime($sitemapRuntimeId, $fileName, $sitemap);
587 if(self::checkActivity($name ==
'ADDELEMENT' ?
true :
false, $fields))
589 $fields[
'LANG_DIR'] = $siteDirs[$sitemap[
'SITE_ID']];
591 $url = $name ==
'ADDSECTION' ? $sitemap[
'SECTION_PAGE_URL'] : $sitemap[
'DETAIL_PAGE_URL'];
592 $urlType = $name ==
'ADDSECTION' ?
'S' :
'E';
596 'url' => \CIBlock::replaceDetailUrl($url, $fields,
false, $urlType),
597 'lastmod' => MakeTimeStamp($fields[
'TIMESTAMP_X']),
600 $sitemapRuntimeFile->setOriginalFile($sitemapFile);
601 $sitemapRuntimeFile->appendIblockEntry($rule[
'url'], $rule[
'lastmod']);
605 if ($sitemapRuntimeFile->isNotEmpty() && $sitemapRuntimeFile->isCurrentPartNotEmpty())
606 $sitemapRuntimeFile->finish();
608 $sitemapRuntimeFile->delete();
610 $sitemapIndex =
new SitemapIndex($sitemap[
'SITEMAP_FILE'], $sitemap);
611 $sitemapIndex->appendIndexEntry($sitemapFile);
613 if ($sitemap[
'ROBOTS'] ==
'Y')
615 $robotsFile =
new RobotsFile($sitemap[
'SITE_ID']);
616 $robotsFile->addRule(
689 $url = str_replace(
'http://',
'', $url);
690 $url = str_replace(
'https://',
'', $url);
693 if (mb_substr($url, 0, mb_strlen(
'#SERVER_NAME#')) ==
'#SERVER_NAME#')
694 $url = mb_substr($url, mb_strlen(
'#SERVER_NAME#'));
699 $filter = array(
'=LID' => $siteId);
700 $dbSite = SiteTable::getList(array(
702 'select' => array(
'LID',
'DIR',
'SERVER_NAME'),
704 $currentSite = $dbSite->fetch();
705 $serverName = $currentSite[
'SERVER_NAME'];
706 $url = str_replace(
'#SERVER_NAME#', $serverName, $url);