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 7912 aaronmk
		$name.'">'.$name."</a></big><i>".$suffix."</i></h".$h_level.">\n");
28
	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 7910 aaronmk
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 7876 aaronmk
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 7902 aaronmk
		if ($path !== "") $url .= "?".$path;
56 7876 aaronmk
		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 7886 aaronmk
		$subject = "schema";
66 7902 aaronmk
		if ($path->head !== "")
67 7876 aaronmk
		{
68
			$url .= "&table=".$path->head;
69 7902 aaronmk
			if ($path->tail !== "")
70 7886 aaronmk
			{
71
				$url .= "&column=".$path->tail;
72
				$subject = "column";
73
			}
74
			else $subject = "table";
75 7876 aaronmk
		}
76 7895 aaronmk
		$url .= "&subject=".$subject;
77
		return $url;
78 7876 aaronmk
	};
79
}
80
81 7893 aaronmk
function phpMyAdmin($url)
82
{
83
	return function($path) use($url)
84
	{
85
		$path = parse_dot_path($path);
86
		$target = "db_structure";
87 7902 aaronmk
		if ($path->head !== "")
88 7893 aaronmk
		{
89
			$url .= "&table=".$path->head;
90 7902 aaronmk
			if ($path->tail !== "") $url .= "&column=".$path->tail;
91 7899 aaronmk
			$target = "tbl_structure";
92 7893 aaronmk
		}
93 7896 aaronmk
		$url .= "&target=".$target.".php";
94 7895 aaronmk
		return $url;
95 7893 aaronmk
	};
96
}
97
98 7876 aaronmk
function VegBank($url)
99
{
100 7911 aaronmk
	return custom_separator($url."/vegbank/views/dba_tabledescription_detail.jsp?view=detail&entity=dba_tabledescription&where=where_tablename&wparam=", "#");
101 7876 aaronmk
}
102
103
ob_start(); // delay output in case there is a redirect
104
?>
105
<html>
106
	<head>
107 7881 aaronmk
		<title>VegPath</title>
108 7876 aaronmk
		<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 7880 aaronmk
		<h1>VegPath&nbsp;&nbsp; <small>human-readable URLs for vegetation resources</small></h1>
116 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>
117 7876 aaronmk
		<blockquote>
118
<?php
119
# add and list URLs
120
print("<h2>Terms</h2>");
121
{
122
	print("<blockquote>\n");
123
	print("<h3>Exchange schemas</h3>");
124
	{
125
		print("<blockquote>\n");
126
		add_ref("VegCore", ".table.column", "https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore#");
127
		add_ref("DwC", ".term", "http://rs.tdwg.org/dwc/terms/#");
128
		{
129
			print("<blockquote>\n"); $h_level++;
130
			add_ref("DwC-history", ".term", "http://rs.tdwg.org/dwc/terms/history/#");
131
			print("</blockquote>\n"); $h_level--;
132
		}
133
		add_ref("TCS", "/XPath", "http://www.tdwg.org/standards/117/download/#/v101.xsd#");
134
		add_ref("VegX", "/XPath", "http://wiki.tdwg.org/twiki/pub/Vegetation/WebHome/VegX_Schema_1.5.3_proposed.zip#/veg.xsd#");
135
		print("</blockquote>\n");
136
	}
137
	print("<h3>Aggregators</h3>");
138
	{
139
		print("<blockquote>\n");
140
		add_ref("VegBank", ".table.column", VegBank("http://vegbank.org"));
141
		add_ref("SALVIAS", ".table.column", "http://salvias.net/Documents/salvias_data_dictionary.html#");
142 7894 aaronmk
		add_ref("BIEN2", ".table.column", phpMyAdmin("http://nimoy.nceas.ucsb.edu/phpmyadmin/index.php?db=bien_web"));
143 7876 aaronmk
		add_ref("VegBIEN", ".table.column", phpPgAdmin("http://vegbiendev.nceas.ucsb.edu/phppgadmin/redirect.php?server=localhost%3A5432%3Aallow&database=vegbien&schema=public"));
144
		print("</blockquote>\n");
145
	}
146
	print("<h3>Primary databases</h3>");
147
	{
148
		print("<blockquote>\n");
149
		add_ref("TNRS", ".term", fragment_override("http://tnrs.iplantcollaborative.org/instructions.html", "download_results"));
150
		print("</blockquote>\n");
151
	}
152
	print("</blockquote>\n");
153
}
154
print("<h2>Data</h2>");
155
{
156
	print("<blockquote>\n");
157 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=",
158 7876 aaronmk
			"http://sweetgum.nybg.org/ih/"));
159
	print("</blockquote>\n");
160
}
161
?>
162
			<script type="text/javascript">
163
var loc = document.location
164
if (loc.hash)
165
{
166
	var fragment = rm_prefix('#', loc.hash)
167 7905 aaronmk
	var namespace = parse_dot_path(fragment).head
168
	document.getElementById(namespace).className = 'progress'
169 7906 aaronmk
	document.location = fragment
170 7876 aaronmk
}
171
			</script>
172
		</blockquote>
173
	</body>
174
</html>
175
<?php
176
ob_end_flush();
177
?>