silence errors on these xpath queries

This commit is contained in:
hannes 2016-01-26 11:28:24 +00:00
parent 884aeb4d2e
commit b8d1e1f4a6

View File

@ -50,18 +50,18 @@ class OembedPlugin extends Plugin
// Facebook just gives us javascript in its oembed html, // Facebook just gives us javascript in its oembed html,
// so use the content of the title element instead // so use the content of the title element instead
if(strpos($url,'https://www.facebook.com/') === 0) { if(strpos($url,'https://www.facebook.com/') === 0) {
$metadata->html = $dom->getElementsByTagName('title')->item(0)->nodeValue; $metadata->html = @$dom->getElementsByTagName('title')->item(0)->nodeValue;
} }
// Wordpress sometimes also just gives us javascript, use og:description if it is available // Wordpress sometimes also just gives us javascript, use og:description if it is available
$xpath = new DomXpath($dom); $xpath = new DomXpath($dom);
$generatorNode = $xpath->query('//meta[@name="generator"][1]')->item(0); $generatorNode = @$xpath->query('//meta[@name="generator"][1]')->item(0);
if ($generatorNode instanceof DomElement) { if ($generatorNode instanceof DomElement) {
// when wordpress only gives us javascript, the html stripped from tags // when wordpress only gives us javascript, the html stripped from tags
// is the same as the title, so this helps us to identify this (common) case // is the same as the title, so this helps us to identify this (common) case
if(strpos($generatorNode->getAttribute('content'),'WordPress') === 0 if(strpos($generatorNode->getAttribute('content'),'WordPress') === 0
&& trim(strip_tags($metadata->html)) == trim($metadata->title)) { && trim(strip_tags($metadata->html)) == trim($metadata->title)) {
$propertyNode = $xpath->query('//meta[@property="og:description"][1]')->item(0); $propertyNode = @$xpath->query('//meta[@property="og:description"][1]')->item(0);
if ($propertyNode instanceof DomElement) { if ($propertyNode instanceof DomElement) {
$metadata->html = $propertyNode->getAttribute('content'); $metadata->html = $propertyNode->getAttribute('content');
} }