-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo.php
124 lines (111 loc) · 3.57 KB
/
video.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
use Herbie\DI;
use Herbie\Hook;
class VideoPlugin
{
/**
* @var int
*/
private static $vimeoInstances = 0;
/**
* @var int
*/
private static $youtubeInstances = 0;
private static $config;
/**
* @return array
*/
public static function install()
{
static::$config = DI::get('Config');
if ((bool)static::$config->get('plugins.config.video.twig', false)) {
Hook::attach('twigInitialized', ['VideoPlugin', 'addTwigFunctions']);
}
if ((bool)static::$config->get('plugins.config.video.shortcode', true)) {
Hook::attach('shortcodeInitialized', ['VideoPlugin', 'addShortcodes']);
}
}
public static function addTwigFunctions($twig)
{
$twig->addFunction(
new Twig_SimpleFunction('video_vimeo', ['VideoPlugin', 'vimeo'], ['is_safe' => ['html']])
);
$twig->addFunction(
new Twig_SimpleFunction('video_youtube', ['VideoPlugin', 'youtube'], ['is_safe' => ['html']])
);
}
public static function addShortcodes($shortcode)
{
$shortcode->add('video_vimeo', ['VideoPlugin', 'vimeoShortcode']);
$shortcode->add('video_youtube', ['VideoPlugin', 'youtubeShortcode']);
}
/**
* @param string $id
* @param int $width
* @param int $height
* @param int $responsive
* @return string
* @see http://embedresponsively.com/
*/
public static function vimeo($id, $width = 480, $height = 320, $responsive = 1)
{
self::$vimeoInstances++;
$template = static::$config->get(
'plugins.config.video.template.vimeo',
'@plugin/video/templates/vimeo.twig'
);
return DI::get('Twig')->render($template, [
'src' => sprintf('//player.vimeo.com/video/%s', $id),
'width' => $width,
'height' => $height,
'responsive' => $responsive,
'class' => $responsive ? 'video-vimeo-responsive' : '',
'instances' => self::$vimeoInstances
]);
}
/**
* @param string $id
* @param int $width
* @param int $height
* @param int $responsive
* @return string
* @see http://embedresponsively.com/
*/
public static function youtube($id, $width = 480, $height = 320, $responsive = 1)
{
self::$youtubeInstances++;
$template = static::$config->get(
'plugins.config.video.template.youtube',
'@plugin/video/templates/youtube.twig'
);
return DI::get('Twig')->render($template, [
'src' => sprintf('//www.youtube.com/embed/%s?rel=0', $id),
'width' => $width,
'height' => $height,
'responsive' => $responsive,
'class' => $responsive ? 'video-youtube-responsive' : '',
'instances' => self::$youtubeInstances
]);
}
public static function youtubeShortcode($options)
{
$options = array_merge([
'id' => empty($options[0]) ? '' : $options[0],
'width' => 480,
'height' => 320,
'responsive' => 1
], $options);
return call_user_func_array(['VideoPlugin', 'youtube'], $options);
}
public static function vimeoShortcode($options)
{
$options = array_merge([
'id' => empty($options[0]) ? '' : $options[0],
'width' => 480,
'height' => 320,
'responsive' => 1
], $options);
return call_user_func_array(['VideoPlugin', 'vimeo'], $options);
}
}
VideoPlugin::install();