]> source.dussan.org Git - nextcloud-server.git/commitdiff
allow transparent opening of zip files from the web interface
authorRobin Appelman <icewind@owncloud.com>
Sat, 3 Mar 2012 19:46:46 +0000 (20:46 +0100)
committerRobin Appelman <icewind@owncloud.com>
Sat, 3 Mar 2012 20:23:35 +0000 (21:23 +0100)
apps/files_archive/appinfo/app.php
apps/files_archive/js/archive.js [new file with mode: 0644]
apps/files_archive/lib/storage.php

index e75f6fa055997c9d3683a8db62490ba4062a7ea2..693c28d98a07a44d4b6e7fffc8a9d80c02fb895d 100644 (file)
@@ -12,3 +12,7 @@ foreach(array('ZIP') as $type){
 }
 
 OC::$CLASSPATH['OC_Filestorage_Archive']='apps/files_archive/lib/storage.php';
+
+OC_Hook::connect('OC_Filesystem','get_mountpoint','OC_Filestorage_Archive','autoMount');
+
+OC_Util::addScript( 'files_archive', 'archive' );
diff --git a/apps/files_archive/js/archive.js b/apps/files_archive/js/archive.js
new file mode 100644 (file)
index 0000000..ec316c7
--- /dev/null
@@ -0,0 +1,15 @@
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+$(document).ready(function() {
+       if(typeof FileActions!=='undefined'){
+               FileActions.register('application/zip','Open','',function(filename){
+                       window.location='index.php?dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename);
+               });
+               FileActions.setDefault('application/zip','Open');
+       }
+});
index 4f4c0ef2abe06c941b76d14c24bd557ee412229c..72a96ca5a5d7f4b8eead02d621f87818d18accdb 100644 (file)
@@ -13,10 +13,13 @@ class OC_Filestorage_Archive extends OC_Filestorage_Common{
         */
        private $archive;
        private $path;
+       private static $mounted=array();
+       private static $enableAutomount=true;
+       private static $rootView;
        
        private function stripPath($path){//files should never start with /
                if(substr($path,0,1)=='/'){
-                       return substr($path,1);
+                       $path=substr($path,1);
                }
                return $path;
        }
@@ -52,9 +55,14 @@ class OC_Filestorage_Archive extends OC_Filestorage_Common{
                if($path==''){
                        $stat=stat($this->path);
                }else{
-                       $stat=array();
-                       $stat['mtime']=$this->archive->mtime($path);
-                       $stat['size']=$this->archive->filesize($path);
+                       if($this->is_dir($path)){
+                               $stat=array('size'=>0);
+                               $stat['mtime']=filemtime($this->path);
+                       }else{
+                               $stat=array();
+                               $stat['mtime']=$this->archive->mtime($path);
+                               $stat['size']=$this->archive->filesize($path);
+                       }
                }
                $stat['ctime']=$ctime;
                return $stat;
@@ -64,7 +72,11 @@ class OC_Filestorage_Archive extends OC_Filestorage_Common{
                if($path==''){
                        return 'dir';
                }
-               return $this->archive->fileExists($path.'/')?'dir':'file';
+               if(substr($path,-1)=='/'){
+                       return $this->archive->fileExists($path)?'dir':'file';
+               }else{
+                       return $this->archive->fileExists($path.'/')?'dir':'file';
+               }
        }
        public function is_readable($path){
                return is_readable($this->path);
@@ -99,4 +111,32 @@ class OC_Filestorage_Archive extends OC_Filestorage_Common{
                        return false;//not supported
                }
        }
+
+       /**
+        * automount paths from file hooks
+        * @param aray params
+        */
+       public static function autoMount($params){
+               if(!self::$enableAutomount){
+                       return;
+               }
+               $path=$params['path'];
+               if(!self::$rootView){
+                       self::$rootView=new OC_FilesystemView('');
+               }
+               self::$enableAutomount=false;//prevent recursion
+               $supported=array('zip');
+               foreach($supported as $type){
+                       $ext='.'.$type.'/';
+                       if(($pos=strpos(strtolower($path),$ext))!==false){
+                               $archive=substr($path,0,$pos+strlen($ext)-1);
+                               if(self::$rootView->file_exists($archive) and  array_search($archive,self::$mounted)===false){
+                                       $localArchive=self::$rootView->getLocalFile($archive);
+                                       OC_Filesystem::mount('OC_Filestorage_Archive',array('archive'=>$localArchive),$archive.'/');
+                                       self::$mounted[]=$archive;
+                               }
+                       }
+               }
+               self::$enableAutomount=true;
+       }
 }