Skip to content

Commit 4151aaf

Browse files
committed
Cleaner handling of media domains.
1 parent c932454 commit 4151aaf

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ A fork from the official Cloudflare Stream plugin 1.0.5 for WordPress. This fork
55
* Take full advantage of Cloudflare Stream's security features.
66
* Uses signed URL's / tokens, so video access can be strictly controlled and limited.
77
* Uses a limited access API token for API access, eliminating the use of the global API key which presents a huge security risk.
8+
* Incorporate additional features and new features as they're made available.
89

910
The Gutenberg Block method of adding videos appears to be broken (in the original plugin also). I've only left code related to the Gutenberg Block in this fork, so as to not break existing content should you switch from the official plugin. Adding new block content will fail as the global API key it's expecting to use is no longer stored in this plugin. Note the Gutenberg Block as it currently exists, does not support signed URL's / tokens.
1011

@@ -57,16 +58,16 @@ The admin area has been completely revised from the official plugin. Instead of
5758
![admin-settings](https://user-images.githubusercontent.com/16984998/188538819-ac0b9905-7d62-4118-81ff-d92a78ba7ea7.png)
5859

5960

61+
### API Account ID ###
62+
* **Cloudflare** > [domain] > **Overview** > [scroll down to API section on the right and copy the Account ID].
63+
6064
### API Token ###
6165
An API token must be created in your Cloudflare dashboard, for this plugin. For security sake, the token should only be used for this plugin and provide only the permissions necesarry for the plugin to work. I'd recommend setting up Client IP Address Filtering when creating the token too. Where feasible, restrict access to only the IP addresses that need it (eg: your webserver's IP where WordPress is installed).
6266
* **Cloudflare** > **My Profile** > **API Tokens** > **API Tokens** > [Create Token]
6367
Must have permission for: **Account - Stream:Edit**
6468

65-
### API Account ID ###
66-
* **Cloudflare** > [domain] > **Overview** > [scroll down to API section on the right and copy the Account ID].
67-
6869
### Use Signed URLs ###
69-
When this is checked [x], videos are accessed using a temporary time-limited token, aka signed URL. This alone does not secure your content however. Please see **Securing Video Access** below for further details on how to do that.
70+
When this is checked [x], videos are accessed using a temporary time-limited token, aka signed URL. This alone does not secure your content however. Please see **[Securing Video Access](#securing-video-access)** below for further details on how to do that.
7071

7172
### Signed URL Expiration ###
7273
When **Use Signed URLs** is checked [x], this setting controls how long any particular token / signed ULR is valid for **in minutes**. The Cloudflare default, is 60 minutes. Generally, you'd want to make sure this is larger than your longest video.

src/inc/class-cloudflare-stream-api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public function get_video_embed( $uid, $args = array(), $return_headers = false
255255
$standard_uri = ' src="https://iframe.' . $media_domain . '/' . $uid . '?';
256256
$account_subdomain_uri = ' src="https://' . $media_domain . '/' . $uid . '/iframe?';
257257

258-
$src_uri = ( $media_domain == "cloudflarestream.com" || $media_domain == "videodelivery.net" ) ? $standard_uri : $account_subdomain_uri;
258+
$src_uri = ( in_array( $media_domain, Cloudflare_Stream_Settings::STANDARD_MEDIA_DOMAINS ) ) ? $standard_uri : $account_subdomain_uri;
259259

260260
$video_embed = '<div style="position: relative; padding-top: 56.25%"><iframe'
261261
. $src_uri

src/inc/class-cloudflare-stream-settings.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Cloudflare_Stream_Settings {
3333
const OPTION_SIGNED_URLS = 'cloudflare_stream_signed_urls';
3434
const OPTION_SIGNED_URLS_DURATION = 'cloudflare_stream_signed_urls_duration';
3535
const OPTION_MEDIA_DOMAIN = 'cloudflare_stream_media_domain';
36+
const STANDARD_MEDIA_DOMAINS = [ 'cloudflarestream.com', 'videodelivery.net' ];
3637

3738
/**
3839
* Singleton
@@ -176,8 +177,11 @@ public function api_signed_urls_duration_cb() {
176177
*/
177178
public function media_domain_cb() {
178179
$media_domain = get_option( self::OPTION_MEDIA_DOMAIN );
179-
echo '<label for="cloudflare_stream_media_domain_0"><input type="radio" class="radio-option" name="cloudflare_stream_media_domain" id="cloudflare_stream_media_domain_0" value="cloudflarestream.com" ' . checked( "cloudflarestream.com", $media_domain, false ) . ' >cloudflarestream.com (default)</label>'
180-
. '<label for="cloudflare_stream_media_domain_"><input type="radio" class="radio-option" name="cloudflare_stream_media_domain" id="cloudflare_stream_media_domain_1" value="videodelivery.net" ' . checked( "videodelivery.net", $media_domain, false ) . ' >videodelivery.net</label>';
180+
181+
for ( $i = 0; $i < count( self::STANDARD_MEDIA_DOMAINS ); $i++ ) {
182+
$default = !$i ? ' (default)' : '';
183+
echo '<label for="cloudflare_stream_media_domain_' . $i . '"><input type="radio" class="radio-option" name="cloudflare_stream_media_domain" id="cloudflare_stream_media_domain_' . $i . '" value="' . self::STANDARD_MEDIA_DOMAINS[$i] . '" ' . checked( self::STANDARD_MEDIA_DOMAINS[$i], $media_domain, false ) . ' >' . self::STANDARD_MEDIA_DOMAINS[$i] . $default . '</label>';
184+
}
181185

182186
// The account subdomain option is only presented if it was able to be retrieved from the API.
183187
$account_subdomain = self::get_account_subdomain();

0 commit comments

Comments
 (0)