A bare bones front-end for knockout designed for maximum compatibility with "obsolete" browsers
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

36 lignes
847B

  1. <?php
  2. namespace App\BbCode\Tag;
  3. use Knockout\BbCode\Tag\TagInterface;
  4. use Knockout\BbCode\Tokenizer\Tag as TokenTag;
  5. class Link implements TagInterface
  6. {
  7. const REG_EXP_VALID_URL = '~https?://[a-zA-Z0-9_\-.:/#?]+~';
  8. public function format(TokenTag $tokenTag): string
  9. {
  10. $args = $tokenTag->parseArgument();
  11. $url = $args['href'] ?? null;
  12. if (!preg_match(self::REG_EXP_VALID_URL, $url)) {
  13. $simpleTag = new Unknown();
  14. return $simpleTag->format($tokenTag);
  15. }
  16. return "<a href=\"{$url}\" target=\"_blank\">{$tokenTag->getText()}</a>";
  17. }
  18. public function getName(): string
  19. {
  20. return 'url';
  21. }
  22. public function getOriginalText(TokenTag $tokenTag) : string
  23. {
  24. return "[url={$tokenTag->getArgument()}]{$tokenTag->getText()}[/url]";
  25. }
  26. }