Get rid of unused JSON stuff.

This commit is contained in:
flash 2023-07-10 20:12:20 +00:00
parent 9feb6bcb66
commit 9cb0a04611
13 changed files with 13 additions and 171 deletions

View file

@ -163,12 +163,6 @@ $statistics = DB::query('
) 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,
]);

View file

@ -1,7 +1,6 @@
<?php
namespace Misuzu\Changelog;
use JsonSerializable;
use UnexpectedValueException;
use Misuzu\DB;
use Misuzu\Memoizer;
@ -15,7 +14,7 @@ use Misuzu\Users\UserNotFoundException;
class ChangelogChangeException extends ChangelogException {}
class ChangelogChangeNotFoundException extends ChangelogChangeException {}
class ChangelogChange implements JsonSerializable {
class ChangelogChange {
public const ACTION_UNKNOWN = 0;
public const ACTION_ADD = 1;
public const ACTION_REMOVE = 2;
@ -179,18 +178,6 @@ class ChangelogChange implements JsonSerializable {
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) {

View file

@ -1,14 +1,13 @@
<?php
namespace Misuzu\Changelog;
use JsonSerializable;
use Misuzu\DB;
class ChangelogChangeTagException extends ChangelogException {}
class ChangelogChangeTagNotFoundException extends ChangelogChangeTagException {}
class ChangelogChangeCreationFailedException extends ChangelogChangeTagException {}
class ChangelogChangeTag implements JsonSerializable {
class ChangelogChangeTag {
// Database fields
private $change_id = -1;
private $tag_id = -1;
@ -38,13 +37,6 @@ class ChangelogChangeTag implements JsonSerializable {
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`)'

View file

@ -1,14 +1,13 @@
<?php
namespace Misuzu\Changelog;
use JsonSerializable;
use Misuzu\DB;
use Misuzu\Memoizer;
class ChangelogTagException extends ChangelogException {}
class ChangelogTagNotFoundException extends ChangelogTagException {}
class ChangelogTag implements JsonSerializable {
class ChangelogTag {
// Database fields
private $tag_id = -1;
private $tag_name = '';
@ -69,16 +68,6 @@ class ChangelogTag implements JsonSerializable {
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();
}

View file

@ -1,7 +1,6 @@
<?php
namespace Misuzu\Comments;
use JsonSerializable;
use Misuzu\DB;
use Misuzu\Memoizer;
use Misuzu\Pagination;
@ -10,7 +9,7 @@ use Misuzu\Users\User;
class CommentsCategoryException extends CommentsException {};
class CommentsCategoryNotFoundException extends CommentsCategoryException {};
class CommentsCategory implements JsonSerializable {
class CommentsCategory {
// Database fields
private $category_id = -1;
private $category_name = '';
@ -88,15 +87,6 @@ class CommentsCategory implements JsonSerializable {
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) {

View file

@ -1,7 +1,6 @@
<?php
namespace Misuzu\Comments;
use JsonSerializable;
use Misuzu\DB;
use Misuzu\Pagination;
use Misuzu\Users\User;
@ -12,7 +11,7 @@ class CommentsPostNotFoundException extends CommentsPostException {}
class CommentsPostHasNoParentException extends CommentsPostException {}
class CommentsPostSaveFailedException extends CommentsPostException {}
class CommentsPost implements JsonSerializable {
class CommentsPost {
// Database fields
private $comment_id = -1;
private $category_id = -1;
@ -180,30 +179,6 @@ class CommentsPost implements JsonSerializable {
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) {

View file

@ -1,7 +1,6 @@
<?php
namespace Misuzu\Comments;
use JsonSerializable;
use Misuzu\DB;
use Misuzu\Pagination;
use Misuzu\Users\User;
@ -10,7 +9,7 @@ class CommentsVoteException extends CommentsException {}
class CommentsVoteCountFailedException extends CommentsVoteException {}
class CommentsVoteCreateFailedException extends CommentsVoteException {}
class CommentsVoteCount implements JsonSerializable {
class CommentsVoteCount {
private $comment_id = -1;
private $likes = 0;
private $dislikes = 0;
@ -28,18 +27,9 @@ class CommentsVoteCount implements JsonSerializable {
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 {
class CommentsVote {
// Database fields
private $comment_id = -1;
private $user_id = -1;
@ -83,14 +73,6 @@ class CommentsVote implements JsonSerializable {
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`

View file

@ -2,14 +2,13 @@
namespace Misuzu\News;
use ArrayAccess;
use JsonSerializable;
use Misuzu\DB;
use Misuzu\Pagination;
class NewsCategoryException extends NewsException {};
class NewsCategoryNotFoundException extends NewsCategoryException {};
class NewsCategory implements ArrayAccess, JsonSerializable {
class NewsCategory implements ArrayAccess {
// Database fields
private $category_id = -1;
private $category_name = '';
@ -58,16 +57,6 @@ class NewsCategory implements ArrayAccess, JsonSerializable {
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)

View file

@ -1,7 +1,6 @@
<?php
namespace Misuzu\News;
use JsonSerializable;
use Misuzu\DB;
use Misuzu\Pagination;
use Misuzu\Comments\CommentsCategory;
@ -13,7 +12,7 @@ use Misuzu\Users\UserNotFoundException;
class NewsPostException extends NewsException {};
class NewsPostNotFoundException extends NewsPostException {};
class NewsPost implements JsonSerializable {
class NewsPost {
// Database fields
private $post_id = -1;
private $category_id = -1;
@ -171,22 +170,6 @@ class NewsPost implements JsonSerializable {
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;

View file

@ -136,12 +136,4 @@ class UserBackgroundAsset extends UserImageAsset {
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(),
]);
}
}

View file

@ -1,7 +1,6 @@
<?php
namespace Misuzu\Users\Assets;
use JsonSerializable;
use Misuzu\Config;
use Misuzu\Config\IConfig;
use Misuzu\Users\User;
@ -14,7 +13,7 @@ class UserImageAssetInvalidDimensionsException extends UserAssetException {}
class UserImageAssetFileTooLargeException extends UserAssetException {}
class UserImageAssetMoveFailedException extends UserAssetException {}
abstract class UserImageAsset implements JsonSerializable, UserImageAssetInterface {
abstract class UserImageAsset implements UserImageAssetInterface {
public const PUBLIC_STORAGE = '/msz-storage';
public const TYPE_PNG = IMAGETYPE_PNG;
@ -128,13 +127,4 @@ abstract class UserImageAsset implements JsonSerializable, UserImageAssetInterfa
self::setFromPath($file);
unlink($file);
}
public function jsonSerialize(): mixed {
return [
'is_present' => $this->isPresent(),
'width' => $this->getWidth(),
'height' => $this->getHeight(),
'mime' => $this->getMimeType(),
];
}
}

View file

@ -3,7 +3,6 @@ namespace Misuzu\Users;
use DateTime;
use DateTimeZone;
use JsonSerializable;
use Index\XString;
use Index\Colour\Colour;
use Misuzu\DB;
@ -29,7 +28,7 @@ class UserCreationFailedException extends UserException {}
// - Move background settings and about shit to a separate users_profiles table (should birthdate be profile specific?)
// - Create a users_stats table containing static counts for things like followers, followings, topics, posts, etc.
class User implements HasRankInterface, JsonSerializable {
class User implements HasRankInterface {
public const NAME_MIN_LENGTH = 3; // Minimum username length
public const NAME_MAX_LENGTH = 16; // Maximum username length, unless your name is Flappyzor(WorldwideOnline2018through2019through2020)
public const NAME_REGEX = '[A-Za-z0-9-_]+'; // Username character constraint
@ -374,26 +373,6 @@ class User implements HasRankInterface, JsonSerializable {
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 *
************/

View file

@ -1,8 +1,7 @@
<?php
use Index\Colour\Colour;
// 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
// render_error and render_info need to be nuked from orbit
function render_error(int $code, string $template = 'errors.%d'): string {
return render_info(null, $code, $template);
@ -311,6 +310,7 @@ function get_country_name(string $code): string {
'XK' => 'Kosovo',
'XM' => 'The Moon',
'XX' => 'Unknown',
'YE' => 'Yemen',
'YT' => 'Mayotte',