diff --git a/.styleci.yml b/.styleci.yml index 238f41a..9c2c76c 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -17,7 +17,7 @@ disabled: - concat_without_spaces - declare_equal_normalize - heredoc_to_nowdoc - - method_argument_space + - method_argument_space_strict - new_with_braces - no_alternative_syntax - phpdoc_align diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e95452..91936c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * **1.4 (not yet released)** * CHANGED: Minimum required PHP version is 5.6, due to a change in the identicon library and to use php's native hash_equals() * CHANGED: Upgrading libraries to: identicon 2.0.0 + * FIXED: Support custom expiration options in email function (#586) * **1.3.3 (2020-02-16)** * CHANGED: Upgrading libraries to: DOMpurify 2.0.8 * CHANGED: Several translations got updated with missing messages diff --git a/i18n/de.json b/i18n/de.json index 31eec78..47e8adc 100644 --- a/i18n/de.json +++ b/i18n/de.json @@ -172,9 +172,9 @@ "Notice:": "Hinweis:", "This link will expire after %s.": - "Dieser Link wird in %s ablaufen.", + "Dieser Link wird um %s ablaufen.", "This link can only be accessed once, do not use back or refresh button in your browser.": - "Dieser Link kann nur einmal geöffnet werden, verwende nicht den \"Zurück\" oder \"Neu laden\" Knopf Deines Browsers.", + "Dieser Link kann nur einmal geöffnet werden, verwende nicht den Zurück- oder Neu-laden-Knopf Deines Browsers.", "Link:": "Link:", "Recipient may become aware of your timezone, convert time to UTC?": diff --git a/js/privatebin.js b/js/privatebin.js index 73bdd92..65b407e 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -209,6 +209,64 @@ jQuery.PrivateBin = (function($, RawDeflate) { '=': '=' }; + /** + * number of seconds in a minute + * + * @name Helper.minute + * @private + * @enum {number} + * @readonly + */ + const minute = 60; + + /** + * number of seconds in an hour + * + * = 60 * 60 seconds + * + * @name Helper.minute + * @private + * @enum {number} + * @readonly + */ + const hour = 3600; + + /** + * number of seconds in a day + * + * = 60 * 60 * 24 seconds + * + * @name Helper.day + * @private + * @enum {number} + * @readonly + */ + const day = 86400; + + /** + * number of seconds in a month (30 days, an approximation) + * + * = 60 * 60 * 24 * 30 seconds + * + * @name Helper.month + * @private + * @enum {number} + * @readonly + */ + const month = 2592000; + + /** + * number of seconds in a non-leap year + * + * = 60 * 60 * 24 * 365 seconds + * + * @name Helper.year + * @private + * @enum {number} + * @readonly + */ + const year = 31536000; + /** * cache for script location * @@ -229,31 +287,67 @@ jQuery.PrivateBin = (function($, RawDeflate) { me.secondsToHuman = function(seconds) { let v; - if (seconds < 60) + if (seconds < minute) { v = Math.floor(seconds); return [v, 'second']; } - if (seconds < 60 * 60) + if (seconds < hour) { - v = Math.floor(seconds / 60); + v = Math.floor(seconds / minute); return [v, 'minute']; } - if (seconds < 60 * 60 * 24) + if (seconds < day) { - v = Math.floor(seconds / (60 * 60)); + v = Math.floor(seconds / hour); return [v, 'hour']; } // If less than 2 months, display in days: - if (seconds < 60 * 60 * 24 * 60) + if (seconds < (2 * month)) { - v = Math.floor(seconds / (60 * 60 * 24)); + v = Math.floor(seconds / day); return [v, 'day']; } - v = Math.floor(seconds / (60 * 60 * 24 * 30)); + v = Math.floor(seconds / month); return [v, 'month']; }; + /** + * converts a duration string into seconds + * + * The string is expected to be optional digits, followed by a time. + * Supported times are: min, hour, day, month, year, never + * Examples: 5min, 13hour, never + * + * @name Helper.durationToSeconds + * @function + * @param {String} duration + * @return {number} + */ + me.durationToSeconds = function(duration) + { + let pieces = duration.split(/\d+/), + factor = pieces[0] || 0, + timespan = pieces[1] || pieces[0]; + switch (timespan) + { + case 'min': + return factor * minute; + case 'hour': + return factor * hour; + case 'day': + return factor * day; + case 'month': + return factor * month; + case 'year': + return factor * year; + case 'never': + return 0; + default: + return factor; + } + }; + /** * text range selection * @@ -433,22 +527,10 @@ jQuery.PrivateBin = (function($, RawDeflate) { * @return {Date} */ me.calculateExpirationDate = function(initialDate, expirationDisplayStringOrSecondsToExpire) { - let expirationDate = new Date(initialDate); - - const expirationDisplayStringToSecondsDict = { - '5min': 300, - '10min': 600, - '1hour': 3500, - '1day': 86400, - '1week': 604800, - '1month': 2592000, - '1year': 31536000, - 'never': 0 - }; - - let secondsToExpiration = expirationDisplayStringOrSecondsToExpire; + let expirationDate = new Date(initialDate), + secondsToExpiration = expirationDisplayStringOrSecondsToExpire; if (typeof expirationDisplayStringOrSecondsToExpire === 'string') { - secondsToExpiration = expirationDisplayStringToSecondsDict[expirationDisplayStringOrSecondsToExpire]; + secondsToExpiration = me.durationToSeconds(expirationDisplayStringOrSecondsToExpire); } if (typeof secondsToExpiration !== 'number') { diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index b511a48..1ea2686 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -72,7 +72,7 @@ endif; ?> - + diff --git a/tpl/page.php b/tpl/page.php index f9b5584..935a172 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -50,7 +50,7 @@ endif; ?> - +