-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathembed-extras.php
117 lines (82 loc) · 3.7 KB
/
embed-extras.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
<?php
/*
Plugin Name: Cogdog Auto Embed Extras
Plugin URI: https://github.com/cogdog/embed-extras
Description: Enables a few more auto embeds for padlet, Internet Archive audio/video, Vocaroo, Sodphonic, Mastodon
Version: 0.5
License: GPLv2
Author: Alan Levine
Author URI: https://cog.dog
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
define('EMBED_EXTRAS_PLUGIN_VERSION', '0.5');
// scripts and styles get in the queue
add_action('wp_enqueue_scripts', 'embed_extras_enqueue_stuff');
function embed_extras_enqueue_stuff() {
wp_enqueue_style( 'embed-extras' , plugin_dir_url( __FILE__ ) . 'css/embed-extras.css', null, EMBED_EXTRAS_PLUGIN_VERSION);
wp_register_script( 'h5p-resizer', plugin_dir_url( __FILE__ ) . 'js/h5p-resizer.js' );
wp_enqueue_script( 'h5p-resizer' );
}
add_action( 'init', 'embed_extras_register_embeds' );
function embed_extras_register_embeds() {
// enable padlet as an oembed provider
wp_oembed_add_provider( "https://padlet.com/*", "https://padlet.com/oembed/", false );
// enable internet archive
wp_embed_register_handler(
'archive_org',
'#^https://archive\.org\/details\/(.*)$#i',
'embed_extras_handler_archive_org'
);
// handler for vocaroo audio
wp_embed_register_handler(
'vocaroo',
'#^https?:\/\/(vocaroo\.com|voca\.ro)\/([a-zAA-Z0-9]+)$#i',
'embed_extras_handler_vocaroo'
);
// handler for sodaphonic boombox audio
wp_embed_register_handler(
'sodaphonic',
'#^https?:\/\/sodaphonic.com\/audio\/([a-zAA-Z0-9]+)(.*)$#i',
'embed_extras_handler_sodaphonic'
);
// handler for mastodon
wp_embed_register_handler(
'mastodon',
'#^https?:\/\/((?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9])\/@([a-zA-Z0-9\_]+)\/(\d+)$#i',
'embed_extras_handler_mastodon'
);
// handler for pixelfed
wp_embed_register_handler(
'pixelfed',
'#^https?:\/\/((?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9])\/p\/[a-zA-Z0-9\_]+\/(\d+)$#i',
'embed_extras_handler_pixelfed'
);
}
function embed_extras_handler_archive_org( $matches, $attr, $url, $rawattr ) {
$embed = sprintf(
'<div class="archive-org-embed"><iframe src="https://archive.org/embed/%1$s" width="640" height="480" style="border:none" frameborder="0" allowTransparency="true"></iframe>',
esc_attr($matches[1])
);
return $embed;
}
function embed_extras_handler_vocaroo( $matches, $attr, $url, $rawattr ) {
$embed = '<iframe width="100%" height="60" src="https://vocaroo.com/embed/' . esc_attr($matches[2]) .' ?autoplay=0" frameborder="0" allow="autoplay"></iframe>';
return $embed;
}
function embed_extras_handler_sodaphonic( $matches, $attr, $url, $rawattr ) {
$embed = '<iframe width="100%" height="156" scrolling="no" frameborder="no" allow="autoplay" src="https://sodaphonic.com/embed/' . esc_attr($matches[1]) .'"></iframe>';
return $embed;
}
function embed_extras_handler_mastodon( $matches, $attr, $url, $rawattr ) {
$embed = '<iframe src="https://' . esc_attr($matches[1]) . '/@' . esc_attr($matches[2]) . '/' . esc_attr($matches[3]) . '/embed" class="mastodon-embed" style="max-width: 100%; border: 0" width="400" allowfullscreen="allowfullscreen"></iframe><script src="https://' . esc_attr($matches[1]) . '/embed.js" async="async"></script>';
return $embed;
}
function embed_extras_handler_pixelfed( $matches, $attr, $url, $rawattr ) {
// handler for pixelfed embeds
$embed = '<iframe src="' . esc_attr($matches[0]) . '/embed?caption=false&likes=false&layout=compact" class="pixelfed__embed" style="max-width:100%; min-height:600px; border:0" width="600" allowfullscreen="allowfullscreen"></iframe><script async defer src="https:/' . esc_attr($matches[1]) . '/embed.js" async="async"></script>';
return $embed;
}
?>