Update for new formatting API.

This commit is contained in:
Toby Zerner 2015-06-08 15:04:22 +09:30
parent b2557e2ae9
commit 0511982426
2 changed files with 20 additions and 19 deletions

View File

@ -1,6 +1,9 @@
<?php namespace Flarum\Mentions;
class PostMentionsFormatter
use Flarum\Core\Formatter\FormatterAbstract;
use Flarum\Core\Models\Post;
class PostMentionsFormatter extends FormatterAbstract
{
protected $parser;
@ -9,23 +12,16 @@ class PostMentionsFormatter
$this->parser = $parser;
}
public function format($text, $post = null)
public function afterPurification($text, Post $post = null)
{
if ($post) {
$text = $this->parser->replace($text, function ($match) use ($post) {
return '<a href="#/d/'.$post->discussion_id.'/-/'.$match['number'].'" class="mention-post" data-number="'.$match['number'].'">'.$match['username'].'</a>';
}, $text);
$text = $this->ignoreTags($text, ['a', 'code', 'pre'], function ($text) use ($post) {
return $this->parser->replace($text, function ($match) use ($post) {
return '<a href="#/d/'.$post->discussion_id.'/-/'.$match['number'].'" class="mention-post" data-number="'.$match['number'].'">'.$match['username'].'</a>';
}, $text);
});
}
return $text;
}
public function strip($text)
{
$text = $this->parser->replace($text, function () {
return ' ';
});
return $text;
}
}

View File

@ -1,6 +1,9 @@
<?php namespace Flarum\Mentions;
class UserMentionsFormatter
use Flarum\Core\Formatter\FormatterAbstract;
use Flarum\Core\Models\Post;
class UserMentionsFormatter extends FormatterAbstract
{
protected $parser;
@ -9,11 +12,13 @@ class UserMentionsFormatter
$this->parser = $parser;
}
public function format($text, $post = null)
public function afterPurification($text, Post $post = null)
{
$text = $this->parser->replace($text, function ($match) {
return '<a href="#/u/'.$match['username'].'" class="mention-user" data-user="'.$match['username'].'">'.$match['username'].'</a>';
}, $text);
$text = $this->ignoreTags($text, ['a', 'code', 'pre'], function ($text) {
return $this->parser->replace($text, function ($match) {
return '<a href="#/u/'.$match['username'].'" class="mention-user" data-user="'.$match['username'].'">'.$match['username'].'</a>';
}, $text);
});
return $text;
}