From 4daf30d75a14fd410a5492ab8ae90450b2180944 Mon Sep 17 00:00:00 2001 From: flashwave Date: Sun, 18 Dec 2016 23:00:24 +0100 Subject: [PATCH] various fixes --- .../Command/PurgeInactiveUsersCommand.php | 1 - app/Controllers/AuthController.php | 2 +- app/Controllers/UserController.php | 41 +- app/News/Category.php | 3 +- resources/assets/less/yuuno/bem/content.less | 2 +- resources/views/yuuno/auth/header_auth.twig | 78 ++++ .../yuuno/elements/comments_javascript.twig | 0 resources/views/yuuno/macros.twig | 11 +- resources/views/yuuno/master.twig | 79 +--- resources/views/yuuno/user/profile.twig | 392 +++++------------- .../views/yuuno/user/profile_header.twig | 60 +++ .../views/yuuno/user/profile_javascript.twig | 127 ++++++ .../views/yuuno/user/profile_macros.twig | 8 + 13 files changed, 411 insertions(+), 393 deletions(-) create mode 100644 resources/views/yuuno/auth/header_auth.twig create mode 100644 resources/views/yuuno/elements/comments_javascript.twig create mode 100644 resources/views/yuuno/user/profile_header.twig create mode 100644 resources/views/yuuno/user/profile_javascript.twig create mode 100644 resources/views/yuuno/user/profile_macros.twig diff --git a/app/Console/Command/PurgeInactiveUsersCommand.php b/app/Console/Command/PurgeInactiveUsersCommand.php index 655344b..05362c5 100644 --- a/app/Console/Command/PurgeInactiveUsersCommand.php +++ b/app/Console/Command/PurgeInactiveUsersCommand.php @@ -8,7 +8,6 @@ namespace Sakura\Console\Command; use CLIFramework\Command; use Sakura\DB; -use Sakura\Forum\Post; /** * Purges users that have been inactive for 30 days or more. diff --git a/app/Controllers/AuthController.php b/app/Controllers/AuthController.php index 9aa9905..7ed6557 100644 --- a/app/Controllers/AuthController.php +++ b/app/Controllers/AuthController.php @@ -61,7 +61,7 @@ class AuthController extends Controller public function logout(): void { if (!session_check()) { - throw new HttpMethodNotAllowedException; + throw new HttpMethodNotAllowedException; } // Destroy the active session diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index 7b043f3..7d92ada 100644 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -24,24 +24,27 @@ class UserController extends Controller /** * Display the profile of a user. * @param int $id + * @throws HttpRouteNotFoundException * @return string */ public function profile(int $id = 0): string { $profile = User::construct($id); - // If the user id is zero check if there was a namechange - if ($profile->id === 0) { - // Fetch from username_history - $check = DB::table('username_history') - ->where('username_old_clean', clean_string($id, true)) - ->orderBy('change_id', 'desc') - ->first(); - - // Redirect if so - if ($check) { - return redirect(route('user.profile', $check->user_id)); - } + if ($profile->id === 0 + || !$profile->activated + || ( + $profile->restricted + && ( + $profile->id !== CurrentSession::$user->id + || !( + CurrentSession::$user->perms->isMod + || CurrentSession::$user->perms->isAdmin + ) + ) + ) + ) { + throw new HttpRouteNotFoundException; } return view('user/profile', compact('profile')); @@ -54,12 +57,22 @@ class UserController extends Controller */ public function resolve(string $name): string { + $clean_name = clean_string($name, true); + $id = DB::table('users') - ->where('username_clean', clean_string($name, true)) + ->where('username_clean', $clean_name) ->value('user_id'); if (!$id) { - throw new HttpRouteNotFoundException; + // Fetch from username_history + $id = DB::table('username_history') + ->where('username_old_clean', $clean_name) + ->orderBy('change_id', 'desc') + ->value('user_id'); + + if (!$id) { + throw new HttpRouteNotFoundException; + } } return redirect(route('user.profile', $id)); diff --git a/app/News/Category.php b/app/News/Category.php index 56a2abe..5dd9f90 100644 --- a/app/News/Category.php +++ b/app/News/Category.php @@ -8,6 +8,7 @@ namespace Sakura\News; use Carbon\Carbon; use Sakura\DB; +use stdClass; /** * News category object. @@ -90,7 +91,7 @@ class Category $posts->limit($limit); } - $this->postsCache = array_map(function ($post) { + $this->postsCache = array_map(function (stdClass $post) { return new Post($post->post_id); }, $posts->get(['post_id'])); } diff --git a/resources/assets/less/yuuno/bem/content.less b/resources/assets/less/yuuno/bem/content.less index 93fc4bb..412f46e 100644 --- a/resources/assets/less/yuuno/bem/content.less +++ b/resources/assets/less/yuuno/bem/content.less @@ -45,7 +45,7 @@ @media (max-width: 1064px) { &--left, &--right { - width: 100%; + width: 100% !important; } &--left { diff --git a/resources/views/yuuno/auth/header_auth.twig b/resources/views/yuuno/auth/header_auth.twig new file mode 100644 index 0000000..94eb4d4 --- /dev/null +++ b/resources/views/yuuno/auth/header_auth.twig @@ -0,0 +1,78 @@ +{% if user.id == 0 %} +
+ +
+ + +{% else %} + +{% endif %} \ No newline at end of file diff --git a/resources/views/yuuno/elements/comments_javascript.twig b/resources/views/yuuno/elements/comments_javascript.twig new file mode 100644 index 0000000..e69de29 diff --git a/resources/views/yuuno/macros.twig b/resources/views/yuuno/macros.twig index fcbb163..87c9952 100644 --- a/resources/views/yuuno/macros.twig +++ b/resources/views/yuuno/macros.twig @@ -1,12 +1,3 @@ -{% macro profile_image_changer(url, query) %} -
- - -
-{% endmacro %} - {% macro news_post(id, text, created, user, title, comments) %} {% if title is defined and title %} {{ title }} @@ -55,4 +46,4 @@ {% endif %} {% endif %} -{% endmacro %} \ No newline at end of file +{% endmacro %} diff --git a/resources/views/yuuno/master.twig b/resources/views/yuuno/master.twig index 21f1f26..ba409a8 100644 --- a/resources/views/yuuno/master.twig +++ b/resources/views/yuuno/master.twig @@ -63,84 +63,7 @@ - {% if user.id == 0 %} -
- -
- - - {% else %} - - {% endif %} + {% include 'auth/header_auth.twig' %}
diff --git a/resources/views/yuuno/user/profile.twig b/resources/views/yuuno/user/profile.twig index 0913b5f..7a559bd 100644 --- a/resources/views/yuuno/user/profile.twig +++ b/resources/views/yuuno/user/profile.twig @@ -1,10 +1,10 @@ {% extends 'master.twig' %} -{% from 'macros.twig' import profile_image_changer as pic %} -{% set profileHidden = profile.id == 0 or not profile.activated and (user.id != profile.id and not (user.perms.isMod or user.perms.isAdmin)) %} -{% set noUserpage = profile.userPage|length < 1 %} -{% set title = profileHidden ? 'User not found!' : 'Profile of ' ~ profile.username %} +{% from 'user/profile_macros.twig' import profile_image_changer %} + +{% set title = 'Profile of ' ~ profile.username %} {% set youtubeIsChannelId = profile.youtube|slice(0, 2) == 'UC' and profile.youtube|length == 24 %} +{% set possessiveUsername = profile.username ~ "'" ~ (profile.username[:-1] == 's' ? '' : 's') %} {% if user.perms.viewUserLinks or user.perms.viewUserDetails %} {% set fields = { @@ -37,7 +37,7 @@ "title": "YouTube", "value": profile.youtube, "link": "https://youtube.com/" ~ (youtubeIsChannelId ? 'channel/' : '') ~ "%s", - "disp": youtubeIsChannelId ? profile.username ~ "'s channel" : "%s", + "disp": youtubeIsChannelId ? possessiveUsername ~ " channel" : "%s", }, "steam": { "title": "Steam", @@ -70,222 +70,54 @@ } %} {% endif %} +{% set sections = { + "userpage": { + "icon": "fa-file-text-o", + "title": possessiveUsername ~ " user page", + "display": profile.userPage|length > 0 + }, + "friends": { + "icon": "fa-list", + "title": possessiveUsername ~ " topics", + "display": true + }, + "groups": { + "icon": "fa-users", + "title": "Groups " ~ profile.username ~ " is part of", + "display": false + }, + "topics": { + "icon": "fa-reply", + "title": possessiveUsername ~ " posts", + "display": true + }, + "posts": { + "icon": "fa-star", + "title": possessiveUsername ~ " friends", + "display": true + }, + "comments": { + "icon": "fa-comments-o", + "title": possessiveUsername ~ " profile comments", + "display": true + }, +} %} + {% block js %} - {% if not profileHidden %} - - {% endif %} + {% include 'user/profile_javascript.twig' %} {% endblock %} {% block content %} - {% if profileHidden %} -
-
-

The requested user does not exist!

- There are a few possible reasons for this: -
    -
  • They changed their username.
  • -
  • They may have been restricted.
  • -
  • You made a typo.
  • -
  • They never existed.
  • -
-
-
- {% else %} - {% if (user.id == profile.id and not user.restricted and user.activated and user.perms.changeBackground) or user.perms.manageProfileImages %} - {{ pic(route('user.background', profile.id), '.container') }} - {% endif %} -
-
-
-
- {% if (user.id == profile.id and not user.restricted and user.activated and user.perms.changeHeader) or user.perms.manageProfileImages %} - {{ pic(route('user.header', profile.id), '.profile__header') }} - {% endif %} -
- {% if (user.id == profile.id and not user.restricted and user.activated and user.perms.changeAvatar) or user.perms.manageProfileImages %} - {{ pic(route('user.avatar', profile.id), '.avatar') }} - {% endif %} -
-
-

{{ profile.username }}

- {% if profile.isPremium %}Tenshi {% endif %}{{ profile.country }} {{ profile.title }} -
-
- {% spaceless %} -
- Joined  -
-
- {% if profile.lastOnline < 1 %} - {{ profile.username }} hasn't logged in yet. - {% else %} - Last online  - {% endif %} -
- {% if profile.birthday != '0000-00-00' and profile.birthday|split('-')[0] > 0 %} -
- Age {{ profile.birthday(true) }} years old -
- {% endif %} - {% endspaceless %} -
-
-
-
-
- {% if not noUserpage %} - - {% endif %} - - - - -
- {% if user.isActive %} -
- {% if user.id == profile.id %} - - {% else %} - {% if user.isFriends(profile.id) != 0 %}{% endif %} - - - {% endif %} - {% if user.perms.canRestrict %} - - {% endif %} -
- {% endif %} -
-
-
- {% if profile.lastfm %} + {% if (user.id == profile.id and not user.restricted and user.activated and user.perms.changeBackground) or user.perms.manageProfileImages %} + {{ profile_image_changer(route('user.background', profile.id), '.container') }} + {% endif %} + +
+
+ {% include 'user/profile_header.twig' %} +
+
+ {% if profile.lastfm %}
@@ -297,80 +129,66 @@
- {% endif %} - - -
+ {% endfor %} +
+
+ + + + + + + + + + + + + +
Topics{{ profile.forumStats.topics }}
Posts{{ profile.forumStats.posts }}
Friends{{ profile.friends(2)|length }}
+
+ {% if user.perms.viewUserLinks or user.perms.viewUserDetails %} - - - - - - - - - - - - + {% for id, data in fields %} + {% if data.value != null %} + + + + + {% endif %} + {% endfor %}
Topics{{ profile.forumStats.topics }}
Posts{{ profile.forumStats.posts }}
Friends{{ profile.friends(2)|length }}
+ {{ data.title }} + + {% if data.link is defined %} + {{ (data.disp is defined ? data.disp : '%s')|format(data.value) }} + {% else %} + {{ (data.disp is defined ? data.disp : '%s')|format(data.value) }} + {% endif %} +
-
- {% if user.perms.viewUserLinks or user.perms.viewUserDetails %} - - {% for id, data in fields %} - {% if data.value != null %} - - - - - {% endif %} - {% endfor %} -
- {{ data.title }} - - {% if data.link is defined %} - {{ (data.disp is defined ? data.disp : '%s')|format(data.value) }} - {% else %} - {{ (data.disp is defined ? data.disp : '%s')|format(data.value) }} - {% endif %} -
- {% elseif user.id == 0 %} -
Log in to view the full profile!
- {% else %} -
You aren't allowed to view profile details!
- {% endif %} - Account Standing - {% if not profile.activated %} -

Deactivated

- {% elseif profile.restricted %} -

Restricted

- {% elseif false %} -

Bad

- {% else %} -

Good

- {% endif %} -
+ {% elseif user.id == 0 %} +
Log in to view the full profile!
+ {% else %} +
You aren't allowed to view profile details!
+ {% endif %} + Account Standing + {% if not profile.activated %} +

Inactive

+ {% elseif profile.restricted %} +

Restricted

+ {% elseif false %} +

Bad

+ {% else %} +

Good

+ {% endif %}
- {% endif %} +
{% endblock %} diff --git a/resources/views/yuuno/user/profile_header.twig b/resources/views/yuuno/user/profile_header.twig new file mode 100644 index 0000000..60b5ff4 --- /dev/null +++ b/resources/views/yuuno/user/profile_header.twig @@ -0,0 +1,60 @@ +{% from 'user/profile_macros.twig' import profile_image_changer %} + +
+
+ {% if (user.id == profile.id and not user.restricted and user.activated and user.perms.changeHeader) or user.perms.manageProfileImages %} + {{ profile_image_changer(route('user.header', profile.id), '.profile__header') }} + {% endif %} +
+ {% if (user.id == profile.id and not user.restricted and user.activated and user.perms.changeAvatar) or user.perms.manageProfileImages %} + {{ profile_image_changer(route('user.avatar', profile.id), '.avatar') }} + {% endif %} +
+
+

{{ profile.username }}

+ {% if profile.isPremium %}Tenshi {% endif %}{{ profile.country }} {{ profile.title }} +
+
+ {% spaceless %} +
+ Joined  +
+
+ {% if profile.lastOnline < 1 %} + {{ profile.username }} hasn't logged in yet. + {% else %} + Last online  + {% endif %} +
+ {% if profile.birthday != '0000-00-00' and profile.birthday|split('-')[0] > 0 %} +
+ Age {{ profile.birthday(true) }} years old +
+ {% endif %} + {% endspaceless %} +
+
+
+
+
+ {% for name, data in sections %} + {% if data.display %} + + {% endif %} + {% endfor %} +
+ {% if user.isActive %} +
+ {% if user.id == profile.id %} + + {% else %} + {% if user.isFriends(profile.id) != 0 %}{% endif %} + + + {% endif %} + {% if user.perms.canRestrict %} + + {% endif %} +
+ {% endif %} +
diff --git a/resources/views/yuuno/user/profile_javascript.twig b/resources/views/yuuno/user/profile_javascript.twig new file mode 100644 index 0000000..2d22639 --- /dev/null +++ b/resources/views/yuuno/user/profile_javascript.twig @@ -0,0 +1,127 @@ + diff --git a/resources/views/yuuno/user/profile_macros.twig b/resources/views/yuuno/user/profile_macros.twig new file mode 100644 index 0000000..ff95237 --- /dev/null +++ b/resources/views/yuuno/user/profile_macros.twig @@ -0,0 +1,8 @@ +{% macro profile_image_changer(url, query) %} +
+ + +
+{% endmacro %}