Skip to content

Instantly share code, notes, and snippets.

@anointed
Created May 24, 2013 20:13
Show Gist options
  • Save anointed/5646201 to your computer and use it in GitHub Desktop.
Save anointed/5646201 to your computer and use it in GitHub Desktop.
evs class for video thumbnails
<?php
/* Copyright 2013 Marc Fowler (email : [email protected])
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-providers.php' );
class EasyVideoSuite_Thumbnails extends Video_Thumbnails_Providers {
// Human-readable name of the video provider
public $service_name = 'EasyVideoSuite';
const service_name = 'EasyVideoSuite';
// Slug for the video provider
public $service_slug = 'easyvideosuite';
const service_slug = 'easyvideosuite';
public static function register_provider( $providers ) {
$providers[self::service_slug] = new self;
return $providers;
}
// Regex strings
public $regexes = array(
'#/evs/player/([A-Za-z0-9\=]+)/#',
'#evsuite.com/player/([A-Za-z0-9\=]+)/#',
'#<img class="wpevs-container" style="[A-Za-z0-9\;\:\s]+" alt="([A-Za-z0-9\=\+]+)"#',
'#<img class="wpevs-container" alt="([A-Za-z0-9\=\+]+)"#',
'#<img class="wpevs-container" alt="([A-Za-z0-9\=\+]+)" src=".+"#',
'#<img class="wpevs-container" src=".+" style="[A-Za-z0-9\;\:\s]+" alt="([A-Za-z0-9\=\+]+)"#',
);
// Thumbnail URL
public function get_thumbnail_url( $argument ) {
$evs_location = get_option('evs_location');
$code = base64_decode($argument);
preg_match('#'.$evs_location.'/player/([A-Za-z0-9\=]+)/#', $code, $id);
//file_put_contents('videothumboembed.txt', print_r(array('results' => $id, 'exp' => '#'.$evs_location.'/player/([A-Za-z0-9\=]+)/#', 'code' => $code), true));
if(!empty($id[1])) {
$id = $id[1];
} else { // Maybe the first argument was just an ID? (i.e. from the Standard JS embed)
$id = $argument;
}
$result = '';
// Request the oEmbed info
$oembed = wp_remote_get($evs_location.'/oembed.php?file_ref='.urlencode($id));
if(!empty($oembed) && !empty($oembed['body'])) {
$oembed_obj = json_decode($oembed['body']);
if(!empty($oembed_obj)) {
$result = $oembed_obj->thumbnail_url;
}
}
return $result;
}
// Test cases
public $test_cases = array(
array(
'markup' => '<script type="text/javascript" src="http://dfr.evsuite.com/player/SW1wb3J0aW5nLWZyb20tYW55d2hlcmUubXA0/?container=evp-Y5RJS5EG46"></script><div id="evp-Y5RJS5EG46" data-role="evp-video" data-evp-id="SW1wb3J0aW5nLWZyb20tYW55d2hlcmUubXA0"></div>',
'expected' => 'http://evs-hosted-14fa4000e524cb.s3.amazonaws.com/Importing-from-anywhere-thumbnail-0.jpg',
'name' => 'Standard JavaScript'
),
array(
'markup' => '<img class="wpevs-container" src="http://dfr.bounceme.net/apps/wordpress/wp-content/plugins/wp-evs/images/placeholder.png?v=1" style="display: block; width: 400px; height: 200px;" alt="PHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFzY3JpcHQiIHNyYz0iaHR0cDovL2Rmci5ldnN1aXRlLmNvbS9wbGF5ZXIvU1cxd2IzSjBhVzVuTFdaeWIyMHRZVzU1ZDJobGNtVXViWEEwLz9jb250YWluZXI9ZXZwLVk1UkpTNUVHNDYiPjwvc2NyaXB0PjxkaXYgaWQ9ImV2cC1ZNVJKUzVFRzQ2IiBkYXRhLXJvbGU9ImV2cC12aWRlbyIgZGF0YS1ldnAtaWQ9IlNXMXdiM0owYVc1bkxXWnliMjB0WVc1NWQyaGxjbVV1YlhBMCI+PC9kaXY+" />',
'expected' => 'http://evs-hosted-14fa4000e524cb.s3.amazonaws.com/Importing-from-anywhere-thumbnail-0.jpg',
'name' => 'WP EVS Embed'
)
);
}
$evs_location = get_option('evs_location');
if(!empty($evs_location)) { // Add to provider array
add_filter( 'video_thumbnail_providers', array( 'EasyVideoSuite_Thumbnails', 'register_provider' ) );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment