Project

General

Profile

1
<?php
2
function login__from_env()
3
{
4
	return $_SERVER["PHP_AUTH_USER"]
5
		.($_SERVER["PHP_AUTH_PW"] !== "" ? ":".$_SERVER["PHP_AUTH_PW"] : "");
6
}
7

    
8
function user2path($user) # multiple @ and nested . OK: a@b.c@url -> url?b.c.a
9
{
10
	$path = $user;
11
	
12
	# 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
	$path = preg_replace('/\b__|__\b/', '', $path);
15
	
16
	# remove insertion comments: [c]x[d]@url -> x@url
17
	# use [] because in writing, [] denotes insertion
18
	# insertion indicates that the semantic meaning of the [] portion also
19
	#  applies, even though it's not included in the linked term name
20
	$path = preg_replace('/\[.*?\]/', '', $path);
21
	
22
	# remove deletion comments: (-c_-)x@url -> c_x@url
23
	# use () because in editing, () denotes something to remove
24
	# the -...- indicate strikethrough (deletion)
25
	# deletion indicates that the semantic meaning of the () portion does not
26
	#  apply, even though it's included in the linked term name
27
	$path = preg_replace('/\(-([^)]*?)-\)/', '$1', $path);
28
	
29
	# translate reverse @-paths into forward .-paths
30
	$path = implode(".", array_reverse(explode("@", $path)));
31
	
32
	# undo transposes: _y~x@url -> x_y@url , Y~x@url -> xY@url
33
	# these can be used to put the category in a column name first
34
	# the _ should go first so that _y~ lines up vertically with [y_] paths
35
	# can't use : for this because Firefox will not update the "password" for
36
	#  the website with the new value after the :
37
	$path = preg_replace('/([^.]*)~([^.]*)/', '$2$1', $path);
38
	
39
	return $path;
40
}
41

    
42
if (!isset($_SERVER["PHP_AUTH_USER"])) # browser first omits Authorization
43
{
44
	header('WWW-Authenticate: Basic realm="'
45
.'please leave username/password blank or as filled in. '
46
.'**IMPORTANT**: to visit the homepage of this site, you should always '
47
.'append \".\": \"'.$_SERVER["HTTP_HOST"].'.\" "');
48
}
49
else
50
{
51
	$dest = preg_replace('!\b/!', "./", $_SERVER["SCRIPT_URI"])."?";
52
		# append trailing . to host to prevent infinite redirect loop
53
	if ($_SERVER["PHP_AUTH_USER"] !== "") # prepend to query string
54
		$dest .= "."/*force dotpath*/.user2path(login__from_env());
55
	$dest .= $_SERVER["QUERY_STRING"];
56
	
57
	header("Location: ".$dest);
58
}
59
?>
(32-32/34)