Project

General

Profile

« Previous | Next » 

Revision 7990

web/vegpath/: Renamed to web/main/ because the content here is the main site hosted on vegbiendev. It will eventually contain internal links to VegBIEN resources in addition to external links (persistent URLs) to sources used in creating VegBIEN.

View differences:

web/vegpath/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) }
web/vegpath/.htaccess
1
#### URL resolution
2

  
3
DirectorySlash on
4
DirectoryIndex index.php
5

  
6
### mod_rewrite
7

  
8
RewriteEngine on
9
RewriteBase /
10

  
11
# remove www subdomain
12
RewriteCond %{HTTP_HOST} ^www\.(.*)$
13
RewriteRule ^.*$ http://%1/$0 [redirect]
14

  
15
# translate subdomain to path
16
RewriteCond expr "%{HTTP_HOST} != %{SERVER_NAME}"
17
RewriteCond %{HTTP_HOST} ^(.*)(\.[^.]*){2}$
18
RewriteCond ${subdomain2path:%1} ^([^/]*).*$
19
RewriteCond expr "! $0 -fnmatch '%1*'"
20
RewriteRule ^.*$ %0/$0 [last]
21

  
22
# translate dot-paths to dirs
23
RewriteCond %{DOCUMENT_ROOT}/$1 -d [ornext]
24
RewriteCond %{DOCUMENT_ROOT}/$1 -l
25
RewriteRule ^([^.]*)\.(.*)$ $1/$2 [next]
26
	# next: if match, repeat until no more replacements
27

  
28
# non-filesystem paths
29
ErrorDocument 404 /
web/vegpath/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 {text-decoration: blink;}
7

  
8
h2, h3, h4, h5, h6, blockquote {margin-bottom: 3pt;}
9
h3, h4 {margin-top: 8pt;}
10
blockquote, h5, h6 {margin-top: 4pt;}
11
.indent {padding-left: 2em;}
web/vegpath/index.php
1
<?php
2
require_once dirname(__FILE__)."/util.php";
3

  
4
$self_dir = ensure_suffix("/", dirname($_SERVER["SCRIPT_NAME"]));
5

  
6
# config
7
$alias = "j.mp/vegpath#";
8

  
9
function by_prefix($url, $main_url=null)
10
{
11
	if (!isset($main_url)) $main_url = $url;
12
	
13
	return function($path) use($url, $main_url)
14
	{
15
		return $path ? $url.$path : $main_url;
16
	};
17
}
18

  
19
$h_level = 5;
20
$root = $_SERVER["HTTP_HOST"] === $_SERVER["SERVER_NAME"]
21
	? $alias : $_SERVER["HTTP_HOST"].$self_dir;
22
# instead of PATH_INFO, to support the Apache ErrorDocument directive
23
$rel_fs_path = rm_prefix($self_dir, $_SERVER["REQUEST_URI"]);
24
$path = parse_dot_path($rel_fs_path);
25
$ns = strtolower($path->head);
26

  
27
function add_ns($name, $path_pat, $url_func)
28
{
29
	global $root, $h_level, $path, $ns;
30
	if (is_string($url_func)) $url_func = by_prefix($url_func);
31
	
32
	print("<h".$h_level.' id="'.$name.'">'.$root.'<big><a href="http://'.$root
33
		.$name.'">'.$name."</a></big><i>".$path_pat."</i></h".$h_level.">\n");
34
	if ($ns === strtolower($name)) # found match, so redirect
35
	{
36
		header("Location: ".strip_url($url_func($path->tail)));
37
		ob_end_flush();
38
		exit;
39
	}
40
}
41

  
42
function custom_separator($url, $sep, $main_url=null)
43
{
44
	if (!isset($main_url)) $main_url = $url;
45
	
46
	return function($path) use($url, $sep, $main_url)
47
	{
48
		if ($path === "") return $main_url;
49
		$path = parse_dot_path($path);
50
		return $url.join_non_empty($sep, array($path->head, $path->tail));
51
	};
52
}
53

  
54
function fragment_override($url, $fragment=null)
55
{
56
	return function($path) use($url, $fragment)
57
	{
58
		if (!isset($fragment))
59
		{
60
			$path = parse_dot_path($path);
61
			$fragment = $path->head;
62
			$path = $path->tail;
63
		}
64
		if ($path !== "") $url .= "?".$path;
65
		return $url."#".$fragment;
66
	};
67
}
68

  
69
function phpPgAdmin($url, $table=null)
70
{
71
	return function($path) use($url, $table)
72
	{
73
		$path = join_non_empty(".", array($table, $path));
74
		$path = parse_dot_path($path);
75
		$subject = "schema";
76
		if ($path->head !== "")
77
		{
78
			$url .= "&table=".$path->head;
79
			if ($path->tail !== "")
80
			{
81
				$url .= "&column=".$path->tail;
82
				$subject = "column";
83
			}
84
			else $subject = "table";
85
		}
86
		$url .= "&subject=".$subject;
87
		return $url;
88
	};
89
}
90

  
91
function phpMyAdmin($url, $table=null)
92
{
93
	return function($path) use($url, $table)
94
	{
95
		$path = join_non_empty(".", array($table, $path));
96
		$path = parse_dot_path($path);
97
		$target = "db_structure";
98
		if ($path->head !== "")
99
		{
100
			$url .= "&table=".$path->head;
101
			if ($path->tail !== "") $url .= "&column=".$path->tail;
102
			$target = "tbl_structure";
103
		}
104
		$url .= "&target=".$target.".php";
105
		return $url;
106
	};
107
}
108

  
109
ob_start(); // delay output in case there is a redirect
110
?>
111
<html>
112
	<head>
