diff --git a/app/BbCode/KnockoutDefinitionSet.php b/app/BbCode/KnockoutDefinitionSet.php deleted file mode 100644 index efb6f44..0000000 --- a/app/BbCode/KnockoutDefinitionSet.php +++ /dev/null @@ -1,68 +0,0 @@ -{param}'); - $this->definitions[] = $builder->build(); - - /* [i] italics tag */ - $builder = new CodeDefinitionBuilder('i', '{param}'); - $this->definitions[] = $builder->build(); - - /* [u] underline tag */ - $builder = new CodeDefinitionBuilder('u', '{param}'); - $this->definitions[] = $builder->build(); - - $urlValidator = new \JBBCode\validators\UrlValidator(); - - /* [url] link tag */ - $builder = new CodeDefinitionBuilder('url', '{param}'); - $builder->setParseContent(false)->setBodyValidator($urlValidator); - $this->definitions[] = $builder->build(); - - /* [url=http://example.com] link tag */ - $builder = new CodeDefinitionBuilder('url', '{param}'); - $builder->setUseOption(true)->setParseContent(true)->setOptionValidator($urlValidator); - $this->definitions[] = $builder->build(); - - /* [img] image tag */ - $builder = new CodeDefinitionBuilder('img', ''); - $builder->setUseOption(false)->setParseContent(false)->setBodyValidator($urlValidator); - $this->definitions[] = $builder->build(); - - /* [img=alt text] image tag */ - $builder = new CodeDefinitionBuilder('img', '{option}'); - $builder->setUseOption(true)->setParseContent(false)->setBodyValidator($urlValidator); - $this->definitions[] = $builder->build(); - - /* [color] color tag */ - $builder = new CodeDefinitionBuilder('color', '{param}'); - $builder->setUseOption(true)->setOptionValidator(new \JBBCode\validators\CssColorValidator()); - $this->definitions[] = $builder->build(); - } - - /** - * Returns an array of the default code definitions. - * - * @return CodeDefinition[] - */ - public function getCodeDefinitions() - { - return $this->definitions; - } -} diff --git a/app/BbCode/Tag/Bold.php b/app/BbCode/Tag/Bold.php deleted file mode 100644 index c5c8018..0000000 --- a/app/BbCode/Tag/Bold.php +++ /dev/null @@ -1,24 +0,0 @@ -'; - } - - public function getOpenHtmlTag(): string - { - return ''; - } - - public function getTag() : string - { - return 'b'; - } -} diff --git a/app/BbCode/Tag/Image.php b/app/BbCode/Tag/Image.php deleted file mode 100644 index 4a1a7e7..0000000 --- a/app/BbCode/Tag/Image.php +++ /dev/null @@ -1,31 +0,0 @@ -getText(); - if (!preg_match('!^https?://[a-z0-9\-@:.,_&+%#?/=]+$!i', $link)) { - $unknownTag = new Unknown(); - return $unknownTag->format($tokenTag); - } - - return ''; - } - - public function getName(): string - { - return 'img'; - } - - public function getOriginalText(TokenTag $tokenTag): string - { - return "[{$this->getName()}]{$tokenTag->getText()}[/{$this->getName()}"; - } -} diff --git a/app/BbCode/Tag/Italic.php b/app/BbCode/Tag/Italic.php deleted file mode 100644 index f2fb70f..0000000 --- a/app/BbCode/Tag/Italic.php +++ /dev/null @@ -1,24 +0,0 @@ -'; - } - - public function getOpenHtmlTag(): string - { - return ''; - } - - public function getTag() : string - { - return 'i'; - } -} diff --git a/app/BbCode/Tag/Link.php b/app/BbCode/Tag/Link.php deleted file mode 100644 index df78624..0000000 --- a/app/BbCode/Tag/Link.php +++ /dev/null @@ -1,35 +0,0 @@ -parseArgument(); - $url = $args['href'] ?? null; - - if (!preg_match(self::REG_EXP_VALID_URL, $url)) { - $simpleTag = new Unknown(); - return $simpleTag->format($tokenTag); - } - - return "{$tokenTag->getText()}"; - } - - public function getName(): string - { - return 'url'; - } - - public function getOriginalText(TokenTag $tokenTag) : string - { - return "[url={$tokenTag->getArgument()}]{$tokenTag->getText()}[/url]"; - } -} diff --git a/app/BbCode/Tag/Quote.php b/app/BbCode/Tag/Quote.php index 41aa330..b25f19d 100644 --- a/app/BbCode/Tag/Quote.php +++ b/app/BbCode/Tag/Quote.php @@ -2,31 +2,41 @@ namespace App\BbCode\Tag; -use Knockout\BbCode\Tag\TagInterface; -use Knockout\BbCode\Tokenizer\Tag as TokenTag; +use JBBCode\CodeDefinition; +use JBBCode\ElementNode; -class Quote implements TagInterface +class Quote extends CodeDefinition { - public function format(TokenTag $tokenTag): string + public function __construct() { - $attrs = $tokenTag->parseArgument(); - return view('partial/bbcode/quote', [ - 'thread' => $attrs->threadId ?? 1, - 'page' => $attrs->threadPage ?? 1, - 'postId' => $attrs->postId ?? 1, - 'username' => $attrs->username ?? 'Unknown', - 'content' => $tokenTag->getText() - ]); + parent::__construct('quote', null, true); } - public function getName(): string + public function asHtml(ElementNode $e) { - return 'quote'; + return 'lol'; } - public function getOriginalText(TokenTag $tokenTag): string - { - return "[{$this->getName()}]{$tokenTag->getText()}[/{$this->getName()}"; - } + // public function format(TokenTag $tokenTag): string + // { + // $attrs = $tokenTag->parseArgument(); + // return view('partial/bbcode/quote', [ + // 'thread' => $attrs->threadId ?? 1, + // 'page' => $attrs->threadPage ?? 1, + // 'postId' => $attrs->postId ?? 1, + // 'username' => $attrs->username ?? 'Unknown', + // 'content' => $tokenTag->getText() + // ]); + // } + + // public function getName(): string + // { + // return 'quote'; + // } + + // public function getOriginalText(TokenTag $tokenTag): string + // { + // return "[{$this->getName()}]{$tokenTag->getText()}[/{$this->getName()}"; + // } } diff --git a/app/BbCode/Tag/Underline.php b/app/BbCode/Tag/Underline.php deleted file mode 100644 index c012857..0000000 --- a/app/BbCode/Tag/Underline.php +++ /dev/null @@ -1,24 +0,0 @@ -'; - } - - public function getOpenHtmlTag(): string - { - return ''; - } - - public function getTag() : string - { - return 'u'; - } -} diff --git a/app/Helper/BBCode.php b/app/Helper/BBCode.php index b2f1f5d..ad3735a 100644 --- a/app/Helper/BBCode.php +++ b/app/Helper/BBCode.php @@ -4,22 +4,19 @@ namespace App\Helper; use App\BbCode\KnockoutDefinitionSet; -use JBBCode\Parser; class BBCode { - private $parser; + private $content; public function __construct($content) { - $this->parser = new Parser(); - $this->parser->addCodeDefinitionSet(new KnockoutDefinitionSet()); - $this->parser->parse($content); + $this->content = $content; } public function render() { - return $this->parser->getAsHtml(); + return nl2br(htmlentities($this->content)); } } diff --git a/composer.json b/composer.json index 4dc3579..61471e1 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,6 @@ ], "require": { "php": ">=7.4", - "jbbcode/jbbcode": "^1.4", "laravel/lumen-framework": "^8.0", "nesbot/carbon": "^2.43" }, diff --git a/composer.lock b/composer.lock index a0144ac..520d94c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "65ffb6735fb8aab2c27031564c2b60dd", + "content-hash": "e02624169974a56b334e306a119981be", "packages": [ { "name": "brick/math", @@ -1861,58 +1861,6 @@ }, "time": "2020-11-02T14:01:41+00:00" }, - { - "name": "jbbcode/jbbcode", - "version": "v1.4.2", - "source": { - "type": "git", - "url": "https://github.com/jbowens/jBBCode.git", - "reference": "d9a132e7886a11cf997e3ec025a41bdf97899704" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/jbowens/jBBCode/zipball/d9a132e7886a11cf997e3ec025a41bdf97899704", - "reference": "d9a132e7886a11cf997e3ec025a41bdf97899704", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^2.1", - "phpunit/phpunit": "4.5.*", - "satooshi/php-coveralls": "0.6.*" - }, - "type": "library", - "autoload": { - "psr-0": { - "JBBCode": "." - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jackson Owens", - "email": "jackson_owens@alumni.brown.edu", - "homepage": "http://jbowens.org/", - "role": "Developer" - } - ], - "description": "A lightweight but extensible BBCode parser written in PHP 5.3.", - "homepage": "http://jbbcode.com/", - "keywords": [ - "BB", - "bbcode" - ], - "support": { - "issues": "https://github.com/jbowens/jBBCode/issues", - "source": "https://github.com/jbowens/jBBCode/tree/v1.4.2" - }, - "time": "2020-06-19T16:09:00+00:00" - }, { "name": "laravel/lumen-framework", "version": "v8.2.1",