--- a/include/Util.class.php +++ b/include/Util.class.php @@ -44,6 +44,11 @@ return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'); } + public static function NullFile() + { + return self::IsWindows() ? 'NUL' : '/dev/null'; + } + /** * Tests if this is a 64 bit machine * @@ -63,10 +68,10 @@ public static function MakeSlug($str) { $from = array( - '/' + '/&' ); $to = array( - '-' + '--' ); return str_replace($from, $to, $str); } @@ -144,5 +149,50 @@ return $files; } + /** + * Get the base install url (without index) + * + * @param boolean $full true to return full url (include protocol and hostname) + * @return string base url + */ + public static function BaseUrl($full = false) + { + $baseurl = $_SERVER['SCRIPT_NAME']; + if (substr_compare($baseurl, 'index.php', -9) === 0) + $baseurl = dirname($baseurl); + if ($full) { + $baseurl = $_SERVER['HTTP_HOST'] . $baseurl; + if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on')) + $baseurl = 'https://' . $baseurl; + else + $baseurl = 'http://' . $baseurl; + } + if (GitPHP_Util::IsWindows()) + $baseurl = rtrim($baseurl, "\\"); + return rtrim($baseurl, "/"); + } + + /** + * Tests whether a function is allowed to be called + * + * @param string $function functio name + * @return true if allowed + */ + public static function FunctionAllowed($function) + { + if (empty($function)) + return false; + + $disabled = @ini_get('disable_functions'); + if (!$disabled) { + // no disabled functions + // or ini_get is disabled so we can't reliably figure this out + return true; + } + + $disabledlist = explode(', ', $disabled); + return !in_array($function, $disabledlist); + } + }