diff --git a/app/Controllers/Controller.php b/app/Controllers/Controller.php index 3d0c94a..193b0de 100644 --- a/app/Controllers/Controller.php +++ b/app/Controllers/Controller.php @@ -34,7 +34,7 @@ class Controller } } - public function json($object, $operators = JSON_FORCE_OBJECT | JSON_NUMERIC_CHECK | JSON_BIGINT_AS_STRING) + public function json($object, $operators = null) { header('Content-Type: application/json; charset=utf-8'); return json_encode($object, $operators); diff --git a/app/Notification.php b/app/Notification.php index 68d0387..d619324 100644 --- a/app/Notification.php +++ b/app/Notification.php @@ -36,15 +36,15 @@ class Notification if ($data) { $data = $data[0]; - $this->id = $data->alert_id; - $this->user = $data->user_id; - $this->time = $data->alert_timestamp; + $this->id = intval($data->alert_id); + $this->user = intval($data->user_id); + $this->time = intval($data->alert_timestamp); $this->read = intval($data->alert_read) !== 0; $this->title = $data->alert_title; $this->text = $data->alert_text; $this->link = $data->alert_link; $this->image = $data->alert_img; - $this->timeout = $data->alert_timeout; + $this->timeout = intval($data->alert_timeout); } } diff --git a/app/User.php b/app/User.php index 1b10f67..8b76ea7 100644 --- a/app/User.php +++ b/app/User.php @@ -214,13 +214,6 @@ class User */ public $youtube = ''; - /** - * The thing that indicates if it's an id or a name. - * - * @var int - */ - public $youtubeType = 0; - /** * The user's steam community username. * @@ -369,7 +362,6 @@ class User $this->skype = $userRow->user_skype; $this->discord = $userRow->user_discord; $this->youtube = $userRow->user_youtube; - $this->youtubeType = intval($userRow->user_youtube_type); $this->steam = $userRow->user_steam; $this->osu = $userRow->user_osu; $this->lastfm = $userRow->user_lastfm; @@ -1089,7 +1081,7 @@ class User $alerts = []; foreach ($alertIds as $alertId) { - $alerts[$alertId] = new Notification($alertId); + $alerts[] = new Notification($alertId); } return $alerts; diff --git a/database/2016_08_02_204141_move_options_and_profile_into_users.php b/database/2016_08_02_204141_move_options_and_profile_into_users.php index 183a60c..d74a1de 100644 --- a/database/2016_08_02_204141_move_options_and_profile_into_users.php +++ b/database/2016_08_02_204141_move_options_and_profile_into_users.php @@ -47,9 +47,6 @@ class MoveOptionsAndProfileIntoUsers extends Migration ->nullable() ->default(null); - $table->tinyInteger('user_youtube_type') - ->default(0); - $table->string('user_steam', 255) ->nullable() ->default(null); @@ -82,7 +79,6 @@ class MoveOptionsAndProfileIntoUsers extends Migration 'user_skype', 'user_discord', 'user_youtube', - 'user_youtube_type', 'user_steam', 'user_osu', 'user_lastfm', diff --git a/gulpfile.js b/gulpfile.js index 2a42e39..81372d1 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,9 +7,9 @@ elixir(function(mix) { mix .less('aitemu/master.less', 'public/css/aitemu.css') .less('yuuno/master.less', 'public/css/yuuno.css') - .typescript('app/**/*.ts', 'public/js/app.js') - .typescript('aitemu/**/*.ts', 'public/js/aitemu.js') - .typescript('yuuno/**/*.ts', 'public/js/yuuno.js') + .typescript('Sakura/**/*.ts', 'public/js/app.js') + .typescript('Aitemu/**/*.ts', 'public/js/aitemu.js') + .typescript('Yuuno/**/*.ts', 'public/js/yuuno.js') .scripts([ nodePath + 'turbolinks/dist/turbolinks.js', ], 'public/js/libraries.js'); diff --git a/resources/assets/typescript/app/AJAX.ts b/resources/assets/typescript/Sakura/AJAX.ts similarity index 100% rename from resources/assets/typescript/app/AJAX.ts rename to resources/assets/typescript/Sakura/AJAX.ts diff --git a/resources/assets/typescript/app/Changelog.ts b/resources/assets/typescript/Sakura/Changelog.ts similarity index 100% rename from resources/assets/typescript/app/Changelog.ts rename to resources/assets/typescript/Sakura/Changelog.ts diff --git a/resources/assets/typescript/app/Comments.ts b/resources/assets/typescript/Sakura/Comments.ts similarity index 100% rename from resources/assets/typescript/app/Comments.ts rename to resources/assets/typescript/Sakura/Comments.ts diff --git a/resources/assets/typescript/app/Config.ts b/resources/assets/typescript/Sakura/Config.ts similarity index 93% rename from resources/assets/typescript/app/Config.ts rename to resources/assets/typescript/Sakura/Config.ts index 6b25172..c46f610 100644 --- a/resources/assets/typescript/app/Config.ts +++ b/resources/assets/typescript/Sakura/Config.ts @@ -3,6 +3,7 @@ namespace Sakura export class Config { public static Revision: number = 0; + public static UserId: number = 0; public static SessionId: string = ""; public static UserNameMinLength: number = 3; public static UserNameMaxLength: number = 16; diff --git a/resources/assets/typescript/app/Cookies.ts b/resources/assets/typescript/Sakura/Cookies.ts similarity index 100% rename from resources/assets/typescript/app/Cookies.ts rename to resources/assets/typescript/Sakura/Cookies.ts diff --git a/resources/assets/typescript/app/DOM.ts b/resources/assets/typescript/Sakura/DOM.ts similarity index 100% rename from resources/assets/typescript/app/DOM.ts rename to resources/assets/typescript/Sakura/DOM.ts diff --git a/resources/assets/typescript/app/DOMSelector.ts b/resources/assets/typescript/Sakura/DOMSelector.ts similarity index 100% rename from resources/assets/typescript/app/DOMSelector.ts rename to resources/assets/typescript/Sakura/DOMSelector.ts diff --git a/resources/assets/typescript/app/Friend.ts b/resources/assets/typescript/Sakura/Friend.ts similarity index 100% rename from resources/assets/typescript/app/Friend.ts rename to resources/assets/typescript/Sakura/Friend.ts diff --git a/resources/assets/typescript/app/HTTPMethod.ts b/resources/assets/typescript/Sakura/HTTPMethod.ts similarity index 100% rename from resources/assets/typescript/app/HTTPMethod.ts rename to resources/assets/typescript/Sakura/HTTPMethod.ts diff --git a/resources/assets/typescript/app/IChangelogAction.ts b/resources/assets/typescript/Sakura/IChangelogAction.ts similarity index 100% rename from resources/assets/typescript/app/IChangelogAction.ts rename to resources/assets/typescript/Sakura/IChangelogAction.ts diff --git a/resources/assets/typescript/app/IChangelogChange.ts b/resources/assets/typescript/Sakura/IChangelogChange.ts similarity index 100% rename from resources/assets/typescript/app/IChangelogChange.ts rename to resources/assets/typescript/Sakura/IChangelogChange.ts diff --git a/resources/assets/typescript/app/IChangelogContributor.ts b/resources/assets/typescript/Sakura/IChangelogContributor.ts similarity index 100% rename from resources/assets/typescript/app/IChangelogContributor.ts rename to resources/assets/typescript/Sakura/IChangelogContributor.ts diff --git a/resources/assets/typescript/app/IChangelogDate.ts b/resources/assets/typescript/Sakura/IChangelogDate.ts similarity index 100% rename from resources/assets/typescript/app/IChangelogDate.ts rename to resources/assets/typescript/Sakura/IChangelogDate.ts diff --git a/resources/assets/typescript/app/IChangelogRelease.ts b/resources/assets/typescript/Sakura/IChangelogRelease.ts similarity index 100% rename from resources/assets/typescript/app/IChangelogRelease.ts rename to resources/assets/typescript/Sakura/IChangelogRelease.ts diff --git a/resources/assets/typescript/app/IFriendResponse.ts b/resources/assets/typescript/Sakura/IFriendResponse.ts similarity index 100% rename from resources/assets/typescript/app/IFriendResponse.ts rename to resources/assets/typescript/Sakura/IFriendResponse.ts diff --git a/resources/assets/typescript/Sakura/INotification.ts b/resources/assets/typescript/Sakura/INotification.ts new file mode 100644 index 0000000..61400d5 --- /dev/null +++ b/resources/assets/typescript/Sakura/INotification.ts @@ -0,0 +1,15 @@ +namespace Sakura +{ + export interface INotification + { + id: number; + user: number; + time: number; + read: boolean; + title: string; + text: string; + link: string; + image: string; + timeout: number; + } +} diff --git a/resources/assets/typescript/app/Legacy.ts b/resources/assets/typescript/Sakura/Legacy.ts similarity index 100% rename from resources/assets/typescript/app/Legacy.ts rename to resources/assets/typescript/Sakura/Legacy.ts diff --git a/resources/assets/typescript/app/Main.ts b/resources/assets/typescript/Sakura/Main.ts similarity index 89% rename from resources/assets/typescript/app/Main.ts rename to resources/assets/typescript/Sakura/Main.ts index 6add911..bc3fb17 100644 --- a/resources/assets/typescript/app/Main.ts +++ b/resources/assets/typescript/Sakura/Main.ts @@ -6,6 +6,7 @@ namespace Sakura console.log(this.Supported()); TimeAgo.Init(); Friend.Init(); + Notifications.Init(); } public static Supported(): boolean { diff --git a/resources/assets/typescript/Sakura/Notifications.ts b/resources/assets/typescript/Sakura/Notifications.ts new file mode 100644 index 0000000..bf8bd34 --- /dev/null +++ b/resources/assets/typescript/Sakura/Notifications.ts @@ -0,0 +1,51 @@ +namespace Sakura +{ + export class Notifications + { + private static Client: AJAX; + private static IntervalContainer: number; + public static DisplayMethod: Function = (alert: INotification) => { + console.log(alert); + }; + + public static Init(): void + { + this.Client = new AJAX; + this.Client.SetUrl("/notifications"); + this.Client.AddCallback(200, (client: AJAX) => { + Notifications.Load(client.JSON()); + }); + this.Poll(); + this.Start(); + } + + public static Poll(): void + { + this.Client.Start(HTTPMethod.GET); + } + + public static Start(): void + { + this.IntervalContainer = setInterval(() => { + if (document.hidden) { + return; + } + + Notifications.Poll(); + }, 5000); + } + + public static Stop(): void + { + this.Client.Stop(); + clearInterval(this.IntervalContainer); + } + + private static Load(alerts: INotification[]): void + { + for (var i in alerts) { + this.DisplayMethod(alerts[i]); + } + } + } +} diff --git a/resources/assets/typescript/app/TimeAgo.ts b/resources/assets/typescript/Sakura/TimeAgo.ts similarity index 100% rename from resources/assets/typescript/app/TimeAgo.ts rename to resources/assets/typescript/Sakura/TimeAgo.ts diff --git a/resources/assets/typescript/Yuuno/Notifications.ts b/resources/assets/typescript/Yuuno/Notifications.ts new file mode 100644 index 0000000..98f8e00 --- /dev/null +++ b/resources/assets/typescript/Yuuno/Notifications.ts @@ -0,0 +1,28 @@ +/// + +namespace Yuuno +{ + export class Notifications + { + private static Container; + + public static RegisterDisplay(): void + { + this.Container = new Sakura.DOM('notifications', Sakura.DOMSelector.ID); + Sakura.Notifications.DisplayMethod = this.Display; + } + + public static Display(alert: Sakura.INotification): void + { + var id = 'yuuno-alert-' + Date.now(), + container = Sakura.DOM.Create('div', 'notification-enter', id), + icon = Sakura.DOM.Create('div', 'notification-icon'), + inner = Sakura.DOM.Create('div', 'notification-content'), + title = Sakura.DOM.Create('div', 'notification-title'), + text = Sakura.DOM.Create('div', 'notification-text'), + close = Sakura.DOM.Create('div', 'notification-close'), + closeIcon = Sakura.DOM.Create('div'), + clear = Sakura.DOM.Create('div'); + } + } +} diff --git a/resources/assets/typescript/yuuno/Main.ts b/resources/assets/typescript/yuuno/Main.ts index d37f912..fadd7b5 100644 --- a/resources/assets/typescript/yuuno/Main.ts +++ b/resources/assets/typescript/yuuno/Main.ts @@ -5,6 +5,7 @@ namespace Yuuno public static Startup() { Sakura.Main.Startup(); + Notifications.RegisterDisplay(); } } } diff --git a/resources/assets/typescript/yuuno/yuuno.ts b/resources/assets/typescript/yuuno/yuuno.ts index d317652..0d35999 100644 --- a/resources/assets/typescript/yuuno/yuuno.ts +++ b/resources/assets/typescript/yuuno/yuuno.ts @@ -114,37 +114,6 @@ function notifyOpen(id: string): void { } } -// Request notifications -function notifyRequest(session: string): void { - // Check if the document isn't hidden - if (document.hidden) { - return; - } - - // Create AJAX object - var get = new Sakura.AJAX(); - get.SetUrl('/notifications'); - - // Add callbacks - get.AddCallback(200, () => { - // Assign the parsed JSON - var data: Notification = JSON.parse(get.Response()); - - // Check if nothing went wrong - if ((typeof data).toLowerCase() === 'undefined') { - // Inform the user - throw "No or invalid data was returned"; - } - - // Create an object for every notification - for (var id in data) { - notifyUI(data[id]); - } - }); - - get.Start(Sakura.HTTPMethod.GET); -} - // Show the full page busy window function ajaxBusyView(show: boolean, message: string = null, type: string = null): void { // Get elements diff --git a/resources/views/yuuno/auth/register.twig b/resources/views/yuuno/auth/register.twig index df42756..e4b61e8 100644 --- a/resources/views/yuuno/auth/register.twig +++ b/resources/views/yuuno/auth/register.twig @@ -39,9 +39,6 @@
-
diff --git a/resources/views/yuuno/master.twig b/resources/views/yuuno/master.twig index b6b2a78..a757e82 100644 --- a/resources/views/yuuno/master.twig +++ b/resources/views/yuuno/master.twig @@ -167,6 +167,7 @@ UserNameMaxLength: {{ config('user.name_max') }}, PasswordMinEntropy: {{ config('user.pass_min_entropy') }}, LoggedIn: {{ user.isActive ? 'true' : 'false' }}, + UserId: {{ user.id }}, SessionId: "{{ session_id() }}", }); @@ -175,12 +176,6 @@ {% if config('dev.show_changelog', true) and stats %} Sakura.Changelog.Build(new Sakura.DOM('indexPanel', Sakura.DOMSelector.ID)); {% endif %} - - notifyRequest(Sakura.Config.SessionId); - - setInterval(function() { - notifyRequest(Sakura.Config.SessionId); - }, 60000); diff --git a/resources/views/yuuno/user/profile.twig b/resources/views/yuuno/user/profile.twig index 5fda9a8..c6d4a09 100644 --- a/resources/views/yuuno/user/profile.twig +++ b/resources/views/yuuno/user/profile.twig @@ -4,9 +4,58 @@ {% set noUserpage = profile.userPage|length < 1 %} -{% set profileView = noUserpage and profileView == 'index' ? 'comments' : profileView %} +{% set title = profileHidden ? 'User not found!' : 'Profile of ' ~ profile.username %} -{% set title %}{% if profileHidden %}User not found!{% else %}Profile of {{ profile.username }}{% endif %}{% endset %} +{% set youtubeIsChannelId = profile.youtube|slice(0, 2) == 'UC' and profile.youtube|length == 24 %} + +{% set fields = { + "website": { + "title": "Website", + "value": profile.website, + "link": "%s", + }, + "twitter": { + "title": "Twitter", + "value": profile.twitter, + "link": "https://twitter.com/%s", + "disp": "@%s", + }, + "github": { + "title": "GitHub", + "value": profile.github, + "link": "https://github.com/%s", + }, + "skype": { + "title": "Skype", + "value": profile.skype, + "link": "skype:%s?userinfo", + }, + "discord": { + "title": "Discord", + "value": profile.discord, + }, + "youtube": { + "title": "YouTube", + "value": profile.youtube, + "link": "https://youtube.com/" ~ (youtubeIsChannelId ? 'channel/' : '') ~ "%s", + "disp": youtubeIsChannelId ? profile.username ~ "'s channel" : "%s", + }, + "steam": { + "title": "Steam", + "value": profile.steam, + "link": "https://steamcommunity.com/id/%s", + }, + "osu": { + "title": "osu!", + "value": profile.osu, + "link": "https://osu.ppy.sh/u/%s", + }, + "lastfm": { + "title": "Last.fm", + "value": profile.lastfm, + "link": "http://last.fm/user/%s", + }, +} %} {% block js %} {% if not profileHidden %} @@ -102,10 +151,9 @@ {% if not noUserpage %} {% endif %} - {# - #} + + - {##} {% if user.isActive %} @@ -164,25 +212,21 @@ {% if profile.profileFields or user.permission(constant('Sakura\\Perms\\Manage::USE_MANAGE'), constant('Sakura\\Perms::MANAGE')) %} {% if user.isActive %} - {% for name,field in profile.profileFields %} - - - + + - + + + {% endif %} {% endfor %} {% if user.permission(constant('Sakura\\Perms\\Manage::USE_MANAGE'), constant('Sakura\\Perms::MANAGE')) %} diff --git a/tsconfig.json b/tsconfig.json index d8eaf1f..94e259b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,9 +3,8 @@ "module": "commonjs", "noImplicitAny": false, "removeComments": true, - "preserveConstEnums": true - }, - "exclude": [ - "public" - ] + "preserveConstEnums": true, + "moduleResolution": "node", + "rootDir": "resources/assets/typescript" + } }
- {{ field.name }} - - {% if name == 'youtube' %} - {% if field.youtubetype == true %}{{ profile.username }}'s Channel{% else %}{{ field.value }}{% endif %} - {% else %} - {% if field.islink %} - + {% for id, data in fields %} + {% if data.value != null %} +
+ {{ data.title }} + + {% if data.link %} + {{ (data.disp ? data.disp : '%s')|format(data.value) }} + {% else %} + {{ (data.disp ? data.disp : '%s')|format(data.value) }} {% endif %} - {{ field.value }} - {% if field.islink %} - - {% endif %} - {% endif %} -