Created
May 5, 2021 21:06
-
-
Save foliovision/d60446dbb207b10bbbc20ecf49dfbbec to your computer and use it in GitHub Desktop.
Add another CDN for FV Player Pro with custom URL token generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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