Project

General

Profile

1
<?php
2
require_once dirname(__FILE__)."/util.php";
3

    
4
# config
5
$alias = "j.mp/vegpath";
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>VegPath: human-readable URLs for vegetation resources</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>VegPath&nbsp;&nbsp; <small>human-readable URLs for vegetation resources</small></h1>
92
		<div>Supported URLs:&nbsp;&nbsp; <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
?>
(3-3/6)