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 13612 aaronmk
# redirect subpath@host? -> host?subpath (one type of prefix redirect)
17
# better than subpath.host because case is preserved and special chars allowed
18
# must require trailing ? , to avoid needing login to view the page itself
19
if (substr($_SERVER["REQUEST_URI"], -1/*last char*/) === "?")
20
{
21
	if (!isset($_SERVER["PHP_AUTH_USER"])) # browser first omits Authorization
22
	{
23
		header('WWW-Authenticate: Basic realm="please leave username/password blank or as filled in"');
24
	}
25
	elseif ($_SERVER["PHP_AUTH_USER"] !== "")
26
	{
27
		header("Location: ?".$_SERVER["PHP_AUTH_USER"]);
28
		exit;
29
	}
30
	# otherwise, user empty so just display page
31
}
32
33 7904 aaronmk
$h_level = 5;
34 9601 aaronmk
$root = $_SERVER["SERVER_NAME"].rm_suffix("/", $self_dir)."?";
35 7953 aaronmk
# instead of PATH_INFO, to support the Apache ErrorDocument directive
36
$rel_fs_path = rm_prefix($self_dir, $_SERVER["REQUEST_URI"]);
37
$path = parse_dot_path($rel_fs_path);
38 7939 aaronmk
$ns = strtolower($path->head);
39 7876 aaronmk
40 7939 aaronmk
function add_ns($name, $path_pat, $url_func)
41 7876 aaronmk
{
42 7967 aaronmk
	global $root, $h_level, $path, $ns;
43 7876 aaronmk
	if (is_string($url_func)) $url_func = by_prefix($url_func);
44
45 7967 aaronmk
	print("<h".$h_level.' id="'.$name.'">'.$root.'<big><a href="http://'.$root
46 7938 aaronmk
		.$name.'">'.$name."</a></big><i>".$path_pat."</i></h".$h_level.">\n");
47 7939 aaronmk
	if ($ns === strtolower($name)) # found match, so redirect
48 7876 aaronmk
	{
49
		header("Location: ".strip_url($url_func($path->tail)));
50
		ob_end_flush();
51
		exit;
52
	}
53
}
54
55 7937 aaronmk
function custom_separator($url, $sep, $main_url=null)
56 7910 aaronmk
{
57 7914 aaronmk
	if (!isset($main_url)) $main_url = $url;
58
59
	return function($path) use($url, $sep, $main_url)
60 7910 aaronmk
	{
61 7914 aaronmk
		if ($path === "") return $main_url;
62 7910 aaronmk
		$path = parse_dot_path($path);
63
		return $url.join_non_empty($sep, array($path->head, $path->tail));
64
	};
65
}
66
67 7876 aaronmk
function fragment_override($url, $fragment=null)
68
{
69
	return function($path) use($url, $fragment)
70
	{
71
		if (!isset($fragment))
72
		{
73
			$path = parse_dot_path($path);
74
			$fragment = $path->head;
75
			$path = $path->tail;
76
		}
77 7902 aaronmk
		if ($path !== "") $url .= "?".$path;
78 7876 aaronmk
		return $url."#".$fragment;
79
	};
80
}
81
82 7934 aaronmk
function phpPgAdmin($url, $table=null)
83 7876 aaronmk
{
84 7934 aaronmk
	return function($path) use($url, $table)
85 7876 aaronmk
	{
86 7934 aaronmk
		$path = join_non_empty(".", array($table, $path));
87 7876 aaronmk
		$path = parse_dot_path($path);
88 7886 aaronmk
		$subject = "schema";
89 7902 aaronmk
		if ($path->head !== "")
90 7876 aaronmk
		{
91
			$url .= "&table=".$path->head;
92 7902 aaronmk
			if ($path->tail !== "")
93 7886 aaronmk
			{
94
				$url .= "&column=".$path->tail;
95
				$subject = "column";
96
			}
97
			else $subject = "table";
98 7876 aaronmk
		}
99 7895 aaronmk
		$url .= "&subject=".$subject;
100
		return $url;
101 7876 aaronmk
	};
102
}
103
104 7934 aaronmk
function phpMyAdmin($url, $table=null)
105 7893 aaronmk
{
106 7934 aaronmk
	return function($path) use($url, $table)
107 7893 aaronmk
	{
108 7934 aaronmk
		$path = join_non_empty(".", array($table, $path));
109 7893 aaronmk
		$path = parse_dot_path($path);
110
		$target = "db_structure";
111 7902 aaronmk
		if ($path->head !== "")
112 7893 aaronmk
		{
113
			$url .= "&table=".$path->head;
114 7902 aaronmk
			if ($path->tail !== "") $url .= "&column=".$path->tail;
115 7899 aaronmk
			$target = "tbl_structure";
116 7893 aaronmk
		}
117 7896 aaronmk
		$url .= "&target=".$target.".php";
118 7895 aaronmk
		return $url;
119 7893 aaronmk
	};
120
}
121
122 7876 aaronmk
ob_start(); // delay output in case there is a redirect
123
?>
124 9613 aaronmk
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
125
<html xmlns="http://www.w3.org/1999/xhtml">
126 7876 aaronmk
	<head>
