Project

General

Profile

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

    
4
# config
5
$alias = "path.vg/";
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
$ns = strtolower($path->head);
20

    
21
function add_ns($name, $path_pat, $url_func)
22
{
23
	global $alias, $h_level, $path, $ns;
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>".$path_pat."</i></h".$h_level.">\n");
28
	if ($ns === 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=null)
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, $table=null)
64
{
65
	return function($path) use($url, $table)
66
	{
67
		$path = join_non_empty(".", array($table, $path));
68
		$path = parse_dot_path($path);
69
		$subject = "schema";
70
		if ($path->head !== "")
71
		{
72
			$url .= "&table=".$path->head;
73
			if ($path->tail !== "")
74
			{
75
				$url .= "&column=".$path->tail;
76
				$subject = "column";
77
			}
78
			else $subject = "table";
79
		}
80
		$url .= "&subject=".$subject;
81
		return $url;
82
	};
83
}
84

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

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

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

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

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