| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
//////////////////////////////////////////////////////////////////////////////
|
| 5 |
// Theme callbacks: Property-value tables
|
| 6 |
|
| 7 |
function theme_rdf_property_table($data) {
|
| 8 |
$rows = array();
|
| 9 |
|
| 10 |
if (!empty($data)) {
|
| 11 |
$data = is_object($data) ? rdf_normalize($data) : $data;
|
| 12 |
|
| 13 |
foreach ($data as $subject => $predicates) {
|
| 14 |
foreach ($predicates as $predicate => $objects) {
|
| 15 |
foreach ($objects as $object) {
|
| 16 |
$rows[] = array(
|
| 17 |
array('data' => theme('rdf_triple_cell', $predicate), 'header' => TRUE),
|
| 18 |
theme('rdf_triple_cell', $object),
|
| 19 |
);
|
| 20 |
}
|
| 21 |
}
|
| 22 |
}
|
| 23 |
}
|
| 24 |
|
| 25 |
if (empty($rows)) {
|
| 26 |
$rows[] = array(array('data' => t('No data.'), 'colspan' => 2));
|
| 27 |
}
|
| 28 |
|
| 29 |
return theme('table', array(), $rows, array('class' => 'rdf-properties'));
|
| 30 |
}
|
| 31 |
|
| 32 |
//////////////////////////////////////////////////////////////////////////////
|
| 33 |
// Theme callbacks: Triple tables
|
| 34 |
|
| 35 |
function theme_rdf_triple_table($data, array $options = array()) {
|
| 36 |
$head = array(t('Subject'), t('Predicate'), t('Object'));
|
| 37 |
$rows = array();
|
| 38 |
|
| 39 |
if (!empty($data)) {
|
| 40 |
$data = is_object($data) ? rdf_normalize($data) : $data;
|
| 41 |
|
| 42 |
foreach ($data as $subject => $predicates) {
|
| 43 |
foreach ($predicates as $predicate => $objects) {
|
| 44 |
foreach ($objects as $object) {
|
| 45 |
$rows[] = theme('rdf_triple_row', $subject, $predicate, $object, $options);
|
| 46 |
}
|
| 47 |
}
|
| 48 |
}
|
| 49 |
}
|
| 50 |
|
| 51 |
if (empty($rows)) {
|
| 52 |
$rows[] = array(array('data' => t('No data.'), 'colspan' => 3));
|
| 53 |
}
|
| 54 |
|
| 55 |
return theme('table', $head, $rows, array('class' => 'rdf-triples'));
|
| 56 |
}
|
| 57 |
|
| 58 |
function theme_rdf_triple_row($subject, $predicate, $object, array $options = array()) {
|
| 59 |
return array(
|
| 60 |
theme('rdf_triple_cell', $subject, $options),
|
| 61 |
theme('rdf_triple_cell', $predicate, $options),
|
| 62 |
theme('rdf_triple_cell', $object, $options),
|
| 63 |
);
|
| 64 |
}
|
| 65 |
|
| 66 |
function theme_rdf_triple_cell($value, array $options = array()) {
|
| 67 |
$value = (string)$value; // FIXME
|
| 68 |
|
| 69 |
if (rdf_is_valid_uri($value)) { // FIXME
|
| 70 |
$uri = $value;
|
| 71 |
$qname = @rdf_uri_to_qname($uri, FALSE);
|
| 72 |
$title = !empty($options['brackets']) ? ($qname ? "[$qname]" : "<$uri>") : ($qname ? $qname : $uri);
|
| 73 |
return _rdf_truncate_uri($uri, $title, $options);
|
| 74 |
}
|
| 75 |
else {
|
| 76 |
return check_plain(truncate_utf8($value, 56, TRUE, TRUE));
|
| 77 |
}
|
| 78 |
}
|
| 79 |
|
| 80 |
function theme_rdf_value($value) {
|
| 81 |
switch (rdf_get_type($value)) {
|
| 82 |
case 'bnode':
|
| 83 |
case 'uri':
|
| 84 |
return _rdf_truncate_uri((string)$value, rdf_uri_to_qname((string)$value, FALSE));
|
| 85 |
case 'string':
|
| 86 |
return check_plain(truncate_utf8($value, 56, TRUE, TRUE));
|
| 87 |
case 'literal':
|
| 88 |
$tooltip = !empty($value->language) ? '@' . $value->language : $value->qname();
|
| 89 |
return '<span' . drupal_attributes(array('title' => $tooltip)) . '>' . check_plain($value->value) . '</span>';
|
| 90 |
}
|
| 91 |
}
|
| 92 |
|
| 93 |
function _rdf_truncate_uri($uri, $title = NULL, $options = array()) {
|
| 94 |
$title = $title ? $title : $uri;
|
| 95 |
$function = isset($options['link']) ? $options['link'] : 'l';
|
| 96 |
return $function(
|
| 97 |
preg_replace('/ \.\.\.$/', '...', truncate_utf8($title, 32, TRUE, TRUE)),
|
| 98 |
$uri, array('attributes' => array('title' => $uri)));
|
| 99 |
}
|