From 91600138649b8e9da42b93223079d1ffbe6b2607 Mon Sep 17 00:00:00 2001 From: flashwave Date: Sun, 7 Aug 2016 14:49:05 +0200 Subject: [PATCH] readd live post quotes --- app/BBCode/Tags/NamedQuote.php | 39 +++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/app/BBCode/Tags/NamedQuote.php b/app/BBCode/Tags/NamedQuote.php index 7082818..6caf514 100644 --- a/app/BBCode/Tags/NamedQuote.php +++ b/app/BBCode/Tags/NamedQuote.php @@ -6,7 +6,11 @@ namespace Sakura\BBCode\Tags; +use Sakura\ActiveUser; use Sakura\BBCode\TagBase; +use Sakura\Forum\Forum; +use Sakura\Forum\Post; +use Sakura\Perms\Forum as ForumPerms; /** * Named quote tag. @@ -16,14 +20,33 @@ use Sakura\BBCode\TagBase; class NamedQuote extends TagBase { /** - * The pattern to match. - * @var string + * Parses the bbcode. + * @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]; - /** - * The string to replace it with. - * @var string - */ - public static $replace = "
$1$2
"; + if ($matches[1] === '#') { + $post = new Post(intval($matches[2])); + $forum = new Forum($post->forum); + + if ($post->id !== 0 && $forum->permission(ForumPerms::VIEW, ActiveUser::$user->id)) { + $link = route('forums.post', $post->id); + + $quoting = "{$post->poster->username}"; + $content = $post->parsed; + } + } + + return "
{$quoting}{$content}
"; + }, + $text + ); + } }