113
		<title>VegPath</title>
114
		<link rel="stylesheet" type="text/css" href="main.css" />
115
		<style type="text/css">
116
h1 {color: green;}
117
		</style>
118
		<script type="text/javascript" src="util.js"></script>
119
	</head>
120
	<body>
121
		<h1>VegPath&nbsp;&nbsp; <small><a href="http://en.wikipedia.org/wiki/PURL">persistent URLs</a> for vegetation resources</small></h1>
122
		<div>Supported URL patterns:&nbsp;&nbsp; <small>(elements in <i>italics</i> are optional)</small></div>
123
		<p></p>
124
<?php
125
# add and list URLs
126

  
127
$Redmine = "https://projects.nceas.ucsb.edu/nceas/projects/bien";
128
$Redmine_svn = $Redmine."/repository/raw";
129

  
130
$nimoy = "http://nimoy.nceas.ucsb.edu/phpmyadmin/index.php";
131
function nimoy_db($db) { global $nimoy; return phpMyAdmin($nimoy."?db=".$db); }
132

  
133
$IH_db = phpMyAdmin($nimoy."?db=bien3_adb", "ih");
134

  
135
$SALVIAS = "http://salvias.net/Documents/salvias_data_dictionary.html";
136
?>
137
		<table border="0" cellspacing="0" cellpadding="0">
138
			<tr valign="top">
139
				<td nowrap="nowrap"><h2>Terms</h2></td>
140
				<td nowrap="nowrap"><h2>Data</h2></td>
141
			</tr>
142
			<tr valign="top">
143
				<td nowrap="nowrap">
