From f1979c8e4a92b205df1a20329af62ae321a3dc3d Mon Sep 17 00:00:00 2001 From: flashwave Date: Wed, 15 Aug 2018 03:12:58 +0200 Subject: [PATCH] Restructure templating system. --- misuzu.php | 17 +- public/auth.php | 32 ++- public/changelog.php | 12 +- public/forum/forum.php | 3 +- public/forum/index.php | 2 +- public/forum/posting.php | 6 +- public/forum/topic.php | 4 +- public/index.php | 5 +- public/manage/changelog.php | 25 +- public/manage/index.php | 3 +- public/manage/users.php | 25 +- public/members.php | 4 +- public/news.php | 12 +- public/profile.php | 8 +- public/settings.php | 22 +- src/Application.php | 66 ++--- src/TemplateEngine.php | 239 ------------------ src/Twig.php | 26 ++ src/tpl.php | 80 ++++++ .../mio => templates}/_layout/comments.twig | 0 {views/mio => templates}/_layout/header.twig | 0 {views/mio => templates}/_layout/meta.twig | 0 {views => templates}/auth/auth.twig | 2 +- {views => templates}/auth/lockdown.twig | 2 +- {views => templates}/auth/logout.twig | 2 +- {views => templates}/auth/master.twig | 0 {views => templates}/auth/password.twig | 2 +- .../mio => templates}/changelog/change.twig | 4 +- {views/mio => templates}/changelog/index.twig | 8 +- .../mio => templates}/changelog/macros.twig | 0 .../mio => templates}/changelog/master.twig | 2 +- {views/mio => templates}/errors/400.twig | 2 +- {views/mio => templates}/errors/403.twig | 2 +- {views/mio => templates}/errors/404.twig | 2 +- {views/mio => templates}/errors/master.twig | 2 +- {views/mio => templates}/forum/forum.twig | 6 +- {views/mio => templates}/forum/index.twig | 4 +- {views/mio => templates}/forum/macros.twig | 0 templates/forum/master.twig | 1 + {views/mio => templates}/forum/posting.twig | 6 +- {views/mio => templates}/forum/topic.twig | 6 +- {views/mio => templates}/home/index.twig | 6 +- templates/home/master.twig | 1 + {views/mio => templates}/macros.twig | 0 .../manage/changelog/action_edit.twig | 2 +- .../manage/changelog/actions.twig | 4 +- .../manage/changelog/change_edit.twig | 2 +- .../manage/changelog/changes.twig | 4 +- templates/manage/changelog/master.twig | 1 + .../manage/changelog/tag_edit.twig | 2 +- .../manage/changelog/tags.twig | 4 +- templates/manage/general/master.twig | 1 + .../manage/general/overview.twig | 2 +- {views => templates}/manage/macros.twig | 0 {views => templates}/manage/master.twig | 0 .../manage/users/listing.twig | 4 +- templates/manage/users/master.twig | 1 + {views => templates}/manage/users/roles.twig | 4 +- .../manage/users/roles_create.twig | 4 +- {views => templates}/manage/users/view.twig | 4 +- {views/mio => templates}/master.twig | 2 +- {views/mio => templates}/news/category.twig | 6 +- {views/mio => templates}/news/index.twig | 6 +- {views/mio => templates}/news/macros.twig | 0 templates/news/master.twig | 1 + {views/mio => templates}/news/post.twig | 4 +- .../mio => templates}/settings/account.twig | 2 +- {views/mio => templates}/settings/logs.twig | 4 +- {views/mio => templates}/settings/master.twig | 4 +- .../mio => templates}/settings/notfound.twig | 2 +- .../mio => templates}/settings/sessions.twig | 4 +- {views/mio => templates}/user/listing.twig | 4 +- templates/user/master.twig | 1 + {views/mio => templates}/user/notfound.twig | 2 +- {views/mio => templates}/user/view.twig | 4 +- utility.php | 10 +- views/manage/changelog/master.twig | 1 - views/manage/general/master.twig | 1 - views/manage/users/master.twig | 1 - views/mio/forum/master.twig | 1 - views/mio/home/master.twig | 1 - views/mio/news/master.twig | 1 - views/mio/user/master.twig | 1 - 83 files changed, 290 insertions(+), 463 deletions(-) delete mode 100644 src/TemplateEngine.php create mode 100644 src/Twig.php create mode 100644 src/tpl.php rename {views/mio => templates}/_layout/comments.twig (100%) rename {views/mio => templates}/_layout/header.twig (100%) rename {views/mio => templates}/_layout/meta.twig (100%) rename {views => templates}/auth/auth.twig (99%) rename {views => templates}/auth/lockdown.twig (87%) rename {views => templates}/auth/logout.twig (94%) rename {views => templates}/auth/master.twig (100%) rename {views => templates}/auth/password.twig (98%) rename {views/mio => templates}/changelog/change.twig (97%) rename {views/mio => templates}/changelog/index.twig (86%) rename {views/mio => templates}/changelog/macros.twig (100%) rename {views/mio => templates}/changelog/master.twig (75%) rename {views/mio => templates}/errors/400.twig (80%) rename {views/mio => templates}/errors/403.twig (82%) rename {views/mio => templates}/errors/404.twig (84%) rename {views/mio => templates}/errors/master.twig (96%) rename {views/mio => templates}/forum/forum.twig (82%) rename {views/mio => templates}/forum/index.twig (91%) rename {views/mio => templates}/forum/macros.twig (100%) create mode 100644 templates/forum/master.twig rename {views/mio => templates}/forum/posting.twig (78%) rename {views/mio => templates}/forum/topic.twig (91%) rename {views/mio => templates}/home/index.twig (94%) create mode 100644 templates/home/master.twig rename {views/mio => templates}/macros.twig (100%) rename {views => templates}/manage/changelog/action_edit.twig (98%) rename {views => templates}/manage/changelog/actions.twig (90%) rename {views => templates}/manage/changelog/change_edit.twig (99%) rename {views => templates}/manage/changelog/changes.twig (96%) create mode 100644 templates/manage/changelog/master.twig rename {views => templates}/manage/changelog/tag_edit.twig (98%) rename {views => templates}/manage/changelog/tags.twig (90%) create mode 100644 templates/manage/general/master.twig rename {views => templates}/manage/general/overview.twig (75%) rename {views => templates}/manage/macros.twig (100%) rename {views => templates}/manage/master.twig (100%) rename {views => templates}/manage/users/listing.twig (91%) create mode 100644 templates/manage/users/master.twig rename {views => templates}/manage/users/roles.twig (90%) rename {views => templates}/manage/users/roles_create.twig (97%) rename {views => templates}/manage/users/view.twig (98%) rename {views/mio => templates}/master.twig (98%) rename {views/mio => templates}/news/category.twig (92%) rename {views/mio => templates}/news/index.twig (91%) rename {views/mio => templates}/news/macros.twig (100%) create mode 100644 templates/news/master.twig rename {views/mio => templates}/news/post.twig (96%) rename {views/mio => templates}/settings/account.twig (99%) rename {views/mio => templates}/settings/logs.twig (98%) rename {views/mio => templates}/settings/master.twig (92%) rename {views/mio => templates}/settings/notfound.twig (70%) rename {views/mio => templates}/settings/sessions.twig (97%) rename {views/mio => templates}/user/listing.twig (98%) create mode 100644 templates/user/master.twig rename {views/mio => templates}/user/notfound.twig (87%) rename {views/mio => templates}/user/view.twig (99%) delete mode 100644 views/manage/changelog/master.twig delete mode 100644 views/manage/general/master.twig delete mode 100644 views/manage/users/master.twig delete mode 100644 views/mio/forum/master.twig delete mode 100644 views/mio/home/master.twig delete mode 100644 views/mio/news/master.twig delete mode 100644 views/mio/user/master.twig diff --git a/misuzu.php b/misuzu.php index 9b9fa0db..dad3620b 100644 --- a/misuzu.php +++ b/misuzu.php @@ -13,6 +13,7 @@ require_once __DIR__ . '/src/git.php'; require_once __DIR__ . '/src/manage.php'; require_once __DIR__ . '/src/news.php'; require_once __DIR__ . '/src/perms.php'; +require_once __DIR__ . '/src/tpl.php'; require_once __DIR__ . '/src/zalgo.php'; require_once __DIR__ . '/src/Forum/forum.php'; require_once __DIR__ . '/src/Forum/post.php'; @@ -204,17 +205,15 @@ MIG; $app->startCache(); $app->startTemplating(); - $tpl = $app->getTemplating(); + + tpl_add_path(__DIR__ . '/templates'); if ($app->getConfig()->get('Auth', 'lockdown', 'bool', false)) { http_response_code(503); - $tpl->addPath('auth', __DIR__ . '/views/auth'); - echo $tpl->render('lockdown'); + echo tpl_render('auth/lockdown'); exit; } - $tpl->addPath('mio', __DIR__ . '/views/mio'); - if (isset($_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()); $userDisplayInfo = $getUserDisplayInfo->execute() ? $getUserDisplayInfo->fetch() : []; - $tpl->var('current_user', $userDisplayInfo); + tpl_var('current_user', $userDisplayInfo); } } $inManageMode = starts_with($_SERVER['REQUEST_URI'], '/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 (!$hasManageAccess) { @@ -254,8 +253,6 @@ MIG; exit; } - $tpl = $app->getTemplating(); - $tpl->var('manage_menu', manage_get_menu($app->getUserId())); - $tpl->addPath('manage', __DIR__ . '/views/manage'); + tpl_var('manage_menu', manage_get_menu($app->getUserId())); } } diff --git a/public/auth.php b/public/auth.php index ef22511a..3dd675c0 100644 --- a/public/auth.php +++ b/public/auth.php @@ -8,7 +8,6 @@ use Misuzu\Users\Session; require_once __DIR__ . '/../misuzu.php'; $config = $app->getConfig(); -$tpl = $app->getTemplating(); $usernameValidationErrors = [ 'trim' => 'Your username may not start or end with spaces!', @@ -22,9 +21,8 @@ $usernameValidationErrors = [ $authMode = $_GET['m'] ?? 'login'; $preventRegistration = $config->get('Auth', 'prevent_registration', 'bool', false); -$tpl->addPath('auth', __DIR__ . '/../views/auth'); -$tpl->vars([ +tpl_vars([ 'prevent_registration' => $preventRegistration, 'auth_mode' => $authMode, 'auth_username' => $_REQUEST['username'] ?? '', @@ -46,7 +44,7 @@ switch ($authMode) { return; } - echo $tpl->render('@auth.logout'); + echo tpl_render('auth.logout'); break; case 'reset': @@ -69,7 +67,7 @@ switch ($authMode) { 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') { $validateRequest = Database::prepare(' @@ -87,21 +85,21 @@ switch ($authMode) { : false; if (!$validateRequest) { - $tpl->var('auth_reset_error', 'Invalid verification code!'); + tpl_var('auth_reset_error', 'Invalid verification code!'); break; } - $tpl->var('reset_verify', $_POST['verification']); + tpl_var('reset_verify', $_POST['verification']); if (empty($_POST['password']['new']) || empty($_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; } 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; } @@ -136,7 +134,7 @@ switch ($authMode) { break; } - echo $tpl->render('@auth.password', [ + echo tpl_render('auth.password', [ 'reset_user' => $resetUser, ]); break; @@ -149,7 +147,7 @@ switch ($authMode) { while ($_SERVER['REQUEST_METHOD'] === 'POST') { 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; } @@ -221,7 +219,7 @@ MSG; break; } - echo $tpl->render('@auth.auth'); + echo tpl_render('auth.auth'); break; case 'login': @@ -298,10 +296,10 @@ MSG; } 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; case 'register': @@ -359,14 +357,14 @@ MSG; 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; } 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; } diff --git a/public/changelog.php b/public/changelog.php index d73c5549..2f75162c 100644 --- a/public/changelog.php +++ b/public/changelog.php @@ -3,8 +3,6 @@ use Misuzu\Database; require_once __DIR__ . '/../misuzu.php'; -$tpl = $app->getTemplating(); - $changelogOffset = max((int)($_GET['o'] ?? 0), 0); $changelogRange = 30; @@ -15,7 +13,7 @@ $changelogTags = $_GET['t'] ?? ''; $commentPerms = comments_get_perms($app->getUserId()); -$tpl->vars([ +tpl_vars([ 'changelog_offset' => $changelogOffset, 'changelog_take' => $changelogRange, 'comments_perms' => $commentPerms, @@ -55,10 +53,10 @@ if ($changelogChange > 0) { '); $getTags->bindValue('change_id', $change['change_id']); $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, 'comments_category' => $commentsCategory = comments_category_info( "changelog-date-{$change['change_date']}", @@ -88,13 +86,13 @@ if (!$changes) { } if (!empty($changelogDate)) { - $tpl->vars([ + tpl_vars([ 'comments_category' => $commentsCategory = comments_category_info("changelog-date-{$changelogDate}", true), 'comments' => comments_category_get($commentsCategory['category_id'], $app->getUserId()), ]); } -echo $tpl->render('changelog.index', [ +echo tpl_render('changelog.index', [ 'changes' => $changes, 'changelog_count' => $changesCount, 'changelog_date' => $changelogDate, diff --git a/public/forum/forum.php b/public/forum/forum.php index c3b7abaf..df19c3dd 100644 --- a/public/forum/forum.php +++ b/public/forum/forum.php @@ -10,7 +10,6 @@ if ($forumId === 0) { exit; } -$templating = $app->getTemplating(); $forum = forum_fetch($forumId); 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); } -echo $app->getTemplating()->render('forum.forum', [ +echo tpl_render('forum.forum', [ 'forum_breadcrumbs' => forum_get_breadcrumbs($forum['forum_id']), 'forum_info' => $forum, 'forum_topics' => $topics, diff --git a/public/forum/index.php b/public/forum/index.php index 0e2d6d98..299763b3 100644 --- a/public/forum/index.php +++ b/public/forum/index.php @@ -17,7 +17,7 @@ foreach ($categories as $key => $category) { } } -echo $app->getTemplating()->render('forum.index', [ +echo tpl_render('forum.index', [ 'forum_categories' => $categories, 'forum_empty' => $blankForum, ]); diff --git a/public/forum/posting.php b/public/forum/posting.php index 89906911..b6194163 100644 --- a/public/forum/posting.php +++ b/public/forum/posting.php @@ -4,8 +4,6 @@ use Misuzu\Net\IPAddress; require_once __DIR__ . '/../../misuzu.php'; -$templating = $app->getTemplating(); - if (!$app->hasActiveSession()) { echo render_error(403); return; @@ -132,10 +130,10 @@ if ($postRequest) { } 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_forum' => $forum, ]); diff --git a/public/forum/topic.php b/public/forum/topic.php index 66c079f9..943f090a 100644 --- a/public/forum/topic.php +++ b/public/forum/topic.php @@ -1,8 +1,6 @@ getTemplating(); - $postId = (int)($_GET['p'] ?? 0); $topicId = (int)($_GET['t'] ?? 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']); -echo $templating->render('forum.topic', [ +echo tpl_render('forum.topic', [ 'topic_breadcrumbs' => forum_get_breadcrumbs($topic['forum_id']), 'topic_info' => $topic, 'topic_posts' => $posts, diff --git a/public/index.php b/public/index.php index 8812eb89..3b11a01d 100644 --- a/public/index.php +++ b/public/index.php @@ -6,10 +6,9 @@ use Misuzu\Database; require_once __DIR__ . '/../misuzu.php'; $config = $app->getConfig(); -$tpl = $app->getTemplating(); if ($config->get('Site', 'embed_linked_data', 'bool', false)) { - $tpl->vars([ + tpl_vars([ 'embed_linked_data' => true, 'embed_name' => $config->get('Site', 'name'), 'embed_url' => $config->get('Site', 'url'), @@ -72,7 +71,7 @@ $changelog = Cache::instance()->get('index:changelog:v1', function () { ')->fetchAll(PDO::FETCH_ASSOC); }, 1800); -echo $tpl->render('home.index', [ +echo tpl_render('home.index', [ 'users_count' => $statistics['users'], 'last_user' => $statistics['lastUser'], 'featured_changelog' => $changelog, diff --git a/public/manage/changelog.php b/public/manage/changelog.php index da589956..21f1caa4 100644 --- a/public/manage/changelog.php +++ b/public/manage/changelog.php @@ -3,10 +3,7 @@ use Misuzu\Database; require_once __DIR__ . '/../../misuzu.php'; -$tpl = $app->getTemplating(); - $changelogPerms = perms_get_user(MSZ_PERMS_CHANGELOG, $app->getUserId()); - $queryOffset = (int)($_GET['o'] ?? 0); switch ($_GET['v'] ?? null) { @@ -58,7 +55,7 @@ switch ($_GET['v'] ?? null) { $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_count' => $changesCount, 'changelog_offset' => $queryOffset, @@ -157,7 +154,7 @@ switch ($_GET['v'] ?? null) { SELECT `action_id`, `action_name` FROM `msz_changelog_actions` ')->fetchAll(PDO::FETCH_ASSOC); - $tpl->var('changelog_actions', $actions); + tpl_var('changelog_actions', $actions); if ($changeId > 0) { $getChange = Database::prepare(' @@ -171,7 +168,7 @@ switch ($_GET['v'] ?? null) { $change = $getChange->execute() ? $getChange->fetch(PDO::FETCH_ASSOC) : []; if ($change) { - $tpl->var('edit_change', $change); + tpl_var('edit_change', $change); $assignedTags = Database::prepare(' SELECT `tag_id`, `tag_name` @@ -198,7 +195,7 @@ switch ($_GET['v'] ?? null) { $availableTags->bindValue('change_id', $change['change_id']); $availableTags = $availableTags->execute() ? $availableTags->fetchAll(PDO::FETCH_ASSOC) : []; - $tpl->vars([ + tpl_vars([ 'edit_change_assigned_tags' => $assignedTags, '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; case 'tags': @@ -240,7 +237,7 @@ switch ($_GET['v'] ?? null) { $getTags->bindValue('offset', $queryOffset); $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_count' => $tagsCount, 'changelog_take' => $tagsTake, @@ -303,14 +300,14 @@ switch ($_GET['v'] ?? null) { $tag = $getTag->execute() ? $getTag->fetch(PDO::FETCH_ASSOC) : []; if ($tag) { - $tpl->var('edit_tag', $tag); + tpl_var('edit_tag', $tag); } else { header('Location: ?v=tags'); return; } } - echo $tpl->render('@manage.changelog.tag_edit'); + echo tpl_render('manage.changelog.tag_edit'); break; case 'actions': @@ -342,7 +339,7 @@ switch ($_GET['v'] ?? null) { $getActions->bindValue('offset', $queryOffset); $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_count' => $actionTake, 'changelog_take' => $actionTake, @@ -414,13 +411,13 @@ switch ($_GET['v'] ?? null) { $action = $getAction->execute() ? $getAction->fetch(PDO::FETCH_ASSOC) : []; if ($action) { - $tpl->var('edit_action', $action); + tpl_var('edit_action', $action); } else { header('Location: ?v=actions'); return; } } - echo $tpl->render('@manage.changelog.action_edit'); + echo tpl_render('manage.changelog.action_edit'); break; } diff --git a/public/manage/index.php b/public/manage/index.php index 61d71f46..d7ba64b7 100644 --- a/public/manage/index.php +++ b/public/manage/index.php @@ -2,12 +2,11 @@ require_once __DIR__ . '/../../misuzu.php'; $generalPerms = perms_get_user(MSZ_PERMS_GENERAL, $app->getUserId()); -$tpl = $app->getTemplating(); switch ($_GET['v'] ?? null) { default: case 'overview': - echo $tpl->render('@manage.general.overview'); + echo tpl_render('manage.general.overview'); break; case 'logs': diff --git a/public/manage/users.php b/public/manage/users.php index 94664842..90408b00 100644 --- a/public/manage/users.php +++ b/public/manage/users.php @@ -3,14 +3,11 @@ use Misuzu\Database; require_once __DIR__ . '/../../misuzu.php'; -$tpl = $app->getTemplating(); - $userPerms = perms_get_user(MSZ_PERMS_USER, $app->getUserId()); - $isPostRequest = $_SERVER['REQUEST_METHOD'] === 'POST'; $queryQffset = (int)($_GET['o'] ?? 0); -$tpl->vars([ +tpl_vars([ '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_perms' => $canManagePerms = perms_check($userPerms, MSZ_USER_PERM_MANAGE_PERMS), @@ -44,13 +41,13 @@ switch ($_GET['v'] ?? null) { $getManageUsers->bindValue('take', $usersTake); $manageUsers = $getManageUsers->execute() ? $getManageUsers->fetchAll() : []; - $tpl->vars([ + tpl_vars([ 'manage_users' => $manageUsers, 'manage_users_count' => $manageUsersCount, 'manage_users_range' => $usersTake, 'manage_users_offset' => $queryQffset, ]); - echo $tpl->render('@manage.users.listing'); + echo tpl_render('manage.users.listing'); break; case 'view': @@ -111,7 +108,7 @@ switch ($_GET['v'] ?? null) { $availableRoles = $getAvailableRoles->execute() ? $getAvailableRoles->fetchAll() : []; 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) { @@ -251,13 +248,13 @@ switch ($_GET['v'] ?? null) { break; } - $tpl->vars([ + tpl_vars([ 'available_roles' => $availableRoles, 'has_roles' => $hasRoles, 'view_user' => $manageUser, 'profile_fields' => user_profile_fields_get(), ]); - echo $tpl->render('@manage.users.view'); + echo tpl_render('manage.users.view'); break; case 'roles': @@ -287,13 +284,13 @@ switch ($_GET['v'] ?? null) { $getManageRoles->bindValue('take', $rolesTake); $manageRoles = $getManageRoles->execute() ? $getManageRoles->fetchAll() : []; - $tpl->vars([ + tpl_vars([ 'manage_roles' => $manageRoles, 'manage_roles_count' => $manageRolesCount, 'manage_roles_range' => $rolesTake, 'manage_roles_offset' => $queryQffset, ]); - echo $tpl->render('@manage.users.roles'); + echo tpl_render('manage.users.roles'); break; case 'role': @@ -305,7 +302,7 @@ switch ($_GET['v'] ?? null) { $roleId = $_GET['r'] ?? null; 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) { @@ -470,9 +467,9 @@ switch ($_GET['v'] ?? null) { 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; } diff --git a/public/members.php b/public/members.php index 5a2496c7..02bb888e 100644 --- a/public/members.php +++ b/public/members.php @@ -58,8 +58,6 @@ if (empty($orderDir)) { return; } -$tpl = $app->getTemplating(); - $getRole = Database::prepare(' SELECT `role_id`, `role_name`, `role_colour`, `role_description`, `created_at`, @@ -118,7 +116,7 @@ $getUsers->bindValue('offset', $usersOffset); $getUsers->bindValue('take', $usersTake); $users = $getUsers->execute() ? $getUsers->fetchAll(PDO::FETCH_ASSOC) : []; -echo $tpl->render('user.listing', [ +echo tpl_render('user.listing', [ 'roles' => $roles, 'role' => $role, 'users' => $users, diff --git a/public/news.php b/public/news.php index ee0ccb62..01feb2b0 100644 --- a/public/news.php +++ b/public/news.php @@ -3,14 +3,12 @@ use Misuzu\Database; require_once __DIR__ . '/../misuzu.php'; -$templating = $app->getTemplating(); - $categoryId = isset($_GET['c']) ? (int)$_GET['c'] : null; $postId = isset($_GET['p']) ? (int)$_GET['p'] : (isset($_GET['n']) ? (int)$_GET['n'] : null); $postsOffset = (int)($_GET['o'] ?? 0); $postsTake = 5; -$templating->vars([ +tpl_vars([ 'posts_offset' => $postsOffset, 'posts_take' => $postsTake, ]); @@ -57,7 +55,7 @@ if ($postId !== null) { $commentsInfo = comments_category_info($post['comment_section_id']); } - echo $templating->render('news.post', [ + echo tpl_render('news.post', [ 'post' => $post, 'comments_perms' => comments_get_perms($app->getUserId()), 'comments_category' => $commentsInfo, @@ -123,7 +121,7 @@ if ($categoryId !== null) { $getFeatured->bindValue('category_id', $category['category_id'], PDO::PARAM_INT); $featured = $getFeatured->execute() ? $getFeatured->fetchAll() : []; - echo $templating->render('news.category', compact('category', 'posts', 'featured')); + echo tpl_render('news.category', compact('category', 'posts', 'featured')); return; } @@ -149,7 +147,7 @@ $postsCount = (int)Database::query(' AND c.`is_hidden` = false ')->fetchColumn(); -$templating->var('posts_count', $postsCount); +tpl_var('posts_count', $postsCount); if ($postsOffset < 0 || $postsOffset >= $postsCount) { echo render_error(404); @@ -188,4 +186,4 @@ if (!$posts) { return; } -echo $templating->render('news.index', compact('categories', 'posts')); +echo tpl_render('news.index', compact('categories', 'posts')); diff --git a/public/profile.php b/public/profile.php index 50dd5fda..950aeb1e 100644 --- a/public/profile.php +++ b/public/profile.php @@ -40,8 +40,6 @@ switch ($mode) { case 'view': default: - $templating = $app->getTemplating(); - $getProfile = Database::prepare(' SELECT u.*, @@ -77,11 +75,11 @@ switch ($mode) { if (!$profile) { http_response_code(404); - echo $templating->render('user.notfound'); + echo tpl_render('user.notfound'); break; } - $templating->vars(compact('profile')); - echo $templating->render('user.view'); + tpl_vars(compact('profile')); + echo tpl_render('user.view'); break; } diff --git a/public/settings.php b/public/settings.php index 7af984dd..f3bba381 100644 --- a/public/settings.php +++ b/public/settings.php @@ -4,8 +4,6 @@ use Misuzu\IO\File; require_once __DIR__ . '/../misuzu.php'; -$tpl = $app->getTemplating(); - $queryOffset = (int)($_GET['o'] ?? 0); $queryTake = 15; @@ -53,7 +51,7 @@ $avatarErrorStrings = [ ], ]; -$tpl->vars([ +tpl_vars([ 'settings_perms' => $perms, 'settings_mode' => $settingsMode, 'settings_modes' => $settingsModes, @@ -61,8 +59,8 @@ $tpl->vars([ if (!array_key_exists($settingsMode, $settingsModes)) { http_response_code(404); - $tpl->var('settings_title', 'Not Found'); - echo $tpl->render('settings.notfound'); + tpl_var('settings_title', 'Not Found'); + echo tpl_render('settings.notfound'); return; } @@ -269,8 +267,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } } -$tpl->var('settings_title', $settingsModes[$settingsMode]); -$tpl->var('settings_errors', $settingsErrors); +tpl_vars([ + 'settings_title' => $settingsModes[$settingsMode], + 'settings_errors' => $settingsErrors, +]); switch ($settingsMode) { case 'account': @@ -292,7 +292,7 @@ switch ($settingsMode) { $currentEmail = $getMail->execute() ? $getMail->fetchColumn() : 'Failed to fetch e-mail address.'; $userHasAvatar = File::exists($app->getStore('avatars/original')->filename($avatarFileName)); - $tpl->vars([ + tpl_vars([ 'avatar_user_id' => $app->getUserId(), 'avatar_max_width' => $avatarWidthMax, 'avatar_max_height' => $avatarHeightMax, @@ -328,7 +328,7 @@ switch ($settingsMode) { $getSessions->bindValue('user_id', $app->getUserId()); $sessions = $getSessions->execute() ? $getSessions->fetchAll() : []; - $tpl->vars([ + tpl_vars([ 'active_session_id' => $app->getSessionId(), 'user_sessions' => $sessions, 'sessions_offset' => $queryOffset, @@ -370,7 +370,7 @@ switch ($settingsMode) { $app->getUserId() ); - $tpl->vars([ + tpl_vars([ 'audit_logs' => $auditLog, 'audit_log_count' => $auditLogCount, 'audit_log_take' => $queryTake, @@ -397,4 +397,4 @@ switch ($settingsMode) { break; } -echo $tpl->render("settings.{$settingsMode}"); +echo tpl_render("settings.{$settingsMode}"); diff --git a/src/Application.php b/src/Application.php index ea20ac45..55a5de45 100644 --- a/src/Application.php +++ b/src/Application.php @@ -270,54 +270,42 @@ class Application extends ApplicationBase throw new UnexpectedValueException('Templating module has already been started.'); } - $this->templatingInstance = new TemplateEngine; - $this->templatingInstance->debug($this->debugMode); + tpl_init([ + 'debug' => $this->debugMode, + ]); - $this->templatingInstance->var('globals', [ + tpl_var('globals', [ 'site_name' => $this->configInstance->get('Site', 'name', 'string', 'Flashii'), 'site_description' => $this->configInstance->get('Site', 'description'), 'site_twitter' => $this->configInstance->get('Site', 'twitter'), 'site_url' => $this->configInstance->get('Site', 'url'), ]); - $this->templatingInstance->addFilter('json_decode'); - $this->templatingInstance->addFilter('byte_symbol'); - $this->templatingInstance->addFilter('html_link'); - $this->templatingInstance->addFilter('html_colour'); - $this->templatingInstance->addFilter('url_construct'); - $this->templatingInstance->addFilter('country_name', 'get_country_name'); - $this->templatingInstance->addFilter('flip', 'array_flip'); - $this->templatingInstance->addFilter('first_paragraph'); - $this->templatingInstance->addFilter('colour_get_css'); - $this->templatingInstance->addFilter('colour_get_css_contrast'); - $this->templatingInstance->addFilter('colour_get_inherit'); - $this->templatingInstance->addFilter('colour_get_red'); - $this->templatingInstance->addFilter('colour_get_green'); - $this->templatingInstance->addFilter('colour_get_blue'); - $this->templatingInstance->addFilter('parse_line'); - $this->templatingInstance->addFilter('parse_text'); - $this->templatingInstance->addFilter('asset_url'); - $this->templatingInstance->addFilter('vsprintf'); + tpl_add_function('json_decode', true); + tpl_add_function('byte_symbol', true); + tpl_add_function('html_link', true); + tpl_add_function('html_colour', true); + tpl_add_function('url_construct', true); + tpl_add_function('country_name', true, 'get_country_name'); + tpl_add_function('flip', true, 'array_flip'); + tpl_add_function('first_paragraph', true); + tpl_add_function('colour_get_css', true); + tpl_add_function('colour_get_css_contrast', true); + tpl_add_function('colour_get_inherit', true); + tpl_add_function('colour_get_red', true); + tpl_add_function('colour_get_green', true); + tpl_add_function('colour_get_blue', true); + tpl_add_function('parse_line', true); + tpl_add_function('parse_text', true); + tpl_add_function('asset_url', true); + tpl_add_function('vsprintf', true); - $this->templatingInstance->addFunction('git_commit_hash'); - $this->templatingInstance->addFunction('git_branch'); - $this->templatingInstance->addFunction('csrf_token', 'tmp_csrf_token'); - $this->templatingInstance->addFunction('perms_check'); + tpl_add_function('git_commit_hash'); + tpl_add_function('git_branch'); + tpl_add_function('csrf_token', false, 'tmp_csrf_token'); + tpl_add_function('perms_check'); - $this->templatingInstance->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; + tpl_var('app', $this); } public function startMailer(): void diff --git a/src/TemplateEngine.php b/src/TemplateEngine.php deleted file mode 100644 index eaeaa1de..00000000 --- a/src/TemplateEngine.php +++ /dev/null @@ -1,239 +0,0 @@ - - */ -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)); - } -} diff --git a/src/Twig.php b/src/Twig.php new file mode 100644 index 00000000..6b15ffc6 --- /dev/null +++ b/src/Twig.php @@ -0,0 +1,26 @@ + 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]); +} diff --git a/views/mio/_layout/comments.twig b/templates/_layout/comments.twig similarity index 100% rename from views/mio/_layout/comments.twig rename to templates/_layout/comments.twig diff --git a/views/mio/_layout/header.twig b/templates/_layout/header.twig similarity index 100% rename from views/mio/_layout/header.twig rename to templates/_layout/header.twig diff --git a/views/mio/_layout/meta.twig b/templates/_layout/meta.twig similarity index 100% rename from views/mio/_layout/meta.twig rename to templates/_layout/meta.twig diff --git a/views/auth/auth.twig b/templates/auth/auth.twig similarity index 99% rename from views/auth/auth.twig rename to templates/auth/auth.twig index 69cafda5..876b049c 100644 --- a/views/auth/auth.twig +++ b/templates/auth/auth.twig @@ -1,4 +1,4 @@ -{% extends '@auth/master.twig' %} +{% extends 'auth/master.twig' %} {% block content %}
diff --git a/views/auth/lockdown.twig b/templates/auth/lockdown.twig similarity index 87% rename from views/auth/lockdown.twig rename to templates/auth/lockdown.twig index 2a106d3a..2ab3951a 100644 --- a/views/auth/lockdown.twig +++ b/templates/auth/lockdown.twig @@ -1,4 +1,4 @@ -{% extends '@auth/master.twig' %} +{% extends 'auth/master.twig' %} {% block content %}
diff --git a/views/auth/logout.twig b/templates/auth/logout.twig similarity index 94% rename from views/auth/logout.twig rename to templates/auth/logout.twig index 33ce34e0..a05edeb3 100644 --- a/views/auth/logout.twig +++ b/templates/auth/logout.twig @@ -1,4 +1,4 @@ -{% extends '@auth/master.twig' %} +{% extends 'auth/master.twig' %} {% block content %}
diff --git a/views/auth/master.twig b/templates/auth/master.twig similarity index 100% rename from views/auth/master.twig rename to templates/auth/master.twig diff --git a/views/auth/password.twig b/templates/auth/password.twig similarity index 98% rename from views/auth/password.twig rename to templates/auth/password.twig index 352b14b6..194663be 100644 --- a/views/auth/password.twig +++ b/templates/auth/password.twig @@ -1,4 +1,4 @@ -{% extends '@auth/master.twig' %} +{% extends 'auth/master.twig' %} {% block content %}
diff --git a/views/mio/changelog/change.twig b/templates/changelog/change.twig similarity index 97% rename from views/mio/changelog/change.twig rename to templates/changelog/change.twig index 84185511..1f8cc19e 100644 --- a/views/mio/changelog/change.twig +++ b/templates/changelog/change.twig @@ -1,5 +1,5 @@ -{% extends '@mio/changelog/master.twig' %} -{% from '@mio/_layout/comments.twig' import comments_section %} +{% extends 'changelog/master.twig' %} +{% from '_layout/comments.twig' import comments_section %} {% set is_valid = change|length > 0 %} {% set title = 'Changelog » ' ~ (is_valid ? 'Change #' ~ change.change_id : 'Unknown Change') %} diff --git a/views/mio/changelog/index.twig b/templates/changelog/index.twig similarity index 86% rename from views/mio/changelog/index.twig rename to templates/changelog/index.twig index 28dcfbc8..9fb43394 100644 --- a/views/mio/changelog/index.twig +++ b/templates/changelog/index.twig @@ -1,7 +1,7 @@ -{% extends '@mio/changelog/master.twig' %} -{% from '@mio/macros.twig' import pagination %} -{% from '@mio/changelog/macros.twig' import changelog_listing %} -{% from '@mio/_layout/comments.twig' import comments_section %} +{% extends 'changelog/master.twig' %} +{% from 'macros.twig' import pagination %} +{% from 'changelog/macros.twig' import changelog_listing %} +{% from '_layout/comments.twig' import comments_section %} {% set is_valid = changes|length > 0 %} {% set is_date = changelog_date|length > 0 %} diff --git a/views/mio/changelog/macros.twig b/templates/changelog/macros.twig similarity index 100% rename from views/mio/changelog/macros.twig rename to templates/changelog/macros.twig diff --git a/views/mio/changelog/master.twig b/templates/changelog/master.twig similarity index 75% rename from views/mio/changelog/master.twig rename to templates/changelog/master.twig index 886b1320..122c4d7a 100644 --- a/views/mio/changelog/master.twig +++ b/templates/changelog/master.twig @@ -1,4 +1,4 @@ -{% extends '@mio/master.twig' %} +{% extends 'master.twig' %} {% if manage_link is not defined %} {% set manage_link = '/manage/changelog.php' %} diff --git a/views/mio/errors/400.twig b/templates/errors/400.twig similarity index 80% rename from views/mio/errors/400.twig rename to templates/errors/400.twig index 34f9627d..6fd61d10 100644 --- a/views/mio/errors/400.twig +++ b/templates/errors/400.twig @@ -1,4 +1,4 @@ -{% extends '@mio/errors/master.twig' %} +{% extends 'errors/master.twig' %} {% set error_code = 400 %} {% set error_text = 'Bad Request' %} diff --git a/views/mio/errors/403.twig b/templates/errors/403.twig similarity index 82% rename from views/mio/errors/403.twig rename to templates/errors/403.twig index 6543c802..a0e5b238 100644 --- a/views/mio/errors/403.twig +++ b/templates/errors/403.twig @@ -1,4 +1,4 @@ -{% extends '@mio/errors/master.twig' %} +{% extends 'errors/master.twig' %} {% set error_code = 403 %} {% set error_text = 'Access Denied!' %} diff --git a/views/mio/errors/404.twig b/templates/errors/404.twig similarity index 84% rename from views/mio/errors/404.twig rename to templates/errors/404.twig index 2e3518ac..7f8405a9 100644 --- a/views/mio/errors/404.twig +++ b/templates/errors/404.twig @@ -1,4 +1,4 @@ -{% extends '@mio/errors/master.twig' %} +{% extends 'errors/master.twig' %} {% set error_code = 404 %} {% set error_text = 'Not Found!' %} diff --git a/views/mio/errors/master.twig b/templates/errors/master.twig similarity index 96% rename from views/mio/errors/master.twig rename to templates/errors/master.twig index 40188094..dfa48691 100644 --- a/views/mio/errors/master.twig +++ b/templates/errors/master.twig @@ -1,4 +1,4 @@ -{% extends '@mio/master.twig' %} +{% extends 'master.twig' %} {% block content %}
diff --git a/views/mio/forum/forum.twig b/templates/forum/forum.twig similarity index 82% rename from views/mio/forum/forum.twig rename to templates/forum/forum.twig index e49f5ba3..a9eb1863 100644 --- a/views/mio/forum/forum.twig +++ b/templates/forum/forum.twig @@ -1,6 +1,6 @@ -{% extends '@mio/forum/master.twig' %} -{% from '@mio/macros.twig' import navigation, pagination %} -{% from '@mio/forum/macros.twig' import forum_category_listing, forum_topic_listing, forum_category_buttons %} +{% extends 'forum/master.twig' %} +{% from 'macros.twig' import navigation, pagination %} +{% from 'forum/macros.twig' import forum_category_listing, forum_topic_listing, forum_category_buttons %} {% set title = forum_info.forum_name %} {% set canonical_url = '/forum/forum.php'|url_construct({ diff --git a/views/mio/forum/index.twig b/templates/forum/index.twig similarity index 91% rename from views/mio/forum/index.twig rename to templates/forum/index.twig index 6190caa3..6f88103b 100644 --- a/views/mio/forum/index.twig +++ b/templates/forum/index.twig @@ -1,5 +1,5 @@ -{% extends '@mio/forum/master.twig' %} -{% from '@mio/forum/macros.twig' import forum_category_listing %} +{% extends 'forum/master.twig' %} +{% from 'forum/macros.twig' import forum_category_listing %} {% set title = 'Forum Listing' %} {% set canonical_url = '/forum/' %} diff --git a/views/mio/forum/macros.twig b/templates/forum/macros.twig similarity index 100% rename from views/mio/forum/macros.twig rename to templates/forum/macros.twig diff --git a/templates/forum/master.twig b/templates/forum/master.twig new file mode 100644 index 00000000..fc530f21 --- /dev/null +++ b/templates/forum/master.twig @@ -0,0 +1 @@ +{% extends 'master.twig' %} diff --git a/views/mio/forum/posting.twig b/templates/forum/posting.twig similarity index 78% rename from views/mio/forum/posting.twig rename to templates/forum/posting.twig index 82613eb5..528e0ccd 100644 --- a/views/mio/forum/posting.twig +++ b/templates/forum/posting.twig @@ -1,6 +1,6 @@ -{% extends '@mio/forum/master.twig' %} -{% from '@mio/macros.twig' import navigation %} -{% from '@mio/forum/macros.twig' import forum_posting_form %} +{% extends 'forum/master.twig' %} +{% from 'macros.twig' import navigation %} +{% from 'forum/macros.twig' import forum_posting_form %} {% set title = 'Posting' %} diff --git a/views/mio/forum/topic.twig b/templates/forum/topic.twig similarity index 91% rename from views/mio/forum/topic.twig rename to templates/forum/topic.twig index 3907f568..c843a022 100644 --- a/views/mio/forum/topic.twig +++ b/templates/forum/topic.twig @@ -1,7 +1,7 @@ -{% extends '@mio/forum/master.twig' %} -{% from '@mio/macros.twig' import navigation, pagination %} +{% extends 'forum/master.twig' %} +{% from 'macros.twig' import navigation, pagination %} {% - from '@mio/forum/macros.twig' + from 'forum/macros.twig' import forum_post_listing, forum_topic_buttons, diff --git a/views/mio/home/index.twig b/templates/home/index.twig similarity index 94% rename from views/mio/home/index.twig rename to templates/home/index.twig index ccaba672..50f4905e 100644 --- a/views/mio/home/index.twig +++ b/templates/home/index.twig @@ -1,6 +1,6 @@ -{% extends '@mio/home/master.twig' %} -{% from '@mio/news/macros.twig' import news_preview %} -{% from '@mio/changelog/macros.twig' import changelog_listing %} +{% extends 'home/master.twig' %} +{% from 'news/macros.twig' import news_preview %} +{% from 'changelog/macros.twig' import changelog_listing %} {% set canonical_url = '/' %} diff --git a/templates/home/master.twig b/templates/home/master.twig new file mode 100644 index 00000000..fc530f21 --- /dev/null +++ b/templates/home/master.twig @@ -0,0 +1 @@ +{% extends 'master.twig' %} diff --git a/views/mio/macros.twig b/templates/macros.twig similarity index 100% rename from views/mio/macros.twig rename to templates/macros.twig diff --git a/views/manage/changelog/action_edit.twig b/templates/manage/changelog/action_edit.twig similarity index 98% rename from views/manage/changelog/action_edit.twig rename to templates/manage/changelog/action_edit.twig index ab5aad47..9d499ac8 100644 --- a/views/manage/changelog/action_edit.twig +++ b/templates/manage/changelog/action_edit.twig @@ -1,4 +1,4 @@ -{% extends '@manage/changelog/master.twig' %} +{% extends 'manage/changelog/master.twig' %} {% block content %}
diff --git a/views/manage/changelog/actions.twig b/templates/manage/changelog/actions.twig similarity index 90% rename from views/manage/changelog/actions.twig rename to templates/manage/changelog/actions.twig index b2a06281..c78fcc2b 100644 --- a/views/manage/changelog/actions.twig +++ b/templates/manage/changelog/actions.twig @@ -1,5 +1,5 @@ -{% extends '@manage/changelog/master.twig' %} -{% from '@manage/macros.twig' import pagination %} +{% extends 'manage/changelog/master.twig' %} +{% from 'manage/macros.twig' import pagination %} {% block content %}
diff --git a/views/manage/changelog/change_edit.twig b/templates/manage/changelog/change_edit.twig similarity index 99% rename from views/manage/changelog/change_edit.twig rename to templates/manage/changelog/change_edit.twig index 78e24a41..ef30643a 100644 --- a/views/manage/changelog/change_edit.twig +++ b/templates/manage/changelog/change_edit.twig @@ -1,4 +1,4 @@ -{% extends '@manage/changelog/master.twig' %} +{% extends 'manage/changelog/master.twig' %} {% block content %}
diff --git a/views/manage/changelog/changes.twig b/templates/manage/changelog/changes.twig similarity index 96% rename from views/manage/changelog/changes.twig rename to templates/manage/changelog/changes.twig index 055e2864..27771d6d 100644 --- a/views/manage/changelog/changes.twig +++ b/templates/manage/changelog/changes.twig @@ -1,5 +1,5 @@ -{% extends '@manage/changelog/master.twig' %} -{% from '@manage/macros.twig' import pagination %} +{% extends 'manage/changelog/master.twig' %} +{% from 'manage/macros.twig' import pagination %} {% block content %}
diff --git a/templates/manage/changelog/master.twig b/templates/manage/changelog/master.twig new file mode 100644 index 00000000..f04b5b59 --- /dev/null +++ b/templates/manage/changelog/master.twig @@ -0,0 +1 @@ +{% extends 'manage/master.twig' %} diff --git a/views/manage/changelog/tag_edit.twig b/templates/manage/changelog/tag_edit.twig similarity index 98% rename from views/manage/changelog/tag_edit.twig rename to templates/manage/changelog/tag_edit.twig index a59f7e4c..3dcf399f 100644 --- a/views/manage/changelog/tag_edit.twig +++ b/templates/manage/changelog/tag_edit.twig @@ -1,4 +1,4 @@ -{% extends '@manage/changelog/master.twig' %} +{% extends 'manage/changelog/master.twig' %} {% block content %}
diff --git a/views/manage/changelog/tags.twig b/templates/manage/changelog/tags.twig similarity index 90% rename from views/manage/changelog/tags.twig rename to templates/manage/changelog/tags.twig index 1d55c579..7ed53c3d 100644 --- a/views/manage/changelog/tags.twig +++ b/templates/manage/changelog/tags.twig @@ -1,5 +1,5 @@ -{% extends '@manage/changelog/master.twig' %} -{% from '@manage/macros.twig' import pagination %} +{% extends 'manage/changelog/master.twig' %} +{% from 'manage/macros.twig' import pagination %} {% block content %}
diff --git a/templates/manage/general/master.twig b/templates/manage/general/master.twig new file mode 100644 index 00000000..f04b5b59 --- /dev/null +++ b/templates/manage/general/master.twig @@ -0,0 +1 @@ +{% extends 'manage/master.twig' %} diff --git a/views/manage/general/overview.twig b/templates/manage/general/overview.twig similarity index 75% rename from views/manage/general/overview.twig rename to templates/manage/general/overview.twig index 3ea0c56d..b60aa541 100644 --- a/views/manage/general/overview.twig +++ b/templates/manage/general/overview.twig @@ -1,4 +1,4 @@ -{% extends '@manage/general/master.twig' %} +{% extends 'manage/general/master.twig' %} {% block content %}
diff --git a/views/manage/macros.twig b/templates/manage/macros.twig similarity index 100% rename from views/manage/macros.twig rename to templates/manage/macros.twig diff --git a/views/manage/master.twig b/templates/manage/master.twig similarity index 100% rename from views/manage/master.twig rename to templates/manage/master.twig diff --git a/views/manage/users/listing.twig b/templates/manage/users/listing.twig similarity index 91% rename from views/manage/users/listing.twig rename to templates/manage/users/listing.twig index 9dc49789..2a719bd0 100644 --- a/views/manage/users/listing.twig +++ b/templates/manage/users/listing.twig @@ -1,5 +1,5 @@ -{% extends '@manage/users/master.twig' %} -{% from '@manage/macros.twig' import pagination %} +{% extends 'manage/users/master.twig' %} +{% from 'manage/macros.twig' import pagination %} {% block content %}
diff --git a/templates/manage/users/master.twig b/templates/manage/users/master.twig new file mode 100644 index 00000000..f04b5b59 --- /dev/null +++ b/templates/manage/users/master.twig @@ -0,0 +1 @@ +{% extends 'manage/master.twig' %} diff --git a/views/manage/users/roles.twig b/templates/manage/users/roles.twig similarity index 90% rename from views/manage/users/roles.twig rename to templates/manage/users/roles.twig index 169e1f3a..3222d529 100644 --- a/views/manage/users/roles.twig +++ b/templates/manage/users/roles.twig @@ -1,5 +1,5 @@ -{% extends '@manage/users/master.twig' %} -{% from '@manage/macros.twig' import pagination %} +{% extends 'manage/users/master.twig' %} +{% from 'manage/macros.twig' import pagination %} {% block content %} {% if can_manage_roles %} diff --git a/views/manage/users/roles_create.twig b/templates/manage/users/roles_create.twig similarity index 97% rename from views/manage/users/roles_create.twig rename to templates/manage/users/roles_create.twig index 12813b4d..327eb278 100644 --- a/views/manage/users/roles_create.twig +++ b/templates/manage/users/roles_create.twig @@ -1,5 +1,5 @@ -{% extends '@manage/users/master.twig' %} -{% from '@manage/macros.twig' import permissions_table %} +{% extends 'manage/users/master.twig' %} +{% from 'manage/macros.twig' import permissions_table %} {% block content %}
diff --git a/views/manage/users/view.twig b/templates/manage/users/view.twig similarity index 98% rename from views/manage/users/view.twig rename to templates/manage/users/view.twig index 4b11e38c..2484f11c 100644 --- a/views/manage/users/view.twig +++ b/templates/manage/users/view.twig @@ -1,5 +1,5 @@ -{% extends '@manage/users/master.twig' %} -{% from '@manage/macros.twig' import permissions_table %} +{% extends 'manage/users/master.twig' %} +{% from 'manage/macros.twig' import permissions_table %} {% block content %} {% if can_manage_users %} diff --git a/views/mio/master.twig b/templates/master.twig similarity index 98% rename from views/mio/master.twig rename to templates/master.twig index fa887e76..97047137 100644 --- a/views/mio/master.twig +++ b/templates/master.twig @@ -3,7 +3,7 @@ - {% include '@mio/_layout/meta.twig' %} + {% include '_layout/meta.twig' %} diff --git a/views/mio/news/category.twig b/templates/news/category.twig similarity index 92% rename from views/mio/news/category.twig rename to templates/news/category.twig index 4803ed5b..04b75160 100644 --- a/views/mio/news/category.twig +++ b/templates/news/category.twig @@ -1,6 +1,6 @@ -{% extends '@mio/news/master.twig' %} -{% from '@mio/macros.twig' import pagination %} -{% from '@mio/news/macros.twig' import news_preview %} +{% extends 'news/master.twig' %} +{% from 'macros.twig' import pagination %} +{% from 'news/macros.twig' import news_preview %} {% set title = category.category_name ~ ' :: News' %} {% set canonical_url = '/news.php'|url_construct({ diff --git a/views/mio/news/index.twig b/templates/news/index.twig similarity index 91% rename from views/mio/news/index.twig rename to templates/news/index.twig index 6e1c683d..340dc3f9 100644 --- a/views/mio/news/index.twig +++ b/templates/news/index.twig @@ -1,6 +1,6 @@ -{% extends '@mio/news/master.twig' %} -{% from '@mio/macros.twig' import pagination %} -{% from '@mio/news/macros.twig' import news_preview %} +{% extends 'news/master.twig' %} +{% from 'macros.twig' import pagination %} +{% from 'news/macros.twig' import news_preview %} {% set title = 'News' %} {% set canonical_url = '/news.php'|url_construct({'o':posts_offset}) %} diff --git a/views/mio/news/macros.twig b/templates/news/macros.twig similarity index 100% rename from views/mio/news/macros.twig rename to templates/news/macros.twig diff --git a/templates/news/master.twig b/templates/news/master.twig new file mode 100644 index 00000000..fc530f21 --- /dev/null +++ b/templates/news/master.twig @@ -0,0 +1 @@ +{% extends 'master.twig' %} diff --git a/views/mio/news/post.twig b/templates/news/post.twig similarity index 96% rename from views/mio/news/post.twig rename to templates/news/post.twig index 619a9f78..359d5892 100644 --- a/views/mio/news/post.twig +++ b/templates/news/post.twig @@ -1,5 +1,5 @@ -{% extends '@mio/news/master.twig' %} -{% from '@mio/_layout/comments.twig' import comments_section %} +{% extends 'news/master.twig' %} +{% from '_layout/comments.twig' import comments_section %} {% set title = post.post_title ~ ' :: News' %} {% set canonical_url = '/news.php?p=' ~ post.post_id %} diff --git a/views/mio/settings/account.twig b/templates/settings/account.twig similarity index 99% rename from views/mio/settings/account.twig rename to templates/settings/account.twig index 7b038237..28e81094 100644 --- a/views/mio/settings/account.twig +++ b/templates/settings/account.twig @@ -1,4 +1,4 @@ -{% extends '@mio/settings/master.twig' %} +{% extends 'settings/master.twig' %} {% block settings_content %}
diff --git a/views/mio/settings/logs.twig b/templates/settings/logs.twig similarity index 98% rename from views/mio/settings/logs.twig rename to templates/settings/logs.twig index 4e6ebddf..391a3bd5 100644 --- a/views/mio/settings/logs.twig +++ b/templates/settings/logs.twig @@ -1,5 +1,5 @@ -{% extends '@mio/settings/master.twig' %} -{% from '@mio/macros.twig' import pagination %} +{% extends 'settings/master.twig' %} +{% from 'macros.twig' import pagination %} {% set alpagination = pagination( audit_log_count, diff --git a/views/mio/settings/master.twig b/templates/settings/master.twig similarity index 92% rename from views/mio/settings/master.twig rename to templates/settings/master.twig index 22f9f876..c942994f 100644 --- a/views/mio/settings/master.twig +++ b/templates/settings/master.twig @@ -1,5 +1,5 @@ -{% extends '@mio/master.twig' %} -{% from '@mio/macros.twig' import navigation %} +{% extends 'master.twig' %} +{% from 'macros.twig' import navigation %} {% set title = 'Settings » ' ~ settings_title %} diff --git a/views/mio/settings/notfound.twig b/templates/settings/notfound.twig similarity index 70% rename from views/mio/settings/notfound.twig rename to templates/settings/notfound.twig index 44840fd8..f22b28cb 100644 --- a/views/mio/settings/notfound.twig +++ b/templates/settings/notfound.twig @@ -1,4 +1,4 @@ -{% extends '@mio/settings/master.twig' %} +{% extends 'settings/master.twig' %} {% block settings_content %}

Could not find what you were looking for.

diff --git a/views/mio/settings/sessions.twig b/templates/settings/sessions.twig similarity index 97% rename from views/mio/settings/sessions.twig rename to templates/settings/sessions.twig index e9405890..50d35236 100644 --- a/views/mio/settings/sessions.twig +++ b/templates/settings/sessions.twig @@ -1,5 +1,5 @@ -{% extends '@mio/settings/master.twig' %} -{% from '@mio/macros.twig' import pagination %} +{% extends 'settings/master.twig' %} +{% from 'macros.twig' import pagination %} {% set spagination = pagination(sessions_count, sessions_take, sessions_offset, '?m=sessions', 'settings__') %} diff --git a/views/mio/user/listing.twig b/templates/user/listing.twig similarity index 98% rename from views/mio/user/listing.twig rename to templates/user/listing.twig index 28a63e9e..071d4a17 100644 --- a/views/mio/user/listing.twig +++ b/templates/user/listing.twig @@ -1,5 +1,5 @@ -{% extends '@mio/user/master.twig' %} -{% from '@mio/macros.twig' import pagination %} +{% extends 'user/master.twig' %} +{% from 'macros.twig' import pagination %} {% set canonical_url = '/members.php'|url_construct({ 'r': role.role_id != 1 ? role.role_id : 0, diff --git a/templates/user/master.twig b/templates/user/master.twig new file mode 100644 index 00000000..fc530f21 --- /dev/null +++ b/templates/user/master.twig @@ -0,0 +1 @@ +{% extends 'master.twig' %} diff --git a/views/mio/user/notfound.twig b/templates/user/notfound.twig similarity index 87% rename from views/mio/user/notfound.twig rename to templates/user/notfound.twig index 2f0bb2aa..173af112 100644 --- a/views/mio/user/notfound.twig +++ b/templates/user/notfound.twig @@ -1,4 +1,4 @@ -{% extends '@mio/user/master.twig' %} +{% extends 'user/master.twig' %} {% set title = 'User not found!' %} diff --git a/views/mio/user/view.twig b/templates/user/view.twig similarity index 99% rename from views/mio/user/view.twig rename to templates/user/view.twig index 019a7b94..e4c7fcc0 100644 --- a/views/mio/user/view.twig +++ b/templates/user/view.twig @@ -1,5 +1,5 @@ -{% extends '@mio/user/master.twig' %} -{% from '@mio/macros.twig' import navigation %} +{% extends 'user/master.twig' %} +{% from 'macros.twig' import navigation %} {% set image = '/profile.php?u=' ~ profile.user_id ~ '&m=avatar' %} {% set canonical_url = '/profile.php?u=' ~ profile.user_id %} diff --git a/utility.php b/utility.php index 6454b1c1..af12a8ae 100644 --- a/utility.php +++ b/utility.php @@ -283,21 +283,19 @@ function render_info(?string $message, int $httpCode, string $template = 'errors http_response_code($httpCode); try { - $tpl = \Misuzu\Application::getInstance()->getTemplating(); - - $tpl->var('http_code', $httpCode); + tpl_var('http_code', $httpCode); if (strlen($message)) { - $tpl->var('message', $message); + tpl_var('message', $message); } $template = sprintf($template, $httpCode); - if (!$tpl->exists($template, \Misuzu\TemplateEngine::TWIG_DEFAULT)) { + if (!tpl_exists($template)) { $template = 'errors.master'; } - return $tpl->render(sprintf($template, $httpCode)); + return tpl_render(sprintf($template, $httpCode)); } catch (Exception $ex) { echo $ex->getMessage(); return $message ?? ''; diff --git a/views/manage/changelog/master.twig b/views/manage/changelog/master.twig deleted file mode 100644 index b796b165..00000000 --- a/views/manage/changelog/master.twig +++ /dev/null @@ -1 +0,0 @@ -{% extends '@manage/master.twig' %} diff --git a/views/manage/general/master.twig b/views/manage/general/master.twig deleted file mode 100644 index b796b165..00000000 --- a/views/manage/general/master.twig +++ /dev/null @@ -1 +0,0 @@ -{% extends '@manage/master.twig' %} diff --git a/views/manage/users/master.twig b/views/manage/users/master.twig deleted file mode 100644 index b796b165..00000000 --- a/views/manage/users/master.twig +++ /dev/null @@ -1 +0,0 @@ -{% extends '@manage/master.twig' %} diff --git a/views/mio/forum/master.twig b/views/mio/forum/master.twig deleted file mode 100644 index 187fe3a8..00000000 --- a/views/mio/forum/master.twig +++ /dev/null @@ -1 +0,0 @@ -{% extends '@mio/master.twig' %} diff --git a/views/mio/home/master.twig b/views/mio/home/master.twig deleted file mode 100644 index 187fe3a8..00000000 --- a/views/mio/home/master.twig +++ /dev/null @@ -1 +0,0 @@ -{% extends '@mio/master.twig' %} diff --git a/views/mio/news/master.twig b/views/mio/news/master.twig deleted file mode 100644 index 187fe3a8..00000000 --- a/views/mio/news/master.twig +++ /dev/null @@ -1 +0,0 @@ -{% extends '@mio/master.twig' %} diff --git a/views/mio/user/master.twig b/views/mio/user/master.twig deleted file mode 100644 index 187fe3a8..00000000 --- a/views/mio/user/master.twig +++ /dev/null @@ -1 +0,0 @@ -{% extends '@mio/master.twig' %}