Skip to content

Commit

Permalink
Deploying version 2.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmjones committed Dec 14, 2020
1 parent 991694a commit 65d1b99
Show file tree
Hide file tree
Showing 553 changed files with 17,281 additions and 12,252 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
**Requires at least:** 4.9
**Tested up to:** 5.6
**Requires PHP:** 5.5
**Stable tag:** 2.5.1
**Stable tag:** 2.6dev
**License:** GPLv3

Copies files to Amazon S3, DigitalOcean Spaces or Google Cloud Storage as they are uploaded to the Media Library. Optionally configure Amazon CloudFront or another CDN for faster delivery.
Expand Down
86 changes: 86 additions & 0 deletions classes/as3cf-filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,92 @@ protected function get_custom_css_post_id( $stylesheet ) {
return $post->ID;
}

/**
* Get an array of bare base_urls that can be used for uploaded items.
*
* @param bool $refresh Refresh cached domains, default false.
*
* @return array
*/
public function get_bare_upload_base_urls( $refresh = false ) {
static $base_urls = array();

if ( $refresh || empty( $base_urls ) ) {
$domains = array();

// Original domain and path.
$uploads = wp_upload_dir();
$base_url = AS3CF_Utils::remove_scheme( $uploads['baseurl'] );
$orig_domain = AS3CF_Utils::parse_url( $base_url, PHP_URL_HOST );
$domains[] = $orig_domain;
$base_urls[] = $base_url;

// Current domain and path after potential domain mapping.
$base_url = $this->as3cf->maybe_fix_local_subsite_url( $uploads['baseurl'] );
$base_url = AS3CF_Utils::remove_scheme( $base_url );
$curr_domain = AS3CF_Utils::parse_url( $base_url, PHP_URL_HOST );

if ( $curr_domain !== $orig_domain ) {
$domains[] = $curr_domain;
}

/**
* Allow alteration of the local domains that can be matched on.
*
* @param array $domains
*/
$domains = apply_filters( 'as3cf_local_domains', $domains );

if ( ! empty( $domains ) ) {
foreach ( array_unique( $domains ) as $match_domain ) {
$base_urls[] = substr_replace( $base_url, $match_domain, 2, strlen( $curr_domain ) );
}
}
}

return array_unique( $base_urls );
}

/**
* Get an array of domain names that can be used for remote items.
*
* @param bool $refresh Refresh cached domains, default false.
*
* @return array
*/
public function get_remote_domains( $refresh = false ) {
static $domains = array();

if ( $refresh || empty( $domains ) ) {
// Storage Provider's default domain.
$domains = array(
$this->as3cf->get_storage_provider()->get_domain(),
);

// Delivery Provider's default domain.
$delivery_provider = $this->as3cf->get_delivery_provider();
$domains[] = $delivery_provider->get_domain();

// Delivery Provider's custom domain.
if ( $delivery_provider->delivery_domain_allowed() && $this->as3cf->get_setting( 'enable-delivery-domain' ) ) {
$delivery_domain = $this->as3cf->get_setting( 'delivery-domain' );

if ( ! empty( $delivery_domain ) ) {
$domains[] = trim( $delivery_domain );
}
}

/**
* Allow alteration of the remote domains that can be matched on.
*
* @param array $domains
*/
$domains = array_unique( apply_filters( 'as3cf_remote_domains', $domains ) );
}

return $domains;
}

/**
* Does URL need replacing?
*
Expand Down
50 changes: 3 additions & 47 deletions classes/filters/as3cf-local-to-s3.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function filter_widget_display( $instance, $class ) {
*
* @return bool
*/
protected function url_needs_replacing( $url ) {
public function url_needs_replacing( $url ) {
if ( str_replace( $this->get_bare_upload_base_urls(), '', $url ) === $url ) {
// Remote URL, no replacement needed
return false;
Expand All @@ -128,50 +128,6 @@ protected function url_needs_replacing( $url ) {
return true;
}

/**
* Get an array of bare base_urls that can be used for uploaded items.
*
* @return array
*/
private function get_bare_upload_base_urls() {
static $base_urls = array();

if ( empty( $base_urls ) ) {
$domains = array();

// Original domain and path.
$uploads = wp_upload_dir();
$base_url = AS3CF_Utils::remove_scheme( $uploads['baseurl'] );
$orig_domain = AS3CF_Utils::parse_url( $base_url, PHP_URL_HOST );
$domains[] = $orig_domain;
$base_urls[] = $base_url;

// Current domain and path after potential domain mapping.
$base_url = $this->as3cf->maybe_fix_local_subsite_url( $uploads['baseurl'] );
$base_url = AS3CF_Utils::remove_scheme( $base_url );
$curr_domain = AS3CF_Utils::parse_url( $base_url, PHP_URL_HOST );

if ( $curr_domain !== $orig_domain ) {
$domains[] = $curr_domain;
}

/**
* Allow alteration of the local domains that can be matched on.
*
* @param array $domains
*/
$domains = apply_filters( 'as3cf_local_domains', $domains );

if ( ! empty( $domains ) ) {
foreach ( array_unique( $domains ) as $match_domain ) {
$base_urls[] = substr_replace( $base_url, $match_domain, 2, strlen( $curr_domain ) );
}
}
}

return $base_urls;
}

/**
* Get URL
*
Expand Down Expand Up @@ -387,10 +343,10 @@ protected function url_replaced( $find, $replace, $content ) {
*/
public function set_url_scheme( $url, $scheme, $orig_scheme ) {
if (
'http' === $scheme && empty( $orig_scheme ) &&
$this->as3cf->get_setting( 'force-https' ) &&
$this->should_filter_content() &&
! $this->url_needs_replacing( $url ) &&
'http' === $scheme && empty( $orig_scheme )
! $this->url_needs_replacing( $url )
) {
// Check that it's one of ours and not external.
$parts = AS3CF_Utils::parse_url( $url );
Expand Down
12 changes: 7 additions & 5 deletions classes/filters/as3cf-s3-to-local.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ protected function should_filter_content() {
*
* @return bool
*/
protected function url_needs_replacing( $url ) {
$uploads = wp_upload_dir();
$base_url = AS3CF_Utils::remove_scheme( $uploads['baseurl'] );
public function url_needs_replacing( $url ) {
if ( str_replace( $this->get_bare_upload_base_urls(), '', $url ) !== $url ) {
// Local URL, no replacement needed.
return false;
}

if ( false !== strpos( $url, $base_url ) ) {
// Local URL, no replacement needed
if ( str_replace( $this->get_remote_domains(), '', $url ) === $url ) {
// Not a known remote URL, no replacement needed.
return false;
}

Expand Down
Loading

0 comments on commit 65d1b99

Please sign in to comment.