/
oembed.php
64 lines (51 loc) · 1.49 KB
/
oembed.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
<?php
require 'core/oembed.php';
/**
* oEmbed field method: $page->video()->oembed()
*/
field::$methods['oembed'] = function($field, $args = array()) {
$oembed = new OEmbed($field->value);
// autoplay setting
if((isset($args['autoplay']) and $args['autoplay'] == true) or c::get('oembed.autoplay', false)) {
$oembed->autoplay = true;
}
// custom thumbnail
if (isset($args['thumbnail'])) {
$oembed->thumb->set($args['thumbnail']);
}
return $oembed->get($args);
};
/**
* oEmbed Kirbytext tag: (oembed: https://youtube.com/watch?v=wZZ7oFKsKzY)
*/
kirbytext::$tags['oembed'] = array(
'attr' => array(
'class',
'thumb',
'autoplay',
'artwork',
'visual',
'size',
'color',
'jsapi',
),
'html' => function($tag) {
$args = array(
'class' => $tag->attr('class', false),
'artwork' => $tag->attr('artwork', c::get('oembed.defaults.artwork', 'true')),
'visual' => $tag->attr('visual', c::get('oembed.defaults.visual', 'true')),
'size' => $tag->attr('size', c::get('oembed.defaults.size', 'default')),
'jsapi' => $tag->attr('jsapi', false)
);
$oembed = new OEmbed($tag->attr('oembed'));
// autoplay setting
if($tag->attr('autoplay', c::get('oembed.autoplay', false)) == 'true') {
$oembed->autoplay = true;
}
// custom thumbnail
if($tag->attr('thumb', false)) {
$oembed->thumb->set($tag->file($tag->attr('thumb'))->url());
}
return $oembed->get($args);
}
);