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.

37 lines
786B

  1. <?php
  2. namespace Knockout\BbCode\Tag;
  3. use Knockout\BbCode\Tokenizer\Tag as TokenTag;
  4. /**
  5. * ImgTag
  6. *
  7. * Handle [img] tag
  8. *
  9. * @author po_taka <angel.koilov@gmail.com>
  10. */
  11. class ImgTag implements TagInterface
  12. {
  13. public function format(TokenTag $tokenTag): string
  14. {
  15. $link = $tokenTag->getText();
  16. if (!preg_match('!^https?://[a-z0-9\-@:.,_&+%#?/=]+$!i', $link)) {
  17. $unknownTag = new UnknownSimpleType();
  18. return $unknownTag->format($tokenTag);
  19. }
  20. return '<img src="' . $link . '" />';
  21. }
  22. public function getName(): string
  23. {
  24. return 'img';
  25. }
  26. public function getOriginalText(TokenTag $tokenTag): string
  27. {
  28. return "[{$this->getName()}]{$tokenTag->getText()}[/{$this->getName()}";
  29. }
  30. }