Commit f2155ae0 authored by Art4's avatar Art4
parent beb80057
......@@ -145,34 +145,43 @@ function scrd_initialize_feed($feed_url) {
/**
* Expand short urls
*
* via http://sudarmuthu.com/blog/expand-any-shortened-url-using-php
*
* @param <string> $url - Short url
* @return <string> - Longer version of the short url
*/
* Expand short urls
*
* via http://sudarmuthu.com/blog/expand-any-shortened-url-using-php
*
* @param string $url Short url
* @return string Longer version of the short url
*/
function scrd_expand_url($url)
{
//Get response headers
$response = get_headers($url, 1);
$url_parts = parse_url($url);
$domain = $url_parts['scheme'] . '://' . $url_parts['host'];
//Get the location property of the response header. If failure, return original url
if (array_key_exists('Location', $response))
if (is_array($response) and array_key_exists('Location', $response))
{
$location = $response["Location"];
if (is_array($location))
{
// t.co gives Location as an array
return scrd_expand_url($location[count($location) - 1]);
$location = $location[count($location) - 1];
}
else
// Golem.de setzt keine Domain vor die Url
$url_parts = parse_url($location);
if ( ! array_key_exists('host', $url_parts) or $url_parts['host'] === null )
{
return scrd_expand_url($location);
$location = $domain . $location;
}
return scrd_expand_url($location);
}
return $url;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment