[Openupload-svn-update] SF.net SVN: openupload:[195] trunk
Status: Beta
Brought to you by:
tsdogs
|
From: <ts...@us...> - 2008-12-11 22:22:17
|
Revision: 195
http://openupload.svn.sourceforge.net/openupload/?rev=195&view=rev
Author: tsdogs
Date: 2008-12-11 22:00:12 +0000 (Thu, 11 Dec 2008)
Log Message:
-----------
Add compression plugin
Added Paths:
-----------
trunk/plugins/compress.inc.php
trunk/templates/default/plugins/compress/
Added: trunk/plugins/compress.inc.php
===================================================================
--- trunk/plugins/compress.inc.php (rev 0)
+++ trunk/plugins/compress.inc.php 2008-12-11 22:00:12 UTC (rev 195)
@@ -0,0 +1,83 @@
+<?php
+
+class compressPlugin extends OpenUploadPlugin {
+
+ function compressPlugin() {
+ $this->description = tr('Compress the uploaded files');
+ $this->options = array(
+ array('name' => 'command', 'description' => tr('Command to be executed. One per line.'), 'type' => 'list'),
+ array('name' => 'extension', 'description' => tr('Extensions corresponding to commands.'), 'type' => 'list'),
+ array('name' => 'compression', 'description' => tr('Name of compression commands'), 'type' => 'list'),
+ );
+ }
+
+ function uploadOptions(&$finfo, $acl) {
+ if ($acl != 'enable') return true;
+ $group = $this->getGroup('command');
+ if (count($this->config['command'][$group])==0 and count($this->config['command']['*'])>0) {
+ $this->config['command'][$group]=$this->config['command']['*'];
+ $this->config['compression'][$group]=$this->config['compression']['*'];
+ $this->config['extension'][$group]=$this->config['extenion']['*'];
+ }
+ if (count($this->config['command'][$group])>0) {
+ $this->assign('compress',$this->config['compression'][$group]);
+ $this->display('uploadOptions');
+ }
+ return true;
+ }
+
+ function uploadConfirm(&$finfo, $acl) {
+ global $_POST;
+ if ($acl != 'enable') return true;
+ if ($_POST['compress']!='') {
+ if ($finfo[0]['compress']==1) return true; /* file already compressed */
+ $group = $this->getGroup('command');
+ if (count($this->config['command'][$group])==0 and count($this->config['command']['*'])>0) {
+ $this->config['command'][$group]=$this->config['command']['*'];
+ $this->config['compression'][$group]=$this->config['compression']['*'];
+ $this->config['extension'][$group]=$this->config['extension']['*'];
+ }
+ if (count($this->config['command'][$group])>0) {
+ // TODO: more error checking
+ /* create a tmp folder where to store the files */
+ $tmpdir = randomName(20,20);
+ $res = mkdir(app()->config['DATA_PATH'].'/tmp/'.$tmpdir);
+ /* move the uploaded files to that folder with the original name */
+ foreach ($finfo as $f) {
+ rename($f['tmp'],app()->config['DATA_PATH'].'/tmp/'.$tmpdir.'/'.$f['name']);
+ $files .= ' "'.chop($f['name']).'"';
+ $lfiles .= ' "'.app()->config['DATA_PATH'].'/tmp/'.$tmpdir.'/'.chop($f['name']).'"';
+ }
+ /* execute the compress command */
+ $cmd=$this->config['command'][$group][$_POST['compress']];
+ $params['%1']=$finfo[0]['tmp'];
+ $params['%2']=$files;
+ $params['%3']=$lfiles;
+ $params['%4']=app()->config['DATA_PATH'].'/tmp/'.$tmpdir;
+ $cmd = strtr($cmd,$params);
+ $pwd = getcwd();
+ chdir(app()->config['DATA_PATH'].'/tmp/'.$tmpdir);
+ exec($cmd,$output);
+ chdir($pwd);
+ /* remove the files */
+ foreach ($finfo as $f) {
+ unlink(app()->config['DATA_PATH'].'/tmp/'.$tmpdir.'/'.$f['name']);
+ }
+ rmdir(app()->config['DATA_PATH'].'/tmp/'.$tmpdir);
+ /* update the file information with the compressed one */
+ $finfo[0]['mime']='binary/octet-stream';
+ $finfo[0]['name']=$tmpdir.'.'.$this->config['extension'][$group][$_POST['compress']];
+ $finfo[0]['size']=filesize($finfo[0]['tmp'].'.'.$this->config['extension'][$group][$_POST['compress']]);
+ $finfo[0]['tmp']=$finfo[0]['tmp'].'.'.$this->config['extension'][$group][$_POST['compress']];
+ for ($i=1; $i<count($finfo); $i++)
+ unset($finfo[$i]);
+ /* tell the program that the file is already compressed, so not to run it again */
+ $finfo[0]['compress']=1;
+ }
+ }
+ return true;
+ }
+
+}
+
+?>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|