Index: trunk/core/kernel/utility/formatters/upload_formatter.php =================================================================== diff -u -r4758 -r6093 --- trunk/core/kernel/utility/formatters/upload_formatter.php (.../upload_formatter.php) (revision 4758) +++ trunk/core/kernel/utility/formatters/upload_formatter.php (.../upload_formatter.php) (revision 6093) @@ -27,8 +27,8 @@ $this->FullPath = FULL_PATH.$this->DestinationPath; } - if (getArrayValue($value, 'upload') && getArrayValue($value, 'error') == UPLOAD_ERR_NO_FILE) - { + if (getArrayValue($value, 'upload') && getArrayValue($value, 'error') == UPLOAD_ERR_NO_FILE) { + // file was not uploaded this time, but was uploaded before, then use previously uploaded file (from db) return getArrayValue($value, 'upload'); } @@ -95,7 +95,37 @@ return $ret; } + + function Format($value, $field_name, &$object, $format=null) + { + if ( is_null($value) ) return ''; + $options = $object->GetFieldOptions($field_name); + if ( isset($format) ) $options['format'] = $format; + $tc_value = $this->TypeCast($value, $options); + if( ($tc_value === false) || ($tc_value != $value) ) return $value; // for leaving badly formatted date on the form + + return $this->GetFormatted($tc_value, $options); + } + + function GetFormatted($tc_value, &$options) + { + if (isset($options['format'])) { + switch ($options['format']) { + case 'full_url': + $upload_dir = isset($options['upload_dir']) ? $options['upload_dir'] : $this->DestinationPath; + return rtrim($this->Application->BaseURL(), '/').$upload_dir.$tc_value; + break; + + default: + return sprintf($options['format'], $tc_value); + break; + } + } + + return $tc_value; + } + function ValidateFileName($path, $name) { $parts = pathinfo($name); @@ -125,5 +155,18 @@ $this->DestinationPath = IMAGES_PENDING_PATH; parent::kUploadFormatter(); } + + function GetFormatted($tc_value, &$options) + { + if ($options['format'] == 'img_size') { + $upload_dir = isset($options['upload_dir']) ? $options['upload_dir'] : $this->DestinationPath; + $img_path = FULL_PATH.'/'.$upload_dir.$tc_value; + + $image_info = @getimagesize($img_path); + return ' width="'.$image_info[0].'" height="'.$image_info[1].'"'; + } + + return parent::GetFormatted($tc_value, $options); + } } \ No newline at end of file