Project

General

Profile

1 7876 aaronmk
<?php
2
require_once dirname(__FILE__)."/util.php";
3
4 7956 aaronmk
$self_dir = ensure_suffix("/", dirname($_SERVER["SCRIPT_NAME"]));
5
6 7876 aaronmk
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 13613 aaronmk
function user2path($user) # multiple @ and nested . OK: a@b.c@host -> host?b.c.a
17
{ return implode(".", array_reverse(explode("@", $user))); }
18
19 13612 aaronmk
# 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 13613 aaronmk
# subpath prefix: see format in user2path()
23 13612 aaronmk
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 13613 aaronmk
		header("Location: ?".user2path($_SERVER["PHP_AUTH_USER"]));
32 13612 aaronmk
		exit;
33
	}
34
	# otherwise, user empty so just display page
35
}
36
37 7904 aaronmk
$h_level = 5;
38 9601 aaronmk
$root = $_SERVER["SERVER_NAME"].rm_suffix("/", $self_dir)."?";
39 7953 aaronmk
# 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 7939 aaronmk
$ns = strtolower($path->head);
43 7876 aaronmk
44 7939 aaronmk
function add_ns($name, $path_pat, $url_func)
45 7876 aaronmk
{
46 7967 aaronmk
	global $root, $h_level, $path, $ns;
47 7876 aaronmk
	if (is_string($url_func)) $url_func = by_prefix($url_func);
48
49 7967 aaronmk
	print("<h".$h_level.' id="'.$name.'">'.$root.'<big><a href="http://'.$root
50 7938 aaronmk
		.$name.'">'.$name."</a></big><i>".$path_pat."</i></h".$h_level.">\n");
51 7939 aaronmk
	if ($ns === strtolower($name)) # found match, so redirect
52 7876 aaronmk
	{
53
		header("Location: ".strip_url($url_func($path->tail)));
54
		ob_end_flush();
55
		exit;
56
	}
57
}
58
59 7937 aaronmk
function custom_separator($url, $sep, $main_url=null)
60 7910 aaronmk
{
61 7914 aaronmk
	if (!isset($main_url)) $main_url = $url;
62
63
	return function($path) use($url, $sep, $main_url)
64 7910 aaronmk
	{
65 7914 aaronmk
		if ($path === "") return $main_url;
66 7910 aaronmk
		$path = parse_dot_path($path);
67
		return $url.join_non_empty($sep, array($path->head, $path->tail));
68
	};
69
}
70
71 7876 aaronmk
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 7902 aaronmk
		if ($path !== "") $url .= "?".$path;
82 7876 aaronmk
		return $url."#".$fragment;
83
	};
84
}
85
86 7934 aaronmk
function phpPgAdmin($url, $table=null)
87 7876 aaronmk
{
88 7934 aaronmk
	return function($path) use($url, $table)
89 7876 aaronmk
	{
90 7934 aaronmk
		$path = join_non_empty(".", array($table, $path));
91 7876 aaronmk
		$path = parse_dot_path($path);
92 7886 aaronmk
		$subject = "schema";
93 7902 aaronmk
		if ($path->head !== "")
94 7876 aaronmk
		{
95
			$url .= "&table=".$path->head;
96 7902 aaronmk
			if ($path->tail !== "")
97 7886 aaronmk
			{
98
				$url .= "&column=".$path->tail;
99
				$subject = "column";
100
			}
101
			else $subject = "table";
102 7876 aaronmk
		}
103 7895 aaronmk
		$url .= "&subject=".$subject;
104
		return $url;
105 7876 aaronmk
	};
106
}
107
108 7934 aaronmk
function phpMyAdmin($url, $table=null)
109 7893 aaronmk
{
110 7934 aaronmk
	return function($path) use($url, $table)
111 7893 aaronmk
	{
112 7934 aaronmk
		$path = join_non_empty(".", array($table, $path));
113 7893 aaronmk
		$path = parse_dot_path($path);
114
		$target = "db_structure";
115 7902 aaronmk
		if ($path->head !== "")
116 7893 aaronmk
		{
117
			$url .= "&table=".$path->head;
118 7902 aaronmk
			if ($path->tail !== "") $url .= "&column=".$path->tail;
119 7899 aaronmk
			$target = "tbl_structure";
120 7893 aaronmk
		}
121 7896 aaronmk
		$url .= "&target=".$target.".php";
122 7895 aaronmk
		return $url;
123 7893 aaronmk
	};
124
}
125
126 7876 aaronmk
ob_start(); // delay output in case there is a redirect
127
?>
128 9613 aaronmk
<!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 7876 aaronmk
	<head>
