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 = 5;
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.' id="'.$name.'">'.$alias.'<big><a href="http://'.$alias
27
		.$name.'">'.$name."</a></big><i>".$suffix."</i></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
		exit;
33
	}
34
}
35

    
36
function custom_separator($url, $sep)
37
{
38
	return function($path) use($url, $sep)
39
	{
40
		$path = parse_dot_path($path);
41
		return $url.join_non_empty($sep, array($path->head, $path->tail));
42
	};
43
}
44

    
45
function fragment_override($url, $fragment=null)
46
{
47
	return function($path) use($url, $fragment)
48
	{
49
		if (!isset($fragment))
50
		{
51
			$path = parse_dot_path($path);
52
			$fragment = $path->head;
53
			$path = $path->tail;
54
		}
55
		if ($path !== "") $url .= "?".$path;
56
		return $url."#".$fragment;
57
	};
58
}
59

    
60
function phpPgAdmin($url)
61
{
62
	return function($path) use($url)
63
	{
64
		$path = parse_dot_path($path);
65
		$subject = "schema";
66
		if ($path->head !== "")
67
		{
68
			$url .= "&table=".$path->head;
69
			if ($path->tail !== "")
70
			{
71
				$url .= "&column=".$path->tail;
72
				$subject = "column";
73
			}
74
			else $subject = "table";
75
		}
76
		$url .= "&subject=".$subject;
77
		return $url;
78
	};
79
}
80

    
81
function phpMyAdmin($url)
82
{
83
	return function($path) use($url)
84
	{
85
		$path = parse_dot_path($path);
86
		$target = "db_structure";
87
		if ($path->head !== "")
88
		{
89
			$url .= "&table=".$path->head;
90
			if ($path->tail !== "") $url .= "&column=".$path->tail;
91
			$target = "tbl_structure";
92
		}
93
		$url .= "&target=".$target.".php";
94
		return $url;
95
	};
96
}
97

    
98
function VegBank($url)
99
{
100
	return function($path) use($url)
101
	{
102
		$path = parse_dot_path($path);
103
		if ($path->head !== "") $url .= "/vegbank/views/dba_tabledescription_detail.jsp?view=detail&entity=dba_tabledescription&where=where_tablename&wparam=".$path->head."#".$path->tail;
104
		else $url .= "/get/index/dba_tabledescription";
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>human-readable URLs for vegetation resources</small></h1>
122
		<div>Supported URL patterns:&nbsp;&nbsp; <small><i>(elements can be left out successively from the end of the URL)</i></small></div>
123
		<blockquote>
124
<?php
125
# add and list URLs
126
print("<h2>Terms</h2>");
127
{
128
	print("<blockquote>\n");
129
	print("<h3>Exchange schemas</h3>");
130
	{
131
		print("<blockquote>\n");
132
		add_ref("VegCore", ".table.column", "https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore#");
133
		add_ref("DwC", ".term", "http://rs.tdwg.org/dwc/terms/#");
134
		{
135
			print("<blockquote>\n"); $h_level++;
136
			add_ref("DwC-history", ".term", "http://rs.tdwg.org/dwc/terms/history/#");
137
			print("</blockquote>\n"); $h_level--;
138
		}
139
		add_ref("TCS", "/XPath", "http://www.tdwg.org/standards/117/download/#/v101.xsd#");
140
		add_ref("VegX", "/XPath", "http://wiki.tdwg.org/twiki/pub/Vegetation/WebHome/VegX_Schema_1.5.3_proposed.zip#/veg.xsd#");
141
		print("</blockquote>\n");
142
	}
143
	print("<h3>Aggregators</h3>");
144
	{
145
		print("<blockquote>\n");
146
		add_ref("VegBank", ".table.column", VegBank("http://vegbank.org"));
147
		add_ref("SALVIAS", ".table.column", "http://salvias.net/Documents/salvias_data_dictionary.html#");
148
		add_ref("BIEN2", ".table.column", phpMyAdmin("http://nimoy.nceas.ucsb.edu/phpmyadmin/index.php?db=bien_web"));
149
		add_ref("VegBIEN", ".table.column", phpPgAdmin("http://vegbiendev.nceas.ucsb.edu/phppgadmin/redirect.php?server=localhost%3A5432%3Aallow&database=vegbien&schema=public"));
150
		print("</blockquote>\n");
151
	}
152
	print("<h3>Primary databases</h3>");
153
	{
154
		print("<blockquote>\n");
155
		add_ref("TNRS", ".term", fragment_override("http://tnrs.iplantcollaborative.org/instructions.html", "download_results"));
156
		print("</blockquote>\n");
157
	}
158
	print("</blockquote>\n");
159
}
160
print("<h2>Data</h2>");
161
{
162
	print("<blockquote>\n");
163
	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=",
164
			"http://sweetgum.nybg.org/ih/"));
165
	print("</blockquote>\n");
166
}
167
?>
168
			<script type="text/javascript">
169
var loc = document.location
170
if (loc.hash)
171
{
172
	var fragment = rm_prefix('#', loc.hash)
173
	var namespace = parse_dot_path(fragment).head
174
	document.getElementById(namespace).className = 'progress'
175
	document.location = fragment
176
}
177
			</script>
178
		</blockquote>
179
	</body>
180
</html>
181
<?php
182
ob_end_flush();
183
?>
(2-2/5)