diff --git a/apps/files_archive/appinfo/app.php b/apps/files_archive/appinfo/app.php index e75f6fa0559..693c28d98a0 100644 --- a/apps/files_archive/appinfo/app.php +++ b/apps/files_archive/appinfo/app.php @@ -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 index 00000000000..ec316c7bf2c --- /dev/null +++ b/apps/files_archive/js/archive.js @@ -0,0 +1,15 @@ +/** + * Copyright (c) 2012 Robin Appelman + * 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'); + } +}); diff --git a/apps/files_archive/lib/storage.php b/apps/files_archive/lib/storage.php index 4f4c0ef2abe..72a96ca5a5d 100644 --- a/apps/files_archive/lib/storage.php +++ b/apps/files_archive/lib/storage.php @@ -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; + } } diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php index f07814056a3..e768ce00c17 100644 --- a/apps/gallery/ajax/galleryOp.php +++ b/apps/gallery/ajax/galleryOp.php @@ -62,7 +62,7 @@ function handleFilescan($cleanup) { function handlePartialCreate($path) { if (empty($path)) OC_JSON::error(array('cause' => 'No path specified')); - if (!OC_Filesystem::is_dir($path)) OC_JSON::error(array('cause' => 'Invalid path given')); + if (!OC_Filesystem::is_dir($path.'/')) OC_JSON::error(array('cause' => 'Invalid path given')); $album = OC_Gallery_Album::find(OC_User::getUser(), null, $path); $albums = array(); @@ -88,6 +88,22 @@ function handleStoreSettings($root, $order) { OC_JSON::success(array('rescan' => $rescan)); } + +function handleGetGalleries() { + $a = array(); + + $result = OC_Gallery_Album::find(OC_User::getUser()); + + while ($r = $result->fetchRow()) { + $album_name = $r['album_name']; + $tmp_res = OC_Gallery_Photo::find($r['album_id']); + + $a[] = array('name' => utf8_encode($album_name), 'numOfItems' => min($tmp_res->numRows(), 10), 'bgPath' => OC::$WEBROOT.'/data/'.OC_User::getUser().'/gallery/'.$album_name.'.png'); + } + + OC_JSON::success(array('albums'=>$a)); +} + if ($_GET['operation']) { switch($_GET['operation']) { case 'rename': @@ -113,6 +129,9 @@ if ($_GET['operation']) { case 'store_settings': handleStoreSettings($_GET['root'], $_GET['order']); break; + case 'get_galleries': + handleGetGalleries(); + break; default: OC_JSON::error(array('cause' => 'Unknown operation')); } diff --git a/apps/gallery/ajax/getAlbums.php b/apps/gallery/ajax/getAlbums.php deleted file mode 100644 index be87af2abd3..00000000000 --- a/apps/gallery/ajax/getAlbums.php +++ /dev/null @@ -1,41 +0,0 @@ -. -* -*/ - -require_once('../../../lib/base.php'); -OC_JSON::checkLoggedIn(); -OC_JSON::checkAppEnabled('gallery'); - -$a = array(); - -$result = OC_Gallery_Album::find(OC_User::getUser()); - -while ($r = $result->fetchRow()) { - $album_name = $r['album_name']; - $tmp_res = OC_Gallery_Photo::find($r['album_id']); - - $a[] = array('name' => utf8_encode($album_name), 'numOfItems' => min($tmp_res->numRows(), 10), 'bgPath' => OC::$WEBROOT.'/data/'.OC_User::getUser().'/gallery/'.$album_name.'.png'); -} - -OC_JSON::success(array('albums'=>$a)); - -?> diff --git a/apps/gallery/js/album_cover.js b/apps/gallery/js/album_cover.js index 4ddac2f2111..e63bed05fe4 100644 --- a/apps/gallery/js/album_cover.js +++ b/apps/gallery/js/album_cover.js @@ -1,6 +1,6 @@ var actual_cover; $(document).ready(function() { - $.getJSON('ajax/getAlbums.php', function(r) { + $.getJSON('ajax/galleryOp.php', {operation: 'get_galleries'}, function(r) { if (r.status == 'success') { for (var i in r.albums) { var a = r.albums[i]; @@ -53,7 +53,7 @@ function scanForAlbums(cleanup) { } $('#scanprogressbar').progressbar({ value: (albumCounter/totalAlbums)*100 }).fadeIn(); for(var a in r.paths) { - $.getJSON('ajax/galleryOp.php?operation=partial_create&path='+r.paths[a], function(r) { + $.getJSON('ajax/galleryOp.php',{operation:'partial_create','path':r.paths[a]}, function(r) { if (r.status == 'success') { Albums.add(r.album_details.albumName, r.album_details.imagesCount); @@ -81,71 +81,39 @@ function scanForAlbums(cleanup) { } function galleryRemove(albumName) { - // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore! - $( "#dialog:ui-dialog" ).dialog( "destroy" ); - $('#albumName', $("#dialog-confirm")).text(albumName); - - $( '#dialog-confirm' ).dialog({ - resizable: false, - height:150, - buttons: [{ - text: t('gallery', 'OK'), - click: function() { - $.getJSON("ajax/galleryOp.php", {operation: "remove", name: albumName}, function(r) { - if (r.status == "success") { - $(".gallery_album_box").filterAttr('data-album',albumName).remove(); - Albums.remove(albumName); - } else { - alert("Error: " + r.cause); - } - $('#dialog-confirm').dialog('close'); - }); - }}, - { - text: t('gallery', 'Cancel'), - click: function() { - $( this ).dialog( 'close' ); - }}] + OC.dialogs.confirm(t('gallery', 'Do you want to remove album ') + decodeURIComponent(escape(albumName)), + t('gallery', 'Remove confirmation'), + function(decision) { + if (decision) { + $.getJSON("ajax/galleryOp.php", {operation: "remove", name: decodeURIComponent(escape(albumName))}, function(r) { + if (r.status == "success") { + $(".gallery_album_box").filterAttr('data-album',albumName).remove(); + Albums.remove(albumName); + } else { + OC.dialogs.alert(r.cause, "Error"); + } + }); + } }); } function galleryRename(name) { - $('#name', $('#dialog-form')).val(name); - $( "#dialog-form" ).dialog({ - height: 140, - width: 350, - modal: false, - buttons: [{ - text: t('gallery', 'Change name'), - click: function() { - var newname = $('#name', $('#dialog-form')).val(); - if (newname == name || newname == '') { - $(this).dialog("close"); - return; - } - if (Albums.find(newname)) { - alert("Album ", newname, " exists"); - $(this).dialog("close"); - return; - } - $.getJSON('ajax/galleryOp.php', {operation: 'rename', oldname: name, newname: newname}, function(r) { - if (r.status == "success") { - Albums.rename($(".gallery_album_box").filterAttr('data-album',name), newname); - } else { - alert("Error: " + r.cause); - } - $('#dialog-form').dialog('close'); - }); - - } - }, - { - text: t('gallery', 'Cancel'), - click: function() { - $( this ).dialog('close'); - } - } - ], + OC.dialogs.prompt(t('gallery', 'New album name'), + t('gallery', 'Change name'), + name, + function(newname) { + if (newname == name || newname == '') return; + if (Albums.find(newname)) { + OC.dialogs.alert('Album ' + newname + ' exists', 'Alert'); + return; + } + $.getJSON('ajax/galleryOp.php', {operation: 'rename', oldname: name, newname: newname}, function(r) { + if (r.status == 'success') { + Albums.rename($(".gallery_album_box").filterAttr('data-album',name), newname); + } else { + OC.dialogs.alert('Error: ' + r.cause, 'Error'); + } + }); }); } diff --git a/apps/gallery/lib/scanner.php b/apps/gallery/lib/scanner.php index 64efb006ad1..19906c07152 100644 --- a/apps/gallery/lib/scanner.php +++ b/apps/gallery/lib/scanner.php @@ -53,7 +53,7 @@ class OC_Gallery_Scanner { $current_album = array('name'=> $path, 'imagesCount' => 0, 'images' => array()); $current_album['name'] = self::createName($current_album['name']); - if ($dh = OC_Filesystem::opendir($path)) { + if ($dh = OC_Filesystem::opendir($path.'/')) { while (($filename = readdir($dh)) !== false) { $filepath = ($path[strlen($path)-1]=='/'?$path:$path.'/').$filename; if (substr($filename, 0, 1) == '.') continue; @@ -64,7 +64,7 @@ class OC_Gallery_Scanner { } $current_album['imagesCount'] = count($current_album['images']); $albums['imagesCount'] = $current_album['imagesCount']; - $albums['albumName'] = $current_album['name']; + $albums['albumName'] = utf8_encode($current_album['name']); $result = OC_Gallery_Album::find(OC_User::getUser(), /*$current_album['name']*/ null, $path); // don't duplicate galleries with same path (bug oc-33) @@ -103,21 +103,16 @@ class OC_Gallery_Scanner { } public static function find_paths($path) { - $ret = array(); - $dirres; - $addpath = FALSE; - if (($dirres = OC_Filesystem::opendir($path)) == FALSE) return $ret; - - while (($file = readdir($dirres)) != FALSE) { - if ($file[0] == '.') continue; - if (OC_Filesystem::is_dir($path.$file)) - $ret = array_merge($ret, self::find_paths($path.$file.'/')); - if (self::isPhoto($path.$file)) $addpath = TRUE; - } - - if ($addpath) $ret[] = urlencode($path); - - return $ret; + $images=OC_FileCache::searchByMime('image'); + $paths=array(); + foreach($images as $image){ + $path=dirname($image); + if(array_search($path,$paths)===false){ + error_log($path); + $paths[]=$path; + } + } + return $paths; } } ?> diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index de67c342a71..9ce2bae1642 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -52,7 +52,7 @@ OCdialogs = { */ confirm:function(text, title, callback) { var content = '

'+text+'

'; - OCdialogs.message(content, title, OCdialogs.ALERT_DIALOG, OCdialogs.YES_NO_BUTTON, callback); + OCdialogs.message(content, title, OCdialogs.ALERT_DIALOG, OCdialogs.YES_NO_BUTTONS, callback); }, /** * prompt for user input @@ -60,8 +60,8 @@ OCdialogs = { * @param title dialog title * @param callback which will be triggered when user press OK (input text will be passed to callback) */ - prompt:function(text, title, callback) { - var content = '

'+text+':

'; + prompt:function(text, title, default_value, callback) { + var content = '

'+text+':

'; OCdialogs.message(content, title, OCdialogs.PROMPT_DIALOG, OCdialogs.OK_CANCEL_BUTTONS, callback); }, /** @@ -131,15 +131,19 @@ OCdialogs = { } return $(element).val(); }, - prompt_ok_handler: function(callback, c_id){callback(true, $(c_id + " input#oc-dialog-prompt-input").val()); $(c_id).dialog('close');}, + prompt_ok_handler: function(callback, c_id) { $(c_id).dialog('close'); if (callback != undefined) callback($(c_id + " input#oc-dialog-prompt-input").val()); }, form_ok_handler: function(callback, c_id) { - var r = []; - var c = 0; - $(c_id + ' input').each(function(i, elem) { - r[c] = {name: $(elem).attr('name'), value: OCdialogs.determineValue(elem)}; - c++; - }); - $(c_id).dialog('close'); - callback(r); + if (callback != undefined) { + var r = []; + var c = 0; + $(c_id + ' input').each(function(i, elem) { + r[c] = {name: $(elem).attr('name'), value: OCdialogs.determineValue(elem)}; + c++; + }); + $(c_id).dialog('close'); + callback(r); + } else { + $(c_id).dialog('close'); + } } }; diff --git a/files/index.php b/files/index.php index a29d3fb7e1e..79261e495be 100644 --- a/files/index.php +++ b/files/index.php @@ -40,7 +40,7 @@ OC_App::setActiveNavigationEntry( "files_index" ); // Load the files $dir = isset( $_GET['dir'] ) ? stripslashes($_GET['dir']) : ''; // Redirect if directory does not exist -if(!OC_Filesystem::is_dir($dir)) { +if(!OC_Filesystem::is_dir($dir.'/')) { header("Location: ".$_SERVER['PHP_SELF'].""); } diff --git a/lib/filecache.php b/lib/filecache.php index 732160c216a..be2a00a19a0 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -168,19 +168,28 @@ class OC_FileCache{ /** * delete info from the cache - * @param string $path + * @param string/int $file * @param string root (optional) */ - public static function delete($path,$root=''){ - if(!$root){ - $root=OC_Filesystem::getRoot(); + public static function delete($file,$root=''){ + if(!is_numeric($file)){ + if(!$root){ + $root=OC_Filesystem::getRoot(); + } + if($root=='/'){ + $root=''; + } + $path=$root.$file; + self::delete(self::getFileId($path)); + }elseif($file!=-1){ + $query=OC_DB::prepare('SELECT id FROM *PREFIX*fscache WHERE parent=?'); + $query->execute(array($file)); + while($child=$query->fetchRow()){ + self::delete(intval($child['id'])); + } + $query=OC_DB::prepare('DELETE FROM *PREFIX*fscache WHERE id=?'); + $query->execute(array($file)); } - if($root=='/'){ - $root=''; - } - $path=$root.$path; - $query=OC_DB::prepare('DELETE FROM *PREFIX*fscache WHERE path=?'); - $query->execute(array($path)); } /** @@ -323,10 +332,11 @@ class OC_FileCache{ $path=$params['path']; $fullPath=$view->getRoot().$path; $mimetype=$view->getMimeType($path); + $dir=$view->is_dir($path.'/'); //dont use self::get here, we don't want inifinte loops when a file has changed $cachedSize=self::getCachedSize($path,$root); $size=0; - if($mimetype=='httpd/unix-directory'){ + if($dir){ if(self::inCache($path,$root)){ $parent=self::getFileId($fullPath); $query=OC_DB::prepare('SELECT size FROM *PREFIX*fscache WHERE parent=?'); @@ -465,13 +475,13 @@ class OC_FileCache{ $view=new OC_FilesystemView(($root=='/')?'':$root); } self::scanFile($path,$root); - $dh=$view->opendir($path); + $dh=$view->opendir($path.'/'); $totalSize=0; if($dh){ while (($filename = readdir($dh)) !== false) { if($filename != '.' and $filename != '..'){ $file=$path.'/'.$filename; - if($view->is_dir($file)){ + if($view->is_dir($file.'/')){ if($eventSource){ $eventSource->send('scanning',array('file'=>$file,'count'=>$count)); } diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php index ed12e67eeb3..f632474df01 100644 --- a/lib/filestorage/common.php +++ b/lib/filestorage/common.php @@ -99,7 +99,11 @@ abstract class OC_Filestorage_Common extends OC_Filestorage { return false; } $head=fread($source,8192);//8kb should suffice to determine a mimetype - $extention=substr($path,strrpos($path,'.')); + if($pos=strrpos($path,'.')){ + $extention=substr($path,$pos); + }else{ + $extention=''; + } $tmpFile=OC_Helper::tmpFile($extention); file_put_contents($tmpFile,$head); $mime=OC_Helper::getMimeType($tmpFile); @@ -124,7 +128,11 @@ abstract class OC_Filestorage_Common extends OC_Filestorage { if(!$source){ return false; } - $extention=substr($path,strrpos($path,'.')); + if($pos=strrpos($path,'.')){ + $extention=substr($path,$pos); + }else{ + $extention=''; + } $tmpFile=OC_Helper::tmpFile($extention); $target=fopen($tmpFile,'w'); $count=OC_Helper::streamCopy($source,$target); diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index 8e07ce6025b..688501aee90 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -21,7 +21,10 @@ class OC_Filestorage_Local extends OC_Filestorage{ return opendir($this->datadir.$path); } public function is_dir($path){ - return (is_dir($this->datadir.$path) or substr($path,-1)=='/'); + if(substr($path,-1)=='/'){ + $path=substr($path,0,-1); + } + return is_dir($this->datadir.$path); } public function is_file($path){ return is_file($this->datadir.$path); @@ -76,9 +79,8 @@ class OC_Filestorage_Local extends OC_Filestorage{ public function file_get_contents($path){ return file_get_contents($this->datadir.$path); } - public function file_put_contents($path,$data=null){ - if($return=file_put_contents($this->datadir.$path,$data)){ - } + public function file_put_contents($path,$data){ + return file_put_contents($this->datadir.$path,$data); } public function unlink($path){ return $this->delTree($path); diff --git a/lib/filesystem.php b/lib/filesystem.php index 5013b3968c5..12905d189f9 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -146,20 +146,15 @@ class OC_Filesystem{ * @return string */ static public function getMountPoint($path){ + OC_Hook::emit(self::CLASSNAME,'get_mountpoint',array('path'=>$path)); if(!$path){ $path='/'; } if(substr($path,0,1)!=='/'){ $path='/'.$path; } - if(substr($path,-1)!=='/'){ - $path=$path.'/'; - } $foundMountPoint=''; foreach(OC_Filesystem::$mounts as $mountpoint=>$storage){ - if(substr($mountpoint,-1)!=='/'){ - $mountpoint=$mountpoint.'/'; - } if($mountpoint==$path){ return $mountpoint; } @@ -259,6 +254,9 @@ class OC_Filesystem{ * @param string mountpoint */ static public function mount($class,$arguments,$mountpoint){ + if(substr($mountpoint,-1)!=='/'){ + $mountpoint=$mountpoint.'/'; + } if(substr($mountpoint,0,1)!=='/'){ $mountpoint='/'.$mountpoint; } diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 2d54a676c8c..89e0385fe9c 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -205,6 +205,7 @@ class OC_FilesystemView { $count=OC_Helper::streamCopy($data,$target); $storage1=$this->getStorage($path1); $storage1->unlink($this->getInternalPath($path1)); + $result=$count>0; } OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_rename, array( OC_Filesystem::signal_param_oldpath => $path1, OC_Filesystem::signal_param_newpath=>$path2)); return $result;