I have a plugin that uses makeUrl when a document gets saved.
$modx->makeUrl($doc['id'])
This works fine in multiple contexts, with and without friendly URLs enabled.
My problem is that not all MODx installations have a
site_url set. Because of that I am using this method to determine if a hostname is present and act accordingly.
protected function form_url($url = NULL)
{
$host = FALSE;
if($parsed = parse_url($url))
{
if($parsed['host'])
$host = TRUE;
}
// FIXME: Is SERVER_NAME reliable enough?
return $url = ($host) ? $url : 'http://' . $_SERVER['SERVER_NAME'] . '/' . $url;
}
The last line is what I am concerned about - its crap. Does anyone have any suggestions or tips on how to approach this? Note: $url is actually the alias returned by makeUrl.