Skip to content
Permalink
Browse files

Code style updates.

  • Loading branch information...
flashwave committed Jun 10, 2019
1 parent 295944a commit b416bfb030eeabd25a24d612bca4f9b1af4e04ea
Showing with 1,425 additions and 1,830 deletions.
  1. +6 −6 assets/typescript/Colour.ts
  2. +37 −37 assets/typescript/Comments.tsx
  3. +11 −14 assets/typescript/FormUtilities.ts
  4. +8 −8 assets/typescript/Forum/Polls.ts
  5. +13 −14 assets/typescript/Forum/Posting.ts
  6. +1 −1 assets/typescript/Permissions.ts
  7. +14 −18 assets/typescript/UrlRegistry.ts
  8. +7 −11 assets/typescript/User.ts
  9. +16 −17 assets/typescript/UserRelations.ts
  10. +13 −13 assets/typescript/misuzu.ts
  11. +25 −30 build.php
  12. +37 −37 misuzu.php
  13. +1 −1 public/auth.php
  14. +17 −17 public/auth/password.php
  15. +12 −12 public/auth/register.php
  16. +9 −9 public/auth/twofactor.php
  17. +6 −6 public/changelog.php
  18. +40 −40 public/comments.php
  19. +8 −8 public/forum/forum.php
  20. +5 −5 public/forum/index.php
  21. +1 −1 public/forum/leaderboard.php
  22. +15 −15 public/forum/poll.php
  23. +33 −33 public/forum/post.php
  24. +41 −41 public/forum/posting.php
  25. +6 −6 public/forum/topic-priority.php
  26. +37 −37 public/forum/topic.php
  27. +2 −2 public/index.php
  28. +9 −9 public/info.php
  29. +1 −1 public/manage/changelog/change.php
  30. +4 −4 public/manage/changelog/tag.php
  31. +2 −2 public/manage/general/blacklist.php
  32. +1 −1 public/manage/general/logs.php
  33. +7 −7 public/manage/users/role.php
  34. +1 −1 public/manage/users/user.php
  35. +0 −7 public/manage/users/warning.php
  36. +3 −3 public/manage/users/warnings.php
  37. +6 −6 public/members.php
  38. +3 −3 public/news.php
  39. +2 −2 public/news/category.php
  40. +2 −2 public/news/feed.php
  41. +2 −2 public/news/index.php
  42. +3 −3 public/news/post.php
  43. +41 −41 public/profile.php
  44. +6 −6 public/proxy.php
  45. +10 −10 public/relations.php
  46. +1 −1 public/search.php
  47. +4 −4 public/settings/account.php
  48. +1 −1 public/settings/index.php
  49. +1 −1 public/settings/sessions.php
  50. +13 −15 public/user-assets.php
  51. +29 −38 src/DatabaseMigrationManager.php
  52. +41 −59 src/Forum/forum.php
  53. +18 −17 src/Forum/leaderboard.php
  54. +24 −23 src/Forum/perms.php
  55. +23 −35 src/Forum/poll.php
  56. +31 −34 src/Forum/post.php
  57. +58 −65 src/Forum/topic.php
  58. +6 −8 src/Forum/validate.php
  59. +6 −10 src/Net/geoip.php
  60. +31 −47 src/Net/ip.php
  61. +7 −15 src/Parsers/BBCode/BBCodeParser.php
  62. +2 −4 src/Parsers/BBCode/BBCodeSimpleTag.php
  63. +1 −2 src/Parsers/BBCode/BBCodeTag.php
  64. +3 −5 src/Parsers/BBCode/Tags/AudioTag.php
  65. +3 −6 src/Parsers/BBCode/Tags/BoldTag.php
  66. +2 −4 src/Parsers/BBCode/Tags/CodeTag.php
  67. +2 −4 src/Parsers/BBCode/Tags/ImageTag.php
  68. +3 −6 src/Parsers/BBCode/Tags/ItalicsTag.php
  69. +3 −5 src/Parsers/BBCode/Tags/LinkifyTag.php
  70. +3 −6 src/Parsers/BBCode/Tags/NamedUrlTag.php
  71. +3 −6 src/Parsers/BBCode/Tags/NewLineTag.php
  72. +3 −5 src/Parsers/BBCode/Tags/QuoteTag.php
  73. +3 −6 src/Parsers/BBCode/Tags/StrikeTag.php
  74. +3 −6 src/Parsers/BBCode/Tags/UnderlineTag.php
  75. +3 −6 src/Parsers/BBCode/Tags/UrlTag.php
  76. +8 −10 src/Parsers/BBCode/Tags/VideoTag.php
  77. +2 −4 src/Parsers/BBCode/Tags/ZalgoTag.php
  78. +5 −9 src/Parsers/MarkdownParser.php
  79. +1 −2 src/Parsers/ParserInterface.php
  80. +8 −12 src/Parsers/parse.php
  81. +4 −7 src/Twig.php
  82. +5 −9 src/TwigMisuzu.php
  83. +6 −10 src/Users/auth.php
  84. +19 −26 src/Users/avatar.php
  85. +18 −25 src/Users/background.php
  86. +6 −10 src/Users/login_attempt.php
  87. +25 −34 src/Users/profile.php
  88. +5 −10 src/Users/recovery.php
  89. +37 −28 src/Users/relations.php
  90. +12 −22 src/Users/role.php
  91. +25 −40 src/Users/session.php
  92. +42 −65 src/Users/user.php
  93. +15 −19 src/Users/validation.php
  94. +23 −34 src/Users/warning.php
  95. +10 −17 src/WhoopsReporter.php
  96. +7 −10 src/array.php
  97. +7 −10 src/audit_log.php
  98. +5 −7 src/base32.php
  99. +12 −19 src/changelog.php
  100. +23 −39 src/colour.php
  101. +25 −40 src/comments.php
  102. +6 −10 src/config.php
  103. +19 −30 src/db.php
  104. +4 −8 src/git.php
  105. +1 −2 src/integer.php
  106. +14 −19 src/mail.php
  107. +6 −12 src/manage.php
  108. +17 −22 src/news.php
  109. +5 −9 src/otp.php
  110. +9 −14 src/pagination.php
  111. +31 −46 src/perms.php
  112. +12 −22 src/string.php
  113. +10 −17 src/tpl.php
  114. +7 −11 src/twitter.php
  115. +29 −38 src/url.php
  116. +12 −16 src/zalgo.php
  117. +7 −7 templates/profile/index.twig
  118. +26 −36 utility.php
