Show profile link for @username mentions
This commit is contained in:
@@ -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'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user