From 58776ee04731c7e43daf50deb37418347aa9225b Mon Sep 17 00:00:00 2001 From: flashwave Date: Fri, 5 Feb 2016 23:03:08 +0100 Subject: [PATCH] more shit --- libraries/Forum/Post.php | 20 --- libraries/Forum/Thread.php | 20 --- libraries/User.php | 23 --- libraries/Utils.php | 44 ------ public/content/scripts/sakura.js | 36 +++++ public/content/scripts/sakura.ts | 42 ++++++ public/settings.php | 5 - sakura.php | 2 +- templates/yuuno/elements/indexPanel.twig | 2 +- templates/yuuno/elements/newsPost.twig | 2 +- templates/yuuno/forum/forumEntry.twig | 2 +- templates/yuuno/forum/topicEntry.twig | 2 +- templates/yuuno/forum/viewtopic.twig | 2 +- templates/yuuno/global/master.twig | 133 ++++++++++-------- templates/yuuno/main/memberlist.twig | 8 +- templates/yuuno/main/profile.twig | 4 +- .../yuuno/settings/account.username.twig | 2 +- .../yuuno/settings/notifications.history.twig | 2 +- 18 files changed, 167 insertions(+), 184 deletions(-) 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 %} {% for amount,onlineUser in stats.onlineUsers %} - + {% endfor %}
{{ onlineUser.username }}{{ onlineUser.elapsed.lastOnline }}
{{ onlineUser.username }}
{% else %} diff --git a/templates/yuuno/elements/newsPost.twig b/templates/yuuno/elements/newsPost.twig index f9ea61a..19da52f 100644 --- a/templates/yuuno/elements/newsPost.twig +++ b/templates/yuuno/elements/newsPost.twig @@ -12,5 +12,5 @@
- Posted on {{ post.news_timestamp|date(sakura.dateFormat) }}{% if not (viewPost and postExists) %} {{ post.news_comments.count }} comment{% if post.news_comments.count != 1 %}s{% endif %}{% endif %} + Posted on {% if not (viewPost and postExists) %} {{ post.news_comments.count }} comment{% if post.news_comments.count != 1 %}s{% endif %}{% endif %}
diff --git a/templates/yuuno/forum/forumEntry.twig b/templates/yuuno/forum/forumEntry.twig index 845e753..93b1f8f 100644 --- a/templates/yuuno/forum/forumEntry.twig +++ b/templates/yuuno/forum/forumEntry.twig @@ -24,7 +24,7 @@
{% if forum.lastPost.id %} {{ forum.lastPost.subject|slice(0, 30) }}{% if forum.lastPost.subject|length > 30 %}...{% endif %}
- {{ forum.lastPost.timeElapsed }} by {% if forum.lastPost.poster.id %}{{ forum.lastPost.poster.username }}{% else %}[deleted user]{% endif %} + by {% if forum.lastPost.poster.id %}{{ forum.lastPost.poster.username }}{% else %}[deleted user]{% endif %} {% else %} There are no posts in this forum.
  {% endif %} diff --git a/templates/yuuno/forum/topicEntry.twig b/templates/yuuno/forum/topicEntry.twig index efe584b..e125bfb 100644 --- a/templates/yuuno/forum/topicEntry.twig +++ b/templates/yuuno/forum/topicEntry.twig @@ -22,6 +22,6 @@ {% else %} [deleted user] {% endif %}
- {{ thread.lastPost.timeElapsed }} + diff --git a/templates/yuuno/forum/viewtopic.twig b/templates/yuuno/forum/viewtopic.twig index 538a1b0..8df196f 100644 --- a/templates/yuuno/forum/viewtopic.twig +++ b/templates/yuuno/forum/viewtopic.twig @@ -118,7 +118,7 @@ {{ post.subject|slice(0, 50) }}{% if post.subject|length > 50 %}...{% endif %}
- #{{ post.id }} - {{ post.timeElapsed }} + #{{ post.id }} -
diff --git a/templates/yuuno/global/master.twig b/templates/yuuno/global/master.twig index c60d500..63ac67b 100644 --- a/templates/yuuno/global/master.twig +++ b/templates/yuuno/global/master.twig @@ -58,64 +58,6 @@ Sakura.cookiePrefix = "{{ sakura.cookie.prefix }}"; Sakura.cookiePath = "{{ sakura.cookie.path }}"; - // Space for things that need to happen onload - window.addEventListener("load", function() { - {% if session.checkLogin %} - // Convert href to object in logout link - prepareAjaxLink('headerLogoutLink', 'submitPost', ', true, "Logging out..."'); - {% elseif not sakura.lockAuth and php.self != '/authenticate.php' %} - // Make the header login form dynamic - prepareAjaxForm('headerLoginForm', 'Logging in...'); - {% endif %} - - {% if session.checkLogin %} - // Make notification requests (there's a seperate one to make it happen before the first 60 seconds) - notifyRequest('{{ php.sessionid }}'); - - // Create interval - setInterval(function() { - notifyRequest('{{ php.sessionid }}'); - }, 60000); - {% endif %} - - {% if php.self == '/profile.php' and session.checkLogin and user.id != profile.id %} - // Make friend button dynamic - prepareAjaxLink('profileFriendToggle', 'submitPost', ', true, "{% if profile.friend == 0 %}Adding{% else %}Removing{% endif %} friend..."'); - {% endif %} - - {% if php.self == '/viewtopic.php' and session.checkLogin %} - var forumFriendToggles = document.querySelectorAll('.forum-friend-toggle'); - - for(var i in forumFriendToggles) { - prepareAjaxLink(forumFriendToggles[i], 'submitPost', ', true, "Please wait..."'); - } - {% endif %} - - {% if php.self == '/authenticate.php' and not (sakura.lockAuth or session.checkLogin) %} - - // AJAX Form Submission - var forms = { - {% if not auth.changingPass %} - "loginForm": 'Logging in...', - {% if not sakura.disableRegistration %} - "registerForm": 'Processing registration...', - {% endif %} - {% if sakura.requireActivation %} - "resendForm": 'Attempting to resend activation...', - {% endif %} - "passwordForm": 'Sending password recovery mail...' - {% else %} - "passwordForm": 'Changing password...' - {% endif %} - }; - - for(var i in forms) { - prepareAjaxForm(i, forms[i], (i == 'registerForm')); - } - - {% endif %} - }); - // Error reporter window.onerror = function(msg, url, line, col, error) { notifyUI({ @@ -200,6 +142,7 @@
A staff member has set your account to restricted mode most likely due to violation of the rules. While restricted you won't be able to use most public features of the site. If you think this is a mistake please get in touch with one of our staff members.
{% endif %} +