Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
metaog.php
1
<?php
2
namespace
Bitrix\Landing\Hook\Page
;
3
4
use \Bitrix\Landing\Hook;
5
use \Bitrix\Landing\Internals\HookDataTable;
6
use \Bitrix\Landing\File;
7
use \Bitrix\Landing\Manager;
8
use \Bitrix\Landing\Field;
9
use \Bitrix\Landing\PublicAction;
10
use \Bitrix\Landing\Landing\Seo;
11
use \Bitrix\Main\Localization\Loc;
12
13
Loc::loadMessages
(__FILE__);
14
15
class
MetaOg
extends
\Bitrix\Landing\Hook\Page
16
{
21
protected
function
getMap
()
22
{
23
return
array(
24
'TITLE'
=>
new
Field
\
Textarea
(
'TITLE'
, array(
25
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_METAOG_TITLE'
),
26
'placeholder'
=>
Loc::getMessage
(
'LANDING_HOOK_METAOG_TITLE_PLACEHOLDER'
),
27
'maxlength'
=> 140,
28
'searchable'
=>
true
29
)),
30
'DESCRIPTION'
=>
new
Field
\
Textarea
(
'DESCRIPTION'
, array(
31
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_METAOG_DESCRIPTION'
),
32
'placeholder'
=>
Loc::getMessage
(
'LANDING_HOOK_METAOG_DESCRIPTION_PLACEHOLDER'
),
33
'maxlength'
=> 300,
34
'searchable'
=>
true
35
)),
36
'IMAGE'
=>
new
Field
\
Hidden
(
'IMAGE'
, array(
37
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_METAOG_PICTURE'
),
38
'fetch_data_modification'
=>
function
($value)
39
{
40
if
(
PublicAction::restApplication
())
41
{
42
if
($value > 0)
43
{
44
$path =
File::getFilePath
($value);
45
if
($path)
46
{
47
$path =
Manager::getUrlFromFile
($path);
48
return
$path;
49
}
50
}
51
}
52
return
$value;
53
}
54
))
55
);
56
}
57
63
public
static
function
getAllImages
($entityType =
Hook::ENTITY_TYPE_LANDING
)
64
{
65
$images = array();
66
$res = HookDataTable::getList(array(
67
'select'
=> array(
68
'VALUE'
,
'ENTITY_ID'
69
),
70
'filter'
=> array(
71
'=HOOK'
=>
'METAOG'
,
72
'=CODE'
=>
'IMAGE'
,
73
'=ENTITY_TYPE'
=> $entityType,
74
'=PUBLIC'
=>
'N'
75
)
76
));
77
while
($row = $res->fetch())
78
{
79
$images[$row[
'ENTITY_ID'
]] = $row[
'VALUE'
];
80
}
81
82
return
$images;
83
}
84
89
public
function
getTitle
()
90
{
91
return
Loc::getMessage
(
'LANDING_HOOK_METAOG_NAME'
);
92
}
93
98
public
function
enabledInEditMode
()
99
{
100
return
false
;
101
}
102
107
public
function
enabled
()
108
{
109
if
($this->
issetCustomExec
())
110
{
111
return
true
;
112
}
113
114
return
115
trim($this->fields[
'TITLE'
]) !=
''
||
116
trim($this->fields[
'DESCRIPTION'
]) !=
''
||
117
trim($this->fields[
'IMAGE'
]) !=
''
;
118
}
119
124
public
function
exec
()
125
{
126
if
($this->
execCustom
())
127
{
128
return
;
129
}
130
131
$output =
''
;
132
$files = [];
133
$tags = [
134
'title'
=> \htmlspecialcharsbx(Seo::processValue(
'title'
, $this->fields[
'TITLE'
])),
135
'description'
=> \htmlspecialcharsbx(Seo::processValue(
'description'
, $this->fields[
'DESCRIPTION'
])),
136
'image'
=> trim($this->fields[
'IMAGE'
]),
137
'type'
=>
'website'
138
];
139
foreach
([
'og'
,
'twitter'
] as $rootTag)
140
{
141
foreach
($tags as $key => $val)
142
{
143
if
($key ==
'image'
&& intval($val) > 0)
144
{
145
$val = intval($val);
146
if
(!array_key_exists($val, $files))
147
{
148
$files[$val] =
File::getFileArray
($val);
149
}
150
$val = $files[$val];
151
}
152
if
($val)
153
{
154
if
($key ==
'image'
)
155
{
156
if
(is_array($val))
157
{
158
$val[
'SRC'
] =
Manager::getUrlFromFile
($val[
'SRC'
]);
159
$output .=
'<meta property="'
. $rootTag .
':image" content="'
. str_replace(
' '
,
'%20'
, \htmlspecialcharsbx($val[
'SRC'
])) .
'" />'
;
160
if
($rootTag !=
'twitter'
)
161
{
162
$output .=
163
'<meta property="'
. $rootTag .
':image:width" content="'
. $val[
'WIDTH'
] .
'" />'
.
164
'<meta property="'
. $rootTag .
':image:height" content="'
. $val[
'HEIGHT'
] .
'" />'
;
165
}
166
}
167
else
168
{
169
$output .=
'<meta property="'
. $rootTag .
':image" content="'
. str_replace(
' '
,
'%20'
, \htmlspecialcharsbx($val)) .
'" />'
;
170
}
171
if
($rootTag ==
'twitter'
)
172
{
173
$output .=
'<meta name="twitter:card" content="summary_large_image" />'
;
174
}
175
}
176
else
177
{
178
$output .=
'<meta property="'
. $rootTag .
':'
. $key .
'" content="'
. $val .
'" />'
;
179
}
180
}
181
}
182
}
183
if
($output)
184
{
185
Manager::setPageView
(
'MetaOG'
, $output);
186
}
187
}
188
}
Bitrix\Landing\Field\Hidden
Definition
hidden.php:5
Bitrix\Landing\Field\Textarea
Definition
textarea.php:5
Bitrix\Landing\Field
Definition
field.php:5
Bitrix\Landing\File\getFileArray
static getFileArray($fileId)
Definition
file.php:580
Bitrix\Landing\File\getFilePath
static getFilePath($fileId)
Definition
file.php:600
Bitrix\Landing\Hook\Page\MetaOg
Definition
metaog.php:16
Bitrix\Landing\Hook\Page\MetaOg\getAllImages
static getAllImages($entityType=Hook::ENTITY_TYPE_LANDING)
Definition
metaog.php:63
Bitrix\Landing\Hook\Page\MetaOg\getMap
getMap()
Definition
metaog.php:21
Bitrix\Landing\Hook\Page\MetaOg\getTitle
getTitle()
Definition
metaog.php:89
Bitrix\Landing\Hook\Page\MetaOg\enabledInEditMode
enabledInEditMode()
Definition
metaog.php:98
Bitrix\Landing\Hook\Page\MetaOg\enabled
enabled()
Definition
metaog.php:107
Bitrix\Landing\Hook\Page\MetaOg\exec
exec()
Definition
metaog.php:124
Bitrix\Landing\Hook\Page
Definition
page.php:7
Bitrix\Landing\Hook\Page\issetCustomExec
issetCustomExec()
Definition
page.php:253
Bitrix\Landing\Hook\Page\execCustom
execCustom()
Definition
page.php:262
Bitrix\Landing\Hook\ENTITY_TYPE_LANDING
const ENTITY_TYPE_LANDING
Definition
hook.php:25
Bitrix\Landing\Manager\getUrlFromFile
static getUrlFromFile($file)
Definition
manager.php:1067
Bitrix\Landing\Manager\setPageView
static setPageView(string $marker, string $content, bool $skipTrim=false)
Definition
manager.php:465
Bitrix\Landing\PublicAction\restApplication
static restApplication()
Definition
publicaction.php:540
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\Landing\Hook\Page
Definition
b24button.php:2
modules
landing
lib
hook
page
metaog.php
Создано системой
1.10.0