Project

General

Profile

1 7876 aaronmk
<?php
2
require_once dirname(__FILE__)."/util.php";
3
4
# config
5 7909 aaronmk
$alias = "j.mp/vegpath#";
6 7876 aaronmk
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 7904 aaronmk
$h_level = 5;
18 7876 aaronmk
$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 7909 aaronmk
	print("<h".$h_level.' id="'.$name.'">'.$alias.'<big><a href="http://'.$alias
27 7913 aaronmk
		.$name.'">'.$name."</a></big><i>".$suffix."</i></h".$h_level.">\n");
28 7912 aaronmk
	if ($ref === strtolower($name)) # found match, so redirect
29 7876 aaronmk
	{
30
		header("Location: ".strip_url($url_func($path->tail)));
31
		ob_end_flush();
32
		exit;
33
	}
34
}
35
36 7914 aaronmk
function custom_separator($url, $sep, $main_url)
37 7910 aaronmk
{
38 7914 aaronmk
	if (!isset($main_url)) $main_url = $url;
39
40
	return function($path) use($url, $sep, $main_url)
41 7910 aaronmk
	{
42 7914 aaronmk
		if ($path === "") return $main_url;
43 7910 aaronmk
		$path = parse_dot_path($path);
44
		return $url.join_non_empty($sep, array($path->head, $path->tail));
45
	};
46
}
47
48 7876 aaronmk
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 7902 aaronmk
		if ($path !== "") $url .= "?".$path;
59 7876 aaronmk
		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 7886 aaronmk
		$subject = "schema";
69 7902 aaronmk
		if ($path->head !== "")
70 7876 aaronmk
		{
71
			$url .= "&table=".$path->head;
72 7902 aaronmk
			if ($path->tail !== "")
73 7886 aaronmk
			{
74
				$url .= "&column=".$path->tail;
75
				$subject = "column";
76
			}
77
			else $subject = "table";
78 7876 aaronmk
		}
79 7895 aaronmk
		$url .= "&subject=".$subject;
80
		return $url;
81 7876 aaronmk
	};
82
}
83
84 7893 aaronmk
function phpMyAdmin($url)
85
{
86
	return function($path) use($url)
87
	{
88
		$path = parse_dot_path($path);
89
		$target = "db_structure";
90 7902 aaronmk
		if ($path->head !== "")
91 7893 aaronmk
		{
92
			$url .= "&table=".$path->head;
93 7902 aaronmk
			if ($path->tail !== "") $url .= "&column=".$path->tail;
94 7899 aaronmk
			$target = "tbl_structure";
95 7893 aaronmk
		}
96 7896 aaronmk
		$url .= "&target=".$target.".php";
97 7895 aaronmk
		return $url;
98 7893 aaronmk
	};
99
}
100
101 7876 aaronmk
ob_start(); // delay output in case there is a redirect
102
?>
103
<html>
104
	<head>
105 7881 aaronmk
		<title>VegPath</title>
106 7876 aaronmk
		<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 7880 aaronmk
		<h1>VegPath&nbsp;&nbsp; <small>human-readable URLs for vegetation resources</small></h1>
114 7882 aaronmk
		<div>Supported URL patterns:&nbsp;&nbsp; <small><i>(elements can be left out successively from the end of the URL)</i></small></div>
115 7876 aaronmk
		<blockquote>
