fix a tiny bug where imageName would've been assigned to the last file in dir even if it was not on the extension list.

also rewrite a bit (and fix braces)
This commit is contained in:
Piotr KUCHARSKI 2014-11-26 22:04:26 +01:00
parent 4a36279803
commit 83064dce70

View file

@ -58,25 +58,34 @@ if (!function_exists('exif_read_data') && $display_exif == 1) {
function padstring($name, $length) function padstring($name, $length)
{ {
global $label_max_length; global $label_max_length;
if (!isset($length)) if (!isset($length)) {
$length = $label_max_length; $length = $label_max_length;
if (strlen($name) > $length) }
if (strlen($name) > $length) {
return substr($name, 0, $length) . "..."; return substr($name, 0, $length) . "...";
}
return $name; return $name;
} }
function getfirstImage($dirname) function getfirstImage($dirname)
{ {
$imageName = false; $imageName = false;
$ext = array("jpg", "png", "jpeg", "gif", "JPG", "PNG", "GIF", "JPEG"); $extensions = array("jpg", "png", "jpeg", "gif");
if ($handle = opendir($dirname)) { if ($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))) { while(false !== ($file = readdir($handle))) {
$lastdot = strrpos($file, '.'); if ($file[0] == '.') {
$extension = substr($file, $lastdot + 1); continue;
if ($file[0] != '.' && in_array($extension, $ext)) }
$pathinfo = pathinfo($file);
if (empty($pathinfo['extension'])) {
continue;
}
$ext = strtolower($pathinfo['extension']);
if (in_array($ext, $extensions)) {
$imageName = $file;
break; break;
} }
$imageName = $file; }
closedir($handle); closedir($handle);
} }
return $imageName; return $imageName;