Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/kernel/utility/formatters/upload_formatter.php
Show First 20 Lines • Show All 216 Lines • ▼ Show 20 Line(s) | |||||
} | } | ||||
else { | else { | ||||
$real_name = $this->_getRealFilename($value['name'], $options, $object); | $real_name = $this->_getRealFilename($value['name'], $options, $object); | ||||
$file_name = $this->FullPath . $real_name; | $file_name = $this->FullPath . $real_name; | ||||
$storage_format = isset($options['storage_format']) ? $options['storage_format'] : false; | $storage_format = isset($options['storage_format']) ? $options['storage_format'] : false; | ||||
if ( $storage_format ) { | if ( $storage_format ) { | ||||
/** @var ImageHelper $image_helper */ | |||||
$image_helper = $this->Application->recallObject('ImageHelper'); | $image_helper = $this->Application->recallObject('ImageHelper'); | ||||
/* @var $image_helper ImageHelper */ | |||||
move_uploaded_file($value['tmp_name'], $value['tmp_name'] . '.jpg'); // add extension, so ResizeImage can work | move_uploaded_file($value['tmp_name'], $value['tmp_name'] . '.jpg'); // add extension, so ResizeImage can work | ||||
$url = $image_helper->ResizeImage($value['tmp_name'] . '.jpg', $storage_format); | $url = $image_helper->ResizeImage($value['tmp_name'] . '.jpg', $storage_format); | ||||
$tmp_name = preg_replace('/^' . preg_quote($this->Application->BaseURL(), '/') . '/', '/', $url); | $tmp_name = preg_replace('/^' . preg_quote($this->Application->BaseURL(), '/') . '/', '/', $url); | ||||
$moved = rename($tmp_name, $file_name); | $moved = rename($tmp_name, $file_name); | ||||
} | } | ||||
else { | else { | ||||
$moved = move_uploaded_file($value['tmp_name'], $file_name); | $moved = move_uploaded_file($value['tmp_name'], $file_name); | ||||
▲ Show 20 Lines • Show All 208 Lines • ▼ Show 20 Line(s) | |||||
return $value; | return $value; | ||||
} | } | ||||
$options = $object->GetFieldOptions($field_name); | $options = $object->GetFieldOptions($field_name); | ||||
$upload_dir = isset($options['include_path']) && $options['include_path'] ? '' : $this->getUploadDir($options); | $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 : ''; | $file_path = strlen($value) ? FULL_PATH . str_replace('/', DIRECTORY_SEPARATOR, $upload_dir) . $value : ''; | ||||
if ( preg_match('/resize:([\d]*)x([\d]*)/', $format, $regs) ) { | if ( preg_match('/resize:([\d]*)x([\d]*)/', $format, $regs) ) { | ||||
/** @var ImageHelper $image_helper */ | |||||
$image_helper = $this->Application->recallObject('ImageHelper'); | $image_helper = $this->Application->recallObject('ImageHelper'); | ||||
/* @var $image_helper ImageHelper */ | |||||
try { | try { | ||||
return $image_helper->ResizeImage($file_path, $format); | return $image_helper->ResizeImage($file_path, $format); | ||||
} | } | ||||
catch ( RuntimeException $e ) { | catch ( RuntimeException $e ) { | ||||
// error, during image resize -> return empty string | // error, during image resize -> return empty string | ||||
return ''; | return ''; | ||||
} | } | ||||
Show All 33 Lines | |||||
return $file_path; | return $file_path; | ||||
break; | break; | ||||
case 'file_size': | case 'file_size': | ||||
return filesize($file_path); | return filesize($file_path); | ||||
break; | break; | ||||
case 'img_size': | case 'img_size': | ||||
/** @var ImageHelper $image_helper */ | |||||
$image_helper = $this->Application->recallObject('ImageHelper'); | $image_helper = $this->Application->recallObject('ImageHelper'); | ||||
/* @var $image_helper ImageHelper */ | |||||
$image_info = $image_helper->getImageInfo($file_path); | $image_info = $image_helper->getImageInfo($file_path); | ||||
return $image_info ? $image_info[3] : ''; | return $image_info ? $image_info[3] : ''; | ||||
break; | break; | ||||
} | } | ||||
return sprintf($format, $value); | return sprintf($format, $value); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 116 Lines • Show Last 20 Lines |