116
<?php
117
# add and list URLs
118
print("<h2>Terms</h2>");
119
{
120
	print("<blockquote>\n");
121
	print("<h3>Exchange schemas</h3>");
122
	{
123
		print("<blockquote>\n");
124 7918 aaronmk
		add_ref("VegCore", ".term", "https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore#");
125 7876 aaronmk
		add_ref("DwC", ".term", "http://rs.tdwg.org/dwc/terms/#");
126
		{
127
			print("<blockquote>\n"); $h_level++;
128
			add_ref("DwC-history", ".term", "http://rs.tdwg.org/dwc/terms/history/#");
129
			print("</blockquote>\n"); $h_level--;
130
		}
131
		add_ref("TCS", "/XPath", "http://www.tdwg.org/standards/117/download/#/v101.xsd#");
132
		add_ref("VegX", "/XPath", "http://wiki.tdwg.org/twiki/pub/Vegetation/WebHome/VegX_Schema_1.5.3_proposed.zip#/veg.xsd#");
133
		print("</blockquote>\n");
134
	}
135
	print("<h3>Aggregators</h3>");
136
	{
137
		print("<blockquote>\n");
138 7916 aaronmk
		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=",
139
			"#", "http://vegbank.org/get/index/dba_tabledescription"));
140 7876 aaronmk
		add_ref("SALVIAS", ".table.column", "http://salvias.net/Documents/salvias_data_dictionary.html#");
141 7919 aaronmk
		{
142
			print("<blockquote>\n"); $h_level++;
143
			add_ref("SALVIAS-db", ".table.column", phpMyAdmin("http://nimoy.nceas.ucsb.edu/phpmyadmin/index.php?db=salvias_plots"));
144
			add_ref("SALVIAS-users", ".table.column", phpMyAdmin("http://nimoy.nceas.ucsb.edu/phpmyadmin/index.php?db=salvias_users"));
145
			print("</blockquote>\n"); $h_level--;
146
		}
147 7917 aaronmk
		add_ref("BIEN2", "", "http://nimoy.nceas.ucsb.edu/phpmyadmin/index.php?target=server_databases.php");
148
		{
149
			print("<blockquote>\n"); $h_level++;
150
			add_ref("BIEN2-web", ".table.column", phpMyAdmin("http://nimoy.nceas.ucsb.edu/phpmyadmin/index.php?db=bien_web"));
151
			add_ref("BIEN2-core", ".table.column", phpMyAdmin("http://nimoy.nceas.ucsb.edu/phpmyadmin/index.php?db=bien2"));
152
			add_ref("BIEN2-geoscrub", ".table.column", phpMyAdmin("http://nimoy.nceas.ucsb.edu/phpmyadmin/index.php?db=geoscrub"));
153
			add_ref("BIEN2-staging", ".table.column", phpMyAdmin("http://nimoy.nceas.ucsb.edu/phpmyadmin/index.php?db=bien2_staging"));
154
			print("</blockquote>\n"); $h_level--;
155
		}
156 7876 aaronmk
		add_ref("VegBIEN", ".table.column", phpPgAdmin("http://vegbiendev.nceas.ucsb.edu/phppgadmin/redirect.php?server=localhost%3A5432%3Aallow&database=vegbien&schema=public"));
157
		print("</blockquote>\n");
158
	}
159
	print("<h3>Primary databases</h3>");
160
	{
161
		print("<blockquote>\n");
162
		add_ref("TNRS", ".term", fragment_override("http://tnrs.iplantcollaborative.org/instructions.html", "download_results"));
163
		print("</blockquote>\n");
164
	}
165
	print("</blockquote>\n");
166
}
167
print("<h2>Data</h2>");
168
{
169
	print("<blockquote>\n");
170 7883 aaronmk
	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=",
171 7876 aaronmk
			"http://sweetgum.nybg.org/ih/"));
172
	print("</blockquote>\n");
173
}
174
?>
175
			<script type="text/javascript">
176
var loc = document.location
177
if (loc.hash)
178
{
179
	var fragment = rm_prefix('#', loc.hash)
180 7905 aaronmk
	var namespace = parse_dot_path(fragment).head
181
	document.getElementById(namespace).className = 'progress'
182 7906 aaronmk
	document.location = fragment
183 7876 aaronmk
}
184
			</script>
185
		</blockquote>
186
	</body>
187
</html>
188
<?php
189
ob_end_flush();
190
?>