[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * @package s9e\TextFormatter 5 * @copyright Copyright (c) 2010-2019 The s9e Authors 6 * @license http://www.opensource.org/licenses/mit-license.php The MIT License 7 */ 8 namespace s9e\TextFormatter\Configurator\Items\AttributeFilters; 9 use InvalidArgumentException; 10 use RuntimeException; 11 use s9e\TextFormatter\Configurator\Helpers\ContextSafeness; 12 use s9e\TextFormatter\Configurator\Helpers\RegexpBuilder; 13 use s9e\TextFormatter\Configurator\Items\AttributeFilter; 14 use s9e\TextFormatter\Configurator\Items\Regexp; 15 class MapFilter extends AttributeFilter 16 { 17 public function __construct(array $map = \null, $caseSensitive = \false, $strict = \false) 18 { 19 parent::__construct('s9e\\TextFormatter\\Parser\\AttributeFilters\\MapFilter::filter'); 20 $this->resetParameters(); 21 $this->addParameterByName('attrValue'); 22 $this->addParameterByName('map'); 23 $this->setJS('MapFilter.filter'); 24 if (isset($map)) 25 $this->setMap($map, $caseSensitive, $strict); 26 } 27 public function asConfig() 28 { 29 if (!isset($this->vars['map'])) 30 throw new RuntimeException("Map filter is missing a 'map' value"); 31 return parent::asConfig(); 32 } 33 public function setMap(array $map, $caseSensitive = \false, $strict = \false) 34 { 35 if (!\is_bool($caseSensitive)) 36 throw new InvalidArgumentException('Argument 2 passed to ' . __METHOD__ . ' must be a boolean'); 37 if (!\is_bool($strict)) 38 throw new InvalidArgumentException('Argument 3 passed to ' . __METHOD__ . ' must be a boolean'); 39 $this->resetSafeness(); 40 if ($strict) 41 $this->assessSafeness($map); 42 $valueKeys = []; 43 foreach ($map as $key => $value) 44 $valueKeys[$value][] = $key; 45 $map = []; 46 foreach ($valueKeys as $value => $keys) 47 { 48 $regexp = RegexpBuilder::fromList( 49 $keys, 50 [ 51 'delimiter' => '/', 52 'caseInsensitive' => !$caseSensitive 53 ] 54 ); 55 $regexp = '/^' . $regexp . '$/D'; 56 if (!$caseSensitive) 57 $regexp .= 'i'; 58 if (!\preg_match('#^[[:ascii:]]*$#D', $regexp)) 59 $regexp .= 'u'; 60 $map[] = [new Regexp($regexp), $value]; 61 } 62 if ($strict) 63 $map[] = [new Regexp('//'), \false]; 64 $this->vars['map'] = $map; 65 } 66 protected function assessSafeness(array $map) 67 { 68 $values = \implode('', $map); 69 $isSafeInCSS = \true; 70 foreach (ContextSafeness::getDisallowedCharactersInCSS() as $char) 71 if (\strpos($values, $char) !== \false) 72 { 73 $isSafeInCSS = \false; 74 break; 75 } 76 if ($isSafeInCSS) 77 $this->markAsSafeInCSS(); 78 $isSafeInJS = \true; 79 foreach (ContextSafeness::getDisallowedCharactersInJS() as $char) 80 if (\strpos($values, $char) !== \false) 81 { 82 $isSafeInJS = \false; 83 break; 84 } 85 if ($isSafeInJS) 86 $this->markAsSafeInJS(); 87 } 88 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |