Easy Watermark - Version 1.0.9

Version Description

  • [Fixed] Translated view file names causing missing view errors.
  • [Fixed] Errors occuring on the first plugin activation.
Download this release

Release Info

Developer bracketspace
Plugin Icon Easy Watermark
Version 1.0.9
Comparing to
See all releases

Code changes from version 1.0.8 to 1.0.9

Files changed (163) hide show
  1. .distignore +20 -0
  2. .github/workflows/legacy-develop.yml +104 -0
  3. .github/workflows/legacy-stable.yml +185 -0
  4. .github/workflows/release.yml +69 -0
  5. .github/workflows/test.yml +75 -0
  6. assets/dist/scripts/attachment-edit.js +1 -1
  7. assets/dist/scripts/dashboard.js +2 -2
  8. assets/dist/scripts/media-library.js +1 -1
  9. assets/dist/scripts/uploader.js +1 -1
  10. assets/dist/scripts/watermark-edit.js +2 -2
  11. assets/src/fonts/Arial.ttf +0 -0
  12. assets/src/fonts/Arial_Black.ttf +0 -0
  13. assets/src/fonts/Comic_Sans_MS.ttf +0 -0
  14. assets/src/fonts/Courier_New.ttf +0 -0
  15. assets/src/fonts/Georgia.ttf +0 -0
  16. assets/src/fonts/Impact.ttf +0 -0
  17. assets/src/fonts/Tahoma.ttf +0 -0
  18. assets/src/fonts/Times_New_Roman.ttf +0 -0
  19. assets/src/fonts/Trebuchet_MS.ttf +0 -0
  20. assets/src/fonts/Verdana.ttf +0 -0
  21. assets/src/images/alignment-background.jpg +0 -0
  22. assets/src/scripts/attachment-edit.js +0 -8
  23. assets/src/scripts/controllers/bulk-actions.js +0 -322
  24. assets/src/scripts/controllers/media-frame.js +0 -211
  25. assets/src/scripts/dashboard.js +0 -29
  26. assets/src/scripts/includes/vex.js +0 -56
  27. assets/src/scripts/media-library.js +0 -11
  28. assets/src/scripts/metaboxes/attachment/watermarks.js +0 -83
  29. assets/src/scripts/metaboxes/watermark/alignment.js +0 -14
  30. assets/src/scripts/metaboxes/watermark/applying-rules.js +0 -30
  31. assets/src/scripts/metaboxes/watermark/content.js +0 -193
  32. assets/src/scripts/metaboxes/watermark/placeholders.js +0 -52
  33. assets/src/scripts/metaboxes/watermark/preview.js +0 -171
  34. assets/src/scripts/metaboxes/watermark/scaling.js +0 -44
  35. assets/src/scripts/metaboxes/watermark/text-options.js +0 -40
  36. assets/src/scripts/pages/bulk-actions.js +0 -322
  37. assets/src/scripts/pages/settings.js +0 -38
  38. assets/src/scripts/pages/tools.js +0 -192
  39. assets/src/scripts/pages/watermarks.js +0 -44
  40. assets/src/scripts/uploader.js +0 -49
  41. assets/src/scripts/utils/form-fields.js +0 -64
  42. assets/src/scripts/utils/functions.js +0 -79
  43. assets/src/scripts/views/media-grid/attachment.js +0 -100
  44. assets/src/scripts/views/media-grid/attachments-browser.js +0 -89
  45. assets/src/scripts/views/media-grid/buttons/restore.js +0 -66
  46. assets/src/scripts/views/media-grid/buttons/watermark-mode-toggle.js +0 -79
  47. assets/src/scripts/views/media-grid/buttons/watermark.js +0 -51
  48. assets/src/scripts/views/media-grid/filters.js +0 -45
  49. assets/src/scripts/views/media-grid/select-mode-toggle.js +0 -32
  50. assets/src/scripts/views/media-grid/status.js +0 -66
  51. assets/src/scripts/views/media-grid/watermark-selector.js +0 -70
  52. assets/src/scripts/views/media-list/attachment.js +0 -76
  53. assets/src/scripts/views/media-list/status.js +0 -72
  54. assets/src/scripts/views/media-list/view.js +0 -13
  55. assets/src/scripts/views/media-list/watermark-selector.js +0 -79
  56. assets/src/scripts/views/tools/bulk-watermark.js +0 -58
  57. assets/src/scripts/views/tools/restore.js +0 -50
  58. assets/src/scripts/views/tools/tool.js +0 -92
  59. assets/src/scripts/watermark-edit.js +0 -90
  60. assets/src/styles/_edit-screen.scss +0 -51
  61. assets/src/styles/_general.scss +0 -209
  62. assets/src/styles/_mixins.scss +0 -10
  63. assets/src/styles/attachment-edit.scss +0 -1
  64. assets/src/styles/components/_field.scss +0 -12
  65. assets/src/styles/components/_grid.scss +0 -32
  66. assets/src/styles/components/_switch.scss +0 -52
  67. assets/src/styles/components/_vex.scss +0 -148
  68. assets/src/styles/dashboard.scss +0 -6
  69. assets/src/styles/main.scss +0 -8
  70. assets/src/styles/media-library.scss +0 -108
  71. assets/src/styles/metaboxes/_alignment.scss +0 -60
  72. assets/src/styles/metaboxes/_content.scss +0 -40
  73. assets/src/styles/metaboxes/_placeholders.scss +0 -101
  74. assets/src/styles/metaboxes/_preview.scss +0 -32
  75. assets/src/styles/metaboxes/_watermarks.scss +0 -48
  76. assets/src/styles/pages/_tools.scss +0 -7
  77. assets/src/styles/pages/_watermarks.scss +0 -49
  78. assets/src/styles/uploader.scss +0 -5
  79. assets/src/styles/watermark-edit.scss +0 -8
  80. bin/dump-hooks.php +0 -71
  81. easy-watermark.php +22 -22
  82. index.php +20 -20
  83. readme.txt +5 -1
  84. src/bootstrap.php +59 -59
  85. src/classes/AttachmentProcessor/AttachmentProcessor.php +259 -259
  86. src/classes/AttachmentProcessor/AttachmentProcessorGD.php +750 -750
  87. src/classes/AttachmentProcessor/Manager.php +51 -51
  88. src/classes/Backup/Manager.php +108 -108
  89. src/classes/Core/Assets.php +332 -332
  90. src/classes/Core/Hooks.php +83 -83
  91. src/classes/Core/Installer.php +496 -494
  92. src/classes/Core/Manager.php +195 -195
  93. src/classes/Core/Plugin.php +230 -230
  94. src/classes/Core/View.php +131 -131
  95. src/classes/Dashboard/Dashboard.php +162 -162
  96. src/classes/Dashboard/Permissions.php +134 -134
  97. src/classes/Dashboard/Settings.php +39 -39
  98. src/classes/Dashboard/Tools.php +122 -122
  99. src/classes/Dashboard/Watermarks.php +61 -61
  100. src/classes/Features/AutoWatermarkSwitch.php +58 -58
  101. src/classes/Features/CacheBusting.php +147 -147
  102. src/classes/Features/SrcsetFilter.php +180 -181
  103. src/classes/Features/WatermarkPreview.php +152 -152
  104. src/classes/Helpers/Image.php +57 -57
  105. src/classes/Helpers/Text.php +55 -55
  106. src/classes/Metaboxes/Metabox.php +153 -153
  107. src/classes/Metaboxes/Watermark/ApplyingRules.php +47 -47
  108. src/classes/Metaboxes/Watermark/Preview.php +154 -154
  109. src/classes/Metaboxes/Watermark/TextOptions.php +44 -44
  110. src/classes/Placeholders/Abstracts/Placeholder.php +201 -201
  111. src/classes/Placeholders/Abstracts/StringPlaceholder.php +41 -41
  112. src/classes/Placeholders/Abstracts/UrlPlaceholder.php +41 -41
  113. src/classes/Placeholders/Blog/AdminEmail.php +39 -39
  114. src/classes/Placeholders/Blog/BlogName.php +39 -39
  115. src/classes/Placeholders/Blog/BlogUrl.php +39 -39
  116. src/classes/Placeholders/DateTime/Date.php +39 -39
  117. src/classes/Placeholders/DateTime/Time.php +39 -39
  118. src/classes/Placeholders/Resolver.php +154 -154
  119. src/classes/Settings/Field.php +241 -241
  120. src/classes/Settings/Fields/Checkbox.php +1 -1
  121. src/classes/Settings/Fields/SwitchField.php +28 -28
  122. src/classes/Settings/Section.php +170 -170
  123. src/classes/Settings/Settings.php +245 -245
  124. src/classes/Traits/Hookable.php +114 -114
  125. src/classes/Watermark/Ajax.php +281 -281
  126. src/classes/Watermark/Handler.php +503 -503
  127. src/classes/Watermark/Hooks.php +160 -160
  128. src/classes/Watermark/PostType.php +515 -515
  129. src/classes/Watermark/Preview.php +91 -91
  130. src/classes/Watermark/Watermark.php +262 -262
  131. src/inc/functions.php +35 -35
  132. src/inc/hooks.php +90 -90
  133. src/views/dashboard/pages/tools.php +67 -67
  134. src/views/dashboard/pages/watermarks.php +55 -55
  135. src/views/edit-screen/metaboxes/watermark/preview.php +21 -21
  136. src/views/edit-screen/metaboxes/watermark/watermark-content.php +53 -53
  137. src/views/upload/switch.php +15 -15
  138. vendor/autoload.php +1 -1
  139. vendor/composer/ClassLoader.php +32 -0
  140. vendor/composer/InstalledVersions.php +106 -31
  141. vendor/composer/autoload_real.php +5 -5
  142. vendor/composer/autoload_static.php +5 -5
  143. vendor/composer/installed.json +2 -13
  144. vendor/composer/installed.php +6 -6
  145. vendor/composer/installers/.editorconfig +0 -10
  146. vendor/composer/installers/.gitignore +0 -2
  147. vendor/composer/installers/.travis.yml +0 -11
  148. vendor/composer/installers/README.md +0 -162
  149. vendor/composer/installers/composer.json +0 -38
  150. vendor/composer/platform_check.php +15 -3
  151. vendor/micropackage/singleton/.editorconfig +0 -15
  152. vendor/micropackage/singleton/.gitattributes +0 -1
  153. vendor/micropackage/singleton/.gitignore +0 -104
  154. vendor/micropackage/singleton/README.md +0 -39
  155. vendor/micropackage/singleton/composer.json +0 -29
  156. vendor/micropackage/singleton/composer.lock +0 -240
  157. vendor/micropackage/singleton/phpcs.xml +0 -43
  158. vendor/underdev/requirements/.editorconfig +0 -22
  159. vendor/underdev/requirements/.gitattributes +0 -1
  160. vendor/underdev/requirements/.gitignore +0 -7
  161. vendor/underdev/requirements/README.md +0 -90
  162. vendor/underdev/requirements/composer.json +0 -15
  163. vendor/underdev/requirements/package.json +0 -22
.distignore ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .build-excludes
2
+ .git
3
+ .gitignore
4
+ .gitattributes
5
+ .editorconfig
6
+ .eslintrc
7
+ .eslintrc.prod
8
+ .stylelintrc
9
+ .travis.yml
10
+ composer.json
11
+ composer.lock
12
+ package.json
13
+ phpcs.xml
14
+ README.md
15
+ webpack.config.js
16
+ yarn.lock
17
+ node_modules
18
+ assets/src
19
+ builds
20
+ bin
.github/workflows/legacy-develop.yml ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Legacy Develop
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - legacy_develop
7
+
8
+ jobs:
9
+
10
+ # Builds the package and creates artifact with dist files
11
+ build:
12
+ name: Build
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - name: Set PHP version
16
+ run: sudo update-alternatives --set php /usr/bin/php7.4
17
+ - name: Checkout
18
+ uses: actions/checkout@v2
19
+ - name: Setup Node
20
+ uses: actions/setup-node@v1
21
+ with:
22
+ node-version: '11'
23
+ - name: Setup variables
24
+ id: vars
25
+ run: |
26
+ echo "::set-output name=yarn-cache-path::$(yarn cache dir)"
27
+ echo "::set-output name=composer-cache-path::$(composer config cache-files-dir)"
28
+ - name: Cache Yarn
29
+ uses: actions/cache@v1
30
+ with:
31
+ path: ${{ steps.vars.outputs.yarn-cache-path }}
32
+ key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
33
+ restore-keys: ${{ runner.os }}-yarn-
34
+ - name: Cache Composer
35
+ uses: actions/cache@v1
36
+ with:
37
+ path: ${{ steps.vars.outputs.composer-cache-path }}
38
+ key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
39
+ restore-keys: ${{ runner.os }}-composer-
40
+ - name: Install Node dependencies
41
+ run: yarn install --no-progress
42
+ - name: Install Composer dependencies
43
+ run: composer install -o --no-dev --no-progress
44
+ - name: Build static assets
45
+ run: yarn build:production
46
+ - name: Create build dir
47
+ run: mkdir build
48
+ - name: Copy files
49
+ uses: Pendect/action-rsyncer@v1.1.0
50
+ env:
51
+ DEPLOY_KEY: ${{ secrets.PACKAGES_DEPLOY_KEY }}
52
+ with:
53
+ flags: '-avq'
54
+ options: '--exclude-from=".build-excludes"'
55
+ src: '.'
56
+ dest: 'build'
57
+ - name: Fix permissiong
58
+ run: sudo chown -R $USER:$USER ./
59
+ - name: Upload artifact
60
+ uses: actions/upload-artifact@v1
61
+ with:
62
+ name: build
63
+ path: build
64
+
65
+ # Creates the dev package artifact from develop branch
66
+ pack:
67
+ name: Pack
68
+ runs-on: ubuntu-latest
69
+ needs: build
70
+ steps:
71
+ - name: Download artifact
72
+ uses: actions/download-artifact@v1
73
+ with:
74
+ name: build
75
+ path: ${{ secrets.SLUG }}
76
+ - name: Create archive
77
+ run: |
78
+ zip -rq ${{ secrets.SLUG }}-dev.zip ${{ secrets.SLUG }}
79
+ - name: Upload artifact
80
+ uses: actions/upload-artifact@v1
81
+ with:
82
+ name: ${{ secrets.SLUG }}-dev
83
+ path: ${{ secrets.SLUG }}-dev.zip
84
+
85
+ # Uploads the develop package to internal repository
86
+ upload:
87
+ name: Upload to repo
88
+ runs-on: ubuntu-latest
89
+ needs: pack
90
+ steps:
91
+ - name: Download artifact
92
+ uses: actions/download-artifact@v1
93
+ with:
94
+ name: ${{ secrets.SLUG }}-dev
95
+ path: .
96
+ - name: Upload to repo
97
+ uses: Pendect/action-rsyncer@v1.1.0
98
+ env:
99
+ DEPLOY_KEY: ${{ secrets.PACKAGES_DEPLOY_KEY }}
100
+ with:
101
+ flags: '-avz'
102
+ options: '--recursive '
103
+ src: '.'
104
+ dest: '${{ secrets.BRACKETSPACE_REPO_RSYNC_URL }}${{ secrets.SLUG }}/'
.github/workflows/legacy-stable.yml ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Stable
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - '*'
7
+
8
+ jobs:
9
+
10
+ # Builds the package and creates artifact with dist files
11
+ build:
12
+ name: Build
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - name: Set PHP version
16
+ run: sudo update-alternatives --set php /usr/bin/php7.4
17
+ - name: Checkout
18
+ uses: actions/checkout@v2
19
+ - name: Setup Node
20
+ uses: actions/setup-node@v1
21
+ with:
22
+ node-version: '11'
23
+ - name: Setup variables
24
+ id: vars
25
+ run: |
26
+ echo "::set-output name=yarn-cache-path::$(yarn cache dir)"
27
+ echo "::set-output name=composer-cache-path::$(composer config cache-files-dir)"
28
+ - name: Cache Yarn
29
+ uses: actions/cache@v1
30
+ with:
31
+ path: ${{ steps.vars.outputs.yarn-cache-path }}
32
+ key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
33
+ restore-keys: ${{ runner.os }}-yarn-
34
+ - name: Cache Composer
35
+ uses: actions/cache@v1
36
+ with:
37
+ path: ${{ steps.vars.outputs.composer-cache-path }}
38
+ key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
39
+ restore-keys: ${{ runner.os }}-composer-
40
+ - name: Install Node dependencies
41
+ run: yarn install --no-progress
42
+ - name: Install Composer dependencies
43
+ run: composer install -o --no-dev --no-progress
44
+ - name: Build static assets
45
+ run: yarn build:production
46
+ - name: Create build dir
47
+ run: mkdir build
48
+ - name: Copy files
49
+ uses: Pendect/action-rsyncer@v1.1.0
50
+ env:
51
+ DEPLOY_KEY: ${{ secrets.PACKAGES_DEPLOY_KEY }}
52
+ with:
53
+ flags: '-avq'
54
+ options: '--exclude-from=".build-excludes"'
55
+ src: '.'
56
+ dest: 'build'
57
+ - name: Upload artifact
58
+ uses: actions/upload-artifact@v1
59
+ with:
60
+ name: build
61
+ path: build
62
+
63
+ # Creates the stable package artifact when tag is created
64
+ pack:
65
+ name: Pack
66
+ runs-on: ubuntu-latest
67
+ needs: build
68
+ steps:
69
+ - name: Setup variables
70
+ id: vars
71
+ run: |
72
+ echo "::set-output name=package-name::${{ secrets.SLUG }}-${GITHUB_REF#refs/tags/}"
73
+ - name: Download artifact
74
+ uses: actions/download-artifact@v1
75
+ with:
76
+ name: build
77
+ path: ${{ secrets.SLUG }}
78
+ - name: Create archive
79
+ run: |
80
+ zip -rq ${{ steps.vars.outputs.package-name }}.zip ${{ secrets.SLUG }}
81
+ - name: Upload artifact
82
+ uses: actions/upload-artifact@v1
83
+ with:
84
+ name: ${{ steps.vars.outputs.package-name }}
85
+ path: ${{ steps.vars.outputs.package-name }}.zip
86
+
87
+ # Uploads the stable package to internal repository
88
+ upload:
89
+ name: Upload to repo
90
+ runs-on: ubuntu-latest
91
+ needs: pack
92
+ steps:
93
+ - name: Setup variables
94
+ id: vars
95
+ run: |
96
+ echo "::set-output name=package-name::${{ secrets.SLUG }}-${GITHUB_REF#refs/tags/}"
97
+ - name: Download artifact
98
+ uses: actions/download-artifact@v1
99
+ with:
100
+ name: ${{ steps.vars.outputs.package-name }}
101
+ path: .
102
+ - name: Upload to repo
103
+ uses: Pendect/action-rsyncer@v1.1.0
104
+ env:
105
+ DEPLOY_KEY: ${{ secrets.PACKAGES_DEPLOY_KEY }}
106
+ with:
107
+ flags: '-avz'
108
+ options: '--recursive '
109
+ src: '.'
110
+ dest: '${{ secrets.BRACKETSPACE_REPO_RSYNC_URL }}${{ secrets.SLUG }}/'
111
+
112
+ # Release on GitHub
113
+ github-release:
114
+ name: Release on GitHub
115
+ runs-on: ubuntu-latest
116
+ needs: pack
117
+ steps:
118
+ - name: Checkout
119
+ uses: actions/checkout@v2
120
+ - name: Setup variables
121
+ id: vars
122
+ run: |
123
+ echo "::set-output name=version::${GITHUB_REF#refs/tags/}"
124
+ echo "::set-output name=package-name::${{ secrets.SLUG }}-${GITHUB_REF#refs/tags/}"
125
+ - name: Parse changelog
126
+ run: |
127
+ START="= ${{ steps.vars.outputs.version }} ="
128
+ END="= [0-9]+.[0-9]+.[0-9]+ =|==|\$"
129
+ grep -oPz "(?s)${START}.*?\n\K.*?(?=${END})" readme.txt > changelog.txt
130
+ truncate -s-2 changelog.txt
131
+ - name: Download artifact
132
+ uses: actions/download-artifact@v1
133
+ with:
134
+ name: ${{ steps.vars.outputs.package-name }}
135
+ path: .
136
+ - name: Release
137
+ uses: softprops/action-gh-release@v1
138
+ with:
139
+ body_path: changelog.txt
140
+ files: ${{ steps.vars.outputs.package-name }}.zip
141
+ env:
142
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
143
+
144
+ # Deploys the stable tag to WordPress.org repository
145
+ wordpress-org-release:
146
+ name: Release on WordPress.org
147
+ runs-on: ubuntu-latest
148
+ steps:
149
+ - name: Checkout
150
+ uses: actions/checkout@v2
151
+ - name: Setup Node
152
+ uses: actions/setup-node@v1
153
+ with:
154
+ node-version: '11'
155
+ - name: Setup variables
156
+ id: vars
157
+ run: |
158
+ echo "::set-output name=yarn-cache-path::$(yarn cache dir)"
159
+ echo "::set-output name=composer-cache-path::$(composer config cache-files-dir)"
160
+ - name: Cache Yarn
161
+ uses: actions/cache@v1
162
+ with:
163
+ path: ${{ steps.vars.outputs.yarn-cache-path }}
164
+ key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
165
+ restore-keys: ${{ runner.os }}-yarn-
166
+ - name: Cache Composer
167
+ uses: actions/cache@v1
168
+ with:
169
+ path: ${{ steps.vars.outputs.composer-cache-path }}
170
+ key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
171
+ restore-keys: ${{ runner.os }}-composer-
172
+ - name: Install Node dependencies
173
+ run: yarn install --no-progress
174
+ - name: Install Composer dependencies
175
+ run: composer install -o --no-dev --no-progress
176
+ - name: Build static assets
177
+ run: yarn build:production
178
+ - name: Create .distignore file
179
+ run: cp .build-excludes .distignore
180
+ - name: Deploy to WordPress repository
181
+ uses: 10up/action-wordpress-plugin-deploy@1.4.0
182
+ env:
183
+ SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
184
+ SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
185
+ SLUG: ${{ secrets.SLUG }}
.github/workflows/release.yml ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Legacy Release
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ new_version:
7
+ description: 'New version'
8
+ required: true
9
+
10
+ jobs:
11
+ release:
12
+ name: Release
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - name: Set PHP version
16
+ run: sudo update-alternatives --set php /usr/bin/php7.4
17
+ - name: Checkout legacy master
18
+ uses: actions/checkout@v1
19
+ with:
20
+ ref: 'legacy_master'
21
+ - name: Checkout legacy develop
22
+ uses: actions/checkout@v1
23
+ with:
24
+ ref: 'legacy_develop'
25
+ clean: false
26
+ - name: Install git-flow
27
+ run: sudo apt-get install git-flow -y
28
+ - name: Configure commiter
29
+ run: |
30
+ git config --local user.email "${{ secrets.WORKER_EMAIL }}"
31
+ git config --local user.name "${{ secrets.WORKER_NAME }}"
32
+ - name: Init git flow
33
+ run: |
34
+ git config gitflow.branch.develop legacy_develop
35
+ git config gitflow.branch.master legacy_master
36
+ git flow init -d
37
+ - name: Start release
38
+ run: git flow release start ${{ github.event.inputs.new_version }}
39
+ - name: Replace [Next] tags with new version number
40
+ uses: jacobtomlinson/gha-find-replace@master
41
+ with:
42
+ find: "(?i)\\[Next\\]"
43
+ replace: "${{ github.event.inputs.new_version }}"
44
+ - name: Replace stable tag in readme
45
+ uses: jacobtomlinson/gha-find-replace@master
46
+ with:
47
+ find: "Stable tag: [0-9]+.[0-9]+.[0-9]+"
48
+ replace: "Stable tag: ${{ github.event.inputs.new_version }}"
49
+ include: "readme.txt"
50
+ - name: Replace version tag in main file
51
+ uses: jacobtomlinson/gha-find-replace@master
52
+ with:
53
+ find: "Version: [0-9]+.[0-9]+.[0-9]+"
54
+ replace: "Version: ${{ github.event.inputs.new_version }}"
55
+ include: "${{ secrets.SLUG }}.php"
56
+ - name: Commit version bump
57
+ run: git commit -am "Version bump"
58
+ - name: Finish release
59
+ run: git flow release finish ${{ github.event.inputs.new_version }} -m "v${{ github.event.inputs.new_version }}"
60
+ - name: Push legacy develop and tags
61
+ uses: ad-m/github-push-action@master
62
+ with:
63
+ github_token: ${{ secrets.WORKER_TOKEN }}
64
+ branch: 'legacy_develop'
65
+ - name: Push legacy master
66
+ uses: ad-m/github-push-action@master
67
+ with:
68
+ github_token: ${{ secrets.WORKER_TOKEN }}
69
+ branch: 'legacy_master'
.github/workflows/test.yml ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Test
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ phpcs:
7
+ name: WordPress Coding Standards
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - name: Set PHP version
11
+ run: sudo update-alternatives --set php /usr/bin/php7.4
12
+ - name: Checkout
13
+ uses: actions/checkout@v2
14
+ - name: Setup variables
15
+ id: vars
16
+ run: |
17
+ echo "::set-output name=composer-cache-path::$(composer config cache-files-dir)"
18
+ - name: Cache Composer
19
+ uses: actions/cache@v1
20
+ with:
21
+ path: ${{ steps.vars.outputs.composer-cache-path }}
22
+ key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
23
+ restore-keys: ${{ runner.os }}-composer-
24
+ - name: Install Composer dependencies
25
+ run: composer install --no-progress
26
+ - name: Coding Standards
27
+ run: composer phpcs
28
+ css:
29
+ name: CSS Lint
30
+ runs-on: ubuntu-latest
31
+ steps:
32
+ - name: Checkout
33
+ uses: actions/checkout@v2
34
+ - name: Setup Node
35
+ uses: actions/setup-node@v1
36
+ with:
37
+ node-version: '11'
38
+ - name: Setup variables
39
+ id: vars
40
+ run: |
41
+ echo "::set-output name=yarn-cache-path::$(yarn cache dir)"
42
+ - name: Cache Yarn
43
+ uses: actions/cache@v1
44
+ with:
45
+ path: ${{ steps.vars.outputs.yarn-cache-path }}
46
+ key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
47
+ restore-keys: ${{ runner.os }}-yarn-
48
+ - name: Install Node dependencies
49
+ run: yarn install --no-progress
50
+ - name: CSS lint
51
+ run: yarn lint:css
52
+ js:
53
+ name: JS Lint
54
+ runs-on: ubuntu-latest
55
+ steps:
56
+ - name: Checkout
57
+ uses: actions/checkout@v2
58
+ - name: Setup Node
59
+ uses: actions/setup-node@v1
60
+ with:
61
+ node-version: '11'
62
+ - name: Setup variables
63
+ id: vars
64
+ run: |
65
+ echo "::set-output name=yarn-cache-path::$(yarn cache dir)"
66
+ - name: Cache Yarn
67
+ uses: actions/cache@v1
68
+ with:
69
+ path: ${{ steps.vars.outputs.yarn-cache-path }}
70
+ key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
71
+ restore-keys: ${{ runner.os }}-yarn-
72
+ - name: Install Node dependencies
73
+ run: yarn install --no-progress
74
+ - name: JS lint
75
+ run: yarn lint:js
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 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){}});
1
+ !function(e){var t={};function n(r){if(t[r])return t[r].exports;var a=t[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(r,a,function(t){return e[t]}.bind(null,a));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="../",n(n.s=21)}({0:function(e,t){e.exports=jQuery},1:function(e,t,n){"use strict";n.d(t,"a",(function(){return i})),n.d(t,"b",(function(){return s})),n.d(t,"c",(function(){return c})),n.d(t,"d",(function(){return u}));var r=n(0),a=n.n(r);function o(e){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"info",n=a()(document.createElement("div")),r=a()(document.createElement("p")),o=a()(document.createElement("button"));n.addClass("notice notice-"+t+" is-dismissible").hide(),o.addClass("notice-dismiss"),r.html(e),n.append(r).append(o),o.on("click",(function(e){e.preventDefault(),n.fadeOut(200,(function(){n.remove()}))})),a()("hr.wp-header-end").after(n),n.fadeIn(200)}function s(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=e.length,a=!0,o=!1,i=void 0;try{for(var s,c=e.clone().models[Symbol.iterator]();!(a=(s=c.next()).done);a=!0){var f=s.value;(!u(f)||f.get("usedAsWatermark")||!0===t&&!f.get("hasBackup"))&&(!0===n&&e.remove(f),r--)}}catch(e){o=!0,i=e}finally{try{a||null==c.return||c.return()}finally{if(o)throw i}}return r}function c(e){var t,n=e.indexOf("?"),r="t=".concat(Date.now());if(-1!==n){t=e.substr(n),e=e.substr(0,n);var a=/([^\s])t=[0-9]+/;t.match(a)?t=t.replace(a,"$1".concat(r)):t+="&".concat(r)}else t="?".concat(r);return e+t}function u(e){return"object"===o(e)&&e.get&&(e=e.get("mime")),Object.keys(ew.mime).includes(e)}},21:function(e,t,n){"use strict";n.r(t);n(28);var r=n(0),a=n.n(r),o=n(1);function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}new(function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.handleClick=this.handleClick.bind(this),this.metabox=a()("#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=a()("form#post"),this.postID=this.form.find("#post_ID").val(),this.headerEnd=a()("hr.wp-header-end"),this.image=a()(".wp_attachment_image img.thumbnail"),this.metabox.on("click","button",this.handleClick)}var t,n,r;return t=e,(n=[{key:"handleClick",value:function(e){var t=this;e.preventDefault();var n=a()(e.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")),a.a.ajax(ajaxurl,{data:i}).done((function(e){if(!0===e.success){if(t.metaboxContent.replaceWith(e.data.metaboxContent),t.metaboxContent=t.metabox.find(".watermarks-metabox"),t.errorMessage=t.metabox.find(".error-message"),t.spinners=t.metabox.find(".spinner"),t.buttons=t.metabox.find("button"),e.data.attachmentVersion){var n=Object(o.c)(t.image.attr("src"),e.data.attachmentVersion);t.image.attr("src",n),"string"==typeof e.data.message&&Object(o.a)(e.data.message,"success")}}else{var r="string"==typeof e.data.message?e.data.message:ew.genericErrorMessage;Object(o.a)(r,"error")}})).fail((function(){Object(o.a)(ew.genericErrorMessage,"error")})).complete((function(){t.spinners.css("visibility","hidden"),t.buttons.prop("disabled",!1)}))}}])&&i(t.prototype,n),r&&i(t,r),e}())},28:function(e,t){}});
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){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){}]);
1
+ !function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="../",n(n.s=20)}([function(e,t){e.exports=jQuery},function(e,t,n){"use strict";n.d(t,"a",(function(){return a})),n.d(t,"b",(function(){return s})),n.d(t,"c",(function(){return c})),n.d(t,"d",(function(){return l}));var o=n(0),r=n.n(o);function i(e){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function a(e){var t=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-"+t+" is-dismissible").hide(),i.addClass("notice-dismiss"),o.html(e),n.append(o).append(i),i.on("click",(function(e){e.preventDefault(),n.fadeOut(200,(function(){n.remove()}))})),r()("hr.wp-header-end").after(n),n.fadeIn(200)}function s(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],o=e.length,r=!0,i=!1,a=void 0;try{for(var s,c=e.clone().models[Symbol.iterator]();!(r=(s=c.next()).done);r=!0){var u=s.value;(!l(u)||u.get("usedAsWatermark")||!0===t&&!u.get("hasBackup"))&&(!0===n&&e.remove(u),o--)}}catch(e){i=!0,a=e}finally{try{r||null==c.return||c.return()}finally{if(i)throw a}}return o}function c(e){var t,n=e.indexOf("?"),o="t=".concat(Date.now());if(-1!==n){t=e.substr(n),e=e.substr(0,n);var r=/([^\s])t=[0-9]+/;t.match(r)?t=t.replace(r,"$1".concat(o)):t+="&".concat(o)}else t="?".concat(o);return e+t}function l(e){return"object"===i(e)&&e.get&&(e=e.get("mime")),Object.keys(ew.mime).includes(e)}},function(e,t){e.exports=Backbone},function(e,t,n){var o=n(5);o.registerPlugin(n(9)),e.exports=o},,function(e,t,n){n(6),n(7).polyfill();var o=n(8),r=function(e){if(void 0!==e){var t=document.createElement("div");return t.appendChild(document.createTextNode(e)),t.innerHTML}return""},i=function(e,t){if("string"==typeof t&&0!==t.length)for(var n=t.split(" "),o=0;o<n.length;o++){var r=n[o];r.length&&e.classList.add(r)}},a=function(){var e=document.createElement("div"),t={animation:"animationend",WebkitAnimation:"webkitAnimationEnd",MozAnimation:"animationend",OAnimation:"oanimationend",msAnimation:"MSAnimationEnd"};for(var n in t)if(void 0!==e.style[n])return t[n];return!1}(),s="vex",c="vex-content",l="vex-overlay",u="vex-close",f="vex-closing",d="vex-open",p={},h=1,b=!1,v={open:function(e){var t=function(e){console.warn('The "'+e+'" 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")};e.css&&t("css"),e.overlayCSS&&t("overlayCSS"),e.contentCSS&&t("contentCSS"),e.closeCSS&&t("closeCSS");var n={};n.id=h++,p[n.id]=n,n.isOpen=!0,n.close=function(){if(!this.isOpen)return!0;var e=this.options;if(b&&!e.escapeButtonCloses)return!1;if(!1===function(){return!e.beforeClose||e.beforeClose.call(this)}.bind(this)())return!1;this.isOpen=!1;var t=window.getComputedStyle(this.contentEl);function n(e){return"none"!==t.getPropertyValue(e+"animation-name")&&"0s"!==t.getPropertyValue(e+"animation-duration")}var o=n("")||n("-webkit-")||n("-moz-")||n("-o-"),r=function t(){this.rootEl.parentNode&&(this.rootEl.removeEventListener(a,t),this.overlayEl.removeEventListener(a,t),delete p[this.id],this.rootEl.parentNode.removeChild(this.rootEl),this.bodyEl.removeChild(this.overlayEl),e.afterClose&&e.afterClose.call(this),0===Object.keys(p).length&&document.body.classList.remove(d))}.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 e&&(e={content:e}),e.unsafeContent&&!e.content?e.content=e.unsafeContent:e.content&&(e.content=r(e.content));var m=n.options=Object.assign({},v.defaultOptions,e),g=n.bodyEl=document.getElementsByTagName("body")[0],y=n.rootEl=document.createElement("div");y.classList.add(s),i(y,m.className);var w=n.overlayEl=document.createElement("div");w.classList.add(l),i(w,m.overlayClassName),m.overlayClosesOnClick&&y.addEventListener("click",(function(e){e.target===y&&n.close()})),g.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)),y.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(y),m.afterOpen&&m.afterOpen.call(n),document.body.classList.add(d),n},close:function(e){var t;if(e.id)t=e.id;else{if("string"!=typeof e)throw new TypeError("close requires a vex object or id string");t=e}return!!p[t]&&p[t].close()},closeTop:function(){var e=Object.keys(p);return!!e.length&&p[e[e.length-1]].close()},closeAll:function(){for(var e in p)this.close(e);return!0},getAll:function(){return p},getById:function(e){return p[e]}};window.addEventListener("keyup",(function(e){27===e.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(e,t){var n=e(v),o=t||n.name;if(v[o])throw new Error("Plugin "+t+" is already registered.");v[o]=n},e.exports=v},function(e,t){
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(e){"use strict";if("Element"in e){var t=e.Element.prototype,n=Object,o=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},r=Array.prototype.indexOf||function(e){for(var t=0,n=this.length;t<n;t++)if(t in this&&this[t]===e)return t;return-1},i=function(e,t){this.name=e,this.code=DOMException[e],this.message=t},a=function(e,t){if(""===t)throw new i("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(t))throw new i("INVALID_CHARACTER_ERR","String contains an invalid character");return r.call(e,t)},s=function(e){for(var t=o.call(e.getAttribute("class")||""),n=t?t.split(/\s+/):[],r=0,i=n.length;r<i;r++)this.push(n[r]);this._updateClassName=function(){e.setAttribute("class",this.toString())}},c=s.prototype=[],l=function(){return new s(this)};if(i.prototype=Error.prototype,c.item=function(e){return this[e]||null},c.contains=function(e){return-1!==a(this,e+="")},c.add=function(){var e,t=arguments,n=0,o=t.length,r=!1;do{e=t[n]+"",-1===a(this,e)&&(this.push(e),r=!0)}while(++n<o);r&&this._updateClassName()},c.remove=function(){var e,t,n=arguments,o=0,r=n.length,i=!1;do{for(e=n[o]+"",t=a(this,e);-1!==t;)this.splice(t,1),i=!0,t=a(this,e)}while(++o<r);i&&this._updateClassName()},c.toggle=function(e,t){e+="";var n=this.contains(e),o=n?!0!==t&&"remove":!1!==t&&"add";return o&&this[o](e),!0===t||!1===t?t:!n},c.toString=function(){return this.join(" ")},n.defineProperty){var u={get:l,enumerable:!0,configurable:!0};try{n.defineProperty(t,"classList",u)}catch(e){void 0!==e.number&&-2146823252!==e.number||(u.enumerable=!1,n.defineProperty(t,"classList",u))}}else n.prototype.__defineGetter__&&t.__defineGetter__("classList",l)}}(window.self),function(){"use strict";var e=document.createElement("_");if(e.classList.add("c1","c2"),!e.classList.contains("c2")){var t=function(e){var t=DOMTokenList.prototype[e];DOMTokenList.prototype[e]=function(e){var n,o=arguments.length;for(n=0;n<o;n++)e=arguments[n],t.call(this,e)}};t("add"),t("remove")}if(e.classList.toggle("c3",!1),e.classList.contains("c3")){var n=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(e,t){return 1 in arguments&&!this.contains(e)==!t?t:n.call(this,e)}}e=null}())},function(e,t,n){"use strict";function o(e,t){if(null==e)throw new TypeError("Cannot convert first argument to object");for(var n=Object(e),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}e.exports={assign:o,polyfill:function(){Object.assign||Object.defineProperty(Object,"assign",{enumerable:!1,configurable:!0,writable:!0,value:o})}}},function(e,t){e.exports=function(e,t){if("string"!=typeof e)throw new TypeError("String expected");t||(t=document);var n=/<([\w:]+)/.exec(e);if(!n)return t.createTextNode(e);e=e.replace(/^\s+|\s+$/g,"");var o=n[1];if("body"==o){return(i=t.createElement("html")).innerHTML=e,i.removeChild(i.lastChild)}var i,a=r[o]||r._default,s=a[0],c=a[1],l=a[2];(i=t.createElement("div")).innerHTML=c+e+l;for(;s--;)i=i.lastChild;if(i.firstChild==i.lastChild)return i.removeChild(i.firstChild);var u=t.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(e,t,n){e.exports=function e(t,n,o){function r(a,s){if(!n[a]){if(!t[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:{}};t[a][0].call(l.exports,(function(e){var n=t[a][1][e];return r(n||e)}),l,l.exports,e,t,n,o)}return n[a].exports}for(var i=!1,a=0;a<o.length;a++)r(o[a]);return r}({1:[function(e,t,n){"use strict";t.exports=function e(t){if(!t||"object"!=typeof t)return t;if("[object Date]"==Object.prototype.toString.call(t))return new Date(t.getTime());if(Array.isArray(t))return t.map(e);var n={};return Object.keys(t).forEach((function(o){n[o]=e(t[o])})),n}},{}],2:[function(e,t,n){t.exports=function(e,t){if("string"!=typeof e)throw new TypeError("String expected");t||(t=document);var n=/<([\w:]+)/.exec(e);if(!n)return t.createTextNode(e);e=e.replace(/^\s+|\s+$/g,"");var o=n[1];if("body"==o)return(r=t.createElement("html")).innerHTML=e,r.removeChild(r.lastChild);var r,a=i[o]||i._default,s=a[0],c=a[1],l=a[2];for((r=t.createElement("div")).innerHTML=c+e+l;s--;)r=r.lastChild;if(r.firstChild==r.lastChild)return r.removeChild(r.firstChild);for(var u=t.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(e,t,n){var o=/^(?:submit|button|image|reset|file)$/i,r=/^(?:input|select|textarea|keygen)/i,i=/(\[[^\[\]]*\])/g;function a(e,t,n){if(t.match(i))!function e(t,n,o){if(0===n.length)return t=o;var r=n.shift(),i=r.match(/^\[(.+?)\]$/);if("[]"===r)return t=t||[],Array.isArray(t)?t.push(e(null,n,o)):(t._values=t._values||[],t._values.push(e(null,n,o))),t;if(i){var a=i[1],s=+a;isNaN(s)?(t=t||{})[a]=e(t[a],n,o):(t=t||[])[s]=e(t[s],n,o)}else t[r]=e(t[r],n,o);return t}(e,function(e){var t=[],n=new RegExp(i),o=/^([^\[\]]*)/.exec(e);for(o[1]&&t.push(o[1]);null!==(o=n.exec(e));)t.push(o[1]);return t}(t),n);else{var o=e[t];o?(Array.isArray(o)||(e[t]=[o]),e[t].push(n)):e[t]=n}return e}function s(e,t,n){return n=n.replace(/(\r)?\n/g,"\r\n"),n=(n=encodeURIComponent(n)).replace(/%20/g,"+"),e+(e?"&":"")+encodeURIComponent(t)+"="+n}t.exports=function(e,t){"object"!=typeof t?t={hash:!!t}:void 0===t.hash&&(t.hash=!0);for(var n=t.hash?{}:"",i=t.serializer||(t.hash?a:s),c=e&&e.elements?e.elements:[],l=Object.create(null),u=0;u<c.length;++u){var f=c[u];if((t.disabled||!f.disabled)&&f.name&&r.test(f.nodeName)&&!o.test(f.type)){var d=f.name,p=f.value;if("checkbox"!==f.type&&"radio"!==f.type||f.checked||(p=void 0),t.empty){if("checkbox"!==f.type||f.checked||(p=""),"radio"===f.type&&(l[f.name]||f.checked?f.checked&&(l[f.name]=!0):l[f.name]=!1),!p&&"radio"==f.type)continue}else if(!p)continue;if("select-multiple"!==f.type)n=i(n,d,p);else{p=[];for(var h=f.options,b=!1,v=0;v<h.length;++v){var m=h[v],g=t.empty&&!m.value,y=m.value||g;m.selected&&y&&(b=!0,n=t.hash&&"[]"!==d.slice(d.length-2)?i(n,d+"[]",m.value):i(n,d,m.value))}!b&&t.empty&&(n=i(n,d,""))}}}if(t.empty)for(var d in l)l[d]||(n=i(n,d,""));return n}},{}],4:[function(e,t,n){var o=e("domify"),r=e("form-serialize"),i=e("deep-clone-simple"),a=function(e){var t=document.createElement("div");t.classList.add("vex-dialog-buttons");for(var n=0;n<e.length;n++){var o=e[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===e.length-1&&r.classList.add("vex-last"),function(e){r.addEventListener("click",function(t){e.click&&e.click.call(this,t)}.bind(this))}.bind(this)(o),t.appendChild(r)}return t};t.exports=function(e){var t={name:"dialog",open:function(t){var n=Object.assign({},i(this.defaultOptions),t);n.unsafeMessage&&!n.message?n.message=n.unsafeMessage:n.message&&(n.message=e._escapeHtml(n.message));var r=n.unsafeContent=function(e){var t=document.createElement("form");t.classList.add("vex-dialog-form");var n=document.createElement("div");n.classList.add("vex-dialog-message"),n.appendChild(e.message instanceof window.Node?e.message:o(e.message));var r=document.createElement("div");return r.classList.add("vex-dialog-input"),r.appendChild(e.input instanceof window.Node?e.input:o(e.input)),t.appendChild(n),t.appendChild(r),t}(n),s=e.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 e=!c||c();return e&&n.callback(this.value||!1),e}.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(e){return"string"==typeof e&&(e={message:e}),e=Object.assign({},i(this.defaultOptions),i(this.defaultAlertOptions),e),this.open(e)},confirm:function(e){if("object"!=typeof e||"function"!=typeof e.callback)throw new Error("dialog.confirm(options) requires options.callback.");return e=Object.assign({},i(this.defaultOptions),i(this.defaultConfirmOptions),e),this.open(e)},prompt:function(t){if("object"!=typeof t||"function"!=typeof t.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">'+e._escapeHtml(t.label||n.label)+"</label>",input:'<input name="vex" type="text" class="vex-dialog-prompt-input" placeholder="'+e._escapeHtml(t.placeholder||n.placeholder)+'" value="'+e._escapeHtml(t.value||n.value)+'" />'},r=(t=Object.assign(n,o,t)).callback;return t.callback=function(e){if("object"==typeof e){var t=Object.keys(e);e=t.length?e[t[0]]:""}r(e)},this.open(t)},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 t.defaultOptions={callback:function(){},afterOpen:function(){},message:"",input:"",yesText:"",noText:"",buttons:[t.buttons.YES,t.buttons.NO],showCloseButton:!1,onSubmit:function(e){return e.preventDefault(),this.options.input&&(this.value=r(this.form,{hash:!0})),this.close()},focusFirstInput:!0},t.defaultAlertOptions={buttons:[t.buttons.YES]},t.defaultPromptOptions={label:"Prompt:",placeholder:"",value:""},t.defaultConfirmOptions={},t}},{"deep-clone-simple":1,domify:2,"form-serialize":3}]},{},[4])(4)},function(e,t,n){var o=n(11);"string"==typeof o&&(o=[[e.i,o,""]]);var r={hmr:!0,transform:void 0,insertInto:void 0};n(13)(o,r);o.locals&&(e.exports=o.locals)},function(e,t,n){(e.exports=n(12)(!1)).push([e.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(e,t){e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var n=function(e,t){var n=e[1]||"",o=e[3];if(!o)return n;if(t&&"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(e){return"/*# sourceURL="+o.sourceRoot+e+" */"}));return[n].concat(i).concat([r]).join("\n")}var a;return[n].join("\n")}(t,e);return t[2]?"@media "+t[2]+"{"+n+"}":n})).join("")},t.i=function(e,n){"string"==typeof e&&(e=[[null,e,""]]);for(var o={},r=0;r<this.length;r++){var i=this[r][0];"number"==typeof i&&(o[i]=!0)}for(r=0;r<e.length;r++){var a=e[r];"number"==typeof a[0]&&o[a[0]]||(n&&!a[2]?a[2]=n:n&&(a[2]="("+a[2]+") and ("+n+")"),t.push(a))}},t}},function(e,t,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(e,t){return t?t.querySelector(e):document.querySelector(e)},c=function(e){var t={};return function(e,n){if("function"==typeof e)return e();if(void 0===t[e]){var o=s.call(this,e,n);if(window.HTMLIFrameElement&&o instanceof window.HTMLIFrameElement)try{o=o.contentDocument.head}catch(e){o=null}t[e]=o}return t[e]}}(),l=null,u=0,f=[],d=n(14);function p(e,t){for(var n=0;n<e.length;n++){var o=e[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(y(o.parts[a],t))}else{var s=[];for(a=0;a<o.parts.length;a++)s.push(y(o.parts[a],t));i[o.id]={id:o.id,refs:1,parts:s}}}}function h(e,t){for(var n=[],o={},r=0;r<e.length;r++){var i=e[r],a=t.base?i[0]+t.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(e,t){var n=c(e.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"===e.insertAt)o?o.nextSibling?n.insertBefore(t,o.nextSibling):n.appendChild(t):n.insertBefore(t,n.firstChild),f.push(t);else if("bottom"===e.insertAt)n.appendChild(t);else{if("object"!=typeof e.insertAt||!e.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(e.insertAt.before,n);n.insertBefore(t,r)}}function v(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e);var t=f.indexOf(e);t>=0&&f.splice(t,1)}function m(e){var t=document.createElement("style");if(void 0===e.attrs.type&&(e.attrs.type="text/css"),void 0===e.attrs.nonce){var o=function(){0;return n.nc}();o&&(e.attrs.nonce=o)}return g(t,e.attrs),b(e,t),t}function g(e,t){Object.keys(t).forEach((function(n){e.setAttribute(n,t[n])}))}function y(e,t){var n,o,r,i;if(t.transform&&e.css){if(!(i="function"==typeof t.transform?t.transform(e.css):t.transform.default(e.css)))return function(){};e.css=i}if(t.singleton){var a=u++;n=l||(l=m(t)),o=x.bind(null,n,a,!1),r=x.bind(null,n,a,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=function(e){var t=document.createElement("link");return void 0===e.attrs.type&&(e.attrs.type="text/css"),e.attrs.rel="stylesheet",g(t,e.attrs),b(e,t),t}(t),o=C.bind(null,n,t),r=function(){v(n),n.href&&URL.revokeObjectURL(n.href)}):(n=m(t),o=O.bind(null,n),r=function(){v(n)});return o(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;o(e=t)}else r()}}e.exports=function(e,t){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(t=t||{}).attrs="object"==typeof t.attrs?t.attrs:{},t.singleton||"boolean"==typeof t.singleton||(t.singleton=a()),t.insertInto||(t.insertInto="head"),t.insertAt||(t.insertAt="bottom");var n=h(e,t);return p(n,t),function(e){for(var o=[],r=0;r<n.length;r++){var a=n[r];(s=i[a.id]).refs--,o.push(s)}e&&p(h(e,t),t);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(e,t){return w[e]=t,w.filter(Boolean).join("\n")});function x(e,t,n,o){var r=n?"":o.css;if(e.styleSheet)e.styleSheet.cssText=k(t,r);else{var i=document.createTextNode(r),a=e.childNodes;a[t]&&e.removeChild(a[t]),a.length?e.insertBefore(i,a[t]):e.appendChild(i)}}function O(e,t){var n=t.css,o=t.media;if(o&&e.setAttribute("media",o),e.styleSheet)e.styleSheet.cssText=n;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(n))}}function C(e,t,n){var o=n.css,r=n.sourceMap,i=void 0===t.convertToAbsoluteUrls&&r;(t.convertToAbsoluteUrls||i)&&(o=d(o)),r&&(o+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(r))))+" */");var a=new Blob([o],{type:"text/css"}),s=e.href;e.href=URL.createObjectURL(a),s&&URL.revokeObjectURL(s)}},function(e,t){e.exports=function(e){var t="undefined"!=typeof window&&window.location;if(!t)throw new Error("fixUrls requires window.location");if(!e||"string"!=typeof e)return e;var n=t.protocol+"//"+t.host,o=n+t.pathname.replace(/\/[^\/]*$/,"/");return e.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi,(function(e,t){var r,i=t.trim().replace(/^"(.*)"$/,(function(e,t){return t})).replace(/^'(.*)'$/,(function(e,t){return t}));return/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(i)?e:(r=0===i.indexOf("//")?i:0===i.indexOf("/")?n+i:o+i.replace(/^\.\//,""),"url("+JSON.stringify(r)+")")}))}},,,,,,function(e,t,n){"use strict";n.r(t);var o=n(0),r=n.n(o);function i(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}var a=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.form=r()("form#easy-watermark-settings-form"),this.form.length&&this.init()}var t,n,o;return t=e,(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(e){var t=r()(e.target),n=t.data("toggle"),o=this.form.find(".group-".concat(n)),i=o.find("input, textarea, select");!0===t.is(":checked")?(o.show(),i.prop("disabled",!1)):(o.hide(),i.prop("disabled",!0))}}])&&i(t.prototype,n),o&&i(t,o),e}(),s=n(3),c=n.n(s);n(10),n(22);function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function u(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?l(Object(n),!0).forEach((function(t){f(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function f(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}c.a.defaultOptions.className="vex-theme-ew",c.a.defaultOptions.contentClassName="postbox",c.a.dialog.buttons.YES=u({},c.a.dialog.buttons.YES,{className:"button-primary",text:ew.i18n.yes}),c.a.dialog.buttons.OK=u({},c.a.dialog.buttons.YES,{className:"button-primary",text:ew.i18n.ok}),c.a.dialog.buttons.NO=u({},c.a.dialog.buttons.NO,{className:"button",text:ew.i18n.no});c.a;function d(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}var p=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.wrap=r()(".watermarks"),this.wrap.length&&this.init()}var t,n,o;return t=e,(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(e){e.preventDefault();var t=r()(e.currentTarget),n=t.data("watermark-name");!function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){};c.a.dialog.confirm({message:e,callback:t,buttons:[c.a.dialog.buttons.YES,c.a.dialog.buttons.NO]})}(ew.i18n.deleteConfirmation.replace("{watermarkName}",n),(function(e){!0===e&&(window.location=t.attr("href"))}))}}])&&d(t.prototype,n),o&&d(t,o),e}(),h=n(2);function b(e){return(b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function v(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function m(e){return(m=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function g(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function y(e,t){return(y=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var w=function(e){function t(e){var n,o,r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),o=this,(n=!(r=m(t).call(this,e))||"object"!==b(r)&&"function"!=typeof r?g(o):r).state=e.state,n.callback=e.callback,n.handleClick=n.handleClick.bind(g(n)),n.button=n.$el.find("a"),n.spinner=n.$el.find(".spinner"),n.content=n.$el.find(".content"),n.status=n.$el.find(".status"),n.button.on("click",n.handleClick),n.mode=n.state.get("mode"),n.state.on("change",n.update,g(n)),n}var n,o,r;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&y(e,t)}(t,e),n=t,(o=[{key:"template",value:function(){var e=this.state.get("processed"),t=this.state.get("total"),n=Math.floor(e/t*100),o=this.state.get("statusText");return o=o.replace("{counter}","".concat(e,"/").concat(t)),"".concat(o," (").concat(n,"%)")}},{key:"handleClick",value:function(){this.button.hasClass("disabled")||this.callback()}},{key:"update",value:function(){var e=this.state.get("mode"),t=this.state.get("action");this.mode!==e&&this.toggleMode(e),"processing"===e&&this.action===t&&this.status.html(this.template())}},{key:"toggleMode",value:function(e){this.mode=e,this.action===this.state.get("action")||"loading"!==e&&"processing"!==e?"loading"===e?this.loading():"processing"===e?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(n.prototype,o),r&&v(n,r),t}(h.View);function k(e){return(k="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function x(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function O(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function C(e,t,n){return(C="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,n){var o=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=E(e)););return e}(e,t);if(o){var r=Object.getOwnPropertyDescriptor(o,t);return r.get?r.get.call(n):r.value}})(e,t,n||e)}function E(e){return(E=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function j(e,t){return(j=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var S=function(e){function t(e){var n,o,r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),e.el=".tool-bulk-watermark",o=this,(n=!(r=E(t).call(this,e))||"object"!==k(r)&&"function"!=typeof r?O(o):r).action="watermark",n.selectWatermark=n.selectWatermark.bind(O(n)),n.toggleButton=n.toggleButton.bind(O(n)),n.select=n.$el.find("select"),n.select.on("change",n.selectWatermark),n.toggleButton(),n}var n,o,r;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&j(e,t)}(t,e),n=t,(o=[{key:"selectWatermark",value:function(){var e=this.select.val(),t=this.select.find("option:selected").data("nonce");this.state.set({watermark:e,nonce:t}),this.toggleButton()}},{key:"toggleButton",value:function(){"-1"===this.select.val()?this.button.addClass("disabled"):this.button.removeClass("disabled")}},{key:"disable",value:function(){C(E(t.prototype),"disable",this).call(this),this.select.prop({disabled:!0})}},{key:"processing",value:function(){this.select.val("-1"),C(E(t.prototype),"processing",this).call(this)}},{key:"reset",value:function(){C(E(t.prototype),"reset",this).call(this),this.select.prop({disabled:!1}).change()}}])&&x(n.prototype,o),r&&x(n,r),t}(w);function L(e){return(L="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function T(e,t){return!t||"object"!==L(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function N(e,t,n){return(N="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,n){var o=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=P(e)););return e}(e,t);if(o){var r=Object.getOwnPropertyDescriptor(o,t);return r.get?r.get.call(n):r.value}})(e,t,n||e)}function P(e){return(P=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function A(e,t){return(A=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var M=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),e.el=".tool-restore",(n=T(this,P(t).call(this,e))).action="restore",n.backupInfo=n.$el.find("p.has-backup"),n.noBackupInfo=n.$el.find("p.no-backup"),n.backupCountInfo=n.$el.find(".backup-count"),n.state.set({backupCount:n.$el.data("backup-count")}),n.toggleInfo(),n}var n,o,r;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&A(e,t)}(t,e),n=t,(o=[{key:"handleClick",value:function(){this.state.set({nonce:this.button.data("nonce")}),N(P(t.prototype),"handleClick",this).call(this)}},{key:"toggleInfo",value:function(){var e=this.state.get("backupCount");0<e?(this.backupCountInfo.text(e),this.backupInfo.show(),this.noBackupInfo.hide()):(this.backupInfo.hide(),this.noBackupInfo.show())}},{key:"update",value:function(){N(P(t.prototype),"update",this).call(this),this.toggleInfo()}}])&&_(n.prototype,o),r&&_(n,r),t}(w),R=n(1);function I(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}var B=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.wrap=r()(".tools"),this.wrap.length&&this.init()}var t,n,o;return t=e,(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 S({state:this.state,callback:this.bulkWatermark}),this.restoreTool=new M({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 e=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(t){t.success?(e.state.set({items:t.data}),e.start()):Object(R.a)(ew.i18n.genericErrorMessage,"error")})).fail((function(){Object(R.a)(ew.i18n.genericErrorMessage,"error")}))}},{key:"start",value:function(){var e=this.state.get("items");if(!e)return function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){};c.a.dialog.alert({message:e,callback:t,buttons:[c.a.dialog.buttons.OK]})}(ew.i18n.noItemsToWatermark),void this.state.set({mode:"none"});this.state.set({mode:"processing",processed:0,total:e.length,error:!1,backupCount:0}),this.doActionRecursive(e)}},{key:"doActionRecursive",value:function(e){var t=this,n=e.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++,t.state.set({processed:s,backupCount:c}),e.length?t.doActionRecursive(e):t.finish()):t.fail(n.data)})).fail((function(){t.fail(ew.i18n.genericErrorMessage)}))}},{key:"fail",value:function(e){var t=this.state.get("attachment").title,n=ew.i18n.bulkActionErrorMessage.replace("{imageTitle}",t).replace("{error}",e);this.state.set({error:n}),this.finish()}},{key:"finish",value:function(){var e=this.state.get("error"),t=this.state.get("processed"),n=this.state.get("successMessage");e?Object(R.a)(e,"error"):Object(R.a)(n.replace("{procesed}",t),"success"),this.state.set({mode:"none"})}}])&&I(t.prototype,n),o&&I(t,o),e}();n(24);r()(document).ready((function(){switch(r()("a.nav-tab-active").data("tab")){case"settings":new a;break;case"watermarks":new p;break;case"tools":new B}}))},,function(e,t){},,function(e,t){}]);
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){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){}});
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 a})),n.d(e,"b",(function(){return c})),n.d(e,"c",(function(){return s})),n.d(e,"d",(function(){return l}));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 a(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 c(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=t.length,o=!0,i=!1,a=void 0;try{for(var c,s=t.clone().models[Symbol.iterator]();!(o=(c=s.next()).done);o=!0){var u=c.value;(!l(u)||u.get("usedAsWatermark")||!0===e&&!u.get("hasBackup"))&&(!0===n&&t.remove(u),r--)}}catch(t){i=!0,a=t}finally{try{o||null==s.return||s.return()}finally{if(i)throw a}}return r}function s(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"===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){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 a(t,e,n){return(a="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=c(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){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function s(t,e){return(s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}wp.media&&"function"==typeof wp.media.view.SelectModeToggleButton&&(wp.media.view.SelectModeToggleButton=function(t){function e(){return r(this,e),i(this,c(e).apply(this,arguments))}var n,l,u;return 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&&s(t,e)}(e,wp.media.view.SelectModeToggleButton),n=e,(l=[{key:"initialize",value:function(){a(c(e.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(){a(c(e.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(n.prototype,l),u&&o(n,u),e}())},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 a(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 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=s(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 s(t){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function l(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&&u(t,e)}function u(t,e){return(u=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}wp.media&&("function"==typeof wp.media.view.AttachmentFilters.All&&(wp.media.view.AttachmentFilters.All=function(t){function e(){return r(this,e),a(this,s(e).apply(this,arguments))}return l(e,wp.media.view.AttachmentFilters.All),i(e,[{key:"initialize",value:function(){c(s(e.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"))}}]),e}()),"function"==typeof wp.media.view.AttachmentFilters.Uploaded&&(wp.media.view.AttachmentFilters.Uploaded=function(t){function e(){return r(this,e),a(this,s(e).apply(this,arguments))}return l(e,wp.media.view.AttachmentFilters.Uploaded),i(e,[{key:"initialize",value:function(){c(s(e.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"))}}]),e}()),"function"==typeof wp.media.view.DateFilter&&(wp.media.view.DateFilter=function(t){function e(){return r(this,e),a(this,s(e).apply(this,arguments))}return l(e,wp.media.view.DateFilter),i(e,[{key:"initialize",value:function(){c(s(e.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"))}}]),e}()))},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 a=wp.media.view.Attachment.Library;wp.media.view.Attachment.Library=a.extend({initialize:function(){a.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(){a.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)&&a.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 c(t){return(c="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){return!e||"object"!==c(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,e,n){return(f="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=p(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 p(t){return(p=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function h(t,e){return(h=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var y=null;wp.media&&"function"==typeof wp.media.view.Button&&(y=function(t){function e(){return s(this,e),u(this,p(e).apply(this,arguments))}var n,r,o;return 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&&h(t,e)}(e,wp.media.view.Button),n=e,(r=[{key:"initialize",value:function(){var t=this;f(p(e.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 f(p(e.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(){f(p(e.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(n.prototype,r),o&&l(n,o),e}());var d=y;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 m(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function w(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 g(t,e){return!e||"object"!==b(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 v(t,e,n){return(v="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=k(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){return(k=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function O(t,e){return(O=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var S=null;wp.media&&"function"==typeof wp.media.view.Button&&(S=function(t){function e(){return m(this,e),g(this,k(e).apply(this,arguments))}var n,r,o;return 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&&O(t,e)}(e,wp.media.view.Button),n=e,(r=[{key:"initialize",value:function(){v(k(e.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 v(k(e.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(){v(k(e.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)))}}])&&w(n.prototype,r),o&&w(n,o),e}());var j=S;function _(t){return(_="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){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function P(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){return!e||"object"!==_(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,e,n){return(B="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=x(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 x(t){return(x=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function E(t,e){return(E=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var $=null;wp.media&&"function"==typeof wp.media.view.Button&&($=function(t){function e(){return A(this,e),M(this,x(e).apply(this,arguments))}var n,r,o;return 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&&E(t,e)}(e,wp.media.view.Button),n=e,(r=[{key:"initialize",value:function(){var t=this;B(x(e.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 B(x(e.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(){B(x(e.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"))}}}])&&P(n.prototype,r),o&&P(n,o),e}());var C=$;function T(t){return(T="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 r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function D(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function z(t,e,n){return(z="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=N(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 N(t){return(N=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function W(t,e){return(W=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var F=null;wp.media&&"function"==typeof wp.media.View&&(F=function(t){function e(t){var n,r,o;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),r=this,(n=!(o=N(e).call(this,t))||"object"!==T(o)&&"function"!=typeof o?D(r):o).controller.on("watermark:activate",n.show,D(n)),n.controller.on("watermark:deactivate",n.hide,D(n)),n}var n,r,i;return 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&&W(t,e)}(e,wp.media.View),n=e,(r=[{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(z(N(e.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}}])&&R(n.prototype,r),i&&R(n,i),e}());var L=F;function V(t){return(V="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){return(I=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function U(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function H(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 Q(t,e,n){return e&&H(t.prototype,e),n&&H(t,n),t}function q(t,e){return(q=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var G=null;wp.media&&"function"==typeof wp.media.View&&(G=function(t){function e(t){var n,r,o;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),r=this,(n=!(o=I(e).call(this,t))||"object"!==V(o)&&"function"!=typeof o?U(r):o).status=n.controller.state().get("ewStatus"),n.status.on("change",n.update,U(n)),n}return 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&&q(t,e)}(e,wp.media.View),Q(e,[{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>")}}]),Q(e,[{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")}}]),e}());var J=G;function K(t){return(K="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 X(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function Y(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 Z(t,e){return!e||"object"!==K(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 tt(t,e,n){return(tt="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=et(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 et(t){return(et=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function nt(t,e){return(nt=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}wp.media&&"function"==typeof wp.media.view.AttachmentsBrowser&&(wp.media.view.AttachmentsBrowser=function(t){function e(){return X(this,e),Z(this,et(e).apply(this,arguments))}var n,r,o;return 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&&nt(t,e)}(e,wp.media.view.AttachmentsBrowser),n=e,(r=[{key:"createToolbar",value:function(){var t=this;tt(et(e.prototype),"createToolbar",this).call(this),this.controller.state().get("ewStatus")&&(Object.keys(ew.watermarks).length&&(this.toolbar.set("watermarkModeToggleButton",new C({text:ew.i18n.watermarkModeToggleButtonLabel,cancelText:ew.i18n.cancelLabel,controller:this.controller,priority:-60}).render()),this.toolbar.set("watermarkSelector",new L({controller:this.controller,priority:-50}).render()),this.toolbar.set("watermarkButton",new d({text:ew.i18n.watermarkButtonLabel,style:"primary",controller:this.controller,priority:-40}).render())),this.toolbar.set("restoreButton",new j({text:ew.i18n.restoreButtonLabel,controller:this.controller,priority:-30}).render()),this.toolbar.set("watermarkingStatus",new J({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")}}])&&Y(n.prototype,r),o&&Y(n,o),e}());n(16),n(17);var rt=n(2);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 it(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function at(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){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 st(t,e,n){return(st="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=lt(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 lt(t){return(lt=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function ut(t,e){return(ut=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function ft(t){return(ft="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 pt(t,e){return!e||"object"!==ft(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 ht(t){return(ht=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function yt(t,e){return(yt=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}wp.media&&wp.media.view&&wp.media.view.MediaFrame&&"function"==typeof wp.media.view.MediaFrame.Manage&&(wp.media.view.MediaFrame.Manage=function(t){function e(){return it(this,e),ct(this,lt(e).apply(this,arguments))}var n,r,a;return 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&&ut(t,e)}(e,wp.media.view.MediaFrame.Manage),n=e,(r=[{key:"browseContent",value:function(t){this.state().set({ewCollection:new rt.Collection,ewStatus:new rt.Model}),st(lt(e.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"),a=t.get("ewStatus");o.reset();var c=!0,s=!1,l=void 0;try{for(var u,f=e.models[Symbol.iterator]();!(c=(u=f.next()).done);c=!0){var p=u.value;o.add(p),p.trigger("ewBulkAction:start")}}catch(t){s=!0,l=t}finally{try{c||null==f.return||f.return()}finally{if(s)throw l}}this.deactivateMode("watermark").trigger("selection:action:done"),this.activateMode("processing"),a.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"),a=n.get("watermark"),c="easy-watermark/";if("watermark"===r)c+="all"===a?"apply_all":"apply_single",t="all"===a?ew.applyAllNonce:ew.applySingleNonces[a];else{if("restore"!==r)return;c+="restore_backup",t=ew.restoreBackupNonce}var s=n.get("ewStatus"),l=n.get("ewCollection").shift(),u={action:c,nonce:t,watermark:a},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 a=o[r];n[a].url=Object(i.c)(n[a].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 c="string"==typeof t.data.message?t.data.message:ew.i18n.genericErrorMessage;e.ewBulkActionError(c)}})).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=!0,a=!1,c=void 0;try{for(var s,l=r.models[Symbol.iterator]();!(i=(s=l.next()).done);i=!0)s.value.trigger("ewBulkAction:done")}catch(t){a=!0,c=t}finally{try{i||null==l.return||l.return()}finally{if(a)throw c}}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"),a=t.get("ewSuccessMessage");if(this.deactivateMode("watermarking"),this.deactivateMode("restoring"),this.deactivateMode("processing"),r>0&&Object(i.a)(a.replace("{procesed}",r),"success"),o){var c=ew.i18n.bulkActionErrorMessage.replace("{imageTitle}",n.get("title")).replace("{error}",o);Object(i.a)(c,"error")}e.set({visible:!1,progress:!1})}}])&&at(n.prototype,r),a&&at(n,a),e}());var dt=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=pt(this,ht(e).call(this,t))).controller=t.controller,n.bulkActionSelector=t.bulkActionSelector,n}return 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&&yt(t,e)}(e,t),e}(rt.View);function bt(t){return(bt="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 mt(t,e){return!e||"object"!==bt(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 wt(t,e,n){return(wt="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=gt(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 gt(t){return(gt=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function vt(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 kt(t,e,n){return e&&vt(t.prototype,e),n&&vt(t,n),t}function Ot(t,e){return(Ot=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var St=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=mt(this,gt(e).call(this,t))).listenTo(n.controller,"change",n.update),n.listenTo(n.controller,"bulkAction:start",n.reset),n}return 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&&Ot(t,e)}(e,t),kt(e,[{key:"tagName",value:function(){return"select"}},{key:"className",value:function(){return"ew-status"}},{key:"events",value:function(){return{change:"selectWatermark"}}}]),kt(e,[{key:"render",value:function(){for(var t in wt(gt(e.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())}}]),e}(dt);function jt(t){return(jt="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 _t(t,e){return!e||"object"!==jt(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 At(t,e,n){return(At="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=Pt(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 Pt(t){return(Pt=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(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 xt(t,e){return(xt=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var Et=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=_t(this,Pt(e).call(this,t))).status=n.controller.status(),n.listenTo(n.status,"change",n.update),n}return 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&&xt(t,e)}(e,t),Bt(e,[{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}}]),Bt(e,[{key:"render",value:function(){At(Pt(e.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}}]),e}(dt);function $t(t){return($t="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 Ct(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 Tt(t){return(Tt=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function Rt(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function Dt(t,e){return(Dt=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var zt=function(t){function e(t){var n,r,o;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),r=this,(n=!(o=Tt(e).call(this,t))||"object"!==$t(o)&&"function"!=typeof o?Rt(r):o).model=t.model,n.listenTo(n.model,"processing:start",n.showSpinner),n.listenTo(n.model,"processing:done",n.reset),n.listenTo(n.model,"remove",n.deselect),n.controller.on("bulkAction:finished",n.reset,Rt(n)),n}var n,r,a;return 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&&Dt(t,e)}(e,t),n=e,(r=[{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}}])&&Ct(n.prototype,r),a&&Ct(n,a),e}(dt);function Nt(t){return(Nt="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 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 Ft(t,e){return!e||"object"!==Nt(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 Lt(t){return(Lt=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function Vt(t,e){return(Vt=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var It=function(t){function e(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=Ft(this,Lt(e).call(this))).bulkActionsSelectors=o()("select#bulk-action-selector-top, select#bulk-action-selector-bottom"),t.bulkActionsSelectors.length&&t.init(),t}var n,r,a;return 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)}(e,t),n=e,(r=[{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 St({controller:t,bulkActionSelector:r}).render(),new Et({controller:t,bulkActionSelector:r}).render()})).val(-1).on("change",this.selectBulkAction),this.set({attachments:new rt.Collection,selection:new rt.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 a=this.get("attachments"),c=this.get("selection"),s=[];this.trigger("bulkAction:start"),i.each((function(t,e){var n=o()(e).val(),r=a.get(n);r?c.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=!0,r=!1,o=void 0;try{for(var i,s=t.data[Symbol.iterator]();!(n=(i=s.next()).done);n=!0){var l=i.value,u=new rt.Model(l);a.push(u),c.push(u),new zt({el:"#post-".concat(l.id),controller:e,model:u})}}catch(t){r=!0,o=t}finally{try{n||null==s.return||s.return()}finally{if(r)throw o}}e.prepare()}else{var f=t.data.message?t.data.message:ew.i18n.genericErrorMessage;e.actionError(f)}})).fail((function(){e.actionError(ew.i18n.genericErrorMessage)}))):c.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 a=!0,c=!1,s=void 0;try{for(var l,u=e.models[Symbol.iterator]();!(a=(l=u.next()).done);a=!0)l.value.trigger("processing:start")}catch(t){c=!0,s=t}finally{try{a||null==u.return||u.return()}finally{if(c)throw s}}this.doActionRecursive()}},{key:"doActionRecursive",value:function(){var t,e=this,n=this.get("action"),r=this.get("watermark"),a="easy-watermark/";if("watermark"===n)a+="all"===r?"apply_all":"apply_single",t="all"===r?ew.applyAllNonce:ew.applySingleNonces[r];else{if("restore"!==n)return;a+="restore_backup",t=ew.restoreBackupNonce}var c=this.status(),s=this.get("selection"),l=s.shift(),u={action:a,nonce:t,watermark:r},f=c.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++,c.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 a=this.form.find("tr#post-"+o).find(".column-title a").attr("aria-label"),c=ew.i18n.bulkActionErrorMessage.replace("{imageTitle}",a).replace("{error}",n);Object(i.a)(c,"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 rt.Model,t.set({processed:0,total:0}),this.set({status:t})),t}},{key:"checkAction",value:function(t){return["watermark","restore"].includes(t)}}])&&Wt(n.prototype,r),a&&Wt(n,a),e}(rt.Model);o()(document).ready((function(){return new It}))},2:function(t,e){t.exports=Backbone},30:function(t,e){}});
assets/dist/scripts/uploader.js CHANGED
@@ -1 +1 @@
1
- !function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="../",r(r.s=15)}({0:function(t,e){t.exports=jQuery},15:function(t,e,r){"use strict";r.r(e);var n=r(0),o=r.n(n);r(26);function u(t){return(u="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){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function c(t,e,r){return(c="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,r){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=s(t)););return t}(t,e);if(n){var o=Object.getOwnPropertyDescriptor(n,e);return o.get?o.get.call(r):o.value}})(t,e,r||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 r,n=s(t);if(e){var o=s(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return l(this,r)}}function l(t,e){return!e||"object"!==u(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 s(t){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}o()(document).ready((function(){if("undefined"!=typeof wp&&"function"==typeof wp.Uploader){var t=wp.Uploader;wp.Uploader=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)}(l,t);var e,r,n,u=p(l);function l(){return i(this,l),u.apply(this,arguments)}return e=l,(r=[{key:"init",value:function(){c(s(l.prototype),"init",this).call(this),this.updateAutoWatermarkParam=this.updateAutoWatermarkParam.bind(this),o()("body").on("change",".ew-watermark-all-switch input",this.updateAutoWatermarkParam),this.param("auto_watermark",ew.autoWatermark)}},{key:"updateAutoWatermarkParam",value:function(t){ew.autoWatermark=o()(t.target).is(":checked"),this.param("auto_watermark",ew.autoWatermark)}}])&&a(e.prototype,r),n&&a(e,n),l}(t)}if("undefined"!=typeof wp&&wp.media&&"function"==typeof wp.media.view.UploaderInline){var e=wp.media.view.UploaderInline;wp.media.view.UploaderInline=e.extend({render:function(){e.prototype.render.apply(this,arguments),this.$el.hasClass("hidden")||this.$el.find(".ew-watermark-all-switch input").prop("checked",ew.autoWatermark)}})}}))},26:function(t,e){}});
1
+ !function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="../",r(r.s=15)}({0:function(e,t){e.exports=jQuery},15:function(e,t,r){"use strict";r.r(t);var n=r(0),o=r.n(n);r(26);function a(e){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function f(e,t){return!t||"object"!==a(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function c(e,t,r){return(c="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,r){var n=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=p(e)););return e}(e,t);if(n){var o=Object.getOwnPropertyDescriptor(n,t);return o.get?o.get.call(r):o.value}})(e,t,r||e)}function p(e){return(p=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function l(e,t){return(l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}o()(document).ready((function(){if("undefined"!=typeof wp&&"function"==typeof wp.Uploader){var e=wp.Uploader;wp.Uploader=function(e){function t(){return i(this,t),f(this,p(t).apply(this,arguments))}var r,n,a;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&l(e,t)}(t,e),r=t,(n=[{key:"init",value:function(){c(p(t.prototype),"init",this).call(this),this.updateAutoWatermarkParam=this.updateAutoWatermarkParam.bind(this),o()("body").on("change",".ew-watermark-all-switch input",this.updateAutoWatermarkParam),this.param("auto_watermark",ew.autoWatermark)}},{key:"updateAutoWatermarkParam",value:function(e){ew.autoWatermark=o()(e.target).is(":checked"),this.param("auto_watermark",ew.autoWatermark)}}])&&u(r.prototype,n),a&&u(r,a),t}(e)}if("undefined"!=typeof wp&&wp.media&&"function"==typeof wp.media.view.UploaderInline){var t=wp.media.view.UploaderInline;wp.media.view.UploaderInline=t.extend({render:function(){t.prototype.render.apply(this,arguments),this.$el.hasClass("hidden")||this.$el.find(".ew-watermark-all-switch input").prop("checked",ew.autoWatermark)}})}}))},26:function(e,t){}});
assets/dist/scripts/watermark-edit.js CHANGED
@@ -1,8 +1,8 @@
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/
5
  *
6
  * Licensed MIT © Zeno Rocha
7
  */
8
- var n;n=function(){return 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}return 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=6)}([function(t,e){t.exports=function(t){var e;if("SELECT"===t.nodeName)t.focus(),e=t.value;else if("INPUT"===t.nodeName||"TEXTAREA"===t.nodeName){var i=t.hasAttribute("readonly");i||t.setAttribute("readonly",""),t.select(),t.setSelectionRange(0,t.value.length),i||t.removeAttribute("readonly"),e=t.value}else{t.hasAttribute("contenteditable")&&t.focus();var n=window.getSelection(),r=document.createRange();r.selectNodeContents(t),n.removeAllRanges(),n.addRange(r),e=n.toString()}return e}},function(t,e){function i(){}i.prototype={on:function(t,e,i){var n=this.e||(this.e={});return(n[t]||(n[t]=[])).push({fn:e,ctx:i}),this},once:function(t,e,i){var n=this;function r(){n.off(t,r),e.apply(i,arguments)}return r._=e,this.on(t,r,i)},emit:function(t){for(var e=[].slice.call(arguments,1),i=((this.e||(this.e={}))[t]||[]).slice(),n=0,r=i.length;n<r;n++)i[n].fn.apply(i[n].ctx,e);return this},off:function(t,e){var i=this.e||(this.e={}),n=i[t],r=[];if(n&&e)for(var o=0,a=n.length;o<a;o++)n[o].fn!==e&&n[o].fn._!==e&&r.push(n[o]);return r.length?i[t]=r:delete i[t],this}},t.exports=i,t.exports.TinyEmitter=i},function(t,e,i){var n=i(3),r=i(4);t.exports=function(t,e,i){if(!t&&!e&&!i)throw new Error("Missing required arguments");if(!n.string(e))throw new TypeError("Second argument must be a String");if(!n.fn(i))throw new TypeError("Third argument must be a Function");if(n.node(t))return function(t,e,i){return t.addEventListener(e,i),{destroy:function(){t.removeEventListener(e,i)}}}(t,e,i);if(n.nodeList(t))return function(t,e,i){return Array.prototype.forEach.call(t,(function(t){t.addEventListener(e,i)})),{destroy:function(){Array.prototype.forEach.call(t,(function(t){t.removeEventListener(e,i)}))}}}(t,e,i);if(n.string(t))return function(t,e,i){return r(document.body,t,e,i)}(t,e,i);throw new TypeError("First argument must be a String, HTMLElement, HTMLCollection, or NodeList")}},function(t,e){e.node=function(t){return void 0!==t&&t instanceof HTMLElement&&1===t.nodeType},e.nodeList=function(t){var i=Object.prototype.toString.call(t);return void 0!==t&&("[object NodeList]"===i||"[object HTMLCollection]"===i)&&"length"in t&&(0===t.length||e.node(t[0]))},e.string=function(t){return"string"==typeof t||t instanceof String},e.fn=function(t){return"[object Function]"===Object.prototype.toString.call(t)}},function(t,e,i){var n=i(5);function r(t,e,i,n,r){var a=o.apply(this,arguments);return t.addEventListener(i,a,r),{destroy:function(){t.removeEventListener(i,a,r)}}}function o(t,e,i,r){return function(i){i.delegateTarget=n(i.target,e),i.delegateTarget&&r.call(t,i)}}t.exports=function(t,e,i,n,o){return"function"==typeof t.addEventListener?r.apply(null,arguments):"function"==typeof i?r.bind(null,document).apply(null,arguments):("string"==typeof t&&(t=document.querySelectorAll(t)),Array.prototype.map.call(t,(function(t){return r(t,e,i,n,o)})))}},function(t,e){if("undefined"!=typeof Element&&!Element.prototype.matches){var i=Element.prototype;i.matches=i.matchesSelector||i.mozMatchesSelector||i.msMatchesSelector||i.oMatchesSelector||i.webkitMatchesSelector}t.exports=function(t,e){for(;t&&9!==t.nodeType;){if("function"==typeof t.matches&&t.matches(e))return t;t=t.parentNode}}},function(t,e,i){"use strict";i.r(e);var n=i(0),r=i.n(n),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},a=function(){function t(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)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),s=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.resolveOptions(e),this.initSelection()}return a(t,[{key:"resolveOptions",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.action=t.action,this.container=t.container,this.emitter=t.emitter,this.target=t.target,this.text=t.text,this.trigger=t.trigger,this.selectedText=""}},{key:"initSelection",value:function(){this.text?this.selectFake():this.target&&this.selectTarget()}},{key:"selectFake",value:function(){var t=this,e="rtl"==document.documentElement.getAttribute("dir");this.removeFake(),this.fakeHandlerCallback=function(){return t.removeFake()},this.fakeHandler=this.container.addEventListener("click",this.fakeHandlerCallback)||!0,this.fakeElem=document.createElement("textarea"),this.fakeElem.style.fontSize="12pt",this.fakeElem.style.border="0",this.fakeElem.style.padding="0",this.fakeElem.style.margin="0",this.fakeElem.style.position="absolute",this.fakeElem.style[e?"right":"left"]="-9999px";var i=window.pageYOffset||document.documentElement.scrollTop;this.fakeElem.style.top=i+"px",this.fakeElem.setAttribute("readonly",""),this.fakeElem.value=this.text,this.container.appendChild(this.fakeElem),this.selectedText=r()(this.fakeElem),this.copyText()}},{key:"removeFake",value:function(){this.fakeHandler&&(this.container.removeEventListener("click",this.fakeHandlerCallback),this.fakeHandler=null,this.fakeHandlerCallback=null),this.fakeElem&&(this.container.removeChild(this.fakeElem),this.fakeElem=null)}},{key:"selectTarget",value:function(){this.selectedText=r()(this.target),this.copyText()}},{key:"copyText",value:function(){var t=void 0;try{t=document.execCommand(this.action)}catch(e){t=!1}this.handleResult(t)}},{key:"handleResult",value:function(t){this.emitter.emit(t?"success":"error",{action:this.action,text:this.selectedText,trigger:this.trigger,clearSelection:this.clearSelection.bind(this)})}},{key:"clearSelection",value:function(){this.trigger&&this.trigger.focus(),document.activeElement.blur(),window.getSelection().removeAllRanges()}},{key:"destroy",value:function(){this.removeFake()}},{key:"action",set:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"copy";if(this._action=t,"copy"!==this._action&&"cut"!==this._action)throw new Error('Invalid "action" value, use either "copy" or "cut"')},get:function(){return this._action}},{key:"target",set:function(t){if(void 0!==t){if(!t||"object"!==(void 0===t?"undefined":o(t))||1!==t.nodeType)throw new Error('Invalid "target" value, use a valid Element');if("copy"===this.action&&t.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');if("cut"===this.action&&(t.hasAttribute("readonly")||t.hasAttribute("disabled")))throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');this._target=t}},get:function(){return this._target}}]),t}(),c=i(1),l=i.n(c),u=i(2),h=i.n(u),f="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},d=function(){function t(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)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),p=function(t){function e(t,i){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var n=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return n.resolveOptions(i),n.listenClick(t),n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),d(e,[{key:"resolveOptions",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.action="function"==typeof t.action?t.action:this.defaultAction,this.target="function"==typeof t.target?t.target:this.defaultTarget,this.text="function"==typeof t.text?t.text:this.defaultText,this.container="object"===f(t.container)?t.container:document.body}},{key:"listenClick",value:function(t){var e=this;this.listener=h()(t,"click",(function(t){return e.onClick(t)}))}},{key:"onClick",value:function(t){var e=t.delegateTarget||t.currentTarget;this.clipboardAction&&(this.clipboardAction=null),this.clipboardAction=new s({action:this.action(e),target:this.target(e),text:this.text(e),container:this.container,trigger:e,emitter:this})}},{key:"defaultAction",value:function(t){return m("action",t)}},{key:"defaultTarget",value:function(t){var e=m("target",t);if(e)return document.querySelector(e)}},{key:"defaultText",value:function(t){return m("text",t)}},{key:"destroy",value:function(){this.listener.destroy(),this.clipboardAction&&(this.clipboardAction.destroy(),this.clipboardAction=null)}}],[{key:"isSupported",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:["copy","cut"],e="string"==typeof t?[t]:t,i=!!document.queryCommandSupported;return e.forEach((function(t){i=i&&!!document.queryCommandSupported(t)})),i}}]),e}(l.a);function m(t,e){var i="data-clipboard-"+t;if(e.hasAttribute(i))return e.getAttribute(i)}e.default=p}]).default},t.exports=n()}});
1
+ !function(e){var t={};function i(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,i),o.l=!0,o.exports}i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)i.d(n,o,function(t){return e[t]}.bind(null,o));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="../",i(i.s=19)}({0:function(e,t){e.exports=jQuery},1:function(e,t,i){"use strict";i.d(t,"a",(function(){return a})),i.d(t,"b",(function(){return s})),i.d(t,"c",(function(){return c})),i.d(t,"d",(function(){return l}));var n=i(0),o=i.n(n);function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function a(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"info",i=o()(document.createElement("div")),n=o()(document.createElement("p")),r=o()(document.createElement("button"));i.addClass("notice notice-"+t+" is-dismissible").hide(),r.addClass("notice-dismiss"),n.html(e),i.append(n).append(r),r.on("click",(function(e){e.preventDefault(),i.fadeOut(200,(function(){i.remove()}))})),o()("hr.wp-header-end").after(i),i.fadeIn(200)}function s(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],n=e.length,o=!0,r=!1,a=void 0;try{for(var s,c=e.clone().models[Symbol.iterator]();!(o=(s=c.next()).done);o=!0){var u=s.value;(!l(u)||u.get("usedAsWatermark")||!0===t&&!u.get("hasBackup"))&&(!0===i&&e.remove(u),n--)}}catch(e){r=!0,a=e}finally{try{o||null==c.return||c.return()}finally{if(r)throw a}}return n}function c(e){var t,i=e.indexOf("?"),n="t=".concat(Date.now());if(-1!==i){t=e.substr(i),e=e.substr(0,i);var o=/([^\s])t=[0-9]+/;t.match(o)?t=t.replace(o,"$1".concat(n)):t+="&".concat(n)}else t="?".concat(n);return e+t}function l(e){return"object"===r(e)&&e.get&&(e=e.get("mime")),Object.keys(ew.mime).includes(e)}},19:function(e,t,i){"use strict";i.r(t);var n=i(0),o=i.n(n),r=(i(32),i(1));function a(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var s=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.metabox=o()("#watermark-content"),this.form=o()("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 t,i,n;return t=e,(i=[{key:"enable",value:function(e){this.metabox.fadeIn(200),"image"===e?(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 e=this;clearTimeout(this.textChangeTimeout),this.textChangeTimeout=setTimeout((function(){e.form.trigger("ew.save")}),500)}},{key:"prepareTextPreview",value:function(){this.previewWrap||(this.previewWrap=this.metabox.find(".text-preview"),this.preview=o()(document.createElement("img")),this.previewWrap.hide().append(this.preview)),this.refreshPreview()}},{key:"refreshPreview",value:function(){if(this.watermarkTextField.val().length){var e=Object(r.c)(this.previewWrap.data("src"));this.preview.attr("src",e),this.previewWrap.show()}else this.previewWrap.hide()}},{key:"openMediaLibrary",value:function(e){e.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 e=this.frame.state().get("selection").first(),t=e.get("mime"),i=e.get("url");this.attachmentId=e.get("id"),this.mimeTypeField.val(t),this.urlField.val(i),this.attachmentIdField.val(this.attachmentId),this.switchOpacityField(t),this.image.attr("src",i),this.imageWrap.show(),this.buttonWrap.hide(),this.form.trigger("ew.save")}},{key:"applySelection",value:function(){if(this.attachmentId){var e=this.frame.state().get("selection"),t=wp.media.attachment(this.attachmentId);t.fetch(),t&&e.add([t])}}},{key:"checkSelectedAttachment",value:function(){var e=wp.media.attachment(this.attachmentId);e.fetch(),e&&!0!==e.destroyed||(this.mimeTypeField.val(""),this.urlField.val(""),this.attachmentIdField.val(""),this.imageWrap.hide(),this.buttonWrap.show())}},{key:"switchOpacityField",value:function(e){"image/png"===e?(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(t.prototype,i),n&&a(t,n),e}();function c(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var l=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.metabox=o()("#alignment")}var t,i,n;return t=e,(i=[{key:"enable",value:function(){this.metabox.fadeIn(200)}}])&&c(t.prototype,i),n&&c(t,n),e}();function u(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var h=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.metabox=o()("#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 t,i,n;return t=e,(i=[{key:"enable",value:function(){this.metabox.fadeIn(200)}},{key:"toggleOptionsVisibility",value:function(){this.autoAddCheckbox.prop("checked")?this.hiddenSections.show():this.hiddenSections.hide()}}])&&u(t.prototype,i),n&&u(t,n),e}();function f(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var d=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.metabox=o()("#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 t,i,n;return t=e,(i=[{key:"enable",value:function(e){"image"===e?(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(t.prototype,i),n&&f(t,n),e}();function p(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var m=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.metabox=o()("#text-options"),this.form=o()("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 t,i,n;return t=e,(i=[{key:"colorChanged",value:function(){var e=this;clearTimeout(this.colorChangeTimeout),this.colorChangeTimeout=setTimeout((function(){e.form.trigger("ew.save")}),500)}},{key:"enable",value:function(e){"text"===e?(this.metabox.fadeIn(200),this.fields.prop("disabled",!1)):(this.metabox.hide(),this.fields.prop("disabled",!0))}}])&&p(t.prototype,i),n&&p(t,n),e}();function y(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var b=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.metabox=o()("#preview"),this.body=o()("body"),this.form=o()("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=o()(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 t,i,n;return t=e,(i=[{key:"enable",value:function(){this.metabox.fadeIn(200)}},{key:"openMediaLibrary",value:function(e){e.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 e=this.frame.state().get("selection").first(),t=this.form.find("input[name=post_ID]").val();this.contentWrap.hide(),this.spinner.css("display","block"),o.a.ajax({type:"post",url:ajaxurl,data:{action:"easy-watermark/preview_image",attachment_id:e.id,watermark_id:t,nonce:ew.previewImageNonce}}).done(this.imageSelected).fail((function(){}))}},{key:"imageSelected",value:function(e){if(!0===e.success){if(this.link.html(this.link.data("changeLabel")),this.hasImage=!0,e.data.popup){var t=o()(e.data.popup);this.popup.find(".media-frame-content").replaceWith(t.find(".media-frame-content"))}this.refreshPreview()}}},{key:"refreshPreview",value:function(){var e=this;if(this.contentWrap.hide(),this.hasImage){this.imageSelector.hide(),this.spinner.css("display","block");var t=Object(r.c)(this.previewWrap.data("src"));this.popup.find("img").each((function(e,t){var i=o()(t),n=Object(r.c)(i.attr("src"));i.attr("src",n)})),this.image.one("load",(function(){e.spinner.hide(),e.contentWrap.fadeIn(200),e.imageSelector.fadeIn(200)})).attr("src",t)}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 e=this.form.find("input.watermark-type:checked").val();return!("text"!==e||!this.watermarkTextField.val().length)||!("image"!==e||!this.attachmentIdField.val().length)}},{key:"update",value:function(){this.refreshPreview()}}])&&y(t.prototype,i),n&&y(t,n),e}(),v=i(4),g=i.n(v);function w(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var k=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.metabox=o()("#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 t,i,n;return t=e,(i=[{key:"enable",value:function(e){"text"===e?this.metabox.fadeIn(200):this.metabox.hide()}},{key:"clipboardSuccess",value:function(e){var t=o()(e.trigger);t.text("Copied"),setTimeout((function(){t.text(e.text)}),1e3)}},{key:"filterPlaceholders",value:function(e){var t=o()(e.target).val();this.placeholders.hide().each((function(e,i){var n=o()(i);-1!==n.find("code").text().toLowerCase().indexOf(t)&&n.show()}))}}])&&w(t.prototype,i),n&&w(t,n),e}();function x(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var S=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.fields=o()(".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 t,i,n;return t=e,(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),o()(document).on("click",this.hideDropdowns)}},{key:"toggleDropdown",value:function(e){e.preventDefault();var t=o()(e.target),i=t.position();t.toggleClass("is-open"),t.next(".dropdown-menu").css({left:i.left,top:i.top+t.height()}).toggle()}},{key:"dropdownSelect",value:function(e){e.preventDefault();var t=o()(e.target),i=t.closest(".dropdown-menu"),n=o()(i.data("target"));n.length&&(n.val(t.data("value")),i.prev("button[data-toggle=dropdown]").text(t.text()))}},{key:"hideDropdowns",value:function(e){o()(e.target).is(this.buttons)||(this.buttons.removeClass("is-open"),this.dropdowns.hide())}}])&&x(t.prototype,i),n&&x(t,n),e}();function T(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var E=function(){function e(){var t=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.selectWatermarkType=this.selectWatermarkType.bind(this),this.triggerSave=this.triggerSave.bind(this),this.form=o()("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(e){t.selectWatermarkType(e.target.value)})),this.form.on("change","input, select",this.triggerSave).on("ew.save",this.triggerSave)}var t,i,n;return t=e,(i=[{key:"selectWatermarkType",value:function(e){var t=!0,i=!1,n=void 0;try{for(var o,r=this.metaboxes[Symbol.iterator]();!(t=(o=r.next()).done);t=!0)o.value.enable(e)}catch(e){i=!0,n=e}finally{try{t||null==r.return||r.return()}finally{if(i)throw n}}}},{key:"triggerSave",value:function(){var e=this,t={action:"easy-watermark/autosave",nonce:ew.autosaveNonce},i=this.form.find("[name^=watermark], [name=post_ID]").serialize();for(var n in t)i+="&"+encodeURIComponent(n)+"="+encodeURIComponent(t[n]);o.a.ajax({type:"post",url:ajaxurl,data:i}).done((function(t){!0===t.success&&e.form.trigger("ew.update")})).fail((function(){}))}}])&&T(t.prototype,i),n&&T(t,n),e}();o()(document).ready((function(){return new E}))},32:function(e,t){},4:function(e,t,i){
2
  /*!
3
  * clipboard.js v2.0.6
4
  * https://clipboardjs.com/
5
  *
6
  * Licensed MIT © Zeno Rocha
7
  */
8
+ var n;n=function(){return function(e){var t={};function i(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,i),o.l=!0,o.exports}return i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)i.d(n,o,function(t){return e[t]}.bind(null,o));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=6)}([function(e,t){e.exports=function(e){var t;if("SELECT"===e.nodeName)e.focus(),t=e.value;else if("INPUT"===e.nodeName||"TEXTAREA"===e.nodeName){var i=e.hasAttribute("readonly");i||e.setAttribute("readonly",""),e.select(),e.setSelectionRange(0,e.value.length),i||e.removeAttribute("readonly"),t=e.value}else{e.hasAttribute("contenteditable")&&e.focus();var n=window.getSelection(),o=document.createRange();o.selectNodeContents(e),n.removeAllRanges(),n.addRange(o),t=n.toString()}return t}},function(e,t){function i(){}i.prototype={on:function(e,t,i){var n=this.e||(this.e={});return(n[e]||(n[e]=[])).push({fn:t,ctx:i}),this},once:function(e,t,i){var n=this;function o(){n.off(e,o),t.apply(i,arguments)}return o._=t,this.on(e,o,i)},emit:function(e){for(var t=[].slice.call(arguments,1),i=((this.e||(this.e={}))[e]||[]).slice(),n=0,o=i.length;n<o;n++)i[n].fn.apply(i[n].ctx,t);return this},off:function(e,t){var i=this.e||(this.e={}),n=i[e],o=[];if(n&&t)for(var r=0,a=n.length;r<a;r++)n[r].fn!==t&&n[r].fn._!==t&&o.push(n[r]);return o.length?i[e]=o:delete i[e],this}},e.exports=i,e.exports.TinyEmitter=i},function(e,t,i){var n=i(3),o=i(4);e.exports=function(e,t,i){if(!e&&!t&&!i)throw new Error("Missing required arguments");if(!n.string(t))throw new TypeError("Second argument must be a String");if(!n.fn(i))throw new TypeError("Third argument must be a Function");if(n.node(e))return function(e,t,i){return e.addEventListener(t,i),{destroy:function(){e.removeEventListener(t,i)}}}(e,t,i);if(n.nodeList(e))return function(e,t,i){return Array.prototype.forEach.call(e,(function(e){e.addEventListener(t,i)})),{destroy:function(){Array.prototype.forEach.call(e,(function(e){e.removeEventListener(t,i)}))}}}(e,t,i);if(n.string(e))return function(e,t,i){return o(document.body,e,t,i)}(e,t,i);throw new TypeError("First argument must be a String, HTMLElement, HTMLCollection, or NodeList")}},function(e,t){t.node=function(e){return void 0!==e&&e instanceof HTMLElement&&1===e.nodeType},t.nodeList=function(e){var i=Object.prototype.toString.call(e);return void 0!==e&&("[object NodeList]"===i||"[object HTMLCollection]"===i)&&"length"in e&&(0===e.length||t.node(e[0]))},t.string=function(e){return"string"==typeof e||e instanceof String},t.fn=function(e){return"[object Function]"===Object.prototype.toString.call(e)}},function(e,t,i){var n=i(5);function o(e,t,i,n,o){var a=r.apply(this,arguments);return e.addEventListener(i,a,o),{destroy:function(){e.removeEventListener(i,a,o)}}}function r(e,t,i,o){return function(i){i.delegateTarget=n(i.target,t),i.delegateTarget&&o.call(e,i)}}e.exports=function(e,t,i,n,r){return"function"==typeof e.addEventListener?o.apply(null,arguments):"function"==typeof i?o.bind(null,document).apply(null,arguments):("string"==typeof e&&(e=document.querySelectorAll(e)),Array.prototype.map.call(e,(function(e){return o(e,t,i,n,r)})))}},function(e,t){if("undefined"!=typeof Element&&!Element.prototype.matches){var i=Element.prototype;i.matches=i.matchesSelector||i.mozMatchesSelector||i.msMatchesSelector||i.oMatchesSelector||i.webkitMatchesSelector}e.exports=function(e,t){for(;e&&9!==e.nodeType;){if("function"==typeof e.matches&&e.matches(t))return e;e=e.parentNode}}},function(e,t,i){"use strict";i.r(t);var n=i(0),o=i.n(n),r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a=function(){function e(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),t}}(),s=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.resolveOptions(t),this.initSelection()}return a(e,[{key:"resolveOptions",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.action=e.action,this.container=e.container,this.emitter=e.emitter,this.target=e.target,this.text=e.text,this.trigger=e.trigger,this.selectedText=""}},{key:"initSelection",value:function(){this.text?this.selectFake():this.target&&this.selectTarget()}},{key:"selectFake",value:function(){var e=this,t="rtl"==document.documentElement.getAttribute("dir");this.removeFake(),this.fakeHandlerCallback=function(){return e.removeFake()},this.fakeHandler=this.container.addEventListener("click",this.fakeHandlerCallback)||!0,this.fakeElem=document.createElement("textarea"),this.fakeElem.style.fontSize="12pt",this.fakeElem.style.border="0",this.fakeElem.style.padding="0",this.fakeElem.style.margin="0",this.fakeElem.style.position="absolute",this.fakeElem.style[t?"right":"left"]="-9999px";var i=window.pageYOffset||document.documentElement.scrollTop;this.fakeElem.style.top=i+"px",this.fakeElem.setAttribute("readonly",""),this.fakeElem.value=this.text,this.container.appendChild(this.fakeElem),this.selectedText=o()(this.fakeElem),this.copyText()}},{key:"removeFake",value:function(){this.fakeHandler&&(this.container.removeEventListener("click",this.fakeHandlerCallback),this.fakeHandler=null,this.fakeHandlerCallback=null),this.fakeElem&&(this.container.removeChild(this.fakeElem),this.fakeElem=null)}},{key:"selectTarget",value:function(){this.selectedText=o()(this.target),this.copyText()}},{key:"copyText",value:function(){var e=void 0;try{e=document.execCommand(this.action)}catch(t){e=!1}this.handleResult(e)}},{key:"handleResult",value:function(e){this.emitter.emit(e?"success":"error",{action:this.action,text:this.selectedText,trigger:this.trigger,clearSelection:this.clearSelection.bind(this)})}},{key:"clearSelection",value:function(){this.trigger&&this.trigger.focus(),document.activeElement.blur(),window.getSelection().removeAllRanges()}},{key:"destroy",value:function(){this.removeFake()}},{key:"action",set:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"copy";if(this._action=e,"copy"!==this._action&&"cut"!==this._action)throw new Error('Invalid "action" value, use either "copy" or "cut"')},get:function(){return this._action}},{key:"target",set:function(e){if(void 0!==e){if(!e||"object"!==(void 0===e?"undefined":r(e))||1!==e.nodeType)throw new Error('Invalid "target" value, use a valid Element');if("copy"===this.action&&e.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');if("cut"===this.action&&(e.hasAttribute("readonly")||e.hasAttribute("disabled")))throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');this._target=e}},get:function(){return this._target}}]),e}(),c=i(1),l=i.n(c),u=i(2),h=i.n(u),f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},d=function(){function e(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),t}}(),p=function(e){function t(e,i){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var n=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return n.resolveOptions(i),n.listenClick(e),n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),d(t,[{key:"resolveOptions",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.action="function"==typeof e.action?e.action:this.defaultAction,this.target="function"==typeof e.target?e.target:this.defaultTarget,this.text="function"==typeof e.text?e.text:this.defaultText,this.container="object"===f(e.container)?e.container:document.body}},{key:"listenClick",value:function(e){var t=this;this.listener=h()(e,"click",(function(e){return t.onClick(e)}))}},{key:"onClick",value:function(e){var t=e.delegateTarget||e.currentTarget;this.clipboardAction&&(this.clipboardAction=null),this.clipboardAction=new s({action:this.action(t),target:this.target(t),text:this.text(t),container:this.container,trigger:t,emitter:this})}},{key:"defaultAction",value:function(e){return m("action",e)}},{key:"defaultTarget",value:function(e){var t=m("target",e);if(t)return document.querySelector(t)}},{key:"defaultText",value:function(e){return m("text",e)}},{key:"destroy",value:function(){this.listener.destroy(),this.clipboardAction&&(this.clipboardAction.destroy(),this.clipboardAction=null)}}],[{key:"isSupported",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:["copy","cut"],t="string"==typeof e?[e]:e,i=!!document.queryCommandSupported;return t.forEach((function(e){i=i&&!!document.queryCommandSupported(e)})),i}}]),t}(l.a);function m(e,t){var i="data-clipboard-"+e;if(t.hasAttribute(i))return t.getAttribute(i)}t.default=p}]).default},e.exports=n()}});
assets/src/fonts/Arial.ttf DELETED
Binary file
assets/src/fonts/Arial_Black.ttf DELETED
Binary file
assets/src/fonts/Comic_Sans_MS.ttf DELETED
Binary file
assets/src/fonts/Courier_New.ttf DELETED
Binary file
assets/src/fonts/Georgia.ttf DELETED
Binary file
assets/src/fonts/Impact.ttf DELETED
Binary file
assets/src/fonts/Tahoma.ttf DELETED
Binary file
assets/src/fonts/Times_New_Roman.ttf DELETED
Binary file
assets/src/fonts/Trebuchet_MS.ttf DELETED
Binary file
assets/src/fonts/Verdana.ttf DELETED
Binary file
assets/src/images/alignment-background.jpg DELETED
Binary file
assets/src/scripts/attachment-edit.js DELETED
@@ -1,8 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import '../styles/attachment-edit.scss';
5
-
6
- import WatermarksMetabox from './metaboxes/attachment/watermarks.js';
7
-
8
- new WatermarksMetabox();
 
 
 
 
 
 
 
 
assets/src/scripts/controllers/bulk-actions.js DELETED
@@ -1,322 +0,0 @@
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 DELETED
@@ -1,211 +0,0 @@
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/dashboard.js DELETED
@@ -1,29 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import Settings from './pages/settings';
5
- import Watermarks from './pages/watermarks';
6
- import Tools from './pages/tools';
7
-
8
- import '../styles/dashboard.scss';
9
-
10
- /**
11
- * External dependencies
12
- */
13
- import $ from 'jquery';
14
-
15
- $( document ).ready( () => {
16
- const currentTab = $( 'a.nav-tab-active' ).data( 'tab' );
17
-
18
- switch ( currentTab ) {
19
- case 'settings':
20
- new Settings;
21
- break;
22
- case 'watermarks':
23
- new Watermarks;
24
- break;
25
- case 'tools':
26
- new Tools;
27
- break;
28
- }
29
- } );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/scripts/includes/vex.js DELETED
@@ -1,56 +0,0 @@
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/media-library.js DELETED
@@ -1,11 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import '../styles/media-library.scss';
5
-
6
- import './views/media-grid/attachment';
7
- import './views/media-grid/attachments-browser';
8
- import './views/media-grid/select-mode-toggle';
9
- import './views/media-grid/filters';
10
- import './controllers/media-frame';
11
- import './controllers/bulk-actions';
 
 
 
 
 
 
 
 
 
 
 
assets/src/scripts/metaboxes/attachment/watermarks.js DELETED
@@ -1,83 +0,0 @@
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/alignment.js DELETED
@@ -1,14 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
-
6
- export default class {
7
- constructor() {
8
- this.metabox = $( '#alignment' );
9
- }
10
-
11
- enable() {
12
- this.metabox.fadeIn( 200 );
13
- }
14
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/scripts/metaboxes/watermark/applying-rules.js DELETED
@@ -1,30 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
-
6
- export default class {
7
- constructor() {
8
- this.metabox = $( '#applying-rules' );
9
- this.autoAddCheckbox = this.metabox.find( '#watermark-autoadd' );
10
- this.hiddenSections = this.metabox.find( '.hidden' );
11
-
12
- this.toggleOptionsVisibility = this.toggleOptionsVisibility.bind( this );
13
-
14
- this.autoAddCheckbox.on( 'change', this.toggleOptionsVisibility );
15
-
16
- this.toggleOptionsVisibility();
17
- }
18
-
19
- enable() {
20
- this.metabox.fadeIn( 200 );
21
- }
22
-
23
- toggleOptionsVisibility() {
24
- if ( this.autoAddCheckbox.prop( 'checked' ) ) {
25
- this.hiddenSections.show();
26
- } else {
27
- this.hiddenSections.hide();
28
- }
29
- }
30
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/scripts/metaboxes/watermark/content.js DELETED
@@ -1,193 +0,0 @@
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/placeholders.js DELETED
@@ -1,52 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
- import Clipboard from 'clipboard';
6
-
7
- export default class {
8
- constructor() {
9
- this.metabox = $( '#placeholders' );
10
- this.placeholders = this.metabox.find( '.placeholders-list li' );
11
- this.searchField = this.metabox.find( 'input.ew-search-placeholders' );
12
-
13
- this.clipboard = new Clipboard( '.placeholders-list code' );
14
-
15
- this.clipboardSuccess = this.clipboardSuccess.bind( this );
16
- this.filterPlaceholders = this.filterPlaceholders.bind( this );
17
-
18
- this.clipboard.on( 'success', this.clipboardSuccess );
19
- this.searchField.on( 'keyup', this.filterPlaceholders );
20
- }
21
-
22
- enable( type ) {
23
- if ( type === 'text' ) {
24
- this.metabox.fadeIn( 200 );
25
- } else {
26
- this.metabox.hide();
27
- }
28
- }
29
-
30
- clipboardSuccess( e ) {
31
- const item = $( e.trigger );
32
-
33
- item.text( 'Copied' );
34
-
35
- setTimeout( () => {
36
- item.text( e.text );
37
- }, 1000 );
38
- }
39
-
40
- filterPlaceholders( e ) {
41
- const val = $( e.target ).val();
42
-
43
- this.placeholders.hide().each( ( n, item ) => {
44
- const $item = $( item ),
45
- text = $item.find( 'code' ).text().toLowerCase();
46
-
47
- if ( text.indexOf( val ) !== -1 ) {
48
- $item.show();
49
- }
50
- } );
51
- }
52
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/scripts/metaboxes/watermark/preview.js DELETED
@@ -1,171 +0,0 @@
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/metaboxes/watermark/scaling.js DELETED
@@ -1,44 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
-
6
- export default class {
7
- constructor() {
8
- this.metabox = $( '#scaling' );
9
- this.scalingModeSelect = this.metabox.find( '#watermark-scaling-mode' );
10
- this.hiddenSections = this.metabox.find( '.hidden' );
11
- this.fields = this.metabox.find( 'input, select' );
12
-
13
- this.toggleOptionsVisibility = this.toggleOptionsVisibility.bind( this );
14
-
15
- this.scalingModeSelect.on( 'change', this.toggleOptionsVisibility );
16
-
17
- this.toggleOptionsVisibility();
18
- }
19
-
20
- enable( type ) {
21
- if ( type === 'image' ) {
22
- this.metabox.fadeIn( 200 );
23
- this.fields.prop( 'disabled', false );
24
- } else {
25
- this.metabox.hide();
26
- this.fields.prop( 'disabled', true );
27
- }
28
- }
29
-
30
- toggleOptionsVisibility() {
31
- this.hiddenSections.hide();
32
-
33
- switch ( this.scalingModeSelect.val() ) {
34
- case 'fit_to_width' :
35
- case 'fit_to_height' :
36
- this.hiddenSections.show();
37
- break;
38
- case 'cover' :
39
- case 'contain' :
40
- this.hiddenSections.filter( '.show-for-all' ).show();
41
- break;
42
- }
43
- }
44
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/scripts/metaboxes/watermark/text-options.js DELETED
@@ -1,40 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
-
6
- export default class {
7
- constructor() {
8
- this.metabox = $( '#text-options' );
9
- this.form = $( 'form#post' );
10
- this.colorInput = this.metabox.find( '#text-color' );
11
- this.fields = this.metabox.find( 'input, select' );
12
-
13
- this.colorChangeTimeout = null;
14
-
15
- this.colorChanged = this.colorChanged.bind( this );
16
-
17
- this.colorInput.wpColorPicker( {
18
- palettes: true,
19
- change: this.colorChanged,
20
- } );
21
- }
22
-
23
- colorChanged() {
24
- clearTimeout( this.colorChangeTimeout );
25
-
26
- this.colorChangeTimeout = setTimeout( () => {
27
- this.form.trigger( 'ew.save' );
28
- }, 500 );
29
- }
30
-
31
- enable( type ) {
32
- if ( type === 'text' ) {
33
- this.metabox.fadeIn( 200 );
34
- this.fields.prop( 'disabled', false );
35
- } else {
36
- this.metabox.hide();
37
- this.fields.prop( 'disabled', true );
38
- }
39
- }
40
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/scripts/pages/bulk-actions.js DELETED
@@ -1,322 +0,0 @@
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/settings.js DELETED
@@ -1,38 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import $ from 'jquery';
5
-
6
- export default class {
7
- constructor() {
8
- this.form = $( 'form#easy-watermark-settings-form' );
9
-
10
- if ( this.form.length ) {
11
- this.init();
12
- }
13
- }
14
-
15
- init() {
16
- this.toggleGroup = this.toggleGroup.bind( this );
17
-
18
- this.checkboxes = this.form.find( 'input[data-toggle]' );
19
- this.checkboxes.on( 'change', this.toggleGroup );
20
- this.checkboxes.change();
21
- }
22
-
23
- toggleGroup( e ) {
24
- const
25
- checkbox = $( e.target ),
26
- group = checkbox.data( 'toggle' ),
27
- rows = this.form.find( `.group-${ group }` ),
28
- fields = rows.find( 'input, textarea, select' );
29
-
30
- if ( true === checkbox.is( ':checked' ) ) {
31
- rows.show();
32
- fields.prop( 'disabled', false );
33
- } else {
34
- rows.hide();
35
- fields.prop( 'disabled', true );
36
- }
37
- }
38
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/scripts/pages/tools.js DELETED
@@ -1,192 +0,0 @@
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 DELETED
@@ -1,44 +0,0 @@
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 DELETED
@@ -1,49 +0,0 @@
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 DELETED
@@ -1,64 +0,0 @@
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 DELETED
@@ -1,79 +0,0 @@
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 DELETED
@@ -1,100 +0,0 @@
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 DELETED
@@ -1,89 +0,0 @@
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 DELETED
@@ -1,66 +0,0 @@
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 DELETED
@@ -1,79 +0,0 @@
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 DELETED
@@ -1,51 +0,0 @@
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 DELETED
@@ -1,45 +0,0 @@
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 DELETED
@@ -1,32 +0,0 @@
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 DELETED
@@ -1,66 +0,0 @@
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 DELETED
@@ -1,70 +0,0 @@
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 DELETED
@@ -1,76 +0,0 @@
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/status.js DELETED
@@ -1,72 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import View from './view';
5
-
6
- export default class extends View {
7
- tagName() {
8
- return 'p';
9
- }
10
-
11
- className() {
12
- return 'ew-status';
13
- }
14
-
15
- template() {
16
- let text = this.status.get( 'text' );
17
-
18
- if ( this.status.get( 'processing' ) ) {
19
- const
20
- processed = this.status.get( 'processed' ),
21
- total = this.status.get( 'total' ),
22
- counter = `${ processed }/${ total }`;
23
-
24
- let percent = Math.floor( processed / total * 100 );
25
-
26
- if ( 'string' === typeof text ) {
27
- text = text.replace( '{counter}', counter );
28
- }
29
-
30
- if ( isNaN( percent ) ) {
31
- percent = 0;
32
- }
33
-
34
- text = `${ text } (${ percent }%)`;
35
- }
36
-
37
- return text;
38
- }
39
-
40
- constructor( options ) {
41
- super( options );
42
-
43
- this.status = this.controller.status();
44
-
45
- this.listenTo( this.status, 'change', this.update );
46
- }
47
-
48
- render() {
49
- super.render();
50
- this.attach();
51
- }
52
-
53
- update() {
54
- if ( ! this.bulkActionSelector.is( this.controller.get( 'select' ) ) ) {
55
- return;
56
- }
57
-
58
- if ( this.status.get( 'text' ) ) {
59
- this.$el.html( this.template() );
60
- this.$el.show();
61
- } else {
62
- this.$el.hide();
63
- }
64
- }
65
-
66
- attach() {
67
- this.bulkActionSelector.parent().append( this.$el );
68
- this.$el.hide();
69
-
70
- return this;
71
- }
72
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/scripts/views/media-list/view.js DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { View } from 'backbone';
5
-
6
- export default class extends View {
7
- constructor( options ) {
8
- super( options );
9
-
10
- this.controller = options.controller;
11
- this.bulkActionSelector = options.bulkActionSelector;
12
- }
13
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/scripts/views/media-list/watermark-selector.js DELETED
@@ -1,79 +0,0 @@
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/views/tools/bulk-watermark.js DELETED
@@ -1,58 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import Tool from './tool';
5
-
6
- export default class extends Tool {
7
- constructor( options ) {
8
- options.el = '.tool-bulk-watermark';
9
-
10
- super( options );
11
-
12
- this.action = 'watermark';
13
-
14
- this.selectWatermark = this.selectWatermark.bind( this );
15
- this.toggleButton = this.toggleButton.bind( this );
16
-
17
- this.select = this.$el.find( 'select' );
18
- this.select.on( 'change', this.selectWatermark );
19
-
20
- this.toggleButton();
21
- }
22
-
23
- selectWatermark() {
24
- const
25
- watermark = this.select.val(),
26
- nonce = this.select.find( 'option:selected' ).data( 'nonce' );
27
-
28
- this.state.set( {
29
- watermark,
30
- nonce,
31
- } );
32
-
33
- this.toggleButton();
34
- }
35
-
36
- toggleButton() {
37
- if ( '-1' === this.select.val() ) {
38
- this.button.addClass( 'disabled' );
39
- } else {
40
- this.button.removeClass( 'disabled' );
41
- }
42
- }
43
-
44
- disable() {
45
- super.disable();
46
- this.select.prop( { disabled: true } );
47
- }
48
-
49
- processing() {
50
- this.select.val( '-1' );
51
- super.processing();
52
- }
53
-
54
- reset() {
55
- super.reset();
56
- this.select.prop( { disabled: false } ).change();
57
- }
58
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/scripts/views/tools/restore.js DELETED
@@ -1,50 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import Tool from './tool';
5
-
6
- export default class extends Tool {
7
- constructor( options ) {
8
- options.el = '.tool-restore';
9
-
10
- super( options );
11
-
12
- this.action = 'restore';
13
-
14
- this.backupInfo = this.$el.find( 'p.has-backup' );
15
- this.noBackupInfo = this.$el.find( 'p.no-backup' );
16
- this.backupCountInfo = this.$el.find( '.backup-count' );
17
-
18
- this.state.set( {
19
- backupCount: this.$el.data( 'backup-count' ),
20
- } );
21
-
22
- this.toggleInfo();
23
- }
24
-
25
- handleClick() {
26
- this.state.set( {
27
- nonce: this.button.data( 'nonce' ),
28
- } );
29
-
30
- super.handleClick();
31
- }
32
-
33
- toggleInfo() {
34
- const backupCount = this.state.get( 'backupCount' );
35
-
36
- if ( 0 < backupCount ) {
37
- this.backupCountInfo.text( backupCount );
38
- this.backupInfo.show();
39
- this.noBackupInfo.hide();
40
- } else {
41
- this.backupInfo.hide();
42
- this.noBackupInfo.show();
43
- }
44
- }
45
-
46
- update() {
47
- super.update();
48
- this.toggleInfo();
49
- }
50
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/scripts/views/tools/tool.js DELETED
@@ -1,92 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { View } from 'backbone';
5
-
6
- export default class extends View {
7
- constructor( options ) {
8
- super( options );
9
-
10
- this.state = options.state;
11
- this.callback = options.callback;
12
-
13
- this.handleClick = this.handleClick.bind( this );
14
-
15
- this.button = this.$el.find( 'a' );
16
- this.spinner = this.$el.find( '.spinner' );
17
- this.content = this.$el.find( '.content' );
18
- this.status = this.$el.find( '.status' );
19
-
20
- this.button.on( 'click', this.handleClick );
21
-
22
- this.mode = this.state.get( 'mode' );
23
- this.state.on( 'change', this.update, this );
24
- }
25
-
26
- template() {
27
- const
28
- processed = this.state.get( 'processed' ),
29
- total = this.state.get( 'total' ),
30
- percent = Math.floor( processed / total * 100 );
31
-
32
- let text = this.state.get( 'statusText' );
33
-
34
- text = text.replace( '{counter}', `${ processed }/${ total }` );
35
- return `${ text } (${ percent }%)`;
36
- }
37
-
38
- handleClick() {
39
- if ( ! this.button.hasClass( 'disabled' ) ) {
40
- this.callback();
41
- }
42
- }
43
-
44
- update() {
45
- const
46
- mode = this.state.get( 'mode' ),
47
- action = this.state.get( 'action' );
48
-
49
- if ( this.mode !== mode ) {
50
- this.toggleMode( mode );
51
- }
52
-
53
- if ( 'processing' === mode && this.action === action ) {
54
- this.status.html( this.template() );
55
- }
56
- }
57
-
58
- toggleMode( mode ) {
59
- this.mode = mode;
60
-
61
- if ( this.action !== this.state.get( 'action' ) && ( 'loading' === mode || 'processing' === mode ) ) {
62
- this.disable();
63
- } else if ( 'loading' === mode ) {
64
- this.loading();
65
- } else if ( 'processing' === mode ) {
66
- this.processing();
67
- } else {
68
- this.reset();
69
- }
70
- }
71
-
72
- disable() {
73
- this.button.addClass( 'disabled' );
74
- }
75
-
76
- loading() {
77
- this.disable();
78
- this.spinner.css( { visibility: 'visible' } );
79
- }
80
-
81
- processing() {
82
- this.content.hide();
83
- this.status.show();
84
- }
85
-
86
- reset() {
87
- this.spinner.css( { visibility: 'hidden' } );
88
- this.status.hide();
89
- this.content.show();
90
- this.button.removeClass( 'disabled' );
91
- }
92
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/scripts/watermark-edit.js DELETED
@@ -1,90 +0,0 @@
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/_edit-screen.scss DELETED
@@ -1,51 +0,0 @@
1
- body {
2
-
3
- &.post-type-watermark {
4
-
5
- #poststuff {
6
-
7
- .watermark-type-selector {
8
-
9
- h2 {
10
- padding-left: 0;
11
- }
12
-
13
- .buttons {
14
- display: flex;
15
- }
16
-
17
- .button {
18
-
19
- &.first {
20
- border-bottom-right-radius: 0;
21
- border-top-right-radius: 0;
22
- }
23
-
24
- &.last {
25
- border-bottom-left-radius: 0;
26
- border-top-left-radius: 0;
27
- }
28
- }
29
-
30
- input[type="radio"] {
31
- opacity: 0;
32
- position: absolute;
33
- z-index: -1;
34
-
35
- &:checked + .button {
36
- background: #0085ba;
37
- border-color: #0073aa #006799 #006799;
38
- box-shadow: 0 1px 0 #006799;
39
- color: #fff;
40
- text-decoration: none;
41
- text-shadow: 0 -1px 1px #006799, 1px 0 1px #006799, 0 1px 1px #006799, -1px 0 1px #006799;
42
-
43
- &:active {
44
- transform: none;
45
- }
46
- }
47
- }
48
- }
49
- }
50
- }
51
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/styles/_general.scss DELETED
@@ -1,209 +0,0 @@
1
- body {
2
-
3
- &.post-type-watermark,
4
- &.settings_page_easy-watermark {
5
-
6
- .actions {
7
-
8
- &.bulkactions {
9
- padding-right: 0 !important;
10
-
11
- .button {
12
- margin-right: 16px !important;
13
- }
14
- }
15
- }
16
-
17
- .form-field {
18
- display: flex;
19
- justify-content: flex-start;
20
- margin-bottom: 20px;
21
-
22
- &:last-child {
23
- margin-bottom: 0;
24
- }
25
-
26
- input {
27
- margin: 0;
28
- position: relative;
29
-
30
- &[type="number"] {
31
- width: 70px;
32
- }
33
-
34
- &:focus {
35
- z-index: 2;
36
- }
37
- }
38
-
39
- &-prepend,
40
- &-append {
41
- display: flex;
42
- position: relative;
43
- }
44
-
45
- &-text,
46
- button {
47
- align-items: center;
48
- background-color: #eee;
49
- border: 1px solid #ddd;
50
- border-radius: 3px;
51
- display: flex;
52
- padding: 0 8px;
53
- position: relative;
54
- z-index: 1;
55
- }
56
-
57
- &-prepend {
58
-
59
- .form-field-text,
60
- button,
61
- .dropdown-menu {
62
- border-bottom-right-radius: 0;
63
- border-top-right-radius: 0;
64
- margin-right: -1px;
65
- }
66
- }
67
-
68
- &-append {
69
-
70
- .form-field-text,
71
- button,
72
- .dropdown-menu {
73
- border-bottom-left-radius: 0;
74
- border-top-left-radius: 0;
75
- margin-left: -1px;
76
- }
77
- }
78
-
79
- button {
80
-
81
- &:hover {
82
- background-color: #ddd;
83
- border: 1px solid #aaa;
84
- cursor: pointer;
85
- }
86
-
87
- &[data-toggle="dropdown"] {
88
-
89
- &::after {
90
- border: 4px solid transparent;
91
- border-top: 4px solid #777;
92
- content: "";
93
- height: 0;
94
- margin-bottom: -4px;
95
- margin-left: 10px;
96
- width: 0;
97
- }
98
- }
99
- }
100
-
101
- .dropdown-menu {
102
- background: #fff;
103
- border: 1px solid #aaa;
104
- border-radius: 3px;
105
- display: none;
106
- margin-top: 3px;
107
- min-width: calc(100% - 2px);
108
- overflow: hidden;
109
- position: absolute;
110
- z-index: 99;
111
-
112
- .dropdown-item {
113
- color: #333;
114
- display: block;
115
- padding: 3px 6px;
116
- text-decoration: none;
117
-
118
- &:hover {
119
- background-color: #eee;
120
- }
121
- }
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
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/styles/_mixins.scss DELETED
@@ -1,10 +0,0 @@
1
- @mixin checkered-bg( $gridSize: 10px, $color1: #ddd, $color2: #bbb ) {
2
- $bgSize: $gridSize * 2;
3
-
4
- background-color: $color1;
5
- background-image:
6
- linear-gradient(45deg, $color2 25%, transparent 25%, transparent 75%, $color2 75%, $color2),
7
- linear-gradient(45deg, $color2 25%, transparent 25%, transparent 75%, $color2 75%, $color2);
8
- background-position: 0 0, $gridSize $gridSize;
9
- background-size: $bgSize $bgSize;
10
- }
 
 
 
 
 
 
 
 
 
 
assets/src/styles/attachment-edit.scss DELETED
@@ -1 +0,0 @@
1
- @import "metaboxes/watermarks";
 
assets/src/styles/components/_field.scss DELETED
@@ -1,12 +0,0 @@
1
- .ew-field {
2
-
3
- &.layout {
4
-
5
- &-simple {
6
-
7
- td {
8
- padding-left: 0;
9
- }
10
- }
11
- }
12
- }
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/styles/components/_grid.scss DELETED
@@ -1,32 +0,0 @@
1
- .ew-grid {
2
- align-items: stretch;
3
- display: flex;
4
- flex-wrap: wrap;
5
- justify-content: flex-start;
6
- margin: 0 -8px -8px;
7
- padding-top: 2px;
8
-
9
- @media (max-width: 680px) {
10
- justify-content: center;
11
- }
12
-
13
- .item {
14
- flex: 0 0 auto;
15
- margin: 8px;
16
- max-width: 480px;
17
- min-height: 200px;
18
- width: calc(25% - 16px);
19
-
20
- @media (max-width: 1500px) {
21
- width: calc(100% / 3 - 16px);
22
- }
23
-
24
- @media (max-width: 1100px) {
25
- width: calc(50% - 18px);
26
- }
27
-
28
- @media (max-width: 680px) {
29
- width: calc(100% - 16px);
30
- }
31
- }
32
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/styles/components/_switch.scss DELETED
@@ -1,52 +0,0 @@
1
- label.ew-switch {
2
- line-height: 20px;
3
-
4
- span.switch {
5
- background-color: #ccc;
6
- border-radius: 7px;
7
- display: inline-block;
8
- height: 14px;
9
- position: relative;
10
- transition: all 0.3s;
11
- vertical-align: sub;
12
- width: 30px;
13
-
14
- &::before {
15
- background: #fff;
16
- border-radius: 50%;
17
- box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
18
- content: "";
19
- display: block;
20
- height: 18px;
21
- left: -2px;
22
- position: absolute;
23
- top: -2px;
24
- transition: all 0.3s;
25
- width: 18px;
26
- }
27
-
28
- &.left-aligned {
29
- margin-right: 8px;
30
- }
31
-
32
- &.right-aligned {
33
- margin-left: 8px;
34
- }
35
- }
36
-
37
- input {
38
- position: absolute;
39
- visibility: hidden;
40
-
41
- &:checked {
42
-
43
- + span.switch {
44
- background-color: #0073aa;
45
-
46
- &::before {
47
- left: 14px;
48
- }
49
- }
50
- }
51
- }
52
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/styles/components/_vex.scss DELETED
@@ -1,148 +0,0 @@
1
- @import "vex-js/sass/_mixins.sass";
2
- @import "vex-js/sass/_keyframes.sass";
3
- @include keyframes-vex-fadein;
4
- @include keyframes-vex-fadeout;
5
- @include keyframes-vex-pulse;
6
-
7
- .wp-admin .vex {
8
- z-index: 999999;
9
-
10
- &-overlay {
11
- z-index: 999999;
12
- }
13
- }
14
-
15
- $blue: #3288e6;
16
-
17
- .vex.vex-theme-ew {
18
- align-items: center;
19
- display: flex;
20
- justify-content: center;
21
- padding: 20px;
22
-
23
- .vex-content {
24
- animation: vex-fadein 0.5s;
25
- background: #fff;
26
- margin: 0;
27
- max-width: 100%;
28
- padding: 12px;
29
- position: relative;
30
- width: 450px;
31
-
32
- h1,
33
- h2,
34
- h3,
35
- h4,
36
- h5,
37
- h6,
38
- p,
39
- ul,
40
- li {
41
- color: inherit;
42
- }
43
- }
44
-
45
- &.vex-closing .vex-content {
46
- animation: vex-fadeout 0.5s forwards;
47
- }
48
-
49
- .vex-close {
50
- border-radius: 5px;
51
- cursor: pointer;
52
- position: absolute;
53
- right: 0;
54
- top: 0;
55
-
56
- &::before {
57
- background: transparent;
58
- border-radius: 3px;
59
- color: #bbb;
60
- content: "×";
61
- font-size: 26px;
62
- font-weight: 400;
63
- height: 30px;
64
- line-height: 31px;
65
- position: absolute;
66
- right: 3px;
67
- text-align: center;
68
- top: 3px;
69
- width: 30px;
70
- }
71
-
72
- &:hover::before,
73
- &:active::before {
74
- background: #e0e0e0;
75
- color: #777;
76
- }
77
- }
78
-
79
- .vex-dialog-form {
80
-
81
- .vex-dialog-message {
82
- margin-bottom: 2em;
83
- }
84
-
85
- .vex-dialog-input {
86
- margin-bottom: 1em;
87
-
88
- select,
89
- textarea,
90
- input[type="date"],
91
- input[type="datetime"],
92
- input[type="datetime-local"],
93
- input[type="email"],
94
- input[type="month"],
95
- input[type="number"],
96
- input[type="password"],
97
- input[type="search"],
98
- input[type="tel"],
99
- input[type="text"],
100
- input[type="time"],
101
- input[type="url"],
102
- input[type="week"] {
103
- background: #fff;
104
- border: 0;
105
- border-radius: 3px;
106
- font-family: inherit;
107
- font-size: inherit;
108
- font-weight: inherit;
109
- margin: 0 0 0.25em;
110
- min-height: 2.5em;
111
- padding: 0.25em 0.67em;
112
- width: 100%;
113
-
114
- &:focus {
115
- box-shadow: inset 0 0 0 2px lighten($blue, 20%);
116
- outline: none;
117
- }
118
- }
119
- }
120
-
121
- .vex-dialog-buttons {
122
- border-top: 1px solid #eee;
123
- margin: 0 -12px -12px;
124
- padding: 12px;
125
-
126
- @include pie-clearfix;
127
- }
128
- }
129
-
130
- .vex-dialog-button {
131
- float: right;
132
- margin: 0 0 0 8px;
133
-
134
- &.vex-last {
135
- margin-left: 0;
136
- }
137
- }
138
- }
139
-
140
- .vex-loading-spinner.vex-theme-ew {
141
- background: #f0f0f0;
142
- border: 0.2em solid transparent;
143
- border-radius: 100%;
144
- border-top-color: #bbb;
145
- bottom: auto;
146
- box-shadow: 0 0 0 0.5em #f0f0f0, 0 0 1px 0.5em rgba(0, 0, 0, 0.3);
147
- top: -1.1em;
148
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/styles/dashboard.scss DELETED
@@ -1,6 +0,0 @@
1
- @import "mixins";
2
- @import "components/switch";
3
- @import "components/field";
4
- @import "components/grid";
5
- @import "pages/watermarks";
6
- @import "pages/tools";
 
 
 
 
 
 
assets/src/styles/main.scss DELETED
@@ -1,8 +0,0 @@
1
- @import "general";
2
- @import "edit-screen";
3
- @import "metaboxes/content";
4
- @import "metaboxes/alignment";
5
- @import "metaboxes/watermarks";
6
- @import "metaboxes/preview";
7
- @import "metaboxes/placeholders";
8
- @import "components/switch";
 
 
 
 
 
 
 
 
assets/src/styles/media-library.scss DELETED
@@ -1,108 +0,0 @@
1
- .spinner.ew-spinner {
2
- float: none;
3
- margin: 0;
4
- visibility: visible;
5
- }
6
-
7
- p.ew-status {
8
- display: inline-block;
9
- line-height: 28px;
10
- margin: 0 8px 0 0;
11
- vertical-align: middle;
12
-
13
- &.hidden {
14
- display: none !important;
15
- }
16
- }
17
-
18
- .wp-list-table.media {
19
-
20
- .media-icon {
21
- position: relative;
22
-
23
- .spinner {
24
- background-color: rgba(255, 255, 255, 0.8);
25
- background-position: center;
26
- height: 100%;
27
- left: 0;
28
- margin: 0;
29
- opacity: 1;
30
- position: absolute;
31
- top: 0;
32
- width: 100%;
33
- }
34
- }
35
- }
36
-
37
- .media-frame.mode-grid {
38
-
39
- p.ew-status {
40
- margin: 11px 8px 11px 0;
41
- }
42
-
43
- .media-toolbar {
44
-
45
- select.watermark-selector {
46
- height: 30px;
47
- margin: 11px 10px 11px 0;
48
- }
49
-
50
- .view-switch.disabled {
51
- position: relative;
52
-
53
- &::after {
54
- background-color: rgba(#fff, 0.6);
55
- content: "";
56
- display: block;
57
- height: 100%;
58
- left: 0;
59
- position: absolute;
60
- top: 0;
61
- width: 100%;
62
- z-index: 999;
63
- }
64
- }
65
- }
66
-
67
- .attachment {
68
-
69
- &.disabled {
70
- cursor: default;
71
- filter: grayscale(1);
72
-
73
- &:focus {
74
- box-shadow: none;
75
- outline: none;
76
- }
77
- }
78
-
79
- .badge,
80
- .spinner {
81
- bottom: 8px;
82
- left: 8px;
83
- position: absolute;
84
- right: 8px;
85
- top: 8px;
86
- }
87
-
88
- .spinner {
89
- background-color: rgba(255, 255, 255, 0.8);
90
- background-position: center;
91
- height: calc(100% - 16px);
92
- margin: 0;
93
- opacity: 1;
94
- width: calc(100% - 16px);
95
- }
96
-
97
- .badge {
98
- align-items: center;
99
- background-color: rgba(#dedede, 0.6);
100
- color: #444;
101
- display: flex;
102
- font-size: 16px;
103
- justify-content: center;
104
- padding: 16px;
105
- text-shadow: 0 0 5px #fff;
106
- }
107
- }
108
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/styles/metaboxes/_alignment.scss DELETED
@@ -1,60 +0,0 @@
1
- #alignment {
2
-
3
- .alignment-selector {
4
- background-image: url(../images/alignment-background.jpg);
5
- background-size: cover;
6
- display: flex;
7
- flex-wrap: wrap;
8
- justify-content: space-between;
9
- width: 240px;
10
-
11
- label {
12
- background-repeat: no-repeat;
13
- display: block;
14
- float: left;
15
- height: 58px;
16
- margin-bottom: 3px;
17
- position: relative;
18
- text-align: center;
19
- width: 78px;
20
-
21
- &:nth-last-child(-n + 6) {
22
- margin-bottom: 0;
23
- }
24
-
25
- &::after {
26
- background-color: rgba(#fff, 0.2);
27
- bottom: 0;
28
- content: "";
29
- left: 0;
30
- position: absolute;
31
- right: 0;
32
- top: 0;
33
- transition: all 0.2s;
34
- }
35
-
36
- &:hover {
37
-
38
- &::after {
39
- background-color: rgba(#fff, 0.35);
40
- }
41
- }
42
- }
43
-
44
- input {
45
- opacity: 0;
46
- position: absolute;
47
- z-index: -1;
48
-
49
- &:checked {
50
-
51
- + label {
52
-
53
- &::after {
54
- background-color: transparent;
55
- }
56
- }
57
- }
58
- }
59
- }
60
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/styles/metaboxes/_content.scss DELETED
@@ -1,40 +0,0 @@
1
- #watermark-content {
2
-
3
- .image-content,
4
- .text-content,
5
- .select-image-button,
6
- .watermark-image {
7
- display: none;
8
- }
9
-
10
- .watermark-image {
11
-
12
- img {
13
- background-color: #ddd;
14
- cursor: pointer;
15
- height: auto;
16
- max-width: 100%;
17
- width: auto;
18
- }
19
- }
20
-
21
- .text-content {
22
- overflow: hidden;
23
-
24
- input {
25
- width: 100%;
26
- }
27
- }
28
-
29
- .text-preview {
30
- float: left;
31
-
32
- @include checkered-bg( 6px, #ddd, #999);
33
-
34
- img {
35
- display: block;
36
- height: auto;
37
- max-width: 100%;
38
- }
39
- }
40
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/styles/metaboxes/_placeholders.scss DELETED
@@ -1,101 +0,0 @@
1
- #placeholders {
2
-
3
- li {
4
- margin-bottom: 20px;
5
-
6
- > label {
7
- display: block;
8
- font-weight: 700;
9
- margin-bottom: 5px;
10
- width: calc(100% - 30px);
11
- }
12
- }
13
-
14
- code {
15
- cursor: pointer;
16
- width: calc(100% - 30px);
17
- }
18
-
19
- .ew-search-placeholders {
20
- margin: 13px 0 7px;
21
- }
22
-
23
- .help {
24
- float: right;
25
- position: relative;
26
- top: 10px;
27
-
28
- .question-mark {
29
- background-color: #888;
30
- border-radius: 50%;
31
- color: #fff;
32
- cursor: pointer;
33
- display: block;
34
- height: 20px;
35
- line-height: 20px;
36
- text-align: center;
37
- width: 20px;
38
- }
39
-
40
- .description {
41
- background-color: #fff;
42
- border: 1px solid #eee;
43
- box-shadow: 0 0 8px rgba(0, 0, 0, 0.3);
44
- display: none;
45
- font-size: 12px;
46
- min-width: 200px;
47
- opacity: 0;
48
- position: absolute;
49
- right: 0;
50
- top: 32px;
51
- transition: opacity 0.2s;
52
- z-index: 1;
53
-
54
- &::before,
55
- &::after {
56
- border-color: rgba(229, 229, 229, 0);
57
- border-style: solid;
58
- bottom: 100%;
59
- content: "";
60
- height: 0;
61
- pointer-events: none;
62
- position: absolute;
63
- right: 0;
64
- width: 0;
65
- z-index: 18;
66
- }
67
-
68
- &::before {
69
- border-bottom-color: #eee;
70
- border-width: 11px;
71
- margin-left: -11px;
72
- }
73
-
74
- &::after {
75
- border-bottom-color: #fff;
76
- border-width: 9px;
77
- margin-left: -9px;
78
- margin-right: 2px;
79
- }
80
-
81
- label {
82
- display: block;
83
- font-weight: 700;
84
- }
85
-
86
- span,
87
- i {
88
- display: block;
89
- }
90
-
91
- &-content {
92
- padding: 10px;
93
- }
94
- }
95
-
96
- &:hover .description {
97
- display: block;
98
- opacity: 1;
99
- }
100
- }
101
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/styles/metaboxes/_preview.scss DELETED
@@ -1,32 +0,0 @@
1
- .ew-preview-popup {
2
- display: none;
3
-
4
- .media-frame-content {
5
- bottom: 0;
6
- padding: 16px;
7
- top: 50px;
8
-
9
- img {
10
- display: block;
11
- height: auto;
12
- margin-bottom: 16px;
13
- max-width: 100%;
14
- }
15
- }
16
- }
17
-
18
- #preview {
19
-
20
- img {
21
- cursor: pointer;
22
- height: auto;
23
- max-width: 100%;
24
- }
25
-
26
- .spinner {
27
- display: none;
28
- float: none;
29
- margin: 10px 0 0;
30
- visibility: visible;
31
- }
32
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/styles/metaboxes/_watermarks.scss DELETED
@@ -1,48 +0,0 @@
1
- #watermarks {
2
-
3
- table {
4
- margin-bottom: 10px;
5
- text-align: left;
6
-
7
- td {
8
- padding: 5px 10px;
9
- }
10
-
11
- th {
12
- padding: 5px 10px 5px 0;
13
- }
14
- }
15
-
16
- .button-wrap {
17
- margin-bottom: 10px;
18
-
19
- &:last-child {
20
- margin-bottom: 0;
21
- }
22
-
23
- &::after {
24
- clear: both;
25
- content: "";
26
- display: block;
27
- }
28
-
29
- button,
30
- .spinner {
31
- float: left;
32
- }
33
- }
34
-
35
- .error-message {
36
- display: none;
37
- }
38
-
39
- p.description {
40
- margin-top: 20px;
41
- }
42
-
43
- .removed-watermarks {
44
- list-style: initial;
45
- margin: 0;
46
- padding-left: 30px;
47
- }
48
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/styles/pages/_tools.scss DELETED
@@ -1,7 +0,0 @@
1
- .tools {
2
-
3
- .spinner {
4
- float: none;
5
- vertical-align: top;
6
- }
7
- }
 
 
 
 
 
 
 
assets/src/styles/pages/_watermarks.scss DELETED
@@ -1,49 +0,0 @@
1
- .watermarks {
2
-
3
- .postbox {
4
- align-items: stretch;
5
- display: flex;
6
-
7
- h3 {
8
- margin-top: 0;
9
- }
10
-
11
- a {
12
- text-decoration: none;
13
- }
14
- }
15
-
16
- .inside {
17
- display: flex;
18
- flex-direction: column;
19
- justify-content: center;
20
- margin: 0;
21
- padding: 12px;
22
- width: 100%;
23
- }
24
-
25
- .button-hero {
26
- align-self: center;
27
- }
28
-
29
- .watermark-preview {
30
- align-items: center;
31
- background-color: #c8c8c8;
32
- display: flex;
33
- flex: 1 1 auto;
34
- justify-content: center;
35
- margin-bottom: 20px;
36
- padding: 20px;
37
-
38
- @include checkered-bg;
39
-
40
- img {
41
- height: auto;
42
- max-width: 100%;
43
- }
44
- }
45
-
46
- .row-actions {
47
- position: static;
48
- }
49
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/src/styles/uploader.scss DELETED
@@ -1,5 +0,0 @@
1
- @import "components/switch";
2
-
3
- .ew-watermark-all-switch {
4
- margin-bottom: 12px;
5
- }
 
 
 
 
 
assets/src/styles/watermark-edit.scss DELETED
@@ -1,8 +0,0 @@
1
- @import "mixins";
2
- @import "general";
3
- @import "edit-screen";
4
- @import "metaboxes/content";
5
- @import "metaboxes/alignment";
6
- @import "metaboxes/watermarks";
7
- @import "metaboxes/preview";
8
- @import "metaboxes/placeholders";
 
 
 
 
 
 
 
 
bin/dump-hooks.php DELETED
@@ -1,71 +0,0 @@
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
@@ -1,22 +1,22 @@
1
- <?php
2
- /**
3
- * Plugin Name: Easy Watermark
4
- * Description: This plugin can automatically add image and text watermark to pictures as they are uploaded to WordPress media library. You can also watermark existing images manually (all at once or an every single image). Watermark image can be a png, gif (alpha channel supported in both cases) or jpg. It's also possibile to set watermark opacity (doesn't apply to png with alpha channel). For text watermark you can select font, set color, size, angle and opacity.
5
- * Author: BracketSpace
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
13
- */
14
-
15
- define( 'EW_FILE_PATH', __FILE__ );
16
- define( 'EW_DIR_PATH', plugin_dir_path( __FILE__ ) );
17
- define( 'EW_DIR_URL', plugin_dir_url( __FILE__ ) );
18
-
19
- /**
20
- * Require bootstrap file
21
- */
22
- require 'src/bootstrap.php';
1
+ <?php
2
+ /**
3
+ * Plugin Name: Easy Watermark
4
+ * Description: This plugin can automatically add image and text watermark to pictures as they are uploaded to WordPress media library. You can also watermark existing images manually (all at once or an every single image). Watermark image can be a png, gif (alpha channel supported in both cases) or jpg. It's also possibile to set watermark opacity (doesn't apply to png with alpha channel). For text watermark you can select font, set color, size, angle and opacity.
5
+ * Author: BracketSpace
6
+ * Author URI: https://bracketspace.com/
7
+ * Text Domain: easy-watermark
8
+ * Domain Path: /languages
9
+ * Version: 1.0.9
10
+ * License: GPLv3 or later
11
+ *
12
+ * @package easy-watermark
13
+ */
14
+
15
+ define( 'EW_FILE_PATH', __FILE__ );
16
+ define( 'EW_DIR_PATH', plugin_dir_path( __FILE__ ) );
17
+ define( 'EW_DIR_URL', plugin_dir_url( __FILE__ ) );
18
+
19
+ /**
20
+ * Require bootstrap file
21
+ */
22
+ require 'src/bootstrap.php';
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.8
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,10 @@ All available placeholders are listed in a box titled 'Placeholders' displayed w
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.
5
  Requires at least: 4.6
6
  Requires PHP: 5.6
7
  Tested up to: 5.6
8
+ Stable tag: 1.0.9
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.9 =
122
+ * [Fixed] Translated view file names causing `missing view` errors.
123
+ * [Fixed] Errors occuring on the first plugin activation.
124
+
125
  = 1.0.8 =
126
  * [Added] New form styles compatible with new WordPress form styles.
127
  * [Added] Option to disable cache buster responsible for adding version param to image urls.
src/bootstrap.php CHANGED
@@ -1,59 +1,59 @@
1
- <?php
2
- /**
3
- * Plugin bootstrap file
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark;
9
-
10
- use EasyWatermark\Core\Plugin as EasyWatermark;
11
-
12
- /**
13
- * Helper function for startup errors
14
- *
15
- * @param string $message
16
- * @param string $subtitle
17
- * @param string $title
18
- */
19
- $ew_error = function( $message, $subtitle = '', $title = '' ) {
20
- $title = $title ?: __( 'Easy Watermark &rsaquo; Error', 'easy-watermark' );
21
- $footer = '<a href="https://wordpress.org/support/plugin/easy-watermark">Support </a>';
22
- $message = "<h1>{$title}<br><small>{$subtitle}</small></h1><p>{$message}</p><p>{$footer}</p>";
23
- wp_die( $message, $title ); // phpcs:ignore
24
- };
25
-
26
- require EW_DIR_PATH . '/src/inc/functions.php';
27
-
28
- /**
29
- * Composer autoloader file
30
- */
31
- $autoloader = EW_DIR_PATH . '/vendor/autoload.php';
32
-
33
- /**
34
- * Check if the composer vendors are installed
35
- */
36
- if ( ! file_exists( $autoloader ) ) {
37
- $ew_error( 'If you are a developer, please run: `<code>composer install</code>`. Otherwies contact us for help.', 'The plugin vendors are missing.' );
38
- }
39
-
40
- /**
41
- * Require composer autoload
42
- */
43
- require $autoloader;
44
-
45
- /**
46
- * Requirements check
47
- */
48
- $requirements = new \underDEV_Requirements( __( 'Easy Watermark', 'easy-watermark' ), [
49
- 'php' => '5.6.0',
50
- 'wp' => '4.6',
51
- 'php_extensions' => [ 'gd' ],
52
- ] );
53
-
54
- if ( ! $requirements->satisfied() ) {
55
- add_action( 'admin_notices', array( $requirements, 'notice' ) );
56
- return;
57
- }
58
-
59
- $plugin = EasyWatermark::get();
1
+ <?php
2
+ /**
3
+ * Plugin bootstrap file
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark;
9
+
10
+ use EasyWatermark\Core\Plugin as EasyWatermark;
11
+
12
+ /**
13
+ * Helper function for startup errors
14
+ *
15
+ * @param string $message
16
+ * @param string $subtitle
17
+ * @param string $title
18
+ */
19
+ $ew_error = function( $message, $subtitle = '', $title = '' ) {
20
+ $title = $title ?: __( 'Easy Watermark &rsaquo; Error', 'easy-watermark' );
21
+ $footer = '<a href="https://wordpress.org/support/plugin/easy-watermark">Support </a>';
22
+ $message = "<h1>{$title}<br><small>{$subtitle}</small></h1><p>{$message}</p><p>{$footer}</p>";
23
+ wp_die( $message, $title ); // phpcs:ignore
24
+ };
25
+
26
+ require EW_DIR_PATH . '/src/inc/functions.php';
27
+
28
+ /**
29
+ * Composer autoloader file
30
+ */
31
+ $autoloader = EW_DIR_PATH . '/vendor/autoload.php';
32
+
33
+ /**
34
+ * Check if the composer vendors are installed
35
+ */
36
+ if ( ! file_exists( $autoloader ) ) {
37
+ $ew_error( 'If you are a developer, please run: `<code>composer install</code>`. Otherwies contact us for help.', 'The plugin vendors are missing.' );
38
+ }
39
+
40
+ /**
41
+ * Require composer autoload
42
+ */
43
+ require $autoloader;
44
+
45
+ /**
46
+ * Requirements check
47
+ */
48
+ $requirements = new \underDEV_Requirements( __( 'Easy Watermark', 'easy-watermark' ), [
49
+ 'php' => '5.6.0',
50
+ 'wp' => '4.6',
51
+ 'php_extensions' => [ 'gd' ],
52
+ ] );
53
+
54
+ if ( ! $requirements->satisfied() ) {
55
+ add_action( 'admin_notices', [ $requirements, 'notice' ] );
56
+ return;
57
+ }
58
+
59
+ $plugin = EasyWatermark::get();
src/classes/AttachmentProcessor/AttachmentProcessor.php CHANGED
@@ -1,259 +1,259 @@
1
- <?php
2
- /**
3
- * Image Processor
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\AttachmentProcessor;
9
-
10
- use EasyWatermark\Watermark\Watermark;
11
-
12
- /**
13
- * AttachmentProcessor abstract class
14
- */
15
- abstract class AttachmentProcessor {
16
-
17
- /**
18
- * Image file path
19
- *
20
- * @var string
21
- */
22
- protected $image_file;
23
-
24
- /**
25
- * Array of watermark objects
26
- *
27
- * @var array
28
- */
29
- protected $watermarks;
30
-
31
- /**
32
- * Params
33
- *
34
- * @var array
35
- */
36
- protected $params;
37
-
38
- /**
39
- * Constructor
40
- *
41
- * @param string $file Image file.
42
- * @param array $params Params.
43
- */
44
- public function __construct( $file = null, $params = [] ) {
45
-
46
- $this->image_file = $file;
47
- $this->params = $params;
48
-
49
- }
50
-
51
- /**
52
- * Sets image file
53
- *
54
- * @param string $file Image file.
55
- * @return AttachmentProcessor
56
- */
57
- public function set_file( $file ) {
58
-
59
- $this->image_file = $file;
60
- return $this;
61
-
62
- }
63
-
64
- /**
65
- * Sets params array
66
- *
67
- * @param array $params Params.
68
- * @return void|WP_Error
69
- */
70
- public function set_params( $params ) {
71
-
72
- if ( ! is_array( $params ) ) {
73
- return new \WP_Error( 'invalid_params_type', __( 'Params should be an array.', 'easy-watermark' ) );
74
- }
75
-
76
- $this->params = $params;
77
-
78
- }
79
-
80
- /**
81
- * Sets single param
82
- *
83
- * @param string $key Param name.
84
- * @param string $value Param value.
85
- * @return AttachmentProcessor
86
- */
87
- public function set_param( $key, $value ) {
88
-
89
- $this->params[ $key ] = $value;
90
- return $this;
91
-
92
- }
93
-
94
- /**
95
- * Returns single param value
96
- *
97
- * @param string $key Param name.
98
- * @param string $default Default value to return if param is not set.
99
- * @return mixed
100
- */
101
- public function get_param( $key, $default = null ) {
102
-
103
- if ( array_key_exists( $key, $this->params ) ) {
104
- return $this->params[ $key ];
105
- }
106
-
107
- return $default;
108
-
109
- }
110
-
111
- /**
112
- * Adds watermark configuration
113
- *
114
- * @param Watermark $watermark Watermark object.
115
- * @return void|WP_Error
116
- */
117
- public function add_watermark( $watermark ) {
118
-
119
- if ( ! $watermark instanceof Watermark ) {
120
- return new \WP_Error( 'invalid_watermark_type', __( 'Watermark should be an instance of EasyWatermark\Watermark\Watermark class.', 'easy-watermark' ) );
121
- }
122
-
123
- $this->watermarks[] = $watermark;
124
-
125
- }
126
-
127
- /**
128
- * Computes offset
129
- *
130
- * @param string $position Watrermark position.
131
- * @param array $offset Watermark offset array [value => int, unit => string].
132
- * @param numeric $image_dim Image dimension (width or height).
133
- * @param numeric $watermark_dim Watermark dimension (width or height).
134
- * @return integer
135
- */
136
- protected function compute_offset( $position, $offset, $image_dim, $watermark_dim ) {
137
-
138
- if ( '%' === $offset['unit'] ) {
139
- // Percentage offset.
140
- $offset['value'] = round( ( $offset['value'] / 100 ) * $image_dim );
141
- }
142
-
143
- switch ( $position ) {
144
- case 'start':
145
- $result = $offset['value'];
146
- break;
147
- case 'center':
148
- $result = ( ( $image_dim - $watermark_dim ) / 2 ) + $offset['value'];
149
- break;
150
- case 'end':
151
- $result = $image_dim - $watermark_dim - $offset['value'];
152
- break;
153
- }
154
-
155
- return (int) $result;
156
-
157
- }
158
-
159
- /**
160
- * Returns watermark position (horizontal or vertical) based on alignment
161
- *
162
- * @param string $alignment Watrermark alignment.
163
- * @param string $axis X or Y.
164
- * @return string
165
- */
166
- protected function get_position( $alignment, $axis ) {
167
-
168
- if ( 'x' === $axis ) {
169
- $start_key = 'left';
170
- $end_key = 'right';
171
- } else {
172
- $start_key = 'top';
173
- $end_key = 'bottom';
174
- }
175
-
176
- if ( false !== strpos( $alignment, $start_key ) ) {
177
- return 'start';
178
- } elseif ( false !== strpos( $alignment, $end_key ) ) {
179
- return 'end';
180
- } else {
181
- return 'center';
182
- }
183
-
184
- }
185
-
186
- /**
187
- * Changes hexadecimal color string into RGB array.
188
- *
189
- * @param string $color Hexacedimal color string.
190
- * @return array
191
- */
192
- public function get_rgb_color( $color ) {
193
-
194
- if ( 0 === strpos( $color, '#' ) ) {
195
- $color = substr( $color, 1 );
196
- }
197
-
198
- $i = ( 3 === strlen( $color ) ) ? 1 : 2;
199
-
200
- $r = substr( $color, 0, $i );
201
- $g = substr( $color, $i, $i );
202
- $b = substr( $color, ( 2 * $i ), $i );
203
-
204
- if ( 1 === $i ) {
205
- $r .= $r;
206
- $g .= $g;
207
- $b .= $b;
208
- }
209
-
210
- return [
211
- 'red' => hexdec( $r ),
212
- 'green' => hexdec( $g ),
213
- 'blue' => hexdec( $b ),
214
- ];
215
-
216
- }
217
-
218
- /**
219
- * Performs cleaning
220
- *
221
- * @return void
222
- */
223
- public function clean() {
224
- $this->watermarks = [];
225
- }
226
-
227
- /**
228
- * Checks if the processor can be used in particular system
229
- *
230
- * @return boolean
231
- */
232
- public static function is_available() {
233
- return false;
234
- }
235
-
236
- /**
237
- * Processes image
238
- *
239
- * @return array
240
- */
241
- abstract public function process();
242
-
243
- /**
244
- * Prints image directly to the browser
245
- *
246
- * @param Watermark|null $watermark Watermark to apply for the preview.
247
- * @return void
248
- */
249
- abstract public function print_preview( $watermark = null );
250
-
251
- /**
252
- * Prints image with text preview
253
- *
254
- * @param Watermark $watermark Text watermark for preview.
255
- * @param string $format Output image format.
256
- * @return void
257
- */
258
- abstract public function print_text_preview( $watermark, $format = 'png' );
259
- }
1
+ <?php
2
+ /**
3
+ * Image Processor
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\AttachmentProcessor;
9
+
10
+ use EasyWatermark\Watermark\Watermark;
11
+
12
+ /**
13
+ * AttachmentProcessor abstract class
14
+ */
15
+ abstract class AttachmentProcessor {
16
+
17
+ /**
18
+ * Image file path
19
+ *
20
+ * @var string
21
+ */
22
+ protected $image_file;
23
+
24
+ /**
25
+ * Array of watermark objects
26
+ *
27
+ * @var array
28
+ */
29
+ protected $watermarks;
30
+
31
+ /**
32
+ * Params
33
+ *
34
+ * @var array
35
+ */
36
+ protected $params;
37
+
38
+ /**
39
+ * Constructor
40
+ *
41
+ * @param string $file Image file.
42
+ * @param array $params Params.
43
+ */
44
+ public function __construct( $file = null, $params = [] ) {
45
+
46
+ $this->image_file = $file;
47
+ $this->params = $params;
48
+
49
+ }
50
+
51
+ /**
52
+ * Sets image file
53
+ *
54
+ * @param string $file Image file.
55
+ * @return AttachmentProcessor
56
+ */
57
+ public function set_file( $file ) {
58
+
59
+ $this->image_file = $file;
60
+ return $this;
61
+
62
+ }
63
+
64
+ /**
65
+ * Sets params array
66
+ *
67
+ * @param array $params Params.
68
+ * @return void|WP_Error
69
+ */
70
+ public function set_params( $params ) {
71
+
72
+ if ( ! is_array( $params ) ) {
73
+ return new \WP_Error( 'invalid_params_type', __( 'Params should be an array.', 'easy-watermark' ) );
74
+ }
75
+
76
+ $this->params = $params;
77
+
78
+ }
79
+
80
+ /**
81
+ * Sets single param
82
+ *
83
+ * @param string $key Param name.
84
+ * @param string $value Param value.
85
+ * @return AttachmentProcessor
86
+ */
87
+ public function set_param( $key, $value ) {
88
+
89
+ $this->params[ $key ] = $value;
90
+ return $this;
91
+
92
+ }
93
+
94
+ /**
95
+ * Returns single param value
96
+ *
97
+ * @param string $key Param name.
98
+ * @param string $default Default value to return if param is not set.
99
+ * @return mixed
100
+ */
101
+ public function get_param( $key, $default = null ) {
102
+
103
+ if ( array_key_exists( $key, $this->params ) ) {
104
+ return $this->params[ $key ];
105
+ }
106
+
107
+ return $default;
108
+
109
+ }
110
+
111
+ /**
112
+ * Adds watermark configuration
113
+ *
114
+ * @param Watermark $watermark Watermark object.
115
+ * @return void|WP_Error
116
+ */
117
+ public function add_watermark( $watermark ) {
118
+
119
+ if ( ! $watermark instanceof Watermark ) {
120
+ return new \WP_Error( 'invalid_watermark_type', __( 'Watermark should be an instance of EasyWatermark\Watermark\Watermark class.', 'easy-watermark' ) );
121
+ }
122
+
123
+ $this->watermarks[] = $watermark;
124
+
125
+ }
126
+
127
+ /**
128
+ * Computes offset
129
+ *
130
+ * @param string $position Watrermark position.
131
+ * @param array $offset Watermark offset array [value => int, unit => string].
132
+ * @param numeric $image_dim Image dimension (width or height).
133
+ * @param numeric $watermark_dim Watermark dimension (width or height).
134
+ * @return integer
135
+ */
136
+ protected function compute_offset( $position, $offset, $image_dim, $watermark_dim ) {
137
+
138
+ if ( '%' === $offset['unit'] ) {
139
+ // Percentage offset.
140
+ $offset['value'] = round( ( $offset['value'] / 100 ) * $image_dim );
141
+ }
142
+
143
+ switch ( $position ) {
144
+ case 'start':
145
+ $result = $offset['value'];
146
+ break;
147
+ case 'center':
148
+ $result = ( ( $image_dim - $watermark_dim ) / 2 ) + $offset['value'];
149
+ break;
150
+ case 'end':
151
+ $result = $image_dim - $watermark_dim - $offset['value'];
152
+ break;
153
+ }
154
+
155
+ return (int) $result;
156
+
157
+ }
158
+
159
+ /**
160
+ * Returns watermark position (horizontal or vertical) based on alignment
161
+ *
162
+ * @param string $alignment Watrermark alignment.
163
+ * @param string $axis X or Y.
164
+ * @return string
165
+ */
166
+ protected function get_position( $alignment, $axis ) {
167
+
168
+ if ( 'x' === $axis ) {
169
+ $start_key = 'left';
170
+ $end_key = 'right';
171
+ } else {
172
+ $start_key = 'top';
173
+ $end_key = 'bottom';
174
+ }
175
+
176
+ if ( false !== strpos( $alignment, $start_key ) ) {
177
+ return 'start';
178
+ } elseif ( false !== strpos( $alignment, $end_key ) ) {
179
+ return 'end';
180
+ } else {
181
+ return 'center';
182
+ }
183
+
184
+ }
185
+
186
+ /**
187
+ * Changes hexadecimal color string into RGB array.
188
+ *
189
+ * @param string $color Hexacedimal color string.
190
+ * @return array
191
+ */
192
+ public function get_rgb_color( $color ) {
193
+
194
+ if ( 0 === strpos( $color, '#' ) ) {
195
+ $color = substr( $color, 1 );
196
+ }
197
+
198
+ $i = ( 3 === strlen( $color ) ) ? 1 : 2;
199
+
200
+ $r = substr( $color, 0, $i );
201
+ $g = substr( $color, $i, $i );
202
+ $b = substr( $color, ( 2 * $i ), $i );
203
+
204
+ if ( 1 === $i ) {
205
+ $r .= $r;
206
+ $g .= $g;
207
+ $b .= $b;
208
+ }
209
+
210
+ return [
211
+ 'red' => hexdec( $r ),
212
+ 'green' => hexdec( $g ),
213
+ 'blue' => hexdec( $b ),
214
+ ];
215
+
216
+ }
217
+
218
+ /**
219
+ * Performs cleaning
220
+ *
221
+ * @return void
222
+ */
223
+ public function clean() {
224
+ $this->watermarks = [];
225
+ }
226
+
227
+ /**
228
+ * Checks if the processor can be used in particular system
229
+ *
230
+ * @return boolean
231
+ */
232
+ public static function is_available() {
233
+ return false;
234
+ }
235
+
236
+ /**
237
+ * Processes image
238
+ *
239
+ * @return array
240
+ */
241
+ abstract public function process();
242
+
243
+ /**
244
+ * Prints image directly to the browser
245
+ *
246
+ * @param Watermark|null $watermark Watermark to apply for the preview.
247
+ * @return void
248
+ */
249
+ abstract public function print_preview( $watermark = null );
250
+
251
+ /**
252
+ * Prints image with text preview
253
+ *
254
+ * @param Watermark $watermark Text watermark for preview.
255
+ * @param string $format Output image format.
256
+ * @return void
257
+ */
258
+ abstract public function print_text_preview( $watermark, $format = 'png' );
259
+ }
src/classes/AttachmentProcessor/AttachmentProcessorGD.php CHANGED
@@ -1,750 +1,750 @@
1
- <?php
2
- /**
3
- * GD Image Processor
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\AttachmentProcessor;
9
-
10
- use EasyWatermark\Helpers\Text;
11
- use EasyWatermark\Watermark\Watermark;
12
- use WP_Error;
13
-
14
- /**
15
- * GD Image Processor
16
- */
17
- class AttachmentProcessorGD extends AttachmentProcessor {
18
-
19
- /**
20
- * Finfo instance
21
- *
22
- * @var object
23
- */
24
- private $finfo;
25
-
26
- /**
27
- * Is FreeType extension enabled?
28
- *
29
- * @var boolean
30
- */
31
- private $is_freetype_enabled;
32
-
33
- /**
34
- * Allowed image types
35
- *
36
- * @var array
37
- */
38
- private $allowed_types = [ 'jpeg', 'png', 'gif' ];
39
-
40
- /**
41
- * Input image
42
- *
43
- * @var resource
44
- */
45
- private $input_image;
46
-
47
- /**
48
- * Output image
49
- *
50
- * @var resource
51
- */
52
- private $output_image;
53
-
54
- /**
55
- * Input image type
56
- *
57
- * @var string
58
- */
59
- private $image_type;
60
-
61
- /**
62
- * Image size
63
- *
64
- * @var array
65
- */
66
- private $image_size;
67
-
68
- /**
69
- * Watermark image
70
- *
71
- * @var resource
72
- */
73
- private $watermark_image;
74
-
75
- /**
76
- * Constructor
77
- *
78
- * @param string $file Image file.
79
- * @param array $params Params.
80
- */
81
- public function __construct( $file = null, $params = [] ) {
82
-
83
- $gdinfo = gd_info();
84
- $this->is_freetype_enabled = $gdinfo['FreeType Support'];
85
-
86
- parent::__construct( $file, $params );
87
-
88
- }
89
-
90
- /**
91
- * Checks if the processor can be used in particular system
92
- *
93
- * @return boolean
94
- */
95
- public static function is_available() {
96
-
97
- if ( extension_loaded( 'gd' ) && function_exists( 'gd_info' ) ) {
98
- return true;
99
- }
100
-
101
- return false;
102
-
103
- }
104
-
105
- /**
106
- * Filters available watermark types
107
- *
108
- * @filter easy-watermark/watermark-types
109
- *
110
- * @param array $types Available watermark types.
111
- * @return array
112
- */
113
- public function available_watermark_types( $types ) {
114
-
115
- if ( ! $this->is_freetype_enabled && array_key_exists( 'text', $types ) ) {
116
- unset( $types['text'] );
117
- }
118
-
119
- return $types;
120
-
121
- }
122
-
123
- /**
124
- * Processes image
125
- *
126
- * @param boolean $save Whether to save output or print it.
127
- * @return array
128
- */
129
- public function process( $save = true ) {
130
-
131
- $output_image = $this->get_output_image();
132
-
133
- if ( ! $output_image ) {
134
- return false;
135
- }
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;
146
-
147
- $this->prepare_output( $output );
148
-
149
- return $result;
150
-
151
- }
152
-
153
- /**
154
- * Prints image directly to the browser
155
- *
156
- * @param Watermark|null $watermark Watermark to apply for the preview.
157
- * @param string $format Output format.
158
- * @return void
159
- */
160
- public function print_preview( $watermark = null, $format = 'jpg' ) {
161
-
162
- if ( $watermark instanceof Watermark ) {
163
- $this->add_watermark( $watermark );
164
- }
165
-
166
- if ( 'jpg' === $format ) {
167
- $format = 'jpeg';
168
- }
169
-
170
- $this->image_type = $format;
171
-
172
- $this->process( false );
173
-
174
- }
175
-
176
- /**
177
- * Prints image with text preview
178
- *
179
- * @param Watermark $watermark Text watermark for preview.
180
- * @param string $format Output format.
181
- * @return WP_Error|void
182
- */
183
- public function print_text_preview( $watermark, $format = 'png' ) {
184
-
185
- if ( ! $watermark instanceof Watermark ) {
186
- return new WP_Error( 'invalid_watermark_type', __( 'Watermark should be instance of Easywatermark\Watermark\Watermark.', 'easy-watermark' ) );
187
- }
188
-
189
- if ( 'text' !== $watermark->type ) {
190
- return new WP_Error( 'invalid_watermark_type', __( 'Text preview can be only generated for text watermark.', 'easy-watermark' ) );
191
- }
192
-
193
- if ( ! $watermark->text ) {
194
- return new WP_Error( 'empty_watermark_text', __( 'Watermark text not specified.', 'easy-watermark' ) );
195
- }
196
-
197
- $font = Text::get_font_path( $watermark->font );
198
-
199
- if ( ! $font ) {
200
- /* translators: font name */
201
- return new WP_Error( 'font_not_found', sprintf( __( 'Font "%s" could not be found. ', 'easy-watermark' ), $watermark->font ) );
202
- }
203
-
204
- $text_size = $this->calculate_text_size( $watermark->text_size, $watermark->text_angle, $font, $watermark->text );
205
-
206
- $this->output_image = imagecreatetruecolor( $text_size['width'], $text_size['height'] );
207
-
208
- if ( false === $this->output_image ) {
209
- return new WP_Error( 'gd_error', __( 'Could not create output image.', 'easy-watermark' ) );
210
- }
211
-
212
- imagealphablending( $this->output_image, false );
213
- imagesavealpha( $this->output_image, true );
214
-
215
- $color_transparent = imagecolorallocatealpha( $this->output_image, 255, 255, 255, 127 );
216
-
217
- imagefill( $this->output_image, 0, 0, $color_transparent );
218
-
219
- $watermark->alignment = 'top-left';
220
- $watermark->offset = [
221
- 'x' => [
222
- 'value' => 0,
223
- 'unit' => 'px',
224
- ],
225
- 'y' => [
226
- 'value' => 0,
227
- 'unit' => 'px',
228
- ],
229
- ];
230
-
231
- if ( 'jpg' === $format ) {
232
- $format = 'jpeg';
233
- }
234
-
235
- $this->image_type = $format;
236
-
237
- $this->apply_text_watermark( $watermark );
238
-
239
- $this->prepare_output();
240
-
241
- }
242
-
243
- /**
244
- * Processes image
245
- *
246
- * @return resource
247
- */
248
- public function get_input_image() {
249
-
250
- if ( ! $this->input_image ) {
251
- $type = $this->get_param( 'image_type' );
252
-
253
- $result = $this->create_image( $this->image_file, $type );
254
-
255
- if ( ! $result ) {
256
- return false;
257
- }
258
-
259
- list( $this->input_image, $this->image_type ) = $result;
260
- }
261
-
262
- return $this->input_image;
263
-
264
- }
265
-
266
- /**
267
- * Processes image
268
- *
269
- * @return boolean|resource
270
- */
271
- public function get_output_image() {
272
-
273
- if ( ! $this->output_image ) {
274
- $input_image = $this->get_input_image();
275
-
276
- if ( ! $input_image ) {
277
- $this->output_image = false;
278
- } else {
279
- $image_size = $this->get_input_image_size();
280
-
281
- // Create blank image.
282
- $this->output_image = imagecreatetruecolor( $image_size['width'], $image_size['height'] );
283
-
284
- if ( ! $this->output_image ) {
285
- return false;
286
- }
287
-
288
- if ( 'png' === $this->image_type && $this->is_alpha_png( $this->image_file ) ) {
289
- // Preserve opacity for png images.
290
- imagealphablending( $this->output_image, false );
291
- imagesavealpha( $this->output_image, true );
292
- }
293
-
294
- imagecopy(
295
- $this->output_image,
296
- $this->input_image,
297
- 0, 0, 0, 0,
298
- $image_size['width'],
299
- $image_size['height']
300
- );
301
-
302
- // Destroy Input Image to save memory.
303
- imagedestroy( $this->input_image );
304
- unset( $this->input_image );
305
-
306
- imagealphablending( $this->output_image, true );
307
- }
308
- }
309
-
310
- return $this->output_image;
311
-
312
- }
313
-
314
- /**
315
- * Creates GD image
316
- *
317
- * @param string $file_path Path to image file.
318
- * @param string $type MIME type of the image.
319
- * @return mixed
320
- */
321
- private function create_image( $file_path, $type ) {
322
-
323
- $type = $this->detect_image_type( $type, $file_path );
324
-
325
- if ( ! in_array( $type, $this->allowed_types, true ) ) {
326
- return false;
327
- }
328
-
329
- $func_name = 'imagecreatefrom' . $type;
330
-
331
- $image = call_user_func( $func_name, $file_path );
332
-
333
- if ( false === $image ) {
334
- return false;
335
- }
336
-
337
- if ( 'png' === $type && $this->is_alpha_png( $file_path ) ) {
338
- imagealphablending( $image, false );
339
- imagesavealpha( $image, true );
340
- }
341
-
342
- return [ $image, $type ];
343
-
344
- }
345
-
346
- /**
347
- * Applies watermark
348
- *
349
- * @param Watermark $watermark Watermark object.
350
- * @return mixed
351
- */
352
- private function apply_watermark( $watermark ) {
353
-
354
- switch ( $watermark->type ) {
355
- case 'image':
356
- return $this->apply_image_watermark( $watermark );
357
- case 'text':
358
- return $this->apply_text_watermark( $watermark );
359
- }
360
-
361
- }
362
-
363
- /**
364
- * Applies image watermark
365
- *
366
- * @param Watermark $watermark Watermark object.
367
- * @return mixed
368
- */
369
- private function apply_image_watermark( $watermark ) {
370
-
371
- $output_image = $this->get_output_image();
372
-
373
- if ( ! $output_image ) {
374
- return new WP_Error( 'gd_error', __( 'Could not create output image. Please check your server configuration.', 'easy-watermark' ) );
375
- }
376
-
377
- $watermark_file = get_attached_file( $watermark->attachment_id );
378
-
379
- if ( ! $watermark_file || ! is_file( $watermark_file ) ) {
380
- return new WP_Error( 'watermark_file_not_found', __( 'Watermark image file does not exist.', 'easy-watermark' ) );
381
- }
382
-
383
- $result = $this->create_image( $watermark_file, $watermark->mime_type );
384
-
385
- if ( ! $result ) {
386
- return new WP_Error( 'gd_error', __( 'Something went wrong while processing watermark image.', 'easy-watermark' ) );
387
- }
388
-
389
- list( $watermark_image, $watermark_type ) = $result;
390
-
391
- $watermark_size = $this->calculate_image_size( $watermark_image );
392
-
393
- $image_size = $this->get_input_image_size();
394
-
395
- $scaling_mode = $watermark->scaling_mode;
396
-
397
- if ( 'contain' === $scaling_mode || 'cover' === $scaling_mode ) {
398
- $image_ratio = $image_size['width'] / $image_size['height'];
399
- $watermark_ratio = $watermark_size['width'] / $watermark_size['height'];
400
-
401
- if ( ( 'cover' === $scaling_mode && $watermark_ratio < $image_ratio )
402
- || ( 'contain' === $scaling_mode && $watermark_ratio > $image_ratio ) ) {
403
- $scaling_mode = 'fit_to_width';
404
- $watermark->scale = 100;
405
- } else {
406
- $scaling_mode = 'fit_to_height';
407
- $watermark->scale = 100;
408
- }
409
- }
410
-
411
- if ( 'fit_to_width' === $scaling_mode && ( ! $watermark->scale_down_only || $image_size['width'] < $watermark_size['width'] ) ) {
412
- $scale = $image_size['width'] / $watermark_size['width'];
413
- $new_width = $image_size['width'] * $watermark->scale / 100;
414
- $new_height = $watermark_size['height'] * $scale * $watermark->scale / 100;
415
- } elseif ( 'fit_to_height' === $scaling_mode && ( ! $watermark->scale_down_only || $image_size['height'] < $watermark_size['height'] ) ) {
416
- $scale = $image_size['height'] / $watermark_size['height'];
417
- $new_width = $watermark_size['width'] * $scale * $watermark->scale / 100;
418
- $new_height = $image_size['height'] * $watermark->scale / 100;
419
- }
420
-
421
- if ( isset( $new_width ) ) {
422
- $tmp_image = imagecreatetruecolor( $new_width, $new_height );
423
-
424
- if ( ! $tmp_image ) {
425
- return new WP_Error( 'gd_error', __( 'Could not create temporary image. Please check your server configuration.', 'easy-watermark' ) );
426
- }
427
-
428
- if ( 'png' === $watermark_type && $this->is_alpha_png( $watermark_file ) ) {
429
- imagealphablending( $tmp_image, false );
430
- imagesavealpha( $tmp_image, true );
431
- }
432
-
433
- imagecopyresampled(
434
- $tmp_image,
435
- $watermark_image,
436
- 0, 0, 0, 0,
437
- $new_width, $new_height,
438
- $watermark_size['width'], $watermark_size['height']
439
- );
440
-
441
- // Clean memory.
442
- imagedestroy( $watermark_image );
443
-
444
- $watermark_image = $tmp_image;
445
- $watermark_size['width'] = $new_width;
446
- $watermark_size['height'] = $new_height;
447
-
448
- unset( $tmp_image, $new_width, $nwe_height );
449
- }
450
-
451
- // Compute watermark offset.
452
- $offset_x = $this->compute_offset( $this->get_position( $watermark->alignment, 'x' ), $watermark->offset['x'], $image_size['width'], $watermark_size['width'] );
453
- $offset_y = $this->compute_offset( $this->get_position( $watermark->alignment, 'y' ), $watermark->offset['y'], $image_size['height'], $watermark_size['height'] );
454
-
455
- // Prepare params for copying function.
456
- $params = [
457
- $output_image,
458
- $watermark_image,
459
- $offset_x,
460
- $offset_y,
461
- 0,
462
- 0,
463
- $watermark_size['width'],
464
- $watermark_size['height'],
465
- ];
466
-
467
- if ( 'png' === $watermark_type && $this->is_alpha_png( $watermark_file ) ) {
468
- // Watermark is PNG with alpha channel, use imagecopy.
469
- $func_name = 'imagecopy';
470
- } else {
471
- // Use imagecopymerge with opacity param for other images.
472
- $func_name = 'imagecopymerge';
473
- $params[] = $watermark->opacity;
474
- }
475
-
476
- // Copy watermark to output image.
477
- $result = call_user_func_array( $func_name, $params );
478
-
479
- if ( true === $result ) {
480
- return true;
481
- }
482
-
483
- return new WP_Error( 'gd_error', __( 'Something went wrong while applying watermark image.', 'easy-watermark' ) );
484
-
485
- }
486
-
487
- /**
488
- * Applies text watermark
489
- *
490
- * @param Watermark $watermark Watermark object.
491
- * @return mixed
492
- */
493
- private function apply_text_watermark( $watermark ) {
494
-
495
- $output_image = $this->get_output_image();
496
-
497
- if ( ! $output_image ) {
498
- return new WP_Error( 'gd_error', __( 'Could not create output image. Please check your server configuration.', 'easy-watermark' ) );
499
- }
500
-
501
- $font = Text::get_font_path( $watermark->font );
502
-
503
- if ( ! $font ) {
504
- /* translators: font name */
505
- return new WP_Error( 'font_not_found', sprintf( __( 'Font "%s" could not be found. ', 'easy-watermark' ), $watermark->font ) );
506
- }
507
-
508
- $text_size = $this->calculate_text_size( $watermark->text_size, $watermark->text_angle, $font, $watermark->text );
509
- $image_size = $this->get_input_image_size();
510
-
511
- $color_rgb = $this->get_rgb_color( $watermark->text_color );
512
- $color = imagecolorallocatealpha(
513
- $output_image,
514
- $color_rgb['red'],
515
- $color_rgb['green'],
516
- $color_rgb['blue'],
517
- 127 * ( 100 - $watermark->opacity ) / 100
518
- );
519
-
520
- if ( false === $color ) {
521
- return new WP_Error( 'gd_error', __( 'Something went wrong while allocating text color.', 'easy-watermark' ) );
522
- }
523
-
524
- $offset_x = $this->compute_offset( $this->get_position( $watermark->alignment, 'x' ), $watermark->offset['x'], $image_size['width'], $text_size['width'] );
525
- $offset_y = $this->compute_offset( $this->get_position( $watermark->alignment, 'y' ), $watermark->offset['y'], $image_size['height'], $text_size['height'] );
526
-
527
- $result = imagettftext(
528
- $output_image,
529
- $watermark->text_size,
530
- $watermark->text_angle,
531
- $offset_x - $text_size['delta_x'], $offset_y - $text_size['delta_y'],
532
- $color,
533
- $font,
534
- $watermark->text
535
- );
536
-
537
- if ( false === $result ) {
538
- return new WP_Error( 'gd_error', __( 'Something went wrong while applying watermark text.', 'easy-watermark' ) );
539
- }
540
-
541
- return true;
542
-
543
- }
544
-
545
- /**
546
- * Detects mime type using php finfo object
547
- *
548
- * @param string $type MIME type.
549
- * @param string $file_path File path.
550
- * @return string
551
- */
552
- private function detect_image_type( $type, $file_path = null ) {
553
-
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 ) {
562
- return false;
563
- }
564
-
565
- if ( 0 === strpos( $type, 'image/' ) ) {
566
- $type = substr( $type, 6 );
567
- }
568
-
569
- if ( 'jpg' === $type ) {
570
- $type = 'jpeg';
571
- }
572
-
573
- return $type;
574
-
575
- }
576
-
577
- /**
578
- * Returns input image size
579
- *
580
- * @return array
581
- */
582
- private function get_input_image_size() {
583
-
584
- if ( ! $this->image_size ) {
585
- $this->image_size = $this->calculate_image_size( $this->input_image );
586
- }
587
-
588
- return $this->image_size;
589
-
590
- }
591
-
592
- /**
593
- * Returns image size
594
- *
595
- * @param resource $image Image to calculate dimensions.
596
- * @return array
597
- */
598
- private function calculate_image_size( $image ) {
599
-
600
- if ( ! is_resource( $image ) && ! $image instanceof \GdImage ) {
601
- return false;
602
- }
603
-
604
- return [
605
- 'width' => imagesx( $image ),
606
- 'height' => imagesy( $image ),
607
- ];
608
-
609
- }
610
-
611
- /**
612
- * Returns size of text bounding box width x and y distance from font baseline
613
- *
614
- * @param integer $font_size Font size.
615
- * @param integer $angle Text angle.
616
- * @param string $font Path to font file.
617
- * @param string $text Text.
618
- * @return array
619
- */
620
- private function calculate_text_size( $font_size, $angle, $font, $text ) {
621
-
622
- $bb = imagettfbbox( (float) $font_size, $angle, $font, $text );
623
-
624
- $max_x = max( $bb[0], $bb[2], $bb[4], $bb[6] );
625
- $min_x = min( $bb[0], $bb[2], $bb[4], $bb[6] );
626
- $width = $max_x - $min_x;
627
-
628
- $max_y = max( $bb[1], $bb[3], $bb[5], $bb[7] );
629
- $min_y = min( $bb[1], $bb[3], $bb[5], $bb[7] );
630
- $height = $max_y - $min_y;
631
-
632
- return [
633
- 'width' => $width,
634
- 'height' => $height,
635
- 'delta_x' => $min_x,
636
- 'delta_y' => $min_y,
637
- ];
638
-
639
- }
640
-
641
- /**
642
- * Returns finfo object
643
- *
644
- * @return object
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
-
652
- return $this->finfo;
653
-
654
- }
655
-
656
- /**
657
- * Verifies if png file has alpha chanel
658
- *
659
- * @param string $file_path File path.
660
- * @return boolean
661
- */
662
- public function is_alpha_png( $file_path ) {
663
-
664
- /**
665
- * Color type of png image stored at 25 byte:
666
- * 0 - greyscale
667
- * 2 - RGB
668
- * 3 - RGB with palette
669
- * 4 - greyscale + alpha
670
- * 6 - RGB + alpha
671
- */
672
- $content = file_get_contents( $file_path, false, null, 25, 1 ); // phpcs:ignore
673
-
674
- if ( false === $content ) {
675
- return false;
676
- }
677
-
678
- $color_byte = ord( $content );
679
-
680
- return ( 6 === $color_byte || 4 === $color_byte );
681
-
682
- }
683
-
684
- /**
685
- * Saves or outputs created image
686
- *
687
- * @param string $output Output file.
688
- * @return boolean
689
- */
690
- private function prepare_output( $output = null ) {
691
-
692
- if ( ! $this->image_type || ! in_array( $this->image_type, $this->allowed_types, true ) ) {
693
- return false;
694
- }
695
-
696
- if ( null === $output ) {
697
- // Return image directly to the browser.
698
- header( 'Content-Type: image/' . $this->image_type );
699
- }
700
-
701
- $params = [
702
- $this->output_image,
703
- $output,
704
- ];
705
-
706
- if ( 'jpeg' === $this->image_type ) {
707
- $params[] = $this->get_param( 'jpeg_quality', -1 );
708
- }
709
-
710
- $func_name = 'image' . $this->image_type;
711
-
712
- $result = call_user_func_array( $func_name, $params );
713
-
714
- return $result;
715
-
716
- }
717
-
718
- /**
719
- * Performs cleaning
720
- *
721
- * @return void
722
- */
723
- public function clean() {
724
-
725
- parent::clean();
726
-
727
- if ( $this->watermark_image ) {
728
- imagedestroy( $this->watermark_image );
729
- $this->watermark_image = null;
730
- }
731
-
732
- if ( $this->output_image ) {
733
- imagedestroy( $this->output_image );
734
- $this->output_image = null;
735
- }
736
-
737
- $this->image_size = null;
738
- $this->input_image = null;
739
-
740
- }
741
-
742
- /**
743
- * Destructor
744
- */
745
- public function __destruct() {
746
-
747
- $this->clean();
748
-
749
- }
750
- }
1
+ <?php
2
+ /**
3
+ * GD Image Processor
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\AttachmentProcessor;
9
+
10
+ use EasyWatermark\Helpers\Text;
11
+ use EasyWatermark\Watermark\Watermark;
12
+ use WP_Error;
13
+
14
+ /**
15
+ * GD Image Processor
16
+ */
17
+ class AttachmentProcessorGD extends AttachmentProcessor {
18
+
19
+ /**
20
+ * Finfo instance
21
+ *
22
+ * @var object
23
+ */
24
+ private $finfo;
25
+
26
+ /**
27
+ * Is FreeType extension enabled?
28
+ *
29
+ * @var boolean
30
+ */
31
+ private $is_freetype_enabled;
32
+
33
+ /**
34
+ * Allowed image types
35
+ *
36
+ * @var array
37
+ */
38
+ private $allowed_types = [ 'jpeg', 'png', 'gif' ];
39
+
40
+ /**
41
+ * Input image
42
+ *
43
+ * @var resource
44
+ */
45
+ private $input_image;
46
+
47
+ /**
48
+ * Output image
49
+ *
50
+ * @var resource
51
+ */
52
+ private $output_image;
53
+
54
+ /**
55
+ * Input image type
56
+ *
57
+ * @var string
58
+ */
59
+ private $image_type;
60
+
61
+ /**
62
+ * Image size
63
+ *
64
+ * @var array
65
+ */
66
+ private $image_size;
67
+
68
+ /**
69
+ * Watermark image
70
+ *
71
+ * @var resource
72
+ */
73
+ private $watermark_image;
74
+
75
+ /**
76
+ * Constructor
77
+ *
78
+ * @param string $file Image file.
79
+ * @param array $params Params.
80
+ */
81
+ public function __construct( $file = null, $params = [] ) {
82
+
83
+ $gdinfo = gd_info();
84
+ $this->is_freetype_enabled = $gdinfo['FreeType Support'];
85
+
86
+ parent::__construct( $file, $params );
87
+
88
+ }
89
+
90
+ /**
91
+ * Checks if the processor can be used in particular system
92
+ *
93
+ * @return boolean
94
+ */
95
+ public static function is_available() {
96
+
97
+ if ( extension_loaded( 'gd' ) && function_exists( 'gd_info' ) ) {
98
+ return true;
99
+ }
100
+
101
+ return false;
102
+
103
+ }
104
+
105
+ /**
106
+ * Filters available watermark types
107
+ *
108
+ * @filter easy-watermark/watermark-types
109
+ *
110
+ * @param array $types Available watermark types.
111
+ * @return array
112
+ */
113
+ public function available_watermark_types( $types ) {
114
+
115
+ if ( ! $this->is_freetype_enabled && array_key_exists( 'text', $types ) ) {
116
+ unset( $types['text'] );
117
+ }
118
+
119
+ return $types;
120
+
121
+ }
122
+
123
+ /**
124
+ * Processes image
125
+ *
126
+ * @param boolean $save Whether to save output or print it.
127
+ * @return array
128
+ */
129
+ public function process( $save = true ) {
130
+
131
+ $output_image = $this->get_output_image();
132
+
133
+ if ( ! $output_image ) {
134
+ return false;
135
+ }
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;
146
+
147
+ $this->prepare_output( $output );
148
+
149
+ return $result;
150
+
151
+ }
152
+
153
+ /**
154
+ * Prints image directly to the browser
155
+ *
156
+ * @param Watermark|null $watermark Watermark to apply for the preview.
157
+ * @param string $format Output format.
158
+ * @return void
159
+ */
160
+ public function print_preview( $watermark = null, $format = 'jpg' ) {
161
+
162
+ if ( $watermark instanceof Watermark ) {
163
+ $this->add_watermark( $watermark );
164
+ }
165
+
166
+ if ( 'jpg' === $format ) {
167
+ $format = 'jpeg';
168
+ }
169
+
170
+ $this->image_type = $format;
171
+
172
+ $this->process( false );
173
+
174
+ }
175
+
176
+ /**
177
+ * Prints image with text preview
178
+ *
179
+ * @param Watermark $watermark Text watermark for preview.
180
+ * @param string $format Output format.
181
+ * @return WP_Error|void
182
+ */
183
+ public function print_text_preview( $watermark, $format = 'png' ) {
184
+
185
+ if ( ! $watermark instanceof Watermark ) {
186
+ return new WP_Error( 'invalid_watermark_type', __( 'Watermark should be instance of Easywatermark\Watermark\Watermark.', 'easy-watermark' ) );
187
+ }
188
+
189
+ if ( 'text' !== $watermark->type ) {
190
+ return new WP_Error( 'invalid_watermark_type', __( 'Text preview can be only generated for text watermark.', 'easy-watermark' ) );
191
+ }
192
+
193
+ if ( ! $watermark->text ) {
194
+ return new WP_Error( 'empty_watermark_text', __( 'Watermark text not specified.', 'easy-watermark' ) );
195
+ }
196
+
197
+ $font = Text::get_font_path( $watermark->font );
198
+
199
+ if ( ! $font ) {
200
+ /* translators: font name */
201
+ return new WP_Error( 'font_not_found', sprintf( __( 'Font "%s" could not be found. ', 'easy-watermark' ), $watermark->font ) );
202
+ }
203
+
204
+ $text_size = $this->calculate_text_size( $watermark->text_size, $watermark->text_angle, $font, $watermark->text );
205
+
206
+ $this->output_image = imagecreatetruecolor( $text_size['width'], $text_size['height'] );
207
+
208
+ if ( false === $this->output_image ) {
209
+ return new WP_Error( 'gd_error', __( 'Could not create output image.', 'easy-watermark' ) );
210
+ }
211
+
212
+ imagealphablending( $this->output_image, false );
213
+ imagesavealpha( $this->output_image, true );
214
+
215
+ $color_transparent = imagecolorallocatealpha( $this->output_image, 255, 255, 255, 127 );
216
+
217
+ imagefill( $this->output_image, 0, 0, $color_transparent );
218
+
219
+ $watermark->alignment = 'top-left';
220
+ $watermark->offset = [
221
+ 'x' => [
222
+ 'value' => 0,
223
+ 'unit' => 'px',
224
+ ],
225
+ 'y' => [
226
+ 'value' => 0,
227
+ 'unit' => 'px',
228
+ ],
229
+ ];
230
+
231
+ if ( 'jpg' === $format ) {
232
+ $format = 'jpeg';
233
+ }
234
+
235
+ $this->image_type = $format;
236
+
237
+ $this->apply_text_watermark( $watermark );
238
+
239
+ $this->prepare_output();
240
+
241
+ }
242
+
243
+ /**
244
+ * Processes image
245
+ *
246
+ * @return resource
247
+ */
248
+ public function get_input_image() {
249
+
250
+ if ( ! $this->input_image ) {
251
+ $type = $this->get_param( 'image_type' );
252
+
253
+ $result = $this->create_image( $this->image_file, $type );
254
+
255
+ if ( ! $result ) {
256
+ return false;
257
+ }
258
+
259
+ list( $this->input_image, $this->image_type ) = $result;
260
+ }
261
+
262
+ return $this->input_image;
263
+
264
+ }
265
+
266
+ /**
267
+ * Processes image
268
+ *
269
+ * @return boolean|resource
270
+ */
271
+ public function get_output_image() {
272
+
273
+ if ( ! $this->output_image ) {
274
+ $input_image = $this->get_input_image();
275
+
276
+ if ( ! $input_image ) {
277
+ $this->output_image = false;
278
+ } else {
279
+ $image_size = $this->get_input_image_size();
280
+
281
+ // Create blank image.
282
+ $this->output_image = imagecreatetruecolor( $image_size['width'], $image_size['height'] );
283
+
284
+ if ( ! $this->output_image ) {
285
+ return false;
286
+ }
287
+
288
+ if ( 'png' === $this->image_type && $this->is_alpha_png( $this->image_file ) ) {
289
+ // Preserve opacity for png images.
290
+ imagealphablending( $this->output_image, false );
291
+ imagesavealpha( $this->output_image, true );
292
+ }
293
+
294
+ imagecopy(
295
+ $this->output_image,
296
+ $this->input_image,
297
+ 0, 0, 0, 0,
298
+ $image_size['width'],
299
+ $image_size['height']
300
+ );
301
+
302
+ // Destroy Input Image to save memory.
303
+ imagedestroy( $this->input_image );
304
+ unset( $this->input_image );
305
+
306
+ imagealphablending( $this->output_image, true );
307
+ }
308
+ }
309
+
310
+ return $this->output_image;
311
+
312
+ }
313
+
314
+ /**
315
+ * Creates GD image
316
+ *
317
+ * @param string $file_path Path to image file.
318
+ * @param string $type MIME type of the image.
319
+ * @return mixed
320
+ */
321
+ private function create_image( $file_path, $type ) {
322
+
323
+ $type = $this->detect_image_type( $type, $file_path );
324
+
325
+ if ( ! in_array( $type, $this->allowed_types, true ) ) {
326
+ return false;
327
+ }
328
+
329
+ $func_name = 'imagecreatefrom' . $type;
330
+
331
+ $image = call_user_func( $func_name, $file_path );
332
+
333
+ if ( false === $image ) {
334
+ return false;
335
+ }
336
+
337
+ if ( 'png' === $type && $this->is_alpha_png( $file_path ) ) {
338
+ imagealphablending( $image, false );
339
+ imagesavealpha( $image, true );
340
+ }
341
+
342
+ return [ $image, $type ];
343
+
344
+ }
345
+
346
+ /**
347
+ * Applies watermark
348
+ *
349
+ * @param Watermark $watermark Watermark object.
350
+ * @return mixed
351
+ */
352
+ private function apply_watermark( $watermark ) {
353
+
354
+ switch ( $watermark->type ) {
355
+ case 'image':
356
+ return $this->apply_image_watermark( $watermark );
357
+ case 'text':
358
+ return $this->apply_text_watermark( $watermark );
359
+ }
360
+
361
+ }
362
+
363
+ /**
364
+ * Applies image watermark
365
+ *
366
+ * @param Watermark $watermark Watermark object.
367
+ * @return mixed
368
+ */
369
+ private function apply_image_watermark( $watermark ) {
370
+
371
+ $output_image = $this->get_output_image();
372
+
373
+ if ( ! $output_image ) {
374
+ return new WP_Error( 'gd_error', __( 'Could not create output image. Please check your server configuration.', 'easy-watermark' ) );
375
+ }
376
+
377
+ $watermark_file = get_attached_file( $watermark->attachment_id );
378
+
379
+ if ( ! $watermark_file || ! is_file( $watermark_file ) ) {
380
+ return new WP_Error( 'watermark_file_not_found', __( 'Watermark image file does not exist.', 'easy-watermark' ) );
381
+ }
382
+
383
+ $result = $this->create_image( $watermark_file, $watermark->mime_type );
384
+
385
+ if ( ! $result ) {
386
+ return new WP_Error( 'gd_error', __( 'Something went wrong while processing watermark image.', 'easy-watermark' ) );
387
+ }
388
+
389
+ list( $watermark_image, $watermark_type ) = $result;
390
+
391
+ $watermark_size = $this->calculate_image_size( $watermark_image );
392
+
393
+ $image_size = $this->get_input_image_size();
394
+
395
+ $scaling_mode = $watermark->scaling_mode;
396
+
397
+ if ( 'contain' === $scaling_mode || 'cover' === $scaling_mode ) {
398
+ $image_ratio = $image_size['width'] / $image_size['height'];
399
+ $watermark_ratio = $watermark_size['width'] / $watermark_size['height'];
400
+
401
+ if ( ( 'cover' === $scaling_mode && $watermark_ratio < $image_ratio )
402
+ || ( 'contain' === $scaling_mode && $watermark_ratio > $image_ratio ) ) {
403
+ $scaling_mode = 'fit_to_width';
404
+ $watermark->scale = 100;
405
+ } else {
406
+ $scaling_mode = 'fit_to_height';
407
+ $watermark->scale = 100;
408
+ }
409
+ }
410
+
411
+ if ( 'fit_to_width' === $scaling_mode && ( ! $watermark->scale_down_only || $image_size['width'] < $watermark_size['width'] ) ) {
412
+ $scale = $image_size['width'] / $watermark_size['width'];
413
+ $new_width = $image_size['width'] * $watermark->scale / 100;
414
+ $new_height = $watermark_size['height'] * $scale * $watermark->scale / 100;
415
+ } elseif ( 'fit_to_height' === $scaling_mode && ( ! $watermark->scale_down_only || $image_size['height'] < $watermark_size['height'] ) ) {
416
+ $scale = $image_size['height'] / $watermark_size['height'];
417
+ $new_width = $watermark_size['width'] * $scale * $watermark->scale / 100;
418
+ $new_height = $image_size['height'] * $watermark->scale / 100;
419
+ }
420
+
421
+ if ( isset( $new_width ) ) {
422
+ $tmp_image = imagecreatetruecolor( $new_width, $new_height );
423
+
424
+ if ( ! $tmp_image ) {
425
+ return new WP_Error( 'gd_error', __( 'Could not create temporary image. Please check your server configuration.', 'easy-watermark' ) );
426
+ }
427
+
428
+ if ( 'png' === $watermark_type && $this->is_alpha_png( $watermark_file ) ) {
429
+ imagealphablending( $tmp_image, false );
430
+ imagesavealpha( $tmp_image, true );
431
+ }
432
+
433
+ imagecopyresampled(
434
+ $tmp_image,
435
+ $watermark_image,
436
+ 0, 0, 0, 0,
437
+ $new_width, $new_height,
438
+ $watermark_size['width'], $watermark_size['height']
439
+ );
440
+
441
+ // Clean memory.
442
+ imagedestroy( $watermark_image );
443
+
444
+ $watermark_image = $tmp_image;
445
+ $watermark_size['width'] = $new_width;
446
+ $watermark_size['height'] = $new_height;
447
+
448
+ unset( $tmp_image, $new_width, $nwe_height );
449
+ }
450
+
451
+ // Compute watermark offset.
452
+ $offset_x = $this->compute_offset( $this->get_position( $watermark->alignment, 'x' ), $watermark->offset['x'], $image_size['width'], $watermark_size['width'] );
453
+ $offset_y = $this->compute_offset( $this->get_position( $watermark->alignment, 'y' ), $watermark->offset['y'], $image_size['height'], $watermark_size['height'] );
454
+
455
+ // Prepare params for copying function.
456
+ $params = [
457
+ $output_image,
458
+ $watermark_image,
459
+ $offset_x,
460
+ $offset_y,
461
+ 0,
462
+ 0,
463
+ $watermark_size['width'],
464
+ $watermark_size['height'],
465
+ ];
466
+
467
+ if ( 'png' === $watermark_type && $this->is_alpha_png( $watermark_file ) ) {
468
+ // Watermark is PNG with alpha channel, use imagecopy.
469
+ $func_name = 'imagecopy';
470
+ } else {
471
+ // Use imagecopymerge with opacity param for other images.
472
+ $func_name = 'imagecopymerge';
473
+ $params[] = $watermark->opacity;
474
+ }
475
+
476
+ // Copy watermark to output image.
477
+ $result = call_user_func_array( $func_name, $params );
478
+
479
+ if ( true === $result ) {
480
+ return true;
481
+ }
482
+
483
+ return new WP_Error( 'gd_error', __( 'Something went wrong while applying watermark image.', 'easy-watermark' ) );
484
+
485
+ }
486
+
487
+ /**
488
+ * Applies text watermark
489
+ *
490
+ * @param Watermark $watermark Watermark object.
491
+ * @return mixed
492
+ */
493
+ private function apply_text_watermark( $watermark ) {
494
+
495
+ $output_image = $this->get_output_image();
496
+
497
+ if ( ! $output_image ) {
498
+ return new WP_Error( 'gd_error', __( 'Could not create output image. Please check your server configuration.', 'easy-watermark' ) );
499
+ }
500
+
501
+ $font = Text::get_font_path( $watermark->font );
502
+
503
+ if ( ! $font ) {
504
+ /* translators: font name */
505
+ return new WP_Error( 'font_not_found', sprintf( __( 'Font "%s" could not be found. ', 'easy-watermark' ), $watermark->font ) );
506
+ }
507
+
508
+ $text_size = $this->calculate_text_size( $watermark->text_size, $watermark->text_angle, $font, $watermark->text );
509
+ $image_size = $this->get_input_image_size();
510
+
511
+ $color_rgb = $this->get_rgb_color( $watermark->text_color );
512
+ $color = imagecolorallocatealpha(
513
+ $output_image,
514
+ $color_rgb['red'],
515
+ $color_rgb['green'],
516
+ $color_rgb['blue'],
517
+ 127 * ( 100 - $watermark->opacity ) / 100
518
+ );
519
+
520
+ if ( false === $color ) {
521
+ return new WP_Error( 'gd_error', __( 'Something went wrong while allocating text color.', 'easy-watermark' ) );
522
+ }
523
+
524
+ $offset_x = $this->compute_offset( $this->get_position( $watermark->alignment, 'x' ), $watermark->offset['x'], $image_size['width'], $text_size['width'] );
525
+ $offset_y = $this->compute_offset( $this->get_position( $watermark->alignment, 'y' ), $watermark->offset['y'], $image_size['height'], $text_size['height'] );
526
+
527
+ $result = imagettftext(
528
+ $output_image,
529
+ $watermark->text_size,
530
+ $watermark->text_angle,
531
+ $offset_x - $text_size['delta_x'], $offset_y - $text_size['delta_y'],
532
+ $color,
533
+ $font,
534
+ $watermark->text
535
+ );
536
+
537
+ if ( false === $result ) {
538
+ return new WP_Error( 'gd_error', __( 'Something went wrong while applying watermark text.', 'easy-watermark' ) );
539
+ }
540
+
541
+ return true;
542
+
543
+ }
544
+
545
+ /**
546
+ * Detects mime type using php finfo object
547
+ *
548
+ * @param string $type MIME type.
549
+ * @param string $file_path File path.
550
+ * @return string
551
+ */
552
+ private function detect_image_type( $type, $file_path = null ) {
553
+
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 ) {
562
+ return false;
563
+ }
564
+
565
+ if ( 0 === strpos( $type, 'image/' ) ) {
566
+ $type = substr( $type, 6 );
567
+ }
568
+
569
+ if ( 'jpg' === $type ) {
570
+ $type = 'jpeg';
571
+ }
572
+
573
+ return $type;
574
+
575
+ }
576
+
577
+ /**
578
+ * Returns input image size
579
+ *
580
+ * @return array
581
+ */
582
+ private function get_input_image_size() {
583
+
584
+ if ( ! $this->image_size ) {
585
+ $this->image_size = $this->calculate_image_size( $this->input_image );
586
+ }
587
+
588
+ return $this->image_size;
589
+
590
+ }
591
+
592
+ /**
593
+ * Returns image size
594
+ *
595
+ * @param resource $image Image to calculate dimensions.
596
+ * @return array
597
+ */
598
+ private function calculate_image_size( $image ) {
599
+
600
+ if ( ! is_resource( $image ) && ! $image instanceof \GdImage ) {
601
+ return false;
602
+ }
603
+
604
+ return [
605
+ 'width' => imagesx( $image ),
606
+ 'height' => imagesy( $image ),
607
+ ];
608
+
609
+ }
610
+
611
+ /**
612
+ * Returns size of text bounding box width x and y distance from font baseline
613
+ *
614
+ * @param integer $font_size Font size.
615
+ * @param integer $angle Text angle.
616
+ * @param string $font Path to font file.
617
+ * @param string $text Text.
618
+ * @return array
619
+ */
620
+ private function calculate_text_size( $font_size, $angle, $font, $text ) {
621
+
622
+ $bb = imagettfbbox( (float) $font_size, $angle, $font, $text );
623
+
624
+ $max_x = max( $bb[0], $bb[2], $bb[4], $bb[6] );
625
+ $min_x = min( $bb[0], $bb[2], $bb[4], $bb[6] );
626
+ $width = $max_x - $min_x;
627
+
628
+ $max_y = max( $bb[1], $bb[3], $bb[5], $bb[7] );
629
+ $min_y = min( $bb[1], $bb[3], $bb[5], $bb[7] );
630
+ $height = $max_y - $min_y;
631
+
632
+ return [
633
+ 'width' => $width,
634
+ 'height' => $height,
635
+ 'delta_x' => $min_x,
636
+ 'delta_y' => $min_y,
637
+ ];
638
+
639
+ }
640
+
641
+ /**
642
+ * Returns finfo object
643
+ *
644
+ * @return object
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
+
652
+ return $this->finfo;
653
+
654
+ }
655
+
656
+ /**
657
+ * Verifies if png file has alpha chanel
658
+ *
659
+ * @param string $file_path File path.
660
+ * @return boolean
661
+ */
662
+ public function is_alpha_png( $file_path ) {
663
+
664
+ /**
665
+ * Color type of png image stored at 25 byte:
666
+ * 0 - greyscale
667
+ * 2 - RGB
668
+ * 3 - RGB with palette
669
+ * 4 - greyscale + alpha
670
+ * 6 - RGB + alpha
671
+ */
672
+ $content = file_get_contents( $file_path, false, null, 25, 1 ); // phpcs:ignore
673
+
674
+ if ( false === $content ) {
675
+ return false;
676
+ }
677
+
678
+ $color_byte = ord( $content );
679
+
680
+ return ( 6 === $color_byte || 4 === $color_byte );
681
+
682
+ }
683
+
684
+ /**
685
+ * Saves or outputs created image
686
+ *
687
+ * @param string $output Output file.
688
+ * @return boolean
689
+ */
690
+ private function prepare_output( $output = null ) {
691
+
692
+ if ( ! $this->image_type || ! in_array( $this->image_type, $this->allowed_types, true ) ) {
693
+ return false;
694
+ }
695
+
696
+ if ( null === $output ) {
697
+ // Return image directly to the browser.
698
+ header( 'Content-Type: image/' . $this->image_type );
699
+ }
700
+
701
+ $params = [
702
+ $this->output_image,
703
+ $output,
704
+ ];
705
+
706
+ if ( 'jpeg' === $this->image_type ) {
707
+ $params[] = $this->get_param( 'jpeg_quality', -1 );
708
+ }
709
+
710
+ $func_name = 'image' . $this->image_type;
711
+
712
+ $result = call_user_func_array( $func_name, $params );
713
+
714
+ return $result;
715
+
716
+ }
717
+
718
+ /**
719
+ * Performs cleaning
720
+ *
721
+ * @return void
722
+ */
723
+ public function clean() {
724
+
725
+ parent::clean();
726
+
727
+ if ( $this->watermark_image ) {
728
+ imagedestroy( $this->watermark_image );
729
+ $this->watermark_image = null;
730
+ }
731
+
732
+ if ( $this->output_image ) {
733
+ imagedestroy( $this->output_image );
734
+ $this->output_image = null;
735
+ }
736
+
737
+ $this->image_size = null;
738
+ $this->input_image = null;
739
+
740
+ }
741
+
742
+ /**
743
+ * Destructor
744
+ */
745
+ public function __destruct() {
746
+
747
+ $this->clean();
748
+
749
+ }
750
+ }
src/classes/AttachmentProcessor/Manager.php CHANGED
@@ -1,51 +1,51 @@
1
- <?php
2
- /**
3
- * AttachmentProcessor Manager
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\AttachmentProcessor;
9
-
10
- use EasyWatermark\Core\Manager as AbstractManager;
11
- use Micropackage\Singleton\Singleton;
12
- use WP_Error;
13
-
14
- /**
15
- * Manager class
16
- */
17
- class Manager extends AbstractManager {
18
-
19
- /**
20
- * Parent class for created objects
21
- *
22
- * @var string
23
- */
24
- protected $parent_class = 'EasyWatermark\AttachmentProcessor\AttachmentProcessor';
25
-
26
- /**
27
- * Constructor
28
- */
29
- protected function __construct() {
30
-
31
- $processors = [
32
- 'gd' => [
33
- 'label' => __( 'GD', 'easy-watermark' ),
34
- 'class' => 'EasyWatermark\\AttachmentProcessor\\AttachmentProcessorGD',
35
- ],
36
- ];
37
-
38
- $this->default_classes = apply_filters( 'easy-watermark/available-processors', $processors );
39
-
40
- $this->error_messages = [
41
- /* translators: %s: class name. */
42
- 'invalid_class' => __( 'Attachment processor class "%s" does not exist.' ),
43
- /* translators: %1$s: child class name, %2$s: parent class name. */
44
- 'invalid_class_parent' => __( 'Attachment processor "%1$s" must extend %2$s.' ),
45
- /* translators: %s: object type. */
46
- 'invalid_type' => __( 'Attachment processor of type "%s" cannot be created.' ),
47
- ];
48
-
49
- parent::__construct();
50
- }
51
- }
1
+ <?php
2
+ /**
3
+ * AttachmentProcessor Manager
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\AttachmentProcessor;
9
+
10
+ use EasyWatermark\Core\Manager as AbstractManager;
11
+ use Micropackage\Singleton\Singleton;
12
+ use WP_Error;
13
+
14
+ /**
15
+ * Manager class
16
+ */
17
+ class Manager extends AbstractManager {
18
+
19
+ /**
20
+ * Parent class for created objects
21
+ *
22
+ * @var string
23
+ */
24
+ protected $parent_class = 'EasyWatermark\AttachmentProcessor\AttachmentProcessor';
25
+
26
+ /**
27
+ * Constructor
28
+ */
29
+ protected function __construct() {
30
+
31
+ $processors = [
32
+ 'gd' => [
33
+ 'label' => __( 'GD', 'easy-watermark' ),
34
+ 'class' => 'EasyWatermark\\AttachmentProcessor\\AttachmentProcessorGD',
35
+ ],
36
+ ];
37
+
38
+ $this->default_classes = apply_filters( 'easy-watermark/available-processors', $processors );
39
+
40
+ $this->error_messages = [
41
+ /* translators: %s: class name. */
42
+ 'invalid_class' => __( 'Attachment processor class "%s" does not exist.' ),
43
+ /* translators: %1$s: child class name, %2$s: parent class name. */
44
+ 'invalid_class_parent' => __( 'Attachment processor "%1$s" must extend %2$s.' ),
45
+ /* translators: %s: object type. */
46
+ 'invalid_type' => __( 'Attachment processor of type "%s" cannot be created.' ),
47
+ ];
48
+
49
+ parent::__construct();
50
+ }
51
+ }
src/classes/Backup/Manager.php CHANGED
@@ -1,108 +1,108 @@
1
- <?php
2
- /**
3
- * Backupper Factory
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Backup;
9
-
10
- use EasyWatermark\Core\Manager as AbstractManager;
11
- use EasyWatermark\Settings\Settings;
12
- use EasyWatermark\Settings\Section;
13
- use EasyWatermark\Settings\Fields\SwitchField;
14
- use EasyWatermark\Settings\Fields\Dropdown;
15
- use EasyWatermark\Traits\Hookable;
16
- use Micropackage\Singleton\Singleton;
17
- use WP_Error;
18
-
19
- /**
20
- * BackupperFactory class
21
- */
22
- class Manager extends AbstractManager {
23
-
24
- use Hookable;
25
-
26
- /**
27
- * Parent class for created objects
28
- *
29
- * @var string
30
- */
31
- protected $interface = 'EasyWatermark\Backup\BackupperInterface';
32
- /**
33
- * Constructor
34
- */
35
- protected function __construct() {
36
-
37
- $this->hook();
38
-
39
- $backuppers = [
40
- 'local' => [
41
- 'label' => __( 'Local Backup', 'easy-watermark' ),
42
- 'class' => 'EasyWatermark\\Backup\\LocalBackupper',
43
- ],
44
- ];
45
-
46
- $this->default_classes = apply_filters( 'easy-watermark/available-backuppers', $backuppers );
47
-
48
- $this->error_messages = [
49
- /* translators: %s: class name. */
50
- 'invalid_class' => __( 'Backupper class "%s" does not exist.' ),
51
- /* translators: %1$s: child class name, %2$s: parent class name. */
52
- 'invalid_class_interface' => __( 'Backupper "%1$s" must implement %2$s interface.' ),
53
- /* translators: %s: object type. */
54
- 'invalid_type' => __( 'Backupper of type "%s" cannot be created.' ),
55
- ];
56
-
57
- parent::__construct();
58
- }
59
-
60
- /**
61
- * Registers settings section
62
- *
63
- * @action easy-watermark/settings/register
64
- *
65
- * @param Settings $settings Settings object.
66
- * @return void
67
- */
68
- public function register_settings_section( $settings ) {
69
- $settings->add_section( new Section( __( 'Backup', 'easy-watermark' ), 'backup' ) );
70
- }
71
-
72
- /**
73
- * Registers settings fields
74
- *
75
- * @action easy-watermark/settings/register/backup
76
- *
77
- * @param Section $section Settings section.
78
- * @return void
79
- */
80
- public function register_settings_fields( $section ) {
81
-
82
- $section->add_field( new SwitchField( [
83
- 'label' => esc_html__( 'Enable backup', 'easy-watermark' ),
84
- 'slug' => 'backup',
85
- 'default' => true,
86
- 'layout' => 'one-column',
87
- 'toggle' => 'backup',
88
- ] ) );
89
-
90
- $backuppers = $this->get_available_objects();
91
- $options = [];
92
-
93
- foreach ( $backuppers as $backupper => $details ) {
94
- $options[ $backupper ] = $details['label'];
95
- }
96
-
97
- $default = array_key_exists( 'local', $backuppers ) ? 'local' : null;
98
-
99
- $section->add_field( new Dropdown( [
100
- 'label' => esc_html__( 'Backupper', 'easy-watermark' ),
101
- 'slug' => 'backupper',
102
- 'options' => $options,
103
- 'default' => $default,
104
- 'group' => 'backup',
105
- ] ) );
106
-
107
- }
108
- }
1
+ <?php
2
+ /**
3
+ * Backupper Factory
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Backup;
9
+
10
+ use EasyWatermark\Core\Manager as AbstractManager;
11
+ use EasyWatermark\Settings\Settings;
12
+ use EasyWatermark\Settings\Section;
13
+ use EasyWatermark\Settings\Fields\SwitchField;
14
+ use EasyWatermark\Settings\Fields\Dropdown;
15
+ use EasyWatermark\Traits\Hookable;
16
+ use Micropackage\Singleton\Singleton;
17
+ use WP_Error;
18
+
19
+ /**
20
+ * BackupperFactory class
21
+ */
22
+ class Manager extends AbstractManager {
23
+
24
+ use Hookable;
25
+
26
+ /**
27
+ * Parent class for created objects
28
+ *
29
+ * @var string
30
+ */
31
+ protected $interface = 'EasyWatermark\Backup\BackupperInterface';
32
+ /**
33
+ * Constructor
34
+ */
35
+ protected function __construct() {
36
+
37
+ $this->hook();
38
+
39
+ $backuppers = [
40
+ 'local' => [
41
+ 'label' => __( 'Local Backup', 'easy-watermark' ),
42
+ 'class' => 'EasyWatermark\\Backup\\LocalBackupper',
43
+ ],
44
+ ];
45
+
46
+ $this->default_classes = apply_filters( 'easy-watermark/available-backuppers', $backuppers );
47
+
48
+ $this->error_messages = [
49
+ /* translators: %s: class name. */
50
+ 'invalid_class' => __( 'Backupper class "%s" does not exist.' ),
51
+ /* translators: %1$s: child class name, %2$s: parent class name. */
52
+ 'invalid_class_interface' => __( 'Backupper "%1$s" must implement %2$s interface.' ),
53
+ /* translators: %s: object type. */
54
+ 'invalid_type' => __( 'Backupper of type "%s" cannot be created.' ),
55
+ ];
56
+
57
+ parent::__construct();
58
+ }
59
+
60
+ /**
61
+ * Registers settings section
62
+ *
63
+ * @action easy-watermark/settings/register
64
+ *
65
+ * @param Settings $settings Settings object.
66
+ * @return void
67
+ */
68
+ public function register_settings_section( $settings ) {
69
+ $settings->add_section( new Section( __( 'Backup', 'easy-watermark' ), 'backup' ) );
70
+ }
71
+
72
+ /**
73
+ * Registers settings fields
74
+ *
75
+ * @action easy-watermark/settings/register/backup
76
+ *
77
+ * @param Section $section Settings section.
78
+ * @return void
79
+ */
80
+ public function register_settings_fields( $section ) {
81
+
82
+ $section->add_field( new SwitchField( [
83
+ 'label' => esc_html__( 'Enable backup', 'easy-watermark' ),
84
+ 'slug' => 'backup',
85
+ 'default' => true,
86
+ 'layout' => 'one-column',
87
+ 'toggle' => 'backup',
88
+ ] ) );
89
+
90
+ $backuppers = $this->get_available_objects();
91
+ $options = [];
92
+
93
+ foreach ( $backuppers as $backupper => $details ) {
94
+ $options[ $backupper ] = $details['label'];
95
+ }
96
+
97
+ $default = array_key_exists( 'local', $backuppers ) ? 'local' : null;
98
+
99
+ $section->add_field( new Dropdown( [
100
+ 'label' => esc_html__( 'Backupper', 'easy-watermark' ),
101
+ 'slug' => 'backupper',
102
+ 'options' => $options,
103
+ 'default' => $default,
104
+ 'group' => 'backup',
105
+ ] ) );
106
+
107
+ }
108
+ }
src/classes/Core/Assets.php CHANGED
@@ -1,332 +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
- 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
- }
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/Hooks.php CHANGED
@@ -1,83 +1,83 @@
1
- <?php
2
- /**
3
- * View class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Core;
9
-
10
- use Micropackage\Singleton\Singleton;
11
-
12
- /**
13
- * View class
14
- */
15
- class Hooks extends Singleton {
16
-
17
- /**
18
- * Hooked objects
19
- *
20
- * @var array
21
- */
22
- private $objects = [];
23
-
24
- /**
25
- * Adds object.
26
- *
27
- * @param object $object Object.
28
- * @return void
29
- */
30
- public function add_object( $object ) {
31
-
32
- $class_name = get_class( $object );
33
-
34
- if ( ! isset( $this->objects[ $class_name ] ) ) {
35
- $this->objects[ $class_name ] = [
36
- 'instance' => $object,
37
- 'hooks' => [],
38
- ];
39
- }
40
-
41
- }
42
-
43
- /**
44
- * Adds hook.
45
- *
46
- * @param object $object Object.
47
- * @param array $data Hook data.
48
- * @return void
49
- */
50
- public function add_hook( $object, $data ) {
51
-
52
- $class_name = get_class( $object );
53
-
54
- if ( ! isset( $this->objects[ $class_name ] ) ) {
55
- $this->add_object( $object );
56
- }
57
-
58
- $this->objects[ $class_name ]['hooks'][] = $data;
59
-
60
- }
61
-
62
- /**
63
- * Gets hooked objects.
64
- *
65
- * @return array
66
- */
67
- public function get_hooked_objects() {
68
- return $this->objects;
69
- }
70
-
71
- /**
72
- * Gets hooked objects.
73
- *
74
- * @return void
75
- */
76
- public function load_hooks() {
77
- $hooks_file = EW_DIR_PATH . '/src/inc/hooks.php';
78
-
79
- if ( file_exists( $hooks_file ) ) {
80
- include_once $hooks_file;
81
- }
82
- }
83
- }
1
+ <?php
2
+ /**
3
+ * View class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Core;
9
+
10
+ use Micropackage\Singleton\Singleton;
11
+
12
+ /**
13
+ * View class
14
+ */
15
+ class Hooks extends Singleton {
16
+
17
+ /**
18
+ * Hooked objects
19
+ *
20
+ * @var array
21
+ */
22
+ private $objects = [];
23
+
24
+ /**
25
+ * Adds object.
26
+ *
27
+ * @param object $object Object.
28
+ * @return void
29
+ */
30
+ public function add_object( $object ) {
31
+
32
+ $class_name = get_class( $object );
33
+
34
+ if ( ! isset( $this->objects[ $class_name ] ) ) {
35
+ $this->objects[ $class_name ] = [
36
+ 'instance' => $object,
37
+ 'hooks' => [],
38
+ ];
39
+ }
40
+
41
+ }
42
+
43
+ /**
44
+ * Adds hook.
45
+ *
46
+ * @param object $object Object.
47
+ * @param array $data Hook data.
48
+ * @return void
49
+ */
50
+ public function add_hook( $object, $data ) {
51
+
52
+ $class_name = get_class( $object );
53
+
54
+ if ( ! isset( $this->objects[ $class_name ] ) ) {
55
+ $this->add_object( $object );
56
+ }
57
+
58
+ $this->objects[ $class_name ]['hooks'][] = $data;
59
+
60
+ }
61
+
62
+ /**
63
+ * Gets hooked objects.
64
+ *
65
+ * @return array
66
+ */
67
+ public function get_hooked_objects() {
68
+ return $this->objects;
69
+ }
70
+
71
+ /**
72
+ * Gets hooked objects.
73
+ *
74
+ * @return void
75
+ */
76
+ public function load_hooks() {
77
+ $hooks_file = EW_DIR_PATH . '/src/inc/hooks.php';
78
+
79
+ if ( file_exists( $hooks_file ) ) {
80
+ include_once $hooks_file;
81
+ }
82
+ }
83
+ }
src/classes/Core/Installer.php CHANGED
@@ -1,494 +1,496 @@
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
- }
 
 
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
+ if ( version_compare( $from, '1.0.0', '>=' ) ) {
127
+ self::update_attachment_meta();
128
+ return;
129
+ }
130
+
131
+ if ( $from ) {
132
+ $plugin_slug = Plugin::get()->get_slug();
133
+ $settings = [];
134
+
135
+ if ( version_compare( $from, '0.1.1', '>' ) ) {
136
+ $settings['general'] = get_option( $plugin_slug . '-settings-general' );
137
+ $settings['image'] = get_option( $plugin_slug . '-settings-image' );
138
+ $settings['text'] = get_option( $plugin_slug . '-settings-text' );
139
+
140
+ delete_option( $plugin_slug . '-settings-general' );
141
+ delete_option( $plugin_slug . '-settings-image' );
142
+ delete_option( $plugin_slug . '-settings-text' );
143
+ } else {
144
+ $old_settings = get_option( $plugin_slug . '-settings' );
145
+
146
+ delete_option( $plugin_slug . '-settings' );
147
+
148
+ $general = [
149
+ 'auto_add' => $old_settings['auto_add'],
150
+ 'image_types' => $old_settings['image_types'],
151
+ ];
152
+
153
+ switch ( $from ) {
154
+ case '0.1.1':
155
+ $image = [
156
+ 'watermark_url' => $old_settings['image']['url'],
157
+ 'watermark_id' => $old_settings['image']['id'],
158
+ 'watermark_path' => $old_settings['image']['path'],
159
+ 'watermark_mime' => $old_settings['image']['mime'],
160
+ 'position_x' => $old_settings['image']['position_x'],
161
+ 'position_y' => $old_settings['image']['position_y'],
162
+ 'offset_x' => $old_settings['image']['offset_x'],
163
+ 'offset_y' => $old_settings['image']['offset_y'],
164
+ 'opacity' => $old_settings['image']['opacity'],
165
+ ];
166
+ break;
167
+ default:
168
+ $image = [
169
+ 'watermark_url' => $old_settings['image']['url'],
170
+ 'watermark_id' => $old_settings['image']['id'],
171
+ 'watermark_path' => $old_settings['image']['path'],
172
+ 'watermark_mime' => $old_settings['image']['mime'],
173
+ 'position_x' => $old_settings['image']['position-horizontal'],
174
+ 'position_y' => $old_settings['image']['position-vert'],
175
+ 'offset_x' => $old_settings['image']['offset-horizontal'],
176
+ 'offset_y' => $old_settings['image']['offset-vert'],
177
+ 'opacity' => $old_settings['image']['alpha'],
178
+ ];
179
+ break;
180
+ }
181
+
182
+ $settings = [
183
+ 'general' => $general,
184
+ 'image' => $image,
185
+ 'text' => [],
186
+ ];
187
+
188
+ delete_option( $plugin_slug . '-settings' );
189
+ }
190
+
191
+ $settings['image']['alignment'] = self::get_alignment( $settings['image']['position_x'], $settings['image']['position_y'] );
192
+ $settings['text']['alignment'] = self::get_alignment( $settings['text']['position_x'], $settings['text']['position_y'] );
193
+
194
+ $watermark_defaults = Watermark::get_defaults();
195
+
196
+ $watermark_defaults['auto_add'] = $settings['general']['auto_add'];
197
+
198
+ if ( isset( $settings['general']['auto_add_perm'] ) ) {
199
+ $watermark_defaults['auto_add_all'] = $settings['general']['auto_add_perm'];
200
+ }
201
+
202
+ if ( isset( $settings['general']['image_types'] ) ) {
203
+ $watermark_defaults['image_types'] = $settings['general']['image_types'];
204
+ }
205
+
206
+ if ( isset( $settings['general']['image_sizes'] ) ) {
207
+ $watermark_defaults['image_sizes'] = $settings['general']['image_sizes'];
208
+ }
209
+
210
+ if ( isset( $settings['general']['allowed_post_types'] ) ) {
211
+ $watermark_defaults['post_types'] = $settings['general']['allowed_post_types'];
212
+ }
213
+
214
+ if ( isset( $settings['general']['jpg_quality'] ) ) {
215
+ $defaults['general']['jpeg_quality'] = $settings['general']['jpg_quality'];
216
+ }
217
+
218
+ update_option( Plugin::get()->get_slug() . '-settings', $defaults );
219
+
220
+ if ( isset( $settings['image']['watermark_id'] ) && ! empty( $settings['image']['watermark_id'] ) ) {
221
+ self::insert_image_watermark( $watermark_defaults, $settings );
222
+ }
223
+
224
+ if ( ! empty( $settings['text']['text'] ) ) {
225
+ self::insert_text_watermark( $watermark_defaults, $settings );
226
+ }
227
+ }
228
+
229
+ self::update_backup_info();
230
+
231
+ update_option( Plugin::get()->get_slug() . '-version', Plugin::get()->get_version() );
232
+
233
+ }
234
+
235
+ /**
236
+ * Update attachment meta
237
+ *
238
+ * @return void
239
+ */
240
+ private static function update_attachment_meta() {
241
+ global $wpdb;
242
+
243
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery
244
+ $meta = $wpdb->get_results( $wpdb->prepare( "SELECT `post_id`, `meta_value` FROM {$wpdb->postmeta} WHERE `meta_key` = %s", '_ew_applied_watermarks' ) );
245
+
246
+ foreach ( $meta as $entry ) {
247
+ $value = maybe_unserialize( $entry->meta_value );
248
+
249
+ if ( is_array( $value ) ) {
250
+ $new_value = [];
251
+
252
+ foreach ( $value as $watermark_id ) {
253
+ $watermark = Watermark::get( $watermark_id );
254
+
255
+ if ( $watermark ) {
256
+ $new_value[ $watermark_id ] = $watermark->post_title;
257
+ }
258
+ }
259
+
260
+ if ( $new_value ) {
261
+ update_post_meta( $entry->post_id, '_ew_applied_watermarks', $new_value );
262
+ } else {
263
+ delete_post_meta( $entry->post_id, '_ew_applied_watermarks' );
264
+ }
265
+ }
266
+ }
267
+ }
268
+
269
+ /**
270
+ * Updates backup info
271
+ *
272
+ * @return void
273
+ */
274
+ private static function update_backup_info() {
275
+
276
+ $attachments = get_posts( [
277
+ 'posts_per_page' => -1,
278
+ 'post_type' => 'attachment',
279
+ 'meta_query' => [
280
+ [
281
+ 'key' => '_ew_backup_file',
282
+ 'compare' => 'EXISTS',
283
+ ],
284
+ ],
285
+ ] );
286
+
287
+ foreach ( $attachments as $attachment ) {
288
+ update_post_meta( $attachment->ID, '_ew_has_backup', true );
289
+ }
290
+
291
+ }
292
+
293
+ /**
294
+ * Updates backup info
295
+ *
296
+ * @return array
297
+ */
298
+ private static function get_watermarked_attachments() {
299
+
300
+ if ( ! self::$watermarked_attachments ) {
301
+ self::$watermarked_attachments = get_posts( [
302
+ 'posts_per_page' => -1,
303
+ 'post_type' => 'attachment',
304
+ 'meta_key' => '_ew_watermarked',
305
+ 'meta_value' => '1',
306
+ ] );
307
+ }
308
+
309
+ return self::$watermarked_attachments;
310
+
311
+ }
312
+
313
+ /**
314
+ * Inserts image watermark based on previous version settings
315
+ *
316
+ * @param array $defaults Default watermark params.
317
+ * @param array $settings Watermark settings.
318
+ * @return integer
319
+ */
320
+ private static function insert_image_watermark( $defaults, $settings ) {
321
+
322
+ $image_settings = [
323
+ 'type' => 'image',
324
+ 'attachment_id' => $settings['image']['watermark_id'],
325
+ 'mime_type' => $settings['image']['watermark_mime'],
326
+ 'url' => $settings['image']['watermark_url'],
327
+ 'alignment' => $settings['image']['alignment'],
328
+ 'opacity' => $settings['image']['opacity'],
329
+ 'offset' => [
330
+ 'x' => [
331
+ 'value' => intval( $settings['image']['offset_x'] ),
332
+ 'unit' => ( '%' === substr( $settings['image']['offset_x'], -1 ) ) ? '%' : 'px',
333
+ ],
334
+ 'y' => [
335
+ 'value' => intval( $settings['image']['offset_y'] ),
336
+ 'unit' => ( '%' === substr( $settings['image']['offset_y'], -1 ) ) ? '%' : 'px',
337
+ ],
338
+ ],
339
+ ];
340
+
341
+ if ( isset( $settings['image']['scale_mode'] ) ) {
342
+ $image_settings['scaling_mode'] = $settings['image']['scale_mode'];
343
+
344
+ if ( 'fit' === $image_settings['scaling_mode'] ) {
345
+ $image_settings['scaling_mode'] = 'contain';
346
+ }
347
+
348
+ if ( 'fill' === $image_settings['scaling_mode'] ) {
349
+ $image_settings['scaling_mode'] = 'cover';
350
+ }
351
+ }
352
+
353
+ if ( isset( $settings['image']['scale_to_smaller'] ) ) {
354
+ $image_settings['scale_down_only'] = $settings['image']['scale_to_smaller'];
355
+ }
356
+
357
+ if ( isset( $settings['image']['scale'] ) ) {
358
+ $image_settings['scale'] = $settings['image']['scale'];
359
+ }
360
+
361
+ $image_settings = array_merge( $defaults, $image_settings );
362
+
363
+ $watermark_id = wp_insert_post( [
364
+ 'post_title' => __( 'Image Watermark', 'easy-watermark' ),
365
+ 'post_type' => 'watermark',
366
+ 'post_status' => 'publish',
367
+ 'watermark' => $image_settings,
368
+ ] );
369
+
370
+ if ( in_array( $settings['general']['watermark_type'], [ '1', '3' ], true ) ) {
371
+ $attachments = self::get_watermarked_attachments();
372
+
373
+ foreach ( $attachments as $attachment ) {
374
+ self::add_applied_watermark( $attachment->ID, $watermark_id );
375
+ }
376
+ }
377
+
378
+ return $watermark_id;
379
+
380
+ }
381
+
382
+ /**
383
+ * Inserts text watermark based on previous version settings
384
+ *
385
+ * @param array $defaults Default watermark params.
386
+ * @param array $settings Watermark settings.
387
+ * @return integer
388
+ */
389
+ private static function insert_text_watermark( $defaults, $settings ) {
390
+
391
+ $text_settings = [
392
+ 'type' => 'text',
393
+ 'text' => $settings['text']['text'],
394
+ 'font' => $settings['text']['font'],
395
+ 'text_color' => $settings['text']['color'],
396
+ 'text_size' => $settings['text']['size'],
397
+ 'text_angle' => $settings['text']['angle'],
398
+ 'opacity' => $settings['text']['opacity'],
399
+ 'alignment' => $settings['text']['alignment'],
400
+ 'offset' => [
401
+ 'x' => [
402
+ 'value' => intval( $settings['text']['offset_x'] ),
403
+ 'unit' => ( '%' === substr( $settings['text']['offset_x'], -1 ) ) ? '%' : 'px',
404
+ ],
405
+ 'y' => [
406
+ 'value' => intval( $settings['text']['offset_y'] ),
407
+ 'unit' => ( '%' === substr( $settings['text']['offset_y'], -1 ) ) ? '%' : 'px',
408
+ ],
409
+ ],
410
+ ];
411
+
412
+ $text_settings = array_merge( $defaults, $text_settings );
413
+
414
+ $watermark_id = wp_insert_post( [
415
+ 'post_title' => __( 'Text Watermark', 'easy-watermark' ),
416
+ 'post_type' => 'watermark',
417
+ 'post_status' => 'publish',
418
+ 'watermark' => $text_settings,
419
+ ] );
420
+
421
+ if ( in_array( $settings['general']['watermark_type'], [ '2', '3' ], true ) ) {
422
+ $attachments = self::get_watermarked_attachments();
423
+
424
+ foreach ( $attachments as $attachment ) {
425
+ self::add_applied_watermark( $attachment->ID, $watermark_id );
426
+ }
427
+ }
428
+
429
+ return $watermark_id;
430
+
431
+ }
432
+
433
+ /**
434
+ * Add watermark to attachment meta
435
+ *
436
+ * @param integer $attachment_id Attachment ID.
437
+ * @param integer $watermark_id Watermark ID.
438
+ * @return void
439
+ */
440
+ private static function add_applied_watermark( $attachment_id, $watermark_id ) {
441
+
442
+ $meta = get_post_meta( $attachment_id, '_ew_applied_watermarks', true );
443
+
444
+ if ( ! is_array( $meta ) ) {
445
+ $meta = [];
446
+ }
447
+
448
+ if ( ! in_array( $watermark_id, $meta, true ) ) {
449
+ $meta[] = $watermark_id;
450
+ update_post_meta( $attachment_id, '_ew_applied_watermarks', $meta );
451
+ }
452
+
453
+ }
454
+
455
+ /**
456
+ * Computes alignment based on position_x and position_y
457
+ *
458
+ * @param string $x Horizontal position.
459
+ * @param string $y Vertical position.
460
+ * @return string
461
+ */
462
+ private static function get_alignment( $x, $y ) {
463
+ $alignment = null;
464
+
465
+ if ( 'mdl' === $y || 'middle' === $y ) {
466
+ $y = null;
467
+ }
468
+
469
+ if ( 'btm' === $y ) {
470
+ $y = 'bottom';
471
+ }
472
+
473
+ if ( 'lft' === $x ) {
474
+ $x = 'left';
475
+ }
476
+
477
+ if ( 'ctr' === $x || 'center' === $x ) {
478
+ $x = null;
479
+ }
480
+
481
+ if ( 'rgt' === $x ) {
482
+ $x = 'right';
483
+ }
484
+
485
+ $alignment = $y . '-' . $x;
486
+
487
+ if ( null === $x && null === $y ) {
488
+ $alignment = 'center';
489
+ } else {
490
+ $alignment = trim( $y . '-' . $x, '-' );
491
+ }
492
+
493
+ return $alignment;
494
+
495
+ }
496
+ }
src/classes/Core/Manager.php CHANGED
@@ -1,195 +1,195 @@
1
- <?php
2
- /**
3
- * Manager
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Core;
9
-
10
- use Micropackage\Singleton\Singleton;
11
- use WP_Error;
12
-
13
- /**
14
- * Manager class
15
- */
16
- abstract class Manager extends Singleton {
17
-
18
- /**
19
- * Instances
20
- *
21
- * @var array
22
- */
23
- protected $objects = [];
24
-
25
- /**
26
- * Available classes
27
- *
28
- * @var array
29
- */
30
- protected $available_classes = [];
31
-
32
- /**
33
- * Available classes
34
- *
35
- * @var array
36
- */
37
- protected $default_classes = [];
38
-
39
- /**
40
- * Error messages
41
- *
42
- * @var array
43
- */
44
- protected $error_messages = [];
45
-
46
- /**
47
- * Parent class for created objects
48
- *
49
- * @var string
50
- */
51
- protected $parent_class = false;
52
-
53
- /**
54
- * Interface for created objects
55
- *
56
- * @var string
57
- */
58
- protected $interface = false;
59
-
60
- /**
61
- * Constructor
62
- */
63
- protected function __construct() {
64
-
65
- $this->error_messages = array_merge( [
66
- /* translators: %s: class name. */
67
- 'invalid_class' => __( 'Class "%s" does not exist.' ),
68
- /* translators: %1$s: child class name, %2$s: parent class name. */
69
- 'invalid_class_parent' => __( 'Class "%1$s" must extend %2$s.' ),
70
- /* translators: %1$s: child class name, %2$s: parent class name. */
71
- 'invalid_class_interface' => __( 'Class "%1$s" must implement %2$s interface.' ),
72
- /* translators: %s: object type. */
73
- 'invalid_type' => __( 'Object of type "%s" cannot be created.' ),
74
- ], $this->error_messages );
75
-
76
- foreach ( $this->default_classes as $key => $config ) {
77
- $this->register( $key, $config['label'], $config['class'] );
78
- }
79
-
80
- }
81
-
82
- /**
83
- * Registers available class
84
- *
85
- * @param string $type Object type.
86
- * @param string $label Object nice name to show in admin area.
87
- * @param string $class Object class name.
88
- * @return WP_Error|true
89
- */
90
- public function register( $type, $label, $class ) {
91
-
92
- if ( ! class_exists( $class ) ) {
93
- return new WP_Error( 'invalid_class', sprintf( $this->error_messages['invalid_class'], $class ) );
94
- }
95
-
96
- if ( false !== $this->parent_class ) {
97
- $valid = $this->validate_parent( $class );
98
-
99
- if ( is_wp_error( $valid ) ) {
100
- return $valid;
101
- }
102
- }
103
-
104
- if ( false !== $this->interface ) {
105
- $valid = $this->validate_interface( $class );
106
-
107
- if ( is_wp_error( $valid ) ) {
108
- return $valid;
109
- }
110
- }
111
-
112
- $this->available_classes[ $type ] = [
113
- 'label' => $label,
114
- 'class' => $class,
115
- ];
116
-
117
- return true;
118
-
119
- }
120
-
121
- /**
122
- * Validates class parent
123
- *
124
- * @param string $class Class name.
125
- * @return WP_Error|true
126
- */
127
- protected function validate_parent( $class ) {
128
-
129
- if ( ! empty( $this->parent_class ) && ! is_subclass_of( $class, $this->parent_class ) ) {
130
- return new WP_Error( 'invalid_class_parent', sprintf( $this->error_messages['invalid_class_parent'], $class, $this->parent_class ) );
131
- }
132
-
133
- return true;
134
-
135
- }
136
-
137
- /**
138
- * Validates class interface
139
- *
140
- * @param string $class Class name.
141
- * @return WP_Error|true
142
- */
143
- protected function validate_interface( $class ) {
144
-
145
- if ( ! in_array( $this->interface, class_implements( $class ), true ) ) {
146
- return new WP_Error( 'invalid_class_interface', sprintf( $this->error_messages['invalid_class_interface'], $class, $this->interface ) );
147
- }
148
-
149
- return true;
150
-
151
- }
152
-
153
- /**
154
- * Returns instance of given type
155
- *
156
- * @param string $type Object type.
157
- * @return Object|WP_Error
158
- */
159
- public function get_object( $type ) {
160
-
161
- if ( ! array_key_exists( $type, $this->objects ) ) {
162
- return $this->create( $type );
163
- }
164
-
165
- return $this->objects[ $type ];
166
-
167
- }
168
-
169
- /**
170
- * Returns instance of given type
171
- *
172
- * @param string $type Object type.
173
- * @return Object
174
- */
175
- protected function create( $type ) {
176
-
177
- if ( ! array_key_exists( $type, $this->available_classes ) ) {
178
- return new WP_Error( 'invalid_type', sprintf( $this->error_messages['invalid_type'], $type ) );
179
- }
180
-
181
- $class = $this->available_classes[ $type ]['class'];
182
-
183
- return new $class();
184
-
185
- }
186
-
187
- /**
188
- * Returns available classes
189
- *
190
- * @return array
191
- */
192
- public function get_available_objects() {
193
- return $this->available_classes;
194
- }
195
- }
1
+ <?php
2
+ /**
3
+ * Manager
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Core;
9
+
10
+ use Micropackage\Singleton\Singleton;
11
+ use WP_Error;
12
+
13
+ /**
14
+ * Manager class
15
+ */
16
+ abstract class Manager extends Singleton {
17
+
18
+ /**
19
+ * Instances
20
+ *
21
+ * @var array
22
+ */
23
+ protected $objects = [];
24
+
25
+ /**
26
+ * Available classes
27
+ *
28
+ * @var array
29
+ */
30
+ protected $available_classes = [];
31
+
32
+ /**
33
+ * Available classes
34
+ *
35
+ * @var array
36
+ */
37
+ protected $default_classes = [];
38
+
39
+ /**
40
+ * Error messages
41
+ *
42
+ * @var array
43
+ */
44
+ protected $error_messages = [];
45
+
46
+ /**
47
+ * Parent class for created objects
48
+ *
49
+ * @var string
50
+ */
51
+ protected $parent_class = false;
52
+
53
+ /**
54
+ * Interface for created objects
55
+ *
56
+ * @var string
57
+ */
58
+ protected $interface = false;
59
+
60
+ /**
61
+ * Constructor
62
+ */
63
+ protected function __construct() {
64
+
65
+ $this->error_messages = array_merge( [
66
+ /* translators: %s: class name. */
67
+ 'invalid_class' => __( 'Class "%s" does not exist.' ),
68
+ /* translators: %1$s: child class name, %2$s: parent class name. */
69
+ 'invalid_class_parent' => __( 'Class "%1$s" must extend %2$s.' ),
70
+ /* translators: %1$s: child class name, %2$s: parent class name. */
71
+ 'invalid_class_interface' => __( 'Class "%1$s" must implement %2$s interface.' ),
72
+ /* translators: %s: object type. */
73
+ 'invalid_type' => __( 'Object of type "%s" cannot be created.' ),
74
+ ], $this->error_messages );
75
+
76
+ foreach ( $this->default_classes as $key => $config ) {
77
+ $this->register( $key, $config['label'], $config['class'] );
78
+ }
79
+
80
+ }
81
+
82
+ /**
83
+ * Registers available class
84
+ *
85
+ * @param string $type Object type.
86
+ * @param string $label Object nice name to show in admin area.
87
+ * @param string $class Object class name.
88
+ * @return WP_Error|true
89
+ */
90
+ public function register( $type, $label, $class ) {
91
+
92
+ if ( ! class_exists( $class ) ) {
93
+ return new WP_Error( 'invalid_class', sprintf( $this->error_messages['invalid_class'], $class ) );
94
+ }
95
+
96
+ if ( false !== $this->parent_class ) {
97
+ $valid = $this->validate_parent( $class );
98
+
99
+ if ( is_wp_error( $valid ) ) {
100
+ return $valid;
101
+ }
102
+ }
103
+
104
+ if ( false !== $this->interface ) {
105
+ $valid = $this->validate_interface( $class );
106
+
107
+ if ( is_wp_error( $valid ) ) {
108
+ return $valid;
109
+ }
110
+ }
111
+
112
+ $this->available_classes[ $type ] = [
113
+ 'label' => $label,
114
+ 'class' => $class,
115
+ ];
116
+
117
+ return true;
118
+
119
+ }
120
+
121
+ /**
122
+ * Validates class parent
123
+ *
124
+ * @param string $class Class name.
125
+ * @return WP_Error|true
126
+ */
127
+ protected function validate_parent( $class ) {
128
+
129
+ if ( ! empty( $this->parent_class ) && ! is_subclass_of( $class, $this->parent_class ) ) {
130
+ return new WP_Error( 'invalid_class_parent', sprintf( $this->error_messages['invalid_class_parent'], $class, $this->parent_class ) );
131
+ }
132
+
133
+ return true;
134
+
135
+ }
136
+
137
+ /**
138
+ * Validates class interface
139
+ *
140
+ * @param string $class Class name.
141
+ * @return WP_Error|true
142
+ */
143
+ protected function validate_interface( $class ) {
144
+
145
+ if ( ! in_array( $this->interface, class_implements( $class ), true ) ) {
146
+ return new WP_Error( 'invalid_class_interface', sprintf( $this->error_messages['invalid_class_interface'], $class, $this->interface ) );
147
+ }
148
+
149
+ return true;
150
+
151
+ }
152
+
153
+ /**
154
+ * Returns instance of given type
155
+ *
156
+ * @param string $type Object type.
157
+ * @return Object|WP_Error
158
+ */
159
+ public function get_object( $type ) {
160
+
161
+ if ( ! array_key_exists( $type, $this->objects ) ) {
162
+ return $this->create( $type );
163
+ }
164
+
165
+ return $this->objects[ $type ];
166
+
167
+ }
168
+
169
+ /**
170
+ * Returns instance of given type
171
+ *
172
+ * @param string $type Object type.
173
+ * @return Object
174
+ */
175
+ protected function create( $type ) {
176
+
177
+ if ( ! array_key_exists( $type, $this->available_classes ) ) {
178
+ return new WP_Error( 'invalid_type', sprintf( $this->error_messages['invalid_type'], $type ) );
179
+ }
180
+
181
+ $class = $this->available_classes[ $type ]['class'];
182
+
183
+ return new $class();
184
+
185
+ }
186
+
187
+ /**
188
+ * Returns available classes
189
+ *
190
+ * @return array
191
+ */
192
+ public function get_available_objects() {
193
+ return $this->available_classes;
194
+ }
195
+ }
src/classes/Core/Plugin.php CHANGED
@@ -1,230 +1,230 @@
1
- <?php
2
- /**
3
- * Core plugin class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Core;
9
-
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;
17
- use EasyWatermark\Traits\Hookable;
18
- use EasyWatermark\Watermark\Handler;
19
- use EasyWatermark\Watermark\Preview;
20
- use EasyWatermark\Watermark\Watermark;
21
- use EasyWatermark\Watermark\PostType as WatermarkPostType;
22
- use Micropackage\Singleton\Singleton;
23
-
24
- /**
25
- * Main plugin class
26
- */
27
- class Plugin extends Singleton {
28
-
29
- use Hookable;
30
-
31
- /**
32
- * Plugin name
33
- *
34
- * @var string
35
- */
36
- private $name = null;
37
-
38
- /**
39
- * Plugin slug
40
- *
41
- * @var string
42
- */
43
- private $slug = null;
44
-
45
- /**
46
- * Plugin version
47
- *
48
- * @var string
49
- */
50
- private $version = null;
51
-
52
- /**
53
- * Watermark Handler instance
54
- *
55
- * @var Handler
56
- */
57
- private $watermark_handler;
58
-
59
- /**
60
- * Constructor
61
- */
62
- protected function __construct() {
63
-
64
- $data = \get_file_data( EW_FILE_PATH, [
65
- 'name' => 'Plugin Name',
66
- 'version' => 'Version',
67
- ], 'plugin' );
68
-
69
- $this->name = $data['name'];
70
- $this->slug = dirname( plugin_basename( EW_FILE_PATH ) );
71
- $this->version = $data['version'];
72
-
73
- register_activation_hook( EW_FILE_PATH, [ 'EasyWatermark\Core\Installer', 'activate' ] );
74
- register_deactivation_hook( EW_FILE_PATH, [ 'EasyWatermark\Core\Installer', 'deactivate' ] );
75
-
76
- if ( ! ew_dochooks_enabled() ) {
77
- add_action( 'plugins_loaded', [ $this, 'setup' ] );
78
- }
79
-
80
- $this->hook();
81
-
82
- BackupManager::get();
83
-
84
- do_action( 'ew_load', $this );
85
-
86
- }
87
-
88
- /**
89
- * Creates nessesary instances
90
- *
91
- * @action plugins_loaded
92
- *
93
- * @return void
94
- */
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();
109
-
110
- Settings::get();
111
-
112
- $this->setup_metaboxes();
113
-
114
- if ( ! ew_dochooks_enabled() ) {
115
- Hooks::get()->load_hooks();
116
- }
117
-
118
- }
119
-
120
- /**
121
- * Creates metabox objects
122
- *
123
- * @return void
124
- */
125
- private function setup_metaboxes() {
126
-
127
- new Metaboxes\Watermark\Submitdiv();
128
- new Metaboxes\Watermark\WatermarkContent();
129
- new Metaboxes\Watermark\TextOptions();
130
- new Metaboxes\Watermark\Alignment();
131
- new Metaboxes\Watermark\Scaling();
132
- new Metaboxes\Watermark\ApplyingRules();
133
- new Metaboxes\Watermark\Preview();
134
- new Metaboxes\Watermark\Placeholders();
135
-
136
- if ( current_user_can( 'apply_watermark' ) ) {
137
- new Metaboxes\Attachment\Watermarks();
138
- }
139
-
140
- }
141
-
142
- /**
143
- * Initiates plugin
144
- *
145
- * @action init
146
- *
147
- * @return void
148
- */
149
- public function init() {
150
-
151
- add_rewrite_tag( '%easy_watermark_preview%', '([^./-]+)' );
152
- add_rewrite_tag( '%format%', '(jpg|png)' );
153
- add_rewrite_tag( '%watermark_id%', '([0-9]+)' );
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
-
168
- $last_version = get_option( $this->slug . '-version' );
169
- if ( $this->version !== $last_version ) {
170
- // Version has changed. Update.
171
- $settings = Settings::get();
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
-
182
- /**
183
- * Returns plugin name
184
- *
185
- * @return string
186
- */
187
- public function get_name() {
188
- return $this->name;
189
- }
190
-
191
- /**
192
- * Returns plugin slug
193
- *
194
- * @return string
195
- */
196
- public function get_slug() {
197
- return $this->slug;
198
- }
199
-
200
- /**
201
- * Returns plugin version
202
- *
203
- * @return string
204
- */
205
- public function get_version() {
206
- return $this->version;
207
- }
208
-
209
- /**
210
- * Returns plugin version
211
- *
212
- * @return string
213
- */
214
- public function get_watermark_handler() {
215
-
216
- if ( ! $this->watermark_handler ) {
217
- $this->watermark_handler = new Handler();
218
- }
219
-
220
- return $this->watermark_handler;
221
-
222
- }
223
-
224
- /**
225
- * Destructor
226
- */
227
- public function __destruct() {
228
- $this->unhook();
229
- }
230
- }
1
+ <?php
2
+ /**
3
+ * Core plugin class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Core;
9
+
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;
17
+ use EasyWatermark\Traits\Hookable;
18
+ use EasyWatermark\Watermark\Handler;
19
+ use EasyWatermark\Watermark\Preview;
20
+ use EasyWatermark\Watermark\Watermark;
21
+ use EasyWatermark\Watermark\PostType as WatermarkPostType;
22
+ use Micropackage\Singleton\Singleton;
23
+
24
+ /**
25
+ * Main plugin class
26
+ */
27
+ class Plugin extends Singleton {
28
+
29
+ use Hookable;
30
+
31
+ /**
32
+ * Plugin name
33
+ *
34
+ * @var string
35
+ */
36
+ private $name = null;
37
+
38
+ /**
39
+ * Plugin slug
40
+ *
41
+ * @var string
42
+ */
43
+ private $slug = null;
44
+
45
+ /**
46
+ * Plugin version
47
+ *
48
+ * @var string
49
+ */
50
+ private $version = null;
51
+
52
+ /**
53
+ * Watermark Handler instance
54
+ *
55
+ * @var Handler
56
+ */
57
+ private $watermark_handler;
58
+
59
+ /**
60
+ * Constructor
61
+ */
62
+ protected function __construct() {
63
+
64
+ $data = \get_file_data( EW_FILE_PATH, [
65
+ 'name' => 'Plugin Name',
66
+ 'version' => 'Version',
67
+ ], 'plugin' );
68
+
69
+ $this->name = $data['name'];
70
+ $this->slug = dirname( plugin_basename( EW_FILE_PATH ) );
71
+ $this->version = $data['version'];
72
+
73
+ register_activation_hook( EW_FILE_PATH, [ 'EasyWatermark\Core\Installer', 'activate' ] );
74
+ register_deactivation_hook( EW_FILE_PATH, [ 'EasyWatermark\Core\Installer', 'deactivate' ] );
75
+
76
+ if ( ! ew_dochooks_enabled() ) {
77
+ add_action( 'plugins_loaded', [ $this, 'setup' ] );
78
+ }
79
+
80
+ $this->hook();
81
+
82
+ BackupManager::get();
83
+
84
+ do_action( 'ew_load', $this );
85
+
86
+ }
87
+
88
+ /**
89
+ * Creates nessesary instances
90
+ *
91
+ * @action plugins_loaded
92
+ *
93
+ * @return void
94
+ */
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();
109
+
110
+ Settings::get();
111
+
112
+ $this->setup_metaboxes();
113
+
114
+ if ( ! ew_dochooks_enabled() ) {
115
+ Hooks::get()->load_hooks();
116
+ }
117
+
118
+ }
119
+
120
+ /**
121
+ * Creates metabox objects
122
+ *
123
+ * @return void
124
+ */
125
+ private function setup_metaboxes() {
126
+
127
+ new Metaboxes\Watermark\Submitdiv();
128
+ new Metaboxes\Watermark\WatermarkContent();
129
+ new Metaboxes\Watermark\TextOptions();
130
+ new Metaboxes\Watermark\Alignment();
131
+ new Metaboxes\Watermark\Scaling();
132
+ new Metaboxes\Watermark\ApplyingRules();
133
+ new Metaboxes\Watermark\Preview();
134
+ new Metaboxes\Watermark\Placeholders();
135
+
136
+ if ( current_user_can( 'apply_watermark' ) ) {
137
+ new Metaboxes\Attachment\Watermarks();
138
+ }
139
+
140
+ }
141
+
142
+ /**
143
+ * Initiates plugin
144
+ *
145
+ * @action init
146
+ *
147
+ * @return void
148
+ */
149
+ public function init() {
150
+
151
+ add_rewrite_tag( '%easy_watermark_preview%', '([^./-]+)' );
152
+ add_rewrite_tag( '%format%', '(jpg|png)' );
153
+ add_rewrite_tag( '%watermark_id%', '([0-9]+)' );
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
+
168
+ $last_version = get_option( $this->slug . '-version' );
169
+ if ( $this->version !== $last_version ) {
170
+ // Version has changed. Update.
171
+ $settings = Settings::get();
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
+
182
+ /**
183
+ * Returns plugin name
184
+ *
185
+ * @return string
186
+ */
187
+ public function get_name() {
188
+ return $this->name;
189
+ }
190
+
191
+ /**
192
+ * Returns plugin slug
193
+ *
194
+ * @return string
195
+ */
196
+ public function get_slug() {
197
+ return $this->slug;
198
+ }
199
+
200
+ /**
201
+ * Returns plugin version
202
+ *
203
+ * @return string
204
+ */
205
+ public function get_version() {
206
+ return $this->version;
207
+ }
208
+
209
+ /**
210
+ * Returns plugin version
211
+ *
212
+ * @return string
213
+ */
214
+ public function get_watermark_handler() {
215
+
216
+ if ( ! $this->watermark_handler ) {
217
+ $this->watermark_handler = new Handler();
218
+ }
219
+
220
+ return $this->watermark_handler;
221
+
222
+ }
223
+
224
+ /**
225
+ * Destructor
226
+ */
227
+ public function __destruct() {
228
+ $this->unhook();
229
+ }
230
+ }
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' ), 'permissions', 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,39 +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
- * 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
- }
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' ), 'settings', 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' ), 'tools', 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' ), 'watermarks', 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 CHANGED
@@ -1,147 +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
- }
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,181 +1,180 @@
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
- }
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
+ public function __construct() {
35
+ $this->hook();
36
+ }
37
+
38
+ /**
39
+ * Registers settings
40
+ *
41
+ * @action easy-watermark/settings/register/general
42
+ *
43
+ * @param Section $section Settings section.
44
+ * @return void
45
+ */
46
+ public function register_settings( $section ) {
47
+
48
+ $label = sprintf(
49
+ '%s <p class="description">%s</p>',
50
+ esc_html__( 'Filter srcset', 'easy-watermark' ),
51
+ esc_html_x( 'for watermarked images', 'Continuation of "Filter srcset" setting label.', 'easy-watermark' )
52
+ );
53
+
54
+ $description = implode( '<br/>', [
55
+ esc_html_x(
56
+ 'Srcset attribute contains information about other image sizes and lets the browser decide which image to display based on the screen size.',
57
+ '"Filter srcset" setting description line 1',
58
+ 'easy-watermark'
59
+ ),
60
+ esc_html_x(
61
+ 'This is good in general but it might cause problems if some watermarks are applied only to certain image sizes.',
62
+ '"Filter srcset" setting description line 2',
63
+ 'easy-watermark'
64
+ ),
65
+ esc_html_x(
66
+ 'With this option enabled srcset attribute will only contain image sizes watermarked the same way.',
67
+ '"Filter srcset" setting description line 3',
68
+ 'easy-watermark'
69
+ ),
70
+ ] );
71
+
72
+ $this->switch = new SwitchField( [
73
+ 'label' => $label,
74
+ 'slug' => 'filter_srcset',
75
+ 'default' => true,
76
+ 'description' => $description,
77
+ ] );
78
+
79
+ $section->add_field( $this->switch );
80
+
81
+ }
82
+
83
+ /**
84
+ * Filters srcset image sizes to use only the ones watermarked the same way
85
+ *
86
+ * @filter wp_calculate_image_srcset_meta 1000
87
+ *
88
+ * @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
89
+ * @param array $size_array Array of width and height values in pixels (in that order).
90
+ * @param string $image_src The 'src' of the image.
91
+ * @param int $attachment_id The image attachment ID or 0 if not supplied.
92
+ * @return array
93
+ */
94
+ public function wp_calculate_image_srcset_meta( $image_meta, $size_array, $image_src, $attachment_id ) {
95
+
96
+ if ( ! $this->switch ) {
97
+ // Don't do anything if settings have not been loaded yet.
98
+ return $image_meta;
99
+ }
100
+
101
+ if ( true === $this->switch->get_value() && isset( $image_meta['sizes'] ) && is_array( $image_meta['sizes'] ) ) {
102
+ $applied_watermarks = get_post_meta( $attachment_id, '_ew_applied_watermarks', true );
103
+
104
+ if ( is_array( $applied_watermarks ) ) {
105
+ $current_size = $this->get_current_size( $image_src, $image_meta );
106
+ $allowed_sizes = $this->get_allowed_sizes( $applied_watermarks, $current_size );
107
+
108
+ $image_meta['sizes'] = array_filter( $image_meta['sizes'], function( $key ) use ( $allowed_sizes ) {
109
+ return in_array( $key, $allowed_sizes, true );
110
+ }, ARRAY_FILTER_USE_KEY );
111
+ }
112
+ }
113
+
114
+ return $image_meta;
115
+
116
+ }
117
+
118
+ /**
119
+ * Gets image size for the image src
120
+ *
121
+ * @param string $image_src The 'src' of the image.
122
+ * @param array $meta Image meta.
123
+ * @return string|false
124
+ */
125
+ private function get_current_size( $image_src, $meta ) {
126
+
127
+ $image_src = basename( $image_src );
128
+ $pos = strpos( $image_src, '?v=' );
129
+
130
+ if ( $pos ) {
131
+ $image_src = substr( $image_src, 0, $pos );
132
+ }
133
+
134
+ if ( false !== strpos( $meta['file'], $image_src ) ) {
135
+ return 'full';
136
+ }
137
+
138
+ foreach ( $meta['sizes'] as $size => $params ) {
139
+ if ( $image_src === $params['file'] ) {
140
+ return $size;
141
+ }
142
+ }
143
+
144
+ return false;
145
+
146
+ }
147
+
148
+ /**
149
+ * Filters image sizes
150
+ *
151
+ * @param array $watermarks Applied watermarks.
152
+ * @param string $current_size Currently displayed image size.
153
+ * @return array
154
+ */
155
+ private function get_allowed_sizes( $watermarks, $current_size ) {
156
+
157
+ $sizes = get_intermediate_image_sizes();
158
+
159
+ foreach ( $watermarks as $watermark_id ) {
160
+ $watermark = Watermark::get( $watermark_id );
161
+
162
+ if ( ! $watermark ) {
163
+ continue;
164
+ }
165
+
166
+ $should_be = in_array( $current_size, $watermark->image_sizes, true );
167
+
168
+ foreach ( $sizes as $key => $size ) {
169
+ $is = in_array( $size, $watermark->image_sizes, true );
170
+
171
+ if ( ! ( $is * $should_be ) && ( $is || $should_be ) ) {
172
+ unset( $sizes[ $key ] );
173
+ }
174
+ }
175
+ }
176
+
177
+ return $sizes;
178
+
179
+ }
180
+ }
 
src/classes/Features/WatermarkPreview.php CHANGED
@@ -1,152 +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
- }
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', [
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,154 +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\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
- }
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/Placeholders/Resolver.php CHANGED
@@ -1,154 +1,154 @@
1
- <?php
2
- /**
3
- * Resolver class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Placeholders;
9
-
10
- use EasyWatermark\Placeholders\Abstracts\Placeholder;
11
- use Micropackage\Singleton\Singleton;
12
- use WP_Error;
13
-
14
- /**
15
- * Resolver class
16
- */
17
- class Resolver extends Singleton {
18
-
19
- /**
20
- * Placeholder instances
21
- *
22
- * @var array
23
- */
24
- protected $placeholders = [];
25
-
26
- /**
27
- * Regex pattern for placeholders
28
- *
29
- * @var string
30
- */
31
- private $placeholder_pattern = '/\%([^\%]*)\%/';
32
-
33
- /**
34
- * Attachment being processed
35
- *
36
- * @var array
37
- */
38
- protected $attachment;
39
-
40
- /**
41
- * Constructor
42
- *
43
- * @return void
44
- */
45
- public function __construct() {
46
-
47
- $this->load_placeholders();
48
-
49
- }
50
-
51
- /**
52
- * Loads placeholders
53
- *
54
- * @return void
55
- */
56
- public function load_placeholders() {
57
- do_action( 'easy-watermark/placeholders/load', $this );
58
- }
59
-
60
- /**
61
- * Adds single placeholder instance
62
- *
63
- * @param Placeholder $placeholder Placeholder instance.
64
- * @return WP_Error|true
65
- */
66
- public function add_placeholder( $placeholder ) {
67
-
68
- if ( ! $placeholder instanceof Placeholder ) {
69
- return new WP_Error( __( 'Placeholder must be an instance of abstract Placeholder class.', 'easy-watermark' ) );
70
- }
71
-
72
- $this->placeholders[ $placeholder->get_slug() ] = $placeholder;
73
-
74
- }
75
-
76
- /**
77
- * Returns array of registered placeholders
78
- *
79
- * @return array
80
- */
81
- public function get_placeholders() {
82
- return $this->placeholders;
83
- }
84
-
85
- /**
86
- * Resolves placeholders for given value
87
- *
88
- * @param string $value Value to resolve.
89
- * @return string
90
- */
91
- public function resolve( $value ) {
92
-
93
- $value = apply_filters( 'easy-watermark/placeholders/resolving', $value, $this );
94
-
95
- $resolved = preg_replace_callback( $this->placeholder_pattern, array( $this, 'resolve_match' ), $value );
96
-
97
- $resolved = apply_filters( 'easy-watermark/placeholders/resolved', $resolved, $this );
98
-
99
- return $resolved;
100
-
101
- }
102
-
103
- /**
104
- * Resolves placeholder with a real value
105
- *
106
- * @param array $matches Matches from preg_replace.
107
- * @return string
108
- */
109
- public function resolve_match( $matches ) {
110
-
111
- $placeholder_slug = $matches[1];
112
-
113
- if ( ! isset( $this->placeholders[ $placeholder_slug ] ) ) {
114
- return $matches[0];
115
- }
116
-
117
- $resolved = apply_filters( 'easy-watermark/placeholder/resolved', $this->placeholders[ $placeholder_slug ]->get_value( $this ), $this->placeholders[ $placeholder_slug ] );
118
-
119
- return $resolved;
120
-
121
- }
122
-
123
- /**
124
- * Sets attachment data
125
- *
126
- * @param array $attachment Attachment data.
127
- * @return void
128
- */
129
- public function set_attachment( $attachment ) {
130
- $this->attachment = $attachment;
131
- }
132
-
133
- /**
134
- * Gets attachment data
135
- *
136
- * @return array
137
- */
138
- public function get_attachment() {
139
- return $this->attachment;
140
- }
141
-
142
- /**
143
- * Resets resolved placeholders
144
- *
145
- * @return void
146
- */
147
- public function reset() {
148
-
149
- foreach ( $this->placeholders as $placeholder ) {
150
- $placeholder->reset();
151
- }
152
-
153
- }
154
- }
1
+ <?php
2
+ /**
3
+ * Resolver class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Placeholders;
9
+
10
+ use EasyWatermark\Placeholders\Abstracts\Placeholder;
11
+ use Micropackage\Singleton\Singleton;
12
+ use WP_Error;
13
+
14
+ /**
15
+ * Resolver class
16
+ */
17
+ class Resolver extends Singleton {
18
+
19
+ /**
20
+ * Placeholder instances
21
+ *
22
+ * @var array
23
+ */
24
+ protected $placeholders = [];
25
+
26
+ /**
27
+ * Regex pattern for placeholders
28
+ *
29
+ * @var string
30
+ */
31
+ private $placeholder_pattern = '/\%([^\%]*)\%/';
32
+
33
+ /**
34
+ * Attachment being processed
35
+ *
36
+ * @var array
37
+ */
38
+ protected $attachment;
39
+
40
+ /**
41
+ * Constructor
42
+ *
43
+ * @return void
44
+ */
45
+ public function __construct() {
46
+
47
+ $this->load_placeholders();
48
+
49
+ }
50
+
51
+ /**
52
+ * Loads placeholders
53
+ *
54
+ * @return void
55
+ */
56
+ public function load_placeholders() {
57
+ do_action( 'easy-watermark/placeholders/load', $this );
58
+ }
59
+
60
+ /**
61
+ * Adds single placeholder instance
62
+ *
63
+ * @param Placeholder $placeholder Placeholder instance.
64
+ * @return WP_Error|true
65
+ */
66
+ public function add_placeholder( $placeholder ) {
67
+
68
+ if ( ! $placeholder instanceof Placeholder ) {
69
+ return new WP_Error( __( 'Placeholder must be an instance of abstract Placeholder class.', 'easy-watermark' ) );
70
+ }
71
+
72
+ $this->placeholders[ $placeholder->get_slug() ] = $placeholder;
73
+
74
+ }
75
+
76
+ /**
77
+ * Returns array of registered placeholders
78
+ *
79
+ * @return array
80
+ */
81
+ public function get_placeholders() {
82
+ return $this->placeholders;
83
+ }
84
+
85
+ /**
86
+ * Resolves placeholders for given value
87
+ *
88
+ * @param string $value Value to resolve.
89
+ * @return string
90
+ */
91
+ public function resolve( $value ) {
92
+
93
+ $value = apply_filters( 'easy-watermark/placeholders/resolving', $value, $this );
94
+
95
+ $resolved = preg_replace_callback( $this->placeholder_pattern, [ $this, 'resolve_match' ], $value );
96
+
97
+ $resolved = apply_filters( 'easy-watermark/placeholders/resolved', $resolved, $this );
98
+
99
+ return $resolved;
100
+
101
+ }
102
+
103
+ /**
104
+ * Resolves placeholder with a real value
105
+ *
106
+ * @param array $matches Matches from preg_replace.
107
+ * @return string
108
+ */
109
+ public function resolve_match( $matches ) {
110
+
111
+ $placeholder_slug = $matches[1];
112
+
113
+ if ( ! isset( $this->placeholders[ $placeholder_slug ] ) ) {
114
+ return $matches[0];
115
+ }
116
+
117
+ $resolved = apply_filters( 'easy-watermark/placeholder/resolved', $this->placeholders[ $placeholder_slug ]->get_value( $this ), $this->placeholders[ $placeholder_slug ] );
118
+
119
+ return $resolved;
120
+
121
+ }
122
+
123
+ /**
124
+ * Sets attachment data
125
+ *
126
+ * @param array $attachment Attachment data.
127
+ * @return void
128
+ */
129
+ public function set_attachment( $attachment ) {
130
+ $this->attachment = $attachment;
131
+ }
132
+
133
+ /**
134
+ * Gets attachment data
135
+ *
136
+ * @return array
137
+ */
138
+ public function get_attachment() {
139
+ return $this->attachment;
140
+ }
141
+
142
+ /**
143
+ * Resets resolved placeholders
144
+ *
145
+ * @return void
146
+ */
147
+ public function reset() {
148
+
149
+ foreach ( $this->placeholders as $placeholder ) {
150
+ $placeholder->reset();
151
+ }
152
+
153
+ }
154
+ }
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/Checkbox.php CHANGED
@@ -42,6 +42,6 @@ class Checkbox extends Field {
42
  * @return mixed
43
  */
44
  public function sanitize( $value ) {
45
- return ( '1' === $value );
46
  }
47
  }
42
  * @return mixed
43
  */
44
  public function sanitize( $value ) {
45
+ return boolval( $value );
46
  }
47
  }
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/Settings/Settings.php CHANGED
@@ -1,245 +1,245 @@
1
- <?php
2
- /**
3
- * Settings class
4
- *
5
- * @package easy-watermark
6
- */
7
-
8
- namespace EasyWatermark\Settings;
9
-
10
- use EasyWatermark\Backup\Manager as BackupManager;
11
- use EasyWatermark\Core\Plugin;
12
- use EasyWatermark\Core\View;
13
- use EasyWatermark\Traits\Hookable;
14
- use Micropackage\Singleton\Singleton;
15
-
16
- /**
17
- * Settings class
18
- */
19
- class Settings extends Singleton {
20
-
21
- use Hookable;
22
-
23
- /**
24
- * Settings
25
- *
26
- * @var array
27
- */
28
- private $settings;
29
-
30
- /**
31
- * Option key
32
- *
33
- * @var string
34
- */
35
- private $option_key;
36
-
37
- /**
38
- * Sections collection
39
- *
40
- * @var array
41
- */
42
- protected $sections = [];
43
-
44
- /**
45
- * Constructor
46
- */
47
- protected function __construct() {
48
- $this->hook();
49
- $this->register_sections();
50
- $this->load_settings();
51
- }
52
-
53
- /**
54
- * Gets option key
55
- *
56
- * @return void
57
- */
58
- public function register_sections() {
59
- $this->add_section( new Section( __( 'General', 'easy-watermark' ), 'general' ) );
60
- do_action( 'easy-watermark/settings/register', $this );
61
- }
62
-
63
- /**
64
- * Loads settings
65
- *
66
- * @return void
67
- */
68
- public function load_settings() {
69
-
70
- if ( null === $this->settings ) {
71
- $settings_raw = get_option( $this->get_option_key() );
72
- $settings = [];
73
-
74
- foreach ( $this->get_sections() as $section_slug => $section ) {
75
- foreach ( $section->get_fields() as $field_slug => $field ) {
76
- if ( isset( $settings_raw[ $section_slug ][ $field_slug ] ) ) {
77
- $field->set_value( $settings_raw[ $section_slug ][ $field_slug ] );
78
- }
79
-
80
- $settings[ $section_slug ][ $field_slug ] = $field->get_value();
81
- }
82
- }
83
-
84
- $this->settings = $settings;
85
- }
86
-
87
- }
88
-
89
- /**
90
- * Registers settings
91
- *
92
- * @action easy-watermark/settings/register/general 5
93
- *
94
- * @param Section $section Settings section.
95
- * @return void
96
- */
97
- public function register_fields( $section ) {
98
-
99
- $section->add_field( new Fields\Number( [
100
- 'label' => __( 'Jpeg Quality', 'easy-watermark' ),
101
- 'slug' => 'jpeg_quality',
102
- 'description' => __( 'Set jpeg quality from 0 (worst quality, smaller file) to 100 (best quality, biggest file). Set -1 for default quality.', 'easy-watermark' ),
103
- 'default' => -1,
104
- 'min' => -1,
105
- 'max' => 100,
106
- 'step' => 1,
107
- ] ) );
108
-
109
- }
110
-
111
- /**
112
- * Gets option key
113
- *
114
- * @return string
115
- */
116
- public function get_option_key() {
117
- if ( ! $this->option_key ) {
118
- $this->option_key = Plugin::get()->get_slug() . '-settings';
119
- }
120
-
121
- return $this->option_key;
122
- }
123
-
124
- /**
125
- * Adds section
126
- *
127
- * @param Section $section Section instance.
128
- * @throws \Exception If section is not instance of Section class.
129
- * @return void
130
- */
131
- public function add_section( $section ) {
132
- if ( ! $section instanceof Section ) {
133
- /* translators: section variable type */
134
- throw new \Exception( sprintf( __( 'Section must be an instance of EasyWatermark\\Settings\\Section. %s given', 'easy-watermark' ), gettype( $section ) ) );
135
- }
136
-
137
- $section->set_settings( $this );
138
- $this->sections[ $section->get_slug() ] = $section;
139
- }
140
-
141
- /**
142
- * Gets section object
143
- *
144
- * @param string $slug Section slug.
145
- * @return Section|false
146
- */
147
- public function get_section( $slug ) {
148
- return isset( $this->sections[ $slug ] ) ? $this->sections[ $slug ] : false;
149
- }
150
-
151
- /**
152
- * Gets array of sections
153
- *
154
- * @return array
155
- */
156
- public function get_sections() {
157
- return $this->sections;
158
- }
159
-
160
- /**
161
- * Registers settings
162
- *
163
- * @action admin_init
164
- *
165
- * @return void
166
- */
167
- public function register_settings() {
168
-
169
- register_setting(
170
- $this->option_key,
171
- $this->option_key,
172
- [ $this, 'sanitize_settings' ]
173
- );
174
-
175
- }
176
-
177
- /**
178
- * Sanitizes settings
179
- *
180
- * @param array $settings Settings array.
181
- * @return array
182
- */
183
- public function sanitize_settings( $settings ) {
184
-
185
- $sanitized = [];
186
-
187
- foreach ( $this->get_sections() as $section_slug => $section ) {
188
- foreach ( $section->get_fields() as $field_slug => $field ) {
189
- $value = isset( $settings[ $section_slug ][ $field_slug ] ) ? $settings[ $section_slug ][ $field_slug ] : null;
190
-
191
- $sanitized[ $section_slug ][ $field_slug ] = $field->sanitize( $value );
192
- }
193
- }
194
-
195
- return $sanitized;
196
-
197
- }
198
-
199
- /**
200
- * Returns settings array
201
- *
202
- * @return array
203
- */
204
- public function get_settings() {
205
- return $this->settings;
206
- }
207
-
208
- /**
209
- * Creates settings link on plugins list
210
- *
211
- * @filter plugin_action_links_easy-watermark/easy-watermark.php
212
- *
213
- * @param array $links Action links.
214
- * @param string $file Plugin file.
215
- * @return array
216
- */
217
- public function plugin_action_links( $links, $file ) {
218
-
219
- return array_merge( [
220
- '<a href="tools.php?page=easy-watermark&tab=settings">' . __( 'Settings' ) . '</a>',
221
- ], $links );
222
-
223
- }
224
-
225
- /**
226
- * Gets setting value
227
- *
228
- * @param string $key Settings key.
229
- * @return mixed
230
- */
231
- public function get_setting( $key ) {
232
-
233
- $parts = explode( '/', $key );
234
-
235
- if ( 2 === count( $parts ) ) {
236
- $section = $parts[0];
237
- $field = $parts[1];
238
-
239
- if ( isset( $this->settings[ $section ][ $field ] ) ) {
240
- return $this->settings[ $section ][ $field ];
241
- }
242
- }
243
-
244
- }
245
- }
1
+ <?php
2
+ /**
3
+ * Settings class
4
+ *
5
+ * @package easy-watermark
6
+ */
7
+
8
+ namespace EasyWatermark\Settings;
9
+
10
+ use EasyWatermark\Backup\Manager as BackupManager;
11
+ use EasyWatermark\Core\Plugin;
12
+ use EasyWatermark\Core\View;
13
+ use EasyWatermark\Traits\Hookable;
14
+ use Micropackage\Singleton\Singleton;
15
+
16
+ /**
17
+ * Settings class
18
+ */
19
+ class Settings extends Singleton {
20
+
21
+ use Hookable;
22
+
23
+ /**
24
+ * Settings
25
+ *
26
+ * @var array
27
+ */
28
+ private $settings;
29
+
30
+ /**
31
+ * Option key
32
+ *
33
+ * @var string
34
+ */
35
+ private $option_key;
36
+
37
+ /**
38
+ * Sections collection
39
+ *
40
+ * @var array
41
+ */
42
+ protected $sections = [];
43
+
44
+ /**
45
+ * Constructor
46
+ */
47
+ protected function __construct() {
48
+ $this->hook();
49
+ $this->register_sections();
50
+ $this->load_settings();
51
+ }
52
+
53
+ /**
54
+ * Gets option key
55
+ *
56
+ * @return void
57
+ */
58
+ public function register_sections() {
59
+ $this->add_section( new Section( __( 'General', 'easy-watermark' ), 'general' ) );
60
+ do_action( 'easy-watermark/settings/register', $this );
61
+ }
62
+
63
+ /**
64
+ * Loads settings
65
+ *
66
+ * @return void
67
+ */
68
+ public function load_settings() {
69
+
70
+ if ( null === $this->settings ) {
71
+ $settings_raw = get_option( $this->get_option_key() );
72
+ $settings = [];
73
+
74
+ foreach ( $this->get_sections() as $section_slug => $section ) {
75
+ foreach ( $section->get_fields() as $field_slug => $field ) {
76
+ if ( isset( $settings_raw[ $section_slug ][ $field_slug ] ) ) {
77
+ $field->set_value( $settings_raw[ $section_slug ][ $field_slug ] );
78
+ }
79
+
80
+ $settings[ $section_slug ][ $field_slug ] = $field->get_value();
81
+ }
82
+ }
83
+
84
+ $this->settings = $settings;
85
+ }
86
+
87
+ }
88
+
89
+ /**
90
+ * Registers settings
91
+ *
92
+ * @action easy-watermark/settings/register/general 5
93
+ *
94
+ * @param Section $section Settings section.
95
+ * @return void
96
+ */
97
+ public function register_fields( $section ) {
98
+
99
+ $section->add_field( new Fields\Number( [
100
+ 'label' => __( 'Jpeg Quality', 'easy-watermark' ),
101
+ 'slug' => 'jpeg_quality',
102
+ 'description' => __( 'Set jpeg quality from 0 (worst quality, smaller file) to 100 (best quality, biggest file). Set -1 for default quality.', 'easy-watermark' ),
103
+ 'default' => -1,
104
+ 'min' => -1,
105
+ 'max' => 100,
106
+ 'step' => 1,
107
+ ] ) );
108
+
109
+ }
110
+
111
+ /**
112
+ * Gets option key
113
+ *
114
+ * @return string
115
+ */
116
+ public function get_option_key() {
117
+ if ( ! $this->option_key ) {
118
+ $this->option_key = Plugin::get()->get_slug() . '-settings';
119
+ }
120
+
121
+ return $this->option_key;
122
+ }
123
+
124
+ /**
125
+ * Adds section
126
+ *
127
+ * @param Section $section Section instance.
128
+ * @throws \Exception If section is not instance of Section class.
129
+ * @return void
130
+ */
131
+ public function add_section( $section ) {
132
+ if ( ! $section instanceof Section ) {
133
+ /* translators: section variable type */
134
+ throw new \Exception( sprintf( __( 'Section must be an instance of EasyWatermark\\Settings\\Section. %s given', 'easy-watermark' ), gettype( $section ) ) );
135
+ }
136
+
137
+ $section->set_settings( $this );
138
+ $this->sections[ $section->get_slug() ] = $section;
139
+ }
140
+
141
+ /**
142
+ * Gets section object
143
+ *
144
+ * @param string $slug Section slug.
145
+ * @return Section|false
146
+ */
147
+ public function get_section( $slug ) {
148
+ return isset( $this->sections[ $slug ] ) ? $this->sections[ $slug ] : false;
149
+ }
150
+
151
+ /**
152
+ * Gets array of sections
153
+ *
154
+ * @return array
155
+ */
156
+ public function get_sections() {
157
+ return $this->sections;
158
+ }
159
+
160
+ /**
161
+ * Registers settings
162
+ *
163
+ * @action admin_init
164
+ *
165
+ * @return void
166
+ */
167
+ public function register_settings() {
168
+
169
+ register_setting(
170
+ $this->option_key,
171
+ $this->option_key,
172
+ [ $this, 'sanitize_settings' ]
173
+ );
174
+
175
+ }
176
+
177
+ /**
178
+ * Sanitizes settings
179
+ *
180
+ * @param array $settings Settings array.
181
+ * @return array
182
+ */
183
+ public function sanitize_settings( $settings ) {
184
+
185
+ $sanitized = [];
186
+
187
+ foreach ( $this->get_sections() as $section_slug => $section ) {
188
+ foreach ( $section->get_fields() as $field_slug => $field ) {
189
+ $value = isset( $settings[ $section_slug ][ $field_slug ] ) ? $settings[ $section_slug ][ $field_slug ] : null;
190
+
191
+ $sanitized[ $section_slug ][ $field_slug ] = $field->sanitize( $value );
192
+ }
193
+ }
194
+
195
+ return $sanitized;
196
+
197
+ }
198
+
199
+ /**
200
+ * Returns settings array
201
+ *
202
+ * @return array
203
+ */
204
+ public function get_settings() {
205
+ return $this->settings;
206
+ }
207
+
208
+ /**
209
+ * Creates settings link on plugins list
210
+ *
211
+ * @filter plugin_action_links_easy-watermark/easy-watermark.php
212
+ *
213
+ * @param array $links Action links.
214
+ * @param string $file Plugin file.
215
+ * @return array
216
+ */
217
+ public function plugin_action_links( $links, $file ) {
218
+
219
+ return array_merge( [
220
+ '<a href="tools.php?page=easy-watermark&tab=settings">' . __( 'Settings' ) . '</a>',
221
+ ], $links );
222
+
223
+ }
224
+
225
+ /**
226
+ * Gets setting value
227
+ *
228
+ * @param string $key Settings key.
229
+ * @return mixed
230
+ */
231
+ public function get_setting( $key ) {
232
+
233
+ $parts = explode( '/', $key );
234
+
235
+ if ( 2 === count( $parts ) ) {
236
+ $section = $parts[0];
237
+ $field = $parts[1];
238
+
239
+ if ( isset( $this->settings[ $section ][ $field ] ) ) {
240
+ return $this->settings[ $section ][ $field ];
241
+ }
242
+ }
243
+
244
+ }
245
+ }
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 = [ $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,503 +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 ( $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
- }
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,160 +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
- * 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
- }
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
@@ -1,90 +1,90 @@
1
- <?php
2
- /**
3
- * Hooks compatibilty file.
4
- *
5
- * Automatically generated with bin/dump-hooks.php file.
6
- *
7
- * @package easy-watermark
8
- */
9
-
10
- // phpcs:disable
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 );
40
- add_filter( 'post_updated_messages', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'post_updated_messages' ], 10, 1 );
41
- add_filter( 'bulk_post_updated_messages', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'bulk_post_updated_messages' ], 10, 2 );
42
- add_action( 'untrashed_post', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'untrashed_post' ], 10, 1 );
43
- add_action( 'delete_post', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'delete_post' ], 10, 1 );
44
- add_action( 'wp_redirect', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'redirect' ], 10, 1 );
45
- add_action( 'admin_notices', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'admin_notices' ], 10, 0 );
46
- add_filter( 'post_row_actions', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'post_row_actions' ], 10, 2 );
47
- add_filter( 'bulk_actions-edit-watermark', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'bulk_actions' ], 10, 1 );
48
- add_filter( 'screen_options_show_screen', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'screen_options_show_screen' ], 10, 2 );
49
- add_action( 'edit_form_top', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'edit_form_top' ], 10, 1 );
50
- add_action( 'edit_form_after_title', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'edit_form_after_title' ], 10, 1 );
51
- add_filter( 'get_user_option_screen_layout_watermark', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'setup_columns' ], 10, 1 );
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 );
63
- add_action( 'easy-watermark/dashboard/permissions/notices', [ $this->objects['EasyWatermark\Dashboard\Permissions']['instance'], 'admin_notices' ], 10, 0 );
64
- add_filter( 'easy-watermark/dashboard/permissions/view-args', [ $this->objects['EasyWatermark\Dashboard\Permissions']['instance'], 'view_args' ], 10, 1 );
65
- add_filter( 'easy-watermark/dashboard/tabs', [ $this->objects['EasyWatermark\Dashboard\Permissions']['instance'], 'add_tab' ], 10, 1 );
66
- add_action( 'easy-watermark/dashboard/settings/notices', [ $this->objects['EasyWatermark\Dashboard\Tools']['instance'], 'admin_notices' ], 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 );
74
- add_action( 'do_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Submitdiv']['instance'], 'setup' ], 10, 0 );
75
- add_filter( 'hidden_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Submitdiv']['instance'], 'hide' ], 10, 2 );
76
- add_action( 'do_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\WatermarkContent']['instance'], 'setup' ], 10, 0 );
77
- add_filter( 'hidden_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\WatermarkContent']['instance'], 'hide' ], 10, 2 );
78
- add_action( 'do_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\TextOptions']['instance'], 'setup' ], 10, 0 );
79
- add_filter( 'hidden_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\TextOptions']['instance'], 'hide' ], 10, 2 );
80
- add_action( 'do_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Alignment']['instance'], 'setup' ], 10, 0 );
81
- add_filter( 'hidden_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Alignment']['instance'], 'hide' ], 10, 2 );
82
- add_action( 'do_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Scaling']['instance'], 'setup' ], 10, 0 );
83
- add_filter( 'hidden_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Scaling']['instance'], 'hide' ], 10, 2 );
84
- add_action( 'do_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\ApplyingRules']['instance'], 'setup' ], 10, 0 );
85
- add_filter( 'hidden_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\ApplyingRules']['instance'], 'hide' ], 10, 2 );
86
- add_action( 'wp_ajax_easy-watermark/preview_image', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Preview']['instance'], 'ajax_preview_image' ], 10, 0 );
87
- add_action( 'do_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Preview']['instance'], 'setup' ], 10, 0 );
88
- add_filter( 'hidden_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Preview']['instance'], 'hide' ], 10, 2 );
89
- add_action( 'do_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Placeholders']['instance'], 'setup' ], 10, 0 );
90
- add_filter( 'hidden_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Placeholders']['instance'], 'hide' ], 10, 2 );
1
+ <?php
2
+ /**
3
+ * Hooks compatibilty file.
4
+ *
5
+ * Automatically generated with bin/dump-hooks.php file.
6
+ *
7
+ * @package easy-watermark
8
+ */
9
+
10
+ // phpcs:disable
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 );
40
+ add_filter( 'post_updated_messages', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'post_updated_messages' ], 10, 1 );
41
+ add_filter( 'bulk_post_updated_messages', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'bulk_post_updated_messages' ], 10, 2 );
42
+ add_action( 'untrashed_post', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'untrashed_post' ], 10, 1 );
43
+ add_action( 'delete_post', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'delete_post' ], 10, 1 );
44
+ add_action( 'wp_redirect', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'redirect' ], 10, 1 );
45
+ add_action( 'admin_notices', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'admin_notices' ], 10, 0 );
46
+ add_filter( 'post_row_actions', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'post_row_actions' ], 10, 2 );
47
+ add_filter( 'bulk_actions-edit-watermark', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'bulk_actions' ], 10, 1 );
48
+ add_filter( 'screen_options_show_screen', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'screen_options_show_screen' ], 10, 2 );
49
+ add_action( 'edit_form_top', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'edit_form_top' ], 10, 1 );
50
+ add_action( 'edit_form_after_title', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'edit_form_after_title' ], 10, 1 );
51
+ add_filter( 'get_user_option_screen_layout_watermark', [ $this->objects['EasyWatermark\Watermark\PostType']['instance'], 'setup_columns' ], 10, 1 );
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 );
63
+ add_action( 'easy-watermark/dashboard/permissions/notices', [ $this->objects['EasyWatermark\Dashboard\Permissions']['instance'], 'admin_notices' ], 10, 0 );
64
+ add_filter( 'easy-watermark/dashboard/permissions/view-args', [ $this->objects['EasyWatermark\Dashboard\Permissions']['instance'], 'view_args' ], 10, 1 );
65
+ add_filter( 'easy-watermark/dashboard/tabs', [ $this->objects['EasyWatermark\Dashboard\Permissions']['instance'], 'add_tab' ], 10, 1 );
66
+ add_action( 'easy-watermark/dashboard/settings/notices', [ $this->objects['EasyWatermark\Dashboard\Tools']['instance'], 'admin_notices' ], 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 );
74
+ add_action( 'do_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Submitdiv']['instance'], 'setup' ], 10, 0 );
75
+ add_filter( 'hidden_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Submitdiv']['instance'], 'hide' ], 10, 2 );
76
+ add_action( 'do_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\WatermarkContent']['instance'], 'setup' ], 10, 0 );
77
+ add_filter( 'hidden_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\WatermarkContent']['instance'], 'hide' ], 10, 2 );
78
+ add_action( 'do_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\TextOptions']['instance'], 'setup' ], 10, 0 );
79
+ add_filter( 'hidden_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\TextOptions']['instance'], 'hide' ], 10, 2 );
80
+ add_action( 'do_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Alignment']['instance'], 'setup' ], 10, 0 );
81
+ add_filter( 'hidden_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Alignment']['instance'], 'hide' ], 10, 2 );
82
+ add_action( 'do_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Scaling']['instance'], 'setup' ], 10, 0 );
83
+ add_filter( 'hidden_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Scaling']['instance'], 'hide' ], 10, 2 );
84
+ add_action( 'do_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\ApplyingRules']['instance'], 'setup' ], 10, 0 );
85
+ add_filter( 'hidden_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\ApplyingRules']['instance'], 'hide' ], 10, 2 );
86
+ add_action( 'wp_ajax_easy-watermark/preview_image', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Preview']['instance'], 'ajax_preview_image' ], 10, 0 );
87
+ add_action( 'do_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Preview']['instance'], 'setup' ], 10, 0 );
88
+ add_filter( 'hidden_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Preview']['instance'], 'hide' ], 10, 2 );
89
+ add_action( 'do_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Placeholders']['instance'], 'setup' ], 10, 0 );
90
+ add_filter( 'hidden_meta_boxes', [ $this->objects['EasyWatermark\Metaboxes\Watermark\Placeholders']['instance'], 'hide' ], 10, 2 );
src/views/dashboard/pages/tools.php CHANGED
@@ -1,67 +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
- <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>
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,55 +1,55 @@
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>
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,21 +1,21 @@
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>
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,53 +1,53 @@
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>
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 ComposerAutoloaderInit9ea7af8eb9945c998035f76f2b323645::getLoader();
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInita764a2c503e8d5eb9db23821edfa49f4::getLoader();
vendor/composer/ClassLoader.php CHANGED
@@ -42,6 +42,8 @@ namespace Composer\Autoload;
42
  */
43
  class ClassLoader
44
  {
 
 
45
  // PSR-4
46
  private $prefixLengthsPsr4 = array();
47
  private $prefixDirsPsr4 = array();
@@ -57,6 +59,13 @@ class ClassLoader
57
  private $missingClasses = array();
58
  private $apcuPrefix;
59
 
 
 
 
 
 
 
 
60
  public function getPrefixes()
61
  {
62
  if (!empty($this->prefixesPsr0)) {
@@ -300,6 +309,15 @@ class ClassLoader
300
  public function register($prepend = false)
301
  {
302
  spl_autoload_register(array($this, 'loadClass'), true, $prepend);
 
 
 
 
 
 
 
 
 
303
  }
304
 
305
  /**
@@ -308,6 +326,10 @@ class ClassLoader
308
  public function unregister()
309
  {
310
  spl_autoload_unregister(array($this, 'loadClass'));
 
 
 
 
311
  }
312
 
313
  /**
@@ -367,6 +389,16 @@ class ClassLoader
367
  return $file;
368
  }
369
 
 
 
 
 
 
 
 
 
 
 
370
  private function findFileWithExtension($class, $ext)
371
  {
372
  // PSR-4 lookup
42
  */
43
  class ClassLoader
44
  {
45
+ private $vendorDir;
46
+
47
  // PSR-4
48
  private $prefixLengthsPsr4 = array();
49
  private $prefixDirsPsr4 = array();
59
  private $missingClasses = array();
60
  private $apcuPrefix;
61
 
62
+ private static $registeredLoaders = array();
63
+
64
+ public function __construct($vendorDir = null)
65
+ {
66
+ $this->vendorDir = $vendorDir;
67
+ }
68
+
69
  public function getPrefixes()
70
  {
71
  if (!empty($this->prefixesPsr0)) {
309
  public function register($prepend = false)
310
  {
311
  spl_autoload_register(array($this, 'loadClass'), true, $prepend);
312
+
313
+ if (null === $this->vendorDir) {
314
+ //no-op
315
+ } elseif ($prepend) {
316
+ self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
317
+ } else {
318
+ unset(self::$registeredLoaders[$this->vendorDir]);
319
+ self::$registeredLoaders[$this->vendorDir] = $this;
320
+ }
321
  }
322
 
323
  /**
326
  public function unregister()
327
  {
328
  spl_autoload_unregister(array($this, 'loadClass'));
329
+
330
+ if (null !== $this->vendorDir) {
331
+ unset(self::$registeredLoaders[$this->vendorDir]);
332
+ }
333
  }
334
 
335
  /**
389
  return $file;
390
  }
391
 
392
+ /**
393
+ * Returns the currently registered loaders indexed by their corresponding vendor directories.
394
+ *
395
+ * @return self[]
396
+ */
397
+ public static function getRegisteredLoaders()
398
+ {
399
+ return self::$registeredLoaders;
400
+ }
401
+
402
  private function findFileWithExtension($class, $ext)
403
  {
404
  // PSR-4 lookup
vendor/composer/InstalledVersions.php CHANGED
@@ -1,7 +1,18 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
 
3
  namespace Composer;
4
 
 
5
  use Composer\Semver\VersionParser;
6
 
7
 
@@ -14,12 +25,12 @@ class InstalledVersions
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,12 +62,12 @@ private static $installed = array (
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 (
@@ -69,6 +80,8 @@ private static $installed = array (
69
  ),
70
  ),
71
  );
 
 
72
 
73
 
74
 
@@ -78,7 +91,17 @@ private static $installed = array (
78
 
79
  public static function getInstalledPackages()
80
  {
81
- return array_keys(self::$installed['versions']);
 
 
 
 
 
 
 
 
 
 
82
  }
83
 
84
 
@@ -91,7 +114,13 @@ return array_keys(self::$installed['versions']);
91
 
92
  public static function isInstalled($packageName)
93
  {
94
- return isset(self::$installed['versions'][$packageName]);
 
 
 
 
 
 
95
  }
96
 
97
 
@@ -126,42 +155,50 @@ return $provided->matches($constraint);
126
 
127
  public static function getVersionRanges($packageName)
128
  {
129
- if (!isset(self::$installed['versions'][$packageName])) {
130
- throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
 
131
  }
132
 
133
  $ranges = array();
134
- if (isset(self::$installed['versions'][$packageName]['pretty_version'])) {
135
- $ranges[] = self::$installed['versions'][$packageName]['pretty_version'];
136
  }
137
- if (array_key_exists('aliases', self::$installed['versions'][$packageName])) {
138
- $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['aliases']);
139
  }
140
- if (array_key_exists('replaced', self::$installed['versions'][$packageName])) {
141
- $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['replaced']);
142
  }
143
- if (array_key_exists('provided', self::$installed['versions'][$packageName])) {
144
- $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['provided']);
145
  }
146
 
147
  return implode(' || ', $ranges);
148
  }
149
 
 
 
 
150
 
151
 
152
 
153
 
154
  public static function getVersion($packageName)
155
  {
156
- if (!isset(self::$installed['versions'][$packageName])) {
157
- throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
 
158
  }
159
 
160
- if (!isset(self::$installed['versions'][$packageName]['version'])) {
161
  return null;
162
  }
163
 
164
- return self::$installed['versions'][$packageName]['version'];
 
 
 
165
  }
166
 
167
 
@@ -170,15 +207,19 @@ return self::$installed['versions'][$packageName]['version'];
170
 
171
  public static function getPrettyVersion($packageName)
172
  {
173
- if (!isset(self::$installed['versions'][$packageName])) {
174
- throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
 
175
  }
176
 
177
- if (!isset(self::$installed['versions'][$packageName]['pretty_version'])) {
178
  return null;
179
  }
180
 
181
- return self::$installed['versions'][$packageName]['pretty_version'];
 
 
 
182
  }
183
 
184
 
@@ -187,15 +228,19 @@ return self::$installed['versions'][$packageName]['pretty_version'];
187
 
188
  public static function getReference($packageName)
189
  {
190
- if (!isset(self::$installed['versions'][$packageName])) {
191
- throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
 
192
  }
193
 
194
- if (!isset(self::$installed['versions'][$packageName]['reference'])) {
195
  return null;
196
  }
197
 
198
- return self::$installed['versions'][$packageName]['reference'];
 
 
 
199
  }
200
 
201
 
@@ -204,7 +249,9 @@ return self::$installed['versions'][$packageName]['reference'];
204
 
205
  public static function getRootPackage()
206
  {
207
- return self::$installed['root'];
 
 
208
  }
209
 
210
 
@@ -239,5 +286,33 @@ return self::$installed;
239
  public static function reload($data)
240
  {
241
  self::$installed = $data;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  }
243
  }
1
  <?php
2
 
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
  namespace Composer;
14
 
15
+ use Composer\Autoload\ClassLoader;
16
  use Composer\Semver\VersionParser;
17
 
18
 
25
  private static $installed = array (
26
  'root' =>
27
  array (
28
+ 'pretty_version' => '1.0.9',
29
+ 'version' => '1.0.9.0',
30
  'aliases' =>
31
  array (
32
  ),
33
+ 'reference' => 'ccb4690711f71cde94e238b3f5631a8ed958dbe8',
34
  'name' => 'szaleq/easy-watermark',
35
  ),
36
  'versions' =>
62
  ),
63
  'szaleq/easy-watermark' =>
64
  array (
65
+ 'pretty_version' => '1.0.9',
66
+ 'version' => '1.0.9.0',
67
  'aliases' =>
68
  array (
69
  ),
70
+ 'reference' => 'ccb4690711f71cde94e238b3f5631a8ed958dbe8',
71
  ),
72
  'underdev/requirements' =>
73
  array (
80
  ),
81
  ),
82
  );
83
+ private static $canGetVendors;
84
+ private static $installedByVendor = array();
85
 
86
 
87
 
91
 
92
  public static function getInstalledPackages()
93
  {
94
+ $packages = array();
95
+ foreach (self::getInstalled() as $installed) {
96
+ $packages[] = array_keys($installed['versions']);
97
+ }
98
+
99
+
100
+ if (1 === \count($packages)) {
101
+ return $packages[0];
102
+ }
103
+
104
+ return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
105
  }
106
 
107
 
114
 
115
  public static function isInstalled($packageName)
116
  {
117
+ foreach (self::getInstalled() as $installed) {
118
+ if (isset($installed['versions'][$packageName])) {
119
+ return true;
120
+ }
121
+ }
122
+
123
+ return false;
124
  }
125
 
126
 
155
 
156
  public static function getVersionRanges($packageName)
157
  {
158
+ foreach (self::getInstalled() as $installed) {
159
+ if (!isset($installed['versions'][$packageName])) {
160
+ continue;
161
  }
162
 
163
  $ranges = array();
164
+ if (isset($installed['versions'][$packageName]['pretty_version'])) {
165
+ $ranges[] = $installed['versions'][$packageName]['pretty_version'];
166
  }
167
+ if (array_key_exists('aliases', $installed['versions'][$packageName])) {
168
+ $ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
169
  }
170
+ if (array_key_exists('replaced', $installed['versions'][$packageName])) {
171
+ $ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
172
  }
173
+ if (array_key_exists('provided', $installed['versions'][$packageName])) {
174
+ $ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
175
  }
176
 
177
  return implode(' || ', $ranges);
178
  }
179
 
180
+ throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
181
+ }
182
+
183
 
184
 
185
 
186
 
187
  public static function getVersion($packageName)
188
  {
189
+ foreach (self::getInstalled() as $installed) {
190
+ if (!isset($installed['versions'][$packageName])) {
191
+ continue;
192
  }
193
 
194
+ if (!isset($installed['versions'][$packageName]['version'])) {
195
  return null;
196
  }
197
 
198
+ return $installed['versions'][$packageName]['version'];
199
+ }
200
+
201
+ throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
202
  }
203
 
204
 
207
 
208
  public static function getPrettyVersion($packageName)
209
  {
210
+ foreach (self::getInstalled() as $installed) {
211
+ if (!isset($installed['versions'][$packageName])) {
212
+ continue;
213
  }
214
 
215
+ if (!isset($installed['versions'][$packageName]['pretty_version'])) {
216
  return null;
217
  }
218
 
219
+ return $installed['versions'][$packageName]['pretty_version'];
220
+ }
221
+
222
+ throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
223
  }
224
 
225
 
228
 
229
  public static function getReference($packageName)
230
  {
231
+ foreach (self::getInstalled() as $installed) {
232
+ if (!isset($installed['versions'][$packageName])) {
233
+ continue;
234
  }
235
 
236
+ if (!isset($installed['versions'][$packageName]['reference'])) {
237
  return null;
238
  }
239
 
240
+ return $installed['versions'][$packageName]['reference'];
241
+ }
242
+
243
+ throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
244
  }
245
 
246
 
249
 
250
  public static function getRootPackage()
251
  {
252
+ $installed = self::getInstalled();
253
+
254
+ return $installed[0]['root'];
255
  }
256
 
257
 
286
  public static function reload($data)
287
  {
288
  self::$installed = $data;
289
+ self::$installedByVendor = array();
290
+ }
291
+
292
+
293
+
294
+
295
+ private static function getInstalled()
296
+ {
297
+ if (null === self::$canGetVendors) {
298
+ self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
299
+ }
300
+
301
+ $installed = array();
302
+
303
+ if (self::$canGetVendors) {
304
+
305
+ foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
306
+ if (isset(self::$installedByVendor[$vendorDir])) {
307
+ $installed[] = self::$installedByVendor[$vendorDir];
308
+ } elseif (is_file($vendorDir.'/composer/installed.php')) {
309
+ $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
310
+ }
311
+ }
312
+ }
313
+
314
+ $installed[] = self::$installed;
315
+
316
+ return $installed;
317
  }
318
  }
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInit9ea7af8eb9945c998035f76f2b323645
6
  {
7
  private static $loader;
8
 
@@ -24,15 +24,15 @@ class ComposerAutoloaderInit9ea7af8eb9945c998035f76f2b323645
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) {
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
+ class ComposerAutoloaderInita764a2c503e8d5eb9db23821edfa49f4
6
  {
7
  private static $loader;
8
 
24
 
25
  require __DIR__ . '/platform_check.php';
26
 
27
+ spl_autoload_register(array('ComposerAutoloaderInita764a2c503e8d5eb9db23821edfa49f4', 'loadClassLoader'), true, true);
28
+ self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
29
+ spl_autoload_unregister(array('ComposerAutoloaderInita764a2c503e8d5eb9db23821edfa49f4', '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\ComposerStaticInita764a2c503e8d5eb9db23821edfa49f4::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 ComposerStaticInit9ea7af8eb9945c998035f76f2b323645
8
  {
9
  public static $prefixLengthsPsr4 = array (
10
  'M' =>
@@ -163,10 +163,10 @@ class ComposerStaticInit9ea7af8eb9945c998035f76f2b323645
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
  }
4
 
5
  namespace Composer\Autoload;
6
 
7
+ class ComposerStaticInita764a2c503e8d5eb9db23821edfa49f4
8
  {
9
  public static $prefixLengthsPsr4 = array (
10
  'M' =>
163
  public static function getInitializer(ClassLoader $loader)
164
  {
165
  return \Closure::bind(function () use ($loader) {
166
+ $loader->prefixLengthsPsr4 = ComposerStaticInita764a2c503e8d5eb9db23821edfa49f4::$prefixLengthsPsr4;
167
+ $loader->prefixDirsPsr4 = ComposerStaticInita764a2c503e8d5eb9db23821edfa49f4::$prefixDirsPsr4;
168
+ $loader->prefixesPsr0 = ComposerStaticInita764a2c503e8d5eb9db23821edfa49f4::$prefixesPsr0;
169
+ $loader->classMap = ComposerStaticInita764a2c503e8d5eb9db23821edfa49f4::$classMap;
170
 
171
  }, null, ClassLoader::class);
172
  }
vendor/composer/installed.json CHANGED
@@ -74,10 +74,6 @@
74
  "wordpress",
75
  "zend"
76
  ],
77
- "support": {
78
- "issues": "https://github.com/composer/installers/issues",
79
- "source": "https://github.com/composer/installers/tree/master"
80
- },
81
  "install-path": "./installers"
82
  },
83
  {
@@ -122,10 +118,6 @@
122
  }
123
  ],
124
  "description": "Singleton implementation",
125
- "support": {
126
- "issues": "https://github.com/micropackage/singleton/issues",
127
- "source": "https://github.com/micropackage/singleton/tree/1.1.0"
128
- },
129
  "install-path": "../micropackage/singleton"
130
  },
131
  {
@@ -159,13 +151,10 @@
159
  }
160
  ],
161
  "description": "WordPress drop-in to check requirements",
162
- "support": {
163
- "issues": "https://github.com/Kubitomakita/Requirements/issues",
164
- "source": "https://github.com/Kubitomakita/Requirements/tree/1.3.3"
165
- },
166
  "abandoned": true,
167
  "install-path": "../underdev/requirements"
168
  }
169
  ],
170
- "dev": false
 
171
  }
74
  "wordpress",
75
  "zend"
76
  ],
 
 
 
 
77
  "install-path": "./installers"
78
  },
79
  {
118
  }
119
  ],
120
  "description": "Singleton implementation",
 
 
 
 
121
  "install-path": "../micropackage/singleton"
122
  },
123
  {
151
  }
152
  ],
153
  "description": "WordPress drop-in to check requirements",
 
 
 
 
154
  "abandoned": true,
155
  "install-path": "../underdev/requirements"
156
  }
157
  ],
158
+ "dev": false,
159
+ "dev-package-names": []
160
  }
vendor/composer/installed.php CHANGED
@@ -1,12 +1,12 @@
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,12 +38,12 @@
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 (
1
  <?php return array (
2
  'root' =>
3
  array (
4
+ 'pretty_version' => '1.0.9',
5
+ 'version' => '1.0.9.0',
6
  'aliases' =>
7
  array (
8
  ),
9
+ 'reference' => 'ccb4690711f71cde94e238b3f5631a8ed958dbe8',
10
  'name' => 'szaleq/easy-watermark',
11
  ),
12
  'versions' =>
38
  ),
39
  'szaleq/easy-watermark' =>
40
  array (
41
+ 'pretty_version' => '1.0.9',
42
+ 'version' => '1.0.9.0',
43
  'aliases' =>
44
  array (
45
  ),
46
+ 'reference' => 'ccb4690711f71cde94e238b3f5631a8ed958dbe8',
47
  ),
48
  'underdev/requirements' =>
49
  array (
vendor/composer/installers/.editorconfig DELETED
@@ -1,10 +0,0 @@
1
- ; top-most EditorConfig file
2
- root = true
3
-
4
- ; Unix-style newlines
5
- [*]
6
- end_of_line = LF
7
-
8
- [*.php]
9
- indent_style = space
10
- indent_size = 4
 
 
 
 
 
 
 
 
 
 
vendor/composer/installers/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- vendor/
2
- composer.lock
 
 
vendor/composer/installers/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- language: php
2
-
3
- php:
4
- - 5.3
5
- - 5.4
6
-
7
- before_script:
8
- - curl -s http://getcomposer.org/installer | php -- --quiet
9
- - php composer.phar install --dev
10
-
11
- script: phpunit
 
 
 
 
 
 
 
 
 
 
 
vendor/composer/installers/README.md DELETED
@@ -1,162 +0,0 @@
1
- # A Multi-Framework [Composer](http://getcomposer.org) Library Installer
2
-
3
- [![Build Status](https://secure.travis-ci.org/composer/installers.png)](http://travis-ci.org/composer/installers)
4
-
5
- This is for PHP package authors to require in their `composer.json`. It will
6
- install their package to the correct location based on the specified package
7
- type.
8
-
9
- The goal of `installers` is to be a simple package type to install path map.
10
- Users can also customize the install path per package and package authors can
11
- modify the package name upon installing.
12
-
13
- `installers` isn't intended on replacing all custom installers. If your
14
- package requires special installation handling then by all means, create a
15
- custom installer to handle it.
16
-
17
- **Natively Supported Frameworks**:
18
-
19
- The following frameworks natively work with Composer and will be
20
- installed to the default `vendor` directory. `composer/installers`
21
- is not needed to install packages with these frameworks:
22
-
23
- * Aura
24
- * Symfony2
25
- * Yii
26
-
27
- **Current Supported Package Types**:
28
-
29
- > Stable types are marked as **bold**, this means that installation paths
30
- > for those type will not be change. Any adjustment for those types would
31
- > require creation of brand new type that will cover required changes.
32
-
33
- | Framework | Types
34
- | --------- | -----
35
- | AGL | `agl-module`
36
- | AnnotateCms | `annotatecms-module`<br>`annotatecms-component`<br>`annotatecms-service`
37
- | CakePHP 2+ | **`cakephp-plugin`**
38
- | CodeIgniter | `codeigniter-library`<br>`codeigniter-third-party`<br>`codeigniter-module`
39
- | Croogo | `croogo-plugin`<br>`croogo-theme`
40
- | Drupal | <b>`drupal-module`<br>`drupal-theme`</b><br>`drupal-profile`<br>`drupal-drush`
41
- | FuelPHP v1.x | `fuel-module`<br>`fuel-package`
42
- | Joomla | `joomla-component`<br>`joomla-module`<br>`joomla-template`<br>`joomla-plugin`<br>`joomla-library`
43
- | Kohana | **`kohana-module`**
44
- | Laravel | `laravel-library`
45
- | Lithium | **`lithium-library`<br>`lithium-source`**
46
- | Magento | `magento-library`<br>`magento-skin`<br>`magento-theme`
47
- | Mako | `mako-package`
48
- | MediaWiki | `mediawiki-extension`
49
- | OXID | `oxid-module`
50
- | MODULEWork | `modulework-module`
51
- | phpBB | `phpbb-extension`<br>`phpbb-style`<br>`phpbb-language`
52
- | PPI | **`ppi-module`**
53
- | SilverStripe | `silverstripe-module`<br>`silverstripe-theme`
54
- | symfony1 | **`symfony1-plugin`**
55
- | TYPO3 Flow | `typo3-flow-package`<br>`typo3-flow-framework`<br>`typo3-flow-plugin`<br>`typo3-flow-site`<br>`typo3-flow-boilerplate`<br>`typo3-flow-build`
56
- | TYPO3 CMS | `typo3-cms-extension`
57
- | WordPress | <b>`wordpress-plugin`<br>`wordpress-theme`</b><br>`wordpress-muplugin`
58
- | Zend | `zend-library`<br>`zend-extra`
59
-
60
- ## Example `composer.json` File
61
-
62
- This is an example for a CakePHP plugin. The only important parts to set in your
63
- composer.json file are `"type": "cakephp-plugin"` which describes what your
64
- package is and `"require": { "composer/installers": "~1.0" }` which tells composer
65
- to load the custom installers.
66
-
67
- ```json
68
- {
69
- "name": "you/ftp",
70
- "type": "cakephp-plugin",
71
- "require": {
72
- "composer/installers": "~1.0"
73
- }
74
- }
75
- ```
76
-
77
- This would install your package to the `Plugin/Ftp/` folder of a CakePHP app
78
- when a user runs `php composer.phar install`.
79
-
80
- So submit your packages to [packagist.org](http://packagist.org)!
81
-
82
- ## Custom Install Paths
83
-
84
- If you are consuming a package that uses the `composer/installers` you can
85
- override the install path with the following extra in your `composer.json`:
86
-
87
- ```json
88
- {
89
- "extra": {
90
- "installer-paths": {
91
- "your/custom/path/{$name}/": ["shama/ftp", "vendor/package"]
92
- }
93
- }
94
- }
95
- ```
96
-
97
- A package type can have a custom installation path with a `type:` prefix.
98
-
99
- ``` json
100
- {
101
- "extra": {
102
- "installer-paths": {
103
- "your/custom/path/{$name}/": ["type:wordpress-plugin"]
104
- }
105
- }
106
- }
107
- ```
108
-
109
- This would use your custom path for each of the listed packages. The available
110
- variables to use in your paths are: `{$name}`, `{$vendor}`, `{$type}`.
111
-
112
- ## Custom Install Names
113
-
114
- If you're a package author and need your package to be named differently when
115
- installed consider using the `installer-name` extra.
116
-
117
- For example you have a package named `shama/cakephp-ftp` with the type
118
- `cakephp-plugin`. Installing with `composer/installers` would install to the
119
- path `Plugin/CakephpFtp`. Due to the strict naming conventions, you as a
120
- package author actually need the package to be named and installed to
121
- `Plugin/Ftp`. Using the following config within your **package** `composer.json`
122
- will allow this:
123
-
124
- ```json
125
- {
126
- "name": "shama/cakephp-ftp",
127
- "type": "cakephp-plugin",
128
- "extra": {
129
- "installer-name": "Ftp"
130
- }
131
- }
132
- ```
133
-
134
- Please note the name entered into `installer-name` will be the final and will
135
- not be inflected.
136
-
137
- ## Contribute!
138
-
139
- * [Fork and clone](https://help.github.com/articles/fork-a-repo).
140
- * Run the command `php composer.phar install --dev` to install the dev
141
- dependencies. See [Composer](https://github.com/composer/composer#installation--usage).
142
- * Use the command `phpunit` to run the tests. See [PHPUnit](http://phpunit.de).
143
- * Create a branch, commit, push and send us a
144
- [pull request](https://help.github.com/articles/using-pull-requests).
145
-
146
- To ensure a consistent code base, you should make sure the code follows the
147
- [Coding Standards](http://symfony.com/doc/2.0/contributing/code/standards.html)
148
- which we borrowed from Symfony.
149
-
150
- If you would like to help, please take a look at the list of
151
- [issues](https://github.com/composer/installers/issues).
152
-
153
- ### Should we allow dynamic package types or paths? No.
154
- What are they? The ability for a package author to determine where a package
155
- will be installed either through setting the path directly in their
156
- `composer.json` or through a dynamic package type: `"type":
157
- "framework-install-here"`.
158
-
159
- It has been proposed many times. Even implemented once early on and then
160
- removed. `installers` won't do this because it would allow a single package
161
- author to wipe out entire folders without the user's consent. That user would
162
- then come here to yell at us.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/composer/installers/composer.json DELETED
@@ -1,38 +0,0 @@
1
- {
2
- "name": "composer/installers",
3
- "type": "composer-installer",
4
- "license": "MIT",
5
- "description": "A multi-framework Composer library installer",
6
- "keywords": [
7
- "installer", "cakephp", "laravel", "kohana",
8
- "li3", "lithium", "mako","fuelphp",
9
- "codeigniter", "symfony", "phpbb", "ppi",
10
- "joomla", "wordpress", "drupal", "zend",
11
- "silverstripe", "agl", "TYPO3 Flow", "TYPO3 Neos", "modulework",
12
- "TYPO3 CMS"
13
- ],
14
- "homepage": "http://composer.github.com/installers/",
15
- "authors": [
16
- {
17
- "name": "Kyle Robinson Young",
18
- "email": "kyle@dontkry.com",
19
- "homepage": "https://github.com/shama"
20
- }
21
- ],
22
- "autoload": {
23
- "psr-0": { "Composer\\Installers\\": "src/" }
24
- },
25
- "extra": {
26
- "class": "Composer\\Installers\\Installer",
27
- "branch-alias": {
28
- "dev-master": "1.0-dev"
29
- }
30
- },
31
- "replace": {
32
- "shama/baton": "*"
33
- },
34
- "require-dev": {
35
- "composer/composer": "1.0.*@dev",
36
- "phpunit/phpunit": "3.7.*"
37
- }
38
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/composer/platform_check.php CHANGED
@@ -5,10 +5,22 @@
5
  $issues = array();
6
 
7
  if (!(PHP_VERSION_ID >= 50600)) {
8
- $issues[] = 'Your Composer dependencies require a PHP version ">= 5.6.0". You are running ' . PHP_VERSION . '.';
9
  }
10
 
11
  if ($issues) {
12
- echo 'Composer detected issues in your platform:' . "\n\n" . implode("\n", $issues);
13
- exit(104);
 
 
 
 
 
 
 
 
 
 
 
 
14
  }
5
  $issues = array();
6
 
7
  if (!(PHP_VERSION_ID >= 50600)) {
8
+ $issues[] = 'Your Composer dependencies require a PHP version ">= 5.6.0". You are running ' . PHP_VERSION . '.';
9
  }
10
 
11
  if ($issues) {
12
+ if (!headers_sent()) {
13
+ header('HTTP/1.1 500 Internal Server Error');
14
+ }
15
+ if (!ini_get('display_errors')) {
16
+ if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
17
+ fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
18
+ } elseif (!headers_sent()) {
19
+ echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
20
+ }
21
+ }
22
+ trigger_error(
23
+ 'Composer detected issues in your platform: ' . implode(' ', $issues),
24
+ E_USER_ERROR
25
+ );
26
  }
vendor/micropackage/singleton/.editorconfig DELETED
@@ -1,15 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- charset = utf-8
5
- end_of_line = lf
6
- insert_final_newline = true
7
- trim_trailing_whitespace = true
8
- indent_style = tab
9
-
10
- [{*.txt,wp-config-sample.php}]
11
- end_of_line = crlf
12
-
13
- [*.yml]
14
- indent_style = space
15
- indent_size = 2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/micropackage/singleton/.gitattributes DELETED
@@ -1 +0,0 @@
1
- * text eol=lf
 
vendor/micropackage/singleton/.gitignore DELETED
@@ -1,104 +0,0 @@
1
- ### Project ###
2
- *.log
3
- /vendor/
4
-
5
- ### Windows ###
6
- # Windows image file caches
7
- Thumbs.db
8
- ehthumbs.db
9
-
10
- # Folder config file
11
- Desktop.ini
12
-
13
- # Recycle Bin used on file shares
14
- $RECYCLE.BIN/
15
-
16
- # Windows Installer files
17
- *.cab
18
- *.msi
19
- *.msm
20
- *.msp
21
-
22
- # Windows shortcuts
23
- *.lnk
24
-
25
-
26
- ### macOS ###
27
- *.DS_Store
28
- .AppleDouble
29
- .LSOverride
30
-
31
- # Icon must end with two \r
32
- Icon
33
-
34
-
35
- # Thumbnails
36
- ._*
37
-
38
- # Files that might appear in the root of a volume
39
- .DocumentRevisions-V100
40
- .fseventsd
41
- .Spotlight-V100
42
- .TemporaryItems
43
- .Trashes
44
- .VolumeIcon.icns
45
- .com.apple.timemachine.donotpresent
46
-
47
- # Directories potentially created on remote AFP share
48
- .AppleDB
49
- .AppleDesktop
50
- Network Trash Folder
51
- Temporary Items
52
- .apdisk
53
-
54
-
55
- ### Sass ###
56
- .sass-cache/
57
- *.css.map
58
-
59
-
60
- ### SublimeText ###
61
- # cache files for sublime text
62
- *.tmlanguage.cache
63
- *.tmPreferences.cache
64
- *.stTheme.cache
65
-
66
- # workspace files are user-specific
67
- *.sublime-workspace
68
- .vscode
69
-
70
- # project files should be checked into the repository, unless a significant
71
- # proportion of contributors will probably not be using SublimeText
72
- # *.sublime-project
73
-
74
- # sftp configuration file
75
- sftp-config.json
76
-
77
- # postcss sorting config file
78
- settings.json
79
-
80
- # Package control specific files
81
- Package Control.last-run
82
- Package Control.ca-list
83
- Package Control.ca-bundle
84
- Package Control.system-ca-bundle
85
- Package Control.cache/
86
- Package Control.ca-certs/
87
- bh_unicode_properties.cache
88
-
89
- # Sublime-github package stores a github token in this file
90
- # https://packagecontrol.io/packages/sublime-github
91
- GitHub.sublime-settings
92
-
93
-
94
- ### Vim ###
95
- # swap
96
- [._]*.s[a-w][a-z]
97
- [._]s[a-w][a-z]
98
- # session
99
- Session.vim
100
- # temporary
101
- .netrwhist
102
- *~
103
- # auto-generated tag files
104
- tags
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/micropackage/singleton/README.md DELETED
@@ -1,39 +0,0 @@
1
- # Singleton
2
-
3
- [![BracketSpace Micropackage](https://img.shields.io/badge/BracketSpace-Micropackage-brightgreen)](https://bracketspace.com)
4
- [![Latest Stable Version](https://poser.pugx.org/micropackage/singleton/v/stable)](https://packagist.org/packages/micropackage/singleton)
5
- [![PHP from Packagist](https://img.shields.io/packagist/php-v/micropackage/singleton.svg)](https://packagist.org/packages/micropackage/singleton)
6
- [![Total Downloads](https://poser.pugx.org/micropackage/singleton/downloads)](https://packagist.org/packages/micropackage/singleton)
7
- [![License](https://poser.pugx.org/micropackage/singleton/license)](https://packagist.org/packages/micropackage/singleton)
8
-
9
- ## 💾 Installation
10
-
11
- ``` bash
12
- composer require micropackage/singleton
13
- ```
14
-
15
- ## 🕹 Usage
16
-
17
- ```php
18
- use Micropackage\Singleton\Singleton;
19
-
20
- class Example extends Singleton {}
21
-
22
- Example::get();
23
- ```
24
-
25
- ## 📦 About the Micropackage project
26
-
27
- Micropackages - as the name suggests - are micro packages with a tiny bit of reusable code, helpful particularly in WordPress development.
28
-
29
- The aim is to have multiple packages which can be put together to create something bigger by defining only the structure.
30
-
31
- Micropackages are maintained by [BracketSpace](https://bracketspace.com).
32
-
33
- ## 📖 Changelog
34
-
35
- [See the changelog file](./CHANGELOG.md).
36
-
37
- ## 📃 License
38
-
39
- GNU General Public License (GPL) v3.0. See the [LICENSE](./LICENSE) file for more information.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/micropackage/singleton/composer.json DELETED
@@ -1,29 +0,0 @@
1
- {
2
- "name": "micropackage/singleton",
3
- "description": "Singleton implementation",
4
- "version": "1.1.0",
5
- "license": "GPL-3.0-or-later",
6
- "authors": [
7
- {
8
- "name": "Jakub Mikita",
9
- "email": "jakub@bracketspace.com"
10
- }
11
- ],
12
- "scripts": {
13
- "phpcs": "phpcs",
14
- "phpcbf": "phpcbf"
15
- },
16
- "require": {
17
- "php": ">=5.6"
18
- },
19
- "require-dev": {
20
- "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
21
- "phpcompatibility/php-compatibility": "^9.1",
22
- "wp-coding-standards/wpcs": "^2.0"
23
- },
24
- "autoload": {
25
- "psr-4" : {
26
- "Micropackage\\Singleton\\" : "src"
27
- }
28
- }
29
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/micropackage/singleton/composer.lock DELETED
@@ -1,240 +0,0 @@
1
- {
2
- "_readme": [
3
- "This file locks the dependencies of your project to a known state",
4
- "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5
- "This file is @generated automatically"
6
- ],
7
- "content-hash": "3c61a592c24a6bc59b8e9172a516fa20",
8
- "packages": [],
9
- "packages-dev": [
10
- {
11
- "name": "dealerdirect/phpcodesniffer-composer-installer",
12
- "version": "v0.5.0",
13
- "source": {
14
- "type": "git",
15
- "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git",
16
- "reference": "e749410375ff6fb7a040a68878c656c2e610b132"
17
- },
18
- "dist": {
19
- "type": "zip",
20
- "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/e749410375ff6fb7a040a68878c656c2e610b132",
21
- "reference": "e749410375ff6fb7a040a68878c656c2e610b132",
22
- "shasum": ""
23
- },
24
- "require": {
25
- "composer-plugin-api": "^1.0",
26
- "php": "^5.3|^7",
27
- "squizlabs/php_codesniffer": "^2|^3"
28
- },
29
- "require-dev": {
30
- "composer/composer": "*",
31
- "phpcompatibility/php-compatibility": "^9.0",
32
- "sensiolabs/security-checker": "^4.1.0"
33
- },
34
- "type": "composer-plugin",
35
- "extra": {
36
- "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin"
37
- },
38
- "autoload": {
39
- "psr-4": {
40
- "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/"
41
- }
42
- },
43
- "notification-url": "https://packagist.org/downloads/",
44
- "license": [
45
- "MIT"
46
- ],
47
- "authors": [
48
- {
49
- "name": "Franck Nijhof",
50
- "email": "franck.nijhof@dealerdirect.com",
51
- "homepage": "http://www.frenck.nl",
52
- "role": "Developer / IT Manager"
53
- }
54
- ],
55
- "description": "PHP_CodeSniffer Standards Composer Installer Plugin",
56
- "homepage": "http://www.dealerdirect.com",
57
- "keywords": [
58
- "PHPCodeSniffer",
59
- "PHP_CodeSniffer",
60
- "code quality",
61
- "codesniffer",
62
- "composer",
63
- "installer",
64
- "phpcs",
65
- "plugin",
66
- "qa",
67
- "quality",
68
- "standard",
69
- "standards",
70
- "style guide",
71
- "stylecheck",
72
- "tests"
73
- ],
74
- "time": "2018-10-26T13:21:45+00:00"
75
- },
76
- {
77
- "name": "phpcompatibility/php-compatibility",
78
- "version": "9.3.5",
79
- "source": {
80
- "type": "git",
81
- "url": "https://github.com/PHPCompatibility/PHPCompatibility.git",
82
- "reference": "9fb324479acf6f39452e0655d2429cc0d3914243"
83
- },
84
- "dist": {
85
- "type": "zip",
86
- "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/9fb324479acf6f39452e0655d2429cc0d3914243",
87
- "reference": "9fb324479acf6f39452e0655d2429cc0d3914243",
88
- "shasum": ""
89
- },
90
- "require": {
91
- "php": ">=5.3",
92
- "squizlabs/php_codesniffer": "^2.3 || ^3.0.2"
93
- },
94
- "conflict": {
95
- "squizlabs/php_codesniffer": "2.6.2"
96
- },
97
- "require-dev": {
98
- "phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0"
99
- },
100
- "suggest": {
101
- "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.",
102
- "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues."
103
- },
104
- "type": "phpcodesniffer-standard",
105
- "notification-url": "https://packagist.org/downloads/",
106
- "license": [
107
- "LGPL-3.0-or-later"
108
- ],
109
- "authors": [
110
- {
111
- "name": "Wim Godden",
112
- "homepage": "https://github.com/wimg",
113
- "role": "lead"
114
- },
115
- {
116
- "name": "Juliette Reinders Folmer",
117
- "homepage": "https://github.com/jrfnl",
118
- "role": "lead"
119
- },
120
- {
121
- "name": "Contributors",
122
- "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors"
123
- }
124
- ],
125
- "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.",
126
- "homepage": "http://techblog.wimgodden.be/tag/codesniffer/",
127
- "keywords": [
128
- "compatibility",
129
- "phpcs",
130
- "standards"
131
- ],
132
- "time": "2019-12-27T09:44:58+00:00"
133
- },
134
- {
135
- "name": "squizlabs/php_codesniffer",
136
- "version": "3.5.3",
137
- "source": {
138
- "type": "git",
139
- "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
140
- "reference": "557a1fc7ac702c66b0bbfe16ab3d55839ef724cb"
141
- },
142
- "dist": {
143
- "type": "zip",
144
- "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/557a1fc7ac702c66b0bbfe16ab3d55839ef724cb",
145
- "reference": "557a1fc7ac702c66b0bbfe16ab3d55839ef724cb",
146
- "shasum": ""
147
- },
148
- "require": {
149
- "ext-simplexml": "*",
150
- "ext-tokenizer": "*",
151
- "ext-xmlwriter": "*",
152
- "php": ">=5.4.0"
153
- },
154
- "require-dev": {
155
- "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
156
- },
157
- "bin": [
158
- "bin/phpcs",
159
- "bin/phpcbf"
160
- ],
161
- "type": "library",
162
- "extra": {
163
- "branch-alias": {
164
- "dev-master": "3.x-dev"
165
- }
166
- },
167
- "notification-url": "https://packagist.org/downloads/",
168
- "license": [
169
- "BSD-3-Clause"
170
- ],
171
- "authors": [
172
- {
173
- "name": "Greg Sherwood",
174
- "role": "lead"
175
- }
176
- ],
177
- "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
178
- "homepage": "https://github.com/squizlabs/PHP_CodeSniffer",
179
- "keywords": [
180
- "phpcs",
181
- "standards"
182
- ],
183
- "time": "2019-12-04T04:46:47+00:00"
184
- },
185
- {
186
- "name": "wp-coding-standards/wpcs",
187
- "version": "2.2.0",
188
- "source": {
189
- "type": "git",
190
- "url": "https://github.com/WordPress/WordPress-Coding-Standards.git",
191
- "reference": "f90e8692ce97b693633db7ab20bfa78d930f536a"
192
- },
193
- "dist": {
194
- "type": "zip",
195
- "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/f90e8692ce97b693633db7ab20bfa78d930f536a",
196
- "reference": "f90e8692ce97b693633db7ab20bfa78d930f536a",
197
- "shasum": ""
198
- },
199
- "require": {
200
- "php": ">=5.4",
201
- "squizlabs/php_codesniffer": "^3.3.1"
202
- },
203
- "require-dev": {
204
- "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
205
- "phpcompatibility/php-compatibility": "^9.0",
206
- "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
207
- },
208
- "suggest": {
209
- "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically."
210
- },
211
- "type": "phpcodesniffer-standard",
212
- "notification-url": "https://packagist.org/downloads/",
213
- "license": [
214
- "MIT"
215
- ],
216
- "authors": [
217
- {
218
- "name": "Contributors",
219
- "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors"
220
- }
221
- ],
222
- "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions",
223
- "keywords": [
224
- "phpcs",
225
- "standards",
226
- "wordpress"
227
- ],
228
- "time": "2019-11-11T12:34:03+00:00"
229
- }
230
- ],
231
- "aliases": [],
232
- "minimum-stability": "stable",
233
- "stability-flags": [],
234
- "prefer-stable": false,
235
- "prefer-lowest": false,
236
- "platform": {
237
- "php": ">=5.6"
238
- },
239
- "platform-dev": []
240
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/micropackage/singleton/phpcs.xml DELETED
@@ -1,43 +0,0 @@
1
- <?xml version="1.0"?>
2
- <ruleset name="Sniffs for Micropackage">
3
- <rule ref="WordPress">
4
- <exclude name="Generic.Files.LowercasedFilename" />
5
- <exclude name="Generic.Arrays.DisallowShortArraySyntax.Found" />
6
- <exclude name="WordPress.Files.FileName" />
7
- <exclude name="WordPress.Files.FileName.UnderscoresNotAllowed" />
8
- <exclude name="WordPress.NamingConventions.ValidHookName.UseUnderscores" />
9
- <exclude name="WordPress.PHP.DevelopmentFunctions.error_log_trigger_error" />
10
- <exclude name="WordPress.VIP.SuperGlobalInputUsage.AccessDetected" />
11
- <exclude name="WordPress.CSRF.NonceVerification.NoNonceVerification" />
12
- <exclude name="WordPress.Security.NonceVerification.NoNonceVerification" />
13
- <exclude name="WordPress.DB.SlowDBQuery" />
14
- <exclude name="WordPress.WP.I18n.NonSingularStringLiteralText" />
15
- <exclude name="WordPress.VIP.RestrictedVariables.cache_constraints___SERVER__REMOTE_ADDR__" />
16
- <exclude name="WordPress.WP.AlternativeFunctions.file_system_read_file_get_contents" />
17
- <exclude name="WordPress.WP.I18n.NonSingularStringLiteralDomain" />
18
- <exclude name="WordPress.WP.GlobalVariablesOverride" />
19
- <exclude name="PEAR.Functions.FunctionCallSignature.MultipleArguments" />
20
- <exclude name="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket" />
21
- <exclude name="PEAR.Functions.FunctionCallSignature.CloseBracketLine" />
22
- </rule>
23
- <rule ref="Squiz.Commenting.FunctionComment">
24
- <exclude name="Squiz.Commenting.FunctionComment.InvalidTypeHint" />
25
- </rule>
26
- <rule ref="PSR2.Methods.MethodDeclaration">
27
- <exclude name="PSR2.Methods.MethodDeclaration.Underscore" />
28
- </rule>
29
-
30
- <!-- PHPCompatibility -->
31
- <rule ref="PHPCompatibility" />
32
- <config name="testVersion" value="5.6-" />
33
-
34
- <!-- Check all PHP files in directory tree by default. -->
35
- <arg name="extensions" value="php"/>
36
- <file>.</file>
37
-
38
- <!-- Show progress and sniff codes in all reports -->
39
- <arg value="ps"/>
40
-
41
- <exclude-pattern>tests/*</exclude-pattern>
42
- <exclude-pattern>vendor/*</exclude-pattern>
43
- </ruleset>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/underdev/requirements/.editorconfig DELETED
@@ -1,22 +0,0 @@
1
- # This file is for unifying the coding style for different editors and IDEs
2
- # editorconfig.org
3
-
4
- # WordPress Coding Standards
5
- # https://make.wordpress.org/core/handbook/coding-standards/
6
-
7
- root = true
8
-
9
- [*]
10
- charset = utf-8
11
- end_of_line = lf
12
- insert_final_newline = true
13
- trim_trailing_whitespace = true
14
- indent_style = tab
15
- indent_size = 4
16
-
17
- [{.jshintrc,*.json,*.yml}]
18
- indent_style = space
19
- indent_size = 2
20
-
21
- [{*.txt,wp-config-sample.php}]
22
- end_of_line = crlf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/underdev/requirements/.gitattributes DELETED
@@ -1 +0,0 @@
1
- * text=auto
 
vendor/underdev/requirements/.gitignore DELETED
@@ -1,7 +0,0 @@
1
- **.DS_Store*
2
- *.sublime-project
3
- *.sublime-workspace
4
- node_modules
5
- yarn.lock
6
- composer.lock
7
- package-lock.json
 
 
 
 
 
 
 
vendor/underdev/requirements/README.md DELETED
@@ -1,90 +0,0 @@
1
- [![Latest Stable Version](https://poser.pugx.org/underdev/requirements/v/stable)](https://packagist.org/packages/underdev/requirements)
2
- [![Total Downloads](https://poser.pugx.org/underdev/requirements/downloads)](https://packagist.org/packages/underdev/requirements)
3
- [![Latest Unstable Version](https://poser.pugx.org/underdev/requirements/v/unstable)](https://packagist.org/packages/underdev/requirements)
4
-
5
- # WordPress plugin requirements
6
-
7
- A WordPress drop-in to check requirements.
8
-
9
- Simple include the underDEV_Requirements.php file in your project or install and load it via Composer:
10
-
11
- `composer require underdev/requirements`
12
-
13
- Default checks:
14
- * PHP version
15
- * PHP extensions loaded
16
- * WordPress version
17
- * Active plugins and their versions
18
- * Active theme
19
- * Function collisions
20
- * Class collisions
21
-
22
- You can add also your own custom checks. See the example below.
23
-
24
- It doesn't break the user action, such as activating many plugins at once. It will simply display a notice in the admin area:
25
-
26
- ![Requirements in WP Admin](https://www.wpart.co/img/requirements.png)
27
-
28
- ## Sample usage
29
-
30
- ```php
31
- <?php
32
- /*
33
- Plugin Name: My Test Plugin
34
- Version: 1.0
35
- */
36
-
37
- /**
38
- * If installed by download
39
- */
40
- require_once( 'underDEV_Requirements.php' );
41
-
42
- /**
43
- * If installed via Composer it's included in the autoloader
44
- */
45
- require_once( 'vendor/autoload.php' );
46
-
47
- $requirements = new underDEV_Requirements( 'My Test Plugin', array(
48
- 'php' => '5.3',
49
- 'php_extensions' => array( 'soap' ),
50
- 'wp' => '4.8',
51
- 'plugins' => array(
52
- 'akismet/akismet.php' => array( 'name' => 'Akismet', 'version' => '3.0' ),
53
- 'hello-dolly/hello.php' => array( 'name' => 'Hello Dolly', 'version' => '1.5' )
54
- ),
55
- 'theme' => array(
56
- 'slug' => 'twentysixteen',
57
- 'name' => 'Twenty Sixteen'
58
- ),
59
- 'function_collision' => array( 'my_function_name', 'some_other_potential_collision' ),
60
- 'class_collision' => array( 'My_Test_Plugin', 'My_Test_Plugin_Other_Class' ),
61
- 'custom_check' => 'thing to check', // this is not default check and will have to be registered
62
- ) );
63
-
64
- /**
65
- * Add your own check
66
- */
67
- function my_plugin_custom_check( $comparsion, $r ) {
68
- if ( $comparsion != 'thing to check' ) {
69
- $r->add_error( 'this thing to be that' );
70
- }
71
- }
72
-
73
- $requirements->add_check( 'custom_check', 'my_plugin_custom_check' );
74
-
75
- /**
76
- * Run all the checks and check if requirements has been satisfied
77
- * If not - display the admin notice and exit from the file
78
- */
79
- if ( ! $requirements->satisfied() ) {
80
-
81
- add_action( 'admin_notices', array( $requirements, 'notice' ) );
82
- return;
83
-
84
- }
85
-
86
- /**
87
- * Checks passed - load the plugin
88
- */
89
- new My_Test_Plugin();
90
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/underdev/requirements/composer.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "name": "underdev/requirements",
3
- "description": "WordPress drop-in to check requirements",
4
- "type": "library",
5
- "authors": [
6
- {
7
- "name": "Kuba Mikita",
8
- "email": "jakub@underdev.it"
9
- }
10
- ],
11
- "require": {},
12
- "autoload": {
13
- "classmap": ["underDEV_Requirements.php"]
14
- }
15
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/underdev/requirements/package.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "name": "requirements",
3
- "version": "1.3.3",
4
- "description": "WordPress drop-in to check requirements",
5
- "scripts": {
6
- "translate": "wp-pot -s '*.php' -o ./languages/underdev-requirements.pot -p underdev-requirements",
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/Kubitomakita/Requirements.git"
12
- },
13
- "author": "underDEV",
14
- "license": "ISC",
15
- "bugs": {
16
- "url": "https://github.com/Kubitomakita/Requirements/issues"
17
- },
18
- "homepage": "https://github.com/Kubitomakita/Requirements/#readme",
19
- "devDependencies": {
20
- "wp-pot-cli": "1.0.0"
21
- }
22
- }