38 $isHttpClientPassed =
true;
42 $isHttpClientPassed =
false;
49 || $httpClient->getStatus() === 403
51 && mb_strpos($this->metadataUrl,
'http://') === 0)
53 if(!$isHttpClientPassed)
57 $metadataUrl = str_replace(
'http://',
'https://', $this->metadataUrl);
61 if($rawMetadata ===
false)
67 if($parsedMetadata !==
false)
69 if($this->metadataEncoding <>
'' && $document->
getEncoding() !== $this->metadataEncoding)
71 $parsedMetadata = Encoding::convertEncoding($parsedMetadata, $this->metadataEncoding, $document->
getEncoding());
74 if($document->
getTitle() ==
'' && !empty($parsedMetadata[
'title']))
76 $document->
setTitle($parsedMetadata[
'title']);
79 if($document->
getImage() ==
'' && !empty($parsedMetadata[
'thumbnail_url']))
81 $document->
setImage($parsedMetadata[
'thumbnail_url']);
84 if($document->
getEmdbed() ==
'' && !empty($parsedMetadata[
'html']))
86 $document->
setEmbed($parsedMetadata[
'html']);
89 if($document->
getExtraField(
'PROVIDER_NAME') ==
'' && !empty($parsedMetadata[
'provider_name']))
91 $document->
setExtraField(
'PROVIDER_NAME', $parsedMetadata[
'provider_name']);
94 if($document->
getExtraField(
'VIDEO_WIDTH') ==
'' && !empty($parsedMetadata[
'width']))
96 $document->
setExtraField(
'VIDEO_WIDTH', $parsedMetadata[
'width']);
99 if($document->
getExtraField(
'VIDEO_HEIGHT') ==
'' && !empty($parsedMetadata[
'height']))
101 $document->
setExtraField(
'VIDEO_HEIGHT', $parsedMetadata[
'height']);
112 preg_match_all(
'/<link[^>]*rel\s*=\s*["\']?alternate["\']?[^>]*?>/', $document->
getHtml(), $linkElements);
114 foreach($linkElements[0] as $linkElement)
116 $typeJson = (strpos($linkElement, $this::OEMBED_TYPE_JSON) !==
false);
117 $typeXml = (strpos($linkElement, $this::OEMBED_TYPE_XML) !==
false);
118 if($typeJson || $typeXml)
120 if(preg_match(
'/href=[\'"](.+?)[\'"]/', $linkElement, $attributes))
122 $this->metadataType = ($typeJson ?
'json' :
'xml');
123 $this->metadataUrl = htmlspecialcharsback($attributes[1]);
165 $xml = new \CDataXML();
166 if($xml->LoadString($rawMetadata))
169 if(preg_match(
'/<\?xml[^>]+?encoding=[\'"](.+?)[\'"]\?>/', $rawMetadata, $matches))
170 $this->metadataEncoding = $matches[1];
172 $this->metadataEncoding =
'UTF-8';
175 $dom = $xml->GetTree();
176 $mainNode = $dom->elementsByName(
'oembed');
177 foreach($mainNode[0]->children as $node)
179 $result[$node->name] = $node->content;