forked from sweetrdf/easyrdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
foafinfo.php
85 lines (77 loc) · 2.52 KB
/
foafinfo.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* Display the basic information in a FOAF document
*
* The example starts by loading the requested FOAF document
* from the web. It then tries to work out if the URI given
* was for the person or the document about the person.
*
* If a person is found, then the person's name, homepage
* and description are shown, along with a list of the
* person's friends.
*
* @copyright Copyright (c) 2009-2014 Nicholas J Humfrey
* @license http://unlicense.org/
*/
require_once realpath(__DIR__.'/..').'/vendor/autoload.php';
require_once __DIR__.'/html_tag_helpers.php';
?>
<html>
<head><title>EasyRdf FOAF Info Example</title></head>
<body>
<h1>EasyRdf FOAF Info Example</h1>
<?php echo form_tag(); ?>
<?php echo text_field_tag('uri', 'http://njh.me/foaf.rdf', ['size' => 50]); ?>
<?php echo submit_tag(); ?>
<?php echo form_end_tag(); ?>
<?php
if (isset($_REQUEST['uri'])) {
$graph = \EasyRdf\Graph::newAndLoad($_REQUEST['uri']);
if ('foaf:PersonalProfileDocument' == $graph->type()) {
$person = $graph->primaryTopic();
} elseif ('foaf:Person' == $graph->type()) {
$person = $graph->resource();
}
}
if (isset($person)) {
?>
<dl>
<dt>Name:</dt><dd><?php echo $person->get('foaf:name'); ?></dd>
<dt>Homepage:</dt><dd><?php echo link_to($person->get('foaf:homepage')); ?></dd>
</dl>
<?php
echo "<h2>Known Persons</h2>\n";
echo "<ul>\n";
foreach ($person->all('foaf:knows') as $friend) {
$label = $friend->label();
if (!$label) {
$label = $friend->getUri();
}
if ($friend->isBNode()) {
echo "<li>$label</li>";
} else {
echo '<li>'.link_to_self($label, 'uri='.urlencode($friend)).'</li>';
}
}
echo "</ul>\n";
echo "<h2>Interests</h2>\n";
echo "<ul>\n";
foreach ($person->all('foaf:interest') as $interest) {
$label = $interest->label();
if ($label) {
if ($interest->isBNode()) {
echo "<li>$label</li>";
} else {
echo '<li>'.$interest->htmlLink($label).'</li>';
}
}
}
echo "</ul>\n";
}
if (isset($graph)) {
echo '<br />';
echo $graph->dump();
}
?>
</body>
</html>