Commit 7974fef8 authored by root's avatar root
Browse files

major upgrades and refactoring

parent 66f6fbaf
......@@ -13,7 +13,7 @@ ini_set('memory_limit' , '3g');
# Slim
$configuration = [
'settings' => [
'displayErrorDetails' => false,
'displayErrorDetails' => true,
'view_path' => __DIR__.'/templates',
'view_cache_path' => __DIR__.'/templates/cache',
],
......
......@@ -6,8 +6,10 @@ class Config {
private $config = null;
static function get($group){
if (!isset($config))
$config = parse_ini_file(__DIR__.'/../../config.ini', true);
if (!isset($config)){
$cfile = (isset($_SERVER['HTTP_HOST'])) ? __DIR__.'/../../'.$_SERVER['HTTP_HOST'].'_conf.ini' : __DIR__.'/../../config.ini';
$config = parse_ini_file($cfile, true);
}
return (isset($group)) ? $config[$group] : $config;
}
}
......
......@@ -3,12 +3,12 @@
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/terms/"
xmlns:dwc="http://rs.tdwg.org/dwc/terms/" >
<rdf:Description rdf:about="{{ config['catalog_uri'] }}">
<rdf:Description rdf:about="{{ base_url()|replace({'https://':'http://'}) ~ path_for('catalog') }}">
<dc:created>{{ 'now' | date('c') }}</dc:created>
</rdf:Description>
<rdf:Description rdf:about="{{ config['object_base_uri'] }}">
<rdf:Description rdf:about="{{ base_url()|replace({'https://':'http://'}) ~ path_for('object', {barcode:barcode}) }}">
<dwc:Occurrence>
<rdf:Bag rdf:about="{{ config['catalog_uri'] }}">
<rdf:Bag rdf:about="{{ base_url()|replace({'https://':'http://'}) ~ path_for('catalog') }}">
{% for specimen in specimens %}
<rdf:li>
<rdf:Description rdf:about="{{ specimen[config['rdf:about']] }}">
......
......@@ -16,13 +16,25 @@
{"label":"{{ element }}", "value": "{{ specimen[column] }}"}
{% endif %}
{% endfor %}
{% for element, column in iiif_resources|merge(rdf_resources)|merge(rdf_wikidata) %}
{% for element, column in iiif_resources|merge(rdf_resources) %}
{% if element is not same as('rdf:about') and specimen[column] is not empty %}
{% if not first %},{% endif %}
{% set first = false %}
{"label":"{{ element }}", "value": "<a href=\"{{ specimen[column] }}\">{{ specimen[column] }}</a>"}
{% endif %}
{% endfor %}
{% for element, column in rdf_sameas %}
{% if element is not same as('rdf:about') and specimen[column] is not empty %}
{% if not first %},{% endif %}
{% set first = false %}
{"label":"owl:sameAs", "value": "<a href=\"{{ specimen[column] }}\">{{ specimen[column] }}</a>"}
{% endif %}
{% endfor %}
{% for item in iiif %}
{% if not first %},{% endif %}
{% set first = false %}
{"label":"dwc:associatedMedia", "value": "<a href=\"{{ item[iiif_conf['image_url']] }}\">{{ item[iiif_conf['image_url']] }}</a>"}
{% endfor %}
],
"attribution": "Botanisches Museum und Botanischer Garten Berlin",
"logo": "https://www.bgbm.org/sites/all/themes/bgbm_fucd20/images/logo_bgbm.jpg",
......@@ -34,7 +46,7 @@
{
"@type": "sc:Canvas",
"@id": "https://herbarium-dev.bgbm.org/iiif/canvas/{{ loop.index }}",
"label": "{{ item[config['filename']] }}",
"label": "{{ item[iiif_conf['filename']] }}",
"width": 6099,
"height": 8599,
"images": [
......@@ -44,10 +56,10 @@
"on": "https://herbarium-dev.bgbm.org/iiif/canvas/{{ loop.index }}",
"resource": {
"@type": "dctypes:Image",
"@id": "{{ config['image_base_url'] ~ item[config['requestpath']]|replace({'!':'/'}) ~ "/" ~ item[config['filename']] }}",
"@id": "{{ iiif_conf['image_base_url'] ~ item[iiif_conf['requestpath']]|replace({'!':'/'}) ~ "/" ~ item[iiif_conf['filename']] }}",
"service": {
"@context": "http://iiif.io/api/image/2/context.json",
"@id": "{{ config['endpoint'] ~ item[config['requestpath']] ~ "!" ~ item[config['filename']] }}",
"@id": "{{ iiif_conf['endpoint'] ~ item[iiif_conf['requestpath']] ~ "!" ~ item[iiif_conf['filename']] }}",
"profile": "http://iiif.io/api/image/2/level2.json"
}
}
......
......@@ -28,30 +28,32 @@
{% endfor %}
{% for element, column in resources if specimen[column] is not empty %}
<{{ element }} rdf:resource="{{ specimen[column] }}" />
{% endfor %}
{% endfor %}
{% for item in iiif %}
<dwc:associatedMedia rdf:resource="{{ item[iiif_conf['image_url']] }}" />
{% endfor %}
</rdf:Description>
{% if specimen[wikidata['rdf:about']] is not empty %}
<rdf:Description rdf:about="{{ specimen[wikidata['rdf:about']] }}">
{% if specimen[wikidata['owl:sameAsViaf']] is not empty %}
<owl:sameAs rdf:resource="{{ specimen[wikidata['owl:sameAsViaf']] }}" />
{% endif %}
{% if specimen[wikidata['owl:sameAsHuH']] is not empty %}
<owl:sameAs rdf:resource="{{ specimen[wikidata['owl:sameAsHuH']] }}" />
{% if specimen[sameas['rdf:about']] is not empty %}
<rdf:Description rdf:about="{{ specimen[sameas['rdf:about']]|replace({'https://':'http://'}) }}">
{% for element, column in sameas %}
{% if element is not same as('rdf:about') and specimen[column] is not empty %}
<owl:sameAs rdf:resource="{{ specimen[column] }}" />
{% endif %}
{% endfor %}
</rdf:Description>
{% endif %}
{% if specimen[iiif['rdf:Description']] is not empty %}
{% if iiif is not empty %}
<!--This is a link to iiif data-->
<dc:relation>
<rdf:Description rdf:about="{{ specimen[iiif['rdf:Description']] }}" >
<dc:identifier rdf:resource="{{ specimen[iiif['dc:identifier']] }}" />
<dc:type rdf:resource="{{ specimen[iiif['dc:type']] }}" />
<dc:subject rdf:resource="{{ specimen[iiif['dc:subject']] }}" />
<dc:format>{{ specimen[iiif['dc:format']] }}</dc:format>
<dc:description xml:lang="en">{{ specimen[iiif['dc:description']] }}</dc:description>
<dc:created>{{ specimen[iiif['dc:created']] }}</dc:created>
<rdf:Description rdf:about="{{ base_url()|replace({'https://':'http://'}) ~ path_for('iiif', {barcode:barcode}) }}" >
<dc:identifier rdf:resource="{{ base_url()|replace({'https://':'http://'}) ~ path_for('iiif', {barcode:barcode}) }}" />
<dc:type rdf:resource="http://iiif.io/api/presentation/3#Manifest" />
<dc:subject rdf:resource="{{ specimen[iiif_conf['dc:subject']] }}" />
<dc:format>application/ld+json</dc:format>
<dc:description xml:lang="en">A IIIF resource for this specimen.</dc:description>
<dc:created>{{ specimen[iiif_conf['dc:created']] }}</dc:created>
</rdf:Description>
</dc:relation>
{% endif %}
......
......@@ -14,10 +14,10 @@ rdf = 'application/rdf+xml'
reg_match_pattern = '/^((B|BBG|BGT|JACQID)([A-Za-z_0-9])*|BW[0-9]{5}[A-Sa-sV-Zv-z]?[0-9]*)$/'
[database]
server = ''
user = ''
password = ''
db = ''
server = 'bgbm-sql01.bgbm.fu-berlin.de'
user = 'WebUser'
password = 'WebUser2014'
db = 'Herbar'
; ? Will be replaced with Barcode
; Query to fetch specimen data from database to display in RDF (see below)
......@@ -55,21 +55,46 @@ dwc:recordNumber = 'CollectorNumber'
dwc:recordedBy = 'Collector'
dwc:fieldNumber = 'CollectorNumber'
[rdf/resources]
; Mapping of RDF-Resources to Database Column Names returned by query_rdf_one (see above)
; You can add and remove RDF-Elements from this list to adjust the RDF to your needs
; Display Example: <dwc:associatedMedia rdf:resource="http://subdomain.domain.de/myimage"/>
dwc:associatedMedia = 'Image'
; Display Example: <dwciri:recordedBy rdf:resource="https://www.wikidata.org/wiki/Q4172636" />
dwciri:recordedBy = 'WIKIDATA_ID'
[rdf/wikidata]
[rdf/sameas]
; This section is used to describe owl:sameAs declarations for a single other resource
; than the specimen object itself. We are using it only to further describe the botanist specified in dwciri:recordedBy.
; Column Names for Mapping must be returned by query_rdf_one (see above).
; Display Example:
; <rdf:Description rdf:about="https://www.wikidata.org/wiki/Q4172636">
; <owl:sameAs rdf:resource="https://viaf.org/viaf/79386055/" />
; <owl:sameAs rdf:resource="http://purl.oclc.org/net/edu.harvard.huh/guid/uuid/60dc5749-c121-4547-93ab-4a147bde78ee" />
; </rdf:Description>
rdf:about = 'WIKIDATA_ID'
owl:sameAsHuH = 'HUH_PURL'
owl:sameAsViaf = 'VIAF_ID'
; Each entry after this will generate a owl:sameAs declaration with the content of the
; specified database column (query_rdf_one) as rdf:resource.
huh = 'HUH_PURL'
viaf = 'VIAF_ID'
[sitemap]
; Database Column Name for Specimen Object URI returned by query_rdf_one (see above)
rdf:about = 'ObjectURI'
; Database Column Name for Specimen Title returned by query_rdf_one (see above)
dc:title = 'Title'
[iiif]
; Digilib IIIF API Endpoint
endpoint = 'https://pictures.bgbm.org/digilib/Scaler/IIIF/'
; Digilib image base URL
image_base_url = 'https://pictures.bgbm.org/digilib/digilib.html?fn='
; Column Names returned by query_iiif (see above) containing the digilib request path, file name and the image url
requestpath = 'RequestPath'
filename = 'name'
image_url = 'image'
[rdf/iiif]
; Mapping of Relation-Fields linking to IIIF-Data to Database Column Names
; For RDF:
; Mapping of Relation-Fields linking to IIIF-Data to Database Column Names
; returned by query_rdf_one (see above)
; Display Example:
; <dc:relation>
......@@ -82,49 +107,21 @@ owl:sameAsViaf = 'VIAF_ID'
; <dc:created>2011-08-22T11:54:43Z</dc:created>
; </rdf:Description>
; </dc:relation>
rdf:Description = 'iiifID'
dc:identifier = 'iiifID'
dc:subject = 'ObjectURI'
dc:created = 'iiifCreated'
; Interpreted as string, not as column name
dc:type = 'http://iiif.io/api/presentation/3#Manifest'
; Interpreted as string, not as column name
dc:format = 'application/ld+json'
dc:created = 'created'
; Interpreted as string, not as column name
dc:description = 'A IIIF resource for this specimen.'
[sitemap]
; Settings for sitemap
catalog_uri = 'http://herbarium.bgbm.org/data/rdf/catalog'
object_base_uri = 'http://herbarium.bgbm.org/object'
; Database Column Name for Specimen Object URI returned by query_rdf_one (see above)
rdf:about = 'ObjectURI'
; Database Column Name for Specimen Title returned by query_rdf_one (see above)
dc:title = 'Title'
[iiif]
; Digilib IIIF API Endpoint
endpoint = 'https://pictures.bgbm.org/digilib/Scaler/IIIF/'
; Digilib image base URL
image_base_url = 'https://pictures.bgbm.org/digilib/digilib.html?fn='
; Column Names returned by query_iiif (see above) containing the digilib request path and file name
requestpath = 'RequestPath'
filename = 'name'
[iiif/literals]
; Mapping of IIIF Manifest parameters to Database Column Names returned by query_rdf_one (see above)
; Mapping of IIIF Manifest parameters to Database Column Names returned by query_rdf_one (see above).
label = 'Title'
description = 'TitleDescription'
; You can add and delete Elements below this to adjust the IIIF Metadata to your needs
; You can add and delete Elements below this to adjust the IIIF Metadata to your needs.
; All RDF elements defined in the rdf/* segmemts are added automatically.
[iiif/resources]
; Mapping of IIIF Manifest parameters to Database Column Names returned by query_rdf_one (see above)
; Produces "clickable" metadata entries
CETAF_ID = ObjectURI
; You can add and delete Elements below this to adjust the IIIF Metadata to your needs
; You can add and delete Elements below this to adjust the IIIF Metadata to your needs.
; All RDF elements defined in the rdf/* segmemts are added automatically.
......@@ -50,6 +50,78 @@ $app->group('/object', function() use ($app) {
})->setName('object');
$app->get('/{barcode}/manifest.json', function ($request, $response, $args) {
return $response->withRedirect($this->get('router')->pathFor('iiif_manifest', ['barcode' => $args['barcode']]), 303);
})->setName('manifest');
});
$app->get('/iiif/{barcode}', function ($request, $response, $args) {
return $response->withRedirect($this->get('router')->pathFor('iiif_manifest', ['barcode' => $args['barcode']]), 303);
})->setName('iiif');
$app->group('/data', function() use ($app) {
$app->get('/page[/[{barcode}]]', function ($request, $response, $args) {
## Barcode DatabaseUtility Class
$databaseUtil = new DatabaseUtil();
## Check if barcode is given in path or as query parameter
$params = $request->getParams();
$barcode = (isset($args['barcode'])) ? $args['barcode'] : ((isset($params['barcode'])) ? $params['barcode'] : null);
## If no barcode is given, redirect to catalog
if(!isset($barcode))
return $response->withRedirect($this->get('router')->pathFor('catalog'), 303);
## If barcode was not found in DB, return 404
if(!$databaseUtil->isInDB($barcode))
return $this->view->render($response, '404.template.twig')->withStatus(404);
## Get URL for redirect
$htmlUri = $databaseUtil->fetchHtmlUri($barcode);
if(!isset($htmlUri) || empty($htmlUri))
return $response->withRedirect(sprintf(Config::get('urls')['html_url'], $barcode), 303);
return $response->withRedirect($htmlUri, 303);
})->setName('page');
$app->get('/rdf[/[{barcode}]]', function ($request, $response, $args) {
## Barcode DatabaseUtility Class
$databaseUtil = new DatabaseUtil();
## Check if barcode is given in path or as query parameter
$params = $request->getParams();
$barcode = (isset($args['barcode'])) ? $args['barcode'] : ((isset($params['barcode'])) ? $params['barcode'] : null);
## If no barcode is given, return sitemap
if(!isset($barcode)){
$specimens = $databaseUtil->getAllSpecimenEscaped();
return $this->view->render($response, 'sitemap.rdf.template.twig', [
'specimens' => $specimens,
'barcode' => $barcode,
'config' => Config::get('sitemap')
])->withHeader('Content-type', 'application/xml');
}
## Get specimen from db by barcode
$specimen = $databaseUtil->getSpecimenEscaped($barcode);
## Get associated media for barcode
$iiif = $databaseUtil->getIIIF($barcode);
## If no specimen for barcode was found, return 404
if(!isset($specimen))
return $this->view->render($response, '404.template.twig')->withStatus(404);
## Return specimen RDF
return $this->view->render($response, 'specimen.rdf.template.twig', [
'barcode' => $barcode,
'specimen' => $specimen,
'iiif' => $iiif,
'iiif_conf' => Config::get('iiif'),
'literals' => Config::get('rdf/literals'),
'resources'=> Config::get('rdf/resources'),
'sameas'=> Config::get('rdf/sameas')
])->withHeader('Content-type', Config::get('contenttypes')['rdf']);
})->setName('rdf');
$app->get('/iiif/{barcode}/manifest.json', function ($request, $response, $args) {
$barcode = $args['barcode'];
## Barcode DatabaseUtility Class
......@@ -67,76 +139,16 @@ $app->group('/object', function() use ($app) {
'barcode' => $barcode,
'specimen' => $specimen,
'iiif' => $iiif,
'config' => Config::get('iiif'),
'iiif_conf' => Config::get('iiif'),
'rdf_literals' => Config::get('rdf/literals'),
'rdf_resources'=> Config::get('rdf/resources'),
'rdf_wikidata'=> Config::get('rdf/wikidata'),
'rdf_sameas'=> Config::get('rdf/sameas'),
'iiif_literals' => Config::get('iiif/literals'),
'iiif_resources' => Config::get('iiif/resources')
])->withHeader('Content-type', 'application/json')
->withHeader("Access-Control-Allow-Origin","*")
->withHeader("Access-Control-Allow-Methods","GET");
})->setName('manifest');
});
$app->group('/data', function() use ($app) {
$app->get('/page[/[{barcode}]]', function ($request, $response, $args) {
## Barcode DatabaseUtility Class
$databaseUtil = new DatabaseUtil();
## Check if barcode is given in path or as query parameter
$params = $request->getParams();
$barcode = (isset($args['barcode'])) ? $args['barcode'] : ((isset($params['barcode'])) ? $params['barcode'] : null);
## If no barcode is given, redirect to catalog
if(!isset($barcode))
return $response->withRedirect($this->get('router')->pathFor('catalog'), 303);
## If barcode was not found in DB, return 404
if(!$databaseUtil->isInDB($barcode))
return $this->view->render($response, '404.template.twig')->withStatus(404);
## Get URL for redirect
$htmlUri = $databaseUtil->fetchHtmlUri($barcode);
if(!isset($htmlUri) || empty($htmlUri))
return $response->withRedirect(sprintf(Config::get('urls')['html_url'], $barcode), 303);
return $response->withRedirect($htmlUri, 303);
})->setName('page');
$app->get('/rdf[/[{barcode}]]', function ($request, $response, $args) {
## Barcode DatabaseUtility Class
$databaseUtil = new DatabaseUtil();
## Check if barcode is given in path or as query parameter
$params = $request->getParams();
$barcode = (isset($args['barcode'])) ? $args['barcode'] : ((isset($params['barcode'])) ? $params['barcode'] : null);
## If no barcode is given, return sitemap
if(!isset($barcode)){
$specimens = $databaseUtil->getAllSpecimenEscaped();
return $this->view->render($response, 'sitemap.rdf.template.twig', [
'specimens' => $specimens,
'config' => Config::get('sitemap')
])->withHeader('Content-type', 'application/xml');
}
## Get specimen from db by barcode
$specimen = $databaseUtil->getSpecimenEscaped($barcode);
## If no specimen for barcode was found, return 404
if(!isset($specimen))
return $this->view->render($response, '404.template.twig')->withStatus(404);
## Return specimen RDF
return $this->view->render($response, 'specimen.rdf.template.twig', [
'barcode' => $barcode,
'specimen' => $specimen,
'literals' => Config::get('rdf/literals'),
'resources'=> Config::get('rdf/resources'),
'wikidata'=> Config::get('rdf/wikidata'),
'iiif' => Config::get('rdf/iiif')
])->withHeader('Content-type', Config::get('contenttypes')['rdf']);
})->setName('rdf');
})->setName('iiif_manifest');
});
$app->get('/catalog.gz', function ($request, $response, $args) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment