1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
landing.php
См. документацию.
1<?php
2namespace Bitrix\Landing\DataLoader;
3
4use \Bitrix\Landing\Block;
5use \Bitrix\Landing\Hook;
6use \Bitrix\Landing\Landing as LandingCore;
7use \Bitrix\Landing\Landing\Cache;
8
10{
16 protected function getMetadata(array $ids)
17 {
18 $images = [];
19 $res = \Bitrix\Landing\Internals\HookDataTable::getList([
20 'select' => [
21 'VALUE', 'ENTITY_ID', 'CODE'
22 ],
23 'filter' => [
24 '=HOOK' => 'METAOG',
25 '=CODE' => ['IMAGE', 'DESCRIPTION'],
26 '=PUBLIC' => Hook::getEditMode() ? 'N' : 'Y',
27 '=ENTITY_TYPE' => Hook::ENTITY_TYPE_LANDING,
28 'ENTITY_ID' => $ids
29 ]
30 ]);
31 while ($row = $res->fetch())
32 {
33 if (!isset($images[$row['ENTITY_ID']]))
34 {
35 $images[$row['ENTITY_ID']] = [];
36 }
37 if ($row['CODE'] == 'IMAGE')
38 {
39 if (intval($row['VALUE']) > 0)
40 {
41 $row['VALUE'] = \Bitrix\Landing\File::getFilePath($row['VALUE']);
42 }
43 }
44 $images[$row['ENTITY_ID']][$row['CODE']] = $row['VALUE'];
45 }
46
47 return $images;
48 }
49
54 protected function getSearchQuery()
55 {
56 static $currentRequest = null;
57
58 if ($currentRequest === null)
59 {
61 $currentRequest = $context->getRequest();
62 }
63
64 return trim($currentRequest->get('q'));
65 }
66
73 protected function getSearchSnippet(string $query, string $content): string
74 {
75 $phrases = explode(' ', $query);
76 \trimArr($phrases, true);
77 $newContent = '';
78 $snippetOffset = 50;
79
80 foreach ($phrases as $phrase)
81 {
82 $phrasePos = mb_strpos(mb_strtolower($content), mb_strtolower($phrase));
83 if ($phrasePos === false)
84 {
85 continue;
86 }
87 $newContent .= (($phrasePos > $snippetOffset) ? ' ...' : ' ') .
88 mb_substr(
90 ($phrasePos > $snippetOffset) ? $phrasePos - $snippetOffset : 0,
91 $phrasePos + mb_strlen($phrase) + $snippetOffset
92 ) .
93 '... ';
94 }
95
96 return $newContent;
97 }
98
103 public function getElementListData()
104 {
105 $this->seo->clear();
106 $needPreviewPicture = false;
107 $needPreviewText = false;
108 $needLink = true;//always
109
110 // select
112 if (empty($select))
113 {
114 return [];
115 }
116
117 // filter
118 $filter = $this->getInternalFilter();
119 $contextFilter = $this->getOptionsValue('context_filter');
120 $cache = $this->getOptionsValue('cache');
121 if (empty($filter))
122 {
123 $filter = [];
124 }
125 if (isset($contextFilter['SITE_ID']))
126 {
127 $filter['SITE_ID'] = $contextFilter['SITE_ID'];
128 }
129 if (isset($contextFilter['LANDING_ACTIVE']))
130 {
131 $filter['=ACTIVE'] = $contextFilter['LANDING_ACTIVE'];
132 }
133 $filter['==AREAS.ID'] = null;
134
135 // select, order
136 $order = [];
137 $select[] = 'ID';
138 $rawOrder = $this->getOrder();
139 if (isset($rawOrder['by']) && isset($rawOrder['order']))
140 {
141 $order[$rawOrder['by']] = $rawOrder['order'];
142 if (!in_array($rawOrder['by'], $select))
143 {
144 $select[] = $rawOrder['by'];
145 }
146 }
147 foreach ($select as $i => $code)
148 {
149 if ($code == 'IMAGE')
150 {
151 $needPreviewPicture = true;
152 unset($select[$i]);
153 }
154 else if ($code == 'DESCRIPTION')
155 {
156 $needPreviewText = true;
157 unset($select[$i]);
158 }
159 else if ($code == 'LINK')
160 {
161 $needLink = true;
162 unset($select[$i]);
163 }
164 }
165
166 // limit
167 $limit = $this->getLimit();
168 if ($limit <= 0)
169 {
170 $limit = 10;
171 }
172
173 $searchContent = [];
174 $query = $this->getSearchQuery();
175 if ($query)
176 {
177 if ($cache instanceof \CPHPCache)
178 {
179 $cache->abortDataCache();
180 }
181
182 if (mb_strlen($query) < 3)
183 {
184 return [];
185 }
186
187 // search in blocks
188 $blockFilter = [];
189 if (isset($filter['SITE_ID']))
190 {
191 $blockFilter['LANDING.SITE_ID'] = $filter['SITE_ID'];
192 }
193 $blocks = Block::search(
194 $query,
195 $blockFilter,
196 ['LID', 'ID', 'SEARCH_CONTENT']
197 );
198 $landingBlocksIds = [];
199 foreach ($blocks as $block)
200 {
201 $searchContent[$block['LID']] = $this->getSearchSnippet($query, $block['SEARCH_CONTENT']);
202 if (!$searchContent[$block['LID']])
203 {
204 unset($searchContent[$block['LID']]);
205 }
206 $landingBlocksIds[] = $block['LID'];
207 }
208
209 // merge filter with search query
210 $filter[] = [
211 'LOGIC' => 'OR',
212 'TITLE' => '%' . $query . '%',
213 '*%SEARCH_CONTENT' => $query,
214 'ID' => $landingBlocksIds ? $landingBlocksIds : [-1]
215 ];
216 }
217
218 // get data
219 $result = [];
221 'select' => $select,
222 'filter' => $filter,
223 'order' => $order,
224 'limit' => $limit
225 ]);
226 while ($row = $res->fetch())
227 {
228 Cache::register($row['ID']);
229 $result[$row['ID']] = [
230 'TITLE' => \htmlspecialcharsbx($row['TITLE'])
231 ];
232 }
233
234 // get meta data
235 $metaData = [];
236 if (
237 $needPreviewPicture ||
238 $needPreviewText
239 )
240 {
241 $metaData = $this->getMetadata(
242 array_keys($result)
243 );
244 }
245
246 // and feel result data with meta data
247 foreach ($result as $id => &$item)
248 {
249 if (
250 $needPreviewPicture &&
251 isset($metaData[$id]['IMAGE'])
252 )
253 {
254 $item['IMAGE'] = [
255 'src' => $metaData[$id]['IMAGE'],
256 'alt' => $item['TITLE'] ?? ''
257 ];
258 }
259 if ($needPreviewText)
260 {
261 if (isset($searchContent[$id]))
262 {
263 $item['DESCRIPTION'] = \htmlspecialcharsbx($searchContent[$id]);
264 }
265 else if (isset($metaData[$id]['DESCRIPTION']))
266 {
267 $item['DESCRIPTION'] = \htmlspecialcharsbx($metaData[$id]['DESCRIPTION']);
268 }
269 }
270 if ($needLink)
271 {
272 $item['LINK'] = '#landing' . $id;
273 }
274 if ($query)
275 {
276 $item['_GET'] = [
277 'q' => $query
278 ];
279 }
280 }
281
282 return array_values($result);
283 }
284
290 public function getElementData($element)
291 {
292 $this->seo->clear();
293
294 $element = intval($element);
295 if ($element <= 0)
296 {
297 return [];
298 }
299
300 // select
302 if (empty($select))
303 {
304 return [];
305 }
306
307 // filter
308 $filter = $this->getInternalFilter();
309 if (empty($filter))
310 {
311 return [];
312 }
313 $filter['ID'] = $element;
314 $select[] = 'ID';
315
316 // get data
318 'select' => $select,
319 'filter' => $filter,
320 ]);
321 $row = $res->fetch();
322 if (empty($row))
323 {
324 return [];
325 }
326
327 Cache::register($row['ID']);
328 $this->seo->setTitle($row['TITLE']);
329
330 return [$row];
331 }
332}
getSearchSnippet(string $query, string $content)
Определения landing.php:73
getElementData($element)
Определения landing.php:290
getMetadata(array $ids)
Определения landing.php:16
static getFilePath($fileId)
Определения file.php:600
getOptionsValue($index)
Определения dataloader.php:242
static getInstance()
Определения application.php:98
static getList(array $parameters=array())
Определения datamanager.php:431
$content
Определения commerceml.php:144
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$query
Определения get_search.php:11
$select
Определения iblock_catalog_list.php:194
$filter
Определения iblock_catalog_list.php:54
$context
Определения csv_new_setup.php:223
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
Определения agent.php:3
$order
Определения payment.php:8
$i
Определения factura.php:643