dbConn = $dbConn;
$this->config = $config;
$this->urls = new URLRegistry;
$this->registerURLs();
$this->perms = new Permissions($dbConn);
$this->authInfo = new AuthInfo($this->perms);
$this->siteInfo = new SiteInfo($config->scopeTo('site'));
$this->authCtx = new AuthContext($dbConn, $config->scopeTo('auth'));
$this->usersCtx = new UsersContext($dbConn);
$this->forumCtx = new ForumContext($dbConn);
$this->auditLog = new AuditLog($dbConn);
$this->changelog = new Changelog($dbConn);
$this->comments = new Comments($dbConn);
$this->counters = new Counters($dbConn);
$this->emotes = new Emotes($dbConn);
$this->news = new News($dbConn);
$this->profileFields = new ProfileFields($dbConn);
}
public function getDbConn(): IDbConnection {
return $this->dbConn;
}
public function getDbQueryCount(): int {
$result = $this->dbConn->query('SHOW SESSION STATUS LIKE "Questions"');
return $result->next() ? $result->getInteger(1) : 0;
}
public function createMigrationManager(): DbMigrationManager {
return new DbMigrationManager($this->dbConn, 'msz_' . DbMigrationManager::DEFAULT_TABLE);
}
public function createMigrationRepo(): IDbMigrationRepo {
return new FsDbMigrationRepo(MSZ_MIGRATIONS);
}
public function getURLs(): URLRegistry {
return $this->urls;
}
public function getConfig(): IConfig {
return $this->config;
}
public function getRouter(): IRouter {
return $this->router;
}
public function getEmotes(): Emotes {
return $this->emotes;
}
public function getChangelog(): Changelog {
return $this->changelog;
}
public function getNews(): News {
return $this->news;
}
public function getComments(): Comments {
return $this->comments;
}
public function getAuditLog(): AuditLog {
return $this->auditLog;
}
public function getCounters(): Counters {
return $this->counters;
}
public function getProfileFields(): ProfileFields {
return $this->profileFields;
}
public function getPerms(): Permissions {
return $this->perms;
}
public function getAuthContext(): AuthContext {
return $this->authCtx;
}
public function getUsersContext(): UsersContext {
return $this->usersCtx;
}
public function getForumContext(): ForumContext {
return $this->forumCtx;
}
public function getAuthInfo(): AuthInfo {
return $this->authInfo;
}
public function getSiteInfo(): SiteInfo {
return $this->siteInfo;
}
public function createAuditLog(string $action, array $params = [], UserInfo|string|null $userInfo = null): void {
if($userInfo === null && $this->authInfo->isLoggedIn())
$userInfo = $this->authInfo->getUserInfo();
$this->auditLog->createLog(
$userInfo,
$action,
$params,
$_SERVER['REMOTE_ADDR'] ?? '::1',
$_SERVER['COUNTRY_CODE'] ?? 'XX'
);
}
private ?bool $hasManageAccess = null;
public function hasManageAccess(): bool {
$this->hasManageAccess ??= $this->authInfo->isLoggedIn()
&& !$this->usersCtx->hasActiveBan($this->authInfo->getUserInfo())
&& $this->authInfo->getPerms('global')->check(Perm::G_IS_JANITOR);
return $this->hasManageAccess;
}
public function getWebAssetInfo(): ?object {
return json_decode(file_get_contents(MSZ_ASSETS . '/current.json'));
}
private ?string $chatUrl = null;
public function getChatURL(): string {
$this->chatUrl ??= $this->config->getString('sockChat.chatPath.normal');
return $this->chatUrl;
}
public function startTemplating(): void {
$globals = $this->config->getValues([
['eeprom.path:s', '', 'eeprom_path'],
['eeprom.app:s', '', 'eeprom_app'],
]);
$isDebug = Environment::isDebug();
$globals['site_info'] = $this->siteInfo;
$globals['auth_info'] = $this->authInfo;
$globals['assets'] = $this->getWebAssetInfo();
$globals['active_ban_info'] = $this->usersCtx->tryGetActiveBan($this->authInfo->getUserInfo());
$globals['display_timings_info'] = $isDebug || $this->authInfo->getPerms('global')->check(Perm::G_TIMINGS_VIEW);
$this->templating = new SasaeEnvironment(
MSZ_TEMPLATES,
cache: $isDebug ? null : ['Misuzu', GitInfo::hash(true)],
debug: $isDebug
);
$this->templating->addExtension(new MisuzuSasaeExtension($this));
$this->templating->addGlobal('globals', $globals);
Template::init($this->templating);
}
public function startRouter(): void {
$this->router = new HttpFx;
$this->router->use('/', function($response) {
$response->setPoweredBy('Misuzu');
});
$this->registerErrorPages();
$this->registerHttpRoutes();
}
public function dispatchRouter(?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 {
$this->router->register(new HomeRoutes(
$this->config,
$this->dbConn,
$this->siteInfo,
$this->authInfo,
$this->changelog,
$this->comments,
$this->counters,
$this->news,
$this->usersCtx
));
$this->router->register(new AssetsRoutes(
$this->authInfo,
$this->urls,
$this->usersCtx
));
$this->router->register(new InfoRoutes);
$this->router->register(new NewsRoutes(
$this->siteInfo,
$this->authInfo,
$this->urls,
$this->news,
$this->usersCtx,
$this->comments
));
$this->router->register(new ChangelogRoutes(
$this->siteInfo,
$this->urls,
$this->changelog,
$this->usersCtx,
$this->authInfo,
$this->comments
));
$this->router->register(new SharpChatRoutes(
$this->config->scopeTo('sockChat'),
$this->urls,
$this->usersCtx,
$this->authCtx,
$this->emotes,
$this->perms,
$this->authInfo
));
$this->router->register(new SatoriRoutes(
$this->config->scopeTo('satori'),
$this->usersCtx,
$this->forumCtx,
$this->profileFields
));
$this->router->register(new LegacyRoutes($this->urls));
}
public function registerURLs(): void {
// eventually this should be handled by context classes
$this->urls->register('index', '/');
$this->urls->register('info', '/info/
');
$this->urls->register('search-index', '/search.php');
$this->urls->register('search-query', '/search.php', ['q' => ''], '');
$this->urls->register('auth-login', '/auth/login.php', ['username' => '', 'redirect' => '']);
$this->urls->register('auth-login-welcome', '/auth/login.php', ['welcome' => '1', 'username' => '']);
$this->urls->register('auth-register', '/auth/register.php');
$this->urls->register('auth-forgot', '/auth/password.php');
$this->urls->register('auth-reset', '/auth/password.php', ['user' => '']);
$this->urls->register('auth-logout', '/auth/logout.php', ['csrf' => '']);
$this->urls->register('auth-resolve-user', '/auth/login.php', ['resolve' => '1', 'name' => '']);
$this->urls->register('auth-two-factor', '/auth/twofactor.php', ['token' => '']);
$this->urls->register('auth-revert', '/auth/revert.php', ['csrf' => '']);
$this->urls->register('changelog-index', '/changelog', ['date' => '', 'user' => '', 'tags' => '', 'p' => '']);
$this->urls->register('changelog-feed-rss', '/changelog.rss');
$this->urls->register('changelog-feed-atom', '/changelog.atom');
$this->urls->register('changelog-change', '/changelog/change/');
$this->urls->register('changelog-change-comments', '/changelog/change/', fragment: 'comments');
$this->urls->register('news-index', '/news', ['p' => '']);
$this->urls->register('news-category', '/news/', ['p' => '']);
$this->urls->register('news-post', '/news/post/');
$this->urls->register('news-post-comments', '/news/post/', fragment: 'comments');
$this->urls->register('news-feed-rss', '/news.rss');
$this->urls->register('news-category-feed-rss', '/news/.rss');
$this->urls->register('news-feed-atom', '/news.atom');
$this->urls->register('news-category-feed-atom', '/news/.atom');
$this->urls->register('forum-index', '/forum');
$this->urls->register('forum-leaderboard', '/forum/leaderboard.php', ['id' => '', 'mode' => '']);
$this->urls->register('forum-mark-global', '/forum/index.php', ['m' => 'mark']);
$this->urls->register('forum-mark-single', '/forum/index.php', ['m' => 'mark', 'f' => '']);
$this->urls->register('forum-topic-new', '/forum/posting.php', ['f' => '']);
$this->urls->register('forum-reply-new', '/forum/posting.php', ['t' => '']);
$this->urls->register('forum-category', '/forum/forum.php', ['f' => '', 'p' => '']);
$this->urls->register('forum-category-root', '/forum/index.php', fragment: '');
$this->urls->register('forum-topic', '/forum/topic.php', ['t' => '', 'page' => '']);
$this->urls->register('forum-topic-create', '/forum/posting.php', ['f' => '']);
$this->urls->register('forum-topic-bump', '/forum/topic.php', ['t' => '', 'm' => 'bump', 'csrf' => '']);
$this->urls->register('forum-topic-lock', '/forum/topic.php', ['t' => '', 'm' => 'lock', 'csrf' => '']);
$this->urls->register('forum-topic-unlock', '/forum/topic.php', ['t' => '', 'm' => 'unlock', 'csrf' => '']);
$this->urls->register('forum-topic-delete', '/forum/topic.php', ['t' => '', 'm' => 'delete', 'csrf' => '']);
$this->urls->register('forum-topic-restore', '/forum/topic.php', ['t' => '', 'm' => 'restore', 'csrf' => '']);
$this->urls->register('forum-topic-nuke', '/forum/topic.php', ['t' => '', 'm' => 'nuke', 'csrf' => '']);
$this->urls->register('forum-post', '/forum/topic.php', ['p' => ''], 'p');
$this->urls->register('forum-post-create', '/forum/posting.php', ['t' => '']);
$this->urls->register('forum-post-delete', '/forum/post.php', ['p' => '', 'm' => 'delete']);
$this->urls->register('forum-post-restore', '/forum/post.php', ['p' => '', 'm' => 'restore']);
$this->urls->register('forum-post-nuke', '/forum/post.php', ['p' => '', 'm' => 'nuke']);
$this->urls->register('forum-post-quote', '/forum/posting.php', ['q' => '']);
$this->urls->register('forum-post-edit', '/forum/posting.php', ['p' => '', 'm' => 'edit']);
$this->urls->register('user-list', '/members.php', ['r' => '', 'ss' => '', 'sd' => '', 'p' => '']);
$this->urls->register('user-profile', '/profile.php', ['u' => '']);
$this->urls->register('user-profile-forum-topics', '/profile.php', ['u' => '', 'm' => 'forum-topics']);
$this->urls->register('user-profile-forum-posts', '/profile.php', ['u' => '', 'm' => 'forum-posts']);
$this->urls->register('user-profile-edit', '/profile.php', ['u' => '', 'edit' => '1']);
$this->urls->register('user-account-standing', '/profile.php', ['u' => ''], 'account-standing');
$this->urls->register('user-avatar', '/assets/avatar/', ['res' => '']);
$this->urls->register('user-background', '/assets/profile-background/');
$this->urls->register('settings-index', '/settings');
$this->urls->register('settings-account', '/settings/account.php');
$this->urls->register('settings-sessions', '/settings/sessions.php', ['p' => '']);
$this->urls->register('settings-logs', '/settings/logs.php');
$this->urls->register('settings-logs-logins', '/settings/logs.php', ['ap' => '', 'hp' => ''], 'login-history');
$this->urls->register('settings-logs-account', '/settings/logs.php', ['hp' => '', 'ap' => ''], 'account-log');
$this->urls->register('settings-data', '/settings/data.php');
$this->urls->register('comment-create', '/comments.php', ['m' => 'create', 'return' => '']);
$this->urls->register('comment-vote', '/comments.php', ['c' => '', 'csrf' => '', 'm' => 'vote', 'v' => '', 'return' => '']);
$this->urls->register('comment-delete', '/comments.php', ['c' => '', 'csrf' => '', 'm' => 'delete', 'return' => '']);
$this->urls->register('comment-restore', '/comments.php', ['c' => '', 'csrf' => '', 'm' => 'restore', 'return' => '']);
$this->urls->register('comment-pin', '/comments.php', ['c' => '', 'csrf' => '', 'm' => 'pin', 'return' => '']);
$this->urls->register('comment-unpin', '/comments.php', ['c' => '', 'csrf' => '', 'm' => 'unpin', 'return' => '']);
$this->urls->register('manage-index', '/manage');
$this->urls->register('manage-general-overview', '/manage/general');
$this->urls->register('manage-general-logs', '/manage/general/logs.php', ['p' => '']);
$this->urls->register('manage-general-emoticons', '/manage/general/emoticons.php');
$this->urls->register('manage-general-emoticon', '/manage/general/emoticon.php', ['e' => '']);
$this->urls->register('manage-general-emoticon-order-up', '/manage/general/emoticons.php', ['emote' => '', 'order' => 'd', 'csrf' => '']);
$this->urls->register('manage-general-emoticon-order-down', '/manage/general/emoticons.php', ['emote' => '', 'order' => 'i', 'csrf' => '']);
$this->urls->register('manage-general-emoticon-delete', '/manage/general/emoticons.php', ['emote' => '', 'delete' => '1', 'csrf' => '']);
$this->urls->register('manage-general-emoticon-alias', '/manage/general/emoticons.php', ['emote' => '', 'alias' => '', 'csrf' => '']);
$this->urls->register('manage-general-settings', '/manage/general/settings.php');
$this->urls->register('manage-general-setting', '/manage/general/setting.php', ['name' => '', 'type' => '']);
$this->urls->register('manage-general-setting-delete', '/manage/general/setting-delete.php', ['name' => '']);
$this->urls->register('manage-forum-categories', '/manage/forum/index.php');
$this->urls->register('manage-forum-category', '/manage/forum/category.php', ['f' => '']);
$this->urls->register('manage-forum-topic-redirs', '/manage/forum/redirs.php', ['p' => '']);
$this->urls->register('manage-forum-topic-redirs-create', '/manage/forum/redirs.php');
$this->urls->register('manage-forum-topic-redirs-nuke', '/manage/forum/redirs.php', ['m' => 'explode', 't' => '', 'csrf' => '']);
$this->urls->register('manage-changelog-changes', '/manage/changelog', ['p' => '']);
$this->urls->register('manage-changelog-change', '/manage/changelog/change.php', ['c' => '']);
$this->urls->register('manage-changelog-change-delete', '/manage/changelog/change.php', ['c' => '', 'delete' => '1', 'csrf' => '']);
$this->urls->register('manage-changelog-tags', '/manage/changelog/tags.php');
$this->urls->register('manage-changelog-tag', '/manage/changelog/tag.php', ['t' => '']);
$this->urls->register('manage-changelog-tag-delete', '/manage/changelog/tag.php', ['t' => '', 'delete' => '1', 'csrf' => '']);
$this->urls->register('manage-news-categories', '/manage/news/categories.php', ['p' => '']);
$this->urls->register('manage-news-category', '/manage/news/category.php', ['c' => '']);
$this->urls->register('manage-news-category-delete', '/manage/news/category.php', ['c' => '', 'delete' => '1', 'csrf' => '']);
$this->urls->register('manage-news-posts', '/manage/news/posts.php', ['p' => '']);
$this->urls->register('manage-news-post', '/manage/news/post.php', ['p' => '']);
$this->urls->register('manage-news-post-delete', '/manage/news/post.php', ['p' => '', 'delete' => '1', 'csrf' => '']);
$this->urls->register('manage-users', '/manage/users', ['p' => '']);
$this->urls->register('manage-user', '/manage/users/user.php', ['u' => '']);
$this->urls->register('manage-users-warnings', '/manage/users/warnings.php', ['u' => '', 'p' => '']);
$this->urls->register('manage-users-warning', '/manage/users/warning.php', ['u' => '']);
$this->urls->register('manage-users-warning-delete', '/manage/users/warning.php', ['w' => '', 'delete' => '1', 'csrf' => '']);
$this->urls->register('manage-users-notes', '/manage/users/notes.php', ['u' => '', 'p' => '']);
$this->urls->register('manage-users-note', '/manage/users/note.php', ['n' => '', 'u' => '']);
$this->urls->register('manage-users-note-delete', '/manage/users/note.php', ['n' => '', 'delete' => '1', 'csrf' => '']);
$this->urls->register('manage-users-bans', '/manage/users/bans.php', ['u' => '', 'p' => '']);
$this->urls->register('manage-users-ban', '/manage/users/ban.php', ['u' => '']);
$this->urls->register('manage-users-ban-delete', '/manage/users/ban.php', ['b' => '', 'delete' => '1', 'csrf' => '']);
$this->urls->register('manage-roles', '/manage/users/roles.php', ['p' => '']);
$this->urls->register('manage-role', '/manage/users/role.php', ['r' => '']);
}
}