aboutsummaryrefslogtreecommitdiffstats
path: root/librevideojs-html5-player.php
blob: a3ca25901eaba16120c8e6ef610f11717e6a4aac (plain)
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php
/*
Plugin Name: LibreVideoJS HTML5 Player
Version: 1.1.0
Plugin URI: https://wordpress.org/plugins/librevideojs-html5-player
Author: <a href="https://conocimientoslibres.tuxfamily.org">Jesús Eduardo</a>, <a href="http://www.freakspot.net/">Jorge Maldonado</a>
Description: Reproductor de vídeo Libre en Responsive Desing HTML5 para WordPress, construido sobre el ampliamente utilizado <a href="https://notabug.org/Heckyel/LibreVideoJS">LibreVideoJS</a> de la biblioteca del reproductor de vídeo HTML5. Le permite incrustar vídeo en tu post o página con HTML5 para los navegadores principales. Es compatible con <a href="https://www.gnu.org/software/librejs/free-your-javascript.html">LibreJS</a> de acuerdo con la filosofía <a href="https://www.gnu.org">GNU</a>.
Text Domain: librevideojs-html5-player
License: GPLv3 or later
Domain Path: /languages
*/

if (!defined('ABSPATH')) {
    exit;
}

include_once 'GWP_bs3_panel_shortcode.php';

if (!class_exists('LIBREVIDEOJS_HTML5_PLAYER')) {

    class LIBREVIDEOJS_HTML5_PLAYER {

        var $plugin_version = '1.1.0';

        function __construct() {
            define('LIBREVIDEOJS_HTML5_PLAYER_VERSION', $this->plugin_version);
            $this->plugin_includes();
        }

        function plugin_includes() {
            if (is_admin()) {
                add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
            }
            add_action('plugins_loaded', array($this, 'plugins_loaded_handler'));
            add_action('wp_enqueue_scripts', 'librevideojs_html5_player_enqueue_scripts');
            add_action('admin_menu', array($this, 'add_options_menu'));
            add_action('wp_head', 'librevideojs_html5_player_header');
            add_shortcode('librevideojs_video', 'librevideojs_html5_video_embed_handler');
            //allows shortcode execution in the widget, excerpt and content
            add_filter('widget_text', 'do_shortcode');
            add_filter('the_excerpt', 'do_shortcode', 11);
            add_filter('the_content', 'do_shortcode', 11);

        }

        function plugin_url() {
            if ($this->plugin_url)
                return $this->plugin_url;
            return $this->plugin_url = plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__));
        }

        function plugin_action_links($links, $file) {
            if ($file == plugin_basename(dirname(__FILE__) . '/librevideojs-html5-player.php')) {
                $links[] = '<a href="options-general.php?page=librevideojs-html5-player-settings">'.__('Settings', 'librevideojs-html5-player').'</a>';
            }
            return $links;
        }

        function plugins_loaded_handler()
        {
            load_plugin_textdomain('librevideojs-html5-player', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');
        }

        function add_options_menu() {
            if (is_admin()) {
                add_options_page(__('LibreVideoJS Settings', 'librevideojs-html5-player'), __('LibreVideoJS HTML5 Player', 'librevideojs-html5-player'), 'manage_options', 'librevideojs-html5-player-settings', array($this, 'options_page'));
            }
        }

        function options_page() {
            $url = "https://wordpress.org/plugins/librevideojs-html5-player";
            $link_text = sprintf(wp_kses(__('For detailed documentation please visit the plugin homepage <a target="_blank" href="%s">here</a>.', 'librevideojs-html5-player'), array('a' => array('href' => array(), 'target' => array()))), esc_url($url));
            ?>
            <div class="wrap"><h2>LibreVideoJS HTML5 Player - v<?php echo $this->plugin_version; ?></h2>
            <div class="update-nag"><?php echo $link_text;?></div>
            </div>
            <?php
        }
    }

    $GLOBALS['easy_video_player'] = new LIBREVIDEOJS_HTML5_PLAYER();
    new GWP_bs3_panel_shortcode();

}

function librevideojs_html5_player_enqueue_scripts() {
  global $post;
  if (strpos($post->post_content, '[librevideojs_video') !== false){
        $plugin_url = plugins_url('', __FILE__);
        wp_register_script('librevideojs', $plugin_url . '/librevideojs/js/cliplibrejs.dev.js', array(), LIBREVIDEOJS_HTML5_PLAYER_VERSION);
        wp_enqueue_script('librevideojs');
        wp_register_style('librevideojs-mix-master-style', $plugin_url . '/librevideojs/css/mix-material/master.css', array(), $ver='1.4');
        wp_enqueue_style('librevideojs-mix-master-style');
        wp_register_style('librevideojs-material-style', $plugin_url . '/librevideojs/css/librevideojs-material/master.css', array(), $ver='1.4');
        wp_enqueue_style('librevideojs-material-style');
        wp_register_style('librevideojs-style', $plugin_url . '/librevideojs-html5-player.css');
        wp_enqueue_style('librevideojs-style');
        wp_register_script('librevideojs-selector', $plugin_url . '/librevideojs/selector/video-quality-selector.js', array(), LIBREVIDEOJS_HTML5_PLAYER_VERSION);
        wp_enqueue_script('librevideojs-selector');
        wp_register_style('librevideojs-selector', $plugin_url . '/librevideojs/selector/video-quality-selector.css', array(), $ver = '1.4');
        wp_enqueue_style('librevideojs-selector');
    } else{
        return false;
    }
}

