4use \Bitrix\Landing\Hook;
5use \Bitrix\Landing\Manager;
6use \Bitrix\Landing\File;
7use \Bitrix\Landing\Folder;
8use \Bitrix\Landing\Site;
10use \Bitrix\Landing\TemplateRef;
12use \Bitrix\Landing\PublicActionResult;
13use \Bitrix\Landing\Internals\HookDataTable;
14use \Bitrix\Landing\History;
15use \Bitrix\Main\Localization\Loc;
28 $disallow = [
'RULE',
'TPL_CODE',
'ACTIVE',
'INITIATOR_APP_CODE',
'VIEWS'];
30 if (is_array($fields))
32 foreach ($fields as $k => $v)
34 if (in_array($k, $disallow))
52 $landing = LandingCore::createInstance($lid, [
56 if ($landing->exist())
58 $result->setResult($landing->getPreview());
60 $result->setError($landing->getError());
73 $landing = LandingCore::createInstance($lid, [
77 if ($landing->exist())
80 $landing->getPublicUrl()
83 $result->setError($landing->getError());
97 $result->setResult(LandingCore::resolveIdByPublicUrl($landingUrl, $siteId));
109 $landing = LandingCore::createInstance($lid, [
110 'skip_blocks' =>
true
113 if ($landing->exist())
115 $fields = $landing->getAdditionalFields($landing->getId());
116 foreach ($fields as $key => $field)
118 $fields[$key] = $field->getValue();
121 unset($fields[$key]);
128 $result->setError($landing->getError());
141 $landing = LandingCore::createInstance($lid, [
142 'skip_blocks' =>
true
145 if ($landing->exist())
147 if ($landing->publication())
149 $result->setResult(
true);
153 $result->setError($landing->getError());
166 $landing = LandingCore::createInstance($lid, [
167 'skip_blocks' =>
true
170 if ($landing->exist())
177 $result->setError($landing->getError());
189 public static function addBlock($lid, array $fields,
bool $preventHistory =
false)
191 LandingCore::setEditMode();
195 $landing = LandingCore::createInstance($lid);
196 if ($landing->exist())
201 if (isset($fields[
'ACTIVE']))
203 $data[
'ACTIVE'] = $fields[
'ACTIVE'];
205 if (isset($fields[
'CONTENT']))
213 if (isset($fields[
'AFTER_ID']))
215 $blocks = $landing->getBlocks();
216 if (isset($blocks[$fields[
'AFTER_ID']]))
218 $data[
'SORT'] = $blocks[$fields[
'AFTER_ID']]->getSort() + 1;
226 $newBlockId = $landing->addBlock($fields[
'CODE'] ??
'', $data,
true);
227 $landing->resortBlocks();
231 isset($fields[
'RETURN_CONTENT']) &&
232 $fields[
'RETURN_CONTENT'] ==
'Y'
235 $return = BlockCore::getBlockContent($newBlockId,
true);
239 $return = $newBlockId;
241 $result->setResult($return);
243 $result->setError($landing->getError());
255 LandingCore::setEditMode();
258 $landing = LandingCore::createInstance($lid);
259 if ($landing->exist())
261 $result->setResult($landing->deleteBlock($block));
262 $landing->resortBlocks();
264 $result->setError($landing->getError());
278 LandingCore::setEditMode();
281 $landing = LandingCore::createInstance($lid);
282 if ($landing->exist())
286 $landing->markDeletedBlock($block, $mark)
288 $landing->resortBlocks();
290 $result->setError($landing->getError());
303 return self::markDeletedBlock($lid, $block,
false, $preventHistory);
313 private static function sort(
int $lid,
int $block,
string $action):
PublicActionResult
316 $landing = LandingCore::createInstance($lid);
317 if ($landing->exist())
319 if ($action ===
'up')
321 $result->setResult($landing->upBlock($block));
325 $result->setResult($landing->downBlock($block));
327 if ($landing->getError()->isEmpty())
329 $landing->resortBlocks();
332 $result->setError($landing->getError());
346 LandingCore::setEditMode();
349 return self::sort($lid, $block,
'up');
361 LandingCore::setEditMode();
364 return self::sort($lid, $block,
'down');
377 LandingCore::setEditMode();
378 $landing = LandingCore::createInstance($lid);
379 if ($landing->exist())
381 $result->setResult($landing->favoriteBlock($block, $meta));
383 $result->setError($landing->getError());
395 LandingCore::setEditMode();
396 $landing = LandingCore::createInstance(0);
397 $delResult = $landing->unFavoriteBlock($blockId);
400 $result->setResult($delResult);
404 $result->setError($landing->getError());
416 private static function activate($lid, $block, $action)
419 $landing = LandingCore::createInstance($lid);
420 if ($landing->exist())
422 if ($action ==
'show')
424 $result->setResult($landing->showBlock($block));
428 $result->setResult($landing->hideBlock($block));
431 $result->setError($landing->getError());
443 LandingCore::setEditMode();
444 return self::activate($lid, $block,
'show');
455 LandingCore::setEditMode();
456 return self::activate($lid, $block,
'hide');
466 private static function changeParentOfBlock($lid, $block, array $params)
469 $landing = LandingCore::createInstance($lid);
470 $afterId = isset($params[
'AFTER_ID']) ? $params[
'AFTER_ID'] : 0;
471 if ($landing->exist())
475 $res = $landing->moveBlock($block, $afterId);
479 $res = $landing->copyBlock($block, $afterId);
483 isset($params[
'RETURN_CONTENT']) &&
484 $params[
'RETURN_CONTENT'] ==
'Y'
487 $result->setResult(array(
488 'result' => $res > 0,
489 'content' => BlockCore::getBlockContent($res,
true)
494 $result->setResult($res);
497 $result->setError($landing->getError());
508 public static function copyBlock($lid, $block, array $params = array())
510 if (!is_array($params))
514 $params[
'MOVE'] =
false;
515 LandingCore::setEditMode();
516 return self::changeParentOfBlock($lid, $block, $params);
526 public static function moveBlock($lid, $block, array $params = array())
528 if (!is_array($params))
532 $params[
'MOVE'] =
true;
533 LandingCore::setEditMode();
534 return self::changeParentOfBlock($lid, $block, $params);
547 LandingCore::setEditMode();
548 $landing = LandingCore::createInstance($lid);
550 if ($landing->exist())
552 $blocks = $landing->getBlocks();
553 if (isset($data[
'blocks']) && is_array($data[
'blocks']))
555 foreach ($data[
'blocks'] as $block)
557 self::deleteBlock($lid, $block);
558 unset($blocks[$block]);
561 if (isset($data[
'images']) && is_array($data[
'images']))
563 foreach ($data[
'images'] as $item)
565 if (isset($blocks[$item[
'block']]))
571 $result->setResult(
true);
574 $result->setError($landing->getError());
587 $params = $result->sanitizeKeys($params);
588 $landingFake = LandingCore::createInstance(0);
593 if ($params[
'filter'][
'SITE_ID'] ??
null)
595 $siteId = $params[
'filter'][
'SITE_ID'];
596 if (is_array($siteId))
598 $siteId = array_shift($siteId);
600 $params[
'filter'][] = [
602 [
'FOLDER_ID' =>
null],
607 if (isset($params[
'get_preview']))
609 $getPreview = !!$params[
'get_preview'];
610 unset($params[
'get_preview']);
613 if (isset($params[
'get_urls']))
615 $getUrls = !!$params[
'get_urls'];
616 unset($params[
'get_urls']);
619 if (isset($params[
'check_area']))
621 $checkArea = !!$params[
'check_area'];
622 unset($params[
'check_area']);
625 if (isset($params[
'filter'][
'CHECK_PERMISSIONS']))
627 unset($params[
'filter'][
'CHECK_PERMISSIONS']);
634 $params[
'select'] = $params[
'select'] ?? [
'*'];
635 $params[
'select'][
'DOMAIN_ID'] =
'SITE.DOMAIN_ID';
637 while ($row = $res->fetch())
639 $rows[$row[
'ID']] = $row;
642 if ($getPreview || $getUrls)
644 $publicUrls = LandingCore::createInstance(0)->getPublicUrl(array_keys($rows));
647 foreach ($rows as $row)
649 if (isset($row[
'DATE_CREATE']))
651 $row[
'DATE_CREATE'] = (string) $row[
'DATE_CREATE'];
653 if (isset($row[
'DATE_MODIFY']))
655 $row[
'DATE_MODIFY'] = (string) $row[
'DATE_MODIFY'];
657 if ($getUrls && isset($row[
'ID']))
659 $row[
'PUBLIC_URL'] = $publicUrls[$row[
'ID']];
661 if ($getPreview && isset($row[
'ID']))
663 if ($row[
'DOMAIN_ID'] == 0)
665 \Bitrix\Landing\Hook::setEditMode(
true);
667 $row[
'PREVIEW'] = $landingFake->getPreview(
669 $row[
'DOMAIN_ID'] == 0,
670 $publicUrls[$row[
'ID']]
673 if ($checkArea && isset($row[
'ID']))
675 $data[$row[
'ID']] = $row;
690 foreach ($areas as $lid => $isA)
692 $data[$lid][
'IS_AREA'] = $isA;
696 $result->setResult(array_values($data));
712 if (isset($fields[
'BLOCK_ID']))
714 $blockId = (int)$fields[
'BLOCK_ID'];
715 unset($fields[
'BLOCK_ID']);
717 if (isset($fields[
'MENU_CODE']))
719 $menuCode = $fields[
'MENU_CODE'];
720 unset($fields[
'MENU_CODE']);
723 if (!$blockId || !$menuCode || !is_string($menuCode))
731 function(\
Bitrix\Main\
Event $event) use ($blockId, $menuCode)
733 $primary = $event->getParameter(
'primary');
734 $fields = $event->getParameter(
'fields');
738 $landingId = BlockCore::getLandingIdByBlockId($blockId);
744 'text' => $fields[
'TITLE'],
745 'href' =>
'#landing' . $primary[
'ID']
753 [
'appendMenu' =>
true]
769 public static function add(array $fields)
772 $error = new \Bitrix\Landing\Error;
774 $fields = self::clearDisallowFields($fields);
775 $fields[
'ACTIVE'] =
'N';
777 $fields = self::checkAddingInMenu($fields);
781 if ($res->isSuccess())
783 $result->setResult($res->getId());
787 $error->addFromResult($res);
788 $result->setError($error);
804 $error = new \Bitrix\Landing\Error;
807 $siteId = intval($siteId);
808 $fields = self::checkAddingInMenu($fields, $willAdded);
810 $res = LandingCore::addByTemplate($siteId, $code, $fields);
812 if ($res->isSuccess())
814 $result->setResult($res->getId());
817 isset($fields[
'ADD_IN_MENU']) &&
818 isset($fields[
'TITLE']) &&
819 $fields[
'ADD_IN_MENU'] ==
'Y'
823 'ID' => $res->getId(),
824 'TITLE' => $fields[
'TITLE']
830 $error->addFromResult($res);
831 $result->setError($error);
843 public static function update($lid, array $fields)
846 $error = new \Bitrix\Landing\Error;
848 $fields = self::clearDisallowFields($fields);
852 if ($res->isSuccess())
854 $result->setResult(
true);
858 $error->addFromResult($res);
859 $result->setError($error);
870 public static function delete($lid)
873 $error = new \Bitrix\Landing\Error;
877 if ($res->isSuccess())
879 $result->setResult(
true);
883 $error->addFromResult($res);
884 $result->setError($error);
900 $landing = LandingCore::createInstance($lid);
901 $result->setResult($landing->move($toSiteId ?:
null, $toFolderId ?:
null));
902 $result->setError($landing->getError());
914 public static function copy(
int $lid, ?
int $toSiteId =
null, ?
int $toFolderId =
null,
bool $skipSystem =
false):
PublicActionResult
918 LandingCore::disableCheckDeleted();
919 $landing = LandingCore::createInstance($lid);
920 $result->setResult($landing->copy($toSiteId ?:
null, $toFolderId ?:
null,
false,
Utils::isTrue($skipSystem)));
921 $result->setError($landing->getError());
922 LandingCore::enableCheckDeleted();
936 $error = new \Bitrix\Landing\Error;
940 $res = LandingCore::markDelete($lid);
944 $res = LandingCore::markUnDelete($lid);
946 if ($res->isSuccess())
948 $result->setResult($res->getId());
952 $error->addFromResult($res);
953 $result->setError($error);
966 return self::markDelete($lid,
false);
977 public static function uploadFile($lid, $picture, $ext =
false, array $params = array())
979 static $internal =
true;
980 static $mixedParams = [
'picture'];
983 $error = new \Bitrix\Landing\Error;
986 $landing = LandingCore::createInstance($lid, [
987 'skip_blocks' =>
true
990 if ($landing->exist())
996 $result->setResult(array(
998 'src' => $file[
'SRC']
1007 $result->setError($error);
1011 $result->setError($landing->getError());
1024 static $internal =
true;
1026 $lid = intval($lid);
1028 $landing = LandingCore::createInstance($lid, [
1029 'skip_blocks' =>
true
1031 $result->setResult(
false);
1033 if ($landing->exist())
1036 $content = str_replace(
'<st yle',
'<style', $content);
1037 $content = str_replace(
'<li nk ',
'<link ', $content);
1040 'ENTITY_ID' => $lid,
1046 $res = HookDataTable::getList(array(
1052 if ($row = $res->fetch())
1054 $existsContent = $row[
'VALUE'];
1057 $found = preg_match_all(
1058 '#(<noscript>.*?<style.*?data-id="([^"]+)"[^>]*>[^<]+</style>)#is',
1064 foreach ($newFonts[1] as $i => $newFont)
1066 if (mb_strpos($existsContent,
'"' . $newFonts[2][$i] .
'"') ===
false)
1068 $existsContent .= $newFont;
1073 if ($existsContent != $row[
'VALUE'])
1075 HookDataTable::update(
1077 [
'VALUE' => $existsContent]
1083 $fields[
'VALUE'] = $content;
1084 HookDataTable::add($fields);
1093 $result->setResult(
true);
1096 $result->setError($landing->getError());
static addToLanding($lid, $fileId)
static deleteFromBlock($blockId, $fileId=array())
static getFolderIdsForSite(int $siteId, array $additionalFilter=[])
static publicationLanding($lid)
static setEditMode(bool $mode=true)
const ENTITY_TYPE_LANDING
static callback($code, $callback)
static getOption($code, $default=null)
static sanitize($value, &$bad=false, $splitter=' ')
static savePicture($file, $ext=false, $params=array())
static removeEntities($lid, array $data)
static copy(int $lid, ?int $toSiteId=null, ?int $toFolderId=null, bool $skipSystem=false)
static showBlock($lid, $block)
static updateHead($lid, $content)
static addByTemplate($siteId, $code, array $fields=[])
static copyBlock($lid, $block, array $params=array())
static update($lid, array $fields)
static markUnDeletedBlock(int $lid, int $block, bool $preventHistory=false)
static unFavoriteBlock(int $blockId)
static getPublicUrl($lid)
static checkAddingInMenu(array $fields, ?bool &$willAdded=null)
static getList(array $params=[])
static hideBlock($lid, $block)
static clearDisallowFields(array $fields)
static markDelete($lid, $mark=true)
static downBlock(int $lid, int $block, bool $preventHistory=false)
static addBlock($lid, array $fields, bool $preventHistory=false)
static uploadFile($lid, $picture, $ext=false, array $params=array())
static getAdditionalFields($lid)
static resolveIdByPublicUrl(string $landingUrl, int $siteId)
static upBlock(int $lid, int $block, bool $preventHistory=false)
static favoriteBlock(int $lid, int $block, array $meta=[])
static move(int $lid, ?int $toSiteId=null, ?int $toFolderId=null)
static add(array $fields)
static moveBlock($lid, $block, array $params=array())
static deleteBlock($lid, $block)
static markUnDelete($lid)
static markDeletedBlock(int $lid, int $block, bool $mark=true, bool $preventHistory=false)
static addLandingToMenu(int $siteId, array $data)
static landingIsArea($lid)
static update($primary, array $data)
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
static getList(array $parameters=array())