144
<?php
145
print("<blockquote>\n");
146
print("<h3>Exchange schemas</h3>");
147
{
148
	print("<blockquote>\n");
149
	add_ns("VegCore", ".term", "https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore#");
150
	add_ns("DwC", ".term", "http://rs.tdwg.org/dwc/terms/#");
151
	{
152
		print("<blockquote>\n"); $h_level++;
153
		add_ns("DwC-history", ".term", "http://rs.tdwg.org/dwc/terms/history/#");
154
		print("</blockquote>\n"); $h_level--;
155
	}
156
	add_ns("TCS", "#/XPath", "http://www.tdwg.org/standards/117/download/#/v101.xsd");
157
	add_ns("VegX", "#/XPath", "http://wiki.tdwg.org/twiki/pub/Vegetation/WebHome/VegX_Schema_1.5.3_proposed.zip#/veg.xsd");
158
	print("</blockquote>\n");
159
}
160
print("<h3>Aggregators</h3>");
161
{
162
	print("<blockquote>\n");
163
	add_ns("VegBank", ".table.column", custom_separator("http://vegbank.org/vegbank/views/dba_tabledescription_detail.jsp?view=detail&entity=dba_tabledescription&where=where_tablename&wparam=",
164
		"#", "http://vegbank.org/get/index/dba_tabledescription"));
165
	add_ns("SALVIAS", ".table.column", by_prefix($SALVIAS."#Plot_", $SALVIAS));
166
	{
167
		print("<blockquote>\n"); $h_level++;
168
		add_ns("SALVIAS-db", ".table.column", nimoy_db("salvias_plots"));
169
		add_ns("SALVIAS-users", ".table.column", nimoy_db("salvias_users"));
170
		print("</blockquote>\n"); $h_level--;
171
	}
172
	add_ns("BIEN2", "", $nimoy."?target=server_databases.php");
173
	{
174
		print("<blockquote>\n"); $h_level++;
175
		add_ns("BIEN2-web", ".table.column", nimoy_db("bien_web"));
176
		add_ns("BIEN2-core", ".table.column", nimoy_db("bien2"));
177
		add_ns("BIEN2-geoscrub", ".table.column", nimoy_db("geoscrub"));
178
		add_ns("BIEN2-staging", ".table.column", nimoy_db("bien2_staging"));
179
		print("</blockquote>\n"); $h_level--;
180
	}
181
	add_ns("VegBIEN", ".table.column", phpPgAdmin("http://vegbiendev.nceas.ucsb.edu/phppgadmin/redirect.php?server=localhost%3A5432%3Aallow&database=vegbien&schema=public"));
182
	print("</blockquote>\n");
183
}
184
print("<h3>Primary databases</h3>");
185
{
186
	print("<blockquote>\n");
187
	add_ns("TNRS", ".term", fragment_override("http://tnrs.iplantcollaborative.org/instructions.html", "download_results"));
188
	add_ns("CTFS", "", $Redmine."/wiki/CTFS");
189
	{
190
		print("<blockquote>\n"); $h_level++;
191
		add_ns("CTFS-schema", ".table.column", $Redmine_svn."/inputs/CTFS/_archive/DBv5.txt#");
192
		add_ns("CTFS-tables", ".table", fragment_override($Redmine."/wiki/CTFS", "Tables"));
193
		add_ns("CTFS-terms", ".term", $Redmine_svn."/inputs/CTFS/_src/ctfs-comments_worksheet.xls#");
194
		print("</blockquote>\n"); $h_level--;
195
	}
196
	add_ns("IH-db", ".term", $IH_db);
197
	print("</blockquote>\n");
198
}
199
print("<h3>People</h3>");
200
{
201
	print("<blockquote>\n");
202
	add_ns("Brad-Boyle", "", "mailto:bboyleATemail.arizona.edu");
203
	{
204
		print("<blockquote>\n"); $h_level++;
205
		$Brad_Boyle_VegCore = $Redmine_svn."/schemas/VegCore/Brad_Boyle";
206
		add_ns("Brad-Boyle-data-provenance", ".term", $Brad_Boyle_VegCore."/BIEN%20database%20entities%20related%20to%20data%20provenance%20and%20ownership.docx#");
207
		add_ns("Brad-Boyle-DwC-IDs-2013-2-7", ".term", $Brad_Boyle_VegCore."/vegbien_identifiers.xlsx#");
208
		add_ns("Brad-Boyle-DwC-IDs-2013-1-31", ".term", $Brad_Boyle_VegCore."/vegbien_identifier_examples.xlsx#");
209
		print("</blockquote>\n"); $h_level--;
210
	}
211
	print("</blockquote>\n");
212
}
213
print("</blockquote>\n");
214
?>
215
				</td>
216
				<td nowrap="nowrap">
217
<?php
218
print("<blockquote>\n");
219
print("<h3>Institutions</h3>");
220
{
221
	print("<blockquote>\n");
222
	add_ns("IH", ".herbarium_code", by_prefix("http://sweetgum.nybg.org/ih/herbarium_list.php?QueryName=DetailedQuery&Restriction=NamPartyType+%3D+%27IH+Herbarium%27&col_NamOrganisationAcronym=",
223
		"http://sweetgum.nybg.org/ih/"));
224
	print("</blockquote>\n");
225
}
226
print("</blockquote>\n");
227
?>
228
				</td>
229
			</tr>
230
		</table>
231
<?php
232
if (ends_with($root, '#')) # URL shortener requires fragment redirect
233
{
234
?>
235
		<script type="text/javascript">
236
var loc = document.location
237
if (loc.hash) document.location = rm_prefix('#', loc.hash)
238
		</script>
239
<?php
240
}
241
?>
242
	</body>
243
</html>
244
<?php
245
ob_end_flush();
246
?>
web/vegpath/_archive/index.htm
1
<html>
2
	<head>
3
		<title>VegPath</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>VegPath&nbsp;&nbsp; <small>human-readable URLs for vegetation resources</small></h1>
