Restructure templating system.

This commit is contained in:
flash 2018-08-15 03:12:58 +02:00
parent d82277ebdd
commit f1979c8e4a
83 changed files with 290 additions and 463 deletions

View file

@ -13,6 +13,7 @@ require_once __DIR__ . '/src/git.php';
require_once __DIR__ . '/src/manage.php'; require_once __DIR__ . '/src/manage.php';
require_once __DIR__ . '/src/news.php'; require_once __DIR__ . '/src/news.php';
require_once __DIR__ . '/src/perms.php'; require_once __DIR__ . '/src/perms.php';
require_once __DIR__ . '/src/tpl.php';
require_once __DIR__ . '/src/zalgo.php'; require_once __DIR__ . '/src/zalgo.php';
require_once __DIR__ . '/src/Forum/forum.php'; require_once __DIR__ . '/src/Forum/forum.php';
require_once __DIR__ . '/src/Forum/post.php'; require_once __DIR__ . '/src/Forum/post.php';
@ -204,17 +205,15 @@ MIG;
$app->startCache(); $app->startCache();
$app->startTemplating(); $app->startTemplating();
$tpl = $app->getTemplating();
tpl_add_path(__DIR__ . '/templates');
if ($app->getConfig()->get('Auth', 'lockdown', 'bool', false)) { if ($app->getConfig()->get('Auth', 'lockdown', 'bool', false)) {
http_response_code(503); http_response_code(503);
$tpl->addPath('auth', __DIR__ . '/views/auth'); echo tpl_render('auth/lockdown');
echo $tpl->render('lockdown');
exit; exit;
} }
$tpl->addPath('mio', __DIR__ . '/views/mio');
if (isset($_COOKIE['msz_uid'], $_COOKIE['msz_sid'])) { if (isset($_COOKIE['msz_uid'], $_COOKIE['msz_sid'])) {
$app->startSession((int)$_COOKIE['msz_uid'], $_COOKIE['msz_sid']); $app->startSession((int)$_COOKIE['msz_uid'], $_COOKIE['msz_sid']);
@ -240,13 +239,13 @@ MIG;
'); ');
$getUserDisplayInfo->bindValue('user_id', $app->getUserId()); $getUserDisplayInfo->bindValue('user_id', $app->getUserId());
$userDisplayInfo = $getUserDisplayInfo->execute() ? $getUserDisplayInfo->fetch() : []; $userDisplayInfo = $getUserDisplayInfo->execute() ? $getUserDisplayInfo->fetch() : [];
$tpl->var('current_user', $userDisplayInfo); tpl_var('current_user', $userDisplayInfo);
} }
} }
$inManageMode = starts_with($_SERVER['REQUEST_URI'], '/manage'); $inManageMode = starts_with($_SERVER['REQUEST_URI'], '/manage');
$hasManageAccess = perms_check(perms_get_user(MSZ_PERMS_GENERAL, $app->getUserId()), MSZ_GENERAL_PERM_CAN_MANAGE); $hasManageAccess = perms_check(perms_get_user(MSZ_PERMS_GENERAL, $app->getUserId()), MSZ_GENERAL_PERM_CAN_MANAGE);
$tpl->var('has_manage_access', $hasManageAccess); tpl_var('has_manage_access', $hasManageAccess);
if ($inManageMode) { if ($inManageMode) {
if (!$hasManageAccess) { if (!$hasManageAccess) {
@ -254,8 +253,6 @@ MIG;
exit; exit;
} }
$tpl = $app->getTemplating(); tpl_var('manage_menu', manage_get_menu($app->getUserId()));
$tpl->var('manage_menu', manage_get_menu($app->getUserId()));
$tpl->addPath('manage', __DIR__ . '/views/manage');
} }
} }

View file

@ -8,7 +8,6 @@ use Misuzu\Users\Session;
require_once __DIR__ . '/../misuzu.php'; require_once __DIR__ . '/../misuzu.php';
$config = $app->getConfig(); $config = $app->getConfig();
$tpl = $app->getTemplating();
$usernameValidationErrors = [ $usernameValidationErrors = [
'trim' => 'Your username may not start or end with spaces!', 'trim' => 'Your username may not start or end with spaces!',
@ -22,9 +21,8 @@ $usernameValidationErrors = [
$authMode = $_GET['m'] ?? 'login'; $authMode = $_GET['m'] ?? 'login';
$preventRegistration = $config->get('Auth', 'prevent_registration', 'bool', false); $preventRegistration = $config->get('Auth', 'prevent_registration', 'bool', false);
$tpl->addPath('auth', __DIR__ . '/../views/auth');
$tpl->vars([ tpl_vars([
'prevent_registration' => $preventRegistration, 'prevent_registration' => $preventRegistration,
'auth_mode' => $authMode, 'auth_mode' => $authMode,
'auth_username' => $_REQUEST['username'] ?? '', 'auth_username' => $_REQUEST['username'] ?? '',
@ -46,7 +44,7 @@ switch ($authMode) {
return; return;
} }
echo $tpl->render('@auth.logout'); echo tpl_render('auth.logout');
break; break;
case 'reset': case 'reset':
@ -69,7 +67,7 @@ switch ($authMode) {
break; break;
} }
$tpl->var('auth_reset_message', 'A verification code should\'ve been sent to your e-mail address.'); tpl_var('auth_reset_message', 'A verification code should\'ve been sent to your e-mail address.');
while ($_SERVER['REQUEST_METHOD'] === 'POST') { while ($_SERVER['REQUEST_METHOD'] === 'POST') {
$validateRequest = Database::prepare(' $validateRequest = Database::prepare('
@ -87,21 +85,21 @@ switch ($authMode) {
: false; : false;
if (!$validateRequest) { if (!$validateRequest) {
$tpl->var('auth_reset_error', 'Invalid verification code!'); tpl_var('auth_reset_error', 'Invalid verification code!');
break; break;
} }
$tpl->var('reset_verify', $_POST['verification']); tpl_var('reset_verify', $_POST['verification']);
if (empty($_POST['password']['new']) if (empty($_POST['password']['new'])
|| empty($_POST['password']['confirm']) || empty($_POST['password']['confirm'])
|| $_POST['password']['new'] !== $_POST['password']['confirm']) { || $_POST['password']['new'] !== $_POST['password']['confirm']) {
$tpl->var('auth_reset_error', 'Your passwords didn\'t match!'); tpl_var('auth_reset_error', 'Your passwords didn\'t match!');
break; break;
} }
if (user_validate_password($_POST['password']['new']) !== '') { if (user_validate_password($_POST['password']['new']) !== '') {
$tpl->var('auth_reset_error', 'Your password is too weak!'); tpl_var('auth_reset_error', 'Your password is too weak!');
break; break;
} }
@ -136,7 +134,7 @@ switch ($authMode) {
break; break;
} }
echo $tpl->render('@auth.password', [ echo tpl_render('auth.password', [
'reset_user' => $resetUser, 'reset_user' => $resetUser,
]); ]);
break; break;
@ -149,7 +147,7 @@ switch ($authMode) {
while ($_SERVER['REQUEST_METHOD'] === 'POST') { while ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (empty($_POST['email'])) { if (empty($_POST['email'])) {
$tpl->var('auth_forgot_error', 'Please enter an e-mail address.'); tpl_var('auth_forgot_error', 'Please enter an e-mail address.');
break; break;
} }
@ -221,7 +219,7 @@ MSG;
break; break;
} }
echo $tpl->render('@auth.auth'); echo tpl_render('auth.auth');
break; break;
case 'login': case 'login':
@ -298,10 +296,10 @@ MSG;
} }
if (!empty($authLoginError)) { if (!empty($authLoginError)) {
$tpl->var('auth_login_error', $authLoginError); tpl_var('auth_login_error', $authLoginError);
} }
echo $tpl->render('@auth.auth'); echo tpl_render('auth.auth');
break; break;
case 'register': case 'register':
@ -359,14 +357,14 @@ MSG;
user_role_add($createUser, MSZ_ROLE_MAIN); user_role_add($createUser, MSZ_ROLE_MAIN);
$tpl->var('auth_register_message', 'Welcome to Flashii! You may now log in.'); tpl_var('auth_register_message', 'Welcome to Flashii! You may now log in.');
break; break;
} }
if (!empty($authRegistrationError)) { if (!empty($authRegistrationError)) {
$tpl->var('auth_register_error', $authRegistrationError); tpl_var('auth_register_error', $authRegistrationError);
} }
echo $tpl->render('@auth.auth'); echo tpl_render('auth.auth');
break; break;
} }

View file

@ -3,8 +3,6 @@ use Misuzu\Database;
require_once __DIR__ . '/../misuzu.php'; require_once __DIR__ . '/../misuzu.php';
$tpl = $app->getTemplating();
$changelogOffset = max((int)($_GET['o'] ?? 0), 0); $changelogOffset = max((int)($_GET['o'] ?? 0), 0);
$changelogRange = 30; $changelogRange = 30;
@ -15,7 +13,7 @@ $changelogTags = $_GET['t'] ?? '';
$commentPerms = comments_get_perms($app->getUserId()); $commentPerms = comments_get_perms($app->getUserId());
$tpl->vars([ tpl_vars([
'changelog_offset' => $changelogOffset, 'changelog_offset' => $changelogOffset,
'changelog_take' => $changelogRange, 'changelog_take' => $changelogRange,
'comments_perms' => $commentPerms, 'comments_perms' => $commentPerms,
@ -55,10 +53,10 @@ if ($changelogChange > 0) {
'); ');
$getTags->bindValue('change_id', $change['change_id']); $getTags->bindValue('change_id', $change['change_id']);
$tags = $getTags->execute() ? $getTags->fetchAll(PDO::FETCH_ASSOC) : []; $tags = $getTags->execute() ? $getTags->fetchAll(PDO::FETCH_ASSOC) : [];
$tpl->var('tags', $tags); tpl_var('tags', $tags);
} }
echo $tpl->render('changelog.change', [ echo tpl_render('changelog.change', [
'change' => $change, 'change' => $change,
'comments_category' => $commentsCategory = comments_category_info( 'comments_category' => $commentsCategory = comments_category_info(
"changelog-date-{$change['change_date']}", "changelog-date-{$change['change_date']}",
@ -88,13 +86,13 @@ if (!$changes) {
} }
if (!empty($changelogDate)) { if (!empty($changelogDate)) {
$tpl->vars([ tpl_vars([
'comments_category' => $commentsCategory = comments_category_info("changelog-date-{$changelogDate}", true), 'comments_category' => $commentsCategory = comments_category_info("changelog-date-{$changelogDate}", true),
'comments' => comments_category_get($commentsCategory['category_id'], $app->getUserId()), 'comments' => comments_category_get($commentsCategory['category_id'], $app->getUserId()),
]); ]);
} }
echo $tpl->render('changelog.index', [ echo tpl_render('changelog.index', [
'changes' => $changes, 'changes' => $changes,
'changelog_count' => $changesCount, 'changelog_count' => $changesCount,
'changelog_date' => $changelogDate, 'changelog_date' => $changelogDate,

View file

@ -10,7 +10,6 @@ if ($forumId === 0) {
exit; exit;
} }
$templating = $app->getTemplating();
$forum = forum_fetch($forumId); $forum = forum_fetch($forumId);
if (empty($forum) || ($forum['forum_type'] == MSZ_FORUM_TYPE_LINK && empty($forum['forum_link']))) { if (empty($forum) || ($forum['forum_type'] == MSZ_FORUM_TYPE_LINK && empty($forum['forum_link']))) {
@ -35,7 +34,7 @@ foreach ($forum['forum_subforums'] as $skey => $subforum) {
= forum_get_children($subforum['forum_id'], $app->getUserId(), true); = forum_get_children($subforum['forum_id'], $app->getUserId(), true);
} }
echo $app->getTemplating()->render('forum.forum', [ echo tpl_render('forum.forum', [
'forum_breadcrumbs' => forum_get_breadcrumbs($forum['forum_id']), 'forum_breadcrumbs' => forum_get_breadcrumbs($forum['forum_id']),
'forum_info' => $forum, 'forum_info' => $forum,
'forum_topics' => $topics, 'forum_topics' => $topics,

View file

@ -17,7 +17,7 @@ foreach ($categories as $key => $category) {
} }
} }
echo $app->getTemplating()->render('forum.index', [ echo tpl_render('forum.index', [
'forum_categories' => $categories, 'forum_categories' => $categories,
'forum_empty' => $blankForum, 'forum_empty' => $blankForum,
]); ]);

View file

@ -4,8 +4,6 @@ use Misuzu\Net\IPAddress;
require_once __DIR__ . '/../../misuzu.php'; require_once __DIR__ . '/../../misuzu.php';
$templating = $app->getTemplating();
if (!$app->hasActiveSession()) { if (!$app->hasActiveSession()) {
echo render_error(403); echo render_error(403);
return; return;
@ -132,10 +130,10 @@ if ($postRequest) {
} }
if (!empty($topic)) { if (!empty($topic)) {
$templating->var('posting_topic', $topic); tpl_var('posting_topic', $topic);
} }
echo $templating->render('forum.posting', [ echo tpl_render('forum.posting', [
'posting_breadcrumbs' => forum_get_breadcrumbs($forumId), 'posting_breadcrumbs' => forum_get_breadcrumbs($forumId),
'posting_forum' => $forum, 'posting_forum' => $forum,
]); ]);

View file

@ -1,8 +1,6 @@
<?php <?php
require_once __DIR__ . '/../../misuzu.php'; require_once __DIR__ . '/../../misuzu.php';
$templating = $app->getTemplating();
$postId = (int)($_GET['p'] ?? 0); $postId = (int)($_GET['p'] ?? 0);
$topicId = (int)($_GET['t'] ?? 0); $topicId = (int)($_GET['t'] ?? 0);
$postsOffset = max((int)($_GET['o'] ?? 0), 0); $postsOffset = max((int)($_GET['o'] ?? 0), 0);
@ -33,7 +31,7 @@ if (!$posts) {
forum_topic_mark_read($app->getUserId(), $topic['topic_id'], $topic['forum_id']); forum_topic_mark_read($app->getUserId(), $topic['topic_id'], $topic['forum_id']);
echo $templating->render('forum.topic', [ echo tpl_render('forum.topic', [
'topic_breadcrumbs' => forum_get_breadcrumbs($topic['forum_id']), 'topic_breadcrumbs' => forum_get_breadcrumbs($topic['forum_id']),
'topic_info' => $topic, 'topic_info' => $topic,
'topic_posts' => $posts, 'topic_posts' => $posts,

View file

@ -6,10 +6,9 @@ use Misuzu\Database;
require_once __DIR__ . '/../misuzu.php'; require_once __DIR__ . '/../misuzu.php';
$config = $app->getConfig(); $config = $app->getConfig();
$tpl = $app->getTemplating();
if ($config->get('Site', 'embed_linked_data', 'bool', false)) { if ($config->get('Site', 'embed_linked_data', 'bool', false)) {
$tpl->vars([ tpl_vars([
'embed_linked_data' => true, 'embed_linked_data' => true,
'embed_name' => $config->get('Site', 'name'), 'embed_name' => $config->get('Site', 'name'),
'embed_url' => $config->get('Site', 'url'), 'embed_url' => $config->get('Site', 'url'),
@ -72,7 +71,7 @@ $changelog = Cache::instance()->get('index:changelog:v1', function () {
')->fetchAll(PDO::FETCH_ASSOC); ')->fetchAll(PDO::FETCH_ASSOC);
}, 1800); }, 1800);
echo $tpl->render('home.index', [ echo tpl_render('home.index', [
'users_count' => $statistics['users'], 'users_count' => $statistics['users'],
'last_user' => $statistics['lastUser'], 'last_user' => $statistics['lastUser'],
'featured_changelog' => $changelog, 'featured_changelog' => $changelog,

View file

@ -3,10 +3,7 @@ use Misuzu\Database;
require_once __DIR__ . '/../../misuzu.php'; require_once __DIR__ . '/../../misuzu.php';
$tpl = $app->getTemplating();
$changelogPerms = perms_get_user(MSZ_PERMS_CHANGELOG, $app->getUserId()); $changelogPerms = perms_get_user(MSZ_PERMS_CHANGELOG, $app->getUserId());
$queryOffset = (int)($_GET['o'] ?? 0); $queryOffset = (int)($_GET['o'] ?? 0);
switch ($_GET['v'] ?? null) { switch ($_GET['v'] ?? null) {
@ -58,7 +55,7 @@ switch ($_GET['v'] ?? null) {
$changes[$i]['tags'] = $getTags->execute() ? $getTags->fetchAll(PDO::FETCH_ASSOC) : []; $changes[$i]['tags'] = $getTags->execute() ? $getTags->fetchAll(PDO::FETCH_ASSOC) : [];
} }
echo $tpl->render('@manage.changelog.changes', [ echo tpl_render('manage.changelog.changes', [
'changelog_changes' => $changes, 'changelog_changes' => $changes,
'changelog_changes_count' => $changesCount, 'changelog_changes_count' => $changesCount,
'changelog_offset' => $queryOffset, 'changelog_offset' => $queryOffset,
@ -157,7 +154,7 @@ switch ($_GET['v'] ?? null) {
SELECT `action_id`, `action_name` SELECT `action_id`, `action_name`
FROM `msz_changelog_actions` FROM `msz_changelog_actions`
')->fetchAll(PDO::FETCH_ASSOC); ')->fetchAll(PDO::FETCH_ASSOC);
$tpl->var('changelog_actions', $actions); tpl_var('changelog_actions', $actions);
if ($changeId > 0) { if ($changeId > 0) {
$getChange = Database::prepare(' $getChange = Database::prepare('
@ -171,7 +168,7 @@ switch ($_GET['v'] ?? null) {
$change = $getChange->execute() ? $getChange->fetch(PDO::FETCH_ASSOC) : []; $change = $getChange->execute() ? $getChange->fetch(PDO::FETCH_ASSOC) : [];
if ($change) { if ($change) {
$tpl->var('edit_change', $change); tpl_var('edit_change', $change);
$assignedTags = Database::prepare(' $assignedTags = Database::prepare('
SELECT `tag_id`, `tag_name` SELECT `tag_id`, `tag_name`
@ -198,7 +195,7 @@ switch ($_GET['v'] ?? null) {
$availableTags->bindValue('change_id', $change['change_id']); $availableTags->bindValue('change_id', $change['change_id']);
$availableTags = $availableTags->execute() ? $availableTags->fetchAll(PDO::FETCH_ASSOC) : []; $availableTags = $availableTags->execute() ? $availableTags->fetchAll(PDO::FETCH_ASSOC) : [];
$tpl->vars([ tpl_vars([
'edit_change_assigned_tags' => $assignedTags, 'edit_change_assigned_tags' => $assignedTags,
'edit_change_available_tags' => $availableTags, 'edit_change_available_tags' => $availableTags,
]); ]);
@ -208,7 +205,7 @@ switch ($_GET['v'] ?? null) {
} }
} }
echo $tpl->render('@manage.changelog.change_edit'); echo tpl_render('manage.changelog.change_edit');
break; break;
case 'tags': case 'tags':
@ -240,7 +237,7 @@ switch ($_GET['v'] ?? null) {
$getTags->bindValue('offset', $queryOffset); $getTags->bindValue('offset', $queryOffset);
$tags = $getTags->execute() ? $getTags->fetchAll(PDO::FETCH_ASSOC) : []; $tags = $getTags->execute() ? $getTags->fetchAll(PDO::FETCH_ASSOC) : [];
echo $tpl->render('@manage.changelog.tags', [ echo tpl_render('manage.changelog.tags', [
'changelog_tags' => $tags, 'changelog_tags' => $tags,
'changelog_tags_count' => $tagsCount, 'changelog_tags_count' => $tagsCount,
'changelog_take' => $tagsTake, 'changelog_take' => $tagsTake,
@ -303,14 +300,14 @@ switch ($_GET['v'] ?? null) {
$tag = $getTag->execute() ? $getTag->fetch(PDO::FETCH_ASSOC) : []; $tag = $getTag->execute() ? $getTag->fetch(PDO::FETCH_ASSOC) : [];
if ($tag) { if ($tag) {
$tpl->var('edit_tag', $tag); tpl_var('edit_tag', $tag);
} else { } else {
header('Location: ?v=tags'); header('Location: ?v=tags');
return; return;
} }
} }
echo $tpl->render('@manage.changelog.tag_edit'); echo tpl_render('manage.changelog.tag_edit');
break; break;
case 'actions': case 'actions':
@ -342,7 +339,7 @@ switch ($_GET['v'] ?? null) {
$getActions->bindValue('offset', $queryOffset); $getActions->bindValue('offset', $queryOffset);
$actions = $getActions->execute() ? $getActions->fetchAll(PDO::FETCH_ASSOC) : []; $actions = $getActions->execute() ? $getActions->fetchAll(PDO::FETCH_ASSOC) : [];
echo $tpl->render('@manage.changelog.actions', [ echo tpl_render('manage.changelog.actions', [
'changelog_actions' => $actions, 'changelog_actions' => $actions,
'changelog_actions_count' => $actionTake, 'changelog_actions_count' => $actionTake,
'changelog_take' => $actionTake, 'changelog_take' => $actionTake,
@ -414,13 +411,13 @@ switch ($_GET['v'] ?? null) {
$action = $getAction->execute() ? $getAction->fetch(PDO::FETCH_ASSOC) : []; $action = $getAction->execute() ? $getAction->fetch(PDO::FETCH_ASSOC) : [];
if ($action) { if ($action) {
$tpl->var('edit_action', $action); tpl_var('edit_action', $action);
} else { } else {
header('Location: ?v=actions'); header('Location: ?v=actions');
return; return;
} }
} }
echo $tpl->render('@manage.changelog.action_edit'); echo tpl_render('manage.changelog.action_edit');
break; break;
} }

View file

@ -2,12 +2,11 @@
require_once __DIR__ . '/../../misuzu.php'; require_once __DIR__ . '/../../misuzu.php';
$generalPerms = perms_get_user(MSZ_PERMS_GENERAL, $app->getUserId()); $generalPerms = perms_get_user(MSZ_PERMS_GENERAL, $app->getUserId());
$tpl = $app->getTemplating();
switch ($_GET['v'] ?? null) { switch ($_GET['v'] ?? null) {
default: default:
case 'overview': case 'overview':
echo $tpl->render('@manage.general.overview'); echo tpl_render('manage.general.overview');
break; break;
case 'logs': case 'logs':

View file

@ -3,14 +3,11 @@ use Misuzu\Database;
require_once __DIR__ . '/../../misuzu.php'; require_once __DIR__ . '/../../misuzu.php';
$tpl = $app->getTemplating();
$userPerms = perms_get_user(MSZ_PERMS_USER, $app->getUserId()); $userPerms = perms_get_user(MSZ_PERMS_USER, $app->getUserId());
$isPostRequest = $_SERVER['REQUEST_METHOD'] === 'POST'; $isPostRequest = $_SERVER['REQUEST_METHOD'] === 'POST';
$queryQffset = (int)($_GET['o'] ?? 0); $queryQffset = (int)($_GET['o'] ?? 0);
$tpl->vars([ tpl_vars([
'can_manage_users' => $canManageUsers = perms_check($userPerms, MSZ_USER_PERM_MANAGE_USERS), 'can_manage_users' => $canManageUsers = perms_check($userPerms, MSZ_USER_PERM_MANAGE_USERS),
'can_manage_roles' => $canManageRoles = perms_check($userPerms, MSZ_USER_PERM_MANAGE_ROLES), 'can_manage_roles' => $canManageRoles = perms_check($userPerms, MSZ_USER_PERM_MANAGE_ROLES),
'can_manage_perms' => $canManagePerms = perms_check($userPerms, MSZ_USER_PERM_MANAGE_PERMS), 'can_manage_perms' => $canManagePerms = perms_check($userPerms, MSZ_USER_PERM_MANAGE_PERMS),
@ -44,13 +41,13 @@ switch ($_GET['v'] ?? null) {
$getManageUsers->bindValue('take', $usersTake); $getManageUsers->bindValue('take', $usersTake);
$manageUsers = $getManageUsers->execute() ? $getManageUsers->fetchAll() : []; $manageUsers = $getManageUsers->execute() ? $getManageUsers->fetchAll() : [];
$tpl->vars([ tpl_vars([
'manage_users' => $manageUsers, 'manage_users' => $manageUsers,
'manage_users_count' => $manageUsersCount, 'manage_users_count' => $manageUsersCount,
'manage_users_range' => $usersTake, 'manage_users_range' => $usersTake,
'manage_users_offset' => $queryQffset, 'manage_users_offset' => $queryQffset,
]); ]);
echo $tpl->render('@manage.users.listing'); echo tpl_render('manage.users.listing');
break; break;
case 'view': case 'view':
@ -111,7 +108,7 @@ switch ($_GET['v'] ?? null) {
$availableRoles = $getAvailableRoles->execute() ? $getAvailableRoles->fetchAll() : []; $availableRoles = $getAvailableRoles->execute() ? $getAvailableRoles->fetchAll() : [];
if ($canManagePerms) { if ($canManagePerms) {
$tpl->var('permissions', $permissions = manage_perms_list(perms_get_user_raw($userId))); tpl_var('permissions', $permissions = manage_perms_list(perms_get_user_raw($userId)));
} }
if ($isPostRequest) { if ($isPostRequest) {
@ -251,13 +248,13 @@ switch ($_GET['v'] ?? null) {
break; break;
} }
$tpl->vars([ tpl_vars([
'available_roles' => $availableRoles, 'available_roles' => $availableRoles,
'has_roles' => $hasRoles, 'has_roles' => $hasRoles,
'view_user' => $manageUser, 'view_user' => $manageUser,
'profile_fields' => user_profile_fields_get(), 'profile_fields' => user_profile_fields_get(),
]); ]);
echo $tpl->render('@manage.users.view'); echo tpl_render('manage.users.view');
break; break;
case 'roles': case 'roles':
@ -287,13 +284,13 @@ switch ($_GET['v'] ?? null) {
$getManageRoles->bindValue('take', $rolesTake); $getManageRoles->bindValue('take', $rolesTake);
$manageRoles = $getManageRoles->execute() ? $getManageRoles->fetchAll() : []; $manageRoles = $getManageRoles->execute() ? $getManageRoles->fetchAll() : [];
$tpl->vars([ tpl_vars([
'manage_roles' => $manageRoles, 'manage_roles' => $manageRoles,
'manage_roles_count' => $manageRolesCount, 'manage_roles_count' => $manageRolesCount,
'manage_roles_range' => $rolesTake, 'manage_roles_range' => $rolesTake,
'manage_roles_offset' => $queryQffset, 'manage_roles_offset' => $queryQffset,
]); ]);
echo $tpl->render('@manage.users.roles'); echo tpl_render('manage.users.roles');
break; break;
case 'role': case 'role':
@ -305,7 +302,7 @@ switch ($_GET['v'] ?? null) {
$roleId = $_GET['r'] ?? null; $roleId = $_GET['r'] ?? null;
if ($canManagePerms) { if ($canManagePerms) {
$tpl->var('permissions', $permissions = manage_perms_list(perms_get_role_raw($roleId ?? 0))); tpl_var('permissions', $permissions = manage_perms_list(perms_get_role_raw($roleId ?? 0)));
} }
if ($isPostRequest) { if ($isPostRequest) {
@ -470,9 +467,9 @@ switch ($_GET['v'] ?? null) {
break; break;
} }
$tpl->vars(['edit_role' => $editRole]); tpl_vars(['edit_role' => $editRole]);
} }
echo $tpl->render('@manage.users.roles_create'); echo tpl_render('manage.users.roles_create');
break; break;
} }

View file

@ -58,8 +58,6 @@ if (empty($orderDir)) {
return; return;
} }
$tpl = $app->getTemplating();
$getRole = Database::prepare(' $getRole = Database::prepare('
SELECT SELECT
`role_id`, `role_name`, `role_colour`, `role_description`, `created_at`, `role_id`, `role_name`, `role_colour`, `role_description`, `created_at`,
@ -118,7 +116,7 @@ $getUsers->bindValue('offset', $usersOffset);
$getUsers->bindValue('take', $usersTake); $getUsers->bindValue('take', $usersTake);
$users = $getUsers->execute() ? $getUsers->fetchAll(PDO::FETCH_ASSOC) : []; $users = $getUsers->execute() ? $getUsers->fetchAll(PDO::FETCH_ASSOC) : [];
echo $tpl->render('user.listing', [ echo tpl_render('user.listing', [
'roles' => $roles, 'roles' => $roles,
'role' => $role, 'role' => $role,
'users' => $users, 'users' => $users,

View file

@ -3,14 +3,12 @@ use Misuzu\Database;
require_once __DIR__ . '/../misuzu.php'; require_once __DIR__ . '/../misuzu.php';
$templating = $app->getTemplating();
$categoryId = isset($_GET['c']) ? (int)$_GET['c'] : null; $categoryId = isset($_GET['c']) ? (int)$_GET['c'] : null;
$postId = isset($_GET['p']) ? (int)$_GET['p'] : (isset($_GET['n']) ? (int)$_GET['n'] : null); $postId = isset($_GET['p']) ? (int)$_GET['p'] : (isset($_GET['n']) ? (int)$_GET['n'] : null);
$postsOffset = (int)($_GET['o'] ?? 0); $postsOffset = (int)($_GET['o'] ?? 0);
$postsTake = 5; $postsTake = 5;
$templating->vars([ tpl_vars([
'posts_offset' => $postsOffset, 'posts_offset' => $postsOffset,
'posts_take' => $postsTake, 'posts_take' => $postsTake,
]); ]);
@ -57,7 +55,7 @@ if ($postId !== null) {
$commentsInfo = comments_category_info($post['comment_section_id']); $commentsInfo = comments_category_info($post['comment_section_id']);
} }
echo $templating->render('news.post', [ echo tpl_render('news.post', [
'post' => $post, 'post' => $post,
'comments_perms' => comments_get_perms($app->getUserId()), 'comments_perms' => comments_get_perms($app->getUserId()),
'comments_category' => $commentsInfo, 'comments_category' => $commentsInfo,
@ -123,7 +121,7 @@ if ($categoryId !== null) {
$getFeatured->bindValue('category_id', $category['category_id'], PDO::PARAM_INT); $getFeatured->bindValue('category_id', $category['category_id'], PDO::PARAM_INT);
$featured = $getFeatured->execute() ? $getFeatured->fetchAll() : []; $featured = $getFeatured->execute() ? $getFeatured->fetchAll() : [];
echo $templating->render('news.category', compact('category', 'posts', 'featured')); echo tpl_render('news.category', compact('category', 'posts', 'featured'));
return; return;
} }
@ -149,7 +147,7 @@ $postsCount = (int)Database::query('
AND c.`is_hidden` = false AND c.`is_hidden` = false
')->fetchColumn(); ')->fetchColumn();
$templating->var('posts_count', $postsCount); tpl_var('posts_count', $postsCount);
if ($postsOffset < 0 || $postsOffset >= $postsCount) { if ($postsOffset < 0 || $postsOffset >= $postsCount) {
echo render_error(404); echo render_error(404);
@ -188,4 +186,4 @@ if (!$posts) {
return; return;
} }
echo $templating->render('news.index', compact('categories', 'posts')); echo tpl_render('news.index', compact('categories', 'posts'));

View file

@ -40,8 +40,6 @@ switch ($mode) {
case 'view': case 'view':
default: default:
$templating = $app->getTemplating();
$getProfile = Database::prepare(' $getProfile = Database::prepare('
SELECT SELECT
u.*, u.*,
@ -77,11 +75,11 @@ switch ($mode) {
if (!$profile) { if (!$profile) {
http_response_code(404); http_response_code(404);
echo $templating->render('user.notfound'); echo tpl_render('user.notfound');
break; break;
} }
$templating->vars(compact('profile')); tpl_vars(compact('profile'));
echo $templating->render('user.view'); echo tpl_render('user.view');
break; break;
} }

View file

@ -4,8 +4,6 @@ use Misuzu\IO\File;
require_once __DIR__ . '/../misuzu.php'; require_once __DIR__ . '/../misuzu.php';
$tpl = $app->getTemplating();
$queryOffset = (int)($_GET['o'] ?? 0); $queryOffset = (int)($_GET['o'] ?? 0);
$queryTake = 15; $queryTake = 15;
@ -53,7 +51,7 @@ $avatarErrorStrings = [
], ],
]; ];
$tpl->vars([ tpl_vars([
'settings_perms' => $perms, 'settings_perms' => $perms,
'settings_mode' => $settingsMode, 'settings_mode' => $settingsMode,
'settings_modes' => $settingsModes, 'settings_modes' => $settingsModes,
@ -61,8 +59,8 @@ $tpl->vars([
if (!array_key_exists($settingsMode, $settingsModes)) { if (!array_key_exists($settingsMode, $settingsModes)) {
http_response_code(404); http_response_code(404);
$tpl->var('settings_title', 'Not Found'); tpl_var('settings_title', 'Not Found');
echo $tpl->render('settings.notfound'); echo tpl_render('settings.notfound');
return; return;
} }
@ -269,8 +267,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
} }
} }
$tpl->var('settings_title', $settingsModes[$settingsMode]); tpl_vars([
$tpl->var('settings_errors', $settingsErrors); 'settings_title' => $settingsModes[$settingsMode],
'settings_errors' => $settingsErrors,
]);
switch ($settingsMode) { switch ($settingsMode) {
case 'account': case 'account':
@ -292,7 +292,7 @@ switch ($settingsMode) {
$currentEmail = $getMail->execute() ? $getMail->fetchColumn() : 'Failed to fetch e-mail address.'; $currentEmail = $getMail->execute() ? $getMail->fetchColumn() : 'Failed to fetch e-mail address.';
$userHasAvatar = File::exists($app->getStore('avatars/original')->filename($avatarFileName)); $userHasAvatar = File::exists($app->getStore('avatars/original')->filename($avatarFileName));
$tpl->vars([ tpl_vars([
'avatar_user_id' => $app->getUserId(), 'avatar_user_id' => $app->getUserId(),
'avatar_max_width' => $avatarWidthMax, 'avatar_max_width' => $avatarWidthMax,
'avatar_max_height' => $avatarHeightMax, 'avatar_max_height' => $avatarHeightMax,
@ -328,7 +328,7 @@ switch ($settingsMode) {
$getSessions->bindValue('user_id', $app->getUserId()); $getSessions->bindValue('user_id', $app->getUserId());
$sessions = $getSessions->execute() ? $getSessions->fetchAll() : []; $sessions = $getSessions->execute() ? $getSessions->fetchAll() : [];
$tpl->vars([ tpl_vars([
'active_session_id' => $app->getSessionId(), 'active_session_id' => $app->getSessionId(),
'user_sessions' => $sessions, 'user_sessions' => $sessions,
'sessions_offset' => $queryOffset, 'sessions_offset' => $queryOffset,
@ -370,7 +370,7 @@ switch ($settingsMode) {
$app->getUserId() $app->getUserId()
); );
$tpl->vars([ tpl_vars([
'audit_logs' => $auditLog, 'audit_logs' => $auditLog,
'audit_log_count' => $auditLogCount, 'audit_log_count' => $auditLogCount,
'audit_log_take' => $queryTake, 'audit_log_take' => $queryTake,
@ -397,4 +397,4 @@ switch ($settingsMode) {
break; break;
} }
echo $tpl->render("settings.{$settingsMode}"); echo tpl_render("settings.{$settingsMode}");

View file

@ -270,54 +270,42 @@ class Application extends ApplicationBase
throw new UnexpectedValueException('Templating module has already been started.'); throw new UnexpectedValueException('Templating module has already been started.');
} }
$this->templatingInstance = new TemplateEngine; tpl_init([
$this->templatingInstance->debug($this->debugMode); 'debug' => $this->debugMode,
]);
$this->templatingInstance->var('globals', [ tpl_var('globals', [
'site_name' => $this->configInstance->get('Site', 'name', 'string', 'Flashii'), 'site_name' => $this->configInstance->get('Site', 'name', 'string', 'Flashii'),
'site_description' => $this->configInstance->get('Site', 'description'), 'site_description' => $this->configInstance->get('Site', 'description'),
'site_twitter' => $this->configInstance->get('Site', 'twitter'), 'site_twitter' => $this->configInstance->get('Site', 'twitter'),
'site_url' => $this->configInstance->get('Site', 'url'), 'site_url' => $this->configInstance->get('Site', 'url'),
]); ]);
$this->templatingInstance->addFilter('json_decode'); tpl_add_function('json_decode', true);
$this->templatingInstance->addFilter('byte_symbol'); tpl_add_function('byte_symbol', true);
$this->templatingInstance->addFilter('html_link'); tpl_add_function('html_link', true);
$this->templatingInstance->addFilter('html_colour'); tpl_add_function('html_colour', true);
$this->templatingInstance->addFilter('url_construct'); tpl_add_function('url_construct', true);
$this->templatingInstance->addFilter('country_name', 'get_country_name'); tpl_add_function('country_name', true, 'get_country_name');
$this->templatingInstance->addFilter('flip', 'array_flip'); tpl_add_function('flip', true, 'array_flip');
$this->templatingInstance->addFilter('first_paragraph'); tpl_add_function('first_paragraph', true);
$this->templatingInstance->addFilter('colour_get_css'); tpl_add_function('colour_get_css', true);
$this->templatingInstance->addFilter('colour_get_css_contrast'); tpl_add_function('colour_get_css_contrast', true);
$this->templatingInstance->addFilter('colour_get_inherit'); tpl_add_function('colour_get_inherit', true);
$this->templatingInstance->addFilter('colour_get_red'); tpl_add_function('colour_get_red', true);
$this->templatingInstance->addFilter('colour_get_green'); tpl_add_function('colour_get_green', true);
$this->templatingInstance->addFilter('colour_get_blue'); tpl_add_function('colour_get_blue', true);
$this->templatingInstance->addFilter('parse_line'); tpl_add_function('parse_line', true);
$this->templatingInstance->addFilter('parse_text'); tpl_add_function('parse_text', true);
$this->templatingInstance->addFilter('asset_url'); tpl_add_function('asset_url', true);
$this->templatingInstance->addFilter('vsprintf'); tpl_add_function('vsprintf', true);
$this->templatingInstance->addFunction('git_commit_hash'); tpl_add_function('git_commit_hash');
$this->templatingInstance->addFunction('git_branch'); tpl_add_function('git_branch');
$this->templatingInstance->addFunction('csrf_token', 'tmp_csrf_token'); tpl_add_function('csrf_token', false, 'tmp_csrf_token');
$this->templatingInstance->addFunction('perms_check'); tpl_add_function('perms_check');
$this->templatingInstance->var('app', $this); tpl_var('app', $this);
}
/**
* Gets an instance of the templating engine.
* @return TemplateEngine
*/
public function getTemplating(): TemplateEngine
{
if (is_null($this->templatingInstance)) {
throw new UnexpectedValueException('Internal templating engine instance is null, did you run startDatabase yet?');
}
return $this->templatingInstance;
} }
public function startMailer(): void public function startMailer(): void

View file

@ -1,239 +0,0 @@
<?php
namespace Misuzu;
use Twig_Environment;
use Twig_Extensions_Extension_Date;
use Twig_Loader_Filesystem;
use Twig_SimpleFilter;
use Twig_SimpleFunction;
/**
* Wrapper for Twig.
* @package Misuzu
* @author flashwave <me@flash.moe>
*/
class TemplateEngine
{
/**
* Template file extension.
*/
private const FILE_EXTENSION = '.twig';
public const TWIG_DEFAULT = Twig_Loader_Filesystem::MAIN_NAMESPACE;
/**
* Instance of the Twig Environment.
* @var Twig_Environment
*/
private $twig;
/**
* Instance a Twig loader, probably only compatible with the Filesystem type.
* @var Twig_Loader_Filesystem
*/
private $loader;
/**
* Render arguments.
* @var array
*/
private $vars = [];
/**
* TemplateEngine constructor.
* @param null|string $cache
* @param bool $strict
* @param bool $autoReload
* @param bool $debug
*/
public function __construct(
?string $cache = null,
bool $strict = true,
bool $autoReload = false,
bool $debug = false
) {
$this->loader = new Twig_Loader_Filesystem;
$this->twig = new Twig_Environment($this->loader, [
'cache' => $cache ?? false,
'strict_variables' => $strict,
'auto_reload' => $autoReload,
'debug' => $debug,
]);
$this->twig->addExtension(new Twig_Extensions_Extension_Date);
}
/**
* Toggles debug mode on or off.
* @param bool $mode
*/
public function debug(bool $mode): void
{
if ($this->twig->isDebug() === $mode) {
return;
}
if ($mode) {
$this->twig->enableDebug();
return;
}
$this->twig->disableDebug();
}
/**
* Toggles cache auto reloading on or off.
* @param bool $mode
*/
public function autoReload(bool $mode): void
{
if ($this->twig->isAutoReload() === $mode) {
return;
}
if ($mode) {
$this->twig->enableAutoReload();
return;
}
$this->twig->disableAutoReload();
}
/**
* Sets the cache path and alternatively turns it off.
* @param string $path
*/
public function cache(?string $path): void
{
$this->twig->setCache($path ?? false);
}
/**
* Adds a template path, first one is regarded as the master.
* @param string $name
* @param string $path
*/
public function addPath(string $name, string $path): void
{
try {
if (count($this->loader->getPaths()) < 1) {
$this->loader->addPath($path);
}
$this->loader->addPath($path, $name);
} catch (\Twig_Error_Loader $e) {
}
}
/**
* Sets a render var.
* @param string $name
* @param mixed $value
*/
public function var(string $name, $value): void
{
$this->vars[$name] = $value;
}
/**
* Sets render vars.
* @param array $vars
*/
public function vars(array $vars): void
{
$this->vars = array_merge($this->vars, $vars);
}
/**
* Converts . to / and appends the file extension.
* @param string $path
* @return string
*/
private function fixPath(string $path): string
{
// if the .twig extension if already present just assume that the path is already correct
if (ends_with($path, self::FILE_EXTENSION)) {
return $path;
}
return str_replace('.', '/', $path) . self::FILE_EXTENSION;
}
/**
* Renders a template file.
* @param string $path
* @param array|null $vars
* @return string
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
*/
public function render(string $path, ?array $vars = null): string
{
if ($this->twig->isDebug()) {
$this->var('query_count', Database::queryCount());
}
$path = self::fixPath($path);
if ($vars !== null) {
$this->vars($vars);
}
if (!$this->exists($path, Twig_Loader_Filesystem::MAIN_NAMESPACE)) {
$namespace = $this->findNamespace($path);
if ($namespace !== null) {
$path = "@{$this->findNamespace($path)}/{$path}";
}
}
return $this->twig->render($path, $this->vars);
}
/**
* Adds a function.
* @param string $name
* @param Callable $callable
*/
public function addFunction(string $name, callable $callable = null): void
{
$this->twig->addFunction(new Twig_SimpleFunction($name, $callable === null ? $name : $callable));
}
/**
* Adds a filter.
* @param string $name
* @param Callable $callable
*/
public function addFilter(string $name, callable $callable = null): void
{
$this->twig->addFilter(new Twig_SimpleFilter($name, $callable === null ? $name : $callable));
}
/**
* Finds in which namespace a template exists.
* @param string $path
* @return string
*/
public function findNamespace(string $path): ?string
{
foreach ($this->loader->getNamespaces() as $namespace) {
if ($this->exists($path, $namespace)) {
return $namespace;
}
}
return null;
}
/**
* Checks if a template exists.
* @param string $path
* @param string $namespace
* @return bool
*/
public function exists(string $path, string $namespace): bool
{
return $this->loader->exists("@{$namespace}/" . self::fixPath($path));
}
}

26
src/Twig.php Normal file
View file

@ -0,0 +1,26 @@
<?php
namespace Misuzu;
use Twig_Environment;
use Twig_LoaderInterface;
use UnexpectedValueException;
final class Twig extends Twig_Environment
{
protected static $instance = null;
public static function instance(): Twig_Environment
{
return self::$instance;
}
public function __construct(Twig_LoaderInterface $loader, array $options = [])
{
if (self::$instance !== null) {
throw new UnexpectedValueException('Instance of Twig already present, use the static instance() function.');
}
parent::__construct($loader, $options);
self::$instance = $this;
}
}

80
src/tpl.php Normal file
View file

@ -0,0 +1,80 @@
<?php
use Misuzu\Database;
use Misuzu\Twig;
define('MSZ_TPL_FILE_EXT', '.twig');
define('MSZ_TPL_VARS_STORE', '_msz_tpl_vars');
function tpl_init(array $options = []): void
{
$options = array_merge([
'cache' => false,
'strict_variables' => true,
'auto_reload' => false,
'debug' => false,
], $options);
$GLOBALS[MSZ_TPL_VARS_STORE] = [];
$loader = new Twig_Loader_Filesystem;
$twig = new Twig($loader, $options);
$twig->addExtension(new Twig_Extensions_Extension_Date);
}
function tpl_var(string $key, $value): void
{
$GLOBALS[MSZ_TPL_VARS_STORE][$key] = $value;
}
function tpl_vars(array $vars): void
{
$GLOBALS[MSZ_TPL_VARS_STORE] = array_merge($GLOBALS[MSZ_TPL_VARS_STORE], $vars);
}
function tpl_add_path(string $path): void
{
Twig::instance()->getLoader()->addPath($path);
}
function tpl_sanitise_path(string $path): string
{
// if the .twig extension if already present just assume that the path is already correct
if (ends_with($path, MSZ_TPL_FILE_EXT)) {
return $path;
}
return str_replace('.', '/', $path) . MSZ_TPL_FILE_EXT;
}
function tpl_add_function(string $name, bool $isFilter = false, callable $callable = null): void
{
$twig = Twig::instance();
if ($isFilter) {
$twig->addFilter(new Twig_SimpleFilter($name, $callable === null ? $name : $callable));
} else {
$twig->addFunction(new Twig_SimpleFunction($name, $callable === null ? $name : $callable));
}
}
function tpl_exists(string $path): bool
{
return Twig::instance()->getLoader()->exists(tpl_sanitise_path($path));
}
function tpl_render(string $path, array $vars = []): string
{
$twig = Twig::instance();
if ($twig->isDebug()) {
tpl_var('query_count', Database::queryCount());
}
$path = tpl_sanitise_path($path);
if (count($vars)) {
tpl_vars($vars);
}
return $twig->render($path, $GLOBALS[MSZ_TPL_VARS_STORE]);
}

View file

@ -1,4 +1,4 @@
{% extends '@auth/master.twig' %} {% extends 'auth/master.twig' %}
{% block content %} {% block content %}
<div class="container"> <div class="container">

View file

@ -1,4 +1,4 @@
{% extends '@auth/master.twig' %} {% extends 'auth/master.twig' %}
{% block content %} {% block content %}
<div class="container logout"> <div class="container logout">

View file

@ -1,4 +1,4 @@
{% extends '@auth/master.twig' %} {% extends 'auth/master.twig' %}
{% block content %} {% block content %}
<div class="container logout"> <div class="container logout">

View file

@ -1,4 +1,4 @@
{% extends '@auth/master.twig' %} {% extends 'auth/master.twig' %}
{% block content %} {% block content %}
<div class="container"> <div class="container">

View file

@ -1,5 +1,5 @@
{% extends '@mio/changelog/master.twig' %} {% extends 'changelog/master.twig' %}
{% from '@mio/_layout/comments.twig' import comments_section %} {% from '_layout/comments.twig' import comments_section %}
{% set is_valid = change|length > 0 %} {% set is_valid = change|length > 0 %}
{% set title = 'Changelog » ' ~ (is_valid ? 'Change #' ~ change.change_id : 'Unknown Change') %} {% set title = 'Changelog » ' ~ (is_valid ? 'Change #' ~ change.change_id : 'Unknown Change') %}

View file

@ -1,7 +1,7 @@
{% extends '@mio/changelog/master.twig' %} {% extends 'changelog/master.twig' %}
{% from '@mio/macros.twig' import pagination %} {% from 'macros.twig' import pagination %}
{% from '@mio/changelog/macros.twig' import changelog_listing %} {% from 'changelog/macros.twig' import changelog_listing %}
{% from '@mio/_layout/comments.twig' import comments_section %} {% from '_layout/comments.twig' import comments_section %}
{% set is_valid = changes|length > 0 %} {% set is_valid = changes|length > 0 %}
{% set is_date = changelog_date|length > 0 %} {% set is_date = changelog_date|length > 0 %}

View file

@ -1,4 +1,4 @@
{% extends '@mio/master.twig' %} {% extends 'master.twig' %}
{% if manage_link is not defined %} {% if manage_link is not defined %}
{% set manage_link = '/manage/changelog.php' %} {% set manage_link = '/manage/changelog.php' %}

View file

@ -1,4 +1,4 @@
{% extends '@mio/errors/master.twig' %} {% extends 'errors/master.twig' %}
{% set error_code = 400 %} {% set error_code = 400 %}
{% set error_text = 'Bad Request' %} {% set error_text = 'Bad Request' %}

View file

@ -1,4 +1,4 @@
{% extends '@mio/errors/master.twig' %} {% extends 'errors/master.twig' %}
{% set error_code = 403 %} {% set error_code = 403 %}
{% set error_text = 'Access Denied!' %} {% set error_text = 'Access Denied!' %}

View file

@ -1,4 +1,4 @@
{% extends '@mio/errors/master.twig' %} {% extends 'errors/master.twig' %}
{% set error_code = 404 %} {% set error_code = 404 %}
{% set error_text = 'Not Found!' %} {% set error_text = 'Not Found!' %}

View file

@ -1,4 +1,4 @@
{% extends '@mio/master.twig' %} {% extends 'master.twig' %}
{% block content %} {% block content %}
<div class="container"> <div class="container">

View file

@ -1,6 +1,6 @@
{% extends '@mio/forum/master.twig' %} {% extends 'forum/master.twig' %}
{% from '@mio/macros.twig' import navigation, pagination %} {% from 'macros.twig' import navigation, pagination %}
{% from '@mio/forum/macros.twig' import forum_category_listing, forum_topic_listing, forum_category_buttons %} {% from 'forum/macros.twig' import forum_category_listing, forum_topic_listing, forum_category_buttons %}
{% set title = forum_info.forum_name %} {% set title = forum_info.forum_name %}
{% set canonical_url = '/forum/forum.php'|url_construct({ {% set canonical_url = '/forum/forum.php'|url_construct({

View file

@ -1,5 +1,5 @@
{% extends '@mio/forum/master.twig' %} {% extends 'forum/master.twig' %}
{% from '@mio/forum/macros.twig' import forum_category_listing %} {% from 'forum/macros.twig' import forum_category_listing %}
{% set title = 'Forum Listing' %} {% set title = 'Forum Listing' %}
{% set canonical_url = '/forum/' %} {% set canonical_url = '/forum/' %}

View file

@ -0,0 +1 @@
{% extends 'master.twig' %}

View file

@ -1,6 +1,6 @@
{% extends '@mio/forum/master.twig' %} {% extends 'forum/master.twig' %}
{% from '@mio/macros.twig' import navigation %} {% from 'macros.twig' import navigation %}
{% from '@mio/forum/macros.twig' import forum_posting_form %} {% from 'forum/macros.twig' import forum_posting_form %}
{% set title = 'Posting' %} {% set title = 'Posting' %}

View file

@ -1,7 +1,7 @@
{% extends '@mio/forum/master.twig' %} {% extends 'forum/master.twig' %}
{% from '@mio/macros.twig' import navigation, pagination %} {% from 'macros.twig' import navigation, pagination %}
{% {%
from '@mio/forum/macros.twig' from 'forum/macros.twig'
import import
forum_post_listing, forum_post_listing,
forum_topic_buttons, forum_topic_buttons,

View file

@ -1,6 +1,6 @@
{% extends '@mio/home/master.twig' %} {% extends 'home/master.twig' %}
{% from '@mio/news/macros.twig' import news_preview %} {% from 'news/macros.twig' import news_preview %}
{% from '@mio/changelog/macros.twig' import changelog_listing %} {% from 'changelog/macros.twig' import changelog_listing %}
{% set canonical_url = '/' %} {% set canonical_url = '/' %}

View file

@ -0,0 +1 @@
{% extends 'master.twig' %}

View file

@ -1,4 +1,4 @@
{% extends '@manage/changelog/master.twig' %} {% extends 'manage/changelog/master.twig' %}
{% block content %} {% block content %}
<div class="container"> <div class="container">

View file

@ -1,5 +1,5 @@
{% extends '@manage/changelog/master.twig' %} {% extends 'manage/changelog/master.twig' %}
{% from '@manage/macros.twig' import pagination %} {% from 'manage/macros.twig' import pagination %}
{% block content %} {% block content %}
<div class="container"> <div class="container">

View file

@ -1,4 +1,4 @@
{% extends '@manage/changelog/master.twig' %} {% extends 'manage/changelog/master.twig' %}
{% block content %} {% block content %}
<div class="container"> <div class="container">

View file

@ -1,5 +1,5 @@
{% extends '@manage/changelog/master.twig' %} {% extends 'manage/changelog/master.twig' %}
{% from '@manage/macros.twig' import pagination %} {% from 'manage/macros.twig' import pagination %}
{% block content %} {% block content %}
<div class="container"> <div class="container">

View file

@ -0,0 +1 @@
{% extends 'manage/master.twig' %}

View file

@ -1,4 +1,4 @@
{% extends '@manage/changelog/master.twig' %} {% extends 'manage/changelog/master.twig' %}
{% block content %} {% block content %}
<div class="container"> <div class="container">

View file

@ -1,5 +1,5 @@
{% extends '@manage/changelog/master.twig' %} {% extends 'manage/changelog/master.twig' %}
{% from '@manage/macros.twig' import pagination %} {% from 'manage/macros.twig' import pagination %}
{% block content %} {% block content %}
<div class="container"> <div class="container">

View file

@ -0,0 +1 @@
{% extends 'manage/master.twig' %}

View file

@ -1,4 +1,4 @@
{% extends '@manage/general/master.twig' %} {% extends 'manage/general/master.twig' %}
{% block content %} {% block content %}
<div class="container"> <div class="container">

View file

@ -1,5 +1,5 @@
{% extends '@manage/users/master.twig' %} {% extends 'manage/users/master.twig' %}
{% from '@manage/macros.twig' import pagination %} {% from 'manage/macros.twig' import pagination %}
{% block content %} {% block content %}
<div class="container listing user-listing"> <div class="container listing user-listing">

View file

@ -0,0 +1 @@
{% extends 'manage/master.twig' %}

View file

@ -1,5 +1,5 @@
{% extends '@manage/users/master.twig' %} {% extends 'manage/users/master.twig' %}
{% from '@manage/macros.twig' import pagination %} {% from 'manage/macros.twig' import pagination %}
{% block content %} {% block content %}
{% if can_manage_roles %} {% if can_manage_roles %}

View file

@ -1,5 +1,5 @@
{% extends '@manage/users/master.twig' %} {% extends 'manage/users/master.twig' %}
{% from '@manage/macros.twig' import permissions_table %} {% from 'manage/macros.twig' import permissions_table %}
{% block content %} {% block content %}
<form action="?v=role{{ edit_role is defined ? '&r=' ~ edit_role.role_id : '' }}" method="post"> <form action="?v=role{{ edit_role is defined ? '&r=' ~ edit_role.role_id : '' }}" method="post">

View file

@ -1,5 +1,5 @@
{% extends '@manage/users/master.twig' %} {% extends 'manage/users/master.twig' %}
{% from '@manage/macros.twig' import permissions_table %} {% from 'manage/macros.twig' import permissions_table %}
{% block content %} {% block content %}
{% if can_manage_users %} {% if can_manage_users %}

View file

@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
{% include '@mio/_layout/meta.twig' %} {% include '_layout/meta.twig' %}
<link href="{{ '/css/mio.css'|asset_url }}" rel="stylesheet"> <link href="{{ '/css/mio.css'|asset_url }}" rel="stylesheet">
<link href="{{ '/css/libraries.css'|asset_url }}" rel="stylesheet"> <link href="{{ '/css/libraries.css'|asset_url }}" rel="stylesheet">
</head> </head>

View file

@ -1,6 +1,6 @@
{% extends '@mio/news/master.twig' %} {% extends 'news/master.twig' %}
{% from '@mio/macros.twig' import pagination %} {% from 'macros.twig' import pagination %}
{% from '@mio/news/macros.twig' import news_preview %} {% from 'news/macros.twig' import news_preview %}
{% set title = category.category_name ~ ' :: News' %} {% set title = category.category_name ~ ' :: News' %}
{% set canonical_url = '/news.php'|url_construct({ {% set canonical_url = '/news.php'|url_construct({

View file

@ -1,6 +1,6 @@
{% extends '@mio/news/master.twig' %} {% extends 'news/master.twig' %}
{% from '@mio/macros.twig' import pagination %} {% from 'macros.twig' import pagination %}
{% from '@mio/news/macros.twig' import news_preview %} {% from 'news/macros.twig' import news_preview %}
{% set title = 'News' %} {% set title = 'News' %}
{% set canonical_url = '/news.php'|url_construct({'o':posts_offset}) %} {% set canonical_url = '/news.php'|url_construct({'o':posts_offset}) %}

View file

@ -0,0 +1 @@
{% extends 'master.twig' %}

View file

@ -1,5 +1,5 @@
{% extends '@mio/news/master.twig' %} {% extends 'news/master.twig' %}
{% from '@mio/_layout/comments.twig' import comments_section %} {% from '_layout/comments.twig' import comments_section %}
{% set title = post.post_title ~ ' :: News' %} {% set title = post.post_title ~ ' :: News' %}
{% set canonical_url = '/news.php?p=' ~ post.post_id %} {% set canonical_url = '/news.php?p=' ~ post.post_id %}

View file

@ -1,4 +1,4 @@
{% extends '@mio/settings/master.twig' %} {% extends 'settings/master.twig' %}
{% block settings_content %} {% block settings_content %}
<div class="container"> <div class="container">

View file

@ -1,5 +1,5 @@
{% extends '@mio/settings/master.twig' %} {% extends 'settings/master.twig' %}
{% from '@mio/macros.twig' import pagination %} {% from 'macros.twig' import pagination %}
{% set alpagination = pagination( {% set alpagination = pagination(
audit_log_count, audit_log_count,

View file

@ -1,5 +1,5 @@
{% extends '@mio/master.twig' %} {% extends 'master.twig' %}
{% from '@mio/macros.twig' import navigation %} {% from 'macros.twig' import navigation %}
{% set title = 'Settings » ' ~ settings_title %} {% set title = 'Settings » ' ~ settings_title %}

View file

@ -1,4 +1,4 @@
{% extends '@mio/settings/master.twig' %} {% extends 'settings/master.twig' %}
{% block settings_content %} {% block settings_content %}
<p>Could not find what you were looking for.</p> <p>Could not find what you were looking for.</p>

View file

@ -1,5 +1,5 @@
{% extends '@mio/settings/master.twig' %} {% extends 'settings/master.twig' %}
{% from '@mio/macros.twig' import pagination %} {% from 'macros.twig' import pagination %}
{% set spagination = pagination(sessions_count, sessions_take, sessions_offset, '?m=sessions', 'settings__') %} {% set spagination = pagination(sessions_count, sessions_take, sessions_offset, '?m=sessions', 'settings__') %}

View file

@ -1,5 +1,5 @@
{% extends '@mio/user/master.twig' %} {% extends 'user/master.twig' %}
{% from '@mio/macros.twig' import pagination %} {% from 'macros.twig' import pagination %}
{% set canonical_url = '/members.php'|url_construct({ {% set canonical_url = '/members.php'|url_construct({
'r': role.role_id != 1 ? role.role_id : 0, 'r': role.role_id != 1 ? role.role_id : 0,

View file

@ -0,0 +1 @@
{% extends 'master.twig' %}

View file

@ -1,4 +1,4 @@
{% extends '@mio/user/master.twig' %} {% extends 'user/master.twig' %}
{% set title = 'User not found!' %} {% set title = 'User not found!' %}

View file

@ -1,5 +1,5 @@
{% extends '@mio/user/master.twig' %} {% extends 'user/master.twig' %}
{% from '@mio/macros.twig' import navigation %} {% from 'macros.twig' import navigation %}
{% set image = '/profile.php?u=' ~ profile.user_id ~ '&m=avatar' %} {% set image = '/profile.php?u=' ~ profile.user_id ~ '&m=avatar' %}
{% set canonical_url = '/profile.php?u=' ~ profile.user_id %} {% set canonical_url = '/profile.php?u=' ~ profile.user_id %}

View file

@ -283,21 +283,19 @@ function render_info(?string $message, int $httpCode, string $template = 'errors
http_response_code($httpCode); http_response_code($httpCode);
try { try {
$tpl = \Misuzu\Application::getInstance()->getTemplating(); tpl_var('http_code', $httpCode);
$tpl->var('http_code', $httpCode);
if (strlen($message)) { if (strlen($message)) {
$tpl->var('message', $message); tpl_var('message', $message);
} }
$template = sprintf($template, $httpCode); $template = sprintf($template, $httpCode);
if (!$tpl->exists($template, \Misuzu\TemplateEngine::TWIG_DEFAULT)) { if (!tpl_exists($template)) {
$template = 'errors.master'; $template = 'errors.master';
} }
return $tpl->render(sprintf($template, $httpCode)); return tpl_render(sprintf($template, $httpCode));
} catch (Exception $ex) { } catch (Exception $ex) {
echo $ex->getMessage(); echo $ex->getMessage();
return $message ?? ''; return $message ?? '';

View file

@ -1 +0,0 @@
{% extends '@manage/master.twig' %}

View file

@ -1 +0,0 @@
{% extends '@manage/master.twig' %}

View file

@ -1 +0,0 @@
{% extends '@manage/master.twig' %}

View file

@ -1 +0,0 @@
{% extends '@mio/master.twig' %}

View file

@ -1 +0,0 @@
{% extends '@mio/master.twig' %}

View file

@ -1 +0,0 @@
{% extends '@mio/master.twig' %}

View file

@ -1 +0,0 @@
{% extends '@mio/master.twig' %}