Greetings,
first of all, thank you for this great module.
I would like to add a new option to the "actions" menu to unzip the selected file.
Using shell_exec() should be pretty easy as long as "unzip" exists on the server, I would just like a few hints on where to start and how to implement it.

Thank you in advance

Comments

Nicolas Georget’s picture

First, you can add an new action into the function filebrowser_filebrowser_actions_info($node) line 834 of the file filebrowser.module:

[...]
if (user_access(FILEBROWSER_UNARCHIVE_FILE)) { // This condition should be reviewed... depends of lot of things. Like if the user has the right(s), etc... 
      $actions[] = array(
          'operation' => 'unarchive', 
          'title' => t("Unarchive the selected items") 
      );
    }
  }
  return $actions;
}

Then, you will need to implement the new action that you declared into the function filebrowser_filebrowser_action_process($node, $action, $fids) just after (line 856):

[...]
  switch ($action) {
  [...]
  case 'unarchive' :
  //i.e. API Drupal file_get_mimetype()
  if (file_get_mimetype($fids) == 'application/zip') { // Not the best way but why not
    // And because Yoran use the ZIPArchive lib, you can use the same command or use your own exec()
    $zip = new ZipArchive();
    if ($zip->open($fids) === TRUE) {
      $zip->extractTo($target);
      $zip->close();
  }

It's a draft but it's a start. There are other things to consider, as the implementation of the permissions, reload the node after the extraction...
The second way to do that is to use the PHP ZipArchive lib and preview the files inside the ZIP (as a folder) and resulting an extraction of some files only. Use the second parameter of the method $zip->extractTo($target, array($myFile1, $myFile2, $myFile3)) to do that...

smekras’s picture

I'm somewhat of a newbie with php and at the moment I don't really care about extra features other than unzipping a single selected file. I tried copying the code above in the right place but it is returning errors about fids (is that the variable that returns the selected files?). I would appreciate it if someone could help me out with that.

thanks

pantoflen’s picture

subscribe. anyone?

Yoran’s picture

Status: Active » Closed (won't fix)
StatusFileSize
new817 bytes

@Nicolas Georget
You was'nt that far ;-) I attached to this comment a sample module adding "unarchive" to filebrowser.

I don't feel like this should be part of core filebrowser module, but perhaps I'm wrong about this.

Nicolas Georget’s picture

StatusFileSize
new1000 bytes

I added a warning message in case of the user has not the right to view subdirectory listings!
Might be useful if the user unzip the archive and watch nothing happens.

By the way Yoran, do you know your constant FILEBROWSER_VIEW_DIRECORY_LISTINGS should have a 't': FILEBROWSER_VIEW_DIRECTORY_LISTINGS ;-)

Yoran’s picture

Oh well, ok, corrected un -dev :)