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
|
|
|
* "audio" element |
18
|
|
|
* |
19
|
|
|
* https://html.spec.whatwg.org/multipage/semantics.html#the-audio-element |
20
|
|
|
*/ |
21
|
|
|
class Audio extends OpenElement implements FlowContent, PhrasingContent, EmbeddedContent, InteractiveContent, TransparentElement |
22
|
|
|
{ |
23
|
|
|
protected function getAllowedAttributes() |
24
|
|
|
{ |
25
|
|
|
$audioAllowedAttributes = array( |
26
|
|
|
'/^src$/i' => Element::ATTR_URI, |
27
|
|
|
'/^crossorigin$/i' => Element::ATTR_CS_STRING, |
28
|
|
|
'/^preload$/i' => Element::ATTR_CI_ENUM . '("","none","metadata","auto"|"")', |
29
|
|
|
'/^autoplay$/i' => Element::ATTR_BOOL, |
30
|
|
|
'/^mediagroup$/i' => Element::ATTR_CS_STRING, |
31
|
|
|
'/^loop$/i' => Element::ATTR_BOOL, |
32
|
|
|
'/^muted$/i' => Element::ATTR_BOOL, |
33
|
|
|
'/^controls$/i' => Element::ATTR_BOOL |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
return array_merge( |
37
|
|
|
$audioAllowedAttributes, |
38
|
|
|
parent::getAllowedAttributes() |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
protected function removeInvalidChildren(LoggerInterface $logger) |
43
|
|
|
{ |
44
|
|
|
$hasSrc = $this->hasAttribute('src'); |
45
|
|
|
foreach ($this->children as $child) { |
46
|
|
|
if ($child->getType() == Token::COMMENT) { |
47
|
|
|
continue; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if ($child->getType() == Token::TEXT) { |
51
|
|
|
continue; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if ($child->getType() !== Token::ELEMENT) { |
55
|
|
|
$logger->debug('Removing ' . $child . '. Only elements allowed as children of "audio" element.'); |
56
|
|
|
$this->removeChild($child); |
57
|
|
|
|
58
|
|
|
continue; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if (!$hasSrc && $child->getName() == 'source') { |
62
|
|
|
continue; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if ($child->getName() == 'track') { |
66
|
|
|
continue; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if ($child instanceof TransparentElement && |
70
|
|
|
$child->isTransparentElement()) { |
71
|
|
|
continue; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$logger->debug('Removing ' . $child . '. Only "source", "track", and transparent elements allowed as children of "audio" element.'); |
75
|
|
|
$this->removeChild($child); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function isInteractiveContent() |
80
|
|
|
{ |
81
|
|
|
return $this->hasAttribute('controls'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function isTransparentElement() |
85
|
|
|
{ |
86
|
|
|
/// @todo Implement this. Complicated checks involved. |
87
|
|
|
return true; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|