b2evolution PHP Cross Reference Blogging Systems

Source: /plugins/html5_videojs_plugin/_html5_videojs.plugin.php - 263 lines - 6972 bytes - Summary - Text - Print

Description: This file implements the HTML 5 VideoJS Player plugin for b2evolution b2evolution - {@link http://b2evolution.net/} Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}

   1  <?php
   2  /**
   3   * This file implements the HTML 5 VideoJS Player plugin for b2evolution
   4   *
   5   * b2evolution - {@link http://b2evolution.net/}
   6   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
   7   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   8   *
   9   * @author fplanque: Francois PLANQUE.
  10   *
  11   * @package plugins
  12   * @version $Id: _html5_videojs.plugin.php 198 2011-11-05 21:34:08Z fplanque $
  13   */
  14  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  15  
  16  
  17  /**
  18   * @package plugins
  19   */
  20  class html5_videojs_plugin extends Plugin
  21  {
  22      var $code = 'b2evH5V';
  23      var $name = 'HTML 5 VideoJS Player';
  24      var $priority = 80;
  25      var $version = '5.0.0';
  26      var $group = 'files';
  27      var $number_of_installs = 1;
  28      var $allow_ext = array( 'flv', 'm4v', 'f4v', 'mp4', 'ogv', 'webm' );
  29  
  30  
  31  	function PluginInit( & $params )
  32      {
  33          $this->short_desc = sprintf( T_('Media player for the these file formats: %s.'), implode( ', ', $this->allow_ext ) );
  34          $this->long_desc = $this->short_desc;
  35      }
  36  
  37  
  38      /**
  39       * @see Plugin::SkinBeginHtmlHead()
  40       */
  41  	function SkinBeginHtmlHead( & $params )
  42      {
  43          require_css( 'http://vjs.zencdn.net/c/video-js.css', 'relative' );
  44          require_js( 'http://vjs.zencdn.net/c/video.js', 'relative' );
  45          $this->require_skin();
  46  
  47          // Set a video size in css style, because option setting is ignored by some reason
  48          $width = (int) $this->Settings->get( 'width' );
  49          $width = empty( $width ) ? '100%' : $width.'px';
  50          $height = (int) $this->Settings->get( 'height' );
  51          add_css_headline( '.video-js{ width: '.$width.' !important; height: '.$height.'px !important; }' );
  52      }
  53  
  54  
  55      /**
  56       * @see Plugin::AdminEndHtmlHead()
  57       */
  58  	function AdminEndHtmlHead( & $params )
  59      {
  60          $this->SkinBeginHtmlHead( $params );
  61      }
  62  
  63  
  64      /**
  65       * Get the settings that the plugin can use.
  66       *
  67       * Those settings are transfered into a Settings member object of the plugin
  68       * and can be edited in the backoffice (Settings / Plugins).
  69       *
  70       * @see Plugin::GetDefaultSettings()
  71       * @see PluginSettings
  72       * @see Plugin::PluginSettingsValidateSet()
  73       * @return array
  74       */
  75  	function GetDefaultSettings( & $params )
  76      {
  77          return array(
  78              'skin' => array(
  79                  'label' => T_('Skin'),
  80                  'type' => 'select',
  81                  'options' => $this->get_skins_list(),
  82                  'defaultvalue' => 'tubecss',
  83                  ),
  84              'width' => array(
  85                  'label' => T_('Video width (px)'),
  86                  'note' => T_('100% width if left empty or 0'),
  87                  ),
  88              'height' => array(
  89                  'label' => T_('Video height (px)'),
  90                  'type' => 'integer',
  91                  'defaultvalue' => 300,
  92                  'note' => '',
  93                  'valid_range' => array( 'min' => 1 ),
  94                  ),
  95              'allow_download' => array(
  96                  'label' => T_('Allow downloading of the video file'),
  97                  'type' => 'checkbox',
  98                  'defaultvalue' => 0,
  99                  ),
 100              );
 101      }
 102  
 103  
 104      /**
 105       * Check a file for correct extension
 106       *
 107       * @param File
 108       * @return boolean true if extension of file supported by plugin
 109       */
 110  	function is_flp_video( $File )
 111      {
 112          return in_array( strtolower( $File->get_ext() ), $this->allow_ext );
 113      }
 114  
 115  
 116      /**
 117       * Event handler: Called when displaying item attachment.
 118       *
 119       * @param array Associative array of parameters. $params['File'] - attachment, $params['data'] - output
 120       * @param boolean TRUE - when render in comments
 121       * @return boolean true if plugin rendered this attachment
 122       */
 123  	function RenderItemAttachment( & $params, $in_comments = false )
 124      {
 125          $File = $params['File'];
 126  
 127          if( ! $this->is_flp_video( $File ) )
 128          {
 129              return false;
 130          }
 131  
 132          if( $File->exists() )
 133          {
 134              /**
 135               * @var integer A number to assign each video player new id attribute
 136               */
 137              global $html5_videojs_number;
 138              $html5_videojs_number++;
 139  
 140              if( $in_comments )
 141              {
 142                  $params['data'] .= '<div style="clear: both; height: 0px; font-size: 0px"></div>';
 143              }
 144  
 145              /**
 146               * Video options:
 147               *
 148               * controls:  true // The controls option sets whether or not the player has controls that the user can interact with.
 149               * autoplay:  true // If autoplay is true, the video will start playing as soon as page is loaded (without any interaction from the user). NOT SUPPORTED BY APPLE iOS DEVICES
 150               * preload:   'auto'|'metadata'|'none' // The preload attribute informs the browser whether or not the video data should begin downloading as soon as the video tag is loaded.
 151               * poster:    'myPoster.jpg' // The poster attribute sets the image that displays before the video begins playing.
 152               * loop:      true // The loop attribute causes the video to start over as soon as it ends.
 153               */
 154              $video_options = array();
 155              $video_options['controls'] = true;
 156              $video_options['preload'] = 'auto';
 157  
 158  
 159              $params['data'] .= '<video id="html5_videojs_'.$html5_videojs_number.'" class="video-js '.$this->Settings->get( 'skin' ).'" data-setup=\''.evo_json_encode( $video_options ).'\'>'.
 160                  '<source src="'.$File->get_url().'" type="'.$this->get_video_mimetype( $File ).'" />'.
 161                  '</video>';
 162  
 163              if( $this->Settings->get( 'allow_download' ) )
 164              {    // Allow to download the video files
 165                  $params['data'] .= '<div class="small center"><a href="'.$File->get_url().'">'.T_('Download this video').'</a></div>';
 166              }
 167  
 168              return true;
 169          }
 170  
 171          return false;
 172      }
 173  
 174  
 175      /**
 176       * Event handler: Called when displaying comment attachment.
 177       *
 178       * @param array Associative array of parameters. $params['File'] - attachment, $params['data'] - output
 179       * @return boolean true if plugin rendered this attachment
 180       */
 181  	function RenderCommentAttachment( & $params )
 182      {
 183          return $this->RenderItemAttachment( $params, true );
 184      }
 185  
 186      /**
 187       * Get a list of the skins
 188       *
 189       * @return array Skins
 190       */
 191  	function get_skins_list()
 192      {
 193          $skins_path = dirname( $this->classfile_path ).'/skins';
 194  
 195          $skins = array();
 196          // Set this skin permanently, because it is a default skin name
 197          $skins['vjs-default-skin'] = 'vjs-default-skin';
 198  
 199          $files = scandir( $skins_path );
 200          foreach( $files as $file )
 201          {
 202              if( $file != '.' && $file != '..' && is_dir( $skins_path.'/'.$file ) )
 203              {    // Use folder name as skin name
 204                  $skins[ $file ] = $file;
 205              }
 206          }
 207  
 208          return $skins;
 209      }
 210  
 211      /**
 212       * Require css file of current skin
 213       */
 214  	function require_skin()
 215      {
 216          $skin = $this->Settings->get( 'skin' );
 217          if( !empty( $skin ) && $skin != 'vjs-default-skin')
 218          {
 219              $skins_path = dirname( $this->classfile_path ).'/skins';
 220              if( file_exists( $skins_path.'/'.$skin.'/style.css' ) )
 221              {    // Require css file only if it exists
 222                  require_css( $this->get_plugin_url().'skins/'.$skin.'/style.css', 'relative' );
 223              }
 224          }
 225      }
 226  
 227      /**
 228       * Get video mimetype
 229       *
 230       * @param object File
 231       * @return string Mimetype
 232       */
 233  	function get_video_mimetype( $File )
 234      {
 235          switch( $File->get_ext() )
 236          {
 237              case 'flv':
 238                  $mimetype = 'video/flv';
 239                  break;
 240  
 241              case 'm4v':
 242                  $mimetype = 'video/m4v';
 243                  break;
 244  
 245              case 'ogv':
 246                  $mimetype = 'video/ogg';
 247                  break;
 248  
 249              case 'webm':
 250                  $mimetype = 'video/webm';
 251                  break;
 252  
 253              case 'f4v':
 254              case 'mp4':
 255              default:
 256                  $mimetype = 'video/mp4';
 257                  break;
 258          }
 259  
 260          return $mimetype;
 261      }
 262  }
 263  ?>

title

Description

title

Description

title

Description

title

title

Body