Externallink.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace dokuwiki\Parsing\ParserMode;
  3. class Externallink extends AbstractMode
  4. {
  5. protected $schemes = array();
  6. protected $patterns = array();
  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. }