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 |
Helper.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 class Helper
010 {
011 public $allowed;
012 public $attrName = 'with';
013 public $defaultReplacement = '****';
014 public $regexp = '/(?!)/';
015 public $replacements = array();
016 public $tagName = 'CENSOR';
017 public function __construct(array $config)
018 {
019 foreach ($config as $k => $v)
020 $this->$k = $v;
021 }
022 public function censorHtml($html, $censorAttributes = \false)
023 {
024 $_this = $this;
025 $attributesExpr = '';
026 if ($censorAttributes)
027 $attributesExpr = '|[^<">]*+(?=<|$|"(?> [-\\w]+="[^"]*+")*+\\/?>)';
028 $delim = $this->regexp[0];
029 $pos = \strrpos($this->regexp, $delim);
030 $regexp = $delim
031 . '(?<!&#)(?<!&)'
032 . \substr($this->regexp, 1, $pos - 1)
033 . '(?=[^<>]*+(?=<|$)' . $attributesExpr . ')'
034 . \substr($this->regexp, $pos);
035 return \preg_replace_callback(
036 $regexp,
037 function ($m) use ($_this)
038 {
039 return \htmlspecialchars($_this->getReplacement($m[0]), \ENT_QUOTES);
040 },
041 $html
042 );
043 }
044 public function censorText($text)
045 {
046 $_this = $this;
047 return \preg_replace_callback(
048 $this->regexp,
049 function ($m) use ($_this)
050 {
051 return $_this->getReplacement($m[0]);
052 },
053 $text
054 );
055 }
056 public function isCensored($word)
057 {
058 return (\preg_match($this->regexp, $word) && !$this->isAllowed($word));
059 }
060 public function reparse($xml)
061 {
062 $_this = $this;
063 if (\strpos($xml, '</' . $this->tagName . '>') !== \false)
064 {
065 $xml = \preg_replace_callback(
066 '#<' . $this->tagName . '[^>]*>([^<]+)</' . $this->tagName . '>#',
067 function ($m) use ($_this)
068 {
069 return ($_this->isCensored($m[1])) ? $_this->buildTag($m[1]) : $m[1];
070 },
071 $xml
072 );
073 }
074 $delim = $this->regexp[0];
075 $pos = \strrpos($this->regexp, $delim);
076 $regexp = $delim
077 . '(?<!&)'
078 . \substr($this->regexp, 1, $pos - 1)
079 . '(?=[^<>]*+<(?!\\/(?-i)' . $this->tagName . '>))'
080 . \substr($this->regexp, $pos);
081 $xml = \preg_replace_callback(
082 $regexp,
083 function ($m) use ($_this)
084 {
085 return ($_this->isAllowed($m[0])) ? $m[0] : $_this->buildTag($m[0]);
086 },
087 $xml,
088 -1,
089 $cnt
090 );
091 if ($cnt > 0 && $xml[1] === 't')
092 {
093 $xml[1] = 'r';
094 $xml[\strlen($xml) - 2] = 'r';
095 }
096 return $xml;
097 }
098 public function buildTag($word)
099 {
100 $startTag = '<' . $this->tagName;
101 $replacement = $this->getReplacement($word);
102 if ($replacement !== $this->defaultReplacement)
103 $startTag .= ' ' . $this->attrName . '="' . \htmlspecialchars($replacement, \ENT_COMPAT) . '"';
104 return $startTag . '>' . $word . '</' . $this->tagName . '>';
105 }
106 public function getReplacement($word)
107 {
108 if ($this->isAllowed($word))
109 return $word;
110 foreach ($this->replacements as $_23be09c)
111 {
112 list($regexp, $replacement) = $_23be09c;
113 if (\preg_match($regexp, $word))
114 return $replacement;
115 }
116 return $this->defaultReplacement;
117 }
118 public function isAllowed($word)
119 {
120 return (isset($this->allowed) && \preg_match($this->allowed, $word));
121 }
122 }