Compare commits
45 commits
Author | SHA1 | Date | |
---|---|---|---|
flash | 5d3e1d4960 | ||
flash | 9bb943bacf | ||
flash | 107d16cf46 | ||
flash | 0afc5186a7 | ||
flash | 0300bae994 | ||
flash | cb0c64f8ed | ||
flash | 89ef9d9ad1 | ||
flash | c02d922dc6 | ||
flash | 80cd6222c4 | ||
flash | 344a3c9160 | ||
flash | df5dbdf3ad | ||
flash | c0caceed7b | ||
flash | be54ce2c22 | ||
flash | 070dc5e782 | ||
flash | b89621cb1a | ||
flash | 760cca0e5d | ||
flash | fe77f1616c | ||
flash | eb81ed7a82 | ||
flash | 8ef11afe02 | ||
flash | cca016ba10 | ||
flash | b80151583e | ||
flash | d8cc208a85 | ||
flash | 4b2f9a2fec | ||
flash | ddb255bf32 | ||
flash | 5a70e3f3f1 | ||
flash | bd3e055323 | ||
flash | dba5754ccc | ||
flash | ec6ba3f781 | ||
flash | 70ec285f99 | ||
flash | 77eadd5bde | ||
flash | f0fc735975 | ||
flash | adb80bad9e | ||
flash | f30cf41f86 | ||
flash | b4f5dd0660 | ||
flash | 133e2f420c | ||
flash | bf65c95490 | ||
flash | 7ef5994da4 | ||
flash | 2b34bde413 | ||
flash | 432615508d | ||
flash | a4cc14e4c1 | ||
flash | 65e695e9d9 | ||
flash | 2e6a84b46d | ||
flash | 8f56174637 | ||
flash | 19fbe59ddd | ||
flash | f7a571e551 |
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -45,3 +45,7 @@
|
|||
|
||||
# Google
|
||||
/public/robots.txt
|
||||
|
||||
# moguu?
|
||||
/public/moguu.swf
|
||||
/public/moguu.html
|
||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,4 +1,4 @@
|
|||
Copyright (c) 2017-2023, flashwave <me@flash.moe>
|
||||
Copyright (c) 2017-2024, flashwave <me@flash.moe>
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -17,15 +17,10 @@ exports.process = async function(root, options) {
|
|||
return '';
|
||||
included.push(fullPath);
|
||||
|
||||
if(!fullPath.startsWith(root)) {
|
||||
console.error('INVALID PATH: ' + fullPath);
|
||||
if(!fullPath.startsWith(root))
|
||||
return '/* *** INVALID PATH: ' + fullPath + ' */';
|
||||
}
|
||||
|
||||
if(!fs.existsSync(fullPath)) {
|
||||
console.error('FILE NOT FOUND: ' + fullPath);
|
||||
if(!fs.existsSync(fullPath))
|
||||
return '/* *** FILE NOT FOUND: ' + fullPath + ' */';
|
||||
}
|
||||
|
||||
const lines = readline.createInterface({
|
||||
input: fs.createReadStream(fullPath),
|
||||
|
@ -58,6 +53,19 @@ exports.process = async function(root, options) {
|
|||
break;
|
||||
}
|
||||
|
||||
case 'buildvars':
|
||||
if(typeof options.buildVars === 'object') {
|
||||
const bvTarget = options.buildVarsTarget || 'window';
|
||||
const bvProps = [];
|
||||
|
||||
for(const bvName in options.buildVars)
|
||||
bvProps.push(`${bvName}: { value: ${JSON.stringify(options.buildVars[bvName])}, writable: false }`);
|
||||
|
||||
if(Object.keys(bvProps).length > 0)
|
||||
output += `Object.defineProperties(${bvTarget}, { ${bvProps.join(', ')} });\n`;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
output += line;
|
||||
output += "\n";
|
||||
|
@ -84,7 +92,7 @@ exports.housekeep = function(assetsPath) {
|
|||
};
|
||||
}).sort((a, b) => b.lastMod - a.lastMod).map(info => info.name);
|
||||
|
||||
const regex = /^(.+)-([a-f0-9]+)\.(.+)$/i;
|
||||
const regex = /^(.+)[\-\.]([a-f0-9]+)\.(.+)$/i;
|
||||
const counts = {};
|
||||
|
||||
for(const fileName of files) {
|
||||
|
|
|
@ -154,6 +154,9 @@
|
|||
}
|
||||
|
||||
.forum__post__action {
|
||||
background-color: transparent;
|
||||
border: 0;
|
||||
display: block;
|
||||
padding: 5px 10px;
|
||||
margin: 1px;
|
||||
color: inherit;
|
||||
|
|
|
@ -146,9 +146,14 @@
|
|||
}
|
||||
.header__desktop__user__button__count {
|
||||
position: absolute;
|
||||
bottom: 1px;
|
||||
right: 1px;
|
||||
font-size: 10px;
|
||||
top: -5px;
|
||||
right: -3px;
|
||||
z-index: 1;
|
||||
font-size: .5em;
|
||||
line-height: 1.4em;
|
||||
text-align: right;
|
||||
padding: 2px 2px 0;
|
||||
border-radius: 4px;
|
||||
background-color: var(--header-accent-colour);
|
||||
opacity: .9;
|
||||
border-radius: 4px;
|
||||
|
|
92
assets/misuzu.css/hljs.css
Normal file
92
assets/misuzu.css/hljs.css
Normal file
|
@ -0,0 +1,92 @@
|
|||
pre code.hljs {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
padding: 1em;
|
||||
font-size: 1.2em;
|
||||
font-family: var(--font-monospace);
|
||||
}
|
||||
|
||||
code.hljs {
|
||||
padding: 2px 5px;
|
||||
}
|
||||
|
||||
.hljs {
|
||||
color: #eee;
|
||||
background: #121212;
|
||||
}
|
||||
|
||||
.hljs-strong,
|
||||
.hljs-emphasis,
|
||||
.hljs-section {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.hljs-bullet,
|
||||
.hljs-quote,
|
||||
.hljs-number,
|
||||
.hljs-regexp,
|
||||
.hljs-literal {
|
||||
color: #b2b376;
|
||||
}
|
||||
|
||||
.hljs-code {
|
||||
background-color: #242424;
|
||||
}
|
||||
|
||||
.hljs-comment,
|
||||
.hljs-meta,
|
||||
.hljs-emphasis,
|
||||
.hljs-stronge,
|
||||
.hljs-type,
|
||||
.hljs-attribute,
|
||||
.hljs-params {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.hljs-keyword,
|
||||
.hljs-selector-tag,
|
||||
.hljs-section,
|
||||
.hljs-symbol,
|
||||
.hljs-name {
|
||||
color: #9475b2;
|
||||
}
|
||||
|
||||
.hljs-built_in,
|
||||
.hljs-subst,
|
||||
.hljs-tag,
|
||||
.hljs-title,
|
||||
.hljs-selector-attr {
|
||||
color: #c8b9d7;
|
||||
}
|
||||
|
||||
.hljs-variable,
|
||||
.hljs-class .hljs-title,
|
||||
.hljs-selector-class,
|
||||
.hljs-selector-id,
|
||||
.hljs-selector-pseudo {
|
||||
color: #b37fae;
|
||||
}
|
||||
|
||||
.hljs-string {
|
||||
color: #76b38a;
|
||||
}
|
||||
|
||||
.hljs-type,
|
||||
.hljs-template-tag,
|
||||
.hljs-template-variable,
|
||||
.hljs-link {
|
||||
color: #b39a76;
|
||||
}
|
||||
|
||||
.hljs-comment,
|
||||
.hljs-meta {
|
||||
color: #70647b;
|
||||
}
|
||||
|
||||
.hljs-addition {
|
||||
background: #0e4d0e;
|
||||
}
|
||||
|
||||
.hljs-deletion {
|
||||
background: #4d0e0e;
|
||||
}
|
|
@ -3,7 +3,6 @@
|
|||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
position: relative;
|
||||
outline-style: none;
|
||||
}
|
||||
|
||||
html,
|
||||
|
@ -53,13 +52,12 @@ body {
|
|||
--user-header: url('/images/pixel.png');
|
||||
--accent-colour: #8559a5;
|
||||
--header-accent-colour: var(--accent-colour);
|
||||
|
||||
--accent-colour: #ff9600;
|
||||
--site-logo: url('/images/logos/imouto-halloween.png');
|
||||
}
|
||||
|
||||
html {
|
||||
scrollbar-color: var(--accent-colour) var(--background-colour);
|
||||
accent-color: var(--accent-colour);
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
.main {
|
||||
|
@ -120,6 +118,8 @@ html {
|
|||
@include permissions.css;
|
||||
@include warning.css;
|
||||
|
||||
@include hljs.css;
|
||||
|
||||
@include _input/button.css;
|
||||
@include _input/checkbox.css;
|
||||
@include _input/colour.css;
|
||||
|
@ -164,6 +164,8 @@ html {
|
|||
|
||||
@include manage/_manage.css;
|
||||
|
||||
@include messages/messages.css;
|
||||
|
||||
@include news/container.css;
|
||||
@include news/feeds.css;
|
||||
@include news/list.css;
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
.markdown code {
|
||||
padding: .2em .4em;
|
||||
margin: 0;
|
||||
background-color: rgba(0, 0, 0, .7);
|
||||
border-radius: 2px;
|
||||
}
|
||||
.markdown del code { text-decoration: inherit; }
|
||||
|
@ -65,7 +64,6 @@
|
|||
overflow: hidden;
|
||||
line-height: inherit;
|
||||
word-wrap: break-word;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,4 +17,5 @@
|
|||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 5px;
|
||||
gap: 5px;
|
||||
}
|
||||
|
|
37
assets/misuzu.css/messages/actions.css
Normal file
37
assets/misuzu.css/messages/actions.css
Normal file
|
@ -0,0 +1,37 @@
|
|||
.messages-actions-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 30px;
|
||||
margin: 1px;
|
||||
font-size: 1.3em;
|
||||
line-height: 1.4em;
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
transition: background-color .1s;
|
||||
width: 100%;
|
||||
border: 0;
|
||||
background-color: inherit;
|
||||
text-align: left;
|
||||
}
|
||||
.messages-actions-item:hover,
|
||||
.messages-actions-item:focus {
|
||||
background-color: #444f;
|
||||
}
|
||||
.messages-actions-item:active,
|
||||
.messages-actions-item-current {
|
||||
background-color: var(--accent-colour) !important;
|
||||
}
|
||||
.messages-actions-item[disabled] {
|
||||
background-color: inherit !important;
|
||||
opacity: .4;
|
||||
}
|
||||
.messages-actions-item-icon {
|
||||
text-align: center;
|
||||
width: 30px;
|
||||
flex-grow: 0;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.messages-actions-item-label {
|
||||
flex-grow: 1;
|
||||
flex-shrink: 1;
|
||||
}
|
26
assets/misuzu.css/messages/columns.css
Normal file
26
assets/misuzu.css/messages/columns.css
Normal file
|
@ -0,0 +1,26 @@
|
|||
.messages-columns {
|
||||
display: flex;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.messages-columns-sidebar {
|
||||
width: 200px;
|
||||
flex-shrink: 0;
|
||||
flex-grow: 0;
|
||||
}
|
||||
|
||||
.messages-columns-content {
|
||||
flex-shrink: 1;
|
||||
flex-grow: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
@media (max-width: 800px) {
|
||||
.messages-columns {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.messages-columns-sidebar {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
80
assets/misuzu.css/messages/entry.css
Normal file
80
assets/misuzu.css/messages/entry.css
Normal file
|
@ -0,0 +1,80 @@
|
|||
.messages-entry {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 2px 4px;
|
||||
gap: 4px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
}
|
||||
.messages-entry-header {
|
||||
display: flex;
|
||||
font-size: 1.1em;
|
||||
line-height: 1.6em;
|
||||
border-bottom: 2px solid #9999;
|
||||
gap: 2px;
|
||||
}
|
||||
.messages-entry-check {
|
||||
flex-grow: 0;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 20px;
|
||||
}
|
||||
.messages-entry-check input {
|
||||
display: block;
|
||||
}
|
||||
.messages-entry-unread {
|
||||
flex-grow: 0;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 20px;
|
||||
}
|
||||
.messages-entry-unread-orb {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
background-color: var(--accent-colour);
|
||||
border-radius: 100%;
|
||||
}
|
||||
.messages-entry-author {
|
||||
font-weight: bold;
|
||||
border-bottom: 2px solid var(--user-colour, currentColor);
|
||||
margin: 0 0 -2px;
|
||||
flex-grow: 0;
|
||||
flex-shrink: 1;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.messages-entry-spacing {
|
||||
flex-grow: 1;
|
||||
flex-shrink: 1;
|
||||
}
|
||||
.messages-entry-datetime {
|
||||
flex-grow: 0;
|
||||
flex-shrink: 0;
|
||||
color: #aaa;
|
||||
align-self: flex-end;
|
||||
}
|
||||
.messages-entry-subject {
|
||||
line-height: 1.4em;
|
||||
color: #fff;
|
||||
overflow: hidden;
|
||||
}
|
||||
.messages-entry-preview {
|
||||
line-height: 1.4em;
|
||||
color: #888;
|
||||
overflow: hidden;
|
||||
}
|
||||
.messages-entry-preview .messages-entry-overflow {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
.messages-entry-overflow {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
33
assets/misuzu.css/messages/folder.css
Normal file
33
assets/misuzu.css/messages/folder.css
Normal file
|
@ -0,0 +1,33 @@
|
|||
.messages-folder {
|
||||
margin: 1px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1px;
|
||||
padding: 1px;
|
||||
}
|
||||
.messages-folder-item {
|
||||
background-color: #161616;
|
||||
transition: background-color .1s;
|
||||
}
|
||||
.messages-folder-item:nth-child(2n) {
|
||||
background-color: #1f1f1f;
|
||||
}
|
||||
.messages-folder-item:hover,
|
||||
.messages-folder-item:focus {
|
||||
background-color: #262626;
|
||||
}
|
||||
.messages-folder-item:active,
|
||||
.messages-folder-item-current {
|
||||
background-color: var(--accent-colour) !important;
|
||||
}
|
||||
.messages-folder-notice {
|
||||
text-align: center;
|
||||
margin: 10px;
|
||||
}
|
||||
.messages-folder-notice-text {
|
||||
font-size: 1.4em;
|
||||
line-height: 1.5em;
|
||||
}
|
||||
.messages-folder .pagination {
|
||||
margin-top: 2px;
|
||||
}
|
135
assets/misuzu.css/messages/message.css
Normal file
135
assets/misuzu.css/messages/message.css
Normal file
|
@ -0,0 +1,135 @@
|
|||
.messages-message {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
padding: 10px;
|
||||
}
|
||||
.messages-message-snippet {
|
||||
cursor: pointer;
|
||||
font-size: .9em;
|
||||
line-height: 1.5em;
|
||||
color: #888;
|
||||
gap: 5px;
|
||||
opacity: .8;
|
||||
transition: opacity .1s;
|
||||
}
|
||||
.messages-message-snippet:hover,
|
||||
.messages-message-snippet:focus,
|
||||
.messages-message-snippet:focus-within {
|
||||
opacity: 1;
|
||||
}
|
||||
.messages-message-draft {
|
||||
border-top: 2px solid var(--accent-colour) !important;
|
||||
border-left: 2px solid var(--accent-colour) !important;
|
||||
border-right: 2px solid var(--accent-colour);
|
||||
border-bottom: 2px solid var(--accent-colour);
|
||||
}
|
||||
.messages-message-deleted {
|
||||
border-top: 2px solid red;
|
||||
border-left: 2px solid red;
|
||||
border-right: 2px solid red !important;
|
||||
border-bottom: 2px solid red !important;
|
||||
}
|
||||
|
||||
.messages-message-overflow {
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.messages-message-header {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
border-bottom: 1px #444 solid;
|
||||
padding-bottom: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.messages-message-sender-avatar {
|
||||
flex-shrink: 0;
|
||||
flex-grow: 0;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
.messages-message-sender-avatar img {
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.messages-message-details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-shrink: 1;
|
||||
flex-grow: 1;
|
||||
overflow: hidden;
|
||||
gap: 2px;
|
||||
}
|
||||
.messages-message-details-spacing {
|
||||
flex-grow: 1;
|
||||
flex-shrink: 1;
|
||||
}
|
||||
|
||||
.messages-message-header-columns {
|
||||
display: flex;
|
||||
gap: 2px;
|
||||
}
|
||||
.messages-message-sender-name {
|
||||
flex-grow: 0;
|
||||
flex-shrink: 1;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.messages-message-sender-name a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
font-weight: 700;
|
||||
border-bottom: 2px solid var(--user-colour, currentColor);
|
||||
}
|
||||
.messages-message-datetime {
|
||||
flex-shrink: 0;
|
||||
flex-grow: 0;
|
||||
align-self: flex-end;
|
||||
padding-bottom: 2px;
|
||||
}
|
||||
|
||||
.messages-message-addressee {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
}
|
||||
.messages-message-addressee-to {
|
||||
flex-shrink: 0;
|
||||
flex-grow: 0;
|
||||
}
|
||||
.messages-message-addressee-user {
|
||||
flex-shrink: 1;
|
||||
flex-grow: 0;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.messages-message-addressee-user a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
font-weight: 700;
|
||||
border-bottom: 2px solid var(--user-colour, currentColor);
|
||||
}
|
||||
|
||||
.messages-message-subject {
|
||||
line-height: 2em;
|
||||
}
|
||||
|
||||
.messages-message-body {
|
||||
line-height: 1.4em;
|
||||
}
|
||||
.messages-message-body p:first-child {
|
||||
margin-top: 0 !important;
|
||||
}
|
||||
.messages-message-body p:last-child {
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.messages-message-snippet-body {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
line-height: 1.4em;
|
||||
}
|
9
assets/misuzu.css/messages/messages.css
Normal file
9
assets/misuzu.css/messages/messages.css
Normal file
|
@ -0,0 +1,9 @@
|
|||
@include messages/actions.css;
|
||||
@include messages/columns.css;
|
||||
@include messages/entry.css;
|
||||
@include messages/folder.css;
|
||||
@include messages/message.css;
|
||||
@include messages/recipient.css;
|
||||
@include messages/reply.css;
|
||||
@include messages/sidebar.css;
|
||||
@include messages/thread.css;
|
17
assets/misuzu.css/messages/recipient.css
Normal file
17
assets/misuzu.css/messages/recipient.css
Normal file
|
@ -0,0 +1,17 @@
|
|||
.messages-recipient {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.messages-recipient-avatar {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.messages-recipient-name {
|
||||
padding: 5px;
|
||||
}
|
||||
.messages-recipient-name-input {
|
||||
width: 100%;
|
||||
}
|
52
assets/misuzu.css/messages/reply.css
Normal file
52
assets/misuzu.css/messages/reply.css
Normal file
|
@ -0,0 +1,52 @@
|
|||
.messages-reply-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
gap: 5px;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.messages-reply-subject-input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.messages-reply-body-input {
|
||||
min-width: 100%;
|
||||
max-width: 100%;
|
||||
min-height: 100px;
|
||||
}
|
||||
.messages-reply-compose .messages-reply-body-input {
|
||||
min-height: 300px;
|
||||
}
|
||||
|
||||
.messages-reply-actions {
|
||||
display: flex;
|
||||
padding: 1px;
|
||||
gap: 1px;
|
||||
}
|
||||
.messages-reply-action {
|
||||
background-color: transparent;
|
||||
border: 0;
|
||||
display: block;
|
||||
padding: 5px 10px;
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
transition: background-color .2s;
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.messages-reply-action:hover,
|
||||
.messages-reply-action:focus {
|
||||
background-color: rgba(0, 0, 0, .2);
|
||||
}
|
||||
|
||||
.messages-reply-options {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.messages-reply-settings {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
11
assets/misuzu.css/messages/sidebar.css
Normal file
11
assets/misuzu.css/messages/sidebar.css
Normal file
|
@ -0,0 +1,11 @@
|
|||
.messages-sidebar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
.messages-sidebar-button {
|
||||
text-align: center;
|
||||
padding: 10px;
|
||||
}
|
5
assets/misuzu.css/messages/thread.css
Normal file
5
assets/misuzu.css/messages/thread.css
Normal file
|
@ -0,0 +1,5 @@
|
|||
.messages-thread {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1px;
|
||||
}
|
40
assets/misuzu.js/csrfp.js
Normal file
40
assets/misuzu.js/csrfp.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
#include utility.js
|
||||
|
||||
const MszCSRFP = (() => {
|
||||
let elem;
|
||||
const getElement = () => {
|
||||
if(elem === undefined)
|
||||
elem = $q('meta[name="csrfp-token"]');
|
||||
return elem;
|
||||
};
|
||||
|
||||
const getToken = () => {
|
||||
const elem = getElement();
|
||||
return typeof elem.content === 'string' ? elem.content : '';
|
||||
};
|
||||
|
||||
const setToken = token => {
|
||||
if(typeof token !== 'string')
|
||||
throw 'token must be a string';
|
||||
|
||||
const elem = getElement();
|
||||
if(typeof elem.content === 'string')
|
||||
elem.content = token;
|
||||
};
|
||||
|
||||
return {
|
||||
getToken: getToken,
|
||||
setToken: setToken,
|
||||
setFromHeaders: result => {
|
||||
if(typeof result.headers !== 'function')
|
||||
throw 'result.headers is not a function';
|
||||
|
||||
const headers = result.headers();
|
||||
if(!(headers instanceof Map))
|
||||
throw 'result of result.headers does not return a map';
|
||||
|
||||
if(headers.has('x-csrfp-token'))
|
||||
setToken(headers.get('x-csrfp-token'));
|
||||
},
|
||||
};
|
||||
})();
|
|
@ -1,128 +0,0 @@
|
|||
#include utils.js
|
||||
#include uiharu.js
|
||||
#include aembed.js
|
||||
#include iembed.js
|
||||
#include vembed.js
|
||||
|
||||
var MszEmbed = (function() {
|
||||
let uiharu = undefined;
|
||||
|
||||
return {
|
||||
init: function(endPoint) {
|
||||
uiharu = new Uiharu(endPoint);
|
||||
},
|
||||
handle: function(targets) {
|
||||
if(!Array.isArray(targets))
|
||||
targets = Array.from(targets);
|
||||
|
||||
const filtered = new Map;
|
||||
for(const target of targets) {
|
||||
if(!(target instanceof HTMLElement)
|
||||
|| !('dataset' in target)
|
||||
|| !('mszEmbedUrl' in target.dataset))
|
||||
continue;
|
||||
|
||||
const cleanUrl = target.dataset.mszEmbedUrl.replace(/ /, '%20');
|
||||
if(cleanUrl.indexOf('https://') !== 0
|
||||
&& cleanUrl.indexOf('http://') !== 0
|
||||
&& cleanUrl.indexOf('//') !== 0) {
|
||||
target.textContent = target.dataset.mszEmbedUrl;
|
||||
continue;
|
||||
}
|
||||
|
||||
$rc(target);
|
||||
target.appendChild($e({
|
||||
tag: 'i',
|
||||
attrs: {
|
||||
className: 'fas fa-2x fa-spinner fa-pulse',
|
||||
style: {
|
||||
width: '32px',
|
||||
height: '32px',
|
||||
lineHeight: '32px',
|
||||
textAlign: 'center',
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
if(filtered.has(cleanUrl))
|
||||
filtered.get(cleanUrl).push(target);
|
||||
else
|
||||
filtered.set(cleanUrl, [target]);
|
||||
}
|
||||
|
||||
const replaceWithUrl = function(targets, url) {
|
||||
for(const target of targets) {
|
||||
let body = $e({
|
||||
tag: 'a',
|
||||
attrs: {
|
||||
className: 'link',
|
||||
href: url,
|
||||
target: '_blank',
|
||||
rel: 'noopener noreferrer',
|
||||
},
|
||||
child: url
|
||||
});
|
||||
$ib(target, body);
|
||||
$r(target);
|
||||
}
|
||||
};
|
||||
|
||||
filtered.forEach(function(targets, url) {
|
||||
uiharu.lookupOne(url, function(metadata) {
|
||||
if(metadata.error) {
|
||||
replaceWithUrl(targets, url);
|
||||
console.error(metadata.error);
|
||||
return;
|
||||
}
|
||||
|
||||
if(metadata.title === undefined) {
|
||||
replaceWithUrl(targets, url);
|
||||
console.warn('Media is no longer available.');
|
||||
return;
|
||||
}
|
||||
|
||||
let phc = undefined,
|
||||
options = {
|
||||
onembed: console.log,
|
||||
};
|
||||
|
||||
if(metadata.type === 'youtube:video') {
|
||||
phc = MszVideoEmbedPlaceholder;
|
||||
options.type = 'youtube';
|
||||
options.player = MszVideoEmbedYouTube;
|
||||
} else if(metadata.type === 'niconico:video') {
|
||||
phc = MszVideoEmbedPlaceholder;
|
||||
options.type = 'nicovideo';
|
||||
options.player = MszVideoEmbedNicoNico;
|
||||
} else if(metadata.is_video) {
|
||||
phc = MszVideoEmbedPlaceholder;
|
||||
options.type = 'external';
|
||||
options.player = MszVideoEmbedPlayer;
|
||||
//options.frame = MszVideoEmbedFrame;
|
||||
options.nativeControls = true;
|
||||
options.autosize = false;
|
||||
options.maxWidth = 640;
|
||||
options.maxHeight = 360;
|
||||
} else if(metadata.is_audio) {
|
||||
phc = MszAudioEmbedPlaceholder;
|
||||
options.type = 'external';
|
||||
options.player = MszAudioEmbedPlayer;
|
||||
options.nativeControls = true;
|
||||
} else if(metadata.is_image) {
|
||||
phc = MszImageEmbed;
|
||||
options.type = 'external';
|
||||
}
|
||||
|
||||
if(phc === undefined)
|
||||
return;
|
||||
|
||||
for(const target of targets) {
|
||||
const placeholder = new phc(metadata, options, target);
|
||||
if(placeholder !== undefined)
|
||||
placeholder.replaceElement(target);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
})();
|
|
@ -1,4 +1,4 @@
|
|||
#include utils.js
|
||||
#include utility.js
|
||||
#include watcher.js
|
||||
|
||||
const MszAudioEmbedPlayerEvents = function() {
|
||||
|
@ -56,7 +56,7 @@ const MszAudioEmbedPlayer = function(metadata, options) {
|
|||
if(haveNativeControls)
|
||||
playerAttrs.controls = 'controls';
|
||||
|
||||
const watchers = new MszWatcherCollection;
|
||||
const watchers = new MszWatchers;
|
||||
watchers.define(MszAudioEmbedPlayerEvents());
|
||||
|
||||
const player = $e({
|
||||
|
@ -84,7 +84,8 @@ const MszAudioEmbedPlayer = function(metadata, options) {
|
|||
getType: function() { return 'external'; },
|
||||
};
|
||||
|
||||
watchers.proxy(pub);
|
||||
pub.watch = (name, handler) => watchers.watch(name, handler);
|
||||
pub.unwatch = (name, handler) => watchers.unwatch(name, handler);
|
||||
|
||||
player.addEventListener('play', function() { watchers.call('play', pub); });
|
||||
|
135
assets/misuzu.js/embed/embed.js
Normal file
135
assets/misuzu.js/embed/embed.js
Normal file
|
@ -0,0 +1,135 @@
|
|||
#include utility.js
|
||||
#include embed/audio.js
|
||||
#include embed/image.js
|
||||
#include embed/video.js
|
||||
#include ext/uiharu.js
|
||||
|
||||
const MszEmbed = (function() {
|
||||
let uiharu = undefined;
|
||||
|
||||
return {
|
||||
init: function(endPoint) {
|
||||
uiharu = new MszUiharu(endPoint);
|
||||
},
|
||||
handle: function(targets) {
|
||||
if(!Array.isArray(targets))
|
||||
targets = Array.from(targets);
|
||||
|
||||
const filtered = new Map;
|
||||
for(const target of targets) {
|
||||
if(!(target instanceof HTMLElement)
|
||||
|| !('dataset' in target)
|
||||
|| !('mszEmbedUrl' in target.dataset))
|
||||
continue;
|
||||
|
||||
const cleanUrl = target.dataset.mszEmbedUrl.replace(/ /, '%20');
|
||||
if(cleanUrl.indexOf('https://') !== 0
|
||||
&& cleanUrl.indexOf('http://') !== 0
|
||||
&& cleanUrl.indexOf('//') !== 0) {
|
||||
target.textContent = target.dataset.mszEmbedUrl;
|
||||
continue;
|
||||
}
|
||||
|
||||
$rc(target);
|
||||
target.appendChild($e({
|
||||
tag: 'i',
|
||||
attrs: {
|
||||
className: 'fas fa-2x fa-spinner fa-pulse',
|
||||
style: {
|
||||
width: '32px',
|
||||
height: '32px',
|
||||
lineHeight: '32px',
|
||||
textAlign: 'center',
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
if(filtered.has(cleanUrl))
|
||||
filtered.get(cleanUrl).push(target);
|
||||
else
|
||||
filtered.set(cleanUrl, [target]);
|
||||
}
|
||||
|
||||
const replaceWithUrl = function(targets, url) {
|
||||
for(const target of targets) {
|
||||
let body = $e({
|
||||
tag: 'a',
|
||||
attrs: {
|
||||
className: 'link',
|
||||
href: url,
|
||||
target: '_blank',
|
||||
rel: 'noopener noreferrer',
|
||||
},
|
||||
child: url
|
||||
});
|
||||
$ib(target, body);
|
||||
$r(target);
|
||||
}
|
||||
};
|
||||
|
||||
filtered.forEach(function(targets, url) {
|
||||
uiharu.lookupOne(url)
|
||||
.catch(ex => {
|
||||
replaceWithUrl(targets, url);
|
||||
console.error(ex);
|
||||
})
|
||||
.then(result => {
|
||||
const metadata = result.body();
|
||||
|
||||
if(metadata.error) {
|
||||
replaceWithUrl(targets, url);
|
||||
console.error(metadata.error);
|
||||
return;
|
||||
}
|
||||
|
||||
if(metadata.title === undefined) {
|
||||
replaceWithUrl(targets, url);
|
||||
console.warn('Media is no longer available.');
|
||||
return;
|
||||
}
|
||||
|
||||
let phc = undefined,
|
||||
options = {
|
||||
onembed: console.log,
|
||||
};
|
||||
|
||||
if(metadata.type === 'youtube:video') {
|
||||
phc = MszVideoEmbedPlaceholder;
|
||||
options.type = 'youtube';
|
||||
options.player = MszVideoEmbedYouTube;
|
||||
} else if(metadata.type === 'niconico:video') {
|
||||
phc = MszVideoEmbedPlaceholder;
|
||||
options.type = 'nicovideo';
|
||||
options.player = MszVideoEmbedNicoNico;
|
||||
} else if(metadata.is_video) {
|
||||
phc = MszVideoEmbedPlaceholder;
|
||||
options.type = 'external';
|
||||
options.player = MszVideoEmbedPlayer;
|
||||
//options.frame = MszVideoEmbedFrame;
|
||||
options.nativeControls = true;
|
||||
options.autosize = false;
|
||||
options.maxWidth = 640;
|
||||
options.maxHeight = 360;
|
||||
} else if(metadata.is_audio) {
|
||||
phc = MszAudioEmbedPlaceholder;
|
||||
options.type = 'external';
|
||||
options.player = MszAudioEmbedPlayer;
|
||||
options.nativeControls = true;
|
||||
} else if(metadata.is_image) {
|
||||
phc = MszImageEmbed;
|
||||
options.type = 'external';
|
||||
}
|
||||
|
||||
if(phc === undefined)
|
||||
return;
|
||||
|
||||
for(const target of targets) {
|
||||
const placeholder = new phc(metadata, options, target);
|
||||
if(placeholder !== undefined)
|
||||
placeholder.replaceElement(target);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
})();
|
|
@ -1,4 +1,4 @@
|
|||
#include utils.js
|
||||
#include utility.js
|
||||
|
||||
const MszImageEmbed = function(metadata, options, target) {
|
||||
options = options || {};
|
|
@ -1,5 +1,5 @@
|
|||
#include utils.js
|
||||
#include rng.js
|
||||
#include utility.js
|
||||
#include uniqstr.js
|
||||
#include watcher.js
|
||||
|
||||
const MszVideoEmbedPlayerEvents = function() {
|
||||
|
@ -229,7 +229,7 @@ const MszVideoEmbedPlayer = function(metadata, options) {
|
|||
videoAttrs.style.width = initialSize[0].toString() + 'px';
|
||||
videoAttrs.style.height = initialSize[1].toString() + 'px';
|
||||
|
||||
const watchers = new MszWatcherCollection;
|
||||
const watchers = new MszWatchers;
|
||||
watchers.define(MszVideoEmbedPlayerEvents());
|
||||
|
||||
const player = $e({
|
||||
|
@ -265,12 +265,13 @@ const MszVideoEmbedPlayer = function(metadata, options) {
|
|||
getHeight: function() { return height; },
|
||||
};
|
||||
|
||||
watchers.proxy(pub);
|
||||
pub.watch = (name, handler) => watchers.watch(name, handler);
|
||||
pub.unwatch = (name, handler) => watchers.unwatch(name, handler);
|
||||
|
||||
if(shouldObserveResize)
|
||||
player.addEventListener('resize', function() { setSize(player.videoWidth, player.videoHeight); });
|
||||
|
||||
player.addEventListener('play', function() { watchers.call('play', pub); });
|
||||
player.addEventListener('play', function() { watchers.call('play'); });
|
||||
|
||||
const pPlay = function() { player.play(); };
|
||||
pub.play = pPlay;
|
||||
|
@ -280,7 +281,7 @@ const MszVideoEmbedPlayer = function(metadata, options) {
|
|||
|
||||
let stopCalled = false;
|
||||
player.addEventListener('pause', function() {
|
||||
watchers.call(stopCalled ? 'stop' : 'pause', pub);
|
||||
watchers.call(stopCalled ? 'stop' : 'pause');
|
||||
stopCalled = false;
|
||||
});
|
||||
|
||||
|
@ -301,9 +302,9 @@ const MszVideoEmbedPlayer = function(metadata, options) {
|
|||
player.addEventListener('volumechange', function() {
|
||||
if(lastMuteState !== player.muted) {
|
||||
lastMuteState = player.muted;
|
||||
watchers.call('mute', pub, [lastMuteState]);
|
||||
watchers.call('mute', lastMuteState);
|
||||
} else
|
||||
watchers.call('volume', pub, [player.volume]);
|
||||
watchers.call('volume', player.volume);
|
||||
});
|
||||
|
||||
const pSetMuted = function(state) { player.muted = state; };
|
||||
|
@ -319,21 +320,21 @@ const MszVideoEmbedPlayer = function(metadata, options) {
|
|||
pub.getPlaybackRate = pGetPlaybackRate;
|
||||
|
||||
player.addEventListener('ratechange', function() {
|
||||
watchers.call('rate', pub, [player.playbackRate]);
|
||||
watchers.call('rate', player.playbackRate);
|
||||
});
|
||||
|
||||
const pSetPlaybackRate = function(rate) { player.playbackRate = rate; };
|
||||
pub.setPlaybackRate = pSetPlaybackRate;
|
||||
|
||||
window.addEventListener('durationchange', function() {
|
||||
watchers.call('duration', pub, [player.duration]);
|
||||
watchers.call('duration', player.duration);
|
||||
});
|
||||
|
||||
const pGetDuration = function() { return player.duration; };
|
||||
pub.getDuration = pGetDuration;
|
||||
|
||||
window.addEventListener('timeupdate', function() {
|
||||
watchers.call('time', pub, [player.currentTime]);
|
||||
watchers.call('time', player.currentTime);
|
||||
});
|
||||
|
||||
const pGetTime = function() { return player.currentTime; };
|
||||
|
@ -374,7 +375,7 @@ const MszVideoEmbedYouTube = function(metadata, options) {
|
|||
currentTime = undefined,
|
||||
isPlaying = undefined;
|
||||
|
||||
const watchers = new MszWatcherCollection;
|
||||
const watchers = new MszWatchers;
|
||||
watchers.define(MszVideoEmbedPlayerEvents());
|
||||
|
||||
const player = $e({
|
||||
|
@ -410,7 +411,8 @@ const MszVideoEmbedYouTube = function(metadata, options) {
|
|||
getPlayerId: function() { return playerId; },
|
||||
};
|
||||
|
||||
watchers.proxy(pub);
|
||||
pub.watch = (name, handler) => watchers.watch(name, handler);
|
||||
pub.unwatch = (name, handler) => watchers.unwatch(name, handler);
|
||||
|
||||
const postMessage = function(data) {
|
||||
player.contentWindow.postMessage(JSON.stringify(data), ytOrigin);
|
||||
|
@ -463,33 +465,33 @@ const MszVideoEmbedYouTube = function(metadata, options) {
|
|||
lastPlayerState = state;
|
||||
if(eventName !== undefined && eventName !== lastPlayerStateEvent) {
|
||||
lastPlayerStateEvent = eventName;
|
||||
watchers.call(eventName, pub);
|
||||
watchers.call(eventName);
|
||||
}
|
||||
};
|
||||
|
||||
const handleMuted = function(muted) {
|
||||
isMuted = muted;
|
||||
watchers.call('mute', pub, [isMuted]);
|
||||
watchers.call('mute', isMuted);
|
||||
};
|
||||
|
||||
const handleVolume = function(value) {
|
||||
volume = value / 100;
|
||||
watchers.call('volume', pub, [volume]);
|
||||
watchers.call('volume', volume);
|
||||
};
|
||||
|
||||
const handleRate = function(rate) {
|
||||
playbackRate = rate;
|
||||
watchers.call('rate', pub, [playbackRate]);
|
||||
watchers.call('rate', playbackRate);
|
||||
};
|
||||
|
||||
const handleDuration = function(time) {
|
||||
duration = time;
|
||||
watchers.call('duration', pub, [duration]);
|
||||
watchers.call('duration', duration);
|
||||
};
|
||||
|
||||
const handleTime = function(time) {
|
||||
currentTime = time;
|
||||
watchers.call('time', pub, [currentTime]);
|
||||
watchers.call('time', currentTime);
|
||||
};
|
||||
|
||||
const handlePresetRates = function(rates) {
|
||||
|
@ -574,7 +576,7 @@ const MszVideoEmbedNicoNico = function(metadata, options) {
|
|||
currentTime = undefined,
|
||||
isPlaying = false;
|
||||
|
||||
const watchers = new MszWatcherCollection;
|
||||
const watchers = new MszWatchers;
|
||||
watchers.define(MszVideoEmbedPlayerEvents());
|
||||
|
||||
const player = $e({
|
||||
|
@ -610,7 +612,8 @@ const MszVideoEmbedNicoNico = function(metadata, options) {
|
|||
getPlayerId: function() { return playerId; },
|
||||
};
|
||||
|
||||
watchers.proxy(pub);
|
||||
pub.watch = (name, handler) => watchers.watch(name, handler);
|
||||
pub.unwatch = (name, handler) => watchers.unwatch(name, handler);
|
||||
|
||||
const postMessage = function(name, data) {
|
||||
if(name === undefined)
|
||||
|
@ -660,28 +663,28 @@ const MszVideoEmbedNicoNico = function(metadata, options) {
|
|||
|
||||
if(eventName !== undefined && eventName !== lastPlayerStateEvent) {
|
||||
lastPlayerStateEvent = eventName;
|
||||
watchers.call(eventName, pub);
|
||||
watchers.call(eventName);
|
||||
}
|
||||
};
|
||||
|
||||
const handleMuted = function(muted) {
|
||||
isMuted = muted;
|
||||
watchers.call('mute', pub, [isMuted]);
|
||||
watchers.call('mute', isMuted);
|
||||
};
|
||||
|
||||
const handleVolume = function(value) {
|
||||
volume = value;
|
||||
watchers.call('volume', pub, [volume]);
|
||||
watchers.call('volume', volume);
|
||||
};
|
||||
|
||||
const handleDuration = function(time) {
|
||||
duration = time / 1000;
|
||||
watchers.call('duration', pub, [duration]);
|
||||
watchers.call('duration', duration);
|
||||
};
|
||||
|
||||
const handleTime = function(time) {
|
||||
currentTime = time / 1000;
|
||||
watchers.call('time', pub, [currentTime]);
|
||||
watchers.call('time', currentTime);
|
||||
};
|
||||
|
||||
const metadataHanders = {
|
|
@ -1,35 +1,49 @@
|
|||
#include utils.js
|
||||
#include utility.js
|
||||
|
||||
Misuzu.Events.Christmas2019 = function() {
|
||||
this.propName = propName = 'msz-christmas-' + (new Date).getFullYear().toString();
|
||||
const MszChristmas2019EventInfo = function() {
|
||||
return {
|
||||
isActive: () => {
|
||||
const d = new Date;
|
||||
return d.getMonth() === 11 && d.getDate() > 5 && d.getDate() < 27;
|
||||
},
|
||||
dispatch: () => {
|
||||
const impl = new MszChristmas2019Event;
|
||||
impl.dispatch();
|
||||
return impl;
|
||||
},
|
||||
};
|
||||
};
|
||||
Misuzu.Events.Christmas2019.prototype.changeColour = function() {
|
||||
var count = parseInt(localStorage.getItem(this.propName));
|
||||
document.body.style.setProperty('--header-accent-colour', (count++ % 2) ? 'green' : 'red');
|
||||
localStorage.setItem(this.propName, count.toString());
|
||||
};
|
||||
Misuzu.Events.Christmas2019.prototype.isActive = function() {
|
||||
var d = new Date;
|
||||
return d.getMonth() === 11 && d.getDate() > 5 && d.getDate() < 27;
|
||||
};
|
||||
Misuzu.Events.Christmas2019.prototype.dispatch = function() {
|
||||
var headerBg = $q('.header__background'),
|
||||
menuBgs = $qa('.header__desktop__submenu__background');
|
||||
|
||||
if(!localStorage.getItem(this.propName))
|
||||
localStorage.setItem(this.propName, '0');
|
||||
|
||||
if(headerBg)
|
||||
headerBg.style.transition = 'background-color .4s';
|
||||
|
||||
setTimeout(function() {
|
||||
if(headerBg)
|
||||
headerBg.style.transition = 'background-color 1s';
|
||||
|
||||
for(var i = 0; i < menuBgs.length; i++)
|
||||
menuBgs[i].style.transition = 'background-color 1s';
|
||||
}, 1000);
|
||||
|
||||
this.changeColour();
|
||||
setInterval(this.changeColour, 10000);
|
||||
|
||||
const MszChristmas2019Event = function() {
|
||||
const propName = 'msz-christmas-' + (new Date).getFullYear().toString();
|
||||
const headerBg = $q('.header__background');
|
||||
const menuBgs = Array.from($qa('.header__desktop__submenu__background'));
|
||||
|
||||
if(!localStorage.getItem(propName))
|
||||
localStorage.setItem(propName, '0');
|
||||
|
||||
const changeColour = () => {
|
||||
let count = parseInt(localStorage.getItem(propName));
|
||||
document.body.style.setProperty('--header-accent-colour', (count++ % 2) ? 'green' : 'red');
|
||||
localStorage.setItem(propName, count.toString());
|
||||
};
|
||||
|
||||
return {
|
||||
changeColour: changeColour,
|
||||
dispatch: () => {
|
||||
if(headerBg)
|
||||
headerBg.style.transition = 'background-color .4s';
|
||||
|
||||
setTimeout(() => {
|
||||
if(headerBg)
|
||||
headerBg.style.transition = 'background-color 1s';
|
||||
|
||||
for(const menuBg of menuBgs)
|
||||
menuBg.style.transition = 'background-color 1s';
|
||||
}, 1000);
|
||||
|
||||
changeColour();
|
||||
setInterval(changeColour, 10000);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
Misuzu.Events = {};
|
||||
const MszSeasonalEvents = function() {
|
||||
const events = [];
|
||||
|
||||
#include events/christmas2019.js
|
||||
|
||||
Misuzu.Events.getList = function() {
|
||||
return [
|
||||
new Misuzu.Events.Christmas2019,
|
||||
];
|
||||
};
|
||||
Misuzu.Events.dispatch = function() {
|
||||
var list = Misuzu.Events.getList();
|
||||
for(var i = 0; i < list.length; ++i)
|
||||
if(list[i].isActive())
|
||||
list[i].dispatch();
|
||||
return {
|
||||
add: eventInfo => {
|
||||
if(!events.includes(eventInfo))
|
||||
events.push(eventInfo);
|
||||
},
|
||||
dispatch: () => {
|
||||
for(const info of events)
|
||||
if(info.isActive())
|
||||
info.dispatch();
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
37
assets/misuzu.js/ext/eeprom.js
Normal file
37
assets/misuzu.js/ext/eeprom.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
#include utility.js
|
||||
|
||||
const MszEEPROM = (() => {
|
||||
let eepromScript;
|
||||
|
||||
return {
|
||||
init: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if(eepromScript !== undefined) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof peepPath !== 'string') {
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
|
||||
const scriptElem = $e({
|
||||
tag: 'script',
|
||||
attrs: {
|
||||
src: `${peepPath}/scripts/eepromv1a.js`,
|
||||
charset: 'utf-8',
|
||||
type: 'text/javascript',
|
||||
onerror: () => reject(),
|
||||
onload: () => {
|
||||
eepromScript = scriptElem;
|
||||
resolve(true);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
document.body.appendChild(scriptElem);
|
||||
});
|
||||
},
|
||||
};
|
||||
})();
|
|
@ -1,4 +1,4 @@
|
|||
const Sakuya = (function() {
|
||||
const MszSakuya = (function() {
|
||||
const formatter = new Intl.RelativeTimeFormat(undefined, { numeric: 'auto' });
|
||||
const divisions = [
|
||||
{ amount: 60, name: 'seconds' },
|
15
assets/misuzu.js/ext/uiharu.js
Normal file
15
assets/misuzu.js/ext/uiharu.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include utility.js
|
||||
|
||||
const MszUiharu = function(apiUrl) {
|
||||
const maxBatchSize = 4;
|
||||
const lookupOneUrl = apiUrl + '/metadata';
|
||||
|
||||
return {
|
||||
lookupOne: async targetUrl => {
|
||||
if(typeof targetUrl !== 'string')
|
||||
throw 'targetUrl must be a string';
|
||||
|
||||
return $x.post(lookupOneUrl, { type: 'json' }, targetUrl);
|
||||
},
|
||||
};
|
||||
};
|
|
@ -1,437 +0,0 @@
|
|||
#include forum/forum.js
|
||||
|
||||
Misuzu.Forum.Editor = {};
|
||||
Misuzu.Forum.Editor.allowWindowClose = false;
|
||||
Misuzu.Forum.Editor.init = function() {
|
||||
const postingForm = $q('.js-forum-posting');
|
||||
if(!postingForm)
|
||||
return;
|
||||
|
||||
const postingButtons = postingForm.querySelector('.js-forum-posting-buttons'),
|
||||
postingText = postingForm.querySelector('.js-forum-posting-text'),
|
||||
postingParser = postingForm.querySelector('.js-forum-posting-parser'),
|
||||
postingPreview = postingForm.querySelector('.js-forum-posting-preview'),
|
||||
postingMode = postingForm.querySelector('.js-forum-posting-mode'),
|
||||
previewButton = document.createElement('button'),
|
||||
bbcodeButtons = $q('.forum__post__actions--bbcode'),
|
||||
markdownButtons = $q('.forum__post__actions--markdown'),
|
||||
markupButtons = $qa('.forum__post__action--tag');
|
||||
|
||||
// Initialise EEPROM, code sucks ass but it's getting nuked soon again anyway
|
||||
if(typeof peepPath === 'string')
|
||||
document.body.appendChild($e({
|
||||
tag: 'script',
|
||||
attrs: {
|
||||
src: peepPath + '/eeprom.js',
|
||||
charset: 'utf-8',
|
||||
type: 'text/javascript',
|
||||
onload: function() {
|
||||
const eepromClient = new EEPROM(peepApp, peepPath + '/uploads', '');
|
||||
|
||||
const eepromHistory = $e({
|
||||
attrs: {
|
||||
className: 'eeprom-widget-history-items',
|
||||
},
|
||||
});
|
||||
|
||||
const eepromHandleFileUpload = function(file) {
|
||||
const uploadElemNameValue = $e({
|
||||
attrs: {
|
||||
className: 'eeprom-widget-file-name-value',
|
||||
title: file.name,
|
||||
},
|
||||
child: file.name,
|
||||
});
|
||||
|
||||
const uploadElemName = $e({
|
||||
tag: 'a',
|
||||
attrs: {
|
||||
className: 'eeprom-widget-file-name',
|
||||
target: '_blank',
|
||||
},
|
||||
child: uploadElemNameValue,
|
||||
});
|
||||
|
||||
const uploadElemProgressText = $e({
|
||||
attrs: {
|
||||
className: 'eeprom-widget-file-progress',
|
||||
},
|
||||
child: 'Please wait...',
|
||||
});
|
||||
|
||||
const uploadElemProgressBarValue = $e({
|
||||
attrs: {
|
||||
className: 'eeprom-widget-file-bar-fill',
|
||||
style: {
|
||||
width: '0%',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const uploadElem = $e({
|
||||
attrs: {
|
||||
className: 'eeprom-widget-file',
|
||||
},
|
||||
child: [
|
||||
{
|
||||
attrs: {
|
||||
className: 'eeprom-widget-file-info',
|
||||
},
|
||||
child: [
|
||||
uploadElemName,
|
||||
uploadElemProgressText,
|
||||
],
|
||||
},
|
||||
{
|
||||
attrs: {
|
||||
className: 'eeprom-widget-file-bar',
|
||||
},
|
||||
child: uploadElemProgressBarValue,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
if(eepromHistory.children.length > 0)
|
||||
$ib(eepromHistory.firstChild, uploadElem);
|
||||
else
|
||||
eepromHistory.appendChild(uploadElem);
|
||||
|
||||
const explodeUploadElem = function() {
|
||||
$r(uploadElem);
|
||||
};
|
||||
|
||||
const uploadTask = eepromClient.createUpload(file);
|
||||
|
||||
uploadTask.onProgress = function(progressInfo) {
|
||||
const progressValue = progressInfo.progress.toString() + '%';
|
||||
uploadElemProgressBarValue.style.width = progressValue;
|
||||
uploadElemProgressText.textContent = progressValue + ' (' + (progressInfo.total - progressInfo.loaded).toString() + ' bytes remaining)';
|
||||
};
|
||||
|
||||
uploadTask.onFailure = function(errorInfo) {
|
||||
if(!errorInfo.userAborted) {
|
||||
let errorText = 'Was unable to upload file.';
|
||||
|
||||
switch(errorInfo.error) {
|
||||
case EEPROM.ERR_INVALID:
|
||||
errorText = 'Upload request was invalid.';
|
||||
break;
|
||||
case EEPROM.ERR_AUTH:
|
||||
errorText = 'Upload authentication failed, refresh and try again.';
|
||||
break;
|
||||
case EEPROM.ERR_ACCESS:
|
||||
errorText = 'You\'re not allowed to upload files.';
|
||||
break;
|
||||
case EEPROM.ERR_GONE:
|
||||
errorText = 'Upload client has a configuration error or the server is gone.';
|
||||
break;
|
||||
case EEPROM.ERR_DMCA:
|
||||
errorText = 'This file has been uploaded before and was removed for copyright reasons, you cannot upload this file.';
|
||||
break;
|
||||
case EEPROM.ERR_SERVER:
|
||||
errorText = 'Upload server returned a critical error, try again later.';
|
||||
break;
|
||||
case EEPROM.ERR_SIZE:
|
||||
if(errorInfo.maxSize < 1)
|
||||
errorText = 'Selected file is too large.';
|
||||
else {
|
||||
const _t = ['bytes', 'KB', 'MB', 'GB', 'TB'],
|
||||
_i = parseInt(Math.floor(Math.log(errorInfo.maxSize) / Math.log(1024))),
|
||||
_s = Math.round(errorInfo.maxSize / Math.pow(1024, _i), 2);
|
||||
|
||||
errorText = 'Upload may not be larger than %1 %2.'.replace('%1', _s).replace('%2', _t[_i]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
uploadElem.classList.add('eeprom-widget-file-fail');
|
||||
uploadElemProgressText.textContent = errorText;
|
||||
Misuzu.showMessageBox(errorText, 'Upload Error');
|
||||
}
|
||||
};
|
||||
|
||||
uploadTask.onComplete = function(fileInfo) {
|
||||
uploadElem.classList.add('eeprom-widget-file-done');
|
||||
uploadElemName.href = fileInfo.url;
|
||||
uploadElemProgressText.textContent = '';
|
||||
|
||||
const insertTheLinkIntoTheBoxEx2 = function() {
|
||||
const parserMode = parseInt(postingParser.value);
|
||||
let insertText = location.protocol + fileInfo.url;
|
||||
|
||||
if(parserMode == 1) { // bbcode
|
||||
if(fileInfo.isImage())
|
||||
insertText = '[img]' + fileInfo.url + '[/img]';
|
||||
else if(fileInfo.isAudio())
|
||||
insertText = '[audio]' + fileInfo.url + '[/audio]';
|
||||
else if(fileInfo.isVideo())
|
||||
insertText = '[video]' + fileInfo.url + '[/video]';
|
||||
} else if(parserMode == 2) { // markdown
|
||||
if(fileInfo.isMedia())
|
||||
insertText = '![](' + fileInfo.url + ')';
|
||||
}
|
||||
|
||||
$insertTags(postingText, insertText, '');
|
||||
postingText.value = postingText.value.trim();
|
||||
};
|
||||
|
||||
uploadElemProgressText.appendChild($e({
|
||||
tag: 'a',
|
||||
attrs: {
|
||||
href: 'javascript:void(0);',
|
||||
onclick: function() { insertTheLinkIntoTheBoxEx2(); },
|
||||
},
|
||||
child: 'Insert',
|
||||
}));
|
||||
uploadElemProgressText.appendChild($t(' '));
|
||||
uploadElemProgressText.appendChild($e({
|
||||
tag: 'a',
|
||||
attrs: {
|
||||
href: 'javascript:void(0);',
|
||||
onclick: function() {
|
||||
eepromClient.deleteUpload(fileInfo).start();
|
||||
explodeUploadElem();
|
||||
},
|
||||
},
|
||||
child: 'Delete',
|
||||
}));
|
||||
|
||||
insertTheLinkIntoTheBoxEx2();
|
||||
};
|
||||
|
||||
uploadTask.start();
|
||||
};
|
||||
|
||||
const eepromFormInput = $e({
|
||||
tag: 'input',
|
||||
attrs: {
|
||||
type: 'file',
|
||||
multiple: 'multiple',
|
||||
className: 'eeprom-widget-form-input',
|
||||
onchange: function(ev) {
|
||||
const files = this.files;
|
||||
for(const file of files)
|
||||
eepromHandleFileUpload(file);
|
||||
this.value = '';
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const eepromForm = $e({
|
||||
tag: 'label',
|
||||
attrs: {
|
||||
className: 'eeprom-widget-form',
|
||||
},
|
||||
child: [
|
||||
eepromFormInput,
|
||||
{
|
||||
attrs: {
|
||||
className: 'eeprom-widget-form-text',
|
||||
},
|
||||
child: 'Select Files...',
|
||||
}
|
||||
],
|
||||
});
|
||||
|
||||
const eepromWidget = $e({
|
||||
attrs: {
|
||||
className: 'eeprom-widget',
|
||||
},
|
||||
child: [
|
||||
eepromForm,
|
||||
{
|
||||
attrs: {
|
||||
className: 'eeprom-widget-history',
|
||||
},
|
||||
child: eepromHistory,
|
||||
},
|
||||
],
|
||||
});
|
||||
postingForm.appendChild(eepromWidget);
|
||||
|
||||
postingText.addEventListener('paste', function(ev) {
|
||||
if(ev.clipboardData && ev.clipboardData.files.length > 0) {
|
||||
ev.preventDefault();
|
||||
|
||||
const files = ev.clipboardData.files;
|
||||
for(const file of files)
|
||||
eepromHandleFileUpload(file);
|
||||
}
|
||||
});
|
||||
|
||||
document.body.addEventListener('dragenter', function(ev) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
});
|
||||
document.body.addEventListener('dragover', function(ev) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
});
|
||||
document.body.addEventListener('dragleave', function(ev) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
});
|
||||
document.body.addEventListener('drop', function(ev) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
if(ev.dataTransfer && ev.dataTransfer.files.length > 0) {
|
||||
const files = ev.dataTransfer.files;
|
||||
for(const file of files)
|
||||
eepromHandleFileUpload(file);
|
||||
}
|
||||
});
|
||||
},
|
||||
onerror: function(ev) {
|
||||
console.error('Failed to initialise EEPROM: ', ev);
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
// hack: don't prompt user when hitting submit, really need to make this not stupid.
|
||||
postingButtons.firstElementChild.addEventListener('click', function() {
|
||||
Misuzu.Forum.Editor.allowWindowClose = true;
|
||||
});
|
||||
|
||||
window.addEventListener('beforeunload', function(ev) {
|
||||
if(!Misuzu.Forum.Editor.allowWindowClose && postingText.value.length > 0) {
|
||||
ev.preventDefault();
|
||||
ev.returnValue = '';
|
||||
}
|
||||
});
|
||||
|
||||
for(var i = 0; i < markupButtons.length; ++i)
|
||||
(function(currentBtn) {
|
||||
currentBtn.addEventListener('click', function(ev) {
|
||||
$insertTags(postingText, currentBtn.dataset.tagOpen, currentBtn.dataset.tagClose);
|
||||
});
|
||||
})(markupButtons[i]);
|
||||
|
||||
Misuzu.Forum.Editor.switchButtons(parseInt(postingParser.value));
|
||||
|
||||
var lastPostText = '',
|
||||
lastPostParser = null;
|
||||
|
||||
postingParser.addEventListener('change', function() {
|
||||
var postParser = parseInt(postingParser.value);
|
||||
Misuzu.Forum.Editor.switchButtons(postParser);
|
||||
|
||||
if(postingPreview.hasAttribute('hidden'))
|
||||
return;
|
||||
|
||||
// dunno if this would even be possible, but ech
|
||||
if(postParser === lastPostParser)
|
||||
return;
|
||||
|
||||
postingParser.setAttribute('disabled', 'disabled');
|
||||
previewButton.setAttribute('disabled', 'disabled');
|
||||
previewButton.classList.add('input__button--busy');
|
||||
|
||||
Misuzu.Forum.Editor.renderPreview(postParser, lastPostText, function(success, text) {
|
||||
if(!success) {
|
||||
Misuzu.showMessageBox(text);
|
||||
return;
|
||||
}
|
||||
|
||||
postingPreview.classList[postParser == 2 ? 'add' : 'remove']('markdown');
|
||||
|
||||
lastPostParser = postParser;
|
||||
postingPreview.innerHTML = text;
|
||||
MszEmbed.handle($qa('.js-msz-embed-media'));
|
||||
|
||||
previewButton.removeAttribute('disabled');
|
||||
postingParser.removeAttribute('disabled');
|
||||
previewButton.classList.remove('input__button--busy');
|
||||
});
|
||||
});
|
||||
|
||||
previewButton.className = 'input__button';
|
||||
previewButton.textContent = 'Preview';
|
||||
previewButton.type = 'button';
|
||||
previewButton.value = 'preview';
|
||||
previewButton.addEventListener('click', function() {
|
||||
if(previewButton.value === 'back') {
|
||||
postingPreview.setAttribute('hidden', 'hidden');
|
||||
postingText.removeAttribute('hidden');
|
||||
previewButton.value = 'preview';
|
||||
previewButton.textContent = 'Preview';
|
||||
postingMode.textContent = postingMode.dataset.original;
|
||||
postingMode.dataset.original = null;
|
||||
} else {
|
||||
var postText = postingText.value,
|
||||
postParser = parseInt(postingParser.value);
|
||||
|
||||
if(lastPostText === postText && lastPostParser === postParser) {
|
||||
postingPreview.removeAttribute('hidden');
|
||||
postingText.setAttribute('hidden', 'hidden');
|
||||
previewButton.value = 'back';
|
||||
previewButton.textContent = 'Edit';
|
||||
postingMode.dataset.original = postingMode.textContent;
|
||||
postingMode.textContent = 'Previewing';
|
||||
return;
|
||||
}
|
||||
|
||||
postingParser.setAttribute('disabled', 'disabled');
|
||||
previewButton.setAttribute('disabled', 'disabled');
|
||||
previewButton.classList.add('input__button--busy');
|
||||
|
||||
Misuzu.Forum.Editor.renderPreview(postParser, postText, function(success, text) {
|
||||
if(!success) {
|
||||
Misuzu.showMessageBox(text);
|
||||
return;
|
||||
}
|
||||
|
||||
postingPreview.classList[postParser == 2 ? 'add' : 'remove']('markdown');
|
||||
|
||||
lastPostText = postText;
|
||||
lastPostParser = postParser;
|
||||
postingPreview.innerHTML = text;
|
||||
MszEmbed.handle($qa('.js-msz-embed-media'));
|
||||
|
||||
postingPreview.removeAttribute('hidden');
|
||||
postingText.setAttribute('hidden', 'hidden');
|
||||
previewButton.value = 'back';
|
||||
previewButton.textContent = 'Back';
|
||||
previewButton.removeAttribute('disabled');
|
||||
postingParser.removeAttribute('disabled');
|
||||
previewButton.classList.remove('input__button--busy');
|
||||
postingMode.dataset.original = postingMode.textContent;
|
||||
postingMode.textContent = 'Previewing';
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
postingButtons.insertBefore(previewButton, postingButtons.firstChild);
|
||||
};
|
||||
Misuzu.Forum.Editor.switchButtons = function(parser) {
|
||||
var bbcodeButtons = $q('.forum__post__actions--bbcode'),
|
||||
markdownButtons = $q('.forum__post__actions--markdown');
|
||||
|
||||
bbcodeButtons.hidden = parser != 1;
|
||||
markdownButtons.hidden = parser != 2;
|
||||
};
|
||||
Misuzu.Forum.Editor.renderPreview = function(parser, text, callback) {
|
||||
if(!callback)
|
||||
return;
|
||||
parser = parseInt(parser);
|
||||
text = text || '';
|
||||
|
||||
var xhr = new XMLHttpRequest,
|
||||
formData = new FormData;
|
||||
|
||||
formData.append('post[mode]', 'preview');
|
||||
formData.append('post[text]', text);
|
||||
formData.append('post[parser]', parser.toString());
|
||||
|
||||
xhr.addEventListener('readystatechange', function() {
|
||||
if(xhr.readyState !== XMLHttpRequest.DONE)
|
||||
return;
|
||||
if(xhr.status === 200)
|
||||
callback(true, xhr.response);
|
||||
else
|
||||
callback(false, 'Failed to render preview.');
|
||||
});
|
||||
// need to figure out a url registry system again, current one is too much overhead so lets just do this for now
|
||||
xhr.open('POST', '/forum/posting.php');
|
||||
xhr.withCredentials = true;
|
||||
xhr.send(formData);
|
||||
};
|
291
assets/misuzu.js/forum/editor.jsx
Normal file
291
assets/misuzu.js/forum/editor.jsx
Normal file
|
@ -0,0 +1,291 @@
|
|||
#include msgbox.jsx
|
||||
#include parsing.js
|
||||
#include utility.js
|
||||
#include ext/eeprom.js
|
||||
|
||||
let MszForumEditorAllowClose = false;
|
||||
|
||||
const MszForumEditor = function(form) {
|
||||
if(!(form instanceof Element))
|
||||
throw 'form must be an instance of element';
|
||||
|
||||
const buttonsElem = form.querySelector('.js-forum-posting-buttons'),
|
||||
textElem = form.querySelector('.js-forum-posting-text'),
|
||||
parserElem = form.querySelector('.js-forum-posting-parser'),
|
||||
previewElem = form.querySelector('.js-forum-posting-preview'),
|
||||
modeElem = form.querySelector('.js-forum-posting-mode'),
|
||||
markupActs = form.querySelector('.js-forum-posting-actions');
|
||||
|
||||
let lastPostText = '',
|
||||
lastPostParser;
|
||||
|
||||
MszEEPROM.init()
|
||||
.catch(() => console.error('Failed to initialise EEPROM'))
|
||||
.then(() => {
|
||||
const eepromClient = new EEPROM(peepApp, peepPath);
|
||||
const eepromHistory = <div class="eeprom-widget-history-items"/>;
|
||||
|
||||
const eepromHandleFileUpload = async file => {
|
||||
const uploadElemNameValue = <div class="eeprom-widget-file-name-value" title={file.name}>{file.name}</div>;
|
||||
const uploadElemName = <a class="eeprom-widget-file-name" target="_blank">{uploadElemNameValue}</a>;
|
||||
const uploadElemProgressText = <div class="eeprom-widget-file-progress">Please wait...</div>;
|
||||
const uploadElemProgressBarValue = <div class="eeprom-widget-file-bar-fill" style={{ width: '0%' }}/>;
|
||||
const uploadElem = <div class="eeprom-widget-file">
|
||||
<div class="eeprom-widget-file-info">
|
||||
{uploadElemName}
|
||||
{uploadElemProgressText}
|
||||
</div>
|
||||
<div class="eeprom-widget-file-bar">
|
||||
{uploadElemProgressBarValue}
|
||||
</div>
|
||||
</div>;
|
||||
|
||||
if(eepromHistory.children.length > 0)
|
||||
$ib(eepromHistory.firstChild, uploadElem);
|
||||
else
|
||||
eepromHistory.appendChild(uploadElem);
|
||||
|
||||
const explodeUploadElem = () => $r(uploadElem);
|
||||
const uploadTask = eepromClient.create(file);
|
||||
|
||||
uploadTask.onProgress(prog => {
|
||||
uploadElemProgressBarValue.style.width = `${Math.ceil(prog.progress * 100)}%`;
|
||||
uploadElemProgressText.textContent = `${prog.progress.toLocaleString(undefined, { style: 'percent' })} (${prog.total - prog.loaded} bytes remaining)`;
|
||||
});
|
||||
|
||||
try {
|
||||
const fileInfo = await uploadTask.start();
|
||||
|
||||
uploadElem.classList.add('eeprom-widget-file-done');
|
||||
uploadElemName.href = fileInfo.url;
|
||||
uploadElemProgressText.textContent = '';
|
||||
|
||||
const insertTheLinkIntoTheBoxEx2 = () => {
|
||||
const parserMode = parseInt(parserElem.value);
|
||||
let insertText = location.protocol + fileInfo.url;
|
||||
|
||||
if(parserMode == 1) { // bbcode
|
||||
if(fileInfo.isImage())
|
||||
insertText = `[img]${fileInfo.url}[/img]`;
|
||||
else if(fileInfo.isAudio())
|
||||
insertText = `[audio]${fileInfo.url}[/audio]`;
|
||||
else if(fileInfo.isVideo())
|
||||
insertText = `[video]${fileInfo.url}[/video]`;
|
||||
} else if(parserMode == 2) { // markdown
|
||||
if(fileInfo.isMedia())
|
||||
insertText = `![](${fileInfo.url})`;
|
||||
}
|
||||
|
||||
$insertTags(textElem, insertText, '');
|
||||
textElem.value = textElem.value.trim();
|
||||
};
|
||||
|
||||
uploadElemProgressText.appendChild(<a href="javascript:void(0)" onclick={() => insertTheLinkIntoTheBoxEx2()}>Insert</a>);
|
||||
uploadElemProgressText.appendChild($t(' '));
|
||||
uploadElemProgressText.appendChild(<a href="javascript:void(0)" onclick={() => {
|
||||
eepromClient.delete(fileInfo)
|
||||
.then(() => explodeUploadElem())
|
||||
.catch(ex => {
|
||||
console.error(ex);
|
||||
MszShowMessageBox(ex, 'Upload Error');
|
||||
});
|
||||
}}>Delete</a>);
|
||||
|
||||
insertTheLinkIntoTheBoxEx2();
|
||||
} catch(ex) {
|
||||
let errorText = 'Upload aborted.';
|
||||
|
||||
if(!ex.aborted) {
|
||||
console.error(ex);
|
||||
errorText = ex.toString();
|
||||
}
|
||||
|
||||
uploadElem.classList.add('eeprom-widget-file-fail');
|
||||
uploadElemProgressText.textContent = errorText;
|
||||
await MszShowMessageBox(errorText, 'Upload Error');
|
||||
}
|
||||
};
|
||||
|
||||
const eepromFormInput = <input type="file" multiple={true} class="eeprom-widget-form-input"
|
||||
onchange={() => {
|
||||
const files = eepromFormInput.files;
|
||||
for(const file of files)
|
||||
eepromHandleFileUpload(file);
|
||||
eepromFormInput.value = '';
|
||||
}}/>;
|
||||
|
||||
const eepromForm = <label class="eeprom-widget-form">
|
||||
{eepromFormInput}
|
||||
<div class="eeprom-widget-form-text">
|
||||
Select Files...
|
||||
</div>
|
||||
</label>;
|
||||
|
||||
const eepromWidget = <div class="eeprom-widget">
|
||||
{eepromForm}
|
||||
<div class="eeprom-widget-history">
|
||||
{eepromHistory}
|
||||
</div>
|
||||
</div>;
|
||||
|
||||
form.appendChild(eepromWidget);
|
||||
|
||||
textElem.addEventListener('paste', ev => {
|
||||
if(ev.clipboardData && ev.clipboardData.files.length > 0) {
|
||||
ev.preventDefault();
|
||||
|
||||
const files = ev.clipboardData.files;
|
||||
for(const file of files)
|
||||
eepromHandleFileUpload(file);
|
||||
}
|
||||
});
|
||||
|
||||
document.body.addEventListener('dragenter', ev => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
});
|
||||
document.body.addEventListener('dragover', ev => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
});
|
||||
document.body.addEventListener('dragleave', ev => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
});
|
||||
document.body.addEventListener('drop', ev => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
if(ev.dataTransfer && ev.dataTransfer.files.length > 0) {
|
||||
const files = ev.dataTransfer.files;
|
||||
for(const file of files)
|
||||
eepromHandleFileUpload(file);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// hack: don't prompt user when hitting submit, really need to make this not stupid.
|
||||
buttonsElem.firstChild.addEventListener('click', () => MszForumEditorAllowClose = true);
|
||||
|
||||
window.addEventListener('beforeunload', function(ev) {
|
||||
if(!MszForumEditorAllowClose && textElem.value.length > 0) {
|
||||
ev.preventDefault();
|
||||
ev.returnValue = '';
|
||||
}
|
||||
});
|
||||
|
||||
const switchButtons = parser => {
|
||||
$rc(markupActs);
|
||||
|
||||
const tags = MszParsing.getTagsFor(parser);
|
||||
for(const tag of tags)
|
||||
markupActs.appendChild(<button class={['forum__post__action', 'forum__post__action--tag', `forum__post__action--${tag.name}`]}
|
||||
type="button" title={tag.summary} onclick={() => $insertTags(textElem, tag.open, tag.close)}>
|
||||
<i class={tag.icon}/>
|
||||
</button>);
|
||||
};
|
||||
|
||||
const renderPreview = async (parser, text) => {
|
||||
if(typeof text !== 'string')
|
||||
return '';
|
||||
|
||||
const formData = new FormData;
|
||||
formData.append('post[mode]', 'preview');
|
||||
formData.append('post[text]', text);
|
||||
formData.append('post[parser]', parseInt(parser));
|
||||
|
||||
const result = await $x.post('/forum/posting.php', { authed: true }, formData);
|
||||
|
||||
return result.body();
|
||||
};
|
||||
|
||||
const previewBtn = <button class="input__button" type="button" value="preview">Preview</button>;
|
||||
previewBtn.addEventListener('click', function() {
|
||||
if(previewBtn.value === 'back') {
|
||||
previewElem.setAttribute('hidden', 'hidden');
|
||||
textElem.removeAttribute('hidden');
|
||||
previewBtn.value = 'preview';
|
||||
previewBtn.textContent = 'Preview';
|
||||
modeElem.textContent = modeElem.dataset.original;
|
||||
modeElem.dataset.original = null;
|
||||
} else {
|
||||
const postText = textElem.value,
|
||||
postParser = parseInt(parserElem.value);
|
||||
|
||||
if(lastPostText === postText && lastPostParser === postParser) {
|
||||
previewElem.removeAttribute('hidden');
|
||||
textElem.setAttribute('hidden', 'hidden');
|
||||
previewBtn.value = 'back';
|
||||
previewBtn.textContent = 'Edit';
|
||||
modeElem.dataset.original = modeElem.textContent;
|
||||
modeElem.textContent = 'Previewing';
|
||||
return;
|
||||
}
|
||||
|
||||
parserElem.setAttribute('disabled', 'disabled');
|
||||
previewBtn.setAttribute('disabled', 'disabled');
|
||||
previewBtn.classList.add('input__button--busy');
|
||||
|
||||
renderPreview(postParser, postText)
|
||||
.catch(() => {
|
||||
previewElem.innerHTML = '';
|
||||
MszShowMessageBox('Failed to render preview.');
|
||||
})
|
||||
.then(body => {
|
||||
previewElem.classList.toggle('markdown', postParser === 2);
|
||||
|
||||
lastPostText = postText;
|
||||
lastPostParser = postParser;
|
||||
previewElem.innerHTML = body;
|
||||
|
||||
MszEmbed.handle($qa('.js-msz-embed-media'));
|
||||
|
||||
previewElem.removeAttribute('hidden');
|
||||
textElem.setAttribute('hidden', 'hidden');
|
||||
previewBtn.value = 'back';
|
||||
previewBtn.textContent = 'Back';
|
||||
previewBtn.removeAttribute('disabled');
|
||||
parserElem.removeAttribute('disabled');
|
||||
previewBtn.classList.remove('input__button--busy');
|
||||
modeElem.dataset.original = modeElem.textContent;
|
||||
modeElem.textContent = 'Previewing';
|
||||
});
|
||||
}
|
||||
});
|
||||
buttonsElem.insertBefore(previewBtn, buttonsElem.firstChild);
|
||||
|
||||
switchButtons(parserElem.value);
|
||||
|
||||
parserElem.addEventListener('change', () => {
|
||||
const postParser = parseInt(parserElem.value);
|
||||
switchButtons(postParser);
|
||||
|
||||
if(previewElem.hasAttribute('hidden'))
|
||||
return;
|
||||
|
||||
// dunno if this would even be possible, but ech
|
||||
if(postParser === lastPostParser)
|
||||
return;
|
||||
|
||||
parserElem.setAttribute('disabled', 'disabled');
|
||||
previewBtn.setAttribute('disabled', 'disabled');
|
||||
previewBtn.classList.add('input__button--busy');
|
||||
|
||||
renderPreview(postParser, lastPostText)
|
||||
.catch(() => {
|
||||
previewElem.innerHTML = '';
|
||||
MszShowMessageBox('Failed to render preview.');
|
||||
})
|
||||
.then(body => {
|
||||
previewElem.classList.add('markdown', postParser === 2);
|
||||
lastPostParser = postParser;
|
||||
previewElem.innerHTML = body;
|
||||
|
||||
MszEmbed.handle($qa('.js-msz-embed-media'));
|
||||
|
||||
previewBtn.removeAttribute('disabled');
|
||||
parserElem.removeAttribute('disabled');
|
||||
previewBtn.classList.remove('input__button--busy');
|
||||
});
|
||||
});
|
||||
};
|
|
@ -1 +0,0 @@
|
|||
Misuzu.Forum = {};
|
|
@ -1,135 +1,90 @@
|
|||
#include sakuya.js
|
||||
|
||||
var Misuzu = function() {
|
||||
Sakuya.trackElements($qa('time'));
|
||||
hljs.initHighlighting();
|
||||
|
||||
MszEmbed.init(location.protocol + '//uiharu.' + location.host);
|
||||
|
||||
Misuzu.initQuickSubmit(); // only used by the forum posting form
|
||||
Misuzu.Forum.Editor.init();
|
||||
Misuzu.Events.dispatch();
|
||||
Misuzu.initLoginPage();
|
||||
|
||||
MszEmbed.handle($qa('.js-msz-embed-media'));
|
||||
};
|
||||
|
||||
#include utils.js
|
||||
#include embed.js
|
||||
#include forum/editor.js
|
||||
#include utility.js
|
||||
#include embed/embed.js
|
||||
#include events/christmas2019.js
|
||||
#include events/events.js
|
||||
#include ext/sakuya.js
|
||||
#include forum/editor.jsx
|
||||
#include messages/messages.js
|
||||
|
||||
Misuzu.showMessageBox = function(text, title, buttons) {
|
||||
if($q('.messagebox'))
|
||||
return false;
|
||||
(async () => {
|
||||
const initLoginPage = async () => {
|
||||
const forms = Array.from($qa('.js-login-form'));
|
||||
if(forms.length < 1)
|
||||
return;
|
||||
|
||||
text = text || '';
|
||||
title = title || '';
|
||||
buttons = buttons || [];
|
||||
|
||||
var element = document.createElement('div');
|
||||
element.className = 'messagebox';
|
||||
|
||||
var container = element.appendChild(document.createElement('div'));
|
||||
container.className = 'container messagebox__container';
|
||||
|
||||
var titleElement = container.appendChild(document.createElement('div')),
|
||||
titleBackground = titleElement.appendChild(document.createElement('div')),
|
||||
titleText = titleElement.appendChild(document.createElement('div'));
|
||||
|
||||
titleElement.className = 'container__title';
|
||||
titleBackground.className = 'container__title__background';
|
||||
titleText.className = 'container__title__text';
|
||||
titleText.textContent = title || 'Information';
|
||||
|
||||
var textElement = container.appendChild(document.createElement('div'));
|
||||
textElement.className = 'container__content';
|
||||
textElement.textContent = text;
|
||||
|
||||
var buttonsContainer = container.appendChild(document.createElement('div'));
|
||||
buttonsContainer.className = 'messagebox__buttons';
|
||||
|
||||
var firstButton = null;
|
||||
|
||||
if(buttons.length < 1) {
|
||||
firstButton = buttonsContainer.appendChild(document.createElement('button'));
|
||||
firstButton.className = 'input__button';
|
||||
firstButton.textContent = 'OK';
|
||||
firstButton.addEventListener('click', function() { element.remove(); });
|
||||
} else {
|
||||
for(var i = 0; i < buttons.length; i++) {
|
||||
var button = buttonsContainer.appendChild(document.createElement('button'));
|
||||
button.className = 'input__button';
|
||||
button.textContent = buttons[i].text;
|
||||
button.addEventListener('click', function() {
|
||||
element.remove();
|
||||
buttons[i].callback();
|
||||
});
|
||||
|
||||
if(firstButton === null)
|
||||
firstButton = button;
|
||||
}
|
||||
}
|
||||
|
||||
document.body.appendChild(element);
|
||||
firstButton.focus();
|
||||
return true;
|
||||
};
|
||||
Misuzu.initLoginPage = function() {
|
||||
var updateForm = function(avatarElem, usernameElem) {
|
||||
var xhr = new XMLHttpRequest;
|
||||
xhr.addEventListener('readystatechange', function() {
|
||||
if(xhr.readyState !== 4)
|
||||
const updateForm = async (avatar, userName) => {
|
||||
if(!(avatar instanceof Element) || !(userName instanceof Element))
|
||||
return;
|
||||
|
||||
var json = JSON.parse(xhr.responseText);
|
||||
if(!json)
|
||||
return;
|
||||
const result = (await $x.get(`/auth/login.php?resolve=1&name=${encodeURIComponent(userName.value)}`, { type: 'json' })).body();
|
||||
|
||||
if(json.name)
|
||||
usernameElem.value = json.name;
|
||||
avatarElem.src = json.avatar;
|
||||
});
|
||||
// need to figure out a url registry system again, current one is too much overhead so lets just do this for now
|
||||
xhr.open('GET', '/auth/login.php?resolve=1&name=' + encodeURIComponent(usernameElem.value));
|
||||
xhr.send();
|
||||
};
|
||||
avatar.src = result.avatar;
|
||||
if(result.name.length > 0)
|
||||
userName.value = result.name;
|
||||
};
|
||||
|
||||
var loginForms = $c('js-login-form');
|
||||
for(const form of forms) {
|
||||
const avatar = form.querySelector('.js-login-avatar');
|
||||
const userName = form.querySelector('.js-login-username');
|
||||
let timeOut;
|
||||
|
||||
for(var i = 0; i < loginForms.length; ++i)
|
||||
(function(form) {
|
||||
var loginTimeOut = 0,
|
||||
loginAvatar = form.querySelector('.js-login-avatar'),
|
||||
loginUsername = form.querySelector('.js-login-username');
|
||||
await updateForm(avatar, userName);
|
||||
|
||||
updateForm(loginAvatar, loginUsername);
|
||||
loginUsername.addEventListener('keyup', function() {
|
||||
if(loginTimeOut)
|
||||
userName.addEventListener('input', function() {
|
||||
if(timeOut !== undefined)
|
||||
return;
|
||||
loginTimeOut = setTimeout(function() {
|
||||
updateForm(loginAvatar, loginUsername);
|
||||
clearTimeout(loginTimeOut);
|
||||
loginTimeOut = 0;
|
||||
|
||||
timeOut = setTimeout(() => {
|
||||
updateForm(avatar, userName)
|
||||
.finally(() => {
|
||||
clearTimeout(timeOut);
|
||||
timeOut = undefined;
|
||||
});
|
||||
}, 750);
|
||||
});
|
||||
})(loginForms[i]);
|
||||
};
|
||||
Misuzu.initQuickSubmit = function() {
|
||||
var ctrlSubmit = Array.from($qa('.js-quick-submit, .js-ctrl-enter-submit'));
|
||||
if(!ctrlSubmit)
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
for(var i = 0; i < ctrlSubmit.length; ++i)
|
||||
ctrlSubmit[i].addEventListener('keydown', function(ev) {
|
||||
if((ev.code === 'Enter' || ev.code === 'NumpadEnter') // i hate this fucking language so much
|
||||
&& ev.ctrlKey && !ev.altKey && !ev.shiftKey && !ev.metaKey) {
|
||||
// hack: prevent forum editor from screaming when using this keycombo
|
||||
// can probably be done in a less stupid manner
|
||||
Misuzu.Forum.Editor.allowWindowClose = true;
|
||||
const initQuickSubmit = () => {
|
||||
const elems = Array.from($qa('.js-quick-submit, .js-ctrl-enter-submit'));
|
||||
if(elems.length < 1)
|
||||
return;
|
||||
|
||||
this.form.submit();
|
||||
ev.preventDefault();
|
||||
}
|
||||
});
|
||||
};
|
||||
for(const elem of elems)
|
||||
elem.addEventListener('keydown', ev => {
|
||||
if((ev.code === 'Enter' || ev.code === 'NumpadEnter') && ev.ctrlKey && !ev.altKey && !ev.shiftKey && !ev.metaKey) {
|
||||
// hack: prevent forum editor from screaming when using this keycombo
|
||||
// can probably be done in a less stupid manner
|
||||
MszForumEditorAllowClose = true;
|
||||
|
||||
elem.form.submit();
|
||||
ev.preventDefault();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
try {
|
||||
MszSakuya.trackElements($qa('time'));
|
||||
hljs.highlightAll();
|
||||
|
||||
MszEmbed.init(`${location.protocol}//uiharu.${location.host}`);
|
||||
|
||||
// only used by the forum posting form
|
||||
initQuickSubmit();
|
||||
const forumPostingForm = $q('.js-forum-posting');
|
||||
if(forumPostingForm !== null)
|
||||
MszForumEditor(forumPostingForm);
|
||||
|
||||
const events = new MszSeasonalEvents;
|
||||
events.add(new MszChristmas2019EventInfo);
|
||||
events.dispatch();
|
||||
|
||||
await initLoginPage();
|
||||
|
||||
MszMessages();
|
||||
|
||||
MszEmbed.handle($qa('.js-msz-embed-media'));
|
||||
} catch(ex) {
|
||||
console.error(ex);
|
||||
}
|
||||
})();
|
||||
|
|
89
assets/misuzu.js/messages/actbtn.js
Normal file
89
assets/misuzu.js/messages/actbtn.js
Normal file
|
@ -0,0 +1,89 @@
|
|||
#include watcher.js
|
||||
|
||||
const MszMessagesActionButton = function(button, stateless) {
|
||||
if(!(button instanceof Element))
|
||||
throw 'button must be an element';
|
||||
|
||||
const stateful = !stateless;
|
||||
const pub = {};
|
||||
|
||||
const icon = button.querySelector('.js-messages-button-icon i');
|
||||
const label = button.querySelector('.js-messages-button-label');
|
||||
|
||||
const update = () => {
|
||||
if(stateful) {
|
||||
icon.className = button.dataset[`${button.dataset.state}Ico`];
|
||||
label.textContent = button.dataset[`${button.dataset.state}Str`];
|
||||
}
|
||||
};
|
||||
pub.update = update;
|
||||
|
||||
const stateWatcher = new MszWatcher;
|
||||
const getState = () => button.dataset.state !== 'inactive';
|
||||
const setState = state => {
|
||||
button.dataset.state = state ? 'active' : 'inactive';
|
||||
update();
|
||||
stateWatcher.call(getState());
|
||||
};
|
||||
|
||||
if(stateful) {
|
||||
pub.getState = getState;
|
||||
pub.setState = setState;
|
||||
pub.watchState = handler => { stateWatcher.watch(handler, getState()); };
|
||||
pub.unwatchState = handler => { stateWatcher.unwatch(handler); };
|
||||
}
|
||||
|
||||
let clickAction;
|
||||
const click = async () => {
|
||||
if(clickAction !== undefined) {
|
||||
if(stateful) {
|
||||
const result = await clickAction(getState());
|
||||
if(typeof result === 'boolean')
|
||||
setState(result);
|
||||
} else
|
||||
await clickAction();
|
||||
}
|
||||
};
|
||||
pub.click = click;
|
||||
|
||||
button.addEventListener('click', () => click());
|
||||
|
||||
update();
|
||||
|
||||
pub.setAction = action => {
|
||||
if(typeof action !== 'function')
|
||||
throw 'action must be a function';
|
||||
clickAction = action;
|
||||
};
|
||||
|
||||
let preventEnable = false;
|
||||
|
||||
pub.getEnabled = () => !button.disabled;
|
||||
pub.setEnabled = state => {
|
||||
if(!preventEnable)
|
||||
button.disabled = !state;
|
||||
};
|
||||
pub.disableWith = async callback => {
|
||||
if(typeof callback !== 'function')
|
||||
throw 'callback must be a function';
|
||||
if(preventEnable)
|
||||
throw 'preventEnable is true';
|
||||
|
||||
preventEnable = true;
|
||||
const wasDisabled = button.disabled;
|
||||
button.disabled = true;
|
||||
|
||||
try {
|
||||
return await callback();
|
||||
} finally {
|
||||
button.disabled = wasDisabled;
|
||||
preventEnable = false;
|
||||
}
|
||||
};
|
||||
|
||||
pub.setHidden = state => {
|
||||
button.hidden = state;
|
||||
};
|
||||
|
||||
return pub;
|
||||
};
|
167
assets/misuzu.js/messages/list.js
Normal file
167
assets/misuzu.js/messages/list.js
Normal file
|
@ -0,0 +1,167 @@
|
|||
#include utility.js
|
||||
#include watcher.js
|
||||
|
||||
const MsgMessagesList = function(list) {
|
||||
if(!(list instanceof Element))
|
||||
throw 'list must be an element';
|
||||
|
||||
const watchers = new MszWatchers;
|
||||
watchers.define(['select']);
|
||||
|
||||
let selectedCount = 0;
|
||||
|
||||
const items = Array.from(list.querySelectorAll('.js-messages-entry')).map(elem => {
|
||||
const item = new MsgMessagesEntry(elem);
|
||||
item.onSelectedChange((state, initial) => {
|
||||
if(state)
|
||||
++selectedCount;
|
||||
else if(!initial)
|
||||
--selectedCount;
|
||||
|
||||
if(!initial)
|
||||
watchers.call('select', selectedCount, items.length);
|
||||
});
|
||||
return item;
|
||||
});
|
||||
|
||||
const recountSelected = () => {
|
||||
selectedCount = 0;
|
||||
|
||||
for(const item of items)
|
||||
if(item.getSelected())
|
||||
++selectedCount;
|
||||
};
|
||||
|
||||
const onSelectedChange = handler => {
|
||||
watchers.watch('select', handler, selectedCount, items.length);
|
||||
};
|
||||
|
||||
onSelectedChange(selectedCount => {
|
||||
const state = selectedCount > 0;
|
||||
for(const item of items)
|
||||
item.setClickIsSelect(state);
|
||||
});
|
||||
|
||||
return {
|
||||
getItems: () => items,
|
||||
getItemsCount: () => items.length,
|
||||
getSelectedItems: () => {
|
||||
const selected = [];
|
||||
|
||||
for(const item of items)
|
||||
if(item.getSelected())
|
||||
selected.push(item);
|
||||
|
||||
return selected;
|
||||
},
|
||||
removeItem: item => {
|
||||
$ari(items, item);
|
||||
$r(item.getElement());
|
||||
recountSelected();
|
||||
watchers.call('select', selectedCount, items.length);
|
||||
},
|
||||
getAllSelected: () => {
|
||||
if(items.length < 1)
|
||||
return false;
|
||||
|
||||
for(const item of items)
|
||||
if(!item.getSelected())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
},
|
||||
setAllSelected: state => {
|
||||
for(const item of items)
|
||||
item.setSelected(state);
|
||||
selectedCount = state ? items.length : 0;
|
||||
watchers.call('select', selectedCount, items.length);
|
||||
},
|
||||
onSelectedChange: onSelectedChange,
|
||||
};
|
||||
};
|
||||
|
||||
const MsgMessagesEntry = function(entry) {
|
||||
if(!(entry instanceof Element))
|
||||
throw 'entry must be an element';
|
||||
|
||||
const msgId = entry.dataset.msgId;
|
||||
|
||||
const unreadElem = entry.querySelector('.js-messages-entry-unread');
|
||||
const isRead = () => entry.dataset.msgRead === 'read';
|
||||
const setRead = state => {
|
||||
if(state) {
|
||||
entry.dataset.msgRead = 'read';
|
||||
unreadElem.hidden = true;
|
||||
} else {
|
||||
entry.dataset.msgRead = 'unread';
|
||||
unreadElem.hidden = false;
|
||||
}
|
||||
};
|
||||
|
||||
const isSent = () => entry.dataset.msgSent === 'sent';
|
||||
const setSent = state => {
|
||||
entry.dataset.msgRead = state ? 'sent' : 'draft';
|
||||
};
|
||||
|
||||
const checkbox = entry.querySelector('.js-entry-checkbox');
|
||||
const getSelected = () => checkbox.checked;
|
||||
const setSelected = state => checkbox.checked = state;
|
||||
const toggleSelected = () => checkbox.checked = !checkbox.checked;
|
||||
|
||||
let clickIsSelect = false;
|
||||
|
||||
const watchers = new MszWatchers;
|
||||
watchers.define(['select']);
|
||||
|
||||
checkbox.addEventListener('click', ev => ev.stopPropagation());
|
||||
checkbox.addEventListener('keydown', ev => ev.stopPropagation());
|
||||
|
||||
checkbox.addEventListener('change', () => {
|
||||
watchers.call('select', getSelected());
|
||||
});
|
||||
|
||||
const navigateToMessage = () => {
|
||||
const url = entry.dataset.msgUrl;
|
||||
if(url !== undefined && url.startsWith('/') && !url.startsWith('//'))
|
||||
location.assign(url);
|
||||
};
|
||||
|
||||
entry.addEventListener('keydown', ev => {
|
||||
if(ev.key === 'Enter' || ev.key === 'NumpadEnter') {
|
||||
ev.preventDefault();
|
||||
entry.click();
|
||||
}
|
||||
});
|
||||
|
||||
entry.addEventListener('click', ev => {
|
||||
ev.preventDefault();
|
||||
|
||||
if(clickIsSelect)
|
||||
checkbox.click();
|
||||
else
|
||||
navigateToMessage();
|
||||
});
|
||||
|
||||
entry.addEventListener('dblclick', ev => {
|
||||
ev.preventDefault();
|
||||
|
||||
if(clickIsSelect)
|
||||
navigateToMessage();
|
||||
});
|
||||
|
||||
return {
|
||||
getId: () => msgId,
|
||||
getElement: () => entry,
|
||||
isRead: isRead,
|
||||
setRead: setRead,
|
||||
isSent: isSent,
|
||||
setSent: setSent,
|
||||
getSelected: getSelected,
|
||||
setSelected: setSelected,
|
||||
toggleSelected: toggleSelected,
|
||||
setClickIsSelect: state => clickIsSelect = state,
|
||||
onSelectedChange: handler => {
|
||||
watchers.watch('select', handler, getSelected());
|
||||
},
|
||||
};
|
||||
};
|
386
assets/misuzu.js/messages/messages.js
Normal file
386
assets/misuzu.js/messages/messages.js
Normal file
|
@ -0,0 +1,386 @@
|
|||
#include csrfp.js
|
||||
#include msgbox.js
|
||||
#include utility.js
|
||||
#include messages/actbtn.js
|
||||
#include messages/list.js
|
||||
#include messages/recipient.js
|
||||
#include messages/reply.jsx
|
||||
#include messages/thread.js
|
||||
|
||||
const MszMessages = () => {
|
||||
const extractMsgIds = msg => {
|
||||
if(typeof msg.getId === 'function')
|
||||
return msg.getId();
|
||||
if(typeof msg.toString === 'function')
|
||||
return msg.toString();
|
||||
throw 'unsupported message type';
|
||||
};
|
||||
|
||||
const displayErrorMessage = async error => {
|
||||
let text;
|
||||
if(typeof error === 'string')
|
||||
text = error;
|
||||
else if(typeof error.text === 'string')
|
||||
text = error.text;
|
||||
else if(typeof error.toString === 'function')
|
||||
text = error.toString();
|
||||
else
|
||||
text = 'Something indescribable happened.';
|
||||
|
||||
await MszShowMessageBox(text, 'Error');
|
||||
return false;
|
||||
};
|
||||
|
||||
const msgsCreate = async (title, text, parser, draft, recipient, replyTo) => {
|
||||
const formData = new FormData;
|
||||
formData.append('_csrfp', MszCSRFP.getToken());
|
||||
formData.append('title', title);
|
||||
formData.append('body', text);
|
||||
formData.append('parser', parser);
|
||||
formData.append('draft', draft);
|
||||
formData.append('recipient', recipient);
|
||||
formData.append('reply', replyTo);
|
||||
|
||||
const result = await $x.post('/messages/create', { type: 'json' }, formData);
|
||||
|
||||
MszCSRFP.setFromHeaders(result);
|
||||
|
||||
const body = result.body();
|
||||
if(body.error !== undefined)
|
||||
throw body.error;
|
||||
|
||||
return body;
|
||||
};
|
||||
|
||||
const msgsUpdate = async (messageId, title, text, parser, draft) => {
|
||||
const formData = new FormData;
|
||||
formData.append('_csrfp', MszCSRFP.getToken());
|
||||
formData.append('title', title);
|
||||
formData.append('body', text);
|
||||
formData.append('parser', parser);
|
||||
formData.append('draft', draft);
|
||||
|
||||
const result = await $x.post(`/messages/${encodeURIComponent(messageId)}`, { type: 'json' }, formData);
|
||||
|
||||
MszCSRFP.setFromHeaders(result);
|
||||
|
||||
const body = result.body();
|
||||
if(body.error !== undefined)
|
||||
throw body.error;
|
||||
|
||||
return body;
|
||||
};
|
||||
|
||||
const msgsMark = async (msgs, state) => {
|
||||
const result = await $x.post('/messages/mark', { type: 'json' }, {
|
||||
_csrfp: MszCSRFP.getToken(),
|
||||
type: state,
|
||||
messages: msgs.map(extractMsgIds).join(','),
|
||||
});
|
||||
|
||||
MszCSRFP.setFromHeaders(result);
|
||||
|
||||
const body = result.body();
|
||||
if(body.error !== undefined)
|
||||
throw body.error;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const msgsDelete = async msgs => {
|
||||
const result = await $x.post('/messages/delete', { type: 'json' }, {
|
||||
_csrfp: MszCSRFP.getToken(),
|
||||
messages: msgs.map(extractMsgIds).join(','),
|
||||
});
|
||||
|
||||
MszCSRFP.setFromHeaders(result);
|
||||
|
||||
const body = result.body();
|
||||
if(body.error !== undefined)
|
||||
throw body.error;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const msgsRestore = async msgs => {
|
||||
const result = await $x.post('/messages/restore', { type: 'json' }, {
|
||||
_csrfp: MszCSRFP.getToken(),
|
||||
messages: msgs.map(extractMsgIds).join(','),
|
||||
});
|
||||
|
||||
MszCSRFP.setFromHeaders(result);
|
||||
|
||||
const body = result.body();
|
||||
if(body.error !== undefined)
|
||||
throw body.error;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const msgsNuke = async msgs => {
|
||||
const result = await $x.post('/messages/nuke', { type: 'json' }, {
|
||||
_csrfp: MszCSRFP.getToken(),
|
||||
messages: msgs.map(extractMsgIds).join(','),
|
||||
});
|
||||
|
||||
MszCSRFP.setFromHeaders(result);
|
||||
|
||||
const body = result.body();
|
||||
if(body.error !== undefined)
|
||||
throw body.error;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const msgsUserBtns = Array.from($qa('.js-header-pms-button'));
|
||||
if(msgsUserBtns.length > 0)
|
||||
$x.get('/messages/stats', { type: 'json' }).then(result => {
|
||||
const body = result.body();
|
||||
if(typeof body === 'object' && typeof body.unread === 'number')
|
||||
if(body.unread > 0)
|
||||
for(const msgsUserBtn of msgsUserBtns)
|
||||
msgsUserBtn.append($e({ child: body.unread.toLocaleString(), attrs: { className: 'header__desktop__user__button__count' } }));
|
||||
});
|
||||
|
||||
const msgsListElem = $q('.js-messages-list');
|
||||
const msgsList = msgsListElem instanceof Element ? new MsgMessagesList(msgsListElem) : undefined;
|
||||
|
||||
const msgsListEmptyNotice = $q('.js-messages-folder-empty');
|
||||
|
||||
const msgsThreadElem = $q('.js-messages-thread');
|
||||
const msgsThread = msgsThreadElem instanceof Element ? new MszMessagesThread(msgsThreadElem) : undefined;
|
||||
|
||||
const msgsRecipientElem = $q('.js-messages-recipient');
|
||||
const msgsRecipient = msgsRecipientElem instanceof Element ? new MszMessagesRecipient(msgsRecipientElem) : undefined;
|
||||
|
||||
const msgsReplyElem = $q('.js-messages-reply');
|
||||
const msgsReply = msgsReplyElem instanceof Element ? new MszMessagesReply(msgsReplyElem) : undefined;
|
||||
|
||||
if(msgsReply !== undefined) {
|
||||
if(msgsRecipient !== undefined)
|
||||
msgsRecipient.onUpdate(async info => {
|
||||
msgsReply.setRecipient(typeof info.id === 'string' ? info.id : '');
|
||||
msgsReply.setWarning(info.ban ? `${(typeof info.name === 'string' ? info.name : 'This user')} has been banned and will be unable to respond to your messages.` : undefined);
|
||||
});
|
||||
|
||||
msgsReply.onSubmit(async form => {
|
||||
try {
|
||||
let result;
|
||||
if(typeof form.message === 'string') {
|
||||
result = await msgsUpdate(
|
||||
form.message,
|
||||
form.title,
|
||||
form.body,
|
||||
form.parser,
|
||||
form.draft
|
||||
);
|
||||
} else {
|
||||
result = await msgsCreate(
|
||||
form.title,
|
||||
form.body,
|
||||
form.parser,
|
||||
form.draft,
|
||||
form.recipient,
|
||||
form.reply || ''
|
||||
);
|
||||
}
|
||||
|
||||
if(typeof result.url === 'string')
|
||||
location.assign(result.url);
|
||||
} catch(ex) {
|
||||
return await displayErrorMessage(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let actSelectAll, actMarkRead, actMoveTrash, actNuke;
|
||||
|
||||
const actSelectAllBtn = $q('.js-messages-actions-select-all');
|
||||
if(actSelectAllBtn instanceof Element) {
|
||||
actSelectAll = new MszMessagesActionButton(actSelectAllBtn);
|
||||
|
||||
if(msgsList !== undefined) {
|
||||
actSelectAll.setAction(async state => {
|
||||
msgsList.setAllSelected(!state);
|
||||
return !state;
|
||||
});
|
||||
msgsList.onSelectedChange((selectedNo, itemNo) => {
|
||||
actSelectAll.setState(selectedNo >= itemNo);
|
||||
});
|
||||
actSelectAll.setState(msgsList.getAllSelected());
|
||||
}
|
||||
}
|
||||
|
||||
const actMarkReadBtn = $q('.js-messages-actions-mark-read');
|
||||
if(actMarkReadBtn instanceof Element) {
|
||||
actMarkRead = new MszMessagesActionButton(actMarkReadBtn);
|
||||
|
||||
if(msgsList !== undefined) {
|
||||
msgsList.onSelectedChange(selectedNo => {
|
||||
const enabled = selectedNo > 0;
|
||||
actMarkRead.setEnabled(enabled);
|
||||
|
||||
if(enabled) {
|
||||
const items = msgsList.getSelectedItems();
|
||||
let readNo = 0, unreadNo = 0;
|
||||
|
||||
for(const item of items) {
|
||||
if(item.isRead())
|
||||
++readNo;
|
||||
else
|
||||
++unreadNo;
|
||||
}
|
||||
|
||||
actMarkRead.setState(readNo > unreadNo);
|
||||
}
|
||||
});
|
||||
actMarkRead.setAction(async state => {
|
||||
const items = msgsList.getSelectedItems();
|
||||
|
||||
const result = await actMarkRead.disableWith(async () => {
|
||||
try {
|
||||
return await msgsMark(items, state ? 'unread' : 'read');
|
||||
} catch(ex) {
|
||||
return await displayErrorMessage(ex);
|
||||
}
|
||||
});
|
||||
|
||||
if(result) {
|
||||
state = !state;
|
||||
|
||||
for(const item of items)
|
||||
item.setRead(state);
|
||||
|
||||
return state;
|
||||
}
|
||||
});
|
||||
} else if(msgsThread !== undefined) {
|
||||
actMarkRead.setAction(async state => {
|
||||
const items = [msgsThread.getMessage()];
|
||||
|
||||
const result = await actMarkRead.disableWith(async () => {
|
||||
try {
|
||||
return await msgsMark(items, state ? 'unread' : 'read');
|
||||
} catch(ex) {
|
||||
return await displayErrorMessage(ex);
|
||||
}
|
||||
});
|
||||
|
||||
return result ? !state : state;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const actMoveTrashBtn = $q('.js-messages-actions-move-trash');
|
||||
if(actMoveTrashBtn instanceof Element) {
|
||||
actMoveTrash = new MszMessagesActionButton(actMoveTrashBtn);
|
||||
|
||||
if(msgsList !== undefined) {
|
||||
msgsList.onSelectedChange(selectedNo => actMoveTrash.setEnabled(selectedNo > 0));
|
||||
actMoveTrash.setAction(async state => {
|
||||
const items = msgsList.getSelectedItems();
|
||||
|
||||
if(!state && !await MszShowConfirmBox(`Are you sure you wish to delete ${items.length} item${items.length === 1 ? '' : 's'}?`, 'Confirmation'))
|
||||
return;
|
||||
|
||||
const result = await actMoveTrash.disableWith(async () => {
|
||||
try {
|
||||
if(state)
|
||||
return await msgsRestore(items);
|
||||
return await msgsDelete(items);
|
||||
} catch(ex) {
|
||||
return await displayErrorMessage(ex);
|
||||
}
|
||||
});
|
||||
|
||||
if(result)
|
||||
for(const message of items)
|
||||
msgsList.removeItem(message);
|
||||
|
||||
if(msgsListEmptyNotice instanceof Element)
|
||||
msgsListEmptyNotice.hidden = msgsList.getItemsCount() > 0;
|
||||
});
|
||||
} else if(msgsThread !== undefined) {
|
||||
actMoveTrash.setAction(async state => {
|
||||
if(!state && !await MszShowConfirmBox('Are you sure you wish to delete this message?', 'Confirmation'))
|
||||
return;
|
||||
|
||||
const items = [msgsThread.getMessage()];
|
||||
|
||||
const result = await actMoveTrash.disableWith(async () => {
|
||||
try {
|
||||
if(state)
|
||||
return await msgsRestore(items);
|
||||
return await msgsDelete(items);
|
||||
} catch(ex) {
|
||||
return await displayErrorMessage(ex);
|
||||
}
|
||||
});
|
||||
|
||||
if(result) {
|
||||
state = !state;
|
||||
|
||||
if(msgsReply !== undefined)
|
||||
msgsReply.setHidden(state);
|
||||
|
||||
const msg = msgsThread.getMessage();
|
||||
if(msg !== undefined)
|
||||
msg.setDeleted(state);
|
||||
|
||||
return state;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const actNukeBtn = $q('.js-messages-actions-nuke');
|
||||
if(actNukeBtn instanceof Element) {
|
||||
actNuke = new MszMessagesActionButton(actNukeBtn, true);
|
||||
|
||||
if(msgsList !== undefined) {
|
||||
msgsList.onSelectedChange(selectedNo => actNuke.setEnabled(selectedNo > 0));
|
||||
actNuke.setAction(async () => {
|
||||
const items = msgsList.getSelectedItems();
|
||||
|
||||
if(!await MszShowConfirmBox(`Are you sure you wish to PERMANENTLY delete ${items.length} item${items.length === 1 ? '' : 's'}?`, 'Confirmation'))
|
||||
return;
|
||||
|
||||
const result = await actNuke.disableWith(async () => {
|
||||
try {
|
||||
return await msgsNuke(items);
|
||||
} catch(ex) {
|
||||
return await displayErrorMessage(ex);
|
||||
}
|
||||
});
|
||||
|
||||
if(result)
|
||||
for(const message of items)
|
||||
msgsList.removeItem(message);
|
||||
|
||||
if(msgsListEmptyNotice instanceof Element)
|
||||
msgsListEmptyNotice.hidden = msgsList.getItemsCount() > 0;
|
||||
});
|
||||
} else if(msgsThread !== undefined) {
|
||||
actMoveTrash.watchState(state => {
|
||||
actNuke.setHidden(!state);
|
||||
});
|
||||
actNuke.setAction(async () => {
|
||||
if(!await MszShowConfirmBox('Are you sure you wish to PERMANENTLY delete this message?', 'Confirmation'))
|
||||
return;
|
||||
|
||||
const items = [msgsThread.getMessage()];
|
||||
|
||||
const result = await actNuke.disableWith(async () => {
|
||||
try {
|
||||
return await msgsNuke(items);
|
||||
} catch(ex) {
|
||||
return await displayErrorMessage(ex);
|
||||
}
|
||||
});
|
||||
|
||||
if(result)
|
||||
location.assign('/messages');
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
56
assets/misuzu.js/messages/recipient.js
Normal file
56
assets/misuzu.js/messages/recipient.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
#include csrfp.js
|
||||
#include utility.js
|
||||
|
||||
const MszMessagesRecipient = function(element) {
|
||||
if(!(element instanceof Element))
|
||||
throw 'element must be an instance of Element';
|
||||
|
||||
const avatarElem = element.querySelector('.js-messages-recipient-avatar img');
|
||||
const nameInput = element.querySelector('.js-messages-recipient-name');
|
||||
|
||||
let updateHandler = undefined;
|
||||
const update = async () => {
|
||||
const result = await $x.post(element.dataset.msgLookup, { type: 'json' }, {
|
||||
_csrfp: MszCSRFP.getToken(),
|
||||
name: nameInput.value,
|
||||
});
|
||||
|
||||
MszCSRFP.setFromHeaders(result);
|
||||
|
||||
const body = result.body();
|
||||
|
||||
if(updateHandler !== undefined)
|
||||
await updateHandler(body);
|
||||
|
||||
if(typeof body.avatar === 'string')
|
||||
avatarElem.src = body.avatar;
|
||||
|
||||
if(typeof body.name === 'string')
|
||||
nameInput.value = body.name;
|
||||
};
|
||||
|
||||
let nameTimeout = null;
|
||||
nameInput.addEventListener('input', () => {
|
||||
if(nameTimeout !== undefined)
|
||||
return;
|
||||
|
||||
nameTimeout = setTimeout(() => {
|
||||
update().finally(() => {
|
||||
clearTimeout(nameTimeout);
|
||||
nameTimeout = undefined;
|
||||
});
|
||||
}, 750);
|
||||
});
|
||||
|
||||
update().finally(() => nameTimeout = undefined);
|
||||
|
||||
return {
|
||||
getElement: () => element,
|
||||
onUpdate: handler => {
|
||||
if(typeof handler !== 'function')
|
||||
throw 'handler must be a function';
|
||||
|
||||
updateHandler = handler;
|
||||
},
|
||||
};
|
||||
};
|
171
assets/misuzu.js/messages/reply.jsx
Normal file
171
assets/misuzu.js/messages/reply.jsx
Normal file
|
@ -0,0 +1,171 @@
|
|||
#include parsing.js
|
||||
#include ext/eeprom.js
|
||||
|
||||
const MszMessagesReply = function(element) {
|
||||
if(!(element instanceof Element))
|
||||
throw 'element must be an Element';
|
||||
|
||||
const form = element.querySelector('.js-messages-reply-form');
|
||||
const bodyElem = form.querySelector('.js-messages-reply-body');
|
||||
const actsElem = form.querySelector('.js-messages-reply-actions');
|
||||
const parserSelect = form.querySelector('.js-messages-reply-parser');
|
||||
const saveBtn = form.querySelector('.js-messages-reply-save');
|
||||
const sendBtn = form.querySelector('.js-messages-reply-send');
|
||||
const warnElem = form.querySelector('.js-reply-form-warning');
|
||||
const warnText = warnElem instanceof Element ? warnElem.querySelector('.js-reply-form-warning-text') : undefined;
|
||||
|
||||
let submitHandler;
|
||||
form.addEventListener('submit', ev => {
|
||||
ev.preventDefault();
|
||||
|
||||
if(typeof submitHandler === 'function') {
|
||||
const fields = Array.from(form.elements);
|
||||
const result = {};
|
||||
|
||||
for(const field of fields) {
|
||||
if((field instanceof HTMLButtonElement || (field instanceof HTMLInputElement && field.type === 'submit')) && ev.submitter !== field)
|
||||
continue;
|
||||
|
||||
if(typeof field.name === 'string' && field.name.length > 0)
|
||||
result[field.name] = field.value;
|
||||
}
|
||||
|
||||
submitHandler(result);
|
||||
}
|
||||
});
|
||||
|
||||
bodyElem.addEventListener('keydown', ev => {
|
||||
if((ev.code === 'Enter' || ev.code === 'NumpadEnter') && ev.ctrlKey && !ev.altKey && !ev.metaKey) {
|
||||
ev.preventDefault();
|
||||
|
||||
if(ev.shiftKey)
|
||||
saveBtn.click();
|
||||
else
|
||||
sendBtn.click();
|
||||
}
|
||||
});
|
||||
|
||||
const switchButtons = parser => {
|
||||
$rc(actsElem);
|
||||
|
||||
const tags = MszParsing.getTagsFor(parser);
|
||||
actsElem.hidden = tags.length < 1;
|
||||
for(const tag of tags)
|
||||
actsElem.appendChild(<button class="messages-reply-action" type="button" title={tag.summary} onclick={() => $insertTags(bodyElem, tag.open, tag.close)}>
|
||||
<i class={tag.icon}/>
|
||||
</button>);
|
||||
};
|
||||
|
||||
switchButtons(parserSelect.value);
|
||||
|
||||
parserSelect.addEventListener('change', () => {
|
||||
switchButtons(parserSelect.value);
|
||||
});
|
||||
|
||||
// this implementation is godawful but it'll do for now lol
|
||||
// need to make it easier to share the forum's implementation
|
||||
MszEEPROM.init()
|
||||
.catch(() => console.error('Failed to initialise EEPROM'))
|
||||
.then(() => {
|
||||
const eepromClient = new EEPROM(peepApp, peepPath);
|
||||
const eepromHandleFileUpload = async file => {
|
||||
const uploadTask = eepromClient.create(file);
|
||||
|
||||
try {
|
||||
const fileInfo = await uploadTask.start();
|
||||
const parserMode = parseInt(parserSelect.value);
|
||||
let insertText = location.protocol + fileInfo.url;
|
||||
|
||||
if(parserMode == 1) { // bbcode
|
||||
if(fileInfo.isImage())
|
||||
insertText = `[img]${fileInfo.url}[/img]`;
|
||||
else if(fileInfo.isAudio())
|
||||
insertText = `[audio]${fileInfo.url}[/audio]`;
|
||||
else if(fileInfo.isVideo())
|
||||
insertText = `[video]${fileInfo.url}[/video]`;
|
||||
} else if(parserMode == 2) { // markdown
|
||||
if(fileInfo.isMedia())
|
||||
insertText = `![](${fileInfo.url})`;
|
||||
}
|
||||
|
||||
$insertTags(bodyElem, insertText, '');
|
||||
bodyElem.value = bodyElem.value.trim();
|
||||
} catch(ex) {
|
||||
let errorText = 'Upload aborted.';
|
||||
|
||||
if(!ex.aborted) {
|
||||
console.error(ex);
|
||||
errorText = ex.toString();
|
||||
}
|
||||
|
||||
await MszShowMessageBox(errorText, 'Upload Error');
|
||||
}
|
||||
};
|
||||
|
||||
bodyElem.addEventListener('paste', ev => {
|
||||
if(ev.clipboardData && ev.clipboardData.files.length > 0) {
|
||||
ev.preventDefault();
|
||||
|
||||
const files = ev.clipboardData.files;
|
||||
for(const file of files)
|
||||
eepromHandleFileUpload(file);
|
||||
}
|
||||
});
|
||||
|
||||
document.body.addEventListener('dragenter', ev => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
});
|
||||
document.body.addEventListener('dragover', ev => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
});
|
||||
document.body.addEventListener('dragleave', ev => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
});
|
||||
document.body.addEventListener('drop', ev => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
if(ev.dataTransfer && ev.dataTransfer.files.length > 0) {
|
||||
const files = ev.dataTransfer.files;
|
||||
for(const file of files)
|
||||
eepromHandleFileUpload(file);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
getElement: () => element,
|
||||
setWarning: text => {
|
||||
if(warnElem === undefined || warnText === undefined)
|
||||
return;
|
||||
|
||||
if(text === undefined) {
|
||||
warnElem.hidden = true;
|
||||
warnText.textContent = '';
|
||||
} else {
|
||||
warnElem.hidden = false;
|
||||
warnText.textContent = text;
|
||||
}
|
||||
},
|
||||
setRecipient: userId => {
|
||||
for(const field of form.elements)
|
||||
if(field.name === 'recipient') {
|
||||
field.value = userId;
|
||||
break;
|
||||
}
|
||||
},
|
||||
getHidden: () => element.hidden,
|
||||
setHidden: state => {
|
||||
element.hidden = state;
|
||||
},
|
||||
onSubmit: handler => {
|
||||
if(typeof handler !== 'function')
|
||||
throw 'handler must be a function';
|
||||
|
||||
submitHandler = handler;
|
||||
},
|
||||
};
|
||||
};
|
78
assets/misuzu.js/messages/thread.js
Normal file
78
assets/misuzu.js/messages/thread.js
Normal file
|
@ -0,0 +1,78 @@
|
|||
const MszMessagesThread = function(thread) {
|
||||
if(!(thread instanceof Element))
|
||||
throw 'thread must be an element';
|
||||
|
||||
const messages = Array.from(thread.querySelectorAll('.js-messages-message')).map(elem => new MszMessagesThreadMessage(elem));
|
||||
const message = messages.find(msg => msg.isFull());
|
||||
|
||||
return {
|
||||
getMessage: () => message,
|
||||
getMessages: () => messages,
|
||||
};
|
||||
};
|
||||
|
||||
const MszMessagesThreadMessage = function(message) {
|
||||
if(!(message instanceof Element))
|
||||
throw 'message must be an element';
|
||||
|
||||
const msgId = message.dataset.msgId;
|
||||
const type = message.dataset.msgType;
|
||||
const url = message.dataset.msgUrl;
|
||||
|
||||
if(type === 'snip') {
|
||||
message.addEventListener('click', ev => {
|
||||
if(typeof url !== 'string')
|
||||
return;
|
||||
|
||||
let target = ev.target;
|
||||
while(target !== message) {
|
||||
if(target instanceof HTMLAnchorElement)
|
||||
return;
|
||||
|
||||
target = target.parentNode;
|
||||
}
|
||||
|
||||
ev.preventDefault();
|
||||
location.assign(url);
|
||||
});
|
||||
} else if(type === 'full') {
|
||||
message.scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
block: 'start',
|
||||
});
|
||||
}
|
||||
|
||||
const isRead = () => message.dataset.msgRead === 'read';
|
||||
const setRead = state => {
|
||||
message.dataset.msgRead = state ? 'read' : 'unread';
|
||||
};
|
||||
|
||||
const isSent = () => message.dataset.msgSent === 'sent';
|
||||
const setSent = state => {
|
||||
message.dataset.msgRead = state ? 'sent' : 'draft';
|
||||
};
|
||||
|
||||
const isDeleted = () => message.dataset.msgDeleted === 'yes';
|
||||
const setDeleted = state => {
|
||||
if(state) {
|
||||
message.dataset.msgDeleted = 'yes';
|
||||
message.classList.add('messages-message-deleted');
|
||||
} else {
|
||||
message.dataset.msgDeleted = 'no';
|
||||
message.classList.remove('messages-message-deleted');
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
getId: () => msgId,
|
||||
getType: () => type,
|
||||
isFull: () => type === 'full',
|
||||
isSnippet: () => type === 'snip',
|
||||
isRead: isRead,
|
||||
setRead: setRead,
|
||||
isSent: isSent,
|
||||
setSent: setSent,
|
||||
isDeleted: isDeleted,
|
||||
setDeleted: setDeleted,
|
||||
};
|
||||
};
|
73
assets/misuzu.js/msgbox.jsx
Normal file
73
assets/misuzu.js/msgbox.jsx
Normal file
|
@ -0,0 +1,73 @@
|
|||
#include utility.js
|
||||
|
||||
const MszShowConfirmBox = async (text, title, target) => {
|
||||
let result = false;
|
||||
|
||||
await MszShowMessageBox(text, title, [
|
||||
{ text: 'Yes', callback: async () => result = true },
|
||||
{ text: 'No' },
|
||||
], target);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
const MszShowMessageBox = (text, title, buttons, target) => {
|
||||
if(typeof text !== 'string') {
|
||||
if(text !== undefined && text !== null && typeof text.toString === 'function')
|
||||
text = text.toString();
|
||||
else throw 'text must be a string';
|
||||
}
|
||||
if(!(target instanceof Element))
|
||||
target = document.body;
|
||||
|
||||
if(typeof title !== 'string')
|
||||
title = 'Information';
|
||||
if(!Array.isArray(buttons))
|
||||
buttons = [];
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if(target.querySelector('.messagebox')) {
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
|
||||
let buttonsElem;
|
||||
const html = <div class="messagebox">
|
||||
<div class="container messagebox__container">
|
||||
<div class="container__title">
|
||||
<div class="container__title__background"/>
|
||||
<div class="container__title__text">{title}</div>
|
||||
</div>
|
||||
<div class="container__content">{text}</div>
|
||||
{buttonsElem = <div class="messagebox__buttons"/>}
|
||||
</div>
|
||||
</div>;
|
||||
|
||||
let firstButton;
|
||||
if(buttons.length < 1) {
|
||||
firstButton = <button class="input__button" onclick={() => {
|
||||
html.remove();
|
||||
resolve();
|
||||
}}>OK</button>;
|
||||
buttonsElem.appendChild(firstButton);
|
||||
} else {
|
||||
for(const button of buttons) {
|
||||
const buttonElem = <button class="input__button" onclick={() => {
|
||||
html.remove();
|
||||
|
||||
if(typeof button.callback === 'function')
|
||||
button.callback().finally(() => resolve());
|
||||
else
|
||||
resolve();
|
||||
}}>{button.text}</button>;
|
||||
buttonsElem.appendChild(buttonElem);
|
||||
|
||||
if(firstButton === undefined)
|
||||
firstButton = buttonElem;
|
||||
}
|
||||
}
|
||||
|
||||
target.appendChild(html);
|
||||
firstButton.focus();
|
||||
});
|
||||
};
|
56
assets/misuzu.js/parsing.js
Normal file
56
assets/misuzu.js/parsing.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
// welcome to the shitty temporary file for managing the bbcode/markdown/whatever button
|
||||
const MszParsing = (() => {
|
||||
const defineTag = (name, open, close, summary, icon) => {
|
||||
return {
|
||||
name: name,
|
||||
open: open,
|
||||
close: close,
|
||||
summary: summary,
|
||||
icon: icon,
|
||||
};
|
||||
};
|
||||
|
||||
const bbTags = [
|
||||
defineTag('bb-bold', '[b]', '[/b]', 'Bold [b]<text>[/b]', 'fas fa-bold fa-fw'),
|
||||
defineTag('bb-italic', '[i]', '[/i]', 'Italic [i]<text>[/i]', 'fas fa-italic fa-fw'),
|
||||
defineTag('bb-underline', '[u]', '[/u]', 'Underline [u]<text>[/u]', 'fas fa-underline fa-fw'),
|
||||
defineTag('bb-strike', '[s]', '[/s]', 'Strikethrough [s]<text>[/s]', 'fas fa-strikethrough fa-fw'),
|
||||
defineTag('bb-link', '[url=]', '[/url]', 'Link [url]<url>[/url] or [url=<url>]<text>[/url]', 'fas fa-link fa-fw'),
|
||||
defineTag('bb-image', '[img]', '[/img]', 'Image [img]<url>[/img]', 'fas fa-image fa-fw'),
|
||||
defineTag('bb-audio', '[audio]', '[/audio]', 'Audio [audio]<url>[/audio]', 'fas fa-music fa-fw'),
|
||||
defineTag('bb-video', '[video]', '[/video]', 'Video [video]<url>[/video]', 'fas fa-video fa-fw'),
|
||||
defineTag('bb-code', '[code]', '[/code]', 'Code [code]<code>[/code]', 'fas fa-code fa-fw'),
|
||||
defineTag('bb-zalgo', '[zalgo]', '[/zalgo]', 'Zalgo [zalgo]<text>[/zalgo]', 'fas fa-frog fa-fw'),
|
||||
];
|
||||
|
||||
const mdTags = [
|
||||
defineTag('md-bold', '**', '**', 'Bold **<text>**', 'fas fa-bold fa-fw'),
|
||||
defineTag('md-italic', '*', '*', 'Italic *<text>* or _<text>_', 'fas fa-italic fa-fw'),
|
||||
defineTag('md-underline', '__', '__', 'Underline __<text>__', 'fas fa-underline fa-fw'),
|
||||
defineTag('md-strike', '~~', '~~', 'Strikethrough ~~<text>~~', 'fas fa-strikethrough fa-fw'),
|
||||
defineTag('md-link', '[](', ')', 'Link [<text>](<url>)', 'fas fa-link fa-fw'),
|
||||
defineTag('md-image', '![](', ')', 'Image ![<alt text>](<url>)', 'fas fa-image fa-fw'),
|
||||
defineTag('md-audio', '![](', ')', 'Audio ![<alt text>](<url>)', 'fas fa-music fa-fw'),
|
||||
defineTag('md-video', '![](', ')', 'Video ![<alt text>](<url>)', 'fas fa-video fa-fw'),
|
||||
defineTag('md-code', '```', '```', 'Code `<code>` or ```<code>```', 'fas fa-code fa-fw'),
|
||||
];
|
||||
|
||||
const getTagsFor = parser => {
|
||||
if(typeof parser !== 'number')
|
||||
parser = parseInt(parser);
|
||||
|
||||
if(parser === 1)
|
||||
return bbTags;
|
||||
if(parser === 2)
|
||||
return mdTags;
|
||||
|
||||
return [];
|
||||
};
|
||||
|
||||
return {
|
||||
getTagsFor: getTagsFor,
|
||||
getTagsForPlainText: () => getTagsFor(0),
|
||||
getTagsForBBcode: () => getTagsFor(1),
|
||||
getTagsForMarkdown: () => getTagsFor(2),
|
||||
};
|
||||
})();
|
|
@ -1,58 +0,0 @@
|
|||
const Uiharu = function(apiUrl) {
|
||||
const maxBatchSize = 4;
|
||||
const lookupOneUrl = apiUrl + '/metadata',
|
||||
lookupManyUrl = apiUrl + '/metadata/batch';
|
||||
|
||||
const lookupManyInternal = function(targetUrls, callback) {
|
||||
const formData = new FormData;
|
||||
|
||||
for(const url of targetUrls)
|
||||
formData.append('url[]', url);
|
||||
|
||||
const xhr = new XMLHttpRequest;
|
||||
xhr.addEventListener('load', function() {
|
||||
callback(JSON.parse(xhr.responseText));
|
||||
});
|
||||
xhr.addEventListener('error', function(ev) {
|
||||
callback({ status: xhr.status, error: 'xhr', details: ev });
|
||||
});
|
||||
xhr.open('POST', lookupManyUrl);
|
||||
xhr.send(formData);
|
||||
};
|
||||
|
||||
return {
|
||||
lookupOne: function(targetUrl, callback) {
|
||||
if(typeof callback !== 'function')
|
||||
throw 'callback is missing';
|
||||
targetUrl = (targetUrl || '').toString();
|
||||
if(targetUrl.length < 1)
|
||||
return;
|
||||
|
||||
const xhr = new XMLHttpRequest;
|
||||
xhr.addEventListener('load', function() {
|
||||
callback(JSON.parse(xhr.responseText));
|
||||
});
|
||||
xhr.addEventListener('error', function() {
|
||||
callback({ status: xhr.status, error: 'xhr', details: ex });
|
||||
});
|
||||
xhr.open('POST', lookupOneUrl);
|
||||
xhr.send(targetUrl);
|
||||
},
|
||||
lookupMany: function(targetUrls, callback) {
|
||||
if(!Array.isArray(targetUrls))
|
||||
throw 'targetUrls must be an array of urls';
|
||||
if(typeof callback !== 'function')
|
||||
throw 'callback is missing';
|
||||
if(targetUrls < 1)
|
||||
return;
|
||||
|
||||
if(targetUrls.length <= maxBatchSize) {
|
||||
lookupManyInternal(targetUrls, callback);
|
||||
return;
|
||||
}
|
||||
|
||||
for(let i = 0; i < targetUrls.length; i += maxBatchSize)
|
||||
lookupManyInternal(targetUrls.slice(i, i + maxBatchSize), callback);
|
||||
},
|
||||
};
|
||||
};
|
|
@ -13,6 +13,10 @@ const $ri = function(name) {
|
|||
$r($i(name));
|
||||
};
|
||||
|
||||
const $rq = function(query) {
|
||||
$r($q(query));
|
||||
};
|
||||
|
||||
const $ib = function(ref, elem) {
|
||||
ref.parentNode.insertBefore(elem, ref);
|
||||
};
|
||||
|
@ -79,6 +83,11 @@ const $e = function(info, attrs, child, created) {
|
|||
}
|
||||
break;
|
||||
|
||||
case 'boolean':
|
||||
if(attr)
|
||||
elem.setAttribute(key, '');
|
||||
break;
|
||||
|
||||
default:
|
||||
if(key === 'className')
|
||||
key = 'class';
|
||||
|
@ -153,17 +162,125 @@ const $as = function(array) {
|
|||
}
|
||||
};
|
||||
|
||||
var $insertTags = function(target, tagOpen, tagClose) {
|
||||
const $x = (function() {
|
||||
const send = function(method, url, options, body) {
|
||||
if(options === undefined)
|
||||
options = {};
|
||||
else if(typeof options !== 'object')
|
||||
throw 'options must be undefined or an object';
|
||||
|
||||
const xhr = new XMLHttpRequest;
|
||||
const requestHeaders = new Map;
|
||||
|
||||
if('headers' in options && typeof options.headers === 'object')
|
||||
for(const name in options.headers)
|
||||
if(options.headers.hasOwnProperty(name))
|
||||
requestHeaders.set(name.toLowerCase(), options.headers[name]);
|
||||
|
||||
if(typeof options.download === 'function') {
|
||||
xhr.onloadstart = ev => options.download(ev);
|
||||
xhr.onprogress = ev => options.download(ev);
|
||||
xhr.onloadend = ev => options.download(ev);
|
||||
}
|
||||
|
||||
if(typeof options.upload === 'function') {
|
||||
xhr.upload.onloadstart = ev => options.upload(ev);
|
||||
xhr.upload.onprogress = ev => options.upload(ev);
|
||||
xhr.upload.onloadend = ev => options.upload(ev);
|
||||
}
|
||||
|
||||
if(options.authed)
|
||||
xhr.withCredentials = true;
|
||||
|
||||
if(typeof options.timeout === 'number')
|
||||
xhr.timeout = options.timeout;
|
||||
|
||||
if(typeof options.type === 'string')
|
||||
xhr.responseType = options.type;
|
||||
|
||||
if(typeof options.abort === 'function')
|
||||
options.abort(() => xhr.abort());
|
||||
|
||||
if(typeof options.xhr === 'function')
|
||||
options.xhr(() => xhr);
|
||||
|
||||
if(typeof body === 'object') {
|
||||
if(body instanceof URLSearchParams) {
|
||||
requestHeaders.set('content-type', 'application/x-www-form-urlencoded');
|
||||
} else if(body instanceof FormData) {
|
||||
// content-type is implicitly set
|
||||
} else if(body instanceof Blob || body instanceof ArrayBuffer || body instanceof DataView) {
|
||||
if(!requestHeaders.has('content-type'))
|
||||
requestHeaders.set('content-type', 'application/octet-stream');
|
||||
} else if(!requestHeaders.has('content-type')) {
|
||||
const bodyParts = [];
|
||||
for(const name in body)
|
||||
if(body.hasOwnProperty(name))
|
||||
bodyParts.push(encodeURIComponent(name) + '=' + encodeURIComponent(body[name]));
|
||||
body = bodyParts.join('&');
|
||||
requestHeaders.set('content-type', 'application/x-www-form-urlencoded');
|
||||
}
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
let responseHeaders = undefined;
|
||||
|
||||
xhr.onload = ev => resolve({
|
||||
status: xhr.status,
|
||||
body: () => xhr.response,
|
||||
text: () => xhr.responseText,
|
||||
headers: () => {
|
||||
if(responseHeaders !== undefined)
|
||||
return responseHeaders;
|
||||
|
||||
responseHeaders = new Map;
|
||||
|
||||
const raw = xhr.getAllResponseHeaders().trim().split(/[\r\n]+/);
|
||||
for(const name in raw)
|
||||
if(raw.hasOwnProperty(name)) {
|
||||
const parts = raw[name].split(': ');
|
||||
responseHeaders.set(parts.shift(), parts.join(': '));
|
||||
}
|
||||
|
||||
return responseHeaders;
|
||||
},
|
||||
xhr: xhr,
|
||||
ev: ev,
|
||||
});
|
||||
|
||||
xhr.onerror = ev => reject({
|
||||
xhr: xhr,
|
||||
ev: ev,
|
||||
});
|
||||
|
||||
xhr.open(method, url);
|
||||
for(const [name, value] of requestHeaders)
|
||||
xhr.setRequestHeader(name, value);
|
||||
xhr.send(body);
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
send: send,
|
||||
get: (url, options, body) => send('GET', url, options, body),
|
||||
post: (url, options, body) => send('POST', url, options, body),
|
||||
delete: (url, options, body) => send('DELETE', url, options, body),
|
||||
patch: (url, options, body) => send('PATCH', url, options, body),
|
||||
put: (url, options, body) => send('PUT', url, options, body),
|
||||
};
|
||||
})();
|
||||
|
||||
const $insertTags = function(target, tagOpen, tagClose) {
|
||||
tagOpen = tagOpen || '';
|
||||
tagClose = tagClose || '';
|
||||
|
||||
if(document.selection) {
|
||||
target.focus();
|
||||
var selected = document.selection.createRange();
|
||||
const selected = document.selection.createRange();
|
||||
selected.text = tagOpen + selected.text + tagClose;
|
||||
target.focus();
|
||||
} else if(target.selectionStart || target.selectionStart === 0) {
|
||||
var startPos = target.selectionStart,
|
||||
const startPos = target.selectionStart,
|
||||
endPos = target.selectionEnd,
|
||||
scrollTop = target.scrollTop;
|
||||
|
||||
|
@ -176,7 +293,7 @@ var $insertTags = function(target, tagOpen, tagClose) {
|
|||
target.focus();
|
||||
target.selectionStart = startPos + tagOpen.length;
|
||||
target.selectionEnd = endPos + tagOpen.length;
|
||||
target.scrollTop + scrollTop;
|
||||
target.scrollTop = scrollTop;
|
||||
} else {
|
||||
target.value += tagOpen + tagClose;
|
||||
target.focus();
|
|
@ -1,83 +1,65 @@
|
|||
const MszWatcher = function() {
|
||||
let watchers = [];
|
||||
const handlers = [];
|
||||
|
||||
return {
|
||||
watch: function(watcher, thisArg, args) {
|
||||
if(typeof watcher !== 'function')
|
||||
throw 'watcher must be a function';
|
||||
if(watchers.indexOf(watcher) >= 0)
|
||||
return;
|
||||
const watch = (handler, ...args) => {
|
||||
if(typeof handler !== 'function')
|
||||
throw 'handler must be a function';
|
||||
if(handlers.includes(handler))
|
||||
throw 'handler already registered';
|
||||
|
||||
watchers.push(watcher);
|
||||
|
||||
if(thisArg !== undefined) {
|
||||
if(!Array.isArray(args)) {
|
||||
if(args !== undefined)
|
||||
args = [args];
|
||||
else args = [];
|
||||
}
|
||||
|
||||
// initial call
|
||||
args.push(true);
|
||||
|
||||
watcher.apply(thisArg, args);
|
||||
}
|
||||
},
|
||||
unwatch: function(watcher) {
|
||||
$ari(watchers, watcher);
|
||||
},
|
||||
call: function(thisArg, args) {
|
||||
if(!Array.isArray(args)) {
|
||||
if(args !== undefined)
|
||||
args = [args];
|
||||
else args = [];
|
||||
}
|
||||
|
||||
args.push(false);
|
||||
|
||||
for(const watcher of watchers)
|
||||
watcher.apply(thisArg, args);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const MszWatcherCollection = function() {
|
||||
const collection = new Map;
|
||||
|
||||
const watch = function(name, watcher, thisArg, args) {
|
||||
const watchers = collection.get(name);
|
||||
if(watchers === undefined)
|
||||
throw 'undefined watcher name';
|
||||
watchers.watch(watcher, thisArg, args);
|
||||
handlers.push(handler);
|
||||
args.push(true);
|
||||
handler(...args);
|
||||
};
|
||||
|
||||
const unwatch = function(name, watcher) {
|
||||
const watchers = collection.get(name);
|
||||
if(watchers === undefined)
|
||||
throw 'undefined watcher name';
|
||||
watchers.unwatch(watcher);
|
||||
const unwatch = handler => {
|
||||
$ari(handlers, handler);
|
||||
};
|
||||
|
||||
return {
|
||||
define: function(names) {
|
||||
if(!Array.isArray(names))
|
||||
names = [names];
|
||||
for(const name of names)
|
||||
collection.set(name, new MszWatcher);
|
||||
},
|
||||
call: function(name, thisArg, args) {
|
||||
const watchers = collection.get(name);
|
||||
if(watchers === undefined)
|
||||
throw 'undefined watcher name';
|
||||
watchers.call(thisArg, args);
|
||||
},
|
||||
watch: watch,
|
||||
unwatch: unwatch,
|
||||
proxy: function(obj) {
|
||||
obj.watch = function(name, watcher) {
|
||||
watch(name, watcher);
|
||||
};
|
||||
obj.unwatch = unwatch;
|
||||
call: (...args) => {
|
||||
args.push(false);
|
||||
|
||||
for(const handler of handlers)
|
||||
handler(...args);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const MszWatchers = function() {
|
||||
const watchers = new Map;
|
||||
|
||||
const getWatcher = name => {
|
||||
const watcher = watchers.get(name);
|
||||
if(watcher === undefined)
|
||||
throw 'undefined watcher name';
|
||||
return watcher;
|
||||
};
|
||||
|
||||
const watch = (name, handler, ...args) => {
|
||||
getWatcher(name).watch(handler, ...args);
|
||||
};
|
||||
|
||||
const unwatch = (name, handler) => {
|
||||
getWatcher(name).unwatch(handler);
|
||||
};
|
||||
|
||||
return {
|
||||
watch: watch,
|
||||
unwatch: unwatch,
|
||||
define: names => {
|
||||
if(typeof names === 'string')
|
||||
watchers.set(names, new MszWatcher);
|
||||
else if(Array.isArray(names))
|
||||
for(const name of names)
|
||||
watchers.set(name, new MszWatcher);
|
||||
else
|
||||
throw 'names must be an array of names or a single name';
|
||||
},
|
||||
call: (name, ...args) => {
|
||||
getWatcher(name).call(...args);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
const crypto = require('crypto');
|
||||
|
||||
exports.strtr = (str, replacements) => str.toString().replace(
|
||||
/{([^}]+)}/g, (match, key) => replacements[key] || match
|
||||
);
|
||||
|
||||
const trim = function(str, chars, flags) {
|
||||
if(chars === undefined)
|
||||
chars = " \n\r\t\v\0";
|
||||
|
|
146
build.js
146
build.js
|
@ -1,3 +1,4 @@
|
|||
// IMPORTS
|
||||
const fs = require('fs');
|
||||
const swc = require('@swc/core');
|
||||
const path = require('path');
|
||||
|
@ -6,25 +7,42 @@ const postcss = require('postcss');
|
|||
const utils = require('./assets/utils.js');
|
||||
const assproc = require('./assets/assproc.js');
|
||||
|
||||
|
||||
// CONFIG
|
||||
const rootDir = __dirname;
|
||||
const modulesDir = path.join(rootDir, 'node_modules');
|
||||
|
||||
const assetsDir = path.join(rootDir, 'assets');
|
||||
const assetsCSS = path.join(assetsDir, 'misuzu.css');
|
||||
const assetsJS = path.join(assetsDir, 'misuzu.js');
|
||||
const assetsInfo = path.join(assetsDir, 'current.json');
|
||||
|
||||
const srcDir = path.join(rootDir, 'assets');
|
||||
const srcCurrentInfo = path.join(srcDir, 'current.json');
|
||||
const pubDir = path.join(rootDir, 'public');
|
||||
const pubIndex = path.join(pubDir, 'index.html');
|
||||
const pubAssets = '/assets';
|
||||
const pubAssetsFull = path.join(pubDir, pubAssets);
|
||||
const pubAssetCSSFormat = '%s-%s.css';
|
||||
const pubAssetJSFormat = '%s-%s.js';
|
||||
const pubAssetsDir = path.join(pubDir, 'assets');
|
||||
|
||||
const isDebugBuild = fs.existsSync(path.join(rootDir, '.debug'));
|
||||
|
||||
const buildTasks = {
|
||||
js: [
|
||||
{ source: 'misuzu.js', target: '/assets', name: 'misuzu.{hash}.js', },
|
||||
],
|
||||
css: [
|
||||
{ source: 'misuzu.css', target: '/assets', name: 'misuzu.{hash}.css', },
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
// PREP
|
||||
const postcssPlugins = [ require('autoprefixer')({ remove: false }) ];
|
||||
if(!isDebugBuild)
|
||||
postcssPlugins.push(require('cssnano')({
|
||||
preset: [
|
||||
'cssnano-preset-default',
|
||||
{
|
||||
minifyGradients: false,
|
||||
reduceIdents: false,
|
||||
zindex: true,
|
||||
}
|
||||
],
|
||||
}));
|
||||
|
||||
const swcJscOptions = {
|
||||
target: 'es2016',
|
||||
target: 'es2021',
|
||||
loose: false,
|
||||
externalHelpers: false,
|
||||
keepClassNames: true,
|
||||
|
@ -51,39 +69,89 @@ const swcJscOptions = {
|
|||
},
|
||||
};
|
||||
|
||||
const postcssPlugins = [];
|
||||
if(!isDebugBuild) postcssPlugins.push(require('cssnano'));
|
||||
postcssPlugins.push(require('autoprefixer')({
|
||||
remove: false,
|
||||
}));
|
||||
|
||||
fs.mkdirSync(pubAssetsFull, { recursive: true });
|
||||
|
||||
// BUILD
|
||||
(async () => {
|
||||
const mszCssName = await assproc.process(assetsCSS, { 'prefix': '@', 'entry': 'main.css' })
|
||||
.then(output => postcss(postcssPlugins).process(output, { from: assetsCSS }).then(output => {
|
||||
const mszCssName = path.join(pubAssets, util.format(pubAssetCSSFormat, 'misuzu', utils.shortHash(output.css)));
|
||||
fs.writeFileSync(path.join(pubDir, mszCssName), output.css);
|
||||
return mszCssName;
|
||||
}));
|
||||
const files = {};
|
||||
|
||||
const mszJsName = await assproc.process(assetsJS, { 'prefix': '#', 'entry': 'main.js' })
|
||||
.then(output => swc.transform(output, {
|
||||
filename: 'misuzu.js',
|
||||
console.log('Ensuring assets directory exists...');
|
||||
fs.mkdirSync(pubAssetsDir, { recursive: true });
|
||||
|
||||
|
||||
console.log();
|
||||
console.log('JS assets');
|
||||
for(const info of buildTasks.js) {
|
||||
console.log(`=> Building ${info.source}...`);
|
||||
|
||||
let origTarget = undefined;
|
||||
if('es' in info) {
|
||||
origTarget = swcJscOptions.target;
|
||||
swcJscOptions.target = info.es;
|
||||
}
|
||||
|
||||
const assprocOpts = {
|
||||
prefix: '#',
|
||||
entry: info.entry || 'main.js',
|
||||
};
|
||||
const swcOpts = {
|
||||
filename: info.source,
|
||||
sourceMaps: false,
|
||||
isModule: false,
|
||||
minify: !isDebugBuild,
|
||||
jsc: swcJscOptions,
|
||||
}).then(async output => {
|
||||
const mszJsName = path.join(pubAssets, util.format(pubAssetJSFormat, 'misuzu', utils.shortHash(output.code)));
|
||||
fs.writeFileSync(path.join(pubDir, mszJsName), output.code);
|
||||
return mszJsName;
|
||||
}));
|
||||
};
|
||||
|
||||
fs.writeFileSync(assetsInfo, JSON.stringify({
|
||||
mszjs: mszJsName,
|
||||
mszcss: mszCssName,
|
||||
}));
|
||||
const pubName = await assproc.process(path.join(srcDir, info.source), assprocOpts)
|
||||
.then(output => swc.transform(output, swcOpts))
|
||||
.then(output => {
|
||||
const name = utils.strtr(info.name, { hash: utils.shortHash(output.code) });
|
||||
const pubName = path.join(info.target || '', name);
|
||||
|
||||
assproc.housekeep(pubAssetsFull);
|
||||
console.log(` Saving to ${pubName}...`);
|
||||
fs.writeFileSync(path.join(pubDir, pubName), output.code);
|
||||
|
||||
return pubName;
|
||||
});
|
||||
|
||||
if(origTarget !== undefined)
|
||||
swcJscOptions.target = origTarget;
|
||||
|
||||
files[info.source] = pubName;
|
||||
}
|
||||
|
||||
|
||||
console.log();
|
||||
console.log('CSS assets');
|
||||
for(const info of buildTasks.css) {
|
||||
console.log(`=> Building ${info.source}...`);
|
||||
|
||||
const sourcePath = path.join(srcDir, info.source);
|
||||
const assprocOpts = {
|
||||
prefix: '@',
|
||||
entry: info.entry || 'main.css',
|
||||
};
|
||||
const postcssOpts = { from: sourcePath };
|
||||
|
||||
files[info.source] = await assproc.process(sourcePath, assprocOpts)
|
||||
.then(output => postcss(postcssPlugins).process(output, postcssOpts)
|
||||
.then(output => {
|
||||
const name = utils.strtr(info.name, { hash: utils.shortHash(output.css) });
|
||||
const pubName = path.join(info.target || '', name);
|
||||
|
||||
console.log(` Saving to ${pubName}...`);
|
||||
fs.writeFileSync(path.join(pubDir, pubName), output.css);
|
||||
|
||||
return pubName;
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
console.log();
|
||||
console.log('Writing assets info...');
|
||||
fs.writeFileSync(srcCurrentInfo, JSON.stringify(files));
|
||||
|
||||
|
||||
console.log();
|
||||
console.log('Cleaning up old builds...');
|
||||
assproc.housekeep(pubAssetsDir);
|
||||
})();
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
"chillerlan/php-qrcode": "^4.3",
|
||||
"symfony/mailer": "^6.0",
|
||||
"matomo/device-detector": "^6.1",
|
||||
"sentry/sdk": "^3.5",
|
||||
"sentry/sdk": "^4.0",
|
||||
"flashwave/syokuhou": "dev-master"
|
||||
},
|
||||
"autoload": {
|
||||
|
|
1269
composer.lock
generated
1269
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -41,9 +41,7 @@ final class NewPermissionsSystem_20230830_213930 implements IDbMigration {
|
|||
$conn->execute('
|
||||
ALTER TABLE msz_perms
|
||||
ADD CONSTRAINT perms_53bit
|
||||
CHECK (perms_allow >= 0 AND perms_deny >= 0 AND perms_allow <= 9007199254740991 AND perms_deny <= 9007199254740991),
|
||||
ADD CONSTRAINT perms_only_user_or_role
|
||||
CHECK ((user_id IS NULL AND role_id IS NULL) OR (user_id IS NULL AND role_id IS NOT NULL) OR (user_id IS NOT NULL AND role_id IS NULL))
|
||||
CHECK (perms_allow >= 0 AND perms_deny >= 0 AND perms_allow <= 9007199254740991 AND perms_deny <= 9007199254740991)
|
||||
');
|
||||
|
||||
$conn->execute('
|
||||
|
|
48
database/2024_01_30_233734_create_messages_table.php
Normal file
48
database/2024_01_30_233734_create_messages_table.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
use Index\Data\IDbConnection;
|
||||
use Index\Data\Migration\IDbMigration;
|
||||
|
||||
final class CreateMessagesTable_20240130_233734 implements IDbMigration {
|
||||
public function migrate(IDbConnection $conn): void {
|
||||
$conn->execute('
|
||||
CREATE TABLE msz_messages (
|
||||
msg_id BINARY(8) NOT NULL,
|
||||
msg_owner_id INT(10) UNSIGNED NOT NULL,
|
||||
msg_author_id INT(10) UNSIGNED NULL DEFAULT NULL,
|
||||
msg_recipient_id INT(10) UNSIGNED NULL DEFAULT NULL,
|
||||
msg_reply_to BINARY(8) NULL DEFAULT NULL,
|
||||
msg_title TINYTEXT NOT NULL COLLATE "utf8mb4_unicode_520_ci",
|
||||
msg_body TEXT NOT NULL COLLATE "utf8mb4_unicode_520_ci",
|
||||
msg_parser TINYINT(3) UNSIGNED NOT NULL,
|
||||
msg_created TIMESTAMP NOT NULL DEFAULT current_timestamp(),
|
||||
msg_sent TIMESTAMP NULL DEFAULT NULL,
|
||||
msg_read TIMESTAMP NULL DEFAULT NULL,
|
||||
msg_deleted TIMESTAMP NULL DEFAULT NULL,
|
||||
PRIMARY KEY (msg_id, msg_owner_id),
|
||||
KEY messages_owner_foreign (msg_owner_id),
|
||||
KEY messages_author_foreign (msg_author_id),
|
||||
KEY messages_recipient_foreign (msg_recipient_id),
|
||||
KEY messages_reply_to_index (msg_reply_to),
|
||||
KEY messages_created_index (msg_created),
|
||||
KEY messages_sent_index (msg_sent),
|
||||
KEY messages_read_index (msg_read),
|
||||
KEY messages_deleted_index (msg_deleted),
|
||||
CONSTRAINT messages_owner_foreign
|
||||
FOREIGN KEY (msg_owner_id)
|
||||
REFERENCES msz_users (user_id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE,
|
||||
CONSTRAINT messages_author_foreign
|
||||
FOREIGN KEY (msg_author_id)
|
||||
REFERENCES msz_users (user_id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE SET NULL,
|
||||
CONSTRAINT messages_recipient_foreign
|
||||
FOREIGN KEY (msg_recipient_id)
|
||||
REFERENCES msz_users (user_id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE SET NULL
|
||||
) ENGINE=InnoDB COLLATE=utf8mb4_bin;
|
||||
');
|
||||
}
|
||||
}
|
|
@ -1,12 +1,29 @@
|
|||
# Source Code Repositories
|
||||
|
||||
- [Misuzu](https://git.flash.moe/flashii/misuzu): Backend of the main website.
|
||||
- [Sharp Chat](https://git.flash.moe/flashii/sharp-chat): Chat Server software.
|
||||
- [Backup Manager](https://git.flash.moe/flashii/backup-manager): Program that runs every day at 12:00am UTC to back up any user generated content.
|
||||
- [Index](https://git.flash.moe/flash/index): Base library used in almost any component of the website that uses PHP.
|
||||
- [Uiharu](https://git.flash.moe/flashii/uiharu): Service for looking up URL metadata.
|
||||
- [Futami](https://git.flash.moe/flashii/futami): Common data shared between the chat clients.
|
||||
- [AJAX Chat (fork)](https://git.flash.moe/flashii/ajax-chat): Old chat software (2013-2015).
|
||||
- [Seria](https://git.flash.moe/flashii/seria): Software used by the torrent tracker.
|
||||
- [Mince](https://git.flash.moe/flashii/mince): Source code for the Minecraft servers subwebsite.
|
||||
- [Awaki](https://git.flash.moe/flashii/awaki): Redirect service hosted on fii.moe.
|
||||
Below are a number of links to source code repositories related to Flashii.net and its services.
|
||||
|
||||
## Websites & Services
|
||||
- [Misuzu](https://patchii.net/flashii/misuzu): Backend of the main website.
|
||||
- [Sharp Chat](https://patchii.net/flashii/sharp-chat): Chat Server software.
|
||||
- [Futami](https://patchii.net/flashii/futami): Common data shared between the chat clients.
|
||||
- [Mami](https://patchii.net/flashii/mami): Web client for chat.
|
||||
- [Ami](https://patchii.net/flashii/ami): Web client for chat for older browsers.
|
||||
- [EEPROM](https://patchii.net/flashii/eeprom): Service for file uploading.
|
||||
- [Uiharu](https://patchii.net/flashii/uiharu): Service for looking up URL metadata.
|
||||
- [Seria](https://patchii.net/flashii/seria): Software used by the downloads tracker.
|
||||
- [Mince](https://patchii.net/flashii/mince): Source code for the Minecraft servers subwebsite.
|
||||
- [Awaki](https://patchii.net/flashii/awaki): Redirect service hosted on fii.moe.
|
||||
|
||||
## Tools & Software
|
||||
- [SoFii](https://patchii.net/flashii/sofii): Launcher for Soldier of Fortune 2
|
||||
- [MCExts](https://patchii.net/flashii/mcexts): Minecraft Client and Server extensions.
|
||||
- [Backup Tools](https://patchii.net/flashii/backup-tools): Scripts that run every day at 12:00am UTC to back up any user generated content.
|
||||
|
||||
## First-Party Libraries
|
||||
- [Index](https://patchii.net/flash/index): Base library used in almost any component of the website that uses PHP.
|
||||
- [Sasae](https://patchii.net/flash/sasae): Extension to the Twig templating library.
|
||||
- [Syokuhou](https://patchii.net/flash/syokuhou): Configuration library.
|
||||
|
||||
## Historical
|
||||
- [AJAX Chat (fork)](https://patchii.net/flashii/ajax-chat): Old chat software (2013-2015). Still kept on life support for the nostalgia.
|
||||
- [Hajime](https://patchii.net/flash/hajime): Cleaned up source of an older version of the website (2014-2015).
|
||||
|
|
|
@ -20,8 +20,8 @@ define('MSZ_ASSETS', MSZ_ROOT . '/assets');
|
|||
require_once MSZ_ROOT . '/vendor/autoload.php';
|
||||
|
||||
Environment::setDebug(MSZ_DEBUG);
|
||||
mb_internal_encoding('utf-8');
|
||||
date_default_timezone_set('utc');
|
||||
mb_internal_encoding('UTF-8');
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
$cfg = SharpConfig::fromFile(MSZ_CONFIG . '/config.cfg');
|
||||
|
||||
|
|
576
package-lock.json
generated
576
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"@swc/core": "^1.3.69",
|
||||
"autoprefixer": "^10.4.14",
|
||||
"cssnano": "^6.0.1",
|
||||
"postcss": "^8.4.26"
|
||||
"@swc/core": "^1.4.11",
|
||||
"autoprefixer": "^10.4.19",
|
||||
"cssnano": "^6.1.2",
|
||||
"postcss": "^8.4.38"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -168,7 +168,7 @@ $perms = $perms->checkMany([
|
|||
]);
|
||||
|
||||
Template::render('forum.forum', [
|
||||
'forum_breadcrumbs' => $forumCategories->getCategoryAncestry($categoryInfo),
|
||||
'forum_breadcrumbs' => iterator_to_array($forumCategories->getCategoryAncestry($categoryInfo)),
|
||||
'global_accent_colour' => $forumCategories->getCategoryColour($categoryInfo),
|
||||
'forum_info' => $categoryInfo,
|
||||
'forum_children' => $children,
|
||||
|
|
|
@ -296,7 +296,7 @@ try {
|
|||
}
|
||||
|
||||
Template::render('forum.posting', [
|
||||
'posting_breadcrumbs' => $forumCategories->getCategoryAncestry($categoryInfo),
|
||||
'posting_breadcrumbs' => iterator_to_array($forumCategories->getCategoryAncestry($categoryInfo)),
|
||||
'global_accent_colour' => $forumCategories->getCategoryColour($categoryInfo),
|
||||
'posting_user' => $currentUser,
|
||||
'posting_user_colour' => $usersCtx->getUserColour($currentUser),
|
||||
|
|
|
@ -291,7 +291,11 @@ $postInfos = $forumPosts->getPosts(
|
|||
if(empty($postInfos))
|
||||
Template::throwError(404);
|
||||
|
||||
$originalPostInfo = $forumPosts->getPost(topicInfo: $topicInfo);
|
||||
try {
|
||||
$originalPostInfo = $forumPosts->getPost(topicInfo: $topicInfo);
|
||||
} catch(RuntimeException $ex) {
|
||||
Template::throwError(404);
|
||||
}
|
||||
|
||||
$posts = [];
|
||||
|
||||
|
@ -326,7 +330,7 @@ $perms = $perms->checkMany([
|
|||
]);
|
||||
|
||||
Template::render('forum.topic', [
|
||||
'topic_breadcrumbs' => $forumCategories->getCategoryAncestry($topicInfo),
|
||||
'topic_breadcrumbs' => iterator_to_array($forumCategories->getCategoryAncestry($topicInfo)),
|
||||
'global_accent_colour' => $forumCategories->getCategoryColour($topicInfo),
|
||||
'topic_info' => $topicInfo,
|
||||
'category_info' => $categoryInfo,
|
||||
|
|
|
@ -115,5 +115,5 @@ Template::render('manage.changelog.change', [
|
|||
'change_info_tags' => $changeTagIds,
|
||||
'change_tags' => $tagInfos,
|
||||
'change_actions' => $changeActions,
|
||||
'change_author_id' => $authInfo->getUserInfo(),
|
||||
'change_author_id' => $authInfo->getUserInfo()->getId(),
|
||||
]);
|
||||
|
|
|
@ -9,6 +9,8 @@ if(!$msz->getAuthInfo()->getPerms('global')->check(Perm::G_EMOTES_MANAGE))
|
|||
|
||||
$emotes = $msz->getEmotes();
|
||||
$emoteId = (string)filter_input(INPUT_GET, 'e', FILTER_SANITIZE_NUMBER_INT);
|
||||
$emoteInfo = [];
|
||||
$emoteStrings = [];
|
||||
|
||||
if(empty($emoteId))
|
||||
$isNew = true;
|
||||
|
@ -16,7 +18,7 @@ else
|
|||
try {
|
||||
$isNew = false;
|
||||
$emoteInfo = $emotes->getEmote($emoteId);
|
||||
$emoteStrings = $emotes->getEmoteStrings($emoteInfo);
|
||||
$emoteStrings = iterator_to_array($emotes->getEmoteStrings($emoteInfo));
|
||||
} catch(RuntimeException $ex) {
|
||||
Template::throwError(404);
|
||||
}
|
||||
|
@ -101,6 +103,6 @@ while($_SERVER['REQUEST_METHOD'] === 'POST' && CSRF::validateRequest()) {
|
|||
|
||||
Template::render('manage.general.emoticon', [
|
||||
'emote_new' => $isNew,
|
||||
'emote_info' => $emoteInfo ?? null,
|
||||
'emote_strings' => $emoteStrings ?? [],
|
||||
'emote_info' => $emoteInfo,
|
||||
'emote_strings' => $emoteStrings,
|
||||
]);
|
||||
|
|
|
@ -13,7 +13,7 @@ $pagination = new Pagination($auditLog->countLogs(), 50);
|
|||
if(!$pagination->hasValidOffset())
|
||||
Template::throwError(404);
|
||||
|
||||
$logs = $auditLog->getLogs(pagination: $pagination);
|
||||
$logs = iterator_to_array($auditLog->getLogs(pagination: $pagination));
|
||||
$userInfos = [];
|
||||
$userColours = [];
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ $viewerPerms = $authInfo->getPerms('user');
|
|||
if(!$viewerPerms->check(Perm::U_ROLES_MANAGE))
|
||||
Template::throwError(403);
|
||||
|
||||
$roleInfo = null;
|
||||
$usersCtx = $msz->getUsersContext();
|
||||
$users = $usersCtx->getUsers();
|
||||
$roles = $usersCtx->getRoles();
|
||||
|
@ -30,7 +31,7 @@ if(filter_has_var(INPUT_GET, 'r')) {
|
|||
$currentUser = $authInfo->getUserInfo();
|
||||
$canEditPerms = $viewerPerms->check(Perm::U_PERMS_MANAGE);
|
||||
|
||||
$permsInfos = $perms->getPermissionInfo(roleInfo: $roleInfo, categoryNames: Perm::INFO_FOR_ROLE);
|
||||
$permsInfos = $roleInfo === null ? null : $perms->getPermissionInfo(roleInfo: $roleInfo, categoryNames: Perm::INFO_FOR_ROLE);
|
||||
$permsLists = Perm::createList(Perm::LISTS_FOR_ROLE);
|
||||
|
||||
while($_SERVER['REQUEST_METHOD'] === 'POST' && CSRF::validateRequest()) {
|
||||
|
|
|
@ -106,7 +106,7 @@ if(CSRF::validateRequest() && $canEdit) {
|
|||
}
|
||||
|
||||
$existingRoles = [];
|
||||
foreach($roles->getRoles(userInfo: $userInfo) as $roleInfo)
|
||||
foreach(iterator_to_array($roles->getRoles(userInfo: $userInfo)) as $roleInfo)
|
||||
$existingRoles[$roleInfo->getId()] = $roleInfo;
|
||||
|
||||
$removeRoles = [];
|
||||
|
@ -226,7 +226,7 @@ if(CSRF::validateRequest() && $canEdit) {
|
|||
return;
|
||||
}
|
||||
|
||||
$rolesAll = $roles->getRoles();
|
||||
$rolesAll = iterator_to_array($roles->getRoles());
|
||||
$userRoleIds = $users->hasRoles($userInfo, $rolesAll);
|
||||
|
||||
Template::render('manage.users.user', [
|
||||
|
|
|
@ -71,15 +71,16 @@ $notices = [];
|
|||
$userRank = $usersCtx->getUserRank($userInfo);
|
||||
$viewerRank = $usersCtx->getUserRank($viewerInfo);
|
||||
|
||||
$viewerPerms = $authInfo->getPerms('user');
|
||||
$viewerPermsGlobal = $authInfo->getPerms('global');
|
||||
$viewerPermsUser = $authInfo->getPerms('user');
|
||||
|
||||
$activeBanInfo = $usersCtx->tryGetActiveBan($userInfo);
|
||||
$isBanned = $activeBanInfo !== null;
|
||||
$profileFields = $msz->getProfileFields();
|
||||
$viewingOwnProfile = (string)$viewerId === $userInfo->getId();
|
||||
$canManageWarnings = $viewerPerms->check(Perm::U_WARNINGS_MANAGE);
|
||||
$canManageWarnings = $viewerPermsUser->check(Perm::U_WARNINGS_MANAGE);
|
||||
$canEdit = !$viewingAsGuest && ((!$isBanned && $viewingOwnProfile) || $viewerInfo->isSuperUser() || (
|
||||
$viewerPerms->check(Perm::U_USERS_MANAGE) && ($viewingOwnProfile || $viewerRank > $userRank)
|
||||
$viewerPermsUser->check(Perm::U_USERS_MANAGE) && ($viewingOwnProfile || $viewerRank > $userRank)
|
||||
));
|
||||
$avatarInfo = new UserAvatarAsset($userInfo);
|
||||
$backgroundInfo = new UserBackgroundAsset($userInfo);
|
||||
|
@ -88,7 +89,7 @@ if($isEditing) {
|
|||
if(!$canEdit)
|
||||
Template::throwError(403);
|
||||
|
||||
$perms = $viewerPerms->checkMany([
|
||||
$perms = $viewerPermsUser->checkMany([
|
||||
'edit_profile' => Perm::U_PROFILE_EDIT,
|
||||
'edit_avatar' => Perm::U_AVATAR_CHANGE,
|
||||
'edit_background' => PERM::U_PROFILE_BACKGROUND_CHANGE,
|
||||
|
@ -112,7 +113,7 @@ if($isEditing) {
|
|||
if(!$perms->edit_profile) {
|
||||
$notices[] = 'You\'re not allowed to edit your profile';
|
||||
} else {
|
||||
$profileFieldInfos = $profileFields->getFields();
|
||||
$profileFieldInfos = iterator_to_array($profileFields->getFields());
|
||||
$profileFieldsSetInfos = [];
|
||||
$profileFieldsSetValues = [];
|
||||
$profileFieldsRemove = [];
|
||||
|
@ -298,7 +299,7 @@ $profileStats->forum_post_count = $forumCtx->countTotalUserPosts($userInfo);
|
|||
$profileStats->comments_count = $msz->getComments()->countPosts(userInfo: $userInfo, deleted: false);
|
||||
|
||||
if(!$viewingAsGuest) {
|
||||
Template::set('profile_warnings', $usersCtx->getWarnings()->getWarningsWithDefaultBacklog($userInfo));
|
||||
Template::set('profile_warnings', iterator_to_array($usersCtx->getWarnings()->getWarningsWithDefaultBacklog($userInfo)));
|
||||
|
||||
if((!$isBanned || $canEdit)) {
|
||||
$unranked = $cfg->getValues([
|
||||
|
@ -322,9 +323,9 @@ if(!$viewingAsGuest) {
|
|||
);
|
||||
$activeTopicInfo = $activeTopicStats->success ? $forumTopics->getTopic(topicId: $activeTopicStats->topicId) : null;
|
||||
|
||||
$profileFieldValues = $profileFields->getFieldValues($userInfo);
|
||||
$profileFieldInfos = $profileFieldInfos ?? $profileFields->getFields(fieldValueInfos: $isEditing ? null : $profileFieldValues);
|
||||
$profileFieldFormats = $profileFields->getFieldFormats(fieldValueInfos: $profileFieldValues);
|
||||
$profileFieldValues = iterator_to_array($profileFields->getFieldValues($userInfo));
|
||||
$profileFieldInfos = $profileFieldInfos ?? iterator_to_array($profileFields->getFields(fieldValueInfos: $isEditing ? null : $profileFieldValues));
|
||||
$profileFieldFormats = iterator_to_array($profileFields->getFieldFormats(fieldValueInfos: $profileFieldValues));
|
||||
|
||||
$profileFieldRawValues = [];
|
||||
$profileFieldLinkValues = [];
|
||||
|
@ -384,4 +385,5 @@ Template::render('profile.index', [
|
|||
'profile_ban_info' => $activeBanInfo,
|
||||
'profile_avatar_info' => $avatarInfo,
|
||||
'profile_background_info' => $backgroundInfo,
|
||||
'profile_can_send_messages' => $viewerPermsGlobal->check(Perm::G_MESSAGES_SEND),
|
||||
]);
|
||||
|
|
|
@ -116,7 +116,7 @@ if($isVerifiedRequest && !empty($_POST['current_password'])) {
|
|||
if($_SERVER['REQUEST_METHOD'] === 'POST' && $isVerifiedRequest)
|
||||
$userInfo = $users->getUser($userInfo->getId(), 'id');
|
||||
|
||||
$userRoles = $roles->getRoles(userInfo: $userInfo);
|
||||
$userRoles = iterator_to_array($roles->getRoles(userInfo: $userInfo));
|
||||
|
||||
Template::render('settings.account', [
|
||||
'errors' => $errors,
|
||||
|
|
|
@ -129,6 +129,7 @@ if(isset($_POST['action']) && is_string($_POST['action'])) {
|
|||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'forum_topics_redirects', ['topic_id:s', 'user_id:s:n', 'topic_redir_url:s', 'topic_redir_created:t']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'forum_topics_track', ['user_id:s', 'topic_id:s', 'forum_id:s', 'track_last_read:t']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'login_attempts', ['user_id:s:n', 'attempt_success:b', 'attempt_ip:a', 'attempt_country:s', 'attempt_created:t', 'attempt_user_agent:s']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'messages', ['msg_id:s', 'msg_owner_id:s', 'msg_author_id:s:n', 'msg_recipient_id:s:n', 'msg_reply_to:s:n', 'msg_title:s', 'msg_body:s', 'msg_parser:i', 'msg_created:t', 'msg_sent:t:n', 'msg_read:t:n', 'msg_deleted:t:n'], 'msg_owner_id');
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'news_posts', ['post_id:s', 'category_id:s', 'user_id:s:n', 'comment_section_id:s:n', 'post_is_featured:b', 'post_title:s', 'post_text:s', 'post_scheduled:t', 'post_created:t', 'post_updated:t', 'post_deleted:t:n']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'perms', ['user_id:s:n', 'role_id:s:n', 'forum_id:s:n', 'perms_category:s', 'perms_allow:i', 'perms_deny:i']);
|
||||
$tmpFiles[] = db_to_zip($archive, $userInfo, 'perms_calculated', ['user_id:s:n', 'forum_id:s:n', 'perms_category:s', 'perms_calculated:i']);
|
||||
|
|
|
@ -15,8 +15,8 @@ $auditLog = $msz->getAuditLog();
|
|||
$loginHistoryPagination = new Pagination($loginAttempts->countAttempts(userInfo: $currentUser), 5, 'hp');
|
||||
$accountLogPagination = new Pagination($auditLog->countLogs(userInfo: $currentUser), 10, 'ap');
|
||||
|
||||
$loginHistory = $loginAttempts->getAttempts(userInfo: $currentUser, pagination: $loginHistoryPagination);
|
||||
$auditLogs = $auditLog->getLogs(userInfo: $currentUser, pagination: $accountLogPagination);
|
||||
$loginHistory = iterator_to_array($loginAttempts->getAttempts(userInfo: $currentUser, pagination: $loginHistoryPagination));
|
||||
$auditLogs = iterator_to_array($auditLog->getLogs(userInfo: $currentUser, pagination: $accountLogPagination));
|
||||
|
||||
Template::render('settings.logs', [
|
||||
'login_history_list' => $loginHistory,
|
||||
|
|
2068
public/vendor/highlightjs/highlight.min.js
vendored
Normal file
2068
public/vendor/highlightjs/highlight.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
6
public/vendor/highlightjs/highlight.pack.js
vendored
6
public/vendor/highlightjs/highlight.pack.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1,75 +0,0 @@
|
|||
/* Tomorrow Night Theme */
|
||||
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
|
||||
/* Original theme - https://github.com/chriskempson/tomorrow-theme */
|
||||
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
|
||||
|
||||
/* Tomorrow Comment */
|
||||
.hljs-comment,
|
||||
.hljs-quote {
|
||||
color: #969896;
|
||||
}
|
||||
|
||||
/* Tomorrow Red */
|
||||
.hljs-variable,
|
||||
.hljs-template-variable,
|
||||
.hljs-tag,
|
||||
.hljs-name,
|
||||
.hljs-selector-id,
|
||||
.hljs-selector-class,
|
||||
.hljs-regexp,
|
||||
.hljs-deletion {
|
||||
color: #cc6666;
|
||||
}
|
||||
|
||||
/* Tomorrow Orange */
|
||||
.hljs-number,
|
||||
.hljs-built_in,
|
||||
.hljs-builtin-name,
|
||||
.hljs-literal,
|
||||
.hljs-type,
|
||||
.hljs-params,
|
||||
.hljs-meta,
|
||||
.hljs-link {
|
||||
color: #de935f;
|
||||
}
|
||||
|
||||
/* Tomorrow Yellow */
|
||||
.hljs-attribute {
|
||||
color: #f0c674;
|
||||
}
|
||||
|
||||
/* Tomorrow Green */
|
||||
.hljs-string,
|
||||
.hljs-symbol,
|
||||
.hljs-bullet,
|
||||
.hljs-addition {
|
||||
color: #b5bd68;
|
||||
}
|
||||
|
||||
/* Tomorrow Blue */
|
||||
.hljs-title,
|
||||
.hljs-section {
|
||||
color: #81a2be;
|
||||
}
|
||||
|
||||
/* Tomorrow Purple */
|
||||
.hljs-keyword,
|
||||
.hljs-selector-tag {
|
||||
color: #b294bb;
|
||||
}
|
||||
|
||||
.hljs {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
background: #1d1f21;
|
||||
color: #c5c8c6;
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
.hljs-emphasis {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.hljs-strong {
|
||||
font-weight: bold;
|
||||
}
|
|
@ -61,7 +61,7 @@ class AuditLog {
|
|||
UserInfo|string|null $userInfo = null,
|
||||
IPAddress|string|null $remoteAddr = null,
|
||||
?Pagination $pagination = null
|
||||
): array {
|
||||
): iterable {
|
||||
if($userInfo instanceof UserInfo)
|
||||
$userInfo = $userInfo->getId();
|
||||
if($remoteAddr instanceof IPAddress)
|
||||
|
@ -98,13 +98,8 @@ class AuditLog {
|
|||
}
|
||||
|
||||
$stmt->execute();
|
||||
$result = $stmt->getResult();
|
||||
$logs = [];
|
||||
|
||||
while($result->next())
|
||||
$logs[] = new AuditLogInfo($result);
|
||||
|
||||
return $logs;
|
||||
return $stmt->getResult()->getIterator(AuditLogInfo::fromResult(...));
|
||||
}
|
||||
|
||||
public function createLog(
|
||||
|
|
|
@ -7,20 +7,24 @@ use Index\Data\IDbResult;
|
|||
use Index\Net\IPAddress;
|
||||
|
||||
class AuditLogInfo {
|
||||
private ?string $userId;
|
||||
private string $action;
|
||||
private array $params;
|
||||
private int $created;
|
||||
private string $address;
|
||||
private string $country;
|
||||
public function __construct(
|
||||
private ?string $userId,
|
||||
private string $action,
|
||||
private array $params,
|
||||
private int $created,
|
||||
private string $address,
|
||||
private string $country,
|
||||
) {}
|
||||
|
||||
public function __construct(IDbResult $result) {
|
||||
$this->userId = $result->isNull(0) ? null : (string)$result->getInteger(0);
|
||||
$this->action = $result->getString(1);
|
||||
$this->params = json_decode($result->getString(2));
|
||||
$this->created = $result->getInteger(3);
|
||||
$this->address = $result->isNull(4) ? '::1' : $result->getString(4); // apparently this being NULL is possible?
|
||||
$this->country = $result->getString(5);
|
||||
public static function fromResult(IDbResult $result): AuditLogInfo {
|
||||
return new AuditLogInfo(
|
||||
userId: $result->getStringOrNull(0),
|
||||
action: $result->getString(1),
|
||||
params: json_decode($result->getString(2)),
|
||||
created: $result->getInteger(3),
|
||||
address: $result->isNull(4) ? '::1' : $result->getString(4), // apparently this being NULL is possible?
|
||||
country: $result->getString(5),
|
||||
);
|
||||
}
|
||||
|
||||
public function hasUserId(): bool {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
namespace Misuzu\Auth;
|
||||
|
||||
// is this the right way to do this?
|
||||
use DateTimeImmutable;
|
||||
|
||||
// is this the right way to do this?
|
||||
final class AuthTokenCookie {
|
||||
public static function domain(): string {
|
||||
$url = parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST);
|
||||
|
@ -16,10 +17,24 @@ final class AuthTokenCookie {
|
|||
}
|
||||
|
||||
public static function apply(string $packed): void {
|
||||
setcookie('msz_auth', $packed, strtotime('+3 months'), '/', self::domain(), !empty($_SERVER['HTTPS']), true);
|
||||
$now = new DateTimeImmutable('now');
|
||||
$threeMonths = $now->modify('+3 months');
|
||||
|
||||
header(sprintf(
|
||||
'Set-Cookie: msz_auth=%s; Expires=%s; Max-Age=%d; Domain=%s; Path=/; SameSite=Lax; HttpOnly;%s',
|
||||
$packed,
|
||||
$threeMonths->format('D, d M Y H:i:s e'),
|
||||
$threeMonths->getTimestamp() - $now->getTimestamp(),
|
||||
self::domain(),
|
||||
filter_has_var(INPUT_SERVER, 'HTTPS') ? ' Secure' : ''
|
||||
));
|
||||
}
|
||||
|
||||
public static function nuke(): void {
|
||||
setcookie('msz_auth', '', -9001, '/', self::domain(), !empty($_SERVER['HTTPS']), true);
|
||||
header(sprintf(
|
||||
'Set-Cookie: msz_auth=; Expires=Wed, 31 Dec 1969 21:29:59 UTC; Max-Age=-9001; Domain=%s; Path=/; SameSite=Lax; HttpOnly;%s',
|
||||
self::domain(),
|
||||
filter_has_var(INPUT_SERVER, 'HTTPS') ? ' Secure' : ''
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,22 +7,26 @@ use Index\Net\IPAddress;
|
|||
use Misuzu\ClientInfo;
|
||||
|
||||
class LoginAttemptInfo {
|
||||
private ?string $userId;
|
||||
private bool $success;
|
||||
private string $remoteAddr;
|
||||
private string $countryCode;
|
||||
private int $created;
|
||||
private string $userAgent;
|
||||
private string $clientInfo;
|
||||
public function __construct(
|
||||
private ?string $userId,
|
||||
private bool $success,
|
||||
private string $remoteAddr,
|
||||
private string $countryCode,
|
||||
private int $created,
|
||||
private string $userAgent,
|
||||
private string $clientInfo,
|
||||
) {}
|
||||
|
||||
public function __construct(IDbResult $result) {
|
||||
$this->userId = $result->isNull(0) ? null : (string)$result->getInteger(0);
|
||||
$this->success = $result->getInteger(1) !== 0;
|
||||
$this->remoteAddr = $result->getString(2);
|
||||
$this->countryCode = $result->getString(3);
|
||||
$this->created = $result->getInteger(4);
|
||||
$this->userAgent = $result->getString(5);
|
||||
$this->clientInfo = $result->getString(6);
|
||||
public static function fromResult(IDbResult $result): LoginAttemptInfo {
|
||||
return new LoginAttemptInfo(
|
||||
userId: $result->getStringOrNull(0),
|
||||
success: $result->getBoolean(1),
|
||||
remoteAddr: $result->getString(2),
|
||||
countryCode: $result->getString(3),
|
||||
created: $result->getInteger(4),
|
||||
userAgent: $result->getString(5),
|
||||
clientInfo: $result->getString(6),
|
||||
);
|
||||
}
|
||||
|
||||
public function hasUserId(): bool {
|
||||
|
|
|
@ -83,7 +83,7 @@ class LoginAttempts {
|
|||
IPAddress|string|null $remoteAddr = null,
|
||||
TimeSpan|int|null $timeRange = null,
|
||||
?Pagination $pagination = null
|
||||
): array {
|
||||
): iterable {
|
||||
if($userInfo instanceof UserInfo)
|
||||
$userInfo = $userInfo->getId();
|
||||
if($remoteAddr instanceof IPAddress)
|
||||
|
@ -127,13 +127,7 @@ class LoginAttempts {
|
|||
}
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->getResult();
|
||||
$attempts = [];
|
||||
|
||||
while($result->next())
|
||||
$attempts[] = new LoginAttemptInfo($result);
|
||||
|
||||
return $attempts;
|
||||
return $stmt->getResult()->getIterator(LoginAttemptInfo::fromResult(...));
|
||||
}
|
||||
|
||||
public function recordAttempt(
|
||||
|
|
|
@ -7,32 +7,36 @@ use Index\Net\IPAddress;
|
|||
use Misuzu\ClientInfo;
|
||||
|
||||
class SessionInfo {
|
||||
private string $id;
|
||||
private string $userId;
|
||||
private string $token;
|
||||
private string $firstRemoteAddr;
|
||||
private ?string $lastRemoteAddr;
|
||||
private string $userAgent;
|
||||
private string $clientInfo;
|
||||
private string $countryCode;
|
||||
private int $expires;
|
||||
private bool $bumpExpires;
|
||||
private int $created;
|
||||
private ?int $lastActive;
|
||||
public function __construct(
|
||||
private string $id,
|
||||
private string $userId,
|
||||
private string $token,
|
||||
private string $firstRemoteAddr,
|
||||
private ?string $lastRemoteAddr,
|
||||
private string $userAgent,
|
||||
private string $clientInfo,
|
||||
private string $countryCode,
|
||||
private int $expires,
|
||||
private bool $bumpExpires,
|
||||
private int $created,
|
||||
private ?int $lastActive,
|
||||
) {}
|
||||
|
||||
public function __construct(IDbResult $result) {
|
||||
$this->id = (string)$result->getInteger(0);
|
||||
$this->userId = (string)$result->getInteger(1);
|
||||
$this->token = $result->getString(2);
|
||||
$this->firstRemoteAddr = $result->getString(3);
|
||||
$this->lastRemoteAddr = $result->isNull(4) ? null : $result->getString(4);
|
||||
$this->userAgent = $result->getString(5);
|
||||
$this->clientInfo = $result->getString(6);
|
||||
$this->countryCode = $result->getString(7);
|
||||
$this->expires = $result->getInteger(8);
|
||||
$this->bumpExpires = $result->getInteger(9) !== 0;
|
||||
$this->created = $result->getInteger(10);
|
||||
$this->lastActive = $result->isNull(11) ? null : $result->getInteger(11);
|
||||
public static function fromResult(IDbResult $result): SessionInfo {
|
||||
return new SessionInfo(
|
||||
id: $result->getString(0),
|
||||
userId: $result->getString(1),
|
||||
token: $result->getString(2),
|
||||
firstRemoteAddr: $result->getString(3),
|
||||
lastRemoteAddr: $result->getStringOrNull(4),
|
||||
userAgent: $result->getString(5),
|
||||
clientInfo: $result->getString(6),
|
||||
countryCode: $result->getString(7),
|
||||
expires: $result->getInteger(8),
|
||||
bumpExpires: $result->getBoolean(9),
|
||||
created: $result->getInteger(10),
|
||||
lastActive: $result->getIntegerOrNull(11),
|
||||
);
|
||||
}
|
||||
|
||||
public function getId(): string {
|
||||
|
|
|
@ -58,7 +58,7 @@ class Sessions {
|
|||
public function getSessions(
|
||||
UserInfo|string|null $userInfo = null,
|
||||
?Pagination $pagination = null
|
||||
): array {
|
||||
): iterable {
|
||||
if($userInfo instanceof UserInfo)
|
||||
$userInfo = $userInfo->getId();
|
||||
|
||||
|
@ -85,13 +85,7 @@ class Sessions {
|
|||
}
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->getResult();
|
||||
$sessions = [];
|
||||
|
||||
while($result->next())
|
||||
$sessions[] = new SessionInfo($result);
|
||||
|
||||
return $sessions;
|
||||
return $stmt->getResult()->getIterator(SessionInfo::fromResult(...));
|
||||
}
|
||||
|
||||
public function getSession(
|
||||
|
@ -124,7 +118,7 @@ class Sessions {
|
|||
if(!$result->next())
|
||||
throw new RuntimeException('Session not found.');
|
||||
|
||||
return new SessionInfo($result);
|
||||
return SessionInfo::fromResult($result);
|
||||
}
|
||||
|
||||
public function createSession(
|
||||
|
|
|
@ -5,20 +5,24 @@ use Index\DateTime;
|
|||
use Index\Data\IDbResult;
|
||||
|
||||
class ChangeInfo {
|
||||
private string $id;
|
||||
private ?string $userId;
|
||||
private int $action;
|
||||
private int $created;
|
||||
private string $summary;
|
||||
private string $body;
|
||||
public function __construct(
|
||||
private string $id,
|
||||
private ?string $userId,
|
||||
private int $action,
|
||||
private int $created,
|
||||
private string $summary,
|
||||
private string $body,
|
||||
) {}
|
||||
|
||||
public function __construct(IDbResult $result) {
|
||||
$this->id = (string)$result->getInteger(0);
|
||||
$this->userId = $result->isNull(1) ? null : (string)$result->getInteger(1);
|
||||
$this->action = $result->getInteger(2);
|
||||
$this->created = $result->getInteger(3);
|
||||
$this->summary = $result->getString(4);
|
||||
$this->body = $result->getString(5);
|
||||
public static function fromResult(IDbResult $result): ChangeInfo {
|
||||
return new ChangeInfo(
|
||||
id: $result->getString(0),
|
||||
userId: $result->getStringOrNull(1),
|
||||
action: $result->getInteger(2),
|
||||
created: $result->getInteger(3),
|
||||
summary: $result->getString(4),
|
||||
body: $result->getString(5),
|
||||
);
|
||||
}
|
||||
|
||||
public function getId(): string {
|
||||
|
|
|
@ -121,7 +121,7 @@ class Changelog {
|
|||
DateTime|int|null $dateTime = null,
|
||||
?array $tags = null,
|
||||
?Pagination $pagination = null
|
||||
): array {
|
||||
): iterable {
|
||||
if($userInfo instanceof UserInfo)
|
||||
$userInfo = $userInfo->getId();
|
||||
if($dateTime instanceof DateTime)
|
||||
|
@ -169,13 +169,7 @@ class Changelog {
|
|||
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->getResult();
|
||||
$changes = [];
|
||||
|
||||
while($result->next())
|
||||
$changes[] = new ChangeInfo($result);
|
||||
|
||||
return $changes;
|
||||
return $stmt->getResult()->getIterator(ChangeInfo::fromResult(...));
|
||||
}
|
||||
|
||||
public function getChange(string $changeId): ChangeInfo {
|
||||
|
@ -187,7 +181,7 @@ class Changelog {
|
|||
if(!$result->next())
|
||||
throw new RuntimeException('No tag with that ID exists.');
|
||||
|
||||
return new ChangeInfo($result);
|
||||
return ChangeInfo::fromResult($result);
|
||||
}
|
||||
|
||||
public function createChange(
|
||||
|
|
|
@ -3,20 +3,12 @@ namespace Misuzu\Changelog;
|
|||
|
||||
use ErrorException;
|
||||
use RuntimeException;
|
||||
use Index\Routing\Route;
|
||||
use Index\Routing\RouteHandler;
|
||||
use Misuzu\Pagination;
|
||||
use Misuzu\SiteInfo;
|
||||
use Misuzu\Template;
|
||||
use Index\Http\Routing\{HttpGet,RouteHandler};
|
||||
use Misuzu\{Pagination,SiteInfo,Template};
|
||||
use Misuzu\Auth\AuthInfo;
|
||||
use Misuzu\Comments\Comments;
|
||||
use Misuzu\Comments\CommentsEx;
|
||||
use Misuzu\Feeds\Feed;
|
||||
use Misuzu\Feeds\FeedItem;
|
||||
use Misuzu\Feeds\AtomFeedSerializer;
|
||||
use Misuzu\Feeds\RssFeedSerializer;
|
||||
use Misuzu\URLs\URLInfo;
|
||||
use Misuzu\URLs\URLRegistry;
|
||||
use Misuzu\Comments\{Comments,CommentsEx};
|
||||
use Misuzu\Feeds\{Feed,FeedItem,AtomFeedSerializer,RssFeedSerializer};
|
||||
use Misuzu\URLs\{URLInfo,URLRegistry};
|
||||
use Misuzu\Users\UsersContext;
|
||||
|
||||
final class ChangelogRoutes extends RouteHandler {
|
||||
|
@ -34,7 +26,7 @@ final class ChangelogRoutes extends RouteHandler {
|
|||
return $comments->getCommentsForLayout($categoryName);
|
||||
}
|
||||
|
||||
#[Route('GET', '/changelog')]
|
||||
#[HttpGet('/changelog')]
|
||||
#[URLInfo('changelog-index', '/changelog', ['date' => '<date>', 'user' => '<user>', 'tags' => '<tags>', 'p' => '<page>'])]
|
||||
public function getIndex($response, $request) {
|
||||
$filterDate = (string)$request->getParam('date');
|
||||
|
@ -73,15 +65,16 @@ final class ChangelogRoutes extends RouteHandler {
|
|||
if(!$pagination->hasValidOffset())
|
||||
return 404;
|
||||
|
||||
$changeInfos = $this->changelog->getChanges(userInfo: $filterUser, dateTime: $filterDate, tags: $filterTags, pagination: $pagination);
|
||||
if(empty($changeInfos))
|
||||
return 404;
|
||||
|
||||
$changes = [];
|
||||
$changeInfos = $this->changelog->getChanges(userInfo: $filterUser, dateTime: $filterDate, tags: $filterTags, pagination: $pagination);
|
||||
$commentsCategoryName = null;
|
||||
|
||||
foreach($changeInfos as $changeInfo) {
|
||||
$userInfo = $changeInfo->hasUserId() ? $this->usersCtx->getUserInfo($changeInfo->getUserId()) : null;
|
||||
|
||||
if($commentsCategoryName === null)
|
||||
$commentsCategoryName = $changeInfo->getCommentsCategoryName();
|
||||
|
||||
$changes[] = [
|
||||
'change' => $changeInfo,
|
||||
'user' => $userInfo,
|
||||
|
@ -89,17 +82,20 @@ final class ChangelogRoutes extends RouteHandler {
|
|||
];
|
||||
}
|
||||
|
||||
if(empty($changes))
|
||||
return 404;
|
||||
|
||||
return Template::renderRaw('changelog.index', [
|
||||
'changelog_infos' => $changes,
|
||||
'changelog_date' => $filterDate,
|
||||
'changelog_user' => $filterUser,
|
||||
'changelog_tags' => $filterTags,
|
||||
'changelog_pagination' => $pagination,
|
||||
'comments_info' => empty($filterDate) ? null : $this->getCommentsInfo($changeInfos[0]->getCommentsCategoryName()),
|
||||
'comments_info' => empty($filterDate) && $commentsCategoryName !== null ? null : $this->getCommentsInfo($commentsCategoryName),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('GET', '/changelog/change/:id')]
|
||||
#[HttpGet('/changelog/change/([0-9]+)')]
|
||||
#[URLInfo('changelog-change', '/changelog/change/<change>')]
|
||||
#[URLInfo('changelog-change-comments', '/changelog/change/<change>', fragment: 'comments')]
|
||||
public function getChange($response, $request, string $changeId) {
|
||||
|
@ -148,14 +144,14 @@ final class ChangelogRoutes extends RouteHandler {
|
|||
return $feed;
|
||||
}
|
||||
|
||||
#[Route('GET', '/changelog.rss')]
|
||||
#[HttpGet('/changelog.rss')]
|
||||
#[URLInfo('changelog-feed-rss', '/changelog.rss')]
|
||||
public function getFeedRSS($response) {
|
||||
$response->setContentType('application/rss+xml; charset=utf-8');
|
||||
return (new RssFeedSerializer)->serializeFeed($this->createFeed('rss'));
|
||||
}
|
||||
|
||||
#[Route('GET', '/changelog.atom')]
|
||||
#[HttpGet('/changelog.atom')]
|
||||
#[URLInfo('changelog-feed-atom', '/changelog.atom')]
|
||||
public function getFeedAtom($response) {
|
||||
$response->setContentType('application/atom+xml; charset=utf-8');
|
||||
|
|
|
@ -46,7 +46,7 @@ class Comments {
|
|||
public function getCategories(
|
||||
UserInfo|string|null $owner = null,
|
||||
?Pagination $pagination = null
|
||||
): array {
|
||||
): iterable {
|
||||
if($owner instanceof UserInfo)
|
||||
$owner = $owner->getId();
|
||||
|
||||
|
@ -72,13 +72,7 @@ class Comments {
|
|||
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->getResult();
|
||||
$categories = [];
|
||||
|
||||
while($result->next())
|
||||
$categories[] = new CommentsCategoryInfo($result);
|
||||
|
||||
return $categories;
|
||||
return $stmt->getResult()->getIterator(CommentsCategoryInfo::fromResult(...));
|
||||
}
|
||||
|
||||
public function getCategory(
|
||||
|
@ -124,7 +118,7 @@ class Comments {
|
|||
if(!$result->next())
|
||||
throw new RuntimeException('Comments category not found.');
|
||||
|
||||
return new CommentsCategoryInfo($result);
|
||||
return CommentsCategoryInfo::fromResult($result);
|
||||
}
|
||||
|
||||
public function checkCategoryNameExists(string $name): bool {
|
||||
|
@ -276,7 +270,7 @@ class Comments {
|
|||
?bool $deleted = null,
|
||||
bool $includeRepliesCount = false,
|
||||
bool $includeVotesCount = false
|
||||
): array {
|
||||
): iterable {
|
||||
if($categoryInfo instanceof CommentsCategoryInfo)
|
||||
$categoryInfo = $categoryInfo->getId();
|
||||
if($parentInfo instanceof CommentsPostInfo)
|
||||
|
@ -330,13 +324,7 @@ class Comments {
|
|||
$stmt->addParameter(++$args, $userInfo instanceof UserInfo ? $userInfo->getId() : $userInfo);
|
||||
$stmt->execute();
|
||||
|
||||
$posts = [];
|
||||
$result = $stmt->getResult();
|
||||
|
||||
while($result->next())
|
||||
$posts[] = new CommentsPostInfo($result, $includeRepliesCount, $includeVotesCount);
|
||||
|
||||
return $posts;
|
||||
return $stmt->getResult()->getIterator(fn($result) => CommentsPostInfo::fromResult($result, $includeRepliesCount, $includeVotesCount));
|
||||
}
|
||||
|
||||
public function getPost(
|
||||
|
@ -362,7 +350,7 @@ class Comments {
|
|||
if(!$result->next())
|
||||
throw new RuntimeException('No comment with that ID exists.');
|
||||
|
||||
return new CommentsPostInfo($result, $includeRepliesCount, $includeVotesCount);
|
||||
return CommentsPostInfo::fromResult($result, $includeRepliesCount, $includeVotesCount);
|
||||
}
|
||||
|
||||
public function createPost(
|
||||
|
|
|
@ -6,20 +6,24 @@ use Index\Data\IDbResult;
|
|||
use Misuzu\Users\UserInfo;
|
||||
|
||||
class CommentsCategoryInfo {
|
||||
private string $id;
|
||||
private string $name;
|
||||
private ?string $ownerId;
|
||||
private int $created;
|
||||
private ?int $locked;
|
||||
private int $comments;
|
||||
public function __construct(
|
||||
private string $id,
|
||||
private string $name,
|
||||
private ?string $ownerId,
|
||||
private int $created,
|
||||
private ?int $locked,
|
||||
private int $comments,
|
||||
) {}
|
||||
|
||||
public function __construct(IDbResult $result) {
|
||||
$this->id = (string)$result->getInteger(0);
|
||||
$this->name = $result->getString(1);
|
||||
$this->ownerId = $result->isNull(2) ? null : (string)$result->getInteger(2);
|
||||
$this->created = $result->getInteger(3);
|
||||
$this->locked = $result->isNull(4) ? null : $result->getInteger(4);
|
||||
$this->comments = $result->getInteger(5);
|
||||
public static function fromResult(IDbResult $result): CommentsCategoryInfo {
|
||||
return new CommentsCategoryInfo(
|
||||
id: $result->getString(0),
|
||||
name: $result->getString(1),
|
||||
ownerId: $result->getStringOrNull(2),
|
||||
created: $result->getInteger(3),
|
||||
locked: $result->getIntegerOrNull(4),
|
||||
comments: $result->getInteger(5),
|
||||
);
|
||||
}
|
||||
|
||||
public function getId(): string {
|
||||
|
|
|
@ -5,47 +5,53 @@ use Index\DateTime;
|
|||
use Index\Data\IDbResult;
|
||||
|
||||
class CommentsPostInfo {
|
||||
private string $id;
|
||||
private string $categoryId;
|
||||
private ?string $userId;
|
||||
private ?string $replyingTo;
|
||||
private string $body;
|
||||
private int $created;
|
||||
private ?int $pinned;
|
||||
private ?int $updated;
|
||||
private ?int $deleted;
|
||||
private int $replies;
|
||||
private int $votesTotal;
|
||||
private int $votesPositive;
|
||||
private int $votesNegative;
|
||||
|
||||
public function __construct(
|
||||
private string $id,
|
||||
private string $categoryId,
|
||||
private ?string $userId,
|
||||
private ?string $replyingTo,
|
||||
private string $body,
|
||||
private int $created,
|
||||
private ?int $pinned,
|
||||
private ?int $updated,
|
||||
private ?int $deleted,
|
||||
private int $replies,
|
||||
private int $votesTotal,
|
||||
private int $votesPositive,
|
||||
private int $votesNegative,
|
||||
) {}
|
||||
|
||||
public static function fromResult(
|
||||
IDbResult $result,
|
||||
bool $includeRepliesCount = false,
|
||||
bool $includeVotesCount = false
|
||||
) {
|
||||
$args = 0;
|
||||
$this->id = (string)$result->getInteger($args);
|
||||
$this->categoryId = (string)$result->getInteger(++$args);
|
||||
$this->userId = $result->isNull(++$args) ? null : (string)$result->getInteger($args);
|
||||
$this->replyingTo = $result->isNull(++$args) ? null : (string)$result->getInteger($args);
|
||||
$this->body = $result->getString(++$args);
|
||||
$this->created = $result->getInteger(++$args);
|
||||
$this->pinned = $result->isNull(++$args) ? null : $result->getInteger($args);
|
||||
$this->updated = $result->isNull(++$args) ? null : $result->getInteger($args);
|
||||
$this->deleted = $result->isNull(++$args) ? null : $result->getInteger($args);
|
||||
): CommentsPostInfo {
|
||||
$args = [];
|
||||
$count = 0;
|
||||
|
||||
$this->replies = $includeRepliesCount ? $result->getInteger(++$args) : 0;
|
||||
$args[] = $result->getString($count); // id
|
||||
$args[] = $result->getString(++$count); // categoryId
|
||||
$args[] = $result->getStringOrNull(++$count); // userId
|
||||
$args[] = $result->getStringOrNull(++$count); // replyingTo
|
||||
$args[] = $result->getString(++$count); // body
|
||||
$args[] = $result->getInteger(++$count); // created
|
||||
$args[] = $result->getIntegerOrNull(++$count); // pinned
|
||||
$args[] = $result->getIntegerOrNull(++$count); // updated
|
||||
$args[] = $result->getIntegerOrNull(++$count); // deleted
|
||||
|
||||
$args[] = $includeRepliesCount ? $result->getInteger(++$count) : 0;
|
||||
|
||||
if($includeVotesCount) {
|
||||
$this->votesTotal = $result->getInteger(++$args);
|
||||
$this->votesPositive = $result->getInteger(++$args);
|
||||
$this->votesNegative = $result->getInteger(++$args);
|
||||
$args[] = $result->getInteger(++$count); // votesTotal
|
||||
$args[] = $result->getInteger(++$count); // votesPositive
|
||||
$args[] = $result->getInteger(++$count); // votesNegative
|
||||
} else {
|
||||
$this->votesTotal = 0;
|
||||
$this->votesPositive = 0;
|
||||
$this->votesNegative = 0;
|
||||
$args[] = 0;
|
||||
$args[] = 0;
|
||||
$args[] = 0;
|
||||
}
|
||||
|
||||
return new CommentsPostInfo(...$args);
|
||||
}
|
||||
|
||||
public function getId(): string {
|
||||
|
|
|
@ -5,14 +5,18 @@ use Index\DateTime;
|
|||
use Index\Data\IDbResult;
|
||||
|
||||
class CounterInfo {
|
||||
private string $name;
|
||||
private int $value;
|
||||
private int $updated;
|
||||
public function __construct(
|
||||
private string $name,
|
||||
private int $value,
|
||||
private int $updated,
|
||||
) {}
|
||||
|
||||
public function __construct(IDbResult $result) {
|
||||
$this->name = $result->getString(0);
|
||||
$this->value = $result->getInteger(1);
|
||||
$this->updated = $result->getInteger(2);
|
||||
public static function fromResult(IDbResult $result): CounterInfo {
|
||||
return new CounterInfo(
|
||||
name: $result->getString(0),
|
||||
value: $result->getInteger(1),
|
||||
updated: $result->getInteger(2),
|
||||
);
|
||||
}
|
||||
|
||||
public function getName(): string {
|
||||
|
|
|
@ -25,7 +25,7 @@ class Counters {
|
|||
public function getCounters(
|
||||
?string $orderBy = null,
|
||||
?Pagination $pagination = null
|
||||
): array {
|
||||
): iterable {
|
||||
$hasOrderBy = $orderBy !== null;
|
||||
$hasPagination = $pagination !== null;
|
||||
|
||||
|
@ -47,13 +47,7 @@ class Counters {
|
|||
}
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->getResult();
|
||||
$counters = [];
|
||||
|
||||
while($result->next())
|
||||
$counters[] = new CounterInfo($result);
|
||||
|
||||
return $counters;
|
||||
return $stmt->getResult()->getIterator(CounterInfo::fromResult(...));
|
||||
}
|
||||
|
||||
public function get(array|string $names): array|int {
|
||||
|
|
|
@ -5,16 +5,20 @@ use Stringable;
|
|||
use Index\Data\IDbResult;
|
||||
|
||||
class EmoteInfo implements Stringable {
|
||||
private string $id;
|
||||
private int $order;
|
||||
private int $rank;
|
||||
private string $url;
|
||||
public function __construct(
|
||||
private string $id,
|
||||
private int $order,
|
||||
private int $rank,
|
||||
private string $url,
|
||||
) {}
|
||||
|
||||
public function __construct(IDbResult $result) {
|
||||
$this->id = (string)$result->getInteger(0);
|
||||
$this->order = $result->getInteger(1);
|
||||
$this->rank = $result->getInteger(2);
|
||||
$this->url = $result->getString(3);
|
||||
public static function fromResult(IDbResult $result): EmoteInfo {
|
||||
return new EmoteInfo(
|
||||
id: $result->getString(0),
|
||||
order: $result->getInteger(1),
|
||||
rank: $result->getInteger(2),
|
||||
url: $result->getString(3),
|
||||
);
|
||||
}
|
||||
|
||||
public function getId(): string {
|
||||
|
|
|
@ -5,14 +5,18 @@ use Stringable;
|
|||
use Index\Data\IDbResult;
|
||||
|
||||
class EmoteStringInfo implements Stringable {
|
||||
private string $emoteId;
|
||||
private int $order;
|
||||
private string $string;
|
||||
public function __construct(
|
||||
private string $emoteId,
|
||||
private int $order,
|
||||
private string $string,
|
||||
) {}
|
||||
|
||||
public function __construct(IDbResult $result) {
|
||||
$this->emoteId = (string)$result->getInteger(0);
|
||||
$this->order = $result->getInteger(1);
|
||||
$this->string = $result->getString(2);
|
||||
public static function fromResult(IDbResult $result): EmoteStringInfo {
|
||||
return new EmoteStringInfo(
|
||||
emoteId: $result->getString(0),
|
||||
order: $result->getInteger(1),
|
||||
string: $result->getString(2),
|
||||
);
|
||||
}
|
||||
|
||||
public function getEmoteId(): string {
|
||||
|
|
|
@ -31,7 +31,7 @@ class Emotes {
|
|||
if(!$result->next())
|
||||
throw new RuntimeException('No emoticon with that ID exists.');
|
||||
|
||||
return new EmoteInfo($result);
|
||||
return EmoteInfo::fromResult($result);
|
||||
}
|
||||
|
||||
public static function emoteOrderOptions(): array {
|
||||
|
@ -43,7 +43,7 @@ class Emotes {
|
|||
?int $minRank = null,
|
||||
?string $orderBy = null,
|
||||
?bool $reverse = null
|
||||
): array {
|
||||
): iterable {
|
||||
$hasMinRank = $minRank !== null;
|
||||
$hasOrderBy = $orderBy !== null;
|
||||
$hasReverse = $reverse !== null;
|
||||
|
@ -65,13 +65,7 @@ class Emotes {
|
|||
$stmt->addParameter(1, $minRank);
|
||||
$stmt->execute();
|
||||
|
||||
$emotes = [];
|
||||
$result = $stmt->getResult();
|
||||
|
||||
while($result->next())
|
||||
$emotes[] = new EmoteInfo($result);
|
||||
|
||||
return $emotes;
|
||||
return $stmt->getResult()->getIterator(EmoteInfo::fromResult(...));
|
||||
}
|
||||
|
||||
private static function checkEmoteUrlInternal(string $url): string {
|
||||
|
@ -156,7 +150,7 @@ class Emotes {
|
|||
$stmt->execute();
|
||||
}
|
||||
|
||||
public function getEmoteStrings(EmoteInfo|string $infoOrId): array {
|
||||
public function getEmoteStrings(EmoteInfo|string $infoOrId): iterable {
|
||||
if($infoOrId instanceof EmoteInfo)
|
||||
$infoOrId = $infoOrId->getId();
|
||||
|
||||
|
@ -164,13 +158,7 @@ class Emotes {
|
|||
$stmt->addParameter(1, $infoOrId);
|
||||
$stmt->execute();
|
||||
|
||||
$strings = [];
|
||||
$result = $stmt->getResult();
|
||||
|
||||
while($result->next())
|
||||
$strings[] = new EmoteStringInfo($result);
|
||||
|
||||
return $strings;
|
||||
return $stmt->getResult()->getIterator(EmoteStringInfo::fromResult(...));
|
||||
}
|
||||
|
||||
private static function checkEmoteStringInternal(string $string): string {
|
||||
|
|
|
@ -12,19 +12,20 @@ use Misuzu\Pagination;
|
|||
use Misuzu\Users\UserInfo;
|
||||
|
||||
class ForumCategories {
|
||||
private IDbConnection $dbConn;
|
||||
private DbStatementCache $cache;
|
||||
|
||||
public function __construct(IDbConnection $dbConn) {
|
||||
$this->dbConn = $dbConn;
|
||||
$this->cache = new DbStatementCache($dbConn);
|
||||
}
|
||||
|
||||
public static function convertCategoryListToTree(
|
||||
array $catInfos,
|
||||
iterable $catInfos,
|
||||
ForumCategoryInfo|string|null $parentInfo = null,
|
||||
?Colour $colour = null
|
||||
): array {
|
||||
if(!is_array($catInfos))
|
||||
$catInfos = iterator_to_array($catInfos);
|
||||
|
||||
$colour ??= Colour::none();
|
||||
$tree = [];
|
||||
$predicate = $parentInfo
|
||||
|
@ -103,7 +104,7 @@ class ForumCategories {
|
|||
?bool $hidden = null,
|
||||
bool $asTree = false,
|
||||
?Pagination $pagination = null
|
||||
): array {
|
||||
): iterable {
|
||||
$isRootParent = false;
|
||||
$hasParentInfo = $parentInfo !== false;
|
||||
$hasType = $type !== null;
|
||||
|
@ -155,11 +156,7 @@ class ForumCategories {
|
|||
}
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->getResult();
|
||||
$cats = [];
|
||||
|
||||
while($result->next())
|
||||
$cats[] = new ForumCategoryInfo($result);
|
||||
$cats = $stmt->getResult()->getIterator(ForumCategoryInfo::fromResult(...));
|
||||
|
||||
if($asTree)
|
||||
$cats = self::convertCategoryListToTree($cats);
|
||||
|
@ -216,7 +213,7 @@ class ForumCategories {
|
|||
if(!$result->next())
|
||||
throw new RuntimeException('Forum category info not found.');
|
||||
|
||||
return new ForumCategoryInfo($result);
|
||||
return ForumCategoryInfo::fromResult($result);
|
||||
}
|
||||
|
||||
public function updateCategory(
|
||||
|
@ -261,7 +258,7 @@ class ForumCategories {
|
|||
|
||||
public function getCategoryAncestry(
|
||||
ForumCategoryInfo|ForumTopicInfo|ForumPostInfo|string $categoryInfo
|
||||
): array {
|
||||
): iterable {
|
||||
if($categoryInfo instanceof ForumCategoryInfo)
|
||||
$categoryInfo = $categoryInfo->getId();
|
||||
elseif($categoryInfo instanceof ForumTopicInfo || $categoryInfo instanceof ForumPostInfo)
|
||||
|
@ -277,13 +274,7 @@ class ForumCategories {
|
|||
$stmt->addParameter(1, $categoryInfo);
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->getResult();
|
||||
$cats = [];
|
||||
|
||||
while($result->next())
|
||||
$cats[] = new ForumCategoryInfo($result);
|
||||
|
||||
return $cats;
|
||||
return $stmt->getResult()->getIterator(ForumCategoryInfo::fromResult(...));
|
||||
}
|
||||
|
||||
public function getCategoryChildren(
|
||||
|
@ -291,7 +282,7 @@ class ForumCategories {
|
|||
bool $includeSelf = false,
|
||||
?bool $hidden = null,
|
||||
bool $asTree = false
|
||||
): array {
|
||||
): iterable {
|
||||
if($parentInfo instanceof ForumCategoryInfo)
|
||||
$parentInfo = $parentInfo->getId();
|
||||
|
||||
|
@ -319,11 +310,7 @@ class ForumCategories {
|
|||
$stmt->addParameter(++$args, $parentInfo);
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->getResult();
|
||||
$cats = [];
|
||||
|
||||
while($result->next())
|
||||
$cats[] = new ForumCategoryInfo($result);
|
||||
$cats = $stmt->getResult()->getIterator(ForumCategoryInfo::fromResult(...));
|
||||
|
||||
if($asTree)
|
||||
$cats = self::convertCategoryListToTree($cats, $parentInfo);
|
||||
|
|
|
@ -26,38 +26,42 @@ class ForumCategoryInfo {
|
|||
self::TYPE_DISCUSSION,
|
||||
];
|
||||
|
||||
private string $id;
|
||||
private int $order;
|
||||
private ?string $parentId;
|
||||
private string $name;
|
||||
private int $type;
|
||||
private ?string $desc;
|
||||
private ?string $icon;
|
||||
private ?int $colour;
|
||||
private ?string $link;
|
||||
private ?int $clicks;
|
||||
private int $created;
|
||||
private bool $archived;
|
||||
private bool $hidden;
|
||||
private int $topicsCount;
|
||||
private int $postsCount;
|
||||
public function __construct(
|
||||
private string $id,
|
||||
private int $order,
|
||||
private ?string $parentId,
|
||||
private string $name,
|
||||
private int $type,
|
||||
private ?string $desc,
|
||||
private ?string $icon,
|
||||
private ?int $colour,
|
||||
private ?string $link,
|
||||
private ?int $clicks,
|
||||
private int $created,
|
||||
private bool $archived,
|
||||
private bool $hidden,
|
||||
private int $topicsCount,
|
||||
private int $postsCount,
|
||||
) {}
|
||||
|
||||
public function __construct(IDbResult $result) {
|
||||
$this->id = (string)$result->getInteger(0);
|
||||
$this->order = $result->getInteger(1);
|
||||
$this->parentId = $result->isNull(2) ? null : (string)$result->getInteger(2);
|
||||
$this->name = $result->getString(3);
|
||||
$this->type = $result->getInteger(4);
|
||||
$this->desc = $result->isNull(5) ? null : $result->getString(5);
|
||||
$this->icon = $result->isNull(6) ? null : $result->getString(6);
|
||||
$this->colour = $result->isNull(7) ? null : $result->getInteger(7);
|
||||
$this->link = $result->isNull(8) ? null : $result->getString(8);
|
||||
$this->clicks = $result->isNull(9) ? null : $result->getInteger(9);
|
||||
$this->created = $result->getInteger(10);
|
||||
$this->archived = $result->getInteger(11) !== 0;
|
||||
$this->hidden = $result->getInteger(12) !== 0;
|
||||
$this->topicsCount = $result->getInteger(13);
|
||||
$this->postsCount = $result->getInteger(14);
|
||||
public static function fromResult(IDbResult $result): ForumCategoryInfo {
|
||||
return new ForumCategoryInfo(
|
||||
id: $result->getString(0),
|
||||
order: $result->getInteger(1),
|
||||
parentId: $result->getStringOrNull(2),
|
||||
name: $result->getString(3),
|
||||
type: $result->getInteger(4),
|
||||
desc: $result->getStringOrNull(5),
|
||||
icon: $result->getStringOrNull(6),
|
||||
colour: $result->getIntegerOrNull(7),
|
||||
link: $result->getStringOrNull(8),
|
||||
clicks: $result->getIntegerOrNull(9),
|
||||
created: $result->getInteger(10),
|
||||
archived: $result->getBoolean(11),
|
||||
hidden: $result->getBoolean(12),
|
||||
topicsCount: $result->getInteger(13),
|
||||
postsCount: $result->getInteger(14),
|
||||
);
|
||||
}
|
||||
|
||||
public function getId(): string {
|
||||
|
|
|
@ -7,30 +7,34 @@ use Index\Net\IPAddress;
|
|||
use Misuzu\Parsers\Parser;
|
||||
|
||||
class ForumPostInfo {
|
||||
private string $id;
|
||||
private string $topicId;
|
||||
private string $categoryId;
|
||||
private ?string $userId;
|
||||
private string $remoteAddr;
|
||||
private string $body;
|
||||
private int $parser;
|
||||
private bool $displaySignature;
|
||||
private int $created;
|
||||
private ?int $edited;
|
||||
private ?int $deleted;
|
||||
public function __construct(
|
||||
private string $id,
|
||||
private string $topicId,
|
||||
private string $categoryId,
|
||||
private ?string $userId,
|
||||
private string $remoteAddr,
|
||||
private string $body,
|
||||
private int $parser,
|
||||
private bool $displaySignature,
|
||||
private int $created,
|
||||
private ?int $edited,
|
||||
private ?int $deleted,
|
||||
) {}
|
||||
|
||||
public function __construct(IDbResult $result) {
|
||||
$this->id = (string)$result->getInteger(0);
|
||||
$this->topicId = (string)$result->getInteger(1);
|
||||
$this->categoryId = (string)$result->getInteger(2);
|
||||
$this->userId = $result->isNull(3) ? null : (string)$result->getInteger(3);
|
||||
$this->remoteAddr = $result->getString(4);
|
||||
$this->body = $result->getString(5);
|
||||
$this->parser = $result->getInteger(6);
|
||||
$this->displaySignature = $result->getInteger(7) !== 0;
|
||||
$this->created = $result->getInteger(8);
|
||||
$this->edited = $result->isNull(9) ? null : $result->getInteger(9);
|
||||
$this->deleted = $result->isNull(10) ? null : $result->getInteger(10);
|
||||
public static function fromResult(IDbResult $result): ForumPostInfo {
|
||||
return new ForumPostInfo(
|
||||
id: $result->getString(0),
|
||||
topicId: $result->getString(1),
|
||||
categoryId: $result->getString(2),
|
||||
userId: $result->getStringOrNull(3),
|
||||
remoteAddr: $result->getString(4),
|
||||
body: $result->getString(5),
|
||||
parser: $result->getInteger(6),
|
||||
displaySignature: $result->getBoolean(7),
|
||||
created: $result->getInteger(8),
|
||||
edited: $result->getIntegerOrNull(9),
|
||||
deleted: $result->getIntegerOrNull(10),
|
||||
);
|
||||
}
|
||||
|
||||
public function getId(): string {
|
||||
|
|
|
@ -84,7 +84,7 @@ class ForumPosts {
|
|||
?array $searchQuery = null,
|
||||
?bool $deleted = null,
|
||||
?Pagination $pagination = null
|
||||
): array {
|
||||
): iterable {
|
||||
// remove this hack when search server
|
||||
$hasSearchQuery = $searchQuery !== null;
|
||||
$doSearchOrder = false;
|
||||
|
@ -189,13 +189,7 @@ class ForumPosts {
|
|||
}
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->getResult();
|
||||
$posts = [];
|
||||
|
||||
while($result->next())
|
||||
$posts[] = new ForumPostInfo($result);
|
||||
|
||||
return $posts;
|
||||
return $stmt->getResult()->getIterator(ForumPostInfo::fromResult(...));
|
||||
}
|
||||
|
||||
public function getPost(
|
||||
|
@ -267,7 +261,7 @@ class ForumPosts {
|
|||
if(!$result->next())
|
||||
throw new RuntimeException('Forum post not found.');
|
||||
|
||||
return new ForumPostInfo($result);
|
||||
return ForumPostInfo::fromResult($result);
|
||||
}
|
||||
|
||||
public function createPost(
|
||||
|
|
|
@ -17,32 +17,36 @@ class ForumTopicInfo {
|
|||
'global' => self::TYPE_GLOBAL,
|
||||
];
|
||||
|
||||
private string $id;
|
||||
private string $categoryId;
|
||||
private ?string $userId;
|
||||
private int $type;
|
||||
private string $title;
|
||||
private int $postsCount;
|
||||
private int $deletedPostsCount;
|
||||
private int $viewsCount;
|
||||
private int $created;
|
||||
private int $bumped;
|
||||
private ?int $deleted;
|
||||
private ?int $locked;
|
||||
public function __construct(
|
||||
private string $id,
|
||||
private string $categoryId,
|
||||
private ?string $userId,
|
||||
private int $type,
|
||||
private string $title,
|
||||
private int $postsCount,
|
||||
private int $deletedPostsCount,
|
||||
private int $viewsCount,
|
||||
private int $created,
|
||||
private int $bumped,
|
||||
private ?int $deleted,
|
||||
private ?int $locked,
|
||||
) {}
|
||||
|
||||
public function __construct(IDbResult $result) {
|
||||
$this->id = (string)$result->getInteger(0);
|
||||
$this->categoryId = (string)$result->getInteger(1);
|
||||
$this->userId = $result->isNull(2) ? null : (string)$result->getInteger(2);
|
||||
$this->type = $result->getInteger(3);
|
||||
$this->title = $result->getString(4);
|
||||
$this->viewsCount = $result->getInteger(5);
|
||||
$this->created = $result->getInteger(6);
|
||||
$this->bumped = $result->getInteger(7);
|
||||
$this->deleted = $result->isNull(8) ? null : $result->getInteger(8);
|
||||
$this->locked = $result->isNull(9) ? null : $result->getInteger(9);
|
||||
$this->postsCount = $result->getInteger(10);
|
||||
$this->deletedPostsCount = $result->getInteger(11);
|
||||
public static function fromResult(IDbResult $result): ForumTopicInfo {
|
||||
return new ForumTopicInfo(
|
||||
id: $result->getString(0),
|
||||
categoryId: $result->getString(1),
|
||||
userId: $result->getStringOrNull(2),
|
||||
type: $result->getInteger(3),
|
||||
title: $result->getString(4),
|
||||
viewsCount: $result->getInteger(5),
|
||||
created: $result->getInteger(6),
|
||||
bumped: $result->getInteger(7),
|
||||
deleted: $result->getIntegerOrNull(8),
|
||||
locked: $result->getIntegerOrNull(9),
|
||||
postsCount: $result->getInteger(10),
|
||||
deletedPostsCount: $result->getInteger(11),
|
||||
);
|
||||
}
|
||||
|
||||
public function getId(): string {
|
||||
|
|
|
@ -5,16 +5,20 @@ use Index\DateTime;
|
|||
use Index\Data\IDbResult;
|
||||
|
||||
class ForumTopicRedirectInfo {
|
||||
private string $topicId;
|
||||
private ?string $userId;
|
||||
private string $link;
|
||||
private int $created;
|
||||
public function __construct(
|
||||
private string $topicId,
|
||||
private ?string $userId,
|
||||
private string $link,
|
||||
private int $created,
|
||||
) {}
|
||||
|
||||
public function __construct(IDbResult $result) {
|
||||
$this->topicId = (string)$result->getInteger(0);
|
||||
$this->userId = $result->isNull(1) ? null : (string)$result->getInteger(1);
|
||||
$this->link = $result->getString(2);
|
||||
$this->created = $result->getInteger(3);
|
||||
public static function fromResult(IDbResult $result): ForumTopicRedirectInfo {
|
||||
return new ForumTopicRedirectInfo(
|
||||
topicId: $result->getString(0),
|
||||
userId: $result->getStringOrNull(1),
|
||||
link: $result->getString(2),
|
||||
created: $result->getInteger(3),
|
||||
);
|
||||
}
|
||||
|
||||
public function getTopicId(): string {
|
||||
|
|
|
@ -38,7 +38,7 @@ class ForumTopicRedirects {
|
|||
public function getTopicRedirects(
|
||||
UserInfo|string|null $userInfo = null,
|
||||
?Pagination $pagination = null
|
||||
): array {
|
||||
): iterable {
|
||||
if($userInfo instanceof UserInfo)
|
||||
$userInfo = $userInfo->getId();
|
||||
|
||||
|
@ -61,13 +61,7 @@ class ForumTopicRedirects {
|
|||
}
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->getResult();
|
||||
$redirs = [];
|
||||
|
||||
while($result->next())
|
||||
$redirs[] = new ForumTopicRedirectInfo($result);
|
||||
|
||||
return $redirs;
|
||||
return $stmt->getResult()->getIterator(ForumTopicRedirectInfo::fromResult(...));
|
||||
}
|
||||
|
||||
public function hasTopicRedirect(ForumTopicInfo|string $topicInfo): bool {
|
||||
|
@ -97,7 +91,7 @@ class ForumTopicRedirects {
|
|||
if(!$result->next())
|
||||
throw new RuntimeException('Could not find that forum topic redirect.');
|
||||
|
||||
return new ForumTopicRedirectInfo($result);
|
||||
return ForumTopicRedirectInfo::fromResult($result);
|
||||
}
|
||||
|
||||
public function createTopicRedirect(
|
||||
|
|
|
@ -91,7 +91,7 @@ class ForumTopics {
|
|||
?bool $global = null,
|
||||
?bool $deleted = null,
|
||||
?Pagination $pagination = null
|
||||
): array {
|
||||
): iterable {
|
||||
// remove this hack when search server
|
||||
$hasSearchQuery = $searchQuery !== null;
|
||||
$hasAfterTopicId = false;
|
||||
|
@ -194,13 +194,7 @@ class ForumTopics {
|
|||
}
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->getResult();
|
||||
$topics = [];
|
||||
|
||||
while($result->next())
|
||||
$topics[] = new ForumTopicInfo($result);
|
||||
|
||||
return $topics;
|
||||
return $stmt->getResult()->getIterator(ForumTopicInfo::fromResult(...));
|
||||
}
|
||||
|
||||
public function getTopic(
|
||||
|
@ -239,7 +233,7 @@ class ForumTopics {
|
|||
if(!$result->next())
|
||||
throw new RuntimeException('Forum topic not found.');
|
||||
|
||||
return new ForumTopicInfo($result);
|
||||
return ForumTopicInfo::fromResult($result);
|
||||
}
|
||||
|
||||
public function createTopic(
|
||||
|
|
|
@ -3,14 +3,10 @@ namespace Misuzu\Home;
|
|||
|
||||
use RuntimeException;
|
||||
use Index\DateTime;
|
||||
use Index\Data\DbTools;
|
||||
use Index\Data\IDbConnection;
|
||||
use Index\Routing\Route;
|
||||
use Index\Routing\RouteHandler;
|
||||
use Index\Data\{DbTools,IDbConnection};
|
||||
use Index\Http\Routing\{HttpGet,RouteHandler};
|
||||
use Syokuhou\IConfig;
|
||||
use Misuzu\Pagination;
|
||||
use Misuzu\SiteInfo;
|
||||
use Misuzu\Template;
|
||||
use Misuzu\{Pagination,SiteInfo,Template};
|
||||
use Misuzu\Auth\AuthInfo;
|
||||
use Misuzu\Changelog\Changelog;
|
||||
use Misuzu\Comments\Comments;
|
||||
|
@ -43,7 +39,7 @@ class HomeRoutes extends RouteHandler {
|
|||
]);
|
||||
}
|
||||
|
||||
private function getOnlineUsers(): array {
|
||||
private function getOnlineUsers(): iterable {
|
||||
return $this->usersCtx->getUsers()->getUsers(
|
||||
lastActiveInMinutes: 5,
|
||||
deleted: false,
|
||||
|
@ -53,14 +49,14 @@ class HomeRoutes extends RouteHandler {
|
|||
|
||||
private array $newsCategoryInfos = [];
|
||||
|
||||
private function getFeaturedNewsPosts(int $amount, bool $decorate): array {
|
||||
private function getFeaturedNewsPosts(int $amount, bool $decorate): iterable {
|
||||
$postInfos = $this->news->getPosts(
|
||||
onlyFeatured: true,
|
||||
pagination: new Pagination($amount)
|
||||
);
|
||||
|
||||
if(!$decorate)
|
||||
return $postInfos;
|
||||
return iterator_to_array($postInfos);
|
||||
|
||||
$posts = [];
|
||||
|
||||
|
@ -154,7 +150,7 @@ class HomeRoutes extends RouteHandler {
|
|||
return $topics;
|
||||
}
|
||||
|
||||
#[Route('GET', '/')]
|
||||
#[HttpGet('/')]
|
||||
#[URLInfo('index', '/')]
|
||||
public function getIndex(...$args) {
|
||||
return $this->authInfo->isLoggedIn()
|
||||
|
@ -164,9 +160,9 @@ class HomeRoutes extends RouteHandler {
|
|||
|
||||
public function getHome() {
|
||||
$stats = $this->getStats();
|
||||
$onlineUserInfos = $this->getOnlineUsers();
|
||||
$onlineUserInfos = iterator_to_array($this->getOnlineUsers());
|
||||
$featuredNews = $this->getFeaturedNewsPosts(5, true);
|
||||
$changelog = $this->changelog->getChanges(pagination: new Pagination(10));
|
||||
$changelog = iterator_to_array($this->changelog->getChanges(pagination: new Pagination(10)));
|
||||
|
||||
$stats['users:online:recent'] = count($onlineUserInfos);
|
||||
|
||||
|
@ -201,7 +197,7 @@ class HomeRoutes extends RouteHandler {
|
|||
]);
|
||||
}
|
||||
|
||||
#[Route('GET', '/_landing')]
|
||||
#[HttpGet('/_landing')]
|
||||
public function getLanding($response, $request) {
|
||||
$config = $this->config->getValues([
|
||||
['social.embed_linked:b'],
|
||||
|
@ -221,7 +217,7 @@ class HomeRoutes extends RouteHandler {
|
|||
} else $linkedData = null;
|
||||
|
||||
$stats = $this->getStats();
|
||||
$onlineUserInfos = $this->getOnlineUsers();
|
||||
$onlineUserInfos = iterator_to_array($this->getOnlineUsers());
|
||||
$featuredNews = $this->getFeaturedNewsPosts(3, false);
|
||||
$popularTopics = $this->getPopularForumTopics($config['landing.forum_categories']);
|
||||
$activeTopics = $this->getActiveForumTopics($config['landing.forum_categories']);
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
<?php
|
||||
namespace Misuzu\Info;
|
||||
|
||||
use Index\Routing\Route;
|
||||
use Index\Routing\RouteHandler;
|
||||
use Index\Http\Routing\{HttpGet,RouteHandler};
|
||||
use Misuzu\Template;
|
||||
use Misuzu\Parsers\Parser;
|
||||
use Misuzu\URLs\URLInfo;
|
||||
|
@ -18,23 +17,16 @@ class InfoRoutes extends RouteHandler {
|
|||
'index' => 'Index Project » %s',
|
||||
];
|
||||
|
||||
private static function checkName(string $name): bool {
|
||||
return preg_match('#^([A-Za-z0-9_]+)$#', $name) === 1;
|
||||
}
|
||||
|
||||
#[Route('GET', '/info')]
|
||||
#[HttpGet('/info')]
|
||||
#[URLInfo('info-index', '/info')]
|
||||
public function getIndex() {
|
||||
return Template::renderRaw('info.index');
|
||||
}
|
||||
|
||||
#[Route('GET', '/info/:name')]
|
||||
#[HttpGet('/info/([A-Za-z0-9_]+)')]
|
||||
#[URLInfo('info', '/info/<title>')]
|
||||
#[URLInfo('info-doc', '/info/<title>')]
|
||||
public function getDocsPage($response, $request, string $name) {
|
||||
if(!self::checkName($name))
|
||||
return 404;
|
||||
|
||||
return $this->serveMarkdownDocument(
|
||||
sprintf('%s/%s.md', self::DOCS_PATH, $name)
|
||||
);
|
||||
|
@ -78,13 +70,11 @@ class InfoRoutes extends RouteHandler {
|
|||
return '';
|
||||
}
|
||||
|
||||
#[Route('GET', '/info/:project/:name')]
|
||||
#[HttpGet('/info/([A-Za-z0-9_]+)/([A-Za-z0-9_]+)')]
|
||||
#[URLInfo('info-project-doc', '/info/<project>/<title>')]
|
||||
public function getProjectPage($response, $request, string $project, string $name) {
|
||||
if(!array_key_exists($project, self::PROJECT_PATHS))
|
||||
return 404;
|
||||
if(!self::checkName($name))
|
||||
return 404;
|
||||
|
||||
$projectPath = self::PROJECT_PATHS[$project];
|
||||
$titleSuffix = array_key_exists($project, self::PROJECT_SUFFIXES) ? self::PROJECT_SUFFIXES[$project] : '';
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
<?php
|
||||
namespace Misuzu;
|
||||
|
||||
use Index\Routing\Route;
|
||||
use Index\Routing\RouteHandler;
|
||||
use Misuzu\URLs\IURLSource;
|
||||
use Misuzu\URLs\URLInfo;
|
||||
use Misuzu\URLs\URLRegistry;
|
||||
use Index\Http\Routing\{HttpGet,RouteHandler};
|
||||
use Misuzu\URLs\{IURLSource,URLInfo,URLRegistry};
|
||||
|
||||
class LegacyRoutes extends RouteHandler implements IURLSource {
|
||||
public function __construct(
|
||||
|
@ -124,27 +121,27 @@ class LegacyRoutes extends RouteHandler implements IURLSource {
|
|||
$urls->register('manage-role', '/manage/users/role.php', ['r' => '<role>']);
|
||||
}
|
||||
|
||||
#[Route('GET', '/index.php')]
|
||||
#[HttpGet('/index.php')]
|
||||
public function getIndexPHP($response): void {
|
||||
$response->redirect($this->urls->format('index'), true);
|
||||
}
|
||||
|
||||
#[Route('GET', '/info.php')]
|
||||
#[HttpGet('/info.php')]
|
||||
public function getInfoPHP($response): void {
|
||||
$response->redirect($this->urls->format('info'), true);
|
||||
}
|
||||
|
||||
#[Route('GET', '/info.php/:name')]
|
||||
#[HttpGet('/info.php/([A-Za-z0-9_]+)')]
|
||||
public function getInfoDocsPHP($response, $request, string $name): void {
|
||||
$response->redirect($this->urls->format('info', ['title' => $name]), true);
|
||||
}
|
||||
|
||||
#[Route('GET', '/info.php/:project/:name')]
|
||||
#[HttpGet('/info.php/([A-Za-z0-9_]+)/([A-Za-z0-9_]+)')]
|
||||
public function getInfoProjectPHP($response, $request, string $project, string $name): void {
|
||||
$response->redirect($this->urls->format('info', ['title' => $project . '/' . $name]), true);
|
||||
}
|
||||
|
||||
#[Route('GET', '/news.php')]
|
||||
#[HttpGet('/news.php')]
|
||||
public function getNewsPHP($response, $request): void {
|
||||
$postId = (int)($request->getParam('n', FILTER_SANITIZE_NUMBER_INT) ?? $request->getParam('p', FILTER_SANITIZE_NUMBER_INT));
|
||||
|
||||
|
@ -159,28 +156,28 @@ class LegacyRoutes extends RouteHandler implements IURLSource {
|
|||
$response->redirect($location, true);
|
||||
}
|
||||
|
||||
#[Route('GET', '/news.php/rss')]
|
||||
#[HttpGet('/news.php/rss')]
|
||||
public function getNewsRssPHP($response, $request): void {
|
||||
$catId = (int)$request->getParam('c', FILTER_SANITIZE_NUMBER_INT);
|
||||
$location = $this->urls->format($catId > 0 ? 'news-category-feed-rss' : 'news-feed-rss', ['category' => $catId]);
|
||||
$response->redirect($location, true);
|
||||
}
|
||||
|
||||
#[Route('GET', '/news.php/atom')]
|
||||
#[HttpGet('/news.php/atom')]
|
||||
public function getNewsAtomPHP($response, $request): void {
|
||||
$catId = (int)$request->getParam('c', FILTER_SANITIZE_NUMBER_INT);
|
||||
$location = $this->urls->format($catId > 0 ? 'news-category-feed-atom' : 'news-feed-atom', ['category' => $catId]);
|
||||
$response->redirect($location, true);
|
||||
}
|
||||
|
||||
#[Route('GET', '/news/index.php')]
|
||||
#[HttpGet('/news/index.php')]
|
||||
public function getNewsIndexPHP($response, $request): void {
|
||||
$response->redirect($this->urls->format('news-index', [
|
||||
'page' => $request->getParam('page', FILTER_SANITIZE_NUMBER_INT),
|
||||
]), true);
|
||||
}
|
||||
|
||||
#[Route('GET', '/news/category.php')]
|
||||
#[HttpGet('/news/category.php')]
|
||||
public function getNewsCategoryPHP($response, $request): void {
|
||||
$response->redirect($this->urls->format('news-category', [
|
||||
'category' => $request->getParam('c', FILTER_SANITIZE_NUMBER_INT),
|
||||
|
@ -188,19 +185,19 @@ class LegacyRoutes extends RouteHandler implements IURLSource {
|
|||
]), true);
|
||||
}
|
||||
|
||||
#[Route('GET', '/news/post.php')]
|
||||
#[HttpGet('/news/post.php')]
|
||||
public function getNewsPostPHP($response, $request): void {
|
||||
$response->redirect($this->urls->format('news-post', [
|
||||
'post' => $request->getParam('p', FILTER_SANITIZE_NUMBER_INT),
|
||||
]), true);
|
||||
}
|
||||
|
||||
#[Route('GET', '/news/feed.php')]
|
||||
#[HttpGet('/news/feed.php')]
|
||||
public function getNewsFeedPHP($response, $request): int {
|
||||
return 400;
|
||||
}
|
||||
|
||||
#[Route('GET', '/news/feed.php/rss')]
|
||||
#[HttpGet('/news/feed.php/rss')]
|
||||
public function getNewsFeedRssPHP($response, $request): void {
|
||||
$catId = (int)$request->getParam('c', FILTER_SANITIZE_NUMBER_INT);
|
||||
$response->redirect($this->urls->format(
|
||||
|
@ -209,7 +206,7 @@ class LegacyRoutes extends RouteHandler implements IURLSource {
|
|||
), true);
|
||||
}
|
||||
|
||||
#[Route('GET', '/news/feed.php/atom')]
|
||||
#[HttpGet('/news/feed.php/atom')]
|
||||
public function getNewsFeedAtomPHP($response, $request): void {
|
||||
$catId = (int)$request->getParam('c', FILTER_SANITIZE_NUMBER_INT);
|
||||
$response->redirect($this->urls->format(
|
||||
|
@ -218,7 +215,7 @@ class LegacyRoutes extends RouteHandler implements IURLSource {
|
|||
), true);
|
||||
}
|
||||
|
||||
#[Route('GET', '/changelog.php')]
|
||||
#[HttpGet('/changelog.php')]
|
||||
public function getChangelogPHP($response, $request): void {
|
||||
$changeId = $request->getParam('c', FILTER_SANITIZE_NUMBER_INT);
|
||||
if($changeId) {
|
||||
|
@ -232,7 +229,7 @@ class LegacyRoutes extends RouteHandler implements IURLSource {
|
|||
]), true);
|
||||
}
|
||||
|
||||
#[Route('GET', '/auth.php')]
|
||||
#[HttpGet('/auth.php')]
|
||||
public function getAuthPHP($response, $request): void {
|
||||
$response->redirect($this->urls->format(match($request->getParam('m')) {
|
||||
'logout' => 'auth-logout',
|
||||
|
@ -243,44 +240,44 @@ class LegacyRoutes extends RouteHandler implements IURLSource {
|
|||
}), true);
|
||||
}
|
||||
|
||||
#[Route('GET', '/auth')]
|
||||
#[Route('GET', '/auth/index.php')]
|
||||
#[HttpGet('/auth')]
|
||||
#[HttpGet('/auth/index.php')]
|
||||
public function getAuthIndexPHP($response, $request): void {
|
||||
$response->redirect($this->urls->format('auth-login'), true);
|
||||
}
|
||||
|
||||
#[Route('GET', '/settings.php')]
|
||||
#[HttpGet('/settings.php')]
|
||||
public function getSettingsPHP($response): void {
|
||||
$response->redirect($this->urls->format('settings-index'), true);
|
||||
}
|
||||
|
||||
#[Route('GET', '/settings')]
|
||||
#[HttpGet('/settings')]
|
||||
public function getSettingsIndex($response): void {
|
||||
$response->redirect($this->urls->format('settings-account'));
|
||||
}
|
||||
|
||||
#[Route('GET', '/settings/index.php')]
|
||||
#[HttpGet('/settings/index.php')]
|
||||
public function getSettingsIndexPHP($response): void {
|
||||
$response->redirect($this->urls->format('settings-account'), true);
|
||||
}
|
||||
|
||||
#[Route('GET', '/manage')]
|
||||
#[HttpGet('/manage')]
|
||||
#[URLInfo('manage-index', '/manage')]
|
||||
public function getManageIndex($response): void {
|
||||
$response->redirect($this->urls->format('manage-general-overview'));
|
||||
}
|
||||
|
||||
#[Route('GET', '/manage/index.php')]
|
||||
#[HttpGet('/manage/index.php')]
|
||||
public function getManageIndexPHP($response): void {
|
||||
$response->redirect($this->urls->format('manage-general-overview'), true);
|
||||
}
|
||||
|
||||
#[Route('GET', '/manage/news')]
|
||||
#[HttpGet('/manage/news')]
|
||||
public function getManageNewsIndex($response): void {
|
||||
$response->redirect($this->urls->format('manage-news-categories'));
|
||||
}
|
||||
|
||||
#[Route('GET', '/manage/news/index.php')]
|
||||
#[HttpGet('/manage/news/index.php')]
|
||||
public function getManageNewsIndexPHP($response): void {
|
||||
$response->redirect($this->urls->format('manage-news-categories'), true);
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue