diff --git a/public_html/dispatch.php b/public_html/dispatch.php
index 2d7808a4..4971299d 100644
--- a/public_html/dispatch.php
+++ b/public_html/dispatch.php
@@ -87,6 +87,9 @@ $postValidation =
\Chibi\Router::register(['PostController', 'favoritesView'], 'GET', '/favorites/{page}', $postValidation);
\Chibi\Router::register(['PostController', 'upvotedView'], 'GET', '/upvoted', $postValidation);
\Chibi\Router::register(['PostController', 'upvotedView'], 'GET', '/upvoted/{page}', $postValidation);
+
+\Chibi\Router::register(['PostController', 'genericView'], 'GET', '/post/{id}', $postValidation);
+
\Chibi\Router::register(['PostController', 'toggleTagAction'], 'POST', '/post/{id}/toggle-tag/{tag}/{enable}', $postValidation);
\Chibi\Router::register(['PostController', 'flagAction'], 'POST', '/post/{id}/flag', $postValidation);
\Chibi\Router::register(['PostController', 'hideAction'], 'POST', '/post/{id}/hide', $postValidation);
@@ -96,16 +99,21 @@ $postValidation =
\Chibi\Router::register(['PostController', 'scoreAction'], 'POST', '/post/{id}/score/{score}', $postValidation);
\Chibi\Router::register(['PostController', 'featureAction'], 'POST', '/post/{id}/feature', $postValidation);
-\Chibi\Router::register(['CommentController', 'listView'], 'GET', '/comments');
-\Chibi\Router::register(['CommentController', 'listView'], 'GET', '/comments/{page}', ['page' => '\d+']);
-\Chibi\Router::register(['CommentController', 'addAction'], 'POST', '/comment/add');
-\Chibi\Router::register(['CommentController', 'deleteAction'], 'POST', '/comment/{id}/delete', ['id' => '\d+']);
-\Chibi\Router::register(['CommentController', 'editView'], 'GET', '/comment/{id}/edit', ['id' => '\d+']);
-\Chibi\Router::register(['CommentController', 'editAction'], 'POST', '/comment/{id}/edit', ['id' => '\d+']);
+$commentValidation =
+[
+ 'id' => '\d+',
+ 'page' => '\d+',
+];
+
+\Chibi\Router::register(['CommentController', 'listView'], 'GET', '/comments', $commentValidation);
+\Chibi\Router::register(['CommentController', 'listView'], 'GET', '/comments/{page}', $commentValidation);
+\Chibi\Router::register(['CommentController', 'addAction'], 'POST', '/comment/add', $commentValidation);
+\Chibi\Router::register(['CommentController', 'deleteAction'], 'POST', '/comment/{id}/delete', $commentValidation);
+\Chibi\Router::register(['CommentController', 'editView'], 'GET', '/comment/{id}/edit', $commentValidation);
+\Chibi\Router::register(['CommentController', 'editAction'], 'POST', '/comment/{id}/edit', $commentValidation);
foreach (['GET', 'POST'] as $method)
{
- \Chibi\Router::register(['PostController', 'viewAction'], $method, '/post/{id}', $postValidation);
\Chibi\Router::register(['PostController', 'retrieveAction'], $method, '/post/{name}/retrieve', $postValidation);
\Chibi\Router::register(['PostController', 'thumbAction'], $method, '/post/{name}/thumb', $postValidation);
diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php
index 970ca611..ef4631bd 100644
--- a/src/Controllers/PostController.php
+++ b/src/Controllers/PostController.php
@@ -218,16 +218,13 @@ class PostController
FeaturePostJob::POST_ID => $id]);
}
- public function viewAction($id)
+ public function genericView($id)
{
$context = getContext();
- $post = PostModel::findByIdOrName($id);
- CommentModel::preloadCommenters($post->getComments());
+ $context->viewName = 'post-view';
- if ($post->hidden)
- Access::assert(Privilege::ViewPost, 'hidden');
- Access::assert(Privilege::ViewPost);
- Access::assert(Privilege::ViewPost, PostSafety::toString($post->safety));
+ $post = Api::run(new GetPostJob(), [
+ GetPostJob::POST_ID => $id]);
try
{
@@ -245,6 +242,8 @@ class PostController
$context->transport->lastSearchQuery, $id);
}
+ //todo:
+ //move these to PostEntity when implementing ApiController
$favorite = Auth::getCurrentUser()->hasFavorited($post);
$score = Auth::getCurrentUser()->getScore($post);
$flagged = in_array(TextHelper::reprPost($post), SessionHelper::get('flagged', []));
diff --git a/src/CustomMarkdown.php b/src/CustomMarkdown.php
index cda304be..4c83d451 100644
--- a/src/CustomMarkdown.php
+++ b/src/CustomMarkdown.php
@@ -127,7 +127,7 @@ class CustomMarkdown extends \Michelf\MarkdownExtra
protected function doPosts($text)
{
- $link = \Chibi\Router::linkTo(['PostController', 'viewAction'], ['id' => '_post_']);
+ $link = \Chibi\Router::linkTo(['PostController', 'genericView'], ['id' => '_post_']);
return preg_replace_callback('/(?:(?hashPart('' . $x[0] . '
');
diff --git a/src/Jobs/GetPostJob.php b/src/Jobs/GetPostJob.php
new file mode 100644
index 00000000..410f2088
--- /dev/null
+++ b/src/Jobs/GetPostJob.php
@@ -0,0 +1,34 @@
+post;
+
+ //todo: refactor this so that requiresPrivilege can accept multiple privileges
+ if ($this->post->hidden)
+ Access::assert(Privilege::ViewPost, 'hidden');
+ Access::assert(Privilege::ViewPost);
+ Access::assert(Privilege::ViewPost, PostSafety::toString($this->post->safety));
+
+ CommentModel::preloadCommenters($post->getComments());
+
+ return $post;
+ }
+
+ public function requiresPrivilege()
+ {
+ //temporarily enforced in execute
+ return false;
+ }
+
+ public function requiresAuthentication()
+ {
+ return false;
+ }
+
+ public function requiresConfirmedEmail()
+ {
+ return false;
+ }
+}
diff --git a/src/Views/comment-list.phtml b/src/Views/comment-list.phtml
index 508ab12a..5c8ce22e 100644
--- a/src/Views/comment-list.phtml
+++ b/src/Views/comment-list.phtml
@@ -32,7 +32,7 @@ Assets::setSubTitle('comments');
count($commentsToDisplay)): ?>
(more…)
diff --git a/src/Views/post-small.phtml b/src/Views/post-small.phtml
index 7492b57f..5ac83ce2 100644
--- a/src/Views/post-small.phtml
+++ b/src/Views/post-small.phtml
@@ -44,7 +44,7 @@ if ($masstag)
hasEnabledPostTagTitles()): ?>
title="= TextHelper::reprTags($this->context->post->getTags()) ?>"
- href="= \Chibi\Router::linkTo(['PostController', 'viewAction'], ['id' => $this->context->post->id]) ?>">
+ href="= \Chibi\Router::linkTo(['PostController', 'genericView'], ['id' => $this->context->post->id]) ?>">
0;