-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgumlet-video.php
150 lines (130 loc) · 4.89 KB
/
gumlet-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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
/*
* Plugin Name: Gumlet Video
* Description: Video Hosting Plugin for WordPress
* Plugin URI: https://github.com/gumlet/wordpress-video-plugin
* Version: 1.0.3
* Author: Gumlet
* Author URI: https://www.gumlet.com
* Text Domain: gumlet-video
* License: GPLv2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
include('includes/video-options.php');
if (!defined('GUMLET_PLUGIN_VERSION')) {
define('GUMLET_PLUGIN_VERSION', '1.0');
}
function gumlet_oembed_provider() {
wp_oembed_add_provider( '#https?://play\.gumlet\.io/embed/.*#i', 'https://api.gumlet.com/v1/oembed', true );
wp_oembed_add_provider( '#https?://gumlet\.tv/watch/.*#i', 'https://api.gumlet.com/v1/oembed', true );
}
function gumlet_video_shortcode($atts)
{
$watermark = get_option('gumlet_video_settings');
$sc_args = shortcode_atts(
array(
'width' => '100%',
'height' => '100%',
'cc_enabled' => get_option('gumlet_default_cc_enabled'),
'id' => 'id',
'annotate'=> true,
'user_analytics'=> get_option('gumlet_default_user_analytics'),
'autoplay'=> false,
'loop'=> false,
'controls'=> 'on',
),
$atts
);
$width = $sc_args['width'];
$height = $sc_args['height'];
$id = $sc_args['id'];
$annotate = $sc_args['annotate'];
$cc_enabled = $sc_args['cc_enabled'];
$user_analytics = $sc_args['user_analytics'];
if (!$atts['id']) {
return "Required argument id for embedded video not found.";
} else {
$video = $id;
}
$watermark_text = '';
$logged_in = is_user_logged_in();
if($annotate && $logged_in) {
$current_user = wp_get_current_user();
if(isset($watermark['dynamic_watermark_name']) && $watermark['dynamic_watermark_name']) {
$watermark_text .= $current_user->display_name . " ";
}
if(isset($watermark['dynamic_watermark_email']) && $watermark['dynamic_watermark_email']) {
$watermark_text .= $current_user->user_email. " ";
}
if(isset($watermark['dynamic_watermark_user_id']) && $watermark['dynamic_watermark_user_id']) {
$watermark_text .= $current_user->ID;
}
}
$analytics_text = '';
if($user_analytics && $logged_in) {
$analytics_text = 'gm_user_id='.$current_user->ID.
'&gm_user_name='. urlencode($current_user->display_name).
'&gm_user_email='.$current_user->user_email;
}
$uniq = 'u' . wp_rand();
$url = "https://play.gumlet.io/embed/$video?";
if ($sc_args['autoplay']) {
$url .= "autoplay=true&";
}
if ($sc_args['loop']) {
$url .= "loop=true&";
}
if ($sc_args['controls'] == 'off') {
$url .= "disable_player_controls=false&";
}
if(!!$cc_enabled) {
$url .= "caption=true&";
}
if($watermark_text != '') {
$url .= "watermark_text=".$watermark_text."&";
}
if($analytics_text != '') {
$url .= $analytics_text;
}
if($width != "100%") {
$opening_div = '<div>';
$style = 'width="'.$width.'" height="'.$height.'" style="border:none;"';
$closing_div = '</div>';
} else {
$opening_div = '<div style="padding:56.25% 0 0 0;position:relative;">';
$style = 'style="border:none; position: absolute; top:0; left:0; height: 100%; width: 100%;"';
$closing_div = '</div>';
}
$output =
$opening_div.'
<iframe src="'.$url.'" id="'.$uniq.'" loading="lazy" title="Gumlet video player"' .$style.'
allow="accelerometer; gyroscope; autoplay; encrypted-media; picture-in-picture; fullscreen;" frameborder="0"></iframe>'.
$closing_div;
return $output;
}
add_shortcode('gumlet', 'gumlet_video_shortcode');
function gumlet_video_plugin_admin_action_links($links, $file)
{
if ($file === plugin_basename(__FILE__)) {
$settings_link = '<a href="options-general.php?page=gumlet-video-options">Settings</a>';
array_unshift($links, $settings_link);
}
return $links;
}
add_filter('plugin_action_links', 'gumlet_video_plugin_admin_action_links', 10, 2);
register_activation_hook(__FILE__, 'gumlet_video_plugin_activate');
add_action( 'init', 'gumlet_oembed_provider' );
function gumlet_video_plugin_activate()
{
// plugin activation code here...
if (!get_option('gumlet_video_settings')) {
update_option('gumlet_video_settings', ["dynamic_watermark_email" => 0, "dynamic_watermark_name"=> 0, "dynamic_watermark_user_id"=> 0]);
}
if(!get_option('gumlet_default_cc_enabled')) {
update_option('gumlet_default_cc_enabled', 1);
}
if(!get_option('gumlet_default_user_analytics')) {
update_option('gumlet_default_user_analytics', 1);
}
}