1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
b24button.php
См. документацию.
1
<?php
2
namespace
Bitrix\Landing\Hook\Page
;
3
4
use
Bitrix\Landing
;
5
use Bitrix\Crm\SiteButton;
6
use
Bitrix\Main\Application
;
7
use
Bitrix\Main\Loader
;
8
use
Bitrix\Main\Localization\Loc
;
9
use
Bitrix\Main\Page
;
10
use
Bitrix\Socialservices\ApClient
;
11
12
Loc::loadMessages(__FILE__);
13
14
class
B24button
extends
\Bitrix\Landing\Hook\Page
15
{
16
protected
const
COLOR_TYPE_BUTTON
=
'button'
;
17
protected
const
COLOR_TYPE_SITE
=
'site'
;
18
protected
const
COLOR_TYPE_CUSTOM
=
'custom'
;
19
protected
const
COLOR_DEFAULT
=
'#03c1fe'
;
20
26
protected
static
function
getScriptUrl
($script)
27
{
28
if
(preg_match(
'/\}\)\(window,document,\'([^\']+)\'\);/is'
, $script,
$matches
))
29
{
30
return
$matches
[1];
31
}
32
33
return
''
;
34
}
35
40
public
static
function
getButtons
():
array
41
{
42
static
$buttons =
null
;
43
if
($buttons !==
null
)
44
{
45
return
$buttons;
46
}
47
48
$buttons = [];
49
foreach
(self::getButtonsData() as $button)
50
{
51
$key
=
self::getScriptUrl
($button[
'SCRIPT'
]);
52
if
(
$key
)
53
{
54
$buttons[
$key
] =
\htmlspecialcharsbx
($button[
'NAME'
]);
55
}
56
}
57
58
return
$buttons;
59
}
60
70
public
static
function
getButtonsData
(): ?
array
71
{
72
static
$buttonsData =
null
;
73
74
if
($buttonsData !==
null
)
75
{
76
return
$buttonsData;
77
}
78
79
$buttonsData = [];
80
81
// b24 crm
82
if
(Loader::includeModule(
'crm'
))
83
{
84
// if buttons not exist (new portal) - create before
85
if
(SiteButton\Preset::checkVersion())
86
{
87
$preset =
new
SiteButton\Preset();
88
$preset->install();
89
}
90
91
$buttonsData = SiteButton\Manager::getList([
92
'filter'
=> [
'=ACTIVE'
=>
'Y'
],
93
'select'
=> [
94
'ID'
,
'SECURITY_CODE'
,
'NAME'
95
],
96
'order'
=> [
97
'ID'
=>
'DESC'
98
]
99
]);
100
}
101
// site manager
102
elseif
(
Landing
\
Manager::isB24Connector
())
103
{
104
$client = ApClient::init();
105
if
($client)
106
{
107
$res
= $client->call(
'crm.button.list'
);
108
if
(isset(
$res
[
'result'
]) && is_array(
$res
[
'result'
]))
109
{
110
$buttonsData =
$res
[
'result'
];
111
}
112
}
113
}
114
115
return
$buttonsData;
116
}
117
127
public
static
function
getButtonIdByCode
(
$code
)
128
{
129
foreach
(self::getButtonsData() as $button)
130
{
131
if
(
$code
=== self::getScriptUrl($button[
'SCRIPT'
]))
132
{
133
return
$button[
'ID'
];
134
}
135
}
136
137
return
false
;
138
}
139
144
protected
function
getMap
()
145
{
146
$items
=
array
(
147
'N'
=> Loc::getMessage(
'LANDING_HOOK_B24BUTTONCODE_NO'
)
148
);
149
150
// show connectors only for edit
151
if
($this->
isEditMode
())
152
{
153
$context
= Application::getInstance()->getContext();
154
$server =
$context
->getServer();
155
$items
+= $this->
getButtons
();
156
}
157
158
159
$helpUrl =
\Bitrix\Landing\Help::getHelpUrl
(
'B24BUTTON'
);
160
return
[
161
'USE'
=>
new
Landing\Field\Checkbox
(
'USE'
, [
162
'title'
=> Loc::getMessage(
'LANDING_HOOK_B24BUTTONCODE_USE'
),
163
]),
164
'CODE'
=>
new
Landing\Field\Select
(
'CODE'
, [
165
'title'
=> Loc::getMessage(
'LANDING_HOOK_B24BUTTONCODE'
),
166
'options'
=>
$items
167
]),
168
'COLOR'
=>
new
Landing\Field\Select
(
'COLOR'
, [
169
'title'
=> Loc::getMessage(
'LANDING_HOOK_B24BUTTONCOLOR'
),
170
'options'
=> [
171
self::COLOR_TYPE_SITE => Loc::getMessage(
'LANDING_HOOK_B24BUTTONCOLOR_SITE'
),
172
self::COLOR_TYPE_BUTTON => Loc::getMessage(
'LANDING_HOOK_B24BUTTONCOLOR_BUTTON'
),
173
self::COLOR_TYPE_CUSTOM => Loc::getMessage(
'LANDING_HOOK_B24BUTTONCOLOR_CUSTOM'
)
174
]
175
]),
176
'COLOR_VALUE'
=>
new
Landing\Field\Text
(
'COLOR_VALUE'
, [
177
'title'
=> Loc::getMessage(
'LANDING_HOOK_B24BUTTONCOLOR_VALUE'
),
178
'default'
=> self::COLOR_DEFAULT,
179
]),
180
'HELP'
=>
new
Landing\Field\Text
(
'HELP'
, [
181
'title'
=>
''
,
182
'help'
=> $helpUrl
183
?
'<a href="'
. $helpUrl .
'" target="_blank">'
.
184
Loc::getMessage(
'LANDING_HOOK_DETAIL_HELP'
) .
185
'</a>'
186
:
''
187
]),
188
];
189
}
190
195
public
function
enabled
()
196
{
197
if
($this->
issetCustomExec
())
198
{
199
return
true
;
200
}
201
202
$isTelegramWebView =
self::isTelegramWebView
();
203
204
if
($this->fields[
'USE'
]->getValue() ===
null
)
205
{
206
return
207
trim($this->fields[
'CODE'
]) !==
''
208
&& !$isTelegramWebView;
209
}
210
211
return
212
$this->fields[
'USE'
]->getValue() ===
'Y'
213
&& !$isTelegramWebView;
214
}
215
220
protected
static
function
isTelegramWebView
(): bool
221
{
222
if
(!
$application
= Application::getInstance())
223
{
224
return
false
;
225
}
226
$session =
$application
->getSession();
227
$request
=
$application
->getContext()->getRequest();
228
if
(
$request
->get(
'tgWebApp'
) !==
null
)
229
{
230
$session->set(
'tgWebApp'
,
'Y'
);
231
232
return
true
;
233
}
234
235
return
$session->has(
'tgWebApp'
) && $session->get(
'tgWebApp'
) ===
'Y'
;
236
}
237
242
public
function
enabledInEditMode
()
243
{
244
return
false
;
245
}
246
251
public
function
exec
()
252
{
253
if
($this->
execCustom
())
254
{
255
return
;
256
}
257
258
$code
=
\htmlspecialcharsbx
(trim($this->fields[
'CODE'
]));
259
if
(
$code
!=
'N'
)
260
{
261
Landing\Manager::setPageView
(
262
'BeforeBodyClose'
,
263
'<script data-skip-moving="true">
264
(function(w,d,u,b){ \'use strict\';
265
var s=d.createElement(\'script\');var r=(Date.now()/1000|0);s.async=1;s.src=u+\'?\'+r;
266
var h=d.getElementsByTagName(\'script\')[0];h.parentNode.insertBefore(s,h);
267
})(window,document,\''
.
$code
.
'\'
);
268
</script>
'
269
);
270
271
// set COLOR
272
if ($this->fields['
COLOR
']->getValue() !== self::COLOR_TYPE_BUTTON)
273
{
274
Landing\Manager::setPageView(
275
'
BodyClass
',
276
'
landing
-b24button-use-
style
'
277
);
278
279
$color =
280
(
281
$this->fields['
COLOR
']->getValue() === self::COLOR_TYPE_CUSTOM
282
&& !empty($this->fields['
COLOR_VALUE
']->getValue())
283
)
284
? Theme::prepareColor($this->fields['
COLOR_VALUE
']->getValue())
285
: '
var(--primary)
';
286
287
Page\Asset::getInstance()->addString(
288
"<style type=\"text/css\">
289
:root {
290
--theme-color-b24button: {$color};
291
}
292
</style>",
293
false,
294
Page\AssetLocation::BEFORE_CSS
295
);
296
}
297
}
298
}
299
304
public function getPageTitle()
305
{
306
return Loc::getMessage('LANDING_HOOK_B24BUTTONCODE_PAGE_TITLE
');
307
}
308
309
}
$request
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения
catalog_reindex.php:36
Bitrix\Landing\Field\Checkbox
Определения
checkbox.php:5
Bitrix\Landing\Field\Select
Определения
select.php:9
Bitrix\Landing\Field\Text
Определения
text.php:5
Bitrix\Landing\Help\getHelpUrl
static getHelpUrl(string $code)
Определения
help.php:174
Bitrix\Landing\Hook\Page\B24button
Определения
b24button.php:15
Bitrix\Landing\Hook\Page\B24button\getButtons
static getButtons()
Определения
b24button.php:40
Bitrix\Landing\Hook\Page\B24button\getButtonIdByCode
static getButtonIdByCode($code)
Определения
b24button.php:127
Bitrix\Landing\Hook\Page\B24button\isTelegramWebView
static isTelegramWebView()
Определения
b24button.php:220
Bitrix\Landing\Hook\Page\B24button\COLOR_TYPE_BUTTON
const COLOR_TYPE_BUTTON
Определения
b24button.php:16
Bitrix\Landing\Hook\Page\B24button\getScriptUrl
static getScriptUrl($script)
Определения
b24button.php:26
Bitrix\Landing\Hook\Page\B24button\getButtonsData
static getButtonsData()
Определения
b24button.php:70
Bitrix\Landing\Hook\Page\B24button\COLOR_TYPE_SITE
const COLOR_TYPE_SITE
Определения
b24button.php:17
Bitrix\Landing\Hook\Page\B24button\getMap
getMap()
Определения
b24button.php:144
Bitrix\Landing\Hook\Page\B24button\enabledInEditMode
enabledInEditMode()
Определения
b24button.php:242
Bitrix\Landing\Hook\Page\B24button\enabled
enabled()
Определения
b24button.php:195
Bitrix\Landing\Hook\Page\B24button\COLOR_TYPE_CUSTOM
const COLOR_TYPE_CUSTOM
Определения
b24button.php:18
Bitrix\Landing\Hook\Page\B24button\exec
exec()
Определения
b24button.php:251
Bitrix\Landing\Hook\Page\B24button\COLOR_DEFAULT
const COLOR_DEFAULT
Определения
b24button.php:19
Bitrix\Landing\Hook\Page\issetCustomExec
issetCustomExec()
Определения
page.php:253
Bitrix\Landing\Hook\Page\isEditMode
isEditMode()
Определения
page.php:93
Bitrix\Landing\Hook\Page\execCustom
execCustom()
Определения
page.php:262
Bitrix\Landing\Manager\isB24Connector
static isB24Connector()
Определения
manager.php:1178
Bitrix\Landing\Manager\setPageView
static setPageView(string $marker, string $content, bool $skipTrim=false)
Определения
manager.php:470
Bitrix\Main\Application
Определения
application.php:30
Bitrix\Main\Loader
Определения
loader.php:13
Bitrix\Main\Localization\Loc
Определения
loc.php:12
Bitrix\Socialservices\ApClient
Определения
apclient.php:14
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$res
$res
Определения
filter_act.php:7
$context
$context
Определения
csv_new_setup.php:223
$code
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения
options.php:195
$application
$application
Определения
bitrix.php:23
htmlspecialcharsbx
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения
tools.php:2701
Bitrix\Landing\Hook\Page
Определения
b24button.php:2
Bitrix\Landing\Metrika\landing
@ landing
Определения
Tools.php:9
Bitrix\Landing
Определения
agent.php:3
Bitrix\Main\Page
Определения
aliases.php:54
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$key
if(empty($signedUserToken)) $key
Определения
quickway.php:257
style
font style
Определения
invoice.php:442
$items
$items
Определения
template.php:224
$matches
$matches
Определения
index.php:22
bitrix
modules
landing
lib
hook
page
b24button.php
Создано системой
1.14.0