mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-23 16:33:17 +01:00
new method Api\Framework::getUrl() to get a full / externally usable Url
This commit is contained in:
parent
8c23fca35e
commit
762c60a61f
@ -170,6 +170,39 @@ abstract class Framework extends Framework\Extra
|
||||
return $GLOBALS['egw']->session->link($url, $extravars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a full / externally usable URL from an EGroupware link
|
||||
*
|
||||
* Code is only used, if the Setup defined webserver_url is only a path!
|
||||
*
|
||||
* The following HTTP Headers / $_SERVER variables and EGroupware configuration
|
||||
* is taken into account to determine if URL should use https schema:
|
||||
* - $_SERVER['HTTPS'] !== off
|
||||
* - $GLOBALS['egw_info']['server']['enforce_ssl'] (EGroupware Setup)
|
||||
* - $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' (X-Forwarded-Proto HTTP header)
|
||||
*
|
||||
* Host is determined in the following order / priority:
|
||||
* 1. $GLOBALS['egw_info']['server']['hostname'] !== 'localhost' (EGroupware Setup)
|
||||
* 2. $_SERVER['HTTP_X_FORWARDED_HOST'] (X-Forwarded-Host HTTP header)
|
||||
* 3. $_SERVER['HTTP_HOST'] (Host HTTP header)
|
||||
*
|
||||
* @param string $link
|
||||
*/
|
||||
static function getUrl($link)
|
||||
{
|
||||
if ($link[0] === '/')
|
||||
{
|
||||
$link = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ||
|
||||
!empty($GLOBALS['egw_info']['server']['enforce_ssl']) || $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ?
|
||||
'https://' : 'http://').
|
||||
($GLOBALS['egw_info']['server']['hostname'] && $GLOBALS['egw_info']['server']['hostname'] !== 'localhost' ?
|
||||
$GLOBALS['egw_info']['server']['hostname'] :
|
||||
(isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'])).
|
||||
$link;
|
||||
}
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles redirects under iis and apache, it does NOT return (calls exit)
|
||||
*
|
||||
|
@ -358,11 +358,8 @@ abstract class Merge
|
||||
$link = Api\Framework::link($link, array());
|
||||
}
|
||||
// Prepend site
|
||||
if ($link{0} == '/')
|
||||
{
|
||||
$link = ($_SERVER['HTTPS'] || $GLOBALS['egw_info']['server']['enforce_ssl'] ? 'https://' : 'http://').
|
||||
($GLOBALS['egw_info']['server']['hostname'] ? $GLOBALS['egw_info']['server']['hostname'] : $_SERVER['HTTP_HOST']).$link;
|
||||
}
|
||||
if ($link[0] == '/') $link = Api\Framework::getUrl($link);
|
||||
|
||||
$title = $style == 'href' ? Api\Html::a_href(Api\Html::htmlspecialchars($title), $link) : $link;
|
||||
}
|
||||
$link_titles[] = $title;
|
||||
@ -417,11 +414,8 @@ abstract class Merge
|
||||
$link = Api\Framework::link($link, array());
|
||||
}
|
||||
// Prepend site
|
||||
if ($link{0} == '/')
|
||||
{
|
||||
$link = ($_SERVER['HTTPS'] || $GLOBALS['egw_info']['server']['enforce_ssl'] ? 'https://' : 'http://').
|
||||
($GLOBALS['egw_info']['server']['hostname'] ? $GLOBALS['egw_info']['server']['hostname'] : $_SERVER['HTTP_HOST']).$link;
|
||||
}
|
||||
if ($link[0] == '/') $link = Api\Framework::getUrl($link);
|
||||
|
||||
$array[($prefix?$prefix.'/':'').$placeholder] = Api\Html::a_href(Api\Html::htmlspecialchars($title), $link);
|
||||
break;
|
||||
case 'links':
|
||||
|
@ -966,15 +966,12 @@ abstract class Tracking
|
||||
{
|
||||
if (($view = Api\Link::view($this->app,$data[$this->id_field])))
|
||||
{
|
||||
$link = $GLOBALS['egw']->link('/index.php',$view);
|
||||
$link = Api\Framework::link('/index.php',$view);
|
||||
$popup = Api\Link::is_popup($this->app,'view');
|
||||
}
|
||||
}
|
||||
if ($link[0] == '/')
|
||||
{
|
||||
$link = ($_SERVER['HTTPS'] || $GLOBALS['egw_info']['server']['enforce_ssl'] ? 'https://' : 'http://').
|
||||
($GLOBALS['egw_info']['server']['hostname'] ? $GLOBALS['egw_info']['server']['hostname'] : $_SERVER['HTTP_HOST']).$link;
|
||||
}
|
||||
if ($link[0] == '/') Api\Framework::getUrl($link);
|
||||
|
||||
if (!$allow_popup)
|
||||
{
|
||||
// remove the session-id in the notification mail!
|
||||
|
@ -675,21 +675,13 @@ class Sharing
|
||||
* Generate link from share or share-token
|
||||
*
|
||||
* @param string|array $share share or share-token
|
||||
* @return string
|
||||
* @return string full Url incl. schema and host
|
||||
*/
|
||||
public static function share2link($share)
|
||||
{
|
||||
if (is_array($share)) $share = $share['share_token'];
|
||||
|
||||
$link = Api\Framework::link('/share.php').'/'.$share;
|
||||
if ($link[0] == '/')
|
||||
{
|
||||
$link = ($_SERVER['HTTPS'] ? 'https://' : 'http://').
|
||||
($GLOBALS['egw_info']['server']['hostname'] && $GLOBALS['egw_info']['server']['hostname'] !== 'localhost' ?
|
||||
$GLOBALS['egw_info']['server']['hostname'] : $_SERVER['HTTP_HOST']).
|
||||
$link;
|
||||
}
|
||||
return $link;
|
||||
return Api\Framework::getUrl(Api\Framework::link('/share.php')).'/'.$share;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1796,12 +1796,7 @@ class calendar_boupdate extends calendar_bo
|
||||
$eventStart_arr = $this->date2array($event['start']); // give this as 'date' to the link to pick the right recurrence for the participants state
|
||||
$link = $GLOBALS['egw_info']['server']['webserver_url'].'/index.php?menuaction=calendar.calendar_uiforms.edit&cal_id='.$event['id'].'&date='.$eventStart_arr['full'].'&no_popup=1&ajax=true';
|
||||
// if url is only a path, try guessing the rest ;-)
|
||||
if ($link[0] == '/')
|
||||
{
|
||||
$link = ($GLOBALS['egw_info']['server']['enforce_ssl'] || $_SERVER['HTTPS'] ? 'https://' : 'http://').
|
||||
($GLOBALS['egw_info']['server']['hostname'] ? $GLOBALS['egw_info']['server']['hostname'] : $_SERVER['HTTP_HOST']).
|
||||
$link;
|
||||
}
|
||||
if ($link[0] == '/') $link = Api\Framework::getUrl($link);
|
||||
$event_arr['link']['data'] = $details['link'] = $link;
|
||||
|
||||
/* this is needed for notification-app
|
||||
|
@ -200,11 +200,8 @@ class filemanager_merge extends Api\Storage\Merge
|
||||
}
|
||||
|
||||
// Prepend site, if missing
|
||||
if ($link{0} == '/')
|
||||
{
|
||||
$link = ($_SERVER['HTTPS'] || $GLOBALS['egw_info']['server']['enforce_ssl'] ? 'https://' : 'http://').
|
||||
($GLOBALS['egw_info']['server']['hostname'] ? $GLOBALS['egw_info']['server']['hostname'] : $_SERVER['HTTP_HOST']).$link;
|
||||
}
|
||||
if ($link[0] == '/') $link = Api\Framework::getUrl($link);
|
||||
|
||||
$file['link'] = Api\Html::a_href(Api\Html::htmlspecialchars($file['name']), $link);
|
||||
$file['url'] = $link;
|
||||
|
||||
|
@ -157,10 +157,7 @@ class notifications_email implements notifications_iface {
|
||||
// do not expose sensitive data
|
||||
$url = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',Api\Html::link('/index.php', $link->view));
|
||||
// complete missing protocol and domain part if needed
|
||||
if ($url{0} == '/' && $_render_external) {
|
||||
$url = ($_SERVER['HTTPS'] || $GLOBALS['egw_info']['server']['enforce_ssl'] ? 'https://' : 'http://').
|
||||
($GLOBALS['egw_info']['server']['hostname'] ? $GLOBALS['egw_info']['server']['hostname'] : $_SERVER['HTTP_HOST']).$url;
|
||||
}
|
||||
if ($url[0] == '/' && $_render_external) $url = Api\Framework::getUrl($url);
|
||||
$a_href = '<a href="'.$url.'" target="_blank">'.$link->text.'</a>';
|
||||
$rendered_links[] = $_render_html ? $a_href : $url;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user