public static function url($uri, $full = false, $opts = array())
{
if (is_array($opts)) {
$append_session = isset($opts['append_session']) ? $opts['append_session'] : 0;
if (!empty($opts['force_ssl'])) {
$full = true;
}
} else {
$append_session = $opts;
$opts = array();
}
$puri = parse_url($uri);
/* @todo Fix for PHP < 5.3.6 */
if (isset($puri['fragment']) && !isset($puri['path'])) {
$pos = strpos($uri, '/', strpos($uri, $puri['host']) + strlen($puri['host']));
$puri['path'] = substr($uri, $pos, strpos($uri, '#', $pos) - $pos);
}
/* End fix */
$url = '';
$schemeRegexp = '|^([a-zA-Z][a-zA-Z0-9+.-]{0,19})://|';
$webroot = ltrim($GLOBALS['registry']->get('webroot', empty($opts['app']) ? null : $opts['app']), '/');
if ($full && !isset($puri['scheme']) && !preg_match($schemeRegexp, $webroot)) {
/* Store connection parameters in local variables. */
$server_name = $GLOBALS['conf']['server']['name'];
$server_port = isset($GLOBALS['conf']['server']['port']) ? $GLOBALS['conf']['server']['port'] : '';
$protocol = 'http';
switch ($GLOBALS['conf']['use_ssl']) {
case self::SSL_ALWAYS:
$protocol = 'https';
break;
case self::SSL_AUTO:
if ($GLOBALS['browser']->usingSSLConnection()) {
$protocol = 'https';
}
break;
case self::SSL_ONLY_LOGIN:
if (!empty($opts['force_ssl'])) {
$protocol = 'https';
$server_port = '';
}
break;
}
/* If using a non-standard port, add to the URL. */
if (!empty($server_port) && ($protocol == 'http' && $server_port != 80 || $protocol == 'https' && $server_port != 443)) {
$server_name .= ':' . $server_port;
}
$url = $protocol . '://' . $server_name;
} elseif (isset($puri['scheme'])) {
$url = $puri['scheme'] . '://' . $puri['host'];
/* If using a non-standard port, add to the URL. */
if (isset($puri['port']) && ($puri['scheme'] == 'http' && $puri['port'] != 80 || $puri['scheme'] == 'https' && $puri['port'] != 443)) {
$url .= ':' . $puri['port'];
}
}
if (isset($puri['path']) && substr($puri['path'], 0, 1) == '/' && (!preg_match($schemeRegexp, $webroot) || preg_match($schemeRegexp, $webroot) && isset($puri['scheme']))) {
$url .= $puri['path'];
} elseif (isset($puri['path']) && preg_match($schemeRegexp, $webroot)) {
if (substr($puri['path'], 0, 1) == '/') {
$pwebroot = parse_url($webroot);
$url = $pwebroot['scheme'] . '://' . $pwebroot['host'] . $puri['path'];
} else {
$url = $webroot . '/' . $puri['path'];
}
} else {
$url .= '/' . ($webroot ? $webroot . '/' : '') . (isset($puri['path']) ? $puri['path'] : '');
}
if (isset($puri['query'])) {
$url .= '?' . $puri['query'];
}
if (isset($puri['fragment'])) {
$url .= '#' . $puri['fragment'];
}
$ob = new Horde_Url($url, $full);
if (empty($GLOBALS['conf']['session']['use_only_cookies']) && ($append_session == 1 || $append_session == 0 && !isset($_COOKIE[session_name()]))) {
$ob->add(session_name(), session_id());
}
return $ob;
}