1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
comp_findtools.php
См. документацию.
1<?php
2
4{
5 public static function GetElementID($element_id, $element_code, $section_id, $section_code, $arFilter)
6 {
7 $element_id = (int)$element_id;
8 $element_code = (string)$element_code;
9 if ($element_id > 0)
10 {
11 return $element_id;
12 }
13 elseif ($element_code != '')
14 {
15 if (!is_array($arFilter))
16 $arFilter = array();
17 $arFilter['=CODE'] = $element_code;
18
19 $section_id = (int)$section_id;
20 $section_code = (string)$section_code;
21 if ($section_id > 0)
22 $arFilter['SECTION_ID'] = $section_id;
23 elseif ($section_code != '')
24 $arFilter["SECTION_CODE"] = $section_code;
25
26 $rsElement = CIBlockElement::GetList(array(), $arFilter, false, false, array("ID"));
27 if ($arElement = $rsElement->Fetch())
28 return (int)$arElement["ID"];
29 }
30 return 0;
31 }
32
33 public static function GetSectionID($section_id, $section_code, $arFilter)
34 {
35 $section_id = (int)$section_id;
36 $section_code = (string)$section_code;
37 if ($section_id > 0)
38 {
39 return $section_id;
40 }
41 elseif ($section_code != '')
42 {
43 if (!is_array($arFilter))
44 $arFilter = array();
45 $arFilter['=CODE'] = $section_code;
46
47 $rsSection = CIBlockSection::GetList(array(), $arFilter, false, array("ID"));
48 if ($arSection = $rsSection->Fetch())
49 return (int)$arSection["ID"];
50 }
51 return 0;
52 }
53
54 public static function GetSectionIDByCodePath($iblock_id, $section_code_path)
55 {
56 if ($section_code_path == '')
57 {
58 return 0;
59 }
60 $arVariables = array(
61 "SECTION_CODE_PATH" => $section_code_path,
62 );
63 return (self::checkSection($iblock_id, $arVariables) ? $arVariables["SECTION_ID"] : 0);
64 }
65
66 public static function resolveComponentEngine(CComponentEngine $engine, $pageCandidates, &$arVariables)
67 {
70 static $aSearch = array("&lt;", "&gt;", "&quot;", "&#039;");
71 static $aReplace = array("<", ">", "\"", "'");
72
73 $component = $engine->getComponent();
74 if ($component)
75 {
76 $iblock_id = (int)$component->arParams["IBLOCK_ID"];
77 $strict_check = ($component->arParams["DETAIL_STRICT_SECTION_CHECK"] ?? '') === "Y";
78 }
79 else
80 {
81 $iblock_id = 0;
82 $strict_check = false;
83 }
84
85 //To fix GetPagePath security hack for SMART_FILTER_PATH
86 foreach ($pageCandidates as $pageID => $arVariablesTmp)
87 {
88 foreach ($arVariablesTmp as $variableName => $variableValue)
89 {
90 if ($variableName === "SMART_FILTER_PATH")
91 $pageCandidates[$pageID][$variableName] = str_replace($aSearch, $aReplace, $variableValue);
92 }
93 }
94
95 $requestURL = $APPLICATION->GetCurPage(true);
96
97 $cacheId = $requestURL.implode("|", array_keys($pageCandidates))."|".SITE_ID."|".$iblock_id.$engine->cacheSalt;
98 $cache = new CPHPCache;
99 if ($cache->StartDataCache(3600, $cacheId, "iblock_find"))
100 {
101 if (defined("BX_COMP_MANAGED_CACHE"))
102 {
103 $CACHE_MANAGER->StartTagCache("iblock_find");
104 CIBlock::registerWithTagCache($iblock_id);
105 }
106
107 foreach ($pageCandidates as $pageID => $arVariablesTmp)
108 {
109 if (
110 (isset($arVariablesTmp["SECTION_CODE_PATH"]) && $arVariablesTmp["SECTION_CODE_PATH"] !== "")
111 && (isset($arVariablesTmp["ELEMENT_ID"]) || isset($arVariablesTmp["ELEMENT_CODE"]))
112 )
113 {
114 if (CIBlockFindTools::checkElement($iblock_id, $arVariablesTmp, $strict_check))
115 {
116 $arVariables = $arVariablesTmp;
117 if (defined("BX_COMP_MANAGED_CACHE"))
118 $CACHE_MANAGER->EndTagCache();
119 $cache->EndDataCache(array($pageID, $arVariablesTmp));
120 return $pageID;
121 }
122 }
123 }
124
125 foreach ($pageCandidates as $pageID => $arVariablesTmp)
126 {
127 if (
128 (isset($arVariablesTmp["SECTION_CODE_PATH"]) && $arVariablesTmp["SECTION_CODE_PATH"] !== "")
129 && (!isset($arVariablesTmp["ELEMENT_ID"]) && !isset($arVariablesTmp["ELEMENT_CODE"]))
130 )
131 {
132 if (CIBlockFindTools::checkSection($iblock_id, $arVariablesTmp))
133 {
134 $arVariables = $arVariablesTmp;
135 if (defined("BX_COMP_MANAGED_CACHE"))
136 $CACHE_MANAGER->EndTagCache();
137 $cache->EndDataCache(array($pageID, $arVariablesTmp));
138 return $pageID;
139 }
140 }
141 }
142
143 if (defined("BX_COMP_MANAGED_CACHE"))
144 $CACHE_MANAGER->AbortTagCache();
145 $cache->AbortDataCache();
146 }
147 else
148 {
149 $vars = $cache->GetVars();
150 $pageID = $vars[0];
151 $arVariables = $vars[1];
152
153 return $pageID;
154 }
155
156 reset($pageCandidates);
157 $pageID = key($pageCandidates);
158 $arVariables = $pageCandidates[$pageID];
159
160 return $pageID;
161 }
162
163 public static function checkElement($iblock_id, &$arVariables, $strict_check = false)
164 {
165 global $DB;
166
167 $select = "BE.ID";
168
169 $strFrom = "
170 b_iblock_element BE
171 ";
172
173 $elementId = $arVariables["ELEMENT_ID"] ?? '';
174 $elementCode = $arVariables["ELEMENT_CODE"] ?? '';
175 $strWhere = "
176 " . ($elementId != "" ? "AND BE.ID = " . (int)$elementId : "") . "
177 " . ($elementCode != "" ? "AND BE.CODE = '" . $DB->ForSql($elementCode) . "'" : "") . "
178 ";
179
180 if (
181 isset($arVariables["SECTION_CODE_PATH"])
182 && is_string($arVariables["SECTION_CODE_PATH"])
183 && $arVariables["SECTION_CODE_PATH"] != ""
184 )
185 {
186 $select .= ", BS.ID as SECTION_ID, BS.CODE as SECTION_CODE";
187 //The path may be incomplete so we join part of the section tree BS and BSP
188 $strFrom .= "
189 INNER JOIN b_iblock_section_element BSE ON BSE.IBLOCK_ELEMENT_ID = BE.ID AND BSE.ADDITIONAL_PROPERTY_ID IS NULL
190 INNER JOIN b_iblock_section BS ON BS.ID = BSE.IBLOCK_SECTION_ID
191 INNER JOIN b_iblock_section BSP ON BS.IBLOCK_ID = BSP.IBLOCK_ID AND BS.LEFT_MARGIN >= BSP.LEFT_MARGIN AND BS.RIGHT_MARGIN <= BSP.RIGHT_MARGIN
192 ";
193 $joinField = "BSP.ID";
194
195 $sectionPath = explode("/", $arVariables["SECTION_CODE_PATH"]);
196 // B24 fix
197 if (count($sectionPath) > 58) // $strFrom already contains three join (max - 61)
198 {
199 return false;
200 }
201
202 $i = 0;
203 foreach (array_reverse($sectionPath) as $i => $SECTION_CODE)
204 {
205 $strFrom .= "
206 INNER JOIN b_iblock_section BS".$i." ON BS".$i.".ID = ".$joinField."
207 ";
208 $joinField = "BS".$i.".IBLOCK_SECTION_ID";
209 $strWhere .= "
210 AND BS".$i.".CODE = '".$DB->ForSql($SECTION_CODE)."'
211 ";
212 }
213
214 if ($strict_check)
215 {
216 $strWhere .= "
217 AND BS".$i.".IBLOCK_SECTION_ID is null
218 ";
219 }
220 }
221
222 $strSql = "
223 select ".$select."
224 from ".$strFrom."
225 WHERE BE.IBLOCK_ID = ".$iblock_id."
226 ".$strWhere."
227 ";
228 $rs = $DB->Query($strSql);
229 $r = $rs->Fetch();
230 unset($rs);
231 if ($r)
232 {
233 if (isset($sectionPath) && is_array($sectionPath))
234 {
235 $arVariables["SECTION_CODE"] = $sectionPath[count($sectionPath) - 1];
236 if (isset($r['SECTION_ID']) && isset($r['SECTION_CODE']))
237 {
238 if ($arVariables["SECTION_CODE"] === $r['SECTION_CODE'])
239 {
240 $arVariables["SECTION_ID"] = $r['SECTION_ID'];
241 $arVariables["ELEMENT_ID"] = $r['ID'];
242 }
243 }
244 }
245
246 return true;
247 }
248 else
249 {
250 return false;
251 }
252 }
253
254 public static function checkSection($iblock_id, &$arVariables)
255 {
256 global $DB;
257
258 if (
259 !isset($arVariables["SECTION_CODE_PATH"])
260 || !is_string($arVariables["SECTION_CODE_PATH"])
261 )
262 {
263 return false;
264 }
265
266 $sectionPath = explode("/", $arVariables["SECTION_CODE_PATH"]);
267
268 // B24 fix
269 if (count($sectionPath) > 61)
270 {
271 return false;
272 }
273
274 $strFrom = "";
275 $joinField = "";
276 $strWhere = "";
277 $strRoot = "";
278 foreach (array_reverse($sectionPath) as $i => $SECTION_CODE)
279 {
280 if ($i == 0)
281 {
282 $strFrom .= "
283 b_iblock_section BS
284 ";
285 $joinField .= "BS.IBLOCK_SECTION_ID";
286 $strWhere .= "
287 AND BS.CODE = '".$DB->ForSql($SECTION_CODE)."'
288 ";
289 $strRoot = "AND BS.IBLOCK_SECTION_ID IS NULL";
290 }
291 else
292 {
293 $strFrom .= "
294 INNER JOIN b_iblock_section BS".$i." ON BS".$i.".ID = ".$joinField."
295 ";
296 $joinField = "BS".$i.".IBLOCK_SECTION_ID";
297 $strWhere .= "
298 AND BS".$i.".CODE = '".$DB->ForSql($SECTION_CODE)."'
299 ";
300 $strRoot = "AND BS".$i.".IBLOCK_SECTION_ID IS NULL";
301 }
302 }
303
304 $strSql = "
305 select BS.ID
306 from ".$strFrom."
307 WHERE BS.IBLOCK_ID = ".$iblock_id."
308 ".$strWhere."
309 ".$strRoot."
310 ";
311 $rs = $DB->Query($strSql);
312 $ar = $rs->Fetch();
313 unset($rs);
314 if ($ar)
315 {
316 $arVariables["SECTION_ID"] = $ar["ID"];
317 $arVariables["SECTION_CODE"] = $sectionPath[count($sectionPath)-1];
318
319 return true;
320 }
321 else
322 {
323 return false;
324 }
325 }
326}
global $APPLICATION
Определения include.php:80
static GetElementID($element_id, $element_code, $section_id, $section_code, $arFilter)
Определения comp_findtools.php:5
static checkSection($iblock_id, &$arVariables)
Определения comp_findtools.php:254
static GetSectionID($section_id, $section_code, $arFilter)
Определения comp_findtools.php:33
static resolveComponentEngine(CComponentEngine $engine, $pageCandidates, &$arVariables)
Определения comp_findtools.php:66
static checkElement($iblock_id, &$arVariables, $strict_check=false)
Определения comp_findtools.php:163
static GetSectionIDByCodePath($iblock_id, $section_code_path)
Определения comp_findtools.php:54
global $CACHE_MANAGER
Определения clear_component_cache.php:7
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$select
Определения iblock_catalog_list.php:194
global $DB
Определения cron_frame.php:29
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$engine
Определения options.php:121
const SITE_ID
Определения sonet_set_content_view.php:12
$rs
Определения action.php:82
$arFilter
Определения user_search.php:106