12
		<div>Supported URL patterns:&nbsp;&nbsp; <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/vegpath'
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 phpMyAdmin(url)
75
{
76
	return function(path)
77
	{
78
		path = parse_dot_path(path)
79
		if (path.head)
80
		{
81
			url += '&table='+path.head
82
			if (path.tail) url += '&column='+path.tail+'&subject=column'
83
			else url += '&subject=table'
84
		}
85
		else url += '&subject=schema'
86
		return url
87
	}
88
}
89

  
90
function VegBank(url)
91
{
92
	return function(path)
93
	{
94
		path = parse_dot_path(path)
95
		if (path.head) url += '/vegbank/views/dba_tabledescription_detail.jsp?view=detail&entity=dba_tabledescription&where=where_tablename&wparam='+path.head+'#'+path.tail
96
		else url += '/get/index/dba_tabledescription'
97
		return url
98
	}
99
}
100

  
101
document.write('<h2>Terms</h2>')
102
{
103
	document.write('<blockquote>')
104
	document.write('<h3>Exchange schemas</h3>')
105
	{
106
		document.write('<blockquote>')
107
		add_ref('VegCore', '.table.column', 'https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore#')
108
		add_ref('DwC', '.term', 'http://rs.tdwg.org/dwc/terms/#')
109
		{
110
			document.write('<blockquote>'); h_level++
111
			add_ref('DwC-history', '.term', 'http://rs.tdwg.org/dwc/terms/history/#')
112
			document.write('</blockquote>'); h_level--
113
		}
114
		add_ref('TCS', '/XPath', 'http://www.tdwg.org/standards/117/download/#/v101.xsd#')
115
		add_ref('VegX', '/XPath', 'http://wiki.tdwg.org/twiki/pub/Vegetation/WebHome/VegX_Schema_1.5.3_proposed.zip#/veg.xsd#')
116
		document.write('</blockquote>')
117
	}
118
	document.write('<h3>Aggregators</h3>')
119
	{
120
		document.write('<blockquote>')
121
		add_ref('VegBank', '.table.column', VegBank('http://vegbank.org'))
122
		add_ref('SALVIAS', '.table.column', 'http://salvias.net/Documents/salvias_data_dictionary.html#')
123
		add_ref('BIEN2', '.table.column', phpPgAdmin('http://vegbiendev.nceas.ucsb.edu/phppgadmin/redirect.php?server=localhost%3A5432%3Aallow&database=vegbien&schema=public'))
124
		add_ref('VegBIEN', '.table.column', phpPgAdmin('http://vegbiendev.nceas.ucsb.edu/phppgadmin/redirect.php?server=localhost%3A5432%3Aallow&database=vegbien&schema=public'))
125
		document.write('</blockquote>')
126
	}
127
	document.write('<h3>Primary databases</h3>')
128
	{
129
		document.write('<blockquote>')
130
		add_ref('TNRS', '.term', fragment_override('http://tnrs.iplantcollaborative.org/instructions.html', 'download_results'))
131
		document.write('</blockquote>')
132
	}
133
	document.write('</blockquote>')
134
}
135
document.write('<h2>Data</h2>')
136
{
137
	document.write('<blockquote>')
138
	add_ref('IH', '.herbarium_code', by_prefix('http://sweetgum.nybg.org/ih/herbarium_list.php?QueryName=DetailedQuery&Restriction=NamPartyType+%3D+%27IH+Herbarium%27&col_NamOrganisationAcronym=',
139
			'http://sweetgum.nybg.org/ih/'))
140
	document.write('</blockquote>')
141
}
142
			</script>
143
		</blockquote>
144
	</body>
145
</html>
146 0

  
web/vegpath/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
function ensure_prefix($prefix, $str)
24
{
25
	return starts_with($str, $prefix) ? $str : $prefix.$str;
26
}
27

  
28
function ensure_suffix($suffix, $str)
29
{
30
	return ends_with($str, $suffix) ? $str : $str.$suffix;
31
}
32

  
33
class Path
34
{
35
	public $head;
36
	public $tail;
37
	
38
	function Path($head, $tail="")
39
	{
40
		$this->head = $head;
41
		$this->tail = $tail;
42
	}
43
}
44

  
45
function partition($str, $delim)
46
{
47
	$delim_idx = strpos($str, $delim);
48
	return $delim_idx !== false ? new Path(substr($str, 0, $delim_idx),
49
		substr($str, $delim_idx+strlen($delim))) : new Path($str);
50
}
51

  
52
function array_non_empty($array)
53
{
54
	foreach ($array as $key => $value)
55
		if (!isset($value) || $value === "") unset($array[$key]);
56
	return $array;
57
}
58

  
59
function join_non_empty($delim, $array)
60
{
61
	return implode($delim, array_non_empty($array));
62
}
63

  
64
function parse_dot_path($path) { return partition($path, "."); }
65

  
66
function parse_mixed_path($path)
67
{
68
	preg_match('/^([\w-]*)(.*)$/', $path, $path);
69
	return new Path($path[1], rm_prefix(".", $path[2]));
70
}
71

  
72
function strip_url($url) { return rm_suffix("#", $url); }
73
?>
web/vegpath.conf
1
<VirtualHost *:80>
2
	ServerRoot /home/bien/svn/web
3
	ServerAdmin aaronmk@nceas.ucsb.edu
4
	
5
	RewriteEngine on
6
	RewriteMap subdomain2path prg:subdomain2path
7
	
8
	DocumentRoot vegpath
9
	<Directory vegpath>
