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 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
		if ($path !== "") $url .= "?".$path;
47
		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
		$subject = "schema";
57
		if ($path->head !== "")
58
		{
59
			$url .= "&table=".$path->head;
60
			if ($path->tail !== "")
61
			{
62
				$url .= "&column=".$path->tail;
63
				$subject = "column";
64
			}
65
			else $subject = "table";
66
		}
67
		$url .= "&subject=".$subject;
68
		return $url;
69
	};
70
}
71

    
72
function phpMyAdmin($url)
73
{
74
	return function($path) use($url)
75
	{
76
		$path = parse_dot_path($path);
77
		$target = "db_structure";
78
		if ($path->head !== "")
79
		{
80
			$url .= "&table=".$path->head;
81
			if ($path->tail !== "") $url .= "&column=".$path->tail;
82
			$target = "tbl_structure";
83
		}
84
		$url .= "&target=".$target.".php";
85
		return $url;
86
	};
87
}
88

    
89
function VegBank($url)
90
{
91
	return function($path) use($url)
92
	{
93
		$path = parse_dot_path($path);
94
		if ($path->head !== "") $url .= "/vegbank/views/dba_tabledescription_detail.jsp?view=detail&entity=dba_tabledescription&where=where_tablename&wparam=".$path->head."#".$path->tail;
95
		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
		<title>VegPath</title>
105
		<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
		<h1>VegPath&nbsp;&nbsp; <small>human-readable URLs for vegetation resources</small></h1>
113
		<div>Supported URL patterns:&nbsp;&nbsp; <small><i>(elements can be left out successively from the end of the URL)</i></small></div>
114
		<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
		add_ref("BIEN2", ".table.column", phpMyAdmin("http://nimoy.nceas.ucsb.edu/phpmyadmin/index.php?db=bien_web"));
140
		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
	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
			"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
	var namespace = parse_dot_path(fragment).head
165
	document.getElementById(namespace).className = 'progress'
166
	document.location = fragment
167
}
168
			</script>
169
		</blockquote>
170
	</body>
171
</html>
172
<?php
173
ob_end_flush();
174
?>
(2-2/5)