SPR-787 use same logo resized
This commit is contained in:
parent
2387fd467e
commit
06cdf1484d
3 changed files with 107 additions and 20 deletions
40
Template.php
40
Template.php
|
@ -30,7 +30,6 @@ class Template {
|
|||
return $instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Template constructor.
|
||||
*/
|
||||
|
@ -80,4 +79,43 @@ class Template {
|
|||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an image tag and includes the first found image correctly resized
|
||||
*
|
||||
* @param string $tag
|
||||
* @param array $attributes
|
||||
* @param int $w
|
||||
* @param int $h
|
||||
* @return string
|
||||
*/
|
||||
public static function getResizedImgTag($tag, $attributes, $w, $h) {
|
||||
$attr = '';
|
||||
$medias = array();
|
||||
|
||||
// the attribute having an array defines where the image goes
|
||||
foreach($attributes as $attribute => $data) {
|
||||
if(is_array($data)) {
|
||||
$medias = $data;
|
||||
$attr = $attribute;
|
||||
}
|
||||
}
|
||||
// if the image attribute could not be found return
|
||||
if(!$attr || !$medias) return '';
|
||||
|
||||
// try all medias until an existing one is found
|
||||
$media = '';
|
||||
foreach($medias as $media) {
|
||||
if(file_exists(mediaFN($media))) break;
|
||||
$media = '';
|
||||
}
|
||||
if($media === '') return '';
|
||||
|
||||
// replace the array
|
||||
$media = ml($media, array('w' => $w, 'h' => $h, 'crop' => 1), true, '&');
|
||||
$attributes[$attr] = $media;
|
||||
|
||||
// return the full tag
|
||||
return '<' . $tag . ' ' . buildAttributes($attributes) . ' />';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue