Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add another CDN for FV Player Pro with custom URL token generator
<?php
/*
Plugin Name: FV Player Pro - Custom CDN
Description: Add Settings -> FV Player Pro -> Hosting -> BunnyCDN Extended which signs the URLs for use in SK and US countries only.
Author: Foliovision
Version: 0.1
*/
add_action( 'plugins_loaded', 'fv_player_custom_cdn_load', 0 );
function fv_player_custom_cdn_load() {
if( class_exists('FV_Player_Pro_Ajax_Loader') ) {
class FV_Player_Pro_BunnyCDN_Extended extends FV_Player_Pro_Ajax_Loader {
function __construct() {
parent::__construct( array( 'key' => 'bunnycdn_extended', 'title' => 'BunnyCDN Extended') );
}
function args($args) {
$args[] = 'token';
return $args;
}
function secure_link( $url, $securityKey, $ttl = false ) {
$parsed = parse_url( $url );
$expires = time() + ( $ttl ? $ttl : apply_filters('fv_player_secure_link_timeout', 900) );
$hashableBase = $securityKey.urldecode($parsed['path']).$expires.'token_countries=SK,US';
$token = hash('sha256', $hashableBase, true);
$token = base64_encode($token);
$token = strtr($token, '+/', '-_');
$token = str_replace('=', '', $token);
$url = add_query_arg( 'token', $token, $url);
$url = add_query_arg( 'expires', $expires, $url);
$url = add_query_arg( 'token_countries', 'SK,US', $url);
return $url;
}
}
new FV_Player_Pro_BunnyCDN_Extended;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment