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, $main_url)
37
{
38
	if (!isset($main_url)) $main_url = $url;
39
	
40
	return function($path) use($url, $sep, $main_url)
41
	{
42
		if ($path === "") return $main_url;
43
		$path = parse_dot_path($path);
44
		return $url.join_non_empty($sep, array($path->head, $path->tail));
45
	};
46
}
47

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

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

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

    
101
ob_start(); // delay output in case there is a redirect
102
?>
103
<html>
104
	<head>
105
		<title>VegPath</title>
106
		<link rel="stylesheet" type="text/css" href="main.css" />
107
		<style type="text/css">
108
h1 {color: green;}
109
		</style>
110
		<script type="text/javascript" src="util.js"></script>
111
	</head>
112
	<body>
113
		<h1>VegPath&nbsp;&nbsp; <small>human-readable URLs for vegetation resources</small></h1>
114
		<div>Supported URL patterns:&nbsp;&nbsp; <small>(elements in <i>italics</i> are optional)</small></div>
115
		<p></p>
116
<?php
117
# add and list URLs
118

    
119
$Redmine = "https://projects.nceas.ucsb.edu/nceas/projects/bien";
120
$Redmine_svn = $Redmine."/repository/raw";
121

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