* @package ARC2 * @version 2010-11-16 */ ARC2::inc('RDFSerializer'); class ARC2_MicroRDFSerializer extends ARC2_RDFSerializer { function __construct($a, &$caller) { parent::__construct($a, $caller); } function __init() { parent::__init(); $this->content_header = 'text/html'; $this->label_store = $this->v('label_store', '', $this->a); } /* */ function getLabel($res, $ps = '') { if (!$ps) $ps = array(); foreach ($ps as $p => $os) { if (preg_match('/[\/\#](name|label|summary|title|fn)$/i', $p)) { return $os[0]['value']; } } if (preg_match('/^\_\:/', $res)) return "An unnamed resource"; return $this->extractTermLabel($res); return preg_replace("/^(.*[\/\#])([^\/\#]+)$/", '\\2', str_replace('_', ' ', $res)); } function getSerializedIndex($index, $res = '') { $r = ''; $n = "\n"; if ($res) $index = array($res => $index[$res]); //return Trice::dump($index); $types = $this->v($this->expandPName('rdf:type'), array(), $index); $main_type = $types ? $types[0]['value'] : ''; foreach ($index as $s => $ps) { /* node */ $r .= '
mdAttrs($s, $main_type) . '>

' . ucfirst($this->getLabel($s, $ps)) . '

'; /* arcs */ foreach ($ps as $p => $os) { $p_cls = strtolower($this->getPName($p)); $p_cls = str_replace(':', '-', $p_cls); $r .= '
' . ucfirst($this->getLabel($p)) . ':
'; } /* /node */ $r .= '
'; } return $r; } function getObjectValue($o, $p) { if ($o['type'] == 'uri') { if (preg_match('/(jpe?g|gif|png)$/i', $o['value'])) { return $this->getImageObjectValue($o, $p); } return $this->getURIObjectValue($o, $p); } if ($o['type'] == "bnode") { return $this->getBNodeObjectValue($o, $p); } return $this->getLiteralObjectValue($o, $p); } function getImageObjectValue($o, $p) { return 'img'; } function getURIObjectValue($o, $p) { $id = htmlspecialchars($o['value']); $label = $this->getObjectLabel($o['value']); /* differing href */ $href = htmlspecialchars($this->v('href', $o['value'], $o)); if ($id != $href) { return '' . $label . ''; } return '' . $label . ''; //$label = $o['value']; //$label = preg_replace('/^https?\:\/\/(www\.)?/', '', $label); } function getBNodeObjectValue($o, $p) { return '
' . $o['value'] . '
'; return '
An unnamed resource
'; } function getLiteralObjectValue($o, $p) { return '
' . $o['value'] . '
'; } /* */ function getObjectLabel($id) { $r = $this->extractTermLabel($id); if (!$this->label_store) return $r; $q = ' SELECT ?val WHERE { <' . $id . '> ?p ?val . FILTER(REGEX(str(?p), "(label|title|name|summary)$")) } LIMIT 1 '; $row = $this->label_store->query($q, 'row'); return $row ? $row['val'] : $r; } /* */ }