librevideojs-html5-player.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <?php
  2. /*
  3. Plugin Name: LibreVideoJS HTML5 Player
  4. Version: 1.1.0
  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.1.0';
  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. global $post;
  72. if (!is_admin() && strpos($post->post_content, '[librevideojs_video') !== false){
  73. $plugin_url = plugins_url('', __FILE__);
  74. wp_register_script('librevideojs', $plugin_url . '/librevideojs/js/cliplibrejs.dev.js', array(), LIBREVIDEOJS_HTML5_PLAYER_VERSION);
  75. wp_enqueue_script('librevideojs');
  76. wp_register_style('librevideojs-mix-master-style', $plugin_url . '/librevideojs/css/mix-material/master.css', array(), $ver='1.4');
  77. wp_enqueue_style('librevideojs-mix-master-style');
  78. wp_register_style('librevideojs-material-style', $plugin_url . '/librevideojs/css/librevideojs-material/master.css', array(), $ver='1.4');
  79. wp_enqueue_style('librevideojs-material-style');
  80. wp_register_style('librevideojs-style', $plugin_url . '/librevideojs-html5-player.css');
  81. wp_enqueue_style('librevideojs-style');
  82. wp_register_script('librevideojs-selector', $plugin_url . '/librevideojs/selector/video-quality-selector.js', array(), LIBREVIDEOJS_HTML5_PLAYER_VERSION);
  83. wp_enqueue_script('librevideojs-selector');
  84. wp_register_style('librevideojs-selector', $plugin_url . '/librevideojs/selector/video-quality-selector.css', array(), $ver = '1.4');
  85. wp_enqueue_style('librevideojs-selector');
  86. } else{
  87. return false;
  88. }
  89. }
  90. function librevideojs_html5_player_header() {
  91. if (!is_admin()) {
  92. $config = '<!-- This site is embedding videos using the LibreVideoJS HTML5 Player plugin v' . LIBREVIDEOJS_HTML5_PLAYER_VERSION . ' - https://conocimientoslibres.tuxfamily.org -->';
  93. echo $config;
  94. }
  95. }
  96. function librevideojs_html5_video_embed_handler($atts, $content=null) {
  97. extract(shortcode_atts(array(
  98. 'url' => '',
  99. 'url_calidad' => '',
  100. 'code' => '',
  101. 'selector' => '',
  102. 'width' => '',
  103. 'controls' => '',
  104. 'preload' => 'auto',
  105. 'autoplay' => 'false',
  106. 'loop' => '',
  107. 'muted' => '',
  108. 'poster' => '',
  109. 'skin' => '',
  110. 'class' => '',
  111. ), $atts));
  112. if(empty($url)){
  113. return __('you need to specify the src of the video file', 'librevideojs-html5-player');
  114. }
  115. //src
  116. $src = '<source data-res="'.$url_calidad.'" src="'.$url.'" type="video/'.$code.'"/>';
  117. //resolution selector
  118. if (!empty($selector)) {
  119. $resolution = "$selector";
  120. }
  121. else {
  122. $resolution = "$url_calidad";
  123. }
  124. //controls
  125. if($controls == "false") {
  126. $controls = "";
  127. }
  128. else{
  129. $controls = " controls";
  130. }
  131. //preload
  132. if($preload == "metadata") {
  133. $preload = ' preload="metadata"';
  134. }
  135. else if($preload == "none") {
  136. $preload = ' preload="none"';
  137. }
  138. else{
  139. $preload = ' preload="auto"';
  140. }
  141. //autoplay
  142. if($autoplay == "true"){
  143. $autoplay = " autoplay";
  144. }
  145. else{
  146. $autoplay = "";
  147. }
  148. //loop
  149. if($loop == "true"){
  150. $loop = " loop";
  151. }
  152. else{
  153. $loop = "";
  154. }
  155. //muted
  156. if($muted == "true"){
  157. $muted = " muted";
  158. }
  159. else{
  160. $muted = "";
  161. }
  162. //Tracks
  163. if(!is_null( $content )){
  164. $track = do_shortcode($content);
  165. }
  166. else{
  167. $track = "";
  168. }
  169. //Qualities
  170. if(!is_null( $content = '' )){
  171. $calidades = do_shortcode($content);
  172. }
  173. else{
  174. $calidades = "";
  175. }
  176. //skin theme
  177. if (!empty($skin)) {
  178. $_skin = "$skin";
  179. }
  180. else{
  181. $_skin= "materialteal";
  182. }
  183. //poster
  184. if(!empty($poster)) {
  185. $poster = " poster='$poster'";
  186. }
  187. $player = "librevideojs" . uniqid();
  188. //custom style
  189. $style = '';
  190. if(!empty($width)){
  191. $style = <<<EOT
  192. <style>
  193. $player {
  194. max-width:{$width}px;
  195. }
  196. </style>
  197. EOT;
  198. }
  199. $output = <<<EOT
  200. <!-- Begin LibreVideoJS -->
  201. <div class="LibreVideoJS">
  202. <video id="$player" class="cliplibre-js-responsive-container librevjs-hd cliplibre-js librevjs-libre-{$_skin}-skin" {$controls}{$preload}{$autoplay}{$loop}{$muted}{$poster} data-setup='{}'>
  203. {$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>
  204. </video>
  205. <div>
  206. <script type="text/javascript">
  207. // @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
  208. cliplibrejs('$player',{plugins:{resolutionSelector:{force_types:['video/webm','video/ogg','video/mp4'],default_res:"$resolution"}},nativeControlsForTouch: false});
  209. // @license-end
  210. </script>
  211. $style
  212. <br>
  213. <!-- End LibreVideoJS -->
  214. EOT;
  215. return $output;
  216. }
  217. /*Adding subtitles using... [track]*/
  218. function track_shortcode($atts, $content=null){
  219. extract(shortcode_atts(array(
  220. 'kind' => '',
  221. 'subt' => '',
  222. 'srclang' => '',
  223. 'label' => '',
  224. 'default' => '',
  225. ), $atts));
  226. if($kind){
  227. $kind = " kind='$kind'";
  228. }
  229. if($subt){
  230. $subt = " src='$subt'";
  231. }
  232. if($srclang){
  233. $srclang = " srclang='$srclang'";
  234. }
  235. if($label){
  236. $label = " label='$label'";
  237. }
  238. if($default == "true" || $default == "default"){
  239. $default = " default";
  240. }
  241. else{
  242. $default = "";
  243. }
  244. $track = "<track" . $kind . $subt . $srclang . $label . $default . "/>\n\t\t";
  245. return $track;
  246. }
  247. add_shortcode('track', 'track_shortcode');
  248. /*Adding qualities*/
  249. function calidades_shortcode($atts, $content=null){
  250. extract(shortcode_atts(array(
  251. 'lvjs_calidad' => '',
  252. 'src_video' => '',
  253. 'lvjs_code' => '',
  254. ), $atts));
  255. if ($lvjs_calidad) {
  256. $lvjs_calidad = " data-res='$lvjs_calidad'";
  257. }
  258. if ($src_video) {
  259. $src_video = " src='$src_video'";
  260. }
  261. $calidades = "<source" . $lvjs_calidad . $src_video . " type='video/".$lvjs_code."'/>\n\t\t";
  262. return $calidades;
  263. }
  264. add_shortcode('calidades', 'calidades_shortcode');
  265. ?>