diff --git a/app/controllers/course/overview.php b/app/controllers/course/overview.php index 9246fe3aebcc7ad116af3af3a1ffd066799f70b2..3d209e6c652da6fa0ababeb13f9195474cce5596 100644 --- a/app/controllers/course/overview.php +++ b/app/controllers/course/overview.php @@ -55,7 +55,7 @@ class Course_OverviewController extends AuthenticatedController } // Fetch news - $response = $this->relay('news/display/' . $this->course_id); + $response = $this->relayWithRedirect('news/display/' . $this->course_id); $this->news = $response->body; // Fetch votes diff --git a/app/controllers/institute/overview.php b/app/controllers/institute/overview.php index 29b5fcac6b8ad416fdedb6078b9de2a4d27b19d1..38cf38111bfa35795b0d426558f6af992b76e37e 100644 --- a/app/controllers/institute/overview.php +++ b/app/controllers/institute/overview.php @@ -132,7 +132,7 @@ class Institute_OverviewController extends AuthenticatedController } // Fetch news - $response = $this->relay('news/display/' . $this->institute_id); + $response = $this->relayWithRedirect('news/display/' . $this->institute_id); $this->news = $response->body; // Fetch votes diff --git a/app/controllers/news.php b/app/controllers/news.php index a8d5237f1aeea57bf5cebf621d150fbcf6b90d74..e98704e3506b1023944d6cd865b5e371511f0932 100644 --- a/app/controllers/news.php +++ b/app/controllers/news.php @@ -59,7 +59,6 @@ class NewsController extends StudipController * Widget controller to produce the formally known show_votes() * * @param String $range_id range id of the news to get displayed - * @return array() Array of votes */ public function display_action($range_id) { @@ -81,11 +80,21 @@ class NewsController extends StudipController // Check if user wrote a comment if (Request::submitted('accept') && trim(Request::get('comment_content')) && Request::isPost()) { CSRFProtection::verifySecurityToken(); - StudipComment::create([ - 'object_id' => Request::get('comsubmit'), + + $news_id = Request::get('comsubmit'); + $comment = StudipComment::create([ + 'object_id' => $news_id, 'user_id' => $GLOBALS['user']->id, 'content' => trim(Request::get('comment_content')) ]); + + $url = URLHelper::getURL(Request::url() . "#newscomment-{$comment->id}", [ + 'contentbox_open' => $news_id, + 'comments' => true, + ]); + + $this->redirect($url); + return; } // Check if user wants to remove a announcement diff --git a/app/controllers/profile.php b/app/controllers/profile.php index cf9e1f51f61fa4c505d459423faef28d66154e04..c5a136f78bce1b1c25ba17081a31a2c65234edd1 100644 --- a/app/controllers/profile.php +++ b/app/controllers/profile.php @@ -116,7 +116,7 @@ class ProfileController extends AuthenticatedController $show_admin = ($this->perm->have_perm('autor') && $this->user->user_id == $this->current_user->user_id) || (Deputy::isEditActivated() && Deputy::isDeputy($this->user->user_id, $this->current_user->user_id, true)); if (Visibility::verify('news', $this->current_user->user_id) || $show_admin) { - $response = $this->relay('news/display/' . $this->current_user->user_id); + $response = $this->relayWithRedirect('news/display/' . $this->current_user->user_id); $this->news = $response->body; } diff --git a/app/controllers/studip_controller.php b/app/controllers/studip_controller.php index 45e0bc25476cb2dbfe44b40d76b2af046346c359..ffe04e3ad29b4542be5fd44b3257530b47fe52d1 100644 --- a/app/controllers/studip_controller.php +++ b/app/controllers/studip_controller.php @@ -534,6 +534,28 @@ abstract class StudipController extends Trails_Controller return call_user_func_array([$controller, 'perform_relayed'], $args); } + /** + * Relays current request and performs redirect if neccessary. + * + * @param string $to_uri a trails route + * @return Trails_Response + * + * @see StudipController::relay() + */ + public function relayWithRedirect(...$args): Trails_Response + { + $response = $this->relay(...$args); + + // If the relayed action should perform a redirect, do so + if (isset($response->headers['Location'])) { + header("Location: {$response->headers['Location']}"); + page_close(); + die; + } + + return $response; + } + /** * perform a given action/parameter string from an relayed request * before_filter and after_filter methods are not called diff --git a/app/views/news/_commentbox.php b/app/views/news/_commentbox.php index 87d4fadbd65bbf224902c4dd7e358f35f72229e0..3e3033a69ae5cbc9290f3721a05b2e2360e6607f 100644 --- a/app/views/news/_commentbox.php +++ b/app/views/news/_commentbox.php @@ -1,9 +1,9 @@ -<article class="comment open"> - <time><?= reltime($comment[3]) ?></time> +<article class="comment open" id="newscomment-<?= htmlReady($comment['comment_id']) ?>"> + <time><?= reltime($comment['mkdate']) ?></time> <h1>#<?= $index + 1 ?> - <a href="<?= URLHelper::getLink('dispatch.php/profile?username=' . $comment[2]) ?>"> - <?= htmlReady($comment[1]) ?> + <a href="<?= URLHelper::getLink('dispatch.php/profile', ['username' => $comment['username']]) ?>"> + <?= htmlReady($comment['fullname']) ?> </a> </h1> - <?= formatReady($comment[0]) ?> -</article> \ No newline at end of file + <?= formatReady($comment['content']) ?> +</article> diff --git a/public/plugins_packages/core/NewsWidget/NewsWidget.php b/public/plugins_packages/core/NewsWidget/NewsWidget.php index 8dd150bec88bdc928067099ca05d03cebf5e4e50..a2d8c3334af939044139af775455290afeb493d8 100644 --- a/public/plugins_packages/core/NewsWidget/NewsWidget.php +++ b/public/plugins_packages/core/NewsWidget/NewsWidget.php @@ -22,7 +22,7 @@ class NewsWidget extends StudIPPlugin implements PortalPlugin { $dispatcher = new StudipDispatcher(); $controller = new NewsController($dispatcher); - $response = $controller->relay('news/display/studip'); + $response = $controller->relayWithRedirect('news/display/studip'); $template = $GLOBALS['template_factory']->open('shared/string'); $template->content = $response->body;