diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-12-15 22:39:39 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-12-15 22:39:39 -0500 |
commit | 7f980cffcc3a20f5c93e128313c1a4a47b39dc8e (patch) | |
tree | a1fdbee2ecc6026c192126db8be78db45e22b80b /app/Core/Markdown.php | |
parent | 9e1f4fa6c7eae1b46cf5431ab085b82e970e2d57 (diff) |
Show profile link for @username mentions
Diffstat (limited to 'app/Core/Markdown.php')
-rw-r--r-- | app/Core/Markdown.php | 80 |
1 files changed, 70 insertions, 10 deletions
diff --git a/app/Core/Markdown.php b/app/Core/Markdown.php index f08c486a..827fd0df 100644 --- a/app/Core/Markdown.php +++ b/app/Core/Markdown.php @@ -3,7 +3,7 @@ namespace Kanboard\Core; use Parsedown; -use Kanboard\Helper\Url; +use Pimple\Container; /** * Specific Markdown rules for Kanboard @@ -14,22 +14,51 @@ use Kanboard\Helper\Url; */ class Markdown extends Parsedown { - private $link; - private $helper; + /** + * Link params for tasks + * + * @access private + * @var array + */ + private $link = array(); - public function __construct($link, Url $helper) + /** + * Container + * + * @access private + * @var Container + */ + private $container; + + /** + * Constructor + * + * @access public + * @param Container $container + * @param array $link + */ + public function __construct(Container $container, array $link) { $this->link = $link; - $this->helper = $helper; + $this->container = $container; $this->InlineTypes['#'][] = 'TaskLink'; - $this->inlineMarkerList .= '#'; + $this->InlineTypes['@'][] = 'UserLink'; + $this->inlineMarkerList .= '#@'; } - protected function inlineTaskLink($Excerpt) + /** + * Handle Task Links + * + * Replace "#123" by a link to the task + * + * @access public + * @param array $Excerpt + * @return array + */ + protected function inlineTaskLink(array $Excerpt) { - // Replace task #123 by a link to the task if (! empty($this->link) && preg_match('!#(\d+)!i', $Excerpt['text'], $matches)) { - $url = $this->helper->href( + $url = $this->container['helper']->url->href( $this->link['controller'], $this->link['action'], $this->link['params'] + array('task_id' => $matches[1]) @@ -40,7 +69,38 @@ class Markdown extends Parsedown 'element' => array( 'name' => 'a', 'text' => $matches[0], - 'attributes' => array('href' => $url))); + 'attributes' => array('href' => $url) + ), + ); + } + } + + /** + * Handle User Mentions + * + * Replace "@username" by a link to the user + * + * @access public + * @param array $Excerpt + * @return array + */ + protected function inlineUserLink(array $Excerpt) + { + if (preg_match('/^@([^\s]+)/', $Excerpt['text'], $matches)) { + $user_id = $this->container['user']->getIdByUsername($matches[1]); + + if (! empty($user_id)) { + $url = $this->container['helper']->url->href('user', 'profile', array('user_id' => $user_id)); + + return array( + 'extent' => strlen($matches[0]), + 'element' => array( + 'name' => 'a', + 'text' => $matches[0], + 'attributes' => array('href' => $url, 'class' => 'user-mention-link'), + ), + ); + } } } } |