/**
  * @param Question $question
  * @param bool $saveTagsInEntity
  */
 public function addForQuestion(Question $question, $saveTagsInEntity = true)
 {
     $em = $this->getEntityManager();
     if ($question instanceof PollPetition) {
         $tags = HashTagParser::parseHashTags($question->getPetitionBody());
     } else {
         $tags = HashTagParser::parseHashTags($question->getSubject());
     }
     foreach ($tags['parsed'] as $tag) {
         $entity = $this->findOneByName($tag);
         if (!$entity) {
             $entity = new HashTag($tag);
             $em->persist($entity);
         }
         $entity->addQuestion($question);
         $em->flush($entity);
     }
     if ($saveTagsInEntity) {
         $question->setCachedHashTags($tags['original']);
         $em->flush($question);
     }
 }
 public function handleCommentContent(BaseComment $comment)
 {
     $content = $this->escape($comment->getCommentBody());
     $replacements = [];
     $users = [];
     $mentions = Tags::parseMentionTags($content);
     foreach ($mentions as $username) {
         $tag = '@' . $username;
         if (!isset($replacements[$tag])) {
             $user = $this->userRepo->findOneByUsername($username);
             if ($user) {
                 $users[$username] = $user;
                 $replacements[$tag] = "<a data-user-id=\"{$user->getId()}\">{$tag}</a>";
             }
         }
     }
     $content = UrlConverter::wrapLinks($content);
     $content = Tags::replaceMentionTags($content, $replacements);
     $content = Tags::wrapHashTags($content);
     $comment->setCommentBodyHtml($content);
     return $users;
 }
Example #3
0
 /**
  * @group parser
  */
 public function testWrapHashTags()
 {
     $this->assertEquals('<a data-hashtag="#powerline">#powerline</a>', Tags::wrapHashTags('#powerline'));
     $this->assertEquals('<a data-hashtag="#powerline">#powerline</a> <a data-hashtag="#politics">#politics</a>', Tags::wrapHashTags('#powerline #politics'));
     $this->assertEquals('<a data-hashtag="#powerline">#powerline</a>.', Tags::wrapHashTags('#powerline.'));
 }