Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
marcus-lodspeakr
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
uib-ub
Spesialsamlingene
marcus-lodspeakr
Commits
87a3198d
Commit
87a3198d
authored
13 years ago
by
alangrafu
Browse files
Options
Downloads
Patches
Plain Diff
Added uriModule
parent
40cc5800
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
common.inc.php
+2
-1
2 additions, 1 deletion
common.inc.php
modules/uriModule.php
+119
-0
119 additions, 0 deletions
modules/uriModule.php
utils/modules/create-uri.sh
+153
-0
153 additions, 0 deletions
utils/modules/create-uri.sh
utils/modules/delete-uri.sh
+65
-0
65 additions, 0 deletions
utils/modules/delete-uri.sh
with
339 additions
and
1 deletion
common.inc.php
+
2
−
1
View file @
87a3198d
...
...
@@ -36,6 +36,7 @@ $conf['service']['prefix'] = 'service.';
$conf
[
'service'
][
'class'
]
=
'classes/BasicSpecialFunction.php'
;
$conf
[
'class'
][
'prefix'
]
=
'class.'
;
$conf
[
'uri'
][
'prefix'
]
=
'uri.'
;
//Frontpage when user goes to http://example.org/
$conf
[
'root'
]
=
'index.html'
;
...
...
@@ -51,7 +52,7 @@ $conf['debug'] = false;
//using the modules in the following order
$conf
[
'modules'
]
=
array
();
$conf
[
'modules'
][
'directory'
]
=
'modules/'
;
$conf
[
'modules'
][
'available'
]
=
array
(
'static'
,
'class'
,
'service'
);
$conf
[
'modules'
][
'available'
]
=
array
(
'static'
,
'uri'
,
'class'
,
'service'
);
include_once
(
'settings.inc.php'
);
$conf
[
'view'
][
'standard'
][
'baseUrl'
]
=
$conf
[
'basedir'
];
...
...
This diff is collapsed.
Click to expand it.
modules/uriModule.php
0 → 100644
+
119
−
0
View file @
87a3198d
<?
require_once
(
'abstractModule.php'
);
class
UriModule
extends
abstractModule
{
//Uri module
public
function
match
(
$uri
){
global
$conf
;
global
$localUri
;
global
$uri
;
global
$acceptContentType
;
global
$endpoints
;
global
$base
;
require_once
(
'classes/MetaDb.php'
);
$metaDb
=
new
MetaDb
(
$conf
[
'metadata'
][
'db'
][
'location'
]);
$pair
=
Queries
::
getMetadata
(
$localUri
,
$acceptContentType
,
$metaDb
);
if
(
$pair
==
NULL
){
// Original URI is not in metadata
if
(
Queries
::
uriExist
(
$uri
,
$endpoints
[
'local'
])){
$page
=
Queries
::
createPage
(
$uri
,
$localUri
,
$acceptContentType
,
$metaDb
);
if
(
$page
==
NULL
){
Utils
::
send500
(
"Can't write sqlite database."
);
}
Utils
::
send303
(
$page
,
$acceptContentType
);
exit
(
0
);
}
else
{
return
false
;
//Utils::send404($uri);
}
}
$extension
=
Utils
::
getExtension
(
$pair
[
2
]);
$curie
=
Utils
::
uri2curie
(
$pair
[
0
]);
list
(
$modelFile
,
$viewFile
)
=
$this
::
getModelandView
(
$curie
,
$extension
);
if
(
$modelFile
==
NULL
){
return
FALSE
;
}
return
$pair
;
}
public
function
execute
(
$pair
){
global
$conf
;
global
$localUri
;
global
$uri
;
global
$acceptContentType
;
global
$endpoints
;
global
$base
;
global
$results
;
global
$first
;
list
(
$res
,
$page
,
$format
)
=
$pair
;
$uri
=
$res
;
$curie
=
Utils
::
uri2curie
(
$res
);
//If resource is not the page, send a 303 to the document
if
(
$res
==
$localUri
){
Utils
::
send303
(
$page
,
$acceptContentType
);
}
$uri
=
$res
;
if
(
$conf
[
'mirror_external_uris'
]){
$localUri
=
preg_replace
(
"|^"
.
$conf
[
'ns'
][
'local'
]
.
"|"
,
$conf
[
'basedir'
],
$res
);
}
$extension
=
Utils
::
getExtension
(
$format
);
/*Redefine Content type based on the
* dcterms:format for this page
*/
$acceptContentType
=
$format
;
$curie
=
Utils
::
uri2curie
(
$uri
);
list
(
$modelFile
,
$viewFile
)
=
$this
::
getModelandView
(
$curie
,
$extension
);
if
(
$modelFile
==
NULL
){
return
;
}
$base
=
$conf
[
'view'
][
'standard'
];
$base
[
'type'
]
=
$modelFile
;
$base
[
'this'
][
'value'
]
=
$uri
;
$base
[
'this'
][
'curie'
]
=
Utils
::
uri2curie
(
$uri
);
$base
[
'thislocal'
][
'value'
]
=
$localUri
;
$base
[
'thislocal'
][
'curie'
]
=
Utils
::
uri2curie
(
$localUri
);
$base
[
'this'
][
'contentType'
]
=
$acceptContentType
;
$base
[
'model'
][
'directory'
]
=
$conf
[
'model'
][
'directory'
];
$base
[
'view'
][
'directory'
]
=
$conf
[
'view'
][
'directory'
];
$base
[
'ns'
]
=
$conf
[
'ns'
];
chdir
(
$conf
[
'home'
]
.
$conf
[
'model'
][
'directory'
]);
Utils
::
queryFile
(
$modelFile
,
$endpoints
[
'local'
],
$results
,
$first
);
$results
=
Utils
::
internalize
(
$results
);
$base
[
'first'
]
=
Utils
::
getFirsts
(
$results
);
chdir
(
$conf
[
'home'
]);
if
(
is_array
(
$results
)){
$resultsObj
=
Convert
::
array_to_object
(
$results
);
}
else
{
$resultsObj
=
$results
;
}
Utils
::
processDocument
(
$viewFile
,
$base
,
$resultsObj
);
}
private
static
function
getModelandView
(
$uri
,
$extension
){
global
$conf
;
$auxViewFile
=
$conf
[
'view'
][
'directory'
]
.
$conf
[
'uri'
][
'prefix'
]
.
$uri
.
'/'
.
$extension
.
'.template'
;
$auxModelFile
=
$conf
[
'model'
][
'directory'
]
.
$conf
[
'uri'
][
'prefix'
]
.
$uri
.
'/'
.
$extension
.
'.queries'
;
if
(
file_exists
(
$auxModelFile
)
&&
file_exists
(
$auxViewFile
)
){
$viewFile
=
$conf
[
'uri'
][
'prefix'
]
.
$uri
.
'/'
.
$extension
.
'.template'
;
$modelFile
=
$conf
[
'uri'
][
'prefix'
]
.
$uri
.
'/'
.
$extension
.
'.queries'
;
return
array
(
$modelFile
,
$viewFile
);
}
return
array
(
NULL
,
NULL
);
}
}
?>
This diff is collapsed.
Click to expand it.
utils/modules/create-uri.sh
0 → 100755
+
153
−
0
View file @
87a3198d
#!/bin/bash
DIR
=
"
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
"
initToken
=
'uri'
modelHtml
=
$(
cat
<<
QUERY
SELECT ?s2 ?p2 ?s1 ?p1 WHERE {
{
<{{uri}}> ?s1 ?p1 .
}UNION{
?s2 ?p2 <{{uri}}> .
}
}
QUERY
)
viewHtml
=
$(
cat
<<
VIEW
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in base.ns %}xmlns:{{i}}="{{ns}}"
{%endfor%}version="XHTML+RDFa 1.0" xml:lang="en">
<head>
<title>Page about {{base.this.value}}</title>
<link href="{{base.baseUrl}}/lodspeakr/css/basic.css" rel="stylesheet" type="text/css" media="screen" />
<link rel="alternate" type="application/rdf+xml" title="RDF/XML Version" href="{{base.this.value}}.rdf" />
<link rel="alternate" type="text/turtle" title="Turtle Version" href="{{base.this.value}}.ttl" />
<link rel="alternate" type="text/plain" title="N-Triples Version" href="{{base.this.value}}.nt" />
<link rel="alternate" type="application/json" title="RDFJSON Version" href="{{base.this.value}}.json" />
</head>
<body about="{{base.this.value}}">
<h1>Page about <a href='{{base.this.value}}'>{{base.this.curie}}</a></h1>
<div>
<h2>Information from {{base.this.curie}}</h2>
<table>
{% for row in r.main %}
{% if row.s1%}
<tr>
<td><a href='{{row.s1.value}}'>{{row.s1.curie}}</a></td>
{% if row.p1.uri == 1 %}
<td><a rel='{{row.s1.curie}}' href='{{row.p1.value}}'>{{row.p1.curie}}</a></td>
{% else %}
<td><span property='{{row.s1.curie}}'>{{row.p1.value}}</span></td>
{% endif %}
</tr>
{% endif %}
{% endfor %}
</table>
<br/><br/>
<h2>Information pointing to {{base.this.curie}}</h2>
<table>
{% for row in r.main %}
{% if row.s2%}
<tr>
<td><a href='{{row.s2.value}}'>{{row.s2.curie}}</a></td>
<td><a rev='[{{row.p2.curie}}]' href='{{row.s2.value}}'>{{row.p2.curie}}</a></td>
</tr>
{%endif %}
{% endfor %}
</table>
</div>
</body>
</html>
VIEW)
modelRdf=
$(
cat
<<
QUERY
DESCRIBE ?resource WHERE {
[] a ?resource .
}
QUERY)
viewRdf=
$(
cat
<<
VIEW
{{r|safe}}
VIEW)
modelTtl=
$modelRdf
viewTtl=
$viewRdf
modelNt=
$modelRdf
viewNt=
$viewRdf
modelJson=
$modelRdf
viewJson=
$viewJson
#Check models
mainModelDir=
$DIR
/../../models/
$initToken
.
$1
if [ -e "
$mainModelDir
" ]
then
echo "WARNING: At least one model for
$1
exists." >&2
else
mkdir
$mainModelDir
fi
obj=( )
if [ "
$2
" == "all" ]
then
obj=( html rdf ttl nt json )
else
obj=(
$2
)
fi
for i in
${
obj
[@]
}
do
if [ -e
$mainModelDir
/
$i
.queries ]
then
echo ERROR:
$initToken
.
$1
/
$i
.queries exists in models. Operation aborted >&2
exit 1
fi
done
#Check views
mainViewDir=
$DIR
/../../views/
$initToken
.
$1
if [ -e "
$mainViewDir
" ]
then
echo "WARNING: At least one view for
$1
exists." >&2
else
mkdir
$mainViewDir
fi
for i in
${
obj
[@]
}
do
if [ -e
$mainViewDir
/
$i
.template ]
then
echo ERROR:
$initToken
.
$1
/
$i
already exist in views. Operation aborted >&2
exit 1
fi
done
#Create file structure
for i in
${
obj
[@]
}
do
mkdir
$mainModelDir
/
$i
.queries
if [ "
$i
" == "html" ]
then
echo "
$modelHtml
" >
$mainModelDir
/
$i
.queries/main.query
echo "
$viewHtml
" >
$mainViewDir
/
$i
.template
else
echo "
$modelRdf
" >
$mainModelDir
/
$i
.queries/main.query
echo "
$viewRdf
" >
$mainViewDir
/
$i
.template
fi
done
echo
$initToken
.
$1
created/modified successfully! >&2
This diff is collapsed.
Click to expand it.
utils/modules/delete-uri.sh
0 → 100755
+
65
−
0
View file @
87a3198d
#!/bin/bash
DIR
=
"
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
"
initToken
=
'uri'
#Check models
mainModelDir
=
$DIR
/../../models/
$initToken
.
$1
if
[
!
-e
"
$mainModelDir
"
]
then
echo
"ERROR:
$initToken
.
$1
doesn't exist in models. Operation aborted"
>
&2
exit
1
fi
obj
=(
)
if
[
"
$2
"
==
"all"
]
then
obj
=(
html rdf ttl nt json
)
else
obj
=(
$2
)
fi
for
i
in
${
obj
[@]
}
do
if
[
!
-e
$mainModelDir
/
$i
.queries
]
then
echo
"WARNING:
$initToken
.
$1
/
$i
.query does not exists in models."
>
&2
fi
done
#Check views
mainViewDir
=
$DIR
/../../views/
$initToken
.
$1
if
[
!
-e
"
$mainViewDir
"
]
then
echo
"ERROR:
$initToken
.
$1
doesn't exist in views. Operation aborted."
>
&2
fi
for
i
in
${
obj
[@]
}
do
if
[
!
-e
$mainViewDir
/
$i
.template
]
then
echo
"WARNING:
$mainViewDir
/
$i
.template doesn't exist in views."
>
&2
fi
done
#Delete file structure
if
[
"
$2
"
==
"all"
]
then
rm
-rf
$mainModelDir
rm
-rf
$mainViewDir
else
for
i
in
${
obj
[@]
}
do
rm
-rf
$mainModelDir
/
$i
.queries
rm
-rf
$mainViewDir
/
$i
.template
done
fi
echo
$initToken
.
$1
deleted successfully!
>
&2
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment