| <?php |
|
|
| namespace Kanboard\Core; |
|
|
| use Parsedown; |
| use Pimple\Container; |
|
|
| |
| |
| |
| |
| |
| |
| |
| class Markdown extends Parsedown |
| { |
| |
| |
| |
| |
| |
| |
| private $isPublicLink = false; |
|
|
| |
| |
| |
| |
| |
| |
| private $container; |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function __construct(Container $container, $isPublicLink) |
| { |
| $this->isPublicLink = $isPublicLink; |
| $this->container = $container; |
| $this->BlockTypes['#'][0] = 'CustomHeader'; |
| $this->InlineTypes['#'][] = 'TaskLink'; |
| $this->InlineTypes['@'][] = 'UserLink'; |
| $this->inlineMarkerList .= '#@'; |
| } |
|
|
| protected function blockCustomHeader($Line) |
| { |
| if (preg_match('!#(\d+)!i', $Line['text'], $matches)) |
| { |
| $link = $this->buildTaskLink($matches[1]); |
|
|
| if (! empty($link)) { |
| return [ |
| 'extent' => strlen($matches[0]), |
| 'element' => [ |
| 'name' => 'a', |
| 'text' => $matches[0], |
| 'attributes' => ['href' => $link], |
| ], |
| ]; |
| } |
| } |
|
|
| return $this->blockHeader($Line); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| protected function inlineTaskLink(array $Excerpt) |
| { |
| if (preg_match('!#(\d+)!i', $Excerpt['text'], $matches)) { |
| $link = $this->buildTaskLink($matches[1]); |
|
|
| if (! empty($link)) { |
| return array( |
| 'extent' => strlen($matches[0]), |
| 'element' => array( |
| 'name' => 'a', |
| 'text' => $matches[0], |
| 'attributes' => array('href' => $link), |
| ), |
| ); |
| } |
| } |
|
|
| return null; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| protected function inlineUserLink(array $Excerpt) |
| { |
| if (! $this->isPublicLink && preg_match('/^@([^\s,!:?]+)/', $Excerpt['text'], $matches)) { |
| $username = rtrim($matches[1], '.'); |
| $user = $this->container['userCacheDecorator']->getByUsername($username); |
|
|
| if (! empty($user)) { |
| $url = $this->container['helper']->url->to('UserViewController', 'profile', array('user_id' => $user['id'])); |
| $name = $user['name'] ?: $user['username']; |
|
|
| return array( |
| 'extent' => strlen($username) + 1, |
| 'element' => array( |
| 'name' => 'a', |
| 'text' => '@' . $username, |
| 'attributes' => array( |
| 'href' => $url, |
| 'class' => 'user-mention-link', |
| 'title' => $name, |
| 'aria-label' => $name, |
| ), |
| ), |
| ); |
| } |
| } |
|
|
| return null; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| private function buildTaskLink($task_id) |
| { |
| if ($this->isPublicLink) { |
| $token = $this->container['memoryCache']->proxy($this->container['taskFinderModel'], 'getProjectToken', $task_id); |
|
|
| if (! empty($token)) { |
| return $this->container['helper']->url->to( |
| 'TaskViewController', |
| 'readonly', |
| array( |
| 'token' => $token, |
| 'task_id' => $task_id, |
| ), |
| '', |
| true |
| ); |
| } |
|
|
| return ''; |
| } |
|
|
| return $this->container['helper']->url->to( |
| 'TaskViewController', |
| 'show', |
| array('task_id' => $task_id) |
| ); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| protected function inlineLink($Excerpt) |
| { |
| $Inline = parent::inlineLink($Excerpt); |
| if (is_array($Inline)) { |
| array_push($Inline['element']['nonNestables'], 'TaskLink', 'UserLink'); |
| } |
| return $Inline; |
| } |
| } |
|
|