10
		AllowOverride all
11
	</Directory>
12
	
13
	ErrorLog logs/error_log
14
	CustomLog logs/access_log combined
15
</VirtualHost>
web/main/.htaccess
1
#### URL resolution
2

  
3
DirectorySlash on
4
DirectoryIndex index.php
5

  
6
### mod_rewrite
7

  
8
RewriteEngine on
9
RewriteBase /
10

  
11
# remove www subdomain
12
RewriteCond %{HTTP_HOST} ^www\.(.*)$
13
RewriteRule ^.*$ http://%1/$0 [redirect]
14

  
15
# translate subdomain to path
16
RewriteCond expr "%{HTTP_HOST} != %{SERVER_NAME}"
17
RewriteCond %{HTTP_HOST} ^(.*)(\.[^.]*){2}$
18
RewriteCond ${subdomain2path:%1} ^([^/]*).*$
19
RewriteCond expr "! $0 -fnmatch '%1*'"
20
RewriteRule ^.*$ %0/$0 [last]
21

  
22
# translate dot-paths to dirs
23
RewriteCond %{DOCUMENT_ROOT}/$1 -d [ornext]
24
RewriteCond %{DOCUMENT_ROOT}/$1 -l
25
RewriteRule ^([^.]*)\.(.*)$ $1/$2 [next]
26
	# next: if match, repeat until no more replacements
27

  
28
# non-filesystem paths
29
ErrorDocument 404 /
web/main/index.php
1
<?php
2
require_once dirname(__FILE__)."/util.php";
3

  
4
$self_dir = ensure_suffix("/", dirname($_SERVER["SCRIPT_NAME"]));
5

  
6
# config
7
$alias = "j.mp/vegpath#";
8

  
9
function by_prefix($url, $main_url=null)
10
{
11
	if (!isset($main_url)) $main_url = $url;
12
	
13
	return function($path) use($url, $main_url)
14
	{
15
		return $path ? $url.$path : $main_url;
16
	};
17
}
18

  
19
$h_level = 5;
20
$root = $_SERVER["HTTP_HOST"] === $_SERVER["SERVER_NAME"]
21
	? $alias : $_SERVER["HTTP_HOST"].$self_dir;
22
# instead of PATH_INFO, to support the Apache ErrorDocument directive
23
$rel_fs_path = rm_prefix($self_dir, $_SERVER["REQUEST_URI"]);
24
$path = parse_dot_path($rel_fs_path);
25
$ns = strtolower($path->head);
26

  
27
function add_ns($name, $path_pat, $url_func)
28
{
29
	global $root, $h_level, $path, $ns;
30
	if (is_string($url_func)) $url_func = by_prefix($url_func);
31
	
32
	print("<h".$h_level.' id="'.$name.'">'.$root.'<big><a href="http://'.$root
33
		.$name.'">'.$name."</a></big><i>".$path_pat."</i></h".$h_level.">\n");
34
	if ($ns === strtolower($name)) # found match, so redirect
35
	{
36
		header("Location: ".strip_url($url_func($path->tail)));
37
		ob_end_flush();
38
		exit;
39
	}
40
}
41

  
42
function custom_separator($url, $sep, $main_url=null)
43
{
44
	if (!isset($main_url)) $main_url = $url;
45
	
46
	return function($path) use($url, $sep, $main_url)
47
	{
48
		if ($path === "") return $main_url;
49
		$path = parse_dot_path($path);
50
		return $url.join_non_empty($sep, array($path->head, $path->tail));
51
	};
52
}
53

  
54
function fragment_override($url, $fragment=null)
55
{
56
	return function($path) use($url, $fragment)
57
	{
58
		if (!isset($fragment))
59
		{
60
			$path = parse_dot_path($path);
61
			$fragment = $path->head;
62
			$path = $path->tail;
63
		}
64
		if ($path !== "") $url .= "?".$path;
65
		return $url."#".$fragment;
66
	};
67
}
68

  
69
function phpPgAdmin($url, $table=null)
70
{
71
	return function($path) use($url, $table)
72
	{
73
		$path = join_non_empty(".", array($table, $path));
74
		$path = parse_dot_path($path);
75
		$subject = "schema";
76
		if ($path->head !== "")
77
		{
78
			$url .= "&table=".$path->head;
79
			if ($path->tail !== "")
80
			{
81
				$url .= "&column=".$path->tail;
82
				$subject = "column";
83
			}
84
			else $subject = "table";
85
		}
86
		$url .= "&subject=".$subject;
87
		return $url;
88
	};
89
}
90

  
91
function phpMyAdmin($url, $table=null)
92
{
93
	return function($path) use($url, $table)
94
	{
95
		$path = join_non_empty(".", array($table, $path));
96
		$path = parse_dot_path($path);
97
		$target = "db_structure";
98
		if ($path->head !== "")
99
		{
100
			$url .= "&table=".$path->head;
101
			if ($path->tail !== "") $url .= "&column=".$path->tail;
102
			$target = "tbl_structure";
103
		}
104
		$url .= "&target=".$target.".php";
105
		return $url;
106
	};
107
}
108

  
109
ob_start(); // delay output in case there is a redirect
110
?>
111
<html>
112
	<head>
