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\HTMLElements;
009 use InvalidArgumentException;
010 use RuntimeException;
011 use s9e\TextFormatter\Configurator\Helpers\RegexpBuilder;
012 use s9e\TextFormatter\Configurator\Items\Tag;
013 use s9e\TextFormatter\Configurator\Items\UnsafeTemplate;
014 use s9e\TextFormatter\Configurator\JavaScript\Dictionary;
015 use s9e\TextFormatter\Configurator\Validators\AttributeName;
016 use s9e\TextFormatter\Configurator\Validators\TagName;
017 use s9e\TextFormatter\Plugins\ConfiguratorBase;
018 class Configurator extends ConfiguratorBase
019 {
020 protected $aliases = array();
021 protected $attributeFilters = array(
022 'action' => '#url',
023 'cite' => '#url',
024 'data' => '#url',
025 'formaction' => '#url',
026 'href' => '#url',
027 'icon' => '#url',
028 'longdesc' => '#url',
029 'poster' => '#url',
030 'src' => '#url'
031 );
032 protected $elements = array();
033 protected $prefix = 'html';
034 protected $quickMatch = '<';
035 protected $unsafeElements = array(
036 'base',
037 'embed',
038 'frame',
039 'iframe',
040 'meta',
041 'object',
042 'script'
043 );
044 protected $unsafeAttributes = array(
045 'style',
046 'target'
047 );
048 public function aliasAttribute($elName, $attrName, $alias)
049 {
050 $elName = $this->normalizeElementName($elName);
051 $attrName = $this->normalizeAttributeName($attrName);
052 $this->aliases[$elName][$attrName] = AttributeName::normalize($alias);
053 }
054 public function aliasElement($elName, $tagName)
055 {
056 $elName = $this->normalizeElementName($elName);
057 $this->aliases[$elName][''] = TagName::normalize($tagName);
058 }
059 public function allowElement($elName)
060 {
061 return $this->allowElementWithSafety($elName, \false);
062 }
063 public function allowUnsafeElement($elName)
064 {
065 return $this->allowElementWithSafety($elName, \true);
066 }
067 protected function allowElementWithSafety($elName, $allowUnsafe)
068 {
069 $elName = $this->normalizeElementName($elName);
070 $tagName = $this->prefix . ':' . $elName;
071 if (!$allowUnsafe && \in_array($elName, $this->unsafeElements))
072 throw new RuntimeException("'" . $elName . "' elements are unsafe and are disabled by default. Please use " . __CLASS__ . '::allowUnsafeElement() to bypass this security measure');
073 $tag = ($this->configurator->tags->exists($tagName))
074 ? $this->configurator->tags->get($tagName)
075 : $this->configurator->tags->add($tagName);
076 $this->rebuildTemplate($tag, $elName, $allowUnsafe);
077 $this->elements[$elName] = 1;
078 return $tag;
079 }
080 public function allowAttribute($elName, $attrName)
081 {
082 return $this->allowAttributeWithSafety($elName, $attrName, \false);
083 }
084 public function allowUnsafeAttribute($elName, $attrName)
085 {
086 return $this->allowAttributeWithSafety($elName, $attrName, \true);
087 }
088 protected function allowAttributeWithSafety($elName, $attrName, $allowUnsafe)
089 {
090 $elName = $this->normalizeElementName($elName);
091 $attrName = $this->normalizeAttributeName($attrName);
092 $tagName = $this->prefix . ':' . $elName;
093 if (!isset($this->elements[$elName]))
094 throw new RuntimeException("Element '" . $elName . "' has not been allowed");
095 if (!$allowUnsafe)
096 if (\substr($attrName, 0, 2) === 'on'
097 || \in_array($attrName, $this->unsafeAttributes))
098 throw new RuntimeException("'" . $attrName . "' attributes are unsafe and are disabled by default. Please use " . __CLASS__ . '::allowUnsafeAttribute() to bypass this security measure');
099 $tag = $this->configurator->tags->get($tagName);
100 if (!isset($tag->attributes[$attrName]))
101 {
102 $attribute = $tag->attributes->add($attrName);
103 $attribute->required = \false;
104 if (isset($this->attributeFilters[$attrName]))
105 {
106 $filterName = $this->attributeFilters[$attrName];
107 $filter = $this->configurator->attributeFilters->get($filterName);
108 $attribute->filterChain->append($filter);
109 }
110 }
111 $this->rebuildTemplate($tag, $elName, $allowUnsafe);
112 return $tag->attributes[$attrName];
113 }
114 protected function normalizeElementName($elName)
115 {
116 if (!\preg_match('#^[a-z][a-z0-9]*$#Di', $elName))
117 throw new InvalidArgumentException ("Invalid element name '" . $elName . "'");
118 return \strtolower($elName);
119 }
120 protected function normalizeAttributeName($attrName)
121 {
122 if (!\preg_match('#^[a-z][-\\w]*$#Di', $attrName))
123 throw new InvalidArgumentException ("Invalid attribute name '" . $attrName . "'");
124 return \strtolower($attrName);
125 }
126 protected function rebuildTemplate(Tag $tag, $elName, $allowUnsafe)
127 {
128 $template = '<' . $elName . '>';
129 foreach ($tag->attributes as $attrName => $attribute)
130 $template .= '<xsl:copy-of select="@' . $attrName . '"/>';
131 $template .= '<xsl:apply-templates/></' . $elName . '>';
132 if ($allowUnsafe)
133 $template = new UnsafeTemplate($template);
134 $tag->setTemplate($template);
135 }
136 public function asConfig()
137 {
138 if (empty($this->elements) && empty($this->aliases))
139 return;
140 $attrRegexp = '[a-z][-a-z0-9]*(?>\\s*=\\s*(?>"[^"]*"|\'[^\']*\'|[^\\s"\'=<>`]+))?';
141 $tagRegexp = RegexpBuilder::fromList(\array_merge(
142 \array_keys($this->aliases),
143 \array_keys($this->elements)
144 ));
145 $endTagRegexp = '/(' . $tagRegexp . ')';
146 $startTagRegexp = '(' . $tagRegexp . ')((?>\\s+' . $attrRegexp . ')*+)\\s*/?';
147 $regexp = '#<(?>' . $endTagRegexp . '|' . $startTagRegexp . ')\\s*>#i';
148 $config = array(
149 'quickMatch' => $this->quickMatch,
150 'prefix' => $this->prefix,
151 'regexp' => $regexp
152 );
153 if (!empty($this->aliases))
154 {
155 $config['aliases'] = new Dictionary;
156 foreach ($this->aliases as $elName => $aliases)
157 $config['aliases'][$elName] = new Dictionary($aliases);
158 }
159 return $config;
160 }
161 public function getJSHints()
162 {
163 return array('HTMLELEMENTS_HAS_ALIASES' => (int) !empty($this->aliases));
164 }
165 }