From 4e214883d64acf4dc9cc3191780086d0a9dac60f Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Sun, 7 Jul 2013 20:26:09 +0200 Subject: Partly integrate plural translations into js --- core/js/js.js | 55 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 19 deletions(-) (limited to 'core/js') diff --git a/core/js/js.js b/core/js/js.js index 3904787c4e5..15cf1d286fa 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -1,6 +1,6 @@ /** * Disable console output unless DEBUG mode is enabled. - * Add + * Add * define('DEBUG', true); * To the end of config/config.php to enable debug mode. * The undefined checks fix the broken ie8 console @@ -28,9 +28,11 @@ if (oc_debug !== true || typeof console === "undefined" || typeof console.log == * translate a string * @param app the id of the app for which to translate the string * @param text the string to translate + * @param vars (optional) FIXME + * @param count (optional) number to replace %n with * @return string */ -function t(app,text, vars){ +function t(app, text, vars, count){ if( !( t.cache[app] )){ $.ajax(OC.filePath('core','ajax','translations.php'),{ async:false,//todo a proper sollution for this without sync ajax calls @@ -46,7 +48,8 @@ function t(app,text, vars){ t.cache[app] = []; } } - var _build = function (text, vars) { + var _build = function (text, vars, count) { + // FIXME: replace %n with content of count return text.replace(/{([^{}]*)}/g, function (a, b) { var r = vars[b]; @@ -54,30 +57,44 @@ function t(app,text, vars){ } ); }; + var translation = text; if( typeof( t.cache[app][text] ) !== 'undefined' ){ - if(typeof vars === 'object') { - return _build(t.cache[app][text], vars); - } else { - return t.cache[app][text]; - } + translation = t.cache[app][text]; } - else{ - if(typeof vars === 'object') { - return _build(text, vars); - } else { - return text; - } + + if(typeof vars === 'object' || typeof count !== 'undefined' ) { + return _build(translation, vars, count); + } else { + return translation; } } t.cache={}; -/* +/** + * translate a string + * @param app the id of the app for which to translate the string + * @param text_singular the string to translate for exactly one object + * @param text_plural the string to translate for n objects + * @param count number to determine whether to use singular or plural + * @param vars (optional) FIXME + * @return string + */ +function tp(app, text_singular, text_plural, count, vars){ + if(count==1){ + return t(app, text_singular, vars, count); + } + else{ + return t(app, text_plural, vars, count); + } +} + +/** * Sanitizes a HTML string -* @param string +* @param s string * @return Sanitized string */ function escapeHTML(s) { - return s.toString().split('&').join('&').split('<').join('<').split('"').join('"'); + return s.toString().split('&').join('&').split('<').join('<').split('"').join('"'); } /** @@ -741,7 +758,7 @@ OC.get=function(name) { var namespaces = name.split("."); var tail = namespaces.pop(); var context=window; - + for(var i = 0; i < namespaces.length; i++) { context = context[namespaces[i]]; if(!context){ @@ -760,7 +777,7 @@ OC.set=function(name, value) { var namespaces = name.split("."); var tail = namespaces.pop(); var context=window; - + for(var i = 0; i < namespaces.length; i++) { if(!context[namespaces[i]]){ context[namespaces[i]]={}; -- cgit v1.2.3 From d18bd17eb7d13010e3daef5351d7f7ec64480fd7 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Thu, 11 Jul 2013 00:00:01 +0200 Subject: - eventsource.php: in case of potential CSRF attack we send an error message from the EventSource to the browser - eventsource.js: handle undefined data on event - update.js: in case of error we close the event source - advise the user to reload the page - update.php: EventSource initialization is now done before we enter the maintenance mode in order to allow browser reload in case of possible CSRF attack --- core/js/eventsource.js | 6 +++++- core/js/update.js | 5 ++++- lib/eventsource.php | 9 +++++---- 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'core/js') diff --git a/core/js/eventsource.js b/core/js/eventsource.js index ce8c8387c8e..536b180bc8f 100644 --- a/core/js/eventsource.js +++ b/core/js/eventsource.js @@ -110,7 +110,11 @@ OC.EventSource.prototype={ this.listeners[type].push(callback); }else{ this.source.addEventListener(type,function(e){ - callback(JSON.parse(e.data)); + if (typeof e.data != 'undefined') { + callback(JSON.parse(e.data)); + } else { + callback(''); + } },false); } }else{ diff --git a/core/js/update.js b/core/js/update.js index 8ab02bbf935..2c28e72f7cd 100644 --- a/core/js/update.js +++ b/core/js/update.js @@ -5,6 +5,9 @@ $(document).ready(function () { }); updateEventSource.listen('error', function(message) { $('').addClass('error').append(message).append('
').appendTo($('.update')); + message = 'Please reload the page.'; + $('').addClass('error').append(message).append('
').appendTo($('.update')); + updateEventSource.close(); }); updateEventSource.listen('failure', function(message) { $('').addClass('error').append(message).append('
').appendTo($('.update')); @@ -20,4 +23,4 @@ $(document).ready(function () { window.location.href = OC.webroot; }, 3000); }); -}); \ No newline at end of file +}); diff --git a/lib/eventsource.php b/lib/eventsource.php index 63f19792529..31d6edc1874 100644 --- a/lib/eventsource.php +++ b/lib/eventsource.php @@ -25,7 +25,7 @@ * wrapper for server side events (http://en.wikipedia.org/wiki/Server-sent_events) * includes a fallback for older browsers and IE * - * use server side events with causion, to many open requests can hang the server + * use server side events with caution, to many open requests can hang the server */ class OC_EventSource{ private $fallback; @@ -43,6 +43,7 @@ class OC_EventSource{ header("Content-Type: text/event-stream"); } if( !OC_Util::isCallRegistered()) { + $this->send('error', 'Possible CSRF attack. Connection will be closed.'); exit(); } flush(); @@ -51,10 +52,10 @@ class OC_EventSource{ /** * send a message to the client - * @param string type - * @param object data + * @param string $type + * @param object $data * - * if only one paramater is given, a typeless message will be send with that paramater as data + * if only one parameter is given, a typeless message will be send with that parameter as data */ public function send($type, $data=null) { if(is_null($data)) { -- cgit v1.2.3 From fc2d5383119f548f58b5000ebb94422b7feb08a7 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Fri, 12 Jul 2013 17:03:51 +0200 Subject: new admin setting added which allows to turn off anonymous uploads --- apps/files/index.php | 1 + apps/files/templates/index.php | 2 +- core/js/share.js | 7 ++++++- settings/admin.php | 3 ++- settings/templates/admin.php | 10 +++++++++- 5 files changed, 19 insertions(+), 4 deletions(-) (limited to 'core/js') diff --git a/apps/files/index.php b/apps/files/index.php index 2338cf439e4..892f75a3513 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -138,5 +138,6 @@ if ($needUpgrade) { $tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true))); $tmpl->assign('usedSpacePercent', (int)$storageInfo['relative']); $tmpl->assign('isPublic', false); + $tmpl->assign('publicUploadEnabled', \OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes')); $tmpl->printPage(); } diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 7d679bc4bf6..dacd2be0b32 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -61,7 +61,7 @@
t('Nothing in here. Upload something!'))?>
- +
+ + + ').attr({ "class": "filesize", - "title": humanFileSize(size), "style": 'color:rgb('+sizeColor+','+sizeColor+','+sizeColor+')' }).text(simpleSize); tr.append(td); diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 51b3f31fb96..98fc53b71a9 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -756,9 +756,7 @@ function procesSelection(){ for(var i=0;i0){ if(selectedFolders.length==1){ diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 7d679bc4bf6..fa4cda6f6b2 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -77,7 +77,7 @@ - + diff --git a/core/js/js.js b/core/js/js.js index 5158b66d73a..cf4e72324dc 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -666,8 +666,6 @@ $(document).ready(function(){ $('.selectedActions a').tipsy({gravity:'s', fade:true, live:true}); $('a.delete').tipsy({gravity: 'e', fade:true, live:true}); $('a.action').tipsy({gravity:'s', fade:true, live:true}); - $('#headerSize').tipsy({gravity:'s', fade:true, live:true}); - $('td.filesize').tipsy({gravity:'s', fade:true, live:true}); $('td .modified').tipsy({gravity:'s', fade:true, live:true}); $('input').tipsy({gravity:'w', fade:true}); @@ -697,14 +695,6 @@ function humanFileSize(size) { return relativeSize + ' ' + readableFormat; } -function simpleFileSize(bytes) { - var mbytes = Math.round(bytes/(1024*1024/10))/10; - if(bytes == 0) { return '0'; } - else if(mbytes < 0.1) { return '< 0.1'; } - else if(mbytes > 1000) { return '> 1000'; } - else { return mbytes.toFixed(1); } -} - function formatDate(date){ if(typeof date=='number'){ date=new Date(date); diff --git a/lib/public/template.php b/lib/public/template.php index ccf19cf052c..d81a169579e 100644 --- a/lib/public/template.php +++ b/lib/public/template.php @@ -76,16 +76,6 @@ function relative_modified_date($timestamp) { } -/** - * @brief Return a human readable outout for a file size. - * @param $byte size of a file in byte - * @returns human readable interpretation of a file size - */ -function simple_file_size($bytes) { - return(\simple_file_size($bytes)); -} - - /** * @brief Generate html code for an options block. * @param $options the options diff --git a/lib/template.php b/lib/template.php index ae9ea187445..08df168afc6 100644 --- a/lib/template.php +++ b/lib/template.php @@ -84,24 +84,6 @@ function human_file_size( $bytes ) { return OC_Helper::humanFileSize( $bytes ); } -function simple_file_size($bytes) { - if ($bytes < 0) { - return '?'; - } - $mbytes = round($bytes / (1024 * 1024), 1); - if ($bytes == 0) { - return '0'; - } - if ($mbytes < 0.1) { - return '< 0.1'; - } - if ($mbytes > 1000) { - return '> 1000'; - } else { - return number_format($mbytes, 1); - } -} - function relative_modified_date($timestamp) { $l=OC_L10N::get('lib'); $timediff = time() - $timestamp; -- cgit v1.2.3 From 5160ea60639d58a054359834d7ac6e82096c4d57 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Mon, 22 Jul 2013 21:02:18 +0300 Subject: Show generic error when there is no error --- core/js/share.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'core/js') diff --git a/core/js/share.js b/core/js/share.js index 4c8fd874107..71e6136bf71 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -122,7 +122,12 @@ OC.Share={ callback(result.data); } } else { - OC.dialogs.alert(result.data.message, t('core', 'Error while sharing')); + if (result.data && result.data.message) { + var msg = result.data.message; + } else { + var msg = t('core', 'Error'); + } + OC.dialogs.alert(msg, t('core', 'Error while sharing')); } }); }, -- cgit v1.2.3 From ab997bdc68042fa292877e17bb991d79cbed0738 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Mon, 22 Jul 2013 21:02:56 +0300 Subject: Create an array entry before filling it --- core/js/share.js | 1 + 1 file changed, 1 insertion(+) (limited to 'core/js') diff --git a/core/js/share.js b/core/js/share.js index 71e6136bf71..e59669cbc2b 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -92,6 +92,7 @@ OC.Share={ } } if (shares) { + OC.Share.statuses[itemSource] = OC.Share.statuses[itemSource] || {}; OC.Share.statuses[itemSource]['link'] = link; } else { delete OC.Share.statuses[itemSource]; -- cgit v1.2.3 From 284fb862589bb3a6441f464236abe735c6fe5dfc Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 24 Jul 2013 18:02:36 +0200 Subject: show tablespace only for oracle, hide dbhost for sqlite, remove unnecessary js & html ids --- core/js/setup.js | 26 ++++++++++---------------- core/templates/installation.php | 30 +++++++++++++++--------------- 2 files changed, 25 insertions(+), 31 deletions(-) (limited to 'core/js') diff --git a/core/js/setup.js b/core/js/setup.js index 76812b29979..c0df1ed96b0 100644 --- a/core/js/setup.js +++ b/core/js/setup.js @@ -11,42 +11,36 @@ $(document).ready(function() { $('#selectDbType').buttonset(); $('#datadirContent').hide(250); $('#databaseField').hide(250); - if($('#hasSQLite').val()=='true'){ + if($('#hasSQLite').val()){ $('#use_other_db').hide(); - $('#dbhost').hide(); - $('#dbhostlabel').hide(); + $('#use_oracle_db').hide(); } $('#adminlogin').change(function(){ $('#adminlogin').val($.trim($('#adminlogin').val())); }); $('#sqlite').click(function() { $('#use_other_db').slideUp(250); - $('#dbhost').hide(250); - $('#dbhostlabel').hide(250); + $('#use_oracle_db').slideUp(250); }); $('#mysql').click(function() { $('#use_other_db').slideDown(250); - $('#dbhost').show(250); - $('#dbhostlabel').show(250); + $('#use_oracle_db').slideUp(250); }); - + $('#pgsql').click(function() { $('#use_other_db').slideDown(250); - $('#dbhost').show(250); - $('#dbhostlabel').show(250); + $('#use_oracle_db').slideUp(250); }); - + $('#oci').click(function() { $('#use_other_db').slideDown(250); - $('#dbhost').show(250); - $('#dbhostlabel').show(250); + $('#use_oracle_db').show(250); }); - + $('#mssql').click(function() { $('#use_other_db').slideDown(250); - $('#dbhost').show(250); - $('#dbhostlabel').show(250); + $('#use_oracle_db').slideUp(250); }); $('input[checked]').trigger('click'); diff --git a/core/templates/installation.php b/core/templates/installation.php index 6de67a83d42..77c455304d3 100644 --- a/core/templates/installation.php +++ b/core/templates/installation.php @@ -121,7 +121,7 @@ /> - + @@ -131,7 +131,7 @@ /> - + @@ -154,22 +154,22 @@ value="" autocomplete="off" pattern="[0-9a-zA-Z$_-]+" />

- - - -
-

- - + +

+

+ + +

+
+ +

+ +

-

- - -

-- cgit v1.2.3 From 17c36b50746555444c34feb70147a5fbc1d6ac3c Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 30 Jul 2013 10:26:42 +0200 Subject: fixes #4026 --- core/js/share.js | 30 +++++++++++++++++++++--------- lib/public/share.php | 3 +++ 2 files changed, 24 insertions(+), 9 deletions(-) (limited to 'core/js') diff --git a/core/js/share.js b/core/js/share.js index e59669cbc2b..b4b5159b0b5 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -592,8 +592,7 @@ $(document).ready(function() { } // Update the share information - OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', permissions, function(data) { - return; + OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', permissions, function(data) { }); }); @@ -609,13 +608,26 @@ $(document).ready(function() { }); $(document).on('focusout keyup', '#dropdown #linkPassText', function(event) { - if ( $('#linkPassText').val() != '' && (event.type == 'focusout' || event.keyCode == 13) ) { - var itemType = $('#dropdown').data('item-type'); - var itemSource = $('#dropdown').data('item-source'); - OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $('#linkPassText').val(), OC.PERMISSION_READ, function() { - console.log("password set to: '" + $('#linkPassText').val() +"' by event: " + event.type); - $('#linkPassText').val(''); - $('#linkPassText').attr('placeholder', t('core', 'Password protected')); + var linkPassText = $('#linkPassText'); + if ( linkPassText.val() != '' && (event.type == 'focusout' || event.keyCode == 13) ) { + + var allowPublicUpload = $('#sharingDialogAllowPublicUpload').is(':checked'); + var dropDown = $('#dropdown'); + var itemType = dropDown.data('item-type'); + var itemSource = dropDown.data('item-source'); + var permissions = 0; + + // Calculate permissions + if (allowPublicUpload) { + permissions = OC.PERMISSION_UPDATE + OC.PERMISSION_CREATE + OC.PERMISSION_READ; + } else { + permissions = OC.PERMISSION_READ; + } + + OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $('#linkPassText').val(), permissions, function() { + console.log("password set to: '" + linkPassText.val() +"' by event: " + event.type); + linkPassText.val(''); + linkPassText.attr('placeholder', t('core', 'Password protected')); }); } }); diff --git a/lib/public/share.php b/lib/public/share.php index 596a729a47d..b349dd48776 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -454,6 +454,9 @@ class Share { $forcePortable = (CRYPT_BLOWFISH != 1); $hasher = new \PasswordHash(8, $forcePortable); $shareWith = $hasher->HashPassword($shareWith.\OC_Config::getValue('passwordsalt', '')); + } else { + // reuse the already set password + $shareWith = $checkExists['share_with']; } // Generate token -- cgit v1.2.3 From 44594fb41cb8883d77e0c375a734b3f4a2ce54d9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 1 Aug 2013 16:46:01 +0200 Subject: make sure the first breadcrumb item is inserted before any other elements in the topbar --- core/js/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/js') diff --git a/core/js/js.js b/core/js/js.js index cf4e72324dc..a92d41f236f 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -387,7 +387,7 @@ OC.Breadcrumb={ existing.removeClass('last'); existing.last().after(crumb); }else{ - OC.Breadcrumb.container.append(crumb); + OC.Breadcrumb.container.prepend(crumb); } OC.Breadcrumb.crumbs.push(crumb); return crumb; -- cgit v1.2.3 From b12c1cb32521f643bcb3e2c4238fa2b9cf0fda55 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Thu, 1 Aug 2013 14:38:06 +0200 Subject: add OC.Breadcrumb.show(dir, filename, link) --- core/js/js.js | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'core/js') diff --git a/core/js/js.js b/core/js/js.js index a92d41f236f..17a24dd4bc5 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -370,6 +370,68 @@ OC.Notification={ OC.Breadcrumb={ container:null, crumbs:[], + show:function(dir, filename, link){ + OC.Breadcrumb.clear(); + var path = dir.split('/'); + + //add home + var link = OC.linkTo('files','index.php'); + + var crumb=$('
'); + crumb.addClass('crumb'); + + var crumbLink=$(''); + crumbLink.attr('href',link); + + var crumbImg=$(''); + crumbImg.attr('src',OC.imagePath('core','places/home')); + crumbLink.append(crumbImg); + crumb.append(crumbLink); + OC.Breadcrumb.crumbs.push(crumb); + + //add path parts + var pathurl = ''; + jQuery.each(path, function(i,name) { + if (name !== '') { + pathurl = pathurl+'/'+name; + var link = OC.linkTo('files','index.php')+'?dir='+encodeURIComponent(pathurl); + + var crumb=$('
'); + crumb.addClass('crumb'); + + var crumbLink=$(''); + crumbLink.attr('href',link); + crumbLink.text(name); + crumb.append(crumbLink); + OC.Breadcrumb.crumbs.push(crumb); + } + }); + + //add filename (optional) + if (filename && link) { + pathurl = pathurl+'/'+filename; + + var crumb=$('
'); + crumb.addClass('crumb'); + + var crumbLink=$(''); + crumbLink.attr('href',link); + crumbLink.text(filename); + crumb.append(crumbLink); + OC.Breadcrumb.crumbs.push(crumb); + } + + // update crumb array + var lastCrumb = OC.Breadcrumb.crumbs.pop(); + lastCrumb = jQuery(lastCrumb).addClass('last'); + OC.Breadcrumb.crumbs.push(lastCrumb); + var crumbs = OC.Breadcrumb.crumbs; + crumbs.reverse(); + jQuery.each(crumbs, function(i,crumb){ + OC.Breadcrumb.container.prepend(crumb); + }); + + }, push:function(name, link){ if(!OC.Breadcrumb.container){//default OC.Breadcrumb.container=$('#controls'); -- cgit v1.2.3 From f8bb4e10ae5378122328f8e105494fd7af3db260 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 2 Aug 2013 11:44:53 +0200 Subject: use fixed OC.Breadcrumb.push() --- core/js/js.js | 88 ++++++++++++++++++++++------------------------------------- 1 file changed, 32 insertions(+), 56 deletions(-) (limited to 'core/js') diff --git a/core/js/js.js b/core/js/js.js index 17a24dd4bc5..03f660be62c 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -370,67 +370,43 @@ OC.Notification={ OC.Breadcrumb={ container:null, crumbs:[], - show:function(dir, filename, link){ + show:function(dir, leafname, leaflink){ OC.Breadcrumb.clear(); - var path = dir.split('/'); - //add home - var link = OC.linkTo('files','index.php'); - - var crumb=$('
'); - crumb.addClass('crumb'); + // show home + path in subdirectories + if (dir && dir !== '/') { + //add home + var link = OC.linkTo('files','index.php'); - var crumbLink=$(''); - crumbLink.attr('href',link); - - var crumbImg=$(''); - crumbImg.attr('src',OC.imagePath('core','places/home')); - crumbLink.append(crumbImg); - crumb.append(crumbLink); - OC.Breadcrumb.crumbs.push(crumb); - - //add path parts - var pathurl = ''; - jQuery.each(path, function(i,name) { - if (name !== '') { - pathurl = pathurl+'/'+name; - var link = OC.linkTo('files','index.php')+'?dir='+encodeURIComponent(pathurl); - - var crumb=$('
'); - crumb.addClass('crumb'); - - var crumbLink=$(''); - crumbLink.attr('href',link); - crumbLink.text(name); - crumb.append(crumbLink); - OC.Breadcrumb.crumbs.push(crumb); - } - }); - - //add filename (optional) - if (filename && link) { - pathurl = pathurl+'/'+filename; - - var crumb=$('
'); - crumb.addClass('crumb'); - - var crumbLink=$(''); - crumbLink.attr('href',link); - crumbLink.text(filename); - crumb.append(crumbLink); - OC.Breadcrumb.crumbs.push(crumb); - } - - // update crumb array - var lastCrumb = OC.Breadcrumb.crumbs.pop(); - lastCrumb = jQuery(lastCrumb).addClass('last'); - OC.Breadcrumb.crumbs.push(lastCrumb); - var crumbs = OC.Breadcrumb.crumbs; - crumbs.reverse(); - jQuery.each(crumbs, function(i,crumb){ + var crumb=$('
'); + crumb.addClass('crumb'); + + var crumbLink=$(''); + crumbLink.attr('href',link); + + var crumbImg=$(''); + crumbImg.attr('src',OC.imagePath('core','places/home')); + crumbLink.append(crumbImg); + crumb.append(crumbLink); OC.Breadcrumb.container.prepend(crumb); - }); + OC.Breadcrumb.crumbs.push(crumb); + + //add path parts + var segments = dir.split('/'); + var pathurl = ''; + jQuery.each(segments, function(i,name) { + if (name !== '') { + pathurl = pathurl+'/'+name; + var link = OC.linkTo('files','index.php')+'?dir='+encodeURIComponent(pathurl); + OC.Breadcrumb.push(name, link); + } + }); + } + //add leafname + if (leafname && leaflink) { + OC.Breadcrumb.push(leafname, leaflink); + } }, push:function(name, link){ if(!OC.Breadcrumb.container){//default -- cgit v1.2.3 From d97e3c3571acb2ea88623384f4b17ced41dc0be9 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Sat, 3 Aug 2013 23:31:49 +0200 Subject: adding proper evaluation of plural form - uses LGPL licensed code of jsgettext --- core/js/js.js | 79 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 62 insertions(+), 17 deletions(-) (limited to 'core/js') diff --git a/core/js/js.js b/core/js/js.js index 37540bd15e7..b687c408bca 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -24,6 +24,55 @@ if (oc_debug !== true || typeof console === "undefined" || typeof console.log == } } +function initL10N(app) { + if (!( t.cache[app] )) { + $.ajax(OC.filePath('core', 'ajax', 'translations.php'), { + async: false,//todo a proper solution for this without sync ajax calls + data: {'app': app}, + type: 'POST', + success: function (jsondata) { + t.cache[app] = jsondata.data; + t.plural_form = jsondata.plural_form; + } + }); + + // Bad answer ... + if (!( t.cache[app] )) { + t.cache[app] = []; + } + } + if (typeof t.plural_function == 'undefined') { + t.plural_function = function (n) { + var p = (n != 1) ? 1 : 0; + return { 'nplural' : 2, 'plural' : p }; + }; + + /** + * code below has been taken from jsgettext - which is LGPL licensed + * https://developer.berlios.de/projects/jsgettext/ + * http://cvs.berlios.de/cgi-bin/viewcvs.cgi/jsgettext/jsgettext/lib/Gettext.js + */ + var pf_re = new RegExp('^(\\s*nplurals\\s*=\\s*[0-9]+\\s*;\\s*plural\\s*=\\s*(?:\\s|[-\\?\\|&=!<>+*/%:;a-zA-Z0-9_\(\)])+)', 'm'); + if (pf_re.test(t.plural_form)) { + //ex english: "Plural-Forms: nplurals=2; plural=(n != 1);\n" + //pf = "nplurals=2; plural=(n != 1);"; + //ex russian: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10< =4 && (n%100<10 or n%100>=20) ? 1 : 2) + //pf = "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)"; + var pf = t.plural_form; + if (! /;\s*$/.test(pf)) pf = pf.concat(';'); + /* We used to use eval, but it seems IE has issues with it. + * We now use "new Function", though it carries a slightly + * bigger performance hit. + var code = 'function (n) { var plural; var nplurals; '+pf+' return { "nplural" : nplurals, "plural" : (plural === true ? 1 : plural ? plural : 0) }; };'; + Gettext._locale_data[domain].head.plural_func = eval("("+code+")"); + */ + 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+"]"); + } + } +} /** * translate a string * @param app the id of the app for which to translate the string @@ -33,21 +82,7 @@ if (oc_debug !== true || typeof console === "undefined" || typeof console.log == * @return string */ function t(app, text, vars, count){ - if( !( t.cache[app] )) { - $.ajax(OC.filePath('core','ajax','translations.php'),{ - async:false,//todo a proper sollution for this without sync ajax calls - data:{'app': app}, - type:'POST', - success:function(jsondata){ - t.cache[app] = jsondata.data; - } - }); - - // Bad answer ... - if( !( t.cache[app] )){ - t.cache[app] = []; - } - } + initL10N(app); var _build = function (text, vars, count) { return text.replace(/%n/g, count).replace(/{([^{}]*)}/g, function (a, b) { @@ -67,7 +102,7 @@ function t(app, text, vars, count){ return translation; } } -t.cache={}; +t.cache = {}; /** * translate a string @@ -78,7 +113,17 @@ t.cache={}; * @param vars (optional) FIXME * @return string */ -function n(app, text_singular, text_plural, count, vars){ +function n(app, text_singular, text_plural, count, vars) { + initL10N(app); + var identifier = '_' + text_singular + '__' + text_plural + '_'; + if( typeof( t.cache[app][identifier] ) !== 'undefined' ){ + var translation = t.cache[app][identifier]; + if ($.isArray(translation)) { + var plural = t.plural_function(count); + return t(app, translation[plural.plural], vars, count); + } + } + if(count === 1) { return t(app, text_singular, vars, count); } -- cgit v1.2.3 From ff67f115d403d13dedf77457c539963f50a80eec Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Thu, 8 Aug 2013 13:50:04 +0200 Subject: fix #2711 using a custom event, also use css selectors over filterAttr --- apps/files/js/fileactions.js | 5 +++-- apps/files_sharing/js/share.js | 7 +++++-- core/js/share.js | 6 +++--- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'core/js') diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index aa66a57a7b5..de67d13559e 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -65,7 +65,7 @@ var FileActions = { FileActions.currentFile = parent; var actions = FileActions.get(FileActions.getCurrentMimeType(), FileActions.getCurrentType(), FileActions.getCurrentPermissions()); var file = FileActions.getCurrentFile(); - if ($('tr').filterAttr('data-file', file).data('renaming')) { + if ($('tr[data-file="'+file+'"]').data('renaming')) { return; } parent.children('a.name').append(''); @@ -164,10 +164,11 @@ $(document).ready(function () { window.location = OC.filePath('files', 'ajax', 'download.php') + '?files=' + encodeURIComponent(filename) + '&dir=' + encodeURIComponent($('#dir').val()); }); } - $('#fileList tr').each(function () { FileActions.display($(this).children('td.filename')); }); + + $('#fileList').trigger(jQuery.Event("fileActionsReady")); }); diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index eb5a6e8cb7f..b2efafde4e7 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -4,6 +4,10 @@ $(document).ready(function() { if (typeof OC.Share !== 'undefined' && typeof FileActions !== 'undefined' && !disableSharing) { + $('#fileList').one('fileActionsReady',function(){ + OC.Share.loadIcons('file'); + }); + FileActions.register('all', 'Share', OC.PERMISSION_READ, OC.imagePath('core', 'actions/share'), function(filename) { if ($('#dir').val() == '/') { var item = $('#dir').val() + filename; @@ -33,6 +37,5 @@ $(document).ready(function() { OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, true, possiblePermissions); } }); - OC.Share.loadIcons('file'); } -}); +}); \ No newline at end of file diff --git a/core/js/share.js b/core/js/share.js index b4b5159b0b5..b0d38c45cb8 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -22,9 +22,9 @@ OC.Share={ if (itemType != 'file' && itemType != 'folder') { $('a.share[data-item="'+item+'"]').css('background', 'url('+image+') no-repeat center'); } else { - var file = $('tr').filterAttr('data-id', item); + var file = $('tr[data-id="'+item+'"]'); if (file.length > 0) { - var action = $(file).find('.fileactions .action').filterAttr('data-action', 'Share'); + var action = $(file).find('.fileactions .action[data-action="Share"]'); var img = action.find('img').attr('src', image); action.addClass('permanent'); action.html(' '+t('core', 'Shared')).prepend(img); @@ -36,7 +36,7 @@ OC.Share={ // Search for possible parent folders that are shared while (path != last) { if (path == data['path']) { - var actions = $('.fileactions .action').filterAttr('data-action', 'Share'); + var actions = $('.fileactions .action[data-action="Share"]'); $.each(actions, function(index, action) { var img = $(action).find('img'); if (img.attr('src') != OC.imagePath('core', 'actions/public')) { -- cgit v1.2.3 From 9549bd3e68aa32bb9fa1a9a54bda84fa5070966f Mon Sep 17 00:00:00 2001 From: kondou Date: Fri, 9 Aug 2013 20:37:18 +0200 Subject: Use plural translations --- apps/files/js/filelist.js | 5 +++-- apps/files/js/files.js | 14 +++----------- apps/files_trashbin/js/trash.js | 12 ++---------- core/js/js.js | 10 ++++------ lib/template/functions.php | 10 ++++------ 5 files changed, 16 insertions(+), 35 deletions(-) (limited to 'core/js') diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index b858e2580ee..e0c72295702 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -452,13 +452,14 @@ $(document).ready(function(){ var currentUploads = parseInt(uploadtext.attr('currentUploads')); currentUploads += 1; uploadtext.attr('currentUploads', currentUploads); + var translatedText = n('files', '%n file uploading', '%n files uploading', currentUploads); if(currentUploads === 1) { var img = OC.imagePath('core', 'loading.gif'); data.context.find('td.filename').attr('style','background-image:url('+img+')'); - uploadtext.text(t('files', '1 file uploading')); + uploadtext.text(translatedText); uploadtext.show(); } else { - uploadtext.text(currentUploads + ' ' + t('files', 'files uploading')); + uploadtext.text(translatedText); } } else { // add as stand-alone row to filelist diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 3fad3fae7d3..53fc25f41b0 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -759,21 +759,13 @@ function procesSelection(){ $('#headerSize').text(humanFileSize(totalSize)); var selection=''; if(selectedFolders.length>0){ - if(selectedFolders.length==1){ - selection+=t('files','1 folder'); - }else{ - selection+=t('files','{count} folders',{count: selectedFolders.length}); - } + selection += n('files', '%n folder', '%n folders', selectedFolders.length); if(selectedFiles.length>0){ selection+=' & '; } } if(selectedFiles.length>0){ - if(selectedFiles.length==1){ - selection+=t('files','1 file'); - }else{ - selection+=t('files','{count} files',{count: selectedFiles.length}); - } + selection += n('files', '%n file', '%n files', selectedFiles.length); } $('#headerName>span.name').text(selection); $('#modified').text(''); @@ -852,4 +844,4 @@ function checkTrashStatus() { $("input[type=button][id=trash]").removeAttr("disabled"); } }); -} \ No newline at end of file +} diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index c3c958b07a7..b14a7240cbe 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -188,21 +188,13 @@ function processSelection(){ $('.selectedActions').show(); var selection=''; if(selectedFolders.length>0){ - if(selectedFolders.length === 1){ - selection+=t('files','1 folder'); - }else{ - selection+=t('files','{count} folders',{count: selectedFolders.length}); - } + selection += n('files', '%n folder', '%n folders', selectedFolders.length); if(selectedFiles.length>0){ selection+=' & '; } } if(selectedFiles.length>0){ - if(selectedFiles.length === 1){ - selection+=t('files','1 file'); - }else{ - selection+=t('files','{count} files',{count: selectedFiles.length}); - } + selection += n('files', '%n file', '%n files', selectedFiles.length); } $('#headerName>span.name').text(selection); $('#modified').text(''); diff --git a/core/js/js.js b/core/js/js.js index 1d1711383f7..0fc4bab80a7 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -812,15 +812,13 @@ function relative_modified_date(timestamp) { var diffdays = Math.round(diffhours/24); var diffmonths = Math.round(diffdays/31); if(timediff < 60) { return t('core','seconds ago'); } - else if(timediff < 120) { return t('core','1 minute ago'); } - else if(timediff < 3600) { return t('core','{minutes} minutes ago',{minutes: diffminutes}); } - else if(timediff < 7200) { return t('core','1 hour ago'); } - else if(timediff < 86400) { return t('core','{hours} hours ago',{hours: diffhours}); } + else if(timediff < 3600) { return n('core','%n minute ago', '%n minutes ago', diffminutes); } + else if(timediff < 86400) { return n('core', '%n hour ago', '%n hours ago', diffhours); } else if(timediff < 86400) { return t('core','today'); } else if(timediff < 172800) { return t('core','yesterday'); } - else if(timediff < 2678400) { return t('core','{days} days ago',{days: diffdays}); } + else if(timediff < 2678400) { return n('core', '%n day ago', '%n days ago', diffdays); } else if(timediff < 5184000) { return t('core','last month'); } - else if(timediff < 31556926) { return t('core','{months} months ago',{months: diffmonths}); } + else if(timediff < 31556926) { return n('core', '%n month ago', '%n months ago', diffmonths); } //else if(timediff < 31556926) { return t('core','months ago'); } else if(timediff < 63113852) { return t('core','last year'); } else { return t('core','years ago'); } diff --git a/lib/template/functions.php b/lib/template/functions.php index 2d43cae1c0c..717e197c1cb 100644 --- a/lib/template/functions.php +++ b/lib/template/functions.php @@ -78,15 +78,13 @@ function relative_modified_date($timestamp) { $diffmonths = round($diffdays/31); if($timediff < 60) { return $l->t('seconds ago'); } - else if($timediff < 120) { return $l->t('1 minute ago'); } - else if($timediff < 3600) { return $l->t('%d minutes ago', $diffminutes); } - else if($timediff < 7200) { return $l->t('1 hour ago'); } - else if($timediff < 86400) { return $l->t('%d hours ago', $diffhours); } + else if($timediff < 3600) { return $l->n('%n minute ago', '%n minutes ago', $diffminutes); } + else if($timediff < 86400) { return $l->n('%n hour ago', '%n hours ago', $diffhours); } else if((date('G')-$diffhours) > 0) { return $l->t('today'); } else if((date('G')-$diffhours) > -24) { return $l->t('yesterday'); } - else if($timediff < 2678400) { return $l->t('%d days ago', $diffdays); } + else if($timediff < 2678400) { return $l->n('%n day go', '%n days ago', $diffdays); } else if($timediff < 5184000) { return $l->t('last month'); } - else if((date('n')-$diffmonths) > 0) { return $l->t('%d months ago', $diffmonths); } + else if((date('n')-$diffmonths) > 0) { return $l->n('%n month ago', '%n months ago', $diffmonths); } else if($timediff < 63113852) { return $l->t('last year'); } else { return $l->t('years ago'); } } -- cgit v1.2.3 From 5660f99592b313e423c0b7d9682dacb1896ce102 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Tue, 13 Aug 2013 22:58:27 +0200 Subject: add PERMISSIONS_ALL summary --- core/js/js.js | 1 + 1 file changed, 1 insertion(+) (limited to 'core/js') diff --git a/core/js/js.js b/core/js/js.js index 1d1711383f7..64b5556987d 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -157,6 +157,7 @@ var OC={ PERMISSION_UPDATE:2, PERMISSION_DELETE:8, PERMISSION_SHARE:16, + PERMISSION_ALL:31, webroot:oc_webroot, appswebroots:(typeof oc_appswebroots !== 'undefined') ? oc_appswebroots:false, currentUser:(typeof oc_current_user!=='undefined')?oc_current_user:false, -- cgit v1.2.3 From ca95a475d5fa81f3b3a8b5dcbce87189b79fc56e Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Tue, 13 Aug 2013 22:58:47 +0200 Subject: use edit & reshare permission as default --- core/js/share.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core/js') diff --git a/core/js/share.js b/core/js/share.js index b4b5159b0b5..622b23d05a2 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -256,8 +256,8 @@ OC.Share={ var shareType = selected.item.value.shareType; var shareWith = selected.item.value.shareWith; $(this).val(shareWith); - // Default permissions are Read and Share - var permissions = OC.PERMISSION_READ | OC.PERMISSION_SHARE; + // Default permissions are Edit and Share (all) + var permissions = OC.PERMISSION_ALL; OC.Share.share(itemType, itemSource, shareType, shareWith, permissions, function() { OC.Share.addShareWith(shareType, shareWith, selected.item.label, permissions, possiblePermissions); $('#shareWith').val(''); -- cgit v1.2.3 From 11a404b90b8676cd38b1f6dbfbc7ca074f9a31ab Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 14 Aug 2013 00:25:07 +0200 Subject: comment clarification --- core/js/share.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/js') diff --git a/core/js/share.js b/core/js/share.js index 622b23d05a2..a0ae39fffed 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -256,7 +256,7 @@ OC.Share={ var shareType = selected.item.value.shareType; var shareWith = selected.item.value.shareWith; $(this).val(shareWith); - // Default permissions are Edit and Share (all) + // Default permissions are Edit (CRUD) and Share var permissions = OC.PERMISSION_ALL; OC.Share.share(itemType, itemSource, shareType, shareWith, permissions, function() { OC.Share.addShareWith(shareType, shareWith, selected.item.label, permissions, possiblePermissions); -- cgit v1.2.3 From 5fb7aab7a07d05a7d05c7f0dbb5dacf33d401383 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 15 Aug 2013 13:05:26 +0200 Subject: remove jPlayer css rules from core css file --- core/css/styles.css | 7 +++---- core/js/js.js | 2 -- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'core/js') diff --git a/core/css/styles.css b/core/css/styles.css index cf58a3b5f3f..1b58899eef6 100644 --- a/core/css/styles.css +++ b/core/css/styles.css @@ -45,7 +45,7 @@ body { background:#fefefe; font:normal .8em/1.6em "Helvetica Neue",Helvetica,Ari input[type="text"], input[type="password"], input[type="search"], input[type="number"], input[type="email"], input[type="url"], textarea, select, button, .button, -#quota, div.jp-progress, .pager li a { +#quota, .pager li a { width:10em; margin:.3em; padding:.6em .5em .4em; font-size:1em; background:#fff; color:#333; border:1px solid #ddd; outline:none; @@ -85,7 +85,7 @@ input[type="checkbox"]:hover+label, input[type="checkbox"]:focus+label { color:# /* BUTTONS */ input[type="submit"], input[type="button"], button, .button, -#quota, div.jp-progress, select, .pager li a { +#quota, select, .pager li a { width:auto; padding:.4em; background-color:rgba(240,240,240,.9); font-weight:bold; color:#555; text-shadow:rgba(255,255,255,.9) 0 1px 0; border:1px solid rgba(190,190,190,.9); cursor:pointer; -moz-box-shadow:0 1px 1px rgba(255,255,255,.9), 0 1px 1px rgba(255,255,255,.9) inset; -webkit-box-shadow:0 1px 1px rgba(255,255,255,.9), 0 1px 1px rgba(255,255,255,.9) inset; box-shadow:0 1px 1px rgba(255,255,255,.9), 0 1px 1px rgba(255,255,255,.9) inset; @@ -545,7 +545,7 @@ tbody tr:hover, tr:active { background-color:#f8f8f8; } .personalblock > legend, th, dt, label { font-weight:bold; } code { font-family:"Lucida Console", "Lucida Sans Typewriter", "DejaVu Sans Mono", monospace; } -#quota div, div.jp-play-bar, div.jp-seek-bar { +#quota div { padding: 0; background-color: rgb(220,220,220); font-weight: normal; @@ -553,7 +553,6 @@ code { font-family:"Lucida Console", "Lucida Sans Typewriter", "DejaVu Sans Mono -moz-border-radius-bottomleft: .4em; -webkit-border-bottom-left-radius: .4em; border-bottom-left-radius:.4em; -moz-border-radius-topleft: .4em; -webkit-border-top-left-radius: .4em; border-top-left-radius: .4em; } #quotatext {padding:.6em 1em;} -div.jp-play-bar, div.jp-seek-bar { padding:0; } .pager { list-style:none; float:right; display:inline; margin:.7em 13em 0 0; } .pager li { display:inline-block; } diff --git a/core/js/js.js b/core/js/js.js index 4dfe4d0e5ee..60a29342f26 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -758,8 +758,6 @@ $(document).ready(function(){ }); // all the tipsy stuff needs to be here (in reverse order) to work - $('.jp-controls .jp-previous').tipsy({gravity:'nw', fade:true, live:true}); - $('.jp-controls .jp-next').tipsy({gravity:'n', fade:true, live:true}); $('.displayName .action').tipsy({gravity:'se', fade:true, live:true}); $('.password .action').tipsy({gravity:'se', fade:true, live:true}); $('#upload').tipsy({gravity:'w', fade:true}); -- cgit v1.2.3
diff --git a/core/js/share.js b/core/js/share.js index 21e352ee1c6..4c8fd874107 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -161,7 +161,12 @@ OC.Share={ // respective checkbox should be checked or // not. + var publicUploadEnabled = $('#filestable').data('allow-public-upload'); + if (typeof publicUploadEnabled == 'undefined') { + publicUploadEnabled = 'no'; + } var allowPublicUploadStatus = false; + $.each(data.shares, function(key, value) { if (allowPublicUploadStatus) { return true; @@ -181,7 +186,7 @@ OC.Share={ html += '
'; html += ''; html += '
'; - if (itemType === 'folder' && (possiblePermissions & OC.PERMISSION_CREATE)) { + if (itemType === 'folder' && (possiblePermissions & OC.PERMISSION_CREATE) && publicUploadEnabled === 'yes') { html += '
> /> + value="1" />
t('Allow users to share items to the public with links')); ?>
> + /> +
+ t('Allow users to enable others to anonymously upload into their publicly shared folders')); ?> +
> Date: Tue, 16 Jul 2013 22:16:53 +0200 Subject: Add multiple plural forms to the php part --- core/js/js.js | 11 +++++------ lib/l10n.php | 34 ++++++++++++++++++++++++++++++---- lib/l10n/string.php | 9 ++++++++- 3 files changed, 43 insertions(+), 11 deletions(-) (limited to 'core/js') diff --git a/core/js/js.js b/core/js/js.js index 15cf1d286fa..37540bd15e7 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -33,7 +33,7 @@ if (oc_debug !== true || typeof console === "undefined" || typeof console.log == * @return string */ function t(app, text, vars, count){ - if( !( t.cache[app] )){ + if( !( t.cache[app] )) { $.ajax(OC.filePath('core','ajax','translations.php'),{ async:false,//todo a proper sollution for this without sync ajax calls data:{'app': app}, @@ -49,8 +49,7 @@ function t(app, text, vars, count){ } } var _build = function (text, vars, count) { - // FIXME: replace %n with content of count - return text.replace(/{([^{}]*)}/g, + return text.replace(/%n/g, count).replace(/{([^{}]*)}/g, function (a, b) { var r = vars[b]; return typeof r === 'string' || typeof r === 'number' ? r : a; @@ -62,7 +61,7 @@ function t(app, text, vars, count){ translation = t.cache[app][text]; } - if(typeof vars === 'object' || typeof count !== 'undefined' ) { + if(typeof vars === 'object' || count !== undefined ) { return _build(translation, vars, count); } else { return translation; @@ -79,8 +78,8 @@ t.cache={}; * @param vars (optional) FIXME * @return string */ -function tp(app, text_singular, text_plural, count, vars){ - if(count==1){ +function n(app, text_singular, text_plural, count, vars){ + if(count === 1) { return t(app, text_singular, vars, count); } else{ diff --git a/lib/l10n.php b/lib/l10n.php index 03528c22746..8348962cc10 100644 --- a/lib/l10n.php +++ b/lib/l10n.php @@ -176,13 +176,28 @@ class OC_L10N{ * * Returns the translation. If no translation is found, $text will be * returned. %n will be replaced with the number of objects. + * + * In case there is more than one plural form you can add a function + * "selectplural" in core/l10n/l10n-*.php + * + * Example: + * + * [...] + * 'selectplural' => function($i){return $i == 1 ? 0 : $i == 2 ? 1 : 2}, + * [...] */ - public function tp($text_singular, $text_plural, $count, $parameters = array()) { - if($count == 1){ - return new OC_L10N_String($this, $text_singular, $parameters, $count); + public function n($text_singular, $text_plural, $count, $parameters = array()) { + $identifier = "_${text_singular}__${text_plural}_"; + if(array_key_exists( $this->localizations, "selectplural") && array_key_exists($this->translations, $identifier)) { + return new OC_L10N_String( $this, $identifier, $parameters, $count ); } else{ - return new OC_L10N_String($this, $text_plural, $parameters, $count); + if($count === 1) { + return new OC_L10N_String($this, $text_singular, $parameters, $count); + } + else{ + return new OC_L10N_String($this, $text_plural, $parameters, $count); + } } } @@ -220,6 +235,17 @@ class OC_L10N{ return $this->translations; } + /** + * @brief get localizations + * @returns Fetch all localizations + * + * Returns an associative array with all localizations + */ + public function getLocalizations() { + $this->init(); + return $this->localizations; + } + /** * @brief Localization * @param $type Type of localization diff --git a/lib/l10n/string.php b/lib/l10n/string.php index 1bef7330945..3cda5eab506 100644 --- a/lib/l10n/string.php +++ b/lib/l10n/string.php @@ -18,10 +18,17 @@ class OC_L10N_String{ public function __toString() { $translations = $this->l10n->getTranslations(); + $localizations = $this->l10n->getLocalizations(); $text = $this->text; if(array_key_exists($this->text, $translations)) { - $text = $translations[$this->text]; + if(is_array($translations[$this->text])) { + $id = $localizations["selectplural"]( $count ); + $text = $translations[$this->text][$id] + } + else{ + $text = $translations[$this->text]; + } } // Replace %n first (won't interfere with vsprintf) $text = str_replace('%n', $this->count, $text); -- cgit v1.2.3 From 48948ccf5f6f1d7de2765fb955f956063d9bedc8 Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Thu, 18 Jul 2013 22:15:26 +0200 Subject: finally remove the file size obfuscation as it had more disadvantages. I was wrong, sorry. --- apps/files/js/filelist.js | 3 +-- apps/files/js/files.js | 4 +--- apps/files/templates/index.php | 2 +- apps/files/templates/part.list.php | 6 ++---- core/js/js.js | 10 ---------- lib/public/template.php | 10 ---------- lib/template.php | 18 ------------------ 7 files changed, 5 insertions(+), 48 deletions(-) (limited to 'core/js') diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index c847e2eff8b..04a9fb91649 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -47,7 +47,7 @@ var FileList={ //size column if(size!=t('files', 'Pending')){ - simpleSize=simpleFileSize(size); + simpleSize = humanFileSize(size); }else{ simpleSize=t('files', 'Pending'); } @@ -55,7 +55,6 @@ var FileList={ var lastModifiedTime = Math.round(lastModified.getTime() / 1000); td = $('t('Size (MB)')); ?>t('Size')); ?> t( 'Modified' )); ?> diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php index 97a9026860b..0c7d6936697 100644 --- a/apps/files/templates/part.list.php +++ b/apps/files/templates/part.list.php @@ -9,7 +9,6 @@ $totalsize = 0; ?> } else { $totalfiles++; } - $simple_file_size = OCP\simple_file_size($file['size']); // the bigger the file, the darker the shade of grey; megabytes*2 $simple_size_color = intval(160-$file['size']/(1024*1024)*2); if($simple_size_color<0) $simple_size_color = 0; @@ -52,9 +51,8 @@ $totalsize = 0; ?> - + } ?> - +