Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
text.php
1<?php
2namespace Bitrix\Landing\Node;
3
5
7{
12 public static function getHandlerJS()
13 {
14 return 'BX.Landing.Node.Text';
15 }
16
25 public static function saveNode(\Bitrix\Landing\Block $block, $selector, array $data, $additional = []): array
26 {
27 $result = [];
28 $doc = $block->getDom();
29 $resultList = $doc->querySelectorAll($selector);
30 $additional['sanitize'] = !isset($additional['sanitize']) ||
31 isset($additional['sanitize']) &&
32 $additional['sanitize'] === true;
33
34 foreach ($data as $pos => $value)
35 {
36 if (isset($value['url']))
37 {
38 $url = is_array($value['url'])
39 ? json_encode($value['url'])
40 : $value['url'];
41 }
42 else
43 {
44 $url = '';
45 }
46
47 if (isset($value['text']))
48 {
49 $value = $value['text'];
50 }
51
52 if (!is_string($value) && !is_int($value))
53 {
54 continue;
55 }
56
57 $value = trim($value);
58
59 if (isset($resultList[$pos]))
60 {
61 $result[$pos] = [];
62
63 if ($additional['sanitize'])
64 {
65 $value = \Bitrix\Landing\Manager::sanitize($value, $bad);
66 }
67
68 // clear some amp
69 if ($value)
70 {
71 $value = preg_replace('/&amp;([^\s]{1})/is', '&$1', $value);
72 $value = str_replace(
73 ' bxstyle="',
74 ' style="',
75 $value
76 );
77 }
78 else
79 {
80 $value = ' ';
81 }
82
83 if (History::isActive())
84 {
85 $history = new History($block->getLandingId(), History::ENTITY_TYPE_LANDING);
86 $history->push('EDIT_TEXT', [
87 'block' => $block,
88 'selector' => $selector,
89 'position' => (int)$pos,
90 'valueBefore' => $resultList[$pos]->getInnerHTML(),
91 'valueAfter' => $value,
92 ]);
93 }
94
95 $result[$pos]['content'] = $value;
96 $resultList[$pos]->setInnerHTML($value);
97
98 if ($url)
99 {
100 $result[$pos]['attrs'] = [
101 'data-pseudo-url' => $url
102 ];
103 $resultList[$pos]->setAttribute('data-pseudo-url', $url);
104 }
105 }
106 }
107
108 return $result;
109 }
110
117 public static function getNode(\Bitrix\Landing\Block $block, $selector)
118 {
119 $data = array();
120 $doc = $block->getDom();
121 $resultList = $doc->querySelectorAll($selector);
122
123 foreach ($resultList as $pos => $res)
124 {
125 $data[$pos] = $res->getInnerHTML();
126 $data[$pos] = str_replace(
127 ' style="',
128 ' bxstyle="',
129 $data[$pos]
130 );
131 $data[$pos] = \Bitrix\Main\Text\Emoji::encode(
132 $data[$pos]
133 );
134 }
135
136 return $data;
137 }
138
145 public static function getSearchableNode($block, $selector)
146 {
147 $searchContent = [];
148
149 $nodes = self::getNode($block, $selector);
150 foreach ($nodes as $value)
151 {
152 $value = self::prepareSearchContent($value);
153 if ($value && !in_array($value, $searchContent))
154 {
155 $searchContent[] = $value;
156 }
157 }
158
159 return $searchContent;
160 }
161}
static getSearchableNode($block, $selector)
Definition text.php:145
static saveNode(\Bitrix\Landing\Block $block, $selector, array $data, $additional=[])
Definition text.php:25
static getNode(\Bitrix\Landing\Block $block, $selector)
Definition text.php:117
static getHandlerJS()
Definition text.php:12