forked from easyrdf/easyrdf
-
Notifications
You must be signed in to change notification settings - Fork 6
/
open_graph_protocol.php
41 lines (38 loc) · 1.08 KB
/
open_graph_protocol.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
* Example of reading Open Graph Protocol properties
*
* Fetches and parses an HTML, reading the Open Graph Protocol data from the page.
* Open Graph Protocol uses a subset of RDFa.
*
* @copyright Copyright (c) 2020 Nicholas J Humfrey
* @license http://unlicense.org/
*/
require_once realpath(__DIR__.'/..').'/vendor/autoload.php';
require_once __DIR__.'/html_tag_helpers.php';
EasyRdf\RdfNamespace::setDefault('og');
?>
<html>
<head>
<title>Open Graph Protocol example</title>
<style type="text/css">
body { font-family: sans-serif; }
dt { font-weight: bold; }
.image { float: right; margin: 10px;}
</style>
</head>
<body>
<?php
$doc = EasyRdf\Graph::newAndLoad('https://www.rottentomatoes.com/m/oceans_eleven');
if ($doc->image) {
echo content_tag('img', null, ['src' => $doc->image, 'class' => 'image']);
}
?>
<h1>Open Graph Protocol example</h1>
<dl>
<dt>Page:</dt> <dd><?php echo link_to($doc->url); ?></dd>
<dt>Title:</dt> <dd><?php echo $doc->title; ?></dd>
<dt>Description:</dt> <dd><?php echo $doc->description; ?></dd>
</dl>
</body>
</html>