WP Offload S3 Lite - Version 1.1.2

Version Description

= 1.1 = This is a major change, which ensures S3 URLs are no longer saved in post content. Instead, local URLs are filtered on page generation and replaced with the S3 version. If you depend on the S3 URLs being stored in post content you will need to make modifications to support this version.

= 0.6 = This version requires PHP 5.3.3+ and the Amazon Web Services plugin

Download this release

Release Info

Developer deliciousbrains
Plugin Icon 128x128 WP Offload S3 Lite
Version 1.1.2
Comparing to
See all releases

Code changes from version 1.1 to 1.1.2

README.md CHANGED
@@ -3,7 +3,7 @@
3
**Tags:** uploads, amazon, s3, amazon s3, mirror, admin, media, cdn, cloudfront
4
**Requires at least:** 4.4
5
**Tested up to:** 4.6.1
6
- **Stable tag:** 1.1
7
**License:** GPLv3
8
9
Copies files to Amazon S3 as they are uploaded to the Media Library. Optionally configure Amazon CloudFront for faster delivery.
@@ -69,6 +69,15 @@ This version requires PHP 5.3.3+ and the Amazon Web Services plugin
69
70
## Changelog ##
71
72
### WP Offload S3 Lite 1.1 - 2016-09-29 ###
73
* New: Filter post content. S3 URLs will no longer be saved to the database
74
* New: Upgrade routine to replace all S3 URLs in content with local URLs
3
**Tags:** uploads, amazon, s3, amazon s3, mirror, admin, media, cdn, cloudfront
4
**Requires at least:** 4.4
5
**Tested up to:** 4.6.1
6
+ **Stable tag:** 1.1.2
7
**License:** GPLv3
8
9
Copies files to Amazon S3 as they are uploaded to the Media Library. Optionally configure Amazon CloudFront for faster delivery.
69
70
## Changelog ##
71
72
+ ### WP Offload S3 Lite 1.1.2 - 2016-11-02 ###
73
+ * Improvement: Better content filtering support for third party plugins and themes
74
+ * Bug fix: PHP Warning: Division by zero
75
+
76
+ ### WP Offload S3 Lite 1.1.1 - 2016-10-17 ###
77
+ * New: Filter post excerpts - S3 URLs will no longer be saved to the database
78
+ * Bug fix: PHP 5.3 Fatal error: Using $this when not in object context
79
+ * Bug fix: Query string parameters incorrectly encoded for Media Library items
80
+
81
### WP Offload S3 Lite 1.1 - 2016-09-29 ###
82
* New: Filter post content. S3 URLs will no longer be saved to the database
83
* New: Upgrade routine to replace all S3 URLs in content with local URLs
assets/js/tinymce.min.js DELETED
@@ -1 +0,0 @@
1
- tinymce.PluginManager.add("as3cf",function(a){function b(a){var b=[];if(h.each(a,function(a,c){h.has(j,a)||b.push(a)}),0!==b.length&&!(h.isUndefined(i.frame)||h.isUndefined(i.frame.states)||h.isUndefined(i.frame.states.models))){var c=h.find(i.frame.states.models,function(a){return"insert"===a.id});if(!h.isUndefined(c)&&0!==h.size(c.attributes.library.models)){var d=c.attributes.library.models,e={};h.each(a,function(a,b){var c=a.replace(/-[0-9]{1,4}x[0-9]{1,4}(\.[a-z]{2,4})#x2F;,"$1"),f=h.find(d,function(a){return a.attributes.url===c});if(!h.isUndefined(f)){var g=h.find(f.attributes.sizes,function(b){return a===b.local_url});return h.isUndefined(g)?!1:void(e[a]=g.url)}}),h.extend(j,e)}}}function c(a){var b=[];h.each(a,function(a,c){h.has(j,a)||b.push(a)}),0!==b.length&&g.ajax({url:ajaxurl,type:"POST",dataType:"JSON",async:!1,cache:!1,data:{action:"as3cf_tinymce_fetch_urls",_nonce:as3cf_tinymce.fetch_urls_nonce,urls:b},success:function(a){j=h.extend(j,a.data)}})}function d(a){return h.has(j,a)?j[a]:!1}function e(a){var e=new RegExp("("+as3cf_tinymce.local_url_escaped+'[^"<\\s]*)',"g"),f=a.match(e);return null===f?a:(b(f),c(f),h.each(f,function(b,c){var e=d(b);!1!==e&&(a=a.replace(new RegExp(b,"g"),e))}),a)}function f(a){return h.each(j,function(b,c){!1!==b&&(a=a.replace(new RegExp(b,"g"),c))}),a}var g=window.jQuery,h=window._,i=window.wp.media,j={};a.on("BeforeSetContent",function(a){a.content=e(a.content)}),a.on("PostProcess",function(a){a.get&&(a.content=f(a.content))})});
classes/amazon-s3-and-cloudfront.php CHANGED
@@ -1937,8 +1937,8 @@ class Amazon_S3_And_CloudFront extends AWS_Plugin_Base {
1937
* @return null|string
1938
*/
1939
protected function convert_dimensions_to_size_name( $attachment_id, $dimensions ) {
1940
- $w = $dimensions[0];
1941
- $h = $dimensions[1];
1942
$original_aspect_ratio = $w / $h;
1943
$meta = wp_get_attachment_metadata( $attachment_id );
1944
@@ -2030,7 +2030,7 @@ class Amazon_S3_And_CloudFront extends AWS_Plugin_Base {
2030
return $file;
2031
}
2032
2033
- $file_name = basename( $file );
2034
2035
if ( false !== strpos( $file_name, '%' ) ) {
2036
// File name already encoded, return original
1937
* @return null|string
1938
*/
1939
protected function convert_dimensions_to_size_name( $attachment_id, $dimensions ) {
1940
+ $w = ( isset( $dimensions[0] ) && $dimensions[0] > 0 ) ? $dimensions[0] : 1;
1941
+ $h = ( isset( $dimensions[1] ) && $dimensions[1] > 0 ) ? $dimensions[1] : 1;
1942
$original_aspect_ratio = $w / $h;
1943
$meta = wp_get_attachment_metadata( $attachment_id );
1944
2030
return $file;
2031
}
2032
2033
+ $file_name = basename( $url['path'] );
2034
2035
if ( false !== strpos( $file_name, '%' ) ) {
2036
// File name already encoded, return original
classes/as3cf-filter.php CHANGED
@@ -104,6 +104,11 @@ abstract class AS3CF_Filter {
104
* @return string
105
*/
106
public function filter_post( $content ) {
107
$cache = $this->get_post_cache();
108
$to_cache = array();
109
$content = $this->process_content( $content, $cache, $to_cache );
@@ -123,6 +128,11 @@ abstract class AS3CF_Filter {
123
* @return mixed
124
*/
125
protected function process_content( $content, $cache, &$to_cache ) {
126
if ( ! $this->should_filter_content() ) {
127
// Not filtering content, return
128
return $content;
104
* @return string
105
*/
106
public function filter_post( $content ) {
107
+ if ( empty( $content ) ) {
108
+ // Nothing to filter, continue
109
+ return $content;
110
+ }
111
+
112
$cache = $this->get_post_cache();
113
$to_cache = array();
114
$content = $this->process_content( $content, $cache, $to_cache );
128
* @return mixed
129
*/
130
protected function process_content( $content, $cache, &$to_cache ) {
131
+ if ( empty( $content ) ) {
132
+ // Nothing to filter, return
133
+ return $content;
134
+ }
135
+
136
if ( ! $this->should_filter_content() ) {
137
// Not filtering content, return
138
return $content;
classes/filters/as3cf-local-to-s3.php CHANGED
@@ -6,27 +6,66 @@ class AS3CF_Local_To_S3 extends AS3CF_Filter {
6
* Init.
7
*/
8
protected function init() {
9
- // Hot fix for 4.4 responsive images
10
- $priority = 1;
11
-
12
- global $wp_version;
13
- if ( 0 === version_compare( $wp_version, '4.4' ) ) {
14
- $priority = 10;
15
- }
16
-
17
// EDD
18
add_filter( 'edd_download_files', array( $this, 'filter_edd_download_files' ) );
19
// Customizer
20
add_filter( 'theme_mod_background_image', array( $this, 'filter_customizer_image' ) );
21
add_filter( 'theme_mod_header_image', array( $this, 'filter_customizer_image' ) );
22
// Posts
23
- add_filter( 'the_content', array( $this, 'filter_post' ), $priority, 1 );
24
add_filter( 'content_edit_pre', array( $this, 'filter_post' ) );
25
// Widgets
26
add_filter( 'widget_text', array( $this, 'filter_widget' ) );
27
add_filter( 'widget_form_callback', array( $this, 'filter_widget_form' ), 10, 2 );
28
}
29
30
/**
31
* Filter widget.
32
*
6
* Init.
7
*/
8
protected function init() {
9
// EDD
10
add_filter( 'edd_download_files', array( $this, 'filter_edd_download_files' ) );
11
// Customizer
12
add_filter( 'theme_mod_background_image', array( $this, 'filter_customizer_image' ) );
13
add_filter( 'theme_mod_header_image', array( $this, 'filter_customizer_image' ) );
14
// Posts
15
+ add_action( 'the_post', array( $this, 'filter_post_data' ) );
16
+ add_filter( 'content_pagination', array( $this, 'filter_content_pagination' ) );
17
+ add_filter( 'the_content', array( $this, 'filter_post' ), 100 );
18
+ add_filter( 'the_excerpt', array( $this, 'filter_post' ), 100 );
19
add_filter( 'content_edit_pre', array( $this, 'filter_post' ) );
20
+ add_filter( 'excerpt_edit_pre', array( $this, 'filter_post' ) );
21
// Widgets
22
add_filter( 'widget_text', array( $this, 'filter_widget' ) );
23
add_filter( 'widget_form_callback', array( $this, 'filter_widget_form' ), 10, 2 );
24
}
25
26
+ /**
27
+ * Filter post data.
28
+ *
29
+ * @param WP_Post $post
30
+ */
31
+ public function filter_post_data( $post ) {
32
+ global $pages;
33
+
34
+ $cache = $this->get_post_cache();
35
+ $to_cache = array();
36
+
37
+ if ( count( $pages ) === 1 ) {
38
+ // Post already filtered and available on global $page array, continue
39
+ $post->post_content = $pages[0];
40
+ } else {
41
+ $post->post_content = $this->process_content( $post->post_content, $cache, $to_cache );
42
+ }
43
+
44
+ $post->post_excerpt = $this->process_content( $post->post_excerpt, $cache, $to_cache );
45
+
46
+ $this->maybe_update_post_cache( $to_cache );
47
+ }
48
+
49
+ /**
50
+ * Filter content pagination.
51
+ *
52
+ * @param array $pages
53
+ *
54
+ * @return array
55
+ */
56
+ public function filter_content_pagination( $pages ) {
57
+ $cache = $this->get_post_cache();
58
+ $to_cache = array();
59
+
60
+ foreach ( $pages as $key => $page ) {
61
+ $pages[ $key ] = $this->process_content( $page, $cache, $to_cache );
62
+ }
63
+
64
+ $this->maybe_update_post_cache( $to_cache );
65
+
66
+ return $pages;
67
+ }
68
+
69
/**
70
* Filter widget.
71
*
classes/filters/as3cf-s3-to-local.php CHANGED
@@ -14,6 +14,7 @@ class AS3CF_S3_To_Local extends AS3CF_Filter {
14
add_filter( 'pre_set_theme_mod_header_image_data', array( $this, 'filter_header_image_data' ), 10, 2 );
15
// Posts
16
add_filter( 'content_save_pre', array( $this, 'filter_post' ) );
17
// Widgets
18
add_filter( 'widget_update_callback', array( $this, 'filter_widget_update' ), 10, 4 );
19
}
14
add_filter( 'pre_set_theme_mod_header_image_data', array( $this, 'filter_header_image_data' ), 10, 2 );
15
// Posts
16
add_filter( 'content_save_pre', array( $this, 'filter_post' ) );
17
+ add_filter( 'excerpt_save_pre', array( $this, 'filter_post' ) );
18
// Widgets
19
add_filter( 'widget_update_callback', array( $this, 'filter_widget_update' ), 10, 4 );
20
}
classes/upgrades/as3cf-content-replace-urls.php CHANGED
@@ -406,12 +406,10 @@ class AS3CF_Upgrade_Content_Replace_URLs extends AS3CF_Upgrade {
406
$url_pairs = $this->maybe_add_encoded_url_pairs( $url_pairs );
407
408
// Remove URL protocols
409
- $url_pairs = array_map( function ( $url_pair ) {
410
- $url_pair['old_url'] = $this->as3cf->remove_scheme( $url_pair['old_url'] );
411
- $url_pair['new_url'] = $this->as3cf->remove_scheme( $url_pair['new_url'] );
412
-
413
- return $url_pair;
414
- }, $url_pairs );
415
416
return apply_filters( 'as3cf_find_replace_url_pairs', $url_pairs, $file_path, $old_url, $new_url, $meta );
417
}
@@ -506,12 +504,15 @@ class AS3CF_Upgrade_Content_Replace_URLs extends AS3CF_Upgrade {
506
protected function generate_select_sql( $url_pairs, $where_lowest_id, $where_highest_id ) {
507
global $wpdb;
508
509
// Get unique URLs without size string and extension
510
- $paths = array_unique( array_map( function ( $pair ) {
511
- return $this->as3cf->remove_size_from_filename( $pair['old_url'], true );
512
- }, $url_pairs ) );
513
514
- $sql = '';
515
516
foreach ( $paths as $path ) {
517
if ( ! empty( $sql ) ) {
406
$url_pairs = $this->maybe_add_encoded_url_pairs( $url_pairs );
407
408
// Remove URL protocols
409
+ foreach ( $url_pairs as $key => $url_pair ) {
410
+ $url_pairs[ $key ]['old_url'] = $this->as3cf->remove_scheme( $url_pair['old_url'] );
411
+ $url_pairs[ $key ]['new_url'] = $this->as3cf->remove_scheme( $url_pair['new_url'] );
412
+ }
413
414
return apply_filters( 'as3cf_find_replace_url_pairs', $url_pairs, $file_path, $old_url, $new_url, $meta );
415
}
504
protected function generate_select_sql( $url_pairs, $where_lowest_id, $where_highest_id ) {
505
global $wpdb;
506
507
+ $paths = array();
508
+
509
// Get unique URLs without size string and extension
510
+ foreach ( $url_pairs as $url_pair ) {
511
+ $paths[] = $this->as3cf->remove_size_from_filename( $url_pair['old_url'], true );
512
+ }
513
514
+ $paths = array_unique( $paths );
515
+ $sql = '';
516
517
foreach ( $paths as $path ) {
518
if ( ! empty( $sql ) ) {
languages/amazon-s3-and-cloudfront-en.pot CHANGED
@@ -8,7 +8,7 @@ msgid ""
8
msgstr ""
9
"Project-Id-Version: amazon-s3-and-cloudfront\n"
10
"Report-Msgid-Bugs-To: nom@deliciousbrains.com\n"
11
- "POT-Creation-Date: 2016-09-29 13:21+0100\n"
12
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -346,25 +346,25 @@ msgstr ""
346
msgid "and ensuring that only the local URL exists in post content."
347
msgstr ""
348
349
- #: classes/upgrades/as3cf-content-replace-urls.php:565
350
#, php-format
351
msgid ""
352
"<strong>Running 1.2 Upgrade%1$s</strong><br>A find &amp; replace is running "
353
"in the background to update URLs in your content. %2$s"
354
msgstr ""
355
356
- #: classes/upgrades/as3cf-content-replace-urls.php:574
357
#, php-format
358
msgid ""
359
"<strong>Paused 1.2 Upgrade</strong><br>The find &amp; replace to update URLs "
360
"in your content has been paused. %s"
361
msgstr ""
362
363
- #: classes/upgrades/as3cf-content-replace-urls.php:583
364
msgid "See our documentation"
365
msgstr ""
366
367
- #: classes/upgrades/as3cf-content-replace-urls.php:586
368
#, php-format
369
msgid ""
370
"%s for details on why we&#8217;re doing this, why it runs slowly, and how to "
8
msgstr ""
9
"Project-Id-Version: amazon-s3-and-cloudfront\n"
10
"Report-Msgid-Bugs-To: nom@deliciousbrains.com\n"
11
+ "POT-Creation-Date: 2016-11-02 13:33+0000\n"
12
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
"Language-Team: LANGUAGE <LL@li.org>\n"
346
msgid "and ensuring that only the local URL exists in post content."
347
msgstr ""
348
349
+ #: classes/upgrades/as3cf-content-replace-urls.php:566
350
#, php-format
351
msgid ""
352
"<strong>Running 1.2 Upgrade%1$s</strong><br>A find &amp; replace is running "
353
"in the background to update URLs in your content. %2$s"
354
msgstr ""
355
356
+ #: classes/upgrades/as3cf-content-replace-urls.php:575
357
#, php-format
358
msgid ""
359
"<strong>Paused 1.2 Upgrade</strong><br>The find &amp; replace to update URLs "
360
"in your content has been paused. %s"
361
msgstr ""
362
363
+ #: classes/upgrades/as3cf-content-replace-urls.php:584
364
msgid "See our documentation"
365
msgstr ""
366
367
+ #: classes/upgrades/as3cf-content-replace-urls.php:587
368
#, php-format
369
msgid ""
370
"%s for details on why we&#8217;re doing this, why it runs slowly, and how to "
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: bradt, deliciousbrains
3
Tags: uploads, amazon, s3, amazon s3, mirror, admin, media, cdn, cloudfront
4
Requires at least: 4.4
5
Tested up to: 4.6.1
6
- Stable tag: 1.1
7
License: GPLv3
8
9
Copies files to Amazon S3 as they are uploaded to the Media Library. Optionally configure Amazon CloudFront for faster delivery.
@@ -65,6 +65,15 @@ This version requires PHP 5.3.3+ and the Amazon Web Services plugin
65
66
== Changelog ==
67
68
= WP Offload S3 Lite 1.1 - 2016-09-29 =
69
* New: Filter post content. S3 URLs will no longer be saved to the database
70
* New: Upgrade routine to replace all S3 URLs in content with local URLs
3
Tags: uploads, amazon, s3, amazon s3, mirror, admin, media, cdn, cloudfront
4
Requires at least: 4.4
5
Tested up to: 4.6.1
6
+ Stable tag: 1.1.2
7
License: GPLv3
8
9
Copies files to Amazon S3 as they are uploaded to the Media Library. Optionally configure Amazon CloudFront for faster delivery.
65
66
== Changelog ==
67
68
+ = WP Offload S3 Lite 1.1.2 - 2016-11-02 =
69
+ * Improvement: Better content filtering support for third party plugins and themes
70
+ * Bug fix: PHP Warning: Division by zero
71
+
72
+ = WP Offload S3 Lite 1.1.1 - 2016-10-17 =
73
+ * New: Filter post excerpts - S3 URLs will no longer be saved to the database
74
+ * Bug fix: PHP 5.3 Fatal error: Using $this when not in object context
75
+ * Bug fix: Query string parameters incorrectly encoded for Media Library items
76
+
77
= WP Offload S3 Lite 1.1 - 2016-09-29 =
78
* New: Filter post content. S3 URLs will no longer be saved to the database
79
* New: Upgrade routine to replace all S3 URLs in content with local URLs
wordpress-s3.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: WP Offload S3 Lite
4
Plugin URI: http://wordpress.org/extend/plugins/amazon-s3-and-cloudfront/
5
Description: Automatically copies media uploads to Amazon S3 for storage and delivery. Optionally configure Amazon CloudFront for even faster delivery.
6
Author: Delicious Brains
7
- Version: 1.1
8
Author URI: http://deliciousbrains.com/
9
Network: True
10
Text Domain: amazon-s3-and-cloudfront
@@ -26,7 +26,7 @@ Domain Path: /languages/
26
// Then completely rewritten.
27
*/
28
29
- $GLOBALS['aws_meta']['amazon-s3-and-cloudfront']['version'] = '1.1';
30
31
$aws_plugin_version_required = '1.0';
32
4
Plugin URI: http://wordpress.org/extend/plugins/amazon-s3-and-cloudfront/
5
Description: Automatically copies media uploads to Amazon S3 for storage and delivery. Optionally configure Amazon CloudFront for even faster delivery.
6
Author: Delicious Brains
7
+ Version: 1.1.2
8
Author URI: http://deliciousbrains.com/
9
Network: True
10
Text Domain: amazon-s3-and-cloudfront
26
// Then completely rewritten.
27
*/
28
29
+ $GLOBALS['aws_meta']['amazon-s3-and-cloudfront']['version'] = '1.1.2';
30
31
$aws_plugin_version_required = '1.0';
32