File: functions.php

package info (click to toggle)
bamboo 1.2-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 580 kB
  • ctags: 1,338
  • sloc: php: 4,061; makefile: 44; sh: 36
file content (44 lines) | stat: -rw-r--r-- 1,102 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php

/* 
 * Random help functions that don't have any place better to live
 *
 */


/*
 * guess_url_root
 * returns the best guess for what the root url of this site is.
 * examples:
 *  - thissite.org/some/file returns ''
 *  - domain.org/thissite/some/file returns '/thissite'
 * root must NOT end in /
 */

function guess_url_root() {
	# the variables we use to determine the site root change depending 
	# on if we are called for an error document, and index, or a file

	$docroot = preg_replace('#/$#','',$_SERVER[DOCUMENT_ROOT]); // trim trailing slash
	
	if (isset($_SERVER['REDIRECT_URL']))
		$path = $docroot . $_SERVER['REDIRECT_URL'];
	else
		$path = $_SERVER['PATH_TRANSLATED'];
		
	# file does not exist
	#if ($_SERVER['SCRIPT_FILENAME'] == $_SERVER['PATH_TRANSLATED']) {
	#	$uribase = preg_replace('#^(/.*?)/.*$#', '$1',$_SERVER['REQUEST_URI']);
	#	
	#}
	
	# file exists
#	else {
		# find the web site root by comparing path_translated (e.g. /var/www/root/file)
		# with the document root (e.g. /var/www/).
		return preg_replace("|^$docroot(/.*?)/.*$|", '$1', $path);
#	}
}

return;
?>