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