public static url ( mixed $uri, boolean $full = false, mixed $opts = [] ) : Horde_Url | ||
$uri | mixed | The URI to be modified (either a string or any object with a __toString() function). |
$full | boolean | Generate a full (http://server/path/) URL. |
$opts | mixed | Additional options. If a string/integer, it is taken to be the 'append_session' option. If an array, one of the following: - app: (string) Use this app for the webroot. DEFAULT: current application - append_session: (integer) 0 = only if needed [DEFAULT], 1 = always, -1 = never. - force_ssl: (boolean) Ignore $conf['use_ssl'] and force creation of a SSL URL? DEFAULT: false |
return | Horde_Url | The URL with the session id appended (if needed). |
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;
}
/** * Sends a message to an email address supposed to be added to the * identity. * * A message is send to this address containing a time-sensitive link to * confirm that the address really belongs to that user. * * @param integer $id The identity's ID. * @param string $old_addr The old From: address. * * @throws Horde_Mime_Exception */ public function verifyIdentity($id, $old_addr) { global $injector, $notification, $registry; $hash = strval(new Horde_Support_Randomid()); $pref = $this->_confirmEmail(); $pref[$hash] = $this->get($id); $pref[$hash][self::EXPIRE] = time() + self::EXPIRE_SECS; $this->_confirmEmail($pref); $new_addr = $this->getValue($this->_prefnames['from_addr'], $id); $confirm = Horde::url($registry->getServiceLink('emailconfirm')->add('h', $hash)->setRaw(true), true); $message = sprintf(Horde_Core_Translation::t("You have requested to add the email address \"%s\" to the list of your personal email addresses.\n\nGo to the following link to confirm that this is really your address:\n%s\n\nIf you don't know what this message means, you can delete it."), $new_addr, $confirm); $msg_headers = new Horde_Mime_Headers(); $msg_headers->addHeaderOb(Horde_Mime_Headers_MessageId::create()); $msg_headers->addHeaderOb(Horde_Mime_Headers_UserAgent::create()); $msg_headers->addHeaderOb(Horde_Mime_Headers_Date::create()); $msg_headers->addHeader('To', $new_addr); $msg_headers->addHeader('From', $old_addr); $msg_headers->addHeader('Subject', Horde_Core_Translation::t("Confirm new email address")); $body = new Horde_Mime_Part(); $body->setType('text/plain'); $body->setContents(Horde_String::wrap($message, 76)); $body->setCharset('UTF-8'); $body->send($new_addr, $msg_headers, $injector->getInstance('Horde_Mail')); $notification->push(sprintf(Horde_Core_Translation::t("A message has been sent to \"%s\" to verify that this is really your address. The new email address is activated as soon as you confirm this message."), $new_addr), 'horde.message'); }