public
Created

Self-hosted video module for Agility

  • Download Gist
video.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
<?php
/**
* Self-hosted Video Module
*/
 
function agility_videojs_scripts_and_styles(){
 
global $agilitySettings;
 
if( $agilitySettings->op( 'self-hosted-video' ) ){
//Stylesheets
wp_enqueue_style( 'videojs', 'http://vjs.zencdn.net/c/video-js.css' );
 
//Javascript
wp_enqueue_script( 'videojs' , 'http://vjs.zencdn.net/c/video.js' , false, false ); // false );
}
}
add_action( 'wp_enqueue_scripts', 'agility_videojs_scripts_and_styles' );
 
 
 
function agility_featured_videojs( $delay = false , $width = 640 , $height = 264 ){
global $post;
 
$sources = array(
'ogg' => get_post_meta( $post->ID , 'featured_video_ogg' , true ),
'webm' => get_post_meta( $post->ID , 'featured_video_webm' , true ),
'mp4' => get_post_meta( $post->ID , 'featured_video_mp4' , true ), //
'img' => wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) ),
);
 
$_width = get_post_meta( $post->ID , 'featured_video_width' , true );
$_height = get_post_meta( $post->ID , 'featured_video_height' , true );
 
if( $_width != '' ) $width = $_width;
if( $_height != '' ) $height = $_height;
 
agility_videojs( 'featured-video-'.$post->ID, $sources , $width, $height, $delay );
 
}
 
function agility_videojs( $id, $sources , $width = 640 , $height = 264 , $delay = false ){
 
$source_defaults = array(
'ogg' => '',
'mp4' => '',
'webm' => '',
'img' => '',
);
 
extract( wp_parse_args( $sources , $source_defaults ) );
 
?>
 
<?php if( !$ogg && !$mp4 && !$webm ):?>
 
<div class="hint">Please define at least one video source file (ogg, mp4, webm).</div>
 
<?php else: ?>
 
 
<!-- featured-video -->
<div id="<?php echo $id; ?>" class="featured-video featured-video-videojs">
<!-- Begin VideoJS - Self Hosted Video -->
<!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody -->
<video class="video-js vjs-default-skin" width="<?php echo $width; ?>" height="<?php echo $height; ?>" controls preload="auto"
poster="<?php echo $img; ?>" data-setup="{}" >
 
<?php if( $mp4 ): ?>
<source src="<?php echo $mp4; ?>" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
<?php endif; ?>
 
<?php if( $webm ): ?>
<source src="<?php echo $webm; ?>" type='video/webm; codecs="vp8, vorbis"' />
<?php endif; ?>
 
<?php if( $ogg ): ?>
<source src="<?php echo $ogg; ?>" type='video/ogg; codecs="theora, vorbis"' />
<?php endif; ?>
 
<?php if( $mp4 ): ?>
<!-- Flash Fallback. -->
<object class="vjs-flash-fallback" width="<?php echo $width; ?>" height="<?php echo $height; ?>" type="application/x-shockwave-flash"
data="http://vjs.zencdn.net/3.2/video-js.swf">
<param name="movie" value="http://vjs.zencdn.net/3.2/video-js.swf" />
<param name="allowfullscreen" value="true" />
<param name="flashvars" value='config={"playlist":["<?php echo $mp4; ?>", {"url": "<?php echo $mp4; ?>","autoPlay":false,"autoBuffering":true}]}' />
<!-- Image Fallback. Typically the same as the poster image. -->
<img src="<?php echo $img; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="Poster Image"
title="No video playback capabilities." />
</object>
<?php endif; ?>
 
</video>
<!-- End VideoJS -->
</div>
<!-- end .featured-video -->
 
<?php endif;
}
 
 
//Create Meta Box
if(!class_exists('AgilityCustomPostType')) require_once( get_template_directory().'/modules/custom_post_types/AgilityCustomPostType.class.php');
 
class SHVideoSettingsMetaBox extends CustomMetaBox{
 
public function __construct( $id, $title, $page, $context = 'side', $priority = 'default' ){
parent::__construct( $id, $title, $page, $context, $priority );
 
$this->addField( new TextMetaField( 'featured_video_mp4', __( 'MP4 Video URL', 'agility' ) , '' , array(
'description' => __( 'MP4 is required for Safari/iOS HTML5 Video and Flash Fallback', 'agility' ),
) ) );
$this->addField( new TextMetaField( 'featured_video_ogg', __( 'OGG Video URL', 'agility' ) , '' , array(
'description' => __( 'OGG (.ogv) is used for Firefox/Opera/Chrome HTML5 Video', 'agility' ),
) ) );
 
$this->addField( new TextMetaField( 'featured_video_webm', __( 'WebM Video URL', 'agility' ) , '' , array(
'description' => '<a href="http://camendesign.com/code/video_for_everybody#webm">WebM</a> '.__( 'is optional.', 'agility' ),
) ) );
 
$this->addField( new TextMetaField( 'featured_video_width', __( 'Video Width', 'agility' ) , '' , array(
'description' => 'Width in pixels (will determine aspect ratio when scaling)'
) ) );
 
$this->addField( new TextMetaField( 'featured_video_height', __( 'Video Height', 'agility' ) , '' , array(
'description' => 'Height in pixels (will determine aspect ratio when scaling)'
) ) );
 
}
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.