@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * The base module implements the basic functionality for each module (Markup: (X)HTML, XML, etc.) |
20 | 20 | */ |
21 | -class MarkupBaseModule extends BaseModule implements BaseModuleInterface{ |
|
21 | +class MarkupBaseModule extends BaseModule implements BaseModuleInterface { |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * Allowed text-align modes |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * |
103 | 103 | * @return string |
104 | 104 | */ |
105 | - public function sanitize($content){ |
|
105 | + public function sanitize($content) { |
|
106 | 106 | return htmlspecialchars($content, ENT_NOQUOTES, 'UTF-8', false); |
107 | 107 | } |
108 | 108 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @see https://xkcd.com/221/ |
115 | 115 | */ |
116 | - protected function randomID(){ |
|
116 | + protected function randomID() { |
|
117 | 117 | return hash('crc32b', mt_rand().microtime(true)); |
118 | 118 | } |
119 | 119 | |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @return string usable as (X)HTML/XML class attribute |
127 | 127 | */ |
128 | - protected function getCssClass(array $additional_classes = []){ |
|
128 | + protected function getCssClass(array $additional_classes = []) { |
|
129 | 129 | $classes = $this->getAttribute('class', '').' '.implode(' ', $additional_classes); |
130 | - $classes =preg_replace('/[^a-z\d\- ]/i', '', $classes); |
|
130 | + $classes = preg_replace('/[^a-z\d\- ]/i', '', $classes); |
|
131 | 131 | $classes = trim($classes); |
132 | 132 | |
133 | 133 | return !empty($classes) ? ' class="'.$classes.'"' : ''; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @return string usable as (X)HTML/XML title attribute |
143 | 143 | */ |
144 | - protected function getTitle($title = ''){ |
|
144 | + protected function getTitle($title = '') { |
|
145 | 145 | $title = $this->getAttribute('title', $title); |
146 | 146 | |
147 | 147 | // @todo: filter |
@@ -156,13 +156,13 @@ discard block |
||
156 | 156 | * |
157 | 157 | * @return string usable as (X)HTML/XML style attribute |
158 | 158 | */ |
159 | - protected function getStyle(array $style = []){ |
|
159 | + protected function getStyle(array $style = []) { |
|
160 | 160 | $out = []; |
161 | 161 | |
162 | - foreach($style as $property => $value){ |
|
162 | + foreach ($style as $property => $value) { |
|
163 | 163 | // @todo: if(in_array($property, $allowed))? |
164 | 164 | // handle exclusions of common user definable properties |
165 | - switch(true){ |
|
165 | + switch (true) { |
|
166 | 166 | // color |
167 | 167 | case in_array($property, ['background-color', 'color']) |
168 | 168 | && !preg_match('/^#([a-f\d]{3}){1,2}$/i', $value): |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | break; |
175 | 175 | } |
176 | 176 | |
177 | - if($value){ |
|
177 | + if ($value) { |
|
178 | 178 | $out[] = $property.':'.$value; |
179 | 179 | } |
180 | 180 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * The base module implements the basic functionality for each module (Mediawiki) |
20 | 20 | */ |
21 | -class MediawikiBaseModule extends BaseModule implements BaseModuleInterface{ |
|
21 | +class MediawikiBaseModule extends BaseModule implements BaseModuleInterface { |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * Holds an array of FQN strings to the current base module's children |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @return string |
39 | 39 | */ |
40 | - public function sanitize($content){ |
|
40 | + public function sanitize($content) { |
|
41 | 41 | // TODO: Implement sanitize() method. |
42 | 42 | return $content; |
43 | 43 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | /** |
18 | 18 | * Implements the module specific functionality |
19 | 19 | */ |
20 | -interface ModuleInterface{ |
|
20 | +interface ModuleInterface { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * Transforms the bbcode, called from BaseModuleInterface |
@@ -17,7 +17,7 @@ |
||
17 | 17 | * |
18 | 18 | * @see \chillerlan\bbcode\Modules\BaseModuleInterface::getTags() |
19 | 19 | */ |
20 | -class Tagmap{ |
|
20 | +class Tagmap { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * An array of tags a module is able to process |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * The base module implements the basic functionality for each module (plain text) |
20 | 20 | */ |
21 | -class TextBaseModule extends BaseModule implements BaseModuleInterface{ |
|
21 | +class TextBaseModule extends BaseModule implements BaseModuleInterface { |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * Holds an array of FQN strings to the current base module's children |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @return string |
39 | 39 | */ |
40 | - public function sanitize($content){ |
|
40 | + public function sanitize($content) { |
|
41 | 41 | // TODO: Implement sanitize() method. |
42 | 42 | return 'Implement sanitize() method!'; |
43 | 43 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @link http://www.developers-guide.net/c/152-bbcode-parser-mit-noparse-tag-selbst-gemacht.html |
29 | 29 | */ |
30 | -class Parser{ |
|
30 | +class Parser { |
|
31 | 31 | use ClassLoaderTrait; |
32 | 32 | |
33 | 33 | /** |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @param \chillerlan\bbcode\ParserOptions $options [optional] |
141 | 141 | */ |
142 | - public function __construct(ParserOptions $options = null){ |
|
142 | + public function __construct(ParserOptions $options = null) { |
|
143 | 143 | $this->setOptions(!$options ? new ParserOptions : $options); |
144 | 144 | $this->BBTemp = new BBTemp; |
145 | 145 | } |
@@ -151,22 +151,22 @@ discard block |
||
151 | 151 | * |
152 | 152 | * @throws \chillerlan\bbcode\BBCodeException |
153 | 153 | */ |
154 | - public function setOptions(ParserOptions $options){ |
|
154 | + public function setOptions(ParserOptions $options) { |
|
155 | 155 | $this->parserOptions = $options; |
156 | 156 | $this->baseModuleInterface = $this->__loadClass($this->parserOptions->baseModuleInterface, BaseModuleInterface::class); |
157 | 157 | $this->languageInterface = $this->__loadClass($this->parserOptions->languageInterface, LanguageInterface::class); |
158 | 158 | |
159 | - if($this->parserOptions->parserExtensionInterface){ |
|
159 | + if ($this->parserOptions->parserExtensionInterface) { |
|
160 | 160 | $this->parserExtensionInterface = |
161 | 161 | $this->__loadClass($this->parserOptions->parserExtensionInterface, ParserExtensionInterface::class, $this->parserOptions); |
162 | 162 | } |
163 | 163 | |
164 | 164 | $module_info = $this->baseModuleInterface->getInfo(); |
165 | - foreach($module_info->modules as $module){ |
|
165 | + foreach ($module_info->modules as $module) { |
|
166 | 166 | $this->moduleInterface = $this->__loadClass($module, ModuleInterface::class); |
167 | 167 | |
168 | 168 | $tagmap = $this->moduleInterface->getTags(); |
169 | - foreach($tagmap->tags as $tag){ |
|
169 | + foreach ($tagmap->tags as $tag) { |
|
170 | 170 | $this->tagmap[$tag] = $module; |
171 | 171 | } |
172 | 172 | |
@@ -178,15 +178,15 @@ discard block |
||
178 | 178 | $this->parserOptions->eol_token = $module_info->eol_token; |
179 | 179 | $this->parserOptions->singletags = implode('|', $this->singletags); |
180 | 180 | |
181 | - if(is_array($this->parserOptions->allowed_tags) && !empty($this->parserOptions->allowed_tags)){ |
|
182 | - foreach($this->parserOptions->allowed_tags as $tag){ |
|
183 | - if(array_key_exists($tag, $this->tagmap)){ |
|
181 | + if (is_array($this->parserOptions->allowed_tags) && !empty($this->parserOptions->allowed_tags)) { |
|
182 | + foreach ($this->parserOptions->allowed_tags as $tag) { |
|
183 | + if (array_key_exists($tag, $this->tagmap)) { |
|
184 | 184 | $this->allowed_tags[] = $tag; |
185 | 185 | } |
186 | 186 | } |
187 | 187 | } |
188 | - else{ |
|
189 | - if($this->parserOptions->allow_all){ |
|
188 | + else { |
|
189 | + if ($this->parserOptions->allow_all) { |
|
190 | 190 | $this->allowed_tags = array_keys($this->tagmap); |
191 | 191 | } |
192 | 192 | } |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * |
198 | 198 | * @return array |
199 | 199 | */ |
200 | - public function getTagmap(){ |
|
200 | + public function getTagmap() { |
|
201 | 201 | ksort($this->tagmap); |
202 | 202 | return $this->tagmap; |
203 | 203 | } |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * |
208 | 208 | * @return array |
209 | 209 | */ |
210 | - public function getAllowed(){ |
|
210 | + public function getAllowed() { |
|
211 | 211 | sort($this->allowed_tags); |
212 | 212 | return $this->allowed_tags; |
213 | 213 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * |
218 | 218 | * @return array |
219 | 219 | */ |
220 | - public function getNoparse(){ |
|
220 | + public function getNoparse() { |
|
221 | 221 | sort($this->noparse_tags); |
222 | 222 | return $this->noparse_tags; |
223 | 223 | } |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @return array |
229 | 229 | */ |
230 | - public function getSingle(){ |
|
230 | + public function getSingle() { |
|
231 | 231 | sort($this->singletags); |
232 | 232 | return $this->singletags; |
233 | 233 | } |
@@ -239,8 +239,8 @@ discard block |
||
239 | 239 | * |
240 | 240 | * @return string |
241 | 241 | */ |
242 | - public function parse($bbcode){ |
|
243 | - if($this->parserOptions->sanitize){ |
|
242 | + public function parse($bbcode) { |
|
243 | + if ($this->parserOptions->sanitize) { |
|
244 | 244 | $bbcode = $this->baseModuleInterface->sanitize($bbcode); |
245 | 245 | } |
246 | 246 | |
@@ -264,12 +264,12 @@ discard block |
||
264 | 264 | * @return string |
265 | 265 | * @throws \chillerlan\bbcode\BBCodeException |
266 | 266 | */ |
267 | - protected function __parse($bbcode){ |
|
267 | + protected function __parse($bbcode) { |
|
268 | 268 | static $callback_count = 0; |
269 | 269 | $callback = false; |
270 | 270 | $preg_error = PREG_NO_ERROR; |
271 | 271 | |
272 | - if(is_array($bbcode) && isset($bbcode['tag'], $bbcode['attributes'], $bbcode['content'])){ |
|
272 | + if (is_array($bbcode) && isset($bbcode['tag'], $bbcode['attributes'], $bbcode['content'])) { |
|
273 | 273 | $tag = strtolower($bbcode['tag']); |
274 | 274 | $attributes = $this->getAttributes($bbcode['attributes']); |
275 | 275 | $content = $bbcode['content']; |
@@ -277,30 +277,30 @@ discard block |
||
277 | 277 | $callback = true; |
278 | 278 | $callback_count++; |
279 | 279 | } |
280 | - else if(is_string($bbcode) && !empty($bbcode)){ |
|
280 | + else if (is_string($bbcode) && !empty($bbcode)) { |
|
281 | 281 | $tag = null; |
282 | 282 | $attributes = []; |
283 | 283 | $content = $bbcode; |
284 | 284 | } |
285 | - else{ |
|
285 | + else { |
|
286 | 286 | return ''; |
287 | 287 | } |
288 | 288 | |
289 | - if($callback_count < (int)$this->parserOptions->nesting_limit && !in_array($tag, $this->noparse_tags)){ |
|
289 | + if ($callback_count < (int)$this->parserOptions->nesting_limit && !in_array($tag, $this->noparse_tags)) { |
|
290 | 290 | $pattern = '#\[(?<tag>\w+)(?<attributes>(?:\s|=)[^]]*)?](?<content>(?:[^[]|\[(?!/?\1((?:\s|=)[^]]*)?])|(?R))*)\[/\1]#'; |
291 | 291 | $content = preg_replace_callback($pattern, __METHOD__, $content); |
292 | 292 | $preg_error = preg_last_error(); |
293 | 293 | } |
294 | 294 | |
295 | 295 | // still testing... |
296 | - if($preg_error !== PREG_NO_ERROR){ |
|
296 | + if ($preg_error !== PREG_NO_ERROR) { |
|
297 | 297 | // @codeCoverageIgnoreStart |
298 | 298 | $message = sprintf($this->languageInterface->parserExceptionCallback(), $tag, self::PREG_ERROR[$preg_error], $preg_error); |
299 | 299 | throw new BBCodeException($message); |
300 | 300 | // @codeCoverageIgnoreEnd |
301 | 301 | } |
302 | 302 | |
303 | - if($callback && isset($this->tagmap[$tag]) && in_array($tag, $this->allowed_tags)){ |
|
303 | + if ($callback && isset($this->tagmap[$tag]) && in_array($tag, $this->allowed_tags)) { |
|
304 | 304 | $this->BBTemp->tag = $tag; |
305 | 305 | $this->BBTemp->attributes = $attributes; |
306 | 306 | $this->BBTemp->content = $content; |
@@ -326,12 +326,12 @@ discard block |
||
326 | 326 | * @return array |
327 | 327 | * @throws \chillerlan\bbcode\BBCodeException |
328 | 328 | */ |
329 | - protected function getAttributes($attributes){ |
|
329 | + protected function getAttributes($attributes) { |
|
330 | 330 | $attr = []; |
331 | 331 | $pattern = '#(?<name>^|\w+)\=(\'?)(?<value>[^\']*?)\2(?: |$)#'; |
332 | 332 | |
333 | - if(preg_match_all($pattern, $attributes, $matches, PREG_SET_ORDER) > 0){ |
|
334 | - foreach($matches as $attribute){ |
|
333 | + if (preg_match_all($pattern, $attributes, $matches, PREG_SET_ORDER) > 0) { |
|
334 | + foreach ($matches as $attribute) { |
|
335 | 335 | $name = empty($attribute['name']) ? $this->parserOptions->bbtag_placeholder : strtolower(trim($attribute['name'])); |
336 | 336 | |
337 | 337 | $value = trim($attribute['value']); |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | |
344 | 344 | $preg_error = preg_last_error(); |
345 | 345 | |
346 | - if($preg_error !== PREG_NO_ERROR){ |
|
346 | + if ($preg_error !== PREG_NO_ERROR) { |
|
347 | 347 | // @codeCoverageIgnoreStart |
348 | 348 | $message = sprintf($this->languageInterface->parserExceptionMatchall(), self::PREG_ERROR[$preg_error], $preg_error); |
349 | 349 | throw new BBCodeException($message); |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * An empty parser extension as ground to start from |
17 | 17 | */ |
18 | -class ParserExtension implements ParserExtensionInterface{ |
|
18 | +class ParserExtension implements ParserExtensionInterface { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var \chillerlan\bbcode\ParserOptions |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @param \chillerlan\bbcode\ParserOptions $options |
29 | 29 | */ |
30 | - public function __construct(ParserOptions $options){ |
|
30 | + public function __construct(ParserOptions $options) { |
|
31 | 31 | $this->options = $options; |
32 | 32 | } |
33 | 33 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @return string preparsed bbcode |
43 | 43 | */ |
44 | - public function pre($bbcode){ |
|
44 | + public function pre($bbcode) { |
|
45 | 45 | return $bbcode; |
46 | 46 | } |
47 | 47 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return string postparsed bbcode |
64 | 64 | */ |
65 | - public function post($bbcode){ |
|
65 | + public function post($bbcode) { |
|
66 | 66 | return $bbcode; |
67 | 67 | } |
68 | 68 |
@@ -15,7 +15,7 @@ |
||
15 | 15 | /** |
16 | 16 | * Implements pre-/post-parser methods, for example: parsing Smileys |
17 | 17 | */ |
18 | -interface ParserExtensionInterface{ |
|
18 | +interface ParserExtensionInterface { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Pre-parser |
@@ -20,7 +20,7 @@ |
||
20 | 20 | * |
21 | 21 | * @see \chillerlan\bbcode\Parser::__construct() |
22 | 22 | */ |
23 | -class ParserOptions{ |
|
23 | +class ParserOptions { |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * The language class to use (FQN) |