katgirl / contao-avatar

avatar for contao
8 stars 6 forks source link

avatar_fallback_image is optional and causes problems in AvatarFileUpload::generate #45

Open fritzmg opened 9 years ago

fritzmg commented 9 years ago

Since the fallback image is optional, the following code causes problems:

if(count($arrValues) === 0)
{
  $objFile = \FilesModel::findByPath($GLOBALS['TL_CONFIG']['avatar_fallback_image']);    
  $strInfo = $objFile->path . ' <span class="tl_gray">(' . $this->getReadableSize($objFile->size) . ($objFile->isGdImage ? ', ' . $arrImage[0] . 'x' . $arrImage[1] . ' px' : '') . ')</span>';
  $arrValues[$objFile->uuid] = \Image::getHtml(\Image::get($objFile->path, $arrImage[0], $arrImage[1], $arrImage[2]), '', 'class="gimage" title="' . specialchars($strInfo) . '"');
}

in AvatarFileUpload.php#L181. When no fallback image is set, there will be an error whenever the widget is generated for a user, that does not have an avatar image set. It should instead say

if(count($arrValues) === 0)
{
  if(($objFile = \FilesModel::findByPath($GLOBALS['TL_CONFIG']['avatar_fallback_image'])) !== null)
  {    
    $strInfo = $objFile->path . ' <span class="tl_gray">(' . $this->getReadableSize($objFile->size) . ($objFile->isGdImage ? ', ' . $arrImage[0] . 'x' . $arrImage[1] . ' px' : '') . ')</span>';
    $arrValues[$objFile->uuid] = \Image::getHtml(\Image::get($objFile->path, $arrImage[0], $arrImage[1], $arrImage[2]), '', 'class="gimage" title="' . specialchars($strInfo) . '"');
  }
}
katgirl commented 9 years ago

is in Master and develop fixed

fritzmg commented 9 years ago

Well, you are just checking for

$GLOBALS['TL_CONFIG']['avatar_fallback_image'] != ''

But if the file gets deleted, it will again lead to an error. Actually you would neet both the null check and a file_exists check.