improve image source label for Moodpics

This commit is contained in:
oliver 2015-08-20 14:28:34 +02:00
commit ca6af3fe92
4 changed files with 43 additions and 3 deletions

View file

@ -209,6 +209,45 @@
return $mimetype;
}
/**
* Transform an URL to a label.
*
* @static
* @param string $url URL to transform
* @return string Resulting Label
*/
public static function urlToLabel($url)
{
// Parse URL
$parts = parse_url($url);
// Process URL parts
if(is_array($parts) && array_key_exists('host', $parts))
{
// Use only hostname as label
$url = $parts['host'];
}
else
{
// Strip protocol
if(($p = strpos($url, '://')) !== false) {
$url = substr($url, $p+3);
}
// Shorten to a specific length
$url = substr($url, 0, \nre\configs\AppConfig::$misc['imagesource_length']).'…';
}
// Strip www-prefix
if(strpos($url, 'www.') === 0) {
$url = substr($url, strlen('www.'));
}
return $url;
}
}
?>