-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModsCodeDefinitions.php
65 lines (52 loc) · 2.13 KB
/
ModsCodeDefinitions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
// TODO: Quote mit Usernamen die '[' oder ']' enthalten können nicht geparsed werden.
class QuoteCodeDefinition extends JBBCode\CodeDefinition {
public function __construct()
{
parent::__construct();
$this->setTagName("quote");
}
public function asHtml(JBBCode\ElementNode $el)
{
$attribute = $el->getAttribute();
$content = "";
foreach($el->getChildren() as $child)
$content .= $child->getAsHtml();
if($attribute == null)
return '<blockquote>' . $content . '</blockquote>';
preg_match('/"(.*?)"]?$/i', $attribute, $matches);
return '<blockquote>' . $content . '<footer>'.htmlspecialchars($matches[1]).'</footer></blockquote>';
}
}
class YouTubeCodeDefinition extends JBBCode\CodeDefinition {
public function __construct()
{
parent::__construct();
$this->setTagName("video");
}
public function endsWith($content, $suffix)
{
return $suffix === '' || substr_compare($content, $suffix, -strlen($suffix)) === 0;
}
public function asHtml(JBBCode\ElementNode $el)
{
$content = "";
foreach($el->getChildren() as $child)
$content .= $child->getAsBBCode();
// TODO: Das geht doch bestimmt schöner.
if($this->endsWith($content, '.webm')){
return '<div class="embed-responsive embed-responsive-16by9"><video autoplay loop class="embed-responsive-item"><source src="'.$content.'" type=video/webm></video></div>';
}
else if($this->endsWith($content, '.mp4')){
return '<div class="embed-responsive embed-responsive-16by9"><video autoplay loop class="embed-responsive-item"><source src="'.$content.'" type=video/mp4></video></div>';
}
else {
$foundMatch = preg_match('/v=([A-z0-9=\-]+?)(&.*)?$/i', $content, $matches);
if($foundMatch)
return '<div class="embed-responsive embed-responsive-16by9"><iframe class="embed-responsive-item" src="http://www.youtube.com/embed/'.$matches[1].'"></iframe></div>';
else
return $el->getAsBBCode();
}
}
}
?>