@@ -1,68 +0,0 @@ | |||||
<?php | |||||
namespace App\BbCode; | |||||
use JBBCode\CodeDefinitionSet; | |||||
use JBBCode\CodeDefinitionBuilder; | |||||
class KnockoutDefinitionSet implements CodeDefinitionSet | |||||
{ | |||||
/** @var CodeDefinition[] The default code definitions in this set. */ | |||||
protected $definitions = array(); | |||||
/** | |||||
* Constructs the default code definitions. | |||||
*/ | |||||
public function __construct() | |||||
{ | |||||
/* [b] bold tag */ | |||||
$builder = new CodeDefinitionBuilder('b', '<strong>{param}</strong>'); | |||||
$this->definitions[] = $builder->build(); | |||||
/* [i] italics tag */ | |||||
$builder = new CodeDefinitionBuilder('i', '<em>{param}</em>'); | |||||
$this->definitions[] = $builder->build(); | |||||
/* [u] underline tag */ | |||||
$builder = new CodeDefinitionBuilder('u', '<u>{param}</u>'); | |||||
$this->definitions[] = $builder->build(); | |||||
$urlValidator = new \JBBCode\validators\UrlValidator(); | |||||
/* [url] link tag */ | |||||
$builder = new CodeDefinitionBuilder('url', '<a href="{param}">{param}</a>'); | |||||
$builder->setParseContent(false)->setBodyValidator($urlValidator); | |||||
$this->definitions[] = $builder->build(); | |||||
/* [url=http://example.com] link tag */ | |||||
$builder = new CodeDefinitionBuilder('url', '<a href="{option}">{param}</a>'); | |||||
$builder->setUseOption(true)->setParseContent(true)->setOptionValidator($urlValidator); | |||||
$this->definitions[] = $builder->build(); | |||||
/* [img] image tag */ | |||||
$builder = new CodeDefinitionBuilder('img', '<img src="{param}" />'); | |||||
$builder->setUseOption(false)->setParseContent(false)->setBodyValidator($urlValidator); | |||||
$this->definitions[] = $builder->build(); | |||||
/* [img=alt text] image tag */ | |||||
$builder = new CodeDefinitionBuilder('img', '<img src="{param}" alt="{option}" />'); | |||||
$builder->setUseOption(true)->setParseContent(false)->setBodyValidator($urlValidator); | |||||
$this->definitions[] = $builder->build(); | |||||
/* [color] color tag */ | |||||
$builder = new CodeDefinitionBuilder('color', '<span style="color: {option}">{param}</span>'); | |||||
$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; | |||||
} | |||||
} |
@@ -1,24 +0,0 @@ | |||||
<?php | |||||
namespace App\BbCode\Tag; | |||||
use Knockout\BbCode\Tag\SimpleTag; | |||||
class Bold extends SimpleTag | |||||
{ | |||||
public function getCloseHtmlTag(): string | |||||
{ | |||||
return '</b>'; | |||||
} | |||||
public function getOpenHtmlTag(): string | |||||
{ | |||||
return '<b>'; | |||||
} | |||||
public function getTag() : string | |||||
{ | |||||
return 'b'; | |||||
} | |||||
} |
@@ -1,31 +0,0 @@ | |||||
<?php | |||||
namespace App\BbCode\Tag; | |||||
use Knockout\BbCode\Tag\TagInterface; | |||||
use Knockout\BbCode\Tokenizer\Tag as TokenTag; | |||||
class Image implements TagInterface | |||||
{ | |||||
public function format(TokenTag $tokenTag): string | |||||
{ | |||||
$link = $tokenTag->getText(); | |||||
if (!preg_match('!^https?://[a-z0-9\-@:.,_&+%#?/=]+$!i', $link)) { | |||||
$unknownTag = new Unknown(); | |||||
return $unknownTag->format($tokenTag); | |||||
} | |||||
return '<img src="' . $link . '" />'; | |||||
} | |||||
public function getName(): string | |||||
{ | |||||
return 'img'; | |||||
} | |||||
public function getOriginalText(TokenTag $tokenTag): string | |||||
{ | |||||
return "[{$this->getName()}]{$tokenTag->getText()}[/{$this->getName()}"; | |||||
} | |||||
} |
@@ -1,24 +0,0 @@ | |||||
<?php | |||||
namespace App\BbCode\Tag; | |||||
use Knockout\BbCode\Tag\SimpleTag; | |||||
class Italic extends SimpleTag | |||||
{ | |||||
public function getCloseHtmlTag(): string | |||||
{ | |||||
return '</em>'; | |||||
} | |||||
public function getOpenHtmlTag(): string | |||||
{ | |||||
return '<em>'; | |||||
} | |||||
public function getTag() : string | |||||
{ | |||||
return 'i'; | |||||
} | |||||
} |
@@ -1,35 +0,0 @@ | |||||
<?php | |||||
namespace App\BbCode\Tag; | |||||
use Knockout\BbCode\Tag\TagInterface; | |||||
use Knockout\BbCode\Tokenizer\Tag as TokenTag; | |||||
class Link implements TagInterface | |||||
{ | |||||
const REG_EXP_VALID_URL = '~https?://[a-zA-Z0-9_\-.:/#?]+~'; | |||||
public function format(TokenTag $tokenTag): string | |||||
{ | |||||
$args = $tokenTag->parseArgument(); | |||||
$url = $args['href'] ?? null; | |||||
if (!preg_match(self::REG_EXP_VALID_URL, $url)) { | |||||
$simpleTag = new Unknown(); | |||||
return $simpleTag->format($tokenTag); | |||||
} | |||||
return "<a href=\"{$url}\" target=\"_blank\">{$tokenTag->getText()}</a>"; | |||||
} | |||||
public function getName(): string | |||||
{ | |||||
return 'url'; | |||||
} | |||||
public function getOriginalText(TokenTag $tokenTag) : string | |||||
{ | |||||
return "[url={$tokenTag->getArgument()}]{$tokenTag->getText()}[/url]"; | |||||
} | |||||
} |
@@ -2,31 +2,41 @@ | |||||
namespace App\BbCode\Tag; | 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()}"; | |||||
// } | |||||
} | } |
@@ -1,24 +0,0 @@ | |||||
<?php | |||||
namespace App\BbCode\Tag; | |||||
use Knockout\BbCode\Tag\SimpleTag; | |||||
class Underline extends SimpleTag | |||||
{ | |||||
public function getCloseHtmlTag(): string | |||||
{ | |||||
return '</u>'; | |||||
} | |||||
public function getOpenHtmlTag(): string | |||||
{ | |||||
return '<u>'; | |||||
} | |||||
public function getTag() : string | |||||
{ | |||||
return 'u'; | |||||
} | |||||
} |
@@ -4,22 +4,19 @@ namespace App\Helper; | |||||
use App\BbCode\KnockoutDefinitionSet; | use App\BbCode\KnockoutDefinitionSet; | ||||
use JBBCode\Parser; | |||||
class BBCode { | class BBCode { | ||||
private $parser; | |||||
private $content; | |||||
public function __construct($content) | public function __construct($content) | ||||
{ | { | ||||
$this->parser = new Parser(); | |||||
$this->parser->addCodeDefinitionSet(new KnockoutDefinitionSet()); | |||||
$this->parser->parse($content); | |||||
$this->content = $content; | |||||
} | } | ||||
public function render() | public function render() | ||||
{ | { | ||||
return $this->parser->getAsHtml(); | |||||
return nl2br(htmlentities($this->content)); | |||||
} | } | ||||
} | } |
@@ -12,7 +12,6 @@ | |||||
], | ], | ||||
"require": { | "require": { | ||||
"php": ">=7.4", | "php": ">=7.4", | ||||
"jbbcode/jbbcode": "^1.4", | |||||
"laravel/lumen-framework": "^8.0", | "laravel/lumen-framework": "^8.0", | ||||
"nesbot/carbon": "^2.43" | "nesbot/carbon": "^2.43" | ||||
}, | }, | ||||
@@ -4,7 +4,7 @@ | |||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", | ||||
"This file is @generated automatically" | "This file is @generated automatically" | ||||
], | ], | ||||
"content-hash": "65ffb6735fb8aab2c27031564c2b60dd", | |||||
"content-hash": "e02624169974a56b334e306a119981be", | |||||
"packages": [ | "packages": [ | ||||
{ | { | ||||
"name": "brick/math", | "name": "brick/math", | ||||
@@ -1861,58 +1861,6 @@ | |||||
}, | }, | ||||
"time": "2020-11-02T14:01:41+00:00" | "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", | "name": "laravel/lumen-framework", | ||||
"version": "v8.2.1", | "version": "v8.2.1", | ||||