Project

General

Profile

1 13614 aaronmk
<?php
2 13694 aaronmk
function login__from_env()
3
{
4
	return $_SERVER["PHP_AUTH_USER"]
5
		.($_SERVER["PHP_AUTH_PW"] !== "" ? ":".$_SERVER["PHP_AUTH_PW"] : "");
6
}
7
8 13614 aaronmk
function user2path($user) # multiple @ and nested . OK: a@b.c@url -> url?b.c.a
9 13695 aaronmk
{
10 13701 aaronmk
	$path = $user;
11
12 14121 aaronmk
	# remove padding used to visually separate elements: x__@y__@url -> x@y@url
13
	# also remove leading __ that indicates internal field: __x@url -> x@url
14 14133 aaronmk
	# this leaves embedded __ (eg. x__y) untouched
15 13701 aaronmk
	$path = preg_replace('/\b__|__\b/', '', $path);
16
17 13720 aaronmk
	# remove insertion comments: [c]x[d]@url -> x@url
18 13718 aaronmk
	# use [] because in writing, [] denotes insertion
19 13723 aaronmk
	# insertion indicates that the semantic meaning of the [] portion also
20
	#  applies, even though it's not included in the linked term name
21 13718 aaronmk
	$path = preg_replace('/\[.*?\]/', '', $path);
22 13702 aaronmk
23 13733 aaronmk
	# remove deletion comments: (-c_-)x@url -> c_x@url
24 13720 aaronmk
	# use () because in editing, () denotes something to remove
25 13733 aaronmk
	# the -...- indicate strikethrough (deletion)
26 13720 aaronmk
	# deletion indicates that the semantic meaning of the () portion does not
27
	#  apply, even though it's included in the linked term name
28 13733 aaronmk
	$path = preg_replace('/\(-([^)]*?)-\)/', '$1', $path);
29 13720 aaronmk
30 13695 aaronmk
	# translate reverse @-paths into forward .-paths
31 13701 aaronmk
	$path = implode(".", array_reverse(explode("@", $path)));
32
33 14119 aaronmk
	# undo transposes: _y~x@url -> x_y@url , Y~x@url -> xY@url
34 14117 aaronmk
	# these can be used to put the category in a column name first
35 14119 aaronmk
	# the _ should go first so that _y~ lines up vertically with [y_] paths
36 14118 aaronmk
	# can't use : for this because Firefox will not update the "password" for
37
	#  the website with the new value after the :
38 14117 aaronmk
	$path = preg_replace('/([^.]*)~([^.]*)/', '$2$1', $path);
39
40 13701 aaronmk
	return $path;
41 13695 aaronmk
}
42 13614 aaronmk
43
if (!isset($_SERVER["PHP_AUTH_USER"])) # browser first omits Authorization
44
{
45 13739 aaronmk
	header('WWW-Authenticate: Basic realm="'
46
.'please leave username/password blank or as filled in. '
47
.'**IMPORTANT**: to visit the homepage of this site, you should always '
48
.'append \".\": \"'.$_SERVER["HTTP_HOST"].'.\" "');
49 13614 aaronmk
}
50
else
51
{
52 13668 aaronmk
	$dest = preg_replace('!\b/!', "./", $_SERVER["SCRIPT_URI"])."?";
53
		# append trailing . to host to prevent infinite redirect loop
54 13665 aaronmk
	if ($_SERVER["PHP_AUTH_USER"] !== "") # prepend to query string
55 13694 aaronmk
		$dest .= "."/*force dotpath*/.user2path(login__from_env());
56 13665 aaronmk
	$dest .= $_SERVER["QUERY_STRING"];
57 13625 aaronmk
58
	header("Location: ".$dest);
59 13614 aaronmk
}
60
?>