113
		<title>VegPath</title>
114
		<link rel="stylesheet" type="text/css" href="main.css" />
115
		<style type="text/css">
116
h1 {color: green;}
117
		</style>
118
		<script type="text/javascript" src="util.js"></script>
119
	</head>
120
	<body>
121
		<h1>VegPath&nbsp;&nbsp; <small><a href="http://en.wikipedia.org/wiki/PURL">persistent URLs</a> for vegetation resources</small></h1>
122
		<div>Supported URL patterns:&nbsp;&nbsp; <small>(elements in <i>italics</i> are optional)</small></div>
123
		<p></p>
124
<?php
125
# add and list URLs
126

  
127
$Redmine = "https://projects.nceas.ucsb.edu/nceas/projects/bien";
128
$Redmine_svn = $Redmine."/repository/raw";
129

  
130
$nimoy = "http://nimoy.nceas.ucsb.edu/phpmyadmin/index.php";
131
function nimoy_db($db) { global $nimoy; return phpMyAdmin($nimoy."?db=".$db); }
132

  
133
$IH_db = phpMyAdmin($nimoy."?db=bien3_adb", "ih");
134

  
135
$SALVIAS = "http://salvias.net/Documents/salvias_data_dictionary.html";
136
?>
137
		<table border="0" cellspacing="0" cellpadding="0">
138
			<tr valign="top">
139
				<td nowrap="nowrap"><h2>Terms</h2></td>
140
				<td nowrap="nowrap"><h2>Data</h2></td>
141
			</tr>
142
			<tr valign="top">
143
				<td nowrap="nowrap">
144
<?php
145
print("<blockquote>\n");
146
print("<h3>Exchange schemas</h3>");
147
{
148
	print("<blockquote>\n");
149
	add_ns("VegCore", ".term", "https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore#");
150
	add_ns("DwC", ".term", "http://rs.tdwg.org/dwc/terms/#");
151
	{
152
		print("<blockquote>\n"); $h_level++;
153
		add_ns("DwC-history", ".term", "http://rs.tdwg.org/dwc/terms/history/#");
154
		print("</blockquote>\n"); $h_level--;
155
	}
156
	add_ns("TCS", "#/XPath", "http://www.tdwg.org/standards/117/download/#/v101.xsd");
157
	add_ns("VegX", "#/XPath", "http://wiki.tdwg.org/twiki/pub/Vegetation/WebHome/VegX_Schema_1.5.3_proposed.zip#/veg.xsd");
158
	print("</blockquote>\n");
159
}
160
print("<h3>Aggregators</h3>");
161
{
162
	print("<blockquote>\n");
163
	add_ns("VegBank", ".table.column", custom_separator("http://vegbank.org/vegbank/views/dba_tabledescription_detail.jsp?view=detail&entity=dba_tabledescription&where=where_tablename&wparam=",
164
		"#", "http://vegbank.org/get/index/dba_tabledescription"));
165
	add_ns("SALVIAS", ".table.column", by_prefix($SALVIAS."#Plot_", $SALVIAS));
166
	{
167
		print("<blockquote>\n"); $h_level++;
168
		add_ns("SALVIAS-db", ".table.column", nimoy_db("salvias_plots"));
169
		add_ns("SALVIAS-users", ".table.column", nimoy_db("salvias_users"));
170
		print("</blockquote>\n"); $h_level--;
171
	}
172
	add_ns("BIEN2", "", $nimoy."?target=server_databases.php");
173
	{
174
		print("<blockquote>\n"); $h_level++;
175
		add_ns("BIEN2-web", ".table.column", nimoy_db("bien_web"));
176
		add_ns("BIEN2-core", ".table.column", nimoy_db("bien2"));
177
		add_ns("BIEN2-geoscrub", ".table.column", nimoy_db("geoscrub"));
178
		add_ns("BIEN2-staging", ".table.column", nimoy_db("bien2_staging"));
179
		print("</blockquote>\n"); $h_level--;
180
	}
181
	add_ns("VegBIEN", ".table.column", phpPgAdmin("http://vegbiendev.nceas.ucsb.edu/phppgadmin/redirect.php?server=localhost%3A5432%3Aallow&database=vegbien&schema=public"));
182
	print("</blockquote>\n");
183
}
184
print("<h3>Primary databases</h3>");
185
{
186
	print("<blockquote>\n");
187
	add_ns("TNRS", ".term", fragment_override("http://tnrs.iplantcollaborative.org/instructions.html", "download_results"));
188
	add_ns("CTFS", "", $Redmine."/wiki/CTFS");
189
	{
190
		print("<blockquote>\n"); $h_level++;
191
		add_ns("CTFS-schema", ".table.column", $Redmine_svn."/inputs/CTFS/_archive/DBv5.txt#");
192
		add_ns("CTFS-tables", ".table", fragment_override($Redmine."/wiki/CTFS", "Tables"));
193
		add_ns("CTFS-terms", ".term", $Redmine_svn."/inputs/CTFS/_src/ctfs-comments_worksheet.xls#");
194
		print("</blockquote>\n"); $h_level--;
195
	}
196
	add_ns("IH-db", ".term", $IH_db);
197
	print("</blockquote>\n");
198
}
199
print("<h3>People</h3>");
200
{
201
	print("<blockquote>\n");
202
	add_ns("Brad-Boyle", "", "mailto:bboyleATemail.arizona.edu");
203
	{
204
		print("<blockquote>\n"); $h_level++;
205
		$Brad_Boyle_VegCore = $Redmine_svn."/schemas/VegCore/Brad_Boyle";
206
		add_ns("Brad-Boyle-data-provenance", ".term", $Brad_Boyle_VegCore."/BIEN%20database%20entities%20related%20to%20data%20provenance%20and%20ownership.docx#");
207
		add_ns("Brad-Boyle-DwC-IDs-2013-2-7", ".term", $Brad_Boyle_VegCore."/vegbien_identifiers.xlsx#");
208
		add_ns("Brad-Boyle-DwC-IDs-2013-1-31", ".term", $Brad_Boyle_VegCore."/vegbien_identifier_examples.xlsx#");
209
		print("</blockquote>\n"); $h_level--;
210
	}
211
	print("</blockquote>\n");
212
}
213
print("</blockquote>\n");
214
?>
215
				</td>
