1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package s9e\TextFormatter |
5
|
|
|
* @copyright Copyright (c) 2010-2023 The s9e authors |
6
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License |
7
|
|
|
*/ |
8
|
|
|
namespace s9e\TextFormatter\Plugins\Autovideo; |
9
|
|
|
|
10
|
|
|
use s9e\TextFormatter\Configurator\Helpers\RegexpBuilder; |
11
|
|
|
use s9e\TextFormatter\Plugins\ConfiguratorBase; |
12
|
|
|
|
13
|
|
|
class Configurator extends ConfiguratorBase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string[] File extensions allowed in URLs |
17
|
|
|
*/ |
18
|
|
|
public array $fileExtensions = ['mov', 'mp4', 'ogg', 'webm']; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string Name of attribute that stores the video's URL |
22
|
|
|
*/ |
23
|
|
|
protected $attrName = 'src'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $quickMatch = '://'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $regexp; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string Name of the tag used to represent videos |
37
|
|
|
*/ |
38
|
|
|
protected $tagName = 'VIDEO'; |
39
|
|
|
|
40
|
9 |
|
public function finalize(): void |
41
|
|
|
{ |
42
|
9 |
|
$this->updateRegexp(); |
43
|
|
|
} |
44
|
1 |
|
|
45
|
|
|
/** |
46
|
|
|
* Creates the tag used by this plugin |
47
|
|
|
* |
48
|
8 |
|
* @return void |
49
|
|
|
*/ |
50
|
|
|
protected function setUp() |
51
|
8 |
|
{ |
52
|
8 |
|
$this->updateRegexp(); |
53
|
|
|
|
54
|
|
|
if (isset($this->configurator->tags[$this->tagName])) |
55
|
8 |
|
{ |
56
|
|
|
return; |
57
|
|
|
} |
58
|
8 |
|
|
59
|
|
|
// Create a tag |
60
|
|
|
$tag = $this->configurator->tags->add($this->tagName); |
61
|
|
|
|
62
|
|
|
// Add an attribute using the default url filter |
63
|
|
|
$filter = $this->configurator->attributeFilters['#url']; |
64
|
|
|
$tag->attributes->add($this->attrName)->filterChain->append($filter); |
65
|
|
|
|
66
|
|
|
// Set the default template |
67
|
|
|
$tag->template = '<video controls="" src="{@' . $this->attrName . '}"/>'; |
68
|
|
|
|
69
|
|
|
// Allow URL tags to be used as fallback |
70
|
|
|
$tag->rules->allowChild('URL'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
protected function updateRegexp(): void |
74
|
|
|
{ |
75
|
|
|
$this->regexp = '#\\bhttps?://[-.\\w]+/(?:[-+.:/\\w]|%[0-9a-f]{2}|\\(\\w+\\))+\\.' . RegexpBuilder::fromList($this->fileExtensions, ['caseInsensitive' => true, 'delimiter' => '#', 'unicode' => false]) . '(?!\\S)#i'; |
76
|
|
|
} |
77
|
|
|
} |