initial commit
This commit is contained in:
@ -0,0 +1,730 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2013 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
class Video_Thumbnails_Settings {
|
||||
|
||||
public $options;
|
||||
|
||||
var $default_options = array(
|
||||
'save_media' => 1,
|
||||
'set_featured' => 1,
|
||||
'post_types' => array( 'post' ),
|
||||
'custom_field' => ''
|
||||
);
|
||||
|
||||
function __construct() {
|
||||
// Activation and deactivation hooks
|
||||
register_activation_hook( VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php', array( &$this, 'plugin_activation' ) );
|
||||
register_deactivation_hook( VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php', array( &$this, 'plugin_deactivation' ) );
|
||||
// Set current options
|
||||
add_action( 'plugins_loaded', array( &$this, 'set_options' ) );
|
||||
// Add options page to menu
|
||||
add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
|
||||
// Initialize options
|
||||
add_action( 'admin_init', array( &$this, 'initialize_options' ) );
|
||||
// Custom field detection callback
|
||||
add_action( 'wp_ajax_video_thumbnail_custom_field_detection', array( &$this, 'custom_field_detection_callback' ) );
|
||||
// Ajax clear all callback
|
||||
add_action( 'wp_ajax_clear_all_video_thumbnails', array( &$this, 'ajax_clear_all_callback' ) );
|
||||
// Ajax test callbacks
|
||||
add_action( 'wp_ajax_video_thumbnail_provider_test', array( &$this, 'provider_test_callback' ) ); // Provider test
|
||||
add_action( 'wp_ajax_video_thumbnail_image_download_test', array( &$this, 'image_download_test_callback' ) ); // Saving media test
|
||||
add_action( 'wp_ajax_video_thumbnail_delete_test_images', array( &$this, 'delete_test_images_callback' ) ); // Delete test images
|
||||
add_action( 'wp_ajax_video_thumbnail_markup_detection_test', array( &$this, 'markup_detection_test_callback' ) ); // Markup input test
|
||||
// Admin scripts
|
||||
add_action( 'admin_enqueue_scripts', array( &$this, 'admin_scripts' ) );
|
||||
// Add "Go Pro" call to action to settings footer
|
||||
add_action( 'video_thumbnails/settings_footer', array( 'Video_Thumbnails_Settings', 'settings_footer' ) );
|
||||
}
|
||||
|
||||
// Activation hook
|
||||
function plugin_activation() {
|
||||
add_option( 'video_thumbnails', $this->default_options );
|
||||
}
|
||||
|
||||
// Deactivation hook
|
||||
function plugin_deactivation() {
|
||||
delete_option( 'video_thumbnails' );
|
||||
}
|
||||
|
||||
// Set options & possibly upgrade
|
||||
function set_options() {
|
||||
// Get the current options from the database
|
||||
$options = get_option( 'video_thumbnails' );
|
||||
// If there aren't any options, load the defaults
|
||||
if ( ! $options ) $options = $this->default_options;
|
||||
// Check if our options need upgrading
|
||||
$options = $this->upgrade_options( $options );
|
||||
// Set the options class variable
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
function upgrade_options( $options ) {
|
||||
|
||||
// Boolean for if options need updating
|
||||
$options_need_updating = false;
|
||||
|
||||
// If there isn't a settings version we need to check for pre 2.0 settings
|
||||
if ( ! isset( $options['version'] ) ) {
|
||||
|
||||
// Check for post type setting
|
||||
$post_types = get_option( 'video_thumbnails_post_types' );
|
||||
|
||||
// If there is a a post type option we know there should be others
|
||||
if ( $post_types !== false ) {
|
||||
|
||||
$options['post_types'] = $post_types;
|
||||
delete_option( 'video_thumbnails_post_types' );
|
||||
|
||||
$options['save_media'] = get_option( 'video_thumbnails_save_media' );
|
||||
delete_option( 'video_thumbnails_save_media' );
|
||||
|
||||
$options['set_featured'] = get_option( 'video_thumbnails_set_featured' );
|
||||
delete_option( 'video_thumbnails_set_featured' );
|
||||
|
||||
$options['custom_field'] = get_option( 'video_thumbnails_custom_field' );
|
||||
delete_option( 'video_thumbnails_custom_field' );
|
||||
|
||||
}
|
||||
|
||||
// Updates the options version to 2.0
|
||||
$options['version'] = '2.0';
|
||||
$options_need_updating = true;
|
||||
|
||||
}
|
||||
|
||||
if ( version_compare( $options['version'], VIDEO_THUMBNAILS_VERSION, '<' ) ) {
|
||||
$options['version'] = VIDEO_THUMBNAILS_VERSION;
|
||||
$options_need_updating = true;
|
||||
}
|
||||
|
||||
// Save options to database if they've been updated
|
||||
if ( $options_need_updating ) {
|
||||
update_option( 'video_thumbnails', $options );
|
||||
}
|
||||
|
||||
return $options;
|
||||
|
||||
}
|
||||
|
||||
function admin_menu() {
|
||||
add_options_page(
|
||||
__( 'Video Thumbnails Options', 'video-thumbnails' ),
|
||||
__( 'Video Thumbnails', 'video-thumbnails' ),
|
||||
'manage_options',
|
||||
'video_thumbnails',
|
||||
array( &$this, 'options_page' )
|
||||
);
|
||||
}
|
||||
|
||||
function admin_scripts( $hook ) {
|
||||
if ( 'settings_page_video_thumbnails' == $hook ) {
|
||||
wp_enqueue_style( 'video-thumbnails-settings-css', plugins_url( '/css/settings.css', VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php' ), false, VIDEO_THUMBNAILS_VERSION );
|
||||
wp_enqueue_script( 'video_thumbnails_settings', plugins_url( 'js/settings.js' , VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php' ), array( 'jquery' ), VIDEO_THUMBNAILS_VERSION );
|
||||
wp_localize_script( 'video_thumbnails_settings', 'video_thumbnails_settings_language', array(
|
||||
'detection_failed' => __( 'We were unable to find a video in the custom fields of your most recently updated post.', 'video-thumbnails' ),
|
||||
'working' => __( 'Working...', 'video-thumbnails' ),
|
||||
'retest' => __( 'Retest', 'video-thumbnails' ),
|
||||
'ajax_error' => __( 'AJAX Error:', 'video-thumbnails' ),
|
||||
'clear_all_confirmation' => __( 'Are you sure you want to clear all video thumbnails? This cannot be undone.', 'video-thumbnails' ),
|
||||
) );
|
||||
global $video_thumbnails;
|
||||
$provider_slugs = array();
|
||||
foreach ( $video_thumbnails->providers as $provider ) {
|
||||
$provider_slugs[] = $provider->service_slug;
|
||||
}
|
||||
wp_localize_script( 'video_thumbnails_settings', 'video_thumbnails_provider_slugs', array(
|
||||
'provider_slugs' => $provider_slugs
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
function custom_field_detection_callback() {
|
||||
if ( current_user_can( 'manage_options' ) ) {
|
||||
echo $this->detect_custom_field();
|
||||
}
|
||||
die();
|
||||
}
|
||||
|
||||
function detect_custom_field() {
|
||||
global $video_thumbnails;
|
||||
$latest_post = get_posts( array(
|
||||
'posts_per_page' => 1,
|
||||
'post_type' => $this->options['post_types'],
|
||||
'orderby' => 'modified',
|
||||
) );
|
||||
$latest_post = $latest_post[0];
|
||||
$custom = get_post_meta( $latest_post->ID );
|
||||
foreach ( $custom as $name => $values ) {
|
||||
foreach ($values as $value) {
|
||||
if ( $video_thumbnails->get_first_thumbnail_url( $value ) ) {
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function ajax_clear_all_callback() {
|
||||
if ( !current_user_can( 'manage_options' ) ) die();
|
||||
if ( wp_verify_nonce( $_POST['nonce'], 'clear_all_video_thumbnails' ) ) {
|
||||
global $wpdb;
|
||||
// Clear images from media library
|
||||
$media_library_items = get_posts( array(
|
||||
'showposts' => -1,
|
||||
'post_type' => 'attachment',
|
||||
'meta_key' => 'video_thumbnail',
|
||||
'meta_value' => '1',
|
||||
'fields' => 'ids'
|
||||
) );
|
||||
foreach ( $media_library_items as $item ) {
|
||||
wp_delete_attachment( $item, true );
|
||||
}
|
||||
echo '<p><span style="color:green">✔</span> ' . sprintf( _n( '1 attachment deleted', '%s attachments deleted', count( $media_library_items ), 'video-thumbnails' ), count( $media_library_items ) ) . '</p>';
|
||||
// Clear custom fields
|
||||
$custom_fields_cleared = $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key='_video_thumbnail'" );
|
||||
echo '<p><span style="color:green">✔</span> ' . sprintf( _n( '1 custom field cleared', '%s custom fields cleared', $custom_fields_cleared, 'video-thumbnails' ), $custom_fields_cleared ) . '</p>';
|
||||
} else {
|
||||
echo '<p><span style="color:red">✖</span> ' . __( '<strong>Error</strong>: Could not verify nonce.', 'video-thumbnails' ) . '</p>';
|
||||
}
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
function get_file_hash( $url ) {
|
||||
$response = wp_remote_get( $url );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = false;
|
||||
} else {
|
||||
$result = md5( $response['body'] );
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function provider_test_callback() {
|
||||
|
||||
if ( !current_user_can( 'manage_options' ) ) die();
|
||||
|
||||
global $video_thumbnails;
|
||||
|
||||
?>
|
||||
<table class="widefat">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php _e( 'Name', 'video-thumbnails' ); ?></th>
|
||||
<th><?php _e( 'Pass/Fail', 'video-thumbnails' ); ?></th>
|
||||
<th><?php _e( 'Result', 'video-thumbnails' ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$provider = $video_thumbnails->providers[$_POST['provider_slug']];
|
||||
foreach ( $provider->get_test_cases() as $test_case ) {
|
||||
echo '<tr>';
|
||||
echo '<td><strong>' . $test_case['name'] . '</strong></td>';
|
||||
$markup = apply_filters( 'the_content', $test_case['markup'] );
|
||||
$result = $video_thumbnails->get_first_thumbnail_url( $markup );
|
||||
if ( is_wp_error( $result ) ) {
|
||||
$error_string = $result->get_error_message();
|
||||
echo '<td style="color:red;">✗ ' . __( 'Failed', 'video-thumbnails' ) . '</td>';
|
||||
echo '<td>';
|
||||
echo '<div class="error"><p>' . $error_string . '</p></div>';
|
||||
echo '</td>';
|
||||
$failed++;
|
||||
} else {
|
||||
$result_hash = false;
|
||||
if ( $result == $test_case['expected'] ) {
|
||||
$matched = true;
|
||||
} else {
|
||||
$result_hash = $this->get_file_hash( $result );
|
||||
$matched = ( $result_hash == $test_case['expected_hash'] ? true : false );
|
||||
}
|
||||
|
||||
if ( $matched ) {
|
||||
echo '<td style="color:green;">✔ ' . __( 'Passed', 'video-thumbnails' ) . '</td>';
|
||||
} else {
|
||||
echo '<td style="color:red;">✗ ' . __( 'Failed', 'video-thumbnails' ) . '</td>';
|
||||
}
|
||||
echo '<td>';
|
||||
if ( $result ) {
|
||||
echo '<a href="' . $result . '">' . __( 'View Image', 'video-thumbnails' ) . '</a>';
|
||||
}
|
||||
if ( $result_hash ) {
|
||||
echo ' <code>' . $result_hash . '</code>';
|
||||
}
|
||||
echo '</td>';
|
||||
}
|
||||
echo '</tr>';
|
||||
} ?>
|
||||
<tbody>
|
||||
</table>
|
||||
<?php die();
|
||||
} // End provider test callback
|
||||
|
||||
function image_download_test_callback() {
|
||||
|
||||
if ( !current_user_can( 'manage_options' ) ) die();
|
||||
|
||||
// Try saving 'http://img.youtube.com/vi/aKAGU2jkaNg/maxresdefault.jpg' to media library
|
||||
$attachment_id = Video_Thumbnails::save_to_media_library( 'http://img.youtube.com/vi/aKAGU2jkaNg/maxresdefault.jpg', 1 );
|
||||
if ( is_wp_error( $attachment_id ) ) {
|
||||
echo '<p><span style="color:red;">✖</span> ' . $attachment_id->get_error_message() . '</p>';
|
||||
} else {
|
||||
update_post_meta( $attachment_id, 'video_thumbnail_test_image', '1' );
|
||||
$image = wp_get_attachment_image_src( $attachment_id, 'full' );
|
||||
echo '<img src="' . $image[0] . '" style="float:left; max-width: 250px; margin-right: 10px;">';
|
||||
echo '<p><span style="color:green;">✔</span> ' . __( 'Attachment created', 'video-thumbnails' ) . '</p>';
|
||||
echo '<p><a href="' . get_edit_post_link( $attachment_id ) . '">' . __( 'View in Media Library', 'video-thumbnails' ) . '</a></p>';
|
||||
echo '<a href="' . $image[0] . '" target="_blank">' . __( 'View full size', 'video-thumbnails' ) . '</a>';
|
||||
echo '<span style="display:block;clear:both;"></span>';
|
||||
}
|
||||
|
||||
die();
|
||||
} // End saving media test callback
|
||||
|
||||
function delete_test_images_callback() {
|
||||
|
||||
if ( !current_user_can( 'manage_options' ) ) die();
|
||||
|
||||
global $wpdb;
|
||||
// Clear images from media library
|
||||
$media_library_items = get_posts( array(
|
||||
'showposts' => -1,
|
||||
'post_type' => 'attachment',
|
||||
'meta_key' => 'video_thumbnail_test_image',
|
||||
'meta_value' => '1',
|
||||
'fields' => 'ids'
|
||||
) );
|
||||
foreach ( $media_library_items as $item ) {
|
||||
wp_delete_attachment( $item, true );
|
||||
}
|
||||
echo '<p><span style="color:green">✔</span> ' . sprintf( _n( '1 attachment deleted', '%s attachments deleted', count( $media_library_items ), 'video-thumbnails' ), count( $media_library_items ) ) . '</p>';
|
||||
|
||||
die();
|
||||
} // End delete test images callback
|
||||
|
||||
function markup_detection_test_callback() {
|
||||
|
||||
if ( !current_user_can( 'manage_options' ) ) die();
|
||||
|
||||
$new_thumbnail = null;
|
||||
|
||||
global $video_thumbnails;
|
||||
|
||||
$markup = apply_filters( 'the_content', stripslashes( $_POST['markup'] ) );
|
||||
|
||||
$new_thumbnail = $video_thumbnails->get_first_thumbnail_url( $markup );
|
||||
|
||||
if ( $new_thumbnail == null ) {
|
||||
// No thumbnail
|
||||
echo '<p><span style="color:red;">✖</span> ' . __( 'No thumbnail found', 'video-thumbnails' ) . '</p>';
|
||||
} elseif ( is_wp_error( $new_thumbnail ) ) {
|
||||
// Error finding thumbnail
|
||||
echo '<p><span style="color:red;">✖</span> ' . __( 'Error Details:', 'video-thumbnails' ) . ' ' . $new_thumbnail->get_error_message() . '</p>';
|
||||
} else {
|
||||
// Found a thumbnail
|
||||
$remote_response = wp_remote_head( $new_thumbnail );
|
||||
if ( is_wp_error( $remote_response ) ) {
|
||||
// WP Error trying to read image from remote server
|
||||
echo '<p><span style="color:red;">✖</span> ' . __( 'Thumbnail found, but there was an error retrieving the URL.', 'video-thumbnails' ) . '</p>';
|
||||
echo '<p>' . __( 'Error Details:', 'video-thumbnails' ) . ' ' . $remote_response->get_error_message() . '</p>';
|
||||
} elseif ( $remote_response['response']['code'] != '200' ) {
|
||||
// Response code isn't okay
|
||||
echo '<p><span style="color:red;">✖</span> ' . __( 'Thumbnail found, but it may not exist on the source server. If opening the URL below in your web browser returns an error, the source is providing an invalid URL.', 'video-thumbnails' ) . '</p>';
|
||||
echo '<p>' . __( 'Thumbnail URL:', 'video-thumbnails' ) . ' <a href="' . $new_thumbnail . '" target="_blank">' . $new_thumbnail . '</a>';
|
||||
} else {
|
||||
// Everything is okay!
|
||||
echo '<p><span style="color:green;">✔</span> ' . __( 'Thumbnail found! Image should appear below.', 'video-thumbnails' ) . ' <a href="' . $new_thumbnail . '" target="_blank">' . __( 'View full size', 'video-thumbnails' ) . '</a></p>';
|
||||
echo '<p><img src="' . $new_thumbnail . '" style="max-width: 500px;"></p>';
|
||||
}
|
||||
}
|
||||
|
||||
die();
|
||||
} // End markup detection test callback
|
||||
|
||||
function initialize_options() {
|
||||
add_settings_section(
|
||||
'general_settings_section',
|
||||
__( 'General Settings', 'video-thumbnails' ),
|
||||
array( &$this, 'general_settings_callback' ),
|
||||
'video_thumbnails'
|
||||
);
|
||||
$this->add_checkbox_setting(
|
||||
'save_media',
|
||||
__( 'Save Thumbnails to Media Library', 'video-thumbnails' ),
|
||||
__( 'Checking this option will download video thumbnails to your server', 'video-thumbnails' )
|
||||
);
|
||||
$this->add_checkbox_setting(
|
||||
'set_featured',
|
||||
__( 'Automatically Set Featured Image', 'video-thumbnails' ),
|
||||
__( 'Check this option to automatically set video thumbnails as the featured image (requires saving to media library)', 'video-thumbnails' )
|
||||
);
|
||||
// Get post types
|
||||
$post_types = get_post_types( null, 'names' );
|
||||
// Remove certain post types from array
|
||||
$post_types = array_diff( $post_types, array( 'attachment', 'revision', 'nav_menu_item' ) );
|
||||
$this->add_multicheckbox_setting(
|
||||
'post_types',
|
||||
__( 'Post Types', 'video-thumbnails' ),
|
||||
$post_types
|
||||
);
|
||||
$this->add_text_setting(
|
||||
'custom_field',
|
||||
__( 'Custom Field (optional)', 'video-thumbnails' ),
|
||||
'<a href="#" class="button" id="vt_detect_custom_field">' . __( 'Automatically Detect', 'video-thumbnails' ) . '</a> ' . __( 'Enter the name of the custom field where your embed code or video URL is stored.', 'video-thumbnails' )
|
||||
);
|
||||
register_setting( 'video_thumbnails', 'video_thumbnails', array( &$this, 'sanitize_callback' ) );
|
||||
}
|
||||
|
||||
function sanitize_callback( $input ) {
|
||||
$current_settings = get_option( 'video_thumbnails' );
|
||||
$output = array();
|
||||
// General settings
|
||||
if ( !isset( $input['provider_options'] ) ) {
|
||||
foreach( $current_settings as $key => $value ) {
|
||||
if ( $key == 'version' OR $key == 'providers' ) {
|
||||
$output[$key] = $current_settings[$key];
|
||||
} elseif ( isset( $input[$key] ) ) {
|
||||
$output[$key] = $input[$key];
|
||||
} else {
|
||||
$output[$key] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
// Provider settings
|
||||
else {
|
||||
$output = $current_settings;
|
||||
unset( $output['providers'] );
|
||||
$output['providers'] = $input['providers'];
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
function general_settings_callback() {
|
||||
echo '<p>' . __( 'These options configure where the plugin will search for videos and what to do with thumbnails once found.', 'video-thumbnails' ) . '</p>';
|
||||
}
|
||||
|
||||
function add_checkbox_setting( $slug, $name, $description ) {
|
||||
add_settings_field(
|
||||
$slug,
|
||||
$name,
|
||||
array( &$this, 'checkbox_callback' ),
|
||||
'video_thumbnails',
|
||||
'general_settings_section',
|
||||
array(
|
||||
'slug' => $slug,
|
||||
'description' => $description
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function checkbox_callback( $args ) {
|
||||
$html = '<label for="' . $args['slug'] . '"><input type="checkbox" id="' . $args['slug'] . '" name="video_thumbnails[' . $args['slug'] . ']" value="1" ' . checked( 1, $this->options[$args['slug']], false ) . '/> ' . $args['description'] . '</label>';
|
||||
echo $html;
|
||||
}
|
||||
|
||||
function add_multicheckbox_setting( $slug, $name, $options ) {
|
||||
add_settings_field(
|
||||
$slug,
|
||||
$name,
|
||||
array( &$this, 'multicheckbox_callback' ),
|
||||
'video_thumbnails',
|
||||
'general_settings_section',
|
||||
array(
|
||||
'slug' => $slug,
|
||||
'options' => $options
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function multicheckbox_callback( $args ) {
|
||||
if ( is_array( $this->options[$args['slug']] ) ) {
|
||||
$selected_types = $this->options[$args['slug']];
|
||||
} else {
|
||||
$selected_types = array();
|
||||
}
|
||||
$html = '';
|
||||
foreach ( $args['options'] as $option ) {
|
||||
$checked = ( in_array( $option, $selected_types ) ? 'checked="checked"' : '' );
|
||||
$html .= '<label for="' . $args['slug'] . '_' . $option . '"><input type="checkbox" id="' . $args['slug'] . '_' . $option . '" name="video_thumbnails[' . $args['slug'] . '][]" value="' . $option . '" ' . $checked . '/> ' . $option . '</label><br>';
|
||||
}
|
||||
echo $html;
|
||||
}
|
||||
|
||||
function add_text_setting( $slug, $name, $description ) {
|
||||
add_settings_field(
|
||||
$slug,
|
||||
$name,
|
||||
array( &$this, 'text_field_callback' ),
|
||||
'video_thumbnails',
|
||||
'general_settings_section',
|
||||
array(
|
||||
'slug' => $slug,
|
||||
'description' => $description
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function text_field_callback( $args ) {
|
||||
$html = '<input type="text" id="' . $args['slug'] . '" name="video_thumbnails[' . $args['slug'] . ']" value="' . $this->options[$args['slug']] . '"/>';
|
||||
$html .= '<label for="' . $args['slug'] . '"> ' . $args['description'] . '</label>';
|
||||
echo $html;
|
||||
}
|
||||
|
||||
function options_page() {
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_die( __( 'You do not have sufficient permissions to access this page.', 'video-thumbnails' ) );
|
||||
}
|
||||
|
||||
global $video_thumbnails;
|
||||
|
||||
?><div class="wrap">
|
||||
|
||||
<div id="icon-options-general" class="icon32"></div><h2><?php _e( 'Video Thumbnails Options', 'video-thumbnails' ); ?></h2>
|
||||
|
||||
<?php $active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'general_settings'; ?>
|
||||
<h2 class="nav-tab-wrapper">
|
||||
<a href="?page=video_thumbnails&tab=general_settings" class="nav-tab <?php echo $active_tab == 'general_settings' ? 'nav-tab-active' : ''; ?>"><?php _e( 'General', 'video-thumbnails' ); ?></a>
|
||||
<a href="?page=video_thumbnails&tab=provider_settings" class="nav-tab <?php echo $active_tab == 'provider_settings' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Providers', 'video-thumbnails' ); ?></a>
|
||||
<a href="?page=video_thumbnails&tab=mass_actions" class="nav-tab <?php echo $active_tab == 'mass_actions' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Mass Actions', 'video-thumbnails' ); ?></a>
|
||||
<a href="?page=video_thumbnails&tab=debugging" class="nav-tab <?php echo $active_tab == 'debugging' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Debugging', 'video-thumbnails' ); ?></a>
|
||||
<a href="?page=video_thumbnails&tab=support" class="nav-tab <?php echo $active_tab == 'support' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Support', 'video-thumbnails' ); ?></a>
|
||||
</h2>
|
||||
|
||||
<?php
|
||||
// Main settings
|
||||
if ( $active_tab == 'general_settings' ) {
|
||||
?>
|
||||
<h3><?php _e( 'Getting started', 'video-thumbnails' ); ?></h3>
|
||||
|
||||
<p><?php _e( 'If your theme supports post thumbnails, just leave "Save Thumbnails to Media Library" and "Automatically Set Featured Image" enabled, then select what post types you\'d like scanned for videos.', 'video-thumbnails' ); ?></p>
|
||||
|
||||
<p><?php _e( 'For more detailed instructions, check out the page for <a href="http://wordpress.org/extend/plugins/video-thumbnails/">Video Thumbnails on the official plugin directory</a>.', 'video-thumbnails' ); ?></p>
|
||||
|
||||
<form method="post" action="options.php">
|
||||
<?php settings_fields( 'video_thumbnails' ); ?>
|
||||
<?php do_settings_sections( 'video_thumbnails' ); ?>
|
||||
<?php submit_button(); ?>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
// End main settings
|
||||
}
|
||||
// Provider Settings
|
||||
if ( $active_tab == 'provider_settings' ) {
|
||||
?>
|
||||
|
||||
<form method="post" action="options.php">
|
||||
<input type="hidden" name="video_thumbnails[provider_options]" value="1" />
|
||||
<?php settings_fields( 'video_thumbnails' ); ?>
|
||||
<?php do_settings_sections( 'video_thumbnails_providers' ); ?>
|
||||
<?php submit_button(); ?>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
// End provider settings
|
||||
}
|
||||
// Scan all posts
|
||||
if ( $active_tab == 'mass_actions' ) {
|
||||
?>
|
||||
<h3><?php _e( 'Scan All Posts', 'video-thumbnails' ); ?></h3>
|
||||
|
||||
<p><?php _e( 'Scan all of your past posts for video thumbnails. Be sure to save any settings before running the scan.', 'video-thumbnails' ); ?></p>
|
||||
|
||||
<p><a class="button-primary" href="<?php echo admin_url( 'tools.php?page=video-thumbnails-bulk' ); ?>"><?php _e( 'Scan Past Posts', 'video-thumbnails' ); ?></a></p>
|
||||
|
||||
<h3><?php _e( 'Clear all Video Thumbnails', 'video-thumbnails' ); ?></h3>
|
||||
|
||||
<p><?php _e( 'This will clear the video thumbnail field for all posts and delete any video thumbnail attachments. Note: This only works for attachments added using version 2.0 or later.', 'video-thumbnails' ); ?></p>
|
||||
|
||||
<p><input type="submit" class="button-primary" onclick="clear_all_video_thumbnails('<?php echo wp_create_nonce( 'clear_all_video_thumbnails' ); ?>');" value="<?php esc_attr_e( 'Clear Video Thumbnails', 'video-thumbnails' ); ?>" /></p>
|
||||
|
||||
<div id="clear-all-video-thumbnails-result"></div>
|
||||
|
||||
<?php
|
||||
// End scan all posts
|
||||
}
|
||||
// Debugging
|
||||
if ( $active_tab == 'debugging' ) {
|
||||
?>
|
||||
|
||||
<p><?php _e( 'Use these tests to help diagnose any problems. Please include results when requesting support.', 'video-thumbnails' ); ?></p>
|
||||
|
||||
<div class="video-thumbnails-test closed">
|
||||
|
||||
<a href="#" class="toggle-video-thumbnails-test-content show-hide-test-link"><span class="show"><?php _e( 'Show', 'video-thumbnails' ); ?></span> <span class="hide"><?php _e( 'Hide', 'video-thumbnails' ); ?></span></a>
|
||||
|
||||
<a href="#" class="toggle-video-thumbnails-test-content title-test-link"><h3 class="test-title"><?php _e( 'Test Video Providers', 'video-thumbnails' ); ?></h3></a>
|
||||
|
||||
<div class="video-thumbnails-test-content">
|
||||
|
||||
<p><?php _e( 'This test automatically searches a sample for every type of video supported and compares it to the expected value. Sometimes tests may fail due to API rate limits.', 'video-thumbnails' ); ?></p>
|
||||
|
||||
<p><input type="submit" class="button-primary video-thumbnails-test-button" id="test-all-video-thumbnail-providers" value="<?php esc_attr_e( 'Test Video Providers', 'video-thumbnails' ); ?>" /></p>
|
||||
|
||||
<div id="provider-test-results" class="hidden">
|
||||
<?php
|
||||
foreach ( $video_thumbnails->providers as $provider ) {
|
||||
echo '<div id="' . $provider->service_slug . '-provider-test" class="single-provider-test-results">';
|
||||
echo '<h3>' . $provider->service_name . ' <input type="submit" data-provider-slug="' . $provider->service_slug . '" class="button-primary retest-video-provider video-thumbnails-test-button" value="' . esc_attr__( 'Waiting...', 'video-thumbnails' ) . '" /></h3>';
|
||||
echo '<div class="test-results"></div>';
|
||||
echo '</div>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
</div><!-- /.video-thumbnails-test-content -->
|
||||
|
||||
</div>
|
||||
<div class="video-thumbnails-test closed">
|
||||
|
||||
<a href="#" class="toggle-video-thumbnails-test-content show-hide-test-link"><span class="show"><?php _e( 'Show', 'video-thumbnails' ); ?></span> <span class="hide"><?php _e( 'Hide', 'video-thumbnails' ); ?></span></a>
|
||||
|
||||
<a href="#" class="toggle-video-thumbnails-test-content title-test-link"><h3 class="test-title"><?php _e( 'Test Markup for Video', 'video-thumbnails' ); ?></h3></a>
|
||||
|
||||
<div class="video-thumbnails-test-content">
|
||||
|
||||
<p><?php _e( 'Copy and paste an embed code below to see if a video is detected.', 'video-thumbnails' ); ?></p>
|
||||
|
||||
<textarea id="markup-input" cols="50" rows="5"></textarea>
|
||||
|
||||
<p><input type="submit" id="test-markup-detection" class="button-primary video-thumbnails-test-button" value="<?php esc_attr_e( 'Scan For Thumbnail', 'video-thumbnails' ); ?>" /></p>
|
||||
|
||||
<div id="markup-test-result"></div>
|
||||
|
||||
</div><!-- /.video-thumbnails-test-content -->
|
||||
|
||||
</div>
|
||||
<div class="video-thumbnails-test closed">
|
||||
|
||||
<a href="#" class="toggle-video-thumbnails-test-content show-hide-test-link"><span class="show"><?php _e( 'Show', 'video-thumbnails' ); ?></span> <span class="hide"><?php _e( 'Hide', 'video-thumbnails' ); ?></span></a>
|
||||
|
||||
<a href="#" class="toggle-video-thumbnails-test-content title-test-link"><h3 class="test-title"><?php _e( 'Test Saving to Media Library', 'video-thumbnails' ); ?></h3></a>
|
||||
|
||||
<div class="video-thumbnails-test-content">
|
||||
|
||||
<p><?php _e( 'This test checks for issues with the process of saving a remote thumbnail to your local media library.', 'video-thumbnails' ); ?></p>
|
||||
|
||||
<p><?php _e( 'Also be sure to test that you can manually upload an image to your site. If you\'re unable to upload images, you may need to <a href="http://codex.wordpress.org/Changing_File_Permissions">change file permissions</a>.', 'video-thumbnails' ); ?></p>
|
||||
|
||||
<p>
|
||||
<input type="submit" id="test-video-thumbnail-saving-media" class="button-primary video-thumbnails-test-button" value="<?php esc_attr_e( 'Download Test Image', 'video-thumbnails' ); ?>" />
|
||||
<input type="submit" id="delete-video-thumbnail-test-images" class="button video-thumbnails-test-button" value="<?php esc_attr_e( 'Delete Test Images', 'video-thumbnails' ); ?>" />
|
||||
</p>
|
||||
|
||||
<div id="media-test-result"></div>
|
||||
|
||||
</div><!-- /.video-thumbnails-test-content -->
|
||||
|
||||
</div>
|
||||
<div class="video-thumbnails-test closed">
|
||||
|
||||
<a href="#" class="toggle-video-thumbnails-test-content show-hide-test-link"><span class="show"><?php _e( 'Show', 'video-thumbnails' ); ?></span> <span class="hide"><?php _e( 'Hide', 'video-thumbnails' ); ?></span></a>
|
||||
|
||||
<a href="#" class="toggle-video-thumbnails-test-content title-test-link"><h3 class="test-title"><?php _e( 'Installation Information', 'video-thumbnails' ); ?></h3></a>
|
||||
|
||||
<div class="video-thumbnails-test-content">
|
||||
|
||||
<table class="widefat">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><strong><?php _e( 'WordPress Version', 'video-thumbnails' ); ?></strong></td>
|
||||
<td><?php echo get_bloginfo( 'version' ); ?></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong><?php _e( 'Video Thumbnails Version', 'video-thumbnails' ); ?></strong></td>
|
||||
<td><?php echo VIDEO_THUMBNAILS_VERSION; ?></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong><?php _e( 'Video Thumbnails Settings Version', 'video-thumbnails' ); ?></strong></td>
|
||||
<td><?php echo $this->options['version']; ?></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong><?php _e( 'PHP Version', 'video-thumbnails' ); ?></strong></td>
|
||||
<td><?php echo PHP_VERSION; ?></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong><?php _e( 'Post Thumbnails', 'video-thumbnails' ); ?></strong></td>
|
||||
<td><?php if ( current_theme_supports( 'post-thumbnails' ) ) : ?><span style="color:green">✔</span> <?php _e( 'Your theme supports post thumbnails.', 'video-thumbnails' ); ?><?php else: ?><span style="color:red">✖</span> <?php _e( 'Your theme does not support post thumbnails, you\'ll need to make modifications or switch to a different theme. <a href="http://codex.wordpress.org/Post_Thumbnails">More info</a>', 'video-thumbnails' ); ?><?php endif; ?></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong><?php _e( 'Video Providers', 'video-thumbnails' ); ?></strong></td>
|
||||
<td>
|
||||
<?php global $video_thumbnails; ?>
|
||||
<?php $provider_names = array(); foreach ( $video_thumbnails->providers as $provider ) { $provider_names[] = $provider->service_name; }; ?>
|
||||
<strong><?php echo count( $video_thumbnails->providers ); ?></strong>: <?php echo implode( ', ', $provider_names ); ?>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
|
||||
</div><!-- /.video-thumbnails-test-content -->
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
// End debugging
|
||||
}
|
||||
// Support
|
||||
if ( $active_tab == 'support' ) {
|
||||
|
||||
Video_Thumbnails::no_video_thumbnail_troubleshooting_instructions();
|
||||
|
||||
// End support
|
||||
}
|
||||
?>
|
||||
|
||||
<?php do_action( 'video_thumbnails/settings_footer' ); ?>
|
||||
|
||||
</div><?php
|
||||
}
|
||||
|
||||
public static function settings_footer() {
|
||||
?>
|
||||
<div style="width: 250px; margin: 20px 0; padding: 0 20px; background: #fff; border: 1px solid #dfdfdf; text-align: center;">
|
||||
<div>
|
||||
<p><?php _e( 'Support video thumbnails and unlock additional features', 'video-thumbnails' ); ?></p>
|
||||
<p><a href="https://refactored.co/plugins/video-thumbnails" class="button button-primary button-large"><?php _e( 'Go Pro', 'video-thumbnails' ); ?></a></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require YouTube provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-youtube-thumbnails.php' );
|
||||
|
||||
/**
|
||||
* Checks if AYVP is importing
|
||||
* @return boolean True if importing, false if not
|
||||
*/
|
||||
function is_ayvp_importing() {
|
||||
// Global variables used by AYVP
|
||||
global $getWP, $tern_wp_youtube_options, $tern_wp_youtube_o;
|
||||
// Check for the class used by AYVP
|
||||
if ( class_exists( 'ternWP' ) && isset( $getWP ) ) {
|
||||
// Load the AYVP options
|
||||
$tern_wp_youtube_o = $getWP->getOption( 'tern_wp_youtube', $tern_wp_youtube_options );
|
||||
if ( $tern_wp_youtube_o['is_importing'] && $tern_wp_youtube_o['is_importing'] !== false ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function ayvp_new_video_thumbnail_url_filter( $new_thumbnail, $post_id ) {
|
||||
global $video_thumbnails;
|
||||
if ( !isset( $video_thumbnails->providers['youtube'] ) ) return false;
|
||||
// When publishing a post during import, use the global variable to generate thumbnail
|
||||
if ( $new_thumbnail == null && is_ayvp_importing() ) {
|
||||
global $tern_wp_youtube_array;
|
||||
if ( isset( $tern_wp_youtube_array['_tern_wp_youtube_video'] ) && $tern_wp_youtube_array['_tern_wp_youtube_video'] != '' ) {
|
||||
$new_thumbnail = $video_thumbnails->providers['youtube']->get_thumbnail_url( $tern_wp_youtube_array['_tern_wp_youtube_video'] );
|
||||
}
|
||||
}
|
||||
// When automatic publishing is disabled or rescanning an existing post, use custom field data to generate thumbnail
|
||||
if ( $new_thumbnail == null ) {
|
||||
$youtube_id = get_post_meta( $post_id, '_tern_wp_youtube_video', true );
|
||||
if ( $youtube_id != '' ) {
|
||||
$new_thumbnail = $video_thumbnails->providers['youtube']->get_thumbnail_url( $youtube_id );
|
||||
}
|
||||
}
|
||||
return $new_thumbnail;
|
||||
}
|
||||
|
||||
// Make sure we can use is_plugin_active()
|
||||
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
||||
|
||||
// If AYVP is active, add filter
|
||||
if ( is_plugin_active( 'automatic-youtube-video-posts/tern_wp_youtube.php' ) ) {
|
||||
add_filter( 'new_video_thumbnail_url', 'ayvp_new_video_thumbnail_url_filter', 10, 2 );
|
||||
remove_filter( 'post_thumbnail_html', 'WP_ayvpp_thumbnail' );
|
||||
remove_filter( 'post_thumbnail_size', 'WP_ayvpp_thumbnail_size' );
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/extensions/automatic-youtube-video-posts.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/extensions/simple-video-embedder.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/extensions/wp-robot.php' );
|
||||
|
||||
?>
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
function simple_video_embedder_video_thumbnail_markup_filter( $markup, $post_id ) {
|
||||
if ( function_exists( 'p75HasVideo' ) ) {
|
||||
if ( p75HasVideo( $post_id ) ) {
|
||||
$markup .= ' ' . p75GetVideo( $post_id );
|
||||
}
|
||||
}
|
||||
return $markup;
|
||||
}
|
||||
|
||||
// Add filter to modify markup
|
||||
add_filter( 'video_thumbnail_markup', 'simple_video_embedder_video_thumbnail_markup_filter', 10, 2 );
|
||||
|
||||
?>
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
function video_thumbnails_wpr_after_post_action( $post_id ) {
|
||||
// Don't save video thumbnails during autosave or for unpublished posts
|
||||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return null;
|
||||
if ( get_post_status( $post_id ) != 'publish' ) return null;
|
||||
// Check that Video Thumbnails are enabled for current post type
|
||||
$post_type = get_post_type( $post_id );
|
||||
global $video_thumbnails;
|
||||
if ( in_array( $post_type, (array) $video_thumbnails->settings->options['post_types'] ) || $post_type == $video_thumbnails->settings->options['post_types'] ) {
|
||||
$video_thumbnails->get_video_thumbnail( $post_id );
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
add_action( 'wpr_after_post', 'video_thumbnails_wpr_after_post_action', 10, 1 );
|
||||
|
||||
?>
|
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Blip_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'Blip';
|
||||
const service_name = 'Blip';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'blip';
|
||||
const service_slug = 'blip';
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#(https?\:\/\/blip\.tv\/[^\r\n\'\"]+)#' // Blip URL
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $url ) {
|
||||
$request = "http://blip.tv/oembed?url=$url";
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$json = json_decode( $response['body'] );
|
||||
if ( isset( $json->error ) ) {
|
||||
$result = new WP_Error( 'blip_invalid_url', sprintf( __( 'Error retrieving video information for <a href="%1$s">%1$s</a>. Check to be sure this is a valid Blip video URL.', 'video-thumbnails' ), $url ) );
|
||||
} else {
|
||||
$result = $json->thumbnail_url;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => 'http://blip.tv/cranetv/illustrator-katie-scott-6617917',
|
||||
'expected' => 'http://a.images.blip.tv/CraneTV-IllustratorKatieScott610.jpg',
|
||||
'expected_hash' => '26a622f72bd4bdb3f8189f85598dd95d',
|
||||
'name' => __( 'Video URL', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => '<iframe src="http://blip.tv/play/AYLz%2BEsC.html?p=1" width="780" height="438" frameborder="0" allowfullscreen></iframe><embed type="application/x-shockwave-flash" src="http://a.blip.tv/api.swf#AYLz+EsC" style="display:none"></embed>',
|
||||
'expected' => 'http://a.images.blip.tv/GeekCrashCourse-TheAvengersMarvelMovieCatchUpGeekCrashCourse331.png',
|
||||
'expected_hash' => '87efa9f6b0d9111b0826ae4fbdddec1b',
|
||||
'name' => __( 'iFrame Embed', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class CollegeHumor_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'CollegeHumor';
|
||||
const service_name = 'CollegeHumor';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'collegehumor';
|
||||
const service_slug = 'collegehumor';
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#https?://(?:www\.)?collegehumor\.com/(?:video|e)/([0-9]+)#' // URL
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
$request = "http://www.collegehumor.com/oembed.json?url=http%3A%2F%2Fwww.collegehumor.com%2Fvideo%2F$id";
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$result = json_decode( $response['body'] );
|
||||
$result = $result->thumbnail_url;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<iframe src="http://www.collegehumor.com/e/6830834" width="600" height="338" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe><div style="padding:5px 0; text-align:center; width:600px;"><p><a href="http://www.collegehumor.com/videos/most-viewed/this-year">CollegeHumor\'s Favorite Funny Videos</a></p></div>',
|
||||
'expected' => 'http://2.media.collegehumor.cvcdn.com/62/99/20502ca0d5b2172421002b52f437dcf8-mitt-romney-style-gangnam-style-parody.jpg',
|
||||
'expected_hash' => 'ceac16f6ee1fa5d8707e813226060a15',
|
||||
'name' => __( 'iFrame Embed', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => 'http://www.collegehumor.com/video/6830834/mitt-romney-style-gangnam-style-parody',
|
||||
'expected' => 'http://2.media.collegehumor.cvcdn.com/62/99/20502ca0d5b2172421002b52f437dcf8-mitt-romney-style-gangnam-style-parody.jpg',
|
||||
'expected_hash' => 'ceac16f6ee1fa5d8707e813226060a15',
|
||||
'name' => __( 'Video URL', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Dailymotion_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'Dailymotion';
|
||||
const service_name = 'Dailymotion';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'dailymotion';
|
||||
const service_slug = 'dailymotion';
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#<object[^>]+>.+?http://www\.dailymotion\.com/swf/video/([A-Za-z0-9]+).+?</object>#s', // Dailymotion flash
|
||||
'#//www\.dailymotion\.com/embed/video/([A-Za-z0-9]+)#', // Dailymotion iframe
|
||||
'#(?:https?://)?(?:www\.)?dailymotion\.com/video/([A-Za-z0-9]+)#' // Dailymotion URL
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
$request = "https://api.dailymotion.com/video/$id?fields=thumbnail_url";
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$result = json_decode( $response['body'] );
|
||||
$result = $result->thumbnail_url;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<iframe frameborder="0" width="480" height="270" src="http://www.dailymotion.com/embed/video/xqlhts"></iframe><br /><a href="http://www.dailymotion.com/video/xqlhts_adam-yauch-of-the-beastie-boys-dies-at-47_people" target="_blank">Adam Yauch of the Beastie Boys Dies at 47</a> <i>by <a href="http://www.dailymotion.com/associatedpress" target="_blank">associatedpress</a></i>',
|
||||
'expected' => 'http://s1.dmcdn.net/AMjdy.jpg',
|
||||
'expected_hash' => '077888b97839254892a377f51c06e642',
|
||||
'name' => __( 'iFrame Embed', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => '<object width="480" height="270"><param name="movie" value="http://www.dailymotion.com/swf/video/xqlhts"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><param name="wmode" value="transparent"></param><embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/xqlhts" width="480" height="270" wmode="transparent" allowfullscreen="true" allowscriptaccess="always"></embed></object><br /><a href="http://www.dailymotion.com/video/xqlhts_adam-yauch-of-the-beastie-boys-dies-at-47_people" target="_blank">Adam Yauch of the Beastie Boys Dies at 47</a> <i>by <a href="http://www.dailymotion.com/associatedpress" target="_blank">associatedpress</a></i>',
|
||||
'expected' => 'http://s1.dmcdn.net/AMjdy.jpg',
|
||||
'expected_hash' => '077888b97839254892a377f51c06e642',
|
||||
'name' => __( 'Flash Embed', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Facebook_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'Facebook';
|
||||
const service_name = 'Facebook';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'facebook';
|
||||
const service_slug = 'facebook';
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#(?://|\%2F\%2F)(?:www\.)?facebook\.com(?:/|\%2F)(?:[a-zA-Z0-9]+)(?:/|\%2F)videos(?:/|\%2F)([0-9]+)#', // URL Embed
|
||||
'#http://www\.facebook\.com/v/([0-9]+)#', // Flash Embed
|
||||
'#https?://www\.facebook\.com/video/embed\?video_id=([0-9]+)#', // iFrame Embed
|
||||
'#https?://www\.facebook\.com/video\.php\?v=([0-9]+)#'
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
$request = 'https://graph.facebook.com/' . $id . '/picture?redirect=false';
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$result = json_decode( $response['body'] );
|
||||
$result = $result->data->url;
|
||||
$high_res = str_replace( '_t.jpg', '_b.jpg', $result);
|
||||
if ( $high_res != $result ) {
|
||||
$response = wp_remote_head( $high_res );
|
||||
if ( !is_wp_error( $response ) && $response['response']['code'] == '200' ) {
|
||||
$result = $high_res;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<object width=420 height=180><param name=allowfullscreen value=true></param><param name=allowscriptaccess value=always></param><param name=movie value="http://www.facebook.com/v/2560032632599"></param><embed src="http://www.facebook.com/v/2560032632599" type="application/x-shockwave-flash" allowscriptaccess=always allowfullscreen=true width=420 height=180></embed></object>',
|
||||
'expected' => 'https://fbcdn-vthumb-a.akamaihd.net/hvthumb-ak-xap1/v/t15.0-10/p160x160/50796_2560034672650_2560032632599_65313_313_b.jpg?oh=e8c767b1efafa6d8a4b672bad7be38d6&oe=55364081&__gda__=1428807476_a4d83140019b11ad602f2ef9960a364e',
|
||||
'expected_hash' => '6b033d8f16dbf273048c5771d32ede64',
|
||||
'name' => __( 'Flash Embed', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => '<iframe src="https://www.facebook.com/video/embed?video_id=2560032632599" width="960" height="720" frameborder="0"></iframe>',
|
||||
'expected' => 'https://fbcdn-vthumb-a.akamaihd.net/hvthumb-ak-xap1/v/t15.0-10/p160x160/50796_2560034672650_2560032632599_65313_313_b.jpg?oh=e8c767b1efafa6d8a4b672bad7be38d6&oe=55364081&__gda__=1428807476_a4d83140019b11ad602f2ef9960a364e',
|
||||
'expected_hash' => '6b033d8f16dbf273048c5771d32ede64',
|
||||
'name' => __( 'iFrame Embed', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => '<div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, \'script\', \'facebook-jssdk\'));</script><div class="fb-post" data-href="https://www.facebook.com/video.php?v=10150326323406807" data-width="466"><div class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/video.php?v=10150326323406807">Post</a> by <a href="https://www.facebook.com/PeterJacksonNZ">Peter Jackson</a>.</div></div>',
|
||||
'expected' => 'https://fbcdn-vthumb-a.akamaihd.net/hvthumb-ak-xfa1/v/t15.0-10/p128x128/244423_10150326375786807_10150326323406807_4366_759_b.jpg?oh=013ce21bb54de51c383071598b269a91&oe=552CD270&__gda__=1428479462_339647870ec32227c391e98000935aec',
|
||||
'expected_hash' => '184d20db21ac8edef9c9cee291be5ee6',
|
||||
'name' => __( 'FBML Embed', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Funnyordie_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'Funny or Die';
|
||||
const service_name = 'Funny or Die';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'funnyordie';
|
||||
const service_slug = 'funnyordie';
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#http://www\.funnyordie\.com/embed/([A-Za-z0-9]+)#', // Iframe src
|
||||
'#id="ordie_player_([A-Za-z0-9]+)"#' // Flash object
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
$request = "http://www.funnyordie.com/oembed.json?url=http%3A%2F%2Fwww.funnyordie.com%2Fvideos%2F$id";
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$result = json_decode( $response['body'] );
|
||||
$result = $result->thumbnail_url;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<iframe src="http://www.funnyordie.com/embed/5325b03b52" width="640" height="400" frameborder="0"></iframe>',
|
||||
'expected' => 'http://t.fod4.com/t/5325b03b52/c480x270_17.jpg',
|
||||
'expected_hash' => '5aafa4a5f27bd4aead574db38a9e8b2b',
|
||||
'name' => __( 'iFrame Embed', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => '<object width="640" height="400" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="ordie_player_5325b03b52"><param name="movie" value="http://player.ordienetworks.com/flash/fodplayer.swf" /><param name="flashvars" value="key=5325b03b52" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always"><embed width="640" height="400" flashvars="key=5325b03b52" allowfullscreen="true" allowscriptaccess="always" quality="high" src="http://player.ordienetworks.com/flash/fodplayer.swf" name="ordie_player_5325b03b52" type="application/x-shockwave-flash"></embed></object>',
|
||||
'expected' => 'http://t.fod4.com/t/5325b03b52/c480x270_17.jpg',
|
||||
'expected_hash' => '5aafa4a5f27bd4aead574db38a9e8b2b',
|
||||
'name' => __( 'Flash Embed', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Googledrive_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'Google Drive';
|
||||
const service_name = 'Google Drive';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'googledrive';
|
||||
const service_slug = 'googledrive';
|
||||
|
||||
public $options_section = array(
|
||||
'description' => '<p><strong>Optional</strong>: Only required if using videos from Google Drive.</p><p><strong>Directions</strong>: Go to the <a href="https://cloud.google.com/console/project">Google Developers Console</a>, create a project, then enable the Drive API. Next go to the credentials section and create a new public API access key. Choose server key, then leave allowed IPs blank and click create. Copy and paste your new API key below.</p>',
|
||||
'fields' => array(
|
||||
'api_key' => array(
|
||||
'name' => 'API Key',
|
||||
'type' => 'text',
|
||||
'description' => ''
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#(?:https?:)?//docs\.google\.com/(?:a/[^/]+/)?file/d/([A-Za-z0-9\-_]+)/preview#', // iFrame URL
|
||||
'#(?:https?:)?//video\.google\.com/get_player\?docid=([A-Za-z0-9\-_]+)#', // Flash URL
|
||||
'#<param value="(?:[^"]+)?docid=([A-Za-z0-9\-_]+)(?:[^"]+)?" name="flashvars">#', // Flash (YouTube player)
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
// Get our API key
|
||||
$api_key = ( isset( $this->options['api_key'] ) && $this->options['api_key'] != '' ? $this->options['api_key'] : false );
|
||||
|
||||
if ( $api_key ) {
|
||||
$request = "https://www.googleapis.com/drive/v2/files/$id?fields=thumbnailLink&key=$api_key";
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$json = json_decode( $response['body'] );
|
||||
if ( isset( $json->error ) ) {
|
||||
$result = new WP_Error( 'googledrive_info_retrieval', $json->error->message );
|
||||
} else {
|
||||
$result = $json->thumbnailLink;
|
||||
$result = str_replace( '=s220', '=s480', $result );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$result = new WP_Error( 'googledrive_api_key', __( 'You must enter an API key in the <a href="' . admin_url( 'options-general.php?page=video_thumbnails&tab=provider_settings' ) . '">provider settings</a> to retrieve thumbnails from Google Drive.', 'video-thumbnails' ) );
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<iframe src="https://docs.google.com/file/d/0B2tG5YeQL99ZUHNja3l6am9jSGM/preview?pli=1" width="640" height="385"></iframe>',
|
||||
'expected' => 'https://lh3.googleusercontent.com/QL3d7Wh7V_qcXnMpXT6bio77RS0veyCZZ0zQbMX6gd-qH7aeIXBkXlcSJVDEyftiiA=s480',
|
||||
'expected_hash' => '3bc674d8d77b342e633ab9e93e345462',
|
||||
'name' => __( 'iFrame Embed', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => '<iframe height="385" src="https://docs.google.com/a/svpanthers.org/file/d/0BxQsabDaO6USYUgxSUJ3T0ZBa3M/preview" width="100%"></iframe>',
|
||||
'expected' => 'https://lh6.googleusercontent.com/WeOdCsaplJ3am25To1uLZiVYkyrilAQ5rxzhjnyyFc5GAF4QeCF1eq3EMpbP7O5dFg=s480',
|
||||
'expected_hash' => 'f120755bbd1d35e381cb84a829ac0dfa',
|
||||
'name' => __( 'iFrame Embed (Apps account)', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => '<object width="500" height="385" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="https://video.google.com/get_player?docid=0B92WKFCDHyg9NTRqYTFjVkZmNlk&ps=docs&partnerid=30&cc_load_policy=1" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><embed width="500" height="385" type="application/x-shockwave-flash" src="https://video.google.com/get_player?docid=0B92WKFCDHyg9NTRqYTFjVkZmNlk&ps=docs&partnerid=30&cc_load_policy=1" allowFullScreen="true" allowScriptAccess="always" allowfullscreen="true" allowscriptaccess="always" /></object>',
|
||||
'expected' => 'https://lh3.googleusercontent.com/U_lqaX1o7E9iU75XwCrHZ4pdSi-Vch2F_GK5Ib7WAxgwKTvTl0kMHXm2GxKo1Pcp3Q=s480',
|
||||
'expected_hash' => '31cf8e05f981c1beb6e04823ad54d267',
|
||||
'name' => __( 'Flash Embed', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => '<object style="" id="" data="https://youtube.com/get_player?el=leaf" wmode="opaque" allowfullscreen="true" allowscriptaccess="always" type="application/x-shockwave-flash" height="720px" width="1280px"><param value="true" name="allowFullScreen"><param value="always" name="allowscriptaccess"><param value="opaque" name="wmode"><param value="allow_embed=0&partnerid=30&autoplay=1&showinfo=0&docid=0B9VJd4kStxIVellHZEdXdmdSamM&el=leaf" name="flashvars"></object>',
|
||||
'expected' => 'https://lh5.googleusercontent.com/mHn5gESachhZHi-kbPCRbR6RVXZm3bR7oNNXL97LyYjpzV3Eqty71J2Waw0DPnXKKw=s480',
|
||||
'expected_hash' => '2d0ad4881e4b38de0510a103d2f40dd1',
|
||||
'name' => __( 'Flash Embed (YouTube player)', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Kaltura_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'Kaltura';
|
||||
const service_name = 'Kaltura';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'kaltura';
|
||||
const service_slug = 'kaltura';
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#http://cdnapi\.kaltura\.com/p/[0-9]+/sp/[0-9]+/embedIframeJs/uiconf_id/[0-9]+/partner_id/[0-9]+\?entry_id=([a-z0-9_]+)#' // Hosted
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
$request = "http://www.kaltura.com/api_v3/?service=thumbAsset&action=getbyentryid&entryId=$id";
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$xml = new SimpleXMLElement( $response['body'] );
|
||||
$result = (string) $xml->result->item->id;
|
||||
$request = "http://www.kaltura.com/api_v3/?service=thumbAsset&action=geturl&id=$result";
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$xml = new SimpleXMLElement( $response['body'] );
|
||||
$result = (string) $xml->result;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<script type="text/javascript" src="http://cdnapi.kaltura.com/p/1374841/sp/137484100/embedIframeJs/uiconf_id/12680902/partner_id/1374841?entry_id=1_y7xzqsxw&playerId=kaltura_player_1363589321&cache_st=1363589321&autoembed=true&width=400&height=333&"></script>',
|
||||
'expected' => 'http://example.com/thumbnail.jpg',
|
||||
'name' => __( 'Auto Embed', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2015 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Livestream_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'Livestream';
|
||||
const service_name = 'Livestream';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'livestream';
|
||||
const service_slug = 'livestream';
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#\/\/cdn\.livestream\.com\/embed\/([A-Za-z0-9_]+)#', // Embed SRC
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
$result = 'http://thumbnail.api.livestream.com/thumbnail?name=' . $id;
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<iframe width="560" height="340" src="http://cdn.livestream.com/embed/WFMZ_Traffic?layout=4&height=340&width=560&autoplay=false" style="border:0;outline:0" frameborder="0" scrolling="no"></iframe>',
|
||||
'expected' => 'http://thumbnail.api.livestream.com/thumbnail?name=WFMZ_Traffic',
|
||||
'expected_hash' => '1be02799b2fab7a4749b2187f7687412',
|
||||
'name' => __( 'iFrame Embed', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Metacafe_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'Metacafe';
|
||||
const service_name = 'Metacafe';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'metacafe';
|
||||
const service_slug = 'metacafe';
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#http://www\.metacafe\.com/fplayer/([A-Za-z0-9\-_]+)/#' // Metacafe embed
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
$request = "http://www.metacafe.com/api/item/$id/";
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$xml = new SimpleXMLElement( $response['body'] );
|
||||
$result = $xml->xpath( "/rss/channel/item/media:thumbnail/@url" );
|
||||
$result = (string) $result[0]['url'];
|
||||
$result = $this->drop_url_parameters( $result );
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<embed flashVars="playerVars=autoPlay=no" src="http://www.metacafe.com/fplayer/8456223/men_in_black_3_trailer_2.swf" width="440" height="248" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_8456223" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>',
|
||||
'expected' => 'http://s4.mcstatic.com/thumb/8456223/22479418/4/catalog_item5/0/1/men_in_black_3_trailer_2.jpg',
|
||||
'expected_hash' => '977187bfb00df55b39724d7de284f617',
|
||||
'name' => __( 'Flash Embed', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Mpora_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'MPORA';
|
||||
const service_name = 'MPORA';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'mpora';
|
||||
const service_slug = 'mpora';
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#http://(?:video\.|www\.)?mpora\.com/(?:ep|videos)/([A-Za-z0-9]+)#', // Flash or iFrame src
|
||||
'#mporaplayer_([A-Za-z0-9]+)_#' // Object ID
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
return 'http://ugc4.mporatrons.com/thumbs/' . $id . '_640x360_0000.jpg';
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<object width="480" height="270" id="mporaplayer_wEr2CBooV_N" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" type="application/x-shockwave-flash" ><param name="movie" value="http://video.mpora.com/ep/wEr2CBooV/"></param><param name="wmode" value="transparent"></param><param name="allowScriptAccess" value="always"></param><param name="allowFullScreen" value="true"></param><embed src="http://video.mpora.com/ep/wEr2CBooV/" width="480" height="270" wmode="transparent" allowfullscreen="true" allowscriptaccess="always" type="application/x-shockwave-flash"></embed></object>',
|
||||
'expected' => 'http://ugc4.mporatrons.com/thumbs/wEr2CBooV_640x360_0000.jpg',
|
||||
'expected_hash' => '95075bd4941251ebecbab3b436a90c49',
|
||||
'name' => __( 'Flash Embed', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => '<iframe width="640" height="360" src="http://mpora.com/videos/AAdfegovdop0/embed" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
|
||||
'expected' => 'http://ugc4.mporatrons.com/thumbs/AAdfegovdop0_640x360_0000.jpg',
|
||||
'expected_hash' => '45db22a2ba5ef20163f52ba562b89259',
|
||||
'name' => __( 'iFrame Embed', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Rutube_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'Rutube';
|
||||
const service_name = 'Rutube';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'rutube';
|
||||
const service_slug = 'rutube';
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#(?:https?://)?(?:www\.)?rutube\.ru/video/(?:embed/)?([A-Za-z0-9]+)#', // Video link/Embed src
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
if ( strlen( $id ) < 32 ) {
|
||||
$request = "http://rutube.ru/api/oembed/?url=http%3A//rutube.ru/tracks/$id.html&format=json";
|
||||
} else {
|
||||
$request = "http://rutube.ru/api/video/$id/?format=json";
|
||||
}
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$result = json_decode( $response['body'] );
|
||||
$result = $result->thumbnail_url;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => 'http://rutube.ru/video/ca8607cd4f7ef28516e043dde0068564/',
|
||||
'expected' => 'http://pic.rutube.ru/video/3a/c8/3ac8c1ded16501002d20fa3ba3ed3d61.jpg',
|
||||
'expected_hash' => '85ad79c118ee82c7c2a756ba29a96354',
|
||||
'name' => __( 'Video URL', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => '<iframe width="720" height="405" src="//rutube.ru/video/embed/6608735" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowfullscreen></iframe>',
|
||||
'expected' => 'http://pic.rutube.ru/video/3a/c8/3ac8c1ded16501002d20fa3ba3ed3d61.jpg',
|
||||
'expected_hash' => '85ad79c118ee82c7c2a756ba29a96354',
|
||||
'name' => __( 'iFrame Embed', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Sapo_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'SAPO';
|
||||
const service_name = 'SAPO';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'sapo';
|
||||
const service_slug = 'sapo';
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#videos\.sapo\.pt/([A-Za-z0-9]+)/mov#', // iFrame SRC
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
$request = "http://videos.sapo.pt/$id";
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$doc = new DOMDocument();
|
||||
@$doc->loadHTML( $response['body'] );
|
||||
$metas = $doc->getElementsByTagName( 'meta' );
|
||||
for ( $i = 0; $i < $metas->length; $i++ ) {
|
||||
$meta = $metas->item( $i );
|
||||
if ( $meta->getAttribute( 'property' ) == 'og:image' ) {
|
||||
$og_image = $meta->getAttribute( 'content' );
|
||||
parse_str( parse_url( $og_image, PHP_URL_QUERY ), $image_array );
|
||||
$result = $image_array['pic'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<iframe src="http://rd3.videos.sapo.pt/playhtml?file=http://rd3.videos.sapo.pt/ddACsFSuDEZZRWfNHTTy/mov/1" frameborder="0" scrolling="no" width="640" height="360" webkitallowfullscreen mozallowfullscreen allowfullscreen ></iframe>',
|
||||
'expected' => 'http://cache02.stormap.sapo.pt/vidstore14/thumbnais/e9/08/37/7038489_l5VMt.jpg',
|
||||
'expected_hash' => 'd8a74c3d4e054263a37abe9ceed782fd',
|
||||
'name' => __( 'iFrame Embed', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Ted_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'TED';
|
||||
const service_name = 'TED';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'ted';
|
||||
const service_slug = 'ted';
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#//embed(?:\-ssl)?\.ted\.com/talks/(?:lang/[A-Za-z_-]+/)?([A-Za-z0-9_-]+)\.html#', // iFrame SRC
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
$request = "http://www.ted.com/talks/oembed.json?url=http%3A%2F%2Fwww.ted.com%2Ftalks%2F$id";
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$result = json_decode( $response['body'] );
|
||||
$result = str_replace( '240x180.jpg', '480x360.jpg', $result->thumbnail_url );
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<iframe src="http://embed.ted.com/talks/kitra_cahana_stories_of_the_homeless_and_hidden.html" width="640" height="360" frameborder="0" scrolling="no" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
|
||||
'expected' => 'http://images.ted.com/images/ted/341053090f8bac8c324c75be3114b673b4355e8a_480x360.jpg?lang=en',
|
||||
'expected_hash' => 'f2a5f6af49e841b4f9c7b95d6ca0372a',
|
||||
'name' => __( 'iFrame Embed', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => '<iframe src="https://embed-ssl.ted.com/talks/lang/fr-ca/shimpei_takahashi_play_this_game_to_come_up_with_original_ideas.html" width="640" height="360" frameborder="0" scrolling="no" allowfullscreen="allowfullscreen"></iframe>',
|
||||
'expected' => 'http://images.ted.com/images/ted/b1f1183311cda4df9e1b65f2b363e0b806bff914_480x360.jpg?lang=en',
|
||||
'expected_hash' => 'ff47c99c9eb95e3d6c4b986b18991f22',
|
||||
'name' => __( 'Custom Language', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Tudou_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'Tudou';
|
||||
const service_name = 'Tudou';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'tudou';
|
||||
const service_slug = 'tudou';
|
||||
|
||||
public $options_section = array(
|
||||
'description' => '<p><strong>Optional</strong>: Only required if using videos from Tudou.</p><p><strong>Directions</strong>: Go to <a href="http://open.tudou.com/">open.tudou.com</a> and create an application, then copy and paste your app key below.</p>',
|
||||
'fields' => array(
|
||||
'app_key' => array(
|
||||
'name' => 'App Key',
|
||||
'type' => 'text',
|
||||
'description' => ''
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#//(?:www\.)?tudou\.com/programs/view/html5embed\.action\?type=(?:[0-9]+)(?:&|&\#038;|&)code=([A-Za-z0-9\-_]+)#', // iFrame SRC
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
// Get our API key
|
||||
$app_key = ( isset( $this->options['app_key'] ) && $this->options['app_key'] != '' ? $this->options['app_key'] : false );
|
||||
|
||||
if ( $app_key ) {
|
||||
$request = "http://api.tudou.com/v6/video/info?app_key=$app_key&format=json&itemCodes=$id";
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$result = json_decode( $response['body'] );
|
||||
if ( isset( $result->error_info ) ) {
|
||||
$result = new WP_Error( 'tudou_api_error', $result->error_info );
|
||||
} elseif ( !isset( $result->results[0]->bigPicUrl ) ) {
|
||||
$result = new WP_Error( 'tudou_not_found', sprintf( __( 'Unable to retrieve thumbnail for Tudou video with an ID of %s', 'video-thumbnails' ), $id ) );
|
||||
} else {
|
||||
$result = $result->results[0]->bigPicUrl;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$result = new WP_Error( 'tudou_api_key', __( 'You must enter an API key in the <a href="' . admin_url( 'options-general.php?page=video_thumbnails&tab=provider_settings' ) . '">provider settings</a> to retrieve thumbnails from Tudou.', 'video-thumbnails' ) );
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<iframe src="http://www.tudou.com/programs/view/html5embed.action?type=1&code=V-TeNdhKVCA&lcode=eNoG-G9OkrQ&resourceId=0_06_05_99" allowtransparency="true" scrolling="no" border="0" frameborder="0" style="width:480px;height:400px;"></iframe>',
|
||||
'expected' => 'http://g3.tdimg.com/83fedbc41cf9055dce9182a0c07da601/w_2.jpg',
|
||||
'expected_hash' => '3a5e656f8c302ae5b23665f22d296ae1',
|
||||
'name' => __( 'iFrame Embed', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Twitch_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'Twitch';
|
||||
const service_name = 'Twitch';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'twitch';
|
||||
const service_slug = 'twitch';
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#(?:www\.)?twitch\.tv/(?:[A-Za-z0-9_]+)/c/([0-9]+)#', // Video URL
|
||||
'#<object[^>]+>.+?http://www\.twitch\.tv/widgets/archive_embed_player\.swf.+?chapter_id=([0-9]+).+?</object>#s', // Flash embed
|
||||
'#<object[^>]+>.+?http://www\.twitch\.tv/swflibs/TwitchPlayer\.swf.+?videoId=c([0-9]+).+?</object>#s', // Newer Flash embed
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
$request = "https://api.twitch.tv/kraken/videos/c$id";
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$result = json_decode( $response['body'] );
|
||||
$result = $result->preview;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => 'http://www.twitch.tv/jodenstone/c/5793313',
|
||||
'expected' => 'http://static-cdn.jtvnw.net/jtv.thumbs/archive-605904705-320x240.jpg',
|
||||
'expected_hash' => '1b2c51fc7380c74d1b2d34751d73e4cb',
|
||||
'name' => __( 'Video URL', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => '<object bgcolor="#000000" data="http://www.twitch.tv/swflibs/TwitchPlayer.swf" height="378" id="clip_embed_player_flash" type="application/x-shockwave-flash" width="620"><param name="movie" value="http://www.twitch.tv/swflibs/TwitchPlayer.swf" /><param name="allowScriptAccess" value="always" /><param name="allowNetworking" value="all" /><param name="allowFullScreen" value="true" /><param name="flashvars" value="channel=jodenstone&auto_play=false&start_volume=25&videoId=c5793313&device_id=bbe9fbac133ab340" /></object>',
|
||||
'expected' => 'http://static-cdn.jtvnw.net/jtv.thumbs/archive-605904705-320x240.jpg',
|
||||
'expected_hash' => '1b2c51fc7380c74d1b2d34751d73e4cb',
|
||||
'name' => __( 'Flash Embed', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
class Video_Thumbnails_Provider {
|
||||
|
||||
public $options = array();
|
||||
|
||||
function __construct() {
|
||||
// If options are defined add the settings section
|
||||
if ( isset( $this->options_section ) ) add_action( 'admin_init', array( &$this, 'initialize_options' ) );
|
||||
// Get current settings for this provider
|
||||
$options = get_option( 'video_thumbnails' );
|
||||
if ( isset( $options['providers'][$this->service_slug] ) ) {
|
||||
$this->options = $options['providers'][$this->service_slug];
|
||||
}
|
||||
}
|
||||
|
||||
function initialize_options() {
|
||||
add_settings_section(
|
||||
$this->service_slug . '_provider_settings_section',
|
||||
$this->service_name . ' Settings',
|
||||
array( &$this, 'settings_section_callback' ),
|
||||
'video_thumbnails_providers'
|
||||
);
|
||||
foreach ( $this->options_section['fields'] as $key => $value ) {
|
||||
add_settings_field(
|
||||
$key,
|
||||
$value['name'],
|
||||
array( &$this, $value['type'] . '_setting_callback' ),
|
||||
'video_thumbnails_providers',
|
||||
$this->service_slug . '_provider_settings_section',
|
||||
array(
|
||||
'slug' => $key,
|
||||
'description' => $value['description']
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function settings_section_callback() {
|
||||
echo $this->options_section['description'];
|
||||
}
|
||||
|
||||
function text_setting_callback( $args ) {
|
||||
$value = ( isset( $this->options[$args['slug']] ) ? $this->options[$args['slug']] : '' );
|
||||
$html = '<input type="text" id="' . $args['slug'] . '" name="video_thumbnails[providers][' . $this->service_slug . '][' . $args['slug'] . ']" value="' . $value . '"/>';
|
||||
$html .= '<label for="' . $args['slug'] . '"> ' . $args['description'] . '</label>';
|
||||
echo $html;
|
||||
}
|
||||
|
||||
public function scan_for_thumbnail( $markup ) {
|
||||
foreach ( $this->regexes as $regex ) {
|
||||
if ( preg_match( $regex, $markup, $matches ) ) {
|
||||
return $this->get_thumbnail_url( $matches[1] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function scan_for_videos( $markup ) {
|
||||
$videos = array();
|
||||
foreach ( $this->regexes as $regex ) {
|
||||
if ( preg_match_all( $regex, $markup, $matches, PREG_OFFSET_CAPTURE ) ) {
|
||||
$videos = array_merge( $videos, $matches[1] );
|
||||
}
|
||||
}
|
||||
return $videos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops the parameters from a thumbnail URL
|
||||
* @param string $url
|
||||
* @return string
|
||||
*/
|
||||
static function drop_url_parameters( $url ) {
|
||||
$url = explode( '?', $url );
|
||||
return $url[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a WP_Error object after failed API retrieval
|
||||
* @param string $request The URL wp_remote_get() failed to retrieve
|
||||
* @param WP_Error $response A WP_Error object returned by the failed wp_remote_get()
|
||||
* @return WP_Error An error object with a descriptive message including troubleshooting instructions
|
||||
*/
|
||||
function construct_info_retrieval_error( $request, $response ) {
|
||||
$code = $this->service_slug . '_info_retrieval';
|
||||
$message = sprintf( __( 'Error retrieving video information from the URL <a href="%1$s">%1$s</a> using <code>wp_remote_get()</code><br />If opening that URL in your web browser returns anything else than an error page, the problem may be related to your web server and might be something your host administrator can solve.', 'video-thumbnails' ), $request ) . '<br />' . __( 'Error Details:', 'video-thumbnails' ) . ' ' . $response->get_error_message();
|
||||
return new WP_Error( $code, $message );
|
||||
}
|
||||
|
||||
// // Requires PHP 5.3.0+
|
||||
// public static function register_provider( $providers ) {
|
||||
// $providers[] = new static;
|
||||
// return $providers;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,677 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Vimeo_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'Vimeo';
|
||||
const service_name = 'Vimeo';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'vimeo';
|
||||
const service_slug = 'vimeo';
|
||||
|
||||
public $options_section = array(
|
||||
'description' => '<p><strong>Optional</strong>: Only required for accessing private videos. <a href="https://developer.vimeo.com/apps">Register an app with Vimeo</a> then fill in the appropriate keys below. Requires cURL to authenticate.</p>',
|
||||
'fields' => array(
|
||||
'client_id' => array(
|
||||
'name' => 'Client ID',
|
||||
'type' => 'text',
|
||||
'description' => ''
|
||||
),
|
||||
'client_secret' => array(
|
||||
'name' => 'Client Secret',
|
||||
'type' => 'text',
|
||||
'description' => ''
|
||||
),
|
||||
'access_token' => array(
|
||||
'name' => 'Access token',
|
||||
'type' => 'text',
|
||||
'description' => ''
|
||||
),
|
||||
'access_token_secret' => array(
|
||||
'name' => 'Access token secret',
|
||||
'type' => 'text',
|
||||
'description' => ''
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#<object[^>]+>.+?http://vimeo\.com/moogaloop.swf\?clip_id=([A-Za-z0-9\-_]+)&.+?</object>#s', // Standard Vimeo embed code
|
||||
'#(?:https?:)?//player\.vimeo\.com/video/([0-9]+)#', // Vimeo iframe player
|
||||
'#\[vimeo id=([A-Za-z0-9\-_]+)]#', // JR_embed shortcode
|
||||
'#\[vimeo clip_id="([A-Za-z0-9\-_]+)"[^>]*]#', // Another shortcode
|
||||
'#\[vimeo video_id="([A-Za-z0-9\-_]+)"[^>]*]#', // Yet another shortcode
|
||||
'#(?:https?://)?(?:www\.)?vimeo\.com/([0-9]+)#', // Vimeo URL
|
||||
'#(?:https?://)?(?:www\.)?vimeo\.com/channels/(?:[A-Za-z0-9]+)/([0-9]+)#' // Channel URL
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
// Get our settings
|
||||
$client_id = ( isset( $this ) && isset( $this->options['client_id'] ) && $this->options['client_id'] != '' ? $this->options['client_id'] : false );
|
||||
$client_secret = ( isset( $this ) && isset( $this->options['client_secret'] ) && $this->options['client_secret'] != '' ? $this->options['client_secret'] : false );
|
||||
$access_token = ( isset( $this ) && isset( $this->options['access_token'] ) && $this->options['access_token'] != '' ? $this->options['access_token'] : false );
|
||||
$access_token_secret = ( isset( $this ) && isset( $this->options['access_token_secret'] ) && $this->options['access_token_secret'] != '' ? $this->options['access_token_secret'] : false );
|
||||
// If API credentials are entered, use the API
|
||||
if ( $client_id && $client_secret && $access_token && $access_token_secret ) {
|
||||
$vimeo = new phpVimeo( $this->options['client_id'], $this->options['client_secret'] );
|
||||
$vimeo->setToken( $this->options['access_token'], $this->options['access_token_secret'] );
|
||||
$response = $vimeo->call('vimeo.videos.getThumbnailUrls', array('video_id'=>$id));
|
||||
$result = $response->thumbnails->thumbnail[count($response->thumbnails->thumbnail)-1]->_content;
|
||||
} else {
|
||||
$request = "http://vimeo.com/api/oembed.json?url=http%3A//vimeo.com/$id";
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} elseif ( $response['response']['code'] == 404 ) {
|
||||
$result = new WP_Error( 'vimeo_info_retrieval', __( 'The Vimeo endpoint located at <a href="' . $request . '">' . $request . '</a> returned a 404 error.<br />Details: ' . $response['response']['message'], 'video-thumbnails' ) );
|
||||
} elseif ( $response['response']['code'] == 403 ) {
|
||||
$result = new WP_Error( 'vimeo_info_retrieval', __( 'The Vimeo endpoint located at <a href="' . $request . '">' . $request . '</a> returned a 403 error.<br />This can occur when a video has embedding disabled or restricted to certain domains. Try entering API credentials in the provider settings.', 'video-thumbnails' ) );
|
||||
} else {
|
||||
$result = json_decode( $response['body'] );
|
||||
$result = $result->thumbnail_url;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<iframe src="http://player.vimeo.com/video/41504360" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
|
||||
'expected' => 'http://i.vimeocdn.com/video/287850781_1280.jpg',
|
||||
'expected_hash' => '5388e0d772b827b0837444b636c9676c',
|
||||
'name' => __( 'iFrame Embed', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => '<object width="500" height="281"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=41504360&force_embed=1&server=vimeo.com&show_title=1&show_byline=1&show_portrait=1&color=00adef&fullscreen=1&autoplay=0&loop=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=41504360&force_embed=1&server=vimeo.com&show_title=1&show_byline=1&show_portrait=1&color=00adef&fullscreen=1&autoplay=0&loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="500" height="281"></embed></object>',
|
||||
'expected' => 'http://i.vimeocdn.com/video/287850781_1280.jpg',
|
||||
'expected_hash' => '5388e0d772b827b0837444b636c9676c',
|
||||
'name' => __( 'Flash Embed', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => 'https://vimeo.com/channels/soundworkscollection/44520894',
|
||||
'expected' => 'http://i.vimeocdn.com/video/502998892_1280.jpg',
|
||||
'expected_hash' => 'fde254d7ef7b6463cbd2451a99f2ddb1',
|
||||
'name' => __( 'Channel URL', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Vimeo API class
|
||||
if( !class_exists( 'phpVimeo' ) ) :
|
||||
class phpVimeo
|
||||
{
|
||||
const API_REST_URL = 'http://vimeo.com/api/rest/v2';
|
||||
const API_AUTH_URL = 'http://vimeo.com/oauth/authorize';
|
||||
const API_ACCESS_TOKEN_URL = 'http://vimeo.com/oauth/access_token';
|
||||
const API_REQUEST_TOKEN_URL = 'http://vimeo.com/oauth/request_token';
|
||||
|
||||
const CACHE_FILE = 'file';
|
||||
|
||||
private $_consumer_key = false;
|
||||
private $_consumer_secret = false;
|
||||
private $_cache_enabled = false;
|
||||
private $_cache_dir = false;
|
||||
private $_token = false;
|
||||
private $_token_secret = false;
|
||||
private $_upload_md5s = array();
|
||||
|
||||
public function __construct($consumer_key, $consumer_secret, $token = null, $token_secret = null)
|
||||
{
|
||||
$this->_consumer_key = $consumer_key;
|
||||
$this->_consumer_secret = $consumer_secret;
|
||||
|
||||
if ($token && $token_secret) {
|
||||
$this->setToken($token, $token_secret);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache a response.
|
||||
*
|
||||
* @param array $params The parameters for the response.
|
||||
* @param string $response The serialized response data.
|
||||
*/
|
||||
private function _cache($params, $response)
|
||||
{
|
||||
// Remove some unique things
|
||||
unset($params['oauth_nonce']);
|
||||
unset($params['oauth_signature']);
|
||||
unset($params['oauth_timestamp']);
|
||||
|
||||
$hash = md5(serialize($params));
|
||||
|
||||
if ($this->_cache_enabled == self::CACHE_FILE) {
|
||||
$file = $this->_cache_dir.'/'.$hash.'.cache';
|
||||
if (file_exists($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
return file_put_contents($file, $response);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the authorization header for a set of params.
|
||||
*
|
||||
* @param array $oauth_params The OAuth parameters for the call.
|
||||
* @return string The OAuth Authorization header.
|
||||
*/
|
||||
private function _generateAuthHeader($oauth_params)
|
||||
{
|
||||
$auth_header = 'Authorization: OAuth realm=""';
|
||||
|
||||
foreach ($oauth_params as $k => $v) {
|
||||
$auth_header .= ','.self::url_encode_rfc3986($k).'="'.self::url_encode_rfc3986($v).'"';
|
||||
}
|
||||
|
||||
return $auth_header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a nonce for the call.
|
||||
*
|
||||
* @return string The nonce
|
||||
*/
|
||||
private function _generateNonce()
|
||||
{
|
||||
return md5(uniqid(microtime()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the OAuth signature.
|
||||
*
|
||||
* @param array $args The full list of args to generate the signature for.
|
||||
* @param string $request_method The request method, either POST or GET.
|
||||
* @param string $url The base URL to use.
|
||||
* @return string The OAuth signature.
|
||||
*/
|
||||
private function _generateSignature($params, $request_method = 'GET', $url = self::API_REST_URL)
|
||||
{
|
||||
uksort($params, 'strcmp');
|
||||
$params = self::url_encode_rfc3986($params);
|
||||
|
||||
// Make the base string
|
||||
$base_parts = array(
|
||||
strtoupper($request_method),
|
||||
$url,
|
||||
urldecode(http_build_query($params, '', '&'))
|
||||
);
|
||||
$base_parts = self::url_encode_rfc3986($base_parts);
|
||||
$base_string = implode('&', $base_parts);
|
||||
|
||||
// Make the key
|
||||
$key_parts = array(
|
||||
$this->_consumer_secret,
|
||||
($this->_token_secret) ? $this->_token_secret : ''
|
||||
);
|
||||
$key_parts = self::url_encode_rfc3986($key_parts);
|
||||
$key = implode('&', $key_parts);
|
||||
|
||||
// Generate signature
|
||||
return base64_encode(hash_hmac('sha1', $base_string, $key, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unserialized contents of the cached request.
|
||||
*
|
||||
* @param array $params The full list of api parameters for the request.
|
||||
*/
|
||||
private function _getCached($params)
|
||||
{
|
||||
// Remove some unique things
|
||||
unset($params['oauth_nonce']);
|
||||
unset($params['oauth_signature']);
|
||||
unset($params['oauth_timestamp']);
|
||||
|
||||
$hash = md5(serialize($params));
|
||||
|
||||
if ($this->_cache_enabled == self::CACHE_FILE) {
|
||||
$file = $this->_cache_dir.'/'.$hash.'.cache';
|
||||
if (file_exists($file)) {
|
||||
return unserialize(file_get_contents($file));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call an API method.
|
||||
*
|
||||
* @param string $method The method to call.
|
||||
* @param array $call_params The parameters to pass to the method.
|
||||
* @param string $request_method The HTTP request method to use.
|
||||
* @param string $url The base URL to use.
|
||||
* @param boolean $cache Whether or not to cache the response.
|
||||
* @param boolean $use_auth_header Use the OAuth Authorization header to pass the OAuth params.
|
||||
* @return string The response from the method call.
|
||||
*/
|
||||
private function _request($method, $call_params = array(), $request_method = 'GET', $url = self::API_REST_URL, $cache = true, $use_auth_header = true)
|
||||
{
|
||||
// Prepare oauth arguments
|
||||
$oauth_params = array(
|
||||
'oauth_consumer_key' => $this->_consumer_key,
|
||||
'oauth_version' => '1.0',
|
||||
'oauth_signature_method' => 'HMAC-SHA1',
|
||||
'oauth_timestamp' => time(),
|
||||
'oauth_nonce' => $this->_generateNonce()
|
||||
);
|
||||
|
||||
// If we have a token, include it
|
||||
if ($this->_token) {
|
||||
$oauth_params['oauth_token'] = $this->_token;
|
||||
}
|
||||
|
||||
// Regular args
|
||||
$api_params = array('format' => 'php');
|
||||
if (!empty($method)) {
|
||||
$api_params['method'] = $method;
|
||||
}
|
||||
|
||||
// Merge args
|
||||
foreach ($call_params as $k => $v) {
|
||||
if (strpos($k, 'oauth_') === 0) {
|
||||
$oauth_params[$k] = $v;
|
||||
}
|
||||
else if ($call_params[$k] !== null) {
|
||||
$api_params[$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate the signature
|
||||
$oauth_params['oauth_signature'] = $this->_generateSignature(array_merge($oauth_params, $api_params), $request_method, $url);
|
||||
|
||||
// Merge all args
|
||||
$all_params = array_merge($oauth_params, $api_params);
|
||||
|
||||
// Returned cached value
|
||||
if ($this->_cache_enabled && ($cache && $response = $this->_getCached($all_params))) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
// Curl options
|
||||
if ($use_auth_header) {
|
||||
$params = $api_params;
|
||||
}
|
||||
else {
|
||||
$params = $all_params;
|
||||
}
|
||||
|
||||
if (strtoupper($request_method) == 'GET') {
|
||||
$curl_url = $url.'?'.http_build_query($params, '', '&');
|
||||
$curl_opts = array(
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_TIMEOUT => 30
|
||||
);
|
||||
}
|
||||
else if (strtoupper($request_method) == 'POST') {
|
||||
$curl_url = $url;
|
||||
$curl_opts = array(
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => http_build_query($params, '', '&')
|
||||
);
|
||||
}
|
||||
|
||||
// Authorization header
|
||||
if ($use_auth_header) {
|
||||
$curl_opts[CURLOPT_HTTPHEADER] = array($this->_generateAuthHeader($oauth_params));
|
||||
}
|
||||
|
||||
// Call the API
|
||||
$curl = curl_init($curl_url);
|
||||
curl_setopt_array($curl, $curl_opts);
|
||||
$response = curl_exec($curl);
|
||||
$curl_info = curl_getinfo($curl);
|
||||
curl_close($curl);
|
||||
|
||||
// Cache the response
|
||||
if ($this->_cache_enabled && $cache) {
|
||||
$this->_cache($all_params, $response);
|
||||
}
|
||||
|
||||
// Return
|
||||
if (!empty($method)) {
|
||||
$response = unserialize($response);
|
||||
if ($response->stat == 'ok') {
|
||||
return $response;
|
||||
}
|
||||
else if ($response->err) {
|
||||
throw new VimeoAPIException($response->err->msg, $response->err->code);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the user to Vimeo to authorize your app.
|
||||
* http://www.vimeo.com/api/docs/oauth
|
||||
*
|
||||
* @param string $perms The level of permissions to request: read, write, or delete.
|
||||
*/
|
||||
public function auth($permission = 'read', $callback_url = 'oob')
|
||||
{
|
||||
$t = $this->getRequestToken($callback_url);
|
||||
$this->setToken($t['oauth_token'], $t['oauth_token_secret'], 'request', true);
|
||||
$url = $this->getAuthorizeUrl($this->_token, $permission);
|
||||
header("Location: {$url}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a method.
|
||||
*
|
||||
* @param string $method The name of the method to call.
|
||||
* @param array $params The parameters to pass to the method.
|
||||
* @param string $request_method The HTTP request method to use.
|
||||
* @param string $url The base URL to use.
|
||||
* @param boolean $cache Whether or not to cache the response.
|
||||
* @return array The response from the API method
|
||||
*/
|
||||
public function call($method, $params = array(), $request_method = 'GET', $url = self::API_REST_URL, $cache = true)
|
||||
{
|
||||
$method = (substr($method, 0, 6) != 'vimeo.') ? "vimeo.{$method}" : $method;
|
||||
return $this->_request($method, $params, $request_method, $url, $cache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the cache.
|
||||
*
|
||||
* @param string $type The type of cache to use (phpVimeo::CACHE_FILE is built in)
|
||||
* @param string $path The path to the cache (the directory for CACHE_FILE)
|
||||
* @param int $expire The amount of time to cache responses (default 10 minutes)
|
||||
*/
|
||||
public function enableCache($type, $path, $expire = 600)
|
||||
{
|
||||
$this->_cache_enabled = $type;
|
||||
if ($this->_cache_enabled == self::CACHE_FILE) {
|
||||
$this->_cache_dir = $path;
|
||||
$files = scandir($this->_cache_dir);
|
||||
foreach ($files as $file) {
|
||||
$last_modified = filemtime($this->_cache_dir.'/'.$file);
|
||||
if (substr($file, -6) == '.cache' && ($last_modified + $expire) < time()) {
|
||||
unlink($this->_cache_dir.'/'.$file);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an access token. Make sure to call setToken() with the
|
||||
* request token before calling this function.
|
||||
*
|
||||
* @param string $verifier The OAuth verifier returned from the authorization page or the user.
|
||||
*/
|
||||
public function getAccessToken($verifier)
|
||||
{
|
||||
$access_token = $this->_request(null, array('oauth_verifier' => $verifier), 'GET', self::API_ACCESS_TOKEN_URL, false, true);
|
||||
parse_str($access_token, $parsed);
|
||||
return $parsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL of the authorization page.
|
||||
*
|
||||
* @param string $token The request token.
|
||||
* @param string $permission The level of permissions to request: read, write, or delete.
|
||||
* @param string $callback_url The URL to redirect the user back to, or oob for the default.
|
||||
* @return string The Authorization URL.
|
||||
*/
|
||||
public function getAuthorizeUrl($token, $permission = 'read')
|
||||
{
|
||||
return self::API_AUTH_URL."?oauth_token={$token}&permission={$permission}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a request token.
|
||||
*/
|
||||
public function getRequestToken($callback_url = 'oob')
|
||||
{
|
||||
$request_token = $this->_request(
|
||||
null,
|
||||
array('oauth_callback' => $callback_url),
|
||||
'GET',
|
||||
self::API_REQUEST_TOKEN_URL,
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
parse_str($request_token, $parsed);
|
||||
return $parsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stored auth token.
|
||||
*
|
||||
* @return array An array with the token and token secret.
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
return array($this->_token, $this->_token_secret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the OAuth token.
|
||||
*
|
||||
* @param string $token The OAuth token
|
||||
* @param string $token_secret The OAuth token secret
|
||||
* @param string $type The type of token, either request or access
|
||||
* @param boolean $session_store Store the token in a session variable
|
||||
* @return boolean true
|
||||
*/
|
||||
public function setToken($token, $token_secret, $type = 'access', $session_store = false)
|
||||
{
|
||||
$this->_token = $token;
|
||||
$this->_token_secret = $token_secret;
|
||||
|
||||
if ($session_store) {
|
||||
$_SESSION["{$type}_token"] = $token;
|
||||
$_SESSION["{$type}_token_secret"] = $token_secret;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload a video in one piece.
|
||||
*
|
||||
* @param string $file_path The full path to the file
|
||||
* @param boolean $use_multiple_chunks Whether or not to split the file up into smaller chunks
|
||||
* @param string $chunk_temp_dir The directory to store the chunks in
|
||||
* @param int $size The size of each chunk in bytes (defaults to 2MB)
|
||||
* @return int The video ID
|
||||
*/
|
||||
public function upload($file_path, $use_multiple_chunks = false, $chunk_temp_dir = '.', $size = 2097152, $replace_id = null)
|
||||
{
|
||||
if (!file_exists($file_path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Figure out the filename and full size
|
||||
$path_parts = pathinfo($file_path);
|
||||
$file_name = $path_parts['basename'];
|
||||
$file_size = filesize($file_path);
|
||||
|
||||
// Make sure we have enough room left in the user's quota
|
||||
$quota = $this->call('vimeo.videos.upload.getQuota');
|
||||
if ($quota->user->upload_space->free < $file_size) {
|
||||
throw new VimeoAPIException('The file is larger than the user\'s remaining quota.', 707);
|
||||
}
|
||||
|
||||
// Get an upload ticket
|
||||
$params = array();
|
||||
|
||||
if ($replace_id) {
|
||||
$params['video_id'] = $replace_id;
|
||||
}
|
||||
|
||||
$rsp = $this->call('vimeo.videos.upload.getTicket', $params, 'GET', self::API_REST_URL, false);
|
||||
$ticket = $rsp->ticket->id;
|
||||
$endpoint = $rsp->ticket->endpoint;
|
||||
|
||||
// Make sure we're allowed to upload this size file
|
||||
if ($file_size > $rsp->ticket->max_file_size) {
|
||||
throw new VimeoAPIException('File exceeds maximum allowed size.', 710);
|
||||
}
|
||||
|
||||
// Split up the file if using multiple pieces
|
||||
$chunks = array();
|
||||
if ($use_multiple_chunks) {
|
||||
if (!is_writeable($chunk_temp_dir)) {
|
||||
throw new Exception('Could not write chunks. Make sure the specified folder has write access.');
|
||||
}
|
||||
|
||||
// Create pieces
|
||||
$number_of_chunks = ceil(filesize($file_path) / $size);
|
||||
for ($i = 0; $i < $number_of_chunks; $i++) {
|
||||
$chunk_file_name = "{$chunk_temp_dir}/{$file_name}.{$i}";
|
||||
|
||||
// Break it up
|
||||
$chunk = file_get_contents($file_path, FILE_BINARY, null, $i * $size, $size);
|
||||
$file = file_put_contents($chunk_file_name, $chunk);
|
||||
|
||||
$chunks[] = array(
|
||||
'file' => realpath($chunk_file_name),
|
||||
'size' => filesize($chunk_file_name)
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$chunks[] = array(
|
||||
'file' => realpath($file_path),
|
||||
'size' => filesize($file_path)
|
||||
);
|
||||
}
|
||||
|
||||
// Upload each piece
|
||||
foreach ($chunks as $i => $chunk) {
|
||||
$params = array(
|
||||
'oauth_consumer_key' => $this->_consumer_key,
|
||||
'oauth_token' => $this->_token,
|
||||
'oauth_signature_method' => 'HMAC-SHA1',
|
||||
'oauth_timestamp' => time(),
|
||||
'oauth_nonce' => $this->_generateNonce(),
|
||||
'oauth_version' => '1.0',
|
||||
'ticket_id' => $ticket,
|
||||
'chunk_id' => $i
|
||||
);
|
||||
|
||||
// Generate the OAuth signature
|
||||
$params = array_merge($params, array(
|
||||
'oauth_signature' => $this->_generateSignature($params, 'POST', self::API_REST_URL),
|
||||
'file_data' => '@'.$chunk['file'] // don't include the file in the signature
|
||||
));
|
||||
|
||||
// Post the file
|
||||
$curl = curl_init($endpoint);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
|
||||
$rsp = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
}
|
||||
|
||||
// Verify
|
||||
$verify = $this->call('vimeo.videos.upload.verifyChunks', array('ticket_id' => $ticket));
|
||||
|
||||
// Make sure our file sizes match up
|
||||
foreach ($verify->ticket->chunks as $chunk_check) {
|
||||
$chunk = $chunks[$chunk_check->id];
|
||||
|
||||
if ($chunk['size'] != $chunk_check->size) {
|
||||
// size incorrect, uh oh
|
||||
echo "Chunk {$chunk_check->id} is actually {$chunk['size']} but uploaded as {$chunk_check->size}<br>";
|
||||
}
|
||||
}
|
||||
|
||||
// Complete the upload
|
||||
$complete = $this->call('vimeo.videos.upload.complete', array(
|
||||
'filename' => $file_name,
|
||||
'ticket_id' => $ticket
|
||||
));
|
||||
|
||||
// Clean up
|
||||
if (count($chunks) > 1) {
|
||||
foreach ($chunks as $chunk) {
|
||||
unlink($chunk['file']);
|
||||
}
|
||||
}
|
||||
|
||||
// Confirmation successful, return video id
|
||||
if ($complete->stat == 'ok') {
|
||||
return $complete->ticket->video_id;
|
||||
}
|
||||
else if ($complete->err) {
|
||||
throw new VimeoAPIException($complete->err->msg, $complete->err->code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload a video in multiple pieces.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function uploadMulti($file_name, $size = 1048576)
|
||||
{
|
||||
// for compatibility with old library
|
||||
return $this->upload($file_name, true, '.', $size);
|
||||
}
|
||||
|
||||
/**
|
||||
* URL encode a parameter or array of parameters.
|
||||
*
|
||||
* @param array/string $input A parameter or set of parameters to encode.
|
||||
*/
|
||||
public static function url_encode_rfc3986($input)
|
||||
{
|
||||
if (is_array($input)) {
|
||||
return array_map(array('phpVimeo', 'url_encode_rfc3986'), $input);
|
||||
}
|
||||
else if (is_scalar($input)) {
|
||||
return str_replace(array('+', '%7E'), array(' ', '~'), rawurlencode($input));
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
if( !class_exists( 'VimeoAPIException' ) ) {
|
||||
class VimeoAPIException extends Exception {}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Vine_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'Vine';
|
||||
const service_name = 'Vine';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'vine';
|
||||
const service_slug = 'vine';
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#(?:www\.)?vine\.co/v/([A-Za-z0-9_]+)#', // URL
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
$request = "https://vine.co/v/$id";
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$doc = new DOMDocument();
|
||||
@$doc->loadHTML( $response['body'] );
|
||||
$metas = $doc->getElementsByTagName( 'meta' );
|
||||
for ( $i = 0; $i < $metas->length; $i++ ) {
|
||||
$meta = $metas->item( $i );
|
||||
if ( $meta->getAttribute( 'property' ) == 'og:image' ) {
|
||||
$result = $meta->getAttribute( 'content' );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<iframe class="vine-embed" src="https://vine.co/v/bpj7Km0T3d5/embed/simple" width="600" height="600" frameborder="0"></iframe><script async src="//platform.vine.co/static/scripts/embed.js" charset="utf-8"></script>',
|
||||
'expected' => 'https://v.cdn.vine.co/v/thumbs/D6DDE013-F8DA-4929-9BED-49568F424343-184-00000008A20C1AEC_1.0.6.mp4.jpg',
|
||||
'expected_hash' => '7cca5921108abe15b8c1c1f884a5b3ac',
|
||||
'name' => __( 'iFrame Embed/Video URL', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Vk_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'VK';
|
||||
const service_name = 'VK';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'vk';
|
||||
const service_slug = 'vk';
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#(//(?:www\.)?vk\.com/video_ext\.php\?oid=\-?[0-9]+(?:&|&\#038;|&)id=\-?[0-9]+(?:&|&\#038;|&)hash=[0-9a-zA-Z]+)#', // URL
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
$request = "http:$id";
|
||||
$request = html_entity_decode( $request );
|
||||
$response = wp_remote_get( $request );
|
||||
$result = false;
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$doc = new DOMDocument();
|
||||
@$doc->loadHTML( $response['body'] );
|
||||
$metas = $doc->getElementsByTagName( 'img' );
|
||||
for ( $i = 0; $i < $metas->length; $i++ ) {
|
||||
$meta = $metas->item( $i );
|
||||
if ( $meta->getAttribute( 'id' ) == 'player_thumb' ) {
|
||||
$result = $meta->getAttribute( 'src' );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<iframe src="http://vk.com/video_ext.php?oid=220943440&id=168591360&hash=75a37bd3930f4fab&hd=1" width="607" height="360" frameborder="0"></iframe>',
|
||||
'expected' => 'http://cs540302.vk.me/u220943440/video/l_afc9770f.jpg',
|
||||
'expected_hash' => 'fd8c2af4ad5cd4e55afe129d80b42d8b',
|
||||
'name' => __( 'iFrame Embed', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Wistia_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'Wistia';
|
||||
const service_name = 'Wistia';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'wistia';
|
||||
const service_slug = 'wistia';
|
||||
|
||||
// public $options_section = array(
|
||||
// 'description' => '<p><strong>Optional</strong>: Only required if you have a CNAME record set up to use a custom domain.</p>',
|
||||
// 'fields' => array(
|
||||
// 'domain' => array(
|
||||
// 'name' => 'Custom Wistia Domain',
|
||||
// 'type' => 'text',
|
||||
// 'description' => 'Enter the domain corresponding to your CNAME record for Wistia. Ex: videos.example.com'
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#Wistia\.embed\("([0-9a-zA-Z]+)"#', // JavaScript API embedding
|
||||
'#(https?://(?:.+)?(?:wistia\.com|wistia\.net|wi\.st)/(?:medias|embed)/(?:[\+~%\/\.\w\-]*))#', // Embed URL
|
||||
'#(https://wistia\.sslcs\.cdngc\.net/deliveries/[0-9a-zA-Z]+\.jpg)#' // Thumbnail image
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
|
||||
// ID is an image URL, return it
|
||||
if ( substr( $id, -4 ) == '.jpg' ) return $id;
|
||||
|
||||
// ID is actually an ID, convert it to a URL
|
||||
if ( substr( $id, 0, 4 ) != 'http' ) $id = 'http://fast.wistia.net/embed/iframe/' . $id;
|
||||
|
||||
// ID should now be an embed URL, use oEmbed to find thumbnail URL
|
||||
$id = urlencode( $id );
|
||||
$request = "http://fast.wistia.com/oembed?url=$id";
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$result = json_decode( $response['body'] );
|
||||
$result = $this->drop_url_parameters( $result->thumbnail_url );
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<iframe src="http://fast.wistia.net/embed/iframe/po4utu3zde?controlsVisibleOnLoad=true&version=v1&videoHeight=360&videoWidth=640&volumeControl=true" allowtransparency="true" frameborder="0" scrolling="no" class="wistia_embed" name="wistia_embed" width="640" height="360"></iframe>',
|
||||
'expected' => 'https://embed-ssl.wistia.com/deliveries/6928fcba8355e38de4d95863a659e1de23cb2071.jpg',
|
||||
'expected_hash' => 'bc4a2cec9ac97e2ccdae2c7387a01cb4',
|
||||
'name' => __( 'iFrame Embed', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => '<div class=\'wistia_embed\' data-video-height=\'312\' data-video-width=\'499\' id=\'wistia_j1qd2lvys1\'></div> <script charset=\'ISO-8859-1\' src=\'http://fast.wistia.com/static/concat/E-v1.js\'></script> <script> var platform = ( Modernizr.touch ) ? "html5" : "flash"; wistiaEmbed = Wistia.embed("j1qd2lvys1", { version: "v1", videoWidth: 499, videoHeight: 312, playButton: Modernizr.touch, smallPlayButton: Modernizr.touch, playbar: Modernizr.touch, platformPreference: platform, chromeless: Modernizr.touch ? false : true, fullscreenButton: false, autoPlay: !Modernizr.touch, videoFoam: true }); </script>',
|
||||
'expected' => 'https://embed-ssl.wistia.com/deliveries/a086707fe096e7f3fbefef1d1dcba1488d23a3e9.jpg',
|
||||
'expected_hash' => '4c63d131604bfc07b5178413ab245813',
|
||||
'name' => __( 'JavaScript Embed', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2015 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Yahooscreen_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'Yahoo Screen';
|
||||
const service_name = 'Yahoo Screen';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'yahooscreen';
|
||||
const service_slug = 'yahooscreen';
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#(\/\/screen\.yahoo\.com\/[^.]+\.html)#' // iFrame SRC
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $url ) {
|
||||
$request = "http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20html%20WHERE%20url%3D%22" . urlencode( 'http:' . $url ) . "%22%20AND%20xpath%3D%22%2F%2Fmeta%5B%40property%3D'og%3Aimage'%5D%22%20and%20compat%3D%22html5%22&format=json&callback=";
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$json = json_decode( $response['body'] );
|
||||
if ( empty( $json->query->results ) ) {
|
||||
$result = new WP_Error( 'yahooscreen_invalid_url', sprintf( __( 'Error retrieving video information for <a href="http:%1$s">http:%1$s</a>. Check to be sure this is a valid Yahoo Screen URL.', 'video-thumbnails' ), $url ) );
|
||||
} else {
|
||||
$result = $json->query->results->meta->content;
|
||||
$result_array = explode( 'http://', $result );
|
||||
if ( count( $result_array ) > 1 ) {
|
||||
$result = 'http://' . $result_array[count( $result_array )-1];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<iframe width="640" height="360" scrolling="no" frameborder="0" src="https://screen.yahoo.com/first-u-bitcoin-exchange-opens-140857495.html?format=embed" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" allowtransparency="true"></iframe>',
|
||||
'expected' => 'http://media.zenfs.com/en-US/video/video.abcnewsplus.com/7c70071008e3711818517f19b6ad9629',
|
||||
'expected_hash' => '22c2b172b297cf09511d832ddab7b9f5',
|
||||
'name' => __( 'iFrame Embed', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Youku_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'Youku';
|
||||
const service_name = 'Youku';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'youku';
|
||||
const service_slug = 'youku';
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#http://player\.youku\.com/embed/([A-Za-z0-9]+)#', // iFrame
|
||||
'#http://player\.youku\.com/player\.php/sid/([A-Za-z0-9]+)/v\.swf#', // Flash
|
||||
'#http://v\.youku\.com/v_show/id_([A-Za-z0-9]+)\.html#' // Link
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
$request = "http://v.youku.com/player/getPlayList/VideoIDS/$id/";
|
||||
$response = wp_remote_get( $request );
|
||||
if( is_wp_error( $response ) ) {
|
||||
$result = $this->construct_info_retrieval_error( $request, $response );
|
||||
} else {
|
||||
$result = json_decode( $response['body'] );
|
||||
$result = $result->data[0]->logo;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<iframe height=498 width=510 src="http://player.youku.com/embed/XMzQyMzk5MzQ4" frameborder=0 allowfullscreen></iframe>',
|
||||
'expected' => 'http://g1.ykimg.com/1100641F464F0FB57407E2053DFCBC802FBBC4-E4C5-7A58-0394-26C366F10493',
|
||||
'expected_hash' => 'deac7bb89058a8c46ae2350da9d33ba8',
|
||||
'name' => __( 'iFrame Embed', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => '<embed src="http://player.youku.com/player.php/sid/XMzQyMzk5MzQ4/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="sameDomain" allowFullscreen="true" type="application/x-shockwave-flash"></embed>',
|
||||
'expected' => 'http://g1.ykimg.com/1100641F464F0FB57407E2053DFCBC802FBBC4-E4C5-7A58-0394-26C366F10493',
|
||||
'expected_hash' => 'deac7bb89058a8c46ae2350da9d33ba8',
|
||||
'name' => __( 'Flash Embed', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => 'http://v.youku.com/v_show/id_XMzQyMzk5MzQ4.html',
|
||||
'expected' => 'http://g1.ykimg.com/1100641F464F0FB57407E2053DFCBC802FBBC4-E4C5-7A58-0394-26C366F10493',
|
||||
'expected_hash' => 'deac7bb89058a8c46ae2350da9d33ba8',
|
||||
'name' => __( 'Video URL', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Require thumbnail provider class
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-provider.php' );
|
||||
|
||||
class Youtube_Thumbnails extends Video_Thumbnails_Provider {
|
||||
|
||||
// Human-readable name of the video provider
|
||||
public $service_name = 'YouTube';
|
||||
const service_name = 'YouTube';
|
||||
// Slug for the video provider
|
||||
public $service_slug = 'youtube';
|
||||
const service_slug = 'youtube';
|
||||
|
||||
public static function register_provider( $providers ) {
|
||||
$providers[self::service_slug] = new self;
|
||||
return $providers;
|
||||
}
|
||||
|
||||
// Regex strings
|
||||
public $regexes = array(
|
||||
'#(?:https?:)?//www\.youtube(?:\-nocookie)?\.com/(?:v|e|embed)/([A-Za-z0-9\-_]+)#', // Comprehensive search for both iFrame and old school embeds
|
||||
'#(?:https?(?:a|vh?)?://)?(?:www\.)?youtube(?:\-nocookie)?\.com/watch\?.*v=([A-Za-z0-9\-_]+)#', // Any YouTube URL. After http(s) support a or v for Youtube Lyte and v or vh for Smart Youtube plugin
|
||||
'#(?:https?(?:a|vh?)?://)?youtu\.be/([A-Za-z0-9\-_]+)#', // Any shortened youtu.be URL. After http(s) a or v for Youtube Lyte and v or vh for Smart Youtube plugin
|
||||
'#<div class="lyte" id="([A-Za-z0-9\-_]+)"#', // YouTube Lyte
|
||||
'#data-youtube-id="([A-Za-z0-9\-_]+)"#' // LazyYT.js
|
||||
);
|
||||
|
||||
// Thumbnail URL
|
||||
public function get_thumbnail_url( $id ) {
|
||||
$maxres = 'http://img.youtube.com/vi/' . $id . '/maxresdefault.jpg';
|
||||
$response = wp_remote_head( $maxres );
|
||||
if ( !is_wp_error( $response ) && $response['response']['code'] == '200' ) {
|
||||
$result = $maxres;
|
||||
} else {
|
||||
$result = 'http://img.youtube.com/vi/' . $id . '/0.jpg';
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Test cases
|
||||
public static function get_test_cases() {
|
||||
return array(
|
||||
array(
|
||||
'markup' => '<iframe width="560" height="315" src="http://www.youtube.com/embed/Fp0U2Vglkjw" frameborder="0" allowfullscreen></iframe>',
|
||||
'expected' => 'http://img.youtube.com/vi/Fp0U2Vglkjw/maxresdefault.jpg',
|
||||
'expected_hash' => 'c66256332969c38790c2b9f26f725e7a',
|
||||
'name' => __( 'iFrame Embed HD', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => '<object width="560" height="315"><param name="movie" value="http://www.youtube.com/v/Fp0U2Vglkjw?version=3&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Fp0U2Vglkjw?version=3&hl=en_US" type="application/x-shockwave-flash" width="560" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object>',
|
||||
'expected' => 'http://img.youtube.com/vi/Fp0U2Vglkjw/maxresdefault.jpg',
|
||||
'expected_hash' => 'c66256332969c38790c2b9f26f725e7a',
|
||||
'name' => __( 'Flash Embed HD', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => '<iframe width="560" height="315" src="http://www.youtube.com/embed/vv_AitYPjtc" frameborder="0" allowfullscreen></iframe>',
|
||||
'expected' => 'http://img.youtube.com/vi/vv_AitYPjtc/0.jpg',
|
||||
'expected_hash' => '6c00b9ab335a6ea00b0fb964c39a6dc9',
|
||||
'name' => __( 'iFrame Embed SD', 'video-thumbnails' )
|
||||
),
|
||||
array(
|
||||
'markup' => '<object width="560" height="315"><param name="movie" value="http://www.youtube.com/v/vv_AitYPjtc?version=3&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/vv_AitYPjtc?version=3&hl=en_US" type="application/x-shockwave-flash" width="560" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object>',
|
||||
'expected' => 'http://img.youtube.com/vi/vv_AitYPjtc/0.jpg',
|
||||
'expected_hash' => '6c00b9ab335a6ea00b0fb964c39a6dc9',
|
||||
'name' => __( 'Flash Embed SD', 'video-thumbnails' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/* Copyright 2014 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Include provider classes
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-youtube-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-vimeo-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-facebook-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-vine-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-blip-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-dailymotion-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-metacafe-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-vk-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-funnyordie-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-mpora-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-wistia-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-youku-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-tudou-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-collegehumor-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-rutube-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-sapo-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-ted-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-twitch-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-googledrive-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-yahooscreen-thumbnails.php' );
|
||||
require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-livestream-thumbnails.php' );
|
||||
// require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-kaltura-thumbnails.php' );
|
||||
|
||||
// Register providers
|
||||
add_filter( 'video_thumbnail_providers', array( 'Youtube_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Vimeo_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Facebook_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Vine_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Blip_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Dailymotion_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Metacafe_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Vk_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Funnyordie_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Mpora_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Wistia_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Youku_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Tudou_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Collegehumor_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Rutube_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Sapo_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Ted_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Twitch_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Googledrive_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Yahooscreen_Thumbnails', 'register_provider' ) );
|
||||
add_filter( 'video_thumbnail_providers', array( 'Livestream_Thumbnails', 'register_provider' ) );
|
||||
// add_filter( 'video_thumbnail_providers', array( 'Kaltura_Thumbnails', 'register_provider' ) );
|
||||
|
||||
?>
|
Reference in New Issue
Block a user