/**
* Obtains a SimpleID URL. URLs produced by SimpleID should use this function.
*
* @param string $path the FatFree path or alias
* @param string $query a properly encoded query string
* @param string $secure if $relative is false, either 'https' to force an HTTPS connection, 'http' to force
* an unencrypted HTTP connection, 'detect' to base on the current connection, or NULL to vary based on SIMPLEID_BASE_URL
* @return string the url
*
* @since 0.7
*/
public function getCanonicalURL($path = '', $query = '', $secure = null)
{
$config = $this->f3->get('config');
$canonical_base_path = $config['canonical_base_path'];
if (preg_match('/^(?:@(\\w+)(?:(\\(.+?)\\))*|https?:\\/\\/)/', $path, $parts)) {
if (isset($parts[1])) {
$aliases = $this->f3->get('ALIASES');
if (!empty($aliases[$parts[1]])) {
$path = $aliases[$parts[1]];
$path = $this->f3->build($path, isset($parts[2]) ? $this->f3->parse($parts[2]) : array());
$path = ltrim($path, '/');
}
}
}
// Make sure that the base has a trailing slash
if (substr($config['canonical_base_path'], -1) == '/') {
$url = $config['canonical_base_path'];
} else {
$url = $config['canonical_base_path'] . '/';
}
if ($secure == 'https' && stripos($url, 'http:') === 0) {
$url = 'https:' . substr($url, 5);
}
if ($secure == 'http' && stripos($url, 'https:') === 0) {
$url = 'http:' . substr($url, 6);
}
if ($secure == 'detect' && $this->isHttps() && stripos($url, 'http:') === 0) {
$url = 'https:' . substr($url, 5);
}
if ($secure == 'detect' && !$this->isHttps() && stripos($url, 'https:') === 0) {
$url = 'http:' . substr($url, 6);
}
$url .= $path . ($query == '' ? '' : '?' . $query);
return $url;
}