Example #1
0
 /**
  * Returns an absolute URL for the given one
  *
  * @param string $url absilute or relative URL
  * @return string
  */
 public static function absoluteUrl($url)
 {
     if (empty($url)) {
         return OpenID::selfUrl();
     } else {
         if (!preg_match('|^([^:]+)://|', $url)) {
             if (preg_match('|^([^:]+)://([^:@]*(?:[:][^@]*)?@)?([^/:@?#]*)(?:[:]([^/?#]*))?(/[^?]*)?((?:[?](?:[^#]*))?(?:#.*)?)$|', OpenID::selfUrl(), $reg)) {
                 $scheme = $reg[1];
                 $auth = $reg[2];
                 $host = $reg[3];
                 $port = $reg[4];
                 $path = $reg[5];
                 $query = $reg[6];
                 if ($url[0] == '/') {
                     return $scheme . '://' . $auth . $host . (empty($port) ? '' : ':' . $port) . $url;
                 } else {
                     $dir = dirname($path);
                     return $scheme . '://' . $auth . $host . (empty($port) ? '' : ':' . $port) . (strlen($dir) > 1 ? $dir : '') . '/' . $url;
                 }
             }
         }
     }
     return $url;
 }