Easy Watermark - Version 1.0.8

Version Description

  • [Added] New form styles compatible with new WordPress form styles.
  • [Added] Option to disable cache buster responsible for adding version param to image urls.
  • [Fixed] Watermark preview.
Download this release

Release Info

Developer Kubitomakita
Plugin Icon Easy Watermark
Version 1.0.8
Comparing to
See all releases

Code changes from version 1.0.7 to 1.0.8

Files changed (85) hide show
  1. assets/dist/scripts/attachment-edit.js +1 -1
  2. assets/dist/scripts/dashboard.js +1 -1
  3. assets/dist/scripts/media-library.js +1 -1
  4. assets/dist/scripts/watermark-edit.js +1 -1
  5. assets/dist/styles/watermark-edit.css +1 -1
  6. assets/src/scripts/controllers/bulk-actions.js +322 -322
  7. assets/src/scripts/controllers/media-frame.js +211 -211
  8. assets/src/scripts/includes/vex.js +56 -56
  9. assets/src/scripts/metaboxes/attachment/watermarks.js +83 -83
  10. assets/src/scripts/metaboxes/watermark/content.js +193 -188
  11. assets/src/scripts/metaboxes/watermark/preview.js +171 -173
  12. assets/src/scripts/pages/bulk-actions.js +322 -322
  13. assets/src/scripts/pages/tools.js +192 -192
  14. assets/src/scripts/pages/watermarks.js +44 -44
  15. assets/src/scripts/uploader.js +49 -49
  16. assets/src/scripts/utils/form-fields.js +64 -60
  17. assets/src/scripts/utils/functions.js +79 -67
  18. assets/src/scripts/views/media-grid/attachment.js +100 -100
  19. assets/src/scripts/views/media-grid/attachments-browser.js +89 -89
  20. assets/src/scripts/views/media-grid/buttons/restore.js +66 -66
  21. assets/src/scripts/views/media-grid/buttons/watermark-mode-toggle.js +79 -79
  22. assets/src/scripts/views/media-grid/buttons/watermark.js +51 -51
  23. assets/src/scripts/views/media-grid/filters.js +45 -45
  24. assets/src/scripts/views/media-grid/select-mode-toggle.js +32 -32
  25. assets/src/scripts/views/media-grid/status.js +66 -66
  26. assets/src/scripts/views/media-grid/watermark-selector.js +70 -70
  27. assets/src/scripts/views/media-list/attachment.js +76 -76
  28. assets/src/scripts/views/media-list/watermark-selector.js +79 -79
  29. assets/src/scripts/watermark-edit.js +90 -90
  30. assets/src/styles/_general.scss +85 -1
  31. bin/dump-hooks.php +71 -71
  32. easy-watermark.php +1 -1
  33. index.php +20 -20
  34. readme.txt +6 -1
  35. src/classes/AttachmentProcessor/AttachmentProcessorGD.php +7 -4
  36. src/classes/Core/Assets.php +332 -313
  37. src/classes/Core/Installer.php +494 -492
  38. src/classes/Core/Plugin.php +11 -41
  39. src/classes/Core/View.php +131 -131
  40. src/classes/Dashboard/Dashboard.php +162 -162
  41. src/classes/Dashboard/Permissions.php +134 -134
  42. src/classes/Dashboard/Settings.php +39 -56
  43. src/classes/Dashboard/Tools.php +122 -122
  44. src/classes/Dashboard/Watermarks.php +61 -61
  45. src/classes/Features/AutoWatermarkSwitch.php +58 -58
  46. src/classes/Features/CacheBusting.php +147 -0
  47. src/classes/Features/SrcsetFilter.php +181 -213
  48. src/classes/Features/WatermarkPreview.php +152 -0
  49. src/classes/Helpers/Image.php +57 -57
  50. src/classes/Helpers/Text.php +55 -55
  51. src/classes/Metaboxes/Metabox.php +153 -153
  52. src/classes/Metaboxes/Watermark/ApplyingRules.php +47 -47
  53. src/classes/Metaboxes/Watermark/Preview.php +154 -157
  54. src/classes/Metaboxes/Watermark/TextOptions.php +44 -44
  55. src/classes/Placeholders/Abstracts/Placeholder.php +201 -201
  56. src/classes/Placeholders/Abstracts/StringPlaceholder.php +41 -41
  57. src/classes/Placeholders/Abstracts/UrlPlaceholder.php +41 -41
  58. src/classes/Placeholders/Blog/AdminEmail.php +39 -39
  59. src/classes/Placeholders/Blog/BlogName.php +39 -39
  60. src/classes/Placeholders/Blog/BlogUrl.php +39 -39
  61. src/classes/Placeholders/DateTime/Date.php +39 -39
  62. src/classes/Placeholders/DateTime/Time.php +39 -39
  63. src/classes/Settings/Field.php +241 -241
  64. src/classes/Settings/Fields/SwitchField.php +28 -28
  65. src/classes/Settings/Section.php +170 -170
  66. src/classes/Traits/Hookable.php +114 -114
  67. src/classes/Watermark/Ajax.php +281 -281
  68. src/classes/Watermark/Handler.php +503 -522
  69. src/classes/Watermark/Hooks.php +160 -188
  70. src/classes/Watermark/PostType.php +515 -515
  71. src/classes/Watermark/Preview.php +91 -91
  72. src/classes/Watermark/Watermark.php +262 -262
  73. src/inc/functions.php +35 -35
  74. src/inc/hooks.php +21 -21
  75. src/views/dashboard/pages/tools.php +67 -55
  76. src/views/dashboard/pages/watermarks.php +55 -50
  77. src/views/edit-screen/metaboxes/watermark/preview.php +21 -19
  78. src/views/edit-screen/metaboxes/watermark/watermark-content.php +53 -51
  79. src/views/upload/switch.php +15 -15
  80. vendor/autoload.php +1 -1
  81. vendor/composer/InstalledVersions.php +6 -6
  82. vendor/composer/autoload_classmap.php +117 -0
  83. vendor/composer/autoload_real.php +4 -4
  84. vendor/composer/autoload_static.php +122 -5
  85. vendor/composer/installed.php +6 -6
assets/dist/scripts/attachment-edit.js CHANGED
@@ -1 +1 @@
1
- !function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="../",n(n.s=21)}({0:function(t,e){t.exports=jQuery},1:function(t,e,n){"use strict";n.d(e,"a",(function(){return u})),n.d(e,"b",(function(){return c})),n.d(e,"c",(function(){return f})),n.d(e,"d",(function(){return l}));var r=n(0),o=n.n(r);function a(t){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return s(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return s(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,u=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return i=t.done,t},e:function(t){u=!0,a=t},f:function(){try{i||null==n.return||n.return()}finally{if(u)throw a}}}}function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function u(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"info",n=o()(document.createElement("div")),r=o()(document.createElement("p")),a=o()(document.createElement("button"));n.addClass("notice notice-"+e+" is-dismissible").hide(),a.addClass("notice-dismiss"),r.html(t),n.append(r).append(a),a.on("click",(function(t){t.preventDefault(),n.fadeOut(200,(function(){n.remove()}))})),o()("hr.wp-header-end").after(n),n.fadeIn(200)}function c(t){var e,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],o=t.length,a=i(t.clone().models);try{for(a.s();!(e=a.n()).done;){var s=e.value;(!l(s)||s.get("usedAsWatermark")||!0===n&&!s.get("hasBackup"))&&(!0===r&&t.remove(s),o--)}}catch(t){a.e(t)}finally{a.f()}return o}function f(t,e){var n=t.indexOf("?");return-1!==n&&(t=t.substr(0,n)),t+="?v="+e}function l(t){return"object"===a(t)&&t.get&&(t=t.get("mime")),Object.keys(ew.mime).includes(t)}},21:function(t,e,n){"use strict";n.r(e);n(28);var r=n(0),o=n.n(r),a=n(1);function i(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}new(function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.handleClick=this.handleClick.bind(this),this.metabox=o()("#watermarks"),this.metaboxContent=this.metabox.find(".watermarks-metabox"),this.errorMessage=this.metabox.find(".error-message"),this.spinners=this.metabox.find(".spinner"),this.buttons=this.metabox.find("button"),this.form=o()("form#post"),this.postID=this.form.find("#post_ID").val(),this.headerEnd=o()("hr.wp-header-end"),this.image=o()(".wp_attachment_image img.thumbnail"),this.metabox.on("click","button",this.handleClick)}var e,n,r;return e=t,(n=[{key:"handleClick",value:function(t){var e=this;t.preventDefault();var n=o()(t.target),r=n.data("action");this.buttons.prop("disabled",!0),n.next(".spinner").css("visibility","visible"),this.errorMessage.hide();var i={action:"easy-watermark/"+r,nonce:n.data("nonce"),attachment_id:this.postID};"apply_single"===r&&(i.watermark=n.data("watermark")),o.a.ajax(ajaxurl,{data:i}).done((function(t){if(!0===t.success){if(e.metaboxContent.replaceWith(t.data.metaboxContent),e.metaboxContent=e.metabox.find(".watermarks-metabox"),e.errorMessage=e.metabox.find(".error-message"),e.spinners=e.metabox.find(".spinner"),e.buttons=e.metabox.find("button"),t.data.attachmentVersion){var n=Object(a.c)(e.image.attr("src"),t.data.attachmentVersion);e.image.attr("src",n),"string"==typeof t.data.message&&Object(a.a)(t.data.message,"success")}}else{var r="string"==typeof t.data.message?t.data.message:ew.genericErrorMessage;Object(a.a)(r,"error")}})).fail((function(){Object(a.a)(ew.genericErrorMessage,"error")})).complete((function(){e.spinners.css("visibility","hidden"),e.buttons.prop("disabled",!1)}))}}])&&i(e.prototype,n),r&&i(e,r),t}())},28:function(t,e){}});
1
+ !function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="../",n(n.s=21)}({0:function(t,e){t.exports=jQuery},1:function(t,e,n){"use strict";n.d(e,"a",(function(){return c})),n.d(e,"b",(function(){return u})),n.d(e,"c",(function(){return f})),n.d(e,"d",(function(){return l}));var r=n(0),o=n.n(r);function a(t){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return s(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return s(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,c=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return i=t.done,t},e:function(t){c=!0,a=t},f:function(){try{i||null==n.return||n.return()}finally{if(c)throw a}}}}function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function c(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"info",n=o()(document.createElement("div")),r=o()(document.createElement("p")),a=o()(document.createElement("button"));n.addClass("notice notice-"+e+" is-dismissible").hide(),a.addClass("notice-dismiss"),r.html(t),n.append(r).append(a),a.on("click",(function(t){t.preventDefault(),n.fadeOut(200,(function(){n.remove()}))})),o()("hr.wp-header-end").after(n),n.fadeIn(200)}function u(t){var e,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],o=t.length,a=i(t.clone().models);try{for(a.s();!(e=a.n()).done;){var s=e.value;(!l(s)||s.get("usedAsWatermark")||!0===n&&!s.get("hasBackup"))&&(!0===r&&t.remove(s),o--)}}catch(t){a.e(t)}finally{a.f()}return o}function f(t){var e,n=t.indexOf("?"),r="t=".concat(Date.now());if(-1!==n){e=t.substr(n),t=t.substr(0,n);var o=/([^\s])t=[0-9]+/;e.match(o)?e=e.replace(o,"$1".concat(r)):e+="&".concat(r)}else e="?".concat(r);return t+e}function l(t){return"object"===a(t)&&t.get&&(t=t.get("mime")),Object.keys(ew.mime).includes(t)}},21:function(t,e,n){"use strict";n.r(e);n(28);var r=n(0),o=n.n(r),a=n(1);function i(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}new(function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.handleClick=this.handleClick.bind(this),this.metabox=o()("#watermarks"),this.metaboxContent=this.metabox.find(".watermarks-metabox"),this.errorMessage=this.metabox.find(".error-message"),this.spinners=this.metabox.find(".spinner"),this.buttons=this.metabox.find("button"),this.form=o()("form#post"),this.postID=this.form.find("#post_ID").val(),this.headerEnd=o()("hr.wp-header-end"),this.image=o()(".wp_attachment_image img.thumbnail"),this.metabox.on("click","button",this.handleClick)}var e,n,r;return e=t,(n=[{key:"handleClick",value:function(t){var e=this;t.preventDefault();var n=o()(t.target),r=n.data("action");this.buttons.prop("disabled",!0),n.next(".spinner").css("visibility","visible"),this.errorMessage.hide();var i={action:"easy-watermark/"+r,nonce:n.data("nonce"),attachment_id:this.postID};"apply_single"===r&&(i.watermark=n.data("watermark")),o.a.ajax(ajaxurl,{data:i}).done((function(t){if(!0===t.success){if(e.metaboxContent.replaceWith(t.data.metaboxContent),e.metaboxContent=e.metabox.find(".watermarks-metabox"),e.errorMessage=e.metabox.find(".error-message"),e.spinners=e.metabox.find(".spinner"),e.buttons=e.metabox.find("button"),t.data.attachmentVersion){var n=Object(a.c)(e.image.attr("src"),t.data.attachmentVersion);e.image.attr("src",n),"string"==typeof t.data.message&&Object(a.a)(t.data.message,"success")}}else{var r="string"==typeof t.data.message?t.data.message:ew.genericErrorMessage;Object(a.a)(r,"error")}})).fail((function(){Object(a.a)(ew.genericErrorMessage,"error")})).complete((function(){e.spinners.css("visibility","hidden"),e.buttons.prop("disabled",!1)}))}}])&&i(e.prototype,n),r&&i(e,r),t}())},28:function(t,e){}});
assets/dist/scripts/dashboard.js CHANGED
@@ -1,3 +1,3 @@
1
- !function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="../",n(n.s=20)}([function(t,e){t.exports=jQuery},function(t,e,n){"use strict";n.d(e,"a",(function(){return c})),n.d(e,"b",(function(){return l})),n.d(e,"c",(function(){return u})),n.d(e,"d",(function(){return f}));var o=n(0),r=n.n(o);function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function a(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return s(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return s(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=new Array(e);n<e;n++)o[n]=t[n];return o}function c(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"info",n=r()(document.createElement("div")),o=r()(document.createElement("p")),i=r()(document.createElement("button"));n.addClass("notice notice-"+e+" is-dismissible").hide(),i.addClass("notice-dismiss"),o.html(t),n.append(o).append(i),i.on("click",(function(t){t.preventDefault(),n.fadeOut(200,(function(){n.remove()}))})),r()("hr.wp-header-end").after(n),n.fadeIn(200)}function l(t){var e,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],o=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=t.length,i=a(t.clone().models);try{for(i.s();!(e=i.n()).done;){var s=e.value;(!f(s)||s.get("usedAsWatermark")||!0===n&&!s.get("hasBackup"))&&(!0===o&&t.remove(s),r--)}}catch(t){i.e(t)}finally{i.f()}return r}function u(t,e){var n=t.indexOf("?");return-1!==n&&(t=t.substr(0,n)),t+="?v="+e}function f(t){return"object"===i(t)&&t.get&&(t=t.get("mime")),Object.keys(ew.mime).includes(t)}},function(t,e){t.exports=Backbone},function(t,e,n){var o=n(5);o.registerPlugin(n(9)),t.exports=o},,function(t,e,n){n(6),n(7).polyfill();var o=n(8),r=function(t){if(void 0!==t){var e=document.createElement("div");return e.appendChild(document.createTextNode(t)),e.innerHTML}return""},i=function(t,e){if("string"==typeof e&&0!==e.length)for(var n=e.split(" "),o=0;o<n.length;o++){var r=n[o];r.length&&t.classList.add(r)}},a=function(){var t=document.createElement("div"),e={animation:"animationend",WebkitAnimation:"webkitAnimationEnd",MozAnimation:"animationend",OAnimation:"oanimationend",msAnimation:"MSAnimationEnd"};for(var n in e)if(void 0!==t.style[n])return e[n];return!1}(),s="vex",c="vex-content",l="vex-overlay",u="vex-close",f="vex-closing",p="vex-open",d={},h=1,b=!1,v={open:function(t){var e=function(t){console.warn('The "'+t+'" property is deprecated in vex 3. Use CSS classes and the appropriate "ClassName" options, instead.'),console.warn("See http://github.hubspot.com/vex/api/advanced/#options")};t.css&&e("css"),t.overlayCSS&&e("overlayCSS"),t.contentCSS&&e("contentCSS"),t.closeCSS&&e("closeCSS");var n={};n.id=h++,d[n.id]=n,n.isOpen=!0,n.close=function(){if(!this.isOpen)return!0;var t=this.options;if(b&&!t.escapeButtonCloses)return!1;if(!1===function(){return!t.beforeClose||t.beforeClose.call(this)}.bind(this)())return!1;this.isOpen=!1;var e=window.getComputedStyle(this.contentEl);function n(t){return"none"!==e.getPropertyValue(t+"animation-name")&&"0s"!==e.getPropertyValue(t+"animation-duration")}var o=n("")||n("-webkit-")||n("-moz-")||n("-o-"),r=function e(){this.rootEl.parentNode&&(this.rootEl.removeEventListener(a,e),this.overlayEl.removeEventListener(a,e),delete d[this.id],this.rootEl.parentNode.removeChild(this.rootEl),this.bodyEl.removeChild(this.overlayEl),t.afterClose&&t.afterClose.call(this),0===Object.keys(d).length&&document.body.classList.remove(p))}.bind(this);return a&&o?(this.rootEl.addEventListener(a,r),this.overlayEl.addEventListener(a,r),this.rootEl.classList.add(f),this.overlayEl.classList.add(f)):r(),!0},"string"==typeof t&&(t={content:t}),t.unsafeContent&&!t.content?t.content=t.unsafeContent:t.content&&(t.content=r(t.content));var m=n.options=Object.assign({},v.defaultOptions,t),y=n.bodyEl=document.getElementsByTagName("body")[0],g=n.rootEl=document.createElement("div");g.classList.add(s),i(g,m.className);var w=n.overlayEl=document.createElement("div");w.classList.add(l),i(w,m.overlayClassName),m.overlayClosesOnClick&&g.addEventListener("click",(function(t){t.target===g&&n.close()})),y.appendChild(w);var k=n.contentEl=document.createElement("div");if(k.classList.add(c),i(k,m.contentClassName),k.appendChild(m.content instanceof window.Node?m.content:o(m.content)),g.appendChild(k),m.showCloseButton){var x=n.closeEl=document.createElement("div");x.classList.add(u),i(x,m.closeClassName),x.addEventListener("click",n.close.bind(n)),k.appendChild(x)}return document.querySelector(m.appendLocation).appendChild(g),m.afterOpen&&m.afterOpen.call(n),document.body.classList.add(p),n},close:function(t){var e;if(t.id)e=t.id;else{if("string"!=typeof t)throw new TypeError("close requires a vex object or id string");e=t}return!!d[e]&&d[e].close()},closeTop:function(){var t=Object.keys(d);return!!t.length&&d[t[t.length-1]].close()},closeAll:function(){for(var t in d)this.close(t);return!0},getAll:function(){return d},getById:function(t){return d[t]}};window.addEventListener("keyup",(function(t){27===t.keyCode&&(b=!0,v.closeTop(),b=!1)})),window.addEventListener("popstate",(function(){v.defaultOptions.closeAllOnPopState&&v.closeAll()})),v.defaultOptions={content:"",showCloseButton:!0,escapeButtonCloses:!0,overlayClosesOnClick:!0,appendLocation:"body",className:"",overlayClassName:"",contentClassName:"",closeClassName:"",closeAllOnPopState:!0},Object.defineProperty(v,"_escapeHtml",{configurable:!1,enumerable:!1,writable:!1,value:r}),v.registerPlugin=function(t,e){var n=t(v),o=e||n.name;if(v[o])throw new Error("Plugin "+e+" is already registered.");v[o]=n},t.exports=v},function(t,e){
2
  /*! @source http://purl.eligrey.com/github/classList.js/blob/master/classList.js */
3
  "document"in window.self&&((!("classList"in document.createElement("_"))||document.createElementNS&&!("classList"in document.createElementNS("http://www.w3.org/2000/svg","g")))&&function(t){"use strict";if("Element"in t){var e=t.Element.prototype,n=Object,o=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},r=Array.prototype.indexOf||function(t){for(var e=0,n=this.length;e<n;e++)if(e in this&&this[e]===t)return e;return-1},i=function(t,e){this.name=t,this.code=DOMException[t],this.message=e},a=function(t,e){if(""===e)throw new i("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(e))throw new i("INVALID_CHARACTER_ERR","String contains an invalid character");return r.call(t,e)},s=function(t){for(var e=o.call(t.getAttribute("class")||""),n=e?e.split(/\s+/):[],r=0,i=n.length;r<i;r++)this.push(n[r]);this._updateClassName=function(){t.setAttribute("class",this.toString())}},c=s.prototype=[],l=function(){return new s(this)};if(i.prototype=Error.prototype,c.item=function(t){return this[t]||null},c.contains=function(t){return-1!==a(this,t+="")},c.add=function(){var t,e=arguments,n=0,o=e.length,r=!1;do{t=e[n]+"",-1===a(this,t)&&(this.push(t),r=!0)}while(++n<o);r&&this._updateClassName()},c.remove=function(){var t,e,n=arguments,o=0,r=n.length,i=!1;do{for(t=n[o]+"",e=a(this,t);-1!==e;)this.splice(e,1),i=!0,e=a(this,t)}while(++o<r);i&&this._updateClassName()},c.toggle=function(t,e){t+="";var n=this.contains(t),o=n?!0!==e&&"remove":!1!==e&&"add";return o&&this[o](t),!0===e||!1===e?e:!n},c.toString=function(){return this.join(" ")},n.defineProperty){var u={get:l,enumerable:!0,configurable:!0};try{n.defineProperty(e,"classList",u)}catch(t){void 0!==t.number&&-2146823252!==t.number||(u.enumerable=!1,n.defineProperty(e,"classList",u))}}else n.prototype.__defineGetter__&&e.__defineGetter__("classList",l)}}(window.self),function(){"use strict";var t=document.createElement("_");if(t.classList.add("c1","c2"),!t.classList.contains("c2")){var e=function(t){var e=DOMTokenList.prototype[t];DOMTokenList.prototype[t]=function(t){var n,o=arguments.length;for(n=0;n<o;n++)t=arguments[n],e.call(this,t)}};e("add"),e("remove")}if(t.classList.toggle("c3",!1),t.classList.contains("c3")){var n=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(t,e){return 1 in arguments&&!this.contains(t)==!e?e:n.call(this,t)}}t=null}())},function(t,e,n){"use strict";function o(t,e){if(null==t)throw new TypeError("Cannot convert first argument to object");for(var n=Object(t),o=1;o<arguments.length;o++){var r=arguments[o];if(null!=r)for(var i=Object.keys(Object(r)),a=0,s=i.length;a<s;a++){var c=i[a],l=Object.getOwnPropertyDescriptor(r,c);void 0!==l&&l.enumerable&&(n[c]=r[c])}}return n}t.exports={assign:o,polyfill:function(){Object.assign||Object.defineProperty(Object,"assign",{enumerable:!1,configurable:!0,writable:!0,value:o})}}},function(t,e){t.exports=function(t,e){if("string"!=typeof t)throw new TypeError("String expected");e||(e=document);var n=/<([\w:]+)/.exec(t);if(!n)return e.createTextNode(t);t=t.replace(/^\s+|\s+$/g,"");var o=n[1];if("body"==o){return(i=e.createElement("html")).innerHTML=t,i.removeChild(i.lastChild)}var i,a=r[o]||r._default,s=a[0],c=a[1],l=a[2];(i=e.createElement("div")).innerHTML=c+t+l;for(;s--;)i=i.lastChild;if(i.firstChild==i.lastChild)return i.removeChild(i.firstChild);var u=e.createDocumentFragment();for(;i.firstChild;)u.appendChild(i.removeChild(i.firstChild));return u};var n,o=!1;"undefined"!=typeof document&&((n=document.createElement("div")).innerHTML=' <link/><table></table><a href="/a">a</a><input type="checkbox"/>',o=!n.getElementsByTagName("link").length,n=void 0);var r={legend:[1,"<fieldset>","</fieldset>"],tr:[2,"<table><tbody>","</tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],_default:o?[1,"X<div>","</div>"]:[0,"",""]};r.td=r.th=[3,"<table><tbody><tr>","</tr></tbody></table>"],r.option=r.optgroup=[1,'<select multiple="multiple">',"</select>"],r.thead=r.tbody=r.colgroup=r.caption=r.tfoot=[1,"<table>","</table>"],r.polyline=r.ellipse=r.polygon=r.circle=r.text=r.line=r.path=r.rect=r.g=[1,'<svg xmlns="http://www.w3.org/2000/svg" version="1.1">',"</svg>"]},function(t,e,n){t.exports=function t(e,n,o){function r(a,s){if(!n[a]){if(!e[a]){if(i)return i(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var l=n[a]={exports:{}};e[a][0].call(l.exports,(function(t){var n=e[a][1][t];return r(n||t)}),l,l.exports,t,e,n,o)}return n[a].exports}for(var i=!1,a=0;a<o.length;a++)r(o[a]);return r}({1:[function(t,e,n){"use strict";e.exports=function t(e){if(!e||"object"!=typeof e)return e;if("[object Date]"==Object.prototype.toString.call(e))return new Date(e.getTime());if(Array.isArray(e))return e.map(t);var n={};return Object.keys(e).forEach((function(o){n[o]=t(e[o])})),n}},{}],2:[function(t,e,n){e.exports=function(t,e){if("string"!=typeof t)throw new TypeError("String expected");e||(e=document);var n=/<([\w:]+)/.exec(t);if(!n)return e.createTextNode(t);t=t.replace(/^\s+|\s+$/g,"");var o=n[1];if("body"==o)return(r=e.createElement("html")).innerHTML=t,r.removeChild(r.lastChild);var r,a=i[o]||i._default,s=a[0],c=a[1],l=a[2];for((r=e.createElement("div")).innerHTML=c+t+l;s--;)r=r.lastChild;if(r.firstChild==r.lastChild)return r.removeChild(r.firstChild);for(var u=e.createDocumentFragment();r.firstChild;)u.appendChild(r.removeChild(r.firstChild));return u};var o,r=!1;"undefined"!=typeof document&&((o=document.createElement("div")).innerHTML=' <link/><table></table><a href="/a">a</a><input type="checkbox"/>',r=!o.getElementsByTagName("link").length,o=void 0);var i={legend:[1,"<fieldset>","</fieldset>"],tr:[2,"<table><tbody>","</tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],_default:r?[1,"X<div>","</div>"]:[0,"",""]};i.td=i.th=[3,"<table><tbody><tr>","</tr></tbody></table>"],i.option=i.optgroup=[1,'<select multiple="multiple">',"</select>"],i.thead=i.tbody=i.colgroup=i.caption=i.tfoot=[1,"<table>","</table>"],i.polyline=i.ellipse=i.polygon=i.circle=i.text=i.line=i.path=i.rect=i.g=[1,'<svg xmlns="http://www.w3.org/2000/svg" version="1.1">',"</svg>"]},{}],3:[function(t,e,n){var o=/^(?:submit|button|image|reset|file)$/i,r=/^(?:input|select|textarea|keygen)/i,i=/(\[[^\[\]]*\])/g;function a(t,e,n){if(e.match(i))!function t(e,n,o){if(0===n.length)return e=o;var r=n.shift(),i=r.match(/^\[(.+?)\]$/);if("[]"===r)return e=e||[],Array.isArray(e)?e.push(t(null,n,o)):(e._values=e._values||[],e._values.push(t(null,n,o))),e;if(i){var a=i[1],s=+a;isNaN(s)?(e=e||{})[a]=t(e[a],n,o):(e=e||[])[s]=t(e[s],n,o)}else e[r]=t(e[r],n,o);return e}(t,function(t){var e=[],n=new RegExp(i),o=/^([^\[\]]*)/.exec(t);for(o[1]&&e.push(o[1]);null!==(o=n.exec(t));)e.push(o[1]);return e}(e),n);else{var o=t[e];o?(Array.isArray(o)||(t[e]=[o]),t[e].push(n)):t[e]=n}return t}function s(t,e,n){return n=n.replace(/(\r)?\n/g,"\r\n"),n=(n=encodeURIComponent(n)).replace(/%20/g,"+"),t+(t?"&":"")+encodeURIComponent(e)+"="+n}e.exports=function(t,e){"object"!=typeof e?e={hash:!!e}:void 0===e.hash&&(e.hash=!0);for(var n=e.hash?{}:"",i=e.serializer||(e.hash?a:s),c=t&&t.elements?t.elements:[],l=Object.create(null),u=0;u<c.length;++u){var f=c[u];if((e.disabled||!f.disabled)&&f.name&&r.test(f.nodeName)&&!o.test(f.type)){var p=f.name,d=f.value;if("checkbox"!==f.type&&"radio"!==f.type||f.checked||(d=void 0),e.empty){if("checkbox"!==f.type||f.checked||(d=""),"radio"===f.type&&(l[f.name]||f.checked?f.checked&&(l[f.name]=!0):l[f.name]=!1),!d&&"radio"==f.type)continue}else if(!d)continue;if("select-multiple"!==f.type)n=i(n,p,d);else{d=[];for(var h=f.options,b=!1,v=0;v<h.length;++v){var m=h[v],y=e.empty&&!m.value,g=m.value||y;m.selected&&g&&(b=!0,n=e.hash&&"[]"!==p.slice(p.length-2)?i(n,p+"[]",m.value):i(n,p,m.value))}!b&&e.empty&&(n=i(n,p,""))}}}if(e.empty)for(var p in l)l[p]||(n=i(n,p,""));return n}},{}],4:[function(t,e,n){var o=t("domify"),r=t("form-serialize"),i=t("deep-clone-simple"),a=function(t){var e=document.createElement("div");e.classList.add("vex-dialog-buttons");for(var n=0;n<t.length;n++){var o=t[n],r=document.createElement("button");r.type=o.type,r.textContent=o.text,r.className=o.className,r.classList.add("vex-dialog-button"),0===n?r.classList.add("vex-first"):n===t.length-1&&r.classList.add("vex-last"),function(t){r.addEventListener("click",function(e){t.click&&t.click.call(this,e)}.bind(this))}.bind(this)(o),e.appendChild(r)}return e};e.exports=function(t){var e={name:"dialog",open:function(e){var n=Object.assign({},i(this.defaultOptions),e);n.unsafeMessage&&!n.message?n.message=n.unsafeMessage:n.message&&(n.message=t._escapeHtml(n.message));var r=n.unsafeContent=function(t){var e=document.createElement("form");e.classList.add("vex-dialog-form");var n=document.createElement("div");n.classList.add("vex-dialog-message"),n.appendChild(t.message instanceof window.Node?t.message:o(t.message));var r=document.createElement("div");return r.classList.add("vex-dialog-input"),r.appendChild(t.input instanceof window.Node?t.input:o(t.input)),e.appendChild(n),e.appendChild(r),e}(n),s=t.open(n);""!==n.yesText&&(n.buttons[0].text=n.yesText),""!==n.noText&&(n.buttons[1].text=n.noText);var c=n.beforeClose&&n.beforeClose.bind(s);if(s.options.beforeClose=function(){var t=!c||c();return t&&n.callback(this.value||!1),t}.bind(s),r.appendChild(a.call(s,n.buttons)),s.form=r,r.addEventListener("submit",n.onSubmit.bind(s)),n.focusFirstInput){var l=s.contentEl.querySelector("button, input, select, textarea");l&&l.focus()}return s},alert:function(t){return"string"==typeof t&&(t={message:t}),t=Object.assign({},i(this.defaultOptions),i(this.defaultAlertOptions),t),this.open(t)},confirm:function(t){if("object"!=typeof t||"function"!=typeof t.callback)throw new Error("dialog.confirm(options) requires options.callback.");return t=Object.assign({},i(this.defaultOptions),i(this.defaultConfirmOptions),t),this.open(t)},prompt:function(e){if("object"!=typeof e||"function"!=typeof e.callback)throw new Error("dialog.prompt(options) requires options.callback.");var n=Object.assign({},i(this.defaultOptions),i(this.defaultPromptOptions)),o={unsafeMessage:'<label for="vex">'+t._escapeHtml(e.label||n.label)+"</label>",input:'<input name="vex" type="text" class="vex-dialog-prompt-input" placeholder="'+t._escapeHtml(e.placeholder||n.placeholder)+'" value="'+t._escapeHtml(e.value||n.value)+'" />'},r=(e=Object.assign(n,o,e)).callback;return e.callback=function(t){if("object"==typeof t){var e=Object.keys(t);t=e.length?t[e[0]]:""}r(t)},this.open(e)},buttons:{YES:{text:"OK",type:"submit",className:"vex-dialog-button-primary",click:function(){this.value=!0}},NO:{text:"Cancel",type:"button",className:"vex-dialog-button-secondary",click:function(){this.value=!1,this.close()}}}};return e.defaultOptions={callback:function(){},afterOpen:function(){},message:"",input:"",yesText:"",noText:"",buttons:[e.buttons.YES,e.buttons.NO],showCloseButton:!1,onSubmit:function(t){return t.preventDefault(),this.options.input&&(this.value=r(this.form,{hash:!0})),this.close()},focusFirstInput:!0},e.defaultAlertOptions={buttons:[e.buttons.YES]},e.defaultPromptOptions={label:"Prompt:",placeholder:"",value:""},e.defaultConfirmOptions={},e}},{"deep-clone-simple":1,domify:2,"form-serialize":3}]},{},[4])(4)},function(t,e,n){var o=n(11);"string"==typeof o&&(o=[[t.i,o,""]]);var r={hmr:!0,transform:void 0,insertInto:void 0};n(13)(o,r);o.locals&&(t.exports=o.locals)},function(t,e,n){(t.exports=n(12)(!1)).push([t.i,'@-webkit-keyframes vex-fadein {\n 0% {\n opacity: 0; }\n 100% {\n opacity: 1; } }\n\n@keyframes vex-fadein {\n 0% {\n opacity: 0; }\n 100% {\n opacity: 1; } }\n\n@-webkit-keyframes vex-fadeout {\n 0% {\n opacity: 1; }\n 100% {\n opacity: 0; } }\n\n@keyframes vex-fadeout {\n 0% {\n opacity: 1; }\n 100% {\n opacity: 0; } }\n\n@-webkit-keyframes vex-rotation {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg); }\n 100% {\n -webkit-transform: rotate(359deg);\n transform: rotate(359deg); } }\n\n@keyframes vex-rotation {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg); }\n 100% {\n -webkit-transform: rotate(359deg);\n transform: rotate(359deg); } }\n\n.vex, .vex *, .vex *:before, .vex *:after {\n -moz-box-sizing: border-box;\n box-sizing: border-box; }\n\n.vex {\n position: fixed;\n overflow: auto;\n -webkit-overflow-scrolling: touch;\n z-index: 1111;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0; }\n\n.vex-scrollbar-measure {\n position: absolute;\n top: -9999px;\n width: 50px;\n height: 50px;\n overflow: scroll; }\n\n.vex-overlay {\n -webkit-animation: vex-fadein .5s;\n animation: vex-fadein .5s;\n position: fixed;\n z-index: 1111;\n background: rgba(0, 0, 0, 0.4);\n top: 0;\n right: 0;\n bottom: 0;\n left: 0; }\n\n.vex-overlay.vex-closing {\n -webkit-animation: vex-fadeout .5s forwards;\n animation: vex-fadeout .5s forwards; }\n\n.vex-content {\n -webkit-animation: vex-fadein .5s;\n animation: vex-fadein .5s;\n background: #fff; }\n\n.vex.vex-closing .vex-content {\n -webkit-animation: vex-fadeout .5s forwards;\n animation: vex-fadeout .5s forwards; }\n\n.vex-close:before {\n font-family: Arial, sans-serif;\n content: "\\D7"; }\n\n.vex-dialog-form {\n margin: 0; }\n\n.vex-dialog-button {\n text-rendering: optimizeLegibility;\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n cursor: pointer;\n -webkit-tap-highlight-color: transparent; }\n\n.vex-loading-spinner {\n -webkit-animation: vex-rotation .7s linear infinite;\n animation: vex-rotation .7s linear infinite;\n box-shadow: 0 0 1em rgba(0, 0, 0, 0.1);\n position: fixed;\n z-index: 1112;\n margin: auto;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n height: 2em;\n width: 2em;\n background: #fff; }\n\nbody.vex-open {\n overflow: hidden; }\n',""])},function(t,e){t.exports=function(t){var e=[];return e.toString=function(){return this.map((function(e){var n=function(t,e){var n=t[1]||"",o=t[3];if(!o)return n;if(e&&"function"==typeof btoa){var r=(a=o,"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(a))))+" */"),i=o.sources.map((function(t){return"/*# sourceURL="+o.sourceRoot+t+" */"}));return[n].concat(i).concat([r]).join("\n")}var a;return[n].join("\n")}(e,t);return e[2]?"@media "+e[2]+"{"+n+"}":n})).join("")},e.i=function(t,n){"string"==typeof t&&(t=[[null,t,""]]);for(var o={},r=0;r<this.length;r++){var i=this[r][0];"number"==typeof i&&(o[i]=!0)}for(r=0;r<t.length;r++){var a=t[r];"number"==typeof a[0]&&o[a[0]]||(n&&!a[2]?a[2]=n:n&&(a[2]="("+a[2]+") and ("+n+")"),e.push(a))}},e}},function(t,e,n){var o,r,i={},a=(o=function(){return window&&document&&document.all&&!window.atob},function(){return void 0===r&&(r=o.apply(this,arguments)),r}),s=function(t,e){return e?e.querySelector(t):document.querySelector(t)},c=function(t){var e={};return function(t,n){if("function"==typeof t)return t();if(void 0===e[t]){var o=s.call(this,t,n);if(window.HTMLIFrameElement&&o instanceof window.HTMLIFrameElement)try{o=o.contentDocument.head}catch(t){o=null}e[t]=o}return e[t]}}(),l=null,u=0,f=[],p=n(14);function d(t,e){for(var n=0;n<t.length;n++){var o=t[n],r=i[o.id];if(r){r.refs++;for(var a=0;a<r.parts.length;a++)r.parts[a](o.parts[a]);for(;a<o.parts.length;a++)r.parts.push(g(o.parts[a],e))}else{var s=[];for(a=0;a<o.parts.length;a++)s.push(g(o.parts[a],e));i[o.id]={id:o.id,refs:1,parts:s}}}}function h(t,e){for(var n=[],o={},r=0;r<t.length;r++){var i=t[r],a=e.base?i[0]+e.base:i[0],s={css:i[1],media:i[2],sourceMap:i[3]};o[a]?o[a].parts.push(s):n.push(o[a]={id:a,parts:[s]})}return n}function b(t,e){var n=c(t.insertInto);if(!n)throw new Error("Couldn't find a style target. This probably means that the value for the 'insertInto' parameter is invalid.");var o=f[f.length-1];if("top"===t.insertAt)o?o.nextSibling?n.insertBefore(e,o.nextSibling):n.appendChild(e):n.insertBefore(e,n.firstChild),f.push(e);else if("bottom"===t.insertAt)n.appendChild(e);else{if("object"!=typeof t.insertAt||!t.insertAt.before)throw new Error("[Style Loader]\n\n Invalid value for parameter 'insertAt' ('options.insertAt') found.\n Must be 'top', 'bottom', or Object.\n (https://github.com/webpack-contrib/style-loader#insertat)\n");var r=c(t.insertAt.before,n);n.insertBefore(e,r)}}function v(t){if(null===t.parentNode)return!1;t.parentNode.removeChild(t);var e=f.indexOf(t);e>=0&&f.splice(e,1)}function m(t){var e=document.createElement("style");if(void 0===t.attrs.type&&(t.attrs.type="text/css"),void 0===t.attrs.nonce){var o=function(){0;return n.nc}();o&&(t.attrs.nonce=o)}return y(e,t.attrs),b(t,e),e}function y(t,e){Object.keys(e).forEach((function(n){t.setAttribute(n,e[n])}))}function g(t,e){var n,o,r,i;if(e.transform&&t.css){if(!(i="function"==typeof e.transform?e.transform(t.css):e.transform.default(t.css)))return function(){};t.css=i}if(e.singleton){var a=u++;n=l||(l=m(e)),o=x.bind(null,n,a,!1),r=x.bind(null,n,a,!0)}else t.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=function(t){var e=document.createElement("link");return void 0===t.attrs.type&&(t.attrs.type="text/css"),t.attrs.rel="stylesheet",y(e,t.attrs),b(t,e),e}(e),o=C.bind(null,n,e),r=function(){v(n),n.href&&URL.revokeObjectURL(n.href)}):(n=m(e),o=O.bind(null,n),r=function(){v(n)});return o(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap)return;o(t=e)}else r()}}t.exports=function(t,e){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(e=e||{}).attrs="object"==typeof e.attrs?e.attrs:{},e.singleton||"boolean"==typeof e.singleton||(e.singleton=a()),e.insertInto||(e.insertInto="head"),e.insertAt||(e.insertAt="bottom");var n=h(t,e);return d(n,e),function(t){for(var o=[],r=0;r<n.length;r++){var a=n[r];(s=i[a.id]).refs--,o.push(s)}t&&d(h(t,e),e);for(r=0;r<o.length;r++){var s;if(0===(s=o[r]).refs){for(var c=0;c<s.parts.length;c++)s.parts[c]();delete i[s.id]}}}};var w,k=(w=[],function(t,e){return w[t]=e,w.filter(Boolean).join("\n")});function x(t,e,n,o){var r=n?"":o.css;if(t.styleSheet)t.styleSheet.cssText=k(e,r);else{var i=document.createTextNode(r),a=t.childNodes;a[e]&&t.removeChild(a[e]),a.length?t.insertBefore(i,a[e]):t.appendChild(i)}}function O(t,e){var n=e.css,o=e.media;if(o&&t.setAttribute("media",o),t.styleSheet)t.styleSheet.cssText=n;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(n))}}function C(t,e,n){var o=n.css,r=n.sourceMap,i=void 0===e.convertToAbsoluteUrls&&r;(e.convertToAbsoluteUrls||i)&&(o=p(o)),r&&(o+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(r))))+" */");var a=new Blob([o],{type:"text/css"}),s=t.href;t.href=URL.createObjectURL(a),s&&URL.revokeObjectURL(s)}},function(t,e){t.exports=function(t){var e="undefined"!=typeof window&&window.location;if(!e)throw new Error("fixUrls requires window.location");if(!t||"string"!=typeof t)return t;var n=e.protocol+"//"+e.host,o=n+e.pathname.replace(/\/[^\/]*$/,"/");return t.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi,(function(t,e){var r,i=e.trim().replace(/^"(.*)"$/,(function(t,e){return e})).replace(/^'(.*)'$/,(function(t,e){return e}));return/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(i)?t:(r=0===i.indexOf("//")?i:0===i.indexOf("/")?n+i:o+i.replace(/^\.\//,""),"url("+JSON.stringify(r)+")")}))}},,,,,,function(t,e,n){"use strict";n.r(e);var o=n(0),r=n.n(o);function i(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var a=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.form=r()("form#easy-watermark-settings-form"),this.form.length&&this.init()}var e,n,o;return e=t,(n=[{key:"init",value:function(){this.toggleGroup=this.toggleGroup.bind(this),this.checkboxes=this.form.find("input[data-toggle]"),this.checkboxes.on("change",this.toggleGroup),this.checkboxes.change()}},{key:"toggleGroup",value:function(t){var e=r()(t.target),n=e.data("toggle"),o=this.form.find(".group-".concat(n)),i=o.find("input, textarea, select");!0===e.is(":checked")?(o.show(),i.prop("disabled",!1)):(o.hide(),i.prop("disabled",!0))}}])&&i(e.prototype,n),o&&i(e,o),t}(),s=n(3),c=n.n(s);n(10),n(22);function l(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,o)}return n}function u(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?l(Object(n),!0).forEach((function(e){f(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function f(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}c.a.defaultOptions.className="vex-theme-ew",c.a.defaultOptions.contentClassName="postbox",c.a.dialog.buttons.YES=u(u({},c.a.dialog.buttons.YES),{},{className:"button-primary",text:ew.i18n.yes}),c.a.dialog.buttons.OK=u(u({},c.a.dialog.buttons.YES),{},{className:"button-primary",text:ew.i18n.ok}),c.a.dialog.buttons.NO=u(u({},c.a.dialog.buttons.NO),{},{className:"button",text:ew.i18n.no});c.a;function p(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var d=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.wrap=r()(".watermarks"),this.wrap.length&&this.init()}var e,n,o;return e=t,(n=[{key:"init",value:function(){this.confirm=this.confirm.bind(this),this.deleteButtons=this.wrap.find(".row-actions a.submitdelete"),this.deleteButtons.on("click",this.confirm)}},{key:"confirm",value:function(t){t.preventDefault();var e=r()(t.currentTarget),n=e.data("watermark-name");!function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){};c.a.dialog.confirm({message:t,callback:e,buttons:[c.a.dialog.buttons.YES,c.a.dialog.buttons.NO]})}(ew.i18n.deleteConfirmation.replace("{watermarkName}",n),(function(t){!0===t&&(window.location=e.attr("href"))}))}}])&&p(e.prototype,n),o&&p(e,o),t}(),h=n(2);function b(t){return(b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function v(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function m(t,e){return(m=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function y(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,o=k(t);if(e){var r=k(this).constructor;n=Reflect.construct(o,arguments,r)}else n=o.apply(this,arguments);return g(this,n)}}function g(t,e){return!e||"object"!==b(e)&&"function"!=typeof e?w(t):e}function w(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function k(t){return(k=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var x=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&m(t,e)}(i,t);var e,n,o,r=y(i);function i(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,i),(e=r.call(this,t)).state=t.state,e.callback=t.callback,e.handleClick=e.handleClick.bind(w(e)),e.button=e.$el.find("a"),e.spinner=e.$el.find(".spinner"),e.content=e.$el.find(".content"),e.status=e.$el.find(".status"),e.button.on("click",e.handleClick),e.mode=e.state.get("mode"),e.state.on("change",e.update,w(e)),e}return e=i,(n=[{key:"template",value:function(){var t=this.state.get("processed"),e=this.state.get("total"),n=Math.floor(t/e*100),o=this.state.get("statusText");return o=o.replace("{counter}","".concat(t,"/").concat(e)),"".concat(o," (").concat(n,"%)")}},{key:"handleClick",value:function(){this.button.hasClass("disabled")||this.callback()}},{key:"update",value:function(){var t=this.state.get("mode"),e=this.state.get("action");this.mode!==t&&this.toggleMode(t),"processing"===t&&this.action===e&&this.status.html(this.template())}},{key:"toggleMode",value:function(t){this.mode=t,this.action===this.state.get("action")||"loading"!==t&&"processing"!==t?"loading"===t?this.loading():"processing"===t?this.processing():this.reset():this.disable()}},{key:"disable",value:function(){this.button.addClass("disabled")}},{key:"loading",value:function(){this.disable(),this.spinner.css({visibility:"visible"})}},{key:"processing",value:function(){this.content.hide(),this.status.show()}},{key:"reset",value:function(){this.spinner.css({visibility:"hidden"}),this.status.hide(),this.content.show(),this.button.removeClass("disabled")}}])&&v(e.prototype,n),o&&v(e,o),i}(h.View);function O(t){return(O="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function C(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function E(t,e,n){return(E="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var o=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=_(t)););return t}(t,e);if(o){var r=Object.getOwnPropertyDescriptor(o,e);return r.get?r.get.call(n):r.value}})(t,e,n||t)}function j(t,e){return(j=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function S(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,o=_(t);if(e){var r=_(this).constructor;n=Reflect.construct(o,arguments,r)}else n=o.apply(this,arguments);return L(this,n)}}function L(t,e){return!e||"object"!==O(e)&&"function"!=typeof e?T(t):e}function T(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function _(t){return(_=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var N=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&j(t,e)}(i,t);var e,n,o,r=S(i);function i(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,i),t.el=".tool-bulk-watermark",(e=r.call(this,t)).action="watermark",e.selectWatermark=e.selectWatermark.bind(T(e)),e.toggleButton=e.toggleButton.bind(T(e)),e.select=e.$el.find("select"),e.select.on("change",e.selectWatermark),e.toggleButton(),e}return e=i,(n=[{key:"selectWatermark",value:function(){var t=this.select.val(),e=this.select.find("option:selected").data("nonce");this.state.set({watermark:t,nonce:e}),this.toggleButton()}},{key:"toggleButton",value:function(){"-1"===this.select.val()?this.button.addClass("disabled"):this.button.removeClass("disabled")}},{key:"disable",value:function(){E(_(i.prototype),"disable",this).call(this),this.select.prop({disabled:!0})}},{key:"processing",value:function(){this.select.val("-1"),E(_(i.prototype),"processing",this).call(this)}},{key:"reset",value:function(){E(_(i.prototype),"reset",this).call(this),this.select.prop({disabled:!1}).change()}}])&&C(e.prototype,n),o&&C(e,o),i}(x);function P(t){return(P="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function R(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function A(t,e,n){return(A="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var o=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=B(t)););return t}(t,e);if(o){var r=Object.getOwnPropertyDescriptor(o,e);return r.get?r.get.call(n):r.value}})(t,e,n||t)}function M(t,e){return(M=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function I(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,o=B(t);if(e){var r=B(this).constructor;n=Reflect.construct(o,arguments,r)}else n=o.apply(this,arguments);return D(this,n)}}function D(t,e){return!e||"object"!==P(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function B(t){return(B=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var U=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&M(t,e)}(i,t);var e,n,o,r=I(i);function i(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,i),t.el=".tool-restore",(e=r.call(this,t)).action="restore",e.backupInfo=e.$el.find("p.has-backup"),e.noBackupInfo=e.$el.find("p.no-backup"),e.backupCountInfo=e.$el.find(".backup-count"),e.state.set({backupCount:e.$el.data("backup-count")}),e.toggleInfo(),e}return e=i,(n=[{key:"handleClick",value:function(){this.state.set({nonce:this.button.data("nonce")}),A(B(i.prototype),"handleClick",this).call(this)}},{key:"toggleInfo",value:function(){var t=this.state.get("backupCount");0<t?(this.backupCountInfo.text(t),this.backupInfo.show(),this.noBackupInfo.hide()):(this.backupInfo.hide(),this.noBackupInfo.show())}},{key:"update",value:function(){A(B(i.prototype),"update",this).call(this),this.toggleInfo()}}])&&R(e.prototype,n),o&&R(e,o),i}(x),$=n(1);function H(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var z=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.wrap=r()(".tools"),this.wrap.length&&this.init()}var e,n,o;return e=t,(n=[{key:"init",value:function(){this.bulkWatermark=this.bulkWatermark.bind(this),this.restore=this.restore.bind(this),this.state=new h.Model,this.state.set({mode:"none"}),this.bulkWatermarkTool=new N({state:this.state,callback:this.bulkWatermark}),this.restoreTool=new U({state:this.state,callback:this.restore})}},{key:"bulkWatermark",value:function(){this.state.set({action:"watermark",successMessage:ew.i18n.watermarkingSuccessMessage,statusText:ew.i18n.watermarkingStatus}),this.getInfo()}},{key:"restore",value:function(){this.state.set({action:"restore",successMessage:ew.i18n.restoringSuccessMessage,statusText:ew.i18n.restoringStatus}),this.getInfo()}},{key:"getInfo",value:function(){var t=this;this.state.set({mode:"loading"}),r.a.ajax(ajaxurl,{data:{action:"easy-watermark/tools/get-attachments",nonce:ew.nonce,mode:this.state.get("action")}}).done((function(e){e.success?(t.state.set({items:e.data}),t.start()):Object($.a)(ew.i18n.genericErrorMessage,"error")})).fail((function(){Object($.a)(ew.i18n.genericErrorMessage,"error")}))}},{key:"start",value:function(){var t=this.state.get("items");if(!t)return function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){};c.a.dialog.alert({message:t,callback:e,buttons:[c.a.dialog.buttons.OK]})}(ew.i18n.noItemsToWatermark),void this.state.set({mode:"none"});this.state.set({mode:"processing",processed:0,total:t.length,error:!1,backupCount:0}),this.doActionRecursive(t)}},{key:"doActionRecursive",value:function(t){var e=this,n=t.shift(),o=this.state.get("nonce"),i=this.state.get("watermark"),a="easy-watermark/",s=this.state.get("processed"),c=this.state.get("backupCount");"watermark"===this.state.get("action")?a+="all"===i?"apply_all":"apply_single":a+="restore_backup",this.state.set({attachment:n}),r.a.ajax(ajaxurl,{data:{action:a,nonce:o,watermark:i,attachment_id:n.id}}).done((function(n){!0===n.success?(s++,n.data.hasBackup&&c++,e.state.set({processed:s,backupCount:c}),t.length?e.doActionRecursive(t):e.finish()):e.fail(n.data)})).fail((function(){e.fail(ew.i18n.genericErrorMessage)}))}},{key:"fail",value:function(t){var e=this.state.get("attachment").title,n=ew.i18n.bulkActionErrorMessage.replace("{imageTitle}",e).replace("{error}",t);this.state.set({error:n}),this.finish()}},{key:"finish",value:function(){var t=this.state.get("error"),e=this.state.get("processed"),n=this.state.get("successMessage");t?Object($.a)(t,"error"):Object($.a)(n.replace("{procesed}",e),"success"),this.state.set({mode:"none"})}}])&&H(e.prototype,n),o&&H(e,o),t}();n(24);r()(document).ready((function(){switch(r()("a.nav-tab-active").data("tab")){case"settings":new a;break;case"watermarks":new d;break;case"tools":new z}}))},,function(t,e){},,function(t,e){}]);
1
+ !function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="../",n(n.s=20)}([function(t,e){t.exports=jQuery},function(t,e,n){"use strict";n.d(e,"a",(function(){return c})),n.d(e,"b",(function(){return l})),n.d(e,"c",(function(){return u})),n.d(e,"d",(function(){return f}));var o=n(0),r=n.n(o);function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function a(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return s(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return s(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=new Array(e);n<e;n++)o[n]=t[n];return o}function c(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"info",n=r()(document.createElement("div")),o=r()(document.createElement("p")),i=r()(document.createElement("button"));n.addClass("notice notice-"+e+" is-dismissible").hide(),i.addClass("notice-dismiss"),o.html(t),n.append(o).append(i),i.on("click",(function(t){t.preventDefault(),n.fadeOut(200,(function(){n.remove()}))})),r()("hr.wp-header-end").after(n),n.fadeIn(200)}function l(t){var e,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],o=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=t.length,i=a(t.clone().models);try{for(i.s();!(e=i.n()).done;){var s=e.value;(!f(s)||s.get("usedAsWatermark")||!0===n&&!s.get("hasBackup"))&&(!0===o&&t.remove(s),r--)}}catch(t){i.e(t)}finally{i.f()}return r}function u(t){var e,n=t.indexOf("?"),o="t=".concat(Date.now());if(-1!==n){e=t.substr(n),t=t.substr(0,n);var r=/([^\s])t=[0-9]+/;e.match(r)?e=e.replace(r,"$1".concat(o)):e+="&".concat(o)}else e="?".concat(o);return t+e}function f(t){return"object"===i(t)&&t.get&&(t=t.get("mime")),Object.keys(ew.mime).includes(t)}},function(t,e){t.exports=Backbone},function(t,e,n){var o=n(5);o.registerPlugin(n(9)),t.exports=o},,function(t,e,n){n(6),n(7).polyfill();var o=n(8),r=function(t){if(void 0!==t){var e=document.createElement("div");return e.appendChild(document.createTextNode(t)),e.innerHTML}return""},i=function(t,e){if("string"==typeof e&&0!==e.length)for(var n=e.split(" "),o=0;o<n.length;o++){var r=n[o];r.length&&t.classList.add(r)}},a=function(){var t=document.createElement("div"),e={animation:"animationend",WebkitAnimation:"webkitAnimationEnd",MozAnimation:"animationend",OAnimation:"oanimationend",msAnimation:"MSAnimationEnd"};for(var n in e)if(void 0!==t.style[n])return e[n];return!1}(),s="vex",c="vex-content",l="vex-overlay",u="vex-close",f="vex-closing",p="vex-open",d={},h=1,b=!1,v={open:function(t){var e=function(t){console.warn('The "'+t+'" property is deprecated in vex 3. Use CSS classes and the appropriate "ClassName" options, instead.'),console.warn("See http://github.hubspot.com/vex/api/advanced/#options")};t.css&&e("css"),t.overlayCSS&&e("overlayCSS"),t.contentCSS&&e("contentCSS"),t.closeCSS&&e("closeCSS");var n={};n.id=h++,d[n.id]=n,n.isOpen=!0,n.close=function(){if(!this.isOpen)return!0;var t=this.options;if(b&&!t.escapeButtonCloses)return!1;if(!1===function(){return!t.beforeClose||t.beforeClose.call(this)}.bind(this)())return!1;this.isOpen=!1;var e=window.getComputedStyle(this.contentEl);function n(t){return"none"!==e.getPropertyValue(t+"animation-name")&&"0s"!==e.getPropertyValue(t+"animation-duration")}var o=n("")||n("-webkit-")||n("-moz-")||n("-o-"),r=function e(){this.rootEl.parentNode&&(this.rootEl.removeEventListener(a,e),this.overlayEl.removeEventListener(a,e),delete d[this.id],this.rootEl.parentNode.removeChild(this.rootEl),this.bodyEl.removeChild(this.overlayEl),t.afterClose&&t.afterClose.call(this),0===Object.keys(d).length&&document.body.classList.remove(p))}.bind(this);return a&&o?(this.rootEl.addEventListener(a,r),this.overlayEl.addEventListener(a,r),this.rootEl.classList.add(f),this.overlayEl.classList.add(f)):r(),!0},"string"==typeof t&&(t={content:t}),t.unsafeContent&&!t.content?t.content=t.unsafeContent:t.content&&(t.content=r(t.content));var m=n.options=Object.assign({},v.defaultOptions,t),y=n.bodyEl=document.getElementsByTagName("body")[0],g=n.rootEl=document.createElement("div");g.classList.add(s),i(g,m.className);var w=n.overlayEl=document.createElement("div");w.classList.add(l),i(w,m.overlayClassName),m.overlayClosesOnClick&&g.addEventListener("click",(function(t){t.target===g&&n.close()})),y.appendChild(w);var k=n.contentEl=document.createElement("div");if(k.classList.add(c),i(k,m.contentClassName),k.appendChild(m.content instanceof window.Node?m.content:o(m.content)),g.appendChild(k),m.showCloseButton){var x=n.closeEl=document.createElement("div");x.classList.add(u),i(x,m.closeClassName),x.addEventListener("click",n.close.bind(n)),k.appendChild(x)}return document.querySelector(m.appendLocation).appendChild(g),m.afterOpen&&m.afterOpen.call(n),document.body.classList.add(p),n},close:function(t){var e;if(t.id)e=t.id;else{if("string"!=typeof t)throw new TypeError("close requires a vex object or id string");e=t}return!!d[e]&&d[e].close()},closeTop:function(){var t=Object.keys(d);return!!t.length&&d[t[t.length-1]].close()},closeAll:function(){for(var t in d)this.close(t);return!0},getAll:function(){return d},getById:function(t){return d[t]}};window.addEventListener("keyup",(function(t){27===t.keyCode&&(b=!0,v.closeTop(),b=!1)})),window.addEventListener("popstate",(function(){v.defaultOptions.closeAllOnPopState&&v.closeAll()})),v.defaultOptions={content:"",showCloseButton:!0,escapeButtonCloses:!0,overlayClosesOnClick:!0,appendLocation:"body",className:"",overlayClassName:"",contentClassName:"",closeClassName:"",closeAllOnPopState:!0},Object.defineProperty(v,"_escapeHtml",{configurable:!1,enumerable:!1,writable:!1,value:r}),v.registerPlugin=function(t,e){var n=t(v),o=e||n.name;if(v[o])throw new Error("Plugin "+e+" is already registered.");v[o]=n},t.exports=v},function(t,e){
2
  /*! @source http://purl.eligrey.com/github/classList.js/blob/master/classList.js */
3
  "document"in window.self&&((!("classList"in document.createElement("_"))||document.createElementNS&&!("classList"in document.createElementNS("http://www.w3.org/2000/svg","g")))&&function(t){"use strict";if("Element"in t){var e=t.Element.prototype,n=Object,o=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},r=Array.prototype.indexOf||function(t){for(var e=0,n=this.length;e<n;e++)if(e in this&&this[e]===t)return e;return-1},i=function(t,e){this.name=t,this.code=DOMException[t],this.message=e},a=function(t,e){if(""===e)throw new i("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(e))throw new i("INVALID_CHARACTER_ERR","String contains an invalid character");return r.call(t,e)},s=function(t){for(var e=o.call(t.getAttribute("class")||""),n=e?e.split(/\s+/):[],r=0,i=n.length;r<i;r++)this.push(n[r]);this._updateClassName=function(){t.setAttribute("class",this.toString())}},c=s.prototype=[],l=function(){return new s(this)};if(i.prototype=Error.prototype,c.item=function(t){return this[t]||null},c.contains=function(t){return-1!==a(this,t+="")},c.add=function(){var t,e=arguments,n=0,o=e.length,r=!1;do{t=e[n]+"",-1===a(this,t)&&(this.push(t),r=!0)}while(++n<o);r&&this._updateClassName()},c.remove=function(){var t,e,n=arguments,o=0,r=n.length,i=!1;do{for(t=n[o]+"",e=a(this,t);-1!==e;)this.splice(e,1),i=!0,e=a(this,t)}while(++o<r);i&&this._updateClassName()},c.toggle=function(t,e){t+="";var n=this.contains(t),o=n?!0!==e&&"remove":!1!==e&&"add";return o&&this[o](t),!0===e||!1===e?e:!n},c.toString=function(){return this.join(" ")},n.defineProperty){var u={get:l,enumerable:!0,configurable:!0};try{n.defineProperty(e,"classList",u)}catch(t){void 0!==t.number&&-2146823252!==t.number||(u.enumerable=!1,n.defineProperty(e,"classList",u))}}else n.prototype.__defineGetter__&&e.__defineGetter__("classList",l)}}(window.self),function(){"use strict";var t=document.createElement("_");if(t.classList.add("c1","c2"),!t.classList.contains("c2")){var e=function(t){var e=DOMTokenList.prototype[t];DOMTokenList.prototype[t]=function(t){var n,o=arguments.length;for(n=0;n<o;n++)t=arguments[n],e.call(this,t)}};e("add"),e("remove")}if(t.classList.toggle("c3",!1),t.classList.contains("c3")){var n=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(t,e){return 1 in arguments&&!this.contains(t)==!e?e:n.call(this,t)}}t=null}())},function(t,e,n){"use strict";function o(t,e){if(null==t)throw new TypeError("Cannot convert first argument to object");for(var n=Object(t),o=1;o<arguments.length;o++){var r=arguments[o];if(null!=r)for(var i=Object.keys(Object(r)),a=0,s=i.length;a<s;a++){var c=i[a],l=Object.getOwnPropertyDescriptor(r,c);void 0!==l&&l.enumerable&&(n[c]=r[c])}}return n}t.exports={assign:o,polyfill:function(){Object.assign||Object.defineProperty(Object,"assign",{enumerable:!1,configurable:!0,writable:!0,value:o})}}},function(t,e){t.exports=function(t,e){if("string"!=typeof t)throw new TypeError("String expected");e||(e=document);var n=/<([\w:]+)/.exec(t);if(!n)return e.createTextNode(t);t=t.replace(/^\s+|\s+$/g,"");var o=n[1];if("body"==o){return(i=e.createElement("html")).innerHTML=t,i.removeChild(i.lastChild)}var i,a=r[o]||r._default,s=a[0],c=a[1],l=a[2];(i=e.createElement("div")).innerHTML=c+t+l;for(;s--;)i=i.lastChild;if(i.firstChild==i.lastChild)return i.removeChild(i.firstChild);var u=e.createDocumentFragment();for(;i.firstChild;)u.appendChild(i.removeChild(i.firstChild));return u};var n,o=!1;"undefined"!=typeof document&&((n=document.createElement("div")).innerHTML=' <link/><table></table><a href="/a">a</a><input type="checkbox"/>',o=!n.getElementsByTagName("link").length,n=void 0);var r={legend:[1,"<fieldset>","</fieldset>"],tr:[2,"<table><tbody>","</tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],_default:o?[1,"X<div>","</div>"]:[0,"",""]};r.td=r.th=[3,"<table><tbody><tr>","</tr></tbody></table>"],r.option=r.optgroup=[1,'<select multiple="multiple">',"</select>"],r.thead=r.tbody=r.colgroup=r.caption=r.tfoot=[1,"<table>","</table>"],r.polyline=r.ellipse=r.polygon=r.circle=r.text=r.line=r.path=r.rect=r.g=[1,'<svg xmlns="http://www.w3.org/2000/svg" version="1.1">',"</svg>"]},function(t,e,n){t.exports=function t(e,n,o){function r(a,s){if(!n[a]){if(!e[a]){if(i)return i(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var l=n[a]={exports:{}};e[a][0].call(l.exports,(function(t){var n=e[a][1][t];return r(n||t)}),l,l.exports,t,e,n,o)}return n[a].exports}for(var i=!1,a=0;a<o.length;a++)r(o[a]);return r}({1:[function(t,e,n){"use strict";e.exports=function t(e){if(!e||"object"!=typeof e)return e;if("[object Date]"==Object.prototype.toString.call(e))return new Date(e.getTime());if(Array.isArray(e))return e.map(t);var n={};return Object.keys(e).forEach((function(o){n[o]=t(e[o])})),n}},{}],2:[function(t,e,n){e.exports=function(t,e){if("string"!=typeof t)throw new TypeError("String expected");e||(e=document);var n=/<([\w:]+)/.exec(t);if(!n)return e.createTextNode(t);t=t.replace(/^\s+|\s+$/g,"");var o=n[1];if("body"==o)return(r=e.createElement("html")).innerHTML=t,r.removeChild(r.lastChild);var r,a=i[o]||i._default,s=a[0],c=a[1],l=a[2];for((r=e.createElement("div")).innerHTML=c+t+l;s--;)r=r.lastChild;if(r.firstChild==r.lastChild)return r.removeChild(r.firstChild);for(var u=e.createDocumentFragment();r.firstChild;)u.appendChild(r.removeChild(r.firstChild));return u};var o,r=!1;"undefined"!=typeof document&&((o=document.createElement("div")).innerHTML=' <link/><table></table><a href="/a">a</a><input type="checkbox"/>',r=!o.getElementsByTagName("link").length,o=void 0);var i={legend:[1,"<fieldset>","</fieldset>"],tr:[2,"<table><tbody>","</tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],_default:r?[1,"X<div>","</div>"]:[0,"",""]};i.td=i.th=[3,"<table><tbody><tr>","</tr></tbody></table>"],i.option=i.optgroup=[1,'<select multiple="multiple">',"</select>"],i.thead=i.tbody=i.colgroup=i.caption=i.tfoot=[1,"<table>","</table>"],i.polyline=i.ellipse=i.polygon=i.circle=i.text=i.line=i.path=i.rect=i.g=[1,'<svg xmlns="http://www.w3.org/2000/svg" version="1.1">',"</svg>"]},{}],3:[function(t,e,n){var o=/^(?:submit|button|image|reset|file)$/i,r=/^(?:input|select|textarea|keygen)/i,i=/(\[[^\[\]]*\])/g;function a(t,e,n){if(e.match(i))!function t(e,n,o){if(0===n.length)return e=o;var r=n.shift(),i=r.match(/^\[(.+?)\]$/);if("[]"===r)return e=e||[],Array.isArray(e)?e.push(t(null,n,o)):(e._values=e._values||[],e._values.push(t(null,n,o))),e;if(i){var a=i[1],s=+a;isNaN(s)?(e=e||{})[a]=t(e[a],n,o):(e=e||[])[s]=t(e[s],n,o)}else e[r]=t(e[r],n,o);return e}(t,function(t){var e=[],n=new RegExp(i),o=/^([^\[\]]*)/.exec(t);for(o[1]&&e.push(o[1]);null!==(o=n.exec(t));)e.push(o[1]);return e}(e),n);else{var o=t[e];o?(Array.isArray(o)||(t[e]=[o]),t[e].push(n)):t[e]=n}return t}function s(t,e,n){return n=n.replace(/(\r)?\n/g,"\r\n"),n=(n=encodeURIComponent(n)).replace(/%20/g,"+"),t+(t?"&":"")+encodeURIComponent(e)+"="+n}e.exports=function(t,e){"object"!=typeof e?e={hash:!!e}:void 0===e.hash&&(e.hash=!0);for(var n=e.hash?{}:"",i=e.serializer||(e.hash?a:s),c=t&&t.elements?t.elements:[],l=Object.create(null),u=0;u<c.length;++u){var f=c[u];if((e.disabled||!f.disabled)&&f.name&&r.test(f.nodeName)&&!o.test(f.type)){var p=f.name,d=f.value;if("checkbox"!==f.type&&"radio"!==f.type||f.checked||(d=void 0),e.empty){if("checkbox"!==f.type||f.checked||(d=""),"radio"===f.type&&(l[f.name]||f.checked?f.checked&&(l[f.name]=!0):l[f.name]=!1),!d&&"radio"==f.type)continue}else if(!d)continue;if("select-multiple"!==f.type)n=i(n,p,d);else{d=[];for(var h=f.options,b=!1,v=0;v<h.length;++v){var m=h[v],y=e.empty&&!m.value,g=m.value||y;m.selected&&g&&(b=!0,n=e.hash&&"[]"!==p.slice(p.length-2)?i(n,p+"[]",m.value):i(n,p,m.value))}!b&&e.empty&&(n=i(n,p,""))}}}if(e.empty)for(var p in l)l[p]||(n=i(n,p,""));return n}},{}],4:[function(t,e,n){var o=t("domify"),r=t("form-serialize"),i=t("deep-clone-simple"),a=function(t){var e=document.createElement("div");e.classList.add("vex-dialog-buttons");for(var n=0;n<t.length;n++){var o=t[n],r=document.createElement("button");r.type=o.type,r.textContent=o.text,r.className=o.className,r.classList.add("vex-dialog-button"),0===n?r.classList.add("vex-first"):n===t.length-1&&r.classList.add("vex-last"),function(t){r.addEventListener("click",function(e){t.click&&t.click.call(this,e)}.bind(this))}.bind(this)(o),e.appendChild(r)}return e};e.exports=function(t){var e={name:"dialog",open:function(e){var n=Object.assign({},i(this.defaultOptions),e);n.unsafeMessage&&!n.message?n.message=n.unsafeMessage:n.message&&(n.message=t._escapeHtml(n.message));var r=n.unsafeContent=function(t){var e=document.createElement("form");e.classList.add("vex-dialog-form");var n=document.createElement("div");n.classList.add("vex-dialog-message"),n.appendChild(t.message instanceof window.Node?t.message:o(t.message));var r=document.createElement("div");return r.classList.add("vex-dialog-input"),r.appendChild(t.input instanceof window.Node?t.input:o(t.input)),e.appendChild(n),e.appendChild(r),e}(n),s=t.open(n);""!==n.yesText&&(n.buttons[0].text=n.yesText),""!==n.noText&&(n.buttons[1].text=n.noText);var c=n.beforeClose&&n.beforeClose.bind(s);if(s.options.beforeClose=function(){var t=!c||c();return t&&n.callback(this.value||!1),t}.bind(s),r.appendChild(a.call(s,n.buttons)),s.form=r,r.addEventListener("submit",n.onSubmit.bind(s)),n.focusFirstInput){var l=s.contentEl.querySelector("button, input, select, textarea");l&&l.focus()}return s},alert:function(t){return"string"==typeof t&&(t={message:t}),t=Object.assign({},i(this.defaultOptions),i(this.defaultAlertOptions),t),this.open(t)},confirm:function(t){if("object"!=typeof t||"function"!=typeof t.callback)throw new Error("dialog.confirm(options) requires options.callback.");return t=Object.assign({},i(this.defaultOptions),i(this.defaultConfirmOptions),t),this.open(t)},prompt:function(e){if("object"!=typeof e||"function"!=typeof e.callback)throw new Error("dialog.prompt(options) requires options.callback.");var n=Object.assign({},i(this.defaultOptions),i(this.defaultPromptOptions)),o={unsafeMessage:'<label for="vex">'+t._escapeHtml(e.label||n.label)+"</label>",input:'<input name="vex" type="text" class="vex-dialog-prompt-input" placeholder="'+t._escapeHtml(e.placeholder||n.placeholder)+'" value="'+t._escapeHtml(e.value||n.value)+'" />'},r=(e=Object.assign(n,o,e)).callback;return e.callback=function(t){if("object"==typeof t){var e=Object.keys(t);t=e.length?t[e[0]]:""}r(t)},this.open(e)},buttons:{YES:{text:"OK",type:"submit",className:"vex-dialog-button-primary",click:function(){this.value=!0}},NO:{text:"Cancel",type:"button",className:"vex-dialog-button-secondary",click:function(){this.value=!1,this.close()}}}};return e.defaultOptions={callback:function(){},afterOpen:function(){},message:"",input:"",yesText:"",noText:"",buttons:[e.buttons.YES,e.buttons.NO],showCloseButton:!1,onSubmit:function(t){return t.preventDefault(),this.options.input&&(this.value=r(this.form,{hash:!0})),this.close()},focusFirstInput:!0},e.defaultAlertOptions={buttons:[e.buttons.YES]},e.defaultPromptOptions={label:"Prompt:",placeholder:"",value:""},e.defaultConfirmOptions={},e}},{"deep-clone-simple":1,domify:2,"form-serialize":3}]},{},[4])(4)},function(t,e,n){var o=n(11);"string"==typeof o&&(o=[[t.i,o,""]]);var r={hmr:!0,transform:void 0,insertInto:void 0};n(13)(o,r);o.locals&&(t.exports=o.locals)},function(t,e,n){(t.exports=n(12)(!1)).push([t.i,'@-webkit-keyframes vex-fadein {\n 0% {\n opacity: 0; }\n 100% {\n opacity: 1; } }\n\n@keyframes vex-fadein {\n 0% {\n opacity: 0; }\n 100% {\n opacity: 1; } }\n\n@-webkit-keyframes vex-fadeout {\n 0% {\n opacity: 1; }\n 100% {\n opacity: 0; } }\n\n@keyframes vex-fadeout {\n 0% {\n opacity: 1; }\n 100% {\n opacity: 0; } }\n\n@-webkit-keyframes vex-rotation {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg); }\n 100% {\n -webkit-transform: rotate(359deg);\n transform: rotate(359deg); } }\n\n@keyframes vex-rotation {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg); }\n 100% {\n -webkit-transform: rotate(359deg);\n transform: rotate(359deg); } }\n\n.vex, .vex *, .vex *:before, .vex *:after {\n -moz-box-sizing: border-box;\n box-sizing: border-box; }\n\n.vex {\n position: fixed;\n overflow: auto;\n -webkit-overflow-scrolling: touch;\n z-index: 1111;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0; }\n\n.vex-scrollbar-measure {\n position: absolute;\n top: -9999px;\n width: 50px;\n height: 50px;\n overflow: scroll; }\n\n.vex-overlay {\n -webkit-animation: vex-fadein .5s;\n animation: vex-fadein .5s;\n position: fixed;\n z-index: 1111;\n background: rgba(0, 0, 0, 0.4);\n top: 0;\n right: 0;\n bottom: 0;\n left: 0; }\n\n.vex-overlay.vex-closing {\n -webkit-animation: vex-fadeout .5s forwards;\n animation: vex-fadeout .5s forwards; }\n\n.vex-content {\n -webkit-animation: vex-fadein .5s;\n animation: vex-fadein .5s;\n background: #fff; }\n\n.vex.vex-closing .vex-content {\n -webkit-animation: vex-fadeout .5s forwards;\n animation: vex-fadeout .5s forwards; }\n\n.vex-close:before {\n font-family: Arial, sans-serif;\n content: "\\D7"; }\n\n.vex-dialog-form {\n margin: 0; }\n\n.vex-dialog-button {\n text-rendering: optimizeLegibility;\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n cursor: pointer;\n -webkit-tap-highlight-color: transparent; }\n\n.vex-loading-spinner {\n -webkit-animation: vex-rotation .7s linear infinite;\n animation: vex-rotation .7s linear infinite;\n box-shadow: 0 0 1em rgba(0, 0, 0, 0.1);\n position: fixed;\n z-index: 1112;\n margin: auto;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n height: 2em;\n width: 2em;\n background: #fff; }\n\nbody.vex-open {\n overflow: hidden; }\n',""])},function(t,e){t.exports=function(t){var e=[];return e.toString=function(){return this.map((function(e){var n=function(t,e){var n=t[1]||"",o=t[3];if(!o)return n;if(e&&"function"==typeof btoa){var r=(a=o,"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(a))))+" */"),i=o.sources.map((function(t){return"/*# sourceURL="+o.sourceRoot+t+" */"}));return[n].concat(i).concat([r]).join("\n")}var a;return[n].join("\n")}(e,t);return e[2]?"@media "+e[2]+"{"+n+"}":n})).join("")},e.i=function(t,n){"string"==typeof t&&(t=[[null,t,""]]);for(var o={},r=0;r<this.length;r++){var i=this[r][0];"number"==typeof i&&(o[i]=!0)}for(r=0;r<t.length;r++){var a=t[r];"number"==typeof a[0]&&o[a[0]]||(n&&!a[2]?a[2]=n:n&&(a[2]="("+a[2]+") and ("+n+")"),e.push(a))}},e}},function(t,e,n){var o,r,i={},a=(o=function(){return window&&document&&document.all&&!window.atob},function(){return void 0===r&&(r=o.apply(this,arguments)),r}),s=function(t,e){return e?e.querySelector(t):document.querySelector(t)},c=function(t){var e={};return function(t,n){if("function"==typeof t)return t();if(void 0===e[t]){var o=s.call(this,t,n);if(window.HTMLIFrameElement&&o instanceof window.HTMLIFrameElement)try{o=o.contentDocument.head}catch(t){o=null}e[t]=o}return e[t]}}(),l=null,u=0,f=[],p=n(14);function d(t,e){for(var n=0;n<t.length;n++){var o=t[n],r=i[o.id];if(r){r.refs++;for(var a=0;a<r.parts.length;a++)r.parts[a](o.parts[a]);for(;a<o.parts.length;a++)r.parts.push(g(o.parts[a],e))}else{var s=[];for(a=0;a<o.parts.length;a++)s.push(g(o.parts[a],e));i[o.id]={id:o.id,refs:1,parts:s}}}}function h(t,e){for(var n=[],o={},r=0;r<t.length;r++){var i=t[r],a=e.base?i[0]+e.base:i[0],s={css:i[1],media:i[2],sourceMap:i[3]};o[a]?o[a].parts.push(s):n.push(o[a]={id:a,parts:[s]})}return n}function b(t,e){var n=c(t.insertInto);if(!n)throw new Error("Couldn't find a style target. This probably means that the value for the 'insertInto' parameter is invalid.");var o=f[f.length-1];if("top"===t.insertAt)o?o.nextSibling?n.insertBefore(e,o.nextSibling):n.appendChild(e):n.insertBefore(e,n.firstChild),f.push(e);else if("bottom"===t.insertAt)n.appendChild(e);else{if("object"!=typeof t.insertAt||!t.insertAt.before)throw new Error("[Style Loader]\n\n Invalid value for parameter 'insertAt' ('options.insertAt') found.\n Must be 'top', 'bottom', or Object.\n (https://github.com/webpack-contrib/style-loader#insertat)\n");var r=c(t.insertAt.before,n);n.insertBefore(e,r)}}function v(t){if(null===t.parentNode)return!1;t.parentNode.removeChild(t);var e=f.indexOf(t);e>=0&&f.splice(e,1)}function m(t){var e=document.createElement("style");if(void 0===t.attrs.type&&(t.attrs.type="text/css"),void 0===t.attrs.nonce){var o=function(){0;return n.nc}();o&&(t.attrs.nonce=o)}return y(e,t.attrs),b(t,e),e}function y(t,e){Object.keys(e).forEach((function(n){t.setAttribute(n,e[n])}))}function g(t,e){var n,o,r,i;if(e.transform&&t.css){if(!(i="function"==typeof e.transform?e.transform(t.css):e.transform.default(t.css)))return function(){};t.css=i}if(e.singleton){var a=u++;n=l||(l=m(e)),o=x.bind(null,n,a,!1),r=x.bind(null,n,a,!0)}else t.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=function(t){var e=document.createElement("link");return void 0===t.attrs.type&&(t.attrs.type="text/css"),t.attrs.rel="stylesheet",y(e,t.attrs),b(t,e),e}(e),o=C.bind(null,n,e),r=function(){v(n),n.href&&URL.revokeObjectURL(n.href)}):(n=m(e),o=O.bind(null,n),r=function(){v(n)});return o(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap)return;o(t=e)}else r()}}t.exports=function(t,e){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(e=e||{}).attrs="object"==typeof e.attrs?e.attrs:{},e.singleton||"boolean"==typeof e.singleton||(e.singleton=a()),e.insertInto||(e.insertInto="head"),e.insertAt||(e.insertAt="bottom");var n=h(t,e);return d(n,e),function(t){for(var o=[],r=0;r<n.length;r++){var a=n[r];(s=i[a.id]).refs--,o.push(s)}t&&d(h(t,e),e);for(r=0;r<o.length;r++){var s;if(0===(s=o[r]).refs){for(var c=0;c<s.parts.length;c++)s.parts[c]();delete i[s.id]}}}};var w,k=(w=[],function(t,e){return w[t]=e,w.filter(Boolean).join("\n")});function x(t,e,n,o){var r=n?"":o.css;if(t.styleSheet)t.styleSheet.cssText=k(e,r);else{var i=document.createTextNode(r),a=t.childNodes;a[e]&&t.removeChild(a[e]),a.length?t.insertBefore(i,a[e]):t.appendChild(i)}}function O(t,e){var n=e.css,o=e.media;if(o&&t.setAttribute("media",o),t.styleSheet)t.styleSheet.cssText=n;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(n))}}function C(t,e,n){var o=n.css,r=n.sourceMap,i=void 0===e.convertToAbsoluteUrls&&r;(e.convertToAbsoluteUrls||i)&&(o=p(o)),r&&(o+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(r))))+" */");var a=new Blob([o],{type:"text/css"}),s=t.href;t.href=URL.createObjectURL(a),s&&URL.revokeObjectURL(s)}},function(t,e){t.exports=function(t){var e="undefined"!=typeof window&&window.location;if(!e)throw new Error("fixUrls requires window.location");if(!t||"string"!=typeof t)return t;var n=e.protocol+"//"+e.host,o=n+e.pathname.replace(/\/[^\/]*$/,"/");return t.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi,(function(t,e){var r,i=e.trim().replace(/^"(.*)"$/,(function(t,e){return e})).replace(/^'(.*)'$/,(function(t,e){return e}));return/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(i)?t:(r=0===i.indexOf("//")?i:0===i.indexOf("/")?n+i:o+i.replace(/^\.\//,""),"url("+JSON.stringify(r)+")")}))}},,,,,,function(t,e,n){"use strict";n.r(e);var o=n(0),r=n.n(o);function i(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var a=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.form=r()("form#easy-watermark-settings-form"),this.form.length&&this.init()}var e,n,o;return e=t,(n=[{key:"init",value:function(){this.toggleGroup=this.toggleGroup.bind(this),this.checkboxes=this.form.find("input[data-toggle]"),this.checkboxes.on("change",this.toggleGroup),this.checkboxes.change()}},{key:"toggleGroup",value:function(t){var e=r()(t.target),n=e.data("toggle"),o=this.form.find(".group-".concat(n)),i=o.find("input, textarea, select");!0===e.is(":checked")?(o.show(),i.prop("disabled",!1)):(o.hide(),i.prop("disabled",!0))}}])&&i(e.prototype,n),o&&i(e,o),t}(),s=n(3),c=n.n(s);n(10),n(22);function l(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,o)}return n}function u(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?l(Object(n),!0).forEach((function(e){f(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function f(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}c.a.defaultOptions.className="vex-theme-ew",c.a.defaultOptions.contentClassName="postbox",c.a.dialog.buttons.YES=u(u({},c.a.dialog.buttons.YES),{},{className:"button-primary",text:ew.i18n.yes}),c.a.dialog.buttons.OK=u(u({},c.a.dialog.buttons.YES),{},{className:"button-primary",text:ew.i18n.ok}),c.a.dialog.buttons.NO=u(u({},c.a.dialog.buttons.NO),{},{className:"button",text:ew.i18n.no});c.a;function p(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var d=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.wrap=r()(".watermarks"),this.wrap.length&&this.init()}var e,n,o;return e=t,(n=[{key:"init",value:function(){this.confirm=this.confirm.bind(this),this.deleteButtons=this.wrap.find(".row-actions a.submitdelete"),this.deleteButtons.on("click",this.confirm)}},{key:"confirm",value:function(t){t.preventDefault();var e=r()(t.currentTarget),n=e.data("watermark-name");!function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){};c.a.dialog.confirm({message:t,callback:e,buttons:[c.a.dialog.buttons.YES,c.a.dialog.buttons.NO]})}(ew.i18n.deleteConfirmation.replace("{watermarkName}",n),(function(t){!0===t&&(window.location=e.attr("href"))}))}}])&&p(e.prototype,n),o&&p(e,o),t}(),h=n(2);function b(t){return(b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function v(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function m(t,e){return(m=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function y(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,o=k(t);if(e){var r=k(this).constructor;n=Reflect.construct(o,arguments,r)}else n=o.apply(this,arguments);return g(this,n)}}function g(t,e){return!e||"object"!==b(e)&&"function"!=typeof e?w(t):e}function w(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function k(t){return(k=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var x=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&m(t,e)}(i,t);var e,n,o,r=y(i);function i(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,i),(e=r.call(this,t)).state=t.state,e.callback=t.callback,e.handleClick=e.handleClick.bind(w(e)),e.button=e.$el.find("a"),e.spinner=e.$el.find(".spinner"),e.content=e.$el.find(".content"),e.status=e.$el.find(".status"),e.button.on("click",e.handleClick),e.mode=e.state.get("mode"),e.state.on("change",e.update,w(e)),e}return e=i,(n=[{key:"template",value:function(){var t=this.state.get("processed"),e=this.state.get("total"),n=Math.floor(t/e*100),o=this.state.get("statusText");return o=o.replace("{counter}","".concat(t,"/").concat(e)),"".concat(o," (").concat(n,"%)")}},{key:"handleClick",value:function(){this.button.hasClass("disabled")||this.callback()}},{key:"update",value:function(){var t=this.state.get("mode"),e=this.state.get("action");this.mode!==t&&this.toggleMode(t),"processing"===t&&this.action===e&&this.status.html(this.template())}},{key:"toggleMode",value:function(t){this.mode=t,this.action===this.state.get("action")||"loading"!==t&&"processing"!==t?"loading"===t?this.loading():"processing"===t?this.processing():this.reset():this.disable()}},{key:"disable",value:function(){this.button.addClass("disabled")}},{key:"loading",value:function(){this.disable(),this.spinner.css({visibility:"visible"})}},{key:"processing",value:function(){this.content.hide(),this.status.show()}},{key:"reset",value:function(){this.spinner.css({visibility:"hidden"}),this.status.hide(),this.content.show(),this.button.removeClass("disabled")}}])&&v(e.prototype,n),o&&v(e,o),i}(h.View);function O(t){return(O="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function C(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function E(t,e,n){return(E="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var o=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=_(t)););return t}(t,e);if(o){var r=Object.getOwnPropertyDescriptor(o,e);return r.get?r.get.call(n):r.value}})(t,e,n||t)}function j(t,e){return(j=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function S(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,o=_(t);if(e){var r=_(this).constructor;n=Reflect.construct(o,arguments,r)}else n=o.apply(this,arguments);return L(this,n)}}function L(t,e){return!e||"object"!==O(e)&&"function"!=typeof e?T(t):e}function T(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function _(t){return(_=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var N=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&j(t,e)}(i,t);var e,n,o,r=S(i);function i(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,i),t.el=".tool-bulk-watermark",(e=r.call(this,t)).action="watermark",e.selectWatermark=e.selectWatermark.bind(T(e)),e.toggleButton=e.toggleButton.bind(T(e)),e.select=e.$el.find("select"),e.select.on("change",e.selectWatermark),e.toggleButton(),e}return e=i,(n=[{key:"selectWatermark",value:function(){var t=this.select.val(),e=this.select.find("option:selected").data("nonce");this.state.set({watermark:t,nonce:e}),this.toggleButton()}},{key:"toggleButton",value:function(){"-1"===this.select.val()?this.button.addClass("disabled"):this.button.removeClass("disabled")}},{key:"disable",value:function(){E(_(i.prototype),"disable",this).call(this),this.select.prop({disabled:!0})}},{key:"processing",value:function(){this.select.val("-1"),E(_(i.prototype),"processing",this).call(this)}},{key:"reset",value:function(){E(_(i.prototype),"reset",this).call(this),this.select.prop({disabled:!1}).change()}}])&&C(e.prototype,n),o&&C(e,o),i}(x);function P(t){return(P="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function R(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function A(t,e,n){return(A="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var o=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=B(t)););return t}(t,e);if(o){var r=Object.getOwnPropertyDescriptor(o,e);return r.get?r.get.call(n):r.value}})(t,e,n||t)}function M(t,e){return(M=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function I(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,o=B(t);if(e){var r=B(this).constructor;n=Reflect.construct(o,arguments,r)}else n=o.apply(this,arguments);return D(this,n)}}function D(t,e){return!e||"object"!==P(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function B(t){return(B=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var U=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&M(t,e)}(i,t);var e,n,o,r=I(i);function i(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,i),t.el=".tool-restore",(e=r.call(this,t)).action="restore",e.backupInfo=e.$el.find("p.has-backup"),e.noBackupInfo=e.$el.find("p.no-backup"),e.backupCountInfo=e.$el.find(".backup-count"),e.state.set({backupCount:e.$el.data("backup-count")}),e.toggleInfo(),e}return e=i,(n=[{key:"handleClick",value:function(){this.state.set({nonce:this.button.data("nonce")}),A(B(i.prototype),"handleClick",this).call(this)}},{key:"toggleInfo",value:function(){var t=this.state.get("backupCount");0<t?(this.backupCountInfo.text(t),this.backupInfo.show(),this.noBackupInfo.hide()):(this.backupInfo.hide(),this.noBackupInfo.show())}},{key:"update",value:function(){A(B(i.prototype),"update",this).call(this),this.toggleInfo()}}])&&R(e.prototype,n),o&&R(e,o),i}(x),$=n(1);function H(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var z=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.wrap=r()(".tools"),this.wrap.length&&this.init()}var e,n,o;return e=t,(n=[{key:"init",value:function(){this.bulkWatermark=this.bulkWatermark.bind(this),this.restore=this.restore.bind(this),this.state=new h.Model,this.state.set({mode:"none"}),this.bulkWatermarkTool=new N({state:this.state,callback:this.bulkWatermark}),this.restoreTool=new U({state:this.state,callback:this.restore})}},{key:"bulkWatermark",value:function(){this.state.set({action:"watermark",successMessage:ew.i18n.watermarkingSuccessMessage,statusText:ew.i18n.watermarkingStatus}),this.getInfo()}},{key:"restore",value:function(){this.state.set({action:"restore",successMessage:ew.i18n.restoringSuccessMessage,statusText:ew.i18n.restoringStatus}),this.getInfo()}},{key:"getInfo",value:function(){var t=this;this.state.set({mode:"loading"}),r.a.ajax(ajaxurl,{data:{action:"easy-watermark/tools/get-attachments",nonce:ew.nonce,mode:this.state.get("action")}}).done((function(e){e.success?(t.state.set({items:e.data}),t.start()):Object($.a)(ew.i18n.genericErrorMessage,"error")})).fail((function(){Object($.a)(ew.i18n.genericErrorMessage,"error")}))}},{key:"start",value:function(){var t=this.state.get("items");if(!t)return function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){};c.a.dialog.alert({message:t,callback:e,buttons:[c.a.dialog.buttons.OK]})}(ew.i18n.noItemsToWatermark),void this.state.set({mode:"none"});this.state.set({mode:"processing",processed:0,total:t.length,error:!1,backupCount:0}),this.doActionRecursive(t)}},{key:"doActionRecursive",value:function(t){var e=this,n=t.shift(),o=this.state.get("nonce"),i=this.state.get("watermark"),a="easy-watermark/",s=this.state.get("processed"),c=this.state.get("backupCount");"watermark"===this.state.get("action")?a+="all"===i?"apply_all":"apply_single":a+="restore_backup",this.state.set({attachment:n}),r.a.ajax(ajaxurl,{data:{action:a,nonce:o,watermark:i,attachment_id:n.id}}).done((function(n){!0===n.success?(s++,n.data.hasBackup&&c++,e.state.set({processed:s,backupCount:c}),t.length?e.doActionRecursive(t):e.finish()):e.fail(n.data)})).fail((function(){e.fail(ew.i18n.genericErrorMessage)}))}},{key:"fail",value:function(t){var e=this.state.get("attachment").title,n=ew.i18n.bulkActionErrorMessage.replace("{imageTitle}",e).replace("{error}",t);this.state.set({error:n}),this.finish()}},{key:"finish",value:function(){var t=this.state.get("error"),e=this.state.get("processed"),n=this.state.get("successMessage");t?Object($.a)(t,"error"):Object($.a)(n.replace("{procesed}",e),"success"),this.state.set({mode:"none"})}}])&&H(e.prototype,n),o&&H(e,o),t}();n(24);r()(document).ready((function(){switch(r()("a.nav-tab-active").data("tab")){case"settings":new a;break;case"watermarks":new d;break;case"tools":new z}}))},,function(t,e){},,function(t,e){}]);
assets/dist/scripts/media-library.js CHANGED
@@ -1 +1 @@
1
- !function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="../",n(n.s=18)}({0:function(t,e){t.exports=jQuery},1:function(t,e,n){"use strict";n.d(e,"a",(function(){return s})),n.d(e,"b",(function(){return l})),n.d(e,"c",(function(){return u})),n.d(e,"d",(function(){return f}));var r=n(0),o=n.n(r);function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function c(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return a(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return a(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,c=!0,s=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return c=t.done,t},e:function(t){s=!0,i=t},f:function(){try{c||null==n.return||n.return()}finally{if(s)throw i}}}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function s(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"info",n=o()(document.createElement("div")),r=o()(document.createElement("p")),i=o()(document.createElement("button"));n.addClass("notice notice-"+e+" is-dismissible").hide(),i.addClass("notice-dismiss"),r.html(t),n.append(r).append(i),i.on("click",(function(t){t.preventDefault(),n.fadeOut(200,(function(){n.remove()}))})),o()("hr.wp-header-end").after(n),n.fadeIn(200)}function l(t){var e,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],o=t.length,i=c(t.clone().models);try{for(i.s();!(e=i.n()).done;){var a=e.value;(!f(a)||a.get("usedAsWatermark")||!0===n&&!a.get("hasBackup"))&&(!0===r&&t.remove(a),o--)}}catch(t){i.e(t)}finally{i.f()}return o}function u(t,e){var n=t.indexOf("?");return-1!==n&&(t=t.substr(0,n)),t+="?v="+e}function f(t){return"object"===i(t)&&t.get&&(t=t.get("mime")),Object.keys(ew.mime).includes(t)}},16:function(t,e){function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function i(t,e,n){return(i="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=l(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function c(t,e){return(c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function a(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=l(t);if(e){var o=l(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return s(this,n)}}function s(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function l(t){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}wp.media&&"function"==typeof wp.media.view.SelectModeToggleButton&&(wp.media.view.SelectModeToggleButton=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&c(t,e)}(f,wp.media.view.SelectModeToggleButton);var e,n,s,u=a(f);function f(){return r(this,f),u.apply(this,arguments)}return e=f,(n=[{key:"initialize",value:function(){i(l(f.prototype),"initialize",this).call(this),this.controller.on("processing:activate processing:deactivate",this.toggleDisabled,this)}},{key:"toggleDisabled",value:function(){this.model.set("disabled",this.controller.isModeActive("processing"))}},{key:"toggleBulkEditHandler",value:function(){i(l(f.prototype),"toggleBulkEditHandler",this).call(this),this.controller.trigger("selection:toggle");var t=this.controller.content.get().toolbar;this.controller.isModeActive("select")?t.$(".watermark-mode-toggle-button").removeClass("hidden"):t.$(".watermark-mode-toggle-button").addClass("hidden"),t.$(".watermark-selector").css("display",""),t.$(".ew-status").css("display","")}}])&&o(e.prototype,n),s&&o(e,s),f}())},17:function(t,e){function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function i(t,e,n){return e&&o(t.prototype,e),n&&o(t,n),t}function c(t,e,n){return(c="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=f(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&s(t,e)}function s(t,e){return(s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function l(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=f(t);if(e){var o=f(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return u(this,n)}}function u(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function f(t){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}wp.media&&("function"==typeof wp.media.view.AttachmentFilters.All&&(wp.media.view.AttachmentFilters.All=function(t){a(n,wp.media.view.AttachmentFilters.All);var e=l(n);function n(){return r(this,n),e.apply(this,arguments)}return i(n,[{key:"initialize",value:function(){c(f(n.prototype),"initialize",this).call(this),this.controller.on("processing:activate processing:deactivate",this.toggleDisabled,this)}},{key:"toggleDisabled",value:function(){this.$el.prop("disabled",!this.$el.is(":disabled"))}}]),n}()),"function"==typeof wp.media.view.AttachmentFilters.Uploaded&&(wp.media.view.AttachmentFilters.Uploaded=function(t){a(n,wp.media.view.AttachmentFilters.Uploaded);var e=l(n);function n(){return r(this,n),e.apply(this,arguments)}return i(n,[{key:"initialize",value:function(){c(f(n.prototype),"initialize",this).call(this),this.controller.on("processing:activate processing:deactivate",this.toggleDisabled,this)}},{key:"toggleDisabled",value:function(){this.$el.prop("disabled",!this.$el.is(":disabled"))}}]),n}()),"function"==typeof wp.media.view.DateFilter&&(wp.media.view.DateFilter=function(t){a(n,wp.media.view.DateFilter);var e=l(n);function n(){return r(this,n),e.apply(this,arguments)}return i(n,[{key:"initialize",value:function(){c(f(n.prototype),"initialize",this).call(this),this.controller.on("processing:activate processing:deactivate",this.toggleDisabled,this)}},{key:"toggleDisabled",value:function(){this.$el.prop("disabled",!this.$el.is(":disabled"))}}]),n}()))},18:function(t,e,n){"use strict";n.r(e);n(30);var r=n(0),o=n.n(r),i=n(1);if(wp.media&&"function"==typeof wp.media.view.Attachment.Library){var c=wp.media.view.Attachment.Library;wp.media.view.Attachment.Library=c.extend({initialize:function(){c.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:function(){c.prototype.render.apply(this,arguments),this.$el.append(o()("<span></span>").addClass("spinner"))},toggleSelection:function(t){var e=t.method;(!this.controller.isModeActive("watermark")||Object(i.d)(this.model)&&!this.model.get("usedAsWatermark")||"between"===e)&&c.prototype.toggleSelection.apply(this,arguments),this.controller.isModeActive("watermark")&&(Object(i.d)(this.model)&&!this.model.get("usedAsWatermark")||this.$el.blur(),"between"===e&&Object(i.b)(this.options.selection))},showLoader:function(){this.$el.find(".spinner").css({visibility:"visible"})},disable:function(){if((this.controller.isModeActive("watermark")||this.controller.isModeActive("processing"))&&!this.hasBadge&&(!this.controller.isModeActive("processing")||this.wasSelected())){var t;if(Object(i.d)(this.model))if(this.model.get("usedAsWatermark"))t=ew.i18n.usedAsWatermark;else{if(!this.controller.isModeActive("restoring")||this.model.get("hasBackup"))return;t=ew.i18n.noBackupAvailable}else t=ew.i18n.notSupported;var e=o()("<div>",{class:"badge"}).text(t);this.$el.addClass("disabled").append(e),this.hasBadge=!0}},enable:function(){this.controller.isModeActive("watermark")||this.controller.isModeActive("processing")||(this.$el.removeClass("disabled").find(".badge").remove(),this.hasBadge=!1)},wasSelected:function(){var t=this.controller.state().get("originalSelection");if(t)return!!t.get(this.model.cid)}})}function a(t){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function l(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function u(t,e,n){return(u="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=y(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function f(t,e){return(f=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function p(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=y(t);if(e){var o=y(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return h(this,n)}}function h(t,e){return!e||"object"!==a(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function y(t){return(y=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var d=null;wp.media&&"function"==typeof wp.media.view.Button&&(d=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&f(t,e)}(i,wp.media.view.Button);var e,n,r,o=p(i);function i(){return s(this,i),o.apply(this,arguments)}return e=i,(n=[{key:"initialize",value:function(){var t=this;u(y(i.prototype),"initialize",this).call(this),this.controller.on("watermark:activate",(function(){t.$el.removeClass("hidden").show()})),this.controller.on("watermark:deactivate",(function(){t.$el.addClass("hidden").hide()})),this.controller.on("watermark:selected",this.toggleDisabled,this),this.model.set("disabled",!0)}},{key:"render",value:function(){return u(y(i.prototype),"render",this).call(this),this.controller.isModeActive("watermark")?this.$el.addClass("watermark-button"):this.$el.addClass("watermark-button hidden"),this}},{key:"click",value:function(){u(y(i.prototype),"click",this).call(this),this.controller.state().get("watermark")&&this.controller.ewWatermark()}},{key:"toggleDisabled",value:function(t){this.model.set("disabled",!t.length)}}])&&l(e.prototype,n),r&&l(e,r),i}());var b=d;function m(t){return(m="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function v(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function g(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function w(t,e,n){return(w="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=j(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function k(t,e){return(k=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function O(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=j(t);if(e){var o=j(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return S(this,n)}}function S(t,e){return!e||"object"!==m(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function j(t){return(j=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var _=null;wp.media&&"function"==typeof wp.media.view.Button&&(_=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&k(t,e)}(c,wp.media.view.Button);var e,n,r,o=O(c);function c(){return v(this,c),o.apply(this,arguments)}return e=c,(n=[{key:"initialize",value:function(){w(j(c.prototype),"initialize",this).call(this),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)}},{key:"render",value:function(){return w(j(c.prototype),"render",this).call(this),this.controller.isModeActive("select")&&!this.controller.isModeActive("watermark")?this.$el.addClass("restore-button"):this.$el.addClass("restore-button hidden"),this.update(),this}},{key:"click",value:function(){w(j(c.prototype),"click",this).call(this),this.controller.isModeActive("select")&&this.controller.ewRestoreBackup()}},{key:"update",value:function(){var t=this.model.get("filteredSelectionCount"),e=Object(i.b)(this.controller.state().get("selection"),!0,!1);e!==t&&(this.model.set({filteredSelectionCount:e,text:"".concat(this.model.get("originalText")," (").concat(e,")")}),this.model.set("disabled",!Boolean(e)))}}])&&g(e.prototype,n),r&&g(e,r),c}());var R=_;function A(t){return(A="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function P(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function x(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function M(t,e,n){return(M="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=$(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function B(t,e){return(B=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function E(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=$(t);if(e){var o=$(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return D(this,n)}}function D(t,e){return!e||"object"!==A(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function $(t){return($=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var C=null;wp.media&&"function"==typeof wp.media.view.Button&&(C=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&B(t,e)}(c,wp.media.view.Button);var e,n,r,o=E(c);function c(){return P(this,c),o.apply(this,arguments)}return e=c,(n=[{key:"initialize",value:function(){var t=this;M($(c.prototype),"initialize",this).call(this),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",(function(){return t.$el.html(t.model.get("cancelText"))})),this.controller.on("watermark:deactivate",this.update,this)}},{key:"render",value:function(){return M($(c.prototype),"render",this).call(this),this.controller.isModeActive("select")?this.$el.addClass("watermark-mode-toggle-button"):this.$el.addClass("watermark-mode-toggle-button hidden"),this.update(),this}},{key:"click",value:function(){M($(c.prototype),"click",this).call(this),this.controller.isModeActive("watermark")?this.controller.deactivateMode("watermark"):(this.controller.activateMode("watermark"),Object(i.b)(this.controller.state().get("selection")))}},{key:"update",value:function(){if(!this.controller.isModeActive("watermark")){var t=this.model.get("filteredSelectionCount"),e=Object(i.b)(this.controller.state().get("selection"),!1,!1);e!==t&&(this.model.set({filteredSelectionCount:e,text:"".concat(this.model.get("originalText")," (").concat(e,")")}),this.model.set("disabled",!Boolean(e)),this.controller.state().get("selection").length||this.controller.deactivateMode("watermark"))}}}])&&x(e.prototype,n),r&&x(e,r),c}());var T=C;function z(t){return(z="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function N(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function W(t,e,n){return(W="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=U(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function I(t,e){return(I=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function F(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=U(t);if(e){var o=U(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return L(this,n)}}function L(t,e){return!e||"object"!==z(e)&&"function"!=typeof e?V(t):e}function V(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function U(t){return(U=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var H=null;wp.media&&"function"==typeof wp.media.View&&(H=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&I(t,e)}(c,wp.media.View);var e,n,r,i=F(c);function c(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,c),(e=i.call(this,t)).controller.on("watermark:activate",e.show,V(e)),e.controller.on("watermark:deactivate",e.hide,V(e)),e}return e=c,(n=[{key:"events",value:function(){return{change:"selectWatermark"}}},{key:"tagName",value:function(){return"select"}},{key:"selectWatermark",value:function(){this.controller.trigger("watermark:selected",this.$el.val()),this.controller.state().set("watermark",this.$el.val())}},{key:"show",value:function(){this.$el.removeClass("hidden")}},{key:"hide",value:function(){this.$el.addClass("hidden")}},{key:"render",value:function(){if(W(U(c.prototype),"render",this).call(this),this.$el.append(o()("<option>",{value:""}).html(ew.i18n.selectWatermarkLabel)),ew.watermarks)for(var t in 1<Object.keys(ew.watermarks).length&&this.$el.append(o()("<option>",{value:"all"}).html(ew.i18n.allWatermarksLabel)),ew.watermarks)this.$el.append(o()("<option>",{value:t}).html(ew.watermarks[t]));return this.controller.isModeActive("select")?this.$el.addClass("watermark-selector"):this.$el.addClass("watermark-selector hidden"),this}}])&&N(e.prototype,n),r&&N(e,r),c}());var Q=H;function q(t){return(q="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function G(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function J(t,e,n){return e&&G(t.prototype,e),n&&G(t,n),t}function K(t,e){return(K=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function X(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=tt(t);if(e){var o=tt(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return Y(this,n)}}function Y(t,e){return!e||"object"!==q(e)&&"function"!=typeof e?Z(t):e}function Z(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function tt(t){return(tt=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var et=null;wp.media&&"function"==typeof wp.media.View&&(et=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&K(t,e)}(n,wp.media.View);var e=X(n);function n(t){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),(r=e.call(this,t)).status=r.controller.state().get("ewStatus"),r.status.on("change",r.update,Z(r)),r}return J(n,[{key:"tagName",value:function(){return"p"}},{key:"className",value:function(){return"ew-status"}},{key:"template",value:function(){var t=this.status.get("text");if(this.status.get("progress")){var e=this.status.get("processed"),n=this.status.get("total"),r="".concat(e,"/").concat(n),o=Math.floor(e/n*100);"string"==typeof status&&(t=t.replace("{counter}",r)),t+=" (".concat(o,"%)")}return'<span class="status">'.concat(t,"</span>")}}]),J(n,[{key:"render",value:function(){return this.update(),this}},{key:"update",value:function(){this.status.get("visible")?this.$el.removeClass("hidden").html(this.template()):this.$el.addClass("hidden")}},{key:"cancel",value:function(t){t.preventDefault(),this.controller.deactivateMode("watermarking")}}]),n}());var nt=et;function rt(t){return(rt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function ot(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function it(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function ct(t,e,n){return(ct="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=ut(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function at(t,e){return(at=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function st(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=ut(t);if(e){var o=ut(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return lt(this,n)}}function lt(t,e){return!e||"object"!==rt(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function ut(t){return(ut=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}wp.media&&"function"==typeof wp.media.view.AttachmentsBrowser&&(wp.media.view.AttachmentsBrowser=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&at(t,e)}(i,wp.media.view.AttachmentsBrowser);var e,n,r,o=st(i);function i(){return ot(this,i),o.apply(this,arguments)}return e=i,(n=[{key:"createToolbar",value:function(){var t=this;ct(ut(i.prototype),"createToolbar",this).call(this),this.controller.state().get("ewStatus")&&(Object.keys(ew.watermarks).length&&(this.toolbar.set("watermarkModeToggleButton",new T({text:ew.i18n.watermarkModeToggleButtonLabel,cancelText:ew.i18n.cancelLabel,controller:this.controller,priority:-60}).render()),this.toolbar.set("watermarkSelector",new Q({controller:this.controller,priority:-50}).render()),this.toolbar.set("watermarkButton",new b({text:ew.i18n.watermarkButtonLabel,style:"primary",controller:this.controller,priority:-40}).render())),this.toolbar.set("restoreButton",new R({text:ew.i18n.restoreButtonLabel,controller:this.controller,priority:-30}).render()),this.toolbar.set("watermarkingStatus",new nt({style:"primary",controller:this.controller,priority:-20}).render()),this.controller.on("select:deactivate",(function(){return t.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))}},{key:"hideButtons",value:function(){this.$(".select-mode-toggle-button").addClass("hidden"),this.$(".delete-selected-button").addClass("hidden")}},{key:"showButtons",value:function(){this.$el.html(this.model.get("text")),this.$(".select-mode-toggle-button").removeClass("hidden"),this.$(".delete-selected-button").removeClass("hidden")}},{key:"disableViewSwitch",value:function(){var t=this.toolbar.$(".view-switch");t.hasClass("disabled")?t.removeClass("disabled"):t.addClass("disabled")}}])&&it(e.prototype,n),r&&it(e,r),i}());n(16),n(17);var ft=n(2);function pt(t){return(pt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function ht(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return yt(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return yt(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,c=!0,a=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return c=t.done,t},e:function(t){a=!0,i=t},f:function(){try{c||null==n.return||n.return()}finally{if(a)throw i}}}}function yt(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function dt(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function bt(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function mt(t,e,n){return(mt="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=kt(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function vt(t,e){return(vt=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function gt(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=kt(t);if(e){var o=kt(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return wt(this,n)}}function wt(t,e){return!e||"object"!==pt(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function kt(t){return(kt=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function Ot(t){return(Ot="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function St(t,e){return(St=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function jt(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=Rt(t);if(e){var o=Rt(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return _t(this,n)}}function _t(t,e){return!e||"object"!==Ot(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function Rt(t){return(Rt=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}wp.media&&wp.media.view&&wp.media.view.MediaFrame&&"function"==typeof wp.media.view.MediaFrame.Manage&&(wp.media.view.MediaFrame.Manage=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&vt(t,e)}(a,wp.media.view.MediaFrame.Manage);var e,n,r,c=gt(a);function a(){return dt(this,a),c.apply(this,arguments)}return e=a,(n=[{key:"browseContent",value:function(t){this.state().set({ewCollection:new ft.Collection,ewStatus:new ft.Model}),mt(kt(a.prototype),"browseContent",this).call(this,t)}},{key:"ewBulkAction",value:function(){var t=this.state(),e=t.get("selection"),n=t.get("ewAction"),r=e.clone();if(t.set("originalSelection",r),Object(i.b)(e,"restore"===n),e.length){var o=t.get("ewCollection"),c=t.get("ewStatus");o.reset();var a,s=ht(e.models);try{for(s.s();!(a=s.n()).done;){var l=a.value;o.add(l),l.trigger("ewBulkAction:start")}}catch(t){s.e(t)}finally{s.f()}this.deactivateMode("watermark").trigger("selection:action:done"),this.activateMode("processing"),c.set({total:o.length,processed:0,error:!1,visible:!0,progress:!0}),this.ewBulkActionRecursive()}}},{key:"ewBulkActionRecursive",value:function(){var t,e=this,n=this.state(),r=n.get("ewAction"),c=n.get("watermark"),a="easy-watermark/";if("watermark"===r)a+="all"===c?"apply_all":"apply_single",t="all"===c?ew.applyAllNonce:ew.applySingleNonces[c];else{if("restore"!==r)return;a+="restore_backup",t=ew.restoreBackupNonce}var s=n.get("ewStatus"),l=n.get("ewCollection").shift(),u={action:a,nonce:t,watermark:c},f=s.get("processed");u.attachment_id=l.get("id"),n.set("ewCurrentModel",l),o.a.ajax(ajaxurl,{data:u}).done((function(t){if(!0===t.success){if(t.data.attachmentVersion){l.set("url",Object(i.c)(l.get("url"),t.data.attachmentVersion));for(var n=l.get("sizes"),r=0,o=Object.keys(n);r<o.length;r++){var c=o[r];n[c].url=Object(i.c)(n[c].url,t.data.attachmentVersion)}l.set("sizes",n)}l.set("hasBackup",!!t.data.hasBackup),f++,s.set({processed:f}),l.trigger("ewBulkAction:done"),s.get("total")===f?e.ewBulkActionDone():e.ewBulkActionRecursive()}else{var a="string"==typeof t.data.message?t.data.message:ew.i18n.genericErrorMessage;e.ewBulkActionError(a)}})).fail((function(){e.ewBulkActionError(ew.i18n.genericErrorMessage)}))}},{key:"ewWatermark",value:function(){this.state().set({ewAction:"watermark",ewSuccessMessage:ew.i18n.watermarkingSuccessMessage}).get("ewStatus").set({text:ew.i18n.watermarkingStatus}),this.activateMode("watermarking"),this.ewBulkAction()}},{key:"ewRestoreBackup",value:function(){this.state().set({ewAction:"restore",ewSuccessMessage:ew.i18n.restoringSuccessMessage}).get("ewStatus").set({text:ew.i18n.restoringStatus}),this.activateMode("restoring"),this.ewBulkAction()}},{key:"ewBulkActionError",value:function(t){var e=this.state(),n=e.get("ewStatus"),r=e.get("ewCollection"),o=e.get("ewCurrentModel");o&&r.push(o);var i,c=ht(r.models);try{for(c.s();!(i=c.n()).done;)i.value.trigger("ewBulkAction:done")}catch(t){c.e(t)}finally{c.f()}n.set({error:t}),this.ewBulkActionDone()}},{key:"ewBulkActionDone",value:function(){var t=this.state(),e=t.get("ewStatus"),n=t.get("ewCurrentModel"),r=e.get("processed"),o=e.get("error"),c=t.get("ewSuccessMessage");if(this.deactivateMode("watermarking"),this.deactivateMode("restoring"),this.deactivateMode("processing"),r>0&&Object(i.a)(c.replace("{procesed}",r),"success"),o){var a=ew.i18n.bulkActionErrorMessage.replace("{imageTitle}",n.get("title")).replace("{error}",o);Object(i.a)(a,"error")}e.set({visible:!1,progress:!1})}}])&&bt(e.prototype,n),r&&bt(e,r),a}());var At=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&St(t,e)}(n,t);var e=jt(n);function n(t){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),(r=e.call(this,t)).controller=t.controller,r.bulkActionSelector=t.bulkActionSelector,r}return n}(ft.View);function Pt(t){return(Pt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function xt(t,e,n){return(xt="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=Ct(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function Mt(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function Bt(t,e,n){return e&&Mt(t.prototype,e),n&&Mt(t,n),t}function Et(t,e){return(Et=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function Dt(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=Ct(t);if(e){var o=Ct(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return $t(this,n)}}function $t(t,e){return!e||"object"!==Pt(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function Ct(t){return(Ct=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var Tt=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&Et(t,e)}(n,t);var e=Dt(n);function n(t){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),(r=e.call(this,t)).listenTo(r.controller,"change",r.update),r.listenTo(r.controller,"bulkAction:start",r.reset),r}return Bt(n,[{key:"tagName",value:function(){return"select"}},{key:"className",value:function(){return"ew-status"}},{key:"events",value:function(){return{change:"selectWatermark"}}}]),Bt(n,[{key:"render",value:function(){for(var t in xt(Ct(n.prototype),"render",this).call(this),this.$el.append(o()("<option>",{value:""}).html(ew.i18n.selectWatermarkLabel)),1<Object.keys(ew.watermarks).length&&this.$el.append(o()("<option>",{value:"all"}).html(ew.i18n.allWatermarksLabel)),ew.watermarks)this.$el.append(o()("<option>",{value:t}).html(ew.watermarks[t]));return this.attach(),this}},{key:"update",value:function(){this.bulkActionSelector.is(this.controller.get("select"))&&("watermark"!==this.controller.get("action")||this.controller.status().get("processing")?this.$el.hide():this.$el.show())}},{key:"reset",value:function(){this.$el.val("all").hide()}},{key:"attach",value:function(){return this.bulkActionSelector.after(this.$el),this.$el.hide(),this}},{key:"selectWatermark",value:function(){this.controller.set("watermark",this.$el.val())}}]),n}(At);function zt(t){return(zt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function Nt(t,e,n){return(Nt="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=Ut(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function Wt(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function It(t,e,n){return e&&Wt(t.prototype,e),n&&Wt(t,n),t}function Ft(t,e){return(Ft=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function Lt(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=Ut(t);if(e){var o=Ut(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return Vt(this,n)}}function Vt(t,e){return!e||"object"!==zt(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function Ut(t){return(Ut=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var Ht=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&Ft(t,e)}(n,t);var e=Lt(n);function n(t){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),(r=e.call(this,t)).status=r.controller.status(),r.listenTo(r.status,"change",r.update),r}return It(n,[{key:"tagName",value:function(){return"p"}},{key:"className",value:function(){return"ew-status"}},{key:"template",value:function(){var t=this.status.get("text");if(this.status.get("processing")){var e=this.status.get("processed"),n=this.status.get("total"),r="".concat(e,"/").concat(n),o=Math.floor(e/n*100);"string"==typeof t&&(t=t.replace("{counter}",r)),isNaN(o)&&(o=0),t="".concat(t," (").concat(o,"%)")}return t}}]),It(n,[{key:"render",value:function(){Nt(Ut(n.prototype),"render",this).call(this),this.attach()}},{key:"update",value:function(){this.bulkActionSelector.is(this.controller.get("select"))&&(this.status.get("text")?(this.$el.html(this.template()),this.$el.show()):this.$el.hide())}},{key:"attach",value:function(){return this.bulkActionSelector.parent().append(this.$el),this.$el.hide(),this}}]),n}(At);function Qt(t){return(Qt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function qt(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function Gt(t,e){return(Gt=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function Jt(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=Yt(t);if(e){var o=Yt(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return Kt(this,n)}}function Kt(t,e){return!e||"object"!==Qt(e)&&"function"!=typeof e?Xt(t):e}function Xt(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function Yt(t){return(Yt=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var Zt=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&Gt(t,e)}(a,t);var e,n,r,c=Jt(a);function a(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,a),(e=c.call(this,t)).model=t.model,e.listenTo(e.model,"processing:start",e.showSpinner),e.listenTo(e.model,"processing:done",e.reset),e.listenTo(e.model,"remove",e.deselect),e.controller.on("bulkAction:finished",e.reset,Xt(e)),e}return e=a,(n=[{key:"showSpinner",value:function(){this.getSpinner().appendTo(this.$el.find("span.media-icon"))}},{key:"getSpinner",value:function(){return this.spinner||(this.spinner=o()("<span>",{class:"spinner ew-spinner"})),this.spinner}},{key:"reset",value:function(){this.spinner&&this.spinner.remove(),this.getStatus().text(""),this.$el.find('input[type="checkbox"]').click().prop("checked",!1)}},{key:"deselect",value:function(){var t;this.controller.status().get("processing")||(this.$el.find('input[type="checkbox"]').click().prop("checked",!1),Object(i.d)(this.model)?this.model.get("usedAsWatermark")?t=ew.i18n.usedAsWatermark:"restore"!==this.controller.get("action")||this.model.get("hasBackup")||(t=ew.i18n.noBackupAvailable):t=ew.i18n.notSupported,this.getStatus().text(" - ".concat(t)))}},{key:"getStatus",value:function(){return this.status||(this.status=o()("<span>",{class:"ew-status"}),this.$el.find("strong.has-media-icon").append(this.status)),this.status}}])&&qt(e.prototype,n),r&&qt(e,r),a}(At);function te(t){return(te="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function ee(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return ne(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return ne(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,c=!0,a=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return c=t.done,t},e:function(t){a=!0,i=t},f:function(){try{c||null==n.return||n.return()}finally{if(a)throw i}}}}function ne(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function re(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function oe(t,e){return(oe=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function ie(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=ae(t);if(e){var o=ae(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return ce(this,n)}}function ce(t,e){return!e||"object"!==te(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function ae(t){return(ae=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var se=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&oe(t,e)}(a,t);var e,n,r,c=ie(a);function a(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,a),(t=c.call(this)).bulkActionsSelectors=o()("select#bulk-action-selector-top, select#bulk-action-selector-bottom"),t.bulkActionsSelectors.length&&t.init(),t}return e=a,(n=[{key:"init",value:function(){var t=this;this.selectBulkAction=this.selectBulkAction.bind(this),this.doAction=this.doAction.bind(this),this.form=o()("form#posts-filter"),this.actionButtons=this.form.find("#doaction, #doaction2"),this.bulkActionsSelectors.each((function(e,n){var r=o()(n);new Tt({controller:t,bulkActionSelector:r}).render(),new Ht({controller:t,bulkActionSelector:r}).render()})).val(-1).on("change",this.selectBulkAction),this.set({attachments:new ft.Collection,selection:new ft.Collection}),this.actionButtons.on("click",this.doAction),this.on("bulkAction:start",(function(){t.bulkActionsSelectors.val(-1).prop("disabled",!0),t.actionButtons.prop("disabled",!0)})),this.on("bulkAction:finished",(function(){t.bulkActionsSelectors.prop("disabled",!1),t.actionButtons.prop("disabled",!1)}))}},{key:"selectBulkAction",value:function(t){var e=o()(t.target);this.set({select:e,action:e.val()})}},{key:"doAction",value:function(t){var e=this,n=this.get("action");if(this.checkAction(n)){t.preventDefault();var r=this.get("watermark");if("watermark"!==n||r){var i=this.form.find('input[name="media[]"]:checked');if(i.length){var c=this.get("attachments"),a=this.get("selection"),s=[];this.trigger("bulkAction:start"),i.each((function(t,e){var n=o()(e).val(),r=c.get(n);r?a.add(r):s.push(n)})),s.length?(this.status().set({text:'<span class="spinner ew-spinner"></span>'}),o.a.ajax(ajaxurl,{data:{action:"easy-watermark/attachments-info",nonce:ew.attachmentsInfoNonce,attachments:s}}).done((function(t){if(!0===t.success){var n,r=ee(t.data);try{for(r.s();!(n=r.n()).done;){var o=n.value,i=new ft.Model(o);c.push(i),a.push(i),new Zt({el:"#post-".concat(o.id),controller:e,model:i})}}catch(t){r.e(t)}finally{r.f()}e.prepare()}else{var s=t.data.message?t.data.message:ew.i18n.genericErrorMessage;e.actionError(s)}})).fail((function(){e.actionError(ew.i18n.genericErrorMessage)}))):a.length&&this.prepare()}else this.status().set({text:ew.i18n.noItemsSelected})}}}},{key:"prepare",value:function(){var t=this.get("action"),e=this.get("selection"),n="restore"===t,r="watermark"===t?ew.i18n.watermarkingStatus:ew.i18n.restoringStatus,o="watermark"===t?ew.i18n.watermarkingSuccessMessage:ew.i18n.restoringSuccessMessage;if(Object(i.b)(e,n),!e.length)return this.status().set({successMessage:"watermark"===t?ew.i18n.watermarkingNoItems:ew.i18n.restoringNoItems}),void this.actionDone();this.status().set({successMessage:o,text:r,processing:!0,total:e.length,processed:0});var c,a=ee(e.models);try{for(a.s();!(c=a.n()).done;)c.value.trigger("processing:start")}catch(t){a.e(t)}finally{a.f()}this.doActionRecursive()}},{key:"doActionRecursive",value:function(){var t,e=this,n=this.get("action"),r=this.get("watermark"),c="easy-watermark/";if("watermark"===n)c+="all"===r?"apply_all":"apply_single",t="all"===r?ew.applyAllNonce:ew.applySingleNonces[r];else{if("restore"!==n)return;c+="restore_backup",t=ew.restoreBackupNonce}var a=this.status(),s=this.get("selection"),l=s.shift(),u={action:c,nonce:t,watermark:r},f=a.get("processed");u.attachment_id=l.get("id"),this.set("currentAttachmentID",u.attachment_id),o.a.ajax(ajaxurl,{data:u}).done((function(t){if(!0===t.success){if(t.data.attachmentVersion){var n=e.form.find("tr#post-"+u.attachment_id+" img"),r=Object(i.c)(n.attr("src"),t.data.attachmentVersion);n.attr({src:r,srcset:""})}f++,a.set({processed:f}),l.set("hasBackup",!!t.data.hasBackup),l.trigger("processing:done"),s.length?e.doActionRecursive():e.actionDone()}else{var o="string"==typeof t.data.message?t.data.message:ew.i18n.genericErrorMessage;e.actionError(o)}})).fail((function(){e.actionError(ew.i18n.genericErrorMessage)}))}},{key:"actionError",value:function(t){this.status().set({error:t}),this.actionDone()}},{key:"actionDone",value:function(){this.trigger("bulkAction:finished"),this.bulkActionsSelectors.prop("disabled",!1);var t=this.status(),e=t.get("processed"),n=t.get("error"),r=t.get("successMessage"),o=this.get("currentAttachmentID");if(e>0?Object(i.a)(r.replace("{procesed}",e),"success"):Object(i.a)(r,"info"),n){var c=this.form.find("tr#post-"+o).find(".column-title a").attr("aria-label"),a=ew.i18n.bulkActionErrorMessage.replace("{imageTitle}",c).replace("{error}",n);Object(i.a)(a,"error")}this.status().set({processing:!1,processed:0,total:0,text:""})}},{key:"status",value:function(){var t=this.get("status");return void 0===t&&(t=new ft.Model,t.set({processed:0,total:0}),this.set({status:t})),t}},{key:"checkAction",value:function(t){return["watermark","restore"].includes(t)}}])&&re(e.prototype,n),r&&re(e,r),a}(ft.Model);o()(document).ready((function(){return new se}))},2:function(t,e){t.exports=Backbone},30:function(t,e){}});
1
+ !function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="../",n(n.s=18)}({0:function(t,e){t.exports=jQuery},1:function(t,e,n){"use strict";n.d(e,"a",(function(){return s})),n.d(e,"b",(function(){return l})),n.d(e,"c",(function(){return u})),n.d(e,"d",(function(){return f}));var r=n(0),o=n.n(r);function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function c(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return a(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return a(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,c=!0,s=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return c=t.done,t},e:function(t){s=!0,i=t},f:function(){try{c||null==n.return||n.return()}finally{if(s)throw i}}}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function s(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"info",n=o()(document.createElement("div")),r=o()(document.createElement("p")),i=o()(document.createElement("button"));n.addClass("notice notice-"+e+" is-dismissible").hide(),i.addClass("notice-dismiss"),r.html(t),n.append(r).append(i),i.on("click",(function(t){t.preventDefault(),n.fadeOut(200,(function(){n.remove()}))})),o()("hr.wp-header-end").after(n),n.fadeIn(200)}function l(t){var e,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],o=t.length,i=c(t.clone().models);try{for(i.s();!(e=i.n()).done;){var a=e.value;(!f(a)||a.get("usedAsWatermark")||!0===n&&!a.get("hasBackup"))&&(!0===r&&t.remove(a),o--)}}catch(t){i.e(t)}finally{i.f()}return o}function u(t){var e,n=t.indexOf("?"),r="t=".concat(Date.now());if(-1!==n){e=t.substr(n),t=t.substr(0,n);var o=/([^\s])t=[0-9]+/;e.match(o)?e=e.replace(o,"$1".concat(r)):e+="&".concat(r)}else e="?".concat(r);return t+e}function f(t){return"object"===i(t)&&t.get&&(t=t.get("mime")),Object.keys(ew.mime).includes(t)}},16:function(t,e){function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function i(t,e,n){return(i="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=l(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function c(t,e){return(c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function a(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=l(t);if(e){var o=l(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return s(this,n)}}function s(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function l(t){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}wp.media&&"function"==typeof wp.media.view.SelectModeToggleButton&&(wp.media.view.SelectModeToggleButton=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&c(t,e)}(f,wp.media.view.SelectModeToggleButton);var e,n,s,u=a(f);function f(){return r(this,f),u.apply(this,arguments)}return e=f,(n=[{key:"initialize",value:function(){i(l(f.prototype),"initialize",this).call(this),this.controller.on("processing:activate processing:deactivate",this.toggleDisabled,this)}},{key:"toggleDisabled",value:function(){this.model.set("disabled",this.controller.isModeActive("processing"))}},{key:"toggleBulkEditHandler",value:function(){i(l(f.prototype),"toggleBulkEditHandler",this).call(this),this.controller.trigger("selection:toggle");var t=this.controller.content.get().toolbar;this.controller.isModeActive("select")?t.$(".watermark-mode-toggle-button").removeClass("hidden"):t.$(".watermark-mode-toggle-button").addClass("hidden"),t.$(".watermark-selector").css("display",""),t.$(".ew-status").css("display","")}}])&&o(e.prototype,n),s&&o(e,s),f}())},17:function(t,e){function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function i(t,e,n){return e&&o(t.prototype,e),n&&o(t,n),t}function c(t,e,n){return(c="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=f(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&s(t,e)}function s(t,e){return(s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function l(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=f(t);if(e){var o=f(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return u(this,n)}}function u(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function f(t){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}wp.media&&("function"==typeof wp.media.view.AttachmentFilters.All&&(wp.media.view.AttachmentFilters.All=function(t){a(n,wp.media.view.AttachmentFilters.All);var e=l(n);function n(){return r(this,n),e.apply(this,arguments)}return i(n,[{key:"initialize",value:function(){c(f(n.prototype),"initialize",this).call(this),this.controller.on("processing:activate processing:deactivate",this.toggleDisabled,this)}},{key:"toggleDisabled",value:function(){this.$el.prop("disabled",!this.$el.is(":disabled"))}}]),n}()),"function"==typeof wp.media.view.AttachmentFilters.Uploaded&&(wp.media.view.AttachmentFilters.Uploaded=function(t){a(n,wp.media.view.AttachmentFilters.Uploaded);var e=l(n);function n(){return r(this,n),e.apply(this,arguments)}return i(n,[{key:"initialize",value:function(){c(f(n.prototype),"initialize",this).call(this),this.controller.on("processing:activate processing:deactivate",this.toggleDisabled,this)}},{key:"toggleDisabled",value:function(){this.$el.prop("disabled",!this.$el.is(":disabled"))}}]),n}()),"function"==typeof wp.media.view.DateFilter&&(wp.media.view.DateFilter=function(t){a(n,wp.media.view.DateFilter);var e=l(n);function n(){return r(this,n),e.apply(this,arguments)}return i(n,[{key:"initialize",value:function(){c(f(n.prototype),"initialize",this).call(this),this.controller.on("processing:activate processing:deactivate",this.toggleDisabled,this)}},{key:"toggleDisabled",value:function(){this.$el.prop("disabled",!this.$el.is(":disabled"))}}]),n}()))},18:function(t,e,n){"use strict";n.r(e);n(30);var r=n(0),o=n.n(r),i=n(1);if(wp.media&&"function"==typeof wp.media.view.Attachment.Library){var c=wp.media.view.Attachment.Library;wp.media.view.Attachment.Library=c.extend({initialize:function(){c.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:function(){c.prototype.render.apply(this,arguments),this.$el.append(o()("<span></span>").addClass("spinner"))},toggleSelection:function(t){var e=t.method;(!this.controller.isModeActive("watermark")||Object(i.d)(this.model)&&!this.model.get("usedAsWatermark")||"between"===e)&&c.prototype.toggleSelection.apply(this,arguments),this.controller.isModeActive("watermark")&&(Object(i.d)(this.model)&&!this.model.get("usedAsWatermark")||this.$el.blur(),"between"===e&&Object(i.b)(this.options.selection))},showLoader:function(){this.$el.find(".spinner").css({visibility:"visible"})},disable:function(){if((this.controller.isModeActive("watermark")||this.controller.isModeActive("processing"))&&!this.hasBadge&&(!this.controller.isModeActive("processing")||this.wasSelected())){var t;if(Object(i.d)(this.model))if(this.model.get("usedAsWatermark"))t=ew.i18n.usedAsWatermark;else{if(!this.controller.isModeActive("restoring")||this.model.get("hasBackup"))return;t=ew.i18n.noBackupAvailable}else t=ew.i18n.notSupported;var e=o()("<div>",{class:"badge"}).text(t);this.$el.addClass("disabled").append(e),this.hasBadge=!0}},enable:function(){this.controller.isModeActive("watermark")||this.controller.isModeActive("processing")||(this.$el.removeClass("disabled").find(".badge").remove(),this.hasBadge=!1)},wasSelected:function(){var t=this.controller.state().get("originalSelection");if(t)return!!t.get(this.model.cid)}})}function a(t){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function l(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function u(t,e,n){return(u="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=y(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function f(t,e){return(f=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function p(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=y(t);if(e){var o=y(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return h(this,n)}}function h(t,e){return!e||"object"!==a(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function y(t){return(y=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var d=null;wp.media&&"function"==typeof wp.media.view.Button&&(d=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&f(t,e)}(i,wp.media.view.Button);var e,n,r,o=p(i);function i(){return s(this,i),o.apply(this,arguments)}return e=i,(n=[{key:"initialize",value:function(){var t=this;u(y(i.prototype),"initialize",this).call(this),this.controller.on("watermark:activate",(function(){t.$el.removeClass("hidden").show()})),this.controller.on("watermark:deactivate",(function(){t.$el.addClass("hidden").hide()})),this.controller.on("watermark:selected",this.toggleDisabled,this),this.model.set("disabled",!0)}},{key:"render",value:function(){return u(y(i.prototype),"render",this).call(this),this.controller.isModeActive("watermark")?this.$el.addClass("watermark-button"):this.$el.addClass("watermark-button hidden"),this}},{key:"click",value:function(){u(y(i.prototype),"click",this).call(this),this.controller.state().get("watermark")&&this.controller.ewWatermark()}},{key:"toggleDisabled",value:function(t){this.model.set("disabled",!t.length)}}])&&l(e.prototype,n),r&&l(e,r),i}());var b=d;function m(t){return(m="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function v(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function g(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function w(t,e,n){return(w="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=j(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function k(t,e){return(k=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function O(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=j(t);if(e){var o=j(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return S(this,n)}}function S(t,e){return!e||"object"!==m(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function j(t){return(j=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var _=null;wp.media&&"function"==typeof wp.media.view.Button&&(_=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&k(t,e)}(c,wp.media.view.Button);var e,n,r,o=O(c);function c(){return v(this,c),o.apply(this,arguments)}return e=c,(n=[{key:"initialize",value:function(){w(j(c.prototype),"initialize",this).call(this),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)}},{key:"render",value:function(){return w(j(c.prototype),"render",this).call(this),this.controller.isModeActive("select")&&!this.controller.isModeActive("watermark")?this.$el.addClass("restore-button"):this.$el.addClass("restore-button hidden"),this.update(),this}},{key:"click",value:function(){w(j(c.prototype),"click",this).call(this),this.controller.isModeActive("select")&&this.controller.ewRestoreBackup()}},{key:"update",value:function(){var t=this.model.get("filteredSelectionCount"),e=Object(i.b)(this.controller.state().get("selection"),!0,!1);e!==t&&(this.model.set({filteredSelectionCount:e,text:"".concat(this.model.get("originalText")," (").concat(e,")")}),this.model.set("disabled",!Boolean(e)))}}])&&g(e.prototype,n),r&&g(e,r),c}());var R=_;function A(t){return(A="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function P(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function x(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function M(t,e,n){return(M="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=$(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function B(t,e){return(B=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function E(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=$(t);if(e){var o=$(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return D(this,n)}}function D(t,e){return!e||"object"!==A(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function $(t){return($=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var C=null;wp.media&&"function"==typeof wp.media.view.Button&&(C=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&B(t,e)}(c,wp.media.view.Button);var e,n,r,o=E(c);function c(){return P(this,c),o.apply(this,arguments)}return e=c,(n=[{key:"initialize",value:function(){var t=this;M($(c.prototype),"initialize",this).call(this),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",(function(){return t.$el.html(t.model.get("cancelText"))})),this.controller.on("watermark:deactivate",this.update,this)}},{key:"render",value:function(){return M($(c.prototype),"render",this).call(this),this.controller.isModeActive("select")?this.$el.addClass("watermark-mode-toggle-button"):this.$el.addClass("watermark-mode-toggle-button hidden"),this.update(),this}},{key:"click",value:function(){M($(c.prototype),"click",this).call(this),this.controller.isModeActive("watermark")?this.controller.deactivateMode("watermark"):(this.controller.activateMode("watermark"),Object(i.b)(this.controller.state().get("selection")))}},{key:"update",value:function(){if(!this.controller.isModeActive("watermark")){var t=this.model.get("filteredSelectionCount"),e=Object(i.b)(this.controller.state().get("selection"),!1,!1);e!==t&&(this.model.set({filteredSelectionCount:e,text:"".concat(this.model.get("originalText")," (").concat(e,")")}),this.model.set("disabled",!Boolean(e)),this.controller.state().get("selection").length||this.controller.deactivateMode("watermark"))}}}])&&x(e.prototype,n),r&&x(e,r),c}());var T=C;function z(t){return(z="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function N(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function W(t,e,n){return(W="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=U(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function I(t,e){return(I=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function F(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=U(t);if(e){var o=U(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return L(this,n)}}function L(t,e){return!e||"object"!==z(e)&&"function"!=typeof e?V(t):e}function V(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function U(t){return(U=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var H=null;wp.media&&"function"==typeof wp.media.View&&(H=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&I(t,e)}(c,wp.media.View);var e,n,r,i=F(c);function c(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,c),(e=i.call(this,t)).controller.on("watermark:activate",e.show,V(e)),e.controller.on("watermark:deactivate",e.hide,V(e)),e}return e=c,(n=[{key:"events",value:function(){return{change:"selectWatermark"}}},{key:"tagName",value:function(){return"select"}},{key:"selectWatermark",value:function(){this.controller.trigger("watermark:selected",this.$el.val()),this.controller.state().set("watermark",this.$el.val())}},{key:"show",value:function(){this.$el.removeClass("hidden")}},{key:"hide",value:function(){this.$el.addClass("hidden")}},{key:"render",value:function(){if(W(U(c.prototype),"render",this).call(this),this.$el.append(o()("<option>",{value:""}).html(ew.i18n.selectWatermarkLabel)),ew.watermarks)for(var t in 1<Object.keys(ew.watermarks).length&&this.$el.append(o()("<option>",{value:"all"}).html(ew.i18n.allWatermarksLabel)),ew.watermarks)this.$el.append(o()("<option>",{value:t}).html(ew.watermarks[t]));return this.controller.isModeActive("select")?this.$el.addClass("watermark-selector"):this.$el.addClass("watermark-selector hidden"),this}}])&&N(e.prototype,n),r&&N(e,r),c}());var Q=H;function q(t){return(q="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function G(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function J(t,e,n){return e&&G(t.prototype,e),n&&G(t,n),t}function K(t,e){return(K=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function X(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=tt(t);if(e){var o=tt(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return Y(this,n)}}function Y(t,e){return!e||"object"!==q(e)&&"function"!=typeof e?Z(t):e}function Z(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function tt(t){return(tt=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var et=null;wp.media&&"function"==typeof wp.media.View&&(et=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&K(t,e)}(n,wp.media.View);var e=X(n);function n(t){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),(r=e.call(this,t)).status=r.controller.state().get("ewStatus"),r.status.on("change",r.update,Z(r)),r}return J(n,[{key:"tagName",value:function(){return"p"}},{key:"className",value:function(){return"ew-status"}},{key:"template",value:function(){var t=this.status.get("text");if(this.status.get("progress")){var e=this.status.get("processed"),n=this.status.get("total"),r="".concat(e,"/").concat(n),o=Math.floor(e/n*100);"string"==typeof status&&(t=t.replace("{counter}",r)),t+=" (".concat(o,"%)")}return'<span class="status">'.concat(t,"</span>")}}]),J(n,[{key:"render",value:function(){return this.update(),this}},{key:"update",value:function(){this.status.get("visible")?this.$el.removeClass("hidden").html(this.template()):this.$el.addClass("hidden")}},{key:"cancel",value:function(t){t.preventDefault(),this.controller.deactivateMode("watermarking")}}]),n}());var nt=et;function rt(t){return(rt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function ot(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function it(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function ct(t,e,n){return(ct="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=ut(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function at(t,e){return(at=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function st(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=ut(t);if(e){var o=ut(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return lt(this,n)}}function lt(t,e){return!e||"object"!==rt(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function ut(t){return(ut=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}wp.media&&"function"==typeof wp.media.view.AttachmentsBrowser&&(wp.media.view.AttachmentsBrowser=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&at(t,e)}(i,wp.media.view.AttachmentsBrowser);var e,n,r,o=st(i);function i(){return ot(this,i),o.apply(this,arguments)}return e=i,(n=[{key:"createToolbar",value:function(){var t=this;ct(ut(i.prototype),"createToolbar",this).call(this),this.controller.state().get("ewStatus")&&(Object.keys(ew.watermarks).length&&(this.toolbar.set("watermarkModeToggleButton",new T({text:ew.i18n.watermarkModeToggleButtonLabel,cancelText:ew.i18n.cancelLabel,controller:this.controller,priority:-60}).render()),this.toolbar.set("watermarkSelector",new Q({controller:this.controller,priority:-50}).render()),this.toolbar.set("watermarkButton",new b({text:ew.i18n.watermarkButtonLabel,style:"primary",controller:this.controller,priority:-40}).render())),this.toolbar.set("restoreButton",new R({text:ew.i18n.restoreButtonLabel,controller:this.controller,priority:-30}).render()),this.toolbar.set("watermarkingStatus",new nt({style:"primary",controller:this.controller,priority:-20}).render()),this.controller.on("select:deactivate",(function(){return t.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))}},{key:"hideButtons",value:function(){this.$(".select-mode-toggle-button").addClass("hidden"),this.$(".delete-selected-button").addClass("hidden")}},{key:"showButtons",value:function(){this.$el.html(this.model.get("text")),this.$(".select-mode-toggle-button").removeClass("hidden"),this.$(".delete-selected-button").removeClass("hidden")}},{key:"disableViewSwitch",value:function(){var t=this.toolbar.$(".view-switch");t.hasClass("disabled")?t.removeClass("disabled"):t.addClass("disabled")}}])&&it(e.prototype,n),r&&it(e,r),i}());n(16),n(17);var ft=n(2);function pt(t){return(pt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function ht(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return yt(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return yt(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,c=!0,a=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return c=t.done,t},e:function(t){a=!0,i=t},f:function(){try{c||null==n.return||n.return()}finally{if(a)throw i}}}}function yt(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function dt(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function bt(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function mt(t,e,n){return(mt="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=kt(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function vt(t,e){return(vt=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function gt(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=kt(t);if(e){var o=kt(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return wt(this,n)}}function wt(t,e){return!e||"object"!==pt(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function kt(t){return(kt=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function Ot(t){return(Ot="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function St(t,e){return(St=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function jt(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=Rt(t);if(e){var o=Rt(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return _t(this,n)}}function _t(t,e){return!e||"object"!==Ot(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function Rt(t){return(Rt=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}wp.media&&wp.media.view&&wp.media.view.MediaFrame&&"function"==typeof wp.media.view.MediaFrame.Manage&&(wp.media.view.MediaFrame.Manage=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&vt(t,e)}(a,wp.media.view.MediaFrame.Manage);var e,n,r,c=gt(a);function a(){return dt(this,a),c.apply(this,arguments)}return e=a,(n=[{key:"browseContent",value:function(t){this.state().set({ewCollection:new ft.Collection,ewStatus:new ft.Model}),mt(kt(a.prototype),"browseContent",this).call(this,t)}},{key:"ewBulkAction",value:function(){var t=this.state(),e=t.get("selection"),n=t.get("ewAction"),r=e.clone();if(t.set("originalSelection",r),Object(i.b)(e,"restore"===n),e.length){var o=t.get("ewCollection"),c=t.get("ewStatus");o.reset();var a,s=ht(e.models);try{for(s.s();!(a=s.n()).done;){var l=a.value;o.add(l),l.trigger("ewBulkAction:start")}}catch(t){s.e(t)}finally{s.f()}this.deactivateMode("watermark").trigger("selection:action:done"),this.activateMode("processing"),c.set({total:o.length,processed:0,error:!1,visible:!0,progress:!0}),this.ewBulkActionRecursive()}}},{key:"ewBulkActionRecursive",value:function(){var t,e=this,n=this.state(),r=n.get("ewAction"),c=n.get("watermark"),a="easy-watermark/";if("watermark"===r)a+="all"===c?"apply_all":"apply_single",t="all"===c?ew.applyAllNonce:ew.applySingleNonces[c];else{if("restore"!==r)return;a+="restore_backup",t=ew.restoreBackupNonce}var s=n.get("ewStatus"),l=n.get("ewCollection").shift(),u={action:a,nonce:t,watermark:c},f=s.get("processed");u.attachment_id=l.get("id"),n.set("ewCurrentModel",l),o.a.ajax(ajaxurl,{data:u}).done((function(t){if(!0===t.success){if(t.data.attachmentVersion){l.set("url",Object(i.c)(l.get("url"),t.data.attachmentVersion));for(var n=l.get("sizes"),r=0,o=Object.keys(n);r<o.length;r++){var c=o[r];n[c].url=Object(i.c)(n[c].url,t.data.attachmentVersion)}l.set("sizes",n)}l.set("hasBackup",!!t.data.hasBackup),f++,s.set({processed:f}),l.trigger("ewBulkAction:done"),s.get("total")===f?e.ewBulkActionDone():e.ewBulkActionRecursive()}else{var a="string"==typeof t.data.message?t.data.message:ew.i18n.genericErrorMessage;e.ewBulkActionError(a)}})).fail((function(){e.ewBulkActionError(ew.i18n.genericErrorMessage)}))}},{key:"ewWatermark",value:function(){this.state().set({ewAction:"watermark",ewSuccessMessage:ew.i18n.watermarkingSuccessMessage}).get("ewStatus").set({text:ew.i18n.watermarkingStatus}),this.activateMode("watermarking"),this.ewBulkAction()}},{key:"ewRestoreBackup",value:function(){this.state().set({ewAction:"restore",ewSuccessMessage:ew.i18n.restoringSuccessMessage}).get("ewStatus").set({text:ew.i18n.restoringStatus}),this.activateMode("restoring"),this.ewBulkAction()}},{key:"ewBulkActionError",value:function(t){var e=this.state(),n=e.get("ewStatus"),r=e.get("ewCollection"),o=e.get("ewCurrentModel");o&&r.push(o);var i,c=ht(r.models);try{for(c.s();!(i=c.n()).done;)i.value.trigger("ewBulkAction:done")}catch(t){c.e(t)}finally{c.f()}n.set({error:t}),this.ewBulkActionDone()}},{key:"ewBulkActionDone",value:function(){var t=this.state(),e=t.get("ewStatus"),n=t.get("ewCurrentModel"),r=e.get("processed"),o=e.get("error"),c=t.get("ewSuccessMessage");if(this.deactivateMode("watermarking"),this.deactivateMode("restoring"),this.deactivateMode("processing"),r>0&&Object(i.a)(c.replace("{procesed}",r),"success"),o){var a=ew.i18n.bulkActionErrorMessage.replace("{imageTitle}",n.get("title")).replace("{error}",o);Object(i.a)(a,"error")}e.set({visible:!1,progress:!1})}}])&&bt(e.prototype,n),r&&bt(e,r),a}());var At=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&St(t,e)}(n,t);var e=jt(n);function n(t){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),(r=e.call(this,t)).controller=t.controller,r.bulkActionSelector=t.bulkActionSelector,r}return n}(ft.View);function Pt(t){return(Pt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function xt(t,e,n){return(xt="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=Ct(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function Mt(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function Bt(t,e,n){return e&&Mt(t.prototype,e),n&&Mt(t,n),t}function Et(t,e){return(Et=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function Dt(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=Ct(t);if(e){var o=Ct(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return $t(this,n)}}function $t(t,e){return!e||"object"!==Pt(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function Ct(t){return(Ct=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var Tt=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&Et(t,e)}(n,t);var e=Dt(n);function n(t){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),(r=e.call(this,t)).listenTo(r.controller,"change",r.update),r.listenTo(r.controller,"bulkAction:start",r.reset),r}return Bt(n,[{key:"tagName",value:function(){return"select"}},{key:"className",value:function(){return"ew-status"}},{key:"events",value:function(){return{change:"selectWatermark"}}}]),Bt(n,[{key:"render",value:function(){for(var t in xt(Ct(n.prototype),"render",this).call(this),this.$el.append(o()("<option>",{value:""}).html(ew.i18n.selectWatermarkLabel)),1<Object.keys(ew.watermarks).length&&this.$el.append(o()("<option>",{value:"all"}).html(ew.i18n.allWatermarksLabel)),ew.watermarks)this.$el.append(o()("<option>",{value:t}).html(ew.watermarks[t]));return this.attach(),this}},{key:"update",value:function(){this.bulkActionSelector.is(this.controller.get("select"))&&("watermark"!==this.controller.get("action")||this.controller.status().get("processing")?this.$el.hide():this.$el.show())}},{key:"reset",value:function(){this.$el.val("all").hide()}},{key:"attach",value:function(){return this.bulkActionSelector.after(this.$el),this.$el.hide(),this}},{key:"selectWatermark",value:function(){this.controller.set("watermark",this.$el.val())}}]),n}(At);function zt(t){return(zt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function Nt(t,e,n){return(Nt="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=Ut(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(n):o.value}})(t,e,n||t)}function Wt(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function It(t,e,n){return e&&Wt(t.prototype,e),n&&Wt(t,n),t}function Ft(t,e){return(Ft=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function Lt(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=Ut(t);if(e){var o=Ut(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return Vt(this,n)}}function Vt(t,e){return!e||"object"!==zt(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function Ut(t){return(Ut=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var Ht=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&Ft(t,e)}(n,t);var e=Lt(n);function n(t){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),(r=e.call(this,t)).status=r.controller.status(),r.listenTo(r.status,"change",r.update),r}return It(n,[{key:"tagName",value:function(){return"p"}},{key:"className",value:function(){return"ew-status"}},{key:"template",value:function(){var t=this.status.get("text");if(this.status.get("processing")){var e=this.status.get("processed"),n=this.status.get("total"),r="".concat(e,"/").concat(n),o=Math.floor(e/n*100);"string"==typeof t&&(t=t.replace("{counter}",r)),isNaN(o)&&(o=0),t="".concat(t," (").concat(o,"%)")}return t}}]),It(n,[{key:"render",value:function(){Nt(Ut(n.prototype),"render",this).call(this),this.attach()}},{key:"update",value:function(){this.bulkActionSelector.is(this.controller.get("select"))&&(this.status.get("text")?(this.$el.html(this.template()),this.$el.show()):this.$el.hide())}},{key:"attach",value:function(){return this.bulkActionSelector.parent().append(this.$el),this.$el.hide(),this}}]),n}(At);function Qt(t){return(Qt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function qt(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function Gt(t,e){return(Gt=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function Jt(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=Yt(t);if(e){var o=Yt(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return Kt(this,n)}}function Kt(t,e){return!e||"object"!==Qt(e)&&"function"!=typeof e?Xt(t):e}function Xt(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function Yt(t){return(Yt=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var Zt=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&Gt(t,e)}(a,t);var e,n,r,c=Jt(a);function a(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,a),(e=c.call(this,t)).model=t.model,e.listenTo(e.model,"processing:start",e.showSpinner),e.listenTo(e.model,"processing:done",e.reset),e.listenTo(e.model,"remove",e.deselect),e.controller.on("bulkAction:finished",e.reset,Xt(e)),e}return e=a,(n=[{key:"showSpinner",value:function(){this.getSpinner().appendTo(this.$el.find("span.media-icon"))}},{key:"getSpinner",value:function(){return this.spinner||(this.spinner=o()("<span>",{class:"spinner ew-spinner"})),this.spinner}},{key:"reset",value:function(){this.spinner&&this.spinner.remove(),this.getStatus().text(""),this.$el.find('input[type="checkbox"]').click().prop("checked",!1)}},{key:"deselect",value:function(){var t;this.controller.status().get("processing")||(this.$el.find('input[type="checkbox"]').click().prop("checked",!1),Object(i.d)(this.model)?this.model.get("usedAsWatermark")?t=ew.i18n.usedAsWatermark:"restore"!==this.controller.get("action")||this.model.get("hasBackup")||(t=ew.i18n.noBackupAvailable):t=ew.i18n.notSupported,this.getStatus().text(" - ".concat(t)))}},{key:"getStatus",value:function(){return this.status||(this.status=o()("<span>",{class:"ew-status"}),this.$el.find("strong.has-media-icon").append(this.status)),this.status}}])&&qt(e.prototype,n),r&&qt(e,r),a}(At);function te(t){return(te="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function ee(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return ne(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return ne(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,c=!0,a=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return c=t.done,t},e:function(t){a=!0,i=t},f:function(){try{c||null==n.return||n.return()}finally{if(a)throw i}}}}function ne(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function re(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function oe(t,e){return(oe=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function ie(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=ae(t);if(e){var o=ae(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return ce(this,n)}}function ce(t,e){return!e||"object"!==te(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function ae(t){return(ae=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var se=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&oe(t,e)}(a,t);var e,n,r,c=ie(a);function a(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,a),(t=c.call(this)).bulkActionsSelectors=o()("select#bulk-action-selector-top, select#bulk-action-selector-bottom"),t.bulkActionsSelectors.length&&t.init(),t}return e=a,(n=[{key:"init",value:function(){var t=this;this.selectBulkAction=this.selectBulkAction.bind(this),this.doAction=this.doAction.bind(this),this.form=o()("form#posts-filter"),this.actionButtons=this.form.find("#doaction, #doaction2"),this.bulkActionsSelectors.each((function(e,n){var r=o()(n);new Tt({controller:t,bulkActionSelector:r}).render(),new Ht({controller:t,bulkActionSelector:r}).render()})).val(-1).on("change",this.selectBulkAction),this.set({attachments:new ft.Collection,selection:new ft.Collection}),this.actionButtons.on("click",this.doAction),this.on("bulkAction:start",(function(){t.bulkActionsSelectors.val(-1).prop("disabled",!0),t.actionButtons.prop("disabled",!0)})),this.on("bulkAction:finished",(function(){t.bulkActionsSelectors.prop("disabled",!1),t.actionButtons.prop("disabled",!1)}))}},{key:"selectBulkAction",value:function(t){var e=o()(t.target);this.set({select:e,action:e.val()})}},{key:"doAction",value:function(t){var e=this,n=this.get("action");if(this.checkAction(n)){t.preventDefault();var r=this.get("watermark");if("watermark"!==n||r){var i=this.form.find('input[name="media[]"]:checked');if(i.length){var c=this.get("attachments"),a=this.get("selection"),s=[];this.trigger("bulkAction:start"),i.each((function(t,e){var n=o()(e).val(),r=c.get(n);r?a.add(r):s.push(n)})),s.length?(this.status().set({text:'<span class="spinner ew-spinner"></span>'}),o.a.ajax(ajaxurl,{data:{action:"easy-watermark/attachments-info",nonce:ew.attachmentsInfoNonce,attachments:s}}).done((function(t){if(!0===t.success){var n,r=ee(t.data);try{for(r.s();!(n=r.n()).done;){var o=n.value,i=new ft.Model(o);c.push(i),a.push(i),new Zt({el:"#post-".concat(o.id),controller:e,model:i})}}catch(t){r.e(t)}finally{r.f()}e.prepare()}else{var s=t.data.message?t.data.message:ew.i18n.genericErrorMessage;e.actionError(s)}})).fail((function(){e.actionError(ew.i18n.genericErrorMessage)}))):a.length&&this.prepare()}else this.status().set({text:ew.i18n.noItemsSelected})}}}},{key:"prepare",value:function(){var t=this.get("action"),e=this.get("selection"),n="restore"===t,r="watermark"===t?ew.i18n.watermarkingStatus:ew.i18n.restoringStatus,o="watermark"===t?ew.i18n.watermarkingSuccessMessage:ew.i18n.restoringSuccessMessage;if(Object(i.b)(e,n),!e.length)return this.status().set({successMessage:"watermark"===t?ew.i18n.watermarkingNoItems:ew.i18n.restoringNoItems}),void this.actionDone();this.status().set({successMessage:o,text:r,processing:!0,total:e.length,processed:0});var c,a=ee(e.models);try{for(a.s();!(c=a.n()).done;)c.value.trigger("processing:start")}catch(t){a.e(t)}finally{a.f()}this.doActionRecursive()}},{key:"doActionRecursive",value:function(){var t,e=this,n=this.get("action"),r=this.get("watermark"),c="easy-watermark/";if("watermark"===n)c+="all"===r?"apply_all":"apply_single",t="all"===r?ew.applyAllNonce:ew.applySingleNonces[r];else{if("restore"!==n)return;c+="restore_backup",t=ew.restoreBackupNonce}var a=this.status(),s=this.get("selection"),l=s.shift(),u={action:c,nonce:t,watermark:r},f=a.get("processed");u.attachment_id=l.get("id"),this.set("currentAttachmentID",u.attachment_id),o.a.ajax(ajaxurl,{data:u}).done((function(t){if(!0===t.success){if(t.data.attachmentVersion){var n=e.form.find("tr#post-"+u.attachment_id+" img"),r=Object(i.c)(n.attr("src"),t.data.attachmentVersion);n.attr({src:r,srcset:""})}f++,a.set({processed:f}),l.set("hasBackup",!!t.data.hasBackup),l.trigger("processing:done"),s.length?e.doActionRecursive():e.actionDone()}else{var o="string"==typeof t.data.message?t.data.message:ew.i18n.genericErrorMessage;e.actionError(o)}})).fail((function(){e.actionError(ew.i18n.genericErrorMessage)}))}},{key:"actionError",value:function(t){this.status().set({error:t}),this.actionDone()}},{key:"actionDone",value:function(){this.trigger("bulkAction:finished"),this.bulkActionsSelectors.prop("disabled",!1);var t=this.status(),e=t.get("processed"),n=t.get("error"),r=t.get("successMessage"),o=this.get("currentAttachmentID");if(e>0?Object(i.a)(r.replace("{procesed}",e),"success"):Object(i.a)(r,"info"),n){var c=this.form.find("tr#post-"+o).find(".column-title a").attr("aria-label"),a=ew.i18n.bulkActionErrorMessage.replace("{imageTitle}",c).replace("{error}",n);Object(i.a)(a,"error")}this.status().set({processing:!1,processed:0,total:0,text:""})}},{key:"status",value:function(){var t=this.get("status");return void 0===t&&(t=new ft.Model,t.set({processed:0,total:0}),this.set({status:t})),t}},{key:"checkAction",value:function(t){return["watermark","restore"].includes(t)}}])&&re(e.prototype,n),r&&re(e,r),a}(ft.Model);o()(document).ready((function(){return new se}))},2:function(t,e){t.exports=Backbone},30:function(t,e){}});
assets/dist/scripts/watermark-edit.js CHANGED
@@ -1,4 +1,4 @@
1
- !function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="../",i(i.s=19)}({0:function(t,e){t.exports=jQuery},1:function(t,e,i){"use strict";i.d(e,"a",(function(){return c})),i.d(e,"b",(function(){return l})),i.d(e,"c",(function(){return u})),i.d(e,"d",(function(){return h}));var n=i(0),r=i.n(n);function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function a(t,e){var i;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(i=function(t,e){if(!t)return;if("string"==typeof t)return s(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);"Object"===i&&t.constructor&&(i=t.constructor.name);if("Map"===i||"Set"===i)return Array.from(t);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return s(t,e)}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0,r=function(){};return{s:r,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,c=!1;return{s:function(){i=t[Symbol.iterator]()},n:function(){var t=i.next();return a=t.done,t},e:function(t){c=!0,o=t},f:function(){try{a||null==i.return||i.return()}finally{if(c)throw o}}}}function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function c(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"info",i=r()(document.createElement("div")),n=r()(document.createElement("p")),o=r()(document.createElement("button"));i.addClass("notice notice-"+e+" is-dismissible").hide(),o.addClass("notice-dismiss"),n.html(t),i.append(n).append(o),o.on("click",(function(t){t.preventDefault(),i.fadeOut(200,(function(){i.remove()}))})),r()("hr.wp-header-end").after(i),i.fadeIn(200)}function l(t){var e,i=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=t.length,o=a(t.clone().models);try{for(o.s();!(e=o.n()).done;){var s=e.value;(!h(s)||s.get("usedAsWatermark")||!0===i&&!s.get("hasBackup"))&&(!0===n&&t.remove(s),r--)}}catch(t){o.e(t)}finally{o.f()}return r}function u(t,e){var i=t.indexOf("?");return-1!==i&&(t=t.substr(0,i)),t+="?v="+e}function h(t){return"object"===o(t)&&t.get&&(t=t.get("mime")),Object.keys(ew.mime).includes(t)}},19:function(t,e,i){"use strict";i.r(e);var n=i(0),r=i.n(n);i(32);function o(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var a=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.metabox=r()("#watermark-content"),this.form=r()("form#post"),this.imageContent=this.metabox.find(".image-content"),this.textContent=this.metabox.find(".text-content"),this.buttonWrap=this.metabox.find(".select-image-button"),this.button=this.buttonWrap.find("a"),this.imageWrap=this.metabox.find(".watermark-image"),this.image=this.imageWrap.find("img"),this.mimeTypeField=this.metabox.find("input.watermark-mime-type"),this.urlField=this.metabox.find("input.watermark-url"),this.attachmentIdField=this.metabox.find("input.watermark-id"),this.opacityField=this.metabox.find("input#opacity"),this.opacityFieldDesc=this.metabox.find(".opacity-desc"),this.watermarkTextField=this.metabox.find("input.watermark-text"),this.attachmentId=this.attachmentIdField.val(),this.openMediaLibrary=this.openMediaLibrary.bind(this),this.update=this.update.bind(this),this.watermarkTextChange=this.watermarkTextChange.bind(this),this.form.on("ew.update",this.update),this.button.on("click",this.openMediaLibrary),this.image.on("click",this.openMediaLibrary),this.image.attr("src")?(this.imageWrap.show(),this.switchOpacityField(this.mimeTypeField.val())):this.buttonWrap.show(),this.textChangeTimeout=null,this.watermarkTextField.on("input",this.watermarkTextChange)}var e,i,n;return e=t,(i=[{key:"enable",value:function(t){this.metabox.fadeIn(200),"image"===t?(this.imageContent.show(),this.textContent.hide(),this.opacityField.prop("disabled",!1)):(this.textContent.show(),this.imageContent.hide(),this.opacityField.prop("disabled",!0),this.prepareTextPreview())}},{key:"watermarkTextChange",value:function(){var t=this;clearTimeout(this.textChangeTimeout),this.textChangeTimeout=setTimeout((function(){t.form.trigger("ew.save")}),500)}},{key:"prepareTextPreview",value:function(){this.previewWrap||(this.previewWrap=this.metabox.find(".text-preview"),this.preview=r()(document.createElement("img")),this.previewWrap.hide().append(this.preview)),this.refreshPreview()}},{key:"refreshPreview",value:function(){if(this.watermarkTextField.val().length){var t=this.previewWrap.data("src")+"?t="+Date.now();this.preview.attr("src",t),this.previewWrap.show()}else this.previewWrap.hide()}},{key:"openMediaLibrary",value:function(t){t.preventDefault(),this.frame||this.createMediaFrame(),this.frame.open()}},{key:"createMediaFrame",value:function(){this.frame=wp.media.frames.watermarkSelection=wp.media({title:this.button.data("choose"),library:{type:"image"},button:{text:this.button.data("buttonLabel"),close:!0}}),this.frame.on("select",this.selectImage,this).on("open",this.applySelection,this).on("close",this.checkSelectedAttachment,this)}},{key:"selectImage",value:function(){var t=this.frame.state().get("selection").first(),e=t.get("mime"),i=t.get("url");this.attachmentId=t.get("id"),this.mimeTypeField.val(e),this.urlField.val(i),this.attachmentIdField.val(this.attachmentId),this.switchOpacityField(e),this.image.attr("src",i),this.imageWrap.show(),this.buttonWrap.hide(),this.form.trigger("ew.save")}},{key:"applySelection",value:function(){if(this.attachmentId){var t=this.frame.state().get("selection"),e=wp.media.attachment(this.attachmentId);e.fetch(),e&&t.add([e])}}},{key:"checkSelectedAttachment",value:function(){var t=wp.media.attachment(this.attachmentId);t.fetch(),t&&!0!==t.destroyed||(this.mimeTypeField.val(""),this.urlField.val(""),this.attachmentIdField.val(""),this.imageWrap.hide(),this.buttonWrap.show())}},{key:"switchOpacityField",value:function(t){"image/png"===t?(this.opacityField.parent().hide(),this.opacityFieldDesc.show()):(this.opacityField.parent().show(),this.opacityFieldDesc.hide())}},{key:"update",value:function(){"text"===this.form.find("input.watermark-type:checked").val()&&this.refreshPreview()}}])&&o(e.prototype,i),n&&o(e,n),t}();function s(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var c=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.metabox=r()("#alignment")}var e,i,n;return e=t,(i=[{key:"enable",value:function(){this.metabox.fadeIn(200)}}])&&s(e.prototype,i),n&&s(e,n),t}();function l(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var u=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.metabox=r()("#applying-rules"),this.autoAddCheckbox=this.metabox.find("#watermark-autoadd"),this.hiddenSections=this.metabox.find(".hidden"),this.toggleOptionsVisibility=this.toggleOptionsVisibility.bind(this),this.autoAddCheckbox.on("change",this.toggleOptionsVisibility),this.toggleOptionsVisibility()}var e,i,n;return e=t,(i=[{key:"enable",value:function(){this.metabox.fadeIn(200)}},{key:"toggleOptionsVisibility",value:function(){this.autoAddCheckbox.prop("checked")?this.hiddenSections.show():this.hiddenSections.hide()}}])&&l(e.prototype,i),n&&l(e,n),t}();function h(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var f=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.metabox=r()("#scaling"),this.scalingModeSelect=this.metabox.find("#watermark-scaling-mode"),this.hiddenSections=this.metabox.find(".hidden"),this.fields=this.metabox.find("input, select"),this.toggleOptionsVisibility=this.toggleOptionsVisibility.bind(this),this.scalingModeSelect.on("change",this.toggleOptionsVisibility),this.toggleOptionsVisibility()}var e,i,n;return e=t,(i=[{key:"enable",value:function(t){"image"===t?(this.metabox.fadeIn(200),this.fields.prop("disabled",!1)):(this.metabox.hide(),this.fields.prop("disabled",!0))}},{key:"toggleOptionsVisibility",value:function(){switch(this.hiddenSections.hide(),this.scalingModeSelect.val()){case"fit_to_width":case"fit_to_height":this.hiddenSections.show();break;case"cover":case"contain":this.hiddenSections.filter(".show-for-all").show()}}}])&&h(e.prototype,i),n&&h(e,n),t}();function d(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var p=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.metabox=r()("#text-options"),this.form=r()("form#post"),this.colorInput=this.metabox.find("#text-color"),this.fields=this.metabox.find("input, select"),this.colorChangeTimeout=null,this.colorChanged=this.colorChanged.bind(this),this.colorInput.wpColorPicker({palettes:!0,change:this.colorChanged})}var e,i,n;return e=t,(i=[{key:"colorChanged",value:function(){var t=this;clearTimeout(this.colorChangeTimeout),this.colorChangeTimeout=setTimeout((function(){t.form.trigger("ew.save")}),500)}},{key:"enable",value:function(t){"text"===t?(this.metabox.fadeIn(200),this.fields.prop("disabled",!1)):(this.metabox.hide(),this.fields.prop("disabled",!0))}}])&&d(e.prototype,i),n&&d(e,n),t}(),m=i(1);function y(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var b=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.metabox=r()("#preview"),this.body=r()("body"),this.form=r()("form#post"),this.watermarkTextField=this.form.find("input.watermark-text"),this.attachmentIdField=this.form.find("input.watermark-id"),this.link=this.metabox.find(".select-preview-image"),this.previewWrap=this.metabox.find(".preview-wrap"),this.contentWrap=this.metabox.find(".content-wrap"),this.imageSelector=this.metabox.find(".image-selector"),this.popup=this.metabox.find(".ew-preview-popup"),this.spinner=this.metabox.find("span.spinner"),this.image=r()(document.createElement("img")),this.popup.appendTo(this.body),this.openMediaLibrary=this.openMediaLibrary.bind(this),this.openPopup=this.openPopup.bind(this),this.closePopup=this.closePopup.bind(this),this.selectImage=this.selectImage.bind(this),this.imageSelected=this.imageSelected.bind(this),this.update=this.update.bind(this),this.hasImage=this.previewWrap.data("hasImage"),this.link.on("click",this.openMediaLibrary),this.form.on("ew.update",this.update),this.image.on("click",this.openPopup),this.popup.find(".media-modal-close, .media-modal-backdrop").on("click",this.closePopup),this.imageSelector.hide(),this.contentWrap.hide(),this.previewWrap.prepend(this.image),this.refreshPreview()}var e,i,n;return e=t,(i=[{key:"enable",value:function(){this.metabox.fadeIn(200)}},{key:"openMediaLibrary",value:function(t){t.preventDefault(),this.frame||this.createMediaFrame(),this.frame.open()}},{key:"createMediaFrame",value:function(){this.frame=wp.media.frames.previewImage=wp.media({title:this.link.data("choose"),library:{type:"image"},button:{text:this.link.data("buttonLabel"),close:!0}}),this.frame.on("select",this.selectImage)}},{key:"selectImage",value:function(){var t=this.frame.state().get("selection").first(),e=this.form.find("input[name=post_ID]").val();this.contentWrap.hide(),this.spinner.css("display","block"),r.a.ajax({type:"post",url:ajaxurl,data:{action:"easy-watermark/preview_image",attachment_id:t.id,watermark_id:e,nonce:ew.previewImageNonce}}).done(this.imageSelected).fail((function(){}))}},{key:"imageSelected",value:function(t){if(!0===t.success){if(this.link.html(this.link.data("changeLabel")),this.hasImage=!0,t.data.popup){var e=r()(t.data.popup);this.popup.find(".media-frame-content").replaceWith(e.find(".media-frame-content"))}this.refreshPreview()}}},{key:"refreshPreview",value:function(){var t=this;if(this.contentWrap.hide(),this.hasImage){this.imageSelector.hide(),this.spinner.css("display","block");var e=Date.now(),i=Object(m.c)(this.previewWrap.data("src"),e);this.popup.find("img").each((function(t,i){var n=r()(i),o=Object(m.c)(n.attr("src"),e);n.attr("src",o)})),this.image.one("load",(function(){t.spinner.hide(),t.contentWrap.fadeIn(200),t.imageSelector.fadeIn(200)})).attr("src",i)}else this.imageSelector.show()}},{key:"openPopup",value:function(){this.popup.show(),this.body.addClass("modal-open")}},{key:"closePopup",value:function(){this.popup.hide(),this.body.removeClass("modal-open")}},{key:"hasPreview",value:function(){var t=this.form.find("input.watermark-type:checked").val();return!("text"!==t||!this.watermarkTextField.val().length)||!("image"!==t||!this.attachmentIdField.val().length)}},{key:"update",value:function(){this.refreshPreview()}}])&&y(e.prototype,i),n&&y(e,n),t}(),v=i(4),g=i.n(v);function w(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var k=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.metabox=r()("#placeholders"),this.placeholders=this.metabox.find(".placeholders-list li"),this.searchField=this.metabox.find("input.ew-search-placeholders"),this.clipboard=new g.a(".placeholders-list code"),this.clipboardSuccess=this.clipboardSuccess.bind(this),this.filterPlaceholders=this.filterPlaceholders.bind(this),this.clipboard.on("success",this.clipboardSuccess),this.searchField.on("keyup",this.filterPlaceholders)}var e,i,n;return e=t,(i=[{key:"enable",value:function(t){"text"===t?this.metabox.fadeIn(200):this.metabox.hide()}},{key:"clipboardSuccess",value:function(t){var e=r()(t.trigger);e.text("Copied"),setTimeout((function(){e.text(t.text)}),1e3)}},{key:"filterPlaceholders",value:function(t){var e=r()(t.target).val();this.placeholders.hide().each((function(t,i){var n=r()(i);-1!==n.find("code").text().toLowerCase().indexOf(e)&&n.show()}))}}])&&w(e.prototype,i),n&&w(e,n),t}();function x(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var S=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.fields=r()(".form-field"),this.buttons=this.fields.find("button[data-toggle=dropdown]"),this.dropdowns=this.fields.find(".dropdown-menu[data-target]"),this.links=this.dropdowns.find("a"),this.init()}var e,i,n;return e=t,(i=[{key:"init",value:function(){this.toggleDropdown=this.toggleDropdown.bind(this),this.dropdownSelect=this.dropdownSelect.bind(this),this.hideDropdowns=this.hideDropdowns.bind(this),this.buttons.on("click",this.toggleDropdown),this.links.on("click",this.dropdownSelect),r()(document).on("click",this.hideDropdowns)}},{key:"toggleDropdown",value:function(t){t.preventDefault();var e=r()(t.target),i=e.position();e.next(".dropdown-menu").css({left:i.left,top:i.top+e.height()}).toggle()}},{key:"dropdownSelect",value:function(t){t.preventDefault();var e=r()(t.target),i=e.closest(".dropdown-menu"),n=r()(i.data("target"));n.length&&(n.val(e.data("value")),i.prev("button[data-toggle=dropdown]").text(e.text()))}},{key:"hideDropdowns",value:function(t){r()(t.target).is(this.buttons)||this.dropdowns.hide()}}])&&x(e.prototype,i),n&&x(e,n),t}();function T(t,e){var i;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(i=function(t,e){if(!t)return;if("string"==typeof t)return E(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);"Object"===i&&t.constructor&&(i=t.constructor.name);if("Map"===i||"Set"===i)return Array.from(t);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return E(t,e)}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0,r=function(){};return{s:r,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){i=t[Symbol.iterator]()},n:function(){var t=i.next();return a=t.done,t},e:function(t){s=!0,o=t},f:function(){try{a||null==i.return||i.return()}finally{if(s)throw o}}}}function E(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function C(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var O=function(){function t(){var e=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.selectWatermarkType=this.selectWatermarkType.bind(this),this.triggerSave=this.triggerSave.bind(this),this.form=r()("form#post"),this.selector=this.form.find("input.watermark-type"),this.metaboxes=[new a,new c,new u,new f,new p,new b,new k],new S;var i=this.selector.filter("[checked]");i.length&&this.selectWatermarkType(i[0].value),this.selector.on("change",(function(t){e.selectWatermarkType(t.target.value)})),this.form.on("change","input, select",this.triggerSave).on("ew.save",this.triggerSave)}var e,i,n;return e=t,(i=[{key:"selectWatermarkType",value:function(t){var e,i=T(this.metaboxes);try{for(i.s();!(e=i.n()).done;)e.value.enable(t)}catch(t){i.e(t)}finally{i.f()}}},{key:"triggerSave",value:function(){var t=this,e={action:"easy-watermark/autosave",nonce:ew.autosaveNonce},i=this.form.find("[name^=watermark], [name=post_ID]").serialize();for(var n in e)i+="&"+encodeURIComponent(n)+"="+encodeURIComponent(e[n]);r.a.ajax({type:"post",url:ajaxurl,data:i}).done((function(e){!0===e.success&&t.form.trigger("ew.update")})).fail((function(){}))}}])&&C(e.prototype,i),n&&C(e,n),t}();r()(document).ready((function(){return new O}))},32:function(t,e){},4:function(t,e,i){
2
  /*!
3
  * clipboard.js v2.0.6
4
  * https://clipboardjs.com/
1
+ !function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="../",i(i.s=19)}({0:function(t,e){t.exports=jQuery},1:function(t,e,i){"use strict";i.d(e,"a",(function(){return c})),i.d(e,"b",(function(){return l})),i.d(e,"c",(function(){return u})),i.d(e,"d",(function(){return h}));var n=i(0),r=i.n(n);function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function a(t,e){var i;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(i=function(t,e){if(!t)return;if("string"==typeof t)return s(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);"Object"===i&&t.constructor&&(i=t.constructor.name);if("Map"===i||"Set"===i)return Array.from(t);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return s(t,e)}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0,r=function(){};return{s:r,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,c=!1;return{s:function(){i=t[Symbol.iterator]()},n:function(){var t=i.next();return a=t.done,t},e:function(t){c=!0,o=t},f:function(){try{a||null==i.return||i.return()}finally{if(c)throw o}}}}function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function c(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"info",i=r()(document.createElement("div")),n=r()(document.createElement("p")),o=r()(document.createElement("button"));i.addClass("notice notice-"+e+" is-dismissible").hide(),o.addClass("notice-dismiss"),n.html(t),i.append(n).append(o),o.on("click",(function(t){t.preventDefault(),i.fadeOut(200,(function(){i.remove()}))})),r()("hr.wp-header-end").after(i),i.fadeIn(200)}function l(t){var e,i=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=t.length,o=a(t.clone().models);try{for(o.s();!(e=o.n()).done;){var s=e.value;(!h(s)||s.get("usedAsWatermark")||!0===i&&!s.get("hasBackup"))&&(!0===n&&t.remove(s),r--)}}catch(t){o.e(t)}finally{o.f()}return r}function u(t){var e,i=t.indexOf("?"),n="t=".concat(Date.now());if(-1!==i){e=t.substr(i),t=t.substr(0,i);var r=/([^\s])t=[0-9]+/;e.match(r)?e=e.replace(r,"$1".concat(n)):e+="&".concat(n)}else e="?".concat(n);return t+e}function h(t){return"object"===o(t)&&t.get&&(t=t.get("mime")),Object.keys(ew.mime).includes(t)}},19:function(t,e,i){"use strict";i.r(e);var n=i(0),r=i.n(n),o=(i(32),i(1));function a(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var s=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.metabox=r()("#watermark-content"),this.form=r()("form#post"),this.imageContent=this.metabox.find(".image-content"),this.textContent=this.metabox.find(".text-content"),this.buttonWrap=this.metabox.find(".select-image-button"),this.button=this.buttonWrap.find("a"),this.imageWrap=this.metabox.find(".watermark-image"),this.image=this.imageWrap.find("img"),this.mimeTypeField=this.metabox.find("input.watermark-mime-type"),this.urlField=this.metabox.find("input.watermark-url"),this.attachmentIdField=this.metabox.find("input.watermark-id"),this.opacityField=this.metabox.find("input#opacity"),this.opacityFieldDesc=this.metabox.find(".opacity-desc"),this.watermarkTextField=this.metabox.find("input.watermark-text"),this.attachmentId=this.attachmentIdField.val(),this.openMediaLibrary=this.openMediaLibrary.bind(this),this.update=this.update.bind(this),this.watermarkTextChange=this.watermarkTextChange.bind(this),this.form.on("ew.update",this.update),this.button.on("click",this.openMediaLibrary),this.image.on("click",this.openMediaLibrary),this.image.attr("src")?(this.imageWrap.show(),this.switchOpacityField(this.mimeTypeField.val())):this.buttonWrap.show(),this.textChangeTimeout=null,this.watermarkTextField.on("input",this.watermarkTextChange)}var e,i,n;return e=t,(i=[{key:"enable",value:function(t){this.metabox.fadeIn(200),"image"===t?(this.imageContent.show(),this.textContent.hide(),this.opacityField.prop("disabled",!1)):(this.textContent.show(),this.imageContent.hide(),this.opacityField.prop("disabled",!0),this.prepareTextPreview())}},{key:"watermarkTextChange",value:function(){var t=this;clearTimeout(this.textChangeTimeout),this.textChangeTimeout=setTimeout((function(){t.form.trigger("ew.save")}),500)}},{key:"prepareTextPreview",value:function(){this.previewWrap||(this.previewWrap=this.metabox.find(".text-preview"),this.preview=r()(document.createElement("img")),this.previewWrap.hide().append(this.preview)),this.refreshPreview()}},{key:"refreshPreview",value:function(){if(this.watermarkTextField.val().length){var t=Object(o.c)(this.previewWrap.data("src"));this.preview.attr("src",t),this.previewWrap.show()}else this.previewWrap.hide()}},{key:"openMediaLibrary",value:function(t){t.preventDefault(),this.frame||this.createMediaFrame(),this.frame.open()}},{key:"createMediaFrame",value:function(){this.frame=wp.media.frames.watermarkSelection=wp.media({title:this.button.data("choose"),library:{type:"image"},button:{text:this.button.data("buttonLabel"),close:!0}}),this.frame.on("select",this.selectImage,this).on("open",this.applySelection,this).on("close",this.checkSelectedAttachment,this)}},{key:"selectImage",value:function(){var t=this.frame.state().get("selection").first(),e=t.get("mime"),i=t.get("url");this.attachmentId=t.get("id"),this.mimeTypeField.val(e),this.urlField.val(i),this.attachmentIdField.val(this.attachmentId),this.switchOpacityField(e),this.image.attr("src",i),this.imageWrap.show(),this.buttonWrap.hide(),this.form.trigger("ew.save")}},{key:"applySelection",value:function(){if(this.attachmentId){var t=this.frame.state().get("selection"),e=wp.media.attachment(this.attachmentId);e.fetch(),e&&t.add([e])}}},{key:"checkSelectedAttachment",value:function(){var t=wp.media.attachment(this.attachmentId);t.fetch(),t&&!0!==t.destroyed||(this.mimeTypeField.val(""),this.urlField.val(""),this.attachmentIdField.val(""),this.imageWrap.hide(),this.buttonWrap.show())}},{key:"switchOpacityField",value:function(t){"image/png"===t?(this.opacityField.parent().hide(),this.opacityFieldDesc.show()):(this.opacityField.parent().show(),this.opacityFieldDesc.hide())}},{key:"update",value:function(){"text"===this.form.find("input.watermark-type:checked").val()&&this.refreshPreview()}}])&&a(e.prototype,i),n&&a(e,n),t}();function c(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var l=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.metabox=r()("#alignment")}var e,i,n;return e=t,(i=[{key:"enable",value:function(){this.metabox.fadeIn(200)}}])&&c(e.prototype,i),n&&c(e,n),t}();function u(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var h=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.metabox=r()("#applying-rules"),this.autoAddCheckbox=this.metabox.find("#watermark-autoadd"),this.hiddenSections=this.metabox.find(".hidden"),this.toggleOptionsVisibility=this.toggleOptionsVisibility.bind(this),this.autoAddCheckbox.on("change",this.toggleOptionsVisibility),this.toggleOptionsVisibility()}var e,i,n;return e=t,(i=[{key:"enable",value:function(){this.metabox.fadeIn(200)}},{key:"toggleOptionsVisibility",value:function(){this.autoAddCheckbox.prop("checked")?this.hiddenSections.show():this.hiddenSections.hide()}}])&&u(e.prototype,i),n&&u(e,n),t}();function f(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var d=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.metabox=r()("#scaling"),this.scalingModeSelect=this.metabox.find("#watermark-scaling-mode"),this.hiddenSections=this.metabox.find(".hidden"),this.fields=this.metabox.find("input, select"),this.toggleOptionsVisibility=this.toggleOptionsVisibility.bind(this),this.scalingModeSelect.on("change",this.toggleOptionsVisibility),this.toggleOptionsVisibility()}var e,i,n;return e=t,(i=[{key:"enable",value:function(t){"image"===t?(this.metabox.fadeIn(200),this.fields.prop("disabled",!1)):(this.metabox.hide(),this.fields.prop("disabled",!0))}},{key:"toggleOptionsVisibility",value:function(){switch(this.hiddenSections.hide(),this.scalingModeSelect.val()){case"fit_to_width":case"fit_to_height":this.hiddenSections.show();break;case"cover":case"contain":this.hiddenSections.filter(".show-for-all").show()}}}])&&f(e.prototype,i),n&&f(e,n),t}();function p(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var m=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.metabox=r()("#text-options"),this.form=r()("form#post"),this.colorInput=this.metabox.find("#text-color"),this.fields=this.metabox.find("input, select"),this.colorChangeTimeout=null,this.colorChanged=this.colorChanged.bind(this),this.colorInput.wpColorPicker({palettes:!0,change:this.colorChanged})}var e,i,n;return e=t,(i=[{key:"colorChanged",value:function(){var t=this;clearTimeout(this.colorChangeTimeout),this.colorChangeTimeout=setTimeout((function(){t.form.trigger("ew.save")}),500)}},{key:"enable",value:function(t){"text"===t?(this.metabox.fadeIn(200),this.fields.prop("disabled",!1)):(this.metabox.hide(),this.fields.prop("disabled",!0))}}])&&p(e.prototype,i),n&&p(e,n),t}();function y(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var b=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.metabox=r()("#preview"),this.body=r()("body"),this.form=r()("form#post"),this.watermarkTextField=this.form.find("input.watermark-text"),this.attachmentIdField=this.form.find("input.watermark-id"),this.link=this.metabox.find(".select-preview-image"),this.previewWrap=this.metabox.find(".preview-wrap"),this.contentWrap=this.metabox.find(".content-wrap"),this.imageSelector=this.metabox.find(".image-selector"),this.popup=this.metabox.find(".ew-preview-popup"),this.spinner=this.metabox.find("span.spinner"),this.image=r()(document.createElement("img")),this.popup.appendTo(this.body),this.openMediaLibrary=this.openMediaLibrary.bind(this),this.openPopup=this.openPopup.bind(this),this.closePopup=this.closePopup.bind(this),this.selectImage=this.selectImage.bind(this),this.imageSelected=this.imageSelected.bind(this),this.update=this.update.bind(this),this.hasImage=this.previewWrap.data("hasImage"),this.link.on("click",this.openMediaLibrary),this.form.on("ew.update",this.update),this.image.on("click",this.openPopup),this.popup.find(".media-modal-close, .media-modal-backdrop").on("click",this.closePopup),this.imageSelector.hide(),this.contentWrap.hide(),this.previewWrap.prepend(this.image),this.refreshPreview()}var e,i,n;return e=t,(i=[{key:"enable",value:function(){this.metabox.fadeIn(200)}},{key:"openMediaLibrary",value:function(t){t.preventDefault(),this.frame||this.createMediaFrame(),this.frame.open()}},{key:"createMediaFrame",value:function(){this.frame=wp.media.frames.previewImage=wp.media({title:this.link.data("choose"),library:{type:"image"},button:{text:this.link.data("buttonLabel"),close:!0}}),this.frame.on("select",this.selectImage)}},{key:"selectImage",value:function(){var t=this.frame.state().get("selection").first(),e=this.form.find("input[name=post_ID]").val();this.contentWrap.hide(),this.spinner.css("display","block"),r.a.ajax({type:"post",url:ajaxurl,data:{action:"easy-watermark/preview_image",attachment_id:t.id,watermark_id:e,nonce:ew.previewImageNonce}}).done(this.imageSelected).fail((function(){}))}},{key:"imageSelected",value:function(t){if(!0===t.success){if(this.link.html(this.link.data("changeLabel")),this.hasImage=!0,t.data.popup){var e=r()(t.data.popup);this.popup.find(".media-frame-content").replaceWith(e.find(".media-frame-content"))}this.refreshPreview()}}},{key:"refreshPreview",value:function(){var t=this;if(this.contentWrap.hide(),this.hasImage){this.imageSelector.hide(),this.spinner.css("display","block");var e=Object(o.c)(this.previewWrap.data("src"));this.popup.find("img").each((function(t,e){var i=r()(e),n=Object(o.c)(i.attr("src"));i.attr("src",n)})),this.image.one("load",(function(){t.spinner.hide(),t.contentWrap.fadeIn(200),t.imageSelector.fadeIn(200)})).attr("src",e)}else this.imageSelector.show()}},{key:"openPopup",value:function(){this.popup.show(),this.body.addClass("modal-open")}},{key:"closePopup",value:function(){this.popup.hide(),this.body.removeClass("modal-open")}},{key:"hasPreview",value:function(){var t=this.form.find("input.watermark-type:checked").val();return!("text"!==t||!this.watermarkTextField.val().length)||!("image"!==t||!this.attachmentIdField.val().length)}},{key:"update",value:function(){this.refreshPreview()}}])&&y(e.prototype,i),n&&y(e,n),t}(),v=i(4),g=i.n(v);function w(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var k=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.metabox=r()("#placeholders"),this.placeholders=this.metabox.find(".placeholders-list li"),this.searchField=this.metabox.find("input.ew-search-placeholders"),this.clipboard=new g.a(".placeholders-list code"),this.clipboardSuccess=this.clipboardSuccess.bind(this),this.filterPlaceholders=this.filterPlaceholders.bind(this),this.clipboard.on("success",this.clipboardSuccess),this.searchField.on("keyup",this.filterPlaceholders)}var e,i,n;return e=t,(i=[{key:"enable",value:function(t){"text"===t?this.metabox.fadeIn(200):this.metabox.hide()}},{key:"clipboardSuccess",value:function(t){var e=r()(t.trigger);e.text("Copied"),setTimeout((function(){e.text(t.text)}),1e3)}},{key:"filterPlaceholders",value:function(t){var e=r()(t.target).val();this.placeholders.hide().each((function(t,i){var n=r()(i);-1!==n.find("code").text().toLowerCase().indexOf(e)&&n.show()}))}}])&&w(e.prototype,i),n&&w(e,n),t}();function x(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var S=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.fields=r()(".form-field"),this.buttons=this.fields.find("button[data-toggle=dropdown]"),this.dropdowns=this.fields.find(".dropdown-menu[data-target]"),this.links=this.dropdowns.find("a"),this.init()}var e,i,n;return e=t,(i=[{key:"init",value:function(){this.toggleDropdown=this.toggleDropdown.bind(this),this.dropdownSelect=this.dropdownSelect.bind(this),this.hideDropdowns=this.hideDropdowns.bind(this),this.buttons.on("click",this.toggleDropdown),this.links.on("click",this.dropdownSelect),r()(document).on("click",this.hideDropdowns)}},{key:"toggleDropdown",value:function(t){t.preventDefault();var e=r()(t.target),i=e.position();e.toggleClass("is-open"),e.next(".dropdown-menu").css({left:i.left,top:i.top+e.height()}).toggle()}},{key:"dropdownSelect",value:function(t){t.preventDefault();var e=r()(t.target),i=e.closest(".dropdown-menu"),n=r()(i.data("target"));n.length&&(n.val(e.data("value")),i.prev("button[data-toggle=dropdown]").text(e.text()))}},{key:"hideDropdowns",value:function(t){r()(t.target).is(this.buttons)||(this.buttons.removeClass("is-open"),this.dropdowns.hide())}}])&&x(e.prototype,i),n&&x(e,n),t}();function T(t,e){var i;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(i=function(t,e){if(!t)return;if("string"==typeof t)return E(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);"Object"===i&&t.constructor&&(i=t.constructor.name);if("Map"===i||"Set"===i)return Array.from(t);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return E(t,e)}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0,r=function(){};return{s:r,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){i=t[Symbol.iterator]()},n:function(){var t=i.next();return a=t.done,t},e:function(t){s=!0,o=t},f:function(){try{a||null==i.return||i.return()}finally{if(s)throw o}}}}function E(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function C(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var O=function(){function t(){var e=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.selectWatermarkType=this.selectWatermarkType.bind(this),this.triggerSave=this.triggerSave.bind(this),this.form=r()("form#post"),this.selector=this.form.find("input.watermark-type"),this.metaboxes=[new s,new l,new h,new d,new m,new b,new k],new S;var i=this.selector.filter("[checked]");i.length&&this.selectWatermarkType(i[0].value),this.selector.on("change",(function(t){e.selectWatermarkType(t.target.value)})),this.form.on("change","input, select",this.triggerSave).on("ew.save",this.triggerSave)}var e,i,n;return e=t,(i=[{key:"selectWatermarkType",value:function(t){var e,i=T(this.metaboxes);try{for(i.s();!(e=i.n()).done;)e.value.enable(t)}catch(t){i.e(t)}finally{i.f()}}},{key:"triggerSave",value:function(){var t=this,e={action:"easy-watermark/autosave",nonce:ew.autosaveNonce},i=this.form.find("[name^=watermark], [name=post_ID]").serialize();for(var n in e)i+="&"+encodeURIComponent(n)+"="+encodeURIComponent(e[n]);r.a.ajax({type:"post",url:ajaxurl,data:i}).done((function(e){!0===e.success&&t.form.trigger("ew.update")})).fail((function(){}))}}])&&C(e.prototype,i),n&&C(e,n),t}();r()(document).ready((function(){return new O}))},32:function(t,e){},4:function(t,e,i){
2
  /*!
3
  * clipboard.js v2.0.6
4
  * https://clipboardjs.com/
assets/dist/styles/watermark-edit.css CHANGED
@@ -1 +1 @@
1
- body.post-type-watermark .actions.bulkactions,body.settings_page_easy-watermark .actions.bulkactions{padding-right:0 !important}body.post-type-watermark .actions.bulkactions .button,body.settings_page_easy-watermark .actions.bulkactions .button{margin-right:16px !important}body.post-type-watermark .form-field,body.settings_page_easy-watermark .form-field{display:flex;justify-content:flex-start;margin-bottom:20px}body.post-type-watermark .form-field:last-child,body.settings_page_easy-watermark .form-field:last-child{margin-bottom:0}body.post-type-watermark .form-field input,body.settings_page_easy-watermark .form-field input{margin:0;position:relative}body.post-type-watermark .form-field input[type="number"],body.settings_page_easy-watermark .form-field input[type="number"]{width:70px}body.post-type-watermark .form-field input:focus,body.settings_page_easy-watermark .form-field input:focus{z-index:2}body.post-type-watermark .form-field-prepend,body.post-type-watermark .form-field-append,body.settings_page_easy-watermark .form-field-prepend,body.settings_page_easy-watermark .form-field-append{display:flex;position:relative}body.post-type-watermark .form-field-text,body.post-type-watermark .form-field button,body.settings_page_easy-watermark .form-field-text,body.settings_page_easy-watermark .form-field button{align-items:center;background-color:#eee;border:1px solid #ddd;border-radius:3px;display:flex;padding:0 5px;position:relative;z-index:1}body.post-type-watermark .form-field-prepend .form-field-text,body.post-type-watermark .form-field-prepend button,body.post-type-watermark .form-field-prepend .dropdown-menu,body.settings_page_easy-watermark .form-field-prepend .form-field-text,body.settings_page_easy-watermark .form-field-prepend button,body.settings_page_easy-watermark .form-field-prepend .dropdown-menu{border-bottom-right-radius:0;border-top-right-radius:0;margin-right:-1px}body.post-type-watermark .form-field-append .form-field-text,body.post-type-watermark .form-field-append button,body.post-type-watermark .form-field-append .dropdown-menu,body.settings_page_easy-watermark .form-field-append .form-field-text,body.settings_page_easy-watermark .form-field-append button,body.settings_page_easy-watermark .form-field-append .dropdown-menu{border-bottom-left-radius:0;border-top-left-radius:0;margin-left:-1px}body.post-type-watermark .form-field button:hover,body.settings_page_easy-watermark .form-field button:hover{background-color:#ddd;border:1px solid #aaa;cursor:pointer}body.post-type-watermark .form-field button[data-toggle="dropdown"]::after,body.settings_page_easy-watermark .form-field button[data-toggle="dropdown"]::after{border:4px solid transparent;border-top:4px solid #777;content:"";height:0;margin-bottom:-4px;margin-left:10px;width:0}body.post-type-watermark .form-field .dropdown-menu,body.settings_page_easy-watermark .form-field .dropdown-menu{background:#fff;border:1px solid #aaa;border-radius:3px;display:none;margin-top:3px;min-width:calc(100% - 2px);overflow:hidden;position:absolute;z-index:99}body.post-type-watermark .form-field .dropdown-menu .dropdown-item,body.settings_page_easy-watermark .form-field .dropdown-menu .dropdown-item{color:#333;display:block;padding:3px 6px;text-decoration:none}body.post-type-watermark .form-field .dropdown-menu .dropdown-item:hover,body.settings_page_easy-watermark .form-field .dropdown-menu .dropdown-item:hover{background-color:#eee}body.post-type-watermark #poststuff .watermark-type-selector h2{padding-left:0}body.post-type-watermark #poststuff .watermark-type-selector .buttons{display:flex}body.post-type-watermark #poststuff .watermark-type-selector .button.first{border-bottom-right-radius:0;border-top-right-radius:0}body.post-type-watermark #poststuff .watermark-type-selector .button.last{border-bottom-left-radius:0;border-top-left-radius:0}body.post-type-watermark #poststuff .watermark-type-selector input[type="radio"]{opacity:0;position:absolute;z-index:-1}body.post-type-watermark #poststuff .watermark-type-selector input[type="radio"]:checked+.button{background:#0085ba;border-color:#0073aa #006799 #006799;box-shadow:0 1px 0 #006799;color:#fff;text-decoration:none;text-shadow:0 -1px 1px #006799, 1px 0 1px #006799, 0 1px 1px #006799, -1px 0 1px #006799}body.post-type-watermark #poststuff .watermark-type-selector input[type="radio"]:checked+.button:active{transform:none}#watermark-content .image-content,#watermark-content .text-content,#watermark-content .select-image-button,#watermark-content .watermark-image{display:none}#watermark-content .watermark-image img{background-color:#ddd;cursor:pointer;height:auto;max-width:100%;width:auto}#watermark-content .text-content{overflow:hidden}#watermark-content .text-content input{width:100%}#watermark-content .text-preview{float:left;background-color:#ddd;background-image:linear-gradient(45deg, #999 25%, transparent 25%, transparent 75%, #999 75%, #999),linear-gradient(45deg, #999 25%, transparent 25%, transparent 75%, #999 75%, #999);background-position:0 0,6px 6px;background-size:12px 12px}#watermark-content .text-preview img{display:block;height:auto;max-width:100%}#alignment .alignment-selector{background-image:url(../images/alignment-background.jpg);background-size:cover;display:flex;flex-wrap:wrap;justify-content:space-between;width:240px}#alignment .alignment-selector label{background-repeat:no-repeat;display:block;float:left;height:58px;margin-bottom:3px;position:relative;text-align:center;width:78px}#alignment .alignment-selector label:nth-last-child(-n+6){margin-bottom:0}#alignment .alignment-selector label::after{background-color:rgba(255,255,255,0.2);bottom:0;content:"";left:0;position:absolute;right:0;top:0;transition:all 0.2s}#alignment .alignment-selector label:hover::after{background-color:rgba(255,255,255,0.35)}#alignment .alignment-selector input{opacity:0;position:absolute;z-index:-1}#alignment .alignment-selector input:checked+label::after{background-color:transparent}#watermarks table{margin-bottom:10px;text-align:left}#watermarks table td{padding:5px 10px}#watermarks table th{padding:5px 10px 5px 0}#watermarks .button-wrap{margin-bottom:10px}#watermarks .button-wrap:last-child{margin-bottom:0}#watermarks .button-wrap::after{clear:both;content:"";display:block}#watermarks .button-wrap button,#watermarks .button-wrap .spinner{float:left}#watermarks .error-message{display:none}#watermarks p.description{margin-top:20px}#watermarks .removed-watermarks{list-style:initial;margin:0;padding-left:30px}.ew-preview-popup{display:none}.ew-preview-popup .media-frame-content{bottom:0;padding:16px;top:50px}.ew-preview-popup .media-frame-content img{display:block;height:auto;margin-bottom:16px;max-width:100%}#preview img{cursor:pointer;height:auto;max-width:100%}#preview .spinner{display:none;float:none;margin:10px 0 0;visibility:visible}#placeholders li{margin-bottom:20px}#placeholders li>label{display:block;font-weight:700;margin-bottom:5px;width:calc(100% - 30px)}#placeholders code{cursor:pointer;width:calc(100% - 30px)}#placeholders .ew-search-placeholders{margin:13px 0 7px}#placeholders .help{float:right;position:relative;top:10px}#placeholders .help .question-mark{background-color:#888;border-radius:50%;color:#fff;cursor:pointer;display:block;height:20px;line-height:20px;text-align:center;width:20px}#placeholders .help .description{background-color:#fff;border:1px solid #eee;box-shadow:0 0 8px rgba(0,0,0,0.3);display:none;font-size:12px;min-width:200px;opacity:0;position:absolute;right:0;top:32px;transition:opacity 0.2s;z-index:1}#placeholders .help .description::before,#placeholders .help .description::after{border-color:rgba(229,229,229,0);border-style:solid;bottom:100%;content:"";height:0;pointer-events:none;position:absolute;right:0;width:0;z-index:18}#placeholders .help .description::before{border-bottom-color:#eee;border-width:11px;margin-left:-11px}#placeholders .help .description::after{border-bottom-color:#fff;border-width:9px;margin-left:-9px;margin-right:2px}#placeholders .help .description label{display:block;font-weight:700}#placeholders .help .description span,#placeholders .help .description i{display:block}#placeholders .help .description-content{padding:10px}#placeholders .help:hover .description{display:block;opacity:1}
1
+ body.post-type-watermark .actions.bulkactions,body.settings_page_easy-watermark .actions.bulkactions{padding-right:0 !important}body.post-type-watermark .actions.bulkactions .button,body.settings_page_easy-watermark .actions.bulkactions .button{margin-right:16px !important}body.post-type-watermark .form-field,body.settings_page_easy-watermark .form-field{display:flex;justify-content:flex-start;margin-bottom:20px}body.post-type-watermark .form-field:last-child,body.settings_page_easy-watermark .form-field:last-child{margin-bottom:0}body.post-type-watermark .form-field input,body.settings_page_easy-watermark .form-field input{margin:0;position:relative}body.post-type-watermark .form-field input[type="number"],body.settings_page_easy-watermark .form-field input[type="number"]{width:70px}body.post-type-watermark .form-field input:focus,body.settings_page_easy-watermark .form-field input:focus{z-index:2}body.post-type-watermark .form-field-prepend,body.post-type-watermark .form-field-append,body.settings_page_easy-watermark .form-field-prepend,body.settings_page_easy-watermark .form-field-append{display:flex;position:relative}body.post-type-watermark .form-field-text,body.post-type-watermark .form-field button,body.settings_page_easy-watermark .form-field-text,body.settings_page_easy-watermark .form-field button{align-items:center;background-color:#eee;border:1px solid #ddd;border-radius:3px;display:flex;padding:0 8px;position:relative;z-index:1}body.post-type-watermark .form-field-prepend .form-field-text,body.post-type-watermark .form-field-prepend button,body.post-type-watermark .form-field-prepend .dropdown-menu,body.settings_page_easy-watermark .form-field-prepend .form-field-text,body.settings_page_easy-watermark .form-field-prepend button,body.settings_page_easy-watermark .form-field-prepend .dropdown-menu{border-bottom-right-radius:0;border-top-right-radius:0;margin-right:-1px}body.post-type-watermark .form-field-append .form-field-text,body.post-type-watermark .form-field-append button,body.post-type-watermark .form-field-append .dropdown-menu,body.settings_page_easy-watermark .form-field-append .form-field-text,body.settings_page_easy-watermark .form-field-append button,body.settings_page_easy-watermark .form-field-append .dropdown-menu{border-bottom-left-radius:0;border-top-left-radius:0;margin-left:-1px}body.post-type-watermark .form-field button:hover,body.settings_page_easy-watermark .form-field button:hover{background-color:#ddd;border:1px solid #aaa;cursor:pointer}body.post-type-watermark .form-field button[data-toggle="dropdown"]::after,body.settings_page_easy-watermark .form-field button[data-toggle="dropdown"]::after{border:4px solid transparent;border-top:4px solid #777;content:"";height:0;margin-bottom:-4px;margin-left:10px;width:0}body.post-type-watermark .form-field .dropdown-menu,body.settings_page_easy-watermark .form-field .dropdown-menu{background:#fff;border:1px solid #aaa;border-radius:3px;display:none;margin-top:3px;min-width:calc(100% - 2px);overflow:hidden;position:absolute;z-index:99}body.post-type-watermark .form-field .dropdown-menu .dropdown-item,body.settings_page_easy-watermark .form-field .dropdown-menu .dropdown-item{color:#333;display:block;padding:3px 6px;text-decoration:none}body.post-type-watermark .form-field .dropdown-menu .dropdown-item:hover,body.settings_page_easy-watermark .form-field .dropdown-menu .dropdown-item:hover{background-color:#eee}body.ew-new-form-style .form-field input:not(:last-child){border-bottom-right-radius:0;border-top-right-radius:0}body.ew-new-form-style .form-field .dropdown-menu{border:1px solid #7e8993;border-radius:4px;color:#007cba}body.ew-new-form-style .form-field .dropdown-menu .dropdown-item:hover{background-color:#0078d7;color:#fff}body.ew-new-form-style .form-field-text,body.ew-new-form-style .form-field button{background-color:#f0f2f3;border:1px solid #7e8993;color:#32373c}body.ew-new-form-style .form-field-prepend+input{border-bottom-left-radius:0;border-top-left-radius:0}body.ew-new-form-style .form-field-prepend .form-field-text,body.ew-new-form-style .form-field-prepend button{border-radius:4px 0 0 4px;border-right:0 !important;margin-right:0}body.ew-new-form-style .form-field-append .form-field-text,body.ew-new-form-style .form-field-append button{border-left:0 !important;border-radius:0 4px 4px 0;margin-left:0}body.ew-new-form-style .form-field button{background:#f0f2f3 url(data:image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2220%22%20height%3D%2220%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M5%206l5%205%205-5%202%201-7%207-7-7%202-1z%22%20fill%3D%22%23555%22%2F%3E%3C%2Fsvg%3E) no-repeat right 5px top 55%;background-size:16px 16px;cursor:pointer;padding-right:24px}body.ew-new-form-style .form-field button::after{display:none}body.ew-new-form-style .form-field button:focus,body.ew-new-form-style .form-field button:active{box-shadow:0 0 0 1px #007cba;outline:none}body.ew-new-form-style .form-field button.is-open,body.ew-new-form-style .form-field button:hover{background-color:#fff;border:1px solid #7e8993;color:#007cba}body.ew-new-form-style .form-field button[data-toggle="dropdown"]::after{border-top:4px solid #7e8993}body.post-type-watermark #poststuff .watermark-type-selector h2{padding-left:0}body.post-type-watermark #poststuff .watermark-type-selector .buttons{display:flex}body.post-type-watermark #poststuff .watermark-type-selector .button.first{border-bottom-right-radius:0;border-top-right-radius:0}body.post-type-watermark #poststuff .watermark-type-selector .button.last{border-bottom-left-radius:0;border-top-left-radius:0}body.post-type-watermark #poststuff .watermark-type-selector input[type="radio"]{opacity:0;position:absolute;z-index:-1}body.post-type-watermark #poststuff .watermark-type-selector input[type="radio"]:checked+.button{background:#0085ba;border-color:#0073aa #006799 #006799;box-shadow:0 1px 0 #006799;color:#fff;text-decoration:none;text-shadow:0 -1px 1px #006799, 1px 0 1px #006799, 0 1px 1px #006799, -1px 0 1px #006799}body.post-type-watermark #poststuff .watermark-type-selector input[type="radio"]:checked+.button:active{transform:none}#watermark-content .image-content,#watermark-content .text-content,#watermark-content .select-image-button,#watermark-content .watermark-image{display:none}#watermark-content .watermark-image img{background-color:#ddd;cursor:pointer;height:auto;max-width:100%;width:auto}#watermark-content .text-content{overflow:hidden}#watermark-content .text-content input{width:100%}#watermark-content .text-preview{float:left;background-color:#ddd;background-image:linear-gradient(45deg, #999 25%, transparent 25%, transparent 75%, #999 75%, #999),linear-gradient(45deg, #999 25%, transparent 25%, transparent 75%, #999 75%, #999);background-position:0 0,6px 6px;background-size:12px 12px}#watermark-content .text-preview img{display:block;height:auto;max-width:100%}#alignment .alignment-selector{background-image:url(../images/alignment-background.jpg);background-size:cover;display:flex;flex-wrap:wrap;justify-content:space-between;width:240px}#alignment .alignment-selector label{background-repeat:no-repeat;display:block;float:left;height:58px;margin-bottom:3px;position:relative;text-align:center;width:78px}#alignment .alignment-selector label:nth-last-child(-n+6){margin-bottom:0}#alignment .alignment-selector label::after{background-color:rgba(255,255,255,0.2);bottom:0;content:"";left:0;position:absolute;right:0;top:0;transition:all 0.2s}#alignment .alignment-selector label:hover::after{background-color:rgba(255,255,255,0.35)}#alignment .alignment-selector input{opacity:0;position:absolute;z-index:-1}#alignment .alignment-selector input:checked+label::after{background-color:transparent}#watermarks table{margin-bottom:10px;text-align:left}#watermarks table td{padding:5px 10px}#watermarks table th{padding:5px 10px 5px 0}#watermarks .button-wrap{margin-bottom:10px}#watermarks .button-wrap:last-child{margin-bottom:0}#watermarks .button-wrap::after{clear:both;content:"";display:block}#watermarks .button-wrap button,#watermarks .button-wrap .spinner{float:left}#watermarks .error-message{display:none}#watermarks p.description{margin-top:20px}#watermarks .removed-watermarks{list-style:initial;margin:0;padding-left:30px}.ew-preview-popup{display:none}.ew-preview-popup .media-frame-content{bottom:0;padding:16px;top:50px}.ew-preview-popup .media-frame-content img{display:block;height:auto;margin-bottom:16px;max-width:100%}#preview img{cursor:pointer;height:auto;max-width:100%}#preview .spinner{display:none;float:none;margin:10px 0 0;visibility:visible}#placeholders li{margin-bottom:20px}#placeholders li>label{display:block;font-weight:700;margin-bottom:5px;width:calc(100% - 30px)}#placeholders code{cursor:pointer;width:calc(100% - 30px)}#placeholders .ew-search-placeholders{margin:13px 0 7px}#placeholders .help{float:right;position:relative;top:10px}#placeholders .help .question-mark{background-color:#888;border-radius:50%;color:#fff;cursor:pointer;display:block;height:20px;line-height:20px;text-align:center;width:20px}#placeholders .help .description{background-color:#fff;border:1px solid #eee;box-shadow:0 0 8px rgba(0,0,0,0.3);display:none;font-size:12px;min-width:200px;opacity:0;position:absolute;right:0;top:32px;transition:opacity 0.2s;z-index:1}#placeholders .help .description::before,#placeholders .help .description::after{border-color:rgba(229,229,229,0);border-style:solid;bottom:100%;content:"";height:0;pointer-events:none;position:absolute;right:0;width:0;z-index:18}#placeholders .help .description::before{border-bottom-color:#eee;border-width:11px;margin-left:-11px}#placeholders .help .description::after{border-bottom-color:#fff;border-width:9px;margin-left:-9px;margin-right:2px}#placeholders .help .description label{display:block;font-weight:700}#placeholders .help .description span,#placeholders .help .description i{display:block}#placeholders .help .description-content{padding:10px}#placeholders .help:hover .description{display:block;opacity:1}
assets/src/scripts/controllers/bulk-actions.js CHANGED
@@ -1,322 +1,322 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
- import { Model, Collection } from 'backbone';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- import WatermarkSelector from '../views/media-list/watermark-selector';
11
- import Status from '../views/media-list/status';
12
- import Attachment from '../views/media-list/attachment';
13
-
14
- import {
15
- addNotice,
16
- imageVersion,
17
- filterSelection,
18
- } from '../utils/functions.js';
19
-
20
- /* global ew, ajaxurl */
21
-
22
- class BulkActions extends Model {
23
- constructor() {
24
- super();
25
-
26
- this.bulkActionsSelectors = $( 'select#bulk-action-selector-top, select#bulk-action-selector-bottom' );
27
-
28
- if ( this.bulkActionsSelectors.length ) {
29
- this.init();
30
- }
31
- }
32
-
33
- init() {
34
- this.selectBulkAction = this.selectBulkAction.bind( this );
35
- this.doAction = this.doAction.bind( this );
36
-
37
- this.form = $( 'form#posts-filter' );
38
- this.actionButtons = this.form.find( '#doaction, #doaction2' );
39
-
40
- this.bulkActionsSelectors.each( ( n, item ) => {
41
- const select = $( item );
42
-
43
- new WatermarkSelector( {
44
- controller: this,
45
- bulkActionSelector: select,
46
- } ).render();
47
-
48
- new Status( {
49
- controller: this,
50
- bulkActionSelector: select,
51
- } ).render();
52
- } ).val( -1 ).on( 'change', this.selectBulkAction );
53
-
54
- this.set( {
55
- attachments: new Collection,
56
- selection: new Collection,
57
- } );
58
-
59
- this.actionButtons.on( 'click', this.doAction );
60
-
61
- this.on( 'bulkAction:start', () => {
62
- this.bulkActionsSelectors.val( -1 ).prop( 'disabled', true );
63
- this.actionButtons.prop( 'disabled', true );
64
- } );
65
-
66
- this.on( 'bulkAction:finished', () => {
67
- this.bulkActionsSelectors.prop( 'disabled', false );
68
- this.actionButtons.prop( 'disabled', false );
69
- } );
70
- }
71
-
72
- selectBulkAction( e ) {
73
- const select = $( e.target );
74
-
75
- this.set( {
76
- select,
77
- action: select.val(),
78
- } );
79
- }
80
-
81
- doAction( e ) {
82
- const action = this.get( 'action' );
83
-
84
- if ( ! this.checkAction( action ) ) {
85
- return;
86
- }
87
-
88
- e.preventDefault();
89
-
90
- const watermark = this.get( 'watermark' );
91
-
92
- if ( 'watermark' === action && ! watermark ) {
93
- return;
94
- }
95
-
96
- const checkedItems = this.form.find( 'input[name="media[]"]:checked' );
97
-
98
- if ( ! checkedItems.length ) {
99
- this.status().set( { text: ew.i18n.noItemsSelected } );
100
- return;
101
- }
102
-
103
- const
104
- attachments = this.get( 'attachments' ),
105
- selection = this.get( 'selection' ),
106
- attachmentIds = [];
107
-
108
- this.trigger( 'bulkAction:start' );
109
-
110
- checkedItems.each( ( n, checkbox ) => {
111
- const
112
- id = $( checkbox ).val(),
113
- model = attachments.get( id );
114
-
115
- if ( model ) {
116
- selection.add( model );
117
- } else {
118
- attachmentIds.push( id );
119
- }
120
- } );
121
-
122
- if ( ! attachmentIds.length ) {
123
- if ( selection.length ) {
124
- this.prepare();
125
- }
126
-
127
- return;
128
- }
129
-
130
- this.status().set( {
131
- text: '<span class="spinner ew-spinner"></span>',
132
- } );
133
-
134
- $.ajax( ajaxurl, { data: {
135
- action: 'easy-watermark/attachments-info',
136
- nonce: ew.attachmentsInfoNonce,
137
- attachments: attachmentIds,
138
- } } ).done( ( response ) => {
139
- if ( true === response.success ) {
140
- for ( const item of response.data ) {
141
- const model = new Model( item );
142
-
143
- attachments.push( model );
144
- selection.push( model );
145
-
146
- new Attachment( {
147
- el: `#post-${ item.id }`,
148
- controller: this,
149
- model,
150
- } );
151
- }
152
-
153
- this.prepare();
154
- } else {
155
- const error = response.data.message ? response.data.message : ew.i18n.genericErrorMessage;
156
- this.actionError( error );
157
- }
158
- } ).fail( () => {
159
- this.actionError( ew.i18n.genericErrorMessage );
160
- } );
161
- }
162
-
163
- prepare() {
164
- const
165
- action = this.get( 'action' ),
166
- selection = this.get( 'selection' ),
167
- backup = ( 'restore' === action ),
168
- statusText = 'watermark' === action ? ew.i18n.watermarkingStatus : ew.i18n.restoringStatus,
169
- successMessage = 'watermark' === action ? ew.i18n.watermarkingSuccessMessage : ew.i18n.restoringSuccessMessage;
170
-
171
- filterSelection( selection, backup );
172
-
173
- if ( ! selection.length ) {
174
- this.status().set( {
175
- successMessage: 'watermark' === action ? ew.i18n.watermarkingNoItems : ew.i18n.restoringNoItems,
176
- } );
177
-
178
- this.actionDone();
179
- return;
180
- }
181
-
182
- this.status().set( {
183
- successMessage,
184
- text: statusText,
185
- processing: true,
186
- total: selection.length,
187
- processed: 0,
188
- } );
189
-
190
- for ( const model of selection.models ) {
191
- model.trigger( 'processing:start' );
192
- }
193
-
194
- this.doActionRecursive();
195
- }
196
-
197
- doActionRecursive() {
198
- const
199
- bulkAction = this.get( 'action' ),
200
- watermark = this.get( 'watermark' );
201
-
202
- let
203
- action = 'easy-watermark/',
204
- nonce;
205
-
206
- if ( 'watermark' === bulkAction ) {
207
- action += ( ( 'all' === watermark ) ? 'apply_all' : 'apply_single' );
208
- nonce = ( 'all' === watermark ) ? ew.applyAllNonce : ew.applySingleNonces[ watermark ];
209
- } else if ( 'restore' === bulkAction ) {
210
- action += 'restore_backup';
211
- nonce = ew.restoreBackupNonce;
212
- } else {
213
- return;
214
- }
215
-
216
- const
217
- status = this.status(),
218
- selection = this.get( 'selection' ),
219
- model = selection.shift(),
220
- data = { action, nonce, watermark };
221
-
222
- let processed = status.get( 'processed' );
223
-
224
- data.attachment_id = model.get( 'id' );
225
-
226
- this.set( 'currentAttachmentID', data.attachment_id );
227
-
228
- $.ajax( ajaxurl, {
229
- data,
230
- } ).done( ( response ) => {
231
- if ( true === response.success ) {
232
- if ( response.data.attachmentVersion ) {
233
- const img = this.form.find( 'tr#post-' + data.attachment_id + ' img' ),
234
- src = imageVersion( img.attr( 'src' ), response.data.attachmentVersion );
235
-
236
- img.attr( { src, srcset: '' } );
237
- }
238
-
239
- processed++;
240
- status.set( { processed } );
241
-
242
- model.set( 'hasBackup', response.data.hasBackup ? true : false );
243
- model.trigger( 'processing:done' );
244
-
245
- if ( selection.length ) {
246
- this.doActionRecursive();
247
- } else {
248
- this.actionDone();
249
- }
250
- } else {
251
- const error = ( 'string' === typeof response.data.message ) ? response.data.message : ew.i18n.genericErrorMessage;
252
- this.actionError( error );
253
- }
254
- } ).fail( () => {
255
- this.actionError( ew.i18n.genericErrorMessage );
256
- } );
257
- }
258
-
259
- actionError( error ) {
260
- this.status().set( { error } );
261
- this.actionDone();
262
- }
263
-
264
- actionDone() {
265
- this.trigger( 'bulkAction:finished' );
266
-
267
- this.bulkActionsSelectors.prop( 'disabled', false );
268
-
269
- const
270
- status = this.status(),
271
- processed = status.get( 'processed' ),
272
- error = status.get( 'error' ),
273
- successMessage = status.get( 'successMessage' ),
274
- currentID = this.get( 'currentAttachmentID' );
275
-
276
- if ( processed > 0 ) {
277
- addNotice( successMessage.replace( '{procesed}', processed ), 'success' );
278
- } else {
279
- addNotice( successMessage, 'info' );
280
- }
281
-
282
- if ( error ) {
283
- const
284
- row = this.form.find( 'tr#post-' + currentID ),
285
- imageTitle = row.find( '.column-title a' ).attr( 'aria-label' );
286
-
287
- const errorMessage = ew.i18n.bulkActionErrorMessage
288
- .replace( '{imageTitle}', imageTitle )
289
- .replace( '{error}', error );
290
- addNotice( errorMessage, 'error' );
291
- }
292
-
293
- this.status().set( {
294
- processing: false,
295
- processed: 0,
296
- total: 0,
297
- text: '',
298
- } );
299
- }
300
-
301
- status() {
302
- let status = this.get( 'status' );
303
-
304
- if ( undefined === status ) {
305
- status = new Model;
306
- status.set( {
307
- processed: 0,
308
- total: 0,
309
- } );
310
-
311
- this.set( { status } );
312
- }
313
-
314
- return status;
315
- }
316
-
317
- checkAction( action ) {
318
- return [ 'watermark', 'restore' ].includes( action );
319
- }
320
- }
321
-
322
- $( document ).ready( () => new BulkActions );
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import $ from 'jquery';
5
+ import { Model, Collection } from 'backbone';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import WatermarkSelector from '../views/media-list/watermark-selector';
11
+ import Status from '../views/media-list/status';
12
+ import Attachment from '../views/media-list/attachment';
13
+
14
+ import {
15
+ addNotice,
16
+ imageVersion,
17
+ filterSelection,
18
+ } from '../utils/functions.js';
19
+
20
+ /* global ew, ajaxurl */
21
+
22
+ class BulkActions extends Model {
23
+ constructor() {
24
+ super();
25
+
26
+ this.bulkActionsSelectors = $( 'select#bulk-action-selector-top, select#bulk-action-selector-bottom' );
27
+
28
+ if ( this.bulkActionsSelectors.length ) {
29
+ this.init();
30
+ }
31
+ }
32
+
33
+ init() {
34
+ this.selectBulkAction = this.selectBulkAction.bind( this );
35
+ this.doAction = this.doAction.bind( this );
36
+
37
+ this.form = $( 'form#posts-filter' );
38
+ this.actionButtons = this.form.find( '#doaction, #doaction2' );
39
+
40
+ this.bulkActionsSelectors.each( ( n, item ) => {
41
+ const select = $( item );
42
+
43
+ new WatermarkSelector( {
44
+ controller: this,
45
+ bulkActionSelector: select,
46
+ } ).render();
47
+
48
+ new Status( {
49
+ controller: this,
50
+ bulkActionSelector: select,
51
+ } ).render();
52
+ } ).val( -1 ).on( 'change', this.selectBulkAction );
53
+
54
+ this.set( {
55
+ attachments: new Collection,
56
+ selection: new Collection,
57
+ } );
58
+
59
+ this.actionButtons.on( 'click', this.doAction );
60
+
61
+ this.on( 'bulkAction:start', () => {
62
+ this.bulkActionsSelectors.val( -1 ).prop( 'disabled', true );
63
+ this.actionButtons.prop( 'disabled', true );
64
+ } );
65
+
66
+ this.on( 'bulkAction:finished', () => {
67
+ this.bulkActionsSelectors.prop( 'disabled', false );
68
+ this.actionButtons.prop( 'disabled', false );
69
+ } );
70
+ }
71
+
72
+ selectBulkAction( e ) {
73
+ const select = $( e.target );
74
+
75
+ this.set( {
76
+ select,
77
+ action: select.val(),
78
+ } );
79
+ }
80
+
81
+ doAction( e ) {
82
+ const action = this.get( 'action' );
83
+
84
+ if ( ! this.checkAction( action ) ) {
85
+ return;
86
+ }
87
+
88
+ e.preventDefault();
89
+
90
+ const watermark = this.get( 'watermark' );
91
+
92
+ if ( 'watermark' === action && ! watermark ) {
93
+ return;
94
+ }
95
+
96
+ const checkedItems = this.form.find( 'input[name="media[]"]:checked' );
97
+
98
+ if ( ! checkedItems.length ) {
99
+ this.status().set( { text: ew.i18n.noItemsSelected } );
100
+ return;
101
+ }
102
+
103
+ const
104
+ attachments = this.get( 'attachments' ),
105
+ selection = this.get( 'selection' ),
106
+ attachmentIds = [];
107
+
108
+ this.trigger( 'bulkAction:start' );
109
+
110
+ checkedItems.each( ( n, checkbox ) => {
111
+ const
112
+ id = $( checkbox ).val(),
113
+ model = attachments.get( id );
114
+
115
+ if ( model ) {
116
+ selection.add( model );
117
+ } else {
118
+ attachmentIds.push( id );
119
+ }
120
+ } );
121
+
122
+ if ( ! attachmentIds.length ) {
123
+ if ( selection.length ) {
124
+ this.prepare();
125
+ }
126
+
127
+ return;
128
+ }
129
+
130
+ this.status().set( {
131
+ text: '<span class="spinner ew-spinner"></span>',
132
+ } );
133
+
134
+ $.ajax( ajaxurl, { data: {
135
+ action: 'easy-watermark/attachments-info',
136
+ nonce: ew.attachmentsInfoNonce,
137
+ attachments: attachmentIds,
138
+ } } ).done( ( response ) => {
139
+ if ( true === response.success ) {
140
+ for ( const item of response.data ) {
141
+ const model = new Model( item );
142
+
143
+ attachments.push( model );
144
+ selection.push( model );
145
+
146
+ new Attachment( {
147
+ el: `#post-${ item.id }`,
148
+ controller: this,
149
+ model,
150
+ } );
151
+ }
152
+
153
+ this.prepare();
154
+ } else {
155
+ const error = response.data.message ? response.data.message : ew.i18n.genericErrorMessage;
156
+ this.actionError( error );
157
+ }
158
+ } ).fail( () => {
159
+ this.actionError( ew.i18n.genericErrorMessage );
160
+ } );
161
+ }
162
+
163
+ prepare() {
164
+ const
165
+ action = this.get( 'action' ),
166
+ selection = this.get( 'selection' ),
167
+ backup = ( 'restore' === action ),
168
+ statusText = 'watermark' === action ? ew.i18n.watermarkingStatus : ew.i18n.restoringStatus,
169
+ successMessage = 'watermark' === action ? ew.i18n.watermarkingSuccessMessage : ew.i18n.restoringSuccessMessage;
170
+
171
+ filterSelection( selection, backup );
172
+
173
+ if ( ! selection.length ) {
174
+ this.status().set( {
175
+ successMessage: 'watermark' === action ? ew.i18n.watermarkingNoItems : ew.i18n.restoringNoItems,
176
+ } );
177
+
178
+ this.actionDone();
179
+ return;
180
+ }
181
+
182
+ this.status().set( {
183
+ successMessage,
184
+ text: statusText,
185
+ processing: true,
186
+ total: selection.length,
187
+ processed: 0,
188
+ } );
189
+
190
+ for ( const model of selection.models ) {
191
+ model.trigger( 'processing:start' );
192
+ }
193
+
194
+ this.doActionRecursive();
195
+ }
196
+
197
+ doActionRecursive() {
198
+ const
199
+ bulkAction = this.get( 'action' ),
200
+ watermark = this.get( 'watermark' );
201
+
202
+ let
203
+ action = 'easy-watermark/',
204
+ nonce;
205
+
206
+ if ( 'watermark' === bulkAction ) {
207
+ action += ( ( 'all' === watermark ) ? 'apply_all' : 'apply_single' );
208
+ nonce = ( 'all' === watermark ) ? ew.applyAllNonce : ew.applySingleNonces[ watermark ];
209
+ } else if ( 'restore' === bulkAction ) {
210
+ action += 'restore_backup';
211
+ nonce = ew.restoreBackupNonce;
212
+ } else {
213
+ return;
214
+ }
215
+
216
+ const
217
+ status = this.status(),
218
+ selection = this.get( 'selection' ),
219
+ model = selection.shift(),
220
+ data = { action, nonce, watermark };
221
+
222
+ let processed = status.get( 'processed' );
223
+
224
+ data.attachment_id = model.get( 'id' );
225
+
226
+ this.set( 'currentAttachmentID', data.attachment_id );
227
+
228
+ $.ajax( ajaxurl, {
229
+ data,
230
+ } ).done( ( response ) => {
231
+ if ( true === response.success ) {
232
+ if ( response.data.attachmentVersion ) {
233
+ const img = this.form.find( 'tr#post-' + data.attachment_id + ' img' ),
234
+ src = imageVersion( img.attr( 'src' ), response.data.attachmentVersion );
235
+
236
+ img.attr( { src, srcset: '' } );
237
+ }
238
+
239
+ processed++;
240
+ status.set( { processed } );
241
+
242
+ model.set( 'hasBackup', response.data.hasBackup ? true : false );
243
+ model.trigger( 'processing:done' );
244
+
245
+ if ( selection.length ) {
246
+ this.doActionRecursive();
247
+ } else {
248
+ this.actionDone();
249
+ }
250
+ } else {
251
+ const error = ( 'string' === typeof response.data.message ) ? response.data.message : ew.i18n.genericErrorMessage;
252
+ this.actionError( error );
253
+ }
254
+ } ).fail( () => {
255
+ this.actionError( ew.i18n.genericErrorMessage );
256
+ } );
257
+ }
258
+
259
+ actionError( error ) {
260
+ this.status().set( { error } );
261
+ this.actionDone();
262
+ }
263
+
264
+ actionDone() {
265
+ this.trigger( 'bulkAction:finished' );
266
+
267
+ this.bulkActionsSelectors.prop( 'disabled', false );
268
+
269
+ const
270
+ status = this.status(),
271
+ processed = status.get( 'processed' ),
272
+ error = status.get( 'error' ),
273
+ successMessage = status.get( 'successMessage' ),
274
+ currentID = this.get( 'currentAttachmentID' );
275
+
276
+ if ( processed > 0 ) {
277
+ addNotice( successMessage.replace( '{procesed}', processed ), 'success' );
278
+ } else {
279
+ addNotice( successMessage, 'info' );
280
+ }
281
+
282
+ if ( error ) {
283
+ const
284
+ row = this.form.find( 'tr#post-' + currentID ),
285
+ imageTitle = row.find( '.column-title a' ).attr( 'aria-label' );
286
+
287
+ const errorMessage = ew.i18n.bulkActionErrorMessage
288
+ .replace( '{imageTitle}', imageTitle )
289
+ .replace( '{error}', error );
290
+ addNotice( errorMessage, 'error' );
291
+ }
292
+
293
+ this.status().set( {
294
+ processing: false,
295
+ processed: 0,
296
+ total: 0,
297
+ text: '',
298
+ } );
299
+ }
300
+
301
+ status() {
302
+ let status = this.get( 'status' );
303
+
304
+ if ( undefined === status ) {
305
+ status = new Model;
306
+ status.set( {
307
+ processed: 0,
308
+ total: 0,
309
+ } );
310
+
311
+ this.set( { status } );
312
+ }
313
+
314
+ return status;
315
+ }
316
+
317
+ checkAction( action ) {
318
+ return [ 'watermark', 'restore' ].includes( action );
319
+ }
320
+ }
321
+
322
+ $( document ).ready( () => new BulkActions );
assets/src/scripts/controllers/media-frame.js CHANGED
@@ -1,211 +1,211 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
- import { Collection, Model } from 'backbone';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- import {
11
- addNotice,
12
- imageVersion,
13
- filterSelection,
14
- } from '../utils/functions.js';
15
-
16
- /* global wp, ew, ajaxurl */
17
-
18
- if ( wp.media && wp.media.view && wp.media.view.MediaFrame && 'function' === typeof wp.media.view.MediaFrame.Manage ) {
19
- wp.media.view.MediaFrame.Manage = class extends wp.media.view.MediaFrame.Manage {
20
- browseContent( contentRegion ) {
21
- this.state().set( {
22
- ewCollection: new Collection,
23
- ewStatus: new Model,
24
- } );
25
-
26
- super.browseContent( contentRegion );
27
- }
28
-
29
- ewBulkAction() {
30
- const
31
- state = this.state(),
32
- selection = state.get( 'selection' ),
33
- action = state.get( 'ewAction' ),
34
- originalSelection = selection.clone();
35
-
36
- state.set( 'originalSelection', originalSelection );
37
-
38
- filterSelection( selection, ( 'restore' === action ) );
39
-
40
- if ( ! selection.length ) {
41
- return;
42
- }
43
-
44
- const
45
- collection = state.get( 'ewCollection' ),
46
- status = state.get( 'ewStatus' );
47
-
48
- collection.reset();
49
-
50
- for ( const model of selection.models ) { // eslint-disable-line no-unused-vars
51
- collection.add( model );
52
- model.trigger( 'ewBulkAction:start' );
53
- }
54
-
55
- this.deactivateMode( 'watermark' ).trigger( 'selection:action:done' );
56
- this.activateMode( 'processing' );
57
-
58
- status.set( {
59
- total: collection.length,
60
- processed: 0,
61
- error: false,
62
- visible: true,
63
- progress: true,
64
- } );
65
-
66
- this.ewBulkActionRecursive();
67
- }
68
-
69
- ewBulkActionRecursive() {
70
- const
71
- state = this.state(),
72
- bulkAction = state.get( 'ewAction' ),
73
- watermark = state.get( 'watermark' );
74
-
75
- let
76
- action = 'easy-watermark/',
77
- nonce;
78
-
79
- if ( 'watermark' === bulkAction ) {
80
- action += ( ( 'all' === watermark ) ? 'apply_all' : 'apply_single' );
81
- nonce = ( 'all' === watermark ) ? ew.applyAllNonce : ew.applySingleNonces[ watermark ];
82
- } else if ( 'restore' === bulkAction ) {
83
- action += 'restore_backup';
84
- nonce = ew.restoreBackupNonce;
85
- } else {
86
- return;
87
- }
88
-
89
- const
90
- status = state.get( 'ewStatus' ),
91
- collection = state.get( 'ewCollection' ),
92
- model = collection.shift(),
93
- data = { action, nonce, watermark };
94
-
95
- let processed = status.get( 'processed' );
96
-
97
- data.attachment_id = model.get( 'id' );
98
-
99
- state.set( 'ewCurrentModel', model );
100
-
101
- $.ajax( ajaxurl, {
102
- data,
103
- } ).done( ( response ) => {
104
- if ( true === response.success ) {
105
- if ( response.data.attachmentVersion ) {
106
- model.set( 'url', imageVersion( model.get( 'url' ), response.data.attachmentVersion ) );
107
-
108
- const sizes = model.get( 'sizes' );
109
-
110
- for ( const size of Object.keys( sizes ) ) { // eslint-disable-line no-unused-vars
111
- sizes[ size ].url = imageVersion( sizes[ size ].url, response.data.attachmentVersion );
112
- }
113
-
114
- model.set( 'sizes', sizes );
115
- }
116
-
117
- model.set( 'hasBackup', response.data.hasBackup ? true : false );
118
-
119
- processed++;
120
- status.set( { processed } );
121
- model.trigger( 'ewBulkAction:done' );
122
-
123
- if ( status.get( 'total' ) === processed ) {
124
- this.ewBulkActionDone();
125
- } else {
126
- this.ewBulkActionRecursive();
127
- }
128
- } else {
129
- const error = ( 'string' === typeof response.data.message ) ? response.data.message : ew.i18n.genericErrorMessage;
130
- this.ewBulkActionError( error );
131
- }
132
- } ).fail( () => {
133
- this.ewBulkActionError( ew.i18n.genericErrorMessage );
134
- } );
135
- }
136
-
137
- ewWatermark() {
138
- this.state().set( {
139
- ewAction: 'watermark',
140
- ewSuccessMessage: ew.i18n.watermarkingSuccessMessage,
141
- } ).get( 'ewStatus' ).set( {
142
- text: ew.i18n.watermarkingStatus,
143
- } );
144
-
145
- this.activateMode( 'watermarking' );
146
- this.ewBulkAction();
147
- }
148
-
149
- ewRestoreBackup() {
150
- this.state().set( {
151
- ewAction: 'restore',
152
- ewSuccessMessage: ew.i18n.restoringSuccessMessage,
153
- } ).get( 'ewStatus' ).set( {
154
- text: ew.i18n.restoringStatus,
155
- } );
156
-
157
- this.activateMode( 'restoring' );
158
- this.ewBulkAction();
159
- }
160
-
161
- ewBulkActionError( error ) {
162
- const
163
- state = this.state(),
164
- status = state.get( 'ewStatus' ),
165
- collection = state.get( 'ewCollection' ),
166
- currentModel = state.get( 'ewCurrentModel' );
167
-
168
- if ( currentModel ) {
169
- collection.push( currentModel );
170
- }
171
-
172
- for ( const model of collection.models ) { // eslint-disable-line no-unused-vars
173
- model.trigger( 'ewBulkAction:done' );
174
- }
175
-
176
- status.set( { error } );
177
-
178
- this.ewBulkActionDone();
179
- }
180
-
181
- ewBulkActionDone() {
182
- const
183
- state = this.state(),
184
- status = state.get( 'ewStatus' ),
185
- currentModel = state.get( 'ewCurrentModel' ),
186
- procesed = status.get( 'processed' ),
187
- error = status.get( 'error' ),
188
- successMessage = state.get( 'ewSuccessMessage' );
189
-
190
- this.deactivateMode( 'watermarking' );
191
- this.deactivateMode( 'restoring' );
192
- this.deactivateMode( 'processing' );
193
-
194
- if ( procesed > 0 ) {
195
- addNotice( successMessage.replace( '{procesed}', procesed ), 'success' );
196
- }
197
-
198
- if ( error ) {
199
- const errorMessage = ew.i18n.bulkActionErrorMessage
200
- .replace( '{imageTitle}', currentModel.get( 'title' ) )
201
- .replace( '{error}', error );
202
- addNotice( errorMessage, 'error' );
203
- }
204
-
205
- status.set( {
206
- visible: false,
207
- progress: false,
208
- } );
209
- }
210
- };
211
- }
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import $ from 'jquery';
5
+ import { Collection, Model } from 'backbone';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import {
11
+ addNotice,
12
+ imageVersion,
13
+ filterSelection,
14
+ } from '../utils/functions.js';
15
+
16
+ /* global wp, ew, ajaxurl */
17
+
18
+ if ( wp.media && wp.media.view && wp.media.view.MediaFrame && 'function' === typeof wp.media.view.MediaFrame.Manage ) {
19
+ wp.media.view.MediaFrame.Manage = class extends wp.media.view.MediaFrame.Manage {
20
+ browseContent( contentRegion ) {
21
+ this.state().set( {
22
+ ewCollection: new Collection,
23
+ ewStatus: new Model,
24
+ } );
25
+
26
+ super.browseContent( contentRegion );
27
+ }
28
+
29
+ ewBulkAction() {
30
+ const
31
+ state = this.state(),
32
+ selection = state.get( 'selection' ),
33
+ action = state.get( 'ewAction' ),
34
+ originalSelection = selection.clone();
35
+
36
+ state.set( 'originalSelection', originalSelection );
37
+
38
+ filterSelection( selection, ( 'restore' === action ) );
39
+
40
+ if ( ! selection.length ) {
41
+ return;
42
+ }
43
+
44
+ const
45
+ collection = state.get( 'ewCollection' ),
46
+ status = state.get( 'ewStatus' );
47
+
48
+ collection.reset();
49
+
50
+ for ( const model of selection.models ) { // eslint-disable-line no-unused-vars
51
+ collection.add( model );
52
+ model.trigger( 'ewBulkAction:start' );
53
+ }
54
+
55
+ this.deactivateMode( 'watermark' ).trigger( 'selection:action:done' );
56
+ this.activateMode( 'processing' );
57
+
58
+ status.set( {
59
+ total: collection.length,
60
+ processed: 0,
61
+ error: false,
62
+ visible: true,
63
+ progress: true,
64
+ } );
65
+
66
+ this.ewBulkActionRecursive();
67
+ }
68
+
69
+ ewBulkActionRecursive() {
70
+ const
71
+ state = this.state(),
72
+ bulkAction = state.get( 'ewAction' ),
73
+ watermark = state.get( 'watermark' );
74
+
75
+ let
76
+ action = 'easy-watermark/',
77
+ nonce;
78
+
79
+ if ( 'watermark' === bulkAction ) {
80
+ action += ( ( 'all' === watermark ) ? 'apply_all' : 'apply_single' );
81
+ nonce = ( 'all' === watermark ) ? ew.applyAllNonce : ew.applySingleNonces[ watermark ];
82
+ } else if ( 'restore' === bulkAction ) {
83
+ action += 'restore_backup';
84
+ nonce = ew.restoreBackupNonce;
85
+ } else {
86
+ return;
87
+ }
88
+
89
+ const
90
+ status = state.get( 'ewStatus' ),
91
+ collection = state.get( 'ewCollection' ),
92
+ model = collection.shift(),
93
+ data = { action, nonce, watermark };
94
+
95
+ let processed = status.get( 'processed' );
96
+
97
+ data.attachment_id = model.get( 'id' );
98
+
99
+ state.set( 'ewCurrentModel', model );
100
+
101
+ $.ajax( ajaxurl, {
102
+ data,
103
+ } ).done( ( response ) => {
104
+ if ( true === response.success ) {
105
+ if ( response.data.attachmentVersion ) {
106
+ model.set( 'url', imageVersion( model.get( 'url' ), response.data.attachmentVersion ) );
107
+
108
+ const sizes = model.get( 'sizes' );
109
+
110
+ for ( const size of Object.keys( sizes ) ) { // eslint-disable-line no-unused-vars
111
+ sizes[ size ].url = imageVersion( sizes[ size ].url, response.data.attachmentVersion );
112
+ }
113
+
114
+ model.set( 'sizes', sizes );
115
+ }
116
+
117
+ model.set( 'hasBackup', response.data.hasBackup ? true : false );
118
+
119
+ processed++;
120
+ status.set( { processed } );
121
+ model.trigger( 'ewBulkAction:done' );
122
+
123
+ if ( status.get( 'total' ) === processed ) {
124
+ this.ewBulkActionDone();
125
+ } else {
126
+ this.ewBulkActionRecursive();
127
+ }
128
+ } else {
129
+ const error = ( 'string' === typeof response.data.message ) ? response.data.message : ew.i18n.genericErrorMessage;
130
+ this.ewBulkActionError( error );
131
+ }
132
+ } ).fail( () => {
133
+ this.ewBulkActionError( ew.i18n.genericErrorMessage );
134
+ } );
135
+ }
136
+
137
+ ewWatermark() {
138
+ this.state().set( {
139
+ ewAction: 'watermark',
140
+ ewSuccessMessage: ew.i18n.watermarkingSuccessMessage,
141
+ } ).get( 'ewStatus' ).set( {
142
+ text: ew.i18n.watermarkingStatus,
143
+ } );
144
+
145
+ this.activateMode( 'watermarking' );
146
+ this.ewBulkAction();
147
+ }
148
+
149
+ ewRestoreBackup() {
150
+ this.state().set( {
151
+ ewAction: 'restore',
152
+ ewSuccessMessage: ew.i18n.restoringSuccessMessage,
153
+ } ).get( 'ewStatus' ).set( {
154
+ text: ew.i18n.restoringStatus,
155
+ } );
156
+
157
+ this.activateMode( 'restoring' );
158
+ this.ewBulkAction();
159
+ }
160
+
161
+ ewBulkActionError( error ) {
162
+ const
163
+ state = this.state(),
164
+ status = state.get( 'ewStatus' ),
165
+ collection = state.get( 'ewCollection' ),
166
+ currentModel = state.get( 'ewCurrentModel' );
167
+
168
+ if ( currentModel ) {
169
+ collection.push( currentModel );
170
+ }
171
+
172
+ for ( const model of collection.models ) { // eslint-disable-line no-unused-vars
173
+ model.trigger( 'ewBulkAction:done' );
174
+ }
175
+
176
+ status.set( { error } );
177
+
178
+ this.ewBulkActionDone();
179
+ }
180
+
181
+ ewBulkActionDone() {
182
+ const
183
+ state = this.state(),
184
+ status = state.get( 'ewStatus' ),
185
+ currentModel = state.get( 'ewCurrentModel' ),
186
+ procesed = status.get( 'processed' ),
187
+ error = status.get( 'error' ),
188
+ successMessage = state.get( 'ewSuccessMessage' );
189
+
190
+ this.deactivateMode( 'watermarking' );
191
+ this.deactivateMode( 'restoring' );
192
+ this.deactivateMode( 'processing' );
193
+
194
+ if ( procesed > 0 ) {
195
+ addNotice( successMessage.replace( '{procesed}', procesed ), 'success' );
196
+ }
197
+
198
+ if ( error ) {
199
+ const errorMessage = ew.i18n.bulkActionErrorMessage
200
+ .replace( '{imageTitle}', currentModel.get( 'title' ) )
201
+ .replace( '{error}', error );
202
+ addNotice( errorMessage, 'error' );
203
+ }
204
+
205
+ status.set( {
206
+ visible: false,
207
+ progress: false,
208
+ } );
209
+ }
210
+ };
211
+ }
assets/src/scripts/includes/vex.js CHANGED
@@ -1,56 +1,56 @@
1
- /**
2
- * External dependencies
3
- */
4
- import vex from 'vex-js/src/vex.combined';
5
- import 'vex-js/dist/css/vex.css';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- import '../../styles/components/_vex.scss';
11
-
12
- /* global ew */
13
-
14
- vex.defaultOptions.className = 'vex-theme-ew';
15
- vex.defaultOptions.contentClassName = 'postbox';
16
-
17
- vex.dialog.buttons.YES = {
18
- ...vex.dialog.buttons.YES,
19
- className: 'button-primary',
20
- text: ew.i18n.yes,
21
- };
22
-
23
- vex.dialog.buttons.OK = {
24
- ...vex.dialog.buttons.YES,
25
- className: 'button-primary',
26
- text: ew.i18n.ok,
27
- };
28
-
29
- vex.dialog.buttons.NO = {
30
- ...vex.dialog.buttons.NO,
31
- className: 'button',
32
- text: ew.i18n.no,
33
- };
34
-
35
- export default vex;
36
-
37
- export function confirm( message = '', callback = () => {} ) {
38
- return vex.dialog.confirm( {
39
- message,
40
- callback,
41
- buttons: [
42
- vex.dialog.buttons.YES,
43
- vex.dialog.buttons.NO,
44
- ],
45
- } );
46
- }
47
-
48
- export function alert( message = '', callback = () => {} ) {
49
- return vex.dialog.alert( {
50
- message,
51
- callback,
52
- buttons: [
53
- vex.dialog.buttons.OK,
54
- ],
55
- } );
56
- }
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import vex from 'vex-js/src/vex.combined';
5
+ import 'vex-js/dist/css/vex.css';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import '../../styles/components/_vex.scss';
11
+
12
+ /* global ew */
13
+
14
+ vex.defaultOptions.className = 'vex-theme-ew';
15
+ vex.defaultOptions.contentClassName = 'postbox';
16
+
17
+ vex.dialog.buttons.YES = {
18
+ ...vex.dialog.buttons.YES,
19
+ className: 'button-primary',
20
+ text: ew.i18n.yes,
21
+ };
22
+
23
+ vex.dialog.buttons.OK = {
24
+ ...vex.dialog.buttons.YES,
25
+ className: 'button-primary',
26
+ text: ew.i18n.ok,
27
+ };
28
+
29
+ vex.dialog.buttons.NO = {
30
+ ...vex.dialog.buttons.NO,
31
+ className: 'button',
32
+ text: ew.i18n.no,
33
+ };
34
+
35
+ export default vex;
36
+
37
+ export function confirm( message = '', callback = () => {} ) {
38
+ return vex.dialog.confirm( {
39
+ message,
40
+ callback,
41
+ buttons: [
42
+ vex.dialog.buttons.YES,
43
+ vex.dialog.buttons.NO,
44
+ ],
45
+ } );
46
+ }
47
+
48
+ export function alert( message = '', callback = () => {} ) {
49
+ return vex.dialog.alert( {
50
+ message,
51
+ callback,
52
+ buttons: [
53
+ vex.dialog.buttons.OK,
54
+ ],
55
+ } );
56
+ }
assets/src/scripts/metaboxes/attachment/watermarks.js CHANGED
@@ -1,83 +1,83 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import { addNotice, imageVersion } from '../../utils/functions.js';
10
-
11
- /* global ew, ajaxurl */
12
-
13
- export default class {
14
- constructor() {
15
- this.handleClick = this.handleClick.bind( this );
16
-
17
- this.metabox = $( '#watermarks' );
18
- this.metaboxContent = this.metabox.find( '.watermarks-metabox' );
19
- this.errorMessage = this.metabox.find( '.error-message' );
20
- this.spinners = this.metabox.find( '.spinner' );
21
- this.buttons = this.metabox.find( 'button' );
22
- this.form = $( 'form#post' );
23
- this.postID = this.form.find( '#post_ID' ).val();
24
- this.headerEnd = $( 'hr.wp-header-end' );
25
- this.image = $( '.wp_attachment_image img.thumbnail' );
26
-
27
- this.metabox.on( 'click', 'button', this.handleClick );
28
- }
29
-
30
- handleClick( e ) {
31
- e.preventDefault();
32
-
33
- const button = $( e.target ),
34
- action = button.data( 'action' );
35
-
36
- this.buttons.prop( 'disabled', true );
37
- button.next( '.spinner' ).css( 'visibility', 'visible' );
38
-
39
- this.errorMessage.hide();
40
-
41
- const data = {
42
- action: 'easy-watermark/' + action,
43
- nonce: button.data( 'nonce' ),
44
- attachment_id: this.postID,
45
- };
46
-
47
- if ( 'apply_single' === action ) {
48
- data.watermark = button.data( 'watermark' );
49
- }
50
-
51
- $.ajax( ajaxurl, {
52
- data,
53
- } ).done( ( response ) => {
54
- if ( true === response.success ) {
55
- this.metaboxContent.replaceWith( response.data.metaboxContent );
56
-
57
- this.metaboxContent = this.metabox.find( '.watermarks-metabox' );
58
- this.errorMessage = this.metabox.find( '.error-message' );
59
- this.spinners = this.metabox.find( '.spinner' );
60
- this.buttons = this.metabox.find( 'button' );
61
-
62
- if ( response.data.attachmentVersion ) {
63
- const src = imageVersion( this.image.attr( 'src' ), response.data.attachmentVersion );
64
-
65
- this.image.attr( 'src', src );
66
-
67
- if ( 'string' === typeof response.data.message ) {
68
- addNotice( response.data.message, 'success' );
69
- }
70
- }
71
- } else {
72
- const notice = ( 'string' === typeof response.data.message ) ? response.data.message : ew.genericErrorMessage;
73
-
74
- addNotice( notice, 'error' );
75
- }
76
- } ).fail( () => {
77
- addNotice( ew.genericErrorMessage, 'error' );
78
- } ).complete( () => {
79
- this.spinners.css( 'visibility', 'hidden' );
80
- this.buttons.prop( 'disabled', false );
81
- } );
82
- }
83
- }
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import $ from 'jquery';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import { addNotice, imageVersion } from '../../utils/functions.js';
10
+
11
+ /* global ew, ajaxurl */
12
+
13
+ export default class {
14
+ constructor() {
15
+ this.handleClick = this.handleClick.bind( this );
16
+
17
+ this.metabox = $( '#watermarks' );
18
+ this.metaboxContent = this.metabox.find( '.watermarks-metabox' );
19
+ this.errorMessage = this.metabox.find( '.error-message' );
20
+ this.spinners = this.metabox.find( '.spinner' );
21
+ this.buttons = this.metabox.find( 'button' );
22
+ this.form = $( 'form#post' );
23
+ this.postID = this.form.find( '#post_ID' ).val();
24
+ this.headerEnd = $( 'hr.wp-header-end' );
25
+ this.image = $( '.wp_attachment_image img.thumbnail' );
26
+
27
+ this.metabox.on( 'click', 'button', this.handleClick );
28
+ }
29
+
30
+ handleClick( e ) {
31
+ e.preventDefault();
32
+
33
+ const button = $( e.target ),
34
+ action = button.data( 'action' );
35
+
36
+ this.buttons.prop( 'disabled', true );
37
+ button.next( '.spinner' ).css( 'visibility', 'visible' );
38
+
39
+ this.errorMessage.hide();
40
+
41
+ const data = {
42
+ action: 'easy-watermark/' + action,
43
+ nonce: button.data( 'nonce' ),
44
+ attachment_id: this.postID,
45
+ };
46
+
47
+ if ( 'apply_single' === action ) {
48
+ data.watermark = button.data( 'watermark' );
49
+ }
50
+
51
+ $.ajax( ajaxurl, {
52
+ data,
53
+ } ).done( ( response ) => {
54
+ if ( true === response.success ) {
55
+ this.metaboxContent.replaceWith( response.data.metaboxContent );
56
+
57
+ this.metaboxContent = this.metabox.find( '.watermarks-metabox' );
58
+ this.errorMessage = this.metabox.find( '.error-message' );
59
+ this.spinners = this.metabox.find( '.spinner' );
60
+ this.buttons = this.metabox.find( 'button' );
61
+
62
+ if ( response.data.attachmentVersion ) {
63
+ const src = imageVersion( this.image.attr( 'src' ), response.data.attachmentVersion );
64
+
65
+ this.image.attr( 'src', src );
66
+
67
+ if ( 'string' === typeof response.data.message ) {
68
+ addNotice( response.data.message, 'success' );
69
+ }
70
+ }
71
+ } else {
72
+ const notice = ( 'string' === typeof response.data.message ) ? response.data.message : ew.genericErrorMessage;
73
+
74
+ addNotice( notice, 'error' );
75
+ }
76
+ } ).fail( () => {
77
+ addNotice( ew.genericErrorMessage, 'error' );
78
+ } ).complete( () => {
79
+ this.spinners.css( 'visibility', 'hidden' );
80
+ this.buttons.prop( 'disabled', false );
81
+ } );
82
+ }
83
+ }
assets/src/scripts/metaboxes/watermark/content.js CHANGED
@@ -1,188 +1,193 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
-
6
- /* global wp */
7
-
8
- export default class {
9
- constructor() {
10
- this.metabox = $( '#watermark-content' );
11
- this.form = $( 'form#post' );
12
-
13
- this.imageContent = this.metabox.find( '.image-content' );
14
- this.textContent = this.metabox.find( '.text-content' );
15
-
16
- this.buttonWrap = this.metabox.find( '.select-image-button' );
17
- this.button = this.buttonWrap.find( 'a' );
18
-
19
- this.imageWrap = this.metabox.find( '.watermark-image' );
20
- this.image = this.imageWrap.find( 'img' );
21
- this.mimeTypeField = this.metabox.find( 'input.watermark-mime-type' );
22
- this.urlField = this.metabox.find( 'input.watermark-url' );
23
- this.attachmentIdField = this.metabox.find( 'input.watermark-id' );
24
- this.opacityField = this.metabox.find( 'input#opacity' );
25
- this.opacityFieldDesc = this.metabox.find( '.opacity-desc' );
26
- this.watermarkTextField = this.metabox.find( 'input.watermark-text' );
27
-
28
- this.attachmentId = this.attachmentIdField.val();
29
-
30
- this.openMediaLibrary = this.openMediaLibrary.bind( this );
31
- this.update = this.update.bind( this );
32
- this.watermarkTextChange = this.watermarkTextChange.bind( this );
33
-
34
- this.form.on( 'ew.update', this.update );
35
- this.button.on( 'click', this.openMediaLibrary );
36
- this.image.on( 'click', this.openMediaLibrary );
37
-
38
- if ( this.image.attr( 'src' ) ) {
39
- this.imageWrap.show();
40
- this.switchOpacityField( this.mimeTypeField.val() );
41
- } else {
42
- this.buttonWrap.show();
43
- }
44
-
45
- this.textChangeTimeout = null;
46
-
47
- this.watermarkTextField.on( 'input', this.watermarkTextChange );
48
- }
49
-
50
- enable( type ) {
51
- this.metabox.fadeIn( 200 );
52
-
53
- if ( type === 'image' ) {
54
- this.imageContent.show();
55
- this.textContent.hide();
56
- this.opacityField.prop( 'disabled', false );
57
- } else {
58
- this.textContent.show();
59
- this.imageContent.hide();
60
- this.opacityField.prop( 'disabled', true );
61
- this.prepareTextPreview();
62
- }
63
- }
64
-
65
- watermarkTextChange() {
66
- clearTimeout( this.textChangeTimeout );
67
-
68
- this.textChangeTimeout = setTimeout( () => {
69
- this.form.trigger( 'ew.save' );
70
- }, 500 );
71
- }
72
-
73
- prepareTextPreview() {
74
- if ( ! this.previewWrap ) {
75
- this.previewWrap = this.metabox.find( '.text-preview' );
76
- this.preview = $( document.createElement( 'img' ) );
77
-
78
- this.previewWrap.hide().append( this.preview );
79
- }
80
-
81
- this.refreshPreview();
82
- }
83
-
84
- refreshPreview() {
85
- if ( this.watermarkTextField.val().length ) {
86
- const src = this.previewWrap.data( 'src' ) + '?t=' + Date.now();
87
-
88
- this.preview.attr( 'src', src );
89
- this.previewWrap.show();
90
- } else {
91
- this.previewWrap.hide();
92
- }
93
- }
94
-
95
- openMediaLibrary( e ) {
96
- e.preventDefault();
97
-
98
- if ( ! this.frame ) {
99
- this.createMediaFrame();
100
- }
101
-
102
- this.frame.open();
103
- }
104
-
105
- createMediaFrame() {
106
- this.frame = wp.media.frames.watermarkSelection = wp.media( {
107
- title: this.button.data( 'choose' ),
108
- library: {
109
- type: 'image',
110
- },
111
- button: {
112
- text: this.button.data( 'buttonLabel' ),
113
- close: true,
114
- },
115
- } );
116
-
117
- this.frame
118
- .on( 'select', this.selectImage, this )
119
- .on( 'open', this.applySelection, this )
120
- .on( 'close', this.checkSelectedAttachment, this );
121
- }
122
-
123
- selectImage() {
124
- const
125
- attachment = this.frame.state().get( 'selection' ).first(),
126
- mime = attachment.get( 'mime' ),
127
- url = attachment.get( 'url' );
128
-
129
- this.attachmentId = attachment.get( 'id' );
130
-
131
- this.mimeTypeField.val( mime );
132
- this.urlField.val( url );
133
- this.attachmentIdField.val( this.attachmentId );
134
-
135
- this.switchOpacityField( mime );
136
-
137
- this.image.attr( 'src', url );
138
- this.imageWrap.show();
139
- this.buttonWrap.hide();
140
-
141
- this.form.trigger( 'ew.save' );
142
- }
143
-
144
- applySelection() {
145
- if ( this.attachmentId ) {
146
- const
147
- selection = this.frame.state().get( 'selection' ),
148
- attachment = wp.media.attachment( this.attachmentId );
149
-
150
- attachment.fetch();
151
-
152
- if ( attachment ) {
153
- selection.add( [ attachment ] );
154
- }
155
- }
156
- }
157
-
158
- checkSelectedAttachment() {
159
- const attachment = wp.media.attachment( this.attachmentId );
160
-
161
- attachment.fetch();
162
-
163
- if ( ! attachment || true === attachment.destroyed ) {
164
- this.mimeTypeField.val( '' );
165
- this.urlField.val( '' );
166
- this.attachmentIdField.val( '' );
167
-
168
- this.imageWrap.hide();
169
- this.buttonWrap.show();
170
- }
171
- }
172
-
173
- switchOpacityField( imgType ) {
174
- if ( 'image/png' === imgType ) {
175
- this.opacityField.parent().hide();
176
- this.opacityFieldDesc.show();
177
- } else {
178
- this.opacityField.parent().show();
179
- this.opacityFieldDesc.hide();
180
- }
181
- }
182
-
183
- update() {
184
- if ( 'text' === this.form.find( 'input.watermark-type:checked' ).val() ) {
185
- this.refreshPreview();
186
- }
187
- }
188
- }
 
 
 
 
 
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import $ from 'jquery';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import { imageVersion } from '../../utils/functions';
10
+
11
+ /* global wp */
12
+
13
+ export default class {
14
+ constructor() {
15
+ this.metabox = $( '#watermark-content' );
16
+ this.form = $( 'form#post' );
17
+
18
+ this.imageContent = this.metabox.find( '.image-content' );
19
+ this.textContent = this.metabox.find( '.text-content' );
20
+
21
+ this.buttonWrap = this.metabox.find( '.select-image-button' );
22
+ this.button = this.buttonWrap.find( 'a' );
23
+
24
+ this.imageWrap = this.metabox.find( '.watermark-image' );
25
+ this.image = this.imageWrap.find( 'img' );
26
+ this.mimeTypeField = this.metabox.find( 'input.watermark-mime-type' );
27
+ this.urlField = this.metabox.find( 'input.watermark-url' );
28
+ this.attachmentIdField = this.metabox.find( 'input.watermark-id' );
29
+ this.opacityField = this.metabox.find( 'input#opacity' );
30
+ this.opacityFieldDesc = this.metabox.find( '.opacity-desc' );
31
+ this.watermarkTextField = this.metabox.find( 'input.watermark-text' );
32
+
33
+ this.attachmentId = this.attachmentIdField.val();
34
+
35
+ this.openMediaLibrary = this.openMediaLibrary.bind( this );
36
+ this.update = this.update.bind( this );
37
+ this.watermarkTextChange = this.watermarkTextChange.bind( this );
38
+
39
+ this.form.on( 'ew.update', this.update );
40
+ this.button.on( 'click', this.openMediaLibrary );
41
+ this.image.on( 'click', this.openMediaLibrary );
42
+
43
+ if ( this.image.attr( 'src' ) ) {
44
+ this.imageWrap.show();
45
+ this.switchOpacityField( this.mimeTypeField.val() );
46
+ } else {
47
+ this.buttonWrap.show();
48
+ }
49
+
50
+ this.textChangeTimeout = null;
51
+
52
+ this.watermarkTextField.on( 'input', this.watermarkTextChange );
53
+ }
54
+
55
+ enable( type ) {
56
+ this.metabox.fadeIn( 200 );
57
+
58
+ if ( type === 'image' ) {
59
+ this.imageContent.show();
60
+ this.textContent.hide();
61
+ this.opacityField.prop( 'disabled', false );
62
+ } else {
63
+ this.textContent.show();
64
+ this.imageContent.hide();
65
+ this.opacityField.prop( 'disabled', true );
66
+ this.prepareTextPreview();
67
+ }
68
+ }
69
+
70
+ watermarkTextChange() {
71
+ clearTimeout( this.textChangeTimeout );
72
+
73
+ this.textChangeTimeout = setTimeout( () => {
74
+ this.form.trigger( 'ew.save' );
75
+ }, 500 );
76
+ }
77
+
78
+ prepareTextPreview() {
79
+ if ( ! this.previewWrap ) {
80
+ this.previewWrap = this.metabox.find( '.text-preview' );
81
+ this.preview = $( document.createElement( 'img' ) );
82
+
83
+ this.previewWrap.hide().append( this.preview );
84
+ }
85
+
86
+ this.refreshPreview();
87
+ }
88
+
89
+ refreshPreview() {
90
+ if ( this.watermarkTextField.val().length ) {
91
+ const src = imageVersion( this.previewWrap.data( 'src' ) );
92
+
93
+ this.preview.attr( 'src', src );
94
+ this.previewWrap.show();
95
+ } else {
96
+ this.previewWrap.hide();
97
+ }
98
+ }
99
+
100
+ openMediaLibrary( e ) {
101
+ e.preventDefault();
102
+
103
+ if ( ! this.frame ) {
104
+ this.createMediaFrame();
105
+ }
106
+
107
+ this.frame.open();
108
+ }
109
+
110
+ createMediaFrame() {
111
+ this.frame = wp.media.frames.watermarkSelection = wp.media( {
112
+ title: this.button.data( 'choose' ),
113
+ library: {
114
+ type: 'image',
115
+ },
116
+ button: {
117
+ text: this.button.data( 'buttonLabel' ),
118
+ close: true,
119
+ },
120
+ } );
121
+
122
+ this.frame
123
+ .on( 'select', this.selectImage, this )
124
+ .on( 'open', this.applySelection, this )
125
+ .on( 'close', this.checkSelectedAttachment, this );
126
+ }
127
+
128
+ selectImage() {
129
+ const
130
+ attachment = this.frame.state().get( 'selection' ).first(),
131
+ mime = attachment.get( 'mime' ),
132
+ url = attachment.get( 'url' );
133
+
134
+ this.attachmentId = attachment.get( 'id' );
135
+
136
+ this.mimeTypeField.val( mime );
137
+ this.urlField.val( url );
138
+ this.attachmentIdField.val( this.attachmentId );
139
+
140
+ this.switchOpacityField( mime );
141
+
142
+ this.image.attr( 'src', url );
143
+ this.imageWrap.show();
144
+ this.buttonWrap.hide();
145
+
146
+ this.form.trigger( 'ew.save' );
147
+ }
148
+
149
+ applySelection() {
150
+ if ( this.attachmentId ) {
151
+ const
152
+ selection = this.frame.state().get( 'selection' ),
153
+ attachment = wp.media.attachment( this.attachmentId );
154
+
155
+ attachment.fetch();
156
+
157
+ if ( attachment ) {
158
+ selection.add( [ attachment ] );
159
+ }
160
+ }
161
+ }
162
+
163
+ checkSelectedAttachment() {
164
+ const attachment = wp.media.attachment( this.attachmentId );
165
+
166
+ attachment.fetch();
167
+
168
+ if ( ! attachment || true === attachment.destroyed ) {
169
+ this.mimeTypeField.val( '' );
170
+ this.urlField.val( '' );
171
+ this.attachmentIdField.val( '' );
172
+
173
+ this.imageWrap.hide();
174
+ this.buttonWrap.show();
175
+ }
176
+ }
177
+
178
+ switchOpacityField( imgType ) {
179
+ if ( 'image/png' === imgType ) {
180
+ this.opacityField.parent().hide();
181
+ this.opacityFieldDesc.show();
182
+ } else {
183
+ this.opacityField.parent().show();
184
+ this.opacityFieldDesc.hide();
185
+ }
186
+ }
187
+
188
+ update() {
189
+ if ( 'text' === this.form.find( 'input.watermark-type:checked' ).val() ) {
190
+ this.refreshPreview();
191
+ }
192
+ }
193
+ }
assets/src/scripts/metaboxes/watermark/preview.js CHANGED
@@ -1,173 +1,171 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import { imageVersion } from '../../utils/functions';
10
-
11
- /* global wp, ew, ajaxurl */
12
-
13
- export default class {
14
- constructor() {
15
- this.metabox = $( '#preview' );
16
- this.body = $( 'body' );
17
- this.form = $( 'form#post' );
18
- this.watermarkTextField = this.form.find( 'input.watermark-text' );
19
- this.attachmentIdField = this.form.find( 'input.watermark-id' );
20
- this.link = this.metabox.find( '.select-preview-image' );
21
- this.previewWrap = this.metabox.find( '.preview-wrap' );
22
- this.contentWrap = this.metabox.find( '.content-wrap' );
23
- this.imageSelector = this.metabox.find( '.image-selector' );
24
- this.popup = this.metabox.find( '.ew-preview-popup' );
25
- this.spinner = this.metabox.find( 'span.spinner' );
26
- this.image = $( document.createElement( 'img' ) );
27
-
28
- this.popup.appendTo( this.body );
29
-
30
- this.openMediaLibrary = this.openMediaLibrary.bind( this );
31
- this.openPopup = this.openPopup.bind( this );
32
- this.closePopup = this.closePopup.bind( this );
33
- this.selectImage = this.selectImage.bind( this );
34
- this.imageSelected = this.imageSelected.bind( this );
35
- this.update = this.update.bind( this );
36
-
37
- this.hasImage = this.previewWrap.data( 'hasImage' );
38
-
39
- this.link.on( 'click', this.openMediaLibrary );
40
- this.form.on( 'ew.update', this.update );
41
- this.image.on( 'click', this.openPopup );
42
-
43
- this.popup.find( '.media-modal-close, .media-modal-backdrop' ).on( 'click', this.closePopup );
44
-
45
- this.imageSelector.hide();
46
- this.contentWrap.hide();
47
- this.previewWrap.prepend( this.image );
48
-
49
- this.refreshPreview();
50
- }
51
-
52
- enable() {
53
- this.metabox.fadeIn( 200 );
54
- }
55
-
56
- openMediaLibrary( e ) {
57
- e.preventDefault();
58
-
59
- if ( ! this.frame ) {
60
- this.createMediaFrame();
61
- }
62
-
63
- this.frame.open();
64
- }
65
-
66
- createMediaFrame() {
67
- this.frame = wp.media.frames.previewImage = wp.media( {
68
- title: this.link.data( 'choose' ),
69
- library: {
70
- type: 'image',
71
- },
72
- button: {
73
- text: this.link.data( 'buttonLabel' ),
74
- close: true,
75
- },
76
- } );
77
-
78
- this.frame.on( 'select', this.selectImage );
79
- }
80
-
81
- selectImage() {
82
- const attachment = this.frame.state().get( 'selection' ).first(),
83
- watermarkId = this.form.find( 'input[name=post_ID]' ).val();
84
-
85
- this.contentWrap.hide();
86
- this.spinner.css( 'display', 'block' );
87
-
88
- $.ajax( {
89
- type: 'post',
90
- url: ajaxurl,
91
- data: {
92
- action: 'easy-watermark/preview_image',
93
- attachment_id: attachment.id,
94
- watermark_id: watermarkId,
95
- nonce: ew.previewImageNonce,
96
- },
97
- } ).done( this.imageSelected ).fail( () => {
98
- // TODO: handle errors.
99
- } );
100
- }
101
-
102
- imageSelected( response ) {
103
- if ( true === response.success ) {
104
- this.link.html( this.link.data( 'changeLabel' ) );
105
- this.hasImage = true;
106
-
107
- if ( response.data.popup ) {
108
- const popup = $( response.data.popup );
109
-
110
- this.popup.find( '.media-frame-content' ).replaceWith( popup.find( '.media-frame-content' ) );
111
- }
112
-
113
- this.refreshPreview();
114
- }
115
- }
116
-
117
- refreshPreview() {
118
- this.contentWrap.hide();
119
-
120
- if ( this.hasImage ) {
121
- this.imageSelector.hide();
122
- this.spinner.css( 'display', 'block' );
123
-
124
- const
125
- time = Date.now(),
126
- src = imageVersion( this.previewWrap.data( 'src' ), time );
127
-
128
- this.popup.find( 'img' ).each( ( i, e ) => {
129
- const
130
- img = $( e ),
131
- psrc = imageVersion( img.attr( 'src' ), time );
132
-
133
- img.attr( 'src', psrc );
134
- } );
135
-
136
- this.image.one( 'load', () => {
137
- this.spinner.hide();
138
- this.contentWrap.fadeIn( 200 );
139
- this.imageSelector.fadeIn( 200 );
140
- } ).attr( 'src', src );
141
- } else {
142
- this.imageSelector.show();
143
- }
144
- }
145
-
146
- openPopup() {
147
- this.popup.show();
148
- this.body.addClass( 'modal-open' );
149
- }
150
-
151
- closePopup() {
152
- this.popup.hide();
153
- this.body.removeClass( 'modal-open' );
154
- }
155
-
156
- hasPreview() {
157
- const type = this.form.find( 'input.watermark-type:checked' ).val();
158
-
159
- if ( 'text' === type && this.watermarkTextField.val().length ) {
160
- return true;
161
- }
162
-
163
- if ( 'image' === type && this.attachmentIdField.val().length ) {
164
- return true;
165
- }
166
-
167
- return false;
168
- }
169
-
170
- update() {
171
- this.refreshPreview();
172
- }
173
- }
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import $ from 'jquery';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import { imageVersion } from '../../utils/functions';
10
+
11
+ /* global wp, ew, ajaxurl */
12
+
13
+ export default class {
14
+ constructor() {
15
+ this.metabox = $( '#preview' );
16
+ this.body = $( 'body' );
17
+ this.form = $( 'form#post' );
18
+ this.watermarkTextField = this.form.find( 'input.watermark-text' );
19
+ this.attachmentIdField = this.form.find( 'input.watermark-id' );
20
+ this.link = this.metabox.find( '.select-preview-image' );
21
+ this.previewWrap = this.metabox.find( '.preview-wrap' );
22
+ this.contentWrap = this.metabox.find( '.content-wrap' );
23
+ this.imageSelector = this.metabox.find( '.image-selector' );
24
+ this.popup = this.metabox.find( '.ew-preview-popup' );
25
+ this.spinner = this.metabox.find( 'span.spinner' );
26
+ this.image = $( document.createElement( 'img' ) );
27
+
28
+ this.popup.appendTo( this.body );
29
+
30
+ this.openMediaLibrary = this.openMediaLibrary.bind( this );
31
+ this.openPopup = this.openPopup.bind( this );
32
+ this.closePopup = this.closePopup.bind( this );
33
+ this.selectImage = this.selectImage.bind( this );
34
+ this.imageSelected = this.imageSelected.bind( this );
35
+ this.update = this.update.bind( this );
36
+
37
+ this.hasImage = this.previewWrap.data( 'hasImage' );
38
+
39
+ this.link.on( 'click', this.openMediaLibrary );
40
+ this.form.on( 'ew.update', this.update );
41
+ this.image.on( 'click', this.openPopup );
42
+
43
+ this.popup.find( '.media-modal-close, .media-modal-backdrop' ).on( 'click', this.closePopup );
44
+
45
+ this.imageSelector.hide();
46
+ this.contentWrap.hide();
47
+ this.previewWrap.prepend( this.image );
48
+
49
+ this.refreshPreview();
50
+ }
51
+
52
+ enable() {
53
+ this.metabox.fadeIn( 200 );
54
+ }
55
+
56
+ openMediaLibrary( e ) {
57
+ e.preventDefault();
58
+
59
+ if ( ! this.frame ) {
60
+ this.createMediaFrame();
61
+ }
62
+
63
+ this.frame.open();
64
+ }
65
+
66
+ createMediaFrame() {
67
+ this.frame = wp.media.frames.previewImage = wp.media( {
68
+ title: this.link.data( 'choose' ),
69
+ library: {
70
+ type: 'image',
71
+ },
72
+ button: {
73
+ text: this.link.data( 'buttonLabel' ),
74
+ close: true,
75
+ },
76
+ } );
77
+
78
+ this.frame.on( 'select', this.selectImage );
79
+ }
80
+
81
+ selectImage() {
82
+ const attachment = this.frame.state().get( 'selection' ).first(),
83
+ watermarkId = this.form.find( 'input[name=post_ID]' ).val();
84
+
85
+ this.contentWrap.hide();
86
+ this.spinner.css( 'display', 'block' );
87
+
88
+ $.ajax( {
89
+ type: 'post',
90
+ url: ajaxurl,
91
+ data: {
92
+ action: 'easy-watermark/preview_image',
93
+ attachment_id: attachment.id,
94
+ watermark_id: watermarkId,
95
+ nonce: ew.previewImageNonce,
96
+ },
97
+ } ).done( this.imageSelected ).fail( () => {
98
+ // TODO: handle errors.
99
+ } );
100
+ }
101
+
102
+ imageSelected( response ) {
103
+ if ( true === response.success ) {
104
+ this.link.html( this.link.data( 'changeLabel' ) );
105
+ this.hasImage = true;
106
+
107
+ if ( response.data.popup ) {
108
+ const popup = $( response.data.popup );
109
+
110
+ this.popup.find( '.media-frame-content' ).replaceWith( popup.find( '.media-frame-content' ) );
111
+ }
112
+
113
+ this.refreshPreview();
114
+ }
115
+ }
116
+
117
+ refreshPreview() {
118
+ this.contentWrap.hide();
119
+
120
+ if ( this.hasImage ) {
121
+ this.imageSelector.hide();
122
+ this.spinner.css( 'display', 'block' );
123
+
124
+ const src = imageVersion( this.previewWrap.data( 'src' ) );
125
+
126
+ this.popup.find( 'img' ).each( ( i, e ) => {
127
+ const
128
+ img = $( e ),
129
+ psrc = imageVersion( img.attr( 'src' ) );
130
+
131
+ img.attr( 'src', psrc );
132
+ } );
133
+
134
+ this.image.one( 'load', () => {
135
+ this.spinner.hide();
136
+ this.contentWrap.fadeIn( 200 );
137
+ this.imageSelector.fadeIn( 200 );
138
+ } ).attr( 'src', src );
139
+ } else {
140
+ this.imageSelector.show();
141
+ }
142
+ }
143
+
144
+ openPopup() {
145
+ this.popup.show();
146
+ this.body.addClass( 'modal-open' );
147
+ }
148
+
149
+ closePopup() {
150
+ this.popup.hide();
151
+ this.body.removeClass( 'modal-open' );
152
+ }
153
+
154
+ hasPreview() {
155
+ const type = this.form.find( 'input.watermark-type:checked' ).val();
156
+
157
+ if ( 'text' === type && this.watermarkTextField.val().length ) {
158
+ return true;
159
+ }
160
+
161
+ if ( 'image' === type && this.attachmentIdField.val().length ) {
162
+ return true;
163
+ }
164
+
165
+ return false;
166
+ }
167
+
168
+ update() {
169
+ this.refreshPreview();
170
+ }
171
+ }
 
 
assets/src/scripts/pages/bulk-actions.js CHANGED
@@ -1,322 +1,322 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
- import { Model, Collection } from 'backbone';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- import WatermarkSelector from '../views/media-list/watermark-selector';
11
- import Status from '../views/media-list/status';
12
- import Attachment from '../views/media-list/attachment';
13
-
14
- import {
15
- addNotice,
16
- imageVersion,
17
- filterSelection,
18
- } from '../utils/functions.js';
19
-
20
- /* global ew, ajaxurl */
21
-
22
- class BulkActions extends Model {
23
- constructor() {
24
- super();
25
-
26
- this.bulkActionsSelectors = $( 'select#bulk-action-selector-top, select#bulk-action-selector-bottom' );
27
-
28
- if ( this.bulkActionsSelectors.length ) {
29
- this.init();
30
- }
31
- }
32
-
33
- init() {
34
- this.selectBulkAction = this.selectBulkAction.bind( this );
35
- this.doAction = this.doAction.bind( this );
36
-
37
- this.form = $( 'form#posts-filter' );
38
- this.actionButtons = this.form.find( '#doaction, #doaction2' );
39
-
40
- this.bulkActionsSelectors.each( ( n, item ) => {
41
- const select = $( item );
42
-
43
- new WatermarkSelector( {
44
- controller: this,
45
- bulkActionSelector: select,
46
- } ).render();
47
-
48
- new Status( {
49
- controller: this,
50
- bulkActionSelector: select,
51
- } ).render();
52
- } ).val( -1 ).on( 'change', this.selectBulkAction );
53
-
54
- this.set( {
55
- attachments: new Collection,
56
- selection: new Collection,
57
- } );
58
-
59
- this.actionButtons.on( 'click', this.doAction );
60
-
61
- this.on( 'bulkAction:start', () => {
62
- this.bulkActionsSelectors.val( -1 ).prop( 'disabled', true );
63
- this.actionButtons.prop( 'disabled', true );
64
- } );
65
-
66
- this.on( 'bulkAction:finished', () => {
67
- this.bulkActionsSelectors.prop( 'disabled', false );
68
- this.actionButtons.prop( 'disabled', false );
69
- } );
70
- }
71
-
72
- selectBulkAction( e ) {
73
- const select = $( e.target );
74
-
75
- this.set( {
76
- select,
77
- action: select.val(),
78
- } );
79
- }
80
-
81
- doAction( e ) {
82
- const action = this.get( 'action' );
83
-
84
- if ( ! this.checkAction( action ) ) {
85
- return;
86
- }
87
-
88
- e.preventDefault();
89
-
90
- const watermark = this.get( 'watermark' );
91
-
92
- if ( 'watermark' === action && ! watermark ) {
93
- return;
94
- }
95
-
96
- const checkedItems = this.form.find( 'input[name="media[]"]:checked' );
97
-
98
- if ( ! checkedItems.length ) {
99
- this.status().set( { text: ew.i18n.noItemsSelected } );
100
- return;
101
- }
102
-
103
- const
104
- attachments = this.get( 'attachments' ),
105
- selection = this.get( 'selection' ),
106
- attachmentIds = [];
107
-
108
- this.trigger( 'bulkAction:start' );
109
-
110
- checkedItems.each( ( n, checkbox ) => {
111
- const
112
- id = $( checkbox ).val(),
113
- model = attachments.get( id );
114
-
115
- if ( model ) {
116
- selection.add( model );
117
- } else {
118
- attachmentIds.push( id );
119
- }
120
- } );
121
-
122
- if ( ! attachmentIds.length ) {
123
- if ( selection.length ) {
124
- this.prepare();
125
- }
126
-
127
- return;
128
- }
129
-
130
- this.status().set( {
131
- text: '<span class="spinner ew-spinner"></span>',
132
- } );
133
-
134
- $.ajax( ajaxurl, { data: {
135
- action: 'easy-watermark/attachments-info',
136
- nonce: ew.attachmentsInfoNonce,
137
- attachments: attachmentIds,
138
- } } ).done( ( response ) => {
139
- if ( true === response.success ) {
140
- for ( const item of response.data ) {
141
- const model = new Model( item );
142
-
143
- attachments.push( model );
144
- selection.push( model );
145
-
146
- new Attachment( {
147
- el: `#post-${ item.id }`,
148
- controller: this,
149
- model,
150
- } );
151
- }
152
-
153
- this.prepare();
154
- } else {
155
- const error = response.data.message ? response.data.message : ew.i18n.genericErrorMessage;
156
- this.actionError( error );
157
- }
158
- } ).fail( () => {
159
- this.actionError( ew.i18n.genericErrorMessage );
160
- } );
161
- }
162
-
163
- prepare() {
164
- const
165
- action = this.get( 'action' ),
166
- selection = this.get( 'selection' ),
167
- backup = ( 'restore' === action ),
168
- statusText = 'watermark' === action ? ew.i18n.watermarkingStatus : ew.i18n.restoringStatus,
169
- successMessage = 'watermark' === action ? ew.i18n.watermarkingSuccessMessage : ew.i18n.restoringSuccessMessage;
170
-
171
- filterSelection( selection, backup );
172
-
173
- if ( ! selection.length ) {
174
- this.status().set( {
175
- successMessage: 'watermark' === action ? ew.i18n.watermarkingNoItems : ew.i18n.restoringNoItems,
176
- } );
177
-
178
- this.actionDone();
179
- return;
180
- }
181
-
182
- this.status().set( {
183
- successMessage,
184
- text: statusText,
185
- processing: true,
186
- total: selection.length,
187
- processed: 0,
188
- } );
189
-
190
- for ( const model of selection.models ) {
191
- model.trigger( 'processing:start' );
192
- }
193
-
194
- this.doActionRecursive();
195
- }
196
-
197
- doActionRecursive() {
198
- const
199
- bulkAction = this.get( 'action' ),
200
- watermark = this.get( 'watermark' );
201
-
202
- let
203
- action = 'easy-watermark/',
204
- nonce;
205
-
206
- if ( 'watermark' === bulkAction ) {
207
- action += ( ( 'all' === watermark ) ? 'apply_all' : 'apply_single' );
208
- nonce = ( 'all' === watermark ) ? ew.applyAllNonce : ew.applySingleNonces[ watermark ];
209
- } else if ( 'restore' === bulkAction ) {
210
- action += 'restore_backup';
211
- nonce = ew.restoreBackupNonce;
212
- } else {
213
- return;
214
- }
215
-
216
- const
217
- status = this.status(),
218
- selection = this.get( 'selection' ),
219
- model = selection.shift(),
220
- data = { action, nonce, watermark };
221
-
222
- let processed = status.get( 'processed' );
223
-
224
- data.attachment_id = model.get( 'id' );
225
-
226
- this.set( 'currentAttachmentID', data.attachment_id );
227
-
228
- $.ajax( ajaxurl, {
229
- data,
230
- } ).done( ( response ) => {
231
- if ( true === response.success ) {
232
- if ( response.data.attachmentVersion ) {
233
- const img = this.form.find( 'tr#post-' + data.attachment_id + ' img' ),
234
- src = imageVersion( img.attr( 'src' ), response.data.attachmentVersion );
235
-
236
- img.attr( { src, srcset: '' } );
237
- }
238
-
239
- processed++;
240
- status.set( { processed } );
241
-
242
- model.set( 'hasBackup', response.data.hasBackup ? true : false );
243
- model.trigger( 'processing:done' );
244
-
245
- if ( selection.length ) {
246
- this.doActionRecursive();
247
- } else {
248
- this.actionDone();
249
- }
250
- } else {
251
- const error = ( 'string' === typeof response.data.message ) ? response.data.message : ew.i18n.genericErrorMessage;
252
- this.actionError( error );
253
- }
254
- } ).fail( () => {
255
- this.actionError( ew.i18n.genericErrorMessage );
256
- } );
257
- }
258
-
259
- actionError( error ) {
260
- this.status().set( { error } );
261
- this.actionDone();
262
- }
263
-
264
- actionDone() {
265
- this.trigger( 'bulkAction:finished' );
266
-
267
- this.bulkActionsSelectors.prop( 'disabled', false );
268
-
269
- const
270
- status = this.status(),
271
- processed = status.get( 'processed' ),
272
- error = status.get( 'error' ),
273
- successMessage = status.get( 'successMessage' ),
274
- currentID = this.get( 'currentAttachmentID' );
275
-
276
- if ( processed > 0 ) {
277
- addNotice( successMessage.replace( '{procesed}', processed ), 'success' );
278
- } else {
279
- addNotice( successMessage, 'info' );
280
- }
281
-
282
- if ( error ) {
283
- const
284
- row = this.form.find( 'tr#post-' + currentID ),
285
- imageTitle = row.find( '.column-title a' ).attr( 'aria-label' );
286
-
287
- const errorMessage = ew.i18n.bulkActionErrorMessage
288
- .replace( '{imageTitle}', imageTitle )
289
- .replace( '{error}', error );
290
- addNotice( errorMessage, 'error' );
291
- }
292
-
293
- this.status().set( {
294
- processing: false,
295
- processed: 0,
296
- total: 0,
297
- text: '',
298
- } );
299
- }
300
-
301
- status() {
302
- let status = this.get( 'status' );
303
-
304
- if ( undefined === status ) {
305
- status = new Model;
306
- status.set( {
307
- processed: 0,
308
- total: 0,
309
- } );
310
-
311
- this.set( { status } );
312
- }
313
-
314
- return status;
315
- }
316
-
317
- checkAction( action ) {
318
- return [ 'watermark', 'restore' ].includes( action );
319
- }
320
- }
321
-
322
- $( document ).ready( () => new BulkActions );
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import $ from 'jquery';
5
+ import { Model, Collection } from 'backbone';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import WatermarkSelector from '../views/media-list/watermark-selector';
11
+ import Status from '../views/media-list/status';
12
+ import Attachment from '../views/media-list/attachment';
13
+
14
+ import {
15
+ addNotice,
16
+ imageVersion,
17
+ filterSelection,
18
+ } from '../utils/functions.js';
19
+
20
+ /* global ew, ajaxurl */
21
+
22
+ class BulkActions extends Model {
23
+ constructor() {
24
+ super();
25
+
26
+ this.bulkActionsSelectors = $( 'select#bulk-action-selector-top, select#bulk-action-selector-bottom' );
27
+
28
+ if ( this.bulkActionsSelectors.length ) {
29
+ this.init();
30
+ }
31
+ }
32
+
33
+ init() {
34
+ this.selectBulkAction = this.selectBulkAction.bind( this );
35
+ this.doAction = this.doAction.bind( this );
36
+
37
+ this.form = $( 'form#posts-filter' );
38
+ this.actionButtons = this.form.find( '#doaction, #doaction2' );
39
+
40
+ this.bulkActionsSelectors.each( ( n, item ) => {
41
+ const select = $( item );
42
+
43
+ new WatermarkSelector( {
44
+ controller: this,
45
+ bulkActionSelector: select,
46
+ } ).render();
47
+
48
+ new Status( {
49
+ controller: this,
50
+ bulkActionSelector: select,
51
+ } ).render();
52
+ } ).val( -1 ).on( 'change', this.selectBulkAction );
53
+
54
+ this.set( {
55
+ attachments: new Collection,
56
+ selection: new Collection,
57
+ } );
58
+
59
+ this.actionButtons.on( 'click', this.doAction );
60
+
61
+ this.on( 'bulkAction:start', () => {
62
+ this.bulkActionsSelectors.val( -1 ).prop( 'disabled', true );
63
+ this.actionButtons.prop( 'disabled', true );
64
+ } );
65
+
66
+ this.on( 'bulkAction:finished', () => {
67
+ this.bulkActionsSelectors.prop( 'disabled', false );
68
+ this.actionButtons.prop( 'disabled', false );
69
+ } );
70
+ }
71
+
72
+ selectBulkAction( e ) {
73
+ const select = $( e.target );
74
+
75
+ this.set( {
76
+ select,
77
+ action: select.val(),
78
+ } );
79
+ }
80
+
81
+ doAction( e ) {
82
+ const action = this.get( 'action' );
83
+
84
+ if ( ! this.checkAction( action ) ) {
85
+ return;
86
+ }
87
+
88
+ e.preventDefault();
89
+
90
+ const watermark = this.get( 'watermark' );
91
+
92
+ if ( 'watermark' === action && ! watermark ) {
93
+ return;
94
+ }
95
+
96
+ const checkedItems = this.form.find( 'input[name="media[]"]:checked' );
97
+
98
+ if ( ! checkedItems.length ) {
99
+ this.status().set( { text: ew.i18n.noItemsSelected } );
100
+ return;
101
+ }
102
+
103
+ const
104
+ attachments = this.get( 'attachments' ),
105
+ selection = this.get( 'selection' ),
106
+ attachmentIds = [];
107
+
108
+ this.trigger( 'bulkAction:start' );
109
+
110
+ checkedItems.each( ( n, checkbox ) => {
111
+ const
112
+ id = $( checkbox ).val(),
113
+ model = attachments.get( id );
114
+
115
+ if ( model ) {
116
+ selection.add( model );
117
+ } else {
118
+ attachmentIds.push( id );
119
+ }
120
+ } );
121
+
122
+ if ( ! attachmentIds.length ) {
123
+ if ( selection.length ) {
124
+ this.prepare();
125
+ }
126
+
127
+ return;
128
+ }
129
+
130
+ this.status().set( {
131
+ text: '<span class="spinner ew-spinner"></span>',
132
+ } );
133
+
134
+ $.ajax( ajaxurl, { data: {
135
+ action: 'easy-watermark/attachments-info',
136
+ nonce: ew.attachmentsInfoNonce,
137
+ attachments: attachmentIds,
138
+ } } ).done( ( response ) => {
139
+ if ( true === response.success ) {
140
+ for ( const item of response.data ) {
141
+ const model = new Model( item );
142
+
143
+ attachments.push( model );
144
+ selection.push( model );
145
+
146
+ new Attachment( {
147
+ el: `#post-${ item.id }`,
148
+ controller: this,
149
+ model,
150
+ } );
151
+ }
152
+
153
+ this.prepare();
154
+ } else {
155
+ const error = response.data.message ? response.data.message : ew.i18n.genericErrorMessage;
156
+ this.actionError( error );
157
+ }
158
+ } ).fail( () => {
159
+ this.actionError( ew.i18n.genericErrorMessage );
160
+ } );
161
+ }
162
+
163
+ prepare() {
164
+ const
165
+ action = this.get( 'action' ),
166
+ selection = this.get( 'selection' ),
167
+ backup = ( 'restore' === action ),
168
+ statusText = 'watermark' === action ? ew.i18n.watermarkingStatus : ew.i18n.restoringStatus,
169
+ successMessage = 'watermark' === action ? ew.i18n.watermarkingSuccessMessage : ew.i18n.restoringSuccessMessage;
170
+
171
+ filterSelection( selection, backup );
172
+
173
+ if ( ! selection.length ) {
174
+ this.status().set( {
175
+ successMessage: 'watermark' === action ? ew.i18n.watermarkingNoItems : ew.i18n.restoringNoItems,
176
+ } );
177
+
178
+ this.actionDone();
179
+ return;
180
+ }
181
+
182
+ this.status().set( {
183
+ successMessage,
184
+ text: statusText,
185
+ processing: true,
186
+ total: selection.length,
187
+ processed: 0,
188
+ } );
189
+
190
+ for ( const model of selection.models ) {
191
+ model.trigger( 'processing:start' );
192
+ }
193
+
194
+ this.doActionRecursive();
195
+ }
196
+
197
+ doActionRecursive() {
198
+ const
199
+ bulkAction = this.get( 'action' ),
200
+ watermark = this.get( 'watermark' );
201
+
202
+ let
203
+ action = 'easy-watermark/',
204
+ nonce;
205
+
206
+ if ( 'watermark' === bulkAction ) {
207
+ action += ( ( 'all' === watermark ) ? 'apply_all' : 'apply_single' );
208
+ nonce = ( 'all' === watermark ) ? ew.applyAllNonce : ew.applySingleNonces[ watermark ];
209
+ } else if ( 'restore' === bulkAction ) {
210
+ action += 'restore_backup';
211
+ nonce = ew.restoreBackupNonce;
212
+ } else {
213
+ return;
214
+ }
215
+
216
+ const
217
+ status = this.status(),
218
+ selection = this.get( 'selection' ),
219
+ model = selection.shift(),
220
+ data = { action, nonce, watermark };
221
+
222
+ let processed = status.get( 'processed' );
223
+
224
+ data.attachment_id = model.get( 'id' );
225
+
226
+ this.set( 'currentAttachmentID', data.attachment_id );
227
+
228
+ $.ajax( ajaxurl, {
229
+ data,
230
+ } ).done( ( response ) => {
231
+ if ( true === response.success ) {
232
+ if ( response.data.attachmentVersion ) {
233
+ const img = this.form.find( 'tr#post-' + data.attachment_id + ' img' ),
234
+ src = imageVersion( img.attr( 'src' ), response.data.attachmentVersion );
235
+
236
+ img.attr( { src, srcset: '' } );
237
+ }
238
+
239
+ processed++;
240
+ status.set( { processed } );
241
+
242
+ model.set( 'hasBackup', response.data.hasBackup ? true : false );
243
+ model.trigger( 'processing:done' );
244
+
245
+ if ( selection.length ) {
246
+ this.doActionRecursive();
247
+ } else {
248
+ this.actionDone();
249
+ }
250
+ } else {
251
+ const error = ( 'string' === typeof response.data.message ) ? response.data.message : ew.i18n.genericErrorMessage;
252
+ this.actionError( error );
253
+ }
254
+ } ).fail( () => {
255
+ this.actionError( ew.i18n.genericErrorMessage );
256
+ } );
257
+ }
258
+
259
+ actionError( error ) {
260
+ this.status().set( { error } );
261
+ this.actionDone();
262
+ }
263
+
264
+ actionDone() {
265
+ this.trigger( 'bulkAction:finished' );
266
+
267
+ this.bulkActionsSelectors.prop( 'disabled', false );
268
+
269
+ const
270
+ status = this.status(),
271
+ processed = status.get( 'processed' ),
272
+ error = status.get( 'error' ),
273
+ successMessage = status.get( 'successMessage' ),
274
+ currentID = this.get( 'currentAttachmentID' );
275
+
276
+ if ( processed > 0 ) {
277
+ addNotice( successMessage.replace( '{procesed}', processed ), 'success' );
278
+ } else {
279
+ addNotice( successMessage, 'info' );
280
+ }
281
+
282
+ if ( error ) {
283
+ const
284
+ row = this.form.find( 'tr#post-' + currentID ),
285
+ imageTitle = row.find( '.column-title a' ).attr( 'aria-label' );
286
+
287
+ const errorMessage = ew.i18n.bulkActionErrorMessage
288
+ .replace( '{imageTitle}', imageTitle )
289
+ .replace( '{error}', error );
290
+ addNotice( errorMessage, 'error' );
291
+ }
292
+
293
+ this.status().set( {
294
+ processing: false,
295
+ processed: 0,
296
+ total: 0,
297
+ text: '',
298
+ } );
299
+ }
300
+
301
+ status() {
302
+ let status = this.get( 'status' );
303
+
304
+ if ( undefined === status ) {
305
+ status = new Model;
306
+ status.set( {
307
+ processed: 0,
308
+ total: 0,
309
+ } );
310
+
311
+ this.set( { status } );
312
+ }
313
+
314
+ return status;
315
+ }
316
+
317
+ checkAction( action ) {
318
+ return [ 'watermark', 'restore' ].includes( action );
319
+ }
320
+ }
321
+
322
+ $( document ).ready( () => new BulkActions );
assets/src/scripts/pages/tools.js CHANGED
@@ -1,192 +1,192 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
- import { Model } from 'backbone';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- import BulkWatermarkTool from '../views/tools/bulk-watermark';
11
- import RestoreTool from '../views/tools/restore';
12
- import { addNotice } from '../utils/functions.js';
13
- import { alert } from '../includes/vex.js';
14
- /* global ew, ajaxurl */
15
-
16
- export default class {
17
- constructor() {
18
- this.wrap = $( '.tools' );
19
-
20
- if ( this.wrap.length ) {
21
- this.init();
22
- }
23
- }
24
-
25
- init() {
26
- this.bulkWatermark = this.bulkWatermark.bind( this );
27
- this.restore = this.restore.bind( this );
28
-
29
- this.state = new Model;
30
- this.state.set( {
31
- mode: 'none',
32
- } );
33
-
34
- this.bulkWatermarkTool = new BulkWatermarkTool( {
35
- state: this.state,
36
- callback: this.bulkWatermark,
37
- } );
38
-
39
- this.restoreTool = new RestoreTool( {
40
- state: this.state,
41
- callback: this.restore,
42
- } );
43
- }
44
-
45
- bulkWatermark() {
46
- this.state.set( {
47
- action: 'watermark',
48
- successMessage: ew.i18n.watermarkingSuccessMessage,
49
- statusText: ew.i18n.watermarkingStatus,
50
- } );
51
-
52
- this.getInfo();
53
- }
54
-
55
- restore() {
56
- this.state.set( {
57
- action: 'restore',
58
- successMessage: ew.i18n.restoringSuccessMessage,
59
- statusText: ew.i18n.restoringStatus,
60
- } );
61
-
62
- this.getInfo();
63
- }
64
-
65
- getInfo() {
66
- this.state.set( {
67
- mode: 'loading',
68
- } );
69
-
70
- $.ajax( ajaxurl, { data: {
71
- action: 'easy-watermark/tools/get-attachments',
72
- nonce: ew.nonce,
73
- mode: this.state.get( 'action' ),
74
- } } ).done( ( response ) => {
75
- if ( response.success ) {
76
- this.state.set( {
77
- items: response.data,
78
- } );
79
-
80
- this.start();
81
- } else {
82
- addNotice( ew.i18n.genericErrorMessage, 'error' );
83
- }
84
- } ).fail( () => {
85
- addNotice( ew.i18n.genericErrorMessage, 'error' );
86
- } );
87
- }
88
-
89
- start() {
90
- const items = this.state.get( 'items' );
91
-
92
- if ( ! items ) {
93
- alert( ew.i18n.noItemsToWatermark );
94
- this.state.set( { mode: 'none' } );
95
- return;
96
- }
97
-
98
- this.state.set( {
99
- mode: 'processing',
100
- processed: 0,
101
- total: items.length,
102
- error: false,
103
- backupCount: 0,
104
- } );
105
-
106
- this.doActionRecursive( items );
107
- }
108
-
109
- doActionRecursive( items ) {
110
- const
111
- attachment = items.shift(),
112
- nonce = this.state.get( 'nonce' ),
113
- watermark = this.state.get( 'watermark' );
114
-
115
- let
116
- action = 'easy-watermark/',
117
- processed = this.state.get( 'processed' ),
118
- backupCount = this.state.get( 'backupCount' );
119
-
120
- if ( 'watermark' === this.state.get( 'action' ) ) {
121
- action += ( ( 'all' === watermark ) ? 'apply_all' : 'apply_single' );
122
- } else {
123
- action += 'restore_backup';
124
- }
125
-
126
- this.state.set( {
127
- attachment,
128
- } );
129
-
130
- $.ajax( ajaxurl, { data: {
131
- action,
132
- nonce,
133
- watermark,
134
- attachment_id: attachment.id,
135
- } } ).done( ( response ) => {
136
- if ( true === response.success ) {
137
- processed++;
138
-
139
- if ( response.data.hasBackup ) {
140
- backupCount++;
141
- }
142
-
143
- this.state.set( {
144
- processed,
145
- backupCount,
146
- } );
147
-
148
- if ( items.length ) {
149
- this.doActionRecursive( items );
150
- } else {
151
- this.finish();
152
- }
153
- } else {
154
- this.fail( response.data );
155
- }
156
- } ).fail( () => {
157
- this.fail( ew.i18n.genericErrorMessage );
158
- } );
159
- }
160
-
161
- fail( errorMessage ) {
162
- const
163
- attachment = this.state.get( 'attachment' ),
164
- imageTitle = attachment.title,
165
- error = ew.i18n.bulkActionErrorMessage
166
- .replace( '{imageTitle}', imageTitle )
167
- .replace( '{error}', errorMessage );
168
-
169
- this.state.set( {
170
- error,
171
- } );
172
-
173
- this.finish();
174
- }
175
-
176
- finish() {
177
- const
178
- error = this.state.get( 'error' ),
179
- processed = this.state.get( 'processed' ),
180
- successMessage = this.state.get( 'successMessage' );
181
-
182
- if ( error ) {
183
- addNotice( error, 'error' );
184
- } else {
185
- addNotice( successMessage.replace( '{procesed}', processed ), 'success' );
186
- }
187
-
188
- this.state.set( {
189
- mode: 'none',
190
- } );
191
- }
192
- }
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import $ from 'jquery';
5
+ import { Model } from 'backbone';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import BulkWatermarkTool from '../views/tools/bulk-watermark';
11
+ import RestoreTool from '../views/tools/restore';
12
+ import { addNotice } from '../utils/functions.js';
13
+ import { alert } from '../includes/vex.js';
14
+ /* global ew, ajaxurl */
15
+
16
+ export default class {
17
+ constructor() {
18
+ this.wrap = $( '.tools' );
19
+
20
+ if ( this.wrap.length ) {
21
+ this.init();
22
+ }
23
+ }
24
+
25
+ init() {
26
+ this.bulkWatermark = this.bulkWatermark.bind( this );
27
+ this.restore = this.restore.bind( this );
28
+
29
+ this.state = new Model;
30
+ this.state.set( {
31
+ mode: 'none',
32
+ } );
33
+
34
+ this.bulkWatermarkTool = new BulkWatermarkTool( {
35
+ state: this.state,
36
+ callback: this.bulkWatermark,
37
+ } );
38
+
39
+ this.restoreTool = new RestoreTool( {
40
+ state: this.state,
41
+ callback: this.restore,
42
+ } );
43
+ }
44
+
45
+ bulkWatermark() {
46
+ this.state.set( {
47
+ action: 'watermark',
48
+ successMessage: ew.i18n.watermarkingSuccessMessage,
49
+ statusText: ew.i18n.watermarkingStatus,
50
+ } );
51
+
52
+ this.getInfo();
53
+ }
54
+
55
+ restore() {
56
+ this.state.set( {
57
+ action: 'restore',
58
+ successMessage: ew.i18n.restoringSuccessMessage,
59
+ statusText: ew.i18n.restoringStatus,
60
+ } );
61
+
62
+ this.getInfo();
63
+ }
64
+
65
+ getInfo() {
66
+ this.state.set( {
67
+ mode: 'loading',
68
+ } );
69
+
70
+ $.ajax( ajaxurl, { data: {
71
+ action: 'easy-watermark/tools/get-attachments',
72
+ nonce: ew.nonce,
73
+ mode: this.state.get( 'action' ),
74
+ } } ).done( ( response ) => {
75
+ if ( response.success ) {
76
+ this.state.set( {
77
+ items: response.data,
78
+ } );
79
+
80
+ this.start();
81
+ } else {
82
+ addNotice( ew.i18n.genericErrorMessage, 'error' );
83
+ }
84
+ } ).fail( () => {
85
+ addNotice( ew.i18n.genericErrorMessage, 'error' );
86
+ } );
87
+ }
88
+
89
+ start() {
90
+ const items = this.state.get( 'items' );
91
+
92
+ if ( ! items ) {
93
+ alert( ew.i18n.noItemsToWatermark );
94
+ this.state.set( { mode: 'none' } );
95
+ return;
96
+ }
97
+
98
+ this.state.set( {
99
+ mode: 'processing',
100
+ processed: 0,
101
+ total: items.length,
102
+ error: false,
103
+ backupCount: 0,
104
+ } );
105
+
106
+ this.doActionRecursive( items );
107
+ }
108
+
109
+ doActionRecursive( items ) {
110
+ const
111
+ attachment = items.shift(),
112
+ nonce = this.state.get( 'nonce' ),
113
+ watermark = this.state.get( 'watermark' );
114
+
115
+ let
116
+ action = 'easy-watermark/',
117
+ processed = this.state.get( 'processed' ),
118
+ backupCount = this.state.get( 'backupCount' );
119
+
120
+ if ( 'watermark' === this.state.get( 'action' ) ) {
121
+ action += ( ( 'all' === watermark ) ? 'apply_all' : 'apply_single' );
122
+ } else {
123
+ action += 'restore_backup';
124
+ }
125
+
126
+ this.state.set( {
127
+ attachment,
128
+ } );
129
+
130
+ $.ajax( ajaxurl, { data: {
131
+ action,
132
+ nonce,
133
+ watermark,
134
+ attachment_id: attachment.id,
135
+ } } ).done( ( response ) => {
136
+ if ( true === response.success ) {
137
+ processed++;
138
+
139
+ if ( response.data.hasBackup ) {
140
+ backupCount++;
141
+ }
142
+
143
+ this.state.set( {
144
+ processed,
145
+ backupCount,
146
+ } );
147
+
148
+ if ( items.length ) {
149
+ this.doActionRecursive( items );
150
+ } else {
151
+ this.finish();
152
+ }
153
+ } else {
154
+ this.fail( response.data );
155
+ }
156
+ } ).fail( () => {
157
+ this.fail( ew.i18n.genericErrorMessage );
158
+ } );
159
+ }
160
+
161
+ fail( errorMessage ) {
162
+ const
163
+ attachment = this.state.get( 'attachment' ),
164
+ imageTitle = attachment.title,
165
+ error = ew.i18n.bulkActionErrorMessage
166
+ .replace( '{imageTitle}', imageTitle )
167
+ .replace( '{error}', errorMessage );
168
+
169
+ this.state.set( {
170
+ error,
171
+ } );
172
+
173
+ this.finish();
174
+ }
175
+
176
+ finish() {
177
+ const
178
+ error = this.state.get( 'error' ),
179
+ processed = this.state.get( 'processed' ),
180
+ successMessage = this.state.get( 'successMessage' );
181
+
182
+ if ( error ) {
183
+ addNotice( error, 'error' );
184
+ } else {
185
+ addNotice( successMessage.replace( '{procesed}', processed ), 'success' );
186
+ }
187
+
188
+ this.state.set( {
189
+ mode: 'none',
190
+ } );
191
+ }
192
+ }
assets/src/scripts/pages/watermarks.js CHANGED
@@ -1,44 +1,44 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import { confirm } from '../includes/vex';
10
-
11
- /* global ew */
12
-
13
- export default class {
14
- constructor() {
15
- this.wrap = $( '.watermarks' );
16
-
17
- if ( this.wrap.length ) {
18
- this.init();
19
- }
20
- }
21
-
22
- init() {
23
- this.confirm = this.confirm.bind( this );
24
-
25
- this.deleteButtons = this.wrap.find( '.row-actions a.submitdelete' );
26
-
27
- this.deleteButtons.on( 'click', this.confirm );
28
- }
29
-
30
- confirm( e ) {
31
- e.preventDefault();
32
-
33
- const
34
- link = $( e.currentTarget ),
35
- watermarkName = link.data( 'watermark-name' ),
36
- message = ew.i18n.deleteConfirmation.replace( '{watermarkName}', watermarkName );
37
-
38
- confirm( message, ( result ) => {
39
- if ( true === result ) {
40
- window.location = link.attr( 'href' );
41
- }
42
- } );
43
- }
44
- }
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import $ from 'jquery';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import { confirm } from '../includes/vex';
10
+
11
+ /* global ew */
12
+
13
+ export default class {
14
+ constructor() {
15
+ this.wrap = $( '.watermarks' );
16
+
17
+ if ( this.wrap.length ) {
18
+ this.init();
19
+ }
20
+ }
21
+
22
+ init() {
23
+ this.confirm = this.confirm.bind( this );
24
+
25
+ this.deleteButtons = this.wrap.find( '.row-actions a.submitdelete' );
26
+
27
+ this.deleteButtons.on( 'click', this.confirm );
28
+ }
29
+
30
+ confirm( e ) {
31
+ e.preventDefault();
32
+
33
+ const
34
+ link = $( e.currentTarget ),
35
+ watermarkName = link.data( 'watermark-name' ),
36
+ message = ew.i18n.deleteConfirmation.replace( '{watermarkName}', watermarkName );
37
+
38
+ confirm( message, ( result ) => {
39
+ if ( true === result ) {
40
+ window.location = link.attr( 'href' );
41
+ }
42
+ } );
43
+ }
44
+ }
assets/src/scripts/uploader.js CHANGED
@@ -1,49 +1,49 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import '../styles/uploader.scss';
10
-
11
- /* global wp, ew */
12
-
13
- $( document ).ready( () => {
14
- if ( typeof wp !== 'undefined' && typeof wp.Uploader === 'function' ) {
15
- const Uploader = wp.Uploader;
16
-
17
- wp.Uploader = class extends Uploader {
18
- init() {
19
- super.init();
20
-
21
- this.updateAutoWatermarkParam = this.updateAutoWatermarkParam.bind( this );
22
-
23
- $( 'body' ).on( 'change', '.ew-watermark-all-switch input', this.updateAutoWatermarkParam );
24
-
25
- this.param( 'auto_watermark', ew.autoWatermark );
26
- }
27
-
28
- updateAutoWatermarkParam( e ) {
29
- ew.autoWatermark = $( e.target ).is( ':checked' );
30
-
31
- this.param( 'auto_watermark', ew.autoWatermark );
32
- }
33
- };
34
- }
35
-
36
- if ( typeof wp !== 'undefined' && wp.media && typeof wp.media.view.UploaderInline === 'function' ) {
37
- const UploaderInline = wp.media.view.UploaderInline;
38
-
39
- wp.media.view.UploaderInline = UploaderInline.extend( {
40
- render() {
41
- UploaderInline.prototype.render.apply( this, arguments );
42
-
43
- if ( ! this.$el.hasClass( 'hidden' ) ) {
44
- this.$el.find( '.ew-watermark-all-switch input' ).prop( 'checked', ew.autoWatermark );
45
- }
46
- },
47
- } );
48
- }
49
- } );
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import $ from 'jquery';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import '../styles/uploader.scss';
10
+
11
+ /* global wp, ew */
12
+
13
+ $( document ).ready( () => {
14
+ if ( typeof wp !== 'undefined' && typeof wp.Uploader === 'function' ) {
15
+ const Uploader = wp.Uploader;
16
+
17
+ wp.Uploader = class extends Uploader {
18
+ init() {
19
+ super.init();
20
+
21
+ this.updateAutoWatermarkParam = this.updateAutoWatermarkParam.bind( this );
22
+
23
+ $( 'body' ).on( 'change', '.ew-watermark-all-switch input', this.updateAutoWatermarkParam );
24
+
25
+ this.param( 'auto_watermark', ew.autoWatermark );
26
+ }
27
+
28
+ updateAutoWatermarkParam( e ) {
29
+ ew.autoWatermark = $( e.target ).is( ':checked' );
30
+
31
+ this.param( 'auto_watermark', ew.autoWatermark );
32
+ }
33
+ };
34
+ }
35
+
36
+ if ( typeof wp !== 'undefined' && wp.media && typeof wp.media.view.UploaderInline === 'function' ) {
37
+ const UploaderInline = wp.media.view.UploaderInline;
38
+
39
+ wp.media.view.UploaderInline = UploaderInline.extend( {
40
+ render() {
41
+ UploaderInline.prototype.render.apply( this, arguments );
42
+
43
+ if ( ! this.$el.hasClass( 'hidden' ) ) {
44
+ this.$el.find( '.ew-watermark-all-switch input' ).prop( 'checked', ew.autoWatermark );
45
+ }
46
+ },
47
+ } );
48
+ }
49
+ } );
assets/src/scripts/utils/form-fields.js CHANGED
@@ -1,60 +1,64 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
-
6
- export default class {
7
- constructor() {
8
- this.fields = $( '.form-field' );
9
- this.buttons = this.fields.find( 'button[data-toggle=dropdown]' );
10
- this.dropdowns = this.fields.find( '.dropdown-menu[data-target]' );
11
- this.links = this.dropdowns.find( 'a' );
12
-
13
- this.init();
14
- }
15
-
16
- init() {
17
- this.toggleDropdown = this.toggleDropdown.bind( this );
18
- this.dropdownSelect = this.dropdownSelect.bind( this );
19
- this.hideDropdowns = this.hideDropdowns.bind( this );
20
-
21
- this.buttons.on( 'click', this.toggleDropdown );
22
- this.links.on( 'click', this.dropdownSelect );
23
- $( document ).on( 'click', this.hideDropdowns );
24
- }
25
-
26
- toggleDropdown( e ) {
27
- e.preventDefault();
28
-
29
- const button = $( e.target ),
30
- position = button.position();
31
-
32
- button.next( '.dropdown-menu' ).css( {
33
- left: position.left,
34
- top: position.top + button.height(),
35
- } ).toggle();
36
- }
37
-
38
- dropdownSelect( e ) {
39
- e.preventDefault();
40
-
41
- const item = $( e.target ),
42
- dropdown = item.closest( '.dropdown-menu' ),
43
- target = $( dropdown.data( 'target' ) );
44
-
45
- if ( target.length ) {
46
- target.val( item.data( 'value' ) );
47
- dropdown.prev( 'button[data-toggle=dropdown]' ).text( item.text() );
48
- }
49
- }
50
-
51
- hideDropdowns( e ) {
52
- const item = $( e.target );
53
-
54
- if ( item.is( this.buttons ) ) {
55
- return;
56
- }
57
-
58
- this.dropdowns.hide();
59
- }
60
- }
 
 
 
 
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import $ from 'jquery';
5
+
6
+ export default class {
7
+ constructor() {
8
+ this.fields = $( '.form-field' );
9
+ this.buttons = this.fields.find( 'button[data-toggle=dropdown]' );
10
+ this.dropdowns = this.fields.find( '.dropdown-menu[data-target]' );
11
+ this.links = this.dropdowns.find( 'a' );
12
+
13
+ this.init();
14
+ }
15
+
16
+ init() {
17
+ this.toggleDropdown = this.toggleDropdown.bind( this );
18
+ this.dropdownSelect = this.dropdownSelect.bind( this );
19
+ this.hideDropdowns = this.hideDropdowns.bind( this );
20
+
21
+ this.buttons.on( 'click', this.toggleDropdown );
22
+ this.links.on( 'click', this.dropdownSelect );
23
+ $( document ).on( 'click', this.hideDropdowns );
24
+ }
25
+
26
+ toggleDropdown( e ) {
27
+ e.preventDefault();
28
+
29
+ const button = $( e.target ),
30
+ position = button.position();
31
+
32
+ button.toggleClass( 'is-open' );
33
+
34
+ button.next( '.dropdown-menu' ).css( {
35
+ left: position.left,
36
+ top: position.top + button.height(),
37
+ } ).toggle();
38
+ }
39
+
40
+ dropdownSelect( e ) {
41
+ e.preventDefault();
42
+
43
+ const item = $( e.target ),
44
+ dropdown = item.closest( '.dropdown-menu' ),
45
+ target = $( dropdown.data( 'target' ) );
46
+
47
+ if ( target.length ) {
48
+ target.val( item.data( 'value' ) );
49
+ dropdown.prev( 'button[data-toggle=dropdown]' ).text( item.text() );
50
+ }
51
+ }
52
+
53
+ hideDropdowns( e ) {
54
+ const item = $( e.target );
55
+
56
+ if ( item.is( this.buttons ) ) {
57
+ return;
58
+ }
59
+
60
+ this.buttons.removeClass( 'is-open' );
61
+
62
+ this.dropdowns.hide();
63
+ }
64
+ }
assets/src/scripts/utils/functions.js CHANGED
@@ -1,67 +1,79 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
-
6
- /* global ew */
7
-
8
- export function addNotice( content, type = 'info' ) {
9
- const notice = $( document.createElement( 'div' ) ),
10
- p = $( document.createElement( 'p' ) ),
11
- button = $( document.createElement( 'button' ) );
12
-
13
- notice.addClass( 'notice notice-' + type + ' is-dismissible' ).hide();
14
- button.addClass( 'notice-dismiss' );
15
- p.html( content );
16
-
17
- notice.append( p ).append( button );
18
-
19
- button.on( 'click', ( e ) => {
20
- e.preventDefault();
21
- notice.fadeOut( 200, () => {
22
- notice.remove();
23
- } );
24
- } );
25
-
26
- $( 'hr.wp-header-end' ).after( notice );
27
-
28
- notice.fadeIn( 200 );
29
- }
30
-
31
- export function filterSelection( selection, backup = false, remove = true ) {
32
- let length = selection.length;
33
-
34
- for ( const model of selection.clone().models ) { // eslint-disable-line no-unused-vars
35
- if ( ! isImage( model ) || model.get( 'usedAsWatermark' ) ||
36
- ( true === backup && ! model.get( 'hasBackup' ) ) ) {
37
- if ( true === remove ) {
38
- selection.remove( model );
39
- }
40
-
41
- length--;
42
- }
43
- }
44
-
45
- return length;
46
- }
47
-
48
- export function imageVersion( url, version ) {
49
- const index = url.indexOf( '?' );
50
-
51
- if ( -1 !== index ) {
52
- url = url.substr( 0, index );
53
- }
54
-
55
- url += '?v=' + version;
56
-
57
- return url;
58
- }
59
-
60
- export function isImage( mime ) {
61
- if ( 'object' === typeof mime && mime.get ) {
62
- // It's a model.
63
- mime = mime.get( 'mime' );
64
- }
65
-
66
- return Object.keys( ew.mime ).includes( mime );
67
- }
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import $ from 'jquery';
5
+
6
+ /* global ew */
7
+
8
+ export function addNotice( content, type = 'info' ) {
9
+ const notice = $( document.createElement( 'div' ) ),
10
+ p = $( document.createElement( 'p' ) ),
11
+ button = $( document.createElement( 'button' ) );
12
+
13
+ notice.addClass( 'notice notice-' + type + ' is-dismissible' ).hide();
14
+ button.addClass( 'notice-dismiss' );
15
+ p.html( content );
16
+
17
+ notice.append( p ).append( button );
18
+
19
+ button.on( 'click', ( e ) => {
20
+ e.preventDefault();
21
+ notice.fadeOut( 200, () => {
22
+ notice.remove();
23
+ } );
24
+ } );
25
+
26
+ $( 'hr.wp-header-end' ).after( notice );
27
+
28
+ notice.fadeIn( 200 );
29
+ }
30
+
31
+ export function filterSelection( selection, backup = false, remove = true ) {
32
+ let length = selection.length;
33
+
34
+ for ( const model of selection.clone().models ) { // eslint-disable-line no-unused-vars
35
+ if ( ! isImage( model ) || model.get( 'usedAsWatermark' ) ||
36
+ ( true === backup && ! model.get( 'hasBackup' ) ) ) {
37
+ if ( true === remove ) {
38
+ selection.remove( model );
39
+ }
40
+
41
+ length--;
42
+ }
43
+ }
44
+
45
+ return length;
46
+ }
47
+
48
+ export function imageVersion( url ) {
49
+ const index = url.indexOf( '?' );
50
+ const version = `t=${ Date.now() }`;
51
+
52
+ let query;
53
+
54
+ if ( -1 !== index ) {
55
+ query = url.substr( index );
56
+ url = url.substr( 0, index );
57
+
58
+ const regex = /([^\s])t=[0-9]+/;
59
+
60
+ if ( query.match( regex ) ) {
61
+ query = query.replace( regex, `$1${ version }` );
62
+ } else {
63
+ query += `&${ version }`;
64
+ }
65
+ } else {
66
+ query = `?${ version }`;
67
+ }
68
+
69
+ return url + query;
70
+ }
71
+
72
+ export function isImage( mime ) {
73
+ if ( 'object' === typeof mime && mime.get ) {
74
+ // It's a model.
75
+ mime = mime.get( 'mime' );
76
+ }
77
+
78
+ return Object.keys( ew.mime ).includes( mime );
79
+ }
assets/src/scripts/views/media-grid/attachment.js CHANGED
@@ -1,100 +1,100 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import { filterSelection, isImage } from '../../utils/functions.js';
10
-
11
- /* global wp, ew */
12
-
13
- if ( wp.media && 'function' === typeof wp.media.view.Attachment.Library ) {
14
- const Library = wp.media.view.Attachment.Library;
15
- wp.media.view.Attachment.Library = Library.extend( {
16
- initialize() {
17
- Library.prototype.initialize.apply( this, arguments );
18
-
19
- this.listenTo( this.model, 'ewBulkAction:start', this.showLoader );
20
- this.listenTo( this.model, 'ewBulkAction:done', this.render );
21
-
22
- this.controller.on( 'selection:toggle watermark:activate processing:activate', this.disable, this );
23
- this.controller.on( 'watermark:deactivate processing:deactivate', this.enable, this );
24
- },
25
-
26
- render() {
27
- Library.prototype.render.apply( this, arguments );
28
-
29
- this.$el.append( $( '<span></span>' ).addClass( 'spinner' ) );
30
- },
31
-
32
- toggleSelection( { method } ) {
33
- if ( ! this.controller.isModeActive( 'watermark' ) ||
34
- ( ( isImage( this.model ) && ! this.model.get( 'usedAsWatermark' ) ) || 'between' === method ) ) {
35
- // In watermark mode only select images.
36
- Library.prototype.toggleSelection.apply( this, arguments );
37
- }
38
-
39
- if ( this.controller.isModeActive( 'watermark' ) ) {
40
- if ( ! isImage( this.model ) || this.model.get( 'usedAsWatermark' ) ) {
41
- this.$el.blur();
42
- }
43
-
44
- if ( 'between' === method ) {
45
- filterSelection( this.options.selection );
46
- }
47
- }
48
- },
49
-
50
- showLoader() {
51
- this.$el.find( '.spinner' ).css( { visibility: 'visible' } );
52
- },
53
-
54
- disable() {
55
- if ( ! this.controller.isModeActive( 'watermark' ) && ! this.controller.isModeActive( 'processing' ) ) {
56
- return;
57
- }
58
-
59
- if ( this.hasBadge ) {
60
- return;
61
- }
62
-
63
- if ( this.controller.isModeActive( 'processing' ) && ! this.wasSelected() ) {
64
- return;
65
- }
66
-
67
- let text;
68
-
69
- if ( ! isImage( this.model ) ) {
70
- text = ew.i18n.notSupported;
71
- } else if ( this.model.get( 'usedAsWatermark' ) ) {
72
- text = ew.i18n.usedAsWatermark;
73
- } else if ( this.controller.isModeActive( 'restoring' ) && ! this.model.get( 'hasBackup' ) ) {
74
- text = ew.i18n.noBackupAvailable;
75
- } else {
76
- return;
77
- }
78
-
79
- const badge = $( '<div>', { class: 'badge' } ).text( text );
80
-
81
- this.$el.addClass( 'disabled' ).append( badge );
82
- this.hasBadge = true;
83
- },
84
-
85
- enable() {
86
- if ( ! this.controller.isModeActive( 'watermark' ) && ! this.controller.isModeActive( 'processing' ) ) {
87
- this.$el.removeClass( 'disabled' ).find( '.badge' ).remove();
88
- this.hasBadge = false;
89
- }
90
- },
91
-
92
- wasSelected() {
93
- const selection = this.controller.state().get( 'originalSelection' );
94
-
95
- if ( selection ) {
96
- return !! selection.get( this.model.cid );
97
- }
98
- },
99
- } );
100
- }
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import $ from 'jquery';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import { filterSelection, isImage } from '../../utils/functions.js';
10
+
11
+ /* global wp, ew */
12
+
13
+ if ( wp.media && 'function' === typeof wp.media.view.Attachment.Library ) {
14
+ const Library = wp.media.view.Attachment.Library;
15
+ wp.media.view.Attachment.Library = Library.extend( {
16
+ initialize() {
17
+ Library.prototype.initialize.apply( this, arguments );
18
+
19
+ this.listenTo( this.model, 'ewBulkAction:start', this.showLoader );
20
+ this.listenTo( this.model, 'ewBulkAction:done', this.render );
21
+
22
+ this.controller.on( 'selection:toggle watermark:activate processing:activate', this.disable, this );
23
+ this.controller.on( 'watermark:deactivate processing:deactivate', this.enable, this );
24
+ },
25
+
26
+ render() {
27
+ Library.prototype.render.apply( this, arguments );
28
+
29
+ this.$el.append( $( '<span></span>' ).addClass( 'spinner' ) );
30
+ },
31
+
32
+ toggleSelection( { method } ) {
33
+ if ( ! this.controller.isModeActive( 'watermark' ) ||
34
+ ( ( isImage( this.model ) && ! this.model.get( 'usedAsWatermark' ) ) || 'between' === method ) ) {
35
+ // In watermark mode only select images.
36
+ Library.prototype.toggleSelection.apply( this, arguments );
37
+ }
38
+
39
+ if ( this.controller.isModeActive( 'watermark' ) ) {
40
+ if ( ! isImage( this.model ) || this.model.get( 'usedAsWatermark' ) ) {
41
+ this.$el.blur();
42
+ }
43
+
44
+ if ( 'between' === method ) {
45
+ filterSelection( this.options.selection );
46
+ }
47
+ }
48
+ },
49
+
50
+ showLoader() {
51
+ this.$el.find( '.spinner' ).css( { visibility: 'visible' } );
52
+ },
53
+
54
+ disable() {
55
+ if ( ! this.controller.isModeActive( 'watermark' ) && ! this.controller.isModeActive( 'processing' ) ) {
56
+ return;
57
+ }
58
+
59
+ if ( this.hasBadge ) {
60
+ return;
61
+ }
62
+
63
+ if ( this.controller.isModeActive( 'processing' ) && ! this.wasSelected() ) {
64
+ return;
65
+ }
66
+
67
+ let text;
68
+
69
+ if ( ! isImage( this.model ) ) {
70
+ text = ew.i18n.notSupported;
71
+ } else if ( this.model.get( 'usedAsWatermark' ) ) {
72
+ text = ew.i18n.usedAsWatermark;
73
+ } else if ( this.controller.isModeActive( 'restoring' ) && ! this.model.get( 'hasBackup' ) ) {
74
+ text = ew.i18n.noBackupAvailable;
75
+ } else {
76
+ return;
77
+ }
78
+
79
+ const badge = $( '<div>', { class: 'badge' } ).text( text );
80
+
81
+ this.$el.addClass( 'disabled' ).append( badge );
82
+ this.hasBadge = true;
83
+ },
84
+
85
+ enable() {
86
+ if ( ! this.controller.isModeActive( 'watermark' ) && ! this.controller.isModeActive( 'processing' ) ) {
87
+ this.$el.removeClass( 'disabled' ).find( '.badge' ).remove();
88
+ this.hasBadge = false;
89
+ }
90
+ },
91
+
92
+ wasSelected() {
93
+ const selection = this.controller.state().get( 'originalSelection' );
94
+
95
+ if ( selection ) {
96
+ return !! selection.get( this.model.cid );
97
+ }
98
+ },
99
+ } );
100
+ }
assets/src/scripts/views/media-grid/attachments-browser.js CHANGED
@@ -1,89 +1,89 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import WatermarkButton from './buttons/watermark.js';
5
- import RestoreButton from './buttons/restore.js';
6
- import WatermarkModeToggleButton from './buttons/watermark-mode-toggle.js';
7
- import WatermarkSelector from './watermark-selector.js';
8
- import Status from './status.js';
9
-
10
- /* global wp, ew */
11
-
12
- if ( wp.media && 'function' === typeof wp.media.view.AttachmentsBrowser ) {
13
- wp.media.view.AttachmentsBrowser = class extends wp.media.view.AttachmentsBrowser {
14
- createToolbar() {
15
- super.createToolbar();
16
-
17
- if ( ! this.controller.state().get( 'ewStatus' ) ) {
18
- /**
19
- * If there is no 'ewStatus' in controller, Media Library has been
20
- * obviously replaced by some plugin (and not extended, as we do in EW).
21
- * This is the case with Enhanced Media Library plugin.
22
- *
23
- * In this situation our modifications are not present in controller,
24
- * so our views loaded below might cause errors.
25
- */
26
- return;
27
- }
28
-
29
- if ( Object.keys( ew.watermarks ).length ) {
30
- this.toolbar.set( 'watermarkModeToggleButton', new WatermarkModeToggleButton( {
31
- text: ew.i18n.watermarkModeToggleButtonLabel,
32
- cancelText: ew.i18n.cancelLabel,
33
- controller: this.controller,
34
- priority: -60,
35
- } ).render() );
36
-
37
- this.toolbar.set( 'watermarkSelector', new WatermarkSelector( {
38
- controller: this.controller,
39
- priority: -50,
40
- } ).render() );
41
-
42
- this.toolbar.set( 'watermarkButton', new WatermarkButton( {
43
- text: ew.i18n.watermarkButtonLabel,
44
- style: 'primary',
45
- controller: this.controller,
46
- priority: -40,
47
- } ).render() );
48
- }
49
-
50
- this.toolbar.set( 'restoreButton', new RestoreButton( {
51
- text: ew.i18n.restoreButtonLabel,
52
- controller: this.controller,
53
- priority: -30,
54
- } ).render() );
55
-
56
- this.toolbar.set( 'watermarkingStatus', new Status( {
57
- style: 'primary',
58
- controller: this.controller,
59
- priority: -20,
60
- } ).render() );
61
-
62
- this.controller.on( 'select:deactivate', () => this.controller.deactivateMode( 'watermark' ) );
63
- this.controller.on( 'watermark:activate', this.hideButtons, this );
64
- this.controller.on( 'watermark:deactivate', this.showButtons, this );
65
- this.controller.on( 'processing:activate processing:deactivate', this.disableViewSwitch, this );
66
- }
67
-
68
- hideButtons() {
69
- this.$( '.select-mode-toggle-button' ).addClass( 'hidden' );
70
- this.$( '.delete-selected-button' ).addClass( 'hidden' );
71
- }
72
-
73
- showButtons() {
74
- this.$el.html( this.model.get( 'text' ) );
75
- this.$( '.select-mode-toggle-button' ).removeClass( 'hidden' );
76
- this.$( '.delete-selected-button' ).removeClass( 'hidden' );
77
- }
78
-
79
- disableViewSwitch() {
80
- const viewSwitch = this.toolbar.$( '.view-switch' );
81
-
82
- if ( viewSwitch.hasClass( 'disabled' ) ) {
83
- viewSwitch.removeClass( 'disabled' );
84
- } else {
85
- viewSwitch.addClass( 'disabled' );
86
- }
87
- }
88
- };
89
- }
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import WatermarkButton from './buttons/watermark.js';
5
+ import RestoreButton from './buttons/restore.js';
6
+ import WatermarkModeToggleButton from './buttons/watermark-mode-toggle.js';
7
+ import WatermarkSelector from './watermark-selector.js';
8
+ import Status from './status.js';
9
+
10
+ /* global wp, ew */
11
+
12
+ if ( wp.media && 'function' === typeof wp.media.view.AttachmentsBrowser ) {
13
+ wp.media.view.AttachmentsBrowser = class extends wp.media.view.AttachmentsBrowser {
14
+ createToolbar() {
15
+ super.createToolbar();
16
+
17
+ if ( ! this.controller.state().get( 'ewStatus' ) ) {
18
+ /**
19
+ * If there is no 'ewStatus' in controller, Media Library has been
20
+ * obviously replaced by some plugin (and not extended, as we do in EW).
21
+ * This is the case with Enhanced Media Library plugin.
22
+ *
23
+ * In this situation our modifications are not present in controller,
24
+ * so our views loaded below might cause errors.
25
+ */
26
+ return;
27
+ }
28
+
29
+ if ( Object.keys( ew.watermarks ).length ) {
30
+ this.toolbar.set( 'watermarkModeToggleButton', new WatermarkModeToggleButton( {
31
+ text: ew.i18n.watermarkModeToggleButtonLabel,
32
+ cancelText: ew.i18n.cancelLabel,
33
+ controller: this.controller,
34
+ priority: -60,
35
+ } ).render() );
36
+
37
+ this.toolbar.set( 'watermarkSelector', new WatermarkSelector( {
38
+ controller: this.controller,
39
+ priority: -50,
40
+ } ).render() );
41
+
42
+ this.toolbar.set( 'watermarkButton', new WatermarkButton( {
43
+ text: ew.i18n.watermarkButtonLabel,
44
+ style: 'primary',
45
+ controller: this.controller,
46
+ priority: -40,
47
+ } ).render() );
48
+ }
49
+
50
+ this.toolbar.set( 'restoreButton', new RestoreButton( {
51
+ text: ew.i18n.restoreButtonLabel,
52
+ controller: this.controller,
53
+ priority: -30,
54
+ } ).render() );
55
+
56
+ this.toolbar.set( 'watermarkingStatus', new Status( {
57
+ style: 'primary',
58
+ controller: this.controller,
59
+ priority: -20,
60
+ } ).render() );
61
+
62
+ this.controller.on( 'select:deactivate', () => this.controller.deactivateMode( 'watermark' ) );
63
+ this.controller.on( 'watermark:activate', this.hideButtons, this );
64
+ this.controller.on( 'watermark:deactivate', this.showButtons, this );
65
+ this.controller.on( 'processing:activate processing:deactivate', this.disableViewSwitch, this );
66
+ }
67
+
68
+ hideButtons() {
69
+ this.$( '.select-mode-toggle-button' ).addClass( 'hidden' );
70
+ this.$( '.delete-selected-button' ).addClass( 'hidden' );
71
+ }
72
+
73
+ showButtons() {
74
+ this.$el.html( this.model.get( 'text' ) );
75
+ this.$( '.select-mode-toggle-button' ).removeClass( 'hidden' );
76
+ this.$( '.delete-selected-button' ).removeClass( 'hidden' );
77
+ }
78
+
79
+ disableViewSwitch() {
80
+ const viewSwitch = this.toolbar.$( '.view-switch' );
81
+
82
+ if ( viewSwitch.hasClass( 'disabled' ) ) {
83
+ viewSwitch.removeClass( 'disabled' );
84
+ } else {
85
+ viewSwitch.addClass( 'disabled' );
86
+ }
87
+ }
88
+ };
89
+ }
assets/src/scripts/views/media-grid/buttons/restore.js CHANGED
@@ -1,66 +1,66 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import { filterSelection } from '../../../utils/functions';
5
-
6
- /* global wp */
7
-
8
- let RestoreButton = null;
9
-
10
- if ( wp.media && 'function' === typeof wp.media.view.Button ) {
11
- RestoreButton = class extends wp.media.view.Button {
12
- initialize() {
13
- super.initialize();
14
-
15
- this.model.set( {
16
- originalText: this.model.get( 'text' ),
17
- } );
18
-
19
- this.controller.on( 'selection:toggle', this.update, this );
20
-
21
- this.controller.on( 'watermark:activate watermark:deactivate', this.render, this );
22
- this.controller.on( 'select:activate select:deactivate', this.render, this );
23
- }
24
-
25
- render() {
26
- super.render();
27
-
28
- if ( this.controller.isModeActive( 'select' ) && ! this.controller.isModeActive( 'watermark' ) ) {
29
- this.$el.addClass( 'restore-button' );
30
- } else {
31
- this.$el.addClass( 'restore-button hidden' );
32
- }
33
-
34
- this.update();
35
-
36
- return this;
37
- }
38
-
39
- click() {
40
- super.click();
41
-
42
- if ( ! this.controller.isModeActive( 'select' ) ) {
43
- return;
44
- }
45
-
46
- this.controller.ewRestoreBackup();
47
- }
48
-
49
- update() {
50
- const
51
- lastSelectionCount = this.model.get( 'filteredSelectionCount' ),
52
- filteredSelectionCount = filterSelection( this.controller.state().get( 'selection' ), true, false );
53
-
54
- if ( filteredSelectionCount !== lastSelectionCount ) {
55
- this.model.set( {
56
- filteredSelectionCount,
57
- text: `${ this.model.get( 'originalText' ) } (${ filteredSelectionCount })`,
58
- } );
59
-
60
- this.model.set( 'disabled', ! Boolean( filteredSelectionCount ) );
61
- }
62
- }
63
- };
64
- }
65
-
66
- export default RestoreButton;
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import { filterSelection } from '../../../utils/functions';
5
+
6
+ /* global wp */
7
+
8
+ let RestoreButton = null;
9
+
10
+ if ( wp.media && 'function' === typeof wp.media.view.Button ) {
11
+ RestoreButton = class extends wp.media.view.Button {
12
+ initialize() {
13
+ super.initialize();
14
+
15
+ this.model.set( {
16
+ originalText: this.model.get( 'text' ),
17
+ } );
18
+
19
+ this.controller.on( 'selection:toggle', this.update, this );
20
+
21
+ this.controller.on( 'watermark:activate watermark:deactivate', this.render, this );
22
+ this.controller.on( 'select:activate select:deactivate', this.render, this );
23
+ }
24
+
25
+ render() {
26
+ super.render();
27
+
28
+ if ( this.controller.isModeActive( 'select' ) && ! this.controller.isModeActive( 'watermark' ) ) {
29
+ this.$el.addClass( 'restore-button' );
30
+ } else {
31
+ this.$el.addClass( 'restore-button hidden' );
32
+ }
33
+
34
+ this.update();
35
+
36
+ return this;
37
+ }
38
+
39
+ click() {
40
+ super.click();
41
+
42
+ if ( ! this.controller.isModeActive( 'select' ) ) {
43
+ return;
44
+ }
45
+
46
+ this.controller.ewRestoreBackup();
47
+ }
48
+
49
+ update() {
50
+ const
51
+ lastSelectionCount = this.model.get( 'filteredSelectionCount' ),
52
+ filteredSelectionCount = filterSelection( this.controller.state().get( 'selection' ), true, false );
53
+
54
+ if ( filteredSelectionCount !== lastSelectionCount ) {
55
+ this.model.set( {
56
+ filteredSelectionCount,
57
+ text: `${ this.model.get( 'originalText' ) } (${ filteredSelectionCount })`,
58
+ } );
59
+
60
+ this.model.set( 'disabled', ! Boolean( filteredSelectionCount ) );
61
+ }
62
+ }
63
+ };
64
+ }
65
+
66
+ export default RestoreButton;
assets/src/scripts/views/media-grid/buttons/watermark-mode-toggle.js CHANGED
@@ -1,79 +1,79 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import { filterSelection } from '../../../utils/functions';
5
-
6
- /* global wp */
7
-
8
- let WatermarkModeExport = null;
9
-
10
- if ( wp.media && 'function' === typeof wp.media.view.Button ) {
11
- class WatermarkModeButton extends wp.media.view.Button {
12
- initialize() {
13
- super.initialize();
14
-
15
- this.model.set( {
16
- originalText: this.model.get( 'text' ),
17
- cancelText: this.options.cancelText,
18
- } );
19
- delete this.options.cancelText;
20
-
21
- this.controller.on( 'selection:toggle', this.update, this );
22
- this.controller.on( 'watermark:activate', () => this.$el.html( this.model.get( 'cancelText' ) ) );
23
- this.controller.on( 'watermark:deactivate', this.update, this );
24
- }
25
-
26
- render() {
27
- super.render();
28
-
29
- if ( this.controller.isModeActive( 'select' ) ) {
30
- this.$el.addClass( 'watermark-mode-toggle-button' );
31
- } else {
32
- this.$el.addClass( 'watermark-mode-toggle-button hidden' );
33
- }
34
-
35
- this.update();
36
-
37
- return this;
38
- }
39
-
40
- click() {
41
- super.click();
42
-
43
- if ( this.controller.isModeActive( 'watermark' ) ) {
44
- this.controller.deactivateMode( 'watermark' );
45
- } else {
46
- this.controller.activateMode( 'watermark' );
47
-
48
- filterSelection( this.controller.state().get( 'selection' ) );
49
- }
50
- }
51
-
52
- update() {
53
- if ( this.controller.isModeActive( 'watermark' ) ) {
54
- return;
55
- }
56
-
57
- const
58
- lastSelectionCount = this.model.get( 'filteredSelectionCount' ),
59
- filteredSelectionCount = filterSelection( this.controller.state().get( 'selection' ), false, false );
60
-
61
- if ( filteredSelectionCount !== lastSelectionCount ) {
62
- this.model.set( {
63
- filteredSelectionCount,
64
- text: `${ this.model.get( 'originalText' ) } (${ filteredSelectionCount })`,
65
- } );
66
-
67
- this.model.set( 'disabled', ! Boolean( filteredSelectionCount ) );
68
-
69
- if ( ! this.controller.state().get( 'selection' ).length ) {
70
- this.controller.deactivateMode( 'watermark' );
71
- }
72
- }
73
- }
74
- }
75
-
76
- WatermarkModeExport = WatermarkModeButton;
77
- }
78
-
79
- export default WatermarkModeExport;
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import { filterSelection } from '../../../utils/functions';
5
+
6
+ /* global wp */
7
+
8
+ let WatermarkModeExport = null;
9
+
10
+ if ( wp.media && 'function' === typeof wp.media.view.Button ) {
11
+ class WatermarkModeButton extends wp.media.view.Button {
12
+ initialize() {
13
+ super.initialize();
14
+
15
+ this.model.set( {
16
+ originalText: this.model.get( 'text' ),
17
+ cancelText: this.options.cancelText,
18
+ } );
19
+ delete this.options.cancelText;
20
+
21
+ this.controller.on( 'selection:toggle', this.update, this );
22
+ this.controller.on( 'watermark:activate', () => this.$el.html( this.model.get( 'cancelText' ) ) );
23
+ this.controller.on( 'watermark:deactivate', this.update, this );
24
+ }
25
+
26
+ render() {
27
+ super.render();
28
+
29
+ if ( this.controller.isModeActive( 'select' ) ) {
30
+ this.$el.addClass( 'watermark-mode-toggle-button' );
31
+ } else {
32
+ this.$el.addClass( 'watermark-mode-toggle-button hidden' );
33
+ }
34
+
35
+ this.update();
36
+
37
+ return this;
38
+ }
39
+
40
+ click() {
41
+ super.click();
42
+
43
+ if ( this.controller.isModeActive( 'watermark' ) ) {
44
+ this.controller.deactivateMode( 'watermark' );
45
+ } else {
46
+ this.controller.activateMode( 'watermark' );
47
+
48
+ filterSelection( this.controller.state().get( 'selection' ) );
49
+ }
50
+ }
51
+
52
+ update() {
53
+ if ( this.controller.isModeActive( 'watermark' ) ) {
54
+ return;
55
+ }
56
+
57
+ const
58
+ lastSelectionCount = this.model.get( 'filteredSelectionCount' ),
59
+ filteredSelectionCount = filterSelection( this.controller.state().get( 'selection' ), false, false );
60
+
61
+ if ( filteredSelectionCount !== lastSelectionCount ) {
62
+ this.model.set( {
63
+ filteredSelectionCount,
64
+ text: `${ this.model.get( 'originalText' ) } (${ filteredSelectionCount })`,
65
+ } );
66
+
67
+ this.model.set( 'disabled', ! Boolean( filteredSelectionCount ) );
68
+
69
+ if ( ! this.controller.state().get( 'selection' ).length ) {
70
+ this.controller.deactivateMode( 'watermark' );
71
+ }
72
+ }
73
+ }
74
+ }
75
+
76
+ WatermarkModeExport = WatermarkModeButton;
77
+ }
78
+
79
+ export default WatermarkModeExport;
assets/src/scripts/views/media-grid/buttons/watermark.js CHANGED
@@ -1,51 +1,51 @@
1
- /* global wp */
2
-
3
- let WatermarkButton = null;
4
-
5
- if ( wp.media && 'function' === typeof wp.media.view.Button ) {
6
- WatermarkButton = class extends wp.media.view.Button {
7
- initialize() {
8
- super.initialize();
9
-
10
- this.controller.on( 'watermark:activate', () => {
11
- this.$el.removeClass( 'hidden' ).show();
12
- } );
13
-
14
- this.controller.on( 'watermark:deactivate', () => {
15
- this.$el.addClass( 'hidden' ).hide();
16
- } );
17
-
18
- this.controller.on( 'watermark:selected', this.toggleDisabled, this );
19
-
20
- this.model.set( 'disabled', true );
21
- }
22
-
23
- render() {
24
- super.render();
25
-
26
- if ( this.controller.isModeActive( 'watermark' ) ) {
27
- this.$el.addClass( 'watermark-button' );
28
- } else {
29
- this.$el.addClass( 'watermark-button hidden' );
30
- }
31
-
32
- return this;
33
- }
34
-
35
- click() {
36
- super.click();
37
-
38
- if ( ! this.controller.state().get( 'watermark' ) ) {
39
- return;
40
- }
41
-
42
- this.controller.ewWatermark();
43
- }
44
-
45
- toggleDisabled( watermark ) {
46
- this.model.set( 'disabled', ! watermark.length );
47
- }
48
- };
49
- }
50
-
51
- export default WatermarkButton;
1
+ /* global wp */
2
+
3
+ let WatermarkButton = null;
4
+
5
+ if ( wp.media && 'function' === typeof wp.media.view.Button ) {
6
+ WatermarkButton = class extends wp.media.view.Button {
7
+ initialize() {
8
+ super.initialize();
9
+
10
+ this.controller.on( 'watermark:activate', () => {
11
+ this.$el.removeClass( 'hidden' ).show();
12
+ } );
13
+
14
+ this.controller.on( 'watermark:deactivate', () => {
15
+ this.$el.addClass( 'hidden' ).hide();
16
+ } );
17
+
18
+ this.controller.on( 'watermark:selected', this.toggleDisabled, this );
19
+
20
+ this.model.set( 'disabled', true );
21
+ }
22
+
23
+ render() {
24
+ super.render();
25
+
26
+ if ( this.controller.isModeActive( 'watermark' ) ) {
27
+ this.$el.addClass( 'watermark-button' );
28
+ } else {
29
+ this.$el.addClass( 'watermark-button hidden' );
30
+ }
31
+
32
+ return this;
33
+ }
34
+
35
+ click() {
36
+ super.click();
37
+
38
+ if ( ! this.controller.state().get( 'watermark' ) ) {
39
+ return;
40
+ }
41
+
42
+ this.controller.ewWatermark();
43
+ }
44
+
45
+ toggleDisabled( watermark ) {
46
+ this.model.set( 'disabled', ! watermark.length );
47
+ }
48
+ };
49
+ }
50
+
51
+ export default WatermarkButton;
assets/src/scripts/views/media-grid/filters.js CHANGED
@@ -1,45 +1,45 @@
1
- /* global wp */
2
-
3
- if ( wp.media ) {
4
- if ( 'function' === typeof wp.media.view.AttachmentFilters.All ) {
5
- wp.media.view.AttachmentFilters.All = class extends wp.media.view.AttachmentFilters.All {
6
- initialize() {
7
- super.initialize();
8
-
9
- this.controller.on( 'processing:activate processing:deactivate', this.toggleDisabled, this );
10
- }
11
-
12
- toggleDisabled() {
13
- this.$el.prop( 'disabled', ! this.$el.is( ':disabled' ) );
14
- }
15
- };
16
- }
17
-
18
- if ( 'function' === typeof wp.media.view.AttachmentFilters.Uploaded ) {
19
- wp.media.view.AttachmentFilters.Uploaded = class extends wp.media.view.AttachmentFilters.Uploaded {
20
- initialize() {
21
- super.initialize();
22
-
23
- this.controller.on( 'processing:activate processing:deactivate', this.toggleDisabled, this );
24
- }
25
-
26
- toggleDisabled() {
27
- this.$el.prop( 'disabled', ! this.$el.is( ':disabled' ) );
28
- }
29
- };
30
- }
31
-
32
- if ( 'function' === typeof wp.media.view.DateFilter ) {
33
- wp.media.view.DateFilter = class extends wp.media.view.DateFilter {
34
- initialize() {
35
- super.initialize();
36
-
37
- this.controller.on( 'processing:activate processing:deactivate', this.toggleDisabled, this );
38
- }
39
-
40
- toggleDisabled() {
41
- this.$el.prop( 'disabled', ! this.$el.is( ':disabled' ) );
42
- }
43
- };
44
- }
45
- }
1
+ /* global wp */
2
+
3
+ if ( wp.media ) {
4
+ if ( 'function' === typeof wp.media.view.AttachmentFilters.All ) {
5
+ wp.media.view.AttachmentFilters.All = class extends wp.media.view.AttachmentFilters.All {
6
+ initialize() {
7
+ super.initialize();
8
+
9
+ this.controller.on( 'processing:activate processing:deactivate', this.toggleDisabled, this );
10
+ }
11
+
12
+ toggleDisabled() {
13
+ this.$el.prop( 'disabled', ! this.$el.is( ':disabled' ) );
14
+ }
15
+ };
16
+ }
17
+
18
+ if ( 'function' === typeof wp.media.view.AttachmentFilters.Uploaded ) {
19
+ wp.media.view.AttachmentFilters.Uploaded = class extends wp.media.view.AttachmentFilters.Uploaded {
20
+ initialize() {
21
+ super.initialize();
22
+
23
+ this.controller.on( 'processing:activate processing:deactivate', this.toggleDisabled, this );
24
+ }
25
+
26
+ toggleDisabled() {
27
+ this.$el.prop( 'disabled', ! this.$el.is( ':disabled' ) );
28
+ }
29
+ };
30
+ }
31
+
32
+ if ( 'function' === typeof wp.media.view.DateFilter ) {
33
+ wp.media.view.DateFilter = class extends wp.media.view.DateFilter {
34
+ initialize() {
35
+ super.initialize();
36
+
37
+ this.controller.on( 'processing:activate processing:deactivate', this.toggleDisabled, this );
38
+ }
39
+
40
+ toggleDisabled() {
41
+ this.$el.prop( 'disabled', ! this.$el.is( ':disabled' ) );
42
+ }
43
+ };
44
+ }
45
+ }
assets/src/scripts/views/media-grid/select-mode-toggle.js CHANGED
@@ -1,32 +1,32 @@
1
- /* global wp */
2
-
3
- if ( wp.media && 'function' === typeof wp.media.view.SelectModeToggleButton ) {
4
- wp.media.view.SelectModeToggleButton = class extends wp.media.view.SelectModeToggleButton {
5
- initialize() {
6
- super.initialize();
7
-
8
- this.controller.on( 'processing:activate processing:deactivate', this.toggleDisabled, this );
9
- }
10
-
11
- toggleDisabled() {
12
- this.model.set( 'disabled', this.controller.isModeActive( 'processing' ) );
13
- }
14
-
15
- toggleBulkEditHandler() {
16
- super.toggleBulkEditHandler();
17
-
18
- this.controller.trigger( 'selection:toggle' );
19
-
20
- const toolbar = this.controller.content.get().toolbar;
21
-
22
- if ( this.controller.isModeActive( 'select' ) ) {
23
- toolbar.$( '.watermark-mode-toggle-button' ).removeClass( 'hidden' );
24
- } else {
25
- toolbar.$( '.watermark-mode-toggle-button' ).addClass( 'hidden' );
26
- }
27
-
28
- toolbar.$( '.watermark-selector' ).css( 'display', '' );
29
- toolbar.$( '.ew-status' ).css( 'display', '' );
30
- }
31
- };
32
- }
1
+ /* global wp */
2
+
3
+ if ( wp.media && 'function' === typeof wp.media.view.SelectModeToggleButton ) {
4
+ wp.media.view.SelectModeToggleButton = class extends wp.media.view.SelectModeToggleButton {
5
+ initialize() {
6
+ super.initialize();
7
+
8
+ this.controller.on( 'processing:activate processing:deactivate', this.toggleDisabled, this );
9
+ }
10
+
11
+ toggleDisabled() {
12
+ this.model.set( 'disabled', this.controller.isModeActive( 'processing' ) );
13
+ }
14
+
15
+ toggleBulkEditHandler() {
16
+ super.toggleBulkEditHandler();
17
+
18
+ this.controller.trigger( 'selection:toggle' );
19
+
20
+ const toolbar = this.controller.content.get().toolbar;
21
+
22
+ if ( this.controller.isModeActive( 'select' ) ) {
23
+ toolbar.$( '.watermark-mode-toggle-button' ).removeClass( 'hidden' );
24
+ } else {
25
+ toolbar.$( '.watermark-mode-toggle-button' ).addClass( 'hidden' );
26
+ }
27
+
28
+ toolbar.$( '.watermark-selector' ).css( 'display', '' );
29
+ toolbar.$( '.ew-status' ).css( 'display', '' );
30
+ }
31
+ };
32
+ }
assets/src/scripts/views/media-grid/status.js CHANGED
@@ -1,66 +1,66 @@
1
- /* global wp */
2
-
3
- let StatusExport = null;
4
-
5
- if ( wp.media && 'function' === typeof wp.media.View ) {
6
- class Status extends wp.media.View {
7
- tagName() {
8
- return 'p';
9
- }
10
-
11
- className() {
12
- return 'ew-status';
13
- }
14
-
15
- template() {
16
- let statusText = this.status.get( 'text' );
17
-
18
- if ( this.status.get( 'progress' ) ) {
19
- const
20
- processed = this.status.get( 'processed' ),
21
- total = this.status.get( 'total' ),
22
- counter = `${ processed }/${ total }`,
23
- percent = Math.floor( processed / total * 100 );
24
-
25
- if ( 'string' === typeof status ) {
26
- statusText = statusText.replace( '{counter}', counter );
27
- }
28
-
29
- statusText += ` (${ percent }%)`;
30
- }
31
-
32
- return `<span class="status">${ statusText }</span>`;
33
- }
34
-
35
- constructor( options ) {
36
- super( options );
37
-
38
- this.status = this.controller.state().get( 'ewStatus' );
39
- this.status.on( 'change', this.update, this );
40
- }
41
-
42
- render() {
43
- this.update();
44
-
45
- return this;
46
- }
47
-
48
- update() {
49
- if ( ! this.status.get( 'visible' ) ) {
50
- this.$el.addClass( 'hidden' );
51
- return;
52
- }
53
-
54
- this.$el.removeClass( 'hidden' ).html( this.template() );
55
- }
56
-
57
- cancel( e ) {
58
- e.preventDefault();
59
- this.controller.deactivateMode( 'watermarking' );
60
- }
61
- }
62
-
63
- StatusExport = Status;
64
- }
65
-
66
- export default StatusExport;
1
+ /* global wp */
2
+
3
+ let StatusExport = null;
4
+
5
+ if ( wp.media && 'function' === typeof wp.media.View ) {
6
+ class Status extends wp.media.View {
7
+ tagName() {
8
+ return 'p';
9
+ }
10
+
11
+ className() {
12
+ return 'ew-status';
13
+ }
14
+
15
+ template() {
16
+ let statusText = this.status.get( 'text' );
17
+
18
+ if ( this.status.get( 'progress' ) ) {
19
+ const
20
+ processed = this.status.get( 'processed' ),
21
+ total = this.status.get( 'total' ),
22
+ counter = `${ processed }/${ total }`,
23
+ percent = Math.floor( processed / total * 100 );
24
+
25
+ if ( 'string' === typeof status ) {
26
+ statusText = statusText.replace( '{counter}', counter );
27
+ }
28
+
29
+ statusText += ` (${ percent }%)`;
30
+ }
31
+
32
+ return `<span class="status">${ statusText }</span>`;
33
+ }
34
+
35
+ constructor( options ) {
36
+ super( options );
37
+
38
+ this.status = this.controller.state().get( 'ewStatus' );
39
+ this.status.on( 'change', this.update, this );
40
+ }
41
+
42
+ render() {
43
+ this.update();
44
+
45
+ return this;
46
+ }
47
+
48
+ update() {
49
+ if ( ! this.status.get( 'visible' ) ) {
50
+ this.$el.addClass( 'hidden' );
51
+ return;
52
+ }
53
+
54
+ this.$el.removeClass( 'hidden' ).html( this.template() );
55
+ }
56
+
57
+ cancel( e ) {
58
+ e.preventDefault();
59
+ this.controller.deactivateMode( 'watermarking' );
60
+ }
61
+ }
62
+
63
+ StatusExport = Status;
64
+ }
65
+
66
+ export default StatusExport;
assets/src/scripts/views/media-grid/watermark-selector.js CHANGED
@@ -1,70 +1,70 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
-
6
- /* global wp, ew */
7
-
8
- let WatermarkSelectorExport = null;
9
-
10
- if ( wp.media && 'function' === typeof wp.media.View ) {
11
- class WatermarkSelector extends wp.media.View {
12
- constructor( options ) {
13
- super( options );
14
-
15
- this.controller.on( 'watermark:activate', this.show, this );
16
- this.controller.on( 'watermark:deactivate', this.hide, this );
17
- }
18
-
19
- events() {
20
- return {
21
- change: 'selectWatermark',
22
- };
23
- }
24
-
25
- tagName() {
26
- return 'select';
27
- }
28
-
29
- selectWatermark() {
30
- this.controller.trigger( 'watermark:selected', this.$el.val() );
31
- this.controller.state().set( 'watermark', this.$el.val() );
32
- }
33
-
34
- show() {
35
- this.$el.removeClass( 'hidden' );
36
- }
37
-
38
- hide() {
39
- this.$el.addClass( 'hidden' );
40
- }
41
-
42
- render() {
43
- super.render();
44
-
45
- this.$el.append( $( '<option>', { value: '' } ).html( ew.i18n.selectWatermarkLabel ) );
46
-
47
- if ( ew.watermarks ) {
48
- if ( 1 < Object.keys( ew.watermarks ).length ) {
49
- this.$el.append( $( '<option>', { value: 'all' } ).html( ew.i18n.allWatermarksLabel ) );
50
- }
51
-
52
- for ( const id in ew.watermarks ) { // eslint-disable-line no-unused-vars
53
- this.$el.append( $( '<option>', { value: id } ).html( ew.watermarks[ id ] ) );
54
- }
55
- }
56
-
57
- if ( this.controller.isModeActive( 'select' ) ) {
58
- this.$el.addClass( 'watermark-selector' );
59
- } else {
60
- this.$el.addClass( 'watermark-selector hidden' );
61
- }
62
-
63
- return this;
64
- }
65
- }
66
-
67
- WatermarkSelectorExport = WatermarkSelector;
68
- }
69
-
70
- export default WatermarkSelectorExport;
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import $ from 'jquery';
5
+
6
+ /* global wp, ew */
7
+
8
+ let WatermarkSelectorExport = null;
9
+
10
+ if ( wp.media && 'function' === typeof wp.media.View ) {
11
+ class WatermarkSelector extends wp.media.View {
12
+ constructor( options ) {
13
+ super( options );
14
+
15
+ this.controller.on( 'watermark:activate', this.show, this );
16
+ this.controller.on( 'watermark:deactivate', this.hide, this );
17
+ }
18
+
19
+ events() {
20
+ return {
21
+ change: 'selectWatermark',
22
+ };
23
+ }
24
+
25
+ tagName() {
26
+ return 'select';
27
+ }
28
+
29
+ selectWatermark() {
30
+ this.controller.trigger( 'watermark:selected', this.$el.val() );
31
+ this.controller.state().set( 'watermark', this.$el.val() );
32
+ }
33
+
34
+ show() {
35
+ this.$el.removeClass( 'hidden' );
36
+ }
37
+
38
+ hide() {
39
+ this.$el.addClass( 'hidden' );
40
+ }
41
+
42
+ render() {
43
+ super.render();
44
+
45
+ this.$el.append( $( '<option>', { value: '' } ).html( ew.i18n.selectWatermarkLabel ) );
46
+
47
+ if ( ew.watermarks ) {
48
+ if ( 1 < Object.keys( ew.watermarks ).length ) {
49
+ this.$el.append( $( '<option>', { value: 'all' } ).html( ew.i18n.allWatermarksLabel ) );
50
+ }
51
+
52
+ for ( const id in ew.watermarks ) { // eslint-disable-line no-unused-vars
53
+ this.$el.append( $( '<option>', { value: id } ).html( ew.watermarks[ id ] ) );
54
+ }
55
+ }
56
+
57
+ if ( this.controller.isModeActive( 'select' ) ) {
58
+ this.$el.addClass( 'watermark-selector' );
59
+ } else {
60
+ this.$el.addClass( 'watermark-selector hidden' );
61
+ }
62
+
63
+ return this;
64
+ }
65
+ }
66
+
67
+ WatermarkSelectorExport = WatermarkSelector;
68
+ }
69
+
70
+ export default WatermarkSelectorExport;
assets/src/scripts/views/media-list/attachment.js CHANGED
@@ -1,76 +1,76 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import View from './view';
5
- import { isImage } from '../../utils/functions.js';
6
-
7
- /**
8
- * External dependencies
9
- */
10
- import $ from 'jquery';
11
-
12
- /* global ew */
13
-
14
- export default class extends View {
15
- constructor( options ) {
16
- super( options );
17
-
18
- this.model = options.model;
19
-
20
- this.listenTo( this.model, 'processing:start', this.showSpinner );
21
- this.listenTo( this.model, 'processing:done', this.reset );
22
- this.listenTo( this.model, 'remove', this.deselect );
23
-
24
- this.controller.on( 'bulkAction:finished', this.reset, this );
25
- }
26
-
27
- showSpinner() {
28
- this.getSpinner().appendTo( this.$el.find( 'span.media-icon' ) );
29
- }
30
-
31
- getSpinner() {
32
- if ( ! this.spinner ) {
33
- this.spinner = $( '<span>', { class: 'spinner ew-spinner' } );
34
- }
35
-
36
- return this.spinner;
37
- }
38
-
39
- reset() {
40
- if ( this.spinner ) {
41
- this.spinner.remove();
42
- }
43
-
44
- this.getStatus().text( '' );
45
- this.$el.find( 'input[type="checkbox"]' ).click().prop( 'checked', false );
46
- }
47
-
48
- deselect() {
49
- if ( this.controller.status().get( 'processing' ) ) {
50
- return;
51
- }
52
-
53
- this.$el.find( 'input[type="checkbox"]' ).click().prop( 'checked', false );
54
-
55
- let text;
56
-
57
- if ( ! isImage( this.model ) ) {
58
- text = ew.i18n.notSupported;
59
- } else if ( this.model.get( 'usedAsWatermark' ) ) {
60
- text = ew.i18n.usedAsWatermark;
61
- } else if ( 'restore' === this.controller.get( 'action' ) && ! this.model.get( 'hasBackup' ) ) {
62
- text = ew.i18n.noBackupAvailable;
63
- }
64
-
65
- this.getStatus().text( ` - ${ text }` );
66
- }
67
-
68
- getStatus() {
69
- if ( ! this.status ) {
70
- this.status = $( '<span>', { class: 'ew-status' } );
71
- this.$el.find( 'strong.has-media-icon' ).append( this.status );
72
- }
73
-
74
- return this.status;
75
- }
76
- }
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import View from './view';
5
+ import { isImage } from '../../utils/functions.js';
6
+
7
+ /**
8
+ * External dependencies
9
+ */
10
+ import $ from 'jquery';
11
+
12
+ /* global ew */
13
+
14
+ export default class extends View {
15
+ constructor( options ) {
16
+ super( options );
17
+
18
+ this.model = options.model;
19
+
20
+ this.listenTo( this.model, 'processing:start', this.showSpinner );
21
+ this.listenTo( this.model, 'processing:done', this.reset );
22
+ this.listenTo( this.model, 'remove', this.deselect );
23
+
24
+ this.controller.on( 'bulkAction:finished', this.reset, this );
25
+ }
26
+
27
+ showSpinner() {
28
+ this.getSpinner().appendTo( this.$el.find( 'span.media-icon' ) );
29
+ }
30
+
31
+ getSpinner() {
32
+ if ( ! this.spinner ) {
33
+ this.spinner = $( '<span>', { class: 'spinner ew-spinner' } );
34
+ }
35
+
36
+ return this.spinner;
37
+ }
38
+
39
+ reset() {
40
+ if ( this.spinner ) {
41
+ this.spinner.remove();
42
+ }
43
+
44
+ this.getStatus().text( '' );
45
+ this.$el.find( 'input[type="checkbox"]' ).click().prop( 'checked', false );
46
+ }
47
+
48
+ deselect() {
49
+ if ( this.controller.status().get( 'processing' ) ) {
50
+ return;
51
+ }
52
+
53
+ this.$el.find( 'input[type="checkbox"]' ).click().prop( 'checked', false );
54
+
55
+ let text;
56
+
57
+ if ( ! isImage( this.model ) ) {
58
+ text = ew.i18n.notSupported;
59
+ } else if ( this.model.get( 'usedAsWatermark' ) ) {
60
+ text = ew.i18n.usedAsWatermark;
61
+ } else if ( 'restore' === this.controller.get( 'action' ) && ! this.model.get( 'hasBackup' ) ) {
62
+ text = ew.i18n.noBackupAvailable;
63
+ }
64
+
65
+ this.getStatus().text( ` - ${ text }` );
66
+ }
67
+
68
+ getStatus() {
69
+ if ( ! this.status ) {
70
+ this.status = $( '<span>', { class: 'ew-status' } );
71
+ this.$el.find( 'strong.has-media-icon' ).append( this.status );
72
+ }
73
+
74
+ return this.status;
75
+ }
76
+ }
assets/src/scripts/views/media-list/watermark-selector.js CHANGED
@@ -1,79 +1,79 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import View from './view';
10
-
11
- /* global ew */
12
-
13
- export default class extends View {
14
- tagName() {
15
- return 'select';
16
- }
17
-
18
- className() {
19
- return 'ew-status';
20
- }
21
-
22
- events() {
23
- return {
24
- change: 'selectWatermark',
25
- };
26
- }
27
-
28
- constructor( options ) {
29
- super( options );
30
-
31
- this.listenTo( this.controller, 'change', this.update );
32
- this.listenTo( this.controller, 'bulkAction:start', this.reset );
33
- }
34
-
35
- render() {
36
- super.render();
37
-
38
- this.$el.append( $( '<option>', { value: '' } ).html( ew.i18n.selectWatermarkLabel ) );
39
-
40
- if ( 1 < Object.keys( ew.watermarks ).length ) {
41
- this.$el.append( $( '<option>', { value: 'all' } ).html( ew.i18n.allWatermarksLabel ) );
42
- }
43
-
44
- for ( const id in ew.watermarks ) { // eslint-disable-line no-unused-vars
45
- this.$el.append( $( '<option>', { value: id } ).html( ew.watermarks[ id ] ) );
46
- }
47
-
48
- this.attach();
49
-
50
- return this;
51
- }
52
-
53
- update() {
54
- if ( ! this.bulkActionSelector.is( this.controller.get( 'select' ) ) ) {
55
- return;
56
- }
57
-
58
- if ( 'watermark' === this.controller.get( 'action' ) && ! this.controller.status().get( 'processing' ) ) {
59
- this.$el.show();
60
- } else {
61
- this.$el.hide();
62
- }
63
- }
64
-
65
- reset() {
66
- this.$el.val( 'all' ).hide();
67
- }
68
-
69
- attach() {
70
- this.bulkActionSelector.after( this.$el );
71
- this.$el.hide();
72
-
73
- return this;
74
- }
75
-
76
- selectWatermark() {
77
- this.controller.set( 'watermark', this.$el.val() );
78
- }
79
- }
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import $ from 'jquery';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import View from './view';
10
+
11
+ /* global ew */
12
+
13
+ export default class extends View {
14
+ tagName() {
15
+ return 'select';
16
+ }
17
+
18
+ className() {
19
+ return 'ew-status';
20
+ }
21
+
22
+ events() {
23
+ return {
24
+ change: 'selectWatermark',
25
+ };
26
+ }
27
+
28
+ constructor( options ) {
29
+ super( options );
30
+
31
+ this.listenTo( this.controller, 'change', this.update );
32
+ this.listenTo( this.controller, 'bulkAction:start', this.reset );
33
+ }
34
+
35
+ render() {
36
+ super.render();
37
+
38
+ this.$el.append( $( '<option>', { value: '' } ).html( ew.i18n.selectWatermarkLabel ) );
39
+
40
+ if ( 1 < Object.keys( ew.watermarks ).length ) {
41
+ this.$el.append( $( '<option>', { value: 'all' } ).html( ew.i18n.allWatermarksLabel ) );
42
+ }
43
+
44
+ for ( const id in ew.watermarks ) { // eslint-disable-line no-unused-vars
45
+ this.$el.append( $( '<option>', { value: id } ).html( ew.watermarks[ id ] ) );
46
+ }
47
+
48
+ this.attach();
49
+
50
+ return this;
51
+ }
52
+
53
+ update() {
54
+ if ( ! this.bulkActionSelector.is( this.controller.get( 'select' ) ) ) {
55
+ return;
56
+ }
57
+
58
+ if ( 'watermark' === this.controller.get( 'action' ) && ! this.controller.status().get( 'processing' ) ) {
59
+ this.$el.show();
60
+ } else {
61
+ this.$el.hide();
62
+ }
63
+ }
64
+
65
+ reset() {
66
+ this.$el.val( 'all' ).hide();
67
+ }
68
+
69
+ attach() {
70
+ this.bulkActionSelector.after( this.$el );
71
+ this.$el.hide();
72
+
73
+ return this;
74
+ }
75
+
76
+ selectWatermark() {
77
+ this.controller.set( 'watermark', this.$el.val() );
78
+ }
79
+ }
assets/src/scripts/watermark-edit.js CHANGED
@@ -1,90 +1,90 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import '../styles/watermark-edit.scss';
10
-
11
- import ContentMetabox from './metaboxes/watermark/content';
12
- import AlignmentMetabox from './metaboxes/watermark/alignment';
13
- import ApplyingRules from './metaboxes/watermark/applying-rules';
14
- import Scaling from './metaboxes/watermark/scaling';
15
- import TextOptions from './metaboxes/watermark/text-options';
16
- import Preview from './metaboxes/watermark/preview';
17
- import Placeholders from './metaboxes/watermark/placeholders';
18
-
19
- import FormFields from './utils/form-fields';
20
-
21
- /* global ew, ajaxurl */
22
-
23
- class WatermarkEdit {
24
- constructor() {
25
- this.selectWatermarkType = this.selectWatermarkType.bind( this );
26
- this.triggerSave = this.triggerSave.bind( this );
27
-
28
- this.form = $( 'form#post' );
29
- this.selector = this.form.find( 'input.watermark-type' );
30
-
31
- this.metaboxes = [
32
- new ContentMetabox,
33
- new AlignmentMetabox,
34
- new ApplyingRules,
35
- new Scaling,
36
- new TextOptions,
37
- new Preview,
38
- new Placeholders,
39
- ];
40
-
41
- new FormFields;
42
-
43
- const selected = this.selector.filter( '[checked]' );
44
-
45
- if ( selected.length ) {
46
- this.selectWatermarkType( selected[ 0 ].value );
47
- }
48
-
49
- this.selector.on( 'change', ( e ) => {
50
- this.selectWatermarkType( e.target.value );
51
- } );
52
-
53
- this.form
54
- .on( 'change', 'input, select', this.triggerSave )
55
- .on( 'ew.save', this.triggerSave );
56
- }
57
-
58
- selectWatermarkType( type ) {
59
- for ( const metabox of this.metaboxes ) { // eslint-disable-line no-unused-vars
60
- metabox.enable( type );
61
- }
62
- }
63
-
64
- triggerSave() {
65
- const params = {
66
- action: 'easy-watermark/autosave',
67
- nonce: ew.autosaveNonce,
68
- };
69
-
70
- let data = this.form.find( '[name^=watermark], [name=post_ID]' ).serialize();
71
-
72
- for ( const key in params ) { // eslint-disable-line no-unused-vars
73
- data += '&' + encodeURIComponent( key ) + '=' + encodeURIComponent( params[ key ] );
74
- }
75
-
76
- $.ajax( {
77
- type: 'post',
78
- url: ajaxurl,
79
- data,
80
- } ).done( ( response ) => {
81
- if ( true === response.success ) {
82
- this.form.trigger( 'ew.update' );
83
- }
84
- } ).fail( () => {
85
- // TODO: handle errors.
86
- } );
87
- }
88
- }
89
-
90
- $( document ).ready( () => new WatermarkEdit );
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import $ from 'jquery';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import '../styles/watermark-edit.scss';
10
+
11
+ import ContentMetabox from './metaboxes/watermark/content';
12
+ import AlignmentMetabox from './metaboxes/watermark/alignment';
13
+ import ApplyingRules from './metaboxes/watermark/applying-rules';
14
+ import Scaling from './metaboxes/watermark/scaling';
15
+ import TextOptions from './metaboxes/watermark/text-options';
16
+ import Preview from './metaboxes/watermark/preview';
17
+ import Placeholders from './metaboxes/watermark/placeholders';
18
+
19
+ import FormFields from './utils/form-fields';
20
+
21
+ /* global ew, ajaxurl */
22
+
23
+ class WatermarkEdit {
24
+ constructor() {
25
+ this.selectWatermarkType = this.selectWatermarkType.bind( this );
26
+ this.triggerSave = this.triggerSave.bind( this );
27
+
28
+ this.form = $( 'form#post' );
29
+ this.selector = this.form.find( 'input.watermark-type' );
30
+
31
+ this.metaboxes = [
32
+ new ContentMetabox,
33
+ new AlignmentMetabox,
34
+ new ApplyingRules,
35
+ new Scaling,
36
+ new TextOptions,
37
+ new Preview,
38
+ new Placeholders,
39
+ ];
40
+
41
+ new FormFields;
42
+
43
+ const selected = this.selector.filter( '[checked]' );
44
+
45
+ if ( selected.length ) {
46
+ this.selectWatermarkType( selected[ 0 ].value );
47
+ }
48
+
49
+ this.selector.on( 'change', ( e ) => {
50
+ this.selectWatermarkType( e.target.value );
51
+ } );
52
+
53
+ this.form
54
+ .on( 'change', 'input, select', this.triggerSave )
55
+ .on( 'ew.save', this.triggerSave );
56
+ }
57
+
58
+ selectWatermarkType( type ) {
59
+ for ( const metabox of this.metaboxes ) { // eslint-disable-line no-unused-vars
60
+ metabox.enable( type );
61
+ }
62
+ }
63
+
64
+ triggerSave() {
65
+ const params = {
66
+ action: 'easy-watermark/autosave',
67
+ nonce: ew.autosaveNonce,
68
+ };
69
+
70
+ let data = this.form.find( '[name^=watermark], [name=post_ID]' ).serialize();
71
+
72
+ for ( const key in params ) { // eslint-disable-line no-unused-vars
73
+ data += '&' + encodeURIComponent( key ) + '=' + encodeURIComponent( params[ key ] );
74
+ }
75
+
76
+ $.ajax( {
77
+ type: 'post',
78
+ url: ajaxurl,
79
+ data,
80
+ } ).done( ( response ) => {
81
+ if ( true === response.success ) {
82
+ this.form.trigger( 'ew.update' );
83
+ }
84
+ } ).fail( () => {
85
+ // TODO: handle errors.
86
+ } );
87
+ }
88
+ }
89
+
90
+ $( document ).ready( () => new WatermarkEdit );
assets/src/styles/_general.scss CHANGED
@@ -49,7 +49,7 @@ body {
49
  border: 1px solid #ddd;
50
  border-radius: 3px;
51
  display: flex;
52
- padding: 0 5px;
53
  position: relative;
54
  z-index: 1;
55
  }
@@ -122,4 +122,88 @@ body {
122
  }
123
  }
124
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  }
49
  border: 1px solid #ddd;
50
  border-radius: 3px;
51
  display: flex;
52
+ padding: 0 8px;
53
  position: relative;
54
  z-index: 1;
55
  }
122
  }
123
  }
124
  }
125
+
126
+
127
+ /* stylelint-disable no-descending-specificity */
128
+ &.ew-new-form-style .form-field {
129
+
130
+ input:not(:last-child) {
131
+ border-bottom-right-radius: 0;
132
+ border-top-right-radius: 0;
133
+ }
134
+
135
+ .dropdown-menu {
136
+ border: 1px solid #7e8993;
137
+ border-radius: 4px;
138
+ color: #007cba;
139
+
140
+ .dropdown-item:hover {
141
+ background-color: #0078d7;
142
+ color: #fff;
143
+ }
144
+ }
145
+
146
+ &-text,
147
+ button {
148
+ background-color: #f0f2f3;
149
+ border: 1px solid #7e8993;
150
+ color: #32373c;
151
+ }
152
+
153
+ &-prepend {
154
+
155
+ + input {
156
+ border-bottom-left-radius: 0;
157
+ border-top-left-radius: 0;
158
+ }
159
+
160
+ .form-field-text,
161
+ button {
162
+ border-radius: 4px 0 0 4px;
163
+ border-right: 0 !important;
164
+ margin-right: 0;
165
+ }
166
+ }
167
+
168
+ &-append {
169
+
170
+ .form-field-text,
171
+ button {
172
+ border-left: 0 !important;
173
+ border-radius: 0 4px 4px 0;
174
+ margin-left: 0;
175
+ }
176
+ }
177
+
178
+ button {
179
+ background: #f0f2f3 url(data:image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2220%22%20height%3D%2220%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M5%206l5%205%205-5%202%201-7%207-7-7%202-1z%22%20fill%3D%22%23555%22%2F%3E%3C%2Fsvg%3E) no-repeat right 5px top 55%;
180
+ background-size: 16px 16px;
181
+ cursor: pointer;
182
+ padding-right: 24px;
183
+
184
+ &::after {
185
+ display: none;
186
+ }
187
+
188
+ &:focus,
189
+ &:active {
190
+ box-shadow: 0 0 0 1px #007cba;
191
+ outline: none;
192
+ }
193
+
194
+ &.is-open,
195
+ &:hover {
196
+ background-color: #fff;
197
+ border: 1px solid #7e8993;
198
+ color: #007cba;
199
+ }
200
+
201
+ &[data-toggle="dropdown"] {
202
+
203
+ &::after {
204
+ border-top: 4px solid #7e8993;
205
+ }
206
+ }
207
+ }
208
+ }
209
  }
bin/dump-hooks.php CHANGED
@@ -1,71 +1,71 @@
1
- <?php
2
- /**
3
- * This file dumps all the Dochooks to an external file: /src/inc/hooks.php
4
- * It's used only when OP Cache has `save_comments` setting saved to false.
5
- *
6
- * @usage: wp eval-file dump-hooks.php
7
- * @usage: wp eval-file wp-content/plugins/easy-watermark/bin/dump-hooks.php
8
- *
9
- * @package easy-watermark
10
- */
11
-
12
- use EasyWatermark\Core\Hooks;
13
- use EasyWatermark\Core\Plugin;
14
-
15
- $hooks = Hooks::get();
16
- $objects = $hooks->get_hooked_objects();
17
-
18
- $hook_functions = [];
19
-
20
- // Loop over each class who added own hooks.
21
- foreach ( $objects as $class_name => $data ) {
22
- $count = 0;
23
-
24
- $callback_object_name = '$this->objects[\'' . $class_name . '\'][\'instance\']';
25
-
26
- foreach ( $data['hooks'] as $hook ) {
27
- $hook_functions[] = sprintf(
28
- "add_%s( '%s', [ %s, '%s' ], %d, %d );",
29
- $hook['type'],
30
- $hook['name'],
31
- $callback_object_name,
32
- $hook['callback'],
33
- $hook['priority'],
34
- $hook['arg_count']
35
- );
36
-
37
- $count++;
38
- }
39
-
40
- WP_CLI::log( str_replace( 'EasyWatermark\\', '', $class_name ) . ' added ' . $count . ' hooks' );
41
- }
42
-
43
- // Clear the hooks file.
44
- $hooks_file = EW_DIR_PATH . '/src/inc/hooks.php';
45
-
46
- if ( file_exists( $hooks_file ) ) {
47
- unlink( $hooks_file );
48
- }
49
-
50
- $hook_functions = implode( "\n", $hook_functions );
51
-
52
- // Save the content.
53
- $file_content = <<<EOT
54
- <?php
55
- /**
56
- * Hooks compatibilty file.
57
- *
58
- * Automatically generated with bin/dump-hooks.php file.
59
- *
60
- * @package easy-watermark
61
- */
62
-
63
- // phpcs:disable
64
-
65
- {$hook_functions}
66
-
67
- EOT;
68
-
69
- // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
70
- file_put_contents( $hooks_file, $file_content );
71
- WP_CLI::success( 'All the hooks dumped!' );
1
+ <?php
2
+ /**
3
+ * This file dumps all the Dochooks to an external file: /src/inc/hooks.php
4
+ * It's used only when OP Cache has `save_comments` setting saved to false.
5
+ *
6
+ * @usage: wp eval-file dump-hooks.php
7
+ * @usage: wp eval-file wp-content/plugins/easy-watermark/bin/dump-hooks.php
8
+ *
9
+ * @package easy-watermark
10
+ */
11
+
12
+ use EasyWatermark\Core\Hooks;
13
+ use EasyWatermark\Core\Plugin;
14
+
15
+ $hooks = Hooks::get();
16
+ $objects = $hooks->get_hooked_objects();
17
+
18
+ $hook_functions = [];
19
+
20
+ // Loop over each class who added own hooks.
21
+ foreach ( $objects as $class_name => $data ) {
22
+ $count = 0;
23
+
24
+ $callback_object_name = '$this->objects[\'' . $class_name . '\'][\'instance\']';
25
+
26
+ foreach ( $data['hooks'] as $hook ) {
27
+ $hook_functions[] = sprintf(
28
+ "add_%s( '%s', [ %s, '%s' ], %d, %d );",
29
+ $hook['type'],
30
+ $hook['name'],
31
+ $callback_object_name,
32
+ $hook['callback'],
33
+ $hook['priority'],
34
+ $hook['arg_count']
35
+ );
36
+
37
+ $count++;
38
+ }
39
+
40
+ WP_CLI::log( str_replace( 'EasyWatermark\\', '', $class_name ) . ' added ' . $count . ' hooks' );
41
+ }
42
+
43
+ // Clear the hooks file.
44
+ $hooks_file = EW_DIR_PATH . '/src/inc/hooks.php';
45
+
46
+ if ( file_exists( $hooks_file ) ) {
47
+ unlink( $hooks_file );
48
+ }
49
+
50
+ $hook_functions = implode( "\n", $hook_functions );
51
+
52
+ // Save the content.
53
+ $file_content = <<<EOT
54
+ <?php
55
+ /**
56
+ * Hooks compatibilty file.
57
+ *
58
+ * Automatically generated with bin/dump-hooks.php file.
59
+ *
60
+ * @package easy-watermark
61
+ */
62
+
63
+ // phpcs:disable
64
+
65
+ {$hook_functions}
66
+
67
+ EOT;
68
+
69
+ // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
70
+ file_put_contents( $hooks_file, $file_content );
71
+ WP_CLI::success( 'All the hooks dumped!' );
easy-watermark.php CHANGED
@@ -6,7 +6,7 @@
6
  * Author URI: https://bracketspace.com/
7
  * Text Domain: easy-watermark
8
  * Domain Path: /languages
9
- * Version: 1.0.7
10
  * License: GPLv3 or later
11
  *
12
  * @package easy-watermark
6
  * Author URI: https://bracketspace.com/
7
  * Text Domain: easy-watermark
8
  * Domain Path: /languages
9
+ * Version: 1.0.8
10
  * License: GPLv3 or later
11
  *
12
  * @package easy-watermark
index.php CHANGED
@@ -1,20 +1,20 @@
1
- <?php
2
- /**
3
- * Legacy file for updating from previous version
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- /**
9
- * Activates plugin with new file, deactivates the old file.
10
- */
11
- add_action( 'admin_init', function() {
12
-
13
- $new_file = dirname( __FILE__ ) . '/easy-watermark.php';
14
-
15
- deactivate_plugins( __FILE__ );
16
- activate_plugin( $new_file, $_SERVER['REQUEST_URI'] ); //phpcs:ignore
17
-
18
- // Remove this file after new plugin activtion.
19
- unlink( __FILE__ );
20
- } );
1
+ <?php
2
+ /**
3
+ * Legacy file for updating from previous version
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ /**
9
+ * Activates plugin with new file, deactivates the old file.
10
+ */
11
+ add_action( 'admin_init', function() {
12
+
13
+ $new_file = dirname( __FILE__ ) . '/easy-watermark.php';
14
+
15
+ deactivate_plugins( __FILE__ );
16
+ activate_plugin( $new_file, $_SERVER['REQUEST_URI'] ); //phpcs:ignore
17
+
18
+ // Remove this file after new plugin activtion.
19
+ unlink( __FILE__ );
20
+ } );
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: watermark, image, picture, photo, media, gallery, signature, transparent,
5
  Requires at least: 4.6
6
  Requires PHP: 5.6
7
  Tested up to: 5.6
8
- Stable tag: 1.0.7
9
  License: GPLv3 or later
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
11
  Text Domain: easy-watermark
@@ -118,6 +118,11 @@ All available placeholders are listed in a box titled 'Placeholders' displayed w
118
 
119
  == Changelog ==
120
 
 
 
 
 
 
121
  = 1.0.7 =
122
  * [Removed] Freemius library.
123
  * [Fixed] Potential PHP 8 issue.
5
  Requires at least: 4.6
6
  Requires PHP: 5.6
7
  Tested up to: 5.6
8
+ Stable tag: 1.0.8
9
  License: GPLv3 or later
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
11
  Text Domain: easy-watermark
118
 
119
  == Changelog ==
120
 
121
+ = 1.0.8 =
122
+ * [Added] New form styles compatible with new WordPress form styles.
123
+ * [Added] Option to disable cache buster responsible for adding version param to image urls.
124
+ * [Fixed] Watermark preview.
125
+
126
  = 1.0.7 =
127
  * [Removed] Freemius library.
128
  * [Fixed] Potential PHP 8 issue.
src/classes/AttachmentProcessor/AttachmentProcessorGD.php CHANGED
@@ -136,8 +136,10 @@ class AttachmentProcessorGD extends AttachmentProcessor {
136
 
137
  $result = [];
138
 
139
- foreach ( $this->watermarks as $watermark ) {
140
- $result[ $watermark->ID ] = $this->apply_watermark( $watermark );
 
 
141
  }
142
 
143
  $output = ( true === $save ) ? $this->image_file : null;
@@ -552,7 +554,8 @@ class AttachmentProcessorGD extends AttachmentProcessor {
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 ) {
@@ -642,7 +645,7 @@ class AttachmentProcessorGD extends AttachmentProcessor {
642
  */
643
  private function get_finfo() {
644
 
645
- if ( ! $this->finfo instanceof \finfo ) {
646
  $this->finfo = new \finfo( FILEINFO_MIME_TYPE );
647
  }
648
 
136
 
137
  $result = [];
138
 
139
+ if ( $this->watermarks ) {
140
+ foreach ( $this->watermarks as $watermark ) {
141
+ $result[ $watermark->ID ] = $this->apply_watermark( $watermark );
142
+ }
143
  }
144
 
145
  $output = ( true === $save ) ? $this->image_file : null;
554
  if ( empty( $type ) && $file_path ) {
555
  // Get finfo object to detect mime types.
556
  $finfo = $this->get_finfo();
557
+ $type = $finfo ?
558
+ $finfo->file( $file_path ) : pathinfo( $file_path, PATHINFO_EXTENSION );
559
  }
560
 
561
  if ( ! $type ) {
645
  */
646
  private function get_finfo() {
647
 
648
+ if ( class_exists( 'finfo' ) && ! $this->finfo instanceof \finfo ) {
649
  $this->finfo = new \finfo( FILEINFO_MIME_TYPE );
650
  }
651
 
src/classes/Core/Assets.php CHANGED
@@ -1,313 +1,332 @@
1
- <?php
2
- /**
3
- * Assets class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Core;
9
-
10
- use EasyWatermark\Helpers\Image as ImageHelper;
11
- use EasyWatermark\Traits\Hookable;
12
- use EasyWatermark\Watermark\Handler;
13
-
14
- /**
15
- * Assets class
16
- */
17
- class Assets {
18
-
19
- use Hookable;
20
-
21
- /**
22
- * Flag whether assets has been registered already
23
- *
24
- * @var boolean
25
- */
26
- private $registered = false;
27
-
28
- /**
29
- * Watermark handler instance
30
- *
31
- * @var Handler
32
- */
33
- private $handler;
34
-
35
- /**
36
- * Constructor
37
- *
38
- * @param Plugin $plugin Plugin instance.
39
- */
40
- public function __construct( $plugin ) {
41
-
42
- $this->hook();
43
- $this->handler = $plugin->get_watermark_handler();
44
-
45
- }
46
-
47
- /**
48
- * Registers admin scripts/styles
49
- *
50
- * @action admin_enqueue_scripts 20
51
- *
52
- * @return void
53
- */
54
- public function register_admin_scripts() {
55
-
56
- if ( true === $this->registered ) {
57
- return;
58
- }
59
-
60
- $assets = [
61
- 'attachment-edit' => [ 'jquery' ],
62
- 'dashboard' => [ 'jquery', 'backbone' ],
63
- 'uploader' => [ 'jquery' ],
64
- 'media-library' => [ 'jquery', 'backbone' ],
65
- 'watermark-edit' => [ 'jquery', 'wp-color-picker' ],
66
- ];
67
-
68
- if ( class_exists( 'FileBird' ) && wp_script_is( 'njt-filebird-upload-libray-scripts' ) ) {
69
- /**
70
- * Add dependency to load FileBird script before ours.
71
- *
72
- * This script is not used in list mode, so we need to check if it is enqueued first.
73
- */
74
- $assets['uploader'][] = 'njt-filebird-upload-libray-scripts';
75
- }
76
-
77
- foreach ( $assets as $filename => $deps ) {
78
- $script_version = $this->asset_version( 'scripts', $filename . '.js' );
79
- $style_version = $this->asset_version( 'styles', $filename . '.css' );
80
- $in_footer = true;
81
-
82
- if ( 'uploader' === $filename ) {
83
- $in_footer = false;
84
- }
85
-
86
- if ( false !== $script_version ) {
87
- wp_register_script( 'ew-' . $filename, $this->asset_url( 'scripts', $filename . '.js' ), $deps, $script_version, $in_footer );
88
- }
89
-
90
- if ( false !== $style_version ) {
91
- wp_register_style( 'ew-' . $filename, $this->asset_url( 'styles', $filename . '.css' ), [], $style_version );
92
- }
93
- }
94
-
95
- $this->registered = true;
96
-
97
- }
98
-
99
- /**
100
- * Loads admin scripts/styles
101
- *
102
- * @action admin_enqueue_scripts 30
103
- *
104
- * @return void
105
- */
106
- public function enqueue_admin_scripts() {
107
-
108
- $current_screen = get_current_screen();
109
- $enqueue = false;
110
- $localize = [];
111
-
112
- switch ( $current_screen->id ) {
113
- case 'attachment':
114
- $enqueue = 'attachment-edit';
115
- $localize = [
116
- 'genericErrorMessage' => __( 'Something went wrong. Please refresh the page and try again.', 'easy-watermark' ),
117
- ];
118
- break;
119
- case 'tools_page_easy-watermark':
120
- $enqueue = 'dashboard';
121
- $localize = [
122
- 'nonce' => wp_create_nonce( 'get_attachments' ),
123
- 'i18n' => [
124
- /* translators: watermark name */
125
- 'deleteConfirmation' => sprintf( __( 'You are about to permanently delete "%s". Are you sure?', 'easy-watermark' ), '{watermarkName}' ),
126
- 'noItemsToWatermark' => __( 'There are no images eligible for watermarking.', 'easy-watermark' ),
127
- 'noItemsToRestore' => __( 'There are no backed up images.', 'easy-watermark' ),
128
- /* translators: watermarked images number */
129
- 'watermarkingStatus' => sprintf( __( 'Watermarked %s images', 'easy-watermark' ), '{counter}' ),
130
- /* translators: watermarked images number */
131
- 'restoringStatus' => sprintf( __( 'Restored %s images', 'easy-watermark' ), '{counter}' ),
132
- /* translators: watermarked images number */
133
- 'watermarkingSuccessMessage' => sprintf( __( 'Successfully watermarked %s images.', 'easy-watermark' ), '{procesed}' ),
134
- /* translators: watermarked images number */
135
- 'restoringSuccessMessage' => sprintf( __( 'Successfully restored %s images.', 'easy-watermark' ), '{procesed}' ),
136
- /* translators: %1&s - image title, %2&s - error content */
137
- 'bulkActionErrorMessage' => sprintf( __( 'An error occured while processing %1$s: %2$s', 'easy-watermark' ), '{imageTitle}', '{error}' ),
138
- ],
139
- ];
140
- break;
141
- case 'upload':
142
- if ( ! current_user_can( 'apply_watermark' ) ) {
143
- break;
144
- }
145
-
146
- $this->wp_enqueue_media();
147
- $enqueue = 'media-library';
148
- $localize = [
149
- 'watermarks' => $this->get_watermarks(),
150
- 'mime' => ImageHelper::get_available_mime_types(),
151
- 'applyAllNonce' => wp_create_nonce( 'apply_all' ),
152
- 'applySingleNonces' => $this->get_watermark_nonces(),
153
- 'restoreBackupNonce' => wp_create_nonce( 'restore_backup' ),
154
- 'attachmentsInfoNonce' => wp_create_nonce( 'attachments_info' ),
155
- 'i18n' => [
156
- 'noItemsSelected' => __( 'No items selected', 'easy-watermark' ),
157
- 'watermarkModeToggleButtonLabel' => __( 'Watermark Selected', 'easy-watermark' ),
158
- 'watermarkButtonLabel' => __( 'Watermark', 'easy-watermark' ),
159
- 'restoreButtonLabel' => __( 'Restore original images', 'easy-watermark' ),
160
- 'cancelLabel' => __( 'Cancel', 'easy-watermark' ),
161
- 'selectWatermarkLabel' => __( 'Select Watermark', 'easy-watermark' ),
162
- 'allWatermarksLabel' => __( 'All Watermarks', 'easy-watermark' ),
163
- 'notSupported' => _x( 'Not supported', 'label for unsupported attachment type (other than image)', 'easy-watermark' ),
164
- 'usedAsWatermark' => _x( 'Used as watermark', 'label for image used as watermark', 'easy-watermark' ),
165
- 'noBackupAvailable' => _x( 'No backup available', 'label for attachments which has no backup to restore', 'easy-watermark' ),
166
- 'watermarkingNoItems' => __( 'None from the selected items qualified for watermarking.', 'easy-watermark' ),
167
- 'restoringNoItems' => __( 'No backup available for any of selected items.', 'easy-watermark' ),
168
- /* translators: watermarked images number */
169
- 'watermarkingStatus' => sprintf( __( 'Watermarked %s images', 'easy-watermark' ), '{counter}' ),
170
- /* translators: watermarked images number */
171
- 'restoringStatus' => sprintf( __( 'Restored %s images', 'easy-watermark' ), '{counter}' ),
172
- /* translators: watermarked images number */
173
- 'watermarkingSuccessMessage' => sprintf( __( 'Successfully watermarked %s images.', 'easy-watermark' ), '{procesed}' ),
174
- /* translators: watermarked images number */
175
- 'restoringSuccessMessage' => sprintf( __( 'Successfully restored %s images.', 'easy-watermark' ), '{procesed}' ),
176
- /* translators: %1&s - image title, %2&s - error content */
177
- 'bulkActionErrorMessage' => sprintf( __( 'An error occured while processing %1$s: %2$s', 'easy-watermark' ), '{imageTitle}', '{error}' ),
178
- ],
179
- ];
180
- break;
181
- case 'watermark':
182
- wp_enqueue_style( 'wp-color-picker' );
183
- wp_enqueue_media();
184
- $enqueue = 'watermark-edit';
185
- $localize = [
186
- 'autosaveNonce' => wp_create_nonce( 'watermark_autosave' ),
187
- 'previewImageNonce' => wp_create_nonce( 'preview_image' ),
188
- ];
189
- break;
190
- }
191
-
192
- if ( $enqueue ) {
193
- $this->enqueue_asset( $enqueue, $localize );
194
- }
195
-
196
- }
197
-
198
- /**
199
- * Loads scripts/styles altering WordPress media library
200
- *
201
- * @action wp_enqueue_media
202
- *
203
- * @return void
204
- */
205
- public function wp_enqueue_media() {
206
-
207
- // In block editor wp_enqueue_media runs before admin_enqueue_scripts, so the scripts are not registered by now.
208
- $this->register_admin_scripts();
209
- $this->enqueue_asset( 'uploader', [
210
- 'autoWatermark' => true,
211
- ] );
212
-
213
- }
214
-
215
- /**
216
- * Enqueues script/style and localizes if necessary
217
- *
218
- * @param string $asset_name Asset name.
219
- * @param array $localize Localize data.
220
- * @return void
221
- */
222
- private function enqueue_asset( $asset_name, $localize = [] ) {
223
-
224
- $asset_name = 'ew-' . $asset_name;
225
-
226
- wp_enqueue_style( $asset_name );
227
- wp_enqueue_script( $asset_name );
228
-
229
- $localize['i18n'] = array_merge( isset( $localize['i18n'] ) ? $localize['i18n'] : [], [
230
- 'yes' => __( 'Yes', 'easy-watermark' ),
231
- 'ok' => __( 'OK', 'easy-watermark' ),
232
- 'no' => __( 'Cancel', 'easy-watermark' ),
233
- 'genericErrorMessage' => __( 'Something went wrong. Please refresh the page and try again.', 'easy-watermark' ),
234
- ] );
235
-
236
- wp_localize_script( $asset_name, 'ew', $localize );
237
-
238
- }
239
-
240
- /**
241
- * Returns asset url
242
- *
243
- * @param string $type Asset type.
244
- * @param string $file Filename.
245
- * @return string
246
- */
247
- private function asset_url( $type, $file ) {
248
- return EW_DIR_URL . 'assets/dist/' . $type . '/' . $file;
249
- }
250
-
251
- /**
252
- * Returns asset version
253
- *
254
- * @param string $type Asset type.
255
- * @param string $file Filename.
256
- * @return string|false
257
- */
258
- private function asset_version( $type, $file ) {
259
-
260
- $path = EW_DIR_PATH . 'assets/dist/' . $type . '/' . $file;
261
-
262
- if ( is_file( $path ) ) {
263
- return filemtime( $path );
264
- }
265
-
266
- return false;
267
-
268
- }
269
-
270
- /**
271
- * Returns watermarks list
272
- *
273
- * @return array
274
- */
275
- private function get_watermarks() {
276
-
277
- $watermarks = $this->handler->get_watermarks();
278
- $watermarks_list = [];
279
-
280
- foreach ( $watermarks as $watermark ) {
281
- $watermarks_list[ $watermark->ID ] = $watermark->post_title;
282
- }
283
-
284
- return $watermarks_list;
285
-
286
- }
287
-
288
- /**
289
- * Returns watermarks list
290
- *
291
- * @return array
292
- */
293
- private function get_watermark_nonces() {
294
-
295
- $watermarks = $this->handler->get_watermarks();
296
- $nonces = [];
297
-
298
- foreach ( $watermarks as $watermark ) {
299
- $nonces[ $watermark->ID ] = wp_create_nonce( 'apply_single-' . $watermark->ID );
300
- }
301
-
302
- return $nonces;
303
-
304
- }
305
-
306
- /**
307
- * Destructor
308
- */
309
- public function __destruct() {
310
- $this->unhook();
311
- }
312
-
313
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Assets class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Core;
9
+
10
+ use EasyWatermark\Helpers\Image as ImageHelper;
11
+ use EasyWatermark\Traits\Hookable;
12
+ use EasyWatermark\Watermark\Handler;
13
+
14
+ /**
15
+ * Assets class
16
+ */
17
+ class Assets {
18
+
19
+ use Hookable;
20
+
21
+ /**
22
+ * Flag whether assets has been registered already
23
+ *
24
+ * @var boolean
25
+ */
26
+ private $registered = false;
27
+
28
+ /**
29
+ * Watermark handler instance
30
+ *
31
+ * @var Handler
32
+ */
33
+ private $handler;
34
+
35
+ /**
36
+ * Constructor
37
+ *
38
+ * @param Plugin $plugin Plugin instance.
39
+ */
40
+ public function __construct( $plugin ) {
41
+ global $wp_version;
42
+
43
+ $this->hook();
44
+ $this->handler = $plugin->get_watermark_handler();
45
+
46
+ }
47
+
48
+ /**
49
+ * Filter body classes
50
+ *
51
+ * @filter admin_body_class
52
+ *
53
+ * @param array $classes Classes array.
54
+ * @return array Filtered classes array.
55
+ */
56
+ public function body_class( $classes ) {
57
+ global $wp_version;
58
+
59
+ if ( version_compare( $wp_version, '5.3', '>=' ) ) {
60
+ $classes .= ' ew-new-form-style ';
61
+ }
62
+
63
+ return $classes;
64
+ }
65
+
66
+ /**
67
+ * Registers admin scripts/styles
68
+ *
69
+ * @action admin_enqueue_scripts 20
70
+ *
71
+ * @return void
72
+ */
73
+ public function register_admin_scripts() {
74
+
75
+ if ( true === $this->registered ) {
76
+ return;
77
+ }
78
+
79
+ $assets = [
80
+ 'attachment-edit' => [ 'jquery' ],
81
+ 'dashboard' => [ 'jquery', 'backbone' ],
82
+ 'uploader' => [ 'jquery' ],
83
+ 'media-library' => [ 'jquery', 'backbone' ],
84
+ 'watermark-edit' => [ 'jquery', 'wp-color-picker' ],
85
+ ];
86
+
87
+ if ( class_exists( 'FileBird' ) && wp_script_is( 'njt-filebird-upload-libray-scripts' ) ) {
88
+ /**
89
+ * Add dependency to load FileBird script before ours.
90
+ *
91
+ * This script is not used in list mode, so we need to check if it is enqueued first.
92
+ */
93
+ $assets['uploader'][] = 'njt-filebird-upload-libray-scripts';
94
+ }
95
+
96
+ foreach ( $assets as $filename => $deps ) {
97
+ $script_version = $this->asset_version( 'scripts', $filename . '.js' );
98
+ $style_version = $this->asset_version( 'styles', $filename . '.css' );
99
+ $in_footer = true;
100
+
101
+ if ( 'uploader' === $filename ) {
102
+ $in_footer = false;
103
+ }
104
+
105
+ if ( false !== $script_version ) {
106
+ wp_register_script( 'ew-' . $filename, $this->asset_url( 'scripts', $filename . '.js' ), $deps, $script_version, $in_footer );
107
+ }
108
+
109
+ if ( false !== $style_version ) {
110
+ wp_register_style( 'ew-' . $filename, $this->asset_url( 'styles', $filename . '.css' ), [], $style_version );
111
+ }
112
+ }
113
+
114
+ $this->registered = true;
115
+
116
+ }
117
+
118
+ /**
119
+ * Loads admin scripts/styles
120
+ *
121
+ * @action admin_enqueue_scripts 30
122
+ *
123
+ * @return void
124
+ */
125
+ public function enqueue_admin_scripts() {
126
+
127
+ $current_screen = get_current_screen();
128
+ $enqueue = false;
129
+ $localize = [];
130
+
131
+ switch ( $current_screen->id ) {
132
+ case 'attachment':
133
+ $enqueue = 'attachment-edit';
134
+ $localize = [
135
+ 'genericErrorMessage' => __( 'Something went wrong. Please refresh the page and try again.', 'easy-watermark' ),
136
+ ];
137
+ break;
138
+ case 'tools_page_easy-watermark':
139
+ $enqueue = 'dashboard';
140
+ $localize = [
141
+ 'nonce' => wp_create_nonce( 'get_attachments' ),
142
+ 'i18n' => [
143
+ /* translators: watermark name */
144
+ 'deleteConfirmation' => sprintf( __( 'You are about to permanently delete "%s". Are you sure?', 'easy-watermark' ), '{watermarkName}' ),
145
+ 'noItemsToWatermark' => __( 'There are no images eligible for watermarking.', 'easy-watermark' ),
146
+ 'noItemsToRestore' => __( 'There are no backed up images.', 'easy-watermark' ),
147
+ /* translators: watermarked images number */
148
+ 'watermarkingStatus' => sprintf( __( 'Watermarked %s images', 'easy-watermark' ), '{counter}' ),
149
+ /* translators: watermarked images number */
150
+ 'restoringStatus' => sprintf( __( 'Restored %s images', 'easy-watermark' ), '{counter}' ),
151
+ /* translators: watermarked images number */
152
+ 'watermarkingSuccessMessage' => sprintf( __( 'Successfully watermarked %s images.', 'easy-watermark' ), '{procesed}' ),
153
+ /* translators: watermarked images number */
154
+ 'restoringSuccessMessage' => sprintf( __( 'Successfully restored %s images.', 'easy-watermark' ), '{procesed}' ),
155
+ /* translators: %1&s - image title, %2&s - error content */
156
+ 'bulkActionErrorMessage' => sprintf( __( 'An error occured while processing %1$s: %2$s', 'easy-watermark' ), '{imageTitle}', '{error}' ),
157
+ ],
158
+ ];
159
+ break;
160
+ case 'upload':
161
+ if ( ! current_user_can( 'apply_watermark' ) ) {
162
+ break;
163
+ }
164
+
165
+ $this->wp_enqueue_media();
166
+ $enqueue = 'media-library';
167
+ $localize = [
168
+ 'watermarks' => $this->get_watermarks(),
169
+ 'mime' => ImageHelper::get_available_mime_types(),
170
+ 'applyAllNonce' => wp_create_nonce( 'apply_all' ),
171
+ 'applySingleNonces' => $this->get_watermark_nonces(),
172
+ 'restoreBackupNonce' => wp_create_nonce( 'restore_backup' ),
173
+ 'attachmentsInfoNonce' => wp_create_nonce( 'attachments_info' ),
174
+ 'i18n' => [
175
+ 'noItemsSelected' => __( 'No items selected', 'easy-watermark' ),
176
+ 'watermarkModeToggleButtonLabel' => __( 'Watermark Selected', 'easy-watermark' ),
177
+ 'watermarkButtonLabel' => __( 'Watermark', 'easy-watermark' ),
178
+ 'restoreButtonLabel' => __( 'Restore original images', 'easy-watermark' ),
179
+ 'cancelLabel' => __( 'Cancel', 'easy-watermark' ),
180
+ 'selectWatermarkLabel' => __( 'Select Watermark', 'easy-watermark' ),
181
+ 'allWatermarksLabel' => __( 'All Watermarks', 'easy-watermark' ),
182
+ 'notSupported' => _x( 'Not supported', 'label for unsupported attachment type (other than image)', 'easy-watermark' ),
183
+ 'usedAsWatermark' => _x( 'Used as watermark', 'label for image used as watermark', 'easy-watermark' ),
184
+ 'noBackupAvailable' => _x( 'No backup available', 'label for attachments which has no backup to restore', 'easy-watermark' ),
185
+ 'watermarkingNoItems' => __( 'None from the selected items qualified for watermarking.', 'easy-watermark' ),
186
+ 'restoringNoItems' => __( 'No backup available for any of selected items.', 'easy-watermark' ),
187
+ /* translators: watermarked images number */
188
+ 'watermarkingStatus' => sprintf( __( 'Watermarked %s images', 'easy-watermark' ), '{counter}' ),
189
+ /* translators: watermarked images number */
190
+ 'restoringStatus' => sprintf( __( 'Restored %s images', 'easy-watermark' ), '{counter}' ),
191
+ /* translators: watermarked images number */
192
+ 'watermarkingSuccessMessage' => sprintf( __( 'Successfully watermarked %s images.', 'easy-watermark' ), '{procesed}' ),
193
+ /* translators: watermarked images number */
194
+ 'restoringSuccessMessage' => sprintf( __( 'Successfully restored %s images.', 'easy-watermark' ), '{procesed}' ),
195
+ /* translators: %1&s - image title, %2&s - error content */
196
+ 'bulkActionErrorMessage' => sprintf( __( 'An error occured while processing %1$s: %2$s', 'easy-watermark' ), '{imageTitle}', '{error}' ),
197
+ ],
198
+ ];
199
+ break;
200
+ case 'watermark':
201
+ wp_enqueue_style( 'wp-color-picker' );
202
+ wp_enqueue_media();
203
+ $enqueue = 'watermark-edit';
204
+ $localize = [
205
+ 'autosaveNonce' => wp_create_nonce( 'watermark_autosave' ),
206
+ 'previewImageNonce' => wp_create_nonce( 'preview_image' ),
207
+ ];
208
+ break;
209
+ }
210
+
211
+ if ( $enqueue ) {
212
+ $this->enqueue_asset( $enqueue, $localize );
213
+ }
214
+
215
+ }
216
+
217
+ /**
218
+ * Loads scripts/styles altering WordPress media library
219
+ *
220
+ * @action wp_enqueue_media
221
+ *
222
+ * @return void
223
+ */
224
+ public function wp_enqueue_media() {
225
+
226
+ // In block editor wp_enqueue_media runs before admin_enqueue_scripts, so the scripts are not registered by now.
227
+ $this->register_admin_scripts();
228
+ $this->enqueue_asset( 'uploader', [
229
+ 'autoWatermark' => true,
230
+ ] );
231
+
232
+ }
233
+
234
+ /**
235
+ * Enqueues script/style and localizes if necessary
236
+ *
237
+ * @param string $asset_name Asset name.
238
+ * @param array $localize Localize data.
239
+ * @return void
240
+ */
241
+ private function enqueue_asset( $asset_name, $localize = [] ) {
242
+
243
+ $asset_name = 'ew-' . $asset_name;
244
+
245
+ wp_enqueue_style( $asset_name );
246
+ wp_enqueue_script( $asset_name );
247
+
248
+ $localize['i18n'] = array_merge( isset( $localize['i18n'] ) ? $localize['i18n'] : [], [
249
+ 'yes' => __( 'Yes', 'easy-watermark' ),
250
+ 'ok' => __( 'OK', 'easy-watermark' ),
251
+ 'no' => __( 'Cancel', 'easy-watermark' ),
252
+ 'genericErrorMessage' => __( 'Something went wrong. Please refresh the page and try again.', 'easy-watermark' ),
253
+ ] );
254
+
255
+ wp_localize_script( $asset_name, 'ew', $localize );
256
+
257
+ }
258
+
259
+ /**
260
+ * Returns asset url
261
+ *
262
+ * @param string $type Asset type.
263
+ * @param string $file Filename.
264
+ * @return string
265
+ */
266
+ private function asset_url( $type, $file ) {
267
+ return EW_DIR_URL . 'assets/dist/' . $type . '/' . $file;
268
+ }
269
+
270
+ /**
271
+ * Returns asset version
272
+ *
273
+ * @param string $type Asset type.
274
+ * @param string $file Filename.
275
+ * @return string|false
276
+ */
277
+ private function asset_version( $type, $file ) {
278
+
279
+ $path = EW_DIR_PATH . 'assets/dist/' . $type . '/' . $file;
280
+
281
+ if ( is_file( $path ) ) {
282
+ return filemtime( $path );
283
+ }
284
+
285
+ return false;
286
+
287
+ }
288
+
289
+ /**
290
+ * Returns watermarks list
291
+ *
292
+ * @return array
293
+ */
294
+ private function get_watermarks() {
295
+
296
+ $watermarks = $this->handler->get_watermarks();
297
+ $watermarks_list = [];
298
+
299
+ foreach ( $watermarks as $watermark ) {
300
+ $watermarks_list[ $watermark->ID ] = $watermark->post_title;
301
+ }
302
+
303
+ return $watermarks_list;
304
+
305
+ }
306
+
307
+ /**
308
+ * Returns watermarks list
309
+ *
310
+ * @return array
311
+ */
312
+ private function get_watermark_nonces() {
313
+
314
+ $watermarks = $this->handler->get_watermarks();
315
+ $nonces = [];
316
+
317
+ foreach ( $watermarks as $watermark ) {
318
+ $nonces[ $watermark->ID ] = wp_create_nonce( 'apply_single-' . $watermark->ID );
319
+ }
320
+
321
+ return $nonces;
322
+
323
+ }
324
+
325
+ /**
326
+ * Destructor
327
+ */
328
+ public function __destruct() {
329
+ $this->unhook();
330
+ }
331
+
332
+ }
src/classes/Core/Installer.php CHANGED
@@ -1,492 +1,494 @@
1
- <?php
2
- /**
3
- * Installer class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Core;
9
-
10
- use EasyWatermark\Watermark\Watermark;
11
-
12
- /**
13
- * Helper class providing install, uninstall, update methods
14
- */
15
- class Installer {
16
-
17
- /**
18
- * Watermarked attachments
19
- *
20
- * @var array
21
- */
22
- private static $watermarked_attachments = [];
23
-
24
- /**
25
- * Activates plugin
26
- *
27
- * @return void
28
- */
29
- public static function activate() {
30
-
31
- $version = get_option( Plugin::get()->get_slug() . '-version', false );
32
-
33
- if ( ! $version ) {
34
- // First activation.
35
- self::install();
36
- }
37
-
38
- $admin = get_role( 'administrator' );
39
-
40
- $admin->add_cap( 'edit_watermark' );
41
- $admin->add_cap( 'edit_watermarks' );
42
- $admin->add_cap( 'edit_others_watermarks' );
43
- $admin->add_cap( 'delete_watermarks' );
44
- $admin->add_cap( 'delete_others_watermarks' );
45
- $admin->add_cap( 'apply_watermark' );
46
-
47
- $editor = get_role( 'editor' );
48
-
49
- $admin->add_cap( 'edit_watermark' );
50
- $admin->add_cap( 'edit_watermarks' );
51
- $admin->add_cap( 'edit_others_watermarks' );
52
- $admin->add_cap( 'delete_watermarks' );
53
- $admin->add_cap( 'delete_others_watermarks' );
54
- $admin->add_cap( 'apply_watermark' );
55
-
56
- $author = get_role( 'author' );
57
-
58
- $admin->add_cap( 'edit_watermark' );
59
- $admin->add_cap( 'edit_watermarks' );
60
- $admin->add_cap( 'delete_watermarks' );
61
- $admin->add_cap( 'apply_watermark' );
62
-
63
- }
64
-
65
- /**
66
- * Deactivates plugin
67
- *
68
- * @return void
69
- */
70
- public static function deactivate() {
71
- delete_option( 'easy-watermark-first-booted' );
72
- flush_rewrite_rules();
73
- }
74
-
75
- /**
76
- * Installs plugin
77
- * This method is called on the first activation
78
- *
79
- * @return void
80
- */
81
- public static function install() {}
82
-
83
- /**
84
- * Uninstalls plugin
85
- *
86
- * @return void
87
- */
88
- public static function uninstall() {
89
-
90
- delete_option( Plugin::get()->get_slug() . '-version' );
91
-
92
- $roles = get_editable_roles();
93
-
94
- foreach ( $roles as $role => $details ) {
95
- $role = get_role( $role );
96
-
97
- $role->remove_cap( 'edit_watermark' );
98
- $role->remove_cap( 'read_watermark' );
99
- $role->remove_cap( 'delete_watermark' );
100
- $role->remove_cap( 'edit_watermarks' );
101
- $role->remove_cap( 'edit_others_watermarks' );
102
- $role->remove_cap( 'publish_watermarks' );
103
- $role->remove_cap( 'read_private_watermarks' );
104
- $role->remove_cap( 'apply_watermark' );
105
- }
106
-
107
- $watermarks = Watermark::get_all();
108
-
109
- foreach ( $watermarks as $watermark ) {
110
- $result = wp_delete_post( $watermark->ID, true );
111
- }
112
-
113
- }
114
-
115
- /**
116
- * Updates plugin
117
- *
118
- * @param string $from Previous active version.
119
- * @param array $defaults Default settings.
120
- * @return void
121
- */
122
- public static function update( $from, $defaults ) {
123
-
124
- update_option( Plugin::get()->get_slug() . '-version', Plugin::get()->get_version() );
125
-
126
- if ( version_compare( $from, '1.0.0', '>=' ) ) {
127
- self::update_attachment_meta();
128
- return;
129
- }
130
-
131
- $plugin_slug = Plugin::get()->get_slug();
132
- $settings = [];
133
-
134
- if ( version_compare( $from, '0.1.1', '>' ) ) {
135
- $settings['general'] = get_option( $plugin_slug . '-settings-general' );
136
- $settings['image'] = get_option( $plugin_slug . '-settings-image' );
137
- $settings['text'] = get_option( $plugin_slug . '-settings-text' );
138
-
139
- delete_option( $plugin_slug . '-settings-general' );
140
- delete_option( $plugin_slug . '-settings-image' );
141
- delete_option( $plugin_slug . '-settings-text' );
142
- } else {
143
- $old_settings = get_option( $plugin_slug . '-settings' );
144
-
145
- delete_option( $plugin_slug . '-settings' );
146
-
147
- $general = [
148
- 'auto_add' => $old_settings['auto_add'],
149
- 'image_types' => $old_settings['image_types'],
150
- ];
151
-
152
- switch ( $from ) {
153
- case '0.1.1':
154
- $image = [
155
- 'watermark_url' => $old_settings['image']['url'],
156
- 'watermark_id' => $old_settings['image']['id'],
157
- 'watermark_path' => $old_settings['image']['path'],
158
- 'watermark_mime' => $old_settings['image']['mime'],
159
- 'position_x' => $old_settings['image']['position_x'],
160
- 'position_y' => $old_settings['image']['position_y'],
161
- 'offset_x' => $old_settings['image']['offset_x'],
162
- 'offset_y' => $old_settings['image']['offset_y'],
163
- 'opacity' => $old_settings['image']['opacity'],
164
- ];
165
- break;
166
- default:
167
- $image = [
168
- 'watermark_url' => $old_settings['image']['url'],
169
- 'watermark_id' => $old_settings['image']['id'],
170
- 'watermark_path' => $old_settings['image']['path'],
171
- 'watermark_mime' => $old_settings['image']['mime'],
172
- 'position_x' => $old_settings['image']['position-horizontal'],
173
- 'position_y' => $old_settings['image']['position-vert'],
174
- 'offset_x' => $old_settings['image']['offset-horizontal'],
175
- 'offset_y' => $old_settings['image']['offset-vert'],
176
- 'opacity' => $old_settings['image']['alpha'],
177
- ];
178
- break;
179
- }
180
-
181
- $settings = [
182
- 'general' => $general,
183
- 'image' => $image,
184
- 'text' => [],
185
- ];
186
-
187
- delete_option( $plugin_slug . '-settings' );
188
- }
189
-
190
- $settings['image']['alignment'] = self::get_alignment( $settings['image']['position_x'], $settings['image']['position_y'] );
191
- $settings['text']['alignment'] = self::get_alignment( $settings['text']['position_x'], $settings['text']['position_y'] );
192
-
193
- $watermark_defaults = Watermark::get_defaults();
194
-
195
- $watermark_defaults['auto_add'] = $settings['general']['auto_add'];
196
-
197
- if ( isset( $settings['general']['auto_add_perm'] ) ) {
198
- $watermark_defaults['auto_add_all'] = $settings['general']['auto_add_perm'];
199
- }
200
-
201
- if ( isset( $settings['general']['image_types'] ) ) {
202
- $watermark_defaults['image_types'] = $settings['general']['image_types'];
203
- }
204
-
205
- if ( isset( $settings['general']['image_sizes'] ) ) {
206
- $watermark_defaults['image_sizes'] = $settings['general']['image_sizes'];
207
- }
208
-
209
- if ( isset( $settings['general']['allowed_post_types'] ) ) {
210
- $watermark_defaults['post_types'] = $settings['general']['allowed_post_types'];
211
- }
212
-
213
- if ( isset( $settings['general']['jpg_quality'] ) ) {
214
- $defaults['general']['jpeg_quality'] = $settings['general']['jpg_quality'];
215
- }
216
-
217
- update_option( Plugin::get()->get_slug() . '-settings', $defaults );
218
-
219
- if ( isset( $settings['image']['watermark_id'] ) && ! empty( $settings['image']['watermark_id'] ) ) {
220
- self::insert_image_watermark( $watermark_defaults, $settings );
221
- }
222
-
223
- if ( ! empty( $settings['text']['text'] ) ) {
224
- self::insert_text_watermark( $watermark_defaults, $settings );
225
- }
226
-
227
- self::update_backup_info();
228
-
229
- }
230
-
231
- /**
232
- * Update attachment meta
233
- *
234
- * @return void
235
- */
236
- private static function update_attachment_meta() {
237
- global $wpdb;
238
-
239
- // phpcs:ignore WordPress.DB.DirectDatabaseQuery
240
- $meta = $wpdb->get_results( $wpdb->prepare( "SELECT `post_id`, `meta_value` FROM {$wpdb->postmeta} WHERE `meta_key` = %s", '_ew_applied_watermarks' ) );
241
-
242
- foreach ( $meta as $entry ) {
243
- $value = maybe_unserialize( $entry->meta_value );
244
-
245
- if ( is_array( $value ) ) {
246
- $new_value = [];
247
-
248
- foreach ( $value as $watermark_id ) {
249
- $watermark = Watermark::get( $watermark_id );
250
-
251
- if ( $watermark ) {
252
- $new_value[ $watermark_id ] = $watermark->post_title;
253
- }
254
- }
255
-
256
- if ( $new_value ) {
257
- update_post_meta( $entry->post_id, '_ew_applied_watermarks', $new_value );
258
- } else {
259
- delete_post_meta( $entry->post_id, '_ew_applied_watermarks' );
260
- }
261
- }
262
- }
263
- }
264
-
265
- /**
266
- * Updates backup info
267
- *
268
- * @return void
269
- */
270
- private static function update_backup_info() {
271
-
272
- $attachments = get_posts( [
273
- 'posts_per_page' => -1,
274
- 'post_type' => 'attachment',
275
- 'meta_query' => [
276
- [
277
- 'key' => '_ew_backup_file',
278
- 'compare' => 'EXISTS',
279
- ],
280
- ],
281
- ] );
282
-
283
- foreach ( $attachments as $attachment ) {
284
- update_post_meta( $attachment->ID, '_ew_has_backup', true );
285
- }
286
-
287
- }
288
-
289
- /**
290
- * Updates backup info
291
- *
292
- * @return array
293
- */
294
- private static function get_watermarked_attachments() {
295
-
296
- if ( ! self::$watermarked_attachments ) {
297
- self::$watermarked_attachments = get_posts( [
298
- 'posts_per_page' => -1,
299
- 'post_type' => 'attachment',
300
- 'meta_key' => '_ew_watermarked',
301
- 'meta_value' => '1',
302
- ] );
303
- }
304
-
305
- return self::$watermarked_attachments;
306
-
307
- }
308
-
309
- /**
310
- * Inserts image watermark based on previous version settings
311
- *
312
- * @param array $defaults Default watermark params.
313
- * @param array $settings Watermark settings.
314
- * @return integer
315
- */
316
- private static function insert_image_watermark( $defaults, $settings ) {
317
-
318
- $image_settings = [
319
- 'type' => 'image',
320
- 'attachment_id' => $settings['image']['watermark_id'],
321
- 'mime_type' => $settings['image']['watermark_mime'],
322
- 'url' => $settings['image']['watermark_url'],
323
- 'alignment' => $settings['image']['alignment'],
324
- 'opacity' => $settings['image']['opacity'],
325
- 'offset' => [
326
- 'x' => [
327
- 'value' => intval( $settings['image']['offset_x'] ),
328
- 'unit' => ( '%' === substr( $settings['image']['offset_x'], -1 ) ) ? '%' : 'px',
329
- ],
330
- 'y' => [
331
- 'value' => intval( $settings['image']['offset_y'] ),
332
- 'unit' => ( '%' === substr( $settings['image']['offset_y'], -1 ) ) ? '%' : 'px',
333
- ],
334
- ],
335
- ];
336
-
337
- if ( isset( $settings['image']['scale_mode'] ) ) {
338
- $image_settings['scaling_mode'] = $settings['image']['scale_mode'];
339
-
340
- if ( 'fit' === $image_settings['scaling_mode'] ) {
341
- $image_settings['scaling_mode'] = 'contain';
342
- }
343
-
344
- if ( 'fill' === $image_settings['scaling_mode'] ) {
345
- $image_settings['scaling_mode'] = 'cover';
346
- }
347
- }
348
-
349
- if ( isset( $settings['image']['scale_to_smaller'] ) ) {
350
- $image_settings['scale_down_only'] = $settings['image']['scale_to_smaller'];
351
- }
352
-
353
- if ( isset( $settings['image']['scale'] ) ) {
354
- $image_settings['scale'] = $settings['image']['scale'];
355
- }
356
-
357
- $image_settings = array_merge( $defaults, $image_settings );
358
-
359
- $watermark_id = wp_insert_post( [
360
- 'post_title' => __( 'Image Watermark', 'easy-watermark' ),
361
- 'post_type' => 'watermark',
362
- 'post_status' => 'publish',
363
- 'watermark' => $image_settings,
364
- ] );
365
-
366
- if ( in_array( $settings['general']['watermark_type'], [ '1', '3' ], true ) ) {
367
- $attachments = self::get_watermarked_attachments();
368
-
369
- foreach ( $attachments as $attachment ) {
370
- self::add_applied_watermark( $attachment->ID, $watermark_id );
371
- }
372
- }
373
-
374
- return $watermark_id;
375
-
376
- }
377
-
378
- /**
379
- * Inserts text watermark based on previous version settings
380
- *
381
- * @param array $defaults Default watermark params.
382
- * @param array $settings Watermark settings.
383
- * @return integer
384
- */
385
- private static function insert_text_watermark( $defaults, $settings ) {
386
-
387
- $text_settings = [
388
- 'type' => 'text',
389
- 'text' => $settings['text']['text'],
390
- 'font' => $settings['text']['font'],
391
- 'text_color' => $settings['text']['color'],
392
- 'text_size' => $settings['text']['size'],
393
- 'text_angle' => $settings['text']['angle'],
394
- 'opacity' => $settings['text']['opacity'],
395
- 'alignment' => $settings['text']['alignment'],
396
- 'offset' => [
397
- 'x' => [
398
- 'value' => intval( $settings['text']['offset_x'] ),
399
- 'unit' => ( '%' === substr( $settings['text']['offset_x'], -1 ) ) ? '%' : 'px',
400
- ],
401
- 'y' => [
402
- 'value' => intval( $settings['text']['offset_y'] ),
403
- 'unit' => ( '%' === substr( $settings['text']['offset_y'], -1 ) ) ? '%' : 'px',
404
- ],
405
- ],
406
- ];
407
-
408
- $text_settings = array_merge( $defaults, $text_settings );
409
-
410
- $watermark_id = wp_insert_post( [
411
- 'post_title' => __( 'Text Watermark', 'easy-watermark' ),
412
- 'post_type' => 'watermark',
413
- 'post_status' => 'publish',
414
- 'watermark' => $text_settings,
415
- ] );
416
-
417
- if ( in_array( $settings['general']['watermark_type'], [ '2', '3' ], true ) ) {
418
- $attachments = self::get_watermarked_attachments();
419
-
420
- foreach ( $attachments as $attachment ) {
421
- self::add_applied_watermark( $attachment->ID, $watermark_id );
422
- }
423
- }
424
-
425
- return $watermark_id;
426
-
427
- }
428
-
429
- /**
430
- * Add watermark to attachment meta
431
- *
432
- * @param integer $attachment_id Attachment ID.
433
- * @param integer $watermark_id Watermark ID.
434
- * @return void
435
- */
436
- private static function add_applied_watermark( $attachment_id, $watermark_id ) {
437
-
438
- $meta = get_post_meta( $attachment_id, '_ew_applied_watermarks', true );
439
-
440
- if ( ! is_array( $meta ) ) {
441
- $meta = [];
442
- }
443
-
444
- if ( ! in_array( $watermark_id, $meta, true ) ) {
445
- $meta[] = $watermark_id;
446
- update_post_meta( $attachment_id, '_ew_applied_watermarks', $meta );
447
- }
448
-
449
- }
450
-
451
- /**
452
- * Computes alignment based on position_x and position_y
453
- *
454
- * @param string $x Horizontal position.
455
- * @param string $y Vertical position.
456
- * @return string
457
- */
458
- private static function get_alignment( $x, $y ) {
459
- $alignment = null;
460
-
461
- if ( 'mdl' === $y || 'middle' === $y ) {
462
- $y = null;
463
- }
464
-
465
- if ( 'btm' === $y ) {
466
- $y = 'bottom';
467
- }
468
-
469
- if ( 'lft' === $x ) {
470
- $x = 'left';
471
- }
472
-
473
- if ( 'ctr' === $x || 'center' === $x ) {
474
- $x = null;
475
- }
476
-
477
- if ( 'rgt' === $x ) {
478
- $x = 'right';
479
- }
480
-
481
- $alignment = $y . '-' . $x;
482
-
483
- if ( null === $x && null === $y ) {
484
- $alignment = 'center';
485
- } else {
486
- $alignment = trim( $y . '-' . $x, '-' );
487
- }
488
-
489
- return $alignment;
490
-
491
- }
492
- }
 
 
1
+ <?php
2
+ /**
3
+ * Installer class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Core;
9
+
10
+ use EasyWatermark\Watermark\Watermark;
11
+
12
+ /**
13
+ * Helper class providing install, uninstall, update methods
14
+ */
15
+ class Installer {
16
+
17
+ /**
18
+ * Watermarked attachments
19
+ *
20
+ * @var array
21
+ */
22
+ private static $watermarked_attachments = [];
23
+
24
+ /**
25
+ * Activates plugin
26
+ *
27
+ * @return void
28
+ */
29
+ public static function activate() {
30
+
31
+ $version = get_option( Plugin::get()->get_slug() . '-version', false );
32
+
33
+ if ( ! $version ) {
34
+ // First activation.
35
+ self::install();
36
+ }
37
+
38
+ $admin = get_role( 'administrator' );
39
+
40
+ $admin->add_cap( 'edit_watermark' );
41
+ $admin->add_cap( 'edit_watermarks' );
42
+ $admin->add_cap( 'edit_others_watermarks' );
43
+ $admin->add_cap( 'delete_watermarks' );
44
+ $admin->add_cap( 'delete_others_watermarks' );
45
+ $admin->add_cap( 'apply_watermark' );
46
+
47
+ $editor = get_role( 'editor' );
48
+
49
+ $editor->add_cap( 'edit_watermark' );
50
+ $editor->add_cap( 'edit_watermarks' );
51
+ $editor->add_cap( 'edit_others_watermarks' );
52
+ $editor->add_cap( 'delete_watermarks' );
53
+ $editor->add_cap( 'delete_others_watermarks' );
54
+ $editor->add_cap( 'apply_watermark' );
55
+
56
+ $author = get_role( 'author' );
57
+
58
+ $author->add_cap( 'edit_watermark' );
59
+ $author->add_cap( 'edit_watermarks' );
60
+ $author->add_cap( 'delete_watermarks' );
61
+ $author->add_cap( 'apply_watermark' );
62
+
63
+ }
64
+
65
+ /**
66
+ * Deactivates plugin
67
+ *
68
+ * @return void
69
+ */
70
+ public static function deactivate() {
71
+ delete_option( 'easy-watermark-first-booted' );
72
+ flush_rewrite_rules();
73
+ }
74
+
75
+ /**
76
+ * Installs plugin
77
+ * This method is called on the first activation
78
+ *
79
+ * @return void
80
+ */
81
+ public static function install() {}
82
+
83
+ /**
84
+ * Uninstalls plugin
85
+ *
86
+ * @return void
87
+ */
88
+ public static function uninstall() {
89
+
90
+ delete_option( Plugin::get()->get_slug() . '-version' );
91
+
92
+ $roles = get_editable_roles();
93
+
94
+ foreach ( $roles as $role => $details ) {
95
+ $role = get_role( $role );
96
+
97
+ $role->remove_cap( 'edit_watermark' );
98
+ $role->remove_cap( 'read_watermark' );
99
+ $role->remove_cap( 'delete_watermark' );
100
+ $role->remove_cap( 'edit_watermarks' );
101
+ $role->remove_cap( 'edit_others_watermarks' );
102
+ $role->remove_cap( 'publish_watermarks' );
103
+ $role->remove_cap( 'read_private_watermarks' );
104
+ $role->remove_cap( 'apply_watermark' );
105
+ }
106
+
107
+ $watermarks = Watermark::get_all();
108
+
109
+ foreach ( $watermarks as $watermark ) {
110
+ $result = wp_delete_post( $watermark->ID, true );
111
+ }
112
+
113
+ }
114
+
115
+ /**
116
+ * Updates plugin
117
+ *
118
+ * @param string $from Previous active version.
119
+ * @param array $defaults Default settings.
120
+ * @return void
121
+ */
122
+ public static function update( $from, $defaults ) {
123
+
124
+ flush_rewrite_rules();
125
+
126
+ update_option( Plugin::get()->get_slug() . '-version', Plugin::get()->get_version() );
127
+
128
+ if ( version_compare( $from, '1.0.0', '>=' ) ) {
129
+ self::update_attachment_meta();
130
+ return;
131
+ }
132
+
133
+ $plugin_slug = Plugin::get()->get_slug();
134
+ $settings = [];
135
+
136
+ if ( version_compare( $from, '0.1.1', '>' ) ) {
137
+ $settings['general'] = get_option( $plugin_slug . '-settings-general' );
138
+ $settings['image'] = get_option( $plugin_slug . '-settings-image' );
139
+ $settings['text'] = get_option( $plugin_slug . '-settings-text' );
140
+
141
+ delete_option( $plugin_slug . '-settings-general' );
142
+ delete_option( $plugin_slug . '-settings-image' );
143
+ delete_option( $plugin_slug . '-settings-text' );
144
+ } else {
145
+ $old_settings = get_option( $plugin_slug . '-settings' );
146
+
147
+ delete_option( $plugin_slug . '-settings' );
148
+
149
+ $general = [
150
+ 'auto_add' => $old_settings['auto_add'],
151
+ 'image_types' => $old_settings['image_types'],
152
+ ];
153
+
154
+ switch ( $from ) {
155
+ case '0.1.1':
156
+ $image = [
157
+ 'watermark_url' => $old_settings['image']['url'],
158
+ 'watermark_id' => $old_settings['image']['id'],
159
+ 'watermark_path' => $old_settings['image']['path'],
160
+ 'watermark_mime' => $old_settings['image']['mime'],
161
+ 'position_x' => $old_settings['image']['position_x'],
162
+ 'position_y' => $old_settings['image']['position_y'],
163
+ 'offset_x' => $old_settings['image']['offset_x'],
164
+ 'offset_y' => $old_settings['image']['offset_y'],
165
+ 'opacity' => $old_settings['image']['opacity'],
166
+ ];
167
+ break;
168
+ default:
169
+ $image = [
170
+ 'watermark_url' => $old_settings['image']['url'],
171
+ 'watermark_id' => $old_settings['image']['id'],
172
+ 'watermark_path' => $old_settings['image']['path'],
173
+ 'watermark_mime' => $old_settings['image']['mime'],
174
+ 'position_x' => $old_settings['image']['position-horizontal'],
175
+ 'position_y' => $old_settings['image']['position-vert'],
176
+ 'offset_x' => $old_settings['image']['offset-horizontal'],
177
+ 'offset_y' => $old_settings['image']['offset-vert'],
178
+ 'opacity' => $old_settings['image']['alpha'],
179
+ ];
180
+ break;
181
+ }
182
+
183
+ $settings = [
184
+ 'general' => $general,
185
+ 'image' => $image,
186
+ 'text' => [],
187
+ ];
188
+
189
+ delete_option( $plugin_slug . '-settings' );
190
+ }
191
+
192
+ $settings['image']['alignment'] = self::get_alignment( $settings['image']['position_x'], $settings['image']['position_y'] );
193
+ $settings['text']['alignment'] = self::get_alignment( $settings['text']['position_x'], $settings['text']['position_y'] );
194
+
195
+ $watermark_defaults = Watermark::get_defaults();
196
+
197
+ $watermark_defaults['auto_add'] = $settings['general']['auto_add'];
198
+
199
+ if ( isset( $settings['general']['auto_add_perm'] ) ) {
200
+ $watermark_defaults['auto_add_all'] = $settings['general']['auto_add_perm'];
201
+ }
202
+
203
+ if ( isset( $settings['general']['image_types'] ) ) {
204
+ $watermark_defaults['image_types'] = $settings['general']['image_types'];
205
+ }
206
+
207
+ if ( isset( $settings['general']['image_sizes'] ) ) {
208
+ $watermark_defaults['image_sizes'] = $settings['general']['image_sizes'];
209
+ }
210
+
211
+ if ( isset( $settings['general']['allowed_post_types'] ) ) {
212
+ $watermark_defaults['post_types'] = $settings['general']['allowed_post_types'];
213
+ }
214
+
215
+ if ( isset( $settings['general']['jpg_quality'] ) ) {
216
+ $defaults['general']['jpeg_quality'] = $settings['general']['jpg_quality'];
217
+ }
218
+
219
+ update_option( Plugin::get()->get_slug() . '-settings', $defaults );
220
+
221
+ if ( isset( $settings['image']['watermark_id'] ) && ! empty( $settings['image']['watermark_id'] ) ) {
222
+ self::insert_image_watermark( $watermark_defaults, $settings );
223
+ }
224
+
225
+ if ( ! empty( $settings['text']['text'] ) ) {
226
+ self::insert_text_watermark( $watermark_defaults, $settings );
227
+ }
228
+
229
+ self::update_backup_info();
230
+
231
+ }
232
+
233
+ /**
234
+ * Update attachment meta
235
+ *
236
+ * @return void
237
+ */
238
+ private static function update_attachment_meta() {
239
+ global $wpdb;
240
+
241
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery
242
+ $meta = $wpdb->get_results( $wpdb->prepare( "SELECT `post_id`, `meta_value` FROM {$wpdb->postmeta} WHERE `meta_key` = %s", '_ew_applied_watermarks' ) );
243
+
244
+ foreach ( $meta as $entry ) {
245
+ $value = maybe_unserialize( $entry->meta_value );
246
+
247
+ if ( is_array( $value ) ) {
248
+ $new_value = [];
249
+
250
+ foreach ( $value as $watermark_id ) {
251
+ $watermark = Watermark::get( $watermark_id );
252
+
253
+ if ( $watermark ) {
254
+ $new_value[ $watermark_id ] = $watermark->post_title;
255
+ }
256
+ }
257
+
258
+ if ( $new_value ) {
259
+ update_post_meta( $entry->post_id, '_ew_applied_watermarks', $new_value );
260
+ } else {
261
+ delete_post_meta( $entry->post_id, '_ew_applied_watermarks' );
262
+ }
263
+ }
264
+ }
265
+ }
266
+
267
+ /**
268
+ * Updates backup info
269
+ *
270
+ * @return void
271
+ */
272
+ private static function update_backup_info() {
273
+
274
+ $attachments = get_posts( [
275
+ 'posts_per_page' => -1,
276
+ 'post_type' => 'attachment',
277
+ 'meta_query' => [
278
+ [
279
+ 'key' => '_ew_backup_file',
280
+ 'compare' => 'EXISTS',
281
+ ],
282
+ ],
283
+ ] );
284
+
285
+ foreach ( $attachments as $attachment ) {
286
+ update_post_meta( $attachment->ID, '_ew_has_backup', true );
287
+ }
288
+
289
+ }
290
+
291
+ /**
292
+ * Updates backup info
293
+ *
294
+ * @return array
295
+ */
296
+ private static function get_watermarked_attachments() {
297
+
298
+ if ( ! self::$watermarked_attachments ) {
299
+ self::$watermarked_attachments = get_posts( [
300
+ 'posts_per_page' => -1,
301
+ 'post_type' => 'attachment',
302
+ 'meta_key' => '_ew_watermarked',
303
+ 'meta_value' => '1',
304
+ ] );
305
+ }
306
+
307
+ return self::$watermarked_attachments;
308
+
309
+ }
310
+
311
+ /**
312
+ * Inserts image watermark based on previous version settings
313
+ *
314
+ * @param array $defaults Default watermark params.
315
+ * @param array $settings Watermark settings.
316
+ * @return integer
317
+ */
318
+ private static function insert_image_watermark( $defaults, $settings ) {
319
+
320
+ $image_settings = [
321
+ 'type' => 'image',
322
+ 'attachment_id' => $settings['image']['watermark_id'],
323
+ 'mime_type' => $settings['image']['watermark_mime'],
324
+ 'url' => $settings['image']['watermark_url'],
325
+ 'alignment' => $settings['image']['alignment'],
326
+ 'opacity' => $settings['image']['opacity'],
327
+ 'offset' => [
328
+ 'x' => [
329
+ 'value' => intval( $settings['image']['offset_x'] ),
330
+ 'unit' => ( '%' === substr( $settings['image']['offset_x'], -1 ) ) ? '%' : 'px',
331
+ ],
332
+ 'y' => [
333
+ 'value' => intval( $settings['image']['offset_y'] ),
334
+ 'unit' => ( '%' === substr( $settings['image']['offset_y'], -1 ) ) ? '%' : 'px',
335
+ ],
336
+ ],
337
+ ];
338
+
339
+ if ( isset( $settings['image']['scale_mode'] ) ) {
340
+ $image_settings['scaling_mode'] = $settings['image']['scale_mode'];
341
+
342
+ if ( 'fit' === $image_settings['scaling_mode'] ) {
343
+ $image_settings['scaling_mode'] = 'contain';
344
+ }
345
+
346
+ if ( 'fill' === $image_settings['scaling_mode'] ) {
347
+ $image_settings['scaling_mode'] = 'cover';
348
+ }
349
+ }
350
+
351
+ if ( isset( $settings['image']['scale_to_smaller'] ) ) {
352
+ $image_settings['scale_down_only'] = $settings['image']['scale_to_smaller'];
353
+ }
354
+
355
+ if ( isset( $settings['image']['scale'] ) ) {
356
+ $image_settings['scale'] = $settings['image']['scale'];
357
+ }
358
+
359
+ $image_settings = array_merge( $defaults, $image_settings );
360
+
361
+ $watermark_id = wp_insert_post( [
362
+ 'post_title' => __( 'Image Watermark', 'easy-watermark' ),
363
+ 'post_type' => 'watermark',
364
+ 'post_status' => 'publish',
365
+ 'watermark' => $image_settings,
366
+ ] );
367
+
368
+ if ( in_array( $settings['general']['watermark_type'], [ '1', '3' ], true ) ) {
369
+ $attachments = self::get_watermarked_attachments();
370
+
371
+ foreach ( $attachments as $attachment ) {
372
+ self::add_applied_watermark( $attachment->ID, $watermark_id );
373
+ }
374
+ }
375
+
376
+ return $watermark_id;
377
+
378
+ }
379
+
380
+ /**
381
+ * Inserts text watermark based on previous version settings
382
+ *
383
+ * @param array $defaults Default watermark params.
384
+ * @param array $settings Watermark settings.
385
+ * @return integer
386
+ */
387
+ private static function insert_text_watermark( $defaults, $settings ) {
388
+
389
+ $text_settings = [
390
+ 'type' => 'text',
391
+ 'text' => $settings['text']['text'],
392
+ 'font' => $settings['text']['font'],
393
+ 'text_color' => $settings['text']['color'],
394
+ 'text_size' => $settings['text']['size'],
395
+ 'text_angle' => $settings['text']['angle'],
396
+ 'opacity' => $settings['text']['opacity'],
397
+ 'alignment' => $settings['text']['alignment'],
398
+ 'offset' => [
399
+ 'x' => [
400
+ 'value' => intval( $settings['text']['offset_x'] ),
401
+ 'unit' => ( '%' === substr( $settings['text']['offset_x'], -1 ) ) ? '%' : 'px',
402
+ ],
403
+ 'y' => [
404
+ 'value' => intval( $settings['text']['offset_y'] ),
405
+ 'unit' => ( '%' === substr( $settings['text']['offset_y'], -1 ) ) ? '%' : 'px',
406
+ ],
407
+ ],
408
+ ];
409
+
410
+ $text_settings = array_merge( $defaults, $text_settings );
411
+
412
+ $watermark_id = wp_insert_post( [
413
+ 'post_title' => __( 'Text Watermark', 'easy-watermark' ),
414
+ 'post_type' => 'watermark',
415
+ 'post_status' => 'publish',
416
+ 'watermark' => $text_settings,
417
+ ] );
418
+
419
+ if ( in_array( $settings['general']['watermark_type'], [ '2', '3' ], true ) ) {
420
+ $attachments = self::get_watermarked_attachments();
421
+
422
+ foreach ( $attachments as $attachment ) {
423
+ self::add_applied_watermark( $attachment->ID, $watermark_id );
424
+ }
425
+ }
426
+
427
+ return $watermark_id;
428
+
429
+ }
430
+
431
+ /**
432
+ * Add watermark to attachment meta
433
+ *
434
+ * @param integer $attachment_id Attachment ID.
435
+ * @param integer $watermark_id Watermark ID.
436
+ * @return void
437
+ */
438
+ private static function add_applied_watermark( $attachment_id, $watermark_id ) {
439
+
440
+ $meta = get_post_meta( $attachment_id, '_ew_applied_watermarks', true );
441
+
442
+ if ( ! is_array( $meta ) ) {
443
+ $meta = [];
444
+ }
445
+
446
+ if ( ! in_array( $watermark_id, $meta, true ) ) {
447
+ $meta[] = $watermark_id;
448
+ update_post_meta( $attachment_id, '_ew_applied_watermarks', $meta );
449
+ }
450
+
451
+ }
452
+
453
+ /**
454
+ * Computes alignment based on position_x and position_y
455
+ *
456
+ * @param string $x Horizontal position.
457
+ * @param string $y Vertical position.
458
+ * @return string
459
+ */
460
+ private static function get_alignment( $x, $y ) {
461
+ $alignment = null;
462
+
463
+ if ( 'mdl' === $y || 'middle' === $y ) {
464
+ $y = null;
465
+ }
466
+
467
+ if ( 'btm' === $y ) {
468
+ $y = 'bottom';
469
+ }
470
+
471
+ if ( 'lft' === $x ) {
472
+ $x = 'left';
473
+ }
474
+
475
+ if ( 'ctr' === $x || 'center' === $x ) {
476
+ $x = null;
477
+ }
478
+
479
+ if ( 'rgt' === $x ) {
480
+ $x = 'right';
481
+ }
482
+
483
+ $alignment = $y . '-' . $x;
484
+
485
+ if ( null === $x && null === $y ) {
486
+ $alignment = 'center';
487
+ } else {
488
+ $alignment = trim( $y . '-' . $x, '-' );
489
+ }
490
+
491
+ return $alignment;
492
+
493
+ }
494
+ }
src/classes/Core/Plugin.php CHANGED
@@ -10,8 +10,7 @@ namespace EasyWatermark\Core;
10
  use EasyWatermark\AttachmentProcessor\AttachmentProcessorGD;
11
  use EasyWatermark\Backup\Manager as BackupManager;
12
  use EasyWatermark\Dashboard\Dashboard;
13
- use EasyWatermark\Features\AutoWatermarkSwitch;
14
- use EasyWatermark\Features\SrcsetFilter;
15
  use EasyWatermark\Metaboxes;
16
  use EasyWatermark\Placeholders\Defaults as DefaultPlaceholders;
17
  use EasyWatermark\Settings\Settings;
@@ -96,10 +95,14 @@ class Plugin extends Singleton {
96
  public function setup() {
97
 
98
  new DefaultPlaceholders();
 
 
 
 
 
 
99
  new WatermarkPostType();
100
- new AutoWatermarkSwitch();
101
  new Dashboard();
102
- new SrcsetFilter( $this );
103
  new Assets( $this );
104
 
105
  $this->get_watermark_handler();
@@ -151,14 +154,14 @@ class Plugin extends Singleton {
151
  add_rewrite_tag( '%image_size%', '([^./-]+)' );
152
 
153
  add_rewrite_rule(
154
- 'easy-watermark-preview/([^/.-]+)-([0-9]+)-([^/.]+).(jpg|png)?',
155
- 'index.php?easy_watermark_preview=$matches[1]&watermark_id=$matches[2]&image_size=$matches[3]&format=$matches[4]',
156
  'top'
157
  );
158
 
159
  add_rewrite_rule(
160
- 'easy-watermark-preview/([^/.-]+)-([0-9]+).(jpg|png)?',
161
- 'index.php?easy_watermark_preview=$matches[1]&watermark_id=$matches[2]&format=$matches[3]',
162
  'top'
163
  );
164
 
@@ -169,43 +172,10 @@ class Plugin extends Singleton {
169
  Installer::update( $last_version, $settings->get_settings() );
170
  }
171
 
172
- }
173
-
174
- /**
175
- * Performs actions on shutdown
176
- *
177
- * @action shutdown
178
- *
179
- * @return void
180
- */
181
- public function shutdown() {
182
  if ( ! get_option( 'easy-watermark-first-booted' ) ) {
183
  flush_rewrite_rules();
184
  update_option( 'easy-watermark-first-booted', true );
185
  }
186
- }
187
-
188
- /**
189
- * Initiates plugin
190
- *
191
- * @action parse_request
192
- *
193
- * @param WP $wp WP object.
194
- * @return void
195
- */
196
- public function parse_request( $wp ) {
197
-
198
- if ( ! array_key_exists( 'easy_watermark_preview', $wp->query_vars ) ) {
199
- return;
200
- }
201
-
202
- $preview = new Preview( $this->get_watermark_handler() );
203
- $type = $wp->query_vars['easy_watermark_preview'];
204
- $watermark_id = $wp->query_vars['watermark_id'];
205
- $format = $wp->query_vars['format'];
206
- $size = isset( $wp->query_vars['image_size'] ) ? $wp->query_vars['image_size'] : 'full';
207
-
208
- $preview->show( $type, $watermark_id, $format, $size );
209
 
210
  }
211
 
10
  use EasyWatermark\AttachmentProcessor\AttachmentProcessorGD;
11
  use EasyWatermark\Backup\Manager as BackupManager;
12
  use EasyWatermark\Dashboard\Dashboard;
13
+ use EasyWatermark\Features;
 
14
  use EasyWatermark\Metaboxes;
15
  use EasyWatermark\Placeholders\Defaults as DefaultPlaceholders;
16
  use EasyWatermark\Settings\Settings;
95
  public function setup() {
96
 
97
  new DefaultPlaceholders();
98
+
99
+ new Features\AutoWatermarkSwitch();
100
+ new Features\CacheBusting();
101
+ new Features\SrcsetFilter();
102
+ new Features\WatermarkPreview( $this );
103
+
104
  new WatermarkPostType();
 
105
  new Dashboard();
 
106
  new Assets( $this );
107
 
108
  $this->get_watermark_handler();
154
  add_rewrite_tag( '%image_size%', '([^./-]+)' );
155
 
156
  add_rewrite_rule(
157
+ 'easy-watermark-preview/([^/.-]+)-([0-9]+)-([^/.]+)?',
158
+ 'index.php?easy_watermark_preview=$matches[1]&watermark_id=$matches[2]&image_size=$matches[3]',
159
  'top'
160
  );
161
 
162
  add_rewrite_rule(
163
+ 'easy-watermark-preview/([^/.-]+)-([0-9]+)?',
164
+ 'index.php?easy_watermark_preview=$matches[1]&watermark_id=$matches[2]',
165
  'top'
166
  );
167
 
172
  Installer::update( $last_version, $settings->get_settings() );
173
  }
174
 
 
 
 
 
 
 
 
 
 
 
175
  if ( ! get_option( 'easy-watermark-first-booted' ) ) {
176
  flush_rewrite_rules();
177
  update_option( 'easy-watermark-first-booted', true );
178
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
 
180
  }
181
 
src/classes/Core/View.php CHANGED
@@ -1,131 +1,131 @@
1
- <?php
2
- /**
3
- * View class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Core;
9
-
10
- /**
11
- * View class
12
- */
13
- class View {
14
- /**
15
- * View name
16
- *
17
- * @var string
18
- */
19
- private $name;
20
-
21
- /**
22
- * Params
23
- *
24
- * @var array
25
- */
26
- private $params = [];
27
-
28
- /**
29
- * Views path
30
- *
31
- * @var string
32
- */
33
- private $path;
34
-
35
- /**
36
- * Constructor
37
- *
38
- * @param string $name View name.
39
- * @param array $params View params.
40
- */
41
- public function __construct( $name = '', $params = [] ) {
42
- $this->name = $name;
43
- $this->params = $params;
44
-
45
- $this->path = EW_DIR_PATH . '/src/views/';
46
- }
47
-
48
- /**
49
- * Sets view name
50
- *
51
- * @param string $name View name.
52
- * @return void
53
- */
54
- public function set_name( $name ) {
55
- $this->name = $name;
56
- }
57
-
58
- /**
59
- * Sets single param
60
- *
61
- * @param string $key Param name.
62
- * @param mixed $value Param value.
63
- * @return mixed previous value if exists or null
64
- */
65
- public function set_param( $key, $value ) {
66
- $previous = isset( $this->params[ $key ] ) ? $this->params[ $key ] : null;
67
-
68
- $this->params[ $key ] = $value;
69
-
70
- return $previous;
71
- }
72
-
73
- /**
74
- * Sets params
75
- *
76
- * @param array $params View params.
77
- * @return array previous params
78
- */
79
- public function set_params( $params ) {
80
- $previous = $this->params;
81
-
82
- $this->params = (array) $params;
83
-
84
- return $previous;
85
- }
86
-
87
- /**
88
- * Renders view
89
- *
90
- * @return string
91
- */
92
- public function render() {
93
- if ( ! is_string( $this->name ) ) {
94
- /* translators: argument type */
95
- wp_die( sprintf( esc_html__( 'View name should be a string, %s given.', 'easy-watermark' ), esc_html( gettype( $this->name ) ) ), esc_html__( 'Invalid view name type', 'easy-watermark' ) );
96
- }
97
-
98
- $filename = $this->path . $this->name . '.php';
99
-
100
- if ( ! file_exists( $filename ) ) {
101
- /* translators: view name */
102
- wp_die( sprintf( esc_html__( 'View file does not exist: %s', 'easy-watermark' ), esc_html( $this->name ) ), esc_html__( 'View not found', 'easy-watermark' ) );
103
- }
104
-
105
- ob_start();
106
-
107
- extract( $this->params ); // phpcs:ignore
108
-
109
- include $filename;
110
-
111
- return ob_get_clean();
112
- }
113
-
114
- /**
115
- * Displays view
116
- *
117
- * @return void
118
- */
119
- public function display() {
120
- echo $this->render(); // phpcs:ignore
121
- }
122
-
123
- /**
124
- * Magic method for object to string conversion
125
- *
126
- * @return string
127
- */
128
- public function __toString() {
129
- return $this->render();
130
- }
131
- }
1
+ <?php
2
+ /**
3
+ * View class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Core;
9
+
10
+ /**
11
+ * View class
12
+ */
13
+ class View {
14
+ /**
15
+ * View name
16
+ *
17
+ * @var string
18
+ */
19
+ private $name;
20
+
21
+ /**
22
+ * Params
23
+ *
24
+ * @var array
25
+ */
26
+ private $params = [];
27
+
28
+ /**
29
+ * Views path
30
+ *
31
+ * @var string
32
+ */
33
+ private $path;
34
+
35
+ /**
36
+ * Constructor
37
+ *
38
+ * @param string $name View name.
39
+ * @param array $params View params.
40
+ */
41
+ public function __construct( $name = '', $params = [] ) {
42
+ $this->name = $name;
43
+ $this->params = $params;
44
+
45
+ $this->path = EW_DIR_PATH . '/src/views/';
46
+ }
47
+
48
+ /**
49
+ * Sets view name
50
+ *
51
+ * @param string $name View name.
52
+ * @return void
53
+ */
54
+ public function set_name( $name ) {
55
+ $this->name = $name;
56
+ }
57
+
58
+ /**
59
+ * Sets single param
60
+ *
61
+ * @param string $key Param name.
62
+ * @param mixed $value Param value.
63
+ * @return mixed previous value if exists or null
64
+ */
65
+ public function set_param( $key, $value ) {
66
+ $previous = isset( $this->params[ $key ] ) ? $this->params[ $key ] : null;
67
+
68
+ $this->params[ $key ] = $value;
69
+
70
+ return $previous;
71
+ }
72
+
73
+ /**
74
+ * Sets params
75
+ *
76
+ * @param array $params View params.
77
+ * @return array previous params
78
+ */
79
+ public function set_params( $params ) {
80
+ $previous = $this->params;
81
+
82
+ $this->params = (array) $params;
83
+
84
+ return $previous;
85
+ }
86
+
87
+ /**
88
+ * Renders view
89
+ *
90
+ * @return string
91
+ */
92
+ public function render() {
93
+ if ( ! is_string( $this->name ) ) {
94
+ /* translators: argument type */
95
+ wp_die( sprintf( esc_html__( 'View name should be a string, %s given.', 'easy-watermark' ), esc_html( gettype( $this->name ) ) ), esc_html__( 'Invalid view name type', 'easy-watermark' ) );
96
+ }
97
+
98
+ $filename = $this->path . $this->name . '.php';
99
+
100
+ if ( ! file_exists( $filename ) ) {
101
+ /* translators: view name */
102
+ wp_die( sprintf( esc_html__( 'View file does not exist: %s', 'easy-watermark' ), esc_html( $this->name ) ), esc_html__( 'View not found', 'easy-watermark' ) );
103
+ }
104
+
105
+ ob_start();
106
+
107
+ extract( $this->params ); // phpcs:ignore
108
+
109
+ include $filename;
110
+
111
+ return ob_get_clean();
112
+ }
113
+
114
+ /**
115
+ * Displays view
116
+ *
117
+ * @return void
118
+ */
119
+ public function display() {
120
+ echo $this->render(); // phpcs:ignore
121
+ }
122
+
123
+ /**
124
+ * Magic method for object to string conversion
125
+ *
126
+ * @return string
127
+ */
128
+ public function __toString() {
129
+ return $this->render();
130
+ }
131
+ }
src/classes/Dashboard/Dashboard.php CHANGED
@@ -1,162 +1,162 @@
1
- <?php
2
- /**
3
- * Settings class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Dashboard;
9
-
10
- use EasyWatermark\Core\View;
11
- use EasyWatermark\Traits\Hookable;
12
-
13
- /**
14
- * Settings class
15
- */
16
- class Dashboard {
17
-
18
- use Hookable;
19
-
20
- /**
21
- * Page hook
22
- *
23
- * @var string
24
- */
25
- private $page_hook;
26
-
27
- /**
28
- * Tabs
29
- *
30
- * @var array
31
- */
32
- private $tabs;
33
-
34
- /**
35
- * Current tab
36
- *
37
- * @var string
38
- */
39
- private $current_tab;
40
-
41
- /**
42
- * Constructor
43
- */
44
- public function __construct() {
45
-
46
- $this->hook();
47
-
48
- new Watermarks();
49
- new Settings();
50
- new Permissions();
51
- new Tools();
52
-
53
- }
54
-
55
- /**
56
- * Adds options page
57
- *
58
- * @action admin_menu
59
- *
60
- * @return void
61
- */
62
- public function add_options_page() {
63
-
64
- $this->page_hook = add_management_page(
65
- __( 'Easy Watermark', 'easy-watermark' ),
66
- __( 'Easy Watermark', 'easy-watermark' ),
67
- 'apply_watermark',
68
- 'easy-watermark',
69
- [ $this, 'page_content' ]
70
- );
71
-
72
- }
73
-
74
- /**
75
- * Returns page hook
76
- *
77
- * @return string
78
- */
79
- public function get_page_hook() {
80
- return $this->page_hook;
81
- }
82
-
83
- /**
84
- * Displats options page content
85
- *
86
- * @return void
87
- */
88
- public function page_content() {
89
-
90
- $current_tab = $this->get_current_tab();
91
- $tabs = $this->get_tabs();
92
- $args = apply_filters( "easy-watermark/dashboard/{$current_tab}/view-args", [] );
93
- $content = new View( "dashboard/pages/{$current_tab}", $args );
94
-
95
- // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
96
- echo new View( 'dashboard/wrap', [
97
- 'tabs' => $tabs,
98
- 'current_tab' => $current_tab,
99
- 'content' => $content,
100
- ] );
101
- // phpcs:enable
102
-
103
- }
104
-
105
- /**
106
- * Display admin notices
107
- *
108
- * @action admin_notices
109
- *
110
- * @return void
111
- */
112
- public function admin_notices() {
113
- if ( get_current_screen()->id !== $this->get_page_hook() ) {
114
- return;
115
- }
116
-
117
- $tab = $this->get_current_tab();
118
-
119
- do_action( 'easy-watermark/dashboard/notices', $tab );
120
- do_action( "easy-watermark/dashboard/{$tab}/notices" );
121
- }
122
-
123
- /**
124
- * Returns tabs array
125
- *
126
- * @return array
127
- */
128
- private function get_tabs() {
129
- if ( ! $this->tabs ) {
130
- $this->tabs = apply_filters( 'easy-watermark/dashboard/tabs', [] );
131
-
132
- uasort( $this->tabs, function( $a, $b ) {
133
- return $a['priority'] - $b['priority'];
134
- } );
135
- }
136
-
137
- return $this->tabs;
138
- }
139
-
140
- /**
141
- * Returns tabs array
142
- *
143
- * @return array
144
- */
145
- private function get_current_tab() {
146
- if ( ! $this->current_tab ) {
147
- $tabs = $this->get_tabs();
148
-
149
- // phpcs:ignore WordPress.Security.NonceVerification.Recommended
150
- $tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : null;
151
-
152
- if ( null === $tab || ! array_key_exists( $tab, $tabs ) ) {
153
- reset( $tabs );
154
- $tab = key( $tabs );
155
- }
156
-
157
- $this->current_tab = $tab;
158
- }
159
-
160
- return $this->current_tab;
161
- }
162
- }
1
+ <?php
2
+ /**
3
+ * Settings class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Dashboard;
9
+
10
+ use EasyWatermark\Core\View;
11
+ use EasyWatermark\Traits\Hookable;
12
+
13
+ /**
14
+ * Settings class
15
+ */
16
+ class Dashboard {
17
+
18
+ use Hookable;
19
+
20
+ /**
21
+ * Page hook
22
+ *
23
+ * @var string
24
+ */
25
+ private $page_hook;
26
+
27
+ /**
28
+ * Tabs
29
+ *
30
+ * @var array
31
+ */
32
+ private $tabs;
33
+
34
+ /**
35
+ * Current tab
36
+ *
37
+ * @var string
38
+ */
39
+ private $current_tab;
40
+
41
+ /**
42
+ * Constructor
43
+ */
44
+ public function __construct() {
45
+
46
+ $this->hook();
47
+
48
+ new Watermarks();
49
+ new Settings();
50
+ new Permissions();
51
+ new Tools();
52
+
53
+ }
54
+
55
+ /**
56
+ * Adds options page
57
+ *
58
+ * @action admin_menu
59
+ *
60
+ * @return void
61
+ */
62
+ public function add_options_page() {
63
+
64
+ $this->page_hook = add_management_page(
65
+ __( 'Easy Watermark', 'easy-watermark' ),
66
+ __( 'Easy Watermark', 'easy-watermark' ),
67
+ 'apply_watermark',
68
+ 'easy-watermark',
69
+ [ $this, 'page_content' ]
70
+ );
71
+
72
+ }
73
+
74
+ /**
75
+ * Returns page hook
76
+ *
77
+ * @return string
78
+ */
79
+ public function get_page_hook() {
80
+ return $this->page_hook;
81
+ }
82
+
83
+ /**
84
+ * Displats options page content
85
+ *
86
+ * @return void
87
+ */
88
+ public function page_content() {
89
+
90
+ $current_tab = $this->get_current_tab();
91
+ $tabs = $this->get_tabs();
92
+ $args = apply_filters( "easy-watermark/dashboard/{$current_tab}/view-args", [] );
93
+ $content = new View( "dashboard/pages/{$current_tab}", $args );
94
+
95
+ // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
96
+ echo new View( 'dashboard/wrap', [
97
+ 'tabs' => $tabs,
98
+ 'current_tab' => $current_tab,
99
+ 'content' => $content,
100
+ ] );
101
+ // phpcs:enable
102
+
103
+ }
104
+
105
+ /**
106
+ * Display admin notices
107
+ *
108
+ * @action admin_notices
109
+ *
110
+ * @return void
111
+ */
112
+ public function admin_notices() {
113
+ if ( get_current_screen()->id !== $this->get_page_hook() ) {
114
+ return;
115
+ }
116
+
117
+ $tab = $this->get_current_tab();
118
+
119
+ do_action( 'easy-watermark/dashboard/notices', $tab );
120
+ do_action( "easy-watermark/dashboard/{$tab}/notices" );
121
+ }
122
+
123
+ /**
124
+ * Returns tabs array
125
+ *
126
+ * @return array
127
+ */
128
+ private function get_tabs() {
129
+ if ( ! $this->tabs ) {
130
+ $this->tabs = apply_filters( 'easy-watermark/dashboard/tabs', [] );
131
+
132
+ uasort( $this->tabs, function( $a, $b ) {
133
+ return $a['priority'] - $b['priority'];
134
+ } );
135
+ }
136
+
137
+ return $this->tabs;
138
+ }
139
+
140
+ /**
141
+ * Returns tabs array
142
+ *
143
+ * @return array
144
+ */
145
+ private function get_current_tab() {
146
+ if ( ! $this->current_tab ) {
147
+ $tabs = $this->get_tabs();
148
+
149
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended
150
+ $tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : null;
151
+
152
+ if ( null === $tab || ! array_key_exists( $tab, $tabs ) ) {
153
+ reset( $tabs );
154
+ $tab = key( $tabs );
155
+ }
156
+
157
+ $this->current_tab = $tab;
158
+ }
159
+
160
+ return $this->current_tab;
161
+ }
162
+ }
src/classes/Dashboard/Permissions.php CHANGED
@@ -1,134 +1,134 @@
1
- <?php
2
- /**
3
- * Settings class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Dashboard;
9
-
10
- use EasyWatermark\Core\View;
11
-
12
- /**
13
- * Settings class
14
- */
15
- class Permissions extends Page {
16
-
17
- /**
18
- * Constructor
19
- */
20
- public function __construct() {
21
- $this->permission = 'manage_options';
22
- parent::__construct( __( 'Permissions', 'easy-watermark' ), null, 100 );
23
- }
24
-
25
- /**
26
- * Display admin notices
27
- *
28
- * @action admin_init
29
- *
30
- * @return void
31
- */
32
- public function setup_permissions() {
33
-
34
- // phpcs:disable WordPress.Security.ValidatedSanitizedInput
35
- if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'easy-watermark-permissions' ) ) {
36
- return;
37
- }
38
-
39
- if ( ! isset( $_REQUEST['permissions'] ) ) {
40
- return;
41
- }
42
-
43
- $permissions = $_REQUEST['permissions'];
44
-
45
- $roles = $this->get_roles();
46
-
47
- foreach ( $roles as $role_name => $details ) {
48
-
49
- $role = get_role( $role_name );
50
-
51
- $can_create = ( isset( $permissions[ $role_name ]['create'] ) && '1' === $permissions[ $role_name ]['create'] );
52
- $can_edit = ( isset( $permissions[ $role_name ]['edit'] ) && '1' === $permissions[ $role_name ]['edit'] );
53
- $can_apply = ( isset( $permissions[ $role_name ]['apply'] ) && '1' === $permissions[ $role_name ]['apply'] );
54
-
55
- $role->add_cap( 'edit_watermark', $can_create );
56
- $role->add_cap( 'edit_watermarks', $can_create );
57
- $role->add_cap( 'delete_watermark', $can_create );
58
-
59
- $role->add_cap( 'edit_others_watermarks', $can_edit );
60
- $role->add_cap( 'delete_others_watermarks', $can_edit );
61
-
62
- $role->add_cap( 'apply_watermark', $can_apply );
63
-
64
- }
65
-
66
- $redirect_url = add_query_arg( [ 'settings-updated' => true ], $_REQUEST['_wp_http_referer'] );
67
-
68
- wp_safe_redirect( $redirect_url );
69
- exit;
70
- // phpcs:enable
71
-
72
- }
73
-
74
- /**
75
- * Display admin notices
76
- *
77
- * @action easy-watermark/dashboard/permissions/notices
78
- *
79
- * @return void
80
- */
81
- public function admin_notices() {
82
-
83
- // phpcs:disable WordPress.Security
84
- if ( isset( $_GET['settings-updated'] ) ) {
85
- echo new View( 'notices/success', [
86
- 'message' => __( 'Permissions saved.', 'easy-watermark' ),
87
- ] );
88
- }
89
- // phpcs:enable
90
-
91
- }
92
-
93
- /**
94
- * Prepares arguments for view
95
- *
96
- * @filter easy-watermark/dashboard/permissions/view-args
97
- *
98
- * @param array $args View args.
99
- * @return array
100
- */
101
- public function view_args( $args ) {
102
- return [
103
- 'roles' => $this->get_roles(),
104
- ];
105
- }
106
-
107
- /**
108
- * Returns user roles array array
109
- *
110
- * @return array
111
- */
112
- public function get_roles() {
113
-
114
- $all_roles = get_editable_roles();
115
-
116
- $roles = [];
117
- foreach ( $all_roles as $role => $details ) {
118
- if ( 'administrator' === $role ) {
119
- continue;
120
- }
121
-
122
- if ( isset( $details['capabilities']['upload_files'] ) && true === $details['capabilities']['upload_files'] ) {
123
- $roles[ $role ] = array_merge( $details, [
124
- 'can_create' => ( isset( $details['capabilities']['edit_watermark'] ) && true === $details['capabilities']['edit_watermark'] ),
125
- 'can_edit' => ( isset( $details['capabilities']['edit_others_watermarks'] ) && true === $details['capabilities']['edit_others_watermarks'] ),
126
- 'can_apply' => ( isset( $details['capabilities']['apply_watermark'] ) && true === $details['capabilities']['apply_watermark'] ),
127
- ] );
128
- }
129
- }
130
-
131
- return $roles;
132
-
133
- }
134
- }
1
+ <?php
2
+ /**
3
+ * Settings class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Dashboard;
9
+
10
+ use EasyWatermark\Core\View;
11
+
12
+ /**
13
+ * Settings class
14
+ */
15
+ class Permissions extends Page {
16
+
17
+ /**
18
+ * Constructor
19
+ */
20
+ public function __construct() {
21
+ $this->permission = 'manage_options';
22
+ parent::__construct( __( 'Permissions', 'easy-watermark' ), null, 100 );
23
+ }
24
+
25
+ /**
26
+ * Display admin notices
27
+ *
28
+ * @action admin_init
29
+ *
30
+ * @return void
31
+ */
32
+ public function setup_permissions() {
33
+
34
+ // phpcs:disable WordPress.Security.ValidatedSanitizedInput
35
+ if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'easy-watermark-permissions' ) ) {
36
+ return;
37
+ }
38
+
39
+ if ( ! isset( $_REQUEST['permissions'] ) ) {
40
+ return;
41
+ }
42
+
43
+ $permissions = $_REQUEST['permissions'];
44
+
45
+ $roles = $this->get_roles();
46
+
47
+ foreach ( $roles as $role_name => $details ) {
48
+
49
+ $role = get_role( $role_name );
50
+
51
+ $can_create = ( isset( $permissions[ $role_name ]['create'] ) && '1' === $permissions[ $role_name ]['create'] );
52
+ $can_edit = ( isset( $permissions[ $role_name ]['edit'] ) && '1' === $permissions[ $role_name ]['edit'] );
53
+ $can_apply = ( isset( $permissions[ $role_name ]['apply'] ) && '1' === $permissions[ $role_name ]['apply'] );
54
+
55
+ $role->add_cap( 'edit_watermark', $can_create );
56
+ $role->add_cap( 'edit_watermarks', $can_create );
57
+ $role->add_cap( 'delete_watermark', $can_create );
58
+
59
+ $role->add_cap( 'edit_others_watermarks', $can_edit );
60
+ $role->add_cap( 'delete_others_watermarks', $can_edit );
61
+
62
+ $role->add_cap( 'apply_watermark', $can_apply );
63
+
64
+ }
65
+
66
+ $redirect_url = add_query_arg( [ 'settings-updated' => true ], $_REQUEST['_wp_http_referer'] );
67
+
68
+ wp_safe_redirect( $redirect_url );
69
+ exit;
70
+ // phpcs:enable
71
+
72
+ }
73
+
74
+ /**
75
+ * Display admin notices
76
+ *
77
+ * @action easy-watermark/dashboard/permissions/notices
78
+ *
79
+ * @return void
80
+ */
81
+ public function admin_notices() {
82
+
83
+ // phpcs:disable WordPress.Security
84
+ if ( isset( $_GET['settings-updated'] ) ) {
85
+ echo new View( 'notices/success', [
86
+ 'message' => __( 'Permissions saved.', 'easy-watermark' ),
87
+ ] );
88
+ }
89
+ // phpcs:enable
90
+
91
+ }
92
+
93
+ /**
94
+ * Prepares arguments for view
95
+ *
96
+ * @filter easy-watermark/dashboard/permissions/view-args
97
+ *
98
+ * @param array $args View args.
99
+ * @return array
100
+ */
101
+ public function view_args( $args ) {
102
+ return [
103
+ 'roles' => $this->get_roles(),
104
+ ];
105
+ }
106
+
107
+ /**
108
+ * Returns user roles array array
109
+ *
110
+ * @return array
111
+ */
112
+ public function get_roles() {
113
+
114
+ $all_roles = get_editable_roles();
115
+
116
+ $roles = [];
117
+ foreach ( $all_roles as $role => $details ) {
118
+ if ( 'administrator' === $role ) {
119
+ continue;
120
+ }
121
+
122
+ if ( isset( $details['capabilities']['upload_files'] ) && true === $details['capabilities']['upload_files'] ) {
123
+ $roles[ $role ] = array_merge( $details, [
124
+ 'can_create' => ( isset( $details['capabilities']['edit_watermark'] ) && true === $details['capabilities']['edit_watermark'] ),
125
+ 'can_edit' => ( isset( $details['capabilities']['edit_others_watermarks'] ) && true === $details['capabilities']['edit_others_watermarks'] ),
126
+ 'can_apply' => ( isset( $details['capabilities']['apply_watermark'] ) && true === $details['capabilities']['apply_watermark'] ),
127
+ ] );
128
+ }
129
+ }
130
+
131
+ return $roles;
132
+
133
+ }
134
+ }
src/classes/Dashboard/Settings.php CHANGED
@@ -1,56 +1,39 @@
1
- <?php
2
- /**
3
- * Settings class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Dashboard;
9
-
10
- use EasyWatermark\Core\View;
11
- use EasyWatermark\Settings\Settings as SettingsAPI;
12
-
13
- /**
14
- * Settings class
15
- */
16
- class Settings extends Page {
17
-
18
- /**
19
- * Constructor
20
- */
21
- public function __construct() {
22
- $this->permission = 'manage_options';
23
- parent::__construct( __( 'Settings', 'easy-watermark' ), null, 80 );
24
- }
25
-
26
- /**
27
- * Display admin notices
28
- *
29
- * @action easy-watermark/dashboard/settings/notices
30
- *
31
- * @return void
32
- */
33
- public function admin_notices() {
34
- // phpcs:disable WordPress.Security
35
- if ( isset( $_GET['settings-updated'] ) ) {
36
- echo new View( 'notices/success', [
37
- 'message' => __( 'Settings saved.', 'easy-watermark' ),
38
- ] );
39
- }
40
- // phpcs:enable
41
- }
42
-
43
- /**
44
- * Prepares arguments for view
45
- *
46
- * @filter easy-watermark/dashboard/settings/view-args
47
- *
48
- * @param array $args View args.
49
- * @return array
50
- */
51
- public function view_args( $args ) {
52
- return [
53
- 'sections' => SettingsAPI::get()->get_sections(),
54
- ];
55
- }
56
- }
1
+ <?php
2
+ /**
3
+ * Settings class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Dashboard;
9
+
10
+ use EasyWatermark\Core\View;
11
+ use EasyWatermark\Settings\Settings as SettingsAPI;
12
+
13
+ /**
14
+ * Settings class
15
+ */
16
+ class Settings extends Page {
17
+
18
+ /**
19
+ * Constructor
20
+ */
21
+ public function __construct() {
22
+ $this->permission = 'manage_options';
23
+ parent::__construct( __( 'Settings', 'easy-watermark' ), null, 80 );
24
+ }
25
+
26
+ /**
27
+ * Prepares arguments for view
28
+ *
29
+ * @filter easy-watermark/dashboard/settings/view-args
30
+ *
31
+ * @param array $args View args.
32
+ * @return array
33
+ */
34
+ public function view_args( $args ) {
35
+ return [
36
+ 'sections' => SettingsAPI::get()->get_sections(),
37
+ ];
38
+ }
39
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/classes/Dashboard/Tools.php CHANGED
@@ -1,122 +1,122 @@
1
- <?php
2
- /**
3
- * Settings class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Dashboard;
9
-
10
- use EasyWatermark\Core\Plugin;
11
- use EasyWatermark\Core\View;
12
- use EasyWatermark\Helpers\Image as ImageHelper;
13
-
14
- /**
15
- * Settings class
16
- */
17
- class Tools extends Page {
18
-
19
- /**
20
- * Constructor
21
- */
22
- public function __construct() {
23
- parent::__construct( __( 'Tools', 'easy-watermark' ), null, 20 );
24
- }
25
-
26
- /**
27
- * Display admin notices
28
- *
29
- * @action easy-watermark/dashboard/settings/notices
30
- *
31
- * @return void
32
- */
33
- public function admin_notices() {
34
- // phpcs:disable WordPress.Security
35
- if ( isset( $_GET['settings-updated'] ) ) {
36
- echo new View( 'notices/success', [
37
- 'message' => __( 'Settings saved.', 'easy-watermark' ),
38
- ] );
39
- }
40
- // phpcs:enable
41
- }
42
-
43
- /**
44
- * Prepares arguments for view
45
- *
46
- * @filter easy-watermark/dashboard/tools/view-args
47
- *
48
- * @param array $args View args.
49
- * @return array
50
- */
51
- public function view_args( $args ) {
52
-
53
- global $wpdb;
54
-
55
- $handler = Plugin::get()->get_watermark_handler();
56
-
57
- // phpcs:ignore WordPress.DB.DirectDatabaseQuery
58
- $backup_count = (int) $wpdb->get_var( "SELECT COUNT( post_id ) FROM {$wpdb->postmeta} WHERE meta_key = '_ew_has_backup'" );
59
-
60
- return [
61
- 'watermarks' => $handler->get_watermarks(),
62
- 'backup_count' => $backup_count,
63
- 'attachments' => $this->get_attachments(),
64
- ];
65
- }
66
-
67
- /**
68
- * Gets attachments available for watermarking
69
- *
70
- * @param string $mode Mode (watermark|restore).
71
- * @return array
72
- */
73
- private function get_attachments( $mode = 'watermark' ) {
74
-
75
- $mime_types = ImageHelper::get_available_mime_types();
76
- $result = [];
77
- $posts = get_posts( [
78
- 'post_type' => 'attachment',
79
- 'post_mime_type' => array_keys( $mime_types ),
80
- 'numberposts' => -1,
81
- ] );
82
-
83
- foreach ( $posts as $post ) {
84
- if ( get_post_meta( $post->ID, '_ew_used_as_watermark', true ) ) {
85
- // Skip images used as watermark.
86
- continue;
87
- }
88
-
89
- if ( 'restore' === $mode && ! get_post_meta( $post->ID, '_ew_has_backup', true ) ) {
90
- // In 'restore' mode skip items without backup.
91
- continue;
92
- }
93
-
94
- $result[] = [
95
- 'id' => $post->ID,
96
- 'title' => $post->post_title,
97
- ];
98
- }
99
-
100
- return $result;
101
-
102
- }
103
-
104
- /**
105
- * Prepares arguments for view
106
- *
107
- * @action wp_ajax_easy-watermark/tools/get-attachments
108
- *
109
- * @return void
110
- */
111
- public function ajax_get_attachments() {
112
-
113
- check_ajax_referer( 'get_attachments', 'nonce' );
114
-
115
- // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
116
- $mode = isset( $_REQUEST['mode'] ) ? $_REQUEST['mode'] : null;
117
- $result = $this->get_attachments( $mode );
118
-
119
- wp_send_json_success( $result );
120
-
121
- }
122
- }
1
+ <?php
2
+ /**
3
+ * Settings class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Dashboard;
9
+
10
+ use EasyWatermark\Core\Plugin;
11
+ use EasyWatermark\Core\View;
12
+ use EasyWatermark\Helpers\Image as ImageHelper;
13
+
14
+ /**
15
+ * Settings class
16
+ */
17
+ class Tools extends Page {
18
+
19
+ /**
20
+ * Constructor
21
+ */
22
+ public function __construct() {
23
+ parent::__construct( __( 'Tools', 'easy-watermark' ), null, 20 );
24
+ }
25
+
26
+ /**
27
+ * Display admin notices
28
+ *
29
+ * @action easy-watermark/dashboard/settings/notices
30
+ *
31
+ * @return void
32
+ */
33
+ public function admin_notices() {
34
+ // phpcs:disable WordPress.Security
35
+ if ( isset( $_GET['settings-updated'] ) ) {
36
+ echo new View( 'notices/success', [
37
+ 'message' => __( 'Settings saved.', 'easy-watermark' ),
38
+ ] );
39
+ }
40
+ // phpcs:enable
41
+ }
42
+
43
+ /**
44
+ * Prepares arguments for view
45
+ *
46
+ * @filter easy-watermark/dashboard/tools/view-args
47
+ *
48
+ * @param array $args View args.
49
+ * @return array
50
+ */
51
+ public function view_args( $args ) {
52
+
53
+ global $wpdb;
54
+
55
+ $handler = Plugin::get()->get_watermark_handler();
56
+
57
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery
58
+ $backup_count = (int) $wpdb->get_var( "SELECT COUNT( post_id ) FROM {$wpdb->postmeta} WHERE meta_key = '_ew_has_backup'" );
59
+
60
+ return [
61
+ 'watermarks' => $handler->get_watermarks(),
62
+ 'backup_count' => $backup_count,
63
+ 'attachments' => $this->get_attachments(),
64
+ ];
65
+ }
66
+
67
+ /**
68
+ * Gets attachments available for watermarking
69
+ *
70
+ * @param string $mode Mode (watermark|restore).
71
+ * @return array
72
+ */
73
+ private function get_attachments( $mode = 'watermark' ) {
74
+
75
+ $mime_types = ImageHelper::get_available_mime_types();
76
+ $result = [];
77
+ $posts = get_posts( [
78
+ 'post_type' => 'attachment',
79
+ 'post_mime_type' => array_keys( $mime_types ),
80
+ 'numberposts' => -1,
81
+ ] );
82
+
83
+ foreach ( $posts as $post ) {
84
+ if ( get_post_meta( $post->ID, '_ew_used_as_watermark', true ) ) {
85
+ // Skip images used as watermark.
86
+ continue;
87
+ }
88
+
89
+ if ( 'restore' === $mode && ! get_post_meta( $post->ID, '_ew_has_backup', true ) ) {
90
+ // In 'restore' mode skip items without backup.
91
+ continue;
92
+ }
93
+
94
+ $result[] = [
95
+ 'id' => $post->ID,
96
+ 'title' => $post->post_title,
97
+ ];
98
+ }
99
+
100
+ return $result;
101
+
102
+ }
103
+
104
+ /**
105
+ * Prepares arguments for view
106
+ *
107
+ * @action wp_ajax_easy-watermark/tools/get-attachments
108
+ *
109
+ * @return void
110
+ */
111
+ public function ajax_get_attachments() {
112
+
113
+ check_ajax_referer( 'get_attachments', 'nonce' );
114
+
115
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
116
+ $mode = isset( $_REQUEST['mode'] ) ? $_REQUEST['mode'] : null;
117
+ $result = $this->get_attachments( $mode );
118
+
119
+ wp_send_json_success( $result );
120
+
121
+ }
122
+ }
src/classes/Dashboard/Watermarks.php CHANGED
@@ -1,61 +1,61 @@
1
- <?php
2
- /**
3
- * Settings class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Dashboard;
9
-
10
- use EasyWatermark\Core\View;
11
- use EasyWatermark\Traits\Hookable;
12
- use EasyWatermark\Watermark\Watermark;
13
-
14
- /**
15
- * Settings class
16
- */
17
- class Watermarks extends Page {
18
-
19
- use Hookable;
20
-
21
- /**
22
- * Constructor
23
- */
24
- public function __construct() {
25
- parent::__construct( __( 'Watermarks', 'easy-watermark' ), null, 10 );
26
- }
27
-
28
- /**
29
- * Display admin notices
30
- *
31
- * @action easy-watermark/dashboard/watermarks/notices
32
- *
33
- * @return void
34
- */
35
- public function admin_notices() {
36
- // phpcs:disable WordPress.Security
37
- if ( isset( $_GET['deleted'] ) ) {
38
- echo new View( 'notices/success', [
39
- 'message' => esc_html__( 'Watermark has been deleted.', 'easy-watermark' ),
40
- ] );
41
- }
42
- // phpcs:enable
43
- }
44
-
45
- /**
46
- * Prepares arguments for view
47
- *
48
- * @filter easy-watermark/dashboard/watermarks/view-args
49
- *
50
- * @param array $args View args.
51
- * @return array
52
- */
53
- public function view_args( $args ) {
54
- $watermarks = Watermark::get_all();
55
-
56
- return [
57
- 'watermarks' => $watermarks,
58
- 'watermarks_count' => wp_count_posts( 'watermark' )->publish,
59
- ];
60
- }
61
- }
1
+ <?php
2
+ /**
3
+ * Settings class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Dashboard;
9
+
10
+ use EasyWatermark\Core\View;
11
+ use EasyWatermark\Traits\Hookable;
12
+ use EasyWatermark\Watermark\Watermark;
13
+
14
+ /**
15
+ * Settings class
16
+ */
17
+ class Watermarks extends Page {
18
+
19
+ use Hookable;
20
+
21
+ /**
22
+ * Constructor
23
+ */
24
+ public function __construct() {
25
+ parent::__construct( __( 'Watermarks', 'easy-watermark' ), null, 10 );
26
+ }
27
+
28
+ /**
29
+ * Display admin notices
30
+ *
31
+ * @action easy-watermark/dashboard/watermarks/notices
32
+ *
33
+ * @return void
34
+ */
35
+ public function admin_notices() {
36
+ // phpcs:disable WordPress.Security
37
+ if ( isset( $_GET['deleted'] ) ) {
38
+ echo new View( 'notices/success', [
39
+ 'message' => esc_html__( 'Watermark has been deleted.', 'easy-watermark' ),
40
+ ] );
41
+ }
42
+ // phpcs:enable
43
+ }
44
+
45
+ /**
46
+ * Prepares arguments for view
47
+ *
48
+ * @filter easy-watermark/dashboard/watermarks/view-args
49
+ *
50
+ * @param array $args View args.
51
+ * @return array
52
+ */
53
+ public function view_args( $args ) {
54
+ $watermarks = Watermark::get_all();
55
+
56
+ return [
57
+ 'watermarks' => $watermarks,
58
+ 'watermarks_count' => wp_count_posts( 'watermark' )->publish,
59
+ ];
60
+ }
61
+ }
src/classes/Features/AutoWatermarkSwitch.php CHANGED
@@ -1,58 +1,58 @@
1
- <?php
2
- /**
3
- * Auto Watermark switch class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Features;
9
-
10
- use EasyWatermark\Core\View;
11
- use EasyWatermark\Traits\Hookable;
12
-
13
- /**
14
- * Auto Watermark switch class
15
- */
16
- class AutoWatermarkSwitch {
17
-
18
- use Hookable;
19
-
20
- /**
21
- * Constructor
22
- */
23
- public function __construct() {
24
- $this->hook();
25
- }
26
-
27
- /**
28
- * Displays switch to turn off auto watermarking in upload ui
29
- *
30
- * @action pre-plupload-upload-ui
31
- *
32
- * @return void
33
- */
34
- public function pre_plupload_upload_ui() {
35
-
36
- if ( ! is_admin() || 'media' !== get_current_screen()->id ) {
37
- // phpcs:ignore
38
- echo new View( 'upload/switch' );
39
- }
40
-
41
- }
42
-
43
- /**
44
- * Displays notice about Auto Watermark feature
45
- *
46
- * @action admin_notices
47
- *
48
- * @return void
49
- */
50
- public function admin_notices() {
51
-
52
- if ( 'media' === get_current_screen()->id ) {
53
- // phpcs:ignore
54
- echo new View( 'notices/auto-watermark-warning' );
55
- }
56
-
57
- }
58
- }
1
+ <?php
2
+ /**
3
+ * Auto Watermark switch class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Features;
9
+
10
+ use EasyWatermark\Core\View;
11
+ use EasyWatermark\Traits\Hookable;
12
+
13
+ /**
14
+ * Auto Watermark switch class
15
+ */
16
+ class AutoWatermarkSwitch {
17
+
18
+ use Hookable;
19
+
20
+ /**
21
+ * Constructor
22
+ */
23
+ public function __construct() {
24
+ $this->hook();
25
+ }
26
+
27
+ /**
28
+ * Displays switch to turn off auto watermarking in upload ui
29
+ *
30
+ * @action pre-plupload-upload-ui
31
+ *
32
+ * @return void
33
+ */
34
+ public function pre_plupload_upload_ui() {
35
+
36
+ if ( ! is_admin() || 'media' !== get_current_screen()->id ) {
37
+ // phpcs:ignore
38
+ echo new View( 'upload/switch' );
39
+ }
40
+
41
+ }
42
+
43
+ /**
44
+ * Displays notice about Auto Watermark feature
45
+ *
46
+ * @action admin_notices
47
+ *
48
+ * @return void
49
+ */
50
+ public function admin_notices() {
51
+
52
+ if ( 'media' === get_current_screen()->id ) {
53
+ // phpcs:ignore
54
+ echo new View( 'notices/auto-watermark-warning' );
55
+ }
56
+
57
+ }
58
+ }
src/classes/Features/CacheBusting.php ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Auto Watermark switch class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Features;
9
+
10
+ use EasyWatermark\Settings\Section;
11
+ use EasyWatermark\Settings\Fields\SwitchField;
12
+ use EasyWatermark\Traits\Hookable;
13
+ use EasyWatermark\Watermark\Watermark;
14
+
15
+ /**
16
+ * Auto Watermark switch class
17
+ */
18
+ class CacheBusting {
19
+
20
+ use Hookable;
21
+
22
+ /**
23
+ * Setting field
24
+ *
25
+ * @var SwitchField
26
+ */
27
+ private $switch;
28
+
29
+ /**
30
+ * Constructor
31
+ */
32
+ public function __construct() {
33
+ $this->hook();
34
+ }
35
+
36
+ /**
37
+ * Registers settings
38
+ *
39
+ * @action easy-watermark/settings/register/general
40
+ *
41
+ * @param Section $section Settings section.
42
+ * @return void
43
+ */
44
+ public function register_settings( $section ) {
45
+
46
+ $description = implode( '<br/>', [
47
+ esc_html_x(
48
+ 'This feature will add version parameter to image file url. This will prevent browser from using cached image.',
49
+ '"Cache busting" setting description line 1',
50
+ 'easy-watermark'
51
+ ),
52
+ esc_html_x(
53
+ 'Without this option turned on browser might display original image which was cached before instead of the watermarked one.',
54
+ '"Cache busting" setting description line 2',
55
+ 'easy-watermark'
56
+ ),
57
+ esc_html_x(
58
+ 'Turn this off only if it causes problems in your environment (e.g. images do not show at all).',
59
+ '"Cache busting" setting description line 3',
60
+ 'easy-watermark'
61
+ ),
62
+ ] );
63
+
64
+ $this->switch = new SwitchField( [
65
+ 'label' => esc_html__( 'Cache busting', 'easy-watermark' ),
66
+ 'slug' => 'cache_busting',
67
+ 'default' => true,
68
+ 'description' => $description,
69
+ ] );
70
+
71
+ $section->add_field( $this->switch );
72
+
73
+ }
74
+
75
+ /**
76
+ * Adds attachment version to the URL
77
+ *
78
+ * @param string $url Attachment url.
79
+ * @param integer $attachment_id Attachment ID.
80
+ * @return string
81
+ */
82
+ public function add_attachment_version( $url, $attachment_id ) {
83
+
84
+ $version = get_post_meta( $attachment_id, '_ew_attachment_version', true );
85
+
86
+ if ( ! $version ) {
87
+ return $url;
88
+ }
89
+
90
+ return $url . '?v=' . $version;
91
+
92
+ }
93
+
94
+ /**
95
+ * Adds attachment version to the url
96
+ *
97
+ * @filter wp_get_attachment_image_src
98
+ *
99
+ * @param array|false $image Either array with src, width & height, icon src, or false.
100
+ * @param integer $attachment_id Image attachment ID.
101
+ * @param string|array $size Size of image. Image size or array of width and height values
102
+ * (in that order). Default 'thumbnail'.
103
+ * @param bool $icon Whether the image should be treated as an icon. Default false.
104
+ * @return array|false
105
+ */
106
+ public function wp_get_attachment_image_src( $image, $attachment_id, $size, $icon ) {
107
+
108
+ if ( false === $image ) {
109
+ return false;
110
+ }
111
+
112
+ if ( true === $this->switch->get_value() ) {
113
+ if ( is_array( $image ) && ! empty( $image ) && is_string( $image[0] ) ) {
114
+ $image[0] = $this->add_attachment_version( $image[0], $attachment_id );
115
+ } elseif ( is_string( $image ) ) {
116
+ $image = $this->add_attachment_version( $image, $attachment_id );
117
+ }
118
+ }
119
+
120
+ return $image;
121
+
122
+ }
123
+
124
+ /**
125
+ * Adds attachment version to the 'srcset' urls
126
+ *
127
+ * @filter wp_calculate_image_srcset
128
+ *
129
+ * @param array $sources One or more arrays of source data to include in the 'srcset'.
130
+ * @param array $size_array Array of width and height values in pixels (in that order).
131
+ * @param string $image_src The 'src' of the image.
132
+ * @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
133
+ * @param integer $attachment_id Image attachment ID or 0.
134
+ * @return array
135
+ */
136
+ public function wp_calculate_image_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ) {
137
+
138
+ if ( true === $this->switch->get_value() ) {
139
+ foreach ( $sources as &$source ) {
140
+ $source['url'] = $this->add_attachment_version( $source['url'], $attachment_id );
141
+ }
142
+ }
143
+
144
+ return $sources;
145
+
146
+ }
147
+ }
src/classes/Features/SrcsetFilter.php CHANGED
@@ -1,213 +1,181 @@
1
- <?php
2
- /**
3
- * Auto Watermark switch class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Features;
9
-
10
- use EasyWatermark\Core\Settings;
11
- use EasyWatermark\Core\Plugin;
12
- use EasyWatermark\Settings\Section;
13
- use EasyWatermark\Settings\Fields\SwitchField;
14
- use EasyWatermark\Traits\Hookable;
15
- use EasyWatermark\Watermark\Watermark;
16
- use EasyWatermark\Watermark\Handler;
17
-
18
- /**
19
- * Auto Watermark switch class
20
- */
21
- class SrcsetFilter {
22
-
23
- use Hookable;
24
-
25
- /**
26
- * Watermark Handler instance
27
- *
28
- * @var Handler
29
- */
30
- private $handler;
31
-
32
- /**
33
- * Setting field
34
- *
35
- * @var SwitchField
36
- */
37
- private $switch;
38
-
39
- /**
40
- * Constructor
41
- *
42
- * @param Plugin $plugin Plugin instance.
43
- */
44
- public function __construct( Plugin $plugin ) {
45
- $this->hook();
46
- $this->handler = $plugin->get_watermark_handler();
47
- }
48
-
49
- /**
50
- * Registers settings
51
- *
52
- * @action easy-watermark/settings/register/general
53
- *
54
- * @param Section $section Settings section.
55
- * @return void
56
- */
57
- public function register_settings( $section ) {
58
-
59
- $label = sprintf(
60
- '%s <p class="description">%s</p>',
61
- esc_html__( 'Filter srcset', 'easy-watermark' ),
62
- esc_html_x( 'for watermarked images', 'Continuation of "Filter srcset" setting label.', 'easy-watermark' )
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( [
84
- 'label' => $label,
85
- 'slug' => 'filter_srcset',
86
- 'default' => true,
87
- 'description' => $description,
88
- ] );
89
-
90
- $section->add_field( $this->switch );
91
-
92
- }
93
-
94
- /**
95
- * Filters srcset image sizes to use only the ones watermarked the same way
96
- *
97
- * @filter wp_calculate_image_srcset_meta 1000
98
- *
99
- * @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
100
- * @param array $size_array Array of width and height values in pixels (in that order).
101
- * @param string $image_src The 'src' of the image.
102
- * @param int $attachment_id The image attachment ID or 0 if not supplied.
103
- * @return array
104
- */
105
- public function wp_calculate_image_srcset_meta( $image_meta, $size_array, $image_src, $attachment_id ) {
106
-
107
- if ( ! $this->switch ) {
108
- // Don't do anything if settings have not been loaded yet.
109
- return $image_meta;
110
- }
111
-
112
- if ( true === $this->switch->get_value() && isset( $image_meta['sizes'] ) && is_array( $image_meta['sizes'] ) ) {
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 ) {
120
- return in_array( $key, $allowed_sizes, true );
121
- }, ARRAY_FILTER_USE_KEY );
122
- }
123
- }
124
-
125
- return $image_meta;
126
-
127
- }
128
-
129
- /**
130
- * Adds attachment version to the 'srcset' urls
131
- *
132
- * @filter wp_calculate_image_srcset
133
- *
134
- * @param array $sources One or more arrays of source data to include in the 'srcset'.
135
- * @param array $size_array Array of width and height values in pixels (in that order).
136
- * @param string $image_src The 'src' of the image.
137
- * @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
138
- * @param integer $attachment_id Image attachment ID or 0.
139
- * @return array
140
- */
141
- public function wp_calculate_image_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ) {
142
-
143
- foreach ( $sources as &$source ) {
144
- $source['url'] = $this->handler->add_attachment_version( $source['url'], $attachment_id );
145
- }
146
-
147
- return $sources;
148
-
149
- }
150
-
151
- /**
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
- }
175
- }
176
-
177
- return false;
178
-
179
- }
180
-
181
- /**
182
- * Filters image sizes
183
- *
184
- * @param array $watermarks Applied watermarks.
185
- * @param string $current_size Currently displayed image size.
186
- * @return array
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
- }
1
+ <?php
2
+ /**
3
+ * Auto Watermark switch class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Features;
9
+
10
+ use EasyWatermark\Core\Settings;
11
+ use EasyWatermark\Core\Plugin;
12
+ use EasyWatermark\Settings\Section;
13
+ use EasyWatermark\Settings\Fields\SwitchField;
14
+ use EasyWatermark\Traits\Hookable;
15
+ use EasyWatermark\Watermark\Watermark;
16
+
17
+ /**
18
+ * Auto Watermark switch class
19
+ */
20
+ class SrcsetFilter {
21
+
22
+ use Hookable;
23
+
24
+ /**
25
+ * Setting field
26
+ *
27
+ * @var SwitchField
28
+ */
29
+ private $switch;
30
+
31
+ /**
32
+ * Constructor
33
+ *
34
+ */
35
+ public function __construct() {
36
+ $this->hook();
37
+ }
38
+
39
+ /**
40
+ * Registers settings
41
+ *
42
+ * @action easy-watermark/settings/register/general
43
+ *
44
+ * @param Section $section Settings section.
45
+ * @return void
46
+ */
47
+ public function register_settings( $section ) {
48
+
49
+ $label = sprintf(
50
+ '%s <p class="description">%s</p>',
51
+ esc_html__( 'Filter srcset', 'easy-watermark' ),
52
+ esc_html_x( 'for watermarked images', 'Continuation of "Filter srcset" setting label.', 'easy-watermark' )
53
+ );
54
+
55
+ $description = implode( '<br/>', [
56
+ esc_html_x(
57
+ 'Srcset attribute contains information about other image sizes and lets the browser decide which image to display based on the screen size.',
58
+ '"Filter srcset" setting description line 1',
59
+ 'easy-watermark'
60
+ ),
61
+ esc_html_x(
62
+ 'This is good in general but it might cause problems if some watermarks are applied only to certain image sizes.',
63
+ '"Filter srcset" setting description line 2',
64
+ 'easy-watermark'
65
+ ),
66
+ esc_html_x(
67
+ 'With this option enabled srcset attribute will only contain image sizes watermarked the same way.',
68
+ '"Filter srcset" setting description line 3',
69
+ 'easy-watermark'
70
+ ),
71
+ ] );
72
+
73
+ $this->switch = new SwitchField( [
74
+ 'label' => $label,
75
+ 'slug' => 'filter_srcset',
76
+ 'default' => true,
77
+ 'description' => $description,
78
+ ] );
79
+
80
+ $section->add_field( $this->switch );
81
+
82
+ }
83
+
84
+ /**
85
+ * Filters srcset image sizes to use only the ones watermarked the same way
86
+ *
87
+ * @filter wp_calculate_image_srcset_meta 1000
88
+ *
89
+ * @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
90
+ * @param array $size_array Array of width and height values in pixels (in that order).
91
+ * @param string $image_src The 'src' of the image.
92
+ * @param int $attachment_id The image attachment ID or 0 if not supplied.
93
+ * @return array
94
+ */
95
+ public function wp_calculate_image_srcset_meta( $image_meta, $size_array, $image_src, $attachment_id ) {
96
+
97
+ if ( ! $this->switch ) {
98
+ // Don't do anything if settings have not been loaded yet.
99
+ return $image_meta;
100
+ }
101
+
102
+ if ( true === $this->switch->get_value() && isset( $image_meta['sizes'] ) && is_array( $image_meta['sizes'] ) ) {
103
+ $applied_watermarks = get_post_meta( $attachment_id, '_ew_applied_watermarks', true );
104
+
105
+ if ( is_array( $applied_watermarks ) ) {
106
+ $current_size = $this->get_current_size( $image_src, $image_meta );
107
+ $allowed_sizes = $this->get_allowed_sizes( $applied_watermarks, $current_size );
108
+
109
+ $image_meta['sizes'] = array_filter( $image_meta['sizes'], function( $key ) use ( $allowed_sizes ) {
110
+ return in_array( $key, $allowed_sizes, true );
111
+ }, ARRAY_FILTER_USE_KEY );
112
+ }
113
+ }
114
+
115
+ return $image_meta;
116
+
117
+ }
118
+
119
+ /**
120
+ * Gets image size for the image src
121
+ *
122
+ * @param string $image_src The 'src' of the image.
123
+ * @param array $meta Image meta.
124
+ * @return string|false
125
+ */
126
+ private function get_current_size( $image_src, $meta ) {
127
+
128
+ $image_src = basename( $image_src );
129
+ $pos = strpos( $image_src, '?v=' );
130
+
131
+ if ( $pos ) {
132
+ $image_src = substr( $image_src, 0, $pos );
133
+ }
134
+
135
+ if ( false !== strpos( $meta['file'], $image_src ) ) {
136
+ return 'full';
137
+ }
138
+
139
+ foreach ( $meta['sizes'] as $size => $params ) {
140
+ if ( $image_src === $params['file'] ) {
141
+ return $size;
142
+ }
143
+ }
144
+
145
+ return false;
146
+
147
+ }
148
+
149
+ /**
150
+ * Filters image sizes
151
+ *
152
+ * @param array $watermarks Applied watermarks.
153
+ * @param string $current_size Currently displayed image size.
154
+ * @return array
155
+ */
156
+ private function get_allowed_sizes( $watermarks, $current_size ) {
157
+
158
+ $sizes = get_intermediate_image_sizes();
159
+
160
+ foreach ( $watermarks as $watermark_id ) {
161
+ $watermark = Watermark::get( $watermark_id );
162
+
163
+ if ( ! $watermark ) {
164
+ continue;
165
+ }
166
+
167
+ $should_be = in_array( $current_size, $watermark->image_sizes, true );
168
+
169
+ foreach ( $sizes as $key => $size ) {
170
+ $is = in_array( $size, $watermark->image_sizes, true );
171
+
172
+ if ( ! ( $is * $should_be ) && ( $is || $should_be ) ) {
173
+ unset( $sizes[ $key ] );
174
+ }
175
+ }
176
+ }
177
+
178
+ return $sizes;
179
+
180
+ }
181
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/classes/Features/WatermarkPreview.php ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Preview class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Features;
9
+
10
+ use EasyWatermark\Helpers\Image as ImageHelper;
11
+ use EasyWatermark\Traits\Hookable;
12
+ use EasyWatermark\Watermark\Watermark;
13
+
14
+ /**
15
+ * Watermark class
16
+ */
17
+ class WatermarkPreview {
18
+
19
+ use Hookable;
20
+
21
+ /**
22
+ * Watermark Handler instance
23
+ *
24
+ * @var Handler
25
+ */
26
+ private $handler;
27
+
28
+ /**
29
+ * Build watermark preview URL
30
+ *
31
+ * @param string $type Watermark type.
32
+ * @param int $watermark_id Watermark ID.
33
+ * @param string $size Image size.
34
+ * @return string Preview URL.
35
+ */
36
+ public static function get_url( $type, $watermark_id, $size = null ) {
37
+ $args = [
38
+ 't' => time(),
39
+ ];
40
+
41
+ if ( get_option( 'permalink_structure' ) ) {
42
+ $base = sprintf(
43
+ 'easy-watermark-preview/%s-%s',
44
+ $type,
45
+ $size ? sprintf( '%s-%s', $watermark_id, $size ) : $watermark_id
46
+ );
47
+ } else {
48
+ $base = 'index.php';
49
+
50
+ $args['easy_watermark_preview'] = $type;
51
+ $args['watermark_id'] = $watermark_id;
52
+
53
+ if ( $size ) {
54
+ $args['image_size'] = $size;
55
+ }
56
+ }
57
+
58
+ return add_query_arg( $args, site_url( $base ) );
59
+ }
60
+
61
+ /**
62
+ * Constructor
63
+ *
64
+ * @param EasyWatermark\Core\Plugin $plugin Plugin instance.
65
+ */
66
+ public function __construct( $plugin ) {
67
+ $this->handler = $plugin->get_watermark_handler();
68
+
69
+ $this->hook();
70
+ }
71
+
72
+ /**
73
+ * Initiates plugin
74
+ *
75
+ * @action parse_request
76
+ *
77
+ * @param WP $wp WP object.
78
+ * @return void
79
+ */
80
+ public function parse_request( $wp ) {
81
+
82
+ if ( ! array_key_exists( 'easy_watermark_preview', $wp->query_vars ) ) {
83
+ return;
84
+ }
85
+
86
+ $type = $wp->query_vars['easy_watermark_preview'];
87
+ $watermark_id = $wp->query_vars['watermark_id'];
88
+ $size = isset( $wp->query_vars['image_size'] ) ? $wp->query_vars['image_size'] : 'full';
89
+
90
+ $this->show( $type, $watermark_id, 'png', $size );
91
+
92
+ }
93
+
94
+ /**
95
+ * Prints preview
96
+ *
97
+ * @param string $type Preview type.
98
+ * @param integer $watermark_id Watermark id.
99
+ * @param string $format Preview format (jpg|png).
100
+ * @param string $size Image size.
101
+ * @return void
102
+ */
103
+ public function show( $type, $watermark_id, $format, $size ) {
104
+
105
+ $watermark = Watermark::get( $watermark_id );
106
+
107
+ $watermark->use_temporary_params();
108
+
109
+ switch ( $type ) {
110
+ case 'text':
111
+ $this->print_text_preview( $watermark, $format );
112
+ break;
113
+ case 'image':
114
+ $this->print_image_preview( $watermark, $format, $size );
115
+ break;
116
+ }
117
+
118
+ do_action( 'easy-watermark/print-preview', $type, $format, $size );
119
+
120
+ }
121
+
122
+ /**
123
+ * Prints text preview
124
+ *
125
+ * @param Watermark $watermark Watermark object.
126
+ * @param string $format Preview format (jpg|png).
127
+ * @return void
128
+ */
129
+ public function print_text_preview( $watermark, $format ) {
130
+ $this->handler->print_text_preview( $watermark, $format );
131
+ }
132
+
133
+ /**
134
+ * Prints text preview
135
+ *
136
+ * @param Watermark $watermark Watermark object.
137
+ * @param string $format Preview format (jpg|png).
138
+ * @param string $size Image size.
139
+ * @return void|false
140
+ */
141
+ public function print_image_preview( $watermark, $format, $size ) {
142
+
143
+ $available_sizes = ImageHelper::get_available_sizes();
144
+
145
+ if ( ! array_key_exists( $size, $available_sizes ) ) {
146
+ return false;
147
+ }
148
+
149
+ $this->handler->print_preview( $watermark, $format, $size );
150
+ }
151
+
152
+ }
src/classes/Helpers/Image.php CHANGED
@@ -1,57 +1,57 @@
1
- <?php
2
- /**
3
- * Image helper
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Helpers;
9
-
10
- /**
11
- * Image helper
12
- */
13
- class Image {
14
- /**
15
- * Returns all registered image sizes
16
- *
17
- * @return array
18
- */
19
- public static function get_available_sizes() {
20
- global $_wp_additional_image_sizes;
21
-
22
- $size_names = apply_filters( 'image_size_names_choose', array(
23
- 'thumbnail' => __( 'Thumbnail' ),
24
- 'medium' => __( 'Medium' ),
25
- 'medium_large' => __( 'Intermediate' ),
26
- 'large' => __( 'Large' ),
27
- 'full' => __( 'Full Size' ),
28
- ) );
29
-
30
- $available_sizes = get_intermediate_image_sizes();
31
- array_push( $available_sizes, 'full' );
32
-
33
- $sizes = [];
34
- foreach ( $available_sizes as $size ) {
35
- if ( array_key_exists( $size, $size_names ) ) {
36
- $sizes[ $size ] = $size_names[ $size ];
37
- } else {
38
- $sizes[ $size ] = $size;
39
- }
40
- }
41
-
42
- return $sizes;
43
- }
44
-
45
- /**
46
- * Returns available mime types
47
- *
48
- * @return array
49
- */
50
- public static function get_available_mime_types() {
51
- return [
52
- 'image/jpeg' => 'JPEG',
53
- 'image/png' => 'PNG',
54
- 'image/gif' => 'GIF',
55
- ];
56
- }
57
- }
1
+ <?php
2
+ /**
3
+ * Image helper
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Helpers;
9
+
10
+ /**
11
+ * Image helper
12
+ */
13
+ class Image {
14
+ /**
15
+ * Returns all registered image sizes
16
+ *
17
+ * @return array
18
+ */
19
+ public static function get_available_sizes() {
20
+ global $_wp_additional_image_sizes;
21
+
22
+ $size_names = apply_filters( 'image_size_names_choose', array(
23
+ 'thumbnail' => __( 'Thumbnail' ),
24
+ 'medium' => __( 'Medium' ),
25
+ 'medium_large' => __( 'Intermediate' ),
26
+ 'large' => __( 'Large' ),
27
+ 'full' => __( 'Full Size' ),
28
+ ) );
29
+
30
+ $available_sizes = get_intermediate_image_sizes();
31
+ array_push( $available_sizes, 'full' );
32
+
33
+ $sizes = [];
34
+ foreach ( $available_sizes as $size ) {
35
+ if ( array_key_exists( $size, $size_names ) ) {
36
+ $sizes[ $size ] = $size_names[ $size ];
37
+ } else {
38
+ $sizes[ $size ] = $size;
39
+ }
40
+ }
41
+
42
+ return $sizes;
43
+ }
44
+
45
+ /**
46
+ * Returns available mime types
47
+ *
48
+ * @return array
49
+ */
50
+ public static function get_available_mime_types() {
51
+ return [
52
+ 'image/jpeg' => 'JPEG',
53
+ 'image/png' => 'PNG',
54
+ 'image/gif' => 'GIF',
55
+ ];
56
+ }
57
+ }
src/classes/Helpers/Text.php CHANGED
@@ -1,55 +1,55 @@
1
- <?php
2
- /**
3
- * Text helper
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Helpers;
9
-
10
- /**
11
- * Text helper
12
- */
13
- class Text {
14
- /**
15
- * Returns available fonts
16
- *
17
- * @return array
18
- */
19
- public static function get_available_fonts() {
20
- return [
21
- 'Arial.ttf' => 'Arial',
22
- 'Arial_Black.ttf' => 'Arial Black',
23
- 'Comic_Sans_MS.ttf' => 'Comic Sans MS',
24
- 'Courier_New.ttf' => 'Courier New',
25
- 'Georgia.ttf' => 'Georgia',
26
- 'Impact.ttf' => 'Impact',
27
- 'Tahoma.ttf' => 'Tahoma',
28
- 'Times_New_Roman.ttf' => 'Times New Roman',
29
- 'Trebuchet_MS.ttf' => 'Trebuchet MS',
30
- 'Verdana.ttf' => 'Verdana',
31
- ];
32
- }
33
-
34
- /**
35
- * Returns font file path
36
- *
37
- * @param string $font Font name.
38
- * @return string
39
- */
40
- public static function get_font_path( $font ) {
41
-
42
- if ( file_exists( $font ) && is_file( $font ) ) {
43
- $path = $font;
44
- } else {
45
- $path = EW_DIR_PATH . 'assets/dist/fonts/' . $font;
46
-
47
- if ( ! file_exists( $path ) || ! is_file( $path ) ) {
48
- $path = null;
49
- }
50
- }
51
-
52
- return apply_filters( 'easy-watermark/font-path', $path, $font );
53
-
54
- }
55
- }
1
+ <?php
2
+ /**
3
+ * Text helper
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Helpers;
9
+
10
+ /**
11
+ * Text helper
12
+ */
13
+ class Text {
14
+ /**
15
+ * Returns available fonts
16
+ *
17
+ * @return array
18
+ */
19
+ public static function get_available_fonts() {
20
+ return [
21
+ 'Arial.ttf' => 'Arial',
22
+ 'Arial_Black.ttf' => 'Arial Black',
23
+ 'Comic_Sans_MS.ttf' => 'Comic Sans MS',
24
+ 'Courier_New.ttf' => 'Courier New',
25
+ 'Georgia.ttf' => 'Georgia',
26
+ 'Impact.ttf' => 'Impact',
27
+ 'Tahoma.ttf' => 'Tahoma',
28
+ 'Times_New_Roman.ttf' => 'Times New Roman',
29
+ 'Trebuchet_MS.ttf' => 'Trebuchet MS',
30
+ 'Verdana.ttf' => 'Verdana',
31
+ ];
32
+ }
33
+
34
+ /**
35
+ * Returns font file path
36
+ *
37
+ * @param string $font Font name.
38
+ * @return string
39
+ */
40
+ public static function get_font_path( $font ) {
41
+
42
+ if ( file_exists( $font ) && is_file( $font ) ) {
43
+ $path = $font;
44
+ } else {
45
+ $path = EW_DIR_PATH . 'assets/dist/fonts/' . $font;
46
+
47
+ if ( ! file_exists( $path ) || ! is_file( $path ) ) {
48
+ $path = null;
49
+ }
50
+ }
51
+
52
+ return apply_filters( 'easy-watermark/font-path', $path, $font );
53
+
54
+ }
55
+ }
src/classes/Metaboxes/Metabox.php CHANGED
@@ -1,153 +1,153 @@
1
- <?php
2
- /**
3
- * Metabox class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Metaboxes;
9
-
10
- use EasyWatermark\Core\View;
11
- use EasyWatermark\Traits\Hookable;
12
- use EasyWatermark\Watermark\Watermark;
13
-
14
- /**
15
- * Metabox class
16
- */
17
- abstract class Metabox {
18
-
19
- use Hookable;
20
-
21
- /**
22
- * Metabox id
23
- *
24
- * @var string
25
- */
26
- protected $id;
27
-
28
- /**
29
- * Metabox title
30
- *
31
- * @var string
32
- */
33
- protected $title;
34
-
35
- /**
36
- * Metabox position (normal|side|advanced)
37
- *
38
- * @var string
39
- */
40
- protected $position = 'normal';
41
-
42
- /**
43
- * Metabox priority
44
- *
45
- * @var string
46
- */
47
- protected $priority = 'default';
48
-
49
- /**
50
- * Whether to initially hide metabox
51
- *
52
- * @var bool
53
- */
54
- protected $hide = false;
55
-
56
- /**
57
- * Post type
58
- *
59
- * @var string
60
- */
61
- protected $post_type = 'post';
62
-
63
- /**
64
- * Constructor
65
- *
66
- * @return void
67
- */
68
- public function __construct() {
69
-
70
- $this->hook();
71
- $this->init();
72
-
73
- }
74
-
75
- /**
76
- * Metabox setup
77
- *
78
- * @action do_meta_boxes
79
- *
80
- * @return void
81
- */
82
- public function setup() {
83
- add_meta_box( $this->id, $this->title, [ $this, 'content' ], $this->post_type, $this->position, $this->priority );
84
- }
85
-
86
- /**
87
- * Hides metabox
88
- *
89
- * @filter hidden_meta_boxes
90
- *
91
- * @param array $hidden Hidden metaboxes.
92
- * @param object $screen Current screen.
93
- * @return bool
94
- */
95
- public function hide( $hidden, $screen ) {
96
- if ( true === $this->hide && $this->post_type === $screen->id ) {
97
- array_push( $hidden, $this->id );
98
- }
99
-
100
- return $hidden;
101
- }
102
-
103
- /**
104
- * Inits metabox
105
- *
106
- * @return void
107
- */
108
- abstract public function init();
109
-
110
- /**
111
- * Prepares params for metabox view
112
- *
113
- * @param array $params Params.
114
- * @param object $post Current post.
115
- * @return array
116
- */
117
- public function prepare_params( $params, $post ) {
118
- return $params;
119
- }
120
-
121
- /**
122
- * Renders metabox content
123
- *
124
- * @param object $post Current post.
125
- * @return void
126
- */
127
- public function content( $post ) {
128
-
129
- $params = $this->prepare_params( [
130
- 'post' => $post,
131
- ], $post );
132
-
133
- // phpcs:ignore
134
- echo new View( 'edit-screen/metaboxes/' . $this->post_type . '/' . $this->id, $params );
135
-
136
- }
137
-
138
- /**
139
- * Returns watermarks count
140
- *
141
- * @return object
142
- */
143
- public function get_watermarks_count() {
144
- return wp_count_posts( 'watermark' )->publish;
145
- }
146
-
147
- /**
148
- * Destructor
149
- */
150
- public function __destruct() {
151
- $this->unhook();
152
- }
153
- }
1
+ <?php
2
+ /**
3
+ * Metabox class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Metaboxes;
9
+
10
+ use EasyWatermark\Core\View;
11
+ use EasyWatermark\Traits\Hookable;
12
+ use EasyWatermark\Watermark\Watermark;
13
+
14
+ /**
15
+ * Metabox class
16
+ */
17
+ abstract class Metabox {
18
+
19
+ use Hookable;
20
+
21
+ /**
22
+ * Metabox id
23
+ *
24
+ * @var string
25
+ */
26
+ protected $id;
27
+
28
+ /**
29
+ * Metabox title
30
+ *
31
+ * @var string
32
+ */
33
+ protected $title;
34
+
35
+ /**
36
+ * Metabox position (normal|side|advanced)
37
+ *
38
+ * @var string
39
+ */
40
+ protected $position = 'normal';
41
+
42
+ /**
43
+ * Metabox priority
44
+ *
45
+ * @var string
46
+ */
47
+ protected $priority = 'default';
48
+
49
+ /**
50
+ * Whether to initially hide metabox
51
+ *
52
+ * @var bool
53
+ */
54
+ protected $hide = false;
55
+
56
+ /**
57
+ * Post type
58
+ *
59
+ * @var string
60
+ */
61
+ protected $post_type = 'post';
62
+
63
+ /**
64
+ * Constructor
65
+ *
66
+ * @return void
67
+ */
68
+ public function __construct() {
69
+
70
+ $this->hook();
71
+ $this->init();
72
+
73
+ }
74
+
75
+ /**
76
+ * Metabox setup
77
+ *
78
+ * @action do_meta_boxes
79
+ *
80
+ * @return void
81
+ */
82
+ public function setup() {
83
+ add_meta_box( $this->id, $this->title, [ $this, 'content' ], $this->post_type, $this->position, $this->priority );
84
+ }
85
+
86
+ /**
87
+ * Hides metabox
88
+ *
89
+ * @filter hidden_meta_boxes
90
+ *
91
+ * @param array $hidden Hidden metaboxes.
92
+ * @param object $screen Current screen.
93
+ * @return bool
94
+ */
95
+ public function hide( $hidden, $screen ) {
96
+ if ( true === $this->hide && $this->post_type === $screen->id ) {
97
+ array_push( $hidden, $this->id );
98
+ }
99
+
100
+ return $hidden;
101
+ }
102
+
103
+ /**
104
+ * Inits metabox
105
+ *
106
+ * @return void
107
+ */
108
+ abstract public function init();
109
+
110
+ /**
111
+ * Prepares params for metabox view
112
+ *
113
+ * @param array $params Params.
114
+ * @param object $post Current post.
115
+ * @return array
116
+ */
117
+ public function prepare_params( $params, $post ) {
118
+ return $params;
119
+ }
120
+
121
+ /**
122
+ * Renders metabox content
123
+ *
124
+ * @param object $post Current post.
125
+ * @return void
126
+ */
127
+ public function content( $post ) {
128
+
129
+ $params = $this->prepare_params( [
130
+ 'post' => $post,
131
+ ], $post );
132
+
133
+ // phpcs:ignore
134
+ echo new View( 'edit-screen/metaboxes/' . $this->post_type . '/' . $this->id, $params );
135
+
136
+ }
137
+
138
+ /**
139
+ * Returns watermarks count
140
+ *
141
+ * @return object
142
+ */
143
+ public function get_watermarks_count() {
144
+ return wp_count_posts( 'watermark' )->publish;
145
+ }
146
+
147
+ /**
148
+ * Destructor
149
+ */
150
+ public function __destruct() {
151
+ $this->unhook();
152
+ }
153
+ }
src/classes/Metaboxes/Watermark/ApplyingRules.php CHANGED
@@ -1,47 +1,47 @@
1
- <?php
2
- /**
3
- * Metabox class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Metaboxes\Watermark;
9
-
10
- use EasyWatermark\Core\View;
11
- use EasyWatermark\Helpers\Image;
12
- use EasyWatermark\Metaboxes\WatermarkMetabox;
13
- use EasyWatermark\Watermark\Watermark;
14
-
15
-
16
- /**
17
- * Metabox class
18
- */
19
- class ApplyingRules extends WatermarkMetabox {
20
-
21
- /**
22
- * Inits metabox
23
- *
24
- * @return void
25
- */
26
- public function init() {
27
- $this->id = 'applying-rules';
28
- $this->title = __( 'Applying Rules', 'easy-watermark' );
29
- }
30
-
31
- /**
32
- * Prepares params for metabox view
33
- *
34
- * @param array $params Params.
35
- * @param object $post Current post.
36
- * @return array
37
- */
38
- public function prepare_params( $params, $post ) {
39
- $watermark = Watermark::get( $post );
40
-
41
- return array_merge( $params, $watermark->get_params(), [
42
- 'available_image_sizes' => Image::get_available_sizes(),
43
- 'available_mime_types' => Image::get_available_mime_types(),
44
- 'available_post_types' => get_post_types( [ 'public' => true ], 'objects' ),
45
- ] );
46
- }
47
- }
1
+ <?php
2
+ /**
3
+ * Metabox class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Metaboxes\Watermark;
9
+
10
+ use EasyWatermark\Core\View;
11
+ use EasyWatermark\Helpers\Image;
12
+ use EasyWatermark\Metaboxes\WatermarkMetabox;
13
+ use EasyWatermark\Watermark\Watermark;
14
+
15
+
16
+ /**
17
+ * Metabox class
18
+ */
19
+ class ApplyingRules extends WatermarkMetabox {
20
+
21
+ /**
22
+ * Inits metabox
23
+ *
24
+ * @return void
25
+ */
26
+ public function init() {
27
+ $this->id = 'applying-rules';
28
+ $this->title = __( 'Applying Rules', 'easy-watermark' );
29
+ }
30
+
31
+ /**
32
+ * Prepares params for metabox view
33
+ *
34
+ * @param array $params Params.
35
+ * @param object $post Current post.
36
+ * @return array
37
+ */
38
+ public function prepare_params( $params, $post ) {
39
+ $watermark = Watermark::get( $post );
40
+
41
+ return array_merge( $params, $watermark->get_params(), [
42
+ 'available_image_sizes' => Image::get_available_sizes(),
43
+ 'available_mime_types' => Image::get_available_mime_types(),
44
+ 'available_post_types' => get_post_types( [ 'public' => true ], 'objects' ),
45
+ ] );
46
+ }
47
+ }
src/classes/Metaboxes/Watermark/Preview.php CHANGED
@@ -1,157 +1,154 @@
1
- <?php
2
- /**
3
- * Metabox class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Metaboxes\Watermark;
9
-
10
- use EasyWatermark\Core\View;
11
- use EasyWatermark\Helpers\Image as ImageHelper;
12
- use EasyWatermark\Metaboxes\WatermarkMetabox;
13
- use EasyWatermark\Traits\Hookable;
14
- use EasyWatermark\Watermark\Watermark;
15
-
16
- /**
17
- * Metabox class
18
- */
19
- class Preview extends WatermarkMetabox {
20
-
21
- use Hookable;
22
-
23
- /**
24
- * Metabox position (normal|side|advanced)
25
- *
26
- * @var string
27
- */
28
- protected $position = 'side';
29
-
30
- /**
31
- * Inits metabox
32
- *
33
- * @return void
34
- */
35
- public function init() {
36
- $this->id = 'preview';
37
- $this->title = __( 'Preview' );
38
-
39
- $this->hook();
40
- }
41
-
42
- /**
43
- * Prepares params for metabox view
44
- *
45
- * @param array $params Params.
46
- * @param object $post Current post.
47
- * @return array
48
- */
49
- public function prepare_params( $params, $post ) {
50
- $watermark = Watermark::get( $post );
51
-
52
- $preview_image_id = get_option( '_ew_preview_image_id' );
53
-
54
- if ( $preview_image_id ) {
55
- $attachment = get_post( $preview_image_id );
56
-
57
- if ( null === $attachment ) {
58
- // Invalid attachment ID.
59
- $preview_image_id = false;
60
- delete_option( '_ew_preview_image_id' );
61
- }
62
- }
63
-
64
- $params['select_label'] = __( 'Select preview image', 'easy-watermark' );
65
- $params['change_label'] = __( 'Change preview image', 'easy-watermark' );
66
- $params['link_label'] = $preview_image_id ? $params['change_label'] : $params['select_label'];
67
- $params['has_image'] = (bool) $preview_image_id;
68
-
69
- $base_image_src = site_url( 'easy-watermark-preview/image-%s-%s.png?t=%s' );
70
- $images = [];
71
- $available_sizes = ImageHelper::get_available_sizes();
72
- $timestamp = time();
73
-
74
- foreach ( $available_sizes as $size => $label ) {
75
- $src = sprintf( $base_image_src, $post->ID, $size, $timestamp );
76
- $images[ $src ] = $label;
77
- }
78
-
79
- $params['images'] = $images;
80
- $params['popup'] = $this->get_preview_popup( $post->ID );
81
-
82
- return array_merge( $params, $watermark->get_params() );
83
- }
84
-
85
- /**
86
- * Handles preview image selection
87
- *
88
- * @action wp_ajax_easy-watermark/preview_image
89
- *
90
- * @return void
91
- */
92
- public function ajax_preview_image() {
93
-
94
- check_ajax_referer( 'preview_image', 'nonce' );
95
-
96
- if ( ! isset( $_REQUEST['attachment_id'] ) ) {
97
- wp_send_json_error( [
98
- 'message' => __( 'No attachment id.', 'easy-watermark' ),
99
- ] );
100
- }
101
-
102
- if ( ! isset( $_REQUEST['watermark_id'] ) ) {
103
- wp_send_json_error( [
104
- 'message' => __( 'No watermark id.', 'easy-watermark' ),
105
- ] );
106
- }
107
-
108
- $attachment_id = intval( $_REQUEST['attachment_id'] );
109
- $watermark_id = intval( $_REQUEST['watermark_id'] );
110
-
111
- $result = update_option( '_ew_preview_image_id', $attachment_id );
112
-
113
- if ( true === $result ) {
114
- wp_send_json_success( [
115
- 'popup' => (string) $this->get_preview_popup( $watermark_id ),
116
- ] );
117
- }
118
-
119
- wp_send_json_error( [
120
- 'message' => __( 'Saving preview image failed.', 'easy-watermark' ),
121
- ] );
122
-
123
- }
124
-
125
- /**
126
- * Returns preview popup content
127
- *
128
- * @param integer $watermark_id Watermark ID.
129
- * @return View|null
130
- */
131
- public function get_preview_popup( $watermark_id ) {
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();
139
- $timestamp = time();
140
-
141
- if ( $preview_image_id ) {
142
- $meta = get_post_meta( $preview_image_id, '_wp_attachment_metadata', true );
143
- $sizes = $meta['sizes'];
144
- }
145
-
146
- foreach ( $available_sizes as $size => $label ) {
147
- if ( 'full' === $size || array_key_exists( $size, $sizes ) ) {
148
- $src = sprintf( $base_image_src, $watermark_id, $size, $timestamp );
149
- $images[ $src ] = $label;
150
- }
151
- }
152
-
153
- return new View( 'edit-screen/metaboxes/watermark/preview-popup', [
154
- 'images' => $images,
155
- ] );
156
- }
157
- }
1
+ <?php
2
+ /**
3
+ * Metabox class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Metaboxes\Watermark;
9
+
10
+ use EasyWatermark\Core\View;
11
+ use EasyWatermark\Features\WatermarkPreview;
12
+ use EasyWatermark\Helpers\Image as ImageHelper;
13
+ use EasyWatermark\Metaboxes\WatermarkMetabox;
14
+ use EasyWatermark\Traits\Hookable;
15
+ use EasyWatermark\Watermark\Watermark;
16
+
17
+ /**
18
+ * Metabox class
19
+ */
20
+ class Preview extends WatermarkMetabox {
21
+
22
+ use Hookable;
23
+
24
+ /**
25
+ * Metabox position (normal|side|advanced)
26
+ *
27
+ * @var string
28
+ */
29
+ protected $position = 'side';
30
+
31
+ /**
32
+ * Inits metabox
33
+ *
34
+ * @return void
35
+ */
36
+ public function init() {
37
+ $this->id = 'preview';
38
+ $this->title = __( 'Preview' );
39
+
40
+ $this->hook();
41
+ }
42
+
43
+ /**
44
+ * Prepares params for metabox view
45
+ *
46
+ * @param array $params Params.
47
+ * @param object $post Current post.
48
+ * @return array
49
+ */
50
+ public function prepare_params( $params, $post ) {
51
+ $watermark = Watermark::get( $post );
52
+
53
+ $preview_image_id = get_option( '_ew_preview_image_id' );
54
+
55
+ if ( $preview_image_id ) {
56
+ $attachment = get_post( $preview_image_id );
57
+
58
+ if ( null === $attachment ) {
59
+ // Invalid attachment ID.
60
+ $preview_image_id = false;
61
+ delete_option( '_ew_preview_image_id' );
62
+ }
63
+ }
64
+
65
+ $params['select_label'] = __( 'Select preview image', 'easy-watermark' );
66
+ $params['change_label'] = __( 'Change preview image', 'easy-watermark' );
67
+ $params['link_label'] = $preview_image_id ? $params['change_label'] : $params['select_label'];
68
+ $params['has_image'] = (bool) $preview_image_id;
69
+
70
+ $images = [];
71
+ $available_sizes = ImageHelper::get_available_sizes();
72
+
73
+ foreach ( $available_sizes as $size => $label ) {
74
+ $src = WatermarkPreview::get_url( 'image', $post->ID, $size );
75
+ $images[ $src ] = $label;
76
+ }
77
+
78
+ $params['images'] = $images;
79
+ $params['popup'] = $this->get_preview_popup( $post->ID );
80
+
81
+ return array_merge( $params, $watermark->get_params() );
82
+ }
83
+
84
+ /**
85
+ * Handles preview image selection
86
+ *
87
+ * @action wp_ajax_easy-watermark/preview_image
88
+ *
89
+ * @return void
90
+ */
91
+ public function ajax_preview_image() {
92
+
93
+ check_ajax_referer( 'preview_image', 'nonce' );
94
+
95
+ if ( ! isset( $_REQUEST['attachment_id'] ) ) {
96
+ wp_send_json_error( [
97
+ 'message' => __( 'No attachment id.', 'easy-watermark' ),
98
+ ] );
99
+ }
100
+
101
+ if ( ! isset( $_REQUEST['watermark_id'] ) ) {
102
+ wp_send_json_error( [
103
+ 'message' => __( 'No watermark id.', 'easy-watermark' ),
104
+ ] );
105
+ }
106
+
107
+ $attachment_id = intval( $_REQUEST['attachment_id'] );
108
+ $watermark_id = intval( $_REQUEST['watermark_id'] );
109
+
110
+ $result = update_option( '_ew_preview_image_id', $attachment_id );
111
+
112
+ if ( true === $result ) {
113
+ wp_send_json_success( [
114
+ 'popup' => (string) $this->get_preview_popup( $watermark_id ),
115
+ ] );
116
+ }
117
+
118
+ wp_send_json_error( [
119
+ 'message' => __( 'Saving preview image failed.', 'easy-watermark' ),
120
+ ] );
121
+
122
+ }
123
+
124
+ /**
125
+ * Returns preview popup content
126
+ *
127
+ * @param integer $watermark_id Watermark ID.
128
+ * @return View|null
129
+ */
130
+ public function get_preview_popup( $watermark_id ) {
131
+
132
+ $preview_image_id = get_option( '_ew_preview_image_id' );
133
+
134
+ $images = [];
135
+ $sizes = [];
136
+ $available_sizes = ImageHelper::get_available_sizes();
137
+
138
+ if ( $preview_image_id ) {
139
+ $meta = get_post_meta( $preview_image_id, '_wp_attachment_metadata', true );
140
+ $sizes = $meta['sizes'];
141
+ }
142
+
143
+ foreach ( $available_sizes as $size => $label ) {
144
+ if ( 'full' === $size || array_key_exists( $size, $sizes ) ) {
145
+ $src = WatermarkPreview::get_url( 'image', $watermark_id, $size );
146
+ $images[ $src ] = $label;
147
+ }
148
+ }
149
+
150
+ return new View( 'edit-screen/metaboxes/watermark/preview-popup', [
151
+ 'images' => $images,
152
+ ] );
153
+ }
154
+ }
 
 
 
src/classes/Metaboxes/Watermark/TextOptions.php CHANGED
@@ -1,44 +1,44 @@
1
- <?php
2
- /**
3
- * Metabox class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Metaboxes\Watermark;
9
-
10
- use EasyWatermark\Core\View;
11
- use EasyWatermark\Helpers\Text;
12
- use EasyWatermark\Metaboxes\WatermarkMetabox;
13
- use EasyWatermark\Watermark\Watermark;
14
-
15
- /**
16
- * Metabox class
17
- */
18
- class TextOptions extends WatermarkMetabox {
19
-
20
- /**
21
- * Inits metabox
22
- *
23
- * @return void
24
- */
25
- public function init() {
26
- $this->id = 'text-options';
27
- $this->title = __( 'Text Options' );
28
- }
29
-
30
- /**
31
- * Prepares params for metabox view
32
- *
33
- * @param array $params Params.
34
- * @param object $post Current post.
35
- * @return array
36
- */
37
- public function prepare_params( $params, $post ) {
38
- $watermark = Watermark::get( $post );
39
-
40
- $params['available_fonts'] = Text::get_available_fonts();
41
-
42
- return array_merge( $params, $watermark->get_params() );
43
- }
44
- }
1
+ <?php
2
+ /**
3
+ * Metabox class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Metaboxes\Watermark;
9
+
10
+ use EasyWatermark\Core\View;
11
+ use EasyWatermark\Helpers\Text;
12
+ use EasyWatermark\Metaboxes\WatermarkMetabox;
13
+ use EasyWatermark\Watermark\Watermark;
14
+
15
+ /**
16
+ * Metabox class
17
+ */
18
+ class TextOptions extends WatermarkMetabox {
19
+
20
+ /**
21
+ * Inits metabox
22
+ *
23
+ * @return void
24
+ */
25
+ public function init() {
26
+ $this->id = 'text-options';
27
+ $this->title = __( 'Text Options' );
28
+ }
29
+
30
+ /**
31
+ * Prepares params for metabox view
32
+ *
33
+ * @param array $params Params.
34
+ * @param object $post Current post.
35
+ * @return array
36
+ */
37
+ public function prepare_params( $params, $post ) {
38
+ $watermark = Watermark::get( $post );
39
+
40
+ $params['available_fonts'] = Text::get_available_fonts();
41
+
42
+ return array_merge( $params, $watermark->get_params() );
43
+ }
44
+ }
src/classes/Placeholders/Abstracts/Placeholder.php CHANGED
@@ -1,201 +1,201 @@
1
- <?php
2
- /**
3
- * Abstract placeholder
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Placeholders\Abstracts;
9
-
10
- /**
11
- * Abstract placeholder
12
- */
13
- abstract class Placeholder {
14
-
15
- /**
16
- * Code pattern
17
- *
18
- * @var string
19
- */
20
- protected $code_pattern = '%%%s%%';
21
-
22
- /**
23
- * Slug
24
- *
25
- * @var string
26
- */
27
- protected $slug;
28
-
29
- /**
30
- * Name
31
- *
32
- * @var string
33
- */
34
- protected $name;
35
-
36
- /**
37
- * Example
38
- *
39
- * @var string
40
- */
41
- protected $example;
42
-
43
- /**
44
- * Resolved value
45
- *
46
- * @var mixed
47
- */
48
- protected $value;
49
-
50
- /**
51
- * Value type
52
- *
53
- * @var string
54
- */
55
- protected $value_type;
56
-
57
- /**
58
- * Does this placeholder need reset?
59
- *
60
- * @var boolean
61
- */
62
- protected $resetable = false;
63
-
64
- /**
65
- * Returns placeholder slug
66
- *
67
- * @return string
68
- */
69
- public function get_slug() {
70
- return $this->slug;
71
- }
72
-
73
- /**
74
- * Returns placeholder name
75
- *
76
- * @return string
77
- */
78
- public function get_name() {
79
- return $this->name;
80
- }
81
-
82
- /**
83
- * Returns placeholder example
84
- *
85
- * @return string
86
- */
87
- public function get_example() {
88
- return $this->example;
89
- }
90
-
91
- /**
92
- * Returns placeholder value type
93
- *
94
- * @return string
95
- */
96
- public function get_value_type() {
97
- return $this->value_type;
98
- }
99
-
100
- /**
101
- * Returns placeholder code
102
- *
103
- * @return string
104
- */
105
- public function get_code() {
106
- return sprintf( $this->code_pattern, $this->slug );
107
- }
108
-
109
- /**
110
- * Tells whether placeholder is already resolved
111
- *
112
- * @return boolean
113
- */
114
- public function is_resolved() {
115
- return ( null !== $this->value );
116
- }
117
-
118
- /**
119
- * Tells whether placeholder is resetable
120
- *
121
- * @return boolean
122
- */
123
- public function is_resetable() {
124
- return $this->resetable;
125
- }
126
-
127
- /**
128
- * Tells whether placeholder is valid
129
- *
130
- * @param Resolver $resolver Placeholders resolver instance.
131
- * @return boolean
132
- */
133
- public function is_valid( $resolver ) {
134
- return true;
135
- }
136
-
137
- /**
138
- * Resets resolved value
139
- *
140
- * @return void
141
- */
142
- public function reset() {
143
-
144
- if ( $this->is_resetable() ) {
145
- $this->value = null;
146
- $this->data = [];
147
- }
148
-
149
- }
150
-
151
- /**
152
- * Returns resolved value
153
- *
154
- * @param Resolver $resolver Placeholders resolver instance.
155
- * @return mixed
156
- */
157
- public function get_value( $resolver ) {
158
-
159
- if ( ! $this->is_resolved() ) {
160
- if ( ! $this->is_valid( $resolver ) ) {
161
- return $this->get_code();
162
- }
163
-
164
- $value = $this->resolve( $resolver );
165
-
166
- if ( ! empty( $value ) && ! $this->validate( $value ) ) {
167
- $error_type = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? E_USER_ERROR : E_USER_NOTICE;
168
- trigger_error( 'Resolved value is a wrong type', $error_type );
169
- }
170
-
171
- $this->value = apply_filters( 'easy-watermark/placeholder/resolve', $this->sanitize( $value ) );
172
- }
173
-
174
- return $this->value;
175
-
176
- }
177
-
178
- /**
179
- * Resolves placeholder
180
- *
181
- * @param Resolver $resolver Placeholders resolver instance.
182
- * @return string
183
- */
184
- abstract public function resolve( $resolver );
185
-
186
- /**
187
- * Checks if the value is the correct type
188
- *
189
- * @param mixed $value placeholder value.
190
- * @return boolean
191
- */
192
- abstract public function validate( $value );
193
-
194
- /**
195
- * Sanitizes the merge tag value
196
- *
197
- * @param mixed $value placeholder value.
198
- * @return mixed sanitized value
199
- */
200
- abstract public function sanitize( $value );
201
- }
1
+ <?php
2
+ /**
3
+ * Abstract placeholder
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Placeholders\Abstracts;
9
+
10
+ /**
11
+ * Abstract placeholder
12
+ */
13
+ abstract class Placeholder {
14
+
15
+ /**
16
+ * Code pattern
17
+ *
18
+ * @var string
19
+ */
20
+ protected $code_pattern = '%%%s%%';
21
+
22
+ /**
23
+ * Slug
24
+ *
25
+ * @var string
26
+ */
27
+ protected $slug;
28
+
29
+ /**
30
+ * Name
31
+ *
32
+ * @var string
33
+ */
34
+ protected $name;
35
+
36
+ /**
37
+ * Example
38
+ *
39
+ * @var string
40
+ */
41
+ protected $example;
42
+
43
+ /**
44
+ * Resolved value
45
+ *
46
+ * @var mixed
47
+ */
48
+ protected $value;
49
+
50
+ /**
51
+ * Value type
52
+ *
53
+ * @var string
54
+ */
55
+ protected $value_type;
56
+
57
+ /**
58
+ * Does this placeholder need reset?
59
+ *
60
+ * @var boolean
61
+ */
62
+ protected $resetable = false;
63
+
64
+ /**
65
+ * Returns placeholder slug
66
+ *
67
+ * @return string
68
+ */
69
+ public function get_slug() {
70
+ return $this->slug;
71
+ }
72
+
73
+ /**
74
+ * Returns placeholder name
75
+ *
76
+ * @return string
77
+ */
78
+ public function get_name() {
79
+ return $this->name;
80
+ }
81
+
82
+ /**
83
+ * Returns placeholder example
84
+ *
85
+ * @return string
86
+ */
87
+ public function get_example() {
88
+ return $this->example;
89
+ }
90
+
91
+ /**
92
+ * Returns placeholder value type
93
+ *
94
+ * @return string
95
+ */
96
+ public function get_value_type() {
97
+ return $this->value_type;
98
+ }
99
+
100
+ /**
101
+ * Returns placeholder code
102
+ *
103
+ * @return string
104
+ */
105
+ public function get_code() {
106
+ return sprintf( $this->code_pattern, $this->slug );
107
+ }
108
+
109
+ /**
110
+ * Tells whether placeholder is already resolved
111
+ *
112
+ * @return boolean
113
+ */
114
+ public function is_resolved() {
115
+ return ( null !== $this->value );
116
+ }
117
+
118
+ /**
119
+ * Tells whether placeholder is resetable
120
+ *
121
+ * @return boolean
122
+ */
123
+ public function is_resetable() {
124
+ return $this->resetable;
125
+ }
126
+
127
+ /**
128
+ * Tells whether placeholder is valid
129
+ *
130
+ * @param Resolver $resolver Placeholders resolver instance.
131
+ * @return boolean
132
+ */
133
+ public function is_valid( $resolver ) {
134
+ return true;
135
+ }
136
+
137
+ /**
138
+ * Resets resolved value
139
+ *
140
+ * @return void
141
+ */
142
+ public function reset() {
143
+
144
+ if ( $this->is_resetable() ) {
145
+ $this->value = null;
146
+ $this->data = [];
147
+ }
148
+
149
+ }
150
+
151
+ /**
152
+ * Returns resolved value
153
+ *
154
+ * @param Resolver $resolver Placeholders resolver instance.
155
+ * @return mixed
156
+ */
157
+ public function get_value( $resolver ) {
158
+
159
+ if ( ! $this->is_resolved() ) {
160
+ if ( ! $this->is_valid( $resolver ) ) {
161
+ return $this->get_code();
162
+ }
163
+
164
+ $value = $this->resolve( $resolver );
165
+
166
+ if ( ! empty( $value ) && ! $this->validate( $value ) ) {
167
+ $error_type = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? E_USER_ERROR : E_USER_NOTICE;
168
+ trigger_error( 'Resolved value is a wrong type', $error_type );
169
+ }
170
+
171
+ $this->value = apply_filters( 'easy-watermark/placeholder/resolve', $this->sanitize( $value ) );
172
+ }
173
+
174
+ return $this->value;
175
+
176
+ }
177
+
178
+ /**
179
+ * Resolves placeholder
180
+ *
181
+ * @param Resolver $resolver Placeholders resolver instance.
182
+ * @return string
183
+ */
184
+ abstract public function resolve( $resolver );
185
+
186
+ /**
187
+ * Checks if the value is the correct type
188
+ *
189
+ * @param mixed $value placeholder value.
190
+ * @return boolean
191
+ */
192
+ abstract public function validate( $value );
193
+
194
+ /**
195
+ * Sanitizes the merge tag value
196
+ *
197
+ * @param mixed $value placeholder value.
198
+ * @return mixed sanitized value
199
+ */
200
+ abstract public function sanitize( $value );
201
+ }
src/classes/Placeholders/Abstracts/StringPlaceholder.php CHANGED
@@ -1,41 +1,41 @@
1
- <?php
2
- /**
3
- * String placeholder class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Placeholders\Abstracts;
9
-
10
- /**
11
- * String placeholder class
12
- */
13
- abstract class StringPlaceholder extends Placeholder {
14
-
15
- /**
16
- * Value type
17
- *
18
- * @var string
19
- */
20
- protected $value_type = 'string';
21
-
22
- /**
23
- * Checks if the value is the correct type
24
- *
25
- * @param mixed $value placeholder value.
26
- * @return boolean
27
- */
28
- public function validate( $value ) {
29
- return is_string( $value );
30
- }
31
-
32
- /**
33
- * Sanitizes the merge tag value
34
- *
35
- * @param mixed $value placeholder value.
36
- * @return mixed sanitized value
37
- */
38
- public function sanitize( $value ) {
39
- return sanitize_text_field( $value );
40
- }
41
- }
1
+ <?php
2
+ /**
3
+ * String placeholder class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Placeholders\Abstracts;
9
+
10
+ /**
11
+ * String placeholder class
12
+ */
13
+ abstract class StringPlaceholder extends Placeholder {
14
+
15
+ /**
16
+ * Value type
17
+ *
18
+ * @var string
19
+ */
20
+ protected $value_type = 'string';
21
+
22
+ /**
23
+ * Checks if the value is the correct type
24
+ *
25
+ * @param mixed $value placeholder value.
26
+ * @return boolean
27
+ */
28
+ public function validate( $value ) {
29
+ return is_string( $value );
30
+ }
31
+
32
+ /**
33
+ * Sanitizes the merge tag value
34
+ *
35
+ * @param mixed $value placeholder value.
36
+ * @return mixed sanitized value
37
+ */
38
+ public function sanitize( $value ) {
39
+ return sanitize_text_field( $value );
40
+ }
41
+ }
src/classes/Placeholders/Abstracts/UrlPlaceholder.php CHANGED
@@ -1,41 +1,41 @@
1
- <?php
2
- /**
3
- * String placeholder class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Placeholders\Abstracts;
9
-
10
- /**
11
- * String placeholder class
12
- */
13
- abstract class UrlPlaceholder extends Placeholder {
14
-
15
- /**
16
- * Value type
17
- *
18
- * @var string
19
- */
20
- protected $value_type = 'url';
21
-
22
- /**
23
- * Checks if the value is the correct type
24
- *
25
- * @param mixed $value placeholder value.
26
- * @return boolean
27
- */
28
- public function validate( $value ) {
29
- return empty( $value ) || filter_var( $value, FILTER_VALIDATE_URL ) !== false;
30
- }
31
-
32
- /**
33
- * Sanitizes the merge tag value
34
- *
35
- * @param mixed $value placeholder value.
36
- * @return mixed sanitized value
37
- */
38
- public function sanitize( $value ) {
39
- return esc_url( $value );
40
- }
41
- }
1
+ <?php
2
+ /**
3
+ * String placeholder class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Placeholders\Abstracts;
9
+
10
+ /**
11
+ * String placeholder class
12
+ */
13
+ abstract class UrlPlaceholder extends Placeholder {
14
+
15
+ /**
16
+ * Value type
17
+ *
18
+ * @var string
19
+ */
20
+ protected $value_type = 'url';
21
+
22
+ /**
23
+ * Checks if the value is the correct type
24
+ *
25
+ * @param mixed $value placeholder value.
26
+ * @return boolean
27
+ */
28
+ public function validate( $value ) {
29
+ return empty( $value ) || filter_var( $value, FILTER_VALIDATE_URL ) !== false;
30
+ }
31
+
32
+ /**
33
+ * Sanitizes the merge tag value
34
+ *
35
+ * @param mixed $value placeholder value.
36
+ * @return mixed sanitized value
37
+ */
38
+ public function sanitize( $value ) {
39
+ return esc_url( $value );
40
+ }
41
+ }
src/classes/Placeholders/Blog/AdminEmail.php CHANGED
@@ -1,39 +1,39 @@
1
- <?php
2
- /**
3
- * Abstract placeholder
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Placeholders\Blog;
9
-
10
- use EasyWatermark\Placeholders\Abstracts\EmailPlaceholder;
11
-
12
- /**
13
- * Abstract placeholder
14
- */
15
- class AdminEmail extends EmailPlaceholder {
16
-
17
- /**
18
- * Constructor
19
- *
20
- * @return void
21
- */
22
- public function __construct() {
23
-
24
- $this->slug = 'admin_email';
25
- $this->name = __( 'Admin email', 'easy-watermark' );
26
- $this->example = __( 'admin@example.com', 'easy-watermark' );
27
-
28
- }
29
-
30
- /**
31
- * Resolves placeholder
32
- *
33
- * @param Resolver $resolver Placeholders resolver instance.
34
- * @return string
35
- */
36
- public function resolve( $resolver ) {
37
- return get_bloginfo( 'admin_email' );
38
- }
39
- }
1
+ <?php
2
+ /**
3
+ * Abstract placeholder
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Placeholders\Blog;
9
+
10
+ use EasyWatermark\Placeholders\Abstracts\EmailPlaceholder;
11
+
12
+ /**
13
+ * Abstract placeholder
14
+ */
15
+ class AdminEmail extends EmailPlaceholder {
16
+
17
+ /**
18
+ * Constructor
19
+ *
20
+ * @return void
21
+ */
22
+ public function __construct() {
23
+
24
+ $this->slug = 'admin_email';
25
+ $this->name = __( 'Admin email', 'easy-watermark' );
26
+ $this->example = __( 'admin@example.com', 'easy-watermark' );
27
+
28
+ }
29
+
30
+ /**
31
+ * Resolves placeholder
32
+ *
33
+ * @param Resolver $resolver Placeholders resolver instance.
34
+ * @return string
35
+ */
36
+ public function resolve( $resolver ) {
37
+ return get_bloginfo( 'admin_email' );
38
+ }
39
+ }
src/classes/Placeholders/Blog/BlogName.php CHANGED
@@ -1,39 +1,39 @@
1
- <?php
2
- /**
3
- * Abstract placeholder
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Placeholders\Blog;
9
-
10
- use EasyWatermark\Placeholders\Abstracts\StringPlaceholder;
11
-
12
- /**
13
- * Abstract placeholder
14
- */
15
- class BlogName extends StringPlaceholder {
16
-
17
- /**
18
- * Constructor
19
- *
20
- * @return void
21
- */
22
- public function __construct() {
23
-
24
- $this->slug = 'blog_name';
25
- $this->name = __( 'Blog name', 'easy-watermark' );
26
- $this->example = __( 'John Doe\'s Blog', 'easy-watermark' );
27
-
28
- }
29
-
30
- /**
31
- * Resolves placeholder
32
- *
33
- * @param Resolver $resolver Placeholders resolver instance.
34
- * @return string
35
- */
36
- public function resolve( $resolver ) {
37
- return get_bloginfo( 'name' );
38
- }
39
- }
1
+ <?php
2
+ /**
3
+ * Abstract placeholder
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Placeholders\Blog;
9
+
10
+ use EasyWatermark\Placeholders\Abstracts\StringPlaceholder;
11
+
12
+ /**
13
+ * Abstract placeholder
14
+ */
15
+ class BlogName extends StringPlaceholder {
16
+
17
+ /**
18
+ * Constructor
19
+ *
20
+ * @return void
21
+ */
22
+ public function __construct() {
23
+
24
+ $this->slug = 'blog_name';
25
+ $this->name = __( 'Blog name', 'easy-watermark' );
26
+ $this->example = __( 'John Doe\'s Blog', 'easy-watermark' );
27
+
28
+ }
29
+
30
+ /**
31
+ * Resolves placeholder
32
+ *
33
+ * @param Resolver $resolver Placeholders resolver instance.
34
+ * @return string
35
+ */
36
+ public function resolve( $resolver ) {
37
+ return get_bloginfo( 'name' );
38
+ }
39
+ }
src/classes/Placeholders/Blog/BlogUrl.php CHANGED
@@ -1,39 +1,39 @@
1
- <?php
2
- /**
3
- * Abstract placeholder
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Placeholders\Blog;
9
-
10
- use EasyWatermark\Placeholders\Abstracts\UrlPlaceholder;
11
-
12
- /**
13
- * Abstract placeholder
14
- */
15
- class BlogUrl extends UrlPlaceholder {
16
-
17
- /**
18
- * Constructor
19
- *
20
- * @return void
21
- */
22
- public function __construct() {
23
-
24
- $this->slug = 'blog_url';
25
- $this->name = __( 'Blog URL', 'easy-watermark' );
26
- $this->example = __( 'http://example.com', 'easy-watermark' );
27
-
28
- }
29
-
30
- /**
31
- * Resolves placeholder
32
- *
33
- * @param Resolver $resolver Placeholders resolver instance.
34
- * @return string
35
- */
36
- public function resolve( $resolver ) {
37
- return home_url();
38
- }
39
- }
1
+ <?php
2
+ /**
3
+ * Abstract placeholder
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Placeholders\Blog;
9
+
10
+ use EasyWatermark\Placeholders\Abstracts\UrlPlaceholder;
11
+
12
+ /**
13
+ * Abstract placeholder
14
+ */
15
+ class BlogUrl extends UrlPlaceholder {
16
+
17
+ /**
18
+ * Constructor
19
+ *
20
+ * @return void
21
+ */
22
+ public function __construct() {
23
+
24
+ $this->slug = 'blog_url';
25
+ $this->name = __( 'Blog URL', 'easy-watermark' );
26
+ $this->example = __( 'http://example.com', 'easy-watermark' );
27
+
28
+ }
29
+
30
+ /**
31
+ * Resolves placeholder
32
+ *
33
+ * @param Resolver $resolver Placeholders resolver instance.
34
+ * @return string
35
+ */
36
+ public function resolve( $resolver ) {
37
+ return home_url();
38
+ }
39
+ }
src/classes/Placeholders/DateTime/Date.php CHANGED
@@ -1,39 +1,39 @@
1
- <?php
2
- /**
3
- * Abstract placeholder
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Placeholders\DateTime;
9
-
10
- use EasyWatermark\Placeholders\Abstracts\StringPlaceholder;
11
-
12
- /**
13
- * Abstract placeholder
14
- */
15
- class Date extends StringPlaceholder {
16
-
17
- /**
18
- * Constructor
19
- *
20
- * @return void
21
- */
22
- public function __construct() {
23
-
24
- $this->slug = 'date';
25
- $this->name = __( 'Current date', 'easy-watermark' );
26
- $this->example = date_i18n( get_option( 'date_format' ) );
27
-
28
- }
29
-
30
- /**
31
- * Resolves placeholder
32
- *
33
- * @param Resolver $resolver Placeholders resolver instance.
34
- * @return string
35
- */
36
- public function resolve( $resolver ) {
37
- return date_i18n( get_option( 'date_format' ) );
38
- }
39
- }
1
+ <?php
2
+ /**
3
+ * Abstract placeholder
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Placeholders\DateTime;
9
+
10
+ use EasyWatermark\Placeholders\Abstracts\StringPlaceholder;
11
+
12
+ /**
13
+ * Abstract placeholder
14
+ */
15
+ class Date extends StringPlaceholder {
16
+
17
+ /**
18
+ * Constructor
19
+ *
20
+ * @return void
21
+ */
22
+ public function __construct() {
23
+
24
+ $this->slug = 'date';
25
+ $this->name = __( 'Current date', 'easy-watermark' );
26
+ $this->example = date_i18n( get_option( 'date_format' ) );
27
+
28
+ }
29
+
30
+ /**
31
+ * Resolves placeholder
32
+ *
33
+ * @param Resolver $resolver Placeholders resolver instance.
34
+ * @return string
35
+ */
36
+ public function resolve( $resolver ) {
37
+ return date_i18n( get_option( 'date_format' ) );
38
+ }
39
+ }
src/classes/Placeholders/DateTime/Time.php CHANGED
@@ -1,39 +1,39 @@
1
- <?php
2
- /**
3
- * Abstract placeholder
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Placeholders\DateTime;
9
-
10
- use EasyWatermark\Placeholders\Abstracts\StringPlaceholder;
11
-
12
- /**
13
- * Abstract placeholder
14
- */
15
- class Time extends StringPlaceholder {
16
-
17
- /**
18
- * Constructor
19
- *
20
- * @return void
21
- */
22
- public function __construct() {
23
-
24
- $this->slug = 'time';
25
- $this->name = __( 'Current time', 'easy-watermark' );
26
- $this->example = date_i18n( get_option( 'time_format' ) );
27
-
28
- }
29
-
30
- /**
31
- * Resolves placeholder
32
- *
33
- * @param Resolver $resolver Placeholders resolver instance.
34
- * @return string
35
- */
36
- public function resolve( $resolver ) {
37
- return date_i18n( get_option( 'time_format' ) );
38
- }
39
- }
1
+ <?php
2
+ /**
3
+ * Abstract placeholder
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Placeholders\DateTime;
9
+
10
+ use EasyWatermark\Placeholders\Abstracts\StringPlaceholder;
11
+
12
+ /**
13
+ * Abstract placeholder
14
+ */
15
+ class Time extends StringPlaceholder {
16
+
17
+ /**
18
+ * Constructor
19
+ *
20
+ * @return void
21
+ */
22
+ public function __construct() {
23
+
24
+ $this->slug = 'time';
25
+ $this->name = __( 'Current time', 'easy-watermark' );
26
+ $this->example = date_i18n( get_option( 'time_format' ) );
27
+
28
+ }
29
+
30
+ /**
31
+ * Resolves placeholder
32
+ *
33
+ * @param Resolver $resolver Placeholders resolver instance.
34
+ * @return string
35
+ */
36
+ public function resolve( $resolver ) {
37
+ return date_i18n( get_option( 'time_format' ) );
38
+ }
39
+ }
src/classes/Settings/Field.php CHANGED
@@ -1,241 +1,241 @@
1
- <?php
2
- /**
3
- * Settings Field
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Settings;
9
-
10
- use EasyWatermark\Core\View;
11
-
12
- /**
13
- * Field class
14
- */
15
- abstract class Field {
16
-
17
- /**
18
- * Field label
19
- *
20
- * @var string
21
- */
22
- protected $label;
23
-
24
- /**
25
- * Field slug
26
- *
27
- * @var string
28
- */
29
- protected $slug;
30
-
31
- /**
32
- * Array of params
33
- *
34
- * @var array
35
- */
36
- protected $params = [];
37
-
38
- /**
39
- * Field value
40
- *
41
- * @var mixed
42
- */
43
- protected $value;
44
-
45
- /**
46
- * Section
47
- *
48
- * @var Section
49
- */
50
- protected $section;
51
-
52
- /**
53
- * Constructor
54
- *
55
- * @param string $label Field label.
56
- * @param string $slug Field slug.
57
- * @param string $default Default value.
58
- */
59
- public function __construct( $label, $slug = null, $default = null ) {
60
- if ( is_array( $label ) ) {
61
- $params = $label;
62
-
63
- if ( isset( $params['label'] ) ) {
64
- $label = $params['label'];
65
- unset( $params['label'] );
66
- }
67
-
68
- if ( isset( $params['slug'] ) ) {
69
- $slug = $params['slug'];
70
- unset( $params['slug'] );
71
- }
72
-
73
- $this->set( $params );
74
- } elseif ( $default ) {
75
- $this->set( 'default', $default );
76
- }
77
-
78
- $this->set_label( $label );
79
- $this->set_slug( is_string( $slug ) ? $slug : sanitize_title( $label ) );
80
- }
81
-
82
- /**
83
- * Sets name
84
- *
85
- * @param string $label Field label.
86
- * @return void
87
- */
88
- public function set_label( $label ) {
89
- $this->label = $label;
90
- }
91
-
92
- /**
93
- * Gets name
94
- *
95
- * @return string
96
- */
97
- public function get_label() {
98
- return $this->label;
99
- }
100
-
101
- /**
102
- * Sets slug
103
- *
104
- * @param string $slug Field slug.
105
- * @return void
106
- */
107
- public function set_slug( $slug ) {
108
- $this->slug = $slug;
109
- }
110
-
111
- /**
112
- * Gets slug
113
- *
114
- * @return string
115
- */
116
- public function get_slug() {
117
- return $this->slug;
118
- }
119
-
120
- /**
121
- * Sets param
122
- *
123
- * @param mixed $key Param key.
124
- * @param string $value Param value.
125
- * @return void
126
- */
127
- public function set( $key, $value = null ) {
128
- if ( null === $value && is_array( $key ) ) {
129
- $params = $key;
130
-
131
- foreach ( $params as $key => $value ) {
132
- $this->set( $key, $value );
133
- }
134
- } else {
135
- $this->params[ $key ] = $value;
136
- }
137
- }
138
-
139
- /**
140
- * Gets param value
141
- *
142
- * @param string $key Param key.
143
- * @param string $default Default param value.
144
- * @return string
145
- */
146
- public function get( $key, $default = null ) {
147
- return isset( $this->params[ $key ] ) ? $this->params[ $key ] : $default;
148
- }
149
-
150
- /**
151
- * Sets value
152
- *
153
- * @param string $value Field value.
154
- * @return void
155
- */
156
- public function set_value( $value ) {
157
- $this->value = $value;
158
- }
159
-
160
- /**
161
- * Gets value
162
- *
163
- * @return string
164
- */
165
- public function get_value() {
166
- return null !== $this->value ? $this->value : $this->get( 'default' );
167
- }
168
-
169
- /**
170
- * Gets layout
171
- *
172
- * @return string
173
- */
174
- public function get_layout() {
175
- return $this->get( 'layout', 'two-column' );
176
- }
177
-
178
- /**
179
- * Sets section
180
- *
181
- * @param Section $section Section instance.
182
- * @throws \Exception If section is not instance of Section class.
183
- * @return void
184
- */
185
- public function set_section( $section ) {
186
- if ( ! $section instanceof Section ) {
187
- /* translators: section variable type */
188
- throw new \Exception( sprintf( __( 'Section must be an instance of EasyWatermark\\Settings\\Section. %s given', 'easy-watermark' ), gettype( $section ) ) );
189
- }
190
-
191
- $this->section = $section;
192
- }
193
-
194
- /**
195
- * Gets field id
196
- *
197
- * @return string
198
- */
199
- public function get_id() {
200
- return "ew-field-{$this->section->get_slug()}-{$this->get_slug()}";
201
- }
202
-
203
- /**
204
- * Gets field name
205
- *
206
- * @return string
207
- */
208
- public function get_name() {
209
- return "{$this->section->get_option_key()}[{$this->section->get_slug()}][{$this->get_slug()}]";
210
- }
211
-
212
- /**
213
- * Renders Field
214
- *
215
- * @return void
216
- */
217
- public function render() {
218
- $layout = $this->get_layout();
219
-
220
- // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
221
- echo new View( "dashboard/settings/field-{$layout}", [
222
- 'field' => $this,
223
- ] );
224
- // phpcs:enable
225
- }
226
-
227
- /**
228
- * Renders Field
229
- *
230
- * @return string
231
- */
232
- abstract public function render_field();
233
-
234
- /**
235
- * Sanitizes value
236
- *
237
- * @param mixed $value Field value to sanitize.
238
- * @return mixed
239
- */
240
- abstract public function sanitize( $value );
241
- }
1
+ <?php
2
+ /**
3
+ * Settings Field
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Settings;
9
+
10
+ use EasyWatermark\Core\View;
11
+
12
+ /**
13
+ * Field class
14
+ */
15
+ abstract class Field {
16
+
17
+ /**
18
+ * Field label
19
+ *
20
+ * @var string
21
+ */
22
+ protected $label;
23
+
24
+ /**
25
+ * Field slug
26
+ *
27
+ * @var string
28
+ */
29
+ protected $slug;
30
+
31
+ /**
32
+ * Array of params
33
+ *
34
+ * @var array
35
+ */
36
+ protected $params = [];
37
+
38
+ /**
39
+ * Field value
40
+ *
41
+ * @var mixed
42
+ */
43
+ protected $value;
44
+
45
+ /**
46
+ * Section
47
+ *
48
+ * @var Section
49
+ */
50
+ protected $section;
51
+
52
+ /**
53
+ * Constructor
54
+ *
55
+ * @param string $label Field label.
56
+ * @param string $slug Field slug.
57
+ * @param string $default Default value.
58
+ */
59
+ public function __construct( $label, $slug = null, $default = null ) {
60
+ if ( is_array( $label ) ) {
61
+ $params = $label;
62
+
63
+ if ( isset( $params['label'] ) ) {
64
+ $label = $params['label'];
65
+ unset( $params['label'] );
66
+ }
67
+
68
+ if ( isset( $params['slug'] ) ) {
69
+ $slug = $params['slug'];
70
+ unset( $params['slug'] );
71
+ }
72
+
73
+ $this->set( $params );
74
+ } elseif ( $default ) {
75
+ $this->set( 'default', $default );
76
+ }
77
+
78
+ $this->set_label( $label );
79
+ $this->set_slug( is_string( $slug ) ? $slug : sanitize_title( $label ) );
80
+ }
81
+
82
+ /**
83
+ * Sets name
84
+ *
85
+ * @param string $label Field label.
86
+ * @return void
87
+ */
88
+ public function set_label( $label ) {
89
+ $this->label = $label;
90
+ }
91
+
92
+ /**
93
+ * Gets name
94
+ *
95
+ * @return string
96
+ */
97
+ public function get_label() {
98
+ return $this->label;
99
+ }
100
+
101
+ /**
102
+ * Sets slug
103
+ *
104
+ * @param string $slug Field slug.
105
+ * @return void
106
+ */
107
+ public function set_slug( $slug ) {
108
+ $this->slug = $slug;
109
+ }
110
+
111
+ /**
112
+ * Gets slug
113
+ *
114
+ * @return string
115
+ */
116
+ public function get_slug() {
117
+ return $this->slug;
118
+ }
119
+
120
+ /**
121
+ * Sets param
122
+ *
123
+ * @param mixed $key Param key.
124
+ * @param string $value Param value.
125
+ * @return void
126
+ */
127
+ public function set( $key, $value = null ) {
128
+ if ( null === $value && is_array( $key ) ) {
129
+ $params = $key;
130
+
131
+ foreach ( $params as $key => $value ) {
132
+ $this->set( $key, $value );
133
+ }
134
+ } else {
135
+ $this->params[ $key ] = $value;
136
+ }
137
+ }
138
+
139
+ /**
140
+ * Gets param value
141
+ *
142
+ * @param string $key Param key.
143
+ * @param string $default Default param value.
144
+ * @return string
145
+ */
146
+ public function get( $key, $default = null ) {
147
+ return isset( $this->params[ $key ] ) ? $this->params[ $key ] : $default;
148
+ }
149
+
150
+ /**
151
+ * Sets value
152
+ *
153
+ * @param string $value Field value.
154
+ * @return void
155
+ */
156
+ public function set_value( $value ) {
157
+ $this->value = $value;
158
+ }
159
+
160
+ /**
161
+ * Gets value
162
+ *
163
+ * @return string
164
+ */
165
+ public function get_value() {
166
+ return null !== $this->value ? $this->value : $this->get( 'default' );
167
+ }
168
+
169
+ /**
170
+ * Gets layout
171
+ *
172
+ * @return string
173
+ */
174
+ public function get_layout() {
175
+ return $this->get( 'layout', 'two-column' );
176
+ }
177
+
178
+ /**
179
+ * Sets section
180
+ *
181
+ * @param Section $section Section instance.
182
+ * @throws \Exception If section is not instance of Section class.
183
+ * @return void
184
+ */
185
+ public function set_section( $section ) {
186
+ if ( ! $section instanceof Section ) {
187
+ /* translators: section variable type */
188
+ throw new \Exception( sprintf( __( 'Section must be an instance of EasyWatermark\\Settings\\Section. %s given', 'easy-watermark' ), gettype( $section ) ) );
189
+ }
190
+
191
+ $this->section = $section;
192
+ }
193
+
194
+ /**
195
+ * Gets field id
196
+ *
197
+ * @return string
198
+ */
199
+ public function get_id() {
200
+ return "ew-field-{$this->section->get_slug()}-{$this->get_slug()}";
201
+ }
202
+
203
+ /**
204
+ * Gets field name
205
+ *
206
+ * @return string
207
+ */
208
+ public function get_name() {
209
+ return "{$this->section->get_option_key()}[{$this->section->get_slug()}][{$this->get_slug()}]";
210
+ }
211
+
212
+ /**
213
+ * Renders Field
214
+ *
215
+ * @return void
216
+ */
217
+ public function render() {
218
+ $layout = $this->get_layout();
219
+
220
+ // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
221
+ echo new View( "dashboard/settings/field-{$layout}", [
222
+ 'field' => $this,
223
+ ] );
224
+ // phpcs:enable
225
+ }
226
+
227
+ /**
228
+ * Renders Field
229
+ *
230
+ * @return string
231
+ */
232
+ abstract public function render_field();
233
+
234
+ /**
235
+ * Sanitizes value
236
+ *
237
+ * @param mixed $value Field value to sanitize.
238
+ * @return mixed
239
+ */
240
+ abstract public function sanitize( $value );
241
+ }
src/classes/Settings/Fields/SwitchField.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
- /**
3
- * Settings Switch Field
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Settings\Fields;
9
-
10
- use EasyWatermark\Core\View;
11
-
12
- /**
13
- * SwitchField class
14
- */
15
- class SwitchField extends Checkbox {
16
-
17
- /**
18
- * Renders Field
19
- *
20
- * @return string
21
- */
22
- public function render_field() {
23
- return new View( 'dashboard/settings/fields/switch', [
24
- 'input' => parent::render_field(),
25
- 'field' => $this,
26
- ] );
27
- }
28
- }
1
+ <?php
2
+ /**
3
+ * Settings Switch Field
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Settings\Fields;
9
+
10
+ use EasyWatermark\Core\View;
11
+
12
+ /**
13
+ * SwitchField class
14
+ */
15
+ class SwitchField extends Checkbox {
16
+
17
+ /**
18
+ * Renders Field
19
+ *
20
+ * @return string
21
+ */
22
+ public function render_field() {
23
+ return new View( 'dashboard/settings/fields/switch', [
24
+ 'input' => parent::render_field(),
25
+ 'field' => $this,
26
+ ] );
27
+ }
28
+ }
src/classes/Settings/Section.php CHANGED
@@ -1,170 +1,170 @@
1
- <?php
2
- /**
3
- * Settings section
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Settings;
9
-
10
- use EasyWatermark\Core\View;
11
-
12
- /**
13
- * Section class
14
- */
15
- class Section {
16
-
17
- /**
18
- * Section name
19
- *
20
- * @var string
21
- */
22
- protected $name;
23
-
24
- /**
25
- * Section slug
26
- *
27
- * @var string
28
- */
29
- protected $slug;
30
-
31
- /**
32
- * Settings instance
33
- *
34
- * @var Settings
35
- */
36
- protected $settings;
37
-
38
- /**
39
- * Fields collection
40
- *
41
- * @var array
42
- */
43
- protected $fields = [];
44
-
45
- /**
46
- * Constructor
47
- *
48
- * @param string $name Section name.
49
- * @param string $slug Section slug.
50
- */
51
- public function __construct( $name, $slug = null ) {
52
- $this->set_name( $name );
53
- $this->set_slug( is_string( $slug ) ? $slug : sanitize_title( $name ) );
54
-
55
- do_action( "easy-watermark/settings/register/{$this->get_slug()}", $this );
56
- }
57
-
58
- /**
59
- * Sets name
60
- *
61
- * @param string $name Section name.
62
- * @return void
63
- */
64
- public function set_name( $name ) {
65
- $this->name = $name;
66
- }
67
-
68
- /**
69
- * Gets name
70
- *
71
- * @return string
72
- */
73
- public function get_name() {
74
- return $this->name;
75
- }
76
-
77
- /**
78
- * Sets slug
79
- *
80
- * @param string $slug Section slug.
81
- * @return void
82
- */
83
- public function set_slug( $slug ) {
84
- $this->slug = $slug;
85
- }
86
-
87
- /**
88
- * Gets slug
89
- *
90
- * @return string
91
- */
92
- public function get_slug() {
93
- return $this->slug;
94
- }
95
-
96
- /**
97
- * Sets settings instance
98
- *
99
- * @param Settings $settings Settings instance.
100
- * @throws \Exception If $settings is not instance of Settings class.
101
- * @return void
102
- */
103
- public function set_settings( $settings ) {
104
- if ( ! $settings instanceof Settings ) {
105
- /* translators: field variable type */
106
- throw new \Exception( sprintf( __( 'Settings must be an instance of EasyWatermark\\Settings\\Settings. %s given', 'easy-watermark' ), gettype( $settings ) ) );
107
- }
108
-
109
- $this->settings = $settings;
110
- }
111
-
112
- /**
113
- * Adds field
114
- *
115
- * @param Field $field Field instance.
116
- * @throws \Exception If field is not instance of Field class.
117
- * @return void
118
- */
119
- public function add_field( $field ) {
120
- if ( ! $field instanceof Field ) {
121
- /* translators: field variable type */
122
- throw new \Exception( sprintf( __( 'Field must be an instance of EasyWatermark\\Settings\\Field. %s given', 'easy-watermark' ), gettype( $field ) ) );
123
- }
124
-
125
- $field->set_section( $this );
126
- $this->fields[ $field->get_slug() ] = $field;
127
- }
128
-
129
- /**
130
- * Gets field object
131
- *
132
- * @param string $slug Field slug.
133
- * @return Field|false
134
- */
135
- public function get_field( $slug ) {
136
- return isset( $this->fields[ $slug ] ) ? $this->fields[ $slug ] : false;
137
- }
138
-
139
- /**
140
- * Gets array of fields
141
- *
142
- * @return array
143
- */
144
- public function get_fields() {
145
- return $this->fields;
146
- }
147
-
148
- /**
149
- * Gets option key
150
- *
151
- * @return string|false
152
- */
153
- public function get_option_key() {
154
- return $this->settings ? $this->settings->get_option_key() : false;
155
- }
156
-
157
- /**
158
- * Renders section
159
- *
160
- * @return void
161
- */
162
- public function render() {
163
- // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
164
- echo new View( 'dashboard/settings/section', [
165
- 'name' => $this->get_name(),
166
- 'fields' => $this->get_fields(),
167
- ] );
168
- // phpcs:enable
169
- }
170
- }
1
+ <?php
2
+ /**
3
+ * Settings section
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Settings;
9
+
10
+ use EasyWatermark\Core\View;
11
+
12
+ /**
13
+ * Section class
14
+ */
15
+ class Section {
16
+
17
+ /**
18
+ * Section name
19
+ *
20
+ * @var string
21
+ */
22
+ protected $name;
23
+
24
+ /**
25
+ * Section slug
26
+ *
27
+ * @var string
28
+ */
29
+ protected $slug;
30
+
31
+ /**
32
+ * Settings instance
33
+ *
34
+ * @var Settings
35
+ */
36
+ protected $settings;
37
+
38
+ /**
39
+ * Fields collection
40
+ *
41
+ * @var array
42
+ */
43
+ protected $fields = [];
44
+
45
+ /**
46
+ * Constructor
47
+ *
48
+ * @param string $name Section name.
49
+ * @param string $slug Section slug.
50
+ */
51
+ public function __construct( $name, $slug = null ) {
52
+ $this->set_name( $name );
53
+ $this->set_slug( is_string( $slug ) ? $slug : sanitize_title( $name ) );
54
+
55
+ do_action( "easy-watermark/settings/register/{$this->get_slug()}", $this );
56
+ }
57
+
58
+ /**
59
+ * Sets name
60
+ *
61
+ * @param string $name Section name.
62
+ * @return void
63
+ */
64
+ public function set_name( $name ) {
65
+ $this->name = $name;
66
+ }
67
+
68
+ /**
69
+ * Gets name
70
+ *
71
+ * @return string
72
+ */
73
+ public function get_name() {
74
+ return $this->name;
75
+ }
76
+
77
+ /**
78
+ * Sets slug
79
+ *
80
+ * @param string $slug Section slug.
81
+ * @return void
82
+ */
83
+ public function set_slug( $slug ) {
84
+ $this->slug = $slug;
85
+ }
86
+
87
+ /**
88
+ * Gets slug
89
+ *
90
+ * @return string
91
+ */
92
+ public function get_slug() {
93
+ return $this->slug;
94
+ }
95
+
96
+ /**
97
+ * Sets settings instance
98
+ *
99
+ * @param Settings $settings Settings instance.
100
+ * @throws \Exception If $settings is not instance of Settings class.
101
+ * @return void
102
+ */
103
+ public function set_settings( $settings ) {
104
+ if ( ! $settings instanceof Settings ) {
105
+ /* translators: field variable type */
106
+ throw new \Exception( sprintf( __( 'Settings must be an instance of EasyWatermark\\Settings\\Settings. %s given', 'easy-watermark' ), gettype( $settings ) ) );
107
+ }
108
+
109
+ $this->settings = $settings;
110
+ }
111
+
112
+ /**
113
+ * Adds field
114
+ *
115
+ * @param Field $field Field instance.
116
+ * @throws \Exception If field is not instance of Field class.
117
+ * @return void
118
+ */
119
+ public function add_field( $field ) {
120
+ if ( ! $field instanceof Field ) {
121
+ /* translators: field variable type */
122
+ throw new \Exception( sprintf( __( 'Field must be an instance of EasyWatermark\\Settings\\Field. %s given', 'easy-watermark' ), gettype( $field ) ) );
123
+ }
124
+
125
+ $field->set_section( $this );
126
+ $this->fields[ $field->get_slug() ] = $field;
127
+ }
128
+
129
+ /**
130
+ * Gets field object
131
+ *
132
+ * @param string $slug Field slug.
133
+ * @return Field|false
134
+ */
135
+ public function get_field( $slug ) {
136
+ return isset( $this->fields[ $slug ] ) ? $this->fields[ $slug ] : false;
137
+ }
138
+
139
+ /**
140
+ * Gets array of fields
141
+ *
142
+ * @return array
143
+ */
144
+ public function get_fields() {
145
+ return $this->fields;
146
+ }
147
+
148
+ /**
149
+ * Gets option key
150
+ *
151
+ * @return string|false
152
+ */
153
+ public function get_option_key() {
154
+ return $this->settings ? $this->settings->get_option_key() : false;
155
+ }
156
+
157
+ /**
158
+ * Renders section
159
+ *
160
+ * @return void
161
+ */
162
+ public function render() {
163
+ // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
164
+ echo new View( 'dashboard/settings/section', [
165
+ 'name' => $this->get_name(),
166
+ 'fields' => $this->get_fields(),
167
+ ] );
168
+ // phpcs:enable
169
+ }
170
+ }
src/classes/Traits/Hookable.php CHANGED
@@ -1,114 +1,114 @@
1
- <?php
2
- /**
3
- * Hookable trait allows to hook actions from doc comment.
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Traits;
9
-
10
- use EasyWatermark\Core\Hooks;
11
-
12
- trait Hookable {
13
-
14
- /**
15
- * Whether current object is hooked
16
- *
17
- * @var boolean
18
- */
19
- protected $hooked = false;
20
-
21
- /**
22
- * Pattern for doc hooks
23
- *
24
- * @var string
25
- */
26
- protected $pattern = '#\* @(?P<type>filter|action|shortcode)\s+(?P<name>[a-z0-9\-\.\/_]+)(\s+(?P<priority>\d+))?#';
27
-
28
- /**
29
- * Add actions/filters/shortcodes from the methods of a class based on DocBlocks
30
- */
31
- public function hook() {
32
-
33
- if ( true === $this->hooked ) {
34
- return;
35
- }
36
-
37
- $this->hooked = true;
38
-
39
- $reflector = new \ReflectionObject( $this );
40
- $hooks = Hooks::get();
41
-
42
- $hooks->add_object( $this );
43
-
44
- foreach ( $reflector->getMethods() as $method ) {
45
-
46
- $doc = $method->getDocComment();
47
- $arg_count = $method->getNumberOfParameters();
48
-
49
- if ( preg_match_all( $this->pattern, $doc, $matches, PREG_SET_ORDER ) ) {
50
-
51
- foreach ( $matches as $match ) {
52
-
53
- $type = $match['type'];
54
- $name = $match['name'];
55
-
56
- $priority = empty( $match['priority'] ) ? 10 : intval( $match['priority'] );
57
- $callback = [ $this, $method->getName() ];
58
-
59
- $function = sprintf( '\add_%s', $type );
60
-
61
- $retval = \call_user_func( $function, $name, $callback, $priority, $arg_count );
62
-
63
- $hooks->add_hook( $this, [
64
- 'name' => $name,
65
- 'type' => $type,
66
- 'callback' => $method->getName(),
67
- 'priority' => $priority,
68
- 'arg_count' => $arg_count,
69
- ] );
70
- }
71
- }
72
- }
73
-
74
- }
75
-
76
- /**
77
- * Removes the added DocBlock hooks
78
- */
79
- public function unhook() {
80
-
81
- $class_name = get_class( $this );
82
- $reflector = new \ReflectionObject( $this );
83
-
84
- foreach ( $reflector->getMethods() as $method ) {
85
-
86
- $doc = $method->getDocComment();
87
-
88
- if ( preg_match_all( $this->pattern, $doc, $matches, PREG_SET_ORDER ) ) {
89
-
90
- foreach ( $matches as $match ) {
91
-
92
- $type = $match['type'];
93
- $name = $match['name'];
94
-
95
- $priority = empty( $match['priority'] ) ? 10 : intval( $match['priority'] );
96
- $callback = array( $this, $method->getName() );
97
-
98
- call_user_func( "remove_{$type}", $name, $callback, $priority );
99
-
100
- }
101
- }
102
- }
103
-
104
- $this->hooked = false;
105
-
106
- }
107
-
108
- /**
109
- * Destructor
110
- */
111
- public function __destruct() {
112
- $this->unhook();
113
- }
114
- }
1
+ <?php
2
+ /**
3
+ * Hookable trait allows to hook actions from doc comment.
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Traits;
9
+
10
+ use EasyWatermark\Core\Hooks;
11
+
12
+ trait Hookable {
13
+
14
+ /**
15
+ * Whether current object is hooked
16
+ *
17
+ * @var boolean
18
+ */
19
+ protected $hooked = false;
20
+
21
+ /**
22
+ * Pattern for doc hooks
23
+ *
24
+ * @var string
25
+ */
26
+ protected $pattern = '#\* @(?P<type>filter|action|shortcode)\s+(?P<name>[a-z0-9\-\.\/_]+)(\s+(?P<priority>\d+))?#';
27
+
28
+ /**
29
+ * Add actions/filters/shortcodes from the methods of a class based on DocBlocks
30
+ */
31
+ public function hook() {
32
+
33
+ if ( true === $this->hooked ) {
34
+ return;
35
+ }
36
+
37
+ $this->hooked = true;
38
+
39
+ $reflector = new \ReflectionObject( $this );
40
+ $hooks = Hooks::get();
41
+
42
+ $hooks->add_object( $this );
43
+
44
+ foreach ( $reflector->getMethods() as $method ) {
45
+
46
+ $doc = $method->getDocComment();
47
+ $arg_count = $method->getNumberOfParameters();
48
+
49
+ if ( preg_match_all( $this->pattern, $doc, $matches, PREG_SET_ORDER ) ) {
50
+
51
+ foreach ( $matches as $match ) {
52
+
53
+ $type = $match['type'];
54
+ $name = $match['name'];
55
+
56
+ $priority = empty( $match['priority'] ) ? 10 : intval( $match['priority'] );
57
+ $callback = [ $this, $method->getName() ];
58
+
59
+ $function = sprintf( '\add_%s', $type );
60
+
61
+ $retval = \call_user_func( $function, $name, $callback, $priority, $arg_count );
62
+
63
+ $hooks->add_hook( $this, [
64
+ 'name' => $name,
65
+ 'type' => $type,
66
+ 'callback' => $method->getName(),
67
+ 'priority' => $priority,
68
+ 'arg_count' => $arg_count,
69
+ ] );
70
+ }
71
+ }
72
+ }
73
+
74
+ }
75
+
76
+ /**
77
+ * Removes the added DocBlock hooks
78
+ */
79
+ public function unhook() {
80
+
81
+ $class_name = get_class( $this );
82
+ $reflector = new \ReflectionObject( $this );
83
+
84
+ foreach ( $reflector->getMethods() as $method ) {
85
+
86
+ $doc = $method->getDocComment();
87
+
88
+ if ( preg_match_all( $this->pattern, $doc, $matches, PREG_SET_ORDER ) ) {
89
+
90
+ foreach ( $matches as $match ) {
91
+
92
+ $type = $match['type'];
93
+ $name = $match['name'];
94
+
95
+ $priority = empty( $match['priority'] ) ? 10 : intval( $match['priority'] );
96
+ $callback = array( $this, $method->getName() );
97
+
98
+ call_user_func( "remove_{$type}", $name, $callback, $priority );
99
+
100
+ }
101
+ }
102
+ }
103
+
104
+ $this->hooked = false;
105
+
106
+ }
107
+
108
+ /**
109
+ * Destructor
110
+ */
111
+ public function __destruct() {
112
+ $this->unhook();
113
+ }
114
+ }
src/classes/Watermark/Ajax.php CHANGED
@@ -1,281 +1,281 @@
1
- <?php
2
- /**
3
- * AjaxHandler class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Watermark;
9
-
10
- use EasyWatermark\Traits\Hookable;
11
- use EasyWatermark\Metaboxes\Attachment\Watermarks;
12
-
13
- /**
14
- * AjaxHandler class
15
- */
16
- class Ajax {
17
-
18
- use Hookable;
19
-
20
- /**
21
- * Watermark Handler instance
22
- *
23
- * @var Handler
24
- */
25
- private $watermark_handler;
26
-
27
- /**
28
- * Constructor
29
- *
30
- * @param Handler $handler Handler instance.
31
- */
32
- public function __construct( $handler ) {
33
-
34
- $this->hook();
35
-
36
- $this->watermark_handler = $handler;
37
-
38
- }
39
-
40
- /**
41
- * Applies single watermark
42
- *
43
- * @action wp_ajax_easy-watermark/apply_single
44
- *
45
- * @return void
46
- */
47
- public function apply_single_watermark() {
48
-
49
- if ( ! isset( $_REQUEST['watermark'] ) || ! isset( $_REQUEST['attachment_id'] ) ) {
50
- wp_send_json_error( [
51
- 'message' => __( 'Something went wrong. Please try again.', 'easy-watermark' ),
52
- ] );
53
- }
54
-
55
- $watermark_id = intval( $_REQUEST['watermark'] );
56
-
57
- check_ajax_referer( 'apply_single-' . $watermark_id, 'nonce' );
58
-
59
- if ( ! current_user_can( 'apply_watermark' ) ) {
60
- wp_send_json_error( [
61
- 'message' => __( 'You don\'t have permission to apply watermarks.', 'easy-watermark' ),
62
- ] );
63
- }
64
-
65
- $attachment_id = intval( $_REQUEST['attachment_id'] );
66
- $result = $this->watermark_handler->apply_single_watermark( $attachment_id, $watermark_id );
67
- $version = get_post_meta( $attachment_id, '_ew_attachment_version', true );
68
- $success_message = __( 'Watermark has been applied.', 'easy-watermark' );
69
-
70
- $this->send_response( $result, $version, $attachment_id, $success_message );
71
-
72
- }
73
-
74
- /**
75
- * Applies all watermarks
76
- *
77
- * @action wp_ajax_easy-watermark/apply_all
78
- *
79
- * @return void
80
- */
81
- public function apply_all_watermarks() {
82
-
83
- check_ajax_referer( 'apply_all', 'nonce' );
84
-
85
- if ( ! isset( $_REQUEST['attachment_id'] ) ) {
86
- wp_send_json_error( [
87
- 'message' => __( 'Something went wrong. Please try again.', 'easy-watermark' ),
88
- ] );
89
- }
90
-
91
- if ( ! current_user_can( 'apply_watermark' ) ) {
92
- wp_send_json_error( [
93
- 'messages' => [
94
- __( 'You don\'t have permission to apply watermarks.', 'easy-watermark' ),
95
- ],
96
- ] );
97
- }
98
-
99
- $attachment_id = intval( $_REQUEST['attachment_id'] );
100
- $result = $this->watermark_handler->apply_all_watermarks( $attachment_id );
101
- $version = get_post_meta( $attachment_id, '_ew_attachment_version', true );
102
- $success_message = __( 'All watermarks has been applied.', 'easy-watermark' );
103
-
104
- $this->send_response( $result, $version, $attachment_id, $success_message );
105
-
106
- }
107
-
108
- /**
109
- * Restores backup
110
- *
111
- * @action wp_ajax_easy-watermark/restore_backup
112
- *
113
- * @return void
114
- */
115
- public function restore_backup() {
116
-
117
- check_ajax_referer( 'restore_backup', 'nonce' );
118
-
119
- if ( ! isset( $_REQUEST['attachment_id'] ) ) {
120
- wp_send_json_error( [
121
- 'message' => __( 'Something went wrong. Please try again.', 'easy-watermark' ),
122
- ] );
123
- }
124
-
125
- if ( ! current_user_can( 'apply_watermark' ) ) {
126
- wp_send_json_error( [
127
- 'messages' => [
128
- __( 'You don\'t have permission to restore backup.', 'easy-watermark' ),
129
- ],
130
- ] );
131
- }
132
-
133
- $attachment_id = intval( $_REQUEST['attachment_id'] );
134
- $meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
135
- $result = $this->watermark_handler->restore_backup( $attachment_id, $meta );
136
- $version = get_post_meta( $attachment_id, '_ew_attachment_version', true );
137
- $success_message = __( 'Original image has been restored.', 'easy-watermark' );
138
-
139
- $this->send_response( $result, $version, $attachment_id, $success_message );
140
-
141
- }
142
-
143
- /**
144
- * Temporarily saves watermark settings
145
- *
146
- * @action wp_ajax_easy-watermark/autosave
147
- *
148
- * @return void
149
- */
150
- public function autosave() {
151
-
152
- check_ajax_referer( 'watermark_autosave', 'nonce' );
153
-
154
- if ( ! isset( $_REQUEST['watermark'] ) || ! isset( $_REQUEST['post_ID'] ) ) {
155
- wp_send_json_error( [
156
- 'message' => __( 'No watermark data to save.', 'easy-watermark' ),
157
- ] );
158
- }
159
-
160
- $post_id = intval( $_REQUEST['post_ID'] );
161
-
162
- // phpcs:ignore
163
- $result = update_post_meta( $post_id, '_ew_tmp_params', $_REQUEST['watermark'] );
164
-
165
- if ( false === $result ) {
166
- wp_send_json_error( [
167
- 'message' => __( 'Something went wrong while saving temporary data.', 'easy-watermark' ),
168
- ] );
169
- }
170
-
171
- wp_send_json_success( $result );
172
-
173
- }
174
-
175
- /**
176
- * Temporarily saves watermark settings
177
- *
178
- * @action wp_ajax_easy-watermark/attachments-info
179
- *
180
- * @return void
181
- */
182
- public function get_attachments_info() {
183
-
184
- check_ajax_referer( 'attachments_info', 'nonce' );
185
-
186
- if ( ! isset( $_REQUEST['attachments'] ) || ! is_array( $_REQUEST['attachments'] ) ) {
187
- wp_send_json_error( [
188
- 'message' => __( 'Invalid request.', 'easy-watermark' ),
189
- ] );
190
- }
191
-
192
- $attachment_ids = [];
193
-
194
- // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
195
- foreach ( $_REQUEST['attachments'] as $id ) {
196
- $attachment_ids[] = intval( $id );
197
- }
198
-
199
- $placeholders = implode( ',', array_fill( 0, count( $attachment_ids ), '%d' ) );
200
-
201
- global $wpdb;
202
-
203
- $query = "
204
- SELECT
205
- `{$wpdb->posts}`.`ID` as id,
206
- `{$wpdb->posts}`.`post_mime_type` as mime,
207
- EXISTS( SELECT `{$wpdb->postmeta}`.`meta_value` FROM `{$wpdb->postmeta}` WHERE `{$wpdb->postmeta}`.`post_id` = `{$wpdb->posts}`.`ID` AND `{$wpdb->postmeta}`.`meta_key` = '_ew_used_as_watermark' ) AS 'usedAsWatermark',
208
- EXISTS( SELECT `{$wpdb->postmeta}`.`meta_value` FROM `{$wpdb->postmeta}` WHERE `{$wpdb->postmeta}`.`post_id` = `{$wpdb->posts}`.`ID` AND `{$wpdb->postmeta}`.`meta_key` = '_ew_has_backup' ) AS 'hasBackup'
209
- FROM
210
- `{$wpdb->posts}`
211
- WHERE `{$wpdb->posts}`.`ID` IN ({$placeholders})
212
- ";
213
-
214
- // phpcs:ignore WordPress.DB
215
- $results = $wpdb->get_results( $wpdb->prepare( $query, $attachment_ids ), ARRAY_A );
216
-
217
- if ( ! $results ) {
218
- wp_send_json_error( [
219
- 'message' => __( 'Something went wrong. Please refresh the page and try again.', 'easy-watermark' ),
220
- ] );
221
- }
222
-
223
- foreach ( $results as &$row ) {
224
- array_walk( $row, function ( &$value, $key ) {
225
- if ( 'id' === $key ) {
226
- return;
227
- }
228
-
229
- if ( is_numeric( $value ) ) {
230
- $value = (bool) $value;
231
- }
232
- } );
233
- }
234
-
235
- wp_send_json_success( $results );
236
-
237
- }
238
-
239
- /**
240
- * Sends response
241
- *
242
- * @param mixed $result Watermarking result.
243
- * @param string $version Attachment version.
244
- * @param integer $attachment_id Attachment ID.
245
- * @param string $success_message Success message.
246
- * @return void
247
- */
248
- protected function send_response( $result, $version, $attachment_id, $success_message ) {
249
-
250
- $response_data = [
251
- 'metaboxContent' => (string) Watermarks::get_content( get_post( $attachment_id ) ),
252
- 'result' => $result,
253
- 'attachmentVersion' => $version,
254
- 'hasBackup' => get_post_meta( $attachment_id, '_ew_has_backup', true ),
255
- ];
256
-
257
- if ( is_wp_error( $result ) ) {
258
- $messages = $result->get_error_messages();
259
- $count = count( $messages );
260
-
261
- /* translators: errors count. */
262
- $error_message = sprintf( _n( '%s error has occured.', '%s errors has occured.', $count, 'easy-watermark' ), $count );
263
-
264
- $response_data['message'] = $error_message . '<ul><li>' . implode( '</li><li>', $messages ) . '</li></ul>';
265
-
266
- wp_send_json_error( $response_data );
267
- } else {
268
- $response_data['message'] = $success_message;
269
-
270
- wp_send_json_success( $response_data );
271
- }
272
-
273
- }
274
-
275
- /**
276
- * Destructor
277
- */
278
- public function __destruct() {
279
- $this->unhook();
280
- }
281
- }
1
+ <?php
2
+ /**
3
+ * AjaxHandler class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Watermark;
9
+
10
+ use EasyWatermark\Traits\Hookable;
11
+ use EasyWatermark\Metaboxes\Attachment\Watermarks;
12
+
13
+ /**
14
+ * AjaxHandler class
15
+ */
16
+ class Ajax {
17
+
18
+ use Hookable;
19
+
20
+ /**
21
+ * Watermark Handler instance
22
+ *
23
+ * @var Handler
24
+ */
25
+ private $watermark_handler;
26
+
27
+ /**
28
+ * Constructor
29
+ *
30
+ * @param Handler $handler Handler instance.
31
+ */
32
+ public function __construct( $handler ) {
33
+
34
+ $this->hook();
35
+
36
+ $this->watermark_handler = $handler;
37
+
38
+ }
39
+
40
+ /**
41
+ * Applies single watermark
42
+ *
43
+ * @action wp_ajax_easy-watermark/apply_single
44
+ *
45
+ * @return void
46
+ */
47
+ public function apply_single_watermark() {
48
+
49
+ if ( ! isset( $_REQUEST['watermark'] ) || ! isset( $_REQUEST['attachment_id'] ) ) {
50
+ wp_send_json_error( [
51
+ 'message' => __( 'Something went wrong. Please try again.', 'easy-watermark' ),
52
+ ] );
53
+ }
54
+
55
+ $watermark_id = intval( $_REQUEST['watermark'] );
56
+
57
+ check_ajax_referer( 'apply_single-' . $watermark_id, 'nonce' );
58
+
59
+ if ( ! current_user_can( 'apply_watermark' ) ) {
60
+ wp_send_json_error( [
61
+ 'message' => __( 'You don\'t have permission to apply watermarks.', 'easy-watermark' ),
62
+ ] );
63
+ }
64
+
65
+ $attachment_id = intval( $_REQUEST['attachment_id'] );
66
+ $result = $this->watermark_handler->apply_single_watermark( $attachment_id, $watermark_id );
67
+ $version = get_post_meta( $attachment_id, '_ew_attachment_version', true );
68
+ $success_message = __( 'Watermark has been applied.', 'easy-watermark' );
69
+
70
+ $this->send_response( $result, $version, $attachment_id, $success_message );
71
+
72
+ }
73
+
74
+ /**
75
+ * Applies all watermarks
76
+ *
77
+ * @action wp_ajax_easy-watermark/apply_all
78
+ *
79
+ * @return void
80
+ */
81
+ public function apply_all_watermarks() {
82
+
83
+ check_ajax_referer( 'apply_all', 'nonce' );
84
+
85
+ if ( ! isset( $_REQUEST['attachment_id'] ) ) {
86
+ wp_send_json_error( [
87
+ 'message' => __( 'Something went wrong. Please try again.', 'easy-watermark' ),
88
+ ] );
89
+ }
90
+
91
+ if ( ! current_user_can( 'apply_watermark' ) ) {
92
+ wp_send_json_error( [
93
+ 'messages' => [
94
+ __( 'You don\'t have permission to apply watermarks.', 'easy-watermark' ),
95
+ ],
96
+ ] );
97
+ }
98
+
99
+ $attachment_id = intval( $_REQUEST['attachment_id'] );
100
+ $result = $this->watermark_handler->apply_all_watermarks( $attachment_id );
101
+ $version = get_post_meta( $attachment_id, '_ew_attachment_version', true );
102
+ $success_message = __( 'All watermarks has been applied.', 'easy-watermark' );
103
+
104
+ $this->send_response( $result, $version, $attachment_id, $success_message );
105
+
106
+ }
107
+
108
+ /**
109
+ * Restores backup
110
+ *
111
+ * @action wp_ajax_easy-watermark/restore_backup
112
+ *
113
+ * @return void
114
+ */
115
+ public function restore_backup() {
116
+
117
+ check_ajax_referer( 'restore_backup', 'nonce' );
118
+
119
+ if ( ! isset( $_REQUEST['attachment_id'] ) ) {
120
+ wp_send_json_error( [
121
+ 'message' => __( 'Something went wrong. Please try again.', 'easy-watermark' ),
122
+ ] );
123
+ }
124
+
125
+ if ( ! current_user_can( 'apply_watermark' ) ) {
126
+ wp_send_json_error( [
127
+ 'messages' => [
128
+ __( 'You don\'t have permission to restore backup.', 'easy-watermark' ),
129
+ ],
130
+ ] );
131
+ }
132
+
133
+ $attachment_id = intval( $_REQUEST['attachment_id'] );
134
+ $meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
135
+ $result = $this->watermark_handler->restore_backup( $attachment_id, $meta );
136
+ $version = get_post_meta( $attachment_id, '_ew_attachment_version', true );
137
+ $success_message = __( 'Original image has been restored.', 'easy-watermark' );
138
+
139
+ $this->send_response( $result, $version, $attachment_id, $success_message );
140
+
141
+ }
142
+
143
+ /**
144
+ * Temporarily saves watermark settings
145
+ *
146
+ * @action wp_ajax_easy-watermark/autosave
147
+ *
148
+ * @return void
149
+ */
150
+ public function autosave() {
151
+
152
+ check_ajax_referer( 'watermark_autosave', 'nonce' );
153
+
154
+ if ( ! isset( $_REQUEST['watermark'] ) || ! isset( $_REQUEST['post_ID'] ) ) {
155
+ wp_send_json_error( [
156
+ 'message' => __( 'No watermark data to save.', 'easy-watermark' ),
157
+ ] );
158
+ }
159
+
160
+ $post_id = intval( $_REQUEST['post_ID'] );
161
+
162
+ // phpcs:ignore
163
+ $result = update_post_meta( $post_id, '_ew_tmp_params', $_REQUEST['watermark'] );
164
+
165
+ if ( false === $result ) {
166
+ wp_send_json_error( [
167
+ 'message' => __( 'Something went wrong while saving temporary data.', 'easy-watermark' ),
168
+ ] );
169
+ }
170
+
171
+ wp_send_json_success( $result );
172
+
173
+ }
174
+
175
+ /**
176
+ * Temporarily saves watermark settings
177
+ *
178
+ * @action wp_ajax_easy-watermark/attachments-info
179
+ *
180
+ * @return void
181
+ */
182
+ public function get_attachments_info() {
183
+
184
+ check_ajax_referer( 'attachments_info', 'nonce' );
185
+
186
+ if ( ! isset( $_REQUEST['attachments'] ) || ! is_array( $_REQUEST['attachments'] ) ) {
187
+ wp_send_json_error( [
188
+ 'message' => __( 'Invalid request.', 'easy-watermark' ),
189
+ ] );
190
+ }
191
+
192
+ $attachment_ids = [];
193
+
194
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
195
+ foreach ( $_REQUEST['attachments'] as $id ) {
196
+ $attachment_ids[] = intval( $id );
197
+ }
198
+
199
+ $placeholders = implode( ',', array_fill( 0, count( $attachment_ids ), '%d' ) );
200
+
201
+ global $wpdb;
202
+
203
+ $query = "
204
+ SELECT
205
+ `{$wpdb->posts}`.`ID` as id,
206
+ `{$wpdb->posts}`.`post_mime_type` as mime,
207
+ EXISTS( SELECT `{$wpdb->postmeta}`.`meta_value` FROM `{$wpdb->postmeta}` WHERE `{$wpdb->postmeta}`.`post_id` = `{$wpdb->posts}`.`ID` AND `{$wpdb->postmeta}`.`meta_key` = '_ew_used_as_watermark' ) AS 'usedAsWatermark',
208
+ EXISTS( SELECT `{$wpdb->postmeta}`.`meta_value` FROM `{$wpdb->postmeta}` WHERE `{$wpdb->postmeta}`.`post_id` = `{$wpdb->posts}`.`ID` AND `{$wpdb->postmeta}`.`meta_key` = '_ew_has_backup' ) AS 'hasBackup'
209
+ FROM
210
+ `{$wpdb->posts}`
211
+ WHERE `{$wpdb->posts}`.`ID` IN ({$placeholders})
212
+ ";
213
+
214
+ // phpcs:ignore WordPress.DB
215
+ $results = $wpdb->get_results( $wpdb->prepare( $query, $attachment_ids ), ARRAY_A );
216
+
217
+ if ( ! $results ) {
218
+ wp_send_json_error( [
219
+ 'message' => __( 'Something went wrong. Please refresh the page and try again.', 'easy-watermark' ),
220
+ ] );
221
+ }
222
+
223
+ foreach ( $results as &$row ) {
224
+ array_walk( $row, function ( &$value, $key ) {
225
+ if ( 'id' === $key ) {
226
+ return;
227
+ }
228
+
229
+ if ( is_numeric( $value ) ) {
230
+ $value = (bool) $value;
231
+ }
232
+ } );
233
+ }
234
+
235
+ wp_send_json_success( $results );
236
+
237
+ }
238
+
239
+ /**
240
+ * Sends response
241
+ *
242
+ * @param mixed $result Watermarking result.
243
+ * @param string $version Attachment version.
244
+ * @param integer $attachment_id Attachment ID.
245
+ * @param string $success_message Success message.
246
+ * @return void
247
+ */
248
+ protected function send_response( $result, $version, $attachment_id, $success_message ) {
249
+
250
+ $response_data = [
251
+ 'metaboxContent' => (string) Watermarks::get_content( get_post( $attachment_id ) ),
252
+ 'result' => $result,
253
+ 'attachmentVersion' => $version,
254
+ 'hasBackup' => get_post_meta( $attachment_id, '_ew_has_backup', true ),
255
+ ];
256
+
257
+ if ( is_wp_error( $result ) ) {
258
+ $messages = $result->get_error_messages();
259
+ $count = count( $messages );
260
+
261
+ /* translators: errors count. */
262
+ $error_message = sprintf( _n( '%s error has occured.', '%s errors has occured.', $count, 'easy-watermark' ), $count );
263
+
264
+ $response_data['message'] = $error_message . '<ul><li>' . implode( '</li><li>', $messages ) . '</li></ul>';
265
+
266
+ wp_send_json_error( $response_data );
267
+ } else {
268
+ $response_data['message'] = $success_message;
269
+
270
+ wp_send_json_success( $response_data );
271
+ }
272
+
273
+ }
274
+
275
+ /**
276
+ * Destructor
277
+ */
278
+ public function __destruct() {
279
+ $this->unhook();
280
+ }
281
+ }
src/classes/Watermark/Handler.php CHANGED
@@ -1,522 +1,503 @@
1
- <?php
2
- /**
3
- * Handler class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Watermark;
9
-
10
- use EasyWatermark\AttachmentProcessor;
11
- use EasyWatermark\AttachmentProcessor\Manager as ProcessorManager;
12
- use EasyWatermark\Backup\BackupperInterface;
13
- use EasyWatermark\Backup\Manager as BackupManager;
14
- use EasyWatermark\Settings\Settings;
15
- use EasyWatermark\Helpers\Image as ImageHelper;
16
- use EasyWatermark\Metaboxes\Attachment\Watermarks;
17
- use EasyWatermark\Placeholders\Resolver;
18
- use WP_Error;
19
-
20
- /**
21
- * Handler class
22
- */
23
- class Handler {
24
-
25
- /**
26
- * If set to true, watermarks will not be applied.
27
- *
28
- * @var boolean
29
- */
30
- private $lock = false;
31
-
32
- /**
33
- * AttachmentProcessor instance
34
- *
35
- * @var AttachmentProcessor
36
- */
37
- private $processor;
38
-
39
- /**
40
- * Backupper instance
41
- *
42
- * @var Backupper
43
- */
44
- private $backupper;
45
-
46
- /**
47
- * Placeholders Resolver instance
48
- *
49
- * @var Resolver
50
- */
51
- private $resolver;
52
-
53
- /**
54
- * Settings instance
55
- *
56
- * @var Settings
57
- */
58
- private $settings;
59
-
60
- /**
61
- * Temporarily stored meta for newly uploaded attachment
62
- *
63
- * @var Settings
64
- */
65
- private $tmp_meta;
66
-
67
- /**
68
- * Constructor
69
- */
70
- public function __construct() {
71
-
72
- new Ajax( $this );
73
- new Hooks( $this );
74
-
75
- $this->settings = Settings::get();
76
-
77
- $backup = $this->settings->get_setting( 'backup/backup' );
78
- $backupper = $this->settings->get_setting( 'backup/backupper' );
79
-
80
- if ( false === $backup || ! $backupper ) {
81
- // If backup is not enabled load local backuper for temporary backups.
82
- $backupper = 'local';
83
- }
84
-
85
- $this->backupper = BackupManager::get()->get_object( $backupper );
86
- $this->processor = ProcessorManager::get()->get_object( 'gd' );
87
- $this->resolver = Resolver::get();
88
-
89
- $this->processor->set_param( 'jpeg_quality', $this->settings->get_setting( 'general/jpeg_quality' ) );
90
-
91
- }
92
-
93
- /**
94
- * Returns array of all published watermarks
95
- *
96
- * @return array
97
- */
98
- public function get_watermarks() {
99
-
100
- $posts = get_posts( [
101
- 'post_type' => 'watermark',
102
- 'post_status' => 'publish',
103
- 'posts_per_page' => -1,
104
- ] );
105
-
106
- $watermarks = [];
107
-
108
- foreach ( $posts as $post ) {
109
- $watermarks[] = Watermark::get( $post );
110
- }
111
-
112
- return $watermarks;
113
-
114
- }
115
-
116
- /**
117
- * Returns available watermark types
118
- *
119
- * @return array
120
- */
121
- public function get_watermark_types() {
122
-
123
- global $post;
124
-
125
- $types = [
126
- 'text' => [
127
- 'label' => __( 'Text', 'easy-watermark' ),
128
- 'available' => true,
129
- ],
130
- 'image' => [
131
- 'label' => __( 'Image', 'easy-watermark' ),
132
- 'available' => true,
133
- ],
134
- ];
135
-
136
- $types = apply_filters( 'easy-watermark/watermark-types', $types );
137
-
138
- $watermarks = $this->get_watermarks();
139
-
140
- foreach ( $watermarks as $watermark ) {
141
- if ( $post && $watermark->ID === $post->ID ) {
142
- continue;
143
- }
144
-
145
- if ( array_key_exists( $watermark->type, $types ) ) {
146
- $types[ $watermark->type ]['available'] = false;
147
- }
148
- }
149
-
150
- return $types;
151
-
152
- }
153
-
154
- /**
155
- * Applies single watermark
156
- *
157
- * @param integer $attachment_id Attachment id.
158
- * @param integer $watermark_id Watermark id.
159
- * @return boolean|WP_Error
160
- */
161
- public function apply_single_watermark( $attachment_id, $watermark_id ) {
162
-
163
- if ( true === $this->lock ) {
164
- return true;
165
- }
166
-
167
- $watermark = Watermark::get( $watermark_id );
168
-
169
- if ( 'publish' !== $watermark->post_status ) {
170
- return false;
171
- }
172
-
173
- return $this->apply_watermarks( $attachment_id, [ $watermark ] );
174
-
175
- }
176
-
177
- /**
178
- * Applies single watermark
179
- *
180
- * @param integer $attachment_id Attachment id.
181
- * @return boolean|WP_Error
182
- */
183
- public function apply_all_watermarks( $attachment_id ) {
184
-
185
- if ( true === $this->lock ) {
186
- return true;
187
- }
188
-
189
- $watermarks = $this->get_watermarks();
190
-
191
- return $this->apply_watermarks( $attachment_id, $watermarks );
192
-
193
- }
194
-
195
- /**
196
- * Applies single watermark
197
- *
198
- * @param integer $attachment_id Attachment ID.
199
- * @param array $watermarks Array of Watermark objects.
200
- * @param array $meta Attachment metadata.
201
- * @return bool|WP_Error
202
- */
203
- public function apply_watermarks( $attachment_id, $watermarks, $meta = [] ) {
204
-
205
- if ( true === $this->lock ) {
206
- return false;
207
- }
208
-
209
- if ( empty( $watermarks ) ) {
210
- return false;
211
- }
212
-
213
- $used_as_watermark = get_post_meta( $attachment_id, '_ew_used_as_watermark', true );
214
-
215
- if ( $used_as_watermark ) {
216
- return false;
217
- }
218
-
219
- $attachment = get_post( $attachment_id );
220
- $available_mime_types = ImageHelper::get_available_mime_types();
221
-
222
- if ( ! array_key_exists( $attachment->post_mime_type, $available_mime_types ) ) {
223
- return false;
224
- }
225
-
226
- $error = new WP_Error();
227
-
228
- $this->resolver->reset();
229
- $this->resolver->set_attachment( $attachment );
230
-
231
- $applied_watermarks = get_post_meta( $attachment_id, '_ew_applied_watermarks', true );
232
-
233
- if ( ! is_array( $applied_watermarks ) ) {
234
- $applied_watermarks = [];
235
- }
236
-
237
- $watermarks = array_filter( $watermarks, function( $watermark ) use ( $applied_watermarks ) {
238
- return ! array_key_exists( $watermark->ID, $applied_watermarks );
239
- } );
240
-
241
- if ( empty( $meta ) ) {
242
- $meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
243
- }
244
-
245
- if ( ! $meta ) {
246
- $error->add( 'empty_metadata', __( 'You try to watermark an item that doesn\'t exist. Please refresh the page and try again.', 'easy-watermark' ) );
247
-
248
- return $error;
249
- }
250
-
251
- $filepath = get_attached_file( $attachment_id );
252
- $sizes = $meta['sizes'];
253
- $baename = wp_basename( $meta['file'] );
254
-
255
- $sizes['full'] = [
256
- 'file' => $meta['file'],
257
- 'mime-type' => $attachment->post_mime_type,
258
- ];
259
-
260
- $this->do_backup( $attachment_id );
261
-
262
- foreach ( $sizes as $size => $image ) {
263
- $apply = false;
264
-
265
- foreach ( $watermarks as $watermark ) {
266
- if ( in_array( $size, $watermark->image_sizes, true ) ) {
267
- $apply = true;
268
-
269
- if ( 'text' === $watermark->type ) {
270
- $watermark->text = $this->resolver->resolve( $watermark->text );
271
- }
272
-
273
- $this->processor->add_watermark( $watermark );
274
-
275
- if ( ! array_key_exists( $watermark->ID, $applied_watermarks ) ) {
276
- $applied_watermarks[ $watermark->ID ] = $watermark->post_title;
277
- }
278
- }
279
- }
280
-
281
- if ( true === $apply ) {
282
- $image_file = str_replace( $baename, wp_basename( $image['file'] ), $filepath );
283
-
284
- $this->processor
285
- ->set_file( $image_file )
286
- ->set_param( 'image_type', $image['mime-type'] );
287
-
288
- $results = $this->processor->process();
289
-
290
- $this->processor->clean();
291
-
292
- foreach ( $results as $watermark_id => $result ) {
293
- if ( is_wp_error( $result ) ) {
294
- /* translators: watermark name, image size, original error message. */
295
- $error->add( 'watermark_error', sprintf( __( 'Watermark "%1$s" couldn\'t be applied for "%2$s" image size: %3$s', 'easy-watermark' ), Watermark::get( $watermark_id )->post_title, $size, $result->get_error_message() ) );
296
- }
297
- }
298
- }
299
- }
300
-
301
- $error_messages = $error->get_error_messages();
302
- $has_error = ! empty( $error_messages );
303
- if ( false === $this->settings->get_setting( 'backup/backup' ) || true === $has_error ) {
304
- $this->clean_backup( $attachment_id );
305
- }
306
-
307
- if ( empty( $error_messages ) ) {
308
- update_post_meta( $attachment_id, '_ew_applied_watermarks', $applied_watermarks );
309
- update_post_meta( $attachment_id, '_ew_attachment_version', time() );
310
-
311
- return true;
312
- }
313
-
314
- $this->restore_backup( $attachment_id, $meta );
315
-
316
- return $error;
317
-
318
- }
319
-
320
- /**
321
- * Performs attachment backup
322
- *
323
- * @param integer $attachment_id Attachment ID.
324
- * @return bool|WP_Error
325
- */
326
- public function do_backup( $attachment_id ) {
327
-
328
- if ( ! $this->backupper instanceof BackupperInterface ) {
329
- return false;
330
- }
331
-
332
- $has_backup = get_post_meta( $attachment_id, '_ew_has_backup', true );
333
-
334
- if ( '1' === $has_backup ) {
335
- return false;
336
- }
337
-
338
- $result = $this->backupper->backup( $attachment_id );
339
-
340
- if ( is_wp_error( $result ) ) {
341
- return $result;
342
- }
343
-
344
- update_post_meta( $attachment_id, '_ew_has_backup', true );
345
-
346
- return true;
347
-
348
- }
349
-
350
- /**
351
- * Restores attachment backup
352
- *
353
- * @param integer $attachment_id Attachment ID.
354
- * @param array $old_meta Attachment metadata array.
355
- * @return true|WP_Error
356
- */
357
- public function restore_backup( $attachment_id, $old_meta ) {
358
-
359
- if ( ! $this->backupper instanceof BackupperInterface ) {
360
- return;
361
- }
362
-
363
- $has_backup = get_post_meta( $attachment_id, '_ew_has_backup', true );
364
-
365
- if ( '1' !== $has_backup ) {
366
- return;
367
- }
368
-
369
- // Set lock to prevent regenerated thumbnails from being watermarked.
370
- $this->lock = true;
371
-
372
- $restored = $this->backupper->restore( $attachment_id );
373
-
374
- if ( is_wp_error( $restored ) ) {
375
- return $restored;
376
- }
377
-
378
- $current_file = get_attached_file( $attachment_id );
379
- $filebasename = wp_basename( $current_file );
380
-
381
- foreach ( $old_meta['sizes'] as $size => $image ) {
382
- $file = str_replace( $filebasename, wp_basename( $image['file'] ), $current_file );
383
- file_exists( $file ) && unlink( $file );
384
- }
385
-
386
- wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $current_file ) );
387
-
388
- update_post_meta( $attachment_id, '_ew_attachment_version', time() );
389
- delete_post_meta( $attachment_id, '_ew_applied_watermarks' );
390
- delete_post_meta( $attachment_id, '_ew_has_backup' );
391
-
392
- $this->lock = false;
393
-
394
- return true;
395
-
396
- }
397
-
398
- /**
399
- * Removes attachment backup
400
- *
401
- * @param integer $attachment_id Attachment ID.
402
- * @return true|WP_Error
403
- */
404
- public function clean_backup( $attachment_id ) {
405
-
406
- if ( ! $this->backupper instanceof BackupperInterface ) {
407
- return;
408
- }
409
-
410
- $result = $this->backupper->clean( $attachment_id );
411
-
412
- if ( is_wp_error( $result ) ) {
413
- return $result;
414
- }
415
-
416
- delete_post_meta( $attachment_id, '_ew_has_backup' );
417
-
418
- return true;
419
-
420
- }
421
-
422
- /**
423
- * Prints text preview
424
- *
425
- * @param Watermark $watermark Watermark object.
426
- * @param string $format Preview format (jpg|png).
427
- * @return void
428
- */
429
- public function print_text_preview( $watermark, $format ) {
430
-
431
- if ( 'text' !== $watermark->type ) {
432
- return;
433
- }
434
-
435
- if ( $watermark->text ) {
436
- $watermark->text = $this->resolver->resolve( $watermark->text );
437
- } else {
438
- $watermark->text = sprintf( '{%s}', _x( 'no_text', 'Placeholder for watermark text preview if no text specified.', 'easy-watermark' ) );
439
- }
440
-
441
- $result = $this->processor->print_text_preview( $watermark, $format );
442
-
443
- if ( ! is_wp_error( $result ) ) {
444
- exit;
445
- }
446
-
447
- }
448
-
449
- /**
450
- * Prints watermark preview
451
- *
452
- * @param Watermark $watermark Watermark object.
453
- * @param string $format Preview format (jpg|png).
454
- * @param string $size Preview image size.
455
- * @return void
456
- */
457
- public function print_preview( $watermark, $format, $size ) {
458
-
459
- $attachment_id = get_option( '_ew_preview_image_id' );
460
-
461
- if ( ! $attachment_id ) {
462
- return;
463
- }
464
-
465
- if ( ! in_array( $size, $watermark->image_sizes, true ) ) {
466
- $watermark = null;
467
- }
468
-
469
- $attachment = get_post( $attachment_id );
470
-
471
- if ( 'text' === $watermark->type ) {
472
- $this->resolver->set_attachment( $attachment );
473
- $watermark->text = $this->resolver->resolve( $watermark->text );
474
- }
475
-
476
- $meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
477
-
478
- $filepath = get_attached_file( $attachment_id );
479
- $sizes = $meta['sizes'];
480
- $baename = wp_basename( $meta['file'] );
481
-
482
- $sizes['full'] = [
483
- 'file' => $meta['file'],
484
- 'mime-type' => $attachment->post_mime_type,
485
- ];
486
-
487
- if ( ! array_key_exists( $size, $sizes ) ) {
488
- return false;
489
- }
490
-
491
- $image = $sizes[ $size ];
492
- $image_file = str_replace( $baename, wp_basename( $image['file'] ), $filepath );
493
-
494
- $this->processor->set_file( $image_file );
495
-
496
- $result = $this->processor->print_preview( $watermark, $format );
497
-
498
- if ( ! is_wp_error( $result ) ) {
499
- exit;
500
- }
501
-
502
- }
503
-
504
- /**
505
- * Adds attachment version to the URL
506
- *
507
- * @param string $url Attachment url.
508
- * @param integer $attachment_id Attachment ID.
509
- * @return string
510
- */
511
- public function add_attachment_version( $url, $attachment_id ) {
512
-
513
- $version = get_post_meta( $attachment_id, '_ew_attachment_version', true );
514
-
515
- if ( ! $version ) {
516
- return $url;
517
- }
518
-
519
- return $url . '?v=' . $version;
520
-
521
- }
522
- }
1
+ <?php
2
+ /**
3
+ * Handler class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Watermark;
9
+
10
+ use EasyWatermark\AttachmentProcessor;
11
+ use EasyWatermark\AttachmentProcessor\Manager as ProcessorManager;
12
+ use EasyWatermark\Backup\BackupperInterface;
13
+ use EasyWatermark\Backup\Manager as BackupManager;
14
+ use EasyWatermark\Settings\Settings;
15
+ use EasyWatermark\Helpers\Image as ImageHelper;
16
+ use EasyWatermark\Metaboxes\Attachment\Watermarks;
17
+ use EasyWatermark\Placeholders\Resolver;
18
+ use WP_Error;
19
+
20
+ /**
21
+ * Handler class
22
+ */
23
+ class Handler {
24
+
25
+ /**
26
+ * If set to true, watermarks will not be applied.
27
+ *
28
+ * @var boolean
29
+ */
30
+ private $lock = false;
31
+
32
+ /**
33
+ * AttachmentProcessor instance
34
+ *
35
+ * @var AttachmentProcessor
36
+ */
37
+ private $processor;
38
+
39
+ /**
40
+ * Backupper instance
41
+ *
42
+ * @var Backupper
43
+ */
44
+ private $backupper;
45
+
46
+ /**
47
+ * Placeholders Resolver instance
48
+ *
49
+ * @var Resolver
50
+ */
51
+ private $resolver;
52
+
53
+ /**
54
+ * Settings instance
55
+ *
56
+ * @var Settings
57
+ */
58
+ private $settings;
59
+
60
+ /**
61
+ * Temporarily stored meta for newly uploaded attachment
62
+ *
63
+ * @var Settings
64
+ */
65
+ private $tmp_meta;
66
+
67
+ /**
68
+ * Constructor
69
+ */
70
+ public function __construct() {
71
+
72
+ new Ajax( $this );
73
+ new Hooks( $this );
74
+
75
+ $this->settings = Settings::get();
76
+
77
+ $backup = $this->settings->get_setting( 'backup/backup' );
78
+ $backupper = $this->settings->get_setting( 'backup/backupper' );
79
+
80
+ if ( false === $backup || ! $backupper ) {
81
+ // If backup is not enabled load local backuper for temporary backups.
82
+ $backupper = 'local';
83
+ }
84
+
85
+ $this->backupper = BackupManager::get()->get_object( $backupper );
86
+ $this->processor = ProcessorManager::get()->get_object( 'gd' );
87
+ $this->resolver = Resolver::get();
88
+
89
+ $this->processor->set_param( 'jpeg_quality', $this->settings->get_setting( 'general/jpeg_quality' ) );
90
+
91
+ }
92
+
93
+ /**
94
+ * Returns array of all published watermarks
95
+ *
96
+ * @return array
97
+ */
98
+ public function get_watermarks() {
99
+
100
+ $posts = get_posts( [
101
+ 'post_type' => 'watermark',
102
+ 'post_status' => 'publish',
103
+ 'posts_per_page' => -1,
104
+ ] );
105
+
106
+ $watermarks = [];
107
+
108
+ foreach ( $posts as $post ) {
109
+ $watermarks[] = Watermark::get( $post );
110
+ }
111
+
112
+ return $watermarks;
113
+
114
+ }
115
+
116
+ /**
117
+ * Returns available watermark types
118
+ *
119
+ * @return array
120
+ */
121
+ public function get_watermark_types() {
122
+
123
+ global $post;
124
+
125
+ $types = [
126
+ 'text' => [
127
+ 'label' => __( 'Text', 'easy-watermark' ),
128
+ 'available' => true,
129
+ ],
130
+ 'image' => [
131
+ 'label' => __( 'Image', 'easy-watermark' ),
132
+ 'available' => true,
133
+ ],
134
+ ];
135
+
136
+ $types = apply_filters( 'easy-watermark/watermark-types', $types );
137
+
138
+ $watermarks = $this->get_watermarks();
139
+
140
+ foreach ( $watermarks as $watermark ) {
141
+ if ( $post && $watermark->ID === $post->ID ) {
142
+ continue;
143
+ }
144
+
145
+ if ( array_key_exists( $watermark->type, $types ) ) {
146
+ $types[ $watermark->type ]['available'] = false;
147
+ }
148
+ }
149
+
150
+ return $types;
151
+
152
+ }
153
+
154
+ /**
155
+ * Applies single watermark
156
+ *
157
+ * @param integer $attachment_id Attachment id.
158
+ * @param integer $watermark_id Watermark id.
159
+ * @return boolean|WP_Error
160
+ */
161
+ public function apply_single_watermark( $attachment_id, $watermark_id ) {
162
+
163
+ if ( true === $this->lock ) {
164
+ return true;
165
+ }
166
+
167
+ $watermark = Watermark::get( $watermark_id );
168
+
169
+ if ( 'publish' !== $watermark->post_status ) {
170
+ return false;
171
+ }
172
+
173
+ return $this->apply_watermarks( $attachment_id, [ $watermark ] );
174
+
175
+ }
176
+
177
+ /**
178
+ * Applies single watermark
179
+ *
180
+ * @param integer $attachment_id Attachment id.
181
+ * @return boolean|WP_Error
182
+ */
183
+ public function apply_all_watermarks( $attachment_id ) {
184
+
185
+ if ( true === $this->lock ) {
186
+ return true;
187
+ }
188
+
189
+ $watermarks = $this->get_watermarks();
190
+
191
+ return $this->apply_watermarks( $attachment_id, $watermarks );
192
+
193
+ }
194
+
195
+ /**
196
+ * Applies single watermark
197
+ *
198
+ * @param integer $attachment_id Attachment ID.
199
+ * @param array $watermarks Array of Watermark objects.
200
+ * @param array $meta Attachment metadata.
201
+ * @return bool|WP_Error
202
+ */
203
+ public function apply_watermarks( $attachment_id, $watermarks, $meta = [] ) {
204
+
205
+ if ( true === $this->lock ) {
206
+ return false;
207
+ }
208
+
209
+ if ( empty( $watermarks ) ) {
210
+ return false;
211
+ }
212
+
213
+ $used_as_watermark = get_post_meta( $attachment_id, '_ew_used_as_watermark', true );
214
+
215
+ if ( $used_as_watermark ) {
216
+ return false;
217
+ }
218
+
219
+ $attachment = get_post( $attachment_id );
220
+ $available_mime_types = ImageHelper::get_available_mime_types();
221
+
222
+ if ( ! array_key_exists( $attachment->post_mime_type, $available_mime_types ) ) {
223
+ return false;
224
+ }
225
+
226
+ $error = new WP_Error();
227
+
228
+ $this->resolver->reset();
229
+ $this->resolver->set_attachment( $attachment );
230
+
231
+ $applied_watermarks = get_post_meta( $attachment_id, '_ew_applied_watermarks', true );
232
+
233
+ if ( ! is_array( $applied_watermarks ) ) {
234
+ $applied_watermarks = [];
235
+ }
236
+
237
+ $watermarks = array_filter( $watermarks, function( $watermark ) use ( $applied_watermarks ) {
238
+ return ! array_key_exists( $watermark->ID, $applied_watermarks );
239
+ } );
240
+
241
+ if ( empty( $meta ) ) {
242
+ $meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
243
+ }
244
+
245
+ if ( ! $meta ) {
246
+ $error->add( 'empty_metadata', __( 'You try to watermark an item that doesn\'t exist. Please refresh the page and try again.', 'easy-watermark' ) );
247
+
248
+ return $error;
249
+ }
250
+
251
+ $filepath = get_attached_file( $attachment_id );
252
+ $sizes = $meta['sizes'];
253
+ $baename = wp_basename( $meta['file'] );
254
+
255
+ $sizes['full'] = [
256
+ 'file' => $meta['file'],
257
+ 'mime-type' => $attachment->post_mime_type,
258
+ ];
259
+
260
+ $this->do_backup( $attachment_id );
261
+
262
+ foreach ( $sizes as $size => $image ) {
263
+ $apply = false;
264
+
265
+ foreach ( $watermarks as $watermark ) {
266
+ if ( in_array( $size, $watermark->image_sizes, true ) ) {
267
+ $apply = true;
268
+
269
+ if ( 'text' === $watermark->type ) {
270
+ $watermark->text = $this->resolver->resolve( $watermark->text );
271
+ }
272
+
273
+ $this->processor->add_watermark( $watermark );
274
+
275
+ if ( ! array_key_exists( $watermark->ID, $applied_watermarks ) ) {
276
+ $applied_watermarks[ $watermark->ID ] = $watermark->post_title;
277
+ }
278
+ }
279
+ }
280
+
281
+ if ( true === $apply ) {
282
+ $image_file = str_replace( $baename, wp_basename( $image['file'] ), $filepath );
283
+
284
+ $this->processor
285
+ ->set_file( $image_file )
286
+ ->set_param( 'image_type', $image['mime-type'] );
287
+
288
+ $results = $this->processor->process();
289
+
290
+ $this->processor->clean();
291
+
292
+ foreach ( $results as $watermark_id => $result ) {
293
+ if ( is_wp_error( $result ) ) {
294
+ /* translators: watermark name, image size, original error message. */
295
+ $error->add( 'watermark_error', sprintf( __( 'Watermark "%1$s" couldn\'t be applied for "%2$s" image size: %3$s', 'easy-watermark' ), Watermark::get( $watermark_id )->post_title, $size, $result->get_error_message() ) );
296
+ }
297
+ }
298
+ }
299
+ }
300
+
301
+ $error_messages = $error->get_error_messages();
302
+ $has_error = ! empty( $error_messages );
303
+ if ( false === $this->settings->get_setting( 'backup/backup' ) || true === $has_error ) {
304
+ $this->clean_backup( $attachment_id );
305
+ }
306
+
307
+ if ( empty( $error_messages ) ) {
308
+ update_post_meta( $attachment_id, '_ew_applied_watermarks', $applied_watermarks );
309
+ update_post_meta( $attachment_id, '_ew_attachment_version', time() );
310
+
311
+ return true;
312
+ }
313
+
314
+ $this->restore_backup( $attachment_id, $meta );
315
+
316
+ return $error;
317
+
318
+ }
319
+
320
+ /**
321
+ * Performs attachment backup
322
+ *
323
+ * @param integer $attachment_id Attachment ID.
324
+ * @return bool|WP_Error
325
+ */
326
+ public function do_backup( $attachment_id ) {
327
+
328
+ if ( ! $this->backupper instanceof BackupperInterface ) {
329
+ return false;
330
+ }
331
+
332
+ $has_backup = get_post_meta( $attachment_id, '_ew_has_backup', true );
333
+
334
+ if ( '1' === $has_backup ) {
335
+ return false;
336
+ }
337
+
338
+ $result = $this->backupper->backup( $attachment_id );
339
+
340
+ if ( is_wp_error( $result ) ) {
341
+ return $result;
342
+ }
343
+
344
+ update_post_meta( $attachment_id, '_ew_has_backup', true );
345
+
346
+ return true;
347
+
348
+ }
349
+
350
+ /**
351
+ * Restores attachment backup
352
+ *
353
+ * @param integer $attachment_id Attachment ID.
354
+ * @param array $old_meta Attachment metadata array.
355
+ * @return true|WP_Error
356
+ */
357
+ public function restore_backup( $attachment_id, $old_meta ) {
358
+
359
+ if ( ! $this->backupper instanceof BackupperInterface ) {
360
+ return;
361
+ }
362
+
363
+ $has_backup = get_post_meta( $attachment_id, '_ew_has_backup', true );
364
+
365
+ if ( '1' !== $has_backup ) {
366
+ return;
367
+ }
368
+
369
+ // Set lock to prevent regenerated thumbnails from being watermarked.
370
+ $this->lock = true;
371
+
372
+ $restored = $this->backupper->restore( $attachment_id );
373
+
374
+ if ( is_wp_error( $restored ) ) {
375
+ return $restored;
376
+ }
377
+
378
+ $current_file = get_attached_file( $attachment_id );
379
+ $filebasename = wp_basename( $current_file );
380
+
381
+ foreach ( $old_meta['sizes'] as $size => $image ) {
382
+ $file = str_replace( $filebasename, wp_basename( $image['file'] ), $current_file );
383
+ file_exists( $file ) && unlink( $file );
384
+ }
385
+
386
+ wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $current_file ) );
387
+
388
+ update_post_meta( $attachment_id, '_ew_attachment_version', time() );
389
+ delete_post_meta( $attachment_id, '_ew_applied_watermarks' );
390
+ delete_post_meta( $attachment_id, '_ew_has_backup' );
391
+
392
+ $this->lock = false;
393
+
394
+ return true;
395
+
396
+ }
397
+
398
+ /**
399
+ * Removes attachment backup
400
+ *
401
+ * @param integer $attachment_id Attachment ID.
402
+ * @return true|WP_Error
403
+ */
404
+ public function clean_backup( $attachment_id ) {
405
+
406
+ if ( ! $this->backupper instanceof BackupperInterface ) {
407
+ return;
408
+ }
409
+
410
+ $result = $this->backupper->clean( $attachment_id );
411
+
412
+ if ( is_wp_error( $result ) ) {
413
+ return $result;
414
+ }
415
+
416
+ delete_post_meta( $attachment_id, '_ew_has_backup' );
417
+
418
+ return true;
419
+
420
+ }
421
+
422
+ /**
423
+ * Prints text preview
424
+ *
425
+ * @param Watermark $watermark Watermark object.
426
+ * @param string $format Preview format (jpg|png).
427
+ * @return void
428
+ */
429
+ public function print_text_preview( $watermark, $format ) {
430
+
431
+ if ( 'text' !== $watermark->type ) {
432
+ return;
433
+ }
434
+
435
+ if ( $watermark->text ) {
436
+ $watermark->text = $this->resolver->resolve( $watermark->text );
437
+ } else {
438
+ $watermark->text = sprintf( '{%s}', _x( 'no_text', 'Placeholder for watermark text preview if no text specified.', 'easy-watermark' ) );
439
+ }
440
+
441
+ $result = $this->processor->print_text_preview( $watermark, $format );
442
+
443
+ if ( ! is_wp_error( $result ) ) {
444
+ exit;
445
+ }
446
+
447
+ }
448
+
449
+ /**
450
+ * Prints watermark preview
451
+ *
452
+ * @param Watermark $watermark Watermark object.
453
+ * @param string $format Preview format (jpg|png).
454
+ * @param string $size Preview image size.
455
+ * @return void
456
+ */
457
+ public function print_preview( $watermark, $format, $size ) {
458
+
459
+ $attachment_id = get_option( '_ew_preview_image_id' );
460
+
461
+ if ( ! $attachment_id ) {
462
+ return;
463
+ }
464
+
465
+ if ( ! in_array( $size, $watermark->image_sizes, true ) ) {
466
+ $watermark = null;
467
+ }
468
+
469
+ $attachment = get_post( $attachment_id );
470
+
471
+ if ( $watermark && 'text' === $watermark->type ) {
472
+ $this->resolver->set_attachment( $attachment );
473
+ $watermark->text = $this->resolver->resolve( $watermark->text );
474
+ }
475
+
476
+ $meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
477
+
478
+ $filepath = get_attached_file( $attachment_id );
479
+ $sizes = $meta['sizes'];
480
+ $baename = wp_basename( $meta['file'] );
481
+
482
+ $sizes['full'] = [
483
+ 'file' => $meta['file'],
484
+ 'mime-type' => $attachment->post_mime_type,
485
+ ];
486
+
487
+ if ( ! array_key_exists( $size, $sizes ) ) {
488
+ return false;
489
+ }
490
+
491
+ $image = $sizes[ $size ];
492
+ $image_file = str_replace( $baename, wp_basename( $image['file'] ), $filepath );
493
+
494
+ $this->processor->set_file( $image_file );
495
+
496
+ $result = $this->processor->print_preview( $watermark, $format );
497
+
498
+ if ( ! is_wp_error( $result ) ) {
499
+ exit;
500
+ }
501
+
502
+ }
503
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/classes/Watermark/Hooks.php CHANGED
@@ -1,188 +1,160 @@
1
- <?php
2
- /**
3
- * Hooks class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Watermark;
9
-
10
- use EasyWatermark\AttachmentProcessor;
11
- use EasyWatermark\Metaboxes\Attachment\Watermarks;
12
- use EasyWatermark\Traits\Hookable;
13
-
14
- /**
15
- * Hooks class
16
- */
17
- class Hooks {
18
-
19
- use Hookable;
20
-
21
- /**
22
- * Watermark Handler instance
23
- *
24
- * @var Handler
25
- */
26
- private $handler;
27
-
28
- /**
29
- * Constructor
30
- *
31
- * @param Handler $handler Handler instance.
32
- */
33
- public function __construct( $handler ) {
34
-
35
- $this->hook();
36
-
37
- $this->handler = $handler;
38
-
39
- }
40
-
41
- /**
42
- * Cleans backup on attachment removal
43
- *
44
- * @action delete_attachment
45
- *
46
- * @param integer $attachment_id Image attachment ID.
47
- * @return void
48
- */
49
- public function delete_attachment( $attachment_id ) {
50
-
51
- $has_backup = get_post_meta( $attachment_id, '_ew_has_backup', true );
52
-
53
- if ( '1' === $has_backup ) {
54
- $this->handler->clean_backup( $attachment_id );
55
- }
56
-
57
- }
58
-
59
- /**
60
- * Adds attachment version to the url
61
- *
62
- * @filter wp_get_attachment_image_src
63
- *
64
- * @param array|false $image Either array with src, width & height, icon src, or false.
65
- * @param integer $attachment_id Image attachment ID.
66
- * @param string|array $size Size of image. Image size or array of width and height values
67
- * (in that order). Default 'thumbnail'.
68
- * @param bool $icon Whether the image should be treated as an icon. Default false.
69
- * @return array|false
70
- */
71
- public function wp_get_attachment_image_src( $image, $attachment_id, $size, $icon ) {
72
-
73
- if ( false === $image ) {
74
- return false;
75
- }
76
-
77
- if ( is_array( $image ) && ! empty( $image ) && is_string( $image[0] ) ) {
78
- $image[0] = $this->handler->add_attachment_version( $image[0], $attachment_id );
79
- } elseif ( is_string( $image ) ) {
80
- $image = $this->handler->add_attachment_version( $image, $attachment_id );
81
- }
82
-
83
- return $image;
84
-
85
- }
86
-
87
- /**
88
- * Applies watermarks after upload
89
- *
90
- * @filter wp_generate_attachment_metadata
91
- *
92
- * @param array $metadata Attachment metadata.
93
- * @param integer $attachment_id Attachment ID.
94
- * @return array
95
- */
96
- public function wp_generate_attachment_metadata( $metadata, $attachment_id ) {
97
-
98
- $auto_watermark = true;
99
-
100
- // phpcs:disable WordPress.Security.NonceVerification.Recommended
101
- if ( isset( $_REQUEST['auto_watermark'] ) ) {
102
- $auto_watermark = filter_var( wp_unslash( $_REQUEST['auto_watermark'] ), FILTER_VALIDATE_BOOLEAN );
103
- }
104
- // phpcs:enable
105
-
106
- if ( ! $auto_watermark ) {
107
- return $metadata;
108
- }
109
-
110
- $all_watermarks = $this->handler->get_watermarks();
111
-
112
- $watermarks = [];
113
-
114
- foreach ( $all_watermarks as $watermark ) {
115
- if ( ! $watermark->auto_add ) {
116
- continue;
117
- }
118
-
119
- if ( ! $watermark->auto_add_all && ! current_user_can( 'apply_watermark' ) ) {
120
- continue;
121
- }
122
-
123
- $mime_type = get_post_mime_type( $attachment_id );
124
-
125
- if ( ! in_array( $mime_type, $watermark->image_types, true ) ) {
126
- continue;
127
- }
128
-
129
- $attachment = get_post( $attachment_id );
130
-
131
- if ( $attachment->post_parent > 0 ) {
132
- $post_type = get_post_type( $attachment->post_parent );
133
- } else {
134
- $post_type = 'unattached';
135
- }
136
-
137
- if ( ! in_array( $post_type, $watermark->post_types, true ) ) {
138
- continue;
139
- }
140
-
141
- $watermarks[] = $watermark;
142
- }
143
-
144
- $this->handler->apply_watermarks( $attachment_id, $watermarks, $metadata );
145
-
146
- return $metadata;
147
-
148
- }
149
-
150
- /**
151
- * Filters the attachment data prepared for JavaScript.
152
- *
153
- * @filter wp_prepare_attachment_for_js
154
- *
155
- * @param array $response Array of prepared attachment data.
156
- * @param WP_Post $attachment Attachment object.
157
- * @param array|false $meta Array of attachment meta data, or false if there is none.
158
- */
159
- public function wp_prepare_attachment_for_js( $response, $attachment, $meta ) {
160
- $response['nonces']['watermark'] = wp_create_nonce( 'watermark' );
161
- $response['usedAsWatermark'] = get_post_meta( $attachment->ID, '_ew_used_as_watermark', true ) ? true : false;
162
- $response['hasBackup'] = get_post_meta( $attachment->ID, '_ew_has_backup', true ) ? true : false;
163
-
164
- return $response;
165
- }
166
-
167
- /**
168
- * Adds bulk actions
169
- *
170
- * @filter bulk_actions-upload
171
- *
172
- * @param array $bulk_actions Bulk actions.
173
- * @return array
174
- */
175
- public function bulk_actions( $bulk_actions ) {
176
- $bulk_actions['watermark'] = __( 'Watermark' );
177
- $bulk_actions['restore'] = __( 'Restore original images' );
178
-
179
- return $bulk_actions;
180
- }
181
-
182
- /**
183
- * Destructor
184
- */
185
- public function __destruct() {
186
- $this->unhook();
187
- }
188
- }
1
+ <?php
2
+ /**
3
+ * Hooks class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Watermark;
9
+
10
+ use EasyWatermark\AttachmentProcessor;
11
+ use EasyWatermark\Metaboxes\Attachment\Watermarks;
12
+ use EasyWatermark\Traits\Hookable;
13
+
14
+ /**
15
+ * Hooks class
16
+ */
17
+ class Hooks {
18
+
19
+ use Hookable;
20
+
21
+ /**
22
+ * Watermark Handler instance
23
+ *
24
+ * @var Handler
25
+ */
26
+ private $handler;
27
+
28
+ /**
29
+ * Constructor
30
+ *
31
+ * @param Handler $handler Handler instance.
32
+ */
33
+ public function __construct( $handler ) {
34
+
35
+ $this->hook();
36
+
37
+ $this->handler = $handler;
38
+
39
+ }
40
+
41
+ /**
42
+ * Cleans backup on attachment removal
43
+ *
44
+ * @action delete_attachment
45
+ *
46
+ * @param integer $attachment_id Image attachment ID.
47
+ * @return void
48
+ */
49
+ public function delete_attachment( $attachment_id ) {
50
+
51
+ $has_backup = get_post_meta( $attachment_id, '_ew_has_backup', true );
52
+
53
+ if ( '1' === $has_backup ) {
54
+ $this->handler->clean_backup( $attachment_id );
55
+ }
56
+
57
+ }
58
+
59
+ /**
60
+ * Applies watermarks after upload
61
+ *
62
+ * @filter wp_generate_attachment_metadata
63
+ *
64
+ * @param array $metadata Attachment metadata.
65
+ * @param integer $attachment_id Attachment ID.
66
+ * @return array
67
+ */
68
+ public function wp_generate_attachment_metadata( $metadata, $attachment_id ) {
69
+
70
+ $auto_watermark = true;
71
+
72
+ // phpcs:disable WordPress.Security.NonceVerification.Recommended
73
+ if ( isset( $_REQUEST['auto_watermark'] ) ) {
74
+ $auto_watermark = filter_var( wp_unslash( $_REQUEST['auto_watermark'] ), FILTER_VALIDATE_BOOLEAN );
75
+ }
76
+ // phpcs:enable
77
+
78
+ if ( ! $auto_watermark ) {
79
+ return $metadata;
80
+ }
81
+
82
+ $all_watermarks = $this->handler->get_watermarks();
83
+
84
+ $watermarks = [];
85
+
86
+ foreach ( $all_watermarks as $watermark ) {
87
+ if ( ! $watermark->auto_add ) {
88
+ continue;
89
+ }
90
+
91
+ if ( ! $watermark->auto_add_all && ! current_user_can( 'apply_watermark' ) ) {
92
+ continue;
93
+ }
94
+
95
+ $mime_type = get_post_mime_type( $attachment_id );
96
+
97
+ if ( ! in_array( $mime_type, $watermark->image_types, true ) ) {
98
+ continue;
99
+ }
100
+
101
+ $attachment = get_post( $attachment_id );
102
+
103
+ if ( $attachment->post_parent > 0 ) {
104
+ $post_type = get_post_type( $attachment->post_parent );
105
+ } else {
106
+ $post_type = 'unattached';
107
+ }
108
+
109
+ if ( ! in_array( $post_type, $watermark->post_types, true ) ) {
110
+ continue;
111
+ }
112
+
113
+ $watermarks[] = $watermark;
114
+ }
115
+
116
+ $this->handler->apply_watermarks( $attachment_id, $watermarks, $metadata );
117
+
118
+ return $metadata;
119
+
120
+ }
121
+
122
+ /**
123
+ * Filters the attachment data prepared for JavaScript.
124
+ *
125
+ * @filter wp_prepare_attachment_for_js
126
+ *
127
+ * @param array $response Array of prepared attachment data.
128
+ * @param WP_Post $attachment Attachment object.
129
+ * @param array|false $meta Array of attachment meta data, or false if there is none.
130
+ */
131
+ public function wp_prepare_attachment_for_js( $response, $attachment, $meta ) {
132
+ $response['nonces']['watermark'] = wp_create_nonce( 'watermark' );
133
+ $response['usedAsWatermark'] = get_post_meta( $attachment->ID, '_ew_used_as_watermark', true ) ? true : false;
134
+ $response['hasBackup'] = get_post_meta( $attachment->ID, '_ew_has_backup', true ) ? true : false;
135
+
136
+ return $response;
137
+ }
138
+
139
+ /**
140
+ * Adds bulk actions
141
+ *
142
+ * @filter bulk_actions-upload
143
+ *
144
+ * @param array $bulk_actions Bulk actions.
145
+ * @return array
146
+ */
147
+ public function bulk_actions( $bulk_actions ) {
148
+ $bulk_actions['watermark'] = __( 'Watermark' );
149
+ $bulk_actions['restore'] = __( 'Restore original images' );
150
+
151
+ return $bulk_actions;
152
+ }
153
+
154
+ /**
155
+ * Destructor
156
+ */
157
+ public function __destruct() {
158
+ $this->unhook();
159
+ }
160
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/classes/Watermark/PostType.php CHANGED
@@ -1,515 +1,515 @@
1
- <?php
2
- /**
3
- * Watermark post type class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Watermark;
9
-
10
- use EasyWatermark\Core\Plugin;
11
- use EasyWatermark\Core\View;
12
- use EasyWatermark\Traits\Hookable;
13
-
14
- /**
15
- * Watermark post type class
16
- */
17
- class PostType {
18
-
19
- use Hookable;
20
-
21
- /**
22
- * Post type
23
- *
24
- * @var string
25
- */
26
- private $post_type = 'watermark';
27
-
28
- /**
29
- * Is watermark untrashed?
30
- *
31
- * @var bool
32
- */
33
- private $untrashed = false;
34
-
35
- /**
36
- * Constructor
37
- */
38
- public function __construct() {
39
- $this->hook();
40
- }
41
-
42
- /**
43
- * Registers custom post type
44
- *
45
- * @action init
46
- * @return void
47
- */
48
- public function register() {
49
-
50
- $labels = [
51
- 'name' => _x( 'Watermarks', 'post type general name', 'easy-watermark' ),
52
- 'singular_name' => _x( 'Watermark', 'post type singular name', 'easy-watermark' ),
53
- 'menu_name' => _x( 'Watermarks', 'admin menu', 'easy-watermark' ),
54
- 'name_admin_bar' => _x( 'Watermark', 'add new on admin bar', 'easy-watermark' ),
55
- 'add_new' => _x( 'Add New', 'Watermark', 'easy-watermark' ),
56
- 'add_new_item' => __( 'Add New Watermark', 'easy-watermark' ),
57
- 'new_item' => __( 'New Watermark', 'easy-watermark' ),
58
- 'edit_item' => __( 'Edit Watermark', 'easy-watermark' ),
59
- 'view_item' => __( 'View Watermark', 'easy-watermark' ),
60
- 'all_items' => __( 'All Watermarks', 'easy-watermark' ),
61
- 'search_items' => __( 'Search Watermarks', 'easy-watermark' ),
62
- 'parent_item_colon' => __( 'Parent Watermarks:', 'easy-watermark' ),
63
- 'not_found' => __( 'No watermarks found.', 'easy-watermark' ),
64
- 'not_found_in_trash' => __( 'No watermarks found in Trash.', 'easy-watermark' ),
65
- ];
66
-
67
- $args = [
68
- 'labels' => $labels,
69
- 'description' => __( 'Watermarks', 'easy-watermark' ),
70
- 'public' => false,
71
- 'show_ui' => true,
72
- 'exclude_from_search' => true,
73
- 'has_archive' => false,
74
- 'hierarchical' => false,
75
- 'menu_icon' => 'dashicons-media-text',
76
- 'menu_position' => null,
77
- 'supports' => [ 'title' ],
78
- 'map_meta_cap' => true,
79
- 'show_in_menu' => false,
80
- 'capabilities' => [
81
- 'edit_post' => 'edit_watermark',
82
- 'edit_posts' => 'edit_watermarks',
83
- 'edit_others_posts' => 'edit_others_watermarks',
84
- 'delete_posts' => 'delete_watermarks',
85
- 'delete_others_posts' => 'delete_others_watermarks',
86
- ],
87
- ];
88
-
89
- register_post_type( $this->post_type, $args );
90
-
91
- }
92
-
93
- /**
94
- * Filters parent file to highlight top level menu item as active
95
- *
96
- * @filter parent_file
97
- *
98
- * @since 1.0.4
99
- * @param string $parent_file Parent file.
100
- * @return string
101
- */
102
- public function parent_file( $parent_file ) {
103
- global $current_screen, $submenu_file;
104
-
105
- if ( $current_screen->post_type === $this->post_type ) {
106
- $parent_file = 'tools.php';
107
- $submenu_file = 'easy-watermark';
108
- }
109
-
110
- return $parent_file;
111
- }
112
-
113
- /**
114
- * Removes temporary params on watermark edit screen
115
- *
116
- * @action current_screen
117
- *
118
- * @return void
119
- */
120
- public function current_screen() {
121
- if ( 'watermark' === get_current_screen()->id ) {
122
- // phpcs:disable WordPress.Security.NonceVerification.Recommended
123
- if ( isset( $_REQUEST['post'] ) && isset( $_REQUEST['action'] ) && 'edit' === $_REQUEST['action'] ) {
124
- delete_post_meta( intval( $_REQUEST['post'] ), '_ew_tmp_params' );
125
- }
126
- // phpcs:enable
127
- }
128
- }
129
-
130
- /**
131
- * Sets watermark update messages
132
- *
133
- * @filter post_updated_messages
134
- * @param array $messages Watermark update messages.
135
- * @return array
136
- */
137
- public function post_updated_messages( $messages ) {
138
- global $post;
139
-
140
- $messages['watermark'] = [
141
- '',
142
- __( 'Watermark updated.', 'easy-watermark' ),
143
- __( 'Custom field updated.', 'easy-watermark' ),
144
- __( 'Custom field deleted.', 'easy-watermark' ),
145
- __( 'Watermark updated.', 'easy-watermark' ),
146
- isset( $_GET['revision'] ) ? sprintf( __( 'Watermark restored to revision from %s', 'easy-watermark' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, //phpcs:ignore
147
- __( 'Watermark saved.', 'easy-watermark' ),
148
- __( 'Watermark saved.', 'easy-watermark' ),
149
- __( 'Watermark submitted.', 'easy-watermark' ),
150
- sprintf(
151
- __( 'Watermark scheduled for: <strong>%1$s</strong>.', 'easy-watermark' ), //phpcs:ignore
152
- date_i18n( __( 'M j, Y @ G:i', 'easy-watermark' ), strtotime( $post->post_date ) )
153
- ),
154
- __( 'Watermark draft updated.', 'easy-watermark' ),
155
- ];
156
-
157
- return $messages;
158
- }
159
-
160
- /**
161
- * Sets watermark bulk update messages
162
- *
163
- * @filter bulk_post_updated_messages
164
- *
165
- * @param array $messages Bulk update messages.
166
- * @param array $counts Counts.
167
- * @return array
168
- */
169
- public function bulk_post_updated_messages( $messages, $counts ) {
170
- global $post;
171
-
172
- $messages['watermark'] = [
173
- /* translators: updated watermarks number */
174
- 'updated' => _n( '%s watermark updated.', '%s watermarks updated.', $counts['updated'], 'easy-watermark' ),
175
- 'locked' => ( 1 === $counts['locked'] ) ? __( '1 watermarkt not updated, somebody is editing it.', 'easy-watermark' ) :
176
- /* translators: not updated watermarks number */
177
- _n( '%s watermark not updated, somebody is editing it.', '%s watermarks not updated, somebody is editing them.', $counts['locked'], 'easy-watermark' ),
178
- /* translators: deleted watermarks number */
179
- 'deleted' => _n( '%s watermark permanently deleted.', '%s watermarks permanently deleted.', $counts['deleted'], 'easy-watermark' ),
180
- /* translators: moved to trash watermarks number */
181
- 'trashed' => _n( '%s watermark moved to the Trash.', '%s watermarks moved to the Trash.', $counts['trashed'], 'easy-watermark' ),
182
- /* translators: restored from trash watermarks number */
183
- 'untrashed' => _n( '%s watermark restored from the Trash.', '%s watermarks restored from the Trash.', $counts['untrashed'], 'easy-watermark' ),
184
- ];
185
-
186
- return $messages;
187
- }
188
-
189
- /**
190
- * Checks if watermark has been untrashed
191
- *
192
- * @action untrashed_post
193
- *
194
- * @param integer $post_id Post ID.
195
- * @return void
196
- */
197
- public function untrashed_post( $post_id ) {
198
- global $post;
199
-
200
- if ( 'watermark' === $post->post_type ) {
201
- $this->untrashed = true;
202
- }
203
- }
204
-
205
- /**
206
- * Removes watermark ID from attachment meta
207
- *
208
- * @action delete_post
209
- *
210
- * @param integer $post_id Post ID.
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 );
218
-
219
- if ( $watermark->attachment_id ) {
220
- $this->remove_watrmark_from_meta( $watermark->attachment_id, $post_id );
221
- }
222
- }
223
- }
224
-
225
- /**
226
- * Changes redirect location after watermark restoration from trash
227
- *
228
- * @action wp_redirect
229
- *
230
- * @param string $location Location.
231
- * @return string
232
- */
233
- public function redirect( $location ) {
234
- global $post;
235
-
236
- if ( $post && 'watermark' === $post->post_type ) {
237
- if ( false !== strpos( $location, 'untrashed=1' ) && ! $this->untrashed ) {
238
- $location = add_query_arg( [
239
- 'ew-limited' => '1',
240
- ], remove_query_arg( 'untrashed', $location ) );
241
- }
242
- }
243
-
244
- return $location;
245
- }
246
-
247
- /**
248
- * Prints admin notices
249
- *
250
- * @action admin_notices
251
- *
252
- * @return void
253
- */
254
- public function admin_notices() {
255
- global $post;
256
-
257
- if ( 'watermark' === get_current_screen()->id && 2 <= $this->get_watermarks_count() && 'publish' !== $post->post_status ) {
258
- echo new View( 'notices/watermarks-number-exceeded-error' ); // phpcs:ignore
259
- }
260
-
261
- if ( isset( $_REQUEST['ew-limited'] ) && $_REQUEST['ew-limited'] ) { // phpcs:ignore
262
-
263
- echo new View( 'notices/untrash-error' ); // phpcs:ignore
264
-
265
- $_SERVER['REQUEST_URI'] = remove_query_arg( [ 'ew-limited' ], $_SERVER['REQUEST_URI'] ); // phpcs:ignore
266
- }
267
- }
268
-
269
- /**
270
- * Filters row actions for watermark post type
271
- *
272
- * @filter post_row_actions
273
- *
274
- * @param array $actions Row actions.
275
- * @param WP_Post $post Post object.
276
- * @return array
277
- */
278
- public function post_row_actions( $actions, $post ) {
279
- if ( 'watermark' === $post->post_type ) {
280
- if ( 2 <= $this->get_watermarks_count() && isset( $actions['untrash'] ) ) {
281
- unset( $actions['untrash'] );
282
- }
283
-
284
- $watermark_types = Plugin::get()->get_watermark_handler()->get_watermark_types();
285
- $watermark = Watermark::get( $post );
286
-
287
- if ( array_key_exists( $watermark->type, $watermark_types ) && false === $watermark_types[ $watermark->type ]['available'] ) {
288
- unset( $actions['untrash'] );
289
- }
290
- }
291
-
292
- return $actions;
293
- }
294
-
295
- /**
296
- * Filters watermark bulk actions
297
- *
298
- * @filter bulk_actions-edit-watermark
299
- *
300
- * @param array $actions Bulk actions.
301
- * @return array
302
- */
303
- public function bulk_actions( $actions ) {
304
- if ( isset( $actions['untrash'] ) ) {
305
- unset( $actions['untrash'] );
306
- }
307
-
308
- return $actions;
309
- }
310
-
311
- /**
312
- * Returns watermarks count
313
- *
314
- * @return object
315
- */
316
- public function get_watermarks_count() {
317
- return wp_count_posts( 'watermark' )->publish;
318
- }
319
-
320
- /**
321
- * Hides screen options on watermark editing screen
322
- *
323
- * @filter screen_options_show_screen
324
- *
325
- * @param bool $show_screen Whether to show Screen Options tab.
326
- * @param object $screen Current WP_Screen instance.
327
- * @return bool
328
- */
329
- public function screen_options_show_screen( $show_screen, $screen ) {
330
- if ( 'watermark' === $screen->id ) {
331
- return false;
332
- }
333
-
334
- return $show_screen;
335
- }
336
-
337
- /**
338
- * Adds hidden field for attachment id storage
339
- *
340
- * @action edit_form_top
341
- *
342
- * @param WP_Post $post Post object.
343
- * @return void
344
- */
345
- public function edit_form_top( $post ) {
346
- if ( 'watermark' === get_current_screen()->id && ( 2 > $this->get_watermarks_count() || 'publish' === $post->post_status ) ) {
347
- $watermark = Watermark::get( $post );
348
-
349
- // phpcs:disable
350
- echo new View( 'edit-screen/attachment-id-field', [
351
- 'attachment_id' => $watermark->attachment_id,
352
- ] );
353
- // phpcs:enable
354
- }
355
- }
356
-
357
- /**
358
- * Adds watermark type selector
359
- *
360
- * @action edit_form_after_title
361
- *
362
- * @param WP_Post $post Post object.
363
- * @return void
364
- */
365
- public function edit_form_after_title( $post ) {
366
- if ( 'watermark' === get_current_screen()->id && ( 2 > $this->get_watermarks_count() || 'publish' === $post->post_status ) ) {
367
- $watermark = Watermark::get( $post );
368
- $watermark_handler = Plugin::get()->get_watermark_handler();
369
-
370
- // phpcs:disable
371
- echo new View( 'edit-screen/watermark-type-selector', [
372
- 'watermark_types' => $watermark_handler->get_watermark_types(),
373
- 'selected_type' => $watermark->type,
374
- ] );
375
- // phpcs:enable
376
- }
377
- }
378
-
379
- /**
380
- * Watermark edit screen columns setup
381
- *
382
- * @filter get_user_option_screen_layout_watermark
383
- *
384
- * @param integer $columns User setup columns.
385
- * @return integer
386
- */
387
- public function setup_columns( $columns ) {
388
- global $post;
389
-
390
- if ( 2 <= $this->get_watermarks_count() && 'publish' !== $post->post_status ) {
391
- // Force one column.
392
- return 1;
393
- }
394
-
395
- return $columns;
396
- }
397
-
398
- /**
399
- * Watermark edit screen title support setup
400
- *
401
- * @action edit_form_top
402
- *
403
- * @return void
404
- */
405
- public function change_title_support() {
406
- global $_wp_post_type_features, $post;
407
-
408
- if ( 'publish' === $post->post_status ) {
409
- return;
410
- }
411
-
412
- if ( 2 <= $this->get_watermarks_count() && isset( $_wp_post_type_features['watermark']['title'] ) ) {
413
- unset( $_wp_post_type_features['watermark']['title'] );
414
- }
415
- }
416
-
417
- /**
418
- * Filters whether a post untrashing should take place.
419
- *
420
- * @filter pre_untrash_post
421
- *
422
- * @param null $untrash Whether to go forward with untrashing.
423
- * @param WP_Post $post Post object.
424
- * @return bool
425
- */
426
- public function pre_untrash_post( $untrash, $post ) {
427
-
428
- if ( 'watermark' === $post->post_type && 2 <= $this->get_watermarks_count() ) {
429
- return true;
430
- }
431
-
432
- return $untrash;
433
-
434
- }
435
-
436
- /**
437
- * Stores serialized watermark data in post content
438
- *
439
- * @filter wp_insert_post_data
440
- *
441
- * @param array $data An array of slashed post data.
442
- * @param array $postarr An array of sanitized, but otherwise unmodified post data.
443
- * @return array
444
- */
445
- public function wp_insert_post_data( $data, $postarr ) {
446
-
447
- if ( 'watermark' === $data['post_type'] && isset( $postarr['watermark'] ) ) {
448
- $watermark_data = Watermark::parse_params( $postarr['watermark'] );
449
-
450
- $data['post_content'] = wp_json_encode( $watermark_data, JSON_UNESCAPED_UNICODE );
451
-
452
- $old_attachment_id = isset( $postarr['ew-previous-attachment-id'] ) ? $postarr['ew-previous-attachment-id'] : false;
453
- $new_attachment_id = $postarr['watermark']['attachment_id'];
454
-
455
- if ( $old_attachment_id !== $new_attachment_id ) {
456
- if ( is_numeric( $old_attachment_id ) ) {
457
- $this->remove_watrmark_from_meta( $old_attachment_id, $postarr['ID'] );
458
- }
459
-
460
- $this->add_watrmark_to_meta( $new_attachment_id, $postarr['ID'] );
461
- }
462
-
463
- delete_post_meta( $postarr['ID'], '_ew_tmp_params' );
464
- }
465
-
466
- return $data;
467
-
468
- }
469
-
470
- /**
471
- * Add watermark to attachment meta
472
- *
473
- * @param integer $attachment_id Attachment ID.
474
- * @param integer $watermark_id Watermark ID.
475
- * @return void
476
- */
477
- private function add_watrmark_to_meta( $attachment_id, $watermark_id ) {
478
-
479
- $meta = get_post_meta( $attachment_id, '_ew_used_as_watermark', true );
480
-
481
- if ( ! is_array( $meta ) ) {
482
- $meta = [];
483
- }
484
-
485
- if ( ! in_array( $watermark_id, $meta, true ) ) {
486
- $meta[] = $watermark_id;
487
- update_post_meta( $attachment_id, '_ew_used_as_watermark', $meta );
488
- }
489
-
490
- }
491
-
492
- /**
493
- * Remove watermark to attachment meta
494
- *
495
- * @param integer $attachment_id Attachment ID.
496
- * @param integer $watermark_id Watermark ID.
497
- * @return void
498
- */
499
- private function remove_watrmark_from_meta( $attachment_id, $watermark_id ) {
500
-
501
- $meta = get_post_meta( $attachment_id, '_ew_used_as_watermark', true );
502
-
503
- if ( is_array( $meta ) && in_array( $watermark_id, $meta, true ) ) {
504
- $key = array_search( $watermark_id, $meta, true );
505
- unset( $meta[ $key ] );
506
-
507
- if ( empty( $meta ) ) {
508
- delete_post_meta( $attachment_id, '_ew_used_as_watermark' );
509
- } else {
510
- update_post_meta( $attachment_id, '_ew_used_as_watermark', $meta );
511
- }
512
- }
513
-
514
- }
515
- }
1
+ <?php
2
+ /**
3
+ * Watermark post type class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Watermark;
9
+
10
+ use EasyWatermark\Core\Plugin;
11
+ use EasyWatermark\Core\View;
12
+ use EasyWatermark\Traits\Hookable;
13
+
14
+ /**
15
+ * Watermark post type class
16
+ */
17
+ class PostType {
18
+
19
+ use Hookable;
20
+
21
+ /**
22
+ * Post type
23
+ *
24
+ * @var string
25
+ */
26
+ private $post_type = 'watermark';
27
+
28
+ /**
29
+ * Is watermark untrashed?
30
+ *
31
+ * @var bool
32
+ */
33
+ private $untrashed = false;
34
+
35
+ /**
36
+ * Constructor
37
+ */
38
+ public function __construct() {
39
+ $this->hook();
40
+ }
41
+
42
+ /**
43
+ * Registers custom post type
44
+ *
45
+ * @action init
46
+ * @return void
47
+ */
48
+ public function register() {
49
+
50
+ $labels = [
51
+ 'name' => _x( 'Watermarks', 'post type general name', 'easy-watermark' ),
52
+ 'singular_name' => _x( 'Watermark', 'post type singular name', 'easy-watermark' ),
53
+ 'menu_name' => _x( 'Watermarks', 'admin menu', 'easy-watermark' ),
54
+ 'name_admin_bar' => _x( 'Watermark', 'add new on admin bar', 'easy-watermark' ),
55
+ 'add_new' => _x( 'Add New', 'Watermark', 'easy-watermark' ),
56
+ 'add_new_item' => __( 'Add New Watermark', 'easy-watermark' ),
57
+ 'new_item' => __( 'New Watermark', 'easy-watermark' ),
58
+ 'edit_item' => __( 'Edit Watermark', 'easy-watermark' ),
59
+ 'view_item' => __( 'View Watermark', 'easy-watermark' ),
60
+ 'all_items' => __( 'All Watermarks', 'easy-watermark' ),
61
+ 'search_items' => __( 'Search Watermarks', 'easy-watermark' ),
62
+ 'parent_item_colon' => __( 'Parent Watermarks:', 'easy-watermark' ),
63
+ 'not_found' => __( 'No watermarks found.', 'easy-watermark' ),
64
+ 'not_found_in_trash' => __( 'No watermarks found in Trash.', 'easy-watermark' ),
65
+ ];
66
+
67
+ $args = [
68
+ 'labels' => $labels,
69
+ 'description' => __( 'Watermarks', 'easy-watermark' ),
70
+ 'public' => false,
71
+ 'show_ui' => true,
72
+ 'exclude_from_search' => true,
73
+ 'has_archive' => false,
74
+ 'hierarchical' => false,
75
+ 'menu_icon' => 'dashicons-media-text',
76
+ 'menu_position' => null,
77
+ 'supports' => [ 'title' ],
78
+ 'map_meta_cap' => true,
79
+ 'show_in_menu' => false,
80
+ 'capabilities' => [
81
+ 'edit_post' => 'edit_watermark',
82
+ 'edit_posts' => 'edit_watermarks',
83
+ 'edit_others_posts' => 'edit_others_watermarks',
84
+ 'delete_posts' => 'delete_watermarks',
85
+ 'delete_others_posts' => 'delete_others_watermarks',
86
+ ],
87
+ ];
88
+
89
+ register_post_type( $this->post_type, $args );
90
+
91
+ }
92
+
93
+ /**
94
+ * Filters parent file to highlight top level menu item as active
95
+ *
96
+ * @filter parent_file
97
+ *
98
+ * @since 1.0.4
99
+ * @param string $parent_file Parent file.
100
+ * @return string
101
+ */
102
+ public function parent_file( $parent_file ) {
103
+ global $current_screen, $submenu_file;
104
+
105
+ if ( $current_screen->post_type === $this->post_type ) {
106
+ $parent_file = 'tools.php';
107
+ $submenu_file = 'easy-watermark';
108
+ }
109
+
110
+ return $parent_file;
111
+ }
112
+
113
+ /**
114
+ * Removes temporary params on watermark edit screen
115
+ *
116
+ * @action current_screen
117
+ *
118
+ * @return void
119
+ */
120
+ public function current_screen() {
121
+ if ( 'watermark' === get_current_screen()->id ) {
122
+ // phpcs:disable WordPress.Security.NonceVerification.Recommended
123
+ if ( isset( $_REQUEST['post'] ) && isset( $_REQUEST['action'] ) && 'edit' === $_REQUEST['action'] ) {
124
+ delete_post_meta( intval( $_REQUEST['post'] ), '_ew_tmp_params' );
125
+ }
126
+ // phpcs:enable
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Sets watermark update messages
132
+ *
133
+ * @filter post_updated_messages
134
+ * @param array $messages Watermark update messages.
135
+ * @return array
136
+ */
137
+ public function post_updated_messages( $messages ) {
138
+ global $post;
139
+
140
+ $messages['watermark'] = [
141
+ '',
142
+ __( 'Watermark updated.', 'easy-watermark' ),
143
+ __( 'Custom field updated.', 'easy-watermark' ),
144
+ __( 'Custom field deleted.', 'easy-watermark' ),
145
+ __( 'Watermark updated.', 'easy-watermark' ),
146
+ isset( $_GET['revision'] ) ? sprintf( __( 'Watermark restored to revision from %s', 'easy-watermark' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, //phpcs:ignore
147
+ __( 'Watermark saved.', 'easy-watermark' ),
148
+ __( 'Watermark saved.', 'easy-watermark' ),
149
+ __( 'Watermark submitted.', 'easy-watermark' ),
150
+ sprintf(
151
+ __( 'Watermark scheduled for: <strong>%1$s</strong>.', 'easy-watermark' ), //phpcs:ignore
152
+ date_i18n( __( 'M j, Y @ G:i', 'easy-watermark' ), strtotime( $post->post_date ) )
153
+ ),
154
+ __( 'Watermark draft updated.', 'easy-watermark' ),
155
+ ];
156
+
157
+ return $messages;
158
+ }
159
+
160
+ /**
161
+ * Sets watermark bulk update messages
162
+ *
163
+ * @filter bulk_post_updated_messages
164
+ *
165
+ * @param array $messages Bulk update messages.
166
+ * @param array $counts Counts.
167
+ * @return array
168
+ */
169
+ public function bulk_post_updated_messages( $messages, $counts ) {
170
+ global $post;
171
+
172
+ $messages['watermark'] = [
173
+ /* translators: updated watermarks number */
174
+ 'updated' => _n( '%s watermark updated.', '%s watermarks updated.', $counts['updated'], 'easy-watermark' ),
175
+ 'locked' => ( 1 === $counts['locked'] ) ? __( '1 watermarkt not updated, somebody is editing it.', 'easy-watermark' ) :
176
+ /* translators: not updated watermarks number */
177
+ _n( '%s watermark not updated, somebody is editing it.', '%s watermarks not updated, somebody is editing them.', $counts['locked'], 'easy-watermark' ),
178
+ /* translators: deleted watermarks number */
179
+ 'deleted' => _n( '%s watermark permanently deleted.', '%s watermarks permanently deleted.', $counts['deleted'], 'easy-watermark' ),
180
+ /* translators: moved to trash watermarks number */
181
+ 'trashed' => _n( '%s watermark moved to the Trash.', '%s watermarks moved to the Trash.', $counts['trashed'], 'easy-watermark' ),
182
+ /* translators: restored from trash watermarks number */
183
+ 'untrashed' => _n( '%s watermark restored from the Trash.', '%s watermarks restored from the Trash.', $counts['untrashed'], 'easy-watermark' ),
184
+ ];
185
+
186
+ return $messages;
187
+ }
188
+
189
+ /**
190
+ * Checks if watermark has been untrashed
191
+ *
192
+ * @action untrashed_post
193
+ *
194
+ * @param integer $post_id Post ID.
195
+ * @return void
196
+ */
197
+ public function untrashed_post( $post_id ) {
198
+ global $post;
199
+
200
+ if ( 'watermark' === $post->post_type ) {
201
+ $this->untrashed = true;
202
+ }
203
+ }
204
+
205
+ /**
206
+ * Removes watermark ID from attachment meta
207
+ *
208
+ * @action delete_post
209
+ *
210
+ * @param integer $post_id Post ID.
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 );
218
+
219
+ if ( $watermark->attachment_id ) {
220
+ $this->remove_watrmark_from_meta( $watermark->attachment_id, $post_id );
221
+ }
222
+ }
223
+ }
224
+
225
+ /**
226
+ * Changes redirect location after watermark restoration from trash
227
+ *
228
+ * @action wp_redirect
229
+ *
230
+ * @param string $location Location.
231
+ * @return string
232
+ */
233
+ public function redirect( $location ) {
234
+ global $post;
235
+
236
+ if ( $post && 'watermark' === $post->post_type ) {
237
+ if ( false !== strpos( $location, 'untrashed=1' ) && ! $this->untrashed ) {
238
+ $location = add_query_arg( [
239
+ 'ew-limited' => '1',
240
+ ], remove_query_arg( 'untrashed', $location ) );
241
+ }
242
+ }
243
+
244
+ return $location;
245
+ }
246
+
247
+ /**
248
+ * Prints admin notices
249
+ *
250
+ * @action admin_notices
251
+ *
252
+ * @return void
253
+ */
254
+ public function admin_notices() {
255
+ global $post;
256
+
257
+ if ( 'watermark' === get_current_screen()->id && 2 <= $this->get_watermarks_count() && 'publish' !== $post->post_status ) {
258
+ echo new View( 'notices/watermarks-number-exceeded-error' ); // phpcs:ignore
259
+ }
260
+
261
+ if ( isset( $_REQUEST['ew-limited'] ) && $_REQUEST['ew-limited'] ) { // phpcs:ignore
262
+
263
+ echo new View( 'notices/untrash-error' ); // phpcs:ignore
264
+
265
+ $_SERVER['REQUEST_URI'] = remove_query_arg( [ 'ew-limited' ], $_SERVER['REQUEST_URI'] ); // phpcs:ignore
266
+ }
267
+ }
268
+
269
+ /**
270
+ * Filters row actions for watermark post type
271
+ *
272
+ * @filter post_row_actions
273
+ *
274
+ * @param array $actions Row actions.
275
+ * @param WP_Post $post Post object.
276
+ * @return array
277
+ */
278
+ public function post_row_actions( $actions, $post ) {
279
+ if ( 'watermark' === $post->post_type ) {
280
+ if ( 2 <= $this->get_watermarks_count() && isset( $actions['untrash'] ) ) {
281
+ unset( $actions['untrash'] );
282
+ }
283
+
284
+ $watermark_types = Plugin::get()->get_watermark_handler()->get_watermark_types();
285
+ $watermark = Watermark::get( $post );
286
+
287
+ if ( array_key_exists( $watermark->type, $watermark_types ) && false === $watermark_types[ $watermark->type ]['available'] ) {
288
+ unset( $actions['untrash'] );
289
+ }
290
+ }
291
+
292
+ return $actions;
293
+ }
294
+
295
+ /**
296
+ * Filters watermark bulk actions
297
+ *
298
+ * @filter bulk_actions-edit-watermark
299
+ *
300
+ * @param array $actions Bulk actions.
301
+ * @return array
302
+ */
303
+ public function bulk_actions( $actions ) {
304
+ if ( isset( $actions['untrash'] ) ) {
305
+ unset( $actions['untrash'] );
306
+ }
307
+
308
+ return $actions;
309
+ }
310
+
311
+ /**
312
+ * Returns watermarks count
313
+ *
314
+ * @return object
315
+ */
316
+ public function get_watermarks_count() {
317
+ return wp_count_posts( 'watermark' )->publish;
318
+ }
319
+
320
+ /**
321
+ * Hides screen options on watermark editing screen
322
+ *
323
+ * @filter screen_options_show_screen
324
+ *
325
+ * @param bool $show_screen Whether to show Screen Options tab.
326
+ * @param object $screen Current WP_Screen instance.
327
+ * @return bool
328
+ */
329
+ public function screen_options_show_screen( $show_screen, $screen ) {
330
+ if ( 'watermark' === $screen->id ) {
331
+ return false;
332
+ }
333
+
334
+ return $show_screen;
335
+ }
336
+
337
+ /**
338
+ * Adds hidden field for attachment id storage
339
+ *
340
+ * @action edit_form_top
341
+ *
342
+ * @param WP_Post $post Post object.
343
+ * @return void
344
+ */
345
+ public function edit_form_top( $post ) {
346
+ if ( 'watermark' === get_current_screen()->id && ( 2 > $this->get_watermarks_count() || 'publish' === $post->post_status ) ) {
347
+ $watermark = Watermark::get( $post );
348
+
349
+ // phpcs:disable
350
+ echo new View( 'edit-screen/attachment-id-field', [
351
+ 'attachment_id' => $watermark->attachment_id,
352
+ ] );
353
+ // phpcs:enable
354
+ }
355
+ }
356
+
357
+ /**
358
+ * Adds watermark type selector
359
+ *
360
+ * @action edit_form_after_title
361
+ *
362
+ * @param WP_Post $post Post object.
363
+ * @return void
364
+ */
365
+ public function edit_form_after_title( $post ) {
366
+ if ( 'watermark' === get_current_screen()->id && ( 2 > $this->get_watermarks_count() || 'publish' === $post->post_status ) ) {
367
+ $watermark = Watermark::get( $post );
368
+ $watermark_handler = Plugin::get()->get_watermark_handler();
369
+
370
+ // phpcs:disable
371
+ echo new View( 'edit-screen/watermark-type-selector', [
372
+ 'watermark_types' => $watermark_handler->get_watermark_types(),
373
+ 'selected_type' => $watermark->type,
374
+ ] );
375
+ // phpcs:enable
376
+ }
377
+ }
378
+
379
+ /**
380
+ * Watermark edit screen columns setup
381
+ *
382
+ * @filter get_user_option_screen_layout_watermark
383
+ *
384
+ * @param integer $columns User setup columns.
385
+ * @return integer
386
+ */
387
+ public function setup_columns( $columns ) {
388
+ global $post;
389
+
390
+ if ( 2 <= $this->get_watermarks_count() && 'publish' !== $post->post_status ) {
391
+ // Force one column.
392
+ return 1;
393
+ }
394
+
395
+ return $columns;
396
+ }
397
+
398
+ /**
399
+ * Watermark edit screen title support setup
400
+ *
401
+ * @action edit_form_top
402
+ *
403
+ * @return void
404
+ */
405
+ public function change_title_support() {
406
+ global $_wp_post_type_features, $post;
407
+
408
+ if ( 'publish' === $post->post_status ) {
409
+ return;
410
+ }
411
+
412
+ if ( 2 <= $this->get_watermarks_count() && isset( $_wp_post_type_features['watermark']['title'] ) ) {
413
+ unset( $_wp_post_type_features['watermark']['title'] );
414
+ }
415
+ }
416
+
417
+ /**
418
+ * Filters whether a post untrashing should take place.
419
+ *
420
+ * @filter pre_untrash_post
421
+ *
422
+ * @param null $untrash Whether to go forward with untrashing.
423
+ * @param WP_Post $post Post object.
424
+ * @return bool
425
+ */
426
+ public function pre_untrash_post( $untrash, $post ) {
427
+
428
+ if ( 'watermark' === $post->post_type && 2 <= $this->get_watermarks_count() ) {
429
+ return true;
430
+ }
431
+
432
+ return $untrash;
433
+
434
+ }
435
+
436
+ /**
437
+ * Stores serialized watermark data in post content
438
+ *
439
+ * @filter wp_insert_post_data
440
+ *
441
+ * @param array $data An array of slashed post data.
442
+ * @param array $postarr An array of sanitized, but otherwise unmodified post data.
443
+ * @return array
444
+ */
445
+ public function wp_insert_post_data( $data, $postarr ) {
446
+
447
+ if ( 'watermark' === $data['post_type'] && isset( $postarr['watermark'] ) ) {
448
+ $watermark_data = Watermark::parse_params( $postarr['watermark'] );
449
+
450
+ $data['post_content'] = wp_json_encode( $watermark_data, JSON_UNESCAPED_UNICODE );
451
+
452
+ $old_attachment_id = isset( $postarr['ew-previous-attachment-id'] ) ? $postarr['ew-previous-attachment-id'] : false;
453
+ $new_attachment_id = $postarr['watermark']['attachment_id'];
454
+
455
+ if ( $old_attachment_id !== $new_attachment_id ) {
456
+ if ( is_numeric( $old_attachment_id ) ) {
457
+ $this->remove_watrmark_from_meta( $old_attachment_id, $postarr['ID'] );
458
+ }
459
+
460
+ $this->add_watrmark_to_meta( $new_attachment_id, $postarr['ID'] );
461
+ }
462
+
463
+ delete_post_meta( $postarr['ID'], '_ew_tmp_params' );
464
+ }
465
+
466
+ return $data;
467
+
468
+ }
469
+
470
+ /**
471
+ * Add watermark to attachment meta
472
+ *
473
+ * @param integer $attachment_id Attachment ID.
474
+ * @param integer $watermark_id Watermark ID.
475
+ * @return void
476
+ */
477
+ private function add_watrmark_to_meta( $attachment_id, $watermark_id ) {
478
+
479
+ $meta = get_post_meta( $attachment_id, '_ew_used_as_watermark', true );
480
+
481
+ if ( ! is_array( $meta ) ) {
482
+ $meta = [];
483
+ }
484
+
485
+ if ( ! in_array( $watermark_id, $meta, true ) ) {
486
+ $meta[] = $watermark_id;
487
+ update_post_meta( $attachment_id, '_ew_used_as_watermark', $meta );
488
+ }
489
+
490
+ }
491
+
492
+ /**
493
+ * Remove watermark to attachment meta
494
+ *
495
+ * @param integer $attachment_id Attachment ID.
496
+ * @param integer $watermark_id Watermark ID.
497
+ * @return void
498
+ */
499
+ private function remove_watrmark_from_meta( $attachment_id, $watermark_id ) {
500
+
501
+ $meta = get_post_meta( $attachment_id, '_ew_used_as_watermark', true );
502
+
503
+ if ( is_array( $meta ) && in_array( $watermark_id, $meta, true ) ) {
504
+ $key = array_search( $watermark_id, $meta, true );
505
+ unset( $meta[ $key ] );
506
+
507
+ if ( empty( $meta ) ) {
508
+ delete_post_meta( $attachment_id, '_ew_used_as_watermark' );
509
+ } else {
510
+ update_post_meta( $attachment_id, '_ew_used_as_watermark', $meta );
511
+ }
512
+ }
513
+
514
+ }
515
+ }
src/classes/Watermark/Preview.php CHANGED
@@ -1,91 +1,91 @@
1
- <?php
2
- /**
3
- * Preview class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Watermark;
9
-
10
- use EasyWatermark\Helpers\Image as ImageHelper;
11
-
12
- /**
13
- * Watermark class
14
- */
15
- class Preview {
16
-
17
- /**
18
- * Watermark Handler instance
19
- *
20
- * @var Handler
21
- */
22
- private $handler;
23
-
24
- /**
25
- * Constructor
26
- *
27
- * @param Handler $handler Handler object.
28
- */
29
- public function __construct( $handler ) {
30
- $this->handler = $handler;
31
- }
32
-
33
- /**
34
- * Prints preview
35
- *
36
- * @param string $type Preview type.
37
- * @param integer $watermark_id Watermark id.
38
- * @param string $format Preview format (jpg|png).
39
- * @param string $size Image size.
40
- * @return void
41
- */
42
- public function show( $type, $watermark_id, $format, $size ) {
43
-
44
- $watermark = Watermark::get( $watermark_id );
45
-
46
- $watermark->use_temporary_params();
47
-
48
- switch ( $type ) {
49
- case 'text':
50
- $this->print_text_preview( $watermark, $format );
51
- break;
52
- case 'image':
53
- $this->print_image_preview( $watermark, $format, $size );
54
- break;
55
- }
56
-
57
- do_action( 'easy-watermark/print-preview', $type, $format, $size );
58
-
59
- }
60
-
61
- /**
62
- * Prints text preview
63
- *
64
- * @param Watermark $watermark Watermark object.
65
- * @param string $format Preview format (jpg|png).
66
- * @return void
67
- */
68
- public function print_text_preview( $watermark, $format ) {
69
- $this->handler->print_text_preview( $watermark, $format );
70
- }
71
-
72
- /**
73
- * Prints text preview
74
- *
75
- * @param Watermark $watermark Watermark object.
76
- * @param string $format Preview format (jpg|png).
77
- * @param string $size Image size.
78
- * @return void|false
79
- */
80
- public function print_image_preview( $watermark, $format, $size ) {
81
-
82
- $available_sizes = ImageHelper::get_available_sizes();
83
-
84
- if ( ! array_key_exists( $size, $available_sizes ) ) {
85
- return false;
86
- }
87
-
88
- $this->handler->print_preview( $watermark, $format, $size );
89
- }
90
-
91
- }
1
+ <?php
2
+ /**
3
+ * Preview class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Watermark;
9
+
10
+ use EasyWatermark\Helpers\Image as ImageHelper;
11
+
12
+ /**
13
+ * Watermark class
14
+ */
15
+ class Preview {
16
+
17
+ /**
18
+ * Watermark Handler instance
19
+ *
20
+ * @var Handler
21
+ */
22
+ private $handler;
23
+
24
+ /**
25
+ * Constructor
26
+ *
27
+ * @param Handler $handler Handler object.
28
+ */
29
+ public function __construct( $handler ) {
30
+ $this->handler = $handler;
31
+ }
32
+
33
+ /**
34
+ * Prints preview
35
+ *
36
+ * @param string $type Preview type.
37
+ * @param integer $watermark_id Watermark id.
38
+ * @param string $format Preview format (jpg|png).
39
+ * @param string $size Image size.
40
+ * @return void
41
+ */
42
+ public function show( $type, $watermark_id, $format, $size ) {
43
+
44
+ $watermark = Watermark::get( $watermark_id );
45
+
46
+ $watermark->use_temporary_params();
47
+
48
+ switch ( $type ) {
49
+ case 'text':
50
+ $this->print_text_preview( $watermark, $format );
51
+ break;
52
+ case 'image':
53
+ $this->print_image_preview( $watermark, $format, $size );
54
+ break;
55
+ }
56
+
57
+ do_action( 'easy-watermark/print-preview', $type, $format, $size );
58
+
59
+ }
60
+
61
+ /**
62
+ * Prints text preview
63
+ *
64
+ * @param Watermark $watermark Watermark object.
65
+ * @param string $format Preview format (jpg|png).
66
+ * @return void
67
+ */
68
+ public function print_text_preview( $watermark, $format ) {
69
+ $this->handler->print_text_preview( $watermark, $format );
70
+ }
71
+
72
+ /**
73
+ * Prints text preview
74
+ *
75
+ * @param Watermark $watermark Watermark object.
76
+ * @param string $format Preview format (jpg|png).
77
+ * @param string $size Image size.
78
+ * @return void|false
79
+ */
80
+ public function print_image_preview( $watermark, $format, $size ) {
81
+
82
+ $available_sizes = ImageHelper::get_available_sizes();
83
+
84
+ if ( ! array_key_exists( $size, $available_sizes ) ) {
85
+ return false;
86
+ }
87
+
88
+ $this->handler->print_preview( $watermark, $format, $size );
89
+ }
90
+
91
+ }
src/classes/Watermark/Watermark.php CHANGED
@@ -1,262 +1,262 @@
1
- <?php
2
- /**
3
- * Watermark class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Watermark;
9
-
10
- /**
11
- * Watermark class
12
- */
13
- class Watermark {
14
-
15
- /**
16
- * Default params
17
- *
18
- * @var array
19
- */
20
- private static $defaults = [
21
- 'type' => null,
22
- 'attachment_id' => null,
23
- 'mime_type' => null,
24
- 'url' => null,
25
- 'text' => '',
26
- 'auto_add' => true,
27
- 'auto_add_all' => true,
28
- 'scaling_mode' => 'none',
29
- 'scale_down_only' => false,
30
- 'scale' => 100,
31
- 'font' => null,
32
- 'text_color' => '#000000',
33
- 'text_size' => 24,
34
- 'text_angle' => 0,
35
- 'opacity' => 100,
36
- 'alignment' => 'center',
37
- 'offset' => [
38
- 'x' => [
39
- 'value' => 0,
40
- 'unit' => 'px',
41
- ],
42
- 'y' => [
43
- 'value' => 0,
44
- 'unit' => 'px',
45
- ],
46
- ],
47
- 'image_types' => [
48
- 'image/jpeg',
49
- 'image/png',
50
- 'image/gif',
51
- ],
52
- 'image_sizes' => [
53
- 'medium',
54
- 'medium_large',
55
- 'large',
56
- 'full',
57
- ],
58
- 'post_types' => [
59
- 'unattached',
60
- 'post',
61
- 'page',
62
- ],
63
- ];
64
-
65
- /**
66
- * Instances
67
- *
68
- * @var array
69
- */
70
- private static $instances = [];
71
-
72
- /**
73
- * Factory method for watermark instances.
74
- * Creates one instance for post id.
75
- *
76
- * @param mixed $post Post ID or WP_Post instance.
77
- * @return mixed
78
- */
79
- public static function get( $post ) {
80
-
81
- if ( is_numeric( $post ) ) {
82
- $post = get_post( $post );
83
- }
84
-
85
- if ( ! $post instanceof \WP_Post || 'watermark' !== $post->post_type ) {
86
- return false;
87
- }
88
-
89
- if ( ! isset( self::$instances[ $post->ID ] ) ) {
90
- self::$instances[ $post->ID ] = new self( $post );
91
- }
92
-
93
- return self::$instances[ $post->ID ];
94
-
95
- }
96
-
97
- /**
98
- * Gets all watermarks
99
- *
100
- * @return array
101
- */
102
- public static function get_all() {
103
-
104
- $posts = get_posts( [
105
- 'post_type' => 'watermark',
106
- 'numberposts' => -1,
107
- ] );
108
-
109
- foreach ( $posts as $post ) {
110
- self::get( $post );
111
- }
112
-
113
- return self::$instances;
114
-
115
- }
116
-
117
- /**
118
- * Builds complete params array to save in post content
119
- *
120
- * @param array $params Params array.
121
- * @return array
122
- */
123
- public static function parse_params( $params ) {
124
-
125
- foreach ( self::$defaults as $key => $value ) {
126
- if ( ! array_key_exists( $key, $params ) ) {
127
- if ( 'array' === gettype( self::$defaults[ $key ] ) ) {
128
- $params[ $key ] = [];
129
- } else {
130
- $params[ $key ] = false;
131
- }
132
- }
133
- }
134
-
135
- return $params;
136
-
137
- }
138
-
139
- /**
140
- * Returns defaults array
141
- *
142
- * @return array
143
- */
144
- public static function get_defaults() {
145
- return self::$defaults;
146
- }
147
-
148
- /**
149
- * Original post object
150
- *
151
- * @var object
152
- */
153
- private $post;
154
-
155
- /**
156
- * Watermark configuration params
157
- *
158
- * @var array
159
- */
160
- private $params;
161
-
162
- /**
163
- * Watermark configuration params
164
- *
165
- * @var array
166
- */
167
- private $tmp_params;
168
-
169
- /**
170
- * Constructor
171
- *
172
- * @param WP_Post $post Post object.
173
- * @return void
174
- */
175
- public function __construct( $post ) {
176
-
177
- $this->post = $post;
178
-
179
- $this->params = $post->post_content ? json_decode( $post->post_content, true ) : [];
180
- $this->params = wp_parse_args( $this->params, self::$defaults );
181
-
182
- }
183
-
184
- /**
185
- * Switches params to temporary if exist
186
- *
187
- * @return mixed
188
- */
189
- public function use_temporary_params() {
190
-
191
- $tmp_params = get_post_meta( $this->post->ID, '_ew_tmp_params', true );
192
-
193
- if ( $tmp_params ) {
194
- $this->params = wp_parse_args( $tmp_params, self::$defaults );
195
- }
196
-
197
- }
198
-
199
- /**
200
- * Getter for watermark config params
201
- *
202
- * @param string $key Param name.
203
- * @return mixed
204
- */
205
- public function get_param( $key ) {
206
-
207
- if ( isset( $this->params[ $key ] ) ) {
208
- return $this->params[ $key ];
209
- }
210
-
211
- }
212
-
213
- /**
214
- * Setter for watermark config params
215
- *
216
- * @param string $key Param name.
217
- * @param string $value Param value.
218
- * @return void
219
- */
220
- public function set_param( $key, $value ) {
221
- $this->params[ $key ] = $value;
222
- }
223
-
224
- /**
225
- * Getter for watermark config params
226
- *
227
- * @return array watermark config params
228
- */
229
- public function get_params() {
230
- return $this->params;
231
- }
232
-
233
- /**
234
- * Magic method for more WordPress feel
235
- *
236
- * Allows to do:
237
- * echo $watermark->post_title;
238
- *
239
- * @param string $key Param name or WP_Post field.
240
- * @return mixed
241
- */
242
- public function __get( $key ) {
243
-
244
- if ( isset( $this->post->$key ) ) {
245
- return $this->post->$key;
246
- }
247
-
248
- return $this->get_param( $key );
249
-
250
- }
251
-
252
- /**
253
- * Magic setter for watermark params
254
- *
255
- * @param string $key Param name.
256
- * @param mixed $value Param value.
257
- * @return void
258
- */
259
- public function __set( $key, $value ) {
260
- $this->set_param( $key, $value );
261
- }
262
- }
1
+ <?php
2
+ /**
3
+ * Watermark class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Watermark;
9
+
10
+ /**
11
+ * Watermark class
12
+ */
13
+ class Watermark {
14
+
15
+ /**
16
+ * Default params
17
+ *
18
+ * @var array
19
+ */
20
+ private static $defaults = [
21
+ 'type' => null,
22
+ 'attachment_id' => null,
23
+ 'mime_type' => null,
24
+ 'url' => null,
25
+ 'text' => '',
26
+ 'auto_add' => true,
27
+ 'auto_add_all' => true,
28
+ 'scaling_mode' => 'none',
29
+ 'scale_down_only' => false,
30
+ 'scale' => 100,
31
+ 'font' => null,
32
+ 'text_color' => '#000000',
33
+ 'text_size' => 24,
34
+ 'text_angle' => 0,
35
+ 'opacity' => 100,
36
+ 'alignment' => 'center',
37
+ 'offset' => [
38
+ 'x' => [
39
+ 'value' => 0,
40
+ 'unit' => 'px',
41
+ ],
42
+ 'y' => [
43
+ 'value' => 0,
44
+ 'unit' => 'px',
45
+ ],
46
+ ],
47
+ 'image_types' => [
48
+ 'image/jpeg',
49
+ 'image/png',
50
+ 'image/gif',
51
+ ],
52
+ 'image_sizes' => [
53
+ 'medium',
54
+ 'medium_large',
55
+ 'large',
56
+ 'full',
57
+ ],
58
+ 'post_types' => [
59
+ 'unattached',
60
+ 'post',
61
+ 'page',
62
+ ],
63
+ ];
64
+
65
+ /**
66
+ * Instances
67
+ *
68
+ * @var array
69
+ */
70
+ private static $instances = [];
71
+
72
+ /**
73
+ * Factory method for watermark instances.
74
+ * Creates one instance for post id.
75
+ *
76
+ * @param mixed $post Post ID or WP_Post instance.
77
+ * @return mixed
78
+ */
79
+ public static function get( $post ) {
80
+
81
+ if ( is_numeric( $post ) ) {
82
+ $post = get_post( $post );
83
+ }
84
+
85
+ if ( ! $post instanceof \WP_Post || 'watermark' !== $post->post_type ) {
86
+ return false;
87
+ }
88
+
89
+ if ( ! isset( self::$instances[ $post->ID ] ) ) {
90
+ self::$instances[ $post->ID ] = new self( $post );
91
+ }
92
+
93
+ return self::$instances[ $post->ID ];
94
+
95
+ }
96
+
97
+ /**
98
+ * Gets all watermarks
99
+ *
100
+ * @return array
101
+ */
102
+ public static function get_all() {
103
+
104
+ $posts = get_posts( [
105
+ 'post_type' => 'watermark',
106
+ 'numberposts' => -1,
107
+ ] );
108
+
109
+ foreach ( $posts as $post ) {
110
+ self::get( $post );
111
+ }
112
+
113
+ return self::$instances;
114
+
115
+ }
116
+
117
+ /**
118
+ * Builds complete params array to save in post content
119
+ *
120
+ * @param array $params Params array.
121
+ * @return array
122
+ */
123
+ public static function parse_params( $params ) {
124
+
125
+ foreach ( self::$defaults as $key => $value ) {
126
+ if ( ! array_key_exists( $key, $params ) ) {
127
+ if ( 'array' === gettype( self::$defaults[ $key ] ) ) {
128
+ $params[ $key ] = [];
129
+ } else {
130
+ $params[ $key ] = false;
131
+ }
132
+ }
133
+ }
134
+
135
+ return $params;
136
+
137
+ }
138
+
139
+ /**
140
+ * Returns defaults array
141
+ *
142
+ * @return array
143
+ */
144
+ public static function get_defaults() {
145
+ return self::$defaults;
146
+ }
147
+
148
+ /**
149
+ * Original post object
150
+ *
151
+ * @var object
152
+ */
153
+ private $post;
154
+
155
+ /**
156
+ * Watermark configuration params
157
+ *
158
+ * @var array
159
+ */
160
+ private $params;
161
+
162
+ /**
163
+ * Watermark configuration params
164
+ *
165
+ * @var array
166
+ */
167
+ private $tmp_params;
168
+
169
+ /**
170
+ * Constructor
171
+ *
172
+ * @param WP_Post $post Post object.
173
+ * @return void
174
+ */
175
+ public function __construct( $post ) {
176
+
177
+ $this->post = $post;
178
+
179
+ $this->params = $post->post_content ? json_decode( $post->post_content, true ) : [];
180
+ $this->params = wp_parse_args( $this->params, self::$defaults );
181
+
182
+ }
183
+
184
+ /**
185
+ * Switches params to temporary if exist
186
+ *
187
+ * @return mixed
188
+ */
189
+ public function use_temporary_params() {
190
+
191
+ $tmp_params = get_post_meta( $this->post->ID, '_ew_tmp_params', true );
192
+
193
+ if ( $tmp_params ) {
194
+ $this->params = wp_parse_args( $tmp_params, self::$defaults );
195
+ }
196
+
197
+ }
198
+
199
+ /**
200
+ * Getter for watermark config params
201
+ *
202
+ * @param string $key Param name.
203
+ * @return mixed
204
+ */
205
+ public function get_param( $key ) {
206
+
207
+ if ( isset( $this->params[ $key ] ) ) {
208
+ return $this->params[ $key ];
209
+ }
210
+
211
+ }
212
+
213
+ /**
214
+ * Setter for watermark config params
215
+ *
216
+ * @param string $key Param name.
217
+ * @param string $value Param value.
218
+ * @return void
219
+ */
220
+ public function set_param( $key, $value ) {
221
+ $this->params[ $key ] = $value;
222
+ }
223
+
224
+ /**
225
+ * Getter for watermark config params
226
+ *
227
+ * @return array watermark config params
228
+ */
229
+ public function get_params() {
230
+ return $this->params;
231
+ }
232
+
233
+ /**
234
+ * Magic method for more WordPress feel
235
+ *
236
+ * Allows to do:
237
+ * echo $watermark->post_title;
238
+ *
239
+ * @param string $key Param name or WP_Post field.
240
+ * @return mixed
241
+ */
242
+ public function __get( $key ) {
243
+
244
+ if ( isset( $this->post->$key ) ) {
245
+ return $this->post->$key;
246
+ }
247
+
248
+ return $this->get_param( $key );
249
+
250
+ }
251
+
252
+ /**
253
+ * Magic setter for watermark params
254
+ *
255
+ * @param string $key Param name.
256
+ * @param mixed $value Param value.
257
+ * @return void
258
+ */
259
+ public function __set( $key, $value ) {
260
+ $this->set_param( $key, $value );
261
+ }
262
+ }
src/inc/functions.php CHANGED
@@ -1,35 +1,35 @@
1
- <?php
2
- /**
3
- * Function for dochooks test
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- /**
9
- * Checks if the DocHooks are enabled and working.
10
- *
11
- * @return boolean
12
- */
13
- function ew_dochooks_enabled() {
14
- if ( ! class_exists( 'EasyWatermarkDocHookTest' ) ) {
15
- /**
16
- * EasyWatermarkDocHookTest class
17
- */
18
- class EasyWatermarkDocHookTest {
19
- /**
20
- * Test method
21
- *
22
- * @action test 10
23
- * @return void
24
- */
25
- public function test_method() {}
26
- }
27
- }
28
-
29
- $reflector = new \ReflectionObject( new EasyWatermarkDocHookTest() );
30
-
31
- foreach ( $reflector->getMethods() as $method ) {
32
- $doc = $method->getDocComment();
33
- return (bool) strpos( $doc, '@action' );
34
- }
35
- }
1
+ <?php
2
+ /**
3
+ * Function for dochooks test
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ /**
9
+ * Checks if the DocHooks are enabled and working.
10
+ *
11
+ * @return boolean
12
+ */
13
+ function ew_dochooks_enabled() {
14
+ if ( ! class_exists( 'EasyWatermarkDocHookTest' ) ) {
15
+ /**
16
+ * EasyWatermarkDocHookTest class
17
+ */
18
+ class EasyWatermarkDocHookTest {
19
+ /**
20
+ * Test method
21
+ *
22
+ * @action test 10
23
+ * @return void
24
+ */
25
+ public function test_method() {}
26
+ }
27
+ }
28
+
29
+ $reflector = new \ReflectionObject( new EasyWatermarkDocHookTest() );
30
+
31
+ foreach ( $reflector->getMethods() as $method ) {
32
+ $doc = $method->getDocComment();
33
+ return (bool) strpos( $doc, '@action' );
34
+ }
35
+ }
src/inc/hooks.php CHANGED
@@ -11,11 +11,29 @@
11
 
12
  add_action( 'plugins_loaded', [ $this->objects['EasyWatermark\Core\Plugin']['instance'], 'setup' ], 10, 0 );
13
  add_action( 'init', [ $this->objects['EasyWatermark\Core\Plugin']['instance'], 'init' ], 10, 0 );
14
- add_action( 'shutdown', [ $this->objects['EasyWatermark\Core\Plugin']['instance'], 'shutdown' ], 10, 0 );
15
- add_action( 'parse_request', [ $this->objects['EasyWatermark\Core\Plugin']['instance'], 'parse_request' ], 10, 1 );
16
  add_action( 'easy-watermark/settings/register', [ $this->objects['EasyWatermark\Backup\Manager']['instance'], 'register_settings_section' ], 10, 1 );
17
  add_action( 'easy-watermark/settings/register/backup', [ $this->objects['EasyWatermark\Backup\Manager']['instance'], 'register_settings_fields' ], 10, 1 );
18
  add_action( 'easy-watermark/placeholders/load', [ $this->objects['EasyWatermark\Placeholders\Defaults']['instance'], 'load_default_placeholders' ], 10, 1 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  add_action( 'init', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'register' ], 10, 0 );
20
  add_filter( 'parent_file', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'parent_file' ], 10, 1 );
21
  add_action( 'current_screen', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'current_screen' ], 10, 0 );
@@ -34,14 +52,11 @@ add_filter( 'get_user_option_screen_layout_watermark', [ $this->objects['EasyWat
34
  add_action( 'edit_form_top', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'change_title_support' ], 10, 0 );
35
  add_filter( 'pre_untrash_post', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'pre_untrash_post' ], 10, 2 );
36
  add_filter( 'wp_insert_post_data', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'wp_insert_post_data' ], 10, 2 );
37
- add_action( 'pre-plupload-upload-ui', [ $this->objects['EasyWatermark\Features\AutoWatermarkSwitch']['instance'], 'pre_plupload_upload_ui' ], 10, 0 );
38
- add_action( 'admin_notices', [ $this->objects['EasyWatermark\Features\AutoWatermarkSwitch']['instance'], 'admin_notices' ], 10, 0 );
39
  add_action( 'admin_menu', [ $this->objects['EasyWatermark\Dashboard\Dashboard']['instance'], 'add_options_page' ], 10, 0 );
40
  add_action( 'admin_notices', [ $this->objects['EasyWatermark\Dashboard\Dashboard']['instance'], 'admin_notices' ], 10, 0 );
41
  add_action( 'easy-watermark/dashboard/watermarks/notices', [ $this->objects['EasyWatermark\Dashboard\Watermarks']['instance'], 'admin_notices' ], 10, 0 );
42
  add_filter( 'easy-watermark/dashboard/watermarks/view-args', [ $this->objects['EasyWatermark\Dashboard\Watermarks']['instance'], 'view_args' ], 10, 1 );
43
  add_filter( 'easy-watermark/dashboard/tabs', [ $this->objects['EasyWatermark\Dashboard\Watermarks']['instance'], 'add_tab' ], 10, 1 );
44
- add_action( 'easy-watermark/dashboard/settings/notices', [ $this->objects['EasyWatermark\Dashboard\Settings']['instance'], 'admin_notices' ], 10, 0 );
45
  add_filter( 'easy-watermark/dashboard/settings/view-args', [ $this->objects['EasyWatermark\Dashboard\Settings']['instance'], 'view_args' ], 10, 1 );
46
  add_filter( 'easy-watermark/dashboard/tabs', [ $this->objects['EasyWatermark\Dashboard\Settings']['instance'], 'add_tab' ], 10, 1 );
47
  add_action( 'admin_init', [ $this->objects['EasyWatermark\Dashboard\Permissions']['instance'], 'setup_permissions' ], 10, 0 );
@@ -52,22 +67,7 @@ add_action( 'easy-watermark/dashboard/settings/notices', [ $this->objects['EasyW
52
  add_filter( 'easy-watermark/dashboard/tools/view-args', [ $this->objects['EasyWatermark\Dashboard\Tools']['instance'], 'view_args' ], 10, 1 );
53
  add_action( 'wp_ajax_easy-watermark/tools/get-attachments', [ $this->objects['EasyWatermark\Dashboard\Tools']['instance'], 'ajax_get_attachments' ], 10, 0 );
54
  add_filter( 'easy-watermark/dashboard/tabs', [ $this->objects['EasyWatermark\Dashboard\Tools']['instance'], 'add_tab' ], 10, 1 );
55
- add_action( 'easy-watermark/settings/register/general', [ $this->objects['EasyWatermark\Features\SrcsetFilter']['instance'], 'register_settings' ], 10, 1 );
56
- add_filter( 'wp_calculate_image_srcset_meta', [ $this->objects['EasyWatermark\Features\SrcsetFilter']['instance'], 'wp_calculate_image_srcset_meta' ], 1000, 4 );
57
- add_filter( 'wp_calculate_image_srcset', [ $this->objects['EasyWatermark\Features\SrcsetFilter']['instance'], 'wp_calculate_image_srcset' ], 10, 5 );
58
- add_action( 'wp_ajax_easy-watermark/apply_single', [ $this->objects['EasyWatermark\Watermark\Ajax']['instance'], 'apply_single_watermark' ], 10, 0 );
59
- add_action( 'wp_ajax_easy-watermark/apply_all', [ $this->objects['EasyWatermark\Watermark\Ajax']['instance'], 'apply_all_watermarks' ], 10, 0 );
60
- add_action( 'wp_ajax_easy-watermark/restore_backup', [ $this->objects['EasyWatermark\Watermark\Ajax']['instance'], 'restore_backup' ], 10, 0 );
61
- add_action( 'wp_ajax_easy-watermark/autosave', [ $this->objects['EasyWatermark\Watermark\Ajax']['instance'], 'autosave' ], 10, 0 );
62
- add_action( 'wp_ajax_easy-watermark/attachments-info', [ $this->objects['EasyWatermark\Watermark\Ajax']['instance'], 'get_attachments_info' ], 10, 0 );
63
- add_action( 'delete_attachment', [ $this->objects['EasyWatermark\Watermark\Hooks']['instance'], 'delete_attachment' ], 10, 1 );
64
- add_filter( 'wp_get_attachment_image_src', [ $this->objects['EasyWatermark\Watermark\Hooks']['instance'], 'wp_get_attachment_image_src' ], 10, 4 );
65
- add_filter( 'wp_generate_attachment_metadata', [ $this->objects['EasyWatermark\Watermark\Hooks']['instance'], 'wp_generate_attachment_metadata' ], 10, 2 );
66
- add_filter( 'wp_prepare_attachment_for_js', [ $this->objects['EasyWatermark\Watermark\Hooks']['instance'], 'wp_prepare_attachment_for_js' ], 10, 3 );
67
- add_filter( 'bulk_actions-upload', [ $this->objects['EasyWatermark\Watermark\Hooks']['instance'], 'bulk_actions' ], 10, 1 );
68
- add_action( 'easy-watermark/settings/register/general', [ $this->objects['EasyWatermark\Settings\Settings']['instance'], 'register_fields' ], 5, 1 );
69
- add_action( 'admin_init', [ $this->objects['EasyWatermark\Settings\Settings']['instance'], 'register_settings' ], 10, 0 );
70
- add_filter( 'plugin_action_links_easy-watermark/easy-watermark.php', [ $this->objects['EasyWatermark\Settings\Settings']['instance'], 'plugin_action_links' ], 10, 2 );
71
  add_action( 'admin_enqueue_scripts', [ $this->objects['EasyWatermark\Core\Assets']['instance'], 'register_admin_scripts' ], 20, 0 );
72
  add_action( 'admin_enqueue_scripts', [ $this->objects['EasyWatermark\Core\Assets']['instance'], 'enqueue_admin_scripts' ], 30, 0 );
73
  add_action( 'wp_enqueue_media', [ $this->objects['EasyWatermark\Core\Assets']['instance'], 'wp_enqueue_media' ], 10, 0 );
11
 
12
  add_action( 'plugins_loaded', [ $this->objects['EasyWatermark\Core\Plugin']['instance'], 'setup' ], 10, 0 );
13
  add_action( 'init', [ $this->objects['EasyWatermark\Core\Plugin']['instance'], 'init' ], 10, 0 );
 
 
14
  add_action( 'easy-watermark/settings/register', [ $this->objects['EasyWatermark\Backup\Manager']['instance'], 'register_settings_section' ], 10, 1 );
15
  add_action( 'easy-watermark/settings/register/backup', [ $this->objects['EasyWatermark\Backup\Manager']['instance'], 'register_settings_fields' ], 10, 1 );
16
  add_action( 'easy-watermark/placeholders/load', [ $this->objects['EasyWatermark\Placeholders\Defaults']['instance'], 'load_default_placeholders' ], 10, 1 );
17
+ add_action( 'pre-plupload-upload-ui', [ $this->objects['EasyWatermark\Features\AutoWatermarkSwitch']['instance'], 'pre_plupload_upload_ui' ], 10, 0 );
18
+ add_action( 'admin_notices', [ $this->objects['EasyWatermark\Features\AutoWatermarkSwitch']['instance'], 'admin_notices' ], 10, 0 );
19
+ add_action( 'easy-watermark/settings/register/general', [ $this->objects['EasyWatermark\Features\CacheBusting']['instance'], 'register_settings' ], 10, 1 );
20
+ add_filter( 'wp_get_attachment_image_src', [ $this->objects['EasyWatermark\Features\CacheBusting']['instance'], 'wp_get_attachment_image_src' ], 10, 4 );
21
+ add_filter( 'wp_calculate_image_srcset', [ $this->objects['EasyWatermark\Features\CacheBusting']['instance'], 'wp_calculate_image_srcset' ], 10, 5 );
22
+ add_action( 'easy-watermark/settings/register/general', [ $this->objects['EasyWatermark\Features\SrcsetFilter']['instance'], 'register_settings' ], 10, 1 );
23
+ add_filter( 'wp_calculate_image_srcset_meta', [ $this->objects['EasyWatermark\Features\SrcsetFilter']['instance'], 'wp_calculate_image_srcset_meta' ], 1000, 4 );
24
+ add_action( 'wp_ajax_easy-watermark/apply_single', [ $this->objects['EasyWatermark\Watermark\Ajax']['instance'], 'apply_single_watermark' ], 10, 0 );
25
+ add_action( 'wp_ajax_easy-watermark/apply_all', [ $this->objects['EasyWatermark\Watermark\Ajax']['instance'], 'apply_all_watermarks' ], 10, 0 );
26
+ add_action( 'wp_ajax_easy-watermark/restore_backup', [ $this->objects['EasyWatermark\Watermark\Ajax']['instance'], 'restore_backup' ], 10, 0 );
27
+ add_action( 'wp_ajax_easy-watermark/autosave', [ $this->objects['EasyWatermark\Watermark\Ajax']['instance'], 'autosave' ], 10, 0 );
28
+ add_action( 'wp_ajax_easy-watermark/attachments-info', [ $this->objects['EasyWatermark\Watermark\Ajax']['instance'], 'get_attachments_info' ], 10, 0 );
29
+ add_action( 'delete_attachment', [ $this->objects['EasyWatermark\Watermark\Hooks']['instance'], 'delete_attachment' ], 10, 1 );
30
+ add_filter( 'wp_generate_attachment_metadata', [ $this->objects['EasyWatermark\Watermark\Hooks']['instance'], 'wp_generate_attachment_metadata' ], 10, 2 );
31
+ add_filter( 'wp_prepare_attachment_for_js', [ $this->objects['EasyWatermark\Watermark\Hooks']['instance'], 'wp_prepare_attachment_for_js' ], 10, 3 );
32
+ add_filter( 'bulk_actions-upload', [ $this->objects['EasyWatermark\Watermark\Hooks']['instance'], 'bulk_actions' ], 10, 1 );
33
+ add_action( 'easy-watermark/settings/register/general', [ $this->objects['EasyWatermark\Settings\Settings']['instance'], 'register_fields' ], 5, 1 );
34
+ add_action( 'admin_init', [ $this->objects['EasyWatermark\Settings\Settings']['instance'], 'register_settings' ], 10, 0 );
35
+ add_filter( 'plugin_action_links_easy-watermark/easy-watermark.php', [ $this->objects['EasyWatermark\Settings\Settings']['instance'], 'plugin_action_links' ], 10, 2 );
36
+ add_action( 'parse_request', [ $this->objects['EasyWatermark\Features\WatermarkPreview']['instance'], 'parse_request' ], 10, 1 );
37
  add_action( 'init', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'register' ], 10, 0 );
38
  add_filter( 'parent_file', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'parent_file' ], 10, 1 );
39
  add_action( 'current_screen', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'current_screen' ], 10, 0 );
52
  add_action( 'edit_form_top', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'change_title_support' ], 10, 0 );
53
  add_filter( 'pre_untrash_post', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'pre_untrash_post' ], 10, 2 );
54
  add_filter( 'wp_insert_post_data', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'wp_insert_post_data' ], 10, 2 );
 
 
55
  add_action( 'admin_menu', [ $this->objects['EasyWatermark\Dashboard\Dashboard']['instance'], 'add_options_page' ], 10, 0 );
56
  add_action( 'admin_notices', [ $this->objects['EasyWatermark\Dashboard\Dashboard']['instance'], 'admin_notices' ], 10, 0 );
57
  add_action( 'easy-watermark/dashboard/watermarks/notices', [ $this->objects['EasyWatermark\Dashboard\Watermarks']['instance'], 'admin_notices' ], 10, 0 );
58
  add_filter( 'easy-watermark/dashboard/watermarks/view-args', [ $this->objects['EasyWatermark\Dashboard\Watermarks']['instance'], 'view_args' ], 10, 1 );
59
  add_filter( 'easy-watermark/dashboard/tabs', [ $this->objects['EasyWatermark\Dashboard\Watermarks']['instance'], 'add_tab' ], 10, 1 );
 
60
  add_filter( 'easy-watermark/dashboard/settings/view-args', [ $this->objects['EasyWatermark\Dashboard\Settings']['instance'], 'view_args' ], 10, 1 );
61
  add_filter( 'easy-watermark/dashboard/tabs', [ $this->objects['EasyWatermark\Dashboard\Settings']['instance'], 'add_tab' ], 10, 1 );
62
  add_action( 'admin_init', [ $this->objects['EasyWatermark\Dashboard\Permissions']['instance'], 'setup_permissions' ], 10, 0 );
67
  add_filter( 'easy-watermark/dashboard/tools/view-args', [ $this->objects['EasyWatermark\Dashboard\Tools']['instance'], 'view_args' ], 10, 1 );
68
  add_action( 'wp_ajax_easy-watermark/tools/get-attachments', [ $this->objects['EasyWatermark\Dashboard\Tools']['instance'], 'ajax_get_attachments' ], 10, 0 );
69
  add_filter( 'easy-watermark/dashboard/tabs', [ $this->objects['EasyWatermark\Dashboard\Tools']['instance'], 'add_tab' ], 10, 1 );
70
+ add_filter( 'admin_body_class', [ $this->objects['EasyWatermark\Core\Assets']['instance'], 'body_class' ], 10, 1 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  add_action( 'admin_enqueue_scripts', [ $this->objects['EasyWatermark\Core\Assets']['instance'], 'register_admin_scripts' ], 20, 0 );
72
  add_action( 'admin_enqueue_scripts', [ $this->objects['EasyWatermark\Core\Assets']['instance'], 'enqueue_admin_scripts' ], 30, 0 );
73
  add_action( 'wp_enqueue_media', [ $this->objects['EasyWatermark\Core\Assets']['instance'], 'wp_enqueue_media' ], 10, 0 );
src/views/dashboard/pages/tools.php CHANGED
@@ -1,55 +1,67 @@
1
- <?php
2
- /**
3
- * Tools page content
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- ?>
9
- <div class="tools ew-grid">
10
- <div class="postbox item tool-bulk-watermark">
11
- <div class="inside">
12
- <h3><?php esc_html_e( 'Bulk Watermark', 'easy-watermark' ); ?></h3>
13
- <div class="content">
14
- <p><?php esc_html_e( 'Using this tool you can quickly apply watermark to all images in the Media Library.', 'easy-watermark' ); ?></p>
15
- <?php if ( count( $watermarks ) ) : ?>
16
- <?php if ( count( $attachments ) ) : ?>
17
- <p>
18
- <select class="watermark">
19
- <option value="-1"><?php esc_html_e( 'Select Watermark', 'easy-watermark' ); ?></option>
20
- <?php if ( 1 < count( $watermarks ) ) : ?>
21
- <option value="all" data-nonce="<?php echo esc_attr( wp_create_nonce( 'apply_all' ) ); ?>"><?php esc_html_e( 'All Watermarks', 'easy-watermark' ); ?></option>
22
- <?php endif; ?>
23
- <?php foreach ( $watermarks as $watermark ) : ?>
24
- <option value="<?php echo esc_attr( $watermark->ID ); ?>" data-nonce="<?php echo esc_attr( wp_create_nonce( 'apply_single-' . $watermark->ID ) ); ?>"><?php echo esc_html( $watermark->post_title ); ?></option>
25
- <?php endforeach; ?>
26
- </select>
27
- </p>
28
- <p><a href="#" class="button-primary"><?php esc_html_e( 'Start', 'easy-watermark' ); ?></a><span class="spinner"></span></p>
29
- <p class="description"><?php esc_html_e( 'Note: The same watermark will never get applied twice to the same image. This tool is safe to use even if some of the images are already watermarked.', 'easy-watermark' ); ?></p>
30
- <?php else : ?>
31
- <p><?php esc_html_e( 'There are no image attachments in your Media Library available for watermarking.', 'easy-watermark' ); ?></p>
32
- <?php endif; ?>
33
- <?php else : ?>
34
- <?php $link = sprintf( '<a href="%s">%s</a>', admin_url( 'post-new.php?post_type=watermark' ), esc_html_x( 'create watermark', 'link text for new watermark page', 'easy-watermark' ) ); ?>
35
- <?php /* translators: %s is a "create watermark" link */ ?>
36
- <p><?php printf( esc_html__( 'There are no watermarks configured. Please %s first.', 'easy-watermark' ), $link ); // phpcs:ignore ?></p>
37
- <?php endif; ?>
38
- </div>
39
- <p class="status"></p>
40
- </div>
41
- </div>
42
- <div class="postbox item tool-restore" data-backup-count="<?php echo esc_attr( $backup_count ); ?>">
43
- <div class="inside">
44
- <h3><?php esc_html_e( 'Restore Backup', 'easy-watermark' ); ?></h3>
45
- <div class="content">
46
- <p><?php esc_html_e( 'Here you can quickly restore backup for all images in Media Library.', 'easy-watermark' ); ?></p>
47
- <?php /* translators: %s is backed up images count */ ?>
48
- <p class="hidden has-backup"><?php printf( esc_html__( 'There are %s backed up images in your Media Library.', 'easy-watermark' ), "<span class=\"backup-count\">{$backup_count}</span>" ); // phpcs:ignore ?></p>
49
- <p class="hidden has-backup"><a href="#" class="button-primary" data-nonce="<?php echo esc_attr( wp_create_nonce( 'restore_backup' ) ); ?>"><?php esc_html_e( 'Restore', 'easy-watermark' ); ?></a><span class="spinner"></span></p>
50
- <p class="hidden no-backup"><?php esc_html_e( 'There are no backed up images in your Media Library.', 'easy-watermark' ); ?></p>
51
- </div>
52
- <p class="status"></p>
53
- </div>
54
- </div>
55
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Tools page content
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ ?>
9
+ <div class="tools ew-grid">
10
+ <div class="postbox item tool-bulk-watermark">
11
+ <div class="inside">
12
+ <h3><?php esc_html_e( 'Bulk Watermark', 'easy-watermark' ); ?></h3>
13
+ <div class="content">
14
+ <p><?php esc_html_e( 'Using this tool you can quickly apply watermark to all images in the Media Library.', 'easy-watermark' ); ?></p>
15
+ <?php if ( count( $watermarks ) ) : ?>
16
+ <?php if ( count( $attachments ) ) : ?>
17
+ <p>
18
+ <select class="watermark">
19
+ <option value="-1"><?php esc_html_e( 'Select Watermark', 'easy-watermark' ); ?></option>
20
+ <?php if ( 1 < count( $watermarks ) ) : ?>
21
+ <option value="all" data-nonce="<?php echo esc_attr( wp_create_nonce( 'apply_all' ) ); ?>"><?php esc_html_e( 'All Watermarks', 'easy-watermark' ); ?></option>
22
+ <?php endif; ?>
23
+ <?php foreach ( $watermarks as $watermark ) : ?>
24
+ <option value="<?php echo esc_attr( $watermark->ID ); ?>" data-nonce="<?php echo esc_attr( wp_create_nonce( 'apply_single-' . $watermark->ID ) ); ?>"><?php echo esc_html( $watermark->post_title ); ?></option>
25
+ <?php endforeach; ?>
26
+ </select>
27
+ </p>
28
+ <p><a href="#" class="button-primary"><?php esc_html_e( 'Start', 'easy-watermark' ); ?></a><span class="spinner"></span></p>
29
+ <p class="description"><?php esc_html_e( 'Note: The same watermark will never get applied twice to the same image. This tool is safe to use even if some of the images are already watermarked.', 'easy-watermark' ); ?></p>
30
+ <?php else : ?>
31
+ <p><?php esc_html_e( 'There are no image attachments in your Media Library available for watermarking.', 'easy-watermark' ); ?></p>
32
+ <?php endif; ?>
33
+ <?php else : ?>
34
+ <?php $link = sprintf( '<a href="%s">%s</a>', admin_url( 'post-new.php?post_type=watermark' ), esc_html_x( 'create watermark', 'link text for new watermark page', 'easy-watermark' ) ); ?>
35
+ <?php /* translators: %s is a "create watermark" link */ ?>
36
+ <p><?php printf( esc_html__( 'There are no watermarks configured. Please %s first.', 'easy-watermark' ), $link ); // phpcs:ignore ?></p>
37
+ <?php endif; ?>
38
+ </div>
39
+ <p class="status"></p>
40
+ </div>
41
+ </div>
42
+ <div class="postbox item tool-restore" data-backup-count="<?php echo esc_attr( $backup_count ); ?>">
43
+ <div class="inside">
44
+ <h3><?php esc_html_e( 'Restore Backup', 'easy-watermark' ); ?></h3>
45
+ <div class="content">
46
+ <p><?php esc_html_e( 'Here you can quickly restore backup for all images in Media Library.', 'easy-watermark' ); ?></p>
47
+ <p class="hidden has-backup">
48
+ <?php
49
+ printf(
50
+ /* translators: %s is backed up images count */
51
+ esc_html( _n(
52
+ 'There is %s backed up image in your Media Library.',
53
+ 'There are %s backed up images in your Media Library.',
54
+ $backup_count,
55
+ 'easy-watermark'
56
+ ) ),
57
+ "<span class=\"backup-count\">{$backup_count}</span>" // phpcs:ignore
58
+ );
59
+ ?>
60
+ </p>
61
+ <p class="hidden has-backup"><a href="#" class="button-primary" data-nonce="<?php echo esc_attr( wp_create_nonce( 'restore_backup' ) ); ?>"><?php esc_html_e( 'Restore', 'easy-watermark' ); ?></a><span class="spinner"></span></p>
62
+ <p class="hidden no-backup"><?php esc_html_e( 'There are no backed up images in your Media Library.', 'easy-watermark' ); ?></p>
63
+ </div>
64
+ <p class="status"></p>
65
+ </div>
66
+ </div>
67
+ </div>
src/views/dashboard/pages/watermarks.php CHANGED
@@ -1,50 +1,55 @@
1
- <?php
2
- /**
3
- * Watermarks page content
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- ?>
9
- <div class="watermarks ew-grid">
10
- <?php foreach ( $watermarks as $watermark ) : ?>
11
- <div class="postbox item">
12
- <div class="inside">
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 ); ?>
20
- <?php endif; ?>
21
- </h3>
22
- <div class="watermark-preview">
23
- <?php if ( 'image' === $watermark->type ) : ?>
24
- <?php echo wp_get_attachment_image( $watermark->attachment_id, 'full' ); ?>
25
- <?php else : ?>
26
- <img src="<?php echo esc_attr( site_url( sprintf( 'easy-watermark-preview/text-%s.png', $watermark->ID ) ) ); ?>" />
27
- <?php endif; ?>
28
- </div>
29
- <div class="row-actions">
30
- <?php if ( current_user_can( 'edit_others_watermarks' ) || get_current_user_id() === (int) $watermark->post_author ) : ?>
31
- <?php /* translators: watermark name */ ?>
32
- <span class="edit"><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 esc_html_e( 'Edit', 'easy-watermark' ); ?></a> | </span>
33
- <?php endif; ?>
34
- <?php if ( current_user_can( 'delete_others_watermarks' ) || get_current_user_id() === (int) $watermark->post_author ) : ?>
35
- <?php /* translators: watermark name */ ?>
36
- <span class="delete"><a href="<?php echo esc_url( get_delete_post_link( $watermark->ID, '', true ) ); ?>" class="submitdelete" data-watermark-name="<?php echo esc_attr( $watermark->post_title ); ?>" aria-label="<?php esc_attr_e( sprintf( 'Permanently Delete “%s”', $watermark->post_title ) ); ?>"><?php esc_html_e( 'Delete Permanently', 'easy-watermark' ); ?></a></span>
37
- <?php endif; ?>
38
- </div>
39
- </div>
40
- </div>
41
- <?php endforeach; ?>
42
-
43
- <?php if ( 2 > $watermarks_count && current_user_can( 'edit_watermarks' ) ) : ?>
44
- <div class="postbox item">
45
- <div class="inside">
46
- <a href="<?php echo esc_url( admin_url( 'post-new.php?post_type=watermark' ) ); ?>" class="button button-primary button-hero"><?php esc_html_e( 'Add New Watermark', 'easy-watermark' ); ?></a>
47
- </div>
48
- </div>
49
- <?php endif; ?>
50
- </div>
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Watermarks page content
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ use EasyWatermark\Features\WatermarkPreview;
9
+
10
+ ?>
11
+ <div class="watermarks ew-grid">
12
+ <?php foreach ( $watermarks as $watermark ) : ?>
13
+ <div class="postbox item">
14
+ <div class="inside">
15
+ <?php /* translators: watermark name */ ?>
16
+ <h3>
17
+ <?php if ( current_user_can( 'edit_others_watermarks' ) || get_current_user_id() === (int) $watermark->post_author ) : ?>
18
+ <?php /* translators: %s is watermark title */ ?>
19
+ <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>
20
+ <?php else : ?>
21
+ <?php echo esc_html( $watermark->post_title ); ?>
22
+ <?php endif; ?>
23
+ </h3>
24
+ <div class="watermark-preview">
25
+ <?php if ( 'image' === $watermark->type ) : ?>
26
+ <?php $opacity = $watermark->opacity / 100; ?>
27
+ <div class="image-wrap" style="opacity: <?php echo esc_attr( $opacity ); ?>">
28
+ <?php echo wp_get_attachment_image( $watermark->attachment_id, 'full' ); ?>
29
+ </div>
30
+ <?php else : ?>
31
+ <img src="<?php echo esc_url( WatermarkPreview::get_url( 'text', $watermark->ID ) ); ?>" />
32
+ <?php endif; ?>
33
+ </div>
34
+ <div class="row-actions">
35
+ <?php if ( current_user_can( 'edit_others_watermarks' ) || get_current_user_id() === (int) $watermark->post_author ) : ?>
36
+ <?php /* translators: watermark name */ ?>
37
+ <span class="edit"><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 esc_html_e( 'Edit', 'easy-watermark' ); ?></a> | </span>
38
+ <?php endif; ?>
39
+ <?php if ( current_user_can( 'delete_others_watermarks' ) || get_current_user_id() === (int) $watermark->post_author ) : ?>
40
+ <?php /* translators: watermark name */ ?>
41
+ <span class="delete"><a href="<?php echo esc_url( get_delete_post_link( $watermark->ID, '', true ) ); ?>" class="submitdelete" data-watermark-name="<?php echo esc_attr( $watermark->post_title ); ?>" aria-label="<?php esc_attr_e( sprintf( 'Permanently Delete “%s”', $watermark->post_title ) ); ?>"><?php esc_html_e( 'Delete Permanently', 'easy-watermark' ); ?></a></span>
42
+ <?php endif; ?>
43
+ </div>
44
+ </div>
45
+ </div>
46
+ <?php endforeach; ?>
47
+
48
+ <?php if ( 2 > $watermarks_count && current_user_can( 'edit_watermarks' ) ) : ?>
49
+ <div class="postbox item">
50
+ <div class="inside">
51
+ <a href="<?php echo esc_url( admin_url( 'post-new.php?post_type=watermark' ) ); ?>" class="button button-primary button-hero"><?php esc_html_e( 'Add New Watermark', 'easy-watermark' ); ?></a>
52
+ </div>
53
+ </div>
54
+ <?php endif; ?>
55
+ </div>
src/views/edit-screen/metaboxes/watermark/preview.php CHANGED
@@ -1,19 +1,21 @@
1
- <?php
2
- /**
3
- * Preview metabox
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- ?>
9
- <div class="preview-metabox">
10
- <span class="spinner"></span>
11
- <p class="image-selector">
12
- <a href="#" class="select-preview-image" data-choose="<?php esc_attr_e( 'Choose preview image', 'easy-watermark' ); ?>" data-button-label="<?php esc_attr_e( 'Set as preview image', 'easy-watermark' ); ?>" data-change-label="<?php echo esc_attr( $change_label ); ?>"><?php echo esc_html( $link_label ); ?></a>
13
- </p>
14
- <div class="content-wrap">
15
- <div class="preview-wrap" data-src="<?php echo esc_attr( site_url( sprintf( 'easy-watermark-preview/image-%s.png', $post->ID ) ) ); ?>" data-has-image="<?php echo esc_attr( $has_image ); ?>"></div>
16
- <p class="description"><?php esc_html_e( 'Click on image to show fullsize preview.', 'easy-watermark' ); ?></p>
17
- </div>
18
- <?php echo $popup; //phpcs:ignore ?>
19
- </div>
 
 
1
+ <?php
2
+ /**
3
+ * Preview metabox
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ use EasyWatermark\Features\WatermarkPreview;
9
+
10
+ ?>
11
+ <div class="preview-metabox">
12
+ <span class="spinner"></span>
13
+ <p class="image-selector">
14
+ <a href="#" class="select-preview-image" data-choose="<?php esc_attr_e( 'Choose preview image', 'easy-watermark' ); ?>" data-button-label="<?php esc_attr_e( 'Set as preview image', 'easy-watermark' ); ?>" data-change-label="<?php echo esc_attr( $change_label ); ?>"><?php echo esc_html( $link_label ); ?></a>
15
+ </p>
16
+ <div class="content-wrap">
17
+ <div class="preview-wrap" data-src="<?php echo esc_url( WatermarkPreview::get_url( 'image', $post->ID ) ); ?>" data-has-image="<?php echo esc_attr( $has_image ); ?>"></div>
18
+ <p class="description"><?php esc_html_e( 'Click on image to show fullsize preview.', 'easy-watermark' ); ?></p>
19
+ </div>
20
+ <?php echo $popup; //phpcs:ignore ?>
21
+ </div>
src/views/edit-screen/metaboxes/watermark/watermark-content.php CHANGED
@@ -1,51 +1,53 @@
1
- <?php
2
- /**
3
- * Watermark content metabox
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- global $post;
9
-
10
- ?>
11
- <div class="watermark-content-metabox">
12
-
13
- <div class="image-content">
14
- <input class="watermark-id" name="watermark[attachment_id]" type="hidden" value="<?php echo esc_html( $attachment_id ); ?>" />
15
- <input class="watermark-url" name="watermark[url]" type="hidden" value="<?php echo esc_attr( $url ); ?>" />
16
- <input class="watermark-mime-type" name="watermark[mime_type]" type="hidden" value="<?php echo esc_attr( $mime_type ); ?>" />
17
-
18
- <div class="select-image-button">
19
- <a class="button-secondary" data-choose="<?php esc_attr_e( 'Choose Watermark Image', 'easy-watermark' ); ?>" data-button-label="<?php esc_attr_e( 'Set as Watermark Image', 'easy-watermark' ); ?>" href="#"><?php esc_html_e( 'Select/Upload Image', 'easy-watermark' ); ?></a>
20
- <p class="description"><?php esc_html_e( 'Note: Opacity can be applied to gif and jpg images only.', 'easy-watermark' ); ?></p>
21
- </div>
22
-
23
- <div class="watermark-image">
24
- <p class="description"><?php esc_html_e( 'Click on image to change it.', 'easy-watermark' ); ?></p>
25
- <img src="<?php echo esc_attr( $url ); ?>" />
26
- <table class="form-table">
27
- <tbody>
28
- <tr>
29
- <th scope="row"><?php esc_html_e( 'Opacity', 'easy-watermark' ); ?></th>
30
- <td>
31
- <div class="form-field">
32
- <input type="number" size="3" min="0" max="100" step="0.1" name="watermark[opacity]" id="opacity" value="<?php echo esc_attr( $opacity ); ?>" />
33
- <div class="form-field-append">
34
- <span class="form-field-text"> %</span>
35
- </div>
36
- </div>
37
- <p class="description opacity-desc hidden"><?php esc_html_e( 'Opacity does not apply to png images.', 'easy-watermark' ); ?></p>
38
- </td>
39
- </tr>
40
- </tbody>
41
- </table>
42
- </div>
43
- </div>
44
-
45
- <div class="text-content">
46
- <input class="watermark-text" name="watermark[text]" type="text" value="<?php echo esc_attr( $text ); ?>" placeholder="<?php esc_attr_e( 'Watermark text', 'easy-watermark' ); ?>" />
47
- <p class="description"><?php esc_html_e( 'You can use placeholders listed in "Placeholders" metabox.', 'easy-watermark' ); ?></p>
48
- <div class="text-preview" data-src="<?php echo esc_attr( site_url( sprintf( 'easy-watermark-preview/text-%s.png', $post->ID ) ) ); ?>"></div>
49
- </div>
50
-
51
- </div>
 
 
1
+ <?php
2
+ /**
3
+ * Watermark content metabox
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ use EasyWatermark\Features\WatermarkPreview;
9
+
10
+ global $post;
11
+
12
+ ?>
13
+ <div class="watermark-content-metabox">
14
+
15
+ <div class="image-content">
16
+ <input class="watermark-id" name="watermark[attachment_id]" type="hidden" value="<?php echo esc_html( $attachment_id ); ?>" />
17
+ <input class="watermark-url" name="watermark[url]" type="hidden" value="<?php echo esc_attr( $url ); ?>" />
18
+ <input class="watermark-mime-type" name="watermark[mime_type]" type="hidden" value="<?php echo esc_attr( $mime_type ); ?>" />
19
+
20
+ <div class="select-image-button">
21
+ <a class="button-secondary" data-choose="<?php esc_attr_e( 'Choose Watermark Image', 'easy-watermark' ); ?>" data-button-label="<?php esc_attr_e( 'Set as Watermark Image', 'easy-watermark' ); ?>" href="#"><?php esc_html_e( 'Select/Upload Image', 'easy-watermark' ); ?></a>
22
+ <p class="description"><?php esc_html_e( 'Note: Opacity can be applied to gif and jpg images only.', 'easy-watermark' ); ?></p>
23
+ </div>
24
+
25
+ <div class="watermark-image">
26
+ <p class="description"><?php esc_html_e( 'Click on image to change it.', 'easy-watermark' ); ?></p>
27
+ <img src="<?php echo esc_attr( $url ); ?>" />
28
+ <table class="form-table">
29
+ <tbody>
30
+ <tr>
31
+ <th scope="row"><?php esc_html_e( 'Opacity', 'easy-watermark' ); ?></th>
32
+ <td>
33
+ <div class="form-field">
34
+ <input type="number" size="3" min="0" max="100" step="0.1" name="watermark[opacity]" id="opacity" value="<?php echo esc_attr( $opacity ); ?>" />
35
+ <div class="form-field-append">
36
+ <span class="form-field-text"> %</span>
37
+ </div>
38
+ </div>
39
+ <p class="description opacity-desc hidden"><?php esc_html_e( 'Opacity does not apply to png images.', 'easy-watermark' ); ?></p>
40
+ </td>
41
+ </tr>
42
+ </tbody>
43
+ </table>
44
+ </div>
45
+ </div>
46
+
47
+ <div class="text-content">
48
+ <input class="watermark-text" name="watermark[text]" type="text" value="<?php echo esc_attr( $text ); ?>" placeholder="<?php esc_attr_e( 'Watermark text', 'easy-watermark' ); ?>" />
49
+ <p class="description"><?php esc_html_e( 'You can use placeholders listed in "Placeholders" metabox.', 'easy-watermark' ); ?></p>
50
+ <div class="text-preview" data-src="<?php echo esc_url( WatermarkPreview::get_url( 'text', $post->ID ) ); ?>"></div>
51
+ </div>
52
+
53
+ </div>
src/views/upload/switch.php CHANGED
@@ -1,15 +1,15 @@
1
- <?php
2
- /**
3
- * Auto Watermark switch
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- ?>
9
-
10
- <div class="ew-watermark-all-switch">
11
- <label class="ew-switch">
12
- <input id="ew-auto-watermark" class="ew-auto-watermark" type="checkbox" name="ew-auto-watermark" checked />
13
- <span class="switch left-aligned"></span> <?php esc_html_e( 'Auto Watermark', 'easy-watermark' ); ?>
14
- </label>
15
- </div>
1
+ <?php
2
+ /**
3
+ * Auto Watermark switch
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ ?>
9
+
10
+ <div class="ew-watermark-all-switch">
11
+ <label class="ew-switch">
12
+ <input id="ew-auto-watermark" class="ew-auto-watermark" type="checkbox" name="ew-auto-watermark" checked />
13
+ <span class="switch left-aligned"></span> <?php esc_html_e( 'Auto Watermark', 'easy-watermark' ); ?>
14
+ </label>
15
+ </div>
vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
- return ComposerAutoloaderInitba2a014f4462bcb6d6aeb5d97a14b1b8::getLoader();
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInit9ea7af8eb9945c998035f76f2b323645::getLoader();
vendor/composer/InstalledVersions.php CHANGED
@@ -14,12 +14,12 @@ class InstalledVersions
14
  private static $installed = array (
15
  'root' =>
16
  array (
17
- 'pretty_version' => '1.0.0+no-version-set',
18
- 'version' => '1.0.0.0',
19
  'aliases' =>
20
  array (
21
  ),
22
- 'reference' => NULL,
23
  'name' => 'szaleq/easy-watermark',
24
  ),
25
  'versions' =>
@@ -51,12 +51,12 @@ private static $installed = array (
51
  ),
52
  'szaleq/easy-watermark' =>
53
  array (
54
- 'pretty_version' => '1.0.0+no-version-set',
55
- 'version' => '1.0.0.0',
56
  'aliases' =>
57
  array (
58
  ),
59
- 'reference' => NULL,
60
  ),
61
  'underdev/requirements' =>
62
  array (
14
  private static $installed = array (
15
  'root' =>
16
  array (
17
+ 'pretty_version' => 'dev-develop',
18
+ 'version' => 'dev-develop',
19
  'aliases' =>
20
  array (
21
  ),
22
+ 'reference' => 'cc407ab07468a7441f58d36d4caab5f23f71b7dc',
23
  'name' => 'szaleq/easy-watermark',
24
  ),
25
  'versions' =>
51
  ),
52
  'szaleq/easy-watermark' =>
53
  array (
54
+ 'pretty_version' => 'dev-develop',
55
+ 'version' => 'dev-develop',
56
  'aliases' =>
57
  array (
58
  ),
59
+ 'reference' => 'cc407ab07468a7441f58d36d4caab5f23f71b7dc',
60
  ),
61
  'underdev/requirements' =>
62
  array (
vendor/composer/autoload_classmap.php CHANGED
@@ -7,5 +7,122 @@ $baseDir = dirname($vendorDir);
7
 
8
  return array(
9
  'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  'underDEV_Requirements' => $vendorDir . '/underdev/requirements/underDEV_Requirements.php',
11
  );
7
 
8
  return array(
9
  'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
10
+ 'Composer\\Installers\\AglInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/AglInstaller.php',
11
+ 'Composer\\Installers\\AnnotateCmsInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/AnnotateCmsInstaller.php',
12
+ 'Composer\\Installers\\BaseInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/BaseInstaller.php',
13
+ 'Composer\\Installers\\CakePHPInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/CakePHPInstaller.php',
14
+ 'Composer\\Installers\\CodeIgniterInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/CodeIgniterInstaller.php',
15
+ 'Composer\\Installers\\CroogoInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/CroogoInstaller.php',
16
+ 'Composer\\Installers\\DrupalInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/DrupalInstaller.php',
17
+ 'Composer\\Installers\\FuelInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/FuelInstaller.php',
18
+ 'Composer\\Installers\\Installer' => $vendorDir . '/composer/installers/src/Composer/Installers/Installer.php',
19
+ 'Composer\\Installers\\JoomlaInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/JoomlaInstaller.php',
20
+ 'Composer\\Installers\\KohanaInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/KohanaInstaller.php',
21
+ 'Composer\\Installers\\LaravelInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/LaravelInstaller.php',
22
+ 'Composer\\Installers\\LithiumInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/LithiumInstaller.php',
23
+ 'Composer\\Installers\\MODULEWorkInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/MODULEWorkInstaller.php',
24
+ 'Composer\\Installers\\MagentoInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/MagentoInstaller.php',
25
+ 'Composer\\Installers\\MakoInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/MakoInstaller.php',
26
+ 'Composer\\Installers\\MediaWikiInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/MediaWikiInstaller.php',
27
+ 'Composer\\Installers\\OxidInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/OxidInstaller.php',
28
+ 'Composer\\Installers\\PPIInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/PPIInstaller.php',
29
+ 'Composer\\Installers\\PhpBBInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/PhpBBInstaller.php',
30
+ 'Composer\\Installers\\SilverStripeInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/SilverStripeInstaller.php',
31
+ 'Composer\\Installers\\Symfony1Installer' => $vendorDir . '/composer/installers/src/Composer/Installers/Symfony1Installer.php',
32
+ 'Composer\\Installers\\TYPO3CmsInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/TYPO3CmsInstaller.php',
33
+ 'Composer\\Installers\\TYPO3FlowInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/TYPO3FlowInstaller.php',
34
+ 'Composer\\Installers\\WordPressInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/WordPressInstaller.php',
35
+ 'Composer\\Installers\\ZendInstaller' => $vendorDir . '/composer/installers/src/Composer/Installers/ZendInstaller.php',
36
+ 'EasyWatermark\\AttachmentProcessor\\AttachmentProcessor' => $baseDir . '/src/classes/AttachmentProcessor/AttachmentProcessor.php',
37
+ 'EasyWatermark\\AttachmentProcessor\\AttachmentProcessorGD' => $baseDir . '/src/classes/AttachmentProcessor/AttachmentProcessorGD.php',
38
+ 'EasyWatermark\\AttachmentProcessor\\Manager' => $baseDir . '/src/classes/AttachmentProcessor/Manager.php',
39
+ 'EasyWatermark\\Backup\\BackupperInterface' => $baseDir . '/src/classes/Backup/BackupperInterface.php',
40
+ 'EasyWatermark\\Backup\\LocalBackupper' => $baseDir . '/src/classes/Backup/LocalBackupper.php',
41
+ 'EasyWatermark\\Backup\\Manager' => $baseDir . '/src/classes/Backup/Manager.php',
42
+ 'EasyWatermark\\Core\\Assets' => $baseDir . '/src/classes/Core/Assets.php',
43
+ 'EasyWatermark\\Core\\Hooks' => $baseDir . '/src/classes/Core/Hooks.php',
44
+ 'EasyWatermark\\Core\\Installer' => $baseDir . '/src/classes/Core/Installer.php',
45
+ 'EasyWatermark\\Core\\Manager' => $baseDir . '/src/classes/Core/Manager.php',
46
+ 'EasyWatermark\\Core\\Plugin' => $baseDir . '/src/classes/Core/Plugin.php',
47
+ 'EasyWatermark\\Core\\View' => $baseDir . '/src/classes/Core/View.php',
48
+ 'EasyWatermark\\Dashboard\\Dashboard' => $baseDir . '/src/classes/Dashboard/Dashboard.php',
49
+ 'EasyWatermark\\Dashboard\\Page' => $baseDir . '/src/classes/Dashboard/Page.php',
50
+ 'EasyWatermark\\Dashboard\\Permissions' => $baseDir . '/src/classes/Dashboard/Permissions.php',
51
+ 'EasyWatermark\\Dashboard\\Settings' => $baseDir . '/src/classes/Dashboard/Settings.php',
52
+ 'EasyWatermark\\Dashboard\\Tools' => $baseDir . '/src/classes/Dashboard/Tools.php',
53
+ 'EasyWatermark\\Dashboard\\Watermarks' => $baseDir . '/src/classes/Dashboard/Watermarks.php',
54
+ 'EasyWatermark\\Features\\AutoWatermarkSwitch' => $baseDir . '/src/classes/Features/AutoWatermarkSwitch.php',
55
+ 'EasyWatermark\\Features\\CacheBusting' => $baseDir . '/src/classes/Features/CacheBusting.php',
56
+ 'EasyWatermark\\Features\\SrcsetFilter' => $baseDir . '/src/classes/Features/SrcsetFilter.php',
57
+ 'EasyWatermark\\Features\\WatermarkPreview' => $baseDir . '/src/classes/Features/WatermarkPreview.php',
58
+ 'EasyWatermark\\Helpers\\Image' => $baseDir . '/src/classes/Helpers/Image.php',
59
+ 'EasyWatermark\\Helpers\\Text' => $baseDir . '/src/classes/Helpers/Text.php',
60
+ 'EasyWatermark\\Metaboxes\\AttachmentMetabox' => $baseDir . '/src/classes/Metaboxes/AttachmentMetabox.php',
61
+ 'EasyWatermark\\Metaboxes\\Attachment\\Watermarks' => $baseDir . '/src/classes/Metaboxes/Attachment/Watermarks.php',
62
+ 'EasyWatermark\\Metaboxes\\Metabox' => $baseDir . '/src/classes/Metaboxes/Metabox.php',
63
+ 'EasyWatermark\\Metaboxes\\WatermarkMetabox' => $baseDir . '/src/classes/Metaboxes/WatermarkMetabox.php',
64
+ 'EasyWatermark\\Metaboxes\\Watermark\\Alignment' => $baseDir . '/src/classes/Metaboxes/Watermark/Alignment.php',
65
+ 'EasyWatermark\\Metaboxes\\Watermark\\ApplyingRules' => $baseDir . '/src/classes/Metaboxes/Watermark/ApplyingRules.php',
66
+ 'EasyWatermark\\Metaboxes\\Watermark\\Placeholders' => $baseDir . '/src/classes/Metaboxes/Watermark/Placeholders.php',
67
+ 'EasyWatermark\\Metaboxes\\Watermark\\Preview' => $baseDir . '/src/classes/Metaboxes/Watermark/Preview.php',
68
+ 'EasyWatermark\\Metaboxes\\Watermark\\Scaling' => $baseDir . '/src/classes/Metaboxes/Watermark/Scaling.php',
69
+ 'EasyWatermark\\Metaboxes\\Watermark\\Submitdiv' => $baseDir . '/src/classes/Metaboxes/Watermark/Submitdiv.php',
70
+ 'EasyWatermark\\Metaboxes\\Watermark\\TextOptions' => $baseDir . '/src/classes/Metaboxes/Watermark/TextOptions.php',
71
+ 'EasyWatermark\\Metaboxes\\Watermark\\WatermarkContent' => $baseDir . '/src/classes/Metaboxes/Watermark/WatermarkContent.php',
72
+ 'EasyWatermark\\Placeholders\\Abstracts\\EmailPlaceholder' => $baseDir . '/src/classes/Placeholders/Abstracts/EmailPlaceholder.php',
73
+ 'EasyWatermark\\Placeholders\\Abstracts\\IntegerPlaceholder' => $baseDir . '/src/classes/Placeholders/Abstracts/IntegerPlaceholder.php',
74
+ 'EasyWatermark\\Placeholders\\Abstracts\\Placeholder' => $baseDir . '/src/classes/Placeholders/Abstracts/Placeholder.php',
75
+ 'EasyWatermark\\Placeholders\\Abstracts\\StringPlaceholder' => $baseDir . '/src/classes/Placeholders/Abstracts/StringPlaceholder.php',
76
+ 'EasyWatermark\\Placeholders\\Abstracts\\UrlPlaceholder' => $baseDir . '/src/classes/Placeholders/Abstracts/UrlPlaceholder.php',
77
+ 'EasyWatermark\\Placeholders\\Attachment\\AttachmentDirectUrl' => $baseDir . '/src/classes/Placeholders/Attachment/AttachmentDirectUrl.php',
78
+ 'EasyWatermark\\Placeholders\\Attachment\\AttachmentHeight' => $baseDir . '/src/classes/Placeholders/Attachment/AttachmentHeight.php',
79
+ 'EasyWatermark\\Placeholders\\Attachment\\AttachmentID' => $baseDir . '/src/classes/Placeholders/Attachment/AttachmentID.php',
80
+ 'EasyWatermark\\Placeholders\\Attachment\\AttachmentMimeType' => $baseDir . '/src/classes/Placeholders/Attachment/AttachmentMimeType.php',
81
+ 'EasyWatermark\\Placeholders\\Attachment\\AttachmentPage' => $baseDir . '/src/classes/Placeholders/Attachment/AttachmentPage.php',
82
+ 'EasyWatermark\\Placeholders\\Attachment\\AttachmentSize' => $baseDir . '/src/classes/Placeholders/Attachment/AttachmentSize.php',
83
+ 'EasyWatermark\\Placeholders\\Attachment\\AttachmentTitle' => $baseDir . '/src/classes/Placeholders/Attachment/AttachmentTitle.php',
84
+ 'EasyWatermark\\Placeholders\\Attachment\\AttachmentUploadDate' => $baseDir . '/src/classes/Placeholders/Attachment/AttachmentUploadDate.php',
85
+ 'EasyWatermark\\Placeholders\\Attachment\\AttachmentWidth' => $baseDir . '/src/classes/Placeholders/Attachment/AttachmentWidth.php',
86
+ 'EasyWatermark\\Placeholders\\Author\\AuthorDisplayName' => $baseDir . '/src/classes/Placeholders/Author/AuthorDisplayName.php',
87
+ 'EasyWatermark\\Placeholders\\Author\\AuthorEmail' => $baseDir . '/src/classes/Placeholders/Author/AuthorEmail.php',
88
+ 'EasyWatermark\\Placeholders\\Author\\AuthorFirstName' => $baseDir . '/src/classes/Placeholders/Author/AuthorFirstName.php',
89
+ 'EasyWatermark\\Placeholders\\Author\\AuthorID' => $baseDir . '/src/classes/Placeholders/Author/AuthorID.php',
90
+ 'EasyWatermark\\Placeholders\\Author\\AuthorLastName' => $baseDir . '/src/classes/Placeholders/Author/AuthorLastName.php',
91
+ 'EasyWatermark\\Placeholders\\Author\\AuthorLogin' => $baseDir . '/src/classes/Placeholders/Author/AuthorLogin.php',
92
+ 'EasyWatermark\\Placeholders\\Author\\AuthorNicename' => $baseDir . '/src/classes/Placeholders/Author/AuthorNicename.php',
93
+ 'EasyWatermark\\Placeholders\\Author\\AuthorRole' => $baseDir . '/src/classes/Placeholders/Author/AuthorRole.php',
94
+ 'EasyWatermark\\Placeholders\\Author\\AuthorUrl' => $baseDir . '/src/classes/Placeholders/Author/AuthorUrl.php',
95
+ 'EasyWatermark\\Placeholders\\Blog\\AdminEmail' => $baseDir . '/src/classes/Placeholders/Blog/AdminEmail.php',
96
+ 'EasyWatermark\\Placeholders\\Blog\\BlogName' => $baseDir . '/src/classes/Placeholders/Blog/BlogName.php',
97
+ 'EasyWatermark\\Placeholders\\Blog\\BlogUrl' => $baseDir . '/src/classes/Placeholders/Blog/BlogUrl.php',
98
+ 'EasyWatermark\\Placeholders\\DateTime\\Date' => $baseDir . '/src/classes/Placeholders/DateTime/Date.php',
99
+ 'EasyWatermark\\Placeholders\\DateTime\\Time' => $baseDir . '/src/classes/Placeholders/DateTime/Time.php',
100
+ 'EasyWatermark\\Placeholders\\Defaults' => $baseDir . '/src/classes/Placeholders/Defaults.php',
101
+ 'EasyWatermark\\Placeholders\\Resolver' => $baseDir . '/src/classes/Placeholders/Resolver.php',
102
+ 'EasyWatermark\\Placeholders\\User\\UserDisplayName' => $baseDir . '/src/classes/Placeholders/User/UserDisplayName.php',
103
+ 'EasyWatermark\\Placeholders\\User\\UserEmail' => $baseDir . '/src/classes/Placeholders/User/UserEmail.php',
104
+ 'EasyWatermark\\Placeholders\\User\\UserFirstName' => $baseDir . '/src/classes/Placeholders/User/UserFirstName.php',
105
+ 'EasyWatermark\\Placeholders\\User\\UserID' => $baseDir . '/src/classes/Placeholders/User/UserID.php',
106
+ 'EasyWatermark\\Placeholders\\User\\UserLastName' => $baseDir . '/src/classes/Placeholders/User/UserLastName.php',
107
+ 'EasyWatermark\\Placeholders\\User\\UserLogin' => $baseDir . '/src/classes/Placeholders/User/UserLogin.php',
108
+ 'EasyWatermark\\Placeholders\\User\\UserNicename' => $baseDir . '/src/classes/Placeholders/User/UserNicename.php',
109
+ 'EasyWatermark\\Placeholders\\User\\UserRole' => $baseDir . '/src/classes/Placeholders/User/UserRole.php',
110
+ 'EasyWatermark\\Placeholders\\User\\UserUrl' => $baseDir . '/src/classes/Placeholders/User/UserUrl.php',
111
+ 'EasyWatermark\\Settings\\Field' => $baseDir . '/src/classes/Settings/Field.php',
112
+ 'EasyWatermark\\Settings\\Fields\\Checkbox' => $baseDir . '/src/classes/Settings/Fields/Checkbox.php',
113
+ 'EasyWatermark\\Settings\\Fields\\Dropdown' => $baseDir . '/src/classes/Settings/Fields/Dropdown.php',
114
+ 'EasyWatermark\\Settings\\Fields\\Number' => $baseDir . '/src/classes/Settings/Fields/Number.php',
115
+ 'EasyWatermark\\Settings\\Fields\\SwitchField' => $baseDir . '/src/classes/Settings/Fields/SwitchField.php',
116
+ 'EasyWatermark\\Settings\\Fields\\Text' => $baseDir . '/src/classes/Settings/Fields/Text.php',
117
+ 'EasyWatermark\\Settings\\Section' => $baseDir . '/src/classes/Settings/Section.php',
118
+ 'EasyWatermark\\Settings\\Settings' => $baseDir . '/src/classes/Settings/Settings.php',
119
+ 'EasyWatermark\\Traits\\Hookable' => $baseDir . '/src/classes/Traits/Hookable.php',
120
+ 'EasyWatermark\\Watermark\\Ajax' => $baseDir . '/src/classes/Watermark/Ajax.php',
121
+ 'EasyWatermark\\Watermark\\Handler' => $baseDir . '/src/classes/Watermark/Handler.php',
122
+ 'EasyWatermark\\Watermark\\Hooks' => $baseDir . '/src/classes/Watermark/Hooks.php',
123
+ 'EasyWatermark\\Watermark\\PostType' => $baseDir . '/src/classes/Watermark/PostType.php',
124
+ 'EasyWatermark\\Watermark\\Preview' => $baseDir . '/src/classes/Watermark/Preview.php',
125
+ 'EasyWatermark\\Watermark\\Watermark' => $baseDir . '/src/classes/Watermark/Watermark.php',
126
+ 'Micropackage\\Singleton\\Singleton' => $vendorDir . '/micropackage/singleton/src/Singleton.php',
127
  'underDEV_Requirements' => $vendorDir . '/underdev/requirements/underDEV_Requirements.php',
128
  );
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInitba2a014f4462bcb6d6aeb5d97a14b1b8
6
  {
7
  private static $loader;
8
 
@@ -24,15 +24,15 @@ class ComposerAutoloaderInitba2a014f4462bcb6d6aeb5d97a14b1b8
24
 
25
  require __DIR__ . '/platform_check.php';
26
 
27
- spl_autoload_register(array('ComposerAutoloaderInitba2a014f4462bcb6d6aeb5d97a14b1b8', 'loadClassLoader'), true, true);
28
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
29
- spl_autoload_unregister(array('ComposerAutoloaderInitba2a014f4462bcb6d6aeb5d97a14b1b8', 'loadClassLoader'));
30
 
31
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
32
  if ($useStaticLoader) {
33
  require __DIR__ . '/autoload_static.php';
34
 
35
- call_user_func(\Composer\Autoload\ComposerStaticInitba2a014f4462bcb6d6aeb5d97a14b1b8::getInitializer($loader));
36
  } else {
37
  $map = require __DIR__ . '/autoload_namespaces.php';
38
  foreach ($map as $namespace => $path) {
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
+ class ComposerAutoloaderInit9ea7af8eb9945c998035f76f2b323645
6
  {
7
  private static $loader;
8
 
24
 
25
  require __DIR__ . '/platform_check.php';
26
 
27
+ spl_autoload_register(array('ComposerAutoloaderInit9ea7af8eb9945c998035f76f2b323645', 'loadClassLoader'), true, true);
28
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
29
+ spl_autoload_unregister(array('ComposerAutoloaderInit9ea7af8eb9945c998035f76f2b323645', 'loadClassLoader'));
30
 
31
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
32
  if ($useStaticLoader) {
33
  require __DIR__ . '/autoload_static.php';
34
 
35
+ call_user_func(\Composer\Autoload\ComposerStaticInit9ea7af8eb9945c998035f76f2b323645::getInitializer($loader));
36
  } else {
37
  $map = require __DIR__ . '/autoload_namespaces.php';
38
  foreach ($map as $namespace => $path) {
vendor/composer/autoload_static.php CHANGED
@@ -4,7 +4,7 @@
4
 
5
  namespace Composer\Autoload;
6
 
7
- class ComposerStaticInitba2a014f4462bcb6d6aeb5d97a14b1b8
8
  {
9
  public static $prefixLengthsPsr4 = array (
10
  'M' =>
@@ -40,16 +40,133 @@ class ComposerStaticInitba2a014f4462bcb6d6aeb5d97a14b1b8
40
 
41
  public static $classMap = array (
42
  'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  'underDEV_Requirements' => __DIR__ . '/..' . '/underdev/requirements/underDEV_Requirements.php',
44
  );
45
 
46
  public static function getInitializer(ClassLoader $loader)
47
  {
48
  return \Closure::bind(function () use ($loader) {
49
- $loader->prefixLengthsPsr4 = ComposerStaticInitba2a014f4462bcb6d6aeb5d97a14b1b8::$prefixLengthsPsr4;
50
- $loader->prefixDirsPsr4 = ComposerStaticInitba2a014f4462bcb6d6aeb5d97a14b1b8::$prefixDirsPsr4;
51
- $loader->prefixesPsr0 = ComposerStaticInitba2a014f4462bcb6d6aeb5d97a14b1b8::$prefixesPsr0;
52
- $loader->classMap = ComposerStaticInitba2a014f4462bcb6d6aeb5d97a14b1b8::$classMap;
53
 
54
  }, null, ClassLoader::class);
55
  }
4
 
5
  namespace Composer\Autoload;
6
 
7
+ class ComposerStaticInit9ea7af8eb9945c998035f76f2b323645
8
  {
9
  public static $prefixLengthsPsr4 = array (
10
  'M' =>
40
 
41
  public static $classMap = array (
42
  'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
43
+ 'Composer\\Installers\\AglInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/AglInstaller.php',
44
+ 'Composer\\Installers\\AnnotateCmsInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/AnnotateCmsInstaller.php',
45
+ 'Composer\\Installers\\BaseInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/BaseInstaller.php',
46
+ 'Composer\\Installers\\CakePHPInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/CakePHPInstaller.php',
47
+ 'Composer\\Installers\\CodeIgniterInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/CodeIgniterInstaller.php',
48
+ 'Composer\\Installers\\CroogoInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/CroogoInstaller.php',
49
+ 'Composer\\Installers\\DrupalInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/DrupalInstaller.php',
50
+ 'Composer\\Installers\\FuelInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/FuelInstaller.php',
51
+ 'Composer\\Installers\\Installer' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/Installer.php',
52
+ 'Composer\\Installers\\JoomlaInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/JoomlaInstaller.php',
53
+ 'Composer\\Installers\\KohanaInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/KohanaInstaller.php',
54
+ 'Composer\\Installers\\LaravelInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/LaravelInstaller.php',
55
+ 'Composer\\Installers\\LithiumInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/LithiumInstaller.php',
56
+ 'Composer\\Installers\\MODULEWorkInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/MODULEWorkInstaller.php',
57
+ 'Composer\\Installers\\MagentoInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/MagentoInstaller.php',
58
+ 'Composer\\Installers\\MakoInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/MakoInstaller.php',
59
+ 'Composer\\Installers\\MediaWikiInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/MediaWikiInstaller.php',
60
+ 'Composer\\Installers\\OxidInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/OxidInstaller.php',
61
+ 'Composer\\Installers\\PPIInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/PPIInstaller.php',
62
+ 'Composer\\Installers\\PhpBBInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/PhpBBInstaller.php',
63
+ 'Composer\\Installers\\SilverStripeInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/SilverStripeInstaller.php',
64
+ 'Composer\\Installers\\Symfony1Installer' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/Symfony1Installer.php',
65
+ 'Composer\\Installers\\TYPO3CmsInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/TYPO3CmsInstaller.php',
66
+ 'Composer\\Installers\\TYPO3FlowInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/TYPO3FlowInstaller.php',
67
+ 'Composer\\Installers\\WordPressInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/WordPressInstaller.php',
68
+ 'Composer\\Installers\\ZendInstaller' => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers/ZendInstaller.php',
69
+ 'EasyWatermark\\AttachmentProcessor\\AttachmentProcessor' => __DIR__ . '/../..' . '/src/classes/AttachmentProcessor/AttachmentProcessor.php',
70
+ 'EasyWatermark\\AttachmentProcessor\\AttachmentProcessorGD' => __DIR__ . '/../..' . '/src/classes/AttachmentProcessor/AttachmentProcessorGD.php',
71
+ 'EasyWatermark\\AttachmentProcessor\\Manager' => __DIR__ . '/../..' . '/src/classes/AttachmentProcessor/Manager.php',
72
+ 'EasyWatermark\\Backup\\BackupperInterface' => __DIR__ . '/../..' . '/src/classes/Backup/BackupperInterface.php',
73
+ 'EasyWatermark\\Backup\\LocalBackupper' => __DIR__ . '/../..' . '/src/classes/Backup/LocalBackupper.php',
74
+ 'EasyWatermark\\Backup\\Manager' => __DIR__ . '/../..' . '/src/classes/Backup/Manager.php',
75
+ 'EasyWatermark\\Core\\Assets' => __DIR__ . '/../..' . '/src/classes/Core/Assets.php',
76
+ 'EasyWatermark\\Core\\Hooks' => __DIR__ . '/../..' . '/src/classes/Core/Hooks.php',
77
+ 'EasyWatermark\\Core\\Installer' => __DIR__ . '/../..' . '/src/classes/Core/Installer.php',
78
+ 'EasyWatermark\\Core\\Manager' => __DIR__ . '/../..' . '/src/classes/Core/Manager.php',
79
+ 'EasyWatermark\\Core\\Plugin' => __DIR__ . '/../..' . '/src/classes/Core/Plugin.php',
80
+ 'EasyWatermark\\Core\\View' => __DIR__ . '/../..' . '/src/classes/Core/View.php',
81
+ 'EasyWatermark\\Dashboard\\Dashboard' => __DIR__ . '/../..' . '/src/classes/Dashboard/Dashboard.php',
82
+ 'EasyWatermark\\Dashboard\\Page' => __DIR__ . '/../..' . '/src/classes/Dashboard/Page.php',
83
+ 'EasyWatermark\\Dashboard\\Permissions' => __DIR__ . '/../..' . '/src/classes/Dashboard/Permissions.php',
84
+ 'EasyWatermark\\Dashboard\\Settings' => __DIR__ . '/../..' . '/src/classes/Dashboard/Settings.php',
85
+ 'EasyWatermark\\Dashboard\\Tools' => __DIR__ . '/../..' . '/src/classes/Dashboard/Tools.php',
86
+ 'EasyWatermark\\Dashboard\\Watermarks' => __DIR__ . '/../..' . '/src/classes/Dashboard/Watermarks.php',
87
+ 'EasyWatermark\\Features\\AutoWatermarkSwitch' => __DIR__ . '/../..' . '/src/classes/Features/AutoWatermarkSwitch.php',
88
+ 'EasyWatermark\\Features\\CacheBusting' => __DIR__ . '/../..' . '/src/classes/Features/CacheBusting.php',
89
+ 'EasyWatermark\\Features\\SrcsetFilter' => __DIR__ . '/../..' . '/src/classes/Features/SrcsetFilter.php',
90
+ 'EasyWatermark\\Features\\WatermarkPreview' => __DIR__ . '/../..' . '/src/classes/Features/WatermarkPreview.php',
91
+ 'EasyWatermark\\Helpers\\Image' => __DIR__ . '/../..' . '/src/classes/Helpers/Image.php',
92
+ 'EasyWatermark\\Helpers\\Text' => __DIR__ . '/../..' . '/src/classes/Helpers/Text.php',
93
+ 'EasyWatermark\\Metaboxes\\AttachmentMetabox' => __DIR__ . '/../..' . '/src/classes/Metaboxes/AttachmentMetabox.php',
94
+ 'EasyWatermark\\Metaboxes\\Attachment\\Watermarks' => __DIR__ . '/../..' . '/src/classes/Metaboxes/Attachment/Watermarks.php',
95
+ 'EasyWatermark\\Metaboxes\\Metabox' => __DIR__ . '/../..' . '/src/classes/Metaboxes/Metabox.php',
96
+ 'EasyWatermark\\Metaboxes\\WatermarkMetabox' => __DIR__ . '/../..' . '/src/classes/Metaboxes/WatermarkMetabox.php',
97
+ 'EasyWatermark\\Metaboxes\\Watermark\\Alignment' => __DIR__ . '/../..' . '/src/classes/Metaboxes/Watermark/Alignment.php',
98
+ 'EasyWatermark\\Metaboxes\\Watermark\\ApplyingRules' => __DIR__ . '/../..' . '/src/classes/Metaboxes/Watermark/ApplyingRules.php',
99
+ 'EasyWatermark\\Metaboxes\\Watermark\\Placeholders' => __DIR__ . '/../..' . '/src/classes/Metaboxes/Watermark/Placeholders.php',
100
+ 'EasyWatermark\\Metaboxes\\Watermark\\Preview' => __DIR__ . '/../..' . '/src/classes/Metaboxes/Watermark/Preview.php',
101
+ 'EasyWatermark\\Metaboxes\\Watermark\\Scaling' => __DIR__ . '/../..' . '/src/classes/Metaboxes/Watermark/Scaling.php',
102
+ 'EasyWatermark\\Metaboxes\\Watermark\\Submitdiv' => __DIR__ . '/../..' . '/src/classes/Metaboxes/Watermark/Submitdiv.php',
103
+ 'EasyWatermark\\Metaboxes\\Watermark\\TextOptions' => __DIR__ . '/../..' . '/src/classes/Metaboxes/Watermark/TextOptions.php',
104
+ 'EasyWatermark\\Metaboxes\\Watermark\\WatermarkContent' => __DIR__ . '/../..' . '/src/classes/Metaboxes/Watermark/WatermarkContent.php',
105
+ 'EasyWatermark\\Placeholders\\Abstracts\\EmailPlaceholder' => __DIR__ . '/../..' . '/src/classes/Placeholders/Abstracts/EmailPlaceholder.php',
106
+ 'EasyWatermark\\Placeholders\\Abstracts\\IntegerPlaceholder' => __DIR__ . '/../..' . '/src/classes/Placeholders/Abstracts/IntegerPlaceholder.php',
107
+ 'EasyWatermark\\Placeholders\\Abstracts\\Placeholder' => __DIR__ . '/../..' . '/src/classes/Placeholders/Abstracts/Placeholder.php',
108
+ 'EasyWatermark\\Placeholders\\Abstracts\\StringPlaceholder' => __DIR__ . '/../..' . '/src/classes/Placeholders/Abstracts/StringPlaceholder.php',
109
+ 'EasyWatermark\\Placeholders\\Abstracts\\UrlPlaceholder' => __DIR__ . '/../..' . '/src/classes/Placeholders/Abstracts/UrlPlaceholder.php',
110
+ 'EasyWatermark\\Placeholders\\Attachment\\AttachmentDirectUrl' => __DIR__ . '/../..' . '/src/classes/Placeholders/Attachment/AttachmentDirectUrl.php',
111
+ 'EasyWatermark\\Placeholders\\Attachment\\AttachmentHeight' => __DIR__ . '/../..' . '/src/classes/Placeholders/Attachment/AttachmentHeight.php',
112
+ 'EasyWatermark\\Placeholders\\Attachment\\AttachmentID' => __DIR__ . '/../..' . '/src/classes/Placeholders/Attachment/AttachmentID.php',
113
+ 'EasyWatermark\\Placeholders\\Attachment\\AttachmentMimeType' => __DIR__ . '/../..' . '/src/classes/Placeholders/Attachment/AttachmentMimeType.php',
114
+ 'EasyWatermark\\Placeholders\\Attachment\\AttachmentPage' => __DIR__ . '/../..' . '/src/classes/Placeholders/Attachment/AttachmentPage.php',
115
+ 'EasyWatermark\\Placeholders\\Attachment\\AttachmentSize' => __DIR__ . '/../..' . '/src/classes/Placeholders/Attachment/AttachmentSize.php',
116
+ 'EasyWatermark\\Placeholders\\Attachment\\AttachmentTitle' => __DIR__ . '/../..' . '/src/classes/Placeholders/Attachment/AttachmentTitle.php',
117
+ 'EasyWatermark\\Placeholders\\Attachment\\AttachmentUploadDate' => __DIR__ . '/../..' . '/src/classes/Placeholders/Attachment/AttachmentUploadDate.php',
118
+ 'EasyWatermark\\Placeholders\\Attachment\\AttachmentWidth' => __DIR__ . '/../..' . '/src/classes/Placeholders/Attachment/AttachmentWidth.php',
119
+ 'EasyWatermark\\Placeholders\\Author\\AuthorDisplayName' => __DIR__ . '/../..' . '/src/classes/Placeholders/Author/AuthorDisplayName.php',
120
+ 'EasyWatermark\\Placeholders\\Author\\AuthorEmail' => __DIR__ . '/../..' . '/src/classes/Placeholders/Author/AuthorEmail.php',
121
+ 'EasyWatermark\\Placeholders\\Author\\AuthorFirstName' => __DIR__ . '/../..' . '/src/classes/Placeholders/Author/AuthorFirstName.php',
122
+ 'EasyWatermark\\Placeholders\\Author\\AuthorID' => __DIR__ . '/../..' . '/src/classes/Placeholders/Author/AuthorID.php',
123
+ 'EasyWatermark\\Placeholders\\Author\\AuthorLastName' => __DIR__ . '/../..' . '/src/classes/Placeholders/Author/AuthorLastName.php',
124
+ 'EasyWatermark\\Placeholders\\Author\\AuthorLogin' => __DIR__ . '/../..' . '/src/classes/Placeholders/Author/AuthorLogin.php',
125
+ 'EasyWatermark\\Placeholders\\Author\\AuthorNicename' => __DIR__ . '/../..' . '/src/classes/Placeholders/Author/AuthorNicename.php',
126
+ 'EasyWatermark\\Placeholders\\Author\\AuthorRole' => __DIR__ . '/../..' . '/src/classes/Placeholders/Author/AuthorRole.php',
127
+ 'EasyWatermark\\Placeholders\\Author\\AuthorUrl' => __DIR__ . '/../..' . '/src/classes/Placeholders/Author/AuthorUrl.php',
128
+ 'EasyWatermark\\Placeholders\\Blog\\AdminEmail' => __DIR__ . '/../..' . '/src/classes/Placeholders/Blog/AdminEmail.php',
129
+ 'EasyWatermark\\Placeholders\\Blog\\BlogName' => __DIR__ . '/../..' . '/src/classes/Placeholders/Blog/BlogName.php',
130
+ 'EasyWatermark\\Placeholders\\Blog\\BlogUrl' => __DIR__ . '/../..' . '/src/classes/Placeholders/Blog/BlogUrl.php',
131
+ 'EasyWatermark\\Placeholders\\DateTime\\Date' => __DIR__ . '/../..' . '/src/classes/Placeholders/DateTime/Date.php',
132
+ 'EasyWatermark\\Placeholders\\DateTime\\Time' => __DIR__ . '/../..' . '/src/classes/Placeholders/DateTime/Time.php',
133
+ 'EasyWatermark\\Placeholders\\Defaults' => __DIR__ . '/../..' . '/src/classes/Placeholders/Defaults.php',
134
+ 'EasyWatermark\\Placeholders\\Resolver' => __DIR__ . '/../..' . '/src/classes/Placeholders/Resolver.php',
135
+ 'EasyWatermark\\Placeholders\\User\\UserDisplayName' => __DIR__ . '/../..' . '/src/classes/Placeholders/User/UserDisplayName.php',
136
+ 'EasyWatermark\\Placeholders\\User\\UserEmail' => __DIR__ . '/../..' . '/src/classes/Placeholders/User/UserEmail.php',
137
+ 'EasyWatermark\\Placeholders\\User\\UserFirstName' => __DIR__ . '/../..' . '/src/classes/Placeholders/User/UserFirstName.php',
138
+ 'EasyWatermark\\Placeholders\\User\\UserID' => __DIR__ . '/../..' . '/src/classes/Placeholders/User/UserID.php',
139
+ 'EasyWatermark\\Placeholders\\User\\UserLastName' => __DIR__ . '/../..' . '/src/classes/Placeholders/User/UserLastName.php',
140
+ 'EasyWatermark\\Placeholders\\User\\UserLogin' => __DIR__ . '/../..' . '/src/classes/Placeholders/User/UserLogin.php',
141
+ 'EasyWatermark\\Placeholders\\User\\UserNicename' => __DIR__ . '/../..' . '/src/classes/Placeholders/User/UserNicename.php',
142
+ 'EasyWatermark\\Placeholders\\User\\UserRole' => __DIR__ . '/../..' . '/src/classes/Placeholders/User/UserRole.php',
143
+ 'EasyWatermark\\Placeholders\\User\\UserUrl' => __DIR__ . '/../..' . '/src/classes/Placeholders/User/UserUrl.php',
144
+ 'EasyWatermark\\Settings\\Field' => __DIR__ . '/../..' . '/src/classes/Settings/Field.php',
145
+ 'EasyWatermark\\Settings\\Fields\\Checkbox' => __DIR__ . '/../..' . '/src/classes/Settings/Fields/Checkbox.php',
146
+ 'EasyWatermark\\Settings\\Fields\\Dropdown' => __DIR__ . '/../..' . '/src/classes/Settings/Fields/Dropdown.php',
147
+ 'EasyWatermark\\Settings\\Fields\\Number' => __DIR__ . '/../..' . '/src/classes/Settings/Fields/Number.php',
148
+ 'EasyWatermark\\Settings\\Fields\\SwitchField' => __DIR__ . '/../..' . '/src/classes/Settings/Fields/SwitchField.php',
149
+ 'EasyWatermark\\Settings\\Fields\\Text' => __DIR__ . '/../..' . '/src/classes/Settings/Fields/Text.php',
150
+ 'EasyWatermark\\Settings\\Section' => __DIR__ . '/../..' . '/src/classes/Settings/Section.php',
151
+ 'EasyWatermark\\Settings\\Settings' => __DIR__ . '/../..' . '/src/classes/Settings/Settings.php',
152
+ 'EasyWatermark\\Traits\\Hookable' => __DIR__ . '/../..' . '/src/classes/Traits/Hookable.php',
153
+ 'EasyWatermark\\Watermark\\Ajax' => __DIR__ . '/../..' . '/src/classes/Watermark/Ajax.php',
154
+ 'EasyWatermark\\Watermark\\Handler' => __DIR__ . '/../..' . '/src/classes/Watermark/Handler.php',
155
+ 'EasyWatermark\\Watermark\\Hooks' => __DIR__ . '/../..' . '/src/classes/Watermark/Hooks.php',
156
+ 'EasyWatermark\\Watermark\\PostType' => __DIR__ . '/../..' . '/src/classes/Watermark/PostType.php',
157
+ 'EasyWatermark\\Watermark\\Preview' => __DIR__ . '/../..' . '/src/classes/Watermark/Preview.php',
158
+ 'EasyWatermark\\Watermark\\Watermark' => __DIR__ . '/../..' . '/src/classes/Watermark/Watermark.php',
159
+ 'Micropackage\\Singleton\\Singleton' => __DIR__ . '/..' . '/micropackage/singleton/src/Singleton.php',
160
  'underDEV_Requirements' => __DIR__ . '/..' . '/underdev/requirements/underDEV_Requirements.php',
161
  );
162
 
163
  public static function getInitializer(ClassLoader $loader)
164
  {
165
  return \Closure::bind(function () use ($loader) {
166
+ $loader->prefixLengthsPsr4 = ComposerStaticInit9ea7af8eb9945c998035f76f2b323645::$prefixLengthsPsr4;
167
+ $loader->prefixDirsPsr4 = ComposerStaticInit9ea7af8eb9945c998035f76f2b323645::$prefixDirsPsr4;
168
+ $loader->prefixesPsr0 = ComposerStaticInit9ea7af8eb9945c998035f76f2b323645::$prefixesPsr0;
169
+ $loader->classMap = ComposerStaticInit9ea7af8eb9945c998035f76f2b323645::$classMap;
170
 
171
  }, null, ClassLoader::class);
172
  }
vendor/composer/installed.php CHANGED
@@ -1,12 +1,12 @@
1
  <?php return array (
2
  'root' =>
3
  array (
4
- 'pretty_version' => '1.0.0+no-version-set',
5
- 'version' => '1.0.0.0',
6
  'aliases' =>
7
  array (
8
  ),
9
- 'reference' => NULL,
10
  'name' => 'szaleq/easy-watermark',
11
  ),
12
  'versions' =>
@@ -38,12 +38,12 @@
38
  ),
39
  'szaleq/easy-watermark' =>
40
  array (
41
- 'pretty_version' => '1.0.0+no-version-set',
42
- 'version' => '1.0.0.0',
43
  'aliases' =>
44
  array (
45
  ),
46
- 'reference' => NULL,
47
  ),
48
  'underdev/requirements' =>
49
  array (
1
  <?php return array (
2
  'root' =>
3
  array (
4
+ 'pretty_version' => 'dev-develop',
5
+ 'version' => 'dev-develop',
6
  'aliases' =>
7
  array (
8
  ),
9
+ 'reference' => 'cc407ab07468a7441f58d36d4caab5f23f71b7dc',
10
  'name' => 'szaleq/easy-watermark',
11
  ),
12
  'versions' =>
38
  ),
39
  'szaleq/easy-watermark' =>
40
  array (
41
+ 'pretty_version' => 'dev-develop',
42
+ 'version' => 'dev-develop',
43
  'aliases' =>
44
  array (
45
  ),
46
+ 'reference' => 'cc407ab07468a7441f58d36d4caab5f23f71b7dc',
47
  ),
48
  'underdev/requirements' =>
49
  array (