127 7881 aaronmk
		<title>VegPath</title>
128 8033 aaronmk
		<link rel="stylesheet" type="text/css" href="/main.css" />
129 7876 aaronmk
		<style type="text/css">
130
h1 {color: green;}
131
		</style>
132 8033 aaronmk
		<script type="text/javascript" src="/util.js"></script>
133 7876 aaronmk
	</head>
134
	<body>
135 7951 aaronmk
		<h1>VegPath&nbsp;&nbsp; <small><a href="http://en.wikipedia.org/wiki/PURL">persistent URLs</a> for vegetation resources</small></h1>
136 7923 aaronmk
		<div>Supported URL patterns:&nbsp;&nbsp; <small>(elements in <i>italics</i> are optional)</small></div>
137 7876 aaronmk
<?php
138
# add and list URLs
139 7920 aaronmk
140 7924 aaronmk
$Redmine = "https://projects.nceas.ucsb.edu/nceas/projects/bien";
141 7928 aaronmk
$Redmine_svn = $Redmine."/repository/raw";
142 7924 aaronmk
143 7920 aaronmk
$nimoy = "http://nimoy.nceas.ucsb.edu/phpmyadmin/index.php";
144 7921 aaronmk
function nimoy_db($db) { global $nimoy; return phpMyAdmin($nimoy."?db=".$db); }
145 7936 aaronmk
146
$IH_db = phpMyAdmin($nimoy."?db=bien3_adb", "ih");
147 7944 aaronmk
148
$SALVIAS = "http://salvias.net/Documents/salvias_data_dictionary.html";
149 7931 aaronmk
?>
150
		<table border="0" cellspacing="0" cellpadding="0">
151
			<tr valign="top">
152
				<td nowrap="nowrap"><h2>Terms</h2></td>
153 8044 aaronmk
				<td nowrap="nowrap"><h2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</h2></td>
154 7931 aaronmk
				<td nowrap="nowrap"><h2>Data</h2></td>
155
			</tr>
156
			<tr valign="top">
157
				<td nowrap="nowrap">
158
<?php
159
print("<blockquote>\n");
160
print("<h3>Exchange schemas</h3>");
161 7876 aaronmk
{
162
	print("<blockquote>\n");
163 7939 aaronmk
	add_ns("VegCore", ".term", "https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore#");
164
	add_ns("DwC", ".term", "http://rs.tdwg.org/dwc/terms/#");
165 7876 aaronmk
	{
166 7931 aaronmk
		print("<blockquote>\n"); $h_level++;
167 8050 aaronmk
		add_ns("DwC.history", ".term", "http://rs.tdwg.org/dwc/terms/history/#");
168 7931 aaronmk
		print("</blockquote>\n"); $h_level--;
169 7876 aaronmk
	}
170 7942 aaronmk
	add_ns("TCS", "#/XPath", "http://www.tdwg.org/standards/117/download/#/v101.xsd");
171
	add_ns("VegX", "#/XPath", "http://wiki.tdwg.org/twiki/pub/Vegetation/WebHome/VegX_Schema_1.5.3_proposed.zip#/veg.xsd");
172 7931 aaronmk
	print("</blockquote>\n");
173
}
174
print("<h3>Aggregators</h3>");
175
{
176
	print("<blockquote>\n");
177 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=",
178 7931 aaronmk
		"#", "http://vegbank.org/get/index/dba_tabledescription"));
179 7945 aaronmk
	add_ns("SALVIAS", ".table.column", by_prefix($SALVIAS."#Plot_", $SALVIAS));
180 7876 aaronmk
	{
181 7931 aaronmk
		print("<blockquote>\n"); $h_level++;
182 8050 aaronmk
		add_ns("SALVIAS.db", ".table.column", nimoy_db("salvias_plots"));
183
		add_ns("SALVIAS.users", ".table.column", nimoy_db("salvias_users"));
184 7931 aaronmk
		print("</blockquote>\n"); $h_level--;
185 7876 aaronmk
	}
186 7939 aaronmk
	add_ns("BIEN2", "", $nimoy."?target=server_databases.php");
