function print_rdf($rdf, $tabs = 0, $ns = array(), $hide = array(), $aria = false) { $hide = array_merge($hide, array('rdf:type', 'dcterms:title', 'sioc:content')); foreach ($rdf as $p => $values) { if (in_array($p, $hide)) { continue; } foreach ($values as $value) { if (isURL($value['value'])) { $str = '<a class="metadata" aria-hidden="' . ($aria ? 'false' : 'true') . '" rel="' . toNS($p, $ns) . '" href="' . $value['value'] . '"></a>' . "\n"; } else { $str = '<span class="metadata" aria-hidden="' . ($aria ? 'false' : 'true') . '" property="' . toNS($p, $ns) . '">' . $value['value'] . '</span>' . "\n"; } for ($j = 0; $j < $tabs; $j++) { $str = "\t" . $str; } echo $str; } } }
echo "</tr>\n"; } } ?> </table> <?php foreach ($page->versions as $key => $version) { echo '<table class="metadata" cellspacing="2" cellpadding="0">'; echo '<tr><th colspan="3">Version (' . $version->version_num . ')</th></tr>'; echo '<tr><td style="white-space:nowrap;"><b>resource</b></td><td>rdf:resource</td><td><a href="' . $base_uri . $page->slug . '.' . $version->version_num . '">' . $base_uri . $page->slug . '.' . $version->version_num . '</a></td></tr>'; foreach ($version->meta as $p => $values) { if ('http://rdfs.org/sioc/ns#content' == $p) { continue; } foreach ($values as $value) { $p = toNS($p, $ns); $human_title = spacify(str_replace('_', ' ', no_ns($p))); if (strstr($human_title, '#')) { $human_title = substr($human_title, strpos($human_title, '#') + 1); } if ($p == 'sioc:primaryTopic') { $human_title = 'Source file'; } if ($human_title == 'urn') { continue; } $type = $value['type']; $value = $value['value']; $value = substr($value, 0, 4) == 'http' ? '<a href="' . $value . '">' . $value . '</a>' : $value; echo '<tr>'; echo '<td style="white-space:nowrap;"><b>' . $human_title . '</b></td>';
/** * Filter a DB result of versions based on a search query (an array of terms) */ public function filter_result_i($result, $sq) { $result = (array) $result; $results = array(); $matched = array(); $ns = $this->config->item('namespaces'); foreach ($sq as $term) { // Version fields foreach ($result as $key => $value) { if (!is_string($value)) { continue; } $value = strip_tags($value); if (!stristr($value, $term)) { continue; } if (!in_array($term, $results)) { $results[] = $term; } $matched[] = toNS($key, $ns); } } //if (count($results)==count($sq)) return $matched; if (isset($result['rdf']) && !empty($result['rdf'])) { foreach ($sq as $term) { // RDF fields foreach ($result['rdf'] as $key => $values) { $type = $values[0]['type']; if ('literal' != $type) { continue; } $value = $values[0]['value']; $value = strip_tags($value); if (!stristr($value, $term)) { continue; } if (!in_array($term, $results)) { $results[] = $term; } $matched[] = toNS($key, $ns); } } } if (count($results) == count($sq)) { return $matched; } return false; }
private function _scrub_version_fields($obj, $content_id = 0, $options = array()) { $ns_array = $this->CI->config->item('namespaces'); $array = (array) $obj; // RDF fields have colons in them, invalid as object field names // Scrub fields if (isset($array['created'])) { unset($array['created']); } if (isset($array['urn'])) { unset($array['urn']); } $array['user_id'] = isset($array['user']) ? (int) $array['user'] : 0; $array['content_id'] = (int) $content_id; // Flatten RDF fields in the array, then remove the RDF field if (isset($array['rdf'])) { foreach ($array['rdf'] as $field => $value) { $field = toNS($field, $ns_array); $array[$field] = $value; } } unset($array['rdf']); // URLs: set to previous book's URL, to avoid duplicating media if (isset($array['url']) && !empty($array['url']) && isset($options['prev_uri'])) { $has_transcribed = false; // Soft URL if (!isURL($array['url'])) { $array['url'] = confirm_slash($options['prev_uri']) . $array['url']; // Update RDF dcterms:source with title of previous book if (!isset($array['dcterms:source'])) { $array['dcterms:source'] = array(); } $array['dcterms:source'][] = array('value' => strip_tags($options['prev_title']), 'type' => 'literal'); } } // Text content: remove hard URLs in resource="" and make hard href="" if (isset($options['prev_uri'])) { $array['content'] = str_replace('resource="' . confirm_slash($options['prev_uri']), 'resource="', $array['content']); // TODO: replace with regex on the href="" attribute $array['content'] = str_replace('href="media/', 'href="' . confirm_slash($options['prev_uri']) . 'media/', $array['content']); } return $array; }