/* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
license. */
+require_once ("inc/settings.php");
+
+function gethost() {
+ $host = $_SERVER ["HTTP_HOST"];
+ $colpos = strpos ($host, ':');
+ // some web clients add port informations in Host header
+ if ($colpos !== false) {
+ $host = substr ($host, 0, $colpos);
+ }
+ return $host;
+}
+
+function basename_safe ($path) {
+ return end (explode ("/", $path));
+}
+
function unquote($gpc_str) {
if (!isset ($gpc_str)) {
return $gpc_str;
return $gpc_str;
}
}
+
+function full_url_from_imgpath ($filename) {
+ if (defined ("IMGSDIRURL") && (strlen (IMGSDIRURL) != 0)) {
+ return rtrim (IMGSDIRURL, '/') . "/" . rawurlencode ($filename);
+ }
+
+ $rel_path = UPLOADDIR . "/" . rawurlencode ($filename);
+
+ return full_url_from_path (UPLOADDIR . "/" . rawurlencode ($filename));
+}
+
+function full_url_from_path ($path) {
+ $rel_path = $path;
+
+ while (substr($rel_path, 0, 2) == "./") { // strips ./
+ $rel_path = substr ($rel_path, 2);
+ }
+
+ if ($rel_path [0] == "/") {
+ $path = $rel_path;
+ } else {
+ $script_dir = dirname ($_SERVER ["SCRIPT_NAME"]);
+ while ((substr ($rel_path, 0, 3) == "../") &&
+ (strlen($script_dir) != 0)) {
+ $rel_path = substr ($rel_path, 3);
+ while (substr($rel_path, 0, 2) == "./") {
+ $rel_path = substr ($rel_path, 2);
+ }
+ $script_dir = substr ($script_dir, 0, strrpos ($script_dir, "/"));
+ }
+ if ((strlen ($script_dir) == 0) && (substr ($rel_path, 0, 3) == "../")) {
+ return null;
+ }
+ $path = "$script_dir/$rel_path";
+ }
+
+ $host = gethost();
+ $port = $_SERVER ["SERVER_PORT"];
+ if ($_SERVER ["HTTPS"] == "on") {
+ $proto = "https";
+ } else {
+ $proto = "http";
+ }
+
+ if (($port == "80" && $proto == "http") ||
+ ($port == "443" && $proto == "https")) {
+ $port = "";
+ } else {
+ $port = ":$port";
+ }
+
+ return "$proto://$host$port$path";
+}
?>