WP Offload S3 Lite - Version 0.8.2

Version Description

  • 2015-01-31 =
  • New: Input bucket in settings to avoid listing all buckets
  • New: Specify bucket with 'AS3CF_BUCKET' constant
  • Improvement: Compatibility with beta release of Pro plugin
  • Bug Fix: Incorrect file prefix in S3 permission check
Download this release

Release Info

Developer bradt
Plugin Icon 128x128 WP Offload S3 Lite
Version 0.8.2
Comparing to
See all releases

Code changes from version 0.8.1 to 0.8.2

assets/.jshintrc ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "boss": true,
3
+ "browser": true,
4
+ "curly": true,
5
+ "devel": true,
6
+ "eqeqeq": true,
7
+ "eqnull": true,
8
+ "es3": false,
9
+ "immed": true,
10
+ "jquery": true,
11
+ "latedef": true,
12
+ "maxerr": 10000,
13
+ "newcap": true,
14
+ "noarg": true,
15
+ "sub": true,
16
+ "undef": true,
17
+ "globals": {
18
+ "ajaxurl": true,
19
+ "as3cf_i18n": true
20
+ }
21
+ }
assets/Gruntfile.js CHANGED
@@ -2,6 +2,16 @@ module.exports = function(grunt) {
2
 
3
  grunt.initConfig({
4
  pkg: grunt.file.readJSON('package.json'),
 
 
 
 
 
 
 
 
 
 
5
  uglify: {
6
  build: {
7
  files: {
@@ -27,10 +37,11 @@ module.exports = function(grunt) {
27
  }
28
  });
29
 
 
30
  grunt.loadNpmTasks('grunt-contrib-uglify');
31
  grunt.loadNpmTasks('grunt-contrib-watch');
32
  grunt.loadNpmTasks('grunt-contrib-compass');
33
 
34
- grunt.registerTask('default', ['uglify','compass']);
35
 
36
  };
2
 
3
  grunt.initConfig({
4
  pkg: grunt.file.readJSON('package.json'),
5
+ jshint: {
6
+ all: [
7
+ 'js/*.js',
8
+ '!js/*.min.js'
9
+ ],
10
+ options: {
11
+ jshintrc: '.jshintrc',
12
+ force: true
13
+ }
14
+ },
15
  uglify: {
16
  build: {
17
  files: {
37
  }
38
  });
39
 
40
+ grunt.loadNpmTasks('grunt-contrib-jshint');
41
  grunt.loadNpmTasks('grunt-contrib-uglify');
42
  grunt.loadNpmTasks('grunt-contrib-watch');
43
  grunt.loadNpmTasks('grunt-contrib-compass');
44
 
45
+ grunt.registerTask('default', ['jshint','uglify','compass']);
46
 
47
  };
assets/css/styles.css CHANGED
@@ -1 +1 @@
1
- .aws-main .error pre{background:#eaeaea;background:rgba(0,0,0,0.07);display:block;padding:10px 15px}.aws-main .error pre code{padding:0;background:none}.aws-main .as3cf-notice,.aws-main .error{max-width:935px}.aws-main .updated{display:none}.aws-main .updated.as3cf-notice,.aws-main .updated.show{display:block}.as3cf-settings{position:relative;width:650px;min-height:800px}.as3cf-settings .as3cf-main-settings{display:none}.as3cf-settings .as3cf-main-settings p{font-size:13px}.as3cf-settings .as3cf-main-settings p a{color:#444}.as3cf-settings.as3cf-has-bucket .as3cf-bucket-select{display:none}.as3cf-settings.as3cf-has-bucket .as3cf-main-settings{display:block}.as3cf-settings tr.configure-url,.as3cf-settings tr.advanced-options{display:none}.as3cf-settings .object-prefix-desc em{white-space:nowrap}.as3cf-settings .as3cf-url-preview-wrap{background:#ffffff;text-align:center;padding:20px 20px 10px;max-width:610px;width:100%}.as3cf-settings .as3cf-url-preview-wrap .as3cf-url-preview{margin-top:5px;overflow-x:scroll;padding-bottom:15px}.as3cf-settings .as3cf-url-preview-wrap span{color:#aaa;text-transform:uppercase;font-weight:bold}.as3cf-settings .as3cf-ssl p.info{margin-top:10px;padding:0}.as3cf-settings .as3cf-radio-group label{display:block;margin-bottom:10px}.as3cf-settings .as3cf-radio-group label.disabled,.as3cf-settings .as3cf-radio-group label.disabled p{color:#bbbbbb;cursor:default}.as3cf-settings .as3cf-radio-group p{padding-left:25px;color:#6b6b6b;margin:0;font-size:12px}.as3cf-settings .as3cf-radio-group p.as3cf-setting{margin-top:5px}.as3cf-settings .as3cf-switch{position:relative}.as3cf-settings .as3cf-switch.disabled span{cursor:default;margin:1px 0 0 0}.as3cf-settings .as3cf-switch.disabled span.checked{background:#F1F1F1;border:1px solid #dddddd;color:#a3a3a3}.as3cf-settings .as3cf-switch span{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;cursor:pointer;float:left;display:inline-block;height:100%;font-size:12px;line-height:20px;border-radius:2px;-webkit-border-radius:2px;font-weight:bold;padding:4px 8px;background:#F1F1F1;border:1px solid #dddddd;color:#CCCCCC;margin:1px -1px 0;z-index:1}.as3cf-settings .as3cf-switch span.checked{background:#ffffff;border-color:#E4E4E4;color:#373737;padding:5px 10px;margin:0;z-index:2}.as3cf-settings .as3cf-switch input[type="checkbox"]{position:absolute !important;top:0;left:0;opacity:0;filter:alpha(opacity=0);z-index:-1}.as3cf-settings .as3cf-setting.hide{display:none}.as3cf-settings .as3cf-bucket-actions{position:absolute;right:0;top:2px}.as3cf-settings .as3cf-bucket-actions .as3cf-cancel-bucket-select-wrap{display:none}.as3cf-settings .as3cf-bucket-actions .as3cf-cancel-bucket-select-wrap:after{content:" | "}.as3cf-settings .as3cf-bucket-list-wrapper{background:#fff;padding:15px 20px;margin-bottom:2em}.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list{max-height:300px;overflow:auto;margin:0}.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list li{font-size:14px;padding:10px 0}.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list a{color:#444;text-decoration:none}.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list a:hover,.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list a.selected{color:#0074A2}.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list a.selected{font-weight:bold}.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list a .bucket{float:left;clear:both}.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list a .bucket .dashicons{margin-right:5px}.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list a .spinner{float:left;background-size:15px 15px}.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list.saving{opacity:0.5}.as3cf-settings .as3cf-create-bucket-form input[type="text"]{width:80%}.as3cf-settings select.bucket{margin-bottom:5px;width:380px}.as3cf-settings .form-table td{padding-left:0;padding-right:0}.as3cf-settings .form-table td:first-child{vertical-align:top;min-width:120px}.as3cf-settings .form-table h3{font-weight:normal;text-transform:uppercase;margin:0}.as3cf-settings .form-table h4{margin:0}.as3cf-settings .form-table .as3cf-border-bottom td{border-bottom:1px solid #ddd}.as3cf-settings .as3cf-active-bucket{font-weight:bold;margin-right:10px}.as3cf-settings .tooltip{position:relative;z-index:2;cursor:pointer}.as3cf-settings .tooltip:before,.as3cf-settings .tooltip:after{visibility:hidden;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=0);opacity:0;pointer-events:none}.as3cf-settings .tooltip:before{position:absolute;bottom:150%;left:50%;margin-bottom:5px;margin-left:-250px;padding:10px;width:500px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;background-color:#000;background-color:rgba(51,51,51,0.9);color:#fff;content:attr(data-tooltip);text-align:center;font-size:14px;line-height:1.3}.as3cf-settings .tooltip:after{position:absolute;bottom:150%;left:50%;margin-left:-5px;width:0;border-top:5px solid #000;border-top:5px solid rgba(51,51,51,0.9);border-right:5px solid transparent;border-left:5px solid transparent;content:" ";font-size:0;line-height:0}.as3cf-settings .tooltip:hover:before,.as3cf-settings .tooltip:hover:after{visibility:visible;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=100);opacity:1}.as3cf-banner img{display:block}.as3cf-sidebar{position:absolute;top:17px;right:-312px;width:292px}.as3cf-sidebar .block{padding:20px;border:1px solid #ccc}.as3cf-sidebar .subscribe{border-top:none}.as3cf-sidebar .subscribe h2{padding:0;margin:0;margin-bottom:0.5em;color:#666;font-size:20px;line-height:1.2em;float:none}.as3cf-sidebar .subscribe h3{font-size:16px;margin:0}.as3cf-sidebar .subscribe p{margin:0}.as3cf-sidebar .subscribe .intro{margin-bottom:1em;line-height:1.4}.as3cf-sidebar .subscribe ul{margin-left:20px;list-style-type:disc}.as3cf-sidebar .subscribe li{line-height:1.4}.as3cf-sidebar .subscribe .links{margin-bottom:2em}.as3cf-sidebar .subscribe .links a{text-decoration:none}.as3cf-sidebar .subscribe .promise{color:#999;font-size:12px;line-height:1.4em}.as3cf-sidebar .subscribe .field{margin-bottom:0.5em}.as3cf-sidebar .subscribe .field p{margin-bottom:0.3em}.as3cf-sidebar .subscribe .field.submit-button{margin-bottom:1em}.as3cf-sidebar .credits{border-top:0}.as3cf-sidebar .credits h4{font-size:16px;margin-top:0;margin-bottom:10px}.as3cf-sidebar .credits ul{margin:0}.as3cf-sidebar .credits li{overflow:hidden}.as3cf-sidebar .credits li:last-child{margin-bottom:0}.as3cf-sidebar .credits img{float:left;margin-right:10px}.as3cf-sidebar .credits span{float:left;display:block;line-height:32px}.as3cf-sidebar .credits a{display:block;text-decoration:none;color:#444;font-size:16px;text-align:center}.as3cf-sidebar .credits a:hover{color:#888}@media (min--moz-device-pixel-ratio: 1.3), (-o-min-device-pixel-ratio: 2.6 / 2), (-webkit-min-device-pixel-ratio: 1.3), (min-device-pixel-ratio: 1.3), (min-resolution: 1.3dppx){.as3cf-sidebar .as3cf-banner{background-image:url(../img/snail@2x.jpg);background-size:292px 165px;width:292px;height:165px;display:block}.as3cf-sidebar .as3cf-banner img{display:none}}@media screen and (max-width: 1052px){.as3cf-sidebar{position:relative;top:auto;right:auto;margin-top:50px}}
1
+ .aws-main .error pre{background:#eaeaea;background:rgba(0,0,0,0.07);display:block;padding:10px 15px}.aws-main .error pre code{padding:0;background:none}.aws-main .as3cf-notice,.aws-main .error{max-width:935px}.aws-main .updated{display:none}.aws-main .updated.as3cf-notice,.aws-main .updated.show{display:block}.as3cf-settings{position:relative;width:650px;min-height:800px}.as3cf-settings .as3cf-main-settings{display:none}.as3cf-settings .as3cf-main-settings p{font-size:13px}.as3cf-settings .as3cf-main-settings p a{color:#444}.as3cf-settings.as3cf-has-bucket .as3cf-bucket-select{display:none}.as3cf-settings.as3cf-has-bucket .as3cf-main-settings{display:block}.as3cf-settings .object-prefix-desc em{white-space:nowrap}.as3cf-settings .as3cf-url-preview-wrap{background:#ffffff;text-align:center;padding:20px 20px 10px;max-width:610px;width:100%}.as3cf-settings .as3cf-url-preview-wrap .as3cf-url-preview{margin-top:5px;overflow-x:scroll;padding-bottom:15px}.as3cf-settings .as3cf-url-preview-wrap span{color:#aaa;text-transform:uppercase;font-weight:bold}.as3cf-settings .as3cf-ssl p.info{margin-top:10px;padding:0}.as3cf-settings .as3cf-radio-group label{display:block;margin-bottom:10px}.as3cf-settings .as3cf-radio-group label.disabled,.as3cf-settings .as3cf-radio-group label.disabled p{color:#bbbbbb;cursor:default}.as3cf-settings .as3cf-radio-group p{padding-left:25px;color:#6b6b6b;margin:0;font-size:12px}.as3cf-settings .as3cf-radio-group p.as3cf-setting{margin-top:5px}.as3cf-settings .as3cf-switch{position:relative}.as3cf-settings .as3cf-switch.disabled span{cursor:default;margin:1px 0 0 0}.as3cf-settings .as3cf-switch.disabled span.checked{background:#F1F1F1;border:1px solid #dddddd;color:#a3a3a3}.as3cf-settings .as3cf-switch span{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;cursor:pointer;float:left;display:inline-block;height:100%;font-size:12px;line-height:20px;border-radius:2px;-webkit-border-radius:2px;font-weight:bold;padding:4px 8px;background:#F1F1F1;border:1px solid #dddddd;color:#CCCCCC;margin:1px -1px 0;z-index:1}.as3cf-settings .as3cf-switch span.checked{background:#ffffff;border-color:#E4E4E4;color:#373737;padding:5px 10px;margin:0;z-index:2}.as3cf-settings .as3cf-switch input[type="checkbox"]{position:absolute !important;top:0;left:0;opacity:0;filter:alpha(opacity=0);z-index:-1}.as3cf-settings .as3cf-setting.hide{display:none}.as3cf-settings .as3cf-bucket-actions{position:absolute;right:0;top:2px}.as3cf-settings .as3cf-bucket-actions .as3cf-cancel-bucket-select-wrap{display:none}.as3cf-settings .as3cf-bucket-actions .as3cf-cancel-bucket-select-wrap:after{content:" | "}.as3cf-settings .as3cf-bucket-select.manual .as3cf-manual-bucket-toggle,.as3cf-settings .as3cf-bucket-select.manual .as3cf-refresh-buckets,.as3cf-settings .as3cf-bucket-select.manual .as3cf-bucket-list-wrapper{display:none}.as3cf-settings .as3cf-bucket-select.manual .as3cf-bucket-list-toggle,.as3cf-settings .as3cf-bucket-select.manual .as3cf-manual-save-bucket-wrapper{display:block}.as3cf-settings .as3cf-bucket-select.manual .as3cf-cancel-bucket-select-wrap:after{content:""}.as3cf-settings .as3cf-bucket-select .as3cf-manual-bucket-toggle,.as3cf-settings .as3cf-bucket-select .as3cf-bucket-list-wrapper{display:block}.as3cf-settings .as3cf-bucket-select .as3cf-refresh-buckets{display:inline}.as3cf-settings .as3cf-bucket-select .as3cf-bucket-list-toggle,.as3cf-settings .as3cf-bucket-select .as3cf-manual-save-bucket-wrapper{display:none}.as3cf-settings .as3cf-bucket-list-wrapper{background:#fff;padding:15px 20px;margin-bottom:2em}.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list{max-height:300px;overflow:auto;margin:0}.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list li{font-size:14px;padding:10px 0}.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list a{color:#444;text-decoration:none}.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list a:hover,.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list a.selected{color:#0074A2}.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list a.selected{font-weight:bold}.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list a .bucket{float:left;clear:both}.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list a .bucket .dashicons{margin-right:5px}.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list a .spinner{float:left;background-size:15px 15px}.as3cf-settings .as3cf-bucket-list-wrapper .as3cf-bucket-list.saving{opacity:0.5}.as3cf-settings input[type="text"].as3cf-bucket-name{width:80%}.as3cf-settings select.bucket{margin-bottom:5px;width:380px}.as3cf-settings .form-table td{padding-left:0;padding-right:0}.as3cf-settings .form-table td:first-child{vertical-align:top;min-width:120px}.as3cf-settings .form-table h3{font-weight:normal;text-transform:uppercase;margin:0}.as3cf-settings .form-table h4{margin:0}.as3cf-settings .form-table .as3cf-border-bottom td{border-bottom:1px solid #ddd}.as3cf-settings .as3cf-active-bucket{font-weight:bold;margin-right:10px}.as3cf-settings .tooltip{position:relative;z-index:2;cursor:pointer}.as3cf-settings .tooltip:before,.as3cf-settings .tooltip:after{visibility:hidden;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=0);opacity:0;pointer-events:none}.as3cf-settings .tooltip:before{position:absolute;bottom:150%;left:50%;margin-bottom:5px;margin-left:-250px;padding:10px;width:500px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;background-color:#000;background-color:rgba(51,51,51,0.9);color:#fff;content:attr(data-tooltip);text-align:center;font-size:14px;line-height:1.3}.as3cf-settings .tooltip:after{position:absolute;bottom:150%;left:50%;margin-left:-5px;width:0;border-top:5px solid #000;border-top:5px solid rgba(51,51,51,0.9);border-right:5px solid transparent;border-left:5px solid transparent;content:" ";font-size:0;line-height:0}.as3cf-settings .tooltip:hover:before,.as3cf-settings .tooltip:hover:after{visibility:visible;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=100);opacity:1}.as3cf-banner img{display:block}.as3cf-sidebar{position:absolute;top:17px;right:-312px;width:292px}.as3cf-sidebar .block{padding:20px;border:1px solid #ccc}.as3cf-sidebar .subscribe{border-top:none}.as3cf-sidebar .subscribe h2{padding:0;margin:0;margin-bottom:0.5em;color:#666;font-size:20px;line-height:1.2em;float:none}.as3cf-sidebar .subscribe h3{font-size:16px;margin:0}.as3cf-sidebar .subscribe p{margin:0}.as3cf-sidebar .subscribe .intro{margin-bottom:1em;line-height:1.4}.as3cf-sidebar .subscribe ul{margin-left:20px;list-style-type:disc}.as3cf-sidebar .subscribe li{line-height:1.4}.as3cf-sidebar .subscribe .links{margin-bottom:2em}.as3cf-sidebar .subscribe .links a{text-decoration:none}.as3cf-sidebar .subscribe .promise{color:#999;font-size:12px;line-height:1.4em}.as3cf-sidebar .subscribe .field{margin-bottom:0.5em}.as3cf-sidebar .subscribe .field p{margin-bottom:0.3em}.as3cf-sidebar .subscribe .field.submit-button{margin-bottom:1em}.as3cf-sidebar .credits{border-top:0}.as3cf-sidebar .credits h4{font-size:16px;margin-top:0;margin-bottom:10px}.as3cf-sidebar .credits ul{margin:0}.as3cf-sidebar .credits li{overflow:hidden}.as3cf-sidebar .credits li:last-child{margin-bottom:0}.as3cf-sidebar .credits img{float:left;margin-right:10px}.as3cf-sidebar .credits span{float:left;display:block;line-height:32px}.as3cf-sidebar .credits a{display:block;text-decoration:none;color:#444;font-size:16px;text-align:center}.as3cf-sidebar .credits a:hover{color:#888}@media (min--moz-device-pixel-ratio: 1.3), (-o-min-device-pixel-ratio: 2.6 / 2), (-webkit-min-device-pixel-ratio: 1.3), (min-device-pixel-ratio: 1.3), (min-resolution: 1.3dppx){.as3cf-sidebar .as3cf-banner{background-image:url(../img/snail@2x.jpg);background-size:292px 165px;width:292px;height:165px;display:block}.as3cf-sidebar .as3cf-banner img{display:none}}@media screen and (max-width: 1052px){.as3cf-sidebar{position:relative;top:auto;right:auto;margin-top:50px}}
assets/js/script.js CHANGED
@@ -1,175 +1,239 @@
1
  (function($) {
2
  var saved_settings;
3
 
4
- $(document).ready(function() {
5
 
6
- $('.as3cf-settings').each(function() {
7
- var $container = $(this);
8
- var $bucketList = $('.as3cf-bucket-list');
9
- var $createBucketForm = $container.find('.as3cf-create-bucket-form');
 
10
 
11
- if($createBucketForm.length){
12
- var $createBucketButton = $createBucketForm.find('button'),
13
- origButtonText = $createBucketButton.text();
14
 
15
- $createBucketForm.on('submit', function(e){
16
  e.preventDefault();
17
  $( '.as3cf-bucket-error' ).hide();
18
- $bucketList.addClass('saving');
19
- $createBucketButton.text($createBucketButton.attr('data-working'));
20
- $createBucketButton.prop('disabled', true);
21
- var bucketName = $createBucketForm.find('input[name="bucket_name"]').val();
22
 
23
  var data = {
24
- action: 'as3cf-create-bucket',
25
- bucket_name: bucketName,
26
- _nonce: as3cf_i18n.create_bucket_nonce
27
  };
28
 
29
- $.ajax({
30
- url: ajaxurl,
31
- type: 'POST',
32
- dataType: 'JSON',
33
- data: data,
34
- error: function(jqXHR, textStatus, errorThrown) {
35
- $createBucketButton.text(origButtonText);
36
  show_bucket_error( as3cf_i18n.create_bucket_error, errorThrown );
37
  },
38
- success: function(data, textStatus, jqXHR) {
39
- $createBucketButton.text(origButtonText);
40
- $createBucketButton.prop('disabled', false);
41
- if (typeof data['success'] !== 'undefined') {
42
- bucket_select( bucketName, data['region'], data['can_write'] );
43
  // tidy up create bucket form
44
- $createBucketForm.find('input[name="bucket_name"]').val('');
45
- $('.as3cf-bucket-list a' ).removeClass('selected');
46
- loadBuckets();
47
- $bucketList.removeClass('saving');
 
 
 
48
  } else {
49
- show_bucket_error( as3cf_i18n.create_bucket_error, data['error'] );
50
  }
51
  }
52
- });
53
- });
54
  }
55
 
56
- var $changeBucket = $container.find('.as3cf-change-bucket');
57
- if($changeBucket.length){
58
- $changeBucket.on('click', function(e){
 
 
59
  e.preventDefault();
60
- $( '.updated' ).not('.as3cf-notice').hide();
61
- $('.as3cf-can-write-error').hide();
62
- $('.as3cf-settings').removeClass('as3cf-has-bucket');
63
- loadBuckets();
64
- if ( $('.as3cf-active-bucket' ).html ) {
65
- $('.as3cf-cancel-bucket-select-wrap' ).show();
66
  }
67
- if ( $( '.as3cf-bucket-list a.selected' ).length ) {
68
- $( '.as3cf-bucket-list' ).scrollTop( $( '.as3cf-bucket-list a.selected' ).position().top - 50 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  }
70
- });
71
  }
72
 
73
- var $refreshBuckets = $container.find('.as3cf-refresh-buckets');
74
- if($refreshBuckets.length){
75
- $refreshBuckets.on('click', function(e){
76
  e.preventDefault();
77
  loadBuckets();
78
- });
79
  }
80
 
81
- var $cancelChangeBucket = $container.find('.as3cf-cancel-bucket-select');
82
- if($cancelChangeBucket.length){
83
- $cancelChangeBucket.on('click', function(e){
84
  e.preventDefault();
85
  $( '.as3cf-bucket-error' ).hide();
86
- $('.as3cf-settings').addClass('as3cf-has-bucket');
87
- });
88
  }
89
 
90
- });
 
 
91
 
92
- var $bucketList = $('.as3cf-bucket-list');
93
  function loadBuckets() {
94
  $( '.as3cf-bucket-error' ).hide();
95
- $bucketList.html('<li class="loading">'+ $bucketList.attr('data-working') +'</li>');
96
 
97
  var data = {
98
  action: 'as3cf-get-buckets',
99
  _nonce: as3cf_i18n.get_buckets_nonce
100
  };
101
 
102
- $.ajax({
103
- url: ajaxurl,
104
- type: 'POST',
105
- dataType: 'JSON',
106
- data: data,
107
- error: function(jqXHR, textStatus, errorThrown) {
108
- $bucketList.html('');
109
  show_bucket_error( as3cf_i18n.get_buckets_error, errorThrown );
110
  },
111
- success: function(data, textStatus, jqXHR) {
112
- $bucketList.html('');
113
- if (typeof data['success'] !== 'undefined') {
114
- $(data['buckets']).each(function(idx, bucket){
115
- var bucket_class = ( bucket.Name == data['selected'] ) ? 'selected' : '';
116
- $bucketList.append('<li><a class="' + bucket_class + '" href="#" data-bucket="'+ bucket.Name +'"><span class="bucket"><span class="dashicons dashicons-portfolio"></span> '+ bucket.Name +'</span><span class="spinner"></span></span></a></li>');
117
- });
 
 
 
118
  } else {
119
  show_bucket_error( as3cf_i18n.get_buckets_error, data[ 'error' ] );
120
  }
121
  }
122
- });
123
  }
124
 
125
- $bucketList.on('click', 'a', function(e){
126
  e.preventDefault();
127
 
128
- if ( $(this).hasClass('selected') ) {
129
- $('.as3cf-settings').addClass('as3cf-has-bucket');
130
  return;
131
  }
132
 
133
  var bucket = this;
134
- var previous_bucket = $('.as3cf-bucket-list a.selected' ).attr('data-bucket');
135
 
136
- $('.as3cf-bucket-list a' ).removeClass('selected');
137
- $(bucket).addClass('selected');
138
 
139
- $bucketList.addClass('saving');
140
- $(bucket).find('.spinner').show();
141
- var bucketName = $(bucket).attr('data-bucket');
142
 
143
  var data = {
144
- action: 'as3cf-save-bucket',
145
  bucket_name: bucketName,
146
- _nonce: as3cf_i18n.save_bucket_nonce
147
  };
148
 
149
- $.ajax({
150
- url: ajaxurl,
151
- type: 'POST',
152
- dataType: 'JSON',
153
- data: data,
154
- error: function(jqXHR, textStatus, errorThrown) {
155
- $bucketList.removeClass('saving');
156
  show_bucket_error( as3cf_i18n.save_bucket_error, errorThrown );
157
- $('.as3cf-bucket-list a' ).removeClass('selected');
158
  $( '.as3cf-bucket-list a[data-bucket="' + previous_bucket + '"]' ).addClass( 'selected' );
159
  },
160
- success: function(data, textStatus, jqXHR) {
161
- $(bucket).find('.spinner').hide();
162
- $bucketList.removeClass('saving');
163
- if (typeof data['success'] !== 'undefined') {
164
- bucket_select( bucketName, data['region'], data['can_write'] );
165
  } else {
166
- show_bucket_error( as3cf_i18n.save_bucket_error, data['error'] );
167
- $('.as3cf-bucket-list a' ).removeClass('selected');
168
  $( '.as3cf-bucket-list a[data-bucket="' + previous_bucket + '"]' ).addClass( 'selected' );
169
  }
170
  }
171
- });
172
- });
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
  function show_bucket_error( title, error ) {
175
  $( '.as3cf-bucket-error span.title' ).html( title );
@@ -178,78 +242,77 @@
178
  }
179
 
180
  function bucket_select( bucket, region, can_write ) {
181
- if ( '' == $( '.as3cf-active-bucket' ).text() ) {
182
  // first time bucket select - enable main options by default
183
  set_checkbox( 'copy-to-s3-wrap' );
184
  set_checkbox( 'serve-from-s3-wrap' );
185
  }
186
  $( '.as3cf-active-bucket' ).text( bucket );
 
187
  $( '#as3cf-bucket' ).val( bucket );
188
  $( '#as3cf-region' ).val( region );
189
- $( '.updated' ).not('.as3cf-notice' ).show();
190
  // check permission on bucket
191
- if( can_write === false){
192
- $('.as3cf-can-write-error').show();
193
  }
194
  $( '.as3cf-settings' ).addClass( 'as3cf-has-bucket' );
195
  generate_url_preview();
196
  }
197
 
198
- $('.as3cf-switch').on('click', 'span', function(e){
199
- if ( ! $(this).parent().hasClass('disabled') ) {
200
- var parent_id = $(this).parent().attr('id');
201
  set_checkbox( parent_id );
202
  }
203
- });
204
 
205
  function set_checkbox( checkbox_wrap ) {
206
- $('#' + checkbox_wrap + ' span' ).toggleClass('checked');
207
- var switch_on = $('#' + checkbox_wrap + ' span.on' ).hasClass('checked');
208
- var checkbox_name = $('#' + checkbox_wrap).data('checkbox');
209
- var $checkbox = $('input#' + checkbox_name);
210
  $checkbox.attr( "checked", switch_on );
211
- $checkbox.trigger("change");
212
  }
213
 
214
  if ( $( '.as3cf-settings' ).length && ! $( '.as3cf-settings' ).hasClass( 'as3cf-has-bucket' ) ) {
215
- loadBuckets();
216
- }
217
-
218
- if ( $( '#copy-to-s3' ).is( ":checked" ) ) {
219
- $('tr.advanced-options').show();
220
  }
221
 
222
- $('.as3cf-settings').on('change', '#copy-to-s3', function(e){
223
- $('tr.advanced-options').toggle();
224
- });
225
-
226
- if ( $( '#serve-from-s3' ).is( ":checked" ) ) {
227
- $('tr.configure-url').show();
228
- }
229
 
230
- $('.as3cf-settings').on('change', '#serve-from-s3', function(e){
231
- $('tr.configure-url').toggle();
232
- });
 
233
 
234
- $('.as3cf-settings').on('change', '.sub-toggle', function(e){
235
- var setting = $(this ).attr('id');
236
- $('.as3cf-setting.' + setting ).toggleClass('hide');
237
- });
 
 
238
 
239
- $('.as3cf-domain').on('change', 'input[type="radio"]', function(e){
240
  var domain = $( 'input:radio[name="domain"]:checked' ).val();
241
- if ( 'cloudfront' == domain && $('.as3cf-setting.cloudfront' ).hasClass('hide') ) {
242
- $('.as3cf-setting.cloudfront' ).removeClass('hide');
243
  } else {
244
- $('.as3cf-setting.cloudfront' ).addClass('hide');
245
  }
246
- });
247
 
248
  $( '.as3cf-ssl' ).on( 'change', 'input[type="radio"]', function( e ) {
249
  var ssl = $( 'input:radio[name="ssl"]:checked' ).val();
250
- if ( 'https' == ssl ) {
251
  var domain = $( 'input:radio[name="domain"]:checked' ).val();
252
- if ( 'subdomain' == domain ) {
253
  $( 'input[name="domain"][value="path"]' ).attr( "checked", true );
254
  }
255
  $( '.subdomain-wrap input' ).attr( 'disabled', true );
@@ -260,49 +323,59 @@
260
  }
261
  } );
262
 
263
- $('.url-preview').on('change', 'input', function(e){
264
  generate_url_preview();
265
- });
266
 
267
  function generate_url_preview() {
268
- $('.as3cf-url-preview' ).html( 'Generating...' );
269
 
270
  var data = {
271
  _nonce: as3cf_i18n.get_url_preview_nonce
272
  };
273
 
274
- $.each( $(".as3cf-main-settings form").serializeArray(), function(i,o){
275
  var n = o.name,
276
  v = o.value;
277
- n = n.replace('[]', '');
278
- data[n] = data[n] === undefined ? v
279
- : $.isArray( data[n] ) ? data[n].concat( v )
280
- : [ data[n], v ];
281
- });
282
 
283
  // overwrite the save action stored in the form
284
- data['action'] = 'as3cf-get-url-preview';
285
-
286
- $.ajax({
287
- url: ajaxurl,
288
- type: 'POST',
289
- dataType: 'JSON',
290
- data: data,
291
- error: function(jqXHR, textStatus, errorThrown) {
292
- alert(as3cf_i18n.get_url_preview_error + errorThrown);
293
  },
294
- success: function(data, textStatus, jqXHR) {
295
- if (typeof data['success'] !== 'undefined') {
296
- $('.as3cf-url-preview' ).html( data['url'] );
297
  } else {
298
- alert(as3cf_i18n.get_url_preview_error + data['error']);
299
  }
300
  }
301
- });
 
 
 
 
 
 
 
 
 
 
302
  }
303
 
304
  // save the original state of the form for comparison later
305
- saved_settings = $( '.as3cf-main-settings form' ).serialize();
306
 
307
  // let the save settings submit happen as normal
308
  $( document ).on( 'submit', '.as3cf-main-settings form', function( event ) {
@@ -312,11 +385,11 @@
312
 
313
  // prompt user with dialog if leaving the settings page with unsaved changes
314
  $( window ).on( 'beforeunload.as3cf-settings', function() {
315
- if ( $( '.as3cf-main-settings form' ).serialize() != saved_settings ) {
316
  return as3cf_i18n.save_alert;
317
  }
318
  } );
319
 
320
- });
321
 
322
  })(jQuery);
1
  (function($) {
2
  var saved_settings;
3
 
4
+ $( document ).ready( function() {
5
 
6
+ $( '.as3cf-settings' ).each( function() {
7
+ var $container = $( this );
8
+ var $bucketList = $( '.as3cf-bucket-list' );
9
+ var $createBucketForm = $container.find( '.as3cf-create-bucket-form' );
10
+ var $manualBucketForm = $container.find( '.as3cf-manual-save-bucket-form' );
11
 
12
+ if ( $createBucketForm.length ) {
13
+ var $createBucketButton = $createBucketForm.find( 'button' );
14
+ var origButtonText = $createBucketButton.text();
15
 
16
+ $createBucketForm.on( 'submit', function( e ) {
17
  e.preventDefault();
18
  $( '.as3cf-bucket-error' ).hide();
19
+ $bucketList.addClass( 'saving' );
20
+ $createBucketButton.text( $createBucketButton.attr( 'data-working' ) );
21
+ $createBucketButton.prop( 'disabled', true );
22
+ var bucketName = $createBucketForm.find( 'input[name="bucket_name"]' ).val();
23
 
24
  var data = {
25
+ action : 'as3cf-create-bucket',
26
+ bucket_name: bucketName,
27
+ _nonce : as3cf_i18n.create_bucket_nonce
28
  };
29
 
30
+ $.ajax( {
31
+ url : ajaxurl,
32
+ type : 'POST',
33
+ dataType: 'JSON',
34
+ data : data,
35
+ error : function( jqXHR, textStatus, errorThrown ) {
36
+ $createBucketButton.text( origButtonText );
37
  show_bucket_error( as3cf_i18n.create_bucket_error, errorThrown );
38
  },
39
+ success : function( data, textStatus, jqXHR ) {
40
+ $createBucketButton.text( origButtonText );
41
+ $createBucketButton.prop( 'disabled', false );
42
+ if ( typeof data[ 'success' ] !== 'undefined' ) {
43
+ bucket_select( bucketName, data[ 'region' ], data[ 'can_write' ] );
44
  // tidy up create bucket form
45
+ $createBucketForm.find( 'input[name="bucket_name"]' ).val( '' );
46
+ if ( $( '.as3cf-bucket-list-wrapper' ).is( ':visible' ) ) {
47
+ loadBuckets();
48
+ }
49
+ $( '.as3cf-bucket-list a' ).removeClass( 'selected' );
50
+ $bucketList.removeClass( 'saving' );
51
+ $manualBucketForm.find( 'input[name="bucket_name"]' ).val( bucketName );
52
  } else {
53
+ show_bucket_error( as3cf_i18n.create_bucket_error, data[ 'error' ] );
54
  }
55
  }
56
+ } );
57
+ } );
58
  }
59
 
60
+ if ( $manualBucketForm.length ) {
61
+ var $manualBucketButton = $manualBucketForm.find( 'button' );
62
+ var origManualButtonText = $manualBucketButton.text();
63
+
64
+ $manualBucketForm.on( 'submit', function( e ) {
65
  e.preventDefault();
66
+ var bucketName = $manualBucketForm.find( 'input[name="bucket_name"]' ).val();
67
+ if ( bucketName === $( '.as3cf-active-bucket' ).text() ) {
68
+ $( '.as3cf-bucket-error' ).hide();
69
+ $( '.as3cf-settings' ).addClass( 'as3cf-has-bucket' );
70
+ return;
 
71
  }
72
+ $( '.as3cf-bucket-error' ).hide();
73
+ $manualBucketButton.text( $manualBucketButton.attr( 'data-working' ) );
74
+ $manualBucketButton.prop( 'disabled', true );
75
+
76
+ var data = {
77
+ action : 'as3cf-manual-save-bucket',
78
+ bucket_name: bucketName,
79
+ _nonce : as3cf_i18n.manual_bucket_nonce
80
+ };
81
+
82
+ $.ajax( {
83
+ url : ajaxurl,
84
+ type : 'POST',
85
+ dataType: 'JSON',
86
+ data : data,
87
+ error : function( jqXHR, textStatus, errorThrown ) {
88
+ $manualBucketButton.text( origManualButtonText );
89
+ show_bucket_error( as3cf_i18n.save_bucket_error, errorThrown );
90
+ },
91
+ success : function( data, textStatus, jqXHR ) {
92
+ $manualBucketButton.text( origManualButtonText );
93
+ $manualBucketButton.prop( 'disabled', false );
94
+ if ( typeof data[ 'success' ] !== 'undefined' ) {
95
+ bucket_select( bucketName, data[ 'region' ], data[ 'can_write' ] );
96
+ $( '.as3cf-bucket-list a' ).removeClass( 'selected' );
97
+ } else {
98
+ show_bucket_error( as3cf_i18n.save_bucket_error, data[ 'error' ] );
99
+ }
100
+ }
101
+ } );
102
+ } );
103
+ }
104
+
105
+ var $changeBucket = $container.find( '.as3cf-change-bucket' );
106
+ if ( $changeBucket.length ) {
107
+ $changeBucket.on( 'click', function( e ) {
108
+ e.preventDefault();
109
+ $( '.updated' ).not( '.as3cf-notice' ).hide();
110
+ $( '.as3cf-can-write-error' ).hide();
111
+ $( '.as3cf-settings' ).removeClass( 'as3cf-has-bucket' );
112
+ if ( $( '.as3cf-bucket-list-wrapper' ).is( ':visible' ) ) {
113
+ loadBuckets();
114
+ if ( $( '.as3cf-active-bucket' ).html ) {
115
+ $( '.as3cf-cancel-bucket-select-wrap' ).show();
116
+ }
117
  }
118
+ } );
119
  }
120
 
121
+ var $refreshBuckets = $container.find( '.as3cf-refresh-buckets' );
122
+ if ( $refreshBuckets.length ) {
123
+ $refreshBuckets.on( 'click', function( e ) {
124
  e.preventDefault();
125
  loadBuckets();
126
+ } );
127
  }
128
 
129
+ var $cancelChangeBucket = $container.find( '.as3cf-cancel-bucket-select' );
130
+ if ( $cancelChangeBucket.length ) {
131
+ $cancelChangeBucket.on( 'click', function( e ) {
132
  e.preventDefault();
133
  $( '.as3cf-bucket-error' ).hide();
134
+ $( '.as3cf-settings' ).addClass( 'as3cf-has-bucket' );
135
+ } );
136
  }
137
 
138
+ } );
139
+
140
+ var $bucketList = $( '.as3cf-bucket-list' );
141
 
 
142
  function loadBuckets() {
143
  $( '.as3cf-bucket-error' ).hide();
144
+ $bucketList.html( '<li class="loading">' + $bucketList.attr( 'data-working' ) + '</li>' );
145
 
146
  var data = {
147
  action: 'as3cf-get-buckets',
148
  _nonce: as3cf_i18n.get_buckets_nonce
149
  };
150
 
151
+ $.ajax( {
152
+ url : ajaxurl,
153
+ type : 'POST',
154
+ dataType: 'JSON',
155
+ data : data,
156
+ error : function( jqXHR, textStatus, errorThrown ) {
157
+ $bucketList.html( '' );
158
  show_bucket_error( as3cf_i18n.get_buckets_error, errorThrown );
159
  },
160
+ success : function( data, textStatus, jqXHR ) {
161
+ $bucketList.html( '' );
162
+ if ( typeof data[ 'success' ] !== 'undefined' ) {
163
+ $( data[ 'buckets' ] ).each( function( idx, bucket ) {
164
+ var bucket_class = (
165
+ bucket.Name === data[ 'selected' ]
166
+ ) ? 'selected' : '';
167
+ $bucketList.append( '<li><a class="' + bucket_class + '" href="#" data-bucket="' + bucket.Name + '"><span class="bucket"><span class="dashicons dashicons-portfolio"></span> ' + bucket.Name + '</span><span class="spinner"></span></span></a></li>' );
168
+ } );
169
+ scroll_to_selected_bucket();
170
  } else {
171
  show_bucket_error( as3cf_i18n.get_buckets_error, data[ 'error' ] );
172
  }
173
  }
174
+ } );
175
  }
176
 
177
+ $bucketList.on( 'click', 'a', function( e ) {
178
  e.preventDefault();
179
 
180
+ if ( $( this ).hasClass( 'selected' ) ) {
181
+ $( '.as3cf-settings' ).addClass( 'as3cf-has-bucket' );
182
  return;
183
  }
184
 
185
  var bucket = this;
186
+ var previous_bucket = $( '.as3cf-bucket-list a.selected' ).attr( 'data-bucket' );
187
 
188
+ $( '.as3cf-bucket-list a' ).removeClass( 'selected' );
189
+ $( bucket ).addClass( 'selected' );
190
 
191
+ $bucketList.addClass( 'saving' );
192
+ $( bucket ).find( '.spinner' ).show();
193
+ var bucketName = $( bucket ).attr( 'data-bucket' );
194
 
195
  var data = {
196
+ action : 'as3cf-save-bucket',
197
  bucket_name: bucketName,
198
+ _nonce : as3cf_i18n.save_bucket_nonce
199
  };
200
 
201
+ $.ajax( {
202
+ url : ajaxurl,
203
+ type : 'POST',
204
+ dataType: 'JSON',
205
+ data : data,
206
+ error : function( jqXHR, textStatus, errorThrown ) {
207
+ $bucketList.removeClass( 'saving' );
208
  show_bucket_error( as3cf_i18n.save_bucket_error, errorThrown );
209
+ $( '.as3cf-bucket-list a' ).removeClass( 'selected' );
210
  $( '.as3cf-bucket-list a[data-bucket="' + previous_bucket + '"]' ).addClass( 'selected' );
211
  },
212
+ success : function( data, textStatus, jqXHR ) {
213
+ $( bucket ).find( '.spinner' ).hide();
214
+ $bucketList.removeClass( 'saving' );
215
+ if ( typeof data[ 'success' ] !== 'undefined' ) {
216
+ bucket_select( bucketName, data[ 'region' ], data[ 'can_write' ] );
217
  } else {
218
+ show_bucket_error( as3cf_i18n.save_bucket_error, data[ 'error' ] );
219
+ $( '.as3cf-bucket-list a' ).removeClass( 'selected' );
220
  $( '.as3cf-bucket-list a[data-bucket="' + previous_bucket + '"]' ).addClass( 'selected' );
221
  }
222
  }
223
+ } );
224
+ } );
225
+
226
+ function scroll_to_selected_bucket() {
227
+ if ( ! $( '.as3cf-bucket-list a.selected' ).length ) {
228
+ return;
229
+ }
230
+
231
+ var offset = $( 'ul.as3cf-bucket-list li' ).first().position().top + 150;
232
+
233
+ $( 'ul.as3cf-bucket-list' ).animate( {
234
+ scrollTop: $( 'ul.as3cf-bucket-list li a.selected' ).position().top - offset
235
+ } );
236
+ }
237
 
238
  function show_bucket_error( title, error ) {
239
  $( '.as3cf-bucket-error span.title' ).html( title );
242
  }
243
 
244
  function bucket_select( bucket, region, can_write ) {
245
+ if ( '' === $( '.as3cf-active-bucket' ).text() ) {
246
  // first time bucket select - enable main options by default
247
  set_checkbox( 'copy-to-s3-wrap' );
248
  set_checkbox( 'serve-from-s3-wrap' );
249
  }
250
  $( '.as3cf-active-bucket' ).text( bucket );
251
+ $( 'form.as3cf-manual-save-bucket-form .as3cf-bucket-name' ).val( bucket );
252
  $( '#as3cf-bucket' ).val( bucket );
253
  $( '#as3cf-region' ).val( region );
254
+ $( '.updated' ).not( '.as3cf-notice' ).show();
255
  // check permission on bucket
256
+ if ( can_write === false ) {
257
+ $( '.as3cf-can-write-error' ).show();
258
  }
259
  $( '.as3cf-settings' ).addClass( 'as3cf-has-bucket' );
260
  generate_url_preview();
261
  }
262
 
263
+ $( '.as3cf-switch' ).on( 'click', 'span', function( e ) {
264
+ if ( ! $( this ).parent().hasClass( 'disabled' ) ) {
265
+ var parent_id = $( this ).parent().attr( 'id' );
266
  set_checkbox( parent_id );
267
  }
268
+ } );
269
 
270
  function set_checkbox( checkbox_wrap ) {
271
+ $( '#' + checkbox_wrap + ' span' ).toggleClass( 'checked' );
272
+ var switch_on = $( '#' + checkbox_wrap + ' span.on' ).hasClass( 'checked' );
273
+ var checkbox_name = $( '#' + checkbox_wrap ).data( 'checkbox' );
274
+ var $checkbox = $( 'input#' + checkbox_name );
275
  $checkbox.attr( "checked", switch_on );
276
+ $checkbox.trigger( "change" );
277
  }
278
 
279
  if ( $( '.as3cf-settings' ).length && ! $( '.as3cf-settings' ).hasClass( 'as3cf-has-bucket' ) ) {
280
+ if ( $( '.as3cf-bucket-list-wrapper' ).is( ':visible' ) ) {
281
+ loadBuckets();
282
+ }
 
 
283
  }
284
 
285
+ $( '.as3cf-settings' ).on( 'change', '.sub-toggle', function( e ) {
286
+ var setting = $( this ).attr( 'id' );
287
+ $( '.as3cf-setting.' + setting ).toggleClass( 'hide' );
288
+ } );
 
 
 
289
 
290
+ $( '.as3cf-settings' ).on( 'click', '.as3cf-manual-bucket-toggle', function( e ) {
291
+ e.preventDefault();
292
+ $( '.as3cf-bucket-select' ).addClass( 'manual' );
293
+ } );
294
 
295
+ $( '.as3cf-settings' ).on( 'click', '.as3cf-bucket-list-toggle', function( e ) {
296
+ e.preventDefault();
297
+ loadBuckets();
298
+ $( '.as3cf-bucket-select' ).removeClass( 'manual' );
299
+ $( '.as3cf-cancel-bucket-select-wrap' ).show();
300
+ } );
301
 
302
+ $( '.as3cf-domain' ).on( 'change', 'input[type="radio"]', function( e ) {
303
  var domain = $( 'input:radio[name="domain"]:checked' ).val();
304
+ if ( 'cloudfront' === domain && $( '.as3cf-setting.cloudfront' ).hasClass( 'hide' ) ) {
305
+ $( '.as3cf-setting.cloudfront' ).removeClass( 'hide' );
306
  } else {
307
+ $( '.as3cf-setting.cloudfront' ).addClass( 'hide' );
308
  }
309
+ } );
310
 
311
  $( '.as3cf-ssl' ).on( 'change', 'input[type="radio"]', function( e ) {
312
  var ssl = $( 'input:radio[name="ssl"]:checked' ).val();
313
+ if ( 'https' === ssl ) {
314
  var domain = $( 'input:radio[name="domain"]:checked' ).val();
315
+ if ( 'subdomain' === domain ) {
316
  $( 'input[name="domain"][value="path"]' ).attr( "checked", true );
317
  }
318
  $( '.subdomain-wrap input' ).attr( 'disabled', true );
323
  }
324
  } );
325
 
326
+ $( '.url-preview' ).on( 'change', 'input', function( e ) {
327
  generate_url_preview();
328
+ } );
329
 
330
  function generate_url_preview() {
331
+ $( '.as3cf-url-preview' ).html( 'Generating...' );
332
 
333
  var data = {
334
  _nonce: as3cf_i18n.get_url_preview_nonce
335
  };
336
 
337
+ $.each( $( ".as3cf-main-settings form" ).serializeArray(), function( i, o ) {
338
  var n = o.name,
339
  v = o.value;
340
+ n = n.replace( '[]', '' );
341
+ data[ n ] = data[ n ] === undefined ? v
342
+ : $.isArray( data[ n ] ) ? data[ n ].concat( v )
343
+ : [ data[ n ], v ];
344
+ } );
345
 
346
  // overwrite the save action stored in the form
347
+ data[ 'action' ] = 'as3cf-get-url-preview';
348
+
349
+ $.ajax( {
350
+ url : ajaxurl,
351
+ type : 'POST',
352
+ dataType: 'JSON',
353
+ data : data,
354
+ error : function( jqXHR, textStatus, errorThrown ) {
355
+ alert( as3cf_i18n.get_url_preview_error + errorThrown );
356
  },
357
+ success : function( data, textStatus, jqXHR ) {
358
+ if ( typeof data[ 'success' ] !== 'undefined' ) {
359
+ $( '.as3cf-url-preview' ).html( data[ 'url' ] );
360
  } else {
361
+ alert( as3cf_i18n.get_url_preview_error + data[ 'error' ] );
362
  }
363
  }
364
+ } );
365
+ }
366
+
367
+ /**
368
+ * Return the serialized string of the settings form
369
+ * excluding the bucket and region inputs as they get saved via AJAX
370
+ *
371
+ * @returns {string}
372
+ */
373
+ function serialized_form() {
374
+ return $( '.as3cf-main-settings form' ).find( 'input:not(.no-compare)' ).serialize();
375
  }
376
 
377
  // save the original state of the form for comparison later
378
+ saved_settings = serialized_form();
379
 
380
  // let the save settings submit happen as normal
381
  $( document ).on( 'submit', '.as3cf-main-settings form', function( event ) {
385
 
386
  // prompt user with dialog if leaving the settings page with unsaved changes
387
  $( window ).on( 'beforeunload.as3cf-settings', function() {
388
+ if ( serialized_form() !== saved_settings ) {
389
  return as3cf_i18n.save_alert;
390
  }
391
  } );
392
 
393
+ } );
394
 
395
  })(jQuery);
assets/js/script.min.js CHANGED
@@ -1 +1 @@
1
- !function(a){var b;a(document).ready(function(){function c(){a(".as3cf-bucket-error").hide(),h.html('<li class="loading">'+h.attr("data-working")+"</li>");var b={action:"as3cf-get-buckets",_nonce:as3cf_i18n.get_buckets_nonce};a.ajax({url:ajaxurl,type:"POST",dataType:"JSON",data:b,error:function(a,b,c){h.html(""),d(as3cf_i18n.get_buckets_error,c)},success:function(b){h.html(""),"undefined"!=typeof b.success?a(b.buckets).each(function(a,c){var d=c.Name==b.selected?"selected":"";h.append('<li><a class="'+d+'" href="#" data-bucket="'+c.Name+'"><span class="bucket"><span class="dashicons dashicons-portfolio"></span> '+c.Name+'</span><span class="spinner"></span></span></a></li>')}):d(as3cf_i18n.get_buckets_error,b.error)}})}function d(b,c){a(".as3cf-bucket-error span.title").html(b),a(".as3cf-bucket-error span.message").html(c),a(".as3cf-bucket-error").show()}function e(b,c,d){""==a(".as3cf-active-bucket").text()&&(f("copy-to-s3-wrap"),f("serve-from-s3-wrap")),a(".as3cf-active-bucket").text(b),a("#as3cf-bucket").val(b),a("#as3cf-region").val(c),a(".updated").not(".as3cf-notice").show(),d===!1&&a(".as3cf-can-write-error").show(),a(".as3cf-settings").addClass("as3cf-has-bucket"),g()}function f(b){a("#"+b+" span").toggleClass("checked");var c=a("#"+b+" span.on").hasClass("checked"),d=a("#"+b).data("checkbox"),e=a("input#"+d);e.attr("checked",c),e.trigger("change")}function g(){a(".as3cf-url-preview").html("Generating...");var b={_nonce:as3cf_i18n.get_url_preview_nonce};a.each(a(".as3cf-main-settings form").serializeArray(),function(c,d){var e=d.name,f=d.value;e=e.replace("[]",""),b[e]=void 0===b[e]?f:a.isArray(b[e])?b[e].concat(f):[b[e],f]}),b.action="as3cf-get-url-preview",a.ajax({url:ajaxurl,type:"POST",dataType:"JSON",data:b,error:function(a,b,c){alert(as3cf_i18n.get_url_preview_error+c)},success:function(b){"undefined"!=typeof b.success?a(".as3cf-url-preview").html(b.url):alert(as3cf_i18n.get_url_preview_error+b.error)}})}a(".as3cf-settings").each(function(){var b=a(this),f=a(".as3cf-bucket-list"),g=b.find(".as3cf-create-bucket-form");if(g.length){var h=g.find("button"),i=h.text();g.on("submit",function(b){b.preventDefault(),a(".as3cf-bucket-error").hide(),f.addClass("saving"),h.text(h.attr("data-working")),h.prop("disabled",!0);var j=g.find('input[name="bucket_name"]').val(),k={action:"as3cf-create-bucket",bucket_name:j,_nonce:as3cf_i18n.create_bucket_nonce};a.ajax({url:ajaxurl,type:"POST",dataType:"JSON",data:k,error:function(a,b,c){h.text(i),d(as3cf_i18n.create_bucket_error,c)},success:function(b){h.text(i),h.prop("disabled",!1),"undefined"!=typeof b.success?(e(j,b.region,b.can_write),g.find('input[name="bucket_name"]').val(""),a(".as3cf-bucket-list a").removeClass("selected"),c(),f.removeClass("saving")):d(as3cf_i18n.create_bucket_error,b.error)}})})}var j=b.find(".as3cf-change-bucket");j.length&&j.on("click",function(b){b.preventDefault(),a(".updated").not(".as3cf-notice").hide(),a(".as3cf-can-write-error").hide(),a(".as3cf-settings").removeClass("as3cf-has-bucket"),c(),a(".as3cf-active-bucket").html&&a(".as3cf-cancel-bucket-select-wrap").show(),a(".as3cf-bucket-list a.selected").length&&a(".as3cf-bucket-list").scrollTop(a(".as3cf-bucket-list a.selected").position().top-50)});var k=b.find(".as3cf-refresh-buckets");k.length&&k.on("click",function(a){a.preventDefault(),c()});var l=b.find(".as3cf-cancel-bucket-select");l.length&&l.on("click",function(b){b.preventDefault(),a(".as3cf-bucket-error").hide(),a(".as3cf-settings").addClass("as3cf-has-bucket")})});var h=a(".as3cf-bucket-list");h.on("click","a",function(b){if(b.preventDefault(),a(this).hasClass("selected"))return void a(".as3cf-settings").addClass("as3cf-has-bucket");var c=this,f=a(".as3cf-bucket-list a.selected").attr("data-bucket");a(".as3cf-bucket-list a").removeClass("selected"),a(c).addClass("selected"),h.addClass("saving"),a(c).find(".spinner").show();var g=a(c).attr("data-bucket"),i={action:"as3cf-save-bucket",bucket_name:g,_nonce:as3cf_i18n.save_bucket_nonce};a.ajax({url:ajaxurl,type:"POST",dataType:"JSON",data:i,error:function(b,c,e){h.removeClass("saving"),d(as3cf_i18n.save_bucket_error,e),a(".as3cf-bucket-list a").removeClass("selected"),a('.as3cf-bucket-list a[data-bucket="'+f+'"]').addClass("selected")},success:function(b){a(c).find(".spinner").hide(),h.removeClass("saving"),"undefined"!=typeof b.success?e(g,b.region,b.can_write):(d(as3cf_i18n.save_bucket_error,b.error),a(".as3cf-bucket-list a").removeClass("selected"),a('.as3cf-bucket-list a[data-bucket="'+f+'"]').addClass("selected"))}})}),a(".as3cf-switch").on("click","span",function(){if(!a(this).parent().hasClass("disabled")){var b=a(this).parent().attr("id");f(b)}}),a(".as3cf-settings").length&&!a(".as3cf-settings").hasClass("as3cf-has-bucket")&&c(),a("#copy-to-s3").is(":checked")&&a("tr.advanced-options").show(),a(".as3cf-settings").on("change","#copy-to-s3",function(){a("tr.advanced-options").toggle()}),a("#serve-from-s3").is(":checked")&&a("tr.configure-url").show(),a(".as3cf-settings").on("change","#serve-from-s3",function(){a("tr.configure-url").toggle()}),a(".as3cf-settings").on("change",".sub-toggle",function(){var b=a(this).attr("id");a(".as3cf-setting."+b).toggleClass("hide")}),a(".as3cf-domain").on("change",'input[type="radio"]',function(){var b=a('input:radio[name="domain"]:checked').val();"cloudfront"==b&&a(".as3cf-setting.cloudfront").hasClass("hide")?a(".as3cf-setting.cloudfront").removeClass("hide"):a(".as3cf-setting.cloudfront").addClass("hide")}),a(".as3cf-ssl").on("change",'input[type="radio"]',function(){var b=a('input:radio[name="ssl"]:checked').val();if("https"==b){var c=a('input:radio[name="domain"]:checked').val();"subdomain"==c&&a('input[name="domain"][value="path"]').attr("checked",!0),a(".subdomain-wrap input").attr("disabled",!0),a(".subdomain-wrap").addClass("disabled")}else a(".subdomain-wrap input").removeAttr("disabled"),a(".subdomain-wrap").removeClass("disabled")}),a(".url-preview").on("change","input",function(){g()}),b=a(".as3cf-main-settings form").serialize(),a(document).on("submit",".as3cf-main-settings form",function(){a(window).off("beforeunload.as3cf-settings")}),a(window).on("beforeunload.as3cf-settings",function(){return a(".as3cf-main-settings form").serialize()!=b?as3cf_i18n.save_alert:void 0})})}(jQuery);
1
+ !function(a){var b;a(document).ready(function(){function c(){a(".as3cf-bucket-error").hide(),j.html('<li class="loading">'+j.attr("data-working")+"</li>");var b={action:"as3cf-get-buckets",_nonce:as3cf_i18n.get_buckets_nonce};a.ajax({url:ajaxurl,type:"POST",dataType:"JSON",data:b,error:function(a,b,c){j.html(""),e(as3cf_i18n.get_buckets_error,c)},success:function(b){j.html(""),"undefined"!=typeof b.success?(a(b.buckets).each(function(a,c){var d=c.Name===b.selected?"selected":"";j.append('<li><a class="'+d+'" href="#" data-bucket="'+c.Name+'"><span class="bucket"><span class="dashicons dashicons-portfolio"></span> '+c.Name+'</span><span class="spinner"></span></span></a></li>')}),d()):e(as3cf_i18n.get_buckets_error,b.error)}})}function d(){if(a(".as3cf-bucket-list a.selected").length){var b=a("ul.as3cf-bucket-list li").first().position().top+150;a("ul.as3cf-bucket-list").animate({scrollTop:a("ul.as3cf-bucket-list li a.selected").position().top-b})}}function e(b,c){a(".as3cf-bucket-error span.title").html(b),a(".as3cf-bucket-error span.message").html(c),a(".as3cf-bucket-error").show()}function f(b,c,d){""===a(".as3cf-active-bucket").text()&&(g("copy-to-s3-wrap"),g("serve-from-s3-wrap")),a(".as3cf-active-bucket").text(b),a("form.as3cf-manual-save-bucket-form .as3cf-bucket-name").val(b),a("#as3cf-bucket").val(b),a("#as3cf-region").val(c),a(".updated").not(".as3cf-notice").show(),d===!1&&a(".as3cf-can-write-error").show(),a(".as3cf-settings").addClass("as3cf-has-bucket"),h()}function g(b){a("#"+b+" span").toggleClass("checked");var c=a("#"+b+" span.on").hasClass("checked"),d=a("#"+b).data("checkbox"),e=a("input#"+d);e.attr("checked",c),e.trigger("change")}function h(){a(".as3cf-url-preview").html("Generating...");var b={_nonce:as3cf_i18n.get_url_preview_nonce};a.each(a(".as3cf-main-settings form").serializeArray(),function(c,d){var e=d.name,f=d.value;e=e.replace("[]",""),b[e]=void 0===b[e]?f:a.isArray(b[e])?b[e].concat(f):[b[e],f]}),b.action="as3cf-get-url-preview",a.ajax({url:ajaxurl,type:"POST",dataType:"JSON",data:b,error:function(a,b,c){alert(as3cf_i18n.get_url_preview_error+c)},success:function(b){"undefined"!=typeof b.success?a(".as3cf-url-preview").html(b.url):alert(as3cf_i18n.get_url_preview_error+b.error)}})}function i(){return a(".as3cf-main-settings form").find("input:not(.no-compare)").serialize()}a(".as3cf-settings").each(function(){var b=a(this),d=a(".as3cf-bucket-list"),g=b.find(".as3cf-create-bucket-form"),h=b.find(".as3cf-manual-save-bucket-form");if(g.length){var i=g.find("button"),j=i.text();g.on("submit",function(b){b.preventDefault(),a(".as3cf-bucket-error").hide(),d.addClass("saving"),i.text(i.attr("data-working")),i.prop("disabled",!0);var k=g.find('input[name="bucket_name"]').val(),l={action:"as3cf-create-bucket",bucket_name:k,_nonce:as3cf_i18n.create_bucket_nonce};a.ajax({url:ajaxurl,type:"POST",dataType:"JSON",data:l,error:function(a,b,c){i.text(j),e(as3cf_i18n.create_bucket_error,c)},success:function(b){i.text(j),i.prop("disabled",!1),"undefined"!=typeof b.success?(f(k,b.region,b.can_write),g.find('input[name="bucket_name"]').val(""),a(".as3cf-bucket-list-wrapper").is(":visible")&&c(),a(".as3cf-bucket-list a").removeClass("selected"),d.removeClass("saving"),h.find('input[name="bucket_name"]').val(k)):e(as3cf_i18n.create_bucket_error,b.error)}})})}if(h.length){var k=h.find("button"),l=k.text();h.on("submit",function(b){b.preventDefault();var c=h.find('input[name="bucket_name"]').val();if(c===a(".as3cf-active-bucket").text())return a(".as3cf-bucket-error").hide(),void a(".as3cf-settings").addClass("as3cf-has-bucket");a(".as3cf-bucket-error").hide(),k.text(k.attr("data-working")),k.prop("disabled",!0);var d={action:"as3cf-manual-save-bucket",bucket_name:c,_nonce:as3cf_i18n.manual_bucket_nonce};a.ajax({url:ajaxurl,type:"POST",dataType:"JSON",data:d,error:function(a,b,c){k.text(l),e(as3cf_i18n.save_bucket_error,c)},success:function(b){k.text(l),k.prop("disabled",!1),"undefined"!=typeof b.success?(f(c,b.region,b.can_write),a(".as3cf-bucket-list a").removeClass("selected")):e(as3cf_i18n.save_bucket_error,b.error)}})})}var m=b.find(".as3cf-change-bucket");m.length&&m.on("click",function(b){b.preventDefault(),a(".updated").not(".as3cf-notice").hide(),a(".as3cf-can-write-error").hide(),a(".as3cf-settings").removeClass("as3cf-has-bucket"),a(".as3cf-bucket-list-wrapper").is(":visible")&&(c(),a(".as3cf-active-bucket").html&&a(".as3cf-cancel-bucket-select-wrap").show())});var n=b.find(".as3cf-refresh-buckets");n.length&&n.on("click",function(a){a.preventDefault(),c()});var o=b.find(".as3cf-cancel-bucket-select");o.length&&o.on("click",function(b){b.preventDefault(),a(".as3cf-bucket-error").hide(),a(".as3cf-settings").addClass("as3cf-has-bucket")})});var j=a(".as3cf-bucket-list");j.on("click","a",function(b){if(b.preventDefault(),a(this).hasClass("selected"))return void a(".as3cf-settings").addClass("as3cf-has-bucket");var c=this,d=a(".as3cf-bucket-list a.selected").attr("data-bucket");a(".as3cf-bucket-list a").removeClass("selected"),a(c).addClass("selected"),j.addClass("saving"),a(c).find(".spinner").show();var g=a(c).attr("data-bucket"),h={action:"as3cf-save-bucket",bucket_name:g,_nonce:as3cf_i18n.save_bucket_nonce};a.ajax({url:ajaxurl,type:"POST",dataType:"JSON",data:h,error:function(b,c,f){j.removeClass("saving"),e(as3cf_i18n.save_bucket_error,f),a(".as3cf-bucket-list a").removeClass("selected"),a('.as3cf-bucket-list a[data-bucket="'+d+'"]').addClass("selected")},success:function(b){a(c).find(".spinner").hide(),j.removeClass("saving"),"undefined"!=typeof b.success?f(g,b.region,b.can_write):(e(as3cf_i18n.save_bucket_error,b.error),a(".as3cf-bucket-list a").removeClass("selected"),a('.as3cf-bucket-list a[data-bucket="'+d+'"]').addClass("selected"))}})}),a(".as3cf-switch").on("click","span",function(){if(!a(this).parent().hasClass("disabled")){var b=a(this).parent().attr("id");g(b)}}),a(".as3cf-settings").length&&!a(".as3cf-settings").hasClass("as3cf-has-bucket")&&a(".as3cf-bucket-list-wrapper").is(":visible")&&c(),a(".as3cf-settings").on("change",".sub-toggle",function(){var b=a(this).attr("id");a(".as3cf-setting."+b).toggleClass("hide")}),a(".as3cf-settings").on("click",".as3cf-manual-bucket-toggle",function(b){b.preventDefault(),a(".as3cf-bucket-select").addClass("manual")}),a(".as3cf-settings").on("click",".as3cf-bucket-list-toggle",function(b){b.preventDefault(),c(),a(".as3cf-bucket-select").removeClass("manual"),a(".as3cf-cancel-bucket-select-wrap").show()}),a(".as3cf-domain").on("change",'input[type="radio"]',function(){var b=a('input:radio[name="domain"]:checked').val();"cloudfront"===b&&a(".as3cf-setting.cloudfront").hasClass("hide")?a(".as3cf-setting.cloudfront").removeClass("hide"):a(".as3cf-setting.cloudfront").addClass("hide")}),a(".as3cf-ssl").on("change",'input[type="radio"]',function(){var b=a('input:radio[name="ssl"]:checked').val();if("https"===b){var c=a('input:radio[name="domain"]:checked').val();"subdomain"===c&&a('input[name="domain"][value="path"]').attr("checked",!0),a(".subdomain-wrap input").attr("disabled",!0),a(".subdomain-wrap").addClass("disabled")}else a(".subdomain-wrap input").removeAttr("disabled"),a(".subdomain-wrap").removeClass("disabled")}),a(".url-preview").on("change","input",function(){h()}),b=i(),a(document).on("submit",".as3cf-main-settings form",function(){a(window).off("beforeunload.as3cf-settings")}),a(window).on("beforeunload.as3cf-settings",function(){return i()!==b?as3cf_i18n.save_alert:void 0})})}(jQuery);
assets/package.json CHANGED
@@ -5,6 +5,7 @@
5
  "grunt": "^0.4.4",
6
  "grunt-contrib-uglify": "^0.4.0",
7
  "grunt-contrib-watch": "^0.6.0",
8
- "grunt-contrib-compass": "^0.7.2"
 
9
  }
10
  }
5
  "grunt": "^0.4.4",
6
  "grunt-contrib-uglify": "^0.4.0",
7
  "grunt-contrib-watch": "^0.6.0",
8
+ "grunt-contrib-compass": "^0.7.2",
9
+ "grunt-contrib-jshint": "~0.10.0"
10
  }
11
  }
assets/sass/styles.scss CHANGED
@@ -48,10 +48,6 @@
48
  }
49
  }
50
 
51
- tr.configure-url, tr.advanced-options {
52
- display: none;
53
- }
54
-
55
  .object-prefix-desc {
56
  em {
57
  white-space: nowrap;
@@ -176,6 +172,40 @@
176
  }
177
  }
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  .as3cf-bucket-list-wrapper {
180
  background: #fff;
181
  padding: 15px 20px;
@@ -217,10 +247,8 @@
217
  }
218
  }
219
 
220
- .as3cf-create-bucket-form {
221
- input[type="text"] {
222
- width: 80%;
223
- }
224
  }
225
 
226
  select.bucket {
48
  }
49
  }
50
 
 
 
 
 
51
  .object-prefix-desc {
52
  em {
53
  white-space: nowrap;
172
  }
173
  }
174
 
175
+ .as3cf-bucket-select {
176
+ &.manual {
177
+ .as3cf-manual-bucket-toggle,
178
+ .as3cf-refresh-buckets,
179
+ .as3cf-bucket-list-wrapper {
180
+ display: none;
181
+ }
182
+ .as3cf-bucket-list-toggle,
183
+ .as3cf-manual-save-bucket-wrapper {
184
+ display: block;
185
+ }
186
+
187
+ .as3cf-cancel-bucket-select-wrap {
188
+ &:after {
189
+ content: ""
190
+ }
191
+ }
192
+ }
193
+
194
+ .as3cf-manual-bucket-toggle,
195
+ .as3cf-bucket-list-wrapper {
196
+ display: block;
197
+ }
198
+
199
+ .as3cf-refresh-buckets {
200
+ display: inline;
201
+ }
202
+
203
+ .as3cf-bucket-list-toggle,
204
+ .as3cf-manual-save-bucket-wrapper {
205
+ display: none;
206
+ }
207
+ }
208
+
209
  .as3cf-bucket-list-wrapper {
210
  background: #fff;
211
  padding: 15px 20px;
247
  }
248
  }
249
 
250
+ input[type="text"].as3cf-bucket-name {
251
+ width: 80%;
 
 
252
  }
253
 
254
  select.bucket {
classes/amazon-s3-and-cloudfront.php CHANGED
@@ -2,7 +2,11 @@
2
  use Aws\S3\S3Client;
3
 
4
  class Amazon_S3_And_CloudFront extends AWS_Plugin_Base {
5
- private $aws, $s3client;
 
 
 
 
6
 
7
  const DEFAULT_ACL = 'public-read';
8
  const PRIVATE_ACL = 'private';
@@ -10,24 +14,38 @@ class Amazon_S3_And_CloudFront extends AWS_Plugin_Base {
10
 
11
  const SETTINGS_KEY = 'tantan_wordpress_s3';
12
 
13
- function __construct( $plugin_file_path, $aws ) {
14
- $this->plugin_slug = 'amazon-s3-and-cloudfront';
 
 
 
 
 
15
 
16
  parent::__construct( $plugin_file_path );
17
 
18
  $this->aws = $aws;
19
 
20
- // fire up the plugin upgrade checker
21
- new AS3CF_Upgrade( $this );
22
-
23
- add_action( 'aws_admin_menu', array( $this, 'admin_menu' ) );
24
 
 
 
 
 
 
 
25
  $this->plugin_title = __( 'Amazon S3 and CloudFront', 'as3cf' );
26
  $this->plugin_menu_title = __( 'S3 and CloudFront', 'as3cf' );
27
 
 
 
 
 
28
  add_action( 'wp_ajax_as3cf-get-buckets', array( $this, 'ajax_get_buckets' ) );
29
  add_action( 'wp_ajax_as3cf-save-bucket', array( $this, 'ajax_save_bucket' ) );
30
  add_action( 'wp_ajax_as3cf-create-bucket', array( $this, 'ajax_create_bucket' ) );
 
31
  add_action( 'wp_ajax_as3cf-get-url-preview', array( $this, 'ajax_get_url_preview' ) );
32
 
33
  add_filter( 'wp_get_attachment_url', array( $this, 'wp_get_attachment_url' ), 99, 2 );
@@ -138,13 +156,12 @@ class Amazon_S3_And_CloudFront extends AWS_Plugin_Base {
138
  }
139
 
140
  if ( 'bucket' == $key && defined( 'AS3CF_BUCKET' ) ) {
 
141
  return AS3CF_BUCKET;
142
  }
143
 
144
-
145
  $value = parent::get_setting( $key, $default );
146
 
147
-
148
  return apply_filters( 'as3cf_setting_' . $key, $value );
149
  }
150
 
@@ -326,12 +343,31 @@ class Amazon_S3_And_CloudFront extends AWS_Plugin_Base {
326
  return $data;
327
  }
328
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
  $type = get_post_mime_type( $post_id );
330
  $allowed_types = $this->get_allowed_mime_types();
331
 
332
  // check mime type of file is in allowed S3 mime types
333
  if ( ! in_array( $type, $allowed_types ) ) {
334
- return $data;
335
  }
336
 
337
  $acl = self::DEFAULT_ACL;
@@ -418,8 +454,10 @@ class Amazon_S3_And_CloudFront extends AWS_Plugin_Base {
418
  $s3client->putObject( $args );
419
  }
420
  catch ( Exception $e ) {
421
- error_log( 'Error uploading ' . $file_path . ' to S3: ' . $e->getMessage() );
422
- return $data;
 
 
423
  }
424
  }
425
 
@@ -485,7 +523,7 @@ class Amazon_S3_And_CloudFront extends AWS_Plugin_Base {
485
  $this->remove_local_files( $files_to_remove );
486
  }
487
 
488
- return $data;
489
  }
490
 
491
  function remove_local_files( $file_paths ) {
@@ -1039,11 +1077,12 @@ class Amazon_S3_And_CloudFront extends AWS_Plugin_Base {
1039
  /**
1040
  * Save bucket and bucket's region
1041
  *
1042
- * @param $bucket_name
 
1043
  *
1044
  * @return string|bool|WP_Error Region on success
1045
  */
1046
- function save_bucket( $bucket_name ) {
1047
  if ( $bucket_name ) {
1048
  $this->get_settings();
1049
  // first time bucket select - enable main options by default
@@ -1057,6 +1096,14 @@ class Amazon_S3_And_CloudFront extends AWS_Plugin_Base {
1057
  return false;
1058
  }
1059
  $this->set_setting( 'region', $region );
 
 
 
 
 
 
 
 
1060
  $this->save_settings();
1061
 
1062
  return $region;
@@ -1065,13 +1112,42 @@ class Amazon_S3_And_CloudFront extends AWS_Plugin_Base {
1065
  return false;
1066
  }
1067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1068
  function admin_menu( $aws ) {
1069
  $hook_suffix = $aws->add_page( $this->plugin_title, $this->plugin_menu_title, 'manage_options', $this->plugin_slug, array( $this, 'render_page' ) );
1070
  add_action( 'load-' . $hook_suffix , array( $this, 'plugin_load' ) );
1071
  }
1072
 
1073
- function get_s3client( $region = false ) {
1074
- if ( is_null( $this->s3client ) ) {
 
 
 
 
 
 
 
 
1075
 
1076
  if ( $region ) {
1077
  $args = array(
@@ -1230,7 +1306,7 @@ class Amazon_S3_And_CloudFront extends AWS_Plugin_Base {
1230
  $region = $this->get_setting( 'region' );
1231
  }
1232
  // attempt to create the test file
1233
- $this->get_s3client( $region )->putObject( $args );
1234
  // delete it straight away if created
1235
  $this->get_s3client()->deleteObject( array(
1236
  'Bucket' => $bucket,
@@ -1260,6 +1336,7 @@ class Amazon_S3_And_CloudFront extends AWS_Plugin_Base {
1260
  'create_bucket_prompt' => __( 'Bucket Name:', 'as3cf' ),
1261
  'create_bucket_error' => __( 'Error creating bucket: ', 'as3cf' ),
1262
  'create_bucket_nonce' => wp_create_nonce( 'as3cf-create-bucket' ),
 
1263
  'get_buckets_error' => __( 'Error fetching buckets: ', 'as3cf' ),
1264
  'get_buckets_nonce' => wp_create_nonce( 'as3cf-get-buckets' ),
1265
  'save_bucket_error' => __( 'Error saving bucket: ', 'as3cf' ),
@@ -1281,7 +1358,7 @@ class Amazon_S3_And_CloudFront extends AWS_Plugin_Base {
1281
  die( __( "Cheatin' eh?", 'amazon-web-services' ) );
1282
  }
1283
 
1284
- $post_vars = array( 'domain', 'virtual-host', 'expires', 'permissions', 'cloudfront', 'object-prefix', 'copy-to-s3', 'serve-from-s3', 'remove-local-file', 'ssl', 'hidpi-images', 'object-versioning', 'use-yearmonth-folders', 'enable-object-prefix' );
1285
 
1286
  foreach ( $post_vars as $var ) {
1287
  $this->remove_setting( $var );
@@ -1301,6 +1378,9 @@ class Amazon_S3_And_CloudFront extends AWS_Plugin_Base {
1301
  exit;
1302
  }
1303
 
 
 
 
1304
  function render_page() {
1305
  $this->aws->render_view( 'header', array( 'page_title' => $this->plugin_title ) );
1306
 
@@ -1312,6 +1392,7 @@ class Amazon_S3_And_CloudFront extends AWS_Plugin_Base {
1312
  else {
1313
  do_action( 'as3cf_pre_settings_render' );
1314
  $this->render_view( 'settings' );
 
1315
  }
1316
 
1317
  $this->aws->render_view( 'footer' );
2
  use Aws\S3\S3Client;
3
 
4
  class Amazon_S3_And_CloudFront extends AWS_Plugin_Base {
5
+ private $aws;
6
+ private $s3client;
7
+
8
+ protected $plugin_title;
9
+ protected $plugin_menu_title;
10
 
11
  const DEFAULT_ACL = 'public-read';
12
  const PRIVATE_ACL = 'private';
14
 
15
  const SETTINGS_KEY = 'tantan_wordpress_s3';
16
 
17
+ /**
18
+ * @param string $plugin_file_path
19
+ * @param Amazon_Web_Services $aws
20
+ * @param string|null $slug
21
+ */
22
+ function __construct( $plugin_file_path, $aws, $slug = null ) {
23
+ $this->plugin_slug = ( is_null( $slug ) ) ? 'amazon-s3-and-cloudfront' : $slug;
24
 
25
  parent::__construct( $plugin_file_path );
26
 
27
  $this->aws = $aws;
28
 
29
+ $this->init( $plugin_file_path );
30
+ }
 
 
31
 
32
+ /**
33
+ * Abstract class constructor
34
+ *
35
+ * @param string $plugin_file_path
36
+ */
37
+ function init( $plugin_file_path ) {
38
  $this->plugin_title = __( 'Amazon S3 and CloudFront', 'as3cf' );
39
  $this->plugin_menu_title = __( 'S3 and CloudFront', 'as3cf' );
40
 
41
+ // fire up the plugin upgrade checker
42
+ new AS3CF_Upgrade( $this );
43
+
44
+ add_action( 'aws_admin_menu', array( $this, 'admin_menu' ) );
45
  add_action( 'wp_ajax_as3cf-get-buckets', array( $this, 'ajax_get_buckets' ) );
46
  add_action( 'wp_ajax_as3cf-save-bucket', array( $this, 'ajax_save_bucket' ) );
47
  add_action( 'wp_ajax_as3cf-create-bucket', array( $this, 'ajax_create_bucket' ) );
48
+ add_action( 'wp_ajax_as3cf-manual-save-bucket', array( $this, 'ajax_manual_save_bucket' ) );
49
  add_action( 'wp_ajax_as3cf-get-url-preview', array( $this, 'ajax_get_url_preview' ) );
50
 
51
  add_filter( 'wp_get_attachment_url', array( $this, 'wp_get_attachment_url' ), 99, 2 );
156
  }
157
 
158
  if ( 'bucket' == $key && defined( 'AS3CF_BUCKET' ) ) {
159
+
160
  return AS3CF_BUCKET;
161
  }
162
 
 
163
  $value = parent::get_setting( $key, $default );
164
 
 
165
  return apply_filters( 'as3cf_setting_' . $key, $value );
166
  }
167
 
343
  return $data;
344
  }
345
 
346
+ // upload attachment to S3
347
+ $this->upload_attachment_to_s3( $post_id, $data );
348
+
349
+ return $data;
350
+ }
351
+
352
+ /**
353
+ * Upload attachment to S3
354
+ *
355
+ * @param $post_id
356
+ * @param $data
357
+ *
358
+ * @return array|WP_Error $s3object
359
+ */
360
+ function upload_attachment_to_s3( $post_id, $data = null ) {
361
+ if ( is_null( $data ) ) {
362
+ $data = wp_get_attachment_metadata( $post_id, true );
363
+ }
364
+
365
  $type = get_post_mime_type( $post_id );
366
  $allowed_types = $this->get_allowed_mime_types();
367
 
368
  // check mime type of file is in allowed S3 mime types
369
  if ( ! in_array( $type, $allowed_types ) ) {
370
+ return new WP_Error( 'exception', sprintf( __( 'Mime type %s is not allowed', 'as3cf' ), $type ) );
371
  }
372
 
373
  $acl = self::DEFAULT_ACL;
454
  $s3client->putObject( $args );
455
  }
456
  catch ( Exception $e ) {
457
+ $error_msg = sprintf( __( 'Error uploading %s to S3: %s', 'as3cf' ), $file_path, $e->getMessage() );
458
+ error_log( $error_msg );
459
+
460
+ return new WP_Error( 'exception', $error_msg );
461
  }
462
  }
463
 
523
  $this->remove_local_files( $files_to_remove );
524
  }
525
 
526
+ return $s3object;
527
  }
528
 
529
  function remove_local_files( $file_paths ) {
1077
  /**
1078
  * Save bucket and bucket's region
1079
  *
1080
+ * @param string $bucket_name
1081
+ * @param bool $manual if we are entering the bucket via the manual input form
1082
  *
1083
  * @return string|bool|WP_Error Region on success
1084
  */
1085
+ function save_bucket( $bucket_name, $manual = false ) {
1086
  if ( $bucket_name ) {
1087
  $this->get_settings();
1088
  // first time bucket select - enable main options by default
1096
  return false;
1097
  }
1098
  $this->set_setting( 'region', $region );
1099
+
1100
+ if ( $manual ) {
1101
+ // record that we have entered the bucket via the manual form
1102
+ $this->set_setting( 'manual_bucket', true );
1103
+ } else {
1104
+ $this->remove_setting( 'manual_bucket' );
1105
+ }
1106
+
1107
  $this->save_settings();
1108
 
1109
  return $region;
1112
  return false;
1113
  }
1114
 
1115
+ function ajax_manual_save_bucket() {
1116
+ $this->verify_ajax_request();
1117
+
1118
+ $bucket = $this->ajax_check_bucket();
1119
+
1120
+ $region = $this->save_bucket( $bucket, true );
1121
+
1122
+ if ( $region !== false ) {
1123
+ $out = array(
1124
+ 'success' => '1',
1125
+ 'region' => $region,
1126
+ );
1127
+ $out['can_write'] = $this->check_write_permission( $bucket, $region );
1128
+ } else {
1129
+ $out = array( 'error' => __( 'Failed to retrieve bucket region.', 'as3cf' ) );
1130
+ }
1131
+
1132
+ echo json_encode( $out );
1133
+ exit;
1134
+ }
1135
+
1136
  function admin_menu( $aws ) {
1137
  $hook_suffix = $aws->add_page( $this->plugin_title, $this->plugin_menu_title, 'manage_options', $this->plugin_slug, array( $this, 'render_page' ) );
1138
  add_action( 'load-' . $hook_suffix , array( $this, 'plugin_load' ) );
1139
  }
1140
 
1141
+ /**
1142
+ * Get the S3 client
1143
+ *
1144
+ * @param bool|string $region specify region to client for signature
1145
+ * @param bool $force force return of new S3 client when swapping regions
1146
+ *
1147
+ * @return mixed
1148
+ */
1149
+ function get_s3client( $region = false, $force = false ) {
1150
+ if ( is_null( $this->s3client ) || $force ) {
1151
 
1152
  if ( $region ) {
1153
  $args = array(
1306
  $region = $this->get_setting( 'region' );
1307
  }
1308
  // attempt to create the test file
1309
+ $this->get_s3client( $region, true )->putObject( $args );
1310
  // delete it straight away if created
1311
  $this->get_s3client()->deleteObject( array(
1312
  'Bucket' => $bucket,
1336
  'create_bucket_prompt' => __( 'Bucket Name:', 'as3cf' ),
1337
  'create_bucket_error' => __( 'Error creating bucket: ', 'as3cf' ),
1338
  'create_bucket_nonce' => wp_create_nonce( 'as3cf-create-bucket' ),
1339
+ 'manual_bucket_nonce' => wp_create_nonce( 'as3cf-manual-save-bucket' ),
1340
  'get_buckets_error' => __( 'Error fetching buckets: ', 'as3cf' ),
1341
  'get_buckets_nonce' => wp_create_nonce( 'as3cf-get-buckets' ),
1342
  'save_bucket_error' => __( 'Error saving bucket: ', 'as3cf' ),
1358
  die( __( "Cheatin' eh?", 'amazon-web-services' ) );
1359
  }
1360
 
1361
+ $post_vars = array( 'bucket', 'region', 'domain', 'virtual-host', 'expires', 'permissions', 'cloudfront', 'object-prefix', 'copy-to-s3', 'serve-from-s3', 'remove-local-file', 'ssl', 'hidpi-images', 'object-versioning', 'use-yearmonth-folders', 'enable-object-prefix' );
1362
 
1363
  foreach ( $post_vars as $var ) {
1364
  $this->remove_setting( $var );
1378
  exit;
1379
  }
1380
 
1381
+ /**
1382
+ * Display the main settings page for the plugin
1383
+ */
1384
  function render_page() {
1385
  $this->aws->render_view( 'header', array( 'page_title' => $this->plugin_title ) );
1386
 
1392
  else {
1393
  do_action( 'as3cf_pre_settings_render' );
1394
  $this->render_view( 'settings' );
1395
+ do_action( 'as3cf_post_settings_render' );
1396
  }
1397
 
1398
  $this->aws->render_view( 'footer' );
languages/amazon-s3-and-cloudfront.pot CHANGED
@@ -1,8 +1,8 @@
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: Amazon S3 and CloudFront\n"
4
- "POT-Creation-Date: 2015-01-19 16:02-0000\n"
5
- "PO-Revision-Date: 2015-01-19 16:02-0000\n"
6
  "Last-Translator: Delicious Brains <nom@deliciousbrains.com>\n"
7
  "Language-Team: Delicious Brains <nom@deliciousbrains.com>\n"
8
  "Language: en\n"
@@ -20,71 +20,82 @@ msgstr ""
20
  "X-Poedit-SearchPathExcluded-0: vendor\n"
21
  "X-Poedit-SearchPathExcluded-1: assets\n"
22
 
23
- #: classes/amazon-s3-and-cloudfront.php:25
24
  msgid "Amazon S3 and CloudFront"
25
  msgstr ""
26
 
27
- #: classes/amazon-s3-and-cloudfront.php:26
28
  msgid "S3 and CloudFront"
29
  msgstr ""
30
 
31
- #: classes/amazon-s3-and-cloudfront.php:923
 
 
 
 
 
 
 
 
 
 
32
  msgid "There was an error attempting to access the file system"
33
  msgstr ""
34
 
35
- #: classes/amazon-s3-and-cloudfront.php:963
36
  msgid "Cheatin&#8217; eh?"
37
  msgstr ""
38
 
39
- #: classes/amazon-s3-and-cloudfront.php:967
40
  msgid "You do not have sufficient permissions to access this page."
41
  msgstr ""
42
 
43
- #: classes/amazon-s3-and-cloudfront.php:973
44
  msgid "No bucket name provided."
45
  msgstr ""
46
 
47
- #: classes/amazon-s3-and-cloudfront.php:999
48
- #: classes/amazon-s3-and-cloudfront.php:1032
 
49
  msgid "Failed to retrieve bucket region."
50
  msgstr ""
51
 
52
- #: classes/amazon-s3-and-cloudfront.php:1103
53
  #, php-format
54
  msgid "There was an error attempting to get the region of the bucket %s: %s"
55
  msgstr ""
56
 
57
- #: classes/amazon-s3-and-cloudfront.php:1215
58
  msgid ""
59
  "This is a test file to check if the user has write permission to S3. Delete "
60
  "me if found."
61
  msgstr ""
62
 
63
- #: classes/amazon-s3-and-cloudfront.php:1260
64
  msgid "Bucket Name:"
65
  msgstr ""
66
 
67
- #: classes/amazon-s3-and-cloudfront.php:1261
68
  msgid "Error creating bucket: "
69
  msgstr ""
70
 
71
- #: classes/amazon-s3-and-cloudfront.php:1263
72
  msgid "Error fetching buckets: "
73
  msgstr ""
74
 
75
- #: classes/amazon-s3-and-cloudfront.php:1265
76
  msgid "Error saving bucket: "
77
  msgstr ""
78
 
79
- #: classes/amazon-s3-and-cloudfront.php:1268
80
  msgid "Error getting URL preview: "
81
  msgstr ""
82
 
83
- #: classes/amazon-s3-and-cloudfront.php:1269
84
  msgid "The changes you made will be lost if you navigate away from this page"
85
  msgstr ""
86
 
87
- #: classes/amazon-s3-and-cloudfront.php:1281
88
  msgid "Cheatin' eh?"
89
  msgstr ""
90
 
@@ -217,156 +228,179 @@ msgid "Refresh"
217
  msgstr ""
218
 
219
  #: view/settings.php:60
220
- msgid "Loading..."
 
 
 
221
  msgstr ""
222
 
223
  #: view/settings.php:63
224
- msgid "Or create a new bucket:"
225
  msgstr ""
226
 
227
- #: view/settings.php:66
 
 
 
 
228
  msgid "Bucket Name"
229
  msgstr ""
230
 
231
- #: view/settings.php:67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232
  msgid "Creating..."
233
  msgstr ""
234
 
235
- #: view/settings.php:67
236
  msgid "Create"
237
  msgstr ""
238
 
239
- #: view/settings.php:78
240
  msgid "Bucket"
241
  msgstr ""
242
 
243
- #: view/settings.php:81
244
  msgid "Change"
245
  msgstr ""
246
 
247
- #: view/settings.php:87
248
  msgid "Enable/Disable the Plugin"
249
  msgstr ""
250
 
251
- #: view/settings.php:94
252
  msgid "Copy Files to S3"
253
  msgstr ""
254
 
255
- #: view/settings.php:95
256
  msgid ""
257
  "When a file is uploaded to the Media Library, copy it to S3. Existing files "
258
  "are <em>not</em> copied to S3."
259
  msgstr ""
260
 
261
- #: view/settings.php:103
262
  msgid "Rewrite File URLs"
263
  msgstr ""
264
 
265
- #: view/settings.php:104
266
  msgid ""
267
  "For Media Library files that have been copied to S3, rewrite the URLs so "
268
  "that they are served from S3/CloudFront instead of your server."
269
  msgstr ""
270
 
271
- #: view/settings.php:108
272
  msgid "Configure File URLs"
273
  msgstr ""
274
 
275
- #: view/settings.php:122
276
  msgid "Domain:"
277
  msgstr ""
278
 
279
- #: view/settings.php:168
280
  msgid "Path"
281
  msgstr ""
282
 
283
- #: view/settings.php:170
284
  msgid "By default the path is the same as your local WordPress files:"
285
  msgstr ""
286
 
287
- #: view/settings.php:183
288
  msgid "Year/Month"
289
  msgstr ""
290
 
291
- #: view/settings.php:185
292
  msgid "Add the Year/Month in the URL."
293
  msgstr ""
294
 
295
- #: view/settings.php:191
296
  msgid "SSL"
297
  msgstr ""
298
 
299
- #: view/settings.php:199
300
  msgid "Same as request"
301
  msgstr ""
302
 
303
- #: view/settings.php:200
304
  msgid "When the request is https://, use https:// for the file URL as well."
305
  msgstr ""
306
 
307
- #: view/settings.php:204
308
  msgid "Always SSL"
309
  msgstr ""
310
 
311
- #: view/settings.php:205
312
  msgid "Forces https:// to be used."
313
  msgstr ""
314
 
315
- #: view/settings.php:206
316
  msgid ""
317
  "You cannot use the \"Bucket as a subdomain\" domain option when using SSL."
318
  msgstr ""
319
 
320
- #: view/settings.php:210
321
  msgid "Always non-SSL"
322
  msgstr ""
323
 
324
- #: view/settings.php:211
325
  msgid "Forces http:// to be used."
326
  msgstr ""
327
 
328
- #: view/settings.php:217
329
  msgid "Advanced Options"
330
  msgstr ""
331
 
332
- #: view/settings.php:224
333
  msgid "Remove Files From Server"
334
  msgstr ""
335
 
336
- #: view/settings.php:225
337
  msgid "Once a file has been copied to S3, remove it from the local server."
338
  msgstr ""
339
 
340
- #: view/settings.php:233
341
  msgid "Object Versioning"
342
  msgstr ""
343
 
344
- #: view/settings.php:235
345
  msgid ""
346
  "Append a timestamp to the S3 file path. Recommended when using CloudFront so "
347
  "you don't have to worry about cache invalidation."
348
  msgstr ""
349
 
350
- #: view/settings.php:237 view/settings.php:250
351
  msgid "More info"
352
  msgstr ""
353
 
354
- #: view/settings.php:247
355
  msgid "Far Future Expiration Header"
356
  msgstr ""
357
 
358
- #: view/settings.php:248
359
  msgid ""
360
  "Implements a \"Never Expire\" caching policy for browsers by setting an "
361
  "Expires header for 10 years in the future. Should be used in conjunction "
362
  "with object versioning above."
363
  msgstr ""
364
 
365
- #: view/settings.php:260
366
  msgid "Copy HiDPI (@2x) Images"
367
  msgstr ""
368
 
369
- #: view/settings.php:261
370
  #, php-format
371
  msgid ""
372
  "When uploading a file to S3, checks if there's a file of the same name with "
@@ -374,7 +408,7 @@ msgid ""
374
  "Retina 2x</a> plugin."
375
  msgstr ""
376
 
377
- #: view/settings.php:267
378
  msgid "Save Changes"
379
  msgstr ""
380
 
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: Amazon S3 and CloudFront\n"
4
+ "POT-Creation-Date: 2015-01-29 12:40-0000\n"
5
+ "PO-Revision-Date: 2015-01-29 12:40-0000\n"
6
  "Last-Translator: Delicious Brains <nom@deliciousbrains.com>\n"
7
  "Language-Team: Delicious Brains <nom@deliciousbrains.com>\n"
8
  "Language: en\n"
20
  "X-Poedit-SearchPathExcluded-0: vendor\n"
21
  "X-Poedit-SearchPathExcluded-1: assets\n"
22
 
23
+ #: classes/amazon-s3-and-cloudfront.php:38
24
  msgid "Amazon S3 and CloudFront"
25
  msgstr ""
26
 
27
+ #: classes/amazon-s3-and-cloudfront.php:39
28
  msgid "S3 and CloudFront"
29
  msgstr ""
30
 
31
+ #: classes/amazon-s3-and-cloudfront.php:370
32
+ #, php-format
33
+ msgid "Mime type %s is not allowed"
34
+ msgstr ""
35
+
36
+ #: classes/amazon-s3-and-cloudfront.php:457
37
+ #, php-format
38
+ msgid "Error uploading %s to S3: %s"
39
+ msgstr ""
40
+
41
+ #: classes/amazon-s3-and-cloudfront.php:961
42
  msgid "There was an error attempting to access the file system"
43
  msgstr ""
44
 
45
+ #: classes/amazon-s3-and-cloudfront.php:1001
46
  msgid "Cheatin&#8217; eh?"
47
  msgstr ""
48
 
49
+ #: classes/amazon-s3-and-cloudfront.php:1005
50
  msgid "You do not have sufficient permissions to access this page."
51
  msgstr ""
52
 
53
+ #: classes/amazon-s3-and-cloudfront.php:1011
54
  msgid "No bucket name provided."
55
  msgstr ""
56
 
57
+ #: classes/amazon-s3-and-cloudfront.php:1037
58
+ #: classes/amazon-s3-and-cloudfront.php:1070
59
+ #: classes/amazon-s3-and-cloudfront.php:1129
60
  msgid "Failed to retrieve bucket region."
61
  msgstr ""
62
 
63
+ #: classes/amazon-s3-and-cloudfront.php:1179
64
  #, php-format
65
  msgid "There was an error attempting to get the region of the bucket %s: %s"
66
  msgstr ""
67
 
68
+ #: classes/amazon-s3-and-cloudfront.php:1291
69
  msgid ""
70
  "This is a test file to check if the user has write permission to S3. Delete "
71
  "me if found."
72
  msgstr ""
73
 
74
+ #: classes/amazon-s3-and-cloudfront.php:1336
75
  msgid "Bucket Name:"
76
  msgstr ""
77
 
78
+ #: classes/amazon-s3-and-cloudfront.php:1337
79
  msgid "Error creating bucket: "
80
  msgstr ""
81
 
82
+ #: classes/amazon-s3-and-cloudfront.php:1340
83
  msgid "Error fetching buckets: "
84
  msgstr ""
85
 
86
+ #: classes/amazon-s3-and-cloudfront.php:1342
87
  msgid "Error saving bucket: "
88
  msgstr ""
89
 
90
+ #: classes/amazon-s3-and-cloudfront.php:1345
91
  msgid "Error getting URL preview: "
92
  msgstr ""
93
 
94
+ #: classes/amazon-s3-and-cloudfront.php:1346
95
  msgid "The changes you made will be lost if you navigate away from this page"
96
  msgstr ""
97
 
98
+ #: classes/amazon-s3-and-cloudfront.php:1358
99
  msgid "Cheatin' eh?"
100
  msgstr ""
101
 
228
  msgstr ""
229
 
230
  #: view/settings.php:60
231
+ msgid ""
232
+ "You can enter a bucket manually to avoid listing the buckets available. This "
233
+ "can be helpful if you have an IAM policy that does not allow bucket listing "
234
+ "or you have a large amount of buckets to load."
235
  msgstr ""
236
 
237
  #: view/settings.php:63
238
+ msgid "Enter Bucket"
239
  msgstr ""
240
 
241
+ #: view/settings.php:64
242
+ msgid "Select Bucket"
243
+ msgstr ""
244
+
245
+ #: view/settings.php:68 view/settings.php:79
246
  msgid "Bucket Name"
247
  msgstr ""
248
 
249
+ #: view/settings.php:69
250
+ msgid "Saving..."
251
+ msgstr ""
252
+
253
+ #: view/settings.php:69
254
+ msgid "Save"
255
+ msgstr ""
256
+
257
+ #: view/settings.php:73
258
+ msgid "Loading..."
259
+ msgstr ""
260
+
261
+ #: view/settings.php:76
262
+ msgid "Or create a new bucket:"
263
+ msgstr ""
264
+
265
+ #: view/settings.php:80
266
  msgid "Creating..."
267
  msgstr ""
268
 
269
+ #: view/settings.php:80
270
  msgid "Create"
271
  msgstr ""
272
 
273
+ #: view/settings.php:91
274
  msgid "Bucket"
275
  msgstr ""
276
 
277
+ #: view/settings.php:95
278
  msgid "Change"
279
  msgstr ""
280
 
281
+ #: view/settings.php:102
282
  msgid "Enable/Disable the Plugin"
283
  msgstr ""
284
 
285
+ #: view/settings.php:109
286
  msgid "Copy Files to S3"
287
  msgstr ""
288
 
289
+ #: view/settings.php:110
290
  msgid ""
291
  "When a file is uploaded to the Media Library, copy it to S3. Existing files "
292
  "are <em>not</em> copied to S3."
293
  msgstr ""
294
 
295
+ #: view/settings.php:118
296
  msgid "Rewrite File URLs"
297
  msgstr ""
298
 
299
+ #: view/settings.php:119
300
  msgid ""
301
  "For Media Library files that have been copied to S3, rewrite the URLs so "
302
  "that they are served from S3/CloudFront instead of your server."
303
  msgstr ""
304
 
305
+ #: view/settings.php:123
306
  msgid "Configure File URLs"
307
  msgstr ""
308
 
309
+ #: view/settings.php:137
310
  msgid "Domain:"
311
  msgstr ""
312
 
313
+ #: view/settings.php:183
314
  msgid "Path"
315
  msgstr ""
316
 
317
+ #: view/settings.php:185
318
  msgid "By default the path is the same as your local WordPress files:"
319
  msgstr ""
320
 
321
+ #: view/settings.php:198
322
  msgid "Year/Month"
323
  msgstr ""
324
 
325
+ #: view/settings.php:200
326
  msgid "Add the Year/Month in the URL."
327
  msgstr ""
328
 
329
+ #: view/settings.php:206
330
  msgid "SSL"
331
  msgstr ""
332
 
333
+ #: view/settings.php:214
334
  msgid "Same as request"
335
  msgstr ""
336
 
337
+ #: view/settings.php:215
338
  msgid "When the request is https://, use https:// for the file URL as well."
339
  msgstr ""
340
 
341
+ #: view/settings.php:219
342
  msgid "Always SSL"
343
  msgstr ""
344
 
345
+ #: view/settings.php:220
346
  msgid "Forces https:// to be used."
347
  msgstr ""
348
 
349
+ #: view/settings.php:221
350
  msgid ""
351
  "You cannot use the \"Bucket as a subdomain\" domain option when using SSL."
352
  msgstr ""
353
 
354
+ #: view/settings.php:225
355
  msgid "Always non-SSL"
356
  msgstr ""
357
 
358
+ #: view/settings.php:226
359
  msgid "Forces http:// to be used."
360
  msgstr ""
361
 
362
+ #: view/settings.php:232
363
  msgid "Advanced Options"
364
  msgstr ""
365
 
366
+ #: view/settings.php:239
367
  msgid "Remove Files From Server"
368
  msgstr ""
369
 
370
+ #: view/settings.php:240
371
  msgid "Once a file has been copied to S3, remove it from the local server."
372
  msgstr ""
373
 
374
+ #: view/settings.php:248
375
  msgid "Object Versioning"
376
  msgstr ""
377
 
378
+ #: view/settings.php:250
379
  msgid ""
380
  "Append a timestamp to the S3 file path. Recommended when using CloudFront so "
381
  "you don't have to worry about cache invalidation."
382
  msgstr ""
383
 
384
+ #: view/settings.php:252 view/settings.php:265
385
  msgid "More info"
386
  msgstr ""
387
 
388
+ #: view/settings.php:262
389
  msgid "Far Future Expiration Header"
390
  msgstr ""
391
 
392
+ #: view/settings.php:263
393
  msgid ""
394
  "Implements a \"Never Expire\" caching policy for browsers by setting an "
395
  "Expires header for 10 years in the future. Should be used in conjunction "
396
  "with object versioning above."
397
  msgstr ""
398
 
399
+ #: view/settings.php:275
400
  msgid "Copy HiDPI (@2x) Images"
401
  msgstr ""
402
 
403
+ #: view/settings.php:276
404
  #, php-format
405
  msgid ""
406
  "When uploading a file to S3, checks if there's a file of the same name with "
408
  "Retina 2x</a> plugin."
409
  msgstr ""
410
 
411
+ #: view/settings.php:282
412
  msgid "Save Changes"
413
  msgstr ""
414
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: bradt
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5VPMGLLK94XJC
4
  Tags: uploads, amazon, s3, mirror, admin, media, cdn, cloudfront
5
  Requires at least: 3.5
6
- Tested up to: 4.1
7
- Stable tag: 0.8.1
8
  License: GPLv3
9
 
10
  Copies files to Amazon S3 as they are uploaded to the Media Library. Optionally configure Amazon CloudFront for faster delivery.
@@ -59,6 +59,12 @@ This version requires PHP 5.3.3+ and the Amazon Web Services plugin
59
 
60
  == Changelog ==
61
 
 
 
 
 
 
 
62
  = 0.8.1 - 2015-01-19 =
63
  * Bug Fix: Permission problems on installs running on EC2s
64
  * Bug Fix: Blank settings page due to WP_Error on S3 permission check
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5VPMGLLK94XJC
4
  Tags: uploads, amazon, s3, mirror, admin, media, cdn, cloudfront
5
  Requires at least: 3.5
6
+ Tested up to: 4.2
7
+ Stable tag: 0.8.2
8
  License: GPLv3
9
 
10
  Copies files to Amazon S3 as they are uploaded to the Media Library. Optionally configure Amazon CloudFront for faster delivery.
59
 
60
  == Changelog ==
61
 
62
+ = 0.8.2 - 2015-01-31 =
63
+ * New: Input bucket in settings to avoid listing all buckets
64
+ * New: Specify bucket with 'AS3CF_BUCKET' constant
65
+ * Improvement: Compatibility with beta release of Pro plugin
66
+ * Bug Fix: Incorrect file prefix in S3 permission check
67
+
68
  = 0.8.1 - 2015-01-19 =
69
  * Bug Fix: Permission problems on installs running on EC2s
70
  * Bug Fix: Blank settings page due to WP_Error on S3 permission check
view/settings.php CHANGED
@@ -47,8 +47,8 @@ if ( is_wp_error( $can_write ) ) {
47
  ]
48
  }</code></pre>
49
  </div>
50
-
51
- <div class="as3cf-bucket-select">
52
  <h3><?php _e( 'Select an existing S3 bucket to use:', 'as3cf' ); ?></h3>
53
  <div class="as3cf-bucket-actions">
54
  <span class="as3cf-cancel-bucket-select-wrap">
@@ -56,6 +56,19 @@ if ( is_wp_error( $can_write ) ) {
56
  </span>
57
  <a href="#" class="as3cf-refresh-buckets"><?php _e( 'Refresh', 'as3cf' ); ?></a>
58
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  <div class="as3cf-bucket-list-wrapper">
60
  <ul class="as3cf-bucket-list" data-working="<?php _e( 'Loading...', 'as3cf' ); ?>">
61
  </ul>
@@ -63,7 +76,7 @@ if ( is_wp_error( $can_write ) ) {
63
  <h3><?php _e( 'Or create a new bucket:', 'as3cf' ); ?></h3>
64
  <form method="post" class="as3cf-create-bucket-form">
65
  <?php wp_nonce_field( 'as3cf-save-settings' ) ?>
66
- <input type="text" name="bucket_name" placeholder="<?php _e( 'Bucket Name', 'as3cf' ); ?>">
67
  <button type="submit" class="button" data-working="<?php _e( 'Creating...', 'as3cf' ); ?>"><?php _e( 'Create', 'as3cf' ); ?></button>
68
  </form>
69
  </div>
@@ -78,9 +91,11 @@ if ( is_wp_error( $can_write ) ) {
78
  <td><h3><?php _e( 'Bucket', 'as3cf' ); ?></h3></td>
79
  <td>
80
  <span class="as3cf-active-bucket"><?php echo $selected_bucket; // xss ok ?></span>
81
- <a href="#" class="as3cf-change-bucket"><?php _e( 'Change', 'as3cf' ); ?></a>
82
- <input id="as3cf-bucket" type="hidden" name="bucket" value="<?php echo esc_attr( $selected_bucket ); ?>">
83
- <input id="as3cf-region" type="hidden" name="region" value="<?php echo esc_attr( $this->get_setting( 'region' ) ); ?>">
 
 
84
  </td>
85
  </tr>
86
  <tr>
47
  ]
48
  }</code></pre>
49
  </div>
50
+ <?php $bucket_toggle_class = $this->get_setting( 'manual_bucket' ) ? 'manual' : ''; ?>
51
+ <div class="as3cf-bucket-select <?php echo $bucket_toggle_class; ?>">
52
  <h3><?php _e( 'Select an existing S3 bucket to use:', 'as3cf' ); ?></h3>
53
  <div class="as3cf-bucket-actions">
54
  <span class="as3cf-cancel-bucket-select-wrap">
56
  </span>
57
  <a href="#" class="as3cf-refresh-buckets"><?php _e( 'Refresh', 'as3cf' ); ?></a>
58
  </div>
59
+ <p>
60
+ <?php _e( 'You can enter a bucket manually to avoid listing the buckets available. This can be helpful if you have an IAM policy that does not allow bucket listing or you have a large amount of buckets to load.', 'as3cf' ); ?>
61
+ </p>
62
+ <p>
63
+ <a href="#" class="as3cf-manual-bucket-toggle"> <?php _e( 'Enter Bucket', 'as3cf' ); ?></a>
64
+ <a href="#" class="as3cf-bucket-list-toggle"><?php _e( 'Select Bucket', 'as3cf' ); ?></a>
65
+ </p>
66
+ <div class="as3cf-manual-save-bucket-wrapper">
67
+ <form method="post" class="as3cf-manual-save-bucket-form">
68
+ <input type="text" class="as3cf-bucket-name" name="bucket_name" placeholder="<?php _e( 'Bucket Name', 'as3cf' ); ?>" value="<?php echo $selected_bucket; ?>">
69
+ <button type="submit" class="button" data-working="<?php _e( 'Saving...', 'as3cf' ); ?>"><?php _e( 'Save', 'as3cf' ); ?></button>
70
+ </form>
71
+ </div>
72
  <div class="as3cf-bucket-list-wrapper">
73
  <ul class="as3cf-bucket-list" data-working="<?php _e( 'Loading...', 'as3cf' ); ?>">
74
  </ul>
76
  <h3><?php _e( 'Or create a new bucket:', 'as3cf' ); ?></h3>
77
  <form method="post" class="as3cf-create-bucket-form">
78
  <?php wp_nonce_field( 'as3cf-save-settings' ) ?>
79
+ <input type="text" class="as3cf-bucket-name" name="bucket_name" placeholder="<?php _e( 'Bucket Name', 'as3cf' ); ?>">
80
  <button type="submit" class="button" data-working="<?php _e( 'Creating...', 'as3cf' ); ?>"><?php _e( 'Create', 'as3cf' ); ?></button>
81
  </form>
82
  </div>
91
  <td><h3><?php _e( 'Bucket', 'as3cf' ); ?></h3></td>
92
  <td>
93
  <span class="as3cf-active-bucket"><?php echo $selected_bucket; // xss ok ?></span>
94
+ <?php if ( ! defined( 'AS3CF_BUCKET' ) ) : ?>
95
+ <a href="#" class="as3cf-change-bucket"><?php _e( 'Change', 'as3cf' ); ?></a>
96
+ <?php endif; ?>
97
+ <input id="as3cf-bucket" type="hidden" class="no-compare" name="bucket" value="<?php echo esc_attr( $selected_bucket ); ?>">
98
+ <input id="as3cf-region" type="hidden" class="no-compare" name="region" value="<?php echo esc_attr( $this->get_setting( 'region' ) ); ?>">
99
  </td>
100
  </tr>
101
  <tr>
view/sidebar.php CHANGED
@@ -8,14 +8,14 @@
8
  <?php $user = wp_get_current_user(); ?>
9
 
10
  <p class="intro">
11
- <?php echo esc_html( wptexturize( __( "We're working on a pro version that will include the following features:", 'as3cf' ) ) ); ?>
12
  </p>
13
 
14
  <ul>
15
- <li><?php echo esc_html( wptexturize( __( 'Copy existing Media Library to S3', 'as3cf' ) ) ); ?></li>
16
- <li><?php echo esc_html( wptexturize( __( 'Serve theme JS & CSS from S3/CloudFront', 'as3cf' ) ) ); ?></li>
17
- <li><?php echo esc_html( wptexturize( __( 'WooCommerce & <abbr title="Easy Digital Downloads">EDD</abbr> integration', 'as3cf' ) ) ); ?></li>
18
- <li><?php echo esc_html( wptexturize( __( 'Awesome email support', 'as3cf' ) ) ); ?></li>
19
  </ul>
20
 
21
  <div class="field notify-name">
8
  <?php $user = wp_get_current_user(); ?>
9
 
10
  <p class="intro">
11
+ <?php echo wptexturize( __( "We're working on a pro version that will include the following features:", 'as3cf' ) ); // xss ok ?>
12
  </p>
13
 
14
  <ul>
15
+ <li><?php echo wptexturize( __( 'Copy existing Media Library to S3', 'as3cf' ) ); // xss ok ?></li>
16
+ <li><?php echo wptexturize( __( 'Serve theme JS & CSS from S3/CloudFront', 'as3cf' ) ); // xss ok ?></li>
17
+ <li><?php echo wptexturize( __( 'WooCommerce & <abbr title="Easy Digital Downloads">EDD</abbr> integration', 'as3cf' ) ); // xss ok ?></li>
18
+ <li><?php echo wptexturize( __( 'Awesome email support', 'as3cf' ) ); // xss ok ?></li>
19
  </ul>
20
 
21
  <div class="field notify-name">
wordpress-s3.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Amazon S3 and CloudFront
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: Brad Touesnard
7
- Version: 0.8.1
8
  Author URI: http://bradt.ca
9
  Network: True
10
  Text Domain: as3cf
@@ -26,10 +26,11 @@ Domain Path: /languages/
26
  // Then completely rewritten.
27
  */
28
 
29
- $GLOBALS['aws_meta']['amazon-s3-and-cloudfront']['version'] = '0.8.1';
30
 
31
  $GLOBALS['aws_meta']['amazon-s3-and-cloudfront']['supported_addon_versions'] = array(
32
- 'amazon-s3-and-cloudfront-edd' => '1.0',
 
33
  );
34
 
35
  $aws_plugin_version_required = '0.2.2';
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: Brad Touesnard
7
+ Version: 0.8.2
8
  Author URI: http://bradt.ca
9
  Network: True
10
  Text Domain: as3cf
26
  // Then completely rewritten.
27
  */
28
 
29
+ $GLOBALS['aws_meta']['amazon-s3-and-cloudfront']['version'] = '0.8.2';
30
 
31
  $GLOBALS['aws_meta']['amazon-s3-and-cloudfront']['supported_addon_versions'] = array(
32
+ 'amazon-s3-and-cloudfront-edd' => '1.0.1',
33
+ 'amazon-s3-and-cloudfront-pro' => '0.9',
34
  );
35
 
36
  $aws_plugin_version_required = '0.2.2';