Aleksander Machniak
2014-08-24 5f58127eae9ed8c54c190506e11af13e8ba57170
Added rcube_utils::resolve_url()
2 files modified
55 ■■■■■ changed files
program/include/rcmail.php 25 ●●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_utils.php 30 ●●●●● patch | view | raw | blame | history
program/include/rcmail.php
@@ -827,26 +827,17 @@
        }
        if ($absolute || $full) {
            $prefix = '';
            // prepend protocol://hostname:port
            if ($full) {
                $schema = 'http';
                $default_port = 80;
                if (rcube_utils::https_check()) {
                    $schema = 'https';
                    $default_port = 443;
                }
                $prefix = $schema . '://' . preg_replace('/:\d+$/', '', $_SERVER['HTTP_HOST']);
                if ($_SERVER['SERVER_PORT'] != $default_port) {
                  $prefix .= ':' . $_SERVER['SERVER_PORT'];
                }
            }
            // add base path to this Roundcube installation
            $base_path = preg_replace('![^/]+$!', '', strval($_SERVER['SCRIPT_NAME']));
            if ($base_path == '') $base_path = '/';
            $prefix .= $base_path;
            $prefix = $base_path;
            // prepend protocol://hostname:port
            if ($full) {
                $prefix = rcube_utils::resolve_url($prefix);
            }
            $prefix = rtrim($prefix, '/') . '/';
        }
        else {
            $prefix = './';
program/lib/Roundcube/rcube_utils.php
@@ -1071,4 +1071,34 @@
            return $path[0] == DIRECTORY_SEPARATOR;
        }
    }
    /**
     * Resolve relative URL
     *
     * @param string $url Relative URL
     *
     * @return string Absolute URL
     */
    public static function resolve_url($url)
    {
        // prepend protocol://hostname:port
        if (!preg_match('|^https?://|', $url)) {
            $schema       = 'http';
            $default_port = 80;
            if (self::https_check()) {
                $schema       = 'https';
                $default_port = 443;
            }
            $prefix = $schema . '://' . preg_replace('/:\d+$/', '', $_SERVER['HTTP_HOST']);
            if ($_SERVER['SERVER_PORT'] != $default_port) {
                $prefix .= ':' . $_SERVER['SERVER_PORT'];
            }
            $url = $prefix . ($url[0] == '/' ? '' : '/') . $url;
        }
        return $url;
    }
}