216
				<td nowrap="nowrap">
217
<?php
218
print("<blockquote>\n");
219
print("<h3>Institutions</h3>");
220
{
221
	print("<blockquote>\n");
222
	add_ns("IH", ".herbarium_code", by_prefix("http://sweetgum.nybg.org/ih/herbarium_list.php?QueryName=DetailedQuery&Restriction=NamPartyType+%3D+%27IH+Herbarium%27&col_NamOrganisationAcronym=",
223
		"http://sweetgum.nybg.org/ih/"));
224
	print("</blockquote>\n");
225
}
226
print("</blockquote>\n");
227
?>
228
				</td>
229
			</tr>
230
		</table>
231
<?php
232
if (ends_with($root, '#')) # URL shortener requires fragment redirect
233
{
234
?>
235
		<script type="text/javascript">
236
var loc = document.location
237
if (loc.hash) document.location = rm_prefix('#', loc.hash)
238
		</script>
239
<?php
240
}
241
?>
242
	</body>
243
</html>
244
<?php
245
ob_end_flush();
246
?>
web/main/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
function ensure_prefix($prefix, $str)
24
{
25
	return starts_with($str, $prefix) ? $str : $prefix.$str;
26
}
27

  
28
function ensure_suffix($suffix, $str)
29
{
30
	return ends_with($str, $suffix) ? $str : $str.$suffix;
31
}
32

  
33
class Path
34
{
35
	public $head;
36
	public $tail;
37
	
38
	function Path($head, $tail="")
39
	{
40
		$this->head = $head;
41
		$this->tail = $tail;
42
	}
43
}
44

  
45
function partition($str, $delim)
46
{
47
	$delim_idx = strpos($str, $delim);
48
	return $delim_idx !== false ? new Path(substr($str, 0, $delim_idx),
49
		substr($str, $delim_idx+strlen($delim))) : new Path($str);
50
}
51

  
52
function array_non_empty($array)
53
{
54
	foreach ($array as $key => $value)
55
		if (!isset($value) || $value === "") unset($array[$key]);
56
	return $array;
57
}
58

  
59
function join_non_empty($delim, $array)
60
{
61
	return implode($delim, array_non_empty($array));
62
}
63

  
64
function parse_dot_path($path) { return partition($path, "."); }
65

  
66
function parse_mixed_path($path)
67
{
68
	preg_match('/^([\w-]*)(.*)$/', $path, $path);
69
	return new Path($path[1], rm_prefix(".", $path[2]));
70
}
71

  
72
function strip_url($url) { return rm_suffix("#", $url); }
73
?>
web/main/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) }
web/main/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 {text-decoration: blink;}
7

  
8
h2, h3, h4, h5, h6, blockquote {margin-bottom: 3pt;}
9
h3, h4 {margin-top: 8pt;}
10
blockquote, h5, h6 {margin-top: 4pt;}
11
.indent {padding-left: 2em;}
web/main/_archive/index.htm
1
<html>
2
	<head>
