Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Configurator.php
001 <?php
002
003 /*
004 * @package s9e\TextFormatter
005 * @copyright Copyright (c) 2010-2016 The s9e Authors
006 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
007 */
008 namespace s9e\TextFormatter\Plugins\Censor;
009 use ArrayAccess;
010 use Countable;
011 use Iterator;
012 use s9e\TextFormatter\Configurator\Collections\NormalizedCollection;
013 use s9e\TextFormatter\Configurator\Helpers\ConfigHelper;
014 use s9e\TextFormatter\Configurator\Helpers\RegexpBuilder;
015 use s9e\TextFormatter\Configurator\Items\Regexp;
016 use s9e\TextFormatter\Configurator\JavaScript\Code;
017 use s9e\TextFormatter\Configurator\JavaScript\RegexpConvertor;
018 use s9e\TextFormatter\Configurator\Traits\CollectionProxy;
019 use s9e\TextFormatter\Plugins\ConfiguratorBase;
020 class Configurator extends ConfiguratorBase implements ArrayAccess, Countable, Iterator
021 {
022 public function __call($methodName, $args)
023 {
024 return \call_user_func_array(array($this->collection, $methodName), $args);
025 }
026 public function offsetExists($offset)
027 {
028 return isset($this->collection[$offset]);
029 }
030 public function offsetGet($offset)
031 {
032 return $this->collection[$offset];
033 }
034 public function offsetSet($offset, $value)
035 {
036 $this->collection[$offset] = $value;
037 }
038 public function offsetUnset($offset)
039 {
040 unset($this->collection[$offset]);
041 }
042 public function count()
043 {
044 return \count($this->collection);
045 }
046 public function current()
047 {
048 return $this->collection->current();
049 }
050 public function key()
051 {
052 return $this->collection->key();
053 }
054 public function next()
055 {
056 return $this->collection->next();
057 }
058 public function rewind()
059 {
060 $this->collection->rewind();
061 }
062 public function valid()
063 {
064 return $this->collection->valid();
065 }
066 protected $allowed = array();
067 protected $attrName = 'with';
068 protected $collection;
069 protected $defaultReplacement = '****';
070 protected $regexpOptions = array(
071 'caseInsensitive' => \true,
072 'specialChars' => array(
073 '*' => '[\\pL\\pN]*',
074 '?' => '.',
075 ' ' => '\\s*'
076 )
077 );
078 protected $tagName = 'CENSOR';
079 protected function setUp()
080 {
081 $this->collection = new NormalizedCollection;
082 $this->collection->onDuplicate('replace');
083 if (isset($this->configurator->tags[$this->tagName]))
084 return;
085 $tag = $this->configurator->tags->add($this->tagName);
086 $tag->attributes->add($this->attrName)->required = \false;
087 $tag->rules->ignoreTags();
088 $tag->template =
089 '<xsl:choose>
090 <xsl:when test="@' . $this->attrName . '">
091 <xsl:value-of select="@' . \htmlspecialchars($this->attrName) . '"/>
092 </xsl:when>
093 <xsl:otherwise>' . \htmlspecialchars($this->defaultReplacement) . '</xsl:otherwise>
094 </xsl:choose>';
095 }
096 public function allow($word)
097 {
098 $this->allowed[$word] = \true;
099 }
100 public function getHelper()
101 {
102 $config = $this->asConfig();
103 if (isset($config))
104 $config = ConfigHelper::filterConfig($config, 'PHP');
105 else
106 $config = array(
107 'attrName' => $this->attrName,
108 'regexp' => '/(?!)/',
109 'tagName' => $this->tagName
110 );
111 return new Helper($config);
112 }
113 public function asConfig()
114 {
115 $words = $this->getWords();
116 if (empty($words))
117 return;
118 $config = array(
119 'attrName' => $this->attrName,
120 'regexp' => $this->getWordsRegexp(\array_keys($words)),
121 'tagName' => $this->tagName
122 );
123 $replacementWords = array();
124 foreach ($words as $word => $replacement)
125 if (isset($replacement) && $replacement !== $this->defaultReplacement)
126 $replacementWords[$replacement][] = $word;
127 foreach ($replacementWords as $replacement => $words)
128 {
129 $wordsRegexp = '/^' . RegexpBuilder::fromList($words, $this->regexpOptions) . '$/Diu';
130 $regexp = new Regexp($wordsRegexp);
131 $regexp->setJS(RegexpConvertor::toJS(\str_replace('[\\pL\\pN]', '[^\\s!-\\/:-?]', $wordsRegexp)));
132 $config['replacements'][] = array($regexp, $replacement);
133 }
134 if (!empty($this->allowed))
135 $config['allowed'] = $this->getWordsRegexp(\array_keys($this->allowed));
136 return $config;
137 }
138 public function getJSHints()
139 {
140 $hints = array(
141 'CENSOR_HAS_ALLOWED' => !empty($this->allowed),
142 'CENSOR_HAS_REPLACEMENTS' => \false
143 );
144 foreach ($this->getWords() as $replacement)
145 if (isset($replacement) && $replacement !== $this->defaultReplacement)
146 {
147 $hints['CENSOR_HAS_REPLACEMENTS'] = \true;
148 break;
149 }
150 return $hints;
151 }
152 protected function getWords()
153 {
154 return \array_diff_key(\iterator_to_array($this->collection), $this->allowed);
155 }
156 protected function getWordsRegexp(array $words)
157 {
158 $expr = RegexpBuilder::fromList($words, $this->regexpOptions);
159 $expr = \preg_replace('/(?<!\\\\)((?>\\\\\\\\)*)\\(\\?:/', '$1(?>', $expr);
160 $regexp = new Regexp('/(?<![\\pL\\pN])' . $expr . '(?![\\pL\\pN])/Siu');
161 $regexp->setJS('/(?:^|\\W)' . \str_replace('[\\pL\\pN]', '[^\\s!-\\/:-?]', $expr) . '(?!\\w)/gi');
162 return $regexp;
163 }
164 }