You are here

function taxonomy_xml_parse_curie in Taxonomy import/export via XML 6.2

Utility function to try and figure out what a given CURIE means

Returns an array containing (most likely) an id shortname of the CURIE. This will be either the fragment or the last pat of the path found.

Depending on available informations, maybe also the prefix and namespace.

Give it either a URI or CURIE - it'll guess. TODO actual namespaces.

Parameters

$part Name a part of the CURIE/URI, eg 'prefix', 'id', 'host' and that: is the bit that will be returned.

See also

parse_url()

1 call to taxonomy_xml_parse_curie()
taxonomy_xml_entity_to_rdf in ./rdf_format.inc
Given a Drupal object, some mapping rules and a DOMDocument, create the XML representationof the thing

File

./rdf_format.inc, line 1283
Include routines for RDF parsing and taxonomy/term creation. @author dman http://coders.co.nz

Code

function taxonomy_xml_parse_curie($curie, $part = NULL) {
  $rdf_namespaces = taxonomy_xml_get_namespaces();
  if (taxonomy_xml_is_valid_curie($curie)) {
    list($prefix, $id) = explode(':', $curie, 2);
    $curie_parts['prefix'] = $prefix;
    $curie_parts['id'] = $id;

    // TODO namespace expansion - when we need it
  }
  elseif (valid_url($curie)) {
    $curie_parts = parse_url($curie);

    // in that case, the CURIE is the version splitting the main from the last # or /
    // TODO
    $curie_parts['id'] = empty($curie_parts['fragment']) ? basename($curie_parts['id']) : $curie_parts['fragment'];
  }
  $curie_parts = $curie_parts + array(
    'css_class' => preg_replace('/[^a-z0-9]+/i', '-', basename($curie_parts['id'])),
  );
  if (empty($curie_parts['uri']) && !empty($rdf_namespaces[$curie_parts['prefix']])) {
    $curie_parts['uri'] = $rdf_namespaces[$curie_parts['prefix']];
  }
  if ($part) {
    return @$curie_parts[$part];
  }
  return $curie_parts;
}