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 |
BuiltInFilters.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\Parser;
009 class BuiltInFilters
010 {
011 public static function filterAlnum($attrValue)
012 {
013 return \filter_var($attrValue, \FILTER_VALIDATE_REGEXP, array(
014 'options' => array('regexp' => '/^[0-9A-Za-z]+$/D')
015 ));
016 }
017 public static function filterColor($attrValue)
018 {
019 return \filter_var($attrValue, \FILTER_VALIDATE_REGEXP, array(
020 'options' => array(
021 'regexp' => '/^(?>#[0-9a-f]{3,6}|rgb\\(\\d{1,3}, *\\d{1,3}, *\\d{1,3}\\)|[a-z]+)$/Di'
022 )
023 ));
024 }
025 public static function filterEmail($attrValue)
026 {
027 return \filter_var($attrValue, \FILTER_VALIDATE_EMAIL);
028 }
029 public static function filterFalse($attrValue)
030 {
031 return \false;
032 }
033 public static function filterFloat($attrValue)
034 {
035 return \filter_var($attrValue, \FILTER_VALIDATE_FLOAT);
036 }
037 public static function filterHashmap($attrValue, array $map, $strict)
038 {
039 if (isset($map[$attrValue]))
040 return $map[$attrValue];
041 return ($strict) ? \false : $attrValue;
042 }
043 public static function filterIdentifier($attrValue)
044 {
045 return \filter_var($attrValue, \FILTER_VALIDATE_REGEXP, array(
046 'options' => array('regexp' => '/^[-0-9A-Za-z_]+$/D')
047 ));
048 }
049 public static function filterInt($attrValue)
050 {
051 return \filter_var($attrValue, \FILTER_VALIDATE_INT);
052 }
053 public static function filterIp($attrValue)
054 {
055 return \filter_var($attrValue, \FILTER_VALIDATE_IP);
056 }
057 public static function filterIpport($attrValue)
058 {
059 if (\preg_match('/^\\[([^\\]]+)(\\]:[1-9][0-9]*)$/D', $attrValue, $m))
060 {
061 $ip = self::filterIpv6($m[1]);
062 if ($ip === \false)
063 return \false;
064 return '[' . $ip . $m[2];
065 }
066 if (\preg_match('/^([^:]+)(:[1-9][0-9]*)$/D', $attrValue, $m))
067 {
068 $ip = self::filterIpv4($m[1]);
069 if ($ip === \false)
070 return \false;
071 return $ip . $m[2];
072 }
073 return \false;
074 }
075 public static function filterIpv4($attrValue)
076 {
077 return \filter_var($attrValue, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4);
078 }
079 public static function filterIpv6($attrValue)
080 {
081 return \filter_var($attrValue, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6);
082 }
083 public static function filterMap($attrValue, array $map)
084 {
085 foreach ($map as $pair)
086 if (\preg_match($pair[0], $attrValue))
087 return $pair[1];
088 return $attrValue;
089 }
090 public static function filterNumber($attrValue)
091 {
092 return \filter_var($attrValue, \FILTER_VALIDATE_REGEXP, array(
093 'options' => array('regexp' => '/^[0-9]+$/D')
094 ));
095 }
096 public static function filterRange($attrValue, $min, $max, Logger $logger = \null)
097 {
098 $attrValue = \filter_var($attrValue, \FILTER_VALIDATE_INT);
099 if ($attrValue === \false)
100 return \false;
101 if ($attrValue < $min)
102 {
103 if (isset($logger))
104 $logger->warn(
105 'Value outside of range, adjusted up to min value',
106 array(
107 'attrValue' => $attrValue,
108 'min' => $min,
109 'max' => $max
110 )
111 );
112 return $min;
113 }
114 if ($attrValue > $max)
115 {
116 if (isset($logger))
117 $logger->warn(
118 'Value outside of range, adjusted down to max value',
119 array(
120 'attrValue' => $attrValue,
121 'min' => $min,
122 'max' => $max
123 )
124 );
125 return $max;
126 }
127 return $attrValue;
128 }
129 public static function filterRegexp($attrValue, $regexp)
130 {
131 return \filter_var($attrValue, \FILTER_VALIDATE_REGEXP, array(
132 'options' => array('regexp' => $regexp)
133 ));
134 }
135 public static function filterSimpletext($attrValue)
136 {
137 return \filter_var($attrValue, \FILTER_VALIDATE_REGEXP, array(
138 'options' => array('regexp' => '/^[- +,.0-9A-Za-z_]+$/D')
139 ));
140 }
141 public static function filterUint($attrValue)
142 {
143 return \filter_var($attrValue, \FILTER_VALIDATE_INT, array(
144 'options' => array('min_range' => 0)
145 ));
146 }
147 public static function filterUrl($attrValue, array $urlConfig, Logger $logger = \null)
148 {
149 $p = self::parseUrl(\trim($attrValue));
150 $error = self::validateUrl($urlConfig, $p);
151 if (!empty($error))
152 {
153 if (isset($logger))
154 {
155 $p['attrValue'] = $attrValue;
156 $logger->err($error, $p);
157 }
158 return \false;
159 }
160 return self::rebuildUrl($p);
161 }
162 protected static function parseUrl($url)
163 {
164 $regexp = '(^(?:([a-z][-+.\\w]*):)?(?://(?:([^:/?#]*)(?::([^/?#]*)?)?@)?(?:(\\[[a-f\\d:]+\\]|[^:/?#]+)(?::(\\d*))?)?(?![^/?#]))?([^?#]*)(\\?[^#]*)?(#.*)?$)Di';
165 \preg_match($regexp, $url, $m);
166 $parts = array();
167 $tokens = array('scheme', 'user', 'pass', 'host', 'port', 'path', 'query', 'fragment');
168 foreach ($tokens as $i => $name)
169 $parts[$name] = (isset($m[$i + 1])) ? $m[$i + 1] : '';
170 $parts['scheme'] = \strtolower($parts['scheme']);
171 $parts['host'] = \rtrim(\preg_replace("/\xE3\x80\x82|\xEF(?:\xBC\x8E|\xBD\xA1)/s", '.', $parts['host']), '.');
172 if (\preg_match('#[^[:ascii:]]#', $parts['host']) && \function_exists('idn_to_ascii'))
173 $parts['host'] = \idn_to_ascii($parts['host']);
174 return $parts;
175 }
176 protected static function rebuildUrl(array $p)
177 {
178 $url = '';
179 if ($p['scheme'] !== '')
180 $url .= $p['scheme'] . ':';
181 if ($p['host'] === '')
182 {
183 if ($p['scheme'] === 'file')
184 $url .= '//';
185 }
186 else
187 {
188 $url .= '//';
189 if ($p['user'] !== '')
190 {
191 $url .= \rawurlencode(\urldecode($p['user']));
192 if ($p['pass'] !== '')
193 $url .= ':' . \rawurlencode(\urldecode($p['pass']));
194 $url .= '@';
195 }
196 $url .= $p['host'];
197 if ($p['port'] !== '')
198 $url .= ':' . $p['port'];
199 }
200 $path = $p['path'] . $p['query'] . $p['fragment'];
201 $path = \preg_replace_callback(
202 '/%.?[a-f]/',
203 function ($m)
204 {
205 return \strtoupper($m[0]);
206 },
207 $path
208 );
209 $url .= self::sanitizeUrl($path);
210 if (!$p['scheme'])
211 $url = \preg_replace('#^([^/]*):#', '$1%3A', $url);
212 return $url;
213 }
214 public static function sanitizeUrl($url)
215 {
216 return \preg_replace_callback(
217 '/%(?![0-9A-Fa-f]{2})|[^!#-&*-;=?-Z_a-z]/S',
218 function ($m)
219 {
220 return \rawurlencode($m[0]);
221 },
222 $url
223 );
224 }
225 protected static function validateUrl(array $urlConfig, array $p)
226 {
227 if ($p['scheme'] !== '' && !\preg_match($urlConfig['allowedSchemes'], $p['scheme']))
228 return 'URL scheme is not allowed';
229 if ($p['host'] === '')
230 {
231 if ($p['scheme'] !== 'file' && $p['scheme'] !== '')
232 return 'Missing host';
233 }
234 else
235 {
236 $regexp = '/^(?!-)[-a-z0-9]{0,62}[a-z0-9](?:\\.(?!-)[-a-z0-9]{0,62}[a-z0-9])*$/i';
237 if (!\preg_match($regexp, $p['host']))
238 if (!self::filterIpv4($p['host'])
239 && !self::filterIpv6(\preg_replace('/^\\[(.*)\\]$/', '$1', $p['host'])))
240 return 'URL host is invalid';
241 if ((isset($urlConfig['disallowedHosts']) && \preg_match($urlConfig['disallowedHosts'], $p['host']))
242 || (isset($urlConfig['restrictedHosts']) && !\preg_match($urlConfig['restrictedHosts'], $p['host'])))
243 return 'URL host is not allowed';
244 }
245 }
246 }