function librevideojs_html5_player_header() {
    if (!is_admin()) {
        $config = '<!-- This site is embedding videos using the LibreVideoJS HTML5 Player plugin v' . LIBREVIDEOJS_HTML5_PLAYER_VERSION . ' - https://conocimientoslibres.tuxfamily.org -->';
        echo $config;
    }
}

function librevideojs_html5_video_embed_handler($atts, $content=null) {
    extract(shortcode_atts(array(
        'url' => '',
        'url_calidad' => '',
        'code' => '',
        'selector' => '',
        'width' => '',
        'controls' => '',
        'preload' => 'auto',
        'autoplay' => 'false',
        'loop' => '',
        'muted' => '',
        'poster' => '',
        'skin' => '',
        'class' => '',
    ), $atts));

    if(empty($url)){
        return __('you need to specify the src of the video file', 'librevideojs-html5-player');
    }
    //src
    $src = '<source data-res="'.$url_calidad.'" src="'.$url.'" type="video/'.$code.'"/>';

    //resolution selector
    if (!empty($selector)) {
        $resolution = "$selector";
    }
    else {
        $resolution = "$url_calidad";
    }

    //controls
    if($controls == "false") {
        $controls = "";
    }
    else{
        $controls = " controls";
    }

    //preload
    if($preload == "metadata") {
        $preload = ' preload="metadata"';
    }
    else if($preload == "none") {
        $preload = ' preload="none"';
    }
    else{
        $preload = ' preload="auto"';
    }

    //autoplay
    if($autoplay == "true"){
        $autoplay = " autoplay";
    }
    else{
        $autoplay = "";
    }

    //loop
    if($loop == "true"){
        $loop = " loop";
    }
    else{
        $loop = "";
    }

    //muted
    if($muted == "true"){
        $muted = " muted";
    }
    else{
        $muted = "";
    }

    //Tracks
    if(!is_null( $content )){
      $track = do_shortcode($content);
    }
    else{
      $track = "";
    }

    //Qualities
    if(!is_null( $content = '' )){
      $calidades = do_shortcode($content);
    }
    else{
    $calidades = "";
    }

    //skin theme
    if (!empty($skin)) {
      $_skin = "$skin";
    }
    else{
      $_skin= "materialteal";
    }

    //poster
    if(!empty($poster)) {
        $poster = " poster='$poster'";
    }
    $player = "librevideojs" . uniqid();

    //custom style
    $style = '';
    if(!empty($width)){
        $style = <<<EOT
        <style>
        $player {
            max-width:{$width}px;
        }
        </style>
EOT;

    }
    $output = <<<EOT
    <!-- Begin LibreVideoJS -->
    <div class="LibreVideoJS">
    <video id="$player" class="cliplibre-js-responsive-container librevjs-hd cliplibre-js librevjs-libre-{$_skin}-skin" {$controls}{$preload}{$autoplay}{$loop}{$muted}{$poster} data-setup='{}'>
        {$src}\n\t\t{$calidades}{$track}<p class="no_html5">Sorry, this video will not work because your web browser does not support HTML5 video.<br>We recommend that you install a <a href='https://libreplanet.org/wiki/Libre_Browsers_Libre_Formats' target='_blank'> browser that respects the freedom and support free formats</a>!</p>
    </video>
    <div>
    <script type="text/javascript">
    // @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
    cliplibrejs('$player',{plugins:{resolutionSelector:{force_types:['video/webm','video/ogg','video/mp4'],default_res:"$resolution"}},nativeControlsForTouch: false});
    // @license-end
    </script>
    $style
    <br>
    <!-- End LibreVideoJS -->
EOT;
    return $output;
}

/*Adding subtitles using... [track]*/
function track_shortcode($atts, $content=null){
	extract(shortcode_atts(array(
		'kind' => '',
		'subt' => '',
		'srclang' => '',
		'label' => '',
		'default' => '',
	), $atts));

	if($kind){
    $kind = " kind='$kind'";
  }

	if($subt){
    $subt = " src='$subt'";
  }

	if($srclang){
    $srclang = " srclang='$srclang'";
  }

	if($label){
    $label = " label='$label'";
  }

	if($default == "true" || $default == "default"){
    $default = " default";
  }
	else{
    $default = "";
  }

	$track = "<track" . $kind . $subt . $srclang . $label . $default . "/>\n\t\t";

	return $track;
}
add_shortcode('track', 'track_shortcode');

/*Adding qualities*/
function calidades_shortcode($atts, $content=null){
  extract(shortcode_atts(array(
    'lvjs_calidad' => '',
    'src_video' => '',
    'lvjs_code' => '',
  ), $atts));

  if ($lvjs_calidad) {
    $lvjs_calidad = " data-res='$lvjs_calidad'";
  }
  if ($src_video) {
    $src_video = " src='$src_video'";
  }

  $calidades = "<source" . $lvjs_calidad . $src_video . " type='video/".$lvjs_code."'/>\n\t\t";

  return $calidades;
}
add_shortcode('calidades', 'calidades_shortcode');

?>