1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Groundskeeper\Tokens\Elements; |
4
|
|
|
|
5
|
|
|
use Groundskeeper\Configuration; |
6
|
|
|
use Groundskeeper\Tokens\Element; |
7
|
|
|
use Groundskeeper\Tokens\ElementTypes\EmbeddedContent; |
8
|
|
|
use Groundskeeper\Tokens\ElementTypes\FlowContent; |
9
|
|
|
use Groundskeeper\Tokens\ElementTypes\InteractiveContent; |
10
|
|
|
use Groundskeeper\Tokens\ElementTypes\OpenElement; |
11
|
|
|
use Groundskeeper\Tokens\ElementTypes\PhrasingContent; |
12
|
|
|
use Groundskeeper\Tokens\ElementTypes\TransparentElement; |
13
|
|
|
use Groundskeeper\Tokens\Token; |
14
|
|
|
use Psr\Log\LoggerInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* "video" element |
18
|
|
|
* |
19
|
|
|
* https://html.spec.whatwg.org/multipage/semantics.html#the-video-element |
20
|
|
|
*/ |
21
|
|
|
class Video extends OpenElement implements FlowContent, PhrasingContent, EmbeddedContent, InteractiveContent, TransparentElement |
22
|
|
|
{ |
23
|
|
View Code Duplication |
protected function getAllowedAttributes() |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$videoAllowedAttributes = array( |
26
|
|
|
'/^src$/i' => Element::ATTR_URI, |
27
|
|
|
'/^crossorigin$/i' => Element::ATTR_CS_STRING, |
28
|
|
|
'/^poster$/i' => Element::ATTR_URI, |
29
|
|
|
'/^preload$/i' => Element::ATTR_CI_ENUM . '("","none","metadata","auto"|"")', |
30
|
|
|
'/^autoplay$/i' => Element::ATTR_BOOL, |
31
|
|
|
'/^mediagroup$/i' => Element::ATTR_CS_STRING, |
32
|
|
|
'/^loop$/i' => Element::ATTR_BOOL, |
33
|
|
|
'/^muted$/i' => Element::ATTR_BOOL, |
34
|
|
|
'/^controls$/i' => Element::ATTR_BOOL, |
35
|
|
|
'/^width$/i' => Element::ATTR_INT, |
36
|
|
|
'/^height$/i' => Element::ATTR_INT |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
return array_merge( |
40
|
|
|
$videoAllowedAttributes, |
41
|
|
|
parent::getAllowedAttributes() |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
View Code Duplication |
protected function doClean(LoggerInterface $logger) |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) { |
48
|
|
|
$hasSrc = $this->hasAttribute('src'); |
49
|
|
|
foreach ($this->children as $child) { |
50
|
|
|
if ($child->getType() == Token::COMMENT) { |
51
|
|
|
continue; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if ($child->getType() == Token::TEXT) { |
55
|
|
|
continue; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if ($child->getType() !== Token::ELEMENT) { |
59
|
|
|
$logger->debug('Removing ' . $child . '. Only elements allowed as children of "video" element.'); |
60
|
|
|
$this->removeChild($child); |
61
|
|
|
|
62
|
|
|
continue; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if (!$hasSrc && $child->getName() == 'source') { |
66
|
|
|
continue; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if ($child->getName() == 'track') { |
70
|
|
|
continue; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if ($child instanceof TransparentElement && |
74
|
|
|
$child->isTransparentElement()) { |
75
|
|
|
continue; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$logger->debug('Removing ' . $child . '. Only "source", "track", and transparent elements allowed as children of "video" element.'); |
79
|
|
|
$this->removeChild($child); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return true; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function isInteractiveContent() |
87
|
|
|
{ |
88
|
|
|
return $this->hasAttribute('controls'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function isTransparentElement() |
92
|
|
|
{ |
93
|
|
|
/// @todo Implement this. Complicated checks involved. |
94
|
|
|
return true; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.