Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
gmap.php
1
<?php
2
namespace
Bitrix\Landing\Hook\Page
;
3
4
use
Bitrix\Landing\Field
;
5
use
Bitrix\Landing\Help
;
6
use
Bitrix\Landing\Hook\Page
;
7
use
Bitrix\Landing\Internals\SiteTable
;
8
use
Bitrix\Landing\Manager
;
9
use
Bitrix\Main\Localization\Loc
;
10
use Bitrix\Main\Page\Asset;
11
use
Bitrix\Main\Text\HtmlFilter
;
12
13
Loc::loadMessages
(__FILE__);
14
15
class
GMap
extends
Page
16
{
17
private
$lang;
18
private
$siteId;
19
24
protected
function
getMap
()
25
{
26
$helpUrl =
Help::getHelpUrl
(
'GMAP_EDIT'
);
27
return
[
28
'USE'
=>
new
Field\Checkbox
(
'USE'
, [
29
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_MAPCODE_USE'
),
30
]),
31
'CODE'
=>
new
Field\Text
(
'CODE'
, [
32
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_MAPCODE'
),
33
'placeholder'
=>
Loc::getMessage
(
'LANDING_HOOK_MAPCODE_PLACEHOLDER'
),
34
'help'
=> $helpUrl
35
?
'<a href="'
. $helpUrl .
'" target="_blank">'
36
.
Loc::getMessage
(
'LANDING_HOOK_MAPCODE_HELP'
)
37
.
'</a>'
38
:
''
,
39
]),
40
];
41
}
42
47
public
function
enabled
()
48
{
49
if
($this->
issetCustomExec
())
50
{
51
return
true
;
52
}
53
54
if
($this->
isPage
())
55
{
56
return
false
;
57
}
58
59
return
60
$this->fields[
'USE'
]->getValue() ===
'Y'
61
&& !empty($this->fields[
'CODE'
]->getValue())
62
;
63
}
64
69
public
function
exec
()
70
{
71
if
($this->
execCustom
())
72
{
73
return
;
74
}
75
76
$code = HtmlFilter::encode(trim($this->fields[
'CODE'
]));
77
$assets = Asset::getInstance();
78
$assets->addString(
79
"<script defer>
80
(function(){
81
'use strict';
82
//fake function, if API will loaded fasten than blocks
83
window.onGoogleMapApiLoaded = function(){}
84
})();
85
</script>"
86
);
87
$lang = $this->
getLang
();
88
$assets->addString(
89
'<script defer src="https://maps.googleapis.com/maps/api/js?key='
90
. $code
91
.
'®ion='
92
. $lang
93
.
'&language='
94
. $lang
95
.
'&callback=onGoogleMapApiLoaded"></script>'
96
);
97
}
98
104
public
function
setSiteId
(
int
$siteId): void
105
{
106
$this->siteId = $siteId;
107
}
108
113
protected
function
getLang
(): string
114
{
115
$lang =
null
;
116
if
($this->siteId > 0)
117
{
118
$res = SiteTable::getList([
119
'select'
=> [
120
'LANG'
121
],
122
'filter'
=> [
123
'=ID'
=> $this->siteId
124
]
125
])->fetch();
126
if
($res[
'LANG'
])
127
{
128
$lang = $res[
'LANG'
];
129
if
($lang ===
'tc'
)
130
{
131
$lang =
'zh'
;
132
}
133
if
($lang ===
'vn'
)
134
{
135
$lang =
'vi'
;
136
}
137
}
138
}
139
return
$lang ?:
Manager::getZone
();
140
}
141
}
Bitrix\Landing\Assets\Manager
Definition
manager.php:20
Bitrix\Landing\Field\Checkbox
Definition
checkbox.php:5
Bitrix\Landing\Field\Text
Definition
text.php:5
Bitrix\Landing\Help
Definition
help.php:5
Bitrix\Landing\Help\getHelpUrl
static getHelpUrl(string $code)
Definition
help.php:268
Bitrix\Landing\Hook\Page\GMap
Definition
gmap.php:16
Bitrix\Landing\Hook\Page\GMap\getMap
getMap()
Definition
gmap.php:24
Bitrix\Landing\Hook\Page\GMap\enabled
enabled()
Definition
gmap.php:47
Bitrix\Landing\Hook\Page\GMap\setSiteId
setSiteId(int $siteId)
Definition
gmap.php:104
Bitrix\Landing\Hook\Page\GMap\getLang
getLang()
Definition
gmap.php:113
Bitrix\Landing\Hook\Page\GMap\exec
exec()
Definition
gmap.php:69
Bitrix\Landing\Hook\Page
Definition
page.php:7
Bitrix\Landing\Hook\Page\isPage
isPage()
Definition
page.php:66
Bitrix\Landing\Hook\Page\issetCustomExec
issetCustomExec()
Definition
page.php:253
Bitrix\Landing\Hook\Page\execCustom
execCustom()
Definition
page.php:262
Bitrix\Landing\Internals\SiteTable
Definition
site.php:34
Bitrix\Landing\Manager\getZone
static getZone()
Definition
manager.php:925
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\Text\HtmlFilter
Definition
htmlfilter.php:11
Bitrix\Landing\Field
Definition
checkbox.php:2
Bitrix\Landing\Hook\Page
Definition
b24button.php:2
modules
landing
lib
hook
page
gmap.php
Создано системой
1.10.0