diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-12-17 12:11:17 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-12-17 12:11:17 -0500 |
commit | aafa1de4d56b0791c4d367aa530587082c833faf (patch) | |
tree | 46fce88a2d1a6119973ae8cffb741d06e7e6ac43 /app | |
parent | b6ea1ac9a4cfe4b56a9e226f6087945f01fc57b8 (diff) |
Handle username with dots in user mentions
Diffstat (limited to 'app')
-rw-r--r-- | app/Core/Markdown.php | 21 | ||||
-rw-r--r-- | app/Job/UserMentionJob.php | 3 |
2 files changed, 15 insertions, 9 deletions
diff --git a/app/Core/Markdown.php b/app/Core/Markdown.php index 799aefb4..5d723bad 100644 --- a/app/Core/Markdown.php +++ b/app/Core/Markdown.php @@ -86,18 +86,23 @@ class Markdown extends Parsedown */ protected function inlineUserLink(array $Excerpt) { - if (! $this->isPublicLink && preg_match('/^@([^\s,!.:?]+)/', $Excerpt['text'], $matches)) { - $user_id = $this->container['userModel']->getIdByUsername($matches[1]); + if (! $this->isPublicLink && preg_match('/^@([^\s,!:?]+)/', $Excerpt['text'], $matches)) { + $username = rtrim($matches[1], '.'); + $user = $this->container['userModel']->getByUsername($username); - if (! empty($user_id)) { - $url = $this->container['helper']->url->href('UserViewController', 'profile', array('user_id' => $user_id)); + if (! empty($user)) { + $url = $this->container['helper']->url->href('UserViewController', 'profile', array('user_id' => $user['id'])); return array( - 'extent' => strlen($matches[0]), + 'extent' => strlen($username) + 1, 'element' => array( - 'name' => 'a', - 'text' => $matches[0], - 'attributes' => array('href' => $url, 'class' => 'user-mention-link'), + 'name' => 'a', + 'text' => '@' . $username, + 'attributes' => array( + 'href' => $url, + 'class' => 'user-mention-link', + 'title' => $user['name'] ?: $user['username'], + ), ), ); } diff --git a/app/Job/UserMentionJob.php b/app/Job/UserMentionJob.php index bbb27131..355095bb 100644 --- a/app/Job/UserMentionJob.php +++ b/app/Job/UserMentionJob.php @@ -58,7 +58,8 @@ class UserMentionJob extends BaseJob { $users = array(); - if (preg_match_all('/@([^\s,!.:?]+)/', $text, $matches)) { + if (preg_match_all('/@([^\s,!:?]+)/', $text, $matches)) { + array_walk($matches[1], function (&$username) { $username = rtrim($username, '.'); }); $users = $this->db->table(UserModel::TABLE) ->columns('id', 'username', 'name', 'email', 'language') ->eq('notifications_enabled', 1) |