Index: branches/5.2.x/core/kernel/utility/formatters/upload_formatter.php =================================================================== diff -u -N -r15346 -r15347 --- branches/5.2.x/core/kernel/utility/formatters/upload_formatter.php (.../upload_formatter.php) (revision 15346) +++ branches/5.2.x/core/kernel/utility/formatters/upload_formatter.php (.../upload_formatter.php) (revision 15347) @@ -1,6 +1,6 @@ sorting = isset($value['order']) ? explode('|', $value['order']) : Array (); + if ($value['tmp_deleted']) { $deleted = explode('|', $value['tmp_deleted']); $upload = explode('|', $value['upload']); @@ -78,8 +88,8 @@ } if (!$value['tmp_ids']) { - // no pending files -> return already uploded files - return getArrayValue($value, 'upload'); + // no pending files -> return already uploaded files + return $this->_sortFiles($value['upload']); } $swf_uploaded_ids = explode('|', $value['tmp_ids']); @@ -119,9 +129,11 @@ @chmod($file_name, 0666); $fret[] = getArrayValue($options, 'upload_dir') ? $real_name : $this->DestinationPath . $real_name; + + $this->_renameFileInSorting($swf_uploaded_names[$i], $real_name); } - return implode('|', array_merge($existing, $fret)); + return $this->_sortFiles(array_merge($existing, $fret)); } // SWF Uploader END @@ -225,6 +237,42 @@ } /** + * Resorts uploaded files according to given file order + * + * @param Array|string $new_files + * @return string + * @access protected + */ + protected function _sortFiles($files) + { + if ( !is_array($files) ) { + $files = explode('|', $files); + } + + $sorted_files = array_intersect($this->sorting, $files); // removes deleted files from sorting + $new_files = array_diff($files, $sorted_files); // files, that weren't sorted - add to the end + + return implode('|', array_merge($sorted_files, $new_files)); + } + + /** + * Renames file in sorting list + * + * @param string $old_name + * @param string $new_name + * @return void + * @access protected + */ + protected function _renameFileInSorting($old_name, $new_name) + { + $index = array_search($old_name, $this->sorting); + + if ( $index !== false ) { + $this->sorting[$index] = $new_name; + } + } + + /** * Checks, that given file name has on of provided file extensions * * @param string $filename