2 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
5 require_once ("inc/settings.php");
8 $host = $_SERVER ["HTTP_HOST"];
9 $colpos = strpos ($host, ':');
10 // some web clients add port informations in Host header
11 if ($colpos !== false) {
12 $host = substr ($host, 0, $colpos);
17 function unquote($gpc_str) {
18 if (!isset ($gpc_str)) {
21 if (get_magic_quotes_gpc ()) {
22 return stripslashes ($gpc_str);
28 function full_url_from_imgpath ($filename) {
29 if (defined ("IMGSDIRURL") && (strlen (IMGSDIRURL) != 0)) {
30 return rtrim (IMGSDIRURL, '/') . "/" . rawurlencode ($filename);
33 $rel_path = UPLOADDIR . "/" . rawurlencode ($filename);
35 return full_url_from_path (UPLOADDIR . "/" . rawurlencode ($filename));
38 function full_url_from_path ($path) {
41 while (substr($rel_path, 0, 2) == "./") { // strips ./
42 $rel_path = substr ($rel_path, 2);
45 if ($rel_path [0] == "/") {
48 $script_dir = dirname ($_SERVER ["SCRIPT_NAME"]);
49 while ((substr ($rel_path, 0, 3) == "../") &&
50 (strlen($script_dir) != 0)) {
51 $rel_path = substr ($rel_path, 3);
52 while (substr($rel_path, 0, 2) == "./") {
53 $rel_path = substr ($rel_path, 2);
55 $script_dir = substr ($script_dir, 0, strrpos ($script_dir, "/"));
57 if ((strlen ($script_dir) == 0) && (substr ($rel_path, 0, 3) == "../")) {
60 $path = "$script_dir/$rel_path";
64 $port = $_SERVER ["SERVER_PORT"];
65 if ($_SERVER ["HTTPS"] == "on") {
71 if (($port == "80" && $proto == "http") ||
72 ($port == "443" && $proto == "https")) {
78 return "$proto://$host$port$path";