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
	$path = preg_replace('/\b__|__\b/', '', $path);
14
	
15
	# remove category comments: x+y@url -> y@url
16
	# this special syntax is shorter than [x]_-_y@url
17
	# a UI can replace + with ' ' to produce a linewrap
18
	# can't use : for this because Firefox will not update the "password" for
19
	#  the website with the new value after the :
20
	$path = preg_replace('/^.*?\+/', '', $path);
21
	
22
	# remove insertion comments: [c]x[d]@url -> x@url
23
	# use [] because in writing, [] denotes insertion
24
	# insertion indicates that the semantic meaning of the [] portion also
25
	#  applies, even though it's not included in the linked term name
26
	$path = preg_replace('/\[.*?\]/', '', $path);
27
	
28
	# remove deletion comments: (-c_-)x@url -> c_x@url
29
	# use () because in editing, () denotes something to remove
30
	# the -...- indicate strikethrough (deletion)
31
	# deletion indicates that the semantic meaning of the () portion does not
32
	#  apply, even though it's included in the linked term name
33
	$path = preg_replace('/\(-([^)]*?)-\)/', '$1', $path);
34
	
35
	# translate reverse @-paths into forward .-paths
36
	$path = implode(".", array_reverse(explode("@", $path)));
37
	
38
	return $path;
39
}
40

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