commit 28890cd5d59ba02bb46361a31517d611746b7a42 Author: flashwave Date: Tue Sep 13 15:14:49 2022 +0200 Imported into new repository. diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9141329 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +indent_style = space +indent_size = 4 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..c5f949a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +* text=auto +/msz text eol=lf +*.sh text eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a350838 --- /dev/null +++ b/.gitignore @@ -0,0 +1,39 @@ +# Libraries +/vendor +/node_modules +/npm-debug.log +/yarn-error.log + +# Configuration +/config/config.ini +/config/github.ini +/.debug +/.migrating + +# Storage +/store + +# OS specific +[Tt]humbs.db +[Dd]esktop.ini +.DS_Store + +# IDE specific +.vscode/ +.vs/ +.idea/ + +# Vagrant things +.vagrant/ +/devel/nginx/dhparam.pem +/devel/nginx/misuzu.crt +/devel/nginx/misuzu.key + +# Compiled/copied assets +/public/js +/public/css +/public/webfonts +/assets/typescript/*.d.ts + +# Google +/public/robots.txt diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..525bff2 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/index"] + path = lib/index + url = https://git.flash.moe/flash/index.git diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..fd7d251 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,3 @@ +# Code of Conduct + +p: diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..68e179a --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2017-2022 flashwave + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ef2823a --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# Misuzu +> Misuzu can and will steal your lunch money. + +## Requirements + - PHP 8.1 + - MariaDB 10.6 + - [Composer](https://getcomposer.org/) + +## Important + +DON'T RUN ANYTHING IN THE `devel` FOLDER IN PRODUCTION UNLESS YOU SERIOUSLY WANT TO FUCK EVERYTHING UP. diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..e233c7a --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,7 @@ +Vagrant.configure("2") do |config| + config.vm.box = "ubuntu/focal64" + config.vm.network "forwarded_port", guest: 80, host: 10080 + config.vm.network "forwarded_port", guest: 443, host: 10443 + config.vm.network "forwarded_port", guest: 3306, host: 13306 + config.vm.provision :shell, path: "devel/setup-devbox.sh" +end diff --git a/assets/README.md b/assets/README.md new file mode 100644 index 0000000..7ddbc9a --- /dev/null +++ b/assets/README.md @@ -0,0 +1,6 @@ +# Misuzu Assets + +Subdirectories of the `css` and `js` folder are accessible through the web as `example.com/assets/.`. +Meaning `/assets/js/misuzu` is accessible as `/assets/misuzu.js`. +Files are concatenated recursively, files first then directories in alphabetical order. +Use `_` prefixes to raise things up. diff --git a/assets/css/misuzu/_input/button.css b/assets/css/misuzu/_input/button.css new file mode 100644 index 0000000..510ed07 --- /dev/null +++ b/assets/css/misuzu/_input/button.css @@ -0,0 +1,34 @@ +.input__button { + background-color: var(--background-colour); + font-family: var(--font-regular); + font-size: 1.2em; + line-height: 1.4em; + padding: 5px 10px; + min-width: 80px; + text-align: center; + cursor: pointer; + transition: color .2s, background-color .2s, opacity .2s, border-color .2s; + color: var(--accent-colour); + border: 1px solid var(--accent-colour); + border-radius: 2px; + display: inline-flex; + align-items: center; + justify-content: center; + text-decoration: none; +} +.input__button:hover, .input__button:active, +.input__button:focus, .input__button:checked, +.input__button--active, .input__button--checked { + color: #111; + background-color: var(--accent-colour); + border-color: var(--accent-colour); +} +.input__button[disabled], +.input__button--busy { + opacity: .4; +} +.input__button--autosize { min-width: auto; } +.input__button--disabled { --accent-colour: #333; } +.input__button--destroy { --accent-colour: #c00; } +.input__button--save { --accent-colour: #080; } +.input__button--blue { --accent-colour: #09f; } diff --git a/assets/css/misuzu/_input/checkbox.css b/assets/css/misuzu/_input/checkbox.css new file mode 100644 index 0000000..57bf77b --- /dev/null +++ b/assets/css/misuzu/_input/checkbox.css @@ -0,0 +1,55 @@ +.input__checkbox { + display: inline-flex; + margin: 1px 0; + overflow: hidden; +} +.input__checkbox:not(.input__checkbox--disabled) { + cursor: pointer; +} +.input__checkbox--radio .input__checkbox__display, +.input__checkbox--radio .input__checkbox__display__icon { + border-radius: 100%; +} +.input__checkbox__input { + display: inline-block; + position: absolute; + z-index: -1000; + top: -100%; +} +.input__checkbox__display { + display: inline-block; + width: 20px; + height: 20px; + border: 1px solid #222; + background: #222; + color: #fff; + border-radius: 2px; + box-shadow: inset 0 0 4px #111; + transition: border-color .2s; +} +.input__checkbox__display__icon { + background-color: var(--accent-colour); + background-size: 28px 28px; + background-image: radial-gradient(ellipse at center, rgba(255, 255, 255, .2) 0%, rgba(0, 0, 0, .4) 100%); + box-shadow: 0 0 2px #111; + border-radius: 2px; + margin: 2px; + width: 14px; + height: 14px; + opacity: 0; + transition: opacity .2s; +} +.input__checkbox__input:checked ~ .input__checkbox__display .input__checkbox__display__icon { + opacity: 1; +} +.input__checkbox:not(.input__checkbox--disabled):hover .input__checkbox__display, +.input__checkbox:not(.input__checkbox--disabled) .input__checkbox__input:focus ~ .input__checkbox__display { + border-color: var(--accent-colour); +} +.input__checkbox__text { + display: inline-block; + margin-left: 4px; +} +.input__checkbox--disabled { + opacity: .5; +} diff --git a/assets/css/misuzu/_input/colour.css b/assets/css/misuzu/_input/colour.css new file mode 100644 index 0000000..07500c4 --- /dev/null +++ b/assets/css/misuzu/_input/colour.css @@ -0,0 +1,35 @@ +.input__colour { + display: inline-block; + width: 40px; + height: 20px; + overflow: hidden; + border: 1px solid #222; + background: #222; + border-radius: 2px; + transition: border-color .2s; + cursor: pointer; +} +.input__colour:hover, +.input__colour:focus, +.input__colour:focus-within { + border-color: var(--accent-colour); +} +.input__colour__overlay { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + z-index: 20; + background-image: radial-gradient(ellipse at center, rgba(255, 255, 255, .2) 0%, rgba(0, 0, 0, .4) 100%); + background-size: 80px 40px; +} +.input__colour__control { + border-width: 0; + position: absolute; + top: -5px; + left: -5px; + width: 100px; + height: 100px; + z-index: 10; +} diff --git a/assets/css/misuzu/_input/select.css b/assets/css/misuzu/_input/select.css new file mode 100644 index 0000000..2aa1d7b --- /dev/null +++ b/assets/css/misuzu/_input/select.css @@ -0,0 +1,14 @@ +.input__select { + border: 1px solid #222; + padding: 5px 10px; + background: #222; + color: #fff; + min-width: 150px; + font-size: 1.2em; + border-radius: 2px; + box-shadow: inset 0 0 4px #111; + transition: border-color .2s; +} +.input__select:focus { + border-color: var(--accent-colour); +} diff --git a/assets/css/misuzu/_input/text.css b/assets/css/misuzu/_input/text.css new file mode 100644 index 0000000..7f642a9 --- /dev/null +++ b/assets/css/misuzu/_input/text.css @@ -0,0 +1,14 @@ +.input__text { + font-size: 1.2em; + border: 1px solid #222; + padding: 5px 10px; + background: #222; + color: #fff; + border-radius: 2px; + box-shadow: inset 0 0 4px #111; + transition: border-color .2s; +} +.input__text:focus { border-color: var(--accent-colour); } +.input__text--readonly { color: #888; } +.input__text--monospace { font-family: var(--font-monospace); } +.input__text--centre { text-align: center; } diff --git a/assets/css/misuzu/_input/textarea.css b/assets/css/misuzu/_input/textarea.css new file mode 100644 index 0000000..bc3efe6 --- /dev/null +++ b/assets/css/misuzu/_input/textarea.css @@ -0,0 +1,13 @@ +.input__textarea { + font-size: 1.2em; + border: 1px solid #222; + padding: 5px 10px; + vertical-align: bottom; + background: #222; + color: #fff; + font-family: var(--font-monospace); + border-radius: 2px; + box-shadow: inset 0 0 4px #111; + transition: border-color .2s; +} +.input__textarea:focus { border-color: var(--accent-colour); } diff --git a/assets/css/misuzu/_input/upload.css b/assets/css/misuzu/_input/upload.css new file mode 100644 index 0000000..9587684 --- /dev/null +++ b/assets/css/misuzu/_input/upload.css @@ -0,0 +1,28 @@ +.input__upload { + display: inline-block; + cursor: pointer; + margin: 1px 0; +} +.input__upload__input { + display: inline-block; + position: absolute; + z-index: -1000; +} +.input__upload__selection { + text-align: center; + font-size: 1.2em; + border: 1px solid #222; + padding: 5px 10px; + background: #222; + color: #fff; + border-radius: 2px; + box-shadow: inset 0 0 4px #111; + transition: border-color .2s; + overflow: hidden; + word-wrap: break-word; +} +.input__upload:focus-within .input__upload__selection, +.input__upload__input:focus ~ .input__upload__selection, +.input__upload__input:active ~ .input__upload__selection { + border-color: var(--accent-colour); +} diff --git a/assets/css/misuzu/_msz.css b/assets/css/misuzu/_msz.css new file mode 100644 index 0000000..afe7f67 --- /dev/null +++ b/assets/css/misuzu/_msz.css @@ -0,0 +1,96 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; + position: relative; + outline-style: none; +} + +html, +body { + width: 100%; + height: 100%; +} + +[hidden], +.hidden { + display: none !important; + visibility: hidden !important; +} + +:root { + --font-size: 12px; + --line-height: 20px; + --font-regular: Verdana, Geneva, 'Dejavu Sans', Arial, Helvetica, sans-serif; + --font-monospace: Consolas, 'Liberation Mono', Menlo, Courier, monospace; + + --site-max-width: 1200px; + --site-mobile-width: 800px; + --site-logo: url('/images/logos/imouto-default.png'); + + --header-height-desktop: 70px; + --header-height-mobile: 50px; + + --background-image: initial; + --background-colour: #111; + --background-colour-translucent-1: rgba(17, 17, 17, 0.1); + --background-colour-translucent-2: rgba(17, 17, 17, 0.2); + --background-colour-translucent-3: rgba(17, 17, 17, 0.3); + --background-colour-translucent-4: rgba(17, 17, 17, 0.4); + --background-colour-translucent-5: rgba(17, 17, 17, 0.5); + --background-colour-translucent-6: rgba(17, 17, 17, 0.6); + --background-colour-translucent-7: rgba(17, 17, 17, 0.7); + --background-colour-translucent-8: rgba(17, 17, 17, 0.8); + --background-colour-translucent-9: rgba(17, 17, 17, 0.9); + --background-pattern: url('/images/clouds.png') fixed; + + --container-colour: #161616; + + --text-colour: #fff; + --text-colour-inverted: #000; + + --user-colour: inherit; + --user-header: url('/images/pixel.png'); + --accent-colour: #8559a5; + --header-accent-colour: var(--accent-colour); +} + +html { + scrollbar-color: var(--accent-colour) var(--background-colour); +} + +.main { + display: flex; + flex-direction: column; + background-image: var(--background-image); + background-color: var(--background-colour); + font-size: var(--font-size); + line-height: var(--line-height); + font-family: var(--font-regular); + color: var(--text-colour); + background-attachment: fixed; + background-position: center center; +} +.main__wrapper { + max-width: var(--site-max-width); + width: 100%; + margin: 0 auto; + flex: 1 0 auto; +} + +.main--bg-blend { + background-color: var(--accent-colour); + background-blend-mode: multiply; +} +.main--bg-slide { animation: background-slide infinite linear 2s; } +.main--bg-cover { background-size: cover; } +.main--bg-contain { background-size: contain; } +.main--bg-stretch { background-size: 100% 100%; } +.main--bg-tile { background-size: auto; } + +.link { + color: var(--accent-colour); + text-decoration: none; +} +.link:hover, .link:focus { text-decoration: underline; } + diff --git a/assets/css/misuzu/animations.css b/assets/css/misuzu/animations.css new file mode 100644 index 0000000..a40481f --- /dev/null +++ b/assets/css/misuzu/animations.css @@ -0,0 +1,4 @@ +@keyframes background-slide { + 0% { background-position: 0 0; } + 100% { background-position: var(--background-width) var(--background-height); } +} diff --git a/assets/css/misuzu/auth/buttons.css b/assets/css/misuzu/auth/buttons.css new file mode 100644 index 0000000..6ad353f --- /dev/null +++ b/assets/css/misuzu/auth/buttons.css @@ -0,0 +1,11 @@ +.auth__buttons { + margin: 5px; + display: flex; + flex-direction: row-reverse; + justify-content: space-between; +} +.auth__buttons__button--minor { + background-color: transparent; + border-color: transparent; + color: inherit; +} diff --git a/assets/css/misuzu/auth/container.css b/assets/css/misuzu/auth/container.css new file mode 100644 index 0000000..d6a4ed0 --- /dev/null +++ b/assets/css/misuzu/auth/container.css @@ -0,0 +1,4 @@ +.auth__container { + margin: 2px auto; + max-width: 400px; +} diff --git a/assets/css/misuzu/auth/label.css b/assets/css/misuzu/auth/label.css new file mode 100644 index 0000000..5da6fd4 --- /dev/null +++ b/assets/css/misuzu/auth/label.css @@ -0,0 +1,33 @@ +.auth__label { + overflow: hidden; + margin-bottom: 5px; + display: block; +} +.auth__label__text { + padding: 5px 10px; +} +.auth__label__value { + padding: 2px 5px; +} +.auth__label__input { + width: 100%; +} +.auth__label__action { + padding: 3px 8px; + display: block; + color: inherit; + text-decoration: none; + position: absolute; + top: 0; + right: 0; + border-radius: 4px; + transition: background-color .2s; + margin: 2px; +} +.auth__label__action:hover, +.auth__label__action:focus { + background-color: rgba(255, 255, 255, .2); +} +.auth__label__action:active { + background-color: rgba(255, 255, 255, .2); +} diff --git a/assets/css/misuzu/auth/login.css b/assets/css/misuzu/auth/login.css new file mode 100644 index 0000000..e54518c --- /dev/null +++ b/assets/css/misuzu/auth/login.css @@ -0,0 +1,14 @@ +.auth__login--disabled { + --accent-colour: #555; + opacity: .5; +} +.auth__login__header { + display: flex; + justify-content: center; + padding: 20px; +} +.auth__login__avatar { + width: 100px; + height: 100px; + margin: 10px; +} diff --git a/assets/css/misuzu/auth/logout.css b/assets/css/misuzu/auth/logout.css new file mode 100644 index 0000000..8a1265d --- /dev/null +++ b/assets/css/misuzu/auth/logout.css @@ -0,0 +1,6 @@ +.auth__logout { + margin: 5px; +} +.auth__logout__paragraph { + margin: 5px 0; +} diff --git a/assets/css/misuzu/auth/register.css b/assets/css/misuzu/auth/register.css new file mode 100644 index 0000000..b4e37d6 --- /dev/null +++ b/assets/css/misuzu/auth/register.css @@ -0,0 +1,34 @@ +.auth__register { + max-width: 700px; + width: 100%; +} +.auth__register__container { + display: flex; + +} +.auth__register__form { + flex: 1 1 auto; +} +.auth__register__info { + max-width: 300px; + width: 100%; + flex: 0 1 auto; + padding: 5px; +} +.auth__register__paragraph { + line-height: 1.5em; + margin: 5px 0; +} +.auth__register__link { + color: inherit; + text-decoration: underline; +} + +@media (max-width: 800px) { + .auth__register__container { + flex-direction: column; + } + .auth__register__info { + max-width: 100%; + } +} \ No newline at end of file diff --git a/assets/css/misuzu/auth/warning.css b/assets/css/misuzu/auth/warning.css new file mode 100644 index 0000000..8db4266 --- /dev/null +++ b/assets/css/misuzu/auth/warning.css @@ -0,0 +1,10 @@ +.auth__warning { + margin: 5px; +} +.auth__warning--welcome { + --start-colour: var(--accent-colour); + --end-colour: #222; +} +.auth__warning__paragraph { + line-height: 2em; +} diff --git a/assets/css/misuzu/avatar.css b/assets/css/misuzu/avatar.css new file mode 100644 index 0000000..0813d08 --- /dev/null +++ b/assets/css/misuzu/avatar.css @@ -0,0 +1,13 @@ +.avatar { + flex-shrink: 0; + background-color: var(--background-colour); + display: block; + border: 0; + border-radius: 5%; + box-sizing: content-box; + box-shadow: 0 1px 4px #111; + vertical-align: middle; + max-width: 100%; + max-height: 100%; + overflow: hidden; +} diff --git a/assets/css/misuzu/changelog/_changelog.css b/assets/css/misuzu/changelog/_changelog.css new file mode 100644 index 0000000..1cd8f09 --- /dev/null +++ b/assets/css/misuzu/changelog/_changelog.css @@ -0,0 +1,6 @@ +.changelog__action--add { --action-colour: #159635 !important; } +.changelog__action--remove { --action-colour: #e33743 !important; } +.changelog__action--update { --action-colour: #297b8a !important; } +.changelog__action--fix { --action-colour: #2d5e96 !important; } +.changelog__action--import { --action-colour: #2b9678 !important; } +.changelog__action--revert { --action-colour: #e38245 !important; } diff --git a/assets/css/misuzu/changelog/change.css b/assets/css/misuzu/changelog/change.css new file mode 100644 index 0000000..d1fd8ee --- /dev/null +++ b/assets/css/misuzu/changelog/change.css @@ -0,0 +1,142 @@ +.changelog__change { + display: flex; + margin: 2px 0; +} +.changelog__change__info__content { + width: 200px; + text-align: center; + display: flex; + flex-direction: column; + padding: 15px; + flex: 0 0 auto; + margin-right: 4px; +} +.changelog__change__info__background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + mask-image: linear-gradient(270deg, transparent 10%, var(--background-colour) 100%); + -webkit-mask-image: linear-gradient(270deg, transparent 10%, var(--background-colour) 100%); + background: var(--background-pattern); + background-color: var(--accent-colour); + background-blend-mode: multiply; +} + +.changelog__change__user { + display: flex; + text-align: left; + align-items: center; + margin-bottom: 10px; +} +.changelog__change__user__details { + display: flex; + flex-direction: column; +} + +.changelog__change__avatar { + width: 60px; + height: 60px; + margin-right: 10px; +} + +.changelog__change__username { + color: inherit; + font-size: 1.4em; + line-height: 1.5em; + text-decoration: none; +} +.changelog__change__username[href]:hover { + text-decoration: underline; +} + +.changelog__change__userrole { + font-size: .9em; + line-height: 1.5em; + color: inherit; + text-decoration: none; +} +.changelog__change__userrole[href]:hover { + text-decoration: underline; +} + +.changelog__change__date { + color: inherit; + text-decoration: none; + font-size: 1.1em; + line-height: 1.5em; +} +.changelog__change__date:hover { + text-decoration: underline; +} + +.changelog__change__text { + line-height: 1.2em; + flex: 1 1 auto; + word-wrap: break-word; + overflow: hidden; + margin: 2px; +} + +.changelog__change__tags { + list-style: none; + display: flex; + flex-wrap: wrap; + margin-top: 10px; + justify-content: center; +} + +.changelog__change__tag { + border: 1px solid var(--accent-colour); + background-color: var(--accent-colour); + margin: 1px; + border-radius: 2px; +} +.changelog__change__tag__link { + background-color: var(--background-colour-translucent-9); + display: block; + width: 100%; + height: 100%; + color: inherit; + text-decoration: none; + padding: 0 5px; +} +.changelog__change__tag:hover, +.changelog__change__tag:focus { + text-decoration: underline; +} + +@media (max-width: 800px) { + .changelog__change { + flex-direction: column; + } + .changelog__change__info__content { + flex-direction: row; + align-items: center; + width: 100%; + flex-wrap: wrap; + } + .changelog__change__info__background { + mask-image: linear-gradient(0deg, transparent 10%, var(--background-colour) 100%); + -webkit-mask-image: linear-gradient(0deg, transparent 10%, var(--background-colour) 100%); + } + .changelog__change__info { + flex-direction: row; + margin: 0; + padding: 5px; + } + .changelog__change__user { + margin-bottom: 0; + margin-right: 10px; + } + .changelog__change__avatar { + width: 50px; + height: 50px; + } + .changelog__change__userrole { display: none; } + .changelog__change__tags { + margin-top: 0; + margin-left: 10px; + } +} diff --git a/assets/css/misuzu/changelog/container.css b/assets/css/misuzu/changelog/container.css new file mode 100644 index 0000000..5c6c990 --- /dev/null +++ b/assets/css/misuzu/changelog/container.css @@ -0,0 +1,3 @@ +.changelog__container { + margin: 2px 0; +} diff --git a/assets/css/misuzu/changelog/entry.css b/assets/css/misuzu/changelog/entry.css new file mode 100644 index 0000000..21a27bf --- /dev/null +++ b/assets/css/misuzu/changelog/entry.css @@ -0,0 +1,93 @@ +.changelog__entry { + display: flex; + margin: 5px; +} +.changelog__entry__info { display: flex; } + +.changelog__entry__datetime, +.changelog__entry__user, +.changelog__entry__action { + --action-colour: inherit; + + background-color: var(--action-colour); + color: var(--user-colour); + flex: 0 0 auto; + margin-right: 1px; + text-decoration: none; + display: flex; + align-items: center; +} +.changelog__entry__datetime:hover, +.changelog__entry__datetime:focus, +.changelog__entry__user:hover, +.changelog__entry__user:focus, +.changelog__entry__action:hover, +.changelog__entry__action:focus { + text-decoration: underline; +} +.changelog__entry__datetime__text, +.changelog__entry__user__text, +.changelog__entry__action__text { + width: 100%; +} + +.changelog__entry__datetime { + min-width: 100px; + text-align: center; +} + +.changelog__entry__user { + min-width: 100px; + padding-left: 4px; +} + +.changelog__entry__action { + border-radius: 2px; + min-width: 5px; +} +.changelog__entry__action__text { + text-align: right; + min-width: 80px; + padding-right: 4px; +} + +.changelog__entry__log { + word-wrap: break-word; + overflow: hidden; + flex: 1 1 auto; + margin-left: 2px; +} +.changelog__entry__log--link { + color: inherit; + text-decoration: underline dotted; +} +.changelog__entry__log--link:hover { + text-decoration: underline solid; +} + +.changelog__entry__tags { + display: flex; + flex-wrap: wrap; + font-size: .9em; + line-height: 1.5em; +} + +.changelog__entry__tag { + border: 1px solid var(--accent-colour); + margin-right: 1px; + border-radius: 2px; + display: block; + color: inherit; + text-decoration: none; + padding: 0 5px; +} +.changelog__entry__tag:hover { + text-decoration: underline; +} + +@media (max-width: 800px) { + .changelog__entry { flex-wrap: wrap; } + .changelog__entry__user { flex-grow: 1; } + .changelog__entry__action { margin-right: 0; } + .changelog__entry__log { width: 100%; } +} diff --git a/assets/css/misuzu/changelog/listing.css b/assets/css/misuzu/changelog/listing.css new file mode 100644 index 0000000..e16a4d8 --- /dev/null +++ b/assets/css/misuzu/changelog/listing.css @@ -0,0 +1,17 @@ +.changelog__listing__none { + margin: 1px 4px; +} +.changelog__listing__date { + display: block; + text-decoration: none; + padding: 1px 3px; + color: var(--accent-colour); + font-size: 1.2em; + line-height: 1.5em; +} +.changelog__listing__date:hover { + text-decoration: underline; +} +.changelog__listing__date:not(:first-child) { + margin-top: 4px; +} diff --git a/assets/css/misuzu/changelog/log.css b/assets/css/misuzu/changelog/log.css new file mode 100644 index 0000000..77da047 --- /dev/null +++ b/assets/css/misuzu/changelog/log.css @@ -0,0 +1,32 @@ +.changelog__log { + --action-colour: var(--accent-colour); + + border: 1px solid var(--action-colour); + background-color: var(--background-colour); + display: flex; + align-items: stretch; + flex: 1 0 auto; + margin: 2px 0; +} +.changelog__log__action { + display: block; + padding: 6px 2px; + background-color: var(--action-colour); + border-right: 1px solid var(--action-colour); + writing-mode: sideways-lr; + text-orientation: sideways; + letter-spacing: 1px; + text-align: center; + flex: 0 0 auto; +} +.changelog__log__text { + padding: 8px 12px; + font-size: 1.5em; + line-height: 1.3em; + align-self: center; + flex: 1 1 auto; + overflow: hidden; + width: 100%; + height: 100%; + word-wrap: break-word; +} diff --git a/assets/css/misuzu/changelog/pagination.css b/assets/css/misuzu/changelog/pagination.css new file mode 100644 index 0000000..1b9b235 --- /dev/null +++ b/assets/css/misuzu/changelog/pagination.css @@ -0,0 +1,3 @@ +.changelog__pagination { + margin: 5px; +} diff --git a/assets/css/misuzu/comments/comment.css b/assets/css/misuzu/comments/comment.css new file mode 100644 index 0000000..671b5d3 --- /dev/null +++ b/assets/css/misuzu/comments/comment.css @@ -0,0 +1,159 @@ +.comment { + margin: 10px; +} +.comment__reply-toggle { + display: none; +} +.comment__reply-toggle:checked ~ .comment--reply { + display: block; +} + +.comment--reply { + display: none; +} + +.comment--deleted > .comment__container { + opacity: .5; + transition: opacity .2s; +} +.comment--deleted > .comment__container:hover { + opacity: .9; +} + +.comment__container { + display: flex; + margin-bottom: 3px; +} + +.comment__mention { + color: var(--user-colour); + text-decoration: none; + font-weight: 700; +} +.comment__mention:hover { + text-decoration: underline; +} + +.comment__actions { + list-style: none; + display: flex; + font-size: .9em; + align-items: center; +} +.comment__action { + color: inherit; + text-decoration: none; + vertical-align: middle; + cursor: pointer; +} + +.comment__action:not(:last-child) { + margin-right: 6px; +} + +.comment__action--link:hover { + text-decoration: underline; +} + +.comment__action--post { + margin-left: auto; +} + +.comment__action--button { + cursor: pointer; + font: 12px/20px var(--font-regular); + padding: 0 10px; +} + +.comment__action--hide { + opacity: 0; + transition: opacity .2s; +} + +.comment__action--voted { + font-weight: 700; +} + +.comment__action__checkbox { + vertical-align: text-top; + margin-right: 2px; +} + +.comment__replies .comment--indent-1, +.comment__replies .comment--indent-2, +.comment__replies .comment--indent-3, +.comment__replies .comment--indent-4, +.comment__replies .comment--indent-5 { + margin-left: 20px; +} + +.comment__avatar { + flex: 0 0 auto; + height: 50px; + width: 50px; + margin-right: 5px; +} +.comment__replies .comment__avatar { + width: 40px; + height: 40px; +} + +.comment__content { + flex: 1 1 auto; + display: flex; + flex-direction: column; + overflow: hidden; + word-wrap: break-word; + padding-left: 5px; +} +.comment__content:hover .comment__action--hide { + opacity: 1; +} + +.comment__info { + display: inline-flex; +} + +.comment__text { + margin-right: 2px; +} +.comment__text--input { + min-width: 100%; + max-width: 100%; + min-height: 50px; + font: 12px/20px var(--font-regular); + margin-right: 1px; +} + +.comment__user { + color: var(--user-colour); + text-decoration: none; +} +.comment__user--link:hover { + text-decoration: underline; +} + +.comment__date, +.comment__pin { + color: #666; + font-size: .9em; + margin-left: 8px; +} + +.comment__link { + color: #666; + display: inline-flex; + text-decoration: none; + + &:hover { + text-decoration: underline; + } +} + +.comment__pin { + margin-left: 4px; +} +.comment__pin:before { + content: "-"; + padding-right: 4px; +} diff --git a/assets/css/misuzu/comments/comments.css b/assets/css/misuzu/comments/comments.css new file mode 100644 index 0000000..8b38130 --- /dev/null +++ b/assets/css/misuzu/comments/comments.css @@ -0,0 +1,36 @@ +.comments { + --comments-max-height: 600px; + margin: 1px; + overflow: hidden; + word-wrap: break-word; +} +.comments__listing { + overflow-y: auto; +} +.comments__listing--limit { + max-height: var(--comments-max-height); +} + +/*.comments__input,*/ +.comments__javascript, +.comments__notice--staff { + border-bottom: 1px solid var(--accent-colour); + padding-bottom: 1px; + margin-bottom: 1px; +} + +.comments__none, +.comments__javascript, +.comments__notice { + padding: 10px; + font-size: 1.2em; + text-align: center; +} + +.comments__notice__link { + color: var(--accent-colour); + text-decoration: none; +} +.comments__notice__link:hover { + text-decoration: underline; +} diff --git a/assets/css/misuzu/confirm.css b/assets/css/misuzu/confirm.css new file mode 100644 index 0000000..543edca --- /dev/null +++ b/assets/css/misuzu/confirm.css @@ -0,0 +1,11 @@ +.confirm { + max-width: 400px; + margin: 0 auto; +} +.confirm__buttons { + display: flex; + padding: 5px; + justify-content: center; +} +.confirm__message { padding: 2px 5px; } +.confirm__button { margin-right: 5px; } diff --git a/assets/css/misuzu/container.css b/assets/css/misuzu/container.css new file mode 100644 index 0000000..c1a4732 --- /dev/null +++ b/assets/css/misuzu/container.css @@ -0,0 +1,43 @@ +.container { + background-color: var(--container-colour); + box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); + text-shadow: 0 1px 4px #000; + overflow: hidden; + word-wrap: break-word; +} +.container--lazy { /* don't use this */ + margin-bottom: 2px; +} + +.container__title { + display: block; + overflow: hidden; +} +.container__title__text { + font-size: 1.5em; + line-height: 1.5em; + padding: 8px 10px; + word-wrap: break-word; +} +.container__title__link { + color: inherit; + text-decoration: none; +} +.container__title__link:hover { color: var(--accent-colour); } +.container__title__background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + mask-image: linear-gradient(0deg, transparent 10%, var(--background-colour) 100%); + -webkit-mask-image: linear-gradient(0deg, transparent 10%, var(--background-colour) 100%); + background: var(--background-pattern); + background-color: var(--accent-colour); + background-blend-mode: multiply; +} + +.container__content { /* only use this for text going forward, just throw your child directly after __title */ + margin: 0; + padding: 2px 5px; +} diff --git a/assets/css/misuzu/emoticon.css b/assets/css/misuzu/emoticon.css new file mode 100644 index 0000000..dd0f861 --- /dev/null +++ b/assets/css/misuzu/emoticon.css @@ -0,0 +1,4 @@ +.emoticon { + vertical-align: middle; + display: inline-block; +} diff --git a/assets/css/misuzu/flags.css b/assets/css/misuzu/flags.css new file mode 100644 index 0000000..f203698 --- /dev/null +++ b/assets/css/misuzu/flags.css @@ -0,0 +1,308 @@ +.flag { + display: inline-block; + width: 16px; + height: 11px; + background-image: url('/images/flag-sprite.png'); + background-repeat: no-repeat; + font-size: 0; + background-position: top -276px left -368px; +} +.flag__container { + min-width: 16px; + min-height: 11px; + display: block; +} + +/* Ax */ +.flag--ad { background-position: top 0 left -48px; } +.flag--ae { background-position: top 0 left -64px; } +.flag--af { background-position: top 0 left -80px; } +.flag--ag { background-position: top 0 left -96px; } +.flag--ai { background-position: top 0 left -128px; } +.flag--al { background-position: top 0 left -176px; } +.flag--am { background-position: top 0 left -192px; } +.flag--an { background-position: top 0 left -208px; } +.flag--ao { background-position: top 0 left -224px; } +.flag--ar { background-position: top 0 left -272px; } +.flag--as { background-position: top 0 left -288px; } +.flag--at { background-position: top 0 left -304px; } +.flag--au { background-position: top 0 left -320px; } +.flag--aw { background-position: top 0 left -352px; } +.flag--ax { background-position: top 0 left -368px; } +.flag--az { background-position: top 0 left -400px; } + +/* Bx */ +.flag--ba { background-position: top -12px left 0; } +.flag--bb { background-position: top -12px left -16px; } +.flag--bd { background-position: top -12px left -48px; } +.flag--be { background-position: top -12px left -64px; } +.flag--bf { background-position: top -12px left -80px; } +.flag--bg { background-position: top -12px left -96px; } +.flag--bh { background-position: top -12px left -112px; } +.flag--bi { background-position: top -12px left -128px; } +.flag--bj { background-position: top -12px left -144px; } +.flag--bm { background-position: top -12px left -192px; } +.flag--bn { background-position: top -12px left -208px; } +.flag--bo { background-position: top -12px left -224px; } +.flag--br { background-position: top -12px left -272px; } +.flag--bs { background-position: top -12px left -288px; } +.flag--bt { background-position: top -12px left -304px; } +.flag--bv { background-position: top -12px left -336px; } +.flag--bw { background-position: top -12px left -352px; } +.flag--by { background-position: top -12px left -384px; } +.flag--bz { background-position: top -12px left -400px; } + +/* Cx */ +.flag--ca { background-position: top -24px left 0; } +.flag--cc { background-position: top -24px left -32px; } +.flag--cd { background-position: top -24px left -48px; } +.flag--cf { background-position: top -24px left -80px; } +.flag--cg { background-position: top -24px left -96px; } +.flag--ch { background-position: top -24px left -112px; width: 11px; } +.flag--ci { background-position: top -24px left -128px; } +.flag--ck { background-position: top -24px left -160px; } +.flag--cl { background-position: top -24px left -176px; } +.flag--cm { background-position: top -24px left -192px; } +.flag--cn { background-position: top -24px left -208px; } +.flag--co { background-position: top -24px left -224px; } +.flag--cr { background-position: top -24px left -272px; } +.flag--cs { background-position: top -24px left -288px; } +.flag--cu { background-position: top -24px left -320px; } +.flag--cv { background-position: top -24px left -336px; } +.flag--cx { background-position: top -24px left -368px; } +.flag--cy { background-position: top -24px left -384px; } +.flag--cz { background-position: top -24px left -400px; } + +/* Dx */ +.flag--de { background-position: top -36px left -64px; } +.flag--dj { background-position: top -36px left -144px; } +.flag--dk { background-position: top -36px left -160px; } +.flag--dm { background-position: top -36px left -192px; } +.flag--do { background-position: top -36px left -224px; } +.flag--dz { background-position: top -36px left -400px; } + +/* Ex */ +.flag--ec { background-position: top -48px left -32px; } +.flag--ee { background-position: top -48px left -64px; } +.flag--eg { background-position: top -48px left -96px; } +.flag--eh { background-position: top -48px left -112px; } +.flag--er { background-position: top -48px left -272px; } +.flag--es { background-position: top -48px left -288px; } +.flag--et { background-position: top -48px left -304px; } + +/* Fx */ +.flag--fi { background-position: top -60px left -128px; } +.flag--fj { background-position: top -60px left -144px; } +.flag--fk { background-position: top -60px left -160px; } +.flag--fm { background-position: top -60px left -192px; } +.flag--fo { background-position: top -60px left -224px; } +.flag--fr { background-position: top -60px left -272px; } + +/* Gx */ +.flag--ga { background-position: top -72px left 0; } +.flag--gb { background-position: top -72px left -16px; } +.flag--gd { background-position: top -72px left -48px; } +.flag--ge { background-position: top -72px left -64px; } +.flag--gf { background-position: top -72px left -80px; } +.flag--gh { background-position: top -72px left -112px; } +.flag--gi { background-position: top -72px left -128px; } +.flag--gl { background-position: top -72px left -176px; } +.flag--gm { background-position: top -72px left -192px; } +.flag--gn { background-position: top -72px left -208px; } +.flag--gp { background-position: top -72px left -240px; } +.flag--gq { background-position: top -72px left -256px; } +.flag--gr { background-position: top -72px left -272px; } +.flag--gs { background-position: top -72px left -288px; } +.flag--gt { background-position: top -72px left -304px; } +.flag--gu { background-position: top -72px left -320px; } +.flag--gw { background-position: top -72px left -352px; } +.flag--gy { background-position: top -72px left -384px; } + +/* Hx */ +.flag--hk { background-position: top -84px left -160px; } +.flag--hm { background-position: top -84px left -192px; } +.flag--hn { background-position: top -84px left -208px; } +.flag--hr { background-position: top -84px left -272px; } +.flag--ht { background-position: top -84px left -304px; } +.flag--hu { background-position: top -84px left -320px; } + +/* Ix */ +.flag--id { background-position: top -96px left -48px; } +.flag--ie { background-position: top -96px left -64px; } +.flag--il { background-position: top -96px left -176px; } +.flag--in { background-position: top -96px left -208px; } +.flag--io { background-position: top -96px left -224px; } +.flag--iq { background-position: top -96px left -256px; } +.flag--ir { background-position: top -96px left -272px; } +.flag--is { background-position: top -96px left -288px; } +.flag--it { background-position: top -96px left -304px; } + +/* Jx */ +.flag--jm { background-position: top -108px left -192px; } +.flag--jo { background-position: top -108px left -224px; } +.flag--jp { background-position: top -108px left -240px; } + +/* Kx */ +.flag--ke { background-position: top -120px left -64px; } +.flag--kg { background-position: top -120px left -96px; } +.flag--kh { background-position: top -120px left -112px; } +.flag--ki { background-position: top -120px left -128px; } +.flag--km { background-position: top -120px left -192px; } +.flag--kn { background-position: top -120px left -208px; } +.flag--kp { background-position: top -120px left -240px; } +.flag--kr { background-position: top -120px left -272px; } +.flag--kw { background-position: top -120px left -352px; } +.flag--ky { background-position: top -120px left -384px; } +.flag--kz { background-position: top -120px left -400px; } + +/* Lx */ +.flag--la { background-position: top -132px left 0; } +.flag--lb { background-position: top -132px left -16px; } +.flag--lc { background-position: top -132px left -32px; } +.flag--li { background-position: top -132px left -128px; } +.flag--lk { background-position: top -132px left -160px; } +.flag--lr { background-position: top -132px left -272px; } +.flag--ls { background-position: top -132px left -288px; } +.flag--lt { background-position: top -132px left -304px; } +.flag--lu { background-position: top -132px left -320px; } +.flag--lv { background-position: top -132px left -336px; } +.flag--ly { background-position: top -132px left -384px; } + +/* Mx */ +.flag--ma { background-position: top -144px left 0; } +.flag--mc { background-position: top -144px left -32px; } +.flag--md { background-position: top -144px left -48px; } +.flag--me { background-position: top -144px left -64px; height: 12px; } +.flag--mg { background-position: top -144px left -96px; } +.flag--mh { background-position: top -144px left -112px; } +.flag--mk { background-position: top -144px left -160px; } +.flag--ml { background-position: top -144px left -176px; } +.flag--mm { background-position: top -144px left -192px; } +.flag--mn { background-position: top -144px left -208px; } +.flag--mo { background-position: top -144px left -224px; } +.flag--mp { background-position: top -144px left -240px; } +.flag--mq { background-position: top -144px left -256px; } +.flag--mr { background-position: top -144px left -272px; } +.flag--ms { background-position: top -144px left -288px; } +.flag--mt { background-position: top -144px left -304px; } +.flag--mu { background-position: top -144px left -320px; } +.flag--mv { background-position: top -144px left -336px; } +.flag--mw { background-position: top -144px left -352px; } +.flag--mx { background-position: top -144px left -368px; } +.flag--my { background-position: top -144px left -384px; } +.flag--mz { background-position: top -144px left -400px; } + +/* Nx */ +.flag--na { background-position: top -156px left 0; } +.flag--nc { background-position: top -156px left -32px; } +.flag--ne { background-position: top -156px left -64px; } +.flag--nf { background-position: top -156px left -80px; } +.flag--ng { background-position: top -156px left -96px; } +.flag--ni { background-position: top -156px left -128px; } +.flag--nl { background-position: top -156px left -176px; } +.flag--no { background-position: top -156px left -224px; } +.flag--np { background-position: top -156px left -240px; width: 9px; } +.flag--nr { background-position: top -156px left -272px; } +.flag--nu { background-position: top -156px left -320px; } +.flag--nz { background-position: top -156px left -400px; } + +/* Ox */ +.flag--ok { background-position: top -168px left -160px; } + +/* Px */ +.flag--pa { background-position: top -180px left 0; } +.flag--pe { background-position: top -180px left -64px; } +.flag--pf { background-position: top -180px left -80px; } +.flag--pg { background-position: top -180px left -96px; } +.flag--ph { background-position: top -180px left -112px; } +.flag--pk { background-position: top -180px left -160px; } +.flag--pl { background-position: top -180px left -176px; } +.flag--pm { background-position: top -180px left -192px; } +.flag--pn { background-position: top -180px left -208px; } +.flag--pr { background-position: top -180px left -272px; } +.flag--ps { background-position: top -180px left -288px; } +.flag--pt { background-position: top -180px left -304px; } +.flag--pw { background-position: top -180px left -352px; } +.flag--py { background-position: top -180px left -384px; } + +/* Qx */ +.flag--qa { background-position: top -192px left 0; } + +/* Rx */ +.flag--re { background-position: top -204px left -64px; } +.flag--ro { background-position: top -204px left -224px; } +.flag--rs { background-position: top -204px left -288px; } +.flag--ru { background-position: top -204px left -320px; } +.flag--rw { background-position: top -204px left -352px; } + +/* Sx */ +.flag--sa { background-position: top -216px left 0; } +.flag--sb { background-position: top -216px left -16px; } +.flag--sc { background-position: top -216px left -32px; } +.flag--sd { background-position: top -216px left -48px; } +.flag--se { background-position: top -216px left -64px; } +.flag--sg { background-position: top -216px left -96px; } +.flag--sh { background-position: top -216px left -112px; } +.flag--si { background-position: top -216px left -128px; } +.flag--sj { background-position: top -216px left -144px; } +.flag--sk { background-position: top -216px left -160px; } +.flag--sl { background-position: top -216px left -176px; } +.flag--sm { background-position: top -216px left -192px; } +.flag--sn { background-position: top -216px left -208px; } +.flag--so { background-position: top -216px left -224px; } +.flag--sr { background-position: top -216px left -272px; } +.flag--st { background-position: top -216px left -304px; } +.flag--sv { background-position: top -216px left -336px; } +.flag--sy { background-position: top -216px left -384px; } +.flag--sz { background-position: top -216px left -400px; } + +/* Tx */ +.flag--tc { background-position: top -228px left -32px; } +.flag--td { background-position: top -228px left -48px; } +.flag--tf { background-position: top -228px left -80px; } +.flag--tg { background-position: top -228px left -96px; } +.flag--th { background-position: top -228px left -112px; } +.flag--tj { background-position: top -228px left -144px; } +.flag--tk { background-position: top -228px left -160px; } +.flag--tl { background-position: top -228px left -176px; } +.flag--tm { background-position: top -228px left -192px; } +.flag--tn { background-position: top -228px left -208px; } +.flag--to { background-position: top -228px left -224px; } +.flag--tr { background-position: top -228px left -272px; } +.flag--tt { background-position: top -228px left -304px; } +.flag--tv { background-position: top -228px left -336px; } +.flag--tw { background-position: top -228px left -352px; } +.flag--tz { background-position: top -228px left -400px; } + +/* Ux */ +.flag--ua { background-position: top -240px left 0; } +.flag--ug { background-position: top -240px left -96px; } +.flag--um { background-position: top -240px left -192px; } +.flag--us { background-position: top -240px left -288px; } +.flag--uy { background-position: top -240px left -384px; } +.flag--uz { background-position: top -240px left -400px; } + +/* Vx */ +.flag--va { background-position: top -252px left 0; } +.flag--vc { background-position: top -252px left -32px; } +.flag--ve { background-position: top -252px left -64px; } +.flag--vg { background-position: top -252px left -96px; } +.flag--vi { background-position: top -252px left -128px; } +.flag--vn { background-position: top -252px left -208px; } +.flag--vu { background-position: top -252px left -320px; } + +/* Wx */ +.flag--wf { background-position: top -264px left -80px; } +.flag--ws { background-position: top -264px left -288px; } + +/* Xx */ +.flag--xm { background-position: top -276px left -192px; } + +/* Yx */ +.flag--ye { background-position: top -288px left -64px; } +.flag--yt { background-position: top -288px left -304px; } + +/* Zx */ +.flag--za { background-position: top -300px left 0; } +.flag--zm { background-position: top -300px left -192px; } +.flag--zw { background-position: top -300px left -352px; } diff --git a/assets/css/misuzu/footer.css b/assets/css/misuzu/footer.css new file mode 100644 index 0000000..79360e9 --- /dev/null +++ b/assets/css/misuzu/footer.css @@ -0,0 +1,31 @@ +.footer { + flex: 0 0 auto; +} +.footer__link { + color: inherit; + text-decoration: none; +} +.footer__link:focus, +.footer__link:hover { + text-decoration: underline; +} +.footer__wrapper { + max-width: var(--site-max-width); + margin: 0 auto; + text-align: center; + font-size: .9em; + line-height: 1.5em; + padding: 1em 0; +} +.footer__background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + mask-image: linear-gradient(180deg, transparent 10%, var(--background-colour) 100%); + -webkit-mask-image: linear-gradient(180deg, transparent 10%, var(--background-colour) 100%); + background: var(--background-pattern); + background-color: var(--header-accent-colour); + background-blend-mode: multiply; +} diff --git a/assets/css/misuzu/forum/actions.css b/assets/css/misuzu/forum/actions.css new file mode 100644 index 0000000..6822c85 --- /dev/null +++ b/assets/css/misuzu/forum/actions.css @@ -0,0 +1,32 @@ +.forum__actions { + margin: 2px 0; + padding: 5px; + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: stretch; +} + +.forum__actions__pagination { + max-width: 500px; + flex: 1 1 auto; + display: flex; + align-items: stretch; + justify-content: space-between; +} + +.forum__actions__buttons { + flex: 0 0 auto; + display: flex; + align-items: stretch; +} +.forum__actions__button { + margin-right: 5px; +} + +@media (max-width: 800px) { + .forum__actions__pagination { + max-width: 100%; + flex-grow: 0; + } +} diff --git a/assets/css/misuzu/forum/categories.css b/assets/css/misuzu/forum/categories.css new file mode 100644 index 0000000..efd55e5 --- /dev/null +++ b/assets/css/misuzu/forum/categories.css @@ -0,0 +1,232 @@ +.forum__categories { + margin: 2px 0; + box-sizing: content-box; + overflow: auto; +} +.forum__categories__empty { + font-size: 1.2em; + line-height: 1.5em; + text-align: center; + padding: 10px; +} +.forum__categories__list { + display: flex; + flex-direction: column; + margin: 5px; + overflow: hidden; +} + +.forum__category { + border-radius: 2px; + background-color: rgba(17, 17, 17, .6); + transition: background-color .2s, box-shadow .2s; +} +.forum__category:nth-child(even) { + background-color: rgba(25, 25, 25, .6); +} +.forum__category:hover, +.forum__category:focus { + background-color: #2229; + box-shadow: 0 1px 4px #222; +} +.forum__category:not(:last-child) { + margin-bottom: 4px; +} + +.forum__category__link { + display: block; + position: absolute; + left: 0; + top: 0; + width: 100%; + height: 100%; + color: inherit; + text-decoration: none; +} + +.forum__category__container { + display: flex; + padding: 5px; + align-items: center; + min-height: 50px; + pointer-events: none; + +} + +.forum__category__icon { + flex: 0 0 40px; + border-radius: 2px; + width: 40px; + height: 40px; + margin-right: 4px; + background-color: #333; + background-size: 80px 80px; + background-image: radial-gradient(ellipse at center, rgba(255, 255, 255, .2) 0%, rgba(0, 0, 0, .4) 100%); + box-shadow: 0 1px 4px #111; + font-size: 2em; + line-height: 1.5em; + color: #fff; + display: flex; + justify-content: center; + align-items: center; + padding-bottom: 1px; /* fixes centering */ +} +.forum__category__icon--unread { + background-color: var(--accent-colour); +} + +.forum__category__details { + margin: 0 4px; + flex: 1 1 auto; + display: flex; + justify-content: center; + flex-direction: column; + line-height: 1.5em; +} + +.forum__category__title { + font-size: 1.3em; +} + +.forum__category__description, +.forum__category__subforums { + font-size: .9em; +} + +.forum__category__subforums { + display: flex; +} +.forum__category__subforum { + padding: 2px; + pointer-events: initial; + color: var(--accent-colour); + text-decoration: none; +} + +.forum__category__subforum:hover, +.forum__category__subforum:focus { + text-decoration: underline; +} + +.forum__category__subforum--unread { + font-weight: 700; +} + +.forum__category__stats, +.forum__category__activity { + display: flex; + flex: 0 0 auto; +} + +.forum__category__stats { + text-align: center; + min-width: 100px; + flex-direction: column; +} + +.forum__category__stat { + font-size: .9em; + line-height: 1.3em; + opacity: .7; + pointer-events: auto; +} + +.forum__category__stat:first-child { + font-size: 1.5em; + opacity: 1; +} + +.forum__category__activity { + text-align: right; + min-width: 270px; + line-height: 1.5em; +} +.forum__category__activity__none, +.forum__category__activity__details { + margin: 0 8px; + flex: 1 1 auto; +} + +.forum__category__activity__details { + display: flex; + flex-direction: column; + align-items: flex-end; +} + +.forum__category__activity__post { + color: var(--accent-colour); + text-decoration: none; + pointer-events: initial; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + max-width: 200px; +} +.forum__category__activity__post:hover, +.forum__category__activity__post:focus { + text-decoration: underline; +} + +.forum__category__username { + color: var(--user-colour); + text-decoration: none; + pointer-events: initial; +} +.forum__category__username:hover, +.forum__category__username:focus { + text-decoration: underline; +} + +.forum__category__avatar { + display: block; + flex: 0 0 auto; + text-decoration: none; + color: inherit; + width: 40px; + height: 40px; + pointer-events: initial; +} + + +@media (max-width: 800px) { + .forum__category__container { + flex-wrap: wrap; + } + .forum__category__details { + flex-basis: calc(100% - 100px); + } + .forum__category__stats { + min-width: initial; + border-left-width: 0; + align-self: flex-start; + align-items: flex-end; + } + .forum__category__stat { + font-size: 1em; + margin: 0 4px; + } + .forum__category__activity { + min-width: 100%; + } + .forum__category__activity--empty { + display: none; + } + .forum__category__activity__none, + .forum__category__activity__details { + margin: 1px 4px 0; + } + .forum__category__activity__details { + flex-direction: row; + } + .forum__category__activity__post { + flex: 1 0 auto; + text-align: left; + max-width: 120px; + } + .forum__category__activity__info { + width: 100%; + } + .forum__category__avatar { + display: none; + } +} \ No newline at end of file diff --git a/assets/css/misuzu/forum/confirm.css b/assets/css/misuzu/forum/confirm.css new file mode 100644 index 0000000..9056387 --- /dev/null +++ b/assets/css/misuzu/forum/confirm.css @@ -0,0 +1,15 @@ +.forum__confirm { + max-width: 400px; + margin: 0 auto; +} +.forum__confirm__message { + padding: 2px 5px; +} +.forum__confirm__buttons { + display: flex; + padding: 5px; + justify-content: center; +} +.forum__confirm__button { + margin-right: 5px; +} diff --git a/assets/css/misuzu/forum/header.css b/assets/css/misuzu/forum/header.css new file mode 100644 index 0000000..b3d86c7 --- /dev/null +++ b/assets/css/misuzu/forum/header.css @@ -0,0 +1,73 @@ +.forum__header { + display: flex; + flex-direction: column; + align-items: flex-start; + padding: 8px 10px; + margin: 2px 0; +} + +.forum__header__title { + font-size: 2em; + line-height: 1.5em; + color: inherit; + text-decoration: none; + padding: 0 5px; +} +.forum__header__title[href]:hover { + text-decoration: underline; +} +.forum__header__title--fill { + width: 100%; +} + +.forum__header__input { + width: 100%; + background-color: transparent; + border: 0; + padding: 0; + margin: 0; + box-shadow: initial; + font-size: 1em; + font-family: inherit; +} + +.forum__header__breadcrumbs { + display: flex; + font-size: 1.1em; + line-height: 1.5em; + align-items: center; +} +.forum__header__breadcrumb { + color: var(--accent-colour); + text-decoration: none; + padding: 2px 5px; +} +.forum__header__breadcrumb:hover { + text-decoration: underline; +} +.forum__header__breadcrumb__separator { + color: var(--accent-colour); + margin: 0 4px; + font-size: .9em; +} + +.forum__header__actions { + display: flex; +} +.forum__header__action { + color: inherit; + text-decoration: none; + transition: color .2s; + padding: 2px 5px; + transition: opacity .2s; +} +.forum__header__action:hover, +.forum__header__action:focus { + color: var(--accent-colour); +} +.forum__header__action:not(:last-child) { + margin-right: 5px; +} +.forum__header__action[disabled] { + opacity: .4; +} diff --git a/assets/css/misuzu/forum/leaderboard.css b/assets/css/misuzu/forum/leaderboard.css new file mode 100644 index 0000000..0805743 --- /dev/null +++ b/assets/css/misuzu/forum/leaderboard.css @@ -0,0 +1,113 @@ +.forum__leaderboard__categories { + display: block; + overflow-x: auto; + overflow-y: hidden; + white-space: nowrap; + margin: 2px 0; + scrollbar-width: thin; +} + +.forum__leaderboard__category { + display: inline-block; + color: inherit; + text-decoration: none; + margin: 2px; + padding: 2px 5px; + border-radius: 4px; + transition: background-color .2s; +} +.forum__leaderboard__category:hover, +.forum__leaderboard__category:focus { + background-color: rgba(255, 255, 255, .2); +} +.forum__leaderboard__category--active, +.forum__leaderboard__category:active { + background-color: rgba(255, 255, 255, .1); +} + +.forum__leaderboard__markdown { + display: block; + width: 100%; + min-width: 100%; + max-width: 100%; + min-height: 500px; + margin: 2px auto; +} + +.forum__leaderboard__user { + margin: 2px 0; + font-size: 1.2em; +} +.forum__leaderboard__user--rank-1 { + font-size: 1.6em; +} +.forum__leaderboard__user--rank-2, +.forum__leaderboard__user--rank-3 { + font-size: 1.4em; +} + +.forum__leaderboard__user__background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + text-decoration: none; + color: inherit; +} + +.forum__leaderboard__user__content { + display: flex; + pointer-events: none; +} + +.forum__leaderboard__user__rank { + height: 40px; + min-width: 50px; + display: flex; + align-items: center; + justify-content: center; + font-weight: 700; + flex: 0 0 auto; +} +.forum__leaderboard__user__rank:before { + content: "#"; +} +.forum__leaderboard__user--rank-1 .forum__leaderboard__user__rank { + height: 50px; +} + +.forum__leaderboard__user__avatar { + width: 40px; + height: 40px; + margin: 2px 7px; + flex: 0 0 auto; +} +.forum__leaderboard__user--rank-1 .forum__leaderboard__user__avatar { + width: 50px; + height: 50px; + margin: 2px; +} + +.forum__leaderboard__user__username { + flex: 1 1 auto; + line-height: 30px; + padding: 5px; + margin: 2px; +} +.forum__leaderboard__user--rank-1 .forum__leaderboard__user__username { + line-height: 40px; +} + +.forum__leaderboard__user__posts { + flex: 0 0 auto; + min-width: 150px; + border-left: 1px solid rgba(255, 255, 255, .2); + line-height: 30px; + padding: 5px; + margin: 2px; +} + +.forum__leaderboard__user--rank-1 .forum__leaderboard__user__posts { + line-height: 40px; +} diff --git a/assets/css/misuzu/forum/poll.css b/assets/css/misuzu/forum/poll.css new file mode 100644 index 0000000..1e77a8d --- /dev/null +++ b/assets/css/misuzu/forum/poll.css @@ -0,0 +1,104 @@ +.forum__poll__container { + margin: 2px 0; + padding: 5px; + display: flex; + flex-direction: column; + align-items: center; +} + +.forum__poll__toggle, +.forum__poll__toggle:checked ~ .forum__poll__container--poll, +.forum__poll__toggle:not(:checked) ~ .forum__poll__container--results { + display: none; +} + +.forum__poll__options { + display: flex; + flex-direction: column; + max-width: 500px; + min-width: 100%; +} + +.forum__poll__results { + max-width: 800px; + width: 100%; + padding: 0 1px; +} + +.forum__poll__option { + padding: 2px; +} + +.forum__poll__remaining, +.forum__poll__expires { + line-height: 1.5em; +} +.forum__poll__remaining__num, +.forum__poll__expires__num, +.forum__poll__remaining__datetime, +.forum__poll__expires__datetime { + font-weight: 700; +} + +.forum__poll__buttons { + display: flex; + margin-top: 2px; +} + +.forum__poll__button { + margin: 0 2px; +} + +.forum__poll__result { + overflow: hidden; + border-radius: 5px; + margin: 4px 0; + border: 1px solid var(--accent-colour); + width: 100%; +} + +.forum__poll__result__background { + position: absolute; + top: 0; + left: 0; + height: 100%; + background: var(--accent-colour); + opacity: .2; +} + +.forum__poll__result--voted .forum__poll__result__background { + opacity: .4; +} + +.forum__poll__result__container { + display: flex; + justify-content: center; +} + +.forum__poll__result__text { + flex: 1 1 auto; + padding: 5px; +} + +.forum__poll__result--voted .forum__poll__result__text { + font-weight: 700; +} + +.forum__poll__result__votes { + flex: 0 0 auto; + padding: 5px; + text-align: right; +} + +.forum__poll__result__percent { + flex: 0 0 auto; + padding: 5px; + min-width: 60px; + text-align: right; +} + +@media (min-width: 400px) { + .forum__poll__options { + min-width: 300px; + } +} diff --git a/assets/css/misuzu/forum/post.css b/assets/css/misuzu/forum/post.css new file mode 100644 index 0000000..eaeb376 --- /dev/null +++ b/assets/css/misuzu/forum/post.css @@ -0,0 +1,254 @@ +.forum__post { + display: flex; + margin: 2px 0; +} +.forum__post--deleted { + opacity: .5; + transition: opacity .2s; +} +.forum__post--deleted:hover, +.forum__post--deleted:focus, +.forum__post--deleted:focus-within { + opacity: .8; +} + +.forum__post__content { + display: flex; + flex-direction: column; + flex-grow: 1; + flex-shrink: 1; + word-wrap: break-word; + overflow: hidden; +} + +.forum__post__details { + font-size: .9em; + line-height: 1.7em; + padding: 0 2px; + display: flex; + justify-content: space-between; + color: #888; +} + +.forum__post__datetime, +.forum__post__id, +.forum__post__mode { + color: inherit; + text-decoration: none; +} +.forum__post__datetime:hover, +.forum__post__datetime:focus, +.forum__post__id:hover, +.forum__post__id:focus, +.forum__post__mode:hover, +.forum__post__mode:focus { + text-decoration: underline; +} + +.forum__post__text { + margin: 2px; + line-height: 1.2em; + flex: 1 1 auto; + overflow: auto; +} +.forum__post__text--edit { + /* figure out why this is needed */ + max-width: calc(100% - 4px); + min-width: calc(100% - 4px); + margin: 2px 2px 0; + min-height: 400px; + height: 100%; + border: 0; + padding: 2px 5px; + font-size: inherit; + color: inherit; + background-color: rgba(0, 0, 0, .2); + font-family: inherit; +} + +.forum__post__info__content { + width: 150px; + text-align: center; + display: flex; + flex-direction: column; + align-items: center; + padding: 15px; + flex: 0 0 auto; + margin-right: 4px; +} +.forum__post__info__background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + mask-image: linear-gradient(270deg, transparent 10%, var(--background-colour) 100%); + -webkit-mask-image: linear-gradient(270deg, transparent 10%, var(--background-colour) 100%); + background: var(--background-pattern); + background-color: var(--accent-colour); + background-blend-mode: multiply; +} + +.forum__post__icons { + display: flex; + align-items: center; +} + +.forum__post__posts-count { + font-size: .9em; + margin-left: 4px; +} + +.forum__post__joined { + flex: 1 1 auto; + max-width: 170px; + font-size: .9em; + justify-self: flex-end; +} + +.forum__post__avatar { + color: inherit; + text-decoration: none; + width: 120px; + height: 120px; +} + +.forum__post__username { + color: inherit; + font-size: 1.4em; + line-height: 2em; + text-decoration: none; +} +.forum__post__username[href]:hover, +.forum__post__username[href]:focus { + text-decoration: underline; +} + +.forum__post__usertitle { + font-size: .9em; + line-height: 1.5em; + margin-bottom: 4px; +} + +.forum__post__options { + margin: 5px; + display: flex; + justify-content: space-between; + align-items: center; +} + +.forum__post__settings { + display: flex; + align-items: center; +} + +.forum__post__dropdown { + margin-right: 5px; +} + +.forum__post__actions { + display: flex; + padding: 1px; +} + +.forum__post__action { + padding: 5px 10px; + margin: 1px; + color: inherit; + text-decoration: none; + transition: background-color .2s; + border-radius: 3px; + cursor: pointer; +} +.forum__post__action:hover, +.forum__post__action:focus { + background-color: rgba(0, 0, 0, .2); +} + +.forum__post__signature { + background-color: rgba(0, 0, 0, .2); + padding: 2px; + max-height: 150px; + overflow: hidden; +} +.forum__post__signature img { + vertical-align: middle; +} + +.forum__post__badge { + background-color: var(--accent-colour); + border-radius: 12px; + width: 100%; + padding: 2px; + box-shadow: 0 2px 3px #000A; + margin: 4px; + overflow: hidden; +} +.forum__post__badge__desktop { + display: block; +} +.forum__post__badge__mobile { + display: none; +} + +@media (max-width: 800px) { + .forum__post { + flex-direction: column; + } + .forum__post__text { + margin: 4px; + font-size: 1.2em; + line-height: 1.3em; + } + .forum__post__info { + flex-direction: row; + margin: 0; + padding: 5px; + } + .forum__post__info__content { + width: 100%; + flex-direction: row; + padding: 10px; + } + .forum__post__info__background { + mask-image: linear-gradient(0deg, transparent 10%, var(--background-colour) 100%); + -webkit-mask-image: linear-gradient(0deg, transparent 10%, var(--background-colour) 100%); + } + .forum__post__icons { + flex-direction: column; + align-items: flex-end; + } + .forum__post__joined { + display: none; + } + .forum__post__avatar { + width: 40px; + height: 40px; + margin-right: 4px; + } + .forum__post__username { + flex: 1 1 auto; + text-align: left; + margin: 0 4px; + } + .forum__post__usertitle { + display: none; + } + .forum__post__options { + flex-direction: column; + } + .forum__post__badge { + width: auto; + padding: 2px 10px; + margin: 0; + align-self: flex-start; + margin-left: 5px; + font-size: .9em; + } + .forum__post__badge__desktop { + display: none; + } + .forum__post__badge__mobile { + display: block; + } +} diff --git a/assets/css/misuzu/forum/priority.css b/assets/css/misuzu/forum/priority.css new file mode 100644 index 0000000..2a15218 --- /dev/null +++ b/assets/css/misuzu/forum/priority.css @@ -0,0 +1,37 @@ +.forum__priority__votes { + text-align: center; + margin: 5px 16px 5px 5px; + -webkit-touch-callout: none !important; + -webkit-user-select: none !important; + -khtml-user-select: none !important; + -moz-user-select: none !important; + -ms-user-select: none !important; + user-select: none !important; + cursor: default; +} + +.forum__priority__vote { + font-size: 14px; + display: inline; +} + +.forum__priority__star { + margin-right: -.9em; + opacity: .6; + text-shadow: 0 1px 1px #000; + color: var(--user-colour); + transition: text-shadow .2s; +} +.forum__priority__star:last-child { + margin-right: 0; + opacity: 1; +} + +.forum__priority__vote:hover .forum__priority__star { + text-shadow: 0 0 1px #fff; +} + +.forum__priority__input { + margin: 5px; + text-align: center; +} diff --git a/assets/css/misuzu/forum/status.css b/assets/css/misuzu/forum/status.css new file mode 100644 index 0000000..176f7d1 --- /dev/null +++ b/assets/css/misuzu/forum/status.css @@ -0,0 +1,38 @@ +.forum__status { + display: flex; + align-items: center; + min-height: 40px; + margin: 2px 0; +} + +.forum__status__icon { + height: 40px; + width: 40px; + flex: 0 0 auto; + display: flex; + justify-content: center; + align-items: center; + font-size: 2em; + padding-bottom: 1px; +} +.forum__status__icon__background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + mask-image: linear-gradient(270deg, transparent 10%, var(--background-colour) 100%); + -webkit-mask-image: linear-gradient(270deg, transparent 10%, var(--background-colour) 100%); + background: var(--background-pattern); + background-color: var(--accent-colour); + background-blend-mode: multiply; +} + +.forum__status__text { + margin: 0 5px; + flex: 1 1 auto; +} + +.forum__status__emphasis { + font-weight: 700; +} diff --git a/assets/css/misuzu/forum/topics.css b/assets/css/misuzu/forum/topics.css new file mode 100644 index 0000000..91a24f4 --- /dev/null +++ b/assets/css/misuzu/forum/topics.css @@ -0,0 +1,288 @@ +.forum__topics { + margin-bottom: 2px; + box-sizing: content-box; + overflow: auto; +} +.forum__topics__empty { + font-size: 1.2em; + line-height: 1.5em; + text-align: center; + padding: 10px; +} +.forum__topics__list { + display: flex; + flex-direction: column; + margin: 5px; + overflow: hidden; +} + +.forum__topic { + border-radius: 2px; + background-color: rgba(17, 17, 17, .6); + transition: background-color .2s, box-shadow .2s, opacity .2s; +} +.forum__topic:nth-child(even) { + background-color: rgba(25, 25, 25, .6); +} +.forum__topic:hover, +.forum__topic:focus { + background-color: rgba(34, 34, 34, .6); + box-shadow: 0 1px 4px #222; +} +.forum__topic:not(:last-child) { + margin-bottom: 4px; +} +.forum__topic--deleted { + opacity: .4; +} +.forum__topic--deleted .forum__topic:hover, +.forum__topic--deleted .forum__topic:focus { + opacity: .8; +} +.forum__topic--locked { + opacity: .6; +} +.forum__topic--locked .forum__topic:hover, +.forum__topic--locked .forum__topic:focus { + opacity: 1; +} + +.forum__topic__link { + display: block; + position: absolute; + left: 0; + top: 0; + width: 100%; + height: 100%; + color: inherit; + text-decoration: none; +} + +.forum__topic__container { + display: flex; + padding: 5px; + align-items: center; + min-height: 40px; + pointer-events: none; +} + +.forum__topic__icon { + flex: 0 0 auto; + border-radius: 2px; + width: 30px; + height: 30px; + margin-right: 4px; + background-color: #333; + background-size: 60px 60px; + background-image: radial-gradient(ellipse at center, rgba(255, 255, 255, .2) 0%, rgba(0, 0, 0, .4) 100%); + box-shadow: 0 1px 4px #111; + font-size: 1.5em; + line-height: 1.5em; + color: #fff; + display: flex; + justify-content: center; + align-items: center; + padding: 1px 1px 0 2px; +} +.forum__topic__icon--wide { + width: 60px; +} + +.forum__topic__icon--unread { + background-color: var(--accent-colour); +} +.forum__topic__icon--faded { + opacity: .3; +} +.forum__topic__icon__participated { + position: absolute; + bottom: 2px; + right: 2px; + width: 4px; + height: 4px; + background-color: #fff; + border-radius: 100%; + box-shadow: 0 1px 2px #111; + pointer-events: initial; +} +.forum__topic__icon__priority { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + line-height: 30px; + font-size: .9em; + text-align: center; +} + +.forum__topic__details { + margin: 0 4px; + flex: 1 1 auto; + display: flex; + justify-content: center; + flex-direction: column; + line-height: 1.5em; + overflow: hidden; +} + +.forum__topic__title { + font-size: 1.3em; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.forum__topic__info { + font-size: .9em; +} + +.forum__topic__stats, +.forum__topic__activity { + display: flex; + flex: 0 0 auto; +} + +.forum__topic__stats { + text-align: center; + min-width: 80px; + flex-direction: column; +} + +.forum__topic__stat { + font-size: .9em; + line-height: 1.3em; + opacity: .7; + pointer-events: auto; + cursor: default; +} +.forum__topic__stat:first-child { + font-size: 1.4em; + opacity: 1; +} + +.forum__topic__activity { + display: flex; + align-items: center; + text-align: right; + min-width: 200px; + line-height: 1.5em; +} +.forum__topic__activity__details { + display: flex; + flex-direction: column; + align-items: flex-end; + margin: 0 8px; + flex: 1 1 auto; +} +.forum__topic__activity__post { + color: var(--accent-colour); + text-decoration: none; + pointer-events: initial; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + max-width: 120px; +} +.forum__topic__activity__post:hover, +.forum__topic__activity__post:focus { + text-decoration: underline; +} + +.forum__topic__username { + color: var(--user-colour); + text-decoration: none; + pointer-events: initial; +} +.forum__topic__username:hover { + text-decoration: underline; +} + +.forum__topic__avatar { + display: block; + flex: 0 0 auto; + text-decoration: none; + color: inherit; + width: 30px; + height: 30px; + pointer-events: initial; +} + +.forum__topic__pagination { + display: flex; + align-items: center; + font-size: .9em; + line-height: 1.2em; +} +.forum__topic__pagination__separator { + margin: 0 8px; +} +.forum__topic__pagination__item { + color: inherit; + text-decoration: none; + pointer-events: initial; + margin: 0 1px; + padding: 2px 4px; + border-radius: 2px; + min-width: 25px; + height: 25px; + line-height: 20px; + text-align: center; + background-color: rgba(0, 0, 0, .2); + box-shadow: 0 1px 1px #111; + border-radius: 2px; + transition: background-color .2s, box-shadow .2s; +} +.forum__topic__pagination__item:hover, +.forum__topic__pagination__item:focus { + background-color: rgba(0, 0, 0, .4); + box-shadow: 0 1px 4px #111; +} + + +@media (max-width: 800px) { + .forum__topic__container { + flex-wrap: wrap; + } + .forum__topic__details { + max-width: 70%; + } + .forum__topic__stats { + min-width: initial; + border-left-width: 0; + align-self: flex-start; + align-items: flex-end; + flex: 1 1 auto; + } + .forum__topic__stat { + font-size: 1em; + margin: 0 4px; + } + .forum__topic__activity { + min-width: 100%; + } + .forum__topic__activity__details { + margin: 1px 4px 0; + flex-direction: row; + justify-content: space-between; + } + .forum__topic__avatar { + display: none; + } + .forum__topic__pagination__separator { + display: none; + } + .forum__topic__pagination__item { + min-width: 30px; + height: 30px; + line-height: 26px; + font-size: 1.2em; + } +} + +@media (min-width: 800px) { + .forum__topic__pagination { + position: absolute; + right: 0; + } +} \ No newline at end of file diff --git a/assets/css/misuzu/header.css b/assets/css/misuzu/header.css new file mode 100644 index 0000000..c7e810c --- /dev/null +++ b/assets/css/misuzu/header.css @@ -0,0 +1,286 @@ +.header { + --header-image-px: 60px; + --header-link-margin: 14px; + --header-background-mask-image: linear-gradient(180deg, var(--background-colour) 0, transparent 100%); + + flex: 0 0 auto; +} +.header__background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: var(--background-pattern); + background-color: var(--header-accent-colour); + background-blend-mode: multiply; + mask-image: var(--header-background-mask-image); + -webkit-mask-image: var(--header-background-mask-image); /* fuck chrome */ +} + +/** DESKTOP HEADER **/ +.header__desktop { + margin: 0 auto; + display: flex; + align-items: flex-start; + padding: 4px; + max-width: var(--site-max-width); + height: var(--header-height-desktop); +} +.header__desktop__logo { + flex: 0 0 auto; + color: inherit; + text-decoration: none; + cursor: pointer; + display: block; + background: no-repeat center / cover; + background-image: var(--site-logo); + width: var(--header-image-px); + height: var(--header-image-px); + font-size: 0; + transition: width .1s, height .1s; +} + +.header__desktop__link { + color: inherit; + text-decoration: none; + display: block; + min-width: 100px; + cursor: pointer; + border-radius: 2px; + padding: 4px 10px; + transition: background-color .2s; +} +.header__desktop__link:hover, +.header__desktop__link:focus { + background-color: rgba(255, 255, 255, .2); +} +.header__desktop__link:active { + background-color: rgba(255, 255, 255, .1); +} + +.header__desktop__menus { + display: flex; + flex: 0 0 auto; + height: 100%; +} +.header__desktop__menu { + margin: 0 5px; +} +.header__desktop__menu__link { + margin: var(--header-link-margin) 0; + font-size: 1.2em; + padding: 6px 10px; + text-align: center; +} + +.header__desktop__submenu { + position: absolute; + z-index: 100; + overflow: hidden; + max-height: 0; + transition: max-height .2s; + left: -5px; + top: 50px; + box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); +} +.header__desktop__submenu__link { + margin: 5px; +} +.header__desktop__submenu__background { + background: var(--header-accent-colour); + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; +} +.header__desktop__submenu__content { + background: var(--background-colour-translucent-9); + overflow: hidden; +} +.header__desktop__menu:hover .header__desktop__submenu, +.header__desktop__menu:focus .header__desktop__submenu, +.header__desktop__menu:focus-within .header__desktop__submenu, +.header__desktop__menu:active .header__desktop__submenu { + max-height: 200px; +} + +.header__desktop__user { + flex: 0 0 auto; + display: flex; + align-items: center; + margin-left: auto; +} +.header__desktop__user__avatar { + width: var(--header-image-px); + height: var(--header-image-px); + margin-left: 5px; + transition: width .1s, height .1s; + box-shadow: 0 0 4px #111; +} +.header__desktop__user__avatar:hover, +.header__desktop__user__avatar:focus, +.header__desktop__user__avatar:active { + box-shadow: inset 0 0 0 1px var(--user-colour), 0 0 4px #111; +} +.header__desktop__user__button { + margin: 2px; + color: inherit; + text-decoration: none; + font-size: 1.5em; + line-height: 32px; + width: 32px; + height: 32px; + transition: background-color .2s; + border-radius: 4px; + text-align: center; + +} +.header__desktop__user__button:hover, +.header__desktop__user__button:focus { + background-color: rgba(255, 255, 255, .2); +} +.header__desktop__user__button:active { + background-color: rgba(255, 255, 255, .1); +} +.header__desktop__user__button__count { + position: absolute; + bottom: 1px; + right: 1px; + font-size: 10px; + background-color: var(--header-accent-colour); + opacity: .9; + border-radius: 4px; + line-height: 12px; + padding: 2px 4px; +} + +/** MOBILE HEADER **/ +.header__mobile { + --header-icon-px: 40px; + display: block; +} + + +.header__mobile__icons { + display: flex; + justify-content: space-between; + height: var(--header-height-mobile); + padding: 5px; + z-index: 100; + + -webkit-touch-callout: none !important; + -webkit-user-select: none !important; + -khtml-user-select: none !important; + -moz-user-select: none !important; + -ms-user-select: none !important; + user-select: none !important; +} + +.header__mobile__icon { + flex: 0 0 auto; + cursor: pointer; + font-size: 32px; + width: var(--header-icon-px); + height: var(--header-icon-px); + display: flex; + justify-content: center; + align-items: center; + + -webkit-touch-callout: none !important; + -webkit-user-select: none !important; + -khtml-user-select: none !important; + -moz-user-select: none !important; + -ms-user-select: none !important; + user-select: none !important; +} + +.header__mobile__logo { + color: inherit; + text-decoration: none; + background: no-repeat center / cover; + background-image: var(--site-logo); + font-size: 0; +} + +.header__mobile__avatar { + transition: box-shadow .2s; + box-shadow: 0 0 4px #111; +} + +.header__mobile__toggle { + display: none; +} + +.header__mobile__menu { + position: absolute; + top: 0; + left: 0; + right: 0; + z-index: 99; + background: var(--background-pattern); + background-color: var(--header-accent-colour); + background-blend-mode: multiply; + transition: max-height .2s; + box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); + text-shadow: 0 1px 4px #000; + max-height: 0; + overflow: hidden; +} +.header__mobile__menu__spacer { + height: var(--header-height-mobile); +} + +.header__mobile__toggle:checked ~ .header__mobile__menu { + max-height: 600px; +} + +.header__mobile__user { + display: grid; + grid-template-columns: 1fr 1fr; + border-bottom: 1px solid #fff; + padding: 5px 5px 3px; /* extra 2px is provided by the buttons */ +} + +.header__mobile__navigation { + padding: 5px; +} + +.header__mobile__link { + color: inherit; + text-decoration: none; + display: block; + padding: 8px; + padding-left: 20px; + cursor: pointer; + border-radius: 2px; + transition: background-color .2s, margin .1s, opacity .1s; + font-size: 1.2em; +} +.header__mobile__link:not(:last-child) { + margin-bottom: 2px; +} +.header__mobile__link--primary { + font-size: 1.5em; + padding: 10px; +} +.header__mobile__link--user { + margin: 2px; + font-size: 1.5em; + padding: 10px; +} +.header__mobile__link:hover, +.header__mobile__link:focus { + background-color: rgba(255, 255, 255, .2); +} +.header__mobile__link:active { + background-color: rgba(255, 255, 255, .1); +} + +@media (max-width: 800px) { + .header__desktop { display: none; } +} +@media (min-width: 801px) { + .header__mobile { display: none; } +} diff --git a/assets/css/misuzu/home/landingv2-footer.css b/assets/css/misuzu/home/landingv2-footer.css new file mode 100644 index 0000000..f9590fe --- /dev/null +++ b/assets/css/misuzu/home/landingv2-footer.css @@ -0,0 +1,84 @@ +.landingv2-footer { + flex: 0 0 auto; + --footer-background-mask-image: linear-gradient(180deg, transparent, var(--background-colour) 30px); + margin-top: 4px; + padding-top: 20px; +} +.landingv2-footer-background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + mask-image: var(--footer-background-mask-image); + -webkit-mask-image: var(--footer-background-mask-image); + background: var(--background-pattern); + background-color: var(--header-accent-colour); + background-blend-mode: multiply; +} +.landingv2-footer-wrapper { + max-width: var(--site-max-width); + margin: 0 auto; + padding: 1em 4px; + display: grid; + grid-template-columns: repeat(2, 1fr); +} + +.landingv2-footer-navigation {} +.landingv2-footer-navigation a { + display: inline-block; + color: inherit; + text-decoration: none; + min-width: 200px; + cursor: pointer; + border-radius: 2px; + padding: 4px 10px; + margin: 1px 0; + transition: background-color .2s; +} +.landingv2-footer-navigation a:hover, +.landingv2-footer-navigation a:focus { + background-color: rgba(255, 255, 255, .2); +} +.landingv2-footer-navigation a:active { + background-color: rgba(255, 255, 255, .1); +} + +.landingv2-footer-copyright { + text-align: right; + line-height: 1.8em; + font-size: .9em; + align-self: flex-end; +} + +.landingv2-footer-copyright a { + color: inherit; + text-decoration: none; +} +.landingv2-footer-copyright a:focus, +.landingv2-footer-copyright a:hover { + text-decoration: underline; +} + +@media(max-width: 800px) { + .landingv2-footer-wrapper { + grid-template-columns: 1fr; + } + + .landingv2-footer-navigation { + text-align: center; + margin: 0 8px; + } + .landingv2-footer-navigation div { + display: inline-block; + } + .landingv2-footer-navigation a { + text-align: center; + min-width: 100px; + margin: 2px; + } + + .landingv2-footer-copyright { + text-align: center; + } +} diff --git a/assets/css/misuzu/home/landingv2-header.css b/assets/css/misuzu/home/landingv2-header.css new file mode 100644 index 0000000..81fd084 --- /dev/null +++ b/assets/css/misuzu/home/landingv2-header.css @@ -0,0 +1,91 @@ +.landingv2-header { + flex: 0 0 auto; + --header-background-mask-image: linear-gradient(0deg, transparent, var(--background-colour) 100px); + padding-bottom: 100px; +} +.landingv2-header-background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: var(--background-pattern); + background-color: var(--header-accent-colour); + background-blend-mode: multiply; + mask-image: var(--header-background-mask-image); + -webkit-mask-image: var(--header-background-mask-image); +} +.landingv2-header-content { + margin: 0 auto; + max-width: 800px; +} + +.landingv2-welcome { + text-align: center; + margin: 10px; +} +.landingv2-welcome a { + color: inherit; + text-decoration: none; +} +.landingv2-welcome img { + max-width: 100%; + max-height: 100%; + vertical-align: middle; +} + +.landingv2-header-menu { + display: grid; + grid-template-columns: repeat(2, 1fr); + grid-gap: 4px; + padding: 0 4px; +} + +.landingv2-header-menu-link { + color: #fff; + text-decoration: none; + cursor: pointer; + border-radius: 2px; + background-color: var(--background-colour); + border: 1px solid var(--header-accent-colour); + transition: background-color .2s; + display: flex; + align-items: center; + min-height: 70px; + font-size: 1.4em; + padding: 10px 16px; + grid-column: 1; +} +.landingv2-header-menu-link:hover, +.landingv2-header-menu-link:focus { + background-color: var(--accent-colour); +} + +.landingv2-auth-link { + font-size: 2em; + justify-content: center; + text-align: center; + grid-column: 2; +} +.landingv2-auth-link-login { + grid-row: 1 / span 2; +} + +@media(max-width: 700px) { + .landingv2-header-menu { + grid-template-columns: 1fr; + } + + .landingv2-auth-link { + grid-column: 1; + } + + .landingv2-auth-link-login { + grid-row: 1; + min-height: 100px; + } + + .landingv2-auth-link-register { + grid-row: 2; + } +} diff --git a/assets/css/misuzu/home/landingv2.css b/assets/css/misuzu/home/landingv2.css new file mode 100644 index 0000000..19ac07a --- /dev/null +++ b/assets/css/misuzu/home/landingv2.css @@ -0,0 +1,211 @@ +.landingv2-content { + padding: 0 4px; +} + +.landingv2-stats { + display: grid; + grid-template-columns: repeat(3, 1fr); + grid-gap: 40px; + margin: 40px; +} + +.landingv2-stat { + display: flex; + align-items: center; + margin: 10px; + text-shadow: 0 1px 4px #000; +} +.landingv2-stat-icon { + font-size: 4em; +} +.landingv2-stat-value { + font-size: 2em; + text-align: right; + flex: 1 1 auto; +} +.landingv2-stat-value-num { + font-weight: 700; +} + +.landingv2-forum { + display: grid; + grid-template-columns: repeat(2, 1fr); + grid-gap: 2px; + margin: 4px 0; +} + +.landingv2-forum-topics { + background-color: var(--container-colour); + box-shadow: 0 1px 2px #0009; + text-shadow: 0 1px 4px #000; + overflow: hidden; + word-wrap: break-word; +} +.landingv2-forum-topics-list { + display: flex; + flex-direction: column; + margin: 5px; + overflow: hidden; +} + +.landingv2-forum-topic { + border-radius: 2px; + background-color: rgba(17, 17, 17, .6); + transition: background-color .2s, box-shadow .2s, opacity .2s; +} +.landingv2-forum-topic:nth-child(even) { + background-color: rgba(25, 25, 25, .6); +} +.landingv2-forum-topic:hover, +.landingv2-forum-topic:focus { + background-color: rgba(34, 34, 34, .6); + box-shadow: 0 1px 4px #222; +} +.landingv2-forum-topic:not(:last-child) { + margin-bottom: 4px; +} + +.landingv2-forum-topic-link { + display: block; + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + color: inherit; + text-decoration: none; + z-index: 200; +} + +.landingv2-forum-topic-info { + z-index: 100; + display: flex; + padding: 5px; + align-items: center; + min-height: 40px; + pointer-events: none; +} +.landingv2-forum-topic-info-icon { + flex: 0 0 auto; + border-radius: 2px; + width: 30px; + height: 30px; + margin-right: 4px; + background-color: var(--accent-colour); + background-size: 60px 60px; + background-image: radial-gradient(ellipse at center, rgba(255, 255, 255, .2) 0%, rgba(0, 0, 0, .4) 100%); + box-shadow: 0 1px 4px #111; + font-size: 1.5em; + line-height: 1.5em; + color: #fff; + display: flex; + justify-content: center; + align-items: center; + padding: 1px 1px 0 2px; +} + +.landingv2-forum-topic-info-details { + margin: 0 4px; + flex: 1 1 auto; + display: flex; + justify-content: center; + flex-direction: column; + line-height: 1.6em; + overflow: hidden; +} +.landingv2-forum-topic-info-details-title { + font-size: 1.3em; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.landingv2-forum-topic-info-stats { + font-size: .9em; + display: flex; + flex: 0 0 auto; + text-align: center; + min-width: 60px; + flex-direction: column; +} +.landingv2-forum-topic-info-stats-posts, +.landingv2-forum-topic-info-stats-views { + font-size: .9em; + line-height: 1.3em; + opacity: .7; + pointer-events: auto; + cursor: default; +} +.landingv2-forum-topic-info-stats-posts { + font-size: 1.4em; + opacity: 1; +} + +.landingv2-news { + display: grid; + grid-template-columns: repeat(3, 1fr); + grid-gap: 2px; +} + +.landingv2-news-post { + background-color: var(--container-colour); + box-shadow: 0 1px 2px #0009; + text-shadow: 0 1px 4px #000; + overflow: hidden; + word-wrap: break-word; + padding: 0 10px 10px 10px; + display: flex; + flex-direction: column; +} +.landingv2-news-post p { + flex: 1 1 auto; +} +.landingv2-news-post-options { + text-align: right; +} + +.landingv2-online { + background-color: var(--container-colour); + box-shadow: 0 1px 2px #0009; + text-shadow: 0 1px 4px #000; + margin: 4px 0; +} +.landingv2-online-users { + scrollbar-width: thin; + overflow: auto; +} +.landingv2-online-inner { + display: flex; + padding: 2px; +} +.landingv2-online-avatar { + margin: 2px; + display: block; + flex: 0 0 auto; +} + +@media(max-width: 1100px) { + .landingv2-stat { + margin: 0; + } +} + +@media(max-width: 1024px) { + .landingv2-stats { + grid-template-columns: repeat(2, 1fr); + margin: 20px; + } +} + +@media(max-width: 900px) { + .landingv2-forum, + .landingv2-news { + grid-template-columns: 1fr; + } +} + +@media(max-width: 700px) { + .landingv2-stats { + grid-template-columns: 1fr; + } +} diff --git a/assets/css/misuzu/landing.css b/assets/css/misuzu/landing.css new file mode 100644 index 0000000..49db2b9 --- /dev/null +++ b/assets/css/misuzu/landing.css @@ -0,0 +1,111 @@ +.landing { + display: flex; + flex-direction: row; +} +.landing__container { + margin: 2px 0; +} + +.landing__sidebar { + width: 300px; + margin-right: 2px; + flex: 0 0 auto; +} +.landing__main { + flex: 1 1 auto; +} + +.landing__stats__emphasis { + font-weight: 700; +} +.landing__stats__link { + color: var(--user-colour); + text-decoration: none; +} +.landing__stats__link:hover { + text-decoration: underline; +} + +.landing__online { + display: flex; + flex-wrap: wrap; + overflow: hidden; + margin: 6px; +} +.landing__online__user { + color: var(--user-colour); + text-decoration: none; + font-size: 0; + width: 30px; + height: 30px; + margin: 2px; + transition: box-shadow .2s; +} +.landing__online__user:hover { + box-shadow: 0 0 2px var(--user-colour); +} + +.landing__statistics { + display: flex; + flex-wrap: wrap; + justify-content: center; +} +.landing__statistic { + display: flex; + flex-direction: column; + align-items: center; + width: 45%; + padding: 4px 0; +} +.landing__statistic__name { + font-size: 1.3em; + line-height: 2em; +} +.landing__statistic__value { + font-size: 1.5em; + line-height: 1.5em; +} + +.landing__latest { + display: flex; + padding: 4px; + margin: 4px; + color: inherit; + text-decoration: none; + border-radius: 2px; + transition: background-color .2s, box-shadow .2s; +} +.landing__latest:focus, +.landing__latest:hover { + background-color: rgba(34, 34, 34, .6); + box-shadow: 0 1px 4px #222; +} +.landing__latest__avatar { + width: 50px; + height: 50px; +} +.landing__latest__content { + display: flex; + flex-direction: column; + justify-content: center; + padding-left: 8px; +} +.landing__latest__username { + font-size: 1.5em; + line-height: 1.4em; + color: var(--user-colour); +} +.landing__latest__joined { + font-size: .9em; + line-height: 1.2em; +} + +@media (max-width: 800px) { + .landing { + flex-direction: column; + } + .landing__sidebar { + width: 100%; + margin-right: 0; + } +} diff --git a/assets/css/misuzu/manage/_manage.css b/assets/css/misuzu/manage/_manage.css new file mode 100644 index 0000000..f97f464 --- /dev/null +++ b/assets/css/misuzu/manage/_manage.css @@ -0,0 +1,25 @@ +.manage { + display: flex; +} +.manage__sidebar { + flex: 0 0 auto; + width: 280px; +} +.manage__content { + flex: 1 1 auto; +} +.manage__description { + font-size: .9em; + margin: 1px 2px; + border-bottom: 1px solid var(--accent-colour); + padding: 2px 5px; +} + +@media (max-width: 800px) { + .manage { + flex-direction: column; + } + .manage__sidebar { + width: 100%; + } +} diff --git a/assets/css/misuzu/manage/blacklist.css b/assets/css/misuzu/manage/blacklist.css new file mode 100644 index 0000000..de5b0e4 --- /dev/null +++ b/assets/css/misuzu/manage/blacklist.css @@ -0,0 +1,28 @@ +.manage__blacklist { + display: flex; + justify-content: space-evenly; +} +.manage__blacklist__form { + margin: 2px; + display: flex; + flex-direction: column; + width: 100%; + height: 100%; +} +.manage__blacklist__select, +.manage__blacklist__textarea { + margin: 0; + padding: 5px 10px; + font-family: monospace; + width: 100%; + min-width: 100%; + max-width: 100%; + min-height: 400px; +} +.manage__blacklist__button { margin-top: 1px; } + +@media (max-width: 800px) { + .manage__blacklist { + flex-direction: column; + } +} diff --git a/assets/css/misuzu/manage/changelog-actions-tags.css b/assets/css/misuzu/manage/changelog-actions-tags.css new file mode 100644 index 0000000..6d9a7ef --- /dev/null +++ b/assets/css/misuzu/manage/changelog-actions-tags.css @@ -0,0 +1,39 @@ +.changelog-actions-tags { + display: flex; +} + +.changelog-actions-tags__panel--actions { + flex: 0 0 auto; +} +.changelog-actions-tags__panel--tags { + flex: 1 1 auto; +} + +.changelog-actions-tags__list { + display: flex; + flex-wrap: wrap; + justify-content: center; +} + +.changelog-actions-tags__entry { + color: var(--user-colour); + text-decoration: none; + width: 200px; + border: 1px solid var(--accent-colour); + border-radius: 2px; + margin: 2px; + padding: 0 2px; +} +.changelog-actions-tags__entry:hover { + text-decoration: underline; +} + +@media (max-width: 800px) { + .changelog-actions-tags { + flex-direction: column; + } + .changelog-actions-tags__panel--actions { + margin-left: 2px; + width: 210px; + } +} \ No newline at end of file diff --git a/assets/css/misuzu/manage/emote.css b/assets/css/misuzu/manage/emote.css new file mode 100644 index 0000000..485291b --- /dev/null +++ b/assets/css/misuzu/manage/emote.css @@ -0,0 +1,17 @@ +.manage__emote__field { + display: flex; + margin: 2px; + align-items: center; +} +.manage__emote__field__name { + min-width: 100px; + padding: 5px; +} +.manage__emote__field__value { + flex: 1 1 auto; +} + +.manage__emote__actions { + text-align: center; + margin: 5px; +} diff --git a/assets/css/misuzu/manage/emotes.css b/assets/css/misuzu/manage/emotes.css new file mode 100644 index 0000000..c4f9b7f --- /dev/null +++ b/assets/css/misuzu/manage/emotes.css @@ -0,0 +1,50 @@ +.manage__emotes__actions { + margin: 2px; +} + +.manage__emotes__emoticon { + max-width: 100px; + max-height: 100px; +} + +.manage__emotes__list { + width: 100%; +} + +.manage__emotes__entry { + display: flex; + justify-content: center; + align-items: center; + margin: 2px; + text-align: center; +} + +.manage__emotes__entry--header { + border-bottom: 1px solid var(--accent-colour); + padding-bottom: 2px; +} + +.manage__emotes__entry__id, +.manage__emotes__entry__order, +.manage__emotes__entry__hierarchy { + min-width: 40px; +} + +.manage__emotes__entry__string { + min-width: 150px; +} + +.manage__emotes__entry__image { + flex: 1 1 auto; +} + +.manage__emotes__entry__actions { + min-width: 170px; + display: flex; + justify-content: center; +} +.manage__emotes__entry__actions .input__button { + margin: 1px; + padding: 6px; +} + diff --git a/assets/css/misuzu/manage/navigation.css b/assets/css/misuzu/manage/navigation.css new file mode 100644 index 0000000..fc43de4 --- /dev/null +++ b/assets/css/misuzu/manage/navigation.css @@ -0,0 +1,17 @@ +.manage__navigation { + margin: 0 2px 2px; +} +.manage__navigation__links { + display: flex; + flex-direction: column; + font-size: 1.2em; +} +.manage__navigation__link { + color: inherit; + text-decoration: none; + padding: 2px 5px; + margin-bottom: 2px; +} +.manage__navigation__link:hover { + text-decoration: underline; +} diff --git a/assets/css/misuzu/manage/role-item.css b/assets/css/misuzu/manage/role-item.css new file mode 100644 index 0000000..d91d460 --- /dev/null +++ b/assets/css/misuzu/manage/role-item.css @@ -0,0 +1,125 @@ +.manage__role-item { + display: flex; + text-shadow: 0 1px 4px #000; + box-shadow: 0 1px 4px #000A; + margin-bottom: 4px; +} +.manage__role-item:last-child { + margin-bottom: 0; +} +.manage__role-item__background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background-color: var(--accent-colour); +} + +.manage__role-item__container { + display: flex; + flex-wrap: wrap; + align-items: center; + background-color: var(--background-colour-translucent-9); + width: 100%; + height: 100%; + margin-left: 5px; + pointer-events: none; + transition: background-color .2s; +} +.manage__role-item:hover .manage__role-item__container, +.manage__role-item:focus .manage__role-item__container, +.manage__role-item:focus-within .manage__role-item__container { + background-color: var(--background-colour-translucent-8); +} + +.manage__role-item__icon { + border-radius: 100%; + width: 40px; + height: 40px; + box-shadow: 0 1px 4px #111; + margin: 10px; + flex: 0 0 auto; + overflow: hidden; +} +.manage__role-item__icon__content { + background-color: var(--background-colour-translucent-6); + display: inline-flex; + align-items: center; + justify-content: center; + width: 100%; + height: 100%; + font-size: 1.5em; + transition: background-color .2s; +} +.manage__role-item__icon__background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background-color: var(--accent-colour); +} + +.manage__role-item:hover .manage__role-item__icon__content, +.manage__role-item:focus .manage__role-item__icon__content, +.manage__role-item:focus-within .manage__role-item__icon__content { + background-color: var(--background-colour-translucent-4); +} + +.manage__role-item__info { + display: inline-flex; + flex-direction: column; + flex: 1 1 auto; +} + +.manage__role-item__name { + font-size: 1.4em; + line-height: 1.4em; +} + +.manage__role-item__details { + font-size: .9em; + line-height: 1.3em; + display: inline-flex; + align-items: center; + padding: 1px 0; +} + +.manage__role-item__users { + border-radius: 10px; + background-color: var(--accent-colour); + box-shadow: 0 1px 4px #111; + padding: 2px 5px; +} + +.manage__role-item__title { + padding: 2px 5px; +} + +.manage__role-item__actions { + display: flex; + flex: 0 0 auto; + margin: 10px; +} +.manage__role-item__action { + width: 32px; + height: 32px; + line-height: 32px; + font-size: 1.5em; + border-radius: 2px; + margin: 5px; + margin-right: 0; + color: #fff; + cursor: pointer; + pointer-events: initial; + transition: background-color .2s; + text-align: center; +} +.manage__role-item__action:hover, +.manage__role-item__action:focus { + background-color: rgba(255, 255, 255, .2); +} +.manage__role-item__action:active { + background-color: rgba(255, 255, 255, .1); +} diff --git a/assets/css/misuzu/manage/roles.css b/assets/css/misuzu/manage/roles.css new file mode 100644 index 0000000..a975d88 --- /dev/null +++ b/assets/css/misuzu/manage/roles.css @@ -0,0 +1,4 @@ +.manage__roles__collection, +.manage__roles__pagination { + padding: 5px; +} diff --git a/assets/css/misuzu/manage/settings.css b/assets/css/misuzu/manage/settings.css new file mode 100644 index 0000000..4a0a4e8 --- /dev/null +++ b/assets/css/misuzu/manage/settings.css @@ -0,0 +1,121 @@ +.manage-settings-actions { + margin: 2px; +} + +.manage-settings-list-container { + margin: 5px 2px; +} + +.manage-settings-list { + width: 100%; + border-spacing: 0; +} + +.manage-settings-list-header th { + border-bottom: 1px solid var(--accent-colour); +} +.manage-settings-list-header-options { + width: 80px; +} + +.manage-list-setting:nth-child(even) { + background-color: #fff1; +} + +.manage-list-setting-key { + padding: 5px; +} +.manage-list-setting-key-text { + font-family: var(--font-monospace); +} + +.manage-list-setting-type { + text-align: center; + width: 100px; +} +.manage-list-setting-type--string { + --type-colour: #ef8323; +} +.manage-list-setting-type--integer { + --type-colour: #8c90bc; +} +.manage-list-setting-type--boolean { + --type-colour: #77b34c; +} +.manage-list-setting-type--array { + --type-colour: #f02d7d; +} +.manage-list-setting-type-text { + background: var(--type-colour); + border-radius: 5px; + text-shadow: initial; + font-weight: 700; + padding: 0 5px; + font-size: .9em; + display: inline-block; +} + +.manage-list-setting-value { + padding: 5px; + max-width: 570px; +} +.manage-list-setting-value-text { + font-family: var(--font-monospace); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.manage-list-setting-options { + display: flex; + width: 80px; + justify-content: center; + padding: 5px; +} +.manage-list-setting-options .input__button { + margin: 1px; + padding: 6px; +} + +.manage-setting-field { + display: flex; + margin: 2px; + align-items: center; +} +.manage-setting-field-name { + min-width: 100px; + padding: 5px; +} +.manage-setting-field-value { + flex: 1 1 auto; +} + +.manage-setting-actions { + text-align: center; + margin: 5px; +} + +.manage-setting-array { + width: 100%; +} +.manage-setting-array-select select { + width: 100%; + min-height: 300px; +} +.manage-setting-array-remove { + margin: 2px 0; +} +.manage-setting-array-remove button { + width: 100%; +} +.manage-setting-array-add { + display: flex; + margin: 5px 0; +} +.manage-setting-array-add input { + flex: 1 1 auto; +} +.manage-setting-array-add button { + flex: 0 0 auto; + margin-left: 2px; +} diff --git a/assets/css/misuzu/manage/statistic.css b/assets/css/misuzu/manage/statistic.css new file mode 100644 index 0000000..2825a21 --- /dev/null +++ b/assets/css/misuzu/manage/statistic.css @@ -0,0 +1,14 @@ +.manage__statistic { + border: 1px solid var(--accent-colour); + border-radius: 2px; + padding: 2px 5px; +} +.manage__statistic__name { + font-size: 1.1em; + line-height: 1.5em; +} +.manage__statistic__value { + text-align: right; + font-size: 1.5em; + line-height: 2em; +} diff --git a/assets/css/misuzu/manage/statistics.css b/assets/css/misuzu/manage/statistics.css new file mode 100644 index 0000000..1fe2777 --- /dev/null +++ b/assets/css/misuzu/manage/statistics.css @@ -0,0 +1,16 @@ +.manage__statistics { + display: grid; + grid-template-columns: 1fr 1fr 1fr; + padding: 5px; + grid-gap: 5px; +} +@media (max-width: 900px) { + .manage__statistics { + grid-template-columns: 1fr 1fr; + } +} +@media (max-width: 500px) { + .manage__statistics { + grid-template-columns: 1fr; + } +} diff --git a/assets/css/misuzu/manage/tag.css b/assets/css/misuzu/manage/tag.css new file mode 100644 index 0000000..ffb521d --- /dev/null +++ b/assets/css/misuzu/manage/tag.css @@ -0,0 +1,33 @@ +.manage__tag { + border-radius: 2px; + border: 1px solid var(--accent-colour); + background-color: var(--accent-colour); + display: inline-block; +} +.manage__tag__background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background-color: var(--background-colour-translucent-9); + transition: background-color .2s; +} +.manage__tag:hover .manage__tag__background, +.manage__tag:focus .manage__tag__background, +.manage__tag:focus-within .manage__tag__background { + background-color: var(--background-colour-translucent-8); +} +.manage__tag__content { + margin: 4px; + display: flex; +} +.manage__tag__checkbox { + vertical-align: middle; + margin: 0; + flex: 0 0 auto; +} +.manage__tag__title { + flex: 1 1 auto; + margin: 0 4px; +} diff --git a/assets/css/misuzu/manage/tags.css b/assets/css/misuzu/manage/tags.css new file mode 100644 index 0000000..e8a1d58 --- /dev/null +++ b/assets/css/misuzu/manage/tags.css @@ -0,0 +1,18 @@ +.manage__tags--fixed { + display: grid; + grid-template-columns: 1fr 1fr 1fr; + grid-auto-flow: row dense; + grid-gap: 4px; +} + +@media(max-width: 1000px) { + .manage__tags--fixed { + grid-template-columns: 1fr 1fr; + } +} +@media(max-width: 500px) { + .manage__tags--fixed { + grid-template-columns: 1fr; + } +} + diff --git a/assets/css/misuzu/manage/user-item.css b/assets/css/misuzu/manage/user-item.css new file mode 100644 index 0000000..b1e2919 --- /dev/null +++ b/assets/css/misuzu/manage/user-item.css @@ -0,0 +1,108 @@ +.manage__user-item { + display: flex; + text-shadow: 0 1px 4px #000; + box-shadow: 0 1px 4px #000A; + margin-bottom: 4px; +} +.manage__user-item:last-child { + margin-bottom: 0; +} +.manage__user-item--deleted { + opacity: .5; + transition: opacity .2s; +} +.manage__user-item--deleted:hover, +.manage__user-item--deleted:focus, +.manage__user-item--deleted:focus-within { + opacity: .8; +} + +.manage__user-item__background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background-color: var(--accent-colour); +} + +.manage__user-item__container { + display: flex; + flex-wrap: wrap; + align-items: center; + background-color: var(--background-colour-translucent-9); + width: 100%; + height: 100%; + margin-left: 5px; + pointer-events: none; + transition: background-color .2s; +} +.manage__user-item:hover .manage__user-item__container, +.manage__user-item:focus .manage__user-item__container, +.manage__user-item:focus-within .manage__user-item__container { + background-color: var(--background-colour-translucent-8); +} + +.manage__user-item__avatar { + width: 40px; + height: 40px; + margin: 10px; + flex: 0 0 auto; + overflow: hidden; +} + +.manage__user-item__info { + display: inline-flex; + flex-direction: column; + flex: 1 1 auto; +} + +.manage__user-item__name { + font-size: 1.4em; + line-height: 1.4em; +} + +.manage__user-item__details { + font-size: .9em; + line-height: 1.3em; + display: inline-flex; + align-items: center; +} + +.manage__user-item__detail { + border-radius: 10px; + background-color: var(--accent-colour); + box-shadow: 0 1px 4px #111; + padding: 3px 8px; + pointer-events: initial; + margin: 2px; +} + +.manage__user-item__actions { + display: flex; + flex: 0 0 auto; + margin: 10px; +} + +.manage__user-item__action { + width: 32px; + height: 32px; + line-height: 32px; + font-size: 1.5em; + border-radius: 2px; + margin: 5px; + margin-right: 0; + color: #fff; + cursor: pointer; + pointer-events: initial; + transition: background-color .2s; + text-align: center; +} +.manage__user-item__action:hover, +.manage__user-item__action:focus { + background-color: rgba(255, 255, 255, .2); +} + +.manage__user-item__action:active { + background-color: rgba(255, 255, 255, .1); +} diff --git a/assets/css/misuzu/manage/user.css b/assets/css/misuzu/manage/user.css new file mode 100644 index 0000000..0782655 --- /dev/null +++ b/assets/css/misuzu/manage/user.css @@ -0,0 +1,17 @@ +.manage__user__container { + margin-bottom: 2px; +} +.manage__user__buttons { + display: flex; + justify-content: center; + align-items: center; +} +.manage__user__button { + margin: 5px 2px; +} +.manage__user__details { + margin: 5px; +} +.manage__user__input { + width: 100%; +} diff --git a/assets/css/misuzu/manage/users.css b/assets/css/misuzu/manage/users.css new file mode 100644 index 0000000..c4a8d2b --- /dev/null +++ b/assets/css/misuzu/manage/users.css @@ -0,0 +1,4 @@ +.manage__users__collection, +.manage__users__pagination { + padding: 5px; +} diff --git a/assets/css/misuzu/markdown.css b/assets/css/misuzu/markdown.css new file mode 100644 index 0000000..a6fdd1e --- /dev/null +++ b/assets/css/misuzu/markdown.css @@ -0,0 +1,185 @@ +.markdown { + line-height: 1.7em; +} + +.markdown a { + color: var(--accent-colour); + text-decoration: none; +} +.markdown a:hover { text-decoration: underline; } +.markdown a:not([href]) { + color: inherit; + text-decoration: none; +} + +.markdown p, .markdown blockquote, +.markdown ul, .markdown ol, +.markdown dl, .markdown table, +.markdown pre { + margin-top: 0; + margin-bottom: var(--font-size); +} + +.markdown hr { + height: 2px; + padding: 0; + margin: var(--font-size) 0; + background-color: var(--accent-colour); + border: 0; +} + +.markdown blockquote { + padding: 0 1em; + color: var(--accent-colour); + border-left: 0.25em solid var(--accent-colour); +} +.markdown blockquote > :first-child { margin-top: 0; } +.markdown blockquote > :last-child { margin-bottom: 0; } + +.markdown kbd { + display: inline-block; + padding: 3px 5px; + font-size: 11px; + line-height: 10px; + color: #777; + vertical-align: middle; + background-color: #000; + border: solid 1px darken(#333, 4%); + border-bottom-color: #444; + border-radius: 3px; + box-shadow: inset 0 -1px 0 #444; +} + +.markdown code { + padding: .2em .4em; + margin: 0; + background-color: rgba(0, 0, 0, .7); + border-radius: 2px; +} +.markdown del code { text-decoration: inherit; } + +.markdown pre code { + display: inline; + padding: 0; + margin: 0; + overflow: hidden; + line-height: inherit; + word-wrap: break-word; + background: transparent; + border: 0; +} + +.markdown pre { + word-wrap: normal; +} +.markdown pre > code { + word-break: normal; + white-space: pre; +} + +.markdown h1, .markdown h2, +.markdown h3, .markdown h4, +.markdown h5, .markdown h6 { + margin-top: calc(var(--font-size) * 1.2); + margin-bottom: var(--font-size); + font-weight: 700; + line-height: 1em; +} + +.markdown h1 tt, .markdown h2 tt, +.markdown h3 tt, .markdown h4 tt, +.markdown h5 tt, .markdown h6 tt, +.markdown h1 code, .markdown h2 code, +.markdown h3 code, .markdown h4 code, +.markdown h5 code, .markdown h6 code { + font-size: inherit; +} + +.markdown h1 { + padding-bottom: 0.3em; + font-size: 2em; + border-bottom: 1px solid var(--accent-colour); +} +.markdown h2 { + padding-bottom: 0.3em; + font-size: 1.5em; + border-bottom: 1px solid var(--accent-colour); +} +.markdown h3 { + font-size: 1.25em; +} +.markdown h4 { + font-size: 1em; +} +.markdown h5 { + font-size: 0.875em; +} +.markdown h6 { + font-size: 0.85em; + color: var(--accent-colour); +} + +.markdown img { + box-sizing: content-box; + max-width: 100%; + max-height: 100%; +} +.markdown img[align=right] { padding-left: 20px; } +.markdown img[align=left] { padding-right: 20px; } + +.markdown ul, .markdown ol { + padding-left: 2em; +} +.markdown ul ul, +.markdown ul ol, +.markdown ol ol, +.markdown ol ul { + margin-top: 0; + margin-bottom: 0; +} + +.markdown li { word-wrap: break-all; } +.markdown li > p { margin-top: var(--font-size); } +.markdown li + li { margin-top: .25em; } + +.markdown dl { + padding: 0; +} + +.markdown dl dt { + padding: 0; + margin-top: var(--font-size); + font-size: 1em; + font-style: italic; + font-weight: 700; +} + +.markdown dl dd { + padding: 0 var(--font-size); + margin-bottom: var(--font-size); +} + +.markdown table { + display: block; + width: 100%; + overflow: auto; +} +.markdown table th { + font-weight: 700; +} +.markdown table th, +.markdown table td { + padding: 6px 13px; + border: 1px solid var(--accent-colour); +} +.markdown table tr { + background-color: var(--background-colour); + border-top: 1px solid var(--accent-colour); +} +.markdown table tr:nth-child(2n) { + background-image: linear-gradient(0deg, var(--background-colour-translucent-9), var(--background-colour-translucent-9)); + background-color: var(--accent-colour); +} +.markdown table img { + background-color: transparent; +} diff --git a/assets/css/misuzu/messagebox.css b/assets/css/misuzu/messagebox.css new file mode 100644 index 0000000..46dcd24 --- /dev/null +++ b/assets/css/misuzu/messagebox.css @@ -0,0 +1,20 @@ +.messagebox { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + display: flex; + justify-content: center; + align-items: center; + background-color: var(--background-colour-translucent-8); + z-index: 9000; +} +.messagebox__container { + min-width: 300px; +} +.messagebox__buttons { + display: flex; + justify-content: center; + padding: 5px; +} diff --git a/assets/css/misuzu/navigation.css b/assets/css/misuzu/navigation.css new file mode 100644 index 0000000..2dcaf7c --- /dev/null +++ b/assets/css/misuzu/navigation.css @@ -0,0 +1,85 @@ +.navigation { + margin: 2px 0; + width: 100%; + display: flex; + border-width: 0; + border-color: var(--text-colour); + border-style: solid; + border-top-width: 1px; + align-items: flex-start; + justify-content: center; +} + +.navigation--top { + border-top-width: 0; + border-bottom-width: 1px; + align-items: flex-end; +} +.navigation--top .navigation__option { + border-top-width: 1px; + border-bottom-width: 0; +} + +.navigation__option { + list-style: none; + background-color: #c9bbcc; + border: 1px solid var(--text-colour); + border-top-width: 0; + flex-grow: 0; +} +.navigation__option:not(:first-child) { border-left-width: 0; } +.navigation__option--selected { + background-color: var(--accent-colour); + top: -1px; +} +.navigation__option--selected:not(:first-child) { + margin-left: -1px; + border-left-width: 1px; +} + +.navigation__link { + display: block; + padding: 2px 1em; + color: var(--text-colour); + text-decoration: none; +} +.navigation__link:hover, .navigation__link:focus { color: #609; } + + +@media (max-width: 1000px) { + .navigation { + border: none; + align-items: center; + flex-direction: column; + } + .navigation--left { + justify-content: left; + padding-left: 25px; + } + .navigation--right { + justify-content: right; + padding-right: 25px; + } + + .navigation--top .navigation__option--selected { top: 1px; } + + .navigation__link { + padding: 10px 15px; + font-size: 1.5em; + } + + .navigation__option { + background-color: var(--accent-colour); + width: 100%; + border: none; + flex-grow: 1; + margin-bottom: 1px; + } + .navigation__option--selected { + background-color: #a586c3; + top: 0; + } + .navigation__option--selected .navigation__link { + padding: 3px 1em; + } +} diff --git a/assets/css/misuzu/news/container.css b/assets/css/misuzu/news/container.css new file mode 100644 index 0000000..8601bcb --- /dev/null +++ b/assets/css/misuzu/news/container.css @@ -0,0 +1,8 @@ +.news__container { + display: flex; +} +@media (max-width: 800px) { + .news__container { + flex-direction: column; + } +} diff --git a/assets/css/misuzu/news/feeds.css b/assets/css/misuzu/news/feeds.css new file mode 100644 index 0000000..bf0cda2 --- /dev/null +++ b/assets/css/misuzu/news/feeds.css @@ -0,0 +1,29 @@ +.news__feeds { + display: grid; + grid-template-columns: 1fr 1fr; + grid-gap: 2px; + padding: 2px; +} + +.news__feed { + display: flex; + color: inherit; + text-decoration: none; + font-size: 1.5em; + line-height: 32px; + height: 32px; + transition: background-color .2s; + border-radius: 4px; +} +.news__feed:hover, +.news__feed:focus { + background-color: rgba(255, 255, 255, .2); +} +.news__feed:active { + background-color: rgba(255, 255, 255, .1); +} +.news__feed__icon { + width: 32px; + height: 32px; + text-align: center; +} diff --git a/assets/css/misuzu/news/list.css b/assets/css/misuzu/news/list.css new file mode 100644 index 0000000..c377ac9 --- /dev/null +++ b/assets/css/misuzu/news/list.css @@ -0,0 +1,24 @@ +.news__list { + margin: 2px 0; +} + +.news__list__item { + text-decoration: none; + color: inherit; + display: block; +} +.news__list__item:hover { + text-decoration: underline; +} +.news__list__item--kvp { + display: flex; +} + +.news__list__name { + flex-shrink: 1; + flex-grow: 1; +} +.news__list__value { + flex-shrink: 0; + flex-grow: 0; +} diff --git a/assets/css/misuzu/news/post.css b/assets/css/misuzu/news/post.css new file mode 100644 index 0000000..1a11135 --- /dev/null +++ b/assets/css/misuzu/news/post.css @@ -0,0 +1,104 @@ +.news__post { + display: flex; + margin-bottom: 2px; + flex-direction: row-reverse; +} +.news__post__info__content { + width: 200px; + text-align: center; + display: flex; + flex-direction: column; + padding: 15px; + flex: 0 0 auto; + margin-right: 4px; +} +.news__post__info__background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + mask-image: linear-gradient(90deg, transparent 10%, var(--background-colour) 100%); + -webkit-mask-image: linear-gradient(90deg, transparent 10%, var(--background-colour) 100%); + background: var(--background-pattern); + background-color: var(--accent-colour); + background-blend-mode: multiply; +} + +.news__post__user { + display: flex; + text-align: left; + align-items: center; + margin-bottom: 10px; +} +.news__post__user__details { + display: flex; + flex-direction: column; +} + +.news__post__avatar { + width: 60px; + height: 60px; + margin-right: 10px; +} + +.news__post__username { + color: inherit; + font-size: 1.4em; + line-height: 1.5em; + text-decoration: none; +} +.news__post__username[href]:hover { + text-decoration: underline; +} + +.news__post__date { + font-size: 1.1em; + line-height: 1.5em; +} + +.news__post__category { + color: inherit; + text-decoration: none; + font-size: 1.1em; + line-height: 1.5em; + margin: 6px 0; +} +.news__post__category:hover { + text-decoration: underline; +} + +.news__post__text { + line-height: 1.2em; + flex: 1 1 auto; + word-wrap: break-word; + overflow: hidden; + margin: 2px; + padding: 0 10px; +} + +@media (max-width: 800px) { + .news__post { flex-direction: column-reverse; } + .news__post__info { + flex-direction: row; + margin: 0; + padding: 5px; + } + .news__post__info__content { + width: 100%; + flex-wrap: wrap; + text-align: left; + } + .news__post__info__background { + mask-image: linear-gradient(180deg, transparent 10%, var(--background-colour) 100%); + -webkit-mask-image: linear-gradient(180deg, transparent 10%, var(--background-colour) 100%); + } + .news__post__user { + margin-bottom: 0; + margin-right: 10px; + } + .news__post__avatar { + width: 50px; + height: 50px; + } +} \ No newline at end of file diff --git a/assets/css/misuzu/news/preview.css b/assets/css/misuzu/news/preview.css new file mode 100644 index 0000000..41c2a68 --- /dev/null +++ b/assets/css/misuzu/news/preview.css @@ -0,0 +1,129 @@ +.news__preview { + display: flex; + margin: 2px 0; + flex-direction: row-reverse; + + --user-colour: var(--accent-colour); +} +.news__preview__info__content { + width: 200px; + text-align: center; + display: flex; + flex-direction: column; + padding: 15px; + flex: 0 0 auto; + margin-right: 4px; +} + +.news__preview__info__background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + mask-image: linear-gradient(90deg, transparent 10%, var(--background-colour) 100%); + -webkit-mask-image: linear-gradient(90deg, transparent 10%, var(--background-colour) 100%); + background: var(--background-pattern); + background-color: var(--user-colour); + background-blend-mode: multiply; +} + +.news__preview__listing { + flex-grow: 1; + flex-shrink: 1; +} + +.news__preview__container { + display: flex; + margin: 1px; + flex-direction: column; +} + +.news__preview__user { + display: flex; + text-align: left; + align-items: center; + margin-bottom: 10px; +} +.news__preview__user__details { + display: flex; + flex-direction: column; +} + +.news__preview__avatar { + width: 60px; + height: 60px; + margin-right: 10px; +} + +.news__preview__username { + color: inherit; + font-size: 1.4em; + line-height: 1.5em; + text-decoration: none; +} +.news__preview__username[href]:hover { + text-decoration: underline; +} + +.news__preview__date { + font-size: 1.1em; + line-height: 1.5em; +} + +.news__preview__category { + color: inherit; + text-decoration: none; + font-size: 1.1em; + line-height: 1.5em; + margin: 6px 0; +} +.news__preview__category:hover { + text-decoration: underline; +} + +.news__preview__content { + display: flex; + flex-direction: column; + line-height: 1.2em; + flex: 1 1 auto; + word-wrap: break-word; + overflow: hidden; + margin: 2px; + padding: 0 10px 10px 10px; +} + +.news__preview__text { + flex: 1 1 auto; +} + +.news__preview__links { + display: flex; + justify-content: space-between; +} + +.news__preview__link { + font-size: .9em; +} + +@media (max-width: 800px) { + .news__preview { flex-direction: column-reverse; } + .news__preview__info { display: none; } + .news__preview__info__content { + width: 100%; + flex-wrap: wrap; + text-align: left; + } + .news__preview__info__background { + mask-image: linear-gradient(180deg, transparent 10%, var(--background-colour) 100%); + -webkit-mask-image: linear-gradient(180deg, transparent 10%, var(--background-colour) 100%); + } + .news__preview__user { + margin-bottom: 0; + margin-right: 10px; + } + .news__preview__avatar { + width: 50px; + height: 50px; + } +} \ No newline at end of file diff --git a/assets/css/misuzu/news/sidebar.css b/assets/css/misuzu/news/sidebar.css new file mode 100644 index 0000000..8ddb432 --- /dev/null +++ b/assets/css/misuzu/news/sidebar.css @@ -0,0 +1,14 @@ +.news__sidebar { + width: 300px; + flex-grow: 0; + flex-shrink: 0; + margin-left: 2px; +} + +@media (max-width: 800px) { + .news__sidebar { + margin: 0; + width: 100%; + margin-top: 2px; + } +} diff --git a/assets/css/misuzu/pagination.css b/assets/css/misuzu/pagination.css new file mode 100644 index 0000000..87aca5b --- /dev/null +++ b/assets/css/misuzu/pagination.css @@ -0,0 +1,57 @@ +.pagination { + display: flex; + justify-content: space-between; + align-items: stretch; + width: 100%; +} + +.pagination__section { + display: flex; + align-items: stretch; + overflow: auto; + flex: 0 0 auto; + scrollbar-width: thin; + scrollbar-color: var(--accent-colour) var(--background-colour); +} +.pagination__section--pages { + flex-shrink: 1; +} +.pagination__section:not(:last-child) { + margin-right: 1px; +} + +.pagination__link { + display: flex; + min-width: 40px; + font-size: 1.2em; + line-height: 1.5em; + padding: 3px 10px 4px; + text-align: center; + text-decoration: none; + background-color: var(--background-colour); + color: var(--accent-colour); + border: 1px solid var(--accent-colour); + border-radius: 2px; + transition: background-color .2s, color .2s; + text-align: center; + align-items: center; + justify-content: center; + flex: 1 0 auto; +} +.pagination__link:not(:last-child) { margin-right: 1px; } +.pagination__link--disabled { --accent-colour: #555; } +.pagination__link--first, .pagination__link--last, +.pagination__link--next, .pagination__link--prev { + padding-top: 5px; +} +.pagination__link--current, +.pagination__link:not(.pagination__link--disabled):hover, +.pagination__link:not(.pagination__link--disabled):active, +.pagination__link:not(.pagination__link--disabled):focus { + background-color: var(--accent-colour); + color: var(--background-colour); +} + +@media (max-width: 800px) { + .pagination__section--pages { display: none; } +} diff --git a/assets/css/misuzu/permissions.css b/assets/css/misuzu/permissions.css new file mode 100644 index 0000000..3705f76 --- /dev/null +++ b/assets/css/misuzu/permissions.css @@ -0,0 +1,61 @@ +.permissions { + display: flex; + flex-direction: column; + margin-bottom: 4px; +} + +.permissions__line { + display: flex; + font-size: .9em; + line-height: 1.7em; +} +.permissions__line--header { + font-size: 1.2em; + line-height: 1.4em; + border-bottom: 1px solid rgba(255, 255, 255, .1); + padding-bottom: 1px; + font-weight: 700; +} +.permissions__line--header:not(:first-child) { margin-top: 4px; } + +.permissions__title { + flex: 1 1 auto; + padding: 4px; +} +.permissions__line:not(.permissions__line--header) .permissions__title { + border-bottom: 1px solid rgba(255, 255, 255, .1); +} + +.permissions__choice { + width: 100px; + text-align: center; + padding: 4px; +} +.permissions__choice--radio { justify-content: center; } +.permissions__choice--yes { --accent-colour: #0a0; } +.permissions__choice--no { --accent-colour: #a00; } +.permissions__choice--never { --accent-colour: #400; } + +.permissions__choice__wrapper { + border-left: 1px solid rgba(255, 255, 255, .1); +} + +@media (max-width: 800px) { + .permissions__line { + flex-wrap: wrap; + justify-content: right; + border-bottom: 1px solid rgba(255, 255, 255, .1); + } + + .permissions__line:not(.permissions__line--header) .permissions__title { + width: 100%; + border-bottom-width: 0; + } + + .permissions__choice { + border-left-width: 0; + padding: 10px; + } + + .permissions__choice--yes { border-left-width: 0; } +} diff --git a/assets/css/misuzu/profile/about.css b/assets/css/misuzu/profile/about.css new file mode 100644 index 0000000..1391536 --- /dev/null +++ b/assets/css/misuzu/profile/about.css @@ -0,0 +1,18 @@ +.profile__about__content { + max-height: 1000px; + overflow: auto; + padding: 2px 5px; +} +.profile__about__editor { + padding: 5px; +} +.profile__about__text { + width: 100%; + height: 500px; + max-width: 100%; + min-width: 100%; +} +.profile__about__select { + margin-bottom: 5px; + width: 100%; +} diff --git a/assets/css/misuzu/profile/accounts.css b/assets/css/misuzu/profile/accounts.css new file mode 100644 index 0000000..4e40109 --- /dev/null +++ b/assets/css/misuzu/profile/accounts.css @@ -0,0 +1,42 @@ +.profile__accounts__content { + display: flex; + flex-direction: column; + padding: 2px 5px; +} + +.profile__accounts__item { + padding-bottom: 5px; +} +.profile__accounts__item:not(:last-child) { + border-bottom: 1px solid #222; +} + +.profile__accounts__notice { + font-size: 1.2em; + line-height: 1.5em; + text-align: center; + padding: 10px; +} + +.profile__accounts__title { + font-size: .9em; + line-height: 1.8em; +} +.profile__accounts__value { + font-size: 1.2em; + line-height: 1.2em; + color: inherit; + text-decoration: none; +} + +.profile__accounts__input { + width: 100%; +} + +.profile__accounts__link { + color: inherit; + text-decoration: underline dotted; +} +.profile__accounts__link:hover { + text-decoration: underline; +} diff --git a/assets/css/misuzu/profile/birthdate.css b/assets/css/misuzu/profile/birthdate.css new file mode 100644 index 0000000..6a5b8c1 --- /dev/null +++ b/assets/css/misuzu/profile/birthdate.css @@ -0,0 +1,13 @@ +.profile__birthdate__content { + padding: 2px 5px; +} +.profile__birthdate__select { + min-width: auto; +} +.profile__birthdate__label { + display: inline-block; +} +.profile__birthdate__title { + font-size: .9em; + line-height: 1.8em; +} diff --git a/assets/css/misuzu/profile/guidelines.css b/assets/css/misuzu/profile/guidelines.css new file mode 100644 index 0000000..098ebf0 --- /dev/null +++ b/assets/css/misuzu/profile/guidelines.css @@ -0,0 +1,45 @@ +.profile__guidelines { + display: flex; + flex-wrap: auto; + justify-content: space-evenly; + padding: 2px; +} + +.profile__guidelines__section { + width: 100%; + list-style: none; +} + +.profile__guidelines__line { + padding: 1px; +} +.profile__guidelines__line--header { + font-size: 1.2em; + line-height: 1.5em; + font-weight: 700; + margin-bottom: 2px; + border-bottom: 1px solid var(--accent-colour); + padding-bottom: 2px; +} +.profile__guidelines__line:not(&--header) { + margin-left: 1.3em; + list-style: square; +} + +.profile__guidelines__emphasis { + font-weight: 700; +} + +.profile__guidelines__link { + color: inherit; + text-decoration: underline dotted; +} +.profile__guidelines__link:hover { + text-decoration: underline; +} + +@media (max-width: 800px) { + .profile__guidelines { + flex-direction: column; + } +} diff --git a/assets/css/misuzu/profile/header.css b/assets/css/misuzu/profile/header.css new file mode 100644 index 0000000..4750324 --- /dev/null +++ b/assets/css/misuzu/profile/header.css @@ -0,0 +1,202 @@ +.profile__header { + display: flex; + flex-direction: column; + margin-bottom: 2px; + color: #fff; + background-color: var(--background-colour); + + --profile-header-overlay-start: transparent; + --profile-header-overlay-stop: var(--background-colour-translucent-9); +} + +.profile__header__background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: var(--accent-colour) var(--background-pattern); + background-blend-mode: multiply; +} + +.profile__header--has-header { + --profile-header-overlay-start: var(--background-colour-translucent-3); +} + +.profile__header--has-header .profile__header__background { + background: var(--user-header) center / cover no-repeat; + background-blend-mode: unset; +} + +.profile__header__avatar { + display: flex; +} +.profile__header__avatar__image { + width: 120px; + height: 120px; + z-index: 20; +} +.profile__header__avatar__image--edit { + cursor: pointer; +} + +.profile__header__avatar__check { + display: none; +} + +.profile__header__avatar__check:checked ~ .profile__header__avatar__option { + color: #111; + background-color: var(--accent-colour); + border-color: var(--accent-colour); +} + +.profile__header__avatar__options { + z-index: 10; + margin-left: 2px; + display: flex; + justify-content: flex-end; + flex-direction: column; +} + +.profile__header__avatar__option { + display: inline-block; + margin-top: 2px; +} +.profile__header__avatar__option--delete { + --accent-colour: #c00; +} + +.profile__header__details { + height: 100%; + display: flex; + align-items: flex-end; + padding: 20px; + background-image: linear-gradient(0deg, var(--profile-header-overlay-stop), var(--profile-header-overlay-start)); +} +.profile__header__details__content { + margin: 5px 10px; + flex: 1 1 auto; +} + +.profile__header__details__relation { + font-variant: all-small-caps; + background: var(--profile-header-overlay-stop); + border-radius: 2px; + line-height: 1.2em; + padding: 1px 5px 4px; + cursor: default; +} + +.profile__header__options { + min-height: 62px; + background-color: var(--profile-header-overlay-stop); + padding: 0 20px; + display: flex; + justify-content: space-between; +} + +.profile__header__actions { + display: flex; + align-items: center; +} + +.profile__header__action { + margin-right: 5px; +} + +.profile__header__stats { + display: flex; +} + +.profile__header__stat { + display: block; + color: inherit; + text-decoration: none; + padding: 10px; + cursor: default; +} +.profile__header__stat--date { + min-width: 130px; +} +.profile__header__stat__name { + font-size: .9em; + font-variant: small-caps; + cursor: inherit; +} +.profile__header__stat__value { + font-size: 1.3em; + text-align: right; + cursor: inherit; + display: block; +} +.profile__header__stat--date .profile__header__stat__value { + text-align: left; +} +.profile__header__stat--link { + cursor: pointer; +} + +.profile__header__stat--link:hover, +.profile__header__stat--link:focus, +.profile__header__stat--link:active, +.profile__header__stat--active { + border-bottom: 2px solid var(--accent-colour); +} + +.profile__header__username { + color: var(--user-colour); + font-size: 2em; + line-height: 1.5em; +} + +.profile__header__title { + font-size: .9em; + line-height: 1.2em; +} + +.profile__header__country { + display: inline-flex; + align-items: center; +} +.profile__header__country__name { + font-size: .9em; + margin-left: 4px; + line-height: 1.2em; +} + +@media (max-width: 800px) { + .profile__header { + height: auto; + background-size: 800px auto; + background-position: center top; + } + .profile__header__avatar__image { + width: 80px; + height: 80px; + } + .profile__header__details { + flex-direction: column; + align-items: center; + } + .profile__header__details__content { + text-align: center; + } + .profile__header__options { + flex-direction: column; + } + .profile__header__actions { + flex-direction: column; + } + .profile__header__action { + margin-right: 0; + margin-bottom: 5px; + width: 100%; + } + .profile__header__stats { + flex-direction: column; + flex-wrap: wrap; + } + .profile__header__stat--date .profile__header__stat__value { + text-align: right; + } +} diff --git a/assets/css/misuzu/profile/profile.css b/assets/css/misuzu/profile/profile.css new file mode 100644 index 0000000..fd20872 --- /dev/null +++ b/assets/css/misuzu/profile/profile.css @@ -0,0 +1,38 @@ +.profile__container { + margin-bottom: 2px; +} + +.profile__content { + display: flex; +} +.profile__content__main { + flex: 1 1 auto; + word-wrap: break-word; + overflow: hidden; +} +.profile__content__side { + flex: 0 0 auto; + width: 100%; + max-width: 300px; + margin-right: 2px; +} + +.profile__hidden { + display: none; +} + +.profile__pagination { + margin: 2px 0; + padding: 5px; +} + +.profile__background-settings__content { + display: flex; + flex-direction: column; + padding: 5px; +} + +@media (max-width: 800px) { + .profile__content { flex-direction: column; } + .profile__content__side { max-width: 100%; } +} diff --git a/assets/css/misuzu/profile/relations.css b/assets/css/misuzu/profile/relations.css new file mode 100644 index 0000000..046bef1 --- /dev/null +++ b/assets/css/misuzu/profile/relations.css @@ -0,0 +1,10 @@ +.profile__relations { + display: flex; + flex-wrap: wrap; + justify-content: center; +} +.profile__relations__user { + margin: 2px; + width: 300px; + display: flex; +} diff --git a/assets/css/misuzu/profile/signature.css b/assets/css/misuzu/profile/signature.css new file mode 100644 index 0000000..b5d9089 --- /dev/null +++ b/assets/css/misuzu/profile/signature.css @@ -0,0 +1,21 @@ +.profile__signature__content { + max-height: 150px; + overflow: hidden; + padding: 2px 5px; +} +.profile__signature__editor { + padding: 5px; +} +.profile__signature__text { + width: 100%; + height: 200px; + max-width: 100%; + min-width: 100%; +} +.profile__signature__select { + width: 100%; + margin-bottom: 5px; +} +.profile__signature img { + vertical-align: middle; +} diff --git a/assets/css/misuzu/profile/warning.css b/assets/css/misuzu/profile/warning.css new file mode 100644 index 0000000..bed75fc --- /dev/null +++ b/assets/css/misuzu/profile/warning.css @@ -0,0 +1,139 @@ +.profile__warning { + margin: 2px; + border-radius: 2px; + border: 1px solid var(--accent-colour); +} +.profile__warning__container { + margin: 2px 0; +} + +.profile__warning--warning { + --accent-colour: #666; +} + +.profile__warning--silence { + --accent-colour: #f70; +} + +.profile__warning--ban { + --accent-colour: #c33; +} + +.profile__warning--extendo { + margin: 4px; +} + +.profile__warning__background { + background-color: var(--accent-colour); + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; +} + +.profile__warning__content { + background-color: var(--background-colour-translucent-9); + display: flex; + padding: 1px; +} + +.profile__warning__type, +.profile__warning__created, +.profile__warning__duration { + display: inline-flex; + align-items: center; + justify-content: center; +} + +.profile__warning__type { + min-width: 80px; + background-color: var(--accent-colour); + border-radius: 1px; + padding: 0 4px; +} + +.profile__warning__created, +.profile__warning__duration { + min-width: 100px; + padding: 0 4px; +} + +.profile__warning__note { + padding: 1px 4px; + flex: 1 1 auto; +} + +.profile__warning__private { + border-top: 1px solid var(--accent-colour); + margin-top: 1px; + width: 100%; + opacity: .5; + transition: opacity .2s; +} +.profile__warning__private:hover, +.profile__warning__private:active, +.profile__warning__private:focus { + opacity: 1; +} + +.profile__warning__tools { + display: flex; + padding-bottom: 1px; +} + +.profile__warning__options { + flex: 1 1 auto; + display: flex; + justify-content: flex-end; + align-items: center; +} + +.profile__warning__option { + padding: 2px 5px; + color: inherit; + text-decoration: none; +} + +.profile__warning__user { + display: flex; + padding: 2px; + min-width: 300px; +} + +.profile__warning__user__avatar { + width: 20px; + height: 20px; +} + +.profile__warning__user__username { + padding: 0 5px; + min-width: 60px; + color: inherit; + text-decoration: none; +} +.profile__warning__user__username:hover, +.profile__warning__user__username:focus, +.profile__warning__user__username:active { + text-decoration: underline; +} + +.profile__warning__user__ip { + display: inline-flex; + padding: 0 5px; +} +.profile__warning__user__ip:before { content: "("; } +.profile__warning__user__ip:after { content: ")"; } + + +@media (max-width: 800px) { + .profile__warning__content { + flex-wrap: wrap; + } + .profile__warning__tools { + flex-direction: column; + } + .profile__warning__options { + justify-content: flex-start; + } +} \ No newline at end of file diff --git a/assets/css/misuzu/search/anchor.css b/assets/css/misuzu/search/anchor.css new file mode 100644 index 0000000..6dd83b6 --- /dev/null +++ b/assets/css/misuzu/search/anchor.css @@ -0,0 +1,4 @@ +.search__anchor { + position: relative; + top: -94px; +} diff --git a/assets/css/misuzu/search/categories.css b/assets/css/misuzu/search/categories.css new file mode 100644 index 0000000..b9da202 --- /dev/null +++ b/assets/css/misuzu/search/categories.css @@ -0,0 +1,38 @@ +.search__categories { + display: flex; +} + +.search__category { + display: block; + color: inherit; + text-decoration: none; + background-color: var(--accent-colour); + box-shadow: 0 1px 2px #000A; + text-shadow: 0 1px 4px #000; + overflow: hidden; + border: 1px solid transparent; + border-radius: 5px; + font-size: 1.1em; + margin: 1px 1px 1px 0; +} + +.search__category__background { + background-color: var(--background-colour-translucent-9); + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + transition: background-color .2s; +} +.search__category:hover .search__category__background, +.search__category:focus .search__category__background { + background-color: var(--background-colour-translucent-8); +} +.search__category:active .search__category__background { + background-color: var(--background-colour-translucent-7); +} + +.search__category__content { + padding: 2px 5px; +} diff --git a/assets/css/misuzu/search/container.css b/assets/css/misuzu/search/container.css new file mode 100644 index 0000000..b48464b --- /dev/null +++ b/assets/css/misuzu/search/container.css @@ -0,0 +1,3 @@ +.search__container { + margin: 5px 0; +} diff --git a/assets/css/misuzu/search/header.css b/assets/css/misuzu/search/header.css new file mode 100644 index 0000000..1b0aa8e --- /dev/null +++ b/assets/css/misuzu/search/header.css @@ -0,0 +1,7 @@ +.search__header { + padding: 1em; + position: sticky; + top: 0; + z-index: 50; + background-color: var(--background-colour); +} diff --git a/assets/css/misuzu/search/input.css b/assets/css/misuzu/search/input.css new file mode 100644 index 0000000..3495329 --- /dev/null +++ b/assets/css/misuzu/search/input.css @@ -0,0 +1,48 @@ +.search__input { + background-color: var(--accent-colour); + box-shadow: 0 1px 2px #000A; + text-shadow: 0 1px 4px #000; + overflow: hidden; + border: 1px solid transparent; + border-radius: 5px; + font-size: 1.5em; +} +.search__input__background { + background-color: var(--background-colour-translucent-9); + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; +} +.search__input__container { + display: flex; + margin: 1px; +} + +.search__input__text { + flex: 1 1 auto; + border: 0; + background-color: transparent; + color: #fff; + padding: 5px 10px; + font-size: inherit; +} + +.search__input__button { + flex: 0 0 auto; + border: 0; + color: #fff; + border-radius: 4px; + width: 40px; + height: 40px; + font-size: inherit; + cursor: pointer; + background-color: transparent; + transition: background-color .2s; +} +.search__input__button:hover, +.search__input__button:active, +.search__input__button:focus { + background-color: var(--accent-colour); +} diff --git a/assets/css/misuzu/search/none.css b/assets/css/misuzu/search/none.css new file mode 100644 index 0000000..a1d9c57 --- /dev/null +++ b/assets/css/misuzu/search/none.css @@ -0,0 +1,21 @@ +.search__none { + display: flex; +} +.search__none__icon { + width: 60px; + height: 60px; + line-height: 60px; + text-align: center; + font-size: 3em; + flex: 0 0 auto; +} +.search__none__content { + display: flex; + flex-direction: column; + justify-content: center; + flex: 1 1 auto; +} +.search__none__title { + font-size: 1.5em; + line-height: 1.5em; +} diff --git a/assets/css/misuzu/settings/account-logs.css b/assets/css/misuzu/settings/account-logs.css new file mode 100644 index 0000000..ffa0960 --- /dev/null +++ b/assets/css/misuzu/settings/account-logs.css @@ -0,0 +1,93 @@ +.settings__account-logs__pagination { + margin: 4px; +} + +.settings__account-log { + border: 1px solid var(--accent-colour); + border-radius: 2px; + overflow: hidden; + margin: 4px; +} + +.settings__account-log__container { + width: 100%; + height: 100%; + overflow: hidden; +} + +.settings__account-log__important { + display: flex; + align-items: center; + font-size: 1.4em; + z-index: 2; +} + +.settings__account-log__flag { + flex: 0 0 auto; + margin: 10px; + margin-right: 0; +} + +.settings__account-log__description { + flex: 1 1 auto; + margin: 10px; +} + +.settings__account-log__actions { + flex: 0 0 auto; + display: flex; +} + +.settings__account-log__action { + border: 0; + background: transparent; + color: inherit; + font: inherit; + text-shadow: inherit; + padding: 10px; + cursor: pointer; + transition: color .2s; +} +.settings__account-log__action:hover, +.settings__account-log__action:focus { + color: var(--accent-colour); +} + +.settings__account-log__details { + z-index: 1; + margin: 10px; + margin-top: -5px; + display: flex; + flex-wrap: wrap; +} + +.settings__account-log__detail { + display: inline-block; + margin-right: 2px; + min-width: 120px; +} +.settings__account-log__detail__title { + border-bottom: 1px solid var(--accent-colour); + font-weight: 700; + padding: 1px 5px; +} +.settings__account-log__detail__value { + padding: 1px 5px; +} + +.settings__account-log__user { + color: inherit; + text-decoration: none; + display: flex; + padding: 4px; + border-bottom: 1px solid var(--accent-colour); + margin-bottom: -2px; +} +.settings__account-log__user__avatar { + width: 20px; + height: 20px; +} +.settings__account-log__user__name { + color: var(--user-colour); + padding-left: 4px; +} diff --git a/assets/css/misuzu/settings/account.css b/assets/css/misuzu/settings/account.css new file mode 100644 index 0000000..e90dee0 --- /dev/null +++ b/assets/css/misuzu/settings/account.css @@ -0,0 +1,46 @@ +.settings__account { + display: grid; + grid-template-columns: 1fr 1fr; +} + +.settings__account__section { + margin: 5px; +} +.settings__account__section--confirm { + grid-column: 1 / span 2; +} + +.settings__account__item { + padding-bottom: 5px; +} +.settings__account__item:not(:last-child) { + border-bottom: 1px solid #222; +} + +.settings__account__title { + font-size: .9em; + line-height: 1.8em; +} + +.settings__account__input { + width: 100%; +} + +.settings__account__buttons { + display: flex; + margin-top: 5px; + justify-content: center; +} + +.settings__account__button { + margin: 0 2px; +} + +@media (max-width: 800px) { + .settings__account { + grid-template-columns: 1fr; + } + .settings__account__section { + grid-column: 1 / 1; + } +} \ No newline at end of file diff --git a/assets/css/misuzu/settings/data.css b/assets/css/misuzu/settings/data.css new file mode 100644 index 0000000..77b8d14 --- /dev/null +++ b/assets/css/misuzu/settings/data.css @@ -0,0 +1,11 @@ +.settings__data__content { + padding: 5px; +} +.settings__data__password { + display: block; + width: 100%; +} +.settings__data__actions { + margin-top: 5px; + text-align: center; +} diff --git a/assets/css/misuzu/settings/login-attempts.css b/assets/css/misuzu/settings/login-attempts.css new file mode 100644 index 0000000..39502c9 --- /dev/null +++ b/assets/css/misuzu/settings/login-attempts.css @@ -0,0 +1,88 @@ +.settings__login-attempts__pagination { + margin: 4px; +} +.settings__login-attempts__none { + padding: 2px 5px; + text-align: center; +} + +.settings__login-attempt { + border: 1px solid var(--accent-colour); + border-radius: 2px; + overflow: hidden; + margin: 4px; +} + +.settings__login-attempt--failed { + --accent-colour: #a00; + background-color: var(--accent-colour); +} + +.settings__login-attempt--failed .settings__login-attempt__container { + background-color: rgba(17, 17, 17, .8); +} + +.settings__login-attempt__container { + width: 100%; + height: 100%; + overflow: hidden; +} + +.settings__login-attempt__important { + display: flex; + align-items: center; + font-size: 1.4em; + z-index: 2; +} + +.settings__login-attempt__flag { + flex: 0 0 auto; + margin: 10px; + margin-right: 0; +} + +.settings__login-attempt__description { + flex: 1 1 auto; + margin: 10px; +} + +.settings__login-attempt__actions { + flex: 0 0 auto; + display: flex; +} + +.settings__login-attempt__action { + border: 0; + background: transparent; + color: inherit; + font: inherit; + text-shadow: inherit; + padding: 10px; + cursor: pointer; + transition: color .2s; +} +.settings__login-attempt__action:hover { + color: var(--accent-colour); +} + +.settings__login-attempt__details { + z-index: 1; + margin: 10px; + margin-top: -5px; + display: flex; + flex-wrap: wrap; +} + +.settings__login-attempt__detail { + display: inline-block; + margin-right: 2px; + min-width: 120px; +} +.settings__login-attempt__detail__title { + border-bottom: 1px solid var(--accent-colour); + font-weight: 700; + padding: 1px 5px; +} +.settings__login-attempt__detail__value { + padding: 1px 5px; +} diff --git a/assets/css/misuzu/settings/role.css b/assets/css/misuzu/settings/role.css new file mode 100644 index 0000000..9f25979 --- /dev/null +++ b/assets/css/misuzu/settings/role.css @@ -0,0 +1,64 @@ +.settings__role { + border: 1px solid var(--accent-colour); + background-color: var(--accent-colour); + border-radius: 2px; + margin: 2px; + overflow: hidden; + width: 200px; +} + +.settings__role__collection { + display: flex; + flex-wrap: wrap; + justify-content: center; + margin: 2px; +} + +.settings__role__content { + background-color: var(--background-colour-translucent-9); + width: 100%; + height: 100%; + display: flex; + flex-direction: column; +} + +.settings__role__name { + font-size: 1.2em; + line-height: 1.7em; + border-bottom: 1px solid var(--accent-colour); + padding: 0 5px; +} + +.settings__role__description { + font-size: .9em; + line-height: 1.8em; + padding: 0 2px; + margin: 0 2px; + flex: 1 1 auto; +} + +.settings__role__options { + flex: 0 0 auto; + display: flex; + font-size: 1.5em; + justify-content: space-evenly; +} + +.settings__role__option { + border: 0; + background: transparent; + color: inherit; + font: inherit; + text-shadow: inherit; + transition: color .2s; + flex: 0 0 auto; + width: 40px; + height: 40px; +} +.settings__role__option:not(.settings__role__option--disabled):hover { + color: var(--accent-colour); + cursor: pointer; +} +.settings__role__option--disabled { + opacity: .2; +} diff --git a/assets/css/misuzu/settings/sessions.css b/assets/css/misuzu/settings/sessions.css new file mode 100644 index 0000000..bff545c --- /dev/null +++ b/assets/css/misuzu/settings/sessions.css @@ -0,0 +1,86 @@ +.settings__sessions__all { + display: flex; + justify-content: center; + margin: 10px; +} +.settings__sessions__pagination { + margin: 4px; +} + +.settings__session { + border: 1px solid var(--accent-colour); + border-radius: 2px; + overflow: hidden; + margin: 4px; +} +.settings__session--current { + background-color: var(--accent-colour); +} +.settings__session--current .settings__session__container { + background-color: rgba(17, 17, 17, .8); +} + +.settings__session__container { + width: 100%; + height: 100%; + overflow: hidden; +} + +.settings__session__important { + display: flex; + align-items: center; + font-size: 1.4em; + z-index: 2; +} + +.settings__session__flag { + flex: 0 0 auto; + margin: 10px; + margin-right: 0; +} + +.settings__session__description { + flex: 1 1 auto; + margin: 10px; +} + +.settings__session__actions { + flex: 0 0 auto; + display: flex; +} + +.settings__session__action { + border: 0; + background: transparent; + color: inherit; + font: inherit; + text-shadow: inherit; + padding: 10px; + cursor: pointer; + transition: color .2s; +} +.settings__session__action:hover { + color: var(--accent-colour); +} + +.settings__session__details { + z-index: 1; + margin: 10px; + margin-top: -5px; + display: flex; + flex-wrap: wrap; +} + +.settings__session__detail { + display: inline-block; + margin-right: 2px; + min-width: 120px; +} +.settings__session__detail__title { + border-bottom: 1px solid var(--accent-colour); + font-weight: 700; + padding: 1px 5px; +} +.settings__session__detail__value { + padding: 1px 5px; +} diff --git a/assets/css/misuzu/settings/settings.css b/assets/css/misuzu/settings/settings.css new file mode 100644 index 0000000..011c3c4 --- /dev/null +++ b/assets/css/misuzu/settings/settings.css @@ -0,0 +1,65 @@ +.settings__container { + overflow: auto; +} +.settings__container:not(:last-child) { + margin-bottom: 2px; +} + +.settings__description { + font-size: .9em; + padding: 2px 5px; + border-bottom: 1px solid var(--accent-colour); + margin: 1px 1px 2px; +} + +.settings__pagination { + max-width: 400px; + margin: 2px auto; +} + +.settings__wrapper { + display: flex; +} +.settings__wrapper__sidebar { + flex: 0 0 auto; +} + +.settings__wrapper__content { + flex: 1 1 auto; +} + +.settings__wrapper__menu { + width: 280px; + margin-right: 2px; +} + +.settings__wrapper__link { + color: inherit; + text-decoration: none; + display: block; + padding: 4px; + margin: 2px; + font-size: 1.5em; + line-height: 1.5em; + border-radius: 2px; + transition: background-color .2s; +} +.settings__wrapper__link:hover { + background-color: var(--background-colour-translucent-9); +} + +@media (max-width: 800px) { + .settings__wrapper { + flex-direction: column; + } + .settings__wrapper__sidebar { + width: 100%; + } + .settings__wrapper__menu { + width: 100%; + } + .settings__wrapper__link { + display: inline-block; + padding: 4px 10px; + } +} \ No newline at end of file diff --git a/assets/css/misuzu/settings/two-factor.css b/assets/css/misuzu/settings/two-factor.css new file mode 100644 index 0000000..2b573fc --- /dev/null +++ b/assets/css/misuzu/settings/two-factor.css @@ -0,0 +1,42 @@ +.settings__two-factor { + display: flex; + margin: 5px; +} + +.settings__two-factor__code { + display: flex; + flex-direction: column; + align-items: center; + background-color: #fff; + flex: 0 0 auto; +} +.settings__two-factor__code__image { + vertical-align: middle; + flex: 0 0 auto; +} +.settings__two-factor__code__text { + color: #000; + flex: 0 0 auto; + font-size: 1.2em; + line-height: 1.5em; + font-family: var(--font-monospace); +} + +.settings__two-factor__settings { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + flex: 1 1 auto; +} +.settings__two-factor__settings__status { + font-size: 1.5em; + line-height: 2em; +} + +@media (max-width: 800px) { + .settings__two-factor { + flex-direction: column; + align-items: center; + } +} diff --git a/assets/css/misuzu/user/usercard.css b/assets/css/misuzu/user/usercard.css new file mode 100644 index 0000000..2041dcf --- /dev/null +++ b/assets/css/misuzu/user/usercard.css @@ -0,0 +1,170 @@ +.usercard { + display: flex; + flex-direction: column; + transition: box-shadow .5s; + z-index: 1; + color: #fff; + background-color: var(--background-colour); + box-shadow: 0 1px 2px #000A; + text-shadow: 0 1px 4px #000; + overflow: hidden; + flex: 1 1 auto; + + --usercard-header-overlay-start: transparent; + --usercard-header-overlay-stop: var(--background-colour-translucent-9); +} +.usercard:hover { + box-shadow: 0 1px 4px #000; + z-index: 2; +} +.usercard__background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: var(--accent-colour) var(--background-pattern); + background-blend-mode: multiply; +} + +.usercard__header { + flex: 0 0 auto; +} +.usercard__header__link { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; +} + +.usercard__header__avatar { + width: 60px; + height: 60px; + z-index: 20; +} + +.usercard__header__container { + display: flex; + align-items: center; + padding: 10px; + background-image: linear-gradient(0deg, var(--usercard-header-overlay-stop), var(--usercard-header-overlay-start)); + pointer-events: none; +} + +.usercard__header__details { + margin: 0 10px; + flex: 1 1 auto; +} + +.usercard__header__relation { + font-variant: all-small-caps; + background: var(--usercard-header-overlay-stop); + border-radius: 2px; + line-height: 1.2em; + padding: 1px 5px 4px; + cursor: default; +} + +.usercard__header__username { + font-size: 1.5em; + line-height: 1.3em; +} + +.usercard__header__title { + font-size: .9em; + line-height: 1.2em; +} + +.usercard__header__country { + display: inline-flex; + align-items: center; +} +.usercard__header__country__name { + font-size: .9em; + margin-left: 4px; + line-height: 1.2em; +} + +.usercard__container { + flex: 1 1 auto; + background-color: var(--usercard-header-overlay-stop); + display: flex; + flex-direction: column; + justify-content: flex-end; +} + +.usercard__dates { + font-size: .9em; + line-height: 1em; + display: flex; + justify-content: space-evenly; + align-items: center; + flex: 0 0 auto; + margin-bottom: 4px; +} +.usercard__date { + padding: 4px; +} + +.usercard__stats { + display: flex; + flex-wrap: wrap; + justify-content: flex-end; + flex: 0 0 auto; +} +.usercard__stat { + display: flex; + flex-direction: column-reverse; + color: inherit; + text-decoration: none; + padding: 5px 10px; + cursor: default; + flex: 0 0 auto; + text-align: right; +} +.usercard__stat[href] { + cursor: pointer; +} +.usercard__stat[href]:hover, +.usercard__stat[href]:focus { + border-bottom: 2px solid var(--accent-colour); + padding-bottom: 3px; +} +.usercard__stat__name { + font-size: .9em; + font-variant: small-caps; + cursor: inherit; +} +.usercard__stat__value { + font-size: 1.3em; + cursor: inherit; + display: block; +} + +.usercard__actions { + flex: 0 0 auto; + display: flex; + height: 38px; +} +.usercard__action { + flex: 1 1 auto; + display: flex; + justify-content: center; + align-items: center; + color: inherit; + text-decoration: none; + font-size: 1.5em; + transition: background-color .2s; + text-align: center; + cursor: pointer; +} +.usercard__action:hover, +.usercard__action:focus { background-color: rgba(255, 255, 255, .2); } +.usercard__action:active { background-color: rgba(255, 255, 255, .1); } + +@media (max-width: 800px) { + .usercard__header__details { + text-align: center; + } +} diff --git a/assets/css/misuzu/user/userlist.css b/assets/css/misuzu/user/userlist.css new file mode 100644 index 0000000..cc7be94 --- /dev/null +++ b/assets/css/misuzu/user/userlist.css @@ -0,0 +1,66 @@ +.userlist { + display: flex; + flex-wrap: wrap; + justify-content: center; + overflow: hidden; + padding: 2px; +} +.userlist__item { + margin: 2px; + width: 300px; + display: flex; +} +.userlist__empty { + text-align: center; + font-size: 2em; + line-height: 1.5em; + margin: 1em; +} +.userlist__container { + padding: 5px; + margin: 2px 0; +} +.userlist__navigation { + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: stretch; +} +.userlist__pagination { + max-width: 500px; + flex: 1 1 auto; + display: flex; + align-items: stretch; + justify-content: space-between; +} +.userlist__sorting { + flex: 0 0 auto; + display: flex; + align-items: stretch; +} +.userlist__select { + margin: 0 2px; + background: inherit; + box-shadow: initial; + border-width: 0; + border-radius: 0; + background: var(--background-colour-translucent-9); + color: var(--text-colour); +} + +@media (max-width: 800px) { + .userlist__navigation { + flex-direction: column; + } + .userlist__pagination { + max-width: 100%; + flex-grow: 0; + margin-top: 5px; + } + .userlist__sorting { + flex-direction: column; + } + .userlist__select:not(:first-child) { + margin-top: 5px; + } +} \ No newline at end of file diff --git a/assets/css/misuzu/warning.css b/assets/css/misuzu/warning.css new file mode 100644 index 0000000..470cfbc --- /dev/null +++ b/assets/css/misuzu/warning.css @@ -0,0 +1,24 @@ +.warning { + --start-colour: yellow; + --end-colour: black; + + background-image: repeating-linear-gradient(-45deg, var(--start-colour), var(--start-colour) 10px, var(--end-colour) 10px, var(--end-colour) 20px); + box-shadow: 0 1px 4px #111; + margin: 2px 0; + padding: 2px; + color: #fff; + text-align: center; +} +.warning__content { + background-color: rgba(17, 17, 17, .9); + padding: 2px 5px; +} +.warning__link { + color: inherit; + text-decoration: underline dotted; +} +.warning__link:hover, +.warning__link:active, +.warning__link:focus { + text-decoration: underline; +} diff --git a/assets/js/misuzu/__extensions.js b/assets/js/misuzu/__extensions.js new file mode 100644 index 0000000..7eff7e2 --- /dev/null +++ b/assets/js/misuzu/__extensions.js @@ -0,0 +1,176 @@ +Array.prototype.removeIndex = function(index) { + this.splice(index, 1); + return this; +}; +Array.prototype.removeItem = function(item) { + var index; + while(this.length > 0 && (index = this.indexOf(item)) >= 0) + this.removeIndex(index); + return this; +}; +Array.prototype.removeFind = function(predicate) { + var index; + while(this.length > 0 && (index = this.findIndex(predicate)) >= 0) + this.removeIndex(index); + return this; +}; + +HTMLCollection.prototype.toArray = function() { + return Array.prototype.slice.call(this); +}; + +HTMLTextAreaElement.prototype.insertTags = function(tagOpen, tagClose) { + tagOpen = tagOpen || ''; + tagClose = tagClose || ''; + + if(document.selection) { + this.focus(); + var selected = document.selection.createRange(); + selected.text = tagOpen + selected.text + tagClose; + this.focus(); + } else if(this.selectionStart || this.selectionStart === 0) { + var startPos = this.selectionStart, + endPos = this.selectionEnd, + scrollTop = this.scrollTop; + + this.value = this.value.substring(0, startPos) + + tagOpen + + this.value.substring(startPos, endPos) + + tagClose + + this.value.substring(endPos, this.value.length); + + this.focus(); + this.selectionStart = startPos + tagOpen.length; + this.selectionEnd = endPos + tagOpen.length; + this.scrollTop + scrollTop; + } else { + this.value += tagOpen + tagClose; + this.focus(); + } +}; + +var CreateElement = function(elemInfo) { + elemInfo = elemInfo || {}; + var elem = document.createElement(elemInfo.tag || 'div'); + + if(elemInfo.props) { + var propKeys = Object.keys(elemInfo.props); + + for(var i = 0; i < propKeys.length; i++) { + var propKey = propKeys[i]; + + if(elemInfo.props[propKey] === undefined + || elemInfo.props[propKey] === null) + continue; + + switch(typeof elemInfo.props[propKey]) { + case 'function': + elem.addEventListener( + propKey.substring(0, 2) === 'on' + ? propKey.substring(2).toLowerCase() + : propKey, + elemInfo.props[propKey] + ); + break; + + default: + elem.setAttribute(propKey === 'className' ? 'class' : propKey, elemInfo.props[propKey]); + break; + } + } + } + + if(elemInfo.children) { + var children = elemInfo.children; + + if(!Array.isArray(children)) + children = [children]; + + for(var i = 0; i < children.length; i++) { + var child = children[i]; + + switch(typeof child) { + case 'string': + elem.appendChild(document.createTextNode(child)); + break; + + case 'object': + if(child instanceof Element) + elem.appendChild(child); + else if(child.getElement) + elem.appendChild(child.getElement()); + else + elem.appendChild(CreateElement(child)); + break; + + default: + elem.appendChild(document.createTextNode(child.toString())); + break; + } + } + } + + if(elemInfo.created) + elemInfo.created(elem); + + return elem; +}; + +var CreateBasicElement = function(className, children, tagName) { + return CreateElement({ + tag: tagName || null, + props: { + 'class': className || null, + }, + 'children': children || null, + }); +}; + +var LoadScript = function(url, loaded, error) { + if(document.querySelector('script[src="' + encodeURI(url) + '"]')) { + if(loaded) + loaded(); + return; + } + + var script = document.createElement('script'); + script.type = 'text/javascript'; + if(loaded) + script.addEventListener('load', function() { loaded(); }); + script.addEventListener('error', function() { + document.body.removeChild(script); + if(error) + error(); + }); + script.src = url; + document.body.appendChild(script); +}; + +var MakeEventTarget = function(object) { + object.eventListeners = {}; + object.addEventListener = function(type, callback) { + if(!(type in this.eventListeners)) + this.eventListeners[type] = []; + this.eventListeners[type].push(callback); + }; + object.removeEventListener = function(type, callback) { + if(!(type in this.eventListeners)) + return; + this.eventListeners[type].removeItem(callback); + }; + object.dispatchEvent = function(event) { + if(!(event.type in this.eventListeners)) + return true; + var stack = this.eventListeners[event.type].slice(); + for(var i = 0; i < stack.length; ++i) + stack[i].call(this, event); + return !event.defaultPrevented; + }; +}; + +var DefineEnum = function(values) { + var keys = Object.keys(values); + for(var i = 0; i < keys.length; ++i) + values[values[keys[i]]] = keys[i]; + return values; +}; diff --git a/assets/js/misuzu/_main.js b/assets/js/misuzu/_main.js new file mode 100644 index 0000000..062c112 --- /dev/null +++ b/assets/js/misuzu/_main.js @@ -0,0 +1,156 @@ +var Misuzu = function() { + if(Misuzu.initialised) + throw 'Misuzu script has already initialised.'; + Misuzu.started = true; + + console.log( + "%cMisuzu%c\nhttps://github.com/flashwave/misuzu", + 'font-size: 48px; color: #8559a5; background: #111;' + + 'border-radius: 5px; padding: 0 10px; text-shadow: 0 0 1em #fff;', + ); + + timeago.render(document.querySelectorAll('time')); + hljs.initHighlighting(); + + Misuzu.CSRF.init(); + Misuzu.Urls.loadFromDocument(); + Misuzu.User.refreshLocalUser(); + Misuzu.FormUtils.initDataRequestMethod(); + Misuzu.initQuickSubmit(); + Misuzu.Comments.init(); + Misuzu.Forum.Editor.init(); + Misuzu.Forum.Polls.init(); + + if(Misuzu.User.isLoggedIn()) + console.log( + 'You are %s with user id %d and colour %s.', + Misuzu.User.localUser.getUsername(), + Misuzu.User.localUser.getId(), + Misuzu.User.localUser.getColour().getCSS() + ); + else + console.log('You aren\'t logged in.'); + + Misuzu.Events.dispatch(); + + Misuzu.initLoginPage(); +}; +Misuzu.Parser = DefineEnum({ + plain: 0, + bbcode: 1, + markdown: 2, +}); +Misuzu.supportsSidewaysText = function() { return CSS.supports('writing-mode', 'sideways-lr'); }; +Misuzu.showMessageBox = function(text, title, buttons) { + if(document.querySelector('.messagebox')) + return false; + + 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) + return; + + var json = JSON.parse(xhr.responseText); + if(!json) + return; + + if(json.name) + usernameElem.value = json.name; + avatarElem.src = json.avatar; + }); + xhr.open('GET', Misuzu.Urls.format('auth-resolve-user', [{name: 'username', value: encodeURIComponent(usernameElem.value)}])); + xhr.send(); + }; + + var loginForms = document.getElementsByClassName('js-login-form'); + + 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'); + + updateForm(loginAvatar, loginUsername); + loginUsername.addEventListener('keyup', function() { + if(loginTimeOut) + return; + loginTimeOut = setTimeout(function() { + updateForm(loginAvatar, loginUsername); + clearTimeout(loginTimeOut); + loginTimeOut = 0; + }, 750); + }); + })(loginForms[i]); +}; +Misuzu.initQuickSubmit = function() { + var ctrlSubmit = document.getElementsByClassName('js-quick-submit').toArray().concat(document.getElementsByClassName('js-ctrl-enter-submit').toArray()); + 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; + + this.form.submit(); + ev.preventDefault(); + } + }); +}; diff --git a/assets/js/misuzu/colour.js b/assets/js/misuzu/colour.js new file mode 100644 index 0000000..1b8e1bb --- /dev/null +++ b/assets/js/misuzu/colour.js @@ -0,0 +1,93 @@ +Misuzu.Colour = function(raw) { + this.setRaw(raw || 0); +}; +Misuzu.Colour.prototype.raw = 0; +Misuzu.Colour.FLAG_INHERIT = 0x40000000; +Misuzu.Colour.READABILITY_THRESHOLD = 186; +Misuzu.Colour.LUMINANCE_WEIGHT_RED = .299; +Misuzu.Colour.LUMINANCE_WEIGHT_GREEN = .587; +Misuzu.Colour.LUMINANCE_WEIGHT_BLUE = .114; +Misuzu.Colour.none = function() { return new Misuzu.Colour(Misuzu.Colour.FLAG_INHERIT); }; +Misuzu.Colour.fromRGB = function(red, green, blue) { + var colour = new Misuzu.Colour; + colour.setRed(red); + colour.setGreen(green); + colour.setBlue(blue); + return colour; +}; +Misuzu.Colour.fromHex = function(hex) { + var colour = new Misuzu.Colour; + colour.setHex(hex); + return colour; +}; +Misuzu.Colour.prototype.getRaw = function() { return this.raw; }; +Misuzu.Colour.prototype.setRaw = function(raw) { + this.raw = parseInt(raw) & 0x7FFFFFFF; +}; +Misuzu.Colour.prototype.getInherit = function() { return (this.getRaw() & Misuzu.Colour.FLAG_INHERIT) > 0; }; +Misuzu.Colour.prototype.setInherit = function(inherit) { + var raw = this.getRaw(); + if(inherit) + raw |= Misuzu.Colour.FLAG_INHERIT; + else + raw &= ~Misuzu.Colour.FLAG_INHERIT; + this.setRaw(raw); +}; +Misuzu.Colour.prototype.getRed = function() { return (this.getRaw() >> 16) & 0xFF }; +Misuzu.Colour.prototype.setRed = function(red) { + var raw = this.getRaw(); + raw &= ~0xFF0000; + raw |= (parseInt(red) & 0xFF) << 16; + this.setRaw(raw); +}; +Misuzu.Colour.prototype.getGreen = function() { return (this.getRaw() >> 8) & 0xFF }; +Misuzu.Colour.prototype.setGreen = function(green) { + var raw = this.getRaw(); + raw &= ~0xFF0000; + raw |= (parseInt(green) & 0xFF) << 8; + this.setRaw(raw); +}; +Misuzu.Colour.prototype.getBlue = function() { return this.getRaw() & 0xFF }; +Misuzu.Colour.prototype.setBlue = function(blue) { + var raw = this.getRaw(); + raw &= ~0xFF0000; + raw |= parseInt(blue) & 0xFF; + this.setRaw(raw); +}; +Misuzu.Colour.prototype.getLuminance = function() { + return Misuzu.Colour.LUMINANCE_WEIGHT_RED * this.getRed() + + Misuzu.Colour.LUMINANCE_WEIGHT_GREEN * this.getGreen() + + Misuzu.Colour.LUMINANCE_WEIGHT_BLUE * this.getBlue(); +}; +Misuzu.Colour.prototype.getHex = function() { + var hex = (this.getRaw() & 0xFFFFFF).toString(16); + if(hex.length < 6) + hex = '000000'.substring(0, 6 - hex.length) + hex; + return hex; +}; +Misuzu.Colour.prototype.setHex = function(hex) { + hex = (hex || '').toString(); + if(hex[0] === '#') + hex = hex.substring(1); + if(/[^A-Fa-f0-9]/g.test(hex)) + throw 'Argument contains invalid characters.'; + if(hex.length === 3) + hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; + else if(hex.length !== 6) + throw 'Argument is not a hex string.'; + return this.setRaw(parseInt(hex, 16)); +}; +Misuzu.Colour.prototype.getCSS = function() { + if(this.getInherit()) + return 'inherit'; + return '#' + this.getHex(); +}; +Misuzu.Colour.prototype.getCSSConstrast = function(dark, light, inheritIsDark) { + dark = dark || 'dark'; + light = light || 'light'; + + if(this.getInherit()) + return inheritIsDark ? dark : light; + + return this.getLuminance() > Misuzu.Colour.READABILITY_THRESHOLD ? dark : light; +}; diff --git a/assets/js/misuzu/comments.js b/assets/js/misuzu/comments.js new file mode 100644 index 0000000..8ba3a8f --- /dev/null +++ b/assets/js/misuzu/comments.js @@ -0,0 +1,491 @@ +Misuzu.Comments = {}; +Misuzu.Comments.Vote = DefineEnum({ + none: 0, + like: 1, + dislike: -1, +}); +Misuzu.Comments.init = function() { + var commentDeletes = document.getElementsByClassName('comment__action--delete'); + for(var i = 0; i < commentDeletes.length; ++i) { + commentDeletes[i].addEventListener('click', Misuzu.Comments.deleteCommentHandler); + commentDeletes[i].dataset.href = commentDeletes[i].href; + commentDeletes[i].href = 'javascript:;'; + } + + var commentInputs = document.getElementsByClassName('comment__text--input'); + for(var i = 0; i < commentInputs.length; ++i) { + commentInputs[i].form.action = 'javascript:void(0);'; + commentInputs[i].form.addEventListener('submit', Misuzu.Comments.postCommentHandler); + commentInputs[i].addEventListener('keydown', Misuzu.Comments.inputCommentHandler); + } + + var voteButtons = document.getElementsByClassName('comment__action--vote'); + for(var i = 0; i < voteButtons.length; ++i) { + voteButtons[i].href = 'javascript:;'; + voteButtons[i].addEventListener('click', Misuzu.Comments.voteCommentHandler); + } + + var pinButtons = document.getElementsByClassName('comment__action--pin'); + for(var i = 0; i < pinButtons.length; ++i) { + pinButtons[i].href = 'javascript:;'; + pinButtons[i].addEventListener('click', Misuzu.Comments.pinCommentHandler); + } +}; +Misuzu.Comments.postComment = function(formData, onSuccess, onFailure) { + if(!Misuzu.User.isLoggedIn() + || !Misuzu.User.localUser.perms.canCreateComment()) { + if(onFailure) + onFailure("You aren't allowed to post comments."); + return; + } + + var xhr = new XMLHttpRequest; + xhr.addEventListener('readystatechange', function() { + if(xhr.readyState !== 4) + return; + + Misuzu.CSRF.setToken(xhr.getResponseHeader('X-Misuzu-CSRF')); + + var json = JSON.parse(xhr.responseText), + message = json.error || json.message; + + if(message && onFailure) + onFailure(message); + else if(!message && onSuccess) + onSuccess(json); + }); + xhr.open('POST', Misuzu.Urls.format('comment-create')); + xhr.setRequestHeader('X-Misuzu-XHR', 'comments'); + xhr.send(formData); +}; +Misuzu.Comments.postCommentHandler = function() { + if(this.dataset.disabled) + return; + this.dataset.disabled = '1'; + this.style.opacity = '0.5'; + + Misuzu.Comments.postComment( + Misuzu.FormUtils.extractFormData(this, true), + Misuzu.Comments.postCommentSuccess.bind(this), + Misuzu.Comments.postCommentFailed.bind(this) + ); +}; +Misuzu.Comments.inputCommentHandler = function(ev) { + if(ev.code === 'Enter' && ev.ctrlKey && !ev.altKey && !ev.shiftKey && !ev.metaKey) { + Misuzu.Comments.postComment( + Misuzu.FormUtils.extractFormData(this.form, true), + Misuzu.Comments.postCommentSuccess.bind(this.form), + Misuzu.Comments.postCommentFailed.bind(this.form) + ); + } +}; +Misuzu.Comments.postCommentSuccess = function(comment) { + if(this.classList.contains('comment--reply')) + this.parentNode.parentNode.querySelector('label.comment__action').click(); + + Misuzu.Comments.insertComment(comment, this); + this.style.opacity = '1'; + this.dataset.disabled = ''; +}; +Misuzu.Comments.postCommentFailed = function(message) { + Misuzu.showMessageBox(message); + this.style.opacity = '1'; + this.dataset.disabled = ''; +}; +Misuzu.Comments.deleteComment = function(commentId, onSuccess, onFailure) { + if(!Misuzu.User.isLoggedIn() + || !Misuzu.User.localUser.perms.canDeleteOwnComment()) { + if(onFailure) + onFailure('You aren\'t allowed to delete comments.'); + return; + } + + var xhr = new XMLHttpRequest; + xhr.addEventListener('readystatechange', function() { + if(xhr.readyState !== 4) + return; + + Misuzu.CSRF.setToken(xhr.getResponseHeader('X-Misuzu-CSRF')); + + var json = JSON.parse(xhr.responseText), + message = json.error || json.message; + + if(message && onFailure) + onFailure(message); + else if(!message && onSuccess) + onSuccess(json); + }); + xhr.open('GET', Misuzu.Urls.format('comment-delete', [Misuzu.Urls.v('comment', commentId)])); + xhr.setRequestHeader('X-Misuzu-XHR', 'comments'); + xhr.send(); +}; +Misuzu.Comments.deleteCommentHandler = function() { + var commentId = parseInt(this.dataset.commentId); + if(commentId < 1) + return; + + Misuzu.Comments.deleteComment( + commentId, + function(info) { + var elem = document.getElementById('comment-' + info.id); + + if(elem) + elem.parentNode.removeChild(elem); + }, + function(message) { Misuzu.showMessageBox(message); } + ); +}; +Misuzu.Comments.pinComment = function(commentId, pin, onSuccess, onFailure) { + if(!Misuzu.User.isLoggedIn() + || !Misuzu.User.localUser.perms.canPinComment()) { + if(onFailure) + onFailure("You aren't allowed to pin comments."); + return; + } + + var xhr = new XMLHttpRequest; + xhr.onreadystatechange = function() { + if(xhr.readyState !== 4) + return; + + Misuzu.CSRF.setToken(xhr.getResponseHeader('X-Misuzu-CSRF')); + + var json = JSON.parse(xhr.responseText), + message = json.error || json.message; + + if(message && onFailure) + onFailure(message); + else if(!message && onSuccess) + onSuccess(json); + }; + xhr.open('GET', Misuzu.Urls.format('comment-' + (pin ? 'pin' : 'unpin'), [Misuzu.Urls.v('comment', commentId)])); + xhr.setRequestHeader('X-Misuzu-XHR', 'comments'); + xhr.send(); +}; +Misuzu.Comments.pinCommentHandler = function() { + var target = this, + commentId = parseInt(target.dataset.commentId), + isPinned = target.dataset.commentPinned !== '0'; + + target.textContent = '...'; + + Misuzu.Comments.pinComment( + commentId, + !isPinned, + function(info) { + if(info.comment_pinned === null) { + target.textContent = 'Pin'; + target.dataset.commentPinned = '0'; + var pinElement = document.querySelector('#comment-' + info.comment_id + ' .comment__pin'); + pinElement.parentElement.removeChild(pinElement); + } else { + target.textContent = 'Unpin'; + target.dataset.commentPinned = '1'; + + var pinInfo = document.querySelector('#comment-' + info.comment_id + ' .comment__info'), + pinElement = document.createElement('div'), + pinTime = document.createElement('time'), + pinDateTime = new Date(info.comment_pinned + 'Z'); + + pinTime.title = pinDateTime.toLocaleString(); + pinTime.dateTime = pinDateTime.toISOString(); + pinTime.textContent = timeago.format(pinDateTime); + timeago.render(pinTime); + + pinElement.className = 'comment__pin'; + pinElement.appendChild(document.createTextNode('Pinned ')); + pinElement.appendChild(pinTime); + pinInfo.appendChild(pinElement); + } + }, + function(message) { + target.textContent = isPinned ? 'Unpin' : 'Pin'; + Misuzu.showMessageBox(message); + } + ); +}; +Misuzu.Comments.voteComment = function(commentId, vote, onSuccess, onFailure) { + if(!Misuzu.User.isLoggedIn() + || !Misuzu.User.localUser.perms.canVoteOnComment()) { + if(onFailure) + onFailure("You aren't allowed to vote on comments."); + return; + } + + var xhr = new XMLHttpRequest; + xhr.onreadystatechange = function() { + if(xhr.readyState !== 4) + return; + + Misuzu.CSRF.setToken(xhr.getResponseHeader('X-Misuzu-CSRF')); + + var json = JSON.parse(xhr.responseText), + message = json.error || json.message; + + if(message && onFailure) + onFailure(message); + else if(!message && onSuccess) + onSuccess(json); + }; + xhr.open('GET', Misuzu.Urls.format('comment-vote', [Misuzu.Urls.v('comment', commentId), Misuzu.Urls.v('vote', vote)])); + xhr.setRequestHeader('X-Misuzu-XHR', 'comments'); + xhr.send(); +}; +Misuzu.Comments.voteCommentHandler = function() { + var commentId = parseInt(this.dataset.commentId), + voteType = parseInt(this.dataset.commentVote), + buttons = document.querySelectorAll('.comment__action--vote[data-comment-id="' + commentId + '"]'), + likeButton = document.querySelector('.comment__action--like[data-comment-id="' + commentId + '"]'), + dislikeButton = document.querySelector('.comment__action--dislike[data-comment-id="' + commentId + '"]'), + classVoted = 'comment__action--voted'; + + for(var i = 0; i < buttons.length; ++i) { + buttons[i].textContent = buttons[i] === this ? '...' : ''; + buttons[i].classList.remove(classVoted); + buttons[i].dataset.commentVote = buttons[i] === likeButton + ? (voteType === Misuzu.Comments.Vote.like ? Misuzu.Comments.Vote.none : Misuzu.Comments.Vote.like ).toString() + : (voteType === Misuzu.Comments.Vote.dislike ? Misuzu.Comments.Vote.none : Misuzu.Comments.Vote.dislike).toString(); + } + + Misuzu.Comments.voteComment( + commentId, + voteType, + function(info) { + switch(voteType) { + case Misuzu.Comments.Vote.like: + likeButton.classList.add(classVoted); + break; + case Misuzu.Comments.Vote.dislike: + dislikeButton.classList.add(classVoted); + break; + } + + likeButton.textContent = info.likes > 0 ? ('Like (' + info.likes.toLocaleString() + ')') : 'Like'; + dislikeButton.textContent = info.dislikes > 0 ? ('Dislike (' + info.dislikes.toLocaleString() + ')') : 'Dislike'; + }, + function(message) { + likeButton.textContent = 'Like'; + dislikeButton.textContent = 'Dislike'; + Misuzu.showMessageBox(message); + } + ); +}; +Misuzu.Comments.insertComment = function(comment, form) { + var isReply = form.classList.contains('comment--reply'), + parent = isReply + ? form.parentElement + : form.parentElement.parentElement.getElementsByClassName('comments__listing')[0], + repliesIndent = isReply + ? (parseInt(parent.classList[1].substr(25)) + 1) + : 1, + commentElement = Misuzu.Comments.buildComment(comment, repliesIndent); + + if(isReply) + parent.appendChild(commentElement); + else + parent.insertBefore(commentElement, parent.firstElementChild); + + var placeholder = document.getElementById('_no_comments_notice_' + comment.category_id); + if(placeholder) + placeholder.parentNode.removeChild(placeholder); +}; +Misuzu.Comments.buildComment = function(comment, layer) { + comment = comment || {}; + layer = parseInt(layer || 0); + + var date = new Date(comment.comment_created + 'Z'), + colour = new Misuzu.Colour(comment.user_colour), + actions = [], + commentTime = CreateElement({ + tag: 'time', + props: { + className: 'comment__date', + title: date.toLocaleString(), + datetime: date.toISOString(), + }, + children: timeago.format(date), + }); + + if(Misuzu.User.isLoggedIn() && Misuzu.User.localUser.perms.canVoteOnComment()) { + actions.push(CreateElement({ + tag: 'a', + props: { + className: 'comment__action comment__action--link comment__action--vote comment__action--like', + 'data-comment-id': comment.comment_id, + 'data-comment-vote': Misuzu.Comments.Vote.like, + href: 'javascript:;', + onclick: Misuzu.Comments.voteCommentHandler, + }, + children: 'Like', + })); + actions.push(CreateElement({ + tag: 'a', + props: { + className: 'comment__action comment__action--link comment__action--vote comment__action--dislike', + 'data-comment-id': comment.comment_id, + 'data-comment-vote': Misuzu.Comments.Vote.dislike, + href: 'javascript:;', + onclick: Misuzu.Comments.voteCommentHandler, + }, + children: 'Dislike', + })); + } + + actions.push(CreateElement({ + tag: 'label', + props: { + className: 'comment__action comment__action--link', + 'for': 'comment-reply-toggle-' + comment.comment_id.toString() + }, + children: 'Reply', + })); + + var commentText = CreateBasicElement('comment__text'); + if(comment.comment_html) + commentText.innerHTML = comment.comment_html; + else + commentText.textContent = comment.comment_text; + + var commentElem = CreateElement({ + props: { + className: 'comment', + id: 'comment-' + comment.comment_id.toString(), + }, + children: [ + { + props: { className: 'comment__container', }, + children: [ + { + tag: 'a', + props: { + className: 'comment__avatar', + href: Misuzu.Urls.format('user-profile', [{name:'user',value:comment.user_id}]), + }, + children: { + tag: 'img', + props: { + className: 'avatar', + alt: comment.username, + width: (layer <= 1 ? 50 : 40), + height: (layer <= 1 ? 50 : 40), + src: Misuzu.Urls.format('user-avatar', [ + { name: 'user', value: comment.user_id }, + { name: 'res', value: layer <= 1 ? 100 : 80 } + ]), + }, + }, + }, + { + props: { className: 'comment__content', }, + children: [ + { + props: { className: 'comment__info', }, + children: [ + { + tag: 'a', + props: { + className: 'comment__user comment__user--link', + href: Misuzu.Urls.format('user-profile', [{name:'user',value:comment.user_id}]), + style: '--user-colour: ' + colour.getCSS(), + }, + children: comment.username, + }, + { + tag: 'a', + props: { + className: 'comment__link', + href: '#comment-' + comment.comment_id.toString(), + }, + children: commentTime, + }, + ], + }, + commentText, + { + props: { className: 'comment__actions', }, + children: actions, + }, + ], + }, + ], + }, + { + props: { + className: 'comment__replies comment__replies--indent-' + layer.toString(), + id: 'comment-' + comment.comment_id.toString() + '-replies', + }, + children: [ + { + tag: 'input', + props: { + className: 'comment__reply-toggle', + type: 'checkbox', + id: ('comment-reply-toggle-' + comment.comment_id.toString()), + }, + }, + { + tag: 'form', + props: { + className: 'comment comment--input comment--reply', + id: 'comment-reply-' + comment.comment_id.toString(), + method: 'post', + action: 'javascript:;', + onsubmit: Misuzu.Comments.postCommentHandler, + }, + children: [ + { tag: 'input', props: { type: 'hidden', name: 'csrf', value: Misuzu.CSRF.getToken() } }, + { tag: 'input', props: { type: 'hidden', name: 'comment[category]', value: comment.category_id } }, + { tag: 'input', props: { type: 'hidden', name: 'comment[reply]', value: comment.comment_id } }, + { + props: { className: 'comment__container' }, + children: [ + { + props: { className: 'avatar comment__avatar' }, + children: { + tag: 'img', + props: { + className: 'avatar', + width: 40, + height: 40, + src: Misuzu.Urls.format('user-avatar', [{name: 'user', value: comment.user_id}, {name: 'res', value: 80}]), + }, + }, + }, + { + props: { className: 'comment__content' }, + children: [ + { props: { className: 'comment__info' } }, + { + tag: 'textarea', + props: { + className: 'comment__text input__textarea comment__text--input', + name: 'comment[text]', + placeholder: 'Share your extensive insights...', + onkeydown: Misuzu.Comments.inputCommentHandler, + }, + }, + { + props: { className: 'comment__actions' }, + children: { + tag: 'button', + props: { + className: 'input__button comment__action comment__action--button comment__action--post', + }, + children: 'Reply', + }, + }, + ], + }, + ], + }, + ], + }, + ], + }, + ], + }); + + timeago.render(commentTime); + + return commentElem; +}; \ No newline at end of file diff --git a/assets/js/misuzu/csrf.js b/assets/js/misuzu/csrf.js new file mode 100644 index 0000000..e022059 --- /dev/null +++ b/assets/js/misuzu/csrf.js @@ -0,0 +1,17 @@ +Misuzu.CSRF = {}; +Misuzu.CSRF.tokenValue = undefined; +Misuzu.CSRF.tokenElement = undefined; +Misuzu.CSRF.init = function() { + Misuzu.CSRF.tokenElement = document.querySelector('[name="csrf-token"]'); + Misuzu.CSRF.tokenValue = Misuzu.CSRF.tokenElement.getAttribute('value'); +}; +Misuzu.CSRF.getToken = function() { return Misuzu.CSRF.tokenValue || ''; }; +Misuzu.CSRF.setToken = function(token) { + if(!token) + return; + Misuzu.CSRF.tokenElement.setAttribute('value', Misuzu.CSRF.tokenValue = token); + + var elems = document.getElementsByName('csrf'); + for(var i = 0; i < elems.length; ++i) + elems[i].value = token; +}; diff --git a/assets/js/misuzu/events/_events.js b/assets/js/misuzu/events/_events.js new file mode 100644 index 0000000..9bfee0b --- /dev/null +++ b/assets/js/misuzu/events/_events.js @@ -0,0 +1,12 @@ +Misuzu.Events = {}; +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(); +}; diff --git a/assets/js/misuzu/events/christmas2019.js b/assets/js/misuzu/events/christmas2019.js new file mode 100644 index 0000000..92e9658 --- /dev/null +++ b/assets/js/misuzu/events/christmas2019.js @@ -0,0 +1,33 @@ +Misuzu.Events.Christmas2019 = function() { + this.propName = propName = 'msz-christmas-' + (new Date).getFullYear().toString(); +}; +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 = document.querySelector('.header__background'), + menuBgs = document.querySelectorAll('.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); +}; diff --git a/assets/js/misuzu/formutils.js b/assets/js/misuzu/formutils.js new file mode 100644 index 0000000..27e7f20 --- /dev/null +++ b/assets/js/misuzu/formutils.js @@ -0,0 +1,81 @@ +Misuzu.FormUtils = {}; +Misuzu.FormUtils.extractFormData = function(form, resetSource) { + var formData = new FormData; + + for(var i = 0; i < form.length; ++i) { + if(form[i].type.toLowerCase() === 'checkbox' && !form[i].checked) + continue; + formData.append(form[i].name, form[i].value || ''); + } + + if(resetSource) + Misuzu.FormUtils.resetFormData(form); + + return formData; +}; +Misuzu.FormUtils.resetFormData = function(form, defaults) { + defaults = defaults || []; + + for(var i = 0; i < form.length; ++i) { + var input = form[i]; + + switch(input.type.toLowerCase()) { + case 'checkbox': + input.checked = false; + break; + + case 'hidden': + var hiddenDefault = defaults.find(function(fhd) { return fhd.Name.toLowerCase() === input.name.toLowerCase(); }); + if(hiddenDefault) + input.value = hiddenDefault.Value; + break; + + default: + input.value = ''; + } + } +}; +Misuzu.FormUtils.initDataRequestMethod = function() { + var links = document.links; + + for(var i = 0; i < links.length; ++i) { + if(!links[i].href || !links[i].dataset || !links[i].dataset.mszMethod) + continue; + + links[i].addEventListener('click', function(ev) { + Misuzu.FormUtils.handleDataRequestMethod(this, this.dataset.mszMethod, this.href); + ev.preventDefault(); + }); + } +}; +Misuzu.FormUtils.handleDataRequestMethod = function(elem, method, url) { + var split = url.split('?', 2), + target = split[0], + query = split[1] || null; + + if(elem.getAttribute('disabled')) + return; + elem.setAttribute('disabled', 'disabled'); + + var xhr = new XMLHttpRequest; + xhr.onreadystatechange = function(ev) { + if(xhr.readyState !== 4) + return; + elem.removeAttribute('disabled'); + + if(xhr.status === 301 || xhr.status === 302 || xhr.status === 307 || xhr.status === 308) { + location.assign(xhr.getResponseHeader('X-Misuzu-Location')); + return; + } + + if(xhr.status >= 400 && xhr.status <= 599) { + alert(xhr.responseText); + return; + } + }; + xhr.open(method, target); + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + xhr.setRequestHeader('X-Misuzu-CSRF', Misuzu.CSRF.getToken()); + xhr.setRequestHeader('X-Misuzu-XHR', '1'); + xhr.send(query); +}; diff --git a/assets/js/misuzu/forum/_forum.js b/assets/js/misuzu/forum/_forum.js new file mode 100644 index 0000000..52d6f67 --- /dev/null +++ b/assets/js/misuzu/forum/_forum.js @@ -0,0 +1 @@ +Misuzu.Forum = {}; diff --git a/assets/js/misuzu/forum/editor.js b/assets/js/misuzu/forum/editor.js new file mode 100644 index 0000000..ff1f333 --- /dev/null +++ b/assets/js/misuzu/forum/editor.js @@ -0,0 +1,178 @@ +Misuzu.Forum.Editor = {}; +Misuzu.Forum.Editor.allowWindowClose = false; +Misuzu.Forum.Editor.init = function() { + var postingForm = document.querySelector('.js-forum-posting'); + if(!postingForm) + return; + + var 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 = document.querySelector('.forum__post__actions--bbcode'), + markdownButtons = document.querySelector('.forum__post__actions--markdown'), + markupButtons = document.querySelectorAll('.forum__post__action--tag'); + + // 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) { + postingText.insertTags(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; + } + + if(postParser === Misuzu.Parser.markdown) + postingPreview.classList.add('markdown'); + else + postingPreview.classList.remove('markdown'); + + lastPostParser = postParser; + postingPreview.innerHTML = text; + 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 = 'Back'; + 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; + } + + if(postParser === Misuzu.Parser.markdown) + postingPreview.classList.add('markdown'); + else + postingPreview.classList.remove('markdown'); + + lastPostText = postText; + lastPostParser = postParser; + postingPreview.innerHTML = text; + 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 = document.querySelector('.forum__post__actions--bbcode'), + markdownButtons = document.querySelector('.forum__post__actions--markdown'); + + switch(parser) { + default: + case Misuzu.Parser.plain: + bbcodeButtons.hidden = markdownButtons.hidden = true; + break; + case Misuzu.Parser.bbcode: + bbcodeButtons.hidden = false; + markdownButtons.hidden = true; + break; + case Misuzu.Parser.markdown: + bbcodeButtons.hidden = true; + markdownButtons.hidden = false; + break; + } +}; +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.'); + }); + xhr.open('POST', Misuzu.Urls.format('forum-topic-new')); + xhr.withCredentials = true; + xhr.send(formData); +}; diff --git a/assets/js/misuzu/forum/polls.js b/assets/js/misuzu/forum/polls.js new file mode 100644 index 0000000..3e4dd82 --- /dev/null +++ b/assets/js/misuzu/forum/polls.js @@ -0,0 +1,49 @@ +Misuzu.Forum.Polls = {}; +Misuzu.Forum.Polls.init = function() { + var polls = document.getElementsByClassName('js-forum-poll'); + if(!polls.length) + return; + for(var i = 0; i < polls.length; ++i) + Misuzu.Forum.Polls.initPoll(polls[i]); +}; +Misuzu.Forum.Polls.initPoll = function() { + var options = poll.getElementsByClassName('input__checkbox__input'), + votesRemaining = poll.querySelector('.js-forum-poll-remaining'), + votesRemainingCount = poll.querySelector('.js-forum-poll-remaining-count'), + votesRemainingPlural = poll.querySelector('.js-forum-poll-remaining-plural'), + maxVotes = parseInt(poll.dataset.pollMaxVotes); + + if(maxVotes < 2) + return; + + var votes = maxVotes; + + for(var i = 0; i < options.length; ++i) { + if(options[i].checked) { + if(votes < 1) + options[i].checked = false; + else + votes--; + } + + options[i].addEventListener('change', function(ev) { + if(this.checked) { + if(votes < 1) { + this.checked = false; + ev.preventDefault(); + return; + } + + votes--; + } else + votes++; + + votesRemainingCount.textContent = votes.toString(); + votesRemainingPlural.hidden = votes == 1; + }); + } + + votesRemaining.hidden = false; + votesRemainingCount.textContent = votes.toString(); + votesRemainingPlural.hidden = votes == 1; +}; diff --git a/assets/js/misuzu/perms.js b/assets/js/misuzu/perms.js new file mode 100644 index 0000000..b4a106b --- /dev/null +++ b/assets/js/misuzu/perms.js @@ -0,0 +1,15 @@ +Misuzu.Perms = function(perms) { + this.perms = perms || {}; +}; +Misuzu.Perms.prototype.perms = undefined; +Misuzu.Perms.check = function(section, value) { + return function() { return this.perms[section] && (this.perms[section] & value) > 0; }; +}; + +// Comment permissions +Misuzu.Perms.prototype.canCreateComment = Misuzu.Perms.check('comments', 0x01); +Misuzu.Perms.prototype.canDeleteOwnComment = Misuzu.Perms.check('comments', 0x08 | 0x10); +Misuzu.Perms.prototype.canDeleteAnyComment = Misuzu.Perms.check('comments', 0x10); +Misuzu.Perms.prototype.canLockCommentSection = Misuzu.Perms.check('comments', 0x20); +Misuzu.Perms.prototype.canPinComment = Misuzu.Perms.check('comments', 0x40); +Misuzu.Perms.prototype.canVoteOnComment = Misuzu.Perms.check('comments', 0x80); diff --git a/assets/js/misuzu/urls.js b/assets/js/misuzu/urls.js new file mode 100644 index 0000000..d911bb6 --- /dev/null +++ b/assets/js/misuzu/urls.js @@ -0,0 +1,66 @@ +Misuzu.Urls = {}; +Misuzu.Urls.registry = []; +Misuzu.Urls.loadFromDocument = function() { + var elem = document.getElementById('js-urls-list'); + if(!elem) + return; + Misuzu.Urls.registry = JSON.parse(elem.textContent); +}; +Misuzu.Urls.handleVariable = function(value, vars) { + if(value[0] === '<' && value.slice(-1) === '>') + return (vars.find(function(x) { return x.name == value.slice(1, -1); }) || {}).value || ''; + if(value[0] === '[' && value.slice(-1) === ']') + return ''; // not sure if there's a proper substitute for this, should probably resolve these in url_list + if(value[0] === '{' && value.slice(-1) === '}') + return Misuzu.CSRF.getToken(); + + // Allow file extensions + var split = value.split('.'), + extension = split[split.length - 1], + fileName = split.slice(0, -1).join('.'); + if(value !== fileName) { + var fallback = Misuzu.Urls.handleVariable(fileName, vars); + if(fallback !== fileName) + return fallback + '.' + extension; + } + + return value; +}; +Misuzu.Urls.v = function(name, value) { + if(typeof value === 'undefined' || value === null) + value = ''; + return { name: name.toString(), value: value.toString() }; +}; +Misuzu.Urls.format = function(name, vars) { + vars = vars || []; + var entry = Misuzu.Urls.registry.find(function(x) { return x.name == name; }); + if(!entry || !entry.path) + return ''; + + var split = entry.path.split('/'); + for(var i = 0; i < split.length; ++i) + split[i] = Misuzu.Urls.handleVariable(split[i], vars); + + var url = split.join('/'); + + if(entry.query) { + url += '?'; + + for(var i = 0; i < entry.query.length; ++i) { + var query = entry.query[i], + value = Misuzu.Urls.handleVariable(query.value, vars); + + if(!value || (query.name === 'page' && parseInt(value) < 2)) + continue; + + url += query.name + '=' + value.toString() + '&'; + } + + url = url.replace(/^[\?\&]+|[\?\&]+$/g, ''); + } + + if(entry.fragment) + url += ('#' + Misuzu.Urls.handleVariable(entry.fragment, vars)).replace(/[\#]+$/g, ''); + + return url; +}; \ No newline at end of file diff --git a/assets/js/misuzu/user.js b/assets/js/misuzu/user.js new file mode 100644 index 0000000..07247bb --- /dev/null +++ b/assets/js/misuzu/user.js @@ -0,0 +1,19 @@ +Misuzu.User = function(userInfo) { + this.id = parseInt(userInfo.user_id || 0); + this.name = (userInfo.username || '').toString(); + this.colour = new Misuzu.Colour(userInfo.user_colour || Misuzu.Colour.FLAG_INHERIT); + this.perms = new Misuzu.Perms(userInfo.perms || {}); +}; +Misuzu.User.localUser = undefined; +Misuzu.User.refreshLocalUser = function() { + var userInfo = document.getElementById('js-user-info'); + + if(!userInfo) + Misuzu.User.localUser = undefined; + else + Misuzu.User.localUser = new Misuzu.User(JSON.parse(userInfo.textContent)); +}; +Misuzu.User.isLoggedIn = function() { return Misuzu.User.localUser !== undefined; }; +Misuzu.User.prototype.getId = function() { return this.id || 0; }; +Misuzu.User.prototype.getUsername = function() { return this.name || ''; }; +Misuzu.User.prototype.getColour = function() { return this.colour || null; }; diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..d945994 --- /dev/null +++ b/composer.json @@ -0,0 +1,28 @@ +{ + "require": { + "twig/twig": "^3.0", + "erusev/parsedown": "~1.6", + "geoip2/geoip2": "~2.0", + "jublonet/codebird-php": "^3.1", + "chillerlan/php-qrcode": "^4.3", + "whichbrowser/parser": "^2.0", + "symfony/mailer": "^6.0" + }, + "autoload": { + "classmap": [ + "database" + ] + }, + "scripts": { + "post-install-cmd": [ + "php misuzu.php migrate", + "php misuzu.php cron low" + ] + }, + "config": { + "preferred-install": "dist", + "allow-plugins": { + "composer/installers": true + } + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..ca46250 --- /dev/null +++ b/composer.lock @@ -0,0 +1,1971 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "d3c39d122a38515484c9d439ecee240b", + "packages": [ + { + "name": "chillerlan/php-qrcode", + "version": "4.3.3", + "source": { + "type": "git", + "url": "https://github.com/chillerlan/php-qrcode.git", + "reference": "6356b246948ac1025882b3f55e7c68ebd4515ae3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/chillerlan/php-qrcode/zipball/6356b246948ac1025882b3f55e7c68ebd4515ae3", + "reference": "6356b246948ac1025882b3f55e7c68ebd4515ae3", + "shasum": "" + }, + "require": { + "chillerlan/php-settings-container": "^2.1", + "ext-mbstring": "*", + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phan/phan": "^5.3", + "phpunit/phpunit": "^9.5", + "setasign/fpdf": "^1.8.2" + }, + "suggest": { + "chillerlan/php-authenticator": "Yet another Google authenticator! Also creates URIs for mobile apps.", + "setasign/fpdf": "Required to use the QR FPDF output." + }, + "type": "library", + "autoload": { + "psr-4": { + "chillerlan\\QRCode\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kazuhiko Arase", + "homepage": "https://github.com/kazuhikoarase" + }, + { + "name": "Smiley", + "email": "smiley@chillerlan.net", + "homepage": "https://github.com/codemasher" + }, + { + "name": "Contributors", + "homepage": "https://github.com/chillerlan/php-qrcode/graphs/contributors" + } + ], + "description": "A QR code generator. PHP 7.4+", + "homepage": "https://github.com/chillerlan/php-qrcode", + "keywords": [ + "phpqrcode", + "qr", + "qr code", + "qrcode", + "qrcode-generator" + ], + "support": { + "issues": "https://github.com/chillerlan/php-qrcode/issues", + "source": "https://github.com/chillerlan/php-qrcode/tree/4.3.3" + }, + "funding": [ + { + "url": "https://www.paypal.com/donate?hosted_button_id=WLYUNAT9ZTJZ4", + "type": "custom" + }, + { + "url": "https://ko-fi.com/codemasher", + "type": "ko_fi" + } + ], + "time": "2021-11-25T22:38:09+00:00" + }, + { + "name": "chillerlan/php-settings-container", + "version": "2.1.2", + "source": { + "type": "git", + "url": "https://github.com/chillerlan/php-settings-container.git", + "reference": "ec834493a88682dd69652a1eeaf462789ed0c5f5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/chillerlan/php-settings-container/zipball/ec834493a88682dd69652a1eeaf462789ed0c5f5", + "reference": "ec834493a88682dd69652a1eeaf462789ed0c5f5", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phan/phan": "^4.0", + "phpunit/phpunit": "^9.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "chillerlan\\Settings\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Smiley", + "email": "smiley@chillerlan.net", + "homepage": "https://github.com/codemasher" + } + ], + "description": "A container class for immutable settings objects. Not a DI container. PHP 7.4+", + "homepage": "https://github.com/chillerlan/php-settings-container", + "keywords": [ + "PHP7", + "Settings", + "container", + "helper" + ], + "support": { + "issues": "https://github.com/chillerlan/php-settings-container/issues", + "source": "https://github.com/chillerlan/php-settings-container" + }, + "funding": [ + { + "url": "https://www.paypal.com/donate?hosted_button_id=WLYUNAT9ZTJZ4", + "type": "custom" + }, + { + "url": "https://ko-fi.com/codemasher", + "type": "ko_fi" + } + ], + "time": "2021-09-06T15:17:01+00:00" + }, + { + "name": "composer/ca-bundle", + "version": "1.3.1", + "source": { + "type": "git", + "url": "https://github.com/composer/ca-bundle.git", + "reference": "4c679186f2aca4ab6a0f1b0b9cf9252decb44d0b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/ca-bundle/zipball/4c679186f2aca4ab6a0f1b0b9cf9252decb44d0b", + "reference": "4c679186f2aca4ab6a0f1b0b9cf9252decb44d0b", + "shasum": "" + }, + "require": { + "ext-openssl": "*", + "ext-pcre": "*", + "php": "^5.3.2 || ^7.0 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^0.12.55", + "psr/log": "^1.0", + "symfony/phpunit-bridge": "^4.2 || ^5", + "symfony/process": "^2.5 || ^3.0 || ^4.0 || ^5.0 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\CaBundle\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.", + "keywords": [ + "cabundle", + "cacert", + "certificate", + "ssl", + "tls" + ], + "support": { + "irc": "irc://irc.freenode.org/composer", + "issues": "https://github.com/composer/ca-bundle/issues", + "source": "https://github.com/composer/ca-bundle/tree/1.3.1" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2021-10-28T20:44:15+00:00" + }, + { + "name": "composer/installers", + "version": "v1.12.0", + "source": { + "type": "git", + "url": "https://github.com/composer/installers.git", + "reference": "d20a64ed3c94748397ff5973488761b22f6d3f19" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/installers/zipball/d20a64ed3c94748397ff5973488761b22f6d3f19", + "reference": "d20a64ed3c94748397ff5973488761b22f6d3f19", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0" + }, + "replace": { + "roundcube/plugin-installer": "*", + "shama/baton": "*" + }, + "require-dev": { + "composer/composer": "1.6.* || ^2.0", + "composer/semver": "^1 || ^3", + "phpstan/phpstan": "^0.12.55", + "phpstan/phpstan-phpunit": "^0.12.16", + "symfony/phpunit-bridge": "^4.2 || ^5", + "symfony/process": "^2.3" + }, + "type": "composer-plugin", + "extra": { + "class": "Composer\\Installers\\Plugin", + "branch-alias": { + "dev-main": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Installers\\": "src/Composer/Installers" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kyle Robinson Young", + "email": "kyle@dontkry.com", + "homepage": "https://github.com/shama" + } + ], + "description": "A multi-framework Composer library installer", + "homepage": "https://composer.github.io/installers/", + "keywords": [ + "Craft", + "Dolibarr", + "Eliasis", + "Hurad", + "ImageCMS", + "Kanboard", + "Lan Management System", + "MODX Evo", + "MantisBT", + "Mautic", + "Maya", + "OXID", + "Plentymarkets", + "Porto", + "RadPHP", + "SMF", + "Starbug", + "Thelia", + "Whmcs", + "WolfCMS", + "agl", + "aimeos", + "annotatecms", + "attogram", + "bitrix", + "cakephp", + "chef", + "cockpit", + "codeigniter", + "concrete5", + "croogo", + "dokuwiki", + "drupal", + "eZ Platform", + "elgg", + "expressionengine", + "fuelphp", + "grav", + "installer", + "itop", + "joomla", + "known", + "kohana", + "laravel", + "lavalite", + "lithium", + "magento", + "majima", + "mako", + "mediawiki", + "miaoxing", + "modulework", + "modx", + "moodle", + "osclass", + "pantheon", + "phpbb", + "piwik", + "ppi", + "processwire", + "puppet", + "pxcms", + "reindex", + "roundcube", + "shopware", + "silverstripe", + "sydes", + "sylius", + "symfony", + "tastyigniter", + "typo3", + "wordpress", + "yawik", + "zend", + "zikula" + ], + "support": { + "issues": "https://github.com/composer/installers/issues", + "source": "https://github.com/composer/installers/tree/v1.12.0" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2021-09-13T08:19:44+00:00" + }, + { + "name": "doctrine/lexer", + "version": "1.2.3", + "source": { + "type": "git", + "url": "https://github.com/doctrine/lexer.git", + "reference": "c268e882d4dbdd85e36e4ad69e02dc284f89d229" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/c268e882d4dbdd85e36e4ad69e02dc284f89d229", + "reference": "c268e882d4dbdd85e36e4ad69e02dc284f89d229", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "doctrine/coding-standard": "^9.0", + "phpstan/phpstan": "^1.3", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "vimeo/psalm": "^4.11" + }, + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\Common\\Lexer\\": "lib/Doctrine/Common/Lexer" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.", + "homepage": "https://www.doctrine-project.org/projects/lexer.html", + "keywords": [ + "annotations", + "docblock", + "lexer", + "parser", + "php" + ], + "support": { + "issues": "https://github.com/doctrine/lexer/issues", + "source": "https://github.com/doctrine/lexer/tree/1.2.3" + }, + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Flexer", + "type": "tidelift" + } + ], + "time": "2022-02-28T11:07:21+00:00" + }, + { + "name": "egulias/email-validator", + "version": "3.1.2", + "source": { + "type": "git", + "url": "https://github.com/egulias/EmailValidator.git", + "reference": "ee0db30118f661fb166bcffbf5d82032df484697" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/ee0db30118f661fb166bcffbf5d82032df484697", + "reference": "ee0db30118f661fb166bcffbf5d82032df484697", + "shasum": "" + }, + "require": { + "doctrine/lexer": "^1.2", + "php": ">=7.2", + "symfony/polyfill-intl-idn": "^1.15" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.2", + "phpunit/phpunit": "^8.5.8|^9.3.3", + "vimeo/psalm": "^4" + }, + "suggest": { + "ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Egulias\\EmailValidator\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Eduardo Gulias Davis" + } + ], + "description": "A library for validating emails against several RFCs", + "homepage": "https://github.com/egulias/EmailValidator", + "keywords": [ + "email", + "emailvalidation", + "emailvalidator", + "validation", + "validator" + ], + "support": { + "issues": "https://github.com/egulias/EmailValidator/issues", + "source": "https://github.com/egulias/EmailValidator/tree/3.1.2" + }, + "funding": [ + { + "url": "https://github.com/egulias", + "type": "github" + } + ], + "time": "2021-10-11T09:18:27+00:00" + }, + { + "name": "erusev/parsedown", + "version": "1.7.4", + "source": { + "type": "git", + "url": "https://github.com/erusev/parsedown.git", + "reference": "cb17b6477dfff935958ba01325f2e8a2bfa6dab3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/erusev/parsedown/zipball/cb17b6477dfff935958ba01325f2e8a2bfa6dab3", + "reference": "cb17b6477dfff935958ba01325f2e8a2bfa6dab3", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35" + }, + "type": "library", + "autoload": { + "psr-0": { + "Parsedown": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Emanuil Rusev", + "email": "hello@erusev.com", + "homepage": "http://erusev.com" + } + ], + "description": "Parser for Markdown.", + "homepage": "http://parsedown.org", + "keywords": [ + "markdown", + "parser" + ], + "support": { + "issues": "https://github.com/erusev/parsedown/issues", + "source": "https://github.com/erusev/parsedown/tree/1.7.x" + }, + "time": "2019-12-30T22:54:17+00:00" + }, + { + "name": "geoip2/geoip2", + "version": "v2.12.2", + "source": { + "type": "git", + "url": "https://github.com/maxmind/GeoIP2-php.git", + "reference": "83adb44ac4b9553d36b579a14673ed124583082f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/GeoIP2-php/zipball/83adb44ac4b9553d36b579a14673ed124583082f", + "reference": "83adb44ac4b9553d36b579a14673ed124583082f", + "shasum": "" + }, + "require": { + "ext-json": "*", + "maxmind-db/reader": "~1.8", + "maxmind/web-service-common": "~0.8", + "php": ">=7.2" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "3.*", + "phpstan/phpstan": "*", + "phpunit/phpunit": "^8.0 || ^9.0", + "squizlabs/php_codesniffer": "3.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "GeoIp2\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Gregory J. Oschwald", + "email": "goschwald@maxmind.com", + "homepage": "https://www.maxmind.com/" + } + ], + "description": "MaxMind GeoIP2 PHP API", + "homepage": "https://github.com/maxmind/GeoIP2-php", + "keywords": [ + "IP", + "geoip", + "geoip2", + "geolocation", + "maxmind" + ], + "support": { + "issues": "https://github.com/maxmind/GeoIP2-php/issues", + "source": "https://github.com/maxmind/GeoIP2-php/tree/v2.12.2" + }, + "time": "2021-11-30T18:15:25+00:00" + }, + { + "name": "jublonet/codebird-php", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/jublo/codebird-php.git", + "reference": "100a8e8f1928a5738b4476f0caf83f2c2ba6da5b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jublo/codebird-php/zipball/100a8e8f1928a5738b4476f0caf83f2c2ba6da5b", + "reference": "100a8e8f1928a5738b4476f0caf83f2c2ba6da5b", + "shasum": "" + }, + "require": { + "composer/installers": "~1.0", + "ext-hash": "*", + "ext-json": "*", + "lib-openssl": "*", + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": ">=3.7", + "satooshi/php-coveralls": ">=0.6", + "squizlabs/php_codesniffer": "2.*" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-3.0+" + ], + "authors": [ + { + "name": "Joshua Atkins", + "email": "joshua.atkins@jublo.net", + "homepage": "http://atkins.im/", + "role": "Developer" + }, + { + "name": "J.M.", + "email": "jm@jublo.net", + "homepage": "http://mynetx.net/", + "role": "Developer" + } + ], + "description": "Easy access to the Twitter REST API, Collections API, Streaming API, TON (Object Nest) API and Twitter Ads API — all from one PHP library.", + "homepage": "https://www.jublo.net/projects/codebird/php", + "keywords": [ + "api", + "networking", + "twitter" + ], + "support": { + "email": "support@jublo.net", + "issues": "https://github.com/jublonet/codebird-php/issues", + "source": "https://github.com/jublonet/codebird-php/releases" + }, + "time": "2016-02-15T18:38:55+00:00" + }, + { + "name": "maxmind-db/reader", + "version": "v1.11.0", + "source": { + "type": "git", + "url": "https://github.com/maxmind/MaxMind-DB-Reader-php.git", + "reference": "b1f3c0699525336d09cc5161a2861268d9f2ae5b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/MaxMind-DB-Reader-php/zipball/b1f3c0699525336d09cc5161a2861268d9f2ae5b", + "reference": "b1f3c0699525336d09cc5161a2861268d9f2ae5b", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "conflict": { + "ext-maxminddb": "<1.10.1,>=2.0.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "3.*", + "php-coveralls/php-coveralls": "^2.1", + "phpstan/phpstan": "*", + "phpunit/phpcov": ">=6.0.0", + "phpunit/phpunit": ">=8.0.0,<10.0.0", + "squizlabs/php_codesniffer": "3.*" + }, + "suggest": { + "ext-bcmath": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder", + "ext-gmp": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder", + "ext-maxminddb": "A C-based database decoder that provides significantly faster lookups" + }, + "type": "library", + "autoload": { + "psr-4": { + "MaxMind\\Db\\": "src/MaxMind/Db" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Gregory J. Oschwald", + "email": "goschwald@maxmind.com", + "homepage": "https://www.maxmind.com/" + } + ], + "description": "MaxMind DB Reader API", + "homepage": "https://github.com/maxmind/MaxMind-DB-Reader-php", + "keywords": [ + "database", + "geoip", + "geoip2", + "geolocation", + "maxmind" + ], + "support": { + "issues": "https://github.com/maxmind/MaxMind-DB-Reader-php/issues", + "source": "https://github.com/maxmind/MaxMind-DB-Reader-php/tree/v1.11.0" + }, + "time": "2021-10-18T15:23:10+00:00" + }, + { + "name": "maxmind/web-service-common", + "version": "v0.8.1", + "source": { + "type": "git", + "url": "https://github.com/maxmind/web-service-common-php.git", + "reference": "32f274051c543fc865e5a84d3a2c703913641ea8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/web-service-common-php/zipball/32f274051c543fc865e5a84d3a2c703913641ea8", + "reference": "32f274051c543fc865e5a84d3a2c703913641ea8", + "shasum": "" + }, + "require": { + "composer/ca-bundle": "^1.0.3", + "ext-curl": "*", + "ext-json": "*", + "php": ">=7.2" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "2.*", + "phpunit/phpunit": "^8.0 || ^9.0", + "squizlabs/php_codesniffer": "3.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "MaxMind\\Exception\\": "src/Exception", + "MaxMind\\WebService\\": "src/WebService" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Gregory Oschwald", + "email": "goschwald@maxmind.com" + } + ], + "description": "Internal MaxMind Web Service API", + "homepage": "https://github.com/maxmind/web-service-common-php", + "support": { + "issues": "https://github.com/maxmind/web-service-common-php/issues", + "source": "https://github.com/maxmind/web-service-common-php/tree/v0.8.1" + }, + "time": "2020-11-02T17:00:53+00:00" + }, + { + "name": "psr/cache", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/cache.git", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Cache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for caching libraries", + "keywords": [ + "cache", + "psr", + "psr-6" + ], + "support": { + "source": "https://github.com/php-fig/cache/tree/master" + }, + "time": "2016-08-06T20:24:11+00:00" + }, + { + "name": "psr/container", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "shasum": "" + }, + "require": { + "php": ">=7.4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "support": { + "issues": "https://github.com/php-fig/container/issues", + "source": "https://github.com/php-fig/container/tree/2.0.2" + }, + "time": "2021-11-05T16:47:00+00:00" + }, + { + "name": "psr/event-dispatcher", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/event-dispatcher.git", + "reference": "dbefd12671e8a14ec7f180cab83036ed26714bb0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/event-dispatcher/zipball/dbefd12671e8a14ec7f180cab83036ed26714bb0", + "reference": "dbefd12671e8a14ec7f180cab83036ed26714bb0", + "shasum": "" + }, + "require": { + "php": ">=7.2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\EventDispatcher\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Standard interfaces for event handling.", + "keywords": [ + "events", + "psr", + "psr-14" + ], + "support": { + "issues": "https://github.com/php-fig/event-dispatcher/issues", + "source": "https://github.com/php-fig/event-dispatcher/tree/1.0.0" + }, + "time": "2019-01-08T18:20:26+00:00" + }, + { + "name": "psr/log", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/fe5ea303b0887d5caefd3d431c3e61ad47037001", + "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001", + "shasum": "" + }, + "require": { + "php": ">=8.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "support": { + "source": "https://github.com/php-fig/log/tree/3.0.0" + }, + "time": "2021-07-14T16:46:02+00:00" + }, + { + "name": "symfony/event-dispatcher", + "version": "v6.0.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "6472ea2dd415e925b90ca82be64b8bc6157f3934" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/6472ea2dd415e925b90ca82be64b8bc6157f3934", + "reference": "6472ea2dd415e925b90ca82be64b8bc6157f3934", + "shasum": "" + }, + "require": { + "php": ">=8.0.2", + "symfony/event-dispatcher-contracts": "^2|^3" + }, + "conflict": { + "symfony/dependency-injection": "<5.4" + }, + "provide": { + "psr/event-dispatcher-implementation": "1.0", + "symfony/event-dispatcher-implementation": "2.0|3.0" + }, + "require-dev": { + "psr/log": "^1|^2|^3", + "symfony/config": "^5.4|^6.0", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/error-handler": "^5.4|^6.0", + "symfony/expression-language": "^5.4|^6.0", + "symfony/http-foundation": "^5.4|^6.0", + "symfony/service-contracts": "^1.1|^2|^3", + "symfony/stopwatch": "^5.4|^6.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/event-dispatcher/tree/v6.0.3" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-01-02T09:55:41+00:00" + }, + { + "name": "symfony/event-dispatcher-contracts", + "version": "v3.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher-contracts.git", + "reference": "aa5422287b75594b90ee9cd807caf8f0df491385" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/aa5422287b75594b90ee9cd807caf8f0df491385", + "reference": "aa5422287b75594b90ee9cd807caf8f0df491385", + "shasum": "" + }, + "require": { + "php": ">=8.0.2", + "psr/event-dispatcher": "^1" + }, + "suggest": { + "symfony/event-dispatcher-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\EventDispatcher\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to dispatching event", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "support": { + "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.0.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-07-15T12:33:35+00:00" + }, + { + "name": "symfony/mailer", + "version": "v6.0.5", + "source": { + "type": "git", + "url": "https://github.com/symfony/mailer.git", + "reference": "0f4772db6521a1beb44529aa2c0c1e56f671be8f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/mailer/zipball/0f4772db6521a1beb44529aa2c0c1e56f671be8f", + "reference": "0f4772db6521a1beb44529aa2c0c1e56f671be8f", + "shasum": "" + }, + "require": { + "egulias/email-validator": "^2.1.10|^3", + "php": ">=8.0.2", + "psr/event-dispatcher": "^1", + "psr/log": "^1|^2|^3", + "symfony/event-dispatcher": "^5.4|^6.0", + "symfony/mime": "^5.4|^6.0", + "symfony/service-contracts": "^1.1|^2|^3" + }, + "conflict": { + "symfony/http-kernel": "<5.4" + }, + "require-dev": { + "symfony/http-client-contracts": "^1.1|^2|^3", + "symfony/messenger": "^5.4|^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Mailer\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Helps sending emails", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/mailer/tree/v6.0.5" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-02-25T10:48:52+00:00" + }, + { + "name": "symfony/mime", + "version": "v6.0.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/mime.git", + "reference": "2cd9601efd040e56f43360daa68f3c6b0534923a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/mime/zipball/2cd9601efd040e56f43360daa68f3c6b0534923a", + "reference": "2cd9601efd040e56f43360daa68f3c6b0534923a", + "shasum": "" + }, + "require": { + "php": ">=8.0.2", + "symfony/polyfill-intl-idn": "^1.10", + "symfony/polyfill-mbstring": "^1.0" + }, + "conflict": { + "egulias/email-validator": "~3.0.0", + "phpdocumentor/reflection-docblock": "<3.2.2", + "phpdocumentor/type-resolver": "<1.4.0", + "symfony/mailer": "<5.4" + }, + "require-dev": { + "egulias/email-validator": "^2.1.10|^3.1", + "phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/property-access": "^5.4|^6.0", + "symfony/property-info": "^5.4|^6.0", + "symfony/serializer": "^5.4|^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Mime\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Allows manipulating MIME messages", + "homepage": "https://symfony.com", + "keywords": [ + "mime", + "mime-type" + ], + "support": { + "source": "https://github.com/symfony/mime/tree/v6.0.3" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-01-02T09:55:41+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.24.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "30885182c981ab175d4d034db0f6f469898070ab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/30885182c981ab175d4d034db0f6f469898070ab", + "reference": "30885182c981ab175d4d034db0f6f469898070ab", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "provide": { + "ext-ctype": "*" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "support": { + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.24.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-10-20T20:35:02+00:00" + }, + { + "name": "symfony/polyfill-intl-idn", + "version": "v1.24.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-idn.git", + "reference": "749045c69efb97c70d25d7463abba812e91f3a44" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/749045c69efb97c70d25d7463abba812e91f3a44", + "reference": "749045c69efb97c70d25d7463abba812e91f3a44", + "shasum": "" + }, + "require": { + "php": ">=7.1", + "symfony/polyfill-intl-normalizer": "^1.10", + "symfony/polyfill-php72": "^1.10" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Intl\\Idn\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Laurent Bassin", + "email": "laurent@bassin.info" + }, + { + "name": "Trevor Rowbotham", + "email": "trevor.rowbotham@pm.me" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "idn", + "intl", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.24.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-09-14T14:02:44+00:00" + }, + { + "name": "symfony/polyfill-intl-normalizer", + "version": "v1.24.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-normalizer.git", + "reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8590a5f561694770bdcd3f9b5c69dde6945028e8", + "reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Intl\\Normalizer\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's Normalizer class and related functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "intl", + "normalizer", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.24.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-02-19T12:13:01+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.24.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/0abb51d2f102e00a4eefcf46ba7fec406d245825", + "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "provide": { + "ext-mbstring": "*" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.24.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-11-30T18:21:41+00:00" + }, + { + "name": "symfony/polyfill-php72", + "version": "v1.24.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php72.git", + "reference": "9a142215a36a3888e30d0a9eeea9766764e96976" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/9a142215a36a3888e30d0a9eeea9766764e96976", + "reference": "9a142215a36a3888e30d0a9eeea9766764e96976", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Php72\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php72/tree/v1.24.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-05-27T09:17:38+00:00" + }, + { + "name": "symfony/service-contracts", + "version": "v3.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/service-contracts.git", + "reference": "36715ebf9fb9db73db0cb24263c79077c6fe8603" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/36715ebf9fb9db73db0cb24263c79077c6fe8603", + "reference": "36715ebf9fb9db73db0cb24263c79077c6fe8603", + "shasum": "" + }, + "require": { + "php": ">=8.0.2", + "psr/container": "^2.0" + }, + "conflict": { + "ext-psr": "<1.1|>=2" + }, + "suggest": { + "symfony/service-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\Service\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to writing services", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "support": { + "source": "https://github.com/symfony/service-contracts/tree/v3.0.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-11-04T17:53:12+00:00" + }, + { + "name": "twig/twig", + "version": "v3.3.8", + "source": { + "type": "git", + "url": "https://github.com/twigphp/Twig.git", + "reference": "972d8604a92b7054828b539f2febb0211dd5945c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/972d8604a92b7054828b539f2febb0211dd5945c", + "reference": "972d8604a92b7054828b539f2febb0211dd5945c", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/polyfill-ctype": "^1.8", + "symfony/polyfill-mbstring": "^1.3" + }, + "require-dev": { + "psr/container": "^1.0", + "symfony/phpunit-bridge": "^4.4.9|^5.0.9|^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Twig\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Twig Team", + "role": "Contributors" + }, + { + "name": "Armin Ronacher", + "email": "armin.ronacher@active-4.com", + "role": "Project Founder" + } + ], + "description": "Twig, the flexible, fast, and secure template language for PHP", + "homepage": "https://twig.symfony.com", + "keywords": [ + "templating" + ], + "support": { + "issues": "https://github.com/twigphp/Twig/issues", + "source": "https://github.com/twigphp/Twig/tree/v3.3.8" + }, + "funding": [ + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/twig/twig", + "type": "tidelift" + } + ], + "time": "2022-02-04T06:59:48+00:00" + }, + { + "name": "whichbrowser/parser", + "version": "v2.1.2", + "source": { + "type": "git", + "url": "https://github.com/WhichBrowser/Parser-PHP.git", + "reference": "bcf642a1891032de16a5ab976fd352753dd7f9a0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WhichBrowser/Parser-PHP/zipball/bcf642a1891032de16a5ab976fd352753dd7f9a0", + "reference": "bcf642a1891032de16a5ab976fd352753dd7f9a0", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/cache": "^1.0" + }, + "require-dev": { + "cache/array-adapter": "^1.1", + "icomefromthenet/reverse-regex": "0.0.6.3", + "php-coveralls/php-coveralls": "^2.0", + "phpunit/php-code-coverage": "^5.0 || ^7.0", + "phpunit/phpunit": "^6.0 || ^8.0", + "squizlabs/php_codesniffer": "^3.5", + "symfony/yaml": "~3.4 || ~4.0" + }, + "suggest": { + "cache/array-adapter": "Allows testing of the caching functionality" + }, + "type": "library", + "autoload": { + "psr-4": { + "WhichBrowser\\": [ + "src/", + "tests/src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Niels Leenheer", + "email": "niels@leenheer.nl", + "role": "Developer" + } + ], + "description": "Useragent sniffing library for PHP", + "homepage": "http://whichbrowser.net", + "keywords": [ + "browser", + "sniffing", + "ua", + "useragent" + ], + "support": { + "issues": "https://github.com/WhichBrowser/Parser-PHP/issues", + "source": "https://github.com/WhichBrowser/Parser-PHP/tree/v2.1.2" + }, + "time": "2021-05-10T10:18:11+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.2.0" +} diff --git a/config/config.example.ini b/config/config.example.ini new file mode 100644 index 0000000..bf3bf81 --- /dev/null +++ b/config/config.example.ini @@ -0,0 +1,10 @@ +; Example configuration for Misuzu + +[Database] +driver = mysql +host = localhost +port = 3306 +username = username +password = password +dbname = database +charset = utf8mb4 diff --git a/config/emails/email-change.txt b/config/emails/email-change.txt new file mode 100644 index 0000000..26eff16 --- /dev/null +++ b/config/emails/email-change.txt @@ -0,0 +1,7 @@ +Flashii.net E-mail Change + +Hey %username%, + +The e-mail address associated with your account has been changed from %email_previous% to %email_new% from IP address %ip_address%. + +If you didn't do this yourself please contact us immediately . diff --git a/config/emails/password-change.txt b/config/emails/password-change.txt new file mode 100644 index 0000000..4cbc6ea --- /dev/null +++ b/config/emails/password-change.txt @@ -0,0 +1,7 @@ +Flashii.net Password Change + +Hey %username%, + +Your password has been changed from IP address %ip_address%. + +If you didn't do this yourself please contact us immediately . diff --git a/config/emails/password-recovery.txt b/config/emails/password-recovery.txt new file mode 100644 index 0000000..75345ea --- /dev/null +++ b/config/emails/password-recovery.txt @@ -0,0 +1,7 @@ +Flashii.net Password Recovery + +Hey %username%, + +You, or someone pretending to be you, has requested a password reset for your account. + +Your verification code is: %token% diff --git a/config/github.example.ini b/config/github.example.ini new file mode 100644 index 0000000..0580278 --- /dev/null +++ b/config/github.example.ini @@ -0,0 +1,9 @@ +[tokens] +token[flashwave/misuzu] = token-here + +[addresses] +github@flash.moe = 1 + +[repo:flashwave/misuzu] +tags[] = 1 +tags[] = 3 diff --git a/database/2019_05_01_200400_initial_structure.php b/database/2019_05_01_200400_initial_structure.php new file mode 100644 index 0000000..bfc9068 --- /dev/null +++ b/database/2019_05_01_200400_initial_structure.php @@ -0,0 +1,704 @@ +prepare("SELECT COUNT(*) FROM `msz_migrations`"); + $migrations = (int)($getMigrations->execute() ? $getMigrations->fetchColumn() : 0); + + if($migrations > 0) { + $conn->exec("TRUNCATE `msz_migrations`"); + return; + } + + $conn->exec(" + CREATE TABLE `msz_ip_blacklist` ( + `ip_subnet` VARBINARY(16) NOT NULL, + `ip_mask` TINYINT(3) UNSIGNED NOT NULL, + UNIQUE INDEX `ip_blacklist_unique` (`ip_subnet`, `ip_mask`) + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_roles` ( + `role_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `role_hierarchy` INT(11) NOT NULL DEFAULT '1', + `role_name` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `role_title` VARCHAR(64) NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `role_description` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `role_hidden` TINYINT(1) NOT NULL DEFAULT '0', + `role_can_leave` TINYINT(1) NOT NULL DEFAULT '0', + `role_colour` INT(11) NULL DEFAULT NULL, + `role_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`role_id`) + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_users` ( + `user_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `username` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `password` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `email` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `register_ip` VARBINARY(16) NOT NULL, + `last_ip` VARBINARY(16) NOT NULL, + `user_super` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0', + `user_country` CHAR(2) NOT NULL DEFAULT 'XX' COLLATE 'utf8mb4_bin', + `user_colour` INT(11) NULL DEFAULT NULL, + `user_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `user_active` TIMESTAMP NULL DEFAULT NULL, + `user_deleted` TIMESTAMP NULL DEFAULT NULL, + `display_role` INT(10) UNSIGNED NULL DEFAULT NULL, + `user_totp_key` CHAR(26) NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `user_about_content` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `user_about_parser` TINYINT(4) NOT NULL DEFAULT '0', + `user_signature_content` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `user_signature_parser` TINYINT(4) NOT NULL DEFAULT '0', + `user_birthdate` DATE NULL DEFAULT NULL, + `user_background_settings` TINYINT(4) NULL DEFAULT '0', + `user_website` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_twitter` VARCHAR(20) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_github` VARCHAR(40) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_skype` VARCHAR(60) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_discord` VARCHAR(40) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_youtube` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_steam` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_ninswitch` VARCHAR(14) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_twitchtv` VARCHAR(30) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_osu` VARCHAR(20) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_lastfm` VARCHAR(20) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_title` VARCHAR(64) NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + PRIMARY KEY (`user_id`), + UNIQUE INDEX `users_username_unique` (`username`), + UNIQUE INDEX `users_email_unique` (`email`), + INDEX `users_display_role_foreign` (`display_role`), + INDEX `users_indices` ( + `user_country`, `user_created`, `user_active`, + `user_deleted`, `user_birthdate` + ), + CONSTRAINT `users_display_role_foreign` + FOREIGN KEY (`display_role`) + REFERENCES `msz_roles` (`role_id`) + ON UPDATE CASCADE + ON DELETE SET NULL + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_user_roles` ( + `user_id` INT(10) UNSIGNED NOT NULL, + `role_id` INT(10) UNSIGNED NOT NULL, + UNIQUE INDEX `user_roles_unique` (`user_id`, `role_id`), + INDEX `user_roles_role_id_foreign` (`role_id`), + CONSTRAINT `user_roles_role_id_foreign` + FOREIGN KEY (`role_id`) + REFERENCES `msz_roles` (`role_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `user_roles_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_users_password_resets` ( + `user_id` INT(10) UNSIGNED NOT NULL, + `reset_ip` VARBINARY(16) NOT NULL, + `reset_requested` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `verification_code` CHAR(12) NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + UNIQUE INDEX `msz_users_password_resets_unique` (`user_id`, `reset_ip`), + INDEX `msz_users_password_resets_index` (`reset_requested`), + CONSTRAINT `msz_users_password_resets_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_user_relations` ( + `user_id` INT(10) UNSIGNED NOT NULL, + `subject_id` INT(10) UNSIGNED NOT NULL, + `relation_type` TINYINT(3) UNSIGNED NOT NULL, + `relation_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + UNIQUE INDEX `user_relations_unique` (`user_id`, `subject_id`), + INDEX `user_relations_subject_id_foreign` (`subject_id`), + CONSTRAINT `user_relations_subject_id_foreign` + FOREIGN KEY (`subject_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `user_relations_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_user_warnings` ( + `warning_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `user_id` INT(10) UNSIGNED NOT NULL, + `user_ip` VARBINARY(16) NOT NULL, + `issuer_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `issuer_ip` VARBINARY(16) NOT NULL, + `warning_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `warning_duration` TIMESTAMP NULL DEFAULT NULL, + `warning_type` TINYINT(3) UNSIGNED NOT NULL, + `warning_note` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `warning_note_private` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + PRIMARY KEY (`warning_id`), + INDEX `user_warnings_user_foreign` (`user_id`), + INDEX `user_warnings_issuer_foreign` (`issuer_id`), + INDEX `user_warnings_created_index` (`warning_created`), + INDEX `user_warnings_duration_index` (`warning_duration`), + INDEX `user_warnings_type_index` (`warning_type`), + INDEX `user_warnings_user_ip_index` (`user_ip`), + CONSTRAINT `user_warnings_issuer_foreign` + FOREIGN KEY (`issuer_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE SET NULL, + CONSTRAINT `user_warnings_user_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_sessions` ( + `session_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `user_id` INT(10) UNSIGNED NOT NULL, + `session_key` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `session_ip` VARBINARY(16) NOT NULL, + `session_ip_last` VARBINARY(16) NULL DEFAULT NULL, + `session_user_agent` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `session_country` CHAR(2) NOT NULL DEFAULT 'XX' COLLATE 'utf8mb4_bin', + `session_expires` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `session_expires_bump` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1', + `session_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `session_active` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`session_id`), + UNIQUE INDEX `sessions_key_unique` (`session_key`), + INDEX `sessions_user_id_foreign` (`user_id`), + INDEX `sessions_expires_index` (`session_expires`), + CONSTRAINT `sessions_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_permissions` ( + `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `role_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `general_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `general_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `user_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `user_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `changelog_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `changelog_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `news_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `news_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `forum_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `forum_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `comments_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `comments_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0', + UNIQUE INDEX `permissions_user_id_unique` (`user_id`), + UNIQUE INDEX `permissions_role_id_unique` (`role_id`), + CONSTRAINT `permissions_role_id_foreign` + FOREIGN KEY (`role_id`) + REFERENCES `msz_roles` (`role_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `permissions_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_audit_log` ( + `log_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `log_action` VARCHAR(50) NOT NULL COLLATE 'utf8mb4_bin', + `log_params` TEXT NOT NULL COLLATE 'utf8mb4_bin', + `log_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `log_ip` VARBINARY(16) NULL DEFAULT NULL, + `log_country` CHAR(2) NOT NULL DEFAULT 'XX' COLLATE 'utf8mb4_bin', + PRIMARY KEY (`log_id`), + INDEX `audit_log_user_id_foreign` (`user_id`), + CONSTRAINT `audit_log_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_auth_tfa` ( + `user_id` INT(10) UNSIGNED NOT NULL, + `tfa_token` CHAR(32) NOT NULL COLLATE 'utf8mb4_bin', + `tfa_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + UNIQUE INDEX `auth_tfa_token_unique` (`tfa_token`), + INDEX `auth_tfa_user_foreign` (`user_id`), + INDEX `auth_tfa_created_index` (`tfa_created`), + CONSTRAINT `auth_tfa_user_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_login_attempts` ( + `attempt_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `attempt_success` TINYINT(1) NOT NULL, + `attempt_ip` VARBINARY(16) NOT NULL, + `attempt_country` CHAR(2) NOT NULL DEFAULT 'XX' COLLATE 'utf8mb4_bin', + `attempt_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `attempt_user_agent` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + PRIMARY KEY (`attempt_id`), + INDEX `login_attempts_user_id_foreign` (`user_id`), + CONSTRAINT `login_attempts_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE SET NULL + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_comments_categories` ( + `category_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `category_name` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `category_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `category_locked` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`category_id`), + UNIQUE INDEX `comments_categories_name_unique` (`category_name`), + INDEX `comments_categories_locked_index` (`category_locked`) + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_comments_posts` ( + `comment_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `category_id` INT(10) UNSIGNED NOT NULL, + `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `comment_reply_to` INT(10) UNSIGNED NULL DEFAULT NULL, + `comment_text` TEXT NOT NULL COLLATE 'utf8mb4_bin', + `comment_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `comment_pinned` TIMESTAMP NULL DEFAULT NULL, + `comment_edited` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + `comment_deleted` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`comment_id`), + INDEX `comments_posts_category_foreign` (`category_id`), + INDEX `comments_posts_user_foreign` (`user_id`), + INDEX `comments_posts_reply_id` (`comment_reply_to`), + INDEX `comments_posts_dates` ( + `comment_created`, `comment_pinned`, + `comment_edited`, `comment_deleted` + ), + CONSTRAINT `comments_posts_category_foreign` + FOREIGN KEY (`category_id`) + REFERENCES `msz_comments_categories` (`category_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `comments_posts_user_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE SET NULL + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_comments_votes` ( + `comment_id` INT(10) UNSIGNED NOT NULL, + `user_id` INT(10) UNSIGNED NOT NULL, + `comment_vote` TINYINT(4) NOT NULL DEFAULT '0', + UNIQUE INDEX `comments_vote_unique` (`comment_id`, `user_id`), + INDEX `comments_vote_user_foreign` (`user_id`), + INDEX `comments_vote_index` (`comment_vote`), + CONSTRAINT `comment_vote_id` + FOREIGN KEY (`comment_id`) + REFERENCES `msz_comments_posts` (`comment_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `comment_vote_user` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_news_categories` ( + `category_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `category_name` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `category_description` TEXT NOT NULL COLLATE 'utf8mb4_bin', + `category_is_hidden` TINYINT(1) NOT NULL DEFAULT '0', + `category_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`category_id`) + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_news_posts` ( + `post_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `category_id` INT(10) UNSIGNED NOT NULL, + `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `comment_section_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `post_is_featured` TINYINT(1) NOT NULL DEFAULT '0', + `post_title` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `post_text` TEXT NOT NULL COLLATE 'utf8mb4_bin', + `post_scheduled` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `post_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `post_updated` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `post_deleted` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`post_id`), + INDEX `news_posts_category_id_foreign` (`category_id`), + INDEX `news_posts_user_id_foreign` (`user_id`), + INDEX `news_posts_comment_section` (`comment_section_id`), + INDEX `news_posts_featured_index` (`post_is_featured`), + INDEX `news_posts_scheduled_index` (`post_scheduled`), + INDEX `news_posts_created_index` (`post_created`), + INDEX `news_posts_updated_index` (`post_updated`), + INDEX `news_posts_deleted_index` (`post_deleted`), + FULLTEXT INDEX `news_posts_fulltext` (`post_title`, `post_text`), + CONSTRAINT `news_posts_category_id_foreign` + FOREIGN KEY (`category_id`) + REFERENCES `msz_news_categories` (`category_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `news_posts_comment_section` + FOREIGN KEY (`comment_section_id`) + REFERENCES `msz_comments_categories` (`category_id`) + ON UPDATE CASCADE + ON DELETE SET NULL, + CONSTRAINT `news_posts_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE SET NULL + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_changelog_tags` ( + `tag_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `tag_name` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `tag_description` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `tag_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `tag_archived` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`tag_id`), + UNIQUE INDEX `tag_name` (`tag_name`), + INDEX `tag_archived` (`tag_archived`) + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_changelog_changes` ( + `change_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `change_action` INT(10) UNSIGNED NULL DEFAULT NULL, + `change_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `change_log` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `change_text` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + PRIMARY KEY (`change_id`), + INDEX `changes_user_foreign` (`user_id`), + INDEX `changes_action_index` (`change_action`), + INDEX `changes_created_index` (`change_created`), + CONSTRAINT `changes_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE SET NULL + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_changelog_change_tags` ( + `change_id` INT(10) UNSIGNED NOT NULL, + `tag_id` INT(10) UNSIGNED NOT NULL, + UNIQUE INDEX `change_tag_unique` (`change_id`, `tag_id`), + INDEX `tag_id_foreign_key` (`tag_id`), + CONSTRAINT `change_id_foreign_key` + FOREIGN KEY (`change_id`) + REFERENCES `msz_changelog_changes` (`change_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `tag_id_foreign_key` + FOREIGN KEY (`tag_id`) + REFERENCES `msz_changelog_tags` (`tag_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_forum_polls` ( + `poll_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `poll_max_votes` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1', + `poll_expires` TIMESTAMP NULL DEFAULT NULL, + `poll_preview_results` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1', + `poll_change_vote` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0', + PRIMARY KEY (`poll_id`) + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_forum_polls_options` ( + `option_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `poll_id` INT(10) UNSIGNED NOT NULL, + `option_text` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + PRIMARY KEY (`option_id`), + INDEX `polls_options_poll_foreign` (`poll_id`), + CONSTRAINT `polls_options_poll_foreign` + FOREIGN KEY (`poll_id`) + REFERENCES `msz_forum_polls` (`poll_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_forum_polls_answers` ( + `user_id` INT(10) UNSIGNED NOT NULL, + `poll_id` INT(10) UNSIGNED NOT NULL, + `option_id` INT(10) UNSIGNED NOT NULL, + UNIQUE INDEX `polls_answers_unique` (`user_id`, `poll_id`, `option_id`), + INDEX `polls_answers_user_foreign` (`user_id`), + INDEX `polls_answers_poll_foreign` (`poll_id`), + INDEX `polls_answers_option_foreign` (`option_id`), + CONSTRAINT `polls_answers_option_foreign` + FOREIGN KEY (`option_id`) + REFERENCES `msz_forum_polls_options` (`option_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `polls_answers_poll_foreign` + FOREIGN KEY (`poll_id`) + REFERENCES `msz_forum_polls` (`poll_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `polls_answers_user_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_forum_categories` ( + `forum_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `forum_order` INT(10) UNSIGNED NOT NULL DEFAULT '1', + `forum_parent` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `forum_name` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `forum_type` TINYINT(4) NOT NULL DEFAULT '0', + `forum_description` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `forum_colour` INT(10) UNSIGNED NULL DEFAULT NULL, + `forum_link` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `forum_link_clicks` INT(10) UNSIGNED NULL DEFAULT NULL, + `forum_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `forum_archived` TINYINT(1) NOT NULL DEFAULT '0', + `forum_hidden` TINYINT(1) NOT NULL DEFAULT '0', + `forum_count_topics` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `forum_count_posts` INT(10) UNSIGNED NOT NULL DEFAULT '0', + PRIMARY KEY (`forum_id`), + INDEX `forum_order_index` (`forum_order`), + INDEX `forum_parent_index` (`forum_parent`), + INDEX `forum_type_index` (`forum_type`) + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_forum_permissions` ( + `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `role_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `forum_id` INT(10) UNSIGNED NOT NULL, + `forum_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `forum_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0', + UNIQUE INDEX `forum_permissions_unique` (`user_id`, `role_id`, `forum_id`), + INDEX `forum_permissions_forum_id` (`forum_id`), + INDEX `forum_permissions_role_id` (`role_id`), + CONSTRAINT `forum_permissions_forum_id_foreign` + FOREIGN KEY (`forum_id`) + REFERENCES `msz_forum_categories` (`forum_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `forum_permissions_role_id_foreign` + FOREIGN KEY (`role_id`) + REFERENCES `msz_roles` (`role_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `forum_permissions_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_forum_topics` ( + `topic_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `forum_id` INT(10) UNSIGNED NOT NULL, + `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `poll_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `topic_type` TINYINT(4) NOT NULL DEFAULT '0', + `topic_title` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `topic_count_views` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `topic_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `topic_bumped` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `topic_deleted` TIMESTAMP NULL DEFAULT NULL, + `topic_locked` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`topic_id`), + INDEX `topics_forum_id_foreign` (`forum_id`), + INDEX `topics_user_id_foreign` (`user_id`), + INDEX `topics_type_index` (`topic_type`), + INDEX `topics_created_index` (`topic_created`), + INDEX `topics_bumped_index` (`topic_bumped`), + INDEX `topics_deleted_index` (`topic_deleted`), + INDEX `topics_locked_index` (`topic_locked`), + INDEX `posts_poll_id_foreign` (`poll_id`), + FULLTEXT INDEX `topics_fulltext` (`topic_title`), + CONSTRAINT `posts_poll_id_foreign` + FOREIGN KEY (`poll_id`) + REFERENCES `msz_forum_polls` (`poll_id`) + ON UPDATE CASCADE + ON DELETE SET NULL, + CONSTRAINT `topics_forum_id_foreign` + FOREIGN KEY (`forum_id`) + REFERENCES `msz_forum_categories` (`forum_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `topics_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_forum_topics_track` ( + `user_id` INT(10) UNSIGNED NOT NULL, + `topic_id` INT(10) UNSIGNED NOT NULL, + `forum_id` INT(10) UNSIGNED NOT NULL, + `track_last_read` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + UNIQUE INDEX `topics_track_unique` (`user_id`, `topic_id`), + INDEX `topics_track_topic_id_foreign` (`topic_id`), + INDEX `topics_track_user_id_foreign` (`user_id`), + INDEX `topics_track_forum_id_foreign` (`forum_id`), + INDEX `forum_track_last_read` (`track_last_read`), + CONSTRAINT `topics_track_forum_id_foreign` + FOREIGN KEY (`forum_id`) + REFERENCES `msz_forum_categories` (`forum_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `topics_track_topic_id_foreign` + FOREIGN KEY (`topic_id`) + REFERENCES `msz_forum_topics` (`topic_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `topics_track_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_forum_posts` ( + `post_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `topic_id` INT(10) UNSIGNED NOT NULL, + `forum_id` INT(10) UNSIGNED NOT NULL, + `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `post_ip` VARBINARY(16) NOT NULL, + `post_text` TEXT NOT NULL COLLATE 'utf8mb4_bin', + `post_parse` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0', + `post_display_signature` TINYINT(4) UNSIGNED NOT NULL DEFAULT '1', + `post_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `post_edited` TIMESTAMP NULL DEFAULT NULL, + `post_deleted` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`post_id`), + INDEX `posts_topic_id_foreign` (`topic_id`), + INDEX `posts_forum_id_foreign` (`forum_id`), + INDEX `posts_user_id_foreign` (`user_id`), + INDEX `posts_created_index` (`post_created`), + INDEX `posts_deleted_index` (`post_deleted`), + INDEX `posts_parse_index` (`post_parse`), + INDEX `posts_edited_index` (`post_edited`), + INDEX `posts_display_signature_index` (`post_display_signature`), + INDEX `posts_ip_index` (`post_ip`), + FULLTEXT INDEX `posts_fulltext` (`post_text`), + CONSTRAINT `posts_forum_id_foreign` + FOREIGN KEY (`forum_id`) + REFERENCES `msz_forum_categories` (`forum_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `posts_topic_id_foreign` + FOREIGN KEY (`topic_id`) + REFERENCES `msz_forum_topics` (`topic_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `posts_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE SET NULL + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); +} + +function migrate_down(PDO $conn): void { + $conn->exec("DROP TABLE `msz_forum_posts`"); + $conn->exec("DROP TABLE `msz_forum_topics_track`"); + $conn->exec("DROP TABLE `msz_forum_topics`"); + $conn->exec("DROP TABLE `msz_forum_permissions`"); + $conn->exec("DROP TABLE `msz_forum_categories`"); + $conn->exec("DROP TABLE `msz_forum_polls_answers`"); + $conn->exec("DROP TABLE `msz_forum_polls_options`"); + $conn->exec("DROP TABLE `msz_forum_polls`"); + $conn->exec("DROP TABLE `msz_changelog_change_tags`"); + $conn->exec("DROP TABLE `msz_changelog_changes`"); + $conn->exec("DROP TABLE `msz_changelog_tags`"); + $conn->exec("DROP TABLE `msz_news_posts`"); + $conn->exec("DROP TABLE `msz_news_categories`"); + $conn->exec("DROP TABLE `msz_comments_votes`"); + $conn->exec("DROP TABLE `msz_comments_posts`"); + $conn->exec("DROP TABLE `msz_comments_categories`"); + $conn->exec("DROP TABLE `msz_login_attempts`"); + $conn->exec("DROP TABLE `msz_auth_tfa`"); + $conn->exec("DROP TABLE `msz_audit_log`"); + $conn->exec("DROP TABLE `msz_permissions`"); + $conn->exec("DROP TABLE `msz_sessions`"); + $conn->exec("DROP TABLE `msz_user_warnings`"); + $conn->exec("DROP TABLE `msz_user_relations`"); + $conn->exec("DROP TABLE `msz_users_password_resets`"); + $conn->exec("DROP TABLE `msz_user_roles`"); + $conn->exec("DROP TABLE `msz_users`"); + $conn->exec("DROP TABLE `msz_roles`"); + $conn->exec("DROP TABLE `msz_ip_blacklist`"); +} diff --git a/database/2019_05_05_163101_add_forum_category_icons.php b/database/2019_05_05_163101_add_forum_category_icons.php new file mode 100644 index 0000000..168f207 --- /dev/null +++ b/database/2019_05_05_163101_add_forum_category_icons.php @@ -0,0 +1,18 @@ +exec(" + ALTER TABLE `msz_forum_categories` + ADD COLUMN `forum_icon` VARCHAR(50) NULL DEFAULT NULL AFTER `forum_description`; + "); +} + +function migrate_down(PDO $conn): void { + $conn->exec(" + ALTER TABLE `msz_forum_categories` + DROP COLUMN `forum_icon`; + "); +} diff --git a/database/2019_05_07_090631_create_feature_forum_type.php b/database/2019_05_07_090631_create_feature_forum_type.php new file mode 100644 index 0000000..f841734 --- /dev/null +++ b/database/2019_05_07_090631_create_feature_forum_type.php @@ -0,0 +1,33 @@ +exec(" + CREATE TABLE `msz_forum_topics_priority` ( + `topic_id` INT(10) UNSIGNED NOT NULL, + `user_id` INT(10) UNSIGNED NOT NULL, + `topic_priority` SMALLINT(6) NOT NULL, + UNIQUE INDEX `forum_topics_priority_unique` (`topic_id`, `user_id`), + INDEX `forum_topics_priority_topic_foreign` (`topic_id`), + INDEX `forum_topics_priority_user_foreign` (`user_id`), + CONSTRAINT `forum_topics_priority_topic_foreign` + FOREIGN KEY (`topic_id`) + REFERENCES `msz_forum_topics` (`topic_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `forum_topics_priority_user_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); +} + +function migrate_down(PDO $conn): void { + $conn->exec(" + DROP TABLE `msz_forum_topics_priority` + "); +} diff --git a/database/2019_07_04_175010_create_emoticons_table.php b/database/2019_07_04_175010_create_emoticons_table.php new file mode 100644 index 0000000..262edde --- /dev/null +++ b/database/2019_07_04_175010_create_emoticons_table.php @@ -0,0 +1,27 @@ +exec(" + CREATE TABLE `msz_emoticons` ( + `emote_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `emote_order` MEDIUMINT(9) NOT NULL DEFAULT 0, + `emote_hierarchy` INT(11) NOT NULL DEFAULT 0, + `emote_string` VARCHAR(50) NOT NULL COLLATE 'ascii_general_nopad_ci', + `emote_url` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + PRIMARY KEY (`emote_id`), + UNIQUE INDEX `emotes_string` (`emote_string`), + INDEX `emotes_order` (`emote_order`), + INDEX `emotes_hierarchy` (`emote_hierarchy`), + INDEX `emotes_url` (`emote_url`) + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); +} + +function migrate_down(PDO $conn): void { + $conn->exec(" + DROP TABLE `msz_emoticons`; + "); +} diff --git a/database/2019_08_14_194510_create_config_table.php b/database/2019_08_14_194510_create_config_table.php new file mode 100644 index 0000000..5f0d0b9 --- /dev/null +++ b/database/2019_08_14_194510_create_config_table.php @@ -0,0 +1,18 @@ +exec(" + CREATE TABLE `msz_config` ( + `config_name` VARCHAR(100) NOT NULL COLLATE 'utf8mb4_bin', + `config_value` BLOB NOT NULL DEFAULT '', + PRIMARY KEY (`config_name`) + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); +} + +function migrate_down(PDO $conn): void { + $conn->exec("DROP TABLE `msz_config`;"); +} diff --git a/database/2019_10_01_181738_profile_fields_in_database.php b/database/2019_10_01_181738_profile_fields_in_database.php new file mode 100644 index 0000000..78e3fe4 --- /dev/null +++ b/database/2019_10_01_181738_profile_fields_in_database.php @@ -0,0 +1,197 @@ +exec(" + CREATE TABLE `msz_profile_fields` ( + `field_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `field_order` INT(11) NOT NULL DEFAULT 0, + `field_key` VARCHAR(50) NOT NULL COLLATE 'utf8mb4_general_ci', + `field_title` VARCHAR(50) NOT NULL COLLATE 'utf8mb4_bin', + `field_regex` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + PRIMARY KEY (`field_id`), + UNIQUE INDEX `profile_fields_key_unique` (`field_key`), + INDEX `profile_fields_order_key` (`field_order`) + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_profile_fields_formats` ( + `format_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `field_id` INT(10) UNSIGNED NOT NULL DEFAULT 0, + `format_regex` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `format_link` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `format_display` VARCHAR(255) NOT NULL DEFAULT '%s' COLLATE 'utf8mb4_bin', + PRIMARY KEY (`format_id`), + INDEX `profile_field_format_field_foreign` (`field_id`), + CONSTRAINT `profile_field_format_field_foreign` + FOREIGN KEY (`field_id`) + REFERENCES `msz_profile_fields` (`field_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_profile_fields_values` ( + `field_id` INT(10) UNSIGNED NOT NULL, + `user_id` INT(10) UNSIGNED NOT NULL, + `format_id` INT(10) UNSIGNED NOT NULL, + `field_value` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + PRIMARY KEY (`field_id`, `user_id`), + INDEX `profile_fields_values_format_foreign` (`format_id`), + INDEX `profile_fields_values_user_foreign` (`user_id`), + INDEX `profile_fields_values_value_key` (`field_value`), + CONSTRAINT `profile_fields_values_field_foreign` + FOREIGN KEY (`field_id`) + REFERENCES `msz_profile_fields` (`field_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `profile_fields_values_format_foreign` + FOREIGN KEY (`format_id`) + REFERENCES `msz_profile_fields_formats` (`format_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `profile_fields_values_user_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $fieldIds = []; + $fields = [ + ['order' => 10, 'key' => 'website', 'title' => 'Website', 'regex' => '#^((?:https?)://.{1,240})$#u'], + ['order' => 20, 'key' => 'youtube', 'title' => 'Youtube', 'regex' => '#^(?:https?://(?:www.)?youtube.com/(?:(?:user|c|channel)/)?)?(UC[a-zA-Z0-9-_]{1,22}|[a-zA-Z0-9-_%]{1,100})/?$#u'], + ['order' => 30, 'key' => 'twitter', 'title' => 'Twitter', 'regex' => '#^(?:https?://(?:www\.)?twitter.com/(?:\#!\/)?)?@?([A-Za-z0-9_]{1,20})/?$#u'], + ['order' => 40, 'key' => 'ninswitch', 'title' => 'Nintendo Switch', 'regex' => '#^(?:SW-)?([0-9]{4}-[0-9]{4}-[0-9]{4})$#u'], + ['order' => 50, 'key' => 'twitchtv', 'title' => 'Twitch.tv', 'regex' => '#^(?:https?://(?:www.)?twitch.tv/)?([0-9A-Za-z_]{3,25})/?$#u'], + ['order' => 60, 'key' => 'steam', 'title' => 'Steam', 'regex' => '#^(?:https?://(?:www.)?steamcommunity.com/(?:id|profiles)/)?([a-zA-Z0-9_-]{2,100})/?$#u'], + ['order' => 70, 'key' => 'osu', 'title' => 'osu!', 'regex' => '#^(?:https?://osu.ppy.sh/u(?:sers)?/)?([a-zA-Z0-9-\[\]_ ]{1,20})/?$#u'], + ['order' => 80, 'key' => 'lastfm', 'title' => 'Last.fm', 'regex' => '#^(?:https?://(?:www.)?last.fm/user/)?([a-zA-Z]{1}[a-zA-Z0-9_-]{1,14})/?$#u'], + ['order' => 90, 'key' => 'github', 'title' => 'Github', 'regex' => '#^(?:https?://(?:www.)?github.com/?)?([a-zA-Z0-9](?:[a-zA-Z0-9]|-(?=[a-zA-Z0-9])){0,38})/?$#u'], + ['order' => 100, 'key' => 'skype', 'title' => 'Skype', 'regex' => '#^((?:live:)?[a-zA-Z][\w\.,\-_@]{1,100})$#u'], + ['order' => 110, 'key' => 'discord', 'title' => 'Discord', 'regex' => '#^(.{1,32}\#[0-9]{4})$#u'], + ]; + $formats = [ + ['field' => 'website', 'regex' => null, 'display' => '%s', 'link' => '%s'], + ['field' => 'youtube', 'regex' => null, 'display' => '%s', 'link' => 'https://youtube.com/%s'], + ['field' => 'youtube', 'regex' => '^UC[a-zA-Z0-9-_]{1,22}$', 'display' => 'Go to Channel', 'link' => 'https://youtube.com/channel/%s'], + ['field' => 'twitter', 'regex' => null, 'display' => '@%s', 'link' => 'https://twitter.com/%s'], + ['field' => 'ninswitch', 'regex' => null, 'display' => 'SW-%s', 'link' => null], + ['field' => 'twitchtv', 'regex' => null, 'display' => '%s', 'link' => 'https://twitch.tv/%s'], + ['field' => 'steam', 'regex' => null, 'display' => '%s', 'link' => 'https://steamcommunity.com/id/%s'], + ['field' => 'osu', 'regex' => null, 'display' => '%s', 'link' => 'https://osu.ppy.sh/users/%s'], + ['field' => 'lastfm', 'regex' => null, 'display' => '%s', 'link' => 'https://www.last.fm/user/%s'], + ['field' => 'github', 'regex' => null, 'display' => '%s', 'link' => 'https://github.com/%s'], + ['field' => 'skype', 'regex' => null, 'display' => '%s', 'link' => 'skype:%s?userinfo'], + ['field' => 'discord', 'regex' => null, 'display' => '%s', 'link' => null], + ]; + + $insertField = $conn->prepare("INSERT INTO `msz_profile_fields` (`field_order`, `field_key`, `field_title`, `field_regex`) VALUES (:order, :key, :title, :regex)"); + $insertFormat = $conn->prepare("INSERT INTO `msz_profile_fields_formats` (`field_id`, `format_regex`, `format_link`, `format_display`) VALUES (:field, :regex, :link, :display)"); + $insertValue = $conn->prepare("INSERT INTO `msz_profile_fields_values` (`field_id`, `user_id`, `format_id`, `field_value`) VALUES (:field, :user, :format, :value)"); + + for($i = 0; $i < count($fields); $i++) { + $insertField->execute($fields[$i]); + $fields[$i]['id'] = $fieldIds[$fields[$i]['key']] = (int)$conn->lastInsertId(); + } + + for($i = 0; $i < count($formats); $i++) { + $formats[$i]['field'] = $fieldIds[$formats[$i]['field']]; + $insertFormat->execute($formats[$i]); + $formats[$i]['id'] = (int)$conn->lastInsertId(); + } + + $users = $conn->query(" + SELECT `user_id`, `user_website`, `user_twitter`, `user_github`, `user_skype`, `user_discord`, + `user_youtube`, `user_steam`, `user_ninswitch`, `user_twitchtv`, `user_osu`, `user_lastfm` + FROM `msz_users` + ")->fetchAll(PDO::FETCH_ASSOC); + + foreach($users as $user) { + foreach($fields as $field) { + $source = 'user_' . $field['key']; + $formatId = 0; + + if(empty($user[$source])) + continue; + + foreach($formats as $format) { + if($format['field'] != $field['id']) + continue; + + if(empty($format['regex']) && $formatId < 1) { + $formatId = $format['id']; + continue; + } + + if(preg_match("#{$format['regex']}#", $user[$source])) { + $formatId = $format['id']; + break; + } + } + + $insertValue->execute([ + 'field' => $field['id'], + 'user' => $user['user_id'], + 'format' => $formatId, + 'value' => $user[$source], + ]); + } + } + + $conn->exec(" + ALTER TABLE `msz_users` + DROP COLUMN `user_website`, + DROP COLUMN `user_twitter`, + DROP COLUMN `user_github`, + DROP COLUMN `user_skype`, + DROP COLUMN `user_discord`, + DROP COLUMN `user_youtube`, + DROP COLUMN `user_steam`, + DROP COLUMN `user_ninswitch`, + DROP COLUMN `user_twitchtv`, + DROP COLUMN `user_osu`, + DROP COLUMN `user_lastfm`; + "); +} + +function migrate_down(PDO $conn): void { + $conn->exec(" + ALTER TABLE `msz_users` + ADD COLUMN `user_website` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin' AFTER `user_background_settings`, + ADD COLUMN `user_twitter` VARCHAR(20) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin' AFTER `user_website`, + ADD COLUMN `user_github` VARCHAR(40) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin' AFTER `user_twitter`, + ADD COLUMN `user_skype` VARCHAR(60) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin' AFTER `user_github`, + ADD COLUMN `user_discord` VARCHAR(40) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin' AFTER `user_skype`, + ADD COLUMN `user_youtube` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin' AFTER `user_discord`, + ADD COLUMN `user_steam` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin' AFTER `user_youtube`, + ADD COLUMN `user_ninswitch` VARCHAR(14) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin' AFTER `user_steam`, + ADD COLUMN `user_twitchtv` VARCHAR(30) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin' AFTER `user_ninswitch`, + ADD COLUMN `user_osu` VARCHAR(20) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin' AFTER `user_twitchtv`, + ADD COLUMN `user_lastfm` VARCHAR(20) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin' AFTER `user_osu`; + "); + + $existingFields = $conn->query(" + SELECT pfv.`user_id`, pf.`field_key`, pfv.`field_value` + FROM `msz_profile_fields_values` AS pfv + LEFT JOIN `msz_profile_fields` AS pf + ON pf.`field_id` = pfv.`field_id` + "); + + $updatePreps = []; + foreach($existingFields as $field) { + ($updatePreps[$field['field_key']] ?? ($updatePreps[$field['field_key']] = $conn->prepare("UPDATE `msz_users` SET `user_{$field['field_key']}` = :value WHERE `user_id` = :user_id")))->execute([ + 'value' => $field['field_value'], + 'user_id' => $field['user_id'], + ]); + } + + $conn->exec("DROP TABLE `msz_profile_fields_values`"); + $conn->exec("DROP TABLE `msz_profile_fields_formats`"); + $conn->exec("DROP TABLE `msz_profile_fields`"); +} diff --git a/database/2019_12_08_181735_emoticon_restructure.php b/database/2019_12_08_181735_emoticon_restructure.php new file mode 100644 index 0000000..f95f211 --- /dev/null +++ b/database/2019_12_08_181735_emoticon_restructure.php @@ -0,0 +1,86 @@ +query('SELECT * FROM `msz_emoticons`')->fetchAll(PDO::FETCH_ASSOC); + $pruneDupes = $conn->prepare('DELETE FROM `msz_emoticons` WHERE `emote_id` = :id'); + + // int order, int hierarchy, string url, array(string string, int order) strings + $images = []; + $delete = []; + + foreach($emotes as $emote) { + if(!isset($images[$emote['emote_url']])) { + $images[$emote['emote_url']] = [ + 'id' => $emote['emote_id'], + 'order' => $emote['emote_order'], + 'hierarchy' => $emote['emote_hierarchy'], + 'url' => $emote['emote_url'], + 'strings' => [], + ]; + } else { + $delete[] = $emote['emote_id']; + } + + $images[$emote['emote_url']]['strings'][] = [ + 'string' => $emote['emote_string'], + 'order' => count($images[$emote['emote_url']]['strings']) + 1, + ]; + } + + foreach($delete as $id) { + $pruneDupes->bindValue('id', $id); + $pruneDupes->execute(); + } + + $conn->exec(' + ALTER TABLE `msz_emoticons` + DROP COLUMN `emote_string`, + DROP INDEX `emotes_string`, + DROP INDEX `emotes_url`, + ADD UNIQUE INDEX `emotes_url` (`emote_url`); + '); + $conn->exec(" + CREATE TABLE `msz_emoticons_strings` ( + `emote_id` INT UNSIGNED NOT NULL, + `emote_string_order` MEDIUMINT NOT NULL DEFAULT 0, + `emote_string` VARCHAR(50) NOT NULL COLLATE 'ascii_general_nopad_ci', + INDEX `string_emote_foreign` (`emote_id`), + INDEX `string_order_key` (`emote_string_order`), + UNIQUE INDEX `string_unique` (`emote_string`), + CONSTRAINT `string_emote_foreign` + FOREIGN KEY (`emote_id`) + REFERENCES `msz_emoticons` (`emote_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin'; + "); + + $insertString = $conn->prepare(' + INSERT INTO `msz_emoticons_strings` (`emote_id`, `emote_string_order`, `emote_string`) + VALUES (:id, :order, :string) + '); + + foreach($images as $image) { + $insertString->bindValue('id', $image['id']); + + foreach($image['strings'] as $string) { + $insertString->bindValue('order', $string['order']); + $insertString->bindValue('string', $string['string']); + $insertString->execute(); + } + } +} + +function migrate_down(PDO $conn): void { + $conn->exec('DROP TABLE `msz_emoticons_strings`'); + $conn->exec(" + ALTER TABLE `msz_emoticons` + ADD COLUMN `emote_string` VARCHAR(50) NOT NULL COLLATE 'ascii_general_nopad_ci' AFTER `emote_hierarchy`, + DROP INDEX `emotes_url`, + ADD INDEX `emotes_url` (`emote_url`), + ADD UNIQUE INDEX `emote_string` (`emote_url`); + "); +} diff --git a/database/2019_12_14_005624_added_chat_tokens_table.php b/database/2019_12_14_005624_added_chat_tokens_table.php new file mode 100644 index 0000000..0161253 --- /dev/null +++ b/database/2019_12_14_005624_added_chat_tokens_table.php @@ -0,0 +1,26 @@ +exec(" + CREATE TABLE `msz_user_chat_tokens` ( + `user_id` INT(10) UNSIGNED NOT NULL, + `token_string` CHAR(64) NOT NULL, + `token_created` TIMESTAMP NOT NULL DEFAULT current_timestamp(), + UNIQUE INDEX `user_chat_token_string_unique` (`token_string`), + INDEX `user_chat_token_user_foreign` (`user_id`), + INDEX `user_chat_token_created_key` (`token_created`), + CONSTRAINT `user_chat_token_user_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); +} + +function migrate_down(PDO $conn): void { + $conn->exec("DROP TABLE `msz_user_chat_tokens`"); +} diff --git a/database/2020_05_21_145756_audit_log_table_fixes.php b/database/2020_05_21_145756_audit_log_table_fixes.php new file mode 100644 index 0000000..7dbf4b3 --- /dev/null +++ b/database/2020_05_21_145756_audit_log_table_fixes.php @@ -0,0 +1,21 @@ +exec(' + ALTER TABLE `msz_audit_log` + DROP COLUMN `log_id`, + ADD INDEX `audit_log_created_index` (`log_created`); + '); +} + +function migrate_down(PDO $conn): void { + $conn->exec(" + ALTER TABLE `msz_audit_log` + ADD COLUMN `log_id` INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, + DROP INDEX `audit_log_created_index`, + ADD PRIMARY KEY (`log_id`); + "); +} diff --git a/database/2020_05_25_133726_login_attempts_table_fixes.php b/database/2020_05_25_133726_login_attempts_table_fixes.php new file mode 100644 index 0000000..5ea464b --- /dev/null +++ b/database/2020_05_25_133726_login_attempts_table_fixes.php @@ -0,0 +1,21 @@ +exec(" + ALTER TABLE `msz_login_attempts` + DROP COLUMN `attempt_id`, + ADD INDEX `login_attempts_created_index` (`attempt_created`); + "); +} + +function migrate_down(PDO $conn): void { + $conn->exec(" + ALTER TABLE `msz_login_attempts` + ADD COLUMN `attempt_id` INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, + DROP INDEX `login_attempts_created_index`, + ADD PRIMARY KEY (`attempt_id`); + "); +} diff --git a/database/2020_05_25_152331_sessions_table_fixes.php b/database/2020_05_25_152331_sessions_table_fixes.php new file mode 100644 index 0000000..9820beb --- /dev/null +++ b/database/2020_05_25_152331_sessions_table_fixes.php @@ -0,0 +1,22 @@ +exec(" + ALTER TABLE `msz_sessions` + CHANGE COLUMN `session_key` `session_key` BINARY(64) NOT NULL AFTER `user_id`, + CHANGE COLUMN `session_expires` `session_expires` TIMESTAMP NOT NULL DEFAULT DATE_ADD(NOW(), INTERVAL 1 MONTH) AFTER `session_country`, + ADD INDEX `sessions_created_index` (`session_created`); + "); +} + +function migrate_down(PDO $conn): void { + $conn->exec(" + ALTER TABLE `msz_sessions` + CHANGE COLUMN `session_key` `session_key` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin' AFTER `user_id`, + CHANGE COLUMN `session_expires` `session_expires` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP() AFTER `session_country`, + DROP INDEX `sessions_created_index`; + "); +} diff --git a/database/2020_05_27_134934_add_missing_indexes.php b/database/2020_05_27_134934_add_missing_indexes.php new file mode 100644 index 0000000..0f1a04b --- /dev/null +++ b/database/2020_05_27_134934_add_missing_indexes.php @@ -0,0 +1,66 @@ +exec(" + ALTER TABLE `msz_forum_categories` + ADD INDEX `forum_link_clicks_index` (`forum_link_clicks`), + ADD INDEX `forum_hidden_index` (`forum_hidden`); + "); + + $conn->exec(" + ALTER TABLE `msz_login_attempts` + ADD INDEX `login_attempts_success_index` (`attempt_success`), + ADD INDEX `login_attempts_ip_index` (`attempt_ip`); + "); + + $conn->exec(" + ALTER TABLE `msz_news_categories` + ADD INDEX `news_categories_is_hidden_index` (`category_is_hidden`); + "); + + $conn->exec(" + ALTER TABLE `msz_roles` + ADD INDEX `roles_hierarchy_index` (`role_hierarchy`), + ADD INDEX `roles_hidden_index` (`role_hidden`); + "); + + $conn->exec(" + ALTER TABLE `msz_user_relations` + ADD INDEX `user_relations_type_index` (`relation_type`), + ADD INDEX `user_relations_created_index` (`relation_created`); + "); +} + +function migrate_down(PDO $conn): void { + $conn->exec(" + ALTER TABLE `msz_forum_categories` + DROP INDEX `forum_link_clicks_index`, + DROP INDEX `forum_hidden_index`; + "); + + $conn->exec(" + ALTER TABLE `msz_login_attempts` + DROP INDEX `login_attempts_success_index`, + DROP INDEX `login_attempts_ip_index`; + "); + + $conn->exec(" + ALTER TABLE `msz_news_categories` + DROP INDEX `news_categories_is_hidden_index`; + "); + + $conn->exec(" + ALTER TABLE `msz_roles` + DROP INDEX `roles_hierarchy_index`, + DROP INDEX `roles_hidden_index`; + "); + + $conn->exec(" + ALTER TABLE `msz_user_relations` + DROP INDEX `user_relations_type_index`, + DROP INDEX `user_relations_created_index`; + "); +} diff --git a/database/2020_05_29_142907_recovery_table_fixes.php b/database/2020_05_29_142907_recovery_table_fixes.php new file mode 100644 index 0000000..1f5b0d4 --- /dev/null +++ b/database/2020_05_29_142907_recovery_table_fixes.php @@ -0,0 +1,28 @@ +exec(" + ALTER TABLE `msz_users_password_resets` + CHANGE COLUMN `verification_code` `verification_code` CHAR(12) NULL DEFAULT NULL COLLATE 'ascii_bin' AFTER `reset_requested`, + DROP INDEX `msz_users_password_resets_unique`, + ADD UNIQUE INDEX `users_password_resets_user_unique` (`user_id`, `reset_ip`), + DROP INDEX `msz_users_password_resets_index`, + ADD INDEX `users_password_resets_created_index` (`reset_requested`), + ADD UNIQUE INDEX `users_password_resets_token_unique` (`verification_code`); + "); +} + +function migrate_down(PDO $conn): void { + $conn->exec(" + ALTER TABLE `msz_users_password_resets` + CHANGE COLUMN `verification_code` `verification_code` CHAR(12) NULL DEFAULT NULL COLLATE 'utf8mb4_bin' AFTER `reset_requested`, + DROP INDEX `users_password_resets_user_unique`, + ADD UNIQUE INDEX `msz_users_password_resets_unique` (`user_id`, `reset_ip`), + DROP INDEX `users_password_resets_created_index`, + ADD INDEX `msz_users_password_resets_index` (`reset_requested`), + DROP INDEX `users_password_resets_token_unique`; + "); +} diff --git a/database/2020_05_29_190810_case_insensitive_forum_search.php b/database/2020_05_29_190810_case_insensitive_forum_search.php new file mode 100644 index 0000000..2cdca7a --- /dev/null +++ b/database/2020_05_29_190810_case_insensitive_forum_search.php @@ -0,0 +1,28 @@ +exec(" + ALTER TABLE `msz_forum_topics` + CHANGE COLUMN `topic_title` `topic_title` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_ci' AFTER `topic_type`; + "); + + $conn->exec(" + ALTER TABLE `msz_forum_posts` + CHANGE COLUMN `post_text` `post_text` TEXT(65535) NOT NULL COLLATE 'utf8mb4_unicode_ci' AFTER `post_ip`; + "); +} + +function migrate_down(PDO $conn): void { + $conn->exec(" + ALTER TABLE `msz_forum_topics` + CHANGE COLUMN `topic_title` `topic_title` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin' AFTER `topic_type`; + "); + + $conn->exec(" + ALTER TABLE `msz_forum_posts` + CHANGE COLUMN `post_text` `post_text` TEXT(65535) NOT NULL COLLATE 'utf8mb4_bin' AFTER `post_ip`; + "); +} diff --git a/database/2020_05_30_142750_add_owner_id_to_comments.php b/database/2020_05_30_142750_add_owner_id_to_comments.php new file mode 100644 index 0000000..9130509 --- /dev/null +++ b/database/2020_05_30_142750_add_owner_id_to_comments.php @@ -0,0 +1,26 @@ +exec(" + ALTER TABLE `msz_comments_categories` + ADD COLUMN `owner_id` INT UNSIGNED NULL DEFAULT NULL AFTER `category_name`, + ADD INDEX `comments_categories_owner_foreign` (`owner_id`), + ADD CONSTRAINT `comments_categories_owner_foreign` + FOREIGN KEY (`owner_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE SET NULL; + "); +} + +function migrate_down(PDO $conn): void { + $conn->exec(" + ALTER TABLE `msz_comments_categories` + DROP COLUMN `owner_id`, + DROP INDEX `comments_categories_owner_foreign`, + DROP FOREIGN KEY `comments_categories_owner_foreign`; + "); +} diff --git a/database/2021_08_28_220000_nuke_relations_table.php b/database/2021_08_28_220000_nuke_relations_table.php new file mode 100644 index 0000000..3311f82 --- /dev/null +++ b/database/2021_08_28_220000_nuke_relations_table.php @@ -0,0 +1,33 @@ +exec("DROP TABLE `msz_user_relations`"); +} + +function migrate_down(PDO $conn): void { + $conn->exec(" + CREATE TABLE `msz_user_relations` ( + `user_id` INT(10) UNSIGNED NOT NULL, + `subject_id` INT(10) UNSIGNED NOT NULL, + `relation_type` TINYINT(3) UNSIGNED NOT NULL, + `relation_created` TIMESTAMP NOT NULL DEFAULT current_timestamp(), + UNIQUE INDEX `user_relations_unique` (`user_id`, `subject_id`) USING BTREE, + INDEX `user_relations_subject_id_foreign` (`subject_id`) USING BTREE, + INDEX `user_relations_type_index` (`relation_type`) USING BTREE, + INDEX `user_relations_created_index` (`relation_created`) USING BTREE, + CONSTRAINT `user_relations_subject_id_foreign` + FOREIGN KEY (`subject_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `user_relations_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); +} diff --git a/database/2022_01_13_005600_nuke_chat_tokens_table.php b/database/2022_01_13_005600_nuke_chat_tokens_table.php new file mode 100644 index 0000000..ccc9a04 --- /dev/null +++ b/database/2022_01_13_005600_nuke_chat_tokens_table.php @@ -0,0 +1,26 @@ +exec("DROP TABLE `msz_user_chat_tokens`"); +} + +function migrate_down(PDO $conn): void { + $conn->exec(" + CREATE TABLE `msz_user_chat_tokens` ( + `user_id` INT(10) UNSIGNED NOT NULL, + `token_string` CHAR(64) NOT NULL, + `token_created` TIMESTAMP NOT NULL DEFAULT current_timestamp(), + UNIQUE INDEX `user_chat_token_string_unique` (`token_string`), + INDEX `user_chat_token_user_foreign` (`user_id`), + INDEX `user_chat_token_created_key` (`token_created`), + CONSTRAINT `user_chat_token_user_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); +} diff --git a/devel/insert-bogus-data.php b/devel/insert-bogus-data.php new file mode 100644 index 0000000..3efb740 --- /dev/null +++ b/devel/insert-bogus-data.php @@ -0,0 +1,482 @@ +exec('DELETE FROM `msz_roles` WHERE `role_id` > 1'); +$db->exec('ALTER TABLE `msz_roles` AUTO_INCREMENT = 2'); + +mkv_log('Running slow cron to ensure main role exists...'); + +// running cron before fuckery +(new \Misuzu\Console\Commands\CronCommand)->dispatch( + new \Misuzu\Console\CommandArgs(['--slow']) +); + +mkv_log('Preparing role and permissions insert statements...'); +$cr = $db->prepare('INSERT INTO `msz_roles` (`role_hierarchy`, `role_name`, `role_title`, `role_description`, `role_hidden`, `role_can_leave`, `role_colour`) VALUES (:rank, :name, :title, :desc, :hide, :leave, :colour)'); +$cp = $db->prepare('REPLACE INTO `msz_permissions` (`role_id`, `general_perms_allow`, `user_perms_allow`, `changelog_perms_allow`, `news_perms_allow`, `forum_perms_allow`, `comments_perms_allow`) VALUES (:role, :general, :user, :changelog, :news, :forum, :comments)'); + +mkv_log('Adding permissions for main role...'); +$cp->bind('role', 1); +$cp->bind('general', 0); +$cp->bind('user', 59); +$cp->bind('changelog', 0); +$cp->bind('news', 0); +$cp->bind('forum', 0); +$cp->bind('comments', 137); +$cp->execute(); + +mkv_log('Creating Global Moderator role...'); +$cr->bind('rank', 5); +$cr->bind('name', 'Global Moderator'); +$cr->bind('title', 'Moderator'); +$cr->bind('desc', 'They are global and in moderation.'); +$cr->bind('hide', 0); +$cr->bind('leave', 0); +$cr->bind('colour', 1693465); +$cr->execute(); + +mkv_log('Adding permissions for Global Moderator...'); +$cp->bind('role', $rIdMod = $db->lastId()); +$cp->bind('general', 3); +$cp->bind('user', 25165887); +$cp->bind('changelog', 0); +$cp->bind('news', 0); +$cp->bind('forum', 0); +$cp->bind('comments', 57); +$cp->execute(); + +mkv_log('Creating Administrator role...'); +$cr->bind('rank', 10); +$cr->bind('name', 'Administrator'); +$cr->bind('title', 'Administrator'); +$cr->bind('desc', 'Administration nation.'); +$cr->bind('hide', 0); +$cr->bind('leave', 0); +$cr->bind('colour', 16711680); +$cr->execute(); + +mkv_log('Adding permissions for Administrator...'); +$cp->bind('role', $rIdAdm = $db->lastId()); +$cp->bind('general', 39); +$cp->bind('user', 28311615); +$cp->bind('changelog', 3); +$cp->bind('news', 3); +$cp->bind('forum', 3); +$cp->bind('comments', 249); +$cp->execute(); + +mkv_log('Creating Bot role...'); +$cr->bind('rank', 7); +$cr->bind('name', 'Bot'); +$cr->bind('title', null); +$cr->bind('desc', 'Service users.'); +$cr->bind('hide', 0); +$cr->bind('leave', 0); +$cr->bind('colour', 10390951); +$cr->execute(); + +$rIdBot = $db->lastId(); + +mkv_log('Creating Tester role...'); +$cr->bind('rank', 1); +$cr->bind('name', 'Tester'); +$cr->bind('title', null); +$cr->bind('desc', 'Experimentalists.'); +$cr->bind('hide', 1); +$cr->bind('leave', 1); +$cr->bind('colour', 1073741824); +$cr->execute(); + +mkv_log('Adding permissions for Tester...'); +$cp->bind('role', $rIdTest = $db->lastId()); +$cp->bind('general', 16); +$cp->bind('user', 0); +$cp->bind('changelog', 3); +$cp->bind('news', 0); +$cp->bind('forum', 0); +$cp->bind('comments', 0); +$cp->execute(); + +mkv_log('Creating OG role...'); +$cr->bind('rank', 1); +$cr->bind('name', 'OG'); +$cr->bind('title', null); +$cr->bind('desc', 'Arbitrarily selected people that joined in 2013 and 2014.'); +$cr->bind('hide', 0); +$cr->bind('leave', 0); +$cr->bind('colour', 15740285); +$cr->execute(); + +mkv_log('Creating Developer role...'); +$cr->bind('rank', 5); +$cr->bind('name', 'Developer'); +$cr->bind('title', 'Developer'); +$cr->bind('desc', 'Moderators but without the requirement to moderate.'); +$cr->bind('hide', 0); +$cr->bind('leave', 0); +$cr->bind('colour', 7558084); +$cr->execute(); + +mkv_log('Adding permissions for Developer...'); +$cp->bind('role', $rIdDev = $db->lastId()); +$cp->bind('general', 3); +$cp->bind('user', 25165887); +$cp->bind('changelog', 3); +$cp->bind('news', 0); +$cp->bind('forum', 0); +$cp->bind('comments', 57); +$cp->execute(); + +mkv_log('Creating Tenshi role...'); +$cr->bind('rank', 1); +$cr->bind('name', 'Tenshi'); +$cr->bind('title', 'Supporter'); +$cr->bind('desc', 'Donators'); +$cr->bind('hide', 0); +$cr->bind('leave', 0); +$cr->bind('colour', 15635456); +$cr->execute(); + +mkv_log('Adding permissions for Tenshi...'); +$cp->bind('role', $rIdTen = $db->lastId()); +$cp->bind('general', 0); +$cp->bind('user', 4); +$cp->bind('changelog', 0); +$cp->bind('news', 0); +$cp->bind('forum', 0); +$cp->bind('comments', 0); +$cp->execute(); + +for($i = 0; $i < 10; ++$i) { + mkv_log('Creating bogus role ' . $i . '...'); + $cr->bind('rank', mt_rand(1, 4)); + $cr->bind('name', $roleNames->generate()); + $cr->bind('title', (mt_rand(0, 100) > 50) ? $roleTitles->generate() : null); + $cr->bind('desc', (mt_rand(0, 100) > 10) ? $roleDescs->generate() : null); + $cr->bind('hide', mt_rand(0, 1)); + $cr->bind('leave', mt_rand(0, 1)); + $cr->bind('colour', ((mt_rand(0, 255) << 16) | (mt_rand(0, 255) << 8) | mt_rand(0, 255))); + $cr->execute(); +} + +mkv_log('Opening user related markov dictionaries...'); +$userNames = new MarkovDictionary(MKV_DICTS . '/users_names.fmk'); +$userTitles = new MarkovDictionary(MKV_DICTS . '/users_titles.fmk'); +$userSigs = new MarkovDictionary(MKV_DICTS . '/users_sigs.fmk'); +$userAbouts = new MarkovDictionary(MKV_DICTS . '/users_abouts.fmk'); + +mkv_log('Nuking users table...'); +$db->exec('DELETE FROM `msz_users`'); +$db->exec('ALTER TABLE `msz_users` AUTO_INCREMENT = 1'); + +mkv_log('Preparing user insert statements...'); +$cu = $db->prepare('INSERT INTO `msz_users` (`username`, `password`, `email`, `register_ip`, `last_ip`, `user_super`, `user_country`, `user_about_content`, `user_about_parser`, `user_signature_content`, `user_signature_parser`, `user_birthdate`, `user_title`, `display_role`) VALUES (:name, :pass, :mail, :reg_addr, :last_addr, :super, :country, :about_text, :about_parse, :sig_text, :sig_parse, :birth, :title, :role)'); + +$ur = $db->prepare('REPLACE INTO `msz_user_roles` (`user_id`, `role_id`) VALUES (:user, :role)'); + +mkv_log('Creating admin user...'); +mkv_log('NOTICE: All passwords will be set to: ' . MKV_PASSWD); +mkv_log('NOTICE: E-mail address will follow the format of: ' . MKV_MAIL); +$cu->bind('name', 'admin'); +$cu->bind('pass', password_hash(MKV_PASSWD, PASSWORD_ARGON2ID)); +$cu->bind('mail', sprintf(MKV_MAIL, 1)); +$cu->bind('reg_addr', "\x7f\0\0\1"); +$cu->bind('last_addr', "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1"); +$cu->bind('super', 1); +$cu->bind('country', 'NL'); +$cu->bind('about_text', '# Default administrator account'); +$cu->bind('about_parse', 2); +$cu->bind('sig_text', '[b]Administrative Signature[/b]'); +$cu->bind('sig_parse', 1); +$cu->bind('birth', '2013-01-27'); +$cu->bind('title', null); +$cu->bind('role', 3); +$cu->execute(); + +mkv_log('Adding Global Moderator role to admin...'); +$ur->bind('user', 1); +$ur->bind('role', 2); +$ur->execute(); + +mkv_log('Adding Administrator role to admin...'); +$ur->bind('user', 1); +$ur->bind('role', 3); +$ur->execute(); + +mkv_log('Adding Developer role to admin...'); +$ur->bind('user', 1); +$ur->bind('role', 8); +$ur->execute(); + +$cu->bind('super', 0); + +for($i = 1; $i < 2000; ++$i) { + mkv_log('Creating bogus user ' . $i . '...'); + $cu->bind('name', mb_substr($userNames->generate(), 0, 200, 'utf-8') . $i); + $cu->bind('pass', password_hash(MKV_PASSWD, PASSWORD_ARGON2ID)); + $cu->bind('mail', sprintf(MKV_MAIL, ($i + 1))); + $cu->bind('reg_addr', random_bytes(mt_rand(0, 1) ? 4 : 16)); + $cu->bind('last_addr', random_bytes(mt_rand(0, 1) ? 4 : 16)); + $cu->bind('country', MKV_ALPHA[mt_rand(0, MKV_ALPHA_LEN - 1)] . MKV_ALPHA[mt_rand(0, MKV_ALPHA_LEN - 1)]); + $cu->bind('about_text', mb_substr($userAbouts->generate(), 0, 60000, 'utf-8')); + $cu->bind('about_parse', mt_rand(0, 2)); + $cu->bind('sig_text', mb_substr($userSigs->generate(), 0, 1000, 'utf-8')); + $cu->bind('sig_parse', mt_rand(0, 2)); + $cu->bind('birth', date('Y-m-d', mt_rand(1, 0x7FFFFFFF))); + $cu->bind('title', mt_rand(0, 100) > 90 ? mb_substr($userTitles->generate(), 0, 64, 'utf-8') : null); + $cu->bind('role', mt_rand(9, 18)); + $cu->execute(); + + $uId = $db->lastId(); + + for($j = 0; $j < mt_rand(1, 4); ++$j) { + $brid = mt_rand(9, 18); + mkv_log('Adding role ' . $brid . ' to bogus user id ' . $uId . '...'); + $ur->bind('user', $uId); + $ur->bind('role', $brid); + $ur->execute(); + } +} + +mkv_log('Opening changelog tag markov dictionaries...'); +$changeTagsNames = new MarkovDictionary(MKV_DICTS . '/changes_tags_names.fmk'); +$changeTagsDescs = new MarkovDictionary(MKV_DICTS . '/changes_tags_descs.fmk'); + +mkv_log('Nuking changelog tags table...'); +$db->exec('DELETE FROM `msz_changelog_tags`'); +$db->exec('ALTER TABLE `msz_changelog_tags` AUTO_INCREMENT = 1'); + +mkv_log('Preparing changelog insert statements...'); +$ct = $db->prepare('INSERT INTO `msz_changelog_tags` (`tag_name`, `tag_description`) VALUES (:name, :descr)'); +$cTagIds = []; + +for($i = 0; $i < 20; ++$i) { + mkv_log('Inserting bogus changelog tag...'); + $ct->bind('name', mb_substr($changeTagsNames->generate(), 0, 200, 'utf-8') . $i); + $ct->bind('descr', mb_substr($changeTagsDescs->generate(), 0, 60000, 'utf-8')); + $ct->execute(); + $cTagIds[] = $db->lastId(); +} + +mkv_log('Opening changelog changes markov dictionaries...'); +$changeLogs = new MarkovDictionary(MKV_DICTS . '/changes_logs.fmk'); +$changeTexts = new MarkovDictionary(MKV_DICTS . '/changes_texts.fmk'); + +mkv_log('Nuking changelog changes tables...'); +$db->exec('DELETE FROM `msz_changelog_changes`'); +$db->exec('ALTER TABLE `msz_changelog_changes` AUTO_INCREMENT = 1'); + +mkv_log('Preparing changelog changes statements...'); +$cc = $db->prepare('INSERT INTO `msz_changelog_changes` (`user_id`, `change_action`, `change_created`, `change_log`, `change_text`) VALUES (:user, :action, FROM_UNIXTIME(:created), :log, :text)'); +$ctt = $db->prepare('REPLACE INTO `msz_changelog_change_tags` (`change_id`, `tag_id`) VALUES (:change, :tag)'); + +$max = mt_rand(1000, 10000); +mkv_log('Inserting ' . $max . ' changelog entries...'); +for($i = 0; $i < $max; ++$i) { + mkv_log('Inserting bogus change ' . $i . '...'); + $userId = mt_rand(-100, 2000); + if($userId < 1) + $userId = null; + $cc->bind('user', $userId); + $cc->bind('action', mt_rand(0, 6)); + $cc->bind('created', mt_rand(1, 0x7FFFFFFF)); + $cc->bind('log', mb_substr($changeLogs->generate(), 0, 240, 'utf-8')); + $cc->bind('text', mt_rand(0, 100) > 90 ? mb_substr($changeTexts->generate(), 0, 60000, 'utf-8') : null); + $cc->execute(); + + $ctt->bind('change', $db->lastId()); + + for($j = 0; $j < mt_rand(1, 5); ++$j) { + $btag = $cTagIds[array_rand($cTagIds)]; + mkv_log('Adding tag ' . $btag . ' to bogus change ' . $i . '...'); + $ctt->bind('tag', $btag); + $ctt->execute(); + } +} + +mkv_log('Opening news category markov dictionaries...'); +$newsCatsNames = new MarkovDictionary(MKV_DICTS . '/news_cats_names.fmk'); +$newsCatsDescs = new MarkovDictionary(MKV_DICTS . '/news_cats_descs.fmk'); + +mkv_log('Nuking news categories table...'); +$db->exec('DELETE FROM `msz_news_categories`'); +$db->exec('ALTER TABLE `msz_news_categories` AUTO_INCREMENT = 1'); + +mkv_log('Preparing news categories insert statements...'); +$nc = $db->prepare('INSERT INTO `msz_news_categories` (`category_name`, `category_description`, `category_is_hidden`) VALUES (:name, :descr, :hidden)'); +$ncIds = []; + +for($i = 0; $i < 10; ++$i) { + mkv_log('Creating bogus news category ' . $i . '...'); + $nc->bind('name', mb_substr($newsCatsNames->generate(), 0, 200, 'utf-8')); + $nc->bind('descr', mb_substr($newsCatsDescs->generate(), 0, 60000, 'utf-8')); + $nc->bind('hidden', mt_rand(0, 1)); + $nc->execute(); + $ncIds[] = $db->lastId(); +} + +mkv_log('Opening news post markov dictionaries...'); +$newsPostsTitles = new MarkovDictionary(MKV_DICTS . '/news_posts_titles.fmk'); +$newsPostsTexts = new MarkovDictionary(MKV_DICTS . '/news_posts_texts.fmk'); + +mkv_log('Nuking news posts table...'); +$db->exec('DELETE FROM `msz_news_posts`'); +$db->exec('ALTER TABLE `msz_news_posts` AUTO_INCREMENT = 1'); + +mkv_log('Preparing news posts table...'); +$np = $db->prepare('INSERT INTO `msz_news_posts` (`category_id`, `user_id`, `post_is_featured`, `post_title`, `post_text`) VALUES (:category, :user, :featured, :title, :text)'); + +for($i = 0; $i < 200; ++$i) { + mkv_log('Creating bogus news post ' . $i . '...'); + $np->bind('category', $ncIds[array_rand($ncIds)]); + $np->bind('user', mt_rand(1, 2000)); + $np->bind('featured', mt_rand(0, 1)); + $np->bind('title', mb_substr($newsPostsTitles->generate(), 0, 200, 'utf-8')); + $np->bind('text', mb_substr($newsPostsTexts->generate(), 0, 60000, 'utf-8')); + $np->execute(); +} + +mkv_log('Opening forum category markov dictionaries...'); +$forumCatsNames = new MarkovDictionary(MKV_DICTS . '/forums_cats_names.fmk'); +$forumCatsDescs = new MarkovDictionary(MKV_DICTS . '/forums_cats_descs.fmk'); + +mkv_log('Nuking forum category table...'); +$db->exec('DELETE FROM `msz_forum_categories`'); +$db->exec('ALTER TABLE `msz_forum_categories` AUTO_INCREMENT = 1'); + +mkv_log('Inserting 5 root categories and permissions...'); +for($i = 0; $i < 5; ++$i) { + mkv_log('Inserting bogus category ' . $i . '...'); + $ic = $db->prepare('INSERT INTO `msz_forum_categories` (`forum_name`, `forum_type`) VALUES (:name, 1)'); + $ic->bind('name', mb_substr($forumCatsNames->generate(), 0, 240, 'utf-8')); + $ic->execute(); + + mkv_log('Inserting permissions for bogus category ' . $i . '...'); + $ip = $db->prepare('INSERT INTO `msz_forum_permissions` (`forum_id`, `forum_perms_allow`) VALUES (:cat, 3)'); + $ip->bind('cat', $i + 1); + $ip->execute(); +} + +$categories = mt_rand(20, 40); +mkv_log('Inserting ' . $categories . ' forum sections...'); + +$catIds = []; +for($i = 0; $i < $categories; ++$i) { + mkv_log('Inserting bogus forum section ' . $i . '...'); + $ic = $db->prepare('INSERT INTO `msz_forum_categories` (`forum_name`, `forum_type`, `forum_description`, `forum_parent`) VALUES (:name, 0, :desc, :parent)'); + $ic->bind('name', mb_substr($forumCatsNames->generate(), 0, 240, 'utf-8')); + $ic->bind('desc', mb_substr($forumCatsDescs->generate(), 0, 1200, 'utf-8')); + $ic->bind('parent', mt_rand(1, 5)); + $ic->execute(); + $catIds[] = $db->lastId(); +} + +mkv_log('Opening forum topic title markov dictionary...'); +$forumTopicsTitles = new MarkovDictionary(MKV_DICTS . '/forums_topics_titles.fmk'); + +mkv_log('Nuking forum topics table...'); +$db->exec('DELETE FROM `msz_forum_topics`'); +$db->exec('ALTER TABLE `msz_forum_topics` AUTO_INCREMENT = 1'); + +mkv_log('Preparing forum topic insertion statement...'); +$ft = $db->prepare('INSERT INTO `msz_forum_topics` (`forum_id`, `user_id`, `topic_type`, `topic_title`, `topic_count_views`, `topic_created`, `topic_bumped`, `topic_deleted`, `topic_locked`) VALUES (:cat, :user, :type, :title, :views, FROM_UNIXTIME(:created), FROM_UNIXTIME(:bumped), FROM_UNIXTIME(:deleted), FROM_UNIXTIME(:locked))'); + +$topics = mt_rand(200, 2000); +mkv_log('Creating ' . $topics . ' bogus forum topics...'); + +$topIds = []; +for($i = 0; $i < $topics; ++$i) { + mkv_log('Creating bogus topic ' . $i . '...'); + $userId = mt_rand(-100, 2000); + if($userId < 1) + $userId = null; + $type = mt_rand(-1000, 2); + if($type < 1) + $type = 0; + $ft->bind('cat', $catIds[array_rand($catIds)]); + $ft->bind('user', $userId); + $ft->bind('type', $type); + $ft->bind('title', mb_substr($forumTopicsTitles->generate(), 0, 240, 'utf-8')); + $ft->bind('views', mt_rand(0, 10000)); + $ft->bind('created', mt_rand(1, 0x7FFFFFFF)); + $ft->bind('bumped', mt_rand(1, 0x7FFFFFFF)); + $ft->bind('deleted', mt_rand(0, 10000) > 9999 ? mt_rand(1, 0x7FFFFFFF) : null); + $ft->bind('locked', mt_rand(0, 10000) > 9900 ? mt_rand(1, 0x7FFFFFFF) : null); + $ft->execute(); + $topIds[] = $db->lastId(); +} + +mkv_log('Opening forum post text markov dictionary...'); +$forumPostsTexts = new MarkovDictionary(MKV_DICTS . '/forums_posts_texts.fmk'); + +mkv_log('Nuking forum posts table...'); +$db->exec('DELETE FROM `msz_forum_posts`'); +$db->exec('ALTER TABLE `msz_forum_posts` AUTO_INCREMENT = 1'); + +mkv_log('Preparing forum post insertion statement...'); +$fp = $db->prepare('INSERT INTO `msz_forum_posts` (`topic_id`, `forum_id`, `user_id`, `post_ip`, `post_text`, `post_parse`, `post_display_signature`, `post_created`, `post_edited`, `post_deleted`) VALUES (:topic, 1, :user, :addr, :text, :parse, :sig, FROM_UNIXTIME(:created), FROM_UNIXTIME(:edited), FROM_UNIXTIME(:deleted))'); + +$topCount = count($topIds); +for($t = 0; $t < $topCount; ++$t) { + $posts = mt_rand(1, 600); + $topId = $topIds[$t]; + + mkv_log('Inserting ' . $posts . ' bogus forum posts for bogus topic ' . $topId . '...'); + + $fp->bind('topic', $topId); + + for($i = 0; $i < $posts; ++$i) { + mkv_log('Inserting bogus post ' . $i . ' into bogus topic ' . $topId . '...'); + + $userId = mt_rand(-100, 2000); + if($userId < 1) + $userId = null; + $fp->bind('user', $userId); + $fp->bind('addr', random_bytes(mt_rand(0, 1) ? 4 : 16)); + $fp->bind('text', mb_substr($forumPostsTexts->generate(), 0, 60000, 'utf-8')); + $fp->bind('parse', mt_rand(0, 2)); + $fp->bind('sig', mt_rand(0, 1000) > 900 ? 0 : 1); + $fp->bind('created', mt_rand(1, 0x7FFFFFFF)); + $fp->bind('created', mt_rand(1, 0x7FFFFFFF)); + $fp->bind('edited', mt_rand(0, 1000) > 900 ? mt_rand(1, 0x7FFFFFFF) : null); + $fp->bind('deleted', mt_rand(0, 10000) > 9000 ? mt_rand(1, 0x7FFFFFFF) : null); + $fp->execute(); + } +} + +mkv_log('Running slow cron once more...'); + +// running cron after fuckery +(new \Misuzu\Console\Commands\CronCommand)->dispatch( + new \Misuzu\Console\CommandArgs(['--slow']) +); + +mkv_log('Done! Enjoy your garbage filled forum.'); diff --git a/devel/misuzu/config.ini b/devel/misuzu/config.ini new file mode 100644 index 0000000..cc392c5 --- /dev/null +++ b/devel/misuzu/config.ini @@ -0,0 +1,7 @@ +[Database] +driver = mysql +unix_socket = /var/run/mysqld/mysqld.sock +username = misuzu +password = toastiscool100 +dbname = misuzu +charset = utf8mb4 diff --git a/devel/nginx/fastcgi_params b/devel/nginx/fastcgi_params new file mode 100644 index 0000000..ac70fd5 --- /dev/null +++ b/devel/nginx/fastcgi_params @@ -0,0 +1,35 @@ +fastcgi_param QUERY_STRING $query_string; +fastcgi_param REQUEST_METHOD $request_method; +fastcgi_param CONTENT_TYPE $content_type; +fastcgi_param CONTENT_LENGTH $content_length; + +#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; +fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; +fastcgi_param SCRIPT_NAME $fastcgi_script_name; +fastcgi_param REQUEST_URI $request_uri; +fastcgi_param DOCUMENT_URI $document_uri; +#fastcgi_param DOCUMENT_ROOT $document_root; +fastcgi_param DOCUMENT_ROOT $realpath_root; +fastcgi_param SERVER_PROTOCOL $server_protocol; +fastcgi_param REQUEST_SCHEME $scheme; +fastcgi_param HTTPS $https if_not_empty; +fastcgi_param PATH_INFO $fastcgi_path_info; +fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; + +fastcgi_param GATEWAY_INTERFACE CGI/1.1; +fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; + +fastcgi_param REMOTE_ADDR $remote_addr; +fastcgi_param REMOTE_PORT $remote_port; +fastcgi_param SERVER_ADDR $server_addr; +fastcgi_param SERVER_PORT $server_port; +fastcgi_param SERVER_NAME $server_name; + +fastcgi_param REDIRECT_STATUS 200; + +fastcgi_connect_timeout 60; +fastcgi_send_timeout 180; +fastcgi_read_timeout 180; +fastcgi_buffers 256 4k; +fastcgi_busy_buffers_size 256k; +fastcgi_temp_file_write_size 256k; diff --git a/devel/nginx/mime.types b/devel/nginx/mime.types new file mode 100644 index 0000000..8fdfaef --- /dev/null +++ b/devel/nginx/mime.types @@ -0,0 +1,94 @@ +types { + text/html html htm shtml; + text/css css; + text/xml xml; + image/gif gif; + image/jpeg jpeg jpg; + application/javascript js; + application/atom+xml atom; + application/rss+xml rss; + application/wasm wasm; + + text/mathml mml; + text/plain txt; + text/vnd.sun.j2me.app-descriptor jad; + text/vnd.wap.wml wml; + text/x-component htc; + + image/png png; + image/tiff tif tiff; + image/vnd.wap.wbmp wbmp; + image/x-icon ico; + image/x-jng jng; + image/x-ms-bmp bmp; + image/svg+xml svg svgz; + image/webp webp; + + application/font-woff woff; + application/java-archive jar war ear; + application/json json; + application/mac-binhex40 hqx; + application/msword doc; + application/pdf pdf; + application/postscript ps eps ai; + application/rtf rtf; + application/vnd.apple.mpegurl m3u8; + application/vnd.ms-excel xls; + application/vnd.ms-fontobject eot; + application/vnd.ms-powerpoint ppt; + application/vnd.wap.wmlc wmlc; + application/vnd.google-earth.kml+xml kml; + application/vnd.google-earth.kmz kmz; + application/x-7z-compressed 7z; + application/x-cocoa cco; + application/x-java-archive-diff jardiff; + application/x-java-jnlp-file jnlp; + application/x-makeself run; + application/x-perl pl pm; + application/x-pilot prc pdb; + application/x-rar-compressed rar; + application/x-redhat-package-manager rpm; + application/x-sea sea; + application/x-shockwave-flash swf; + application/x-stuffit sit; + application/x-tcl tcl tk; + application/x-x509-ca-cert der pem crt; + application/x-xpinstall xpi; + application/xhtml+xml xhtml; + application/xspf+xml xspf; + application/zip zip; + + application/octet-stream bin exe dll; + application/octet-stream deb; + application/octet-stream dmg; + application/octet-stream iso img; + application/octet-stream msi msp msm; + + application/vnd.openxmlformats-officedocument.wordprocessingml.document docx; + application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx; + application/vnd.openxmlformats-officedocument.presentationml.presentation pptx; + + audio/midi mid midi kar; + audio/mpeg mp3; + audio/ogg ogg; + audio/x-m4a m4a; + audio/x-realaudio ra; + audio/opus opus; + audio/x-caf caf; + + video/3gpp 3gpp 3gp; + video/mp2t ts; + video/mp4 mp4; + video/mpeg mpeg mpg; + video/quicktime mov; + video/webm webm; + video/x-flv flv; + video/x-m4v m4v; + video/x-mng mng; + video/x-ms-asf asx asf; + video/x-ms-wmv wmv; + video/x-msvideo avi; + + font/ttf ttf; + font/otf otf; +} diff --git a/devel/nginx/nginx.conf b/devel/nginx/nginx.conf new file mode 100644 index 0000000..cddc6ff --- /dev/null +++ b/devel/nginx/nginx.conf @@ -0,0 +1,91 @@ +user vagrant; +worker_processes auto; +pid /var/run/nginx.pid; + +events { + worker_connections 768; +} + +http { + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + server_tokens off; + + charset utf-8; + + gzip on; + gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; + + include mime.types; + default_type application/octet-stream; + + client_max_body_size 100M; + disable_symlinks off; + + add_header X-Content-Type-Options nosniff; + add_header X-XSS-Protection "1; mode=block"; + + ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; + ssl_prefer_server_ciphers on; + ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS'; + ssl_ecdh_curve secp384r1; + ssl_session_cache shared:SSL:10m; + ssl_session_tickets off; + ssl_stapling on; + ssl_stapling_verify on; + ssl_dhparam dhparam.pem; + + error_log /var/log/nginx/error.log crit; + + server { + root /www/misuzu/public; + server_name misuzu; + index index.php; + + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + location ~* \.(eot|otf|ttf|woff|woff2)$ { + add_header Access-Control-Allow-Origin *; + } + + location /msz-storage { + alias /www/misuzu/store; + internal; + } + + listen 80; + listen 443 ssl; + listen [::]:80; + listen [::]:443 ssl; + + location = /favicon.ico { + log_not_found off; + access_log off; + } + + location = /robots.txt { + log_not_found off; + access_log off; + } + + ssl_certificate misuzu.crt; + ssl_certificate_key misuzu.key; + + location ~ [^/]\.php(/|$) { + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + + if (!-f $document_root$fastcgi_script_name) { + return 404; + } + + fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; + fastcgi_index index.php; + include fastcgi_params; + } + } +} diff --git a/devel/sample/MarkovDictionary.php b/devel/sample/MarkovDictionary.php new file mode 100644 index 0000000..ec2a8a1 --- /dev/null +++ b/devel/sample/MarkovDictionary.php @@ -0,0 +1,115 @@ +handle = $handle = fopen($path, 'rb'); + + $magic = fread($handle, 4); + if($magic !== self::MAGIC) + throw new InvalidArgumentException('$path is not a valid markov dictionary.'); + + $header = fread($handle, 12); + if(strlen($header) !== 12) + throw new InvalidArgumentException('$path is missing header data.'); + + extract(unpack('Cversion/Cunused1/Cunused2/CsegmentSize/VtotalSegments/VstartSegments', $header)); + + if($version !== self::VERSION) + throw new InvalidArgumentException('$path version is incompatible.'); + + $this->segmentSize = $segmentSize; + $this->totalSegments = $totalSegments; + $this->startSegments = $startSegments; + } + + public function close(): void { + if($this->handle !== null) { + fclose($this->handle); + $this->handle = null; + } + } + + public function __destruct() { + $this->close(); + } + + private function reset(): void { + fseek($this->handle, 16, SEEK_SET); + } + + public function getStartPosition(): int { + $randomStart = mt_rand(0, $this->startSegments) - 2; + if($randomStart > 0) { + for(;;) { + fseek($this->handle, 4 * $this->segmentSize, SEEK_CUR); + $isStart = fgetc($this->handle) !== "\0"; + + if($isStart) { + if($randomStart < 1) + break; + --$randomStart; + } + + extract(unpack('vnextSegments', fread($this->handle, 2))); + + fseek($this->handle, 6 * $nextSegments, SEEK_CUR); + } + + fseek($this->handle, -(4 * $this->segmentSize) - 1, SEEK_CUR); + } + + $startPos = ftell($this->handle); + $this->reset(); + + return $startPos; + } + + public function generate(int $safety = 2000, int $start = -1): string { + if($start < 0) + $start = $this->getStartPosition(); + + fseek($this->handle, $start, SEEK_SET); + + $string = ''; + + for($s = 0; $s < $safety; ++$s) { + $string .= fread($this->handle, 4 * $this->segmentSize); + + fseek($this->handle, 1, SEEK_CUR); + + extract(unpack('vnextSegments', fread($this->handle, 2))); + + if($nextSegments < 1) + break; + + $nexts = []; + + // really shitty weighting system + for($i = 0; $i < $nextSegments; ++$i) { + extract(unpack('Voffset/vweight', fread($this->handle, 6))); + + for($j = 0; $j < $weight; ++$j) + $nexts[] = $offset; + } + + $offset = $nexts[array_rand($nexts)]; + + fseek($this->handle, $offset, SEEK_SET); + } + + $this->reset(); + $string = mb_convert_encoding($string, 'utf-8', 'utf-32le'); + + return trim($string); + } +} diff --git a/devel/sample/dicts/changes_logs.fmk b/devel/sample/dicts/changes_logs.fmk new file mode 100644 index 0000000..f687c0d Binary files /dev/null and b/devel/sample/dicts/changes_logs.fmk differ diff --git a/devel/sample/dicts/changes_tags_descs.fmk b/devel/sample/dicts/changes_tags_descs.fmk new file mode 100644 index 0000000..3b2500a Binary files /dev/null and b/devel/sample/dicts/changes_tags_descs.fmk differ diff --git a/devel/sample/dicts/changes_tags_names.fmk b/devel/sample/dicts/changes_tags_names.fmk new file mode 100644 index 0000000..15b9e82 Binary files /dev/null and b/devel/sample/dicts/changes_tags_names.fmk differ diff --git a/devel/sample/dicts/changes_texts.fmk b/devel/sample/dicts/changes_texts.fmk new file mode 100644 index 0000000..e6afebc Binary files /dev/null and b/devel/sample/dicts/changes_texts.fmk differ diff --git a/devel/sample/dicts/comments_texts.fmk b/devel/sample/dicts/comments_texts.fmk new file mode 100644 index 0000000..e03753c Binary files /dev/null and b/devel/sample/dicts/comments_texts.fmk differ diff --git a/devel/sample/dicts/forums_cats_descs.fmk b/devel/sample/dicts/forums_cats_descs.fmk new file mode 100644 index 0000000..b37bd22 Binary files /dev/null and b/devel/sample/dicts/forums_cats_descs.fmk differ diff --git a/devel/sample/dicts/forums_cats_names.fmk b/devel/sample/dicts/forums_cats_names.fmk new file mode 100644 index 0000000..a3e346e Binary files /dev/null and b/devel/sample/dicts/forums_cats_names.fmk differ diff --git a/devel/sample/dicts/forums_posts_texts.fmk b/devel/sample/dicts/forums_posts_texts.fmk new file mode 100644 index 0000000..aa12504 Binary files /dev/null and b/devel/sample/dicts/forums_posts_texts.fmk differ diff --git a/devel/sample/dicts/forums_topics_titles.fmk b/devel/sample/dicts/forums_topics_titles.fmk new file mode 100644 index 0000000..1d0e75a Binary files /dev/null and b/devel/sample/dicts/forums_topics_titles.fmk differ diff --git a/devel/sample/dicts/news_cats_descs.fmk b/devel/sample/dicts/news_cats_descs.fmk new file mode 100644 index 0000000..54e539f Binary files /dev/null and b/devel/sample/dicts/news_cats_descs.fmk differ diff --git a/devel/sample/dicts/news_cats_names.fmk b/devel/sample/dicts/news_cats_names.fmk new file mode 100644 index 0000000..24caebf Binary files /dev/null and b/devel/sample/dicts/news_cats_names.fmk differ diff --git a/devel/sample/dicts/news_posts_texts.fmk b/devel/sample/dicts/news_posts_texts.fmk new file mode 100644 index 0000000..5810fdd Binary files /dev/null and b/devel/sample/dicts/news_posts_texts.fmk differ diff --git a/devel/sample/dicts/news_posts_titles.fmk b/devel/sample/dicts/news_posts_titles.fmk new file mode 100644 index 0000000..4e5184d Binary files /dev/null and b/devel/sample/dicts/news_posts_titles.fmk differ diff --git a/devel/sample/dicts/roles_descs.fmk b/devel/sample/dicts/roles_descs.fmk new file mode 100644 index 0000000..439ca9f Binary files /dev/null and b/devel/sample/dicts/roles_descs.fmk differ diff --git a/devel/sample/dicts/roles_names.fmk b/devel/sample/dicts/roles_names.fmk new file mode 100644 index 0000000..71565c0 Binary files /dev/null and b/devel/sample/dicts/roles_names.fmk differ diff --git a/devel/sample/dicts/roles_titles.fmk b/devel/sample/dicts/roles_titles.fmk new file mode 100644 index 0000000..46ec948 Binary files /dev/null and b/devel/sample/dicts/roles_titles.fmk differ diff --git a/devel/sample/dicts/users_abouts.fmk b/devel/sample/dicts/users_abouts.fmk new file mode 100644 index 0000000..fc98d38 Binary files /dev/null and b/devel/sample/dicts/users_abouts.fmk differ diff --git a/devel/sample/dicts/users_names.fmk b/devel/sample/dicts/users_names.fmk new file mode 100644 index 0000000..e4a8b76 Binary files /dev/null and b/devel/sample/dicts/users_names.fmk differ diff --git a/devel/sample/dicts/users_sigs.fmk b/devel/sample/dicts/users_sigs.fmk new file mode 100644 index 0000000..16bda6c Binary files /dev/null and b/devel/sample/dicts/users_sigs.fmk differ diff --git a/devel/sample/dicts/users_titles.fmk b/devel/sample/dicts/users_titles.fmk new file mode 100644 index 0000000..0254f82 Binary files /dev/null and b/devel/sample/dicts/users_titles.fmk differ diff --git a/devel/set-random-avatars.php b/devel/set-random-avatars.php new file mode 100644 index 0000000..4235e19 --- /dev/null +++ b/devel/set-random-avatars.php @@ -0,0 +1,27 @@ +getId(), $user->getUsername(), PHP_EOL); + + if(mt_rand(0, 1000) > 950) { + printf('[%s] Skipping this one.%s', date('H:i:s'), PHP_EOL); + continue; + } + + printf('[%s] Downloading image from %s...%s', date('H:i:s'), SRA_URL, PHP_EOL); + $data = file_get_contents(SRA_URL); + + printf('[%s] Applying through stupid roundabout method...%s', date('H:i:s'), PHP_EOL); + $user->getAvatarInfo()->setFromData($data); +} diff --git a/devel/setup-devbox.sh b/devel/setup-devbox.sh new file mode 100644 index 0000000..85d5351 --- /dev/null +++ b/devel/setup-devbox.sh @@ -0,0 +1,157 @@ +#!/usr/bin/env bash + +# this is only intended for the vagrant shit +# for the love of god don't run this on anything but that +# configuration is almost identical to production + +echo -e "> Misuzu Vagrant Auto Configurator " +echo -e "" + +echo -e "=> Installing apt requirements" +apt-get update +apt-get install -y software-properties-common dirmngr apt-transport-https + +echo -e "=> Adding PHP PPA" +add-apt-repository -y ppa:ondrej/php + +echo -e "=> Adding MariaDB 10.6 repostiory" +apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc' +add-apt-repository -y 'deb [arch=amd64,arm64,ppc64el,s390x] https://ftp.nluug.nl/db/mariadb/repo/10.6/ubuntu focal main' + +echo -e "=> Performing full package upgrade" +apt-get update +apt-get full-upgrade -y + +echo -e "=> Installing required packages" +apt-get install -y nginx-full mariadb-server-10.6 openssl git \ + php8.1 php8.1-bcmath php8.1-cli php8.1-common php8.1-curl php8.1-dev \ + php8.1-fpm php8.1-gd php8.1-igbinary php8.1-imagick php8.1-intl \ + php8.1-ldap php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-readline \ + php8.1-redis php8.1-sqlite3 php8.1-xml php8.1-zip + +SSL_DHPARAM=/vagrant/devel/nginx/dhparam.pem +SSL_CRT=/vagrant/devel/nginx/misuzu.crt +SSL_KEY=/vagrant/devel/nginx/misuzu.key + +echo -e "=> Generating dhparam.pem" +[ -f "$SSL_DHPARAM" ] || openssl dhparam -out $SSL_DHPARAM 2048 + +echo -e "=> Generating SSL certificate" +[ -f "$SSL_CRT" ] || [ -f "$SSL_KEY" ] || openssl req -subj '/O=Flashii/C=NL/CN=localhost' -new -newkey rsa:2048 -sha256 -days 9001 -nodes -x509 -keyout $SSL_KEY -out $SSL_CRT + +echo -e "=> Replacing NGINX configuration" + +echo -e "==> Removing existing configuration folder" +rm -rf /etc/nginx + +echo -e "==> Linking Misuzu config folder" +ln -fs /vagrant/devel/nginx /etc/nginx + +echo -e "==> Restarting NGINX" +service nginx restart + +echo -e "=> Adjusting PHP configuration" + +echo -e "==> Set display_startup_errors to On" +sed -i 's/display_startup_errors = Off/display_startup_errors = On/g' /etc/php/8.1/fpm/php.ini + +echo -e "==> Increase max upload size to 150M" +sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 150M/g' /etc/php/8.1/fpm/php.ini + +echo -e "==> Increase max body size to 150M" +sed -i 's/post_max_size = 8M/post_max_size = 150M/g' /etc/php/8.1/fpm/php.ini + +echo -e "==> Change FPM user to vagrant" +sed -i 's/user = www-data/user = vagrant/g' /etc/php/8.1/fpm/pool.d/www.conf +sed -i 's/listen.owner = www-data/listen.owner = vagrant/g' /etc/php/8.1/fpm/pool.d/www.conf + +echo -e "==> Change FPM group to vagrant" +sed -i 's/group = www-data/group = vagrant/g' /etc/php/8.1/fpm/pool.d/www.conf +sed -i 's/listen.group = www-data/listen.group = vagrant/g' /etc/php/8.1/fpm/pool.d/www.conf + +echo -e "==> Restarting PHP-FPM" +service php8.1-fpm restart + +echo -e "=> Adjusting MariaDB configuration" + +echo -e "==> Bind to all addresses" +sed -i 's/= 127.0.0.1/= 0.0.0.0/g' /etc/mysql/mariadb.conf.d/50-server.cnf +service mysql restart + +echo -e "==> Creating MariaDB database" +mysql -vv -e "CREATE DATABASE misuzu COLLATE 'utf8mb4_bin'" + +echo -e "==> Creating MariaDB user" +mysql -vv -e "CREATE USER 'misuzu'@'localhost' IDENTIFIED BY 'toastiscool100'" +mysql -vv -e "CREATE USER 'misuzu'@'%' IDENTIFIED BY 'toastiscool100'" + +echo -e "==> Granting database access to MariaDB user" +mysql -vv -e "GRANT EXECUTE, SELECT, SHOW VIEW, ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, INDEX, INSERT, REFERENCES, TRIGGER, UPDATE, LOCK TABLES ON misuzu.* TO 'misuzu'@'localhost'" +mysql -vv -e "GRANT EXECUTE, SELECT, SHOW VIEW, ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, INDEX, INSERT, REFERENCES, TRIGGER, UPDATE, LOCK TABLES ON misuzu.* TO 'misuzu'@'%'" + +echo -e "==> Reloading MariaDB privileges" +mysql -vv -e "FLUSH PRIVILEGES" + +# Taken from https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md +# Remove when composer dependencies are dropkicked + +echo -e "=> Installing Composer" + +echo -e "==> Fetching expecting checksum" +EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')" + +echo -e "==> Downloading installer" +php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" + +echo -e "==> Hashing installer" +ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")" + +echo -e "==> Confirming checksum" +if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ] +then + >&2 echo 'ERROR: Invalid installer checksum' + rm composer-setup.php + exit 1 +fi + +echo -e "==> Installing to /bin/composer" +php composer-setup.php --quiet --install-dir=/bin --filename=composer + +echo -e "==> Removing installer" +rm composer-setup.php +# End of composer things + +echo -e "=> Adjusting Misuzu configuration" + +MSZ_CONFIG=/vagrant/config/config.ini + +echo -e "==> Replacing Misuzu config.ini" +rm $MSZ_CONFIG +cp /vagrant/devel/misuzu/config.ini $MSZ_CONFIG + +echo -e "==> Updating Git submodules" +sudo -u vagrant git -C /vagrant submodule update --init + +# ENTER: JANK +echo -e "==> Enable Misuzu debug mode" +sudo -u vagrant touch /vagrant/.debug + +echo -e "==> Running composer install as vagrant" +sudo -u vagrant composer install -d /vagrant + +echo -e "==> Adding frequent cron jobs as vagrant" +(sudo -u vagrant crontab -l 2>/dev/null; echo "0,10,20,30,40 * * * * php8.1 /www/misuzu/msz cron") | sudo -u vagrant crontab - + +echo -e "==> Adding infrequent cron jobs as vagrant" +(sudo -u vagrant crontab -l 2>/dev/null; echo "50 * * * * php8.1 /www/misuzu/msz cron --slow") | sudo -u vagrant crontab - + +echo -e "==> Nuking /www" +rm -rf /www + +echo -e "==> Creating /www" +mkdir /www + +echo -e "==> Linking /vagrant to /www/misuzu" +ln -fs /vagrant /www/misuzu + +echo -e "Done!" diff --git a/docs/contact.md b/docs/contact.md new file mode 100644 index 0000000..40fc0ed --- /dev/null +++ b/docs/contact.md @@ -0,0 +1,23 @@ +# Contact + +If you need to reach us outside of this website, this is the page for you. Below are a few ways of contact. + +## E-mail + - [flash](mailto:flashii@flash.moe): Site Administrator + +## Twitter + - [@flashiinet](https://twitter.com/flashiinet): General updates and conversation. + - [@flashiistatus](https://twitter.com/flashiistatus): Exclusively system status updates, posts by this accounts are generally retweeted by @flashiinet. + - [@smugwave](https://twitter.com/smugwave): Twitter of the owner, proceed with caution! + +## Source Code + - [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. + - [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. + - [Hamakaze](https://git.flash.moe/flash/hamakaze): HTTP and WebSocket library used by Sharp Chat and Satori. diff --git a/docs/rules.md b/docs/rules.md new file mode 100644 index 0000000..1e2d129 --- /dev/null +++ b/docs/rules.md @@ -0,0 +1,63 @@ +# Rules + +## Global Rules +All of these rules are in effect on any place on the site unless explicitly stated otherwise. + +1. **Spamming/flooding is not allowed unless otherwise stated.** +One-off jokes are fine, don't overdo it. + +1. **Be decent towards each other.** +Respect is not a given but that does not make for an excuse for baseless antagonisation. + +1. **If you have a problem with someone, point it out.** +Don't be passive aggressive. + +1. **NSFW content is disallowed unless otherwise stated.** +This includes anything sexually suggestive. + +1. **Content considered illegal in the United States and/or the Netherlands is never allowed.** +The server is hosted in the Netherlands and the majority user base is in the United States. +There will never be exceptions to this. + +1. **Users may only have a single account.** +Flashii provides a number of services where having multiple accounts could grant unfair advantages. +Exceptions may be granted for bot accounts. + +1. **Keep political discussions to an absolute minimum.** +There is a time and place for it, but Flashii is intended to be a footloose and fancy-free community. +Moderator intervention will be used for petty shouting matches. + +1. **You must be at least 18 years of age on the Gregorian calendar.** +When validating this a staff member will always ask this in a direct message, never in public channels. + +1. **Link shorteners are not allowed.** +Harmless links will result in a warning, malicious links will result in a ban. + +1. **Self promotion is not allowed.** +You CAN show off your creations, however blatant advertising _not relevant to a conversation/channel topic_ is not allowed. + +## Forum Rules +1. **Defacing posts is not allowed.** +If you blank one of your posts, it will be restored and you will be warned. +If you have a legitimate reason for this, talk to a staff member. + +1. **Abusing post formatting tools is not allowed.** +This includes using a persistent font colour as an "avatar", but excludes making a flashy opening post to your topic. + +## Chat Rules +1. **Persistent typing quirks are not allowed.** +This applies where Global Rule 1 applies. + +1. **Try to keep topics to their own channels** +If a lengthy discussion shifts to a topic that has its own channel, try to move the discussion to that channel. Action will be taken only for repeated, flagrant offences. + +## Game Service Rules +1. **Play fairly.** +Do not use exploits to gain unfair advantages. + +## What happens if I break rules? +Major offenses will result in a ban. +Minor offenses will result in warnings; however, after five warnings you will be banned. +A warning is retained for ninety (90) days. +Depending on moderator discretion, you may be banned prior to five warnings, and this warning threshold may change at any time. +Permanent bans are reserved for serious or blatantly repetitious violations, and will be issued by administrators. diff --git a/lib/index b/lib/index new file mode 160000 index 0000000..ac2255d --- /dev/null +++ b/lib/index @@ -0,0 +1 @@ +Subproject commit ac2255d24d7dd39ac91fa50d3a7aa71ce0a92188 diff --git a/misuzu.php b/misuzu.php new file mode 100644 index 0000000..1b49251 --- /dev/null +++ b/misuzu.php @@ -0,0 +1,245 @@ + Config::get('mail.host', Config::TYPE_STR), + 'port' => Config::get('mail.port', Config::TYPE_INT, 25), + 'username' => Config::get('mail.username', Config::TYPE_STR), + 'password' => Config::get('mail.password', Config::TYPE_STR), + 'encryption' => Config::get('mail.encryption', Config::TYPE_STR), + 'sender_name' => Config::get('mail.sender.name', Config::TYPE_STR), + 'sender_addr' => Config::get('mail.sender.address', Config::TYPE_STR), +]); + +// replace this with a better storage mechanism +define('MSZ_STORAGE', Config::get('storage.path', Config::TYPE_STR, MSZ_ROOT . '/store')); +if(!is_dir(MSZ_STORAGE)) + mkdir(MSZ_STORAGE, 0775, true); + +if(MSZ_CLI) { // Temporary backwards compatibility measure, remove this later + if(realpath($_SERVER['SCRIPT_FILENAME']) === __FILE__) { + if(($argv[1] ?? '') === 'cron' && ($argv[2] ?? '') === 'low') + $argv[2] = '--slow'; + array_shift($argv); + echo shell_exec(__DIR__ . '/msz ' . implode(' ', $argv)); + } + return; +} + +$ctx = new MszContext(DB::getInstance()); + +// Everything below here should eventually be moved to index.php, probably only initialised when required. +// Serving things like the css/js doesn't need to initialise sessions. + +ob_start(); + +if(file_exists(MSZ_ROOT . '/.migrating')) { + http_response_code(503); + if(!isset($_GET['_check'])) { + header('Content-Type: text/html; charset-utf-8'); + echo file_get_contents(MSZ_TEMPLATES . '/503.html'); + } + exit; +} + +if(!is_readable(MSZ_STORAGE) || !is_writable(MSZ_STORAGE)) { + echo 'Cannot access storage directory.'; + exit; +} + +GeoIP::init(Config::get('geoip.database', Config::TYPE_STR, '/var/lib/GeoIP/GeoLite2-Country.mmdb')); + +if(!MSZ_DEBUG) { + $twigCache = sys_get_temp_dir() . '/msz-tpl-cache-' . md5(MSZ_ROOT); + if(!is_dir($twigCache)) + mkdir($twigCache, 0775, true); +} + +Template::init($twigCache ?? null, MSZ_DEBUG); + +Template::set('globals', [ + 'site_name' => Config::get('site.name', Config::TYPE_STR, 'Misuzu'), + 'site_description' => Config::get('site.desc', Config::TYPE_STR), + 'site_url' => Config::get('site.url', Config::TYPE_STR), + 'site_twitter' => Config::get('social.twitter', Config::TYPE_STR), +]); + +Template::addPath(MSZ_TEMPLATES); + +if(isset($_COOKIE['msz_uid']) && isset($_COOKIE['msz_sid'])) { + $authToken = (new AuthToken) + ->setUserId(filter_input(INPUT_COOKIE, 'msz_uid', FILTER_SANITIZE_NUMBER_INT) ?? 0) + ->setSessionToken(filter_input(INPUT_COOKIE, 'msz_sid') ?? ''); + + if($authToken->isValid()) + setcookie('msz_auth', $authToken->pack(), strtotime('1 year'), '/', msz_cookie_domain(), !empty($_SERVER['HTTPS']), true); + + setcookie('msz_uid', '', -3600, '/', '', !empty($_SERVER['HTTPS']), true); + setcookie('msz_sid', '', -3600, '/', '', !empty($_SERVER['HTTPS']), true); +} + +if(!isset($authToken)) + $authToken = AuthToken::unpack(filter_input(INPUT_COOKIE, 'msz_auth') ?? ''); + +if($authToken->isValid()) { + try { + $sessionInfo = $authToken->getSession(); + if($sessionInfo->hasExpired()) { + $sessionInfo->delete(); + } elseif($sessionInfo->getUserId() === $authToken->getUserId()) { + $userInfo = $sessionInfo->getUser(); + if(!$userInfo->isDeleted()) { + $sessionInfo->setCurrent(); + $userInfo->setCurrent(); + $sessionInfo->bump(); + + if($sessionInfo->shouldBumpExpire()) + setcookie('msz_auth', $authToken->pack(), $sessionInfo->getExpiresTime(), '/', msz_cookie_domain(), !empty($_SERVER['HTTPS']), true); + } + } + } catch(UserNotFoundException $ex) { + UserSession::unsetCurrent(); + User::unsetCurrent(); + } catch(UserSessionNotFoundException $ex) { + UserSession::unsetCurrent(); + User::unsetCurrent(); + } + + if(UserSession::hasCurrent()) { + $userInfo->bumpActivity(); + } else { + setcookie('msz_auth', '', -9001, '/', msz_cookie_domain(), !empty($_SERVER['HTTPS']), true); + setcookie('msz_auth', '', -9001, '/', '', !empty($_SERVER['HTTPS']), true); + } +} + +CSRF::setGlobalSecretKey(Config::get('csrf.secret', Config::TYPE_STR, 'soup')); +CSRF::setGlobalIdentity(UserSession::hasCurrent() ? UserSession::getCurrent()->getToken() : IPAddress::remote()); + +function mszLockdown(): void { + global $misuzuBypassLockdown; + + if(Config::get('private.enabled', Config::TYPE_BOOL)) { + $onLoginPage = $_SERVER['PHP_SELF'] === url('auth-login'); + $onPasswordPage = parse_url($_SERVER['PHP_SELF'], PHP_URL_PATH) === url('auth-forgot'); + $misuzuBypassLockdown = !empty($misuzuBypassLockdown) || $onLoginPage; + + if(!$misuzuBypassLockdown) { + if(UserSession::hasCurrent()) { + $privatePermCat = Config::get('private.perm.cat', Config::TYPE_STR); + $privatePermVal = Config::get('private.perm.val', Config::TYPE_INT); + + if(!empty($privatePermCat) && $privatePermVal > 0) { + if(!perms_check_user($privatePermCat, User::getCurrent()->getId(), $privatePermVal)) { + // au revoir + UserSession::unsetCurrent(); + User::unsetCurrent(); + } + } + } elseif(!$onLoginPage && !($onPasswordPage && Config::get('private.allow_password_reset', Config::TYPE_BOOL, true))) { + url_redirect('auth-login'); + exit; + } + } + } +} + +if(parse_url($_SERVER['PHP_SELF'], PHP_URL_PATH) !== '/index.php') + mszLockdown(); + +if(!empty($userInfo)) + Template::set('current_user', $userInfo); + +$inManageMode = str_starts_with($_SERVER['REQUEST_URI'], '/manage'); +$hasManageAccess = User::hasCurrent() + && !User::getCurrent()->hasActiveWarning() + && perms_check_user(MSZ_PERMS_GENERAL, User::getCurrent()->getId(), MSZ_PERM_GENERAL_CAN_MANAGE); +Template::set('has_manage_access', $hasManageAccess); + +if($inManageMode) { + if(!$hasManageAccess) { + echo render_error(403); + exit; + } + + Template::set('manage_menu', manage_get_menu(User::getCurrent()->getId())); +} diff --git a/msz b/msz new file mode 100644 index 0000000..7969017 --- /dev/null +++ b/msz @@ -0,0 +1,20 @@ +#!/usr/bin/env php +addCommands( + new \Misuzu\Console\Commands\CronCommand, + new \Misuzu\Console\Commands\MigrateCommand, + new \Misuzu\Console\Commands\NewMigrationCommand, + new \Misuzu\Console\Commands\TwitterAuthCommand, +); +$commands->dispatch(new CommandArgs($argv)); diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..a2e3273 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,6 @@ +parameters: + level: 5 + paths: + - src + bootstrapFiles: + - misuzu.php diff --git a/public/_github-callback.php b/public/_github-callback.php new file mode 100644 index 0000000..5b05082 --- /dev/null +++ b/public/_github-callback.php @@ -0,0 +1,146 @@ += 10 ? $line : mb_substr($line, $findColon + 1)); +} + +function ghcb_changelog_action(string &$line): int { + $original = trim($line); + $line = ghcb_strip_prefix($line); + + $firstSix = mb_strtolower(mb_substr($original, 0, 6)); + + if($firstSix === 'revert' + || $firstSix === 'restor') + return ChangelogChange::ACTION_REVERT; + if($firstSix === 'import') + return ChangelogChange::ACTION_IMPORT; + + $firstThree = mb_strtolower(mb_substr($original, 0, 3)); + + if($firstThree === 'add' + || $firstSix === 'create') + return ChangelogChange::ACTION_ADD; + if($firstThree === 'fix') + return ChangelogChange::ACTION_FIX; + + $firstFour = mb_strtolower(mb_substr($original, 0, 4)); + $firstEight = mb_strtolower(mb_substr($original, 0, 8)); + + if($firstSix === 'delete' + || $firstSix === 'remove' + || $firstFour === 'nuke' + || $firstEight === 'dropkick') + return ChangelogChange::ACTION_REMOVE; + + return ChangelogChange::ACTION_UPDATE; +} + +header('Content-Type: text/plain; charset=utf-8'); + +if($_SERVER['REQUEST_METHOD'] !== 'POST') + die('no'); + +$config = MSZ_ROOT . '/config/github.ini'; +if(!is_file($config)) + die('config missing'); + +$config = parse_ini_file(MSZ_ROOT . '/config/github.ini', true); +if(empty($config['tokens']['token'])) + die('config invalid'); + +$isGitea = isset($_SERVER['HTTP_X_GITEA_DELIVERY']) && isset($_SERVER['HTTP_X_GITEA_EVENT']); + +$rawData = file_get_contents('php://input'); +$sigParts = $isGitea + ? ['sha256', $_SERVER['HTTP_X_GITEA_SIGNATURE']] + : explode('=', $_SERVER['HTTP_X_HUB_SIGNATURE'] ?? '', 2); + +if(empty($sigParts[1])) + die('invalid signature'); + +$repoAuthenticated = false; +foreach($config['tokens']['token'] as $repoName => $repoToken) { + if(hash_equals(hash_hmac($sigParts[0], $rawData, $repoToken), $sigParts[1])) { + $repoAuthenticated = true; + break; + } +} + +if(!$repoAuthenticated) + die('signature check failed'); + +$data = json_decode($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded' + ? $_POST['payload'] + : $rawData); + +if(empty($data)) + die('body is corrupt'); + +if(empty($data->repository->full_name)) + die('body is corrupt'); + +if($data->repository->full_name !== $repoName) + die('invalid repository token'); + +if($_SERVER['HTTP_X_GITHUB_EVENT'] !== 'push') + die('only push event is supported'); + +$commitCount = count($data->commits); +if($commitCount < 1) + die('no commits received'); + +$repoInfo = $config['repo:' . $repoName] ?? []; + +$repoMaster = 'refs/heads/master'; +if(!empty($repoInfo['master'])) + $repoMaster = $repoInfo['master']; + +if($data->ref !== $repoMaster) + die('only the master branch is tracked'); + +// the actual changelog api sucks ass +$changeCreate = DB::prepare('INSERT INTO `msz_changelog_changes` (`change_log`, `change_text`, `change_action`, `user_id`, `change_created`) VALUES (:log, :text, :action, :user, FROM_UNIXTIME(:created))'); +$changeTag = DB::prepare('REPLACE INTO `msz_changelog_change_tags` VALUES (:change_id, :tag_id)'); + +$tags = $repoInfo['tags'] ?? []; +$addresses = $config['addresses'] ?? []; + +foreach($data->commits as $commit) { + $message = trim($commit->message); + + if(mb_strpos($message, $repoName) !== false + || mb_substr($message, 0, 2) === '//' + || mb_strpos(mb_strtolower($message), 'merge pull request') !== false) + continue; + + $index = mb_strpos($message, "\n"); + $line = $index === false ? $message : mb_substr($message, 0, $index); + $body = trim($index === false ? '' : mb_substr($message, $index + 1)); + + $changeCreate->bind('user', $addresses[$commit->author->email] ?? null); + $changeCreate->bind('action', ghcb_changelog_action($line)); + $changeCreate->bind('log', $line); + $changeCreate->bind('text', empty($body) ? null : $body); + $changeCreate->bind('created', max(1, strtotime($commit->timestamp))); + $changeId = $changeCreate->executeGetId(); + + if(!empty($tags) && !empty($changeId)) { + $changeTag->bind('change_id', $changeId); + + foreach($tags as $tag) { + $changeTag->bind('tag_id', $tag); + $changeTag->execute(); + } + } + + unset($changeId, $tag); +} diff --git a/public/_sockchat.php b/public/_sockchat.php new file mode 100644 index 0000000..41cc616 --- /dev/null +++ b/public/_sockchat.php @@ -0,0 +1,2 @@ + 0, + 'name' => '', + 'avatar' => url('user-avatar', ['res' => 200, 'user' => 0]), + ]); + return; + } + + echo json_encode([ + 'id' => $userInfo->getId(), + 'name' => $userInfo->getUsername(), + 'avatar' => url('user-avatar', ['user' => $userInfo->getId(), 'res' => 200]), + ]); + return; +} + +$notices = []; +$siteIsPrivate = Config::get('private.enable', Config::TYPE_BOOL); +$loginPermCat = $siteIsPrivate ? Config::get('private.perm.cat', Config::TYPE_STR) : ''; +$loginPermVal = $siteIsPrivate ? Config::get('private.perm.val', Config::TYPE_INT) : 0; +$remainingAttempts = UserLoginAttempt::remaining(); + +while(!empty($_POST['login']) && is_array($_POST['login'])) { + if(!CSRF::validateRequest()) { + $notices[] = 'Was unable to verify the request, please try again!'; + break; + } + + $loginRedirect = empty($_POST['login']['redirect']) || !is_string($_POST['login']['redirect']) ? '' : $_POST['login']['redirect']; + + if(empty($_POST['login']['username']) || empty($_POST['login']['password']) + || !is_string($_POST['login']['username']) || !is_string($_POST['login']['password'])) { + $notices[] = "You didn't fill in a username and/or password."; + break; + } + + if($remainingAttempts < 1) { + $notices[] = "There are too many failed login attempts from your IP address, please try again later."; + break; + } + + $attemptsRemainingError = sprintf( + "%d attempt%s remaining", + $remainingAttempts - 1, + $remainingAttempts === 2 ? '' : 's' + ); + $loginFailedError = "Invalid username or password, {$attemptsRemainingError}."; + + try { + $userInfo = User::byUsernameOrEMailAddress($_POST['login']['username']); + } catch(UserNotFoundException $ex) { + UserLoginAttempt::create(false); + $notices[] = $loginFailedError; + break; + } + + if(!$userInfo->hasPassword()) { + $notices[] = 'Your password has been invalidated, please reset it.'; + break; + } + + if($userInfo->isDeleted() || !$userInfo->checkPassword($_POST['login']['password'])) { + UserLoginAttempt::create(false, $userInfo); + $notices[] = $loginFailedError; + break; + } + + if($userInfo->passwordNeedsRehash()) + $userInfo->setPassword($_POST['login']['password'])->save(); + + if(!empty($loginPermCat) && $loginPermVal > 0 && !perms_check_user($loginPermCat, $userInfo->getId(), $loginPermVal)) { + $notices[] = "Login succeeded, but you're not allowed to browse the site right now."; + UserLoginAttempt::create(true, $userInfo); + break; + } + + if($userInfo->hasTOTP()) { + url_redirect('auth-two-factor', [ + 'token' => UserAuthSession::create($userInfo)->getToken(), + ]); + return; + } + + UserLoginAttempt::create(true, $userInfo); + + try { + $sessionInfo = UserSession::create($userInfo); + $sessionInfo->setCurrent(); + } catch(UserSessionCreationFailedException $ex) { + $notices[] = "Something broke while creating a session for you, please tell an administrator or developer about this!"; + break; + } + + $authToken = AuthToken::create($userInfo, $sessionInfo); + setcookie('msz_auth', $authToken->pack(), $sessionInfo->getExpiresTime(), '/', msz_cookie_domain(), !empty($_SERVER['HTTPS']), true); + + if(!is_local_url($loginRedirect)) + $loginRedirect = url('index'); + + redirect($loginRedirect); + return; +} + +$welcomeMode = !empty($_GET['welcome']); +$loginUsername = !empty($_POST['login']['username']) && is_string($_POST['login']['username']) ? $_POST['login']['username'] : ( + !empty($_GET['username']) && is_string($_GET['username']) ? $_GET['username'] : '' +); +$loginRedirect = $welcomeMode ? url('index') : (!empty($_GET['redirect']) && is_string($_GET['redirect']) ? $_GET['redirect'] : null) ?? $_SERVER['HTTP_REFERER'] ?? url('index'); +$sitePrivateMessage = $siteIsPrivate ? Config::get('private.msg', Config::TYPE_STR) : ''; +$canResetPassword = $siteIsPrivate ? Config::get('private.allow_password_reset', Config::TYPE_BOOL, true) : true; +$canRegisterAccount = !$siteIsPrivate; + +Template::render('auth.login', [ + 'login_notices' => $notices, + 'login_username' => $loginUsername, + 'login_redirect' => $loginRedirect, + 'login_can_reset_password' => $canResetPassword, + 'login_can_register' => $canRegisterAccount, + 'login_attempts_remaining' => $remainingAttempts, + 'login_welcome' => $welcomeMode, + 'login_private' => [ + 'enabled' => $siteIsPrivate, + 'message' => $sitePrivateMessage, + ], +]); diff --git a/public/auth/logout.php b/public/auth/logout.php new file mode 100644 index 0000000..c75e722 --- /dev/null +++ b/public/auth/logout.php @@ -0,0 +1,24 @@ +delete(); + UserSession::unsetCurrent(); + User::unsetCurrent(); + url_redirect('index'); + return; +} + +Template::render('auth.logout'); diff --git a/public/auth/password.php b/public/auth/password.php new file mode 100644 index 0000000..7cc0e0b --- /dev/null +++ b/public/auth/password.php @@ -0,0 +1,150 @@ + 0) + try { + $userInfo = User::byId($userId); + } catch(UserNotFoundException $ex) { + url_redirect('auth-forgot'); + return; + } + +$notices = []; +$siteIsPrivate = Config::get('private.enable', Config::TYPE_BOOL); +$canResetPassword = $siteIsPrivate ? Config::get('private.allow_password_reset', Config::TYPE_BOOL, true) : true; +$remainingAttempts = UserLoginAttempt::remaining(); + +while($canResetPassword) { + if(!empty($reset) && $userId > 0) { + if(!CSRF::validateRequest()) { + $notices[] = 'Was unable to verify the request, please try again!'; + break; + } + + $verificationCode = !empty($reset['verification']) && is_string($reset['verification']) ? $reset['verification'] : ''; + + try { + $tokenInfo = UserRecoveryToken::byToken($verificationCode); + } catch(UserRecoveryTokenNotFoundException $ex) { + unset($tokenInfo); + } + + if(empty($tokenInfo) || !$tokenInfo->isValid() || $tokenInfo->getUserId() !== $userInfo->getId()) { + $notices[] = 'Invalid verification code!'; + break; + } + + $password = !empty($reset['password']) && is_array($reset['password']) ? $reset['password'] : []; + $passwordNew = !empty($password['new']) && is_string($password['new']) ? $password['new'] : ''; + $passwordConfirm = !empty($password['confirm']) && is_string($password['confirm']) ? $password['confirm'] : ''; + + if(empty($passwordNew) || empty($passwordConfirm) + || $passwordNew !== $passwordConfirm) { + $notices[] = "Password confirmation failed!"; + break; + } + + if(User::validatePassword($passwordNew) !== '') { + $notices[] = 'Your password is too weak!'; + break; + } + + // also disables two factor auth to prevent getting locked out of account entirely + // this behaviour should really be replaced with recovery keys... + $userInfo->setPassword($passwordNew) + ->removeTOTPKey() + ->save(); + + AuditLog::create(AuditLog::PASSWORD_RESET, [], $userInfo); + + $tokenInfo->invalidate(); + + url_redirect('auth-login', ['redirect' => '/']); + return; + } + + if(!empty($forgot)) { + if(!CSRF::validateRequest()) { + $notices[] = 'Was unable to verify the request, please try again!'; + break; + } + + if(empty($forgot['email']) || !is_string($forgot['email'])) { + $notices[] = "You didn't supply an e-mail address."; + break; + } + + if($remainingAttempts < 1) { + $notices[] = "There are too many failed login attempts from your IP address, please try again later."; + break; + } + + try { + $forgotUser = User::byEMailAddress($forgot['email']); + } catch(UserNotFoundException $ex) { + unset($forgotUser); + } + + if(empty($forgotUser) || $forgotUser->isDeleted()) { + $notices[] = "This e-mail address is not registered with us."; + break; + } + + try { + $tokenInfo = UserRecoveryToken::byUserAndRemoteAddress($forgotUser); + } catch(UserRecoveryTokenNotFoundException $ex) { + $tokenInfo = UserRecoveryToken::create($forgotUser); + + $recoveryMessage = Mailer::template('password-recovery', [ + 'username' => $forgotUser->getUsername(), + 'token' => $tokenInfo->getToken(), + ]); + + $recoveryMail = Mailer::sendMessage( + [$forgotUser->getEMailAddress() => $forgotUser->getUsername()], + $recoveryMessage['subject'], $recoveryMessage['message'] + ); + + if(!$recoveryMail) { + $notices[] = "Failed to send reset email, please contact the administrator."; + $tokenInfo->invalidate(); + break; + } + } + + url_redirect('auth-reset', ['user' => $forgotUser->getId()]); + return; + } + + break; +} + +Template::render(isset($userInfo) ? 'auth.password_reset' : 'auth.password_forgot', [ + 'password_notices' => $notices, + 'password_email' => !empty($forget['email']) && is_string($forget['email']) ? $forget['email'] : '', + 'password_attempts_remaining' => $remainingAttempts, + 'password_user' => $userInfo ?? null, + 'password_verification' => $verificationCode ?? '', +]); diff --git a/public/auth/register.php b/public/auth/register.php new file mode 100644 index 0000000..fb1cb9c --- /dev/null +++ b/public/auth/register.php @@ -0,0 +1,102 @@ + 0 ? 'ban' : ''); + +while(!$restricted && !empty($register)) { + if(!CSRF::validateRequest()) { + $notices[] = 'Was unable to verify the request, please try again!'; + break; + } + + if($remainingAttempts < 1) { + $notices[] = "There are too many failed login attempts from your IP address, you may not create an account right now."; + break; + } + + if(empty($register['username']) || empty($register['password']) || empty($register['email']) || empty($register['question']) + || !is_string($register['username']) || !is_string($register['password']) || !is_string($register['email']) || !is_string($register['question'])) { + $notices[] = "You haven't filled in all fields."; + break; + } + + $checkSpamBot = mb_strtolower($register['question']); + $spamBotValid = [ + '21', 'twentyone', 'twenty-one', 'twenty one', + ]; + $spamBotHint = [ + '19', 'nineteen', 'nine-teen', 'nine teen', + ]; + + if(!in_array($checkSpamBot, $spamBotValid)) { + if(in_array($checkSpamBot, $spamBotHint)) + $notices[] = '_play_hint'; + + $notices[] = 'Human only cool club, robots begone.'; + break; + } + + $usernameValidation = User::validateUsername($register['username']); + if($usernameValidation !== '') + $notices[] = User::usernameValidationErrorString($usernameValidation); + + $emailValidation = User::validateEMailAddress($register['email']); + if($emailValidation !== '') + $notices[] = $emailValidation === 'in-use' + ? 'This e-mail address has already been used!' + : 'The e-mail address you entered is invalid!'; + + if($register['password_confirm'] !== $register['password']) + $notices[] = 'The given passwords don\'t match.'; + + if(User::validatePassword($register['password']) !== '') + $notices[] = 'Your password is too weak!'; + + if(!empty($notices)) + break; + + try { + $createUser = User::create( + $register['username'], + $register['password'], + $register['email'], + $ipAddress + ); + } catch(UserCreationFailedException $ex) { + $notices[] = 'Something went wrong while creating your account, please alert an administrator or a developer about this!'; + break; + } + + $createUser->addRole(UserRole::byDefault()); + + url_redirect('auth-login-welcome', ['username' => $createUser->getUsername()]); + return; +} + +Template::render('auth.register', [ + 'register_notices' => $notices, + 'register_username' => !empty($register['username']) && is_string($register['username']) ? $register['username'] : '', + 'register_email' => !empty($register['email']) && is_string($register['email']) ? $register['email'] : '', + 'register_restricted' => $restricted, +]); diff --git a/public/auth/twofactor.php b/public/auth/twofactor.php new file mode 100644 index 0000000..af31b16 --- /dev/null +++ b/public/auth/twofactor.php @@ -0,0 +1,102 @@ +hasExpired()) { + url_redirect('auth-login'); + return; +} + +$userInfo = $tokenInfo->getUser(); + +// checking user_totp_key specifically because there's a fringe chance that +// there's a token present, but totp is actually disabled +if(!$userInfo->hasTOTP()) { + url_redirect('auth-login'); + return; +} + +while(!empty($twofactor)) { + if(!CSRF::validateRequest()) { + $notices[] = 'Was unable to verify the request, please try again!'; + break; + } + + $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? ''; + $redirect = !empty($twofactor['redirect']) && is_string($twofactor['redirect']) ? $twofactor['redirect'] : ''; + + if(empty($twofactor['code']) || !is_string($twofactor['code'])) { + $notices[] = 'Code field was empty.'; + break; + } + + if($remainingAttempts < 1) { + $notices[] = 'There are too many failed login attempts from your IP address, please try again later.'; + break; + } + + if(!in_array($twofactor['code'], $userInfo->getValidTOTPTokens())) { + $notices[] = sprintf( + "Invalid two factor code, %d attempt%s remaining", + $remainingAttempts - 1, + $remainingAttempts === 2 ? '' : 's' + ); + UserLoginAttempt::create(false, $userInfo); + break; + } + + UserLoginAttempt::create(true, $userInfo); + $tokenInfo->delete(); + + try { + $sessionInfo = UserSession::create($userInfo); + $sessionInfo->setCurrent(); + } catch(UserSessionCreationFailedException $ex) { + $notices[] = "Something broke while creating a session for you, please tell an administrator or developer about this!"; + break; + } + + $authToken = AuthToken::create($userInfo, $sessionInfo); + setcookie('msz_auth', $authToken->pack(), $sessionInfo->getExpiresTime(), '/', msz_cookie_domain(), !empty($_SERVER['HTTPS']), true); + + if(!is_local_url($redirect)) { + $redirect = url('index'); + } + + redirect($redirect); + return; +} + +Template::render('auth.twofactor', [ + 'twofactor_notices' => $notices, + 'twofactor_redirect' => !empty($_GET['redirect']) && is_string($_GET['redirect']) ? $_GET['redirect'] : url('index'), + 'twofactor_attempts_remaining' => $remainingAttempts, + 'twofactor_token' => $tokenInfo->getToken(), +]); diff --git a/public/changelog.php b/public/changelog.php new file mode 100644 index 0000000..41cc616 --- /dev/null +++ b/public/changelog.php @@ -0,0 +1,2 @@ +isBanned()) { + echo render_info_or_json($isXHR, 'You have been banned, check your profile for more information.', 403); + return; +} +if($currentUserInfo->isSilenced()) { + echo render_info_or_json($isXHR, 'You have been silenced, check your profile for more information.', 403); + return; +} + +header(CSRF::header()); +$commentPerms = $currentUserInfo->commentPerms(); + +$commentId = (int)filter_input(INPUT_GET, 'c', FILTER_SANITIZE_NUMBER_INT); +$commentMode = filter_input(INPUT_GET, 'm'); +$commentVote = (int)filter_input(INPUT_GET, 'v', FILTER_SANITIZE_NUMBER_INT); + +if($commentId > 0) + try { + $commentInfo2 = CommentsPost::byId($commentId); + } catch(CommentsPostNotFoundException $ex) { + echo render_info_or_json($isXHR, 'Post not found.', 404); + return; + } + +switch($commentMode) { + case 'pin': + case 'unpin': + if(!$commentPerms['can_pin'] && !$commentInfo2->isOwner($currentUserInfo)) { + echo render_info_or_json($isXHR, "You're not allowed to pin comments.", 403); + break; + } + + if($commentInfo2->isDeleted()) { + echo render_info_or_json($isXHR, "This comment doesn't exist!", 400); + break; + } + + if($commentInfo2->hasParent()) { + echo render_info_or_json($isXHR, "You can't pin replies!", 400); + break; + } + + $isPinning = $commentMode === 'pin'; + + if($isPinning && $commentInfo2->isPinned()) { + echo render_info_or_json($isXHR, 'This comment is already pinned.', 400); + break; + } elseif(!$isPinning && !$commentInfo2->isPinned()) { + echo render_info_or_json($isXHR, "This comment isn't pinned yet.", 400); + break; + } + + $commentInfo2->setPinned($isPinning); + $commentInfo2->save(); + + if(!$isXHR) { + redirect($redirect . '#comment-' . $commentInfo2->getId()); + break; + } + + echo json_encode([ + 'comment_id' => $commentInfo2->getId(), + 'comment_pinned' => ($time = $commentInfo2->getPinnedTime()) < 0 ? null : date('Y-m-d H:i:s', $time), + ]); + break; + + case 'vote': + if(!$commentPerms['can_vote'] && !$commentInfo2->isOwner($currentUserInfo)) { + echo render_info_or_json($isXHR, "You're not allowed to vote on comments.", 403); + break; + } + + if($commentInfo2->isDeleted()) { + echo render_info_or_json($isXHR, "This comment doesn't exist!", 400); + break; + } + + if($commentVote > 0) + $commentInfo2->addPositiveVote($currentUserInfo); + elseif($commentVote < 0) + $commentInfo2->addNegativeVote($currentUserInfo); + else + $commentInfo2->removeVote($currentUserInfo); + + if(!$isXHR) { + redirect($redirect . '#comment-' . $commentInfo2->getId()); + break; + } + + echo json_encode($commentInfo2->votes()); + break; + + case 'delete': + if(!$commentPerms['can_delete'] && !$commentInfo2->isOwner($currentUserInfo)) { + echo render_info_or_json($isXHR, "You're not allowed to delete comments.", 403); + break; + } + + if($commentInfo2->isDeleted()) { + echo render_info_or_json( + $isXHR, + $commentPerms['can_delete_any'] ? 'This comment is already marked for deletion.' : "This comment doesn't exist.", + 400 + ); + break; + } + + $isOwnComment = $commentInfo2->getUserId() === $currentUserInfo->getId(); + $isModAction = $commentPerms['can_delete_any'] && !$isOwnComment; + + if(!$isModAction && !$isOwnComment) { + echo render_info_or_json($isXHR, "You're not allowed to delete comments made by others.", 403); + break; + } + + $commentInfo2->setDeleted(true); + $commentInfo2->save(); + + if($isModAction) { + AuditLog::create(AuditLog::COMMENT_ENTRY_DELETE_MOD, [ + $commentInfo2->getId(), + $commentUserId = $commentInfo2->getUserId(), + ($commentUserId < 1 ? '(Deleted User)' : $commentInfo2->getUser()->getUsername()), + ]); + } else { + AuditLog::create(AuditLog::COMMENT_ENTRY_DELETE, [$commentInfo2->getId()]); + } + + if($redirect) { + redirect($redirect); + break; + } + + echo json_encode([ + 'id' => $commentInfo2->getId(), + ]); + break; + + case 'restore': + if(!$commentPerms['can_delete_any']) { + echo render_info_or_json($isXHR, "You're not allowed to restore deleted comments.", 403); + break; + } + + if(!$commentInfo2->isDeleted()) { + echo render_info_or_json($isXHR, "This comment isn't in a deleted state.", 400); + break; + } + + $commentInfo2->setDeleted(false); + $commentInfo2->save(); + + AuditLog::create(AuditLog::COMMENT_ENTRY_RESTORE, [ + $commentInfo2->getId(), + $commentUserId = $commentInfo2->getUserId(), + ($commentUserId < 1 ? '(Deleted User)' : $commentInfo2->getUser()->getUsername()), + ]); + + if($redirect) { + redirect($redirect . '#comment-' . $commentInfo2->getId()); + break; + } + + echo json_encode([ + 'id' => $commentInfo2->getId(), + ]); + break; + + case 'create': + if(!$commentPerms['can_comment'] && !$commentInfo2->isOwner($currentUserInfo)) { + echo render_info_or_json($isXHR, "You're not allowed to post comments.", 403); + break; + } + + if(empty($_POST['comment']) || !is_array($_POST['comment'])) { + echo render_info_or_json($isXHR, 'Missing data.', 400); + break; + } + + try { + $categoryInfo = CommentsCategory::byId( + isset($_POST['comment']['category']) && is_string($_POST['comment']['category']) + ? (int)$_POST['comment']['category'] + : 0 + ); + } catch(CommentsCategoryNotFoundException $ex) { + echo render_info_or_json($isXHR, 'This comment category doesn\'t exist.', 404); + break; + } + + if($categoryInfo->isLocked() && !$commentPerms['can_lock']) { + echo render_info_or_json($isXHR, 'This comment category has been locked.', 403); + break; + } + + $commentText = !empty($_POST['comment']['text']) && is_string($_POST['comment']['text']) ? $_POST['comment']['text'] : ''; + $commentReply = !empty($_POST['comment']['reply']) && is_string($_POST['comment']['reply']) ? (int)$_POST['comment']['reply'] : 0; + $commentLock = !empty($_POST['comment']['lock']) && $commentPerms['can_lock']; + $commentPin = !empty($_POST['comment']['pin']) && $commentPerms['can_pin']; + + if($commentLock) { + $categoryInfo->setLocked(!$categoryInfo->isLocked()); + $categoryInfo->save(); + } + + if(strlen($commentText) > 0) { + $commentText = preg_replace("/[\r\n]{2,}/", "\n", $commentText); + } else { + if($commentPerms['can_lock']) { + echo render_info_or_json($isXHR, 'The action has been processed.'); + } else { + echo render_info_or_json($isXHR, 'Your comment is too short.', 400); + } + break; + } + + if(mb_strlen($commentText) > 5000) { + echo render_info_or_json($isXHR, 'Your comment is too long.', 400); + break; + } + + if($commentReply > 0) { + try { + $parentCommentInfo = CommentsPost::byId($commentReply); + } catch(CommentsPostNotFoundException $ex) { + unset($parentCommentInfo); + } + + if(!isset($parentCommentInfo) || $parentCommentInfo->isDeleted()) { + echo render_info_or_json($isXHR, 'The comment you tried to reply to does not exist.', 404); + break; + } + } + + $commentInfo2 = (new CommentsPost) + ->setUser($currentUserInfo) + ->setCategory($categoryInfo) + ->setParsedText($commentText) + ->setPinned($commentPin); + + if(isset($parentCommentInfo)) + $commentInfo2->setParent($parentCommentInfo); + + try { + $commentInfo2->save(); + } catch(CommentsPostSaveFailedException $ex) { + echo render_info_or_json($isXHR, 'Something went horribly wrong.', 500); + break; + } + + if($redirect) { + redirect($redirect . '#comment-' . $commentInfo2->getId()); + break; + } + + echo json_encode([ + 'comment_id' => $commentInfo2->getId(), + 'category_id' => $commentInfo2->getCategoryId(), + 'comment_text' => $commentInfo2->getText(), + 'comment_created' => ($time = $commentInfo2->getCreatedTime()) < 0 ? null : date('Y-m-d H:i:s', $time), + 'comment_edited' => ($time = $commentInfo2->getEditedTime()) < 0 ? null : date('Y-m-d H:i:s', $time), + 'comment_deleted' => ($time = $commentInfo2->getDeletedTime()) < 0 ? null : date('Y-m-d H:i:s', $time), + 'comment_pinned' => ($time = $commentInfo2->getPinnedTime()) < 0 ? null : date('Y-m-d H:i:s', $time), + 'comment_reply_to' => ($parent = $commentInfo2->getParentId()) < 1 ? null : $parent, + 'user_id' => ($commentInfo2->getUserId() < 1 ? null : $commentInfo2->getUser()->getId()), + 'username' => ($commentInfo2->getUserId() < 1 ? null : $commentInfo2->getUser()->getUsername()), + 'user_colour' => ($commentInfo2->getUserId() < 1 ? 0x40000000 : $commentInfo2->getUser()->getColour()->getRaw()), + ]); + break; + + default: + echo render_info_or_json($isXHR, 'Not found.', 404); +} diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..62a03e7 Binary files /dev/null and b/public/favicon.ico differ diff --git a/public/forum/forum.php b/public/forum/forum.php new file mode 100644 index 0000000..78b67aa --- /dev/null +++ b/public/forum/forum.php @@ -0,0 +1,81 @@ +getId(); + +if(empty($forum) || ($forum['forum_type'] == MSZ_FORUM_TYPE_LINK && empty($forum['forum_link']))) { + echo render_error(404); + return; +} + +$perms = forum_perms_get_user($forum['forum_id'], $forumUserId)[MSZ_FORUM_PERMS_GENERAL]; + +if(!perms_check($perms, MSZ_FORUM_PERM_VIEW_FORUM)) { + echo render_error(403); + return; +} + +if(isset($forumUser) && $forumUser->hasActiveWarning()) + $perms &= ~MSZ_FORUM_PERM_SET_WRITE; + +Template::set('forum_perms', $perms); + +if($forum['forum_type'] == MSZ_FORUM_TYPE_LINK) { + forum_increment_clicks($forum['forum_id']); + redirect($forum['forum_link']); + return; +} + +$forumPagination = new Pagination($forum['forum_topic_count'], 20); + +if(!$forumPagination->hasValidOffset() && $forum['forum_topic_count'] > 0) { + echo render_error(404); + return; +} + +$forumMayHaveTopics = forum_may_have_topics($forum['forum_type']); +$topics = $forumMayHaveTopics + ? forum_topic_listing( + $forum['forum_id'], + $forumUserId, + $forumPagination->getOffset(), + $forumPagination->getRange(), + perms_check($perms, MSZ_FORUM_PERM_DELETE_ANY_POST), + forum_has_priority_voting($forum['forum_type']) + ) + : []; + +$forumMayHaveChildren = forum_may_have_children($forum['forum_type']); + +if($forumMayHaveChildren) { + $forum['forum_subforums'] = forum_get_children($forum['forum_id'], $forumUserId); + + foreach($forum['forum_subforums'] as $skey => $subforum) { + $forum['forum_subforums'][$skey]['forum_subforums'] + = forum_get_children($subforum['forum_id'], $forumUserId); + } +} + +Template::render('forum.forum', [ + 'forum_breadcrumbs' => forum_get_breadcrumbs($forum['forum_id']), + 'global_accent_colour' => forum_get_colour($forum['forum_id']), + 'forum_may_have_topics' => $forumMayHaveTopics, + 'forum_may_have_children' => $forumMayHaveChildren, + 'forum_info' => $forum, + 'forum_topics' => $topics, + 'forum_pagination' => $forumPagination, +]); diff --git a/public/forum/index.php b/public/forum/index.php new file mode 100644 index 0000000..e168c33 --- /dev/null +++ b/public/forum/index.php @@ -0,0 +1,41 @@ +getId(); + +switch($indexMode) { + case 'mark': + url_redirect($forumId < 1 ? 'forum-mark-global' : 'forum-mark-single', ['forum' => $forumId]); + break; + + default: + $categories = forum_get_root_categories($currentUserId); + $blankForum = count($categories) < 1; + + foreach($categories as $key => $category) { + $categories[$key]['forum_subforums'] = forum_get_children($category['forum_id'], $currentUserId); + + foreach($categories[$key]['forum_subforums'] as $skey => $sub) { + if(!forum_may_have_children($sub['forum_type'])) { + continue; + } + + $categories[$key]['forum_subforums'][$skey]['forum_subforums'] + = forum_get_children($sub['forum_id'], $currentUserId); + } + } + + Template::render('forum.index', [ + 'forum_categories' => $categories, + 'forum_empty' => $blankForum, + ]); + break; +} diff --git a/public/forum/leaderboard.php b/public/forum/leaderboard.php new file mode 100644 index 0000000..97eda9b --- /dev/null +++ b/public/forum/leaderboard.php @@ -0,0 +1,60 @@ +getId(), MSZ_PERM_FORUM_VIEW_LEADERBOARD)) { + echo render_error(403); + return; +} + +$leaderboardMode = !empty($_GET['mode']) && is_string($_GET['mode']) && ctype_lower($_GET['mode']) ? $_GET['mode'] : ''; +$leaderboardId = !empty($_GET['id']) && is_string($_GET['id']) + && ctype_digit($_GET['id']) + ? $_GET['id'] + : MSZ_FORUM_LEADERBOARD_CATEGORY_ALL; +$leaderboardIdLength = strlen($leaderboardId); + +$leaderboardYear = $leaderboardIdLength === 4 || $leaderboardIdLength === 6 ? substr($leaderboardId, 0, 4) : null; +$leaderboardMonth = $leaderboardIdLength === 6 ? substr($leaderboardId, 4, 2) : null; + +$unrankedForums = !empty($_GET['allow_unranked']) ? [] : Config::get('forum_leader.unranked.forum', Config::TYPE_ARR); +$unrankedTopics = !empty($_GET['allow_unranked']) ? [] : Config::get('forum_leader.unranked.topic', Config::TYPE_ARR); +$leaderboards = forum_leaderboard_categories(); +$leaderboard = forum_leaderboard_listing($leaderboardYear, $leaderboardMonth, $unrankedForums, $unrankedTopics); + +$leaderboardName = 'All Time'; + +if($leaderboardYear) { + $leaderboardName = "Leaderboard {$leaderboardYear}"; + + if($leaderboardMonth) { + $leaderboardName .= "-{$leaderboardMonth}"; + } +} + +if($leaderboardMode === 'markdown') { + $markdown = << $user['user_id']]), $user['posts']); + } + + Template::set('leaderboard_markdown', $markdown); +} + +Template::render('forum.leaderboard', [ + 'leaderboard_id' => $leaderboardId, + 'leaderboard_name' => $leaderboardName, + 'leaderboard_categories' => $leaderboards, + 'leaderboard_data' => $leaderboard, + 'leaderboard_mode' => $leaderboardMode, +]); diff --git a/public/forum/poll.php b/public/forum/poll.php new file mode 100644 index 0000000..db26181 --- /dev/null +++ b/public/forum/poll.php @@ -0,0 +1,102 @@ +getId(); + +if($currentUser->isBanned()) { + echo render_info_or_json($isXHR, 'You have been banned, check your profile for more information.', 403); + return; +} +if($currentUser->isSilenced()) { + echo render_info_or_json($isXHR, 'You have been silenced, check your profile for more information.', 403); + return; +} + +header(CSRF::header()); + +if(empty($_POST['poll']['id']) || !ctype_digit($_POST['poll']['id'])) { + echo render_info_or_json($isXHR, "Invalid request.", 400); + return; +} + +$poll = forum_poll_get($_POST['poll']['id']); + +if(empty($poll)) { + echo "Poll {$poll['poll_id']} doesn't exist.
"; + return; +} + +$topicInfo = forum_poll_get_topic($poll['poll_id']); + +if(!is_null($topicInfo['topic_locked'])) { + echo "The topic associated with this poll has been locked.
"; + return; +} + +if(!forum_perms_check_user( + MSZ_FORUM_PERMS_GENERAL, $topicInfo['forum_id'], + $currentUserId, MSZ_FORUM_PERM_SET_READ +)) { + echo "You aren't allowed to vote on this poll.
"; + return; +} + +if($poll['poll_expired']) { + echo "Voting for poll {$poll['poll_id']} has closed.
"; + return; +} + +if(!$poll['poll_change_vote'] && forum_poll_has_voted($currentUserId, $poll['poll_id'])) { + echo "Can't change vote for {$poll['poll_id']}
"; + return; +} + +$answers = !empty($_POST['poll']['answers']) + && is_array($_POST['poll']['answers']) + ? $_POST['poll']['answers'] + : []; + +if(count($answers) > $poll['poll_max_votes']) { + echo "Too many votes for poll {$poll['poll_id']}
"; + return; +} + +forum_poll_vote_remove($currentUserId, $poll['poll_id']); + +foreach($answers as $answerId) { + if(!is_string($answerId) || !ctype_digit($answerId) + || !forum_poll_validate_option($poll['poll_id'], (int)$answerId)) { + echo "Vote {$answerId} was invalid for {$poll['poll_id']}
"; + continue; + } + + forum_poll_vote_cast($currentUserId, $poll['poll_id'], (int)$answerId); +} + +url_redirect('forum-topic', ['topic' => $topicInfo['topic_id']]); diff --git a/public/forum/post.php b/public/forum/post.php new file mode 100644 index 0000000..e76411a --- /dev/null +++ b/public/forum/post.php @@ -0,0 +1,279 @@ +getId(); + +if(isset($currentUser) && $currentUser->isBanned()) { + echo render_info_or_json($isXHR, 'You have been banned, check your profile for more information.', 403); + return; +} +if(isset($currentUser) && $currentUser->isSilenced()) { + echo render_info_or_json($isXHR, 'You have been silenced, check your profile for more information.', 403); + return; +} + +if($isXHR) { + if(!$postRequestVerified) { + http_response_code(403); + echo json_encode([ + 'success' => false, + 'message' => 'Possible request forgery detected.', + ]); + return; + } + + header(CSRF::header()); +} + +$postInfo = forum_post_get($postId, true); +$perms = empty($postInfo) + ? 0 + : forum_perms_get_user($postInfo['forum_id'], $currentUserId)[MSZ_FORUM_PERMS_GENERAL]; + +switch($postMode) { + case 'delete': + $canDelete = forum_post_can_delete($postInfo, $currentUserId); + $canDeleteMsg = ''; + $responseCode = 200; + + switch($canDelete) { + case MSZ_E_FORUM_POST_DELETE_USER: // i don't think this is ever reached but we may as well have it + $responseCode = 401; + $canDeleteMsg = 'You must be logged in to delete posts.'; + break; + case MSZ_E_FORUM_POST_DELETE_POST: + $responseCode = 404; + $canDeleteMsg = "This post doesn't exist."; + break; + case MSZ_E_FORUM_POST_DELETE_DELETED: + $responseCode = 404; + $canDeleteMsg = 'This post has already been marked as deleted.'; + break; + case MSZ_E_FORUM_POST_DELETE_OWNER: + $responseCode = 403; + $canDeleteMsg = 'You can only delete your own posts.'; + break; + case MSZ_E_FORUM_POST_DELETE_OLD: + $responseCode = 401; + $canDeleteMsg = 'This post has existed for too long. Ask a moderator to remove if it absolutely necessary.'; + break; + case MSZ_E_FORUM_POST_DELETE_PERM: + $responseCode = 401; + $canDeleteMsg = 'You are not allowed to delete posts.'; + break; + case MSZ_E_FORUM_POST_DELETE_OP: + $responseCode = 403; + $canDeleteMsg = 'This is the opening post of a topic, it may not be deleted without deleting the entire topic as well.'; + break; + case MSZ_E_FORUM_POST_DELETE_OK: + break; + default: + $responseCode = 500; + $canDeleteMsg = sprintf('Unknown error \'%d\'', $canDelete); + } + + if($canDelete !== MSZ_E_FORUM_POST_DELETE_OK) { + if($isXHR) { + http_response_code($responseCode); + echo json_encode([ + 'success' => false, + 'post_id' => $postInfo['post_id'], + 'code' => $canDelete, + 'message' => $canDeleteMsg, + ]); + break; + } + + echo render_info($canDeleteMsg, $responseCode); + break; + } + + if(!$isXHR) { + if($postRequestVerified && !$submissionConfirmed) { + url_redirect('forum-post', [ + 'post' => $postInfo['post_id'], + 'post_fragment' => 'p' . $postInfo['post_id'], + ]); + break; + } elseif(!$postRequestVerified) { + Template::render('forum.confirm', [ + 'title' => 'Confirm post deletion', + 'class' => 'far fa-trash-alt', + 'message' => sprintf('You are about to delete post #%d. Are you sure about that?', $postInfo['post_id']), + 'params' => [ + 'p' => $postInfo['post_id'], + 'm' => 'delete', + ], + ]); + break; + } + } + + $deletePost = forum_post_delete($postInfo['post_id']); + + if($deletePost) { + AuditLog::create(AuditLog::FORUM_POST_DELETE, [$postInfo['post_id']]); + } + + if($isXHR) { + echo json_encode([ + 'success' => $deletePost, + 'post_id' => $postInfo['post_id'], + 'message' => $deletePost ? 'Post deleted!' : 'Failed to delete post.', + ]); + break; + } + + if(!$deletePost) { + echo render_error(500); + break; + } + + url_redirect('forum-topic', ['topic' => $postInfo['topic_id']]); + break; + + case 'nuke': + if(!perms_check($perms, MSZ_FORUM_PERM_DELETE_ANY_POST)) { + echo render_error(403); + break; + } + + if(!$isXHR) { + if($postRequestVerified && !$submissionConfirmed) { + url_redirect('forum-post', [ + 'post' => $postInfo['post_id'], + 'post_fragment' => 'p' . $postInfo['post_id'], + ]); + break; + } elseif(!$postRequestVerified) { + Template::render('forum.confirm', [ + 'title' => 'Confirm post nuke', + 'class' => 'fas fa-radiation', + 'message' => sprintf('You are about to PERMANENTLY DELETE post #%d. Are you sure about that?', $postInfo['post_id']), + 'params' => [ + 'p' => $postInfo['post_id'], + 'm' => 'nuke', + ], + ]); + break; + } + } + + $nukePost = forum_post_nuke($postInfo['post_id']); + + if(!$nukePost) { + echo render_error(500); + break; + } + + AuditLog::create(AuditLog::FORUM_POST_NUKE, [$postInfo['post_id']]); + http_response_code(204); + + if(!$isXHR) { + url_redirect('forum-topic', ['topic' => $postInfo['topic_id']]); + } + break; + + case 'restore': + if(!perms_check($perms, MSZ_FORUM_PERM_DELETE_ANY_POST)) { + echo render_error(403); + break; + } + + if(!$isXHR) { + if($postRequestVerified && !$submissionConfirmed) { + url_redirect('forum-post', [ + 'post' => $postInfo['post_id'], + 'post_fragment' => 'p' . $postInfo['post_id'], + ]); + break; + } elseif(!$postRequestVerified) { + Template::render('forum.confirm', [ + 'title' => 'Confirm post restore', + 'class' => 'fas fa-magic', + 'message' => sprintf('You are about to restore post #%d. Are you sure about that?', $postInfo['post_id']), + 'params' => [ + 'p' => $postInfo['post_id'], + 'm' => 'restore', + ], + ]); + break; + } + } + + $restorePost = forum_post_restore($postInfo['post_id']); + + if(!$restorePost) { + echo render_error(500); + break; + } + + AuditLog::create(AuditLog::FORUM_POST_RESTORE, [$postInfo['post_id']]); + http_response_code(204); + + if(!$isXHR) { + url_redirect('forum-topic', ['topic' => $postInfo['topic_id']]); + } + break; + + default: // function as an alt for topic.php?p= by default + $canDeleteAny = perms_check($perms, MSZ_FORUM_PERM_DELETE_ANY_POST); + + if(!empty($postInfo['post_deleted']) && !$canDeleteAny) { + echo render_error(404); + break; + } + + $postFind = forum_post_find($postInfo['post_id'], $currentUserId); + + if(empty($postFind)) { + echo render_error(404); + break; + } + + if($canDeleteAny) { + $postInfo['preceeding_post_count'] += $postInfo['preceeding_post_deleted_count']; + } + + unset($postInfo['preceeding_post_deleted_count']); + + if($isXHR) { + echo json_encode($postFind); + break; + } + + url_redirect('forum-topic', [ + 'topic' => $postFind['topic_id'], + 'page' => floor($postFind['preceeding_post_count'] / MSZ_FORUM_POSTS_PER_PAGE) + 1, + ]); +} diff --git a/public/forum/posting.php b/public/forum/posting.php new file mode 100644 index 0000000..0538d0e --- /dev/null +++ b/public/forum/posting.php @@ -0,0 +1,273 @@ +getId(); + +if($currentUser->hasActiveWarning()) { + echo render_error(403); + return; +} + +$forumPostingModes = [ + 'create', 'edit', 'quote', 'preview', +]; + +if(!empty($_POST)) { + $mode = !empty($_POST['post']['mode']) && is_string($_POST['post']['mode']) ? $_POST['post']['mode'] : 'create'; + $postId = !empty($_POST['post']['id']) && is_string($_POST['post']['id']) ? (int)$_POST['post']['id'] : 0; + $topicId = !empty($_POST['post']['topic']) && is_string($_POST['post']['topic']) ? (int)$_POST['post']['topic'] : 0; + $forumId = !empty($_POST['post']['forum']) && is_string($_POST['post']['forum']) ? (int)$_POST['post']['forum'] : 0; +} else { + $mode = !empty($_GET['m']) && is_string($_GET['m']) ? $_GET['m'] : 'create'; + $postId = !empty($_GET['p']) && is_string($_GET['p']) ? (int)$_GET['p'] : 0; + $topicId = !empty($_GET['t']) && is_string($_GET['t']) ? (int)$_GET['t'] : 0; + $forumId = !empty($_GET['f']) && is_string($_GET['f']) ? (int)$_GET['f'] : 0; +} + +if(!in_array($mode, $forumPostingModes, true)) { + echo render_error(400); + return; +} + +if($mode === 'preview') { + header('Content-Type: text/plain; charset=utf-8'); + + $postText = (string)($_POST['post']['text']); + $postParser = (int)($_POST['post']['parser']); + + if(!Parser::isValid($postParser)) { + http_response_code(400); + return; + } + + http_response_code(200); + echo Parser::instance($postParser)->parseText(htmlspecialchars($postText)); + return; +} + +if(empty($postId) && empty($topicId) && empty($forumId)) { + echo render_error(404); + return; +} + +if(!empty($postId)) { + $post = forum_post_get($postId); + + if(isset($post['topic_id'])) { // should automatic cross-quoting be a thing? if so, check if $topicId is < 1 first + $topicId = (int)$post['topic_id']; + } +} + +if(!empty($topicId)) { + $topic = forum_topic_get($topicId); + + if(isset($topic['forum_id'])) { + $forumId = (int)$topic['forum_id']; + } +} + +if(!empty($forumId)) { + $forum = forum_get($forumId); +} + +if(empty($forum)) { + echo render_error(404); + return; +} + +$perms = forum_perms_get_user($forum['forum_id'], $currentUserId)[MSZ_FORUM_PERMS_GENERAL]; + +if($forum['forum_archived'] + || (!empty($topic['topic_locked']) && !perms_check($perms, MSZ_FORUM_PERM_LOCK_TOPIC)) + || !perms_check($perms, MSZ_FORUM_PERM_VIEW_FORUM | MSZ_FORUM_PERM_CREATE_POST) + || (empty($topic) && !perms_check($perms, MSZ_FORUM_PERM_CREATE_TOPIC))) { + echo render_error(403); + return; +} + +if(!forum_may_have_topics($forum['forum_type'])) { + echo render_error(400); + return; +} + +$topicTypes = []; + +if($mode === 'create' || $mode === 'edit') { + $topicTypes[MSZ_TOPIC_TYPE_DISCUSSION] = 'Normal discussion'; + + if(perms_check($perms, MSZ_FORUM_PERM_STICKY_TOPIC)) { + $topicTypes[MSZ_TOPIC_TYPE_STICKY] = 'Sticky topic'; + } + if(perms_check($perms, MSZ_FORUM_PERM_ANNOUNCE_TOPIC)) { + $topicTypes[MSZ_TOPIC_TYPE_ANNOUNCEMENT] = 'Announcement'; + } + if(perms_check($perms, MSZ_FORUM_PERM_GLOBAL_ANNOUNCE_TOPIC)) { + $topicTypes[MSZ_TOPIC_TYPE_GLOBAL_ANNOUNCEMENT] = 'Global Announcement'; + } +} + +// edit mode stuff +if($mode === 'edit') { + if(empty($post)) { + echo render_error(404); + return; + } + + if(!perms_check($perms, $post['poster_id'] === $currentUserId ? MSZ_FORUM_PERM_EDIT_POST : MSZ_FORUM_PERM_EDIT_ANY_POST)) { + echo render_error(403); + return; + } +} + +$notices = []; + +if(!empty($_POST)) { + $topicTitle = $_POST['post']['title'] ?? ''; + $postText = $_POST['post']['text'] ?? ''; + $postParser = (int)($_POST['post']['parser'] ?? Parser::BBCODE); + $topicType = isset($_POST['post']['type']) ? (int)$_POST['post']['type'] : null; + $postSignature = isset($_POST['post']['signature']); + + if(!CSRF::validateRequest()) { + $notices[] = 'Could not verify request.'; + } else { + $isEditingTopic = empty($topic) || ($mode === 'edit' && $post['is_opening_post']); + + if($mode === 'create') { + $timeoutCheck = max(1, forum_timeout($forumId, $currentUserId)); + + if($timeoutCheck < 5) { + $notices[] = sprintf("You're posting too quickly! Please wait %s seconds before posting again.", number_format($timeoutCheck)); + $notices[] = "It's possible that your post went through successfully and you pressed the submit button twice by accident."; + } + } + + if($isEditingTopic) { + $originalTopicTitle = $topic['topic_title'] ?? null; + $topicTitleChanged = $topicTitle !== $originalTopicTitle; + $originalTopicType = (int)($topic['topic_type'] ?? MSZ_TOPIC_TYPE_DISCUSSION); + $topicTypeChanged = $topicType !== null && $topicType !== $originalTopicType; + + switch(forum_validate_title($topicTitle)) { + case 'too-short': + $notices[] = 'Topic title was too short.'; + break; + + case 'too-long': + $notices[] = 'Topic title was too long.'; + break; + } + + if($mode === 'create' && $topicType === null) { + $topicType = array_key_first($topicTypes); + } elseif(!array_key_exists($topicType, $topicTypes) && $topicTypeChanged) { + $notices[] = 'You are not allowed to set this topic type.'; + } + } + + if(!Parser::isValid($postParser)) { + $notices[] = 'Invalid parser selected.'; + } + + switch(forum_validate_post($postText)) { + case 'too-short': + $notices[] = 'Post content was too short.'; + break; + + case 'too-long': + $notices[] = 'Post content was too long.'; + break; + } + + if(empty($notices)) { + switch($mode) { + case 'create': + if(!empty($topic)) { + forum_topic_bump($topic['topic_id']); + } else { + $topicId = forum_topic_create( + $forum['forum_id'], + $currentUserId, + $topicTitle, + $topicType + ); + } + + $postId = forum_post_create( + $topicId, + $forum['forum_id'], + $currentUserId, + IPAddress::remote(), + $postText, + $postParser, + $postSignature + ); + forum_topic_mark_read($currentUserId, $topicId, $forum['forum_id']); + forum_count_increase($forum['forum_id'], empty($topic)); + break; + + case 'edit': + if(!forum_post_update($postId, IPAddress::remote(), $postText, $postParser, $postSignature, $postText !== $post['post_text'])) { + $notices[] = 'Post edit failed.'; + } + + if($isEditingTopic && ($topicTitleChanged || $topicTypeChanged)) { + if(!forum_topic_update($topicId, $topicTitle, $topicType)) { + $notices[] = 'Topic update failed.'; + } + } + break; + } + + if(empty($notices)) { + $redirect = url(empty($topic) ? 'forum-topic' : 'forum-post', [ + 'topic' => $topicId ?? 0, + 'post' => $postId ?? 0, + 'post_fragment' => 'p' . ($postId ?? 0), + ]); + redirect($redirect); + return; + } + } + } +} + +if(!empty($topic)) { + Template::set('posting_topic', $topic); +} + +if($mode === 'edit') { // $post is pretty much sure to be populated at this point + Template::set('posting_post', $post); +} + +$displayInfo = forum_posting_info($currentUserId); + +Template::render('forum.posting', [ + 'posting_breadcrumbs' => forum_get_breadcrumbs($forumId), + 'global_accent_colour' => forum_get_colour($forumId), + 'posting_forum' => $forum, + 'posting_info' => $displayInfo, + 'posting_notices' => $notices, + 'posting_mode' => $mode, + 'posting_types' => $topicTypes, + 'posting_defaults' => [ + 'title' => $topicTitle ?? null, + 'type' => $topicType ?? null, + 'text' => $postText ?? null, + 'parser' => $postParser ?? null, + 'signature' => $postSignature ?? null, + ], +]); diff --git a/public/forum/topic-priority.php b/public/forum/topic-priority.php new file mode 100644 index 0000000..3a92e01 --- /dev/null +++ b/public/forum/topic-priority.php @@ -0,0 +1,55 @@ +getId(); + +if($topicUserId < 1) { + echo render_error(403); + return; +} + +$topic = forum_topic_get($topicId, true); +$perms = $topic + ? forum_perms_get_user($topic['forum_id'], $topicUserId)[MSZ_FORUM_PERMS_GENERAL] + : 0; + +if(isset($topicUser) && $topicUser->hasActiveWarning()) + $perms &= ~MSZ_FORUM_PERM_SET_WRITE; + +$topicIsDeleted = !empty($topic['topic_deleted']); +$canDeleteAny = perms_check($perms, MSZ_FORUM_PERM_DELETE_ANY_POST); + +if(!$topic || ($topicIsDeleted && !$canDeleteAny)) { + echo render_error(404); + return; +} + +if(!perms_check($perms, MSZ_FORUM_PERM_VIEW_FORUM, true) // | MSZ_FORUM_PERM_PRIORITY_VOTE + || !$canDeleteAny + && ( + !empty($topic['topic_locked']) + || !empty($topic['topic_archived']) + ) +) { + echo render_error(403); + return; +} + +if(!forum_has_priority_voting($topic['forum_type'])) { + echo render_error(400); + return; +} + +forum_topic_priority_increase($topicId, $topicUserId); + +url_redirect('forum-topic', ['topic' => $topicId]); diff --git a/public/forum/topic.php b/public/forum/topic.php new file mode 100644 index 0000000..690cd47 --- /dev/null +++ b/public/forum/topic.php @@ -0,0 +1,388 @@ +getId(); + +if($topicId < 1 && $postId > 0) { + $postInfo = forum_post_find($postId, $topicUserId); + + if(!empty($postInfo['topic_id'])) { + $topicId = (int)$postInfo['topic_id']; + } +} + +$topic = forum_topic_get($topicId, true); +$perms = $topic + ? forum_perms_get_user($topic['forum_id'], $topicUserId)[MSZ_FORUM_PERMS_GENERAL] + : 0; + +if(isset($topicUser) && $topicUser->hasActiveWarning()) + $perms &= ~MSZ_FORUM_PERM_SET_WRITE; + +$topicIsDeleted = !empty($topic['topic_deleted']); +$canDeleteAny = perms_check($perms, MSZ_FORUM_PERM_DELETE_ANY_POST); + +if(!$topic || ($topicIsDeleted && !$canDeleteAny)) { + echo render_error(404); + return; +} + +if(!perms_check($perms, MSZ_FORUM_PERM_VIEW_FORUM)) { + echo render_error(403); + return; +} + +if(!empty($topic['poll_id'])) { + $pollOptions = forum_poll_get_options($topic['poll_id']); + $pollUserAnswers = forum_poll_get_user_answers($topic['poll_id'], $topicUserId); +} + +if(forum_has_priority_voting($topic['forum_type'])) { + $topicPriority = forum_topic_priority($topic['topic_id']); +} + +$topicIsLocked = !empty($topic['topic_locked']); +$topicIsArchived = !empty($topic['topic_archived']); +$topicPostsTotal = (int)($topic['topic_count_posts'] + $topic['topic_count_posts_deleted']); +$topicIsFrozen = $topicIsArchived || $topicIsDeleted; +$canDeleteOwn = !$topicIsFrozen && !$topicIsLocked && perms_check($perms, MSZ_FORUM_PERM_DELETE_POST); +$canBumpTopic = !$topicIsFrozen && perms_check($perms, MSZ_FORUM_PERM_BUMP_TOPIC); +$canLockTopic = !$topicIsFrozen && perms_check($perms, MSZ_FORUM_PERM_LOCK_TOPIC); +$canNukeOrRestore = $canDeleteAny && $topicIsDeleted; +$canDelete = !$topicIsDeleted && ( + $canDeleteAny || ( + $topicPostsTotal > 0 + && $topicPostsTotal <= MSZ_FORUM_TOPIC_DELETE_POST_LIMIT + && $canDeleteOwn + && $topic['author_user_id'] === $topicUserId + ) +); + +$validModerationModes = [ + 'delete', 'restore', 'nuke', + 'bump', 'lock', 'unlock', +]; + +if(in_array($moderationMode, $validModerationModes, true)) { + $redirect = !empty($_SERVER['HTTP_REFERER']) && empty($_SERVER['HTTP_X_MISUZU_XHR']) ? $_SERVER['HTTP_REFERER'] : ''; + $isXHR = !$redirect; + + if($isXHR) { + header('Content-Type: application/json; charset=utf-8'); + } elseif(!is_local_url($redirect)) { + echo render_info('Possible request forgery detected.', 403); + return; + } + + if(!CSRF::validateRequest()) { + echo render_info_or_json($isXHR, "Couldn't verify this request, please refresh the page and try again.", 403); + return; + } + + header(CSRF::header()); + + if(!UserSession::hasCurrent()) { + echo render_info_or_json($isXHR, 'You must be logged in to manage posts.', 401); + return; + } + + if($topicUser->isBanned()) { + echo render_info_or_json($isXHR, 'You have been banned, check your profile for more information.', 403); + return; + } + if($topicUser->isSilenced()) { + echo render_info_or_json($isXHR, 'You have been silenced, check your profile for more information.', 403); + return; + } + + switch($moderationMode) { + case 'delete': + $canDeleteCode = forum_topic_can_delete($topic, $topicUserId); + $canDeleteMsg = ''; + $responseCode = 200; + + switch($canDeleteCode) { + case MSZ_E_FORUM_TOPIC_DELETE_USER: + $responseCode = 401; + $canDeleteMsg = 'You must be logged in to delete topics.'; + break; + case MSZ_E_FORUM_TOPIC_DELETE_TOPIC: + $responseCode = 404; + $canDeleteMsg = "This topic doesn't exist."; + break; + case MSZ_E_FORUM_TOPIC_DELETE_DELETED: + $responseCode = 404; + $canDeleteMsg = 'This topic has already been marked as deleted.'; + break; + case MSZ_E_FORUM_TOPIC_DELETE_OWNER: + $responseCode = 403; + $canDeleteMsg = 'You can only delete your own topics.'; + break; + case MSZ_E_FORUM_TOPIC_DELETE_OLD: + $responseCode = 401; + $canDeleteMsg = 'This topic has existed for too long. Ask a moderator to remove if it absolutely necessary.'; + break; + case MSZ_E_FORUM_TOPIC_DELETE_PERM: + $responseCode = 401; + $canDeleteMsg = 'You are not allowed to delete topics.'; + break; + case MSZ_E_FORUM_TOPIC_DELETE_POSTS: + $responseCode = 403; + $canDeleteMsg = 'This topic already has replies, you may no longer delete it. Ask a moderator to remove if it absolutely necessary.'; + break; + case MSZ_E_FORUM_TOPIC_DELETE_OK: + break; + default: + $responseCode = 500; + $canDeleteMsg = sprintf('Unknown error \'%d\'', $canDelete); + } + + if($canDeleteCode !== MSZ_E_FORUM_TOPIC_DELETE_OK) { + if($isXHR) { + http_response_code($responseCode); + echo json_encode([ + 'success' => false, + 'topic_id' => $topic['topic_id'], + 'code' => $canDeleteCode, + 'message' => $canDeleteMsg, + ]); + break; + } + + echo render_info($canDeleteMsg, $responseCode); + break; + } + + if(!$isXHR) { + if(!isset($_GET['confirm'])) { + Template::render('forum.confirm', [ + 'title' => 'Confirm topic deletion', + 'class' => 'far fa-trash-alt', + 'message' => sprintf('You are about to delete topic #%d. Are you sure about that?', $topic['topic_id']), + 'params' => [ + 't' => $topic['topic_id'], + 'm' => 'delete', + ], + ]); + break; + } elseif(!$submissionConfirmed) { + url_redirect( + 'forum-topic', + ['topic' => $topic['topic_id']] + ); + break; + } + } + + $deleteTopic = forum_topic_delete($topic['topic_id']); + + if($deleteTopic) { + AuditLog::create(AuditLog::FORUM_TOPIC_DELETE, [$topic['topic_id']]); + } + + if($isXHR) { + echo json_encode([ + 'success' => $deleteTopic, + 'topic_id' => $topic['topic_id'], + 'message' => $deleteTopic ? 'Topic deleted!' : 'Failed to delete topic.', + ]); + break; + } + + if(!$deleteTopic) { + echo render_error(500); + break; + } + + url_redirect('forum-category', [ + 'forum' => $topic['forum_id'], + ]); + break; + + case 'restore': + if(!$canNukeOrRestore) { + echo render_error(403); + break; + } + + if(!$isXHR) { + if(!isset($_GET['confirm'])) { + Template::render('forum.confirm', [ + 'title' => 'Confirm topic restore', + 'class' => 'fas fa-magic', + 'message' => sprintf('You are about to restore topic #%d. Are you sure about that?', $topic['topic_id']), + 'params' => [ + 't' => $topic['topic_id'], + 'm' => 'restore', + ], + ]); + break; + } elseif(!$submissionConfirmed) { + url_redirect('forum-topic', [ + 'topic' => $topic['topic_id'], + ]); + break; + } + } + + $restoreTopic = forum_topic_restore($topic['topic_id']); + + if(!$restoreTopic) { + echo render_error(500); + break; + } + + AuditLog::create(AuditLog::FORUM_TOPIC_RESTORE, [$topic['topic_id']]); + http_response_code(204); + + if(!$isXHR) { + url_redirect('forum-category', [ + 'forum' => $topic['forum_id'], + ]); + } + break; + + case 'nuke': + if(!$canNukeOrRestore) { + echo render_error(403); + break; + } + + if(!$isXHR) { + if(!isset($_GET['confirm'])) { + Template::render('forum.confirm', [ + 'title' => 'Confirm topic nuke', + 'class' => 'fas fa-radiation', + 'message' => sprintf('You are about to PERMANENTLY DELETE topic #%d. Are you sure about that?', $topic['topic_id']), + 'params' => [ + 't' => $topic['topic_id'], + 'm' => 'nuke', + ], + ]); + break; + } elseif(!$submissionConfirmed) { + url_redirect('forum-topic', [ + 'topic' => $topic['topic_id'], + ]); + break; + } + } + + $nukeTopic = forum_topic_nuke($topic['topic_id']); + + if(!$nukeTopic) { + echo render_error(500); + break; + } + + AuditLog::create(AuditLog::FORUM_TOPIC_NUKE, [$topic['topic_id']]); + http_response_code(204); + + if(!$isXHR) { + url_redirect('forum-category', [ + 'forum' => $topic['forum_id'], + ]); + } + break; + + case 'bump': + if($canBumpTopic && forum_topic_bump($topic['topic_id'])) { + AuditLog::create(AuditLog::FORUM_TOPIC_BUMP, [$topic['topic_id']]); + } + + url_redirect('forum-topic', [ + 'topic' => $topic['topic_id'], + ]); + break; + + case 'lock': + if($canLockTopic && !$topicIsLocked && forum_topic_lock($topic['topic_id'])) { + AuditLog::create(AuditLog::FORUM_TOPIC_LOCK, [$topic['topic_id']]); + } + + url_redirect('forum-topic', [ + 'topic' => $topic['topic_id'], + ]); + break; + + case 'unlock': + if($canLockTopic && $topicIsLocked && forum_topic_unlock($topic['topic_id'])) { + AuditLog::create(AuditLog::FORUM_TOPIC_UNLOCK, [$topic['topic_id']]); + } + + url_redirect('forum-topic', [ + 'topic' => $topic['topic_id'], + ]); + break; + } + return; +} + +$topicPosts = $topic['topic_count_posts']; + +if($canDeleteAny) { + $topicPosts += $topic['topic_count_posts_deleted']; +} + +$topicPagination = new Pagination($topicPosts, MSZ_FORUM_POSTS_PER_PAGE, 'page'); + +if(isset($postInfo['preceeding_post_count'])) { + $preceedingPosts = $postInfo['preceeding_post_count']; + + if($canDeleteAny) { + $preceedingPosts += $postInfo['preceeding_post_deleted_count']; + } + + $topicPagination->setPage(floor($preceedingPosts / $topicPagination->getRange()), true); +} + +if(!$topicPagination->hasValidOffset()) { + echo render_error(404); + return; +} + +Template::set('topic_perms', $perms); + +$posts = forum_post_listing( + $topic['topic_id'], + $topicPagination->getOffset(), + $topicPagination->getRange(), + perms_check($perms, MSZ_FORUM_PERM_DELETE_ANY_POST) +); + +if(!$posts) { + echo render_error(404); + return; +} + +$canReply = !$topicIsArchived && !$topicIsLocked && !$topicIsDeleted && perms_check($perms, MSZ_FORUM_PERM_CREATE_POST); + +forum_topic_mark_read($topicUserId, $topic['topic_id'], $topic['forum_id']); + +Template::render('forum.topic', [ + 'topic_breadcrumbs' => forum_get_breadcrumbs($topic['forum_id']), + 'global_accent_colour' => forum_get_colour($topic['forum_id']), + 'topic_info' => $topic, + 'topic_posts' => $posts, + 'can_reply' => $canReply, + 'topic_pagination' => $topicPagination, + 'topic_can_delete' => $canDelete, + 'topic_can_nuke_or_restore' => $canNukeOrRestore, + 'topic_can_bump' => $canBumpTopic, + 'topic_can_lock' => $canLockTopic, + 'topic_poll_options' => $pollOptions ?? [], + 'topic_poll_user_answers' => $pollUserAnswers ?? [], + 'topic_priority_votes' => $topicPriority ?? [], +]); diff --git a/public/images/88x31.gif b/public/images/88x31.gif new file mode 100644 index 0000000..f00df71 Binary files /dev/null and b/public/images/88x31.gif differ diff --git a/public/images/banned-avatar.png b/public/images/banned-avatar.png new file mode 100644 index 0000000..0d7df85 Binary files /dev/null and b/public/images/banned-avatar.png differ diff --git a/public/images/clouds-8559a5.png b/public/images/clouds-8559a5.png new file mode 100644 index 0000000..bcb13b9 Binary files /dev/null and b/public/images/clouds-8559a5.png differ diff --git a/public/images/clouds.png b/public/images/clouds.png new file mode 100644 index 0000000..4191cd7 Binary files /dev/null and b/public/images/clouds.png differ diff --git a/public/images/ffbxexy.png b/public/images/ffbxexy.png new file mode 100644 index 0000000..b5076dc Binary files /dev/null and b/public/images/ffbxexy.png differ diff --git a/public/images/flag-sprite.png b/public/images/flag-sprite.png new file mode 100644 index 0000000..32fc884 Binary files /dev/null and b/public/images/flag-sprite.png differ diff --git a/public/images/landing-logo.png b/public/images/landing-logo.png new file mode 100644 index 0000000..134757e Binary files /dev/null and b/public/images/landing-logo.png differ diff --git a/public/images/logos/imouto-broom.png b/public/images/logos/imouto-broom.png new file mode 100644 index 0000000..d29a4b4 Binary files /dev/null and b/public/images/logos/imouto-broom.png differ diff --git a/public/images/logos/imouto-christmas.png b/public/images/logos/imouto-christmas.png new file mode 100644 index 0000000..52e9aff Binary files /dev/null and b/public/images/logos/imouto-christmas.png differ diff --git a/public/images/logos/imouto-cirno.png b/public/images/logos/imouto-cirno.png new file mode 100644 index 0000000..cde90ad Binary files /dev/null and b/public/images/logos/imouto-cirno.png differ diff --git a/public/images/logos/imouto-default.png b/public/images/logos/imouto-default.png new file mode 100644 index 0000000..845168f Binary files /dev/null and b/public/images/logos/imouto-default.png differ diff --git a/public/images/logos/imouto-halloween.png b/public/images/logos/imouto-halloween.png new file mode 100644 index 0000000..d3006d1 Binary files /dev/null and b/public/images/logos/imouto-halloween.png differ diff --git a/public/images/no-avatar.png b/public/images/no-avatar.png new file mode 100644 index 0000000..f782f29 Binary files /dev/null and b/public/images/no-avatar.png differ diff --git a/public/images/pixel.png b/public/images/pixel.png new file mode 100644 index 0000000..909c66d Binary files /dev/null and b/public/images/pixel.png differ diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..212d259 --- /dev/null +++ b/public/index.php @@ -0,0 +1,9 @@ +setUpHttp(str_contains($request->getPath(), '.php')); +$ctx->dispatchHttp($request); diff --git a/public/info.php b/public/info.php new file mode 100644 index 0000000..41cc616 --- /dev/null +++ b/public/info.php @@ -0,0 +1,2 @@ +getId(), MSZ_PERM_CHANGELOG_MANAGE_CHANGES)) { + echo render_error(403); + return; +} + +define('MANAGE_ACTIONS', [ + ['action_id' => ChangelogChange::ACTION_ADD, 'action_name' => 'Added'], + ['action_id' => ChangelogChange::ACTION_REMOVE, 'action_name' => 'Removed'], + ['action_id' => ChangelogChange::ACTION_UPDATE, 'action_name' => 'Updated'], + ['action_id' => ChangelogChange::ACTION_FIX, 'action_name' => 'Fixed'], + ['action_id' => ChangelogChange::ACTION_IMPORT, 'action_name' => 'Imported'], + ['action_id' => ChangelogChange::ACTION_REVERT, 'action_name' => 'Reverted'], +]); + +$changeId = (int)filter_input(INPUT_GET, 'c', FILTER_SANITIZE_NUMBER_INT); +$tags = ChangelogTag::all(); + +if($changeId > 0) + try { + $change = ChangelogChange::byId($changeId); + } catch(ChangelogChangeNotFoundException $ex) { + url_redirect('manage-changelog-changes'); + return; + } + +if($_SERVER['REQUEST_METHOD'] === 'POST' && CSRF::validateRequest()) { + if(!empty($_POST['change']) && is_array($_POST['change'])) { + if(!isset($change)) { + $change = new ChangelogChange; + $isNew = true; + } + + $changeUserId = filter_var($_POST['change']['user'], FILTER_SANITIZE_NUMBER_INT); + if($changeUserId === 0) + $changeUser = null; + else + try { + $changeUser = User::byId($changeUserId); + } catch(UserNotFoundException $ex) { + $changeUser = User::getCurrent(); + } + + $change->setHeader($_POST['change']['log']) + ->setBody($_POST['change']['text']) + ->setAction($_POST['change']['action']) + ->setUser($changeUser) + ->save(); + + AuditLog::create( + empty($isNew) + ? AuditLog::CHANGELOG_ENTRY_EDIT + : AuditLog::CHANGELOG_ENTRY_CREATE, + [$change->getId()] + ); + } + + if(isset($change) && !empty($_POST['tags']) && is_array($_POST['tags']) && array_test($_POST['tags'], 'ctype_digit')) { + $applyTags = []; + foreach($_POST['tags'] as $tagId) + try { + $applyTags[] = ChangelogTag::byId((int)filter_var($tagId, FILTER_SANITIZE_NUMBER_INT)); + } catch(ChangelogTagNotFoundException $ex) {} + $change->setTags($applyTags); + } + + if(!empty($isNew)) { + url_redirect('manage-changelog-change', ['change' => $change->getId()]); + return; + } +} + +Template::render('manage.changelog.change', [ + 'change' => $change ?? null, + 'change_tags' => $tags, + 'change_actions' => MANAGE_ACTIONS, +]); diff --git a/public/manage/changelog/index.php b/public/manage/changelog/index.php new file mode 100644 index 0000000..022a507 --- /dev/null +++ b/public/manage/changelog/index.php @@ -0,0 +1,26 @@ +getId(), MSZ_PERM_CHANGELOG_MANAGE_CHANGES)) { + echo render_error(403); + return; +} + +$changelogPagination = new Pagination(ChangelogChange::countAll(), 30); + +if(!$changelogPagination->hasValidOffset()) { + echo render_error(404); + return; +} + +$changes = ChangelogChange::all($changelogPagination); + +Template::render('manage.changelog.changes', [ + 'changelog_changes' => $changes, + 'changelog_pagination' => $changelogPagination, +]); diff --git a/public/manage/changelog/tag.php b/public/manage/changelog/tag.php new file mode 100644 index 0000000..497cba0 --- /dev/null +++ b/public/manage/changelog/tag.php @@ -0,0 +1,52 @@ +getId(), MSZ_PERM_CHANGELOG_MANAGE_TAGS)) { + echo render_error(403); + return; +} + +$tagId = (int)filter_input(INPUT_GET, 't', FILTER_SANITIZE_NUMBER_INT); + +if($tagId > 0) + try { + $tagInfo = ChangelogTag::byId($tagId); + } catch(ChangelogTagNotFoundException $ex) { + url_redirect('manage-changelog-tags'); + return; + } + +if(!empty($_POST['tag']) && is_array($_POST['tag']) && CSRF::validateRequest()) { + if(!isset($tagInfo)) { + $tagInfo = new ChangelogTag; + $isNew = true; + } + + $tagInfo->setName($_POST['tag']['name']) + ->setDescription($_POST['tag']['description']) + ->setArchived(!empty($_POST['tag']['archived'])) + ->save(); + + AuditLog::create( + empty($isNew) + ? AuditLog::CHANGELOG_TAG_EDIT + : AuditLog::CHANGELOG_TAG_CREATE, + [$tagInfo->getId()] + ); + + if(!empty($isNew)) { + url_redirect('manage-changelog-tag', ['tag' => $tagInfo->getId()]); + return; + } +} + +Template::render('manage.changelog.tag', [ + 'edit_tag' => $tagInfo ?? null, +]); diff --git a/public/manage/changelog/tags.php b/public/manage/changelog/tags.php new file mode 100644 index 0000000..297cea2 --- /dev/null +++ b/public/manage/changelog/tags.php @@ -0,0 +1,16 @@ +getId(), MSZ_PERM_CHANGELOG_MANAGE_TAGS)) { + echo render_error(403); + return; +} + +Template::render('manage.changelog.tags', [ + 'changelog_tags' => ChangelogTag::all(), +]); diff --git a/public/manage/forum/category.php b/public/manage/forum/category.php new file mode 100644 index 0000000..22a23f3 --- /dev/null +++ b/public/manage/forum/category.php @@ -0,0 +1,26 @@ +getId(), MSZ_PERM_FORUM_MANAGE_FORUMS)) { + echo render_error(403); + return; +} + +$getForum = DB::prepare(' + SELECT * + FROM `msz_forum_categories` + WHERE `forum_id` = :forum_id +'); +$getForum->bind('forum_id', (int)($_GET['f'] ?? 0)); +$forum = $getForum->fetch(); + +if(!$forum) { + echo render_error(404); + return; +} + +Template::render('manage.forum.forum', compact('forum')); diff --git a/public/manage/forum/index.php b/public/manage/forum/index.php new file mode 100644 index 0000000..1cb0ca8 --- /dev/null +++ b/public/manage/forum/index.php @@ -0,0 +1,23 @@ +getId(), MSZ_PERM_FORUM_MANAGE_FORUMS)) { + echo render_error(403); + return; +} + +$forums = DB::query('SELECT * FROM `msz_forum_categories`')->fetchAll(); +$rawPerms = perms_create(MSZ_FORUM_PERM_MODES); +$perms = manage_forum_perms_list($rawPerms); + +if(!empty($_POST['perms']) && is_array($_POST['perms'])) { + $finalPerms = manage_perms_apply($perms, $_POST['perms'], $rawPerms); + $perms = manage_forum_perms_list($finalPerms); + Template::set('calculated_perms', $finalPerms); +} + +Template::render('manage.forum.listing', compact('forums', 'perms')); diff --git a/public/manage/general/blacklist.php b/public/manage/general/blacklist.php new file mode 100644 index 0000000..98c2538 --- /dev/null +++ b/public/manage/general/blacklist.php @@ -0,0 +1,51 @@ +getId(), MSZ_PERM_GENERAL_MANAGE_BLACKLIST)) { + echo render_error(403); + return; +} + +$notices = []; + +if(!empty($_POST)) { + if(!CSRF::validateRequest()) { + $notices[] = 'Verification failed.'; + } else { + header(CSRF::header()); + + if(!empty($_POST['blacklist']['remove']) && is_array($_POST['blacklist']['remove'])) { + foreach($_POST['blacklist']['remove'] as $cidr) { + if(!IPAddressBlacklist::remove($cidr)) { + $notices[] = sprintf('Failed to remove "%s" from the blacklist.', $cidr); + } + } + } + + if(!empty($_POST['blacklist']['add']) && is_string($_POST['blacklist']['add'])) { + $cidrs = explode("\n", $_POST['blacklist']['add']); + + foreach($cidrs as $cidr) { + $cidr = trim($cidr); + + if(empty($cidr)) { + continue; + } + + if(!IPAddressBlacklist::add($cidr)) { + $notices[] = sprintf('Failed to add "%s" to the blacklist.', $cidr); + } + } + } + } +} + +Template::render('manage.general.blacklist', [ + 'notices' => $notices, + 'blacklist' => IPAddressBlacklist::list(), +]); diff --git a/public/manage/general/emoticon.php b/public/manage/general/emoticon.php new file mode 100644 index 0000000..33df847 --- /dev/null +++ b/public/manage/general/emoticon.php @@ -0,0 +1,52 @@ +getId(), MSZ_PERM_GENERAL_MANAGE_EMOTES)) { + echo render_error(403); + return; +} + +$emoteId = !empty($_GET['e']) && is_string($_GET['e']) ? (int)$_GET['e'] : 0; +$isNew = $emoteId <= 0; +$emoteInfo = !$isNew ? Emoticon::byId($emoteId) : new Emoticon; + +if(CSRF::validateRequest() && isset($_POST['emote_order']) && isset($_POST['emote_hierarchy']) && !empty($_POST['emote_url']) && !empty($_POST['emote_strings'])) { + $emoteInfo->setUrl($_POST['emote_url']) + ->setRank($_POST['emote_hierarchy']) + ->setOrder($_POST['emote_order']) + ->save(); + + if($isNew && !$emoteInfo->hasId()) + throw new \Exception("SOMETHING HAPPENED"); + + $setStrings = array_column($emoteInfo->getStrings(), 'emote_string'); + $applyStrings = explode(' ', mb_strtolower($_POST['emote_strings'])); + $removeStrings = []; + + foreach($setStrings as $string) { + if(!in_array($string, $applyStrings)) { + $removeStrings[] = $string; + } + } + + $setStrings = array_diff($setStrings, $removeStrings); + + foreach($applyStrings as $string) { + if(!in_array($string, $setStrings)) { + $setStrings[] = $string; + } + } + + foreach($removeStrings as $string) + $emoteInfo->removeString($string); + foreach($setStrings as $string) + $emoteInfo->addString($string); +} + +Template::render('manage.general.emoticon', [ + 'emote_info' => $emoteInfo, +]); diff --git a/public/manage/general/emoticons.php b/public/manage/general/emoticons.php new file mode 100644 index 0000000..40417ec --- /dev/null +++ b/public/manage/general/emoticons.php @@ -0,0 +1,37 @@ +getId(), MSZ_PERM_GENERAL_MANAGE_EMOTES)) { + echo render_error(403); + return; +} + +if(CSRF::validateRequest() && !empty($_GET['emote']) && is_string($_GET['emote'])) { + $emoteId = (int)$_GET['emote']; + $emoteInfo = Emoticon::byId($emoteId); + + if(empty($emoteInfo)) { + echo render_error(404); + return; + } + + if(!empty($_GET['order']) && is_string($_GET['order'])) { + $emoteInfo->changeOrder($_GET['order'] === 'i' ? 1 : -1); + } elseif(!empty($_GET['alias']) && is_string($_GET['alias']) && ctype_alnum($_GET['alias'])) { + $emoteInfo->addString(mb_strtolower($_GET['alias'])); + return; + } elseif(!empty($_GET['delete'])) { + $emoteInfo->delete(); + } + + url_redirect('manage-general-emoticons'); + return; +} + +Template::render('manage.general.emoticons', [ + 'emotes' => Emoticon::all(PHP_INT_MAX), +]); diff --git a/public/manage/general/index.php b/public/manage/general/index.php new file mode 100644 index 0000000..e247eff --- /dev/null +++ b/public/manage/general/index.php @@ -0,0 +1,178 @@ + 0 + ) AS `stat_comment_likes`, + ( + SELECT COUNT(`user_id`) + FROM `msz_comments_votes` + WHERE `comment_vote` < 0 + ) AS `stat_comment_dislikes`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + ) AS `stat_forum_posts_total`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `post_deleted` IS NOT NULL + ) AS `stat_forum_posts_deleted`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `post_edited` IS NOT NULL + ) AS `stat_forum_posts_edited`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `post_parse` = 0 + ) AS `stat_forum_posts_plain`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `post_parse` = 1 + ) AS `stat_forum_posts_bbcode`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `post_parse` = 2 + ) AS `stat_forum_posts_markdown`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `post_display_signature` != 0 + ) AS `stat_forum_posts_signature`, + ( + SELECT COUNT(`topic_id`) + FROM `msz_forum_topics` + ) AS `stat_forum_topics_total`, + ( + SELECT COUNT(`topic_id`) + FROM `msz_forum_topics` + WHERE `topic_type` = 0 + ) AS `stat_forum_topics_normal`, + ( + SELECT COUNT(`topic_id`) + FROM `msz_forum_topics` + WHERE `topic_type` = 1 + ) AS `stat_forum_topics_pinned`, + ( + SELECT COUNT(`topic_id`) + FROM `msz_forum_topics` + WHERE `topic_type` = 2 + ) AS `stat_forum_topics_announce`, + ( + SELECT COUNT(`topic_id`) + FROM `msz_forum_topics` + WHERE `topic_type` = 3 + ) AS `stat_forum_topics_global_announce`, + ( + SELECT COUNT(`topic_id`) + FROM `msz_forum_topics` + WHERE `topic_deleted` IS NOT NULL + ) AS `stat_forum_topics_deleted`, + ( + SELECT COUNT(`topic_id`) + FROM `msz_forum_topics` + WHERE `topic_locked` IS NOT NULL + ) AS `stat_forum_topics_locked`, + ( + SELECT COUNT(*) + FROM `msz_ip_blacklist` + ) AS `stat_blacklist`, + ( + SELECT COUNT(*) + FROM `msz_login_attempts` + ) AS `stat_login_attempts_total`, + ( + SELECT COUNT(*) + FROM `msz_login_attempts` + WHERE `attempt_success` = 0 + ) AS `stat_login_attempts_failed`, + ( + SELECT COUNT(`session_id`) + FROM `msz_sessions` + ) AS `stat_user_sessions`, + ( + SELECT COUNT(`user_id`) + FROM `msz_users_password_resets` + ) AS `stat_user_password_resets`, + ( + SELECT COUNT(`warning_id`) + FROM `msz_user_warnings` + WHERE `warning_type` != 0 + ) AS `stat_user_warnings` +')->fetch(); + +if(!empty($_GET['poll'])) { + header('Content-Type: application/json; charset=utf-8'); + echo json_encode($statistics); + return; +} + +Template::render('manage.general.overview', [ + 'statistics' => $statistics, +]); diff --git a/public/manage/general/logs.php b/public/manage/general/logs.php new file mode 100644 index 0000000..a8bd18e --- /dev/null +++ b/public/manage/general/logs.php @@ -0,0 +1,27 @@ +getId(), MSZ_PERM_GENERAL_VIEW_LOGS)) { + echo render_error(403); + return; +} + +$pagination = new Pagination(AuditLog::countAll(), 50); + +if(!$pagination->hasValidOffset()) { + echo render_error(404); + return; +} + +$logs = AuditLog::all($pagination); + +Template::render('manage.general.logs', [ + 'global_logs' => $logs, + 'global_logs_pagination' => $pagination, +]); diff --git a/public/manage/general/setting-delete.php b/public/manage/general/setting-delete.php new file mode 100644 index 0000000..21c98bb --- /dev/null +++ b/public/manage/general/setting-delete.php @@ -0,0 +1,37 @@ +getId(), MSZ_PERM_GENERAL_MANAGE_CONFIG)) { + echo render_error(403); + return; +} + +$sName = (string)filter_input(INPUT_GET, 'name'); +if(!Config::validateName($sName) || !Config::has($sName)) + throw new \Exception("Config value does not exist."); + +if($_SERVER['REQUEST_METHOD'] === 'POST') { + if(!CSRF::validateRequest()) + throw new \Exception("Request verification failed."); + + AuditLog::create(AuditLog::CONFIG_DELETE, [$sName]); + Config::remove($sName); + url_redirect('manage-general-settings'); +} else { + $sValue = Config::get($sName); + + Template::render('manage.general.setting-delete', [ + 'conf_var' => [ + 'name' => $sName, + 'type' => Config::type($sValue), + 'value' => $sValue, + ], + ]); +} diff --git a/public/manage/general/setting.php b/public/manage/general/setting.php new file mode 100644 index 0000000..0735092 --- /dev/null +++ b/public/manage/general/setting.php @@ -0,0 +1,116 @@ +getId(), MSZ_PERM_GENERAL_MANAGE_CONFIG)) { + echo render_error(403); + return; +} + +$sVar = [ + 'name' => '', + 'type' => '', + 'value' => null, + 'new' => true, +]; + +$sName = (string)filter_input(INPUT_GET, 'name'); + +if(!empty($sName)) { + if(!Config::validateName($sName)) + throw new \Exception("Config key name has invalid format."); + + $sVar['name'] = $sName; +} + +$sType = (string)filter_input(INPUT_GET, 'type'); +if(!empty($sType)) { + if(!Config::isValidType($sType)) + throw new \Exception("Specified type is invalid."); + + $sVar['type'] = $sType; + $sVar['value'] = Config::default($sType); +} + +if($_SERVER['REQUEST_METHOD'] === 'POST') { + if(!CSRF::validateRequest()) + throw new \Exception("Request verification failed."); + + if(empty($sName)) { + $sName = (string)filter_input(INPUT_POST, 'conf_name'); + + if(empty($sName) || !Config::validateName($sName)) + throw new \Exception("Config key name has invalid format."); + + $sVar['name'] = $sName; + } + + $sLogAction = AuditLog::CONFIG_CREATE; + + if(Config::has($sName)) { + $sType = Config::type(Config::get($sName)); + $sVar['new'] = false; + $sLogAction = AuditLog::CONFIG_UPDATE; + } elseif(empty($sType)) { + $sType = (string)filter_input(INPUT_POST, 'conf_type'); + if(empty($sType) || !Config::isValidType($sType)) + throw new \Exception("Specified type is invalid."); + } + + $sVar['type'] = $sType; + + $sValue = Config::default($sType); + + if($sType === 'array') { + if(!empty($_POST['conf_value']) && is_array($_POST['conf_value'])) { + foreach($_POST['conf_value'] as $fv) { + $fv = strval($fv); + + if(str_starts_with($fv, 's:')) { + $fv = substr($fv, 2); + } elseif(str_starts_with($fv, 'i:')) { + $fv = intval(substr($fv, 2)); + } elseif(str_starts_with($fv, 'b:')) { + $fv = strtolower(substr($fv, 2)); + $fv = $fv !== 'false' && $fv !== '0' && $fv !== ''; + } + + $sValue[] = $fv; + } + } + } elseif($sType === 'boolean') { + $sValue = !empty($_POST['conf_value']); + } else { + $sValue = (string)filter_input(INPUT_POST, 'conf_value'); + if($sType === 'integer') + $sValue = intval($sValue); + } + + $sVar['value'] = $sValue; + + AuditLog::create($sLogAction, [$sName]); + Config::set($sName, $sValue); + url_redirect('manage-general-settings'); + return; +} + +if(Config::has($sName)) { + $sVar['new'] = false; + $sValue = Config::get($sName); + $sVar['type'] = $sType = Config::type($sValue); + + if($sType === Config::TYPE_ARR) + foreach($sValue as $fk => $fv) + $sValue[$fk] = ['integer' => 'i', 'string' => 's', 'boolean' => 'b'][gettype($fv)] . ':' . $fv; + + $sVar['value'] = $sValue; +} + +Template::render('manage.general.setting', [ + 'conf_var' => $sVar, +]); diff --git a/public/manage/general/settings.php b/public/manage/general/settings.php new file mode 100644 index 0000000..6600b2c --- /dev/null +++ b/public/manage/general/settings.php @@ -0,0 +1,29 @@ +getId(), MSZ_PERM_GENERAL_MANAGE_CONFIG)) { + echo render_error(403); + return; +} + +$hidden = Config::get('settings.hidden', Config::TYPE_ARR, []); + +$vars = []; +foreach(Config::keys() as $key) { + $var = Config::get($key); + $vars[] = [ + 'key' => $key, + 'type' => Config::type($var), + 'value' => in_array($key, $hidden) ? '*** hidden ***' : json_encode($var), + ]; +} + +Template::render('manage.general.settings', [ + 'conf_vars' => $vars, +]); diff --git a/public/manage/index.php b/public/manage/index.php new file mode 100644 index 0000000..23923f9 --- /dev/null +++ b/public/manage/index.php @@ -0,0 +1,6 @@ +getId(), MSZ_PERM_NEWS_MANAGE_CATEGORIES)) { + echo render_error(403); + return; +} + +$categoriesPagination = new Pagination(NewsCategory::countAll(true), 15); + +if(!$categoriesPagination->hasValidOffset()) { + echo render_error(404); + return; +} + +$categories = NewsCategory::all($categoriesPagination, true); + +Template::render('manage.news.categories', [ + 'news_categories' => $categories, + 'categories_pagination' => $categoriesPagination, +]); diff --git a/public/manage/news/category.php b/public/manage/news/category.php new file mode 100644 index 0000000..12f34f3 --- /dev/null +++ b/public/manage/news/category.php @@ -0,0 +1,51 @@ +getId(), MSZ_PERM_NEWS_MANAGE_CATEGORIES)) { + echo render_error(403); + return; +} + +$categoryId = (int)filter_input(INPUT_GET, 'c', FILTER_SANITIZE_NUMBER_INT); + +if($categoryId > 0) + try { + $categoryInfo = NewsCategory::byId($categoryId); + Template::set('category_info', $categoryInfo); + } catch(NewsCategoryNotFoundException $ex) { + echo render_error(404); + return; + } + +if(!empty($_POST['category']) && CSRF::validateRequest()) { + if(!isset($categoryInfo)) { + $categoryInfo = new NewsCategory; + $isNew = true; + } + + $categoryInfo->setName($_POST['category']['name']) + ->setDescription($_POST['category']['description']) + ->setHidden(!empty($_POST['category']['hidden'])) + ->save(); + + AuditLog::create( + empty($isNew) + ? AuditLog::NEWS_CATEGORY_EDIT + : AuditLog::NEWS_CATEGORY_CREATE, + [$categoryInfo->getId()] + ); + + if(!empty($isNew)) { + header('Location: ' . url('manage-news-category', ['category' => $categoryInfo->getId()])); + return; + } +} + +Template::render('manage.news.category'); diff --git a/public/manage/news/index.php b/public/manage/news/index.php new file mode 100644 index 0000000..77cbfd5 --- /dev/null +++ b/public/manage/news/index.php @@ -0,0 +1,6 @@ +getId(), MSZ_PERM_NEWS_MANAGE_POSTS)) { + echo render_error(403); + return; +} + +$postId = (int)filter_input(INPUT_GET, 'p', FILTER_SANITIZE_NUMBER_INT); +if($postId > 0) + try { + $postInfo = NewsPost::byId($postId); + Template::set('post_info', $postInfo); + } catch(NewsPostNotFoundException $ex) { + echo render_error(404); + return; + } + +$categories = NewsCategory::all(null, true); + +if(!empty($_POST['post']) && CSRF::validateRequest()) { + if(!isset($postInfo)) { + $postInfo = new NewsPost; + $isNew = true; + } + + $currentUserId = User::getCurrent()->getId(); + $postInfo->setTitle( $_POST['post']['title']) + ->setText($_POST['post']['text']) + ->setCategoryId($_POST['post']['category']) + ->setFeatured(!empty($_POST['post']['featured'])); + + if(!empty($isNew)) + $postInfo->setUserId($currentUserId); + + $postInfo->save(); + + AuditLog::create( + empty($isNew) + ? AuditLog::NEWS_POST_EDIT + : AuditLog::NEWS_POST_CREATE, + [$postInfo->getId()] + ); + + if(!empty($isNew)) { + if($postInfo->isFeatured()) { + $twitterApiKey = Config::get('twitter.api.key', Config::TYPE_STR); + $twitterApiSecret = Config::get('twitter.api.secret', Config::TYPE_STR); + $twitterToken = Config::get('twitter.token.key', Config::TYPE_STR); + $twitterTokenSecret = Config::get('twitter.token.secret', Config::TYPE_STR); + + if(!empty($twitterApiKey) && !empty($twitterApiSecret) + && !empty($twitterToken) && !empty($twitterTokenSecret)) { + Twitter::init($twitterApiKey, $twitterApiSecret, $twitterToken, $twitterTokenSecret); + $url = url('news-post', ['post' => $postInfo->getId()]); + Twitter::sendTweet("News :: {$postInfo->getTitle()}\nhttps://{$_SERVER['HTTP_HOST']}{$url}"); + } + } + + header('Location: ' . url('manage-news-post', ['post' => $postInfo->getId()])); + return; + } +} + +Template::render('manage.news.post', [ + 'categories' => $categories, +]); diff --git a/public/manage/news/posts.php b/public/manage/news/posts.php new file mode 100644 index 0000000..faeb4dd --- /dev/null +++ b/public/manage/news/posts.php @@ -0,0 +1,26 @@ +getId(), MSZ_PERM_NEWS_MANAGE_POSTS)) { + echo render_error(403); + return; +} + +$postsPagination = new Pagination(NewsPost::countAll(false, true, true), 15); + +if(!$postsPagination->hasValidOffset()) { + echo render_error(404); + return; +} + +$posts = NewsPost::all($postsPagination, false, true, true); + +Template::render('manage.news.posts', [ + 'news_posts' => $posts, + 'posts_pagination' => $postsPagination, +]); diff --git a/public/manage/users/index.php b/public/manage/users/index.php new file mode 100644 index 0000000..158b9a9 --- /dev/null +++ b/public/manage/users/index.php @@ -0,0 +1,23 @@ +getId(), MSZ_PERM_USER_MANAGE_USERS)) { + echo render_error(403); + return; +} + +$pagination = new Pagination(User::countAll(true), 30); + +if(!$pagination->hasValidOffset()) { + echo render_error(404); + return; +} + +Template::render('manage.users.users', [ + 'manage_users' => User::all(true, $pagination), + 'manage_users_pagination' => $pagination, +]); diff --git a/public/manage/users/role.php b/public/manage/users/role.php new file mode 100644 index 0000000..bc37926 --- /dev/null +++ b/public/manage/users/role.php @@ -0,0 +1,141 @@ +getId(), MSZ_PERM_USER_MANAGE_ROLES)) { + echo render_error(403); + return; +} + +$roleId = (int)filter_input(INPUT_GET, 'r', FILTER_SANITIZE_NUMBER_INT); + +if($roleId > 0) + try { + $roleInfo = UserRole::byId($roleId); + } catch(UserRoleNotFoundException $ex) { + echo render_error(404); + return; + } + +$currentUser = User::getCurrent(); +$currentUserId = $currentUser->getId(); +$canEditPerms = perms_check_user(MSZ_PERMS_USER, $currentUserId, MSZ_PERM_USER_MANAGE_PERMS); + +if($canEditPerms) + $permissions = manage_perms_list(perms_get_role_raw($roleId ?? 0)); + +if(!empty($_POST['role']) && is_array($_POST['role']) && CSRF::validateRequest()) { + $roleHierarchy = (int)($_POST['role']['hierarchy'] ?? -1); + + if(!$currentUser->isSuper() && (isset($roleInfo) ? $roleInfo->hasAuthorityOver($currentUser) : $currentUser->getRank() <= $roleHierarchy)) { + echo 'You don\'t hold authority over this role.'; + return; + } + + $roleName = $_POST['role']['name'] ?? ''; + $roleNameLength = strlen($roleName); + + if($roleNameLength < 1 || $roleNameLength > 255) { + echo 'invalid name length'; + return; + } + + $roleSecret = !empty($_POST['role']['secret']); + + if($roleHierarchy < 1 || $roleHierarchy > 100) { + echo 'Invalid hierarchy value.'; + return; + } + + $roleColour = new Colour; + + if(!empty($_POST['role']['colour']['inherit'])) { + $roleColour->setInherit(true); + } else { + foreach(['red', 'green', 'blue'] as $key) { + $value = (int)($_POST['role']['colour'][$key] ?? -1); + + try { + $roleColour->{'set' . ucfirst($key)}($value); + } catch(\Exception $ex){ + echo $ex->getMessage(); + return; + } + } + } + + $roleDescription = $_POST['role']['description'] ?? ''; + $roleTitle = $_POST['role']['title'] ?? ''; + + if($roleDescription !== null) { + $rdLength = strlen($roleDescription); + + if($rdLength > 1000) { + echo 'description is too long'; + return; + } + } + + if($roleTitle !== null) { + $rtLength = strlen($roleTitle); + + if($rtLength > 64) { + echo 'title is too long'; + return; + } + } + + if(!isset($roleInfo)) + $roleInfo = new UserRole; + + $roleInfo->setName($roleName) + ->setRank($roleHierarchy) + ->setHidden($roleSecret) + ->setColour($roleColour) + ->setDescription($roleDescription) + ->setTitle($roleTitle) + ->save(); + + if(!empty($permissions) && !empty($_POST['perms']) && is_array($_POST['perms'])) { + $perms = manage_perms_apply($permissions, $_POST['perms']); + + if($perms !== null) { + $permKeys = array_keys($perms); + $setPermissions = DB::prepare(' + REPLACE INTO `msz_permissions` + (`role_id`, `user_id`, `' . implode('`, `', $permKeys) . '`) + VALUES + (:role_id, NULL, :' . implode(', :', $permKeys) . ') + '); + $setPermissions->bind('role_id', $roleInfo->getId()); + + foreach($perms as $key => $value) { + $setPermissions->bind($key, $value); + } + + $setPermissions->execute(); + } else { + $deletePermissions = DB::prepare(' + DELETE FROM `msz_permissions` + WHERE `role_id` = :role_id + AND `user_id` IS NULL + '); + $deletePermissions->bind('role_id', $roleInfo->getId()); + $deletePermissions->execute(); + } + } + + url_redirect('manage-role', ['role' => $roleInfo->getId()]); + return; +} + +Template::render('manage.users.role', [ + 'role_info' => $roleInfo ?? null, + 'can_manage_perms' => $canEditPerms, + 'permissions' => $permissions ?? [], +]); diff --git a/public/manage/users/roles.php b/public/manage/users/roles.php new file mode 100644 index 0000000..f805b08 --- /dev/null +++ b/public/manage/users/roles.php @@ -0,0 +1,24 @@ +getId(), MSZ_PERM_USER_MANAGE_ROLES)) { + echo render_error(403); + return; +} + +$pagination = new Pagination(UserRole::countAll(true), 10); + +if(!$pagination->hasValidOffset()) { + echo render_error(404); + return; +} + +Template::render('manage.users.roles', [ + 'manage_roles' => UserRole::all(true, $pagination), + 'manage_roles_pagination' => $pagination, +]); diff --git a/public/manage/users/user.php b/public/manage/users/user.php new file mode 100644 index 0000000..cb6968d --- /dev/null +++ b/public/manage/users/user.php @@ -0,0 +1,194 @@ +getId(), MSZ_PERM_USER_MANAGE_USERS)) { + echo render_error(403); + return; +} + +$notices = []; +$userId = (int)filter_input(INPUT_GET, 'u', FILTER_SANITIZE_NUMBER_INT); +$currentUser = User::getCurrent(); +$currentUserId = $currentUser->getId(); + +try { + $userInfo = User::byId($userId); +} catch(UserNotFoundException $ex) { + echo render_error(404); + return; +} + +$canEdit = $currentUser->hasAuthorityOver($userInfo); +$canEditPerms = $canEdit && perms_check_user(MSZ_PERMS_USER, $currentUserId, MSZ_PERM_USER_MANAGE_PERMS); +$permissions = manage_perms_list(perms_get_user_raw($userId)); + +if(CSRF::validateRequest() && $canEdit) { + if(!empty($_POST['send_test_email'])) { + if(!$currentUser->isSuper()) { + $notices[] = 'You must be a super user to do this.'; + } elseif(!is_string($_POST['send_test_email']) || $_POST['send_test_email'] !== 'yes_send_it') { + $notices[] = 'Invalid request thing shut the fuck up.'; + } else { + $testMail = Mailer::sendMessage( + [$userInfo->getEMailAddress() => $userInfo->getUsername()], + 'Flashii Test E-mail', + 'You were sent this e-mail to validate if you can receive e-mails from Flashii. You may discard it.' + ); + + if(!$testMail) + $notices[] = 'Failed to send test e-mail.'; + } + } + + if(!empty($_POST['roles']) && is_array($_POST['roles']) && array_test($_POST['roles'], 'ctype_digit')) { + // Fetch existing roles + $existingRoles = $userInfo->getRoles(); + + // Initialise set array with existing roles + $setRoles = $existingRoles; + + // Read user input array and throw intval on em + $applyRoles = array_apply($_POST['roles'], 'intval'); + + // Storage array for roles to dump + $removeRoles = []; + + // STEP 1: Check for roles to be removed in the existing set. + // Roles that the current users isn't allowed to touch (hierarchy) will stay. + foreach($setRoles as $role) { + // Also prevent the main role from being removed. + if($role->isDefault() || !$currentUser->hasAuthorityOver($role)) + continue; + if(!in_array($role->getId(), $applyRoles)) + $removeRoles[] = $role; + } + + // STEP 2: Purge the ones marked for removal. + $setRoles = array_diff($setRoles, $removeRoles); + + // STEP 3: Add roles to the set array from the user input, if the user has authority over the given roles. + foreach($applyRoles as $roleId) { + try { + $role = $existingRoles[$roleId] ?? UserRole::byId($roleId); + } catch(UserRoleNotFoundException $ex) { + continue; + } + if(!$currentUser->hasAuthorityOver($role)) + continue; + if(!in_array($role, $setRoles)) + $setRoles[] = $role; + } + + foreach($removeRoles as $role) + $userInfo->removeRole($role); + + foreach($setRoles as $role) + $userInfo->addRole($role); + } + + if(!empty($_POST['user']) && is_array($_POST['user'])) { + $setUsername = (string)($_POST['user']['username'] ?? ''); + $setEMailAddress = (string)($_POST['user']['email'] ?? ''); + $setCountry = (string)($_POST['user']['country'] ?? ''); + $setTitle = (string)($_POST['user']['title'] ?? ''); + + $displayRole = (int)($_POST['user']['display_role'] ?? 0); + + try { + $userInfo->setDisplayRole(UserRole::byId($displayRole)); + } catch(UserRoleNotFoundException $ex) {} + + $usernameValidation = User::validateUsername($setUsername); + $emailValidation = User::validateEMailAddress($setEMailAddress); + $countryValidation = strlen($setCountry) === 2 + && ctype_alpha($setCountry) + && ctype_upper($setCountry); + + if(!empty($usernameValidation)) + $notices[] = User::usernameValidationErrorString($usernameValidation); + + if(!empty($emailValidation)) { + $notices[] = $emailValidation === 'in-use' + ? 'This e-mail address has already been used!' + : 'This e-mail address is invalid!'; + } + + if(!$countryValidation) + $notices[] = 'Country code was invalid.'; + + if(strlen($setTitle) > 64) + $notices[] = 'User title was invalid.'; + + if(empty($notices)) + $userInfo->setUsername((string)($_POST['user']['username'] ?? '')) + ->setEMailAddress((string)($_POST['user']['email'] ?? '')) + ->setCountry((string)($_POST['user']['country'] ?? '')) + ->setTitle((string)($_POST['user']['title'] ?? '')) + ->setDisplayRole(UserRole::byId((int)($_POST['user']['display_role'] ?? 0))); + } + + if(!empty($_POST['colour']) && is_array($_POST['colour'])) { + $setColour = null; + + if(!empty($_POST['colour']['enable'])) { + $setColour = new Colour; + + try { + $setColour->setHex((string)($_POST['colour']['hex'] ?? '')); + } catch(\Exception $ex) { + $notices[] = $ex->getMessage(); + } + } + + if(empty($notices)) + $userInfo->setColour($setColour); + } + + if(!empty($_POST['password']) && is_array($_POST['password'])) { + $passwordNewValue = (string)($_POST['password']['new'] ?? ''); + $passwordConfirmValue = (string)($_POST['password']['confirm'] ?? ''); + + if(!empty($passwordNewValue)) { + if($passwordNewValue !== $passwordConfirmValue) + $notices[] = 'Confirm password does not match.'; + elseif(!empty(User::validatePassword($passwordNewValue))) + $notices[] = 'New password is too weak.'; + else + $userInfo->setPassword($passwordNewValue); + } + } + + if(empty($notices)) + $userInfo->save(); + + if($canEditPerms && !empty($_POST['perms']) && is_array($_POST['perms'])) { + $perms = manage_perms_apply($permissions, $_POST['perms']); + + if($perms !== null) { + if(!perms_set_user_raw($userId, $perms)) + $notices[] = 'Failed to update permissions.'; + } else { + if(!perms_delete_user($userId)) + $notices[] = 'Failed to remove permissions.'; + } + + // this smells, make it refresh/apply in a non-retarded way + $permissions = manage_perms_list(perms_get_user_raw($userId)); + } +} + +Template::render('manage.users.user', [ + 'user_info' => $userInfo, + 'manage_notices' => $notices, + 'manage_roles' => UserRole::all(true), + 'can_edit_user' => $canEdit, + 'can_edit_perms' => $canEdit && $canEditPerms, + 'permissions' => $permissions ?? [], +]); diff --git a/public/manage/users/warnings.php b/public/manage/users/warnings.php new file mode 100644 index 0000000..818f992 --- /dev/null +++ b/public/manage/users/warnings.php @@ -0,0 +1,160 @@ +getId(), MSZ_PERM_USER_MANAGE_WARNINGS)) { + echo render_error(403); + return; +} + +$notices = []; +$currentUser = User::getCurrent(); +$currentUserId = $currentUser->getId(); + +if(!empty($_POST['lookup']) && is_string($_POST['lookup'])) { + try { + $userId = User::byUsername((string)filter_input(INPUT_POST, 'lookup'))->getId(); + } catch(UserNotFoundException $ex) { + $userId = 0; + } + url_redirect('manage-users-warnings', ['user' => $userId]); + return; +} + +// instead of just kinda taking $_GET['w'] this should really fetch the info from the database +// and make sure that the user has authority +if(!empty($_GET['delete'])) { + try { + UserWarning::byId((int)filter_input(INPUT_GET, 'w', FILTER_SANITIZE_NUMBER_INT))->delete(); + } catch(UserWarningNotFoundException $ex) {} + redirect($_SERVER['HTTP_REFERER'] ?? url('manage-users-warnings')); + return; +} + +if(!empty($_POST['warning']) && is_array($_POST['warning'])) { + $warningType = (int)($_POST['warning']['type'] ?? 0); + $warningDuration = 0; + $warningDuration = (int)($_POST['warning']['duration'] ?? 0); + + if($warningDuration < -1) { + $customDuration = $_POST['warning']['duration_custom'] ?? ''; + + if(!empty($customDuration)) { + switch($warningDuration) { + case -100: // YYYY-MM-DD + $splitDate = array_apply(explode('-', $customDuration, 3), function ($a) { + return (int)$a; + }); + + if(checkdate($splitDate[1], $splitDate[2], $splitDate[0])) + $warningDuration = mktime(0, 0, 0, $splitDate[1], $splitDate[2], $splitDate[0]) - time(); + break; + + case -200: // Raw seconds + $warningDuration = (int)$customDuration; + break; + + case -300: // strtotime + $warningDuration = strtotime($customDuration) - time(); + break; + } + } + } + + try { + $warningsUserInfo = User::byId((int)($_POST['warning']['user'] ?? 0)); + $warningsUser = $warningsUserInfo->getId(); + + if(!$currentUser->hasAuthorityOver($warningsUserInfo)) + $notices[] = 'You do not have authority over this user.'; + } catch(UserNotFoundException $ex) { + $notices[] = 'This user doesn\'t exist.'; + } + + + if(empty($notices) && !empty($warningsUserInfo)) { + try { + $warningInfo = UserWarning::create( + $warningsUserInfo, + $currentUser, + $warningType, + $warningDuration, + $_POST['warning']['note'], + $_POST['warning']['private'] + ); + } catch(InvalidArgumentException $ex) { + $notices[] = $ex->getMessage(); + } catch(UserWarningCreationFailedException $ex) { + $notices[] = 'Warning creation failed.'; + } + } +} + +if(empty($warningsUser)) + $warningsUser = max(0, (int)($_GET['u'] ?? 0)); + +if(empty($warningsUserInfo)) + try { + $warningsUserInfo = User::byId($warningsUser); + } catch(UserNotFoundException $ex) { + $warningsUserInfo = null; + } + +$warningsPagination = new Pagination(UserWarning::countAll($warningsUserInfo), 10); + +if(!$warningsPagination->hasValidOffset()) { + echo render_error(404); + return; +} + +// calling array_flip since the input_select macro wants value => display, but this looks cuter +$warningDurations = array_flip([ + 'Pick a duration...' => 0, + '5 Minutes' => 60 * 5, + '15 Minutes' => 60 * 15, + '30 Minutes' => 60 * 30, + '45 Minutes' => 60 * 45, + '1 Hour' => 60 * 60, + '2 Hours' => 60 * 60 * 2, + '3 Hours' => 60 * 60 * 3, + '6 Hours' => 60 * 60 * 6, + '12 Hours' => 60 * 60 * 12, + '1 Day' => 60 * 60 * 24, + '2 Days' => 60 * 60 * 24 * 2, + '1 Week' => 60 * 60 * 24 * 7, + '2 Weeks' => 60 * 60 * 24 * 7 * 2, + '1 Month' => 60 * 60 * 24 * 365 / 12, + '3 Months' => 60 * 60 * 24 * 365 / 12 * 3, + '6 Months' => 60 * 60 * 24 * 365 / 12 * 6, + '9 Months' => 60 * 60 * 24 * 365 / 12 * 9, + '1 Year' => 60 * 60 * 24 * 365, + 'Permanent' => -1, + 'Until (YYYY-MM-DD) ->' => -100, + 'Until (Seconds) ->' => -200, + 'Until (strtotime) ->' => -300, +]); + +Template::render('manage.users.warnings', [ + 'warnings' => [ + 'notices' => $notices, + 'pagination' => $warningsPagination, + 'list' => UserWarning::all($warningsUserInfo, $warningsPagination), + 'user' => $warningsUserInfo, + 'durations' => $warningDurations, + 'types' => [ + UserWarning::TYPE_NOTE => 'Note', + UserWarning::TYPE_WARN => 'Warning', + UserWarning::TYPE_MUTE => 'Silence', + UserWarning::TYPE_BAHN => 'Ban', + ], + ], +]); diff --git a/public/members.php b/public/members.php new file mode 100644 index 0000000..4856326 --- /dev/null +++ b/public/members.php @@ -0,0 +1,139 @@ + 'Ascending', + 'desc' => 'Descending', +]; + +$defaultOrder = 'last-online'; +$orderFields = [ + 'id' => [ + 'column' => 'u.`user_id`', + 'default-dir' => 'asc', + 'title' => 'User ID', + ], + 'name' => [ + 'column' => 'u.`username`', + 'default-dir' => 'asc', + 'title' => 'Username', + ], + 'country' => [ + 'column' => 'u.`user_country`', + 'default-dir' => 'asc', + 'title' => 'Country', + ], + 'registered' => [ + 'column' => 'u.`user_created`', + 'default-dir' => 'desc', + 'title' => 'Registration Date', + ], + 'last-online' => [ + 'column' => 'u.`user_active`', + 'default-dir' => 'desc', + 'title' => 'Last Online', + ], + 'forum-topics' => [ + 'column' => '`user_count_topics`', + 'default-dir' => 'desc', + 'title' => 'Forum Topics', + ], + 'forum-posts' => [ + 'column' => '`user_count_posts`', + 'default-dir' => 'desc', + 'title' => 'Forum Posts', + ], +]; + +if(empty($orderBy)) { + $orderBy = $defaultOrder; +} elseif(!array_key_exists($orderBy, $orderFields)) { + echo render_error(400); + return; +} + +if(empty($orderDir)) { + $orderDir = $orderFields[$orderBy]['default-dir']; +} elseif(!array_key_exists($orderDir, $orderDirs)) { + echo render_error(400); + return; +} + +$canManageUsers = perms_check_user(MSZ_PERMS_USER, User::hasCurrent() ? User::getCurrent()->getId() : 0, MSZ_PERM_USER_MANAGE_USERS); + +try { + $roleInfo = UserRole::byId($roleId); +} catch(UserRoleNotFoundException $ex) { + echo render_error(404); + return; +} + +$pagination = new Pagination($roleInfo->getUserCount(), 15); + +$roles = UserRole::all(); + +$getUsers = DB::prepare(sprintf( + ' + SELECT + :current_user_id AS `current_user_id`, + u.`user_id`, u.`username`, u.`user_country`, + u.`user_created`, u.`user_active`, r.`role_id`, + COALESCE(u.`user_title`, r.`role_title`) AS `user_title`, + COALESCE(u.`user_colour`, r.`role_colour`) AS `user_colour`, + ( + SELECT COUNT(`topic_id`) + FROM `msz_forum_topics` + WHERE `user_id` = u.`user_id` + AND `topic_deleted` IS NULL + ) AS `user_count_topics`, + ( + SELECT COUNT(`post_Id`) + FROM `msz_forum_posts` + WHERE `user_id` = u.`user_id` + AND `post_deleted` IS NULL + ) AS `user_count_posts` + FROM `msz_users` AS u + LEFT JOIN `msz_roles` AS r + ON r.`role_id` = u.`display_role` + LEFT JOIN `msz_user_roles` AS ur + ON ur.`user_id` = u.`user_id` + WHERE ur.`role_id` = :role_id + %1$s + ORDER BY %2$s %3$s + LIMIT %4$d, %5$d + ', + $canManageUsers ? '' : 'AND u.`user_deleted` IS NULL', + $orderFields[$orderBy]['column'], + $orderDir, + $pagination->getOffset(), + $pagination->getRange() +)); +$getUsers->bind('role_id', $roleInfo->getId()); +$getUsers->bind('current_user_id', User::hasCurrent() ? User::getCurrent()->getId() : 0); +$users = $getUsers->fetchAll(); + +if(empty($users)) + http_response_code(404); + +Template::render('user.listing', [ + 'roles' => $roles, + 'role' => $roleInfo, + 'users' => $users, + 'order_fields' => $orderFields, + 'order_directions' => $orderDirs, + 'order_field' => $orderBy, + 'order_direction' => $orderDir, + 'order_default' => $defaultOrder, + 'can_manage_users' => $canManageUsers, + 'users_pagination' => $pagination, +]); diff --git a/public/news.php b/public/news.php new file mode 100644 index 0000000..41cc616 --- /dev/null +++ b/public/news.php @@ -0,0 +1,2 @@ +isDeleted()) { + http_response_code(404); + Template::render('profile.index'); + return; +} + +$notices = []; + +$currentUser = User::getCurrent(); +$viewingAsGuest = $currentUser === null; +$currentUserId = $viewingAsGuest ? 0 : $currentUser->getId(); +$viewingOwnProfile = $currentUserId === $profileUser->getId(); +$isBanned = $profileUser->hasActiveWarning(); +$userPerms = perms_get_user($currentUserId)[MSZ_PERMS_USER]; +$canManageWarnings = perms_check($userPerms, MSZ_PERM_USER_MANAGE_WARNINGS); +$canEdit = !$isBanned + && UserSession::hasCurrent() + && ($viewingOwnProfile || $currentUser->isSuper() || ( + perms_check($userPerms, MSZ_PERM_USER_MANAGE_USERS) + && $currentUser->hasAuthorityOver($profileUser) + )); + +if($isEditing) { + if(!$canEdit) { + echo render_error(403); + return; + } + + $perms = perms_check_bulk($userPerms, [ + 'edit_profile' => MSZ_PERM_USER_EDIT_PROFILE, + 'edit_avatar' => MSZ_PERM_USER_CHANGE_AVATAR, + 'edit_background' => MSZ_PERM_USER_CHANGE_BACKGROUND, + 'edit_about' => MSZ_PERM_USER_EDIT_ABOUT, + 'edit_birthdate' => MSZ_PERM_USER_EDIT_BIRTHDATE, + 'edit_signature' => MSZ_PERM_USER_EDIT_SIGNATURE, + ]); + + Template::set([ + 'perms' => $perms, + 'background_attachments' => UserBackgroundAsset::getAttachmentStringOptions(), + ]); + + if(!empty($_POST) && is_array($_POST)) { + if(!CSRF::validateRequest()) { + $notices[] = 'Couldn\'t verify you, please refresh the page and retry.'; + } else { + if(!empty($_POST['profile']) && is_array($_POST['profile'])) { + if(!$perms['edit_profile']) { + $notices[] = 'You\'re not allowed to edit your profile'; + } else { + $profileFields = $profileUser->profileFields(false); + + foreach($profileFields as $profileField) { + if(isset($_POST['profile'][$profileField->field_key]) + && $profileField->field_value !== $_POST['profile'][$profileField->field_key] + && !$profileField->setFieldValue($_POST['profile'][$profileField->field_key])) { + $notices[] = sprintf('%s was formatted incorrectly!', $profileField->field_title); + } + } + } + } + + if(!empty($_POST['about']) && is_array($_POST['about'])) { + if(!$perms['edit_about']) { + $notices[] = 'You\'re not allowed to edit your about page.'; + } else { + $aboutText = (string)($_POST['about']['text'] ?? ''); + $aboutParse = (int)($_POST['about']['parser'] ?? Parser::PLAIN); + $aboutValid = User::validateProfileAbout($aboutParse, $aboutText); + + if($aboutValid === '') + $currentUser->setProfileAboutText($aboutText)->setProfileAboutParser($aboutParse); + else switch($aboutValid) { + case 'parser': + $notices[] = 'The selected about section parser is invalid.'; + break; + case 'long': + $notices[] = sprintf('Please keep the length of your about section below %d characters.', User::PROFILE_ABOUT_MAX_LENGTH); + break; + default: + $notices[] = 'Failed to update about section, contact an administator.'; + break; + } + } + } + + if(!empty($_POST['signature']) && is_array($_POST['signature'])) { + if(!$perms['edit_signature']) { + $notices[] = 'You\'re not allowed to edit your forum signature.'; + } else { + $sigText = (string)($_POST['signature']['text'] ?? ''); + $sigParse = (int)($_POST['signature']['parser'] ?? Parser::PLAIN); + $sigValid = User::validateForumSignature($sigParse, $sigText); + + if($sigValid === '') + $currentUser->setForumSignatureText($sigText)->setForumSignatureParser($sigParse); + else switch($sigValid) { + case 'parser': + $notices[] = 'The selected forum signature parser is invalid.'; + break; + case 'long': + $notices[] = sprintf('Please keep the length of your signature below %d characters.', User::FORUM_SIGNATURE_MAX_LENGTH); + break; + default: + $notices[] = 'Failed to update signature, contact an administator.'; + break; + } + } + } + + if(!empty($_POST['birthdate']) && is_array($_POST['birthdate'])) { + if(!$perms['edit_birthdate']) { + $notices[] = "You aren't allow to change your birthdate."; + } else { + $birthYear = (int)($_POST['birthdate']['year'] ?? 0); + $birthMonth = (int)($_POST['birthdate']['month'] ?? 0); + $birthDay = (int)($_POST['birthdate']['day'] ?? 0); + $birthValid = User::validateBirthdate($birthYear, $birthMonth, $birthDay); + + if($birthValid === '') + $currentUser->setBirthdate($birthYear, $birthMonth, $birthDay); + else switch($birthValid) { + case 'year': + $notices[] = 'The given birth year is invalid.'; + break; + case 'date': + $notices[] = 'The given birthdate is invalid.'; + break; + default: + $notices[] = 'Something unexpected happened while setting your birthdate.'; + break; + } + } + } + + if(!empty($_FILES['avatar'])) { + $avatarInfo = $profileUser->getAvatarInfo(); + + if(!empty($_POST['avatar']['delete'])) { + $avatarInfo->delete(); + } else { + if(!$perms['edit_avatar']) { + $notices[] = 'You aren\'t allow to change your avatar.'; + } elseif(!empty($_FILES['avatar']) + && is_array($_FILES['avatar']) + && !empty($_FILES['avatar']['name']['file'])) { + if($_FILES['avatar']['error']['file'] !== UPLOAD_ERR_OK) { + switch($_FILES['avatar']['error']['file']) { + case UPLOAD_ERR_NO_FILE: + $notices[] = 'Select a file before hitting upload!'; + break; + case UPLOAD_ERR_PARTIAL: + $notices[] = 'The upload was interrupted, please try again!'; + break; + case UPLOAD_ERR_INI_SIZE: + case UPLOAD_ERR_FORM_SIZE: + $notices[] = sprintf('Your avatar is not allowed to be larger in file size than %s!', byte_symbol($avatarInfo->getMaxBytes(), true)); + break; + default: + $notices[] = 'Unable to save your avatar, contact an administator!'; + break; + } + } else { + try { + $avatarInfo->setFromPath($_FILES['avatar']['tmp_name']['file']); + } catch(UserImageAssetInvalidImageException $ex) { + $notices[] = 'The file you uploaded was not an image!'; + } catch(UserImageAssetInvalidTypeException $ex) { + $notices[] = 'This type of image is not supported, keep to PNG, JPG or GIF!'; + } catch(UserImageAssetInvalidDimensionsException $ex) { + $notices[] = sprintf('Your avatar can\'t be larger than %dx%d!', $avatarInfo->getMaxWidth(), $avatarInfo->getMaxHeight()); + } catch(UserImageAssetFileTooLargeException $ex) { + $notices[] = sprintf('Your avatar is not allowed to be larger in file size than %s!', byte_symbol($avatarInfo->getMaxBytes(), true)); + } catch(UserImageAssetException $ex) { + $notices[] = 'Unable to save your avatar, contact an administator!'; + } + } + } + } + } + + if(!empty($_FILES['background'])) { + $backgroundInfo = $profileUser->getBackgroundInfo(); + + if((int)($_POST['background']['attach'] ?? -1) === 0) { + $backgroundInfo->delete(); + } else { + if(!$perms['edit_background']) { + $notices[] = 'You aren\'t allow to change your background.'; + } elseif(!empty($_FILES['background']) && is_array($_FILES['background'])) { + if(!empty($_FILES['background']['name']['file'])) { + if($_FILES['background']['error']['file'] !== UPLOAD_ERR_OK) { + switch($_FILES['background']['error']['file']) { + case UPLOAD_ERR_NO_FILE: + $notices[] = 'Select a file before hitting upload!'; + break; + case UPLOAD_ERR_PARTIAL: + $notices[] = 'The upload was interrupted, please try again!'; + break; + case UPLOAD_ERR_INI_SIZE: + case UPLOAD_ERR_FORM_SIZE: + $notices[] = sprintf('Your background is not allowed to be larger in file size than %s!', byte_symbol($backgroundProps['max_size'], true)); + break; + default: + $notices[] = 'Unable to save your background, contact an administator!'; + break; + } + } else { + try { + $backgroundInfo->setFromPath($_FILES['background']['tmp_name']['file']); + } catch(UserImageAssetInvalidImageException $ex) { + $notices[] = 'The file you uploaded was not an image!'; + } catch(UserImageAssetInvalidTypeException $ex) { + $notices[] = 'This type of image is not supported, keep to PNG, JPG or GIF!'; + } catch(UserImageAssetInvalidDimensionsException $ex) { + $notices[] = sprintf('Your background can\'t be larger than %dx%d!', $backgroundInfo->getMaxWidth(), $backgroundInfo->getMaxHeight()); + } catch(UserImageAssetFileTooLargeException $ex) { + $notices[] = sprintf('Your background is not allowed to be larger in file size than %2$s!', byte_symbol($backgroundInfo->getMaxBytes(), true)); + } catch(UserImageAssetException $ex) { + $notices[] = 'Unable to save your background, contact an administator!'; + } + } + } + + $backgroundInfo->setAttachment((int)($_POST['background']['attach'] ?? 0)) + ->setBlend(!empty($_POST['background']['attr']['blend'])) + ->setSlide(!empty($_POST['background']['attr']['slide'])); + } + } + } + + $profileUser->saveProfile(); + } + + // Unset $isEditing and hope the user doesn't refresh their profile! + if(empty($notices)) + $isEditing = false; + } +} + +$profileStats = DB::prepare(' + SELECT ( + SELECT COUNT(`topic_id`) + FROM `msz_forum_topics` + WHERE `user_id` = u.`user_id` + AND `topic_deleted` IS NULL + ) AS `forum_topic_count`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `user_id` = u.`user_id` + AND `post_deleted` IS NULL + ) AS `forum_post_count`, + ( + SELECT COUNT(`change_id`) + FROM `msz_changelog_changes` + WHERE `user_id` = u.`user_id` + ) AS `changelog_count`, + ( + SELECT COUNT(`comment_id`) + FROM `msz_comments_posts` + WHERE `user_id` = u.`user_id` + AND `comment_deleted` IS NULL + ) AS `comments_count` + FROM `msz_users` AS u + WHERE `user_id` = :user_id +')->bind('user_id', $profileUser->getId())->fetch(); + +switch($profileMode) { + default: + echo render_error(404); + return; + + case 'forum-topics': + $template = 'profile.topics'; + $topicsCount = forum_topic_count_user($profileUser->getId(), $currentUserId); + $topicsPagination = new Pagination($topicsCount, 20); + + if(!$topicsPagination->hasValidOffset()) { + echo render_error(404); + return; + } + + $topics = forum_topic_listing_user( + $profileUser->getId(), $currentUserId, + $topicsPagination->getOffset(), $topicsPagination->getRange() + ); + + Template::set([ + 'title' => $profileUser->getUsername() . ' / topics', + 'canonical_url' => url('user-profile-forum-topics', ['user' => $profileUser->getId(), 'page' => Pagination::param()]), + 'profile_topics' => $topics, + 'profile_topics_pagination' => $topicsPagination, + ]); + break; + + case 'forum-posts': + $template = 'profile.posts'; + $postsCount = forum_post_count_user($profileUser->getId()); + $postsPagination = new Pagination($postsCount, 20); + + if(!$postsPagination->hasValidOffset()) { + echo render_error(404); + return; + } + + $posts = forum_post_listing( + $profileUser->getId(), + $postsPagination->getOffset(), + $postsPagination->getRange(), + false, + true + ); + + Template::set([ + 'title' => $profileUser->getUsername() . ' / posts', + 'canonical_url' => url('user-profile-forum-posts', ['user' => $profileUser->getId(), 'page' => Pagination::param()]), + 'profile_posts' => $posts, + 'profile_posts_pagination' => $postsPagination, + ]); + break; + + case '': + $template = 'profile.index'; + $warnings = $profileUser->getProfileWarnings($currentUser); + + Template::set([ + 'profile_warnings' => $warnings, + 'profile_warnings_view_private' => $canManageWarnings, + 'profile_warnings_can_manage' => $canManageWarnings, + ]); + break; +} + +if(!empty($template)) { + Template::render($template, [ + 'profile_viewer' => $currentUser, + 'profile_user' => $profileUser, + 'profile_stats' => $profileStats, + 'profile_mode' => $profileMode, + 'profile_notices' => $notices, + 'profile_can_edit' => $canEdit, + 'profile_is_editing' => $isEditing, + 'profile_is_banned' => $isBanned, + ]); +} diff --git a/public/proxy.php b/public/proxy.php new file mode 100644 index 0000000..84ee915 --- /dev/null +++ b/public/proxy.php @@ -0,0 +1,95 @@ +deserialise($proxyUrl, true); +$parsedUrl = parse_url($proxyUrlDecoded); + +if(empty($parsedUrl['scheme']) + || empty($parsedUrl['host']) + || !in_array($parsedUrl['scheme'], $acceptedProtocols, true)) { + http_response_code(400); + echo '400.2'; + return; +} + +if(!Config::get('media_proxy.enable', Config::TYPE_BOOL)) { + redirect($proxyUrlDecoded); + return; +} + +$proxySecret = Config::get('media_proxy.secret', Config::TYPE_STR, 'insecure'); +$expectedHash = hash_hmac('sha256', $proxyUrl, $proxySecret); + +if(!hash_equals($expectedHash, $proxyHash)) { + http_response_code(400); + echo '400.3'; + return; +} + +$curl = curl_init($proxyUrlDecoded); +curl_setopt_array($curl, [ + CURLOPT_CERTINFO => false, + CURLOPT_FAILONERROR => false, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_TCP_FASTOPEN => true, + CURLOPT_CONNECTTIMEOUT => 2, + CURLOPT_MAXREDIRS => 4, + CURLOPT_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS, + CURLOPT_TIMEOUT => 10, + CURLOPT_USERAGENT => 'Mozilla/5.0 (compatible) Misuzu/' . GitInfo::tag(), +]); +$curlBody = curl_exec($curl); +curl_close($curl); + +$entityTag = 'W/"' . hash('sha256', $curlBody) . '"'; + +if(!empty($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] === $entityTag) { + http_response_code(304); + return; +} + +$finfo = finfo_open(FILEINFO_MIME_TYPE); +$fileMime = strtolower(finfo_buffer($finfo, $curlBody)); +finfo_close($finfo); + +if(!in_array($fileMime, $acceptedMimeTypes, true)) { + http_response_code(404); + echo '404.1'; + return; +} + +$fileSize = strlen($curlBody); +$fileName = basename($parsedUrl['path'] ?? "proxied-image-{$expectedHash}"); + +header("Content-Type: {$fileMime}"); +header("Content-Length: {$fileSize}"); +header("Content-Disposition: inline; filename=\"{$fileName}\""); +header("ETag: {$entityTag}"); + +echo $curlBody; diff --git a/public/search.php b/public/search.php new file mode 100644 index 0000000..88369ef --- /dev/null +++ b/public/search.php @@ -0,0 +1,51 @@ +getId() : 0); + $forumPosts = forum_post_search($searchQuery); + $newsPosts = NewsPost::bySearchQuery($searchQuery); + + $findUsers = DB::prepare(' + SELECT u.`user_id`, u.`username`, u.`user_country`, + u.`user_created`, u.`user_active`, r.`role_id`, + COALESCE(u.`user_title`, r.`role_title`) AS `user_title`, + COALESCE(u.`user_colour`, r.`role_colour`) AS `user_colour`, + ( + SELECT COUNT(`topic_id`) + FROM `msz_forum_topics` + WHERE `user_id` = u.`user_id` + AND `topic_deleted` IS NULL + ) AS `user_count_topics`, + ( + SELECT COUNT(`post_Id`) + FROM `msz_forum_posts` + WHERE `user_id` = u.`user_id` + AND `post_deleted` IS NULL + ) AS `user_count_posts` + FROM `msz_users` AS u + LEFT JOIN `msz_roles` AS r + ON r.`role_id` = u.`display_role` + LEFT JOIN `msz_user_roles` AS ur + ON ur.`user_id` = u.`user_id` + WHERE LOWER(u.`username`) LIKE CONCAT("%%", LOWER(:query), "%%") + GROUP BY u.`user_id` + '); + $findUsers->bind('query', $searchQuery); + $users = $findUsers->fetchAll(); +} + +Template::render('home.search', [ + 'search_query' => $searchQuery, + 'forum_topics' => $forumTopics ?? [], + 'forum_posts' => $forumPosts ?? [], + 'users' => $users ?? [], + 'news_posts' => $newsPosts ?? [], +]); diff --git a/public/settings.php b/public/settings.php new file mode 100644 index 0000000..41cc616 --- /dev/null +++ b/public/settings.php @@ -0,0 +1,2 @@ +getId(); +$isRestricted = $currentUser->hasActiveWarning(); +$isVerifiedRequest = CSRF::validateRequest(); + +if(!$isRestricted && $isVerifiedRequest && !empty($_POST['role'])) { + try { + $roleInfo = UserRole::byId((int)($_POST['role']['id'] ?? 0)); + } catch(UserRoleNotFoundException $ex) {} + + if(empty($roleInfo) || !$currentUser->hasRole($roleInfo)) + $errors[] = "You're trying to modify a role that hasn't been assigned to you."; + else { + switch($_POST['role']['mode'] ?? '') { + case 'display': + $currentUser->setDisplayRole($roleInfo); + break; + + case 'leave': + if($roleInfo->getCanLeave()) + $currentUser->removeRole($roleInfo); + else + $errors[] = "You're not allow to leave this role, an administrator has to remove it for you."; + break; + } + } +} + +if($isVerifiedRequest && isset($_POST['tfa']['enable']) && $currentUser->hasTOTP() !== (bool)$_POST['tfa']['enable']) { + if((bool)$_POST['tfa']['enable']) { + $tfaKey = TOTP::generateKey(); + $tfaIssuer = Config::get('site.name', Config::TYPE_STR, 'Misuzu'); + $tfaQrcode = (new QRCode(new QROptions([ + 'version' => 5, + 'outputType' => QRCode::OUTPUT_IMAGE_JPG, + 'eccLevel' => QRCode::ECC_L, + ])))->render(sprintf('otpauth://totp/%s:%s?%s', $tfaIssuer, $currentUser->getUsername(), http_build_query([ + 'secret' => $tfaKey, + 'issuer' => $tfaIssuer, + ]))); + + Template::set([ + 'settings_2fa_code' => $tfaKey, + 'settings_2fa_image' => $tfaQrcode, + ]); + + $currentUser->setTOTPKey($tfaKey); + } else { + $currentUser->removeTOTPKey(); + } +} + +if($isVerifiedRequest && !empty($_POST['current_password'])) { + if(!$currentUser->checkPassword($_POST['current_password'] ?? '')) { + $errors[] = 'Your password was incorrect.'; + } else { + // Changing e-mail + if(!empty($_POST['email']['new'])) { + if(empty($_POST['email']['confirm']) || $_POST['email']['new'] !== $_POST['email']['confirm']) { + $errors[] = 'The addresses you entered did not match each other.'; + } elseif($currentUser->getEMailAddress() === mb_strtolower($_POST['email']['confirm'])) { + $errors[] = 'This is already your e-mail address!'; + } else { + $checkMail = User::validateEMailAddress($_POST['email']['new'], true); + + if($checkMail !== '') { + switch($checkMail) { + case 'dns': + $errors[] = 'No valid MX record exists for this domain.'; + break; + + case 'format': + $errors[] = 'The given e-mail address was incorrectly formatted.'; + break; + + case 'in-use': + $errors[] = 'This e-mail address is already in use.'; + break; + + default: + $errors[] = 'Unknown e-mail validation error.'; + } + } else { + $currentUser->setEMailAddress($_POST['email']['new']); + AuditLog::create(AuditLog::PERSONAL_EMAIL_CHANGE, [ + $_POST['email']['new'], + ]); + } + } + } + + // Changing password + if(!empty($_POST['password']['new'])) { + if(empty($_POST['password']['confirm']) || $_POST['password']['new'] !== $_POST['password']['confirm']) { + $errors[] = 'The new passwords you entered did not match each other.'; + } else { + $checkPassword = User::validatePassword($_POST['password']['new']); + + if($checkPassword !== '') { + $errors[] = 'The given passwords was too weak.'; + } else { + $currentUser->setPassword($_POST['password']['new']); + AuditLog::create(AuditLog::PERSONAL_PASSWORD_CHANGE); + } + } + } + } +} + +// THIS FUCKING SUCKS AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +if($_SERVER['REQUEST_METHOD'] === 'POST' && $isVerifiedRequest) + $currentUser->save(); + +Template::render('settings.account', [ + 'errors' => $errors, + 'settings_user' => $currentUser, + 'is_restricted' => $isRestricted, +]); diff --git a/public/settings/data.php b/public/settings/data.php new file mode 100644 index 0000000..e4d4859 --- /dev/null +++ b/public/settings/data.php @@ -0,0 +1,92 @@ +bind('user_id', $userId); + } else { + for($i = 1; $i <= $params; $i++) { + $prepare->bind('user_id_' . $i, $userId); + } + } + + $archive->addFromString($filename, json_encode($prepare->fetchAll(), JSON_PRETTY_PRINT)); +} + +$errors = []; +$currentUser = User::getCurrent(); +$currentUserId = $currentUser->getId(); + +if(isset($_POST['action']) && is_string($_POST['action'])) { + if(isset($_POST['password']) && is_string($_POST['password']) + && $currentUser->checkPassword($_POST['password'] ?? '')) { + switch($_POST['action']) { + case 'data': + AuditLog::create(AuditLog::PERSONAL_DATA_DOWNLOAD); + + $timeStamp = floor(time() / 3600) * 3600; + $fileName = sprintf('msz-user-data-%d-%d.zip', $currentUserId, $timeStamp); + $filePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName; + $archive = new ZipArchive; + + if(!is_file($filePath)) { + if($archive->open($filePath, ZipArchive::CREATE | ZIPARCHIVE::OVERWRITE) === true) { + db_to_zip($archive, $currentUserId, 'audit_log.json', 'SELECT *, INET6_NTOA(`log_ip`) AS `log_ip` FROM `msz_audit_log` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'auth_tfa.json', 'SELECT * FROM `msz_auth_tfa` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'changelog_changes.json', 'SELECT * FROM `msz_changelog_changes` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'comments_posts.json', 'SELECT * FROM `msz_comments_posts` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'comments_votes.json', 'SELECT * FROM `msz_comments_votes` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'forum_permissions.json', 'SELECT * FROM `msz_forum_permissions` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'forum_polls_answers.json', 'SELECT * FROM `msz_forum_polls_answers` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'forum_posts.json', 'SELECT *, INET6_NTOA(`post_ip`) AS `post_ip` FROM `msz_forum_posts` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'forum_topics.json', 'SELECT * FROM `msz_forum_topics` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'forum_topics_priority.json', 'SELECT * FROM `msz_forum_topics_priority` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'forum_topics_track.json', 'SELECT * FROM `msz_forum_topics_track` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'login_attempts.json', 'SELECT *, INET6_NTOA(`attempt_ip`) AS `attempt_ip` FROM `msz_login_attempts` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'news_posts.json', 'SELECT * FROM `msz_news_posts` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'permissions.json', 'SELECT * FROM `msz_permissions` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'profile_fields_values.json', 'SELECT * FROM `msz_profile_fields_values` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'sessions.json', 'SELECT *, INET6_NTOA(`session_ip`) AS `session_ip`, INET6_NTOA(`session_ip_last`) AS `session_ip_last` FROM `msz_sessions` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'users.json', 'SELECT *, NULL AS `password`, NULL AS `user_totp_key`, INET6_NTOA(`register_ip`) AS `register_ip`, INET6_NTOA(`last_ip`) AS `last_ip` FROM `msz_users` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'users_password_resets.json', 'SELECT *, INET6_NTOA(`reset_ip`) AS `reset_ip` FROM `msz_users_password_resets` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'user_roles.json', 'SELECT * FROM `msz_user_roles` WHERE `user_id` = :user_id'); + db_to_zip($archive, $currentUserId, 'user_warnings.json', 'SELECT *, INET6_NTOA(`user_ip`) AS `user_ip`, NULL AS `issuer_id`, NULL AS `issuer_ip`, NULL AS `warning_note_private` FROM `msz_user_warnings` WHERE `user_id` = :user_id'); + + $archive->close(); + } else { + $errors[] = 'Something went wrong while creating your account archive.'; + break; + } + } + + header('Content-Type: application/zip'); + header(sprintf('Content-Disposition: inline; filename="%s"', $fileName)); + echo file_get_contents($filePath); + return; + + case 'deactivate': + // deactivation + break; + } + } else { + $errors[] = 'Incorrect password.'; + } +} + +Template::render('settings.data', [ + 'errors' => $errors, +]); diff --git a/public/settings/index.php b/public/settings/index.php new file mode 100644 index 0000000..865505c --- /dev/null +++ b/public/settings/index.php @@ -0,0 +1,13 @@ + UserLoginAttempt::all($loginHistoryPagination, $currentUser), + 'login_history_pagination' => $loginHistoryPagination, + 'account_log_list' => AuditLog::all($accountLogPagination, $currentUser), + 'account_log_pagination' => $accountLogPagination, +]); diff --git a/public/settings/sessions.php b/public/settings/sessions.php new file mode 100644 index 0000000..2e1064a --- /dev/null +++ b/public/settings/sessions.php @@ -0,0 +1,62 @@ +getId(); +$sessionActive = $currentSession->getId();; + +if(!empty($_POST['session']) && CSRF::validateRequest()) { + $currentSessionKilled = false; + + if(is_array($_POST['session'])) { + foreach($_POST['session'] as $sessionId) { + $sessionId = intval($sessionId); + + try { + $sessionInfo = UserSession::byId($sessionId); + } catch(UserSessionNotFoundException $ex) {} + + if(empty($sessionInfo) || $sessionInfo->getUserId() !== $currentUser->getId()) { + $errors[] = "Session #{$sessionId} does not exist."; + continue; + } elseif($sessionInfo->getId() === $sessionActive) { + $currentSessionKilled = true; + } + + $sessionInfo->delete(); + AuditLog::create(AuditLog::PERSONAL_SESSION_DESTROY, [$sessionInfo->getId()]); + } + } elseif($_POST['session'] === 'all') { + $currentSessionKilled = true; + UserSession::purgeUser($currentUser); + AuditLog::create(AuditLog::PERSONAL_SESSION_DESTROY_ALL); + } + + if($currentSessionKilled) { + url_redirect('index'); + return; + } +} + +$pagination = new Pagination(UserSession::countAll($currentUser), 15); + +Template::render('settings.sessions', [ + 'errors' => $errors, + 'session_list' => UserSession::all($pagination, $currentUser), + 'session_current' => $currentSession, + 'session_pagination' => $pagination, +]); diff --git a/public/user-assets.php b/public/user-assets.php new file mode 100644 index 0000000..41cc616 --- /dev/null +++ b/public/user-assets.php @@ -0,0 +1,2 @@ +li{position:relative}.fa-li{left:-2em;position:absolute;text-align:center;width:2em;line-height:inherit}.fa-border{border:.08em solid #eee;border-radius:.1em;padding:.2em .25em .15em}.fa-pull-left{float:left}.fa-pull-right{float:right}.fa.fa-pull-left,.fab.fa-pull-left,.fal.fa-pull-left,.far.fa-pull-left,.fas.fa-pull-left{margin-right:.3em}.fa.fa-pull-right,.fab.fa-pull-right,.fal.fa-pull-right,.far.fa-pull-right,.fas.fa-pull-right{margin-left:.3em}.fa-spin{-webkit-animation:fa-spin 2s linear infinite;animation:fa-spin 2s linear infinite}.fa-pulse{-webkit-animation:fa-spin 1s steps(8) infinite;animation:fa-spin 1s steps(8) infinite}@-webkit-keyframes fa-spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(1turn);transform:rotate(1turn)}}@keyframes fa-spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(1turn);transform:rotate(1turn)}}.fa-rotate-90{-ms-filter:"progid:DXImageTransform.Microsoft.BasicImage(rotation=1)";-webkit-transform:rotate(90deg);transform:rotate(90deg)}.fa-rotate-180{-ms-filter:"progid:DXImageTransform.Microsoft.BasicImage(rotation=2)";-webkit-transform:rotate(180deg);transform:rotate(180deg)}.fa-rotate-270{-ms-filter:"progid:DXImageTransform.Microsoft.BasicImage(rotation=3)";-webkit-transform:rotate(270deg);transform:rotate(270deg)}.fa-flip-horizontal{-ms-filter:"progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1)";-webkit-transform:scaleX(-1);transform:scaleX(-1)}.fa-flip-vertical{-webkit-transform:scaleY(-1);transform:scaleY(-1)}.fa-flip-both,.fa-flip-horizontal.fa-flip-vertical,.fa-flip-vertical{-ms-filter:"progid:DXImageTransform.Microsoft.BasicImage(rotation=2, mirror=1)"}.fa-flip-both,.fa-flip-horizontal.fa-flip-vertical{-webkit-transform:scale(-1);transform:scale(-1)}:root .fa-flip-both,:root .fa-flip-horizontal,:root .fa-flip-vertical,:root .fa-rotate-90,:root .fa-rotate-180,:root .fa-rotate-270{-webkit-filter:none;filter:none}.fa-stack{display:inline-block;height:2em;line-height:2em;position:relative;vertical-align:middle;width:2.5em}.fa-stack-1x,.fa-stack-2x{left:0;position:absolute;text-align:center;width:100%}.fa-stack-1x{line-height:inherit}.fa-stack-2x{font-size:2em}.fa-inverse{color:#fff}.fa-500px:before{content:"\f26e"}.fa-accessible-icon:before{content:"\f368"}.fa-accusoft:before{content:"\f369"}.fa-acquisitions-incorporated:before{content:"\f6af"}.fa-ad:before{content:"\f641"}.fa-address-book:before{content:"\f2b9"}.fa-address-card:before{content:"\f2bb"}.fa-adjust:before{content:"\f042"}.fa-adn:before{content:"\f170"}.fa-adobe:before{content:"\f778"}.fa-adversal:before{content:"\f36a"}.fa-affiliatetheme:before{content:"\f36b"}.fa-air-freshener:before{content:"\f5d0"}.fa-airbnb:before{content:"\f834"}.fa-algolia:before{content:"\f36c"}.fa-align-center:before{content:"\f037"}.fa-align-justify:before{content:"\f039"}.fa-align-left:before{content:"\f036"}.fa-align-right:before{content:"\f038"}.fa-alipay:before{content:"\f642"}.fa-allergies:before{content:"\f461"}.fa-amazon:before{content:"\f270"}.fa-amazon-pay:before{content:"\f42c"}.fa-ambulance:before{content:"\f0f9"}.fa-american-sign-language-interpreting:before{content:"\f2a3"}.fa-amilia:before{content:"\f36d"}.fa-anchor:before{content:"\f13d"}.fa-android:before{content:"\f17b"}.fa-angellist:before{content:"\f209"}.fa-angle-double-down:before{content:"\f103"}.fa-angle-double-left:before{content:"\f100"}.fa-angle-double-right:before{content:"\f101"}.fa-angle-double-up:before{content:"\f102"}.fa-angle-down:before{content:"\f107"}.fa-angle-left:before{content:"\f104"}.fa-angle-right:before{content:"\f105"}.fa-angle-up:before{content:"\f106"}.fa-angry:before{content:"\f556"}.fa-angrycreative:before{content:"\f36e"}.fa-angular:before{content:"\f420"}.fa-ankh:before{content:"\f644"}.fa-app-store:before{content:"\f36f"}.fa-app-store-ios:before{content:"\f370"}.fa-apper:before{content:"\f371"}.fa-apple:before{content:"\f179"}.fa-apple-alt:before{content:"\f5d1"}.fa-apple-pay:before{content:"\f415"}.fa-archive:before{content:"\f187"}.fa-archway:before{content:"\f557"}.fa-arrow-alt-circle-down:before{content:"\f358"}.fa-arrow-alt-circle-left:before{content:"\f359"}.fa-arrow-alt-circle-right:before{content:"\f35a"}.fa-arrow-alt-circle-up:before{content:"\f35b"}.fa-arrow-circle-down:before{content:"\f0ab"}.fa-arrow-circle-left:before{content:"\f0a8"}.fa-arrow-circle-right:before{content:"\f0a9"}.fa-arrow-circle-up:before{content:"\f0aa"}.fa-arrow-down:before{content:"\f063"}.fa-arrow-left:before{content:"\f060"}.fa-arrow-right:before{content:"\f061"}.fa-arrow-up:before{content:"\f062"}.fa-arrows-alt:before{content:"\f0b2"}.fa-arrows-alt-h:before{content:"\f337"}.fa-arrows-alt-v:before{content:"\f338"}.fa-artstation:before{content:"\f77a"}.fa-assistive-listening-systems:before{content:"\f2a2"}.fa-asterisk:before{content:"\f069"}.fa-asymmetrik:before{content:"\f372"}.fa-at:before{content:"\f1fa"}.fa-atlas:before{content:"\f558"}.fa-atlassian:before{content:"\f77b"}.fa-atom:before{content:"\f5d2"}.fa-audible:before{content:"\f373"}.fa-audio-description:before{content:"\f29e"}.fa-autoprefixer:before{content:"\f41c"}.fa-avianex:before{content:"\f374"}.fa-aviato:before{content:"\f421"}.fa-award:before{content:"\f559"}.fa-aws:before{content:"\f375"}.fa-baby:before{content:"\f77c"}.fa-baby-carriage:before{content:"\f77d"}.fa-backspace:before{content:"\f55a"}.fa-backward:before{content:"\f04a"}.fa-bacon:before{content:"\f7e5"}.fa-bahai:before{content:"\f666"}.fa-balance-scale:before{content:"\f24e"}.fa-balance-scale-left:before{content:"\f515"}.fa-balance-scale-right:before{content:"\f516"}.fa-ban:before{content:"\f05e"}.fa-band-aid:before{content:"\f462"}.fa-bandcamp:before{content:"\f2d5"}.fa-barcode:before{content:"\f02a"}.fa-bars:before{content:"\f0c9"}.fa-baseball-ball:before{content:"\f433"}.fa-basketball-ball:before{content:"\f434"}.fa-bath:before{content:"\f2cd"}.fa-battery-empty:before{content:"\f244"}.fa-battery-full:before{content:"\f240"}.fa-battery-half:before{content:"\f242"}.fa-battery-quarter:before{content:"\f243"}.fa-battery-three-quarters:before{content:"\f241"}.fa-battle-net:before{content:"\f835"}.fa-bed:before{content:"\f236"}.fa-beer:before{content:"\f0fc"}.fa-behance:before{content:"\f1b4"}.fa-behance-square:before{content:"\f1b5"}.fa-bell:before{content:"\f0f3"}.fa-bell-slash:before{content:"\f1f6"}.fa-bezier-curve:before{content:"\f55b"}.fa-bible:before{content:"\f647"}.fa-bicycle:before{content:"\f206"}.fa-biking:before{content:"\f84a"}.fa-bimobject:before{content:"\f378"}.fa-binoculars:before{content:"\f1e5"}.fa-biohazard:before{content:"\f780"}.fa-birthday-cake:before{content:"\f1fd"}.fa-bitbucket:before{content:"\f171"}.fa-bitcoin:before{content:"\f379"}.fa-bity:before{content:"\f37a"}.fa-black-tie:before{content:"\f27e"}.fa-blackberry:before{content:"\f37b"}.fa-blender:before{content:"\f517"}.fa-blender-phone:before{content:"\f6b6"}.fa-blind:before{content:"\f29d"}.fa-blog:before{content:"\f781"}.fa-blogger:before{content:"\f37c"}.fa-blogger-b:before{content:"\f37d"}.fa-bluetooth:before{content:"\f293"}.fa-bluetooth-b:before{content:"\f294"}.fa-bold:before{content:"\f032"}.fa-bolt:before{content:"\f0e7"}.fa-bomb:before{content:"\f1e2"}.fa-bone:before{content:"\f5d7"}.fa-bong:before{content:"\f55c"}.fa-book:before{content:"\f02d"}.fa-book-dead:before{content:"\f6b7"}.fa-book-medical:before{content:"\f7e6"}.fa-book-open:before{content:"\f518"}.fa-book-reader:before{content:"\f5da"}.fa-bookmark:before{content:"\f02e"}.fa-bootstrap:before{content:"\f836"}.fa-border-all:before{content:"\f84c"}.fa-border-none:before{content:"\f850"}.fa-border-style:before{content:"\f853"}.fa-bowling-ball:before{content:"\f436"}.fa-box:before{content:"\f466"}.fa-box-open:before{content:"\f49e"}.fa-box-tissue:before{content:"\f95b"}.fa-boxes:before{content:"\f468"}.fa-braille:before{content:"\f2a1"}.fa-brain:before{content:"\f5dc"}.fa-bread-slice:before{content:"\f7ec"}.fa-briefcase:before{content:"\f0b1"}.fa-briefcase-medical:before{content:"\f469"}.fa-broadcast-tower:before{content:"\f519"}.fa-broom:before{content:"\f51a"}.fa-brush:before{content:"\f55d"}.fa-btc:before{content:"\f15a"}.fa-buffer:before{content:"\f837"}.fa-bug:before{content:"\f188"}.fa-building:before{content:"\f1ad"}.fa-bullhorn:before{content:"\f0a1"}.fa-bullseye:before{content:"\f140"}.fa-burn:before{content:"\f46a"}.fa-buromobelexperte:before{content:"\f37f"}.fa-bus:before{content:"\f207"}.fa-bus-alt:before{content:"\f55e"}.fa-business-time:before{content:"\f64a"}.fa-buy-n-large:before{content:"\f8a6"}.fa-buysellads:before{content:"\f20d"}.fa-calculator:before{content:"\f1ec"}.fa-calendar:before{content:"\f133"}.fa-calendar-alt:before{content:"\f073"}.fa-calendar-check:before{content:"\f274"}.fa-calendar-day:before{content:"\f783"}.fa-calendar-minus:before{content:"\f272"}.fa-calendar-plus:before{content:"\f271"}.fa-calendar-times:before{content:"\f273"}.fa-calendar-week:before{content:"\f784"}.fa-camera:before{content:"\f030"}.fa-camera-retro:before{content:"\f083"}.fa-campground:before{content:"\f6bb"}.fa-canadian-maple-leaf:before{content:"\f785"}.fa-candy-cane:before{content:"\f786"}.fa-cannabis:before{content:"\f55f"}.fa-capsules:before{content:"\f46b"}.fa-car:before{content:"\f1b9"}.fa-car-alt:before{content:"\f5de"}.fa-car-battery:before{content:"\f5df"}.fa-car-crash:before{content:"\f5e1"}.fa-car-side:before{content:"\f5e4"}.fa-caravan:before{content:"\f8ff"}.fa-caret-down:before{content:"\f0d7"}.fa-caret-left:before{content:"\f0d9"}.fa-caret-right:before{content:"\f0da"}.fa-caret-square-down:before{content:"\f150"}.fa-caret-square-left:before{content:"\f191"}.fa-caret-square-right:before{content:"\f152"}.fa-caret-square-up:before{content:"\f151"}.fa-caret-up:before{content:"\f0d8"}.fa-carrot:before{content:"\f787"}.fa-cart-arrow-down:before{content:"\f218"}.fa-cart-plus:before{content:"\f217"}.fa-cash-register:before{content:"\f788"}.fa-cat:before{content:"\f6be"}.fa-cc-amazon-pay:before{content:"\f42d"}.fa-cc-amex:before{content:"\f1f3"}.fa-cc-apple-pay:before{content:"\f416"}.fa-cc-diners-club:before{content:"\f24c"}.fa-cc-discover:before{content:"\f1f2"}.fa-cc-jcb:before{content:"\f24b"}.fa-cc-mastercard:before{content:"\f1f1"}.fa-cc-paypal:before{content:"\f1f4"}.fa-cc-stripe:before{content:"\f1f5"}.fa-cc-visa:before{content:"\f1f0"}.fa-centercode:before{content:"\f380"}.fa-centos:before{content:"\f789"}.fa-certificate:before{content:"\f0a3"}.fa-chair:before{content:"\f6c0"}.fa-chalkboard:before{content:"\f51b"}.fa-chalkboard-teacher:before{content:"\f51c"}.fa-charging-station:before{content:"\f5e7"}.fa-chart-area:before{content:"\f1fe"}.fa-chart-bar:before{content:"\f080"}.fa-chart-line:before{content:"\f201"}.fa-chart-pie:before{content:"\f200"}.fa-check:before{content:"\f00c"}.fa-check-circle:before{content:"\f058"}.fa-check-double:before{content:"\f560"}.fa-check-square:before{content:"\f14a"}.fa-cheese:before{content:"\f7ef"}.fa-chess:before{content:"\f439"}.fa-chess-bishop:before{content:"\f43a"}.fa-chess-board:before{content:"\f43c"}.fa-chess-king:before{content:"\f43f"}.fa-chess-knight:before{content:"\f441"}.fa-chess-pawn:before{content:"\f443"}.fa-chess-queen:before{content:"\f445"}.fa-chess-rook:before{content:"\f447"}.fa-chevron-circle-down:before{content:"\f13a"}.fa-chevron-circle-left:before{content:"\f137"}.fa-chevron-circle-right:before{content:"\f138"}.fa-chevron-circle-up:before{content:"\f139"}.fa-chevron-down:before{content:"\f078"}.fa-chevron-left:before{content:"\f053"}.fa-chevron-right:before{content:"\f054"}.fa-chevron-up:before{content:"\f077"}.fa-child:before{content:"\f1ae"}.fa-chrome:before{content:"\f268"}.fa-chromecast:before{content:"\f838"}.fa-church:before{content:"\f51d"}.fa-circle:before{content:"\f111"}.fa-circle-notch:before{content:"\f1ce"}.fa-city:before{content:"\f64f"}.fa-clinic-medical:before{content:"\f7f2"}.fa-clipboard:before{content:"\f328"}.fa-clipboard-check:before{content:"\f46c"}.fa-clipboard-list:before{content:"\f46d"}.fa-clock:before{content:"\f017"}.fa-clone:before{content:"\f24d"}.fa-closed-captioning:before{content:"\f20a"}.fa-cloud:before{content:"\f0c2"}.fa-cloud-download-alt:before{content:"\f381"}.fa-cloud-meatball:before{content:"\f73b"}.fa-cloud-moon:before{content:"\f6c3"}.fa-cloud-moon-rain:before{content:"\f73c"}.fa-cloud-rain:before{content:"\f73d"}.fa-cloud-showers-heavy:before{content:"\f740"}.fa-cloud-sun:before{content:"\f6c4"}.fa-cloud-sun-rain:before{content:"\f743"}.fa-cloud-upload-alt:before{content:"\f382"}.fa-cloudscale:before{content:"\f383"}.fa-cloudsmith:before{content:"\f384"}.fa-cloudversify:before{content:"\f385"}.fa-cocktail:before{content:"\f561"}.fa-code:before{content:"\f121"}.fa-code-branch:before{content:"\f126"}.fa-codepen:before{content:"\f1cb"}.fa-codiepie:before{content:"\f284"}.fa-coffee:before{content:"\f0f4"}.fa-cog:before{content:"\f013"}.fa-cogs:before{content:"\f085"}.fa-coins:before{content:"\f51e"}.fa-columns:before{content:"\f0db"}.fa-comment:before{content:"\f075"}.fa-comment-alt:before{content:"\f27a"}.fa-comment-dollar:before{content:"\f651"}.fa-comment-dots:before{content:"\f4ad"}.fa-comment-medical:before{content:"\f7f5"}.fa-comment-slash:before{content:"\f4b3"}.fa-comments:before{content:"\f086"}.fa-comments-dollar:before{content:"\f653"}.fa-compact-disc:before{content:"\f51f"}.fa-compass:before{content:"\f14e"}.fa-compress:before{content:"\f066"}.fa-compress-alt:before{content:"\f422"}.fa-compress-arrows-alt:before{content:"\f78c"}.fa-concierge-bell:before{content:"\f562"}.fa-confluence:before{content:"\f78d"}.fa-connectdevelop:before{content:"\f20e"}.fa-contao:before{content:"\f26d"}.fa-cookie:before{content:"\f563"}.fa-cookie-bite:before{content:"\f564"}.fa-copy:before{content:"\f0c5"}.fa-copyright:before{content:"\f1f9"}.fa-cotton-bureau:before{content:"\f89e"}.fa-couch:before{content:"\f4b8"}.fa-cpanel:before{content:"\f388"}.fa-creative-commons:before{content:"\f25e"}.fa-creative-commons-by:before{content:"\f4e7"}.fa-creative-commons-nc:before{content:"\f4e8"}.fa-creative-commons-nc-eu:before{content:"\f4e9"}.fa-creative-commons-nc-jp:before{content:"\f4ea"}.fa-creative-commons-nd:before{content:"\f4eb"}.fa-creative-commons-pd:before{content:"\f4ec"}.fa-creative-commons-pd-alt:before{content:"\f4ed"}.fa-creative-commons-remix:before{content:"\f4ee"}.fa-creative-commons-sa:before{content:"\f4ef"}.fa-creative-commons-sampling:before{content:"\f4f0"}.fa-creative-commons-sampling-plus:before{content:"\f4f1"}.fa-creative-commons-share:before{content:"\f4f2"}.fa-creative-commons-zero:before{content:"\f4f3"}.fa-credit-card:before{content:"\f09d"}.fa-critical-role:before{content:"\f6c9"}.fa-crop:before{content:"\f125"}.fa-crop-alt:before{content:"\f565"}.fa-cross:before{content:"\f654"}.fa-crosshairs:before{content:"\f05b"}.fa-crow:before{content:"\f520"}.fa-crown:before{content:"\f521"}.fa-crutch:before{content:"\f7f7"}.fa-css3:before{content:"\f13c"}.fa-css3-alt:before{content:"\f38b"}.fa-cube:before{content:"\f1b2"}.fa-cubes:before{content:"\f1b3"}.fa-cut:before{content:"\f0c4"}.fa-cuttlefish:before{content:"\f38c"}.fa-d-and-d:before{content:"\f38d"}.fa-d-and-d-beyond:before{content:"\f6ca"}.fa-dailymotion:before{content:"\f952"}.fa-dashcube:before{content:"\f210"}.fa-database:before{content:"\f1c0"}.fa-deaf:before{content:"\f2a4"}.fa-delicious:before{content:"\f1a5"}.fa-democrat:before{content:"\f747"}.fa-deploydog:before{content:"\f38e"}.fa-deskpro:before{content:"\f38f"}.fa-desktop:before{content:"\f108"}.fa-dev:before{content:"\f6cc"}.fa-deviantart:before{content:"\f1bd"}.fa-dharmachakra:before{content:"\f655"}.fa-dhl:before{content:"\f790"}.fa-diagnoses:before{content:"\f470"}.fa-diaspora:before{content:"\f791"}.fa-dice:before{content:"\f522"}.fa-dice-d20:before{content:"\f6cf"}.fa-dice-d6:before{content:"\f6d1"}.fa-dice-five:before{content:"\f523"}.fa-dice-four:before{content:"\f524"}.fa-dice-one:before{content:"\f525"}.fa-dice-six:before{content:"\f526"}.fa-dice-three:before{content:"\f527"}.fa-dice-two:before{content:"\f528"}.fa-digg:before{content:"\f1a6"}.fa-digital-ocean:before{content:"\f391"}.fa-digital-tachograph:before{content:"\f566"}.fa-directions:before{content:"\f5eb"}.fa-discord:before{content:"\f392"}.fa-discourse:before{content:"\f393"}.fa-disease:before{content:"\f7fa"}.fa-divide:before{content:"\f529"}.fa-dizzy:before{content:"\f567"}.fa-dna:before{content:"\f471"}.fa-dochub:before{content:"\f394"}.fa-docker:before{content:"\f395"}.fa-dog:before{content:"\f6d3"}.fa-dollar-sign:before{content:"\f155"}.fa-dolly:before{content:"\f472"}.fa-dolly-flatbed:before{content:"\f474"}.fa-donate:before{content:"\f4b9"}.fa-door-closed:before{content:"\f52a"}.fa-door-open:before{content:"\f52b"}.fa-dot-circle:before{content:"\f192"}.fa-dove:before{content:"\f4ba"}.fa-download:before{content:"\f019"}.fa-draft2digital:before{content:"\f396"}.fa-drafting-compass:before{content:"\f568"}.fa-dragon:before{content:"\f6d5"}.fa-draw-polygon:before{content:"\f5ee"}.fa-dribbble:before{content:"\f17d"}.fa-dribbble-square:before{content:"\f397"}.fa-dropbox:before{content:"\f16b"}.fa-drum:before{content:"\f569"}.fa-drum-steelpan:before{content:"\f56a"}.fa-drumstick-bite:before{content:"\f6d7"}.fa-drupal:before{content:"\f1a9"}.fa-dumbbell:before{content:"\f44b"}.fa-dumpster:before{content:"\f793"}.fa-dumpster-fire:before{content:"\f794"}.fa-dungeon:before{content:"\f6d9"}.fa-dyalog:before{content:"\f399"}.fa-earlybirds:before{content:"\f39a"}.fa-ebay:before{content:"\f4f4"}.fa-edge:before{content:"\f282"}.fa-edit:before{content:"\f044"}.fa-egg:before{content:"\f7fb"}.fa-eject:before{content:"\f052"}.fa-elementor:before{content:"\f430"}.fa-ellipsis-h:before{content:"\f141"}.fa-ellipsis-v:before{content:"\f142"}.fa-ello:before{content:"\f5f1"}.fa-ember:before{content:"\f423"}.fa-empire:before{content:"\f1d1"}.fa-envelope:before{content:"\f0e0"}.fa-envelope-open:before{content:"\f2b6"}.fa-envelope-open-text:before{content:"\f658"}.fa-envelope-square:before{content:"\f199"}.fa-envira:before{content:"\f299"}.fa-equals:before{content:"\f52c"}.fa-eraser:before{content:"\f12d"}.fa-erlang:before{content:"\f39d"}.fa-ethereum:before{content:"\f42e"}.fa-ethernet:before{content:"\f796"}.fa-etsy:before{content:"\f2d7"}.fa-euro-sign:before{content:"\f153"}.fa-evernote:before{content:"\f839"}.fa-exchange-alt:before{content:"\f362"}.fa-exclamation:before{content:"\f12a"}.fa-exclamation-circle:before{content:"\f06a"}.fa-exclamation-triangle:before{content:"\f071"}.fa-expand:before{content:"\f065"}.fa-expand-alt:before{content:"\f424"}.fa-expand-arrows-alt:before{content:"\f31e"}.fa-expeditedssl:before{content:"\f23e"}.fa-external-link-alt:before{content:"\f35d"}.fa-external-link-square-alt:before{content:"\f360"}.fa-eye:before{content:"\f06e"}.fa-eye-dropper:before{content:"\f1fb"}.fa-eye-slash:before{content:"\f070"}.fa-facebook:before{content:"\f09a"}.fa-facebook-f:before{content:"\f39e"}.fa-facebook-messenger:before{content:"\f39f"}.fa-facebook-square:before{content:"\f082"}.fa-fan:before{content:"\f863"}.fa-fantasy-flight-games:before{content:"\f6dc"}.fa-fast-backward:before{content:"\f049"}.fa-fast-forward:before{content:"\f050"}.fa-faucet:before{content:"\f905"}.fa-fax:before{content:"\f1ac"}.fa-feather:before{content:"\f52d"}.fa-feather-alt:before{content:"\f56b"}.fa-fedex:before{content:"\f797"}.fa-fedora:before{content:"\f798"}.fa-female:before{content:"\f182"}.fa-fighter-jet:before{content:"\f0fb"}.fa-figma:before{content:"\f799"}.fa-file:before{content:"\f15b"}.fa-file-alt:before{content:"\f15c"}.fa-file-archive:before{content:"\f1c6"}.fa-file-audio:before{content:"\f1c7"}.fa-file-code:before{content:"\f1c9"}.fa-file-contract:before{content:"\f56c"}.fa-file-csv:before{content:"\f6dd"}.fa-file-download:before{content:"\f56d"}.fa-file-excel:before{content:"\f1c3"}.fa-file-export:before{content:"\f56e"}.fa-file-image:before{content:"\f1c5"}.fa-file-import:before{content:"\f56f"}.fa-file-invoice:before{content:"\f570"}.fa-file-invoice-dollar:before{content:"\f571"}.fa-file-medical:before{content:"\f477"}.fa-file-medical-alt:before{content:"\f478"}.fa-file-pdf:before{content:"\f1c1"}.fa-file-powerpoint:before{content:"\f1c4"}.fa-file-prescription:before{content:"\f572"}.fa-file-signature:before{content:"\f573"}.fa-file-upload:before{content:"\f574"}.fa-file-video:before{content:"\f1c8"}.fa-file-word:before{content:"\f1c2"}.fa-fill:before{content:"\f575"}.fa-fill-drip:before{content:"\f576"}.fa-film:before{content:"\f008"}.fa-filter:before{content:"\f0b0"}.fa-fingerprint:before{content:"\f577"}.fa-fire:before{content:"\f06d"}.fa-fire-alt:before{content:"\f7e4"}.fa-fire-extinguisher:before{content:"\f134"}.fa-firefox:before{content:"\f269"}.fa-firefox-browser:before{content:"\f907"}.fa-first-aid:before{content:"\f479"}.fa-first-order:before{content:"\f2b0"}.fa-first-order-alt:before{content:"\f50a"}.fa-firstdraft:before{content:"\f3a1"}.fa-fish:before{content:"\f578"}.fa-fist-raised:before{content:"\f6de"}.fa-flag:before{content:"\f024"}.fa-flag-checkered:before{content:"\f11e"}.fa-flag-usa:before{content:"\f74d"}.fa-flask:before{content:"\f0c3"}.fa-flickr:before{content:"\f16e"}.fa-flipboard:before{content:"\f44d"}.fa-flushed:before{content:"\f579"}.fa-fly:before{content:"\f417"}.fa-folder:before{content:"\f07b"}.fa-folder-minus:before{content:"\f65d"}.fa-folder-open:before{content:"\f07c"}.fa-folder-plus:before{content:"\f65e"}.fa-font:before{content:"\f031"}.fa-font-awesome:before{content:"\f2b4"}.fa-font-awesome-alt:before{content:"\f35c"}.fa-font-awesome-flag:before{content:"\f425"}.fa-font-awesome-logo-full:before{content:"\f4e6"}.fa-fonticons:before{content:"\f280"}.fa-fonticons-fi:before{content:"\f3a2"}.fa-football-ball:before{content:"\f44e"}.fa-fort-awesome:before{content:"\f286"}.fa-fort-awesome-alt:before{content:"\f3a3"}.fa-forumbee:before{content:"\f211"}.fa-forward:before{content:"\f04e"}.fa-foursquare:before{content:"\f180"}.fa-free-code-camp:before{content:"\f2c5"}.fa-freebsd:before{content:"\f3a4"}.fa-frog:before{content:"\f52e"}.fa-frown:before{content:"\f119"}.fa-frown-open:before{content:"\f57a"}.fa-fulcrum:before{content:"\f50b"}.fa-funnel-dollar:before{content:"\f662"}.fa-futbol:before{content:"\f1e3"}.fa-galactic-republic:before{content:"\f50c"}.fa-galactic-senate:before{content:"\f50d"}.fa-gamepad:before{content:"\f11b"}.fa-gas-pump:before{content:"\f52f"}.fa-gavel:before{content:"\f0e3"}.fa-gem:before{content:"\f3a5"}.fa-genderless:before{content:"\f22d"}.fa-get-pocket:before{content:"\f265"}.fa-gg:before{content:"\f260"}.fa-gg-circle:before{content:"\f261"}.fa-ghost:before{content:"\f6e2"}.fa-gift:before{content:"\f06b"}.fa-gifts:before{content:"\f79c"}.fa-git:before{content:"\f1d3"}.fa-git-alt:before{content:"\f841"}.fa-git-square:before{content:"\f1d2"}.fa-github:before{content:"\f09b"}.fa-github-alt:before{content:"\f113"}.fa-github-square:before{content:"\f092"}.fa-gitkraken:before{content:"\f3a6"}.fa-gitlab:before{content:"\f296"}.fa-gitter:before{content:"\f426"}.fa-glass-cheers:before{content:"\f79f"}.fa-glass-martini:before{content:"\f000"}.fa-glass-martini-alt:before{content:"\f57b"}.fa-glass-whiskey:before{content:"\f7a0"}.fa-glasses:before{content:"\f530"}.fa-glide:before{content:"\f2a5"}.fa-glide-g:before{content:"\f2a6"}.fa-globe:before{content:"\f0ac"}.fa-globe-africa:before{content:"\f57c"}.fa-globe-americas:before{content:"\f57d"}.fa-globe-asia:before{content:"\f57e"}.fa-globe-europe:before{content:"\f7a2"}.fa-gofore:before{content:"\f3a7"}.fa-golf-ball:before{content:"\f450"}.fa-goodreads:before{content:"\f3a8"}.fa-goodreads-g:before{content:"\f3a9"}.fa-google:before{content:"\f1a0"}.fa-google-drive:before{content:"\f3aa"}.fa-google-play:before{content:"\f3ab"}.fa-google-plus:before{content:"\f2b3"}.fa-google-plus-g:before{content:"\f0d5"}.fa-google-plus-square:before{content:"\f0d4"}.fa-google-wallet:before{content:"\f1ee"}.fa-gopuram:before{content:"\f664"}.fa-graduation-cap:before{content:"\f19d"}.fa-gratipay:before{content:"\f184"}.fa-grav:before{content:"\f2d6"}.fa-greater-than:before{content:"\f531"}.fa-greater-than-equal:before{content:"\f532"}.fa-grimace:before{content:"\f57f"}.fa-grin:before{content:"\f580"}.fa-grin-alt:before{content:"\f581"}.fa-grin-beam:before{content:"\f582"}.fa-grin-beam-sweat:before{content:"\f583"}.fa-grin-hearts:before{content:"\f584"}.fa-grin-squint:before{content:"\f585"}.fa-grin-squint-tears:before{content:"\f586"}.fa-grin-stars:before{content:"\f587"}.fa-grin-tears:before{content:"\f588"}.fa-grin-tongue:before{content:"\f589"}.fa-grin-tongue-squint:before{content:"\f58a"}.fa-grin-tongue-wink:before{content:"\f58b"}.fa-grin-wink:before{content:"\f58c"}.fa-grip-horizontal:before{content:"\f58d"}.fa-grip-lines:before{content:"\f7a4"}.fa-grip-lines-vertical:before{content:"\f7a5"}.fa-grip-vertical:before{content:"\f58e"}.fa-gripfire:before{content:"\f3ac"}.fa-grunt:before{content:"\f3ad"}.fa-guitar:before{content:"\f7a6"}.fa-gulp:before{content:"\f3ae"}.fa-h-square:before{content:"\f0fd"}.fa-hacker-news:before{content:"\f1d4"}.fa-hacker-news-square:before{content:"\f3af"}.fa-hackerrank:before{content:"\f5f7"}.fa-hamburger:before{content:"\f805"}.fa-hammer:before{content:"\f6e3"}.fa-hamsa:before{content:"\f665"}.fa-hand-holding:before{content:"\f4bd"}.fa-hand-holding-heart:before{content:"\f4be"}.fa-hand-holding-medical:before{content:"\f95c"}.fa-hand-holding-usd:before{content:"\f4c0"}.fa-hand-holding-water:before{content:"\f4c1"}.fa-hand-lizard:before{content:"\f258"}.fa-hand-middle-finger:before{content:"\f806"}.fa-hand-paper:before{content:"\f256"}.fa-hand-peace:before{content:"\f25b"}.fa-hand-point-down:before{content:"\f0a7"}.fa-hand-point-left:before{content:"\f0a5"}.fa-hand-point-right:before{content:"\f0a4"}.fa-hand-point-up:before{content:"\f0a6"}.fa-hand-pointer:before{content:"\f25a"}.fa-hand-rock:before{content:"\f255"}.fa-hand-scissors:before{content:"\f257"}.fa-hand-sparkles:before{content:"\f95d"}.fa-hand-spock:before{content:"\f259"}.fa-hands:before{content:"\f4c2"}.fa-hands-helping:before{content:"\f4c4"}.fa-hands-wash:before{content:"\f95e"}.fa-handshake:before{content:"\f2b5"}.fa-handshake-alt-slash:before{content:"\f95f"}.fa-handshake-slash:before{content:"\f960"}.fa-hanukiah:before{content:"\f6e6"}.fa-hard-hat:before{content:"\f807"}.fa-hashtag:before{content:"\f292"}.fa-hat-cowboy:before{content:"\f8c0"}.fa-hat-cowboy-side:before{content:"\f8c1"}.fa-hat-wizard:before{content:"\f6e8"}.fa-hdd:before{content:"\f0a0"}.fa-head-side-cough:before{content:"\f961"}.fa-head-side-cough-slash:before{content:"\f962"}.fa-head-side-mask:before{content:"\f963"}.fa-head-side-virus:before{content:"\f964"}.fa-heading:before{content:"\f1dc"}.fa-headphones:before{content:"\f025"}.fa-headphones-alt:before{content:"\f58f"}.fa-headset:before{content:"\f590"}.fa-heart:before{content:"\f004"}.fa-heart-broken:before{content:"\f7a9"}.fa-heartbeat:before{content:"\f21e"}.fa-helicopter:before{content:"\f533"}.fa-highlighter:before{content:"\f591"}.fa-hiking:before{content:"\f6ec"}.fa-hippo:before{content:"\f6ed"}.fa-hips:before{content:"\f452"}.fa-hire-a-helper:before{content:"\f3b0"}.fa-history:before{content:"\f1da"}.fa-hockey-puck:before{content:"\f453"}.fa-holly-berry:before{content:"\f7aa"}.fa-home:before{content:"\f015"}.fa-hooli:before{content:"\f427"}.fa-hornbill:before{content:"\f592"}.fa-horse:before{content:"\f6f0"}.fa-horse-head:before{content:"\f7ab"}.fa-hospital:before{content:"\f0f8"}.fa-hospital-alt:before{content:"\f47d"}.fa-hospital-symbol:before{content:"\f47e"}.fa-hospital-user:before{content:"\f80d"}.fa-hot-tub:before{content:"\f593"}.fa-hotdog:before{content:"\f80f"}.fa-hotel:before{content:"\f594"}.fa-hotjar:before{content:"\f3b1"}.fa-hourglass:before{content:"\f254"}.fa-hourglass-end:before{content:"\f253"}.fa-hourglass-half:before{content:"\f252"}.fa-hourglass-start:before{content:"\f251"}.fa-house-damage:before{content:"\f6f1"}.fa-house-user:before{content:"\f965"}.fa-houzz:before{content:"\f27c"}.fa-hryvnia:before{content:"\f6f2"}.fa-html5:before{content:"\f13b"}.fa-hubspot:before{content:"\f3b2"}.fa-i-cursor:before{content:"\f246"}.fa-ice-cream:before{content:"\f810"}.fa-icicles:before{content:"\f7ad"}.fa-icons:before{content:"\f86d"}.fa-id-badge:before{content:"\f2c1"}.fa-id-card:before{content:"\f2c2"}.fa-id-card-alt:before{content:"\f47f"}.fa-ideal:before{content:"\f913"}.fa-igloo:before{content:"\f7ae"}.fa-image:before{content:"\f03e"}.fa-images:before{content:"\f302"}.fa-imdb:before{content:"\f2d8"}.fa-inbox:before{content:"\f01c"}.fa-indent:before{content:"\f03c"}.fa-industry:before{content:"\f275"}.fa-infinity:before{content:"\f534"}.fa-info:before{content:"\f129"}.fa-info-circle:before{content:"\f05a"}.fa-instagram:before{content:"\f16d"}.fa-instagram-square:before{content:"\f955"}.fa-intercom:before{content:"\f7af"}.fa-internet-explorer:before{content:"\f26b"}.fa-invision:before{content:"\f7b0"}.fa-ioxhost:before{content:"\f208"}.fa-italic:before{content:"\f033"}.fa-itch-io:before{content:"\f83a"}.fa-itunes:before{content:"\f3b4"}.fa-itunes-note:before{content:"\f3b5"}.fa-java:before{content:"\f4e4"}.fa-jedi:before{content:"\f669"}.fa-jedi-order:before{content:"\f50e"}.fa-jenkins:before{content:"\f3b6"}.fa-jira:before{content:"\f7b1"}.fa-joget:before{content:"\f3b7"}.fa-joint:before{content:"\f595"}.fa-joomla:before{content:"\f1aa"}.fa-journal-whills:before{content:"\f66a"}.fa-js:before{content:"\f3b8"}.fa-js-square:before{content:"\f3b9"}.fa-jsfiddle:before{content:"\f1cc"}.fa-kaaba:before{content:"\f66b"}.fa-kaggle:before{content:"\f5fa"}.fa-key:before{content:"\f084"}.fa-keybase:before{content:"\f4f5"}.fa-keyboard:before{content:"\f11c"}.fa-keycdn:before{content:"\f3ba"}.fa-khanda:before{content:"\f66d"}.fa-kickstarter:before{content:"\f3bb"}.fa-kickstarter-k:before{content:"\f3bc"}.fa-kiss:before{content:"\f596"}.fa-kiss-beam:before{content:"\f597"}.fa-kiss-wink-heart:before{content:"\f598"}.fa-kiwi-bird:before{content:"\f535"}.fa-korvue:before{content:"\f42f"}.fa-landmark:before{content:"\f66f"}.fa-language:before{content:"\f1ab"}.fa-laptop:before{content:"\f109"}.fa-laptop-code:before{content:"\f5fc"}.fa-laptop-house:before{content:"\f966"}.fa-laptop-medical:before{content:"\f812"}.fa-laravel:before{content:"\f3bd"}.fa-lastfm:before{content:"\f202"}.fa-lastfm-square:before{content:"\f203"}.fa-laugh:before{content:"\f599"}.fa-laugh-beam:before{content:"\f59a"}.fa-laugh-squint:before{content:"\f59b"}.fa-laugh-wink:before{content:"\f59c"}.fa-layer-group:before{content:"\f5fd"}.fa-leaf:before{content:"\f06c"}.fa-leanpub:before{content:"\f212"}.fa-lemon:before{content:"\f094"}.fa-less:before{content:"\f41d"}.fa-less-than:before{content:"\f536"}.fa-less-than-equal:before{content:"\f537"}.fa-level-down-alt:before{content:"\f3be"}.fa-level-up-alt:before{content:"\f3bf"}.fa-life-ring:before{content:"\f1cd"}.fa-lightbulb:before{content:"\f0eb"}.fa-line:before{content:"\f3c0"}.fa-link:before{content:"\f0c1"}.fa-linkedin:before{content:"\f08c"}.fa-linkedin-in:before{content:"\f0e1"}.fa-linode:before{content:"\f2b8"}.fa-linux:before{content:"\f17c"}.fa-lira-sign:before{content:"\f195"}.fa-list:before{content:"\f03a"}.fa-list-alt:before{content:"\f022"}.fa-list-ol:before{content:"\f0cb"}.fa-list-ul:before{content:"\f0ca"}.fa-location-arrow:before{content:"\f124"}.fa-lock:before{content:"\f023"}.fa-lock-open:before{content:"\f3c1"}.fa-long-arrow-alt-down:before{content:"\f309"}.fa-long-arrow-alt-left:before{content:"\f30a"}.fa-long-arrow-alt-right:before{content:"\f30b"}.fa-long-arrow-alt-up:before{content:"\f30c"}.fa-low-vision:before{content:"\f2a8"}.fa-luggage-cart:before{content:"\f59d"}.fa-lungs:before{content:"\f604"}.fa-lungs-virus:before{content:"\f967"}.fa-lyft:before{content:"\f3c3"}.fa-magento:before{content:"\f3c4"}.fa-magic:before{content:"\f0d0"}.fa-magnet:before{content:"\f076"}.fa-mail-bulk:before{content:"\f674"}.fa-mailchimp:before{content:"\f59e"}.fa-male:before{content:"\f183"}.fa-mandalorian:before{content:"\f50f"}.fa-map:before{content:"\f279"}.fa-map-marked:before{content:"\f59f"}.fa-map-marked-alt:before{content:"\f5a0"}.fa-map-marker:before{content:"\f041"}.fa-map-marker-alt:before{content:"\f3c5"}.fa-map-pin:before{content:"\f276"}.fa-map-signs:before{content:"\f277"}.fa-markdown:before{content:"\f60f"}.fa-marker:before{content:"\f5a1"}.fa-mars:before{content:"\f222"}.fa-mars-double:before{content:"\f227"}.fa-mars-stroke:before{content:"\f229"}.fa-mars-stroke-h:before{content:"\f22b"}.fa-mars-stroke-v:before{content:"\f22a"}.fa-mask:before{content:"\f6fa"}.fa-mastodon:before{content:"\f4f6"}.fa-maxcdn:before{content:"\f136"}.fa-mdb:before{content:"\f8ca"}.fa-medal:before{content:"\f5a2"}.fa-medapps:before{content:"\f3c6"}.fa-medium:before{content:"\f23a"}.fa-medium-m:before{content:"\f3c7"}.fa-medkit:before{content:"\f0fa"}.fa-medrt:before{content:"\f3c8"}.fa-meetup:before{content:"\f2e0"}.fa-megaport:before{content:"\f5a3"}.fa-meh:before{content:"\f11a"}.fa-meh-blank:before{content:"\f5a4"}.fa-meh-rolling-eyes:before{content:"\f5a5"}.fa-memory:before{content:"\f538"}.fa-mendeley:before{content:"\f7b3"}.fa-menorah:before{content:"\f676"}.fa-mercury:before{content:"\f223"}.fa-meteor:before{content:"\f753"}.fa-microblog:before{content:"\f91a"}.fa-microchip:before{content:"\f2db"}.fa-microphone:before{content:"\f130"}.fa-microphone-alt:before{content:"\f3c9"}.fa-microphone-alt-slash:before{content:"\f539"}.fa-microphone-slash:before{content:"\f131"}.fa-microscope:before{content:"\f610"}.fa-microsoft:before{content:"\f3ca"}.fa-minus:before{content:"\f068"}.fa-minus-circle:before{content:"\f056"}.fa-minus-square:before{content:"\f146"}.fa-mitten:before{content:"\f7b5"}.fa-mix:before{content:"\f3cb"}.fa-mixcloud:before{content:"\f289"}.fa-mixer:before{content:"\f956"}.fa-mizuni:before{content:"\f3cc"}.fa-mobile:before{content:"\f10b"}.fa-mobile-alt:before{content:"\f3cd"}.fa-modx:before{content:"\f285"}.fa-monero:before{content:"\f3d0"}.fa-money-bill:before{content:"\f0d6"}.fa-money-bill-alt:before{content:"\f3d1"}.fa-money-bill-wave:before{content:"\f53a"}.fa-money-bill-wave-alt:before{content:"\f53b"}.fa-money-check:before{content:"\f53c"}.fa-money-check-alt:before{content:"\f53d"}.fa-monument:before{content:"\f5a6"}.fa-moon:before{content:"\f186"}.fa-mortar-pestle:before{content:"\f5a7"}.fa-mosque:before{content:"\f678"}.fa-motorcycle:before{content:"\f21c"}.fa-mountain:before{content:"\f6fc"}.fa-mouse:before{content:"\f8cc"}.fa-mouse-pointer:before{content:"\f245"}.fa-mug-hot:before{content:"\f7b6"}.fa-music:before{content:"\f001"}.fa-napster:before{content:"\f3d2"}.fa-neos:before{content:"\f612"}.fa-network-wired:before{content:"\f6ff"}.fa-neuter:before{content:"\f22c"}.fa-newspaper:before{content:"\f1ea"}.fa-nimblr:before{content:"\f5a8"}.fa-node:before{content:"\f419"}.fa-node-js:before{content:"\f3d3"}.fa-not-equal:before{content:"\f53e"}.fa-notes-medical:before{content:"\f481"}.fa-npm:before{content:"\f3d4"}.fa-ns8:before{content:"\f3d5"}.fa-nutritionix:before{content:"\f3d6"}.fa-object-group:before{content:"\f247"}.fa-object-ungroup:before{content:"\f248"}.fa-odnoklassniki:before{content:"\f263"}.fa-odnoklassniki-square:before{content:"\f264"}.fa-oil-can:before{content:"\f613"}.fa-old-republic:before{content:"\f510"}.fa-om:before{content:"\f679"}.fa-opencart:before{content:"\f23d"}.fa-openid:before{content:"\f19b"}.fa-opera:before{content:"\f26a"}.fa-optin-monster:before{content:"\f23c"}.fa-orcid:before{content:"\f8d2"}.fa-osi:before{content:"\f41a"}.fa-otter:before{content:"\f700"}.fa-outdent:before{content:"\f03b"}.fa-page4:before{content:"\f3d7"}.fa-pagelines:before{content:"\f18c"}.fa-pager:before{content:"\f815"}.fa-paint-brush:before{content:"\f1fc"}.fa-paint-roller:before{content:"\f5aa"}.fa-palette:before{content:"\f53f"}.fa-palfed:before{content:"\f3d8"}.fa-pallet:before{content:"\f482"}.fa-paper-plane:before{content:"\f1d8"}.fa-paperclip:before{content:"\f0c6"}.fa-parachute-box:before{content:"\f4cd"}.fa-paragraph:before{content:"\f1dd"}.fa-parking:before{content:"\f540"}.fa-passport:before{content:"\f5ab"}.fa-pastafarianism:before{content:"\f67b"}.fa-paste:before{content:"\f0ea"}.fa-patreon:before{content:"\f3d9"}.fa-pause:before{content:"\f04c"}.fa-pause-circle:before{content:"\f28b"}.fa-paw:before{content:"\f1b0"}.fa-paypal:before{content:"\f1ed"}.fa-peace:before{content:"\f67c"}.fa-pen:before{content:"\f304"}.fa-pen-alt:before{content:"\f305"}.fa-pen-fancy:before{content:"\f5ac"}.fa-pen-nib:before{content:"\f5ad"}.fa-pen-square:before{content:"\f14b"}.fa-pencil-alt:before{content:"\f303"}.fa-pencil-ruler:before{content:"\f5ae"}.fa-penny-arcade:before{content:"\f704"}.fa-people-arrows:before{content:"\f968"}.fa-people-carry:before{content:"\f4ce"}.fa-pepper-hot:before{content:"\f816"}.fa-percent:before{content:"\f295"}.fa-percentage:before{content:"\f541"}.fa-periscope:before{content:"\f3da"}.fa-person-booth:before{content:"\f756"}.fa-phabricator:before{content:"\f3db"}.fa-phoenix-framework:before{content:"\f3dc"}.fa-phoenix-squadron:before{content:"\f511"}.fa-phone:before{content:"\f095"}.fa-phone-alt:before{content:"\f879"}.fa-phone-slash:before{content:"\f3dd"}.fa-phone-square:before{content:"\f098"}.fa-phone-square-alt:before{content:"\f87b"}.fa-phone-volume:before{content:"\f2a0"}.fa-photo-video:before{content:"\f87c"}.fa-php:before{content:"\f457"}.fa-pied-piper:before{content:"\f2ae"}.fa-pied-piper-alt:before{content:"\f1a8"}.fa-pied-piper-hat:before{content:"\f4e5"}.fa-pied-piper-pp:before{content:"\f1a7"}.fa-pied-piper-square:before{content:"\f91e"}.fa-piggy-bank:before{content:"\f4d3"}.fa-pills:before{content:"\f484"}.fa-pinterest:before{content:"\f0d2"}.fa-pinterest-p:before{content:"\f231"}.fa-pinterest-square:before{content:"\f0d3"}.fa-pizza-slice:before{content:"\f818"}.fa-place-of-worship:before{content:"\f67f"}.fa-plane:before{content:"\f072"}.fa-plane-arrival:before{content:"\f5af"}.fa-plane-departure:before{content:"\f5b0"}.fa-plane-slash:before{content:"\f969"}.fa-play:before{content:"\f04b"}.fa-play-circle:before{content:"\f144"}.fa-playstation:before{content:"\f3df"}.fa-plug:before{content:"\f1e6"}.fa-plus:before{content:"\f067"}.fa-plus-circle:before{content:"\f055"}.fa-plus-square:before{content:"\f0fe"}.fa-podcast:before{content:"\f2ce"}.fa-poll:before{content:"\f681"}.fa-poll-h:before{content:"\f682"}.fa-poo:before{content:"\f2fe"}.fa-poo-storm:before{content:"\f75a"}.fa-poop:before{content:"\f619"}.fa-portrait:before{content:"\f3e0"}.fa-pound-sign:before{content:"\f154"}.fa-power-off:before{content:"\f011"}.fa-pray:before{content:"\f683"}.fa-praying-hands:before{content:"\f684"}.fa-prescription:before{content:"\f5b1"}.fa-prescription-bottle:before{content:"\f485"}.fa-prescription-bottle-alt:before{content:"\f486"}.fa-print:before{content:"\f02f"}.fa-procedures:before{content:"\f487"}.fa-product-hunt:before{content:"\f288"}.fa-project-diagram:before{content:"\f542"}.fa-pump-medical:before{content:"\f96a"}.fa-pump-soap:before{content:"\f96b"}.fa-pushed:before{content:"\f3e1"}.fa-puzzle-piece:before{content:"\f12e"}.fa-python:before{content:"\f3e2"}.fa-qq:before{content:"\f1d6"}.fa-qrcode:before{content:"\f029"}.fa-question:before{content:"\f128"}.fa-question-circle:before{content:"\f059"}.fa-quidditch:before{content:"\f458"}.fa-quinscape:before{content:"\f459"}.fa-quora:before{content:"\f2c4"}.fa-quote-left:before{content:"\f10d"}.fa-quote-right:before{content:"\f10e"}.fa-quran:before{content:"\f687"}.fa-r-project:before{content:"\f4f7"}.fa-radiation:before{content:"\f7b9"}.fa-radiation-alt:before{content:"\f7ba"}.fa-rainbow:before{content:"\f75b"}.fa-random:before{content:"\f074"}.fa-raspberry-pi:before{content:"\f7bb"}.fa-ravelry:before{content:"\f2d9"}.fa-react:before{content:"\f41b"}.fa-reacteurope:before{content:"\f75d"}.fa-readme:before{content:"\f4d5"}.fa-rebel:before{content:"\f1d0"}.fa-receipt:before{content:"\f543"}.fa-record-vinyl:before{content:"\f8d9"}.fa-recycle:before{content:"\f1b8"}.fa-red-river:before{content:"\f3e3"}.fa-reddit:before{content:"\f1a1"}.fa-reddit-alien:before{content:"\f281"}.fa-reddit-square:before{content:"\f1a2"}.fa-redhat:before{content:"\f7bc"}.fa-redo:before{content:"\f01e"}.fa-redo-alt:before{content:"\f2f9"}.fa-registered:before{content:"\f25d"}.fa-remove-format:before{content:"\f87d"}.fa-renren:before{content:"\f18b"}.fa-reply:before{content:"\f3e5"}.fa-reply-all:before{content:"\f122"}.fa-replyd:before{content:"\f3e6"}.fa-republican:before{content:"\f75e"}.fa-researchgate:before{content:"\f4f8"}.fa-resolving:before{content:"\f3e7"}.fa-restroom:before{content:"\f7bd"}.fa-retweet:before{content:"\f079"}.fa-rev:before{content:"\f5b2"}.fa-ribbon:before{content:"\f4d6"}.fa-ring:before{content:"\f70b"}.fa-road:before{content:"\f018"}.fa-robot:before{content:"\f544"}.fa-rocket:before{content:"\f135"}.fa-rocketchat:before{content:"\f3e8"}.fa-rockrms:before{content:"\f3e9"}.fa-route:before{content:"\f4d7"}.fa-rss:before{content:"\f09e"}.fa-rss-square:before{content:"\f143"}.fa-ruble-sign:before{content:"\f158"}.fa-ruler:before{content:"\f545"}.fa-ruler-combined:before{content:"\f546"}.fa-ruler-horizontal:before{content:"\f547"}.fa-ruler-vertical:before{content:"\f548"}.fa-running:before{content:"\f70c"}.fa-rupee-sign:before{content:"\f156"}.fa-sad-cry:before{content:"\f5b3"}.fa-sad-tear:before{content:"\f5b4"}.fa-safari:before{content:"\f267"}.fa-salesforce:before{content:"\f83b"}.fa-sass:before{content:"\f41e"}.fa-satellite:before{content:"\f7bf"}.fa-satellite-dish:before{content:"\f7c0"}.fa-save:before{content:"\f0c7"}.fa-schlix:before{content:"\f3ea"}.fa-school:before{content:"\f549"}.fa-screwdriver:before{content:"\f54a"}.fa-scribd:before{content:"\f28a"}.fa-scroll:before{content:"\f70e"}.fa-sd-card:before{content:"\f7c2"}.fa-search:before{content:"\f002"}.fa-search-dollar:before{content:"\f688"}.fa-search-location:before{content:"\f689"}.fa-search-minus:before{content:"\f010"}.fa-search-plus:before{content:"\f00e"}.fa-searchengin:before{content:"\f3eb"}.fa-seedling:before{content:"\f4d8"}.fa-sellcast:before{content:"\f2da"}.fa-sellsy:before{content:"\f213"}.fa-server:before{content:"\f233"}.fa-servicestack:before{content:"\f3ec"}.fa-shapes:before{content:"\f61f"}.fa-share:before{content:"\f064"}.fa-share-alt:before{content:"\f1e0"}.fa-share-alt-square:before{content:"\f1e1"}.fa-share-square:before{content:"\f14d"}.fa-shekel-sign:before{content:"\f20b"}.fa-shield-alt:before{content:"\f3ed"}.fa-shield-virus:before{content:"\f96c"}.fa-ship:before{content:"\f21a"}.fa-shipping-fast:before{content:"\f48b"}.fa-shirtsinbulk:before{content:"\f214"}.fa-shoe-prints:before{content:"\f54b"}.fa-shopify:before{content:"\f957"}.fa-shopping-bag:before{content:"\f290"}.fa-shopping-basket:before{content:"\f291"}.fa-shopping-cart:before{content:"\f07a"}.fa-shopware:before{content:"\f5b5"}.fa-shower:before{content:"\f2cc"}.fa-shuttle-van:before{content:"\f5b6"}.fa-sign:before{content:"\f4d9"}.fa-sign-in-alt:before{content:"\f2f6"}.fa-sign-language:before{content:"\f2a7"}.fa-sign-out-alt:before{content:"\f2f5"}.fa-signal:before{content:"\f012"}.fa-signature:before{content:"\f5b7"}.fa-sim-card:before{content:"\f7c4"}.fa-simplybuilt:before{content:"\f215"}.fa-sistrix:before{content:"\f3ee"}.fa-sitemap:before{content:"\f0e8"}.fa-sith:before{content:"\f512"}.fa-skating:before{content:"\f7c5"}.fa-sketch:before{content:"\f7c6"}.fa-skiing:before{content:"\f7c9"}.fa-skiing-nordic:before{content:"\f7ca"}.fa-skull:before{content:"\f54c"}.fa-skull-crossbones:before{content:"\f714"}.fa-skyatlas:before{content:"\f216"}.fa-skype:before{content:"\f17e"}.fa-slack:before{content:"\f198"}.fa-slack-hash:before{content:"\f3ef"}.fa-slash:before{content:"\f715"}.fa-sleigh:before{content:"\f7cc"}.fa-sliders-h:before{content:"\f1de"}.fa-slideshare:before{content:"\f1e7"}.fa-smile:before{content:"\f118"}.fa-smile-beam:before{content:"\f5b8"}.fa-smile-wink:before{content:"\f4da"}.fa-smog:before{content:"\f75f"}.fa-smoking:before{content:"\f48d"}.fa-smoking-ban:before{content:"\f54d"}.fa-sms:before{content:"\f7cd"}.fa-snapchat:before{content:"\f2ab"}.fa-snapchat-ghost:before{content:"\f2ac"}.fa-snapchat-square:before{content:"\f2ad"}.fa-snowboarding:before{content:"\f7ce"}.fa-snowflake:before{content:"\f2dc"}.fa-snowman:before{content:"\f7d0"}.fa-snowplow:before{content:"\f7d2"}.fa-soap:before{content:"\f96e"}.fa-socks:before{content:"\f696"}.fa-solar-panel:before{content:"\f5ba"}.fa-sort:before{content:"\f0dc"}.fa-sort-alpha-down:before{content:"\f15d"}.fa-sort-alpha-down-alt:before{content:"\f881"}.fa-sort-alpha-up:before{content:"\f15e"}.fa-sort-alpha-up-alt:before{content:"\f882"}.fa-sort-amount-down:before{content:"\f160"}.fa-sort-amount-down-alt:before{content:"\f884"}.fa-sort-amount-up:before{content:"\f161"}.fa-sort-amount-up-alt:before{content:"\f885"}.fa-sort-down:before{content:"\f0dd"}.fa-sort-numeric-down:before{content:"\f162"}.fa-sort-numeric-down-alt:before{content:"\f886"}.fa-sort-numeric-up:before{content:"\f163"}.fa-sort-numeric-up-alt:before{content:"\f887"}.fa-sort-up:before{content:"\f0de"}.fa-soundcloud:before{content:"\f1be"}.fa-sourcetree:before{content:"\f7d3"}.fa-spa:before{content:"\f5bb"}.fa-space-shuttle:before{content:"\f197"}.fa-speakap:before{content:"\f3f3"}.fa-speaker-deck:before{content:"\f83c"}.fa-spell-check:before{content:"\f891"}.fa-spider:before{content:"\f717"}.fa-spinner:before{content:"\f110"}.fa-splotch:before{content:"\f5bc"}.fa-spotify:before{content:"\f1bc"}.fa-spray-can:before{content:"\f5bd"}.fa-square:before{content:"\f0c8"}.fa-square-full:before{content:"\f45c"}.fa-square-root-alt:before{content:"\f698"}.fa-squarespace:before{content:"\f5be"}.fa-stack-exchange:before{content:"\f18d"}.fa-stack-overflow:before{content:"\f16c"}.fa-stackpath:before{content:"\f842"}.fa-stamp:before{content:"\f5bf"}.fa-star:before{content:"\f005"}.fa-star-and-crescent:before{content:"\f699"}.fa-star-half:before{content:"\f089"}.fa-star-half-alt:before{content:"\f5c0"}.fa-star-of-david:before{content:"\f69a"}.fa-star-of-life:before{content:"\f621"}.fa-staylinked:before{content:"\f3f5"}.fa-steam:before{content:"\f1b6"}.fa-steam-square:before{content:"\f1b7"}.fa-steam-symbol:before{content:"\f3f6"}.fa-step-backward:before{content:"\f048"}.fa-step-forward:before{content:"\f051"}.fa-stethoscope:before{content:"\f0f1"}.fa-sticker-mule:before{content:"\f3f7"}.fa-sticky-note:before{content:"\f249"}.fa-stop:before{content:"\f04d"}.fa-stop-circle:before{content:"\f28d"}.fa-stopwatch:before{content:"\f2f2"}.fa-stopwatch-20:before{content:"\f96f"}.fa-store:before{content:"\f54e"}.fa-store-alt:before{content:"\f54f"}.fa-store-alt-slash:before{content:"\f970"}.fa-store-slash:before{content:"\f971"}.fa-strava:before{content:"\f428"}.fa-stream:before{content:"\f550"}.fa-street-view:before{content:"\f21d"}.fa-strikethrough:before{content:"\f0cc"}.fa-stripe:before{content:"\f429"}.fa-stripe-s:before{content:"\f42a"}.fa-stroopwafel:before{content:"\f551"}.fa-studiovinari:before{content:"\f3f8"}.fa-stumbleupon:before{content:"\f1a4"}.fa-stumbleupon-circle:before{content:"\f1a3"}.fa-subscript:before{content:"\f12c"}.fa-subway:before{content:"\f239"}.fa-suitcase:before{content:"\f0f2"}.fa-suitcase-rolling:before{content:"\f5c1"}.fa-sun:before{content:"\f185"}.fa-superpowers:before{content:"\f2dd"}.fa-superscript:before{content:"\f12b"}.fa-supple:before{content:"\f3f9"}.fa-surprise:before{content:"\f5c2"}.fa-suse:before{content:"\f7d6"}.fa-swatchbook:before{content:"\f5c3"}.fa-swift:before{content:"\f8e1"}.fa-swimmer:before{content:"\f5c4"}.fa-swimming-pool:before{content:"\f5c5"}.fa-symfony:before{content:"\f83d"}.fa-synagogue:before{content:"\f69b"}.fa-sync:before{content:"\f021"}.fa-sync-alt:before{content:"\f2f1"}.fa-syringe:before{content:"\f48e"}.fa-table:before{content:"\f0ce"}.fa-table-tennis:before{content:"\f45d"}.fa-tablet:before{content:"\f10a"}.fa-tablet-alt:before{content:"\f3fa"}.fa-tablets:before{content:"\f490"}.fa-tachometer-alt:before{content:"\f3fd"}.fa-tag:before{content:"\f02b"}.fa-tags:before{content:"\f02c"}.fa-tape:before{content:"\f4db"}.fa-tasks:before{content:"\f0ae"}.fa-taxi:before{content:"\f1ba"}.fa-teamspeak:before{content:"\f4f9"}.fa-teeth:before{content:"\f62e"}.fa-teeth-open:before{content:"\f62f"}.fa-telegram:before{content:"\f2c6"}.fa-telegram-plane:before{content:"\f3fe"}.fa-temperature-high:before{content:"\f769"}.fa-temperature-low:before{content:"\f76b"}.fa-tencent-weibo:before{content:"\f1d5"}.fa-tenge:before{content:"\f7d7"}.fa-terminal:before{content:"\f120"}.fa-text-height:before{content:"\f034"}.fa-text-width:before{content:"\f035"}.fa-th:before{content:"\f00a"}.fa-th-large:before{content:"\f009"}.fa-th-list:before{content:"\f00b"}.fa-the-red-yeti:before{content:"\f69d"}.fa-theater-masks:before{content:"\f630"}.fa-themeco:before{content:"\f5c6"}.fa-themeisle:before{content:"\f2b2"}.fa-thermometer:before{content:"\f491"}.fa-thermometer-empty:before{content:"\f2cb"}.fa-thermometer-full:before{content:"\f2c7"}.fa-thermometer-half:before{content:"\f2c9"}.fa-thermometer-quarter:before{content:"\f2ca"}.fa-thermometer-three-quarters:before{content:"\f2c8"}.fa-think-peaks:before{content:"\f731"}.fa-thumbs-down:before{content:"\f165"}.fa-thumbs-up:before{content:"\f164"}.fa-thumbtack:before{content:"\f08d"}.fa-ticket-alt:before{content:"\f3ff"}.fa-times:before{content:"\f00d"}.fa-times-circle:before{content:"\f057"}.fa-tint:before{content:"\f043"}.fa-tint-slash:before{content:"\f5c7"}.fa-tired:before{content:"\f5c8"}.fa-toggle-off:before{content:"\f204"}.fa-toggle-on:before{content:"\f205"}.fa-toilet:before{content:"\f7d8"}.fa-toilet-paper:before{content:"\f71e"}.fa-toilet-paper-slash:before{content:"\f972"}.fa-toolbox:before{content:"\f552"}.fa-tools:before{content:"\f7d9"}.fa-tooth:before{content:"\f5c9"}.fa-torah:before{content:"\f6a0"}.fa-torii-gate:before{content:"\f6a1"}.fa-tractor:before{content:"\f722"}.fa-trade-federation:before{content:"\f513"}.fa-trademark:before{content:"\f25c"}.fa-traffic-light:before{content:"\f637"}.fa-trailer:before{content:"\f941"}.fa-train:before{content:"\f238"}.fa-tram:before{content:"\f7da"}.fa-transgender:before{content:"\f224"}.fa-transgender-alt:before{content:"\f225"}.fa-trash:before{content:"\f1f8"}.fa-trash-alt:before{content:"\f2ed"}.fa-trash-restore:before{content:"\f829"}.fa-trash-restore-alt:before{content:"\f82a"}.fa-tree:before{content:"\f1bb"}.fa-trello:before{content:"\f181"}.fa-tripadvisor:before{content:"\f262"}.fa-trophy:before{content:"\f091"}.fa-truck:before{content:"\f0d1"}.fa-truck-loading:before{content:"\f4de"}.fa-truck-monster:before{content:"\f63b"}.fa-truck-moving:before{content:"\f4df"}.fa-truck-pickup:before{content:"\f63c"}.fa-tshirt:before{content:"\f553"}.fa-tty:before{content:"\f1e4"}.fa-tumblr:before{content:"\f173"}.fa-tumblr-square:before{content:"\f174"}.fa-tv:before{content:"\f26c"}.fa-twitch:before{content:"\f1e8"}.fa-twitter:before{content:"\f099"}.fa-twitter-square:before{content:"\f081"}.fa-typo3:before{content:"\f42b"}.fa-uber:before{content:"\f402"}.fa-ubuntu:before{content:"\f7df"}.fa-uikit:before{content:"\f403"}.fa-umbraco:before{content:"\f8e8"}.fa-umbrella:before{content:"\f0e9"}.fa-umbrella-beach:before{content:"\f5ca"}.fa-underline:before{content:"\f0cd"}.fa-undo:before{content:"\f0e2"}.fa-undo-alt:before{content:"\f2ea"}.fa-uniregistry:before{content:"\f404"}.fa-unity:before{content:"\f949"}.fa-universal-access:before{content:"\f29a"}.fa-university:before{content:"\f19c"}.fa-unlink:before{content:"\f127"}.fa-unlock:before{content:"\f09c"}.fa-unlock-alt:before{content:"\f13e"}.fa-untappd:before{content:"\f405"}.fa-upload:before{content:"\f093"}.fa-ups:before{content:"\f7e0"}.fa-usb:before{content:"\f287"}.fa-user:before{content:"\f007"}.fa-user-alt:before{content:"\f406"}.fa-user-alt-slash:before{content:"\f4fa"}.fa-user-astronaut:before{content:"\f4fb"}.fa-user-check:before{content:"\f4fc"}.fa-user-circle:before{content:"\f2bd"}.fa-user-clock:before{content:"\f4fd"}.fa-user-cog:before{content:"\f4fe"}.fa-user-edit:before{content:"\f4ff"}.fa-user-friends:before{content:"\f500"}.fa-user-graduate:before{content:"\f501"}.fa-user-injured:before{content:"\f728"}.fa-user-lock:before{content:"\f502"}.fa-user-md:before{content:"\f0f0"}.fa-user-minus:before{content:"\f503"}.fa-user-ninja:before{content:"\f504"}.fa-user-nurse:before{content:"\f82f"}.fa-user-plus:before{content:"\f234"}.fa-user-secret:before{content:"\f21b"}.fa-user-shield:before{content:"\f505"}.fa-user-slash:before{content:"\f506"}.fa-user-tag:before{content:"\f507"}.fa-user-tie:before{content:"\f508"}.fa-user-times:before{content:"\f235"}.fa-users:before{content:"\f0c0"}.fa-users-cog:before{content:"\f509"}.fa-usps:before{content:"\f7e1"}.fa-ussunnah:before{content:"\f407"}.fa-utensil-spoon:before{content:"\f2e5"}.fa-utensils:before{content:"\f2e7"}.fa-vaadin:before{content:"\f408"}.fa-vector-square:before{content:"\f5cb"}.fa-venus:before{content:"\f221"}.fa-venus-double:before{content:"\f226"}.fa-venus-mars:before{content:"\f228"}.fa-viacoin:before{content:"\f237"}.fa-viadeo:before{content:"\f2a9"}.fa-viadeo-square:before{content:"\f2aa"}.fa-vial:before{content:"\f492"}.fa-vials:before{content:"\f493"}.fa-viber:before{content:"\f409"}.fa-video:before{content:"\f03d"}.fa-video-slash:before{content:"\f4e2"}.fa-vihara:before{content:"\f6a7"}.fa-vimeo:before{content:"\f40a"}.fa-vimeo-square:before{content:"\f194"}.fa-vimeo-v:before{content:"\f27d"}.fa-vine:before{content:"\f1ca"}.fa-virus:before{content:"\f974"}.fa-virus-slash:before{content:"\f975"}.fa-viruses:before{content:"\f976"}.fa-vk:before{content:"\f189"}.fa-vnv:before{content:"\f40b"}.fa-voicemail:before{content:"\f897"}.fa-volleyball-ball:before{content:"\f45f"}.fa-volume-down:before{content:"\f027"}.fa-volume-mute:before{content:"\f6a9"}.fa-volume-off:before{content:"\f026"}.fa-volume-up:before{content:"\f028"}.fa-vote-yea:before{content:"\f772"}.fa-vr-cardboard:before{content:"\f729"}.fa-vuejs:before{content:"\f41f"}.fa-walking:before{content:"\f554"}.fa-wallet:before{content:"\f555"}.fa-warehouse:before{content:"\f494"}.fa-water:before{content:"\f773"}.fa-wave-square:before{content:"\f83e"}.fa-waze:before{content:"\f83f"}.fa-weebly:before{content:"\f5cc"}.fa-weibo:before{content:"\f18a"}.fa-weight:before{content:"\f496"}.fa-weight-hanging:before{content:"\f5cd"}.fa-weixin:before{content:"\f1d7"}.fa-whatsapp:before{content:"\f232"}.fa-whatsapp-square:before{content:"\f40c"}.fa-wheelchair:before{content:"\f193"}.fa-whmcs:before{content:"\f40d"}.fa-wifi:before{content:"\f1eb"}.fa-wikipedia-w:before{content:"\f266"}.fa-wind:before{content:"\f72e"}.fa-window-close:before{content:"\f410"}.fa-window-maximize:before{content:"\f2d0"}.fa-window-minimize:before{content:"\f2d1"}.fa-window-restore:before{content:"\f2d2"}.fa-windows:before{content:"\f17a"}.fa-wine-bottle:before{content:"\f72f"}.fa-wine-glass:before{content:"\f4e3"}.fa-wine-glass-alt:before{content:"\f5ce"}.fa-wix:before{content:"\f5cf"}.fa-wizards-of-the-coast:before{content:"\f730"}.fa-wolf-pack-battalion:before{content:"\f514"}.fa-won-sign:before{content:"\f159"}.fa-wordpress:before{content:"\f19a"}.fa-wordpress-simple:before{content:"\f411"}.fa-wpbeginner:before{content:"\f297"}.fa-wpexplorer:before{content:"\f2de"}.fa-wpforms:before{content:"\f298"}.fa-wpressr:before{content:"\f3e4"}.fa-wrench:before{content:"\f0ad"}.fa-x-ray:before{content:"\f497"}.fa-xbox:before{content:"\f412"}.fa-xing:before{content:"\f168"}.fa-xing-square:before{content:"\f169"}.fa-y-combinator:before{content:"\f23b"}.fa-yahoo:before{content:"\f19e"}.fa-yammer:before{content:"\f840"}.fa-yandex:before{content:"\f413"}.fa-yandex-international:before{content:"\f414"}.fa-yarn:before{content:"\f7e3"}.fa-yelp:before{content:"\f1e9"}.fa-yen-sign:before{content:"\f157"}.fa-yin-yang:before{content:"\f6ad"}.fa-yoast:before{content:"\f2b1"}.fa-youtube:before{content:"\f167"}.fa-youtube-square:before{content:"\f431"}.fa-zhihu:before{content:"\f63f"}.sr-only{border:0;clip:rect(0,0,0,0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px}.sr-only-focusable:active,.sr-only-focusable:focus{clip:auto;height:auto;margin:0;overflow:visible;position:static;width:auto}@font-face{font-family:"Font Awesome 5 Brands";font-style:normal;font-weight:400;font-display:block;src:url(../webfonts/fa-brands-400.eot);src:url(../webfonts/fa-brands-400.eot?#iefix) format("embedded-opentype"),url(../webfonts/fa-brands-400.woff2) format("woff2"),url(../webfonts/fa-brands-400.woff) format("woff"),url(../webfonts/fa-brands-400.ttf) format("truetype"),url(../webfonts/fa-brands-400.svg#fontawesome) format("svg")}.fab{font-family:"Font Awesome 5 Brands"}@font-face{font-family:"Font Awesome 5 Free";font-style:normal;font-weight:400;font-display:block;src:url(../webfonts/fa-regular-400.eot);src:url(../webfonts/fa-regular-400.eot?#iefix) format("embedded-opentype"),url(../webfonts/fa-regular-400.woff2) format("woff2"),url(../webfonts/fa-regular-400.woff) format("woff"),url(../webfonts/fa-regular-400.ttf) format("truetype"),url(../webfonts/fa-regular-400.svg#fontawesome) format("svg")}.fab,.far{font-weight:400}@font-face{font-family:"Font Awesome 5 Free";font-style:normal;font-weight:900;font-display:block;src:url(../webfonts/fa-solid-900.eot);src:url(../webfonts/fa-solid-900.eot?#iefix) format("embedded-opentype"),url(../webfonts/fa-solid-900.woff2) format("woff2"),url(../webfonts/fa-solid-900.woff) format("woff"),url(../webfonts/fa-solid-900.ttf) format("truetype"),url(../webfonts/fa-solid-900.svg#fontawesome) format("svg")}.fa,.far,.fas{font-family:"Font Awesome 5 Free"}.fa,.fas{font-weight:900} \ No newline at end of file diff --git a/public/vendor/fontawesome/webfonts/fa-brands-400.eot b/public/vendor/fontawesome/webfonts/fa-brands-400.eot new file mode 100644 index 0000000..a1bc094 Binary files /dev/null and b/public/vendor/fontawesome/webfonts/fa-brands-400.eot differ diff --git a/public/vendor/fontawesome/webfonts/fa-brands-400.svg b/public/vendor/fontawesome/webfonts/fa-brands-400.svg new file mode 100644 index 0000000..46ad237 --- /dev/null +++ b/public/vendor/fontawesome/webfonts/fa-brands-400.svg @@ -0,0 +1,3570 @@ + + + + + +Created by FontForge 20190801 at Mon Mar 23 10:45:51 2020 + By Robert Madole +Copyright (c) Font Awesome + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/vendor/fontawesome/webfonts/fa-brands-400.ttf b/public/vendor/fontawesome/webfonts/fa-brands-400.ttf new file mode 100644 index 0000000..948a2a6 Binary files /dev/null and b/public/vendor/fontawesome/webfonts/fa-brands-400.ttf differ diff --git a/public/vendor/fontawesome/webfonts/fa-brands-400.woff b/public/vendor/fontawesome/webfonts/fa-brands-400.woff new file mode 100644 index 0000000..2a89d52 Binary files /dev/null and b/public/vendor/fontawesome/webfonts/fa-brands-400.woff differ diff --git a/public/vendor/fontawesome/webfonts/fa-brands-400.woff2 b/public/vendor/fontawesome/webfonts/fa-brands-400.woff2 new file mode 100644 index 0000000..141a90a Binary files /dev/null and b/public/vendor/fontawesome/webfonts/fa-brands-400.woff2 differ diff --git a/public/vendor/fontawesome/webfonts/fa-regular-400.eot b/public/vendor/fontawesome/webfonts/fa-regular-400.eot new file mode 100644 index 0000000..38cf251 Binary files /dev/null and b/public/vendor/fontawesome/webfonts/fa-regular-400.eot differ diff --git a/public/vendor/fontawesome/webfonts/fa-regular-400.svg b/public/vendor/fontawesome/webfonts/fa-regular-400.svg new file mode 100644 index 0000000..48634a9 --- /dev/null +++ b/public/vendor/fontawesome/webfonts/fa-regular-400.svg @@ -0,0 +1,803 @@ + + + + + +Created by FontForge 20190801 at Mon Mar 23 10:45:51 2020 + By Robert Madole +Copyright (c) Font Awesome + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/vendor/fontawesome/webfonts/fa-regular-400.ttf b/public/vendor/fontawesome/webfonts/fa-regular-400.ttf new file mode 100644 index 0000000..abe99e2 Binary files /dev/null and b/public/vendor/fontawesome/webfonts/fa-regular-400.ttf differ diff --git a/public/vendor/fontawesome/webfonts/fa-regular-400.woff b/public/vendor/fontawesome/webfonts/fa-regular-400.woff new file mode 100644 index 0000000..24de566 Binary files /dev/null and b/public/vendor/fontawesome/webfonts/fa-regular-400.woff differ diff --git a/public/vendor/fontawesome/webfonts/fa-regular-400.woff2 b/public/vendor/fontawesome/webfonts/fa-regular-400.woff2 new file mode 100644 index 0000000..7e0118e Binary files /dev/null and b/public/vendor/fontawesome/webfonts/fa-regular-400.woff2 differ diff --git a/public/vendor/fontawesome/webfonts/fa-solid-900.eot b/public/vendor/fontawesome/webfonts/fa-solid-900.eot new file mode 100644 index 0000000..d3b77c2 Binary files /dev/null and b/public/vendor/fontawesome/webfonts/fa-solid-900.eot differ diff --git a/public/vendor/fontawesome/webfonts/fa-solid-900.svg b/public/vendor/fontawesome/webfonts/fa-solid-900.svg new file mode 100644 index 0000000..7742838 --- /dev/null +++ b/public/vendor/fontawesome/webfonts/fa-solid-900.svg @@ -0,0 +1,4938 @@ + + + + + +Created by FontForge 20190801 at Mon Mar 23 10:45:51 2020 + By Robert Madole +Copyright (c) Font Awesome + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/vendor/fontawesome/webfonts/fa-solid-900.ttf b/public/vendor/fontawesome/webfonts/fa-solid-900.ttf new file mode 100644 index 0000000..5b97903 Binary files /dev/null and b/public/vendor/fontawesome/webfonts/fa-solid-900.ttf differ diff --git a/public/vendor/fontawesome/webfonts/fa-solid-900.woff b/public/vendor/fontawesome/webfonts/fa-solid-900.woff new file mode 100644 index 0000000..beec791 Binary files /dev/null and b/public/vendor/fontawesome/webfonts/fa-solid-900.woff differ diff --git a/public/vendor/fontawesome/webfonts/fa-solid-900.woff2 b/public/vendor/fontawesome/webfonts/fa-solid-900.woff2 new file mode 100644 index 0000000..978a681 Binary files /dev/null and b/public/vendor/fontawesome/webfonts/fa-solid-900.woff2 differ diff --git a/public/vendor/highlightjs/LICENSE b/public/vendor/highlightjs/LICENSE new file mode 100644 index 0000000..2250cc7 --- /dev/null +++ b/public/vendor/highlightjs/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2006, Ivan Sagalaev. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/public/vendor/highlightjs/highlight.pack.js b/public/vendor/highlightjs/highlight.pack.js new file mode 100644 index 0000000..0e72b8a --- /dev/null +++ b/public/vendor/highlightjs/highlight.pack.js @@ -0,0 +1,6 @@ +/* + Highlight.js 10.0.2 (e29f8f7d) + License: BSD-3-Clause + Copyright (c) 2006-2020, Ivan Sagalaev +*/ +var hljs=function(){"use strict";function e(n){Object.freeze(n);var t="function"==typeof n;return Object.getOwnPropertyNames(n).forEach((function(r){!n.hasOwnProperty(r)||null===n[r]||"object"!=typeof n[r]&&"function"!=typeof n[r]||t&&("caller"===r||"callee"===r||"arguments"===r)||Object.isFrozen(n[r])||e(n[r])})),n}function n(e){return e.replace(/&/g,"&").replace(//g,">")}function t(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach((function(e){for(n in e)t[n]=e[n]})),t}function r(e){return e.nodeName.toLowerCase()}var a=Object.freeze({__proto__:null,escapeHTML:n,inherit:t,nodeStream:function(e){var n=[];return function e(t,a){for(var i=t.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&&(n.push({event:"start",offset:a,node:i}),a=e(i,a),r(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n},mergeStreams:function(e,t,a){var i=0,s="",o=[];function l(){return e.length&&t.length?e[0].offset!==t[0].offset?e[0].offset"}function u(e){s+=""}function d(e){("start"===e.event?c:u)(e.node)}for(;e.length||t.length;){var g=l();if(s+=n(a.substring(i,g[0].offset)),i=g[0].offset,g===e){o.reverse().forEach(u);do{d(g.splice(0,1)[0]),g=l()}while(g===e&&g.length&&g[0].offset===i);o.reverse().forEach(c)}else"start"===g[0].event?o.push(g[0].node):o.pop(),d(g.splice(0,1)[0])}return s+n(a.substr(i))}});const i="",s=e=>!!e.kind;class o{constructor(e,n){this.buffer="",this.classPrefix=n.classPrefix,e.walk(this)}addText(e){this.buffer+=n(e)}openNode(e){if(!s(e))return;let n=e.kind;e.sublanguage||(n=`${this.classPrefix}${n}`),this.span(n)}closeNode(e){s(e)&&(this.buffer+=i)}span(e){this.buffer+=``}value(){return this.buffer}}class l{constructor(){this.rootNode={children:[]},this.stack=[this.rootNode]}get top(){return this.stack[this.stack.length-1]}get root(){return this.rootNode}add(e){this.top.children.push(e)}openNode(e){let n={kind:e,children:[]};this.add(n),this.stack.push(n)}closeNode(){if(this.stack.length>1)return this.stack.pop()}closeAllNodes(){for(;this.closeNode(););}toJSON(){return JSON.stringify(this.rootNode,null,4)}walk(e){return this.constructor._walk(e,this.rootNode)}static _walk(e,n){return"string"==typeof n?e.addText(n):n.children&&(e.openNode(n),n.children.forEach(n=>this._walk(e,n)),e.closeNode(n)),e}static _collapse(e){e.children&&(e.children.every(e=>"string"==typeof e)?(e.text=e.children.join(""),delete e.children):e.children.forEach(e=>{"string"!=typeof e&&l._collapse(e)}))}}class c extends l{constructor(e){super(),this.options=e}addKeyword(e,n){""!==e&&(this.openNode(n),this.addText(e),this.closeNode())}addText(e){""!==e&&this.add(e)}addSublanguage(e,n){let t=e.root;t.kind=n,t.sublanguage=!0,this.add(t)}toHTML(){return new o(this,this.options).value()}finalize(){}}function u(e){return e&&e.source||e}const d="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",g={begin:"\\\\[\\s\\S]",relevance:0},h={className:"string",begin:"'",end:"'",illegal:"\\n",contains:[g]},f={className:"string",begin:'"',end:'"',illegal:"\\n",contains:[g]},p={begin:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},m=function(e,n,r){var a=t({className:"comment",begin:e,end:n,contains:[]},r||{});return a.contains.push(p),a.contains.push({className:"doctag",begin:"(?:TODO|FIXME|NOTE|BUG|XXX):",relevance:0}),a},b=m("//","$"),v=m("/\\*","\\*/"),x=m("#","$");var _=Object.freeze({__proto__:null,IDENT_RE:"[a-zA-Z]\\w*",UNDERSCORE_IDENT_RE:"[a-zA-Z_]\\w*",NUMBER_RE:"\\b\\d+(\\.\\d+)?",C_NUMBER_RE:d,BINARY_NUMBER_RE:"\\b(0b[01]+)",RE_STARTERS_RE:"!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",BACKSLASH_ESCAPE:g,APOS_STRING_MODE:h,QUOTE_STRING_MODE:f,PHRASAL_WORDS_MODE:p,COMMENT:m,C_LINE_COMMENT_MODE:b,C_BLOCK_COMMENT_MODE:v,HASH_COMMENT_MODE:x,NUMBER_MODE:{className:"number",begin:"\\b\\d+(\\.\\d+)?",relevance:0},C_NUMBER_MODE:{className:"number",begin:d,relevance:0},BINARY_NUMBER_MODE:{className:"number",begin:"\\b(0b[01]+)",relevance:0},CSS_NUMBER_MODE:{className:"number",begin:"\\b\\d+(\\.\\d+)?(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",relevance:0},REGEXP_MODE:{begin:/(?=\/[^\/\n]*\/)/,contains:[{className:"regexp",begin:/\//,end:/\/[gimuy]*/,illegal:/\n/,contains:[g,{begin:/\[/,end:/\]/,relevance:0,contains:[g]}]}]},TITLE_MODE:{className:"title",begin:"[a-zA-Z]\\w*",relevance:0},UNDERSCORE_TITLE_MODE:{className:"title",begin:"[a-zA-Z_]\\w*",relevance:0},METHOD_GUARD:{begin:"\\.\\s*[a-zA-Z_]\\w*",relevance:0}}),E="of and for in not or if then".split(" ");function R(e,n){return n?+n:(t=e,E.includes(t.toLowerCase())?0:1);var t}const N=n,w=t,{nodeStream:y,mergeStreams:O}=a;return function(n){var r=[],a={},i={},s=[],o=!0,l=/((^(<[^>]+>|\t|)+|(?:\n)))/gm,d="Could not find the language '{}', did you forget to load/include a language module?",g={noHighlightRe:/^(no-?highlight)$/i,languageDetectRe:/\blang(?:uage)?-([\w-]+)\b/i,classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0,__emitter:c};function h(e){return g.noHighlightRe.test(e)}function f(e,n,t,r){var a={code:n,language:e};T("before:highlight",a);var i=a.result?a.result:p(a.language,a.code,t,r);return i.code=a.code,T("after:highlight",i),i}function p(e,n,r,i){var s=n;function l(e,n){var t=v.case_insensitive?n[0].toLowerCase():n[0];return e.keywords.hasOwnProperty(t)&&e.keywords[t]}function c(){null!=_.subLanguage?function(){if(""!==k){var e="string"==typeof _.subLanguage;if(!e||a[_.subLanguage]){var n=e?p(_.subLanguage,k,!0,E[_.subLanguage]):m(k,_.subLanguage.length?_.subLanguage:void 0);_.relevance>0&&(T+=n.relevance),e&&(E[_.subLanguage]=n.top),w.addSublanguage(n.emitter,n.language)}else w.addText(k)}}():function(){var e,n,t,r;if(_.keywords){for(n=0,_.lexemesRe.lastIndex=0,t=_.lexemesRe.exec(k),r="";t;){r+=k.substring(n,t.index);var a=null;(e=l(_,t))?(w.addText(r),r="",T+=e[1],a=e[0],w.addKeyword(t[0],a)):r+=t[0],n=_.lexemesRe.lastIndex,t=_.lexemesRe.exec(k)}r+=k.substr(n),w.addText(r)}else w.addText(k)}(),k=""}function h(e){e.className&&w.openNode(e.className),_=Object.create(e,{parent:{value:_}})}var f={};function b(n,t){var a,i=t&&t[0];if(k+=n,null==i)return c(),0;if("begin"==f.type&&"end"==t.type&&f.index==t.index&&""===i){if(k+=s.slice(t.index,t.index+1),!o)throw(a=Error("0 width match regex")).languageName=e,a.badRule=f.rule,a;return 1}if(f=t,"begin"===t.type)return function(e){var n=e[0],t=e.rule;return t.__onBegin&&(t.__onBegin(e)||{}).ignoreMatch?function(e){return 0===_.matcher.regexIndex?(k+=e[0],1):(B=!0,0)}(n):(t&&t.endSameAsBegin&&(t.endRe=RegExp(n.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"m")),t.skip?k+=n:(t.excludeBegin&&(k+=n),c(),t.returnBegin||t.excludeBegin||(k=n)),h(t),t.returnBegin?0:n.length)}(t);if("illegal"===t.type&&!r)throw(a=Error('Illegal lexeme "'+i+'" for mode "'+(_.className||"")+'"')).mode=_,a;if("end"===t.type){var l=function(e){var n=e[0],t=s.substr(e.index),r=function e(n,t){if(function(e,n){var t=e&&e.exec(n);return t&&0===t.index}(n.endRe,t)){for(;n.endsParent&&n.parent;)n=n.parent;return n}if(n.endsWithParent)return e(n.parent,t)}(_,t);if(r){var a=_;a.skip?k+=n:(a.returnEnd||a.excludeEnd||(k+=n),c(),a.excludeEnd&&(k=n));do{_.className&&w.closeNode(),_.skip||_.subLanguage||(T+=_.relevance),_=_.parent}while(_!==r.parent);return r.starts&&(r.endSameAsBegin&&(r.starts.endRe=r.endRe),h(r.starts)),a.returnEnd?0:n.length}}(t);if(null!=l)return l}if("illegal"===t.type&&""===i)return 1;if(A>1e5&&A>3*t.index)throw Error("potential infinite loop, way more iterations than matches");return k+=i,i.length}var v=M(e);if(!v)throw console.error(d.replace("{}",e)),Error('Unknown language: "'+e+'"');!function(e){function n(n,t){return RegExp(u(n),"m"+(e.case_insensitive?"i":"")+(t?"g":""))}class r{constructor(){this.matchIndexes={},this.regexes=[],this.matchAt=1,this.position=0}addRule(e,n){n.position=this.position++,this.matchIndexes[this.matchAt]=n,this.regexes.push([n,e]),this.matchAt+=function(e){return RegExp(e.toString()+"|").exec("").length-1}(e)+1}compile(){0===this.regexes.length&&(this.exec=()=>null);let e=this.regexes.map(e=>e[1]);this.matcherRe=n(function(e,n){for(var t=/\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./,r=0,a="",i=0;i0&&(a+="|"),a+="(";o.length>0;){var l=t.exec(o);if(null==l){a+=o;break}a+=o.substring(0,l.index),o=o.substring(l.index+l[0].length),"\\"==l[0][0]&&l[1]?a+="\\"+(+l[1]+s):(a+=l[0],"("==l[0]&&r++)}a+=")"}return a}(e),!0),this.lastIndex=0}exec(e){this.matcherRe.lastIndex=this.lastIndex;let n=this.matcherRe.exec(e);if(!n)return null;let t=n.findIndex((e,n)=>n>0&&null!=e),r=this.matchIndexes[t];return Object.assign(n,r)}}class a{constructor(){this.rules=[],this.multiRegexes=[],this.count=0,this.lastIndex=0,this.regexIndex=0}getMatcher(e){if(this.multiRegexes[e])return this.multiRegexes[e];let n=new r;return this.rules.slice(e).forEach(([e,t])=>n.addRule(e,t)),n.compile(),this.multiRegexes[e]=n,n}considerAll(){this.regexIndex=0}addRule(e,n){this.rules.push([e,n]),"begin"===n.type&&this.count++}exec(e){let n=this.getMatcher(this.regexIndex);n.lastIndex=this.lastIndex;let t=n.exec(e);return t&&(this.regexIndex+=t.position+1,this.regexIndex===this.count&&(this.regexIndex=0)),t}}function i(e){let n=e.input[e.index-1],t=e.input[e.index+e[0].length];if("."===n||"."===t)return{ignoreMatch:!0}}if(e.contains&&e.contains.includes("self"))throw Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");!function r(s,o){s.compiled||(s.compiled=!0,s.__onBegin=null,s.keywords=s.keywords||s.beginKeywords,s.keywords&&(s.keywords=function(e,n){var t={};return"string"==typeof e?r("keyword",e):Object.keys(e).forEach((function(n){r(n,e[n])})),t;function r(e,r){n&&(r=r.toLowerCase()),r.split(" ").forEach((function(n){var r=n.split("|");t[r[0]]=[e,R(r[0],r[1])]}))}}(s.keywords,e.case_insensitive)),s.lexemesRe=n(s.lexemes||/\w+/,!0),o&&(s.beginKeywords&&(s.begin="\\b("+s.beginKeywords.split(" ").join("|")+")(?=\\b|\\s)",s.__onBegin=i),s.begin||(s.begin=/\B|\b/),s.beginRe=n(s.begin),s.endSameAsBegin&&(s.end=s.begin),s.end||s.endsWithParent||(s.end=/\B|\b/),s.end&&(s.endRe=n(s.end)),s.terminator_end=u(s.end)||"",s.endsWithParent&&o.terminator_end&&(s.terminator_end+=(s.end?"|":"")+o.terminator_end)),s.illegal&&(s.illegalRe=n(s.illegal)),null==s.relevance&&(s.relevance=1),s.contains||(s.contains=[]),s.contains=[].concat(...s.contains.map((function(e){return function(e){return e.variants&&!e.cached_variants&&(e.cached_variants=e.variants.map((function(n){return t(e,{variants:null},n)}))),e.cached_variants?e.cached_variants:function e(n){return!!n&&(n.endsWithParent||e(n.starts))}(e)?t(e,{starts:e.starts?t(e.starts):null}):Object.isFrozen(e)?t(e):e}("self"===e?s:e)}))),s.contains.forEach((function(e){r(e,s)})),s.starts&&r(s.starts,o),s.matcher=function(e){let n=new a;return e.contains.forEach(e=>n.addRule(e.begin,{rule:e,type:"begin"})),e.terminator_end&&n.addRule(e.terminator_end,{type:"end"}),e.illegal&&n.addRule(e.illegal,{type:"illegal"}),n}(s))}(e)}(v);var x,_=i||v,E={},w=new g.__emitter(g);!function(){for(var e=[],n=_;n!==v;n=n.parent)n.className&&e.unshift(n.className);e.forEach(e=>w.openNode(e))}();var y,O,k="",T=0,L=0,A=0,B=!1;try{for(_.matcher.considerAll();A++,B?B=!1:(_.matcher.lastIndex=L,_.matcher.considerAll()),y=_.matcher.exec(s);)O=b(s.substring(L,y.index),y),L=y.index+O;return b(s.substr(L)),w.closeAllNodes(),w.finalize(),x=w.toHTML(),{relevance:T,value:x,language:e,illegal:!1,emitter:w,top:_}}catch(n){if(n.message&&n.message.includes("Illegal"))return{illegal:!0,illegalBy:{msg:n.message,context:s.slice(L-100,L+100),mode:n.mode},sofar:x,relevance:0,value:N(s),emitter:w};if(o)return{relevance:0,value:N(s),emitter:w,language:e,top:_,errorRaised:n};throw n}}function m(e,n){n=n||g.languages||Object.keys(a);var t=function(e){const n={relevance:0,emitter:new g.__emitter(g),value:N(e),illegal:!1,top:E};return n.emitter.addText(e),n}(e),r=t;return n.filter(M).filter(k).forEach((function(n){var a=p(n,e,!1);a.language=n,a.relevance>r.relevance&&(r=a),a.relevance>t.relevance&&(r=t,t=a)})),r.language&&(t.second_best=r),t}function b(e){return g.tabReplace||g.useBR?e.replace(l,(function(e,n){return g.useBR&&"\n"===e?"
":g.tabReplace?n.replace(/\t/g,g.tabReplace):""})):e}function v(e){var n,t,r,a,s,o=function(e){var n,t=e.className+" ";if(t+=e.parentNode?e.parentNode.className:"",n=g.languageDetectRe.exec(t)){var r=M(n[1]);return r||(console.warn(d.replace("{}",n[1])),console.warn("Falling back to no-highlight mode for this block.",e)),r?n[1]:"no-highlight"}return t.split(/\s+/).find(e=>h(e)||M(e))}(e);h(o)||(T("before:highlightBlock",{block:e,language:o}),g.useBR?(n=document.createElement("div")).innerHTML=e.innerHTML.replace(/\n/g,"").replace(//g,"\n"):n=e,s=n.textContent,r=o?f(o,s,!0):m(s),(t=y(n)).length&&((a=document.createElement("div")).innerHTML=r.value,r.value=O(t,y(a),s)),r.value=b(r.value),T("after:highlightBlock",{block:e,result:r}),e.innerHTML=r.value,e.className=function(e,n,t){var r=n?i[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),e.includes(r)||a.push(r),a.join(" ").trim()}(e.className,o,r.language),e.result={language:r.language,re:r.relevance},r.second_best&&(e.second_best={language:r.second_best.language,re:r.second_best.relevance}))}function x(){if(!x.called){x.called=!0;var e=document.querySelectorAll("pre code");r.forEach.call(e,v)}}const E={disableAutodetect:!0,name:"Plain text"};function M(e){return e=(e||"").toLowerCase(),a[e]||a[i[e]]}function k(e){var n=M(e);return n&&!n.disableAutodetect}function T(e,n){var t=e;s.forEach((function(e){e[t]&&e[t](n)}))}Object.assign(n,{highlight:f,highlightAuto:m,fixMarkup:b,highlightBlock:v,configure:function(e){g=w(g,e)},initHighlighting:x,initHighlightingOnLoad:function(){window.addEventListener("DOMContentLoaded",x,!1)},registerLanguage:function(e,t){var r;try{r=t(n)}catch(n){if(console.error("Language definition for '{}' could not be registered.".replace("{}",e)),!o)throw n;console.error(n),r=E}r.name||(r.name=e),a[e]=r,r.rawDefinition=t.bind(null,n),r.aliases&&r.aliases.forEach((function(n){i[n]=e}))},listLanguages:function(){return Object.keys(a)},getLanguage:M,requireLanguage:function(e){var n=M(e);if(n)return n;throw Error("The '{}' language is required, but not loaded.".replace("{}",e))},autoDetection:k,inherit:w,addPlugin:function(e,n){s.push(e)}}),n.debugMode=function(){o=!1},n.safeMode=function(){o=!0},n.versionString="10.0.2";for(const n in _)"object"==typeof _[n]&&e(_[n]);return Object.assign(n,_),n}({})}();"object"==typeof exports&&"undefined"!=typeof module&&(module.exports=hljs);hljs.registerLanguage("vhdl",function(){"use strict";return function(e){return{name:"VHDL",case_insensitive:!0,keywords:{keyword:"abs access after alias all and architecture array assert assume assume_guarantee attribute begin block body buffer bus case component configuration constant context cover disconnect downto default else elsif end entity exit fairness file for force function generate generic group guarded if impure in inertial inout is label library linkage literal loop map mod nand new next nor not null of on open or others out package parameter port postponed procedure process property protected pure range record register reject release rem report restrict restrict_guarantee return rol ror select sequence severity shared signal sla sll sra srl strong subtype then to transport type unaffected units until use variable view vmode vprop vunit wait when while with xnor xor",built_in:"boolean bit character integer time delay_length natural positive string bit_vector file_open_kind file_open_status std_logic std_logic_vector unsigned signed boolean_vector integer_vector std_ulogic std_ulogic_vector unresolved_unsigned u_unsigned unresolved_signed u_signed real_vector time_vector",literal:"false true note warning error failure line text side width"},illegal:"{",contains:[e.C_BLOCK_COMMENT_MODE,e.COMMENT("--","$"),e.QUOTE_STRING_MODE,{className:"number",begin:"\\b(\\d(_|\\d)*#\\w+(\\.\\w+)?#([eE][-+]?\\d(_|\\d)*)?|\\d(_|\\d)*(\\.\\d(_|\\d)*)?([eE][-+]?\\d(_|\\d)*)?)",relevance:0},{className:"string",begin:"'(U|X|0|1|Z|W|L|H|-)'",contains:[e.BACKSLASH_ESCAPE]},{className:"symbol",begin:"'[A-Za-z](_?[A-Za-z0-9])*",contains:[e.BACKSLASH_ESCAPE]}]}}}());hljs.registerLanguage("mipsasm",function(){"use strict";return function(e){return{name:"MIPS Assembly",case_insensitive:!0,aliases:["mips"],lexemes:"\\.?"+e.IDENT_RE,keywords:{meta:".2byte .4byte .align .ascii .asciz .balign .byte .code .data .else .end .endif .endm .endr .equ .err .exitm .extern .global .hword .if .ifdef .ifndef .include .irp .long .macro .rept .req .section .set .skip .space .text .word .ltorg ",built_in:"$0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 $16 $17 $18 $19 $20 $21 $22 $23 $24 $25 $26 $27 $28 $29 $30 $31 zero at v0 v1 a0 a1 a2 a3 a4 a5 a6 a7 t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 s0 s1 s2 s3 s4 s5 s6 s7 s8 k0 k1 gp sp fp ra $f0 $f1 $f2 $f2 $f4 $f5 $f6 $f7 $f8 $f9 $f10 $f11 $f12 $f13 $f14 $f15 $f16 $f17 $f18 $f19 $f20 $f21 $f22 $f23 $f24 $f25 $f26 $f27 $f28 $f29 $f30 $f31 Context Random EntryLo0 EntryLo1 Context PageMask Wired EntryHi HWREna BadVAddr Count Compare SR IntCtl SRSCtl SRSMap Cause EPC PRId EBase Config Config1 Config2 Config3 LLAddr Debug DEPC DESAVE CacheErr ECC ErrorEPC TagLo DataLo TagHi DataHi WatchLo WatchHi PerfCtl PerfCnt "},contains:[{className:"keyword",begin:"\\b(addi?u?|andi?|b(al)?|beql?|bgez(al)?l?|bgtzl?|blezl?|bltz(al)?l?|bnel?|cl[oz]|divu?|ext|ins|j(al)?|jalr(.hb)?|jr(.hb)?|lbu?|lhu?|ll|lui|lw[lr]?|maddu?|mfhi|mflo|movn|movz|move|msubu?|mthi|mtlo|mul|multu?|nop|nor|ori?|rotrv?|sb|sc|se[bh]|sh|sllv?|slti?u?|srav?|srlv?|subu?|sw[lr]?|xori?|wsbh|abs.[sd]|add.[sd]|alnv.ps|bc1[ft]l?|c.(s?f|un|u?eq|[ou]lt|[ou]le|ngle?|seq|l[et]|ng[et]).[sd]|(ceil|floor|round|trunc).[lw].[sd]|cfc1|cvt.d.[lsw]|cvt.l.[dsw]|cvt.ps.s|cvt.s.[dlw]|cvt.s.p[lu]|cvt.w.[dls]|div.[ds]|ldx?c1|luxc1|lwx?c1|madd.[sd]|mfc1|mov[fntz]?.[ds]|msub.[sd]|mth?c1|mul.[ds]|neg.[ds]|nmadd.[ds]|nmsub.[ds]|p[lu][lu].ps|recip.fmt|r?sqrt.[ds]|sdx?c1|sub.[ds]|suxc1|swx?c1|break|cache|d?eret|[de]i|ehb|mfc0|mtc0|pause|prefx?|rdhwr|rdpgpr|sdbbp|ssnop|synci?|syscall|teqi?|tgei?u?|tlb(p|r|w[ir])|tlti?u?|tnei?|wait|wrpgpr)",end:"\\s"},e.COMMENT("[;#](?!s*$)","$"),e.C_BLOCK_COMMENT_MODE,e.QUOTE_STRING_MODE,{className:"string",begin:"'",end:"[^\\\\]'",relevance:0},{className:"title",begin:"\\|",end:"\\|",illegal:"\\n",relevance:0},{className:"number",variants:[{begin:"0x[0-9a-f]+"},{begin:"\\b-?\\d+"}],relevance:0},{className:"symbol",variants:[{begin:"^\\s*[a-z_\\.\\$][a-z0-9_\\.\\$]+:"},{begin:"^\\s*[0-9]+:"},{begin:"[0-9]+[bf]"}],relevance:0}],illegal:"/"}}}());hljs.registerLanguage("rust",function(){"use strict";return function(e){var n="([ui](8|16|32|64|128|size)|f(32|64))?",t="drop i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize f32 f64 str char bool Box Option Result String Vec Copy Send Sized Sync Drop Fn FnMut FnOnce ToOwned Clone Debug PartialEq PartialOrd Eq Ord AsRef AsMut Into From Default Iterator Extend IntoIterator DoubleEndedIterator ExactSizeIterator SliceConcatExt ToString assert! assert_eq! bitflags! bytes! cfg! col! concat! concat_idents! debug_assert! debug_assert_eq! env! panic! file! format! format_args! include_bin! include_str! line! local_data_key! module_path! option_env! print! println! select! stringify! try! unimplemented! unreachable! vec! write! writeln! macro_rules! assert_ne! debug_assert_ne!";return{name:"Rust",aliases:["rs"],keywords:{keyword:"abstract as async await become box break const continue crate do dyn else enum extern false final fn for if impl in let loop macro match mod move mut override priv pub ref return self Self static struct super trait true try type typeof unsafe unsized use virtual where while yield",literal:"true false Some None Ok Err",built_in:t},lexemes:e.IDENT_RE+"!?",illegal:""}]}}}());hljs.registerLanguage("xml",function(){"use strict";return function(e){var n={className:"symbol",begin:"&[a-z]+;|&#[0-9]+;|&#x[a-f0-9]+;"},a={begin:"\\s",contains:[{className:"meta-keyword",begin:"#?[a-z_][a-z1-9_-]+",illegal:"\\n"}]},s=e.inherit(a,{begin:"\\(",end:"\\)"}),t=e.inherit(e.APOS_STRING_MODE,{className:"meta-string"}),i=e.inherit(e.QUOTE_STRING_MODE,{className:"meta-string"}),c={endsWithParent:!0,illegal:/`]+/}]}]}]};return{name:"HTML, XML",aliases:["html","xhtml","rss","atom","xjb","xsd","xsl","plist","wsf","svg"],case_insensitive:!0,contains:[{className:"meta",begin:"",relevance:10,contains:[a,i,t,s,{begin:"\\[",end:"\\]",contains:[{className:"meta",begin:"",contains:[a,s,i,t]}]}]},e.COMMENT("\x3c!--","--\x3e",{relevance:10}),{begin:"<\\!\\[CDATA\\[",end:"\\]\\]>",relevance:10},n,{className:"meta",begin:/<\?xml/,end:/\?>/,relevance:10},{className:"tag",begin:")",end:">",keywords:{name:"style"},contains:[c],starts:{end:"",returnEnd:!0,subLanguage:["css","xml"]}},{className:"tag",begin:")",end:">",keywords:{name:"script"},contains:[c],starts:{end:"<\/script>",returnEnd:!0,subLanguage:["javascript","handlebars","xml"]}},{className:"tag",begin:"",contains:[{className:"name",begin:/[^\/><\s]+/,relevance:0},c]}]}}}());hljs.registerLanguage("sql",function(){"use strict";return function(e){var t=e.COMMENT("--","$");return{name:"SQL",case_insensitive:!0,illegal:/[<>{}*]/,contains:[{beginKeywords:"begin end start commit rollback savepoint lock alter create drop rename call delete do handler insert load replace select truncate update set show pragma grant merge describe use explain help declare prepare execute deallocate release unlock purge reset change stop analyze cache flush optimize repair kill install uninstall checksum restore check backup revoke comment values with",end:/;/,endsWithParent:!0,lexemes:/[\w\.]+/,keywords:{keyword:"as abort abs absolute acc acce accep accept access accessed accessible account acos action activate add addtime admin administer advanced advise aes_decrypt aes_encrypt after agent aggregate ali alia alias all allocate allow alter always analyze ancillary and anti any anydata anydataset anyschema anytype apply archive archived archivelog are as asc ascii asin assembly assertion associate asynchronous at atan atn2 attr attri attrib attribu attribut attribute attributes audit authenticated authentication authid authors auto autoallocate autodblink autoextend automatic availability avg backup badfile basicfile before begin beginning benchmark between bfile bfile_base big bigfile bin binary_double binary_float binlog bit_and bit_count bit_length bit_or bit_xor bitmap blob_base block blocksize body both bound bucket buffer_cache buffer_pool build bulk by byte byteordermark bytes cache caching call calling cancel capacity cascade cascaded case cast catalog category ceil ceiling chain change changed char_base char_length character_length characters characterset charindex charset charsetform charsetid check checksum checksum_agg child choose chr chunk class cleanup clear client clob clob_base clone close cluster_id cluster_probability cluster_set clustering coalesce coercibility col collate collation collect colu colum column column_value columns columns_updated comment commit compact compatibility compiled complete composite_limit compound compress compute concat concat_ws concurrent confirm conn connec connect connect_by_iscycle connect_by_isleaf connect_by_root connect_time connection consider consistent constant constraint constraints constructor container content contents context contributors controlfile conv convert convert_tz corr corr_k corr_s corresponding corruption cos cost count count_big counted covar_pop covar_samp cpu_per_call cpu_per_session crc32 create creation critical cross cube cume_dist curdate current current_date current_time current_timestamp current_user cursor curtime customdatum cycle data database databases datafile datafiles datalength date_add date_cache date_format date_sub dateadd datediff datefromparts datename datepart datetime2fromparts day day_to_second dayname dayofmonth dayofweek dayofyear days db_role_change dbtimezone ddl deallocate declare decode decompose decrement decrypt deduplicate def defa defau defaul default defaults deferred defi defin define degrees delayed delegate delete delete_all delimited demand dense_rank depth dequeue des_decrypt des_encrypt des_key_file desc descr descri describ describe descriptor deterministic diagnostics difference dimension direct_load directory disable disable_all disallow disassociate discardfile disconnect diskgroup distinct distinctrow distribute distributed div do document domain dotnet double downgrade drop dumpfile duplicate duration each edition editionable editions element ellipsis else elsif elt empty enable enable_all enclosed encode encoding encrypt end end-exec endian enforced engine engines enqueue enterprise entityescaping eomonth error errors escaped evalname evaluate event eventdata events except exception exceptions exchange exclude excluding execu execut execute exempt exists exit exp expire explain explode export export_set extended extent external external_1 external_2 externally extract failed failed_login_attempts failover failure far fast feature_set feature_value fetch field fields file file_name_convert filesystem_like_logging final finish first first_value fixed flash_cache flashback floor flush following follows for forall force foreign form forma format found found_rows freelist freelists freepools fresh from from_base64 from_days ftp full function general generated get get_format get_lock getdate getutcdate global global_name globally go goto grant grants greatest group group_concat group_id grouping grouping_id groups gtid_subtract guarantee guard handler hash hashkeys having hea head headi headin heading heap help hex hierarchy high high_priority hosts hour hours http id ident_current ident_incr ident_seed identified identity idle_time if ifnull ignore iif ilike ilm immediate import in include including increment index indexes indexing indextype indicator indices inet6_aton inet6_ntoa inet_aton inet_ntoa infile initial initialized initially initrans inmemory inner innodb input insert install instance instantiable instr interface interleaved intersect into invalidate invisible is is_free_lock is_ipv4 is_ipv4_compat is_not is_not_null is_used_lock isdate isnull isolation iterate java join json json_exists keep keep_duplicates key keys kill language large last last_day last_insert_id last_value lateral lax lcase lead leading least leaves left len lenght length less level levels library like like2 like4 likec limit lines link list listagg little ln load load_file lob lobs local localtime localtimestamp locate locator lock locked log log10 log2 logfile logfiles logging logical logical_reads_per_call logoff logon logs long loop low low_priority lower lpad lrtrim ltrim main make_set makedate maketime managed management manual map mapping mask master master_pos_wait match matched materialized max maxextents maximize maxinstances maxlen maxlogfiles maxloghistory maxlogmembers maxsize maxtrans md5 measures median medium member memcompress memory merge microsecond mid migration min minextents minimum mining minus minute minutes minvalue missing mod mode model modification modify module monitoring month months mount move movement multiset mutex name name_const names nan national native natural nav nchar nclob nested never new newline next nextval no no_write_to_binlog noarchivelog noaudit nobadfile nocheck nocompress nocopy nocycle nodelay nodiscardfile noentityescaping noguarantee nokeep nologfile nomapping nomaxvalue nominimize nominvalue nomonitoring none noneditionable nonschema noorder nopr nopro noprom nopromp noprompt norely noresetlogs noreverse normal norowdependencies noschemacheck noswitch not nothing notice notnull notrim novalidate now nowait nth_value nullif nulls num numb numbe nvarchar nvarchar2 object ocicoll ocidate ocidatetime ociduration ociinterval ociloblocator ocinumber ociref ocirefcursor ocirowid ocistring ocitype oct octet_length of off offline offset oid oidindex old on online only opaque open operations operator optimal optimize option optionally or oracle oracle_date oradata ord ordaudio orddicom orddoc order ordimage ordinality ordvideo organization orlany orlvary out outer outfile outline output over overflow overriding package pad parallel parallel_enable parameters parent parse partial partition partitions pascal passing password password_grace_time password_lock_time password_reuse_max password_reuse_time password_verify_function patch path patindex pctincrease pctthreshold pctused pctversion percent percent_rank percentile_cont percentile_disc performance period period_add period_diff permanent physical pi pipe pipelined pivot pluggable plugin policy position post_transaction pow power pragma prebuilt precedes preceding precision prediction prediction_cost prediction_details prediction_probability prediction_set prepare present preserve prior priority private private_sga privileges procedural procedure procedure_analyze processlist profiles project prompt protection public publishingservername purge quarter query quick quiesce quota quotename radians raise rand range rank raw read reads readsize rebuild record records recover recovery recursive recycle redo reduced ref reference referenced references referencing refresh regexp_like register regr_avgx regr_avgy regr_count regr_intercept regr_r2 regr_slope regr_sxx regr_sxy reject rekey relational relative relaylog release release_lock relies_on relocate rely rem remainder rename repair repeat replace replicate replication required reset resetlogs resize resource respect restore restricted result result_cache resumable resume retention return returning returns reuse reverse revoke right rlike role roles rollback rolling rollup round row row_count rowdependencies rowid rownum rows rtrim rules safe salt sample save savepoint sb1 sb2 sb4 scan schema schemacheck scn scope scroll sdo_georaster sdo_topo_geometry search sec_to_time second seconds section securefile security seed segment select self semi sequence sequential serializable server servererror session session_user sessions_per_user set sets settings sha sha1 sha2 share shared shared_pool short show shrink shutdown si_averagecolor si_colorhistogram si_featurelist si_positionalcolor si_stillimage si_texture siblings sid sign sin size size_t sizes skip slave sleep smalldatetimefromparts smallfile snapshot some soname sort soundex source space sparse spfile split sql sql_big_result sql_buffer_result sql_cache sql_calc_found_rows sql_small_result sql_variant_property sqlcode sqldata sqlerror sqlname sqlstate sqrt square standalone standby start starting startup statement static statistics stats_binomial_test stats_crosstab stats_ks_test stats_mode stats_mw_test stats_one_way_anova stats_t_test_ stats_t_test_indep stats_t_test_one stats_t_test_paired stats_wsr_test status std stddev stddev_pop stddev_samp stdev stop storage store stored str str_to_date straight_join strcmp strict string struct stuff style subdate subpartition subpartitions substitutable substr substring subtime subtring_index subtype success sum suspend switch switchoffset switchover sync synchronous synonym sys sys_xmlagg sysasm sysaux sysdate sysdatetimeoffset sysdba sysoper system system_user sysutcdatetime table tables tablespace tablesample tan tdo template temporary terminated tertiary_weights test than then thread through tier ties time time_format time_zone timediff timefromparts timeout timestamp timestampadd timestampdiff timezone_abbr timezone_minute timezone_region to to_base64 to_date to_days to_seconds todatetimeoffset trace tracking transaction transactional translate translation treat trigger trigger_nestlevel triggers trim truncate try_cast try_convert try_parse type ub1 ub2 ub4 ucase unarchived unbounded uncompress under undo unhex unicode uniform uninstall union unique unix_timestamp unknown unlimited unlock unnest unpivot unrecoverable unsafe unsigned until untrusted unusable unused update updated upgrade upped upper upsert url urowid usable usage use use_stored_outlines user user_data user_resources users using utc_date utc_timestamp uuid uuid_short validate validate_password_strength validation valist value values var var_samp varcharc vari varia variab variabl variable variables variance varp varraw varrawc varray verify version versions view virtual visible void wait wallet warning warnings week weekday weekofyear wellformed when whene whenev wheneve whenever where while whitespace window with within without work wrapped xdb xml xmlagg xmlattributes xmlcast xmlcolattval xmlelement xmlexists xmlforest xmlindex xmlnamespaces xmlpi xmlquery xmlroot xmlschema xmlserialize xmltable xmltype xor year year_to_month years yearweek",literal:"true false null unknown",built_in:"array bigint binary bit blob bool boolean char character date dec decimal float int int8 integer interval number numeric real record serial serial8 smallint text time timestamp tinyint varchar varchar2 varying void"},contains:[{className:"string",begin:"'",end:"'",contains:[{begin:"''"}]},{className:"string",begin:'"',end:'"',contains:[{begin:'""'}]},{className:"string",begin:"`",end:"`"},e.C_NUMBER_MODE,e.C_BLOCK_COMMENT_MODE,t,e.HASH_COMMENT_MODE]},e.C_BLOCK_COMMENT_MODE,t,e.HASH_COMMENT_MODE]}}}());hljs.registerLanguage("ebnf",function(){"use strict";return function(a){var e=a.COMMENT(/\(\*/,/\*\)/);return{name:"Extended Backus-Naur Form",illegal:/\S/,contains:[e,{className:"attribute",begin:/^[ ]*[a-zA-Z][a-zA-Z-_]*([\s-_]+[a-zA-Z][a-zA-Z]*)*/},{begin:/=/,end:/[.;]/,contains:[e,{className:"meta",begin:/\?.*\?/},{className:"string",variants:[a.APOS_STRING_MODE,a.QUOTE_STRING_MODE,{begin:"`",end:"`"}]}]}]}}}());hljs.registerLanguage("javascript",function(){"use strict";return function(e){var n={begin:/<[A-Za-z0-9\\._:-]+/,end:/\/[A-Za-z0-9\\._:-]+>|\/>/},a="[A-Za-z$_][0-9A-Za-z$_]*",s={keyword:"in of if for while finally var new function do return void else break catch instanceof with throw case default try this switch continue typeof delete let yield const export super debugger as async await static import from as",literal:"true false null undefined NaN Infinity",built_in:"eval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError Number Math Date String RegExp Array Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray ArrayBuffer DataView JSON Intl arguments require module console window document Symbol Set Map WeakSet WeakMap Proxy Reflect Promise"},r={className:"number",variants:[{begin:"\\b(0[bB][01]+)n?"},{begin:"\\b(0[oO][0-7]+)n?"},{begin:e.C_NUMBER_RE+"n?"}],relevance:0},i={className:"subst",begin:"\\$\\{",end:"\\}",keywords:s,contains:[]},t={begin:"html`",end:"",starts:{end:"`",returnEnd:!1,contains:[e.BACKSLASH_ESCAPE,i],subLanguage:"xml"}},c={begin:"css`",end:"",starts:{end:"`",returnEnd:!1,contains:[e.BACKSLASH_ESCAPE,i],subLanguage:"css"}},o={className:"string",begin:"`",end:"`",contains:[e.BACKSLASH_ESCAPE,i]};i.contains=[e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,t,c,o,r,e.REGEXP_MODE];var l=i.contains.concat([e.C_BLOCK_COMMENT_MODE,e.C_LINE_COMMENT_MODE]),d={className:"params",begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,contains:l};return{name:"JavaScript",aliases:["js","jsx","mjs","cjs"],keywords:s,contains:[{className:"meta",relevance:10,begin:/^\s*['"]use (strict|asm)['"]/},{className:"meta",begin:/^#!/,end:/$/},e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,t,c,o,e.C_LINE_COMMENT_MODE,e.COMMENT("/\\*\\*","\\*/",{relevance:0,contains:[{className:"doctag",begin:"@[A-Za-z]+",contains:[{className:"type",begin:"\\{",end:"\\}",relevance:0},{className:"variable",begin:a+"(?=\\s*(-)|$)",endsParent:!0,relevance:0},{begin:/(?=[^\n])\s/,relevance:0}]}]}),e.C_BLOCK_COMMENT_MODE,r,{begin:/[{,\n]\s*/,relevance:0,contains:[{begin:a+"\\s*:",returnBegin:!0,relevance:0,contains:[{className:"attr",begin:a,relevance:0}]}]},{begin:"("+e.RE_STARTERS_RE+"|\\b(case|return|throw)\\b)\\s*",keywords:"return throw case",contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.REGEXP_MODE,{className:"function",begin:"(\\(.*?\\)|"+a+")\\s*=>",returnBegin:!0,end:"\\s*=>",contains:[{className:"params",variants:[{begin:a},{begin:/\(\s*\)/},{begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:s,contains:l}]}]},{begin:/,/,relevance:0},{className:"",begin:/\s/,end:/\s*/,skip:!0},{variants:[{begin:"<>",end:""},{begin:n.begin,end:n.end}],subLanguage:"xml",contains:[{begin:n.begin,end:n.end,skip:!0,contains:["self"]}]}],relevance:0},{className:"function",beginKeywords:"function",end:/\{/,excludeEnd:!0,contains:[e.inherit(e.TITLE_MODE,{begin:a}),d],illegal:/\[|%/},{begin:/\$[(.]/},e.METHOD_GUARD,{className:"class",beginKeywords:"class",end:/[{;=]/,excludeEnd:!0,illegal:/[:"\[\]]/,contains:[{beginKeywords:"extends"},e.UNDERSCORE_TITLE_MODE]},{beginKeywords:"constructor",end:/\{/,excludeEnd:!0},{begin:"(get|set)\\s*(?="+a+"\\()",end:/{/,keywords:"get set",contains:[e.inherit(e.TITLE_MODE,{begin:a}),{begin:/\(\)/},d]}],illegal:/#(?!!)/}}}());hljs.registerLanguage("java",function(){"use strict";return function(e){var a="false synchronized int abstract float private char boolean var static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",n={className:"meta",begin:"@[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",contains:[{begin:/\(/,end:/\)/,contains:["self"]}]};return{name:"Java",aliases:["jsp"],keywords:a,illegal:/<\/|#/,contains:[e.COMMENT("/\\*\\*","\\*/",{relevance:0,contains:[{begin:/\w+@/,relevance:0},{className:"doctag",begin:"@[A-Za-z]+"}]}),e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,{className:"class",beginKeywords:"class interface",end:/[{;=]/,excludeEnd:!0,keywords:"class interface",illegal:/[:"\[\]]/,contains:[{beginKeywords:"extends implements"},e.UNDERSCORE_TITLE_MODE]},{beginKeywords:"new throw return else",relevance:0},{className:"function",begin:"([À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*(<[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*(\\s*,\\s*[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*)*>)?\\s+)+"+e.UNDERSCORE_IDENT_RE+"\\s*\\(",returnBegin:!0,end:/[{;=]/,excludeEnd:!0,keywords:a,contains:[{begin:e.UNDERSCORE_IDENT_RE+"\\s*\\(",returnBegin:!0,relevance:0,contains:[e.UNDERSCORE_TITLE_MODE]},{className:"params",begin:/\(/,end:/\)/,keywords:a,relevance:0,contains:[n,e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,e.C_NUMBER_MODE,e.C_BLOCK_COMMENT_MODE]},e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{className:"number",begin:"\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",relevance:0},n]}}}());hljs.registerLanguage("actionscript",function(){"use strict";return function(e){return{name:"ActionScript",aliases:["as"],keywords:{keyword:"as break case catch class const continue default delete do dynamic each else extends final finally for function get if implements import in include instanceof interface internal is namespace native new override package private protected public return set static super switch this throw try typeof use var void while with",literal:"true false null undefined"},contains:[e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.C_NUMBER_MODE,{className:"class",beginKeywords:"package",end:"{",contains:[e.TITLE_MODE]},{className:"class",beginKeywords:"class interface",end:"{",excludeEnd:!0,contains:[{beginKeywords:"extends implements"},e.TITLE_MODE]},{className:"meta",beginKeywords:"import include",end:";",keywords:{"meta-keyword":"import include"}},{className:"function",beginKeywords:"function",end:"[{;]",excludeEnd:!0,illegal:"\\S",contains:[e.TITLE_MODE,{className:"params",begin:"\\(",end:"\\)",contains:[e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,{className:"rest_arg",begin:"[.]{3}",end:"[a-zA-Z_$][a-zA-Z0-9_$]*",relevance:10}]},{begin:":\\s*([*]|[a-zA-Z_$][a-zA-Z0-9_$]*)"}]},e.METHOD_GUARD],illegal:/#/}}}());hljs.registerLanguage("awk",function(){"use strict";return function(e){return{name:"Awk",keywords:{keyword:"BEGIN END if else while do for in break continue delete next nextfile function func exit|10"},contains:[{className:"variable",variants:[{begin:/\$[\w\d#@][\w\d_]*/},{begin:/\$\{(.*?)}/}]},{className:"string",contains:[e.BACKSLASH_ESCAPE],variants:[{begin:/(u|b)?r?'''/,end:/'''/,relevance:10},{begin:/(u|b)?r?"""/,end:/"""/,relevance:10},{begin:/(u|r|ur)'/,end:/'/,relevance:10},{begin:/(u|r|ur)"/,end:/"/,relevance:10},{begin:/(b|br)'/,end:/'/},{begin:/(b|br)"/,end:/"/},e.APOS_STRING_MODE,e.QUOTE_STRING_MODE]},e.REGEXP_MODE,e.HASH_COMMENT_MODE,e.NUMBER_MODE]}}}());hljs.registerLanguage("c-like",function(){"use strict";return function(e){function t(e){return"(?:"+e+")?"}var n="(decltype\\(auto\\)|"+t("[a-zA-Z_]\\w*::")+"[a-zA-Z_]\\w*"+t("<.*?>")+")",r={className:"keyword",begin:"\\b[a-z\\d_]*_t\\b"},a={className:"string",variants:[{begin:'(u8?|U|L)?"',end:'"',illegal:"\\n",contains:[e.BACKSLASH_ESCAPE]},{begin:"(u8?|U|L)?'(\\\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4,8}|[0-7]{3}|\\S)|.)",end:"'",illegal:"."},{begin:/(?:u8?|U|L)?R"([^()\\ ]{0,16})\((?:.|\n)*?\)\1"/}]},s={className:"number",variants:[{begin:"\\b(0b[01']+)"},{begin:"(-?)\\b([\\d']+(\\.[\\d']*)?|\\.[\\d']+)(u|U|l|L|ul|UL|f|F|b|B)"},{begin:"(-?)(\\b0[xX][a-fA-F0-9']+|(\\b[\\d']+(\\.[\\d']*)?|\\.[\\d']+)([eE][-+]?[\\d']+)?)"}],relevance:0},i={className:"meta",begin:/#\s*[a-z]+\b/,end:/$/,keywords:{"meta-keyword":"if else elif endif define undef warning error line pragma _Pragma ifdef ifndef include"},contains:[{begin:/\\\n/,relevance:0},e.inherit(a,{className:"meta-string"}),{className:"meta-string",begin:/<.*?>/,end:/$/,illegal:"\\n"},e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},c={className:"title",begin:t("[a-zA-Z_]\\w*::")+e.IDENT_RE,relevance:0},o=t("[a-zA-Z_]\\w*::")+e.IDENT_RE+"\\s*\\(",l={keyword:"int float while private char char8_t char16_t char32_t catch import module export virtual operator sizeof dynamic_cast|10 typedef const_cast|10 const for static_cast|10 union namespace unsigned long volatile static protected bool template mutable if public friend do goto auto void enum else break extern using asm case typeid wchar_t short reinterpret_cast|10 default double register explicit signed typename try this switch continue inline delete alignas alignof constexpr consteval constinit decltype concept co_await co_return co_yield requires noexcept static_assert thread_local restrict final override atomic_bool atomic_char atomic_schar atomic_uchar atomic_short atomic_ushort atomic_int atomic_uint atomic_long atomic_ulong atomic_llong atomic_ullong new throw return and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq",built_in:"std string wstring cin cout cerr clog stdin stdout stderr stringstream istringstream ostringstream auto_ptr deque list queue stack vector map set bitset multiset multimap unordered_set unordered_map unordered_multiset unordered_multimap array shared_ptr abort terminate abs acos asin atan2 atan calloc ceil cosh cos exit exp fabs floor fmod fprintf fputs free frexp fscanf future isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper labs ldexp log10 log malloc realloc memchr memcmp memcpy memset modf pow printf putchar puts scanf sinh sin snprintf sprintf sqrt sscanf strcat strchr strcmp strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr tanh tan vfprintf vprintf vsprintf endl initializer_list unique_ptr _Bool complex _Complex imaginary _Imaginary",literal:"true false nullptr NULL"},d=[r,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,s,a],_={variants:[{begin:/=/,end:/;/},{begin:/\(/,end:/\)/},{beginKeywords:"new throw return else",end:/;/}],keywords:l,contains:d.concat([{begin:/\(/,end:/\)/,keywords:l,contains:d.concat(["self"]),relevance:0}]),relevance:0},u={className:"function",begin:"("+n+"[\\*&\\s]+)+"+o,returnBegin:!0,end:/[{;=]/,excludeEnd:!0,keywords:l,illegal:/[^\w\s\*&:<>]/,contains:[{begin:"decltype\\(auto\\)",keywords:l,relevance:0},{begin:o,returnBegin:!0,contains:[c],relevance:0},{className:"params",begin:/\(/,end:/\)/,keywords:l,relevance:0,contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,s,r,{begin:/\(/,end:/\)/,keywords:l,relevance:0,contains:["self",e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,s,r]}]},r,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,i]};return{aliases:["c","cc","h","c++","h++","hpp","hh","hxx","cxx"],keywords:l,disableAutodetect:!0,illegal:"",keywords:l,contains:["self",r]},{begin:e.IDENT_RE+"::",keywords:l},{className:"class",beginKeywords:"class struct",end:/[{;:]/,contains:[{begin://,contains:["self"]},e.TITLE_MODE]}]),exports:{preprocessor:i,strings:a,keywords:l}}}}());hljs.registerLanguage("cpp",function(){"use strict";return function(e){var t=e.getLanguage("c-like").rawDefinition();return t.disableAutodetect=!1,t.name="C++",t.aliases=["cc","c++","h++","hpp","hh","hxx","cxx"],t}}());hljs.registerLanguage("makefile",function(){"use strict";return function(e){var i={className:"variable",variants:[{begin:"\\$\\("+e.UNDERSCORE_IDENT_RE+"\\)",contains:[e.BACKSLASH_ESCAPE]},{begin:/\$[@%",returnBegin:!0,end:"\\s*=>",contains:[{className:"params",variants:[{begin:e.IDENT_RE},{begin:/\(\s*\)/},{begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:n,contains:["self",e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]}]}]}],relevance:0},{className:"function",beginKeywords:"function",end:/[\{;]/,excludeEnd:!0,keywords:n,contains:["self",e.inherit(e.TITLE_MODE,{begin:"[A-Za-z$_][0-9A-Za-z$_]*"}),t],illegal:/%/,relevance:0},{beginKeywords:"constructor",end:/[\{;]/,excludeEnd:!0,contains:["self",t]},{begin:/module\./,keywords:{built_in:"module"},relevance:0},{beginKeywords:"module",end:/\{/,excludeEnd:!0},{beginKeywords:"interface",end:/\{/,excludeEnd:!0,keywords:"interface extends"},{begin:/\$[(.]/},{begin:"\\."+e.IDENT_RE,relevance:0},r,a]}}}());hljs.registerLanguage("bnf",function(){"use strict";return function(n){return{name:"Backus–Naur Form",contains:[{className:"attribute",begin://},{begin:/::=/,end:/$/,contains:[{begin://},n.C_LINE_COMMENT_MODE,n.C_BLOCK_COMMENT_MODE,n.APOS_STRING_MODE,n.QUOTE_STRING_MODE]}]}}}());hljs.registerLanguage("powershell",function(){"use strict";return function(e){var n={keyword:"if else foreach return do while until elseif begin for trap data dynamicparam end break throw param continue finally in switch exit filter try process catch hidden static parameter",built_in:"ac asnp cat cd CFS chdir clc clear clhy cli clp cls clv cnsn compare copy cp cpi cpp curl cvpa dbp del diff dir dnsn ebp echo|0 epal epcsv epsn erase etsn exsn fc fhx fl ft fw gal gbp gc gcb gci gcm gcs gdr gerr ghy gi gin gjb gl gm gmo gp gps gpv group gsn gsnp gsv gtz gu gv gwmi h history icm iex ihy ii ipal ipcsv ipmo ipsn irm ise iwmi iwr kill lp ls man md measure mi mount move mp mv nal ndr ni nmo npssc nsn nv ogv oh popd ps pushd pwd r rbp rcjb rcsn rd rdr ren ri rjb rm rmdir rmo rni rnp rp rsn rsnp rujb rv rvpa rwmi sajb sal saps sasv sbp sc scb select set shcm si sl sleep sls sort sp spjb spps spsv start stz sujb sv swmi tee trcm type wget where wjb write"},s={begin:"`[\\s\\S]",relevance:0},i={className:"variable",variants:[{begin:/\$\B/},{className:"keyword",begin:/\$this/},{begin:/\$[\w\d][\w\d_:]*/}]},a={className:"string",variants:[{begin:/"/,end:/"/},{begin:/@"/,end:/^"@/}],contains:[s,i,{className:"variable",begin:/\$[A-z]/,end:/[^A-z]/}]},t={className:"string",variants:[{begin:/'/,end:/'/},{begin:/@'/,end:/^'@/}]},r=e.inherit(e.COMMENT(null,null),{variants:[{begin:/#/,end:/$/},{begin:/<#/,end:/#>/}],contains:[{className:"doctag",variants:[{begin:/\.(synopsis|description|example|inputs|outputs|notes|link|component|role|functionality)/},{begin:/\.(parameter|forwardhelptargetname|forwardhelpcategory|remotehelprunspace|externalhelp)\s+\S+/}]}]}),c={className:"class",beginKeywords:"class enum",end:/\s*[{]/,excludeEnd:!0,relevance:0,contains:[e.TITLE_MODE]},l={className:"function",begin:/function\s+/,end:/\s*\{|$/,excludeEnd:!0,returnBegin:!0,relevance:0,contains:[{begin:"function",relevance:0,className:"keyword"},{className:"title",begin:/\w[\w\d]*((-)[\w\d]+)*/,relevance:0},{begin:/\(/,end:/\)/,className:"params",relevance:0,contains:[i]}]},o={begin:/using\s/,end:/$/,returnBegin:!0,contains:[a,t,{className:"keyword",begin:/(using|assembly|command|module|namespace|type)/}]},p={className:"function",begin:/\[.*\]\s*[\w]+[ ]??\(/,end:/$/,returnBegin:!0,relevance:0,contains:[{className:"keyword",begin:"(".concat(n.keyword.toString().replace(/\s/g,"|"),")\\b"),endsParent:!0,relevance:0},e.inherit(e.TITLE_MODE,{endsParent:!0})]},g=[p,r,s,e.NUMBER_MODE,a,t,{className:"built_in",variants:[{begin:"(Add|Clear|Close|Copy|Enter|Exit|Find|Format|Get|Hide|Join|Lock|Move|New|Open|Optimize|Pop|Push|Redo|Remove|Rename|Reset|Resize|Search|Select|Set|Show|Skip|Split|Step|Switch|Undo|Unlock|Watch|Backup|Checkpoint|Compare|Compress|Convert|ConvertFrom|ConvertTo|Dismount|Edit|Expand|Export|Group|Import|Initialize|Limit|Merge|New|Out|Publish|Restore|Save|Sync|Unpublish|Update|Approve|Assert|Complete|Confirm|Deny|Disable|Enable|Install|Invoke|Register|Request|Restart|Resume|Start|Stop|Submit|Suspend|Uninstall|Unregister|Wait|Debug|Measure|Ping|Repair|Resolve|Test|Trace|Connect|Disconnect|Read|Receive|Send|Write|Block|Grant|Protect|Revoke|Unblock|Unprotect|Use|ForEach|Sort|Tee|Where)+(-)[\\w\\d]+"}]},i,{className:"literal",begin:/\$(null|true|false)\b/},{className:"selector-tag",begin:/\@\B/,relevance:0}],m={begin:/\[/,end:/\]/,excludeBegin:!0,excludeEnd:!0,relevance:0,contains:[].concat("self",g,{begin:"(string|char|byte|int|long|bool|decimal|single|double|DateTime|xml|array|hashtable|void)",className:"built_in",relevance:0},{className:"type",begin:/[\.\w\d]+/,relevance:0})};return p.contains.unshift(m),{name:"PowerShell",aliases:["ps","ps1"],lexemes:/-?[A-z\.\-]+\b/,case_insensitive:!0,keywords:n,contains:g.concat(c,l,o,{variants:[{className:"operator",begin:"(-and|-as|-band|-bnot|-bor|-bxor|-casesensitive|-ccontains|-ceq|-cge|-cgt|-cle|-clike|-clt|-cmatch|-cne|-cnotcontains|-cnotlike|-cnotmatch|-contains|-creplace|-csplit|-eq|-exact|-f|-file|-ge|-gt|-icontains|-ieq|-ige|-igt|-ile|-ilike|-ilt|-imatch|-in|-ine|-inotcontains|-inotlike|-inotmatch|-ireplace|-is|-isnot|-isplit|-join|-le|-like|-lt|-match|-ne|-not|-notcontains|-notin|-notlike|-notmatch|-or|-regex|-replace|-shl|-shr|-split|-wildcard|-xor)\\b"},{className:"literal",begin:/(-)[\w\d]+/,relevance:0}]},m)}}}());hljs.registerLanguage("http",function(){"use strict";return function(e){var n="HTTP/[0-9\\.]+";return{name:"HTTP",aliases:["https"],illegal:"\\S",contains:[{begin:"^"+n,end:"$",contains:[{className:"number",begin:"\\b\\d{3}\\b"}]},{begin:"^[A-Z]+ (.*?) "+n+"$",returnBegin:!0,end:"$",contains:[{className:"string",begin:" ",end:" ",excludeBegin:!0,excludeEnd:!0},{begin:n},{className:"keyword",begin:"[A-Z]+"}]},{className:"attribute",begin:"^\\w",end:": ",excludeEnd:!0,illegal:"\\n|\\s|=",starts:{end:"$",relevance:0}},{begin:"\\n\\n",starts:{subLanguage:[],endsWithParent:!0}}]}}}());hljs.registerLanguage("glsl",function(){"use strict";return function(e){return{name:"GLSL",keywords:{keyword:"break continue discard do else for if return while switch case default attribute binding buffer ccw centroid centroid varying coherent column_major const cw depth_any depth_greater depth_less depth_unchanged early_fragment_tests equal_spacing flat fractional_even_spacing fractional_odd_spacing highp in index inout invariant invocations isolines layout line_strip lines lines_adjacency local_size_x local_size_y local_size_z location lowp max_vertices mediump noperspective offset origin_upper_left out packed patch pixel_center_integer point_mode points precise precision quads r11f_g11f_b10f r16 r16_snorm r16f r16i r16ui r32f r32i r32ui r8 r8_snorm r8i r8ui readonly restrict rg16 rg16_snorm rg16f rg16i rg16ui rg32f rg32i rg32ui rg8 rg8_snorm rg8i rg8ui rgb10_a2 rgb10_a2ui rgba16 rgba16_snorm rgba16f rgba16i rgba16ui rgba32f rgba32i rgba32ui rgba8 rgba8_snorm rgba8i rgba8ui row_major sample shared smooth std140 std430 stream triangle_strip triangles triangles_adjacency uniform varying vertices volatile writeonly",type:"atomic_uint bool bvec2 bvec3 bvec4 dmat2 dmat2x2 dmat2x3 dmat2x4 dmat3 dmat3x2 dmat3x3 dmat3x4 dmat4 dmat4x2 dmat4x3 dmat4x4 double dvec2 dvec3 dvec4 float iimage1D iimage1DArray iimage2D iimage2DArray iimage2DMS iimage2DMSArray iimage2DRect iimage3D iimageBuffer iimageCube iimageCubeArray image1D image1DArray image2D image2DArray image2DMS image2DMSArray image2DRect image3D imageBuffer imageCube imageCubeArray int isampler1D isampler1DArray isampler2D isampler2DArray isampler2DMS isampler2DMSArray isampler2DRect isampler3D isamplerBuffer isamplerCube isamplerCubeArray ivec2 ivec3 ivec4 mat2 mat2x2 mat2x3 mat2x4 mat3 mat3x2 mat3x3 mat3x4 mat4 mat4x2 mat4x3 mat4x4 sampler1D sampler1DArray sampler1DArrayShadow sampler1DShadow sampler2D sampler2DArray sampler2DArrayShadow sampler2DMS sampler2DMSArray sampler2DRect sampler2DRectShadow sampler2DShadow sampler3D samplerBuffer samplerCube samplerCubeArray samplerCubeArrayShadow samplerCubeShadow image1D uimage1DArray uimage2D uimage2DArray uimage2DMS uimage2DMSArray uimage2DRect uimage3D uimageBuffer uimageCube uimageCubeArray uint usampler1D usampler1DArray usampler2D usampler2DArray usampler2DMS usampler2DMSArray usampler2DRect usampler3D samplerBuffer usamplerCube usamplerCubeArray uvec2 uvec3 uvec4 vec2 vec3 vec4 void",built_in:"gl_MaxAtomicCounterBindings gl_MaxAtomicCounterBufferSize gl_MaxClipDistances gl_MaxClipPlanes gl_MaxCombinedAtomicCounterBuffers gl_MaxCombinedAtomicCounters gl_MaxCombinedImageUniforms gl_MaxCombinedImageUnitsAndFragmentOutputs gl_MaxCombinedTextureImageUnits gl_MaxComputeAtomicCounterBuffers gl_MaxComputeAtomicCounters gl_MaxComputeImageUniforms gl_MaxComputeTextureImageUnits gl_MaxComputeUniformComponents gl_MaxComputeWorkGroupCount gl_MaxComputeWorkGroupSize gl_MaxDrawBuffers gl_MaxFragmentAtomicCounterBuffers gl_MaxFragmentAtomicCounters gl_MaxFragmentImageUniforms gl_MaxFragmentInputComponents gl_MaxFragmentInputVectors gl_MaxFragmentUniformComponents gl_MaxFragmentUniformVectors gl_MaxGeometryAtomicCounterBuffers gl_MaxGeometryAtomicCounters gl_MaxGeometryImageUniforms gl_MaxGeometryInputComponents gl_MaxGeometryOutputComponents gl_MaxGeometryOutputVertices gl_MaxGeometryTextureImageUnits gl_MaxGeometryTotalOutputComponents gl_MaxGeometryUniformComponents gl_MaxGeometryVaryingComponents gl_MaxImageSamples gl_MaxImageUnits gl_MaxLights gl_MaxPatchVertices gl_MaxProgramTexelOffset gl_MaxTessControlAtomicCounterBuffers gl_MaxTessControlAtomicCounters gl_MaxTessControlImageUniforms gl_MaxTessControlInputComponents gl_MaxTessControlOutputComponents gl_MaxTessControlTextureImageUnits gl_MaxTessControlTotalOutputComponents gl_MaxTessControlUniformComponents gl_MaxTessEvaluationAtomicCounterBuffers gl_MaxTessEvaluationAtomicCounters gl_MaxTessEvaluationImageUniforms gl_MaxTessEvaluationInputComponents gl_MaxTessEvaluationOutputComponents gl_MaxTessEvaluationTextureImageUnits gl_MaxTessEvaluationUniformComponents gl_MaxTessGenLevel gl_MaxTessPatchComponents gl_MaxTextureCoords gl_MaxTextureImageUnits gl_MaxTextureUnits gl_MaxVaryingComponents gl_MaxVaryingFloats gl_MaxVaryingVectors gl_MaxVertexAtomicCounterBuffers gl_MaxVertexAtomicCounters gl_MaxVertexAttribs gl_MaxVertexImageUniforms gl_MaxVertexOutputComponents gl_MaxVertexOutputVectors gl_MaxVertexTextureImageUnits gl_MaxVertexUniformComponents gl_MaxVertexUniformVectors gl_MaxViewports gl_MinProgramTexelOffset gl_BackColor gl_BackLightModelProduct gl_BackLightProduct gl_BackMaterial gl_BackSecondaryColor gl_ClipDistance gl_ClipPlane gl_ClipVertex gl_Color gl_DepthRange gl_EyePlaneQ gl_EyePlaneR gl_EyePlaneS gl_EyePlaneT gl_Fog gl_FogCoord gl_FogFragCoord gl_FragColor gl_FragCoord gl_FragData gl_FragDepth gl_FrontColor gl_FrontFacing gl_FrontLightModelProduct gl_FrontLightProduct gl_FrontMaterial gl_FrontSecondaryColor gl_GlobalInvocationID gl_InstanceID gl_InvocationID gl_Layer gl_LightModel gl_LightSource gl_LocalInvocationID gl_LocalInvocationIndex gl_ModelViewMatrix gl_ModelViewMatrixInverse gl_ModelViewMatrixInverseTranspose gl_ModelViewMatrixTranspose gl_ModelViewProjectionMatrix gl_ModelViewProjectionMatrixInverse gl_ModelViewProjectionMatrixInverseTranspose gl_ModelViewProjectionMatrixTranspose gl_MultiTexCoord0 gl_MultiTexCoord1 gl_MultiTexCoord2 gl_MultiTexCoord3 gl_MultiTexCoord4 gl_MultiTexCoord5 gl_MultiTexCoord6 gl_MultiTexCoord7 gl_Normal gl_NormalMatrix gl_NormalScale gl_NumSamples gl_NumWorkGroups gl_ObjectPlaneQ gl_ObjectPlaneR gl_ObjectPlaneS gl_ObjectPlaneT gl_PatchVerticesIn gl_Point gl_PointCoord gl_PointSize gl_Position gl_PrimitiveID gl_PrimitiveIDIn gl_ProjectionMatrix gl_ProjectionMatrixInverse gl_ProjectionMatrixInverseTranspose gl_ProjectionMatrixTranspose gl_SampleID gl_SampleMask gl_SampleMaskIn gl_SamplePosition gl_SecondaryColor gl_TessCoord gl_TessLevelInner gl_TessLevelOuter gl_TexCoord gl_TextureEnvColor gl_TextureMatrix gl_TextureMatrixInverse gl_TextureMatrixInverseTranspose gl_TextureMatrixTranspose gl_Vertex gl_VertexID gl_ViewportIndex gl_WorkGroupID gl_WorkGroupSize gl_in gl_out EmitStreamVertex EmitVertex EndPrimitive EndStreamPrimitive abs acos acosh all any asin asinh atan atanh atomicAdd atomicAnd atomicCompSwap atomicCounter atomicCounterDecrement atomicCounterIncrement atomicExchange atomicMax atomicMin atomicOr atomicXor barrier bitCount bitfieldExtract bitfieldInsert bitfieldReverse ceil clamp cos cosh cross dFdx dFdy degrees determinant distance dot equal exp exp2 faceforward findLSB findMSB floatBitsToInt floatBitsToUint floor fma fract frexp ftransform fwidth greaterThan greaterThanEqual groupMemoryBarrier imageAtomicAdd imageAtomicAnd imageAtomicCompSwap imageAtomicExchange imageAtomicMax imageAtomicMin imageAtomicOr imageAtomicXor imageLoad imageSize imageStore imulExtended intBitsToFloat interpolateAtCentroid interpolateAtOffset interpolateAtSample inverse inversesqrt isinf isnan ldexp length lessThan lessThanEqual log log2 matrixCompMult max memoryBarrier memoryBarrierAtomicCounter memoryBarrierBuffer memoryBarrierImage memoryBarrierShared min mix mod modf noise1 noise2 noise3 noise4 normalize not notEqual outerProduct packDouble2x32 packHalf2x16 packSnorm2x16 packSnorm4x8 packUnorm2x16 packUnorm4x8 pow radians reflect refract round roundEven shadow1D shadow1DLod shadow1DProj shadow1DProjLod shadow2D shadow2DLod shadow2DProj shadow2DProjLod sign sin sinh smoothstep sqrt step tan tanh texelFetch texelFetchOffset texture texture1D texture1DLod texture1DProj texture1DProjLod texture2D texture2DLod texture2DProj texture2DProjLod texture3D texture3DLod texture3DProj texture3DProjLod textureCube textureCubeLod textureGather textureGatherOffset textureGatherOffsets textureGrad textureGradOffset textureLod textureLodOffset textureOffset textureProj textureProjGrad textureProjGradOffset textureProjLod textureProjLodOffset textureProjOffset textureQueryLevels textureQueryLod textureSize transpose trunc uaddCarry uintBitsToFloat umulExtended unpackDouble2x32 unpackHalf2x16 unpackSnorm2x16 unpackSnorm4x8 unpackUnorm2x16 unpackUnorm4x8 usubBorrow",literal:"true false"},illegal:'"',contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.C_NUMBER_MODE,{className:"meta",begin:"#",end:"$"}]}}}());hljs.registerLanguage("cmake",function(){"use strict";return function(e){return{name:"CMake",aliases:["cmake.in"],case_insensitive:!0,keywords:{keyword:"break cmake_host_system_information cmake_minimum_required cmake_parse_arguments cmake_policy configure_file continue elseif else endforeach endfunction endif endmacro endwhile execute_process file find_file find_library find_package find_path find_program foreach function get_cmake_property get_directory_property get_filename_component get_property if include include_guard list macro mark_as_advanced math message option return separate_arguments set_directory_properties set_property set site_name string unset variable_watch while add_compile_definitions add_compile_options add_custom_command add_custom_target add_definitions add_dependencies add_executable add_library add_link_options add_subdirectory add_test aux_source_directory build_command create_test_sourcelist define_property enable_language enable_testing export fltk_wrap_ui get_source_file_property get_target_property get_test_property include_directories include_external_msproject include_regular_expression install link_directories link_libraries load_cache project qt_wrap_cpp qt_wrap_ui remove_definitions set_source_files_properties set_target_properties set_tests_properties source_group target_compile_definitions target_compile_features target_compile_options target_include_directories target_link_directories target_link_libraries target_link_options target_sources try_compile try_run ctest_build ctest_configure ctest_coverage ctest_empty_binary_directory ctest_memcheck ctest_read_custom_files ctest_run_script ctest_sleep ctest_start ctest_submit ctest_test ctest_update ctest_upload build_name exec_program export_library_dependencies install_files install_programs install_targets load_command make_directory output_required_files remove subdir_depends subdirs use_mangled_mesa utility_source variable_requires write_file qt5_use_modules qt5_use_package qt5_wrap_cpp on off true false and or not command policy target test exists is_newer_than is_directory is_symlink is_absolute matches less greater equal less_equal greater_equal strless strgreater strequal strless_equal strgreater_equal version_less version_greater version_equal version_less_equal version_greater_equal in_list defined"},contains:[{className:"variable",begin:"\\${",end:"}"},e.HASH_COMMENT_MODE,e.QUOTE_STRING_MODE,e.NUMBER_MODE]}}}());hljs.registerLanguage("bash",function(){"use strict";return function(e){const s={};Object.assign(s,{className:"variable",variants:[{begin:/\$[\w\d#@][\w\d_]*/},{begin:/\$\{/,end:/\}/,contains:[{begin:/:-/,contains:[s]}]}]});const n={className:"subst",begin:/\$\(/,end:/\)/,contains:[e.BACKSLASH_ESCAPE]},t={className:"string",begin:/"/,end:/"/,contains:[e.BACKSLASH_ESCAPE,s,n]};n.contains.push(t);const a={begin:/\$\(\(/,end:/\)\)/,contains:[{begin:/\d+#[0-9a-f]+/,className:"number"},e.NUMBER_MODE,s]};return{name:"Bash",aliases:["sh","zsh"],lexemes:/\b-?[a-z\._]+\b/,keywords:{keyword:"if then else elif fi for while in do done case esac function",literal:"true false",built_in:"break cd continue eval exec exit export getopts hash pwd readonly return shift test times trap umask unset alias bind builtin caller command declare echo enable help let local logout mapfile printf read readarray source type typeset ulimit unalias set shopt autoload bg bindkey bye cap chdir clone comparguments compcall compctl compdescribe compfiles compgroups compquote comptags comptry compvalues dirs disable disown echotc echoti emulate fc fg float functions getcap getln history integer jobs kill limit log noglob popd print pushd pushln rehash sched setcap setopt stat suspend ttyctl unfunction unhash unlimit unsetopt vared wait whence where which zcompile zformat zftp zle zmodload zparseopts zprof zpty zregexparse zsocket zstyle ztcp",_:"-ne -eq -lt -gt -f -d -e -s -l -a"},contains:[{className:"meta",begin:/^#![^\n]+sh\s*$/,relevance:10},{className:"function",begin:/\w[\w\d_]*\s*\(\s*\)\s*\{/,returnBegin:!0,contains:[e.inherit(e.TITLE_MODE,{begin:/\w[\w\d_]*/})],relevance:0},a,e.HASH_COMMENT_MODE,t,{className:"",begin:/\\"/},{className:"string",begin:/'/,end:/'/},s]}}}());hljs.registerLanguage("shell",function(){"use strict";return function(s){return{name:"Shell Session",aliases:["console"],contains:[{className:"meta",begin:"^\\s{0,3}[/\\w\\d\\[\\]()@-]*[>%$#]",starts:{end:"$",subLanguage:"bash"}}]}}}());hljs.registerLanguage("plaintext",function(){"use strict";return function(t){return{name:"Plain text",aliases:["text","txt"],disableAutodetect:!0}}}());hljs.registerLanguage("python",function(){"use strict";return function(e){var n={keyword:"and elif is global as in if from raise for except finally print import pass return exec else break not with class assert yield try while continue del or def lambda async await nonlocal|10",built_in:"Ellipsis NotImplemented",literal:"False None True"},a={className:"meta",begin:/^(>>>|\.\.\.) /},i={className:"subst",begin:/\{/,end:/\}/,keywords:n,illegal:/#/},s={begin:/\{\{/,relevance:0},r={className:"string",contains:[e.BACKSLASH_ESCAPE],variants:[{begin:/(u|b)?r?'''/,end:/'''/,contains:[e.BACKSLASH_ESCAPE,a],relevance:10},{begin:/(u|b)?r?"""/,end:/"""/,contains:[e.BACKSLASH_ESCAPE,a],relevance:10},{begin:/(fr|rf|f)'''/,end:/'''/,contains:[e.BACKSLASH_ESCAPE,a,s,i]},{begin:/(fr|rf|f)"""/,end:/"""/,contains:[e.BACKSLASH_ESCAPE,a,s,i]},{begin:/(u|r|ur)'/,end:/'/,relevance:10},{begin:/(u|r|ur)"/,end:/"/,relevance:10},{begin:/(b|br)'/,end:/'/},{begin:/(b|br)"/,end:/"/},{begin:/(fr|rf|f)'/,end:/'/,contains:[e.BACKSLASH_ESCAPE,s,i]},{begin:/(fr|rf|f)"/,end:/"/,contains:[e.BACKSLASH_ESCAPE,s,i]},e.APOS_STRING_MODE,e.QUOTE_STRING_MODE]},l={className:"number",relevance:0,variants:[{begin:e.BINARY_NUMBER_RE+"[lLjJ]?"},{begin:"\\b(0o[0-7]+)[lLjJ]?"},{begin:e.C_NUMBER_RE+"[lLjJ]?"}]},t={className:"params",variants:[{begin:/\(\s*\)/,skip:!0,className:null},{begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,contains:["self",a,l,r,e.HASH_COMMENT_MODE]}]};return i.contains=[r,l,a],{name:"Python",aliases:["py","gyp","ipython"],keywords:n,illegal:/(<\/|->|\?)|=>/,contains:[a,l,{beginKeywords:"if",relevance:0},r,e.HASH_COMMENT_MODE,{variants:[{className:"function",beginKeywords:"def"},{className:"class",beginKeywords:"class"}],end:/:/,illegal:/[${=;\n,]/,contains:[e.UNDERSCORE_TITLE_MODE,t,{begin:/->/,endsWithParent:!0,keywords:"None"}]},{className:"meta",begin:/^[\t ]*@/,end:/$/},{begin:/\b(print|exec)\(/}]}}}());hljs.registerLanguage("json",function(){"use strict";return function(n){var e={literal:"true false null"},i=[n.C_LINE_COMMENT_MODE,n.C_BLOCK_COMMENT_MODE],t=[n.QUOTE_STRING_MODE,n.C_NUMBER_MODE],a={end:",",endsWithParent:!0,excludeEnd:!0,contains:t,keywords:e},l={begin:"{",end:"}",contains:[{className:"attr",begin:/"/,end:/"/,contains:[n.BACKSLASH_ESCAPE],illegal:"\\n"},n.inherit(a,{begin:/:/})].concat(i),illegal:"\\S"},s={begin:"\\[",end:"\\]",contains:[n.inherit(a)],illegal:"\\S"};return t.push(l,s),i.forEach((function(n){t.push(n)})),{name:"JSON",contains:t,keywords:e,illegal:"\\S"}}}());hljs.registerLanguage("php",function(){"use strict";return function(e){var r={begin:"\\$+[a-zA-Z_-ÿ][a-zA-Z0-9_-ÿ]*"},t={className:"meta",variants:[{begin:/<\?php/,relevance:10},{begin:/<\?[=]?/},{begin:/\?>/}]},a={className:"string",contains:[e.BACKSLASH_ESCAPE,t],variants:[{begin:'b"',end:'"'},{begin:"b'",end:"'"},e.inherit(e.APOS_STRING_MODE,{illegal:null}),e.inherit(e.QUOTE_STRING_MODE,{illegal:null})]},n={variants:[e.BINARY_NUMBER_MODE,e.C_NUMBER_MODE]},i={keyword:"__CLASS__ __DIR__ __FILE__ __FUNCTION__ __LINE__ __METHOD__ __NAMESPACE__ __TRAIT__ die echo exit include include_once print require require_once array abstract and as binary bool boolean break callable case catch class clone const continue declare default do double else elseif empty enddeclare endfor endforeach endif endswitch endwhile eval extends final finally float for foreach from global goto if implements instanceof insteadof int integer interface isset iterable list new object or private protected public real return string switch throw trait try unset use var void while xor yield",literal:"false null true",built_in:"Error|0 AppendIterator ArgumentCountError ArithmeticError ArrayIterator ArrayObject AssertionError BadFunctionCallException BadMethodCallException CachingIterator CallbackFilterIterator CompileError Countable DirectoryIterator DivisionByZeroError DomainException EmptyIterator ErrorException Exception FilesystemIterator FilterIterator GlobIterator InfiniteIterator InvalidArgumentException IteratorIterator LengthException LimitIterator LogicException MultipleIterator NoRewindIterator OutOfBoundsException OutOfRangeException OuterIterator OverflowException ParentIterator ParseError RangeException RecursiveArrayIterator RecursiveCachingIterator RecursiveCallbackFilterIterator RecursiveDirectoryIterator RecursiveFilterIterator RecursiveIterator RecursiveIteratorIterator RecursiveRegexIterator RecursiveTreeIterator RegexIterator RuntimeException SeekableIterator SplDoublyLinkedList SplFileInfo SplFileObject SplFixedArray SplHeap SplMaxHeap SplMinHeap SplObjectStorage SplObserver SplObserver SplPriorityQueue SplQueue SplStack SplSubject SplSubject SplTempFileObject TypeError UnderflowException UnexpectedValueException ArrayAccess Closure Generator Iterator IteratorAggregate Serializable Throwable Traversable WeakReference Directory __PHP_Incomplete_Class parent php_user_filter self static stdClass"};return{aliases:["php","php3","php4","php5","php6","php7"],case_insensitive:!0,keywords:i,contains:[e.HASH_COMMENT_MODE,e.COMMENT("//","$",{contains:[t]}),e.COMMENT("/\\*","\\*/",{contains:[{className:"doctag",begin:"@[A-Za-z]+"}]}),e.COMMENT("__halt_compiler.+?;",!1,{endsWithParent:!0,keywords:"__halt_compiler",lexemes:e.UNDERSCORE_IDENT_RE}),{className:"string",begin:/<<<['"]?\w+['"]?$/,end:/^\w+;?$/,contains:[e.BACKSLASH_ESCAPE,{className:"subst",variants:[{begin:/\$\w+/},{begin:/\{\$/,end:/\}/}]}]},t,{className:"keyword",begin:/\$this\b/},r,{begin:/(::|->)+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/},{className:"function",beginKeywords:"fn function",end:/[;{]/,excludeEnd:!0,illegal:"[$%\\[]",contains:[e.UNDERSCORE_TITLE_MODE,{className:"params",begin:"\\(",end:"\\)",excludeBegin:!0,excludeEnd:!0,keywords:i,contains:["self",r,e.C_BLOCK_COMMENT_MODE,a,n]}]},{className:"class",beginKeywords:"class interface",end:"{",excludeEnd:!0,illegal:/[:\(\$"]/,contains:[{beginKeywords:"extends implements"},e.UNDERSCORE_TITLE_MODE]},{beginKeywords:"namespace",end:";",illegal:/[\.']/,contains:[e.UNDERSCORE_TITLE_MODE]},{beginKeywords:"use",end:";",contains:[e.UNDERSCORE_TITLE_MODE]},{begin:"=>"},a,n]}}}());hljs.registerLanguage("php-template",function(){"use strict";return function(n){return{name:"PHP template",subLanguage:"xml",contains:[{begin:/<\?(php|=)?/,end:/\?>/,subLanguage:"php",contains:[{begin:"/\\*",end:"\\*/",skip:!0},{begin:'b"',end:'"',skip:!0},{begin:"b'",end:"'",skip:!0},n.inherit(n.APOS_STRING_MODE,{illegal:null,className:null,contains:null,skip:!0}),n.inherit(n.QUOTE_STRING_MODE,{illegal:null,className:null,contains:null,skip:!0})]}]}}}());hljs.registerLanguage("ini",function(){"use strict";return function(e){var n={className:"number",relevance:0,variants:[{begin:/([\+\-]+)?[\d]+_[\d_]+/},{begin:e.NUMBER_RE}]},a=e.COMMENT();a.variants=[{begin:/;/,end:/$/},{begin:/#/,end:/$/}];var s={className:"variable",variants:[{begin:/\$[\w\d"][\w\d_]*/},{begin:/\$\{(.*?)}/}]},i={className:"literal",begin:/\bon|off|true|false|yes|no\b/},t={className:"string",contains:[e.BACKSLASH_ESCAPE],variants:[{begin:"'''",end:"'''",relevance:10},{begin:'"""',end:'"""',relevance:10},{begin:'"',end:'"'},{begin:"'",end:"'"}]};return{name:"TOML, also INI",aliases:["toml"],case_insensitive:!0,illegal:/\S/,contains:[a,{className:"section",begin:/\[+/,end:/\]+/},{begin:/^[a-z0-9\[\]_\.-]+(?=\s*=\s*)/,className:"attr",starts:{end:/$/,contains:[a,{begin:/\[/,end:/\]/,contains:[a,i,s,t,n,"self"],relevance:0},i,s,t,n]}}]}}}());hljs.registerLanguage("haskell",function(){"use strict";return function(e){var n={variants:[e.COMMENT("--","$"),e.COMMENT("{-","-}",{contains:["self"]})]},i={className:"meta",begin:"{-#",end:"#-}"},a={className:"meta",begin:"^#",end:"$"},s={className:"type",begin:"\\b[A-Z][\\w']*",relevance:0},l={begin:"\\(",end:"\\)",illegal:'"',contains:[i,a,{className:"type",begin:"\\b[A-Z][\\w]*(\\((\\.\\.|,|\\w+)\\))?"},e.inherit(e.TITLE_MODE,{begin:"[_a-z][\\w']*"}),n]};return{name:"Haskell",aliases:["hs"],keywords:"let in if then else case of where do module import hiding qualified type data newtype deriving class instance as default infix infixl infixr foreign export ccall stdcall cplusplus jvm dotnet safe unsafe family forall mdo proc rec",contains:[{beginKeywords:"module",end:"where",keywords:"module where",contains:[l,n],illegal:"\\W\\.|;"},{begin:"\\bimport\\b",end:"$",keywords:"import qualified as hiding",contains:[l,n],illegal:"\\W\\.|;"},{className:"class",begin:"^(\\s*)?(class|instance)\\b",end:"where",keywords:"class family instance where",contains:[s,l,n]},{className:"class",begin:"\\b(data|(new)?type)\\b",end:"$",keywords:"data family type newtype deriving",contains:[i,s,l,{begin:"{",end:"}",contains:l.contains},n]},{beginKeywords:"default",end:"$",contains:[s,l,n]},{beginKeywords:"infix infixl infixr",end:"$",contains:[e.C_NUMBER_MODE,n]},{begin:"\\bforeign\\b",end:"$",keywords:"foreign import export ccall stdcall cplusplus jvm dotnet safe unsafe",contains:[s,e.QUOTE_STRING_MODE,n]},{className:"meta",begin:"#!\\/usr\\/bin\\/env runhaskell",end:"$"},i,a,e.QUOTE_STRING_MODE,e.C_NUMBER_MODE,s,e.inherit(e.TITLE_MODE,{begin:"^[_a-z][\\w']*"}),n,{begin:"->|<-"}]}}}());hljs.registerLanguage("fsharp",function(){"use strict";return function(e){var n={begin:"<",end:">",contains:[e.inherit(e.TITLE_MODE,{begin:/'[a-zA-Z0-9_]+/})]};return{name:"F#",aliases:["fs"],keywords:"abstract and as assert base begin class default delegate do done downcast downto elif else end exception extern false finally for fun function global if in inherit inline interface internal lazy let match member module mutable namespace new null of open or override private public rec return sig static struct then to true try type upcast use val void when while with yield",illegal:/\/\*/,contains:[{className:"keyword",begin:/\b(yield|return|let|do)!/},{className:"string",begin:'@"',end:'"',contains:[{begin:'""'}]},{className:"string",begin:'"""',end:'"""'},e.COMMENT("\\(\\*","\\*\\)"),{className:"class",beginKeywords:"type",end:"\\(|=|$",excludeEnd:!0,contains:[e.UNDERSCORE_TITLE_MODE,n]},{className:"meta",begin:"\\[<",end:">\\]",relevance:10},{className:"symbol",begin:"\\B('[A-Za-z])\\b",contains:[e.BACKSLASH_ESCAPE]},e.C_LINE_COMMENT_MODE,e.inherit(e.QUOTE_STRING_MODE,{illegal:null}),e.C_NUMBER_MODE]}}}());hljs.registerLanguage("verilog",function(){"use strict";return function(e){return{name:"Verilog",aliases:["v","sv","svh"],case_insensitive:!1,keywords:{keyword:"accept_on alias always always_comb always_ff always_latch and assert assign assume automatic before begin bind bins binsof bit break buf|0 bufif0 bufif1 byte case casex casez cell chandle checker class clocking cmos config const constraint context continue cover covergroup coverpoint cross deassign default defparam design disable dist do edge else end endcase endchecker endclass endclocking endconfig endfunction endgenerate endgroup endinterface endmodule endpackage endprimitive endprogram endproperty endspecify endsequence endtable endtask enum event eventually expect export extends extern final first_match for force foreach forever fork forkjoin function generate|5 genvar global highz0 highz1 if iff ifnone ignore_bins illegal_bins implements implies import incdir include initial inout input inside instance int integer interconnect interface intersect join join_any join_none large let liblist library local localparam logic longint macromodule matches medium modport module nand negedge nettype new nexttime nmos nor noshowcancelled not notif0 notif1 or output package packed parameter pmos posedge primitive priority program property protected pull0 pull1 pulldown pullup pulsestyle_ondetect pulsestyle_onevent pure rand randc randcase randsequence rcmos real realtime ref reg reject_on release repeat restrict return rnmos rpmos rtran rtranif0 rtranif1 s_always s_eventually s_nexttime s_until s_until_with scalared sequence shortint shortreal showcancelled signed small soft solve specify specparam static string strong strong0 strong1 struct super supply0 supply1 sync_accept_on sync_reject_on table tagged task this throughout time timeprecision timeunit tran tranif0 tranif1 tri tri0 tri1 triand trior trireg type typedef union unique unique0 unsigned until until_with untyped use uwire var vectored virtual void wait wait_order wand weak weak0 weak1 while wildcard wire with within wor xnor xor",literal:"null",built_in:"$finish $stop $exit $fatal $error $warning $info $realtime $time $printtimescale $bitstoreal $bitstoshortreal $itor $signed $cast $bits $stime $timeformat $realtobits $shortrealtobits $rtoi $unsigned $asserton $assertkill $assertpasson $assertfailon $assertnonvacuouson $assertoff $assertcontrol $assertpassoff $assertfailoff $assertvacuousoff $isunbounded $sampled $fell $changed $past_gclk $fell_gclk $changed_gclk $rising_gclk $steady_gclk $coverage_control $coverage_get $coverage_save $set_coverage_db_name $rose $stable $past $rose_gclk $stable_gclk $future_gclk $falling_gclk $changing_gclk $display $coverage_get_max $coverage_merge $get_coverage $load_coverage_db $typename $unpacked_dimensions $left $low $increment $clog2 $ln $log10 $exp $sqrt $pow $floor $ceil $sin $cos $tan $countbits $onehot $isunknown $fatal $warning $dimensions $right $high $size $asin $acos $atan $atan2 $hypot $sinh $cosh $tanh $asinh $acosh $atanh $countones $onehot0 $error $info $random $dist_chi_square $dist_erlang $dist_exponential $dist_normal $dist_poisson $dist_t $dist_uniform $q_initialize $q_remove $q_exam $async$and$array $async$nand$array $async$or$array $async$nor$array $sync$and$array $sync$nand$array $sync$or$array $sync$nor$array $q_add $q_full $psprintf $async$and$plane $async$nand$plane $async$or$plane $async$nor$plane $sync$and$plane $sync$nand$plane $sync$or$plane $sync$nor$plane $system $display $displayb $displayh $displayo $strobe $strobeb $strobeh $strobeo $write $readmemb $readmemh $writememh $value$plusargs $dumpvars $dumpon $dumplimit $dumpports $dumpportson $dumpportslimit $writeb $writeh $writeo $monitor $monitorb $monitorh $monitoro $writememb $dumpfile $dumpoff $dumpall $dumpflush $dumpportsoff $dumpportsall $dumpportsflush $fclose $fdisplay $fdisplayb $fdisplayh $fdisplayo $fstrobe $fstrobeb $fstrobeh $fstrobeo $swrite $swriteb $swriteh $swriteo $fscanf $fread $fseek $fflush $feof $fopen $fwrite $fwriteb $fwriteh $fwriteo $fmonitor $fmonitorb $fmonitorh $fmonitoro $sformat $sformatf $fgetc $ungetc $fgets $sscanf $rewind $ftell $ferror"},lexemes:/[\w\$]+/,contains:[e.C_BLOCK_COMMENT_MODE,e.C_LINE_COMMENT_MODE,e.QUOTE_STRING_MODE,{className:"number",contains:[e.BACKSLASH_ESCAPE],variants:[{begin:"\\b((\\d+'(b|h|o|d|B|H|O|D))[0-9xzXZa-fA-F_]+)"},{begin:"\\B(('(b|h|o|d|B|H|O|D))[0-9xzXZa-fA-F_]+)"},{begin:"\\b([0-9_])+",relevance:0}]},{className:"variable",variants:[{begin:"#\\((?!parameter).+\\)"},{begin:"\\.\\w+",relevance:0}]},{className:"meta",begin:"`",end:"$",keywords:{"meta-keyword":"define __FILE__ __LINE__ begin_keywords celldefine default_nettype define else elsif end_keywords endcelldefine endif ifdef ifndef include line nounconnected_drive pragma resetall timescale unconnected_drive undef undefineall"},relevance:0}]}}}());hljs.registerLanguage("ocaml",function(){"use strict";return function(e){return{name:"OCaml",aliases:["ml"],keywords:{keyword:"and as assert asr begin class constraint do done downto else end exception external for fun function functor if in include inherit! inherit initializer land lazy let lor lsl lsr lxor match method!|10 method mod module mutable new object of open! open or private rec sig struct then to try type val! val virtual when while with parser value",built_in:"array bool bytes char exn|5 float int int32 int64 list lazy_t|5 nativeint|5 string unit in_channel out_channel ref",literal:"true false"},illegal:/\/\/|>>/,lexemes:"[a-z_]\\w*!?",contains:[{className:"literal",begin:"\\[(\\|\\|)?\\]|\\(\\)",relevance:0},e.COMMENT("\\(\\*","\\*\\)",{contains:["self"]}),{className:"symbol",begin:"'[A-Za-z_](?!')[\\w']*"},{className:"type",begin:"`[A-Z][\\w']*"},{className:"type",begin:"\\b[A-Z][\\w']*",relevance:0},{begin:"[a-z_]\\w*'[\\w']*",relevance:0},e.inherit(e.APOS_STRING_MODE,{className:"string",relevance:0}),e.inherit(e.QUOTE_STRING_MODE,{illegal:null}),{className:"number",begin:"\\b(0[xX][a-fA-F0-9_]+[Lln]?|0[oO][0-7_]+[Lln]?|0[bB][01_]+[Lln]?|[0-9][0-9_]*([Lln]|(\\.[0-9_]*)?([eE][-+]?[0-9_]+)?)?)",relevance:0},{begin:/[-=]>/}]}}}());hljs.registerLanguage("d",function(){"use strict";return function(e){var a="((0|[1-9][\\d_]*)|0[bB][01_]+|0[xX]([\\da-fA-F][\\da-fA-F_]*|_[\\da-fA-F][\\da-fA-F_]*))",d="\\\\(['\"\\?\\\\abfnrtv]|u[\\dA-Fa-f]{4}|[0-7]{1,3}|x[\\dA-Fa-f]{2}|U[\\dA-Fa-f]{8})|&[a-zA-Z\\d]{2,};",n={className:"number",begin:"\\b"+a+"(L|u|U|Lu|LU|uL|UL)?",relevance:0},t={className:"number",begin:"\\b(((0[xX](([\\da-fA-F][\\da-fA-F_]*|_[\\da-fA-F][\\da-fA-F_]*)\\.([\\da-fA-F][\\da-fA-F_]*|_[\\da-fA-F][\\da-fA-F_]*)|\\.?([\\da-fA-F][\\da-fA-F_]*|_[\\da-fA-F][\\da-fA-F_]*))[pP][+-]?(0|[1-9][\\d_]*|\\d[\\d_]*|[\\d_]+?\\d))|((0|[1-9][\\d_]*|\\d[\\d_]*|[\\d_]+?\\d)(\\.\\d*|([eE][+-]?(0|[1-9][\\d_]*|\\d[\\d_]*|[\\d_]+?\\d)))|\\d+\\.(0|[1-9][\\d_]*|\\d[\\d_]*|[\\d_]+?\\d)(0|[1-9][\\d_]*|\\d[\\d_]*|[\\d_]+?\\d)|\\.(0|[1-9][\\d_]*)([eE][+-]?(0|[1-9][\\d_]*|\\d[\\d_]*|[\\d_]+?\\d))?))([fF]|L|i|[fF]i|Li)?|"+a+"(i|[fF]i|Li))",relevance:0},_={className:"string",begin:"'("+d+"|.)",end:"'",illegal:"."},r={className:"string",begin:'"',contains:[{begin:d,relevance:0}],end:'"[cwd]?'},i=e.COMMENT("\\/\\+","\\+\\/",{contains:["self"],relevance:10});return{name:"D",lexemes:e.UNDERSCORE_IDENT_RE,keywords:{keyword:"abstract alias align asm assert auto body break byte case cast catch class const continue debug default delete deprecated do else enum export extern final finally for foreach foreach_reverse|10 goto if immutable import in inout int interface invariant is lazy macro mixin module new nothrow out override package pragma private protected public pure ref return scope shared static struct super switch synchronized template this throw try typedef typeid typeof union unittest version void volatile while with __FILE__ __LINE__ __gshared|10 __thread __traits __DATE__ __EOF__ __TIME__ __TIMESTAMP__ __VENDOR__ __VERSION__",built_in:"bool cdouble cent cfloat char creal dchar delegate double dstring float function idouble ifloat ireal long real short string ubyte ucent uint ulong ushort wchar wstring",literal:"false null true"},contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,i,{className:"string",begin:'x"[\\da-fA-F\\s\\n\\r]*"[cwd]?',relevance:10},r,{className:"string",begin:'[rq]"',end:'"[cwd]?',relevance:5},{className:"string",begin:"`",end:"`[cwd]?"},{className:"string",begin:'q"\\{',end:'\\}"'},t,n,_,{className:"meta",begin:"^#!",end:"$",relevance:5},{className:"meta",begin:"#(line)",end:"$",relevance:5},{className:"keyword",begin:"@[a-zA-Z_][a-zA-Z_\\d]*"}]}}}());hljs.registerLanguage("x86asm",function(){"use strict";return function(s){return{name:"Intel x86 Assembly",case_insensitive:!0,lexemes:"[.%]?"+s.IDENT_RE,keywords:{keyword:"lock rep repe repz repne repnz xaquire xrelease bnd nobnd aaa aad aam aas adc add and arpl bb0_reset bb1_reset bound bsf bsr bswap bt btc btr bts call cbw cdq cdqe clc cld cli clts cmc cmp cmpsb cmpsd cmpsq cmpsw cmpxchg cmpxchg486 cmpxchg8b cmpxchg16b cpuid cpu_read cpu_write cqo cwd cwde daa das dec div dmint emms enter equ f2xm1 fabs fadd faddp fbld fbstp fchs fclex fcmovb fcmovbe fcmove fcmovnb fcmovnbe fcmovne fcmovnu fcmovu fcom fcomi fcomip fcomp fcompp fcos fdecstp fdisi fdiv fdivp fdivr fdivrp femms feni ffree ffreep fiadd ficom ficomp fidiv fidivr fild fimul fincstp finit fist fistp fisttp fisub fisubr fld fld1 fldcw fldenv fldl2e fldl2t fldlg2 fldln2 fldpi fldz fmul fmulp fnclex fndisi fneni fninit fnop fnsave fnstcw fnstenv fnstsw fpatan fprem fprem1 fptan frndint frstor fsave fscale fsetpm fsin fsincos fsqrt fst fstcw fstenv fstp fstsw fsub fsubp fsubr fsubrp ftst fucom fucomi fucomip fucomp fucompp fxam fxch fxtract fyl2x fyl2xp1 hlt ibts icebp idiv imul in inc incbin insb insd insw int int01 int1 int03 int3 into invd invpcid invlpg invlpga iret iretd iretq iretw jcxz jecxz jrcxz jmp jmpe lahf lar lds lea leave les lfence lfs lgdt lgs lidt lldt lmsw loadall loadall286 lodsb lodsd lodsq lodsw loop loope loopne loopnz loopz lsl lss ltr mfence monitor mov movd movq movsb movsd movsq movsw movsx movsxd movzx mul mwait neg nop not or out outsb outsd outsw packssdw packsswb packuswb paddb paddd paddsb paddsiw paddsw paddusb paddusw paddw pand pandn pause paveb pavgusb pcmpeqb pcmpeqd pcmpeqw pcmpgtb pcmpgtd pcmpgtw pdistib pf2id pfacc pfadd pfcmpeq pfcmpge pfcmpgt pfmax pfmin pfmul pfrcp pfrcpit1 pfrcpit2 pfrsqit1 pfrsqrt pfsub pfsubr pi2fd pmachriw pmaddwd pmagw pmulhriw pmulhrwa pmulhrwc pmulhw pmullw pmvgezb pmvlzb pmvnzb pmvzb pop popa popad popaw popf popfd popfq popfw por prefetch prefetchw pslld psllq psllw psrad psraw psrld psrlq psrlw psubb psubd psubsb psubsiw psubsw psubusb psubusw psubw punpckhbw punpckhdq punpckhwd punpcklbw punpckldq punpcklwd push pusha pushad pushaw pushf pushfd pushfq pushfw pxor rcl rcr rdshr rdmsr rdpmc rdtsc rdtscp ret retf retn rol ror rdm rsdc rsldt rsm rsts sahf sal salc sar sbb scasb scasd scasq scasw sfence sgdt shl shld shr shrd sidt sldt skinit smi smint smintold smsw stc std sti stosb stosd stosq stosw str sub svdc svldt svts swapgs syscall sysenter sysexit sysret test ud0 ud1 ud2b ud2 ud2a umov verr verw fwait wbinvd wrshr wrmsr xadd xbts xchg xlatb xlat xor cmove cmovz cmovne cmovnz cmova cmovnbe cmovae cmovnb cmovb cmovnae cmovbe cmovna cmovg cmovnle cmovge cmovnl cmovl cmovnge cmovle cmovng cmovc cmovnc cmovo cmovno cmovs cmovns cmovp cmovpe cmovnp cmovpo je jz jne jnz ja jnbe jae jnb jb jnae jbe jna jg jnle jge jnl jl jnge jle jng jc jnc jo jno js jns jpo jnp jpe jp sete setz setne setnz seta setnbe setae setnb setnc setb setnae setcset setbe setna setg setnle setge setnl setl setnge setle setng sets setns seto setno setpe setp setpo setnp addps addss andnps andps cmpeqps cmpeqss cmpleps cmpless cmpltps cmpltss cmpneqps cmpneqss cmpnleps cmpnless cmpnltps cmpnltss cmpordps cmpordss cmpunordps cmpunordss cmpps cmpss comiss cvtpi2ps cvtps2pi cvtsi2ss cvtss2si cvttps2pi cvttss2si divps divss ldmxcsr maxps maxss minps minss movaps movhps movlhps movlps movhlps movmskps movntps movss movups mulps mulss orps rcpps rcpss rsqrtps rsqrtss shufps sqrtps sqrtss stmxcsr subps subss ucomiss unpckhps unpcklps xorps fxrstor fxrstor64 fxsave fxsave64 xgetbv xsetbv xsave xsave64 xsaveopt xsaveopt64 xrstor xrstor64 prefetchnta prefetcht0 prefetcht1 prefetcht2 maskmovq movntq pavgb pavgw pextrw pinsrw pmaxsw pmaxub pminsw pminub pmovmskb pmulhuw psadbw pshufw pf2iw pfnacc pfpnacc pi2fw pswapd maskmovdqu clflush movntdq movnti movntpd movdqa movdqu movdq2q movq2dq paddq pmuludq pshufd pshufhw pshuflw pslldq psrldq psubq punpckhqdq punpcklqdq addpd addsd andnpd andpd cmpeqpd cmpeqsd cmplepd cmplesd cmpltpd cmpltsd cmpneqpd cmpneqsd cmpnlepd cmpnlesd cmpnltpd cmpnltsd cmpordpd cmpordsd cmpunordpd cmpunordsd cmppd comisd cvtdq2pd cvtdq2ps cvtpd2dq cvtpd2pi cvtpd2ps cvtpi2pd cvtps2dq cvtps2pd cvtsd2si cvtsd2ss cvtsi2sd cvtss2sd cvttpd2pi cvttpd2dq cvttps2dq cvttsd2si divpd divsd maxpd maxsd minpd minsd movapd movhpd movlpd movmskpd movupd mulpd mulsd orpd shufpd sqrtpd sqrtsd subpd subsd ucomisd unpckhpd unpcklpd xorpd addsubpd addsubps haddpd haddps hsubpd hsubps lddqu movddup movshdup movsldup clgi stgi vmcall vmclear vmfunc vmlaunch vmload vmmcall vmptrld vmptrst vmread vmresume vmrun vmsave vmwrite vmxoff vmxon invept invvpid pabsb pabsw pabsd palignr phaddw phaddd phaddsw phsubw phsubd phsubsw pmaddubsw pmulhrsw pshufb psignb psignw psignd extrq insertq movntsd movntss lzcnt blendpd blendps blendvpd blendvps dppd dpps extractps insertps movntdqa mpsadbw packusdw pblendvb pblendw pcmpeqq pextrb pextrd pextrq phminposuw pinsrb pinsrd pinsrq pmaxsb pmaxsd pmaxud pmaxuw pminsb pminsd pminud pminuw pmovsxbw pmovsxbd pmovsxbq pmovsxwd pmovsxwq pmovsxdq pmovzxbw pmovzxbd pmovzxbq pmovzxwd pmovzxwq pmovzxdq pmuldq pmulld ptest roundpd roundps roundsd roundss crc32 pcmpestri pcmpestrm pcmpistri pcmpistrm pcmpgtq popcnt getsec pfrcpv pfrsqrtv movbe aesenc aesenclast aesdec aesdeclast aesimc aeskeygenassist vaesenc vaesenclast vaesdec vaesdeclast vaesimc vaeskeygenassist vaddpd vaddps vaddsd vaddss vaddsubpd vaddsubps vandpd vandps vandnpd vandnps vblendpd vblendps vblendvpd vblendvps vbroadcastss vbroadcastsd vbroadcastf128 vcmpeq_ospd vcmpeqpd vcmplt_ospd vcmpltpd vcmple_ospd vcmplepd vcmpunord_qpd vcmpunordpd vcmpneq_uqpd vcmpneqpd vcmpnlt_uspd vcmpnltpd vcmpnle_uspd vcmpnlepd vcmpord_qpd vcmpordpd vcmpeq_uqpd vcmpnge_uspd vcmpngepd vcmpngt_uspd vcmpngtpd vcmpfalse_oqpd vcmpfalsepd vcmpneq_oqpd vcmpge_ospd vcmpgepd vcmpgt_ospd vcmpgtpd vcmptrue_uqpd vcmptruepd vcmplt_oqpd vcmple_oqpd vcmpunord_spd vcmpneq_uspd vcmpnlt_uqpd vcmpnle_uqpd vcmpord_spd vcmpeq_uspd vcmpnge_uqpd vcmpngt_uqpd vcmpfalse_ospd vcmpneq_ospd vcmpge_oqpd vcmpgt_oqpd vcmptrue_uspd vcmppd vcmpeq_osps vcmpeqps vcmplt_osps vcmpltps vcmple_osps vcmpleps vcmpunord_qps vcmpunordps vcmpneq_uqps vcmpneqps vcmpnlt_usps vcmpnltps vcmpnle_usps vcmpnleps vcmpord_qps vcmpordps vcmpeq_uqps vcmpnge_usps vcmpngeps vcmpngt_usps vcmpngtps vcmpfalse_oqps vcmpfalseps vcmpneq_oqps vcmpge_osps vcmpgeps vcmpgt_osps vcmpgtps vcmptrue_uqps vcmptrueps vcmplt_oqps vcmple_oqps vcmpunord_sps vcmpneq_usps vcmpnlt_uqps vcmpnle_uqps vcmpord_sps vcmpeq_usps vcmpnge_uqps vcmpngt_uqps vcmpfalse_osps vcmpneq_osps vcmpge_oqps vcmpgt_oqps vcmptrue_usps vcmpps vcmpeq_ossd vcmpeqsd vcmplt_ossd vcmpltsd vcmple_ossd vcmplesd vcmpunord_qsd vcmpunordsd vcmpneq_uqsd vcmpneqsd vcmpnlt_ussd vcmpnltsd vcmpnle_ussd vcmpnlesd vcmpord_qsd vcmpordsd vcmpeq_uqsd vcmpnge_ussd vcmpngesd vcmpngt_ussd vcmpngtsd vcmpfalse_oqsd vcmpfalsesd vcmpneq_oqsd vcmpge_ossd vcmpgesd vcmpgt_ossd vcmpgtsd vcmptrue_uqsd vcmptruesd vcmplt_oqsd vcmple_oqsd vcmpunord_ssd vcmpneq_ussd vcmpnlt_uqsd vcmpnle_uqsd vcmpord_ssd vcmpeq_ussd vcmpnge_uqsd vcmpngt_uqsd vcmpfalse_ossd vcmpneq_ossd vcmpge_oqsd vcmpgt_oqsd vcmptrue_ussd vcmpsd vcmpeq_osss vcmpeqss vcmplt_osss vcmpltss vcmple_osss vcmpless vcmpunord_qss vcmpunordss vcmpneq_uqss vcmpneqss vcmpnlt_usss vcmpnltss vcmpnle_usss vcmpnless vcmpord_qss vcmpordss vcmpeq_uqss vcmpnge_usss vcmpngess vcmpngt_usss vcmpngtss vcmpfalse_oqss vcmpfalsess vcmpneq_oqss vcmpge_osss vcmpgess vcmpgt_osss vcmpgtss vcmptrue_uqss vcmptruess vcmplt_oqss vcmple_oqss vcmpunord_sss vcmpneq_usss vcmpnlt_uqss vcmpnle_uqss vcmpord_sss vcmpeq_usss vcmpnge_uqss vcmpngt_uqss vcmpfalse_osss vcmpneq_osss vcmpge_oqss vcmpgt_oqss vcmptrue_usss vcmpss vcomisd vcomiss vcvtdq2pd vcvtdq2ps vcvtpd2dq vcvtpd2ps vcvtps2dq vcvtps2pd vcvtsd2si vcvtsd2ss vcvtsi2sd vcvtsi2ss vcvtss2sd vcvtss2si vcvttpd2dq vcvttps2dq vcvttsd2si vcvttss2si vdivpd vdivps vdivsd vdivss vdppd vdpps vextractf128 vextractps vhaddpd vhaddps vhsubpd vhsubps vinsertf128 vinsertps vlddqu vldqqu vldmxcsr vmaskmovdqu vmaskmovps vmaskmovpd vmaxpd vmaxps vmaxsd vmaxss vminpd vminps vminsd vminss vmovapd vmovaps vmovd vmovq vmovddup vmovdqa vmovqqa vmovdqu vmovqqu vmovhlps vmovhpd vmovhps vmovlhps vmovlpd vmovlps vmovmskpd vmovmskps vmovntdq vmovntqq vmovntdqa vmovntpd vmovntps vmovsd vmovshdup vmovsldup vmovss vmovupd vmovups vmpsadbw vmulpd vmulps vmulsd vmulss vorpd vorps vpabsb vpabsw vpabsd vpacksswb vpackssdw vpackuswb vpackusdw vpaddb vpaddw vpaddd vpaddq vpaddsb vpaddsw vpaddusb vpaddusw vpalignr vpand vpandn vpavgb vpavgw vpblendvb vpblendw vpcmpestri vpcmpestrm vpcmpistri vpcmpistrm vpcmpeqb vpcmpeqw vpcmpeqd vpcmpeqq vpcmpgtb vpcmpgtw vpcmpgtd vpcmpgtq vpermilpd vpermilps vperm2f128 vpextrb vpextrw vpextrd vpextrq vphaddw vphaddd vphaddsw vphminposuw vphsubw vphsubd vphsubsw vpinsrb vpinsrw vpinsrd vpinsrq vpmaddwd vpmaddubsw vpmaxsb vpmaxsw vpmaxsd vpmaxub vpmaxuw vpmaxud vpminsb vpminsw vpminsd vpminub vpminuw vpminud vpmovmskb vpmovsxbw vpmovsxbd vpmovsxbq vpmovsxwd vpmovsxwq vpmovsxdq vpmovzxbw vpmovzxbd vpmovzxbq vpmovzxwd vpmovzxwq vpmovzxdq vpmulhuw vpmulhrsw vpmulhw vpmullw vpmulld vpmuludq vpmuldq vpor vpsadbw vpshufb vpshufd vpshufhw vpshuflw vpsignb vpsignw vpsignd vpslldq vpsrldq vpsllw vpslld vpsllq vpsraw vpsrad vpsrlw vpsrld vpsrlq vptest vpsubb vpsubw vpsubd vpsubq vpsubsb vpsubsw vpsubusb vpsubusw vpunpckhbw vpunpckhwd vpunpckhdq vpunpckhqdq vpunpcklbw vpunpcklwd vpunpckldq vpunpcklqdq vpxor vrcpps vrcpss vrsqrtps vrsqrtss vroundpd vroundps vroundsd vroundss vshufpd vshufps vsqrtpd vsqrtps vsqrtsd vsqrtss vstmxcsr vsubpd vsubps vsubsd vsubss vtestps vtestpd vucomisd vucomiss vunpckhpd vunpckhps vunpcklpd vunpcklps vxorpd vxorps vzeroall vzeroupper pclmullqlqdq pclmulhqlqdq pclmullqhqdq pclmulhqhqdq pclmulqdq vpclmullqlqdq vpclmulhqlqdq vpclmullqhqdq vpclmulhqhqdq vpclmulqdq vfmadd132ps vfmadd132pd vfmadd312ps vfmadd312pd vfmadd213ps vfmadd213pd vfmadd123ps vfmadd123pd vfmadd231ps vfmadd231pd vfmadd321ps vfmadd321pd vfmaddsub132ps vfmaddsub132pd vfmaddsub312ps vfmaddsub312pd vfmaddsub213ps vfmaddsub213pd vfmaddsub123ps vfmaddsub123pd vfmaddsub231ps vfmaddsub231pd vfmaddsub321ps vfmaddsub321pd vfmsub132ps vfmsub132pd vfmsub312ps vfmsub312pd vfmsub213ps vfmsub213pd vfmsub123ps vfmsub123pd vfmsub231ps vfmsub231pd vfmsub321ps vfmsub321pd vfmsubadd132ps vfmsubadd132pd vfmsubadd312ps vfmsubadd312pd vfmsubadd213ps vfmsubadd213pd vfmsubadd123ps vfmsubadd123pd vfmsubadd231ps vfmsubadd231pd vfmsubadd321ps vfmsubadd321pd vfnmadd132ps vfnmadd132pd vfnmadd312ps vfnmadd312pd vfnmadd213ps vfnmadd213pd vfnmadd123ps vfnmadd123pd vfnmadd231ps vfnmadd231pd vfnmadd321ps vfnmadd321pd vfnmsub132ps vfnmsub132pd vfnmsub312ps vfnmsub312pd vfnmsub213ps vfnmsub213pd vfnmsub123ps vfnmsub123pd vfnmsub231ps vfnmsub231pd vfnmsub321ps vfnmsub321pd vfmadd132ss vfmadd132sd vfmadd312ss vfmadd312sd vfmadd213ss vfmadd213sd vfmadd123ss vfmadd123sd vfmadd231ss vfmadd231sd vfmadd321ss vfmadd321sd vfmsub132ss vfmsub132sd vfmsub312ss vfmsub312sd vfmsub213ss vfmsub213sd vfmsub123ss vfmsub123sd vfmsub231ss vfmsub231sd vfmsub321ss vfmsub321sd vfnmadd132ss vfnmadd132sd vfnmadd312ss vfnmadd312sd vfnmadd213ss vfnmadd213sd vfnmadd123ss vfnmadd123sd vfnmadd231ss vfnmadd231sd vfnmadd321ss vfnmadd321sd vfnmsub132ss vfnmsub132sd vfnmsub312ss vfnmsub312sd vfnmsub213ss vfnmsub213sd vfnmsub123ss vfnmsub123sd vfnmsub231ss vfnmsub231sd vfnmsub321ss vfnmsub321sd rdfsbase rdgsbase rdrand wrfsbase wrgsbase vcvtph2ps vcvtps2ph adcx adox rdseed clac stac xstore xcryptecb xcryptcbc xcryptctr xcryptcfb xcryptofb montmul xsha1 xsha256 llwpcb slwpcb lwpval lwpins vfmaddpd vfmaddps vfmaddsd vfmaddss vfmaddsubpd vfmaddsubps vfmsubaddpd vfmsubaddps vfmsubpd vfmsubps vfmsubsd vfmsubss vfnmaddpd vfnmaddps vfnmaddsd vfnmaddss vfnmsubpd vfnmsubps vfnmsubsd vfnmsubss vfrczpd vfrczps vfrczsd vfrczss vpcmov vpcomb vpcomd vpcomq vpcomub vpcomud vpcomuq vpcomuw vpcomw vphaddbd vphaddbq vphaddbw vphadddq vphaddubd vphaddubq vphaddubw vphaddudq vphadduwd vphadduwq vphaddwd vphaddwq vphsubbw vphsubdq vphsubwd vpmacsdd vpmacsdqh vpmacsdql vpmacssdd vpmacssdqh vpmacssdql vpmacsswd vpmacssww vpmacswd vpmacsww vpmadcsswd vpmadcswd vpperm vprotb vprotd vprotq vprotw vpshab vpshad vpshaq vpshaw vpshlb vpshld vpshlq vpshlw vbroadcasti128 vpblendd vpbroadcastb vpbroadcastw vpbroadcastd vpbroadcastq vpermd vpermpd vpermps vpermq vperm2i128 vextracti128 vinserti128 vpmaskmovd vpmaskmovq vpsllvd vpsllvq vpsravd vpsrlvd vpsrlvq vgatherdpd vgatherqpd vgatherdps vgatherqps vpgatherdd vpgatherqd vpgatherdq vpgatherqq xabort xbegin xend xtest andn bextr blci blcic blsi blsic blcfill blsfill blcmsk blsmsk blsr blcs bzhi mulx pdep pext rorx sarx shlx shrx tzcnt tzmsk t1mskc valignd valignq vblendmpd vblendmps vbroadcastf32x4 vbroadcastf64x4 vbroadcasti32x4 vbroadcasti64x4 vcompresspd vcompressps vcvtpd2udq vcvtps2udq vcvtsd2usi vcvtss2usi vcvttpd2udq vcvttps2udq vcvttsd2usi vcvttss2usi vcvtudq2pd vcvtudq2ps vcvtusi2sd vcvtusi2ss vexpandpd vexpandps vextractf32x4 vextractf64x4 vextracti32x4 vextracti64x4 vfixupimmpd vfixupimmps vfixupimmsd vfixupimmss vgetexppd vgetexpps vgetexpsd vgetexpss vgetmantpd vgetmantps vgetmantsd vgetmantss vinsertf32x4 vinsertf64x4 vinserti32x4 vinserti64x4 vmovdqa32 vmovdqa64 vmovdqu32 vmovdqu64 vpabsq vpandd vpandnd vpandnq vpandq vpblendmd vpblendmq vpcmpltd vpcmpled vpcmpneqd vpcmpnltd vpcmpnled vpcmpd vpcmpltq vpcmpleq vpcmpneqq vpcmpnltq vpcmpnleq vpcmpq vpcmpequd vpcmpltud vpcmpleud vpcmpnequd vpcmpnltud vpcmpnleud vpcmpud vpcmpequq vpcmpltuq vpcmpleuq vpcmpnequq vpcmpnltuq vpcmpnleuq vpcmpuq vpcompressd vpcompressq vpermi2d vpermi2pd vpermi2ps vpermi2q vpermt2d vpermt2pd vpermt2ps vpermt2q vpexpandd vpexpandq vpmaxsq vpmaxuq vpminsq vpminuq vpmovdb vpmovdw vpmovqb vpmovqd vpmovqw vpmovsdb vpmovsdw vpmovsqb vpmovsqd vpmovsqw vpmovusdb vpmovusdw vpmovusqb vpmovusqd vpmovusqw vpord vporq vprold vprolq vprolvd vprolvq vprord vprorq vprorvd vprorvq vpscatterdd vpscatterdq vpscatterqd vpscatterqq vpsraq vpsravq vpternlogd vpternlogq vptestmd vptestmq vptestnmd vptestnmq vpxord vpxorq vrcp14pd vrcp14ps vrcp14sd vrcp14ss vrndscalepd vrndscaleps vrndscalesd vrndscaless vrsqrt14pd vrsqrt14ps vrsqrt14sd vrsqrt14ss vscalefpd vscalefps vscalefsd vscalefss vscatterdpd vscatterdps vscatterqpd vscatterqps vshuff32x4 vshuff64x2 vshufi32x4 vshufi64x2 kandnw kandw kmovw knotw kortestw korw kshiftlw kshiftrw kunpckbw kxnorw kxorw vpbroadcastmb2q vpbroadcastmw2d vpconflictd vpconflictq vplzcntd vplzcntq vexp2pd vexp2ps vrcp28pd vrcp28ps vrcp28sd vrcp28ss vrsqrt28pd vrsqrt28ps vrsqrt28sd vrsqrt28ss vgatherpf0dpd vgatherpf0dps vgatherpf0qpd vgatherpf0qps vgatherpf1dpd vgatherpf1dps vgatherpf1qpd vgatherpf1qps vscatterpf0dpd vscatterpf0dps vscatterpf0qpd vscatterpf0qps vscatterpf1dpd vscatterpf1dps vscatterpf1qpd vscatterpf1qps prefetchwt1 bndmk bndcl bndcu bndcn bndmov bndldx bndstx sha1rnds4 sha1nexte sha1msg1 sha1msg2 sha256rnds2 sha256msg1 sha256msg2 hint_nop0 hint_nop1 hint_nop2 hint_nop3 hint_nop4 hint_nop5 hint_nop6 hint_nop7 hint_nop8 hint_nop9 hint_nop10 hint_nop11 hint_nop12 hint_nop13 hint_nop14 hint_nop15 hint_nop16 hint_nop17 hint_nop18 hint_nop19 hint_nop20 hint_nop21 hint_nop22 hint_nop23 hint_nop24 hint_nop25 hint_nop26 hint_nop27 hint_nop28 hint_nop29 hint_nop30 hint_nop31 hint_nop32 hint_nop33 hint_nop34 hint_nop35 hint_nop36 hint_nop37 hint_nop38 hint_nop39 hint_nop40 hint_nop41 hint_nop42 hint_nop43 hint_nop44 hint_nop45 hint_nop46 hint_nop47 hint_nop48 hint_nop49 hint_nop50 hint_nop51 hint_nop52 hint_nop53 hint_nop54 hint_nop55 hint_nop56 hint_nop57 hint_nop58 hint_nop59 hint_nop60 hint_nop61 hint_nop62 hint_nop63",built_in:"ip eip rip al ah bl bh cl ch dl dh sil dil bpl spl r8b r9b r10b r11b r12b r13b r14b r15b ax bx cx dx si di bp sp r8w r9w r10w r11w r12w r13w r14w r15w eax ebx ecx edx esi edi ebp esp eip r8d r9d r10d r11d r12d r13d r14d r15d rax rbx rcx rdx rsi rdi rbp rsp r8 r9 r10 r11 r12 r13 r14 r15 cs ds es fs gs ss st st0 st1 st2 st3 st4 st5 st6 st7 mm0 mm1 mm2 mm3 mm4 mm5 mm6 mm7 xmm0 xmm1 xmm2 xmm3 xmm4 xmm5 xmm6 xmm7 xmm8 xmm9 xmm10 xmm11 xmm12 xmm13 xmm14 xmm15 xmm16 xmm17 xmm18 xmm19 xmm20 xmm21 xmm22 xmm23 xmm24 xmm25 xmm26 xmm27 xmm28 xmm29 xmm30 xmm31 ymm0 ymm1 ymm2 ymm3 ymm4 ymm5 ymm6 ymm7 ymm8 ymm9 ymm10 ymm11 ymm12 ymm13 ymm14 ymm15 ymm16 ymm17 ymm18 ymm19 ymm20 ymm21 ymm22 ymm23 ymm24 ymm25 ymm26 ymm27 ymm28 ymm29 ymm30 ymm31 zmm0 zmm1 zmm2 zmm3 zmm4 zmm5 zmm6 zmm7 zmm8 zmm9 zmm10 zmm11 zmm12 zmm13 zmm14 zmm15 zmm16 zmm17 zmm18 zmm19 zmm20 zmm21 zmm22 zmm23 zmm24 zmm25 zmm26 zmm27 zmm28 zmm29 zmm30 zmm31 k0 k1 k2 k3 k4 k5 k6 k7 bnd0 bnd1 bnd2 bnd3 cr0 cr1 cr2 cr3 cr4 cr8 dr0 dr1 dr2 dr3 dr8 tr3 tr4 tr5 tr6 tr7 r0 r1 r2 r3 r4 r5 r6 r7 r0b r1b r2b r3b r4b r5b r6b r7b r0w r1w r2w r3w r4w r5w r6w r7w r0d r1d r2d r3d r4d r5d r6d r7d r0h r1h r2h r3h r0l r1l r2l r3l r4l r5l r6l r7l r8l r9l r10l r11l r12l r13l r14l r15l db dw dd dq dt ddq do dy dz resb resw resd resq rest resdq reso resy resz incbin equ times byte word dword qword nosplit rel abs seg wrt strict near far a32 ptr",meta:"%define %xdefine %+ %undef %defstr %deftok %assign %strcat %strlen %substr %rotate %elif %else %endif %if %ifmacro %ifctx %ifidn %ifidni %ifid %ifnum %ifstr %iftoken %ifempty %ifenv %error %warning %fatal %rep %endrep %include %push %pop %repl %pathsearch %depend %use %arg %stacksize %local %line %comment %endcomment .nolist __FILE__ __LINE__ __SECT__ __BITS__ __OUTPUT_FORMAT__ __DATE__ __TIME__ __DATE_NUM__ __TIME_NUM__ __UTC_DATE__ __UTC_TIME__ __UTC_DATE_NUM__ __UTC_TIME_NUM__ __PASS__ struc endstruc istruc at iend align alignb sectalign daz nodaz up down zero default option assume public bits use16 use32 use64 default section segment absolute extern global common cpu float __utf16__ __utf16le__ __utf16be__ __utf32__ __utf32le__ __utf32be__ __float8__ __float16__ __float32__ __float64__ __float80m__ __float80e__ __float128l__ __float128h__ __Infinity__ __QNaN__ __SNaN__ Inf NaN QNaN SNaN float8 float16 float32 float64 float80m float80e float128l float128h __FLOAT_DAZ__ __FLOAT_ROUND__ __FLOAT__"},contains:[s.COMMENT(";","$",{relevance:0}),{className:"number",variants:[{begin:"\\b(?:([0-9][0-9_]*)?\\.[0-9_]*(?:[eE][+-]?[0-9_]+)?|(0[Xx])?[0-9][0-9_]*\\.?[0-9_]*(?:[pP](?:[+-]?[0-9_]+)?)?)\\b",relevance:0},{begin:"\\$[0-9][0-9A-Fa-f]*",relevance:0},{begin:"\\b(?:[0-9A-Fa-f][0-9A-Fa-f_]*[Hh]|[0-9][0-9_]*[DdTt]?|[0-7][0-7_]*[QqOo]|[0-1][0-1_]*[BbYy])\\b"},{begin:"\\b(?:0[Xx][0-9A-Fa-f_]+|0[DdTt][0-9_]+|0[QqOo][0-7_]+|0[BbYy][0-1_]+)\\b"}]},s.QUOTE_STRING_MODE,{className:"string",variants:[{begin:"'",end:"[^\\\\]'"},{begin:"`",end:"[^\\\\]`"}],relevance:0},{className:"symbol",variants:[{begin:"^\\s*[A-Za-z._?][A-Za-z0-9_$#@~.?]*(:|\\s+label)"},{begin:"^\\s*%%[A-Za-z0-9_$#@~.?]*:"}],relevance:0},{className:"subst",begin:"%[0-9]+",relevance:0},{className:"subst",begin:"%!S+",relevance:0},{className:"meta",begin:/^\s*\.[\w_-]+/}]}}}());hljs.registerLanguage("c",function(){"use strict";return function(e){var n=e.getLanguage("c-like").rawDefinition();return n.name="C",n.aliases=["c","h"],n}}());hljs.registerLanguage("twig",function(){"use strict";return function(e){var a="attribute block constant cycle date dump include max min parent random range source template_from_string",n={beginKeywords:a,keywords:{name:a},relevance:0,contains:[{className:"params",begin:"\\(",end:"\\)"}]},t={begin:/\|[A-Za-z_]+:?/,keywords:"abs batch capitalize column convert_encoding date date_modify default escape filter first format inky_to_html inline_css join json_encode keys last length lower map markdown merge nl2br number_format raw reduce replace reverse round slice sort spaceless split striptags title trim upper url_encode",contains:[n]},s="apply autoescape block deprecated do embed extends filter flush for from if import include macro sandbox set use verbatim with";return s=s+" "+s.split(" ").map((function(e){return"end"+e})).join(" "),{name:"Twig",aliases:["craftcms"],case_insensitive:!0,subLanguage:"xml",contains:[e.COMMENT(/\{#/,/#}/),{className:"template-tag",begin:/\{%/,end:/%}/,contains:[{className:"name",begin:/\w+/,keywords:s,starts:{endsWithParent:!0,contains:[t,n],relevance:0}}]},{className:"template-variable",begin:/\{\{/,end:/}}/,contains:["self",t,n]}]}}}());hljs.registerLanguage("pgsql",function(){"use strict";return function(E){var T=E.COMMENT("--","$"),N="BIGINT INT8 BIGSERIAL SERIAL8 BIT VARYING VARBIT BOOLEAN BOOL BOX BYTEA CHARACTER CHAR VARCHAR CIDR CIRCLE DATE DOUBLE PRECISION FLOAT8 FLOAT INET INTEGER INT INT4 INTERVAL JSON JSONB LINE LSEG|10 MACADDR MACADDR8 MONEY NUMERIC DEC DECIMAL PATH POINT POLYGON REAL FLOAT4 SMALLINT INT2 SMALLSERIAL|10 SERIAL2|10 SERIAL|10 SERIAL4|10 TEXT TIME ZONE TIMETZ|10 TIMESTAMP TIMESTAMPTZ|10 TSQUERY|10 TSVECTOR|10 TXID_SNAPSHOT|10 UUID XML NATIONAL NCHAR INT4RANGE|10 INT8RANGE|10 NUMRANGE|10 TSRANGE|10 TSTZRANGE|10 DATERANGE|10 ANYELEMENT ANYARRAY ANYNONARRAY ANYENUM ANYRANGE CSTRING INTERNAL RECORD PG_DDL_COMMAND VOID UNKNOWN OPAQUE REFCURSOR NAME OID REGPROC|10 REGPROCEDURE|10 REGOPER|10 REGOPERATOR|10 REGCLASS|10 REGTYPE|10 REGROLE|10 REGNAMESPACE|10 REGCONFIG|10 REGDICTIONARY|10 ",A=N.trim().split(" ").map((function(E){return E.split("|")[0]})).join("|"),R="ARRAY_AGG AVG BIT_AND BIT_OR BOOL_AND BOOL_OR COUNT EVERY JSON_AGG JSONB_AGG JSON_OBJECT_AGG JSONB_OBJECT_AGG MAX MIN MODE STRING_AGG SUM XMLAGG CORR COVAR_POP COVAR_SAMP REGR_AVGX REGR_AVGY REGR_COUNT REGR_INTERCEPT REGR_R2 REGR_SLOPE REGR_SXX REGR_SXY REGR_SYY STDDEV STDDEV_POP STDDEV_SAMP VARIANCE VAR_POP VAR_SAMP PERCENTILE_CONT PERCENTILE_DISC ROW_NUMBER RANK DENSE_RANK PERCENT_RANK CUME_DIST NTILE LAG LEAD FIRST_VALUE LAST_VALUE NTH_VALUE NUM_NONNULLS NUM_NULLS ABS CBRT CEIL CEILING DEGREES DIV EXP FLOOR LN LOG MOD PI POWER RADIANS ROUND SCALE SIGN SQRT TRUNC WIDTH_BUCKET RANDOM SETSEED ACOS ACOSD ASIN ASIND ATAN ATAND ATAN2 ATAN2D COS COSD COT COTD SIN SIND TAN TAND BIT_LENGTH CHAR_LENGTH CHARACTER_LENGTH LOWER OCTET_LENGTH OVERLAY POSITION SUBSTRING TREAT TRIM UPPER ASCII BTRIM CHR CONCAT CONCAT_WS CONVERT CONVERT_FROM CONVERT_TO DECODE ENCODE INITCAP LEFT LENGTH LPAD LTRIM MD5 PARSE_IDENT PG_CLIENT_ENCODING QUOTE_IDENT|10 QUOTE_LITERAL|10 QUOTE_NULLABLE|10 REGEXP_MATCH REGEXP_MATCHES REGEXP_REPLACE REGEXP_SPLIT_TO_ARRAY REGEXP_SPLIT_TO_TABLE REPEAT REPLACE REVERSE RIGHT RPAD RTRIM SPLIT_PART STRPOS SUBSTR TO_ASCII TO_HEX TRANSLATE OCTET_LENGTH GET_BIT GET_BYTE SET_BIT SET_BYTE TO_CHAR TO_DATE TO_NUMBER TO_TIMESTAMP AGE CLOCK_TIMESTAMP|10 DATE_PART DATE_TRUNC ISFINITE JUSTIFY_DAYS JUSTIFY_HOURS JUSTIFY_INTERVAL MAKE_DATE MAKE_INTERVAL|10 MAKE_TIME MAKE_TIMESTAMP|10 MAKE_TIMESTAMPTZ|10 NOW STATEMENT_TIMESTAMP|10 TIMEOFDAY TRANSACTION_TIMESTAMP|10 ENUM_FIRST ENUM_LAST ENUM_RANGE AREA CENTER DIAMETER HEIGHT ISCLOSED ISOPEN NPOINTS PCLOSE POPEN RADIUS WIDTH BOX BOUND_BOX CIRCLE LINE LSEG PATH POLYGON ABBREV BROADCAST HOST HOSTMASK MASKLEN NETMASK NETWORK SET_MASKLEN TEXT INET_SAME_FAMILY INET_MERGE MACADDR8_SET7BIT ARRAY_TO_TSVECTOR GET_CURRENT_TS_CONFIG NUMNODE PLAINTO_TSQUERY PHRASETO_TSQUERY WEBSEARCH_TO_TSQUERY QUERYTREE SETWEIGHT STRIP TO_TSQUERY TO_TSVECTOR JSON_TO_TSVECTOR JSONB_TO_TSVECTOR TS_DELETE TS_FILTER TS_HEADLINE TS_RANK TS_RANK_CD TS_REWRITE TSQUERY_PHRASE TSVECTOR_TO_ARRAY TSVECTOR_UPDATE_TRIGGER TSVECTOR_UPDATE_TRIGGER_COLUMN XMLCOMMENT XMLCONCAT XMLELEMENT XMLFOREST XMLPI XMLROOT XMLEXISTS XML_IS_WELL_FORMED XML_IS_WELL_FORMED_DOCUMENT XML_IS_WELL_FORMED_CONTENT XPATH XPATH_EXISTS XMLTABLE XMLNAMESPACES TABLE_TO_XML TABLE_TO_XMLSCHEMA TABLE_TO_XML_AND_XMLSCHEMA QUERY_TO_XML QUERY_TO_XMLSCHEMA QUERY_TO_XML_AND_XMLSCHEMA CURSOR_TO_XML CURSOR_TO_XMLSCHEMA SCHEMA_TO_XML SCHEMA_TO_XMLSCHEMA SCHEMA_TO_XML_AND_XMLSCHEMA DATABASE_TO_XML DATABASE_TO_XMLSCHEMA DATABASE_TO_XML_AND_XMLSCHEMA XMLATTRIBUTES TO_JSON TO_JSONB ARRAY_TO_JSON ROW_TO_JSON JSON_BUILD_ARRAY JSONB_BUILD_ARRAY JSON_BUILD_OBJECT JSONB_BUILD_OBJECT JSON_OBJECT JSONB_OBJECT JSON_ARRAY_LENGTH JSONB_ARRAY_LENGTH JSON_EACH JSONB_EACH JSON_EACH_TEXT JSONB_EACH_TEXT JSON_EXTRACT_PATH JSONB_EXTRACT_PATH JSON_OBJECT_KEYS JSONB_OBJECT_KEYS JSON_POPULATE_RECORD JSONB_POPULATE_RECORD JSON_POPULATE_RECORDSET JSONB_POPULATE_RECORDSET JSON_ARRAY_ELEMENTS JSONB_ARRAY_ELEMENTS JSON_ARRAY_ELEMENTS_TEXT JSONB_ARRAY_ELEMENTS_TEXT JSON_TYPEOF JSONB_TYPEOF JSON_TO_RECORD JSONB_TO_RECORD JSON_TO_RECORDSET JSONB_TO_RECORDSET JSON_STRIP_NULLS JSONB_STRIP_NULLS JSONB_SET JSONB_INSERT JSONB_PRETTY CURRVAL LASTVAL NEXTVAL SETVAL COALESCE NULLIF GREATEST LEAST ARRAY_APPEND ARRAY_CAT ARRAY_NDIMS ARRAY_DIMS ARRAY_FILL ARRAY_LENGTH ARRAY_LOWER ARRAY_POSITION ARRAY_POSITIONS ARRAY_PREPEND ARRAY_REMOVE ARRAY_REPLACE ARRAY_TO_STRING ARRAY_UPPER CARDINALITY STRING_TO_ARRAY UNNEST ISEMPTY LOWER_INC UPPER_INC LOWER_INF UPPER_INF RANGE_MERGE GENERATE_SERIES GENERATE_SUBSCRIPTS CURRENT_DATABASE CURRENT_QUERY CURRENT_SCHEMA|10 CURRENT_SCHEMAS|10 INET_CLIENT_ADDR INET_CLIENT_PORT INET_SERVER_ADDR INET_SERVER_PORT ROW_SECURITY_ACTIVE FORMAT_TYPE TO_REGCLASS TO_REGPROC TO_REGPROCEDURE TO_REGOPER TO_REGOPERATOR TO_REGTYPE TO_REGNAMESPACE TO_REGROLE COL_DESCRIPTION OBJ_DESCRIPTION SHOBJ_DESCRIPTION TXID_CURRENT TXID_CURRENT_IF_ASSIGNED TXID_CURRENT_SNAPSHOT TXID_SNAPSHOT_XIP TXID_SNAPSHOT_XMAX TXID_SNAPSHOT_XMIN TXID_VISIBLE_IN_SNAPSHOT TXID_STATUS CURRENT_SETTING SET_CONFIG BRIN_SUMMARIZE_NEW_VALUES BRIN_SUMMARIZE_RANGE BRIN_DESUMMARIZE_RANGE GIN_CLEAN_PENDING_LIST SUPPRESS_REDUNDANT_UPDATES_TRIGGER LO_FROM_BYTEA LO_PUT LO_GET LO_CREAT LO_CREATE LO_UNLINK LO_IMPORT LO_EXPORT LOREAD LOWRITE GROUPING CAST".split(" ").map((function(E){return E.split("|")[0]})).join("|");return{name:"PostgreSQL",aliases:["postgres","postgresql"],case_insensitive:!0,keywords:{keyword:"ABORT ALTER ANALYZE BEGIN CALL CHECKPOINT|10 CLOSE CLUSTER COMMENT COMMIT COPY CREATE DEALLOCATE DECLARE DELETE DISCARD DO DROP END EXECUTE EXPLAIN FETCH GRANT IMPORT INSERT LISTEN LOAD LOCK MOVE NOTIFY PREPARE REASSIGN|10 REFRESH REINDEX RELEASE RESET REVOKE ROLLBACK SAVEPOINT SECURITY SELECT SET SHOW START TRUNCATE UNLISTEN|10 UPDATE VACUUM|10 VALUES AGGREGATE COLLATION CONVERSION|10 DATABASE DEFAULT PRIVILEGES DOMAIN TRIGGER EXTENSION FOREIGN WRAPPER|10 TABLE FUNCTION GROUP LANGUAGE LARGE OBJECT MATERIALIZED VIEW OPERATOR CLASS FAMILY POLICY PUBLICATION|10 ROLE RULE SCHEMA SEQUENCE SERVER STATISTICS SUBSCRIPTION SYSTEM TABLESPACE CONFIGURATION DICTIONARY PARSER TEMPLATE TYPE USER MAPPING PREPARED ACCESS METHOD CAST AS TRANSFORM TRANSACTION OWNED TO INTO SESSION AUTHORIZATION INDEX PROCEDURE ASSERTION ALL ANALYSE AND ANY ARRAY ASC ASYMMETRIC|10 BOTH CASE CHECK COLLATE COLUMN CONCURRENTLY|10 CONSTRAINT CROSS DEFERRABLE RANGE DESC DISTINCT ELSE EXCEPT FOR FREEZE|10 FROM FULL HAVING ILIKE IN INITIALLY INNER INTERSECT IS ISNULL JOIN LATERAL LEADING LIKE LIMIT NATURAL NOT NOTNULL NULL OFFSET ON ONLY OR ORDER OUTER OVERLAPS PLACING PRIMARY REFERENCES RETURNING SIMILAR SOME SYMMETRIC TABLESAMPLE THEN TRAILING UNION UNIQUE USING VARIADIC|10 VERBOSE WHEN WHERE WINDOW WITH BY RETURNS INOUT OUT SETOF|10 IF STRICT CURRENT CONTINUE OWNER LOCATION OVER PARTITION WITHIN BETWEEN ESCAPE EXTERNAL INVOKER DEFINER WORK RENAME VERSION CONNECTION CONNECT TABLES TEMP TEMPORARY FUNCTIONS SEQUENCES TYPES SCHEMAS OPTION CASCADE RESTRICT ADD ADMIN EXISTS VALID VALIDATE ENABLE DISABLE REPLICA|10 ALWAYS PASSING COLUMNS PATH REF VALUE OVERRIDING IMMUTABLE STABLE VOLATILE BEFORE AFTER EACH ROW PROCEDURAL ROUTINE NO HANDLER VALIDATOR OPTIONS STORAGE OIDS|10 WITHOUT INHERIT DEPENDS CALLED INPUT LEAKPROOF|10 COST ROWS NOWAIT SEARCH UNTIL ENCRYPTED|10 PASSWORD CONFLICT|10 INSTEAD INHERITS CHARACTERISTICS WRITE CURSOR ALSO STATEMENT SHARE EXCLUSIVE INLINE ISOLATION REPEATABLE READ COMMITTED SERIALIZABLE UNCOMMITTED LOCAL GLOBAL SQL PROCEDURES RECURSIVE SNAPSHOT ROLLUP CUBE TRUSTED|10 INCLUDE FOLLOWING PRECEDING UNBOUNDED RANGE GROUPS UNENCRYPTED|10 SYSID FORMAT DELIMITER HEADER QUOTE ENCODING FILTER OFF FORCE_QUOTE FORCE_NOT_NULL FORCE_NULL COSTS BUFFERS TIMING SUMMARY DISABLE_PAGE_SKIPPING RESTART CYCLE GENERATED IDENTITY DEFERRED IMMEDIATE LEVEL LOGGED UNLOGGED OF NOTHING NONE EXCLUDE ATTRIBUTE USAGE ROUTINES TRUE FALSE NAN INFINITY ALIAS BEGIN CONSTANT DECLARE END EXCEPTION RETURN PERFORM|10 RAISE GET DIAGNOSTICS STACKED|10 FOREACH LOOP ELSIF EXIT WHILE REVERSE SLICE DEBUG LOG INFO NOTICE WARNING ASSERT OPEN SUPERUSER NOSUPERUSER CREATEDB NOCREATEDB CREATEROLE NOCREATEROLE INHERIT NOINHERIT LOGIN NOLOGIN REPLICATION NOREPLICATION BYPASSRLS NOBYPASSRLS ",built_in:"CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURRENT_CATALOG|10 CURRENT_DATE LOCALTIME LOCALTIMESTAMP CURRENT_ROLE|10 CURRENT_SCHEMA|10 SESSION_USER PUBLIC FOUND NEW OLD TG_NAME|10 TG_WHEN|10 TG_LEVEL|10 TG_OP|10 TG_RELID|10 TG_RELNAME|10 TG_TABLE_NAME|10 TG_TABLE_SCHEMA|10 TG_NARGS|10 TG_ARGV|10 TG_EVENT|10 TG_TAG|10 ROW_COUNT RESULT_OID|10 PG_CONTEXT|10 RETURNED_SQLSTATE COLUMN_NAME CONSTRAINT_NAME PG_DATATYPE_NAME|10 MESSAGE_TEXT TABLE_NAME SCHEMA_NAME PG_EXCEPTION_DETAIL|10 PG_EXCEPTION_HINT|10 PG_EXCEPTION_CONTEXT|10 SQLSTATE SQLERRM|10 SUCCESSFUL_COMPLETION WARNING DYNAMIC_RESULT_SETS_RETURNED IMPLICIT_ZERO_BIT_PADDING NULL_VALUE_ELIMINATED_IN_SET_FUNCTION PRIVILEGE_NOT_GRANTED PRIVILEGE_NOT_REVOKED STRING_DATA_RIGHT_TRUNCATION DEPRECATED_FEATURE NO_DATA NO_ADDITIONAL_DYNAMIC_RESULT_SETS_RETURNED SQL_STATEMENT_NOT_YET_COMPLETE CONNECTION_EXCEPTION CONNECTION_DOES_NOT_EXIST CONNECTION_FAILURE SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION TRANSACTION_RESOLUTION_UNKNOWN PROTOCOL_VIOLATION TRIGGERED_ACTION_EXCEPTION FEATURE_NOT_SUPPORTED INVALID_TRANSACTION_INITIATION LOCATOR_EXCEPTION INVALID_LOCATOR_SPECIFICATION INVALID_GRANTOR INVALID_GRANT_OPERATION INVALID_ROLE_SPECIFICATION DIAGNOSTICS_EXCEPTION STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER CASE_NOT_FOUND CARDINALITY_VIOLATION DATA_EXCEPTION ARRAY_SUBSCRIPT_ERROR CHARACTER_NOT_IN_REPERTOIRE DATETIME_FIELD_OVERFLOW DIVISION_BY_ZERO ERROR_IN_ASSIGNMENT ESCAPE_CHARACTER_CONFLICT INDICATOR_OVERFLOW INTERVAL_FIELD_OVERFLOW INVALID_ARGUMENT_FOR_LOGARITHM INVALID_ARGUMENT_FOR_NTILE_FUNCTION INVALID_ARGUMENT_FOR_NTH_VALUE_FUNCTION INVALID_ARGUMENT_FOR_POWER_FUNCTION INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION INVALID_CHARACTER_VALUE_FOR_CAST INVALID_DATETIME_FORMAT INVALID_ESCAPE_CHARACTER INVALID_ESCAPE_OCTET INVALID_ESCAPE_SEQUENCE NONSTANDARD_USE_OF_ESCAPE_CHARACTER INVALID_INDICATOR_PARAMETER_VALUE INVALID_PARAMETER_VALUE INVALID_REGULAR_EXPRESSION INVALID_ROW_COUNT_IN_LIMIT_CLAUSE INVALID_ROW_COUNT_IN_RESULT_OFFSET_CLAUSE INVALID_TABLESAMPLE_ARGUMENT INVALID_TABLESAMPLE_REPEAT INVALID_TIME_ZONE_DISPLACEMENT_VALUE INVALID_USE_OF_ESCAPE_CHARACTER MOST_SPECIFIC_TYPE_MISMATCH NULL_VALUE_NOT_ALLOWED NULL_VALUE_NO_INDICATOR_PARAMETER NUMERIC_VALUE_OUT_OF_RANGE SEQUENCE_GENERATOR_LIMIT_EXCEEDED STRING_DATA_LENGTH_MISMATCH STRING_DATA_RIGHT_TRUNCATION SUBSTRING_ERROR TRIM_ERROR UNTERMINATED_C_STRING ZERO_LENGTH_CHARACTER_STRING FLOATING_POINT_EXCEPTION INVALID_TEXT_REPRESENTATION INVALID_BINARY_REPRESENTATION BAD_COPY_FILE_FORMAT UNTRANSLATABLE_CHARACTER NOT_AN_XML_DOCUMENT INVALID_XML_DOCUMENT INVALID_XML_CONTENT INVALID_XML_COMMENT INVALID_XML_PROCESSING_INSTRUCTION INTEGRITY_CONSTRAINT_VIOLATION RESTRICT_VIOLATION NOT_NULL_VIOLATION FOREIGN_KEY_VIOLATION UNIQUE_VIOLATION CHECK_VIOLATION EXCLUSION_VIOLATION INVALID_CURSOR_STATE INVALID_TRANSACTION_STATE ACTIVE_SQL_TRANSACTION BRANCH_TRANSACTION_ALREADY_ACTIVE HELD_CURSOR_REQUIRES_SAME_ISOLATION_LEVEL INAPPROPRIATE_ACCESS_MODE_FOR_BRANCH_TRANSACTION INAPPROPRIATE_ISOLATION_LEVEL_FOR_BRANCH_TRANSACTION NO_ACTIVE_SQL_TRANSACTION_FOR_BRANCH_TRANSACTION READ_ONLY_SQL_TRANSACTION SCHEMA_AND_DATA_STATEMENT_MIXING_NOT_SUPPORTED NO_ACTIVE_SQL_TRANSACTION IN_FAILED_SQL_TRANSACTION IDLE_IN_TRANSACTION_SESSION_TIMEOUT INVALID_SQL_STATEMENT_NAME TRIGGERED_DATA_CHANGE_VIOLATION INVALID_AUTHORIZATION_SPECIFICATION INVALID_PASSWORD DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST DEPENDENT_OBJECTS_STILL_EXIST INVALID_TRANSACTION_TERMINATION SQL_ROUTINE_EXCEPTION FUNCTION_EXECUTED_NO_RETURN_STATEMENT MODIFYING_SQL_DATA_NOT_PERMITTED PROHIBITED_SQL_STATEMENT_ATTEMPTED READING_SQL_DATA_NOT_PERMITTED INVALID_CURSOR_NAME EXTERNAL_ROUTINE_EXCEPTION CONTAINING_SQL_NOT_PERMITTED MODIFYING_SQL_DATA_NOT_PERMITTED PROHIBITED_SQL_STATEMENT_ATTEMPTED READING_SQL_DATA_NOT_PERMITTED EXTERNAL_ROUTINE_INVOCATION_EXCEPTION INVALID_SQLSTATE_RETURNED NULL_VALUE_NOT_ALLOWED TRIGGER_PROTOCOL_VIOLATED SRF_PROTOCOL_VIOLATED EVENT_TRIGGER_PROTOCOL_VIOLATED SAVEPOINT_EXCEPTION INVALID_SAVEPOINT_SPECIFICATION INVALID_CATALOG_NAME INVALID_SCHEMA_NAME TRANSACTION_ROLLBACK TRANSACTION_INTEGRITY_CONSTRAINT_VIOLATION SERIALIZATION_FAILURE STATEMENT_COMPLETION_UNKNOWN DEADLOCK_DETECTED SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION SYNTAX_ERROR INSUFFICIENT_PRIVILEGE CANNOT_COERCE GROUPING_ERROR WINDOWING_ERROR INVALID_RECURSION INVALID_FOREIGN_KEY INVALID_NAME NAME_TOO_LONG RESERVED_NAME DATATYPE_MISMATCH INDETERMINATE_DATATYPE COLLATION_MISMATCH INDETERMINATE_COLLATION WRONG_OBJECT_TYPE GENERATED_ALWAYS UNDEFINED_COLUMN UNDEFINED_FUNCTION UNDEFINED_TABLE UNDEFINED_PARAMETER UNDEFINED_OBJECT DUPLICATE_COLUMN DUPLICATE_CURSOR DUPLICATE_DATABASE DUPLICATE_FUNCTION DUPLICATE_PREPARED_STATEMENT DUPLICATE_SCHEMA DUPLICATE_TABLE DUPLICATE_ALIAS DUPLICATE_OBJECT AMBIGUOUS_COLUMN AMBIGUOUS_FUNCTION AMBIGUOUS_PARAMETER AMBIGUOUS_ALIAS INVALID_COLUMN_REFERENCE INVALID_COLUMN_DEFINITION INVALID_CURSOR_DEFINITION INVALID_DATABASE_DEFINITION INVALID_FUNCTION_DEFINITION INVALID_PREPARED_STATEMENT_DEFINITION INVALID_SCHEMA_DEFINITION INVALID_TABLE_DEFINITION INVALID_OBJECT_DEFINITION WITH_CHECK_OPTION_VIOLATION INSUFFICIENT_RESOURCES DISK_FULL OUT_OF_MEMORY TOO_MANY_CONNECTIONS CONFIGURATION_LIMIT_EXCEEDED PROGRAM_LIMIT_EXCEEDED STATEMENT_TOO_COMPLEX TOO_MANY_COLUMNS TOO_MANY_ARGUMENTS OBJECT_NOT_IN_PREREQUISITE_STATE OBJECT_IN_USE CANT_CHANGE_RUNTIME_PARAM LOCK_NOT_AVAILABLE OPERATOR_INTERVENTION QUERY_CANCELED ADMIN_SHUTDOWN CRASH_SHUTDOWN CANNOT_CONNECT_NOW DATABASE_DROPPED SYSTEM_ERROR IO_ERROR UNDEFINED_FILE DUPLICATE_FILE SNAPSHOT_TOO_OLD CONFIG_FILE_ERROR LOCK_FILE_EXISTS FDW_ERROR FDW_COLUMN_NAME_NOT_FOUND FDW_DYNAMIC_PARAMETER_VALUE_NEEDED FDW_FUNCTION_SEQUENCE_ERROR FDW_INCONSISTENT_DESCRIPTOR_INFORMATION FDW_INVALID_ATTRIBUTE_VALUE FDW_INVALID_COLUMN_NAME FDW_INVALID_COLUMN_NUMBER FDW_INVALID_DATA_TYPE FDW_INVALID_DATA_TYPE_DESCRIPTORS FDW_INVALID_DESCRIPTOR_FIELD_IDENTIFIER FDW_INVALID_HANDLE FDW_INVALID_OPTION_INDEX FDW_INVALID_OPTION_NAME FDW_INVALID_STRING_LENGTH_OR_BUFFER_LENGTH FDW_INVALID_STRING_FORMAT FDW_INVALID_USE_OF_NULL_POINTER FDW_TOO_MANY_HANDLES FDW_OUT_OF_MEMORY FDW_NO_SCHEMAS FDW_OPTION_NAME_NOT_FOUND FDW_REPLY_HANDLE FDW_SCHEMA_NOT_FOUND FDW_TABLE_NOT_FOUND FDW_UNABLE_TO_CREATE_EXECUTION FDW_UNABLE_TO_CREATE_REPLY FDW_UNABLE_TO_ESTABLISH_CONNECTION PLPGSQL_ERROR RAISE_EXCEPTION NO_DATA_FOUND TOO_MANY_ROWS ASSERT_FAILURE INTERNAL_ERROR DATA_CORRUPTED INDEX_CORRUPTED "},illegal:/:==|\W\s*\(\*|(^|\s)\$[a-z]|{{|[a-z]:\s*$|\.\.\.|TO:|DO:/,contains:[{className:"keyword",variants:[{begin:/\bTEXT\s*SEARCH\b/},{begin:/\b(PRIMARY|FOREIGN|FOR(\s+NO)?)\s+KEY\b/},{begin:/\bPARALLEL\s+(UNSAFE|RESTRICTED|SAFE)\b/},{begin:/\bSTORAGE\s+(PLAIN|EXTERNAL|EXTENDED|MAIN)\b/},{begin:/\bMATCH\s+(FULL|PARTIAL|SIMPLE)\b/},{begin:/\bNULLS\s+(FIRST|LAST)\b/},{begin:/\bEVENT\s+TRIGGER\b/},{begin:/\b(MAPPING|OR)\s+REPLACE\b/},{begin:/\b(FROM|TO)\s+(PROGRAM|STDIN|STDOUT)\b/},{begin:/\b(SHARE|EXCLUSIVE)\s+MODE\b/},{begin:/\b(LEFT|RIGHT)\s+(OUTER\s+)?JOIN\b/},{begin:/\b(FETCH|MOVE)\s+(NEXT|PRIOR|FIRST|LAST|ABSOLUTE|RELATIVE|FORWARD|BACKWARD)\b/},{begin:/\bPRESERVE\s+ROWS\b/},{begin:/\bDISCARD\s+PLANS\b/},{begin:/\bREFERENCING\s+(OLD|NEW)\b/},{begin:/\bSKIP\s+LOCKED\b/},{begin:/\bGROUPING\s+SETS\b/},{begin:/\b(BINARY|INSENSITIVE|SCROLL|NO\s+SCROLL)\s+(CURSOR|FOR)\b/},{begin:/\b(WITH|WITHOUT)\s+HOLD\b/},{begin:/\bWITH\s+(CASCADED|LOCAL)\s+CHECK\s+OPTION\b/},{begin:/\bEXCLUDE\s+(TIES|NO\s+OTHERS)\b/},{begin:/\bFORMAT\s+(TEXT|XML|JSON|YAML)\b/},{begin:/\bSET\s+((SESSION|LOCAL)\s+)?NAMES\b/},{begin:/\bIS\s+(NOT\s+)?UNKNOWN\b/},{begin:/\bSECURITY\s+LABEL\b/},{begin:/\bSTANDALONE\s+(YES|NO|NO\s+VALUE)\b/},{begin:/\bWITH\s+(NO\s+)?DATA\b/},{begin:/\b(FOREIGN|SET)\s+DATA\b/},{begin:/\bSET\s+(CATALOG|CONSTRAINTS)\b/},{begin:/\b(WITH|FOR)\s+ORDINALITY\b/},{begin:/\bIS\s+(NOT\s+)?DOCUMENT\b/},{begin:/\bXML\s+OPTION\s+(DOCUMENT|CONTENT)\b/},{begin:/\b(STRIP|PRESERVE)\s+WHITESPACE\b/},{begin:/\bNO\s+(ACTION|MAXVALUE|MINVALUE)\b/},{begin:/\bPARTITION\s+BY\s+(RANGE|LIST|HASH)\b/},{begin:/\bAT\s+TIME\s+ZONE\b/},{begin:/\bGRANTED\s+BY\b/},{begin:/\bRETURN\s+(QUERY|NEXT)\b/},{begin:/\b(ATTACH|DETACH)\s+PARTITION\b/},{begin:/\bFORCE\s+ROW\s+LEVEL\s+SECURITY\b/},{begin:/\b(INCLUDING|EXCLUDING)\s+(COMMENTS|CONSTRAINTS|DEFAULTS|IDENTITY|INDEXES|STATISTICS|STORAGE|ALL)\b/},{begin:/\bAS\s+(ASSIGNMENT|IMPLICIT|PERMISSIVE|RESTRICTIVE|ENUM|RANGE)\b/}]},{begin:/\b(FORMAT|FAMILY|VERSION)\s*\(/},{begin:/\bINCLUDE\s*\(/,keywords:"INCLUDE"},{begin:/\bRANGE(?!\s*(BETWEEN|UNBOUNDED|CURRENT|[-0-9]+))/},{begin:/\b(VERSION|OWNER|TEMPLATE|TABLESPACE|CONNECTION\s+LIMIT|PROCEDURE|RESTRICT|JOIN|PARSER|COPY|START|END|COLLATION|INPUT|ANALYZE|STORAGE|LIKE|DEFAULT|DELIMITER|ENCODING|COLUMN|CONSTRAINT|TABLE|SCHEMA)\s*=/},{begin:/\b(PG_\w+?|HAS_[A-Z_]+_PRIVILEGE)\b/,relevance:10},{begin:/\bEXTRACT\s*\(/,end:/\bFROM\b/,returnEnd:!0,keywords:{type:"CENTURY DAY DECADE DOW DOY EPOCH HOUR ISODOW ISOYEAR MICROSECONDS MILLENNIUM MILLISECONDS MINUTE MONTH QUARTER SECOND TIMEZONE TIMEZONE_HOUR TIMEZONE_MINUTE WEEK YEAR"}},{begin:/\b(XMLELEMENT|XMLPI)\s*\(\s*NAME/,keywords:{keyword:"NAME"}},{begin:/\b(XMLPARSE|XMLSERIALIZE)\s*\(\s*(DOCUMENT|CONTENT)/,keywords:{keyword:"DOCUMENT CONTENT"}},{beginKeywords:"CACHE INCREMENT MAXVALUE MINVALUE",end:E.C_NUMBER_RE,returnEnd:!0,keywords:"BY CACHE INCREMENT MAXVALUE MINVALUE"},{className:"type",begin:/\b(WITH|WITHOUT)\s+TIME\s+ZONE\b/},{className:"type",begin:/\bINTERVAL\s+(YEAR|MONTH|DAY|HOUR|MINUTE|SECOND)(\s+TO\s+(MONTH|HOUR|MINUTE|SECOND))?\b/},{begin:/\bRETURNS\s+(LANGUAGE_HANDLER|TRIGGER|EVENT_TRIGGER|FDW_HANDLER|INDEX_AM_HANDLER|TSM_HANDLER)\b/,keywords:{keyword:"RETURNS",type:"LANGUAGE_HANDLER TRIGGER EVENT_TRIGGER FDW_HANDLER INDEX_AM_HANDLER TSM_HANDLER"}},{begin:"\\b("+R+")\\s*\\("},{begin:"\\.("+A+")\\b"},{begin:"\\b("+A+")\\s+PATH\\b",keywords:{keyword:"PATH",type:N.replace("PATH ","")}},{className:"type",begin:"\\b("+A+")\\b"},{className:"string",begin:"'",end:"'",contains:[{begin:"''"}]},{className:"string",begin:"(e|E|u&|U&)'",end:"'",contains:[{begin:"\\\\."}],relevance:10},{begin:"\\$([a-zA-Z_]?|[a-zA-Z_][a-zA-Z_0-9]*)\\$",endSameAsBegin:!0,contains:[{subLanguage:["pgsql","perl","python","tcl","r","lua","java","php","ruby","bash","scheme","xml","json"],endsWithParent:!0}]},{begin:'"',end:'"',contains:[{begin:'""'}]},E.C_NUMBER_MODE,E.C_BLOCK_COMMENT_MODE,T,{className:"meta",variants:[{begin:"%(ROW)?TYPE",relevance:10},{begin:"\\$\\d+"},{begin:"^#\\w",end:"$"}]},{className:"symbol",begin:"<<\\s*[a-zA-Z_][a-zA-Z_0-9$]*\\s*>>",relevance:10}]}}}());hljs.registerLanguage("properties",function(){"use strict";return function(e){var n="[ \\t\\f]*",t="("+n+"[:=]"+n+"|[ \\t\\f]+)",a="([^\\\\:= \\t\\f\\n]|\\\\.)+",s={end:t,relevance:0,starts:{className:"string",end:/$/,relevance:0,contains:[{begin:"\\\\\\n"}]}};return{name:".properties",case_insensitive:!0,illegal:/\S/,contains:[e.COMMENT("^\\s*[!#]","$"),{begin:"([^\\\\\\W:= \\t\\f\\n]|\\\\.)+"+t,returnBegin:!0,contains:[{className:"attr",begin:"([^\\\\\\W:= \\t\\f\\n]|\\\\.)+",endsParent:!0,relevance:0}],starts:s},{begin:a+t,returnBegin:!0,relevance:0,contains:[{className:"meta",begin:a,endsParent:!0,relevance:0}],starts:s},{className:"attr",relevance:0,begin:a+n+"$"}]}}}());hljs.registerLanguage("csharp",function(){"use strict";return function(e){var n={keyword:"abstract as base bool break byte case catch char checked const continue decimal default delegate do double enum event explicit extern finally fixed float for foreach goto if implicit in int interface internal is lock long object operator out override params private protected public readonly ref sbyte sealed short sizeof stackalloc static string struct switch this try typeof uint ulong unchecked unsafe ushort using virtual void volatile while add alias ascending async await by descending dynamic equals from get global group into join let nameof on orderby partial remove select set value var when where yield",literal:"null false true"},i=e.inherit(e.TITLE_MODE,{begin:"[a-zA-Z](\\.?\\w)*"}),a={className:"number",variants:[{begin:"\\b(0b[01']+)"},{begin:"(-?)\\b([\\d']+(\\.[\\d']*)?|\\.[\\d']+)(u|U|l|L|ul|UL|f|F|b|B)"},{begin:"(-?)(\\b0[xX][a-fA-F0-9']+|(\\b[\\d']+(\\.[\\d']*)?|\\.[\\d']+)([eE][-+]?[\\d']+)?)"}],relevance:0},s={className:"string",begin:'@"',end:'"',contains:[{begin:'""'}]},t=e.inherit(s,{illegal:/\n/}),l={className:"subst",begin:"{",end:"}",keywords:n},r=e.inherit(l,{illegal:/\n/}),c={className:"string",begin:/\$"/,end:'"',illegal:/\n/,contains:[{begin:"{{"},{begin:"}}"},e.BACKSLASH_ESCAPE,r]},o={className:"string",begin:/\$@"/,end:'"',contains:[{begin:"{{"},{begin:"}}"},{begin:'""'},l]},g=e.inherit(o,{illegal:/\n/,contains:[{begin:"{{"},{begin:"}}"},{begin:'""'},r]});l.contains=[o,c,s,e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,a,e.C_BLOCK_COMMENT_MODE],r.contains=[g,c,t,e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,a,e.inherit(e.C_BLOCK_COMMENT_MODE,{illegal:/\n/})];var d={variants:[o,c,s,e.APOS_STRING_MODE,e.QUOTE_STRING_MODE]},E=e.IDENT_RE+"(<"+e.IDENT_RE+"(\\s*,\\s*"+e.IDENT_RE+")*>)?(\\[\\])?",_={begin:"@"+e.IDENT_RE,relevance:0};return{name:"C#",aliases:["cs","c#"],keywords:n,illegal:/::/,contains:[e.COMMENT("///","$",{returnBegin:!0,contains:[{className:"doctag",variants:[{begin:"///",relevance:0},{begin:"\x3c!--|--\x3e"},{begin:""}]}]}),e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,{className:"meta",begin:"#",end:"$",keywords:{"meta-keyword":"if else elif endif define undef warning error line region endregion pragma checksum"}},d,a,{beginKeywords:"class interface",end:/[{;=]/,illegal:/[^\s:,]/,contains:[{beginKeywords:"where class"},i,{begin:"<",end:">",keywords:"in out"},e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{beginKeywords:"namespace",end:/[{;=]/,illegal:/[^\s:]/,contains:[i,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{className:"meta",begin:"^\\s*\\[",excludeBegin:!0,end:"\\]",excludeEnd:!0,contains:[{className:"meta-string",begin:/"/,end:/"/}]},{beginKeywords:"new return throw await else",relevance:0},{className:"function",begin:"("+E+"\\s+)+"+e.IDENT_RE+"\\s*\\(",returnBegin:!0,end:/\s*[{;=]/,excludeEnd:!0,keywords:n,contains:[{begin:e.IDENT_RE+"\\s*\\(",returnBegin:!0,contains:[e.TITLE_MODE],relevance:0},{className:"params",begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:n,relevance:0,contains:[d,a,e.C_BLOCK_COMMENT_MODE]},e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},_]}}}());hljs.registerLanguage("ruby",function(){"use strict";return function(e){var n="[a-zA-Z_]\\w*[!?=]?|[-+~]\\@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?",a={keyword:"and then defined module in return redo if BEGIN retry end for self when next until do begin unless END rescue else break undef not super class case require yield alias while ensure elsif or include attr_reader attr_writer attr_accessor",literal:"true false nil"},s={className:"doctag",begin:"@[A-Za-z]+"},i={begin:"#<",end:">"},r=[e.COMMENT("#","$",{contains:[s]}),e.COMMENT("^\\=begin","^\\=end",{contains:[s],relevance:10}),e.COMMENT("^__END__","\\n$")],c={className:"subst",begin:"#\\{",end:"}",keywords:a},t={className:"string",contains:[e.BACKSLASH_ESCAPE,c],variants:[{begin:/'/,end:/'/},{begin:/"/,end:/"/},{begin:/`/,end:/`/},{begin:"%[qQwWx]?\\(",end:"\\)"},{begin:"%[qQwWx]?\\[",end:"\\]"},{begin:"%[qQwWx]?{",end:"}"},{begin:"%[qQwWx]?<",end:">"},{begin:"%[qQwWx]?/",end:"/"},{begin:"%[qQwWx]?%",end:"%"},{begin:"%[qQwWx]?-",end:"-"},{begin:"%[qQwWx]?\\|",end:"\\|"},{begin:/\B\?(\\\d{1,3}|\\x[A-Fa-f0-9]{1,2}|\\u[A-Fa-f0-9]{4}|\\?\S)\b/},{begin:/<<[-~]?'?(\w+)(?:.|\n)*?\n\s*\1\b/,returnBegin:!0,contains:[{begin:/<<[-~]?'?/},{begin:/\w+/,endSameAsBegin:!0,contains:[e.BACKSLASH_ESCAPE,c]}]}]},b={className:"params",begin:"\\(",end:"\\)",endsParent:!0,keywords:a},d=[t,i,{className:"class",beginKeywords:"class module",end:"$|;",illegal:/=/,contains:[e.inherit(e.TITLE_MODE,{begin:"[A-Za-z_]\\w*(::\\w+)*(\\?|\\!)?"}),{begin:"<\\s*",contains:[{begin:"("+e.IDENT_RE+"::)?"+e.IDENT_RE}]}].concat(r)},{className:"function",beginKeywords:"def",end:"$|;",contains:[e.inherit(e.TITLE_MODE,{begin:n}),b].concat(r)},{begin:e.IDENT_RE+"::"},{className:"symbol",begin:e.UNDERSCORE_IDENT_RE+"(\\!|\\?)?:",relevance:0},{className:"symbol",begin:":(?!\\s)",contains:[t,{begin:n}],relevance:0},{className:"number",begin:"(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b",relevance:0},{begin:"(\\$\\W)|((\\$|\\@\\@?)(\\w+))"},{className:"params",begin:/\|/,end:/\|/,keywords:a},{begin:"("+e.RE_STARTERS_RE+"|unless)\\s*",keywords:"unless",contains:[i,{className:"regexp",contains:[e.BACKSLASH_ESCAPE,c],illegal:/\n/,variants:[{begin:"/",end:"/[a-z]*"},{begin:"%r{",end:"}[a-z]*"},{begin:"%r\\(",end:"\\)[a-z]*"},{begin:"%r!",end:"![a-z]*"},{begin:"%r\\[",end:"\\][a-z]*"}]}].concat(r),relevance:0}].concat(r);c.contains=d,b.contains=d;var g=[{begin:/^\s*=>/,starts:{end:"$",contains:d}},{className:"meta",begin:"^([>?]>|[\\w#]+\\(\\w+\\):\\d+:\\d+>|(\\w+-)?\\d+\\.\\d+\\.\\d(p\\d+)?[^>]+>)",starts:{end:"$",contains:d}}];return{name:"Ruby",aliases:["rb","gemspec","podspec","thor","irb"],keywords:a,illegal:/\/\*/,contains:r.concat(g).concat(d)}}}());hljs.registerLanguage("apache",function(){"use strict";return function(e){var n={className:"number",begin:"\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(:\\d{1,5})?"};return{name:"Apache config",aliases:["apacheconf"],case_insensitive:!0,contains:[e.HASH_COMMENT_MODE,{className:"section",begin:"",contains:[n,{className:"number",begin:":\\d{1,5}"},e.inherit(e.QUOTE_STRING_MODE,{relevance:0})]},{className:"attribute",begin:/\w+/,relevance:0,keywords:{nomarkup:"order deny allow setenv rewriterule rewriteengine rewritecond documentroot sethandler errordocument loadmodule options header listen serverroot servername"},starts:{end:/$/,relevance:0,keywords:{literal:"on off all deny allow"},contains:[{className:"meta",begin:"\\s\\[",end:"\\]$"},{className:"variable",begin:"[\\$%]\\{",end:"\\}",contains:["self",{className:"number",begin:"[\\$%]\\d+"}]},n,{className:"number",begin:"\\d+"},e.QUOTE_STRING_MODE]}}],illegal:/\S/}}}());hljs.registerLanguage("armasm",function(){"use strict";return function(s){const e={variants:[s.COMMENT("^[ \\t]*(?=#)","$",{relevance:0,excludeBegin:!0}),s.COMMENT("[;@]","$",{relevance:0}),s.C_LINE_COMMENT_MODE,s.C_BLOCK_COMMENT_MODE]};return{name:"ARM Assembly",case_insensitive:!0,aliases:["arm"],lexemes:"\\.?"+s.IDENT_RE,keywords:{meta:".2byte .4byte .align .ascii .asciz .balign .byte .code .data .else .end .endif .endm .endr .equ .err .exitm .extern .global .hword .if .ifdef .ifndef .include .irp .long .macro .rept .req .section .set .skip .space .text .word .arm .thumb .code16 .code32 .force_thumb .thumb_func .ltorg ALIAS ALIGN ARM AREA ASSERT ATTR CN CODE CODE16 CODE32 COMMON CP DATA DCB DCD DCDU DCDO DCFD DCFDU DCI DCQ DCQU DCW DCWU DN ELIF ELSE END ENDFUNC ENDIF ENDP ENTRY EQU EXPORT EXPORTAS EXTERN FIELD FILL FUNCTION GBLA GBLL GBLS GET GLOBAL IF IMPORT INCBIN INCLUDE INFO KEEP LCLA LCLL LCLS LTORG MACRO MAP MEND MEXIT NOFP OPT PRESERVE8 PROC QN READONLY RELOC REQUIRE REQUIRE8 RLIST FN ROUT SETA SETL SETS SN SPACE SUBT THUMB THUMBX TTL WHILE WEND ",built_in:"r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 pc lr sp ip sl sb fp a1 a2 a3 a4 v1 v2 v3 v4 v5 v6 v7 v8 f0 f1 f2 f3 f4 f5 f6 f7 p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 q0 q1 q2 q3 q4 q5 q6 q7 q8 q9 q10 q11 q12 q13 q14 q15 cpsr_c cpsr_x cpsr_s cpsr_f cpsr_cx cpsr_cxs cpsr_xs cpsr_xsf cpsr_sf cpsr_cxsf spsr_c spsr_x spsr_s spsr_f spsr_cx spsr_cxs spsr_xs spsr_xsf spsr_sf spsr_cxsf s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 s15 s16 s17 s18 s19 s20 s21 s22 s23 s24 s25 s26 s27 s28 s29 s30 s31 d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12 d13 d14 d15 d16 d17 d18 d19 d20 d21 d22 d23 d24 d25 d26 d27 d28 d29 d30 d31 {PC} {VAR} {TRUE} {FALSE} {OPT} {CONFIG} {ENDIAN} {CODESIZE} {CPU} {FPU} {ARCHITECTURE} {PCSTOREOFFSET} {ARMASM_VERSION} {INTER} {ROPI} {RWPI} {SWST} {NOSWST} . @"},contains:[{className:"keyword",begin:"\\b(adc|(qd?|sh?|u[qh]?)?add(8|16)?|usada?8|(q|sh?|u[qh]?)?(as|sa)x|and|adrl?|sbc|rs[bc]|asr|b[lx]?|blx|bxj|cbn?z|tb[bh]|bic|bfc|bfi|[su]bfx|bkpt|cdp2?|clz|clrex|cmp|cmn|cpsi[ed]|cps|setend|dbg|dmb|dsb|eor|isb|it[te]{0,3}|lsl|lsr|ror|rrx|ldm(([id][ab])|f[ds])?|ldr((s|ex)?[bhd])?|movt?|mvn|mra|mar|mul|[us]mull|smul[bwt][bt]|smu[as]d|smmul|smmla|mla|umlaal|smlal?([wbt][bt]|d)|mls|smlsl?[ds]|smc|svc|sev|mia([bt]{2}|ph)?|mrr?c2?|mcrr2?|mrs|msr|orr|orn|pkh(tb|bt)|rbit|rev(16|sh)?|sel|[su]sat(16)?|nop|pop|push|rfe([id][ab])?|stm([id][ab])?|str(ex)?[bhd]?|(qd?)?sub|(sh?|q|u[qh]?)?sub(8|16)|[su]xt(a?h|a?b(16)?)|srs([id][ab])?|swpb?|swi|smi|tst|teq|wfe|wfi|yield)(eq|ne|cs|cc|mi|pl|vs|vc|hi|ls|ge|lt|gt|le|al|hs|lo)?[sptrx]?(?=\\s)"},e,s.QUOTE_STRING_MODE,{className:"string",begin:"'",end:"[^\\\\]'",relevance:0},{className:"title",begin:"\\|",end:"\\|",illegal:"\\n",relevance:0},{className:"number",variants:[{begin:"[#$=]?0x[0-9a-f]+"},{begin:"[#$=]?0b[01]+"},{begin:"[#$=]\\d+"},{begin:"\\b\\d+"}],relevance:0},{className:"symbol",variants:[{begin:"^[ \\t]*[a-z_\\.\\$][a-z0-9_\\.\\$]+:"},{begin:"^[a-z_\\.\\$][a-z0-9_\\.\\$]+"},{begin:"[=#]\\w+"}],relevance:0}]}}}());hljs.registerLanguage("objectivec",function(){"use strict";return function(e){var n=/[a-zA-Z@][a-zA-Z0-9_]*/,_="@interface @class @protocol @implementation";return{name:"Objective-C",aliases:["mm","objc","obj-c"],keywords:{keyword:"int float while char export sizeof typedef const struct for union unsigned long volatile static bool mutable if do return goto void enum else break extern asm case short default double register explicit signed typename this switch continue wchar_t inline readonly assign readwrite self @synchronized id typeof nonatomic super unichar IBOutlet IBAction strong weak copy in out inout bycopy byref oneway __strong __weak __block __autoreleasing @private @protected @public @try @property @end @throw @catch @finally @autoreleasepool @synthesize @dynamic @selector @optional @required @encode @package @import @defs @compatibility_alias __bridge __bridge_transfer __bridge_retained __bridge_retain __covariant __contravariant __kindof _Nonnull _Nullable _Null_unspecified __FUNCTION__ __PRETTY_FUNCTION__ __attribute__ getter setter retain unsafe_unretained nonnull nullable null_unspecified null_resettable class instancetype NS_DESIGNATED_INITIALIZER NS_UNAVAILABLE NS_REQUIRES_SUPER NS_RETURNS_INNER_POINTER NS_INLINE NS_AVAILABLE NS_DEPRECATED NS_ENUM NS_OPTIONS NS_SWIFT_UNAVAILABLE NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_END NS_REFINED_FOR_SWIFT NS_SWIFT_NAME NS_SWIFT_NOTHROW NS_DURING NS_HANDLER NS_ENDHANDLER NS_VALUERETURN NS_VOIDRETURN",literal:"false true FALSE TRUE nil YES NO NULL",built_in:"BOOL dispatch_once_t dispatch_queue_t dispatch_sync dispatch_async dispatch_once"},lexemes:n,illegal:"/,end:/$/,illegal:"\\n"},e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{className:"class",begin:"("+_.split(" ").join("|")+")\\b",end:"({|$)",excludeEnd:!0,keywords:_,lexemes:n,contains:[e.UNDERSCORE_TITLE_MODE]},{begin:"\\."+e.UNDERSCORE_IDENT_RE,relevance:0}]}}}());hljs.registerLanguage("vbnet",function(){"use strict";return function(e){return{name:"Visual Basic .NET",aliases:["vb"],case_insensitive:!0,keywords:{keyword:"addhandler addressof alias and andalso aggregate ansi as async assembly auto await binary by byref byval call case catch class compare const continue custom declare default delegate dim distinct do each equals else elseif end enum erase error event exit explicit finally for friend from function get global goto group handles if implements imports in inherits interface into is isfalse isnot istrue iterator join key let lib like loop me mid mod module mustinherit mustoverride mybase myclass nameof namespace narrowing new next not notinheritable notoverridable of off on operator option optional or order orelse overloads overridable overrides paramarray partial preserve private property protected public raiseevent readonly redim rem removehandler resume return select set shadows shared skip static step stop structure strict sub synclock take text then throw to try unicode until using when where while widening with withevents writeonly xor yield",built_in:"boolean byte cbool cbyte cchar cdate cdec cdbl char cint clng cobj csbyte cshort csng cstr ctype date decimal directcast double gettype getxmlnamespace iif integer long object sbyte short single string trycast typeof uinteger ulong ushort",literal:"true false nothing"},illegal:"//|{|}|endif|gosub|variant|wend|^\\$ ",contains:[e.inherit(e.QUOTE_STRING_MODE,{contains:[{begin:'""'}]}),e.COMMENT("'","$",{returnBegin:!0,contains:[{className:"doctag",begin:"'''|\x3c!--|--\x3e",contains:[e.PHRASAL_WORDS_MODE]},{className:"doctag",begin:"",contains:[e.PHRASAL_WORDS_MODE]}]}),e.C_NUMBER_MODE,{className:"meta",begin:"#",end:"$",keywords:{"meta-keyword":"if else elseif end region externalsource"}}]}}}());hljs.registerLanguage("brainfuck",function(){"use strict";return function(e){var n={className:"literal",begin:"[\\+\\-]",relevance:0};return{name:"Brainfuck",aliases:["bf"],contains:[e.COMMENT("[^\\[\\]\\.,\\+\\-<> \r\n]","[\\[\\]\\.,\\+\\-<> \r\n]",{returnEnd:!0,relevance:0}),{className:"title",begin:"[\\[\\]]",relevance:0},{className:"string",begin:"[\\.,]",relevance:0},{begin:/(?:\+\+|\-\-)/,contains:[n]},n]}}}());hljs.registerLanguage("less",function(){"use strict";return function(e){var n="([\\w-]+|@{[\\w-]+})",a=[],s=[],t=function(e){return{className:"string",begin:"~?"+e+".*?"+e}},r=function(e,n,a){return{className:e,begin:n,relevance:a}},i={begin:"\\(",end:"\\)",contains:s,relevance:0};s.push(e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,t("'"),t('"'),e.CSS_NUMBER_MODE,{begin:"(url|data-uri)\\(",starts:{className:"string",end:"[\\)\\n]",excludeEnd:!0}},r("number","#[0-9A-Fa-f]+\\b"),i,r("variable","@@?[\\w-]+",10),r("variable","@{[\\w-]+}"),r("built_in","~?`[^`]*?`"),{className:"attribute",begin:"[\\w-]+\\s*:",end:":",returnBegin:!0,excludeEnd:!0},{className:"meta",begin:"!important"});var c=s.concat({begin:"{",end:"}",contains:a}),l={beginKeywords:"when",endsWithParent:!0,contains:[{beginKeywords:"and not"}].concat(s)},o={begin:n+"\\s*:",returnBegin:!0,end:"[;}]",relevance:0,contains:[{className:"attribute",begin:n,end:":",excludeEnd:!0,starts:{endsWithParent:!0,illegal:"[<=$]",relevance:0,contains:s}}]},g={className:"keyword",begin:"@(import|media|charset|font-face|(-[a-z]+-)?keyframes|supports|document|namespace|page|viewport|host)\\b",starts:{end:"[;{}]",returnEnd:!0,contains:s,relevance:0}},d={className:"variable",variants:[{begin:"@[\\w-]+\\s*:",relevance:15},{begin:"@[\\w-]+"}],starts:{end:"[;}]",returnEnd:!0,contains:c}},b={variants:[{begin:"[\\.#:&\\[>]",end:"[;{}]"},{begin:n,end:"{"}],returnBegin:!0,returnEnd:!0,illegal:"[<='$\"]",relevance:0,contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,l,r("keyword","all\\b"),r("variable","@{[\\w-]+}"),r("selector-tag",n+"%?",0),r("selector-id","#"+n),r("selector-class","\\."+n,0),r("selector-tag","&",0),{className:"selector-attr",begin:"\\[",end:"\\]"},{className:"selector-pseudo",begin:/:(:)?[a-zA-Z0-9\_\-\+\(\)"'.]+/},{begin:"\\(",end:"\\)",contains:c},{begin:"!important"}]};return a.push(e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,g,d,o,b),{name:"Less",case_insensitive:!0,illegal:"[=>'/<($\"]",contains:a}}}());hljs.registerLanguage("css",function(){"use strict";return function(e){var n={begin:/(?:[A-Z\_\.\-]+|--[a-zA-Z0-9_-]+)\s*:/,returnBegin:!0,end:";",endsWithParent:!0,contains:[{className:"attribute",begin:/\S/,end:":",excludeEnd:!0,starts:{endsWithParent:!0,excludeEnd:!0,contains:[{begin:/[\w-]+\(/,returnBegin:!0,contains:[{className:"built_in",begin:/[\w-]+/},{begin:/\(/,end:/\)/,contains:[e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,e.CSS_NUMBER_MODE]}]},e.CSS_NUMBER_MODE,e.QUOTE_STRING_MODE,e.APOS_STRING_MODE,e.C_BLOCK_COMMENT_MODE,{className:"number",begin:"#[0-9A-Fa-f]+"},{className:"meta",begin:"!important"}]}}]};return{name:"CSS",case_insensitive:!0,illegal:/[=\/|'\$]/,contains:[e.C_BLOCK_COMMENT_MODE,{className:"selector-id",begin:/#[A-Za-z0-9_-]+/},{className:"selector-class",begin:/\.[A-Za-z0-9_-]+/},{className:"selector-attr",begin:/\[/,end:/\]/,illegal:"$",contains:[e.APOS_STRING_MODE,e.QUOTE_STRING_MODE]},{className:"selector-pseudo",begin:/:(:)?[a-zA-Z0-9\_\-\+\(\)"'.]+/},{begin:"@(page|font-face)",lexemes:"@[a-z-]+",keywords:"@page @font-face"},{begin:"@",end:"[{;]",illegal:/:/,returnBegin:!0,contains:[{className:"keyword",begin:/@\-?\w[\w]*(\-\w+)*/},{begin:/\s/,endsWithParent:!0,excludeEnd:!0,relevance:0,keywords:"and or not only",contains:[{begin:/[a-z-]+:/,className:"attribute"},e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,e.CSS_NUMBER_MODE]}]},{className:"selector-tag",begin:"[a-zA-Z-][a-zA-Z0-9_-]*",relevance:0},{begin:"{",end:"}",illegal:/\S/,contains:[e.C_BLOCK_COMMENT_MODE,n]}]}}}());hljs.registerLanguage("yaml",function(){"use strict";return function(e){var n={className:"string",relevance:0,variants:[{begin:/'/,end:/'/},{begin:/"/,end:/"/},{begin:/\S+/}],contains:[e.BACKSLASH_ESCAPE,{className:"template-variable",variants:[{begin:"{{",end:"}}"},{begin:"%{",end:"}"}]}]};return{name:"YAML",case_insensitive:!0,aliases:["yml","YAML"],contains:[{className:"attr",variants:[{begin:"\\w[\\w :\\/.-]*:(?=[ \t]|$)"},{begin:'"\\w[\\w :\\/.-]*":(?=[ \t]|$)'},{begin:"'\\w[\\w :\\/.-]*':(?=[ \t]|$)"}]},{className:"meta",begin:"^---s*$",relevance:10},{className:"string",begin:"[\\|>]([0-9]?[+-])?[ ]*\\n( *)[\\S ]+\\n(\\2[\\S ]+\\n?)*"},{begin:"<%[%=-]?",end:"[%-]?%>",subLanguage:"ruby",excludeBegin:!0,excludeEnd:!0,relevance:0},{className:"type",begin:"!"+e.UNDERSCORE_IDENT_RE},{className:"type",begin:"!!"+e.UNDERSCORE_IDENT_RE},{className:"meta",begin:"&"+e.UNDERSCORE_IDENT_RE+"$"},{className:"meta",begin:"\\*"+e.UNDERSCORE_IDENT_RE+"$"},{className:"bullet",begin:"\\-(?=[ ]|$)",relevance:0},e.HASH_COMMENT_MODE,{beginKeywords:"true false yes no null",keywords:{literal:"true false yes no null"}},{className:"number",begin:"\\b[0-9]{4}(-[0-9][0-9]){0,2}([Tt \\t][0-9][0-9]?(:[0-9][0-9]){2})?(\\.[0-9]*)?([ \\t])*(Z|[-+][0-9][0-9]?(:[0-9][0-9])?)?\\b"},{className:"number",begin:e.C_NUMBER_RE+"\\b"},n]}}}());hljs.registerLanguage("scss",function(){"use strict";return function(e){var t={className:"variable",begin:"(\\$[a-zA-Z-][a-zA-Z0-9_-]*)\\b"},i={className:"number",begin:"#[0-9A-Fa-f]+"};return e.CSS_NUMBER_MODE,e.QUOTE_STRING_MODE,e.APOS_STRING_MODE,e.C_BLOCK_COMMENT_MODE,{name:"SCSS",case_insensitive:!0,illegal:"[=/|']",contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,{className:"selector-id",begin:"\\#[A-Za-z0-9_-]+",relevance:0},{className:"selector-class",begin:"\\.[A-Za-z0-9_-]+",relevance:0},{className:"selector-attr",begin:"\\[",end:"\\]",illegal:"$"},{className:"selector-tag",begin:"\\b(a|abbr|acronym|address|area|article|aside|audio|b|base|big|blockquote|body|br|button|canvas|caption|cite|code|col|colgroup|command|datalist|dd|del|details|dfn|div|dl|dt|em|embed|fieldset|figcaption|figure|footer|form|frame|frameset|(h[1-6])|head|header|hgroup|hr|html|i|iframe|img|input|ins|kbd|keygen|label|legend|li|link|map|mark|meta|meter|nav|noframes|noscript|object|ol|optgroup|option|output|p|param|pre|progress|q|rp|rt|ruby|samp|script|section|select|small|span|strike|strong|style|sub|sup|table|tbody|td|textarea|tfoot|th|thead|time|title|tr|tt|ul|var|video)\\b",relevance:0},{className:"selector-pseudo",begin:":(visited|valid|root|right|required|read-write|read-only|out-range|optional|only-of-type|only-child|nth-of-type|nth-last-of-type|nth-last-child|nth-child|not|link|left|last-of-type|last-child|lang|invalid|indeterminate|in-range|hover|focus|first-of-type|first-line|first-letter|first-child|first|enabled|empty|disabled|default|checked|before|after|active)"},{className:"selector-pseudo",begin:"::(after|before|choices|first-letter|first-line|repeat-index|repeat-item|selection|value)"},t,{className:"attribute",begin:"\\b(src|z-index|word-wrap|word-spacing|word-break|width|widows|white-space|visibility|vertical-align|unicode-bidi|transition-timing-function|transition-property|transition-duration|transition-delay|transition|transform-style|transform-origin|transform|top|text-underline-position|text-transform|text-shadow|text-rendering|text-overflow|text-indent|text-decoration-style|text-decoration-line|text-decoration-color|text-decoration|text-align-last|text-align|tab-size|table-layout|right|resize|quotes|position|pointer-events|perspective-origin|perspective|page-break-inside|page-break-before|page-break-after|padding-top|padding-right|padding-left|padding-bottom|padding|overflow-y|overflow-x|overflow-wrap|overflow|outline-width|outline-style|outline-offset|outline-color|outline|orphans|order|opacity|object-position|object-fit|normal|none|nav-up|nav-right|nav-left|nav-index|nav-down|min-width|min-height|max-width|max-height|mask|marks|margin-top|margin-right|margin-left|margin-bottom|margin|list-style-type|list-style-position|list-style-image|list-style|line-height|letter-spacing|left|justify-content|initial|inherit|ime-mode|image-orientation|image-resolution|image-rendering|icon|hyphens|height|font-weight|font-variant-ligatures|font-variant|font-style|font-stretch|font-size-adjust|font-size|font-language-override|font-kerning|font-feature-settings|font-family|font|float|flex-wrap|flex-shrink|flex-grow|flex-flow|flex-direction|flex-basis|flex|filter|empty-cells|display|direction|cursor|counter-reset|counter-increment|content|column-width|column-span|column-rule-width|column-rule-style|column-rule-color|column-rule|column-gap|column-fill|column-count|columns|color|clip-path|clip|clear|caption-side|break-inside|break-before|break-after|box-sizing|box-shadow|box-decoration-break|bottom|border-width|border-top-width|border-top-style|border-top-right-radius|border-top-left-radius|border-top-color|border-top|border-style|border-spacing|border-right-width|border-right-style|border-right-color|border-right|border-radius|border-left-width|border-left-style|border-left-color|border-left|border-image-width|border-image-source|border-image-slice|border-image-repeat|border-image-outset|border-image|border-color|border-collapse|border-bottom-width|border-bottom-style|border-bottom-right-radius|border-bottom-left-radius|border-bottom-color|border-bottom|border|background-size|background-repeat|background-position|background-origin|background-image|background-color|background-clip|background-attachment|background-blend-mode|background|backface-visibility|auto|animation-timing-function|animation-play-state|animation-name|animation-iteration-count|animation-fill-mode|animation-duration|animation-direction|animation-delay|animation|align-self|align-items|align-content)\\b",illegal:"[^\\s]"},{begin:"\\b(whitespace|wait|w-resize|visible|vertical-text|vertical-ideographic|uppercase|upper-roman|upper-alpha|underline|transparent|top|thin|thick|text|text-top|text-bottom|tb-rl|table-header-group|table-footer-group|sw-resize|super|strict|static|square|solid|small-caps|separate|se-resize|scroll|s-resize|rtl|row-resize|ridge|right|repeat|repeat-y|repeat-x|relative|progress|pointer|overline|outside|outset|oblique|nowrap|not-allowed|normal|none|nw-resize|no-repeat|no-drop|newspaper|ne-resize|n-resize|move|middle|medium|ltr|lr-tb|lowercase|lower-roman|lower-alpha|loose|list-item|line|line-through|line-edge|lighter|left|keep-all|justify|italic|inter-word|inter-ideograph|inside|inset|inline|inline-block|inherit|inactive|ideograph-space|ideograph-parenthesis|ideograph-numeric|ideograph-alpha|horizontal|hidden|help|hand|groove|fixed|ellipsis|e-resize|double|dotted|distribute|distribute-space|distribute-letter|distribute-all-lines|disc|disabled|default|decimal|dashed|crosshair|collapse|col-resize|circle|char|center|capitalize|break-word|break-all|bottom|both|bolder|bold|block|bidi-override|below|baseline|auto|always|all-scroll|absolute|table|table-cell)\\b"},{begin:":",end:";",contains:[t,i,e.CSS_NUMBER_MODE,e.QUOTE_STRING_MODE,e.APOS_STRING_MODE,{className:"meta",begin:"!important"}]},{begin:"@(page|font-face)",lexemes:"@[a-z-]+",keywords:"@page @font-face"},{begin:"@",end:"[{;]",returnBegin:!0,keywords:"and or not only",contains:[{begin:"@[a-z-]+",className:"keyword"},t,e.QUOTE_STRING_MODE,e.APOS_STRING_MODE,i,e.CSS_NUMBER_MODE]}]}}}());hljs.registerLanguage("basic",function(){"use strict";return function(E){return{name:"BASIC",case_insensitive:!0,illegal:"^.",lexemes:"[a-zA-Z][a-zA-Z0-9_$%!#]*",keywords:{keyword:"ABS ASC AND ATN AUTO|0 BEEP BLOAD|10 BSAVE|10 CALL CALLS CDBL CHAIN CHDIR CHR$|10 CINT CIRCLE CLEAR CLOSE CLS COLOR COM COMMON CONT COS CSNG CSRLIN CVD CVI CVS DATA DATE$ DEFDBL DEFINT DEFSNG DEFSTR DEF|0 SEG USR DELETE DIM DRAW EDIT END ENVIRON ENVIRON$ EOF EQV ERASE ERDEV ERDEV$ ERL ERR ERROR EXP FIELD FILES FIX FOR|0 FRE GET GOSUB|10 GOTO HEX$ IF THEN ELSE|0 INKEY$ INP INPUT INPUT# INPUT$ INSTR IMP INT IOCTL IOCTL$ KEY ON OFF LIST KILL LEFT$ LEN LET LINE LLIST LOAD LOC LOCATE LOF LOG LPRINT USING LSET MERGE MID$ MKDIR MKD$ MKI$ MKS$ MOD NAME NEW NEXT NOISE NOT OCT$ ON OR PEN PLAY STRIG OPEN OPTION BASE OUT PAINT PALETTE PCOPY PEEK PMAP POINT POKE POS PRINT PRINT] PSET PRESET PUT RANDOMIZE READ REM RENUM RESET|0 RESTORE RESUME RETURN|0 RIGHT$ RMDIR RND RSET RUN SAVE SCREEN SGN SHELL SIN SOUND SPACE$ SPC SQR STEP STICK STOP STR$ STRING$ SWAP SYSTEM TAB TAN TIME$ TIMER TROFF TRON TO USR VAL VARPTR VARPTR$ VIEW WAIT WHILE WEND WIDTH WINDOW WRITE XOR"},contains:[E.QUOTE_STRING_MODE,E.COMMENT("REM","$",{relevance:10}),E.COMMENT("'","$",{relevance:0}),{className:"symbol",begin:"^[0-9]+ ",relevance:10},{className:"number",begin:"\\b([0-9]+[0-9edED.]*[#!]?)",relevance:0},{className:"number",begin:"(&[hH][0-9a-fA-F]{1,4})"},{className:"number",begin:"(&[oO][0-7]{1,6})"}]}}}());hljs.registerLanguage("diff",function(){"use strict";return function(e){return{name:"Diff",aliases:["patch"],contains:[{className:"meta",relevance:10,variants:[{begin:/^@@ +\-\d+,\d+ +\+\d+,\d+ +@@$/},{begin:/^\*\*\* +\d+,\d+ +\*\*\*\*$/},{begin:/^\-\-\- +\d+,\d+ +\-\-\-\-$/}]},{className:"comment",variants:[{begin:/Index: /,end:/$/},{begin:/={3,}/,end:/$/},{begin:/^\-{3}/,end:/$/},{begin:/^\*{3} /,end:/$/},{begin:/^\+{3}/,end:/$/},{begin:/^\*{15}$/}]},{className:"addition",begin:"^\\+",end:"$"},{className:"deletion",begin:"^\\-",end:"$"},{className:"addition",begin:"^\\!",end:"$"}]}}}());hljs.registerLanguage("markdown",function(){"use strict";return function(n){const e={begin:"<",end:">",subLanguage:"xml",relevance:0},a={begin:"\\[.+?\\][\\(\\[].*?[\\)\\]]",returnBegin:!0,contains:[{className:"string",begin:"\\[",end:"\\]",excludeBegin:!0,returnEnd:!0,relevance:0},{className:"link",begin:"\\]\\(",end:"\\)",excludeBegin:!0,excludeEnd:!0},{className:"symbol",begin:"\\]\\[",end:"\\]",excludeBegin:!0,excludeEnd:!0}],relevance:10},i={className:"strong",contains:[],variants:[{begin:/_{2}/,end:/_{2}/},{begin:/\*{2}/,end:/\*{2}/}]},s={className:"emphasis",contains:[],variants:[{begin:/\*(?!\*)/,end:/\*/},{begin:/_(?!_)/,end:/_/,relevance:0}]};i.contains.push(s),s.contains.push(i);var c=[e,a];return i.contains=i.contains.concat(c),s.contains=s.contains.concat(c),{name:"Markdown",aliases:["md","mkdown","mkd"],contains:[{className:"section",variants:[{begin:"^#{1,6}",end:"$",contains:c=c.concat(i,s)},{begin:"(?=^.+?\\n[=-]{2,}$)",contains:[{begin:"^[=-]*$"},{begin:"^",end:"\\n",contains:c}]}]},e,{className:"bullet",begin:"^[ \t]*([*+-]|(\\d+\\.))(?=\\s+)",end:"\\s+",excludeEnd:!0},i,s,{className:"quote",begin:"^>\\s+",contains:c,end:"$"},{className:"code",variants:[{begin:"(`{3,})(.|\\n)*?\\1`*[ ]*"},{begin:"(~{3,})(.|\\n)*?\\1~*[ ]*"},{begin:"```",end:"```+[ ]*$"},{begin:"~~~",end:"~~~+[ ]*$"},{begin:"`.+?`"},{begin:"(?=^( {4}|\\t))",contains:[{begin:"^( {4}|\\t)",end:"(\\n)$"}],relevance:0}]},{begin:"^[-\\*]{3,}",end:"$"},a,{begin:/^\[[^\n]+\]:/,returnBegin:!0,contains:[{className:"symbol",begin:/\[/,end:/\]/,excludeBegin:!0,excludeEnd:!0},{className:"link",begin:/:\s*/,end:/$/,excludeBegin:!0}]}]}}}());hljs.registerLanguage("gml",function(){"use strict";return function(e){return{name:"GML",aliases:["gml","GML"],case_insensitive:!1,keywords:{keyword:"begin end if then else while do for break continue with until repeat exit and or xor not return mod div switch case default var globalvar enum #macro #region #endregion",built_in:"is_real is_string is_array is_undefined is_int32 is_int64 is_ptr is_vec3 is_vec4 is_matrix is_bool typeof variable_global_exists variable_global_get variable_global_set variable_instance_exists variable_instance_get variable_instance_set variable_instance_get_names array_length_1d array_length_2d array_height_2d array_equals array_create array_copy random random_range irandom irandom_range random_set_seed random_get_seed randomize randomise choose abs round floor ceil sign frac sqrt sqr exp ln log2 log10 sin cos tan arcsin arccos arctan arctan2 dsin dcos dtan darcsin darccos darctan darctan2 degtorad radtodeg power logn min max mean median clamp lerp dot_product dot_product_3d dot_product_normalised dot_product_3d_normalised dot_product_normalized dot_product_3d_normalized math_set_epsilon math_get_epsilon angle_difference point_distance_3d point_distance point_direction lengthdir_x lengthdir_y real string int64 ptr string_format chr ansi_char ord string_length string_byte_length string_pos string_copy string_char_at string_ord_at string_byte_at string_set_byte_at string_delete string_insert string_lower string_upper string_repeat string_letters string_digits string_lettersdigits string_replace string_replace_all string_count string_hash_to_newline clipboard_has_text clipboard_set_text clipboard_get_text date_current_datetime date_create_datetime date_valid_datetime date_inc_year date_inc_month date_inc_week date_inc_day date_inc_hour date_inc_minute date_inc_second date_get_year date_get_month date_get_week date_get_day date_get_hour date_get_minute date_get_second date_get_weekday date_get_day_of_year date_get_hour_of_year date_get_minute_of_year date_get_second_of_year date_year_span date_month_span date_week_span date_day_span date_hour_span date_minute_span date_second_span date_compare_datetime date_compare_date date_compare_time date_date_of date_time_of date_datetime_string date_date_string date_time_string date_days_in_month date_days_in_year date_leap_year date_is_today date_set_timezone date_get_timezone game_set_speed game_get_speed motion_set motion_add place_free place_empty place_meeting place_snapped move_random move_snap move_towards_point move_contact_solid move_contact_all move_outside_solid move_outside_all move_bounce_solid move_bounce_all move_wrap distance_to_point distance_to_object position_empty position_meeting path_start path_end mp_linear_step mp_potential_step mp_linear_step_object mp_potential_step_object mp_potential_settings mp_linear_path mp_potential_path mp_linear_path_object mp_potential_path_object mp_grid_create mp_grid_destroy mp_grid_clear_all mp_grid_clear_cell mp_grid_clear_rectangle mp_grid_add_cell mp_grid_get_cell mp_grid_add_rectangle mp_grid_add_instances mp_grid_path mp_grid_draw mp_grid_to_ds_grid collision_point collision_rectangle collision_circle collision_ellipse collision_line collision_point_list collision_rectangle_list collision_circle_list collision_ellipse_list collision_line_list instance_position_list instance_place_list point_in_rectangle point_in_triangle point_in_circle rectangle_in_rectangle rectangle_in_triangle rectangle_in_circle instance_find instance_exists instance_number instance_position instance_nearest instance_furthest instance_place instance_create_depth instance_create_layer instance_copy instance_change instance_destroy position_destroy position_change instance_id_get instance_deactivate_all instance_deactivate_object instance_deactivate_region instance_activate_all instance_activate_object instance_activate_region room_goto room_goto_previous room_goto_next room_previous room_next room_restart game_end game_restart game_load game_save game_save_buffer game_load_buffer event_perform event_user event_perform_object event_inherited show_debug_message show_debug_overlay debug_event debug_get_callstack alarm_get alarm_set font_texture_page_size keyboard_set_map keyboard_get_map keyboard_unset_map keyboard_check keyboard_check_pressed keyboard_check_released keyboard_check_direct keyboard_get_numlock keyboard_set_numlock keyboard_key_press keyboard_key_release keyboard_clear io_clear mouse_check_button mouse_check_button_pressed mouse_check_button_released mouse_wheel_up mouse_wheel_down mouse_clear draw_self draw_sprite draw_sprite_pos draw_sprite_ext draw_sprite_stretched draw_sprite_stretched_ext draw_sprite_tiled draw_sprite_tiled_ext draw_sprite_part draw_sprite_part_ext draw_sprite_general draw_clear draw_clear_alpha draw_point draw_line draw_line_width draw_rectangle draw_roundrect draw_roundrect_ext draw_triangle draw_circle draw_ellipse draw_set_circle_precision draw_arrow draw_button draw_path draw_healthbar draw_getpixel draw_getpixel_ext draw_set_colour draw_set_color draw_set_alpha draw_get_colour draw_get_color draw_get_alpha merge_colour make_colour_rgb make_colour_hsv colour_get_red colour_get_green colour_get_blue colour_get_hue colour_get_saturation colour_get_value merge_color make_color_rgb make_color_hsv color_get_red color_get_green color_get_blue color_get_hue color_get_saturation color_get_value merge_color screen_save screen_save_part draw_set_font draw_set_halign draw_set_valign draw_text draw_text_ext string_width string_height string_width_ext string_height_ext draw_text_transformed draw_text_ext_transformed draw_text_colour draw_text_ext_colour draw_text_transformed_colour draw_text_ext_transformed_colour draw_text_color draw_text_ext_color draw_text_transformed_color draw_text_ext_transformed_color draw_point_colour draw_line_colour draw_line_width_colour draw_rectangle_colour draw_roundrect_colour draw_roundrect_colour_ext draw_triangle_colour draw_circle_colour draw_ellipse_colour draw_point_color draw_line_color draw_line_width_color draw_rectangle_color draw_roundrect_color draw_roundrect_color_ext draw_triangle_color draw_circle_color draw_ellipse_color draw_primitive_begin draw_vertex draw_vertex_colour draw_vertex_color draw_primitive_end sprite_get_uvs font_get_uvs sprite_get_texture font_get_texture texture_get_width texture_get_height texture_get_uvs draw_primitive_begin_texture draw_vertex_texture draw_vertex_texture_colour draw_vertex_texture_color texture_global_scale surface_create surface_create_ext surface_resize surface_free surface_exists surface_get_width surface_get_height surface_get_texture surface_set_target surface_set_target_ext surface_reset_target surface_depth_disable surface_get_depth_disable draw_surface draw_surface_stretched draw_surface_tiled draw_surface_part draw_surface_ext draw_surface_stretched_ext draw_surface_tiled_ext draw_surface_part_ext draw_surface_general surface_getpixel surface_getpixel_ext surface_save surface_save_part surface_copy surface_copy_part application_surface_draw_enable application_get_position application_surface_enable application_surface_is_enabled display_get_width display_get_height display_get_orientation display_get_gui_width display_get_gui_height display_reset display_mouse_get_x display_mouse_get_y display_mouse_set display_set_ui_visibility window_set_fullscreen window_get_fullscreen window_set_caption window_set_min_width window_set_max_width window_set_min_height window_set_max_height window_get_visible_rects window_get_caption window_set_cursor window_get_cursor window_set_colour window_get_colour window_set_color window_get_color window_set_position window_set_size window_set_rectangle window_center window_get_x window_get_y window_get_width window_get_height window_mouse_get_x window_mouse_get_y window_mouse_set window_view_mouse_get_x window_view_mouse_get_y window_views_mouse_get_x window_views_mouse_get_y audio_listener_position audio_listener_velocity audio_listener_orientation audio_emitter_position audio_emitter_create audio_emitter_free audio_emitter_exists audio_emitter_pitch audio_emitter_velocity audio_emitter_falloff audio_emitter_gain audio_play_sound audio_play_sound_on audio_play_sound_at audio_stop_sound audio_resume_music audio_music_is_playing audio_resume_sound audio_pause_sound audio_pause_music audio_channel_num audio_sound_length audio_get_type audio_falloff_set_model audio_play_music audio_stop_music audio_master_gain audio_music_gain audio_sound_gain audio_sound_pitch audio_stop_all audio_resume_all audio_pause_all audio_is_playing audio_is_paused audio_exists audio_sound_set_track_position audio_sound_get_track_position audio_emitter_get_gain audio_emitter_get_pitch audio_emitter_get_x audio_emitter_get_y audio_emitter_get_z audio_emitter_get_vx audio_emitter_get_vy audio_emitter_get_vz audio_listener_set_position audio_listener_set_velocity audio_listener_set_orientation audio_listener_get_data audio_set_master_gain audio_get_master_gain audio_sound_get_gain audio_sound_get_pitch audio_get_name audio_sound_set_track_position audio_sound_get_track_position audio_create_stream audio_destroy_stream audio_create_sync_group audio_destroy_sync_group audio_play_in_sync_group audio_start_sync_group audio_stop_sync_group audio_pause_sync_group audio_resume_sync_group audio_sync_group_get_track_pos audio_sync_group_debug audio_sync_group_is_playing audio_debug audio_group_load audio_group_unload audio_group_is_loaded audio_group_load_progress audio_group_name audio_group_stop_all audio_group_set_gain audio_create_buffer_sound audio_free_buffer_sound audio_create_play_queue audio_free_play_queue audio_queue_sound audio_get_recorder_count audio_get_recorder_info audio_start_recording audio_stop_recording audio_sound_get_listener_mask audio_emitter_get_listener_mask audio_get_listener_mask audio_sound_set_listener_mask audio_emitter_set_listener_mask audio_set_listener_mask audio_get_listener_count audio_get_listener_info audio_system show_message show_message_async clickable_add clickable_add_ext clickable_change clickable_change_ext clickable_delete clickable_exists clickable_set_style show_question show_question_async get_integer get_string get_integer_async get_string_async get_login_async get_open_filename get_save_filename get_open_filename_ext get_save_filename_ext show_error highscore_clear highscore_add highscore_value highscore_name draw_highscore sprite_exists sprite_get_name sprite_get_number sprite_get_width sprite_get_height sprite_get_xoffset sprite_get_yoffset sprite_get_bbox_left sprite_get_bbox_right sprite_get_bbox_top sprite_get_bbox_bottom sprite_save sprite_save_strip sprite_set_cache_size sprite_set_cache_size_ext sprite_get_tpe sprite_prefetch sprite_prefetch_multi sprite_flush sprite_flush_multi sprite_set_speed sprite_get_speed_type sprite_get_speed font_exists font_get_name font_get_fontname font_get_bold font_get_italic font_get_first font_get_last font_get_size font_set_cache_size path_exists path_get_name path_get_length path_get_time path_get_kind path_get_closed path_get_precision path_get_number path_get_point_x path_get_point_y path_get_point_speed path_get_x path_get_y path_get_speed script_exists script_get_name timeline_add timeline_delete timeline_clear timeline_exists timeline_get_name timeline_moment_clear timeline_moment_add_script timeline_size timeline_max_moment object_exists object_get_name object_get_sprite object_get_solid object_get_visible object_get_persistent object_get_mask object_get_parent object_get_physics object_is_ancestor room_exists room_get_name sprite_set_offset sprite_duplicate sprite_assign sprite_merge sprite_add sprite_replace sprite_create_from_surface sprite_add_from_surface sprite_delete sprite_set_alpha_from_sprite sprite_collision_mask font_add_enable_aa font_add_get_enable_aa font_add font_add_sprite font_add_sprite_ext font_replace font_replace_sprite font_replace_sprite_ext font_delete path_set_kind path_set_closed path_set_precision path_add path_assign path_duplicate path_append path_delete path_add_point path_insert_point path_change_point path_delete_point path_clear_points path_reverse path_mirror path_flip path_rotate path_rescale path_shift script_execute object_set_sprite object_set_solid object_set_visible object_set_persistent object_set_mask room_set_width room_set_height room_set_persistent room_set_background_colour room_set_background_color room_set_view room_set_viewport room_get_viewport room_set_view_enabled room_add room_duplicate room_assign room_instance_add room_instance_clear room_get_camera room_set_camera asset_get_index asset_get_type file_text_open_from_string file_text_open_read file_text_open_write file_text_open_append file_text_close file_text_write_string file_text_write_real file_text_writeln file_text_read_string file_text_read_real file_text_readln file_text_eof file_text_eoln file_exists file_delete file_rename file_copy directory_exists directory_create directory_destroy file_find_first file_find_next file_find_close file_attributes filename_name filename_path filename_dir filename_drive filename_ext filename_change_ext file_bin_open file_bin_rewrite file_bin_close file_bin_position file_bin_size file_bin_seek file_bin_write_byte file_bin_read_byte parameter_count parameter_string environment_get_variable ini_open_from_string ini_open ini_close ini_read_string ini_read_real ini_write_string ini_write_real ini_key_exists ini_section_exists ini_key_delete ini_section_delete ds_set_precision ds_exists ds_stack_create ds_stack_destroy ds_stack_clear ds_stack_copy ds_stack_size ds_stack_empty ds_stack_push ds_stack_pop ds_stack_top ds_stack_write ds_stack_read ds_queue_create ds_queue_destroy ds_queue_clear ds_queue_copy ds_queue_size ds_queue_empty ds_queue_enqueue ds_queue_dequeue ds_queue_head ds_queue_tail ds_queue_write ds_queue_read ds_list_create ds_list_destroy ds_list_clear ds_list_copy ds_list_size ds_list_empty ds_list_add ds_list_insert ds_list_replace ds_list_delete ds_list_find_index ds_list_find_value ds_list_mark_as_list ds_list_mark_as_map ds_list_sort ds_list_shuffle ds_list_write ds_list_read ds_list_set ds_map_create ds_map_destroy ds_map_clear ds_map_copy ds_map_size ds_map_empty ds_map_add ds_map_add_list ds_map_add_map ds_map_replace ds_map_replace_map ds_map_replace_list ds_map_delete ds_map_exists ds_map_find_value ds_map_find_previous ds_map_find_next ds_map_find_first ds_map_find_last ds_map_write ds_map_read ds_map_secure_save ds_map_secure_load ds_map_secure_load_buffer ds_map_secure_save_buffer ds_map_set ds_priority_create ds_priority_destroy ds_priority_clear ds_priority_copy ds_priority_size ds_priority_empty ds_priority_add ds_priority_change_priority ds_priority_find_priority ds_priority_delete_value ds_priority_delete_min ds_priority_find_min ds_priority_delete_max ds_priority_find_max ds_priority_write ds_priority_read ds_grid_create ds_grid_destroy ds_grid_copy ds_grid_resize ds_grid_width ds_grid_height ds_grid_clear ds_grid_set ds_grid_add ds_grid_multiply ds_grid_set_region ds_grid_add_region ds_grid_multiply_region ds_grid_set_disk ds_grid_add_disk ds_grid_multiply_disk ds_grid_set_grid_region ds_grid_add_grid_region ds_grid_multiply_grid_region ds_grid_get ds_grid_get_sum ds_grid_get_max ds_grid_get_min ds_grid_get_mean ds_grid_get_disk_sum ds_grid_get_disk_min ds_grid_get_disk_max ds_grid_get_disk_mean ds_grid_value_exists ds_grid_value_x ds_grid_value_y ds_grid_value_disk_exists ds_grid_value_disk_x ds_grid_value_disk_y ds_grid_shuffle ds_grid_write ds_grid_read ds_grid_sort ds_grid_set ds_grid_get effect_create_below effect_create_above effect_clear part_type_create part_type_destroy part_type_exists part_type_clear part_type_shape part_type_sprite part_type_size part_type_scale part_type_orientation part_type_life part_type_step part_type_death part_type_speed part_type_direction part_type_gravity part_type_colour1 part_type_colour2 part_type_colour3 part_type_colour_mix part_type_colour_rgb part_type_colour_hsv part_type_color1 part_type_color2 part_type_color3 part_type_color_mix part_type_color_rgb part_type_color_hsv part_type_alpha1 part_type_alpha2 part_type_alpha3 part_type_blend part_system_create part_system_create_layer part_system_destroy part_system_exists part_system_clear part_system_draw_order part_system_depth part_system_position part_system_automatic_update part_system_automatic_draw part_system_update part_system_drawit part_system_get_layer part_system_layer part_particles_create part_particles_create_colour part_particles_create_color part_particles_clear part_particles_count part_emitter_create part_emitter_destroy part_emitter_destroy_all part_emitter_exists part_emitter_clear part_emitter_region part_emitter_burst part_emitter_stream external_call external_define external_free window_handle window_device matrix_get matrix_set matrix_build_identity matrix_build matrix_build_lookat matrix_build_projection_ortho matrix_build_projection_perspective matrix_build_projection_perspective_fov matrix_multiply matrix_transform_vertex matrix_stack_push matrix_stack_pop matrix_stack_multiply matrix_stack_set matrix_stack_clear matrix_stack_top matrix_stack_is_empty browser_input_capture os_get_config os_get_info os_get_language os_get_region os_lock_orientation display_get_dpi_x display_get_dpi_y display_set_gui_size display_set_gui_maximise display_set_gui_maximize device_mouse_dbclick_enable display_set_timing_method display_get_timing_method display_set_sleep_margin display_get_sleep_margin virtual_key_add virtual_key_hide virtual_key_delete virtual_key_show draw_enable_drawevent draw_enable_swf_aa draw_set_swf_aa_level draw_get_swf_aa_level draw_texture_flush draw_flush gpu_set_blendenable gpu_set_ztestenable gpu_set_zfunc gpu_set_zwriteenable gpu_set_lightingenable gpu_set_fog gpu_set_cullmode gpu_set_blendmode gpu_set_blendmode_ext gpu_set_blendmode_ext_sepalpha gpu_set_colorwriteenable gpu_set_colourwriteenable gpu_set_alphatestenable gpu_set_alphatestref gpu_set_alphatestfunc gpu_set_texfilter gpu_set_texfilter_ext gpu_set_texrepeat gpu_set_texrepeat_ext gpu_set_tex_filter gpu_set_tex_filter_ext gpu_set_tex_repeat gpu_set_tex_repeat_ext gpu_set_tex_mip_filter gpu_set_tex_mip_filter_ext gpu_set_tex_mip_bias gpu_set_tex_mip_bias_ext gpu_set_tex_min_mip gpu_set_tex_min_mip_ext gpu_set_tex_max_mip gpu_set_tex_max_mip_ext gpu_set_tex_max_aniso gpu_set_tex_max_aniso_ext gpu_set_tex_mip_enable gpu_set_tex_mip_enable_ext gpu_get_blendenable gpu_get_ztestenable gpu_get_zfunc gpu_get_zwriteenable gpu_get_lightingenable gpu_get_fog gpu_get_cullmode gpu_get_blendmode gpu_get_blendmode_ext gpu_get_blendmode_ext_sepalpha gpu_get_blendmode_src gpu_get_blendmode_dest gpu_get_blendmode_srcalpha gpu_get_blendmode_destalpha gpu_get_colorwriteenable gpu_get_colourwriteenable gpu_get_alphatestenable gpu_get_alphatestref gpu_get_alphatestfunc gpu_get_texfilter gpu_get_texfilter_ext gpu_get_texrepeat gpu_get_texrepeat_ext gpu_get_tex_filter gpu_get_tex_filter_ext gpu_get_tex_repeat gpu_get_tex_repeat_ext gpu_get_tex_mip_filter gpu_get_tex_mip_filter_ext gpu_get_tex_mip_bias gpu_get_tex_mip_bias_ext gpu_get_tex_min_mip gpu_get_tex_min_mip_ext gpu_get_tex_max_mip gpu_get_tex_max_mip_ext gpu_get_tex_max_aniso gpu_get_tex_max_aniso_ext gpu_get_tex_mip_enable gpu_get_tex_mip_enable_ext gpu_push_state gpu_pop_state gpu_get_state gpu_set_state draw_light_define_ambient draw_light_define_direction draw_light_define_point draw_light_enable draw_set_lighting draw_light_get_ambient draw_light_get draw_get_lighting shop_leave_rating url_get_domain url_open url_open_ext url_open_full get_timer achievement_login achievement_logout achievement_post achievement_increment achievement_post_score achievement_available achievement_show_achievements achievement_show_leaderboards achievement_load_friends achievement_load_leaderboard achievement_send_challenge achievement_load_progress achievement_reset achievement_login_status achievement_get_pic achievement_show_challenge_notifications achievement_get_challenges achievement_event achievement_show achievement_get_info cloud_file_save cloud_string_save cloud_synchronise ads_enable ads_disable ads_setup ads_engagement_launch ads_engagement_available ads_engagement_active ads_event ads_event_preload ads_set_reward_callback ads_get_display_height ads_get_display_width ads_move ads_interstitial_available ads_interstitial_display device_get_tilt_x device_get_tilt_y device_get_tilt_z device_is_keypad_open device_mouse_check_button device_mouse_check_button_pressed device_mouse_check_button_released device_mouse_x device_mouse_y device_mouse_raw_x device_mouse_raw_y device_mouse_x_to_gui device_mouse_y_to_gui iap_activate iap_status iap_enumerate_products iap_restore_all iap_acquire iap_consume iap_product_details iap_purchase_details facebook_init facebook_login facebook_status facebook_graph_request facebook_dialog facebook_logout facebook_launch_offerwall facebook_post_message facebook_send_invite facebook_user_id facebook_accesstoken facebook_check_permission facebook_request_read_permissions facebook_request_publish_permissions gamepad_is_supported gamepad_get_device_count gamepad_is_connected gamepad_get_description gamepad_get_button_threshold gamepad_set_button_threshold gamepad_get_axis_deadzone gamepad_set_axis_deadzone gamepad_button_count gamepad_button_check gamepad_button_check_pressed gamepad_button_check_released gamepad_button_value gamepad_axis_count gamepad_axis_value gamepad_set_vibration gamepad_set_colour gamepad_set_color os_is_paused window_has_focus code_is_compiled http_get http_get_file http_post_string http_request json_encode json_decode zip_unzip load_csv base64_encode base64_decode md5_string_unicode md5_string_utf8 md5_file os_is_network_connected sha1_string_unicode sha1_string_utf8 sha1_file os_powersave_enable analytics_event analytics_event_ext win8_livetile_tile_notification win8_livetile_tile_clear win8_livetile_badge_notification win8_livetile_badge_clear win8_livetile_queue_enable win8_secondarytile_pin win8_secondarytile_badge_notification win8_secondarytile_delete win8_livetile_notification_begin win8_livetile_notification_secondary_begin win8_livetile_notification_expiry win8_livetile_notification_tag win8_livetile_notification_text_add win8_livetile_notification_image_add win8_livetile_notification_end win8_appbar_enable win8_appbar_add_element win8_appbar_remove_element win8_settingscharm_add_entry win8_settingscharm_add_html_entry win8_settingscharm_add_xaml_entry win8_settingscharm_set_xaml_property win8_settingscharm_get_xaml_property win8_settingscharm_remove_entry win8_share_image win8_share_screenshot win8_share_file win8_share_url win8_share_text win8_search_enable win8_search_disable win8_search_add_suggestions win8_device_touchscreen_available win8_license_initialize_sandbox win8_license_trial_version winphone_license_trial_version winphone_tile_title winphone_tile_count winphone_tile_back_title winphone_tile_back_content winphone_tile_back_content_wide winphone_tile_front_image winphone_tile_front_image_small winphone_tile_front_image_wide winphone_tile_back_image winphone_tile_back_image_wide winphone_tile_background_colour winphone_tile_background_color winphone_tile_icon_image winphone_tile_small_icon_image winphone_tile_wide_content winphone_tile_cycle_images winphone_tile_small_background_image physics_world_create physics_world_gravity physics_world_update_speed physics_world_update_iterations physics_world_draw_debug physics_pause_enable physics_fixture_create physics_fixture_set_kinematic physics_fixture_set_density physics_fixture_set_awake physics_fixture_set_restitution physics_fixture_set_friction physics_fixture_set_collision_group physics_fixture_set_sensor physics_fixture_set_linear_damping physics_fixture_set_angular_damping physics_fixture_set_circle_shape physics_fixture_set_box_shape physics_fixture_set_edge_shape physics_fixture_set_polygon_shape physics_fixture_set_chain_shape physics_fixture_add_point physics_fixture_bind physics_fixture_bind_ext physics_fixture_delete physics_apply_force physics_apply_impulse physics_apply_angular_impulse physics_apply_local_force physics_apply_local_impulse physics_apply_torque physics_mass_properties physics_draw_debug physics_test_overlap physics_remove_fixture physics_set_friction physics_set_density physics_set_restitution physics_get_friction physics_get_density physics_get_restitution physics_joint_distance_create physics_joint_rope_create physics_joint_revolute_create physics_joint_prismatic_create physics_joint_pulley_create physics_joint_wheel_create physics_joint_weld_create physics_joint_friction_create physics_joint_gear_create physics_joint_enable_motor physics_joint_get_value physics_joint_set_value physics_joint_delete physics_particle_create physics_particle_delete physics_particle_delete_region_circle physics_particle_delete_region_box physics_particle_delete_region_poly physics_particle_set_flags physics_particle_set_category_flags physics_particle_draw physics_particle_draw_ext physics_particle_count physics_particle_get_data physics_particle_get_data_particle physics_particle_group_begin physics_particle_group_circle physics_particle_group_box physics_particle_group_polygon physics_particle_group_add_point physics_particle_group_end physics_particle_group_join physics_particle_group_delete physics_particle_group_count physics_particle_group_get_data physics_particle_group_get_mass physics_particle_group_get_inertia physics_particle_group_get_centre_x physics_particle_group_get_centre_y physics_particle_group_get_vel_x physics_particle_group_get_vel_y physics_particle_group_get_ang_vel physics_particle_group_get_x physics_particle_group_get_y physics_particle_group_get_angle physics_particle_set_group_flags physics_particle_get_group_flags physics_particle_get_max_count physics_particle_get_radius physics_particle_get_density physics_particle_get_damping physics_particle_get_gravity_scale physics_particle_set_max_count physics_particle_set_radius physics_particle_set_density physics_particle_set_damping physics_particle_set_gravity_scale network_create_socket network_create_socket_ext network_create_server network_create_server_raw network_connect network_connect_raw network_send_packet network_send_raw network_send_broadcast network_send_udp network_send_udp_raw network_set_timeout network_set_config network_resolve network_destroy buffer_create buffer_write buffer_read buffer_seek buffer_get_surface buffer_set_surface buffer_delete buffer_exists buffer_get_type buffer_get_alignment buffer_poke buffer_peek buffer_save buffer_save_ext buffer_load buffer_load_ext buffer_load_partial buffer_copy buffer_fill buffer_get_size buffer_tell buffer_resize buffer_md5 buffer_sha1 buffer_base64_encode buffer_base64_decode buffer_base64_decode_ext buffer_sizeof buffer_get_address buffer_create_from_vertex_buffer buffer_create_from_vertex_buffer_ext buffer_copy_from_vertex_buffer buffer_async_group_begin buffer_async_group_option buffer_async_group_end buffer_load_async buffer_save_async gml_release_mode gml_pragma steam_activate_overlay steam_is_overlay_enabled steam_is_overlay_activated steam_get_persona_name steam_initialised steam_is_cloud_enabled_for_app steam_is_cloud_enabled_for_account steam_file_persisted steam_get_quota_total steam_get_quota_free steam_file_write steam_file_write_file steam_file_read steam_file_delete steam_file_exists steam_file_size steam_file_share steam_is_screenshot_requested steam_send_screenshot steam_is_user_logged_on steam_get_user_steam_id steam_user_owns_dlc steam_user_installed_dlc steam_set_achievement steam_get_achievement steam_clear_achievement steam_set_stat_int steam_set_stat_float steam_set_stat_avg_rate steam_get_stat_int steam_get_stat_float steam_get_stat_avg_rate steam_reset_all_stats steam_reset_all_stats_achievements steam_stats_ready steam_create_leaderboard steam_upload_score steam_upload_score_ext steam_download_scores_around_user steam_download_scores steam_download_friends_scores steam_upload_score_buffer steam_upload_score_buffer_ext steam_current_game_language steam_available_languages steam_activate_overlay_browser steam_activate_overlay_user steam_activate_overlay_store steam_get_user_persona_name steam_get_app_id steam_get_user_account_id steam_ugc_download steam_ugc_create_item steam_ugc_start_item_update steam_ugc_set_item_title steam_ugc_set_item_description steam_ugc_set_item_visibility steam_ugc_set_item_tags steam_ugc_set_item_content steam_ugc_set_item_preview steam_ugc_submit_item_update steam_ugc_get_item_update_progress steam_ugc_subscribe_item steam_ugc_unsubscribe_item steam_ugc_num_subscribed_items steam_ugc_get_subscribed_items steam_ugc_get_item_install_info steam_ugc_get_item_update_info steam_ugc_request_item_details steam_ugc_create_query_user steam_ugc_create_query_user_ex steam_ugc_create_query_all steam_ugc_create_query_all_ex steam_ugc_query_set_cloud_filename_filter steam_ugc_query_set_match_any_tag steam_ugc_query_set_search_text steam_ugc_query_set_ranked_by_trend_days steam_ugc_query_add_required_tag steam_ugc_query_add_excluded_tag steam_ugc_query_set_return_long_description steam_ugc_query_set_return_total_only steam_ugc_query_set_allow_cached_response steam_ugc_send_query shader_set shader_get_name shader_reset shader_current shader_is_compiled shader_get_sampler_index shader_get_uniform shader_set_uniform_i shader_set_uniform_i_array shader_set_uniform_f shader_set_uniform_f_array shader_set_uniform_matrix shader_set_uniform_matrix_array shader_enable_corner_id texture_set_stage texture_get_texel_width texture_get_texel_height shaders_are_supported vertex_format_begin vertex_format_end vertex_format_delete vertex_format_add_position vertex_format_add_position_3d vertex_format_add_colour vertex_format_add_color vertex_format_add_normal vertex_format_add_texcoord vertex_format_add_textcoord vertex_format_add_custom vertex_create_buffer vertex_create_buffer_ext vertex_delete_buffer vertex_begin vertex_end vertex_position vertex_position_3d vertex_colour vertex_color vertex_argb vertex_texcoord vertex_normal vertex_float1 vertex_float2 vertex_float3 vertex_float4 vertex_ubyte4 vertex_submit vertex_freeze vertex_get_number vertex_get_buffer_size vertex_create_buffer_from_buffer vertex_create_buffer_from_buffer_ext push_local_notification push_get_first_local_notification push_get_next_local_notification push_cancel_local_notification skeleton_animation_set skeleton_animation_get skeleton_animation_mix skeleton_animation_set_ext skeleton_animation_get_ext skeleton_animation_get_duration skeleton_animation_get_frames skeleton_animation_clear skeleton_skin_set skeleton_skin_get skeleton_attachment_set skeleton_attachment_get skeleton_attachment_create skeleton_collision_draw_set skeleton_bone_data_get skeleton_bone_data_set skeleton_bone_state_get skeleton_bone_state_set skeleton_get_minmax skeleton_get_num_bounds skeleton_get_bounds skeleton_animation_get_frame skeleton_animation_set_frame draw_skeleton draw_skeleton_time draw_skeleton_instance draw_skeleton_collision skeleton_animation_list skeleton_skin_list skeleton_slot_data layer_get_id layer_get_id_at_depth layer_get_depth layer_create layer_destroy layer_destroy_instances layer_add_instance layer_has_instance layer_set_visible layer_get_visible layer_exists layer_x layer_y layer_get_x layer_get_y layer_hspeed layer_vspeed layer_get_hspeed layer_get_vspeed layer_script_begin layer_script_end layer_shader layer_get_script_begin layer_get_script_end layer_get_shader layer_set_target_room layer_get_target_room layer_reset_target_room layer_get_all layer_get_all_elements layer_get_name layer_depth layer_get_element_layer layer_get_element_type layer_element_move layer_force_draw_depth layer_is_draw_depth_forced layer_get_forced_depth layer_background_get_id layer_background_exists layer_background_create layer_background_destroy layer_background_visible layer_background_change layer_background_sprite layer_background_htiled layer_background_vtiled layer_background_stretch layer_background_yscale layer_background_xscale layer_background_blend layer_background_alpha layer_background_index layer_background_speed layer_background_get_visible layer_background_get_sprite layer_background_get_htiled layer_background_get_vtiled layer_background_get_stretch layer_background_get_yscale layer_background_get_xscale layer_background_get_blend layer_background_get_alpha layer_background_get_index layer_background_get_speed layer_sprite_get_id layer_sprite_exists layer_sprite_create layer_sprite_destroy layer_sprite_change layer_sprite_index layer_sprite_speed layer_sprite_xscale layer_sprite_yscale layer_sprite_angle layer_sprite_blend layer_sprite_alpha layer_sprite_x layer_sprite_y layer_sprite_get_sprite layer_sprite_get_index layer_sprite_get_speed layer_sprite_get_xscale layer_sprite_get_yscale layer_sprite_get_angle layer_sprite_get_blend layer_sprite_get_alpha layer_sprite_get_x layer_sprite_get_y layer_tilemap_get_id layer_tilemap_exists layer_tilemap_create layer_tilemap_destroy tilemap_tileset tilemap_x tilemap_y tilemap_set tilemap_set_at_pixel tilemap_get_tileset tilemap_get_tile_width tilemap_get_tile_height tilemap_get_width tilemap_get_height tilemap_get_x tilemap_get_y tilemap_get tilemap_get_at_pixel tilemap_get_cell_x_at_pixel tilemap_get_cell_y_at_pixel tilemap_clear draw_tilemap draw_tile tilemap_set_global_mask tilemap_get_global_mask tilemap_set_mask tilemap_get_mask tilemap_get_frame tile_set_empty tile_set_index tile_set_flip tile_set_mirror tile_set_rotate tile_get_empty tile_get_index tile_get_flip tile_get_mirror tile_get_rotate layer_tile_exists layer_tile_create layer_tile_destroy layer_tile_change layer_tile_xscale layer_tile_yscale layer_tile_blend layer_tile_alpha layer_tile_x layer_tile_y layer_tile_region layer_tile_visible layer_tile_get_sprite layer_tile_get_xscale layer_tile_get_yscale layer_tile_get_blend layer_tile_get_alpha layer_tile_get_x layer_tile_get_y layer_tile_get_region layer_tile_get_visible layer_instance_get_instance instance_activate_layer instance_deactivate_layer camera_create camera_create_view camera_destroy camera_apply camera_get_active camera_get_default camera_set_default camera_set_view_mat camera_set_proj_mat camera_set_update_script camera_set_begin_script camera_set_end_script camera_set_view_pos camera_set_view_size camera_set_view_speed camera_set_view_border camera_set_view_angle camera_set_view_target camera_get_view_mat camera_get_proj_mat camera_get_update_script camera_get_begin_script camera_get_end_script camera_get_view_x camera_get_view_y camera_get_view_width camera_get_view_height camera_get_view_speed_x camera_get_view_speed_y camera_get_view_border_x camera_get_view_border_y camera_get_view_angle camera_get_view_target view_get_camera view_get_visible view_get_xport view_get_yport view_get_wport view_get_hport view_get_surface_id view_set_camera view_set_visible view_set_xport view_set_yport view_set_wport view_set_hport view_set_surface_id gesture_drag_time gesture_drag_distance gesture_flick_speed gesture_double_tap_time gesture_double_tap_distance gesture_pinch_distance gesture_pinch_angle_towards gesture_pinch_angle_away gesture_rotate_time gesture_rotate_angle gesture_tap_count gesture_get_drag_time gesture_get_drag_distance gesture_get_flick_speed gesture_get_double_tap_time gesture_get_double_tap_distance gesture_get_pinch_distance gesture_get_pinch_angle_towards gesture_get_pinch_angle_away gesture_get_rotate_time gesture_get_rotate_angle gesture_get_tap_count keyboard_virtual_show keyboard_virtual_hide keyboard_virtual_status keyboard_virtual_height",literal:"self other all noone global local undefined pointer_invalid pointer_null path_action_stop path_action_restart path_action_continue path_action_reverse true false pi GM_build_date GM_version GM_runtime_version timezone_local timezone_utc gamespeed_fps gamespeed_microseconds ev_create ev_destroy ev_step ev_alarm ev_keyboard ev_mouse ev_collision ev_other ev_draw ev_draw_begin ev_draw_end ev_draw_pre ev_draw_post ev_keypress ev_keyrelease ev_trigger ev_left_button ev_right_button ev_middle_button ev_no_button ev_left_press ev_right_press ev_middle_press ev_left_release ev_right_release ev_middle_release ev_mouse_enter ev_mouse_leave ev_mouse_wheel_up ev_mouse_wheel_down ev_global_left_button ev_global_right_button ev_global_middle_button ev_global_left_press ev_global_right_press ev_global_middle_press ev_global_left_release ev_global_right_release ev_global_middle_release ev_joystick1_left ev_joystick1_right ev_joystick1_up ev_joystick1_down ev_joystick1_button1 ev_joystick1_button2 ev_joystick1_button3 ev_joystick1_button4 ev_joystick1_button5 ev_joystick1_button6 ev_joystick1_button7 ev_joystick1_button8 ev_joystick2_left ev_joystick2_right ev_joystick2_up ev_joystick2_down ev_joystick2_button1 ev_joystick2_button2 ev_joystick2_button3 ev_joystick2_button4 ev_joystick2_button5 ev_joystick2_button6 ev_joystick2_button7 ev_joystick2_button8 ev_outside ev_boundary ev_game_start ev_game_end ev_room_start ev_room_end ev_no_more_lives ev_animation_end ev_end_of_path ev_no_more_health ev_close_button ev_user0 ev_user1 ev_user2 ev_user3 ev_user4 ev_user5 ev_user6 ev_user7 ev_user8 ev_user9 ev_user10 ev_user11 ev_user12 ev_user13 ev_user14 ev_user15 ev_step_normal ev_step_begin ev_step_end ev_gui ev_gui_begin ev_gui_end ev_cleanup ev_gesture ev_gesture_tap ev_gesture_double_tap ev_gesture_drag_start ev_gesture_dragging ev_gesture_drag_end ev_gesture_flick ev_gesture_pinch_start ev_gesture_pinch_in ev_gesture_pinch_out ev_gesture_pinch_end ev_gesture_rotate_start ev_gesture_rotating ev_gesture_rotate_end ev_global_gesture_tap ev_global_gesture_double_tap ev_global_gesture_drag_start ev_global_gesture_dragging ev_global_gesture_drag_end ev_global_gesture_flick ev_global_gesture_pinch_start ev_global_gesture_pinch_in ev_global_gesture_pinch_out ev_global_gesture_pinch_end ev_global_gesture_rotate_start ev_global_gesture_rotating ev_global_gesture_rotate_end vk_nokey vk_anykey vk_enter vk_return vk_shift vk_control vk_alt vk_escape vk_space vk_backspace vk_tab vk_pause vk_printscreen vk_left vk_right vk_up vk_down vk_home vk_end vk_delete vk_insert vk_pageup vk_pagedown vk_f1 vk_f2 vk_f3 vk_f4 vk_f5 vk_f6 vk_f7 vk_f8 vk_f9 vk_f10 vk_f11 vk_f12 vk_numpad0 vk_numpad1 vk_numpad2 vk_numpad3 vk_numpad4 vk_numpad5 vk_numpad6 vk_numpad7 vk_numpad8 vk_numpad9 vk_divide vk_multiply vk_subtract vk_add vk_decimal vk_lshift vk_lcontrol vk_lalt vk_rshift vk_rcontrol vk_ralt mb_any mb_none mb_left mb_right mb_middle c_aqua c_black c_blue c_dkgray c_fuchsia c_gray c_green c_lime c_ltgray c_maroon c_navy c_olive c_purple c_red c_silver c_teal c_white c_yellow c_orange fa_left fa_center fa_right fa_top fa_middle fa_bottom pr_pointlist pr_linelist pr_linestrip pr_trianglelist pr_trianglestrip pr_trianglefan bm_complex bm_normal bm_add bm_max bm_subtract bm_zero bm_one bm_src_colour bm_inv_src_colour bm_src_color bm_inv_src_color bm_src_alpha bm_inv_src_alpha bm_dest_alpha bm_inv_dest_alpha bm_dest_colour bm_inv_dest_colour bm_dest_color bm_inv_dest_color bm_src_alpha_sat tf_point tf_linear tf_anisotropic mip_off mip_on mip_markedonly audio_falloff_none audio_falloff_inverse_distance audio_falloff_inverse_distance_clamped audio_falloff_linear_distance audio_falloff_linear_distance_clamped audio_falloff_exponent_distance audio_falloff_exponent_distance_clamped audio_old_system audio_new_system audio_mono audio_stereo audio_3d cr_default cr_none cr_arrow cr_cross cr_beam cr_size_nesw cr_size_ns cr_size_nwse cr_size_we cr_uparrow cr_hourglass cr_drag cr_appstart cr_handpoint cr_size_all spritespeed_framespersecond spritespeed_framespergameframe asset_object asset_unknown asset_sprite asset_sound asset_room asset_path asset_script asset_font asset_timeline asset_tiles asset_shader fa_readonly fa_hidden fa_sysfile fa_volumeid fa_directory fa_archive ds_type_map ds_type_list ds_type_stack ds_type_queue ds_type_grid ds_type_priority ef_explosion ef_ring ef_ellipse ef_firework ef_smoke ef_smokeup ef_star ef_spark ef_flare ef_cloud ef_rain ef_snow pt_shape_pixel pt_shape_disk pt_shape_square pt_shape_line pt_shape_star pt_shape_circle pt_shape_ring pt_shape_sphere pt_shape_flare pt_shape_spark pt_shape_explosion pt_shape_cloud pt_shape_smoke pt_shape_snow ps_distr_linear ps_distr_gaussian ps_distr_invgaussian ps_shape_rectangle ps_shape_ellipse ps_shape_diamond ps_shape_line ty_real ty_string dll_cdecl dll_stdcall matrix_view matrix_projection matrix_world os_win32 os_windows os_macosx os_ios os_android os_symbian os_linux os_unknown os_winphone os_tizen os_win8native os_wiiu os_3ds os_psvita os_bb10 os_ps4 os_xboxone os_ps3 os_xbox360 os_uwp os_tvos os_switch browser_not_a_browser browser_unknown browser_ie browser_firefox browser_chrome browser_safari browser_safari_mobile browser_opera browser_tizen browser_edge browser_windows_store browser_ie_mobile device_ios_unknown device_ios_iphone device_ios_iphone_retina device_ios_ipad device_ios_ipad_retina device_ios_iphone5 device_ios_iphone6 device_ios_iphone6plus device_emulator device_tablet display_landscape display_landscape_flipped display_portrait display_portrait_flipped tm_sleep tm_countvsyncs of_challenge_win of_challen ge_lose of_challenge_tie leaderboard_type_number leaderboard_type_time_mins_secs cmpfunc_never cmpfunc_less cmpfunc_equal cmpfunc_lessequal cmpfunc_greater cmpfunc_notequal cmpfunc_greaterequal cmpfunc_always cull_noculling cull_clockwise cull_counterclockwise lighttype_dir lighttype_point iap_ev_storeload iap_ev_product iap_ev_purchase iap_ev_consume iap_ev_restore iap_storeload_ok iap_storeload_failed iap_status_uninitialised iap_status_unavailable iap_status_loading iap_status_available iap_status_processing iap_status_restoring iap_failed iap_unavailable iap_available iap_purchased iap_canceled iap_refunded fb_login_default fb_login_fallback_to_webview fb_login_no_fallback_to_webview fb_login_forcing_webview fb_login_use_system_account fb_login_forcing_safari phy_joint_anchor_1_x phy_joint_anchor_1_y phy_joint_anchor_2_x phy_joint_anchor_2_y phy_joint_reaction_force_x phy_joint_reaction_force_y phy_joint_reaction_torque phy_joint_motor_speed phy_joint_angle phy_joint_motor_torque phy_joint_max_motor_torque phy_joint_translation phy_joint_speed phy_joint_motor_force phy_joint_max_motor_force phy_joint_length_1 phy_joint_length_2 phy_joint_damping_ratio phy_joint_frequency phy_joint_lower_angle_limit phy_joint_upper_angle_limit phy_joint_angle_limits phy_joint_max_length phy_joint_max_torque phy_joint_max_force phy_debug_render_aabb phy_debug_render_collision_pairs phy_debug_render_coms phy_debug_render_core_shapes phy_debug_render_joints phy_debug_render_obb phy_debug_render_shapes phy_particle_flag_water phy_particle_flag_zombie phy_particle_flag_wall phy_particle_flag_spring phy_particle_flag_elastic phy_particle_flag_viscous phy_particle_flag_powder phy_particle_flag_tensile phy_particle_flag_colourmixing phy_particle_flag_colormixing phy_particle_group_flag_solid phy_particle_group_flag_rigid phy_particle_data_flag_typeflags phy_particle_data_flag_position phy_particle_data_flag_velocity phy_particle_data_flag_colour phy_particle_data_flag_color phy_particle_data_flag_category achievement_our_info achievement_friends_info achievement_leaderboard_info achievement_achievement_info achievement_filter_all_players achievement_filter_friends_only achievement_filter_favorites_only achievement_type_achievement_challenge achievement_type_score_challenge achievement_pic_loaded achievement_show_ui achievement_show_profile achievement_show_leaderboard achievement_show_achievement achievement_show_bank achievement_show_friend_picker achievement_show_purchase_prompt network_socket_tcp network_socket_udp network_socket_bluetooth network_type_connect network_type_disconnect network_type_data network_type_non_blocking_connect network_config_connect_timeout network_config_use_non_blocking_socket network_config_enable_reliable_udp network_config_disable_reliable_udp buffer_fixed buffer_grow buffer_wrap buffer_fast buffer_vbuffer buffer_network buffer_u8 buffer_s8 buffer_u16 buffer_s16 buffer_u32 buffer_s32 buffer_u64 buffer_f16 buffer_f32 buffer_f64 buffer_bool buffer_text buffer_string buffer_surface_copy buffer_seek_start buffer_seek_relative buffer_seek_end buffer_generalerror buffer_outofspace buffer_outofbounds buffer_invalidtype text_type button_type input_type ANSI_CHARSET DEFAULT_CHARSET EASTEUROPE_CHARSET RUSSIAN_CHARSET SYMBOL_CHARSET SHIFTJIS_CHARSET HANGEUL_CHARSET GB2312_CHARSET CHINESEBIG5_CHARSET JOHAB_CHARSET HEBREW_CHARSET ARABIC_CHARSET GREEK_CHARSET TURKISH_CHARSET VIETNAMESE_CHARSET THAI_CHARSET MAC_CHARSET BALTIC_CHARSET OEM_CHARSET gp_face1 gp_face2 gp_face3 gp_face4 gp_shoulderl gp_shoulderr gp_shoulderlb gp_shoulderrb gp_select gp_start gp_stickl gp_stickr gp_padu gp_padd gp_padl gp_padr gp_axislh gp_axislv gp_axisrh gp_axisrv ov_friends ov_community ov_players ov_settings ov_gamegroup ov_achievements lb_sort_none lb_sort_ascending lb_sort_descending lb_disp_none lb_disp_numeric lb_disp_time_sec lb_disp_time_ms ugc_result_success ugc_filetype_community ugc_filetype_microtrans ugc_visibility_public ugc_visibility_friends_only ugc_visibility_private ugc_query_RankedByVote ugc_query_RankedByPublicationDate ugc_query_AcceptedForGameRankedByAcceptanceDate ugc_query_RankedByTrend ugc_query_FavoritedByFriendsRankedByPublicationDate ugc_query_CreatedByFriendsRankedByPublicationDate ugc_query_RankedByNumTimesReported ugc_query_CreatedByFollowedUsersRankedByPublicationDate ugc_query_NotYetRated ugc_query_RankedByTotalVotesAsc ugc_query_RankedByVotesUp ugc_query_RankedByTextSearch ugc_sortorder_CreationOrderDesc ugc_sortorder_CreationOrderAsc ugc_sortorder_TitleAsc ugc_sortorder_LastUpdatedDesc ugc_sortorder_SubscriptionDateDesc ugc_sortorder_VoteScoreDesc ugc_sortorder_ForModeration ugc_list_Published ugc_list_VotedOn ugc_list_VotedUp ugc_list_VotedDown ugc_list_WillVoteLater ugc_list_Favorited ugc_list_Subscribed ugc_list_UsedOrPlayed ugc_list_Followed ugc_match_Items ugc_match_Items_Mtx ugc_match_Items_ReadyToUse ugc_match_Collections ugc_match_Artwork ugc_match_Videos ugc_match_Screenshots ugc_match_AllGuides ugc_match_WebGuides ugc_match_IntegratedGuides ugc_match_UsableInGame ugc_match_ControllerBindings vertex_usage_position vertex_usage_colour vertex_usage_color vertex_usage_normal vertex_usage_texcoord vertex_usage_textcoord vertex_usage_blendweight vertex_usage_blendindices vertex_usage_psize vertex_usage_tangent vertex_usage_binormal vertex_usage_fog vertex_usage_depth vertex_usage_sample vertex_type_float1 vertex_type_float2 vertex_type_float3 vertex_type_float4 vertex_type_colour vertex_type_color vertex_type_ubyte4 layerelementtype_undefined layerelementtype_background layerelementtype_instance layerelementtype_oldtilemap layerelementtype_sprite layerelementtype_tilemap layerelementtype_particlesystem layerelementtype_tile tile_rotate tile_flip tile_mirror tile_index_mask kbv_type_default kbv_type_ascii kbv_type_url kbv_type_email kbv_type_numbers kbv_type_phone kbv_type_phone_name kbv_returnkey_default kbv_returnkey_go kbv_returnkey_google kbv_returnkey_join kbv_returnkey_next kbv_returnkey_route kbv_returnkey_search kbv_returnkey_send kbv_returnkey_yahoo kbv_returnkey_done kbv_returnkey_continue kbv_returnkey_emergency kbv_autocapitalize_none kbv_autocapitalize_words kbv_autocapitalize_sentences kbv_autocapitalize_characters",symbol:"argument_relative argument argument0 argument1 argument2 argument3 argument4 argument5 argument6 argument7 argument8 argument9 argument10 argument11 argument12 argument13 argument14 argument15 argument_count x y xprevious yprevious xstart ystart hspeed vspeed direction speed friction gravity gravity_direction path_index path_position path_positionprevious path_speed path_scale path_orientation path_endaction object_index id solid persistent mask_index instance_count instance_id room_speed fps fps_real current_time current_year current_month current_day current_weekday current_hour current_minute current_second alarm timeline_index timeline_position timeline_speed timeline_running timeline_loop room room_first room_last room_width room_height room_caption room_persistent score lives health show_score show_lives show_health caption_score caption_lives caption_health event_type event_number event_object event_action application_surface gamemaker_pro gamemaker_registered gamemaker_version error_occurred error_last debug_mode keyboard_key keyboard_lastkey keyboard_lastchar keyboard_string mouse_x mouse_y mouse_button mouse_lastbutton cursor_sprite visible sprite_index sprite_width sprite_height sprite_xoffset sprite_yoffset image_number image_index image_speed depth image_xscale image_yscale image_angle image_alpha image_blend bbox_left bbox_right bbox_top bbox_bottom layer background_colour background_showcolour background_color background_showcolor view_enabled view_current view_visible view_xview view_yview view_wview view_hview view_xport view_yport view_wport view_hport view_angle view_hborder view_vborder view_hspeed view_vspeed view_object view_surface_id view_camera game_id game_display_name game_project_name game_save_id working_directory temp_directory program_directory browser_width browser_height os_type os_device os_browser os_version display_aa async_load delta_time webgl_enabled event_data iap_data phy_rotation phy_position_x phy_position_y phy_angular_velocity phy_linear_velocity_x phy_linear_velocity_y phy_speed_x phy_speed_y phy_speed phy_angular_damping phy_linear_damping phy_bullet phy_fixed_rotation phy_active phy_mass phy_inertia phy_com_x phy_com_y phy_dynamic phy_kinematic phy_sleeping phy_collision_points phy_collision_x phy_collision_y phy_col_normal_x phy_col_normal_y phy_position_xprevious phy_position_yprevious"},contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,e.C_NUMBER_MODE]}}}());hljs.registerLanguage("delphi",function(){"use strict";return function(e){var r="exports register file shl array record property for mod while set ally label uses raise not stored class safecall var interface or private static exit index inherited to else stdcall override shr asm far resourcestring finalization packed virtual out and protected library do xorwrite goto near function end div overload object unit begin string on inline repeat until destructor write message program with read initialization except default nil if case cdecl in downto threadvar of try pascal const external constructor type public then implementation finally published procedure absolute reintroduce operator as is abstract alias assembler bitpacked break continue cppdecl cvar enumerator experimental platform deprecated unimplemented dynamic export far16 forward generic helper implements interrupt iochecks local name nodefault noreturn nostackframe oldfpccall otherwise saveregisters softfloat specialize strict unaligned varargs ",a=[e.C_LINE_COMMENT_MODE,e.COMMENT(/\{/,/\}/,{relevance:0}),e.COMMENT(/\(\*/,/\*\)/,{relevance:10})],n={className:"meta",variants:[{begin:/\{\$/,end:/\}/},{begin:/\(\*\$/,end:/\*\)/}]},t={className:"string",begin:/'/,end:/'/,contains:[{begin:/''/}]},i={className:"string",begin:/(#\d+)+/},s={begin:e.IDENT_RE+"\\s*=\\s*class\\s*\\(",returnBegin:!0,contains:[e.TITLE_MODE]},c={className:"function",beginKeywords:"function constructor destructor procedure",end:/[:;]/,keywords:"function constructor|10 destructor|10 procedure|10",contains:[e.TITLE_MODE,{className:"params",begin:/\(/,end:/\)/,keywords:r,contains:[t,i,n].concat(a)},n].concat(a)};return{name:"Delphi",aliases:["dpr","dfm","pas","pascal","freepascal","lazarus","lpr","lfm"],case_insensitive:!0,keywords:r,illegal:/"|\$[G-Zg-z]|\/\*|<\/|\|/,contains:[t,i,e.NUMBER_MODE,{className:"number",relevance:0,variants:[{begin:"\\$[0-9A-Fa-f]+"},{begin:"&[0-7]+"},{begin:"%[01]+"}]},s,c,n].concat(a)}}}());hljs.registerLanguage("perl",function(){"use strict";return function(e){var n="getpwent getservent quotemeta msgrcv scalar kill dbmclose undef lc ma syswrite tr send umask sysopen shmwrite vec qx utime local oct semctl localtime readpipe do return format read sprintf dbmopen pop getpgrp not getpwnam rewinddir qq fileno qw endprotoent wait sethostent bless s|0 opendir continue each sleep endgrent shutdown dump chomp connect getsockname die socketpair close flock exists index shmget sub for endpwent redo lstat msgctl setpgrp abs exit select print ref gethostbyaddr unshift fcntl syscall goto getnetbyaddr join gmtime symlink semget splice x|0 getpeername recv log setsockopt cos last reverse gethostbyname getgrnam study formline endhostent times chop length gethostent getnetent pack getprotoent getservbyname rand mkdir pos chmod y|0 substr endnetent printf next open msgsnd readdir use unlink getsockopt getpriority rindex wantarray hex system getservbyport endservent int chr untie rmdir prototype tell listen fork shmread ucfirst setprotoent else sysseek link getgrgid shmctl waitpid unpack getnetbyname reset chdir grep split require caller lcfirst until warn while values shift telldir getpwuid my getprotobynumber delete and sort uc defined srand accept package seekdir getprotobyname semop our rename seek if q|0 chroot sysread setpwent no crypt getc chown sqrt write setnetent setpriority foreach tie sin msgget map stat getlogin unless elsif truncate exec keys glob tied closedir ioctl socket readlink eval xor readline binmode setservent eof ord bind alarm pipe atan2 getgrent exp time push setgrent gt lt or ne m|0 break given say state when",t={className:"subst",begin:"[$@]\\{",end:"\\}",keywords:n},s={begin:"->{",end:"}"},r={variants:[{begin:/\$\d/},{begin:/[\$%@](\^\w\b|#\w+(::\w+)*|{\w+}|\w+(::\w*)*)/},{begin:/[\$%@][^\s\w{]/,relevance:0}]},i=[e.BACKSLASH_ESCAPE,t,r],a=[r,e.HASH_COMMENT_MODE,e.COMMENT("^\\=\\w","\\=cut",{endsWithParent:!0}),s,{className:"string",contains:i,variants:[{begin:"q[qwxr]?\\s*\\(",end:"\\)",relevance:5},{begin:"q[qwxr]?\\s*\\[",end:"\\]",relevance:5},{begin:"q[qwxr]?\\s*\\{",end:"\\}",relevance:5},{begin:"q[qwxr]?\\s*\\|",end:"\\|",relevance:5},{begin:"q[qwxr]?\\s*\\<",end:"\\>",relevance:5},{begin:"qw\\s+q",end:"q",relevance:5},{begin:"'",end:"'",contains:[e.BACKSLASH_ESCAPE]},{begin:'"',end:'"'},{begin:"`",end:"`",contains:[e.BACKSLASH_ESCAPE]},{begin:"{\\w+}",contains:[],relevance:0},{begin:"-?\\w+\\s*\\=\\>",contains:[],relevance:0}]},{className:"number",begin:"(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b",relevance:0},{begin:"(\\/\\/|"+e.RE_STARTERS_RE+"|\\b(split|return|print|reverse|grep)\\b)\\s*",keywords:"split return print reverse grep",relevance:0,contains:[e.HASH_COMMENT_MODE,{className:"regexp",begin:"(s|tr|y)/(\\\\.|[^/])*/(\\\\.|[^/])*/[a-z]*",relevance:10},{className:"regexp",begin:"(m|qr)?/",end:"/[a-z]*",contains:[e.BACKSLASH_ESCAPE],relevance:0}]},{className:"function",beginKeywords:"sub",end:"(\\s*\\(.*?\\))?[;{]",excludeEnd:!0,relevance:5,contains:[e.TITLE_MODE]},{begin:"-\\w\\b",relevance:0},{begin:"^__DATA__$",end:"^__END__$",subLanguage:"mojolicious",contains:[{begin:"^@@.*",end:"$",className:"comment"}]}];return t.contains=a,s.contains=a,{name:"Perl",aliases:["pl","pm"],lexemes:/[\w\.]+/,keywords:n,contains:a}}}());hljs.registerLanguage("nginx",function(){"use strict";return function(e){var n={className:"variable",variants:[{begin:/\$\d+/},{begin:/\$\{/,end:/}/},{begin:"[\\$\\@]"+e.UNDERSCORE_IDENT_RE}]},a={endsWithParent:!0,lexemes:"[a-z/_]+",keywords:{literal:"on off yes no true false none blocked debug info notice warn error crit select break last permanent redirect kqueue rtsig epoll poll /dev/poll"},relevance:0,illegal:"=>",contains:[e.HASH_COMMENT_MODE,{className:"string",contains:[e.BACKSLASH_ESCAPE,n],variants:[{begin:/"/,end:/"/},{begin:/'/,end:/'/}]},{begin:"([a-z]+):/",end:"\\s",endsWithParent:!0,excludeEnd:!0,contains:[n]},{className:"regexp",contains:[e.BACKSLASH_ESCAPE,n],variants:[{begin:"\\s\\^",end:"\\s|{|;",returnEnd:!0},{begin:"~\\*?\\s+",end:"\\s|{|;",returnEnd:!0},{begin:"\\*(\\.[a-z\\-]+)+"},{begin:"([a-z\\-]+\\.)+\\*"}]},{className:"number",begin:"\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(:\\d{1,5})?\\b"},{className:"number",begin:"\\b\\d+[kKmMgGdshdwy]*\\b",relevance:0},n]};return{name:"Nginx config",aliases:["nginxconf"],contains:[e.HASH_COMMENT_MODE,{begin:e.UNDERSCORE_IDENT_RE+"\\s+{",returnBegin:!0,end:"{",contains:[{className:"section",begin:e.UNDERSCORE_IDENT_RE}],relevance:0},{begin:e.UNDERSCORE_IDENT_RE+"\\s",end:";|{",returnBegin:!0,contains:[{className:"attribute",begin:e.UNDERSCORE_IDENT_RE,starts:a}],relevance:0}],illegal:"[^\\s\\}]"}}}());hljs.registerLanguage("lua",function(){"use strict";return function(e){var t={begin:"\\[=*\\[",end:"\\]=*\\]",contains:["self"]},a=[e.COMMENT("--(?!\\[=*\\[)","$"),e.COMMENT("--\\[=*\\[","\\]=*\\]",{contains:[t],relevance:10})];return{name:"Lua",lexemes:e.UNDERSCORE_IDENT_RE,keywords:{literal:"true false nil",keyword:"and break do else elseif end for goto if in local not or repeat return then until while",built_in:"_G _ENV _VERSION __index __newindex __mode __call __metatable __tostring __len __gc __add __sub __mul __div __mod __pow __concat __unm __eq __lt __le assert collectgarbage dofile error getfenv getmetatable ipairs load loadfile loadstring module next pairs pcall print rawequal rawget rawset require select setfenv setmetatable tonumber tostring type unpack xpcall arg self coroutine resume yield status wrap create running debug getupvalue debug sethook getmetatable gethook setmetatable setlocal traceback setfenv getinfo setupvalue getlocal getregistry getfenv io lines write close flush open output type read stderr stdin input stdout popen tmpfile math log max acos huge ldexp pi cos tanh pow deg tan cosh sinh random randomseed frexp ceil floor rad abs sqrt modf asin min mod fmod log10 atan2 exp sin atan os exit setlocale date getenv difftime remove time clock tmpname rename execute package preload loadlib loaded loaders cpath config path seeall string sub upper len gfind rep find match char dump gmatch reverse byte format gsub lower table setn insert getn foreachi maxn foreach concat sort remove"},contains:a.concat([{className:"function",beginKeywords:"function",end:"\\)",contains:[e.inherit(e.TITLE_MODE,{begin:"([_a-zA-Z]\\w*\\.)*([_a-zA-Z]\\w*:)?[_a-zA-Z]\\w*"}),{className:"params",begin:"\\(",endsWithParent:!0,contains:a}].concat(a)},e.C_NUMBER_MODE,e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,{className:"string",begin:"\\[=*\\[",end:"\\]=*\\]",contains:[t],relevance:5}])}}}()); \ No newline at end of file diff --git a/public/vendor/highlightjs/styles/tomorrow-night.css b/public/vendor/highlightjs/styles/tomorrow-night.css new file mode 100644 index 0000000..ddd270a --- /dev/null +++ b/public/vendor/highlightjs/styles/tomorrow-night.css @@ -0,0 +1,75 @@ +/* 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; +} diff --git a/public/vendor/timeago/LICENSE b/public/vendor/timeago/LICENSE new file mode 100644 index 0000000..5690493 --- /dev/null +++ b/public/vendor/timeago/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Hust.cc + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/public/vendor/timeago/timeago.locales.min.js b/public/vendor/timeago/timeago.locales.min.js new file mode 100644 index 0000000..5378ec4 --- /dev/null +++ b/public/vendor/timeago/timeago.locales.min.js @@ -0,0 +1 @@ +!function(){"use strict";var t=[["ثانية","ثانيتين","%s ثوان","%s ثانية"],["دقيقة","دقيقتين","%s دقائق","%s دقيقة"],["ساعة","ساعتين","%s ساعات","%s ساعة"],["يوم","يومين","%s أيام","%s يوماً"],["أسبوع","أسبوعين","%s أسابيع","%s أسبوعاً"],["شهر","شهرين","%s أشهر","%s شهراً"],["عام","عامين","%s أعوام","%s عاماً"]];var e=s.bind(null,"секунду","%s секунду","%s секунды","%s секунд"),a=s.bind(null,"хвіліну","%s хвіліну","%s хвіліны","%s хвілін"),u=s.bind(null,"гадзіну","%s гадзіну","%s гадзіны","%s гадзін"),i=s.bind(null,"дзень","%s дзень","%s дні","%s дзён"),r=s.bind(null,"тыдзень","%s тыдзень","%s тыдні","%s тыдняў"),o=s.bind(null,"месяц","%s месяц","%s месяцы","%s месяцаў"),m=s.bind(null,"год","%s год","%s гады","%s гадоў");function s(s,n,e,a,u){var t=u%10,i=a;return 1===u?i=s:1===t&&20 'Changed e-mail address to %s.', + self::PERSONAL_PASSWORD_CHANGE => 'Changed account password.', + self::PERSONAL_SESSION_DESTROY => 'Ended session #%d.', + self::PERSONAL_SESSION_DESTROY_ALL => 'Ended all personal sessions.', + self::PERSONAL_DATA_DOWNLOAD => 'Downloaded archive of account data.', + + self::PASSWORD_RESET => 'Successfully used the password reset form to change password.', + + self::CHANGELOG_ENTRY_CREATE => 'Created a new changelog entry #%d.', + self::CHANGELOG_ENTRY_EDIT => 'Edited changelog entry #%d.', + self::CHANGELOG_TAG_ADD => 'Added tag #%2$d to changelog entry #%1$d.', + self::CHANGELOG_TAG_REMOVE => 'Removed tag #%2$d from changelog entry #%1$d.', + self::CHANGELOG_TAG_CREATE => 'Created new changelog tag #%d.', + self::CHANGELOG_TAG_EDIT => 'Edited changelog tag #%d.', + self::CHANGELOG_ACTION_CREATE => 'Created new changelog action #%d.', + self::CHANGELOG_ACTION_EDIT => 'Edited changelog action #%d.', + + self::COMMENT_ENTRY_DELETE => 'Deleted comment #%d.', + self::COMMENT_ENTRY_DELETE_MOD => 'Deleted comment #%d by user #%d %s.', + self::COMMENT_ENTRY_RESTORE => 'Restored comment #%d by user #%d %s.', + + self::NEWS_POST_CREATE => 'Created news post #%d.', + self::NEWS_POST_EDIT => 'Edited news post #%d.', + self::NEWS_CATEGORY_CREATE => 'Created news category #%d.', + self::NEWS_CATEGORY_EDIT => 'Edited news category #%d.', + + self::FORUM_POST_EDIT => 'Edited forum post #%d.', + self::FORUM_POST_DELETE => 'Deleted forum post #%d.', + self::FORUM_POST_RESTORE => 'Restored forum post #%d.', + self::FORUM_POST_NUKE => 'Nuked forum post #%d.', + + self::FORUM_TOPIC_DELETE => 'Deleted forum topic #%d.', + self::FORUM_TOPIC_RESTORE => 'Restored forum topic #%d.', + self::FORUM_TOPIC_NUKE => 'Nuked forum topic #%d.', + self::FORUM_TOPIC_BUMP => 'Manually bumped forum topic #%d.', + self::FORUM_TOPIC_LOCK => 'Locked forum topic #%d.', + self::FORUM_TOPIC_UNLOCK => 'Unlocked forum topic #%d.', + + self::CONFIG_CREATE => 'Created config value with name "%s".', + self::CONFIG_UPDATE => 'Updated config value with name "%s".', + self::CONFIG_DELETE => 'Deleted config value with name "%s".', + ]; + + // Database fields + private $user_id = null; + private $log_action = ''; + private $log_params = []; + private $log_created = null; + private $log_ip = '::1'; + private $log_country = 'XX'; + + private $user = null; + private $userLookedUp = false; + + public const TABLE = 'audit_log'; + private const QUERY_SELECT = 'SELECT %1$s FROM `' . DB::PREFIX . self::TABLE . '` AS '. self::TABLE; + private const SELECT = '%1$s.`user_id`, %1$s.`log_action`, %1$s.`log_params`, %1$s.`log_country`' + . ', INET6_NTOA(%1$s.`log_ip`) AS `log_ip`' + . ', UNIX_TIMESTAMP(%1$s.`log_created`) AS `log_created`'; + + public function getUserId(): int { + return $this->user_id < 1 ? -1 : $this->user_id; + } + public function getUser(): ?User { + if(!$this->userLookedUp && ($userId = $this->getUserId()) > 0) { + $this->userLookedUp = true; + try { + $this->user = User::byId($userId); + } catch(UserNotFoundException $ex) {} + } + return $this->user; + } + + public function getAction(): string { + return $this->log_action; + } + + public function getParams(): array { + if(is_string($this->log_params)) + $this->log_params = json_decode($this->log_params) ?? []; + return $this->log_params; + } + + public function getCreatedTime(): int { + return $this->log_created === null ? -1 : $this->log_created; + } + + public function getRemoteAddress(): string { + return $this->log_ip; + } + + public function getCountry(): string { + return $this->log_country; + } + public function getCountryName(): string { + return get_country_name($this->getCountry()); + } + + public function getString(): string { + if(!array_key_exists($this->getAction(), self::FORMATS)) + return sprintf('%s(%s)', $this->getAction(), json_encode($this->getParams())); + return vsprintf(self::FORMATS[$this->getAction()], $this->getParams()); + } + + public static function create(string $action, array $params = [], ?User $user = null, ?string $remoteAddr = null): void { + $user = $user ?? User::getCurrent(); + $remoteAddr = $remoteAddr ?? IPAddress::remote(); + $createLog = DB::prepare( + 'INSERT INTO `' . DB::PREFIX . self::TABLE . '` (`log_action`, `user_id`, `log_params`, `log_ip`, `log_country`)' + . ' VALUES (:action, :user, :params, INET6_ATON(:ip), :country)' + ) ->bind('action', $action) + ->bind('user', $user === null ? null : $user->getId()) // this null situation should never ever happen but better safe than sorry ! + ->bind('params', json_encode($params)) + ->bind('ip', $remoteAddr) + ->bind('country', IPAddress::country($remoteAddr)) + ->execute(); + } + + private static function countQueryBase(): string { + return sprintf(self::QUERY_SELECT, 'COUNT(*)'); + } + public static function countAll(?User $user = null): int { + $getCount = DB::prepare( + self::countQueryBase() + . ($user === null ? '' : ' WHERE `user_id` = :user') + ); + if($user !== null) + $getCount->bind('user', $user->getId()); + return (int)$getCount->fetchColumn(); + } + + private static function byQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf(self::SELECT, self::TABLE)); + } + public static function all(?Pagination $pagination = null, ?User $user = null): array { + $logsQuery = self::byQueryBase() + . ($user === null ? '' : ' WHERE `user_id` = :user') + . ' ORDER BY `log_created` DESC'; + + if($pagination !== null) + $logsQuery .= ' LIMIT :range OFFSET :offset'; + + $getLogs = DB::prepare($logsQuery); + + if($user !== null) + $getLogs->bind('user', $user->getId()); + + if($pagination !== null) + $getLogs->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getLogs->fetchObjects(self::class); + } +} diff --git a/src/AuthToken.php b/src/AuthToken.php new file mode 100644 index 0000000..785b9d2 --- /dev/null +++ b/src/AuthToken.php @@ -0,0 +1,91 @@ +getUserId() > 0 + && !empty($this->getSessionToken()); + } + + public function getUserId(): int { + return $this->userId < 1 ? -1 : $this->userId; + } + public function setUserId(int $userId): self { + $this->user = null; + $this->userId = $userId; + return $this; + } + public function getUser(): User { + if($this->user === null) + $this->user = User::byId($this->getUserId()); + return $this->user; + } + public function setUser(User $user): self { + $this->user = $user; + $this->userId = $user->getId(); + return $this; + } + + public function getSessionToken(): string { + return $this->sessionToken ?? ''; + } + public function setSessionToken(string $token): self { + $this->session = null; + $this->sessionToken = $token; + return $this; + } + public function getSession(): UserSession { + if($this->session === null) + $this->session = UserSession::byToken($this->getSessionToken()); + return $this->session; + } + public function setSession(UserSession $session): self { + $this->session = $session; + $this->sessionToken = $session->getToken(); + return $this; + } + + public function pack(bool $base64 = true): string { + $packed = pack('CNH*', self::VERSION, $this->getUserId(), $this->getSessionToken()); + if($base64) + $packed = Serialiser::uriBase64()->serialise($packed); + return $packed; + } + + public static function unpack(string $data, bool $base64 = true): self { + $obj = new AuthToken; + + if(empty($data)) + return $obj; + if($base64) + $data = Serialiser::uriBase64()->deserialise($data); + + $data = str_pad($data, self::WIDTH, "\x00"); + $data = unpack('Cversion/Nuser/H*token', $data); + + if($data['version'] >= 1) + $obj->setUserId($data['user']) + ->setSessionToken($data['token']); + + return $obj; + } + + public static function create(User $user, UserSession $session): self { + return (new AuthToken) + ->setUser($user) + ->setSession($session); + } +} diff --git a/src/CSRF.php b/src/CSRF.php new file mode 100644 index 0000000..beb15de --- /dev/null +++ b/src/CSRF.php @@ -0,0 +1,112 @@ +setTolerance($tolerance); + $this->setTimestamp($timestamp ?? self::timestamp()); + } + + public static function timestamp(): int { + return time() - self::EPOCH; + } + + public static function setGlobalIdentity(string $identity): void { + self::$globalIdentity = $identity; + } + public static function setGlobalSecretKey(string $secretKey): void { + self::$globalSecretKey = $secretKey; + } + public static function validate(string $token, ?string $identity = null, ?string $secretKey = null): bool { + try { + return self::decode($token, $identity ?? self::$globalIdentity, $secretKey ?? self::$globalSecretKey)->isValid(); + } catch(Exception $ex) { + return false; + } + } + public static function token(?string $identity = null, int $tolerance = self::TOLERANCE, ?string $secretKey = null, ?int $timestamp = null): string { + return (new static($tolerance, $timestamp))->encode($identity ?? self::$globalIdentity, $secretKey ?? self::$globalSecretKey); + } + + // Should be replaced by filters eventually < + public static function header(...$args): string { + return 'X-Misuzu-CSRF: ' . self::token(...$args); + } + public static function validateRequest($identity = null, ?string $secretKey = null): bool { + if(isset($_SERVER['HTTP_X_MISUZU_CSRF'])) { + $token = $_SERVER['HTTP_X_MISUZU_CSRF']; + } elseif(isset($_REQUEST['_csrf']) && is_string($_REQUEST['_csrf'])) { // Change this to $_POST later, it should never appear in urls + $token = $_REQUEST['_csrf']; + } elseif(isset($_REQUEST['csrf']) && is_string($_REQUEST['csrf'])) { + $token = $_REQUEST['csrf']; + } else { + return false; + } + + return self::validate($token, $identity, $secretKey); + } + // > + + public static function decode(string $token, string $identity, string $secretKey): CSRF { + $hash = substr($token, 12); + $unpacked = unpack('Vtimestamp/vtolerance', hex2bin(substr($token, 0, 12))); + + if(empty($hash) || empty($unpacked['timestamp']) || empty($unpacked['tolerance'])) + throw new InvalidArgumentException('Invalid token provided.'); + + $csrf = new static($unpacked['tolerance'], $unpacked['timestamp']); + + if(!hash_equals($csrf->getHash($identity, $secretKey), $hash)) + throw new InvalidArgumentException('Modified token.'); + + return $csrf; + } + + public function encode(string $identity, string $secretKey): string { + $token = bin2hex(pack('Vv', $this->getTimestamp(), $this->getTolerance())); + $token .= $this->getHash($identity, $secretKey); + return $token; + } + + public function getHash(string $identity, string $secretKey): string { + return hash_hmac(self::HASH_ALGO, "{$identity}|{$this->getTimestamp()}|{$this->getTolerance()}", $secretKey); + } + + public function getTimestamp(): int { + return $this->timestamp; + } + public function setTimestamp(int $timestamp): self { + if($timestamp < 0 || $timestamp > 0xFFFFFFFF) + throw new InvalidArgumentException('Timestamp must be within the constaints of an unsigned 32-bit integer.'); + $this->timestamp = $timestamp; + return $this; + } + + public function getTolerance(): int { + return $this->tolerance; + } + public function setTolerance(int $tolerance): self { + if($tolerance < 0 || $tolerance > 0xFFFF) + throw new InvalidArgumentException('Tolerance must be within the constaints of an unsigned 16-bit integer.'); + $this->tolerance = $tolerance; + return $this; + } + + public function isValid(): bool { + $currentTime = self::timestamp(); + return $currentTime >= $this->getTimestamp() && $currentTime <= $this->getTimestamp() + $this->getTolerance(); + } +} diff --git a/src/Changelog/ChangelogChange.php b/src/Changelog/ChangelogChange.php new file mode 100644 index 0000000..7b96a20 --- /dev/null +++ b/src/Changelog/ChangelogChange.php @@ -0,0 +1,281 @@ + ['unknown', 'Changed'], + self::ACTION_ADD => ['add', 'Added'], + self::ACTION_REMOVE => ['remove', 'Removed'], + self::ACTION_UPDATE => ['update', 'Updated'], + self::ACTION_FIX => ['fix', 'Fixed'], + self::ACTION_IMPORT => ['import', 'Imported'], + self::ACTION_REVERT => ['revert', 'Reverted'], + ]; + + public const DEFAULT_DATE = '0000-00-00'; + + // Database fields + private $change_id = -1; + private $user_id = null; + private $change_action = null; // defaults null apparently, probably a previous oversight + private $change_created = null; + private $change_log = ''; + private $change_text = ''; + + private $user = null; + private $userLookedUp = false; + private $comments = null; + private $tags = null; + private $tagRelations = null; + + public const TABLE = 'changelog_changes'; + private const QUERY_SELECT = 'SELECT %1$s FROM `' . DB::PREFIX . self::TABLE . '` AS '. self::TABLE; + private const SELECT = '%1$s.`change_id`, %1$s.`user_id`, %1$s.`change_action`, %1$s.`change_log`, %1$s.`change_text`' + . ', UNIX_TIMESTAMP(%1$s.`change_created`) AS `change_created`'; + + public function getId(): int { + return $this->change_id < 1 ? -1 : $this->change_id; + } + + public function getUserId(): int { + return $this->user_id < 1 ? -1 : $this->user_id; + } + public function setUserId(?int $userId): self { + $this->user_id = $userId; + $this->userLookedUp = false; + $this->user = null; + return $this; + } + public function getUser(): ?User { + if(!$this->userLookedUp && ($userId = $this->getUserId()) > 0) { + $this->userLookedUp = true; + try { + $this->user = User::byId($userId); + } catch(UserNotFoundException $ex) {} + } + return $this->user; + } + public function setUser(?User $user): self { + $this->user_id = $user === null ? null : $user->getId(); + $this->userLookedUp = true; + $this->user = $user; + return $this; + } + + public function getAction(): int { + return $this->change_action ?? self::ACTION_UNKNOWN; + } + public function setAction(int $actionId): self { + $this->change_action = $actionId; + return $this; + } + private function getActionInfo(): array { + return self::ACTION_STRINGS[$this->getAction()] ?? self::ACTION_STRINGS[self::ACTION_UNKNOWN]; + } + public function getActionClass(): string { + return $this->getActionInfo()[0]; + } + public function getActionString(): string { + return $this->getActionInfo()[1]; + } + + public function getCreatedTime(): int { + return $this->change_created ?? -1; + } + public function getDate(): string { + return ($time = $this->getCreatedTime()) < 0 ? self::DEFAULT_DATE : gmdate('Y-m-d', $time); + } + + public function getHeader(): string { + return $this->change_log; + } + public function setHeader(string $header): self { + $this->change_log = $header; + return $this; + } + + public function getBody(): string { + return $this->change_text ?? ''; + } + public function setBody(string $body): self { + $this->change_text = $body; + return $this; + } + public function hasBody(): bool { + return !empty($this->change_text); + } + public function getParsedBody(): string { + return Parser::instance(Parser::MARKDOWN)->parseText($this->getBody()); + } + + public function getCommentsCategoryName(): ?string { + return ($date = $this->getDate()) === self::DEFAULT_DATE ? null : sprintf('changelog-date-%s', $this->getDate()); + } + public function hasCommentsCategory(): bool { + return $this->getCreatedTime() >= 0; + } + public function getCommentsCategory(): CommentsCategory { + if($this->comments === null) { + $categoryName = $this->getCommentsCategoryName(); + + if(empty($categoryName)) + throw new UnexpectedValueException('Change comments category name is empty.'); + + try { + $this->comments = CommentsCategory::byName($categoryName); + } catch(CommentsCategoryNotFoundException $ex) { + $this->comments = new CommentsCategory($categoryName); + $this->comments->save(); + } + } + return $this->comments; + } + + public function getTags(): array { + if($this->tags === null) + $this->tags = ChangelogTag::byChange($this); + return $this->tags; + } + public function getTagRelations(): array { + if($this->tagRelations === null) + $this->tagRelations = ChangelogChangeTag::byChange($this); + return $this->tagRelations; + } + public function setTags(array $tags): self { + ChangelogChangeTag::purgeChange($this); + foreach($tags as $tag) + if($tag instanceof ChangelogTag) + ChangelogChangeTag::create($this, $tag); + $this->tags = $tags; + $this->tagRelations = null; + return $this; + } + public function hasTag(ChangelogTag $other): bool { + foreach($this->getTags() as $tag) + if($tag->compare($other)) + return true; + return false; + } + + public function jsonSerialize(): mixed { + return [ + 'id' => $this->getId(), + 'user' => $this->getUserId(), + 'action' => $this->getAction(), + 'header' => $this->getHeader(), + 'body' => $this->getBody(), + 'comments' => $this->getCommentsCategoryName(), + 'created' => ($time = $this->getCreatedTime()) < 0 ? null : date('c', $time), + ]; + } + + public function save(): void { + $isInsert = $this->getId() < 1; + if($isInsert) { + $query = 'INSERT INTO `%1$s%2$s` (`user_id`, `change_action`, `change_log`, `change_text`)' + . ' VALUES (:user, :action, :header, :body)'; + } else { + $query = 'UPDATE `%1$s%2$s` SET `user_id` = :user, `change_action` = :action, `change_log` = :header, `change_text` = :body' + . ' WHERE `change_id` = :change'; + } + + $saveChange = DB::prepare(sprintf($query, DB::PREFIX, self::TABLE)) + ->bind('user', $this->user_id) + ->bind('action', $this->change_action) + ->bind('header', $this->change_log) + ->bind('body', $this->change_text); + + if($isInsert) { + $this->change_id = $saveChange->executeGetId(); + $this->change_created = time(); + } else { + $saveChange->bind('change', $this->getId()) + ->execute(); + } + } + + private static function countQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf('COUNT(%s.`change_id`)', self::TABLE)); + } + public static function countAll(?int $date = null, ?User $user = null): int { + $countChanges = DB::prepare( + self::countQueryBase() + . ' WHERE 1' // this is still disgusting + . ($date === null ? '' : ' AND DATE(`change_created`) = :date') + . ($user === null ? '' : ' AND `user_id` = :user') + ); + if($date !== null) + $countChanges->bind('date', gmdate('Y-m-d', $date)); + if($user !== null) + $countChanges->bind('user', $user->getId()); + return (int)$countChanges->fetchColumn(); + } + + private static function memoizer(): Memoizer { + static $memoizer = null; + if($memoizer === null) + $memoizer = new Memoizer; + return $memoizer; + } + + private static function byQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf(self::SELECT, self::TABLE)); + } + public static function byId(int $changeId): self { + return self::memoizer()->find($changeId, function() use ($changeId) { + $change = DB::prepare(self::byQueryBase() . ' WHERE `change_id` = :change') + ->bind('change', $changeId) + ->fetchObject(self::class); + if(!$change) + throw new ChangelogChangeNotFoundException; + return $change; + }); + } + public static function all(?Pagination $pagination = null, ?int $date = null, ?User $user = null): array { + $changeQuery = self::byQueryBase() + . ' WHERE 1' // this is still disgusting + . ($date === null ? '' : ' AND DATE(`change_created`) = :date') + . ($user === null ? '' : ' AND `user_id` = :user') + . ' GROUP BY `change_created`, `change_id`' + . ' ORDER BY `change_created` DESC, `change_id` DESC'; + + if($pagination !== null) + $changeQuery .= ' LIMIT :range OFFSET :offset'; + + $getChanges = DB::prepare($changeQuery); + + if($date !== null) + $getChanges->bind('date', gmdate('Y-m-d', $date)); + + if($user !== null) + $getChanges->bind('user', $user->getId()); + + if($pagination !== null) + $getChanges->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getChanges->fetchObjects(self::class); + } +} diff --git a/src/Changelog/ChangelogChangeTag.php b/src/Changelog/ChangelogChangeTag.php new file mode 100644 index 0000000..9ddf6e6 --- /dev/null +++ b/src/Changelog/ChangelogChangeTag.php @@ -0,0 +1,96 @@ +change_id < 1 ? -1 : $this->change_id; + } + public function getChange(): ChangelogChange { + if($this->change === null) + $this->change = ChangelogChange::byId($this->getChangeId()); + return $this->change; + } + + public function getTagId(): int { + return $this->tag_id < 1 ? -1 : $this->tag_id; + } + public function getTag(): ChangelogTag { + if($this->tag === null) + $this->tag = ChangelogTag::byId($this->getTagId()); + return $this->tag; + } + + public function jsonSerialize(): mixed { + return [ + 'change' => $this->getChangeId(), + 'tag' => $this->getTagId(), + ]; + } + + public static function create(ChangelogChange $change, ChangelogTag $tag, bool $return = false): ?self { + $createRelation = DB::prepare( + 'REPLACE INTO `' . DB::PREFIX . self::TABLE . '` (`change_id`, `tag_id`)' + . ' VALUES (:change, :tag)' + )->bind('change', $change->getId())->bind('tag', $tag->getId()); + + if(!$createRelation->execute()) + throw new ChangelogChangeCreationFailedException; + if(!$return) + return null; + + return self::byExact($change, $tag); + } + + public static function purgeChange(ChangelogChange $change): void { + DB::prepare( + 'DELETE FROM `' . DB::PREFIX . self::TABLE . '` WHERE `change_id` = :change' + )->bind('change', $change->getId())->execute(); + } + + private static function countQueryBase(string $column): string { + return sprintf(self::QUERY_SELECT, sprintf('COUNT(%s.`%s`)', self::TABLE, $column)); + } + public static function countByTag(ChangelogTag $tag): int { + return (int)DB::prepare( + self::countQueryBase('change_id') + . ' WHERE `tag_id` = :tag' + )->bind('tag', $tag->getId())->fetchColumn(); + } + + private static function byQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf(self::SELECT, self::TABLE)); + } + public static function byExact(ChangelogChange $change, ChangelogTag $tag): self { + $tag = DB::prepare(self::byQueryBase() . ' WHERE `tag_id` = :tag') + ->bind('change', $change->getId()) + ->bind('tag', $tag->getId()) + ->fetchObject(self::class); + if(!$tag) + throw new ChangelogChangeTagNotFoundException; + return $tag; + } + public static function byChange(ChangelogChange $change): array { + return DB::prepare( + self::byQueryBase() + . ' WHERE `change_id` = :change' + )->bind('change', $change->getId())->fetchObjects(self::class); + } +} diff --git a/src/Changelog/ChangelogException.php b/src/Changelog/ChangelogException.php new file mode 100644 index 0000000..d7fe4ed --- /dev/null +++ b/src/Changelog/ChangelogException.php @@ -0,0 +1,6 @@ +tag_id < 1 ? -1 : $this->tag_id; + } + + public function getName(): string { + return $this->tag_name; + } + public function setName(string $name): self { + $this->tag_name = $name; + return $this; + } + + public function getDescription(): string { + return $this->tag_description; + } + public function hasDescription(): bool { + return !empty($this->tag_description); + } + public function setDescription(string $description): self { + $this->tag_description = $description; + return $this; + } + + public function getCreatedTime(): int { + return $this->tag_created ?? -1; + } + + public function getArchivedTime(): int { + return $this->tag_archived ?? -1; + } + public function isArchived(): bool { + return $this->getArchivedTime() >= 0; + } + public function setArchived(bool $archived): self { + if($this->isArchived() !== $archived) + $this->tag_archived = $archived ? time() : null; + return $this; + } + + public function getChangeCount(): int { + if($this->changeCount < 0) + $this->changeCount = ChangelogChangeTag::countByTag($this); + return $this->changeCount; + } + + public function jsonSerialize(): mixed { + return [ + 'id' => $this->getId(), + 'name' => $this->getName(), + 'description' => $this->getDescription(), + 'created' => ($time = $this->getCreatedTime()) < 0 ? null : date('c', $time), + 'archived' => ($time = $this->getArchivedTime()) < 0 ? null : date('c', $time), + ]; + } + + public function compare(ChangelogTag $other): bool { + return $other === $this || $other->getId() === $this->getId(); + } + + public function save(): void { + $isInsert = $this->getId() < 1; + if($isInsert) { + $query = 'INSERT INTO `%1$s%2$s` (`tag_name`, `tag_description`, `tag_archived`)' + . ' VALUES (:name, :description, FROM_UNIXTIME(:archived))'; + } else { + $query = 'UPDATE `%1$s%2$s` SET `tag_name` = :name, `tag_description` = :description, `tag_archived` = FROM_UNIXTIME(:archived)' + . ' WHERE `tag_id` = :tag'; + } + + $saveTag = DB::prepare(sprintf($query, DB::PREFIX, self::TABLE)) + ->bind('name', $this->tag_name) + ->bind('description', $this->tag_description) + ->bind('archived', $this->tag_archived); + + if($isInsert) { + $this->tag_id = $saveTag->executeGetId(); + $this->tag_created = time(); + } else { + $saveTag->bind('tag', $this->getId()) + ->execute(); + } + } + + private static function memoizer(): Memoizer { + static $memoizer = null; + if($memoizer === null) + $memoizer = new Memoizer; + return $memoizer; + } + + private static function byQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf(self::SELECT, self::TABLE)); + } + public static function byId(int $tagId): self { + return self::memoizer()->find($tagId, function() use ($tagId) { + $tag = DB::prepare(self::byQueryBase() . ' WHERE `tag_id` = :tag') + ->bind('tag', $tagId) + ->fetchObject(self::class); + if(!$tag) + throw new ChangelogTagNotFoundException; + return $tag; + }); + } + public static function byChange(ChangelogChange $change): array { + return DB::prepare( + self::byQueryBase() + . ' WHERE `tag_id` IN (SELECT `tag_id` FROM `' . DB::PREFIX . ChangelogChangeTag::TABLE . '` WHERE `change_id` = :change)' + )->bind('change', $change->getId())->fetchObjects(self::class); + } + public static function all(): array { + return DB::prepare(self::byQueryBase()) + ->fetchObjects(self::class); + } +} diff --git a/src/Colour.php b/src/Colour.php new file mode 100644 index 0000000..67300af --- /dev/null +++ b/src/Colour.php @@ -0,0 +1,147 @@ +setRaw($raw ?? 0); + } + + public static function none(): self { + return new Colour(self::FLAG_INHERIT); + } + + public static function fromRgb(int $red, int $green, int $blue): self { + return (new Colour)->setRed($red)->setGreen($green)->setBlue($blue); + } + public static function fromHex(string $hex): self { + return (new Colour)->setHex($hex); + } + + public function getRaw(): int { + return $this->raw; + } + public function setRaw(int $raw): self { + if($raw < 0 || $raw > 0x7FFFFFFF) + throw new InvalidArgumentException('Invalid raw colour.'); + $this->raw = $raw; + return $this; + } + + public function getInherit(): bool { + return ($this->getRaw() & self::FLAG_INHERIT) > 0; + } + public function setInherit(bool $inherit): self { + $raw = $this->getRaw(); + + if($inherit) + $raw |= self::FLAG_INHERIT; + else + $raw &= ~self::FLAG_INHERIT; + + $this->setRaw($raw); + + return $this; + } + + public function getRed(): int { + return ($this->getRaw() & 0xFF0000) >> 16; + } + public function setRed(int $red): self { + if($red < 0 || $red > 0xFF) + throw new InvalidArgumentException('Invalid red value.'); + + $raw = $this->getRaw(); + $raw &= ~0xFF0000; + $raw |= $red << 16; + $this->setRaw($raw); + + return $this; + } + + public function getGreen(): int { + return ($this->getRaw() & 0xFF00) >> 8; + } + public function setGreen(int $green): self { + if($green < 0 || $green > 0xFF) + throw new InvalidArgumentException('Invalid green value.'); + + $raw = $this->getRaw(); + $raw &= ~0xFF00; + $raw |= $green << 8; + $this->setRaw($raw); + + return $this; + } + + public function getBlue(): int { + return ($this->getRaw() & 0xFF); + } + public function setBlue(int $blue): self { + if($blue < 0 || $blue > 0xFF) + throw new InvalidArgumentException('Invalid blue value.'); + + $raw = $this->getRaw(); + $raw &= ~0xFF; + $raw |= $blue; + $this->setRaw($raw); + + return $this; + } + + public function getLuminance(): float { + return self::LUMINANCE_WEIGHT_RED * $this->getRed() + + self::LUMINANCE_WEIGHT_GREEN * $this->getGreen() + + self::LUMINANCE_WEIGHT_BLUE * $this->getBlue(); + } + + public function getHex(): string { + return str_pad(dechex($this->getRaw() & 0xFFFFFF), 6, '0', STR_PAD_LEFT); + } + public function setHex(string $hex): self { + if($hex[0] === '#') + $hex = mb_substr($hex, 1); + + if(!ctype_xdigit($hex)) + throw new InvalidArgumentException('Argument contains invalid characters.'); + + $length = mb_strlen($hex); + + if($length === 3) { + $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; + } elseif($length !== 6) { + throw new InvalidArgumentException('Argument is not a hex string.'); + } + + return $this->setRaw(hexdec($hex)); + } + + public function getCSS(): string { + if($this->getInherit()) + return 'inherit'; + return '#' . $this->getHex(); + } + + public function extractCSSContract( + string $dark = 'dark', string $light = 'light', bool $inheritIsDark = true + ): string { + if($this->getInherit()) + return $inheritIsDark ? $dark : $light; + + return $this->getLuminance() > self::READABILITY_THRESHOLD ? $dark : $light; + } + + public function __toString() { + return $this->getCSS(); + } +} diff --git a/src/Comments/CommentsCategory.php b/src/Comments/CommentsCategory.php new file mode 100644 index 0000000..d7aad4b --- /dev/null +++ b/src/Comments/CommentsCategory.php @@ -0,0 +1,177 @@ +setName($name); + } + + public function getId(): int { + return $this->category_id < 1 ? -1 : $this->category_id; + } + + public function getName(): string { + return $this->category_name; + } + public function setName(string $name): self { + $this->category_name = $name; + return $this; + } + + public function getOwnerId(): int { + return $this->owner_id < 1 ? -1 : $this->owner_id; + } + public function hasOwner(): bool { + return $this->owner_id !== null; + } + public function getOwner(): User { + if($this->owner === null && ($ownerId = $this->getOwnerId()) >= 1) + $this->owner = User::byId($ownerId); + return $this->owner; + } + public function isOwner(User $user): bool { + return $this->hasOwner() && $user->getId() === $this->getOwnerId(); + } + + public function getCreatedTime(): int { + return $this->category_created === null ? -1 : $this->category_created; + } + + public function getLockedTime(): int { + return $this->category_locked === null ? -1 : $this->category_locked; + } + public function isLocked(): bool { + return $this->getLockedTime() >= 0; + } + public function setLocked(bool $locked): self { + if($locked !== $this->isLocked()) + $this->category_locked = $locked ? time() : null; + return $this; + } + + // Purely cosmetic, do not use for anything other than displaying + public function getPostCount(): int { + if($this->postCount < 0) + $this->postCount = (int)DB::prepare(' + SELECT COUNT(`comment_id`) + FROM `msz_comments_posts` + WHERE `category_id` = :cat_id + AND `comment_deleted` IS NULL + ')->bind('cat_id', $this->getId())->fetchColumn(); + + return $this->postCount; + } + + public function jsonSerialize(): mixed { + return [ + 'id' => $this->getId(), + 'name' => $this->getName(), + 'created' => ($created = $this->getCreatedTime()) < 0 ? null : date('c', $created), + 'locked' => ($locked = $this->getLockedTime()) < 0 ? null : date('c', $locked), + ]; + } + + public function save(): void { + $isInsert = $this->getId() < 1; + if($isInsert) { + $query = 'INSERT INTO `%1$s%2$s` (`category_name`, `category_locked`) VALUES' + . ' (:name, :locked)'; + } else { + $query = 'UPDATE `%1$s%2$s` SET `category_name` = :name, `category_locked` = FROM_UNIXTIME(:locked)' + . ' WHERE `category_id` = :category'; + } + + $saveCategory = DB::prepare(sprintf($query, DB::PREFIX, self::TABLE)) + ->bind('name', $this->category_name) + ->bind('locked', $this->category_locked); + + if($isInsert) { + $this->category_id = $saveCategory->executeGetId(); + $this->category_created = time(); + } else { + $saveCategory->bind('category', $this->getId()) + ->execute(); + } + } + + public function posts(?User $voteUser = null, bool $includeVotes = true, ?Pagination $pagination = null, bool $rootOnly = true, bool $includeDeleted = true): array { + return CommentsPost::byCategory($this, $voteUser, $includeVotes, $pagination, $rootOnly, $includeDeleted); + } + public function votes(?User $user = null, bool $rootOnly = true, ?Pagination $pagination = null): array { + return CommentsVote::byCategory($this, $user, $rootOnly, $pagination); + } + + private static function memoizer() { + static $memoizer = null; + if($memoizer === null) + $memoizer = new Memoizer; + return $memoizer; + } + + private static function byQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf(self::SELECT, self::TABLE)); + } + public static function byId(int $categoryId): self { + return self::memoizer()->find($categoryId, function() use ($categoryId) { + $cat = DB::prepare(self::byQueryBase() . ' WHERE `category_id` = :cat_id') + ->bind('cat_id', $categoryId) + ->fetchObject(self::class); + if(!$cat) + throw new CommentsCategoryNotFoundException; + return $cat; + }); + } + public static function byName(string $categoryName): self { + return self::memoizer()->find(function($category) use ($categoryName) { + return $category->getName() === $categoryName; + }, function() use ($categoryName) { + $cat = DB::prepare(self::byQueryBase() . ' WHERE `category_name` = :name') + ->bind('name', $categoryName) + ->fetchObject(self::class); + if(!$cat) + throw new CommentsCategoryNotFoundException; + return $cat; + }); + } + public static function all(?Pagination $pagination = null): array { + $catsQuery = self::byQueryBase() + . ' ORDER BY `category_id` ASC'; + + if($pagination !== null) + $catsQuery .= ' LIMIT :range OFFSET :offset'; + + $getCats = DB::prepare($catsQuery); + + if($pagination !== null) + $getCats->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getCats->fetchObjects(self::class); + } +} diff --git a/src/Comments/CommentsException.php b/src/Comments/CommentsException.php new file mode 100644 index 0000000..adaa76d --- /dev/null +++ b/src/Comments/CommentsException.php @@ -0,0 +1,6 @@ +getId()); + } catch(UserNotFoundException $ex) { + return $matches[0]; + } + }, $text); + } + + public static function parseForDisplay(string $text): string { + $text = htmlentities($text); + + $text = preg_replace_callback( + '/(^|[\n ])([\w]*?)([\w]*?:\/\/[\w]+[^ \,\"\n\r\t<]*)/is', + function ($matches) { + $matches[0] = trim($matches[0]); + $url = parse_url($matches[0]); + if(empty($url['scheme']) || !in_array(mb_strtolower($url['scheme']), ['http', 'https'], true)) + return $matches[0]; + return sprintf(' %1$s', $matches[0]); + }, + $text + ); + + $text = preg_replace_callback(self::MARKUP_USERID, function ($matches) { + $getInfo = DB::prepare(' + SELECT + u.`user_id`, u.`username`, + COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour` + FROM `msz_users` as u + LEFT JOIN `msz_roles` as r + ON u.`display_role` = r.`role_id` + WHERE `user_id` = :user_id + '); + $getInfo->bind('user_id', $matches[1]); + $info = $getInfo->fetch(); + + if(empty($info)) + return $matches[0]; + + return sprintf( + '@%s', + url('user-profile', ['user' => $info['user_id']]), + html_colour($info['user_colour']), + $info['username'] + ); + }, $text); + + return nl2br($text); + } +} diff --git a/src/Comments/CommentsPost.php b/src/Comments/CommentsPost.php new file mode 100644 index 0000000..65847d8 --- /dev/null +++ b/src/Comments/CommentsPost.php @@ -0,0 +1,351 @@ +comment_id < 1 ? -1 : $this->comment_id; + } + + public function getCategoryId(): int { + return $this->category_id < 1 ? -1 : $this->category_id; + } + public function setCategoryId(int $categoryId): self { + $this->category_id = $categoryId; + $this->category = null; + return $this; + } + public function getCategory(): CommentsCategory { + if($this->category === null) + $this->category = CommentsCategory::byId($this->getCategoryId()); + return $this->category; + } + public function setCategory(CommentsCategory $category): self { + $this->category_id = $category->getId(); + $this->category = null; + return $this; + } + + public function getUserId(): int { + return $this->user_id < 1 ? -1 : $this->user_id; + } + public function setUserId(int $userId): self { + $this->user_id = $userId < 1 ? null : $userId; + $this->userLookedUp = false; + $this->user = null; + return $this; + } + public function getUser(): ?User { + if(!$this->userLookedUp && ($userId = $this->getUserId()) > 0) { + $this->userLookedUp = true; + try { + $this->user = User::byId($userId); + } catch(UserNotFoundException $ex) {} + } + return $this->user; + } + public function setUser(?User $user): self { + $this->user_id = $user === null ? null : $user->getId(); + $this->userLookedUp = true; + $this->user = $user; + return $this; + } + + public function getParentId(): int { + return $this->comment_reply_to < 1 ? -1 : $this->comment_reply_to; + } + public function setParentId(int $parentId): self { + $this->comment_reply_to = $parentId < 1 ? null : $parentId; + $this->parentPost = null; + return $this; + } + public function hasParent(): bool { + return $this->getParentId() > 0; + } + public function getParent(): CommentsPost { + if(!$this->hasParent()) + throw new CommentsPostHasNoParentException; + if($this->parentPost === null) + $this->parentPost = CommentsPost::byId($this->getParentId()); + return $this->parentPost; + } + public function setParent(?CommentsPost $parent): self { + $this->comment_reply_to = $parent === null ? null : $parent->getId(); + $this->parentPost = $parent; + return $this; + } + + public function getText(): string { + return $this->comment_text; + } + public function setText(string $text): self { + $this->comment_text = $text; + return $this; + } + public function getParsedText(): string { + return CommentsParser::parseForDisplay($this->getText()); + } + public function setParsedText(string $text): self { + return $this->setText(CommentsParser::parseForStorage($text)); + } + + public function getCreatedTime(): int { + return $this->comment_created === null ? -1 : $this->comment_created; + } + + public function getPinnedTime(): int { + return $this->comment_pinned === null ? -1 : $this->comment_pinned; + } + public function isPinned(): bool { + return $this->getPinnedTime() >= 0; + } + public function setPinned(bool $pinned): self { + if($this->isPinned() !== $pinned) + $this->comment_pinned = $pinned ? time() : null; + return $this; + } + + public function getEditedTime(): int { + return $this->comment_edited === null ? -1 : $this->comment_edited; + } + public function isEdited(): bool { + return $this->getEditedTime() >= 0; + } + + public function getDeletedTime(): int { + return $this->comment_deleted === null ? -1 : $this->comment_deleted; + } + public function isDeleted(): bool { + return $this->getDeletedTime() >= 0; + } + public function setDeleted(bool $deleted): self { + if($this->isDeleted() !== $deleted) + $this->comment_deleted = $deleted ? time() : null; + return $this; + } + + public function getLikes(): int { + return $this->comment_likes; + } + public function getDislikes(): int { + return $this->comment_dislikes; + } + + public function hasUserVote(): bool { + return $this->user_vote !== null; + } + public function getUserVote(): int { + return $this->user_vote ?? 0; + } + + public function jsonSerialize(): mixed { + $json = [ + 'id' => $this->getId(), + 'category' => $this->getCategoryId(), + 'user' => $this->getUserId(), + 'parent' => ($parent = $this->getParentId()) < 1 ? null : $parent, + 'text' => $this->getText(), + 'created' => ($created = $this->getCreatedTime()) < 0 ? null : date('c', $created), + 'pinned' => ($pinned = $this->getPinnedTime()) < 0 ? null : date('c', $pinned), + 'edited' => ($edited = $this->getEditedTime()) < 0 ? null : date('c', $edited), + 'deleted' => ($deleted = $this->getDeletedTime()) < 0 ? null : date('c', $deleted), + ]; + + if(($likes = $this->getLikes()) >= 0) + $json['likes'] = $likes; + if(($dislikes = $this->getDislikes()) >= 0) + $json['dislikes'] = $dislikes; + + if($this->hasUserVote()) + $json['user_vote'] = $this->getUserVote(); + + return $json; + } + + public function save(): void { + $isInsert = $this->getId() < 1; + if($isInsert) { + $query = 'INSERT INTO `%1$s%2$s` (`category_id`, `user_id`, `comment_reply_to`, `comment_text`' + . ', `comment_pinned`, `comment_deleted`) VALUES' + . ' (:category, :user, :parent, :text, FROM_UNIXTIME(:pinned), FROM_UNIXTIME(:deleted))'; + } else { + $query = 'UPDATE `%1$s%2$s` SET `category_id` = :category, `user_id` = :user, `comment_reply_to` = :parent' + . ', `comment_text` = :text, `comment_pinned` = FROM_UNIXTIME(:pinned), `comment_deleted` = FROM_UNIXTIME(:deleted)' + . ' WHERE `comment_id` = :post'; + } + + $savePost = DB::prepare(sprintf($query, DB::PREFIX, self::TABLE)) + ->bind('category', $this->category_id) + ->bind('user', $this->user_id) + ->bind('parent', $this->comment_reply_to) + ->bind('text', $this->comment_text) + ->bind('pinned', $this->comment_pinned) + ->bind('deleted', $this->comment_deleted); + + if($isInsert) { + $this->comment_id = $savePost->executeGetId(); + if($this->comment_id < 1) + throw new CommentsPostSaveFailedException; + $this->comment_created = time(); + } else { + $this->comment_edited = time(); + $savePost->bind('post', $this->getId()); + if(!$savePost->execute()) + throw new CommentsPostSaveFailedException; + } + } + + public function nuke(): void { + $replies = $this->replies(null, true); + foreach($replies as $reply) + $reply->nuke(); + DB::prepare('DELETE FROM `' . DB::PREFIX . self::TABLE . '` WHERE `comment_id` = :comment') + ->bind('comment_id', $this->getId()) + ->execute(); + } + + public function replies(?User $voteUser = null, bool $includeVotes = true, ?Pagination $pagination = null, bool $includeDeleted = true): array { + return CommentsPost::byParent($this, $voteUser, $includeVotes, $pagination, $includeDeleted); + } + public function votes(): CommentsVoteCount { + return CommentsVote::countByPost($this); + } + public function childVotes(?User $user = null, ?Pagination $pagination = null): array { + return CommentsVote::byParent($this, $user, $pagination); + } + + public function addPositiveVote(User $user): void { + CommentsVote::create($this, $user, CommentsVote::LIKE); + } + public function addNegativeVote(User $user): void { + CommentsVote::create($this, $user, CommentsVote::DISLIKE); + } + public function removeVote(User $user): void { + CommentsVote::delete($this, $user); + } + + public function getVoteFromUser(User $user): CommentsVote { + return CommentsVote::byExact($this, $user); + } + + private static function byQueryBase(bool $includeVotes = true, bool $includeUserVote = false): string { + $select = self::SELECT; + if($includeVotes) + $select .= ', ' . self::LIKE_VOTE_SELECT + . ', ' . self::DISLIKE_VOTE_SELECT; + if($includeUserVote) + $select .= ', ' . self::USER_VOTE_SELECT; + return sprintf(self::QUERY_SELECT, sprintf($select, self::TABLE)); + } + public static function byId(int $postId): self { + $getPost = DB::prepare(self::byQueryBase() . ' WHERE `comment_id` = :post_id'); + $getPost->bind('post_id', $postId); + $post = $getPost->fetchObject(self::class); + if(!$post) + throw new CommentsPostNotFoundException; + return $post; + } + public static function byCategory(CommentsCategory $category, ?User $voteUser = null, bool $includeVotes = true, ?Pagination $pagination = null, bool $rootOnly = true, bool $includeDeleted = true): array { + $postsQuery = self::byQueryBase($includeVotes, $voteUser !== null) + . ' WHERE `category_id` = :category' + . (!$rootOnly ? '' : ' AND `comment_reply_to` IS NULL') + . ($includeDeleted ? '' : ' AND `comment_deleted` IS NULL') + . ' ORDER BY `comment_deleted` ASC, `comment_pinned` DESC, `comment_id` DESC'; + + if($pagination !== null) + $postsQuery .= ' LIMIT :range OFFSET :offset'; + + $getPosts = DB::prepare($postsQuery) + ->bind('category', $category->getId()); + + if($voteUser !== null) + $getPosts->bind('user', $voteUser->getId()); + + if($pagination !== null) + $getPosts->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getPosts->fetchObjects(self::class); + } + public static function byParent(CommentsPost $parent, ?User $voteUser = null, bool $includeVotes = true, ?Pagination $pagination = null, bool $includeDeleted = true): array { + $postsQuery = self::byQueryBase($includeVotes, $voteUser !== null) + . ' WHERE `comment_reply_to` = :parent' + . ($includeDeleted ? '' : ' AND `comment_deleted` IS NULL') + . ' ORDER BY `comment_deleted` ASC, `comment_pinned` DESC, `comment_id` ASC'; + + if($pagination !== null) + $postsQuery .= ' LIMIT :range OFFSET :offset'; + + $getPosts = DB::prepare($postsQuery) + ->bind('parent', $parent->getId()); + + if($voteUser !== null) + $getPosts->bind('user', $voteUser->getId()); + + if($pagination !== null) + $getPosts->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getPosts->fetchObjects(self::class); + } + public static function all(?Pagination $pagination = null, bool $rootOnly = true, bool $includeDeleted = false): array { + $postsQuery = self::byQueryBase() + . ' WHERE 1' // this is disgusting + . (!$rootOnly ? '' : ' AND `comment_reply_to` IS NULL') + . ($includeDeleted ? '' : ' AND `comment_deleted` IS NULL') + . ' ORDER BY `comment_id` DESC'; + + if($pagination !== null) + $postsQuery .= ' LIMIT :range OFFSET :offset'; + + $getPosts = DB::prepare($postsQuery); + + if($pagination !== null) + $getPosts->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getPosts->fetchObjects(self::class); + } +} diff --git a/src/Comments/CommentsVote.php b/src/Comments/CommentsVote.php new file mode 100644 index 0000000..0ab2bd9 --- /dev/null +++ b/src/Comments/CommentsVote.php @@ -0,0 +1,246 @@ +comment_id < 1 ? -1 : $this->comment_id; + } + public function getLikes(): int { + return $this->likes; + } + public function getDislikes(): int { + return $this->dislikes; + } + public function getTotal(): int { + return $this->total; + } + + public function jsonSerialize(): mixed { + return [ + 'id' => $this->getPostId(), + 'likes' => $this->getLikes(), + 'dislikes' => $this->getDislikes(), + 'total' => $this->getTotal(), + ]; + } +} + +class CommentsVote implements JsonSerializable { + // Database fields + private $comment_id = -1; + private $user_id = -1; + private $comment_vote = 0; + + private $comment = null; + private $user = null; + + public const LIKE = 1; + public const NONE = 0; + public const DISLIKE = -1; + + public const TABLE = 'comments_votes'; + private const QUERY_SELECT = 'SELECT %1$s FROM `' . DB::PREFIX . self::TABLE . '` AS '. self::TABLE; + private const SELECT = '%1$s.`comment_id`, %1$s.`user_id`, %1$s.`comment_vote`'; + + private const QUERY_COUNT = 'SELECT %3$d AS `comment_id`' + . ', (SELECT COUNT(`comment_id`) FROM `%1$s%2$s` WHERE %6$s) AS `total`' + . ', (SELECT COUNT(`comment_id`) FROM `%1$s%2$s` WHERE %6$s AND `comment_vote` = %4$d) AS `likes`' + . ', (SELECT COUNT(`comment_id`) FROM `%1$s%2$s` WHERE %6$s AND `comment_vote` = %5$d) AS `dislikes`'; + + public function getPostId(): int { + return $this->comment_id < 1 ? -1 : $this->comment_id; + } + public function getPost(): CommentsPost { + if($this->comment === null) + $this->comment = CommentsPost::byId($this->comment_id); + return $this->comment; + } + + public function getUserId(): int { + return $this->user_id < 1 ? -1 : $this->user_id; + } + public function getUser(): User { + if($this->user === null) + $this->user = User::byId($this->user_id); + return $this->user; + } + + public function getVote(): int { + return $this->comment_vote; + } + + public function jsonSerialize(): mixed { + return [ + 'post' => $this->getPostId(), + 'user' => $this->getUserId(), + 'vote' => $this->getVote(), + ]; + } + + public static function create(CommentsPost $post, User $user, int $vote, bool $return = false): ?self { + $createVote = DB::prepare(' + REPLACE INTO `msz_comments_votes` + (`comment_id`, `user_id`, `comment_vote`) + VALUES + (:post, :user, :vote) + ') ->bind('post', $post->getId()) + ->bind('user', $user->getId()) + ->bind('vote', $vote); + + if(!$createVote->execute()) + throw new CommentsVoteCreateFailedException; + if(!$return) + return null; + + return self::byExact($post, $user); + } + + public static function delete(CommentsPost $post, User $user): void { + DB::prepare('DELETE FROM `msz_comments_votes` WHERE `comment_id` = :post AND `user_id` = :user') + ->bind('post', $post->getId()) + ->bind('user', $user->getId()) + ->execute(); + } + + private static function countQueryBase(int $id, string $condition = '1'): string { + return sprintf(self::QUERY_COUNT, DB::PREFIX, self::TABLE, $id, self::LIKE, self::DISLIKE, $condition); + } + public static function countByPost(CommentsPost $post): CommentsVoteCount { + $count = DB::prepare(self::countQueryBase($post->getId(), sprintf('`comment_id` = %d', $post->getId()))) + ->fetchObject(CommentsVoteCount::class); + if(!$count) + throw new CommentsVoteCountFailedException; + return $count; + } + + private static function fake(CommentsPost $post, User $user, int $vote): CommentsVote { + $fake = new CommentsVote; + $fake->comment_id = $post->getId(); + $fake->comment = $post; + $fake->user_id = $user->getId(); + $fake->user = $user; + $fake->comment_vote = $vote; + return $fake; + } + + private static function byQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf(self::SELECT, self::TABLE)); + } + public static function byExact(CommentsPost $post, User $user): self { + $vote = DB::prepare(self::byQueryBase() . ' WHERE `comment_id` = :post_id AND `user_id` = :user_id') + ->bind('post_id', $post->getId()) + ->bind('user_id', $user->getId()) + ->fetchObject(self::class); + if(!$vote) + return self::fake($post, $user, self::NONE); + return $vote; + } + public static function byPost(CommentsPost $post, ?User $user = null, ?Pagination $pagination = null): array { + $votesQuery = self::byQueryBase() + . ' WHERE `comment_id` = :post' + . ($user === null ? '' : ' AND `user_id` = :user'); + + if($pagination !== null) + $votesQuery .= ' LIMIT :range OFFSET :offset'; + + $getVotes = DB::prepare($votesQuery) + ->bind('post', $post->getId()); + + if($user !== null) + $getVotes->bind('user', $user->getId()); + + if($pagination !== null) + $getVotes->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getVotes->fetchObjects(self::class); + } + public static function byUser(User $user, ?Pagination $pagination = null): array { + $votesQuery = self::byQueryBase() + . ' WHERE `user_id` = :user'; + + if($pagination !== null) + $votesQuery .= ' LIMIT :range OFFSET :offset'; + + $getVotes = DB::prepare($votesQuery) + ->bind('user', $user->getId()); + + if($pagination !== null) + $getVotes->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getVotes->fetchObjects(self::class); + } + public static function byCategory(CommentsCategory $category, ?User $user = null, bool $rootOnly = true, ?Pagination $pagination = null): array { + $votesQuery = self::byQueryBase() + . ' WHERE `comment_id` IN' + . ' (SELECT `comment_id` FROM `' . DB::PREFIX . CommentsPost::TABLE . '` WHERE `category_id` = :category' + . (!$rootOnly ? '' : ' AND `comment_reply_to` IS NULL') + . ')' + . ($user === null ? '' : ' AND `user_id` = :user'); + + if($pagination !== null) + $votesQuery .= ' LIMIT :range OFFSET :offset'; + + $getVotes = DB::prepare($votesQuery) + ->bind('category', $category->getId()); + + if($user !== null) + $getVotes->bind('user', $user->getId()); + + if($pagination !== null) + $getVotes->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getVotes->fetchObjects(self::class); + } + public static function byParent(CommentsPost $parent, ?User $user = null, ?Pagination $pagination = null): array { + $votesQuery = self::byQueryBase() + . ' WHERE `comment_id` IN' + . ' (SELECT `comment_id` FROM `' . DB::PREFIX . CommentsPost::TABLE . '` WHERE `comment_reply_to` = :parent)' + . ($user === null ? '' : ' AND `user_id` = :user'); + + if($pagination !== null) + $votesQuery .= ' LIMIT :range OFFSET :offset'; + + $getVotes = DB::prepare($votesQuery) + ->bind('parent', $parent->getId()); + + if($user !== null) + $getVotes->bind('user', $user->getId()); + + if($pagination !== null) + $getVotes->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getVotes->fetchObjects(self::class); + } + public static function all(?Pagination $pagination = null): array { + $votesQuery = self::byQueryBase(); + + if($pagination !== null) + $votesQuery .= ' LIMIT :range OFFSET :offset'; + + $getVotes = DB::prepare($votesQuery); + + if($pagination !== null) + $getVotes->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getVotes->fetchObjects(self::class); + } +} diff --git a/src/Config.php b/src/Config.php new file mode 100644 index 0000000..4664ae9 --- /dev/null +++ b/src/Config.php @@ -0,0 +1,97 @@ + null, + self::TYPE_STR => '', + self::TYPE_INT => 0, + self::TYPE_BOOL => false, + self::TYPE_ARR => [], + ]; + + private static $config = []; + + public static function init(): void { + try { + $config = DB::prepare('SELECT * FROM `msz_config`')->fetchAll(); + } catch(PDOException $ex) { + return; + } + + + foreach($config as $record) { + self::$config[$record['config_name']] = unserialize($record['config_value']); + } + } + + public static function keys(): array { + return array_keys(self::$config); + } + + public static function type($value): string { + return gettype($value); + } + + public static function isValidType(string $type): bool { + return $type === self::TYPE_ARR + || $type === self::TYPE_BOOL + || $type === self::TYPE_INT + || $type === self::TYPE_STR; + } + + public static function validateName(string $name): bool { + // this should better validate the format, this allows for a lot of shittery + return preg_match('#^([a-z][a-zA-Z0-9._]+)$#', $name) === 1; + } + + public static function default(string $type) { + return self::DEFAULTS[$type] ?? null; + } + + public static function get(string $key, string $type = self::TYPE_ANY, $default = null) { + $value = self::$config[$key] ?? null; + + if($type !== self::TYPE_ANY && gettype($value) !== $type) + $value = null; + + return $value ?? $default ?? self::DEFAULTS[$type]; + } + + public static function has(string $key): bool { + return array_key_exists($key, self::$config); + } + + public static function set(string $key, $value, bool $soft = false): void { + self::$config[$key] = $value; + + if(!$soft) { + $value = serialize($value); + + DB::prepare(' + REPLACE INTO `msz_config` + (`config_name`, `config_value`) + VALUES + (:name, :value) + ')->bind('name', $key) + ->bind('value', $value) + ->execute(); + } + } + + public static function remove(string $key, bool $soft = false): void { + unset(self::$config[$key]); + + if(!$soft) + DB::prepare('DELETE FROM `msz_config` WHERE `config_name` = :name')->bind('name', $key)->execute(); + } +} diff --git a/src/Console/CommandArgs.php b/src/Console/CommandArgs.php new file mode 100644 index 0000000..c97c1ad --- /dev/null +++ b/src/Console/CommandArgs.php @@ -0,0 +1,49 @@ +args = $args; + } + + public function getArgs(): array { + return array_slice($this->args, 2); + } + + public function getArgCount(): int { + return count($this->args) - 2; + } + + public function getCommand(): string { + return $this->args[1] ?? ''; + } + + public function getArg(int $index): string { + return $this->args[2 + $index] ?? ''; + } + + public function flagIndex(string $long, string $short = ''): int { + $long = '--' . $long; + $short = '-' . $short; + for($i = 2; $i < count($this->args); ++$i) + if(($long !== '--' && $this->args[$i] === $long) || ($short !== '-' && $short === $this->args[$i])) + return $i; + return -1; + } + + public function hasFlag(string $long, string $short = ''): bool { + return $this->flagIndex($long, $short) >= 0; + } + + public function getFlag(string $long, string $short = ''): string { + $index = $this->flagIndex($long, $short); + if($index < 0) + return ''; + $arg = $this->args[$index + 1] ?? ''; + if($arg[0] == '-') + return ''; + return $arg; + } +} diff --git a/src/Console/CommandCollection.php b/src/Console/CommandCollection.php new file mode 100644 index 0000000..9d0820b --- /dev/null +++ b/src/Console/CommandCollection.php @@ -0,0 +1,33 @@ +matchCommand($command->getName()); + } catch(CommandNotFoundException $ex) { + $this->commands[] = $command; + } + } + + public function matchCommand(string $name): CommandInterface { + foreach($this->commands as $command) + if($command->getName() === $name) + return $command; + throw new CommandNotFoundException; + } + + public function dispatch(CommandArgs $args): void { + try { + $this->matchCommand($args->getCommand())->dispatch($args); + } catch(CommandNotFoundException $ex) { + echo 'Command not found.' . PHP_EOL; + } + } +} diff --git a/src/Console/CommandDispatchInterface.php b/src/Console/CommandDispatchInterface.php new file mode 100644 index 0000000..7b0074e --- /dev/null +++ b/src/Console/CommandDispatchInterface.php @@ -0,0 +1,6 @@ +hasFlag('slow'); + + foreach(self::TASKS as $task) { + if($runSlow || empty($task['slow'])) { + echo $task['name'] . PHP_EOL; + + switch($task['type']) { + case 'sql': + DB::exec($task['command']); + break; + + case 'func': + call_user_func($task['command']); + break; + } + } + } + } + + private const TASKS = [ + [ + 'name' => 'Ensures main role exists.', + 'type' => 'sql', + 'slow' => true, + 'command' => " + INSERT IGNORE INTO `msz_roles` + (`role_id`, `role_name`, `role_hierarchy`, `role_colour`, `role_description`, `role_created`) + VALUES + (1, 'Member', 1, 1073741824, NULL, NOW()) + ", + ], + [ + 'name' => 'Ensures all users are in the main role.', + 'type' => 'sql', + 'slow' => true, + 'command' => " + INSERT INTO `msz_user_roles` + (`user_id`, `role_id`) + SELECT `user_id`, 1 FROM `msz_users` as u + WHERE NOT EXISTS ( + SELECT 1 + FROM `msz_user_roles` as ur + WHERE `role_id` = 1 + AND u.`user_id` = ur.`user_id` + ) + ", + ], + [ + 'name' => 'Ensures all display_role values are correct with `msz_user_roles`.', + 'type' => 'sql', + 'slow' => true, + 'command' => " + UPDATE `msz_users` as u + SET `display_role` = ( + SELECT ur.`role_id` + FROM `msz_user_roles` as ur + LEFT JOIN `msz_roles` as r + ON r.`role_id` = ur.`role_id` + WHERE ur.`user_id` = u.`user_id` + ORDER BY `role_hierarchy` DESC + LIMIT 1 + ) + WHERE NOT EXISTS ( + SELECT 1 + FROM `msz_user_roles` as ur + WHERE ur.`role_id` = u.`display_role` + AND `ur`.`user_id` = u.`user_id` + ) + ", + ], + [ + 'name' => 'Remove expired sessions.', + 'type' => 'sql', + 'command' => " + DELETE FROM `msz_sessions` + WHERE `session_expires` < NOW() + ", + ], + [ + 'name' => 'Remove old password reset records.', + 'type' => 'sql', + 'command' => " + DELETE FROM `msz_users_password_resets` + WHERE `reset_requested` < NOW() - INTERVAL 1 WEEK + ", + ], + [ + 'name' => 'Clean up login history.', + 'type' => 'sql', + 'command' => " + DELETE FROM `msz_login_attempts` + WHERE `attempt_created` < NOW() - INTERVAL 1 MONTH + ", + ], + [ + 'name' => 'Clean up audit log.', + 'type' => 'sql', + 'command' => " + DELETE FROM `msz_audit_log` + WHERE `log_created` < NOW() - INTERVAL 3 MONTH + ", + ], + [ + 'name' => 'Remove stale forum tracking entries.', + 'type' => 'sql', + 'command' => " + DELETE tt FROM `msz_forum_topics_track` as tt + LEFT JOIN `msz_forum_topics` as t + ON t.`topic_id` = tt.`topic_id` + WHERE t.`topic_bumped` < NOW() - INTERVAL 1 MONTH + ", + ], + [ + 'name' => 'Synchronise forum_id.', + 'type' => 'sql', + 'slow' => true, + 'command' => " + UPDATE `msz_forum_posts` AS p + INNER JOIN `msz_forum_topics` AS t + ON t.`topic_id` = p.`topic_id` + SET p.`forum_id` = t.`forum_id` + ", + ], + [ + 'name' => 'Recount forum topics and posts.', + 'type' => 'func', + 'slow' => true, + 'command' => 'forum_count_synchronise', + ], + [ + 'name' => 'Clean up expired tfa tokens.', + 'type' => 'sql', + 'command' => " + DELETE FROM `msz_auth_tfa` + WHERE `tfa_created` < NOW() - INTERVAL 15 MINUTE + ", + ], + ]; +} diff --git a/src/Console/Commands/MigrateCommand.php b/src/Console/Commands/MigrateCommand.php new file mode 100644 index 0000000..6a4dd45 --- /dev/null +++ b/src/Console/Commands/MigrateCommand.php @@ -0,0 +1,45 @@ +setLogger(function ($log) { + echo $log . PHP_EOL; + }); + + if($args->getArg(0) === 'rollback') + $migrationManager->rollback(); + else + $migrationManager->migrate(); + + $errors = $migrationManager->getErrors(); + $errorCount = count($errors); + + if($errorCount < 1) { + echo 'Completed with no errors!' . PHP_EOL; + } else { + echo PHP_EOL . "There were {$errorCount} errors during the migrations..." . PHP_EOL; + foreach($errors as $error) + echo $error . PHP_EOL; + } + + unlink(MSZ_ROOT . '/.migrating'); + } +} diff --git a/src/Console/Commands/NewMigrationCommand.php b/src/Console/Commands/NewMigrationCommand.php new file mode 100644 index 0000000..f9df272 --- /dev/null +++ b/src/Console/Commands/NewMigrationCommand.php @@ -0,0 +1,56 @@ +exec(" + CREATE TABLE ... + "); +} + +function migrate_down(PDO \$conn): void { + \$conn->exec(" + DROP TABLE ... + "); +} + +MIG; + + public function getName(): string { + return 'new-mig'; + } + public function getSummary(): string { + return 'Creates a new database migration.'; + } + + public function dispatch(CommandArgs $args): void { + $name = str_replace(' ', '_', implode(' ', $args->getArgs())); + + if(empty($name)) { + echo 'Specify a migration name.' . PHP_EOL; + return; + } + + if(!preg_match('#^([a-z_]+)$#', $name)) { + echo 'Migration name may only contain alpha and _ characters.' . PHP_EOL; + return; + } + + $fileName = date('Y_m_d_His_') . trim($name, '_') . '.php'; + $filePath = MSZ_ROOT . '/database/' . $fileName; + $namespace = str_replace('_', '', ucwords($name, '_')); + + file_put_contents($filePath, sprintf(self::TEMPLATE, $namespace)); + + echo "Template for '{$namespace}' has been created." . PHP_EOL; + } +} diff --git a/src/Console/Commands/TwitterAuthCommand.php b/src/Console/Commands/TwitterAuthCommand.php new file mode 100644 index 0000000..421c2c1 --- /dev/null +++ b/src/Console/Commands/TwitterAuthCommand.php @@ -0,0 +1,50 @@ + PDO::CASE_NATURAL, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, + PDO::ATTR_STRINGIFY_FETCHES => false, + PDO::ATTR_EMULATE_PREPARES => false, + PDO::MYSQL_ATTR_INIT_COMMAND => 'SET SESSION time_zone = \'+00:00\'' + . ', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\'', + ]; + + public static function init(...$args) { + self::$instance = new Database(...$args); + } + + public static function __callStatic(string $name, array $args) { + return self::$instance->{$name}(...$args); + } + + public static function getInstance(): Database { + return self::$instance; + } + + public static function buildDSN(array $vars): string { + $dsn = ($vars['driver'] ?? 'mysql') . ':'; + + foreach($vars as $key => $value) { + if($key === 'driver' || $key === 'username' || $key === 'password') + continue; + if($key === 'database') + $key = 'dbname'; + + $dsn .= $key . '=' . $value . ';'; + } + + return $dsn; + } +} diff --git a/src/Database/Database.php b/src/Database/Database.php new file mode 100644 index 0000000..362d75b --- /dev/null +++ b/src/Database/Database.php @@ -0,0 +1,49 @@ +pdo = new PDO($dsn, $username, $password, $options); + } + + public function getPDO(): PDO { + return $this->pdo; + } + + public function queries(): int { + return (int)$this->query('SHOW SESSION STATUS LIKE "Questions"')->fetchColumn(1); + } + + public function exec(string $stmt): int { + return $this->pdo->exec($stmt); + } + + public function prepare(string $stmt, array $options = []): DatabaseStatement { + $encodedOptions = serialize($options); + + if(empty($this->stmts[$stmt][$encodedOptions])) { + $this->stmts[$stmt][$encodedOptions] = $this->pdo->prepare($stmt, $options); + } + + return new DatabaseStatement($this->stmts[$stmt][$encodedOptions], $this->pdo, false); + } + + public function query(string $stmt, ?int $fetchMode = null, ...$args): DatabaseStatement { + if($fetchMode === null) { + $pdoStmt = $this->pdo->query($stmt); + } else { + $pdoStmt = $this->pdo->query($stmt, $fetchMode, ...$args); + } + + return new DatabaseStatement($pdoStmt, $this->pdo, true); + } + + public function lastId(): int { + return $this->pdo->lastInsertId(); + } +} diff --git a/src/Database/DatabaseMigrationManager.php b/src/Database/DatabaseMigrationManager.php new file mode 100644 index 0000000..17502d6 --- /dev/null +++ b/src/Database/DatabaseMigrationManager.php @@ -0,0 +1,228 @@ +targetConnection = $conn; + $this->migrationStorage = realpath($path); + } + + private function addError(Exception $exception): void { + $this->errors[] = $exception; + $this->writeLog($exception->getMessage()); + } + + public function setLogger(callable $logger): void { + $this->logFunction = $logger; + } + + private function writeLog(string $log): void { + if(!is_callable($this->logFunction)) { + return; + } + + call_user_func($this->logFunction, $log); + } + + public function getErrors(): array { + return $this->errors; + } + + private function getMigrationScripts(): array { + if(!file_exists($this->migrationStorage) || !is_dir($this->migrationStorage)) { + $this->addError(new Exception('Migrations script directory does not exist.')); + return []; + } + + $files = glob(rtrim($this->migrationStorage, '/\\') . '/*.php'); + return $files; + } + + private function createMigrationRepository(): bool { + try { + $this->targetConnection->exec(' + CREATE TABLE IF NOT EXISTS `msz_migrations` ( + `migration_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `migration_name` VARCHAR(255) NOT NULL, + `migration_batch` INT(11) UNSIGNED NOT NULL, + PRIMARY KEY (`migration_id`), + UNIQUE INDEX (`migration_id`) + ) + '); + } catch(PDOException $ex) { + $this->addError($ex); + return false; + } + + return true; + } + + public function migrate(): bool { + $this->writeLog('Running migrations...'); + + if(!$this->createMigrationRepository()) { + return false; + } + + $migrationScripts = $this->getMigrationScripts(); + + if(count($migrationScripts) < 1) { + if(count($this->errors) > 0) { + return false; + } + + $this->writeLog('Nothing to migrate!'); + return true; + } + + try { + $this->writeLog('Fetching completed migration...'); + $fetchStatus = $this->targetConnection->prepare(" + SELECT *, CONCAT(:basepath, '/', `migration_name`, '.php') as `migration_path` + FROM `msz_migrations` + "); + $fetchStatus->bindValue('basepath', $this->migrationStorage); + $migrationStatus = $fetchStatus->execute() ? $fetchStatus->fetchAll() : []; + } catch(PDOException $ex) { + $this->addError($ex); + return false; + } + + if(count($migrationStatus) < 1 && count($this->errors) > 0) { + return false; + } + + $remainingMigrations = array_diff($migrationScripts, array_column($migrationStatus, 'migration_path')); + + if(count($remainingMigrations) < 1) { + $this->writeLog('Nothing to migrate!'); + return true; + } + + $batchNumber = $this->targetConnection->query(' + SELECT COALESCE(MAX(`migration_batch`), 0) + 1 + FROM `msz_migrations` + ')->fetchColumn(); + + $recordMigration = $this->targetConnection->prepare(' + INSERT INTO `msz_migrations` + (`migration_name`, `migration_batch`) + VALUES + (:name, :batch) + '); + $recordMigration->bindValue('batch', $batchNumber); + + foreach($remainingMigrations as $migration) { + $filename = pathinfo($migration, PATHINFO_FILENAME); + $filenameSplit = explode('_', $filename); + $recordMigration->bindValue('name', $filename); + $migrationName = ''; + + if(count($filenameSplit) < 5) { + $this->addError(new Exception("Invalid migration name: '{$filename}'")); + return false; + } + + for($i = 4; $i < count($filenameSplit); $i++) { + $migrationName .= ucfirst(mb_strtolower($filenameSplit[$i])); + } + + include_once $migration; + + $this->writeLog("Running migration '{$filename}'..."); + $migrationFunction = sprintf(self::MIGRATION_NAMESPACE, $migrationName, 'migrate_up'); + $migrationFunction($this->targetConnection); + $recordMigration->execute(); + } + + $this->writeLog('Successfully completed all migrations!'); + + return true; + } + + public function rollback(): bool + { + $this->writeLog('Rolling back last migration batch...'); + + if(!$this->createMigrationRepository()) { + return false; + } + + try { + $fetchStatus = $this->targetConnection->prepare(" + SELECT *, CONCAT(:basepath, '/', `migration_name`, '.php') as `migration_path` + FROM `msz_migrations` + WHERE `migration_batch` = ( + SELECT MAX(`migration_batch`) + FROM `msz_migrations` + ) + "); + $fetchStatus->bindValue('basepath', $this->migrationStorage); + $migrations = $fetchStatus->execute() ? $fetchStatus->fetchAll() : []; + } catch(PDOException $ex) { + $this->addError($ex); + return false; + } + + if(count($migrations) < 1) { + if(count($this->errors) > 0) { + return false; + } + + $this->writeLog('Nothing to roll back!'); + return true; + } + + $migrationScripts = $this->getMigrationScripts(); + + if(count($migrationScripts) < count($migrations)) { + $this->addError(new Exception('There are missing migration scripts!')); + return false; + } + + $removeRecord = $this->targetConnection->prepare(' + DELETE FROM `msz_migrations` + WHERE `migration_id` = :id + '); + + foreach($migrations as $migration) { + if(!file_exists($migration['migration_path'])) { + $this->addError(new Exception("Migration '{$migration['migration_name']}' does not exist.")); + return false; + } + + $nameSplit = explode('_', $migration['migration_name']); + $migrationName = ''; + + for($i = 4; $i < count($nameSplit); $i++) { + $migrationName .= ucfirst(mb_strtolower($nameSplit[$i])); + } + + include_once $migration['migration_path']; + + $this->writeLog("Rolling '{$migration['migration_name']}' back..."); + $migrationFunction = sprintf(self::MIGRATION_NAMESPACE, $migrationName, 'migrate_down'); + $migrationFunction($this->targetConnection); + + $removeRecord->bindValue('id', $migration['migration_id']); + $removeRecord->execute(); + } + + $this->writeLog('Successfully completed all rollbacks'); + + return true; + } +} diff --git a/src/Database/DatabaseStatement.php b/src/Database/DatabaseStatement.php new file mode 100644 index 0000000..39c32e6 --- /dev/null +++ b/src/Database/DatabaseStatement.php @@ -0,0 +1,67 @@ +stmt = $stmt; + $this->pdo = $pdo; + $this->isQuery = $isQuery; + } + + public function bind($param, $value, int $dataType = PDO::PARAM_STR): DatabaseStatement { + $this->stmt->bindValue($param, $value, $dataType); + return $this; + } + + public function execute(array $params = []): bool { + return count($params) ? $this->stmt->execute($params) : $this->stmt->execute(); + } + + public function executeGetId(array $params = []): int { + return $this->execute($params) ? $this->pdo->lastInsertId() : 0; + } + + public function fetch($default = []) { + $out = $this->isQuery || $this->execute() ? $this->stmt->fetch(PDO::FETCH_ASSOC) : false; + return $out ? $out : $default; + } + + public function fetchAll($default = []) { + $out = $this->isQuery || $this->execute() ? $this->stmt->fetchAll(PDO::FETCH_ASSOC) : false; + return $out ? $out : $default; + } + + public function fetchColumn(int $num = 0, $default = null) { + $out = $this->isQuery || $this->execute() ? $this->stmt->fetchColumn($num) : false; + return $out ? $out : $default; + } + + public function fetchObject(string $className = 'stdClass', ?array $args = null, $default = null) { + $out = false; + + if($this->isQuery || $this->execute()) { + $out = $args === null ? $this->stmt->fetchObject($className) : $this->stmt->fetchObject($className, $args); + } + + return $out !== false ? $out : $default; + } + + public function fetchObjects(string $className = 'stdClass', ?array $args = null): array { + $objects = []; + + if($this->isQuery || $this->execute()) { + while(($object = ($args === null ? $this->stmt->fetchObject($className) : $this->stmt->fetchObject($className, $args))) !== false) { + $objects[] = $object; + } + } + + return $objects; + } +} diff --git a/src/Emoticon.php b/src/Emoticon.php new file mode 100644 index 0000000..fa6bdda --- /dev/null +++ b/src/Emoticon.php @@ -0,0 +1,179 @@ +emote_id ?? 0; + } + public function hasId(): bool { + return isset($this->emote_id) && $this->emote_id > 0; + } + + public function getOrder(): int { + return $this->emote_order ?? 0; + } + public function setOrder(int $order): self { + $this->emote_order = $order; + return $this; + } + public function changeOrder(int $difference): self { + if(!$this->hasId()) + return $this; + + DB::prepare(' + UPDATE `msz_emoticons` + SET `emote_order` = `emote_order` + :diff + WHERE `emote_id` = :id + ')->bind('id', $this->getId()) + ->bind('diff', $difference) + ->execute(); + + return $this; + } + + public function getRank(): int { + return $this->emote_hierarchy ?? 0; + } + public function setRank(int $rank): self { + $this->emote_hierarchy = $rank; + return $this; + } + + public function getUrl(): string { + return $this->emote_url ?? ''; + } + public function setUrl(string $url): self { + $this->emote_url = $url; + return $this; + } + + public function addString(string $string, ?int $order = null): bool { + if(!$this->hasId()) + return false; + + if($order === null) { + $order = DB::prepare(' + SELECT MAX(`emote_string_order`) + 1 + FROM `msz_emoticons_strings` + WHERE `emote_id` = :id + ')->bind('id', $this->getId())->fetchColumn(); + } + + return DB::prepare(' + REPLACE INTO `msz_emoticons_strings` (`emote_id`, `emote_string_order`, `emote_string`) + VALUES (:id, :order, :string) + ')->bind('id', $this->getId()) + ->bind('order', $order) + ->bind('string', $string) + ->execute(); + } + public function removeString(string $string): bool { + if(!$this->hasId()) + return false; + + return DB::prepare(' + DELETE FROM `msz_emoticons_strings` + WHERE `emote_string` = :string + ')->bind('string', $string) + ->execute(); + } + public function getStrings(): array { + if(!$this->hasId()) + return []; + + return DB::prepare(' + SELECT `emote_string_order`, `emote_string` + FROM `msz_emoticons_strings` + WHERE `emote_id` = :id + ORDER BY `emote_string_order` + ')->bind('id', $this->getId())->fetchObjects(); + } + + public function save(): bool { + if($this->hasId()) { + $save = DB::prepare(' + UPDATE `msz_emoticons` + SET `emote_order` = :order, + `emote_hierarchy` = :hierarchy, + `emote_url` = :url + WHERE `emote_id` = :id + ')->bind('id', $this->getId()); + } else { + $save = DB::prepare(' + INSERT INTO `msz_emoticons` (`emote_order`, `emote_hierarchy`, `emote_url`) + VALUES (:order, :hierarchy, :url) + '); + } + + $saved = $save->bind('order', $this->getOrder()) + ->bind('hierarchy', $this->getRank()) + ->bind('url', $this->getUrl()) + ->execute(); + + if(!$this->hasId() && $saved) + $this->emote_id = DB::lastId(); + + return $saved; + } + + public function delete(): void { + if(!$this->hasId()) + return; + + DB::prepare('DELETE FROM `msz_emoticons` WHERE `emote_id` = :id') + ->bind('id', $this->getId()) + ->execute(); + } + + public static function byId(int $emoteId): self { + if($emoteId < 1) + throw new InvalidArgumentException('$emoteId is not a valid emoticon id.'); + + $getEmote = DB::prepare(' + SELECT `emote_id`, `emote_order`, `emote_hierarchy`, `emote_url` + FROM `msz_emoticons` + WHERE `emote_id` = :id + '); + $getEmote->bind('id', $emoteId); + return $getEmote->fetchObject(self::class); + } + + public static function all(int $hierarchy = self::ALL, bool $unique = false, bool $order = true): array { + $getEmotes = DB::prepare(' + SELECT `emote_id`, `emote_order`, `emote_hierarchy`, `emote_url` + FROM `msz_emoticons` + WHERE `emote_hierarchy` <= :hierarchy + ORDER BY IF(:order, `emote_order`, `emote_id`) + '); + $getEmotes->bind('hierarchy', $hierarchy); + $getEmotes->bind('order', $order); + $emotes = $getEmotes->fetchObjects(self::class); + + // Removes aliases, emote with lowest ordering is considered the main + if($unique) { + $existing = []; + + for($i = 0; $i < count($emotes); $i++) { + if(in_array($emotes[$i]->emote_url, $existing)) { + unset($emotes[$i]); + } else { + $existing[] = $emotes[$i]->emote_url; + } + } + } + + return $emotes; + } +} diff --git a/src/Feeds/AtomFeedSerializer.php b/src/Feeds/AtomFeedSerializer.php new file mode 100644 index 0000000..486017a --- /dev/null +++ b/src/Feeds/AtomFeedSerializer.php @@ -0,0 +1,115 @@ +appendChild($document->createElement('feed')); + $atom->setAttribute('xmlns', 'http://www.w3.org/2005/Atom'); + + $atom->appendChild( + $document->createElement( + 'id', + $feed->hasContentUrl() + ? $this->cleanString($feed->getContentUrl()) + : time() + ) + ); + + return $atom; + } + + protected function createTitle(DOMDocument $document, string $title): DOMElement { + return $document->createElement('title', $this->cleanString($title)); + } + + protected function createDescription(DOMDocument $document, string $description): ?DOMElement { + return $document->createElement('subtitle', $this->cleanString($description)); + } + + protected function createLastUpdate(DOMDocument $document, int $lastUpdate): ?DOMElement { + return $document->createElement('updated', $this->formatTime($lastUpdate)); + } + + protected function createContentUrl(DOMDocument $document, string $contentUrl): ?DOMElement { + $link = $document->createElement('link'); + $link->setAttribute('href', $this->cleanString($contentUrl)); + return $link; + } + + protected function createFeedUrl(DOMDocument $document, string $feedUrl): ?DOMElement { + $link = $document->createElement('link'); + $link->setAttribute('href', $this->cleanString($feedUrl)); + $link->setAttribute('ref', 'self'); + return $link; + } + + protected function createItem(DOMDocument $document, FeedItem $feedItem): DOMElement { + $elem = $document->createElement('entry'); + + $elem->appendChild( + $document->createElement( + 'id', + $feedItem->hasContentUrl() + ? $this->cleanString($feedItem->getContentUrl()) + : time() + ) + ); + + return $elem; + } + + protected function createItemTitle(DOMDocument $document, string $title): DOMElement { + return $document->createElement('title', $this->cleanString($title)); + } + + protected function createItemSummary(DOMDocument $document, string $summary): ?DOMElement { + return $document->createElement('summary', $this->cleanString($summary)); + } + + protected function createItemContent(DOMDocument $document, string $content): ?DOMElement { + $elem = $document->createElement('content', $this->cleanString($content)); + $elem->setAttribute('type', 'html'); + return $elem; + } + + protected function createItemCreationDate(DOMDocument $document, int $creationDate): ?DOMElement { + return $document->createElement('updated', $this->formatTime($creationDate)); + } + + protected function createItemUniqueId(DOMDocument $document, string $uniqueId): ?DOMElement { + return null; + } + + protected function createItemContentUrl(DOMDocument $document, string $contentUrl): ?DOMElement { + $elem = $document->createElement('link'); + $elem->setAttribute('href', $this->cleanString($contentUrl)); + $elem->setAttribute('type', 'text/html'); + return $elem; + } + + protected function createItemCommentsUrl(DOMDocument $document, string $commentsUrl): ?DOMElement { + return null; + } + + protected function createItemAuthor(DOMDocument $document, ?string $authorName, ?string $authorUrl): ?DOMElement { + if(empty($authorName) && empty($authorUrl)) + return null; + + $elem = $document->createElement('author'); + + if(!empty($authorName)) + $elem->appendChild($document->createElement('name', $this->cleanString($authorName))); + + if(!empty($authorUrl)) + $elem->appendChild($document->createElement('uri', $this->cleanString($authorUrl))); + + return $elem; + } +} diff --git a/src/Feeds/Feed.php b/src/Feeds/Feed.php new file mode 100644 index 0000000..2c4b7c1 --- /dev/null +++ b/src/Feeds/Feed.php @@ -0,0 +1,76 @@ +title; + } + public function setTitle(string $title): self { + $this->title = $title; + return $this; + } + + public function getDescription(): string { + return $this->description ?? ''; + } + public function hasDescription(): bool { + return isset($this->description); + } + public function setDescription(?string $description): self { + $this->description = $description; + return $this; + } + + public function getLastUpdate(): int { + return $this->lastUpdate ?? 0; + } + public function hasLastUpdate(): bool { + return isset($this->lastUpdate); + } + public function setLastUpdate(?int $lastUpdate): self { + $this->lastUpdate = $lastUpdate; + return $this; + } + + public function getContentUrl(): string { + return $this->contentUrl ?? ''; + } + public function hasContentUrl(): bool { + return isset($this->contentUrl); + } + public function setContentUrl(?string $contentUrl): self { + $this->contentUrl = $contentUrl; + return $this; + } + + public function getFeedUrl(): string { + return $this->feedUrl ?? ''; + } + public function hasFeedUrl(): bool { + return isset($this->feedUrl); + } + public function setFeedUrl(?string $feedUrl): self { + $this->feedUrl = $feedUrl; + return $this; + } + + public function getItems(): array { + return $this->feedItems; + } + public function hasItems(): bool { + return count($this->feedItems) > 0; + } + public function addItem(FeedItem $item): self { + $this->feedItems[] = $item; + return $this; + } +} diff --git a/src/Feeds/FeedItem.php b/src/Feeds/FeedItem.php new file mode 100644 index 0000000..34d8e6d --- /dev/null +++ b/src/Feeds/FeedItem.php @@ -0,0 +1,110 @@ +title; + } + public function setTitle(string $title): self { + $this->title = $title; + return $this; + } + + public function getSummary(): string { + return $this->summary ?? ''; + } + public function hasSummary(): bool { + return isset($this->summary); + } + public function setSummary(?string $summary): self { + $this->summary = $summary; + return $this; + } + + public function getContent(): string { + return $this->content ?? ''; + } + public function hasContent(): bool { + return isset($this->content); + } + public function setContent(?string $content): self { + $this->content = $content; + return $this; + } + + public function getCreationDate(): int { + return $this->creationDate; + } + public function hasCreationDate(): bool { + return isset($this->creationDate); + } + public function setCreationDate(?int $creationDate): self { + $this->creationDate = $creationDate; + return $this; + } + + public function getUniqueId(): string { + return $this->uniqueId ?? ''; + } + public function hasUniqueId(): bool { + return isset($this->uniqueId); + } + public function setUniqueId(?string $uniqueId): self { + $this->uniqueId = $uniqueId; + return $this; + } + + public function getContentUrl(): string { + return $this->contentUrl ?? ''; + } + public function hasContentUrl(): bool { + return isset($this->contentUrl); + } + public function setContentUrl(?string $contentUrl): self { + $this->contentUrl = $contentUrl; + return $this; + } + + public function getCommentsUrl(): string { + return $this->commentsUrl ?? ''; + } + public function hasCommentsUrl(): bool { + return isset($this->commentsUrl); + } + public function setCommentsUrl(?string $commentsUrl): self { + $this->commentsUrl = $commentsUrl; + return $this; + } + + public function getAuthorName(): string { + return $this->authorName ?? ''; + } + public function hasAuthorName(): bool { + return isset($this->authorName); + } + public function setAuthorName(?string $authorName): self { + $this->authorName = $authorName; + return $this; + } + + public function getAuthorUrl(): string { + return $this->authorUrl ?? ''; + } + public function hasAuthorUrl(): bool { + return isset($this->authorUrl); + } + public function setAuthorUrl(?string $authorUrl): self { + $this->authorUrl = $authorUrl; + return $this; + } +} diff --git a/src/Feeds/FeedSerializer.php b/src/Feeds/FeedSerializer.php new file mode 100644 index 0000000..6595b76 --- /dev/null +++ b/src/Feeds/FeedSerializer.php @@ -0,0 +1,6 @@ +appendChild($document->createElement('rss')); + $rss->setAttribute('version', '2.0'); + $rss->setAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom'); + + $channel = $rss->appendChild($document->createElement('channel')); + $channel->appendChild($document->createElement('ttl', '900')); + return $channel; + } + + protected function createTitle(DOMDocument $document, string $title): DOMElement { + return $document->createElement('title', $this->cleanString($title)); + } + + protected function createDescription(DOMDocument $document, string $description): ?DOMElement { + return $document->createElement('description', $this->cleanString($description)); + } + + protected function createLastUpdate(DOMDocument $document, int $lastUpdate): ?DOMElement { + return $document->createElement('pubDate', $this->formatTime($lastUpdate)); + } + + protected function createContentUrl(DOMDocument $document, string $contentUrl): ?DOMElement { + return $document->createElement('link', $this->cleanString($contentUrl)); + } + + protected function createFeedUrl(DOMDocument $document, string $feedUrl): ?DOMElement { + $link = $document->createElement('atom:link'); + $link->setAttribute('href', $this->cleanString($feedUrl)); + $link->setAttribute('ref', 'self'); + return $link; + } + + protected function createItem(DOMDocument $document, FeedItem $feedItem): DOMElement { + return $document->createElement('item'); + } + + protected function createItemTitle(DOMDocument $document, string $title): DOMElement { + return $document->createElement('title', $this->cleanString($title)); + } + + protected function createItemSummary(DOMDocument $document, string $summary): ?DOMElement { + return $document->createElement('description', $this->cleanString($summary)); + } + + protected function createItemContent(DOMDocument $document, string $content): ?DOMElement { + return null; + } + + protected function createItemCreationDate(DOMDocument $document, int $creationDate): ?DOMElement { + return $document->createElement('pubDate', $this->formatTime($creationDate)); + } + + protected function createItemUniqueId(DOMDocument $document, string $uniqueId): ?DOMElement { + $elem = $document->createElement('guid', $uniqueId); + $elem->setAttribute('isPermaLink', 'true'); + return $elem; + } + + protected function createItemContentUrl(DOMDocument $document, string $contentUrl): ?DOMElement { + return $document->createElement('link', $contentUrl); + } + + protected function createItemCommentsUrl(DOMDocument $document, string $commentsUrl): ?DOMElement { + return $document->createElement('comments', $commentsUrl); + } + + protected function createItemAuthor(DOMDocument $document, ?string $authorName, ?string $authorUrl): ?DOMElement { + return null; + } +} diff --git a/src/Feeds/XmlFeedSerializer.php b/src/Feeds/XmlFeedSerializer.php new file mode 100644 index 0000000..289e0b3 --- /dev/null +++ b/src/Feeds/XmlFeedSerializer.php @@ -0,0 +1,79 @@ +createRoot($document, $feed); + $root->appendChild($this->createTitle($document, $feed->getTitle())); + + if($feed->hasDescription()) + self::appendChild($root, $this->createDescription($document, $feed->getDescription())); + if($feed->hasLastUpdate()) + self::appendChild($root, $this->createLastUpdate($document, $feed->getLastUpdate())); + if($feed->hasContentUrl()) + self::appendChild($root, $this->createContentUrl($document, $feed->getContentUrl())); + if($feed->hasFeedUrl()) + self::appendChild($root, $this->createFeedUrl($document, $feed->getFeedUrl())); + + if($feed->hasItems()) { + foreach($feed->getItems() as $item) { + $root->appendChild($this->serializeFeedItem($document, $item)); + } + } + + return $document->saveXML(); + } + + private function serializeFeedItem(DOMDocument $document, FeedItem $feedItem): DOMElement { + $elem = $this->createItem($document, $feedItem); + $elem->appendChild($this->createItemTitle($document, $feedItem->getTitle())); + + if($feedItem->hasSummary()) + self::appendChild($elem, $this->createItemSummary($document, $feedItem->getSummary())); + if($feedItem->hasContent()) + self::appendChild($elem, $this->createItemContent($document, $feedItem->getContent())); + if($feedItem->hasCreationDate()) + self::appendChild($elem, $this->createItemCreationDate($document, $feedItem->getCreationDate())); + if($feedItem->hasUniqueId()) + self::appendChild($elem, $this->createItemUniqueId($document, $feedItem->getUniqueId())); + if($feedItem->hasContentUrl()) + self::appendChild($elem, $this->createItemContentUrl($document, $feedItem->getContentUrl())); + if($feedItem->hasCommentsUrl()) + self::appendChild($elem, $this->createItemCommentsUrl($document, $feedItem->getCommentsUrl())); + if($feedItem->hasAuthorName() || $feedItem->hasAuthorUrl()) + self::appendChild($elem, $this->createItemAuthor($document, $feedItem->getAuthorName(), $feedItem->getAuthorUrl())); + + return $elem; + } + + protected function cleanString(string $string): string { + return htmlspecialchars($string, ENT_XML1 | ENT_COMPAT | ENT_SUBSTITUTE); + } + + protected static function appendChild(DOMElement $parent, ?DOMElement $elem): ?DOMElement { + if($elem !== null) + return $parent->appendChild($elem); + return $elem; + } + + abstract protected function formatTime(int $time): string; + abstract protected function createRoot(DOMDocument $document, Feed $feed): DOMElement; + abstract protected function createTitle(DOMDocument $document, string $title): DOMElement; + abstract protected function createDescription(DOMDocument $document, string $description): ?DOMElement; + abstract protected function createLastUpdate(DOMDocument $document, int $lastUpdate): ?DOMElement; + abstract protected function createContentUrl(DOMDocument $document, string $contentUrl): ?DOMElement; + abstract protected function createFeedUrl(DOMDocument $document, string $feedUrl): ?DOMElement; + abstract protected function createItem(DOMDocument $document, FeedItem $feedItem): DOMElement; + abstract protected function createItemTitle(DOMDocument $document, string $title): DOMElement; + abstract protected function createItemSummary(DOMDocument $document, string $summary): ?DOMElement; + abstract protected function createItemContent(DOMDocument $document, string $content): ?DOMElement; + abstract protected function createItemCreationDate(DOMDocument $document, int $creationDate): ?DOMElement; + abstract protected function createItemUniqueId(DOMDocument $document, string $uniqueId): ?DOMElement; + abstract protected function createItemContentUrl(DOMDocument $document, string $contentUrl): ?DOMElement; + abstract protected function createItemCommentsUrl(DOMDocument $document, string $commentsUrl): ?DOMElement; + abstract protected function createItemAuthor(DOMDocument $document, ?string $authorName, ?string $authorUrl): ?DOMElement; +} diff --git a/src/Forum/forum.php b/src/Forum/forum.php new file mode 100644 index 0000000..6dbdf88 --- /dev/null +++ b/src/Forum/forum.php @@ -0,0 +1,536 @@ + MSZ_FORUM_ROOT, + 'forum_name' => 'Forums', + 'forum_children' => 0, + 'forum_type' => MSZ_FORUM_TYPE_CATEGORY, + 'forum_colour' => null, + 'forum_permissions' => MSZ_FORUM_PERM_SET_READ, +]); + +function forum_is_valid_type(int $type): bool { + return in_array($type, MSZ_FORUM_TYPES, true); +} + +function forum_may_have_children(int $forumType): bool { + return in_array($forumType, MSZ_FORUM_MAY_HAVE_CHILDREN); +} + +function forum_may_have_topics(int $forumType): bool { + return in_array($forumType, MSZ_FORUM_MAY_HAVE_TOPICS); +} + +function forum_has_priority_voting(int $forumType): bool { + return in_array($forumType, MSZ_FORUM_HAS_PRIORITY_VOTING); +} + +function forum_get(int $forumId, bool $showDeleted = false): array { + $getForum = \Misuzu\DB::prepare(sprintf( + ' + SELECT + `forum_id`, `forum_name`, `forum_type`, `forum_link`, `forum_archived`, + `forum_link_clicks`, `forum_parent`, `forum_colour`, `forum_icon`, + ( + SELECT COUNT(`topic_id`) + FROM `msz_forum_topics` + WHERE `forum_id` = f.`forum_id` + %1$s + ) as `forum_topic_count` + FROM `msz_forum_categories` as f + WHERE `forum_id` = :forum_id + ', + $showDeleted ? '' : 'AND `topic_deleted` IS NULL' + )); + $getForum->bind('forum_id', $forumId); + return $getForum->fetch(); +} + +function forum_get_root_categories(int $userId): array { + $getCategories = \Misuzu\DB::prepare(sprintf( + ' + SELECT + f.`forum_id`, f.`forum_name`, f.`forum_type`, f.`forum_colour`, f.`forum_icon`, + ( + SELECT COUNT(`forum_id`) + FROM `msz_forum_categories` AS sf + WHERE sf.`forum_parent` = f.`forum_id` + ) AS `forum_children` + FROM `msz_forum_categories` AS f + WHERE f.`forum_parent` = 0 + AND f.`forum_type` = %1$d + AND f.`forum_hidden` = 0 + GROUP BY f.`forum_id` + ORDER BY f.`forum_order` + ', + MSZ_FORUM_TYPE_CATEGORY + )); + $categories = array_merge([MSZ_FORUM_ROOT_DATA], $getCategories->fetchAll()); + + $getRootForumCount = \Misuzu\DB::prepare(sprintf( + " + SELECT COUNT(`forum_id`) + FROM `msz_forum_categories` + WHERE `forum_parent` = %d + AND `forum_type` != %d + ", + MSZ_FORUM_ROOT, + MSZ_FORUM_TYPE_CATEGORY + )); + $categories[0]['forum_children'] = (int)$getRootForumCount->fetchColumn(); + + foreach($categories as $key => $category) { + $categories[$key]['forum_permissions'] = $perms = forum_perms_get_user($category['forum_id'], $userId)[MSZ_FORUM_PERMS_GENERAL]; + + if(!perms_check($perms, MSZ_FORUM_PERM_SET_READ)) { + unset($categories[$key]); + continue; + } + + $categories[$key] = array_merge( + $category, + ['forum_unread' => forum_topics_unread($category['forum_id'], $userId)], + forum_latest_post($category['forum_id'], $userId) + ); + } + + return $categories; +} + +function forum_get_breadcrumbs( + int $forumId, + string $linkFormat = '/forum/forum.php?f=%d', + string $rootFormat = '/forum/#f%d', + array $indexLink = ['Forums' => '/forum/'] +): array { + $breadcrumbs = []; + $getBreadcrumb = \Misuzu\DB::prepare(' + SELECT `forum_id`, `forum_name`, `forum_type`, `forum_parent` + FROM `msz_forum_categories` + WHERE `forum_id` = :forum_id + '); + + while($forumId > 0) { + $getBreadcrumb->bind('forum_id', $forumId); + $breadcrumb = $getBreadcrumb->fetch(); + + if(empty($breadcrumb)) { + break; + } + + $breadcrumbs[$breadcrumb['forum_name']] = sprintf( + $breadcrumb['forum_parent'] === MSZ_FORUM_ROOT + && $breadcrumb['forum_type'] === MSZ_FORUM_TYPE_CATEGORY + ? $rootFormat + : $linkFormat, + $breadcrumb['forum_id'] + ); + $forumId = $breadcrumb['forum_parent']; + } + + return array_reverse($breadcrumbs + $indexLink); +} + +function forum_get_colour(int $forumId): int { + $getColours = \Misuzu\DB::prepare(' + SELECT `forum_id`, `forum_parent`, `forum_colour` + FROM `msz_forum_categories` + WHERE `forum_id` = :forum_id + '); + + while($forumId > 0) { + $getColours->bind('forum_id', $forumId); + $colourInfo = $getColours->fetch(); + + if(empty($colourInfo)) { + break; + } + + if(!empty($colourInfo['forum_colour'])) { + return $colourInfo['forum_colour']; + } + + $forumId = $colourInfo['forum_parent']; + } + + return 0x40000000; +} + +function forum_increment_clicks(int $forumId): void { + $incrementLinkClicks = \Misuzu\DB::prepare(sprintf(' + UPDATE `msz_forum_categories` + SET `forum_link_clicks` = `forum_link_clicks` + 1 + WHERE `forum_id` = :forum_id + AND `forum_type` = %d + AND `forum_link_clicks` IS NOT NULL + ', MSZ_FORUM_TYPE_LINK)); + $incrementLinkClicks->bind('forum_id', $forumId); + $incrementLinkClicks->execute(); +} + +function forum_get_parent_id(int $forumId): int { + if($forumId < 1) { + return 0; + } + + static $memoized = []; + + if(array_key_exists($forumId, $memoized)) { + return $memoized[$forumId]; + } + + $getParent = \Misuzu\DB::prepare(' + SELECT `forum_parent` + FROM `msz_forum_categories` + WHERE `forum_id` = :forum_id + '); + $getParent->bind('forum_id', $forumId); + + return (int)$getParent->fetchColumn(); +} + +function forum_get_child_ids(int $forumId): array { + if($forumId < 1) { + return []; + } + + static $memoized = []; + + if(array_key_exists($forumId, $memoized)) { + return $memoized[$forumId]; + } + + $getChildren = \Misuzu\DB::prepare(' + SELECT `forum_id` + FROM `msz_forum_categories` + WHERE `forum_parent` = :forum_id + '); + $getChildren->bind('forum_id', $forumId); + $children = $getChildren->fetchAll(); + + return $memoized[$forumId] = array_column($children, 'forum_id'); +} + +function forum_topics_unread(int $forumId, int $userId): int { + if($userId < 1 || $forumId < 1) + return 0; + + static $memoized = []; + $memoId = "{$forumId}-{$userId}"; + + if(array_key_exists($memoId, $memoized)) { + return $memoized[$memoId]; + } + + $memoized[$memoId] = 0; + $children = forum_get_child_ids($forumId); + + foreach($children as $child) { + $memoized[$memoId] += forum_topics_unread($child, $userId); + } + + if(forum_perms_check_user(MSZ_FORUM_PERMS_GENERAL, $forumId, $userId, MSZ_FORUM_PERM_SET_READ)) { + $countUnread = \Misuzu\DB::prepare(' + SELECT COUNT(ti.`topic_id`) + FROM `msz_forum_topics` AS ti + LEFT JOIN `msz_forum_topics_track` AS tt + ON tt.`topic_id` = ti.`topic_id` AND tt.`user_id` = :user_id + WHERE ti.`forum_id` = :forum_id + AND ti.`topic_deleted` IS NULL + AND ti.`topic_bumped` >= NOW() - INTERVAL 1 MONTH + AND ( + tt.`track_last_read` IS NULL + OR tt.`track_last_read` < ti.`topic_bumped` + ) + '); + $countUnread->bind('forum_id', $forumId); + $countUnread->bind('user_id', $userId); + $memoized[$memoId] += (int)$countUnread->fetchColumn(); + } + + return $memoized[$memoId]; +} + +function forum_latest_post(int $forumId, int $userId): array { + if($forumId < 1) { + return []; + } + + static $memoized = []; + $memoId = "{$forumId}-{$userId}"; + + if(array_key_exists($memoId, $memoized)) { + return $memoized[$memoId]; + } + + if(!forum_perms_check_user(MSZ_FORUM_PERMS_GENERAL, $forumId, $userId, MSZ_FORUM_PERM_SET_READ)) { + return $memoized[$memoId] = []; + } + + $getLastPost = \Misuzu\DB::prepare(' + SELECT + p.`post_id` AS `recent_post_id`, t.`topic_id` AS `recent_topic_id`, + t.`topic_title` AS `recent_topic_title`, t.`topic_bumped` AS `recent_topic_bumped`, + p.`post_created` AS `recent_post_created`, + u.`user_id` AS `recent_post_user_id`, + u.`username` AS `recent_post_username`, + COALESCE(u.`user_colour`, r.`role_colour`) AS `recent_post_user_colour`, + UNIX_TIMESTAMP(p.`post_created`) AS `post_created_unix` + FROM `msz_forum_posts` AS p + LEFT JOIN `msz_forum_topics` AS t + ON t.`topic_id` = p.`topic_id` + LEFT JOIN `msz_users` AS u + ON u.`user_id` = p.`user_id` + LEFT JOIN `msz_roles` AS r + ON r.`role_id` = u.`display_role` + WHERE p.`forum_id` = :forum_id + AND p.`post_deleted` IS NULL + ORDER BY p.`post_id` DESC + '); + $getLastPost->bind('forum_id', $forumId); + $currentLast = $getLastPost->fetch(); + + $children = forum_get_child_ids($forumId); + + foreach($children as $child) { + $lastPost = forum_latest_post($child, $userId); + + if(($currentLast['post_created_unix'] ?? 0) < ($lastPost['post_created_unix'] ?? 0)) { + $currentLast = $lastPost; + } + } + + return $memoized[$memoId] = $currentLast; +} + +function forum_get_children(int $parentId, int $userId): array { + $getListing = \Misuzu\DB::prepare(sprintf( + ' + SELECT + :user_id AS `target_user_id`, + f.`forum_id`, f.`forum_name`, f.`forum_description`, f.`forum_type`, f.`forum_icon`, + f.`forum_link`, f.`forum_link_clicks`, f.`forum_archived`, f.`forum_colour`, + f.`forum_count_topics`, f.`forum_count_posts` + FROM `msz_forum_categories` AS f + WHERE f.`forum_parent` = :parent_id + AND f.`forum_hidden` = 0 + AND ( + (f.`forum_parent` = %1$d AND f.`forum_type` != %2$d) + OR f.`forum_parent` != %1$d + ) + GROUP BY f.`forum_id` + ORDER BY f.`forum_order` + ', + MSZ_FORUM_ROOT, + MSZ_FORUM_TYPE_CATEGORY + )); + + $getListing->bind('user_id', $userId); + $getListing->bind('parent_id', $parentId); + + $listing = $getListing->fetchAll(); + + foreach($listing as $key => $forum) { + $listing[$key]['forum_permissions'] = $perms = forum_perms_get_user($forum['forum_id'], $userId)[MSZ_FORUM_PERMS_GENERAL]; + + if(!perms_check($perms, MSZ_FORUM_PERM_SET_READ)) { + unset($listing[$key]); + continue; + } + + $listing[$key] = array_merge( + $forum, + ['forum_unread' => forum_topics_unread($forum['forum_id'], $userId)], + forum_latest_post($forum['forum_id'], $userId) + ); + } + + return $listing; +} + +function forum_timeout(int $forumId, int $userId): int { + $checkTimeout = \Misuzu\DB::prepare(' + SELECT TIMESTAMPDIFF(SECOND, COALESCE(MAX(`post_created`), NOW() - INTERVAL 1 YEAR), NOW()) + FROM `msz_forum_posts` + WHERE `forum_id` = :forum_id + AND `user_id` = :user_id + '); + $checkTimeout->bind('forum_id', $forumId); + $checkTimeout->bind('user_id', $userId); + + return (int)$checkTimeout->fetchColumn(); +} + +// $forumId == null marks all forums as read +function forum_mark_read(?int $forumId, int $userId): void { + if(($forumId !== null && $forumId < 1) || $userId < 1) { + return; + } + + $entireForum = $forumId === null; + + if(!$entireForum) { + $children = forum_get_child_ids($forumId); + + foreach($children as $child) { + forum_mark_read($child, $userId); + } + } + + $doMark = \Misuzu\DB::prepare(sprintf( + ' + INSERT INTO `msz_forum_topics_track` + (`user_id`, `topic_id`, `forum_id`, `track_last_read`) + SELECT u.`user_id`, t.`topic_id`, t.`forum_id`, NOW() + FROM `msz_forum_topics` AS t + LEFT JOIN `msz_users` AS u + ON u.`user_id` = :user + WHERE t.`topic_deleted` IS NULL + AND t.`topic_bumped` >= NOW() - INTERVAL 1 MONTH + %1$s + GROUP BY t.`topic_id` + ON DUPLICATE KEY UPDATE + `track_last_read` = NOW() + ', + $entireForum ? '' : 'AND t.`forum_id` = :forum' + )); + $doMark->bind('user', $userId); + + if(!$entireForum) { + $doMark->bind('forum', $forumId); + } + + $doMark->execute(); +} + +function forum_posting_info(int $userId): array { + $getPostingInfo = \Misuzu\DB::prepare(' + SELECT + u.`user_country`, u.`user_created`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `user_id` = u.`user_id` + AND `post_deleted` IS NULL + ) AS `user_forum_posts`, + ( + SELECT `post_parse` + FROM `msz_forum_posts` + WHERE `user_id` = u.`user_id` + AND `post_deleted` IS NULL + ORDER BY `post_id` DESC + LIMIT 1 + ) AS `user_post_parse` + FROM `msz_users` as u + WHERE `user_id` = :user_id + '); + $getPostingInfo->bind('user_id', $userId); + return $getPostingInfo->fetch(); +} + +function forum_count_increase(int $forumId, bool $topic = false): void { + $increaseCount = \Misuzu\DB::prepare(sprintf( + ' + UPDATE `msz_forum_categories` + SET `forum_count_posts` = `forum_count_posts` + 1 + %s + WHERE `forum_id` = :forum + ', + $topic ? ',`forum_count_topics` = `forum_count_topics` + 1' : '' + )); + $increaseCount->bind('forum', $forumId); + $increaseCount->execute(); +} + +function forum_count_synchronise(int $forumId = MSZ_FORUM_ROOT, bool $save = true): array { + static $getChildren = null; + static $getCounts = null; + static $setCounts = null; + + if(is_null($getChildren)) { + $getChildren = \Misuzu\DB::prepare(' + SELECT `forum_id`, `forum_parent` + FROM `msz_forum_categories` + WHERE `forum_parent` = :parent + '); + } + + if(is_null($getCounts)) { + $getCounts = \Misuzu\DB::prepare(' + SELECT :forum as `target_forum_id`, + ( + SELECT COUNT(`topic_id`) + FROM `msz_forum_topics` + WHERE `forum_id` = `target_forum_id` + AND `topic_deleted` IS NULL + ) AS `count_topics`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `forum_id` = `target_forum_id` + AND `post_deleted` IS NULL + ) AS `count_posts` + '); + } + + if($save && is_null($setCounts)) { + $setCounts = \Misuzu\DB::prepare(' + UPDATE `msz_forum_categories` + SET `forum_count_topics` = :topics, + `forum_count_posts` = :posts + WHERE `forum_id` = :forum_id + '); + } + + $getChildren->bind('parent', $forumId); + $children = $getChildren->fetchAll(); + + $topics = 0; + $posts = 0; + + foreach($children as $child) { + $childCount = forum_count_synchronise($child['forum_id'], $save); + $topics += $childCount['topics']; + $posts += $childCount['posts']; + } + + $getCounts->bind('forum', $forumId); + $counts = $getCounts->fetch(); + $topics += $counts['count_topics']; + $posts += $counts['count_posts']; + + if($forumId > 0 && $save) { + $setCounts->bind('forum_id', $forumId); + $setCounts->bind('topics', $topics); + $setCounts->bind('posts', $posts); + $setCounts->execute(); + } + + return compact('topics', 'posts'); +} diff --git a/src/Forum/leaderboard.php b/src/Forum/leaderboard.php new file mode 100644 index 0000000..7d528f5 --- /dev/null +++ b/src/Forum/leaderboard.php @@ -0,0 +1,98 @@ += MSZ_FORUM_LEADERBOARD_START_YEAR && $year <= date('Y'); +} + +function forum_leaderboard_month_valid(?int $year, ?int $month): bool { + if(is_null($month) || !forum_leaderboard_year_valid($year) || $month < 1 || $month > 12) { + return false; + } + + $combo = sprintf('%04d%02d', $year, $month); + $start = sprintf('%04d%02d', MSZ_FORUM_LEADERBOARD_START_YEAR, MSZ_FORUM_LEADERBOARD_START_MONTH); + $current = date('Ym'); + + return $combo >= $start && $combo <= $current; +} + +function forum_leaderboard_categories(): array { + $categories = [ + MSZ_FORUM_LEADERBOARD_CATEGORY_ALL => 'All Time', + ]; + + $currentYear = date('Y'); + $currentMonth = date('m'); + + for($i = $currentYear; $i >= MSZ_FORUM_LEADERBOARD_START_YEAR; $i--) { + $categories[$i] = sprintf('Leaderboard %d', $i); + } + + for($i = $currentYear, $j = $currentMonth;;) { + $categories[sprintf('%d%02d', $i, $j)] = sprintf('Leaderboard %d-%02d', $i, $j); + + if($j <= 1) { + $i--; $j = 12; + } else $j--; + + if($i <= MSZ_FORUM_LEADERBOARD_START_YEAR && $j < MSZ_FORUM_LEADERBOARD_START_MONTH) + break; + } + + return $categories; +} + +function forum_leaderboard_listing( + ?int $year = null, + ?int $month = null, + array $unrankedForums = [], + array $unrankedTopics = [] +): array { + $hasYear = forum_leaderboard_year_valid($year); + $hasMonth = $hasYear && forum_leaderboard_month_valid($year, $month); + $unrankedForums = implode(',', $unrankedForums); + $unrankedTopics = implode(',', $unrankedTopics); + + $rawLeaderboard = \Misuzu\DB::query(sprintf( + ' + SELECT + u.`user_id`, u.`username`, + COUNT(fp.`post_id`) as `posts` + FROM `msz_users` AS u + INNER JOIN `msz_forum_posts` AS fp + ON fp.`user_id` = u.`user_id` + WHERE fp.`post_deleted` IS NULL + %s %s %s + GROUP BY u.`user_id` + HAVING `posts` > 0 + ORDER BY `posts` DESC + ', + $unrankedForums ? sprintf('AND fp.`forum_id` NOT IN (%s)', $unrankedForums) : '', + $unrankedTopics ? sprintf('AND fp.`topic_id` NOT IN (%s)', $unrankedTopics) : '', + !$hasYear ? '' : sprintf( + 'AND DATE(fp.`post_created`) BETWEEN \'%1$04d-%2$02d-01\' AND \'%1$04d-%3$02d-31\'', + $year, + $hasMonth ? $month : 1, + $hasMonth ? $month : 12 + ) + ))->fetchAll(); + + $leaderboard = []; + $ranking = 0; + $lastPosts = null; + + foreach($rawLeaderboard as $entry) { + if(is_null($lastPosts) || $lastPosts > $entry['posts']) { + $ranking++; + $lastPosts = $entry['posts']; + } + + $entry['rank'] = $ranking; + $leaderboard[] = $entry; + } + + return $leaderboard; +} diff --git a/src/Forum/perms.php b/src/Forum/perms.php new file mode 100644 index 0000000..c8ddd9c --- /dev/null +++ b/src/Forum/perms.php @@ -0,0 +1,205 @@ + 0) { + $perms = forum_perms_get_user( + forum_get_parent_id($forum), + $user + ); + } + + $getPerms = \Misuzu\DB::prepare(sprintf( + ' + SELECT %s + FROM `msz_forum_permissions` + WHERE (`forum_id` = :forum_id OR `forum_id` IS NULL) + AND ( + (`user_id` IS NULL AND `role_id` IS NULL) + OR (`user_id` = :user_id_1 AND `role_id` IS NULL) + OR ( + `user_id` IS NULL + AND `role_id` IN ( + SELECT `role_id` + FROM `msz_user_roles` + WHERE `user_id` = :user_id_2 + ) + ) + ) + ', + perms_get_select(MSZ_FORUM_PERM_MODES) + )); + $getPerms->bind('forum_id', $forum); + $getPerms->bind('user_id_1', $user); + $getPerms->bind('user_id_2', $user); + + return $memo[$memoId] = array_bit_or($perms, $getPerms->fetch()); +} + +function forum_perms_get_role(?int $forum, int $role): array { + $perms = perms_get_blank(MSZ_FORUM_PERM_MODES); + + if($role < 1 || $forum < 0) { + return $perms; + } + + static $memo = []; + $memoId = "{$forum}-{$role}"; + + if(array_key_exists($memoId, $memo)) { + return $memo[$memoId]; + } + + if($forum > 0) { + $perms = forum_perms_get_role( + forum_get_parent_id($forum), + $role + ); + } + + $getPerms = \Misuzu\DB::prepare(sprintf( + ' + SELECT %s + FROM `msz_forum_permissions` + WHERE (`forum_id` = :forum_id OR `forum_id` IS NULL) + AND `role_id` = :role_id + AND `user_id` IS NULL + ', + perms_get_select(MSZ_FORUM_PERM_MODES) + )); + $getPerms->bind('forum_id', $forum); + $getPerms->bind('role_id', $role); + + return $memo[$memoId] = array_bit_or($perms, $getPerms->fetch()); +} + +function forum_perms_get_user_raw(?int $forum, int $user): array { + if($user < 1) { + return perms_create(MSZ_FORUM_PERM_MODES); + } + + $getPerms = \Misuzu\DB::prepare(sprintf( + ' + SELECT `%s` + FROM `msz_forum_permissions` + WHERE `forum_id` %s + AND `user_id` = :user_id + AND `role_id` IS NULL + ', + implode('`, `', perms_get_keys(MSZ_FORUM_PERM_MODES)), + $forum === null ? 'IS NULL' : '= :forum_id' + )); + + if($forum !== null) { + $getPerms->bind('forum_id', $forum); + } + + $getPerms->bind('user_id', $user); + $perms = $getPerms->fetch(); + + if(empty($perms)) { + return perms_create(MSZ_FORUM_PERM_MODES); + } + + return $perms; +} + +function forum_perms_get_role_raw(?int $forum, ?int $role): array { + if($role < 1 && $role !== null) { + return perms_create(MSZ_FORUM_PERM_MODES); + } + + $getPerms = \Misuzu\DB::prepare(sprintf( + ' + SELECT `%s` + FROM `msz_forum_permissions` + WHERE `forum_id` %s + AND `user_id` IS NULL + AND `role_id` %s + ', + implode('`, `', perms_get_keys(MSZ_FORUM_PERM_MODES)), + $forum === null ? 'IS NULL' : '= :forum_id', + $role === null ? 'IS NULL' : '= :role_id' + )); + + if($forum !== null) { + $getPerms->bind('forum_id', $forum); + } + + if($role !== null) { + $getPerms->bind('role_id', $role); + } + + $perms = $getPerms->fetch(); + + if(empty($perms)) { + return perms_create(MSZ_FORUM_PERM_MODES); + } + + return $perms; +} + +function forum_perms_check_user( + string $prefix, + ?int $forumId, + ?int $userId, + int $perm, + bool $strict = false +): bool { + return perms_check(forum_perms_get_user($forumId, $userId)[$prefix] ?? 0, $perm, $strict); +} diff --git a/src/Forum/poll.php b/src/Forum/poll.php new file mode 100644 index 0000000..b2a56dc --- /dev/null +++ b/src/Forum/poll.php @@ -0,0 +1,200 @@ +bind('poll', $poll); + return $getPoll->fetch(); +} + +function forum_poll_create(int $maxVotes = 1): int { + if($maxVotes < 1) { + return -1; + } + + $createPoll = \Misuzu\DB::prepare(" + INSERT INTO `msz_forum_polls` + (`poll_max_votes`) + VALUES + (:max_votes) + "); + $createPoll->bind('max_votes', $maxVotes); + return $createPoll->execute() ? \Misuzu\DB::lastId() : -1; +} + +function forum_poll_get_options(int $poll): array { + if($poll < 1) { + return []; + } + + static $polls = []; + + if(array_key_exists($poll, $polls)) { + return $polls[$poll]; + } + + $getOptions = \Misuzu\DB::prepare(' + SELECT `option_id`, `option_text`, + ( + SELECT COUNT(*) + FROM `msz_forum_polls_answers` + WHERE `option_id` = fpo.`option_id` + ) AS `option_votes` + FROM `msz_forum_polls_options` AS fpo + WHERE `poll_id` = :poll + '); + $getOptions->bind('poll', $poll); + + return $polls[$poll] = $getOptions->fetchAll(); +} + +function forum_poll_get_user_answers(int $poll, int $user): array { + if($poll < 1 || $user < 1) { + return []; + } + + $getAnswers = \Misuzu\DB::prepare(" + SELECT `option_id` + FROM `msz_forum_polls_answers` + WHERE `poll_id` = :poll + AND `user_id` = :user + "); + $getAnswers->bind('poll', $poll); + $getAnswers->bind('user', $user); + return array_column($getAnswers->fetchAll(), 'option_id'); +} + +function forum_poll_reset_answers(int $poll): void { + if($poll < 1) { + return; + } + + $resetAnswers = \Misuzu\DB::prepare(" + DELETE FROM `msz_forum_polls_answers` + WHERE `poll_id` = :poll + "); + $resetAnswers->bind('poll', $poll); + $resetAnswers->execute(); +} + +function forum_poll_option_add(int $poll, string $text): int { + if($poll < 1 || empty($text) || strlen($text) > 0xFF) { + return -1; + } + + $addOption = \Misuzu\DB::prepare(" + INSERT INTO `msz_forum_polls_options` + (`poll_id`, `option_text`) + VALUES + (:poll, :text) + "); + $addOption->bind('poll', $poll); + $addOption->bind('text', $text); + return $addOption->execute() ? \Misuzu\DB::lastId() : -1; +} + +function forum_poll_option_remove(int $option): void { + if($option < 1) { + return; + } + + $removeOption = \Misuzu\DB::prepare(" + DELETE FROM `msz_forum_polls_options` + WHERE `option_id` = :option + "); + $removeOption->bind('option', $option); + $removeOption->execute(); +} + +function forum_poll_vote_remove(int $user, int $poll): void { + if($user < 1 || $poll < 1) { + return; + } + + $purgeVote = \Misuzu\DB::prepare(" + DELETE FROM `msz_forum_polls_answers` + WHERE `user_id` = :user + AND `poll_id` = :poll + "); + $purgeVote->bind('user', $user); + $purgeVote->bind('poll', $poll); + $purgeVote->execute(); +} + +function forum_poll_vote_cast(int $user, int $poll, int $option): void { + if($user < 1 || $poll < 1 || $option < 1) { + return; + } + + $castVote = \Misuzu\DB::prepare(" + INSERT INTO `msz_forum_polls_answers` + (`user_id`, `poll_id`, `option_id`) + VALUES + (:user, :poll, :option) + "); + $castVote->bind('user', $user); + $castVote->bind('poll', $poll); + $castVote->bind('option', $option); + $castVote->execute(); +} + +function forum_poll_validate_option(int $poll, int $option): bool { + if($poll < 1 || $option < 1) { + return false; + } + + $checkVote = \Misuzu\DB::prepare(" + SELECT COUNT(`option_id`) > 0 + FROM `msz_forum_polls_options` + WHERE `poll_id` = :poll + AND `option_id` = :option + "); + $checkVote->bind('poll', $poll); + $checkVote->bind('option', $option); + + return (bool)$checkVote->fetchColumn(); +} + +function forum_poll_has_voted(int $user, int $poll): bool { + if($user < 1 || $poll < 1) { + return false; + } + + $getAnswers = \Misuzu\DB::prepare(" + SELECT COUNT(`user_id`) > 0 + FROM `msz_forum_polls_answers` + WHERE `poll_id` = :poll + AND `user_id` = :user + "); + $getAnswers->bind('poll', $poll); + $getAnswers->bind('user', $user); + + return (bool)$getAnswers->fetchColumn(); +} + +function forum_poll_get_topic(int $poll): array { + if($poll < 1) { + return []; + } + + $getTopic = \Misuzu\DB::prepare(" + SELECT `forum_id`, `topic_id`, `topic_locked` + FROM `msz_forum_topics` + WHERE `poll_id` = :poll + "); + $getTopic->bind('poll', $poll); + + return $getTopic->fetch(); +} diff --git a/src/Forum/post.php b/src/Forum/post.php new file mode 100644 index 0000000..8fc3675 --- /dev/null +++ b/src/Forum/post.php @@ -0,0 +1,360 @@ +bind('topic_id', $topicId); + $createPost->bind('forum_id', $forumId); + $createPost->bind('user_id', $userId); + $createPost->bind('post_ip', $ipAddress); + $createPost->bind('post_text', $text); + $createPost->bind('post_parse', $parser); + $createPost->bind('post_display_signature', $displaySignature ? 1 : 0); + + return $createPost->execute() ? \Misuzu\DB::lastId() : 0; +} + +function forum_post_update( + int $postId, + string $ipAddress, + string $text, + int $parser = \Misuzu\Parsers\Parser::PLAIN, + bool $displaySignature = true, + bool $bumpUpdate = true +): bool { + if($postId < 1) { + return false; + } + + $updatePost = \Misuzu\DB::prepare(' + UPDATE `msz_forum_posts` + SET `post_ip` = INET6_ATON(:post_ip), + `post_text` = :post_text, + `post_parse` = :post_parse, + `post_display_signature` = :post_display_signature, + `post_edited` = IF(:bump, NOW(), `post_edited`) + WHERE `post_id` = :post_id + '); + $updatePost->bind('post_id', $postId); + $updatePost->bind('post_ip', $ipAddress); + $updatePost->bind('post_text', $text); + $updatePost->bind('post_parse', $parser); + $updatePost->bind('post_display_signature', $displaySignature ? 1 : 0); + $updatePost->bind('bump', $bumpUpdate ? 1 : 0); + + return $updatePost->execute(); +} + +function forum_post_find(int $postId, int $userId): array { + $getPostInfo = \Misuzu\DB::prepare(sprintf( + ' + SELECT + p.`post_id`, p.`topic_id`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `topic_id` = p.`topic_id` + AND `post_id` < p.`post_id` + AND `post_deleted` IS NULL + ORDER BY `post_id` + ) as `preceeding_post_count`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `topic_id` = p.`topic_id` + AND `post_id` < p.`post_id` + AND `post_deleted` IS NOT NULL + ORDER BY `post_id` + ) as `preceeding_post_deleted_count` + FROM `msz_forum_posts` AS p + WHERE p.`post_id` = :post_id + ')); + $getPostInfo->bind('post_id', $postId); + return $getPostInfo->fetch(); +} + +function forum_post_get(int $postId, bool $allowDeleted = false): array { + $getPost = \Misuzu\DB::prepare(sprintf( + ' + SELECT + p.`post_id`, p.`post_text`, p.`post_created`, p.`post_parse`, p.`post_display_signature`, + p.`topic_id`, p.`post_deleted`, p.`post_edited`, p.`topic_id`, p.`forum_id`, + INET6_NTOA(p.`post_ip`) AS `post_ip`, + u.`user_id` AS `poster_id`, u.`username` AS `poster_name`, + u.`user_created` AS `poster_joined`, u.`user_country` AS `poster_country`, + COALESCE(u.`user_colour`, r.`role_colour`) AS `poster_colour`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `user_id` = p.`user_id` + AND `post_deleted` IS NULL + ) AS `poster_post_count`, + ( + SELECT MIN(`post_id`) = p.`post_id` + FROM `msz_forum_posts` + WHERE `topic_id` = p.`topic_id` + ) AS `is_opening_post`, + ( + SELECT `user_id` = u.`user_id` + FROM `msz_forum_posts` + WHERE `topic_id` = p.`topic_id` + ORDER BY `post_id` + LIMIT 1 + ) AS `is_original_poster` + FROM `msz_forum_posts` AS p + LEFT JOIN `msz_users` AS u + ON u.`user_id` = p.`user_id` + LEFT JOIN `msz_roles` AS r + ON r.`role_id` = u.`display_role` + WHERE `post_id` = :post_id + %1$s + ORDER BY `post_id` + ', + $allowDeleted ? '' : 'AND `post_deleted` IS NULL' + )); + $getPost->bind('post_id', $postId); + return $getPost->fetch(); +} + +function forum_post_search(string $query): array { + $searchPosts = \Misuzu\DB::prepare(' + SELECT + p.`post_id`, p.`post_text`, p.`post_created`, p.`post_parse`, p.`post_display_signature`, + p.`topic_id`, p.`post_deleted`, p.`post_edited`, p.`topic_id`, p.`forum_id`, + INET6_NTOA(p.`post_ip`) AS `post_ip`, + u.`user_id` AS `poster_id`, u.`username` AS `poster_name`, + u.`user_created` AS `poster_joined`, u.`user_country` AS `poster_country`, + u.`user_signature_content` AS `poster_signature_content`, u.`user_signature_parser` AS `poster_signature_parser`, + COALESCE(u.`user_colour`, r.`role_colour`) AS `poster_colour`, + COALESCE(u.`user_title`, r.`role_title`) AS `poster_title`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `user_id` = p.`user_id` + AND `post_deleted` IS NULL + ) AS `poster_post_count`, + ( + SELECT MIN(`post_id`) = p.`post_id` + FROM `msz_forum_posts` + WHERE `topic_id` = p.`topic_id` + ) AS `is_opening_post`, + ( + SELECT `user_id` = u.`user_id` + FROM `msz_forum_posts` + WHERE `topic_id` = p.`topic_id` + ORDER BY `post_id` + LIMIT 1 + ) AS `is_original_poster` + FROM `msz_forum_posts` AS p + LEFT JOIN `msz_users` AS u + ON u.`user_id` = p.`user_id` + LEFT JOIN `msz_roles` AS r + ON r.`role_id` = u.`display_role` + WHERE MATCH(p.`post_text`) + AGAINST (:query IN NATURAL LANGUAGE MODE) + AND `post_deleted` IS NULL + ORDER BY `post_id` + '); + $searchPosts->bind('query', $query); + return $searchPosts->fetchAll(); +} + +function forum_post_count_user(int $userId, bool $showDeleted = false): int { + $getPosts = \Misuzu\DB::prepare(sprintf( + ' + SELECT COUNT(p.`post_id`) + FROM `msz_forum_posts` AS p + WHERE `user_id` = :user_id + %1$s + ', + $showDeleted ? '' : 'AND `post_deleted` IS NULL' + )); + $getPosts->bind('user_id', $userId); + + return (int)$getPosts->fetchColumn(); +} + +function forum_post_listing( + int $topicId, + int $offset = 0, + int $take = 0, + bool $showDeleted = false, + bool $selectAuthor = false +): array { + $hasPagination = $offset >= 0 && $take > 0; + $getPosts = \Misuzu\DB::prepare(sprintf( + ' + SELECT + p.`post_id`, p.`post_text`, p.`post_created`, p.`post_parse`, + p.`topic_id`, p.`post_deleted`, p.`post_edited`, p.`post_display_signature`, + INET6_NTOA(p.`post_ip`) AS `post_ip`, + u.`user_id` AS `poster_id`, u.`username` AS `poster_name`, + u.`user_created` AS `poster_joined`, u.`user_country` AS `poster_country`, + u.`user_signature_content` AS `poster_signature_content`, u.`user_signature_parser` AS `poster_signature_parser`, + COALESCE(u.`user_colour`, r.`role_colour`) AS `poster_colour`, + COALESCE(u.`user_title`, r.`role_title`) AS `poster_title`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `user_id` = p.`user_id` + AND `post_deleted` IS NULL + ) AS `poster_post_count`, + ( + SELECT MIN(`post_id`) = p.`post_id` + FROM `msz_forum_posts` + WHERE `topic_id` = p.`topic_id` + ) AS `is_opening_post`, + ( + SELECT `user_id` = u.`user_id` + FROM `msz_forum_posts` + WHERE `topic_id` = p.`topic_id` + ORDER BY `post_id` + LIMIT 1 + ) AS `is_original_poster` + FROM `msz_forum_posts` AS p + LEFT JOIN `msz_users` AS u + ON u.`user_id` = p.`user_id` + LEFT JOIN `msz_roles` AS r + ON r.`role_id` = u.`display_role` + WHERE %3$s = :topic_id + %1$s + ORDER BY `post_id` + %2$s + ', + $showDeleted ? '' : 'AND `post_deleted` IS NULL', + $hasPagination ? 'LIMIT :offset, :take' : '', + $selectAuthor ? 'p.`user_id`' : 'p.`topic_id`' + )); + $getPosts->bind('topic_id', $topicId); + + if($hasPagination) { + $getPosts->bind('offset', $offset); + $getPosts->bind('take', $take); + } + + return $getPosts->fetchAll(); +} + +define('MSZ_E_FORUM_POST_DELETE_OK', 0); // deleting is fine +define('MSZ_E_FORUM_POST_DELETE_USER', 1); // invalid user +define('MSZ_E_FORUM_POST_DELETE_POST', 2); // post doesn't exist +define('MSZ_E_FORUM_POST_DELETE_DELETED', 3); // post is already marked as deleted +define('MSZ_E_FORUM_POST_DELETE_OWNER', 4); // you may only delete your own posts +define('MSZ_E_FORUM_POST_DELETE_OLD', 5); // posts has existed for too long to be deleted +define('MSZ_E_FORUM_POST_DELETE_PERM', 6); // you aren't allowed to delete posts +define('MSZ_E_FORUM_POST_DELETE_OP', 7); // this is the opening post of a topic + +// only allow posts made within a week of posting to be deleted by normal users +define('MSZ_FORUM_POST_DELETE_LIMIT', 60 * 60 * 24 * 7); + +// set $userId to null for system request, make sure this is NEVER EVER null on user request +// $postId can also be a the return value of forum_post_get if you already grabbed it once before +function forum_post_can_delete($postId, ?int $userId = null): int { + if($userId !== null && $userId < 1) { + return MSZ_E_FORUM_POST_DELETE_USER; + } + + if(is_array($postId)) { + $post = $postId; + } else { + $post = forum_post_get((int)$postId, true); + } + + if(empty($post)) { + return MSZ_E_FORUM_POST_DELETE_POST; + } + + $isSystemReq = $userId === null; + $perms = $isSystemReq ? 0 : forum_perms_get_user($post['forum_id'], $userId)[MSZ_FORUM_PERMS_GENERAL]; + $canDeleteAny = $isSystemReq ? true : perms_check($perms, MSZ_FORUM_PERM_DELETE_ANY_POST); + $canViewPost = $isSystemReq ? true : perms_check($perms, MSZ_FORUM_PERM_VIEW_FORUM); + $postIsDeleted = !empty($post['post_deleted']); + + if(!$canViewPost) { + return MSZ_E_FORUM_POST_DELETE_POST; + } + + if($post['is_opening_post']) { + return MSZ_E_FORUM_POST_DELETE_OP; + } + + if($postIsDeleted) { + return $canDeleteAny ? MSZ_E_FORUM_POST_DELETE_DELETED : MSZ_E_FORUM_POST_DELETE_POST; + } + + if($isSystemReq) { + return MSZ_E_FORUM_POST_DELETE_OK; + } + + if(!$canDeleteAny) { + if(!perms_check($perms, MSZ_FORUM_PERM_DELETE_POST)) { + return MSZ_E_FORUM_POST_DELETE_PERM; + } + + if($post['poster_id'] !== $userId) { + return MSZ_E_FORUM_POST_DELETE_OWNER; + } + + if(strtotime($post['post_created']) <= (time() - MSZ_FORUM_POST_DELETE_LIMIT)) { + return MSZ_E_FORUM_POST_DELETE_OLD; + } + } + + return MSZ_E_FORUM_POST_DELETE_OK; +} + +function forum_post_delete(int $postId): bool { + if($postId < 1) { + return false; + } + + $markDeleted = \Misuzu\DB::prepare(' + UPDATE `msz_forum_posts` + SET `post_deleted` = NOW() + WHERE `post_id` = :post + AND `post_deleted` IS NULL + '); + $markDeleted->bind('post', $postId); + return $markDeleted->execute(); +} + +function forum_post_restore(int $postId): bool { + if($postId < 1) { + return false; + } + + $markDeleted = \Misuzu\DB::prepare(' + UPDATE `msz_forum_posts` + SET `post_deleted` = NULL + WHERE `post_id` = :post + AND `post_deleted` IS NOT NULL + '); + $markDeleted->bind('post', $postId); + return $markDeleted->execute(); +} + +function forum_post_nuke(int $postId): bool { + if($postId < 1) { + return false; + } + + $markDeleted = \Misuzu\DB::prepare(' + DELETE FROM `msz_forum_posts` + WHERE `post_id` = :post + '); + $markDeleted->bind('post', $postId); + return $markDeleted->execute(); +} diff --git a/src/Forum/topic.php b/src/Forum/topic.php new file mode 100644 index 0000000..bfc8325 --- /dev/null +++ b/src/Forum/topic.php @@ -0,0 +1,709 @@ +bind('forum_id', $forumId); + $createTopic->bind('user_id', $userId); + $createTopic->bind('topic_title', $title); + $createTopic->bind('topic_type', $type); + + return $createTopic->execute() ? \Misuzu\DB::lastId() : 0; +} + +function forum_topic_update(int $topicId, ?string $title, ?int $type = null): bool { + if($topicId < 1) { + return false; + } + + // make sure it's null and not some other kinda empty + if(empty($title)) { + $title = null; + } + + if($type !== null && !forum_topic_is_valid_type($type)) { + return false; + } + + $updateTopic = \Misuzu\DB::prepare(' + UPDATE `msz_forum_topics` + SET `topic_title` = COALESCE(:topic_title, `topic_title`), + `topic_type` = COALESCE(:topic_type, `topic_type`) + WHERE `topic_id` = :topic_id + '); + $updateTopic->bind('topic_id', $topicId); + $updateTopic->bind('topic_title', $title); + $updateTopic->bind('topic_type', $type); + + return $updateTopic->execute(); +} + +function forum_topic_get(int $topicId, bool $allowDeleted = false): array { + $getTopic = \Misuzu\DB::prepare(sprintf( + ' + SELECT + t.`topic_id`, t.`forum_id`, t.`topic_title`, t.`topic_type`, t.`topic_locked`, t.`topic_created`, + f.`forum_archived` AS `topic_archived`, t.`topic_deleted`, t.`topic_bumped`, f.`forum_type`, + tp.`poll_id`, tp.`poll_max_votes`, tp.`poll_expires`, tp.`poll_preview_results`, tp.`poll_change_vote`, + (tp.`poll_expires` < CURRENT_TIMESTAMP) AS `poll_expired`, + fp.`topic_id` AS `author_post_id`, fp.`user_id` AS `author_user_id`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `topic_id` = t.`topic_id` + AND `post_deleted` IS NULL + ) AS `topic_count_posts`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `topic_id` = t.`topic_id` + AND `post_deleted` IS NOT NULL + ) AS `topic_count_posts_deleted`, + ( + SELECT COUNT(*) + FROM `msz_forum_polls_answers` + WHERE `poll_id` = tp.`poll_id` + ) AS `poll_votes` + FROM `msz_forum_topics` AS t + LEFT JOIN `msz_forum_categories` AS f + ON f.`forum_id` = t.`forum_id` + LEFT JOIN `msz_forum_posts` AS fp + ON fp.`post_id` = ( + SELECT MIN(`post_id`) + FROM `msz_forum_posts` + WHERE `topic_id` = t.`topic_id` + ) + LEFT JOIN `msz_forum_polls` AS tp + ON tp.`poll_id` = t.`poll_id` + WHERE t.`topic_id` = :topic_id + %s + ', + $allowDeleted ? '' : 'AND t.`topic_deleted` IS NULL' + )); + $getTopic->bind('topic_id', $topicId); + return $getTopic->fetch(); +} + +function forum_topic_bump(int $topicId): bool { + $bumpTopic = \Misuzu\DB::prepare(' + UPDATE `msz_forum_topics` + SET `topic_bumped` = NOW() + WHERE `topic_id` = :topic_id + AND `topic_deleted` IS NULL + '); + $bumpTopic->bind('topic_id', $topicId); + return $bumpTopic->execute(); +} + +function forum_topic_views_increment(int $topicId): void { + if($topicId < 1) { + return; + } + + $bumpViews = \Misuzu\DB::prepare(' + UPDATE `msz_forum_topics` + SET `topic_count_views` = `topic_count_views` + 1 + WHERE `topic_id` = :topic_id + '); + $bumpViews->bind('topic_id', $topicId); + $bumpViews->execute(); +} + +function forum_topic_mark_read(int $userId, int $topicId, int $forumId): void { + if($userId < 1) { + return; + } + + // previously a TRIGGER was used to achieve this behaviour, + // but those explode when running on a lot of queries (like forum_mark_read() does) + // so instead we get to live with this garbage now + try { + $markAsRead = \Misuzu\DB::prepare(' + INSERT INTO `msz_forum_topics_track` + (`user_id`, `topic_id`, `forum_id`, `track_last_read`) + VALUES + (:user_id, :topic_id, :forum_id, NOW()) + '); + $markAsRead->bind('user_id', $userId); + $markAsRead->bind('topic_id', $topicId); + $markAsRead->bind('forum_id', $forumId); + + if($markAsRead->execute()) { + forum_topic_views_increment($topicId); + } + } catch(PDOException $ex) { + if($ex->getCode() != '23000') { + throw $ex; + } + + $markAsRead = \Misuzu\DB::prepare(' + UPDATE `msz_forum_topics_track` + SET `track_last_read` = NOW(), + `forum_id` = :forum_id + WHERE `user_id` = :user_id + AND `topic_id` = :topic_id + '); + $markAsRead->bind('user_id', $userId); + $markAsRead->bind('topic_id', $topicId); + $markAsRead->bind('forum_id', $forumId); + $markAsRead->execute(); + } +} + +function forum_topic_listing( + int $forumId, int $userId, + int $offset = 0, int $take = 0, + bool $showDeleted = false, bool $sortByPriority = false +): array { + $hasPagination = $offset >= 0 && $take > 0; + $getTopics = \Misuzu\DB::prepare(sprintf( + ' + SELECT + :user_id AS `target_user_id`, + t.`topic_id`, t.`topic_title`, t.`topic_locked`, t.`topic_type`, t.`topic_created`, + t.`topic_bumped`, t.`topic_deleted`, t.`topic_count_views`, f.`forum_type`, + COALESCE(SUM(tp.`topic_priority`), 0) AS `topic_priority`, + au.`user_id` AS `author_id`, au.`username` AS `author_name`, + COALESCE(au.`user_colour`, ar.`role_colour`) AS `author_colour`, + lp.`post_id` AS `response_id`, + lp.`post_created` AS `response_created`, + lu.`user_id` AS `respondent_id`, + lu.`username` AS `respondent_name`, + COALESCE(lu.`user_colour`, lr.`role_colour`) AS `respondent_colour`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `topic_id` = t.`topic_id` + %5$s + ) AS `topic_count_posts`, + ( + SELECT CEIL(COUNT(`post_id`) / %6$d) + FROM `msz_forum_posts` + WHERE `topic_id` = t.`topic_id` + %5$s + ) AS `topic_pages`, + ( + SELECT + `target_user_id` > 0 + AND + t.`topic_bumped` > NOW() - INTERVAL 1 MONTH + AND ( + SELECT COUNT(ti.`topic_id`) < 1 + FROM `msz_forum_topics_track` AS tt + RIGHT JOIN `msz_forum_topics` AS ti + ON ti.`topic_id` = tt.`topic_id` + WHERE ti.`topic_id` = t.`topic_id` + AND tt.`user_id` = `target_user_id` + AND `track_last_read` >= `topic_bumped` + ) + ) AS `topic_unread`, + ( + SELECT COUNT(`post_id`) > 0 + FROM `msz_forum_posts` + WHERE `topic_id` = t.`topic_id` + AND `user_id` = `target_user_id` + LIMIT 1 + ) AS `topic_participated` + FROM `msz_forum_topics` AS t + LEFT JOIN `msz_forum_topics_priority` AS tp + ON tp.`topic_id` = t.`topic_id` + LEFT JOIN `msz_forum_categories` AS f + ON f.`forum_id` = t.`forum_id` + LEFT JOIN `msz_users` AS au + ON t.`user_id` = au.`user_id` + LEFT JOIN `msz_roles` AS ar + ON ar.`role_id` = au.`display_role` + LEFT JOIN `msz_forum_posts` AS lp + ON lp.`post_id` = ( + SELECT `post_id` + FROM `msz_forum_posts` + WHERE `topic_id` = t.`topic_id` + %5$s + ORDER BY `post_id` DESC + LIMIT 1 + ) + LEFT JOIN `msz_users` AS lu + ON lu.`user_id` = lp.`user_id` + LEFT JOIN `msz_roles` AS lr + ON lr.`role_id` = lu.`display_role` + WHERE ( + t.`forum_id` = :forum_id + OR t.`topic_type` = %3$d + ) + %1$s + GROUP BY t.`topic_id` + ORDER BY FIELD(t.`topic_type`, %4$s) DESC, %7$s t.`topic_bumped` DESC + %2$s + ', + $showDeleted ? '' : 'AND t.`topic_deleted` IS NULL', + $hasPagination ? 'LIMIT :offset, :take' : '', + MSZ_TOPIC_TYPE_GLOBAL_ANNOUNCEMENT, + implode(',', array_reverse(MSZ_TOPIC_TYPE_ORDER)), + $showDeleted ? '' : 'AND `post_deleted` IS NULL', + MSZ_FORUM_POSTS_PER_PAGE, + $sortByPriority ? '`topic_priority` DESC,' : '' + )); + $getTopics->bind('forum_id', $forumId); + $getTopics->bind('user_id', $userId); + + if($hasPagination) { + $getTopics->bind('offset', $offset); + $getTopics->bind('take', $take); + } + + return $getTopics->fetchAll(); +} + +function forum_topic_count_user(int $authorId, int $userId, bool $showDeleted = false): int { + $getTopics = \Misuzu\DB::prepare(sprintf( + ' + SELECT COUNT(`topic_id`) + FROM `msz_forum_topics` AS t + WHERE t.`user_id` = :author_id + %1$s + ', + $showDeleted ? '' : 'AND t.`topic_deleted` IS NULL' + )); + $getTopics->bind('author_id', $authorId); + //$getTopics->bind('user_id', $userId); + + return (int)$getTopics->fetchColumn(); +} + +// Remove unneccesary stuff from the sql stmt +function forum_topic_listing_user( + int $authorId, + int $userId, + int $offset = 0, + int $take = 0, + bool $showDeleted = false +): array { + $hasPagination = $offset >= 0 && $take > 0; + $getTopics = \Misuzu\DB::prepare(sprintf( + ' + SELECT + :user_id AS `target_user_id`, + t.`topic_id`, t.`topic_title`, t.`topic_locked`, t.`topic_type`, t.`topic_created`, + t.`topic_bumped`, t.`topic_deleted`, t.`topic_count_views`, f.`forum_type`, + au.`user_id` AS `author_id`, au.`username` AS `author_name`, + COALESCE(au.`user_colour`, ar.`role_colour`) AS `author_colour`, + lp.`post_id` AS `response_id`, + lp.`post_created` AS `response_created`, + lu.`user_id` AS `respondent_id`, + lu.`username` AS `respondent_name`, + COALESCE(lu.`user_colour`, lr.`role_colour`) AS `respondent_colour`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `topic_id` = t.`topic_id` + %5$s + ) AS `topic_count_posts`, + ( + SELECT CEIL(COUNT(`post_id`) / %6$d) + FROM `msz_forum_posts` + WHERE `topic_id` = t.`topic_id` + %5$s + ) AS `topic_pages`, + ( + SELECT + `target_user_id` > 0 + AND + t.`topic_bumped` > NOW() - INTERVAL 1 MONTH + AND ( + SELECT COUNT(ti.`topic_id`) < 1 + FROM `msz_forum_topics_track` AS tt + RIGHT JOIN `msz_forum_topics` AS ti + ON ti.`topic_id` = tt.`topic_id` + WHERE ti.`topic_id` = t.`topic_id` + AND tt.`user_id` = `target_user_id` + AND `track_last_read` >= `topic_bumped` + ) + ) AS `topic_unread`, + ( + SELECT COUNT(`post_id`) > 0 + FROM `msz_forum_posts` + WHERE `topic_id` = t.`topic_id` + AND `user_id` = `target_user_id` + LIMIT 1 + ) AS `topic_participated` + FROM `msz_forum_topics` AS t + LEFT JOIN `msz_forum_categories` AS f + ON f.`forum_id` = t.`forum_id` + LEFT JOIN `msz_users` AS au + ON t.`user_id` = au.`user_id` + LEFT JOIN `msz_roles` AS ar + ON ar.`role_id` = au.`display_role` + LEFT JOIN `msz_forum_posts` AS lp + ON lp.`post_id` = ( + SELECT `post_id` + FROM `msz_forum_posts` + WHERE `topic_id` = t.`topic_id` + %5$s + ORDER BY `post_id` DESC + LIMIT 1 + ) + LEFT JOIN `msz_users` AS lu + ON lu.`user_id` = lp.`user_id` + LEFT JOIN `msz_roles` AS lr + ON lr.`role_id` = lu.`display_role` + WHERE au.`user_id` = :author_id + %1$s + ORDER BY FIELD(t.`topic_type`, %4$s) DESC, t.`topic_bumped` DESC + %2$s + ', + $showDeleted ? '' : 'AND t.`topic_deleted` IS NULL', + $hasPagination ? 'LIMIT :offset, :take' : '', + MSZ_TOPIC_TYPE_GLOBAL_ANNOUNCEMENT, + implode(',', array_reverse(MSZ_TOPIC_TYPE_ORDER)), + $showDeleted ? '' : 'AND `post_deleted` IS NULL', + MSZ_FORUM_POSTS_PER_PAGE + )); + $getTopics->bind('author_id', $authorId); + $getTopics->bind('user_id', $userId); + + if($hasPagination) { + $getTopics->bind('offset', $offset); + $getTopics->bind('take', $take); + } + + return $getTopics->fetchAll(); +} + +function forum_topic_listing_search(string $query, int $userId): array { + $getTopics = \Misuzu\DB::prepare(sprintf( + ' + SELECT + :user_id AS `target_user_id`, + t.`topic_id`, t.`topic_title`, t.`topic_locked`, t.`topic_type`, t.`topic_created`, + t.`topic_bumped`, t.`topic_deleted`, t.`topic_count_views`, f.`forum_type`, + au.`user_id` AS `author_id`, au.`username` AS `author_name`, + COALESCE(au.`user_colour`, ar.`role_colour`) AS `author_colour`, + lp.`post_id` AS `response_id`, + lp.`post_created` AS `response_created`, + lu.`user_id` AS `respondent_id`, + lu.`username` AS `respondent_name`, + COALESCE(lu.`user_colour`, lr.`role_colour`) AS `respondent_colour`, + ( + SELECT COUNT(`post_id`) + FROM `msz_forum_posts` + WHERE `topic_id` = t.`topic_id` + AND `post_deleted` IS NULL + ) AS `topic_count_posts`, + ( + SELECT CEIL(COUNT(`post_id`) / %2$d) + FROM `msz_forum_posts` + WHERE `topic_id` = t.`topic_id` + AND `post_deleted` IS NULL + ) AS `topic_pages`, + ( + SELECT + `target_user_id` > 0 + AND + t.`topic_bumped` > NOW() - INTERVAL 1 MONTH + AND ( + SELECT COUNT(ti.`topic_id`) < 1 + FROM `msz_forum_topics_track` AS tt + RIGHT JOIN `msz_forum_topics` AS ti + ON ti.`topic_id` = tt.`topic_id` + WHERE ti.`topic_id` = t.`topic_id` + AND tt.`user_id` = `target_user_id` + AND `track_last_read` >= `topic_bumped` + ) + ) AS `topic_unread`, + ( + SELECT COUNT(`post_id`) > 0 + FROM `msz_forum_posts` + WHERE `topic_id` = t.`topic_id` + AND `user_id` = `target_user_id` + LIMIT 1 + ) AS `topic_participated` + FROM `msz_forum_topics` AS t + LEFT JOIN `msz_forum_categories` AS f + ON f.`forum_id` = t.`forum_id` + LEFT JOIN `msz_users` AS au + ON t.`user_id` = au.`user_id` + LEFT JOIN `msz_roles` AS ar + ON ar.`role_id` = au.`display_role` + LEFT JOIN `msz_forum_posts` AS lp + ON lp.`post_id` = ( + SELECT `post_id` + FROM `msz_forum_posts` + WHERE `topic_id` = t.`topic_id` + AND `post_deleted` IS NULL + ORDER BY `post_id` DESC + LIMIT 1 + ) + LEFT JOIN `msz_users` AS lu + ON lu.`user_id` = lp.`user_id` + LEFT JOIN `msz_roles` AS lr + ON lr.`role_id` = lu.`display_role` + WHERE MATCH(`topic_title`) + AGAINST (:query IN NATURAL LANGUAGE MODE) + AND t.`topic_deleted` IS NULL + ORDER BY FIELD(t.`topic_type`, %1$s) DESC, t.`topic_bumped` DESC + ', + implode(',', array_reverse(MSZ_TOPIC_TYPE_ORDER)), + MSZ_FORUM_POSTS_PER_PAGE + )); + $getTopics->bind('query', $query); + $getTopics->bind('user_id', $userId); + + return $getTopics->fetchAll(); +} + +function forum_topic_lock(int $topicId): bool { + if($topicId < 1) { + return false; + } + + $markLocked = \Misuzu\DB::prepare(' + UPDATE `msz_forum_topics` + SET `topic_locked` = NOW() + WHERE `topic_id` = :topic + AND `topic_locked` IS NULL + '); + $markLocked->bind('topic', $topicId); + + return $markLocked->execute(); +} + +function forum_topic_unlock(int $topicId): bool { + if($topicId < 1) { + return false; + } + + $markUnlocked = \Misuzu\DB::prepare(' + UPDATE `msz_forum_topics` + SET `topic_locked` = NULL + WHERE `topic_id` = :topic + AND `topic_locked` IS NOT NULL + '); + $markUnlocked->bind('topic', $topicId); + + return $markUnlocked->execute(); +} + +define('MSZ_E_FORUM_TOPIC_DELETE_OK', 0); // deleting is fine +define('MSZ_E_FORUM_TOPIC_DELETE_USER', 1); // invalid user +define('MSZ_E_FORUM_TOPIC_DELETE_TOPIC', 2); // topic doesn't exist +define('MSZ_E_FORUM_TOPIC_DELETE_DELETED', 3); // topic is already marked as deleted +define('MSZ_E_FORUM_TOPIC_DELETE_OWNER', 4); // you may only delete your own topics +define('MSZ_E_FORUM_TOPIC_DELETE_OLD', 5); // topic has existed for too long to be deleted +define('MSZ_E_FORUM_TOPIC_DELETE_PERM', 6); // you aren't allowed to delete topics +define('MSZ_E_FORUM_TOPIC_DELETE_POSTS', 7); // the topic already has replies + +// only allow topics made within a day of posting to be deleted by normal users +define('MSZ_FORUM_TOPIC_DELETE_TIME_LIMIT', 60 * 60 * 24); + +// only allow topics with a single post to be deleted, includes soft deleted posts +define('MSZ_FORUM_TOPIC_DELETE_POST_LIMIT', 1); + +// set $userId to null for system request, make sure this is NEVER EVER null on user request +// $topicId can also be a the return value of forum_topic_get if you already grabbed it once before +function forum_topic_can_delete($topicId, ?int $userId = null): int { + if($userId !== null && $userId < 1) { + return MSZ_E_FORUM_TOPIC_DELETE_USER; + } + + if(is_array($topicId)) { + $topic = $topicId; + } else { + $topic = forum_topic_get((int)$topicId, true); + } + + if(empty($topic)) { + return MSZ_E_FORUM_TOPIC_DELETE_TOPIC; + } + + $isSystemReq = $userId === null; + $perms = $isSystemReq ? 0 : forum_perms_get_user($topic['forum_id'], $userId)[MSZ_FORUM_PERMS_GENERAL]; + $canDeleteAny = $isSystemReq ? true : perms_check($perms, MSZ_FORUM_PERM_DELETE_ANY_POST); + $canViewPost = $isSystemReq ? true : perms_check($perms, MSZ_FORUM_PERM_VIEW_FORUM); + $postIsDeleted = !empty($topic['topic_deleted']); + + if(!$canViewPost) { + return MSZ_E_FORUM_TOPIC_DELETE_TOPIC; + } + + if($postIsDeleted) { + return $canDeleteAny ? MSZ_E_FORUM_TOPIC_DELETE_DELETED : MSZ_E_FORUM_TOPIC_DELETE_TOPIC; + } + + if($isSystemReq) { + return MSZ_E_FORUM_TOPIC_DELETE_OK; + } + + if(!$canDeleteAny) { + if(!perms_check($perms, MSZ_FORUM_PERM_DELETE_POST)) { + return MSZ_E_FORUM_TOPIC_DELETE_PERM; + } + + if($topic['author_user_id'] !== $userId) { + return MSZ_E_FORUM_TOPIC_DELETE_OWNER; + } + + if(strtotime($topic['topic_created']) <= (time() - MSZ_FORUM_TOPIC_DELETE_TIME_LIMIT)) { + return MSZ_E_FORUM_TOPIC_DELETE_OLD; + } + + $totalReplies = $topic['topic_count_posts'] + $topic['topic_count_posts_deleted']; + + if($totalReplies > MSZ_E_FORUM_TOPIC_DELETE_POSTS) { + return MSZ_E_FORUM_TOPIC_DELETE_POSTS; + } + } + + return MSZ_E_FORUM_TOPIC_DELETE_OK; +} + +function forum_topic_delete(int $topicId): bool { + if($topicId < 1) { + return false; + } + + $markTopicDeleted = \Misuzu\DB::prepare(' + UPDATE `msz_forum_topics` + SET `topic_deleted` = NOW() + WHERE `topic_id` = :topic + AND `topic_deleted` IS NULL + '); + $markTopicDeleted->bind('topic', $topicId); + + if(!$markTopicDeleted->execute()) { + return false; + } + + $markPostsDeleted = \Misuzu\DB::prepare(' + UPDATE `msz_forum_posts` as p + SET p.`post_deleted` = ( + SELECT `topic_deleted` + FROM `msz_forum_topics` + WHERE `topic_id` = p.`topic_id` + ) + WHERE p.`topic_id` = :topic + AND p.`post_deleted` IS NULL + '); + $markPostsDeleted->bind('topic', $topicId); + + return $markPostsDeleted->execute(); +} + +function forum_topic_restore(int $topicId): bool { + if($topicId < 1) { + return false; + } + + $markPostsRestored = \Misuzu\DB::prepare(' + UPDATE `msz_forum_posts` as p + SET p.`post_deleted` = NULL + WHERE p.`topic_id` = :topic + AND p.`post_deleted` = ( + SELECT `topic_deleted` + FROM `msz_forum_topics` + WHERE `topic_id` = p.`topic_id` + ) + '); + $markPostsRestored->bind('topic', $topicId); + + if(!$markPostsRestored->execute()) { + return false; + } + + $markTopicRestored = \Misuzu\DB::prepare(' + UPDATE `msz_forum_topics` + SET `topic_deleted` = NULL + WHERE `topic_id` = :topic + AND `topic_deleted` IS NOT NULL + '); + $markTopicRestored->bind('topic', $topicId); + + return $markTopicRestored->execute(); +} + +function forum_topic_nuke(int $topicId): bool { + if($topicId < 1) { + return false; + } + + $nukeTopic = \Misuzu\DB::prepare(' + DELETE FROM `msz_forum_topics` + WHERE `topic_id` = :topic + '); + $nukeTopic->bind('topic', $topicId); + return $nukeTopic->execute(); +} + +function forum_topic_priority(int $topic): array { + if($topic < 1) { + return []; + } + + $getPriority = \Misuzu\DB::prepare(' + SELECT + tp.`topic_id`, tp.`topic_priority`, + u.`user_id`, u.`username`, + COALESCE(u.`user_colour`, r.`role_colour`) AS `user_colour` + FROM `msz_forum_topics_priority` AS tp + LEFT JOIN `msz_users` AS u + ON u.`user_id` = tp.`user_id` + LEFT JOIN `msz_roles` AS r + ON u.`display_role` = r.`role_id` + WHERE `topic_id` = :topic + '); + $getPriority->bind('topic', $topic); + + return $getPriority->fetchAll(); +} + +function forum_topic_priority_increase(int $topic, int $user, int $bump = 1): void { + if($topic < 1 || $user < 1 || $bump === 0) { + return; + } + + $bumpPriority = \Misuzu\DB::prepare(' + INSERT INTO `msz_forum_topics_priority` + (`topic_id`, `user_id`, `topic_priority`) + VALUES + (:topic, :user, :bump1) + ON DUPLICATE KEY UPDATE + `topic_priority` = `topic_priority` + :bump2 + '); + $bumpPriority->bind('topic', $topic); + $bumpPriority->bind('user', $user); + $bumpPriority->bind('bump1', $bump); + $bumpPriority->bind('bump2', $bump); + $bumpPriority->execute(); +} diff --git a/src/Forum/validate.php b/src/Forum/validate.php new file mode 100644 index 0000000..5c0a6ba --- /dev/null +++ b/src/Forum/validate.php @@ -0,0 +1,33 @@ + MSZ_TOPIC_TITLE_LENGTH_MAX) { + return 'too-long'; + } + + return ''; +} + +function forum_validate_post(string $text): string { + $length = mb_strlen(trim($text)); + + if($length < MSZ_POST_TEXT_LENGTH_MIN) { + return 'too-short'; + } + + if($length > MSZ_POST_TEXT_LENGTH_MAX) { + return 'too-long'; + } + + return ''; +} diff --git a/src/GitInfo.php b/src/GitInfo.php new file mode 100644 index 0000000..cd73ac3 --- /dev/null +++ b/src/GitInfo.php @@ -0,0 +1,23 @@ + [ + 'root' => MSZ_ROOT . '/assets/js', + 'mime' => 'application/javascript; charset=utf-8', + ], + 'css' => [ + 'root' => MSZ_ROOT . '/assets/css', + 'mime' => 'text/css; charset=utf-8', + ], + ]; + + public function __construct() { + $GLOBALS['misuzuBypassLockdown'] = true; + parent::__construct(); + } + + private static function recurse(string $dir): string { + $str = ''; + $dir = rtrim(realpath($dir), '/') . '/*'; + $dirs = []; + + foreach(glob($dir) as $path) { + if(is_dir($path)) { + $dirs[] = $path; + continue; + } + + if(MSZ_DEBUG) + $str .= "/*** {$path} ***/\n"; + $str .= trim(file_get_contents($path)); + $str .= "\n\n"; + } + + foreach($dirs as $path) + $str .= self::recurse($path); + + return $str; + } + + public function serveComponent($response, $request, string $fileName) { + $name = pathinfo($fileName, PATHINFO_FILENAME); + $type = pathinfo($fileName, PATHINFO_EXTENSION); + + $entityTag = sprintf('%s.%s/%s', $name, $type, GitInfo::hash()); + + if(!MSZ_DEBUG && $name === 'debug') + return 404; + if(!MSZ_DEBUG && $request->getHeaderFirstLine('If-None-Match') === '"' . $entityTag . '"') + return 304; + + if(array_key_exists($type, self::TYPES)) { + $type = self::TYPES[$type]; + $path = ($type['root'] ?? '') . '/' . $name; + + if(is_dir($path)) { + $response->setContentType($type['mime'] ?? 'application/octet-stream'); + $response->setCacheControl(MSZ_DEBUG ? 'no-cache' : 'must-revalidate'); + $response->setEntityTag($entityTag); + return self::recurse($path); + } + } + } + + private function canViewAsset($request, User $assetUser): bool { + return !$assetUser->isBanned() || ( + User::hasCurrent() + && parse_url($request->getHeaderFirstLine('Referer'), PHP_URL_PATH) === url('user-profile') + && perms_check_user(MSZ_PERMS_USER, User::getCurrent()->getId(), MSZ_PERM_USER_MANAGE_USERS) + ); + } + + private function serveUserAsset($response, $request, UserImageAssetInterface $assetInfo): void { + $contentType = $assetInfo->getMimeType(); + $publicPath = $assetInfo->getPublicPath(); + $fileName = $assetInfo->getFileName(); + + if($assetInfo instanceof UserAssetScalableInterface) { + $dimensions = (int)($request->getParam('res', FILTER_SANITIZE_NUMBER_INT) ?? $request->getParam('r', FILTER_SANITIZE_NUMBER_INT)); + + if($dimensions > 0) { + $assetInfo->ensureScaledExists($dimensions); + $contentType = $assetInfo->getScaledMimeType($dimensions); + $publicPath = $assetInfo->getPublicScaledPath($dimensions); + $fileName = $assetInfo->getScaledFileName($dimensions); + } + } + + $response->accelRedirect($publicPath); + $response->setContentType($contentType); + $response->setFileName($fileName, false); + } + + public function serveAvatar($response, $request, string $fileName) { + $userId = intval(pathinfo($fileName, PATHINFO_FILENAME)); + $type = pathinfo($fileName, PATHINFO_EXTENSION); + + if($type !== '' && $type !== 'png') + return 404; + + $assetInfo = new StaticUserImageAsset(MSZ_PUBLIC . '/images/no-avatar.png', MSZ_PUBLIC); + + try { + $userInfo = User::byId($userId); + + if(!$this->canViewAsset($request, $userInfo)) { + $assetInfo = new StaticUserImageAsset(MSZ_PUBLIC . '/images/banned-avatar.png', MSZ_PUBLIC); + } elseif($userInfo->hasAvatar()) { + $assetInfo = $userInfo->getAvatarInfo(); + } + } catch(UserNotFoundException $ex) {} + + $this->serveUserAsset($response, $request, $assetInfo); + } + + public function serveProfileBackground($response, $request, string $fileName) { + $userId = intval(pathinfo($fileName, PATHINFO_FILENAME)); + $type = pathinfo($fileName, PATHINFO_EXTENSION); + + if($type !== '' && $type !== 'png') + return 404; + + try { + $userInfo = User::byId($userId); + } catch(UserNotFoundException $ex) {} + + if(empty($userInfo) || !$userInfo->hasBackground() || !$this->canViewAsset($request, $userInfo)) { + $response->setContent(''); + return 404; + } + + $this->serveUserAsset($response, $request, $userInfo->getBackgroundInfo()); + } + + public function serveLegacy($response, $request) { + $assetUserId = (int)$request->getParam('u', FILTER_SANITIZE_NUMBER_INT); + + switch($request->getParam('m')) { + case 'avatar': + $this->serveAvatar($response, $request, $assetUserId); + return; + case 'background': + $this->serveProfileBackground($response, $request, $assetUserId); + return; + } + + $response->setContent(''); + return 404; + } +} diff --git a/src/Http/Handlers/ChangelogHandler.php b/src/Http/Handlers/ChangelogHandler.php new file mode 100644 index 0000000..f423b18 --- /dev/null +++ b/src/Http/Handlers/ChangelogHandler.php @@ -0,0 +1,117 @@ +getParam('date'); + $filterUser = $request->getParam('user', FILTER_SANITIZE_NUMBER_INT); + //$filterTags = $request->getParam('tags'); + + if($filterDate !== null) + try { + $dateParts = explode('-', $filterDate, 3); + $filterDate = gmmktime(12, 0, 0, intval($dateParts[1]), intval($dateParts[2]), intval($dateParts[0])); + } catch(ErrorException $ex) { + return 404; + } + + if($filterUser !== null) + try { + $filterUser = User::byId($filterUser); + } catch(UserNotFoundException $ex) { + return 404; + } + + /*if($filterTags !== null) { + $splitTags = explode(',', $filterTags); + $filterTags = []; + for($i = 0; $i < min(10, count($splitTags)); ++$i) + try { + $filterTags[] = ChangelogTag::byId($splitTags[$i]); + } catch(ChangelogTagNotFoundException $ex) { + return 404; + } + }*/ + + $count = $filterDate !== null ? -1 : ChangelogChange::countAll($filterDate, $filterUser); + $pagination = new Pagination($count, 30); + if(!$pagination->hasValidOffset()) + return 404; + + $changes = ChangelogChange::all($pagination, $filterDate, $filterUser); + if(empty($changes)) + return 404; + + $response->setContent(Template::renderRaw('changelog.index', [ + 'changelog_infos' => $changes, + 'changelog_date' => $filterDate, + 'changelog_user' => $filterUser, + 'changelog_pagination' => $pagination, + 'comments_user' => User::getCurrent(), + ])); + } + + public function change($response, $request, int $changeId) { + try { + $changeInfo = ChangelogChange::byId($changeId); + } catch(ChangelogChangeNotFoundException $ex) { + return 404; + } + + $response->setContent(Template::renderRaw('changelog.change', [ + 'change_info' => $changeInfo, + 'comments_user' => User::getCurrent(), + ])); + } + + private function createFeed(string $feedMode): Feed { + $changes = ChangelogChange::all(new Pagination(10)); + + $feed = (new Feed) + ->setTitle(Config::get('site.name', Config::TYPE_STR, 'Misuzu') . ' » Changelog') + ->setDescription('Live feed of changes to ' . Config::get('site.name', Config::TYPE_STR, 'Misuzu') . '.') + ->setContentUrl(url_prefix(false) . url('changelog-index')) + ->setFeedUrl(url_prefix(false) . url("changelog-feed-{$feedMode}")); + + foreach($changes as $change) { + $changeUrl = url_prefix(false) . url('changelog-change', ['change' => $change->getId()]); + $commentsUrl = url_prefix(false) . url('changelog-change-comments', ['change' => $change->getId()]); + + $feedItem = (new FeedItem) + ->setTitle($change->getActionString() . ': ' . $change->getHeader()) + ->setCreationDate($change->getCreatedTime()) + ->setUniqueId($changeUrl) + ->setContentUrl($changeUrl) + ->setCommentsUrl($commentsUrl); + + $feed->addItem($feedItem); + } + + return $feed; + } + + public function feedAtom($response, $request) { + $response->setContentType('application/atom+xml; charset=utf-8'); + return (new AtomFeedSerializer)->serializeFeed(self::createFeed('atom')); + } + + public function feedRss($response, $request) { + $response->setContentType('application/rss+xml; charset=utf-8'); + return (new RssFeedSerializer)->serializeFeed(self::createFeed('rss')); + } +} diff --git a/src/Http/Handlers/ForumHandler.php b/src/Http/Handlers/ForumHandler.php new file mode 100644 index 0000000..e982009 --- /dev/null +++ b/src/Http/Handlers/ForumHandler.php @@ -0,0 +1,49 @@ +getParam('forum', FILTER_SANITIZE_NUMBER_INT); + $response->setContent(Template::renderRaw('confirm', [ + 'title' => 'Mark forum as read', + 'message' => 'Are you sure you want to mark ' . ($forumId === 0 ? 'the entire' : 'this') . ' forum as read?', + 'return' => url($forumId ? 'forum-category' : 'forum-index', ['forum' => $forumId]), + 'params' => [ + 'forum' => $forumId, + ] + ])); + } + + public function markAsReadPOST($response, $request) { + if(!UserSession::hasCurrent() || !User::hasCurrent()) + return 403; + + if(!$request->isFormContent()) + return 400; + + + $token = $request->getHeaderLine('X-Misuzu-CSRF'); + if(empty($token)) + $token = $request->getBodyParam('_csrf'); + if(empty($token) || !CSRF::validate($token)) + return 400; + + $forumId = (int)$request->getContent()->getParam('forum', FILTER_SANITIZE_NUMBER_INT); + forum_mark_read($forumId, User::getCurrent()->getId()); + $redirect = url($forumId ? 'forum-category' : 'forum-index', ['forum' => $forumId]); + + if($request->hasHeader('X-Misuzu-XHR')) { + $response->setStatusCode(302); + $response->setHeader('X-Misuzu-Location', $redirect); + } else + $response->redirect($redirect, false); + } +} diff --git a/src/Http/Handlers/Handler.php b/src/Http/Handlers/Handler.php new file mode 100644 index 0000000..faff757 --- /dev/null +++ b/src/Http/Handlers/Handler.php @@ -0,0 +1,8 @@ +home($response, $request); + else + $this->landing($response, $request); + } + + public function landing($response, $request): void { + $linkedData = Config::get('social.embed_linked', Config::TYPE_BOOL) + ? [ + 'name' => Config::get('site.name', Config::TYPE_STR, 'Misuzu'), + 'url' => Config::get('site.url', Config::TYPE_STR), + 'logo' => Config::get('site.ext_logo', Config::TYPE_STR), + 'same_as' => Config::get('social.linked', Config::TYPE_ARR), + ] : null; + + + $featuredNews = NewsPost::all(new Pagination(3), true); + + $stats = DB::query( + 'SELECT' + . ' (SELECT COUNT(`user_id`) FROM `msz_users` WHERE `user_deleted` IS NULL) AS `count_users_all`,' + . ' (SELECT COUNT(`user_id`) FROM `msz_users` WHERE `user_active` >= DATE_SUB(NOW(), INTERVAL 5 MINUTE)) AS `count_users_online`,' + . ' (SELECT COUNT(`user_id`) FROM `msz_users` WHERE `user_active` >= DATE_SUB(NOW(), INTERVAL 24 HOUR)) AS `count_users_active`,' + . ' (SELECT COUNT(`comment_id`) FROM `msz_comments_posts` WHERE `comment_deleted` IS NULL) AS `count_comments`,' + . ' (SELECT COUNT(`topic_id`) FROM `msz_forum_topics` WHERE `topic_deleted` IS NULL) AS `count_forum_topics`,' + . ' (SELECT COUNT(`post_id`) FROM `msz_forum_posts` WHERE `post_deleted` IS NULL) AS `count_forum_posts`' + )->fetch(); + + $onlineUsers = DB::query( + 'SELECT u.`user_id`, u.`username`, COALESCE(u.`user_colour`, r.`role_colour`) AS `user_colour`' + . ' FROM `msz_users` AS u' + . ' LEFT JOIN `msz_roles` AS r' + . ' ON r.`role_id` = u.`display_role`' + . ' WHERE u.`user_active` >= DATE_SUB(NOW(), INTERVAL 5 MINUTE)' + . ' ORDER BY u.`user_active` DESC, RAND()' + . ' LIMIT 100' + )->fetchAll(); + + // TODO: don't hardcode forum ids + $featuredForums = Config::get('landing.forum_categories', Config::TYPE_ARR); + + $popularTopics = []; + $activeTopics = []; + + if(!empty($featuredForums)) { + $getPopularTopics = DB::prepare( + 'SELECT t.`topic_id`, c.`forum_id`, t.`topic_title`, c.`forum_icon`, t.`topic_count_views`' + . ', (SELECT COUNT(*) FROM `msz_forum_posts` AS p WHERE p.`topic_id` = t.`topic_id` AND `post_deleted` IS NULL) AS `topic_count_posts`' + . ' FROM `msz_forum_topics` AS t' + . ' LEFT JOIN `msz_forum_categories` AS c ON c.`forum_id` = t.`forum_id`' + . ' WHERE c.`forum_id` IN (' . implode(',', $featuredForums) . ') AND `topic_deleted` IS NULL AND `topic_locked` IS NULL' + . ' ORDER BY (SELECT COUNT(*) FROM `msz_forum_posts` AS p WHERE p.`topic_id` = t.`topic_id` AND `post_deleted` IS NULL AND `post_created` > NOW() - INTERVAL 3 MONTH) DESC' + )->stmt; + $getPopularTopics->execute(); + for($i = 0; $i < 10; ++$i) { + $topicInfo = $getPopularTopics->fetchObject(); + if(empty($topicInfo)) + break; + $popularTopics[] = $topicInfo; + } + + $getActiveTopics = DB::prepare( + 'SELECT t.`topic_id`, c.`forum_id`, t.`topic_title`, c.`forum_icon`, t.`topic_count_views`' + . ', (SELECT COUNT(*) FROM `msz_forum_posts` AS p WHERE p.`topic_id` = t.`topic_id` AND `post_deleted` IS NULL) AS `topic_count_posts`' + . ', (SELECT MAX(`post_id`) FROM `msz_forum_posts` AS p WHERE p.`topic_id` = t.`topic_id` AND `post_deleted` IS NULL) AS `latest_post_id`' + . ' FROM `msz_forum_topics` AS t' + . ' LEFT JOIN `msz_forum_categories` AS c ON c.`forum_id` = t.`forum_id`' + . ' WHERE c.`forum_id` IN (' . implode(',', $featuredForums) . ') AND `topic_deleted` IS NULL AND `topic_locked` IS NULL' + . ' ORDER BY `topic_bumped` DESC' + )->stmt; + $getActiveTopics->execute(); + for($i = 0; $i < 10; ++$i) { + $topicInfo = $getActiveTopics->fetchObject(); + if(empty($topicInfo)) + break; + $activeTopics[] = $topicInfo; + } + } + + $response->setContent(Template::renderRaw('home.landing', [ + 'statistics' => $stats, + 'online_users' => $onlineUsers, + 'featured_news' => $featuredNews, + 'linked_data' => $linkedData, + 'forum_popular' => $popularTopics, + 'forum_active' => $activeTopics, + ])); + } + + public function home($response, $request): void { + $featuredNews = NewsPost::all(new Pagination(5), true); + + $stats = DB::query( + 'SELECT' + . ' (SELECT COUNT(`user_id`) FROM `msz_users` WHERE `user_deleted` IS NULL) AS `count_users_all`,' + . ' (SELECT COUNT(`user_id`) FROM `msz_users` WHERE `user_active` >= DATE_SUB(NOW(), INTERVAL 5 MINUTE)) AS `count_users_online`,' + . ' (SELECT COUNT(`user_id`) FROM `msz_users` WHERE `user_active` >= DATE_SUB(NOW(), INTERVAL 24 HOUR)) AS `count_users_active`,' + . ' (SELECT COUNT(`comment_id`) FROM `msz_comments_posts` WHERE `comment_deleted` IS NULL) AS `count_comments`,' + . ' (SELECT COUNT(`topic_id`) FROM `msz_forum_topics` WHERE `topic_deleted` IS NULL) AS `count_forum_topics`,' + . ' (SELECT COUNT(`post_id`) FROM `msz_forum_posts` WHERE `post_deleted` IS NULL) AS `count_forum_posts`' + )->fetch(); + + $changelog = ChangelogChange::all(new Pagination(10)); + + $birthdays = User::byBirthdate(); + $latestUser = !empty($birthdays) ? null : User::byLatest(); + + $onlineUsers = DB::query( + 'SELECT u.`user_id`, u.`username`, COALESCE(u.`user_colour`, r.`role_colour`) AS `user_colour`' + . ' FROM `msz_users` AS u' + . ' LEFT JOIN `msz_roles` AS r' + . ' ON r.`role_id` = u.`display_role`' + . ' WHERE u.`user_active` >= DATE_SUB(NOW(), INTERVAL 5 MINUTE)' + . ' ORDER BY u.`user_active` DESC, RAND()' + . ' LIMIT 104' + )->fetchAll(); + + $response->setContent(Template::renderRaw('home.home', [ + 'statistics' => $stats, + 'latest_user' => $latestUser, + 'online_users' => $onlineUsers, + 'birthdays' => $birthdays, + 'featured_changelog' => $changelog, + 'featured_news' => $featuredNews, + ])); + } +} diff --git a/src/Http/Handlers/InfoHandler.php b/src/Http/Handlers/InfoHandler.php new file mode 100644 index 0000000..24929cb --- /dev/null +++ b/src/Http/Handlers/InfoHandler.php @@ -0,0 +1,71 @@ +setContent(Template::renderRaw('info.index')); + } + + public function page($response, $request, string ...$parts) { + $name = implode('/', $parts); + $document = [ + 'content' => '', + 'title' => '', + ]; + + $isIndexDoc = $name === 'index' || str_starts_with($name, 'index/'); + $isMisuzuDoc = $name === 'misuzu' || str_starts_with($name, 'misuzu/'); + + if($isMisuzuDoc) { + $fileName = substr($name, 7); + $fileName = empty($fileName) ? 'README' : strtoupper($fileName); + if($fileName !== 'README') + $titleSuffix = ' - Misuzu Project'; + } elseif($isIndexDoc) { + $fileName = substr($name, 6); + $fileName = empty($fileName) ? 'README' : strtoupper($fileName); + if($fileName !== 'README') + $titleSuffix = ' - Index Project'; + } else $fileName = strtolower($name); + + if(!preg_match('#^([A-Za-z0-9_]+)$#', $fileName)) + return 404; + + if($fileName !== 'LICENSE' && $fileName !== 'LICENCE') + $fileName .= '.md'; + + $pfx = ''; + + if($isIndexDoc) + $pfx = '/lib/index'; + elseif(!$isMisuzuDoc) + $pfx = '/docs'; + + $fileName = MSZ_ROOT . $pfx . '/' . $fileName; + $document['content'] = is_file($fileName) ? file_get_contents($fileName) : ''; + + if(empty($document['content'])) + return 404; + + if($document['title'] === '') { + if(str_starts_with($document['content'], '# ')) { + $titleOffset = strpos($document['content'], "\n"); + $document['title'] = trim(substr($document['content'], 2, $titleOffset - 1)); + $document['content'] = substr($document['content'], $titleOffset); + } else + $document['title'] = ucfirst(basename($fileName)); + + if(!empty($titleSuffix)) + $document['title'] .= $titleSuffix; + } + + $document['content'] = Parser::instance(Parser::MARKDOWN)->parseText($document['content']); + + $response->setContent(Template::renderRaw('info.view', [ + 'document' => $document, + ])); + } +} diff --git a/src/Http/Handlers/NewsHandler.php b/src/Http/Handlers/NewsHandler.php new file mode 100644 index 0000000..2739ac4 --- /dev/null +++ b/src/Http/Handlers/NewsHandler.php @@ -0,0 +1,145 @@ +hasValidOffset()) + return 404; + + $response->setContent(Template::renderRaw('news.index', [ + 'categories' => $categories, + 'posts' => NewsPost::all($newsPagination, true), + 'news_pagination' => $newsPagination, + ])); + } + + public function viewCategory($response, $request, string $fileName) { + $categoryId = intval(pathinfo($fileName, PATHINFO_FILENAME)); + $type = pathinfo($fileName, PATHINFO_EXTENSION); + + try { + $categoryInfo = NewsCategory::byId($categoryId); + } catch(NewsCategoryNotFoundException $ex) { + return 404; + } + + if($type === 'atom') + return $this->feedCategoryAtom($response, $request, $categoryInfo); + elseif($type === 'rss') + return $this->feedCategoryRss($response, $request, $categoryInfo); + elseif($type !== '') + return 404; + + $categoryPagination = new Pagination(NewsPost::countByCategory($categoryInfo), 5); + if(!$categoryPagination->hasValidOffset()) + return 404; + + $response->setContent(Template::renderRaw('news.category', [ + 'category_info' => $categoryInfo, + 'posts' => $categoryInfo->posts($categoryPagination), + 'news_pagination' => $categoryPagination, + ])); + } + + public function viewPost($response, $request, int $postId) { + try { + $postInfo = NewsPost::byId($postId); + } catch(NewsPostNotFoundException $ex) { + return 404; + } + + if(!$postInfo->isPublished() || $postInfo->isDeleted()) + return 404; + + $postInfo->ensureCommentsCategory(); + $commentsInfo = $postInfo->getCommentsCategory(); + + $response->setContent(Template::renderRaw('news.post', [ + 'post_info' => $postInfo, + 'comments_info' => $commentsInfo, + 'comments_user' => User::getCurrent(), + ])); + } + + private function createFeed(string $feedMode, ?NewsCategory $categoryInfo, array $posts): Feed { + $hasCategory = !empty($categoryInfo); + $pagination = new Pagination(10); + $posts = $hasCategory ? $categoryInfo->posts($pagination) : NewsPost::all($pagination, true); + + $feed = (new Feed) + ->setTitle(Config::get('site.name', Config::TYPE_STR, 'Misuzu') . ' » ' . ($hasCategory ? $categoryInfo->getName() : 'Featured News')) + ->setDescription($hasCategory ? $categoryInfo->getDescription() : 'A live featured news feed.') + ->setContentUrl(url_prefix(false) . ($hasCategory ? url('news-category', ['category' => $categoryInfo->getId()]) : url('news-index'))) + ->setFeedUrl(url_prefix(false) . ($hasCategory ? url("news-category-feed-{$feedMode}", ['category' => $categoryInfo->getId()]) : url("news-feed-{$feedMode}"))); + + foreach($posts as $post) { + $postUrl = url_prefix(false) . url('news-post', ['post' => $post->getId()]); + $commentsUrl = url_prefix(false) . url('news-post-comments', ['post' => $post->getId()]); + $authorUrl = url_prefix(false) . url('user-profile', ['user' => $post->getUser()->getId()]); + + $feedItem = (new FeedItem) + ->setTitle($post->getTitle()) + ->setSummary($post->getFirstParagraph()) + ->setContent(Parser::instance(Parser::MARKDOWN)->parseText($post->getText())) + ->setCreationDate($post->getCreatedTime()) + ->setUniqueId($postUrl) + ->setContentUrl($postUrl) + ->setCommentsUrl($commentsUrl) + ->setAuthorName($post->getUser()->getUsername()) + ->setAuthorUrl($authorUrl); + + if(!$feed->hasLastUpdate() || $feed->getLastUpdate() < $feedItem->getCreationDate()) + $feed->setLastUpdate($feedItem->getCreationDate()); + + $feed->addItem($feedItem); + } + + return $feed; + } + + public function feedIndexAtom($response, $request) { + $response->setContentType('application/atom+xml; charset=utf-8'); + return (new AtomFeedSerializer)->serializeFeed( + self::createFeed('atom', null, NewsPost::all(new Pagination(10), true)) + ); + } + + public function feedIndexRss($response, $request) { + $response->setContentType('application/rss+xml; charset=utf-8'); + return (new RssFeedSerializer)->serializeFeed( + self::createFeed('rss', null, NewsPost::all(new Pagination(10), true)) + ); + } + + public function feedCategoryAtom($response, $request, NewsCategory $categoryInfo) { + $response->setContentType('application/atom+xml; charset=utf-8'); + return (new AtomFeedSerializer)->serializeFeed( + self::createFeed('atom', $categoryInfo, $categoryInfo->posts(new Pagination(10))) + ); + } + + public function feedCategoryRss($response, $request, NewsCategory $categoryInfo) { + $response->setContentType('application/rss+xml; charset=utf-8'); + return (new RssFeedSerializer)->serializeFeed( + self::createFeed('rss', $categoryInfo, $categoryInfo->posts(new Pagination(10))) + ); + } +} diff --git a/src/Imaging/GdImage.php b/src/Imaging/GdImage.php new file mode 100644 index 0000000..255d499 --- /dev/null +++ b/src/Imaging/GdImage.php @@ -0,0 +1,112 @@ + 'imagecreatefromgif', + IMAGETYPE_JPEG => 'imagecreatefromjpeg', + IMAGETYPE_PNG => 'imagecreatefrompng', + IMAGETYPE_BMP => 'imagecreatefrombmp', + IMAGETYPE_WBMP => 'imagecreatefromwbmp', + IMAGETYPE_WEBP => 'imagecreatefromwebp', + ]; + + private const SAVERS = [ + IMAGETYPE_GIF => 'imagegif', + IMAGETYPE_JPEG => 'imagejpeg', + IMAGETYPE_PNG => 'imagepng', + IMAGETYPE_BMP => 'imagebmp', + IMAGETYPE_WBMP => 'imagewbmp', + IMAGETYPE_WEBP => 'imagewebp', + ]; + + public function __construct($pathOrWidth, int $height = -1) { + parent::__construct($pathOrWidth); + + if(is_int($pathOrWidth)) { + $this->gd = imagecreatetruecolor($pathOrWidth, $height < 1 ? $pathOrWidth : $height); + $this->type = IMAGETYPE_PNG; + } elseif(is_string($pathOrWidth)) { + $imageInfo = getimagesize($pathOrWidth); + + if($imageInfo !== false) { + $this->type = $imageInfo[2]; + + if(isset(self::CONSTRUCTORS[$this->type])) + $this->gd = self::CONSTRUCTORS[$this->type]($pathOrWidth); + } + } + + if(!isset($this->gd)) { + throw new InvalidArgumentException('Unsupported image format.'); + } + } + + public function __destruct() { + if(isset($this->gd)) + $this->destroy(); + } + + public function getWidth(): int { + return imagesx($this->gd); + } + + public function getHeight(): int { + return imagesy($this->gd); + } + + public function hasFrames(): bool { + return false; + } + + public function next(): bool { + return false; + } + + public function resize(int $width, int $height): bool { + $resized = imagescale($this->gd, $width, $height, IMG_BICUBIC_FIXED); + + if($resized === false) + return false; + + imagedestroy($this->gd); + $this->gd = $resized; + + return true; + } + + public function crop(int $width, int $height, int $x, int $y): bool { + $cropped = imagecrop($this->gd, compact('width', 'height', 'x', 'y')); + + if($cropped === false) + return false; + + imagedestroy($this->gd); + $this->gd = $cropped; + + return true; + } + + public function setPage(int $width, int $height, int $x, int $y): bool { + return false; + } + + public function save(string $path): bool { + if(isset(self::SAVERS[$this->type])) + return self::SAVERS[$this->type]($this->gd, $path); + + return false; + } + + public function destroy(): void { + if(imagedestroy($this->gd)) { + $this->gd = null; + $this->type = 0; + } + } +} diff --git a/src/Imaging/Image.php b/src/Imaging/Image.php new file mode 100644 index 0000000..850ff96 --- /dev/null +++ b/src/Imaging/Image.php @@ -0,0 +1,56 @@ +getWidth(); + $originalHeight = $this->getHeight(); + + if($originalWidth > $originalHeight) { + $targetWidth = $originalWidth * $dimensions / $originalHeight; + $targetHeight = $dimensions; + } else { + $targetWidth = $dimensions; + $targetHeight = $originalHeight * $dimensions / $originalWidth; + } + + $targetWidth = intval($targetWidth); + $targetHeight = intval($targetHeight); + + do { + $this->resize($targetWidth, $targetHeight); + $this->crop( + $dimensions, $dimensions, + ceil(($targetWidth - $dimensions) / 2), + ceil(($targetHeight - $dimensions) / 2) + ); + $this->setPage($dimensions, $dimensions, 0, 0); + } while($this->next()); + } +} diff --git a/src/Imaging/ImagickImage.php b/src/Imaging/ImagickImage.php new file mode 100644 index 0000000..4fd5950 --- /dev/null +++ b/src/Imaging/ImagickImage.php @@ -0,0 +1,76 @@ +imagick = new Imagick(); + $this->imagick->newImage($pathOrWidth, $height < 1 ? $pathOrWidth : $height, 'none'); + $this->imagick->setImageFormat('png'); + } elseif(is_string($pathOrWidth)) { + $imagick = new Imagick($pathOrWidth); + $imagick->setImageFormat($imagick->getNumberImages() > 1 ? 'gif' : 'png'); + $this->imagick = $imagick->coalesceImages(); + } + + if(!isset($this->imagick)) + throw new InvalidArgumentException('Unsupported image format.'); + } + + public function __destruct() { + if(isset($this->imagick)) + $this->destroy(); + } + + public function getImagick(): Imagick { + return $this->imagick; + } + + public function getWidth(): int { + return $this->imagick->getImageWidth(); + } + + public function getHeight(): int { + return $this->imagick->getImageHeight(); + } + + public function hasFrames(): bool { + return $this->imagick->getNumberImages() > 1; + } + + public function next(): bool { + return $this->imagick->nextImage(); + } + + public function resize(int $width, int $height): bool { + return $this->imagick->resizeImage( + $width, $height, Imagick::FILTER_LANCZOS, 0.9 + ); + } + + public function crop(int $width, int $height, int $x, int $y): bool { + return $this->imagick->cropImage($width, $height, $x, $y); + } + + public function setPage(int $width, int $height, int $x, int $y): bool { + return $this->imagick->setImagePage($width, $height, $x, $y); + } + + public function save(string $path): bool { + return $this->imagick + ->deconstructImages() + ->writeImages($path, true); + } + + public function destroy(): void { + if($this->imagick->destroy()) + $this->imagick = null; + } +} diff --git a/src/Mailer.php b/src/Mailer.php new file mode 100644 index 0000000..366dde7 --- /dev/null +++ b/src/Mailer.php @@ -0,0 +1,111 @@ + $name) { + $to = new SymfonyAddress($email, $name); + break; + } + + $message = new SymfonyMessage; + + $message->from(new SymfonyAddress( + self::$senderAddr, + self::$senderName + )); + + if($bcc) + $message->bcc($to); + else + $message->to($to); + + $message->subject(trim($subject)); + $message->text(trim($contents)); + + try { + self::getTransport()->send($message); + return true; + } catch(TransportExceptionInterface $ex) { + if(MSZ_DEBUG) + throw $ex; + return false; + } + } + + public static function template(string $name, array $vars = []): array { + $path = sprintf(self::TEMPLATE_PATH, $name); + + if(!is_file($path)) + throw new InvalidArgumentException('Invalid e-mail template name.'); + + $tpl = file_get_contents($path); + + // Normalise newlines + $tpl = str_replace("\n", "\r\n", str_replace("\r\n", "\n", $tpl)); + + foreach($vars as $key => $val) + $tpl = str_replace("%{$key}%", $val, $tpl); + + [$subject, $message] = explode("\r\n\r\n", $tpl, 2); + + return compact('subject', 'message'); + } +} diff --git a/src/Memoizer.php b/src/Memoizer.php new file mode 100644 index 0000000..40f7af5 --- /dev/null +++ b/src/Memoizer.php @@ -0,0 +1,29 @@ +collection[$find])) + $this->collection[$find] = $create(); + return $this->collection[$find]; + } + + if(is_callable($find)) { + $item = array_find($this->collection, $find) ?? $create(); + if(method_exists($item, 'getId')) + $this->collection[$item->getId()] = $item; + else + $this->collection[] = $item; + return $item; + } + + throw new InvalidArgumentException('Wasn\'t able to figure out your $find argument.'); + } +} diff --git a/src/MszContext.php b/src/MszContext.php new file mode 100644 index 0000000..ff301ea --- /dev/null +++ b/src/MszContext.php @@ -0,0 +1,212 @@ +database = $database; + //$this->users = new Users($this->database); + } + + public function getRouter(): Router { + return $this->router->getRouter(); + } + + /*public function getUsers(): Users { + return $this->users; + }*/ + + public function setUpHttp(bool $legacy = false): void { + $this->router = new HttpFx; + $this->router->use('/', function($response) { + $response->setPoweredBy('Misuzu'); + }); + + $this->registerErrorPages(); + + if($legacy) + $this->registerLegacyRedirects(); + else + $this->registerHttpRoutes(); + } + + public function dispatchHttp(?HttpRequest $request = null): void { + $this->router->dispatch($request); + } + + private function registerErrorPages(): void { + $this->router->addErrorHandler(400, function($response) { + $response->setContent(Template::renderRaw('errors.400')); + }); + $this->router->addErrorHandler(403, function($response) { + $response->setContent(Template::renderRaw('errors.403')); + }); + $this->router->addErrorHandler(404, function($response) { + $response->setContent(Template::renderRaw('errors.404')); + }); + $this->router->addErrorHandler(500, function($response) { + $response->setContent(file_get_contents(MSZ_TEMPLATES . '/500.html')); + }); + $this->router->addErrorHandler(503, function($response) { + $response->setContent(file_get_contents(MSZ_TEMPLATES . '/503.html')); + }); + } + + private function registerHttpRoutes(): void { + function msz_compat_handler(string $className, string $method) { + return function(...$args) use ($className, $method) { + $className = "\\Misuzu\\Http\\Handlers\\{$className}Handler"; + return (new $className)->{$method}(...$args); + }; + } + + $this->router->get('/', msz_compat_handler('Home', 'index')); + + $this->router->get('/assets/:filename', msz_compat_handler('Assets', 'serveComponent')); + $this->router->get('/assets/avatar/:filename', msz_compat_handler('Assets', 'serveAvatar')); + $this->router->get('/assets/profile-background/:filename', msz_compat_handler('Assets', 'serveProfileBackground')); + + $this->router->get('/info', msz_compat_handler('Info', 'index')); + $this->router->get('/info/:name', msz_compat_handler('Info', 'page')); + $this->router->get('/info/:project/:name', msz_compat_handler('Info', 'page')); + + $this->router->get('/changelog', msz_compat_handler('Changelog', 'index')); + $this->router->get('/changelog.rss', msz_compat_handler('Changelog', 'feedRss')); + $this->router->get('/changelog.atom', msz_compat_handler('Changelog', 'feedAtom')); + $this->router->get('/changelog/change/:id', msz_compat_handler('Changelog', 'change')); + + $this->router->get('/news', msz_compat_handler('News', 'index')); + $this->router->get('/news.rss', msz_compat_handler('News', 'feedIndexRss')); + $this->router->get('/news.atom', msz_compat_handler('News', 'feedIndexAtom')); + $this->router->get('/news/:category', msz_compat_handler('News', 'viewCategory')); + $this->router->get('/news/post/:id', msz_compat_handler('News', 'viewPost')); + + $this->router->get('/forum/mark-as-read', msz_compat_handler('Forum', 'markAsReadGET')); + $this->router->post('/forum/mark-as-read', msz_compat_handler('Forum', 'markAsReadPOST')); + + new SharpChatRoutes($this); + } + + private function registerLegacyRedirects(): void { + $this->router->get('/index.php', function($response) { + $response->redirect(url('index'), true); + }); + + $this->router->get('/info.php', function($response) { + $response->redirect(url('info'), true); + }); + + $this->router->get('/settings.php', function($response) { + $response->redirect(url('settings-index'), true); + }); + + $this->router->get('/changelog.php', function($response, $request) { + $changeId = $request->getParam('c', FILTER_SANITIZE_NUMBER_INT); + if($changeId) { + $response->redirect(url('changelog-change', ['change' => $changeId]), true); + return; + } + + $response->redirect(url('changelog-index', [ + 'date' => $request->getParam('d'), + 'user' => $request->getParam('u', FILTER_SANITIZE_NUMBER_INT), + ]), true); + }); + + $infoRedirect = function($response, $request, string ...$parts) { + $response->redirect(url('info', ['title' => implode('/', $parts)]), true); + }; + $this->router->get('/info.php/:name', $infoRedirect); + $this->router->get('/info.php/:project/:name', $infoRedirect); + + $this->router->get('/auth.php', function($response, $request) { + $response->redirect(url([ + 'logout' => 'auth-logout', + 'reset' => 'auth-reset', + 'forgot' => 'auth-forgot', + 'register' => 'auth-register', + ][$request->getParam('m')] ?? 'auth-login'), true); + }); + + $this->router->get('/news.php', function($response, $request) { + $postId = $request->getParam('n', FILTER_SANITIZE_NUMBER_INT) ?? $request->getParam('p', FILTER_SANITIZE_NUMBER_INT); + + if($postId > 0) + $location = url('news-post', ['post' => $postId]); + else { + $catId = $request->getParam('c', FILTER_SANITIZE_NUMBER_INT); + $pageId = $request->getParam('page', FILTER_SANITIZE_NUMBER_INT); + $location = url($catId > 0 ? 'news-category' : 'news-index', ['category' => $catId, 'page' => $pageId]); + } + + $response->redirect($location, true); + }); + + $this->router->get('/news.php/rss', function($response, $request) { + $catId = $request->getParam('c', FILTER_SANITIZE_NUMBER_INT); + $location = url($catId > 0 ? 'news-category-feed-rss' : 'news-feed-rss', ['category' => $catId]); + $response->redirect($location, true); + }); + + $this->router->get('/news.php/atom', function($response, $request) { + $catId = $request->getParam('c', FILTER_SANITIZE_NUMBER_INT); + $location = url($catId > 0 ? 'news-category-feed-atom' : 'news-feed-atom', ['category' => $catId]); + $response->redirect($location, true); + }); + + $this->router->get('/news/index.php', function($response) { + $response->redirect(url('news-index', [ + 'page' => $request->getParam('page', FILTER_SANITIZE_NUMBER_INT), + ]), true); + }); + + $this->router->get('/news/category.php', function($response, $request) { + $response->redirect(url('news-category', [ + 'category' => $request->getParam('c', FILTER_SANITIZE_NUMBER_INT), + 'page' => $request->getParam('p', FILTER_SANITIZE_NUMBER_INT), + ]), true); + }); + + $this->router->get('/news/post.php', function($response, $request) { + $response->redirect(url('news-post', [ + 'post' => $request->getParam('p', FILTER_SANITIZE_NUMBER_INT), + ]), true); + }); + + $this->router->get('/news/feed.php', function() { + return 400; + }); + + $this->router->get('/news/feed.php/rss', function($response, $request) { + $response->redirect(url( + $catId > 0 ? 'news-category-feed-rss' : 'news-feed-rss', + ['category' => $request->getParam('c', FILTER_SANITIZE_NUMBER_INT)] + ), true); + }); + + $this->router->get('/news/feed.php/atom', function($response, $request) { + $response->redirect(url( + $catId > 0 ? 'news-category-feed-atom' : 'news-feed-atom', + ['category' => $request->getParam('c', FILTER_SANITIZE_NUMBER_INT)] + ), true); + }); + + $this->router->get('/user-assets.php', function($response, $request) { + return (new \Misuzu\Http\Handlers\AssetsHandler)->serveLegacy($response, $request); + }); + } +} diff --git a/src/Net/GeoIP.php b/src/Net/GeoIP.php new file mode 100644 index 0000000..8df751a --- /dev/null +++ b/src/Net/GeoIP.php @@ -0,0 +1,28 @@ +country($ipAddress); + } +} diff --git a/src/Net/IPAddress.php b/src/Net/IPAddress.php new file mode 100644 index 0000000..62d00f1 --- /dev/null +++ b/src/Net/IPAddress.php @@ -0,0 +1,112 @@ + 4, + self::VERSION_6 => 16, + ]; + + public const DEFAULT_V4 = '127.1'; + public const DEFAULT_V6 = '::1'; + + public static function remote(string $fallback = self::DEFAULT_V6): string { + return $_SERVER['REMOTE_ADDR'] ?? $fallback; + } + + public static function country(string $address, string $fallback = 'XX'): string { + if(!GeoIP::isAvailable()) + return $fallback; + + try { + return GeoIP::resolveCountry($address)->country->isoCode ?? $fallback; + } catch(AddressNotFoundException $e) { + return $fallback; + } + } + + public static function rawWidth(int $version): int { + return isset(self::SIZES[$version]) ? self::SIZES[$version] : 0; + } + + public static function detectStringVersion(string $address): int { + if(filter_var($address, FILTER_VALIDATE_IP) !== false) { + if(filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) + return self::VERSION_6; + + if(filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false) + return self::VERSION_4; + } + + return self::VERSION_UNKNOWN; + } + + public static function detectRawVersion(string $address): int { + $addressLength = strlen($address); + + foreach(self::SIZES as $version => $length) { + if($length === $addressLength) + return $version; + } + + return self::VERSION_UNKNOWN; + } + + public static function cidrToRaw(string $cidr): ?array { + if(strpos($cidr, '/') !== false) { + [$subnet, $mask] = explode('/', $cidr, 2); + } else { + $subnet = $cidr; + } + + try { + $subnet = inet_pton($subnet); + } catch(Exception $ex) { + return null; + } + + $mask = empty($mask) ? null : (int)$mask; + + return compact('subnet', 'mask'); + } + + public static function matchCidr(string $address, string $cidr): bool { + $address = inet_pton($address); + $cidr = self::cidrToRaw($cidr); + return self::matchCidrRaw($address, $cidr['subnet'], $cidr['mask']); + } + + public static function matchCidrRaw(string $address, string $subnet, ?int $mask = null): bool { + $version = self::detectRawVersion($subnet); + + if($version === self::VERSION_UNKNOWN) + return false; + + $bits = self::SIZES[$version] * 8; + + if(empty($mask)) + $mask = $bits; + + if($mask < 1 || $mask > $bits || $version !== self::detectRawVersion($subnet)) + return false; + + for($i = 0; $i < ceil($mask / 8); $i++) { + $byteMask = (0xFF00 >> max(0, min(8, $mask - ($i * 8)))) & 0xFF; + $addressByte = ord($address[$i]) & $byteMask; + $subnetByte = ord($subnet[$i]) & $byteMask; + + if($addressByte !== $subnetByte) + return false; + } + + return true; + } +} diff --git a/src/Net/IPAddressBlacklist.php b/src/Net/IPAddressBlacklist.php new file mode 100644 index 0000000..8ccd2b9 --- /dev/null +++ b/src/Net/IPAddressBlacklist.php @@ -0,0 +1,80 @@ + 0 + FROM `msz_ip_blacklist` + WHERE LENGTH(`ip_subnet`) = LENGTH(`target`) + AND `ip_subnet` & LPAD('', LENGTH(`ip_subnet`), X'FF') << LENGTH(`ip_subnet`) * 8 - `ip_mask` + = `target` & LPAD('', LENGTH(`ip_subnet`), X'FF') << LENGTH(`ip_subnet`) * 8 - `ip_mask` + ) + ")->bind('address', $address) + ->fetchColumn(1, false); + } + + public static function add(string $cidr): bool { + $raw = IPAddress::cidrToRaw($cidr); + + if(empty($raw)) + return false; + + return self::addRaw($raw['subnet'], $raw['mask']); + } + + public static function addRaw(string $subnet, ?int $mask = null): bool { + $version = IPAddress::detectRawVersion($subnet); + + if($version === IPAddress::VERSION_UNKNOWN) + return false; + + $bits = IPAddress::rawWidth($version) * 8; + + if(empty($mask)) { + $mask = $bits; + } elseif($mask < 1 || $mask > $bits) { + return false; + } + + return DB::prepare(' + REPLACE INTO `msz_ip_blacklist` (`ip_subnet`, `ip_mask`) + VALUES (:subnet, :mask) + ')->bind('subnet', $subnet) + ->bind('mask', $mask) + ->execute(); + } + + public static function remove(string $cidr): bool { + $raw = IPAddress::cidrToRaw($cidr); + + if(empty($raw)) + return false; + + return self::removeRaw($raw['subnet'], $raw['mask']); + } + + public static function removeRaw(string $subnet, ?int $mask = null): bool { + return DB::prepare(' + DELETE FROM `msz_ip_blacklist` + WHERE `ip_subnet` = :subnet + AND `ip_mask` = :mask + ')->bind('subnet', $subnet) + ->bind('mask', $mask) + ->execute(); + } + + public static function list(): array { + return DB::query(" + SELECT + INET6_NTOA(`ip_subnet`) AS `ip_subnet`, + `ip_mask`, + LENGTH(`ip_subnet`) AS `ip_bytes`, + CONCAT(INET6_NTOA(`ip_subnet`), '/', `ip_mask`) as `ip_cidr` + FROM `msz_ip_blacklist` + ")->fetchAll(); + } +} diff --git a/src/Net/socket.php b/src/Net/socket.php new file mode 100644 index 0000000..ac4a467 --- /dev/null +++ b/src/Net/socket.php @@ -0,0 +1,2 @@ +category_id < 1 ? -1 : $this->category_id; + } + + public function getName(): string { + return $this->category_name ?? ''; + } + public function setName(string $name): self { + $this->category_name = $name; + return $this; + } + + public function getDescription(): string { + return $this->category_description ?? ''; + } + public function setDescription(string $description): self { + $this->category_description = $description; + return $this; + } + + public function isHidden(): bool { + return $this->category_is_hidden !== 0; + } + public function setHidden(bool $hide): self { + $this->category_is_hidden = $hide ? 1 : 0; + return $this; + } + + public function getCreatedTime(): int { + return $this->category_created === null ? -1 : $this->category_created; + } + + public function jsonSerialize(): mixed { + return [ + 'id' => $this->getId(), + 'name' => $this->getName(), + 'description' => $this->getDescription(), + 'is_hidden' => $this->isHidden(), + 'created' => ($time = $this->getCreatedTime()) < 0 ? null : date('c', $time), + ]; + } + + // Purely cosmetic, use ::countAll for pagination + public function getPostCount(): int { + if($this->postCount < 0) + $this->postCount = (int)DB::prepare(' + SELECT COUNT(`post_id`) + FROM `msz_news_posts` + WHERE `category_id` = :cat_id + AND `post_scheduled` <= NOW() + AND `post_deleted` IS NULL + ')->bind('cat_id', $this->getId())->fetchColumn(); + + return $this->postCount; + } + + public function save(): void { + $isInsert = $this->getId() < 1; + if($isInsert) { + $query = 'INSERT INTO `%1$s%2$s` (`category_name`, `category_description`, `category_is_hidden`) VALUES' + . ' (:name, :description, :hidden)'; + } else { + $query = 'UPDATE `%1$s%2$s` SET `category_name` = :name, `category_description` = :description, `category_is_hidden` = :hidden' + . ' WHERE `category_id` = :category'; + } + + $savePost = DB::prepare(sprintf($query, DB::PREFIX, self::TABLE)) + ->bind('name', $this->category_name) + ->bind('description', $this->category_description) + ->bind('hidden', $this->category_is_hidden); + + if($isInsert) { + $this->category_id = $savePost->executeGetId(); + $this->category_created = time(); + } else { + $savePost->bind('category', $this->getId()) + ->execute(); + } + } + + public function posts(?Pagination $pagination = null, bool $includeScheduled = false, bool $includeDeleted = false): array { + return NewsPost::byCategory($this, $pagination, $includeScheduled, $includeDeleted); + } + + private static function countQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf('COUNT(%s.`category_id`)', self::TABLE)); + } + public static function countAll(bool $showHidden = false): int { + return (int)DB::prepare(self::countQueryBase() + . ($showHidden ? '' : ' WHERE `category_is_hidden` = 0')) + ->fetchColumn(); + } + + private static function byQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf(self::SELECT, self::TABLE)); + } + public static function byId(int $categoryId): self { + $getCat = DB::prepare(self::byQueryBase() . ' WHERE `category_id` = :cat_id'); + $getCat->bind('cat_id', $categoryId); + $cat = $getCat->fetchObject(self::class); + if(!$cat) + throw new NewsCategoryNotFoundException; + return $cat; + } + public static function all(?Pagination $pagination = null, bool $showHidden = false): array { + $catsQuery = self::byQueryBase() + . ($showHidden ? '' : ' WHERE `category_is_hidden` = 0') + . ' ORDER BY `category_id` ASC'; + + if($pagination !== null) + $catsQuery .= ' LIMIT :range OFFSET :offset'; + + $getCats = DB::prepare($catsQuery); + + if($pagination !== null) + $getCats->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getCats->fetchObjects(self::class); + } + + // Twig shim for the news category list in manage, don't use this class as an array normally. + public function offsetExists($offset): bool { + return $offset === 'name' || $offset === 'id'; + } + public function offsetGet($offset): mixed { + return $this->{'get' . ucfirst($offset)}(); + } + public function offsetSet($offset, $value): void {} + public function offsetUnset($offset): void {} +} diff --git a/src/News/NewsException.php b/src/News/NewsException.php new file mode 100644 index 0000000..faccdd3 --- /dev/null +++ b/src/News/NewsException.php @@ -0,0 +1,6 @@ +post_id < 1 ? -1 : $this->post_id; + } + + public function getCategoryId(): int { + return $this->category_id < 1 ? -1 : $this->category_id; + } + public function setCategoryId(int $categoryId): self { + $this->category_id = max(1, $categoryId); + $this->category = null; + return $this; + } + public function getCategory(): NewsCategory { + if($this->category === null) + $this->category = NewsCategory::byId($this->getCategoryId()); + return $this->category; + } + public function setCategory(NewsCategory $category): self { + $this->category_id = $category->getId(); + $this->category = $category; + return $this; + } + + public function getUserId(): int { + return $this->user_id < 1 ? -1 : $this->user_id; + } + public function setUserId(int $userId): self { + $this->user_id = $userId < 1 ? null : $userId; + $this->userLookedUp = false; + $this->user = null; + return $this; + } + public function getUser(): ?User { + if(!$this->userLookedUp && ($userId = $this->getUserId()) > 0) { + $this->userLookedUp = true; + try { + $this->user = User::byId($userId); + } catch(UserNotFoundException $ex) {} + } + return $this->user; + } + public function setUser(?User $user): self { + $this->user_id = $user === null ? null : $user->getId(); + $this->userLookedUp = true; + $this->user = $user; + return $this; + } + + public function getCommentsCategoryId(): int { + return $this->comment_section_id < 1 ? -1 : $this->comment_section_id; + } + public function hasCommentsCategory(): bool { + return $this->getCommentsCategoryId() > 0; + } + public function getCommentsCategory(): CommentsCategory { + if($this->comments === null) + $this->comments = CommentsCategory::byId($this->getCommentsCategoryId()); + return $this->comments; + } + + public function isFeatured(): bool { + return $this->post_is_featured !== 0; + } + public function setFeatured(bool $featured): self { + $this->post_is_featured = $featured ? 1 : 0; + return $this; + } + + public function getTitle(): string { + return $this->post_title; + } + public function setTitle(string $title): self { + $this->post_title = $title; + return $this; + } + + public function getText(): string { + return $this->post_text; + } + public function setText(string $text): self { + $this->post_text = $text; + return $this; + } + public function getParsedText(): string { + return Parser::instance(Parser::MARKDOWN)->parseText($this->getText()); + } + public function getFirstParagraph(): string { + return first_paragraph($this->getText()); + } + public function getParsedFirstParagraph(): string { + return Parser::instance(Parser::MARKDOWN)->parseText($this->getFirstParagraph()); + } + + public function getScheduledTime(): int { + return $this->post_scheduled === null ? -1 : $this->post_scheduled; + } + public function setScheduledTime(int $scheduled): self { + $time = ($time = $this->getCreatedTime()) < 0 ? time() : $time; + $this->post_scheduled = $scheduled < $time ? $time : $scheduled; + return $this; + } + public function isPublished(): bool { + return $this->getScheduledTime() < time(); + } + + public function getCreatedTime(): int { + return $this->post_created === null ? -1 : $this->post_created; + } + + public function getUpdatedTime(): int { + return $this->post_updated === null ? -1 : $this->post_updated; + } + public function isEdited(): bool { + return $this->getUpdatedTime() >= 0; + } + + public function getDeletedTime(): int { + return $this->post_deleted === null ? -1 : $this->post_deleted; + } + public function isDeleted(): bool { + return $this->getDeletedTime() >= 0; + } + public function setDeleted(bool $isDeleted): self { + if($this->isDeleted() !== $isDeleted) + $this->post_deleted = $isDeleted ? time() : null; + return $this; + } + + public function jsonSerialize(): mixed { + return [ + 'id' => $this->getId(), + 'category' => $this->getCategoryId(), + 'user' => $this->getUserId(), + 'comments' => $this->getCommentsCategoryId(), + 'is_featured' => $this->isFeatured(), + 'title' => $this->getTitle(), + 'text' => $this->getText(), + 'scheduled' => ($time = $this->getScheduledTime()) < 0 ? null : date('c', $time), + 'created' => ($time = $this->getCreatedTime()) < 0 ? null : date('c', $time), + 'updated' => ($time = $this->getUpdatedTime()) < 0 ? null : date('c', $time), + 'deleted' => ($time = $this->getDeletedTime()) < 0 ? null : date('c', $time), + ]; + } + + public function ensureCommentsCategory(): void { + if($this->hasCommentsCategory()) + return; + + $this->comments = new CommentsCategory("news-{$this->getId()}"); + $this->comments->save(); + + $this->comment_section_id = $this->comments->getId(); + DB::prepare('UPDATE `msz_news_posts` SET `comment_section_id` = :comment_section_id WHERE `post_id` = :post_id') + ->execute([ + 'comment_section_id' => $this->getCommentsCategoryId(), + 'post_id' => $this->getId(), + ]); + } + + public function save(): void { + $isInsert = $this->getId() < 1; + if($isInsert) { + $query = 'INSERT INTO `%1$s%2$s` (`category_id`, `user_id`, `post_is_featured`, `post_title`' + . ', `post_text`, `post_scheduled`, `post_deleted`) VALUES' + . ' (:category, :user, :featured, :title, :text, FROM_UNIXTIME(:scheduled), FROM_UNIXTIME(:deleted))'; + } else { + $query = 'UPDATE `%1$s%2$s` SET `category_id` = :category, `user_id` = :user, `post_is_featured` = :featured' + . ', `post_title` = :title, `post_text` = :text, `post_scheduled` = FROM_UNIXTIME(:scheduled)' + . ', `post_deleted` = FROM_UNIXTIME(:deleted)' + . ' WHERE `post_id` = :post'; + } + + $savePost = DB::prepare(sprintf($query, DB::PREFIX, self::TABLE)) + ->bind('category', $this->category_id) + ->bind('user', $this->user_id) + ->bind('featured', $this->post_is_featured) + ->bind('title', $this->post_title) + ->bind('text', $this->post_text) + ->bind('scheduled', $this->post_scheduled) + ->bind('deleted', $this->post_deleted); + + if($isInsert) { + $this->post_id = $savePost->executeGetId(); + $this->post_created = time(); + } else { + $this->post_updated = time(); + $savePost->bind('post', $this->getId()) + ->execute(); + } + } + + private static function countQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf('COUNT(%s.`post_id`)', self::TABLE)); + } + public static function countAll(bool $onlyFeatured = false, bool $includeScheduled = false, bool $includeDeleted = false): int { + return (int)DB::prepare(self::countQueryBase() + . ' WHERE IF(:only_featured, `post_is_featured` <> 0, 1)' + . ($includeScheduled ? '' : ' AND `post_scheduled` < NOW()') + . ($includeDeleted ? '' : ' AND `post_deleted` IS NULL')) + ->bind('only_featured', $onlyFeatured ? 1 : 0) + ->fetchColumn(); + } + public static function countByCategory(NewsCategory $category, bool $includeScheduled = false, bool $includeDeleted = false): int { + return (int)DB::prepare(self::countQueryBase() + . ' WHERE `category_id` = :cat_id' + . ($includeScheduled ? '' : ' AND `post_scheduled` < NOW()') + . ($includeDeleted ? '' : ' AND `post_deleted` IS NULL')) + ->bind('cat_id', $category->getId()) + ->fetchColumn(); + } + + private static function byQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf(self::SELECT, self::TABLE)); + } + public static function byId(int $postId): self { + $post = DB::prepare(self::byQueryBase() . ' WHERE `post_id` = :post_id') + ->bind('post_id', $postId) + ->fetchObject(self::class); + if(!$post) + throw new NewsPostNotFoundException; + return $post; + } + public static function bySearchQuery(string $query, bool $includeScheduled = false, bool $includeDeleted = false): array { + return DB::prepare( + self::byQueryBase() + . ' WHERE MATCH(`post_title`, `post_text`) AGAINST (:query IN NATURAL LANGUAGE MODE)' + . ($includeScheduled ? '' : ' AND `post_scheduled` < NOW()') + . ($includeDeleted ? '' : ' AND `post_deleted` IS NULL') + . ' ORDER BY `post_id` DESC' + ) ->bind('query', $query) + ->fetchObjects(self::class); + } + public static function byCategory(NewsCategory $category, ?Pagination $pagination = null, bool $includeScheduled = false, bool $includeDeleted = false): array { + $postsQuery = self::byQueryBase() + . ' WHERE `category_id` = :cat_id' + . ($includeScheduled ? '' : ' AND `post_scheduled` < NOW()') + . ($includeDeleted ? '' : ' AND `post_deleted` IS NULL') + . ' ORDER BY `post_id` DESC'; + + if($pagination !== null) + $postsQuery .= ' LIMIT :range OFFSET :offset'; + + $getPosts = DB::prepare($postsQuery) + ->bind('cat_id', $category->getId()); + + if($pagination !== null) + $getPosts->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getPosts->fetchObjects(self::class); + } + public static function all(?Pagination $pagination = null, bool $onlyFeatured = false, bool $includeScheduled = false, bool $includeDeleted = false): array { + $postsQuery = self::byQueryBase() + . ' WHERE IF(:only_featured, `post_is_featured` <> 0, 1)' + . ($includeScheduled ? '' : ' AND `post_scheduled` < NOW()') + . ($includeDeleted ? '' : ' AND `post_deleted` IS NULL') + . ' ORDER BY `post_id` DESC'; + + if($pagination !== null) + $postsQuery .= ' LIMIT :range OFFSET :offset'; + + $getPosts = DB::prepare($postsQuery) + ->bind('only_featured', $onlyFeatured ? 1 : 0); + + if($pagination !== null) + $getPosts->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getPosts->fetchObjects(self::class); + } +} diff --git a/src/Pagination.php b/src/Pagination.php new file mode 100644 index 0000000..7f77a15 --- /dev/null +++ b/src/Pagination.php @@ -0,0 +1,77 @@ +count = max(0, $count); + $this->range = $range < 0 ? $count : $range; + + if(!empty($readParam)) + $this->readPage($readParam); + } + + public function getCount(): int { + return $this->count; + } + + public function getRange(): int { + return $this->range; + } + + public function getPages(): int { + return (int)ceil($this->getCount() / $this->getRange()); + } + + public function hasValidOffset(): bool { + return $this->offset !== self::INVALID_OFFSET; + } + + public function getOffset(): int { + return $this->hasValidOffset() ? $this->offset : 0; + } + + public function setOffset(int $offset): self { + if($offset < 0) + $offset = self::INVALID_OFFSET; + + $this->offset = $offset; + return $this; + } + + public function getPage(): int { + if($this->getOffset() < 1) + return self::START_PAGE; + + return (int)floor($this->getOffset() / $this->getRange()) + self::START_PAGE; + } + + public function setPage(int $page, bool $zeroBased = false): self { + if(!$zeroBased) + $page -= self::START_PAGE; + + $this->setOffset($this->getRange() * $page); + return $this; + } + + public function readPage(string $name = self::DEFAULT_PARAM, int $default = self::START_PAGE, ?array $source = null): self { + $this->setPage(self::param($name, $default, $source)); + return $this; + } + + public static function param(string $name = self::DEFAULT_PARAM, int $default = self::START_PAGE, ?array $source = null): int { + $source ??= $_GET; + + if(isset($source[$name]) && is_string($source[$name]) && ctype_digit($source[$name])) + return intval($source[$name]); + + return $default; + } +} diff --git a/src/Parsers/BBCode/BBCodeParser.php b/src/Parsers/BBCode/BBCodeParser.php new file mode 100644 index 0000000..c244444 --- /dev/null +++ b/src/Parsers/BBCode/BBCodeParser.php @@ -0,0 +1,51 @@ +tags = $tags; + } + + public function parseText(string $text): string { + foreach($this->tags as $tag) + $text = $tag->parseText($text); + return $text; + } + + public function parseLine(string $line): string { + return $this->parseText($line); + } +} diff --git a/src/Parsers/BBCode/BBCodeSimpleTag.php b/src/Parsers/BBCode/BBCodeSimpleTag.php new file mode 100644 index 0000000..021b579 --- /dev/null +++ b/src/Parsers/BBCode/BBCodeSimpleTag.php @@ -0,0 +1,11 @@ +getPattern(), $this->getReplacement(), $text); + } +} diff --git a/src/Parsers/BBCode/BBCodeTag.php b/src/Parsers/BBCode/BBCodeTag.php new file mode 100644 index 0000000..e1b9dd2 --- /dev/null +++ b/src/Parsers/BBCode/BBCodeTag.php @@ -0,0 +1,6 @@ +%s', $matches[1], $matches[2]); + }, + $text + ); + } +} diff --git a/src/Parsers/BBCode/Tags/AudioTag.php b/src/Parsers/BBCode/Tags/AudioTag.php new file mode 100644 index 0000000..771509f --- /dev/null +++ b/src/Parsers/BBCode/Tags/AudioTag.php @@ -0,0 +1,25 @@ +"; + }, + $text + ); + } +} diff --git a/src/Parsers/BBCode/Tags/BoldTag.php b/src/Parsers/BBCode/Tags/BoldTag.php new file mode 100644 index 0000000..328ed0f --- /dev/null +++ b/src/Parsers/BBCode/Tags/BoldTag.php @@ -0,0 +1,14 @@ +$1'; + } +} diff --git a/src/Parsers/BBCode/Tags/CodeTag.php b/src/Parsers/BBCode/Tags/CodeTag.php new file mode 100644 index 0000000..fc5e56b --- /dev/null +++ b/src/Parsers/BBCode/Tags/CodeTag.php @@ -0,0 +1,18 @@ +'], ['[', ']', '<', '>'], $matches[2]); + return "
{$text}
"; + }, + $text + ); + } +} diff --git a/src/Parsers/BBCode/Tags/ImageTag.php b/src/Parsers/BBCode/Tags/ImageTag.php new file mode 100644 index 0000000..f164053 --- /dev/null +++ b/src/Parsers/BBCode/Tags/ImageTag.php @@ -0,0 +1,13 @@ +', $mediaUrl, $matches[1]); + }, $text); + } +} diff --git a/src/Parsers/BBCode/Tags/ItalicsTag.php b/src/Parsers/BBCode/Tags/ItalicsTag.php new file mode 100644 index 0000000..d140e64 --- /dev/null +++ b/src/Parsers/BBCode/Tags/ItalicsTag.php @@ -0,0 +1,14 @@ +$1'; + } +} diff --git a/src/Parsers/BBCode/Tags/LinkifyTag.php b/src/Parsers/BBCode/Tags/LinkifyTag.php new file mode 100644 index 0000000..124cf4f --- /dev/null +++ b/src/Parsers/BBCode/Tags/LinkifyTag.php @@ -0,0 +1,23 @@ +%1$s', $matches[0]); + }, + $text + ); + } +} diff --git a/src/Parsers/BBCode/Tags/NamedUrlTag.php b/src/Parsers/BBCode/Tags/NamedUrlTag.php new file mode 100644 index 0000000..7bb66cd --- /dev/null +++ b/src/Parsers/BBCode/Tags/NamedUrlTag.php @@ -0,0 +1,14 @@ +$2'; + } +} diff --git a/src/Parsers/BBCode/Tags/NewLineTag.php b/src/Parsers/BBCode/Tags/NewLineTag.php new file mode 100644 index 0000000..51811f3 --- /dev/null +++ b/src/Parsers/BBCode/Tags/NewLineTag.php @@ -0,0 +1,14 @@ +'; + } +} diff --git a/src/Parsers/BBCode/Tags/QuoteTag.php b/src/Parsers/BBCode/Tags/QuoteTag.php new file mode 100644 index 0000000..d18408c --- /dev/null +++ b/src/Parsers/BBCode/Tags/QuoteTag.php @@ -0,0 +1,22 @@ +{$matches[1]}:"; + } + + return "
{$prefix}{$matches[2]}
"; + }, + $text + ); + } +} diff --git a/src/Parsers/BBCode/Tags/StrikeTag.php b/src/Parsers/BBCode/Tags/StrikeTag.php new file mode 100644 index 0000000..d5036d3 --- /dev/null +++ b/src/Parsers/BBCode/Tags/StrikeTag.php @@ -0,0 +1,14 @@ +$1'; + } +} diff --git a/src/Parsers/BBCode/Tags/UnderlineTag.php b/src/Parsers/BBCode/Tags/UnderlineTag.php new file mode 100644 index 0000000..f50826f --- /dev/null +++ b/src/Parsers/BBCode/Tags/UnderlineTag.php @@ -0,0 +1,14 @@ +$1'; + } +} diff --git a/src/Parsers/BBCode/Tags/UrlTag.php b/src/Parsers/BBCode/Tags/UrlTag.php new file mode 100644 index 0000000..b5a1e5e --- /dev/null +++ b/src/Parsers/BBCode/Tags/UrlTag.php @@ -0,0 +1,14 @@ +$1'; + } +} diff --git a/src/Parsers/BBCode/Tags/VideoTag.php b/src/Parsers/BBCode/Tags/VideoTag.php new file mode 100644 index 0000000..93ce891 --- /dev/null +++ b/src/Parsers/BBCode/Tags/VideoTag.php @@ -0,0 +1,52 @@ +'; + + private const NICODOUGA_EMBED = ''; + + public function parseText(string $text): string { + return preg_replace_callback( + '#\[video\]((?:https?:\/\/).+?)\[/video\]#', + function ($matches) { + $url = parse_url($matches[1]); + + if(empty($url['scheme']) || !in_array(mb_strtolower($url['scheme']), ['http', 'https'], true)) { + return $matches[0]; + } + + $url['host'] = mb_strtolower($url['host']); + + // support youtube playlists? + + if($url['host'] === 'youtu.be' || $url['host'] === 'www.youtu.be') { + return sprintf(self::YOUTUBE_EMBED, $url['path']); + } + + if(!empty($url['query']) && ($url['path'] ?? '') === '/watch' && preg_match(self::YOUTUBE_REGEX, $url['host'])) { + parse_str(html_entity_decode($url['query']), $ytQuery); + + if(!empty($ytQuery['v']) && preg_match('#^([a-zA-Z0-9_-]+)$#u', $ytQuery['v'])) { + return sprintf(self::YOUTUBE_EMBED, $ytQuery['v']); + } + } + + if($url['host'] === 'nicovideo.jp' || $url['host'] === 'www.nicovideo.jp') { + $splitPath = explode('/', trim($url['path'], '/')); + + if(count($splitPath) > 1 && $splitPath[0] === 'watch') { + return sprintf(self::NICODOUGA_EMBED, $splitPath[1]); + } + } + + $mediaUrl = url_proxy_media($matches[1]); + return sprintf('', $mediaUrl); + }, + $text + ); + } +} diff --git a/src/Parsers/BBCode/Tags/ZalgoTag.php b/src/Parsers/BBCode/Tags/ZalgoTag.php new file mode 100644 index 0000000..e0af7e3 --- /dev/null +++ b/src/Parsers/BBCode/Tags/ZalgoTag.php @@ -0,0 +1,17 @@ +text($text); + } + + public function parseLine(string $line): string { + return $this->line($line); + } + + protected function inlineImage($excerpt) { + $object = parent::inlineImage($excerpt); + + if(!empty($object['element']['attributes']['src']) && !is_local_url($object['element']['attributes']['src'])) { + $object['element']['attributes']['src'] = url_proxy_media($object['element']['attributes']['src']); + } + + return $object; + } +} diff --git a/src/Parsers/Parser.php b/src/Parsers/Parser.php new file mode 100644 index 0000000..f49cffb --- /dev/null +++ b/src/Parsers/Parser.php @@ -0,0 +1,44 @@ + PlainParser::class, + self::BBCODE => BBCodeParser::class, + self::MARKDOWN => MarkdownParser::class, + ]; + public const NAMES = [ + self::PLAIN => 'Plain text', + self::BBCODE => 'BB Code', + self::MARKDOWN => 'Markdown', + ]; + + private static $instances = []; + + public static function isValid(int $parser): bool { + return array_key_exists($parser, self::PARSERS); + } + + public static function name(int $parser): string { + return self::isValid($parser) ? self::NAMES[$parser] : ''; + } + + public static function instance(int $parser): ParserInterface { + if(!self::isValid($parser)) + throw new InvalidArgumentException('Invalid parser.'); + + if(!isset(self::$instances[$parser])) { + $className = self::PARSERS[$parser]; + self::$instances[$parser] = new $className; + } + + return self::$instances[$parser]; + } +} diff --git a/src/Parsers/ParserInterface.php b/src/Parsers/ParserInterface.php new file mode 100644 index 0000000..2e315de --- /dev/null +++ b/src/Parsers/ParserInterface.php @@ -0,0 +1,7 @@ +getId(), MSZ_PERM_USER_MANAGE_USERS)) + $perms |= self::PERMS_MANAGE_USERS; + if(perms_check_user(MSZ_PERMS_USER, $userInfo->getId(), MSZ_PERM_USER_MANAGE_WARNINGS)) + $perms |= self::PERMS_MANAGE_WARNS; + if(perms_check_user(MSZ_PERMS_USER, $userInfo->getId(), MSZ_PERM_USER_CHANGE_BACKGROUND)) + $perms |= self::PERMS_CHANGE_BACKG; + if(perms_check_user(MSZ_PERMS_FORUM, $userInfo->getId(), MSZ_PERM_FORUM_MANAGE_FORUMS)) + $perms |= self::PERMS_MANAGE_FORUM; + + return $perms; + } +} diff --git a/src/SharpChat/SharpChatRoutes.php b/src/SharpChat/SharpChatRoutes.php new file mode 100644 index 0000000..e10850b --- /dev/null +++ b/src/SharpChat/SharpChatRoutes.php @@ -0,0 +1,389 @@ +hashKey = file_get_contents($hashKeyPath); + } else { + $this->hashKey = $hashKey; + } + + $router = $ctx->getRouter(); + + // Public endpoints + $router->get('/_sockchat/emotes', [$this, 'emotes']); + $router->get('/_sockchat/login', [$this, 'login']); + $router->options('/_sockchat/token', [$this, 'token']); + $router->get('/_sockchat/token', [$this, 'token']); + + // Private endpoints + $router->get('/_sockchat/resolve', [$this, 'resolve']); + $router->post('/_sockchat/bump', [$this, 'bump']); + $router->post('/_sockchat/verify', [$this, 'verify']); + $router->get('/_sockchat/bans', [$this, 'bans']); + $router->get('/_sockchat/bans/check', [$this, 'checkBan']); + $router->post('/_sockchat/bans/create', [$this, 'createBan']); + $router->delete('/_sockchat/bans/remove', [$this, 'removeBan']); + } + + public static function emotes($response, $request): array { + $response->setHeader('Access-Control-Allow-Origin', '*'); + $response->setHeader('Access-Control-Allow-Methods', 'GET'); + + $raw = Emoticon::all(); + $out = []; + + foreach($raw as $emote) { + $strings = []; + + foreach($emote->getStrings() as $string) + $strings[] = sprintf(':%s:', $string->emote_string); + + $out[] = [ + 'Text' => $strings, + 'Image' => $emote->getUrl(), + 'Hierarchy' => $emote->getRank(), + ]; + } + + return $out; + } + + public static function login($response, $request): void { + $currentUser = User::getCurrent(); + $configKey = $request->hasParam('legacy') ? 'sockChat.chatPath.legacy' : 'sockChat.chatPath.normal'; + $chatPath = Config::get($configKey, Config::TYPE_STR, '/'); + + $response->redirect( + $currentUser === null + ? url('auth-login') + : $chatPath + ); + } + + public function token($response, $request) { + $host = $request->hasHeader('Host') ? $request->getHeaderFirstLine('Host') : ''; + $origin = $request->hasHeader('Origin') ? $request->getHeaderFirstLine('Origin') : ''; + $originHost = strtolower(parse_url($origin, PHP_URL_HOST) ?? ''); + + if(!empty($originHost) && $originHost !== $host) { + $whitelist = Config::get('sockChat.origins', Config::TYPE_ARR, []); + + if(!in_array($originHost, $whitelist)) + return 403; + + $originProto = strtolower(parse_url($origin, PHP_URL_SCHEME)); + $origin = $originProto . '://' . $originHost; + + $response->setHeader('Access-Control-Allow-Origin', $origin); + $response->setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET'); + $response->setHeader('Access-Control-Allow-Credentials', 'true'); + $response->setHeader('Vary', 'Origin'); + } + + if($request->getMethod() === 'OPTIONS') + return 204; + + if(!UserSession::hasCurrent()) + return ['ok' => false]; + + $session = UserSession::getCurrent(); + $user = $session->getUser(); + $token = AuthToken::create($user, $session); + + return [ + 'ok' => true, + 'usr' => $user->getId(), + 'tkn' => $token->pack(), + ]; + } + + public function resolve($response, $request): array { + $userHash = $request->hasHeader('X-SharpChat-Signature') + ? $request->getHeaderFirstLine('X-SharpChat-Signature') : ''; + $method = (string)$request->getParam('m'); + $param = (string)$request->getParam('p'); + $realHash = hash_hmac('sha256', "resolve#{$method}#{$param}", $this->hashKey); + + if(!hash_equals($realHash, $userHash)) + return []; + + try { + switch($method) { + case 'id': + $userInfo = User::byId((int)$param); + break; + + case 'name': + $userInfo = User::byUsername($param); + break; + } + } catch(UserNotFoundException $ex) {} + + if(!isset($userInfo)) + return []; + + return [ + 'user_id' => $userInfo->getId(), + 'username' => $userInfo->getUsername(), + 'colour_raw' => $userInfo->getColour()->getRaw(), + 'rank' => $rank = $userInfo->getRank(), + 'perms' => SharpChatPerms::convert($userInfo), + ]; + } + + public function bump($response, $request) { + if(!$request->isStringContent()) + return 400; + + $userHash = $request->hasHeader('X-SharpChat-Signature') + ? $request->getHeaderFirstLine('X-SharpChat-Signature') : ''; + $bumpString = (string)$request->getContent(); + $realHash = hash_hmac('sha256', $bumpString, $this->hashKey); + + if(!hash_equals($realHash, $userHash)) + return; + + $bumpInfo = json_decode($bumpString); + + if(empty($bumpInfo)) + return; + + foreach($bumpInfo as $bumpUser) + try { + User::byId($bumpUser->id)->bumpActivity($bumpUser->ip); + } catch(UserNotFoundException $ex) {} + } + + public function verify($response, $request): array { + if($request->isStreamContent()) + $authInfo = json_decode((string)$request->getContent()); + elseif($request->isJsonContent()) + $authInfo = $request->getContent()->getContent(); // maybe change this api lol, this looks silly + else + return ['success' => false, 'reason' => 'request']; + + $userHash = $request->hasHeader('X-SharpChat-Signature') + ? $request->getHeaderFirstLine('X-SharpChat-Signature') : ''; + + if(strlen($userHash) !== 64) + return ['success' => false, 'reason' => 'length']; + + if(!isset($authInfo->user_id, $authInfo->token, $authInfo->ip)) + return ['success' => false, 'reason' => 'data']; + + $realHash = hash_hmac('sha256', implode('#', [$authInfo->user_id, $authInfo->token, $authInfo->ip]), $this->hashKey); + + if(!hash_equals($realHash, $userHash)) + return ['success' => false, 'reason' => 'hash']; + + try { + $userInfo = User::byId($authInfo->user_id); + } catch(UserNotFoundException $ex) { + return ['success' => false, 'reason' => 'user']; + } + + $authMethod = mb_substr($authInfo->token, 0, 5); + + if($authMethod === 'SESS:') { + $sessionToken = mb_substr($authInfo->token, 5); + + $authToken = AuthToken::unpack($sessionToken); + if($authToken->isValid()) + $sessionToken = $authToken->getSessionToken(); + + try { + $sessionInfo = UserSession::byToken($sessionToken); + } catch(UserSessionNotFoundException $ex) { + return ['success' => false, 'reason' => 'token']; + } + + if($sessionInfo->getUserId() !== $userInfo->getId()) + return ['success' => false, 'reason' => 'user']; + + if($sessionInfo->hasExpired()) { + $sessionInfo->delete(); + return ['success' => false, 'reason' => 'expired']; + } + + $sessionInfo->bump(); + } else { + return ['success' => false, 'reason' => 'unsupported']; + } + + $userInfo->bumpActivity($authInfo->ip); + + return [ + 'success' => true, + 'user_id' => $userInfo->getId(), + 'username' => $userInfo->getUsername(), + 'colour_raw' => $userInfo->getColour()->getRaw(), + 'rank' => $rank = $userInfo->getRank(), + 'hierarchy' => $rank, + 'is_silenced' => date('c', $userInfo->isSilenced() || $userInfo->isBanned() ? ($userInfo->isActiveWarningPermanent() ? strtotime('10 years') : $userInfo->getActiveWarningExpiration()) : 0), + 'perms' => SharpChatPerms::convert($userInfo), + ]; + } + + public function bans($response, $request): array { + $userHash = $request->hasHeader('X-SharpChat-Signature') + ? $request->getHeaderFirstLine('X-SharpChat-Signature') : ''; + $realHash = hash_hmac('sha256', 'givemethebeans', $this->hashKey); + + if(!hash_equals($realHash, $userHash)) + return []; + + $warnings = UserWarning::byActive(); + $bans = []; + + foreach($warnings as $warning) { + if(!$warning->isBan() || $warning->hasExpired()) + continue; + + $isPermanent = $warning->isPermanent(); + $userInfo = $warning->getUser(); + $bans[] = [ + 'user_id' => $userInfo->getId(), + 'id' => $userInfo->getId(), + 'username' => $userInfo->getUsername(), + 'colour_raw' => $userInfo->getColour()->getRaw(), + 'rank' => $rank = $userInfo->getRank(), + 'ip' => $warning->getUserRemoteAddress(), + 'is_permanent' => $isPermanent, + 'expires' => date('c', $isPermanent ? 0x7FFFFFFF : $warning->getExpirationTime()), + 'perms' => SharpChatPerms::convert($userInfo), + ]; + } + + return $bans; + } + + public function checkBan($response, $request): array { + $userHash = $request->hasHeader('X-SharpChat-Signature') + ? $request->getHeaderFirstLine('X-SharpChat-Signature') : ''; + $ipAddress = (string)$request->getParam('a'); + $userId = (int)$request->getParam('u', FILTER_SANITIZE_NUMBER_INT); + + $realHash = hash_hmac('sha256', "check#{$ipAddress}#{$userId}", $this->hashKey); + if(!hash_equals($realHash, $userHash)) + return []; + + $response = []; + $warning = UserWarning::byRemoteAddressActive($ipAddress) + ?? UserWarning::byUserIdActive($userId); + + if($warning !== null) { + $response['warning'] = $warning->getId(); + $response['id'] = $warning->getUserId(); + $response['user_id'] = $warning->getUserId(); + $response['ip'] = $warning->getUserRemoteAddress(); + $response['is_permanent'] = $warning->isPermanent(); + $response['expires'] = date('c', $response['is_permanent'] ? 0x7FFFFFFF : $warning->getExpirationTime()); + } else { + $response['expires'] = date('c', 0); + $response['is_permanent'] = false; + } + + return $response; + } + + public function createBan($response, $request): int { + if(!$request->isFormContent()) + return 400; + + $userHash = $request->hasHeader('X-SharpChat-Signature') + ? $request->getHeaderFirstLine('X-SharpChat-Signature') : ''; + $content = $request->getContent(); + $userId = (int)$content->getParam('u', FILTER_SANITIZE_NUMBER_INT); + $modId = (int)$content->getParam('m', FILTER_SANITIZE_NUMBER_INT); + $duration = (int)$content->getParam('d', FILTER_SANITIZE_NUMBER_INT); + $isPermanent = (int)$content->getParam('p', FILTER_SANITIZE_NUMBER_INT); + $reason = (string)$content->getParam('r'); + + $realHash = hash_hmac('sha256', "create#{$userId}#{$modId}#{$duration}#{$isPermanent}#{$reason}", $this->hashKey); + if(!hash_equals($realHash, $userHash)) + return 403; + + if(empty($reason)) + $reason = 'Banned through chat.'; + + if($isPermanent) + $duration = -1; + elseif($duration < 1) + return 400; + + try { + $userInfo = User::byId($userId); + } catch(UserNotFoundException $ex) { + return 404; + } + + try { + $modInfo = User::byId($modId); + } catch(UserNotFoundException $ex) { + return 404; + } + + try { + UserWarning::create( + $userInfo, + $modInfo, + UserWarning::TYPE_BAHN, + $duration, + $reason + ); + } catch(UserWarningCreationFailedException $ex) { + return 500; + } + + return 201; + } + + public function removeBan($response, $request): int { + $userHash = $request->hasHeader('X-SharpChat-Signature') + ? $request->getHeaderFirstLine('X-SharpChat-Signature') : ''; + $type = (string)$request->getParam('t'); + $subject = (string)$request->getParam('s'); + + $realHash = hash_hmac('sha256', "remove#{$type}#{$subject}", $this->hashKey); + if(!hash_equals($realHash, $userHash)) + return 403; + + $warning = null; + switch($type) { + case 'ip': + $warning = UserWarning::byRemoteAddressActive($subject); + break; + + case 'user': + $warning = UserWarning::byUserIdActive((int)$subject); + break; + } + + if($warning === null) + return 404; + + $warning->delete(); + + return 204; + } +} diff --git a/src/TOTP.php b/src/TOTP.php new file mode 100644 index 0000000..23971f9 --- /dev/null +++ b/src/TOTP.php @@ -0,0 +1,39 @@ +secretKey = $secretKey; + } + + public static function generateKey(): string { + return Serialiser::base32()->serialise(random_bytes(16)); + } + + public static function timecode(?int $timestamp = null, int $interval = self::INTERVAL): int { + $timestamp = $timestamp ?? time(); + return (int)(($timestamp * 1000) / ($interval * 1000)); + } + + public function generate(?int $timestamp = null): string { + $hash = hash_hmac(self::HASH_ALGO, pack('J', self::timecode($timestamp)), Serialiser::base32()->deserialise($this->secretKey), true); + $offset = ord($hash[strlen($hash) - 1]) & 0x0F; + + $bin = 0; + $bin |= (ord($hash[$offset]) & 0x7F) << 24; + $bin |= (ord($hash[$offset + 1]) & 0xFF) << 16; + $bin |= (ord($hash[$offset + 2]) & 0xFF) << 8; + $bin |= (ord($hash[$offset + 3]) & 0xFF); + $otp = $bin % pow(10, self::DIGITS); + + return str_pad(strval($otp), self::DIGITS, '0', STR_PAD_LEFT); + } +} diff --git a/src/Template.php b/src/Template.php new file mode 100644 index 0000000..01a6a59 --- /dev/null +++ b/src/Template.php @@ -0,0 +1,57 @@ + $cache ?? false, + 'strict_variables' => true, + 'auto_reload' => $debug, + 'debug' => $debug, + ]); + //self::$env->addExtension(new Twig_Extensions_Extension_Date); + self::$env->addExtension(new TwigMisuzu); + } + + public static function addPath(string $path): void { + self::$loader->addPath($path); + } + + public static function renderRaw(string $file, array $vars = []): string { + if(!defined('MSZ_TPL_RENDER')) { + define('MSZ_TPL_RENDER', microtime(true)); + } + + if(!str_ends_with($file, self::FILE_EXT)) { + $file = str_replace('.', DIRECTORY_SEPARATOR, $file) . self::FILE_EXT; + } + + return self::$env->render($file, array_merge(self::$vars, $vars)); + } + + public static function render(string $file, array $vars = []): void { + echo self::renderRaw($file, $vars); + } + + public static function set($arrayOrKey, $value = null): void { + if(is_string($arrayOrKey)) { + self::$vars[$arrayOrKey] = $value; + } elseif(is_array($arrayOrKey)) { + self::$vars = array_merge(self::$vars, $arrayOrKey); + } else { + throw new InvalidArgumentException('First parameter must be of type array or string.'); + } + } +} diff --git a/src/TwigMisuzu.php b/src/TwigMisuzu.php new file mode 100644 index 0000000..e5fef19 --- /dev/null +++ b/src/TwigMisuzu.php @@ -0,0 +1,71 @@ + Parser::instance($parser)->parseText($text)), + new TwigFilter('perms_check', 'perms_check'), + new TwigFilter('clamp', 'clamp'), + new TwigFilter('time_diff', [$this, 'timeDiff'], ['needs_environment' => true]), + ]; + } + + public function getFunctions() { + return [ + new TwigFunction('url_construct', 'url_construct'), + new TwigFunction('url', 'url'), + new TwigFunction('url_list', 'url_list'), + new TwigFunction('html_avatar', 'html_avatar'), + new TwigFunction('forum_may_have_children', 'forum_may_have_children'), + new TwigFunction('forum_may_have_topics', 'forum_may_have_topics'), + new TwigFunction('forum_has_priority_voting', 'forum_has_priority_voting'), + new TwigFunction('csrf_token', fn() => CSRF::token()), + new TwigFunction('git_commit_hash', fn(bool $long = false) => GitInfo::hash($long)), + new TwigFunction('git_tag', fn() => GitInfo::tag()), + new TwigFunction('git_branch', fn() => GitInfo::branch()), + new TwigFunction('startup_time', fn(float $time = MSZ_STARTUP) => microtime(true) - $time), + new TwigFunction('sql_query_count', fn() => DB::queries()), + new TwigFunction('ndx_version', fn() => Environment::getIndexVersion()), + ]; + } + + public static $units = [ + 'y' => 'year', + 'm' => 'month', + 'd' => 'day', + 'h' => 'hour', + 'i' => 'minute', + 's' => 'second', + ]; + + // yoinked from https://github.com/twigphp/Twig-extensions/blob/0c7a08e6de42a3c8f6a68af9628f4c8e4e00de93/src/DateExtension.php + public function timeDiff(TwigEnvironment $env, $date, $now = null) { + $date = \twig_date_converter($env, $date); + $now = \twig_date_converter($env, $now); + + $diff = $date->diff($now); + + foreach(self::$units as $attr => $unit) { + $count = $diff->{$attr}; + + if($count !== 0) { + if($count !== 1) + $unit .= 's'; + return $diff->invert ? "in {$count} {$unit}" : "{$count} {$unit} ago"; + } + } + + return 'just now'; + } +} diff --git a/src/Twitter.php b/src/Twitter.php new file mode 100644 index 0000000..2994899 --- /dev/null +++ b/src/Twitter.php @@ -0,0 +1,59 @@ +setToken($token, $tokenSecret); + } + + public static function createAuth(): ?string { + $codebird = Codebird::getInstance(); + $reply = $codebird->oauth_requestToken([ + 'oauth_callback' => 'oob', + ]); + + if(!$reply) + return null; + + self::setToken($reply->oauth_token, $reply->oauth_token_secret); + + return $codebird->oauth_authorize(); + } + + public static function completeAuth(string $pin): array { + $reply = Codebird::getInstance()->oauth_accessToken([ + 'oauth_verifier' => $pin, + ]); + + if(!$reply) + return []; + + self::setToken($reply->oauth_token, $reply->oauth_token_secret); + + return [ + 'token' => $reply->oauth_token, + 'token_secret' => $reply->oauth_token_secret, + ]; + } + + public static function sendTweet(string $text): void { + Codebird::getInstance()->statuses_update([ + 'status' => $text, + ]); + } +} diff --git a/src/Users/Assets/StaticUserImageAsset.php b/src/Users/Assets/StaticUserImageAsset.php new file mode 100644 index 0000000..fecb65e --- /dev/null +++ b/src/Users/Assets/StaticUserImageAsset.php @@ -0,0 +1,30 @@ +path = $path; + $this->filename = basename($path); + $this->relativePath = substr($path, strlen($absolutePart)); + } + + public function isPresent(): bool { + return is_file($this->path); + } + + public function getMimeType(): string { + return mime_content_type($this->path); + } + + public function getPublicPath(): string { + return $this->relativePath; + } + + public function getFileName(): string { + return $this->filename; + } +} diff --git a/src/Users/Assets/UserAssetException.php b/src/Users/Assets/UserAssetException.php new file mode 100644 index 0000000..2736f0e --- /dev/null +++ b/src/Users/Assets/UserAssetException.php @@ -0,0 +1,6 @@ +getMaxWidth(); + } + public function getMaxBytes(): int { + return Config::get('avatar.max_size', Config::TYPE_INT, self::MAX_BYTES); + } + + public function getUrl(): string { + return url('user-avatar', ['user' => $this->getUser()->getId()]); + } + public function getScaledUrl(int $dims): string { + return url('user-avatar', ['user' => $this->getUser()->getId(), 'res' => $dims]); + } + + public static function clampDimensions(int $dimensions): int { + $closest = null; + foreach(self::DIMENSIONS as $dims) + if($closest === null || abs($dimensions - $closest) >= abs($dims - $dimensions)) + $closest = $dims; + return $closest; + } + + public function getFileName(): string { + return sprintf('avatar-%1$d.%2$s', $this->getUser()->getId(), $this->getFileExtension()); + } + public function getScaledFileName(int $dims): string { + return sprintf('avatar-%1$d-%3$dx%3$d.%2$s', $this->getUser()->getId(), $this->getScaledFileExtension($dims), self::clampDimensions($dims)); + } + + public function getScaledMimeType(int $dims): string { + if(!$this->isScaledPresent($dims)) + return ''; + return mime_content_type($this->getScaledPath($dims)); + } + public function getScaledFileExtension(int $dims): string { + $imageSize = getimagesize($this->getScaledPath($dims)); + if($imageSize === false) + return 'img'; + return self::TYPES_EXT[$imageSize[2]] ?? 'img'; + } + + public function getRelativePath(): string { + return sprintf(self::FORMAT, self::DIR_ORIG, $this->getUser()->getId()); + } + public function getScaledRelativePath(int $dims): string { + $dims = self::clampDimensions($dims); + return sprintf(self::FORMAT, sprintf(self::DIR_SIZE, $dims), $this->getUser()->getId()); + } + + public function getScaledPath(int $dims): string { + return $this->getStoragePath() . DIRECTORY_SEPARATOR . $this->getScaledRelativePath($dims); + } + public function isScaledPresent(int $dims): bool { + return is_file($this->getScaledPath($dims)); + } + public function deleteScaled(int $dims): void { + if($this->isScaledPresent($dims)) + unlink($this->getScaledPath($dims)); + } + public function ensureScaledExists(int $dims): void { + if(!$this->isPresent()) + return; + $dims = self::clampDimensions($dims); + + if($this->isScaledPresent($dims)) + return; + + $scaledPath = $this->getScaledPath($dims); + $scaledDir = dirname($scaledPath); + if(!is_dir($scaledDir)) + mkdir($scaledDir, 0775, true); + + $scale = Image::create($this->getPath()); + $scale->squareCrop($dims); + $scale->save($scaledPath); + $scale->destroy(); + } + + public function getPublicScaledPath(int $dims): string { + return self::PUBLIC_STORAGE . '/' . $this->getScaledRelativePath($dims); + } + + public function delete(): void { + parent::delete(); + foreach(self::DIMENSIONS as $dims) + $this->deleteScaled($dims); + } +} diff --git a/src/Users/Assets/UserBackgroundAsset.php b/src/Users/Assets/UserBackgroundAsset.php new file mode 100644 index 0000000..991ec86 --- /dev/null +++ b/src/Users/Assets/UserBackgroundAsset.php @@ -0,0 +1,146 @@ + 'cover', + self::ATTACH_STRETCH => 'stretch', + self::ATTACH_TILE => 'tile', + self::ATTACH_CONTAIN => 'contain', + ]; + + public const ATTRIBUTE_STRINGS = [ + self::ATTRIB_BLEND => 'blend', + self::ATTRIB_SLIDE => 'slide', + ]; + + public static function getAttachmentStringOptions(): array { + return [ + self::ATTACH_COVER => 'Cover', + self::ATTACH_STRETCH => 'Stretch', + self::ATTACH_TILE => 'Tile', + self::ATTACH_CONTAIN => 'Contain', + ]; + } + + public function getMaxWidth(): int { + return Config::get('background.max_width', Config::TYPE_INT, self::MAX_WIDTH); + } + public function getMaxHeight(): int { + return Config::get('background.max_height', Config::TYPE_INT, self::MAX_HEIGHT); + } + public function getMaxBytes(): int { + return Config::get('background.max_size', Config::TYPE_INT, self::MAX_BYTES); + } + + public function getUrl(): string { + return url('user-background', ['user' => $this->getUser()->getId()]); + } + + public function getFileName(): string { + return sprintf('background-%1$d.%2$s', $this->getUser()->getId(), $this->getFileExtension()); + } + + public function getRelativePath(): string { + return sprintf(self::FORMAT, $this->getUser()->getId()); + } + + public function getAttachment(): int { + return $this->getUser()->getBackgroundSettings() & 0x0F; + } + public function getAttachmentString(): string { + return self::ATTACHMENT_STRINGS[$this->getAttachment()] ?? ''; + } + public function setAttachment(int $attach): self { + $this->getUser()->setBackgroundSettings($this->getAttributes() | ($attach & 0x0F)); + return $this; + } + public function setAttachmentString(string $attach): self { + if(!in_array($attach, self::ATTACHMENT_STRINGS)) + throw new InvalidArgumentException; + $this->setAttachment(array_flip(self::ATTACHMENT_STRINGS)[$attach]); + return $this; + } + + public function getAttributes(): int { + return $this->getUser()->getBackgroundSettings() & 0xF0; + } + public function setAttributes(int $attrib): self { + $this->getUser()->setBackgroundSettings($this->getAttachment() | ($attrib & 0xF0)); + return $this; + } + public function isBlend(): bool { + return ($this->getAttributes() & self::ATTRIB_BLEND) > 0; + } + public function setBlend(bool $blend): self { + $this->getUser()->setBackgroundSettings( + $blend + ? ($this->getUser()->getBackgroundSettings() | self::ATTRIB_BLEND) + : ($this->getUser()->getBackgroundSettings() & ~self::ATTRIB_BLEND) + ); + return $this; + } + public function isSlide(): bool { + return ($this->getAttributes() & self::ATTRIB_SLIDE) > 0; + } + public function setSlide(bool $slide): self { + $this->getUser()->setBackgroundSettings( + $slide + ? ($this->getUser()->getBackgroundSettings() | self::ATTRIB_SLIDE) + : ($this->getUser()->getBackgroundSettings() & ~self::ATTRIB_SLIDE) + ); + return $this; + } + + public function getClassNames(string $format = '%s'): array { + $names = []; + $attachment = $this->getAttachment(); + $attributes = $this->getAttributes(); + + if(array_key_exists($attachment, self::ATTACHMENT_STRINGS)) + $names[] = sprintf($format, self::ATTACHMENT_STRINGS[$attachment]); + + foreach(self::ATTRIBUTE_STRINGS as $flag => $name) + if(($attributes & $flag) > 0) + $names[] = sprintf($format, $name); + + return $names; + } + + public function delete(): void { + parent::delete(); + $this->getUser()->setBackgroundSettings(0); + } + + public function jsonSerialize(): mixed { + return array_merge(parent::jsonSerialize(), [ + 'attachment' => $this->getAttachmentString(), + 'is_blend' => $this->isBlend(), + 'is_slide' => $this->isSlide(), + ]); + } +} diff --git a/src/Users/Assets/UserImageAsset.php b/src/Users/Assets/UserImageAsset.php new file mode 100644 index 0000000..8912600 --- /dev/null +++ b/src/Users/Assets/UserImageAsset.php @@ -0,0 +1,139 @@ + 'png', + self::TYPE_JPG => 'jpg', + self::TYPE_GIF => 'gif', + ]; + + private $user; + + public function __construct(User $user) { + $this->user = $user; + } + + public function getUser(): User { + return $this->user; + } + + public abstract function getMaxWidth(): int; + public abstract function getMaxHeight(): int; + public abstract function getMaxBytes(): int; + + public function getAllowedTypes(): array { + return [self::TYPE_PNG, self::TYPE_JPG, self::TYPE_GIF]; + } + public function isAllowedType(int $type): bool { + return in_array($type, $this->getAllowedTypes()); + } + + private function getImageSize(): array { + return $this->isPresent() && ($imageSize = getimagesize($this->getPath())) ? $imageSize : []; + } + public function getWidth(): int { + return $this->getImageSize()[0] ?? -1; + } + public function getHeight(): int { + return $this->getImageSize()[1] ?? -1; + } + public function getIntType(): int { + return $this->getImageSize()[2] ?? -1; + } + public function getMimeType(): string { + return mime_content_type($this->getPath()); + } + public function getFileExtension(): string { + return self::TYPES_EXT[$this->getIntType()] ?? 'img'; + } + + public abstract function getFileName(): string; + + public abstract function getRelativePath(): string; + public function isPresent(): bool { + return is_file($this->getPath()); + } + + public function getPublicPath(): string { + return self::PUBLIC_STORAGE . '/' . $this->getRelativePath(); + } + + public function delete(): void { + if($this->isPresent()) + unlink($this->getPath()); + } + + public function getStoragePath(): string { + return Config::get('storage.path', Config::TYPE_STR, MSZ_ROOT . DIRECTORY_SEPARATOR . 'store'); + } + + public function getPath(): string { + return $this->getStoragePath() . DIRECTORY_SEPARATOR . $this->getRelativePath(); + } + + public function setFromPath(string $path): void { + if(!is_file($path)) + throw new UserImageAssetFileNotFoundException; + + $imageInfo = getimagesize($path); + if($imageInfo === false || count($imageInfo) < 3 || $imageInfo[0] < 1 || $imageInfo[1] < 1) + throw new UserImageAssetInvalidImageException; + + if(!self::isAllowedType($imageInfo[2])) + throw new UserImageAssetInvalidTypeException; + + if($imageInfo[0] > $this->getMaxWidth() || $imageInfo[1] > $this->getMaxHeight()) + throw new UserImageAssetInvalidDimensionsException; + + if(filesize($path) > $this->getMaxBytes()) + throw new UserImageAssetFileTooLargeException; + + $this->delete(); + + $targetPath = $this->getPath(); + $targetDir = dirname($targetPath); + if(!is_dir($targetDir)) + mkdir($targetDir, 0775, true); + + if(is_uploaded_file($path) ? !move_uploaded_file($path, $targetPath) : !copy($path, $targetPath)) + throw new UserImageAssetMoveFailedException; + } + + public function setFromData(string $data): void { + $file = tempnam(sys_get_temp_dir(), 'msz'); + if($file === false || !is_file($file)) + throw new UserImageAssetFileCreationFailedException; + chmod($file, 0664); + file_put_contents($file, $data); + self::setFromPath($file); + unlink($file); + } + + public function jsonSerialize(): mixed { + return [ + 'is_present' => $this->isPresent(), + 'width' => $this->getWidth(), + 'height' => $this->getHeight(), + 'mime' => $this->getMimeType(), + ]; + } +} diff --git a/src/Users/Assets/UserImageAssetInterface.php b/src/Users/Assets/UserImageAssetInterface.php new file mode 100644 index 0000000..bc38682 --- /dev/null +++ b/src/Users/Assets/UserImageAssetInterface.php @@ -0,0 +1,9 @@ +bind('order', $fieldOrder)->bind('key', $fieldKey) + ->bind('title', $fieldTitle)->bind('regex', $fieldRegex) + ->executeGetId(); + + if($createField < 1) + return null; + + return static::get($createField); + } + public static function createFormat( + int $fieldId, + string $formatDisplay = '%s', + ?string $formatLink = null, + ?string $formatRegex = null + ): ?ProfileField { + $createFormat = DB::prepare(' + INSERT INTO `msz_profile_fields_formats` ( + `field_id`, `format_regex`, `format_link`, `format_display` + ) VALUES (:field, :regex, :link, :display) + ')->bind('field', $fieldId) ->bind('regex', $formatRegex) + ->bind('link', $formatLink)->bind('display', $formatDisplay) + ->executeGetId(); + + if($createFormat < 1) + return null; + + return static::get($createFormat); + } + + public static function get(int $fieldId): ?ProfileField { + return DB::prepare( + 'SELECT `field_id`, `field_order`, `field_key`, `field_title`, `field_regex`' + . ' FROM `msz_profile_fields`' + . ' WHERE `field_id` = :field_id' + )->bind('field_id', $fieldId)->fetchObject(ProfileField::class); + } + + public static function user(int $userId, bool $filterEmpty = true): array { + $fields = DB::prepare( + 'SELECT pf.`field_id`, pf.`field_order`, pf.`field_key`, pf.`field_title`, pf.`field_regex`' + . ', pff.`format_id`, pff.`format_regex`, pff.`format_link`, pff.`format_display`' + . ', COALESCE(pfv.`user_id`, :user2) AS `user_id`, pfv.`field_value`' + . ' FROM `msz_profile_fields` AS pf' + . ' LEFT JOIN `msz_profile_fields_values` AS pfv ON pfv.`field_id` = pf.`field_id` AND pfv.`user_id` = :user1' + . ' LEFT JOIN `msz_profile_fields_formats` AS pff ON pff.`field_id` = pf.`field_id` AND pff.`format_id` = pfv.`format_id`' + . ' ORDER BY pf.`field_order`' + )->bind('user1', $userId)->bind('user2', $userId)->fetchObjects(ProfileField::class); + + if($filterEmpty) { + $newFields = []; + + foreach($fields as $field) { + if(!empty($field->field_value)) + $newFields[] = $field; + } + + $fields = $newFields; + } + + return $fields; + } + + public function findDisplayFormat(string $value): int { + if(!isset($this->field_id)) + return 0; + + $format = DB::prepare(' + SELECT `format_id` + FROM `msz_profile_fields_formats` + WHERE `field_id` = :field + AND `format_regex` IS NOT NULL + AND :value REGEXP `format_regex` + ')->bind('field', $this->field_id) + ->bind('value', $value) + ->fetchColumn(); + + if($format < 1) { + $format = DB::prepare(' + SELECT `format_id` + FROM `msz_profile_fields_formats` + WHERE `field_id` = :field + AND `format_regex` IS NULL + ')->bind('field', $this->field_id) + ->fetchColumn(0, 0); + } + + return $format; + } + + // todo: use exceptions + public function setFieldValue(string $value): bool { + if(!isset($this->user_id, $this->field_id, $this->field_regex)) + return false; + + if(empty($value)) { + DB::prepare(' + DELETE FROM `msz_profile_fields_values` + WHERE `user_id` = :user + AND `field_id` = :field + ')->bind('user', $this->user_id) + ->bind('field', $this->field_id) + ->execute(); + $this->field_value = ''; + return true; + } + + if(preg_match($this->field_regex, $value, $matches)) { + $value = $matches[1]; + } else { + return false; + } + + $displayFormat = $this->findDisplayFormat($value); + + if($displayFormat < 1) + return false; + + $updateField = DB::prepare(' + REPLACE INTO `msz_profile_fields_values` + (`field_id`, `user_id`, `format_id`, `field_value`) + VALUES + (:field, :user, :format, :value) + ')->bind('field', $this->field_id) + ->bind('user', $this->user_id) + ->bind('format', $displayFormat) + ->bind('value', $value) + ->execute(); + + if(!$updateField) + return false; + + $this->field_value = $value; + return true; + } +} diff --git a/src/Users/User.php b/src/Users/User.php new file mode 100644 index 0000000..5d32e21 --- /dev/null +++ b/src/Users/User.php @@ -0,0 +1,896 @@ +user_id < 1 ? -1 : $this->user_id; + } + + public function getUsername(): string { + return $this->username; + } + public function setUsername(string $username): self { + $this->username = $username; + return $this; + } + + public function getEmailAddress(): string { + return $this->email; + } + public function setEmailAddress(string $address): self { + $this->email = mb_strtolower($address); + return $this; + } + + public function getRegisterRemoteAddress(): string { + return $this->register_ip ?? '::1'; + } + public function getLastRemoteAddress(): string { + return $this->last_ip ?? '::1'; + } + + public function isSuper(): bool { + return boolval($this->user_super); + } + public function setSuper(bool $super): self { + $this->user_super = $super ? 1 : 0; + return $this; + } + + public function hasCountry(): bool { + return $this->user_country !== 'XX'; + } + public function getCountry(): string { + return $this->user_country ?? 'XX'; + } + public function setCountry(string $country): self { + $this->user_country = strtoupper(substr($country, 0, 2)); + return $this; + } + public function getCountryName(): string { + return get_country_name($this->getCountry()); + } + + private $userColour = null; + private $realColour = null; + + public function getColour(): Colour { // Swaps role colour in if user has no personal colour + if($this->realColour === null) { + $this->realColour = $this->getUserColour(); + if($this->realColour->getInherit()) + $this->realColour = $this->getDisplayRole()->getColour(); + } + return $this->realColour; + } + public function setColour(?Colour $colour): self { + return $this->setColourRaw($colour === null ? null : $colour->getRaw()); + } + public function getUserColour(): Colour { // Only ever gets the user's actual colour + if($this->userColour === null) + $this->userColour = new Colour($this->getColourRaw()); + return $this->userColour; + } + public function getColourRaw(): int { + return $this->user_colour ?? 0x40000000; + } + public function setColourRaw(?int $colour): self { + $this->user_colour = $colour; + $this->userColour = null; + $this->realColour = null; + return $this; + } + + public function getCreatedTime(): int { + return $this->user_created === null ? -1 : $this->user_created; + } + + public function hasBeenActive(): bool { + return $this->user_active !== null; + } + public function getActiveTime(): int { + return $this->user_active === null ? -1 : $this->user_active; + } + + private $userRank = null; + public function getRank(): int { + if($this->userRank === null) + $this->userRank = (int)DB::prepare( + 'SELECT MAX(`role_hierarchy`)' + . ' FROM `' . DB::PREFIX . UserRole::TABLE . '`' + . ' WHERE `role_id` IN (SELECT `role_id` FROM `' . DB::PREFIX . UserRoleRelation::TABLE . '` WHERE `user_id` = :user)' + )->bind('user', $this->getId())->fetchColumn(); + return $this->userRank; + } + public function hasAuthorityOver(HasRankInterface $other): bool { + // Don't even bother checking if we're a super user + if($this->isSuper()) + return true; + if($other instanceof self && $other->getId() === $this->getId()) + return true; + return $this->getRank() > $other->getRank(); + } + + public function getDisplayRoleId(): int { + return $this->display_role < 1 ? -1 : $this->display_role; + } + public function setDisplayRoleId(int $roleId): self { + $this->display_role = $roleId < 1 ? -1 : $roleId; + return $this; + } + public function getDisplayRole(): UserRole { + return $this->getRoleRelations()[$this->getDisplayRoleId()]->getRole(); + } + public function setDisplayRole(UserRole $role): self { + if($this->hasRole($role)) + $this->setDisplayRoleId($role->getId()); + return $this; + } + public function isDisplayRole(UserRole $role): bool { + return $this->getDisplayRoleId() === $role->getId(); + } + + public function hasTOTP(): bool { + return !empty($this->user_totp_key); + } + public function getTOTP(): TOTP { + if($this->totp === null) + $this->totp = new TOTP($this->user_totp_key); + return $this->totp; + } + public function getTOTPKey(): string { + return $this->user_totp_key ?? ''; + } + public function setTOTPKey(string $key): self { + $this->totp = null; + $this->user_totp_key = $key; + return $this; + } + public function removeTOTPKey(): self { + $this->totp = null; + $this->user_totp_key = null; + return $this; + } + public function getValidTOTPTokens(): array { + if(!$this->hasTOTP()) + return []; + $totp = $this->getTOTP(); + return [ + $totp->generate(time()), + $totp->generate(time() - 30), + $totp->generate(time() + 30), + ]; + } + + public function hasProfileAbout(): bool { + return !empty($this->user_about_content); + } + public function getProfileAboutText(): string { + return $this->user_about_content ?? ''; + } + public function setProfileAboutText(string $text): self { + $this->user_about_content = empty($text) ? null : $text; + return $this; + } + public function getProfileAboutParser(): int { + return $this->hasProfileAbout() ? $this->user_about_parser : Parser::BBCODE; + } + public function setProfileAboutParser(int $parser): self { + $this->user_about_parser = $parser; + return $this; + } + public function getProfileAboutParsed(): string { + if(!$this->hasProfileAbout()) + return ''; + return Parser::instance($this->getProfileAboutParser()) + ->parseText(htmlspecialchars($this->getProfileAboutText())); + } + + public function hasForumSignature(): bool { + return !empty($this->user_signature_content); + } + public function getForumSignatureText(): string { + return $this->user_signature_content ?? ''; + } + public function setForumSignatureText(string $text): self { + $this->user_signature_content = empty($text) ? null : $text; + return $this; + } + public function getForumSignatureParser(): int { + return $this->hasForumSignature() ? $this->user_signature_parser : Parser::BBCODE; + } + public function setForumSignatureParser(int $parser): self { + $this->user_signature_parser = $parser; + return $this; + } + public function getForumSignatureParsed(): string { + if(!$this->hasForumSignature()) + return ''; + return Parser::instance($this->getForumSignatureParser()) + ->parseText(htmlspecialchars($this->getForumSignatureText())); + } + + // Address these through getBackgroundInfo() + public function getBackgroundSettings(): int { + return $this->user_background_settings; + } + public function setBackgroundSettings(int $settings): self { + $this->user_background_settings = $settings; + return $this; + } + + public function hasTitle(): bool { + return !empty($this->user_title); + } + public function getTitle(): string { + return $this->user_title ?? ''; + } + public function setTitle(string $title): self { + $this->user_title = empty($title) ? null : $title; + return $this; + } + + public function hasBirthdate(): bool { + return $this->user_birthdate !== null; + } + public function getBirthdate(): DateTime { + return new DateTime($this->user_birthdate ?? '0000-01-01', new DateTimeZone('UTC')); + } + public function setBirthdate(int $year, int $month, int $day): self { + $this->user_birthdate = $month < 1 || $day < 1 ? null : sprintf('%04d-%02d-%02d', $year, $month, $day); + return $this; + } + public function hasAge(): bool { + return $this->hasBirthdate() && intval($this->getBirthdate()->format('Y')) > 1900; + } + public function getAge(): int { + if(!$this->hasAge()) + return -1; + return intval($this->getBirthdate()->diff(new DateTime('now', new DateTimeZone('UTC')))->format('%y')); + } + + public function profileFields(bool $filterEmpty = true): array { + if(($userId = $this->getId()) < 1) + return []; + return ProfileField::user($userId, $filterEmpty); + } + + public function bumpActivity(?string $lastRemoteAddress = null): void { + $this->user_active = time(); + $this->last_ip = $lastRemoteAddress ?? IPAddress::remote(); + + DB::prepare( + 'UPDATE `' . DB::PREFIX . self::TABLE . '`' + . ' SET `user_active` = FROM_UNIXTIME(:active), `last_ip` = INET6_ATON(:address)' + . ' WHERE `user_id` = :user' + ) ->bind('user', $this->user_id) + ->bind('active', $this->user_active) + ->bind('address', $this->last_ip) + ->execute(); + } + + // TODO: Is this the proper location/implementation for this? (no) + private $commentPermsArray = null; + public function commentPerms(): array { + if($this->commentPermsArray === null) + $this->commentPermsArray = perms_check_user_bulk(MSZ_PERMS_COMMENTS, $this->getId(), [ + 'can_comment' => MSZ_PERM_COMMENTS_CREATE, + 'can_delete' => MSZ_PERM_COMMENTS_DELETE_OWN | MSZ_PERM_COMMENTS_DELETE_ANY, + 'can_delete_any' => MSZ_PERM_COMMENTS_DELETE_ANY, + 'can_pin' => MSZ_PERM_COMMENTS_PIN, + 'can_lock' => MSZ_PERM_COMMENTS_LOCK, + 'can_vote' => MSZ_PERM_COMMENTS_VOTE, + ]); + return $this->commentPermsArray; + } + + private $legacyPerms = null; + public function getLegacyPerms(): array { + if($this->legacyPerms === null) + $this->legacyPerms = perms_get_user($this->getId()); + return $this->legacyPerms; + } + + /******** + * JSON * + ********/ + + public function jsonSerialize(): mixed { + return [ + 'id' => $this->getId(), + 'username' => $this->getUsername(), + 'country' => $this->getCountry(), + 'is_super' => $this->isSuper(), + 'rank' => $this->getRank(), + 'display_role' => $this->getDisplayRoleId(), + 'title' => $this->getTitle(), + 'created' => date('c', $this->getCreatedTime()), + 'last_active' => ($date = $this->getActiveTime()) < 0 ? null : date('c', $date), + 'avatar' => $this->getAvatarInfo(), + 'background' => $this->getBackgroundInfo(), + ]; + } + + /************ + * PASSWORD * + ************/ + + public static function hashPassword(string $password): string { + return password_hash($password, self::PASSWORD_ALGO); + } + public function hasPassword(): bool { + return !empty($this->password); + } + public function checkPassword(string $password): bool { + return $this->hasPassword() && password_verify($password, $this->password); + } + public function passwordNeedsRehash(): bool { + return password_needs_rehash($this->password, self::PASSWORD_ALGO); + } + public function removePassword(): self { + $this->password = null; + return $this; + } + public function setPassword(string $password): self { + $this->password = self::hashPassword($password); + return $this; + } + + /************ + * DELETING * + ************/ + + private const NUKE_TIMEOUT = 600; + + public function getDeletedTime(): int { + return $this->user_deleted === null ? -1 : $this->user_deleted; + } + public function isDeleted(): bool { + return $this->getDeletedTime() >= 0; + } + public function delete(): void { + if($this->isDeleted()) + return; + $this->user_deleted = time(); + DB::prepare('UPDATE `' . DB::PREFIX . self::TABLE . '` SET `user_deleted` = NOW() WHERE `user_id` = :user') + ->bind('user', $this->user_id) + ->execute(); + } + public function restore(): void { + if(!$this->isDeleted()) + return; + $this->user_deleted = null; + DB::prepare('UPDATE `' . DB::PREFIX . self::TABLE . '` SET `user_deleted` = NULL WHERE `user_id` = :user') + ->bind('user', $this->user_id) + ->execute(); + } + public function canBeNuked(): bool { + return $this->isDeleted() && time() > $this->getDeletedTime() + self::NUKE_TIMEOUT; + } + public function nuke(): void { + if(!$this->canBeNuked()) + return; + DB::prepare('DELETE FROM `' . DB::PREFIX . self::TABLE . '` WHERE `user_id` = :user') + ->bind('user', $this->user_id) + ->execute(); + } + + /********** + * ASSETS * + **********/ + + private $avatarAsset = null; + public function getAvatarInfo(): UserAvatarAsset { + if($this->avatarAsset === null) + $this->avatarAsset = new UserAvatarAsset($this); + return $this->avatarAsset; + } + public function hasAvatar(): bool { + return $this->getAvatarInfo()->isPresent(); + } + + private $backgroundAsset = null; + public function getBackgroundInfo(): UserBackgroundAsset { + if($this->backgroundAsset === null) + $this->backgroundAsset = new UserBackgroundAsset($this); + return $this->backgroundAsset; + } + public function hasBackground(): bool { + return $this->getBackgroundInfo()->isPresent(); + } + + /********* + * ROLES * + *********/ + + private $roleRelations = null; + + public function addRole(UserRole $role, bool $display = false): void { + if(!$this->hasRole($role)) + $this->roleRelations[$role->getId()] = UserRoleRelation::create($this, $role); + + if($display && $this->isDisplayRole($role)) + $this->setDisplayRole($role); + } + + public function removeRole(UserRole $role): void { + if(!$this->hasRole($role)) + return; + UserRoleRelation::destroy($this, $role); + unset($this->roleRelations[$role->getId()]); + + if($this->isDisplayRole($role)) + $this->setDisplayRoleId(UserRole::DEFAULT); + } + + public function getRoleRelations(): array { + if($this->roleRelations === null) { + $this->roleRelations = []; + foreach(UserRoleRelation::byUser($this) as $rel) + $this->roleRelations[$rel->getRoleId()] = $rel; + } + return $this->roleRelations; + } + + public function getRoles(): array { + $roles = []; + foreach($this->getRoleRelations() as $rel) + $roles[$rel->getRoleId()] = $rel->getRole(); + return $roles; + } + + public function hasRole(UserRole $role): bool { + return array_key_exists($role->getId(), $this->getRoleRelations()); + } + + /*************** + * FORUM STATS * + ***************/ + + private $forumTopicCount = -1; + private $forumPostCount = -1; + + public function getForumTopicCount(): int { + if($this->forumTopicCount < 0) + $this->forumTopicCount = (int)DB::prepare('SELECT COUNT(*) FROM `msz_forum_topics` WHERE `user_id` = :user AND `topic_deleted` IS NULL') + ->bind('user', $this->getId()) + ->fetchColumn(); + return $this->forumTopicCount; + } + public function getForumPostCount(): int { + if($this->forumPostCount < 0) + $this->forumPostCount = (int)DB::prepare('SELECT COUNT(*) FROM `msz_forum_posts` WHERE `user_id` = :user AND `post_deleted` IS NULL') + ->bind('user', $this->getId()) + ->fetchColumn(); + return $this->forumPostCount; + } + + /************ + * WARNINGS * + ************/ + + private $activeWarning = -1; + + public function getActiveWarning(): ?UserWarning { + if($this->activeWarning === -1) + $this->activeWarning = UserWarning::byUserActive($this); + return $this->activeWarning; + } + public function hasActiveWarning(): bool { + return $this->getActiveWarning() !== null && !$this->getActiveWarning()->hasExpired(); + } + public function isSilenced(): bool { + return $this->hasActiveWarning() && $this->getActiveWarning()->isSilence(); + } + public function isBanned(): bool { + return $this->hasActiveWarning() && $this->getActiveWarning()->isBan(); + } + public function getActiveWarningExpiration(): int { + return !$this->hasActiveWarning() ? 0 : $this->getActiveWarning()->getExpirationTime(); + } + public function isActiveWarningPermanent(): bool { + return $this->hasActiveWarning() && $this->getActiveWarning()->isPermanent(); + } + public function getProfileWarnings(?self $viewer): array { + return UserWarning::byProfile($this, $viewer); + } + + /************** + * LOCAL USER * + **************/ + + public function setCurrent(): void { + self::$localUser = $this; + } + public static function unsetCurrent(): void { + self::$localUser = null; + } + public static function getCurrent(): ?self { + return self::$localUser; + } + public static function hasCurrent(): bool { + return self::$localUser !== null; + } + + public function getClientJson(): string { + return json_encode([ + 'user_id' => $this->getId(), + 'username' => $this->getUsername(), + 'user_colour' => $this->getColour()->getRaw(), + 'perms' => $this->getLegacyPerms(), + ]); + } + + /************** + * VALIDATION * + **************/ + + public static function validateUsername(string $name): string { + if($name !== trim($name)) + return 'trim'; + + $length = mb_strlen($name); + if($length < self::NAME_MIN_LENGTH) + return 'short'; + if($length > self::NAME_MAX_LENGTH) + return 'long'; + + if(!preg_match('#^' . self::NAME_REGEX . '$#u', $name)) + return 'invalid'; + + $userId = (int)DB::prepare( + 'SELECT `user_id`' + . ' FROM `' . DB::PREFIX . self::TABLE . '`' + . ' WHERE LOWER(`username`) = LOWER(:username)' + ) ->bind('username', $name) + ->fetchColumn(); + if($userId > 0) + return 'in-use'; + + return ''; + } + + public static function usernameValidationErrorString(string $error): string { + switch($error) { + case 'trim': + return 'Your username may not start or end with spaces!'; + case 'short': + return sprintf('Your username is too short, it has to be at least %d characters!', self::NAME_MIN_LENGTH); + case 'long': + return sprintf("Your username is too long, it can't be longer than %d characters!", self::NAME_MAX_LENGTH); + case 'invalid': + return 'Your username contains invalid characters.'; + case 'in-use': + return 'This username is already taken!'; + case '': + return 'This username is correctly formatted!'; + default: + return 'This username is incorrectly formatted.'; + } + } + + public static function validateEMailAddress(string $address): string { + if(filter_var($address, FILTER_VALIDATE_EMAIL) === false) + return 'format'; + if(!checkdnsrr(mb_substr(mb_strstr($address, '@'), 1), 'MX')) + return 'dns'; + + $userId = (int)DB::prepare( + 'SELECT `user_id`' + . ' FROM `' . DB::PREFIX . self::TABLE . '`' + . ' WHERE LOWER(`email`) = LOWER(:email)' + ) ->bind('email', $address) + ->fetchColumn(); + if($userId > 0) + return 'in-use'; + + return ''; + } + + public static function validatePassword(string $password): string { + if(unique_chars($password) < self::PASSWORD_UNIQUE) + return 'weak'; + + return ''; + } + + public static function validateBirthdate(int $year, int $month, int $day, int $yearRange = 100): string { + if($year > 0) { + if($year < date('Y') - $yearRange || $year > date('Y')) + return 'year'; + $checkYear = $year; + } else $checkYear = date('Y'); + + if(!($day === 0 && $month === 0) && !checkdate($month, $day, $checkYear)) + return 'date'; + + return ''; + } + + public static function validateProfileAbout(int $parser, string $text): string { + if(!Parser::isValid($parser)) + return 'parser'; + + $length = strlen($text); + if($length > self::PROFILE_ABOUT_MAX_LENGTH) + return 'long'; + + return ''; + } + + public static function validateForumSignature(int $parser, string $text): string { + if(!Parser::isValid($parser)) + return 'parser'; + + $length = strlen($text); + if($length > self::FORUM_SIGNATURE_MAX_LENGTH) + return 'long'; + + return ''; + } + + /********************* + * CREATION + SAVING * + *********************/ + + public function save(): void { + $save = DB::prepare( + 'UPDATE `' . DB::PREFIX . self::TABLE . '`' + . ' SET `username` = :username, `email` = :email, `password` = :password' + . ', `user_super` = :is_super, `user_country` = :country, `user_colour` = :colour, `user_title` = :title' + . ', `display_role` = :display_role, `user_birthdate` = :birthdate, `user_totp_key` = :totp' + . ' WHERE `user_id` = :user' + ) ->bind('user', $this->user_id) + ->bind('username', $this->username) + ->bind('email', $this->email) + ->bind('password', $this->password) + ->bind('is_super', $this->user_super) + ->bind('country', $this->user_country) + ->bind('colour', $this->user_colour) + ->bind('display_role', $this->display_role) + ->bind('birthdate', $this->user_birthdate) + ->bind('totp', $this->user_totp_key) + ->bind('title', $this->user_title) + ->execute(); + } + + public function saveProfile(): void { + $save = DB::prepare( + 'UPDATE `' . DB::PREFIX . self::TABLE . '`' + . ' SET `user_about_content` = :about_content, `user_about_parser` = :about_parser' + . ', `user_signature_content` = :signature_content, `user_signature_parser` = :signature_parser' + . ', `user_background_settings` = :background_settings' + . ' WHERE `user_id` = :user' + ) ->bind('user', $this->user_id) + ->bind('about_content', $this->user_about_content) + ->bind('about_parser', $this->user_about_parser) + ->bind('signature_content', $this->user_signature_content) + ->bind('signature_parser', $this->user_signature_parser) + ->bind('background_settings', $this->user_background_settings) + ->execute(); + } + + public static function create( + string $username, + string $password, + string $email, + string $ipAddress + ): self { + $createUser = DB::prepare( + 'INSERT INTO `' . DB::PREFIX . self::TABLE . '` (`username`, `password`, `email`, `register_ip`, `last_ip`, `user_country`, `display_role`)' + . ' VALUES (:username, :password, LOWER(:email), INET6_ATON(:register_ip), INET6_ATON(:last_ip), :user_country, 1)' + ) ->bind('username', $username) + ->bind('email', $email) + ->bind('register_ip', $ipAddress) + ->bind('last_ip', $ipAddress) + ->bind('password', self::hashPassword($password)) + ->bind('user_country', IPAddress::country($ipAddress)) + ->executeGetId(); + + if($createUser < 1) + throw new UserCreationFailedException; + + return self::byId($createUser); + } + + /************ + * FETCHING * + ************/ + + private static function countQueryBase(): string { + return sprintf(self::QUERY_SELECT, 'COUNT(*)'); + } + public static function countAll(bool $showDeleted = false): int { + return (int)DB::prepare( + self::countQueryBase() + . ($showDeleted ? '' : ' WHERE `user_deleted` IS NULL') + )->fetchColumn(); + } + + private static function memoizer() { + static $memoizer = null; + if($memoizer === null) + $memoizer = new Memoizer; + return $memoizer; + } + + private static function byQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf(self::SELECT, self::TABLE)); + } + public static function byId(int $userId): ?self { + return self::memoizer()->find($userId, function() use ($userId) { + $user = DB::prepare(self::byQueryBase() . ' WHERE `user_id` = :user_id') + ->bind('user_id', $userId) + ->fetchObject(self::class); + if(!$user) + throw new UserNotFoundException; + return $user; + }); + } + public static function byUsername(string $username): ?self { + $username = mb_strtolower($username); + return self::memoizer()->find(function($user) use ($username) { + return mb_strtolower($user->getUsername()) === $username; + }, function() use ($username) { + $user = DB::prepare(self::byQueryBase() . ' WHERE LOWER(`username`) = :username') + ->bind('username', $username) + ->fetchObject(self::class); + if(!$user) + throw new UserNotFoundException; + return $user; + }); + } + public static function byEMailAddress(string $address): ?self { + $address = mb_strtolower($address); + return self::memoizer()->find(function($user) use ($address) { + return mb_strtolower($user->getEmailAddress()) === $address; + }, function() use ($address) { + $user = DB::prepare(self::byQueryBase() . ' WHERE LOWER(`email`) = :email') + ->bind('email', $address) + ->fetchObject(self::class); + if(!$user) + throw new UserNotFoundException; + return $user; + }); + } + public static function byUsernameOrEMailAddress(string $usernameOrAddress): self { + $usernameOrAddressLower = mb_strtolower($usernameOrAddress); + return self::memoizer()->find(function($user) use ($usernameOrAddressLower) { + return mb_strtolower($user->getUsername()) === $usernameOrAddressLower + || mb_strtolower($user->getEmailAddress()) === $usernameOrAddressLower; + }, function() use ($usernameOrAddressLower) { + $user = DB::prepare(self::byQueryBase() . ' WHERE LOWER(`email`) = :email OR LOWER(`username`) = :username') + ->bind('email', $usernameOrAddressLower) + ->bind('username', $usernameOrAddressLower) + ->fetchObject(self::class); + if(!$user) + throw new UserNotFoundException; + return $user; + }); + } + public static function byLatest(): ?self { + return DB::prepare(self::byQueryBase() . ' WHERE `user_deleted` IS NULL ORDER BY `user_id` DESC LIMIT 1') + ->fetchObject(self::class); + } + public static function findForProfile($userIdOrName): ?self { + $userIdOrNameLower = mb_strtolower($userIdOrName); + return self::memoizer()->find(function($user) use ($userIdOrNameLower) { + return $user->getId() == $userIdOrNameLower || mb_strtolower($user->getUsername()) === $userIdOrNameLower; + }, function() use ($userIdOrName) { + $user = DB::prepare(self::byQueryBase() . ' WHERE `user_id` = :user_id OR LOWER(`username`) = LOWER(:username)') + ->bind('user_id', (int)$userIdOrName) + ->bind('username', (string)$userIdOrName) + ->fetchObject(self::class); + if(!$user) + throw new UserNotFoundException; + return $user; + }); + } + public static function byBirthdate(?DateTime $date = null): array { + $date = $date === null ? new DateTime('now', new DateTimeZone('UTC')) : (clone $date)->setTimezone(new DateTimeZone('UTC')); + return DB::prepare(self::byQueryBase() . ' WHERE `user_deleted` IS NULL AND `user_birthdate` LIKE :date') + ->bind('date', $date->format('%-m-d')) + ->fetchObjects(self::class); + } + public static function all(bool $showDeleted = false, ?Pagination $pagination = null): array { + $query = self::byQueryBase(); + + if(!$showDeleted) + $query .= ' WHERE `user_deleted` IS NULL'; + + $query .= ' ORDER BY `user_id` ASC'; + + if($pagination !== null) + $query .= ' LIMIT :range OFFSET :offset'; + + $getObjects = DB::prepare($query); + + if($pagination !== null) + $getObjects->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getObjects->fetchObjects(self::class); + } +} diff --git a/src/Users/UserAuthSession.php b/src/Users/UserAuthSession.php new file mode 100644 index 0000000..9f984e4 --- /dev/null +++ b/src/Users/UserAuthSession.php @@ -0,0 +1,93 @@ +user_id < 1 ? -1 : $this->user_id; + } + public function getUser(): User { + if($this->user === null) + $this->user = User::byId($this->getUserId()); + return $this->user; + } + + public function getToken(): string { + return $this->tfa_token; + } + + public function getCreationTime(): int { + return $this->tfa_created === null ? -1 : $this->tfa_created; + } + public function getExpirationTime(): int { + return $this->getCreationTime() + self::TOKEN_LIFETIME; + } + public function hasExpired(): bool { + return $this->getExpirationTime() <= time(); + } + + public function delete(): void { + DB::prepare('DELETE FROM `' . DB::PREFIX . self::TABLE . '` WHERE `tfa_token` = :token') + ->bind('token', $this->tfa_token) + ->execute(); + } + + public static function generateToken(): string { + return bin2hex(random_bytes(self::TOKEN_WIDTH)); + } + + public static function create(User $user, bool $return = true): ?self { + $token = self::generateToken(); + $created = DB::prepare('INSERT INTO `' . DB::PREFIX . self::TABLE . '` (`user_id`, `tfa_token`) VALUES (:user, :token)') + ->bind('user', $user->getId()) + ->bind('token', $token) + ->execute(); + + if(!$created) + throw new UserAuthSessionCreationFailedException; + if(!$return) + return null; + + try { + $object = self::byToken($token); + $object->user = $user; + return $object; + } catch(UserAuthSessionNotFoundException $ex) { + throw new UserAuthSessionCreationFailedException; + } + } + + private static function byQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf(self::SELECT, self::TABLE)); + } + public static function byToken(string $token): self { + $object = DB::prepare(self::byQueryBase() . ' WHERE `tfa_token` = :token') + ->bind('token', $token) + ->fetchObject(self::class); + + if(!$object) + throw new UserAuthSessionNotFoundException; + + return $object; + } +} diff --git a/src/Users/UserLoginAttempt.php b/src/Users/UserLoginAttempt.php new file mode 100644 index 0000000..1d4b897 --- /dev/null +++ b/src/Users/UserLoginAttempt.php @@ -0,0 +1,130 @@ +user_id < 1 ? -1 : $this->user_id; + } + public function getUser(): ?User { + if(!$this->userLookedUp && ($userId = $this->getUserId()) > 0) { + $this->userLookedUp = true; + try { + $this->user = User::byId($userId); + } catch(UserNotFoundException $ex) {} + } + return $this->user; + } + + public function isSuccess(): bool { + return boolval($this->attempt_success); + } + + public function getRemoteAddress(): string { + return $this->attempt_ip; + } + + public function getCountry(): string { + return $this->attempt_country; + } + public function getCountryName(): string { + return get_country_name($this->getCountry()); + } + + public function getCreatedTime(): int { + return $this->attempt_created === null ? -1 : $this->attempt_created; + } + + public function getUserAgent(): string { + return $this->attempt_user_agent; + } + public function getUserAgentInfo(): UserAgentParser { + if($this->uaInfo === null) + $this->uaInfo = new UserAgentParser($this->getUserAgent()); + return $this->uaInfo; + } + + public static function remaining(?string $remoteAddr = null): int { + $remoteAddr = $remoteAddr ?? IPAddress::remote(); + return (int)DB::prepare( + 'SELECT 5 - COUNT(*)' + . ' FROM `' . DB::PREFIX . self::TABLE . '`' + . ' WHERE `attempt_success` = 0' + . ' AND `attempt_created` > NOW() - INTERVAL 1 HOUR' + . ' AND `attempt_ip` = INET6_ATON(:remote_ip)' + ) ->bind('remote_ip', $remoteAddr) + ->fetchColumn(); + } + + public static function create(bool $success, ?User $user = null, ?string $remoteAddr = null, string $userAgent = null): void { + $remoteAddr = $remoteAddr ?? IPAddress::remote(); + $userAgent = $userAgent ?? filter_input(INPUT_SERVER, 'HTTP_USER_AGENT') ?? ''; + $createLog = DB::prepare( + 'INSERT INTO `' . DB::PREFIX . self::TABLE . '` (`user_id`, `attempt_success`, `attempt_ip`, `attempt_country`, `attempt_user_agent`)' + . ' VALUES (:user, :success, INET6_ATON(:ip), :country, :user_agent)' + ) ->bind('user', $user === null ? null : $user->getId()) // this null situation should never ever happen but better safe than sorry ! + ->bind('success', $success ? 1 : 0) + ->bind('ip', $remoteAddr) + ->bind('country', IPAddress::country($remoteAddr)) + ->bind('user_agent', $userAgent) + ->execute(); + } + + private static function countQueryBase(): string { + return sprintf(self::QUERY_SELECT, 'COUNT(*)'); + } + public static function countAll(?User $user = null): int { + $getCount = DB::prepare( + self::countQueryBase() + . ($user === null ? '' : ' WHERE `user_id` = :user') + ); + if($user !== null) + $getCount->bind('user', $user->getId()); + return (int)$getCount->fetchColumn(); + } + + private static function byQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf(self::SELECT, self::TABLE)); + } + public static function all(?Pagination $pagination = null, ?User $user = null): array { + $attemptsQuery = self::byQueryBase() + . ($user === null ? '' : ' WHERE `user_id` = :user') + . ' ORDER BY `attempt_created` DESC'; + + if($pagination !== null) + $attemptsQuery .= ' LIMIT :range OFFSET :offset'; + + $getAttempts = DB::prepare($attemptsQuery); + + if($user !== null) + $getAttempts->bind('user', $user->getId()); + + if($pagination !== null) + $getAttempts->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getAttempts->fetchObjects(self::class); + } +} diff --git a/src/Users/UserRecoveryToken.php b/src/Users/UserRecoveryToken.php new file mode 100644 index 0000000..467c146 --- /dev/null +++ b/src/Users/UserRecoveryToken.php @@ -0,0 +1,125 @@ +user_id < 1 ? -1 : $this->user_id; + } + public function getUser(): User { + if($this->user === null) + $this->user = User::byId($this->getUserId()); + return $this->user; + } + + public function getRemoteAddress(): string { + return $this->reset_ip; + } + + public function getToken(): string { + return $this->verification_code ?? ''; + } + public function hasToken(): bool { + return !empty($this->verification_code); + } + + public function getCreationTime(): int { + return $this->reset_requested === null ? -1 : $this->reset_requested; + } + public function getExpirationTime(): int { + return $this->getCreationTime() + self::TOKEN_LIFETIME; + } + public function hasExpired(): bool { + return $this->getExpirationTime() <= time(); + } + + public function isValid(): bool { + return $this->hasToken() && !$this->hasExpired(); + } + + public function invalidate(): void { + DB::prepare( + 'UPDATE `' . DB::PREFIX . self::TABLE . '` SET `verification_code` = NULL' + . ' WHERE `verification_code` = :token AND `user_id` = :user' + ) ->bind('token', $this->verification_code) + ->bind('user', $this->user_id) + ->execute(); + } + + public static function generateToken(): string { + return bin2hex(random_bytes(self::TOKEN_WIDTH)); + } + + public static function create(User $user, ?string $remoteAddr = null, bool $return = true): ?self { + $remoteAddr = $remoteAddr ?? IPAddress::remote(); + $token = self::generateToken(); + + $created = DB::prepare('INSERT INTO `' . DB::PREFIX . self::TABLE . '` (`user_id`, `reset_ip`, `verification_code`) VALUES (:user, INET6_ATON(:address), :token)') + ->bind('user', $user->getId()) + ->bind('address', $remoteAddr) + ->bind('token', $token) + ->execute(); + + if(!$created) + throw new UserRecoveryTokenCreationFailedException; + if(!$return) + return null; + + try { + $object = self::byToken($token); + $object->user = $user; + return $object; + } catch(UserRecoveryTokenNotFoundException $ex) { + throw new UserRecoveryTokenCreationFailedException; + } + } + + private static function byQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf(self::SELECT, self::TABLE)); + } + public static function byToken(string $token): self { + $object = DB::prepare(self::byQueryBase() . ' WHERE `verification_code` = :token') + ->bind('token', $token) + ->fetchObject(self::class); + + if(!$object) + throw new UserRecoveryTokenNotFoundException; + + return $object; + } + public static function byUserAndRemoteAddress(User $user, ?string $remoteAddr = null): self { + $remoteAddr = $remoteAddr ?? IPAddress::remote(); + $object = DB::prepare(self::byQueryBase() . ' WHERE `user_id` = :user AND `reset_ip` = INET6_ATON(:address)') + ->bind('user', $user->getId()) + ->bind('address', $remoteAddr) + ->fetchObject(self::class); + + if(!$object) + throw new UserRecoveryTokenNotFoundException; + + return $object; + } +} diff --git a/src/Users/UserRole.php b/src/Users/UserRole.php new file mode 100644 index 0000000..d0aeac9 --- /dev/null +++ b/src/Users/UserRole.php @@ -0,0 +1,227 @@ +role_id < 1 ? -1 : $this->role_id; + } + + public function getRank(): int { + return $this->role_hierarchy; + } + public function setRank(int $rank): self { + $this->role_hierarchy = $rank; + return $this; + } + + public function getName(): string { + return $this->role_name; + } + public function setName(string $name): self { + $this->role_name = $name; + return $this; + } + + public function getTitle(): string { + return $this->role_title ?? ''; + } + public function setTitle(string $title): self { + $this->role_title = empty($title) ? null : $title; + return $this; + } + + public function getDescription(): string { + return $this->role_description ?? ''; + } + public function setDescription(string $description): self { + $this->role_description = empty($description) ? null : $description; + return $this; + } + + public function isHidden(): bool { + return boolval($this->role_hidden); + } + public function setHidden(bool $hidden): self { + $this->role_hidden = $hidden ? 1 : 0; + return $this; + } + + public function getCanLeave(): bool { + return boolval($this->role_can_leave); + } + public function setCanLeave(bool $canLeave): self { + $this->role_can_leave = $canLeave ? 1 : 0; + return $this; + } + + // Provided just because, avoid using these for validations sake + public function getColourRaw(): ?int { + return $this->role_colour; + } + public function setColourRaw(?int $colour): self { + $this->role_colour = $colour; + return $this; + } + + public function getColour(): Colour { + if($this->colour === null || ($this->getColourRaw() ?? 0x40000000) !== $this->colour->getRaw()) + $this->colour = new Colour($this->role_colour ?? 0x40000000); + return $this->colour; + } + public function setColour(Colour $colour): self { + $this->role_colour = $colour->getInherit() ? null : $colour->getRaw(); + $this->colour = $this->colour; + return $this; + } + + public function getCreatedTime(): int { + return $this->role_created === null ? -1 : $this->role_created; + } + + public function getUserCount(): int { + if($this->userCount < 0) + $this->userCount = UserRoleRelation::countUsers($this); + return $this->userCount; + } + + public function isDefault(): bool { + return $this->getId() === self::DEFAULT; + } + + public function hasAuthorityOver(HasRankInterface $other): bool { + if($other instanceof User && $other->isSuper()) + return false; + return $this->getRank() > $other->getRank(); + } + + public function save(): void { + $isInsert = $this->role_id < 1; + if($isInsert) { + $set = DB::prepare( + 'INSERT INTO `' . DB::PREFIX . self::TABLE . '` (`role_hierarchy`, `role_name`, `role_title`, `role_description`, `role_hidden`, `role_can_leave`, `role_colour`)' + . ' VALUES (:rank, :name, :title, :desc, :hide, :can_leave, :colour)' + ); + } else { + $set = DB::prepare( + 'UPDATE `' . DB::PREFIX . self::TABLE . '` SET' + . ' `role_hierarchy` = :rank, `role_name` = :name, `role_title` = :title,' + . ' `role_description` = :desc, `role_hidden` = :hide, `role_can_leave` = :can_leave, `role_colour` = :colour' + . ' WHERE `role_id` = :role' + )->bind('role', $this->role_id); + } + + $set->bind('rank', $this->role_hierarchy) + ->bind('name', $this->role_name) + ->bind('title', $this->role_title) + ->bind('desc', $this->role_description) + ->bind('hide', $this->role_hidden) + ->bind('can_leave', $this->role_can_leave) + ->bind('colour', $this->role_colour); + + if($isInsert) { + $this->role_id = $set->executeGetId(); + $this->role_created = time(); + } else $set->execute(); + } + + private static function countQueryBase(): string { + return sprintf(self::QUERY_SELECT, 'COUNT(*)'); + } + public static function countAll(bool $showHidden = false): int { + return (int)DB::prepare( + self::countQueryBase() + . ($showHidden ? '' : ' WHERE `role_hidden` = 0') + )->fetchColumn(); + } + + private static function memoizer() { + static $memoizer = null; + if($memoizer === null) + $memoizer = new Memoizer; + return $memoizer; + } + + private static function byQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf(self::SELECT, self::TABLE)); + } + public static function byId(int $roleId): self { + return self::memoizer()->find($roleId, function() use ($roleId) { + $object = DB::prepare( + self::byQueryBase() . ' WHERE `role_id` = :role' + ) ->bind('role', $roleId) + ->fetchObject(self::class); + if(!$object) + throw new UserRoleNotFoundException; + return $object; + }); + } + public static function byDefault(): self { + return self::byId(self::DEFAULT); + } + public static function all(bool $showHidden = false, ?Pagination $pagination = null): array { + $query = self::byQueryBase(); + + if(!$showHidden) + $query .= ' WHERE `role_hidden` = 0'; + + if($pagination !== null) + $query .= ' LIMIT :range OFFSET :offset'; + + $getObjects = DB::prepare($query); + + if($pagination !== null) + $getObjects->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getObjects->fetchObjects(self::class); + } + + // to satisfy the fucked behaviour array_diff has + public function __toString() { + return md5($this->getId() . '#' . $this->getName()); + } + + // Twig shim for the roles list on the members page, don't use this class as an array normally. + public function offsetExists($offset): bool { + return $offset === 'name' || $offset === 'id'; + } + public function offsetGet($offset): mixed { + return $this->{'get' . ucfirst($offset)}(); + } + public function offsetSet($offset, $value): void {} + public function offsetUnset($offset): void {} +} diff --git a/src/Users/UserRoleRelation.php b/src/Users/UserRoleRelation.php new file mode 100644 index 0000000..0946d97 --- /dev/null +++ b/src/Users/UserRoleRelation.php @@ -0,0 +1,88 @@ +user_id < 1 ? -1 : $this->user_id; + } + public function getUser(): User { + if($this->user === null) + $this->user = User::byId($this->getUserId()); + return $this->user; + } + + public function getRoleId(): int { + return $this->role_id < 1 ? -1 : $this->role_id; + } + public function getRole(): UserRole { + if($this->role === null) + $this->role = UserRole::byId($this->getRoleId()); + return $this->role; + } + + public function delete(): void { + self::destroy($this->getUser(), $this->getRole()); + } + + public static function destroy(User $user, UserRole $role): void { + DB::prepare('DELETE FROM `' . DB::PREFIX . self::TABLE . '` WHERE `user_id` = :user AND `role_id` = :role') + ->bind('user', $user->getId()) + ->bind('role', $role->getId()) + ->execute(); + } + + public static function purge(User $user): void { + DB::prepare('DELETE FROM `' . DB::PREFIX . self::TABLE . '` WHERE `user_id` = :user') + ->bind('user', $user->getId()) + ->execute(); + } + + public static function create(User $user, UserRole $role): self { + $create = DB::prepare( + 'REPLACE INTO `' . DB::PREFIX . self::TABLE . '` (`user_id`, `role_id`)' + . ' VALUES (:user, :role)' + ) ->bind('user', $user->getId()) + ->bind('role', $role->getId()) + ->execute(); + + // data is predictable, just create a "fake" + $object = new UserRoleRelation; + $object->user = $user; + $object->user_id = $user->getId(); + $object->role = $role; + $object->role_id = $role->getId(); + return $object; + } + + private static function countQueryBase(): string { + return sprintf(self::QUERY_SELECT, 'COUNT(*)'); + } + public static function countUsers(UserRole $role): int { + return (int)DB::prepare(self::countQueryBase() . ' WHERE `role_id` = :role') + ->bind('role', $role->getId()) + ->fetchColumn(); + } + + private static function byQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf(self::SELECT, self::TABLE)); + } + public static function byUser(User $user): array { + return DB::prepare(self::byQueryBase() . ' WHERE `user_id` = :user') + ->bind('user', $user->getId()) + ->fetchObjects(self::class); + } +} diff --git a/src/Users/UserSession.php b/src/Users/UserSession.php new file mode 100644 index 0000000..f6416f4 --- /dev/null +++ b/src/Users/UserSession.php @@ -0,0 +1,256 @@ +session_id < 1 ? -1 : $this->session_id; + } + + public function getUserId(): int { + return $this->user_id < 1 ? -1 : $this->user_id; + } + public function getUser(): User { + if($this->user === null) + $this->user = User::byId($this->getUserId()); + return $this->user; + } + + public function getToken(): string { + return $this->session_key; + } + + public function getInitialRemoteAddress(): string { + return $this->session_ip; + } + + public function getLastRemoteAddress(): string { + return $this->session_ip_last ?? ''; + } + public function hasLastRemoteAddress(): bool { + return !empty($this->session_ip_last); + } + public function setLastRemoteAddress(string $remoteAddr): self { + $this->session_ip_last = $remoteAddr; + return $this; + } + + public function getUserAgent(): string { + return $this->session_user_agent; + } + public function getUserAgentInfo(): UserAgentParser { + if($this->uaInfo === null) + $this->uaInfo = new UserAgentParser($this->getUserAgent()); + return $this->uaInfo; + } + + public function getCountry(): string { + return $this->session_country; + } + public function getCountryName(): string { + return get_country_name($this->getCountry()); + } + + public function getCreatedTime(): int { + return $this->session_created === null ? -1 : $this->session_created; + } + + public function getActiveTime(): int { + return $this->session_active === null ? -1 : $this->session_active; + } + public function hasActiveTime(): bool { + return $this->session_active !== null; + } + public function setActiveTime(int $timestamp): self { + if($timestamp > $this->session_active) + $this->session_active = $timestamp; + return $this; + } + + public function getExpiresTime(): int { + return $this->session_expires === null ? -1 : $this->session_expires; + } + public function setExpiresTime(int $timestamp): self { + $this->session_expires = $timestamp; + return $this; + } + public function hasExpired(): bool { + return $this->getExpiresTime() <= time(); + } + + public function shouldBumpExpire(): bool { + return boolval($this->session_expires_bump); + } + + public function bump(bool $callUpdate = true, ?int $timestamp = null, ?string $remoteAddr = null): void { + $timestamp = $timestamp ?? time(); + $remoteAddr = $remoteAddr ?? IPAddress::remote(); + + $this->setActiveTime($timestamp) + ->setLastRemoteAddress($remoteAddr); + + if($this->shouldBumpExpire()) + $this->setExpiresTime($timestamp + self::LIFETIME); + + if($callUpdate) + $this->update(); + } + + public function delete(): void { + DB::prepare('DELETE FROM `' . DB::PREFIX . self::TABLE . '` WHERE `session_id` = :session') + ->bind('session', $this->getId()) + ->execute(); + } + + public static function purgeUser(User $user): void { + DB::prepare('DELETE FROM `' . DB::PREFIX . self::TABLE . '` WHERE `user_id` = :user') + ->bind('user', $user->getId()) + ->execute(); + } + + public function setCurrent(): void { + self::$localSession = $this; + } + public static function unsetCurrent(): void { + self::$localSession = null; + } + public static function getCurrent(): ?self { + return self::$localSession; + } + public static function hasCurrent(): bool { + return self::$localSession !== null; + } + + public static function generateToken(): string { + return bin2hex(random_bytes(self::TOKEN_SIZE / 2)); + } + + public function update(): void { + DB::prepare( + 'UPDATE `' . DB::PREFIX . self::TABLE . '`' + . ' SET `session_active` = FROM_UNIXTIME(:active), `session_ip_last` = INET6_ATON(:remote_addr), `session_expires` = FROM_UNIXTIME(:expires)' + . ' WHERE `session_id` = :session' + ) ->bind('active', $this->session_active) + ->bind('remote_addr', $this->session_ip_last) + ->bind('expires', $this->session_expires) + ->bind('session', $this->session_id) + ->execute(); + } + + public static function create(User $user, ?string $remoteAddr = null, ?string $userAgent = null, ?string $token = null): self { + $remoteAddr = $remoteAddr ?? IPAddress::remote(); + $userAgent = $userAgent ?? filter_input(INPUT_SERVER, 'HTTP_USER_AGENT') ?? ''; + $token = $token ?? self::generateToken(); + + $sessionId = DB::prepare( + 'INSERT INTO `' . DB::PREFIX . self::TABLE . '`' + . ' (`user_id`, `session_ip`, `session_country`, `session_user_agent`, `session_key`, `session_created`, `session_expires`)' + . ' VALUES (:user, INET6_ATON(:remote_addr), :country, :user_agent, :token, NOW(), NOW() + INTERVAL :expires SECOND)' + ) ->bind('user', $user->getId()) + ->bind('remote_addr', $remoteAddr) + ->bind('country', IPAddress::country($remoteAddr)) + ->bind('user_agent', $userAgent) + ->bind('token', $token) + ->bind('expires', self::LIFETIME) + ->executeGetId(); + + if($sessionId < 1) + throw new UserSessionCreationFailedException; + + return self::byId($sessionId); + } + + private static function countQueryBase(): string { + return sprintf(self::QUERY_SELECT, 'COUNT(*)'); + } + public static function countAll(?User $user = null): int { + $getCount = DB::prepare( + self::countQueryBase() + . ($user === null ? '' : ' WHERE `user_id` = :user') + ); + if($user !== null) + $getCount->bind('user', $user->getId()); + return (int)$getCount->fetchColumn(); + } + + private static function byQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf(self::SELECT, self::TABLE)); + } + public static function byId(int $sessionId): self { + $session = DB::prepare(self::byQueryBase() . ' WHERE `session_id` = :session_id') + ->bind('session_id', $sessionId) + ->fetchObject(self::class); + + if(!$session) + throw new UserSessionNotFoundException; + + return $session; + } + public static function byToken(string $token): self { + $session = DB::prepare(self::byQueryBase() . ' WHERE `session_key` = :token') + ->bind('token', $token) + ->fetchObject(self::class); + + if(!$session) + throw new UserSessionNotFoundException; + + return $session; + } + public static function all(?Pagination $pagination = null, ?User $user = null): array { + $sessionsQuery = self::byQueryBase() + . ($user === null ? '' : ' WHERE `user_id` = :user') + . ' ORDER BY `session_created` DESC'; + + if($pagination !== null) + $sessionsQuery .= ' LIMIT :range OFFSET :offset'; + + $getSessions = DB::prepare($sessionsQuery); + + if($user !== null) + $getSessions->bind('user', $user->getId()); + + if($pagination !== null) + $getSessions->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getSessions->fetchObjects(self::class); + } +} diff --git a/src/Users/UserWarning.php b/src/Users/UserWarning.php new file mode 100644 index 0000000..95836cc --- /dev/null +++ b/src/Users/UserWarning.php @@ -0,0 +1,305 @@ +warning_id; + } + + public function getUserId(): int { + return $this->user_id; + } + public function getUser(): User { + if($this->user === null) + $this->user = User::byId($this->getUserId()); + return $this->user; + } + + public function getUserRemoteAddress(): string { + return $this->user_ip; + } + + public function getIssuerId(): int { + return $this->issuer_id; + } + public function getIssuer(): User { + if($this->issuer === null) + $this->issuer = User::byId($this->getIssuerId()); + return $this->issuer; + } + + public function getIssuerRemoteAddress(): string { + return $this->issuer_ip; + } + + public function getCreatedTime(): int { + return $this->warning_created === null ? -1 : $this->warning_created; + } + + public function getExpirationTime(): int { + return $this->warning_duration === null ? -1 : $this->warning_duration; + } + public function hasExpired(): bool { + return $this->hasDuration() && ($this->getExpirationTime() > 0 && $this->getExpirationTime() < time()); + } + + public function hasDuration(): bool { + return in_array($this->getType(), self::HAS_DURATION); + } + public function getDuration(): int { + return max(-1, $this->getExpirationTime() - $this->getCreatedTime()); + } + + private const DURATION_DIVS = [ + 31536000 => 'year', + 2592000 => 'month', + 604800 => 'week', + 86400 => 'day', + 3600 => 'hour', + 60 => 'minute', + 1 => 'second', + ]; + + public function getDurationString(): string { + $duration = $this->getDuration(); + if($duration < 1) + return 'permanent'; + + foreach(self::DURATION_DIVS as $span => $name) { + $display = floor($duration / $span); + if($display > 0) + return number_format($display) . ' ' . $name . ($display == 1 ? '' : 's'); + } + + return 'an amount of time'; + } + + public function isPermanent(): bool { + return $this->hasDuration() && $this->getDuration() < 0; + } + + public function getType(): int { return $this->warning_type; } + public function isNote(): bool { return $this->getType() === self::TYPE_NOTE; } + public function isWarning(): bool { return $this->getType() === self::TYPE_WARN; } + public function isSilence(): bool { return $this->getType() === self::TYPE_MUTE; } + public function isBan(): bool { return $this->getType() === self::TYPE_BAHN; } + + public function isVisibleToUser(): bool { + return in_array($this->getType(), self::VISIBLE_TO_USER); + } + public function isVisibleToPublic(): bool { + return in_array($this->getType(), self::VISIBLE_TO_PUBLIC); + } + + public function getPublicNote(): string { + return $this->warning_note; + } + + public function getPrivateNote(): string { + return $this->warning_note_private ?? ''; + } + public function hasPrivateNote(): bool { + return !empty($this->warning_note_private); + } + + public function delete(): void { + DB::prepare('DELETE FROM `' . DB::PREFIX . self::TABLE . '` WHERE `warning_id` = :warning') + ->bind('warning', $this->warning_id) + ->execute(); + } + + public static function create(User $user, User $issuer, int $type, int $duration, string $publicNote, ?string $privateNote = null): self { + if(!in_array($type, self::TYPES)) + throw new InvalidArgumentException('Type was invalid.'); + + if(!in_array($type, self::HAS_DURATION)) + $duration = 0; + else { + if($duration === 0) + throw new InvalidArgumentException('Duration must be non-zero.'); + if($duration < 0) + $duration = -1; + } + + $warningId = DB::prepare( + 'INSERT INTO `' . DB::PREFIX . self::TABLE . '` (`user_id`, `user_ip`, `issuer_id`, `issuer_ip`, `warning_created`, `warning_duration`, `warning_type`, `warning_note`, `warning_note_private`)' + . ' VALUES (:user, INET6_ATON(:user_addr), :issuer, INET6_ATON(:issuer_addr), NOW(), IF(:set_duration, NOW() + INTERVAL :duration SECOND, NULL), :type, :public_note, :private_note)' + ) ->bind('user', $user->getId()) + ->bind('user_addr', $user->getLastRemoteAddress()) + ->bind('issuer', $issuer->getId()) + ->bind('issuer_addr', $issuer->getLastRemoteAddress()) + ->bind('set_duration', $duration > 0 ? 1 : 0) + ->bind('duration', $duration) + ->bind('type', $type) + ->bind('public_note', $publicNote) + ->bind('private_note', $privateNote) + ->executeGetId(); + + if($warningId < 1) + throw new UserWarningCreationFailedException; + + return self::byId($warningId); + } + + private static function countQueryBase(): string { + return sprintf(self::QUERY_SELECT, 'COUNT(*)'); + } + public static function countByRemoteAddress(?string $address = null, bool $withDuration = true): int { + $address = $address ?? IPAddress::remote(); + return (int)DB::prepare( + self::countQueryBase() + . ' WHERE `user_ip` = INET6_ATON(:address)' + . ' AND `warning_duration` >= NOW()' + . ($withDuration ? ' AND `warning_type` IN (' . implode(',', self::HAS_DURATION) . ')' : '') + )->bind('address', $address)->fetchColumn(); + } + public static function countAll(?User $user = null): int { + $getCount = DB::prepare(self::countQueryBase() . ($user === null ? '' : ' WHERE `user_id` = :user')); + if($user !== null) + $getCount->bind('user', $user->getId()); + return (int)$getCount->fetchColumn(); + } + + private static function byQueryBase(): string { + return sprintf(self::QUERY_SELECT, sprintf(self::SELECT, self::TABLE)); + } + public static function byId(int $warningId): self { + $object = DB::prepare( + self::byQueryBase() . ' WHERE `warning_id` = :warning' + ) ->bind('warning', $warningId) + ->fetchObject(self::class); + if(!$object) + throw new UserWarningNotFoundException; + return $object; + } + public static function byUserActive(User $user): ?self { + return self::byUserIdActive($user->getId()); + } + public static function byUserIdActive(int $userId): ?self { + if($userId < 1) + return null; + + return DB::prepare( + self::byQueryBase() + . ' WHERE `user_id` = :user' + . ' AND `warning_type` IN (' . implode(',', self::HAS_DURATION) . ')' + . ' AND (`warning_duration` IS NULL OR `warning_duration` >= NOW())' + . ' ORDER BY `warning_type` DESC, `warning_duration` DESC' + ) ->bind('user', $userId) + ->fetchObject(self::class); + } + public static function byRemoteAddressActive(string $ipAddress): ?self { + return DB::prepare( + self::byQueryBase() + . ' WHERE `user_ip` = INET6_ATON(:address)' + . ' AND `warning_type` IN (' . implode(',', self::HAS_DURATION) . ')' + . ' AND (`warning_duration` IS NULL OR `warning_duration` >= NOW())' + . ' ORDER BY `warning_type` DESC, `warning_duration` DESC' + ) ->bind('address', $ipAddress) + ->fetchObject(self::class); + } + public static function byProfile(User $user, ?User $viewer = null): array { + if($viewer === null) + return []; + + $types = self::VISIBLE_TO_PUBLIC; + if(perms_check_user(MSZ_PERMS_USER, $viewer->getId(), MSZ_PERM_USER_MANAGE_WARNINGS)) + $types = self::VISIBLE_TO_STAFF; + elseif($user->getId() === $viewer->getId()) + $types = self::VISIBLE_TO_USER; + + $getObjects = DB::prepare( + self::byQueryBase() + . ' WHERE `user_id` = :user' + . ' AND `warning_type` IN (' . implode(',', $types) . ')' + . ' AND (`warning_type` = 0 OR `warning_created` >= NOW() - INTERVAL ' . self::PROFILE_BACKLOG . ' DAY OR (`warning_duration` IS NOT NULL AND `warning_duration` >= NOW()))' + . ' ORDER BY `warning_created` DESC' + ); + + $getObjects->bind('user', $user->getId()); + + return $getObjects->fetchObjects(self::class); + } + public static function byActive(): array { + return DB::prepare( + self::byQueryBase() + . ' WHERE `warning_type` IN (' . implode(',', self::HAS_DURATION) . ')' + . ' AND (`warning_duration` IS NULL OR `warning_duration` >= NOW())' + . ' ORDER BY `warning_type` DESC, `warning_duration` DESC' + )->fetchObjects(self::class); + } + public static function all(?User $user = null, ?Pagination $pagination = null): array { + $query = self::byQueryBase() + . ($user === null ? '' : ' WHERE `user_id` = :user') + . ' ORDER BY `warning_created` DESC'; + + if($pagination !== null) + $query .= ' LIMIT :range OFFSET :offset'; + + $getObjects = DB::prepare($query); + + if($user !== null) + $getObjects->bind('user', $user->getId()); + + if($pagination !== null) + $getObjects->bind('range', $pagination->getRange()) + ->bind('offset', $pagination->getOffset()); + + return $getObjects->fetchObjects(self::class); + } +} diff --git a/src/Users/Users.php b/src/Users/Users.php new file mode 100644 index 0000000..7a1099e --- /dev/null +++ b/src/Users/Users.php @@ -0,0 +1,43 @@ +db = $db; + } + + public function getById(string $userId): User { + // + } + + public function getByName(string $userName): User { + // + } + + public function getByMailAddress(string $mailAddress): User { + // + } + + public function getByNameOrMailAddress(string $userNameOrMailAddress): User { + // + } + + public function getByIdOrName(string $userIdOrName): User { + // + } + + public function getByBirthDate(DateTimeImmutable $dateTime): array { + // + } + + public function getByAll(bool $includeDeleted = false, ?Pagination $pagination = null): array { + // + } +} diff --git a/src/Users/UsersException.php b/src/Users/UsersException.php new file mode 100644 index 0000000..575038f --- /dev/null +++ b/src/Users/UsersException.php @@ -0,0 +1,6 @@ + 0; + $going_mid = ($direction & self::DIR_MID) > 0; + $going_down = ($direction & self::DIR_DOWN) > 0; + + $str = ''; + + for($i = 0; $i < $length; $i++) { + $char = $text[$i]; + + if(self::isZalgoChar($char)) + continue; + + $str .= $char; + $num_up = $num_mid = $num_down = 0; + + switch($mode) { + case self::MODE_MINI: + $num_up = mt_rand(0, 8); + $num_mid = mt_rand(0, 2); + $num_down = mt_rand(0, 8); + break; + + case self::MODE_NORMAL: + $num_up = mt_rand(0, 16) / 2 + 1; + $num_mid = mt_rand(0, 6) / 2; + $num_down = mt_rand(0, 8) / 2 + 1; + break; + + case self::MODE_MAX: + $num_up = mt_rand(0, 64) / 4 + 3; + $num_mid = mt_rand(0, 16) / 4 + 1; + $num_down = mt_rand(0, 64) / 4 + 3; + break; + } + + if($going_up) + $str .= self::getString(self::CHARS_UP, $num_up); + + if($going_mid) + $str .= self::getString(self::CHARS_MIDDLE, $num_mid); + + if($going_down) + $str .= self::getString(self::CHARS_DOWN, $num_down); + } + + return $str; + } +} diff --git a/src/manage.php b/src/manage.php new file mode 100644 index 0000000..d7e51da --- /dev/null +++ b/src/manage.php @@ -0,0 +1,384 @@ + [ + 'Overview' => url('manage-general-overview'), + ], + ]; + + if(perms_check_user(MSZ_PERMS_GENERAL, $userId, MSZ_PERM_GENERAL_VIEW_LOGS)) + $menu['General']['Logs'] = url('manage-general-logs'); + if(perms_check_user(MSZ_PERMS_GENERAL, $userId, MSZ_PERM_GENERAL_MANAGE_EMOTES)) + $menu['General']['Emoticons'] = url('manage-general-emoticons'); + if(perms_check_user(MSZ_PERMS_GENERAL, $userId, MSZ_PERM_GENERAL_MANAGE_CONFIG)) + $menu['General']['Settings'] = url('manage-general-settings'); + if(perms_check_user(MSZ_PERMS_GENERAL, $userId, MSZ_PERM_GENERAL_MANAGE_BLACKLIST)) + $menu['General']['IP Blacklist'] = url('manage-general-blacklist'); + + if(perms_check_user(MSZ_PERMS_USER, $userId, MSZ_PERM_USER_MANAGE_USERS)) + $menu['Users & Roles']['Users'] = url('manage-users'); + if(perms_check_user(MSZ_PERMS_USER, $userId, MSZ_PERM_USER_MANAGE_ROLES)) + $menu['Users & Roles']['Roles'] = url('manage-roles'); + //if(perms_check_user(MSZ_PERMS_USER, $userId, MSZ_PERM_USER_MANAGE_REPORTS)) + // $menu['Users & Roles']['Reports'] = url('manage-users-reports'); + if(perms_check_user(MSZ_PERMS_USER, $userId, MSZ_PERM_USER_MANAGE_WARNINGS)) + $menu['Users & Roles']['Warnings'] = url('manage-users-warnings'); + + if(perms_check_user(MSZ_PERMS_NEWS, $userId, MSZ_PERM_NEWS_MANAGE_POSTS)) + $menu['News']['Posts'] = url('manage-news-posts'); + if(perms_check_user(MSZ_PERMS_NEWS, $userId, MSZ_PERM_NEWS_MANAGE_CATEGORIES)) + $menu['News']['Categories'] = url('manage-news-categories'); + + if(perms_check_user(MSZ_PERMS_FORUM, $userId, MSZ_PERM_FORUM_MANAGE_FORUMS)) + $menu['Forum']['Categories'] = url('manage-forum-categories'); + + if(perms_check_user(MSZ_PERMS_CHANGELOG, $userId, MSZ_PERM_CHANGELOG_MANAGE_CHANGES)) + $menu['Changelog']['Changes'] = url('manage-changelog-changes'); + if(perms_check_user(MSZ_PERMS_CHANGELOG, $userId, MSZ_PERM_CHANGELOG_MANAGE_TAGS)) + $menu['Changelog']['Tags'] = url('manage-changelog-tags'); + + return $menu; +} + +define('MSZ_MANAGE_PERM_YES', 'yes'); +define('MSZ_MANAGE_PERM_NO', 'no'); +define('MSZ_MANAGE_PERM_NEVER', 'never'); + +function manage_perms_value(int $perm, int $allow, int $deny): string { + if(perms_check($deny, $perm)) + return MSZ_MANAGE_PERM_NEVER; + if(perms_check($allow, $perm)) + return MSZ_MANAGE_PERM_YES; + return MSZ_MANAGE_PERM_NO; +} + +function manage_perms_apply(array $list, array $post, ?array $raw = null): ?array { + $perms = $raw !== null ? $raw : perms_create(); + + foreach($list as $section) { + if(empty($post[$section['section']]) || !is_array($post[$section['section']])) + continue; + + $allowKey = perms_get_key($section['section'], MSZ_PERMS_ALLOW); + $denyKey = perms_get_key($section['section'], MSZ_PERMS_DENY); + + foreach($section['perms'] as $perm) { + if(empty($post[$section['section']][$perm['section']]['value'])) + continue; + + switch($post[$section['section']][$perm['section']]['value']) { + case MSZ_MANAGE_PERM_YES: + $perms[$allowKey] |= $perm['perm']; + $perms[$denyKey] &= ~$perm['perm']; + break; + + case MSZ_MANAGE_PERM_NEVER: + $perms[$allowKey] &= ~$perm['perm']; + $perms[$denyKey] |= $perm['perm']; + break; + + case MSZ_MANAGE_PERM_NO: + default: + $perms[$allowKey] &= ~$perm['perm']; + $perms[$denyKey] &= ~$perm['perm']; + break; + } + } + } + + $returnNothing = 0; + foreach($perms as $perm) + $returnNothing |= $perm; + + return $returnNothing === 0 ? null : $perms; +} + +function manage_perms_calculate(array $rawPerms, array $perms): array { + for($i = 0; $i < count($perms); $i++) { + $section = $perms[$i]['section']; + $allowKey = perms_get_key($section, MSZ_PERMS_ALLOW); + $denyKey = perms_get_key($section, MSZ_PERMS_DENY); + + for($j = 0; $j < count($perms[$i]['perms']); $j++) { + $permission = $perms[$i]['perms'][$j]['perm']; + $perms[$i]['perms'][$j]['value'] = manage_perms_value($permission, $rawPerms[$allowKey], $rawPerms[$denyKey]); + } + } + + return $perms; +} + +function manage_perms_list(array $rawPerms): array { + return manage_perms_calculate($rawPerms, [ + [ + 'section' => MSZ_PERMS_GENERAL, + 'title' => 'General', + 'perms' => [ + [ + 'section' => 'can-manage', + 'title' => 'Can access the management panel.', + 'perm' => MSZ_PERM_GENERAL_CAN_MANAGE, + ], + [ + 'section' => 'view-logs', + 'title' => 'Can view audit logs.', + 'perm' => MSZ_PERM_GENERAL_VIEW_LOGS, + ], + [ + 'section' => 'manage-emotes', + 'title' => 'Can manage emoticons.', + 'perm' => MSZ_PERM_GENERAL_MANAGE_EMOTES, + ], + [ + 'section' => 'manage-settings', + 'title' => 'Can manage general Misuzu settings.', + 'perm' => MSZ_PERM_GENERAL_MANAGE_CONFIG, + ], + [ + 'section' => 'tester', + 'title' => 'Can use experimental features.', + 'perm' => MSZ_PERM_GENERAL_IS_TESTER, + ], + [ + 'section' => 'manage-blacklist', + 'title' => 'Can manage blacklistings.', + 'perm' => MSZ_PERM_GENERAL_MANAGE_BLACKLIST, + ], + ], + ], + [ + 'section' => MSZ_PERMS_USER, + 'title' => 'User', + 'perms' => [ + [ + 'section' => 'edit-profile', + 'title' => 'Can edit own profile.', + 'perm' => MSZ_PERM_USER_EDIT_PROFILE, + ], + [ + 'section' => 'change-avatar', + 'title' => 'Can change own avatar.', + 'perm' => MSZ_PERM_USER_CHANGE_AVATAR, + ], + [ + 'section' => 'change-background', + 'title' => 'Can change own background.', + 'perm' => MSZ_PERM_USER_CHANGE_BACKGROUND, + ], + [ + 'section' => 'edit-about', + 'title' => 'Can change own about section.', + 'perm' => MSZ_PERM_USER_EDIT_ABOUT, + ], + [ + 'section' => 'edit-birthdate', + 'title' => 'Can change own birthdate.', + 'perm' => MSZ_PERM_USER_EDIT_BIRTHDATE, + ], + [ + 'section' => 'edit-signature', + 'title' => 'Can change own signature.', + 'perm' => MSZ_PERM_USER_EDIT_SIGNATURE, + ], + [ + 'section' => 'manage-users', + 'title' => 'Can manage other users.', + 'perm' => MSZ_PERM_USER_MANAGE_USERS, + ], + [ + 'section' => 'manage-roles', + 'title' => 'Can manage roles.', + 'perm' => MSZ_PERM_USER_MANAGE_ROLES, + ], + [ + 'section' => 'manage-perms', + 'title' => 'Can manage permissions.', + 'perm' => MSZ_PERM_USER_MANAGE_PERMS, + ], + [ + 'section' => 'manage-reports', + 'title' => 'Can handle reports.', + 'perm' => MSZ_PERM_USER_MANAGE_REPORTS, + ], + [ + 'section' => 'manage-warnings', + 'title' => 'Can manage warnings, silences and bans.', + 'perm' => MSZ_PERM_USER_MANAGE_WARNINGS, + ], + ], + ], + [ + 'section' => MSZ_PERMS_NEWS, + 'title' => 'News', + 'perms' => [ + [ + 'section' => 'manage-posts', + 'title' => 'Can manage posts.', + 'perm' => MSZ_PERM_NEWS_MANAGE_POSTS, + ], + [ + 'section' => 'manage-cats', + 'title' => 'Can manage catagories.', + 'perm' => MSZ_PERM_NEWS_MANAGE_CATEGORIES, + ], + ], + ], + [ + 'section' => MSZ_PERMS_FORUM, + 'title' => 'Forum', + 'perms' => [ + [ + 'section' => 'manage-forums', + 'title' => 'Can manage forum sections.', + 'perm' => MSZ_PERM_FORUM_MANAGE_FORUMS, + ], + [ + 'section' => 'view-leaderboard', + 'title' => 'Can view the forum leaderboard live.', + 'perm' => MSZ_PERM_FORUM_VIEW_LEADERBOARD, + ], + ], + ], + [ + 'section' => MSZ_PERMS_COMMENTS, + 'title' => 'Comments', + 'perms' => [ + [ + 'section' => 'create', + 'title' => 'Can post comments.', + 'perm' => MSZ_PERM_COMMENTS_CREATE, + ], + [ + 'section' => 'delete-own', + 'title' => 'Can delete own comments.', + 'perm' => MSZ_PERM_COMMENTS_DELETE_OWN, + ], + [ + 'section' => 'delete-any', + 'title' => 'Can delete anyone\'s comments.', + 'perm' => MSZ_PERM_COMMENTS_DELETE_ANY, + ], + [ + 'section' => 'pin', + 'title' => 'Can pin comments.', + 'perm' => MSZ_PERM_COMMENTS_PIN, + ], + [ + 'section' => 'lock', + 'title' => 'Can lock comment threads.', + 'perm' => MSZ_PERM_COMMENTS_LOCK, + ], + [ + 'section' => 'vote', + 'title' => 'Can like or dislike comments.', + 'perm' => MSZ_PERM_COMMENTS_VOTE, + ], + ], + ], + [ + 'section' => MSZ_PERMS_CHANGELOG, + 'title' => 'Changelog', + 'perms' => [ + [ + 'section' => 'manage-changes', + 'title' => 'Can manage changes.', + 'perm' => MSZ_PERM_CHANGELOG_MANAGE_CHANGES, + ], + [ + 'section' => 'manage-tags', + 'title' => 'Can manage tags.', + 'perm' => MSZ_PERM_CHANGELOG_MANAGE_TAGS, + ], + ], + ], + ]); +} + +function manage_forum_perms_list(array $rawPerms): array { + return manage_perms_calculate($rawPerms, [ + [ + 'section' => MSZ_FORUM_PERMS_GENERAL, + 'title' => 'Forum', + 'perms' => [ + [ + 'section' => 'can-list', + 'title' => 'Can see the forum listed, but not access it.', + 'perm' => MSZ_FORUM_PERM_LIST_FORUM, + ], + [ + 'section' => 'can-view', + 'title' => 'Can view and access the forum.', + 'perm' => MSZ_FORUM_PERM_VIEW_FORUM, + ], + [ + 'section' => 'can-create-topic', + 'title' => 'Can create topics.', + 'perm' => MSZ_FORUM_PERM_CREATE_TOPIC, + ], + [ + 'section' => 'can-move-topic', + 'title' => 'Can move topics between forums.', + 'perm' => MSZ_FORUM_PERM_MOVE_TOPIC, + ], + [ + 'section' => 'can-lock-topic', + 'title' => 'Can lock topics.', + 'perm' => MSZ_FORUM_PERM_LOCK_TOPIC, + ], + [ + 'section' => 'can-sticky-topic', + 'title' => 'Can make topics sticky.', + 'perm' => MSZ_FORUM_PERM_STICKY_TOPIC, + ], + [ + 'section' => 'can-announce-topic', + 'title' => 'Can make topics announcements.', + 'perm' => MSZ_FORUM_PERM_ANNOUNCE_TOPIC, + ], + [ + 'section' => 'can-global-announce-topic', + 'title' => 'Can make topics global announcements.', + 'perm' => MSZ_FORUM_PERM_GLOBAL_ANNOUNCE_TOPIC, + ], + [ + 'section' => 'can-bump-topic', + 'title' => 'Can bump topics without posting a reply.', + 'perm' => MSZ_FORUM_PERM_BUMP_TOPIC, + ], + [ + 'section' => 'can-priority-vote', + 'title' => 'Can vote on topic priority.', + 'perm' => MSZ_FORUM_PERM_PRIORITY_VOTE, + ], + [ + 'section' => 'can-create-post', + 'title' => 'Can make posts (reply only, if create topic is disallowed).', + 'perm' => MSZ_FORUM_PERM_CREATE_POST, + ], + [ + 'section' => 'can-edit-post', + 'title' => 'Can edit their own posts.', + 'perm' => MSZ_FORUM_PERM_EDIT_POST, + ], + [ + 'section' => 'can-edit-any-post', + 'title' => 'Can edit any posts.', + 'perm' => MSZ_FORUM_PERM_EDIT_ANY_POST, + ], + [ + 'section' => 'can-delete-post', + 'title' => 'Can delete own posts.', + 'perm' => MSZ_FORUM_PERM_DELETE_POST, + ], + [ + 'section' => 'can-delete-any-post', + 'title' => 'Can delete any posts.', + 'perm' => MSZ_FORUM_PERM_DELETE_ANY_POST, + ], + ], + ], + ]); +} diff --git a/src/perms.php b/src/perms.php new file mode 100644 index 0000000..875a2c6 --- /dev/null +++ b/src/perms.php @@ -0,0 +1,258 @@ +bind('user_id_1', $user); + $getPerms->bind('user_id_2', $user); + + return $memo[$user] = $getPerms->fetch(); +} + +function perms_delete_user(int $user): bool { + if($user < 1) { + return false; + } + + $deletePermissions = \Misuzu\DB::prepare(' + DELETE FROM `msz_permissions` + WHERE `role_id` IS NULL + AND `user_id` = :user_id + '); + $deletePermissions->bind('user_id', $user); + return $deletePermissions->execute(); +} + +function perms_get_role(int $role): array { + if($role < 1) { + return perms_get_blank(); + } + + static $memo = []; + + if(array_key_exists($role, $memo)) { + return $memo[$role]; + } + + $getPerms = \Misuzu\DB::prepare(sprintf( + ' + SELECT %s + FROM `msz_permissions` + WHERE `role_id` = :role_id + AND `user_id` IS NULL + ', + perms_get_select() + )); + $getPerms->bind('role_id', $role); + + return $memo[$role] = $getPerms->fetch(); +} + +function perms_get_user_raw(int $user): array { + if($user < 1) { + return perms_create(); + } + + $getPerms = \Misuzu\DB::prepare(sprintf(' + SELECT `%s` + FROM `msz_permissions` + WHERE `user_id` = :user_id + AND `role_id` IS NULL + ', implode('`, `', perms_get_keys()))); + $getPerms->bind('user_id', $user); + $perms = $getPerms->fetch(); + + if(empty($perms)) { + return perms_create(); + } + + return $perms; +} + +function perms_set_user_raw(int $user, array $perms): bool { + if($user < 1) { + return false; + } + + $realPerms = perms_create(); + $permKeys = array_keys($realPerms); + + foreach($permKeys as $perm) { + $realPerms[$perm] = (int)($perms[$perm] ?? 0); + } + + $setPermissions = \Misuzu\DB::prepare(sprintf( + ' + REPLACE INTO `msz_permissions` + (`role_id`, `user_id`, `%s`) + VALUES + (NULL, :user_id, :%s) + ', + implode('`, `', $permKeys), + implode(', :', $permKeys) + )); + $setPermissions->bind('user_id', $user); + + foreach($realPerms as $key => $value) { + $setPermissions->bind($key, $value); + } + + return $setPermissions->execute(); +} + +function perms_get_role_raw(int $role): array { + if($role < 1) { + return perms_create(); + } + + $getPerms = \Misuzu\DB::prepare(sprintf(' + SELECT `%s` + FROM `msz_permissions` + WHERE `user_id` IS NULL + AND `role_id` = :role_id + ', implode('`, `', perms_get_keys()))); + $getPerms->bind('role_id', $role); + $perms = $getPerms->fetch(); + + if(empty($perms)) { + return perms_create(); + } + + return $perms; +} + +function perms_check(?int $perms, ?int $perm, bool $strict = false): bool { + $and = ($perms ?? 0) & ($perm ?? 0); + return $strict ? $and === $perm : $and > 0; +} + +function perms_check_user(string $prefix, ?int $userId, int $perm, bool $strict = false): bool { + return $userId > 0 && perms_check(perms_get_user($userId)[$prefix] ?? 0, $perm, $strict); +} + +function perms_check_bulk(int $perms, array $set, bool $strict = false): array { + foreach($set as $key => $perm) { + $set[$key] = perms_check($perms, $perm, $strict); + } + + return $set; +} + +function perms_check_user_bulk(string $prefix, ?int $userId, array $set, bool $strict = false): array { + $perms = perms_get_user($userId)[$prefix] ?? 0; + return perms_check_bulk($perms, $set, $strict); +} diff --git a/src/url.php b/src/url.php new file mode 100644 index 0000000..3247052 --- /dev/null +++ b/src/url.php @@ -0,0 +1,279 @@ + Path part of URL. +// [1] => Query part of URL. +// [2] => Fragment part of URL. +// +// text surrounded by < and > will be replaced accordingly to an array of variables supplied to the format function +// text surrounded by [ and ] will be replaced by the constant/define of that name +// text surrounded by { and } will be replaced by a CSRF token with the given text as its realm, this will have no effect in a sessionless environment +define('MSZ_URLS', [ + 'index' => ['/'], + 'info' => ['/info/'], + 'media-proxy' => ['/proxy.php/<hash>/<url>'], + + 'search-index' => ['/search.php'], + 'search-query' => ['/search.php', ['q' => '<query>']], + + 'auth-login' => ['/auth/login.php', ['username' => '<username>', 'redirect' => '<redirect>']], + 'auth-login-welcome' => ['/auth/login.php', ['welcome' => '1', 'username' => '<username>']], + 'auth-register' => ['/auth/register.php'], + 'auth-forgot' => ['/auth/password.php'], + 'auth-reset' => ['/auth/password.php', ['user' => '<user>']], + 'auth-logout' => ['/auth/logout.php', ['csrf' => '{csrf}']], + 'auth-resolve-user' => ['/auth/login.php', ['resolve' => '1', 'name' => '<username>']], + 'auth-two-factor' => ['/auth/twofactor.php', ['token' => '<token>']], + + 'changelog-index' => ['/changelog', ['date' => '<date>', 'user' => '<user>', 'tags' => '<tags>', 'p' => '<page>']], + 'changelog-feed-rss' => ['/changelog.rss'], + 'changelog-feed-atom' => ['/changelog.atom'], + 'changelog-change' => ['/changelog/change/<change>'], + 'changelog-change-comments' => ['/changelog/change/<change>', [], 'comments'], + + 'news-index' => ['/news', ['p' => '<page>']], + 'news-category' => ['/news/<category>', ['p' => '<page>']], + 'news-post' => ['/news/post/<post>'], + 'news-post-comments' => ['/news/post/<post>', [], 'comments'], + 'news-feed-rss' => ['/news.rss'], + 'news-category-feed-rss' => ['/news/<category>.rss'], + 'news-feed-atom' => ['/news.atom'], + 'news-category-feed-atom' => ['/news/<category>.atom'], + + 'forum-index' => ['/forum'], + 'forum-leaderboard' => ['/forum/leaderboard.php', ['id' => '<id>', 'mode' => '<mode>']], + 'forum-mark-global' => ['/forum/mark-as-read'], + 'forum-mark-single' => ['/forum/mark-as-read', ['forum' => '<forum>']], + 'forum-topic-new' => ['/forum/posting.php', ['f' => '<forum>']], + 'forum-reply-new' => ['/forum/posting.php', ['t' => '<topic>']], + 'forum-category' => ['/forum/forum.php', ['f' => '<forum>', 'p' => '<page>']], + 'forum-topic' => ['/forum/topic.php', ['t' => '<topic>', 'page' => '<page>']], + 'forum-topic-create' => ['/forum/posting.php', ['f' => '<forum>']], + 'forum-topic-bump' => ['/forum/topic.php', ['t' => '<topic>', 'm' => 'bump', 'csrf' => '{csrf}']], + 'forum-topic-lock' => ['/forum/topic.php', ['t' => '<topic>', 'm' => 'lock', 'csrf' => '{csrf}']], + 'forum-topic-unlock' => ['/forum/topic.php', ['t' => '<topic>', 'm' => 'unlock', 'csrf' => '{csrf}']], + 'forum-topic-delete' => ['/forum/topic.php', ['t' => '<topic>', 'm' => 'delete', 'csrf' => '{csrf}']], + 'forum-topic-restore' => ['/forum/topic.php', ['t' => '<topic>', 'm' => 'restore', 'csrf' => '{csrf}']], + 'forum-topic-nuke' => ['/forum/topic.php', ['t' => '<topic>', 'm' => 'nuke', 'csrf' => '{csrf}']], + 'forum-topic-priority' => ['/forum/topic-priority.php', ['t' => '<topic>', 'b' => '<bump>']], + 'forum-post' => ['/forum/topic.php', ['p' => '<post>'], '<post_fragment>'], + 'forum-post-create' => ['/forum/posting.php', ['t' => '<topic>']], + 'forum-post-delete' => ['/forum/post.php', ['p' => '<post>', 'm' => 'delete']], + 'forum-post-restore' => ['/forum/post.php', ['p' => '<post>', 'm' => 'restore']], + 'forum-post-nuke' => ['/forum/post.php', ['p' => '<post>', 'm' => 'nuke']], + 'forum-post-quote' => ['/forum/posting.php', ['q' => '<post>']], + 'forum-post-edit' => ['/forum/posting.php', ['p' => '<post>', 'm' => 'edit']], + 'forum-poll-vote' => ['/forum/poll.php'], + + 'user-list' => ['/members.php', ['r' => '<role>', 'ss' => '<sort>', 'sd' => '<direction>', 'p' => '<page>']], + + 'user-profile' => ['/profile.php', ['u' => '<user>']], + 'user-profile-forum-topics' => ['/profile.php', ['u' => '<user>', 'm' => 'forum-topics']], + 'user-profile-forum-posts' => ['/profile.php', ['u' => '<user>', 'm' => 'forum-posts']], + 'user-profile-edit' => ['/profile.php', ['u' => '<user>', 'edit' => '1']], + 'user-account-standing' => ['/profile.php', ['u' => '<user>'], 'account-standing'], + + 'user-avatar' => ['/assets/avatar/<user>', ['res' => '<res>']], + 'user-background' => ['/assets/profile-background/<user>'], + + 'settings-index' => ['/settings'], + 'settings-account' => ['/settings/account.php'], + 'settings-sessions' => ['/settings/sessions.php'], + 'settings-logs' => ['/settings/logs.php'], + 'settings-data' => ['/settings/data.php'], + + 'comment-create' => ['/comments.php', ['m' => 'create']], + 'comment-vote' => ['/comments.php', ['c' => '<comment>', 'csrf' => '{csrf}', 'm' => 'vote', 'v' => '<vote>']], + 'comment-delete' => ['/comments.php', ['c' => '<comment>', 'csrf' => '{csrf}', 'm' => 'delete']], + 'comment-restore' => ['/comments.php', ['c' => '<comment>', 'csrf' => '{csrf}', 'm' => 'restore']], + 'comment-pin' => ['/comments.php', ['c' => '<comment>', 'csrf' => '{csrf}', 'm' => 'pin']], + 'comment-unpin' => ['/comments.php', ['c' => '<comment>', 'csrf' => '{csrf}', 'm' => 'unpin']], + + 'manage-index' => ['/manage'], + + 'manage-general-overview' => ['/manage/general'], + 'manage-general-logs' => ['/manage/general/logs.php'], + 'manage-general-blacklist' => ['/manage/general/blacklist.php'], + + 'manage-general-emoticons' => ['/manage/general/emoticons.php'], + 'manage-general-emoticon' => ['/manage/general/emoticon.php', ['e' => '<emote>']], + 'manage-general-emoticon-order-up' => ['/manage/general/emoticons.php', ['emote' => '<emote>', 'order' => 'd', 'csrf' => '{token}']], + 'manage-general-emoticon-order-down'=> ['/manage/general/emoticons.php', ['emote' => '<emote>', 'order' => 'i', 'csrf' => '{token}']], + 'manage-general-emoticon-delete' => ['/manage/general/emoticons.php', ['emote' => '<emote>', 'delete' => '1', 'csrf' => '{token}']], + 'manage-general-emoticon-alias' => ['/manage/general/emoticons.php', ['emote' => '<emote>', 'alias' => '<string>', 'csrf' => '{token}']], + + 'manage-general-settings' => ['/manage/general/settings.php'], + 'manage-general-setting' => ['/manage/general/setting.php', ['name' => '<name>', 'type' => '<type>']], + 'manage-general-setting-delete' => ['/manage/general/setting-delete.php', ['name' => '<name>']], + + 'manage-forum-categories' => ['/manage/forum/index.php'], + 'manage-forum-category' => ['/manage/forum/category.php', ['f' => '<forum>']], + + 'manage-changelog-changes' => ['/manage/changelog'], + 'manage-changelog-change' => ['/manage/changelog/change.php', ['c' => '<change>']], + 'manage-changelog-tags' => ['/manage/changelog/tags.php'], + 'manage-changelog-tag' => ['/manage/changelog/tag.php', ['t' => '<tag>']], + + 'manage-news-categories' => ['/manage/news/categories.php'], + 'manage-news-category' => ['/manage/news/category.php', ['c' => '<category>']], + 'manage-news-posts' => ['/manage/news/posts.php'], + 'manage-news-post' => ['/manage/news/post.php', ['p' => '<post>']], + + 'manage-users' => ['/manage/users'], + 'manage-user' => ['/manage/users/user.php', ['u' => '<user>']], + 'manage-users-reports' => ['/manage/users/reports.php', ['u' => '<user>']], + 'manage-users-report' => ['/manage/users/report.php', ['r' => '<report>']], + 'manage-users-warnings' => ['/manage/users/warnings.php', ['u' => '<user>']], + 'manage-users-warning-delete' => ['/manage/users/warnings.php', ['w' => '<warning>', 'delete' => '1', 'csrf' => '{csrf}']], + + 'manage-roles' => ['/manage/users/roles.php'], + 'manage-role' => ['/manage/users/role.php', ['r' => '<role>']], +]); + +function url(string $name, array $variables = []): string { + if(!array_key_exists($name, MSZ_URLS)) { + return ''; + } + + $info = MSZ_URLS[$name]; + + if(!isset($info[0]) || !is_string($info[0])) { + return ''; + } + + $splitUrl = explode('/', $info[0]); + + for($i = 0; $i < count($splitUrl); $i++) { + $splitUrl[$i] = url_variable($splitUrl[$i], $variables); + } + + $url = implode('/', $splitUrl); + + if(!empty($info[1]) && is_array($info[1])) { + $url .= '?'; + + foreach($info[1] as $key => $value) { + $value = url_variable($value, $variables); + + if(empty($value) || ($key === 'page' && $value < 2)) + continue; + + $url .= sprintf('%s=%s&', $key, $value); + } + + $url = trim($url, '?&'); + } + + if(!empty($info[2]) && is_string($info[2])) { + $url .= rtrim(sprintf('#%s', url_variable($info[2], $variables)), '#'); + } + + return $url; +} + +function redirect(string $url): void { + header('Location: ' . $url); +} + +function url_redirect(string $name, array $variables = []): void { + redirect(url($name, $variables)); +} + +function url_variable(string $value, array $variables): string { + if(str_starts_with($value, '<') && str_ends_with($value, '>')) + return $variables[trim($value, '<>')] ?? ''; + + if(str_starts_with($value, '[') && str_ends_with($value, ']')) + return constant(trim($value, '[]')); + + if(str_starts_with($value, '{') && str_ends_with($value, '}')) + return \Misuzu\CSRF::token(); + + // Hack that allows variables with file extensions + $pathInfo = pathinfo($value); + if($value !== $pathInfo['filename']) { + $fallback = url_variable($pathInfo['filename'], $variables); + if($fallback !== $pathInfo['filename']) + return $fallback . '.' . $pathInfo['extension']; + } + + return $value; +} + +function url_list(): array { + global $hasManageAccess; + + $collection = []; + + foreach(MSZ_URLS as $name => $urlInfo) { + if(empty($hasManageAccess) && str_starts_with($name, 'manage-')) + continue; + + $item = [ + 'name' => $name, + 'path' => $urlInfo[0], + 'query' => [], + 'fragment' => $urlInfo[2] ?? '', + ]; + + if(!empty($urlInfo[1]) && is_array($urlInfo[1])) { + foreach($urlInfo[1] as $name => $value) { + $item['query'][] = [ + 'name' => $name, + 'value' => $value, + ]; + } + } + + $collection[] = $item; + } + + return $collection; +} + +function url_construct(string $url, array $query = [], ?string $fragment = null): string { + if(count($query)) { + $url .= mb_strpos($url, '?') !== false ? '&' : '?'; + + foreach($query as $key => $value) { + if($value) { + $url .= rawurlencode($key) . '=' . rawurlencode($value) . '&'; + } + } + + $url = mb_substr($url, 0, -1); + } + + if(!empty($fragment)) { + $url .= "#{$fragment}"; + } + + return $url; +} + +function url_proxy_media(?string $url): ?string { + if(empty($url) || !\Misuzu\Config::get('media_proxy.enable', \Misuzu\Config::TYPE_BOOL) || is_local_url($url)) { + return $url; + } + + $secret = \Misuzu\Config::get('media_proxy.secret', \Misuzu\Config::TYPE_STR, 'insecure'); + $url = \Index\Serialisation\Serialiser::uriBase64()->serialise($url); + $hash = hash_hmac('sha256', $url, $secret); + + return url('media-proxy', compact('hash', 'url')); +} + +function url_prefix(bool $trailingSlash = true): string { + return 'http' . (empty($_SERVER['HTTPS']) ? '' : 's') . '://' . $_SERVER['HTTP_HOST'] . ($trailingSlash ? '/' : ''); +} + +function is_local_url(string $url): bool { + $length = mb_strlen($url); + + if($length < 1) + return false; + + if($url[0] === '/' && ($length > 1 ? $url[1] !== '/' : true)) + return true; + + return str_starts_with($url, url_prefix()); +} diff --git a/templates/500.html b/templates/500.html new file mode 100644 index 0000000..9b8fc0b --- /dev/null +++ b/templates/500.html @@ -0,0 +1,16 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"/> + <title>Error 500 + + + +

Error 500

+

Something horrendously went wrong. Please report what you were doing to a developer.

+ + diff --git a/templates/503.html b/templates/503.html new file mode 100644 index 0000000..32f2489 --- /dev/null +++ b/templates/503.html @@ -0,0 +1,29 @@ + + + + + Error 503 + + + +

Error 503

+

The site is currently unavailable due to ongoing updates. It should be back shortly!

+

The page will refresh when the site becomes available again.

+

Retry

+ + + diff --git a/templates/_layout/comments.twig b/templates/_layout/comments.twig new file mode 100644 index 0000000..97f5b13 --- /dev/null +++ b/templates/_layout/comments.twig @@ -0,0 +1,195 @@ +{% macro comments_input(category, user, reply_to) %} + {% set reply_mode = reply_to is not null %} + + {% from 'macros.twig' import avatar %} + {% from '_layout/input.twig' import input_hidden, input_csrf, input_checkbox %} + +
+ {{ input_hidden('comment[category]', category.id) }} + {{ input_csrf() }} + + {% if reply_mode %} + {{ input_hidden('comment[reply]', reply_to.id) }} + {% endif %} + +
+
+ {{ avatar(user.id, reply_mode ? 40 : 50, user.username) }} +
+
+ +
+ {% if not reply_mode %} + {% if user.commentPerms.can_pin|default(false) %} + {{ input_checkbox('comment[pin]', 'Pin this comment', false, 'comment__action') }} + {% endif %} + {% if user.commentPerms.can_lock|default(false) %} + {{ input_checkbox('comment[lock]', 'Toggle locked status', false, 'comment__action') }} + {% endif %} + {% endif %} + +
+
+
+
+{% endmacro %} + +{% macro comments_entry(comment, indent, category, user) %} + {% from 'macros.twig' import avatar %} + {% from '_layout/input.twig' import input_checkbox_raw %} + {% set hide_details = comment.userId < 1 or comment.deleted and not user.commentPerms.can_delete_any|default(false) %} + + {% if user.commentPerms.can_delete_any|default(false) or (not comment.deleted or comment.replies(user)|length > 0) %} +
+
+ {% if hide_details %} +
+ {{ avatar(0, indent > 1 ? 40 : 50) }} +
+ {% else %} + + {{ avatar(comment.user.id, indent > 1 ? 40 : 50, comment.user.username) }} + + {% endif %} +
+
+ {% if not hide_details %} + {{ comment.user.username }} + {% endif %} + + + + {% if comment.pinned %} + {% apply spaceless %} + Pinned + {% if comment.pinnedTime != comment.createdTime %} + + {% endif %} + {% endapply %} + {% endif %} +
+
+ {{ hide_details ? '(deleted)' : comment.parsedText|raw }} +
+
+ {% if not comment.deleted and user is not null %} + {% if user.commentPerms.can_vote|default(false) %} + {% set like_vote_state = comment.userVote > 0 ? 0 : 1 %} + {% set dislike_vote_state = comment.userVote < 0 ? 0 : -1 %} + + + Like + {% if comment.likes > 0 %} + ({{ comment.likes|number_format }}) + {% endif %} + + + Dislike + {% if comment.dislikes > 0 %} + ({{ comment.dislikes|number_format }}) + {% endif %} + + {% endif %} + {% if user.commentPerms.can_comment|default(false) %} + + {% endif %} + {% if user.commentPerms.can_delete_any|default(false) or (comment.user.id|default(0) == user.id and user.commentPerms.can_delete|default(false)) %} + Delete + {% endif %} + {# if user is not null %} + Report + {% endif #} + {% if not comment.hasParent and user.commentPerms.can_pin|default(false) %} + {{ comment.pinned ? 'Unpin' : 'Pin' }} + {% endif %} + {% elseif user.commentPerms.can_delete_any|default(false) %} + Restore + {% endif %} +
+
+
+ +
+ {% from _self import comments_entry, comments_input %} + {% if user|default(null) is not null and category|default(null) is not null and user.commentPerms.can_comment|default(false) %} + {{ input_checkbox_raw('', false, 'comment__reply-toggle', '', false, {'id':'comment-reply-toggle-' ~ comment.id}) }} + {{ comments_input(category, user, comment) }} + {% endif %} + {% if comment.replies|length > 0 %} + {% for reply in comment.replies %} + {{ comments_entry(reply, indent + 1, category, user) }} + {% endfor %} + {% endif %} +
+
+ {% endif %} +{% endmacro %} + +{% macro comments_section(category, user) %} +
+
+ {% if user|default(null) is null %} +
+ Please login to comment. +
+ {% elseif category|default(null) is null %} +
+ Posting new comments here is disabled. +
+ {% elseif not user.commentPerms.can_lock|default(false) and category.locked %} +
+ This comment section was locked, . +
+ {% elseif not user.commentPerms.can_comment|default(false) %} +
+ You are not allowed to post comments. +
+ {% else %} + {% from _self import comments_input %} + {{ comments_input(category, user) }} + {% endif %} +
+ + {% if user.commentPerms.can_lock|default(false) and category.locked %} +
+ This comment section was locked, . +
+ {% endif %} + + + +
+ {% if category.posts|length > 0 %} + {% from _self import comments_entry %} + {% for comment in category.posts(user) %} + {{ comments_entry(comment, 1, category, user) }} + {% endfor %} + {% else %} +
+ There are no comments yet. +
+ {% endif %} +
+
+{% endmacro %} diff --git a/templates/_layout/footer.twig b/templates/_layout/footer.twig new file mode 100644 index 0000000..fcbea20 --- /dev/null +++ b/templates/_layout/footer.twig @@ -0,0 +1,26 @@ +
+ + +
diff --git a/templates/_layout/header.twig b/templates/_layout/header.twig new file mode 100644 index 0000000..b88520f --- /dev/null +++ b/templates/_layout/header.twig @@ -0,0 +1,102 @@ +{% from 'macros.twig' import avatar %} +{% from '_layout/input.twig' import input_checkbox_raw %} + + diff --git a/templates/_layout/input.twig b/templates/_layout/input.twig new file mode 100644 index 0000000..b404066 --- /dev/null +++ b/templates/_layout/input.twig @@ -0,0 +1,119 @@ +{% macro input_hidden(name, value) %} +{% apply spaceless %} + +{% endapply %} +{% endmacro %} + +{% macro input_csrf() %} +{% from _self import input_hidden %} +{% apply spaceless %} + {{ input_hidden('_csrf', csrf_token()) }} +{% endapply %} +{% endmacro %} + +{% macro input_text(name, class, value, type, placeholder, required, attributes, tabindex, autofocus, raw) %} +{% apply spaceless %} + 0 %}name="{{ name }}"{% else %}readonly{% endif %} + class="{% if not raw|default(false) %}input__text{% if name|length < 1 %} input__text--readonly{% endif %}{% endif %}{{ class|length > 0 ? ' ' ~ class : '' }}" + {% if placeholder|length > 0 %}placeholder="{{ placeholder }}"{% endif %} + {% if value|length > 0 %}value="{{ value }}"{% endif %} {% if required|default(false) %}required{% endif %} + {% if tabindex > 0 %}tabindex="{{ tabindex }}"{% endif %} {% if autofocus|default(false) %}autofocus{% endif %} + {% for name, value in attributes|default([]) %} + {{ name }}{% if value|length > 0 %}="{{ value }}"{% endif %} + {% endfor %}/> +{% endapply %} +{% endmacro %} + +{% macro input_checkbox_raw(name, checked, class, value, radio, attributes, disabled) %} +{% apply spaceless %} + 0 %}name="{{ name }}"{% endif %} + {% if checked %}checked{% endif %} + {% if disabled %}disabled{% endif %} + {% if value|length > 0 %}value="{{ value }}"{% endif %} + {% for name, value in attributes|default([]) %} + {{ name }}{% if value|length > 0 %}="{{ value }}"{% endif %} + {% endfor %}/> +{% endapply %} +{% endmacro %} + +{% macro input_checkbox(name, text, checked, class, value, radio, attributes, disabled) %} +{% from _self import input_checkbox_raw %} +{% apply spaceless %} + +{% endapply %} +{% endmacro %} + +{% macro input_file_raw(name, class, accepts, attributes) %} +{% apply spaceless %} + 0 %}name="{{ name }}"{% endif %} + class="{{ class|length > 0 ? class : 'input__upload__input' }}" + {% if accepts|length > 0 %}accept="{{ accepts|join(',') }}"{% endif %} + {% for name, value in attributes|default([]) %} + {{ name }}{% if value|length > 0 %}="{{ value }}"{% endif %} + {% endfor %}/> +{% endapply %} +{% endmacro %} + +{% macro input_file(name, class, accepts, attributes) %} +{% from _self import input_file_raw %} +{% apply spaceless %} + +{% endapply %} +{% endmacro %} + +{% macro input_select_option(value, key, selected) %} +{% apply spaceless %} + 0 %} value="{{ key }}"{% endif %}{% if selected %} selected{% endif %}> + {{ value }} + +{% endapply %} +{% endmacro %} + +{% macro input_select(name, options, selected, value_name, key_name, only_values, class, attributes) %} +{% from _self import input_select_option %} +{% apply spaceless %} + +{% endapply %} +{% endmacro %} + +{% macro input_colour(name, class, value) %} +{% apply spaceless %} + +{% endapply %} +{% endmacro %} diff --git a/templates/_layout/meta.twig b/templates/_layout/meta.twig new file mode 100644 index 0000000..739e917 --- /dev/null +++ b/templates/_layout/meta.twig @@ -0,0 +1,65 @@ +{% apply spaceless %} + {% set description = description|default(globals.site_description) %} + {% set site_twitter = site_twitter|default(globals.site_twitter) %} + + {% if title is defined %} + {% set browser_title = title ~ ' :: ' ~ globals.site_name %} + {% else %} + {% set browser_title = globals.site_name %} + {% endif %} + + {{ browser_title }} + + + + + + {% if description|length > 0 %} + + + + {% endif %} + + {% if site_twitter|length > 0 %} + + {% endif %} + + + + + {% if image is defined %} + {% if image|slice(0, 1) == '/' %} + {% if globals.site_url is not defined or globals.site_url|length < 1 %} + {% set image = '' %} + {% else %} + {% set image = globals.site_url|trim('/') ~ image %} + {% endif %} + {% endif %} + + {% if image|length > 0 %} + + + {% endif %} + {% endif %} + + {% if canonical_url is defined %} + {% if canonical_url|slice(0, 1) == '/' %} + {% if globals.site_url is not defined or globals.site_url|length < 1 %} + {% set canonical_url = '' %} + {% else %} + {% set canonical_url = globals.site_url|trim('/') ~ canonical_url %} + {% endif %} + {% endif %} + + {% if canonical_url|length > 0 %} + + + {% endif %} + {% endif %} + + {% if feeds is defined and feeds is iterable %} + {% for feed in feeds %} + + {% endfor %} + {% endif %} +{% endapply %} diff --git a/templates/auth/login.twig b/templates/auth/login.twig new file mode 100644 index 0000000..17789ea --- /dev/null +++ b/templates/auth/login.twig @@ -0,0 +1,65 @@ +{% extends 'auth/master.twig' %} +{% from 'macros.twig' import avatar %} +{% from '_layout/input.twig' import input_hidden, input_csrf, input_text %} + +{% set title = 'Login' %} + +{% block content %} + +{% endblock %} diff --git a/templates/auth/logout.twig b/templates/auth/logout.twig new file mode 100644 index 0000000..93155ea --- /dev/null +++ b/templates/auth/logout.twig @@ -0,0 +1,17 @@ +{% extends 'auth/master.twig' %} +{% from 'macros.twig' import container_title %} + +{% set title = 'Logout confirmation' %} + +{% block content %} +
+ {{ container_title(' Logout confirmation') }} + +
+

We couldn't verify that you were actually the person attempting to log out.

+

Press the button below to verify the logout request, otherwise click back in your browser or close this tab.

+

This error is usually caused by pressing the logout button on a page that's been loaded for a while.

+ Log out +
+
+{% endblock %} diff --git a/templates/auth/master.twig b/templates/auth/master.twig new file mode 100644 index 0000000..fc530f2 --- /dev/null +++ b/templates/auth/master.twig @@ -0,0 +1 @@ +{% extends 'master.twig' %} diff --git a/templates/auth/password_forgot.twig b/templates/auth/password_forgot.twig new file mode 100644 index 0000000..23b715c --- /dev/null +++ b/templates/auth/password_forgot.twig @@ -0,0 +1,36 @@ +{% extends 'auth/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from '_layout/input.twig' import input_hidden, input_csrf, input_text %} + +{% set title = 'Forgot password' %} + +{% block content %} +
+ {{ container_title(' Forgot password') }} + {{ input_csrf() }} + + {% if password_notices|length > 0 %} +
+
+ {% for notice in password_notices %} +

{{ notice }}

+ {% endfor %} +
+
+ {% endif %} + + + +
+ + Log in +
+
+{% endblock %} diff --git a/templates/auth/password_reset.twig b/templates/auth/password_reset.twig new file mode 100644 index 0000000..b22ce28 --- /dev/null +++ b/templates/auth/password_reset.twig @@ -0,0 +1,66 @@ +{% extends 'auth/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from '_layout/input.twig' import input_hidden, input_csrf, input_text %} + +{% set title = 'Resetting password' %} + +{% block content %} +
+ {{ container_title(' Resetting password for ' ~ password_user.username) }} + + {{ input_hidden('reset[user]', password_user.id) }} + {{ input_csrf() }} + + {% if password_notices|length > 0 %} +
+
+ {% for notice in password_notices %} +

{{ notice }}

+ {% endfor %} +
+
+ {% else %} +
+
+

A verification code should've been sent to your e-mail address.

+
+
+ {% endif %} + + {% if password_verification|length == 12 %} + {{ input_hidden('reset[verification]', password_verification) }} + {% else %} + + {% endif %} + + + + + +
+ + Log in +
+ +{% endblock %} diff --git a/templates/auth/register.twig b/templates/auth/register.twig new file mode 100644 index 0000000..402a278 --- /dev/null +++ b/templates/auth/register.twig @@ -0,0 +1,106 @@ +{% extends 'auth/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from '_layout/input.twig' import input_hidden, input_csrf, input_text %} + +{% set title = 'Register' %} + +{% block content %} + + {{ container_title(' Register') }} + +
+ {% if not register_restricted %} +
+ {% if register_notices|length > 0 %} +
+
+ {% for notice in register_notices %} + {% if notice == '_play_hint' %} + + {% else %} +

{{ notice }}

+ {% endif %} + {% endfor %} +
+
+ {% endif %} + +

Welcome to Flashii! Before creating your account, here are a few things you should take note of.

+

By creating an account you agree to the rules.

+

Engaging in borderline illegal activity on platforms provided by Flashii will result in a permanent ban, as described by Global Rule 5.

+

You are not allowed to have more than one account unless given explicit permission, as described by Global Rule 6.

+

You must be at least 18 years of age to use this website, as described by Global Rule 8.

+
+ {% endif %} + +
+ {{ input_csrf() }} + + {% if register_restricted %} +
+
+ {% if register_restricted == 'ban' %} +

A user is currently in a banned and/or silenced state from the same IP address you're currently visiting the site from. If said user isn't you and you wish to create an account, please contact us!

+ {% else %} +

The IP address from which you are visiting the website appears on our blacklist, you are not allowed to register from this address but if you already have an account you can log in just fine using the form above. If you think this blacklisting is a mistake, please contact us!

+ {% endif %} +
+
+ {% else %} + + + + + + + + + + +
+ + Log in +
+ {% endif %} +
+
+
+{% endblock %} diff --git a/templates/auth/twofactor.twig b/templates/auth/twofactor.twig new file mode 100644 index 0000000..48c413f --- /dev/null +++ b/templates/auth/twofactor.twig @@ -0,0 +1,39 @@ +{% extends 'auth/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from '_layout/input.twig' import input_hidden, input_csrf, input_text %} + +{% set title = 'Two Factor Authentication' %} + +{% block content %} +
+ {{ container_title(' Two Factor Authentication') }} + + {{ input_csrf() }} + {{ input_hidden('twofactor[redirect]', twofactor_redirect) }} + {{ input_hidden('twofactor[token]', twofactor_token) }} + + {% if twofactor_notices|length > 0 %} +
+
+ {% for notice in twofactor_notices %} +

{{ notice }}

+ {% endfor %} +
+
+ {% endif %} + + + +
+ + Log out +
+ +{% endblock %} diff --git a/templates/changelog/change.twig b/templates/changelog/change.twig new file mode 100644 index 0000000..0aa37be --- /dev/null +++ b/templates/changelog/change.twig @@ -0,0 +1,76 @@ +{% extends 'changelog/master.twig' %} +{% from 'macros.twig' import container_title, avatar %} +{% from '_layout/comments.twig' import comments_section %} + +{% set title = 'Changelog » Change #' ~ change_info.id %} +{% set canonical_url = url('changelog-change', {'change': change_info.id}) %} +{% set manage_link = url('manage-changelog-change', {'change': change_info.id}) %} +{% set description = change_info.header %} + +{% block content %} +
+
+ {{ change_info.actionString }} +
+ +
+ {{ change_info.header }} +
+
+ +
+
+
+
+ {% if change_info.user.id|default(null) is not null %} + + {% endif %} + + + Created + + + + {% if change_info.tags|length > 0 %} + + {% endif %} +
+
+ +
+

{{ title }}

+ + {% if change_info.hasBody %} + {{ change_info.parsedBody|raw }} + {% else %} +

This change has no additional notes.

+ {% endif %} +
+
+ + {% if change_info.hasCommentsCategory %} +
+ {{ container_title(' Comments for ' ~ change_info.date) }} + {{ comments_section(change_info.commentsCategory, comments_user) }} +
+ {% endif %} +{% endblock %} diff --git a/templates/changelog/index.twig b/templates/changelog/index.twig new file mode 100644 index 0000000..fb766f8 --- /dev/null +++ b/templates/changelog/index.twig @@ -0,0 +1,53 @@ +{% extends 'changelog/master.twig' %} +{% from 'macros.twig' import pagination, container_title %} +{% from 'changelog/macros.twig' import changelog_listing %} +{% from '_layout/comments.twig' import comments_section %} + +{% set is_date = changelog_date > 0 %} +{% set is_user = changelog_user is not null %} +{% set title = 'Changelog' %} +{% set changelog_date_fmt = changelog_date|default(false) ? changelog_date|date('Y-m-d') : '' %} + +{% set canonical_url = url('changelog-index', { + 'date': changelog_date_fmt, + 'user': changelog_user.id|default(0), + 'page': changelog_pagination.page < 2 ? 0 : changelog_pagination.page, +}) %} + +{% if is_date or is_user %} + {% set title = title ~ ' »' ~ (is_date ? ' ' ~ changelog_infos[0].date : '') ~ (is_user ? ' by ' ~ changelog_infos[0].user.username : '') %} +{% else %} + {% set feeds = [ + { + 'type': 'rss', + 'title': '', + 'url': url('changelog-feed-rss'), + }, + { + 'type': 'atom', + 'title': '', + 'url': url('changelog-feed-atom'), + }, + ] %} +{% endif %} + +{% block content %} +
+ {{ container_title(' ' ~ title) }} + + {{ changelog_listing(changelog_infos, is_date) }} + + {% if not is_date %} +
+ {{ pagination(changelog_pagination, url('changelog-index'), null, {'date':changelog_date_fmt, 'user':changelog_user.id|default(0)})}} +
+ {% endif %} +
+ + {% if is_date %} +
+ {{ container_title(' Comments') }} + {{ comments_section(changelog_infos[0].commentsCategory, comments_user) }} +
+ {% endif %} +{% endblock %} diff --git a/templates/changelog/macros.twig b/templates/changelog/macros.twig new file mode 100644 index 0000000..58debbe --- /dev/null +++ b/templates/changelog/macros.twig @@ -0,0 +1,78 @@ +{% macro changelog_listing(changes, hide_dates, is_small, is_manage) %} + {% from _self import changelog_entry %} + +
+ {% if changes|length > 0 %} + {% for change in changes %} + {% if not hide_dates and (last_date is not defined or last_date != change.date) %} + {% set last_date = change.date %} + + + {{ last_date }} + + {% endif %} + + {{ changelog_entry(change, is_small, is_manage) }} + {% endfor %} + {% else %} +
+ There are no changes to display here. +
+ {% endif %} +
+{% endmacro %} + +{% macro changelog_entry(change, is_small, is_manage) %} + {% set change_url = url(is_manage ? 'manage-changelog-change' : 'changelog-change', {'change': change.id}) %} + +
+ + +
+ + {{ change.header }} + + + {% if is_manage %} + + {% endif %} +
+
+{% endmacro %} diff --git a/templates/changelog/master.twig b/templates/changelog/master.twig new file mode 100644 index 0000000..37c7b7c --- /dev/null +++ b/templates/changelog/master.twig @@ -0,0 +1,5 @@ +{% extends 'master.twig' %} + +{% if manage_link is not defined %} + {% set manage_link = url('manage-changelog-changes') %} +{% endif %} diff --git a/templates/confirm.twig b/templates/confirm.twig new file mode 100644 index 0000000..7ccbb85 --- /dev/null +++ b/templates/confirm.twig @@ -0,0 +1,24 @@ +{% extends 'master.twig' %} +{% from 'macros.twig' import container_title %} +{% from '_layout/input.twig' import input_csrf %} + +{% set title = title|default('Confirm your action') %} + +{% block content %} + + {{ container_title(' ' ~ title) }} + {{ input_csrf() }} + {% for name, value in params|default([]) %} + {% if value is not empty %} + + {% endif %} + {% endfor %} +
+ {{ message|default('Are you sure you w') }} +
+
+ + No +
+
+{% endblock %} diff --git a/templates/errors/400.twig b/templates/errors/400.twig new file mode 100644 index 0000000..6fd61d1 --- /dev/null +++ b/templates/errors/400.twig @@ -0,0 +1,8 @@ +{% extends 'errors/master.twig' %} + +{% set error_code = 400 %} +{% set error_text = 'Bad Request' %} + +{% block error_message %} +

Whatever you tried to do, you probably shouldn't.

+{% endblock %} diff --git a/templates/errors/403.twig b/templates/errors/403.twig new file mode 100644 index 0000000..a0e5b23 --- /dev/null +++ b/templates/errors/403.twig @@ -0,0 +1,8 @@ +{% extends 'errors/master.twig' %} + +{% set error_code = 403 %} +{% set error_text = 'Access Denied!' %} + +{% block error_message %} +

You aren't allowed to be here. Try logging in, if you haven't yet.

+{% endblock %} diff --git a/templates/errors/404.twig b/templates/errors/404.twig new file mode 100644 index 0000000..7f8405a --- /dev/null +++ b/templates/errors/404.twig @@ -0,0 +1,8 @@ +{% extends 'errors/master.twig' %} + +{% set error_code = 404 %} +{% set error_text = 'Not Found!' %} + +{% block error_message %} +

Couldn't find what you were looking for. Check the spelling in the URL or go back to the previous page.

+{% endblock %} diff --git a/templates/errors/master.twig b/templates/errors/master.twig new file mode 100644 index 0000000..bcfa086 --- /dev/null +++ b/templates/errors/master.twig @@ -0,0 +1,22 @@ +{% extends 'master.twig' %} +{% from 'macros.twig' import container_title %} + +{# fuck it #} +{% set http_code = http_code|default(error_code) %} + +{% block content %} +
+ {{ container_title((title|default(error_code|default(http_code) >= 400 ? ' Error' : ' Information')) ~ ' ' ~ (error_code|default(http_code >= 400 ? http_code : '')) ~ (error_text is defined ? ' - ' ~ error_text : '')) }} + +
+ {% if message is defined %} +

{{ message }}

+ {% else %} + {% block error_message %} +

Try again later, perhaps.

+ {% endblock %} + {% endif %} +
+
+{% endblock %} + diff --git a/templates/forum/confirm.twig b/templates/forum/confirm.twig new file mode 100644 index 0000000..8fe6781 --- /dev/null +++ b/templates/forum/confirm.twig @@ -0,0 +1,24 @@ +{% extends 'forum/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from '_layout/input.twig' import input_csrf %} + +{% set title = title|default('Confirm your action') %} + +{% block content %} +
+ {{ container_title(' ' ~ title) }} + {{ input_csrf() }} + {% for name, value in params %} + + {% endfor %} + +
+ {{ message|default('Are you sure you w') }} +
+ +
+ + +
+
+{% endblock %} diff --git a/templates/forum/forum.twig b/templates/forum/forum.twig new file mode 100644 index 0000000..86186c9 --- /dev/null +++ b/templates/forum/forum.twig @@ -0,0 +1,32 @@ +{% extends 'forum/master.twig' %} +{% from 'forum/macros.twig' import forum_category_listing, forum_topic_listing, forum_category_buttons, forum_header, forum_category_tools %} + +{% set title = forum_info.forum_name %} +{% set canonical_url = url('forum-category', { + 'forum': forum_info.forum_id, + 'page': forum_pagination.page|default(0) > 1 ? forum_pagination.page : 0, +}) %} + +{% block content %} + {{ forum_header(forum_info.forum_name, forum_breadcrumbs, true, canonical_url, [ + { + 'html': ' Mark as Read', + 'url': url('forum-mark-single', {'forum': forum_info.forum_id}), + 'display': current_user is defined, + 'method': 'POST', + } + ]) }} + + {% if forum_may_have_children and forum_info.forum_subforums|length > 0 %} + {{ forum_category_listing(forum_info.forum_subforums, 'Forums') }} + {% endif %} + + {% if forum_may_have_topics %} + {% set category_tools = forum_category_tools(forum_info, forum_perms, forum_pagination) %} + {{ category_tools }} + {{ forum_topic_listing(forum_topics) }} + {{ category_tools }} + {% endif %} + + {{ forum_header('', forum_breadcrumbs) }} +{% endblock %} diff --git a/templates/forum/index.twig b/templates/forum/index.twig new file mode 100644 index 0000000..e80ebcc --- /dev/null +++ b/templates/forum/index.twig @@ -0,0 +1,38 @@ +{% extends 'forum/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from 'forum/macros.twig' import forum_category_listing %} + +{% set title = 'Forum Listing' %} +{% set canonical_url = '/forum/' %} + +{% block content %} + {% if not forum_empty %} + {% for category in forum_categories %} + {% if category.forum_children > 0 %} + {{ forum_category_listing( + category.forum_subforums, + category.forum_name, + category.forum_colour, + category.forum_id == constant('MSZ_FORUM_ROOT') + ? '' + : 'f' ~ category.forum_id, + category.forum_icon|default('') + ) }} + {% endif %} + {% endfor %} + + {% if current_user is defined %} + + {% endif %} + {% else %} +
+ {{ container_title(' Forums') }} + +
+

There are currently no visible forums.

+
+
+ {% endif %} +{% endblock %} diff --git a/templates/forum/leaderboard.twig b/templates/forum/leaderboard.twig new file mode 100644 index 0000000..2a7642a --- /dev/null +++ b/templates/forum/leaderboard.twig @@ -0,0 +1,46 @@ +{% extends 'forum/master.twig' %} +{% from 'macros.twig' import avatar %} +{% from 'forum/macros.twig' import forum_header %} + +{% set title = 'Forum Leaderboard » ' ~ leaderboard_name %} +{% set canonical_url = url('forum-leaderboard', { + 'id': leaderboard_id, + 'mode': '', +}) %} + +{% block content %} + {{ forum_header(title, [], false, canonical_url, [ + { + 'html': ' Markdown', + 'url': url('forum-leaderboard', {'id': leaderboard_id, 'mode': 'markdown'}), + 'display': leaderboard_mode != 'markdown', + }, + { + 'html': ' Table', + 'url': url('forum-leaderboard', {'id': leaderboard_id}), + 'display': leaderboard_mode == 'markdown', + }, + ]) }} + +
+ {% for id, name in leaderboard_categories %} + {{ name }} + {% endfor %} +
+ + {% if leaderboard_mode == 'markdown' %} + + {% else %} + {% for user in leaderboard_data %} +
+ +
+
{{ user.rank|number_format }}
+
{{ avatar(user.user_id, user.rank == 1 ? 50 : 40, user.username) }}
+
{{ user.username }}
+
{{ user.posts|number_format }} posts
+
+
+ {% endfor %} + {% endif %} +{% endblock %} diff --git a/templates/forum/macros.twig b/templates/forum/macros.twig new file mode 100644 index 0000000..adca2fb --- /dev/null +++ b/templates/forum/macros.twig @@ -0,0 +1,590 @@ +{% macro forum_category_listing(forums, title, colour, id, icon) %} + {% from _self import forum_category_entry %} + {% from 'macros.twig' import container_title %} + +
0 %}id="{{ id }}"{% endif %}> + {{ container_title(' ' ~ title) }} + + {% if forums|length > 0 %} +
+ {% for forum in forums %} + {{ forum_category_entry(forum) }} + {% endfor %} +
+ {% else %} +
+ This category is empty. +
+ {% endif %} +
+{% endmacro %} + +{% macro forum_header(title, breadcrumbs, omit_last_breadcrumb, title_url, actions) %} +
+ {% if breadcrumbs is iterable and breadcrumbs|length > 0 %} +
+ {% for name, url in breadcrumbs %} + {% if url != breadcrumbs|first %} +
+ +
+ {% endif %} + + {% if not (omit_last_breadcrumb|default(false) and url == breadcrumbs|last) %} + {{ name }} + {% endif %} + {% endfor %} +
+ {% endif %} + + {% if title|length > 0 %} + {% if title_url|length > 0 %} + + {{ title }} + + {% else %} +
+ {{ title }} +
+ {% endif %} + {% endif %} + + {% if actions is iterable and actions|length > 0 %} +
+ {% for action in actions %} + {% if action.display is not defined or action.display %} + + {{ action.html|raw }} + + {% endif %} + {% endfor %} +
+ {% endif %} +
+{% endmacro %} + +{% macro forum_category_tools(info, perms, pagination_info) %} + {% from 'macros.twig' import pagination %} + + {% set is_locked = info.forum_archived != 0 %} + {% set can_topic = not is_locked and perms|perms_check(constant('MSZ_FORUM_PERM_CREATE_TOPIC')) %} + {% set pag = pagination(pagination_info, url('forum-category'), null, {'f': info.forum_id}) %} + + {% if can_topic or pag|trim|length > 0 %} +
+ + +
+ {{ pag }} +
+
+ {% endif %} +{% endmacro %} + +{% macro forum_topic_tools(info, pagination_info, can_reply) %} + {% from 'macros.twig' import pagination %} + + {% set pag = pagination(pagination_info, url('forum-topic'), null, {'t': info.topic_id}, 'page') %} + + {% if can_reply or pag|trim|length > 0 %} +
+
+ {% if can_reply %} + Reply + {% endif %} +
+ +
+ {{ pag }} +
+
+ {% endif %} +{% endmacro %} + +{% macro forum_category_entry(forum, forum_unread, forum_icon) %} + {% from 'macros.twig' import avatar %} + {% set forum_unread = forum_unread|default(forum.forum_unread|default(false)) ? 'unread' : 'read' %} + + {% if forum_icon is empty %} + {% if forum.forum_icon is defined and forum.forum_icon is not empty %} + {% set forum_icon = forum.forum_icon %} + {% elseif forum.forum_archived is defined and forum.forum_archived %} + {% set forum_icon = 'fas fa-archive fa-fw' %} + {% elseif forum.forum_type is defined and forum.forum_type != constant('MSZ_FORUM_TYPE_DISCUSSION') %} + {% if forum.forum_type == constant('MSZ_FORUM_TYPE_FEATURE') %} + {% set forum_icon = 'fas fa-star fa-fw' %} + {% elseif forum.forum_type == constant('MSZ_FORUM_TYPE_LINK') %} + {% set forum_icon = 'fas fa-link fa-fw' %} + {% elseif forum.forum_type == constant('MSZ_FORUM_TYPE_CATEGORY') %} + {% set forum_icon = 'fas fa-folder fa-fw' %} + {% endif %} + {% else %} + {% set forum_icon = 'fas fa-comments fa-fw' %} + {% endif %} + {% endif %} + +
+ + +
+
+ +
+ +
+
+ {{ forum.forum_name }} +
+ +
+ {{ forum.forum_description|nl2br }} +
+ + {% if forum.forum_subforums is defined and forum.forum_subforums|length > 0 %} +
+ {% for subforum in forum.forum_subforums %} + + {{ subforum.forum_name }} + + {% endfor %} +
+ {% endif %} +
+ + {% if forum.forum_type == constant('MSZ_FORUM_TYPE_LINK') %} + {% if forum.forum_link_clicks is not null %} +
+
{{ forum.forum_link_clicks|number_format }}
+
+ {% endif %} + {% elseif forum_may_have_children(forum.forum_type) %} +
+
{{ forum.forum_count_topics|number_format }}
+
{{ forum.forum_count_posts|number_format }}
+
+ {% endif %} + + {% if forum_may_have_topics(forum.forum_type) or forum.forum_link_clicks is not null %} + + {% endif %} +
+
+{% endmacro %} + +{% macro forum_topic_locked(locked, archived) %} + {% if locked is not null or archived %} +
+
+
+ +
+
+ {% if archived %} + This topic has been archived. + {% else %} + This topic was locked + . + {% endif %} +
+
+ {% endif %} +{% endmacro %} + +{% macro forum_topic_listing(topics, title) %} + {% from _self import forum_topic_entry %} + {% from 'macros.twig' import container_title %} + +
+ {{ container_title(' ' ~ title|default('Topics')) }} + +
+ {% if topics|length > 0 %} + {% for topic in topics %} + {{ forum_topic_entry(topic) }} + {% endfor %} + {% else %} +
+ There are no topics in this forum. +
+ {% endif %} +
+
+{% endmacro %} + +{% macro forum_topic_entry(topic, topic_icon, topic_unread) %} + {% from 'macros.twig' import avatar %} + {% set topic_unread = topic_unread|default(topic.topic_unread|default(false)) %} + {% set topic_important = topic.topic_type == constant('MSZ_TOPIC_TYPE_STICKY') or topic.topic_type == constant('MSZ_TOPIC_TYPE_ANNOUNCEMENT') or topic.topic_type == constant('MSZ_TOPIC_TYPE_GLOBAL_ANNOUNCEMENT') %} + {% set has_priority_voting = forum_has_priority_voting(topic.forum_type) %} + + {% if topic_icon is null %} + {% if topic.topic_deleted is defined and topic.topic_deleted is not null %} + {% set topic_icon = 'fas fa-trash-alt' %} + {% elseif topic.topic_type is defined and topic.topic_type != constant('MSZ_TOPIC_TYPE_DISCUSSION') %} + {% if topic.topic_type == constant('MSZ_TOPIC_TYPE_ANNOUNCEMENT') or topic.topic_type == constant('MSZ_TOPIC_TYPE_GLOBAL_ANNOUNCEMENT') %} + {% set topic_icon = 'fas fa-bullhorn' %} + {% elseif topic.topic_type == constant('MSZ_TOPIC_TYPE_STICKY') %} + {% set topic_icon = 'fas fa-thumbtack' %} + {% endif %} + {% elseif topic.topic_locked is defined and topic.topic_locked is not null %} + {% set topic_icon = 'fas fa-lock' %} + {% elseif has_priority_voting %} + {% set topic_icon = 'far fa-star' %} + {% else %} + {% set topic_icon = (topic_unread ? 'fas' : 'far') ~ ' fa-comment' %} + {% endif %} + {% endif %} + +
+ + +
+
+ + + {% if has_priority_voting %} +
{{ topic.topic_priority|number_format }}
+ {% endif %} + + {% if topic.topic_participated %} +
+ {% endif %} +
+ +
+
+ + {{ topic.topic_title }} + +
+ +
+ {% if topic.author_id is not null %} + by {{ topic.author_name }}, + + {% endif %} + +
+ + {% if topic.topic_pages|default(0) > 1 %} +
+ {% for i in 1..topic.topic_pages|clamp(0, 3) %} + + {{ i }} + + {% endfor %} + {% if topic.topic_pages > 3 %} + {% if topic.topic_pages > 6 %} +
+ +
+ {% endif %} + + {% for i in (topic.topic_pages - 2)|clamp(4, topic.topic_pages)..topic.topic_pages %} + + {{ i }} + + {% endfor %} + {% endif %} +
+ {% endif %} +
+ +
+
{{ topic.topic_count_posts|number_format }}
+
{{ topic.topic_count_views|number_format }}
+
+ +
+
+ {% if topic.respondent_id is not null %} + {{ topic.respondent_name }} + {% endif %} + + + + +
+ + {% if topic.respondent_id is not null %} + + {{ avatar(topic.respondent_id, 30, topic.respondent_name) }} + + {% endif %} +
+
+
+{% endmacro %} + +{% macro forum_post_listing(posts, user_id, perms) %} + {% from _self import forum_post_entry %} + + {% for post in posts %} + {{ forum_post_entry(post, user_id, perms) }} + {% endfor %} +{% endmacro %} + +{% macro forum_post_entry(post, user_id, perms) %} + {% from 'macros.twig' import avatar %} + {% set is_deleted = post.post_deleted is not null %} + {% set can_post = perms|perms_check(constant('MSZ_FORUM_PERM_CREATE_POST')) %} + {% set can_edit = perms|perms_check(constant('MSZ_FORUM_PERM_EDIT_ANY_POST')) or ( + user_id == post.poster_id + and perms|perms_check(constant('MSZ_FORUM_PERM_EDIT_POST')) + ) %} + {% set can_delete = not post.is_opening_post and ( + perms|perms_check(constant('MSZ_FORUM_PERM_DELETE_ANY_POST')) or ( + user_id == post.poster_id + and perms|perms_check(constant('MSZ_FORUM_PERM_DELETE_POST')) + and post.post_created|date('U') > ''|date('U') - constant('MSZ_FORUM_POST_DELETE_LIMIT') + ) + ) %} + +
+ + +
+ {% set post_link = url(post.is_opening_post ? 'forum-topic' : 'forum-post', {'topic': post.topic_id, 'post': post.post_id, 'post_fragment': 'p%d'|format(post.post_id)}) %} + +
+ + + + #{{ post.post_id }} + +
+ +
+ {{ post.post_text|escape|parse_text(post.post_parse)|raw }} +
+ + {% if can_post or can_edit or can_delete %} +
+ {% if is_deleted %} + Restore + Permanently Delete + {% else %} + {# if can_post %} + Quote + {% endif #} + {% if can_edit %} + Edit + {% endif %} + {% if can_delete %} + Delete + {% endif %} + {% endif %} +
+ {% endif %} + + {% if post.post_display_signature and post.poster_signature_content|length > 0 %} +
+ {{ post.poster_signature_content|escape|parse_text(post.poster_signature_parser)|raw }} +
+ {% endif %} +
+
+{% endmacro %} + +{% macro forum_poll(poll, options, user_answers, topic_id, can_vote, preview_results) %} + {% from '_layout/input.twig' import input_csrf, input_hidden, input_checkbox, input_checkbox_raw %} + {% set user_answers = user_answers is empty or user_answers is not iterable ? [] : user_answers %} + {% set user_answered = user_answers|length > 0 %} + {% set results_available = preview_results or user_answered or poll.poll_expired or poll.poll_preview_results %} + {% set options_available = not poll.poll_expired and (poll.poll_change_vote or not user_answered) %} + {% set display_results = user_answered or poll.poll_expired %} + + {% if options is iterable and options|length > 0 %} +
+ {% if results_available %} + {% if options_available %} + {{ input_checkbox_raw('', display_results, 'forum__poll__toggle', '', false, {'id':'forum-poll-toggle'}) }} + {% endif %} + +
+
+ {% for option in options %} + {% set percent = poll.poll_votes < 1 ? 0 : (option.option_votes / poll.poll_votes) * 100 %} + +
+
+
+
+
{{ option.option_text }}
+
{{ option.option_votes|number_format }}
+
{{ percent|number_format(2) }}%
+
+
+ {% endfor %} +
+ +
+ This poll got {{ poll.poll_votes|number_format }} vote{{ poll.poll_votes == 1 ? '' : 's' }} +
+ + {% if poll.poll_expires is not null %} +
+ Polling {{ poll.poll_expired ? 'closed' : 'will close' }} . +
+ {% endif %} + + {% if options_available %} +
+ +
+ {% endif %} +
+ {% endif %} + + {% if options_available %} +
+ {{ input_csrf() }} + {{ input_hidden('poll[id]', poll.poll_id) }} + +
+ {% for option in options %} + {{ input_checkbox( + 'poll[answers][]', + option.option_text, option.option_id in user_answers, 'forum__poll__option', + option.option_id, poll.poll_max_votes <= 1, + null, not can_vote + ) }} + {% endfor %} +
+ + {% if can_vote and poll.poll_max_votes > 1 %} +
+ You have + {{ poll.poll_max_votes }} votes + remaining. +
+ {% endif %} + + {% if poll.poll_expires is not null %} +
+ Polling {{ poll.poll_expired ? 'closed' : 'will close' }} . +
+ {% endif %} + +
+ {% if can_vote %} + + {% endif %} + {% if results_available %} + + {% endif %} +
+
+ {% endif %} +
+ {% endif %} +{% endmacro %} + +{% macro forum_priority_votes(topic, votes, can_vote) %} +
+
+ {% for vote in votes %} +
+ {% for i in 1..vote.topic_priority %} + + {% endfor %} +
+ {% endfor %} +
+ + {% if can_vote %} + + {% endif %} +
+{% endmacro %} diff --git a/templates/forum/master.twig b/templates/forum/master.twig new file mode 100644 index 0000000..fc530f2 --- /dev/null +++ b/templates/forum/master.twig @@ -0,0 +1 @@ +{% extends 'master.twig' %} diff --git a/templates/forum/posting.twig b/templates/forum/posting.twig new file mode 100644 index 0000000..3de2cec --- /dev/null +++ b/templates/forum/posting.twig @@ -0,0 +1,173 @@ +{% extends 'forum/master.twig' %} +{% from 'macros.twig' import avatar %} +{% from 'forum/macros.twig' import forum_header %} +{% from '_layout/input.twig' import input_hidden, input_csrf, input_text, input_button, input_select, input_checkbox %} + +{% set title = 'Posting' %} +{% set is_reply = posting_topic is defined %} +{% set is_opening = not is_reply or posting_post.is_opening_post|default(false) %} + +{% block content %} +
+ {{ input_hidden('post[' ~ (is_reply ? 'topic' : 'forum') ~ ']', is_reply ? posting_topic.topic_id : posting_forum.forum_id) }} + {{ input_hidden('post[mode]', posting_mode) }} + {{ input_csrf() }} + {{ forum_header( + is_reply and not is_opening + ? posting_topic.topic_title + : input_text( + 'post[title]', + 'forum__header__input', + posting_defaults.title|default(posting_topic.topic_title|default('')), + 'text', + 'Enter your title here...' + ), + posting_breadcrumbs, + false, + is_reply and not is_opening + ? url('forum-topic', {'topic': posting_topic.topic_id}) + : '' + ) }} + + {% if posting_post is defined %} + {{ input_hidden('post[id]', posting_post.post_id) }} + {% endif %} + + {% if posting_notices|length > 0 %} +
+
+ {% for notice in posting_notices %} +

{{ notice }}

+ {% endfor %} +
+
+ {% endif %} + +
+ + +
+
+ + {% if posting_post is defined %} + Editing + {% elseif is_reply %} + Replying + {% else %} + Creating + {% endif %} + +
+ + + + + + + + +
+
+ {{ input_select( + 'post[parser]', + constant('\\Misuzu\\Parsers\\Parser::NAMES'), + posting_defaults.parser|default(posting_post.post_parse|default(posting_info.user_post_parse|default(constant('\\Misuzu\\Parsers\\Parser::BBCODE')))), + null, null, false, 'forum__post__dropdown js-forum-posting-parser' + ) }} + {% if is_opening and posting_types|length > 1 %} + {{ input_select( + 'post[type]', + posting_types, + posting_defaults.type|default(posting_topic.topic_type|default(posting_types|keys|first)), + null, null, null, 'forum__post__dropdown' + ) }} + {% endif %} + {{ input_checkbox( + 'post[signature]', + 'Display Signature', + posting_defaults.signature is not null + ? posting_defaults.signature : ( + posting_post.post_display_signature is defined + ? posting_post.post_display_signature + : true + ) + ) }} +
+ +
+ +
+
+
+
+
+{% endblock %} diff --git a/templates/forum/topic.twig b/templates/forum/topic.twig new file mode 100644 index 0000000..fdeba47 --- /dev/null +++ b/templates/forum/topic.twig @@ -0,0 +1,69 @@ +{% extends 'forum/master.twig' %} +{% from 'macros.twig' import pagination %} +{% + from 'forum/macros.twig' + import + forum_post_listing, + forum_topic_buttons, + forum_topic_locked, + forum_header, + forum_topic_tools, + forum_poll, + forum_priority_votes +%} + +{% set title = topic_info.topic_title %} +{% set canonical_url = url('forum-topic', { + 'topic': topic_info.topic_id, + 'page': topic_pagination.page > 1 ? topic_pagination.page : 0, +}) %} + +{% set forum_post_csrf = csrf_token() %} +{% set topic_tools = forum_topic_tools(topic_info, topic_pagination, can_reply) %} +{% set topic_notice = forum_topic_locked(topic_info.topic_locked, topic_info.topic_archived) %} +{% set topic_actions = [ + { + 'html': ' Delete', + 'url': url('forum-topic-delete', {'topic': topic_info.topic_id}), + 'display': topic_can_delete, + }, + { + 'html': ' Restore', + 'url': url('forum-topic-restore', {'topic': topic_info.topic_id}), + 'display': topic_can_nuke_or_restore, + }, + { + 'html': ' Permanently Delete', + 'url': url('forum-topic-nuke', {'topic': topic_info.topic_id}), + 'display': topic_can_nuke_or_restore, + }, + { + 'html': ' Bump', + 'url': url('forum-topic-bump', {'topic': topic_info.topic_id}), + 'display': topic_can_bump, + }, + { + 'html': ' Lock', + 'url': url('forum-topic-lock', {'topic': topic_info.topic_id}), + 'display': topic_can_lock and topic_info.topic_locked is null, + }, + { + 'html': ' Unlock', + 'url': url('forum-topic-unlock', {'topic': topic_info.topic_id}), + 'display': topic_can_lock and topic_info.topic_locked is not null, + }, +] %} + +{% block content %} + {{ forum_header(topic_info.topic_title, topic_breadcrumbs, false, canonical_url, topic_actions) }} + {{ topic_notice }} + {% if forum_has_priority_voting(topic_info.forum_type) %} + {{ forum_priority_votes(topic_info, topic_priority_votes, true) }} {# replace true this with perms check #} + {% endif %} + {{ forum_poll(topic_info, topic_poll_options, topic_poll_user_answers, topic_info.topic_id, current_user.id|default(0) > 0, topic_info.author_user_id == current_user.id|default(0)) }} + {{ topic_tools }} + {{ forum_post_listing(topic_posts, current_user.id|default(0), topic_perms) }} + {{ topic_tools }} + {{ topic_notice }} + {{ forum_header('', topic_breadcrumbs) }} +{% endblock %} diff --git a/templates/home/home.twig b/templates/home/home.twig new file mode 100644 index 0000000..fd7b7c9 --- /dev/null +++ b/templates/home/home.twig @@ -0,0 +1,128 @@ +{% extends 'home/master.twig' %} +{% from 'macros.twig' import container_title, avatar %} +{% from 'news/macros.twig' import news_preview %} +{% from 'changelog/macros.twig' import changelog_listing %} + +{% set canonical_url = '/' %} + +{% set landing_stats = [ + { + icon: 'fas fa-users fa-fw', + name: 'Members', + value: statistics.count_users_all|number_format, + }, + { + icon: 'fas fa-comment-dots fa-fw', + name: 'Comments', + value: statistics.count_comments|number_format, + }, + { + icon: 'fas fa-user-check fa-fw', + name: 'Online', + value: statistics.count_users_online|number_format, + }, + { + icon: 'fas fa-user-clock fa-fw', + name: 'Active (24 hr)', + value: statistics.count_users_active|number_format, + }, + { + icon: 'fas fa-list fa-fw', + name: 'Topics', + value: statistics.count_forum_topics|number_format, + }, + { + icon: 'fas fa-comments fa-fw', + name: 'Posts', + value: statistics.count_forum_posts|number_format, + }, +] %} + +{% block content %} +
+
+
+ {{ container_title(' Statistics') }} + +
+{% for stat in landing_stats %} +
+
+ {{ stat.name }} +
+
+ {{ stat.value }} +
+
+{% endfor %} +
+
+ + {% if online_users|length > 0 %} +
+ {{ container_title(' Currently Online') }} + +
+ {% for user in online_users %} + + {{ avatar(user.user_id, 30, user.username) }} + + {% endfor %} +
+
+ {% endif %} + + {% if birthdays|length > 0 %} + + {% elseif latest_user is not null %} + + {% endif %} + +
+ {{ container_title(' Changelog', false, url('changelog-index')) }} +
+ {{ changelog_listing(featured_changelog, false, true) }} +
+
+
+ +
+ {% for post in featured_news %} + {{ news_preview(post) }} + {% endfor %} +
+
+{% endblock %} + diff --git a/templates/home/landing.twig b/templates/home/landing.twig new file mode 100644 index 0000000..fa4b1b4 --- /dev/null +++ b/templates/home/landing.twig @@ -0,0 +1,205 @@ +{% extends 'home/master.twig' %} +{% from 'macros.twig' import container_title, avatar %} + +{% set canonical_url = '/' %} + +{% set landing_stats = [ + { + icon: 'fas fa-users fa-fw', + name: 'members', + value: statistics.count_users_all|number_format, + }, + { + icon: 'fas fa-user-check fa-fw', + name: 'online', + value: statistics.count_users_online|number_format, + }, + { + icon: 'fas fa-user-clock fa-fw', + name: 'active (24 hr)', + value: statistics.count_users_active|number_format, + }, + { + icon: 'fas fa-list fa-fw', + name: 'topics', + value: statistics.count_forum_topics|number_format, + }, + { + icon: 'fas fa-comments fa-fw', + name: 'posts', + value: statistics.count_forum_posts|number_format, + }, + { + icon: 'fas fa-comment-dots fa-fw', + name: 'comments', + value: statistics.count_comments|number_format, + }, +] %} + +{% block main_header %} +
+
+
+
+ + {{ globals.site_name }} + +
+ +
+ {% for item in site_menu[1:] %} + {% if item.display is not defined or item.display %} + {{ item.title }} + {% endif %} + {% endfor %} + + + +
Register
+
+
+
+
+{% endblock %} + +{% block main_footer %} +
+ + +
+{% endblock %} + +{% block content %} +
+
+{% for stat in landing_stats %} +
+
+ +
+
+ {{ stat.value }} {{ stat.name }} +
+
+{% endfor %} +
+ +
+ +
+ {{ container_title(' Active Topics') }} +
+{% for topic in forum_active %} +
+ +
+
+ +
+
+
+ {{ topic.topic_title }} +
+
+
+
{{ topic.topic_count_posts|number_format }}
+
{{ topic.topic_count_views|number_format }}
+
+
+
+{% endfor %} +
+
+
+ + + +{% if online_users|length > 0 %} +
+ {{ container_title(' Currently Online') }} +
+
+ {% for user in online_users %} + + {{ avatar(user.user_id, 50, user.username) }} + + {% endfor %} +
+
+
+{% endif %} +
+ +{% if linked_data is defined and linked_data is iterable %} + +{% endif %} +{% endblock %} + diff --git a/templates/home/master.twig b/templates/home/master.twig new file mode 100644 index 0000000..fc530f2 --- /dev/null +++ b/templates/home/master.twig @@ -0,0 +1 @@ +{% extends 'master.twig' %} diff --git a/templates/home/search.twig b/templates/home/search.twig new file mode 100644 index 0000000..2b8a859 --- /dev/null +++ b/templates/home/search.twig @@ -0,0 +1,119 @@ +{% extends 'home/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from '_layout/input.twig' import input_text %} +{% from 'user/macros.twig' import user_card %} +{% from 'forum/macros.twig' import forum_topic_listing, forum_post_listing %} +{% from 'news/macros.twig' import news_preview %} + +{% set title = search_query|length < 1 ? 'Search' : 'Looking for ' ~ search_query %} +{% set canonical_url = url('search-query', {'query': search_query}) %} + +{% block content %} +
+
+
+
+ {{ input_text('q', 'search__input__text', search_query, 'text', 'What are you looking for?', false, null, 1, true, true) }} + +
+
+ + {% if forum_topics|length > 0 or forum_posts|length > 0 or users|length > 0 or news_posts|length > 0 %} +
+ {% if forum_topics|length > 0 %} + +
+
+ Topics ({{ forum_topics|length|number_format }}) +
+
+ {% endif %} + + {% if forum_posts|length > 0 %} + +
+
+ Posts ({{ forum_posts|length|number_format }}) +
+
+ {% endif %} + + {% if users|length > 0 %} + +
+
+ Users ({{ users|length|number_format }}) +
+
+ {% endif %} + + {% if news_posts|length > 0 %} + +
+
+ News ({{ news_posts|length|number_format }}) +
+
+ {% endif %} +
+ {% endif %} +
+ + {% if search_query is not empty and not ( + forum_topics|length > 0 or forum_posts|length > 0 or users|length > 0 or news_posts|length > 0 + ) %} +
+
+ +
+
+
+ Nothing found! +
+
+ No results found using that query, try something else! +
+
+
+ {% endif %} + + {% if forum_topics|length > 0 %} +
+ {{ forum_topic_listing(forum_topics, 'Topics (%d)'|format(forum_topics|length)) }} + {% endif %} + + {% if forum_posts|length > 0 %} +
+
+ {{ container_title(' Posts (%s)'|format(forum_posts|length|number_format)) }} + + {{ forum_post_listing(forum_posts) }} +
+ {% endif %} + + {% if users|length > 0 %} +
+
+ {{ container_title(' Users (%s)'|format(users|length|number_format)) }} + +
+ {% for user in users %} +
+ {{ user_card(user) }} +
+ {% endfor %} +
+
+ {% endif %} + + {% if news_posts|length > 0 %} +
+
+ {{ container_title(' News (%s)'|format(news_posts|length|number_format)) }} + {% for post in news_posts %} + {{ news_preview(post) }} + {% endfor %} +
+ {% endif %} +{% endblock %} + diff --git a/templates/info/index.twig b/templates/info/index.twig new file mode 100644 index 0000000..d202bd7 --- /dev/null +++ b/templates/info/index.twig @@ -0,0 +1,29 @@ +{% extends 'info/master.twig' %} +{% from 'macros.twig' import container_title %} + +{% set title = 'Info' %} + +{% block content %} +
+ {{ container_title('Flashii Informational Pages') }} + +
+

Here's a listing of a few informational pages that'll probably come in handy during your Flashii Experience™.

+

Flashii

+ +

Misuzu Project

+ +

Index Project

+ +
+
+{% endblock %} diff --git a/templates/info/master.twig b/templates/info/master.twig new file mode 100644 index 0000000..fc530f2 --- /dev/null +++ b/templates/info/master.twig @@ -0,0 +1 @@ +{% extends 'master.twig' %} diff --git a/templates/info/view.twig b/templates/info/view.twig new file mode 100644 index 0000000..33f31ef --- /dev/null +++ b/templates/info/view.twig @@ -0,0 +1,14 @@ +{% extends 'info/master.twig' %} +{% from 'macros.twig' import container_title %} + +{% set title = document.title %} + +{% block content %} +
+ {{ container_title(document.title) }} + +
+ {{ document.content|raw }} +
+
+{% endblock %} diff --git a/templates/macros.twig b/templates/macros.twig new file mode 100644 index 0000000..98b4988 --- /dev/null +++ b/templates/macros.twig @@ -0,0 +1,90 @@ +{% macro navigation(links, current, top, fmt, align) %} + {% set top = top|default(false) == true %} + {% set align = align|default('centre') %} + {% set current = current|default(null) %} + {% set fmt = fmt|default('%s') %} + + +{% endmacro %} + +{% macro pagination(info, path, page_range, params, page_param, url_fragment) %} + {% if info.page is defined and info.pages > 1 %} + {% set params = params is iterable ? params : [] %} + {% set page_param = page_param|default('p') %} + {% set page_range = page_range|default(5) %} + + + {% endif %} +{% endmacro %} + +{% macro container_title(title, unsafe, url) %} + {% set has_url = url is not null and url|length > 0 %} + + +{% endmacro %} + +{% macro avatar(user_id, resolution, alt_text, attributes) %} +{{ html_avatar(user_id, resolution, alt_text|default(''), attributes|default([]))|raw }} +{% endmacro %} diff --git a/templates/manage/changelog/change.twig b/templates/manage/changelog/change.twig new file mode 100644 index 0000000..a80efbc --- /dev/null +++ b/templates/manage/changelog/change.twig @@ -0,0 +1,61 @@ +{% extends 'manage/changelog/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from '_layout/input.twig' import input_csrf, input_text, input_select, input_checkbox %} + +{% if change is not null %} + {% set site_link = url('changelog-change', {'change': change.id}) %} +{% endif %} + +{% block manage_content %} +
+
+ {{ input_csrf() }} + + {{ container_title(change is not null ? 'Editing #' ~ change.id : 'Adding a new change') }} + +
+ {{ input_select('change[action]', change_actions, change.action|default(0), 'action_name', 'action_id') }} + {{ input_text('change[log]', '', change.header|default(''), 'text', '', true, {'maxlength':255,'style':'flex-grow:1'}) }} +
+ + + + + + + +
+ {% for tag in change_tags %} + + {% endfor %} +
+ +
+ +
+
+
+{% endblock %} diff --git a/templates/manage/changelog/changes.twig b/templates/manage/changelog/changes.twig new file mode 100644 index 0000000..40099b0 --- /dev/null +++ b/templates/manage/changelog/changes.twig @@ -0,0 +1,25 @@ +{% extends 'manage/changelog/master.twig' %} +{% from 'macros.twig' import pagination, container_title %} +{% from 'changelog/macros.twig' import changelog_listing %} + +{% block manage_content %} + {% set changelog_pagination = pagination(changelog_pagination, url('manage-changelog-changes')) %} + + +
+ {{ container_title('Changelog') }} + +
+
+ Create new change + {{ changelog_pagination }} +
+ + {{ changelog_listing(changelog_changes, false, false, true) }} + +
+ {{ changelog_pagination }} +
+
+
+{% endblock %} diff --git a/templates/manage/changelog/master.twig b/templates/manage/changelog/master.twig new file mode 100644 index 0000000..da96d86 --- /dev/null +++ b/templates/manage/changelog/master.twig @@ -0,0 +1,5 @@ +{% extends 'manage/master.twig' %} + +{% if site_link is not defined %} + {% set site_link = url('changelog-index') %} +{% endif %} diff --git a/templates/manage/changelog/tag.twig b/templates/manage/changelog/tag.twig new file mode 100644 index 0000000..f508d13 --- /dev/null +++ b/templates/manage/changelog/tag.twig @@ -0,0 +1,47 @@ +{% extends 'manage/changelog/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from '_layout/input.twig' import input_csrf, input_text, input_checkbox %} + +{% block manage_content %} +
+
+ {{ input_csrf() }} + + {{ container_title(edit_tag.id is defined ? 'Editing ' ~ edit_tag.name ~ ' (' ~ edit_tag.id ~ ')' : 'Adding a new tag') }} + + + + + + + + {% if edit_tag.id is defined %} + + {% endif %} + +
+ +
+
+
+{% endblock %} diff --git a/templates/manage/changelog/tags.twig b/templates/manage/changelog/tags.twig new file mode 100644 index 0000000..b6baae1 --- /dev/null +++ b/templates/manage/changelog/tags.twig @@ -0,0 +1,28 @@ +{% extends 'manage/changelog/master.twig' %} +{% from 'macros.twig' import container_title %} + +{% block manage_content %} +
+
+ {{ container_title('Tags') }} + + Create new tag + + +
+
+{% endblock %} diff --git a/templates/manage/forum/forum.twig b/templates/manage/forum/forum.twig new file mode 100644 index 0000000..77d1ec8 --- /dev/null +++ b/templates/manage/forum/forum.twig @@ -0,0 +1,11 @@ +{% extends 'manage/users/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from 'manage/macros.twig' import permissions_table %} +{% from '_layout/input.twig' import input_hidden, input_csrf, input_select %} + +{% block manage_content %} +
+ {{ container_title(forum.forum_name) }} + there's nothing here go away +
+{% endblock %} diff --git a/templates/manage/forum/listing.twig b/templates/manage/forum/listing.twig new file mode 100644 index 0000000..1c17c6b --- /dev/null +++ b/templates/manage/forum/listing.twig @@ -0,0 +1,37 @@ +{% extends 'manage/users/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from 'manage/macros.twig' import permissions_table %} + +{% block manage_content %} +
+ {{ container_title('Forum Listing') }} + +
+ {% for forum in forums %} + {{ forum.forum_name }}
+ {% endfor %} +
+
+ +
+ {{ container_title('Permission Calculator') }} + + Remove this when the permission manager exists. + + {% if calculated_perms is defined %} + + {% for key, value in calculated_perms %} + + + + + {% endfor %} +
{{ key }}{{ value }}
+ {% endif %} + +
+ {{ permissions_table(perms) }} + +
+
+{% endblock %} diff --git a/templates/manage/forum/master.twig b/templates/manage/forum/master.twig new file mode 100644 index 0000000..3fcbcab --- /dev/null +++ b/templates/manage/forum/master.twig @@ -0,0 +1 @@ +{% extends 'manage/forum/master.twig' %} diff --git a/templates/manage/general/blacklist.twig b/templates/manage/general/blacklist.twig new file mode 100644 index 0000000..dff978b --- /dev/null +++ b/templates/manage/general/blacklist.twig @@ -0,0 +1,40 @@ +{% extends 'manage/general/master.twig' %} +{% from 'macros.twig' import container_title, pagination %} +{% from '_layout/input.twig' import input_csrf, input_text, input_checkbox, input_file, input_select %} + +{% block manage_content %} +
+ {{ container_title(' IP Blacklist') }} + +
+ Here you can add or remove CIDR ranges to the IP Blacklist, these ranges are allowed to log into the site but cannot create accounts. +
+ + {% if notices|length > 0 %} +
+
+ {% for notice in notices %} + {{ notice }} + {% endfor %} +
+
+ {% endif %} + +
+
+ {{ input_csrf() }} + + +
+ +
+ {{ input_csrf() }} + {{ input_select('blacklist[remove][]', blacklist, null, 'ip_cidr', null, true, 'manage__blacklist__select', { + 'multiple': true, + 'size': 10, + }) }} + +
+
+
+{% endblock %} diff --git a/templates/manage/general/emoticon.twig b/templates/manage/general/emoticon.twig new file mode 100644 index 0000000..3fbd98e --- /dev/null +++ b/templates/manage/general/emoticon.twig @@ -0,0 +1,39 @@ +{% extends 'manage/general/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from '_layout/input.twig' import input_csrf, input_text, input_checkbox, input_file, input_select, input_colour %} + +{% set title = emote_info is null ? 'Adding a new emoticon' : 'Editing #' ~ emote_info.id %} + +{% block manage_content %} +
+ {{ container_title(' ' ~ title) }} + +
+ {{ input_csrf() }} + + + + + + + + + +
+ +
+
+
+{% endblock %} diff --git a/templates/manage/general/emoticons.twig b/templates/manage/general/emoticons.twig new file mode 100644 index 0000000..1c63c6e --- /dev/null +++ b/templates/manage/general/emoticons.twig @@ -0,0 +1,76 @@ +{% extends 'manage/general/master.twig' %} +{% from 'macros.twig' import container_title %} + +{% block manage_content %} +
+ {{ container_title(' Emoticons') }} + +
+ Here you can manage emoticons and their aliases and other properties. There are no imposed restrictions on strings (aside from being ASCII only) but if you add shit like spaces or uppercase letters I will kill you dead. +
+ +
+ Add +
+ +
+
+
+ ID +
+
+ Order +
+
+ Rank +
+
+ Image +
+
+ Actions +
+
+ + {% for emote in emotes %} +
+
+ #{{ emote.id }} +
+
+ {{ emote.order }} +
+
+ {{ emote.rank }} +
+
+ {{ emote.url }} +
+
+ + + + + +
+
+ {% endfor %} +
+
+ + +{% endblock %} diff --git a/templates/manage/general/logs.twig b/templates/manage/general/logs.twig new file mode 100644 index 0000000..d2e3bcd --- /dev/null +++ b/templates/manage/general/logs.twig @@ -0,0 +1,24 @@ +{% extends 'manage/general/master.twig' %} +{% from 'macros.twig' import container_title, pagination %} +{% from 'user/macros.twig' import user_account_log %} + +{% block manage_content %} +
+ {{ container_title(' Global Log') }} + {% set glp = pagination(global_logs_pagination, url('manage-general-logs'), null, {'v': 'logs'}) %} + + +
+{% endblock %} diff --git a/templates/manage/general/master.twig b/templates/manage/general/master.twig new file mode 100644 index 0000000..f04b5b5 --- /dev/null +++ b/templates/manage/general/master.twig @@ -0,0 +1 @@ +{% extends 'manage/master.twig' %} diff --git a/templates/manage/general/overview.twig b/templates/manage/general/overview.twig new file mode 100644 index 0000000..d065044 --- /dev/null +++ b/templates/manage/general/overview.twig @@ -0,0 +1,62 @@ +{% extends 'manage/general/master.twig' %} +{% from 'macros.twig' import container_title %} + +{% set stat_names = { + 'stat_users_total': 'Total Users', + 'stat_users_deleted': 'Deleted Users', + 'stat_users_active': 'Active Users', + 'stat_audit_logs': 'Logged Actions', + 'stat_changelog_entries': 'Changelogs', + 'stat_comment_categories_total': 'Comment Sections', + 'stat_comment_categories_locked': 'Locked Comment Sections', + 'stat_comment_posts_total': 'Total Comments', + 'stat_comment_posts_deleted': 'Deleted Comments', + 'stat_comment_posts_replies': 'Comment Replies', + 'stat_comment_posts_pinned': 'Pinned Comments', + 'stat_comment_posts_edited': 'Edited Comments', + 'stat_comment_likes': 'Comments Like Votes', + 'stat_comment_dislikes': 'Comments Dislike Votes', + 'stat_forum_posts_total': 'Total Forum Posts', + 'stat_forum_posts_deleted': 'Deleted Forum Posts', + 'stat_forum_posts_edited': 'Edited Forum Posts', + 'stat_forum_posts_plain': 'Forum Posts using Plain Text', + 'stat_forum_posts_bbcode': 'Forum Posts using BBCode', + 'stat_forum_posts_markdown': 'Forum Posts using Markdown', + 'stat_forum_posts_signature': 'Forum Posts with Visible Signature', + 'stat_forum_topics_total': 'Total Forum Topics', + 'stat_forum_topics_normal': 'Regular Forum Topics', + 'stat_forum_topics_pinned': 'Pinned Forum Topics', + 'stat_forum_topics_announce': 'Announcement Forum Topics', + 'stat_forum_topics_global_announce': 'Global Announcement Forum Topics', + 'stat_forum_topics_deleted': 'Deleted Forum Topics', + 'stat_forum_topics_locked': 'Locked Forum Topics', + 'stat_blacklist': 'Blacklisted IP addresses', + 'stat_login_attempts_total': 'Total Login Attempts', + 'stat_login_attempts_failed': 'Failed Login Attempts', + 'stat_user_sessions': 'Active User Sessions', + 'stat_user_password_resets': 'Pending Password Resets', + 'stat_user_warnings': 'User Warnings', +} %} + +{% block manage_content %} +
+ {{ container_title('Overview') }} + +
+

Welcome to Manage, here you can manage things.

+
+
+ +
+ {{ container_title('Statistics') }} + +
+ {% for name, value in statistics %} +
+
{{ stat_names[name]|default(name) }}
+
{{ value|number_format }}
+
+ {% endfor %} +
+
+{% endblock %} diff --git a/templates/manage/general/setting-delete.twig b/templates/manage/general/setting-delete.twig new file mode 100644 index 0000000..c3a492c --- /dev/null +++ b/templates/manage/general/setting-delete.twig @@ -0,0 +1,42 @@ +{% extends 'manage/general/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from '_layout/input.twig' import input_csrf, input_text, input_checkbox, input_file, input_select, input_colour %} + +{% set title = ('Removing setting ' ~ conf_var.name) %} + +{% block manage_content %} +
+ {{ container_title(' ' ~ title) }} + +
+ Are you sure you want to delete this setting? It cannot be recovered. +
+ +
+ {{ input_csrf() }} + +
+ + + + + + + + +
+
{{ conf_var.name }}
+
+
{{ conf_var.type }}
+
+
{{ conf_var.value|json_encode }}
+
+
+ +
+ + No +
+
+
+{% endblock %} diff --git a/templates/manage/general/setting.twig b/templates/manage/general/setting.twig new file mode 100644 index 0000000..9011fe7 --- /dev/null +++ b/templates/manage/general/setting.twig @@ -0,0 +1,104 @@ +{% extends 'manage/general/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from '_layout/input.twig' import input_csrf, input_text, input_checkbox, input_file, input_select, input_colour %} + +{% set title = conf_var.name is empty ? 'Adding a new setting' : ((conf_var.new ? 'Adding ' : 'Editing ') ~ ' setting ' ~ conf_var.name) %} + +{% block manage_content %} +
+ {{ container_title(' ' ~ title) }} + +
+ {{ input_csrf() }} + + {% if conf_var.new %} + + + + {% endif %} + + {% if conf_var.type is not empty %} + + +
+ +
+ {% endif %} +
+
+{% endblock %} diff --git a/templates/manage/general/settings.twig b/templates/manage/general/settings.twig new file mode 100644 index 0000000..6247721 --- /dev/null +++ b/templates/manage/general/settings.twig @@ -0,0 +1,48 @@ +{% extends 'manage/general/master.twig' %} +{% from 'macros.twig' import container_title %} + +{% block manage_content %} +
+ {{ container_title(' Settings') }} + +
+ Editor for the configuration table. This page contains Very Private Things that should Never be shared, be careful. +
+ +
+ New +
+ +
+ + + + + + + + + + + {% for var in conf_vars %} + + + + + + + {% endfor %} + +
NameTypeValueOptions
+
{{ var.key }}
+
+
{{ var.type }}
+
+
{{ var.value }}
+
+ + +
+
+
+{% endblock %} diff --git a/templates/manage/macros.twig b/templates/manage/macros.twig new file mode 100644 index 0000000..95e86d4 --- /dev/null +++ b/templates/manage/macros.twig @@ -0,0 +1,55 @@ +{% macro manage_navigation(nav) %} + {% from 'macros.twig' import container_title %} + + {% for name, value in nav %} +
+ {{ container_title(name) }} + + +
+ {% endfor %} +{% endmacro %} + +{% macro permissions_table(permissions, readonly) %} + {% from '_layout/input.twig' import input_checkbox %} + +
+ {% for perms in permissions %} +
+
+ {{ perms.title }} +
+
+ Yes +
+
+ No +
+
+ Never +
+
+ + {% for perm in perms.perms %} +
+
+ {{ perm.title }} +
+
+ {{ input_checkbox('perms[' ~ perms.section ~ '][' ~ perm.section ~ '][value]', '', perm.value == 'yes', 'permissions__choice permissions__choice--radio permissions__choice--yes', 'yes', true, null, readonly) }} +
+
+ {{ input_checkbox('perms[' ~ perms.section ~ '][' ~ perm.section ~ '][value]', '', perm.value == 'no', 'permissions__choice permissions__choice--radio permissions__choice--no', 'no', true, null, readonly) }} +
+
+ {{ input_checkbox('perms[' ~ perms.section ~ '][' ~ perm.section ~ '][value]', '', perm.value == 'never', 'permissions__choice permissions__choice--radio permissions__choice--never', 'never', true, null, readonly) }} +
+
+ {% endfor %} + {% endfor %} +
+{% endmacro %} diff --git a/templates/manage/master.twig b/templates/manage/master.twig new file mode 100644 index 0000000..66fdf5d --- /dev/null +++ b/templates/manage/master.twig @@ -0,0 +1,25 @@ +{% extends 'master.twig' %} +{% from 'macros.twig' import container_title %} +{% from 'manage/macros.twig' import manage_navigation %} + +{% set title = title|default('Broom Closet') %} +{% set site_logo = '/images/logos/imouto-broom.png' %} + +{% block content %} +
+ + +
+ {% block manage_content %} +
+ {{ container_title('No brooms') }} +
+ This broom closet is empty. +
+
+ {% endblock %} +
+
+{% endblock %} diff --git a/templates/manage/news/categories.twig b/templates/manage/news/categories.twig new file mode 100644 index 0000000..995c502 --- /dev/null +++ b/templates/manage/news/categories.twig @@ -0,0 +1,21 @@ +{% extends 'manage/news/master.twig' %} +{% from 'macros.twig' import pagination, container_title %} + +{% block manage_content %} +
+ {{ container_title('Categories') }} + + New Category + + {% for cat in news_categories %} +

+ {{ cat.id }} + {{ cat.name }}, + {{ cat.isHidden }}, + {{ cat.createdTime|date('r') }} +

+ {% endfor %} + + {{ pagination(categories_pagination, url('manage-news-categories')) }} +
+{% endblock %} diff --git a/templates/manage/news/category.twig b/templates/manage/news/category.twig new file mode 100644 index 0000000..2d078c4 --- /dev/null +++ b/templates/manage/news/category.twig @@ -0,0 +1,33 @@ +{% extends 'manage/news/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from '_layout/input.twig' import input_hidden, input_csrf, input_text, input_checkbox %} + +{% set is_new = category is not defined %} + +{% block manage_content %} +
+ {{ container_title(is_new ? 'New Category' : 'Editing ' ~ category_info.name) }} + + {{ input_csrf() }} + {{ input_hidden('category[id]', category_info.id|default(0)) }} + + + + + + + + + + + + + + + + +
Name{{ input_text('category[name]', '', category_info.name|default(), 'text', '', true) }}
Description
Is Hidden{{ input_checkbox('category[hidden]', '', category_info.isHidden|default(false)) }}
+ + +
+{% endblock %} diff --git a/templates/manage/news/master.twig b/templates/manage/news/master.twig new file mode 100644 index 0000000..b892573 --- /dev/null +++ b/templates/manage/news/master.twig @@ -0,0 +1,5 @@ +{% extends 'manage/master.twig' %} + +{% if site_link is not defined %} + {% set site_link = url('news-index') %} +{% endif %} diff --git a/templates/manage/news/post.twig b/templates/manage/news/post.twig new file mode 100644 index 0000000..2cb3d59 --- /dev/null +++ b/templates/manage/news/post.twig @@ -0,0 +1,37 @@ +{% extends 'manage/news/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from '_layout/input.twig' import input_hidden, input_csrf, input_text, input_checkbox, input_select %} + +{% set is_new = post_info is not defined %} + +{% block manage_content %} +
+ {{ container_title(is_new ? 'New Post' : 'Editing ' ~ post_info.title) }} + + {{ input_csrf() }} + {{ input_hidden('post[id]', post_info.id|default(0)) }} + + + + + + + + + + + + + + + + + + + + +
Name{{ input_text('post[title]', '', post_info.title|default(), 'text', '', true) }}
Category{{ input_select('post[category]', categories, post_info.categoryId|default(0), 'name', 'id') }}
Is Featured{{ input_checkbox('post[featured]', '', post_info.isFeatured|default(false)) }}
+ + +
+{% endblock %} diff --git a/templates/manage/news/posts.twig b/templates/manage/news/posts.twig new file mode 100644 index 0000000..d7abc80 --- /dev/null +++ b/templates/manage/news/posts.twig @@ -0,0 +1,27 @@ +{% extends 'manage/news/master.twig' %} +{% from 'macros.twig' import pagination, container_title %} + +{% block manage_content %} +
+ {{ container_title('News Posts') }} + + New Post + + {% for post in news_posts %} +

+ {{ post.id }} + Cat: {{ post.categoryId }} + {{ post.isFeatured }}, + {{ post.user.id }}, + {{ post.title }}, + {{ post.scheduledTime|date('r') }}, + {{ post.createdTime|date('r') }}, + {{ post.updatedTime|date('r') }}, + {{ post.deletedTime|date('r') }}, + {{ post.commentsCategoryId }} +

+ {% endfor %} + + {{ pagination(posts_pagination, url('manage-news-posts')) }} +
+{% endblock %} diff --git a/templates/manage/users/master.twig b/templates/manage/users/master.twig new file mode 100644 index 0000000..7c37c30 --- /dev/null +++ b/templates/manage/users/master.twig @@ -0,0 +1,5 @@ +{% extends 'manage/master.twig' %} + +{% if site_link is not defined %} + {% set site_link = url('user-list') %} +{% endif %} diff --git a/templates/manage/users/role.twig b/templates/manage/users/role.twig new file mode 100644 index 0000000..b13616b --- /dev/null +++ b/templates/manage/users/role.twig @@ -0,0 +1,94 @@ +{% extends 'manage/users/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from 'manage/macros.twig' import permissions_table %} +{% from '_layout/input.twig' import input_csrf, input_text, input_checkbox %} + +{% block manage_content %} +
+ {{ input_csrf() }} + +
+ {{ container_title(role_info is not null ? 'Editing ' ~ role_info.name ~ ' (' ~ role_info.id ~ ')' : 'Creating a new role') }} + + + + + + + + + +
+ +
+ {{ container_title('Colour') }} + + + + + + + + + +
+ +
+ {{ container_title('Additional') }} + + +
+ +
+ {{ container_title('Permissions') }} + {{ permissions_table(permissions, not can_manage_perms) }} +
+ + +
+{% endblock %} diff --git a/templates/manage/users/roles.twig b/templates/manage/users/roles.twig new file mode 100644 index 0000000..06a4121 --- /dev/null +++ b/templates/manage/users/roles.twig @@ -0,0 +1,78 @@ +{% extends 'manage/users/master.twig' %} +{% from 'macros.twig' import pagination, container_title %} + +{% set roles_pagination = pagination(manage_roles_pagination, url('manage-roles')) %} + +{% block manage_content %} +
+ {{ container_title(' Roles') }} + + {% if roles_pagination|trim|length > 0 %} +
+ {{ roles_pagination }} +
+ {% endif %} + +
+
+ +
+
+
+
+ +
+
+
+
+ Create a new role +
+
+
+
+ + {% for role in manage_roles %} +
+ + +
+
+
+
+ +
+
+
+
+ {{ role.name }} +
+
+ {% if role.userCount > 0 %} +
+ {{ role.userCount|number_format }} +
+ {% endif %} + {% if role.title is not empty %} +
+ {{ role.title }} +
+ {% endif %} +
+
+
+ + + +
+
+
+ {% endfor %} +
+ + {% if roles_pagination|trim|length > 0 %} +
+ {{ roles_pagination }} +
+ {% endif %} +
+{% endblock %} diff --git a/templates/manage/users/user.twig b/templates/manage/users/user.twig new file mode 100644 index 0000000..58cbfaa --- /dev/null +++ b/templates/manage/users/user.twig @@ -0,0 +1,165 @@ +{% extends 'manage/users/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from 'manage/macros.twig' import permissions_table %} +{% from '_layout/input.twig' import input_csrf, input_text, input_checkbox, input_file, input_select, input_colour, input_hidden %} + +{% set site_link = url('user-profile', {'user': user_info.id}) %} + +{% block manage_content %} +
+ {% if manage_notices|length > 0 %} +
+
+ {% for notice in manage_notices %} +

{{ notice }}

+ {% endfor %} +
+
+ {% endif %} + +
+ {{ container_title('Editing ' ~ user_info.username ~ ' (' ~ user_info.id ~ ')') }} + {{ input_csrf() }} + +
+ + + + + + + + + + + + + + + + + {% if can_edit_user %} + + + + {% endif %} +
+ +
+ + + {{ input_colour(can_edit_user ? 'colour[hex]' : '', '', '#%s'|format(user_info.userColour.hex)) }} +
+ + {# TODO: if the hierarchy of the current user is too low to touch the role then opacity should be lowered and input disabled #} +
+
+ {% for role in manage_roles %} + + {% endfor %} +
+
+ + {% if can_edit_user %} +
+ + +
+ {% endif %} +
+ + {% if current_user.super %} +
+ {{ container_title('Send test e-mail to ' ~ user_info.username ~ ' (' ~ user_info.id ~ ')') }} + +

DO NOT ABUSE THIS SHIT

+ + {{ input_csrf() }} + {{ input_hidden('send_test_email', 'yes_send_it') }} + +
+ +
+
+ {% endif %} + +
+ {{ container_title('Permissions for ' ~ user_info.username ~ ' (' ~ user_info.id ~ ')') }} + + {{ permissions_table(permissions, not can_edit_perms) }} + + {% if can_edit_perms %} + {{ input_csrf() }} + +
+ + +
+ {% endif %} +
+
+{% endblock %} diff --git a/templates/manage/users/users.twig b/templates/manage/users/users.twig new file mode 100644 index 0000000..b2156c8 --- /dev/null +++ b/templates/manage/users/users.twig @@ -0,0 +1,62 @@ +{% extends 'manage/users/master.twig' %} +{% from 'macros.twig' import pagination, container_title, avatar %} + +{% set users_pagination = pagination(manage_users_pagination, url('manage-users')) %} + +{% block manage_content %} +
+ {{ container_title(' Users') }} + + {% if users_pagination|trim|length > 0 %} +
+ {{ users_pagination }} +
+ {% endif %} + +
+ {% for user in manage_users %} +
+ + +
+
{{ avatar(user.id, 40, user.username) }}
+
+
+ {{ user.username }} +
+
+
+ + / + {{ user.registerRemoteAddress }} +
+
+ + / + {{ user.lastRemoteAddress }} +
+ {% if user.isDeleted %} +
+ + +
+ {% endif %} +
+
+
+ + + +
+
+
+ {% endfor %} +
+ + {% if users_pagination|trim|length > 0 %} +
+ {{ users_pagination }} +
+ {% endif %} +
+{% endblock %} diff --git a/templates/manage/users/warning.twig b/templates/manage/users/warning.twig new file mode 100644 index 0000000..acc97c8 --- /dev/null +++ b/templates/manage/users/warning.twig @@ -0,0 +1,8 @@ +{% extends 'manage/users/master.twig' %} +{% from 'macros.twig' import pagination, container_title %} +{% from 'user/macros.twig' import user_profile_warning %} +{% from '_layout/input.twig' import input_text, input_csrf, input_select, input_hidden %} + +{% block manage_content %} + +{% endblock %} diff --git a/templates/manage/users/warnings.twig b/templates/manage/users/warnings.twig new file mode 100644 index 0000000..776d072 --- /dev/null +++ b/templates/manage/users/warnings.twig @@ -0,0 +1,95 @@ +{% extends 'manage/users/master.twig' %} +{% from 'macros.twig' import pagination, container_title %} +{% from 'user/macros.twig' import user_profile_warning %} +{% from '_layout/input.twig' import input_text, input_csrf, input_select, input_hidden %} + +{% block manage_content %} +
+ {{ container_title(' Filters') }} + {{ input_text('lookup', null, warnings.user.username|default(''), 'text', 'Enter a username') }} + +
+ + {% if warnings.notices|length > 0 %} +
+
+ {% for notice in warnings.notices %} + {{ notice }} + {% endfor %} +
+
+ {% endif %} + + {% if warnings.user is not null %} +
+ {{ container_title(' Warn ' ~ warnings.user.username) }} + {{ input_csrf() }} + {{ input_hidden('warning[user]', warnings.user.id) }} + + {{ input_select('warning[type]', warnings.types) }} + {{ input_text('warning[note]', '', '', 'text', 'Public note') }} + {{ input_select('warning[duration]', warnings.durations) }} + {{ input_text('warning[duration_custom]', '', '', 'text', 'Custom Duration') }} +
+ + +
+ {% endif %} + +
+ {{ container_title(' Warnings') }} + {% set warnpag = pagination(warnings.pagination, url('manage-users-warnings', {'user': warnings.user.id|default(0)})) %} + + {{ warnpag }} + +
+
+
+ +
+
+
+ User +
+
+ User IP +
+
+ +
+
+ Issuer +
+
+ Issuer IP +
+
+
+ +
+
+ Type +
+ +
+ Created +
+ +
+ Duration +
+ +
+ Note +
+
+
+ + {% for warning in warnings.list %} + {{ user_profile_warning(warning, true, true, csrf_token()) }} + {% endfor %} +
+ + {{ warnpag }} +
+{% endblock %} diff --git a/templates/master.twig b/templates/master.twig new file mode 100644 index 0000000..2be4018 --- /dev/null +++ b/templates/master.twig @@ -0,0 +1,168 @@ + + + + + + {% include '_layout/meta.twig' %} + + + + +{% if site_background is defined %} + +{% endif %} +{% if site_logo is defined %} + +{% endif %} + + +{% set site_menu = [ + { + 'title': 'Home', + 'url': url('index'), + 'menu': [ + { + 'title': 'Members', + 'url': url('user-list'), + 'display': current_user is defined, + }, + { + 'title': 'Changelog', + 'url': url('changelog-index'), + }, + { + 'title': 'Contact', + 'url': url('info', {'title': 'contact'}), + }, + { + 'title': 'Rules', + 'url': url('info', {'title': 'rules'}), + }, + { + 'title': 'Twitter', + 'url': 'https://twitter.com/flashiinet', + }, + ], + }, + { + 'title': 'News', + 'url': url('news-index'), + }, + { + 'title': 'Forum', + 'url': url('forum-index'), + 'menu': [ + { + 'title': 'Leaderboard', + 'url': url('forum-leaderboard'), + 'display': current_user.legacyPerms.forum|default(0)|perms_check(constant('MSZ_PERM_FORUM_VIEW_LEADERBOARD')), + }, + ], + }, + { + 'title': 'Chat', + 'url': 'https://chat.flashii.net', + }, +] %} + +{% set user_menu = + current_user is defined + ? [ + { + 'title': 'Profile', + 'url': url('user-profile', {'user': current_user.id}), + 'icon': 'fas fa-user fa-fw', + }, + { + 'title': 'Settings', + 'url': url('settings-index'), + 'icon': 'fas fa-cog fa-fw', + }, + { + 'title': 'Search', + 'url': url('search-index'), + 'icon': 'fas fa-search fa-fw', + }, + { + 'title': 'Return to Site', + 'url': site_link|default(url('index')), + 'icon': 'fas fa-door-open fa-fw', + 'display': has_manage_access and manage_menu is defined + }, + { + 'title': 'Manage', + 'url': manage_link|default(url('manage-index')), + 'icon': 'fas fa-door-closed fa-fw', + 'display': has_manage_access and manage_menu is not defined + }, + { + 'title': 'Log out', + 'url': url('auth-logout'), + 'icon': 'fas fa-sign-out-alt fa-fw', + }, + ] + : [ + { + 'title': 'Register', + 'url': url('auth-register'), + 'icon': 'fas fa-user-plus fa-fw', + }, + { + 'title': 'Log in', + 'url': url('auth-login'), + 'icon': 'fas fa-sign-in-alt fa-fw', + }, + ] +%} +{% block main_header %} +{% include '_layout/header.twig' %} +{% endblock %} + +
+{% if current_user.hasActiveWarning|default(false) %} +
+
+ You have been {{ current_user.isSilenced ? 'silenced' : 'banned' }} {% if current_user.isActiveWarningPermanent %}permanently{% else %}until {{ current_user.activeWarningExpiration|date('r') }}{% endif %}, view the account standing table on your profile to view why. +
+
+{% endif %} + +{% block content %} +
+ This page is empty, populate it. +
+{% endblock %} +
+ +{% block main_footer %} +{% include '_layout/footer.twig' %} +{% endblock %} + +{% if current_user is defined %} + +{% endif %} + + + + + + + + diff --git a/templates/news/category.twig b/templates/news/category.twig new file mode 100644 index 0000000..afe804b --- /dev/null +++ b/templates/news/category.twig @@ -0,0 +1,70 @@ +{% extends 'news/master.twig' %} +{% from 'macros.twig' import pagination, container_title %} +{% from 'news/macros.twig' import news_preview %} + +{% set title = category_info.name ~ ' :: News' %} +{% set manage_link = url('manage-news-category', {'category': category_info.id}) %} +{% set canonical_url = url('news-category', { + 'category': category_info.id, + 'page': news_pagination.page > 2 ? news_pagination.page : 0, +}) %} + +{% set feeds = [ + { + 'type': 'rss', + 'title': '', + 'url': url('news-category-feed-rss', {'category': category_info.id}), + }, + { + 'type': 'atom', + 'title': '', + 'url': url('news-category-feed-atom', {'category': category_info.id}), + }, +] %} + +{% block content %} +
+
+ {% for post in posts %} + {{ news_preview(post) }} + {% endfor %} + +
+ {{ pagination(news_pagination, url('news-category', {'category':category_info.id})) }} +
+
+ +
+
+ {{ container_title('News » ' ~ category_info.name) }} + +
+ {{ category_info.description }} +
+
+ +
+ {{ container_title('Feeds') }} + + +
+
+
+{% endblock %} diff --git a/templates/news/index.twig b/templates/news/index.twig new file mode 100644 index 0000000..ec7747c --- /dev/null +++ b/templates/news/index.twig @@ -0,0 +1,78 @@ +{% extends 'news/master.twig' %} +{% from 'macros.twig' import pagination, container_title %} +{% from 'news/macros.twig' import news_preview %} + +{% set title = 'News' %} +{% set canonical_url = url('news-index', { + 'page': news_pagination.page > 2 ? news_pagination.page : 0, +}) %} +{% set manage_link = url('manage-news-categories') %} + +{% set feeds = [ + { + 'type': 'rss', + 'title': '', + 'url': url('news-feed-rss'), + }, + { + 'type': 'atom', + 'title': '', + 'url': url('news-feed-atom'), + }, +] %} + +{% block content %} +
+
+ {% for post in posts %} + {{ news_preview(post) }} + {% endfor %} + +
+ {{ pagination(news_pagination, url('news-index')) }} +
+
+ +
+
+ {{ container_title('Categories') }} + + +
+ +
+ {{ container_title('Feeds') }} + + +
+
+
+{% endblock %} diff --git a/templates/news/macros.twig b/templates/news/macros.twig new file mode 100644 index 0000000..658bc24 --- /dev/null +++ b/templates/news/macros.twig @@ -0,0 +1,94 @@ +{% macro news_preview(post) %} + {% from 'macros.twig' import container_title, avatar %} + + +{% endmacro %} + +{% macro news_post(post) %} + {% from 'macros.twig' import avatar %} + +
+ + +
+

{{ post.title }}

+ {{ post.parsedText|raw }} +
+
+{% endmacro %} diff --git a/templates/news/master.twig b/templates/news/master.twig new file mode 100644 index 0000000..fc530f2 --- /dev/null +++ b/templates/news/master.twig @@ -0,0 +1 @@ +{% extends 'master.twig' %} diff --git a/templates/news/post.twig b/templates/news/post.twig new file mode 100644 index 0000000..1e2991f --- /dev/null +++ b/templates/news/post.twig @@ -0,0 +1,19 @@ +{% extends 'news/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from '_layout/comments.twig' import comments_section %} +{% from 'news/macros.twig' import news_post %} + +{% set title = post_info.title ~ ' :: News' %} +{% set canonical_url = url('news-post', {'post': post_info.id}) %} +{% set manage_link = url('manage-news-post', {'post': post_info.id}) %} + +{% block content %} + {{ news_post(post_info) }} + + {% if comments_info is defined %} +
+ {{ container_title(' Comments') }} + {{ comments_section(comments_info, comments_user) }} +
+ {% endif %} +{% endblock %} diff --git a/templates/profile/_layout/header.twig b/templates/profile/_layout/header.twig new file mode 100644 index 0000000..b38c4c7 --- /dev/null +++ b/templates/profile/_layout/header.twig @@ -0,0 +1,110 @@ +{% from 'macros.twig' import avatar %} +{% from '_layout/input.twig' import input_checkbox_raw %} + +
+
+ +
+
+ {% if profile_is_editing and perms.edit_avatar %} + + +
+ + + {{ input_checkbox_raw('avatar[delete]', false, 'profile__header__avatar__check', '', false, {'id':'avatar-delete'}) }} + +
+ {% else %} +
+ {{ avatar(profile_user.id|default(0), 120, profile_user.username|default('')) }} +
+ {% endif %} +
+ +
+ {% if profile_user is defined %} +
+ {{ profile_user.username }} +
+ + {% if profile_user.hasTitle %} +
+ {{ profile_user.title }} +
+ {% endif %} + +
+
+
+ {{ profile_user.countryName }}{% if profile_user.hasAge %},{% set age = profile_user.age %} {{ age }} year{{ age != 's' ? 's' : '' }} old{% endif %} +
+
+ {% else %} +
+ User not found! +
+
+ Check the link and try again. +
+ {% endif %} +
+
+ +
+ {% if profile_user is defined %} +
+ {% if profile_mode is empty %} + {% if profile_is_editing %} + + Discard + Settings + {% elseif profile_can_edit %} + Edit Profile + {% endif %} + {% else %} + Return + {% endif %} +
+ {% endif %} + + {% if stats is defined %} +
+ {% for stat in stats %} + {% if stat.value|default(0) > 0 %} + {% set is_date = stat.is_date|default(false) %} + {% set is_url = stat.url is defined %} + {% set active_class = stat.active|default(false) ? ' profile__header__stat--active' : '' %} + + {% if is_url %} + + {% else %} + {% endif %} + {% endif %} + {% endfor %} +
+ {% endif %} +
+
diff --git a/templates/profile/index.twig b/templates/profile/index.twig new file mode 100644 index 0000000..b3eb10c --- /dev/null +++ b/templates/profile/index.twig @@ -0,0 +1,334 @@ +{% extends 'profile/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from 'user/macros.twig' import user_profile_warning %} +{% from '_layout/input.twig' import input_hidden, input_csrf, input_text, input_checkbox, input_file, input_file_raw, input_select %} + +{% if profile_user is defined %} + {% set canonical_url = url('user-profile', {'user': profile_user.id}) %} + {% set title = profile_user.username %} +{% else %} + {% set title = 'User not found!' %} +{% endif %} + +{% block content %} + {% if profile_is_editing %} +
+ {{ input_csrf('profile') }} + + {% if perms.edit_avatar %} + {{ input_file_raw('avatar[file]', 'profile__hidden', ['image/png', 'image/jpeg', 'image/gif'], {'id':'avatar-selection'}) }} + + + {% endif %} + {% else %} +
+ {% endif %} + + {% include 'profile/_layout/header.twig' %} + + {% if profile_is_editing %} +
+
    +
  • General
  • +
  • Keep things sane and generally suitable for all ages.
  • +
  • Make sure to adhere to the rules.
  • +
+ + {% if perms.edit_avatar %} +
    +
  • Avatar
  • +
  • May not exceed the {{ profile_user.avatarInfo.maxBytes|byte_symbol() }} file size limit.
  • +
  • May not be larger than {{ profile_user.avatarInfo.maxWidth }}x{{ profile_user.avatarInfo.maxHeight }}.
  • +
  • Will be centre cropped and scaled to at most 240x240.
  • +
  • Animated gif images are allowed.
  • +
+ {% endif %} + + {% if perms.edit_background %} +
    +
  • Background
  • +
  • May not exceed the {{ profile_user.backgroundInfo.maxBytes|byte_symbol() }} file size limit.
  • +
  • May not be larger than {{ profile_user.backgroundInfo.maxWidth }}x{{ profile_user.backgroundInfo.maxHeight }}.
  • +
  • Gif images, in general, are only allowed when tiling.
  • +
+ {% endif %} +
+ {% endif %} + + {% if profile_notices|length > 0 %} +
+
+ {% for notice in profile_notices %} +

{{ notice }}

+ {% endfor %} +
+
+ {% endif %} + +
+ {% set profile_fields = profile_user.profileFields(not (profile_is_editing and perms.edit_profile))|default([]) %} + {% set show_profile_fields = profile_is_editing ? perms.edit_profile : profile_fields|length > 0 %} + {% set show_background_settings = profile_is_editing and perms.edit_background %} + {% set show_birthdate = profile_is_editing and perms.edit_birthdate %} + {% set show_sidebar = current_user is not defined or show_profile_fields or show_background_settings %} + + {% if show_sidebar %} +
+ {% if show_background_settings %} +
+ {{ container_title('Background') }} + +
+ {{ input_file('background[file]', '', ['image/png', 'image/jpeg', 'image/gif'], {'id':'background-selection'}) }} + + {{ input_checkbox('background[attach]', 'None', true, '', 0, true, {'onchange':'profileChangeBackgroundAttach(this.value)'}) }} + {% for key, value in background_attachments %} + {{ input_checkbox('background[attach]', value, key == profile_user.backgroundInfo.attachment, '', key, true, {'onchange':'profileChangeBackgroundAttach(this.value)'}) }} + {% endfor %} + + {{ input_checkbox('background[attr][blend]', 'Blend', profile_user.backgroundInfo.blend, '', '', false, {'onchange':'profileToggleBackgroundAttr(\'blend\', this.checked)'}) }} + {{ input_checkbox('background[attr][slide]', 'Slide', profile_user.backgroundInfo.slide, '', '', false, {'onchange':'profileToggleBackgroundAttr(\'slide\', this.checked)'}) }} +
+
+ {% endif %} + {% if current_user is not defined %} +
+
+ You must log in to view full profiles! +
+
+ {% elseif show_profile_fields %} +
+ {{ container_title('Elsewhere') }} + +
+ {% for field in profile_fields %} + + {% endfor %} +
+
+ {% endif %} + {% if show_birthdate %} +
+ {{ container_title('Birthdate') }} + +
+
+ + + +
+ +
+ +
+
+
+ {% endif %} +
+ {% endif %} + + {% if profile_user is defined %} +
+ {% if (profile_is_editing and perms.edit_about) or profile_user.hasProfileAbout %} +
+ {{ container_title('About ' ~ profile_user.username) }} + + {% if profile_is_editing %} +
+ {{ input_select('about[parser]', constant('\\Misuzu\\Parsers\\Parser::NAMES'), profile_user.profileAboutParser, '', '', false, 'profile__about__select') }} + +
+ {% else %} +
+ {{ profile_user.profileAboutParsed|raw }} +
+ {% endif %} +
+ {% endif %} + + {% if (profile_is_editing and perms.edit_signature) or profile_user.hasForumSignature %} +
+ {{ container_title('Signature') }} + + {% if profile_is_editing %} +
+ {{ input_select('signature[parser]', constant('\\Misuzu\\Parsers\\Parser::NAMES'), profile_user.forumSignatureParser, '', '', false, 'profile__signature__select') }} + +
+ {% else %} +
+ {{ profile_user.forumSignatureParsed|raw }} +
+ {% endif %} +
+ {% endif %} + + {% if profile_warnings|length > 0 or profile_warnings_can_manage %} +
+ {{ container_title('Account Standing', false, profile_warnings_can_manage ? url('manage-users-warnings', {'user': profile_user.id}) : '') }} + +
+
+ + {% if profile_warnings_can_manage %} +
+
+
+ User IP +
+
+ +
+
+ Issuer +
+
+ Issuer IP +
+
+
+ {% endif %} + +
+
+ Type +
+ +
+ Created +
+ +
+ Duration +
+ +
+ Note +
+
+
+ + {% for warning in profile_warnings %} + {{ user_profile_warning(warning, profile_warnings_view_private, profile_warnings_can_manage, profile_warnings_can_manage ? csrf_token() : '') }} + {% endfor %} +
+ {% endif %} + {% endif %} +
+
+ {% if profile_is_editing %} + + + {% else %} +
+ {% endif %} +{% endblock %} diff --git a/templates/profile/master.twig b/templates/profile/master.twig new file mode 100644 index 0000000..4e8224a --- /dev/null +++ b/templates/profile/master.twig @@ -0,0 +1,46 @@ +{% extends 'master.twig' %} + +{% if profile_user is defined %} + {% set image = url('user-avatar', {'user': profile_user.id, 'res': 200}) %} + {% set manage_link = url('manage-user', {'user': profile_user.id}) %} + {% if profile_user.hasBackground %} + {% set site_background = profile_user.backgroundInfo %} + {% endif %} + {% set stats = [ + { + 'title': 'Joined', + 'is_date': true, + 'value': profile_user.createdTime, + }, + { + 'title': 'Last seen', + 'is_date': true, + 'value': profile_user.activeTime, + }, + { + 'title': 'Topics', + 'value': profile_stats.forum_topic_count, + 'url': url('user-profile-forum-topics', {'user': profile_user.id}), + 'active': profile_mode == 'forum-topics', + }, + { + 'title': 'Posts', + 'value': profile_stats.forum_post_count, + 'url': url('user-profile-forum-posts', {'user': profile_user.id}), + 'active': profile_mode == 'forum-posts', + }, + { + 'title': 'Comments', + 'value': profile_stats.comments_count, + }, + { + 'title': 'Changes', + 'value': profile_stats.changelog_count, + }, + ] %} +{% else %} + {% set image = url('user-avatar', {'user': 0, 'res': 240}) %} + {% set manage_link = url('manage-users') %} + {% set profile_is_editing = false %} + {% set profile_notices = [] %} +{% endif %} diff --git a/templates/profile/posts.twig b/templates/profile/posts.twig new file mode 100644 index 0000000..bbb02b6 --- /dev/null +++ b/templates/profile/posts.twig @@ -0,0 +1,23 @@ +{% extends 'profile/master.twig' %} +{% from 'macros.twig' import pagination %} +{% from 'forum/macros.twig' import forum_post_listing %} + +{% block content %} +
+ {% include 'profile/_layout/header.twig' %} + + {% set sp = profile_posts_pagination.pages > 1 + ? '
' ~ pagination(profile_posts_pagination, canonical_url) ~ '
' + : '' %} + + {% if sp is not empty %} + {{ sp|raw }} + {% endif %} + + {{ forum_post_listing(profile_posts) }} + + {% if sp is not empty %} + {{ sp|raw }} + {% endif %} +
+{% endblock %} diff --git a/templates/profile/relations.twig b/templates/profile/relations.twig new file mode 100644 index 0000000..3fadaa7 --- /dev/null +++ b/templates/profile/relations.twig @@ -0,0 +1,23 @@ +{% extends 'profile/master.twig' %} +{% from 'macros.twig' import pagination %} +{% from 'user/macros.twig' import user_card %} + +{% block content %} +
+ {% include 'profile/_layout/header.twig' %} + +
+ {% for user in profile_users %} +
+ {{ user_card(attribute(user, relation_prop), profile_viewer) }} +
+ {% endfor %} +
+ + {% if profile_relation_pagination.pages > 1 %} +
+ {{ pagination(profile_relation_pagination, canonical_url) }} +
+ {% endif %} +
+{% endblock %} diff --git a/templates/profile/topics.twig b/templates/profile/topics.twig new file mode 100644 index 0000000..1277302 --- /dev/null +++ b/templates/profile/topics.twig @@ -0,0 +1,23 @@ +{% extends 'profile/master.twig' %} +{% from 'macros.twig' import pagination %} +{% from 'forum/macros.twig' import forum_topic_listing %} + +{% block content %} +
+ {% include 'profile/_layout/header.twig' %} + + {% set sp = profile_topics_pagination.pages > 1 + ? '
' ~ pagination(profile_topics_pagination, canonical_url) ~ '
' + : '' %} + + {% if sp is not empty %} + {{ sp|raw }} + {% endif %} + + {{ forum_topic_listing(profile_topics) }} + + {% if sp is not empty %} + {{ sp|raw }} + {% endif %} +
+{% endblock %} diff --git a/templates/settings/account.twig b/templates/settings/account.twig new file mode 100644 index 0000000..1bc399c --- /dev/null +++ b/templates/settings/account.twig @@ -0,0 +1,144 @@ +{% extends 'settings/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from '_layout/input.twig' import input_hidden, input_csrf, input_text, input_select %} + +{% set title = 'Settings / Account' %} + +{% block settings_content %} +
+ {{ container_title(' Account') }} + {{ input_csrf() }} + +
+

Here you can change your e-mail address and/or your password, please make sure your e-mail is accurate and your password is strong in order to protect your account. For convenience your current e-mail address is displayed. You are required to verify yourself by entering your current password to change either value.

+
+ + +
+ + {% if not is_restricted %} +
+ {{ container_title(' Roles') }} + +
+

This is a listing of the user roles you're a part of, you can select which you want to leave or which one you want to boast as your main role which will change your username colour accordingly.

+
+ +
+ {% for role in settings_user.roles %} + {% set is_display_role = settings_user.isDisplayRole(role) %} + +
+
+
+ {{ role.name }} +
+ +
+ {{ role.description }} +
+ +
+ {{ input_csrf() }} + {{ input_hidden('role[id]', role.id) }} + + + + +
+
+
+ {% endfor %} +
+
+ {% endif %} + +
+ {{ container_title(' Two Factor Authentication') }} + {{ input_csrf() }} + +
+

Secure your account by requiring a second step during log in in the form of a time based code. You can use applications like Authy, Google or Microsoft Authenticator or other compliant TOTP applications.

+
+ +
+ {% if settings_2fa_image is defined and settings_2fa_code is defined %} +
+
+ {{ settings_2fa_code }} +
+ {{ settings_2fa_code }} +
+ {% endif %} + +
+ {% if settings_user.hasTOTP %} +
+ Two Factor Authentication is enabled! +
+ + {% else %} +
+ Two Factor Authentication is disabled. +
+ + {% endif %} +
+
+
+{% endblock %} diff --git a/templates/settings/data.twig b/templates/settings/data.twig new file mode 100644 index 0000000..3a32e6b --- /dev/null +++ b/templates/settings/data.twig @@ -0,0 +1,42 @@ +{% extends 'settings/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from '_layout/input.twig' import input_hidden, input_csrf, input_text, input_select %} + +{% set title = 'Settings / Data' %} + +{% block settings_content %} +
+ {{ container_title(' Download account data') }} + {{ input_csrf() }} + +
+

Here you can request raw json files containing pretty much all data relating to your account. Moderator identities are concealed and password hashes are removed from the output.

+
+ +
+ {{ input_text('password', 'settings__data__password', '', 'password', 'Password', true) }} + +
+ +
+
+
+ + {#
+ {{ container_title(' Deactivate account') }} + {{ input_csrf() }} + +
+

Deactivation will mark your account for deletion after 7 days unless you log in again. All content associated with your account EXCEPT forum topics and posts will be irrecoverably removed after these 7 days. Forum topics and posts will become associated with a default user effectively removing your identity from them. If you wish to have your forum posts removed please contact staff.

+

Temporarily deactivating as a means to gain attention of some kind is frowned upon and you will likely be banned after returning. Use this feature cautiously.

+
+ +
+ {{ input_text('password', 'settings__data__password', '', 'password', 'Password', true) }} + +
+ +
+
+
#} +{% endblock %} diff --git a/templates/settings/logs.twig b/templates/settings/logs.twig new file mode 100644 index 0000000..e2c0213 --- /dev/null +++ b/templates/settings/logs.twig @@ -0,0 +1,63 @@ +{% extends 'settings/master.twig' %} +{% from 'macros.twig' import container_title, pagination %} +{% from 'user/macros.twig' import user_login_attempt, user_account_log %} + +{% set title = 'Settings / Logs' %} + +{% block settings_content %} +
+ {{ container_title(' Login History') }} + {% set lhpagination = pagination(login_history_pagination, url('settings-logs'), null, { + 'ap': account_log_pagination.page > 1 ? account_log_pagination.page : 0, + }, 'hp', 'login-history') %} + +
+

These are all the login attempts to your account. If any attempt that you don't recognise is marked as successful your account may be compromised, ask a staff member for advice in this case.

+
+ + +
+ +
+ {{ container_title(' Account Log') }} + {% set alpagination = pagination(account_log_pagination, url('settings-logs'), null, { + 'hp': login_history_pagination.page > 1 ? login_history_pagination.page : 0, + }, 'ap', 'account-log') %} + +
+

This is a log of all "important" actions that have been done using your account for your review. If you notice anything strange, please alert the staff.

+
+ + +
+{% endblock %} diff --git a/templates/settings/master.twig b/templates/settings/master.twig new file mode 100644 index 0000000..cb5256e --- /dev/null +++ b/templates/settings/master.twig @@ -0,0 +1,56 @@ +{% extends 'master.twig' %} +{% from 'macros.twig' import container_title %} + +{% set menu = [ + { + 'icon': 'fas fa-user fa-fw', + 'title': 'Account', + 'url': url('settings-account'), + }, + { + 'icon': 'fas fa-key fa-fw', + 'title': 'Sessions', + 'url': url('settings-sessions'), + }, + { + 'icon': 'fas fa-file-alt fa-fw', + 'title': 'Logs', + 'url': url('settings-logs'), + }, + { + 'icon': 'fas fa-database fa-fw', + 'title': 'Data', + 'url': url('settings-data'), + }, +] %} + +{% block content %} + {% if errors is defined and errors|length > 0 %} +
+
+ {% for error in errors %} + {{ error }} + {% endfor %} +
+
+ {% endif %} + +
+
+
+ {{ container_title(' Settings') }} + + {% for item in menu %} + + {{ item.title }} + + {% endfor %} +
+
+ +
+ {% block settings_content %} + {% endblock %} +
+
+{% endblock %} diff --git a/templates/settings/sessions.twig b/templates/settings/sessions.twig new file mode 100644 index 0000000..5c13bbb --- /dev/null +++ b/templates/settings/sessions.twig @@ -0,0 +1,43 @@ +{% extends 'settings/master.twig' %} +{% from 'macros.twig' import container_title, pagination %} +{% from 'user/macros.twig' import user_session %} +{% from '_layout/input.twig' import input_hidden, input_csrf %} + +{% set title = 'Settings / Sessions' %} + +{% block settings_content %} +
+ {{ container_title(' Sessions') }} + + {% set spagination = pagination(session_pagination, url('settings-sessions')) %} + +
+

These are the active logins to your account, clicking the Kill button will force a logout on that session. Your current login is highlighted with a different colour so you don't accidentally force yourself to logout.

+
+ +
+
+ {{ input_csrf() }} + {{ input_hidden('session', 'all') }} + + +
+ +
+ {{ spagination }} +
+ +
+ {% for session in session_list %} + {{ user_session(session, session_current.id == session.id) }} + {% endfor %} +
+ +
+ {{ spagination }} +
+
+
+{% endblock %} diff --git a/templates/user/listing.twig b/templates/user/listing.twig new file mode 100644 index 0000000..64b3b3f --- /dev/null +++ b/templates/user/listing.twig @@ -0,0 +1,68 @@ +{% extends 'user/master.twig' %} +{% from 'macros.twig' import container_title %} +{% from 'user/macros.twig' import user_card %} + +{% set url_role = role.id > 1 ? role.id : 0 %} +{% set url_sort = order_field == order_default ? '' : order_field %} +{% set url_direction = order_fields[order_field]['default-dir'] == order_direction ? '' : order_direction %} +{% set canonical_url = url('user-list', { + 'role': url_role, + 'sort': url_sort, + 'direction': url_direction, + 'page': users_pagination.page|default(0) > 2 ? users_pagination.page : 0, +}) %} +{% set title = role.id == 1 ? 'Members' : 'Role » ' ~ role.name %} +{% set manage_link = url('manage-users') %} + +{% macro member_nav(roles, role_id, orders, order, directions, direction, users_pagination, url_role, url_sort, url_direction) %} + {% from 'macros.twig' import pagination %} + {% from '_layout/input.twig' import input_select %} + +
+
+ {{ input_select('r', roles, role_id, 'name', 'id', false, 'userlist__select') }} + {{ input_select('ss', orders, order, 'title', null, false, 'userlist__select') }} + {{ input_select('sd', directions, direction, null, null, false, 'userlist__select') }} + + +
+ +
+ {{ pagination(users_pagination, url('user-list'), null, {'r': url_role, 'ss': url_sort, 'sd': url_direction}) }} +
+
+{% endmacro %} + +{% block content %} + {% from _self import member_nav %} + {% set member_nav = member_nav( + roles, role.id, + order_fields, order_field, + order_directions, order_direction, + users_pagination, url_role, url_sort, url_direction + ) %} + +
+ {{ member_nav }} +
+ + {% if users|length > 0 %} +
+ {% for user in users %} +
+ {{ user_card(user) }} +
+ {% endfor %} +
+ {% else %} +
+ This role has no members +
+ {% endif %} + +
+ {{ member_nav }} +
+{% endblock %} diff --git a/templates/user/macros.twig b/templates/user/macros.twig new file mode 100644 index 0000000..afd37bf --- /dev/null +++ b/templates/user/macros.twig @@ -0,0 +1,461 @@ +{% macro user_card(user, current_user) %} + {% if user.getId is defined %} + {% from _self import user_card_new %} + {{ user_card_new(user, current_user) }} + {% else %} + {% from _self import user_card_old %} + {{ user_card_old(user) }} + {% endif %} +{% endmacro %} + +{% macro user_card_new(user, current_user) %} + {% from 'macros.twig' import avatar %} + +
+
+ +
+ + +
+
+ {{ avatar(user.id, 60, user.username) }} +
+ +
+
+ {{ user.username }} +
+ + {% if user.hasTitle %} +
+ {{ user.title }} +
+ {% endif %} + + {% if user.hasCountry %} +
+
+
+ {{ user.countryName }} +
+
+ {% endif %} +
+
+
+ +
+
+ {% if user.forumTopicCount > 0 %} + +
+ Topics +
+
+ {{ user.forumTopicCount|number_format }} +
+
+ {% endif %} + + {% if user.forumPostCount > 0 %} + +
+ Posts +
+
+ {{ user.forumPostCount|number_format }} +
+
+ {% endif %} +
+ +
+
+ Joined +
+ + {% if user.hasBeenActive %} +
+ Last seen +
+ {% else %} +
+ Never logged in +
+ {% endif %} +
+ +
+ + + +
+
+
+{% endmacro %} + +{% macro user_card_old(user) %} + {% from 'macros.twig' import avatar %} + +
+
+ +
+ + +
+
+ {{ avatar(user.user_id, 60, user.username) }} +
+ +
+
+ {{ user.username }} +
+ + {% if user.user_title is defined and user.user_title is not empty %} +
+ {{ user.user_title }} +
+ {% endif %} + + {% if user.user_country|default('XX') != 'XX' %} +
+
+
+ {{ user.user_country|country_name }} +
+
+ {% endif %} +
+
+
+ +
+
+ {% if user.user_count_topics|default(0) > 0 %} + +
+ Topics +
+
+ {{ user.user_count_topics|number_format }} +
+
+ {% endif %} + + {% if user.user_count_posts|default(0) > 0 %} + +
+ Posts +
+
+ {{ user.user_count_posts|number_format }} +
+
+ {% endif %} +
+ +
+ {% if user.user_created is defined %} +
+ Joined +
+ {% endif %} + + {% if user.user_active is defined %} + {% if user.user_active is null %} +
+ Never logged in +
+ {% else %} +
+ Last seen +
+ {% endif %} + {% endif %} +
+ +
+ + + +
+
+
+{% endmacro %} + +{% macro user_session(session, is_current_session) %} + {% from '_layout/input.twig' import input_hidden, input_csrf, input_checkbox_raw %} + +
+
+
+
{{ session.country }}
+ +
+ {{ session.userAgentInfo.toString }} +
+ +
+ {{ input_csrf() }} + {{ input_hidden('session[]', session.id) }} + + +
+
+ +
+
+
+ Created from IP +
+
+ {{ session.initialRemoteAddress }} +
+
+ + {% if session.hasLastRemoteAddress %} +
+
+ Last used from IP +
+
+ {{ session.lastRemoteAddress }} +
+
+ {% endif %} + +
+
+ Created +
+ +
+ +
+
+ Expires{% if not session.shouldBumpExpire %} (static){% endif %} +
+ +
+ + {% if session.hasActiveTime %} +
+
+ Last Active +
+ +
+ {% endif %} + +
+
+ User Agent +
+
+ {{ session.userAgent is empty ? 'None' : session.userAgent }} +
+
+
+
+
+{% endmacro %} + +{% macro user_login_attempt(attempt) %} + +{% endmacro %} + +{% macro user_account_log(data, is_manage) %} + {% from 'macros.twig' import avatar %} + + +{% endmacro %} + +{% macro user_profile_warning(warning, show_private_note, show_user_info, delete_csrf) %} + {% from 'macros.twig' import avatar %} + {% if warning.isSilence %} + {% set warning_text = 'Silence' %} + {% set warning_class = 'silence' %} + {% elseif warning.isBan %} + {% set warning_text = 'Ban' %} + {% set warning_class = 'ban' %} + {% elseif warning.isWarning %} + {% set warning_text = 'Warning' %} + {% set warning_class = 'warning' %} + {% else %} + {% set warning_text = 'Note' %} + {% set warning_class = 'note' %} + {% endif %} + + +{% endmacro %} diff --git a/templates/user/master.twig b/templates/user/master.twig new file mode 100644 index 0000000..fc530f2 --- /dev/null +++ b/templates/user/master.twig @@ -0,0 +1 @@ +{% extends 'master.twig' %} diff --git a/utility.php b/utility.php new file mode 100644 index 0000000..b79a09e --- /dev/null +++ b/utility.php @@ -0,0 +1,216 @@ + $value) + $array1[$key] |= $array2[$key] ?? 0; + return $array1; +} + +function array_rand_value(array $array) { + return $array[mt_rand(0, count($array) - 1)]; +} + +function array_find(array $array, callable $callback) { + foreach($array as $item) + if($callback($item)) + return $item; + return null; +} + +function clamp($num, int $min, int $max): int { + return max($min, min($max, intval($num))); +} + +function starts_with(string $string, string $text): bool { + return str_starts_with($string, $text); +} + +function ends_with(string $string, string $text): bool { + return str_ends_with($string, $text); +} + +function first_paragraph(string $text, string $delimiter = "\n"): string { + $index = mb_strpos($text, $delimiter); + return $index === false ? $text : mb_substr($text, 0, $index); +} + +function unique_chars(string $input, bool $multibyte = true): int { + $chars = []; + $strlen = $multibyte ? 'mb_strlen' : 'strlen'; + $substr = $multibyte ? 'mb_substr' : 'substr'; + $length = $strlen($input); + + for($i = 0; $i < $length; $i++) { + $current = $substr($input, $i, 1); + + if(!in_array($current, $chars, true)) { + $chars[] = $current; + } + } + + return count($chars); +} + +function byte_symbol(int $bytes, bool $decimal = false, array $symbols = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']): string { + if($bytes < 1) + return '0 B'; + + $divider = $decimal ? 1000 : 1024; + $exp = floor(log($bytes) / log($divider)); + $bytes = $bytes / pow($divider, $exp); + $symbol = $symbols[$exp]; + + return sprintf("%.2f %s%sB", $bytes, $symbol, $symbol !== '' && !$decimal ? 'i' : ''); +} + +function get_country_name(string $code, string $locale = 'en'): string { + $code = strtolower($code); + switch($code) { + case 'xx': + return 'Unknown'; + case 'a1': + return 'Anonymous Proxy'; + case 'a2': + return 'Satellite Provider'; + case 'cn': + return 'West Taiwan'; + case 'xm': + return 'The Moon'; + default: + return \Locale::getDisplayRegion("-{$code}", $locale); + } +} + +// render_error, render_info and render_info_or_json should be redone a bit better +// following a uniform format so there can be a global handler for em + +function render_error(int $code, string $template = 'errors.%d'): string { + return render_info(null, $code, $template); +} + +function render_info(?string $message, int $httpCode, string $template = 'errors.%d'): string { + http_response_code($httpCode); + + \Misuzu\Template::set('http_code', $httpCode); + + if(!empty($message)) + \Misuzu\Template::set('message', $message); + + $template = sprintf($template, $httpCode); + + /*if(!tpl_exists($template)) { + $template = 'errors.master'; + }*/ + + return \Misuzu\Template::renderRaw(sprintf($template, $httpCode)); +} + +function render_info_or_json(bool $json, string $message, int $httpCode = 200, string $template = 'errors.%d'): string { + $error = $httpCode >= 400; + http_response_code($httpCode); + + if($json) { + return json_encode([($error ? 'error' : 'message') => $message, 'success' => $error]); + } + + return render_info($message, $httpCode, $template); +} + +function html_colour(?int $colour, $attribs = '--user-colour'): string { + $colour = $colour == null ? \Misuzu\Colour::none() : new \Misuzu\Colour($colour); + + if(is_string($attribs)) { + $attribs = [ + $attribs => '%s', + ]; + } + + if(!$attribs) { + $attribs = [ + 'color' => '%s', + '--user-colour' => '%s', + ]; + } + + $css = ''; + $value = $colour->getCSS(); + + foreach($attribs as $name => $format) { + $css .= $name . ':' . sprintf($format, $value) . ';'; + } + + return $css; +} + +function html_avatar(?int $userId, int $resolution, string $altText = '', array $attributes = []): string { + $attributes['src'] = url('user-avatar', ['user' => $userId ?? 0, 'res' => $resolution * 2]); + $attributes['alt'] = $altText; + $attributes['class'] = trim('avatar ' . ($attributes['class'] ?? '')); + + if(!isset($attributes['width'])) + $attributes['width'] = $resolution; + if(!isset($attributes['height'])) + $attributes['height'] = $resolution; + + return html_tag('img', $attributes); +} + +function html_tag(string $name, array $atrributes = [], ?bool $close = null, string $content = ''): string { + $html = '<' . $name; + + foreach($atrributes as $key => $value) { + $html .= ' ' . $key; + + if(!empty($value)) + $html .= '="' . $value . '"'; + } + + if($close === false) + $html .= '/'; + + $html .= '>'; + + if($close === true) + $html .= $content . ''; + + return $html; +} + +function msz_server_timing(\Index\Performance\Timings $timings): string { + $laps = $timings->getLaps(); + $timings = []; + + foreach($laps as $lap) { + $timing = $lap->getName(); + if($lap->hasComment()) + $timing .= ';desc="' . strtr($lap->getComment(), ['"' => '\\"']) . '"'; + + $timing .= ';dur=' . round($lap->getDurationTime(), 5); + $timings[] = $timing; + } + + return sprintf('Server-Timing: %s', implode(', ', $timings)); +} + +function msz_cookie_domain(bool $compatible = true): string { + $url = parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST); + if(empty($url)) + $url = $_SERVER['HTTP_HOST']; + + if(!filter_var($url, FILTER_VALIDATE_IP) && $compatible) + $url = '.' . $url; + + return $url; +}