Easy Watermark - Version 1.0.4

Version Description

  • [Fixed] Improved error handling
  • [Fixed] "Enhanced Media Library" plugin compatibility (and possibly some other plugins which replace media library components)
  • [Fixed] Watermark delete error fixed
  • [Fixed] Source set filtering improved
Download this release

Release Info

Developer szaleq
Plugin Icon Easy Watermark
Version 1.0.4
Comparing to
See all releases

Code changes from version 1.0.3 to 1.0.4

assets/dist/scripts/media-library.js CHANGED
@@ -1 +1 @@
1
- !function(e){var t={};function s(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,s),r.l=!0,r.exports}s.m=e,s.c=t,s.d=function(e,t,i){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(s.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)s.d(i,r,function(t){return e[t]}.bind(null,r));return i},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="../",s(s.s=18)}({0:function(e,t){e.exports=jQuery},1:function(e,t,s){"use strict";s.d(t,"a",(function(){return o})),s.d(t,"b",(function(){return a})),s.d(t,"c",(function(){return n})),s.d(t,"d",(function(){return l}));var i=s(0),r=s.n(i);function o(e,t="info"){const s=r()(document.createElement("div")),i=r()(document.createElement("p")),o=r()(document.createElement("button"));s.addClass("notice notice-"+t+" is-dismissible").hide(),o.addClass("notice-dismiss"),i.html(e),s.append(i).append(o),o.on("click",e=>{e.preventDefault(),s.fadeOut(200,()=>{s.remove()})}),r()("hr.wp-header-end").after(s),s.fadeIn(200)}function a(e,t=!1,s=!0){let i=e.length;for(const r of e.clone().models)(!l(r)||r.get("usedAsWatermark")||!0===t&&!r.get("hasBackup"))&&(!0===s&&e.remove(r),i--);return i}function n(e,t){const s=e.indexOf("?");return-1!==s&&(e=e.substr(0,s)),e+="?v="+t}function l(e){return"object"==typeof e&&e.get&&(e=e.get("mime")),Object.keys(ew.mime).includes(e)}},16:function(e,t){wp.media&&"function"==typeof wp.media.view.SelectModeToggleButton&&(wp.media.view.SelectModeToggleButton=class extends wp.media.view.SelectModeToggleButton{initialize(){super.initialize(),this.controller.on("processing:activate processing:deactivate",this.toggleDisabled,this)}toggleDisabled(){this.model.set("disabled",this.controller.isModeActive("processing"))}toggleBulkEditHandler(){super.toggleBulkEditHandler(),this.controller.trigger("selection:toggle");const e=this.controller.content.get().toolbar;this.controller.isModeActive("select")?e.$(".watermark-mode-toggle-button").removeClass("hidden"):e.$(".watermark-mode-toggle-button").addClass("hidden"),e.$(".watermark-selector").css("display",""),e.$(".ew-status").css("display","")}})},17:function(e,t){wp.media&&("function"==typeof wp.media.view.AttachmentFilters.All&&(wp.media.view.AttachmentFilters.All=class extends wp.media.view.AttachmentFilters.All{initialize(){super.initialize(),this.controller.on("processing:activate processing:deactivate",this.toggleDisabled,this)}toggleDisabled(){this.$el.prop("disabled",!this.$el.is(":disabled"))}}),"function"==typeof wp.media.view.AttachmentFilters.Uploaded&&(wp.media.view.AttachmentFilters.Uploaded=class extends wp.media.view.AttachmentFilters.Uploaded{initialize(){super.initialize(),this.controller.on("processing:activate processing:deactivate",this.toggleDisabled,this)}toggleDisabled(){this.$el.prop("disabled",!this.$el.is(":disabled"))}}),"function"==typeof wp.media.view.DateFilter&&(wp.media.view.DateFilter=class extends wp.media.view.DateFilter{initialize(){super.initialize(),this.controller.on("processing:activate processing:deactivate",this.toggleDisabled,this)}toggleDisabled(){this.$el.prop("disabled",!this.$el.is(":disabled"))}}))},18:function(e,t,s){"use strict";s.r(t);s(30);var i=s(0),r=s.n(i),o=s(1);if(wp.media&&"function"==typeof wp.media.view.Attachment.Library){const e=wp.media.view.Attachment.Library;wp.media.view.Attachment.Library=e.extend({initialize(){e.prototype.initialize.apply(this,arguments),this.listenTo(this.model,"ewBulkAction:start",this.showLoader),this.listenTo(this.model,"ewBulkAction:done",this.render),this.controller.on("selection:toggle watermark:activate processing:activate",this.disable,this),this.controller.on("watermark:deactivate processing:deactivate",this.enable,this)},render(){e.prototype.render.apply(this,arguments),this.$el.append(r()("<span></span>").addClass("spinner"))},toggleSelection({method:t}){(!this.controller.isModeActive("watermark")||Object(o.d)(this.model)&&!this.model.get("usedAsWatermark")||"between"===t)&&e.prototype.toggleSelection.apply(this,arguments),this.controller.isModeActive("watermark")&&(Object(o.d)(this.model)&&!this.model.get("usedAsWatermark")||this.$el.blur(),"between"===t&&Object(o.b)(this.options.selection))},showLoader(){this.$el.find(".spinner").css({visibility:"visible"})},disable(){if(!this.controller.isModeActive("watermark")&&!this.controller.isModeActive("processing"))return;if(this.hasBadge)return;if(this.controller.isModeActive("processing")&&!this.wasSelected())return;let e;if(Object(o.d)(this.model))if(this.model.get("usedAsWatermark"))e=ew.i18n.usedAsWatermark;else{if(!this.controller.isModeActive("restoring")||this.model.get("hasBackup"))return;e=ew.i18n.noBackupAvailable}else e=ew.i18n.notSupported;const t=r()("<div>",{class:"badge"}).text(e);this.$el.addClass("disabled").append(t),this.hasBadge=!0},enable(){this.controller.isModeActive("watermark")||this.controller.isModeActive("processing")||(this.$el.removeClass("disabled").find(".badge").remove(),this.hasBadge=!1)},wasSelected(){const e=this.controller.state().get("originalSelection");if(e)return!!e.get(this.model.cid)}})}let a=null;wp.media&&"function"==typeof wp.media.view.Button&&(a=class extends wp.media.view.Button{initialize(){super.initialize(),this.controller.on("watermark:activate",()=>{this.$el.removeClass("hidden").show()}),this.controller.on("watermark:deactivate",()=>{this.$el.addClass("hidden").hide()}),this.controller.on("watermark:selected",this.toggleDisabled,this),this.model.set("disabled",!0)}render(){return super.render(),this.controller.isModeActive("watermark")?this.$el.addClass("watermark-button"):this.$el.addClass("watermark-button hidden"),this}click(){super.click(),this.controller.state().get("watermark")&&this.controller.ewWatermark()}toggleDisabled(e){this.model.set("disabled",!e.length)}});var n=a;let l=null;wp.media&&"function"==typeof wp.media.view.Button&&(l=class extends wp.media.view.Button{initialize(){super.initialize(),this.model.set({originalText:this.model.get("text")}),this.controller.on("selection:toggle",this.update,this),this.controller.on("watermark:activate watermark:deactivate",this.render,this),this.controller.on("select:activate select:deactivate",this.render,this)}render(){return super.render(),this.controller.isModeActive("select")&&!this.controller.isModeActive("watermark")?this.$el.addClass("restore-button"):this.$el.addClass("restore-button hidden"),this.update(),this}click(){super.click(),this.controller.isModeActive("select")&&this.controller.ewRestoreBackup()}update(){const e=this.model.get("filteredSelectionCount"),t=Object(o.b)(this.controller.state().get("selection"),!0,!1);t!==e&&(this.model.set({filteredSelectionCount:t,text:`${this.model.get("originalText")} (${t})`}),this.model.set("disabled",!Boolean(t)))}});var c=l;let d=null;if(wp.media&&"function"==typeof wp.media.view.Button){class e extends wp.media.view.Button{initialize(){super.initialize(),this.model.set({originalText:this.model.get("text"),cancelText:this.options.cancelText}),delete this.options.cancelText,this.controller.on("selection:toggle",this.update,this),this.controller.on("watermark:activate",()=>this.$el.html(this.model.get("cancelText"))),this.controller.on("watermark:deactivate",this.update,this)}render(){return super.render(),this.controller.isModeActive("select")?this.$el.addClass("watermark-mode-toggle-button"):this.$el.addClass("watermark-mode-toggle-button hidden"),this.update(),this}click(){super.click(),this.controller.isModeActive("watermark")?this.controller.deactivateMode("watermark"):(this.controller.activateMode("watermark"),Object(o.b)(this.controller.state().get("selection")))}update(){if(this.controller.isModeActive("watermark"))return;const e=this.model.get("filteredSelectionCount"),t=Object(o.b)(this.controller.state().get("selection"),!1,!1);t!==e&&(this.model.set({filteredSelectionCount:t,text:`${this.model.get("originalText")} (${t})`}),this.model.set("disabled",!Boolean(t)),this.controller.state().get("selection").length||this.controller.deactivateMode("watermark"))}}d=e}var h=d;let u=null;if(wp.media&&"function"==typeof wp.media.View){class e extends wp.media.View{constructor(e){super(e),this.controller.on("watermark:activate",this.show,this),this.controller.on("watermark:deactivate",this.hide,this)}events(){return{change:"selectWatermark"}}tagName(){return"select"}selectWatermark(){this.controller.trigger("watermark:selected",this.$el.val()),this.controller.state().set("watermark",this.$el.val())}show(){this.$el.removeClass("hidden")}hide(){this.$el.addClass("hidden")}render(){if(super.render(),this.$el.append(r()("<option>",{value:""}).html(ew.i18n.selectWatermarkLabel)),ew.watermarks){1<Object.keys(ew.watermarks).length&&this.$el.append(r()("<option>",{value:"all"}).html(ew.i18n.allWatermarksLabel));for(const e in ew.watermarks)this.$el.append(r()("<option>",{value:e}).html(ew.watermarks[e]))}return this.controller.isModeActive("select")?this.$el.addClass("watermark-selector"):this.$el.addClass("watermark-selector hidden"),this}}u=e}var p=u;let g=null;if(wp.media&&"function"==typeof wp.media.View){class e extends wp.media.View{tagName(){return"p"}className(){return"ew-status"}template(){let e=this.status.get("text");if(this.status.get("progress")){const t=this.status.get("processed"),s=this.status.get("total"),i=`${t}/${s}`,r=Math.floor(t/s*100);"string"==typeof status&&(e=e.replace("{counter}",i)),e+=` (${r}%)`}return`<span class="status">${e}</span>`}constructor(e){super(e),this.status=this.controller.state().get("ewStatus"),this.status.on("change",this.update,this)}render(){return this.update(),this}update(){this.status.get("visible")?this.$el.removeClass("hidden").html(this.template()):this.$el.addClass("hidden")}cancel(e){e.preventDefault(),this.controller.deactivateMode("watermarking")}}g=e}var m=g;wp.media&&"function"==typeof wp.media.view.AttachmentsBrowser&&(wp.media.view.AttachmentsBrowser=class extends wp.media.view.AttachmentsBrowser{createToolbar(){super.createToolbar(),Object.keys(ew.watermarks).length&&(this.toolbar.set("watermarkModeToggleButton",new h({text:ew.i18n.watermarkModeToggleButtonLabel,cancelText:ew.i18n.cancelLabel,controller:this.controller,priority:-60}).render()),this.toolbar.set("watermarkSelector",new p({controller:this.controller,priority:-50}).render()),this.toolbar.set("watermarkButton",new n({text:ew.i18n.watermarkButtonLabel,style:"primary",controller:this.controller,priority:-40}).render())),this.toolbar.set("restoreButton",new c({text:ew.i18n.restoreButtonLabel,controller:this.controller,priority:-30}).render()),this.toolbar.set("watermarkingStatus",new m({style:"primary",controller:this.controller,priority:-20}).render()),this.controller.on("select:deactivate",()=>this.controller.deactivateMode("watermark")),this.controller.on("watermark:activate",this.hideButtons,this),this.controller.on("watermark:deactivate",this.showButtons,this),this.controller.on("processing:activate processing:deactivate",this.disableViewSwitch,this)}hideButtons(){this.$(".select-mode-toggle-button").addClass("hidden"),this.$(".delete-selected-button").addClass("hidden")}showButtons(){this.$el.html(this.model.get("text")),this.$(".select-mode-toggle-button").removeClass("hidden"),this.$(".delete-selected-button").removeClass("hidden")}disableViewSwitch(){const e=this.toolbar.$(".view-switch");e.hasClass("disabled")?e.removeClass("disabled"):e.addClass("disabled")}});s(16),s(17);var w=s(2);wp.media&&wp.media.view&&wp.media.view.MediaFrame&&"function"==typeof wp.media.view.MediaFrame.Manage&&(wp.media.view.MediaFrame.Manage=class extends wp.media.view.MediaFrame.Manage{browseContent(e){this.state().set({ewCollection:new w.Collection,ewStatus:new w.Model}),super.browseContent(e)}ewBulkAction(){const e=this.state(),t=e.get("selection"),s=e.get("ewAction"),i=t.clone();if(e.set("originalSelection",i),Object(o.b)(t,"restore"===s),!t.length)return;const r=e.get("ewCollection"),a=e.get("ewStatus");r.reset();for(const e of t.models)r.add(e),e.trigger("ewBulkAction:start");this.deactivateMode("watermark").trigger("selection:action:done"),this.activateMode("processing"),a.set({total:r.length,processed:0,error:!1,visible:!0,progress:!0}),this.ewBulkActionRecursive()}ewBulkActionRecursive(){const e=this.state(),t=e.get("ewAction"),s=e.get("watermark");let i,a="easy-watermark/";if("watermark"===t)a+="all"===s?"apply_all":"apply_single",i="all"===s?ew.applyAllNonce:ew.applySingleNonces[s];else{if("restore"!==t)return;a+="restore_backup",i=ew.restoreBackupNonce}const n=e.get("ewStatus"),l=e.get("ewCollection").shift(),c={action:a,nonce:i,watermark:s};let d=n.get("processed");c.attachment_id=l.get("id"),e.set("ewCurrentModel",l),r.a.ajax(ajaxurl,{data:c}).done(e=>{if(!0===e.success){if(e.data.attachmentVersion){l.set("url",Object(o.c)(l.get("url"),e.data.attachmentVersion));const t=l.get("sizes");for(const s of Object.keys(t))t[s].url=Object(o.c)(t[s].url,e.data.attachmentVersion);l.set("sizes",t)}l.set("hasBackup",!!e.data.hasBackup),d++,n.set({processed:d}),l.trigger("ewBulkAction:done"),n.get("total")===d?this.ewBulkActionDone():this.ewBulkActionRecursive()}else{const t="string"==typeof e.data.message?e.data.message:ew.i18n.genericErrorMessage;this.ewBulkActionError(t)}}).fail(()=>{this.ewBulkActionError(ew.i18n.genericErrorMessage)})}ewWatermark(){this.state().set({ewAction:"watermark",ewSuccessMessage:ew.i18n.watermarkingSuccessMessage}).get("ewStatus").set({text:ew.i18n.watermarkingStatus}),this.activateMode("watermarking"),this.ewBulkAction()}ewRestoreBackup(){this.state().set({ewAction:"restore",ewSuccessMessage:ew.i18n.restoringSuccessMessage}).get("ewStatus").set({text:ew.i18n.restoringStatus}),this.activateMode("restoring"),this.ewBulkAction()}ewBulkActionError(e){const t=this.state(),s=t.get("ewStatus"),i=t.get("ewCollection"),r=t.get("ewCurrentModel");r&&i.push(r);for(const e of i.models)e.trigger("ewBulkAction:done");s.set({error:e}),this.ewBulkActionDone()}ewBulkActionDone(){const e=this.state(),t=e.get("ewStatus"),s=e.get("ewCurrentModel"),i=t.get("processed"),r=t.get("error"),a=e.get("ewSuccessMessage");if(this.deactivateMode("watermarking"),this.deactivateMode("restoring"),this.deactivateMode("processing"),i>0&&Object(o.a)(a.replace("{procesed}",i),"success"),r){const e=ew.i18n.bulkActionErrorMessage.replace("{imageTitle}",s.get("title")).replace("{error}",r);Object(o.a)(e,"error")}t.set({visible:!1,progress:!1})}});var k=class extends w.View{constructor(e){super(e),this.controller=e.controller,this.bulkActionSelector=e.bulkActionSelector}},b=class extends k{tagName(){return"select"}className(){return"ew-status"}events(){return{change:"selectWatermark"}}constructor(e){super(e),this.listenTo(this.controller,"change",this.update),this.listenTo(this.controller,"bulkAction:start",this.reset)}render(){super.render(),this.$el.append(r()("<option>",{value:""}).html(ew.i18n.selectWatermarkLabel)),1<Object.keys(ew.watermarks).length&&this.$el.append(r()("<option>",{value:"all"}).html(ew.i18n.allWatermarksLabel));for(const e in ew.watermarks)this.$el.append(r()("<option>",{value:e}).html(ew.watermarks[e]));return this.attach(),this}update(){this.bulkActionSelector.is(this.controller.get("select"))&&("watermark"!==this.controller.get("action")||this.controller.status().get("processing")?this.$el.hide():this.$el.show())}reset(){this.$el.val("all").hide()}attach(){return this.bulkActionSelector.after(this.$el),this.$el.hide(),this}selectWatermark(){this.controller.set("watermark",this.$el.val())}},f=class extends k{tagName(){return"p"}className(){return"ew-status"}template(){let e=this.status.get("text");if(this.status.get("processing")){const t=this.status.get("processed"),s=this.status.get("total"),i=`${t}/${s}`;let r=Math.floor(t/s*100);"string"==typeof e&&(e=e.replace("{counter}",i)),isNaN(r)&&(r=0),e=`${e} (${r}%)`}return e}constructor(e){super(e),this.status=this.controller.status(),this.listenTo(this.status,"change",this.update)}render(){super.render(),this.attach()}update(){this.bulkActionSelector.is(this.controller.get("select"))&&(this.status.get("text")?(this.$el.html(this.template()),this.$el.show()):this.$el.hide())}attach(){return this.bulkActionSelector.parent().append(this.$el),this.$el.hide(),this}},v=class extends k{constructor(e){super(e),this.model=e.model,this.listenTo(this.model,"processing:start",this.showSpinner),this.listenTo(this.model,"processing:done",this.reset),this.listenTo(this.model,"remove",this.deselect),this.controller.on("bulkAction:finished",this.reset,this)}showSpinner(){this.getSpinner().appendTo(this.$el.find("span.media-icon"))}getSpinner(){return this.spinner||(this.spinner=r()("<span>",{class:"spinner ew-spinner"})),this.spinner}reset(){this.spinner&&this.spinner.remove(),this.getStatus().text(""),this.$el.find('input[type="checkbox"]').click().prop("checked",!1)}deselect(){if(this.controller.status().get("processing"))return;let e;this.$el.find('input[type="checkbox"]').click().prop("checked",!1),Object(o.d)(this.model)?this.model.get("usedAsWatermark")?e=ew.i18n.usedAsWatermark:"restore"!==this.controller.get("action")||this.model.get("hasBackup")||(e=ew.i18n.noBackupAvailable):e=ew.i18n.notSupported,this.getStatus().text(` - ${e}`)}getStatus(){return this.status||(this.status=r()("<span>",{class:"ew-status"}),this.$el.find("strong.has-media-icon").append(this.status)),this.status}};class A extends w.Model{constructor(){super(),this.bulkActionsSelectors=r()("select#bulk-action-selector-top, select#bulk-action-selector-bottom"),this.bulkActionsSelectors.length&&this.init()}init(){this.selectBulkAction=this.selectBulkAction.bind(this),this.doAction=this.doAction.bind(this),this.form=r()("form#posts-filter"),this.actionButtons=this.form.find("#doaction, #doaction2"),this.bulkActionsSelectors.each((e,t)=>{const s=r()(t);new b({controller:this,bulkActionSelector:s}).render(),new f({controller:this,bulkActionSelector:s}).render()}).val(-1).on("change",this.selectBulkAction),this.set({attachments:new w.Collection,selection:new w.Collection}),this.actionButtons.on("click",this.doAction),this.on("bulkAction:start",()=>{this.bulkActionsSelectors.val(-1).prop("disabled",!0),this.actionButtons.prop("disabled",!0)}),this.on("bulkAction:finished",()=>{this.bulkActionsSelectors.prop("disabled",!1),this.actionButtons.prop("disabled",!1)})}selectBulkAction(e){const t=r()(e.target);this.set({select:t,action:t.val()})}doAction(e){const t=this.get("action");if(!this.checkAction(t))return;e.preventDefault();const s=this.get("watermark");if("watermark"===t&&!s)return;const i=this.form.find('input[name="media[]"]:checked');if(!i.length)return void this.status().set({text:ew.i18n.noItemsSelected});const o=this.get("attachments"),a=this.get("selection"),n=[];this.trigger("bulkAction:start"),i.each((e,t)=>{const s=r()(t).val(),i=o.get(s);i?a.add(i):n.push(s)}),n.length?(this.status().set({text:'<span class="spinner ew-spinner"></span>'}),r.a.ajax(ajaxurl,{data:{action:"easy-watermark/attachments-info",nonce:ew.attachmentsInfoNonce,attachments:n}}).done(e=>{if(!0===e.success){for(const t of e.data){const e=new w.Model(t);o.push(e),a.push(e),new v({el:`#post-${t.id}`,controller:this,model:e})}this.prepare()}else{const t=e.data.message?e.data.message:ew.i18n.genericErrorMessage;this.actionError(t)}}).fail(()=>{this.actionError(ew.i18n.genericErrorMessage)})):a.length&&this.prepare()}prepare(){const e=this.get("action"),t=this.get("selection"),s="restore"===e,i="watermark"===e?ew.i18n.watermarkingStatus:ew.i18n.restoringStatus,r="watermark"===e?ew.i18n.watermarkingSuccessMessage:ew.i18n.restoringSuccessMessage;if(Object(o.b)(t,s),!t.length)return this.status().set({successMessage:"watermark"===e?ew.i18n.watermarkingNoItems:ew.i18n.restoringNoItems}),void this.actionDone();this.status().set({successMessage:r,text:i,processing:!0,total:t.length,processed:0});for(const e of t.models)e.trigger("processing:start");this.doActionRecursive()}doActionRecursive(){const e=this.get("action"),t=this.get("watermark");let s,i="easy-watermark/";if("watermark"===e)i+="all"===t?"apply_all":"apply_single",s="all"===t?ew.applyAllNonce:ew.applySingleNonces[t];else{if("restore"!==e)return;i+="restore_backup",s=ew.restoreBackupNonce}const a=this.status(),n=this.get("selection"),l=n.shift(),c={action:i,nonce:s,watermark:t};let d=a.get("processed");c.attachment_id=l.get("id"),this.set("currentAttachmentID",c.attachment_id),r.a.ajax(ajaxurl,{data:c}).done(e=>{if(!0===e.success){if(e.data.attachmentVersion){const t=this.form.find("tr#post-"+c.attachment_id+" img"),s=Object(o.c)(t.attr("src"),e.data.attachmentVersion);t.attr({src:s,srcset:""})}d++,a.set({processed:d}),l.set("hasBackup",!!e.data.hasBackup),l.trigger("processing:done"),n.length?this.doActionRecursive():this.actionDone()}else{const t="string"==typeof e.data.message?e.data.message:ew.i18n.genericErrorMessage;this.actionError(t)}}).fail(()=>{this.actionError(ew.i18n.genericErrorMessage)})}actionError(e){this.status().set({error:e}),this.actionDone()}actionDone(){this.trigger("bulkAction:finished"),this.bulkActionsSelectors.prop("disabled",!1);const e=this.status(),t=e.get("processed"),s=e.get("error"),i=e.get("successMessage"),r=this.get("currentAttachmentID");if(t>0?Object(o.a)(i.replace("{procesed}",t),"success"):Object(o.a)(i,"info"),s){const e=this.form.find("tr#post-"+r).find(".column-title a").attr("aria-label"),t=ew.i18n.bulkActionErrorMessage.replace("{imageTitle}",e).replace("{error}",s);Object(o.a)(t,"error")}this.status().set({processing:!1,processed:0,total:0,text:""})}status(){let e=this.get("status");return void 0===e&&((e=new w.Model).set({processed:0,total:0}),this.set({status:e})),e}checkAction(e){return["watermark","restore"].includes(e)}}r()(document).ready(()=>new A)},2:function(e,t){e.exports=Backbone},30:function(e,t){}});
1
+ !function(e){var t={};function s(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,s),r.l=!0,r.exports}s.m=e,s.c=t,s.d=function(e,t,i){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(s.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)s.d(i,r,function(t){return e[t]}.bind(null,r));return i},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="../",s(s.s=18)}({0:function(e,t){e.exports=jQuery},1:function(e,t,s){"use strict";s.d(t,"a",(function(){return o})),s.d(t,"b",(function(){return a})),s.d(t,"c",(function(){return n})),s.d(t,"d",(function(){return l}));var i=s(0),r=s.n(i);function o(e,t="info"){const s=r()(document.createElement("div")),i=r()(document.createElement("p")),o=r()(document.createElement("button"));s.addClass("notice notice-"+t+" is-dismissible").hide(),o.addClass("notice-dismiss"),i.html(e),s.append(i).append(o),o.on("click",e=>{e.preventDefault(),s.fadeOut(200,()=>{s.remove()})}),r()("hr.wp-header-end").after(s),s.fadeIn(200)}function a(e,t=!1,s=!0){let i=e.length;for(const r of e.clone().models)(!l(r)||r.get("usedAsWatermark")||!0===t&&!r.get("hasBackup"))&&(!0===s&&e.remove(r),i--);return i}function n(e,t){const s=e.indexOf("?");return-1!==s&&(e=e.substr(0,s)),e+="?v="+t}function l(e){return"object"==typeof e&&e.get&&(e=e.get("mime")),Object.keys(ew.mime).includes(e)}},16:function(e,t){wp.media&&"function"==typeof wp.media.view.SelectModeToggleButton&&(wp.media.view.SelectModeToggleButton=class extends wp.media.view.SelectModeToggleButton{initialize(){super.initialize(),this.controller.on("processing:activate processing:deactivate",this.toggleDisabled,this)}toggleDisabled(){this.model.set("disabled",this.controller.isModeActive("processing"))}toggleBulkEditHandler(){super.toggleBulkEditHandler(),this.controller.trigger("selection:toggle");const e=this.controller.content.get().toolbar;this.controller.isModeActive("select")?e.$(".watermark-mode-toggle-button").removeClass("hidden"):e.$(".watermark-mode-toggle-button").addClass("hidden"),e.$(".watermark-selector").css("display",""),e.$(".ew-status").css("display","")}})},17:function(e,t){wp.media&&("function"==typeof wp.media.view.AttachmentFilters.All&&(wp.media.view.AttachmentFilters.All=class extends wp.media.view.AttachmentFilters.All{initialize(){super.initialize(),this.controller.on("processing:activate processing:deactivate",this.toggleDisabled,this)}toggleDisabled(){this.$el.prop("disabled",!this.$el.is(":disabled"))}}),"function"==typeof wp.media.view.AttachmentFilters.Uploaded&&(wp.media.view.AttachmentFilters.Uploaded=class extends wp.media.view.AttachmentFilters.Uploaded{initialize(){super.initialize(),this.controller.on("processing:activate processing:deactivate",this.toggleDisabled,this)}toggleDisabled(){this.$el.prop("disabled",!this.$el.is(":disabled"))}}),"function"==typeof wp.media.view.DateFilter&&(wp.media.view.DateFilter=class extends wp.media.view.DateFilter{initialize(){super.initialize(),this.controller.on("processing:activate processing:deactivate",this.toggleDisabled,this)}toggleDisabled(){this.$el.prop("disabled",!this.$el.is(":disabled"))}}))},18:function(e,t,s){"use strict";s.r(t);s(30);var i=s(0),r=s.n(i),o=s(1);if(wp.media&&"function"==typeof wp.media.view.Attachment.Library){const e=wp.media.view.Attachment.Library;wp.media.view.Attachment.Library=e.extend({initialize(){e.prototype.initialize.apply(this,arguments),this.listenTo(this.model,"ewBulkAction:start",this.showLoader),this.listenTo(this.model,"ewBulkAction:done",this.render),this.controller.on("selection:toggle watermark:activate processing:activate",this.disable,this),this.controller.on("watermark:deactivate processing:deactivate",this.enable,this)},render(){e.prototype.render.apply(this,arguments),this.$el.append(r()("<span></span>").addClass("spinner"))},toggleSelection({method:t}){(!this.controller.isModeActive("watermark")||Object(o.d)(this.model)&&!this.model.get("usedAsWatermark")||"between"===t)&&e.prototype.toggleSelection.apply(this,arguments),this.controller.isModeActive("watermark")&&(Object(o.d)(this.model)&&!this.model.get("usedAsWatermark")||this.$el.blur(),"between"===t&&Object(o.b)(this.options.selection))},showLoader(){this.$el.find(".spinner").css({visibility:"visible"})},disable(){if(!this.controller.isModeActive("watermark")&&!this.controller.isModeActive("processing"))return;if(this.hasBadge)return;if(this.controller.isModeActive("processing")&&!this.wasSelected())return;let e;if(Object(o.d)(this.model))if(this.model.get("usedAsWatermark"))e=ew.i18n.usedAsWatermark;else{if(!this.controller.isModeActive("restoring")||this.model.get("hasBackup"))return;e=ew.i18n.noBackupAvailable}else e=ew.i18n.notSupported;const t=r()("<div>",{class:"badge"}).text(e);this.$el.addClass("disabled").append(t),this.hasBadge=!0},enable(){this.controller.isModeActive("watermark")||this.controller.isModeActive("processing")||(this.$el.removeClass("disabled").find(".badge").remove(),this.hasBadge=!1)},wasSelected(){const e=this.controller.state().get("originalSelection");if(e)return!!e.get(this.model.cid)}})}let a=null;wp.media&&"function"==typeof wp.media.view.Button&&(a=class extends wp.media.view.Button{initialize(){super.initialize(),this.controller.on("watermark:activate",()=>{this.$el.removeClass("hidden").show()}),this.controller.on("watermark:deactivate",()=>{this.$el.addClass("hidden").hide()}),this.controller.on("watermark:selected",this.toggleDisabled,this),this.model.set("disabled",!0)}render(){return super.render(),this.controller.isModeActive("watermark")?this.$el.addClass("watermark-button"):this.$el.addClass("watermark-button hidden"),this}click(){super.click(),this.controller.state().get("watermark")&&this.controller.ewWatermark()}toggleDisabled(e){this.model.set("disabled",!e.length)}});var n=a;let l=null;wp.media&&"function"==typeof wp.media.view.Button&&(l=class extends wp.media.view.Button{initialize(){super.initialize(),this.model.set({originalText:this.model.get("text")}),this.controller.on("selection:toggle",this.update,this),this.controller.on("watermark:activate watermark:deactivate",this.render,this),this.controller.on("select:activate select:deactivate",this.render,this)}render(){return super.render(),this.controller.isModeActive("select")&&!this.controller.isModeActive("watermark")?this.$el.addClass("restore-button"):this.$el.addClass("restore-button hidden"),this.update(),this}click(){super.click(),this.controller.isModeActive("select")&&this.controller.ewRestoreBackup()}update(){const e=this.model.get("filteredSelectionCount"),t=Object(o.b)(this.controller.state().get("selection"),!0,!1);t!==e&&(this.model.set({filteredSelectionCount:t,text:`${this.model.get("originalText")} (${t})`}),this.model.set("disabled",!Boolean(t)))}});var c=l;let d=null;if(wp.media&&"function"==typeof wp.media.view.Button){class e extends wp.media.view.Button{initialize(){super.initialize(),this.model.set({originalText:this.model.get("text"),cancelText:this.options.cancelText}),delete this.options.cancelText,this.controller.on("selection:toggle",this.update,this),this.controller.on("watermark:activate",()=>this.$el.html(this.model.get("cancelText"))),this.controller.on("watermark:deactivate",this.update,this)}render(){return super.render(),this.controller.isModeActive("select")?this.$el.addClass("watermark-mode-toggle-button"):this.$el.addClass("watermark-mode-toggle-button hidden"),this.update(),this}click(){super.click(),this.controller.isModeActive("watermark")?this.controller.deactivateMode("watermark"):(this.controller.activateMode("watermark"),Object(o.b)(this.controller.state().get("selection")))}update(){if(this.controller.isModeActive("watermark"))return;const e=this.model.get("filteredSelectionCount"),t=Object(o.b)(this.controller.state().get("selection"),!1,!1);t!==e&&(this.model.set({filteredSelectionCount:t,text:`${this.model.get("originalText")} (${t})`}),this.model.set("disabled",!Boolean(t)),this.controller.state().get("selection").length||this.controller.deactivateMode("watermark"))}}d=e}var h=d;let u=null;if(wp.media&&"function"==typeof wp.media.View){class e extends wp.media.View{constructor(e){super(e),this.controller.on("watermark:activate",this.show,this),this.controller.on("watermark:deactivate",this.hide,this)}events(){return{change:"selectWatermark"}}tagName(){return"select"}selectWatermark(){this.controller.trigger("watermark:selected",this.$el.val()),this.controller.state().set("watermark",this.$el.val())}show(){this.$el.removeClass("hidden")}hide(){this.$el.addClass("hidden")}render(){if(super.render(),this.$el.append(r()("<option>",{value:""}).html(ew.i18n.selectWatermarkLabel)),ew.watermarks){1<Object.keys(ew.watermarks).length&&this.$el.append(r()("<option>",{value:"all"}).html(ew.i18n.allWatermarksLabel));for(const e in ew.watermarks)this.$el.append(r()("<option>",{value:e}).html(ew.watermarks[e]))}return this.controller.isModeActive("select")?this.$el.addClass("watermark-selector"):this.$el.addClass("watermark-selector hidden"),this}}u=e}var p=u;let g=null;if(wp.media&&"function"==typeof wp.media.View){class e extends wp.media.View{tagName(){return"p"}className(){return"ew-status"}template(){let e=this.status.get("text");if(this.status.get("progress")){const t=this.status.get("processed"),s=this.status.get("total"),i=`${t}/${s}`,r=Math.floor(t/s*100);"string"==typeof status&&(e=e.replace("{counter}",i)),e+=` (${r}%)`}return`<span class="status">${e}</span>`}constructor(e){super(e),this.status=this.controller.state().get("ewStatus"),this.status.on("change",this.update,this)}render(){return this.update(),this}update(){this.status.get("visible")?this.$el.removeClass("hidden").html(this.template()):this.$el.addClass("hidden")}cancel(e){e.preventDefault(),this.controller.deactivateMode("watermarking")}}g=e}var w=g;wp.media&&"function"==typeof wp.media.view.AttachmentsBrowser&&(wp.media.view.AttachmentsBrowser=class extends wp.media.view.AttachmentsBrowser{createToolbar(){super.createToolbar(),this.controller.state().get("ewStatus")&&(Object.keys(ew.watermarks).length&&(this.toolbar.set("watermarkModeToggleButton",new h({text:ew.i18n.watermarkModeToggleButtonLabel,cancelText:ew.i18n.cancelLabel,controller:this.controller,priority:-60}).render()),this.toolbar.set("watermarkSelector",new p({controller:this.controller,priority:-50}).render()),this.toolbar.set("watermarkButton",new n({text:ew.i18n.watermarkButtonLabel,style:"primary",controller:this.controller,priority:-40}).render())),this.toolbar.set("restoreButton",new c({text:ew.i18n.restoreButtonLabel,controller:this.controller,priority:-30}).render()),this.toolbar.set("watermarkingStatus",new w({style:"primary",controller:this.controller,priority:-20}).render()),this.controller.on("select:deactivate",()=>this.controller.deactivateMode("watermark")),this.controller.on("watermark:activate",this.hideButtons,this),this.controller.on("watermark:deactivate",this.showButtons,this),this.controller.on("processing:activate processing:deactivate",this.disableViewSwitch,this))}hideButtons(){this.$(".select-mode-toggle-button").addClass("hidden"),this.$(".delete-selected-button").addClass("hidden")}showButtons(){this.$el.html(this.model.get("text")),this.$(".select-mode-toggle-button").removeClass("hidden"),this.$(".delete-selected-button").removeClass("hidden")}disableViewSwitch(){const e=this.toolbar.$(".view-switch");e.hasClass("disabled")?e.removeClass("disabled"):e.addClass("disabled")}});s(16),s(17);var m=s(2);wp.media&&wp.media.view&&wp.media.view.MediaFrame&&"function"==typeof wp.media.view.MediaFrame.Manage&&(wp.media.view.MediaFrame.Manage=class extends wp.media.view.MediaFrame.Manage{browseContent(e){this.state().set({ewCollection:new m.Collection,ewStatus:new m.Model}),super.browseContent(e)}ewBulkAction(){const e=this.state(),t=e.get("selection"),s=e.get("ewAction"),i=t.clone();if(e.set("originalSelection",i),Object(o.b)(t,"restore"===s),!t.length)return;const r=e.get("ewCollection"),a=e.get("ewStatus");r.reset();for(const e of t.models)r.add(e),e.trigger("ewBulkAction:start");this.deactivateMode("watermark").trigger("selection:action:done"),this.activateMode("processing"),a.set({total:r.length,processed:0,error:!1,visible:!0,progress:!0}),this.ewBulkActionRecursive()}ewBulkActionRecursive(){const e=this.state(),t=e.get("ewAction"),s=e.get("watermark");let i,a="easy-watermark/";if("watermark"===t)a+="all"===s?"apply_all":"apply_single",i="all"===s?ew.applyAllNonce:ew.applySingleNonces[s];else{if("restore"!==t)return;a+="restore_backup",i=ew.restoreBackupNonce}const n=e.get("ewStatus"),l=e.get("ewCollection").shift(),c={action:a,nonce:i,watermark:s};let d=n.get("processed");c.attachment_id=l.get("id"),e.set("ewCurrentModel",l),r.a.ajax(ajaxurl,{data:c}).done(e=>{if(!0===e.success){if(e.data.attachmentVersion){l.set("url",Object(o.c)(l.get("url"),e.data.attachmentVersion));const t=l.get("sizes");for(const s of Object.keys(t))t[s].url=Object(o.c)(t[s].url,e.data.attachmentVersion);l.set("sizes",t)}l.set("hasBackup",!!e.data.hasBackup),d++,n.set({processed:d}),l.trigger("ewBulkAction:done"),n.get("total")===d?this.ewBulkActionDone():this.ewBulkActionRecursive()}else{const t="string"==typeof e.data.message?e.data.message:ew.i18n.genericErrorMessage;this.ewBulkActionError(t)}}).fail(()=>{this.ewBulkActionError(ew.i18n.genericErrorMessage)})}ewWatermark(){this.state().set({ewAction:"watermark",ewSuccessMessage:ew.i18n.watermarkingSuccessMessage}).get("ewStatus").set({text:ew.i18n.watermarkingStatus}),this.activateMode("watermarking"),this.ewBulkAction()}ewRestoreBackup(){this.state().set({ewAction:"restore",ewSuccessMessage:ew.i18n.restoringSuccessMessage}).get("ewStatus").set({text:ew.i18n.restoringStatus}),this.activateMode("restoring"),this.ewBulkAction()}ewBulkActionError(e){const t=this.state(),s=t.get("ewStatus"),i=t.get("ewCollection"),r=t.get("ewCurrentModel");r&&i.push(r);for(const e of i.models)e.trigger("ewBulkAction:done");s.set({error:e}),this.ewBulkActionDone()}ewBulkActionDone(){const e=this.state(),t=e.get("ewStatus"),s=e.get("ewCurrentModel"),i=t.get("processed"),r=t.get("error"),a=e.get("ewSuccessMessage");if(this.deactivateMode("watermarking"),this.deactivateMode("restoring"),this.deactivateMode("processing"),i>0&&Object(o.a)(a.replace("{procesed}",i),"success"),r){const e=ew.i18n.bulkActionErrorMessage.replace("{imageTitle}",s.get("title")).replace("{error}",r);Object(o.a)(e,"error")}t.set({visible:!1,progress:!1})}});var k=class extends m.View{constructor(e){super(e),this.controller=e.controller,this.bulkActionSelector=e.bulkActionSelector}},b=class extends k{tagName(){return"select"}className(){return"ew-status"}events(){return{change:"selectWatermark"}}constructor(e){super(e),this.listenTo(this.controller,"change",this.update),this.listenTo(this.controller,"bulkAction:start",this.reset)}render(){super.render(),this.$el.append(r()("<option>",{value:""}).html(ew.i18n.selectWatermarkLabel)),1<Object.keys(ew.watermarks).length&&this.$el.append(r()("<option>",{value:"all"}).html(ew.i18n.allWatermarksLabel));for(const e in ew.watermarks)this.$el.append(r()("<option>",{value:e}).html(ew.watermarks[e]));return this.attach(),this}update(){this.bulkActionSelector.is(this.controller.get("select"))&&("watermark"!==this.controller.get("action")||this.controller.status().get("processing")?this.$el.hide():this.$el.show())}reset(){this.$el.val("all").hide()}attach(){return this.bulkActionSelector.after(this.$el),this.$el.hide(),this}selectWatermark(){this.controller.set("watermark",this.$el.val())}},f=class extends k{tagName(){return"p"}className(){return"ew-status"}template(){let e=this.status.get("text");if(this.status.get("processing")){const t=this.status.get("processed"),s=this.status.get("total"),i=`${t}/${s}`;let r=Math.floor(t/s*100);"string"==typeof e&&(e=e.replace("{counter}",i)),isNaN(r)&&(r=0),e=`${e} (${r}%)`}return e}constructor(e){super(e),this.status=this.controller.status(),this.listenTo(this.status,"change",this.update)}render(){super.render(),this.attach()}update(){this.bulkActionSelector.is(this.controller.get("select"))&&(this.status.get("text")?(this.$el.html(this.template()),this.$el.show()):this.$el.hide())}attach(){return this.bulkActionSelector.parent().append(this.$el),this.$el.hide(),this}},v=class extends k{constructor(e){super(e),this.model=e.model,this.listenTo(this.model,"processing:start",this.showSpinner),this.listenTo(this.model,"processing:done",this.reset),this.listenTo(this.model,"remove",this.deselect),this.controller.on("bulkAction:finished",this.reset,this)}showSpinner(){this.getSpinner().appendTo(this.$el.find("span.media-icon"))}getSpinner(){return this.spinner||(this.spinner=r()("<span>",{class:"spinner ew-spinner"})),this.spinner}reset(){this.spinner&&this.spinner.remove(),this.getStatus().text(""),this.$el.find('input[type="checkbox"]').click().prop("checked",!1)}deselect(){if(this.controller.status().get("processing"))return;let e;this.$el.find('input[type="checkbox"]').click().prop("checked",!1),Object(o.d)(this.model)?this.model.get("usedAsWatermark")?e=ew.i18n.usedAsWatermark:"restore"!==this.controller.get("action")||this.model.get("hasBackup")||(e=ew.i18n.noBackupAvailable):e=ew.i18n.notSupported,this.getStatus().text(` - ${e}`)}getStatus(){return this.status||(this.status=r()("<span>",{class:"ew-status"}),this.$el.find("strong.has-media-icon").append(this.status)),this.status}};class A extends m.Model{constructor(){super(),this.bulkActionsSelectors=r()("select#bulk-action-selector-top, select#bulk-action-selector-bottom"),this.bulkActionsSelectors.length&&this.init()}init(){this.selectBulkAction=this.selectBulkAction.bind(this),this.doAction=this.doAction.bind(this),this.form=r()("form#posts-filter"),this.actionButtons=this.form.find("#doaction, #doaction2"),this.bulkActionsSelectors.each((e,t)=>{const s=r()(t);new b({controller:this,bulkActionSelector:s}).render(),new f({controller:this,bulkActionSelector:s}).render()}).val(-1).on("change",this.selectBulkAction),this.set({attachments:new m.Collection,selection:new m.Collection}),this.actionButtons.on("click",this.doAction),this.on("bulkAction:start",()=>{this.bulkActionsSelectors.val(-1).prop("disabled",!0),this.actionButtons.prop("disabled",!0)}),this.on("bulkAction:finished",()=>{this.bulkActionsSelectors.prop("disabled",!1),this.actionButtons.prop("disabled",!1)})}selectBulkAction(e){const t=r()(e.target);this.set({select:t,action:t.val()})}doAction(e){const t=this.get("action");if(!this.checkAction(t))return;e.preventDefault();const s=this.get("watermark");if("watermark"===t&&!s)return;const i=this.form.find('input[name="media[]"]:checked');if(!i.length)return void this.status().set({text:ew.i18n.noItemsSelected});const o=this.get("attachments"),a=this.get("selection"),n=[];this.trigger("bulkAction:start"),i.each((e,t)=>{const s=r()(t).val(),i=o.get(s);i?a.add(i):n.push(s)}),n.length?(this.status().set({text:'<span class="spinner ew-spinner"></span>'}),r.a.ajax(ajaxurl,{data:{action:"easy-watermark/attachments-info",nonce:ew.attachmentsInfoNonce,attachments:n}}).done(e=>{if(!0===e.success){for(const t of e.data){const e=new m.Model(t);o.push(e),a.push(e),new v({el:`#post-${t.id}`,controller:this,model:e})}this.prepare()}else{const t=e.data.message?e.data.message:ew.i18n.genericErrorMessage;this.actionError(t)}}).fail(()=>{this.actionError(ew.i18n.genericErrorMessage)})):a.length&&this.prepare()}prepare(){const e=this.get("action"),t=this.get("selection"),s="restore"===e,i="watermark"===e?ew.i18n.watermarkingStatus:ew.i18n.restoringStatus,r="watermark"===e?ew.i18n.watermarkingSuccessMessage:ew.i18n.restoringSuccessMessage;if(Object(o.b)(t,s),!t.length)return this.status().set({successMessage:"watermark"===e?ew.i18n.watermarkingNoItems:ew.i18n.restoringNoItems}),void this.actionDone();this.status().set({successMessage:r,text:i,processing:!0,total:t.length,processed:0});for(const e of t.models)e.trigger("processing:start");this.doActionRecursive()}doActionRecursive(){const e=this.get("action"),t=this.get("watermark");let s,i="easy-watermark/";if("watermark"===e)i+="all"===t?"apply_all":"apply_single",s="all"===t?ew.applyAllNonce:ew.applySingleNonces[t];else{if("restore"!==e)return;i+="restore_backup",s=ew.restoreBackupNonce}const a=this.status(),n=this.get("selection"),l=n.shift(),c={action:i,nonce:s,watermark:t};let d=a.get("processed");c.attachment_id=l.get("id"),this.set("currentAttachmentID",c.attachment_id),r.a.ajax(ajaxurl,{data:c}).done(e=>{if(!0===e.success){if(e.data.attachmentVersion){const t=this.form.find("tr#post-"+c.attachment_id+" img"),s=Object(o.c)(t.attr("src"),e.data.attachmentVersion);t.attr({src:s,srcset:""})}d++,a.set({processed:d}),l.set("hasBackup",!!e.data.hasBackup),l.trigger("processing:done"),n.length?this.doActionRecursive():this.actionDone()}else{const t="string"==typeof e.data.message?e.data.message:ew.i18n.genericErrorMessage;this.actionError(t)}}).fail(()=>{this.actionError(ew.i18n.genericErrorMessage)})}actionError(e){this.status().set({error:e}),this.actionDone()}actionDone(){this.trigger("bulkAction:finished"),this.bulkActionsSelectors.prop("disabled",!1);const e=this.status(),t=e.get("processed"),s=e.get("error"),i=e.get("successMessage"),r=this.get("currentAttachmentID");if(t>0?Object(o.a)(i.replace("{procesed}",t),"success"):Object(o.a)(i,"info"),s){const e=this.form.find("tr#post-"+r).find(".column-title a").attr("aria-label"),t=ew.i18n.bulkActionErrorMessage.replace("{imageTitle}",e).replace("{error}",s);Object(o.a)(t,"error")}this.status().set({processing:!1,processed:0,total:0,text:""})}status(){let e=this.get("status");return void 0===e&&((e=new m.Model).set({processed:0,total:0}),this.set({status:e})),e}checkAction(e){return["watermark","restore"].includes(e)}}r()(document).ready(()=>new A)},2:function(e,t){e.exports=Backbone},30:function(e,t){}});
easy-watermark.php CHANGED
@@ -6,8 +6,8 @@
6
  * Author URI: https://bracketspace.com/
