Skip to content

Commit

Permalink
Deploying version 1.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
A5hleyRich committed Dec 13, 2016
1 parent dea7735 commit dee44bb
Show file tree
Hide file tree
Showing 22 changed files with 500 additions and 289 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
**Contributors:** bradt, deliciousbrains
**Tags:** uploads, amazon, s3, amazon s3, mirror, admin, media, cdn, cloudfront
**Requires at least:** 4.4
**Tested up to:** 4.6.1
**Stable tag:** 1.1.3
**Tested up to:** 4.7
**Stable tag:** 1.1.4
**License:** GPLv3

Copies files to Amazon S3 as they are uploaded to the Media Library. Optionally configure Amazon CloudFront for faster delivery.
Expand Down Expand Up @@ -69,6 +69,12 @@ This version requires PHP 5.3.3+ and the Amazon Web Services plugin

## Changelog ##

### WP Offload S3 Lite 1.1.4 - 2016-12-13 ###
* New: Upgrade routine to replace all S3 URLs in post excerpts with local URLs
* Improvement: Performance improvements
* Improvement: Allow expires time to be filtered for private content using the `as3cf_expires` filter
* Bug fix: Image `srcset` not correctly applied when file names contain special characters

### WP Offload S3 Lite 1.1.3 - 2016-11-28 ###
* Bug fix: Private URL signing params stripped in some circumstances
* Improvement: Performance improvements for URL filtering, especially on large sites
Expand Down
12 changes: 6 additions & 6 deletions assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@
if ( 'as3cf' === as3cfModal.prefix && 0 === $activeBucket.text().trim().length ) {

// First time bucket select - enable main options by default
setCheckbox( 'copy-to-s3-wrap' );
setCheckbox( 'serve-from-s3-wrap' );
setCheckbox( 'as3cf-copy-to-s3-wrap' );
setCheckbox( 'as3cf-serve-from-s3-wrap' );

// Update the saved settings string so we don't trigger the navigation alert
var id = $activeTab.attr( 'id' );
Expand Down Expand Up @@ -636,7 +636,7 @@
* Toggle the lost files notice
*/
function toggleLostFilesNotice() {
if ( $( '#remove-local-file' ).is( ':checked' ) && $( '#serve-from-s3' ).is( ':not(:checked)' ) ) {
if ( $( '#as3cf-remove-local-file' ).is( ':checked' ) && $( '#as3cf-serve-from-s3' ).is( ':not(:checked)' ) ) {
$( '#as3cf-lost-files-notice' ).show();
} else {
$( '#as3cf-lost-files-notice' ).hide();
Expand All @@ -647,7 +647,7 @@
* Toggle the remove local files notice
*/
function toggleRemoveLocalNotice() {
if ( $( '#remove-local-file' ).is( ':checked' ) ) {
if ( $( '#as3cf-remove-local-file' ).is( ':checked' ) ) {
$( '#as3cf-remove-local-notice' ).show();
} else {
$( '#as3cf-remove-local-notice' ).hide();
Expand Down Expand Up @@ -749,12 +749,12 @@
} );

toggleLostFilesNotice();
$( '#serve-from-s3,#remove-local-file' ).on( 'change', function( e ) {
$( '#as3cf-serve-from-s3,#as3cf-remove-local-file' ).on( 'change', function( e ) {
toggleLostFilesNotice();
} );

toggleRemoveLocalNotice();
$( '#remove-local-file' ).on( 'change', function( e ) {
$( '#as3cf-remove-local-file' ).on( 'change', function( e ) {
toggleRemoveLocalNotice();
} );

Expand Down
2 changes: 1 addition & 1 deletion assets/js/script.min.js

Large diffs are not rendered by default.

116 changes: 62 additions & 54 deletions classes/amazon-s3-and-cloudfront.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Amazon_S3_And_CloudFront extends AWS_Plugin_Base {
const SETTINGS_KEY = 'tantan_wordpress_s3';
const SETTINGS_CONSTANT = 'WPOS3_SETTINGS';

const LATEST_UPGRADE_ROUTINE = 5;
const LATEST_UPGRADE_ROUTINE = 6;

/**
* @param string $plugin_file_path
Expand Down Expand Up @@ -113,6 +113,7 @@ function init( $plugin_file_path ) {
new AS3CF_Upgrade_Meta_WP_Error( $this );
new AS3CF_Upgrade_Content_Replace_URLs( $this );
new AS3CF_Upgrade_EDD_Replace_URLs( $this );
new AS3CF_Upgrade_Filter_Post_Excerpt( $this );

// Plugin setup
add_action( 'aws_admin_menu', array( $this, 'admin_menu' ) );
Expand Down Expand Up @@ -400,20 +401,41 @@ public function get_setting_bucket( $key, $value, $constant = 'AS3CF_BUCKET' ) {
if ( 'bucket' === $key && defined( $constant ) ) {
$bucket = constant( $constant );

if ( $bucket !== $value ) {
// Save the defined bucket
parent::set_setting( 'bucket', $bucket );
// Clear region
$this->remove_setting( 'region' );
if ( ! empty( $value ) ) {
// Clear bucket
$this->remove_setting( 'bucket' );
$this->save_settings();
}

$this->remove_region_on_constant_change( $bucket, $constant );

return $bucket;
}

return false;
}

/**
* Remove region on constant change.
*
* @param string $bucket
* @param string $constant
*/
private function remove_region_on_constant_change( $bucket, $constant ) {
$key = 'as3cf_constant_' . strtolower( $constant );
$value = get_site_transient( $key );

if ( false === $value || $bucket !== $value ) {
set_site_transient( $key, $bucket );
}

if ( false !== $value && $bucket !== $value ) {
// Clear region
$this->remove_setting( 'region' );
$this->save_settings();
}
}

/**
* Filter in defined settings with sensible defaults.
*
Expand Down Expand Up @@ -746,6 +768,7 @@ function remove_attachment_files_from_s3( $post_id, $s3object, $remove_backup_si
$bucket = $s3object['bucket'];
$region = $this->get_s3object_region( $s3object );
$paths = $this->get_attachment_file_paths( $post_id, false, false, $remove_backup_sizes );
$paths = apply_filters( 'as3cf_remove_attachment_paths', $paths, $post_id, $s3object, $remove_backup_sizes );

if ( is_wp_error( $region ) ) {
$region = '';
Expand Down Expand Up @@ -1145,7 +1168,15 @@ function remove_local_files( $file_paths ) {
}

if ( ! @unlink( $path ) ) {
AS3CF_Error::log( 'Error removing local file ' . $path );
$message = 'Error removing local file ';

if ( ! file_exists( $path ) ) {
$message = "Error removing local file. Couldn't find the file at ";
} else if ( ! is_writable( $path ) ) {
$message = 'Error removing local file. Ownership or permissions are mis-configured for ';
}

AS3CF_Error::log( $message . $path );
}
}
}
Expand Down Expand Up @@ -1750,7 +1781,7 @@ public function get_attachment_s3_url( $post_id, $s3object, $expires = null, $si

if ( ! is_null( $expires ) && $this->is_plugin_setup() ) {
try {
$expires = time() + $expires;
$expires = time() + apply_filters( 'as3cf_expires', $expires );
$secure_url = $this->get_s3client( $region )->getObjectUrl( $s3object['bucket'], $s3object['key'], $expires, $headers );

return apply_filters( 'as3cf_get_attachment_secure_url', $secure_url, $s3object, $post_id, $expires, $headers );
Expand Down Expand Up @@ -2030,7 +2061,12 @@ public function encode_filename_in_path( $file ) {
return $file;
}

$file_name = basename( $url['path'] );
if ( isset( $url['query'] ) ) {
// Manually strip query string, as passing $url['path'] to basename results in corrupt � characters
$file_name = basename( str_replace( '?' . $url['query'], '', $file ) );
} else {
$file_name = basename( $file );
}

if ( false !== strpos( $file_name, '%' ) ) {
// File name already encoded, return original
Expand Down Expand Up @@ -2339,32 +2375,6 @@ function save_bucket( $bucket_name, $manual = false, $region = null ) {
return false;
}

/**
* Get all AWS regions
*
* @return array
*/
function get_aws_regions() {
$regionEnum = new ReflectionClass( 'Aws\Common\Enum\Region' );
$all_regions = $regionEnum->getConstants();

$regions = array();
foreach ( $all_regions as $label => $region ) {
// Nicely format region name
if ( self::DEFAULT_REGION === $region ) {
$label = 'US Standard';
} else {
$label = strtolower( $label );
$label = str_replace( '_', ' ', $label );
$label = ucwords( $label );
}

$regions[ $region ] = $label;
}

return $regions;
}

/**
* Add the settings menu item
*
Expand Down Expand Up @@ -2934,7 +2944,8 @@ public function get_blog_ids() {
}

$args = array(
'limit' => false,
'limit' => false, // Deprecated
'number' => false, // WordPress 4.6+
'spam' => 0,
'deleted' => 0,
'archived' => 0,
Expand Down Expand Up @@ -3122,10 +3133,13 @@ function output_diagnostic_info( $escape = true ) {
$output .= 'WordPress: ';
$output .= get_bloginfo( 'version', 'display' );
if ( is_multisite() ) {
$output .= ' Multisite';
$output .= ' Multisite ';
$output .= '(' . ( is_subdomain_install() ? 'subdomain' : 'subdirectory' ) . ')';
$output .= "\r\n";
$output .= 'Multisite Site Count: ';
$output .= esc_html( get_blog_count() );
$output .= "\r\n";
$output .= 'Domain Mapping: ' . ( defined( 'SUNRISE' ) && SUNRISE ? 'Enabled' : 'Disabled' );
}
$output .= "\r\n";

Expand Down Expand Up @@ -3444,6 +3458,17 @@ function output_diagnostic_info( $escape = true ) {
$output .= implode( '', $mu_plugin_details );
}

$dropins = get_dropins();
if ( $dropins ) {
$output .= "\r\n\r\n";
$output .= "Drop-ins:\r\n";

foreach ( $dropins as $file => $dropin ) {
$output .= $file . ( isset( $dropin['Name'] ) ? ' - ' . $dropin['Name'] : '' );
$output .= "\r\n";
}
}

return $output;
}

Expand Down Expand Up @@ -4317,21 +4342,4 @@ public function remove_size_from_filename( $url, $remove_extension = false ) {

return $url;
}

/**
* Update site option.
*
* @param string $option
* @param mixed $value
* @param bool $autoload
*
* @return bool
*/
public function update_site_option( $option, $value, $autoload = true ) {
if ( is_multisite() ) {
return update_site_option( $option, $value );
}

return update_option( $option, $value, $autoload );
}
}
3 changes: 1 addition & 2 deletions classes/as3cf-filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,7 @@ protected function is_failure( $value ) {
* @return bool
*/
protected function attachment_id_matches_src( $attachment_id, $url ) {
$base_urls = array();
$meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
$meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );

if ( ! isset( $meta['sizes'] ) ) {
// No sizes found, return
Expand Down
Loading

0 comments on commit dee44bb

Please sign in to comment.