Пример #1
0
 /**
  * @group parser
  */
 public function testReplaceMentionTags()
 {
     $replacements = ['@tom' => '<a>@tom</a>', '@alice21' => '<a>@alice21</a>', '@alice' => '<a>@alice</a>', '@alice2' => '<a>@alice2</a>', '@1.JesseChen' => '<a>@1.JesseChen</a>', '@mobile1.mobile' => '<a>@mobile1.mobile</a>'];
     $this->assertEquals('<a>@tom</a>.', Tags::replaceMentionTags('@tom.', $replacements));
     $this->assertEquals('<a>@alice21</a> is not <a>@alice2</a>', Tags::replaceMentionTags('@alice21 is not @alice2', $replacements));
     $this->assertEquals('@unregistered cannot be replaced', Tags::replaceMentionTags('@unregistered cannot be replaced', $replacements));
     $this->assertEquals('<a>@tom</a>', Tags::replaceMentionTags('<a>@tom</a>', $replacements));
     $this->assertEquals('<a>@1.JesseChen</a>', Tags::replaceMentionTags('@1.JesseChen', $replacements));
     $this->assertEquals('<a>@mobile1.mobile</a> ', Tags::replaceMentionTags('@mobile1.mobile ', $replacements));
 }
Пример #2
0
 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;
 }