Revision 7876
Added by Aaron Marcuse-Kubitza almost 12 years ago
web/.htaccess | ||
---|---|---|
1 |
#### URL resolution |
|
2 |
|
|
3 |
DirectorySlash On |
|
4 |
DirectoryIndex index.php index.htm |
|
0 | 5 |
web/VegRef/util.php | ||
---|---|---|
1 |
<?php |
|
2 |
function starts_with($str, $prefix) |
|
3 |
{ |
|
4 |
return substr($str, 0, strlen($prefix)) === $prefix; |
|
5 |
} |
|
6 |
|
|
7 |
function ends_with($str, $suffix) |
|
8 |
{ |
|
9 |
return substr($str, -strlen($suffix)) === $suffix; |
|
10 |
} |
|
11 |
|
|
12 |
function rm_prefix($prefix, $str) |
|
13 |
{ |
|
14 |
return starts_with($str, $prefix) ? substr($str, strlen($prefix)) : $str; |
|
15 |
} |
|
16 |
|
|
17 |
function rm_suffix($suffix, $str) |
|
18 |
{ |
|
19 |
return ends_with($str, $suffix) ? |
|
20 |
substr($str, 0, strlen($str) - strlen($suffix)) : $str; |
|
21 |
} |
|
22 |
|
|
23 |
class Path |
|
24 |
{ |
|
25 |
public $head; |
|
26 |
public $tail; |
|
27 |
|
|
28 |
function Path($head, $tail) |
|
29 |
{ |
|
30 |
$this->head = $head; |
|
31 |
$this->tail = $tail; |
|
32 |
} |
|
33 |
} |
|
34 |
|
|
35 |
function partition($str, $delim) |
|
36 |
{ |
|
37 |
$delim_idx = strpos($str, $delim); |
|
38 |
return $delim_idx >= 0 ? new Path(substr($str, 0, $delim_idx), |
|
39 |
substr($str, $delim_idx+strlen($delim))) : new Path($str, ""); |
|
40 |
} |
|
41 |
|
|
42 |
function parse_dot_path($path) { return partition($path, "."); } |
|
43 |
|
|
44 |
function parse_mixed_path($path) |
|
45 |
{ |
|
46 |
preg_match('/^([\w-]*)(.*)$/', $path, $path); |
|
47 |
return new Path($path[1], rm_prefix(".", $path[2])); |
|
48 |
} |
|
49 |
|
|
50 |
function strip_url($url) { return rm_suffix("#", $url); } |
|
51 |
?> |
|
0 | 52 |
web/VegRef/util.js | ||
---|---|---|
1 |
function is_undef(value) { return typeof value === 'undefined' } |
|
2 |
|
|
3 |
function coalesce(value, empty) { return !is_undef(value) ? value : empty } |
|
4 |
|
|
5 |
function starts_with(str, prefix) |
|
6 |
{ |
|
7 |
return str.substr(0, prefix.length) === prefix |
|
8 |
} |
|
9 |
|
|
10 |
function ends_with(str, suffix) { return str.substr(-suffix.length) === suffix } |
|
11 |
|
|
12 |
function rm_prefix(prefix, str) |
|
13 |
{ |
|
14 |
return starts_with(str, prefix) ? str.substr(prefix.length) : str |
|
15 |
} |
|
16 |
|
|
17 |
function rm_suffix(suffix, str) |
|
18 |
{ |
|
19 |
return ends_with(str, suffix) ? |
|
20 |
str.substr(0, str.length - suffix.length) : str |
|
21 |
} |
|
22 |
|
|
23 |
function partition(str, delim) |
|
24 |
{ |
|
25 |
var delim_idx = str.indexOf(delim) |
|
26 |
return delim_idx >= 0 ? {head: str.substr(0, delim_idx), |
|
27 |
tail: str.substr(delim_idx+delim.length)} : {head: str, tail: ''} |
|
28 |
} |
|
29 |
|
|
30 |
function parse_dot_path(path) { return partition(path, '.') } |
|
31 |
|
|
32 |
function parse_mixed_path(path) |
|
33 |
{ |
|
34 |
path = /^([\w-]*)(.*)$/.exec(path) |
|
35 |
return {head: path[1], tail: rm_prefix('.', path[2])} |
|
36 |
} |
|
37 |
|
|
38 |
function strip_url(url) { return rm_suffix('#', url) } |
|
0 | 39 |
web/VegRef/.htaccess | ||
---|---|---|
1 |
#### URL resolution |
|
2 |
|
|
3 |
DirectorySlash On |
|
4 |
DirectoryIndex index.php index.htm |
|
5 |
|
|
6 |
### mod_rewrite |
|
7 |
|
|
8 |
RewriteEngine on |
|
9 |
RewriteBase /~aaronmk/VegRef/ |
|
10 |
|
|
11 |
# unknown paths -> VegRef |
|
12 |
RewriteCond %{REQUEST_FILENAME} !-f |
|
13 |
RewriteRule ^.*$ index.php?$0 |
|
0 | 14 |
web/VegRef/main.css | ||
---|---|---|
1 |
html {font-size: 10pt; font-family: Verdana, sans-serif;} |
|
2 |
a {color: blue; text-decoration: none;} |
|
3 |
a:hover {text-decoration: underline;} |
|
4 |
big, .big {font-size: 140%; font-weight: bold;} |
|
5 |
code, .code {font-weight: normal; font-family: Courier, monospace;} |
|
6 |
.progress {color: red; text-decoration: blink;} |
|
7 |
|
|
8 |
h2, h3, h4, h5, blockquote {margin-bottom: 3pt;} |
|
9 |
h3, h4 {margin-top: 8pt;} |
|
10 |
blockquote, h5 {margin-top: 4pt;} |
|
0 | 11 |
web/VegRef/index.php | ||
---|---|---|
1 |
<?php |
|
2 |
require_once dirname(__FILE__)."/util.php"; |
|
3 |
|
|
4 |
# config |
|
5 |
$alias = "j.mp/vegref"; |
|
6 |
|
|
7 |
function by_prefix($url, $main_url=null) |
|
8 |
{ |
|
9 |
if (!isset($main_url)) $main_url = $url; |
|
10 |
|
|
11 |
return function($path) use($url, $main_url) |
|
12 |
{ |
|
13 |
return $path ? $url.$path : $main_url; |
|
14 |
}; |
|
15 |
} |
|
16 |
|
|
17 |
$h_level = 4; |
|
18 |
$path = parse_mixed_path($_SERVER["QUERY_STRING"]); |
|
19 |
$ref = strtolower($path->head); |
|
20 |
|
|
21 |
function add_ref($name, $suffix, $url_func) |
|
22 |
{ |
|
23 |
global $alias, $h_level, $path, $ref; |
|
24 |
if (is_string($url_func)) $url_func = by_prefix($url_func); |
|
25 |
|
|
26 |
print("<h".$h_level."><code>".$alias.'#<big><a href="http://'.$alias |
|
27 |
."#".$name.'">'.$name."</a></big><i>".$suffix."</i></code></h".$h_level.">\n"); |
|
28 |
if ($ref === strtolower($name)) # found match, so redirect |
|
29 |
{ |
|
30 |
header("Location: ".strip_url($url_func($path->tail))); |
|
31 |
ob_end_flush(); |
|
32 |
print('<h4 class="progress">Loading '.$name."...</h4>\n"); |
|
33 |
exit; |
|
34 |
} |
|
35 |
} |
|
36 |
|
|
37 |
function fragment_override($url, $fragment=null) |
|
38 |
{ |
|
39 |
return function($path) use($url, $fragment) |
|
40 |
{ |
|
41 |
if (!isset($fragment)) |
|
42 |
{ |
|
43 |
$path = parse_dot_path($path); |
|
44 |
$fragment = $path->head; |
|
45 |
$path = $path->tail; |
|
46 |
} |
|
47 |
if ($path) $url .= "?".$path; |
|
48 |
return $url."#".$fragment; |
|
49 |
}; |
|
50 |
} |
|
51 |
|
|
52 |
function phpPgAdmin($url) |
|
53 |
{ |
|
54 |
return function($path) use($url) |
|
55 |
{ |
|
56 |
$path = parse_dot_path($path); |
|
57 |
if ($path->head) |
|
58 |
{ |
|
59 |
$url .= "&table=".$path->head; |
|
60 |
if ($path->tail) $url .= "&column=".$path->tail."&subject=column"; |
|
61 |
else $url .= "&subject=table"; |
|
62 |
} |
|
63 |
else $url .= "&subject=schema"; |
|
64 |
return $url; |
|
65 |
}; |
|
66 |
} |
|
67 |
|
|
68 |
function VegBank($url) |
|
69 |
{ |
|
70 |
return function($path) use($url) |
|
71 |
{ |
|
72 |
$path = parse_dot_path($path); |
|
73 |
if ($path->head) $url .= "/vegbank/views/dba_tabledescription_detail.jsp?view=detail&entity=dba_tabledescription&where=where_table$name&wparam=".$path->head."#".$path->tail; |
|
74 |
else $url .= "/get/index/dba_tabledescription"; |
|
75 |
return $url; |
|
76 |
}; |
|
77 |
} |
|
78 |
|
|
79 |
ob_start(); // delay output in case there is a redirect |
|
80 |
?> |
|
81 |
<html> |
|
82 |
<head> |
|
83 |
<title>VegRef: a URL-shortening service for vegetation references</title> |
|
84 |
<link rel="stylesheet" type="text/css" href="main.css" /> |
|
85 |
<style type="text/css"> |
|
86 |
h1 {color: green;} |
|
87 |
</style> |
|
88 |
<script type="text/javascript" src="util.js"></script> |
|
89 |
</head> |
|
90 |
<body> |
|
91 |
<h1>VegRef <small>a URL-shortening service for vegetation references</small></h1> |
|
92 |
<div>Supported URLs: <small><i>(elements can be left out successively from the end of the URL)</i></small></div> |
|
93 |
<blockquote> |
|
94 |
<?php |
|
95 |
# add and list URLs |
|
96 |
print("<h2>Terms</h2>"); |
|
97 |
{ |
|
98 |
print("<blockquote>\n"); |
|
99 |
print("<h3>Exchange schemas</h3>"); |
|
100 |
{ |
|
101 |
print("<blockquote>\n"); |
|
102 |
add_ref("VegCore", ".table.column", "https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore#"); |
|
103 |
add_ref("DwC", ".term", "http://rs.tdwg.org/dwc/terms/#"); |
|
104 |
{ |
|
105 |
print("<blockquote>\n"); $h_level++; |
|
106 |
add_ref("DwC-history", ".term", "http://rs.tdwg.org/dwc/terms/history/#"); |
|
107 |
print("</blockquote>\n"); $h_level--; |
|
108 |
} |
|
109 |
add_ref("TCS", "/XPath", "http://www.tdwg.org/standards/117/download/#/v101.xsd#"); |
|
110 |
add_ref("VegX", "/XPath", "http://wiki.tdwg.org/twiki/pub/Vegetation/WebHome/VegX_Schema_1.5.3_proposed.zip#/veg.xsd#"); |
|
111 |
print("</blockquote>\n"); |
|
112 |
} |
|
113 |
print("<h3>Aggregators</h3>"); |
|
114 |
{ |
|
115 |
print("<blockquote>\n"); |
|
116 |
add_ref("VegBank", ".table.column", VegBank("http://vegbank.org")); |
|
117 |
add_ref("SALVIAS", ".table.column", "http://salvias.net/Documents/salvias_data_dictionary.html#"); |
|
118 |
add_ref("BIEN2", ".table.column", phpPgAdmin("http://vegbiendev.nceas.ucsb.edu/phppgadmin/redirect.php?server=localhost%3A5432%3Aallow&database=vegbien&schema=public")); |
|
119 |
add_ref("VegBIEN", ".table.column", phpPgAdmin("http://vegbiendev.nceas.ucsb.edu/phppgadmin/redirect.php?server=localhost%3A5432%3Aallow&database=vegbien&schema=public")); |
|
120 |
print("</blockquote>\n"); |
|
121 |
} |
|
122 |
print("<h3>Primary databases</h3>"); |
|
123 |
{ |
|
124 |
print("<blockquote>\n"); |
|
125 |
add_ref("TNRS", ".term", fragment_override("http://tnrs.iplantcollaborative.org/instructions.html", "download_results")); |
|
126 |
print("</blockquote>\n"); |
|
127 |
} |
|
128 |
print("</blockquote>\n"); |
|
129 |
} |
|
130 |
print("<h2>Data</h2>"); |
|
131 |
{ |
|
132 |
print("<blockquote>\n"); |
|
133 |
add_ref("IH", ".herbarium_code", by_prefix("http://sweetgum.nybg.org/ih/herbarium_list.php?QueryName=DetailedQuery&Restriction=NamPartyType.%3D.'IH.Herbarium'&col_NamOrganisationAcronym=", |
|
134 |
"http://sweetgum.nybg.org/ih/")); |
|
135 |
print("</blockquote>\n"); |
|
136 |
} |
|
137 |
?> |
|
138 |
<script type="text/javascript"> |
|
139 |
var loc = document.location |
|
140 |
if (loc.hash) |
|
141 |
{ |
|
142 |
var fragment = rm_prefix('#', loc.hash) |
|
143 |
document.write('<h4 class="progress">Loading '+fragment+'...</h4>') |
|
144 |
document.location = '?'+fragment |
|
145 |
} |
|
146 |
</script> |
|
147 |
</blockquote> |
|
148 |
</body> |
|
149 |
</html> |
|
150 |
<?php |
|
151 |
ob_end_flush(); |
|
152 |
?> |
|
0 | 153 |
web/VegRef/index.htm | ||
---|---|---|
1 |
<html> |
|
2 |
<head> |
|
3 |
<title>VegRef: a URL-shortening service for vegetation references</title> |
|
4 |
<link rel="stylesheet" type="text/css" href="main.css" /> |
|
5 |
<style type="text/css"> |
|
6 |
h1 {color: green;} |
|
7 |
</style> |
|
8 |
<script type="text/javascript" src="util.js"></script> |
|
9 |
</head> |
|
10 |
<body> |
|
11 |
<h1>VegRef <small>a URL-shortening service for vegetation references</small></h1> |
|
12 |
<div>Supported URLs: <small><i>(elements can be left out successively from the end of the URL)</i></small></div> |
|
13 |
<blockquote> |
|
14 |
<script type="text/javascript"> |
|
15 |
//// add and list URLs |
|
16 |
|
|
17 |
// config |
|
18 |
var alias = 'j.mp/vegref' |
|
19 |
|
|
20 |
function by_prefix(url, main_url) |
|
21 |
{ |
|
22 |
if (!main_url) main_url = url |
|
23 |
return function(path) { return path ? url+path : main_url } |
|
24 |
} |
|
25 |
|
|
26 |
var h_level = 4 |
|
27 |
var path = parse_mixed_path(rm_prefix('#', document.location.hash)) |
|
28 |
var ref = path.head.toLowerCase() |
|
29 |
|
|
30 |
function add_ref(name, suffix, url_func) |
|
31 |
{ |
|
32 |
if (typeof url_func === 'string') url_func = by_prefix(url_func) |
|
33 |
|
|
34 |
document.write('<h'+h_level+'><code>'+alias+'#<big><a href="http://'+alias |
|
35 |
+'#'+name+'">'+name+'</a></big><i>'+suffix+'</i></code></h'+h_level+'>') |
|
36 |
if (ref === name.toLowerCase()) |
|
37 |
{ |
|
38 |
document.write('<h4 class="progress">Loading '+name+'...</h4>') |
|
39 |
document.location = strip_url(url_func(path.tail)) |
|
40 |
} |
|
41 |
} |
|
42 |
|
|
43 |
function fragment_override(url, fragment/*=path.head*/) |
|
44 |
{ |
|
45 |
return function(path) |
|
46 |
{ |
|
47 |
if (is_undef(fragment)) |
|
48 |
{ |
|
49 |
path = parse_dot_path(path) |
|
50 |
fragment = path.head |
|
51 |
path = path.tail |
|
52 |
} |
|
53 |
if (path) url += '?'+path |
|
54 |
return url+'#'+fragment |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
function phpPgAdmin(url) |
|
59 |
{ |
|
60 |
return function(path) |
|
61 |
{ |
|
62 |
path = parse_dot_path(path) |
|
63 |
if (path.head) |
|
64 |
{ |
|
65 |
url += '&table='+path.head |
|
66 |
if (path.tail) url += '&column='+path.tail+'&subject=column' |
|
67 |
else url += '&subject=table' |
|
68 |
} |
|
69 |
else url += '&subject=schema' |
|
70 |
return url |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
function VegBank(url) |
|
75 |
{ |
|
76 |
return function(path) |
|
77 |
{ |
|
78 |
path = parse_dot_path(path) |
|
79 |
if (path.head) url += '/vegbank/views/dba_tabledescription_detail.jsp?view=detail&entity=dba_tabledescription&where=where_tablename&wparam='+path.head+'#'+path.tail |
|
80 |
else url += '/get/index/dba_tabledescription' |
|
81 |
return url |
|
82 |
} |
|
83 |
} |
|
84 |
|
|
85 |
document.write('<h2>Terms</h2>') |
|
86 |
{ |
|
87 |
document.write('<blockquote>') |
|
88 |
document.write('<h3>Exchange schemas</h3>') |
|
89 |
{ |
|
90 |
document.write('<blockquote>') |
|
91 |
add_ref('VegCore', '.table.column', 'https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore#') |
|
92 |
add_ref('DwC', '.term', 'http://rs.tdwg.org/dwc/terms/#') |
|
93 |
{ |
|
94 |
document.write('<blockquote>'); h_level++ |
|
95 |
add_ref('DwC-history', '.term', 'http://rs.tdwg.org/dwc/terms/history/#') |
|
96 |
document.write('</blockquote>'); h_level-- |
|
97 |
} |
|
98 |
add_ref('TCS', '/XPath', 'http://www.tdwg.org/standards/117/download/#/v101.xsd#') |
|
99 |
add_ref('VegX', '/XPath', 'http://wiki.tdwg.org/twiki/pub/Vegetation/WebHome/VegX_Schema_1.5.3_proposed.zip#/veg.xsd#') |
|
100 |
document.write('</blockquote>') |
|
101 |
} |
|
102 |
document.write('<h3>Aggregators</h3>') |
|
103 |
{ |
|
104 |
document.write('<blockquote>') |
|
105 |
add_ref('VegBank', '.table.column', VegBank('http://vegbank.org')) |
|
106 |
add_ref('SALVIAS', '.table.column', 'http://salvias.net/Documents/salvias_data_dictionary.html#') |
|
107 |
add_ref('BIEN2', '.table.column', phpPgAdmin('http://vegbiendev.nceas.ucsb.edu/phppgadmin/redirect.php?server=localhost%3A5432%3Aallow&database=vegbien&schema=public')) |
|
108 |
add_ref('VegBIEN', '.table.column', phpPgAdmin('http://vegbiendev.nceas.ucsb.edu/phppgadmin/redirect.php?server=localhost%3A5432%3Aallow&database=vegbien&schema=public')) |
|
109 |
document.write('</blockquote>') |
|
110 |
} |
|
111 |
document.write('<h3>Primary databases</h3>') |
|
112 |
{ |
|
113 |
document.write('<blockquote>') |
|
114 |
add_ref('TNRS', '.term', fragment_override('http://tnrs.iplantcollaborative.org/instructions.html', 'download_results')) |
|
115 |
document.write('</blockquote>') |
|
116 |
} |
|
117 |
document.write('</blockquote>') |
|
118 |
} |
|
119 |
document.write('<h2>Data</h2>') |
|
120 |
{ |
|
121 |
document.write('<blockquote>') |
|
122 |
add_ref('IH', '.herbarium_code', by_prefix('http://sweetgum.nybg.org/ih/herbarium_list.php?QueryName=DetailedQuery&Restriction=NamPartyType+%3D+\'IH+Herbarium\'&col_NamOrganisationAcronym=', |
|
123 |
'http://sweetgum.nybg.org/ih/')) |
|
124 |
document.write('</blockquote>') |
|
125 |
} |
|
126 |
</script> |
|
127 |
</blockquote> |
|
128 |
</body> |
|
129 |
</html> |
|
0 | 130 |
Also available in: Unified diff
Added web/VegRef/, which provides a URL-shortening service for vegetation references. VegRef URLs are short and human-readable enough to be used as database column names. This also causes Google spreadsheets to display a clickable link for each column name, which takes the user to the data dictionary definition for the term. String row IDs (such as global IDs <https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/Global_IDs>) can also be clickable VegRef URLs.