A fork of potaka/bbcode to handle future maintenance
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- <?php
-
- namespace Knockout\BbCode\Tag;
-
- use Knockout\BbCode\Tokenizer\Tag as TokenTag;
-
- /**
- * @author po_taka <angel.koilov@gmail.com>
- */
- class Link implements TagInterface
- {
- const REG_EXP_VALID_URL = '~https?://[a-zA-Z0-9_\-.:/#?]+~';
-
- public function format(TokenTag $tokenTag): string
- {
- $url = $tokenTag->getArgument();
-
- if (!preg_match(self::REG_EXP_VALID_URL, $url)) {
- $simpleTag = new UnknownSimpleType();
- 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]";
- }
- }
|