187 7876 aaronmk
	{
188 7931 aaronmk
		print("<blockquote>\n"); $h_level++;
189 8050 aaronmk
		add_ns("BIEN2.web", ".table.column", nimoy_db("bien_web"));
190
		add_ns("BIEN2.core", ".table.column", nimoy_db("bien2"));
191
		add_ns("BIEN2.geoscrub", ".table.column", nimoy_db("geoscrub"));
192
		add_ns("BIEN2.staging", ".table.column", nimoy_db("bien2_staging"));
193 7931 aaronmk
		print("</blockquote>\n"); $h_level--;
194 7876 aaronmk
	}
195 7939 aaronmk
	add_ns("VegBIEN", ".table.column", phpPgAdmin("http://vegbiendev.nceas.ucsb.edu/phppgadmin/redirect.php?server=localhost%3A5432%3Aallow&database=vegbien&schema=public"));
196 7931 aaronmk
	print("</blockquote>\n");
197
}
198
print("<h3>Primary databases</h3>");
199
{
200
	print("<blockquote>\n");
201 7939 aaronmk
	add_ns("TNRS", ".term", fragment_override("http://tnrs.iplantcollaborative.org/instructions.html", "download_results"));
202 7961 aaronmk
	add_ns("CTFS", "", $Redmine."/wiki/CTFS");
203 7929 aaronmk
	{
204 7931 aaronmk
		print("<blockquote>\n"); $h_level++;
205 8050 aaronmk
		add_ns("CTFS.schema", ".table.column", $Redmine_svn."/inputs/CTFS/_archive/DBv5.txt#");
206
		add_ns("CTFS.tables", ".table", fragment_override($Redmine."/wiki/CTFS", "Tables"));
207
		add_ns("CTFS.terms", ".term", $Redmine_svn."/inputs/CTFS/_src/ctfs-comments_worksheet.xls#");
208 7931 aaronmk
		print("</blockquote>\n"); $h_level--;
209 7929 aaronmk
	}
210 8050 aaronmk
	add_ns("IH.db", ".term", $IH_db);
211 7876 aaronmk
	print("</blockquote>\n");
212
}
213 7931 aaronmk
print("<h3>People</h3>");
214 7876 aaronmk
{
215
	print("<blockquote>\n");
216 8042 aaronmk
	add_ns("Brad", "", "mailto:bboyleATemail.arizona.edu");
217 7931 aaronmk
	{
218
		print("<blockquote>\n"); $h_level++;
219
		$Brad_Boyle_VegCore = $Redmine_svn."/schemas/VegCore/Brad_Boyle";
220 8050 aaronmk
		add_ns("Brad.data-provenance", ".term", $Brad_Boyle_VegCore."/BIEN%20database%20entities%20related%20to%20data%20provenance%20and%20ownership.docx#");
221
		add_ns("Brad.DwC-IDs.2013-2-7", ".term", $Brad_Boyle_VegCore."/vegbien_identifiers.xlsx#");
222
		add_ns("Brad.DwC-IDs.2013-1-31", ".term", $Brad_Boyle_VegCore."/vegbien_identifier_examples.xlsx#");
223 7931 aaronmk
		print("</blockquote>\n"); $h_level--;
224
	}
225 7876 aaronmk
	print("</blockquote>\n");
226
}
227 7931 aaronmk
print("</blockquote>\n");
228
?>
229
				</td>
230 8044 aaronmk
				<td nowrap="nowrap"></td>
231 7931 aaronmk
				<td nowrap="nowrap">
232
<?php
233
print("<blockquote>\n");
234 7932 aaronmk
print("<h3>Institutions</h3>");
235
{
236
	print("<blockquote>\n");
237 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=",
238 7931 aaronmk
		"http://sweetgum.nybg.org/ih/"));
239 7932 aaronmk
	print("</blockquote>\n");
240
}
241 7931 aaronmk
print("</blockquote>\n");
242
?>
243
				</td>
244
			</tr>
245
		</table>
246
<?php
247 7967 aaronmk
if (ends_with($root, '#')) # URL shortener requires fragment redirect
248 7922 aaronmk
{
249 7876 aaronmk
?>
250 7931 aaronmk
		<script type="text/javascript">
251 7876 aaronmk
var loc = document.location
252 8365 aaronmk
if (loc.hash) document.location = '?'+rm_prefix('#', loc.hash)
253 7931 aaronmk
		</script>
254 7922 aaronmk
<?php
255
}
256 9607 aaronmk
?>
257
		<p>&nbsp;</p>
258
<?php
259 7876 aaronmk
ob_end_flush();
260 9605 aaronmk
261
# full directory index
262 13305 aaronmk
# to fix bug, only display if invoked as "__.org/", not "__.org/index.php"
263
if (substr($_SERVER["SCRIPT_URI"], -1) === '/')
264 13611 aaronmk
	fpassthru(fopen($_SERVER["SCRIPT_URI"]."all?".$_SERVER["HTTP_AUTHORIZATION"], "r"));
265 9606 aaronmk
?>
266
	</body>
267
</html>