readd live post quotes

This commit is contained in:
flash 2016-08-07 14:49:05 +02:00
parent 0446bc4f41
commit 9160013864

View file

@ -6,7 +6,11 @@
namespace Sakura\BBCode\Tags; namespace Sakura\BBCode\Tags;
use Sakura\ActiveUser;
use Sakura\BBCode\TagBase; use Sakura\BBCode\TagBase;
use Sakura\Forum\Forum;
use Sakura\Forum\Post;
use Sakura\Perms\Forum as ForumPerms;
/** /**
* Named quote tag. * Named quote tag.
@ -16,14 +20,33 @@ use Sakura\BBCode\TagBase;
class NamedQuote extends TagBase class NamedQuote extends TagBase
{ {
/** /**
* The pattern to match. * Parses the bbcode.
* @var string * @param string $text
* @return string
*/ */
public static $pattern = "/\[quote\=(.*?)\](.*)\[\/quote\]/s"; public static function parse($text)
{
return preg_replace_callback(
'/\[quote\=(#?)(.*?)\](.*)\[\/quote\]/s',
function ($matches) {
$quoting = $matches[2];
$content = $matches[3];
/** if ($matches[1] === '#') {
* The string to replace it with. $post = new Post(intval($matches[2]));
* @var string $forum = new Forum($post->forum);
*/
public static $replace = "<blockquote><small>$1</small>$2</blockquote>"; if ($post->id !== 0 && $forum->permission(ForumPerms::VIEW, ActiveUser::$user->id)) {
$link = route('forums.post', $post->id);
$quoting = "<a href='{$link}' style='color: {$post->poster->colour}'>{$post->poster->username}</a>";
$content = $post->parsed;
}
}
return "<blockquote><small>{$quoting}</small>{$content}</blockquote>";
},
$text
);
}
} }