1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
tools.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Iblock\Component;
4
5
use Bitrix\Main;
6
use Bitrix\Iblock\PropertyEnumerationTable;
7
use Bitrix\Iblock\PropertyTable;
8
15
class
Tools
16
{
17
public
const
IPROPERTY_ENTITY_ELEMENT
=
'ELEMENT'
;
18
public
const
IPROPERTY_ENTITY_SECTION
=
'SECTION'
;
19
20
public
const
CHECKBOX_VALUE_YES
=
'Y'
;
21
22
protected
const
WEB_PROTOCOL_MASK
=
'/^(ftp|ftps|http|https):\/\//'
;
23
24
private
static
array
$checkboxPropertyCache = [];
25
37
public
static
function
process404
(
$message
=
""
, $defineConstant =
true
, $setStatus =
true
, $showPage =
false
, $pageFile =
""
)
38
{
40
global
$APPLICATION
;
41
42
$message
= (string)
$message
;
43
$pageFile = (string)$pageFile;
44
if
(
$message
!==
''
)
45
{
46
$APPLICATION
->includeComponent(
47
'bitrix:system.show_message'
,
48
'.default'
,
49
[
50
'MESSAGE'
=>
$message
,
51
'STYLE'
=>
'errortext'
,
52
],
53
null
,
54
[
55
'HIDE_ICONS'
=>
'Y'
,
56
]
57
);
58
}
59
60
if
($defineConstant && !defined(
'ERROR_404'
))
61
{
62
define(
'ERROR_404'
,
'Y'
);
63
}
64
65
if
($setStatus)
66
{
67
\CHTTP::setStatus(
'404 Not Found'
);
68
}
69
70
if
($showPage)
71
{
72
if
(
$APPLICATION
->RestartWorkarea())
73
{
74
if
(!defined(
'BX_URLREWRITE'
))
75
{
76
define(
'BX_URLREWRITE'
,
true
);
77
}
78
Main\Composite\Engine::setEnable
(
false
);
79
if
($pageFile !==
''
)
80
{
81
require
Main\Application::getDocumentRoot
() . rel2abs(
'/'
,
'/'
. $pageFile);
82
}
83
else
84
{
85
require
Main\Application::getDocumentRoot
() .
'/404.php'
;
86
}
87
die
();
88
}
89
}
90
}
91
102
public
static
function
getFieldImageData
(
array
&$item,
array
$keys,
$entity
, $ipropertyKey =
'IPROPERTY_VALUES'
)
103
{
104
if
(empty($item) || empty($keys))
105
return
;
106
107
$entity
= (string)
$entity
;
108
$ipropertyKey = (string)$ipropertyKey;
109
foreach
($keys as $fieldName)
110
{
111
if
(!array_key_exists($fieldName, $item) || is_array($item[$fieldName]))
112
continue
;
113
$imageData =
false
;
114
$imageId = (int)$item[$fieldName];
115
if
($imageId > 0)
116
$imageData = \CFile::getFileArray($imageId);
117
unset($imageId);
118
if
(is_array($imageData))
119
{
120
if
(isset($imageData[
'SAFE_SRC'
]))
121
{
122
$imageData[
'UNSAFE_SRC'
] = $imageData[
'SRC'
];
123
$imageData[
'SRC'
] = $imageData[
'SAFE_SRC'
];
124
}
125
else
126
{
127
if
(!preg_match(self::WEB_PROTOCOL_MASK, $imageData[
'SRC'
]))
128
{
129
$imageData[
'UNSAFE_SRC'
] = $imageData[
'SRC'
];
130
$imageData[
'SAFE_SRC'
] =
Main\Web\Uri::urnEncode
($imageData[
'SRC'
],
'UTF-8'
);
131
$imageData[
'SRC'
] = $imageData[
'SAFE_SRC'
];
132
}
133
}
134
$imageData[
'ALT'
] =
''
;
135
$imageData[
'TITLE'
] =
''
;
136
if
($ipropertyKey !=
''
&& isset($item[$ipropertyKey]) && is_array($item[$ipropertyKey]))
137
{
138
$entityPrefix =
$entity
.
'_'
.$fieldName;
139
if
(isset($item[$ipropertyKey][$entityPrefix.
'_FILE_ALT'
]))
140
$imageData[
'ALT'
] = $item[$ipropertyKey][$entityPrefix.
'_FILE_ALT'
];
141
if
(isset($item[$ipropertyKey][$entityPrefix.
'_FILE_TITLE'
]))
142
$imageData[
'TITLE'
] = $item[$ipropertyKey][$entityPrefix.
'_FILE_TITLE'
];
143
unset($entityPrefix);
144
}
145
if
($imageData[
'ALT'
] ==
''
&& isset($item[
'NAME'
]))
146
$imageData[
'ALT'
] = $item[
'NAME'
];
147
if
($imageData[
'TITLE'
] ==
''
&& isset($item[
'NAME'
]))
148
$imageData[
'TITLE'
] = $item[
'NAME'
];
149
}
150
$item[$fieldName] = $imageData;
151
unset($imageData);
152
}
153
unset($fieldName);
154
}
155
163
public
static
function
getImageSrc
(
array
$image, $safe =
true
)
164
{
165
$result
=
''
;
166
if
(empty($image) || !isset($image[
'SRC'
]))
167
{
168
return
$result
;
169
}
170
$safe = ($safe ===
true
);
171
172
if
($safe)
173
{
174
if
(isset($image[
'SAFE_SRC'
]))
175
{
176
$result
= $image[
'SAFE_SRC'
];
177
}
178
elseif
(preg_match(self::WEB_PROTOCOL_MASK, $image[
'SRC'
]))
179
{
180
$result
= $image[
'SRC'
];
181
}
182
else
183
{
184
$result
=
Main\Web\Uri::urnEncode
($image[
'SRC'
],
'UTF-8'
);
185
}
186
}
187
else
188
{
189
$result
= ($image[
'UNSAFE_SRC'
] ?? $image[
'SRC'
]);
190
}
191
192
return
$result
;
193
}
194
207
public
static
function
isCheckboxProperty
(
array
$property): bool
208
{
209
$propertyId = (int)($property[
'ID'
] ?? 0);
210
if
($propertyId <= 0)
211
{
212
return
false
;
213
}
214
if
(!isset(self::$checkboxPropertyCache[$propertyId]))
215
{
216
$result
=
false
;
217
if
(
218
($property[
'PROPERTY_TYPE'
] ??
''
) ===
PropertyTable::TYPE_LIST
219
&& ($property[
'MULTIPLE'
] ??
''
) ===
'N'
220
&& (
string
)($property[
'USER_TYPE'
] ??
''
) ===
''
221
&& ($property[
'LIST_TYPE'
] ??
''
) ===
PropertyTable::CHECKBOX
222
)
223
{
224
$filter
= [
225
'=PROPERTY_ID'
=> $propertyId,
226
];
227
$cache = [
228
'ttl'
=> 86400,
229
];
230
if
(PropertyEnumerationTable::getCount(
$filter
, $cache) === 1)
231
{
232
$variant = PropertyEnumerationTable::getRow([
233
'select'
=> [
234
'ID'
,
235
'PROPERTY_ID'
,
236
'VALUE'
,
237
],
238
'filter'
=>
$filter
,
239
'cache'
=> $cache,
240
]);
241
if
(($variant[
'VALUE'
] ??
''
) === self::CHECKBOX_VALUE_YES)
242
{
243
$result
=
true
;
244
}
245
}
246
}
247
self::$checkboxPropertyCache[$propertyId] =
$result
;
248
}
249
250
return
self::$checkboxPropertyCache[$propertyId];
251
}
252
253
public
static
function
clearCache
(): void
254
{
255
self::$checkboxPropertyCache = [];
256
}
257
}
$APPLICATION
global $APPLICATION
Определения
include.php:80
Bitrix\Iblock\Component\Tools\getImageSrc
static getImageSrc(array $image, $safe=true)
Определения
tools.php:163
Bitrix\Iblock\Component\Tools\getFieldImageData
static getFieldImageData(array &$item, array $keys, $entity, $ipropertyKey='IPROPERTY_VALUES')
Определения
tools.php:102
Bitrix\Iblock\Component\Tools\process404
static process404($message="", $defineConstant=true, $setStatus=true, $showPage=false, $pageFile="")
Определения
tools.php:37
Bitrix\Iblock\Component\Tools\IPROPERTY_ENTITY_ELEMENT
const IPROPERTY_ENTITY_ELEMENT
Определения
tools.php:17
Bitrix\Iblock\Component\Tools\CHECKBOX_VALUE_YES
const CHECKBOX_VALUE_YES
Определения
tools.php:20
Bitrix\Iblock\Component\Tools\IPROPERTY_ENTITY_SECTION
const IPROPERTY_ENTITY_SECTION
Определения
tools.php:18
Bitrix\Iblock\Component\Tools\isCheckboxProperty
static isCheckboxProperty(array $property)
Определения
tools.php:207
Bitrix\Iblock\Component\Tools\WEB_PROTOCOL_MASK
const WEB_PROTOCOL_MASK
Определения
tools.php:22
Bitrix\Iblock\Component\Tools\clearCache
static clearCache()
Определения
tools.php:253
Bitrix\Iblock\PropertyTable\CHECKBOX
const CHECKBOX
Определения
propertytable.php:62
Bitrix\Iblock\PropertyTable\TYPE_LIST
const TYPE_LIST
Определения
propertytable.php:70
Bitrix\Main\Application\getDocumentRoot
static getDocumentRoot()
Определения
application.php:736
Bitrix\Main\Composite\Engine\setEnable
static setEnable($isEnabled=true)
Определения
engine.php:81
Bitrix\Main\Web\Uri\urnEncode
static urnEncode($str, $charset='UTF-8')
Определения
uri.php:416
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
$entity
$entity
Определения
group_bizproc_workflow_delete.php:17
$filter
$filter
Определения
iblock_catalog_list.php:54
Bitrix\Main\PhoneNumber\Tools
Определения
boolfield.php:3
Bitrix\Main\if
if(!function_exists(__NAMESPACE__.'\\___972068685'))
Определения
license.php:1
$message
$message
Определения
payment.php:8
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
die
die
Определения
quickway.php:367
bitrix
modules
iblock
lib
component
tools.php
Создано системой
1.14.0