77use FullscreenInteractive \SilverStripe \Forum \Form \PostMessageForm ;
88use FullscreenInteractive \SilverStripe \Forum \Model \ForumThread ;
99use PageController ;
10+ use SilverStripe \Control \Controller ;
1011use SilverStripe \View \Requirements ;
1112use FullscreenInteractive \SilverStripe \Forum \Model \ForumThreadSubscription ;
1213use FullscreenInteractive \SilverStripe \Forum \Model \PostAttachment ;
@@ -34,6 +35,7 @@ class ForumController extends PageController
3435 'AdminFormFeatures ' ,
3536 'deleteAttachment ' ,
3637 'deletePost ' ,
38+ 'deletethread ' ,
3739 'editpost ' ,
3840 'markasspam ' ,
3941 'PostMessageForm ' ,
@@ -265,6 +267,7 @@ public function ban()
265267 return ($ request ->isAjax ()) ? true : $ this ->redirectBack ();
266268 }
267269
270+
268271 public function ghost ()
269272 {
270273 $ request = $ this ->getRequest ();
@@ -401,6 +404,7 @@ public function filterLanguage(string $content): string
401404 return $ content ;
402405 }
403406
407+
404408 /**
405409 * Get the link for the reply action
406410 *
@@ -411,6 +415,26 @@ public function ReplyLink()
411415 return self ::join_links ($ this ->Link (), 'reply ' , $ this ->urlParams ['ID ' ]);
412416 }
413417
418+
419+ public function reply ()
420+ {
421+ $ thread = $ this ->getForumThread ();
422+
423+ if (!$ thread ) {
424+ return $ this ->httpError (404 );
425+ }
426+
427+ $ form = $ this ->PostMessageForm ();
428+ $ form ->setThread ($ thread );
429+
430+ return [
431+ 'Thread ' => $ thread ,
432+ 'PostMessageForm ' => $ form ,
433+ 'Title ' => DBField::create_field ('HTMLText ' , _t ('Forum.REPLYTO ' , 'Replying to: %s ' , $ thread ->Title ))
434+ ];
435+ }
436+
437+
414438 /**
415439 * Show will get the selected thread to the user. Also increments the forums view count.
416440 */
@@ -576,12 +600,83 @@ public function deletePost()
576600 return $ this ->httpError (403 );
577601 }
578602
603+ $ thread = $ post ->Thread ();
579604 $ post ->delete ();
580605
606+ $ remainingPosts = Post::get ()->filter ('ThreadID ' , $ thread ->ID )->count ();
607+
608+ if ($ remainingPosts === 0 ) {
609+ $ thread ->delete ();
610+
611+ return $ this ->redirect ($ this ->Link ());
612+ }
613+
581614 return $ this ->redirectBack ();
582615 }
583616
584617
618+ /**
619+ * Delete an entire thread and all its posts.
620+ *
621+ * Requires moderator permissions and a valid security token.
622+ */
623+ public function deletethread ()
624+ {
625+ $ request = $ this ->getRequest ();
626+
627+ if (!SecurityToken::inst ()->checkRequest ($ request )) {
628+ return $ this ->httpError (400 );
629+ }
630+
631+ $ id = $ request ->param ('ID ' );
632+
633+ if (!$ id ) {
634+ return $ this ->httpError (400 );
635+ }
636+
637+ $ thread = ForumThread::get ()->byID ($ id );
638+
639+ if (!$ thread ) {
640+ return $ this ->httpError (404 );
641+ }
642+
643+ if (!$ thread ->canDelete ()) {
644+ return $ this ->httpError (403 );
645+ }
646+
647+ $ currentUser = Security::getCurrentUser ();
648+
649+ Injector::inst ()->get (LoggerInterface::class)->info (sprintf (
650+ 'Deleted thread "%s" (#%d), by moderator %s (#%d) ' ,
651+ $ thread ->Title ,
652+ $ thread ->ID ,
653+ $ currentUser ->Email ?? 'Unknown ' ,
654+ $ currentUser ->ID ?? 0
655+ ));
656+
657+ $ thread ->delete ();
658+
659+ return ($ request ->isAjax ()) ? true : $ this ->redirect ($ this ->Link ());
660+ }
661+
662+
663+ /**
664+ * Returns a tokenised URL for deleting the current thread, if the user can moderate.
665+ */
666+ public function DeleteThreadLink (): ?string
667+ {
668+ $ thread = $ this ->getForumThread ();
669+
670+ if (!$ thread || !$ thread ->canDelete ()) {
671+ return null ;
672+ }
673+
674+ $ url = Controller::join_links ($ this ->Link ('deletethread ' ), $ thread ->ID );
675+
676+ return SecurityToken::inst ()->addToUrl ($ url );
677+ }
678+
679+
585680 /**
586681 * Forum Admin Features form.
587682 * Handles the dropdown to select the new forum category and the checkbox for stickyness
0 commit comments