@@ -13,7 +13,7 @@ function colourNone(): number {
}

function colourSetInherit(colour: number, enabled: boolean): number {
if (enabled) {
if(enabled) {
colour |= MSZ_COLOUR_INHERIT;
} else {
colour &= ~MSZ_COLOUR_INHERIT;
@@ -70,7 +70,7 @@ function colourGetHex(colour: number): string {
}

function colourGetCSS(colour: number): string {
if (colourGetInherit(colour)) {
if(colourGetInherit(colour)) {
return 'inherit';
}

@@ -83,7 +83,7 @@ function colourGetCSSContrast(
light: string = 'light',
inheritIsDark: boolean = true
): string {
if (colourGetInherit(colour)) {
if(colourGetInherit(colour)) {
return inheritIsDark ? dark : light;
}

@@ -101,14 +101,14 @@ function colourFromRGB(red: number, green: number, blue: number): number {
}

function colourFromHex(hex: string): number {
if (hex.startsWith('#'))
if(hex.startsWith('#'))
hex = hex.substr(1);

const length: number = hex.length;

if (length === 3) {
if(length === 3) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
} else if (length !== 6) {
} else if(length !== 6) {
return 0;
}

@@ -45,7 +45,7 @@ function commentDeleteEventHandler(ev: Event): void {
info => {
let elem = document.getElementById('comment-' + info.id);

if (elem)
if(elem)
elem.parentNode.removeChild(elem);
},
message => messageBox(message)
@@ -54,26 +54,26 @@ function commentDeleteEventHandler(ev: Event): void {

function commentDelete(commentId: number, onSuccess: (info: CommentDeletionInfo) => void = null, onFail: (message: string) => void = null): void
{
if (!checkUserPerm('comments', CommentPermission.Delete)) {
if (onFail)
if(!checkUserPerm('comments', CommentPermission.Delete)) {
if(onFail)
onFail("You aren't allowed to delete comments.");
return;
}

const xhr: XMLHttpRequest = new XMLHttpRequest;

xhr.addEventListener('readystatechange', () => {
if (xhr.readyState !== 4)
if(xhr.readyState !== 4)
return;

updateCSRF(xhr.getResponseHeader('X-Misuzu-CSRF'));

let json: CommentDeletionInfo = JSON.parse(xhr.responseText) as CommentDeletionInfo,
message = json.error || json.message;

if (message && onFail)
if(message && onFail)
onFail(message);
else if (!message && onSuccess)
else if(!message && onSuccess)
onSuccess(json);
});
xhr.open('GET', urlFormat('comments-delete', [{name:'comment',value:commentId}]));
@@ -85,7 +85,7 @@ function commentPostEventHandler(ev: Event): void
{
const form: HTMLFormElement = ev.target as HTMLFormElement;

if (form.dataset.disabled)
if(form.dataset.disabled)
return;
form.dataset.disabled = '1';
form.style.opacity = '0.5';
@@ -99,26 +99,26 @@ function commentPostEventHandler(ev: Event): void

function commentPost(formData: FormData, onSuccess: (comment: CommentPostInfo) => void = null, onFail: (message: string) => void = null): void
{
if (!checkUserPerm('comments', CommentPermission.Create)) {
if (onFail)
if(!checkUserPerm('comments', CommentPermission.Create)) {
if(onFail)
onFail("You aren't allowed to post comments.");
return;
}

const xhr = new XMLHttpRequest();

xhr.addEventListener('readystatechange', () => {
if (xhr.readyState !== 4)
if(xhr.readyState !== 4)
return;

updateCSRF(xhr.getResponseHeader('X-Misuzu-CSRF'));

const json: CommentPostInfo = JSON.parse(xhr.responseText) as CommentPostInfo,
message: string = json.error || json.message;

if (message && onFail)
if(message && onFail)
onFail(message);
else if (!message && onSuccess)
else if(!message && onSuccess)
onSuccess(json);
});

@@ -128,7 +128,7 @@ function commentPost(formData: FormData, onSuccess: (comment: CommentPostInfo) =
}

function commentPostSuccess(form: HTMLFormElement, comment: CommentPostInfo): void {
if (form.classList.contains('comment--reply'))
if(form.classList.contains('comment--reply'))
(form.parentNode.parentNode.querySelector('label.comment__action') as HTMLLabelElement).click();

commentInsert(comment, form);
@@ -145,38 +145,38 @@ function commentPostFail(form: HTMLFormElement, message: string): void {
function commentsInit(): void {
const commentDeletes: HTMLCollectionOf<HTMLAnchorElement> = document.getElementsByClassName('comment__action--delete') as HTMLCollectionOf<HTMLAnchorElement>;

for (let i = 0; i < commentDeletes.length; i++) {
for(let i = 0; i < commentDeletes.length; i++) {
commentDeletes[i].addEventListener('click', commentDeleteEventHandler);
commentDeletes[i].dataset.href = commentDeletes[i].href;
commentDeletes[i].href = 'javascript:void(0);';
}

const commentInputs: HTMLCollectionOf<HTMLTextAreaElement> = document.getElementsByClassName('comment__text--input') as HTMLCollectionOf<HTMLTextAreaElement>;

for (let i = 0; i < commentInputs.length; i++) {
for(let i = 0; i < commentInputs.length; i++) {
commentInputs[i].form.action = 'javascript:void(0);';
commentInputs[i].form.addEventListener('submit', commentPostEventHandler);
commentInputs[i].addEventListener('keydown', commentInputEventHandler);
}

const voteButtons: HTMLCollectionOf<HTMLAnchorElement> = document.getElementsByClassName('comment__action--vote') as HTMLCollectionOf<HTMLAnchorElement>;

for (let i = 0; i < voteButtons.length; i++)
for(let i = 0; i < voteButtons.length; i++)
{
voteButtons[i].href = 'javascript:void(0);';
voteButtons[i].addEventListener('click', commentVoteEventHandler);
}

const pinButtons: HTMLCollectionOf<HTMLAnchorElement> = document.getElementsByClassName('comment__action--pin') as HTMLCollectionOf<HTMLAnchorElement>;

for (let i = 0; i < pinButtons.length; i++) {
for(let i = 0; i < pinButtons.length; i++) {
pinButtons[i].href = 'javascript:void(0);';
pinButtons[i].addEventListener('click', commentPinEventHandler);
}
}

function commentInputEventHandler(ev: KeyboardEvent): void {
if (ev.code === 'Enter' && ev.ctrlKey && !ev.altKey && !ev.shiftKey && !ev.metaKey) {
if(ev.code === 'Enter' && ev.ctrlKey && !ev.altKey && !ev.shiftKey && !ev.metaKey) {
const form: HTMLFormElement = (ev.target as HTMLTextAreaElement).form;
commentPost(
extractFormData(form, true),
@@ -191,7 +191,7 @@ function commentConstruct(comment: CommentPostInfo, layer: number = 0): HTMLElem
commentTime: HTMLElement = <time class="comment__date" title={commentDate.toLocaleString()} dateTime={commentDate.toISOString()}>{timeago.format(commentDate)}</time>;
let actions: HTMLElement[] = [];

if (checkUserPerm('comments', CommentPermission.Vote)) {
if(checkUserPerm('comments', CommentPermission.Vote)) {
actions.push(<a class="comment__action comment__action--link comment__action--vote comment__action--like"
data-comment-id={comment.comment_id} data-comment-vote={CommentVoteType.Like}
href="javascript:void(0);" onClick={commentVoteEventHandler}>Like</a>);
@@ -202,7 +202,7 @@ function commentConstruct(comment: CommentPostInfo, layer: number = 0): HTMLElem

const commentText: HTMLDivElement = <div class="comment__text"></div>;

if (comment.comment_html)
if(comment.comment_html)
commentText.innerHTML = comment.comment_html;
else
commentText.textContent = comment.comment_text;
@@ -265,14 +265,14 @@ function commentInsert(comment: CommentPostInfo, form: HTMLFormElement): void
: 1,
commentElement: HTMLElement = commentConstruct(comment, repliesIndent);

if (isReply)
if(isReply)
parent.appendChild(commentElement);
else
parent.insertBefore(commentElement, parent.firstElementChild);

const placeholder: HTMLElement = document.getElementById('_no_comments_notice_' + comment.category_id);

if (placeholder)
if(placeholder)
placeholder.parentNode.removeChild(placeholder);
}

@@ -285,15 +285,15 @@ function commentVoteEventHandler(ev: Event): void {
dislikeButton: HTMLAnchorElement = document.querySelector(`.comment__action--dislike[data-comment-id="${commentId}"]`),
classVoted: string = 'comment__action--voted';

for (let i = 0; i < buttons.length; i++) {
for(let i = 0; i < buttons.length; i++) {
let button: HTMLAnchorElement = buttons[i];

button.textContent = button === target ? '...' : '';
button.classList.remove(classVoted);

if (button === likeButton) {
if(button === likeButton) {
button.dataset.commentVote = (voteType === CommentVoteType.Like ? CommentVoteType.Indifferent : CommentVoteType.Like).toString();
} else if (button === dislikeButton) {
} else if(button === dislikeButton) {
button.dataset.commentVote = (voteType === CommentVoteType.Dislike ? CommentVoteType.Indifferent : CommentVoteType.Dislike).toString();
}
}
@@ -302,7 +302,7 @@ function commentVoteEventHandler(ev: Event): void {
commentId,
voteType,
info => {
switch (voteType) {
switch(voteType) {
case CommentVoteType.Like:
likeButton.classList.add(classVoted);
break;
@@ -329,25 +329,25 @@ function commentVote(
onSuccess: (voteInfo: CommentVotesInfo) => void = null,
onFail: (message: string) => void = null
): void {
if (!checkUserPerm('comments', CommentPermission.Vote)) {
if (onFail)
if(!checkUserPerm('comments', CommentPermission.Vote)) {
if(onFail)
onFail("You aren't allowed to vote on comments.");
return;
}

const xhr: XMLHttpRequest = new XMLHttpRequest;
xhr.onreadystatechange = () => {
if (xhr.readyState !== 4)
if(xhr.readyState !== 4)
return;

updateCSRF(xhr.getResponseHeader('X-Misuzu-CSRF'));

const json: CommentVotesInfo = JSON.parse(xhr.responseText),
message: string = json.error || json.message;

if (message && onFail)
if(message && onFail)
onFail(message);
else if (!message && onSuccess)
else if(!message && onSuccess)
onSuccess(json);
};
xhr.open('GET', urlFormat('comment-vote', [{name: 'comment', value: commentId}, {name: 'vote', value: vote}]));
@@ -366,7 +366,7 @@ function commentPinEventHandler(ev: Event): void {
commentId,
!isPinned,
info => {
if (info.comment_pinned === null) {
if(info.comment_pinned === null) {
target.textContent = 'Pin';
target.dataset.commentPinned = '0';
const pinElement: HTMLDivElement = document.querySelector(`#comment-${info.comment_id} .comment__pin`);
@@ -404,26 +404,26 @@ function commentPin(
onSuccess: (commentInfo: CommentPostInfo) => void = null,
onFail: (message: string) => void = null
): void {
if (!checkUserPerm('comments', CommentPermission.Pin)) {
if (onFail)
if(!checkUserPerm('comments', CommentPermission.Pin)) {
if(onFail)
onFail("You aren't allowed to pin comments.");
return;
}

const mode: string = pin ? 'pin' : 'unpin';
const xhr: XMLHttpRequest = new XMLHttpRequest;
xhr.onreadystatechange = () => {
if (xhr.readyState !== 4)
if(xhr.readyState !== 4)
return;

updateCSRF(xhr.getResponseHeader('X-Misuzu-CSRF'));

const json: CommentPostInfo = JSON.parse(xhr.responseText),
message: string = json.error || json.message;

if (message && onFail)
if(message && onFail)
onFail(message);
else if (!message && onSuccess)
else if(!message && onSuccess)
onSuccess(json);
};
xhr.open('GET', urlFormat(`comment-${mode}`, [{name: 'comment', value: commentId}]));
@@ -1,19 +1,18 @@
function extractFormData(form: HTMLFormElement, resetSource: boolean = false): FormData
{
function extractFormData(form: HTMLFormElement, resetSource: boolean = false): FormData {
const formData: FormData = new FormData;

for (let i = 0; i < form.length; i++) {
for(let i = 0; i < form.length; i++) {
let input: HTMLInputElement = form[i] as HTMLInputElement,
type = input.type.toLowerCase(),
isCheckbox = type === 'checkbox';

if (isCheckbox && !input.checked)
if(isCheckbox && !input.checked)
continue;

formData.append(input.name, input.value || '');
}

if (resetSource)
if(resetSource)
resetForm(form);

return formData;
@@ -24,20 +23,19 @@ interface FormHiddenDefault {
Value: string;
}

function resetForm(form: HTMLFormElement, defaults: FormHiddenDefault[] = []): void
{
for (let i = 0; i < form.length; i++) {
function resetForm(form: HTMLFormElement, defaults: FormHiddenDefault[] = []): void {
for(let i = 0; i < form.length; i++) {
let input: HTMLInputElement = form[i] as HTMLInputElement;

switch (input.type.toLowerCase()) {
switch(input.type.toLowerCase()) {
case 'checkbox':
input.checked = false;
break;

case 'hidden':
let hiddenDefault: FormHiddenDefault = defaults.find(fhd => fhd.Name.toLowerCase() === input.name.toLowerCase());

if (hiddenDefault)
if(hiddenDefault)
input.value = hiddenDefault.Value;
break;

@@ -57,17 +55,16 @@ function getCSRFToken(): string {
return CSRFToken;
}

function updateCSRF(token: string): void
{
if (token === null) {
function updateCSRF(token: string): void {
if(token === null) {
return;
}

document.querySelector('[name="csrf-token"]').setAttribute('value', CSRFToken = token);

const elements: NodeListOf<HTMLInputElement> = document.getElementsByName('csrf') as NodeListOf<HTMLInputElement>;

for (let i = 0; i < elements.length; i++) {
for(let i = 0; i < elements.length; i++) {
elements[i].value = token;
}
}

0 comments on commit b416bfb

Please sign in to comment.
You can’t perform that action at this time.