5use \Bitrix\Landing\Manager;
6use \Bitrix\Landing\File;
7use \Bitrix\Landing\Landing;
8use \Bitrix\Landing\Hook;
9use \Bitrix\Landing\Assets;
10use \Bitrix\Landing\Restriction;
12use \Bitrix\Main\Localization\Loc;
13use \Bitrix\Landing\PublicActionResult;
28 private static function cardAction($action, $lid, $block, $selector, array $params = array())
30 $error = new \Bitrix\Landing\Error;
36 if ($landing->exist())
38 $block = intval($block);
39 $blocks = $landing->getBlocks();
40 if (isset($blocks[$block]))
43 if (mb_strpos($selector,
'@') !==
false)
45 [$selector, $position] = explode(
'@', $selector);
52 mb_strtolower($action) ==
'clonecard' &&
53 isset($params[
'content'])
56 $res = $blocks[$block]->$action(
60 $params[
'content'], $bad
66 $res = $blocks[$block]->$action($selector, $position);
70 $result->setResult($blocks[$block]->save());
72 if ($blocks[$block]->getError()->isEmpty())
76 $result->setError($blocks[$block]->getError());
86 $result->setError($landing->getError());
87 $result->setError($error);
99 public static function cloneCard($lid, $block, $selector,
bool $preventHistory =
false)
104 return self::cardAction(
'cloneCard', $lid, $block, $selector);
116 public static function addCard($lid, $block, $selector, $content,
bool $preventHistory =
false)
121 return self::cardAction(
127 'content' => $content
140 public static function removeCard($lid, $block, $selector,
bool $preventHistory =
false)
145 return self::cardAction(
'removeCard', $lid, $block, $selector);
157 $error = new \Bitrix\Landing\Error;
163 'blocks_id' => $block
165 if ($landing->exist())
167 $block = intval($block);
168 $blocks = $landing->getBlocks();
169 if (isset($blocks[$block]))
171 $currBlock = $blocks[$block];
172 $currBlock->updateCards((array)$data);
173 $result->setResult($currBlock->save());
174 $result->setError($currBlock->getError());
175 if ($currBlock->getError()->isEmpty())
188 $result->setError($landing->getError());
189 $result->setError($error);
202 public static function changeNodeName($lid, $block, array $data,
bool $preventHistory =
false)
204 $error = new \Bitrix\Landing\Error;
213 foreach ($data as $selector => $value)
215 if (mb_strpos($selector,
'@') !==
false)
217 [$selector, $position] = explode(
'@', $selector);
223 if (!isset($content[$selector]))
225 $content[$selector] = array();
227 $content[$selector][$position] = $value;
230 if (!empty($content))
233 'blocks_id' => $block
236 if ($landing->exist())
238 $block = intval($block);
239 $blocks = $landing->getBlocks();
240 if (isset($blocks[$block]))
242 $blocks[$block]->changeNodeName($content);
243 $result->setResult($blocks[$block]->save());
244 $result->setError($blocks[$block]->getError());
245 if ($blocks[$block]->getError()->isEmpty())
258 $result->setError($landing->getError());
279 public static function changeAnchor($lid, $block, $data,
bool $preventHistory =
false)
281 $error = new \Bitrix\Landing\Error;
289 'blocks_id' => $block
292 if ($landing->exist())
294 $block = intval($block);
295 $blocks = $landing->getBlocks();
296 if (isset($blocks[$block]))
298 $blocks[$block]->setAnchor($data);
299 $result->setResult($blocks[$block]->save());
300 $result->setError($blocks[$block]->getError());
301 if ($blocks[$block]->getError()->isEmpty())
314 $result->setError($landing->getError());
328 public static function updateNodes($lid, $block, array $data, array $additional = array(),
bool $preventHistory =
false)
330 $error = new \Bitrix\Landing\Error;
333 $attributes = array();
334 $components = array();
336 $data = (array) $data;
337 $dynamicParamsExists =
false;
338 $block = intval($block);
344 if (isset($data[
'dynamicState']) || isset($data[
'dynamicBlock']))
346 $dynamicParamsExists =
true;
348 'blocks_id' => $block
350 if ($landing->exist())
352 if ($blockCurrent = $landing->getBlockById($block))
354 $manifest = $blockCurrent->getManifest();
356 !isset($manifest[
'block'][
'dynamic']) ||
357 $manifest[
'block'][
'dynamic'] !==
false
361 if (isset($data[
'dynamicParams']))
363 $dynamicParams = $data[
'dynamicParams'];
364 unset($data[
'dynamicParams']);
368 $dynamicParams = $blockCurrent->getDynamicParams();
371 if (isset($data[
'dynamicState']))
373 foreach ((array) $data[
'dynamicState'] as $selector => $flag)
375 if (!
Utils::isTrue($flag) && isset($dynamicParams[$selector]))
377 unset($dynamicParams[$selector]);
381 $blockCurrent->saveDynamicParams(
385 $result->setResult(
true);
393 $result->setError($error);
396 $result->setError($landing->getError());
400 if (!$result->getError()->isEmpty())
406 foreach ($data as $selector => $value)
408 if (mb_strpos($selector,
'@') !==
false)
410 [$selector, $position] = explode(
'@', $selector);
416 if (!isset($data[$selector]))
418 $data[$selector] = array();
420 if (isset($value[
'attrs']) && count($value) == 1)
422 if (mb_strpos($selector,
':') !==
false)
424 $components[$selector] = $value[
'attrs'];
428 $attributes[$selector][$position] = $value[
'attrs'];
433 if (!isset($content[$selector]))
435 $content[$selector] = array();
437 $content[$selector][max(0, $position)] = $value;
442 if (!empty($content) || !empty($attributes) || !empty($components))
444 if (!isset($landing))
447 'blocks_id' => $block
451 if ($landing->exist())
453 $blocks = $landing->getBlocks();
454 if (isset($blocks[$block]))
456 if (!empty($content))
458 $blocks[$block]->updateNodes($content, $additional);
460 if (!empty($attributes))
462 $blocks[$block]->setAttributes($attributes);
464 if (!empty($components))
467 if (!$blocks[$block]->getRepoId())
469 $manifest = $blocks[$block]->getManifest();
470 foreach ($components as $selector => &$attrs)
473 isset($manifest[
'nodes'][$selector][
'waf_ignore']) &&
474 $manifest[
'nodes'][$selector][
'waf_ignore']
477 $rawData = \Bitrix\Landing\PublicAction::getRawData();
478 if (isset($rawData[
'data'][$selector][
'attrs']))
480 $rawAttrs = $rawData[
'data'][$selector][
'attrs'];
481 foreach ($attrs as $attCode => &$attValue)
483 $attValue = $rawAttrs[$attCode];
484 $attValue = \Bitrix\Main\Text\Encoding::convertEncoding(
495 $blocks[$block]->updateNodes($components, $additional);
498 $blocks[$block]->saveContent(
500 'contenteditable="true"',
505 $result->setResult($blocks[$block]->save());
506 $result->setError($blocks[$block]->getError());
507 if ($blocks[$block]->getError()->isEmpty())
520 $result->setError($landing->getError());
522 else if (!$dynamicParamsExists)
530 $result->setError($error);
543 private static function updateAttributes($lid, $block, array $data, $method)
545 $error = new \Bitrix\Landing\Error;
552 'blocks_id' => $block
554 if ($landing->exist())
556 $block = intval($block);
557 $blocks = $landing->getBlocks();
558 if (isset($blocks[$block]))
560 if (is_callable(array($blocks[$block], $method)))
562 $blocks[$block]->$method($data);
564 $result->setResult($blocks[$block]->save());
565 $result->setError($blocks[$block]->getError());
566 if ($blocks[$block]->getError()->isEmpty())
579 $result->setError($landing->getError());
580 $result->setError($error);
593 public static function updateStyles($lid, $block, array $data,
bool $preventHistory =
false)
598 foreach ($data as $selector => $value)
600 $lastResult = self::updateAttributes($lid, $block, [$selector => $value],
'setClasses');
614 foreach ($data as $selector => $value)
616 if (mb_strpos($selector,
'@') !==
false)
618 unset($data[$selector]);
619 [$selector, $pos] = explode(
'@', $selector);
621 !isset($data[$selector]) ||
622 !is_array($data[$selector])
625 $data[$selector] = [];
627 $data[$selector][$pos] = $value;
630 return self::updateAttributes($lid, $block, $data,
'setAttributes');
641 public static function getContent($lid, $block, $editMode =
false, array $params = array())
644 $error = new \Bitrix\Landing\Error;
653 'blocks_id' => $block
656 if ($landing->exist())
658 $block = intval($block);
659 $blocks = $landing->getBlocks();
660 if (isset($blocks[$block]))
662 if (!is_array($params))
668 BlockCore::getBlockContent(
669 $blocks[$block]->getId(),
683 $result->setError($landing->getError());
697 public static function updateContent($lid, $block, $content, $designed =
false,
bool $preventHistory =
false)
700 $error = new \Bitrix\Landing\Error;
706 if (!Restriction\Manager::isAllowed(
'limit_crm_superblock'))
712 if (strpos($content,
'block-wrapper'))
714 $content = preg_replace(
'/^<div.*?class="[^"]*block-wrapper[\s"][^>]+>(.*?)<\/div>$/is',
'$1', $content);
718 'blocks_id' => $block
721 if ($landing->exist())
723 $block = intval($block);
724 $blocks = $landing->getBlocks();
725 if (isset($blocks[$block]))
737 $filesRest = array_intersect($filesBeforeSave, $filesAfterSave);
739 foreach ($filesBeforeSave as $fileId)
741 if (!in_array($fileId, $filesRest))
743 $filesDelete[] = $fileId;
751 if (!$preventHistory)
755 $history->push(
'UPDATE_CONTENT', [
756 'block' => $blocks[$block]->getId(),
757 'contentBefore' => $blocks[$block]->
getContent(),
758 'contentAfter' => $newContent,
759 'designed' => $designed,
768 $blocks[$block]->saveContent(
772 Assets\PreProcessing::blockUpdateNodeProcessing(
776 $blocks[$block]->save()
778 $result->setError($blocks[$block]->getError());
788 $result->setError($landing->getError());
802 $lid = BlockCore::getLandingIdByBlockId($block);
806 if ($landing->exist())
808 $result->setResult($landing->publication($block));
810 $result->setError($landing->getError());
822 public static function getList($lid, array $params = array())
824 static $mixedParams = [
'lid'];
827 $lids = is_array($lid) ? $lid : [$lid];
831 isset($params[
'edit_mode']) &&
840 foreach ($lids as $lid)
844 'deleted' => isset($params[
'deleted']) && $params[
'deleted']
846 if ($landing->exist())
848 foreach ($landing->getBlocks() as $i => $block)
850 if ($manifest = $block->getManifest())
853 'id' => $block->getId(),
855 'code' => $block->getCode(),
856 'name' => $manifest[
'block'][
'name'],
857 'active' => $block->isActive(),
858 'meta' => $block->getMeta()
862 foreach ($data[$i][
'meta'] as &$meta)
864 $meta = (string)$meta;
870 isset($params[
'get_content']) &&
871 $params[
'get_content']
875 $block->view(
false, $landing);
876 $data[$i][
'content'] = ob_get_contents();
877 $data[$i][
'css'] = $block->getCSS();
878 $data[$i][
'js'] = $block->getJS();
884 $result->setError($landing->getError());
887 $result->setResult(array_values($data));
898 public static function getById($block, array $params = array())
900 $error = new \Bitrix\Landing\Error;
902 $block = (int)$block;
905 $lid = BlockCore::getLandingIdByBlockId($block);
909 $blocks = self::getList($lid, $params)->getResult();
910 foreach ($blocks as $item)
912 if ($item[
'id'] == $block)
914 $result->setResult($item);
924 $result->setError($error);
936 public static function getManifest($lid, $block, array $params = array())
938 $error = new \Bitrix\Landing\Error;
942 isset($params[
'edit_mode']) &&
950 'blocks_id' => $block
953 if ($landing->exist())
955 $block = intval($block);
956 $blocks = $landing->getBlocks();
957 if (isset($blocks[$block]))
959 $manifest = $blocks[$block]->getManifest();
960 $manifest[
'preview'] = $blocks[$block]->getPreview();
961 $manifest[
'assets'] = $blocks[$block]->getAsset();
962 $result->setResult($manifest);
973 $result->setError($landing->getError());
974 $result->setError($error);
988 if (mb_strpos(
$code,
':') ===
false)
993 $manifest = BlockCore::getManifestFile(
$code);
994 $result->setResult($manifest);
1009 BlockCore::getContentFromRepository(
$code)
1024 $repo = \Bitrix\Landing\Block::getRepository($withManifest);
1026 if ($section ===
null)
1028 $result->setResult($repo);
1033 (is_string($section) && isset($repo[$section])) ? $repo[$section] : false
1051 static $mixedParams = [
'picture'];
1054 $error = new \Bitrix\Landing\Error;
1055 $block = intval($block);
1058 BlockCore::getLandingIdByBlockId($block),
1059 [
'skip_blocks' =>
true]
1062 if ($landing->exist())
1068 $result->setResult(array(
1069 'id' => $file[
'ID'],
1070 'src' => $file[
'SRC']
1079 $result->setError($error);
1088 $result->setError($error);
1101 static $internal =
true;
1104 $result->setResult(
null);
1108 $result->setResult([
1109 'ID' => $file[
'OBJECT_ID'],
1110 'NAME' => $file[
'NAME']
static getFileInfo(int $objectId, bool $checkRights=true, bool $copyInLocalStorage=false)
static addToBlock(int $blockId, $fileId, bool $temp=false)
static deleteFromBlock($blockId, $fileId=array())
static getFilesFromBlockContent($blockId, $content)
const ENTITY_TYPE_LANDING
static setEditMode(bool $mode=true)
static setEditMode($mode=true)
static createInstance($id, array $params=array())
static sanitize($value, &$bad=false, $splitter=' ')
static savePicture($file, $ext=false, $params=array())
static getById($block, array $params=array())
static cloneCard($lid, $block, $selector, bool $preventHistory=false)
static publication(int $block)
static getManifestFile($code)
static addCard($lid, $block, $selector, $content, bool $preventHistory=false)
static removeCard($lid, $block, $selector, bool $preventHistory=false)
static getContentFromRepository($code)
static uploadFile($block, $picture, $ext=false, array $params=[], $temp=false)
static updateCards($lid, $block, array $data)
static updateStyles($lid, $block, array $data, bool $preventHistory=false)
static getFileDisk(int $fileId)
static getContent($lid, $block, $editMode=false, array $params=array())
static getRepository($section=null, $withManifest=false)
static getManifest($lid, $block, array $params=array())
static updateAttrs($lid, $block, array $data)
static changeNodeName($lid, $block, array $data, bool $preventHistory=false)
static updateContent($lid, $block, $content, $designed=false, bool $preventHistory=false)
static getList($lid, array $params=array())
static updateNodes($lid, $block, array $data, array $additional=array(), bool $preventHistory=false)
static changeAnchor($lid, $block, $data, bool $preventHistory=false)
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)