misuzu/public/changelog.php

96 lines
3 KiB
PHP
Raw Normal View History

2018-07-06 01:28:06 +00:00
<?php
namespace Misuzu;
2020-05-18 21:27:34 +00:00
use Misuzu\Comments\CommentsCategory;
use Misuzu\Comments\CommentsCategoryNotFoundException;
use Misuzu\Users\User;
use Misuzu\Users\UserNotFoundException;
2018-07-06 01:28:06 +00:00
2020-05-18 21:27:34 +00:00
require_once '../misuzu.php';
2018-07-06 01:28:06 +00:00
2020-05-18 21:27:34 +00:00
$changelogChange = !empty($_GET['c']) && is_string($_GET['c']) ? (int)$_GET['c'] : 0;
$changelogDate = !empty($_GET['d']) && is_string($_GET['d']) ? (string)$_GET['d'] : '';
$changelogUser = !empty($_GET['u']) && is_string($_GET['u']) ? (int)$_GET['u'] : 0;
$changelogTags = !empty($_GET['t']) && is_string($_GET['t']) ? (string)$_GET['t'] : '';
2018-07-06 01:28:06 +00:00
2019-06-10 17:04:53 +00:00
if($changelogChange > 0) {
$change = changelog_change_get($changelogChange);
2018-07-06 01:28:06 +00:00
2019-06-10 17:04:53 +00:00
if(!$change) {
2018-11-17 21:59:01 +00:00
echo render_error(404);
return;
2018-07-06 01:28:06 +00:00
}
2020-05-18 21:27:34 +00:00
$commentsCategoryName = "changelog-date-{$change['change_date']}";
try {
$commentsCategory = CommentsCategory::byName($commentsCategoryName);
} catch(CommentsCategoryNotFoundException $ex) {
$commentsCategory = new CommentsCategory($commentsCategoryName);
$commentsCategory->save();
}
try {
$commentsUser = User::byId(user_session_current('user_id', 0));
} catch(UserNotFoundException $ex) {
$commentsUser = null;
}
Template::render('changelog.change', [
2018-08-06 22:19:35 +00:00
'change' => $change,
'tags' => changelog_change_tags_get($change['change_id']),
2020-05-18 21:27:34 +00:00
'comments_category' => $commentsCategory,
'comments_user' => $commentsUser,
2018-08-06 22:19:35 +00:00
]);
2018-07-06 01:28:06 +00:00
return;
}
2019-06-10 17:04:53 +00:00
if(!empty($changelogDate)) {
2018-07-06 01:28:06 +00:00
$dateParts = explode('-', $changelogDate, 3);
2019-06-10 17:04:53 +00:00
if(count($dateParts) !== 3
|| !array_test($dateParts, 'ctype_digit')
|| !checkdate($dateParts[1], $dateParts[2], $dateParts[0])) {
2018-07-06 01:28:06 +00:00
echo render_error(404);
return;
}
}
$changesCount = !empty($changelogDate) ? -1 : changelog_count_changes($changelogDate, $changelogUser);
$changesPagination = new Pagination($changesCount, 30);
$changes = $changesCount === -1 || $changesPagination->hasValidOffset()
? changelog_get_changes($changelogDate, $changelogUser, $changesPagination->getOffset(), $changesPagination->getRange())
2019-01-03 00:33:02 +00:00
: [];
2018-07-06 01:28:06 +00:00
2019-06-10 17:04:53 +00:00
if(!$changes) {
http_response_code(404);
}
2018-07-06 01:28:06 +00:00
2019-06-10 17:04:53 +00:00
if(!empty($changelogDate) && count($changes) > 0) {
2020-05-18 21:27:34 +00:00
$commentsCategoryName = "changelog-date-{$changelogDate}";
try {
$commentsCategory = CommentsCategory::byName($commentsCategoryName);
} catch(CommentsCategoryNotFoundException $ex) {
$commentsCategory = new CommentsCategory($commentsCategoryName);
$commentsCategory->save();
}
try {
$commentsUser = User::byId(user_session_current('user_id', 0));
} catch(UserNotFoundException $ex) {
$commentsUser = null;
}
Template::set([
2020-05-18 21:27:34 +00:00
'comments_category' => $commentsCategory,
'comments_user' => $commentsUser,
2018-08-06 22:19:35 +00:00
]);
}
Template::render('changelog.index', [
2018-07-06 01:28:06 +00:00
'changes' => $changes,
'changelog_count' => $changesCount,
'changelog_date' => $changelogDate,
'changelog_user' => $changelogUser,
2019-01-03 00:33:02 +00:00
'changelog_pagination' => $changesPagination,
2018-07-06 01:28:06 +00:00
]);