-
Notifications
You must be signed in to change notification settings - Fork 1
/
utream-for-wordpress.php
54 lines (49 loc) · 2.2 KB
/
utream-for-wordpress.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
<?php
/*
Plugin Name: UStream for WordPress
Plugin URI: https://www.hoyce.com/wordpress-plugins/
Description: Add easy to use functionality to embed UStrem videos and broadcasts.
Version: 2.3.1
Author: Niklas Olsson
Author URI: https://www.hoyce.com
License: GPL 2.0, @see http://www.gnu.org/licenses/gpl-2.0.html
*/
Class ustream_for_wordpress {
static function secure_embed_handler($matches, $attr, $url, $rawattr) {
$request = new WP_Http;
$result = $request->request( 'https://www.ustream.tv/oembed?url='.$url );
$ustream = json_decode($result['body']);
if(isset($ustream->html)) {
return str_replace('http://www.ustream.tv/embed/', 'https://www.ustream.tv/embed/', $ustream->html);
}
}
static function oembed_provider() {
if(is_ssl()) {
wp_embed_register_handler( 'ustream', '/http(s)?:\/\/(www\.)?ustream\.tv\/.{0,}/i', array('ustream_for_wordpress', 'secure_embed_handler'));
} else {
wp_oembed_add_provider( '/http(s)?:\/\/(www\.)?ustream\.tv\/.{0,}/i', 'http://www.ustream.tv/oembed', true );
}
}
// Maintain backward compatibility of this plugin
static function get_ustream_code($atts, $content=null) {
extract(shortcode_atts(array('cid' => '', 'vid' => ''), $atts));
if (is_numeric($cid)) {
if(is_ssl()) {
return ustream_for_wordpress::secure_embed_handler(null, null, 'https://www.ustream.tv/channel/'.$cid, null);
} else {
return wp_oembed_get('http://www.ustream.tv/channel/'.$cid);
}
} else if (is_numeric($vid)) {
if(is_ssl()) {
return ustream_for_wordpress::secure_embed_handler(null, null, 'https://www.ustream.tv/recorded/'.$vid, null);
} else {
return wp_oembed_get('http://www.ustream.tv/recorded/'.$vid);
}
} else {
return 'Error: Neither the "cid" nor the "vid" was passed to the ustream tag!';
}
}
}
add_action( 'init', array('ustream_for_wordpress', 'oembed_provider') );
// Maintain backward compatibility of this plugin
add_shortcode('ustream', array('ustream_for_wordpress', 'get_ustream_code'));