7
  * Text Domain: easy-watermark
8
  * Domain Path: /languages
9
- * Version: 1.0.3
10
- * License: GPLv2 or later
11
  *
12
  * @package easy-watermark
13
  */
6
  * Author URI: https://bracketspace.com/
7
  * Text Domain: easy-watermark
8
  * Domain Path: /languages
9
+ * Version: 1.0.4
10
+ * License: GPLv3 or later
11
  *
12
  * @package easy-watermark
13
  */
readme.txt CHANGED
@@ -5,9 +5,9 @@ Tags: watermark, image, picture, photo, media, gallery, signature, transparent,
5
  Requires at least: 3.8
6
  Requires PHP: 5.6
7
  Tested up to: 5.2
8
- Stable tag: 1.0.3
9
  License: GPLv3 or later
10
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
  Text Domain: easy-watermark
12
 
13
  Allows to add watermark to images automatically on upload or manually.
@@ -118,6 +118,12 @@ All available placeholders are listed in a box titled 'Placeholders' displayed w
118
 
119
  == Changelog ==
120
 
 
 
 
 
 
 
121
  = 1.0.3 =
122
  * [Fixed] FileBird compatibility
123
  * [Fixed] Frontend content builders compatibility
5
  Requires at least: 3.8
6
  Requires PHP: 5.6
