summaryrefslogtreecommitdiff
path: root/src/application/actions
diff options
context:
space:
mode:
Diffstat (limited to 'src/application/actions')
-rw-r--r--src/application/actions/_default/get.php10
-rw-r--r--src/application/actions/auth/get.php9
-rw-r--r--src/application/actions/deletepost/post.php21
-rw-r--r--src/application/actions/deletetopic/post.php7
-rw-r--r--src/application/actions/newtopic/get.php9
-rw-r--r--src/application/actions/pwreset/get.php16
-rw-r--r--src/application/actions/register/get.php9
-rw-r--r--src/application/actions/search/get.php19
-rw-r--r--src/application/actions/viewtopic/get.php37
-rw-r--r--src/application/actions/viewuser/get.php15
10 files changed, 40 insertions, 112 deletions
diff --git a/src/application/actions/_default/get.php b/src/application/actions/_default/get.php
index cd0c21c..616589f 100644
--- a/src/application/actions/_default/get.php
+++ b/src/application/actions/_default/get.php
@@ -1,11 +1,7 @@
<?php
use mystic\forum\orm\Topic;
-use mystic\forum\utils\RequestUtils;
-_view("template_start");
-_view("template_navigation_start");
-_view("template_navigation", ["user" => RequestUtils::getAuthorizedUser($db)]);
-_view("template_navigation_end");
-_view("view_topics", ["topics" => $db->fetchCustom(Topic::class, "ORDER BY creation_date DESC")]);
-_view("template_end", [...getThemeAndLangInfo()]);
+render("view_topics.twig", [
+ "topics" => $db->fetchCustom(Topic::class, "ORDER BY creation_date DESC"),
+]);
diff --git a/src/application/actions/auth/get.php b/src/application/actions/auth/get.php
index 2ff38ff..dfeb837 100644
--- a/src/application/actions/auth/get.php
+++ b/src/application/actions/auth/get.php
@@ -1,10 +1,3 @@
<?php
-use mystic\forum\utils\RequestUtils;
-
-_view("template_start", ["_title" => __("Log in")]);
-_view("template_navigation_start");
-_view("template_navigation", ["user" => RequestUtils::getAuthorizedUser($db)]);
-_view("template_navigation_end");
-_view("form_login");
-_view("template_end", [...getThemeAndLangInfo()]);
+render("login.twig");
diff --git a/src/application/actions/deletepost/post.php b/src/application/actions/deletepost/post.php
index b711021..4cd9872 100644
--- a/src/application/actions/deletepost/post.php
+++ b/src/application/actions/deletepost/post.php
@@ -24,11 +24,11 @@ if (!$db->fetch($item) || $item->deleted) {
exit;
}
-$topicAuthor = new User();
-$topicAuthor->id = $item->authorId;
+$postAuthor = new User();
+$postAuthor->id = $item->authorId;
-if (!$db->fetch($topicAuthor))
- $topicAuthor = null;
+if (!$db->fetch($postAuthor))
+ $postAuthor = null;
$topic = new Topic();
$topic->id = $item->topicId;
@@ -36,10 +36,10 @@ $topic->id = $item->topicId;
if (!$db->fetch($topic))
$topic = null;
-$canEdit = ($currentUser->id === $topicAuthor?->id && $topicAuthor?->hasPermission(UserPermissions::DELETE_OWN_POST))
+$canDelete = ($currentUser->id === $postAuthor?->id && $postAuthor?->hasPermission(UserPermissions::DELETE_OWN_POST))
|| ($currentUser->hasPermission(UserPermissions::DELETE_OTHER_POST));
-if (!$canEdit) {
+if (!$canDelete) {
http_response_code(403);
msg_error("You don't have permission to delete this post");
exit;
@@ -75,16 +75,11 @@ if ($confirm !== null) {
header("Location: ?_action=viewtopic&topic=" . urlencode($item->topicId));
} else {
- _view("template_start", ["_title" => __("Delete post")]);
- _view("template_navigation_start");
- _view("template_navigation", ["user" => RequestUtils::getAuthorizedUser($db)]);
- _view("template_navigation_end");
- _view("form_delete_post_confirm", [
+ render("delete_post.twig", [
"post" => $item,
- "postAuthor" => $topicAuthor,
+ "postAuthor" => $postAuthor,
"topicAuthor" => null,
"attachments" => $attachments,
"topic" => $topic,
]);
- _view("template_end", [...getThemeAndLangInfo()]);
}
diff --git a/src/application/actions/deletetopic/post.php b/src/application/actions/deletetopic/post.php
index e67cadf..8683c0f 100644
--- a/src/application/actions/deletetopic/post.php
+++ b/src/application/actions/deletetopic/post.php
@@ -55,13 +55,8 @@ if ($confirm !== null) {
header("Location: .");
} else {
- _view("template_start", ["_title" => "Delete topic"]);
- _view("template_navigation_start");
- _view("template_navigation", ["user" => RequestUtils::getAuthorizedUser($db)]);
- _view("template_navigation_end");
- _view("form_delete_topic_confirm", [
+ render("delete_topic.twig", [
"topic" => $topic,
"topicAuthor" => $topicAuthor,
]);
- _view("template_end", [...getThemeAndLangInfo()]);
}
diff --git a/src/application/actions/newtopic/get.php b/src/application/actions/newtopic/get.php
index 366caac..621cd18 100644
--- a/src/application/actions/newtopic/get.php
+++ b/src/application/actions/newtopic/get.php
@@ -1,10 +1,3 @@
<?php
-use mystic\forum\utils\RequestUtils;
-
-_view("template_start", ["_title" => __("New topic")]);
-_view("template_navigation_start");
-_view("template_navigation", ["user" => RequestUtils::getAuthorizedUser($db)]);
-_view("template_navigation_end");
-_view("form_newtopic");
-_view("template_end", [...getThemeAndLangInfo()]);
+render("new_topic.twig");
diff --git a/src/application/actions/pwreset/get.php b/src/application/actions/pwreset/get.php
index c66b28d..35b93f0 100644
--- a/src/application/actions/pwreset/get.php
+++ b/src/application/actions/pwreset/get.php
@@ -11,19 +11,7 @@ if ($token !== null && $signature !== null) {
exit;
}
- _view("template_start", [ "_title" => __("Reset password") ]);
- _view("template_navigation_start");
- _view("template_navigation_end");
- _view("form_new_password", [
- "token" => $token,
- "signature" => $signature,
- ]);
- _view("template_end", [...getThemeAndLangInfo()]);
+ render("new_password.twig");
} else {
- _view("template_start", [ "_title" => __("Reset password") ]);
- _view("template_navigation_start");
- _view("template_navigation", ["user" => null]);
- _view("template_navigation_end");
- _view("form_password_reset");
- _view("template_end", [...getThemeAndLangInfo()]);
+ render("password_reset.twig");
}
diff --git a/src/application/actions/register/get.php b/src/application/actions/register/get.php
index 914ea4e..d1df1b6 100644
--- a/src/application/actions/register/get.php
+++ b/src/application/actions/register/get.php
@@ -1,10 +1,3 @@
<?php
-use mystic\forum\utils\RequestUtils;
-
-_view("template_start", ["_title" => __("Register")]);
-_view("template_navigation_start");
-_view("template_navigation", ["user" => RequestUtils::getAuthorizedUser($db)]);
-_view("template_navigation_end");
-_view("form_register");
-_view("template_end", [...getThemeAndLangInfo()]);
+render("register.twig");
diff --git a/src/application/actions/search/get.php b/src/application/actions/search/get.php
index d3de970..bc1bdba 100644
--- a/src/application/actions/search/get.php
+++ b/src/application/actions/search/get.php
@@ -41,25 +41,14 @@ if ($query !== null) {
}
$end_time = microtime(true);
$search_duration = $end_time - $start_time;
-
- _view("template_start", ["_title" => __("Search results for “%query%”", [ "query" => $query ])]);
- _view("template_navigation_start");
- _view("template_navigation", ["user" => RequestUtils::getAuthorizedUser($db)]);
- _view("template_navigation_end");
- _view("form_search", [ "query" => $query ]);
- _view("view_search_results", [
+
+ render("search.twig", [
"posts" => &$posts,
"topics" => &$topicLookup,
"users" => &$userLookup,
"attachments" => &$attachmentLookup,
"search_duration" => $search_duration,
]);
- _view("template_end", [...getThemeAndLangInfo()]);
} else {
- _view("template_start", ["_title" => __("Search")]);
- _view("template_navigation_start");
- _view("template_navigation", ["user" => RequestUtils::getAuthorizedUser($db)]);
- _view("template_navigation_end");
- _view("form_search");
- _view("template_end", [...getThemeAndLangInfo()]);
-} \ No newline at end of file
+ render("search.twig");
+}
diff --git a/src/application/actions/viewtopic/get.php b/src/application/actions/viewtopic/get.php
index 45dc824..636d791 100644
--- a/src/application/actions/viewtopic/get.php
+++ b/src/application/actions/viewtopic/get.php
@@ -6,7 +6,6 @@ use mystic\forum\orm\Attachment;
use mystic\forum\orm\Post;
use mystic\forum\orm\TopicLogMessage;
use mystic\forum\orm\User;
-use mystic\forum\utils\RequestUtils;
$posts = $db->fetchCustom(Post::class, 'WHERE topic_id = $1 ORDER BY post_date', [ $topicId ]);
/** @var TopicLogMessage[] $logMessages */
@@ -25,13 +24,7 @@ if ($topic->createdBy !== null) {
$allItems = [...$posts, ...$logMessages];
usort($allItems, fn(Post|TopicLogMessage $a, Post|TopicLogMessage $b): int => $a->postDate <=> $b->postDate);
-_view("template_start", ["_title" => $topic->title]);
-_view("template_navigation_start");
-_view("template_navigation", ["user" => RequestUtils::getAuthorizedUser($db)]);
-_view("template_navigation_end");
-_view("view_topic_start", ["topic" => $topic, "topicAuthor" => $topicAuthor]);
-
-foreach ($allItems as $item) {
+$allItems = array_map(function(Post|TopicLogMessage $item) use (&$db, &$topicAuthor, &$topic): array {
/** @var ?User $postAuthor */
$postAuthor = null;
if ($item->authorId !== null && !isset($userCache[$item->authorId])) {
@@ -46,31 +39,27 @@ foreach ($allItems as $item) {
if ($item instanceof Post) {
$attachments = $db->fetchCustom(Attachment::class, 'WHERE post_id = $1', [ $item->id ]);
- _view("view_post", [
+ return [
+ "type" => "post",
"post" => $item,
"postAuthor" => $postAuthor,
"topicAuthor" => $topicAuthor,
"attachments" => $attachments,
"topic" => $topic,
- ]);
+ ];
} else {
- _view("view_topiclog", [
+ return [
+ "type" => "logMessage",
"logMessage" => $item,
"postAuthor" => $postAuthor,
"topicAuthor" => $topicAuthor,
"topic" => $topic,
- ]);
+ ];
}
-}
-
-_view("view_topic_end");
-
-if ($topic->isLocked) {
- _view("view_topic_locked");
-} elseif ($currentUser) {
- _view("form_addpost");
-} else {
- _view("view_logintoreply");
-}
+}, $allItems);
-_view("template_end", [...getThemeAndLangInfo()]);
+render("view_topic.twig", [
+ "topic" => $topic,
+ "topicAuthor" => $topicAuthor,
+ "allItems" => &$allItems,
+]);
diff --git a/src/application/actions/viewuser/get.php b/src/application/actions/viewuser/get.php
index c98df16..e6dac43 100644
--- a/src/application/actions/viewuser/get.php
+++ b/src/application/actions/viewuser/get.php
@@ -17,18 +17,15 @@ foreach ($posts as $item) {
$attachs = $db->fetchCustom(Attachment::class, 'WHERE post_id = $1', [ $item->id ]);
$attachments[$item->id] = $attachs;
}
-_view("template_start", ["_title" => $user->displayName]);
-_view("template_navigation_start");
-_view("template_navigation", [
- "user" => $currentUser,
- "isViewingOwnProfile" => $isOwnProfile,
-]);
-_view("template_navigation_end");
-_view("view_user", [
+
+$dateJoined = DateTime::createFromImmutable($user->created);
+$dateJoined->setTime(0, 0, 0, 0);
+
+render("view_user.twig", [
"user" => $user,
"posts" => $posts,
"topics" => $topics,
"attachments" => $attachments,
"lastNameChangeTooRecent" => $lastNameChangeTooRecent,
+ "dateJoined" => $dateJoined,
]);
-_view("template_end", [...getThemeAndLangInfo()]);