Index: trunk/core/kernel/utility/formatters/upload_formatter.php =================================================================== diff -u -N -r8074 -r8178 --- trunk/core/kernel/utility/formatters/upload_formatter.php (.../upload_formatter.php) (revision 8074) +++ trunk/core/kernel/utility/formatters/upload_formatter.php (.../upload_formatter.php) (revision 8178) @@ -15,7 +15,14 @@ } -//function Parse($value, $options, &$errors) + /** + * Enter description here... + * + * @param mixed $value + * @param string $field_name + * @param kDBItem $object + * @return unknown + */ function Parse($value, $field_name, &$object) { $ret = ''; @@ -27,6 +34,51 @@ $this->FullPath = FULL_PATH.$this->DestinationPath; } + // SWF Uploader + if (is_array($value) && isset($value['tmp_ids'])) { + if ($value['tmp_deleted']) { + $deleted = explode('|', $value['tmp_deleted']); + $upload = explode('|', $value['upload']); + $n_upload = array(); +// $n_ids = array(); + foreach ($upload as $name) { + if (in_array($name, $deleted)) continue; + $n_upload[] = $name; +// $n_ids[] = $name; + } + $value['upload'] = implode('|', $n_upload); +// $value['tmp_ids'] = implode('|', $n_ids); + } + if (!$value['tmp_ids']) { + return getArrayValue($value, 'upload'); + } + $swf_uploaded_ids = explode('|', $value['tmp_ids']); + $swf_uploaded_names = explode('|', $value['tmp_names']); + $existing = $value['upload'] ? explode('|', $value['upload']) : array(); + if (isset($options['multiple'])) { + $max_files = $options['multiple'] == false ? 1 : $options['multiple']; + } + else { + $max_files = 1; + } + $fret = array(); + for ($i=0; $iValidateFileName($this->FullPath, $real_name); + $file_name = $this->FullPath.$real_name; + + $tmp_file = WRITEABLE.'/tmp/'.$swf_uploaded_ids[$i].'_'.$swf_uploaded_names[$i]; + rename($tmp_file, $file_name); + + @chmod($file_name, 0666); + $fret[] = getArrayValue($options, 'upload_dir') ? $real_name : $this->DestinationPath.$real_name; + } + $fret = array_merge($existing, $fret); + return implode('|', $fret); + } + + // SWF Uploader END + 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'); @@ -72,7 +124,7 @@ $object->SetDBField($options['content_type_field'], $value['type']); } $ret = getArrayValue($options, 'upload_dir') ? $real_name : $this->DestinationPath.$real_name; - + // delete previous file, when new file is uploaded under same field /*$previous_file = isset($value['upload']) ? $value['upload'] : false; if ($previous_file && file_exists($this->FullPath.$previous_file)) { @@ -101,19 +153,40 @@ 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; + + if ($format == 'file_urls' || $format == 'file_names' || $format == 'file_sizes') { + $upload_dir = isset($options['upload_dir']) ? $options['upload_dir'] : $this->DestinationPath; + $files = explode('|', $value); + $urls = array(); + $names = array(); + if ($value) { // if value string was not empty + foreach ($files as $a_file) { + $urls[] = rtrim($this->Application->BaseURL(), '/').$upload_dir.$a_file; + $names[] = $a_file; + $sizes[] = filesize(FULL_PATH.$upload_dir.$a_file); + } + } + switch ($format) { + case 'file_urls': return implode('|', $urls); + case 'file_names': return implode('|', $names); + case 'file_sizes': return implode('|', $sizes); + } + return implode('|', $format == 'file_urls' ? $urls : $names); + } + $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'])) { @@ -122,7 +195,7 @@ $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; @@ -161,17 +234,17 @@ $this->DestinationPath = IMAGES_PENDING_PATH; parent::kUploadFormatter(); } - + function GetFormatted($tc_value, &$options) { if (isset($options['format']) && ($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); }