diff --git a/libraries/Forum/Post.php b/libraries/Forum/Post.php index 3828993..8acdb81 100644 --- a/libraries/Forum/Post.php +++ b/libraries/Forum/Post.php @@ -228,24 +228,4 @@ class Post // Return a new post object return new Post($this->id); } - - /** - * The "elapsed" string for this post. - * - * @return string Readable time elapsed since this post was created. - */ - public function timeElapsed() - { - return Utils::timeElapsed($this->time); - } - - /** - * Time "elapsed" since the last edit. - * - * @return string Readable time elapsed since this post was last edited. - */ - public function editTimeElapsed() - { - return Utils::timeElapsed($this->editTime); - } } diff --git a/libraries/Forum/Thread.php b/libraries/Forum/Thread.php index 49c0f76..9a58286 100644 --- a/libraries/Forum/Thread.php +++ b/libraries/Forum/Thread.php @@ -334,26 +334,6 @@ class Thread return Database::count('posts', ['topic_id' => [$this->id, '=']])[0]; } - /** - * The "elapsed" string for this thread since it was created. - * - * @return string Readable time elapsed since this thread was created. - */ - public function timeElapsed() - { - return Utils::timeElapsed($this->time); - } - - /** - * The "elapsed" string for this thread since the status was last changed. - * - * @return string Readble time elapsed since the status was last changed. - */ - public function statusChangeElapsed() - { - return Utils::timeElapsed($this->statusChange); - } - /** * Check if a user has read this thread before. * diff --git a/libraries/User.php b/libraries/User.php index 55be46b..cbd0af7 100644 --- a/libraries/User.php +++ b/libraries/User.php @@ -457,29 +457,6 @@ class User ]; } - /** - * Get the elapsed string for some of the user's dates - * - * @param string $append Append to the value. - * @param string $none Replace the 0 value with this. - * - * @return array The times. - */ - public function elapsed($append = ' ago', $none = 'Just now') - { - $times = []; - $dates = [ - 'joined' => $this->registered, - 'lastOnline' => $this->lastOnline, - ]; - - foreach ($dates as $key => $val) { - $times[$key] = Utils::timeElapsed($val, $append, $none); - } - - return $times; - } - /** * Add ranks to a user. * diff --git a/libraries/Utils.php b/libraries/Utils.php index e13fa9c..1c26543 100644 --- a/libraries/Utils.php +++ b/libraries/Utils.php @@ -686,50 +686,6 @@ class Utils return $logs; } - /** - * Calculate the time that has elapsed since a certain data (doesn't take leap years in account). - * - * @param int $timestamp The timestamp. - * @param string $append Append to - * @param string $none Text if 0. - * - * @return string Returns the time elapsed in a readable format. - */ - public static function timeElapsed($timestamp, $append = ' ago', $none = 'Just now') - { - - // Subtract the entered timestamp from the current timestamp - $time = time() - $timestamp; - - // If the new timestamp is below 1 return a standard string - if ($time < 1) { - return $none; - } - - // Array containing time "types" - $times = [ - 365 * 24 * 60 * 60 => 'year', - 30 * 24 * 60 * 60 => 'month', - 24 * 60 * 60 => 'day', - 60 * 60 => 'hour', - 60 => 'minute', - 1 => 'second', - ]; - - foreach ($times as $secs => $str) { - // Do a devision to check if the given timestamp fits in the current "type" - $calc = $time / $secs; - - if ($calc >= 1) { - // Round the number - $round = floor($calc); - - // Return the string - return $round . ' ' . $times[$secs] . ($round == 1 ? '' : 's') . $append; - } - } - } - /** * Get the byte symbol for a unit from bytes. * diff --git a/public/content/scripts/sakura.js b/public/content/scripts/sakura.js index 251e182..5d89f40 100644 --- a/public/content/scripts/sakura.js +++ b/public/content/scripts/sakura.js @@ -106,6 +106,42 @@ var Sakura = (function () { // Test it on the email var which'll return a boolean return re.test(email); }; + // Calculate the time that has elapsed since a certain data (doesn't take leap years in account). + Sakura.timeElapsed = function (timestamp, append, none) { + if (append === void 0) { append = ' ago'; } + if (none === void 0) { none = 'Just now'; } + // Subtract the entered timestamp from the current timestamp + var time = this.epoch() - timestamp; + // If the new timestamp is below 1 return a standard string + if (time < 1) { + return none; + } + // Times array + var times = { + 31536000: 'year', + 2592000: 'month', + 86400: 'day', + 3600: 'hour', + 60: 'minute', + 1: 'second' + }; + // + var timeKeys = Object.keys(times).reverse(); + // Iterate over the times + for (var i in timeKeys) { + // Do a devision to check if the given timestamp fits in the current "type" + var calc = time / parseInt(timeKeys[i]); + // Check if we have a match + if (calc >= 1) { + // Round the number + var display = Math.floor(calc); + // Return the formatted string + return display + " " + times[timeKeys[i]] + (display === 1 ? '' : 's') + append; + } + } + // If everything fails just return none + return none; + }; Sakura.cookiePrefix = ""; // Cookie prefix, gets prepended to cookie names Sakura.cookiePath = "/"; // Cookie path, can in most cases be left untouched return Sakura; diff --git a/public/content/scripts/sakura.ts b/public/content/scripts/sakura.ts index 1703566..055b7d5 100644 --- a/public/content/scripts/sakura.ts +++ b/public/content/scripts/sakura.ts @@ -128,6 +128,48 @@ class Sakura { // Test it on the email var which'll return a boolean return re.test(email); } + + // Calculate the time that has elapsed since a certain data (doesn't take leap years in account). + public static timeElapsed(timestamp: number, append: string = ' ago', none: string = 'Just now'): string { + // Subtract the entered timestamp from the current timestamp + var time: number = this.epoch() - timestamp; + + // If the new timestamp is below 1 return a standard string + if (time < 1) { + return none; + } + + // Times array + var times: Object = { + 31536000: 'year', + 2592000: 'month', + 86400: 'day', + 3600: 'hour', + 60: 'minute', + 1: 'second' + }; + + // + var timeKeys: string[] = Object.keys(times).reverse(); + + // Iterate over the times + for (var i in timeKeys) { + // Do a devision to check if the given timestamp fits in the current "type" + var calc: number = time / parseInt(timeKeys[i]); + + // Check if we have a match + if (calc >= 1) { + // Round the number + var display: number = Math.floor(calc); + + // Return the formatted string + return display + " " + times[timeKeys[i]] + (display === 1 ? '' : 's') + append; + } + } + + // If everything fails just return none + return none; + } } // UTF-8 functions diff --git a/public/settings.php b/public/settings.php index 181a217..9a89b43 100644 --- a/public/settings.php +++ b/public/settings.php @@ -1498,11 +1498,6 @@ if (Users::checkLogin()) { ]; break; - // Username changing - case 'account.username': - $renderData['difference'] = $currentUser->getUsernameHistory() ? Utils::timeElapsed($currentUser->getUsernameHistory()[0]['change_time']) : 0; - break; - // Sessions case 'advanced.sessions': $renderData['sessions'] = Database::fetch('sessions', true, ['user_id' => [$currentUser->id, '=']]); diff --git a/sakura.php b/sakura.php index 8aa1d7f..7162a74 100644 --- a/sakura.php +++ b/sakura.php @@ -170,7 +170,7 @@ if (!defined('SAKURA_NO_TPL')) { 'siteLogo' => Config::get('sitelogo'), 'siteDesc' => Config::get('sitedesc'), 'siteTags' => json_decode(Config::get('sitetags'), true), - 'dateFormat' => Config::get('date_format'), + 'dateFormat' => 'r', 'currentPage' => (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null), 'referrer' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null), 'onlineTimeout' => Config::get('max_online_time'), diff --git a/templates/yuuno/elements/indexPanel.twig b/templates/yuuno/elements/indexPanel.twig index 6cba99d..740b6bd 100644 --- a/templates/yuuno/elements/indexPanel.twig +++ b/templates/yuuno/elements/indexPanel.twig @@ -32,7 +32,7 @@ All active users in the past {{ sakura.onlineTimeout / 60 }} minute{% if sakura.onlineTimeout != 60 %}s{% endif %}
{{ onlineUser.username }} | {{ onlineUser.elapsed.lastOnline }} |
{{ onlineUser.username }} |