diff options
105 files changed, 1000 insertions, 692 deletions
@@ -28,4 +28,4 @@ With help from many libraries and frameworks including: … "Lock” symbol from thenounproject.com collection -"Clock” symbol by Brandon Hopkins, from thenounproject.com collection
\ No newline at end of file +"Clock” symbol by Brandon Hopkins, from thenounproject.com collection diff --git a/COPYING-README b/COPYING-README index 49e035186ed..8c26709d767 100644 --- a/COPYING-README +++ b/COPYING-README @@ -12,4 +12,4 @@ Licensing of components: All unmodified files from these and other sources retain their original copyright and license notices: see the relevant individual files. -Attribution information for ownCloud is contained in the AUTHORS file.
\ No newline at end of file +Attribution information for ownCloud is contained in the AUTHORS file. diff --git a/apps/files/ajax/download.php b/apps/files/ajax/download.php index b2bfd53506d..6a34cbe4ef1 100644 --- a/apps/files/ajax/download.php +++ b/apps/files/ajax/download.php @@ -39,4 +39,4 @@ if (!is_array($files_list)) { $files_list = array($files); } -OC_Files::get($dir, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false); +OC_Files::get($dir, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD'); diff --git a/apps/files/ajax/list.php b/apps/files/ajax/list.php index 878e4cb2159..c50e96b2429 100644 --- a/apps/files/ajax/list.php +++ b/apps/files/ajax/list.php @@ -10,7 +10,7 @@ OCP\JSON::checkLoggedIn(); // Load the files $dir = isset( $_GET['dir'] ) ? $_GET['dir'] : ''; -$doBreadcrumb = isset( $_GET['breadcrumb'] ) ? true : false; +$doBreadcrumb = isset($_GET['breadcrumb']); $data = array(); // Make breadcrumb diff --git a/apps/files/ajax/newfile.php b/apps/files/ajax/newfile.php index 8c1aad8668c..d224e79d01b 100644 --- a/apps/files/ajax/newfile.php +++ b/apps/files/ajax/newfile.php @@ -77,6 +77,12 @@ if($source) { exit(); } else { $success = false; + if (!$content) { + $templateManager = OC_Helper::getFileTemplateManager(); + $mimeType = OC_Helper::getMimeType($target); + $content = $templateManager->getTemplate($mimeType); + } + if($content) { $success = \OC\Files\Filesystem::file_put_contents($target, $content); } else { @@ -87,9 +93,11 @@ if($source) { $meta = \OC\Files\Filesystem::getFileInfo($target); $id = $meta['fileid']; $mime = $meta['mimetype']; + $size = $meta['size']; OCP\JSON::success(array('data' => array( 'id' => $id, 'mime' => $mime, + 'size' => $size, 'content' => $content, ))); exit(); diff --git a/apps/files/ajax/rename.php b/apps/files/ajax/rename.php index f4551858283..5b07c306af8 100644 --- a/apps/files/ajax/rename.php +++ b/apps/files/ajax/rename.php @@ -38,4 +38,4 @@ if($result['success'] === true){ OCP\JSON::success(array('data' => $result['data'])); } else { OCP\JSON::error(array('data' => $result['data'])); -}
\ No newline at end of file +} diff --git a/apps/files/appinfo/app.php b/apps/files/appinfo/app.php index 99739cb4cee..aa839b81d18 100644 --- a/apps/files/appinfo/app.php +++ b/apps/files/appinfo/app.php @@ -5,11 +5,11 @@ $l = OC_L10N::get('files'); OCP\App::registerAdmin('files', 'admin'); -OCP\App::addNavigationEntry( array( "id" => "files_index", - "order" => 0, - "href" => OCP\Util::linkTo( "files", "index.php" ), - "icon" => OCP\Util::imagePath( "core", "places/files.svg" ), - "name" => $l->t("Files") )); +OCP\App::addNavigationEntry(array("id" => "files_index", + "order" => 0, + "href" => OCP\Util::linkTo("files", "index.php"), + "icon" => OCP\Util::imagePath("core", "places/files.svg"), + "name" => $l->t("Files"))); OC_Search::registerProvider('OC_Search_Provider_File'); @@ -21,3 +21,7 @@ OC_Search::registerProvider('OC_Search_Provider_File'); \OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Updater', 'renameHook'); \OCP\BackgroundJob::addRegularTask('\OC\Files\Cache\BackgroundWatcher', 'checkNext'); + +$templateManager = OC_Helper::getFileTemplateManager(); +$templateManager->registerTemplate('text/html', 'core/templates/filetemplates/template.html'); + diff --git a/apps/files/appinfo/routes.php b/apps/files/appinfo/routes.php index fcd5f4b2608..f3d8e9a4f4d 100644 --- a/apps/files/appinfo/routes.php +++ b/apps/files/appinfo/routes.php @@ -11,4 +11,4 @@ $this->create('download', 'download{file}') ->actionInclude('files/download.php'); // Register with the capabilities API -OC_API::register('get', '/cloud/capabilities', array('OCA\Files\Capabilities', 'getCapabilities'), 'files', OC_API::USER_AUTH);
\ No newline at end of file +OC_API::register('get', '/cloud/capabilities', array('OCA\Files\Capabilities', 'getCapabilities'), 'files', OC_API::USER_AUTH); diff --git a/apps/files/css/files.css b/apps/files/css/files.css index 50aa58b53d7..a2cf8398c27 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -46,12 +46,22 @@ z-index:20; position:relative; cursor:pointer; overflow:hidden; } -#uploadprogresswrapper { float: right; position: relative; } -#uploadprogresswrapper #uploadprogressbar { - position:relative; float: right; - margin-left: 12px; width:10em; height:1.5em; top:.4em; +#uploadprogresswrapper { + position: relative; + display: inline; +} +#uploadprogressbar { + position:relative; + float: left; + margin-left: 12px; + width: 130px; + height: 26px; display:inline-block; } +#uploadprogressbar + stop { + font-size: 13px; +} + /* FILE TABLE */ diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 942a07dfccc..0eddd7e9cd7 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -1,343 +1,345 @@ $(document).ready(function() { - file_upload_param = { - dropZone: $('#content'), // restrict dropZone to content div - //singleFileUploads is on by default, so the data.files array will always have length 1 - add: function(e, data) { + file_upload_param = { + dropZone: $('#content'), // restrict dropZone to content div + //singleFileUploads is on by default, so the data.files array will always have length 1 + add: function(e, data) { - if(data.files[0].type === '' && data.files[0].size == 4096) - { - data.textStatus = 'dirorzero'; - data.errorThrown = t('files','Unable to upload your file as it is a directory or has 0 bytes'); - var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); - fu._trigger('fail', e, data); - return true; //don't upload this file but go on with next in queue - } + if(data.files[0].type === '' && data.files[0].size == 4096) + { + data.textStatus = 'dirorzero'; + data.errorThrown = t('files','Unable to upload your file as it is a directory or has 0 bytes'); + var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); + fu._trigger('fail', e, data); + return true; //don't upload this file but go on with next in queue + } - var totalSize=0; - $.each(data.originalFiles, function(i,file){ - totalSize+=file.size; - }); + var totalSize=0; + $.each(data.originalFiles, function(i,file){ + totalSize+=file.size; + }); - if(totalSize>$('#max_upload').val()){ - data.textStatus = 'notenoughspace'; - data.errorThrown = t('files','Not enough space available'); - var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); - fu._trigger('fail', e, data); - return false; //don't upload anything - } + if(totalSize>$('#max_upload').val()){ + data.textStatus = 'notenoughspace'; + data.errorThrown = t('files','Not enough space available'); + var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); + fu._trigger('fail', e, data); + return false; //don't upload anything + } - // start the actual file upload - var jqXHR = data.submit(); + // start the actual file upload + var jqXHR = data.submit(); - // remember jqXHR to show warning to user when he navigates away but an upload is still in progress - if (typeof data.context !== 'undefined' && data.context.data('type') === 'dir') { - var dirName = data.context.data('file'); - if(typeof uploadingFiles[dirName] === 'undefined') { - uploadingFiles[dirName] = {}; - } - uploadingFiles[dirName][data.files[0].name] = jqXHR; - } else { - uploadingFiles[data.files[0].name] = jqXHR; - } + // remember jqXHR to show warning to user when he navigates away but an upload is still in progress + if (typeof data.context !== 'undefined' && data.context.data('type') === 'dir') { + var dirName = data.context.data('file'); + if(typeof uploadingFiles[dirName] === 'undefined') { + uploadingFiles[dirName] = {}; + } + uploadingFiles[dirName][data.files[0].name] = jqXHR; + } else { + uploadingFiles[data.files[0].name] = jqXHR; + } - //show cancel button - if($('html.lte9').length === 0 && data.dataType !== 'iframe') { - $('#uploadprogresswrapper input.stop').show(); - } - }, - /** - * called after the first add, does NOT have the data param - * @param e - */ - start: function(e) { - //IE < 10 does not fire the necessary events for the progress bar. - if($('html.lte9').length > 0) { - return; - } - $('#uploadprogressbar').progressbar({value:0}); - $('#uploadprogressbar').fadeIn(); - }, - fail: function(e, data) { - if (typeof data.textStatus !== 'undefined' && data.textStatus !== 'success' ) { - if (data.textStatus === 'abort') { - $('#notification').text(t('files', 'Upload cancelled.')); - } else { - // HTTP connection problem - $('#notification').text(data.errorThrown); - } - $('#notification').fadeIn(); - //hide notification after 5 sec - setTimeout(function() { - $('#notification').fadeOut(); - }, 5000); - } - delete uploadingFiles[data.files[0].name]; - }, - progress: function(e, data) { - // TODO: show nice progress bar in file row - }, - progressall: function(e, data) { - //IE < 10 does not fire the necessary events for the progress bar. - if($('html.lte9').length > 0) { - return; - } - var progress = (data.loaded/data.total)*100; - $('#uploadprogressbar').progressbar('value',progress); - }, - /** - * called for every successful upload - * @param e - * @param data - */ - done:function(e, data) { - // handle different responses (json or body from iframe for ie) - var response; - if (typeof data.result === 'string') { - response = data.result; - } else { - //fetch response from iframe - response = data.result[0].body.innerText; - } - var result=$.parseJSON(response); + //show cancel button + if($('html.lte9').length === 0 && data.dataType !== 'iframe') { + $('#uploadprogresswrapper input.stop').show(); + } + }, + /** + * called after the first add, does NOT have the data param + * @param e + */ + start: function(e) { + //IE < 10 does not fire the necessary events for the progress bar. + if($('html.lte9').length > 0) { + return; + } + $('#uploadprogressbar').progressbar({value:0}); + $('#uploadprogressbar').fadeIn(); + }, + fail: function(e, data) { + if (typeof data.textStatus !== 'undefined' && data.textStatus !== 'success' ) { + if (data.textStatus === 'abort') { + $('#notification').text(t('files', 'Upload cancelled.')); + } else { + // HTTP connection problem + $('#notification').text(data.errorThrown); + } + $('#notification').fadeIn(); + //hide notification after 5 sec + setTimeout(function() { + $('#notification').fadeOut(); + }, 5000); + } + delete uploadingFiles[data.files[0].name]; + }, + progress: function(e, data) { + // TODO: show nice progress bar in file row + }, + progressall: function(e, data) { + //IE < 10 does not fire the necessary events for the progress bar. + if($('html.lte9').length > 0) { + return; + } + var progress = (data.loaded/data.total)*100; + $('#uploadprogressbar').progressbar('value',progress); + }, + /** + * called for every successful upload + * @param e + * @param data + */ + done:function(e, data) { + // handle different responses (json or body from iframe for ie) + var response; + if (typeof data.result === 'string') { + response = data.result; + } else { + //fetch response from iframe + response = data.result[0].body.innerText; + } + var result=$.parseJSON(response); - if(typeof result[0] !== 'undefined' && result[0].status === 'success') { - var file = result[0]; - } else { - data.textStatus = 'servererror'; - data.errorThrown = t('files', result.data.message); - var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); - fu._trigger('fail', e, data); - } + if(typeof result[0] !== 'undefined' && result[0].status === 'success') { + var file = result[0]; + } else { + data.textStatus = 'servererror'; + data.errorThrown = t('files', result.data.message); + var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); + fu._trigger('fail', e, data); + } - var filename = result[0].originalname; + var filename = result[0].originalname; - // delete jqXHR reference - if (typeof data.context !== 'undefined' && data.context.data('type') === 'dir') { - var dirName = data.context.data('file'); - delete uploadingFiles[dirName][filename]; - if ($.assocArraySize(uploadingFiles[dirName]) == 0) { - delete uploadingFiles[dirName]; - } - } else { - delete uploadingFiles[filename]; - } + // delete jqXHR reference + if (typeof data.context !== 'undefined' && data.context.data('type') === 'dir') { + var dirName = data.context.data('file'); + delete uploadingFiles[dirName][filename]; + if ($.assocArraySize(uploadingFiles[dirName]) == 0) { + delete uploadingFiles[dirName]; + } + } else { + delete uploadingFiles[filename]; + } - }, - /** - * called after last upload - * @param e - * @param data - */ - stop: function(e, data) { - if(data.dataType !== 'iframe') { - $('#uploadprogresswrapper input.stop').hide(); - } + }, + /** + * called after last upload + * @param e + * @param data + */ + stop: function(e, data) { + if(data.dataType !== 'iframe') { + $('#uploadprogresswrapper input.stop').hide(); + } - //IE < 10 does not fire the necessary events for the progress bar. - if($('html.lte9').length > 0) { - return; - } + //IE < 10 does not fire the necessary events for the progress bar. + if($('html.lte9').length > 0) { + return; + } - $('#uploadprogressbar').progressbar('value',100); - $('#uploadprogressbar').fadeOut(); + $('#uploadprogressbar').progressbar('value',100); + $('#uploadprogressbar').fadeOut(); + } } - } - var file_upload_handler = function() { - $('#file_upload_start').fileupload(file_upload_param); - }; + var file_upload_handler = function() { + $('#file_upload_start').fileupload(file_upload_param); + }; - if ( document.getElementById('data-upload-form') ) { - $(file_upload_handler); - } - $.assocArraySize = function(obj) { - // http://stackoverflow.com/a/6700/11236 - var size = 0, key; - for (key in obj) { - if (obj.hasOwnProperty(key)) size++; + if ( document.getElementById('data-upload-form') ) { + $(file_upload_handler); } - return size; - }; - - // warn user not to leave the page while upload is in progress - $(window).bind('beforeunload', function(e) { - if ($.assocArraySize(uploadingFiles) > 0) - return t('files','File upload is in progress. Leaving the page now will cancel the upload.'); - }); + $.assocArraySize = function(obj) { + // http://stackoverflow.com/a/6700/11236 + var size = 0, key; + for (key in obj) { + if (obj.hasOwnProperty(key)) size++; + } + return size; + }; - //add multiply file upload attribute to all browsers except konqueror (which crashes when it's used) - if(navigator.userAgent.search(/konqueror/i)==-1){ - $('#file_upload_start').attr('multiple','multiple') - } + // warn user not to leave the page while upload is in progress + $(window).bind('beforeunload', function(e) { + if ($.assocArraySize(uploadingFiles) > 0) + return t('files','File upload is in progress. Leaving the page now will cancel the upload.'); + }); - //if the breadcrumb is to long, start by replacing foldernames with '...' except for the current folder - var crumb=$('div.crumb').first(); - while($('div.controls').height()>40 && crumb.next('div.crumb').length>0){ - crumb.children('a').text('...'); - crumb=crumb.next('div.crumb'); - } - //if that isn't enough, start removing items from the breacrumb except for the current folder and it's parent - var crumb=$('div.crumb').first(); - var next=crumb.next('div.crumb'); - while($('div.controls').height()>40 && next.next('div.crumb').length>0){ - crumb.remove(); - crumb=next; - next=crumb.next('div.crumb'); - } - //still not enough, start shorting down the current folder name - var crumb=$('div.crumb>a').last(); - while($('div.controls').height()>40 && crumb.text().length>6){ - var text=crumb.text() - text=text.substr(0,text.length-6)+'...'; - crumb.text(text); - } + //add multiply file upload attribute to all browsers except konqueror (which crashes when it's used) + if(navigator.userAgent.search(/konqueror/i)==-1){ + $('#file_upload_start').attr('multiple','multiple') + } - $(document).click(function(){ - $('#new>ul').hide(); - $('#new').removeClass('active'); - $('#new li').each(function(i,element){ - if($(element).children('p').length==0){ - $(element).children('form').remove(); - $(element).append('<p>'+$(element).data('text')+'</p>'); - } - }); - }); - $('#new li').click(function(){ - if($(this).children('p').length==0){ - return; + //if the breadcrumb is to long, start by replacing foldernames with '...' except for the current folder + var crumb=$('div.crumb').first(); + while($('div.controls').height()>40 && crumb.next('div.crumb').length>0){ + crumb.children('a').text('...'); + crumb=crumb.next('div.crumb'); + } + //if that isn't enough, start removing items from the breacrumb except for the current folder and it's parent + var crumb=$('div.crumb').first(); + var next=crumb.next('div.crumb'); + while($('div.controls').height()>40 && next.next('div.crumb').length>0){ + crumb.remove(); + crumb=next; + next=crumb.next('div.crumb'); + } + //still not enough, start shorting down the current folder name + var crumb=$('div.crumb>a').last(); + while($('div.controls').height()>40 && crumb.text().length>6){ + var text=crumb.text() + text=text.substr(0,text.length-6)+'...'; + crumb.text(text); } - $('#new li').each(function(i,element){ - if($(element).children('p').length==0){ - $(element).children('form').remove(); - $(element).append('<p>'+$(element).data('text')+'</p>'); - } + $(document).click(function(){ + $('#new>ul').hide(); + $('#new').removeClass('active'); + $('#new li').each(function(i,element){ + if($(element).children('p').length==0){ + $(element).children('form').remove(); + $(element).append('<p>'+$(element).data('text')+'</p>'); + } + }); }); + $('#new li').click(function(){ + if($(this).children('p').length==0){ + return; + } - var type=$(this).data('type'); - var text=$(this).children('p').text(); - $(this).data('text',text); - $(this).children('p').remove(); - var form=$('<form></form>'); - var input=$('<input>'); - form.append(input); - $(this).append(form); - input.focus(); - form.submit(function(event){ - event.stopPropagation(); - event.preventDefault(); - var newname=input.val(); - if(type == 'web' && newname.length == 0) { - OC.Notification.show(t('files', 'URL cannot be empty.')); - return false; - } else if (type != 'web' && !Files.isFileNameValid(newname)) { - return false; - } else if( type == 'folder' && $('#dir').val() == '/' && newname == 'Shared') { - OC.Notification.show(t('files','Invalid folder name. Usage of \'Shared\' is reserved by ownCloud')); - return false; - } - if (FileList.lastAction) { - FileList.lastAction(); - } - var name = getUniqueName(newname); - if (newname != name) { - FileList.checkName(name, newname, true); - var hidden = true; - } else { - var hidden = false; - } - switch(type){ - case 'file': - $.post( - OC.filePath('files','ajax','newfile.php'), - {dir:$('#dir').val(),filename:name}, - function(result){ - if (result.status == 'success') { - var date=new Date(); - FileList.addFile(name,0,date,false,hidden); - var tr=$('tr').filterAttr('data-file',name); - tr.attr('data-mime',result.data.mime); - tr.attr('data-id', result.data.id); - getMimeIcon(result.data.mime,function(path){ - tr.find('td.filename').attr('style','background-image:url('+path+')'); - }); - } else { - OC.dialogs.alert(result.data.message, t('core', 'Error')); + $('#new li').each(function(i,element){ + if($(element).children('p').length==0){ + $(element).children('form').remove(); + $(element).append('<p>'+$(element).data('text')+'</p>'); + } + }); + + var type=$(this).data('type'); + var text=$(this).children('p').text(); + $(this).data('text',text); + $(this).children('p').remove(); + var form=$('<form></form>'); + var input=$('<input>'); + form.append(input); + $(this).append(form); + input.focus(); + form.submit(function(event){ + event.stopPropagation(); + event.preventDefault(); + var newname=input.val(); + if(type == 'web' && newname.length == 0) { + OC.Notification.show(t('files', 'URL cannot be empty.')); + return false; + } else if (type != 'web' && !Files.isFileNameValid(newname)) { + return false; + } else if( type == 'folder' && $('#dir').val() == '/' && newname == 'Shared') { + OC.Notification.show(t('files','Invalid folder name. Usage of \'Shared\' is reserved by ownCloud')); + return false; + } + if (FileList.lastAction) { + FileList.lastAction(); } - } - ); - break; - case 'folder': - $.post( - OC.filePath('files','ajax','newfolder.php'), - {dir:$('#dir').val(),foldername:name}, - function(result){ - if (result.status == 'success') { - var date=new Date(); - FileList.addDir(name,0,date,hidden); - var tr=$('tr').filterAttr('data-file',name); - tr.attr('data-id', result.data.id); + var name = getUniqueName(newname); + if (newname != name) { + FileList.checkName(name, newname, true); + var hidden = true; } else { - OC.dialogs.alert(result.data.message, t('core', 'Error')); + var hidden = false; } - } - ); - break; - case 'web': - if(name.substr(0,8)!='https://' && name.substr(0,7)!='http://'){ - name='http://'+name; - } - var localName=name; - if(localName.substr(localName.length-1,1)=='/'){//strip / - localName=localName.substr(0,localName.length-1) - } - if(localName.indexOf('/')){//use last part of url - localName=localName.split('/').pop(); - } else { //or the domain - localName=(localName.match(/:\/\/(.[^\/]+)/)[1]).replace('www.',''); - } - localName = getUniqueName(localName); - //IE < 10 does not fire the necessary events for the progress bar. - if($('html.lte9').length > 0) { - } else { - $('#uploadprogressbar').progressbar({value:0}); - $('#uploadprogressbar').fadeIn(); - } + switch(type){ + case 'file': + $.post( + OC.filePath('files','ajax','newfile.php'), + {dir:$('#dir').val(),filename:name}, + function(result){ + if (result.status == 'success') { + var date=new Date(); + FileList.addFile(name,0,date,false,hidden); + var tr=$('tr').filterAttr('data-file',name); + tr.attr('data-size',result.data.size); + tr.attr('data-mime',result.data.mime); + tr.attr('data-id', result.data.id); + tr.find('.filesize').text(humanFileSize(result.data.size)); + getMimeIcon(result.data.mime,function(path){ + tr.find('td.filename').attr('style','background-image:url('+path+')'); + }); + } else { + OC.dialogs.alert(result.data.message, t('core', 'Error')); + } + } + ); + break; + case 'folder': + $.post( + OC.filePath('files','ajax','newfolder.php'), + {dir:$('#dir').val(),foldername:name}, + function(result){ + if (result.status == 'success') { + var date=new Date(); + FileList.addDir(name,0,date,hidden); + var tr=$('tr').filterAttr('data-file',name); + tr.attr('data-id', result.data.id); + } else { + OC.dialogs.alert(result.data.message, t('core', 'Error')); + } + } + ); + break; + case 'web': + if(name.substr(0,8)!='https://' && name.substr(0,7)!='http://'){ + name='http://'+name; + } + var localName=name; + if(localName.substr(localName.length-1,1)=='/'){//strip / + localName=localName.substr(0,localName.length-1) + } + if(localName.indexOf('/')){//use last part of url + localName=localName.split('/').pop(); + } else { //or the domain + localName=(localName.match(/:\/\/(.[^\/]+)/)[1]).replace('www.',''); + } + localName = getUniqueName(localName); + //IE < 10 does not fire the necessary events for the progress bar. + if($('html.lte9').length > 0) { + } else { + $('#uploadprogressbar').progressbar({value:0}); + $('#uploadprogressbar').fadeIn(); + } - var eventSource=new OC.EventSource(OC.filePath('files','ajax','newfile.php'),{dir:$('#dir').val(),source:name,filename:localName}); - eventSource.listen('progress',function(progress){ - //IE < 10 does not fire the necessary events for the progress bar. - if($('html.lte9').length > 0) { - } else { - $('#uploadprogressbar').progressbar('value',progress); - } - }); - eventSource.listen('success',function(data){ - var mime=data.mime; - var size=data.size; - var id=data.id; - $('#uploadprogressbar').fadeOut(); - var date=new Date(); - FileList.addFile(localName,size,date,false,hidden); - var tr=$('tr').filterAttr('data-file',localName); - tr.data('mime',mime).data('id',id); - tr.attr('data-id', id); - getMimeIcon(mime,function(path){ - tr.find('td.filename').attr('style','background-image:url('+path+')'); - }); - }); - eventSource.listen('error',function(error){ - $('#uploadprogressbar').fadeOut(); - alert(error); + var eventSource=new OC.EventSource(OC.filePath('files','ajax','newfile.php'),{dir:$('#dir').val(),source:name,filename:localName}); + eventSource.listen('progress',function(progress){ + //IE < 10 does not fire the necessary events for the progress bar. + if($('html.lte9').length > 0) { + } else { + $('#uploadprogressbar').progressbar('value',progress); + } + }); + eventSource.listen('success',function(data){ + var mime=data.mime; + var size=data.size; + var id=data.id; + $('#uploadprogressbar').fadeOut(); + var date=new Date(); + FileList.addFile(localName,size,date,false,hidden); + var tr=$('tr').filterAttr('data-file',localName); + tr.data('mime',mime).data('id',id); + tr.attr('data-id', id); + getMimeIcon(mime,function(path){ + tr.find('td.filename').attr('style','background-image:url('+path+')'); + }); + }); + eventSource.listen('error',function(error){ + $('#uploadprogressbar').fadeOut(); + alert(error); + }); + break; + } + var li=form.parent(); + form.remove(); + li.append('<p>'+li.data('text')+'</p>'); + $('#new>a').click(); }); - break; - } - var li=form.parent(); - form.remove(); - li.append('<p>'+li.data('text')+'</p>'); - $('#new>a').click(); }); - }); }); diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 8753319020d..4eb949c2eef 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -379,7 +379,9 @@ $(document).ready(function() { FileList.addFile(name,0,date,false,hidden); var tr=$('tr').filterAttr('data-file',name); tr.attr('data-mime',result.data.mime); + tr.attr('data-size',result.data.size); tr.attr('data-id', result.data.id); + tr.find('.filesize').text(humanFileSize(result.data.size)); getMimeIcon(result.data.mime,function(path){ tr.find('td.filename').attr('style','background-image:url('+path+')'); }); diff --git a/apps/files/js/keyboardshortcuts.js b/apps/files/js/keyboardshortcuts.js index cc2b5d42139..418c38adb99 100644 --- a/apps/files/js/keyboardshortcuts.js +++ b/apps/files/js/keyboardshortcuts.js @@ -165,4 +165,4 @@ var Files = Files || {}; removeA(keys, event.keyCode); }); }; -})(Files);
\ No newline at end of file +})(Files); diff --git a/apps/files/lib/app.php b/apps/files/lib/app.php index f7052ef80b0..579e8676cfc 100644 --- a/apps/files/lib/app.php +++ b/apps/files/lib/app.php @@ -76,4 +76,4 @@ class App { return $result; } -}
\ No newline at end of file +} diff --git a/apps/files/lib/capabilities.php b/apps/files/lib/capabilities.php index 90a5e2f4eb9..d4820e931ba 100644 --- a/apps/files/lib/capabilities.php +++ b/apps/files/lib/capabilities.php @@ -21,4 +21,4 @@ class Capabilities { )); } -}
\ No newline at end of file +} diff --git a/apps/files/tests/ajax_rename.php b/apps/files/tests/ajax_rename.php index 2b90a11743d..8eff978cde0 100644 --- a/apps/files/tests/ajax_rename.php +++ b/apps/files/tests/ajax_rename.php @@ -114,4 +114,4 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase { $this->assertEquals($expected, $result); } -}
\ No newline at end of file +} diff --git a/apps/files_encryption/ajax/changeRecoveryPassword.php b/apps/files_encryption/ajax/changeRecoveryPassword.php index 366f634a51c..945f054ea84 100644 --- a/apps/files_encryption/ajax/changeRecoveryPassword.php +++ b/apps/files_encryption/ajax/changeRecoveryPassword.php @@ -49,4 +49,4 @@ if ($return) { \OCP\JSON::success(array('data' => array('message' => $l->t('Password successfully changed.')))); } else { \OCP\JSON::error(array('data' => array('message' => $l->t('Could not change the password. Maybe the old password was not correct.')))); -}
\ No newline at end of file +} diff --git a/apps/files_encryption/ajax/updatePrivateKeyPassword.php b/apps/files_encryption/ajax/updatePrivateKeyPassword.php index 6fd63dae9cd..1e6644da576 100644 --- a/apps/files_encryption/ajax/updatePrivateKeyPassword.php +++ b/apps/files_encryption/ajax/updatePrivateKeyPassword.php @@ -51,4 +51,4 @@ if ($return) { \OCP\JSON::success(array('data' => array('message' => $l->t('Private key password successfully updated.')))); } else { \OCP\JSON::error(array('data' => array('message' => $l->t('Could not update the private key password. Maybe the old password was not correct.')))); -}
\ No newline at end of file +} diff --git a/apps/files_encryption/ajax/userrecovery.php b/apps/files_encryption/ajax/userrecovery.php index 1d0f1ac2d17..d6c94bde81e 100644 --- a/apps/files_encryption/ajax/userrecovery.php +++ b/apps/files_encryption/ajax/userrecovery.php @@ -38,4 +38,4 @@ if ( } // Return success or failure -($return) ? \OCP\JSON::success() : \OCP\JSON::error();
\ No newline at end of file +($return) ? \OCP\JSON::success() : \OCP\JSON::error(); diff --git a/apps/files_encryption/appinfo/routes.php b/apps/files_encryption/appinfo/routes.php index ab83432a4b2..07ff920a60d 100644 --- a/apps/files_encryption/appinfo/routes.php +++ b/apps/files_encryption/appinfo/routes.php @@ -6,4 +6,4 @@ */ // Register with the capabilities API -OC_API::register('get', '/cloud/capabilities', array('OCA\Encryption\Capabilities', 'getCapabilities'), 'files_encryption', OC_API::USER_AUTH);
\ No newline at end of file +OC_API::register('get', '/cloud/capabilities', array('OCA\Encryption\Capabilities', 'getCapabilities'), 'files_encryption', OC_API::USER_AUTH); diff --git a/apps/files_encryption/css/settings-personal.css b/apps/files_encryption/css/settings-personal.css index 4ee0acc9768..8eb5bedcb06 100644 --- a/apps/files_encryption/css/settings-personal.css +++ b/apps/files_encryption/css/settings-personal.css @@ -7,4 +7,4 @@ , #recoveryEnabledError , #recoveryEnabledSuccess { display: none; -}
\ No newline at end of file +} diff --git a/apps/files_encryption/js/settings-admin.js b/apps/files_encryption/js/settings-admin.js index 7c1866445ee..6647c621e7b 100644 --- a/apps/files_encryption/js/settings-admin.js +++ b/apps/files_encryption/js/settings-admin.js @@ -99,4 +99,4 @@ $(document).ready(function(){ ); }); -});
\ No newline at end of file +}); diff --git a/apps/files_encryption/js/settings-personal.js b/apps/files_encryption/js/settings-personal.js index d6535a25b70..e16519c3c98 100644 --- a/apps/files_encryption/js/settings-personal.js +++ b/apps/files_encryption/js/settings-personal.js @@ -95,4 +95,4 @@ $(document).ready(function(){ updatePrivateKeyPasswd(); }); -});
\ No newline at end of file +}); diff --git a/apps/files_encryption/lib/capabilities.php b/apps/files_encryption/lib/capabilities.php index 72baddcd049..ef94c9e086d 100644 --- a/apps/files_encryption/lib/capabilities.php +++ b/apps/files_encryption/lib/capabilities.php @@ -20,4 +20,4 @@ class Capabilities { )); } -}
\ No newline at end of file +} diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index b2fd650f18d..5386de486e1 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -593,4 +593,4 @@ class Keymanager { return $targetPath; } -}
\ No newline at end of file +} diff --git a/apps/files_encryption/settings-personal.php b/apps/files_encryption/settings-personal.php index fddc3ea5eee..589219f32ad 100644 --- a/apps/files_encryption/settings-personal.php +++ b/apps/files_encryption/settings-personal.php @@ -16,7 +16,7 @@ $view = new \OC_FilesystemView('/'); $util = new \OCA\Encryption\Util($view, $user);
$session = new \OCA\Encryption\Session($view);
-$privateKeySet = ($session->getPrivateKey() !== false) ? true : false;
+$privateKeySet = $session->getPrivateKey() !== false; $recoveryAdminEnabled = OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled');
$recoveryEnabledForUser = $util->recoveryEnabledForUser();
diff --git a/apps/files_encryption/tests/stream.php b/apps/files_encryption/tests/stream.php index 50ac41e4536..5193f8c9686 100644 --- a/apps/files_encryption/tests/stream.php +++ b/apps/files_encryption/tests/stream.php @@ -180,4 +180,4 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase { // tear down $view->unlink($filename); } -}
\ No newline at end of file +} diff --git a/apps/files_encryption/tests/trashbin.php b/apps/files_encryption/tests/trashbin.php index 985271b9021..d64035df50e 100755 --- a/apps/files_encryption/tests/trashbin.php +++ b/apps/files_encryption/tests/trashbin.php @@ -300,4 +300,4 @@ class Test_Encryption_Trashbin extends \PHPUnit_Framework_TestCase { . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.' . $trashFileSuffix)); } -}
\ No newline at end of file +} diff --git a/apps/files_encryption/tests/webdav.php b/apps/files_encryption/tests/webdav.php index 9268bf2c25f..33b3ce6f2f2 100755 --- a/apps/files_encryption/tests/webdav.php +++ b/apps/files_encryption/tests/webdav.php @@ -259,4 +259,4 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase { // return captured content return $content; } -}
\ No newline at end of file +} diff --git a/apps/files_external/ajax/addMountPoint.php b/apps/files_external/ajax/addMountPoint.php index fed2ddfcf3d..9100d47db3a 100644 --- a/apps/files_external/ajax/addMountPoint.php +++ b/apps/files_external/ajax/addMountPoint.php @@ -16,4 +16,4 @@ $status = OC_Mount_Config::addMountPoint($_POST['mountPoint'], $_POST['mountType'], $_POST['applicable'], $isPersonal); -OCP\JSON::success(array('data' => array('message' => $status)));
\ No newline at end of file +OCP\JSON::success(array('data' => array('message' => $status))); diff --git a/apps/files_external/ajax/google.php b/apps/files_external/ajax/google.php index e63b7cb07b9..2594a1780b3 100644 --- a/apps/files_external/ajax/google.php +++ b/apps/files_external/ajax/google.php @@ -39,4 +39,4 @@ if (isset($_POST['client_id']) && isset($_POST['client_secret']) && isset($_POST } } } -}
\ No newline at end of file +} diff --git a/apps/files_external/js/google.js b/apps/files_external/js/google.js index 7e111a95d98..b4be1c1dc41 100644 --- a/apps/files_external/js/google.js +++ b/apps/files_external/js/google.js @@ -126,4 +126,4 @@ $(document).ready(function() { } }); -});
\ No newline at end of file +}); diff --git a/apps/files_external/lib/amazons3.php b/apps/files_external/lib/amazons3.php index f4d1940b184..9363a350e27 100644 --- a/apps/files_external/lib/amazons3.php +++ b/apps/files_external/lib/amazons3.php @@ -79,7 +79,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { $this->bucket = $params['bucket']; $scheme = ($params['use_ssl'] === 'false') ? 'http' : 'https'; - $this->test = ( isset($params['test'])) ? true : false; + $this->test = isset($params['test']); $this->timeout = ( ! isset($params['timeout'])) ? 15 : $params['timeout']; $params['region'] = ( ! isset($params['region'])) ? 'eu-west-1' : $params['region']; $params['hostname'] = ( !isset($params['hostname'])) ? 's3.amazonaws.com' : $params['hostname']; diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 14e974d65ca..1935740cd2e 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -418,9 +418,9 @@ class OC_Mount_Config { public static function checksmbclient() { if(function_exists('shell_exec')) { $output=shell_exec('which smbclient'); - return (empty($output)?false:true); + return !empty($output); }else{ - return(false); + return false; } } @@ -429,9 +429,9 @@ class OC_Mount_Config { */ public static function checkphpftp() { if(function_exists('ftp_login')) { - return(true); + return true; }else{ - return(false); + return false; } } @@ -439,7 +439,7 @@ class OC_Mount_Config { * check if curl is installed */ public static function checkcurl() { - return (function_exists('curl_init')); + return function_exists('curl_init'); } /** @@ -460,6 +460,6 @@ class OC_Mount_Config { $txt.=$l->t('<b>Warning:</b> The Curl support in PHP is not enabled or installed. Mounting of ownCloud / WebDAV or GoogleDrive is not possible. Please ask your system administrator to install it.').'<br />'; } - return($txt); + return $txt; } } diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php index ef8dd6d8cad..e6cdacdec4f 100644 --- a/apps/files_external/lib/google.php +++ b/apps/files_external/lib/google.php @@ -587,4 +587,4 @@ class Google extends \OC\Files\Storage\Common { return false; } -}
\ No newline at end of file +} diff --git a/apps/files_external/lib/sftp.php b/apps/files_external/lib/sftp.php index 4fd36096463..f7f329b8993 100644 --- a/apps/files_external/lib/sftp.php +++ b/apps/files_external/lib/sftp.php @@ -170,7 +170,7 @@ class SFTP extends \OC\Files\Storage\Common { public function file_exists($path) { try { - return $this->client->stat($this->abs_path($path)) === false ? false : true; + return $this->client->stat($this->abs_path($path)) !== false; } catch (\Exception $e) { return false; } diff --git a/apps/files_external/tests/google.php b/apps/files_external/tests/google.php index 12faabb902d..d5495d49c5e 100644 --- a/apps/files_external/tests/google.php +++ b/apps/files_external/tests/google.php @@ -42,4 +42,4 @@ class Google extends Storage { $this->instance->rmdir('/'); } } -}
\ No newline at end of file +} diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 9363a5431fa..895d446a336 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -15,4 +15,4 @@ OCP\Util::addScript('files_sharing', 'share'); \OC_Hook::connect('OC_Filesystem', 'delete', '\OC\Files\Cache\Shared_Updater', 'deleteHook'); \OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Shared_Updater', 'renameHook'); \OC_Hook::connect('OCP\Share', 'post_shared', '\OC\Files\Cache\Shared_Updater', 'shareHook'); -\OC_Hook::connect('OCP\Share', 'pre_unshare', '\OC\Files\Cache\Shared_Updater', 'shareHook');
\ No newline at end of file +\OC_Hook::connect('OCP\Share', 'pre_unshare', '\OC\Files\Cache\Shared_Updater', 'shareHook'); diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index b2efafde4e7..3be89a39fa0 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -38,4 +38,4 @@ $(document).ready(function() { } }); } -});
\ No newline at end of file +}); diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index 2160fe9a393..33cd1428899 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -288,4 +288,4 @@ class Shared_Cache extends Cache { return false; } -}
\ No newline at end of file +} diff --git a/apps/files_sharing/lib/permissions.php b/apps/files_sharing/lib/permissions.php index b6638564cd8..e2978e12bfb 100644 --- a/apps/files_sharing/lib/permissions.php +++ b/apps/files_sharing/lib/permissions.php @@ -106,4 +106,4 @@ class Shared_Permissions extends Permissions { // Not a valid action for Shared Permissions } -}
\ No newline at end of file +} diff --git a/apps/files_sharing/lib/watcher.php b/apps/files_sharing/lib/watcher.php index e67d1ee9086..6fdfc1db36d 100644 --- a/apps/files_sharing/lib/watcher.php +++ b/apps/files_sharing/lib/watcher.php @@ -48,4 +48,4 @@ class Shared_Watcher extends Watcher { } } -}
\ No newline at end of file +} diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index 741ab145384..e9fdf6e4c95 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -112,9 +112,9 @@ if (isset($path)) { if ($files_list === NULL ) { $files_list = array($files); } - OC_Files::get($path, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false); + OC_Files::get($path, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD'); } else { - OC_Files::get($dir, $file, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false); + OC_Files::get($dir, $file, $_SERVER['REQUEST_METHOD'] == 'HEAD'); } exit(); } else { @@ -133,7 +133,7 @@ if (isset($path)) { $tmpl->assign('mimetype', \OC\Files\Filesystem::getMimeType($path)); $tmpl->assign('fileTarget', basename($linkItem['file_target'])); $tmpl->assign('dirToken', $linkItem['token']); - $allowPublicUploadEnabled = (($linkItem['permissions'] & OCP\PERMISSION_CREATE) ? true : false ); + $allowPublicUploadEnabled = (bool) ($linkItem['permissions'] & OCP\PERMISSION_CREATE); if (\OCP\App::isEnabled('files_encryption')) { $allowPublicUploadEnabled = false; } diff --git a/apps/files_sharing/templates/part.404.php b/apps/files_sharing/templates/part.404.php index b5152e1511a..3ef117d7524 100644 --- a/apps/files_sharing/templates/part.404.php +++ b/apps/files_sharing/templates/part.404.php @@ -9,4 +9,4 @@ </ul> <p><?php p($l->t('For more info, please ask the person who sent this link.')); ?></p> </li> -</ul>
\ No newline at end of file +</ul> diff --git a/apps/files_trashbin/appinfo/app.php b/apps/files_trashbin/appinfo/app.php index 3b1e0ac30cc..2c101f0a723 100644 --- a/apps/files_trashbin/appinfo/app.php +++ b/apps/files_trashbin/appinfo/app.php @@ -4,4 +4,4 @@ OC::$CLASSPATH['OCA\Files_Trashbin\Hooks'] = 'files_trashbin/lib/hooks.php'; OC::$CLASSPATH['OCA\Files_Trashbin\Trashbin'] = 'files_trashbin/lib/trash.php'; // register hooks -\OCA\Files_Trashbin\Trashbin::registerHooks();
\ No newline at end of file +\OCA\Files_Trashbin\Trashbin::registerHooks(); diff --git a/apps/files_trashbin/appinfo/update.php b/apps/files_trashbin/appinfo/update.php index f4dad7b26bf..0ca232668d7 100644 --- a/apps/files_trashbin/appinfo/update.php +++ b/apps/files_trashbin/appinfo/update.php @@ -7,4 +7,4 @@ if (version_compare($installedVersion, '0.4', '<')) { //enforce a recalculation during next usage. $query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trashsize`'); $result = $query->execute(); -}
\ No newline at end of file +} diff --git a/apps/files_trashbin/js/disableDefaultActions.js b/apps/files_trashbin/js/disableDefaultActions.js index df08bfb1a50..afa80cacd6b 100644 --- a/apps/files_trashbin/js/disableDefaultActions.js +++ b/apps/files_trashbin/js/disableDefaultActions.js @@ -1,4 +1,4 @@ /* disable download and sharing actions */ var disableDownloadActions = true; var disableSharing = true; -var trashBinApp = true;
\ No newline at end of file +var trashBinApp = true; diff --git a/apps/files_versions/appinfo/routes.php b/apps/files_versions/appinfo/routes.php index 8cef57c9e4d..38c288adf9d 100644 --- a/apps/files_versions/appinfo/routes.php +++ b/apps/files_versions/appinfo/routes.php @@ -6,4 +6,4 @@ */ // Register with the capabilities API -OC_API::register('get', '/cloud/capabilities', array('OCA\Files_Versions\Capabilities', 'getCapabilities'), 'files_versions', OC_API::USER_AUTH);
\ No newline at end of file +OC_API::register('get', '/cloud/capabilities', array('OCA\Files_Versions\Capabilities', 'getCapabilities'), 'files_versions', OC_API::USER_AUTH); diff --git a/apps/files_versions/lib/capabilities.php b/apps/files_versions/lib/capabilities.php index 3251a07b6ae..45d7dd3fb02 100644 --- a/apps/files_versions/lib/capabilities.php +++ b/apps/files_versions/lib/capabilities.php @@ -20,4 +20,4 @@ class Capabilities { )); } -}
\ No newline at end of file +} diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index 70b8f30be5c..0b4699dc5c0 100644 --- a/apps/files_versions/lib/versions.php +++ b/apps/files_versions/lib/versions.php @@ -48,14 +48,14 @@ class Storage { /** * get current size of all versions from a given user - * + * * @param $user user who owns the versions * @return mixed versions size or false if no versions size is stored */ private static function getVersionsSize($user) { $query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*files_versions` WHERE `user`=?'); $result = $query->execute(array($user))->fetchAll(); - + if ($result) { return $result[0]['size']; } @@ -64,7 +64,7 @@ class Storage { /** * write to the database how much space is in use for versions - * + * * @param $user owner of the versions * @param $size size of the versions */ @@ -76,20 +76,20 @@ class Storage { } $query->execute(array($size, $user)); } - + /** * store a new version of a file. */ public static function store($filename) { if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { - + // if the file gets streamed we need to remove the .part extension // to get the right target $ext = pathinfo($filename, PATHINFO_EXTENSION); if ($ext === 'part') { $filename = substr($filename, 0, strlen($filename)-5); } - + list($uid, $filename) = self::getUidAndFilename($filename); $files_view = new \OC\Files\View('/'.$uid .'/files'); @@ -104,17 +104,12 @@ class Storage { // we should have a source file to work with, and the file shouldn't // be empty $fileExists = $files_view->file_exists($filename); - $fileSize = $files_view->filesize($filename); - if ($fileExists === false || $fileSize === 0) { + if (!($fileExists && $files_view->filesize($filename) > 0)) { return false; } // create all parent folders - $info=pathinfo($filename); - $versionsFolderName=$versions_view->getLocalFolder(''); - if(!file_exists($versionsFolderName.'/'.$info['dirname'])) { - mkdir($versionsFolderName.'/'.$info['dirname'], 0750, true); - } + self::createMissingDirectories($filename, $users_view); $versionsSize = self::getVersionsSize($uid); if ( $versionsSize === false || $versionsSize < 0 ) { @@ -174,7 +169,7 @@ class Storage { list($uidn, $newpath) = self::getUidAndFilename($new_path); $versions_view = new \OC\Files\View('/'.$uid .'/files_versions'); $files_view = new \OC\Files\View('/'.$uid .'/files'); - + // if the file already exists than it was a upload of a existing file // over the web interface -> store() is the right function we need here if ($files_view->file_exists($newpath)) { @@ -183,13 +178,12 @@ class Storage { self::expire($newpath); - $abs_newpath = $versions_view->getLocalFile($newpath); - if ( $files_view->is_dir($oldpath) && $versions_view->is_dir($oldpath) ) { $versions_view->rename($oldpath, $newpath); } else if ( ($versions = Storage::getVersions($uid, $oldpath)) ) { - $info=pathinfo($abs_newpath); - if(!file_exists($info['dirname'])) mkdir($info['dirname'], 0750, true); + // create missing dirs if necessary + self::createMissingDirectories($newpath, new \OC\Files\View('/'. $uidn)); + foreach ($versions as $v) { $versions_view->rename($oldpath.'.v'.$v['version'], $newpath.'.v'.$v['version']); } @@ -435,7 +429,7 @@ class Storage { } else { $quota = \OCP\Util::computerFileSize($quota); } - + // make sure that we have the current size of the version history if ( $versionsSize === null ) { $versionsSize = self::getVersionsSize($uid); @@ -568,4 +562,21 @@ class Storage { return $size; } + /** + * @brief create recursively missing directories + * @param string $filename $path to a file + * @param \OC\Files\View $view view on data/user/ + */ + private static function createMissingDirectories($filename, $view) { + $dirname = \OC_Filesystem::normalizePath(dirname($filename)); + $dirParts = explode('/', $dirname); + $dir = "/files_versions"; + foreach ($dirParts as $part) { + $dir = $dir . '/' . $part; + if (!$view->file_exists($dir)) { + $view->mkdir($dir); + } + } + } + } diff --git a/apps/user_ldap/ajax/clearMappings.php b/apps/user_ldap/ajax/clearMappings.php index 5dab39839b6..9118d58c5cf 100644 --- a/apps/user_ldap/ajax/clearMappings.php +++ b/apps/user_ldap/ajax/clearMappings.php @@ -32,4 +32,4 @@ if(\OCA\user_ldap\lib\Helper::clearMapping($subject)) { } else { $l=OC_L10N::get('user_ldap'); OCP\JSON::error(array('message' => $l->t('Failed to clear the mappings.'))); -}
\ No newline at end of file +} diff --git a/apps/user_ldap/ajax/getConfiguration.php b/apps/user_ldap/ajax/getConfiguration.php index dfae68d2dc9..baca588976f 100644 --- a/apps/user_ldap/ajax/getConfiguration.php +++ b/apps/user_ldap/ajax/getConfiguration.php @@ -28,4 +28,4 @@ OCP\JSON::callCheck(); $prefix = $_POST['ldap_serverconfig_chooser']; $connection = new \OCA\user_ldap\lib\Connection($prefix); -OCP\JSON::success(array('configuration' => $connection->getConfiguration()));
\ No newline at end of file +OCP\JSON::success(array('configuration' => $connection->getConfiguration())); diff --git a/apps/user_ldap/ajax/getNewServerConfigPrefix.php b/apps/user_ldap/ajax/getNewServerConfigPrefix.php index 17e78f87072..1c68b2e9a76 100644 --- a/apps/user_ldap/ajax/getNewServerConfigPrefix.php +++ b/apps/user_ldap/ajax/getNewServerConfigPrefix.php @@ -31,4 +31,4 @@ sort($serverConnections); $lk = array_pop($serverConnections); $ln = intval(str_replace('s', '', $lk)); $nk = 's'.str_pad($ln+1, 2, '0', STR_PAD_LEFT); -OCP\JSON::success(array('configPrefix' => $nk));
\ No newline at end of file +OCP\JSON::success(array('configPrefix' => $nk)); diff --git a/apps/user_ldap/ajax/setConfiguration.php b/apps/user_ldap/ajax/setConfiguration.php index 206487c7e0a..d850bda2470 100644 --- a/apps/user_ldap/ajax/setConfiguration.php +++ b/apps/user_ldap/ajax/setConfiguration.php @@ -30,4 +30,4 @@ $prefix = $_POST['ldap_serverconfig_chooser']; $connection = new \OCA\user_ldap\lib\Connection($prefix); $connection->setConfiguration($_POST); $connection->saveConfiguration(); -OCP\JSON::success();
\ No newline at end of file +OCP\JSON::success(); diff --git a/apps/user_ldap/css/settings.css b/apps/user_ldap/css/settings.css index 185952e14bb..6086c7b74e6 100644 --- a/apps/user_ldap/css/settings.css +++ b/apps/user_ldap/css/settings.css @@ -3,14 +3,20 @@ max-width: 200px; display: inline-block; vertical-align: top; + text-align: right; padding-top: 9px; + padding-right: 5px; } #ldap fieldset input, #ldap fieldset textarea { - width: 70%; + width: 60%; display: inline-block; } +#ldap fieldset p input[type=checkbox] { + vertical-align: bottom; +} + .ldapIndent { margin-left: 50px; } @@ -18,4 +24,4 @@ .ldapwarning { margin-left: 1.4em; color: #FF3B3B; -}
\ No newline at end of file +} diff --git a/apps/user_ldap/group_proxy.php b/apps/user_ldap/group_proxy.php index 75e7cd46336..eb6f176c58c 100644 --- a/apps/user_ldap/group_proxy.php +++ b/apps/user_ldap/group_proxy.php @@ -198,4 +198,4 @@ class Group_Proxy extends lib\Proxy implements \OCP\GroupInterface { //it's the same across all our user backends obviously return $this->refBackend->implementsActions($actions); } -}
\ No newline at end of file +} diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js index 52d5dbc48d9..78ec71b70ad 100644 --- a/apps/user_ldap/js/settings.js +++ b/apps/user_ldap/js/settings.js @@ -176,6 +176,13 @@ $(document).ready(function() { $('#ldap_submit').effect('highlight', {'color':'#A8FA87'}, 5000, function() { $('#ldap_submit').css('background', bgcolor); }); + //update the Label in the config chooser + caption = $('#ldap_serverconfig_chooser option:selected:first').text(); + pretext = '. Server: '; + caption = caption.slice(0, caption.indexOf(pretext) + pretext.length); + caption = caption + $('#ldap_host').val(); + $('#ldap_serverconfig_chooser option:selected:first').text(caption); + } else { $('#ldap_submit').css('background', '#fff'); $('#ldap_submit').effect('highlight', {'color':'#E97'}, 5000, function() { @@ -204,4 +211,4 @@ $(document).ready(function() { LdapConfiguration.refreshConfig(); } }); -});
\ No newline at end of file +}); diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php index 0372112f0e2..e5d9b4d5b40 100644 --- a/apps/user_ldap/lib/connection.php +++ b/apps/user_ldap/lib/connection.php @@ -80,7 +80,12 @@ class Connection { public function __construct($configPrefix = '', $configID = 'user_ldap') { $this->configPrefix = $configPrefix; $this->configID = $configID; - $this->cache = \OC_Cache::getGlobalCache(); + $memcache = new \OC\Memcache\Factory(); + if($memcache->isAvailable()) { + $this->cache = $memcache->create(); + } else { + $this->cache = \OC_Cache::getGlobalCache(); + } $this->config['hasPagedResultSupport'] = (function_exists('ldap_control_paged_result') && function_exists('ldap_control_paged_result_response')); } diff --git a/apps/user_ldap/lib/helper.php b/apps/user_ldap/lib/helper.php index f65f466789f..4c9dd07a12c 100644 --- a/apps/user_ldap/lib/helper.php +++ b/apps/user_ldap/lib/helper.php @@ -71,6 +71,34 @@ class Helper { } /** + * + * @brief determines the host for every configured connection + * @return an array with configprefix as keys + * + */ + static public function getServerConfigurationHosts() { + $referenceConfigkey = 'ldap_host'; + + $query = ' + SELECT DISTINCT `configkey`, `configvalue` + FROM `*PREFIX*appconfig` + WHERE `appid` = \'user_ldap\' + AND `configkey` LIKE ? + '; + $query = \OCP\DB::prepare($query); + $configHosts = $query->execute(array('%'.$referenceConfigkey))->fetchAll(); + $result = array(); + + foreach($configHosts as $configHost) { + $len = strlen($configHost['configkey']) - strlen($referenceConfigkey); + $prefix = substr($configHost['configkey'], 0, $len); + $result[$prefix] = $configHost['configvalue']; + } + + return $result; + } + + /** * @brief deletes a given saved LDAP/AD server configuration. * @param string the configuration prefix of the config to delete * @return bool true on success, false otherwise diff --git a/apps/user_ldap/lib/proxy.php b/apps/user_ldap/lib/proxy.php index c80e2163475..ae3e3be7361 100644 --- a/apps/user_ldap/lib/proxy.php +++ b/apps/user_ldap/lib/proxy.php @@ -101,4 +101,4 @@ abstract class Proxy { public function clearCache() { $this->cache->clear($this->getCacheKey(null)); } -}
\ No newline at end of file +} diff --git a/apps/user_ldap/settings.php b/apps/user_ldap/settings.php index 22e2dac6d26..7169192a18e 100644 --- a/apps/user_ldap/settings.php +++ b/apps/user_ldap/settings.php @@ -44,7 +44,9 @@ OCP\Util::addstyle('user_ldap', 'settings'); $tmpl = new OCP\Template('user_ldap', 'settings'); $prefixes = \OCA\user_ldap\lib\Helper::getServerConfigurationPrefixes(); +$hosts = \OCA\user_ldap\lib\Helper::getServerConfigurationHosts(); $tmpl->assign('serverConfigurationPrefixes', $prefixes); +$tmpl->assign('serverConfigurationHosts', $hosts); // assign default values if(!isset($ldap)) { diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php index 95aa592594b..e214d57fb1d 100644 --- a/apps/user_ldap/templates/settings.php +++ b/apps/user_ldap/templates/settings.php @@ -24,7 +24,7 @@ $sel = ' selected'; foreach($_['serverConfigurationPrefixes'] as $prefix) { ?> - <option value="<?php p($prefix); ?>"<?php p($sel); ?>><?php p($i++); ?>. Server</option> + <option value="<?php p($prefix); ?>"<?php p($sel); $sel = ''; ?>><?php p($i++); ?>. Server: <?php p($_['serverConfigurationHosts'][$prefix]); ?></option> <?php } } @@ -51,18 +51,15 @@ <p><label for="ldap_login_filter"><?php p($l->t('User Login Filter'));?></label> <input type="text" id="ldap_login_filter" name="ldap_login_filter" data-default="<?php p($_['ldap_login_filter_default']); ?>" - title="<?php p($l->t('Defines the filter to apply, when login is attempted. %%uid replaces the username in the login action.'));?>" /> - <br /><small><?php p($l->t('use %%uid placeholder, e.g. "uid=%%uid"'));?></small></p> + title="<?php p($l->t('Defines the filter to apply, when login is attempted. %%uid replaces the username in the login action. Example: "uid=%%uid"'));?>" /></p> <p><label for="ldap_userlist_filter"><?php p($l->t('User List Filter'));?></label> <input type="text" id="ldap_userlist_filter" name="ldap_userlist_filter" data-default="<?php p($_['ldap_userlist_filter_default']); ?>" - title="<?php p($l->t('Defines the filter to apply, when retrieving users.'));?>" /> - <br /><small><?php p($l->t('without any placeholder, e.g. "objectClass=person".'));?></small></p> + title="<?php p($l->t('Defines the filter to apply, when retrieving users (no placeholders). Example: "objectClass=person"'));?>" /></p> <p><label for="ldap_group_filter"><?php p($l->t('Group Filter'));?></label> <input type="text" id="ldap_group_filter" name="ldap_group_filter" data-default="<?php p($_['ldap_group_filter_default']); ?>" - title="<?php p($l->t('Defines the filter to apply, when retrieving groups.'));?>" /> - <br /><small><?php p($l->t('without any placeholder, e.g. "objectClass=posixGroup".'));?></small></p> + title="<?php p($l->t('Defines the filter to apply, when retrieving groups (no placeholders). Example: "objectClass=posixGroup"'));?>" /></p> </fieldset> <fieldset id="ldapSettings-2"> <div id="ldapAdvancedAccordion"> @@ -75,7 +72,7 @@ <p><label for="ldap_override_main_server"><?php p($l->t('Disable Main Server'));?></label><input type="checkbox" id="ldap_override_main_server" name="ldap_override_main_server" value="1" data-default="<?php p($_['ldap_override_main_server_default']); ?>" title="<?php p($l->t('Only connect to the replica server.'));?>" /></p> <p><label for="ldap_tls"><?php p($l->t('Use TLS'));?></label><input type="checkbox" id="ldap_tls" name="ldap_tls" value="1" data-default="<?php p($_['ldap_tls_default']); ?>" title="<?php p($l->t('Do not use it additionally for LDAPS connections, it will fail.'));?>" /></p> <p><label for="ldap_nocase"><?php p($l->t('Case insensitve LDAP server (Windows)'));?></label><input type="checkbox" id="ldap_nocase" name="ldap_nocase" data-default="<?php p($_['ldap_nocase_default']); ?>" value="1"<?php if (isset($_['ldap_nocase']) && ($_['ldap_nocase'])) p(' checked'); ?>></p> - <p><label for="ldap_turn_off_cert_check"><?php p($l->t('Turn off SSL certificate validation.'));?></label><input type="checkbox" id="ldap_turn_off_cert_check" name="ldap_turn_off_cert_check" title="<?php p($l->t('If connection only works with this option, import the LDAP server\'s SSL certificate in your %s server.', $theme->getName() ));?>" data-default="<?php p($_['ldap_turn_off_cert_check_default']); ?>" value="1"><br/><small><?php p($l->t('Not recommended, use for testing only.'));?></small></p> + <p><label for="ldap_turn_off_cert_check"><?php p($l->t('Turn off SSL certificate validation.'));?></label><input type="checkbox" id="ldap_turn_off_cert_check" name="ldap_turn_off_cert_check" title="<?php p($l->t('Not recommended, use it for testing only! If connection only works with this option, import the LDAP server\'s SSL certificate in your %s server.', $theme->getName() ));?>" data-default="<?php p($_['ldap_turn_off_cert_check_default']); ?>" value="1"><br/></p> <p><label for="ldap_cache_ttl"><?php p($l->t('Cache Time-To-Live'));?></label><input type="number" id="ldap_cache_ttl" name="ldap_cache_ttl" title="<?php p($l->t('in seconds. A change empties the cache.'));?>" data-default="<?php p($_['ldap_cache_ttl_default']); ?>" /></p> </div> <h3><?php p($l->t('Directory Settings'));?></h3> diff --git a/apps/user_ldap/user_proxy.php b/apps/user_ldap/user_proxy.php index 73cc0963182..0722d8871a4 100644 --- a/apps/user_ldap/user_proxy.php +++ b/apps/user_ldap/user_proxy.php @@ -198,4 +198,4 @@ class User_Proxy extends lib\Proxy implements \OCP\UserInterface { return $this->refBackend->hasUserListings(); } -}
\ No newline at end of file +} diff --git a/core/css/auth.css b/core/css/auth.css index bce7fa7b711..0adc10c77d9 100644 --- a/core/css/auth.css +++ b/core/css/auth.css @@ -36,4 +36,4 @@ h2 img { font-size:1.2em; margin:.7em; padding:0; -}
\ No newline at end of file +} diff --git a/core/css/styles.css b/core/css/styles.css index 2f08b58c04f..52a265d2031 100644 --- a/core/css/styles.css +++ b/core/css/styles.css @@ -196,11 +196,12 @@ input[type="submit"].enabled { background:#66f866; border:1px solid #5e5; -moz-b #body-login #datadirContent label, #body-login form input[type="checkbox"]+label { text-align: center; - color: #000; + color: #ccc; text-shadow: 0 1px 0 rgba(255,255,255,.1); - -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)"; - filter: alpha(opacity=80); - opacity: .8; + -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=60)"; + filter: alpha(opacity=60); + opacity: .6; + text-shadow: 0 -1px 0 rgba(0,0,0,.5); } #body-login div.buttons { text-align:center; } @@ -307,6 +308,31 @@ label.infield { cursor:text !important; top:1.05em; left:.85em; } #body-login form .errors { background:#fed7d7; border:1px solid #f00; list-style-indent:inside; margin:0 0 2em; padding:1em; } #body-login .success { background:#d7fed7; border:1px solid #0f0; width: 35%; margin: 30px auto; padding:1em; text-align: center;} +#body-login #remember_login:hover+label, +#body-login #remember_login:focus+label { + color: #fff !important; +} + +#body-login #showAdvanced > img { + height: 16px; + width: 16px; + padding: 4px; + box-sizing: border-box; +} + +#body-login p.info a, #body-login #showAdvanced { + color: #ccc; +} + +#body-login p.info a:hover, #body-login p.info a:focus { + color: #fff; +} + + +#body-login p.info{ + white-space: nowrap; +} + /* Show password toggle */ #show, #dbpassword { position: absolute; @@ -388,6 +414,7 @@ label.infield { cursor:text !important; top:1.05em; left:.85em; } .error-wide { width: 800px; + margin-left: -250px; } /* Fixes for log in page, TODO should be removed some time */ diff --git a/core/js/jquery.infieldlabel.js b/core/js/jquery.infieldlabel.js index 8a76da1b140..fad15102bcb 100644 --- a/core/js/jquery.infieldlabel.js +++ b/core/js/jquery.infieldlabel.js @@ -174,4 +174,4 @@ }); }; -}(jQuery));
\ No newline at end of file +}(jQuery)); diff --git a/core/js/jquery.inview.js b/core/js/jquery.inview.js index 9687cd83368..511ae95415e 100644 --- a/core/js/jquery.inview.js +++ b/core/js/jquery.inview.js @@ -131,4 +131,4 @@ // By the way, iOS (iPad, iPhone, ...) seems to not execute, or at least delays // intervals while the user scrolls. Therefore the inview event might fire a bit late there setInterval(checkInView, 250); -})(jQuery);
\ No newline at end of file +})(jQuery); diff --git a/core/js/js.js b/core/js/js.js index c2b81ae3272..d580b6113e6 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -69,7 +69,7 @@ function initL10N(app) { var code = 'var plural; var nplurals; '+pf+' return { "nplural" : nplurals, "plural" : (plural === true ? 1 : plural ? plural : 0) };'; t.plural_function = new Function("n", code); } else { - console.log("Syntax error in language file. Plural-Forms header is invalid ["+plural_forms+"]"); + console.log("Syntax error in language file. Plural-Forms header is invalid ["+t.plural_forms+"]"); } } } diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index f4bc174b5eb..5cbc8359d52 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -117,10 +117,6 @@ var OCdialogs = { text: t('core', 'Choose'), click: functionToCall, defaultButton: true - }, - { - text: t('core', 'Cancel'), - click: function(){self.$filePicker.ocdialog('close'); } }]; self.$filePicker.ocdialog({ diff --git a/core/js/oc-requesttoken.js b/core/js/oc-requesttoken.js index f4cf286b8aa..6cc6b5a855b 100644 --- a/core/js/oc-requesttoken.js +++ b/core/js/oc-requesttoken.js @@ -1,3 +1,3 @@ $(document).bind('ajaxSend', function(elm, xhr, s) { xhr.setRequestHeader('requesttoken', oc_requesttoken); -});
\ No newline at end of file +}); diff --git a/core/js/visitortimezone.js b/core/js/visitortimezone.js index 58a1e9ea355..ee0105c783d 100644 --- a/core/js/visitortimezone.js +++ b/core/js/visitortimezone.js @@ -1,4 +1,4 @@ $(document).ready(function () { var visitortimezone = (-new Date().getTimezoneOffset() / 60); $('#timezone-offset').val(visitortimezone); -});
\ No newline at end of file +}); diff --git a/core/lostpassword/templates/email.php b/core/lostpassword/templates/email.php index b65049feffe..3dbae4bfc69 100644 --- a/core/lostpassword/templates/email.php +++ b/core/lostpassword/templates/email.php @@ -1,2 +1,2 @@ <?php -echo str_replace('{link}', $_['link'], $l->t('Use the following link to reset your password: {link}'));
\ No newline at end of file +echo str_replace('{link}', $_['link'], $l->t('Use the following link to reset your password: {link}')); diff --git a/core/routes.php b/core/routes.php index be19b66bf72..dd8222d4378 100644 --- a/core/routes.php +++ b/core/routes.php @@ -73,4 +73,4 @@ $this->create('app_script', '/apps/{app}/{file}') // used for heartbeat $this->create('heartbeat', '/heartbeat')->action(function(){ // do nothing -});
\ No newline at end of file +}); diff --git a/core/templates/filetemplates/template.html b/core/templates/filetemplates/template.html new file mode 100644 index 00000000000..f16e80cb7ef --- /dev/null +++ b/core/templates/filetemplates/template.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<html> + <head> + + </head> + <body> + + </body> +</html> diff --git a/core/templates/installation.php b/core/templates/installation.php index 77c455304d3..8b087706801 100644 --- a/core/templates/installation.php +++ b/core/templates/installation.php @@ -62,7 +62,7 @@ </fieldset> <fieldset id="datadirField"> - <legend><a id="showAdvanced"><?php p($l->t( 'Advanced' )); ?> <img class="svg" src="<?php print_unescaped(image_path('', 'actions/caret-dark.svg')); ?>" /></a></legend> + <legend><a id="showAdvanced"><?php p($l->t( 'Advanced' )); ?> <img class="svg" src="<?php print_unescaped(image_path('', 'actions/caret.svg')); ?>" /></a></legend> <div id="datadirContent"> <label for="directory"><?php p($l->t( 'Data folder' )); ?></label> <input type="text" name="directory" id="directory" @@ -121,4 +121,4 @@ try { } catch (Exception $ex) { \OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL); -}
\ No newline at end of file +} diff --git a/lib/autoloader.php b/lib/autoloader.php index 21170639092..01841f831be 100644 --- a/lib/autoloader.php +++ b/lib/autoloader.php @@ -111,15 +111,39 @@ class Autoloader { * @param string $class * @return bool */ + protected $memoryCache = null; + protected $constructingMemoryCache = true; // hack to prevent recursion public function load($class) { - $paths = $this->findClass($class); + // Does this PHP have an in-memory cache? We cache the paths there + if ($this->constructingMemoryCache && !$this->memoryCache) { + $this->constructingMemoryCache = false; + $this->memoryCache = \OC\Memcache\Factory::createLowLatency('Autoloader'); + } + if ($this->memoryCache) { + $pathsToRequire = $this->memoryCache->get($class); + if (is_array($pathsToRequire)) { + foreach ($pathsToRequire as $path) { + require_once $path; + } + return false; + } + } + // Use the normal class loading path + $paths = $this->findClass($class); if (is_array($paths)) { + $pathsToRequire = array(); foreach ($paths as $path) { if ($fullPath = stream_resolve_include_path($path)) { require_once $fullPath; + $pathsToRequire[] = $fullPath; } } + + // Save in our memory cache + if ($this->memoryCache) { + $this->memoryCache->set($class, $pathsToRequire, 60); // cache 60 sec + } } return false; } diff --git a/lib/connector/sabre/principal.php b/lib/connector/sabre/principal.php index 16c88b96ea6..59a96797c16 100644 --- a/lib/connector/sabre/principal.php +++ b/lib/connector/sabre/principal.php @@ -66,13 +66,13 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend { */ public function getGroupMemberSet($principal) { // TODO: for now the group principal has only one member, the user itself - list($prefix, $name) = Sabre_DAV_URLUtil::splitPath($principal); - - $principal = $this->getPrincipalByPath($prefix); - if (!$principal) throw new Sabre_DAV_Exception('Principal not found'); + $principal = $this->getPrincipalByPath($principal); + if (!$principal) { + throw new Sabre_DAV_Exception('Principal not found'); + } return array( - $prefix + $principal['uri'] ); } @@ -88,7 +88,9 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend { $group_membership = array(); if ($prefix == 'principals') { $principal = $this->getPrincipalByPath($principal); - if (!$principal) throw new Sabre_DAV_Exception('Principal not found'); + if (!$principal) { + throw new Sabre_DAV_Exception('Principal not found'); + } // TODO: for now the user principal has only its own groups return array( diff --git a/lib/files/storage/commontest.php b/lib/files/storage/commontest.php index fbdb7fbf110..c3f1eb31955 100644 --- a/lib/files/storage/commontest.php +++ b/lib/files/storage/commontest.php @@ -77,4 +77,4 @@ class CommonTest extends \OC\Files\Storage\Common{ public function touch($path, $mtime=null) { return $this->storage->touch($path, $mtime); } -}
\ No newline at end of file +} diff --git a/lib/files/type/detection.php b/lib/files/type/detection.php new file mode 100644 index 00000000000..242a81cb5a4 --- /dev/null +++ b/lib/files/type/detection.php @@ -0,0 +1,121 @@ +<?php +/** + * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Files\Type; + +/** + * Class Detection + * + * Mimetype detection + * + * @package OC\Files\Type + */ +class Detection { + protected $mimetypes = array(); + + /** + * add an extension -> mimetype mapping + * + * @param string $extension + * @param string $mimetype + */ + public function registerType($extension, $mimetype) { + $this->mimetypes[$extension] = $mimetype; + } + + /** + * add an array of extension -> mimetype mappings + * + * @param array $types + */ + public function registerTypeArray($types) { + $this->mimetypes = array_merge($this->mimetypes, $types); + } + + /** + * detect mimetype only based on filename, content of file is not used + * + * @param string $path + * @return string + */ + public function detectPath($path) { + if (strpos($path, '.')) { + //try to guess the type by the file extension + $extension = strtolower(strrchr(basename($path), ".")); + $extension = substr($extension, 1); //remove leading . + return (isset($this->mimetypes[$extension])) ? $this->mimetypes[$extension] : 'application/octet-stream'; + } else { + return 'application/octet-stream'; + } + } + + /** + * detect mimetype based on both filename and content + * + * @param string $path + * @return string + */ + public function detect($path) { + $isWrapped = (strpos($path, '://') !== false) and (substr($path, 0, 7) === 'file://'); + + if (@is_dir($path)) { + // directories are easy + return "httpd/unix-directory"; + } + + $mimeType = $this->detectPath($path); + + if ($mimeType === 'application/octet-stream' and function_exists('finfo_open') + and function_exists('finfo_file') and $finfo = finfo_open(FILEINFO_MIME) + ) { + $info = @strtolower(finfo_file($finfo, $path)); + if ($info) { + $mimeType = substr($info, 0, strpos($info, ';')); + } + finfo_close($finfo); + } + if (!$isWrapped and $mimeType === 'application/octet-stream' && function_exists("mime_content_type")) { + // use mime magic extension if available + $mimeType = mime_content_type($path); + } + if (!$isWrapped and $mimeType === 'application/octet-stream' && \OC_Helper::canExecute("file")) { + // it looks like we have a 'file' command, + // lets see if it does have mime support + $path = escapeshellarg($path); + $fp = popen("file -b --mime-type $path 2>/dev/null", "r"); + $reply = fgets($fp); + pclose($fp); + + //trim the newline + $mimeType = trim($reply); + + } + return $mimeType; + } + + /** + * detect mimetype based on the content of a string + * + * @param string $data + * @return string + */ + public function detectString($data) { + if (function_exists('finfo_open') and function_exists('finfo_file')) { + $finfo = finfo_open(FILEINFO_MIME); + return finfo_buffer($finfo, $data); + } else { + $tmpFile = \OC_Helper::tmpFile(); + $fh = fopen($tmpFile, 'wb'); + fwrite($fh, $data, 8024); + fclose($fh); + $mime = $this->detect($tmpFile); + unset($tmpFile); + return $mime; + } + } +} diff --git a/lib/files/type/templatemanager.php b/lib/files/type/templatemanager.php new file mode 100644 index 00000000000..cd1536d2732 --- /dev/null +++ b/lib/files/type/templatemanager.php @@ -0,0 +1,46 @@ +<?php +/** + * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Files\Type; + +class TemplateManager { + protected $templates = array(); + + public function registerTemplate($mimetype, $path) { + $this->templates[$mimetype] = $path; + } + + /** + * get the path of the template for a mimetype + * + * @param string $mimetype + * @return string | null + */ + public function getTemplatePath($mimetype) { + if (isset($this->templates[$mimetype])) { + return $this->templates[$mimetype]; + } else { + return null; + } + } + + /** + * get the template content for a mimetype + * + * @param string $mimetype + * @return string + */ + public function getTemplate($mimetype) { + $path = $this->getTemplatePath($mimetype); + if ($path) { + return file_get_contents($path); + } else { + return ''; + } + } +} diff --git a/lib/geo.php b/lib/geo.php index 4eb785da355..ed01ad0b616 100644 --- a/lib/geo.php +++ b/lib/geo.php @@ -28,4 +28,4 @@ class OC_Geo{ reset($variances); return current($variances); } -}
\ No newline at end of file +} diff --git a/lib/helper.php b/lib/helper.php index 31f0f1698d5..51165193623 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -25,9 +25,10 @@ * Collection of useful functions */ class OC_Helper { - private static $mimetypes=array(); - private static $tmpFiles=array(); + private static $tmpFiles = array(); private static $mimetypeIcons = array(); + private static $mimetypeDetector; + private static $templateManager; /** * @brief Creates an url using a defined route @@ -39,7 +40,7 @@ class OC_Helper { * * Returns a url to the given app and file. */ - public static function linkToRoute( $route, $parameters = array() ) { + public static function linkToRoute($route, $parameters = array()) { $urlLinkTo = OC::getRouter()->generate($route, $parameters); return $urlLinkTo; } @@ -49,38 +50,35 @@ class OC_Helper { * @param string $app app * @param string $file file * @param array $args array with param=>value, will be appended to the returned url - * The value of $args will be urlencoded + * The value of $args will be urlencoded * @return string the url * * Returns a url to the given app and file. */ - public static function linkTo( $app, $file, $args = array() ) { - if( $app != '' ) { + public static function linkTo($app, $file, $args = array()) { + if ($app != '') { $app_path = OC_App::getAppPath($app); // Check if the app is in the app folder - if( $app_path && file_exists( $app_path.'/'.$file )) { - if(substr($file, -3) == 'php' || substr($file, -3) == 'css') { - $urlLinkTo = OC::$WEBROOT . '/index.php/apps/' . $app; - $urlLinkTo .= ($file!='index.php') ? '/' . $file : ''; - }else{ - $urlLinkTo = OC_App::getAppWebPath($app) . '/' . $file; + if ($app_path && file_exists($app_path . '/' . $file)) { + if (substr($file, -3) == 'php' || substr($file, -3) == 'css') { + $urlLinkTo = OC::$WEBROOT . '/index.php/apps/' . $app; + $urlLinkTo .= ($file != 'index.php') ? '/' . $file : ''; + } else { + $urlLinkTo = OC_App::getAppWebPath($app) . '/' . $file; } + } else { + $urlLinkTo = OC::$WEBROOT . '/' . $app . '/' . $file; } - else{ - $urlLinkTo = OC::$WEBROOT . '/' . $app . '/' . $file; - } - } - else{ - if( file_exists( OC::$SERVERROOT . '/core/'. $file )) { - $urlLinkTo = OC::$WEBROOT . '/core/'.$file; - } - else{ - $urlLinkTo = OC::$WEBROOT . '/'.$file; + } else { + if (file_exists(OC::$SERVERROOT . '/core/' . $file)) { + $urlLinkTo = OC::$WEBROOT . '/core/' . $file; + } else { + $urlLinkTo = OC::$WEBROOT . '/' . $file; } } if ($args && $query = http_build_query($args, '', '&')) { - $urlLinkTo .= '?'.$query; + $urlLinkTo .= '?' . $query; } return $urlLinkTo; @@ -91,13 +89,13 @@ class OC_Helper { * @param string $app app * @param string $file file * @param array $args array with param=>value, will be appended to the returned url - * The value of $args will be urlencoded + * The value of $args will be urlencoded * @return string the url * * Returns a absolute url to the given app and file. */ - public static function linkToAbsolute( $app, $file, $args = array() ) { - $urlLinkTo = self::linkTo( $app, $file, $args ); + public static function linkToAbsolute($app, $file, $args = array()) { + $urlLinkTo = self::linkTo($app, $file, $args); return self::makeURLAbsolute($urlLinkTo); } @@ -108,9 +106,8 @@ class OC_Helper { * * Returns a absolute url to the given app and file. */ - public static function makeURLAbsolute( $url ) - { - return OC_Request::serverProtocol(). '://' . OC_Request::serverHost() . $url; + public static function makeURLAbsolute($url) { + return OC_Request::serverProtocol() . '://' . OC_Request::serverHost() . $url; } /** @@ -120,8 +117,8 @@ class OC_Helper { * * Returns a url to the given service. */ - public static function linkToRemoteBase( $service ) { - return self::linkTo( '', 'remote.php') . '/' . $service; + public static function linkToRemoteBase($service) { + return self::linkTo('', 'remote.php') . '/' . $service; } /** @@ -132,9 +129,9 @@ class OC_Helper { * * Returns a absolute url to the given service. */ - public static function linkToRemote( $service, $add_slash = true ) { + public static function linkToRemote($service, $add_slash = true) { return self::makeURLAbsolute(self::linkToRemoteBase($service)) - . (($add_slash && $service[strlen($service)-1]!='/')?'/':''); + . (($add_slash && $service[strlen($service) - 1] != '/') ? '/' : ''); } /** @@ -146,8 +143,8 @@ class OC_Helper { * Returns a absolute url to the given service. */ public static function linkToPublic($service, $add_slash = false) { - return self::linkToAbsolute( '', 'public.php') . '?service=' . $service - . (($add_slash && $service[strlen($service)-1]!='/')?'/':''); + return self::linkToAbsolute('', 'public.php') . '?service=' . $service + . (($add_slash && $service[strlen($service) - 1] != '/') ? '/' : ''); } /** @@ -158,25 +155,25 @@ class OC_Helper { * * Returns the path to the image. */ - public static function imagePath( $app, $image ) { + public static function imagePath($app, $image) { // Read the selected theme from the config file $theme = OC_Util::getTheme(); // Check if the app is in the app folder - if( file_exists( OC::$SERVERROOT."/themes/$theme/apps/$app/img/$image" )) { - return OC::$WEBROOT."/themes/$theme/apps/$app/img/$image"; - }elseif( file_exists(OC_App::getAppPath($app)."/img/$image" )) { - return OC_App::getAppWebPath($app)."/img/$image"; - }elseif( !empty( $app ) and file_exists( OC::$SERVERROOT."/themes/$theme/$app/img/$image" )) { - return OC::$WEBROOT."/themes/$theme/$app/img/$image"; - }elseif( !empty( $app ) and file_exists( OC::$SERVERROOT."/$app/img/$image" )) { - return OC::$WEBROOT."/$app/img/$image"; - }elseif( file_exists( OC::$SERVERROOT."/themes/$theme/core/img/$image" )) { - return OC::$WEBROOT."/themes/$theme/core/img/$image"; - }elseif( file_exists( OC::$SERVERROOT."/core/img/$image" )) { - return OC::$WEBROOT."/core/img/$image"; - }else{ - throw new RuntimeException('image not found: image:'.$image.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); + if (file_exists(OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) { + return OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image"; + } elseif (file_exists(OC_App::getAppPath($app) . "/img/$image")) { + return OC_App::getAppWebPath($app) . "/img/$image"; + } elseif (!empty($app) and file_exists(OC::$SERVERROOT . "/themes/$theme/$app/img/$image")) { + return OC::$WEBROOT . "/themes/$theme/$app/img/$image"; + } elseif (!empty($app) and file_exists(OC::$SERVERROOT . "/$app/img/$image")) { + return OC::$WEBROOT . "/$app/img/$image"; + } elseif (file_exists(OC::$SERVERROOT . "/themes/$theme/core/img/$image")) { + return OC::$WEBROOT . "/themes/$theme/core/img/$image"; + } elseif (file_exists(OC::$SERVERROOT . "/core/img/$image")) { + return OC::$WEBROOT . "/core/img/$image"; + } else { + throw new RuntimeException('image not found: image:' . $image . ' webroot:' . OC::$WEBROOT . ' serverroot:' . OC::$SERVERROOT); } } @@ -197,28 +194,28 @@ class OC_Helper { } // Replace slash and backslash with a minus $icon = str_replace('/', '-', $mimetype); - $icon = str_replace( '\\', '-', $icon); + $icon = str_replace('\\', '-', $icon); // Is it a dir? if ($mimetype === 'dir') { - self::$mimetypeIcons[$mimetype] = OC::$WEBROOT.'/core/img/filetypes/folder.png'; - return OC::$WEBROOT.'/core/img/filetypes/folder.png'; + self::$mimetypeIcons[$mimetype] = OC::$WEBROOT . '/core/img/filetypes/folder.png'; + return OC::$WEBROOT . '/core/img/filetypes/folder.png'; } // Icon exists? - if (file_exists(OC::$SERVERROOT.'/core/img/filetypes/'.$icon.'.png')) { - self::$mimetypeIcons[$mimetype] = OC::$WEBROOT.'/core/img/filetypes/'.$icon.'.png'; - return OC::$WEBROOT.'/core/img/filetypes/'.$icon.'.png'; + if (file_exists(OC::$SERVERROOT . '/core/img/filetypes/' . $icon . '.png')) { + self::$mimetypeIcons[$mimetype] = OC::$WEBROOT . '/core/img/filetypes/' . $icon . '.png'; + return OC::$WEBROOT . '/core/img/filetypes/' . $icon . '.png'; } // Try only the first part of the filetype $mimePart = substr($icon, 0, strpos($icon, '-')); - if (file_exists(OC::$SERVERROOT.'/core/img/filetypes/'.$mimePart.'.png')) { - self::$mimetypeIcons[$mimetype] = OC::$WEBROOT.'/core/img/filetypes/'.$mimePart.'.png'; - return OC::$WEBROOT.'/core/img/filetypes/'.$mimePart.'.png'; + if (file_exists(OC::$SERVERROOT . '/core/img/filetypes/' . $mimePart . '.png')) { + self::$mimetypeIcons[$mimetype] = OC::$WEBROOT . '/core/img/filetypes/' . $mimePart . '.png'; + return OC::$WEBROOT . '/core/img/filetypes/' . $mimePart . '.png'; } else { - self::$mimetypeIcons[$mimetype] = OC::$WEBROOT.'/core/img/filetypes/file.png'; - return OC::$WEBROOT.'/core/img/filetypes/file.png'; + self::$mimetypeIcons[$mimetype] = OC::$WEBROOT . '/core/img/filetypes/file.png'; + return OC::$WEBROOT . '/core/img/filetypes/file.png'; } } @@ -229,25 +226,25 @@ class OC_Helper { * * Makes 2048 to 2 kB. */ - public static function humanFileSize( $bytes ) { - if( $bytes < 0 ) { + public static function humanFileSize($bytes) { + if ($bytes < 0) { $l = OC_L10N::get('lib'); return "?"; } - if( $bytes < 1024 ) { + if ($bytes < 1024) { return "$bytes B"; } - $bytes = round( $bytes / 1024, 1 ); - if( $bytes < 1024 ) { + $bytes = round($bytes / 1024, 1); + if ($bytes < 1024) { return "$bytes kB"; } - $bytes = round( $bytes / 1024, 1 ); - if( $bytes < 1024 ) { + $bytes = round($bytes / 1024, 1); + if ($bytes < 1024) { return "$bytes MB"; } // Wow, heavy duty for owncloud - $bytes = round( $bytes / 1024, 1 ); + $bytes = round($bytes / 1024, 1); return "$bytes GB"; } @@ -260,21 +257,21 @@ class OC_Helper { * * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418 */ - public static function computerFileSize( $str ) { - $str=strtolower($str); + public static function computerFileSize($str) { + $str = strtolower($str); $bytes_array = array( 'b' => 1, 'k' => 1024, 'kb' => 1024, 'mb' => 1024 * 1024, - 'm' => 1024 * 1024, + 'm' => 1024 * 1024, 'gb' => 1024 * 1024 * 1024, - 'g' => 1024 * 1024 * 1024, + 'g' => 1024 * 1024 * 1024, 'tb' => 1024 * 1024 * 1024 * 1024, - 't' => 1024 * 1024 * 1024 * 1024, + 't' => 1024 * 1024 * 1024 * 1024, 'pb' => 1024 * 1024 * 1024 * 1024 * 1024, - 'p' => 1024 * 1024 * 1024 * 1024 * 1024, + 'p' => 1024 * 1024 * 1024 * 1024 * 1024, ); $bytes = floatval($str); @@ -299,18 +296,17 @@ class OC_Helper { return chmod($path, $filemode); $dh = opendir($path); while (($file = readdir($dh)) !== false) { - if($file != '.' && $file != '..') { - $fullpath = $path.'/'.$file; - if(is_link($fullpath)) + if ($file != '.' && $file != '..') { + $fullpath = $path . '/' . $file; + if (is_link($fullpath)) return false; - elseif(!is_dir($fullpath) && !@chmod($fullpath, $filemode)) - return false; - elseif(!self::chmodr($fullpath, $filemode)) + elseif (!is_dir($fullpath) && !@chmod($fullpath, $filemode)) + return false; elseif (!self::chmodr($fullpath, $filemode)) return false; } } closedir($dh); - if(@chmod($path, $filemode)) + if (@chmod($path, $filemode)) return true; else return false; @@ -323,8 +319,8 @@ class OC_Helper { * */ static function copyr($src, $dest) { - if(is_dir($src)) { - if(!is_dir($dest)) { + if (is_dir($src)) { + if (!is_dir($dest)) { mkdir($dest); } $files = scandir($src); @@ -333,7 +329,7 @@ class OC_Helper { self::copyr("$src/$file", "$dest/$file"); } } - }elseif(file_exists($src) && !\OC\Files\Filesystem::isFileBlacklisted($src)) { + } elseif (file_exists($src) && !\OC\Files\Filesystem::isFileBlacklisted($src)) { copy($src, $dest); } } @@ -344,105 +340,74 @@ class OC_Helper { * @return bool */ static function rmdirr($dir) { - if(is_dir($dir)) { - $files=scandir($dir); - foreach($files as $file) { + if (is_dir($dir)) { + $files = scandir($dir); + foreach ($files as $file) { if ($file != "." && $file != "..") { self::rmdirr("$dir/$file"); } } rmdir($dir); - }elseif(file_exists($dir)) { + } elseif (file_exists($dir)) { unlink($dir); } - if(file_exists($dir)) { + if (file_exists($dir)) { return false; - }else{ + } else { return true; } } /** + * @return \OC\Files\Type\Detection + */ + static public function getMimetypeDetector() { + if (!self::$mimetypeDetector) { + self::$mimetypeDetector = new \OC\Files\Type\Detection(); + self::$mimetypeDetector->registerTypeArray(include 'mimetypes.list.php'); + } + return self::$mimetypeDetector; + } + + /** + * @return \OC\Files\Type\TemplateManager + */ + static public function getFileTemplateManager() { + if (!self::$templateManager) { + self::$templateManager = new \OC\Files\Type\TemplateManager(); + } + return self::$templateManager; + } + + /** * Try to guess the mimetype based on filename * * @param string $path * @return string */ - static public function getFileNameMimeType($path){ - if(strpos($path, '.')) { - //try to guess the type by the file extension - if(!self::$mimetypes || self::$mimetypes != include 'mimetypes.list.php') { - self::$mimetypes=include 'mimetypes.list.php'; - } - $extension=strtolower(strrchr(basename($path), ".")); - $extension=substr($extension, 1);//remove leading . - return (isset(self::$mimetypes[$extension]))?self::$mimetypes[$extension]:'application/octet-stream'; - }else{ - return 'application/octet-stream'; - } + static public function getFileNameMimeType($path) { + return self::getMimetypeDetector()->detectPath($path); } /** * get the mimetype form a local file + * * @param string $path * @return string * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead */ static function getMimeType($path) { - $isWrapped=(strpos($path, '://')!==false) and (substr($path, 0, 7)=='file://'); - - if (@is_dir($path)) { - // directories are easy - return "httpd/unix-directory"; - } - - $mimeType = self::getFileNameMimeType($path); - - if($mimeType=='application/octet-stream' and function_exists('finfo_open') - and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)) { - $info = @strtolower(finfo_file($finfo, $path)); - if($info) { - $mimeType=substr($info, 0, strpos($info, ';')); - } - finfo_close($finfo); - } - if (!$isWrapped and $mimeType=='application/octet-stream' && function_exists("mime_content_type")) { - // use mime magic extension if available - $mimeType = mime_content_type($path); - } - if (!$isWrapped and $mimeType=='application/octet-stream' && OC_Helper::canExecute("file")) { - // it looks like we have a 'file' command, - // lets see if it does have mime support - $path=escapeshellarg($path); - $fp = popen("file -b --mime-type $path 2>/dev/null", "r"); - $reply = fgets($fp); - pclose($fp); - - //trim the newline - $mimeType = trim($reply); - - } - return $mimeType; + return self::getMimetypeDetector()->detect($path); } /** * get the mimetype form a data string + * * @param string $data * @return string */ static function getStringMimeType($data) { - if(function_exists('finfo_open') and function_exists('finfo_file')) { - $finfo=finfo_open(FILEINFO_MIME); - return finfo_buffer($finfo, $data); - }else{ - $tmpFile=OC_Helper::tmpFile(); - $fh=fopen($tmpFile, 'wb'); - fwrite($fh, $data, 8024); - fclose($fh); - $mime=self::getMimeType($tmpFile); - unset($tmpFile); - return $mime; - } + return self::getMimetypeDetector()->detectString($data); } /** @@ -454,9 +419,9 @@ class OC_Helper { */ //FIXME: should also check for value validation (i.e. the email is an email). - public static function init_var($s, $d="") { + public static function init_var($s, $d = "") { $r = $d; - if(isset($_REQUEST[$s]) && !empty($_REQUEST[$s])) { + if (isset($_REQUEST[$s]) && !empty($_REQUEST[$s])) { $r = OC_Util::sanitizeHTML($_REQUEST[$s]); } @@ -466,12 +431,13 @@ class OC_Helper { /** * returns "checked"-attribute if request contains selected radio element * OR if radio element is the default one -- maybe? + * * @param string $s Name of radio-button element name * @param string $v Value of current radio-button element * @param string $d Value of default radio-button element */ public static function init_radio($s, $v, $d) { - if((isset($_REQUEST[$s]) && $_REQUEST[$s]==$v) || (!isset($_REQUEST[$s]) && $v == $d)) + if ((isset($_REQUEST[$s]) && $_REQUEST[$s] == $v) || (!isset($_REQUEST[$s]) && $v == $d)) print "checked=\"checked\" "; } @@ -503,17 +469,17 @@ class OC_Helper { $dirs = explode(PATH_SEPARATOR, $path); // WARNING : We have to check if open_basedir is enabled : $obd = ini_get('open_basedir'); - if($obd != "none") { + if ($obd != "none") { $obd_values = explode(PATH_SEPARATOR, $obd); - if(count($obd_values) > 0 and $obd_values[0]) { + if (count($obd_values) > 0 and $obd_values[0]) { // open_basedir is in effect ! // We need to check if the program is in one of these dirs : $dirs = $obd_values; } } - foreach($dirs as $dir) { - foreach($exts as $ext) { - if($check_fn("$dir/$name".$ext)) + foreach ($dirs as $dir) { + foreach ($exts as $ext) { + if ($check_fn("$dir/$name" . $ext)) return true; } } @@ -522,18 +488,19 @@ class OC_Helper { /** * copy the contents of one stream to another + * * @param resource $source * @param resource $target * @return int the number of bytes copied */ public static function streamCopy($source, $target) { - if(!$source or !$target) { + if (!$source or !$target) { return false; } $result = true; $count = 0; - while(!feof($source)) { - if ( ( $c = fwrite($target, fread($source, 8192)) ) === false) { + while (!feof($source)) { + if (($c = fwrite($target, fread($source, 8192))) === false) { $result = false; } else { $count += $c; @@ -544,37 +511,39 @@ class OC_Helper { /** * create a temporary file with an unique filename + * * @param string $postfix * @return string * * temporary files are automatically cleaned up after the script is finished */ - public static function tmpFile($postfix='') { - $file=get_temp_dir().'/'.md5(time().rand()).$postfix; - $fh=fopen($file, 'w'); + public static function tmpFile($postfix = '') { + $file = get_temp_dir() . '/' . md5(time() . rand()) . $postfix; + $fh = fopen($file, 'w'); fclose($fh); - self::$tmpFiles[]=$file; + self::$tmpFiles[] = $file; return $file; } /** * move a file to oc-noclean temp dir + * * @param string $filename * @return mixed * */ - public static function moveToNoClean($filename='') { + public static function moveToNoClean($filename = '') { if ($filename == '') { return false; } - $tmpDirNoClean=get_temp_dir().'/oc-noclean/'; + $tmpDirNoClean = get_temp_dir() . '/oc-noclean/'; if (!file_exists($tmpDirNoClean) || !is_dir($tmpDirNoClean)) { if (file_exists($tmpDirNoClean)) { unlink($tmpDirNoClean); } mkdir($tmpDirNoClean); } - $newname=$tmpDirNoClean.basename($filename); + $newname = $tmpDirNoClean . basename($filename); if (rename($filename, $newname)) { return $newname; } else { @@ -584,34 +553,35 @@ class OC_Helper { /** * create a temporary folder with an unique filename + * * @return string * * temporary files are automatically cleaned up after the script is finished */ public static function tmpFolder() { - $path=get_temp_dir().'/'.md5(time().rand()); + $path = get_temp_dir() . '/' . md5(time() . rand()); mkdir($path); - self::$tmpFiles[]=$path; - return $path.'/'; + self::$tmpFiles[] = $path; + return $path . '/'; } /** * remove all files created by self::tmpFile */ public static function cleanTmp() { - $leftoversFile=get_temp_dir().'/oc-not-deleted'; - if(file_exists($leftoversFile)) { - $leftovers=file($leftoversFile); - foreach($leftovers as $file) { + $leftoversFile = get_temp_dir() . '/oc-not-deleted'; + if (file_exists($leftoversFile)) { + $leftovers = file($leftoversFile); + foreach ($leftovers as $file) { self::rmdirr($file); } unlink($leftoversFile); } - foreach(self::$tmpFiles as $file) { - if(file_exists($file)) { - if(!self::rmdirr($file)) { - file_put_contents($leftoversFile, $file."\n", FILE_APPEND); + foreach (self::$tmpFiles as $file) { + if (file_exists($file)) { + if (!self::rmdirr($file)) { + file_put_contents($leftoversFile, $file . "\n", FILE_APPEND); } } } @@ -621,34 +591,34 @@ class OC_Helper { * remove all files in PHP /oc-noclean temp dir */ public static function cleanTmpNoClean() { - $tmpDirNoCleanFile=get_temp_dir().'/oc-noclean/'; - if(file_exists($tmpDirNoCleanFile)) { + $tmpDirNoCleanFile = get_temp_dir() . '/oc-noclean/'; + if (file_exists($tmpDirNoCleanFile)) { self::rmdirr($tmpDirNoCleanFile); } } /** - * Adds a suffix to the name in case the file exists - * - * @param $path - * @param $filename - * @return string - */ + * Adds a suffix to the name in case the file exists + * + * @param $path + * @param $filename + * @return string + */ public static function buildNotExistingFileName($path, $filename) { $view = \OC\Files\Filesystem::getView(); return self::buildNotExistingFileNameForView($path, $filename, $view); } /** - * Adds a suffix to the name in case the file exists - * - * @param $path - * @param $filename - * @return string - */ + * Adds a suffix to the name in case the file exists + * + * @param $path + * @param $filename + * @return string + */ public static function buildNotExistingFileNameForView($path, $filename, \OC\Files\View $view) { - if($path==='/') { - $path=''; + if ($path === '/') { + $path = ''; } if ($pos = strrpos($filename, '.')) { $name = substr($filename, 0, $pos); @@ -660,10 +630,10 @@ class OC_Helper { $newpath = $path . '/' . $filename; if ($view->file_exists($newpath)) { - if(preg_match_all('/\((\d+)\)/', $name, $matches, PREG_OFFSET_CAPTURE)) { + if (preg_match_all('/\((\d+)\)/', $name, $matches, PREG_OFFSET_CAPTURE)) { //Replace the last "(number)" with "(number+1)" - $last_match = count($matches[0])-1; - $counter = $matches[1][$last_match][0]+1; + $last_match = count($matches[0]) - 1; + $counter = $matches[1][$last_match][0] + 1; $offset = $matches[0][$last_match][1]; $match_length = strlen($matches[0][$last_match][0]); } else { @@ -671,9 +641,9 @@ class OC_Helper { $offset = false; } do { - if($offset) { + if ($offset) { //Replace the last "(number)" with "(number+1)" - $newname = substr_replace($name, '('.$counter.')', $offset, $match_length); + $newname = substr_replace($name, '(' . $counter . ')', $offset, $match_length); } else { $newname = $name . ' (' . $counter . ')'; } @@ -700,17 +670,17 @@ class OC_Helper { } /** - * @brief Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. - * - * @param array $input The array to work on - * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default) - * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 - * @return array - * - * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. - * based on http://www.php.net/manual/en/function.array-change-key-case.php#107715 - * - */ + * @brief Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. + * + * @param array $input The array to work on + * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default) + * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 + * @return array + * + * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. + * based on http://www.php.net/manual/en/function.array-change-key-case.php#107715 + * + */ public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') { $case = ($case != MB_CASE_UPPER) ? MB_CASE_LOWER : MB_CASE_UPPER; $ret = array(); @@ -736,26 +706,26 @@ class OC_Helper { $length = intval($length); $string = mb_substr($string, 0, $start, $encoding) . $replacement . - mb_substr($string, $start+$length, mb_strlen($string, 'UTF-8')-$start, $encoding); + mb_substr($string, $start + $length, mb_strlen($string, 'UTF-8') - $start, $encoding); return $string; } /** - * @brief Replace all occurrences of the search string with the replacement string - * - * @param string $search The value being searched for, otherwise known as the needle. - * @param string $replace The replacement - * @param string $subject The string or array being searched and replaced on, otherwise known as the haystack. - * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 - * @param int $count If passed, this will be set to the number of replacements performed. - * @return string - * - */ + * @brief Replace all occurrences of the search string with the replacement string + * + * @param string $search The value being searched for, otherwise known as the needle. + * @param string $replace The replacement + * @param string $subject The string or array being searched and replaced on, otherwise known as the haystack. + * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 + * @param int $count If passed, this will be set to the number of replacements performed. + * @return string + * + */ public static function mb_str_replace($search, $replace, $subject, $encoding = 'UTF-8', &$count = null) { $offset = -1; $length = mb_strlen($search, $encoding); - while(($i = mb_strrpos($subject, $search, $offset, $encoding)) !== false ) { + while (($i = mb_strrpos($subject, $search, $offset, $encoding)) !== false) { $subject = OC_Helper::mb_substr_replace($subject, $replace, $i, $length); $offset = $i - mb_strlen($subject, $encoding); $count++; @@ -764,21 +734,21 @@ class OC_Helper { } /** - * @brief performs a search in a nested array - * @param array $haystack the array to be searched - * @param string $needle the search string - * @param string $index optional, only search this key name - * @return mixed the key of the matching field, otherwise false - * - * performs a search in a nested array - * - * taken from http://www.php.net/manual/en/function.array-search.php#97645 - */ + * @brief performs a search in a nested array + * @param array $haystack the array to be searched + * @param string $needle the search string + * @param string $index optional, only search this key name + * @return mixed the key of the matching field, otherwise false + * + * performs a search in a nested array + * + * taken from http://www.php.net/manual/en/function.array-search.php#97645 + */ public static function recursiveArraySearch($haystack, $needle, $index = null) { $aIt = new RecursiveArrayIterator($haystack); $it = new RecursiveIteratorIterator($aIt); - while($it->valid()) { + while ($it->valid()) { if (((isset($index) AND ($it->key() == $index)) OR (!isset($index))) AND ($it->current() == $needle)) { return $aIt->key(); } @@ -792,6 +762,7 @@ class OC_Helper { /** * Shortens str to maxlen by replacing characters in the middle with '...', eg. * ellipsis('a very long string with lots of useless info to make a better example', 14) becomes 'a very ...example' + * * @param string $str the string * @param string $maxlen the maximum length of the result * @return string with at most maxlen characters @@ -822,7 +793,7 @@ class OC_Helper { $maxUploadFilesize = min($upload_max_filesize, $post_max_size); } - if($freeSpace !== \OC\Files\FREE_SPACE_UNKNOWN){ + if ($freeSpace !== \OC\Files\FREE_SPACE_UNKNOWN) { $freeSpace = max($freeSpace, 0); return min($maxUploadFilesize, $freeSpace); @@ -833,6 +804,7 @@ class OC_Helper { /** * Checks if a function is available + * * @param string $function_name * @return bool */ @@ -861,7 +833,7 @@ class OC_Helper { $used = 0; } $free = \OC\Files\Filesystem::free_space(); - if ($free >= 0){ + if ($free >= 0) { $total = $free + $used; } else { $total = $free; //either unknown or unlimited @@ -869,7 +841,7 @@ class OC_Helper { if ($total == 0) { $total = 1; // prevent division by zero } - if ($total >= 0){ + if ($total >= 0) { $relative = round(($used / $total) * 10000) / 100; } else { $relative = 0; diff --git a/lib/memcache/factory.php b/lib/memcache/factory.php index 4c1b1ab207f..fde7d947567 100644 --- a/lib/memcache/factory.php +++ b/lib/memcache/factory.php @@ -37,4 +37,33 @@ class Factory { public function isAvailable() { return XCache::isAvailable() || APCu::isAvailable() || APC::isAvailable() || Memcached::isAvailable(); } + + /** + * get a in-server cache instance, will return null if no backend is available + * + * @param string $prefix + * @return \OC\Memcache\Cache + */ + public static function createLowLatency($prefix = '') { + if (XCache::isAvailable()) { + return new XCache($prefix); + } elseif (APCu::isAvailable()) { + return new APCu($prefix); + } elseif (APC::isAvailable()) { + return new APC($prefix); + } else { + return null; + } + } + + /** + * check if there is a in-server backend available + * + * @return bool + */ + public static function isAvailableLowLatency() { + return XCache::isAvailable() || APCu::isAvailable() || APC::isAvailable(); + } + + } diff --git a/lib/ocs/result.php b/lib/ocs/result.php index 729c39056d9..84f06fa01c7 100644 --- a/lib/ocs/result.php +++ b/lib/ocs/result.php @@ -94,4 +94,4 @@ class OC_OCS_Result{ } -}
\ No newline at end of file +} diff --git a/lib/public/groupinterface.php b/lib/public/groupinterface.php index 97833028118..5603faa8265 100644 --- a/lib/public/groupinterface.php +++ b/lib/public/groupinterface.php @@ -28,4 +28,4 @@ namespace OCP; -interface GroupInterface extends \OC_Group_Interface {}
\ No newline at end of file +interface GroupInterface extends \OC_Group_Interface {} diff --git a/lib/public/userinterface.php b/lib/public/userinterface.php index b73a8f8d8b0..53d9faf7a5e 100644 --- a/lib/public/userinterface.php +++ b/lib/public/userinterface.php @@ -28,4 +28,4 @@ namespace OCP; -interface UserInterface extends \OC_User_Interface {}
\ No newline at end of file +interface UserInterface extends \OC_User_Interface {} diff --git a/lib/user/http.php b/lib/user/http.php index 944ede73a0b..1e044ed4188 100644 --- a/lib/user/http.php +++ b/lib/user/http.php @@ -103,4 +103,4 @@ class OC_User_HTTP extends OC_User_Backend { return false; } } -}
\ No newline at end of file +} diff --git a/lib/user/interface.php b/lib/user/interface.php index b1e19aea7fb..c72bdfaf3fd 100644 --- a/lib/user/interface.php +++ b/lib/user/interface.php @@ -77,4 +77,4 @@ interface OC_User_Interface { * @return boolean if users can be listed or not */ public function hasUserListings(); -}
\ No newline at end of file +} diff --git a/lib/vobject/compoundproperty.php b/lib/vobject/compoundproperty.php index d702ab802e0..7fe42574bed 100644 --- a/lib/vobject/compoundproperty.php +++ b/lib/vobject/compoundproperty.php @@ -67,4 +67,4 @@ class CompoundProperty extends \Sabre\VObject\Property\Compound { } -}
\ No newline at end of file +} diff --git a/lib/vobject/stringproperty.php b/lib/vobject/stringproperty.php index b98a8f26c2b..a9d63a0a789 100644 --- a/lib/vobject/stringproperty.php +++ b/lib/vobject/stringproperty.php @@ -77,4 +77,4 @@ class StringProperty extends \Sabre\VObject\Property { } -}
\ No newline at end of file +} diff --git a/ocs/routes.php b/ocs/routes.php index 5fcf05e4f99..1ea698c7a83 100644 --- a/ocs/routes.php +++ b/ocs/routes.php @@ -74,4 +74,4 @@ OC_API::register( array('OC_OCS_Cloud', 'getCapabilities'), 'core', OC_API::USER_AUTH - );
\ No newline at end of file + ); diff --git a/public.php b/public.php index 0154b59cce3..1781632bc78 100644 --- a/public.php +++ b/public.php @@ -28,4 +28,4 @@ try { OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL); OC_Template::printExceptionErrorPage($ex); -}
\ No newline at end of file +} diff --git a/remote.php b/remote.php index ec0f2ecef72..2d0088cd903 100644 --- a/remote.php +++ b/remote.php @@ -46,4 +46,4 @@ try { OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL); OC_Template::printExceptionErrorPage($ex); -}
\ No newline at end of file +} diff --git a/search/css/results.css b/search/css/results.css index 30cc352fd7b..4ae7d67afb3 100644 --- a/search/css/results.css +++ b/search/css/results.css @@ -66,4 +66,4 @@ #searchresults tr.current { background-color:#ddd; -}
\ No newline at end of file +} diff --git a/settings/admin.php b/settings/admin.php index 10e239204f2..869729a9e41 100755 --- a/settings/admin.php +++ b/settings/admin.php @@ -18,7 +18,7 @@ $forms=OC_App::getForms('admin'); $htaccessworking=OC_Util::ishtaccessworking(); $entries=OC_Log_Owncloud::getEntries(3); -$entriesremain=(count(OC_Log_Owncloud::getEntries(4)) > 3)?true:false; +$entriesremain = count(OC_Log_Owncloud::getEntries(4)) > 3; $tmpl->assign('loglevel', OC_Config::getValue( "loglevel", 2 )); $tmpl->assign('entries', $entries); diff --git a/settings/ajax/getlog.php b/settings/ajax/getlog.php index e7151419286..34c8d3ce467 100644 --- a/settings/ajax/getlog.php +++ b/settings/ajax/getlog.php @@ -16,6 +16,6 @@ $data = array(); OC_JSON::success( array( "data" => $entries, - "remain"=>(count(OC_Log_Owncloud::getEntries(1, $offset + $count)) !== 0) ? true : false + "remain" => count(OC_Log_Owncloud::getEntries(1, $offset + $count)) !== 0, ) ); diff --git a/settings/ajax/setsecurity.php b/settings/ajax/setsecurity.php index 16a85aade81..675d7eced47 100644 --- a/settings/ajax/setsecurity.php +++ b/settings/ajax/setsecurity.php @@ -10,4 +10,4 @@ OCP\JSON::callCheck(); OC_Config::setValue( 'forcessl', filter_var($_POST['enforceHTTPS'], FILTER_VALIDATE_BOOLEAN)); -echo 'true';
\ No newline at end of file +echo 'true'; diff --git a/settings/ajax/updateapp.php b/settings/ajax/updateapp.php index 300e8642515..91c342d5d07 100644 --- a/settings/ajax/updateapp.php +++ b/settings/ajax/updateapp.php @@ -12,4 +12,4 @@ if($result !== false) { } else { $l = OC_L10N::get('settings'); OC_JSON::error(array("data" => array( "message" => $l->t("Couldn't update app.") ))); -}
\ No newline at end of file +} diff --git a/settings/js/apps-custom.php b/settings/js/apps-custom.php index d827dfc7058..c25148cdde5 100644 --- a/settings/js/apps-custom.php +++ b/settings/js/apps-custom.php @@ -23,4 +23,4 @@ foreach($combinedApps as $app) { echo("\n"); } -echo ("var appid =".json_encode($_GET['appid']).";");
\ No newline at end of file +echo ("var appid =".json_encode($_GET['appid']).";"); diff --git a/settings/js/isadmin.php b/settings/js/isadmin.php index 8b31f8a7cf9..13a8ba1d312 100644 --- a/settings/js/isadmin.php +++ b/settings/js/isadmin.php @@ -17,4 +17,4 @@ if (OC_User::isAdminUser(OC_User::getUser())) { echo("var isadmin = true;"); } else { echo("var isadmin = false;"); -}
\ No newline at end of file +} diff --git a/status.php b/status.php index bac01c11b28..179fe3f49f2 100644 --- a/status.php +++ b/status.php @@ -39,4 +39,4 @@ try { } catch (Exception $ex) { OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL); -}
\ No newline at end of file +} diff --git a/tests/lib/app.php b/tests/lib/app.php index 5396db8143e..52eade90a6e 100644 --- a/tests/lib/app.php +++ b/tests/lib/app.php @@ -79,4 +79,4 @@ class Test_App extends PHPUnit_Framework_TestCase { $this->assertFalse(OC_App::isAppVersionCompatible($oc, $app)); } -}
\ No newline at end of file +} diff --git a/tests/lib/archive/zip.php b/tests/lib/archive/zip.php index e049a899d88..195e3450f3f 100644 --- a/tests/lib/archive/zip.php +++ b/tests/lib/archive/zip.php @@ -19,4 +19,4 @@ class Test_Archive_ZIP extends Test_Archive { return new OC_Archive_ZIP(OCP\Files::tmpFile('.zip')); } } -}
\ No newline at end of file +} diff --git a/tests/lib/geo.php b/tests/lib/geo.php index 2c3611c092e..1c56a976129 100644 --- a/tests/lib/geo.php +++ b/tests/lib/geo.php @@ -20,4 +20,4 @@ class Test_Geo extends PHPUnit_Framework_TestCase { $expected = 'Pacific/Enderbury'; $this->assertEquals($expected, $result); } -}
\ No newline at end of file +} diff --git a/tests/lib/vobject.php b/tests/lib/vobject.php index f28d22a1fcd..db5b0f99f06 100644 --- a/tests/lib/vobject.php +++ b/tests/lib/vobject.php @@ -35,4 +35,4 @@ class Test_VObject extends PHPUnit_Framework_TestCase { $parts = $property->getParts(); $this->assertEquals('Marketing;Sales', $parts[2]); } -}
\ No newline at end of file +} |