Merge branch 'master' into calendar_sharing

This commit is contained in:
Georg Ehrke 2012-03-04 10:10:19 +01:00
commit c40668e3a9
14 changed files with 188 additions and 165 deletions

View 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' );

View File

@ -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');
}
});

View 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;
}
}

View File

@ -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'));
}

View File

@ -1,41 +0,0 @@
<?php
/**
* ownCloud - gallery application
*
* @author Bartek Przybylski
* @copyright 2012 Bartek Przybylski bart.p.pl@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
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));
?>

View File

@ -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');
}
});
});
}

View File

@ -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;
}
}
?>

View File

@ -52,7 +52,7 @@ OCdialogs = {
*/
confirm:function(text, title, callback) {
var content = '<p><span class="ui-icon ui-icon-notice"></span>'+text+'</p>';
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 = '<p><span class="ui-icon ui-icon-pencil"></span>'+text+':<br/><input type="text" id="oc-dialog-prompt-input" style="width:90%"></p>';
prompt:function(text, title, default_value, callback) {
var content = '<p><span class="ui-icon ui-icon-pencil"></span>'+text+':<br/><input type="text" id="oc-dialog-prompt-input" value="'+default_value+'" style="width:90%"></p>';
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');
}
}
};

View File

@ -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']."");
}

View File

@ -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));
}

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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;