5use \Bitrix\Landing\Internals\HookDataTable as HookData;
7use \Bitrix\Main\EventResult;
56 'BACKGROUND_POSITION',
68 'THEMEFONTS_LINE_HEIGHT',
69 'THEMEFONTS_FONT_WEIGHT',
70 'THEMEFONTS_FONT_WEIGHT_H',
83 if (($handle = opendir($path)))
85 while ((($entry = readdir($handle)) !==
false))
87 if ($entry !=
'.' && $entry !=
'..')
89 $classes[] = mb_strtoupper(pathinfo($entry, PATHINFO_FILENAME));
104 public static function getData($id, $type, $asIs =
false): array
109 if (!is_string($type))
114 $res = HookData::getList([
116 'ID',
'HOOK',
'CODE',
'VALUE'
120 '=ENTITY_TYPE' => $type,
121 '=PUBLIC' => self::$editMode ?
'N' :
'Y'
127 while ($row = $res->fetch())
129 if (!isset($data[$row[
'HOOK']]))
131 $data[$row[
'HOOK']] = [];
133 if (mb_strpos($row[
'VALUE'],
'serialized#') === 0)
135 $row[
'VALUE'] = unserialize(mb_substr($row[
'VALUE'], 11), [
'allowed_classes' =>
false]);
137 $data[$row[
'HOOK']][$row[
'CODE']] = $asIs ? $row : $row[
'VALUE'];
150 protected static function getList($id, $type, array $data = array())
153 $classDir = self::HOOKS_PAGE_DIR;
154 $classNamespace = self::HOOKS_NAMESPACE;
155 $excludedHooks = \Bitrix\Landing\Site\Type::getExcludedHooks();
158 foreach (self::getClassesFromDir($classDir) as $class)
160 if (in_array($class, $excludedHooks))
164 $classFull = __NAMESPACE__ . $classNamespace . $class;
165 if (class_exists($classFull))
167 $hooks[$class] =
new $classFull(
169 !($type == self::ENTITY_TYPE_SITE)
175 uasort($hooks,
function($a, $b)
177 if ($a->getSort() == $b->getSort())
181 return ($a->getSort() < $b->getSort()) ? -1 : 1;
185 $event =
new Event(
'landing',
'onHookExec');
187 foreach ($event->getResults() as $result)
189 if ($result->getType() != EventResult::ERROR)
191 if ($customExec = $result->getModified())
193 foreach ((array)$customExec as $code => $itemExec)
195 $code = mb_strtoupper($code);
196 if (isset($hooks[$code]) && is_callable($itemExec))
198 $hooks[$code]->setCustomExec($itemExec);
201 unset($code, $itemExec);
206 unset($event, $result);
209 if (!empty($hooks) && $id > 0)
213 $data = self::getData($id, $type);
215 foreach ($hooks as $code => $hook)
217 if (isset($data[$code]))
219 $hook->setData($data[$code]);
234 self::$editMode = $mode;
243 return self::$editMode;
253 if (!Landing::getEditMode())
262 if (!array_key_exists($id, $hooks))
264 $hooks[$id] = self::getList($id, self::ENTITY_TYPE_SITE);
277 if (!Landing::getEditMode())
286 if (!array_key_exists($id, $hooks))
288 $hooks[$id] = self::getList($id, self::ENTITY_TYPE_LANDING);
301 return self::getData($id, self::ENTITY_TYPE_LANDING);
312 protected static function copy($from, $to, $type, $publication =
false)
316 $data = self::getData($from, $type);
319 $classDir = self::HOOKS_PAGE_DIR;
320 $classNamespace = self::HOOKS_NAMESPACE;
321 $excludedHooks = \Bitrix\Landing\Site\Type::getExcludedHooks();
324 foreach (self::getClassesFromDir($classDir) as $class)
326 if (in_array($class, $excludedHooks,
true))
330 $classFull = __NAMESPACE__ . $classNamespace . $class;
333 && method_exists($classFull, self::HOOKS_ON_COPY_HANDLER)
336 $handler = self::HOOKS_ON_COPY_HANDLER;
337 if ($preparedData = $classFull::$handler($data[$class], $from, $type, $publication))
339 $data[$class] = $preparedData;
347 $res = HookData::getList([
353 '=ENTITY_TYPE' => $type,
354 '=PUBLIC' => $publication ?
'Y' :
'N'
357 while ($row = $res->fetch())
359 $existData[$row[
'HOOK'] .
'_' . $row[
'CODE']] = $row[
'ID'];
364 foreach ($data as $hookCode => $items)
366 foreach ($items as $code => $value)
368 $existKey = $hookCode .
'_' . $code;
369 if (is_array($value))
371 $value =
'serialized#' . serialize($value);
373 if (array_key_exists($existKey, $existData))
375 HookData::update($existData[$existKey], [
378 unset($existData[$existKey]);
384 'ENTITY_TYPE' => $type,
388 'PUBLIC' => $publication ?
'Y' :
'N'
397 foreach ($existData as $delId)
399 HookData::delete($delId);
412 $originalEditMode = self::$editMode;
413 if (!self::$editMode)
415 self::$editMode =
true;
417 self::copy($from, $to, self::ENTITY_TYPE_SITE);
418 self::$editMode = $originalEditMode;
429 $originalEditMode = self::$editMode;
430 if (!self::$editMode)
432 self::$editMode =
true;
434 self::copy($from, $to, self::ENTITY_TYPE_LANDING);
435 self::$editMode = $originalEditMode;
445 self::copy($siteId, $siteId, self::ENTITY_TYPE_SITE,
true);
455 self::copy($lid, $lid, self::ENTITY_TYPE_LANDING,
true);
465 self::publicationWithSkipNeededPublication($siteId, self::ENTITY_TYPE_SITE);
475 self::publicationWithSkipNeededPublication($landingId, self::ENTITY_TYPE_LANDING);
480 $editModeBack = self::$editMode;
481 self::$editMode =
false;
482 $publicData = self::getData($id, $type,
true);
483 self::$editMode = $editModeBack;
485 if ($type === self::ENTITY_TYPE_SITE)
487 self::publicationSite($id);
489 if ($type === self::ENTITY_TYPE_LANDING)
491 self::publicationLanding($id);
493 $data = self::getData($id, $type,
true);
496 $needClearCache =
false;
497 foreach (self::getList($id, $type) as $hook)
499 if ($hook->isNeedPublication())
501 $fieldsToDelete = [];
502 if (isset($publicData[$hook->getCode()]))
504 foreach ($data[$hook->getCode()] as $fieldCode => $field)
506 if (!isset($publicData[$hook->getCode()][$fieldCode]))
508 $fieldsToDelete[$fieldCode] = $field;
510 elseif ($publicData[$hook->getCode()][$fieldCode][
'VALUE'] !== $field[
'VALUE'])
512 $needClearCache =
true;
513 HookData::update($field[
'ID'],
515 'VALUE' => $field[
'VALUE'],
523 $fieldsToDelete = $data[$hook->getCode()] ?? [];
527 if (!empty($fieldsToDelete))
529 $needClearCache =
true;
530 foreach ($fieldsToDelete as $fieldCode => $field)
532 $res = HookData::getList([
536 '=ENTITY_TYPE' => $type,
537 '=HOOK' => $hook->getCode(),
538 '=CODE' => $fieldCode,
542 if ($row = $res->fetch())
544 HookData::delete($row[
'ID']);
554 if ($type === self::ENTITY_TYPE_SITE)
564 while ($landing = $landings->fetch())
569 if ($type === self::ENTITY_TYPE_LANDING)
585 foreach ($data as $code => $val)
587 if (mb_strpos($code,
'_') !==
false)
589 $codeHook = mb_substr($code, 0, mb_strpos($code,
'_'));
590 $codeVal = mb_substr($code, mb_strpos($code,
'_') + 1);
591 if (!isset($newData[$codeHook]))
593 $newData[$codeHook] = array();
595 $newData[$codeHook][$codeVal] = $val;
609 protected static function saveData($id, $type, array $data)
611 $data = self::prepareData($data);
612 $hooks = self::getList($id, $type, $data);
613 $dataSave = self::getData($id, $type,
true);
616 foreach ($hooks as $hook)
618 $hookLocked = $hook->isLocked();
619 $codeHook = $hook->getCode();
621 foreach ($hook->getFields() as $field)
623 $codeVal = $field->getCode();
624 if ($hookLocked && !$field->isEmptyValue())
628 if (!isset($data[$codeHook][$codeVal]))
633 if (isset($dataSave[$codeHook][$codeVal]))
635 $dataSave[$codeHook][$codeVal][
'CHANGED'] =
true;
636 $dataSave[$codeHook][$codeVal][
'VALUE'] = $field->getValue();
641 if (!isset($dataSave[$codeHook]))
643 $dataSave[$codeHook] = array();
645 $dataSave[$codeHook][$codeVal] = array(
648 'VALUE' => $field->getValue()
651 if (is_array($dataSave[$codeHook][$codeVal][
'VALUE']))
653 $dataSave[$codeHook][$codeVal][
'VALUE'] =
'serialized#' . serialize(
654 $dataSave[$codeHook][$codeVal][
'VALUE']
661 foreach ($dataSave as $codeHook => $dataHook)
663 foreach ($dataHook as $code => $row)
666 is_array($row[
'VALUE']) && empty($row[
'VALUE'])
668 !is_array($row[
'VALUE']) && trim($row[
'VALUE']) ==
''
671 if (isset($row[
'ID']))
673 HookData::delete($row[
'ID']);
678 if (!isset($row[
'ID']))
680 $row[
'ENTITY_ID'] = $id;
681 $row[
'ENTITY_TYPE'] = $type;
684 elseif (isset($row[
'CHANGED']) && $row[
'CHANGED'])
687 unset($row[
'ID'], $row[
'CHANGED']);
688 HookData::update($updId, $row);
705 if ($type == self::ENTITY_TYPE_LANDING)
707 $class =
'\Bitrix\Landing\Landing';
716 $searchContent = $class::getList([
718 'TITLE',
'DESCRIPTION'
722 '=DELETED' => [
'Y',
'N'],
723 '=SITE.DELETED' => [
'Y',
'N']
731 $searchContent = array_values($searchContent);
734 foreach (self::getList($id, $type) as $hook)
736 foreach ($hook->getFields() as $field)
738 if ($field->isSearchable())
740 $searchContent[] = $field->getValue();
745 $searchContent = array_unique($searchContent);
746 $searchContent = $searchContent ? implode(
' ', $searchContent) :
'';
747 $searchContent = trim($searchContent);
751 $res = $class::update($id, [
752 'SEARCH_CONTENT' => $searchContent
766 $check = Site::getList([
776 $editModeBack = self::$editMode;
777 self::$editMode =
true;
778 self::saveData($id, self::ENTITY_TYPE_SITE, $data);
781 self::publicationSiteWithSkipNeededPublication($id);
783 self::$editMode = $editModeBack;
805 $editModeBack = self::$editMode;
806 self::$editMode =
true;
807 self::saveData($id, self::ENTITY_TYPE_LANDING, $data);
808 self::indexContent($id, self::ENTITY_TYPE_LANDING);
811 self::publicationLandingWithSkipNeededPublication($id);
813 self::$editMode = $editModeBack;
824 self::indexContent($id, self::ENTITY_TYPE_LANDING);
837 $res = HookData::getList(array(
843 '=ENTITY_TYPE' => $type
846 while ($row = $res->fetch())
848 HookData::delete($row[
'ID']);
859 self::deleteData($id, self::ENTITY_TYPE_SITE);
869 self::deleteData($id, self::ENTITY_TYPE_LANDING);
static copySite($from, $to)
static publicationSite($siteId)
static saveData($id, $type, array $data)
static getClassesFromDir($dir)
static getForLanding($id)
const HOOKS_ON_COPY_HANDLER
static deleteForSite($id)
static publicationLanding($lid)
static copyLanding($from, $to)
static getList($id, $type, array $data=array())
static indexContent($id, $type)
static getData($id, $type, $asIs=false)
static getForLandingRow($id)
static publicationWithSkipNeededPublication($id, $type)
static publicationLandingWithSkipNeededPublication($landingId)
static setEditMode(bool $mode=true)
static saveForSite(int $id, array $data)
static saveForLanding(int $id, array $data)
static deleteData($id, $type)
const ENTITY_TYPE_LANDING
static prepareData(array $data)
static publicationSiteWithSkipNeededPublication($siteId)
static copy($from, $to, $type, $publication=false)
static deleteForLanding($id)
static getOption($code, $default=null)
static update($primary, array $data)
static getList(array $parameters=array())