7
  Tested up to: 5.2
8
+ Stable tag: 1.0.4
9
  License: GPLv3 or later
10
+ License URI: https://www.gnu.org/licenses/gpl-3.0.html
11
  Text Domain: easy-watermark
12
 
13
  Allows to add watermark to images automatically on upload or manually.
118
 
119
  == Changelog ==
120
 
121
+ = 1.0.4 =
122
+ * [Fixed] Improved error handling
123
+ * [Fixed] "Enhanced Media Library" plugin compatibility (and possibly some other plugins which replace media library components)
124
+ * [Fixed] Watermark delete error fixed
125
+ * [Fixed] Source set filtering improved
126
+
127
  = 1.0.3 =
128
  * [Fixed] FileBird compatibility
129
  * [Fixed] Frontend content builders compatibility
src/classes/AttachmentProcessor/AttachmentProcessorGD.php CHANGED
@@ -204,7 +204,7 @@ class AttachmentProcessorGD extends AttachmentProcessor {
204
  $this->output_image = imagecreatetruecolor( $text_size['width'], $text_size['height'] );
205
 
206
  if ( false === $this->output_image ) {
207
- return new WP_Error( 'gd_error', __( 'Something went wrong while creating output image.', 'easy-watermark' ) );
208
  }
209
 
210
  imagealphablending( $this->output_image, false );
@@ -279,6 +279,10 @@ class AttachmentProcessorGD extends AttachmentProcessor {
279
  // Create blank image.
280
  $this->output_image = imagecreatetruecolor( $image_size['width'], $image_size['height'] );
281
 
 
 
 
 
282
  if ( 'png' === $this->image_type && $this->is_alpha_png( $this->image_file ) ) {
283
  // Preserve opacity for png images.
284
  imagealphablending( $this->output_image, false );
@@ -364,6 +368,10 @@ class AttachmentProcessorGD extends AttachmentProcessor {
364
 
365
  $output_image = $this->get_output_image();
366
 
 
 
 
 
367
  $watermark_file = get_attached_file( $watermark->attachment_id );
368
 
369
  if ( ! $watermark_file || ! is_file( $watermark_file ) ) {
@@ -411,6 +419,10 @@ class AttachmentProcessorGD extends AttachmentProcessor {
411
  if ( isset( $new_width ) ) {
412
  $tmp_image = imagecreatetruecolor( $new_width, $new_height );
413
 
 
 
 
 
414
  if ( 'png' === $watermark_type && $this->is_alpha_png( $watermark_file ) ) {
415
  imagealphablending( $tmp_image, false );
416
  imagesavealpha( $tmp_image, true );
@@ -480,6 +492,10 @@ class AttachmentProcessorGD extends AttachmentProcessor {
480
 
481
  $output_image = $this->get_output_image();
482
 
 
 
 
 
483
  $font = Text::get_font_path( $watermark->font );
484
 
485
  if ( ! $font ) {
@@ -536,8 +552,7 @@ class AttachmentProcessorGD extends AttachmentProcessor {
536
  if ( empty( $type ) && $file_path ) {
537
  // Get finfo object to detect mime types.
538
  $finfo = $this->get_finfo();
539
-
540
- $type = $finfo->file( $file_path );
541
  }
542
 
543
  if ( ! $type ) {
204
  $this->output_image = imagecreatetruecolor( $text_size['width'], $text_size['height'] );
205
 
206
  if ( false === $this->output_image ) {
207
+ return new WP_Error( 'gd_error', __( 'Could not create output image.', 'easy-watermark' ) );
208
  }
209
 
210
  imagealphablending( $this->output_image, false );
279
  // Create blank image.
280
  $this->output_image = imagecreatetruecolor( $image_size['width'], $image_size['height'] );
281
 
282
+ if ( ! $this->output_image ) {
283
+ return false;
284
+ }
285
+
286
  if ( 'png' === $this->image_type && $this->is_alpha_png( $this->image_file ) ) {
287
  // Preserve opacity for png images.
288
  imagealphablending( $this->output_image, false );
368
 
369
  $output_image = $this->get_output_image();
370
 
371
+ if ( ! $output_image ) {
372
+ return new WP_Error( 'gd_error', __( 'Could not create output image. Please check your server configuration.', 'easy-watermark' ) );
373
+ }
374
+
375
  $watermark_file = get_attached_file( $watermark->attachment_id );
376
 
377
  if ( ! $watermark_file || ! is_file( $watermark_file ) ) {
419
  if ( isset( $new_width ) ) {
420
  $tmp_image = imagecreatetruecolor( $new_width, $new_height );
421
 
422
+ if ( ! $tmp_image ) {
423
+ return new WP_Error( 'gd_error', __( 'Could not create temporary image. Please check your server configuration.', 'easy-watermark' ) );
424
+ }
425
+
426
  if ( 'png' === $watermark_type && $this->is_alpha_png( $watermark_file ) ) {
427
  imagealphablending( $tmp_image, false );
428
  imagesavealpha( $tmp_image, true );
492
 
493
  $output_image = $this->get_output_image();
494
 
495
+ if ( ! $output_image ) {
496
+ return new WP_Error( 'gd_error', __( 'Could not create output image. Please check your server configuration.', 'easy-watermark' ) );
497
+ }
498
+
499
  $font = Text::get_font_path( $watermark->font );
500
 
501
  if ( ! $font ) {
552
  if ( empty( $type ) && $file_path ) {
553
  // Get finfo object to detect mime types.
554
  $finfo = $this->get_finfo();
555
+ $type = $finfo->file( $file_path );
 
556
  }
557
 
558
  if ( ! $type ) {
src/classes/Core/Installer.php CHANGED
@@ -60,10 +60,6 @@ class Installer {
60
  $admin->add_cap( 'delete_watermarks' );
61
  $admin->add_cap( 'apply_watermark' );
62
 
63
- add_rewrite_rule( 'easy-watermark-preview/([^/.-]+)-([0-9]+)-([^/.]+).(jpg|png)?', 'index.php?easy_watermark_preview=$matches[1]&watermark_id=$matches[2]&image_size=$matches[3]&format=$matches[4]', 'top' );
64
- add_rewrite_rule( 'easy-watermark-preview/([^/.-]+)-([0-9]+).(jpg|png)?', 'index.php?easy_watermark_preview=$matches[1]&watermark_id=$matches[2]&format=$matches[3]', 'top' );
65
- flush_rewrite_rules();
66
-
67
  }
68
 
69
  /**
@@ -72,6 +68,7 @@ class Installer {
72
  * @return void
73
  */
74
  public static function deactivate() {
 
75
  flush_rewrite_rules();
76
  }
77
 
60
  $admin->add_cap( 'delete_watermarks' );
61
  $admin->add_cap( 'apply_watermark' );
62
 
 
 
 
 
63
  }
64
 
65
  /**
68
  * @return void
69
  */
70
  public static function deactivate() {
71
+ delete_option( 'easy-watermark-first-booted' );
72
  flush_rewrite_rules();
73
  }
74
 
src/classes/Core/Plugin.php CHANGED
@@ -159,6 +159,18 @@ class Plugin extends Singleton {
159
  add_rewrite_tag( '%watermark_id%', '([0-9]+)' );
160
  add_rewrite_tag( '%image_size%', '([^./-]+)' );
161
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  $last_version = get_option( $this->slug . '-version' );
163
  if ( $this->version !== $last_version ) {
164
  // Version has changed. Update.
@@ -168,6 +180,20 @@ class Plugin extends Singleton {
168
 
169
  }
170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  /**
172
  * Initiates plugin
173
  *
159
  add_rewrite_tag( '%watermark_id%', '([0-9]+)' );
160
  add_rewrite_tag( '%image_size%', '([^./-]+)' );
161
 
162
+ add_rewrite_rule(
163
+ 'easy-watermark-preview/([^/.-]+)-([0-9]+)-([^/.]+).(jpg|png)?',
164
+ 'index.php?easy_watermark_preview=$matches[1]&watermark_id=$matches[2]&image_size=$matches[3]&format=$matches[4]',
165
+ 'top'
166
+ );
167
+
168
+ add_rewrite_rule(
169
+ 'easy-watermark-preview/([^/.-]+)-([0-9]+).(jpg|png)?',
170
+ 'index.php?easy_watermark_preview=$matches[1]&watermark_id=$matches[2]&format=$matches[3]',
171
+ 'top'
172
+ );
173
+
174
  $last_version = get_option( $this->slug . '-version' );
175
  if ( $this->version !== $last_version ) {
176
  // Version has changed. Update.
180
 
181
  }
182
 
183
+ /**
184
+ * Performs actions on shutdown
185
+ *
186
+ * @action shutdown
187
+ *
188
+ * @return void
189
+ */
190
+ public function shutdown() {
191
+ if ( ! get_option( 'easy-watermark-first-booted' ) ) {
192
+ flush_rewrite_rules();
193
+ update_option( 'easy-watermark-first-booted', true );
194
+ }
195
+ }
196
+
197
  /**
198
  * Initiates plugin
199
  *
src/classes/Features/SrcsetFilter.php CHANGED
@@ -63,9 +63,21 @@ class SrcsetFilter {
63
  );
64
 
65
  $description = implode( '<br/>', [
66
- esc_html_x( 'Srcset attribute contains information about other image sizes and lets the browser decide which image to display based on the screen size.', '"Filter srcset" setting description line 1', 'easy-watermark' ),
67
- esc_html_x( 'This is good in general but it might cause problems if some watermarks are applied only to certain image sizes.', '"Filter srcset" setting description line 2', 'easy-watermark' ),
68
- esc_html_x( 'With this option enabled srcset attribute will only contain image sizes watermarked the same way.', '"Filter srcset" setting description line 3', 'easy-watermark' ),
 
 
 
 
 
 
 
 
 
 
 
 
69
  ] );
70
 
71
  $this->switch = new SwitchField( [
@@ -101,7 +113,7 @@ class SrcsetFilter {
101
  $applied_watermarks = get_post_meta( $attachment_id, '_ew_applied_watermarks', true );
102
 
103
  if ( is_array( $applied_watermarks ) ) {
104
- $current_size = $this->get_current_size( $image_src, $image_meta['sizes'] );
105
  $allowed_sizes = $this->get_allowed_sizes( $applied_watermarks, $current_size );
106
 
107
  $image_meta['sizes'] = array_filter( $image_meta['sizes'], function( $key ) use ( $allowed_sizes ) {
@@ -140,14 +152,23 @@ class SrcsetFilter {
140
  * Gets image size for the image src
141
  *
142
  * @param string $image_src The 'src' of the image.
143
- * @param array $sizes Image sizes.
144
  * @return string|false
145
  */
146
- private function get_current_size( $image_src, $sizes ) {
147
 
148
  $image_src = basename( $image_src );
 
149
 
150
- foreach ( $sizes as $size => $params ) {
 
 
 
 
 
 
 
 
151
  if ( $image_src === $params['file'] ) {
152
  return $size;
153
  }
@@ -158,7 +179,7 @@ class SrcsetFilter {
158
  }
159
 
160
  /**
161
- * Filters applied watermarks to return only ones applied to the image size
162
  *
163
  * @param array $watermarks Applied watermarks.
164
  * @param string $current_size Currently displayed image size.
@@ -166,21 +187,27 @@ class SrcsetFilter {
166
  */
167
  private function get_allowed_sizes( $watermarks, $current_size ) {
168
 
169
- $sizes = [];
170
 
171
  foreach ( $watermarks as $watermark_id ) {
172
  $watermark = Watermark::get( $watermark_id );
173
 
174
- if ( in_array( $current_size, $watermark->image_sizes, true ) ) {
175
- $sizes[] = $watermark->image_sizes;
176
  }
177
- }
178
 
179
- if ( 1 === count( $sizes ) ) {
180
- return $sizes[0];
 
 
 
 
 
 
 
181
  }
182
 
183
- return $sizes ? call_user_func_array( 'array_intersect', $sizes ) : [];
184
 
185
  }
186
  }
63
  );
64
 
65
  $description = implode( '<br/>', [
66
+ esc_html_x(
67
+ 'Srcset attribute contains information about other image sizes and lets the browser decide which image to display based on the screen size.',
68
+ '"Filter srcset" setting description line 1',
69
+ 'easy-watermark'
70
+ ),
71
+ esc_html_x(
72
+ 'This is good in general but it might cause problems if some watermarks are applied only to certain image sizes.',
73
+ '"Filter srcset" setting description line 2',
74
+ 'easy-watermark'
75
+ ),
76
+ esc_html_x(
77
+ 'With this option enabled srcset attribute will only contain image sizes watermarked the same way.',
78
+ '"Filter srcset" setting description line 3',
79
+ 'easy-watermark'
80
+ ),
81
  ] );
82
 
83
  $this->switch = new SwitchField( [
113
  $applied_watermarks = get_post_meta( $attachment_id, '_ew_applied_watermarks', true );
114
 
115
  if ( is_array( $applied_watermarks ) ) {
116
+ $current_size = $this->get_current_size( $image_src, $image_meta );
117
  $allowed_sizes = $this->get_allowed_sizes( $applied_watermarks, $current_size );
118
 
119
  $image_meta['sizes'] = array_filter( $image_meta['sizes'], function( $key ) use ( $allowed_sizes ) {
152
  * Gets image size for the image src
153
  *
154
  * @param string $image_src The 'src' of the image.
155
+ * @param array $meta Image meta.
156
  * @return string|false
157
  */
158
+ private function get_current_size( $image_src, $meta ) {
159
 
160
  $image_src = basename( $image_src );
161
+ $pos = strpos( $image_src, '?v=' );
162
 
163
+ if ( $pos ) {
164
+ $image_src = substr( $image_src, 0, $pos );
165
+ }
166
+
167
+ if ( false !== strpos( $meta['file'], $image_src ) ) {
168
+ return 'full';
169
+ }
170
+
171
+ foreach ( $meta['sizes'] as $size => $params ) {
172
  if ( $image_src === $params['file'] ) {
173
  return $size;
174
  }
179
  }
180
 
181
  /**
182
+ * Filters image sizes
183
  *
184
  * @param array $watermarks Applied watermarks.
185
  * @param string $current_size Currently displayed image size.
187
  */
188
  private function get_allowed_sizes( $watermarks, $current_size ) {
189
 
190
+ $sizes = get_intermediate_image_sizes();
191
 
192
  foreach ( $watermarks as $watermark_id ) {
193
  $watermark = Watermark::get( $watermark_id );
194
 
195
+ if ( ! $watermark ) {
196
+ continue;
197
  }
 
198
 
199
+ $should_be = in_array( $current_size, $watermark->image_sizes, true );
200
+
201
+ foreach ( $sizes as $key => $size ) {
202
+ $is = in_array( $size, $watermark->image_sizes, true );
203
+
204
+ if ( ! ( $is * $should_be ) && ( $is || $should_be ) ) {
205
+ unset( $sizes[ $key ] );
206
+ }
207
+ }
208
  }
209
 
210
+ return $sizes;
211
 
212
  }
213
  }
src/classes/Metaboxes/Watermark/Preview.php CHANGED
@@ -132,7 +132,7 @@ class Preview extends WatermarkMetabox {
132
 
133
  $preview_image_id = get_option( '_ew_preview_image_id' );
134
 
135
- $base_image_src = site_url( 'easy-watermark-preview/image-%s-%s.png?t =%s' );
136
  $images = [];
137
  $sizes = [];
138
  $available_sizes = ImageHelper::get_available_sizes();
132
 
133
  $preview_image_id = get_option( '_ew_preview_image_id' );
134
 
135
+ $base_image_src = site_url( 'easy-watermark-preview/image-%s-%s.png?t=%s' );
136
  $images = [];
137
  $sizes = [];
138
  $available_sizes = ImageHelper::get_available_sizes();
src/classes/Watermark/PostType.php CHANGED
@@ -95,7 +95,7 @@ class PostType {
95
  *
96
  * @filter parent_file
97
  *
98
- * @since [Next]
99
  * @param string $parent_file Parent file.
100
  * @return string
101
  */
@@ -211,7 +211,7 @@ class PostType {
211
  * @return void
212
  */
213
  public function delete_post( $post_id ) {
214
- global $post;
215
 
216
  if ( 'watermark' === $post->post_type ) {
217
  $watermark = Watermark::get( $post );
95
  *
96
  * @filter parent_file
97
  *
98
+ * @since 1.0.4
99
  * @param string $parent_file Parent file.
100
  * @return string
101
  */
211
  * @return void
212
  */
213
  public function delete_post( $post_id ) {
214
+ $post = get_post( $post_id );
215
 
216
  if ( 'watermark' === $post->post_type ) {
217
  $watermark = Watermark::get( $post );
src/views/dashboard/pages/watermarks.php CHANGED
@@ -13,6 +13,7 @@
13
  <?php /* translators: watermark name */ ?>
14
  <h3>
15
  <?php if ( current_user_can( 'edit_others_watermarks' ) || get_current_user_id() === (int) $watermark->post_author ) : ?>
 
16
  <a href="<?php echo esc_url( get_edit_post_link( $watermark->ID ) ); ?>" aria-label="<?php esc_attr_e( sprintf( 'Edit “%s”', $watermark->post_title ) ); ?>"><?php echo esc_html( $watermark->post_title ); ?></a>
17
  <?php else : ?>
18
  <?php echo esc_html( $watermark->post_title ); ?>
13
  <?php /* translators: watermark name */ ?>
14
  <h3>
15
  <?php if ( current_user_can( 'edit_others_watermarks' ) || get_current_user_id() === (int) $watermark->post_author ) : ?>
16
+ <?php /* translators: %s is watermark title */ ?>
17
  <a href="<?php echo esc_url( get_edit_post_link( $watermark->ID ) ); ?>" aria-label="<?php esc_attr_e( sprintf( 'Edit “%s”', $watermark->post_title ) ); ?>"><?php echo esc_html( $watermark->post_title ); ?></a>
18
  <?php else : ?>
19
  <?php echo esc_html( $watermark->post_title ); ?>