[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/inc/Parsing/ParserMode/ -> Externallink.php (source)

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