From 54a3e2840fb27e54c5ebb7b2d46061bac1c1b16c Mon Sep 17 00:00:00 2001 From: Brad Touesnard Date: Fri, 30 Jan 2015 17:01:27 -0400 Subject: [PATCH] Deploying version 0.8.2 --- assets/.jshintrc | 21 ++ assets/Gruntfile.js | 13 +- assets/css/styles.css | 2 +- assets/js/script.js | 407 +++++++++++++++---------- assets/js/script.min.js | 2 +- assets/package.json | 3 +- assets/sass/styles.scss | 44 ++- classes/amazon-s3-and-cloudfront.php | 119 ++++++-- languages/amazon-s3-and-cloudfront.pot | 146 +++++---- readme.txt | 8 +- view/settings.php | 27 +- view/sidebar.php | 10 +- wordpress-s3.php | 7 +- 13 files changed, 540 insertions(+), 269 deletions(-) create mode 100644 assets/.jshintrc diff --git a/assets/.jshintrc b/assets/.jshintrc new file mode 100644 index 00000000..35162bb7 --- /dev/null +++ b/assets/.jshintrc @@ -0,0 +1,21 @@ +{ + "boss": true, + "browser": true, + "curly": true, + "devel": true, + "eqeqeq": true, + "eqnull": true, + "es3": false, + "immed": true, + "jquery": true, + "latedef": true, + "maxerr": 10000, + "newcap": true, + "noarg": true, + "sub": true, + "undef": true, + "globals": { + "ajaxurl": true, + "as3cf_i18n": true + } +} \ No newline at end of file diff --git a/assets/Gruntfile.js b/assets/Gruntfile.js index e79d497d..7013d6cc 100644 --- a/assets/Gruntfile.js +++ b/assets/Gruntfile.js @@ -2,6 +2,16 @@ module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), + jshint: { + all: [ + 'js/*.js', + '!js/*.min.js' + ], + options: { + jshintrc: '.jshintrc', + force: true + } + }, uglify: { build: { files: { @@ -27,10 +37,11 @@ module.exports = function(grunt) { } }); + grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-compass'); - grunt.registerTask('default', ['uglify','compass']); + grunt.registerTask('default', ['jshint','uglify','compass']); }; diff --git a/assets/css/styles.css b/assets/css/styles.css index c9719edd..0892879b 100644 --- a/assets/css/styles.css +++ b/assets/css/styles.css @@ -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}} +.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}} diff --git a/assets/js/script.js b/assets/js/script.js index be4c42c3..67a2de8c 100644 --- a/assets/js/script.js +++ b/assets/js/script.js @@ -1,175 +1,239 @@ (function($) { var saved_settings; - $(document).ready(function() { + $( document ).ready( function() { - $('.as3cf-settings').each(function() { - var $container = $(this); - var $bucketList = $('.as3cf-bucket-list'); - var $createBucketForm = $container.find('.as3cf-create-bucket-form'); + $( '.as3cf-settings' ).each( function() { + var $container = $( this ); + var $bucketList = $( '.as3cf-bucket-list' ); + var $createBucketForm = $container.find( '.as3cf-create-bucket-form' ); + var $manualBucketForm = $container.find( '.as3cf-manual-save-bucket-form' ); - if($createBucketForm.length){ - var $createBucketButton = $createBucketForm.find('button'), - origButtonText = $createBucketButton.text(); + if ( $createBucketForm.length ) { + var $createBucketButton = $createBucketForm.find( 'button' ); + var origButtonText = $createBucketButton.text(); - $createBucketForm.on('submit', function(e){ + $createBucketForm.on( 'submit', function( e ) { e.preventDefault(); $( '.as3cf-bucket-error' ).hide(); - $bucketList.addClass('saving'); - $createBucketButton.text($createBucketButton.attr('data-working')); - $createBucketButton.prop('disabled', true); - var bucketName = $createBucketForm.find('input[name="bucket_name"]').val(); + $bucketList.addClass( 'saving' ); + $createBucketButton.text( $createBucketButton.attr( 'data-working' ) ); + $createBucketButton.prop( 'disabled', true ); + var bucketName = $createBucketForm.find( 'input[name="bucket_name"]' ).val(); var data = { - action: 'as3cf-create-bucket', - bucket_name: bucketName, - _nonce: as3cf_i18n.create_bucket_nonce + action : 'as3cf-create-bucket', + bucket_name: bucketName, + _nonce : as3cf_i18n.create_bucket_nonce }; - $.ajax({ - url: ajaxurl, - type: 'POST', - dataType: 'JSON', - data: data, - error: function(jqXHR, textStatus, errorThrown) { - $createBucketButton.text(origButtonText); + $.ajax( { + url : ajaxurl, + type : 'POST', + dataType: 'JSON', + data : data, + error : function( jqXHR, textStatus, errorThrown ) { + $createBucketButton.text( origButtonText ); show_bucket_error( as3cf_i18n.create_bucket_error, errorThrown ); }, - success: function(data, textStatus, jqXHR) { - $createBucketButton.text(origButtonText); - $createBucketButton.prop('disabled', false); - if (typeof data['success'] !== 'undefined') { - bucket_select( bucketName, data['region'], data['can_write'] ); + success : function( data, textStatus, jqXHR ) { + $createBucketButton.text( origButtonText ); + $createBucketButton.prop( 'disabled', false ); + if ( typeof data[ 'success' ] !== 'undefined' ) { + bucket_select( bucketName, data[ 'region' ], data[ 'can_write' ] ); // tidy up create bucket form - $createBucketForm.find('input[name="bucket_name"]').val(''); - $('.as3cf-bucket-list a' ).removeClass('selected'); - loadBuckets(); - $bucketList.removeClass('saving'); + $createBucketForm.find( 'input[name="bucket_name"]' ).val( '' ); + if ( $( '.as3cf-bucket-list-wrapper' ).is( ':visible' ) ) { + loadBuckets(); + } + $( '.as3cf-bucket-list a' ).removeClass( 'selected' ); + $bucketList.removeClass( 'saving' ); + $manualBucketForm.find( 'input[name="bucket_name"]' ).val( bucketName ); } else { - show_bucket_error( as3cf_i18n.create_bucket_error, data['error'] ); + show_bucket_error( as3cf_i18n.create_bucket_error, data[ 'error' ] ); } } - }); - }); + } ); + } ); } - var $changeBucket = $container.find('.as3cf-change-bucket'); - if($changeBucket.length){ - $changeBucket.on('click', function(e){ + if ( $manualBucketForm.length ) { + var $manualBucketButton = $manualBucketForm.find( 'button' ); + var origManualButtonText = $manualBucketButton.text(); + + $manualBucketForm.on( 'submit', function( e ) { e.preventDefault(); - $( '.updated' ).not('.as3cf-notice').hide(); - $('.as3cf-can-write-error').hide(); - $('.as3cf-settings').removeClass('as3cf-has-bucket'); - loadBuckets(); - if ( $('.as3cf-active-bucket' ).html ) { - $('.as3cf-cancel-bucket-select-wrap' ).show(); + var bucketName = $manualBucketForm.find( 'input[name="bucket_name"]' ).val(); + if ( bucketName === $( '.as3cf-active-bucket' ).text() ) { + $( '.as3cf-bucket-error' ).hide(); + $( '.as3cf-settings' ).addClass( 'as3cf-has-bucket' ); + return; } - if ( $( '.as3cf-bucket-list a.selected' ).length ) { - $( '.as3cf-bucket-list' ).scrollTop( $( '.as3cf-bucket-list a.selected' ).position().top - 50 ); + $( '.as3cf-bucket-error' ).hide(); + $manualBucketButton.text( $manualBucketButton.attr( 'data-working' ) ); + $manualBucketButton.prop( 'disabled', true ); + + var data = { + action : 'as3cf-manual-save-bucket', + bucket_name: bucketName, + _nonce : as3cf_i18n.manual_bucket_nonce + }; + + $.ajax( { + url : ajaxurl, + type : 'POST', + dataType: 'JSON', + data : data, + error : function( jqXHR, textStatus, errorThrown ) { + $manualBucketButton.text( origManualButtonText ); + show_bucket_error( as3cf_i18n.save_bucket_error, errorThrown ); + }, + success : function( data, textStatus, jqXHR ) { + $manualBucketButton.text( origManualButtonText ); + $manualBucketButton.prop( 'disabled', false ); + if ( typeof data[ 'success' ] !== 'undefined' ) { + bucket_select( bucketName, data[ 'region' ], data[ 'can_write' ] ); + $( '.as3cf-bucket-list a' ).removeClass( 'selected' ); + } else { + show_bucket_error( as3cf_i18n.save_bucket_error, data[ 'error' ] ); + } + } + } ); + } ); + } + + var $changeBucket = $container.find( '.as3cf-change-bucket' ); + if ( $changeBucket.length ) { + $changeBucket.on( 'click', function( e ) { + e.preventDefault(); + $( '.updated' ).not( '.as3cf-notice' ).hide(); + $( '.as3cf-can-write-error' ).hide(); + $( '.as3cf-settings' ).removeClass( 'as3cf-has-bucket' ); + if ( $( '.as3cf-bucket-list-wrapper' ).is( ':visible' ) ) { + loadBuckets(); + if ( $( '.as3cf-active-bucket' ).html ) { + $( '.as3cf-cancel-bucket-select-wrap' ).show(); + } } - }); + } ); } - var $refreshBuckets = $container.find('.as3cf-refresh-buckets'); - if($refreshBuckets.length){ - $refreshBuckets.on('click', function(e){ + var $refreshBuckets = $container.find( '.as3cf-refresh-buckets' ); + if ( $refreshBuckets.length ) { + $refreshBuckets.on( 'click', function( e ) { e.preventDefault(); loadBuckets(); - }); + } ); } - var $cancelChangeBucket = $container.find('.as3cf-cancel-bucket-select'); - if($cancelChangeBucket.length){ - $cancelChangeBucket.on('click', function(e){ + var $cancelChangeBucket = $container.find( '.as3cf-cancel-bucket-select' ); + if ( $cancelChangeBucket.length ) { + $cancelChangeBucket.on( 'click', function( e ) { e.preventDefault(); $( '.as3cf-bucket-error' ).hide(); - $('.as3cf-settings').addClass('as3cf-has-bucket'); - }); + $( '.as3cf-settings' ).addClass( 'as3cf-has-bucket' ); + } ); } - }); + } ); + + var $bucketList = $( '.as3cf-bucket-list' ); - var $bucketList = $('.as3cf-bucket-list'); function loadBuckets() { $( '.as3cf-bucket-error' ).hide(); - $bucketList.html('
  • '+ $bucketList.attr('data-working') +'
  • '); + $bucketList.html( '
  • ' + $bucketList.attr( 'data-working' ) + '
  • ' ); var data = { action: 'as3cf-get-buckets', _nonce: as3cf_i18n.get_buckets_nonce }; - $.ajax({ - url: ajaxurl, - type: 'POST', - dataType: 'JSON', - data: data, - error: function(jqXHR, textStatus, errorThrown) { - $bucketList.html(''); + $.ajax( { + url : ajaxurl, + type : 'POST', + dataType: 'JSON', + data : data, + error : function( jqXHR, textStatus, errorThrown ) { + $bucketList.html( '' ); show_bucket_error( as3cf_i18n.get_buckets_error, errorThrown ); }, - success: function(data, textStatus, jqXHR) { - $bucketList.html(''); - if (typeof data['success'] !== 'undefined') { - $(data['buckets']).each(function(idx, bucket){ - var bucket_class = ( bucket.Name == data['selected'] ) ? 'selected' : ''; - $bucketList.append('
  • '+ bucket.Name +'
  • '); - }); + success : function( data, textStatus, jqXHR ) { + $bucketList.html( '' ); + if ( typeof data[ 'success' ] !== 'undefined' ) { + $( data[ 'buckets' ] ).each( function( idx, bucket ) { + var bucket_class = ( + bucket.Name === data[ 'selected' ] + ) ? 'selected' : ''; + $bucketList.append( '
  • ' + bucket.Name + '
  • ' ); + } ); + scroll_to_selected_bucket(); } else { show_bucket_error( as3cf_i18n.get_buckets_error, data[ 'error' ] ); } } - }); + } ); } - $bucketList.on('click', 'a', function(e){ + $bucketList.on( 'click', 'a', function( e ) { e.preventDefault(); - if ( $(this).hasClass('selected') ) { - $('.as3cf-settings').addClass('as3cf-has-bucket'); + if ( $( this ).hasClass( 'selected' ) ) { + $( '.as3cf-settings' ).addClass( 'as3cf-has-bucket' ); return; } var bucket = this; - var previous_bucket = $('.as3cf-bucket-list a.selected' ).attr('data-bucket'); + var previous_bucket = $( '.as3cf-bucket-list a.selected' ).attr( 'data-bucket' ); - $('.as3cf-bucket-list a' ).removeClass('selected'); - $(bucket).addClass('selected'); + $( '.as3cf-bucket-list a' ).removeClass( 'selected' ); + $( bucket ).addClass( 'selected' ); - $bucketList.addClass('saving'); - $(bucket).find('.spinner').show(); - var bucketName = $(bucket).attr('data-bucket'); + $bucketList.addClass( 'saving' ); + $( bucket ).find( '.spinner' ).show(); + var bucketName = $( bucket ).attr( 'data-bucket' ); var data = { - action: 'as3cf-save-bucket', + action : 'as3cf-save-bucket', bucket_name: bucketName, - _nonce: as3cf_i18n.save_bucket_nonce + _nonce : as3cf_i18n.save_bucket_nonce }; - $.ajax({ - url: ajaxurl, - type: 'POST', - dataType: 'JSON', - data: data, - error: function(jqXHR, textStatus, errorThrown) { - $bucketList.removeClass('saving'); + $.ajax( { + url : ajaxurl, + type : 'POST', + dataType: 'JSON', + data : data, + error : function( jqXHR, textStatus, errorThrown ) { + $bucketList.removeClass( 'saving' ); show_bucket_error( as3cf_i18n.save_bucket_error, errorThrown ); - $('.as3cf-bucket-list a' ).removeClass('selected'); + $( '.as3cf-bucket-list a' ).removeClass( 'selected' ); $( '.as3cf-bucket-list a[data-bucket="' + previous_bucket + '"]' ).addClass( 'selected' ); }, - success: function(data, textStatus, jqXHR) { - $(bucket).find('.spinner').hide(); - $bucketList.removeClass('saving'); - if (typeof data['success'] !== 'undefined') { - bucket_select( bucketName, data['region'], data['can_write'] ); + success : function( data, textStatus, jqXHR ) { + $( bucket ).find( '.spinner' ).hide(); + $bucketList.removeClass( 'saving' ); + if ( typeof data[ 'success' ] !== 'undefined' ) { + bucket_select( bucketName, data[ 'region' ], data[ 'can_write' ] ); } else { - show_bucket_error( as3cf_i18n.save_bucket_error, data['error'] ); - $('.as3cf-bucket-list a' ).removeClass('selected'); + show_bucket_error( as3cf_i18n.save_bucket_error, data[ 'error' ] ); + $( '.as3cf-bucket-list a' ).removeClass( 'selected' ); $( '.as3cf-bucket-list a[data-bucket="' + previous_bucket + '"]' ).addClass( 'selected' ); } } - }); - }); + } ); + } ); + + function scroll_to_selected_bucket() { + if ( ! $( '.as3cf-bucket-list a.selected' ).length ) { + return; + } + + var offset = $( 'ul.as3cf-bucket-list li' ).first().position().top + 150; + + $( 'ul.as3cf-bucket-list' ).animate( { + scrollTop: $( 'ul.as3cf-bucket-list li a.selected' ).position().top - offset + } ); + } function show_bucket_error( title, error ) { $( '.as3cf-bucket-error span.title' ).html( title ); @@ -178,78 +242,77 @@ } function bucket_select( bucket, region, can_write ) { - if ( '' == $( '.as3cf-active-bucket' ).text() ) { + if ( '' === $( '.as3cf-active-bucket' ).text() ) { // first time bucket select - enable main options by default set_checkbox( 'copy-to-s3-wrap' ); set_checkbox( 'serve-from-s3-wrap' ); } $( '.as3cf-active-bucket' ).text( bucket ); + $( 'form.as3cf-manual-save-bucket-form .as3cf-bucket-name' ).val( bucket ); $( '#as3cf-bucket' ).val( bucket ); $( '#as3cf-region' ).val( region ); - $( '.updated' ).not('.as3cf-notice' ).show(); + $( '.updated' ).not( '.as3cf-notice' ).show(); // check permission on bucket - if( can_write === false){ - $('.as3cf-can-write-error').show(); + if ( can_write === false ) { + $( '.as3cf-can-write-error' ).show(); } $( '.as3cf-settings' ).addClass( 'as3cf-has-bucket' ); generate_url_preview(); } - $('.as3cf-switch').on('click', 'span', function(e){ - if ( ! $(this).parent().hasClass('disabled') ) { - var parent_id = $(this).parent().attr('id'); + $( '.as3cf-switch' ).on( 'click', 'span', function( e ) { + if ( ! $( this ).parent().hasClass( 'disabled' ) ) { + var parent_id = $( this ).parent().attr( 'id' ); set_checkbox( parent_id ); } - }); + } ); function set_checkbox( checkbox_wrap ) { - $('#' + checkbox_wrap + ' span' ).toggleClass('checked'); - var switch_on = $('#' + checkbox_wrap + ' span.on' ).hasClass('checked'); - var checkbox_name = $('#' + checkbox_wrap).data('checkbox'); - var $checkbox = $('input#' + checkbox_name); + $( '#' + checkbox_wrap + ' span' ).toggleClass( 'checked' ); + var switch_on = $( '#' + checkbox_wrap + ' span.on' ).hasClass( 'checked' ); + var checkbox_name = $( '#' + checkbox_wrap ).data( 'checkbox' ); + var $checkbox = $( 'input#' + checkbox_name ); $checkbox.attr( "checked", switch_on ); - $checkbox.trigger("change"); + $checkbox.trigger( "change" ); } if ( $( '.as3cf-settings' ).length && ! $( '.as3cf-settings' ).hasClass( 'as3cf-has-bucket' ) ) { - loadBuckets(); - } - - if ( $( '#copy-to-s3' ).is( ":checked" ) ) { - $('tr.advanced-options').show(); + if ( $( '.as3cf-bucket-list-wrapper' ).is( ':visible' ) ) { + loadBuckets(); + } } - $('.as3cf-settings').on('change', '#copy-to-s3', function(e){ - $('tr.advanced-options').toggle(); - }); - - if ( $( '#serve-from-s3' ).is( ":checked" ) ) { - $('tr.configure-url').show(); - } + $( '.as3cf-settings' ).on( 'change', '.sub-toggle', function( e ) { + var setting = $( this ).attr( 'id' ); + $( '.as3cf-setting.' + setting ).toggleClass( 'hide' ); + } ); - $('.as3cf-settings').on('change', '#serve-from-s3', function(e){ - $('tr.configure-url').toggle(); - }); + $( '.as3cf-settings' ).on( 'click', '.as3cf-manual-bucket-toggle', function( e ) { + e.preventDefault(); + $( '.as3cf-bucket-select' ).addClass( 'manual' ); + } ); - $('.as3cf-settings').on('change', '.sub-toggle', function(e){ - var setting = $(this ).attr('id'); - $('.as3cf-setting.' + setting ).toggleClass('hide'); - }); + $( '.as3cf-settings' ).on( 'click', '.as3cf-bucket-list-toggle', function( e ) { + e.preventDefault(); + loadBuckets(); + $( '.as3cf-bucket-select' ).removeClass( 'manual' ); + $( '.as3cf-cancel-bucket-select-wrap' ).show(); + } ); - $('.as3cf-domain').on('change', 'input[type="radio"]', function(e){ + $( '.as3cf-domain' ).on( 'change', 'input[type="radio"]', function( e ) { var domain = $( 'input:radio[name="domain"]:checked' ).val(); - if ( 'cloudfront' == domain && $('.as3cf-setting.cloudfront' ).hasClass('hide') ) { - $('.as3cf-setting.cloudfront' ).removeClass('hide'); + if ( 'cloudfront' === domain && $( '.as3cf-setting.cloudfront' ).hasClass( 'hide' ) ) { + $( '.as3cf-setting.cloudfront' ).removeClass( 'hide' ); } else { - $('.as3cf-setting.cloudfront' ).addClass('hide'); + $( '.as3cf-setting.cloudfront' ).addClass( 'hide' ); } - }); + } ); $( '.as3cf-ssl' ).on( 'change', 'input[type="radio"]', function( e ) { var ssl = $( 'input:radio[name="ssl"]:checked' ).val(); - if ( 'https' == ssl ) { + if ( 'https' === ssl ) { var domain = $( 'input:radio[name="domain"]:checked' ).val(); - if ( 'subdomain' == domain ) { + if ( 'subdomain' === domain ) { $( 'input[name="domain"][value="path"]' ).attr( "checked", true ); } $( '.subdomain-wrap input' ).attr( 'disabled', true ); @@ -260,49 +323,59 @@ } } ); - $('.url-preview').on('change', 'input', function(e){ + $( '.url-preview' ).on( 'change', 'input', function( e ) { generate_url_preview(); - }); + } ); function generate_url_preview() { - $('.as3cf-url-preview' ).html( 'Generating...' ); + $( '.as3cf-url-preview' ).html( 'Generating...' ); var data = { _nonce: as3cf_i18n.get_url_preview_nonce }; - $.each( $(".as3cf-main-settings form").serializeArray(), function(i,o){ + $.each( $( ".as3cf-main-settings form" ).serializeArray(), function( i, o ) { var n = o.name, v = o.value; - n = n.replace('[]', ''); - data[n] = data[n] === undefined ? v - : $.isArray( data[n] ) ? data[n].concat( v ) - : [ data[n], v ]; - }); + n = n.replace( '[]', '' ); + data[ n ] = data[ n ] === undefined ? v + : $.isArray( data[ n ] ) ? data[ n ].concat( v ) + : [ data[ n ], v ]; + } ); // overwrite the save action stored in the form - data['action'] = 'as3cf-get-url-preview'; - - $.ajax({ - url: ajaxurl, - type: 'POST', - dataType: 'JSON', - data: data, - error: function(jqXHR, textStatus, errorThrown) { - alert(as3cf_i18n.get_url_preview_error + errorThrown); + data[ 'action' ] = 'as3cf-get-url-preview'; + + $.ajax( { + url : ajaxurl, + type : 'POST', + dataType: 'JSON', + data : data, + error : function( jqXHR, textStatus, errorThrown ) { + alert( as3cf_i18n.get_url_preview_error + errorThrown ); }, - success: function(data, textStatus, jqXHR) { - if (typeof data['success'] !== 'undefined') { - $('.as3cf-url-preview' ).html( data['url'] ); + success : function( data, textStatus, jqXHR ) { + if ( typeof data[ 'success' ] !== 'undefined' ) { + $( '.as3cf-url-preview' ).html( data[ 'url' ] ); } else { - alert(as3cf_i18n.get_url_preview_error + data['error']); + alert( as3cf_i18n.get_url_preview_error + data[ 'error' ] ); } } - }); + } ); + } + + /** + * Return the serialized string of the settings form + * excluding the bucket and region inputs as they get saved via AJAX + * + * @returns {string} + */ + function serialized_form() { + return $( '.as3cf-main-settings form' ).find( 'input:not(.no-compare)' ).serialize(); } // save the original state of the form for comparison later - saved_settings = $( '.as3cf-main-settings form' ).serialize(); + saved_settings = serialized_form(); // let the save settings submit happen as normal $( document ).on( 'submit', '.as3cf-main-settings form', function( event ) { @@ -312,11 +385,11 @@ // prompt user with dialog if leaving the settings page with unsaved changes $( window ).on( 'beforeunload.as3cf-settings', function() { - if ( $( '.as3cf-main-settings form' ).serialize() != saved_settings ) { + if ( serialized_form() !== saved_settings ) { return as3cf_i18n.save_alert; } } ); - }); + } ); })(jQuery); \ No newline at end of file diff --git a/assets/js/script.min.js b/assets/js/script.min.js index 37d2af18..c1f19b52 100644 --- a/assets/js/script.min.js +++ b/assets/js/script.min.js @@ -1 +1 @@ -!function(a){var b;a(document).ready(function(){function c(){a(".as3cf-bucket-error").hide(),h.html('
  • '+h.attr("data-working")+"
  • ");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('
  • '+c.Name+'
  • ')}):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); \ No newline at end of file +!function(a){var b;a(document).ready(function(){function c(){a(".as3cf-bucket-error").hide(),j.html('
  • '+j.attr("data-working")+"
  • ");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('
  • '+c.Name+'
  • ')}),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); \ No newline at end of file diff --git a/assets/package.json b/assets/package.json index 0287bf0e..21d1b3cb 100644 --- a/assets/package.json +++ b/assets/package.json @@ -5,6 +5,7 @@ "grunt": "^0.4.4", "grunt-contrib-uglify": "^0.4.0", "grunt-contrib-watch": "^0.6.0", - "grunt-contrib-compass": "^0.7.2" + "grunt-contrib-compass": "^0.7.2", + "grunt-contrib-jshint": "~0.10.0" } } diff --git a/assets/sass/styles.scss b/assets/sass/styles.scss index 0e34a07e..c7cc7bea 100644 --- a/assets/sass/styles.scss +++ b/assets/sass/styles.scss @@ -48,10 +48,6 @@ } } - tr.configure-url, tr.advanced-options { - display: none; - } - .object-prefix-desc { em { white-space: nowrap; @@ -176,6 +172,40 @@ } } + .as3cf-bucket-select { + &.manual { + .as3cf-manual-bucket-toggle, + .as3cf-refresh-buckets, + .as3cf-bucket-list-wrapper { + display: none; + } + .as3cf-bucket-list-toggle, + .as3cf-manual-save-bucket-wrapper { + display: block; + } + + .as3cf-cancel-bucket-select-wrap { + &:after { + content: "" + } + } + } + + .as3cf-manual-bucket-toggle, + .as3cf-bucket-list-wrapper { + display: block; + } + + .as3cf-refresh-buckets { + display: inline; + } + + .as3cf-bucket-list-toggle, + .as3cf-manual-save-bucket-wrapper { + display: none; + } + } + .as3cf-bucket-list-wrapper { background: #fff; padding: 15px 20px; @@ -217,10 +247,8 @@ } } - .as3cf-create-bucket-form { - input[type="text"] { - width: 80%; - } + input[type="text"].as3cf-bucket-name { + width: 80%; } select.bucket { diff --git a/classes/amazon-s3-and-cloudfront.php b/classes/amazon-s3-and-cloudfront.php index 5345ff4a..15f34a2b 100644 --- a/classes/amazon-s3-and-cloudfront.php +++ b/classes/amazon-s3-and-cloudfront.php @@ -2,7 +2,11 @@ use Aws\S3\S3Client; class Amazon_S3_And_CloudFront extends AWS_Plugin_Base { - private $aws, $s3client; + private $aws; + private $s3client; + + protected $plugin_title; + protected $plugin_menu_title; const DEFAULT_ACL = 'public-read'; const PRIVATE_ACL = 'private'; @@ -10,24 +14,38 @@ class Amazon_S3_And_CloudFront extends AWS_Plugin_Base { const SETTINGS_KEY = 'tantan_wordpress_s3'; - function __construct( $plugin_file_path, $aws ) { - $this->plugin_slug = 'amazon-s3-and-cloudfront'; + /** + * @param string $plugin_file_path + * @param Amazon_Web_Services $aws + * @param string|null $slug + */ + function __construct( $plugin_file_path, $aws, $slug = null ) { + $this->plugin_slug = ( is_null( $slug ) ) ? 'amazon-s3-and-cloudfront' : $slug; parent::__construct( $plugin_file_path ); $this->aws = $aws; - // fire up the plugin upgrade checker - new AS3CF_Upgrade( $this ); - - add_action( 'aws_admin_menu', array( $this, 'admin_menu' ) ); + $this->init( $plugin_file_path ); + } + /** + * Abstract class constructor + * + * @param string $plugin_file_path + */ + function init( $plugin_file_path ) { $this->plugin_title = __( 'Amazon S3 and CloudFront', 'as3cf' ); $this->plugin_menu_title = __( 'S3 and CloudFront', 'as3cf' ); + // fire up the plugin upgrade checker + new AS3CF_Upgrade( $this ); + + add_action( 'aws_admin_menu', array( $this, 'admin_menu' ) ); add_action( 'wp_ajax_as3cf-get-buckets', array( $this, 'ajax_get_buckets' ) ); add_action( 'wp_ajax_as3cf-save-bucket', array( $this, 'ajax_save_bucket' ) ); add_action( 'wp_ajax_as3cf-create-bucket', array( $this, 'ajax_create_bucket' ) ); + add_action( 'wp_ajax_as3cf-manual-save-bucket', array( $this, 'ajax_manual_save_bucket' ) ); add_action( 'wp_ajax_as3cf-get-url-preview', array( $this, 'ajax_get_url_preview' ) ); add_filter( 'wp_get_attachment_url', array( $this, 'wp_get_attachment_url' ), 99, 2 ); @@ -138,13 +156,12 @@ function get_setting( $key, $default = '' ) { } if ( 'bucket' == $key && defined( 'AS3CF_BUCKET' ) ) { + return AS3CF_BUCKET; } - $value = parent::get_setting( $key, $default ); - return apply_filters( 'as3cf_setting_' . $key, $value ); } @@ -326,12 +343,31 @@ function wp_update_attachment_metadata( $data, $post_id ) { return $data; } + // upload attachment to S3 + $this->upload_attachment_to_s3( $post_id, $data ); + + return $data; + } + + /** + * Upload attachment to S3 + * + * @param $post_id + * @param $data + * + * @return array|WP_Error $s3object + */ + function upload_attachment_to_s3( $post_id, $data = null ) { + if ( is_null( $data ) ) { + $data = wp_get_attachment_metadata( $post_id, true ); + } + $type = get_post_mime_type( $post_id ); $allowed_types = $this->get_allowed_mime_types(); // check mime type of file is in allowed S3 mime types if ( ! in_array( $type, $allowed_types ) ) { - return $data; + return new WP_Error( 'exception', sprintf( __( 'Mime type %s is not allowed', 'as3cf' ), $type ) ); } $acl = self::DEFAULT_ACL; @@ -418,8 +454,10 @@ function wp_update_attachment_metadata( $data, $post_id ) { $s3client->putObject( $args ); } catch ( Exception $e ) { - error_log( 'Error uploading ' . $file_path . ' to S3: ' . $e->getMessage() ); - return $data; + $error_msg = sprintf( __( 'Error uploading %s to S3: %s', 'as3cf' ), $file_path, $e->getMessage() ); + error_log( $error_msg ); + + return new WP_Error( 'exception', $error_msg ); } } @@ -485,7 +523,7 @@ function wp_update_attachment_metadata( $data, $post_id ) { $this->remove_local_files( $files_to_remove ); } - return $data; + return $s3object; } function remove_local_files( $file_paths ) { @@ -1039,11 +1077,12 @@ function ajax_save_bucket() { /** * Save bucket and bucket's region * - * @param $bucket_name + * @param string $bucket_name + * @param bool $manual if we are entering the bucket via the manual input form * * @return string|bool|WP_Error Region on success */ - function save_bucket( $bucket_name ) { + function save_bucket( $bucket_name, $manual = false ) { if ( $bucket_name ) { $this->get_settings(); // first time bucket select - enable main options by default @@ -1057,6 +1096,14 @@ function save_bucket( $bucket_name ) { return false; } $this->set_setting( 'region', $region ); + + if ( $manual ) { + // record that we have entered the bucket via the manual form + $this->set_setting( 'manual_bucket', true ); + } else { + $this->remove_setting( 'manual_bucket' ); + } + $this->save_settings(); return $region; @@ -1065,13 +1112,42 @@ function save_bucket( $bucket_name ) { return false; } + function ajax_manual_save_bucket() { + $this->verify_ajax_request(); + + $bucket = $this->ajax_check_bucket(); + + $region = $this->save_bucket( $bucket, true ); + + if ( $region !== false ) { + $out = array( + 'success' => '1', + 'region' => $region, + ); + $out['can_write'] = $this->check_write_permission( $bucket, $region ); + } else { + $out = array( 'error' => __( 'Failed to retrieve bucket region.', 'as3cf' ) ); + } + + echo json_encode( $out ); + exit; + } + function admin_menu( $aws ) { $hook_suffix = $aws->add_page( $this->plugin_title, $this->plugin_menu_title, 'manage_options', $this->plugin_slug, array( $this, 'render_page' ) ); add_action( 'load-' . $hook_suffix , array( $this, 'plugin_load' ) ); } - function get_s3client( $region = false ) { - if ( is_null( $this->s3client ) ) { + /** + * Get the S3 client + * + * @param bool|string $region specify region to client for signature + * @param bool $force force return of new S3 client when swapping regions + * + * @return mixed + */ + function get_s3client( $region = false, $force = false ) { + if ( is_null( $this->s3client ) || $force ) { if ( $region ) { $args = array( @@ -1230,7 +1306,7 @@ function check_write_permission( $bucket = null, $region = null ) { $region = $this->get_setting( 'region' ); } // attempt to create the test file - $this->get_s3client( $region )->putObject( $args ); + $this->get_s3client( $region, true )->putObject( $args ); // delete it straight away if created $this->get_s3client()->deleteObject( array( 'Bucket' => $bucket, @@ -1260,6 +1336,7 @@ function plugin_load() { 'create_bucket_prompt' => __( 'Bucket Name:', 'as3cf' ), 'create_bucket_error' => __( 'Error creating bucket: ', 'as3cf' ), 'create_bucket_nonce' => wp_create_nonce( 'as3cf-create-bucket' ), + 'manual_bucket_nonce' => wp_create_nonce( 'as3cf-manual-save-bucket' ), 'get_buckets_error' => __( 'Error fetching buckets: ', 'as3cf' ), 'get_buckets_nonce' => wp_create_nonce( 'as3cf-get-buckets' ), 'save_bucket_error' => __( 'Error saving bucket: ', 'as3cf' ), @@ -1281,7 +1358,7 @@ function handle_post_request() { die( __( "Cheatin' eh?", 'amazon-web-services' ) ); } - $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' ); + $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' ); foreach ( $post_vars as $var ) { $this->remove_setting( $var ); @@ -1301,6 +1378,9 @@ function handle_post_request() { exit; } + /** + * Display the main settings page for the plugin + */ function render_page() { $this->aws->render_view( 'header', array( 'page_title' => $this->plugin_title ) ); @@ -1312,6 +1392,7 @@ function render_page() { else { do_action( 'as3cf_pre_settings_render' ); $this->render_view( 'settings' ); + do_action( 'as3cf_post_settings_render' ); } $this->aws->render_view( 'footer' ); diff --git a/languages/amazon-s3-and-cloudfront.pot b/languages/amazon-s3-and-cloudfront.pot index 3385590b..4afa8181 100644 --- a/languages/amazon-s3-and-cloudfront.pot +++ b/languages/amazon-s3-and-cloudfront.pot @@ -1,8 +1,8 @@ msgid "" msgstr "" "Project-Id-Version: Amazon S3 and CloudFront\n" -"POT-Creation-Date: 2015-01-19 16:02-0000\n" -"PO-Revision-Date: 2015-01-19 16:02-0000\n" +"POT-Creation-Date: 2015-01-29 12:40-0000\n" +"PO-Revision-Date: 2015-01-29 12:40-0000\n" "Last-Translator: Delicious Brains \n" "Language-Team: Delicious Brains \n" "Language: en\n" @@ -20,71 +20,82 @@ msgstr "" "X-Poedit-SearchPathExcluded-0: vendor\n" "X-Poedit-SearchPathExcluded-1: assets\n" -#: classes/amazon-s3-and-cloudfront.php:25 +#: classes/amazon-s3-and-cloudfront.php:38 msgid "Amazon S3 and CloudFront" msgstr "" -#: classes/amazon-s3-and-cloudfront.php:26 +#: classes/amazon-s3-and-cloudfront.php:39 msgid "S3 and CloudFront" msgstr "" -#: classes/amazon-s3-and-cloudfront.php:923 +#: classes/amazon-s3-and-cloudfront.php:370 +#, php-format +msgid "Mime type %s is not allowed" +msgstr "" + +#: classes/amazon-s3-and-cloudfront.php:457 +#, php-format +msgid "Error uploading %s to S3: %s" +msgstr "" + +#: classes/amazon-s3-and-cloudfront.php:961 msgid "There was an error attempting to access the file system" msgstr "" -#: classes/amazon-s3-and-cloudfront.php:963 +#: classes/amazon-s3-and-cloudfront.php:1001 msgid "Cheatin’ eh?" msgstr "" -#: classes/amazon-s3-and-cloudfront.php:967 +#: classes/amazon-s3-and-cloudfront.php:1005 msgid "You do not have sufficient permissions to access this page." msgstr "" -#: classes/amazon-s3-and-cloudfront.php:973 +#: classes/amazon-s3-and-cloudfront.php:1011 msgid "No bucket name provided." msgstr "" -#: classes/amazon-s3-and-cloudfront.php:999 -#: classes/amazon-s3-and-cloudfront.php:1032 +#: classes/amazon-s3-and-cloudfront.php:1037 +#: classes/amazon-s3-and-cloudfront.php:1070 +#: classes/amazon-s3-and-cloudfront.php:1129 msgid "Failed to retrieve bucket region." msgstr "" -#: classes/amazon-s3-and-cloudfront.php:1103 +#: classes/amazon-s3-and-cloudfront.php:1179 #, php-format msgid "There was an error attempting to get the region of the bucket %s: %s" msgstr "" -#: classes/amazon-s3-and-cloudfront.php:1215 +#: classes/amazon-s3-and-cloudfront.php:1291 msgid "" "This is a test file to check if the user has write permission to S3. Delete " "me if found." msgstr "" -#: classes/amazon-s3-and-cloudfront.php:1260 +#: classes/amazon-s3-and-cloudfront.php:1336 msgid "Bucket Name:" msgstr "" -#: classes/amazon-s3-and-cloudfront.php:1261 +#: classes/amazon-s3-and-cloudfront.php:1337 msgid "Error creating bucket: " msgstr "" -#: classes/amazon-s3-and-cloudfront.php:1263 +#: classes/amazon-s3-and-cloudfront.php:1340 msgid "Error fetching buckets: " msgstr "" -#: classes/amazon-s3-and-cloudfront.php:1265 +#: classes/amazon-s3-and-cloudfront.php:1342 msgid "Error saving bucket: " msgstr "" -#: classes/amazon-s3-and-cloudfront.php:1268 +#: classes/amazon-s3-and-cloudfront.php:1345 msgid "Error getting URL preview: " msgstr "" -#: classes/amazon-s3-and-cloudfront.php:1269 +#: classes/amazon-s3-and-cloudfront.php:1346 msgid "The changes you made will be lost if you navigate away from this page" msgstr "" -#: classes/amazon-s3-and-cloudfront.php:1281 +#: classes/amazon-s3-and-cloudfront.php:1358 msgid "Cheatin' eh?" msgstr "" @@ -217,156 +228,179 @@ msgid "Refresh" msgstr "" #: view/settings.php:60 -msgid "Loading..." +msgid "" +"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." msgstr "" #: view/settings.php:63 -msgid "Or create a new bucket:" +msgid "Enter Bucket" msgstr "" -#: view/settings.php:66 +#: view/settings.php:64 +msgid "Select Bucket" +msgstr "" + +#: view/settings.php:68 view/settings.php:79 msgid "Bucket Name" msgstr "" -#: view/settings.php:67 +#: view/settings.php:69 +msgid "Saving..." +msgstr "" + +#: view/settings.php:69 +msgid "Save" +msgstr "" + +#: view/settings.php:73 +msgid "Loading..." +msgstr "" + +#: view/settings.php:76 +msgid "Or create a new bucket:" +msgstr "" + +#: view/settings.php:80 msgid "Creating..." msgstr "" -#: view/settings.php:67 +#: view/settings.php:80 msgid "Create" msgstr "" -#: view/settings.php:78 +#: view/settings.php:91 msgid "Bucket" msgstr "" -#: view/settings.php:81 +#: view/settings.php:95 msgid "Change" msgstr "" -#: view/settings.php:87 +#: view/settings.php:102 msgid "Enable/Disable the Plugin" msgstr "" -#: view/settings.php:94 +#: view/settings.php:109 msgid "Copy Files to S3" msgstr "" -#: view/settings.php:95 +#: view/settings.php:110 msgid "" "When a file is uploaded to the Media Library, copy it to S3. Existing files " "are not copied to S3." msgstr "" -#: view/settings.php:103 +#: view/settings.php:118 msgid "Rewrite File URLs" msgstr "" -#: view/settings.php:104 +#: view/settings.php:119 msgid "" "For Media Library files that have been copied to S3, rewrite the URLs so " "that they are served from S3/CloudFront instead of your server." msgstr "" -#: view/settings.php:108 +#: view/settings.php:123 msgid "Configure File URLs" msgstr "" -#: view/settings.php:122 +#: view/settings.php:137 msgid "Domain:" msgstr "" -#: view/settings.php:168 +#: view/settings.php:183 msgid "Path" msgstr "" -#: view/settings.php:170 +#: view/settings.php:185 msgid "By default the path is the same as your local WordPress files:" msgstr "" -#: view/settings.php:183 +#: view/settings.php:198 msgid "Year/Month" msgstr "" -#: view/settings.php:185 +#: view/settings.php:200 msgid "Add the Year/Month in the URL." msgstr "" -#: view/settings.php:191 +#: view/settings.php:206 msgid "SSL" msgstr "" -#: view/settings.php:199 +#: view/settings.php:214 msgid "Same as request" msgstr "" -#: view/settings.php:200 +#: view/settings.php:215 msgid "When the request is https://, use https:// for the file URL as well." msgstr "" -#: view/settings.php:204 +#: view/settings.php:219 msgid "Always SSL" msgstr "" -#: view/settings.php:205 +#: view/settings.php:220 msgid "Forces https:// to be used." msgstr "" -#: view/settings.php:206 +#: view/settings.php:221 msgid "" "You cannot use the \"Bucket as a subdomain\" domain option when using SSL." msgstr "" -#: view/settings.php:210 +#: view/settings.php:225 msgid "Always non-SSL" msgstr "" -#: view/settings.php:211 +#: view/settings.php:226 msgid "Forces http:// to be used." msgstr "" -#: view/settings.php:217 +#: view/settings.php:232 msgid "Advanced Options" msgstr "" -#: view/settings.php:224 +#: view/settings.php:239 msgid "Remove Files From Server" msgstr "" -#: view/settings.php:225 +#: view/settings.php:240 msgid "Once a file has been copied to S3, remove it from the local server." msgstr "" -#: view/settings.php:233 +#: view/settings.php:248 msgid "Object Versioning" msgstr "" -#: view/settings.php:235 +#: view/settings.php:250 msgid "" "Append a timestamp to the S3 file path. Recommended when using CloudFront so " "you don't have to worry about cache invalidation." msgstr "" -#: view/settings.php:237 view/settings.php:250 +#: view/settings.php:252 view/settings.php:265 msgid "More info" msgstr "" -#: view/settings.php:247 +#: view/settings.php:262 msgid "Far Future Expiration Header" msgstr "" -#: view/settings.php:248 +#: view/settings.php:263 msgid "" "Implements a \"Never Expire\" caching policy for browsers by setting an " "Expires header for 10 years in the future. Should be used in conjunction " "with object versioning above." msgstr "" -#: view/settings.php:260 +#: view/settings.php:275 msgid "Copy HiDPI (@2x) Images" msgstr "" -#: view/settings.php:261 +#: view/settings.php:276 #, php-format msgid "" "When uploading a file to S3, checks if there's a file of the same name with " @@ -374,7 +408,7 @@ msgid "" "Retina 2x plugin." msgstr "" -#: view/settings.php:267 +#: view/settings.php:282 msgid "Save Changes" msgstr "" diff --git a/readme.txt b/readme.txt index e3b55151..8dd543f5 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i Tags: uploads, amazon, s3, mirror, admin, media, cdn, cloudfront Requires at least: 3.5 Tested up to: 4.1 -Stable tag: 0.8.1 +Stable tag: 0.8.2 License: GPLv3 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 == Changelog == += 0.8.2 - 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 + = 0.8.1 - 2015-01-19 = * Bug Fix: Permission problems on installs running on EC2s * Bug Fix: Blank settings page due to WP_Error on S3 permission check diff --git a/view/settings.php b/view/settings.php index da13e65a..af45364a 100644 --- a/view/settings.php +++ b/view/settings.php @@ -47,8 +47,8 @@ ] } - -
    + get_setting( 'manual_bucket' ) ? 'manual' : ''; ?> +

    @@ -56,6 +56,19 @@
    +

    + +

    +

    + + +

    +
    +
    + + +
    +
    @@ -63,7 +76,7 @@

    - +
    @@ -78,9 +91,11 @@

    - - - + + + + + diff --git a/view/sidebar.php b/view/sidebar.php index f06ceaef..440392d9 100644 --- a/view/sidebar.php +++ b/view/sidebar.php @@ -8,14 +8,14 @@

    - +

      -
    • -
    • -
    • EDD integration', 'as3cf' ) ) ); ?>
    • -
    • +
    • +
    • +
    • EDD integration', 'as3cf' ) ); // xss ok ?>
    • +
    diff --git a/wordpress-s3.php b/wordpress-s3.php index 3fc7a1f6..de17bf61 100644 --- a/wordpress-s3.php +++ b/wordpress-s3.php @@ -4,7 +4,7 @@ Plugin URI: http://wordpress.org/extend/plugins/amazon-s3-and-cloudfront/ Description: Automatically copies media uploads to Amazon S3 for storage and delivery. Optionally configure Amazon CloudFront for even faster delivery. Author: Brad Touesnard -Version: 0.8.1 +Version: 0.8.2 Author URI: http://bradt.ca Network: True Text Domain: as3cf @@ -26,10 +26,11 @@ // Then completely rewritten. */ -$GLOBALS['aws_meta']['amazon-s3-and-cloudfront']['version'] = '0.8.1'; +$GLOBALS['aws_meta']['amazon-s3-and-cloudfront']['version'] = '0.8.2'; $GLOBALS['aws_meta']['amazon-s3-and-cloudfront']['supported_addon_versions'] = array( - 'amazon-s3-and-cloudfront-edd' => '1.0', + 'amazon-s3-and-cloudfront-edd' => '1.0.1', + 'amazon-s3-and-cloudfront-pro' => '0.9', ); $aws_plugin_version_required = '0.2.2';