X-Git-Url: https://dev.renevier.net/?p=syp.git;a=blobdiff_plain;f=inc%2Futils.php;h=a0824c8dea4293d218717c16714a3dfecef26edf;hp=50eb995f29f484cb9fa59920bde03a1d0375da95;hb=57511b4efd7402ef58de66ac1fe2c01ed1b1d7b5;hpb=cbcf49abc26fb050cadf77d8acedfd844ff94dbe diff --git a/inc/utils.php b/inc/utils.php index 50eb995..a0824c8 100644 --- a/inc/utils.php +++ b/inc/utils.php @@ -2,6 +2,8 @@ /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD license. */ +require_once ("inc/settings.php"); + function unquote($gpc_str) { if (!isset ($gpc_str)) { return $gpc_str; @@ -12,4 +14,52 @@ function unquote($gpc_str) { return $gpc_str; } } + +function full_url_from_filename ($filename) { + if (defined ("IMGSDIRURL") && (strlen (IMGSDIRURL) != 0)) { + return rtrim (IMGSDIRURL, '/') . "/" . rawurlencode ($filename); + } + + $rel_path = UPLOADDIR . "/" . rawurlencode ($filename); + + 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 = $_SERVER ["HTTP_HOST"]; + $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"; +} + ?>