Project

General

Profile

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