improve image source label for Moodpics
This commit is contained in:
parent
fc587be483
commit
ca6af3fe92
4 changed files with 43 additions and 3 deletions
|
|
@ -209,6 +209,45 @@
|
||||||
return $mimetype;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,8 @@
|
||||||
'ranking_range' => 2,
|
'ranking_range' => 2,
|
||||||
'achievements_range' => 3,
|
'achievements_range' => 3,
|
||||||
'title_delimiter' => ' – ',
|
'title_delimiter' => ' – ',
|
||||||
'lists_limit' => 10
|
'lists_limit' => 10,
|
||||||
|
'imagesource_length' => 30
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
<?php if(!is_null($medium)) : ?>
|
<?php if(!is_null($medium)) : ?>
|
||||||
<img src="<?=$medium['url']?>" <?php if(!empty($medium['title'])) : ?>title="<?=$medium['title']?>"<?php endif ?> <?php if(!empty($medium['description'])) : ?>alt="<?=$medium['description']?>"<?php endif ?>/>
|
<img src="<?=$medium['url']?>" <?php if(!empty($medium['title'])) : ?>title="<?=$medium['title']?>"<?php endif ?> <?php if(!empty($medium['description'])) : ?>alt="<?=$medium['description']?>"<?php endif ?>/>
|
||||||
<?php if(!empty($medium['sourcelabel']) || !empty($medium['sourceurl'])) : ?>
|
<?php if(!empty($medium['sourcelabel']) || !empty($medium['sourceurl'])) : ?>
|
||||||
<?php $label = (!empty($medium['sourcelabel'])) ? $medium['sourcelabel'] : substr($medium['sourceurl'], 0, 30).'…'; ?>
|
<?php $label = (!empty($medium['sourcelabel'])) ? $medium['sourcelabel'] : \hhu\z\Utils::urlToLabel($medium['sourceurl']); ?>
|
||||||
<span class="source">
|
<span class="source">
|
||||||
<?=_('Image source')?>:
|
<?=_('Image source')?>:
|
||||||
<?php if(!empty($medium['sourceurl'])): ?>
|
<?php if(!empty($medium['sourceurl'])): ?>
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
<?php if(!is_null($medium)) : ?>
|
<?php if(!is_null($medium)) : ?>
|
||||||
<img src="<?=$medium['url']?>" <?php if(!empty($medium['title'])) : ?>title="<?=$medium['title']?>"<?php endif ?> <?php if(!empty($medium['description'])) : ?>alt="<?=$medium['description']?>"<?php endif ?>/>
|
<img src="<?=$medium['url']?>" <?php if(!empty($medium['title'])) : ?>title="<?=$medium['title']?>"<?php endif ?> <?php if(!empty($medium['description'])) : ?>alt="<?=$medium['description']?>"<?php endif ?>/>
|
||||||
<?php if(!empty($medium['sourcelabel']) || !empty($medium['sourceurl'])) : ?>
|
<?php if(!empty($medium['sourcelabel']) || !empty($medium['sourceurl'])) : ?>
|
||||||
<?php $label = (!empty($medium['sourcelabel'])) ? $medium['sourcelabel'] : substr($medium['sourceurl'], 0, 30).'…'; ?>
|
<?php $label = (!empty($medium['sourcelabel'])) ? $medium['sourcelabel'] : \hhu\z\Utils::urlToLabel($medium['sourceurl']); ?>
|
||||||
<span class="source">
|
<span class="source">
|
||||||
<?=_('Image source')?>:
|
<?=_('Image source')?>:
|
||||||
<?php if(!empty($medium['sourceurl'])): ?>
|
<?php if(!empty($medium['sourceurl'])): ?>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue