librevideojs-html5-player.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?php
  2. /*
  3. Plugin Name: LibreVideoJS HTML5 Player
  4. Version: 1.0.4
  5. Plugin URI: https://wordpress.org/plugins/librevideojs-html5-player
  6. Author: <a href="https://conocimientoslibres.tuxfamily.org">Jesús Eduardo</a>, <a href="http://www.freakspot.net/">Jorge Maldonado</a>
  7. 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>.
  8. Text Domain: librevideojs-html5-player
  9. License: GPLv3 or later
  10. Domain Path: /languages
  11. */
  12. if (!defined('ABSPATH')) {
  13. exit;
  14. }
  15. include_once 'GWP_bs3_panel_shortcode.php';
  16. if (!class_exists('LIBREVIDEOJS_HTML5_PLAYER')) {
  17. class LIBREVIDEOJS_HTML5_PLAYER {
  18. var $plugin_version = '1.0.4';
  19. function __construct() {
  20. define('LIBREVIDEOJS_HTML5_PLAYER_VERSION', $this->plugin_version);
  21. $this->plugin_includes();
  22. }
  23. function plugin_includes() {
  24. if (is_admin()) {
  25. add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
  26. }
  27. add_action('plugins_loaded', array($this, 'plugins_loaded_handler'));
  28. add_action('wp_enqueue_scripts', 'librevideojs_html5_player_enqueue_scripts');
  29. add_action('admin_menu', array($this, 'add_options_menu'));
  30. add_action('wp_head', 'librevideojs_html5_player_header');
  31. add_shortcode('librevideojs_video', 'librevideojs_html5_video_embed_handler');
  32. //allows shortcode execution in the widget, excerpt and content
  33. add_filter('widget_text', 'do_shortcode');
  34. add_filter('the_excerpt', 'do_shortcode', 11);
  35. add_filter('the_content', 'do_shortcode', 11);
  36. }
  37. function plugin_url() {
  38. if ($this->plugin_url)
  39. return $this->plugin_url;
  40. return $this->plugin_url = plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__));
  41. }
  42. function plugin_action_links($links, $file) {
  43. if ($file == plugin_basename(dirname(__FILE__) . '/librevideojs-html5-player.php')) {
  44. $links[] = '<a href="options-general.php?page=librevideojs-html5-player-settings">'.__('Settings', 'librevideojs-html5-player').'</a>';
  45. }
  46. return $links;
  47. }
  48. function plugins_loaded_handler()
  49. {
  50. load_plugin_textdomain('librevideojs-html5-player', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');
  51. }
  52. function add_options_menu() {
  53. if (is_admin()) {
  54. add_options_page(__('LibreVideoJS Settings', 'librevideojs-html5-player'), __('LibreVideoJS HTML5 Player', 'librevideojs-html5-player'), 'manage_options', 'librevideojs-html5-player-settings', array($this, 'options_page'));
  55. }
  56. }
  57. function options_page() {
  58. $url = "https://wordpress.org/plugins/librevideojs-html5-player";
  59. $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));
  60. ?>
  61. <div class="wrap"><h2>LibreVideoJS HTML5 Player - v<?php echo $this->plugin_version; ?></h2>
  62. <div class="update-nag"><?php echo $link_text;?></div>
  63. </div>
  64. <?php
  65. }
  66. }
  67. $GLOBALS['easy_video_player'] = new LIBREVIDEOJS_HTML5_PLAYER();
  68. new GWP_bs3_panel_shortcode();
  69. }
  70. function librevideojs_html5_player_enqueue_scripts() {
  71. if (!is_admin()) {
  72. $plugin_url = plugins_url('', __FILE__);
  73. wp_register_script('librevideojs', $plugin_url . '/librevideojs/js/cliplibrejs.dev.js', true);
  74. wp_enqueue_script('librevideojs');
  75. wp_register_style('librevideojs-mixteal-style', $plugin_url . '/librevideojs/css/mix-material/mix-teal.min.css');
  76. wp_enqueue_style('librevideojs-mixteal-style');
  77. wp_register_style('librevideojs-mixred-style', $plugin_url . '/librevideojs/css/mix-material/mix-red.min.css');
  78. wp_enqueue_style('librevideojs-mixred-style');
  79. //Abrir un directorio conocido, y proceder a leer su contenido
  80. // foreach(glob($plugin_url . '/librevideojs/css/mix-material/*.min.css') as $theme) {
  81. // wp_register_style('librevideojs-mixred-style', $theme);
  82. // wp_enqueue_style('librevideojs-mixred-style');
  83. // }
  84. wp_register_style('librevideojs-material-style', $plugin_url . '/librevideojs/css/librevideojs-material/libre-skin-teal.min.css');
  85. wp_enqueue_style('librevideojs-material-style');
  86. wp_register_style('librevideojs-style', $plugin_url . '/librevideojs-html5-player.css');
  87. wp_enqueue_style('librevideojs-style');
  88. wp_register_script('librevideojs-selector', $plugin_url . '/librevideojs/selector/video-quality-selector.min.js', true);
  89. wp_enqueue_script('librevideojs-selector');
  90. wp_register_style('librevideojs-selector', $plugin_url . '/librevideojs/selector/video-quality-selector.min.css');
  91. wp_enqueue_style('librevideojs-selector');
  92. }
  93. }
  94. function librevideojs_html5_player_header() {
  95. if (!is_admin()) {
  96. $config = '<!-- This site is embedding videos using the LibreVideoJS HTML5 Player plugin v' . LIBREVIDEOJS_HTML5_PLAYER_VERSION . ' - https://conocimientoslibres.tuxfamily.org -->';
  97. echo $config;
  98. }
  99. }
  100. function librevideojs_html5_video_embed_handler($atts, $content=null) {
  101. extract(shortcode_atts(array(
  102. 'url' => '',
  103. 'url_calidad' => '',
  104. 'code' => '',
  105. 'selector' => '',
  106. 'width' => '',
  107. 'controls' => '',
  108. 'preload' => 'auto',
  109. 'autoplay' => 'false',
  110. 'loop' => '',
  111. 'muted' => '',
  112. 'poster' => '',
  113. 'skin' => '',
  114. 'class' => '',
  115. ), $atts));
  116. if(empty($url)){
  117. return __('you need to specify the src of the video file', 'librevideojs-html5-player');
  118. }
  119. //src
  120. $src = '<source data-res="'.$url_calidad.'" src="'.$url.'" type="video/'.$code.'"/>';
  121. //resolution selector
  122. if (!empty($selector)) {
  123. $resolution = "$selector";
  124. }
  125. else {
  126. $resolution = "$url_calidad";
  127. }
  128. //controls
  129. if($controls == "false") {
  130. $controls = "";
  131. }
  132. else{
  133. $controls = " controls";
  134. }
  135. //preload
  136. if($preload == "metadata") {
  137. $preload = ' preload="metadata"';
  138. }
  139. else if($preload == "none") {
  140. $preload = ' preload="none"';
  141. }
  142. else{
  143. $preload = ' preload="auto"';
  144. }
  145. //autoplay
  146. if($autoplay == "true"){
  147. $autoplay = " autoplay";
  148. }
  149. else{
  150. $autoplay = "";
  151. }
  152. //loop
  153. if($loop == "true"){
  154. $loop = " loop";
  155. }
  156. else{
  157. $loop = "";
  158. }
  159. //muted
  160. if($muted == "true"){
  161. $muted = " muted";
  162. }
  163. else{
  164. $muted = "";
  165. }
  166. // Tracks
  167. if(!is_null( $content )){
  168. $track = do_shortcode($content);
  169. }
  170. else{
  171. $track = "";
  172. }
  173. // Calidades
  174. if(!is_null( $content = '' )){
  175. $calidades = do_shortcode($content);
  176. }
  177. else{
  178. $calidades = "";
  179. }
  180. //skin theme
  181. if (!empty($skin)) {
  182. $_skin = "$skin";
  183. }
  184. else{
  185. $_skin= "materialteal";
  186. }
  187. //poster
  188. if(!empty($poster)) {
  189. $poster = " poster='$poster'";
  190. }
  191. $player = "librevideojs" . uniqid();
  192. //custom style
  193. $style = '';
  194. if(!empty($width)){
  195. $style = <<<EOT
  196. <style>
  197. $player {
  198. max-width:{$width}px;
  199. }
  200. </style>
  201. EOT;
  202. }
  203. $output = <<<EOT
  204. <!-- Begin LibreVideoJS -->
  205. <video id="$player" class="cliplibre-js-responsive-container librevjs-hd cliplibre-js librevjs-libre-{$_skin}-skin" {$controls}{$preload}{$autoplay}{$loop}{$muted}{$poster} data-setup='{}'>
  206. {$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>
  207. </video>
  208. <script type="text/javascript">
  209. // @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
  210. cliplibrejs('$player',{plugins:{resolutionSelector:{force_types:['video/webm','video/ogg','video/mp4'],default_res:"$resolution"}},nativeControlsForTouch: false});
  211. // @license-end
  212. </script>
  213. $style
  214. <br>
  215. <!-- End LibreVideoJS -->
  216. EOT;
  217. return $output;
  218. }
  219. /*Trayendo los subtitulos mediante [track]*/
  220. function track_shortcode($atts, $content=null){
  221. extract(shortcode_atts(array(
  222. 'kind' => '',
  223. 'subt' => '',
  224. 'srclang' => '',
  225. 'label' => '',
  226. 'default' => '',
  227. ), $atts));
  228. if($kind){
  229. $kind = " kind='$kind'";
  230. }
  231. if($subt){
  232. $subt = " src='$subt'";
  233. }
  234. if($srclang){
  235. $srclang = " srclang='$srclang'";
  236. }
  237. if($label){
  238. $label = " label='$label'";
  239. }
  240. if($default == "true" || $default == "default"){
  241. $default = " default";
  242. }
  243. else{
  244. $default = "";
  245. }
  246. $track = "<track" . $kind . $subt . $srclang . $label . $default . "/>\n\t\t";
  247. return $track;
  248. }
  249. add_shortcode('track', 'track_shortcode');
  250. /*Trayendo las calidades*/
  251. function calidades_shortcode($atts, $content=null){
  252. extract(shortcode_atts(array(
  253. 'lvjs_calidad' => '',
  254. 'src_video' => '',
  255. 'lvjs_code' => '',
  256. ), $atts));
  257. if ($lvjs_calidad) {
  258. $lvjs_calidad = " data-res='$lvjs_calidad'";
  259. }
  260. if ($src_video) {
  261. $src_video = " src='$src_video'";
  262. }
  263. $calidades = "<source" . $lvjs_calidad . $src_video . " type='video/".$lvjs_code."'/>\n\t\t";
  264. return $calidades;
  265. }
  266. add_shortcode('calidades', 'calidades_shortcode');
  267. ?>