b2evolution PHP Cross Reference Blogging Systems

Source: /plugins/html5_mediaelementjs_plugin/_html5_mediaelementjs.plugin.php - 324 lines - 8414 bytes - Summary - Text - Print

Description: This file implements the HTML 5 MediaElement.js Video 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 MediaElement.js Video 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_mediaelementjs.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_mediaelementjs_plugin extends Plugin
  21  {
  22      var $code = 'b2evH5M';
  23      var $name = 'HTML 5 MediaElement.js Video 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( $this->get_plugin_url().'rsc/mediaelementplayer.min.css', 'relative' );
  44          require_js( '#jquery#', 'blog' );
  45          require_js( $this->get_plugin_url().'rsc/mediaelement-and-player.min.js', 'relative' );
  46          $this->require_skin();
  47  
  48          // Set a video size in css style, because option setting cannot sets correct size
  49          $width = (int) $this->Settings->get( 'width' );
  50          $height = (int) $this->Settings->get( 'height' );
  51          add_css_headline( 'video.html5_mediaelementjs_video{ width: '.$width.'px !important; height: '.$height.'px !important; }' );
  52  
  53          // Initialize a player
  54          add_js_headline( 'jQuery( document ).ready( function() {
  55                  jQuery( "video.html5_mediaelementjs_video" ).mediaelementplayer( {
  56                      defaultVideoWidth: "'.$width.'",
  57                      defaultVideoHeight: "'.$height.'",
  58                      videoWidth: "'.$width.'",
  59                      videoHeight: "'.$height.'",
  60                  } );
  61              } );' );
  62          /**
  63           * Plugin options:
  64  
  65              // if the <video width> is not specified, this is the default
  66              defaultVideoWidth: 480,
  67              // if the <video height> is not specified, this is the default
  68              defaultVideoHeight: 270,
  69              // if set, overrides <video width>
  70              videoWidth: -1,
  71              // if set, overrides <video height>
  72              videoHeight: -1,
  73              // width of audio player
  74              audioWidth: 400,
  75              // height of audio player
  76              audioHeight: 30,
  77              // initial volume when the player starts
  78              startVolume: 0.8,
  79              // useful for <audio> player loops
  80              loop: false,
  81              // enables Flash and Silverlight to resize to content size
  82              enableAutosize: true,
  83              // the order of controls you want on the control bar (and other plugins below)
  84              features: ['playpause','progress','current','duration','tracks','volume','fullscreen'],
  85              // Hide controls when playing and mouse is not over the video
  86              alwaysShowControls: false,
  87              // force iPad's native controls
  88              iPadUseNativeControls: false,
  89              // force iPhone's native controls
  90              iPhoneUseNativeControls: false,
  91              // force Android's native controls
  92              AndroidUseNativeControls: false,
  93              // forces the hour marker (##:00:00)
  94              alwaysShowHours: false,
  95              // show framecount in timecode (##:00:00:00)
  96              showTimecodeFrameCount: false,
  97              // used when showTimecodeFrameCount is set to true
  98              framesPerSecond: 25,
  99              // turns keyboard support on and off for this instance
 100              enableKeyboard: true,
 101              // when this player starts, it will pause other players
 102              pauseOtherPlayers: true,
 103              // array of keyboard commands
 104              keyActions: []
 105  
 106           */
 107      }
 108  
 109  
 110      /**
 111       * @see Plugin::AdminEndHtmlHead()
 112       */
 113  	function AdminEndHtmlHead( & $params )
 114      {
 115          $this->SkinBeginHtmlHead( $params );
 116      }
 117  
 118  
 119      /**
 120       * Get the settings that the plugin can use.
 121       *
 122       * Those settings are transfered into a Settings member object of the plugin
 123       * and can be edited in the backoffice (Settings / Plugins).
 124       *
 125       * @see Plugin::GetDefaultSettings()
 126       * @see PluginSettings
 127       * @see Plugin::PluginSettingsValidateSet()
 128       * @return array
 129       */
 130  	function GetDefaultSettings( & $params )
 131      {
 132          return array(
 133              'skin' => array(
 134                  'label' => T_('Skin'),
 135                  'type' => 'select',
 136                  'options' => $this->get_skins_list(),
 137                  'defaultvalue' => 'default',
 138                  ),
 139              'width' => array(
 140                  'label' => T_('Video width (px)'),
 141                  'type' => 'integer',
 142                  'defaultvalue' => 425,
 143                  'note' => '',
 144                  'valid_range' => array( 'min' => 1 ),
 145                  ),
 146              'height' => array(
 147                  'label' => T_('Video height (px)'),
 148                  'type' => 'integer',
 149                  'defaultvalue' => 300,
 150                  'note' => '',
 151                  'valid_range' => array( 'min' => 1 ),
 152                  ),
 153              'allow_download' => array(
 154                  'label' => T_('Allow downloading of the video file'),
 155                  'type' => 'checkbox',
 156                  'defaultvalue' => 0,
 157                  ),
 158              );
 159      }
 160  
 161  
 162      /**
 163       * Check a file for correct extension
 164       *
 165       * @param File
 166       * @return boolean true if extension of file supported by plugin
 167       */
 168  	function is_flp_video( $File )
 169      {
 170          return in_array( strtolower( $File->get_ext() ), $this->allow_ext );
 171      }
 172  
 173  
 174      /**
 175       * Event handler: Called when displaying item attachment.
 176       *
 177       * @param array Associative array of parameters. $params['File'] - attachment, $params['data'] - output
 178       * @param boolean TRUE - when render in comments
 179       * @return boolean true if plugin rendered this attachment
 180       */
 181  	function RenderItemAttachment( & $params, $in_comments = false )
 182      {
 183          $File = $params['File'];
 184  
 185          if( ! $this->is_flp_video( $File ) )
 186          {
 187              return false;
 188          }
 189  
 190          if( $File->exists() )
 191          {
 192              /**
 193               * @var integer A number to assign each video player new id attribute
 194               */
 195              global $html5_mediaelementjs_number;
 196              $html5_mediaelementjs_number++;
 197  
 198              if( $in_comments )
 199              {
 200                  $params['data'] .= '<div style="clear: both; height: 0px; font-size: 0px"></div>';
 201              }
 202  
 203              $params['data'] .= '<video class="html5_mediaelementjs_video '.$this->get_skin_class().'" id="html5_mediaelementjs_'.$html5_mediaelementjs_number.'">'.
 204                  '<source src="'.$File->get_url().'" type="'.$this->get_video_mimetype( $File ).'" />'.
 205              '</video>';
 206  
 207              if( $this->Settings->get( 'allow_download' ) )
 208              {    // Allow to download the video files
 209                  $params['data'] .= '<div class="small center"><a href="'.$File->get_url().'">'.T_('Download this video').'</a></div>';
 210              }
 211  
 212              return true;
 213          }
 214  
 215          return false;
 216      }
 217  
 218  
 219      /**
 220       * Event handler: Called when displaying comment attachment.
 221       *
 222       * @param array Associative array of parameters. $params['File'] - attachment, $params['data'] - output
 223       * @return boolean true if plugin rendered this attachment
 224       */
 225  	function RenderCommentAttachment( & $params )
 226      {
 227          return $this->RenderItemAttachment( $params, true );
 228      }
 229  
 230      /**
 231       * Get a list of the skins
 232       *
 233       * @return array Skins
 234       */
 235  	function get_skins_list()
 236      {
 237          $skins_path = dirname( $this->classfile_path ).'/skins';
 238  
 239          $skins = array();
 240          // Set this skin permanently, because it is a default skin
 241          $skins['default'] = 'default';
 242  
 243          $files = scandir( $skins_path );
 244          foreach( $files as $file )
 245          {
 246              if( $file != '.' && $file != '..' && is_dir( $skins_path.'/'.$file ) )
 247              {    // Use folder name as skin name
 248                  $skins[ $file ] = $file;
 249              }
 250          }
 251  
 252          return $skins;
 253      }
 254  
 255      /**
 256       * Get skin class name
 257       *
 258       * @return string Skin class name
 259       */
 260  	function get_skin_class()
 261      {
 262          $skin = $this->Settings->get( 'skin' );
 263  
 264          if( !empty( $skin ) && $skin != 'default')
 265          {
 266              return 'mejs-'.$this->Settings->get( 'skin' );
 267          }
 268  
 269          return ''; // Default skin
 270      }
 271  
 272      /**
 273       * Require css file of current skin
 274       */
 275  	function require_skin()
 276      {
 277          $skin = $this->Settings->get( 'skin' );
 278          if( !empty( $skin ) && $skin != 'default')
 279          {
 280              $skins_path = dirname( $this->classfile_path ).'/skins';
 281              if( file_exists( $skins_path.'/'.$skin.'/style.css' ) )
 282              {    // Require css file only if it exists
 283                  require_css( $this->get_plugin_url().'skins/'.$skin.'/style.css', 'relative' );
 284              }
 285          }
 286      }
 287  
 288      /**
 289       * Get video mimetype
 290       *
 291       * @param object File
 292       * @return string Mimetype
 293       */
 294  	function get_video_mimetype( $File )
 295      {
 296          switch( $File->get_ext() )
 297          {
 298              case 'flv':
 299                  $mimetype = 'video/flv';
 300                  break;
 301  
 302              case 'm4v':
 303                  $mimetype = 'video/m4v';
 304                  break;
 305  
 306              case 'ogv':
 307                  $mimetype = 'video/ogg';
 308                  break;
 309  
 310              case 'webm':
 311                  $mimetype = 'video/webm';
 312                  break;
 313  
 314              case 'f4v':
 315              case 'mp4':
 316              default:
 317                  $mimetype = 'video/mp4';
 318                  break;
 319          }
 320  
 321          return $mimetype;
 322      }
 323  }
 324  ?>

title

Description

title

Description

title

Description

title

title

Body