From 0e25e00d921f4627def5b28101c2e7e04d9db796 Mon Sep 17 00:00:00 2001
From: shish <shish@7f39781d-f577-437e-ae19-be835c7a54ca>
Date: Sun, 5 Aug 2007 22:03:43 +0000
Subject: [PATCH] argh. 20 ways of finding the install folder, and none of them
 work -_-

git-svn-id: file:///home/shish/svn/shimmie2/trunk@424 7f39781d-f577-437e-ae19-be835c7a54ca
---
 core/util.inc.php | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/core/util.inc.php b/core/util.inc.php
index d3c8ba31..21c3816e 100644
--- a/core/util.inc.php
+++ b/core/util.inc.php
@@ -210,8 +210,20 @@ function get_memory_limit() {
 	return $memory;
 }
 
+/*
+ * PHP really, really sucks.
+ */
 function get_base_href() {
-	$dir = dirname($_SERVER['SCRIPT_NAME']);
+	$possible_vars = array('SCRIPT_NAME', 'PHP_SELF', 'PATH_INFO', 'ORIG_PATH_INFO');
+	$ok_var = null;
+	foreach($possible_vars as $var) {
+		if(substr($_SERVER[$var], -4) == '.php') {
+			$ok_var = $_SERVER[$var];
+			break;
+		}
+	}
+	assert(!empty($ok_var));
+	$dir = dirname($ok_var);
 	if($dir == "/") $dir = "";
 	return $dir;
 }