Merge remote-tracking branch 'refs/remotes/fguillot/master'

This commit is contained in:
Busfreak
2015-12-17 19:31:57 +01:00
11 changed files with 133 additions and 24 deletions

View File

@@ -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 * Display a form to create a new user
* *

View File

@@ -3,7 +3,7 @@
namespace Kanboard\Core; namespace Kanboard\Core;
use Parsedown; use Parsedown;
use Kanboard\Helper\Url; use Pimple\Container;
/** /**
* Specific Markdown rules for Kanboard * Specific Markdown rules for Kanboard
@@ -14,22 +14,51 @@ use Kanboard\Helper\Url;
*/ */
class Markdown extends Parsedown 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->link = $link;
$this->helper = $helper; $this->container = $container;
$this->InlineTypes['#'][] = 'TaskLink'; $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)) { 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['controller'],
$this->link['action'], $this->link['action'],
$this->link['params'] + array('task_id' => $matches[1]) $this->link['params'] + array('task_id' => $matches[1])
@@ -40,7 +69,38 @@ class Markdown extends Parsedown
'element' => array( 'element' => array(
'name' => 'a', 'name' => 'a',
'text' => $matches[0], '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'),
),
);
}
} }
} }
} }

View File

@@ -3,14 +3,15 @@
namespace Kanboard\Helper; namespace Kanboard\Helper;
use Kanboard\Core\Markdown; use Kanboard\Core\Markdown;
use Kanboard\Core\Base;
/** /**
* Text helpers * Text Helpers
* *
* @package helper * @package helper
* @author Frederic Guillot * @author Frederic Guillot
*/ */
class Text extends \Kanboard\Core\Base class Text extends Base
{ {
/** /**
* Markdown transformation * Markdown transformation
@@ -21,7 +22,7 @@ class Text extends \Kanboard\Core\Base
*/ */
public function markdown($text, array $link = array()) 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); $parser->setMarkupEscaped(MARKDOWN_ESCAPE_HTML);
return $parser->text($text); return $parser->text($text);
} }

View File

@@ -153,6 +153,7 @@ class RouteProvider implements ServiceProviderInterface
// Users // Users
$container['router']->addRoute('users', 'user', 'index'); $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', '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/timesheet', 'user', 'timesheet', array('user_id'));
$container['router']->addRoute('user/show/:user_id/last-logins', 'user', 'last', array('user_id')); $container['router']->addRoute('user/show/:user_id/last-logins', 'user', 'last', array('user_id'));

View 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>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -93,3 +93,13 @@
.documentation li { .documentation li {
line-height: 30px; line-height: 30px;
} }
.user-mention-link {
font-weight: bold;
color: #000;
text-decoration: none;
}
.user-mention-link:hover {
color: #555;
}

View File

@@ -13,7 +13,7 @@
"ext-gd" : "*", "ext-gd" : "*",
"christian-riesen/otp" : "1.4", "christian-riesen/otp" : "1.4",
"eluceo/ical": "0.8.0", "eluceo/ical": "0.8.0",
"erusev/parsedown" : "1.5.4", "erusev/parsedown" : "1.6.0",
"fabiang/xmpp" : "0.6.1", "fabiang/xmpp" : "0.6.1",
"fguillot/json-rpc" : "1.0.3", "fguillot/json-rpc" : "1.0.3",
"fguillot/picodb" : "1.0.3", "fguillot/picodb" : "1.0.3",

15
composer.lock generated
View File

@@ -1,10 +1,11 @@
{ {
"_readme": [ "_readme": [
"This file locks the dependencies of your project to a known state", "This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "e43ebd2c27f6d2afa51ae39f4bedc072", "hash": "a003844ed3fef854d64490d07064c66f",
"content-hash": "2189f3f4d11741a635dbd27a5750b71e",
"packages": [ "packages": [
{ {
"name": "christian-riesen/base32", "name": "christian-riesen/base32",
@@ -163,16 +164,16 @@
}, },
{ {
"name": "erusev/parsedown", "name": "erusev/parsedown",
"version": "1.5.4", "version": "1.6.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/erusev/parsedown.git", "url": "https://github.com/erusev/parsedown.git",
"reference": "0e89e3714bda18973184d30646306bb0a482bd96" "reference": "3ebbd730b5c2cf5ce78bc1bf64071407fc6674b7"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/erusev/parsedown/zipball/0e89e3714bda18973184d30646306bb0a482bd96", "url": "https://api.github.com/repos/erusev/parsedown/zipball/3ebbd730b5c2cf5ce78bc1bf64071407fc6674b7",
"reference": "0e89e3714bda18973184d30646306bb0a482bd96", "reference": "3ebbd730b5c2cf5ce78bc1bf64071407fc6674b7",
"shasum": "" "shasum": ""
}, },
"type": "library", "type": "library",
@@ -198,7 +199,7 @@
"markdown", "markdown",
"parser" "parser"
], ],
"time": "2015-08-03 09:24:05" "time": "2015-10-04 16:44:32"
}, },
{ {
"name": "fabiang/xmpp", "name": "fabiang/xmpp",

View File

@@ -6,7 +6,7 @@ use Kanboard\Helper\Text;
class TextHelperTest extends Base class TextHelperTest extends Base
{ {
public function testMarkdown() public function testMarkdownTaskLink()
{ {
$h = new Text($this->container); $h = new Text($this->container);
@@ -31,6 +31,12 @@ class TextHelperTest extends Base
); );
} }
public function testMarkdownUserLink()
{
$h = new Text($this->container);
$this->assertEquals('<p>Text <a href="?controller=user&amp;action=profile&amp;user_id=1" class="user-mention-link">@admin</a> @notfound</p>', $h->markdown('Text @admin @notfound'));
}
public function testFormatBytes() public function testFormatBytes()
{ {
$h = new Text($this->container); $h = new Text($this->container);