<?php

function getFileSystemRoot() {
static $firstTime = 1;
static $root = "/var/www/sites/homecontrol";

	if ($firstTime) {
		$sysroot = exec(getMinervaRoot()."/bin/getalias webroot");
		$firstTime = 0;
		if ($sysroot != "") {
			$root = $sysroot;
		}
	}
	return $root;
}

function getMinervaRoot() {
   return "/usr/local/minerva";
}

function getWebRelativePath($url) {
	// If this $url is under the filesystem root, we return a suitable
	// path that can be referenced by the web server, so that external
	// clients can access it.
	// If the $url is outside our root, we fail and return null.

	$root = getFileSystemRoot();

	if (substr($url, 0, strlen($root)) == $root) {
		return substr($url, strlen($root));
	}
	return null;
}

?>

