// I FORGOT TO COMMIT THE FILES AHAHAHAHA

This commit is contained in:
flash 2019-12-06 02:04:10 +01:00
parent ce72c69440
commit 7b910c49bb
45 changed files with 411 additions and 414 deletions

14
composer.lock generated
View file

@ -8,27 +8,27 @@
"packages": [
{
"name": "chillerlan/php-qrcode",
"version": "3.1.1",
"version": "3.2.0",
"source": {
"type": "git",
"url": "https://github.com/chillerlan/php-qrcode.git",
"reference": "8d20f2bfc65543a551f306ba00d465f7d7910d14"
"reference": "df33b38b6348ba96e2bf2207d7b0ca6ce3e506f4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/chillerlan/php-qrcode/zipball/8d20f2bfc65543a551f306ba00d465f7d7910d14",
"reference": "8d20f2bfc65543a551f306ba00d465f7d7910d14",
"url": "https://api.github.com/repos/chillerlan/php-qrcode/zipball/df33b38b6348ba96e2bf2207d7b0ca6ce3e506f4",
"reference": "df33b38b6348ba96e2bf2207d7b0ca6ce3e506f4",
"shasum": ""
},
"require": {
"chillerlan/php-settings-container": "^1.1",
"chillerlan/php-settings-container": "^1.2",
"ext-gd": "*",
"ext-json": "*",
"ext-mbstring": "*",
"php": "^7.2"
},
"require-dev": {
"phpunit/phpunit": "^8.3"
"phpunit/phpunit": "^8.4"
},
"suggest": {
"chillerlan/php-authenticator": "Yet another Google authenticator! Also creates URIs for mobile apps."
@ -72,7 +72,7 @@
"qrcode",
"qrcode-generator"
],
"time": "2019-08-09T20:45:07+00:00"
"time": "2019-12-04T21:31:05+00:00"
},
{
"name": "chillerlan/php-settings-container",

View file

@ -6,6 +6,7 @@ use PDO;
define('MSZ_STARTUP', microtime(true));
define('MSZ_ROOT', __DIR__);
define('MSZ_CLI', PHP_SAPI === 'cli');
define('MSZ_DEBUG', is_file(MSZ_ROOT . '/.debug'));
define('MSZ_PHP_MIN_VER', '7.4.0');
@ -16,15 +17,15 @@ if(version_compare(PHP_VERSION, MSZ_PHP_MIN_VER, '<')) {
error_reporting(MSZ_DEBUG ? -1 : 0);
ini_set('display_errors', MSZ_DEBUG ? 'On' : 'Off');
date_default_timezone_set('UTC');
mb_internal_encoding('UTF-8');
date_default_timezone_set('UTC');
set_include_path(get_include_path() . PATH_SEPARATOR . MSZ_ROOT);
require_once 'vendor/autoload.php';
$errorHandler = new \Whoops\Run;
$errorHandler->pushHandler(
PHP_SAPI === 'cli'
MSZ_CLI
? new \Whoops\Handler\PlainTextHandler
: (
MSZ_DEBUG
@ -40,16 +41,11 @@ require_once 'src/colour.php';
require_once 'src/comments.php';
require_once 'src/csrf.php';
require_once 'src/emotes.php';
require_once 'src/general.php';
require_once 'src/git.php';
require_once 'src/manage.php';
require_once 'src/news.php';
require_once 'src/otp.php';
require_once 'src/pagination.php';
require_once 'src/perms.php';
require_once 'src/twitter.php';
require_once 'src/url.php';
require_once 'src/zalgo.php';
require_once 'src/Forum/forum.php';
require_once 'src/Forum/leaderboard.php';
require_once 'src/Forum/perms.php';
@ -117,7 +113,7 @@ if(!empty($errorReporter)) {
define('MSZ_STORAGE', Config::get('storage.path', Config::TYPE_STR, MSZ_ROOT . '/store'));
mkdirs(MSZ_STORAGE, true);
if(PHP_SAPI === 'cli') {
if(MSZ_CLI) {
if(realpath($_SERVER['SCRIPT_FILENAME']) === __FILE__) {
switch($argv[1] ?? null) {
case 'cron':
@ -347,10 +343,10 @@ MIG;
break;
}
twitter_init($apiKey, $apiSecret);
Twitter::init($apiKey, $apiSecret);
echo 'Twitter Authentication' . PHP_EOL;
$authPage = twitter_auth_create();
$authPage = Twitter::createAuth();
if(empty($authPage)) {
echo 'Request to begin authentication failed.' . PHP_EOL;
@ -360,7 +356,7 @@ MIG;
echo 'Go to the page below and paste the pin code displayed.' . PHP_EOL . $authPage . PHP_EOL;
$pin = readline('Pin: ');
$authComplete = twitter_auth_complete($pin);
$authComplete = Twitter::completeAuth($pin);
if(empty($authComplete)) {
echo 'Invalid pin code.' . PHP_EOL;
@ -497,7 +493,7 @@ MIG;
$inManageMode = starts_with($_SERVER['REQUEST_URI'], '/manage');
$hasManageAccess = !empty($userDisplayInfo['user_id'])
&& !user_warning_check_restriction($userDisplayInfo['user_id'])
&& perms_check_user(MSZ_PERMS_GENERAL, $userDisplayInfo['user_id'], MSZ_PERM_GENERAL_CAN_MANAGE);
&& perms_check_user(MSZ_PERMS_GENERAL, $userDisplayInfo['user_id'], General::PERM_CAN_MANAGE);
Template::set('has_manage_access', $hasManageAccess);
if($inManageMode) {

View file

@ -42,10 +42,9 @@ if(!empty($changelogDate)) {
}
$changesCount = !empty($changelogDate) ? -1 : changelog_count_changes($changelogDate, $changelogUser);
$changesPagination = pagination_create($changesCount, 30);
$changesOffset = $changesCount === -1 ? 0 : pagination_offset($changesPagination, pagination_param());
$changes = $changesCount === -1 || pagination_is_valid_offset($changesOffset)
? changelog_get_changes($changelogDate, $changelogUser, $changesOffset, $changesPagination['range'])
$changesPagination = new Pagination($changesCount, 30);
$changes = $changesCount === -1 || $changesPagination->hasValidOffset()
? changelog_get_changes($changelogDate, $changelogUser, $changesPagination->getOffset(), $changesPagination->getRange())
: [];
if(!$changes) {

View file

@ -38,10 +38,9 @@ if($forum['forum_type'] == MSZ_FORUM_TYPE_LINK) {
return;
}
$forumPagination = pagination_create($forum['forum_topic_count'], 20);
$topicsOffset = pagination_offset($forumPagination, pagination_param());
$forumPagination = new Pagination($forum['forum_topic_count'], 20);
if(!pagination_is_valid_offset($topicsOffset) && $forum['forum_topic_count'] > 0) {
if(!$forumPagination->hasValidOffset() && $forum['forum_topic_count'] > 0) {
echo render_error(404);
return;
}
@ -51,8 +50,8 @@ $topics = $forumMayHaveTopics
? forum_topic_listing(
$forum['forum_id'],
$forumUserId,
$topicsOffset,
$forumPagination['range'],
$forumPagination->getOffset(),
$forumPagination->getRange(),
perms_check($perms, MSZ_FORUM_PERM_DELETE_ANY_POST),
forum_has_priority_voting($forum['forum_type'])
)

View file

@ -332,7 +332,7 @@ if($canDeleteAny) {
$topicPosts += $topic['topic_count_posts_deleted'];
}
$topicPagination = pagination_create($topicPosts, MSZ_FORUM_POSTS_PER_PAGE);
$topicPagination = new Pagination($topicPosts, MSZ_FORUM_POSTS_PER_PAGE, 'page');
if(isset($postInfo['preceeding_post_count'])) {
$preceedingPosts = $postInfo['preceeding_post_count'];
@ -341,12 +341,10 @@ if(isset($postInfo['preceeding_post_count'])) {
$preceedingPosts += $postInfo['preceeding_post_deleted_count'];
}
$postsPage = floor($preceedingPosts / $topicPagination['range']) + 1;
$topicPagination->setPage(floor($preceedingPosts / $topicPagination->getRange()), true);
}
$postsOffset = pagination_offset($topicPagination, $postsPage ?? pagination_param('page'));
if(!pagination_is_valid_offset($postsOffset)) {
if(!$topicPagination->hasValidOffset()) {
echo render_error(404);
return;
}
@ -355,8 +353,8 @@ Template::set('topic_perms', $perms);
$posts = forum_post_listing(
$topic['topic_id'],
$postsOffset,
$topicPagination['range'],
$topicPagination->getOffset(),
$topicPagination->getRange(),
perms_check($perms, MSZ_FORUM_PERM_DELETE_ANY_POST)
);

View file

@ -13,10 +13,9 @@ $changesCount = (int)DB::query('
FROM `msz_changelog_changes`
')->fetchColumn();
$changelogPagination = pagination_create($changesCount, 30);
$changelogOffset = pagination_offset($changelogPagination, pagination_param());
$changelogPagination = new Pagination($changesCount, 30);
if(!pagination_is_valid_offset($changelogOffset)) {
if(!$changelogPagination->hasValidOffset()) {
echo render_error(404);
return;
}
@ -36,8 +35,8 @@ $getChanges = DB::prepare('
ORDER BY c.`change_id` DESC
LIMIT :offset, :take
');
$getChanges->bind('take', $changelogPagination['range']);
$getChanges->bind('offset', $changelogOffset);
$getChanges->bind('take', $changelogPagination->getRange());
$getChanges->bind('offset', $changelogPagination->getOffset());
$changes = $getChanges->fetchAll();
$getTags = DB::prepare('

View file

@ -3,7 +3,7 @@ namespace Misuzu;
require_once '../../../misuzu.php';
if(!perms_check_user(MSZ_PERMS_GENERAL, user_session_current('user_id'), MSZ_PERM_GENERAL_MANAGE_BLACKLIST)) {
if(!perms_check_user(MSZ_PERMS_GENERAL, user_session_current('user_id'), General::PERM_MANAGE_BLACKLIST)) {
echo render_error(403);
return;
}

View file

@ -3,7 +3,7 @@ namespace Misuzu;
require_once '../../../misuzu.php';
if(!perms_check_user(MSZ_PERMS_GENERAL, user_session_current('user_id'), MSZ_PERM_GENERAL_MANAGE_EMOTICONS)) {
if(!perms_check_user(MSZ_PERMS_GENERAL, user_session_current('user_id'), General::PERM_MANAGE_EMOTES)) {
echo render_error(403);
return;
}

View file

@ -3,7 +3,7 @@ namespace Misuzu;
require_once '../../../misuzu.php';
if(!perms_check_user(MSZ_PERMS_GENERAL, user_session_current('user_id'), MSZ_PERM_GENERAL_MANAGE_EMOTICONS)) {
if(!perms_check_user(MSZ_PERMS_GENERAL, user_session_current('user_id'), General::PERM_MANAGE_EMOTES)) {
echo render_error(403);
return;
}

View file

@ -3,20 +3,22 @@ namespace Misuzu;
require_once '../../../misuzu.php';
if(!perms_check_user(MSZ_PERMS_GENERAL, user_session_current('user_id'), MSZ_PERM_GENERAL_VIEW_LOGS)) {
if(!perms_check_user(MSZ_PERMS_GENERAL, user_session_current('user_id'), General::PERM_VIEW_LOGS)) {
echo render_error(403);
return;
}
$logsPagination = pagination_create(audit_log_count(), 50);
$logsOffset = pagination_offset($logsPagination, pagination_param());
$logsPagination = new Pagination(audit_log_count(), 50);
if(!pagination_is_valid_offset($logsOffset)) {
if(!$logsPagination->hasValidOffset()) {
echo render_error(404);
return;
}
$logs = audit_log_list($logsOffset, $logsPagination['range']);
$logs = audit_log_list(
$logsPagination->getOffset(),
$logsPagination->getRange()
);
Template::render('manage.general.logs', [
'global_logs' => $logs,

View file

@ -3,7 +3,7 @@ namespace Misuzu;
require_once '../../../misuzu.php';
if(!perms_check_user(MSZ_PERMS_GENERAL, user_session_current('user_id'), MSZ_PERM_GENERAL_MANAGE_SETTINGS)) {
if(!perms_check_user(MSZ_PERMS_GENERAL, user_session_current('user_id'), General::PERM_MANAGE_CONFIG)) {
echo render_error(403);
return;
}

View file

@ -8,15 +8,14 @@ if(!perms_check_user(MSZ_PERMS_NEWS, user_session_current('user_id'), MSZ_PERM_N
return;
}
$categoriesPagination = pagination_create(news_categories_count(true), 15);
$categoriesOffset = pagination_offset($categoriesPagination, pagination_param());
$categoriesPagination = new Pagination(news_categories_count(true), 15);
if(!pagination_is_valid_offset($categoriesOffset)) {
if(!$categoriesPagination->hasValidOffset()) {
echo render_error(404);
return;
}
$categories = news_categories_get($categoriesOffset, $categoriesPagination['range'], true, false, true);
$categories = news_categories_get($categoriesPagination->getOffset(), $categoriesPagination->getRange(), true, false, true);
Template::render('manage.news.categories', [
'news_categories' => $categories,

View file

@ -43,9 +43,9 @@ if(!empty($_POST['post']) && csrf_verify_request()) {
if(!empty($twitterApiKey) && !empty($twitterApiSecret)
&& !empty($twitterToken) && !empty($twitterTokenSecret)) {
twitter_init($twitterApiKey, $twitterApiSecret, $twitterToken, $twitterTokenSecret);
Twitter::init($twitterApiKey, $twitterApiSecret, $twitterToken, $twitterTokenSecret);
$url = url('news-post', ['post' => $postId]);
twitter_tweet_post("News :: {$title}\nhttps://{$_SERVER['HTTP_HOST']}{$url}");
Twitter::sendTweet("News :: {$title}\nhttps://{$_SERVER['HTTP_HOST']}{$url}");
}
}
}

View file

@ -8,15 +8,18 @@ if(!perms_check_user(MSZ_PERMS_NEWS, user_session_current('user_id'), MSZ_PERM_N
return;
}
$postsPagination = pagination_create(news_posts_count(null, false, true, false), 15);
$postsOffset = pagination_offset($postsPagination, pagination_param());
$postsPagination = new Pagination(news_posts_count(null, false, true, false), 15);
if(!pagination_is_valid_offset($postsOffset)) {
if(!$postsPagination->hasValidOffset()) {
echo render_error(404);
return;
}
$posts = news_posts_get($postsOffset, $postsPagination['range'], null, false, true, false);
$posts = news_posts_get(
$postsPagination->getOffset(),
$postsPagination->getRange(),
null, false, true, false
);
Template::render('manage.news.posts', [
'news_posts' => $posts,

View file

@ -13,10 +13,9 @@ $manageUsersCount = (int)DB::query('
FROM `msz_users`
')->fetchColumn();
$usersPagination = pagination_create($manageUsersCount, 30);
$usersOffset = pagination_offset($usersPagination, pagination_param());
$usersPagination = new Pagination($manageUsersCount, 30);
if(!pagination_is_valid_offset($usersOffset)) {
if(!$usersPagination->hasValidOffset()) {
echo render_error(404);
return;
}
@ -34,8 +33,8 @@ $getManageUsers = DB::prepare('
ORDER BY `user_id`
LIMIT :offset, :take
');
$getManageUsers->bind('offset', $usersOffset);
$getManageUsers->bind('take', $usersPagination['range']);
$getManageUsers->bind('offset', $usersPagination->getOffset());
$getManageUsers->bind('take', $usersPagination->getRange());
$manageUsers = $getManageUsers->fetchAll();
Template::render('manage.users.users', [

View file

@ -13,10 +13,9 @@ $manageRolesCount = (int)DB::query('
FROM `msz_roles`
')->fetchColumn();
$rolesPagination = pagination_create($manageRolesCount, 10);
$rolesOffset = pagination_offset($rolesPagination, pagination_param());
$rolesPagination = new Pagination($manageRolesCount, 10);
if(!pagination_is_valid_offset($rolesOffset)) {
if(!$rolesPagination->hasValidOffset()) {
echo render_error(404);
return;
}
@ -32,8 +31,8 @@ $getManageRoles = DB::prepare('
FROM `msz_roles` as r
LIMIT :offset, :take
');
$getManageRoles->bind('offset', $rolesOffset);
$getManageRoles->bind('take', $rolesPagination['range']);
$getManageRoles->bind('offset', $rolesPagination->getOffset());
$getManageRoles->bind('take', $rolesPagination->getRange());
$manageRoles = $getManageRoles->fetchAll();
Template::render('manage.users.roles', [

View file

@ -111,15 +111,18 @@ if(empty($warningsUser)) {
$warningsUser = max(0, (int)($_GET['u'] ?? 0));
}
$warningsPagination = pagination_create(user_warning_global_count($warningsUser), 50);
$warningsOffset = $warningsPagination['count'] > 0 ? pagination_offset($warningsPagination, pagination_param()) : 0;
$warningsPagination = new Pagination(user_warning_global_count($warningsUser), 50);
if(!pagination_is_valid_offset($warningsOffset)) {
if(!$warningsPagination->hasValidOffset()) {
echo render_error(404);
return;
}
$warningsList = user_warning_global_fetch($warningsOffset, $warningsPagination['range'], $warningsUser);
$warningsList = user_warning_global_fetch(
$warningsPagination->getOffset(),
$warningsPagination->getRange(),
$warningsUser
);
// calling array_flip since the input_select macro wants value => display, but this looks cuter
$warningDurations = array_flip([

View file

@ -87,13 +87,7 @@ if(empty($role)) {
return;
}
$usersPagination = pagination_create($role['role_user_count'], 15);
$usersOffset = pagination_offset($usersPagination, pagination_param());
if($usersOffset > 0 && !pagination_is_valid_offset($usersOffset)) {
echo render_error(404);
return;
}
$usersPagination = new Pagination($role['role_user_count'], 15);
$roles = user_role_all();
@ -155,8 +149,8 @@ $getUsers = DB::prepare(sprintf(
$orderFields[$orderBy]['column'],
$orderDir,
MSZ_USER_RELATION_FOLLOW,
$usersOffset < 0 ? 0 : $usersOffset,
isset($usersPagination['range']) ? $usersPagination['range'] : 0
$usersPagination->getOffset(),
$usersPagination->getRange()
));
$getUsers->bind('role_id', $role['role_id']);
$getUsers->bind('current_user_id', user_session_current('user_id', 0));

View file

@ -25,7 +25,7 @@ if($postId > 0) {
}
if($categoryId > 0) {
$location = url('news-category', ['category' => $categoryId, 'page' => pagination_param('page')]);
$location = url('news-category', ['category' => $categoryId, 'page' => Pagination::param('page')]);
}
redirect($location);

View file

@ -11,17 +11,16 @@ if(empty($category)) {
return;
}
$categoryPagination = pagination_create($category['posts_count'], 5);
$postsOffset = pagination_offset($categoryPagination, pagination_param());
$categoryPagination = new Pagination($category['posts_count'], 5);
if(!pagination_is_valid_offset($postsOffset)) {
if(!$categoryPagination->hasValidOffset()) {
echo render_error(404);
return;
}
$posts = news_posts_get(
$postsOffset,
$categoryPagination['range'],
$categoryPagination->getOffset(),
$categoryPagination->getRange(),
$category['category_id']
);

View file

@ -5,17 +5,16 @@ require_once '../../misuzu.php';
$categories = news_categories_get(0, 0, true);
$newsPagination = pagination_create(news_posts_count(null, true), 5);
$postsOffset = pagination_offset($newsPagination, pagination_param('page'));
$newsPagination = new Pagination(news_posts_count(null, true), 5, 'page');
if(!pagination_is_valid_offset($postsOffset)) {
if(!$newsPagination->hasValidOffset()) {
echo render_error(404);
return;
}
$posts = news_posts_get(
$postsOffset,
$newsPagination['range'],
$newsPagination->getOffset(),
$newsPagination->getRange(),
null,
true
);

View file

@ -322,17 +322,17 @@ switch($profileMode) {
case 'following':
$template = 'profile.relations';
$followingCount = user_relation_count_from($profileUser->user_id, MSZ_USER_RELATION_FOLLOW);
$followingPagination = pagination_create($followingCount, MSZ_USER_RELATION_FOLLOW_PER_PAGE);
$followingOffset = pagination_offset($followingPagination, pagination_param());
$followingPagination = new Pagination($followingCount, MSZ_USER_RELATION_FOLLOW_PER_PAGE);
if(!pagination_is_valid_offset($followingOffset)) {
if(!$followingPagination->hasValidOffset()) {
echo render_error(404);
return;
}
$following = user_relation_users_from(
$profileUser->user_id, MSZ_USER_RELATION_FOLLOW, $followingPagination['range'],
$followingOffset, $currentUserId
$profileUser->user_id, MSZ_USER_RELATION_FOLLOW,
$followingPagination->getRange(), $followingPagination->getOffset(),
$currentUserId
);
Template::set([
@ -346,15 +346,18 @@ switch($profileMode) {
case 'followers':
$template = 'profile.relations';
$followerCount = user_relation_count_to($profileUser->user_id, MSZ_USER_RELATION_FOLLOW);
$followerPagination = pagination_create($followerCount, MSZ_USER_RELATION_FOLLOW_PER_PAGE);
$followerOffset = pagination_offset($followerPagination, pagination_param());
$followerPagination = new Pagination($followerCount, MSZ_USER_RELATION_FOLLOW_PER_PAGE);
if(!pagination_is_valid_offset($followerOffset)) {
if(!$followerPagination->hasValidOffset()) {
echo render_error(404);
return;
}
$followers = user_relation_users_to($profileUser->user_id, MSZ_USER_RELATION_FOLLOW, $followerPagination['range'], $followerOffset, $currentUserId);
$followers = user_relation_users_to(
$profileUser->user_id, MSZ_USER_RELATION_FOLLOW,
$followerPagination->getRange(), $followerPagination->getOffset(),
$currentUserId
);
Template::set([
'title' => $profileUser->username . ' / followers',
@ -367,19 +370,21 @@ switch($profileMode) {
case 'forum-topics':
$template = 'profile.topics';
$topicsCount = forum_topic_count_user($profileUser->user_id, $currentUserId);
$topicsPagination = pagination_create($topicsCount, 20);
$topicsOffset = pagination_offset($topicsPagination, pagination_param());
$topicsPagination = new Pagination($topicsCount, 20);
if(!pagination_is_valid_offset($topicsOffset)) {
if(!$topicsPagination->hasValidOffset()) {
echo render_error(404);
return;
}
$topics = forum_topic_listing_user($profileUser->user_id, $currentUserId, $topicsOffset, $topicsPagination['range']);
$topics = forum_topic_listing_user(
$profileUser->user_id, $currentUserId,
$topicsPagination->getOffset(), $topicsPagination->getRange()
);
Template::set([
'title' => $profileUser->username . ' / topics',
'canonical_url' => url('user-profile-forum-topics', ['user' => $profileUser->user_id, 'page' => pagination_param()]),
'canonical_url' => url('user-profile-forum-topics', ['user' => $profileUser->user_id, 'page' => Pagination::param()]),
'profile_topics' => $topics,
'profile_topics_pagination' => $topicsPagination,
]);
@ -388,19 +393,24 @@ switch($profileMode) {
case 'forum-posts':
$template = 'profile.posts';
$postsCount = forum_post_count_user($profileUser->user_id);
$postsPagination = pagination_create($postsCount, 20);
$postsOffset = pagination_offset($postsPagination, pagination_param());
$postsPagination = new Pagination($postsCount, 20);
if(!pagination_is_valid_offset($postsOffset)) {
if(!$postsPagination->hasValidOffset()) {
echo render_error(404);
return;
}
$posts = forum_post_listing($profileUser->user_id, $postsOffset, $postsPagination['range'], false, true);
$posts = forum_post_listing(
$profileUser->user_id,
$postsPagination->getOffset(),
$postsPagination->getRange(),
false,
true
);
Template::set([
'title' => $profileUser->username . ' / posts',
'canonical_url' => url('user-profile-forum-posts', ['user' => $profileUser->user_id, 'page' => pagination_param()]),
'canonical_url' => url('user-profile-forum-posts', ['user' => $profileUser->user_id, 'page' => Pagination::param()]),
'profile_posts' => $posts,
'profile_posts_pagination' => $postsPagination,
]);

View file

@ -60,7 +60,7 @@ curl_setopt_array($curl, [
CURLOPT_MAXREDIRS => 4,
CURLOPT_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS,
CURLOPT_TIMEOUT => 10,
CURLOPT_USERAGENT => 'Mozilla/5.0 (compatible) Misuzu/' . git_tag(),
CURLOPT_USERAGENT => 'Mozilla/5.0 (compatible) Misuzu/' . GitInfo::tag(),
]);
$curlBody = curl_exec($curl);
curl_close($curl);

View file

@ -9,28 +9,18 @@ if(!user_session_active()) {
}
$currentUserId = user_session_current('user_id');
$loginHistoryPagination = pagination_create(user_login_attempts_count($currentUserId), 15);
$accountLogPagination = pagination_create(audit_log_count($currentUserId), 15);
if(!pagination_is_valid_offset(pagination_offset($loginHistoryPagination, pagination_param('hp')))) {
$loginHistoryPagination['offset'] = 0;
$loginHistoryPagination['page'] = 1;
}
if(!pagination_is_valid_offset(pagination_offset($accountLogPagination, pagination_param('ap')))) {
$accountLogPagination['offset'] = 0;
$accountLogPagination['page'] = 1;
}
$loginHistoryPagination = new Pagination(user_login_attempts_count($currentUserId), 15);
$accountLogPagination = new Pagination(audit_log_count($currentUserId), 15);
$loginHistoryList = user_login_attempts_list(
$loginHistoryPagination['offset'],
$loginHistoryPagination['range'],
$loginHistoryPagination->getOffset(),
$loginHistoryPagination->getRange(),
$currentUserId
);
$accountLogList = audit_log_list(
$accountLogPagination['offset'],
$accountLogPagination['range'],
$accountLogPagination->getOffset(),
$accountLogPagination->getRange(),
$currentUserId
);

View file

@ -44,16 +44,11 @@ if(!empty($_POST['session']) && csrf_verify_request()) {
}
}
$sessionPagination = pagination_create(user_session_count($currentUserId), 15);
if(!pagination_is_valid_offset(pagination_offset($sessionPagination, pagination_param()))) {
$sessionPagination['offset'] = 0;
$sessionPagination['page'] = 1;
}
$sessionPagination = new Pagination(user_session_count($currentUserId), 15);
$sessionList = user_session_list(
$sessionPagination['offset'],
$sessionPagination['range'],
$sessionPagination->getOffset(),
$sessionPagination->getRange(),
$currentUserId
);

View file

@ -1,7 +1,7 @@
<?php
namespace Misuzu;
class Base32 {
final class Base32 {
public const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
public static function decode(string $str): string {

View file

@ -1,7 +1,7 @@
<?php
namespace Misuzu;
class Base64 {
final class Base64 {
public static function encode(string $data, bool $url = false): string {
$data = base64_encode($data);

View file

@ -4,7 +4,7 @@ namespace Misuzu;
use PDO;
use PDOException;
class Config {
final class Config {
public const TYPE_ANY = '';
public const TYPE_STR = 'string';
public const TYPE_INT = 'integer';

View file

@ -1,7 +1,11 @@
<?php
define('MSZ_PERM_GENERAL_CAN_MANAGE', 1);
define('MSZ_PERM_GENERAL_VIEW_LOGS', 1 << 1);
define('MSZ_PERM_GENERAL_MANAGE_EMOTICONS', 1 << 2);
define('MSZ_PERM_GENERAL_MANAGE_SETTINGS', 1 << 3);
define('MSZ_PERM_GENERAL_TESTER', 1 << 4);
define('MSZ_PERM_GENERAL_MANAGE_BLACKLIST', 1 << 5);
namespace Misuzu;
final class General {
public const PERM_CAN_MANAGE = 0x00000001;
public const PERM_VIEW_LOGS = 0x00000002;
public const PERM_MANAGE_EMOTES = 0x00000004;
public const PERM_MANAGE_CONFIG = 0x00000008;
public const PERM_IS_TESTER = 0x00000010;
public const PERM_MANAGE_BLACKLIST = 0x00000020;
}

View file

@ -1,20 +0,0 @@
<?php
define('MSZ_GIT_FORMAT_HASH_DATE_TIME', '%cd');
define('MSZ_GIT_FORMAT_HASH_SHORT', '%h');
define('MSZ_GIT_FORMAT_HASH_LONG', '%H');
function git_commit_info(string $format, string $args = ''): string {
return trim(shell_exec(sprintf("git log --pretty=\"%s\" {$args} -n1 HEAD", $format)));
}
function git_commit_hash(bool $long = false): string {
return git_commit_info($long ? MSZ_GIT_FORMAT_HASH_LONG : MSZ_GIT_FORMAT_HASH_SHORT);
}
function git_branch(): string {
return trim(shell_exec('git rev-parse --abbrev-ref HEAD'));
}
function git_tag(): string {
return trim(shell_exec('git describe --abbrev=0 --tags'));
}

23
src/GitInfo.php Normal file
View file

@ -0,0 +1,23 @@
<?php
namespace Misuzu;
final class GitInfo {
private const FORMAT_HASH_SHORT = '%h';
private const FORMAT_HASH_LONG = '%H';
public static function log(string $format, string $args = ''): string {
return trim(shell_exec(sprintf('git log --pretty="%s" %s -n1 HEAD', $format, $args)));
}
public static function hash(bool $long = false): string {
return self::log($long ? self::FORMAT_HASH_LONG : self::FORMAT_HASH_SHORT);
}
public static function branch(): string {
return trim(`git rev-parse --abbrev-ref HEAD`);
}
public static function tag(): string {
return trim(`git describe --abbrev=0 --tags`);
}
}

View file

@ -6,7 +6,7 @@ use Swift_Message;
use Swift_NullTransport;
use Swift_SmtpTransport;
class Mailer {
final class Mailer {
private const TEMPLATE_PATH = MSZ_ROOT . '/config/emails/%s.txt';
private static $mailer = null;

View file

@ -1,46 +1,77 @@
<?php
define('MSZ_PAGINATION_PAGE_START', 1);
define('MSZ_PAGINATION_OFFSET_INVALID', -1);
namespace Misuzu;
function pagination_create(int $count, int $range): array {
$pages = ceil($count / $range);
return compact('count', 'range', 'pages');
}
final class Pagination {
private const INVALID_OFFSET = -1;
private const START_PAGE = 1;
public const DEFAULT_PARAM = 'p';
function pagination_is_valid_array(array $pagination): bool {
return !empty($pagination['count']) && !empty($pagination['range']);
}
private int $count = 0;
private int $range = 0;
private int $offset = 0;
function pagination_is_valid_offset(int $offset): bool {
return $offset !== MSZ_PAGINATION_OFFSET_INVALID;
}
public function __construct(int $count, int $range, ?string $readParam = self::DEFAULT_PARAM) {
$this->count = $count;
$this->range = $range;
// Adds 'page' and 'offset' to the pagination array transparently!!!
function pagination_offset(array &$pagination, ?int $page): int {
if(!pagination_is_valid_array($pagination)) {
return MSZ_PAGINATION_OFFSET_INVALID;
if(!empty($readParam))
$this->readPage($readParam);
}
$page = $page ?? MSZ_PAGINATION_PAGE_START;
if($page < MSZ_PAGINATION_PAGE_START) {
return MSZ_PAGINATION_OFFSET_INVALID;
public function getCount(): int {
return $this->count;
}
$offset = $pagination['range'] * ($page - 1);
if($offset > $pagination['count']) {
return MSZ_PAGINATION_OFFSET_INVALID;
public function getRange(): int {
return $this->range;
}
$pagination['page'] = $page;
return $pagination['offset'] = $offset;
}
public function getPages(): int {
return 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 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 $source[$name];
function pagination_param(string $name = 'p', int $default = 1, ?array $source = null): int {
if(!isset(($source ?? $_GET)[$name]) || !is_string(($source ?? $_GET)[$name])) {
return $default;
}
return (int)(($source ?? $_GET)[$name] ?? $default);
}

View file

@ -1,6 +1,7 @@
<?php
namespace Misuzu\Parsers\BBCode\Tags;
use Misuzu\Zalgo;
use Misuzu\Parsers\BBCode\BBCodeTag;
final class ZalgoTag extends BBCodeTag {
@ -8,7 +9,7 @@ final class ZalgoTag extends BBCodeTag {
return preg_replace_callback(
'#\[zalgo\](.+?)\[\/zalgo\]#s',
function ($matches) {
return zalgo_run($matches[1]);
return Zalgo::run($matches[1]);
},
$text
);

View file

@ -6,7 +6,7 @@ use Twig_Environment;
use Twig_Extensions_Extension_Date;
use Twig_Loader_Filesystem;
class Template {
final class Template {
private const FILE_EXT = '.twig';
private static $loader;

View file

@ -32,9 +32,6 @@ final class TwigMisuzu extends Twig_Extension {
public function getFunctions() {
return [
new Twig_Function('get_browser', 'get_browser'),
new Twig_Function('git_commit_hash', 'git_commit_hash'),
new Twig_Function('git_tag', 'git_tag'),
new Twig_Function('git_branch', 'git_branch'),
new Twig_Function('csrf_token', 'csrf_token'),
new Twig_Function('csrf_input', 'csrf_html'),
new Twig_Function('url_construct', 'url_construct'),
@ -47,12 +44,11 @@ final class TwigMisuzu extends Twig_Extension {
new Twig_Function('forum_may_have_children', 'forum_may_have_children'),
new Twig_Function('forum_may_have_topics', 'forum_may_have_topics'),
new Twig_Function('forum_has_priority_voting', 'forum_has_priority_voting'),
new Twig_Function('startup_time', function(float $time = MSZ_STARTUP) {
return microtime(true) - $time;
}),
new Twig_Function('sql_query_count', function() {
return DB::queries();
}),
new Twig_Function('git_commit_hash', fn(bool $long = false) => GitInfo::hash($long)),
new Twig_Function('git_tag', fn() => GitInfo::tag()),
new Twig_Function('git_branch', fn() => GitInfo::branch()),
new Twig_Function('startup_time', fn(float $time = MSZ_STARTUP) => microtime(true) - $time),
new Twig_Function('sql_query_count', fn() => DB::queries()),
];
}

View file

@ -1,57 +1,59 @@
<?php
namespace Misuzu;
use Codebird\Codebird;
function twitter_init(
string $apiKey,
string $apiSecretKey,
?string $token = null,
?string $tokenSecret = null
): void {
Codebird::setConsumerKey($apiKey, $apiSecretKey);
final class Twitter {
public static function init(
string $apiKey,
string $apiSecretKey,
?string $token = null,
?string $tokenSecret = null
): void {
Codebird::setConsumerKey($apiKey, $apiSecretKey);
if(!is_null($token) && !is_null($tokenSecret)) {
twitter_token_set($token, $tokenSecret);
}
}
function twitter_token_set(string $token, string $tokenSecret): void {
Codebird::getInstance()->setToken($token, $tokenSecret);
}
function twitter_auth_create(): ?string {
$codebird = Codebird::getInstance();
$reply = $codebird->oauth_requestToken([
'oauth_callback' => 'oob',
]);
if(!$reply) {
return null;
if($token !== null && $tokenSecret !== null) {
self::setToken($token, $tokenSecret);
}
}
twitter_token_set($reply->oauth_token, $reply->oauth_token_secret);
return $codebird->oauth_authorize();
}
function twitter_auth_complete(string $pin): array {
$reply = Codebird::getInstance()->oauth_accessToken([
'oauth_verifier' => $pin,
]);
if(!$reply) {
return [];
public static function setToken(string $token, string $tokenSecret): void {
Codebird::getInstance()->setToken($token, $tokenSecret);
}
twitter_token_set($reply->oauth_token, $reply->oauth_token_secret);
public static function createAuth(): ?string {
$codebird = Codebird::getInstance();
$reply = $codebird->oauth_requestToken([
'oauth_callback' => 'oob',
]);
return [
'token' => $reply->oauth_token,
'token_secret' => $reply->oauth_token_secret,
];
}
if(!$reply)
return null;
function twitter_tweet_post(string $text): void {
Codebird::getInstance()->statuses_update([
'status' => $text,
]);
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,
]);
}
}

View file

@ -15,7 +15,7 @@ define('MSZ_PERM_USER_MANAGE_ROLES', 1 << 21);
define('MSZ_PERM_USER_MANAGE_PERMS', 1 << 22);
define('MSZ_PERM_USER_MANAGE_REPORTS', 1 << 23);
define('MSZ_PERM_USER_MANAGE_WARNINGS', 1 << 24);
//define('MSZ_PERM_USER_MANAGE_BLACKLISTS', 1 << 25); // Replaced with MSZ_PERM_GENERAL_MANAGE_BLACKLIST
//define('MSZ_PERM_USER_MANAGE_BLACKLISTS', 1 << 25); // Replaced with General::PERM_MANAGE_BLACKLIST
define(
'MSZ_USERS_PASSWORD_HASH_ALGO',

View file

@ -65,8 +65,8 @@ HTML;
$json = json_encode([
'git' => [
'tag' => git_tag(),
'hash' => git_commit_hash(true),
'tag' => GitInfo::tag(),
'hash' => GitInfo::hash(true),
],
'misuzu' => [
'trace_txt' => $this->getException()->getTraceAsString(),

View file

@ -1,128 +1,122 @@
<?php
define('MSZ_ZALGO_CHARS_UP', [
"\u{030d}", "\u{030e}", "\u{0304}", "\u{0305}", "\u{033f}",
"\u{0311}", "\u{0306}", "\u{0310}", "\u{0352}", "\u{0357}",
"\u{0351}", "\u{0307}", "\u{0308}", "\u{030a}", "\u{0342}",
"\u{0344}", "\u{034a}", "\u{034b}", "\u{034c}", "\u{0303}",
"\u{0302}", "\u{030c}", "\u{0350}", "\u{0300}", "\u{0301}",
"\u{030b}", "\u{030f}", "\u{0312}", "\u{0313}", "\u{0314}",
"\u{033d}", "\u{0309}", "\u{0363}", "\u{0364}", "\u{0365}",
"\u{0366}", "\u{0367}", "\u{0368}", "\u{0369}", "\u{036a}",
"\u{036b}", "\u{036c}", "\u{036d}", "\u{036e}", "\u{036f}",
"\u{033e}", "\u{035b}", "\u{0346}", "\u{031a}",
]);
define('MSZ_ZALGO_CHARS_DOWN', [
"\u{0316}", "\u{0317}", "\u{0318}", "\u{0319}", "\u{031c}",
"\u{031d}", "\u{031e}", "\u{031f}", "\u{0320}", "\u{0324}",
"\u{0325}", "\u{0326}", "\u{0329}", "\u{032a}", "\u{032b}",
"\u{032c}", "\u{032d}", "\u{032e}", "\u{032f}", "\u{0330}",
"\u{0331}", "\u{0332}", "\u{0333}", "\u{0339}", "\u{033a}",
"\u{033b}", "\u{033c}", "\u{0345}", "\u{0347}", "\u{0348}",
"\u{0349}", "\u{034d}", "\u{034e}", "\u{0353}", "\u{0354}",
"\u{0355}", "\u{0356}", "\u{0359}", "\u{035a}", "\u{0323}",
]);
define('MSZ_ZALGO_CHARS_MIDDLE', [
"\u{0315}", "\u{031b}", "\u{0340}", "\u{0341}", "\u{0358}",
"\u{0321}", "\u{0322}", "\u{0327}", "\u{0328}", "\u{0334}",
"\u{0335}", "\u{0336}", "\u{034f}", "\u{035c}", "\u{035d}",
"\u{035e}", "\u{035f}", "\u{0360}", "\u{0362}", "\u{0338}",
"\u{0337}", "\u{0361}", "\u{0489}",
]);
namespace Misuzu;
define('MSZ_ZALGO_MODE_MINI', 1);
define('MSZ_ZALGO_MODE_NORMAL', 2);
define('MSZ_ZALGO_MODE_MAX', 3);
final class Zalgo {
public const MODE_MINI = 1;
public const MODE_NORMAL = 2;
public const MODE_MAX = 3;
define('MSZ_ZALGO_DIR_UP', 0x01);
define('MSZ_ZALGO_DIR_MID', 0x02);
define('MSZ_ZALGO_DIR_DOWN', 0x04);
public const DIR_UP = 0x01;
public const DIR_MID = 0x02;
public const DIR_DOWN = 0x04;
function zalgo_strip(string $text): string {
$text = str_replace(MSZ_ZALGO_CHARS_UP, '', $text);
$text = str_replace(MSZ_ZALGO_CHARS_DOWN, '', $text);
$text = str_replace(MSZ_ZALGO_CHARS_MIDDLE, '', $text);
private const CHARS_UP = [
"\u{030d}", "\u{030e}", "\u{0304}", "\u{0305}", "\u{033f}",
"\u{0311}", "\u{0306}", "\u{0310}", "\u{0352}", "\u{0357}",
"\u{0351}", "\u{0307}", "\u{0308}", "\u{030a}", "\u{0342}",
"\u{0344}", "\u{034a}", "\u{034b}", "\u{034c}", "\u{0303}",
"\u{0302}", "\u{030c}", "\u{0350}", "\u{0300}", "\u{0301}",
"\u{030b}", "\u{030f}", "\u{0312}", "\u{0313}", "\u{0314}",
"\u{033d}", "\u{0309}", "\u{0363}", "\u{0364}", "\u{0365}",
"\u{0366}", "\u{0367}", "\u{0368}", "\u{0369}", "\u{036a}",
"\u{036b}", "\u{036c}", "\u{036d}", "\u{036e}", "\u{036f}",
"\u{033e}", "\u{035b}", "\u{0346}", "\u{031a}",
];
private const CHARS_DOWN = [
"\u{0316}", "\u{0317}", "\u{0318}", "\u{0319}", "\u{031c}",
"\u{031d}", "\u{031e}", "\u{031f}", "\u{0320}", "\u{0324}",
"\u{0325}", "\u{0326}", "\u{0329}", "\u{032a}", "\u{032b}",
"\u{032c}", "\u{032d}", "\u{032e}", "\u{032f}", "\u{0330}",
"\u{0331}", "\u{0332}", "\u{0333}", "\u{0339}", "\u{033a}",
"\u{033b}", "\u{033c}", "\u{0345}", "\u{0347}", "\u{0348}",
"\u{0349}", "\u{034d}", "\u{034e}", "\u{0353}", "\u{0354}",
"\u{0355}", "\u{0356}", "\u{0359}", "\u{035a}", "\u{0323}",
];
private const CHARS_MIDDLE = [
"\u{0315}", "\u{031b}", "\u{0340}", "\u{0341}", "\u{0358}",
"\u{0321}", "\u{0322}", "\u{0327}", "\u{0328}", "\u{0334}",
"\u{0335}", "\u{0336}", "\u{034f}", "\u{035c}", "\u{035d}",
"\u{035e}", "\u{035f}", "\u{0360}", "\u{0362}", "\u{0338}",
"\u{0337}", "\u{0361}", "\u{0489}",
];
return $text;
}
function zalgo_is_char(string $char): bool {
return in_array($char, MSZ_ZALGO_CHARS_UP)
|| in_array($char, MSZ_ZALGO_CHARS_DOWN)
|| in_array($char, MSZ_ZALGO_CHARS_MIDDLE);
}
function zalgo_get_char(array $array): string {
return $array[array_rand($array)];
}
function zalgo_get_string(array $array, int $length): string {
$string = '';
for($i = 0; $i < $length; $i++) {
$string .= zalgo_get_char($array);
}
return $string;
}
function zalgo_run(
string $text,
int $mode = MSZ_ZALGO_MODE_MINI,
int $direction = MSZ_ZALGO_DIR_MID | MSZ_ZALGO_DIR_DOWN
): string {
$text_length = mb_strlen($text);
if(!$text_length || !$mode || !$direction) {
public static function strip(string $text): string {
$text = str_replace(self::CHARS_UP, '', $text);
$text = str_replace(self::CHARS_DOWN, '', $text);
$text = str_replace(self::CHARS_MIDDLE, '', $text);
return $text;
}
$going_up = ($direction & MSZ_ZALGO_DIR_UP) > 0;
$going_mid = ($direction & MSZ_ZALGO_DIR_MID) > 0;
$going_down = ($direction & MSZ_ZALGO_DIR_DOWN) > 0;
$str = '';
for($i = 0; $i < $text_length; $i++) {
$char = $text[$i];
if(zalgo_is_char($char)) {
continue;
}
$str .= $char;
switch($mode) {
case MSZ_ZALGO_MODE_MINI:
$num_up = mt_rand(0, 8);
$num_mid = mt_rand(0, 2);
$num_down = mt_rand(0, 8);
break;
case MSZ_ZALGO_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 MSZ_ZALGO_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 .= zalgo_get_string(MSZ_ZALGO_CHARS_UP, $num_up);
}
if($going_mid) {
$str .= zalgo_get_string(MSZ_ZALGO_CHARS_MIDDLE, $num_mid);
}
if($going_down) {
$str .= zalgo_get_string(MSZ_ZALGO_CHARS_DOWN, $num_down);
}
public static function isZalgoChar(string $char): bool {
return in_array($char, self::CHARS_UP)
|| in_array($char, self::CHARS_DOWN)
|| in_array($char, self::CHARS_MIDDLE);
}
return $str;
public static function getString(array $array, int $length): string {
$string = '';
for($i = 0; $i < $length; $i++)
$string .= array_rand_value($array);
return $string;
}
public static function run(
string $text,
int $mode = self::MODE_MINI,
int $direction = self::DIR_MID | self::DIR_DOWN
): string {
$length = mb_strlen($text);
if($length < 1 || $mode < 1 || $direction < 1) {
return $text;
}
$going_up = ($direction & self::DIR_UP) > 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;
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;
}
}

View file

@ -26,25 +26,6 @@ function changelog_action_is_valid(int $action): bool {
return array_key_exists($action, MSZ_CHANGELOG_ACTIONS);
}
function changelog_entry_create(int $userId, int $action, string $log, string $text = null): int {
if(!changelog_action_is_valid($action)) {
return -1;
}
$createChange = \Misuzu\DB::prepare('
INSERT INTO `msz_changelog_changes`
(`user_id`, `change_action`, `change_log`, `change_text`)
VALUES
(:user_id, :action, :change_log, :change_text)
');
$createChange->bind('user_id', $userId);
$createChange->bind('action', $action);
$createChange->bind('change_log', $log);
$createChange->bind('change_text', $text);
return $createChange->execute() ? \Misuzu\DB::lastId() : 0;
}
define('MSZ_CHANGELOG_GET_QUERY', '
SELECT
c.`change_id`, c.`change_log`, c.`change_action`,

View file

@ -1,6 +1,6 @@
<?php
function manage_get_menu(int $userId): array {
if(!perms_check_user(MSZ_PERMS_GENERAL, $userId, MSZ_PERM_GENERAL_CAN_MANAGE)) {
if(!perms_check_user(MSZ_PERMS_GENERAL, $userId, \Misuzu\General::PERM_CAN_MANAGE)) {
return [];
}
@ -10,19 +10,19 @@ function manage_get_menu(int $userId): array {
],
];
if(perms_check_user(MSZ_PERMS_GENERAL, $userId, MSZ_PERM_GENERAL_VIEW_LOGS)) {
if(perms_check_user(MSZ_PERMS_GENERAL, $userId, \Misuzu\General::PERM_VIEW_LOGS)) {
$menu['General']['Logs'] = url('manage-general-logs');
}
if(perms_check_user(MSZ_PERMS_GENERAL, $userId, MSZ_PERM_GENERAL_MANAGE_EMOTICONS)) {
if(perms_check_user(MSZ_PERMS_GENERAL, $userId, \Misuzu\General::PERM_MANAGE_EMOTES)) {
$menu['General']['Emoticons'] = url('manage-general-emoticons');
}
if(perms_check_user(MSZ_PERMS_GENERAL, $userId, MSZ_PERM_GENERAL_MANAGE_SETTINGS)) {
if(perms_check_user(MSZ_PERMS_GENERAL, $userId, \Misuzu\General::PERM_MANAGE_CONFIG)) {
$menu['General']['Settings'] = url('manage-general-settings');
}
if(perms_check_user(MSZ_PERMS_GENERAL, $userId, MSZ_PERM_GENERAL_MANAGE_BLACKLIST)) {
if(perms_check_user(MSZ_PERMS_GENERAL, $userId, \Misuzu\General::PERM_MANAGE_BLACKLIST)) {
$menu['General']['IP Blacklist'] = url('manage-general-blacklist');
}
@ -155,32 +155,32 @@ function manage_perms_list(array $rawPerms): array {
[
'section' => 'can-manage',
'title' => 'Can access the management panel.',
'perm' => MSZ_PERM_GENERAL_CAN_MANAGE,
'perm' => \Misuzu\General::PERM_CAN_MANAGE,
],
[
'section' => 'view-logs',
'title' => 'Can view audit logs.',
'perm' => MSZ_PERM_GENERAL_VIEW_LOGS,
'perm' => \Misuzu\General::PERM_VIEW_LOGS,
],
[
'section' => 'manage-emotes',
'title' => 'Can manage emoticons.',
'perm' => MSZ_PERM_GENERAL_MANAGE_EMOTICONS,
'perm' => \Misuzu\General::PERM_MANAGE_EMOTES,
],
[
'section' => 'manage-settings',
'title' => 'Can manage general Misuzu settings.',
'perm' => MSZ_PERM_GENERAL_MANAGE_SETTINGS,
'perm' => \Misuzu\General::PERM_MANAGE_CONFIG,
],
[
'section' => 'tester',
'title' => 'Can use experimental features.',
'perm' => MSZ_PERM_GENERAL_TESTER,
'perm' => \Misuzu\General::PERM_IS_TESTER,
],
[
'section' => 'manage-blacklist',
'title' => 'Can manage blacklistings.',
'perm' => MSZ_PERM_GENERAL_MANAGE_BLACKLIST,
'perm' => \Misuzu\General::PERM_MANAGE_BLACKLIST,
],
],
],

View file

@ -12,7 +12,7 @@
set canonical_url = url_construct(url('changelog-index'), {
'd': changelog_date,
'u': changelog_user|default(0),
'p': changelog_pagination.page|default(0) > 1 ? changelog_pagination.page : 0,
'p': changelog_pagination.page,
})
%}

View file

@ -37,15 +37,13 @@
</div>
<div class="pagination__section pagination__section--pages">
{% set p_start = info.page - page_range %}
{% set p_stop = info.page + page_range %}
{% set p_start = max(info.page - page_range, 1) %}
{% set p_stop = min(info.page + page_range, info.pages) %}
{% for i in p_start..p_stop %}
{% if i >= 1 and i <= info.pages %}
<a href="{{ url_construct(path, i <= 1 ? params : params|merge({(page_param): i}), url_fragment) }}" class="pagination__link{{ info.page == i ? ' pagination__link--current' : '' }}">
{{ i }}
</a>
{% endif %}
<a href="{{ url_construct(path, i <= 1 ? params : params|merge({(page_param): i}), url_fragment) }}" class="pagination__link{{ info.page == i ? ' pagination__link--current' : '' }}">
{{ i }}
</a>
{% endfor %}
</div>

View file

@ -25,6 +25,10 @@ function array_bit_or(array $array1, array $array2): array {
return $array1;
}
function array_rand_value(array $array) {
return $array[array_rand($array)];
}
function clamp($num, int $min, int $max): int {
return max($min, min($max, intval($num)));
}
@ -167,7 +171,7 @@ function render_info(?string $message, int $httpCode, string $template = 'errors
$template = 'errors.master';
}*/
return Template::renderRaw(sprintf($template, $httpCode));
return \Misuzu\Template::renderRaw(sprintf($template, $httpCode));
} catch(Exception $ex) {
echo $ex->getMessage();
return $message ?? '';