*/ class Parser { /** * Holds the bbcode parsers. * @var array */ public static $parsers = [ // Basic markup Tags\Bold::class, Tags\Italics::class, Tags\Underline::class, Tags\Strike::class, Tags\Header::class, Tags\Image::class, Tags\Spoiler::class, // More advanced Tags\Colour::class, Tags\Align::class, Tags\Size::class, Tags\YouTube::class, // Links Tags\NamedLink::class, Tags\Link::class, // Quotes Tags\NamedQuote::class, Tags\Quote::class, // Advanced parsing Tags\Box::class, Tags\Code::class, Tags\ListTag::class, Tags\UserTag::class, Tags\Markdown::class, // Newline must always be last Tags\Newline::class, ]; /** * Parse the emoticons. * @param string $text * @param User $poster * @return string */ public static function parseEmoticons(string $text, User $poster = null): string { $emotes = DB::table('emoticons') ->get(); foreach ($emotes as $emote) { if ($poster === null) { // eventually check for hierarchies here continue; } $image = "{$emote->emote_string}"; $icon = preg_quote($emote->emote_string, '#'); $text = preg_replace("#{$icon}#", $image, $text); } return $text; } /** * Convert the parsed text to HTML. * @param string $text * @param User $poster * @return string */ public static function toHTML(string $text, User $poster): string { $text = self::parseEmoticons($text); foreach (self::$parsers as $parser) { $text = call_user_func_array([$parser, 'parse'], [$text, $poster]); } return $text; } }