Exemplo n.º 1
0
 /**
  * blcUtility::normalize_url()
  *
  * @param string $url
  * @params string $base_url (Optional) The base URL is used to convert a relative URL to a fully-qualified one
  * @return string A normalized URL or FALSE if the URL is invalid
  */
 function normalize_url($url, $base_url = '')
 {
     //Sometimes links may contain shortcodes. Parse them.
     $url = do_shortcode($url);
     $parts = @parse_url($url);
     if (!$parts) {
         return false;
     }
     //Invalid URL
     if (isset($parts['scheme'])) {
         //Only HTTP(S) links are checked. Other protocols are not supported.
         if ($parts['scheme'] != 'http' && $parts['scheme'] != 'https') {
             return false;
         }
     }
     $url = html_entity_decode($url);
     $url = preg_replace(array('/([\\?&]PHPSESSID=\\w+)$/i', '/(#[^\\/]*)$/', '/&/', '/^(javascript:.*)/i', '/([\\?&]sid=\\w+)$/i'), array('', '', '&', '', ''), $url);
     $url = trim($url);
     if ($url == '') {
         return false;
     }
     // turn relative URLs into absolute URLs
     if (empty($base_url)) {
         $base_url = get_option('siteurl');
     }
     $url = blcUtility::relative2absolute($base_url, $url);
     return $url;
 }