Index: core/kernel/utility/formatters/upload_formatter.php IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- core/kernel/utility/formatters/upload_formatter.php (revision 15775) +++ core/kernel/utility/formatters/upload_formatter.php (revision ) @@ -443,19 +443,30 @@ */ function GetFormatted($value, $field_name, &$object, $format = NULL) { - if ( !$format || !$value ) { + if ( !$format ) { return $value; } $options = $object->GetFieldOptions($field_name); $upload_dir = isset($options['include_path']) && $options['include_path'] ? '' : $this->getUploadDir($options); + $file_path = strlen($value) ? FULL_PATH . str_replace('/', DIRECTORY_SEPARATOR, $upload_dir) . $value : ''; if ( preg_match('/resize:([\d]*)x([\d]*)/', $format, $regs) ) { $image_helper = $this->Application->recallObject('ImageHelper'); /* @var $image_helper ImageHelper */ - return $image_helper->ResizeImage($value ? FULL_PATH . str_replace('/', DIRECTORY_SEPARATOR, $upload_dir) . $value : '', $format); + try { + return $image_helper->ResizeImage($file_path, $format); - } + } + catch ( \RuntimeException $e ) { + // error, during image resize -> return empty string + return ''; + } + } + elseif ( !strlen($file_path) || !file_exists($file_path) ) { + // file doesn't exist OR not uploaded + return ''; + } switch ($format) { case 'display_name': @@ -463,14 +474,14 @@ break; case 'raw_url': - return $this->fileHelper->pathToUrl(FULL_PATH . $upload_dir . $value); + return $this->fileHelper->pathToUrl($file_path); break; case 'full_url': $direct_links = isset($options['direct_links']) ? $options['direct_links'] : true; if ( $direct_links ) { - return $this->fileHelper->pathToUrl(FULL_PATH . $upload_dir . $value); + return $this->fileHelper->pathToUrl($file_path); } else { $url_params = Array ( @@ -484,18 +495,18 @@ break; case 'full_path': - return FULL_PATH . str_replace('/', DIRECTORY_SEPARATOR, $upload_dir) . $value; + return $file_path; break; case 'file_size': - return filesize(FULL_PATH . str_replace('/', DIRECTORY_SEPARATOR, $upload_dir) . $value); + return filesize($file_path); break; case 'img_size': $image_helper = $this->Application->recallObject('ImageHelper'); /* @var $image_helper ImageHelper */ - $image_info = $image_helper->getImageInfo(FULL_PATH . str_replace('/', DIRECTORY_SEPARATOR, $upload_dir) . $value); + $image_info = $image_helper->getImageInfo($file_path); return $image_info ? $image_info[3] : ''; break; } \ No newline at end of file Index: core/units/helpers/image_helper.php IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- core/units/helpers/image_helper.php (revision 15787) +++ core/units/helpers/image_helper.php (revision ) @@ -75,7 +75,9 @@ * @param string $src_image full path to image (on server) * @param mixed $max_width maximal allowed resized image width or false if no limit * @param mixed $max_height maximal allowed resized image height or false if no limit + * * @return string direct url to resized image + * @throws \RuntimeException When image doesn't exist. */ function ResizeImage($src_image, $max_width, $max_height = false) { @@ -97,6 +99,10 @@ if ((!$src_image || !file_exists($src_image)) && array_key_exists('default', $params) && !(defined('DBG_IMAGE_RECOVERY') && DBG_IMAGE_RECOVERY)) { $src_image = $params['default']; + } + + if ( !strlen($src_image) || !file_exists($src_image) ) { + throw new \RuntimeException(sprintf('Image "%s" doesn\'t exist', $src_image)); } if ($params['max_width'] > 0 || $params['max_height'] > 0) { \ No newline at end of file