diff options
Diffstat (limited to 'librevideojs-html5-player.php')
-rw-r--r-- | librevideojs-html5-player.php | 272 |
1 files changed, 272 insertions, 0 deletions
diff --git a/librevideojs-html5-player.php b/librevideojs-html5-player.php new file mode 100644 index 0000000..c6215e1 --- /dev/null +++ b/librevideojs-html5-player.php @@ -0,0 +1,272 @@ +<?php +/* +Plugin Name: LibreVideoJS HTML5 Player +Version: 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 Video 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 +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.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() { + if (!is_admin()) { + $plugin_url = plugins_url('', __FILE__); + wp_enqueue_script('jquery'); + wp_register_script('librevideojs', $plugin_url . '/librevideojs/js/cliplibrejs.dev.js', true); + wp_enqueue_script('librevideojs'); + wp_register_style('librevideojs', $plugin_url . '/librevideojs/css/librevideojs-material/libre-skin-teal.min.css'); + wp_enqueue_style('librevideojs'); + 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.min.js', true); + wp_enqueue_script('librevideojs-selector'); + wp_register_style('librevideojs-selector', $plugin_url . '/librevideojs/selector/video-quality-selector.min.css'); + wp_enqueue_style('librevideojs-selector'); + } +} + +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) { + extract(shortcode_atts(array( + 'url' => '', + 'rsd' => '', + 'sd' => '', + 'msd' => '', + 'umsd' => '', + 'code' => '', + 'selector' => '', + 'width' => '', + 'controls' => '', + 'preload' => 'auto', + 'autoplay' => 'false', + 'loop' => '', + 'muted' => '', + 'poster' => '', + 'class' => '', + 'subten' => '', + 'subtes' => '', + 'subtpt' => '', + 'subtit' => '', + 'subtfr' => '', + 'subtgl' => '', + 'subteo' => '', + ), $atts)); + + if(empty($url)){ + return __('you need to specify the src of the video file', 'librevideojs-html5-player'); + } + //src + $src = '<source data-res="720p" src="'.$url.'" type="video/'.$code.'" />'; + if (!empty($rsd)) { + $rsd = '<source data-res="480p" src="'.$rsd.'" type="video/'.$code.'" />'; + $src = $src.$rsd; + } + if (!empty($sd)) { + $sd = '<source data-res="360p" src="'.$sd.'" type="video/'.$code.'" />'; + $src = $src.$sd; + } + if (!empty($msd)) { + $msd = '<source data-res="240p" src="'.$msd.'" type="video/'.$code.'" />'; + $src = $src.$msd; + } + if (!empty($umsd)) { + $umsd = '<source data-res="144p" src="'.$umsd.'" type="video/'.$code.'" />'; + $src = $src.$umsd; + } + + //subtitles + if (!empty($subtes)) { + $subtitl_es = '<track kind="captions" src="'.$subtes.'" srclang="es" label="Español"/>'; + }else { + $subtitl_es = ""; + } + + if (!empty($subten)){ + $subtitl_en = '<track kind="captions" src="'.$subten.'" srclang="en" label="English"/>'; + } else { + $subtitl_en = ""; + } + + if (!empty($subtpt)){ + $subtitl_pt = '<track kind="captions" src="'.$subtpt.'" srclang="pt" label="Portuguese"/>'; + } else { + $subtitl_pt = ""; + } + + if (!empty($subtfr)){ + $subtitl_fr = '<track kind="captions" src="'.$subtfr.'" srclang="fr" label="Français"/>'; + } else { + $subtitl_fr = ""; + } + + if (!empty($subtgl)){ + $subtitl_gl = '<track kind="captions" src="'.$subtgl.'" srclang="gl" label="Galego"/>'; + } else { + $subtitl_gl = ""; + } + + if (!empty($subteo)){ + $subtitl_eo = '<track kind="captions" src="'.$subteo.'" srclang="eo" label="Esperanto"/>'; + } else { + $subtitl_eo = ""; + } + + //resolution selector + if (!empty($selector)) { + $resolution = "$selector"; + } + else { + $resolution = "720p"; + } + + //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 = ""; + } + //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 + <video id="$player" class="cliplibre-js-responsive-container librevjs-hd cliplibre-js librevjs-libre-skin" {$controls}{$preload}{$autoplay}{$loop}{$muted}{$poster} width="100%" height="auto" data-setup='{}'> + $src + $subtitl_es $subtitl_en $subtitl_pt $subtitl_fr $subtitl_gl $subtitl_eo + </video> + <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'],default_res:"$resolution"}},nativeControlsForTouch: false}); + // @license-end + </script> + $style + <br> +EOT; + return $output; +} |