Example #1
0
 /**
  * Get the abstract of a post, which has been parsed
  * @param int $length
  * @param string $truncationIndicator
  * @return string
  */
 public function getAbstract($length = 500, $truncationIndicator = '...')
 {
     return PostHelper::safeShorten(PostHelper::parseBBCode($this->contents), $length, $truncationIndicator);
 }
 /**
  * Get comment which has been parsed
  * @return string
  */
 public function getComment()
 {
     return PostHelper::parseBBCode($this->comment);
 }
 /**
  * Get contents which has been parsed
  * @return string
  */
 public function getContents()
 {
     return PostHelper::parseBBCode($this->contents);
 }
 /**
  * @Route("/preview", name="_an_blog_preview")
  * @Method({"POST"})
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response|static
  */
 public function previewPostAction(Request $request)
 {
     $comment = new Comment();
     $commentForm = $this->createForm(new CommentType(), $comment);
     $commentForm->handleRequest($request);
     $errors = [];
     $error = $commentForm->getErrors(true);
     if (count($error) > 0) {
         foreach ($error as $err) {
             $field = $err->getOrigin()->getName();
             if ($field === 'name') {
                 continue;
             }
             $errors[$field][] = $err->getMessage();
         }
     }
     if (count($errors) > 0) {
         return JsonResponse::create(['parsed' => null, 'errors' => $errors]);
     }
     return JsonResponse::create(['parsed' => PostHelper::parseBBCode($comment->getComment())]);
 }