/**
  * Callback function for rendering quotes.
  *
  * @param string $matches PCRE matches.
  * @return string  The quote content.
  */
 protected function replaceCallback($matches)
 {
     $this->view->setControllerContext($this->controllerContext);
     $this->view->setTemplatePathAndFilename(File::replaceSiteRelPath($this->settings['template']));
     $tmp = $this->postRepository->findByUid((int) $matches[1]);
     if (!empty($tmp)) {
         $this->view->assign('post', $tmp);
     }
     $this->view->assign('quote', trim($matches[2]));
     return $this->view->render();
 }
 /**
  * Delete a topic from repository!
  *
  * @param Topic $topic The topic that is be deleted.
  *
  * @return void
  */
 public function topicConformDeleteAction(Topic $topic)
 {
     $this->authenticationService->assertModerationAuthorization($topic->getForum());
     foreach ($topic->getPosts() as $post) {
         $this->postRepository->remove($post);
     }
     $this->topicRepository->remove($topic);
     $this->controllerContext->getFlashMessageQueue()->enqueue(new FlashMessage(Localization::translate('Moderation_DeleteTopic_Success', 'Typo3Forum')));
     $this->clearCacheForCurrentPage();
     $this->redirect('show', 'Forum', NULL, array('forum' => $topic->getForum()));
 }
 /**
  * Show action. Displays a single topic and all posts contained in this topic.
  *
  * @param Topic $topic The topic that is to be displayed.
  * @param Post $quote An optional post that will be quoted within the bodytext of the new post.
  * @param int $showForm ShowForm
  */
 public function showAction(Topic $topic, Post $quote = NULL, $showForm = 0)
 {
     $posts = $this->postRepository->findForTopic($topic);
     if ($quote != FALSE) {
         $this->view->assign('quote', $this->postFactory->createPostWithQuote($quote));
     }
     // Set Title
     $GLOBALS['TSFE']->page['title'] = $topic->getTitle();
     $googlePlus = $topic->getAuthor()->getGoogle();
     if ($googlePlus) {
         $this->response->addAdditionalHeaderData('<link rel="author" href="' . $googlePlus . '"/>');
     }
     // AdHandling End
     $this->authenticationService->assertReadAuthorization($topic);
     $this->markTopicRead($topic);
     $this->view->assignMultiple(['posts' => $posts, 'showForm' => $showForm, 'topic' => $topic, 'user' => $this->authenticationService->getUser()]);
 }
 /**
  * Updates a post.
  *
  * @param Post $post The post that is to be updated.
  * @param array $attachments File attachments for the post.
  *
  * @return void
  */
 public function updateAction(Post $post, array $attachments = array())
 {
     if ($post->getAuthor() != $this->authenticationService->getUser() || $post->getTopic()->getLastPost()->getAuthor() != $post->getAuthor()) {
         // Assert authorization
         $this->authenticationService->assertModerationAuthorization($post->getTopic()->getForum());
     }
     if (!empty($attachments)) {
         $attachments = $this->attachmentService->initAttachments($attachments);
         foreach ($attachments as $attachment) {
             $post->addAttachments($attachment);
         }
     }
     $this->postRepository->update($post);
     $this->signalSlotDispatcher->dispatch('Mittwald\\Typo3Forum\\Domain\\Model\\Forum\\Post', 'postUpdated', array('post' => $post));
     $this->controllerContext->getFlashMessageQueue()->enqueue(new FlashMessage(Localization::translate('Post_Update_Success')));
     $this->clearCacheForCurrentPage();
     $this->redirect('show', 'Topic', NULL, array('topic' => $post->getTopic()));
 }
 /**
  * @param string $displayedPosts
  * @return array
  */
 private function _getPosts($displayedPosts)
 {
     $data = array();
     $displayedPosts = json_decode($displayedPosts);
     if (count($displayedPosts) < 1) {
         return $data;
     }
     $this->request->setFormat('html');
     $posts = $this->postRepository->findByUids($displayedPosts);
     $counter = 0;
     foreach ($posts as $post) {
         /** @var Post $post */
         $this->view->assign('post', $post)->assign('user', $this->getCurrentUser());
         $data[$counter]['uid'] = $post->getUid();
         $data[$counter]['postHelpfulButton'] = $this->view->render('PostHelpfulButton');
         $data[$counter]['postHelpfulCount'] = $post->getHelpfulCount();
         $data[$counter]['postUserHelpfulCount'] = $post->getAuthor()->getHelpfulCount();
         $data[$counter]['author']['uid'] = $post->getAuthor()->getUid();
         $data[$counter]['postEditLink'] = $this->view->render('PostEditLink');
         $counter++;
     }
     $this->request->setFormat('json');
     return $data;
 }