131 7881 aaronmk
		<title>VegPath</title>
132 8033 aaronmk
		<link rel="stylesheet" type="text/css" href="/main.css" />
133 7876 aaronmk
		<style type="text/css">
134
h1 {color: green;}
135
		</style>
136 8033 aaronmk
		<script type="text/javascript" src="/util.js"></script>
137 7876 aaronmk
	</head>
138
	<body>
139 7951 aaronmk
		<h1>VegPath&nbsp;&nbsp; <small><a href="http://en.wikipedia.org/wiki/PURL">persistent URLs</a> for vegetation resources</small></h1>
140 7923 aaronmk
		<div>Supported URL patterns:&nbsp;&nbsp; <small>(elements in <i>italics</i> are optional)</small></div>
141 7876 aaronmk
<?php
142
# add and list URLs
143 7920 aaronmk
144 7924 aaronmk
$Redmine = "https://projects.nceas.ucsb.edu/nceas/projects/bien";
145 7928 aaronmk
$Redmine_svn = $Redmine."/repository/raw";
146 7924 aaronmk
147 7920 aaronmk
$nimoy = "http://nimoy.nceas.ucsb.edu/phpmyadmin/index.php";
148 7921 aaronmk
function nimoy_db($db) { global $nimoy; return phpMyAdmin($nimoy."?db=".$db); }
149 7936 aaronmk
150
$IH_db = phpMyAdmin($nimoy."?db=bien3_adb", "ih");
151 7944 aaronmk
152
$SALVIAS = "http://salvias.net/Documents/salvias_data_dictionary.html";
153 7931 aaronmk
?>
154
		<table border="0" cellspacing="0" cellpadding="0">
155
			<tr valign="top">
156
				<td nowrap="nowrap"><h2>Terms</h2></td>
157 8044 aaronmk
				<td nowrap="nowrap"><h2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</h2></td>
158 7931 aaronmk
				<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 7876 aaronmk
{
166
	print("<blockquote>\n");
167 7939 aaronmk
	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 7876 aaronmk
	{
170 7931 aaronmk
		print("<blockquote>\n"); $h_level++;
171 8050 aaronmk
		add_ns("DwC.history", ".term", "http://rs.tdwg.org/dwc/terms/history/#");
172 7931 aaronmk
		print("</blockquote>\n"); $h_level--;
173 7876 aaronmk
	}
174 7942 aaronmk
	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 7931 aaronmk
	print("</blockquote>\n");
177
}
178
print("<h3>Aggregators</h3>");
179
{
180
	print("<blockquote>\n");
181 7939 aaronmk
	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 7931 aaronmk
		"#", "http://vegbank.org/get/index/dba_tabledescription"));
183 7945 aaronmk
	add_ns("SALVIAS", ".table.column", by_prefix($SALVIAS."#Plot_", $SALVIAS));
184 7876 aaronmk
	{
185 7931 aaronmk
		print("<blockquote>\n"); $h_level++;
186 8050 aaronmk
		add_ns("SALVIAS.db", ".table.column", nimoy_db("salvias_plots"));
187
		add_ns("SALVIAS.users", ".table.column", nimoy_db("salvias_users"));
188 7931 aaronmk
		print("</blockquote>\n"); $h_level--;
189 7876 aaronmk
	}
