Opened 8 years ago

Last modified 8 years ago

#1466 new enhancement

EFM: automatically select a newly uploaded file

Reported by: guest Owned by:
Priority: normal Milestone: 0.97
Component: Plugins Version: trunk
Severity: normal Keywords: auto select image picture upload
Cc:

Description

An issue in ExtendedFileManager is that when you upload files you have to browse the list to find the picture you just uploaded. I guess that the day you upload a file, you want to use it as it's done uploading...

To do this, get to xinha/plugins/ExtendedFileManager/Classes/ExtendedFileManager.php, in the _processFiles($relative, $file) function.

You have to find something like

if(!is_int($result))
{
  Files::delFile($file['tmp_name']);
  Return 'File "$file='.$file['name'].'$" successfully uploaded.';
}

Inside this if-block, erase (or comment) the line that calls a return.

Before or after (not important) the call to Files::delFiles, add these lines:

$entry=Files::escape($file['name']);  //complies with the final name of the file
$t=array();  //our new return value
$t['relative'] = $relative.$entry;  //needed for the call to JS function selectImage (see below)
$img = null;  //should be $img = $this->getImageInfo($fullpath.$entry),
              //up to you to find how to create a fullpath with
              //ExtendedFileManager::getImagesDir, Files::makePath and $relative (given as a parameter)
if(!is_array($img)) $img[0]=$img[1]=0;
$t['image'] = $img;  //needed for the call to JS function selectImage
$t['entry'] = $entry;  //needed for the call to JS function selectImage
Return $t;

You can see it's (almost) a copy/paste of the contruction of the table in ExtendedFileManager::getFiles. Also, the statement $img = null; is because I don't need this piece of information, but perhaps you do.

Once this is done, you'll have to gather the result in JS function init defined in xinha/plugins/ExtendedFileManager/images.php.

Look for "$uploadStatus", you should have something like

if(isset($uploadStatus) && !is_numeric($uploadStatus) && !is_bool($uploadStatus))
  echo "alert(i18n('$uploadStatus'));";
...

Make it become

if(isset($uploadStatus) && is_array($uploadStatus))
  echo "selectImage('"
       .$uploadStatus['relative']."', '"
       .preg_replace('#\..{3,4}$#', '', $uploadStatus['entry'])."', "
       .$uploadStatus['image'][0].", "
       .$uploadStatus['image'][1].")";
else if(isset($uploadStatus) && !is_numeric($uploadStatus) && !is_bool($uploadStatus))
  echo "alert(i18n('$uploadStatus'));";
...

The first case testing if we have our array out of the function issues a (future, JavaScript? is client-sided) call to selectImage. This call is (almost) pasted from the same file. Look for "selectImage" if you don't believe me ;)

That's all, you should have your newly uploaded files already selected once the upload is over.

Change History (1)

comment:1 Changed 8 years ago by gogo

  • Milestone changed from 0.96 to 0.97
Note: See TracTickets for help on using tickets.