/**
  * @group parser
  */
 public function testWrapLinks()
 {
     $this->assertEquals('<a href="www.powerli.ne" target="_blank">www.powerli.ne</a>', UrlConverter::wrapLinks('www.powerli.ne'));
     $this->assertEquals('<a href="www.powerli.ne" target="_blank">www.powerli.ne</a>.', UrlConverter::wrapLinks('www.powerli.ne.'));
     $this->assertEquals('<a href="http://powerli.ne" target="_blank">http://powerli.ne</a>', UrlConverter::wrapLinks('http://powerli.ne'));
     $this->assertEquals('<a href="https://powerli.ne" target="_blank">https://powerli.ne</a>', UrlConverter::wrapLinks('https://powerli.ne'));
     $this->assertEquals('check <a href="https://powerli.ne" target="_blank">https://powerli.ne</a>', UrlConverter::wrapLinks('check https://powerli.ne'));
     $this->assertEquals('<a href="powerli.ne/petitions/322" target="_blank">powerli.ne/petitions/322</a> @powerline', UrlConverter::wrapLinks('powerli.ne/petitions/322 @powerline'));
     $this->assertEquals('@mobile1.mobile should not be a link', UrlConverter::wrapLinks('@mobile1.mobile should not be a link'));
     $this->assertEquals('@powerli.ne should not be a link', UrlConverter::wrapLinks('@powerli.ne should not be a link'));
     $this->assertEquals('#powerli.ne should not be a link', UrlConverter::wrapLinks('#powerli.ne should not be a link'));
 }
 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
 /**
  * @param string $subject
  * @return $this
  */
 public function setSubject($subject)
 {
     parent::setSubject($subject);
     $this->setSubjectParsed(\Civix\CoreBundle\Parser\UrlConverter::convert($subject));
     return $this;
 }
 /**
  * Set content
  *
  * @param string $content
  * @return Announcement
  */
 public function setContent($content)
 {
     $this->content = $content;
     $this->setContentParsed(\Civix\CoreBundle\Parser\UrlConverter::convert($content));
     return $this;
 }