parent
648e171a57
commit
895e9f4b15
@ -24,6 +24,12 @@ class OGPResolver implements Resolver
|
|||||||
$metadata = new Metadata();
|
$metadata = new Metadata();
|
||||||
|
|
||||||
$metadata->title = $this->findContent($xpath, '//meta[@*="og:title"]', '//meta[@*="twitter:title"]');
|
$metadata->title = $this->findContent($xpath, '//meta[@*="og:title"]', '//meta[@*="twitter:title"]');
|
||||||
|
if (empty($metadata->title)) {
|
||||||
|
$nodes = $xpath->query('//title');
|
||||||
|
if ($nodes->length !== 0) {
|
||||||
|
$metadata->title = $nodes->item(0)->textContent;
|
||||||
|
}
|
||||||
|
}
|
||||||
$metadata->description = $this->findContent($xpath, '//meta[@*="og:description"]', '//meta[@*="twitter:description"]');
|
$metadata->description = $this->findContent($xpath, '//meta[@*="og:description"]', '//meta[@*="twitter:description"]');
|
||||||
$metadata->image = $this->findContent($xpath, '//meta[@*="og:image"]', '//meta[@*="twitter:image"]');
|
$metadata->image = $this->findContent($xpath, '//meta[@*="og:image"]', '//meta[@*="twitter:image"]');
|
||||||
|
|
||||||
|
@ -25,4 +25,14 @@ class OGPResolverTest extends TestCase
|
|||||||
$this->assertEquals('The Open Graph protocol enables any web page to become a rich object in a social graph.', $metadata->description);
|
$this->assertEquals('The Open Graph protocol enables any web page to become a rich object in a social graph.', $metadata->description);
|
||||||
$this->assertEquals('http://ogp.me/logo.png', $metadata->image);
|
$this->assertEquals('http://ogp.me/logo.png', $metadata->image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testResolveTitleOnly()
|
||||||
|
{
|
||||||
|
$resolver = new OGPResolver();
|
||||||
|
|
||||||
|
$metadata = $resolver->resolve('http://example.com');
|
||||||
|
$this->assertEquals('Example Domain', $metadata->title);
|
||||||
|
$this->assertEmpty($metadata->description);
|
||||||
|
$this->assertEmpty($metadata->image);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user