Project

General

Profile

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

    
4
$self_dir = ensure_suffix("/", dirname($_SERVER["SCRIPT_NAME"]));
5

    
6
function by_prefix($url, $main_url=null)
7
{
8
	if (!isset($main_url)) $main_url = $url;
9
	
10
	return function($path) use($url, $main_url)
11
	{
12
		return $path ? $url.$path : $main_url;
13
	};
14
}
15

    
16
function user2path($user) # multiple @ and nested . OK: a@b.c@host -> host?b.c.a
17
{ return implode(".", array_reverse(explode("@", $user))); }
18

    
19
# redirect subpath@host? -> host?subpath (one type of prefix redirect)
20
# better than subpath.host because case is preserved and special chars allowed
21
# must require trailing ? , to avoid needing login to view the page itself
22
# subpath prefix: see format in user2path()
23
if (substr($_SERVER["REQUEST_URI"], -1/*last char*/) === "?")
24
{
25
	if (!isset($_SERVER["PHP_AUTH_USER"])) # browser first omits Authorization
26
	{
27
		header('WWW-Authenticate: Basic realm="please leave username/password blank or as filled in"');
28
	}
29
	elseif ($_SERVER["PHP_AUTH_USER"] !== "")
30
	{
31
		header("Location: ?".user2path($_SERVER["PHP_AUTH_USER"]));
32
		exit;
33
	}
34
	# otherwise, user empty so just display page
35
}
36

    
37
$h_level = 5;
38
$root = $_SERVER["SERVER_NAME"].rm_suffix("/", $self_dir)."?";
39
# instead of PATH_INFO, to support the Apache ErrorDocument directive
40
$rel_fs_path = rm_prefix($self_dir, $_SERVER["REQUEST_URI"]);
41
$path = parse_dot_path($rel_fs_path);
42
$ns = strtolower($path->head);
43

    
44
function add_ns($name, $path_pat, $url_func)
45
{
46
	global $root, $h_level, $path, $ns;
47
	if (is_string($url_func)) $url_func = by_prefix($url_func);
48
	
49
	print("<h".$h_level.' id="'.$name.'">'.$root.'<big><a href="http://'.$root
50
		.$name.'">'.$name."</a></big><i>".$path_pat."</i></h".$h_level.">\n");
51
	if ($ns === strtolower($name)) # found match, so redirect
52
	{
53
		header("Location: ".strip_url($url_func($path->tail)));
54
		ob_end_flush();
55
		exit;
56
	}
57
}
58

    
59
function custom_separator($url, $sep, $main_url=null)
60
{
61
	if (!isset($main_url)) $main_url = $url;
62
	
63
	return function($path) use($url, $sep, $main_url)
64
	{
65
		if ($path === "") return $main_url;
66
		$path = parse_dot_path($path);
67
		return $url.join_non_empty($sep, array($path->head, $path->tail));
68
	};
69
}
70

    
71
function fragment_override($url, $fragment=null)
72
{
73
	return function($path) use($url, $fragment)
74
	{
75
		if (!isset($fragment))
76
		{
77
			$path = parse_dot_path($path);
78
			$fragment = $path->head;
79
			$path = $path->tail;
80
		}
81
		if ($path !== "") $url .= "?".$path;
82
		return $url."#".$fragment;
83
	};
84
}
85

    
86
function phpPgAdmin($url, $table=null)
87
{
88
	return function($path) use($url, $table)
89
	{
90
		$path = join_non_empty(".", array($table, $path));
91
		$path = parse_dot_path($path);
92
		$subject = "schema";
93
		if ($path->head !== "")
94
		{
95
			$url .= "&table=".$path->head;
96
			if ($path->tail !== "")
97
			{
98
				$url .= "&column=".$path->tail;
99
				$subject = "column";
100
			}
101
			else $subject = "table";
102
		}
103
		$url .= "&subject=".$subject;
104
		return $url;
105
	};
106
}
107

    
108
function phpMyAdmin($url, $table=null)
109
{
110
	return function($path) use($url, $table)
111
	{
112
		$path = join_non_empty(".", array($table, $path));
113
		$path = parse_dot_path($path);
114
		$target = "db_structure";
115
		if ($path->head !== "")
116
		{
117
			$url .= "&table=".$path->head;
118
			if ($path->tail !== "") $url .= "&column=".$path->tail;
119
			$target = "tbl_structure";
120
		}
121
		$url .= "&target=".$target.".php";
122
		return $url;
123
	};
124
}
125

    
126
ob_start(); // delay output in case there is a redirect
127
?>
128
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
129
<html xmlns="http://www.w3.org/1999/xhtml">
130
	<head>
131
		<title>VegPath</title>
132
		<link rel="stylesheet" type="text/css" href="/main.css" />
133
		<style type="text/css">
134
h1 {color: green;}
135
		</style>
136
		<script type="text/javascript" src="/util.js"></script>
137
	</head>
138
	<body>
139
		<h1>VegPath&nbsp;&nbsp; <small><a href="http://en.wikipedia.org/wiki/PURL">persistent URLs</a> for vegetation resources</small></h1>
140
		<div>Supported URL patterns:&nbsp;&nbsp; <small>(elements in <i>italics</i> are optional)</small></div>
141
<?php
142
# add and list URLs
143

    
144
$Redmine = "https://projects.nceas.ucsb.edu/nceas/projects/bien";
145
$Redmine_svn = $Redmine."/repository/raw";
146

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

    
150
$IH_db = phpMyAdmin($nimoy."?db=bien3_adb", "ih");
151

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

    
265
# full directory index
266
# to fix bug, only display if invoked as "__.org/", not "__.org/index.php"
267
if (substr($_SERVER["SCRIPT_URI"], -1) === '/')
268
	fpassthru(fopen($_SERVER["SCRIPT_URI"]."all?".$_SERVER["HTTP_AUTHORIZATION"], "r"));
269
?>
270
	</body>
271
</html>
(28-28/34)