190 7939 aaronmk
	add_ns("BIEN2", "", $nimoy."?target=server_databases.php");
191 7876 aaronmk
	{
192 7931 aaronmk
		print("<blockquote>\n"); $h_level++;
193 8050 aaronmk
		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 7931 aaronmk
		print("</blockquote>\n"); $h_level--;
198 7876 aaronmk
	}
199 7939 aaronmk
	add_ns("VegBIEN", ".table.column", phpPgAdmin("http://vegbiendev.nceas.ucsb.edu/phppgadmin/redirect.php?server=localhost%3A5432%3Aallow&database=vegbien&schema=public"));
200 7931 aaronmk
	print("</blockquote>\n");
201
}
202
print("<h3>Primary databases</h3>");
203
{
204
	print("<blockquote>\n");
205 7939 aaronmk
	add_ns("TNRS", ".term", fragment_override("http://tnrs.iplantcollaborative.org/instructions.html", "download_results"));
206 7961 aaronmk
	add_ns("CTFS", "", $Redmine."/wiki/CTFS");
207 7929 aaronmk
	{
208 7931 aaronmk
		print("<blockquote>\n"); $h_level++;
209 8050 aaronmk
		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 7931 aaronmk
		print("</blockquote>\n"); $h_level--;
213 7929 aaronmk
	}
214 8050 aaronmk
	add_ns("IH.db", ".term", $IH_db);
215 7876 aaronmk
	print("</blockquote>\n");
216
}
217 7931 aaronmk
print("<h3>People</h3>");
218 7876 aaronmk
{
219
	print("<blockquote>\n");
220 8042 aaronmk
	add_ns("Brad", "", "mailto:bboyleATemail.arizona.edu");
221 7931 aaronmk
	{
222
		print("<blockquote>\n"); $h_level++;
223
		$Brad_Boyle_VegCore = $Redmine_svn."/schemas/VegCore/Brad_Boyle";
224 8050 aaronmk
		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 7931 aaronmk
		print("</blockquote>\n"); $h_level--;
228
	}
229 7876 aaronmk
	print("</blockquote>\n");
230
}
231 7931 aaronmk
print("</blockquote>\n");
232
?>
233
				</td>
234 8044 aaronmk
				<td nowrap="nowrap"></td>
235 7931 aaronmk
				<td nowrap="nowrap">
236
<?php
237
print("<blockquote>\n");
238 7932 aaronmk
print("<h3>Institutions</h3>");
239
{
240
	print("<blockquote>\n");
241 7939 aaronmk
	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 7931 aaronmk
		"http://sweetgum.nybg.org/ih/"));
243 7932 aaronmk
	print("</blockquote>\n");
244
}
245 7931 aaronmk
print("</blockquote>\n");
246
?>
247
				</td>
248
			</tr>
249
		</table>
250
<?php
251 7967 aaronmk
if (ends_with($root, '#')) # URL shortener requires fragment redirect
252 7922 aaronmk
{
253 7876 aaronmk
?>
254 7931 aaronmk
		<script type="text/javascript">
255 7876 aaronmk
var loc = document.location
256 8365 aaronmk
if (loc.hash) document.location = '?'+rm_prefix('#', loc.hash)
257 7931 aaronmk
		</script>
258 7922 aaronmk
<?php
259
}
260 9607 aaronmk
?>
261
		<p>&nbsp;</p>
262
<?php
263 7876 aaronmk
ob_end_flush();
264 9605 aaronmk
265
# full directory index
266 13305 aaronmk
# to fix bug, only display if invoked as "__.org/", not "__.org/index.php"
267
if (substr($_SERVER["SCRIPT_URI"], -1) === '/')
268 13611 aaronmk
	fpassthru(fopen($_SERVER["SCRIPT_URI"]."all?".$_SERVER["HTTP_AUTHORIZATION"], "r"));
269 9606 aaronmk
?>
270
	</body>
271
</html>