Skip to content
Snippets Groups Projects
Commit 4e06e1e3 authored by Stéphane Corlosquet's avatar Stéphane Corlosquet
Browse files

Empty the rdf 7.x-2.x branch. The code has moved to http://drupal.org/project/rdfx

parent a17de66b
No related branches found
No related tags found
No related merge requests found
Showing
with 1 addition and 1579 deletions
RDF is a W3C standard for modeling and sharing distributed knowledge based on a
decentralized open-world assumption. This RDF package for Drupal 7 includes
several modules to enhance the RDF and RDFa functionnalities which are part of
Drupal 7 core.
- RDFx provides APIs for developers to manipulate RDF data, as well as output
Drupal's data as RDF/XML, nTriples or Turtle.
- RDF UI allows site administrators to manage the RDF mappings of their site:
alter default core mappings or specify mappings for the new content types and
fields they create.
- Evoc enables the import of RDF vocabularies (such as FOAF, SIOC, etc.) which
the site administrator can use to map Drupal data to RDF.
== Install the RDF module ==
1. Copy all the module files into a subdirectory called
sites/all/modules/rdf/ under your Drupal installation directory.
2. Go to Administer >> Site building >> Modules and enable the RDFx module and
any other module you like. You will find them in the "RDF" section.
3. Install the ARC2 library following one of these 2 options:
- run "drush rdf-download" (recommended, it will download the right
package and extract it at the right place for you.)
- manual install: download the library from
http://github.com/semsol/arc2/tarball/master and extract it in the rdf
module directory such that you end up with the following file structure:
sites/all/modules/rdf/vendor/arc/ARC2.php
== Bug reports ==
Post bug reports and feature requests to the issue tracking system at:
<http://drupal.org/node/add/project_issue/rdf>
== Credits ==
The original RDF module was written for Drupal 6 by Arto Bendiken. It has been
refactored for Drupal 7 by Stéphane Corlosquet, Lin Clark and Richard Cyganiak,
based on the RDF CCK and Evoc modules, which are now part of the main RDF
package for Drupal 7.
== Current maintainers ==
Stéphane "scor" Corlosquet - <http://openspring.net/>
Lin Clark - <http://lin-clark.com/>
This project has moved to http://drupal.org/project/rdfx
/*
* 3 field widget display
*/
.term {
padding: 2px;
margin-right: 10px;
background-color: #eeeeee;
}
.term-add {
margin-right: 5px;
margin-left: 5px;
}
.term-holder {
margin-top: 10px;
margin-bottom: 10px;
}
.term-remove {
cursor: pointer;
color: red;
font-weight: bold;
}
/*
* Fieldset in RDF Settings block on bundle's main edit page.
*/
.vertical-tabs #edit-rdf-title {
background:none;
padding: 0;
}
.vertical-tabs #edit-rdf-title legend {
display: inline;
padding: 20px 0 30px;
}
/*
* Terms autocomplete on administrative screens.
*/
.rdf-term-autocomplete {
margin: 0;
padding: 0;
white-space: normal;
}
.rdf-comment-autocomplete {
border-bottom: 1px solid #ccc;
color: #666;
font-size: .9em;
font-style: italic;
margin: 0;
padding-bottom: 10px;
}
\ No newline at end of file
<?php
/**
* @file
* drush integration for rdfx.
*/
/**
* Implementation of hook_drush_command().
*
* In this hook, you specify which commands your
* drush module makes available, what it does and
* description.
*
* Notice how this structure closely resembles how
* you define menu hooks.
*
* @See drush_parse_command() for a list of recognized keys.
*
* @return
* An associative array describing your command(s).
*/
function rdfx_drush_command() {
$items = array();
$items['rdf-download'] = array(
'callback' => 'rdfx_drush_arc2_download',
'description' => dt('Downloads the required ARC2 library from http://github.com/semsol/arc2'),
'aliases' => array('rdfdl'),
'arguments' => array(
'path' => dt('Optional. A path to the rdfx module. If omitted Drush will use the default location.'),
),
);
return $items;
}
/**
* Implementation of hook_drush_help().
*
* This function is called whenever a drush user calls
* 'drush help <name-of-your-command>'
*
* @param
* A string with the help section (prepend with 'drush:')
*
* @return
* A string with the help text for your command.
*/
function rdfx_drush_help($section) {
switch ($section) {
case 'drush:rdf-download':
return dt("Downloads the required ARC2 library from http://github.com/semsol/arc2. Include the optional path.");
}
}
/**
* Example drush command callback.
*
* This is where the action takes place.
*
* In this function, all of Drupals API is (usually) available, including
* any functions you have added in your own modules/themes.
*
* To print something to the terminal window, use drush_print().
*
*/
function rdfx_drush_arc2_download() {
$args = func_get_args();
if ($args[0]) {
$path = $args[0];
}
elseif(module_exists('libraries')) {
$path = 'sites/all/libraries';
// Create the path if it does not exist.
if (!is_dir($path)) {
drush_op('mkdir', $path);
drush_log(dt('Directory @path was created', array('@path' => $path)), 'notice');
}
}
else {
$path = drupal_get_path('module', 'rdfx') . '/vendor';
// Create the vendor directory if it does not exist yet.
if (!is_dir($path)) {
drush_op('mkdir', $path);
}
}
drush_op('chdir', $path);
// Download and extract library.
if (drush_shell_exec('wget --no-check-certificate -O arc.tar.gz http://github.com/semsol/arc2/tarball/master') &&
drush_shell_exec('tar zxvf arc.tar.gz') &&
drush_shell_exec('mv semsol-arc2-* arc') &&
drush_shell_exec('rm arc.tar.gz')) {
drush_log(dt('The latest ARC2 library has been downloaded to @path', array('@path' => $path)), 'success');
}
else {
drush_log(dt('Drush was unable to download the ARC2 library to @path', array('@path' => $path)), 'error');
}
}
name = External RDF Vocabulary Importer
description = Allows to import external Vocabularies in order to map them to Drupal data structure.
dependencies[] = rdfx
package = RDF
version = VERSION
core = 7.x
files[] = evoc.module
files[] = evoc.pages.inc
files[] = evoc.load_vocab.inc
files[] = evoc.install
files[] = evoc.test
<?php
/**
* @file
* Install, update and uninstall functions for the evoc module.
*/
/**
* Implements hook_install().
*/
function evoc_install() {
drupal_set_message('You can now ' . l('import the core RDF vocabularies', 'evoc/import_core') . '.');
}
\ No newline at end of file
<?php
function _evoc_load__error_handler($errno, $errstr) {
throw new Exception($errstr);
}
function _evoc_query_for_term_description(&$model, $uri) {
$label = _rdfx_query_find_literal($model, array(
array($uri, 'http://www.w3.org/2000/01/rdf-schema#label', '?')
));
$comment = _rdfx_query_find_literal($model, array(
array($uri, 'http://www.w3.org/2004/02/skos/core#definition', '?'),
array($uri, 'http://www.w3.org/2000/01/rdf-schema#comment', '?'),
));
return array(
'uri' => $uri,
'label' => $label,
'comment' => $comment,
);
}
\ No newline at end of file
<?php
/**
* @file
* Allows to import external Vocabularies in order to map them to Drupal data
* structure.
*/
/**
* Implements hook_menu().
*/
function evoc_menu() {
$items['evoc/import'] = array(
'title' => 'Import external RDF vocabulary',
'description' => 'Import RDF terms of an external vocabulary.',
'page callback' => 'evoc_import',
'access arguments' => array('administer content types'),
'file' => 'evoc.pages.inc',
);
$items['evoc/import_core'] = array(
'title' => 'Import core RDF vocabularies',
'description' => 'Perform a batch import of the vocabularies used by core.',
'page callback' => 'evoc_import_core',
'access arguments' => array('administer content types'),
'file' => 'evoc.pages.inc',
);
return $items;
}
/**
* Implements hook_menu().
*/
function evoc_rdf_namespaces() {
$ns_mappings = array();
$query = db_select('rdfx_vocabulary_graphs', 'g');
$query->fields('n', array('prefix', 'uri'));
$query->join('rdfx_namespaces', 'n', 'g.main_ns = n.nsid');
$query->orderBy('n.prefix');
$namespaces = $query->execute()->fetchAll();
foreach ((array) $namespaces as $namespace) {
$ns_mappings[$namespace->prefix] = $namespace->uri;
}
return $ns_mappings;
}
/*
* Import function for the evoc module.
*/
function evoc_import_vocabulary($vocabulary_uri, $vocabulary_prefix) {
// Fetch the defined terms and a list of the defined namespaces.
$fetched_vocab = evoc_fetch_vocabulary($vocabulary_uri, $vocabulary_prefix);
rdfx_save_terms($vocabulary_uri, $vocabulary_prefix, $fetched_vocab);
// Refresh the static variable that holds the array of namespaces.
drupal_static_reset('rdfx_get_namespaces');
//_evoc_save_rdf_terms($vocabulary_uri, $vocabulary_prefix, $fetched_terms);
}
/**
* Fetches the classes and properties of an external RDF vocabulary.
*
* @param $vocabulary_uri
* The namespace of the vocabulary to be fetched. Note most of the time this
* URI should end with / or #, e.g. http://rdfs.org/sioc/ns#
* @param $vocabulary_prefix
* Prefix used system-wide for referring to this namespace.
* @param $vocabulary_location
* URL of the vocabulary if the vocabulary namespace does not dereference and
* is not available at the namespace. Optionnal.
* @return
* An array of fetched terms.
*/
function evoc_fetch_vocabulary($vocabulary_uri, $vocabulary_prefix, $vocabulary_location = NULL) {
// Uses the vocabulary namespace URI if no specific location is given.
$vocabulary_location = $vocabulary_location ? $vocabulary_location : $vocabulary_uri;
module_load_include('inc', 'evoc', 'evoc.load_vocab');
list($triples, $namespaces) = rdfx_fetch_rdf($vocabulary_uri, $vocabulary_prefix);
$vocabulary = _rdfx_extract_schema($triples, $namespaces, $vocabulary_prefix, $vocabulary_uri);
return $vocabulary;
}
<?php
/**
* @file
* Page callbacks for importing a vocabulary.
*/
/**
* Present a node submission form or a set of links to such forms.
*/
function evoc_import() {
return drupal_get_form('evoc_import_form');
}
function evoc_import_form($form_state) {
// Retrieves all the imported namespaces from the database.
$query = db_select('rdfx_vocabulary_graphs', 'g');
$query->fields('n', array('prefix', 'uri'));
$query->join('rdfx_namespaces', 'n', 'g.main_ns = n.nsid');
$query->orderBy('n.prefix');
$namespaces = $query->execute()->fetchAll();
if (count($namespaces) == 0) {
$namespace_msg = '<p>No RDF vocabularies have been imported. It is recommended that you ' . l('import the core RDF vocabularies', 'evoc/import_core') . '.</p>';
}
else {
$table_variables = array();
foreach ($namespaces as $namespace) {
$table_variables['rows'][] = array($namespace->prefix, $namespace->uri);
}
$namespace_msg = theme('table', $table_variables);
}
$form['help'] = array(
'#type' => 'item',
'#markup' => '<p>This form allows you to import external RDF vocabularies into your site.
These can later be used by other modules such as <a href="http://drupal.org/project/rdf">RDF UI</a> or <a href="http://drupal.org/project/neologism">Neologism</a>.</p>',
);
$form['namespace_box'] = array(
'#type' => 'fieldset',
'#title' => 'Imported vocabularies',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['namespace_box']['namespaces'] = array(
'#type' => 'item',
'#markup' => $namespace_msg,
);
$form['prefix'] = array(
'#type' => 'textfield',
'#title' => t('Prefix'),
'#required' => TRUE,
'#default_value' => isset($form_state['values']['prefix']) ? $form_state['values']['prefix'] : NULL,
'#description' => "Choose a prefix for this vocabulary. Example: dc, foaf, sioc etc. This prefix will later be used in the system to refer to this vocabulary.",
);
$form['ns_uri'] = array(
'#type' => 'textfield',
'#title' => t('Vocabulary URI'),
'#required' => TRUE,
'#default_value' => isset($form_state['values']['ns_uri']) ? $form_state['values']['ns_uri'] : NULL,
'#description' => "Enter the URI of the vocabulary to import. Make sure it finishes by either / or #.",
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
}
function evoc_import_form_validate($form, &$form_state) {
// Load the XML Namespace regular expression patterns.
module_load_include('inc', 'rdfx');
$prefix = $form_state['values']['prefix'];
$ns_uri = $form_state['values']['ns_uri'];
// Ensure the that namespace is a valid URI.
if (!valid_url($ns_uri, $absolute = TRUE)) {
form_set_error('ns_uri', t('The Vocabulary URI must be a valid URI.'));
}
// Ensure the namespace URI ends in either a / or a #.
if (!preg_match('/(\/|\#)$/', $ns_uri)) {
form_set_error('ns_uri', t('The Vocabulary URI must end in either a / or a #.'));
}
// Ensure the prefix is well formed according to the specification.
if (!preg_match('/^' . PREFIX .'$/', $prefix)) {
form_set_error('prefix', t('The prefix must follow the !link.', array('!link' => '<a href="http://www.w3.org/TR/xml-names11/#NT-NCName">XML Namespace Specification</a>')));
}
}
function evoc_import_form_submit($form, &$form_state) {
// @todo is that still the best way to keep the value when the form is reloaded?
$form_state['storage']['values'] = $form_state['values'];
$form_state['rebuild'] = true;
evoc_import_vocabulary($form_state['values']['ns_uri'], $form_state['values']['prefix']);
drupal_set_message(t('The @voc vocabulary has been imported.', array('@voc' => $form_state['values']['prefix'])));
}
/**
* Provide a callback for batch importing the vocabularies used in core.
*/
function evoc_import_core() {
$vocabularies = rdf_rdf_namespaces();
$operations = array();
foreach ($vocabularies as $prefix => $namespace_uri) {
$operations[] = array(
'_evoc_install_batch_process',
array(
$namespace_uri,
$prefix,
),
);
}
$batch = array(
'title' => t('Downloading RDF vocabularies'),
'init_message' => t('Preparing to download the core RDF vocabularies'),
'operations' => $operations,
'finished' => '_evoc_install_batch_finished',
'file' => drupal_get_path('module', 'evoc') . '/evoc.pages.inc',
);
batch_set($batch);
batch_process('evoc/import');
}
/*
* Evoc Install batch process.
*/
function _evoc_install_batch_process($namespace_uri, $prefix, &$context) {
if (!isset($context['sandbox']['progress'])) {
$context['sandbox']['progress'] = 0;
$context['message'] = t('Downloading %prefix', array('%prefix' => $prefix));
$context['finished'] = 0;
return;
}
evoc_import_vocabulary($namespace_uri, $prefix);
// Store result for post-processing in the finished callback.
$context['results'][] = $prefix;
// Update our progress information.
$context['sandbox']['progress']++;
$context['finished'] = 1;
}
/**
* Evoc Install batch 'finished' callback.
*/
function _evoc_install_batch_finished($success, $results, $operations) {
if ($success) {
drupal_set_message(t('The RDF vocabularies ' . implode(', ', $results) . ' have been imported.'));
return;
}
else {
drupal_set_message(t('An error occurred and processing did not complete.'), 'error');
$message = format_plural(count($results), '1 item successfully processed:', '@count items successfully processed:');
$message .= theme('item_list', array('items' => $results));
drupal_set_message($message);
return;
}
}
<?php
/**
* @file
* Tests Evoc functionality.
*/
class VocabularyImportTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Vocab import',
'description' => 'Test vocabulary import.',
'group' => 'Evoc',
);
}
function setUp() {
parent::setUp('rdf', 'rdfx', 'evoc', 'evoc_test');
$this->prefix = array();
$this->vocab_uri = array();
}
/**
* Functional test for vocabulary import.
*
* NOTE: This test requires having evoc_test manually enabled. Even when it is
* enabled in setUp, the parser fails to intialize. It may be that the headers
* aren't sent properly when accessed within site.
*/
function testImport() {
$format = 'rdf_xml';
$this->importVocabulary($format);
$namespaces = array(
$this->prefix[$format] => $this->vocab_uri[$format],
'xml' => 'http://www.w3.org/XML/1998/namespace',
'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
'owl' => 'http://www.w3.org/2002/07/owl#',
'vs' => 'http://www.w3.org/2003/06/sw-vocab-status/ns#',
'foaf' => 'http://xmlns.com/foaf/0.1/',
'dc' => 'http://purl.org/dc/elements/1.1/',
);
// Test that namespaces have been imported and placed in correct
// vocabulary graph.
foreach ($namespaces as $prefix => $namespace) {
$records = db_query("SELECT uri, prefix, gid FROM {rdfx_namespaces} WHERE uri='$namespace' AND prefix='$prefix'")->fetchAll();
if (count($records) == 1) {
$record = $records[0];
$this->assertEqual($record->gid, 1, t("Vocabulary $record->prefix is imported as part of correct vocabulary graph."));
}
else {
$this->assert(FALSE, t("Vocabulary $record->prefix is imported ."));
}
}
// Test that user defined prefix was used, per issue #925520.
$records = db_query("SELECT uri, prefix, gid FROM {rdfx_namespaces} WHERE prefix='doap'")->fetchAll();
$this->assert(count($records) == 0, t('The user defined prefix was used.'));
}
/*
* Test that vocabulary is updated.
*/
function testUpdate() {
}
protected function importVocabulary($format) {
$absolute_url = $this->getAbsoluteUrl("evoc_test/vocabulary_$format");
$this->vocab_uri[$format] = "$absolute_url#";
$this->prefix[$format] = "test_$format";
$this->edit = array(
'prefix' => $this->prefix[$format],
'ns_uri' => $this->vocab_uri[$format] ,
);
$user = $this->drupalCreateUser(array('administer content types'));
$this->drupalLogin($user);
$this->drupalPost('evoc/import', $this->edit, t('Submit'));
}
}
name = Evoc Test
description = Provides vocabularies for import testing.
core = 7.x
package = RDF
files[] = evoc_test.module
hidden = TRUE
<?php
/**
* @file
* Test vocabulary import.
*/
/**
* Implements hook_menu().
*/
function evoc_test_menu() {
$items['evoc_test/vocabulary_rdf_xml'] = array(
'title' => 'RDF/XML vocabulary',
'description' => 'Fake RDF/XML vocabulary for import testing.',
'page callback' => '_vocabulary_rdf_xml',
'access callback' => TRUE,
);
$items['evoc_test/vocabulary_n3'] = array(
'title' => 'N3 vocabulary',
'description' => 'Fake N3 vocabulary for import testing.',
'page callback' => '_vocabulary_n3',
'access callback' => TRUE,
);
return $items;
}
function _vocabulary_n3() {
global $base_url;
$vocab_uri = $base_url . '/evoc_test/vocabulary_n3#';
// We fake an n3 vocabulary to feed into the importer.
print '@prefix : <' . $vocab_uri . '> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix vs: <http://www.w3.org/2003/06/sw-vocab-status/ns#> .
: a owl:Ontology;
dc:description "El vocabulario Descripti\u00F3n of a Project (DOAP, Descripci\u00F3n de un Proyecto), descrito usando RDF Schema de W3C y Web Ontology Language."@es,
"The Description of a Project (DOAP) vocabulary, described using W3C RDF Schema and the Web Ontology Language.";
dc:title "Description of a Project (DOAP) vocabulary" .
:Project a rdfs:Class;
rdfs:isDefinedBy :;
rdfs:label "Project"@en,
"Proyecto"@es;
rdfs:subClassOf foaf:Project,
<http://xmlns.com/wordnet/1.6/Project> .
:homepage a rdf:Property,
owl:InverseFunctionalProperty;
rdfs:comment "El URL de la p\u00E1gina de un proyecto, asociada con exactamente un proyecto."@es,
"URL of a project\'s homepage, associated with exactly one project."@en;
rdfs:domain <http://usefulinc.com/ns/doap#Project>;
rdfs:isDefinedBy :;
rdfs:label "homepage"@en,
"p\u00E1gina web"@es;
rdfs:subPropertyOf foaf:homepage .';
return;
}
/**
* Menu callback ( see evoc_test_menu() ).
*/
function _vocabulary_rdf_xml() {
global $base_url;
$vocab_uri = $base_url . '/evoc_test/vocabulary_rdf_xml#';
// We fake an RDF/XML vocabulary to feed into the importer.
drupal_add_http_header('Content-Type', 'application/rdf+xml; charset=utf-8');
print '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:vs="http://www.w3.org/2003/06/sw-vocab-status/ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:doap="' . $vocab_uri . '"
>
<owl:Ontology rdf:about="' . $vocab_uri . '">
<dc:title>Description of a Project (DOAP) vocabulary</dc:title>
<dc:description>The Description of a Project (DOAP) vocabulary, described using W3C RDF Schema and the Web Ontology Language.</dc:description>
<dc:description xml:lang="es">El vocabulario Descripti&#243;n of a Project (DOAP, Descripci&#243;n de un Proyecto), descrito usando RDF Schema de W3C y Web Ontology Language.</dc:description>
</owl:Ontology>
<rdfs:Class rdf:about="' . $vocab_uri . 'Project">
<rdfs:isDefinedBy rdf:resource="' . $vocab_uri . '" />
<rdfs:label xml:lang="en">Project</rdfs:label>
<rdfs:label xml:lang="es">Proyecto</rdfs:label>
<rdfs:subClassOf rdf:resource="http://xmlns.com/wordnet/1.6/Project" />
<rdfs:subClassOf rdf:resource="http://xmlns.com/foaf/0.1/Project" />
</rdfs:Class>
<rdf:Property rdf:about="' . $vocab_uri . 'homepage">
<rdfs:isDefinedBy rdf:resource="' . $vocab_uri . '" />
<rdfs:label xml:lang="en">homepage</rdfs:label>
<rdfs:label xml:lang="es">p&#225;gina web</rdfs:label>
<rdfs:comment xml:lang="en">URL of a project\'s homepage, associated with exactly one project.</rdfs:comment>
<rdfs:comment xml:lang="es">El URL de la p&#225;gina de un proyecto, asociada con exactamente un proyecto.</rdfs:comment>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#InverseFunctionalProperty" />
<rdfs:domain rdf:resource="http://usefulinc.com/ns/doap#Project" />
<rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/homepage" />
</rdf:Property>
</rdf:RDF>';
return;
}
/*
* 3 field widget display
*/
.term {
padding: 2px;
margin-right: 10px;
background-color: #eeeeee;
}
.term-add {
margin-right: 5px;
margin-left: 5px;
}
.term-holder {
margin-top: 10px;
margin-bottom: 10px;
}
.term-remove {
cursor: pointer;
color: red;
font-weight: bold;
}
/*
* Terms autocomplete on administrative screens.
*/
.rdf-term-autocomplete {
margin: 0;
padding: 0;
white-space: normal;
}
.rdf-comment-autocomplete {
border-bottom: 1px solid #ccc;
color: #666;
font-size: .9em;
font-style: italic;
margin: 0;
padding-bottom: 10px;
}
\ No newline at end of file
name = RDF UI
description = User interface for altering the RDF mapping of Drupal data structure.
package = RDF
version = VERSION
core = 7.x
dependencies[] = rdfx
files[] = rdfui.module
(function ($) {
Drupal.behaviors.rdfuiFieldsetSummaries = {
attach: function (context) {
function setSummary() {
$(this).drupalSetSummary(function (context) {
var formValues = $(':input', context).not('[type=hidden]').map(
function () {
return $(this).closest('.form-item').css('display') === 'none' ? null : $(this).val()
}
);
// Only show values in the vertical tab if the first
// form element (types, predicates) is not empty.
return !formValues[0] ? null : Drupal.checkPlain(formValues.toArray().join(' '))
})
}
$('fieldset.rdf-field', context).each(setSummary);
$(document).bind('state:visible', function () {
Drupal.behaviors.rdfuiFieldsetSummaries.attach($(this).closest('fieldset.rdf-field')[0])
})
}
};
})(jQuery);
This diff is collapsed.
<?php
/**
* Callback function for viewing all bundles' RDF mappings.
*/
function rdfx_mapping_overview() {
return '';
}
/**
* Menu callback for viewing all declared namespaces and their prefixes.
*/
function rdfx_admin_namespaces() {
$output = '';
// Builds a table of existing namespaces known to the system.
$table_namespaces = array();
$table_namespaces['header'] = array('Prefix', 'Namespace');
foreach (rdf_get_namespaces() as $prefix => $namespace) {
$table_namespaces['rows'][] = array($prefix, $namespace);
}
$output .= theme('table', $table_namespaces);
// Form to add namespaces.
$form = drupal_get_form('rdfx_admin_namespaces_form');
$output .= drupal_render($form);
return $output;
}
function rdfx_admin_namespaces_form($form, &$form_state) {
$form['prefix'] = array(
'#type' => 'textfield',
'#title' => t('Prefix'),
'#required' => TRUE,
'#description' => t('Choose a prefix for this namespace, e.g. dc, foaf, sioc. This prefix will be used as an abbreviation for the namespace URI.'),
);
$form['ns_uri'] = array(
'#type' => 'textfield',
'#title' => t('Namespace URI'),
'#required' => TRUE,
'#default_value' => isset($form_state['values']['ns_uri']) ? $form_state['values']['ns_uri'] : NULL,
'#description' => t("Enter the URI of the namespace. Make sure it ends with either / or #."),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function rdfx_admin_namespaces_form_validate($form, &$form_state) {
// Loads the XML Namespace regular expression patterns.
module_load_include('inc', 'rdfx');
$prefix = $form_state['values']['prefix'];
$ns_uri = $form_state['values']['ns_uri'];
// Ensures that the namespace is a valid URI.
if (!valid_url($ns_uri, $absolute = TRUE)) {
form_set_error('ns_uri', t('The namespace URI must be a valid URI.'));
}
// Ensures the namespace URI ends in either / or #.
if (!preg_match('/(\/|\#)$/', $ns_uri)) {
form_set_error('ns_uri', t('The namespace URI must end in either a / or a #.'));
}
// Ensures the prefix is well formed according to the specification.
if (!preg_match('/^' . PREFIX .'$/', $prefix)) {
form_set_error('prefix', t('The prefix must follow the !link.', array('!link' => '<a href="http://www.w3.org/TR/xml-names11/#NT-NCName">XML Namespace Specification</a>')));
}
}
function rdfx_admin_namespaces_form_submit($form, &$form_state) {
$prefix = $form_state['values']['prefix'];
$ns_uri = $form_state['values']['ns_uri'];
// Prepares a fake empty vocabulary for _rdfx_save_vocabulary() to save the
// namespace and prefix.
// @todo use API when http://drupal.org/node/1117646 is fixed.
$vocabulary = array(
'title' => array(),
'description' => array(),
'namespaces' => array(),
);
_rdfx_save_vocabulary($ns_uri, $prefix, $vocabulary);
drupal_set_message(t('The namespace @namespace has been saved with the prefix @prefix.', array('@namespace' => $ns_uri, '@prefix' => $prefix)));
}
<?php
// $Id: votingapi.api.php,v 1.1.2.1.2.1 2009/07/01 07:26:12 eaton Exp $
/**
* @file
* Provides hook documentation for the RDFx module.
*/
function hook_rdfx_term_types_alter()
<?php
/**
* @file
* Functions for importing and parsing RDF data.
*/
/**
* Loads an RDF file from an HTTP URI or local file, parses it, and builds an
* RDF schema representation (associative array) from it.
*
* @param $uri
* The namespace URI for this graph.
* @param $prefix
* The prefix for this graph.
* @param $filename (optional)
* A local RDF file to parse.
* @return array
* @throws Exception On network or parse error
*/
function rdfx_fetch_rdf($uri, $prefix, $filename = NULL) {
if ($filename != NULL) {
if (!is_file($filename)) {
throw new Exception("File not found: '$filename'");
return;
}
$content = file_get_contents($filename);
return _rdfx_parse_rdf($uri, $content);
}
$schema_url = $uri;
$i = strpos($schema_url, '#');
if ($i !== false) {
$schema_url = substr($schema_url, 0, $i);
}
return _rdfx_parse_rdf($uri);
}
function _rdfx_parse_rdf($base_uri) {
$namespaces = array();
include_once(drupal_get_path('module', 'rdfx') . '/vendor/arc/ARC2.php');
$parser = ARC2::getRDFParser();
$parser->parse($base_uri);
// If this is an N3 file, the namespaces array isn't populated. Iterate
// through the attached parser object's prefixes and remove the colon from
// the end of the prefix.
// @todo File an issue with ARC2.
switch ($parser->format) {
case 'turtle':
foreach ($parser->parser->prefixes as $prefix => $uri) {
$formatted_prefix = str_replace(':', '', $prefix);
$namespaces[$formatted_prefix] = $uri;
}
break;
default:
foreach ($parser->parser->nsp as $uri => $prefix) {
$namespaces[$prefix] = $uri;
}
break;
}
return array($parser->getTriples(), $namespaces);
}
<?php
/*
* This file contains regular expressions for the following XML tokens:
* BaseChar, Ideographic, Letter, Digit, Extender, CombiningChar, NameChar,
* EntityRef, CharRef, Reference, Name, NmToken, and AttValue.
*
* The definitions of these tokens were taken from the XML spec
* (Extensible Markup Language 1.0) at L<http://www.w3.org/TR/REC-xml>.
* Also contains the regular expressions for the following tokens from the
* XML Namespaces spec at L<http://www.w3.org/TR/REC-xml-names>:
* NCNameChar, NCName, QName, Prefix and LocalPart.
*
* Modified from the XML:RegExp package, authored by Enno Derksen and
* maintained by T.J. Mather.
* http://search.cpan.org/~tjmather/XML-RegExp-0.03/lib/XML/RegExp.pm
*/
define('BASE_CHAR', '(?:[a-zA-Z]|\xC3[\x80-\x96\x98-\xB6\xB8-\xBF]|\xC4[\x80-\xB1\xB4-\xBE]|\xC5[\x81-\x88\x8A-\xBE]|\xC6[\x80-\xBF]|\xC7[\x80-\x83\x8D-\xB0\xB4\xB5\xBA-\xBF]|\xC8[\x80-\x97]|\xC9[\x90-\xBF]|\xCA[\x80-\xA8\xBB-\xBF]|\xCB[\x80\x81]|\xCE[\x86\x88-\x8A\x8C\x8E-\xA1\xA3-\xBF]|\xCF[\x80-\x8E\x90-\x96\x9A\x9C\x9E\xA0\xA2-\xB3]|\xD0[\x81-\x8C\x8E-\xBF]|\xD1[\x80-\x8F\x91-\x9C\x9E-\xBF]|\xD2[\x80\x81\x90-\xBF]|\xD3[\x80-\x84\x87\x88\x8B\x8C\x90-\xAB\xAE-\xB5\xB8\xB9]|\xD4[\xB1-\xBF]|\xD5[\x80-\x96\x99\xA1-\xBF]|\xD6[\x80-\x86]|\xD7[\x90-\xAA\xB0-\xB2]|\xD8[\xA1-\xBA]|\xD9[\x81-\x8A\xB1-\xBF]|\xDA[\x80-\xB7\xBA-\xBE]|\xDB[\x80-\x8E\x90-\x93\x95\xA5\xA6]|\xE0(?:\xA4[\x85-\xB9\xBD]|\xA5[\x98-\xA1]|\xA6[\x85-\x8C\x8F\x90\x93-\xA8\xAA-\xB0\xB2\xB6-\xB9]|\xA7[\x9C\x9D\x9F-\xA1\xB0\xB1]|\xA8[\x85-\x8A\x8F\x90\x93-\xA8\xAA-\xB0\xB2\xB3\xB5\xB6\xB8\xB9]|\xA9[\x99-\x9C\x9E\xB2-\xB4]|\xAA[\x85-\x8B\x8D\x8F-\x91\x93-\xA8\xAA-\xB0\xB2\xB3\xB5-\xB9\xBD]|\xAB\xA0|\xAC[\x85-\x8C\x8F\x90\x93-\xA8\xAA-\xB0\xB2\xB3\xB6-\xB9\xBD]|\xAD[\x9C\x9D\x9F-\xA1]|\xAE[\x85-\x8A\x8E-\x90\x92-\x95\x99\x9A\x9C\x9E\x9F\xA3\xA4\xA8-\xAA\xAE-\xB5\xB7-\xB9]|\xB0[\x85-\x8C\x8E-\x90\x92-\xA8\xAA-\xB3\xB5-\xB9]|\xB1[\xA0\xA1]|\xB2[\x85-\x8C\x8E-\x90\x92-\xA8\xAA-\xB3\xB5-\xB9]|\xB3[\x9E\xA0\xA1]|\xB4[\x85-\x8C\x8E-\x90\x92-\xA8\xAA-\xB9]|\xB5[\xA0\xA1]|\xB8[\x81-\xAE\xB0\xB2\xB3]|\xB9[\x80-\x85]|\xBA[\x81\x82\x84\x87\x88\x8A\x8D\x94-\x97\x99-\x9F\xA1-\xA3\xA5\xA7\xAA\xAB\xAD\xAE\xB0\xB2\xB3\xBD]|\xBB[\x80-\x84]|\xBD[\x80-\x87\x89-\xA9])|\xE1(?:\x82[\xA0-\xBF]|\x83[\x80-\x85\x90-\xB6]|\x84[\x80\x82\x83\x85-\x87\x89\x8B\x8C\x8E-\x92\xBC\xBE]|\x85[\x80\x8C\x8E\x90\x94\x95\x99\x9F-\xA1\xA3\xA5\xA7\xA9\xAD\xAE\xB2\xB3\xB5]|\x86[\x9E\xA8\xAB\xAE\xAF\xB7\xB8\xBA\xBC-\xBF]|\x87[\x80-\x82\xAB\xB0\xB9]|[\xB8\xB9][\x80-\xBF]|\xBA[\x80-\x9B\xA0-\xBF]|\xBB[\x80-\xB9]|\xBC[\x80-\x95\x98-\x9D\xA0-\xBF]|\xBD[\x80-\x85\x88-\x8D\x90-\x97\x99\x9B\x9D\x9F-\xBD]|\xBE[\x80-\xB4\xB6-\xBC\xBE]|\xBF[\x82-\x84\x86-\x8C\x90-\x93\x96-\x9B\xA0-\xAC\xB2-\xB4\xB6-\xBC])|\xE2(?:\x84[\xA6\xAA\xAB\xAE]|\x86[\x80-\x82])|\xE3(?:\x81[\x81-\xBF]|\x82[\x80-\x94\xA1-\xBF]|\x83[\x80-\xBA]|\x84[\x85-\xAC])|\xEA(?:[\xB0-\xBF][\x80-\xBF])|\xEB(?:[\x80-\xBF][\x80-\xBF])|\xEC(?:[\x80-\xBF][\x80-\xBF])|\xED(?:[\x80-\x9D][\x80-\xBF]|\x9E[\x80-\xA3])))');
define('IDEOGRAPHIC', '(?:\xE3\x80[\x87\xA1-\xA9]|\xE4(?:[\xB8-\xBF][\x80-\xBF])|\xE5(?:[\x80-\xBF][\x80-\xBF])|\xE6(?:[\x80-\xBF][\x80-\xBF])|\xE7(?:[\x80-\xBF][\x80-\xBF])|\xE8(?:[\x80-\xBF][\x80-\xBF])|\xE9(?:[\x80-\xBD][\x80-\xBF]|\xBE[\x80-\xA5])');
define('DIGIT', '(?:[0-9]|\xD9[\xA0-\xA9]|\xDB[\xB0-\xB9]|\xE0(?:\xA5[\xA6-\xAF]|\xA7[\xA6-\xAF]|\xA9[\xA6-\xAF]|\xAB[\xA6-\xAF]|\xAD[\xA6-\xAF]|\xAF[\xA7-\xAF]|\xB1[\xA6-\xAF]|\xB3[\xA6-\xAF]|\xB5[\xA6-\xAF]|\xB9[\x90-\x99]|\xBB[\x90-\x99]|\xBC[\xA0-\xA9]))');
define('EXTENDER', '(?:\xC2\xB7|\xCB[\x90\x91]|\xCE\x87|\xD9\x80|\xE0(?:\xB9\x86|\xBB\x86)|\xE3(?:\x80[\x85\xB1-\xB5]|\x82[\x9D\x9E]|\x83[\xBC-\xBE]))');
define('COMBINING_CHAR', '(?:\xCC[\x80-\xBF]|\xCD[\x80-\x85\xA0\xA1]|\xD2[\x83-\x86]|\xD6[\x91-\xA1\xA3-\xB9\xBB-\xBD\xBF]|\xD7[\x81\x82\x84]|\xD9[\x8B-\x92\xB0]|\xDB[\x96-\xA4\xA7\xA8\xAA-\xAD]|\xE0(?:\xA4[\x81-\x83\xBC\xBE\xBF]|\xA5[\x80-\x8D\x91-\x94\xA2\xA3]|\xA6[\x81-\x83\xBC\xBE\xBF]|\xA7[\x80-\x84\x87\x88\x8B-\x8D\x97\xA2\xA3]|\xA8[\x82\xBC\xBE\xBF]|\xA9[\x80-\x82\x87\x88\x8B-\x8D\xB0\xB1]|\xAA[\x81-\x83\xBC\xBE\xBF]|\xAB[\x80-\x85\x87-\x89\x8B-\x8D]|\xAC[\x81-\x83\xBC\xBE\xBF]|\xAD[\x80-\x83\x87\x88\x8B-\x8D\x96\x97]|\xAE[\x82\x83\xBE\xBF]|\xAF[\x80-\x82\x86-\x88\x8A-\x8D\x97]|\xB0[\x81-\x83\xBE\xBF]|\xB1[\x80-\x84\x86-\x88\x8A-\x8D\x95\x96]|\xB2[\x82\x83\xBE\xBF]|\xB3[\x80-\x84\x86-\x88\x8A-\x8D\x95\x96]|\xB4[\x82\x83\xBE\xBF]|\xB5[\x80-\x83\x86-\x88\x8A-\x8D\x97]|\xB8[\xB1\xB4-\xBA]|\xB9[\x87-\x8E]|\xBA[\xB1\xB4-\xB9\xBB\xBC]|\xBB[\x88-\x8D]|\xBC[\x98\x99\xB5\xB7\xB9\xBE\xBF]|\xBD[\xB1-\xBF]|\xBE[\x80-\x84\x86-\x8B\x90-\x95\x97\x99-\xAD\xB1-\xB7\xB9])|\xE2\x83[\x90-\x9C\xA1]|\xE3(?:\x80[\xAA-\xAF]|\x82[\x99\x9A]))');
define('LETTER', '(?:' . BASE_CHAR . '|' . IDEOGRAPHIC . ')');
define('NAME_CHAR', '(?:[-._:]|' . LETTER . '|' . DIGIT . '|' . COMBINING_CHAR . '|' . EXTENDER . ')');
define('NAME', '(?:(?:[:_]|' . LETTER . ')' . NAME_CHAR . '*)');
define('NM_TOKEN', '(?:' . NAME_CHAR . '+)');
define('ENTITY_REF', '(?:\&' . NAME . ';)');
define('CHAR_REF', '(?:\&#(?:[0-9]+|x[0-9a-fA-F]+)');
define('REFERENCE', '(?:' . ENTITY_REF . '|' . CHAR_REF . ')');
// Comment from original code: What if it contains entity references?
define('ATT_VALUE', "(?:\"(?:[^\"&<]*|" . REFERENCE . ")\"|'(?:[^\'&<]|" . REFERENCE .")*')");
// Prefix definitions from the XML Namespace specification.
define('NC_NAME_CHAR', '(?:[-._]|' . LETTER . '|' . DIGIT . '|' . COMBINING_CHAR . '|' . EXTENDER . ')');
define('NC_NAME', '(?:(?:_|' . LETTER . ')' . NC_NAME_CHAR .'*)');
define('PREFIX', NC_NAME);
define('LOCAL_PART', NC_NAME);
define('QNAME', '/(?:(?:' . PREFIX .':)?' . LOCAL_PART . ')/');
/*
* End XML:RegExp package.
*/
name = RDFx
description = Extends the RDF mapping API of Drupal core to provide more RDF seralization formats and other RDF capabilities.
package = RDF
version = VERSION
core = 7.x
dependencies[] = rdf
files[] = rdfx.install
files[] = rdfx.module
files[] = rdfx.pages.inc
files[] = rdfx.inc
files[] = rdfx.terms.inc
files[] = rdfx.import.inc
files[] = rdfx.query.inc
files[] = rdfx.test
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment