1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Groundskeeper\Tokens\Elements; |
4
|
|
|
|
5
|
|
|
use Groundskeeper\Configuration; |
6
|
|
|
use Groundskeeper\Tokens\ElementTypes\EmbeddedContent; |
7
|
|
|
use Groundskeeper\Tokens\ElementTypes\FlowContent; |
8
|
|
|
use Groundskeeper\Tokens\ElementTypes\OpenElement; |
9
|
|
|
use Groundskeeper\Tokens\ElementTypes\PhrasingContent; |
10
|
|
|
use Groundskeeper\Tokens\ElementTypes\ScriptSupporting; |
11
|
|
|
use Groundskeeper\Tokens\Token; |
12
|
|
|
use Psr\Log\LoggerInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* "picture" element |
16
|
|
|
* |
17
|
|
|
* https://html.spec.whatwg.org/multipage/semantics.html#the-picture-element |
18
|
|
|
*/ |
19
|
|
|
class Picture extends OpenElement implements FlowContent, PhrasingContent, EmbeddedContent |
20
|
|
|
{ |
21
|
|
|
protected function doClean(LoggerInterface $logger) |
22
|
|
|
{ |
23
|
|
|
// Children can consist of zero or more "source" elements, |
24
|
|
|
// followed by one "img" element, optionally intermixed |
25
|
|
|
// with script-supporting elements. |
26
|
|
|
if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) { |
27
|
|
|
$encounteredImgElement = false; |
28
|
|
|
foreach ($this->children as $child) { |
29
|
|
|
if ($child->getType() == Token::COMMENT) { |
30
|
|
|
continue; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
if ($child->getType() !== Token::ELEMENT) { |
34
|
|
|
$logger->debug('Removing ' . $child); |
35
|
|
|
$this->removeChild($child); |
36
|
|
|
|
37
|
|
|
continue; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if ($child instanceof ScriptSupporting) { |
41
|
|
|
continue; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if ($child->getName() == 'img') { |
45
|
|
|
if ($encounteredImgElement) { |
46
|
|
|
$logger->debug('Removing ' . $child . '. Only one "img" element allowed as child of "picture" element.'); |
47
|
|
|
$this->removeChild($child); |
48
|
|
|
|
49
|
|
|
continue; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$encounteredImgElement = true; |
53
|
|
|
|
54
|
|
|
continue; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ($child->getName() != 'source') { |
58
|
|
|
$logger->debug('Removing ' . $child . '. Only one "img" element and zero to many "source" elements allowed as children of the "picture" element.'); |
59
|
|
|
$this->removeChild($child); |
60
|
|
|
|
61
|
|
|
continue; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return true; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|