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.
 
 
 
 
 

55 lines
1.4 KiB

  1. <?php
  2. namespace dokuwiki\Parsing\ParserMode;
  3. class Externallink extends AbstractMode
  4. {
  5. protected $schemes = [];
  6. protected $patterns = [];
  7. /** @inheritdoc */
  8. public function preConnect()
  9. {
  10. if (count($this->patterns)) return;
  11. $ltrs = '\w';
  12. $gunk = '/\#~:.?+=&%@!\-\[\]';
  13. $punc = '.:?\-;,';
  14. $host = $ltrs . $punc;
  15. $any = $ltrs . $gunk . $punc;
  16. $this->schemes = getSchemes();
  17. foreach ($this->schemes as $scheme) {
  18. $this->patterns[] = '\b(?i)' . $scheme . '(?-i)://[' . $any . ']+?(?=[' . $punc . ']*[^' . $any . '])';
  19. }
  20. $this->patterns[] = '(?<![/\\\\])\b(?i)www?(?-i)\.[' . $host . ']+?\.' .
  21. '[' . $host . ']+?[' . $any . ']+?(?=[' . $punc . ']*[^' . $any . '])';
  22. $this->patterns[] = '(?<![/\\\\])\b(?i)ftp?(?-i)\.[' . $host . ']+?\.' .
  23. '[' . $host . ']+?[' . $any . ']+?(?=[' . $punc . ']*[^' . $any . '])';
  24. }
  25. /** @inheritdoc */
  26. public function connectTo($mode)
  27. {
  28. foreach ($this->patterns as $pattern) {
  29. $this->Lexer->addSpecialPattern($pattern, $mode, 'externallink');
  30. }
  31. }
  32. /** @inheritdoc */
  33. public function getSort()
  34. {
  35. return 330;
  36. }
  37. /**
  38. * @return array
  39. */
  40. public function getPatterns()
  41. {
  42. return $this->patterns;
  43. }
  44. }