Arteleku Updated 2017

This commit is contained in:
root 2017-12-15 01:12:11 +01:00
commit dbeadb0d6f
8 changed files with 1295 additions and 0 deletions

0
djatoka.log Executable file
View File

90
includes/Autoridades.inc Executable file
View File

@ -0,0 +1,90 @@
<?php
/**
* @file
*
*
*/
module_load_include('inc', 'xml_form_api', 'Utils');
module_load_include('inc', 'xml_form_api', 'XMLForm');
module_load_include('inc', 'objective_forms', 'Utils');
module_load_include('inc', 'objective_forms', 'FormPopulator');
/**
* A collection of generic static functions that help in constructing elements.
*/
// COPIA DE ELEMENTS
class Autoridades {
/**
* Loads any javascript files which are needed for elements which use AHAH.
*/
public static function addRequiredResources() {
static $load = TRUE;
if ($load) {
drupal_add_js('misc/jquery.form.js'); // Required
$load = FALSE;
}
}
/**
* Includes the given jQuery UI widgets.
*
* @param array $files
* An list of files to be included from the jquery theme. Or a single file name.
*/
public static function addUIWidgets($files = array()) {
// TODO $files needs to be a string or multiple calls to drupal_add_library need to be made.
drupal_add_library('system', $files);
}
/**
* Includes the given jQuery UI theme files.
*
* @param array $files
* An list of files to be included from the jquery theme. Or a single file name.
*/
public static function addUIThemeStyles($files = array()) {
self::addFiles('drupal_add_css', PATH_XML_FORM_ELEMENTS_JQUERY_THEME, $files, array(
'group' => CSS_THEME,
));
}
/**
* Includes the given javascript files from this module.
*
* @param type $files
*/
public static function addJS($files = array()) {
self::addFiles('drupal_add_js', PATH_XML_FORM_ELEMENTS_JS, $files);
}
/**
* Includes the given css files from this module.
*
* @param type $files
*/
public static function addCSS($files = array()) {
self::addFiles('drupal_add_css', PATH_XML_FORM_ELEMENTS_CSS, $files, array(
'group' => CSS_THEME,
));
}
/**
* Adds files using the given $method, $path and $files.
*
* @param string $function
* The function to call to add the given files.
* @param string $path
* The path where the files are located.
* @param array $files
* The file(s) to be added.
*/
private static function addFiles($function, $path, $files = array(), $additional_argument = NULL) {
// Convert string to array.
$files = (array)$files;
foreach ($files as $file) {
$function($path . $file, $additional_argument);
}
}
}

170
includes/theme.inc Normal file
View File

@ -0,0 +1,170 @@
<?php
function theme_mods_object($variables){
global $language_content;
if (empty($variables['mods'])){return;}
if (empty($variables['mods']->mods)){return;}
$mods = $variables['mods']->mods; // -> Objeto MODS con el array en mods.
$lang = $language_content->language;
$ret = array();
foreach($mods as $element => $content):
if (empty($mods[$element])){continue;}
$l_item = _islandora_get_localized($content);
//$ret['_' . $element] = $l_item;
$ret[$element] = theme("modselement__{$element}", array('element' => $l_item)); //array_reduce($l_item, '_islandora_arteleku_reduce_mods_array');
endforeach;
return $ret;
}
function theme_modselement($variables){
$r = "";
$item = $variables['element'];
if (!is_array($item)){
$r = $item;
}else if(isset($item['value'])){
$r = $item['value'];
}else{
$r = array_reduce($item, '_islandora_arteleku_reduce_mods_array');
}
if(!empty($result)){
return $result . ' - ' . $r;
}
return $r;
}
function theme_modselement__tableOfContents($variables){
$r = "";
$item = $variables['element'];
if (!is_array($item)){
$r = $item;
}else if(isset($item['value'])){
$r = $item['value'];
}else{
$r = array_reduce($item, '_islandora_arteleku_reduce_mods_array');
}
$t="";
if(!empty($r)){
$r_split = explode(" ; ", $r);
if(count($r_split)){
$t = '<ul><li>' . join("</li><li>",$r_split) . '</ul>';
}
}
if(!empty($result)){
return $result . ' - ' . $t;
}
return $t;
}
function theme_modselement__name($variables){
if(empty($variables)){return;}
$items = $variables['element'];
//dpm($items);
$ret = array();
foreach($items as $item){
isset($item['@valueURI']) ? $uri = $item['@valueURI'] : $uri = "";
isset($item['namePart']['value']) ? $name = $item['namePart']['value'] : $name = "";
$ret[] = l($name, "islandora/search/mods_name_personal_namePart_ms%3A%28\"".$name."\"%29");
//$ret[] = l($name, $uri);
}
return '<ul><li>' . join("</li><li>", $ret) . "</li></ul>";
}
function theme_modselement__titleInfo($variables){
if(empty($variables)){return;}
$items = $variables['element'];
$ret = array();
foreach($items as $item){
if($item!=""):
if(isset($item['@type'])){continue;}
isset($item['title']['value']) ? $title = $item['title']['value'] : $title = "";
isset($item['subTitle']['value']) ? $title .= ' - ' . $item['subTitle']['value'] : $title .= "";
$ret[] = $title;
endif;
}
$t = join(' - ', $ret);
($t == "") ? $t = t('(none)') : $t=$t;
return $t;
}
function theme_modselement__part($variables){
if(empty($variables)){return;}
$items = $variables['element'];
$inTitle = $variables['title'];
$ret = array();
foreach($items as $item){
$t = "";
if(isset($item['detail']) && $inTitle){
if(!isset($item['detail']['@type'])){continue;}
if($item['detail']['@type'] != 'issue'){continue;}
$ar = _islandora_get_localized($item['detail']);
isset($item['detail']['@type']) ? $tipo = t($item['detail']['@type']) . ' ' : $tipo = '';
if (is_array($ar)):
$t = $tipo . array_reduce($ar, '_islandora_arteleku_reduce_mods_array');
else :
$t = $tipo . $ar;
endif;
}else if (!$inTitle){
$t = array_reduce($item, '_islandora_arteleku_reduce_mods_array');
}
$ret[] = $t;
}
$t = join(' - ', $ret);
($t == "" && !$inTitle) ? $t = t('(none)') : $t=$t;
return $t;
}
function _islandora_arteleku_reduce_mods_array($result, $item){
$r = "";
if (!is_array($item)){
$r = $item;
}else if(isset($item['value'])){
$r = $item['value'];
}else{
$r = array_reduce($item, '_islandora_arteleku_reduce_mods_array');
}
if(!empty($result)){
return $result . ' - ' . $r;
}
return $r;
}
function _islandora_get_localized($item)
{
global $language_content;
$lang = $language_content->language;
if (isset($item[$lang])){return $item[$lang];}
if (isset($item['und'])){return $item['und'];}
$allKeys = array_keys($item);
return $item[$allKeys[0]];
}

