Skip to content

Commit

Permalink
Merge pull request #39 from flowplayer/1.3.0
Browse files Browse the repository at this point in the history
1.3.0
  • Loading branch information
grappler committed Nov 24, 2013
2 parents ef7f43c + a43ed4b commit 714a6d5
Show file tree
Hide file tree
Showing 7 changed files with 382 additions and 249 deletions.
59 changes: 3 additions & 56 deletions admin/class-flowplayer5-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ private function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );

// Add custom post type
add_action( 'init', array( $this, 'add_fp5_videos' ) );

// Add action links
$plugin_basename = plugin_basename( plugin_dir_path( FP5_PLUGIN_FILE ) . 'flowplayer.php' );
add_filter( 'plugin_action_links_' . $plugin_basename, array( $this, 'add_action_links' ) );
Expand Down Expand Up @@ -237,66 +234,16 @@ public function add_action_links( $links ) {

}

/**
* NOTE: Actions are points in the execution of a page or process
* lifecycle that WordPress fires.
*
* @since 1.0.0
*/
public function add_fp5_videos() {

$labels = apply_filters( 'fp5_post_type_labels', array(
'name' => _x( 'Videos', 'Post Type General Name', $this->plugin_slug ),
'singular_name' => _x( 'Video', 'Post Type Singular Name', $this->plugin_slug ),
'menu_name' => __( 'Video', $this->plugin_slug ),
'parent_item_colon' => __( 'Parent Video', $this->plugin_slug ),
'all_items' => __( 'All Videos', $this->plugin_slug ),
'view_item' => __( 'View Video', $this->plugin_slug ),
'add_new_item' => __( 'Add New Video', $this->plugin_slug ),
'add_new' => __( 'New Video', $this->plugin_slug ),
'edit_item' => __( 'Edit Video', $this->plugin_slug ),
'update_item' => __( 'Update Video', $this->plugin_slug ),
'search_items' => __( 'Search videos', $this->plugin_slug ),
'not_found' => __( 'No videos found', $this->plugin_slug ),
'not_found_in_trash' => __( 'No videos found in Trash', $this->plugin_slug ),
) );

$args = apply_filters( 'fp5_post_type_args', array(
'label' => __( 'Video', $this->plugin_slug ),
'description' => __( 'Flowplayer videos', $this->plugin_slug ),
'labels' => $labels,
'supports' => array( 'title' ),
'hierarchical' => false,
'public' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 15,
'menu_icon' => '',
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => true,
'publicly_queryable' => false,
'query_var' => 'video',
'rewrite' => false,
'capability_type' => 'page',
) );

register_post_type( 'flowplayer5', $args );

}

/**
* Edit custom post type messages.
*
* @since 1.0.0
*/
public function set_messages($messages) {
public function set_messages( $messages ) {

global $post;

$messages[$this->plugin_slug] = array(
$messages[$this->plugin_slug] = apply_filters( 'fp5_filter_set_messages', array(

0 => '', // Unused. Messages start at index 1.
1 => __( 'Video updated.', $this->plugin_slug ) . ' ' . sprintf( __( 'Shortcode: %1$s', $this->plugin_slug ), '[flowplayer id="' . get_the_ID() . '"]' ),
Expand All @@ -310,7 +257,7 @@ public function set_messages($messages) {
9 => sprintf( __( 'Video scheduled for: %1$s', $this->plugin_slug ), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ) ),
10 => __( 'Video draft updated.', $this->plugin_slug ),

);
) );

return $messages;

Expand Down
5 changes: 3 additions & 2 deletions flowplayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Plugin Name: Flowplayer 5 for WordPress
* Plugin URI: http://wordpress.org/plugins/flowplayer5/
* Description: A HTML5 responsive video player plugin. From the makers of Flowplayer. Supports all three default Flowplayer skins, subtitles, tracking with Google Analytics, splash images. You can use your own watermark logo if you own a Commercial Flowplayer license.
* Version: 1.2.0
* Version: 1.3.0
* Author: Flowplayer ltd.
* Author URI: http://flowplayer.org/
* Text Domain: flowplayer5
Expand Down Expand Up @@ -42,7 +42,7 @@
require_once( plugin_dir_path( __FILE__ ) . 'admin/class-flowplayer-drive.php' );
} else {
require_once( plugin_dir_path( __FILE__ ) . 'frontend/class-flowplayer5-frontend.php' );
require_once( plugin_dir_path( __FILE__ ) . 'frontend/shortcode.php' );
require_once( plugin_dir_path( __FILE__ ) . 'frontend/class-flowplayer5-shortcode.php' );
}

// Register hooks that are fired when the plugin is activated, deactivated, and uninstalled, respectively.
Expand All @@ -56,4 +56,5 @@
Flowplayer_Drive::get_instance();
} else {
Flowplayer5_Frontend::get_instance();
Flowplayer5_Shortcode::get_instance();
}
25 changes: 23 additions & 2 deletions frontend/class-flowplayer5-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ private function __construct() {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );

// Filter video output to video post
add_filter( 'the_content', array( $this, 'get_video_output' ) );

// Load script for Flowplayer global configuration
add_action( 'wp_head', array( $this, 'global_config_script' ) );

Expand Down Expand Up @@ -94,7 +97,9 @@ public function enqueue_styles() {

// Register stylesheets
if( function_exists( 'has_shortcode' ) ) {
if( has_shortcode( $post->post_content, 'flowplayer' ) ) {
$post_content = isset( $post->post_content ) ? $post->post_content : '';
$has_shortcode = '';
if( has_shortcode( $post_content, 'flowplayer' ) || 'flowplayer5' == get_post_type() || apply_filters( 'fp5_filter_has_shortcode', $has_shortcode ) ) {
wp_enqueue_style( $this->plugin_slug .'-skins' , trailingslashit( $flowplayer5_directory ) . 'all-skins.css', array(), $this->player_version );
wp_enqueue_style( $this->plugin_slug .'-logo-origin', plugins_url( '/assets/css/public.css', __FILE__ ), array(), $this->plugin_version );
}
Expand Down Expand Up @@ -131,7 +136,9 @@ public function enqueue_scripts() {

// Register JavaScript
if( function_exists( 'has_shortcode' ) ) {
if( has_shortcode( $post->post_content, 'flowplayer' ) ) {
$post_content = isset( $post->post_content ) ? $post->post_content : '';
$has_shortcode = '';
if( has_shortcode( $post_content, 'flowplayer' ) || 'flowplayer5' == get_post_type() || apply_filters( 'fp5_filter_has_shortcode', $has_shortcode ) ) {
wp_enqueue_script( $this->plugin_slug . '-script', trailingslashit( $flowplayer5_directory ) . 'flowplayer.min.js', array( 'jquery' ), $this->player_version, false );
}
} else {
Expand All @@ -140,6 +147,20 @@ public function enqueue_scripts() {

}

/**
* Add video to post
*
* Add video html to flowplayer video posts
*
* @since 1.3.0
*/
public function get_video_output( $content ) {
if( is_singular( 'flowplayer5') || is_post_type_archive( 'flowplayer5') && is_main_query() ) {
$content .= Flowplayer5_Shortcode::create_fp5_video_output( get_the_ID() );
}
return $content;
}

/**
* Flowplayer global JavaScript settings.
*
Expand Down
197 changes: 197 additions & 0 deletions frontend/class-flowplayer5-shortcode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
<?php
/**
* Flowplayer 5 for WordPress
*
* @package Flowplayer 5 for WordPress
* @author Ulrich Pogson <[email protected]>
* @license GPL-2.0+
* @link http://flowplayer.org/
* @copyright 2013 Flowplayer Ltd
*/

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}

/**
* Flowplayer Shortcode Class
*
* @package Flowplayer5_Shortcode
* @author Ulrich Pogson <[email protected]>
*/
class Flowplayer5_Shortcode {

/**
* Instance of this class.
*
* @since 1.3.0
*
* @var object
*/
protected static $instance = null;

/**
* Initialize the class by adding the shortcode.
*
* @since 1.3.0
*/
private function __construct() {

// Register shortcode
add_shortcode( 'flowplayer', array( $this, 'create_fp5_video_output' ) );

}

/**
* Return an instance of this class.
*
* @since 1.3.0
*
* @return object A single instance of this class.
*/
public static function get_instance() {

// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}

return self::$instance;

}

/**
* Create Flowplayer Video HTML Output
*
* Retrieves a media files and settings to display a video.
*
* @since 1.3.0
*
* @param array $atts Shortcode attributes
*/
public function create_fp5_video_output( $atts ) {

global $post;

if ( isset( $atts['id'] ) ) {
$id = $atts['id'];
} elseif ( 'flowplayer5' == get_post_type() ) {
$id = get_the_ID();
}

if ( isset( $id ) ) {

/**
* New flowplayer shortcode
*
* @example [flowplayer id="123"]
*/

// get the meta from the post type
$loop = get_post_meta( $id, 'fp5-loop', true );
$autoplay = get_post_meta( $id, 'fp5-autoplay', true );
$preload = get_post_meta( $id, 'fp5-preload', true );
$poster = '';
$fixed_controls = get_post_meta( $id, 'fp5-fixed-controls', true );
$coloring = get_post_meta( $id, 'fp5-coloring', true );
$skin = get_post_meta( $id, 'fp5-select-skin', true );
$splash = get_post_meta( $id, 'fp5-splash-image', true );
$mp4 = get_post_meta( $id, 'fp5-mp4-video', true );
$webm = get_post_meta( $id, 'fp5-webm-video', true );
$ogg = get_post_meta( $id, 'fp5-ogg-video', true) ;
$subtitles = get_post_meta( $id, 'fp5-vtt-subtitles', true );
$max_width = get_post_meta( $id, 'fp5-max-width', true );
$width = get_post_meta( $id, 'fp5-width', true );
$height = get_post_meta( $id, 'fp5-height', true );
$ratio = get_post_meta( $id, 'fp5-aspect-ratio', true );
$fixed = get_post_meta( $id, 'fp5-fixed-width', true );

} else {

/**
* Old flowplayer shortcode
*
* @example [flowplayer splash="trailer_1080p.jpg" webm="trailer_1080p.webm" mp4="trailer_1080p.mp4" ogg="trailer_1080p.ogv" width="1920" height="1080" skin="functional" autoplay="true" loop="true" fixed="false" subtitles="bunny-en.vtt" fixed_controls="true" coloring="default" preload="auto"]
*/

// Attributes
extract(
shortcode_atts(
array(
'mp4' => '',
'webm' => '',
'ogg' => '',
'skin' => 'minimalist',
'splash' => '',
'autoplay' => 'false',
'loop' => 'false',
'subtitles' => '',
'width' => '',
'height' => '',
'fixed' => 'false',
'fixed_controls' => '',
'coloring' => 'default',
'preload' => 'auto',
'poster' => ''
),
$atts
)
);

$max_width = $width;

}

// set the options for the shortcode - pulled from the register-settings.php
$options = get_option('fp5_settings_general');
$key = ( isset( $options['key'] ) ) ? $options['key'] : '';
$logo = ( isset( $options['logo'] ) ) ? $options['logo'] : '';
$ga_account_id = ( isset( $options['ga_account_id'] ) ) ? $options['ga_account_id'] : '';
$logo_origin = ( isset( $options['logo_origin'] ) ) ? $options['logo_origin'] : '';

// Shortcode processing
$ratio = ( ( $width != 0 && $height != 0 ) ? intval( $height ) / intval( $width ) : '' );
$size = ( $fixed == 'true' && $width != '' && $height != '' ? 'width:' . $width . 'px; height:' . $height . 'px; ' : ( ( $max_width != 0 ) ? 'max-width:' . $max_width . 'px; ' : '' ) );
$splash_style = 'background: #777 url(' . $splash . ') no-repeat;';
$class = 'flowplayer ' . $skin . ' ' . ( ! empty ( $splash ) ? 'is-splash ' : '' ) . ( ! empty ( $logo_origin ) ? 'commercial ' : '' );
$data_key = ( 0 < strlen ( $key ) ? 'data-key="' . $key . '" ' : '');
$data_logo = ( 0 < strlen ( $key ) && 0 < strlen ( $logo ) ? 'data-logo="' . $logo . '" ' : '' );
$data_analytics = ( 0 < strlen ( $ga_account_id ) ? 'data-analytics="' . $ga_account_id . '" ' : '' );
$data_ratio = ( $ratio != 0 ? 'data-ratio="' . $ratio . '" ' : '' );

$modifier_classes = ( ( $fixed_controls == 'true' ) ? 'fixed-controls ' : '' ) . ( $coloring != 'default' ? $coloring : '' );
$flowplayer_data = $data_key . $data_logo . $data_analytics . $data_ratio;
$attributes = ( ( $autoplay == 'true' ) ? 'autoplay ' : '' ) . ( ( $loop == 'true' ) ? 'loop ' : '' ) . ( isset ( $preload ) ? 'preload="' . $preload . '" ' : '' ) . ( ( $poster == 'true' ) ? 'poster' : '' );

// Shortcode output
$return = '<div style="' . $size . $splash_style . ' background-size: contain;" class="' . $class . $modifier_classes . '" ' . apply_filters( 'fp5_filter_flowplayer_data', $flowplayer_data ) . '>';
ob_start();
$return .= do_action( 'fp5_video_top' );
$return .= ob_get_contents();
ob_clean();
$return .= '<video ' . $attributes . '>';
$webm != '' ? $return .= '<source type="video/webm" src="' . $webm . '">' : '';
$mp4 != '' ? $return .= '<source type="video/mp4" src="' . $mp4 . '">' : '';
$ogg != '' ? $return .= '<source type="video/ogg" src="' . $ogg . '">' : '';
$subtitles != '' ? $return .= '<track src="' . $subtitles . '"/>' : '';
$return .= '</video>';
ob_start();
$return .= do_action( 'fp5_video_bottom' );
$return .= ob_get_contents();
ob_clean();
$return .= '</div>';

// Extra options
$return .= '<script>';
$width == 0 && $height == 0 ? $return .= 'flowplayer.conf.adaptiveRatio = true;' : '';
$return .= '</script>';

// Check if a video has been added before output
if ( $webm || $mp4 || $ogg ) {
return $return;
}

}

}
Loading

0 comments on commit 714a6d5

Please sign in to comment.