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 basename_safe ($path) {
18 return end (explode ("/", $path));
21 function unquote($gpc_str) {
22 if (!isset ($gpc_str)) {
25 if (get_magic_quotes_gpc ()) {
26 return stripslashes ($gpc_str);
32 function full_url_from_imgpath ($filename) {
33 if (defined ("IMGSDIRURL") && (strlen (IMGSDIRURL) != 0)) {
34 return rtrim (IMGSDIRURL, '/') . "/" . rawurlencode ($filename);
37 $rel_path = UPLOADDIR . "/" . rawurlencode ($filename);
39 return full_url_from_path (UPLOADDIR . "/" . rawurlencode ($filename));
42 function full_url_from_path ($path) {
45 while (substr($rel_path, 0, 2) == "./") { // strips ./
46 $rel_path = substr ($rel_path, 2);
49 if ($rel_path [0] == "/") {
52 $script_dir = dirname ($_SERVER ["SCRIPT_NAME"]);
53 while ((substr ($rel_path, 0, 3) == "../") &&
54 (strlen($script_dir) != 0)) {
55 $rel_path = substr ($rel_path, 3);
56 while (substr($rel_path, 0, 2) == "./") {
57 $rel_path = substr ($rel_path, 2);
59 $script_dir = substr ($script_dir, 0, strrpos ($script_dir, "/"));
61 if ((strlen ($script_dir) == 0) && (substr ($rel_path, 0, 3) == "../")) {
64 $path = "$script_dir/$rel_path";
68 $port = $_SERVER ["SERVER_PORT"];
69 if ($_SERVER ["HTTPS"] == "on") {
75 if (($port == "80" && $proto == "http") ||
76 ($port == "443" && $proto == "https")) {
82 return "$proto://$host$port$path";