3
		<title>VegPath</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>VegPath&nbsp;&nbsp; <small>human-readable URLs for vegetation resources</small></h1>
12
		<div>Supported URL patterns:&nbsp;&nbsp; <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/vegpath'
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 phpMyAdmin(url)
75
{
76
	return function(path)
77
	{
78
		path = parse_dot_path(path)
79
		if (path.head)
80
		{
81
			url += '&table='+path.head
82
			if (path.tail) url += '&column='+path.tail+'&subject=column'
83
			else url += '&subject=table'
84
		}
85
		else url += '&subject=schema'
86
		return url
87
	}
88
}
89

  
90
function VegBank(url)
91
{
92
	return function(path)
93
	{
94
		path = parse_dot_path(path)
95
		if (path.head) url += '/vegbank/views/dba_tabledescription_detail.jsp?view=detail&entity=dba_tabledescription&where=where_tablename&wparam='+path.head+'#'+path.tail
96
		else url += '/get/index/dba_tabledescription'
97
		return url
98
	}
99
}
100

  
101
document.write('<h2>Terms</h2>')
102
{
103
	document.write('<blockquote>')
104
	document.write('<h3>Exchange schemas</h3>')
105
	{
106
		document.write('<blockquote>')
107
		add_ref('VegCore', '.table.column', 'https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore#')
108
		add_ref('DwC', '.term', 'http://rs.tdwg.org/dwc/terms/#')
109
		{
110
			document.write('<blockquote>'); h_level++
111
			add_ref('DwC-history', '.term', 'http://rs.tdwg.org/dwc/terms/history/#')
112
			document.write('</blockquote>'); h_level--
113
		}
114
		add_ref('TCS', '/XPath', 'http://www.tdwg.org/standards/117/download/#/v101.xsd#')
115
		add_ref('VegX', '/XPath', 'http://wiki.tdwg.org/twiki/pub/Vegetation/WebHome/VegX_Schema_1.5.3_proposed.zip#/veg.xsd#')
116
		document.write('</blockquote>')
117
	}
118
	document.write('<h3>Aggregators</h3>')
119
	{
120
		document.write('<blockquote>')
121
		add_ref('VegBank', '.table.column', VegBank('http://vegbank.org'))
122
		add_ref('SALVIAS', '.table.column', 'http://salvias.net/Documents/salvias_data_dictionary.html#')
123
		add_ref('BIEN2', '.table.column', phpPgAdmin('http://vegbiendev.nceas.ucsb.edu/phppgadmin/redirect.php?server=localhost%3A5432%3Aallow&database=vegbien&schema=public'))
124
		add_ref('VegBIEN', '.table.column', phpPgAdmin('http://vegbiendev.nceas.ucsb.edu/phppgadmin/redirect.php?server=localhost%3A5432%3Aallow&database=vegbien&schema=public'))
125
		document.write('</blockquote>')
126
	}
127
	document.write('<h3>Primary databases</h3>')
128
	{
129
		document.write('<blockquote>')
130
		add_ref('TNRS', '.term', fragment_override('http://tnrs.iplantcollaborative.org/instructions.html', 'download_results'))
131
		document.write('</blockquote>')
132
	}
133
	document.write('</blockquote>')
134
}
135
document.write('<h2>Data</h2>')
136
{
137
	document.write('<blockquote>')
138
	add_ref('IH', '.herbarium_code', by_prefix('http://sweetgum.nybg.org/ih/herbarium_list.php?QueryName=DetailedQuery&Restriction=NamPartyType+%3D+%27IH+Herbarium%27&col_NamOrganisationAcronym=',
139
			'http://sweetgum.nybg.org/ih/'))
140
	document.write('</blockquote>')
141
}
142
			</script>
143
		</blockquote>
144
	</body>
145
</html>
0 146

  
web/main.conf
1
<VirtualHost *:80>
2
	ServerRoot /home/bien/svn/web
3
	ServerAdmin aaronmk@nceas.ucsb.edu
4
	
5
	RewriteEngine on
6
	RewriteMap subdomain2path prg:subdomain2path
7
	
8
	DocumentRoot main
9
	<Directory main>
10
		AllowOverride all
11
	</Directory>
12
	
13
	ErrorLog logs/error_log
14
	CustomLog logs/access_log combined
15
</VirtualHost>

Also available in: Unified diff