6
islandora_arteleku.info Executable file
View File

@ -0,0 +1,6 @@
name = "Islandora Arteleku"
description = "Tools for addapt Islandora 7.x Arteleku Artxibo"
dependencies[] = islandora
package = Islandora
core = 7.x
version = 7.x-1.2

470
islandora_arteleku.module Executable file
View File

@ -0,0 +1,470 @@
<?php
/**
* @file
* Hooks and constants for xml_form_elements.
*/
/**
* Constants
*/
// LLAMADAS A WIKIDATA
require("tools/wikidata.php");
require("tools/loc.php");
function islandora_arteleku_form() {
$form = array();
// Tipo vinculado al vocabulario 2 de entidades.
$form['autoridades_test'] = array(
'#title' => t('Autoridades'),
'#type' => 'textfield',
'#default_value' => 'nada',
'#size' => 60,
//'#autocomplete_path' => 'autoridades/autocomplete',
//'#options' => array('test'=>'33'),
);
$form['wikidata'] = array(
'#title' => t('Autoridades Wikidata'),
'#type' => 'textfield',
'#autocomplete_path' => 'autoridades/wikidata/autocomplete',
);
$form['relators'] = array(
'#title' => t('Relators Library of Congress'),
'#type' => 'textfield',
'#autocomplete_path' => 'autoridades/loc/relators',
);
/*$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Save',
);*/
return $form;
}
function islandora_arteleku_element_info() {
return array(
'autoridades_new' => array(
'#type' => 'textfield',
'#title' => t('ejemplos de tipos'),
'#default_value' => 'test',
),
);
}
//function islandora_arteleku_form_alter(&$form, &$form_state, $form_id) { dpm(print_r($form_id)); }
function islandora_arteleku_menu() {
$items=array();
$items['autoridades/autocomplete'] = array(
'page callback' => '_islandora_arteleku_autocomplete',
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
$items['autoridades/wikidata/autocomplete'] = array(
'page callback' => '_islandora_arteleku_wikidata_autocomplete',
'access arguments' => array('autoridades de wikidata'),
'type' => MENU_CALLBACK
);
$items['autoridades/loc/relators'] = array(
'page callback' => '_islandora_arteleku_loc_relators',
'access arguments' => array('loc relators'),
'type' => MENU_CALLBACK
);
$items['genero/autocomplete'] = array(
'page callback' => '_islandora_arteleku_marc_genre_autocomplete',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['topic/autocomplete'] = array(
'page callback' => '_islandora_arteleku_topic_autocomplete',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['relator/autocomplete'] = array(
'page callback' => '_islandora_arteleku_relator_autocomplete',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
function _islandora_arteleku_relator_autocomplete($s) {
$matches = array();
$vid = 3;
$result = db_select('taxonomy_term_data', 't')
-> fields('t', array('tid', 'name'))
-> condition('vid', $vid, '=')
-> condition('name', '%%'.$s.'%%', 'LIKE')
-> execute();
foreach ($result as $term) {
$t = taxonomy_term_load($term->tid);
$matches[$term->name] = $term->name;
//dpm(print_r($t,TRUE));
/*if (isset($t->field_topic_code["und"])):
$matches[$t->field_topic_code["und"][0]["value"]] = $term->name;
endif;*/
}
drupal_json_output($matches);
}
function _islandora_arteleku_topic_autocomplete($s) {
$matches = array();
$vid = 5; // topic list taxonomy
$result = db_select('taxonomy_term_data', 't')
-> fields('t', array('tid', 'name'))
-> condition('vid', $vid, '=')
-> condition('name', '%%'.$s.'%%', 'LIKE')
-> execute();
foreach ($result as $term) {
$t = taxonomy_term_load($term->tid);
//$matches[$term->name] = $term->name;
//dpm(print_r($t,TRUE));
if (isset($t->field_topic_code["und"])):
$matches[$t->field_topic_code["und"][0]["value"]] = $term->name;
endif;
}
drupal_json_output($matches);
}
function _islandora_arteleku_marc_genre_autocomplete($s) {
$matches = array();
$vid = 4; // marc genre list taxonomy
$result = db_select('taxonomy_term_data', 't')
-> fields('t', array('tid', 'name'))
-> condition('vid', $vid, '=')
-> condition('name', '%%'.$s.'%%', 'LIKE')
-> execute();
foreach ($result as $term) {
$t = taxonomy_term_load($term->tid);
//dpm(print_r($t,TRUE));
if (isset($t->field_genre_code["und"])) :
$matches[$t->field_genre_code["und"][0]["value"]] = $term->name;
endif;
}
drupal_json_output($matches);
}
function islandora_arteleku_genre_validate($field) {
$vid = 4;
$id_marcgt = $field["#value"];
// query de busqueda del marcgt para ver si existe en la taxonomy
/*if (!existe_taxonomy($vid,$field["#value"])) {
form_set_error("autoridades",t("{$field["#value"]} no es un genero válido"));
}*/
}
function _islandora_arteleku_autocomplete($string) {
$matches = array();
// Buscamos en el propio vocabulario
//vocabulary id
$vid = 2;
$result = db_select('taxonomy_term_data', 't')
-> fields('t', array('tid', 'name'))
-> condition('vid', $vid, '=')
-> condition('name', '%%'.$string.'%%', 'LIKE')
//-> range(0, 10)
-> execute();
foreach ($result as $term) {
$matches[$term->name] = check_plain($term -> name);
}
// Buscamos en sus sinonimos
$result = db_select('field_data_synonyms_synonyms','s')
-> fields('s',array('entity_id','synonyms_synonyms_value'))
-> condition('synonyms_synonyms_value','%%'.$string.'%%','LIKE')
//-> range(0, 10)
-> execute();
foreach($result as $syn) {
$t = taxonomy_term_load($syn->entity_id);
//print_r($syn,TRUE);
//$matches[$syn->synonyms_synonyms_value] = check_plain($syn->synonyms_synonyms_value);
$matches[$t->name."[{$syn->synonyms_synonyms_value}]"] = check_plain($syn->synonyms_synonyms_value);
//$matches[$syn->synonyms_synonyms_value] = check_plain($t->name);
}
drupal_json_output($matches);
}
function islandora_arteleku_autoridades_validate($field) {
$vid = 2;
$authority = explode("[",$field["#value"]);
if (!existe_taxonomy($vid,$authority[0])) {
form_set_error("autoridades",t("$authority[0] no es una autoridad válida"));
}
}
function islandora_arteleku_autoridades_submit($node,$form,$form_state) {
watchdog("submit authority",print_r($form,TRUE));
}
function islandora_arteleku_topic_validate($field) {
$vid = 5;
if (!existe_taxonomy($vid,$field["#value"]["topic_text"])) {
form_set_error('topic validate',t("<strong>{$field["#value"]["topic_text"]}</strong> no es una temática válida. <br/>Crea la temática antes de editar el documento. <a target='_blank' href='@url'>Crear tematica</a>",array("@url" => url('admin/structure/taxonomy/tem_ticas/add'))));
}
}
function islandora_arteleku_relator_validate($field) {
$vid = 3;
if (!existe_taxonomy($vid,$field["#value"])) {
form_set_error('relator validate',t("<strong>{$field["#value"]}</strong> no es un rol válido. <br/>Crea el rol antes de editar el documento. <a target='_blank' href='@url'>Crear rol</a>",array("@url" => url('admin/structure/taxonomy/marcrelators/add'))));
}
}
function islandora_arteleku_term_validate($field,$vid) {
if (!existe_taxonomy($vid,$field["#value"])) {
form_set_error(NULL,t("{$field["#value"]} no es válido"));
}
}
function existe_taxonomy($vid,$value) {
if ($value=="") { return true; } /* En el caso que sea un valor en blanco y no haya que validarlo */
else if (isset($value)) {
$result = db_select('taxonomy_term_data', 't')
-> fields('t', array('tid', 'name'))
-> condition('vid', $vid, '=')
-> condition('name', $value, 'LIKE')
-> execute()
-> fetchAll();
if (count($result)>0) { return true; }
else { return false; }
}
}
function _islandora_arteleku_loc_relators($string) {
$relators = array();
$r = new lOC();
$it = $r->getRelators()->getIterator();
foreach ($it as $item):
if (isset($item["<http://www.loc.gov/mads/rdf/v1#authoritativeLabel>"][0]["value"])) : $relators[$item["<http://www.loc.gov/mads/rdf/v1#authoritativeLabel>"][0]["value"]] = check_plain($item["<http://www.loc.gov/mads/rdf/v1#authoritativeLabel>"][0]["value"]); endif;
endforeach;
drupal_json_output($relators);
}
function _islandora_arteleku_wikidata_autocomplete($string) {
$matches = array();
$wd = new wikiData();
$it = $wd->searchEntities($string)->getIterator();
foreach ($it as $item) :
$matches[$item['id']] = check_plain($item['label']);
endforeach;
drupal_json_output($matches);
}
/**
* Theme
*/
function islandora_arteleku_theme($existing, $type, $theme, $path) {
$t = array(
'autoridades' => array(
'render element' => 'element',
'file' => 'includes/Autoridades.inc',
),
'mods_object' => array(
'variables' => array('mods' => NULL),
'file' => 'includes/theme.inc',
),
'modselement' => array(
'variables' => array('element' => NULL),
'file' => 'includes/theme.inc',
),
'modselement__name' => array(
'variables' => array('element' => NULL),
'file' => 'includes/theme.inc',
),
'modselement__titleInfo' => array(
'variables' => array('element' => NULL),
'file' => 'includes/theme.inc',
),
'modselement__part' => array(
'variables' => array('element' => NULL, 'title' => FALSE),
'file' => 'includes/theme.inc',
),
'modselement__tableOfContents' => array(
'variables' => array('element' => NULL),
'file' => 'includes/theme.inc',
)
);
return $t;
}
/**
* This hook allows modules to register XSLT transformations.
*
* @return array
* An associative array mapping a shortened name to the full path of the
* transformation.
*/
function islandora_arteleku_xml_form_builder_get_transforms() {
return array(
'mods_to_dc_multilingual.xslt' => 'sites/all/modules/islandora_arteleku/transforms/mods_to_dc_multilingual.xslt',
);
}
function islandora_arteleku_form_submit($node,$form,$form_state) {
watchdog("islandora_arteleu","Form Submit..");
form_set_error("sjsjsj");
dpm(print_r($form,TRUE));
}
function islandora_arteleku_islandora_sp_pdf_islandora_object_alter($object, &$context) {
watchdog("islandora_arteleku","Islandora Object Alter..");
error_log("islandora object alter");
dpm("alter object");
}
function islandora_audio_preprocess_islandora_basic_collection_collection(array &$variables) {
$variables['parent_collections'] = islandora_get_parents_from_rels_ext($islandora_object);
}
function islandora_arteleku_islandora_object_modified($object) {
//function islandora_arteleku_islandora_sp_pdf_islandora_object_modified($object) {
//dpm(t("El objeto ha sido editado correctamente"));
error_log("MODIFIED");
watchdog("islandora_arteleku","Modificacion del objecto $object->id");
if (!$object) { dpm(t('No hay objecto a actualizar')); }
$pid = $object->id;
$mods = $object['MODS'];
$mods_doc = new DomDocument();
global $base_url;
if (!empty($mods->content) && $mods_doc->loadXML($mods->content)) :
//dpm(t("Cargamos el XML"));
$n_list = $mods_doc->getElementsByTagNameNS('http://www.loc.gov/mods/v3','name');
foreach ($n_list as $n) {
//dpm(t("Existe name"));
$name = "sin_nombre";
$np_list = $n->getElementsByTagNameNS('http://www.loc.gov/mods/v3','namePart');
//foreach ($np_list as $np) { $name = $np->nodeValue; }
//Limpiamos el valor del synonimo si es el caso y actualizamos el nodeValue
foreach ($np_list as $np) { $name = explode("[",$np->nodeValue); }
$name = $name[0];
$np->nodeValue = $name;
$result = db_select('taxonomy_term_data', 't')
-> fields('t', array('tid', 'name'))
-> condition('vid', 2, '=')
-> condition('name', $name, 'LIKE')
-> execute();
foreach ($result as $r) { $valueURI = $r->tid; }
//dpm(t("El value uri es {$valueURI}"));
$n->setAttribute('valueURI',"http://artxibo.arteleku.net/taxonomy/term/{$valueURI}");
// El ValueURI de RoleTerm para identificarlo en las taxonomias de islandora
$r_list = $n->getElementsByTagNameNS('http://www.loc.gov/mods/v3','role');
foreach ($r_list as $rl) {
$rt = $rl->getElementsByTagNameNS('http://www.loc.gov/mods/v3','roleTerm');
foreach ($rt as $r):
$role_name=$r->nodeValue;
$result = db_select('taxonomy_term_data','t')
-> fields('t',array('tid','name'))
-> condition('vid',3,'=')
-> condition('name',$role_name,'LIKE')
-> execute();
foreach ($result as $r) { $valueURI = $r->tid; }
$r->setAttribute('valueURI',"http:/artxibo.arteleku.net/taxonomy/term/{$valueURI}");
endforeach;
}
}
$string = $mods_doc->saveXML();
$mods->setContentFromString($string);
$object->ingestDatastream($mods);
else :
//dpm(t("No he encontrado un xml valido"));
endif;
}
function islandora_arteleku_islandora_object_ingested($object) {
//function islandora_arteleku_islandora_sp_pdf_islandora_object_ingested($object) {
watchdog("islandora_arteleku","Ingesta del objecto $object->id");
if (!$object) { dpm(t('No hay objecto a actualizar')); }
$pid = $object->id;
$mods = $object['MODS'];
$mods_doc = new DomDocument();
global $base_url;
if (!empty($mods->content) && $mods_doc->loadXML($mods->content)) :
$loc = $mods_doc->createElement("location");
$url = $mods_doc->createElement("url",$base_url.'/islandora/object/'.$pid);
$loc->appendChild($url);
$m_list = $mods_doc->getElementsByTagNameNS('http://www.loc.gov/mods/v3', 'mods');
foreach ($m_list as $n) :
$n->appendChild($loc);
endforeach;
// Creamos los URIs a los namePart
$n_list = $mods_doc->getElementsByTagNameNS('http://www.loc.gov/mods/v3','name');
foreach ($n_list as $n) {
$name = "sin_nombre";
$np_list = $n->getElementsByTagNameNS('http://www.loc.gov/mods/v3','namePart');
//Limpiamos el valor del synonimo si es el caso y actualizamos el nodeValue
foreach ($np_list as $np) { $name = explode("[",$np->nodeValue); }
$name = $name[0];
$np->nodeValue = $name;
$result = db_select('taxonomy_term_data', 't')
-> fields('t', array('tid', 'name'))
-> condition('vid', 2, '=')
-> condition('name', $name, 'LIKE')
-> execute();
foreach ($result as $r) { $valueURI = $r->tid; }
$n->setAttribute('valueURI',"http://artxibo.arteleku.net/taxonomy/term/{$valueURI}");
// El ValueURI de RoleTerm para identificarlo en las taxonomias de islandora
$r_list = $n->getElementsByTagNameNS('http://www.loc.gov/mods/v3','roleTerm');
foreach ($r_list as $r) {
//dpm($r);
$role_name = $r->nodeValue;
$result = db_select('taxonomy_term_data','t')
-> fields('t',array('tid','name'))
-> condition('vid',3,'=')
-> condition('name',$role_name,'LIKE')
-> execute();
foreach ($result as $v) { $valueURI = $v->tid; }
$r->setAttribute('valueURI',"http:/artxibo.arteleku.net/taxonomy/term/{$valueURI}");
}
}
$string = $mods_doc->saveXML();
$mods->setContentFromString($string);
$object->ingestDatastream($mods);
else :
dpm(t("No existe un XML válido"));
endif;
}
?>

48
tools/loc.php Executable file
View File

@ -0,0 +1,48 @@
<?php
// Acceso a los datos de la Library of Congress
// http://id.loc.gov/vocabulary/relators.json
class lOC {
var $language="eu";
var $type='item';
var $limit='50';
var $url='http://id.loc.gov/vocabulary/relators.json';
function getRelators() {
$ch = curl_init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_URL,$this->url);
$json = curl_exec($ch);
$results = json_decode($json,true);
return new arrayObject($results);
//return new arrayObject($results["<http://id.loc.gov/vocabulary/relators/abr>"]);
}
}
if (isset($argv)) :
if (isset($argv[1])) $query = $argv[1]; else $query="audiolab";
$l = new lOC();
//print_entities($l,$query);
print_relators($l->getRelators());
endif;
function print_relators($r) {
$it = $r->getIterator();
foreach ($it as $rs):
//print_r(array_keys($rs));
//print_r($rs["<http://www.loc.gov/mads/rdf/v1#authoritativeLabel>"][0]);
if (isset($rs["<http://www.loc.gov/mads/rdf/v1#authoritativeLabel>"][0])):
print $rs["<http://www.loc.gov/mads/rdf/v1#authoritativeLabel>"][0]["value"]."\n";
endif;
endforeach;
}
?>

110
tools/wikidata.php Executable file
View File

@ -0,0 +1,110 @@
<?php
class wikiData {
var $language="eu";
var $type='item';
var $limit='50';
function searchEntities($query,$continue=0) {
$ch = curl_init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_URL,'https://en.wikidata.org/w/api.php');
// SEARH
$data = array(
'action' => 'wbsearchentities',
'search' => $query,
'language' => $this->language,
'format' => 'json',
'limit' => $this->limit,
'type' => $this->type,
'continue' => $continue
);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
$json = curl_exec($ch);
$results = json_decode($json,true);
if (isset($results['search-continue'])) {
$offset = $results['search-continue'];
$r0 = new arrayObject($results['search']);
$r = array_merge((array) $r0, (array) $this->searchEntities($query,$continue=$offset));
} else {
$r = new arrayObject($results['search']);
}
return new arrayObject($r);
}
function getEntities($ids) {
$ch = curl_init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_URL,'https://en.wikidata.org/w/api.php');
// get id
// ?action=wbgetentities&ids=Q42
$data = array(
'action' => 'wbgetentities',
'format' => 'json',
'ids' => $ids,
'props' => 'aliases|info'
);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
$json = curl_exec($ch);
$results = json_decode($json,true);
return new arrayObject($results['entities']);
}
}
if (isset($argv)) :
if (isset($argv[1])) $query = $argv[1]; else $query="audiolab";
$wd = new wikiData();
print_entities($wd,$query);
endif;
function print_entities($wd,$query) {
$it = $wd->searchEntities($query)->getIterator();
foreach ($it as $item) :
print $item['id']." | ".$item['label']."\n";
//var_dump($wd->getEntities($item['id']));
$ite = $wd->getEntities($item['id'])->getIterator();
foreach ($ite as $entity) :
print $entity['id']."|".$entity['modified']."|\n";
//check de los alias es,en,eu
if(isset($entity['aliases']['es'])) :
print "CASTELLANO\n";
$aliases = new arrayObject($entity['aliases']['es']);
foreach ($aliases as $alias):
print $alias['value']."\n";
endforeach;
endif;
if(isset($entity['aliases']['en'])) :
print "ENGLISH\n";
$aliases = new arrayObject($entity['aliases']['en']);
foreach ($aliases as $alias):
print $alias['value']."\n";
endforeach;
endif;
if(isset($entity['aliases']['eu'])) :
print "EUSKERA\n";
$aliases = new arrayObject($entity['aliases']['eu']);
foreach ($aliases as $alias):
print $alias['value']."\n";
endforeach;
endif;
endforeach;
print "\n";
endforeach;
}
?>

View File

@ -0,0 +1,401 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mods="http://www.loc.gov/mods/v3" exclude-result-prefixes="mods"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:srw_dc="info:srw/schema/1/dc-schema"
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
This stylesheet transforms MODS version 3.2 records and collections of records to simple Dublin Core (DC) records,
based on the Library of Congress' MODS to simple DC mapping <http://www.loc.gov/standards/mods/mods-dcsimple.html>
The stylesheet will transform a collection of MODS 3.2 records into simple Dublin Core (DC)
as expressed by the SRU DC schema <http://www.loc.gov/standards/sru/dc-schema.xsd>
The stylesheet will transform a single MODS 3.2 record into simple Dublin Core (DC)
as expressed by the OAI DC schema <http://www.openarchives.org/OAI/2.0/oai_dc.xsd>
Because MODS is more granular than DC, transforming a given MODS element or subelement to a DC element frequently results in less precise tagging,
and local customizations of the stylesheet may be necessary to achieve desired results.
This stylesheet makes the following decisions in its interpretation of the MODS to simple DC mapping:
When the roleTerm value associated with a name is creator, then name maps to dc:creator
When there is no roleTerm value associated with name, or the roleTerm value associated with name is a value other than creator, then name maps to dc:contributor
Start and end dates are presented as span dates in dc:date and in dc:coverage
When the first subelement in a subject wrapper is topic, subject subelements are strung together in dc:subject with hyphens separating them
Some subject subelements, i.e., geographic, temporal, hierarchicalGeographic, and cartographics, are also parsed into dc:coverage
The subject subelement geographicCode is dropped in the transform
Revision 1.1 2007-05-18 <tmee@loc.gov>
Added modsCollection conversion to DC SRU
Updated introductory documentation
Version 1.0 2007-05-04 Tracy Meehleib <tmee@loc.gov>
-->
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="//mods:modsCollection">
<srw_dc:dcCollection xsi:schemaLocation="info:srw/schema/1/dc-schema http://www.loc.gov/standards/sru/dc-schema.xsd">
<xsl:apply-templates/>
<xsl:for-each select="mods:modsCollection/mods:mods">
<srw_dc:dc xsi:schemaLocation="info:srw/schema/1/dc-schema http://www.loc.gov/standards/sru/dc-schema.xsd">
<xsl:apply-templates/>
</srw_dc:dc>
</xsl:for-each>
</srw_dc:dcCollection>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="mods:mods">
<oai_dc:dc xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
<xsl:apply-templates/>
</oai_dc:dc>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="mods:titleInfo">
<xsl:for-each select="mods:title">
<dc:title>
<xsl:value-of select="."/>
</dc:title>
</xsl:for-each>
<xsl:for-each select="mods:subTitle">
<dc:title xml:lang="{./@xml:lang}">
<xsl:value-of select="."/>
</dc:title>
</xsl:for-each>
</xsl:template>
<xsl:template match="mods:name">
<xsl:choose>
<xsl:when
test="mods:role/mods:roleTerm[@type='text']='creator' or mods:role/mods:roleTerm[@type='code']='cre' ">
<dc:creator>
<xsl:call-template name="name"/>
</dc:creator>
</xsl:when>
<xsl:otherwise>
<dc:contributor>
<xsl:call-template name="name"/>
</dc:contributor>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="mods:classification">
<dc:subject>
<xsl:value-of select="."/>
</dc:subject>
</xsl:template>
<xsl:template match="mods:subject[mods:topic | mods:name | mods:occupation | mods:geographic | mods:hierarchicalGeographic | mods:cartographics | mods:temporal] ">
<dc:subject>
<xsl:for-each select="mods:topic">
<xsl:value-of select="."/>
<xsl:if test="position()!=last()">--</xsl:if>
</xsl:for-each>
<xsl:for-each select="mods:occupation">
<xsl:value-of select="."/>
<xsl:if test="position()!=last()">--</xsl:if>
</xsl:for-each>
<xsl:for-each select="mods:name">
<xsl:call-template name="name"/>
</xsl:for-each>
</dc:subject>
<xsl:for-each select="mods:titleInfo/mods:title">
<dc:subject>
<xsl:value-of select="mods:titleInfo/mods:title"/>
</dc:subject>
</xsl:for-each>
<xsl:for-each select="mods:geographic">
<dc:coverage>
<xsl:value-of select="."/>
</dc:coverage>
</xsl:for-each>
<xsl:for-each select="mods:hierarchicalGeographic">
<dc:coverage>
<xsl:for-each
select="mods:continent|mods:country|mods:provence|mods:region|mods:state|mods:territory|mods:county|mods:city|mods:island|mods:area">
<xsl:value-of select="."/>
<xsl:if test="position()!=last()">--</xsl:if>
</xsl:for-each>
</dc:coverage>
</xsl:for-each>
<xsl:for-each select="mods:cartographics/*">
<dc:coverage>
<xsl:value-of select="."/>
</dc:coverage>
</xsl:for-each>
<xsl:if test="mods:temporal">
<dc:coverage>
<xsl:for-each select="mods:temporal">
<xsl:value-of select="."/>
<xsl:if test="position()!=last()">-</xsl:if>
</xsl:for-each>
</dc:coverage>
</xsl:if>
<xsl:if test="*[1][local-name()='topic'] and *[local-name()!='topic']">
<dc:subject>
<xsl:for-each select="*[local-name()!='cartographics' and local-name()!='geographicCode' and local-name()!='hierarchicalGeographic'] ">
<xsl:value-of select="."/>
<xsl:if test="position()!=last()">--</xsl:if>
</xsl:for-each>
</dc:subject>
</xsl:if>
</xsl:template>
<xsl:template match="mods:abstract | mods:tableOfContents | mods:note">
<dc:description>
<xsl:value-of select="."/>
</dc:description>
</xsl:template>
<xsl:template match="mods:originInfo">
<xsl:apply-templates select="*[@point='start']"/>
<xsl:for-each
select="mods:dateIssued[@point!='start' and @point!='end'] |mods:dateCreated[@point!='start' and @point!='end'] | mods:dateCaptured[@point!='start' and @point!='end'] | mods:dateOther[@point!='start' and @point!='end']">
<dc:date>
<xsl:value-of select="."/>
</dc:date>
</xsl:for-each>
<xsl:for-each select="mods:publisher">
<dc:publisher>
<xsl:value-of select="."/>
</dc:publisher>
</xsl:for-each>
</xsl:template>
<xsl:template match="mods:dateIssued | mods:dateCreated | mods:dateCaptured">
<dc:date>
<xsl:choose>
<xsl:when test="@point='start'">
<xsl:value-of select="."/>
<xsl:text> - </xsl:text>
</xsl:when>
<xsl:when test="@point='end'">
<xsl:value-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</dc:date>
</xsl:template>
<xsl:template match="mods:genre">
<xsl:choose>
<xsl:when test="@authority='dct'">
<dc:type>
<xsl:value-of select="."/>
</dc:type>
<xsl:for-each select="mods:typeOfResource">
<dc:type>
<xsl:value-of select="."/>
</dc:type>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<dc:type>
<xsl:value-of select="."/>
</dc:type>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="mods:typeOfResource">
<xsl:if test="@collection='yes'">
<dc:type>Collection</dc:type>
</xsl:if>
<xsl:if test=". ='software' and ../mods:genre='database'">
<dc:type>DataSet</dc:type>
</xsl:if>
<xsl:if test=".='software' and ../mods:genre='online system or service'">
<dc:type>Service</dc:type>
</xsl:if>
<xsl:if test=".='software'">
<dc:type>Software</dc:type>
</xsl:if>
<xsl:if test=".='cartographic material'">
<dc:type>Image</dc:type>
</xsl:if>
<xsl:if test=".='multimedia'">
<dc:type>InteractiveResource</dc:type>
</xsl:if>
<xsl:if test=".='moving image'">
<dc:type>MovingImage</dc:type>
</xsl:if>
<xsl:if test=".='three-dimensional object'">
<dc:type>PhysicalObject</dc:type>
</xsl:if>
<xsl:if test="starts-with(.,'sound recording')">
<dc:type>Sound</dc:type>
</xsl:if>
<xsl:if test=".='still image'">
<dc:type>StillImage</dc:type>
</xsl:if>
<xsl:if test=". ='text'">
<dc:type>Text</dc:type>
</xsl:if>
<xsl:if test=".='notated music'">
<dc:type>Text</dc:type>
</xsl:if>
</xsl:template>
<xsl:template match="mods:physicalDescription">
<xsl:if test="mods:extent">
<dc:format>
<xsl:value-of select="mods:extent"/>
</dc:format>
</xsl:if>
<xsl:if test="mods:form">
<dc:format>
<xsl:value-of select="mods:form"/>
</dc:format>
</xsl:if>
<xsl:if test="mods:internetMediaType">
<dc:format>
<xsl:value-of select="mods:internetMediaType"/>
</dc:format>
</xsl:if>
</xsl:template>
<xsl:template match="mods:mimeType">
<dc:format>
<xsl:value-of select="."/>
</dc:format>
</xsl:template>
<xsl:template match="mods:identifier">
<xsl:variable name="type" select="translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/>
<xsl:choose>
<xsl:when test="contains ('isbn issn uri doi lccn uri', $type)">
<dc:identifier>
<xsl:value-of select="$type"/>: <xsl:value-of select="."/>
</dc:identifier>
</xsl:when>
<xsl:otherwise>
<dc:identifier>
<xsl:value-of select="."/>
</dc:identifier>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="mods:location">
<dc:identifier>
<xsl:for-each select="mods:url">
<xsl:value-of select="."/>
</xsl:for-each>
</dc:identifier>
</xsl:template>
<xsl:template match="mods:language">
<dc:language>
<xsl:value-of select="normalize-space(.)"/>
</dc:language>
</xsl:template>
<xsl:template match="mods:relatedItem[mods:titleInfo | mods:name | mods:identifier | mods:location]">
<xsl:choose>
<xsl:when test="@type='original'">
<dc:source>
<xsl:for-each
select="mods:titleInfo/mods:title | mods:identifier | mods:location/mods:url">
<xsl:if test="normalize-space(.)!= ''">
<xsl:value-of select="."/>
<xsl:if test="position()!=last()">--</xsl:if>
</xsl:if>
</xsl:for-each>
</dc:source>
</xsl:when>
<xsl:when test="@type='series'"/>
<xsl:otherwise>
<dc:relation>
<xsl:for-each
select="mods:titleInfo/mods:title | mods:identifier | mods:location/mods:url">
<xsl:if test="normalize-space(.)!= ''">
<xsl:value-of select="."/>
<xsl:if test="position()!=last()">--</xsl:if>
</xsl:if>
</xsl:for-each>
</dc:relation>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="mods:accessCondition">
<dc:rights>
<xsl:value-of select="."/>
</dc:rights>
</xsl:template>
<xsl:template name="name">
<xsl:variable name="name">
<xsl:for-each select="mods:namePart[not(@type)]">
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</xsl:for-each>
<xsl:value-of select="mods:namePart[@type='family']"/>
<xsl:if test="mods:namePart[@type='given']">
<xsl:text>, </xsl:text>
<xsl:value-of select="mods:namePart[@type='given']"/>
</xsl:if>
<xsl:if test="mods:namePart[@type='date']">
<xsl:text>, </xsl:text>
<xsl:value-of select="mods:namePart[@type='date']"/>
<xsl:text/>
</xsl:if>
<xsl:if test="mods:displayForm">
<xsl:text> (</xsl:text>
<xsl:value-of select="mods:displayForm"/>
<xsl:text>) </xsl:text>
</xsl:if>
<xsl:for-each select="mods:role[mods:roleTerm[@type='text']!='creator']">
<xsl:text> (</xsl:text>
<xsl:value-of select="normalize-space(.)"/>
<xsl:text>) </xsl:text>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="normalize-space($name)"/>
</xsl:template>
<xsl:template match="mods:dateIssued[@point='start'] | mods:dateCreated[@point='start'] | mods:dateCaptured[@point='start'] | mods:dateOther[@point='start'] ">
<xsl:variable name="dateName" select="local-name()"/>
<dc:date>
<xsl:value-of select="."/>-<xsl:value-of select="../*[local-name()=$dateName][@point='end']"/>
</dc:date>
</xsl:template>
<xsl:template match="mods:temporal[@point='start'] ">
<xsl:value-of select="."/>-<xsl:value-of select="../mods:temporal[@point='end']"/>
</xsl:template>
<xsl:template match="mods:temporal[@point!='start' and @point!='end'] ">
<xsl:value-of select="."/>
</xsl:template>
<!-- suppress all else:-->
<xsl:template match="*"/>
</xsl:stylesheet>