Show profile link for @username mentions
This commit is contained in:
@@ -57,6 +57,28 @@ class User extends Base
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Public user profile
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function profile()
|
||||
{
|
||||
$user = $this->user->getById($this->request->getIntegerParam('user_id'));
|
||||
|
||||
if (empty($user)) {
|
||||
$this->notfound();
|
||||
}
|
||||
|
||||
$this->response->html(
|
||||
$this->template->layout('user/profile', array(
|
||||
'board_selector' => $this->projectUserRole->getProjectsByUser($this->userSession->getId()),
|
||||
'title' => $user['name'] ?: $user['username'],
|
||||
'user' => $user,
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a form to create a new user
|
||||
*
|
||||
|
||||
@@ -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'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,15 @@
|
||||
namespace Kanboard\Helper;
|
||||
|
||||
use Kanboard\Core\Markdown;
|
||||
use Kanboard\Core\Base;
|
||||
|
||||
/**
|
||||
* Text helpers
|
||||
* Text Helpers
|
||||
*
|
||||
* @package helper
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Text extends \Kanboard\Core\Base
|
||||
class Text extends Base
|
||||
{
|
||||
/**
|
||||
* Markdown transformation
|
||||
@@ -21,7 +22,7 @@ class Text extends \Kanboard\Core\Base
|
||||
*/
|
||||
public function markdown($text, array $link = array())
|
||||
{
|
||||
$parser = new Markdown($link, $this->helper->url);
|
||||
$parser = new Markdown($this->container, $link);
|
||||
$parser->setMarkupEscaped(MARKDOWN_ESCAPE_HTML);
|
||||
return $parser->text($text);
|
||||
}
|
||||
|
||||
@@ -153,6 +153,7 @@ class RouteProvider implements ServiceProviderInterface
|
||||
|
||||
// Users
|
||||
$container['router']->addRoute('users', 'user', 'index');
|
||||
$container['router']->addRoute('user/profile/:user_id', 'user', 'profile', array('user_id'));
|
||||
$container['router']->addRoute('user/show/:user_id', 'user', 'show', array('user_id'));
|
||||
$container['router']->addRoute('user/show/:user_id/timesheet', 'user', 'timesheet', array('user_id'));
|
||||
$container['router']->addRoute('user/show/:user_id/last-logins', 'user', 'last', array('user_id'));
|
||||
|
||||
8
app/Template/user/profile.php
Normal file
8
app/Template/user/profile.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<section id="main">
|
||||
<br>
|
||||
<ul class="listing">
|
||||
<li><?= t('Username:') ?> <strong><?= $this->e($user['username']) ?></strong></li>
|
||||
<li><?= t('Name:') ?> <strong><?= $this->e($user['name']) ?: t('None') ?></strong></li>
|
||||
<li><?= t('Email:') ?> <strong><?= $this->e($user['email']) ?: t('None') ?></strong></li>
|
||||
</ul>
|
||||
</section>
|
||||
Reference in New Issue
Block a user