mirror of
https://github.com/flarum/framework.git
synced 2025-04-25 06:04:04 +08:00
Update for new formatting API.
This commit is contained in:
parent
b2557e2ae9
commit
0511982426
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user