1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class ParserExtension |
4
|
|
|
* |
5
|
|
|
* @filesource ParserExtension.php |
6
|
|
|
* @created 19.09.2015 |
7
|
|
|
* @package chillerlan\bbcode |
8
|
|
|
* @author Smiley <[email protected]> |
9
|
|
|
* @copyright 2015 Smiley |
10
|
|
|
* @license MIT |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace chillerlan\bbcode; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* An empty parser extension as ground to start from |
17
|
|
|
*/ |
18
|
|
|
class ParserExtension implements ParserExtensionInterface{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var \chillerlan\bbcode\ParserOptions |
22
|
|
|
*/ |
23
|
|
|
protected $options; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* ParserExtension constructor. |
27
|
|
|
* |
28
|
|
|
* @param \chillerlan\bbcode\ParserOptions $options |
|
|
|
|
29
|
|
|
*/ |
30
|
|
|
public function __construct(ParserOptions $options = null){ |
31
|
|
|
$this->options = $options; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Pre-parser |
36
|
|
|
* |
37
|
|
|
* The bbcode you receive is already sanitized, which means: any replacements you do here won't be sanitized any further. Take care! |
38
|
|
|
* Do anything here to the unparsed bbcode, just don't touch newlines - these will be replaced with a placeholder after this step. |
39
|
|
|
* |
40
|
|
|
* @param string $bbcode bbcode |
41
|
|
|
* |
42
|
|
|
* @return string preparsed bbcode |
43
|
|
|
*/ |
44
|
|
|
public function pre($bbcode){ |
45
|
|
|
return $bbcode; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Post-parser |
50
|
|
|
* |
51
|
|
|
* Use this method in case you want to alter the parsed bbcode. |
52
|
|
|
* The newline placeholders are still available and any remaining will be removed in the last step before output |
53
|
|
|
* |
54
|
|
|
* Example: you want the "img" bbcode to use database images instead of user URLs. |
55
|
|
|
* You'd go and change the tag so that it only accepts digits like [img=123456] |
56
|
|
|
* and replace any occurence with a unique placeholder like {__IMG#ID__}. |
57
|
|
|
* Now the post-parser gets into play: you preg_match_all() out all your placeholders, |
58
|
|
|
* grab the images in a single query from the database and replace them with their respective <img> tag |
59
|
|
|
* or whatever replacement and any corrupt id with a placeholder image. Profit! |
60
|
|
|
* |
61
|
|
|
* @param string $bbcode bbcode |
62
|
|
|
* |
63
|
|
|
* @return string postparsed bbcode |
64
|
|
|
*/ |
65
|
|
|
public function post($bbcode){ |
66
|
|
|
return $bbcode; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.