3 homepage: http://arc.semsol.org/
4 license: http://arc.semsol.org/license
6 class: ARC2 POSH RDF Serializer
7 author: Benjamin Nowack
8 version: 2008-11-18 (Tweak: Updated to poshRDF spec draft)
11 ARC2::inc('RDFSerializer');
13 class ARC2_POSHRDFSerializer extends ARC2_RDFSerializer {
15 function __construct($a = '', &$caller) {
16 parent::__construct($a, $caller);
19 function ARC2_POSHRDFSerializer($a = '', &$caller) {/* ns */
20 $this->__construct($a, $caller);
25 $this->content_header = 'text/html';
30 function getLabel($res, $ps = '') {
31 if (!$ps) $ps = array();
32 foreach ($ps as $p => $os) {
33 if (preg_match('/[\/\#](name|label|summary|title|fn)$/i', $p)) {
34 return $os[0]['value'];
37 if (preg_match('/^\_\:/', $res)) return "An unnamed resource";
38 return preg_replace("/^(.*[\/\#])([^\/\#]+)$/", '\\2', str_replace('_', ' ', $res));
41 function getSerializedIndex($index, $res = '') {
44 if ($res) $index = array($res => $index[$res]);
45 //return Trice::dump($index);
46 foreach ($index as $s => $ps) {
49 <div class="rdf-view">
50 <h3><a class="rdf-s" href="' . $s . '">' . $this->getLabel($s, $ps) . '</a></h3>
53 foreach ($ps as $p => $os) {
55 <div class="rdf-o-list">
56 <a class="rdf-p" href="' . $p . '">' . ucfirst($this->getLabel($p)) . '</a>
59 $r .= $n . $this->getObjectValue($o);
67 <div class="clb"></div>
74 function getObjectValue($o) {
75 if ($o['type'] == 'uri') {
76 if (preg_match('/(jpe?g|gif|png)$/i', $o['value'])) {
77 return $this->getImageObjectValue($o);
79 return $this->getURIObjectValue($o);
81 if ($o['type'] == "bnode") {
82 return $this->getBNodeObjectValue($o);
84 return $this->getLiteralObjectValue($o);
87 function getImageObjectValue($o) {
88 return '<img class="rdf-o" src="' . htmlspecialchars($o['value']) . '" alt="img" />';
91 function getURIObjectValue($o) {
92 $href = htmlspecialchars($o['value']);
94 $label = preg_replace('/^https?\:\/\/(www\.)?/', '', $label);
95 return '<a class="rdf-o" href="' . $href . '">' . $label . '</a>';
98 function getBNodeObjectValue($o) {
99 return '<div class="rdf-o" title="' . $o['value']. '">An unnamed resource</div>';
102 function getLiteralObjectValue($o) {
103 return '<div class="rdf-o">' . $o['value'] . '</div>';