Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
opengraph.php
1
<?
2
3
namespace
Bitrix\Main\UrlPreview\Parser
;
4
5
use
Bitrix\Main\UrlPreview\HtmlDocument
;
6
use
Bitrix\Main\UrlPreview\Parser
;
7
8
class
OpenGraph
extends
Parser
9
{
16
public
function
handle
(
HtmlDocument
$document)
17
{
18
if
($document->
getTitle
() ==
''
)
19
{
20
$ogTitle = $document->
getMetaContent
(
'og:title'
);
21
if
($ogTitle <>
''
)
22
{
23
$document->
setTitle
($ogTitle);
24
}
25
}
26
27
if
($document->
getDescription
() ==
''
)
28
{
29
$ogDescription = $document->
getMetaContent
(
'og:description'
);
30
if
($ogDescription <>
''
)
31
{
32
$document->
setDescription
($ogDescription);
33
}
34
}
35
36
if
($document->
getImage
() ==
''
)
37
{
38
$ogImage = $document->
getMetaContent
(
'og:image:secure_url'
) ?: $document->
getMetaContent
(
'og:image'
);
39
if
($ogImage <>
''
)
40
{
41
$document->
setImage
($ogImage);
42
}
43
}
44
45
$this->
parseVideoData
($document);
46
47
if
(!$document->
getExtraField
(
'SITE_NAME'
))
48
{
49
$ogSiteName = $document->
getMetaContent
(
'og:site_name'
);
50
if
($ogSiteName <>
''
)
51
{
52
$document->
setExtraField
(
'SITE_NAME'
, $ogSiteName);
53
}
54
}
55
56
/* Not really opengraph property :), but it's placed in opengraph parser to prevent executing full parser chain
57
just to get favicon */
58
if
(!$document->
getExtraField
(
'FAVICON'
))
59
{
60
if
($favicon = $document->
getLinkHref
(
'icon'
))
61
{
62
$document->
setExtraField
(
'FAVICON'
, $favicon);
63
}
64
}
65
}
66
67
protected
function
parseVideoData
(
HtmlDocument
$document)
68
{
69
if
(!$document->
getExtraField
(
'VIDEO'
))
70
{
71
$ogVideo = $document->
getMetaContent
(
'og:video'
)
72
?? $document->
getMetaContent
(
'og:video:secure_url'
)
73
?? $document->
getMetaContent
(
'og:video:url'
)
74
??
''
;
75
if
($ogVideo <>
''
)
76
{
77
$document->
setExtraField
(
'VIDEO'
, $ogVideo);
78
}
79
}
80
81
if
(!$document->
getExtraField
(
'VIDEO_TYPE'
))
82
{
83
$ogVideoType = $document->
getMetaContent
(
'og:video:type'
) ??
''
;
84
if
($ogVideoType <>
''
)
85
{
86
$document->
setExtraField
(
'VIDEO_TYPE'
, $ogVideoType);
87
}
88
}
89
90
if
(!$document->
getExtraField
(
'VIDEO_WIDTH'
))
91
{
92
$ogVideoWidth = $document->
getMetaContent
(
'og:video:width'
) ??
''
;
93
if
($ogVideoWidth <>
''
)
94
{
95
$document->
setExtraField
(
'VIDEO_WIDTH'
, $ogVideoWidth);
96
}
97
}
98
99
if
(!$document->
getExtraField
(
'VIDEO_HEIGHT'
))
100
{
101
$ogVideoHeight = $document->
getMetaContent
(
'og:video:height'
) ??
''
;
102
if
($ogVideoHeight <>
''
)
103
{
104
$document->
setExtraField
(
'VIDEO_HEIGHT'
, $ogVideoHeight);
105
}
106
}
107
}
108
}
Bitrix\Main\PhoneNumber\Parser
Definition
parser.php:10
Bitrix\Main\UrlPreview\HtmlDocument
Definition
htmldocument.php:13
Bitrix\Main\UrlPreview\HtmlDocument\getLinkHref
getLinkHref($rel)
Definition
htmldocument.php:395
Bitrix\Main\UrlPreview\HtmlDocument\getImage
getImage()
Definition
htmldocument.php:155
Bitrix\Main\UrlPreview\HtmlDocument\getDescription
getDescription()
Definition
htmldocument.php:133
Bitrix\Main\UrlPreview\HtmlDocument\setDescription
setDescription($description)
Definition
htmldocument.php:144
Bitrix\Main\UrlPreview\HtmlDocument\getExtraField
getExtraField($fieldName)
Definition
htmldocument.php:246
Bitrix\Main\UrlPreview\HtmlDocument\setTitle
setTitle($title)
Definition
htmldocument.php:122
Bitrix\Main\UrlPreview\HtmlDocument\getTitle
getTitle()
Definition
htmldocument.php:111
Bitrix\Main\UrlPreview\HtmlDocument\setExtraField
setExtraField($fieldName, $fieldValue)
Definition
htmldocument.php:209
Bitrix\Main\UrlPreview\HtmlDocument\getMetaContent
getMetaContent($name)
Definition
htmldocument.php:368
Bitrix\Main\UrlPreview\HtmlDocument\setImage
setImage($image)
Definition
htmldocument.php:166
Bitrix\Main\UrlPreview\Parser\OpenGraph
Definition
opengraph.php:9
Bitrix\Main\UrlPreview\Parser\OpenGraph\parseVideoData
parseVideoData(HtmlDocument $document)
Definition
opengraph.php:67
Bitrix\Main\UrlPreview\Parser\OpenGraph\handle
handle(HtmlDocument $document)
Definition
opengraph.php:16
Bitrix\Main\UrlPreview\Parser
Definition
applemaps.php:2
modules
main
lib
urlpreview
parser
opengraph.php
Создано системой
1.10.0