Version Description
- Tweak: WordPress 5.9 compatibility
- Tweak: PHP 8.x compatibility
Download this release
Release Info
Developer | dfactory |
Plugin | Image Watermark |
Version | 1.7.0 |
Comparing to | |
See all releases |
Code changes from version 1.6.6 to 1.7.0
- image-watermark.php +1517 -1508
- includes/class-settings.php +77 -86
- includes/class-update.php +1 -1
- js/admin-image-actions.js +555 -545
- js/admin-settings.js +75 -73
- js/admin-upload.js +57 -57
- readme.txt +197 -191
image-watermark.php
CHANGED
@@ -1,1509 +1,1518 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Plugin Name: Image Watermark
|
4 |
-
Description: Image Watermark allows you to automatically watermark images uploaded to the WordPress Media Library and bulk watermark previously uploaded images.
|
5 |
-
Version: 1.
|
6 |
-
Author: dFactory
|
7 |
-
Author URI: https://dfactory.eu/
|
8 |
-
Plugin URI: https://dfactory.eu/plugins/image-watermark/
|
9 |
-
License: MIT License
|
10 |
-
License URI: http://opensource.org/licenses/MIT
|
11 |
-
Text Domain: image-watermark
|
12 |
-
Domain Path: /languages
|
13 |
-
|
14 |
-
Image Watermark
|
15 |
-
Copyright (C) 2013-
|
16 |
-
|
17 |
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
18 |
-
|
19 |
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
20 |
-
|
21 |
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22 |
-
*/
|
23 |
-
|
24 |
-
// exit if accessed directly
|
25 |
-
if ( ! defined( 'ABSPATH' ) )
|
26 |
-
exit;
|
27 |
-
|
28 |
-
define( 'IMAGE_WATERMARK_URL', plugins_url( '', __FILE__ ) );
|
29 |
-
define( 'IMAGE_WATERMARK_PATH', plugin_dir_path( __FILE__ ) );
|
30 |
-
|
31 |
-
/**
|
32 |
-
* Image Watermark class.
|
33 |
-
*
|
34 |
-
* @class Image_Watermark
|
35 |
-
* @version 1.
|
36 |
-
*/
|
37 |
-
final class Image_Watermark {
|
38 |
-
|
39 |
-
private static $instance;
|
40 |
-
private $is_admin = true;
|
41 |
-
private $extension = false;
|
42 |
-
private $allowed_mime_types = array(
|
43 |
-
'image/jpeg',
|
44 |
-
'image/pjpeg',
|
45 |
-
'image/png'
|
46 |
-
);
|
47 |
-
private $is_watermarked_metakey = 'iw-is-watermarked';
|
48 |
-
public $is_backup_folder_writable = null;
|
49 |
-
public $extensions;
|
50 |
-
public $defaults = array(
|
51 |
-
'options' => array(
|
52 |
-
'watermark_on' => array(),
|
53 |
-
'watermark_cpt_on' => array( 'everywhere' ),
|
54 |
-
'watermark_image' => array(
|
55 |
-
'extension' => '',
|
56 |
-
'url' => 0,
|
57 |
-
'width' => 80,
|
58 |
-
'plugin_off' => 0,
|
59 |
-
'frontend_active' => false,
|
60 |
-
'manual_watermarking' => 0,
|
61 |
-
'position' => 'bottom_right',
|
62 |
-
'watermark_size_type' => 2,
|
63 |
-
'offset_unit' => 'pixels',
|
64 |
-
'offset_width' => 0,
|
65 |
-
'offset_height' => 0,
|
66 |
-
'absolute_width' => 0,
|
67 |
-
'absolute_height' => 0,
|
68 |
-
'transparent' => 50,
|
69 |
-
'quality' => 90,
|
70 |
-
'jpeg_format' => 'baseline',
|
71 |
-
'deactivation_delete' => false,
|
72 |
-
'media_library_notice' => true
|
73 |
-
),
|
74 |
-
'image_protection' => array(
|
75 |
-
'rightclick' => 0,
|
76 |
-
'draganddrop' => 0,
|
77 |
-
'forlogged' => 0
|
78 |
-
),
|
79 |
-
'backup' => array(
|
80 |
-
'backup_image' => true,
|
81 |
-
'backup_quality' => 90
|
82 |
-
)
|
83 |
-
),
|
84 |
-
'version' => '1.
|
85 |
-
);
|
86 |
-
public $options = array();
|
87 |
-
|
88 |
-
/**
|
89 |
-
* Class constructor.
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
$
|
100 |
-
|
101 |
-
$this->options
|
102 |
-
$this->options['
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
add_action( '
|
111 |
-
add_action( '
|
112 |
-
add_action( '
|
113 |
-
add_action( '
|
114 |
-
add_action( '
|
115 |
-
add_action( '
|
116 |
-
add_action( '
|
117 |
-
add_action( '
|
118 |
-
add_action( '
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
add_filter( '
|
124 |
-
add_filter( '
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
define
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
*
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
*
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
'
|
331 |
-
'
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
if (
|
348 |
-
wp_enqueue_script( '
|
349 |
-
|
350 |
-
wp_localize_script(
|
351 |
-
'
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
)
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
$
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
$
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
*
|
713 |
-
*
|
714 |
-
* @return
|
715 |
-
*/
|
716 |
-
public function
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
$
|
735 |
-
|
736 |
-
|
737 |
-
$
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
//
|
820 |
-
$
|
821 |
-
|
822 |
-
//
|
823 |
-
|
824 |
-
|
825 |
-
//
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
$
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
*
|
975 |
-
*
|
976 |
-
* @param
|
977 |
-
* @return
|
978 |
-
*/
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
//
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
$
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
$watermark
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
-
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
return
|
1171 |
-
}
|
1172 |
-
|
1173 |
-
/**
|
1174 |
-
* Get image
|
1175 |
-
*
|
1176 |
-
* @param string $filepath
|
1177 |
-
* @return string
|
1178 |
-
*/
|
1179 |
-
private function
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
1184 |
-
|
1185 |
-
|
1186 |
-
|
1187 |
-
|
1188 |
-
|
1189 |
-
|
1190 |
-
*
|
1191 |
-
*
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
|
1209 |
-
|
1210 |
-
|
1211 |
-
|
1212 |
-
|
1213 |
-
|
1214 |
-
|
1215 |
-
|
1216 |
-
|
1217 |
-
|
1218 |
-
|
1219 |
-
|
1220 |
-
|
1221 |
-
|
1222 |
-
|
1223 |
-
|
1224 |
-
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
|
1231 |
-
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
|
1237 |
-
|
1238 |
-
|
1239 |
-
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
$
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
|
1268 |
-
|
1269 |
-
|
1270 |
-
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
$
|
1283 |
-
|
1284 |
-
|
1285 |
-
|
1286 |
-
|
1287 |
-
$
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
$
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
$
|
1298 |
-
|
1299 |
-
|
1300 |
-
|
1301 |
-
|
1302 |
-
$
|
1303 |
-
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
1307 |
-
$dest_x = ( $image_width / 2 ) - ( $watermark_width / 2 );
|
1308 |
-
$dest_y =
|
1309 |
-
|
1310 |
-
|
1311 |
-
|
1312 |
-
|
1313 |
-
|
1314 |
-
|
1315 |
-
|
1316 |
-
|
1317 |
-
|
1318 |
-
|
1319 |
-
|
1320 |
-
|
1321 |
-
|
1322 |
-
|
1323 |
-
|
1324 |
-
|
1325 |
-
|
1326 |
-
|
1327 |
-
|
1328 |
-
|
1329 |
-
|
1330 |
-
|
1331 |
-
|
1332 |
-
|
1333 |
-
|
1334 |
-
|
1335 |
-
|
1336 |
-
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
-
|
1341 |
-
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
|
1348 |
-
|
1349 |
-
|
1350 |
-
|
1351 |
-
|
1352 |
-
|
1353 |
-
|
1354 |
-
|
1355 |
-
|
1356 |
-
|
1357 |
-
|
1358 |
-
|
1359 |
-
|
1360 |
-
|
1361 |
-
|
1362 |
-
|
1363 |
-
|
1364 |
-
|
1365 |
-
|
1366 |
-
|
1367 |
-
|
1368 |
-
|
1369 |
-
|
1370 |
-
|
1371 |
-
|
1372 |
-
|
1373 |
-
|
1374 |
-
|
1375 |
-
|
1376 |
-
|
1377 |
-
|
1378 |
-
|
1379 |
-
|
1380 |
-
|
1381 |
-
|
1382 |
-
|
1383 |
-
|
1384 |
-
|
1385 |
-
|
1386 |
-
|
1387 |
-
|
1388 |
-
|
1389 |
-
|
1390 |
-
|
1391 |
-
|
1392 |
-
|
1393 |
-
|
1394 |
-
|
1395 |
-
|
1396 |
-
|
1397 |
-
|
1398 |
-
|
1399 |
-
|
1400 |
-
|
1401 |
-
|
1402 |
-
|
1403 |
-
|
1404 |
-
|
1405 |
-
|
1406 |
-
|
1407 |
-
|
1408 |
-
|
1409 |
-
|
1410 |
-
|
1411 |
-
|
1412 |
-
|
1413 |
-
|
1414 |
-
|
1415 |
-
|
1416 |
-
|
1417 |
-
|
1418 |
-
|
1419 |
-
|
1420 |
-
|
1421 |
-
|
1422 |
-
|
1423 |
-
|
1424 |
-
|
1425 |
-
|
1426 |
-
|
1427 |
-
|
1428 |
-
|
1429 |
-
|
1430 |
-
|
1431 |
-
|
1432 |
-
|
1433 |
-
|
1434 |
-
|
1435 |
-
|
1436 |
-
|
1437 |
-
|
1438 |
-
|
1439 |
-
|
1440 |
-
|
1441 |
-
|
1442 |
-
|
1443 |
-
|
1444 |
-
|
1445 |
-
|
1446 |
-
|
1447 |
-
|
1448 |
-
|
1449 |
-
|
1450 |
-
|
1451 |
-
|
1452 |
-
|
1453 |
-
|
1454 |
-
|
1455 |
-
|
1456 |
-
|
1457 |
-
|
1458 |
-
|
1459 |
-
|
1460 |
-
|
1461 |
-
|
1462 |
-
|
1463 |
-
|
1464 |
-
|
1465 |
-
|
1466 |
-
|
1467 |
-
|
1468 |
-
|
1469 |
-
|
1470 |
-
|
1471 |
-
|
1472 |
-
|
1473 |
-
|
1474 |
-
|
1475 |
-
|
1476 |
-
|
1477 |
-
|
1478 |
-
|
1479 |
-
|
1480 |
-
|
1481 |
-
|
1482 |
-
|
1483 |
-
|
1484 |
-
|
1485 |
-
|
1486 |
-
|
1487 |
-
|
1488 |
-
|
1489 |
-
|
1490 |
-
|
1491 |
-
|
1492 |
-
|
1493 |
-
|
1494 |
-
|
1495 |
-
|
1496 |
-
|
1497 |
-
|
1498 |
-
|
1499 |
-
|
1500 |
-
|
1501 |
-
|
1502 |
-
|
1503 |
-
|
1504 |
-
|
1505 |
-
|
1506 |
-
|
1507 |
-
|
1508 |
-
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
1509 |
Â
$image_watermark = Image_Watermark();
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Image Watermark
|
4 |
+
Description: Image Watermark allows you to automatically watermark images uploaded to the WordPress Media Library and bulk watermark previously uploaded images.
|
5 |
+
Version: 1.7.0
|
6 |
+
Author: dFactory
|
7 |
+
Author URI: https://dfactory.eu/
|
8 |
+
Plugin URI: https://dfactory.eu/plugins/image-watermark/
|
9 |
+
License: MIT License
|
10 |
+
License URI: http://opensource.org/licenses/MIT
|
11 |
+
Text Domain: image-watermark
|
12 |
+
Domain Path: /languages
|
13 |
+
|
14 |
+
Image Watermark
|
15 |
+
Copyright (C) 2013-2022, Digital Factory - info@digitalfactory.pl
|
16 |
+
|
17 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
18 |
+
|
19 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
20 |
+
|
21 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22 |
+
*/
|
23 |
+
|
24 |
+
// exit if accessed directly
|
25 |
+
if ( ! defined( 'ABSPATH' ) )
|
26 |
+
exit;
|
27 |
+
|
28 |
+
define( 'IMAGE_WATERMARK_URL', plugins_url( '', __FILE__ ) );
|
29 |
+
define( 'IMAGE_WATERMARK_PATH', plugin_dir_path( __FILE__ ) );
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Image Watermark class.
|
33 |
+
*
|
34 |
+
* @class Image_Watermark
|
35 |
+
* @version 1.7.0
|
36 |
+
*/
|
37 |
+
final class Image_Watermark {
|
38 |
+
|
39 |
+
private static $instance;
|
40 |
+
private $is_admin = true;
|
41 |
+
private $extension = false;
|
42 |
+
private $allowed_mime_types = array(
|
43 |
+
'image/jpeg',
|
44 |
+
'image/pjpeg',
|
45 |
+
'image/png'
|
46 |
+
);
|
47 |
+
private $is_watermarked_metakey = 'iw-is-watermarked';
|
48 |
+
public $is_backup_folder_writable = null;
|
49 |
+
public $extensions;
|
50 |
+
public $defaults = array(
|
51 |
+
'options' => array(
|
52 |
+
'watermark_on' => array(),
|
53 |
+
'watermark_cpt_on' => array( 'everywhere' ),
|
54 |
+
'watermark_image' => array(
|
55 |
+
'extension' => '',
|
56 |
+
'url' => 0,
|
57 |
+
'width' => 80,
|
58 |
+
'plugin_off' => 0,
|
59 |
+
'frontend_active' => false,
|
60 |
+
'manual_watermarking' => 0,
|
61 |
+
'position' => 'bottom_right',
|
62 |
+
'watermark_size_type' => 2,
|
63 |
+
'offset_unit' => 'pixels',
|
64 |
+
'offset_width' => 0,
|
65 |
+
'offset_height' => 0,
|
66 |
+
'absolute_width' => 0,
|
67 |
+
'absolute_height' => 0,
|
68 |
+
'transparent' => 50,
|
69 |
+
'quality' => 90,
|
70 |
+
'jpeg_format' => 'baseline',
|
71 |
+
'deactivation_delete' => false,
|
72 |
+
'media_library_notice' => true
|
73 |
+
),
|
74 |
+
'image_protection' => array(
|
75 |
+
'rightclick' => 0,
|
76 |
+
'draganddrop' => 0,
|
77 |
+
'forlogged' => 0
|
78 |
+
),
|
79 |
+
'backup' => array(
|
80 |
+
'backup_image' => true,
|
81 |
+
'backup_quality' => 90
|
82 |
+
)
|
83 |
+
),
|
84 |
+
'version' => '1.7.0'
|
85 |
+
);
|
86 |
+
public $options = array();
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Class constructor.
|
90 |
+
*
|
91 |
+
* @return void
|
92 |
+
*/
|
93 |
+
public function __construct() {
|
94 |
+
// installer
|
95 |
+
register_activation_hook( __FILE__, array( $this, 'activate_watermark' ) );
|
96 |
+
register_deactivation_hook( __FILE__, array( $this, 'deactivate_watermark' ) );
|
97 |
+
|
98 |
+
// settings
|
99 |
+
$options = get_option( 'image_watermark_options', $this->defaults['options'] );
|
100 |
+
|
101 |
+
$this->options = array_merge( $this->defaults['options'], $options );
|
102 |
+
$this->options['watermark_image'] = array_merge( $this->defaults['options']['watermark_image'], $options['watermark_image'] );
|
103 |
+
$this->options['image_protection'] = array_merge( $this->defaults['options']['image_protection'], $options['image_protection'] );
|
104 |
+
$this->options['backup'] = array_merge( $this->defaults['options']['backup'], isset( $options['backup'] ) ? $options['backup'] : array() );
|
105 |
+
|
106 |
+
include_once( IMAGE_WATERMARK_PATH . 'includes/class-update.php' );
|
107 |
+
include_once( IMAGE_WATERMARK_PATH . 'includes/class-settings.php' );
|
108 |
+
|
109 |
+
// actions
|
110 |
+
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
|
111 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
|
112 |
+
add_action( 'admin_print_scripts', array( $this, 'admin_print_scripts' ), 20 );
|
113 |
+
add_action( 'wp_enqueue_media', array( $this, 'wp_enqueue_media' ) );
|
114 |
+
add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) );
|
115 |
+
add_action( 'load-upload.php', array( $this, 'watermark_bulk_action' ) );
|
116 |
+
add_action( 'admin_init', array( $this, 'update_plugin' ) );
|
117 |
+
add_action( 'admin_init', array( $this, 'check_extensions' ) );
|
118 |
+
add_action( 'admin_notices', array( $this, 'bulk_admin_notices' ) );
|
119 |
+
add_action( 'delete_attachment', array( $this, 'delete_attachment' ) );
|
120 |
+
add_action( 'wp_ajax_iw_watermark_bulk_action', array( $this, 'watermark_action_ajax' ) );
|
121 |
+
|
122 |
+
// filters
|
123 |
+
add_filter( 'plugin_row_meta', array( $this, 'plugin_extend_links' ), 10, 2 );
|
124 |
+
add_filter( 'plugin_action_links', array( $this, 'plugin_settings_link' ), 10, 2 );
|
125 |
+
add_filter( 'wp_handle_upload', array( $this, 'handle_upload_files' ) );
|
126 |
+
add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 );
|
127 |
+
|
128 |
+
// define our backup location
|
129 |
+
$upload_dir = wp_upload_dir();
|
130 |
+
define( 'IMAGE_WATERMARK_BACKUP_DIR', apply_filters( 'image_watermark_backup_dir', $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'iw-backup' ) );
|
131 |
+
|
132 |
+
// create backup folder and security if enabled
|
133 |
+
if ( $this->options['backup']['backup_image'] ) {
|
134 |
+
if ( is_writable( $upload_dir['basedir'] ) ) {
|
135 |
+
$this->is_backup_folder_writable = true;
|
136 |
+
|
137 |
+
// create backup folder ( if it exists this returns true: https://codex.wordpress.org/Function_Reference/wp_mkdir_p )
|
138 |
+
$backup_folder_created = wp_mkdir_p( IMAGE_WATERMARK_BACKUP_DIR );
|
139 |
+
|
140 |
+
// check if the folder exists and is writable
|
141 |
+
if ( $backup_folder_created && is_writable( IMAGE_WATERMARK_BACKUP_DIR ) ) {
|
142 |
+
// check if the htaccess file exists
|
143 |
+
if ( ! file_exists( IMAGE_WATERMARK_BACKUP_DIR . DIRECTORY_SEPARATOR . '.htaccess' ) ) {
|
144 |
+
// htaccess security
|
145 |
+
file_put_contents( IMAGE_WATERMARK_BACKUP_DIR . DIRECTORY_SEPARATOR . '.htaccess', 'deny from all' );
|
146 |
+
}
|
147 |
+
} else
|
148 |
+
$this->is_backup_folder_writable = false;
|
149 |
+
} else
|
150 |
+
$this->is_backup_folder_writable = false;
|
151 |
+
|
152 |
+
if ( $this->is_backup_folder_writable !== true ) {
|
153 |
+
// disable backup setting
|
154 |
+
$this->options['backup']['backup_image'] = false;
|
155 |
+
update_option( 'image_watermark_options', $this->options );
|
156 |
+
}
|
157 |
+
|
158 |
+
add_action( 'admin_notices', array( $this, 'folder_writable_admin_notice' ) );
|
159 |
+
}
|
160 |
+
}
|
161 |
+
|
162 |
+
/**
|
163 |
+
* Disable object cloning.
|
164 |
+
*
|
165 |
+
* @return void
|
166 |
+
*/
|
167 |
+
public function __clone() {}
|
168 |
+
|
169 |
+
/**
|
170 |
+
* Disable unserializing of the class.
|
171 |
+
*
|
172 |
+
* @return void
|
173 |
+
*/
|
174 |
+
public function __wakeup() {}
|
175 |
+
|
176 |
+
/**
|
177 |
+
* Create single instance.
|
178 |
+
*
|
179 |
+
* @return object Main plugin instance
|
180 |
+
*/
|
181 |
+
public static function instance() {
|
182 |
+
if ( self::$instance === null )
|
183 |
+
self::$instance = new self();
|
184 |
+
|
185 |
+
return self::$instance;
|
186 |
+
}
|
187 |
+
|
188 |
+
/**
|
189 |
+
* Plugin activation.
|
190 |
+
*
|
191 |
+
* @return void
|
192 |
+
*/
|
193 |
+
public function activate_watermark() {
|
194 |
+
add_option( 'image_watermark_options', $this->defaults['options'], '', 'no' );
|
195 |
+
add_option( 'image_watermark_version', $this->defaults['version'], '', 'no' );
|
196 |
+
}
|
197 |
+
|
198 |
+
/**
|
199 |
+
* Plugin deactivation.
|
200 |
+
*
|
201 |
+
* @return void
|
202 |
+
*/
|
203 |
+
public function deactivate_watermark() {
|
204 |
+
// remove options from database?
|
205 |
+
if ( $this->options['watermark_image']['deactivation_delete'] )
|
206 |
+
delete_option( 'image_watermark_options' );
|
207 |
+
}
|
208 |
+
|
209 |
+
/**
|
210 |
+
* Plugin update, fix for version < 1.5.0.
|
211 |
+
*
|
212 |
+
* @return void
|
213 |
+
*/
|
214 |
+
public function update_plugin() {
|
215 |
+
if ( ! current_user_can( 'install_plugins' ) )
|
216 |
+
return;
|
217 |
+
|
218 |
+
$db_version = get_option( 'image_watermark_version' );
|
219 |
+
$db_version = ! ( $db_version ) && ( get_option( 'df_watermark_installed' ) != false ) ? get_option( 'version' ) : $db_version;
|
220 |
+
|
221 |
+
if ( $db_version != false ) {
|
222 |
+
if ( version_compare( $db_version, '1.5.0', '<' ) ) {
|
223 |
+
$options = array();
|
224 |
+
|
225 |
+
$old_new = array(
|
226 |
+
'df_watermark_on' => 'watermark_on',
|
227 |
+
'df_watermark_cpt_on' => 'watermark_cpt_on',
|
228 |
+
'df_watermark_image' => 'watermark_image',
|
229 |
+
'df_image_protection' => 'image_protection',
|
230 |
+
'df_watermark_installed' => '',
|
231 |
+
'version' => '',
|
232 |
+
'image_watermark_version' => '',
|
233 |
+
);
|
234 |
+
|
235 |
+
foreach ( $old_new as $old => $new ) {
|
236 |
+
if ( $new ) {
|
237 |
+
$options[$new] = get_option( $old );
|
238 |
+
}
|
239 |
+
delete_option( $old );
|
240 |
+
}
|
241 |
+
|
242 |
+
add_option( 'image_watermark_options', $options, '', 'no' );
|
243 |
+
add_option( 'image_watermark_version', $this->defaults['version'], '', 'no' );
|
244 |
+
}
|
245 |
+
}
|
246 |
+
}
|
247 |
+
|
248 |
+
/**
|
249 |
+
* Load textdomain.
|
250 |
+
*
|
251 |
+
* @return void
|
252 |
+
*/
|
253 |
+
public function load_textdomain() {
|
254 |
+
load_plugin_textdomain( 'image-watermark', false, basename( dirname( __FILE__ ) ) . '/languages' );
|
255 |
+
}
|
256 |
+
|
257 |
+
/**
|
258 |
+
* Admin inline scripts.
|
259 |
+
*
|
260 |
+
* @global $pagenow
|
261 |
+
* @return void
|
262 |
+
*/
|
263 |
+
public function admin_print_scripts() {
|
264 |
+
global $pagenow;
|
265 |
+
|
266 |
+
if ( $pagenow === 'upload.php' ) {
|
267 |
+
if ( $this->options['watermark_image']['manual_watermarking'] == 1 ) {
|
268 |
+
?>
|
269 |
+
<script type="text/javascript">
|
270 |
+
jQuery( function( $ ) {
|
271 |
+
$( document ).ready( function() {
|
272 |
+
var backup = <?php echo (int) $this->options['backup']['backup_image']; ?>;
|
273 |
+
|
274 |
+
$( "<option>" ).val( "applywatermark" ).text( "<?php _e( 'Apply watermark', 'image-watermark' ); ?>" ).appendTo( "select[name='action'], select[name='action2']" );
|
275 |
+
|
276 |
+
if ( backup === 1 ) {
|
277 |
+
$( "<option>" ).val( "removewatermark" ).text( "<?php _e( 'Remove watermark', 'image-watermark' ); ?>" ).appendTo( "select[name='action'], select[name='action2']" );
|
278 |
+
}
|
279 |
+
});
|
280 |
+
});
|
281 |
+
</script>
|
282 |
+
<?php
|
283 |
+
}
|
284 |
+
}
|
285 |
+
}
|
286 |
+
|
287 |
+
/**
|
288 |
+
* Enqueue admin scripts and styles.
|
289 |
+
*
|
290 |
+
* @return void
|
291 |
+
*/
|
292 |
+
public function wp_enqueue_media( $page ) {
|
293 |
+
wp_enqueue_style( 'watermark-style', plugins_url( 'css/image-watermark.css', __FILE__ ), array(), $this->defaults['version'] );
|
294 |
+
}
|
295 |
+
|
296 |
+
/**
|
297 |
+
* Enqueue admin scripts and styles.
|
298 |
+
*
|
299 |
+
* @global $pagenow
|
300 |
+
* @return void
|
301 |
+
*/
|
302 |
+
public function admin_enqueue_scripts( $page ) {
|
303 |
+
global $pagenow;
|
304 |
+
|
305 |
+
wp_register_style( 'watermark-style', plugins_url( 'css/image-watermark.css', __FILE__ ), array(), $this->defaults['version'] );
|
306 |
+
|
307 |
+
if ( $page === 'settings_page_watermark-options' ) {
|
308 |
+
wp_enqueue_media();
|
309 |
+
|
310 |
+
wp_enqueue_script( 'upload-manager', plugins_url( '/js/admin-upload.js', __FILE__ ), array(), $this->defaults['version'] );
|
311 |
+
|
312 |
+
wp_localize_script(
|
313 |
+
'upload-manager',
|
314 |
+
'iwUploadArgs',
|
315 |
+
array(
|
316 |
+
'title' => __( 'Select watermark', 'image-watermark' ),
|
317 |
+
'originalSize' => __( 'Original size', 'image-watermark' ),
|
318 |
+
'noSelectedImg' => __( 'Watermak has not been selected yet.', 'image-watermark' ),
|
319 |
+
'notAllowedImg' => __( 'This image is not supported as watermark. Use JPEG, PNG or GIF.', 'image-watermark' ),
|
320 |
+
'px' => __( 'px', 'image-watermark' ),
|
321 |
+
'frame' => 'select',
|
322 |
+
'button' => array( 'text' => __( 'Add watermark', 'image-watermark' ) ),
|
323 |
+
'multiple' => false
|
324 |
+
)
|
325 |
+
);
|
326 |
+
|
327 |
+
wp_enqueue_script( 'watermark-admin-script', plugins_url( 'js/admin-settings.js', __FILE__ ), array( 'jquery', 'jquery-ui-core', 'jquery-ui-button', 'jquery-ui-slider' ), $this->defaults['version'] );
|
328 |
+
|
329 |
+
wp_localize_script(
|
330 |
+
'watermark-admin-script',
|
331 |
+
'iwArgs',
|
332 |
+
array(
|
333 |
+
'resetToDefaults' => __( 'Are you sure you want to reset settings to defaults?', 'image-watermark' )
|
334 |
+
)
|
335 |
+
);
|
336 |
+
|
337 |
+
wp_enqueue_style( 'wp-like-ui-theme', plugins_url( 'css/wp-like-ui-theme.css', __FILE__ ), array(), $this->defaults['version'] );
|
338 |
+
wp_enqueue_style( 'watermark-style' );
|
339 |
+
|
340 |
+
wp_enqueue_script( 'postbox' );
|
341 |
+
}
|
342 |
+
|
343 |
+
if ( $pagenow === 'upload.php' )
|
344 |
+
wp_enqueue_style( 'watermark-style' );
|
345 |
+
|
346 |
+
// image modal could be loaded in various places
|
347 |
+
if ( $this->options['watermark_image']['manual_watermarking'] == 1 ) {
|
348 |
+
wp_enqueue_script( 'watermark-admin-image-actions', plugins_url( '/js/admin-image-actions.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], true );
|
349 |
+
|
350 |
+
wp_localize_script(
|
351 |
+
'watermark-admin-image-actions',
|
352 |
+
'iwImageActionArgs',
|
353 |
+
array(
|
354 |
+
'backup_image' => (int) $this->options['backup']['backup_image'],
|
355 |
+
'_nonce' => wp_create_nonce( 'image-watermark' ),
|
356 |
+
'__applied_none' => __( 'Watermark could not be applied to selected files or no valid images (JPEG, PNG) were selected.', 'image-watermark' ),
|
357 |
+
'__applied_one' => __( 'Watermark was succesfully applied to 1 image.', 'image-watermark' ),
|
358 |
+
'__applied_multi' => __( 'Watermark was succesfully applied to %s images.', 'image-watermark' ),
|
359 |
+
'__removed_none' => __( 'Watermark could not be removed from selected files or no valid images (JPEG, PNG) were selected.', 'image-watermark' ),
|
360 |
+
'__removed_one' => __( 'Watermark was succesfully removed from 1 image.', 'image-watermark' ),
|
361 |
+
'__removed_multi' => __( 'Watermark was succesfully removed from %s images.', 'image-watermark' ),
|
362 |
+
'__skipped' => __( 'Skipped files', 'image-watermark' ),
|
363 |
+
'__running' => __( 'Bulk action is currently running, please wait.', 'image-watermark' ),
|
364 |
+
'__dismiss' => __( 'Dismiss this notice.' ) // WordPress default string
|
365 |
+
)
|
366 |
+
);
|
367 |
+
}
|
368 |
+
}
|
369 |
+
|
370 |
+
/**
|
371 |
+
* Enqueue frontend script with 'no right click' and 'drag and drop' functions.
|
372 |
+
*
|
373 |
+
* @return void
|
374 |
+
*/
|
375 |
+
public function wp_enqueue_scripts() {
|
376 |
+
$right_click = true;
|
377 |
+
|
378 |
+
if ( ($this->options['image_protection']['forlogged'] == 0 && is_user_logged_in()) || ($this->options['image_protection']['draganddrop'] == 0 && $this->options['image_protection']['rightclick'] == 0) )
|
379 |
+
$right_click = false;
|
380 |
+
|
381 |
+
if ( apply_filters( 'iw_block_right_click', (bool) $right_click ) === true ) {
|
382 |
+
wp_enqueue_script( 'iw-no-right-click', plugins_url( 'js/no-right-click.js', __FILE__ ), array(), $this->defaults['version'] );
|
383 |
+
|
384 |
+
wp_localize_script(
|
385 |
+
'iw-no-right-click',
|
386 |
+
'IwNRCargs',
|
387 |
+
array(
|
388 |
+
'rightclick' => ( $this->options['image_protection']['rightclick'] == 1 ? 'Y' : 'N' ),
|
389 |
+
'draganddrop' => ( $this->options['image_protection']['draganddrop'] == 1 ? 'Y' : 'N' )
|
390 |
+
)
|
391 |
+
);
|
392 |
+
}
|
393 |
+
}
|
394 |
+
|
395 |
+
/**
|
396 |
+
* Check which extension is available and set it.
|
397 |
+
*
|
398 |
+
* @return void
|
399 |
+
*/
|
400 |
+
public function check_extensions() {
|
401 |
+
$ext = null;
|
402 |
+
|
403 |
+
if ( $this->check_imagick() ) {
|
404 |
+
$this->extensions['imagick'] = 'ImageMagick';
|
405 |
+
$ext = 'imagick';
|
406 |
+
}
|
407 |
+
|
408 |
+
if ( $this->check_gd() ) {
|
409 |
+
$this->extensions['gd'] = 'GD';
|
410 |
+
|
411 |
+
if ( is_null( $ext ) )
|
412 |
+
$ext = 'gd';
|
413 |
+
}
|
414 |
+
|
415 |
+
if ( isset( $this->options['watermark_image']['extension'] ) ) {
|
416 |
+
if ( $this->options['watermark_image']['extension'] === 'imagick' && isset( $this->extensions['imagick'] ) )
|
417 |
+
$this->extension = 'imagick';
|
418 |
+
elseif ( $this->options['watermark_image']['extension'] === 'gd' && isset( $this->extensions['gd'] ) )
|
419 |
+
$this->extension = 'gd';
|
420 |
+
else
|
421 |
+
$this->extension = $ext;
|
422 |
+
} else
|
423 |
+
$this->extension = $ext;
|
424 |
+
}
|
425 |
+
|
426 |
+
/**
|
427 |
+
* Apply watermark everywhere or for specific post types.
|
428 |
+
*
|
429 |
+
* @param resource $file
|
430 |
+
* @return resource
|
431 |
+
*/
|
432 |
+
public function handle_upload_files( $file ) {
|
433 |
+
// is extension available?
|
434 |
+
if ( $this->extension ) {
|
435 |
+
// determine ajax frontend or backend request
|
436 |
+
$script_filename = isset( $_SERVER['SCRIPT_FILENAME'] ) ? $_SERVER['SCRIPT_FILENAME'] : '';
|
437 |
+
|
438 |
+
// try to figure out if frontend AJAX request... if we are DOING_AJAX; let's look closer
|
439 |
+
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
|
440 |
+
// from wp-includes/functions.php, wp_get_referer() function.
|
441 |
+
// required to fix: https://core.trac.wordpress.org/ticket/25294
|
442 |
+
$ref = '';
|
443 |
+
|
444 |
+
if ( ! empty( $_REQUEST['_wp_http_referer'] ) )
|
445 |
+
$ref = wp_unslash( $_REQUEST['_wp_http_referer'] );
|
446 |
+
elseif ( ! empty( $_SERVER['HTTP_REFERER'] ) )
|
447 |
+
$ref = wp_unslash( $_SERVER['HTTP_REFERER'] );
|
448 |
+
|
449 |
+
// if referer does not contain admin URL and we are using the admin-ajax.php endpoint, this is likely a frontend AJAX request
|
450 |
+
if ( ( ( strpos( $ref, admin_url() ) === false ) && ( basename( $script_filename ) === 'admin-ajax.php' ) ) )
|
451 |
+
$this->is_admin = false;
|
452 |
+
else
|
453 |
+
$this->is_admin = true;
|
454 |
+
// not an AJAX request, simple here
|
455 |
+
} else {
|
456 |
+
if ( is_admin() )
|
457 |
+
$this->is_admin = true;
|
458 |
+
else
|
459 |
+
$this->is_admin = false;
|
460 |
+
}
|
461 |
+
|
462 |
+
// admin
|
463 |
+
if ( $this->is_admin === true ) {
|
464 |
+
if ( $this->options['watermark_image']['plugin_off'] == 1 && wp_attachment_is_image( $this->options['watermark_image']['url'] ) && in_array( $file['type'], $this->allowed_mime_types ) )
|
465 |
+
add_filter( 'wp_generate_attachment_metadata', array( $this, 'apply_watermark' ), 10, 2 );
|
466 |
+
// frontend
|
467 |
+
} else {
|
468 |
+
if ( $this->options['watermark_image']['frontend_active'] == 1 && wp_attachment_is_image( $this->options['watermark_image']['url'] ) && in_array( $file['type'], $this->allowed_mime_types ) )
|
469 |
+
add_filter( 'wp_generate_attachment_metadata', array( $this, 'apply_watermark' ), 10, 2 );
|
470 |
+
}
|
471 |
+
}
|
472 |
+
|
473 |
+
return $file;
|
474 |
+
}
|
475 |
+
|
476 |
+
/**
|
477 |
+
* Add watermark buttons on attachment image locations.
|
478 |
+
*
|
479 |
+
* @param array $form_fields
|
480 |
+
* @param object $post
|
481 |
+
* return array
|
482 |
+
*/
|
483 |
+
public function attachment_fields_to_edit( $form_fields, $post ) {
|
484 |
+
if ( $this->options['watermark_image']['manual_watermarking'] == 1 && $this->options['backup']['backup_image'] ) {
|
485 |
+
$data = wp_get_attachment_metadata( $post->ID, false );
|
486 |
+
|
487 |
+
// is this really an image?
|
488 |
+
if ( in_array( get_post_mime_type( $post->ID ), $this->allowed_mime_types ) && is_array( $data ) ) {
|
489 |
+
$form_fields['image_watermark'] = array(
|
490 |
+
'show_in_edit' => false,
|
491 |
+
'tr' => '
|
492 |
+
<div id="image_watermark_buttons"' . ( get_post_meta( $post->ID, $this->is_watermarked_metakey, true ) ? ' class="watermarked"' : '' ) . ' data-id="' . $post->ID . '" style="display: none;">
|
493 |
+
<label class="setting">
|
494 |
+
<span class="name">' . __( 'Image Watermark', 'image-watermark' ) . '</span>
|
495 |
+
<span class="value" style="width: 63%"><a href="#" class="iw-watermark-action" data-action="applywatermark" data-id="' . $post->ID . '">' . __( 'Apply watermark', 'image-watermark' ) . '</a> | <a href="#" class="iw-watermark-action delete-watermark" data-action="removewatermark" data-id="' . $post->ID . '">' . __( 'Remove watermark', 'image-watermark' ) . '</a></span>
|
496 |
+
</label>
|
497 |
+
<div class="clear"></div>
|
498 |
+
</div>
|
499 |
+
<script>
|
500 |
+
jQuery( document ).ready( function( $ ) {
|
501 |
+
if ( typeof watermarkImageActions !== "undefined" ) {
|
502 |
+
$( "#image_watermark_buttons" ).show();
|
503 |
+
}
|
504 |
+
} );
|
505 |
+
</script>'
|
506 |
+
);
|
507 |
+
}
|
508 |
+
}
|
509 |
+
|
510 |
+
return $form_fields;
|
511 |
+
}
|
512 |
+
|
513 |
+
/**
|
514 |
+
* Apply watermark for selected images on media page.
|
515 |
+
*
|
516 |
+
* @return void
|
517 |
+
*/
|
518 |
+
public function watermark_action_ajax() {
|
519 |
+
// Security & data check
|
520 |
+
if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || ! isset( $_POST['_iw_nonce'] ) || ! isset( $_POST['iw-action'] ) || ! isset( $_POST['attachment_id'] ) || ! is_numeric( $_POST['attachment_id'] ) || ! wp_verify_nonce( $_POST['_iw_nonce'], 'image-watermark' ) )
|
521 |
+
wp_send_json_error( __( 'Cheatin uh?', 'image-watermark' ) );
|
522 |
+
|
523 |
+
$post_id = (int) $_POST['attachment_id'];
|
524 |
+
$action = in_array( $_POST['iw-action'], array( 'applywatermark', 'removewatermark' ), true ) ? $_POST['iw-action'] : false;
|
525 |
+
|
526 |
+
// only if manual watermarking is turned and we have a valid action
|
527 |
+
// if the action is NOT "removewatermark" we also require a watermark image to be set
|
528 |
+
if ( $post_id > 0 && $action && $this->options['watermark_image']['manual_watermarking'] == 1 && ( wp_attachment_is_image( $this->options['watermark_image']['url'] ) || $action == 'removewatermark' ) ) {
|
529 |
+
$data = wp_get_attachment_metadata( $post_id, false );
|
530 |
+
|
531 |
+
// is this really an image?
|
532 |
+
if ( in_array( get_post_mime_type( $post_id ), $this->allowed_mime_types ) && is_array( $data ) ) {
|
533 |
+
if ( $action === 'applywatermark' ) {
|
534 |
+
$success = $this->apply_watermark( $data, $post_id, 'manual' );
|
535 |
+
|
536 |
+
if ( ! empty( $success['error'] ) )
|
537 |
+
wp_send_json_success( $success['error'] );
|
538 |
+
else
|
539 |
+
wp_send_json_success( 'watermarked' );
|
540 |
+
} elseif ( $action === 'removewatermark' ) {
|
541 |
+
$success = $this->remove_watermark( $data, $post_id, 'manual' );
|
542 |
+
|
543 |
+
if ( $success )
|
544 |
+
wp_send_json_success( 'watermarkremoved' );
|
545 |
+
else
|
546 |
+
wp_send_json_success( 'skipped' );
|
547 |
+
}
|
548 |
+
} else
|
549 |
+
wp_send_json_success( 'skipped' );
|
550 |
+
}
|
551 |
+
|
552 |
+
wp_send_json_error( __( 'Cheatin uh?', 'image-watermark' ) );
|
553 |
+
}
|
554 |
+
|
555 |
+
/**
|
556 |
+
* Apply watermark for selected images on media page.
|
557 |
+
*
|
558 |
+
* @return void
|
559 |
+
*/
|
560 |
+
public function watermark_bulk_action() {
|
561 |
+
global $pagenow;
|
562 |
+
|
563 |
+
if ( $pagenow == 'upload.php' && $this->extension ) {
|
564 |
+
$wp_list_table = _get_list_table( 'WP_Media_List_Table' );
|
565 |
+
$action = $wp_list_table->current_action();
|
566 |
+
$action = in_array( $action, array( 'applywatermark', 'removewatermark' ), true ) ? $action : false;
|
567 |
+
|
568 |
+
// only if manual watermarking is turned and we have a valid action
|
569 |
+
// if the action is NOT "removewatermark" we also require a watermark image to be set
|
570 |
+
if ( $action && $this->options['watermark_image']['manual_watermarking'] == 1 && ( wp_attachment_is_image( $this->options['watermark_image']['url'] ) || $action == 'removewatermark' ) ) {
|
571 |
+
// security check
|
572 |
+
check_admin_referer( 'bulk-media' );
|
573 |
+
|
574 |
+
$location = esc_url( remove_query_arg( array( 'watermarked', 'watermarkremoved', 'skipped', 'trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted' ), wp_get_referer() ) );
|
575 |
+
|
576 |
+
if ( ! $location )
|
577 |
+
$location = 'upload.php';
|
578 |
+
|
579 |
+
$location = esc_url( add_query_arg( 'paged', $wp_list_table->get_pagenum(), $location ) );
|
580 |
+
|
581 |
+
// make sure ids are submitted. depending on the resource type, this may be 'media' or 'ids'
|
582 |
+
if ( isset( $_REQUEST['media'] ) )
|
583 |
+
$post_ids = array_map( 'intval', $_REQUEST['media'] );
|
584 |
+
|
585 |
+
// do we have selected attachments?
|
586 |
+
if ( $post_ids ) {
|
587 |
+
$watermarked = $watermarkremoved = $skipped = 0;
|
588 |
+
$messages = array();
|
589 |
+
|
590 |
+
foreach ( $post_ids as $post_id ) {
|
591 |
+
$data = wp_get_attachment_metadata( $post_id, false );
|
592 |
+
|
593 |
+
// is this really an image?
|
594 |
+
if ( in_array( get_post_mime_type( $post_id ), $this->allowed_mime_types ) && is_array( $data ) ) {
|
595 |
+
if ( $action === 'applywatermark' ) {
|
596 |
+
$success = $this->apply_watermark( $data, $post_id, 'manual' );
|
597 |
+
if ( ! empty( $success['error'] ) )
|
598 |
+
$messages[] = $success['error'];
|
599 |
+
else {
|
600 |
+
$watermarked++;
|
601 |
+
$watermarkremoved = -1;
|
602 |
+
}
|
603 |
+
} elseif ( $action === 'removewatermark' ) {
|
604 |
+
$success = $this->remove_watermark( $data, $post_id, 'manual' );
|
605 |
+
|
606 |
+
if ( $success )
|
607 |
+
$watermarkremoved++;
|
608 |
+
else
|
609 |
+
$skipped++;
|
610 |
+
|
611 |
+
$watermarked = -1;
|
612 |
+
}
|
613 |
+
} else
|
614 |
+
$skipped++;
|
615 |
+
}
|
616 |
+
|
617 |
+
$location = esc_url( add_query_arg( array( 'watermarked' => $watermarked, 'watermarkremoved' => $watermarkremoved, 'skipped' => $skipped, 'messages' => $messages ), $location ), null, '' );
|
618 |
+
}
|
619 |
+
|
620 |
+
wp_redirect( $location );
|
621 |
+
exit();
|
622 |
+
} else
|
623 |
+
return;
|
624 |
+
}
|
625 |
+
}
|
626 |
+
|
627 |
+
/**
|
628 |
+
* Display admin notices.
|
629 |
+
*
|
630 |
+
* @return void
|
631 |
+
*/
|
632 |
+
public function bulk_admin_notices() {
|
633 |
+
global $post_type, $pagenow;
|
634 |
+
|
635 |
+
if ( $pagenow === 'upload.php' ) {
|
636 |
+
if ( ! current_user_can( 'upload_files' ) )
|
637 |
+
return;
|
638 |
+
|
639 |
+
// hide media library notice
|
640 |
+
if ( isset( $_GET['iw_action'] ) && $_GET['iw_action'] == 'hide_library_notice' ) {
|
641 |
+
$this->options['watermark_image']['media_library_notice'] = false;
|
642 |
+
|
643 |
+
update_option( 'image_watermark_options', $this->options );
|
644 |
+
}
|
645 |
+
|
646 |
+
// check if manual watermarking is enabled
|
647 |
+
if ( ! empty( $this->options['watermark_image']['manual_watermarking'] ) && ( ! isset( $this->options['watermark_image']['media_library_notice'] ) || $this->options['watermark_image']['media_library_notice'] === true ) ) {
|
648 |
+
$mode = get_user_option( 'media_library_mode', get_current_user_id() ) ? get_user_option( 'media_library_mode', get_current_user_id() ) : 'grid';
|
649 |
+
|
650 |
+
if ( isset( $_GET['mode'] ) && in_array( $_GET['mode'], array( 'grid', 'list' ) ) )
|
651 |
+
$mode = $_GET['mode'];
|
652 |
+
|
653 |
+
// display notice in grid mode only
|
654 |
+
if ( $mode === 'grid' ) {
|
655 |
+
// get current admin url
|
656 |
+
$query_string = array();
|
657 |
+
|
658 |
+
parse_str( $_SERVER['QUERY_STRING'], $query_string );
|
659 |
+
|
660 |
+
$current_url = esc_url( add_query_arg( array_merge( (array) $query_string, array( 'iw_action' => 'hide_library_notice' ) ), '', admin_url( trailingslashit( $pagenow ) ) ) );
|
661 |
+
|
662 |
+
echo '<div class="error notice"><p>' . sprintf( __( '<strong>Image Watermark:</strong> Bulk watermarking is available in list mode only, under <em>Bulk Actions</em> dropdown. <a href="%1$s">Got to List Mode</a> or <a href="%2$s">Hide this notice</a>', 'image-watermark' ), esc_url( admin_url( 'upload.php?mode=list' ) ), esc_url( $current_url ) ) . '</p></div>';
|
663 |
+
}
|
664 |
+
}
|
665 |
+
|
666 |
+
if ( isset( $_REQUEST['watermarked'], $_REQUEST['watermarkremoved'], $_REQUEST['skipped'] ) && $post_type === 'attachment' ) {
|
667 |
+
$watermarked = (int) $_REQUEST['watermarked'];
|
668 |
+
$watermarkremoved = (int) $_REQUEST['watermarkremoved'];
|
669 |
+
$skipped = (int) $_REQUEST['skipped'];
|
670 |
+
|
671 |
+
if ( $watermarked === 0 )
|
672 |
+
echo '<div class="error"><p>' . __( 'Watermark could not be applied to selected files or no valid images (JPEG, PNG) were selected.', 'image-watermark' ) . ($skipped > 0 ? ' ' . __( 'Images skipped', 'image-watermark' ) . ': ' . $skipped . '.' : '') . '</p></div>';
|
673 |
+
elseif ( $watermarked > 0 )
|
674 |
+
echo '<div class="updated"><p>' . sprintf( _n( 'Watermark was succesfully applied to 1 image.', 'Watermark was succesfully applied to %s images.', $watermarked, 'image-watermark' ), number_format_i18n( $watermarked ) ) . ($skipped > 0 ? ' ' . __( 'Skipped files', 'image-watermark' ) . ': ' . $skipped . '.' : '') . '</p></div>';
|
675 |
+
|
676 |
+
if ( $watermarkremoved === 0 )
|
677 |
+
echo '<div class="error"><p>' . __( 'Watermark could not be removed from selected files or no valid images (JPEG, PNG) were selected.', 'image-watermark' ) . ($skipped > 0 ? ' ' . __( 'Images skipped', 'image-watermark' ) . ': ' . $skipped . '.' : '') . '</p></div>';
|
678 |
+
elseif ( $watermarkremoved > 0 )
|
679 |
+
echo '<div class="updated"><p>' . sprintf( _n( 'Watermark was succesfully removed from 1 image.', 'Watermark was succesfully removed from %s images.', $watermarkremoved, 'image-watermark' ), number_format_i18n( $watermarkremoved ) ) . ($skipped > 0 ? ' ' . __( 'Skipped files', 'image-watermark' ) . ': ' . $skipped . '.' : '') . '</p></div>';
|
680 |
+
|
681 |
+
$_SERVER['REQUEST_URI'] = esc_url( remove_query_arg( array( 'watermarked', 'skipped' ), $_SERVER['REQUEST_URI'] ) );
|
682 |
+
}
|
683 |
+
}
|
684 |
+
}
|
685 |
+
|
686 |
+
/**
|
687 |
+
* Check whether ImageMagick extension is available.
|
688 |
+
*
|
689 |
+
* @return bool
|
690 |
+
*/
|
691 |
+
public function check_imagick() {
|
692 |
+
// check Imagick's extension and classes
|
693 |
+
if ( ! extension_loaded( 'imagick' ) || ! class_exists( 'Imagick', false ) || ! class_exists( 'ImagickPixel', false ) )
|
694 |
+
return false;
|
695 |
+
|
696 |
+
// check version
|
697 |
+
if ( version_compare( phpversion( 'imagick' ), '2.2.0', '<' ) )
|
698 |
+
return false;
|
699 |
+
|
700 |
+
// check for deep requirements within Imagick
|
701 |
+
if ( ! defined( 'imagick::COMPRESSION_JPEG' ) || ! defined( 'imagick::COMPOSITE_OVERLAY' ) || ! defined( 'Imagick::INTERLACE_PLANE' ) || ! defined( 'imagick::FILTER_CATROM' ) || ! defined( 'Imagick::CHANNEL_ALL' ) )
|
702 |
+
return false;
|
703 |
+
|
704 |
+
// check methods
|
705 |
+
if ( array_diff( array( 'clear', 'destroy', 'valid', 'getimage', 'writeimage', 'getimagegeometry', 'getimageformat', 'setimageformat', 'setimagecompression', 'setimagecompressionquality', 'scaleimage' ), get_class_methods( 'Imagick' ) ) )
|
706 |
+
return false;
|
707 |
+
|
708 |
+
return true;
|
709 |
+
}
|
710 |
+
|
711 |
+
/**
|
712 |
+
* Check whether GD extension is available.
|
713 |
+
*
|
714 |
+
* @return bool
|
715 |
+
*/
|
716 |
+
public function check_gd( $args = array() ) {
|
717 |
+
// check extension
|
718 |
+
if ( ! extension_loaded( 'gd' ) || ! function_exists( 'gd_info' ) )
|
719 |
+
return false;
|
720 |
+
|
721 |
+
return true;
|
722 |
+
}
|
723 |
+
|
724 |
+
/**
|
725 |
+
* Apply watermark to selected image sizes.
|
726 |
+
*
|
727 |
+
* @param array $data
|
728 |
+
* @param int|string $attachment_id Attachment ID
|
729 |
+
* @param string $method
|
730 |
+
* @return array
|
731 |
+
*/
|
732 |
+
public function apply_watermark( $data, $attachment_id, $method = '' ) {
|
733 |
+
$attachment_id = (int) $attachment_id;
|
734 |
+
$post = get_post( $attachment_id );
|
735 |
+
$post_id = ( ! empty( $post ) ? (int) $post->post_parent : 0 );
|
736 |
+
|
737 |
+
if ( $attachment_id === (int) $this->options['watermark_image']['url'] ) {
|
738 |
+
// this is the current watermark, do not apply
|
739 |
+
return array( 'error' => __( 'Watermark prevented, this is your selected watermark image', 'image-watermark' ) );
|
740 |
+
}
|
741 |
+
|
742 |
+
// something went wrong or is it automatic mode?
|
743 |
+
if ( $method !== 'manual' && ( $this->is_admin === true && ! ( ( isset( $this->options['watermark_cpt_on'][0] ) && $this->options['watermark_cpt_on'][0] === 'everywhere' ) || ( $post_id > 0 && in_array( get_post_type( $post_id ), array_keys( $this->options['watermark_cpt_on'] ) ) === true ) ) ) )
|
744 |
+
return $data;
|
745 |
+
|
746 |
+
if ( apply_filters( 'iw_watermark_display', $attachment_id ) === false )
|
747 |
+
return $data;
|
748 |
+
|
749 |
+
// get upload dir data
|
750 |
+
$upload_dir = wp_upload_dir();
|
751 |
+
|
752 |
+
// assign original (full) file
|
753 |
+
$original_file = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $data['file'];
|
754 |
+
|
755 |
+
// is this really an image?
|
756 |
+
if ( getimagesize( $original_file, $original_image_info ) !== false ) {
|
757 |
+
$metadata = $this->get_image_metadata( $original_image_info );
|
758 |
+
|
759 |
+
// remove the watermark if this image was already watermarked
|
760 |
+
if ( (int) get_post_meta( $attachment_id, $this->is_watermarked_metakey, true ) === 1 )
|
761 |
+
$this->remove_watermark( $data, $attachment_id, 'manual' );
|
762 |
+
|
763 |
+
// create a backup if this is enabled
|
764 |
+
if ( $this->options['backup']['backup_image'] )
|
765 |
+
$this->do_backup( $data, $upload_dir, $attachment_id );
|
766 |
+
|
767 |
+
// loop through active image sizes
|
768 |
+
foreach ( $this->options['watermark_on'] as $image_size => $active_size ) {
|
769 |
+
if ( $active_size === 1 ) {
|
770 |
+
switch ( $image_size ) {
|
771 |
+
case 'full':
|
772 |
+
$filepath = $original_file;
|
773 |
+
break;
|
774 |
+
|
775 |
+
default:
|
776 |
+
if ( ! empty( $data['sizes'] ) && array_key_exists( $image_size, $data['sizes'] ) )
|
777 |
+
$filepath = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . dirname( $data['file'] ) . DIRECTORY_SEPARATOR . $data['sizes'][$image_size]['file'];
|
778 |
+
else
|
779 |
+
// early getaway
|
780 |
+
continue 2;
|
781 |
+
}
|
782 |
+
|
783 |
+
do_action( 'iw_before_apply_watermark', $attachment_id, $image_size );
|
784 |
+
|
785 |
+
// apply watermark
|
786 |
+
$this->do_watermark( $attachment_id, $filepath, $image_size, $upload_dir, $metadata );
|
787 |
+
|
788 |
+
// save metadata
|
789 |
+
$this->save_image_metadata( $metadata, $filepath );
|
790 |
+
|
791 |
+
do_action( 'iw_after_apply_watermark', $attachment_id, $image_size );
|
792 |
+
}
|
793 |
+
}
|
794 |
+
|
795 |
+
// update watermark status
|
796 |
+
update_post_meta( $attachment_id, $this->is_watermarked_metakey, 1 );
|
797 |
+
}
|
798 |
+
|
799 |
+
// pass forward attachment metadata
|
800 |
+
return $data;
|
801 |
+
}
|
802 |
+
|
803 |
+
/**
|
804 |
+
* Remove watermark from selected image sizes.
|
805 |
+
*
|
806 |
+
* @param array $data
|
807 |
+
* @param int|string $attachment_id Attachment ID
|
808 |
+
* @param string $method
|
809 |
+
* @return array
|
810 |
+
*/
|
811 |
+
private function remove_watermark( $data, $attachment_id, $method = '' ) {
|
812 |
+
if ( $method !== 'manual' )
|
813 |
+
return $data;
|
814 |
+
|
815 |
+
$upload_dir = wp_upload_dir();
|
816 |
+
|
817 |
+
// is this really an image?
|
818 |
+
if ( getimagesize( $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $data['file'] ) !== false ) {
|
819 |
+
// live file path (probably watermarked)
|
820 |
+
$filepath = get_attached_file( $attachment_id );
|
821 |
+
|
822 |
+
// backup file path (not watermarked)
|
823 |
+
$backup_filepath = $this->get_image_backup_filepath( get_post_meta( $attachment_id, '_wp_attached_file', true ) );
|
824 |
+
|
825 |
+
// replace the image in uploads with our backup if one exists
|
826 |
+
if ( file_exists( $backup_filepath ) ) {
|
827 |
+
if ( ! copy( $backup_filepath, $filepath ) ) {
|
828 |
+
// Failed to copy
|
829 |
+
}
|
830 |
+
}
|
831 |
+
|
832 |
+
// if no backup exists, use the current full-size image to regenerate
|
833 |
+
// if the "full" size is enabled for watermarks and no backup has been made the removal of watermarks can't be done
|
834 |
+
|
835 |
+
// regenerate metadata (and thumbs)
|
836 |
+
$metadata = wp_generate_attachment_metadata( $attachment_id, $filepath );
|
837 |
+
|
838 |
+
// update attachment metadata with new metadata
|
839 |
+
wp_update_attachment_metadata( $attachment_id, $metadata );
|
840 |
+
|
841 |
+
// update watermark status
|
842 |
+
update_post_meta( $attachment_id, $this->is_watermarked_metakey, 0 );
|
843 |
+
|
844 |
+
// ureturn the attachment metadata
|
845 |
+
return wp_get_attachment_metadata( $attachment_id );
|
846 |
+
}
|
847 |
+
|
848 |
+
return false;
|
849 |
+
}
|
850 |
+
|
851 |
+
/**
|
852 |
+
* Get image metadata.
|
853 |
+
*
|
854 |
+
* @param array $imageinfo
|
855 |
+
* @return array
|
856 |
+
*/
|
857 |
+
public function get_image_metadata( $imageinfo ) {
|
858 |
+
$metadata = array(
|
859 |
+
'exif' => null,
|
860 |
+
'iptc' => null
|
861 |
+
);
|
862 |
+
|
863 |
+
if ( is_array( $imageinfo ) ) {
|
864 |
+
// prepare EXIF data bytes from source file
|
865 |
+
$exifdata = key_exists( 'APP1', $imageinfo ) ? $imageinfo['APP1'] : null;
|
866 |
+
|
867 |
+
if ( $exifdata ) {
|
868 |
+
$exiflength = strlen( $exifdata ) + 2;
|
869 |
+
|
870 |
+
// construct EXIF segment
|
871 |
+
if ( $exiflength > 0xFFFF ) {
|
872 |
+
return $metadata;
|
873 |
+
} else
|
874 |
+
$metadata['exif'] = chr( 0xFF ) . chr( 0xE1 ) . chr( ( $exiflength >> 8 ) & 0xFF ) . chr( $exiflength & 0xFF ) . $exifdata;
|
875 |
+
}
|
876 |
+
|
877 |
+
// prepare IPTC data bytes from source file
|
878 |
+
$iptcdata = key_exists( 'APP13', $imageinfo ) ? $imageinfo['APP13'] : null;
|
879 |
+
|
880 |
+
if ( $iptcdata ) {
|
881 |
+
$iptclength = strlen( $iptcdata ) + 2;
|
882 |
+
|
883 |
+
// construct IPTC segment
|
884 |
+
if ( $iptclength > 0xFFFF ) {
|
885 |
+
return $metadata;
|
886 |
+
} else
|
887 |
+
$metadata['iptc'] = chr( 0xFF ) . chr( 0xED ) . chr( ( $iptclength >> 8 ) & 0xFF ) . chr( $iptclength & 0xFF ) . $iptcdata;
|
888 |
+
}
|
889 |
+
}
|
890 |
+
|
891 |
+
return $metadata;
|
892 |
+
}
|
893 |
+
|
894 |
+
/**
|
895 |
+
* Save EXIF and IPTC metadata from one image to another.
|
896 |
+
*
|
897 |
+
* @param array $metadata
|
898 |
+
* @param string $file
|
899 |
+
* @return bool|int
|
900 |
+
*/
|
901 |
+
public function save_image_metadata( $metadata, $file ) {
|
902 |
+
$mime = wp_check_filetype( $file );
|
903 |
+
|
904 |
+
if ( file_exists( $file ) && $mime['type'] !== 'image/png' ) {
|
905 |
+
$exifdata = $metadata['exif'];
|
906 |
+
$iptcdata = $metadata['iptc'];
|
907 |
+
|
908 |
+
$destfilecontent = @file_get_contents( $file );
|
909 |
+
|
910 |
+
if ( ! $destfilecontent )
|
911 |
+
return false;
|
912 |
+
|
913 |
+
if ( strlen( $destfilecontent ) > 0 ) {
|
914 |
+
$destfilecontent = substr( $destfilecontent, 2 );
|
915 |
+
|
916 |
+
// variable accumulates new & original IPTC application segments
|
917 |
+
$portiontoadd = chr( 0xFF ) . chr( 0xD8 );
|
918 |
+
|
919 |
+
$exifadded = ! $exifdata;
|
920 |
+
$iptcadded = ! $iptcdata;
|
921 |
+
|
922 |
+
while ( ( $this->get_safe_chunk( substr( $destfilecontent, 0, 2 ) ) & 0xFFF0 ) === 0xFFE0 ) {
|
923 |
+
$segmentlen = ( $this->get_safe_chunk( substr( $destfilecontent, 2, 2 ) ) & 0xFFFF );
|
924 |
+
|
925 |
+
// last 4 bits of second byte is IPTC segment
|
926 |
+
$iptcsegmentnumber = ( $this->get_safe_chunk( substr( $destfilecontent, 1, 1 ) ) & 0x0F );
|
927 |
+
|
928 |
+
if ( $segmentlen <= 2 )
|
929 |
+
return false;
|
930 |
+
|
931 |
+
$thisexistingsegment = substr( $destfilecontent, 0, $segmentlen + 2 );
|
932 |
+
|
933 |
+
if ( ( $iptcsegmentnumber >= 1 ) && ( ! $exifadded ) ) {
|
934 |
+
$portiontoadd .= $exifdata;
|
935 |
+
$exifadded = true;
|
936 |
+
|
937 |
+
if ( $iptcsegmentnumber === 1 )
|
938 |
+
$thisexistingsegment = '';
|
939 |
+
}
|
940 |
+
|
941 |
+
if ( ( $iptcsegmentnumber >= 13 ) && ( ! $iptcadded ) ) {
|
942 |
+
$portiontoadd .= $iptcdata;
|
943 |
+
$iptcadded = true;
|
944 |
+
|
945 |
+
if ( $iptcsegmentnumber === 13 )
|
946 |
+
$thisexistingsegment = '';
|
947 |
+
}
|
948 |
+
|
949 |
+
$portiontoadd .= $thisexistingsegment;
|
950 |
+
$destfilecontent = substr( $destfilecontent, $segmentlen + 2 );
|
951 |
+
}
|
952 |
+
|
953 |
+
// add EXIF data if not added already
|
954 |
+
if ( ! $exifadded )
|
955 |
+
$portiontoadd .= $exifdata;
|
956 |
+
|
957 |
+
// add IPTC data if not added already
|
958 |
+
if ( ! $iptcadded )
|
959 |
+
$portiontoadd .= $iptcdata;
|
960 |
+
|
961 |
+
$outputfile = fopen( $file, 'w' );
|
962 |
+
|
963 |
+
if ( $outputfile )
|
964 |
+
return fwrite( $outputfile, $portiontoadd . $destfilecontent );
|
965 |
+
else
|
966 |
+
return false;
|
967 |
+
} else
|
968 |
+
return false;
|
969 |
+
} else
|
970 |
+
return false;
|
971 |
+
}
|
972 |
+
|
973 |
+
/**
|
974 |
+
* Get integer value of binary chunk.
|
975 |
+
*
|
976 |
+
* @param bin $value Binary data
|
977 |
+
* @return int
|
978 |
+
*/
|
979 |
+
private function get_safe_chunk( $value ) {
|
980 |
+
// check for numeric value
|
981 |
+
if ( is_numeric( $value ) ) {
|
982 |
+
// cast to integer to do bitwise AND operation
|
983 |
+
return (int) $value;
|
984 |
+
} else
|
985 |
+
return 0;
|
986 |
+
}
|
987 |
+
|
988 |
+
/**
|
989 |
+
* Apply watermark to image.
|
990 |
+
*
|
991 |
+
* @param int $attachment_id Attachment ID
|
992 |
+
* @param string $image_path Path to the file
|
993 |
+
* @param string $image_size Image size
|
994 |
+
* @param array $upload_dir Upload media data
|
995 |
+
* @param array $metadata EXIF and ITPC metadata
|
996 |
+
* @return void
|
997 |
+
*/
|
998 |
+
public function do_watermark( $attachment_id, $image_path, $image_size, $upload_dir, $metadata = array() ) {
|
999 |
+
$options = apply_filters( 'iw_watermark_options', $this->options );
|
1000 |
+
|
1001 |
+
// get image mime type
|
1002 |
+
$mime = wp_check_filetype( $image_path );
|
1003 |
+
|
1004 |
+
if ( ! wp_attachment_is_image( $options['watermark_image']['url'] ) )
|
1005 |
+
return;
|
1006 |
+
|
1007 |
+
// get watermark path
|
1008 |
+
$watermark_file = wp_get_attachment_metadata( $options['watermark_image']['url'], true );
|
1009 |
+
$watermark_path = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $watermark_file['file'];
|
1010 |
+
|
1011 |
+
// imagick extension
|
1012 |
+
if ( $this->extension === 'imagick' ) {
|
1013 |
+
// create image resource
|
1014 |
+
$image = new Imagick( $image_path );
|
1015 |
+
|
1016 |
+
// create watermark resource
|
1017 |
+
$watermark = new Imagick( $watermark_path );
|
1018 |
+
|
1019 |
+
// alpha channel exists?
|
1020 |
+
if ( $watermark->getImageAlphaChannel() > 0 )
|
1021 |
+
$watermark->evaluateImage( Imagick::EVALUATE_MULTIPLY, round( (float) ( $options['watermark_image']['transparent'] / 100 ), 2 ), Imagick::CHANNEL_ALPHA );
|
1022 |
+
// no alpha channel
|
1023 |
+
else
|
1024 |
+
$watermark->setImageOpacity( round( (float) ( $options['watermark_image']['transparent'] / 100 ), 2 ) );
|
1025 |
+
|
1026 |
+
// set compression quality
|
1027 |
+
if ( $mime['type'] === 'image/jpeg' ) {
|
1028 |
+
$image->setImageCompressionQuality( $options['watermark_image']['quality'] );
|
1029 |
+
$image->setImageCompression( imagick::COMPRESSION_JPEG );
|
1030 |
+
} else
|
1031 |
+
$image->setImageCompressionQuality( $options['watermark_image']['quality'] );
|
1032 |
+
|
1033 |
+
// set image output to progressive
|
1034 |
+
if ( $options['watermark_image']['jpeg_format'] === 'progressive' )
|
1035 |
+
$image->setImageInterlaceScheme( Imagick::INTERLACE_PLANE );
|
1036 |
+
|
1037 |
+
// get image dimensions
|
1038 |
+
$image_dim = $image->getImageGeometry();
|
1039 |
+
|
1040 |
+
// get watermark dimensions
|
1041 |
+
$watermark_dim = $watermark->getImageGeometry();
|
1042 |
+
|
1043 |
+
// calculate watermark new dimensions
|
1044 |
+
list( $width, $height ) = $this->calculate_watermark_dimensions( $image_dim['width'], $image_dim['height'], $watermark_dim['width'], $watermark_dim['height'], $options );
|
1045 |
+
|
1046 |
+
// resize watermark
|
1047 |
+
$watermark->resizeImage( $width, $height, imagick::FILTER_CATROM, 1 );
|
1048 |
+
|
1049 |
+
// calculate image coordinates
|
1050 |
+
list( $dest_x, $dest_y ) = $this->calculate_image_coordinates( $image_dim['width'], $image_dim['height'], $width, $height, $options );
|
1051 |
+
|
1052 |
+
// combine two images together
|
1053 |
+
$image->compositeImage( $watermark, Imagick::COMPOSITE_DEFAULT, $dest_x, $dest_y, Imagick::CHANNEL_ALL );
|
1054 |
+
|
1055 |
+
// save watermarked image
|
1056 |
+
$image->writeImage( $image_path );
|
1057 |
+
|
1058 |
+
// clear image memory
|
1059 |
+
$image->clear();
|
1060 |
+
$image->destroy();
|
1061 |
+
$image = null;
|
1062 |
+
|
1063 |
+
// clear watermark memory
|
1064 |
+
$watermark->clear();
|
1065 |
+
$watermark->destroy();
|
1066 |
+
$watermark = null;
|
1067 |
+
// gd extension
|
1068 |
+
} else {
|
1069 |
+
// get image resource
|
1070 |
+
$image = $this->get_image_resource( $image_path, $mime['type'] );
|
1071 |
+
|
1072 |
+
if ( $image !== false ) {
|
1073 |
+
// add watermark image to image
|
1074 |
+
$image = $this->add_watermark_image( $image, $options, $upload_dir );
|
1075 |
+
|
1076 |
+
if ( $image !== false ) {
|
1077 |
+
// save watermarked image
|
1078 |
+
$this->save_image_file( $image, $mime['type'], $image_path, $options['watermark_image']['quality'] );
|
1079 |
+
|
1080 |
+
// clear watermark memory
|
1081 |
+
imagedestroy( $image );
|
1082 |
+
|
1083 |
+
$image = null;
|
1084 |
+
}
|
1085 |
+
}
|
1086 |
+
}
|
1087 |
+
}
|
1088 |
+
|
1089 |
+
/**
|
1090 |
+
* Make a backup of the full size image.
|
1091 |
+
*
|
1092 |
+
* @param array $data
|
1093 |
+
* @param string $upload_dir
|
1094 |
+
* @param int $attachment_id
|
1095 |
+
* @return bool
|
1096 |
+
*/
|
1097 |
+
private function do_backup( $data, $upload_dir, $attachment_id ) {
|
1098 |
+
// get the filepath for the backup image we're creating
|
1099 |
+
$backup_filepath = $this->get_image_backup_filepath( $data['file'] );
|
1100 |
+
|
1101 |
+
// make sure the backup isn't created yet
|
1102 |
+
if ( ! file_exists( $backup_filepath ) ) {
|
1103 |
+
// the original (full size) image
|
1104 |
+
$filepath = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $data['file'];
|
1105 |
+
$mime = wp_check_filetype( $filepath );
|
1106 |
+
|
1107 |
+
// get image resource
|
1108 |
+
$image = $this->get_image_resource( $filepath, $mime['type'] );
|
1109 |
+
|
1110 |
+
if ( $image !== false ) {
|
1111 |
+
// create backup directory if needed
|
1112 |
+
wp_mkdir_p( $this->get_image_backup_folder_location( $data['file'] ) );
|
1113 |
+
|
1114 |
+
// get path to the backup file
|
1115 |
+
$path = pathinfo( $backup_filepath );
|
1116 |
+
|
1117 |
+
// create subfolders in backup folder if needed
|
1118 |
+
wp_mkdir_p( $path['dirname'] );
|
1119 |
+
|
1120 |
+
// save backup image
|
1121 |
+
$this->save_image_file( $image, $mime['type'], $backup_filepath, $this->options['backup']['backup_quality'] );
|
1122 |
+
|
1123 |
+
// clear backup memory
|
1124 |
+
imagedestroy( $image );
|
1125 |
+
$image = null;
|
1126 |
+
}
|
1127 |
+
}
|
1128 |
+
}
|
1129 |
+
|
1130 |
+
/**
|
1131 |
+
* Get image resource accordingly to mimetype.
|
1132 |
+
*
|
1133 |
+
* @param string $filepath
|
1134 |
+
* @param string $mime_type
|
1135 |
+
* @return resource
|
1136 |
+
*/
|
1137 |
+
private function get_image_resource( $filepath, $mime_type ) {
|
1138 |
+
switch ( $mime_type ) {
|
1139 |
+
case 'image/jpeg':
|
1140 |
+
case 'image/pjpeg':
|
1141 |
+
$image = imagecreatefromjpeg( $filepath );
|
1142 |
+
break;
|
1143 |
+
|
1144 |
+
case 'image/png':
|
1145 |
+
$image = imagecreatefrompng( $filepath );
|
1146 |
+
|
1147 |
+
if ( is_resource( $image ) )
|
1148 |
+
imagefilledrectangle( $image, 0, 0, imagesx( $image ), imagesy( $image ), imagecolorallocatealpha( $image, 255, 255, 255, 127 ) );
|
1149 |
+
break;
|
1150 |
+
|
1151 |
+
default:
|
1152 |
+
$image = false;
|
1153 |
+
}
|
1154 |
+
|
1155 |
+
if ( is_resource( $image ) ) {
|
1156 |
+
imagealphablending( $image, false );
|
1157 |
+
imagesavealpha( $image, true );
|
1158 |
+
}
|
1159 |
+
|
1160 |
+
return $image;
|
1161 |
+
}
|
1162 |
+
|
1163 |
+
/**
|
1164 |
+
* Get image filename without the uploaded folders.
|
1165 |
+
*
|
1166 |
+
* @param string $filepath
|
1167 |
+
* @return string $filename
|
1168 |
+
*/
|
1169 |
+
private function get_image_filename( $filepath ) {
|
1170 |
+
return basename( $filepath );
|
1171 |
+
}
|
1172 |
+
|
1173 |
+
/**
|
1174 |
+
* Get image backup folder.
|
1175 |
+
*
|
1176 |
+
* @param string $filepath
|
1177 |
+
* @return string
|
1178 |
+
*/
|
1179 |
+
private function get_image_backup_folder_location( $filepath ) {
|
1180 |
+
$path = explode( DIRECTORY_SEPARATOR, $filepath );
|
1181 |
+
|
1182 |
+
array_pop( $path );
|
1183 |
+
|
1184 |
+
$path = implode( DIRECTORY_SEPARATOR, $path );
|
1185 |
+
|
1186 |
+
return IMAGE_WATERMARK_BACKUP_DIR . DIRECTORY_SEPARATOR . $path;
|
1187 |
+
}
|
1188 |
+
|
1189 |
+
/**
|
1190 |
+
* Get image resource from the backup folder (if available).
|
1191 |
+
*
|
1192 |
+
* @param string $filepath
|
1193 |
+
* @return string
|
1194 |
+
*/
|
1195 |
+
private function get_image_backup_filepath( $filepath ) {
|
1196 |
+
return IMAGE_WATERMARK_BACKUP_DIR . DIRECTORY_SEPARATOR . $filepath;
|
1197 |
+
}
|
1198 |
+
|
1199 |
+
/**
|
1200 |
+
* Delete the image backup if one exists.
|
1201 |
+
*
|
1202 |
+
* @param int $attachment_id
|
1203 |
+
* @return void
|
1204 |
+
*/
|
1205 |
+
public function delete_attachment( $attachment_id ) {
|
1206 |
+
// see get_attached_file() in wp-includes/post.php
|
1207 |
+
$filepath = get_post_meta( $attachment_id, '_wp_attached_file', true );
|
1208 |
+
$backup_filepath = $this->get_image_backup_filepath( $filepath );
|
1209 |
+
|
1210 |
+
if ( file_exists( $backup_filepath ) )
|
1211 |
+
unlink( $backup_filepath );
|
1212 |
+
}
|
1213 |
+
|
1214 |
+
/**
|
1215 |
+
* Create admin notice when we can't create the backup folder.
|
1216 |
+
*
|
1217 |
+
* @return void
|
1218 |
+
*/
|
1219 |
+
function folder_writable_admin_notice() {
|
1220 |
+
if ( current_user_can( 'manage_options' ) && $this->is_backup_folder_writable !== true ) {
|
1221 |
+
?>
|
1222 |
+
<div class="notice notice-error is-dismissible">
|
1223 |
+
<p><?php _e( 'Image Watermark', 'image-watermark' ); ?> - <?php _e( 'Image backup', 'image-watermark' ); ?>: <?php _e( "Your uploads folder is not writable so we can't create a backup of your image uploads. We've disabled this feature for now.", 'image-watermark' ); ?></p>
|
1224 |
+
</div>
|
1225 |
+
<?php
|
1226 |
+
}
|
1227 |
+
}
|
1228 |
+
|
1229 |
+
/**
|
1230 |
+
* Calculate watermark dimensions.
|
1231 |
+
*
|
1232 |
+
* @param int $image_width Image width
|
1233 |
+
* @param int $image_height Image height
|
1234 |
+
* @param int $watermark_width Watermark width
|
1235 |
+
* @param int $watermark_height Watermark height
|
1236 |
+
* @param array $options
|
1237 |
+
* @return array
|
1238 |
+
*/
|
1239 |
+
private function calculate_watermark_dimensions( $image_width, $image_height, $watermark_width, $watermark_height, $options ) {
|
1240 |
+
// custom
|
1241 |
+
if ( $options['watermark_image']['watermark_size_type'] === 1 ) {
|
1242 |
+
$width = $options['watermark_image']['absolute_width'];
|
1243 |
+
$height = $options['watermark_image']['absolute_height'];
|
1244 |
+
// scale
|
1245 |
+
} elseif ( $options['watermark_image']['watermark_size_type'] === 2 ) {
|
1246 |
+
$ratio = $image_width * $options['watermark_image']['width'] / 100 / $watermark_width;
|
1247 |
+
|
1248 |
+
$width = (int) ( $watermark_width * $ratio );
|
1249 |
+
$height = (int) ( $watermark_height * $ratio );
|
1250 |
+
|
1251 |
+
// if watermark scaled height is bigger then image watermark
|
1252 |
+
if ( $height > $image_height ) {
|
1253 |
+
$width = (int) ( $image_height * $width / $height );
|
1254 |
+
$height = $image_height;
|
1255 |
+
}
|
1256 |
+
// original
|
1257 |
+
} else {
|
1258 |
+
$width = $watermark_width;
|
1259 |
+
$height = $watermark_height;
|
1260 |
+
}
|
1261 |
+
|
1262 |
+
return array( $width, $height );
|
1263 |
+
}
|
1264 |
+
|
1265 |
+
/**
|
1266 |
+
* Calculate image coordinates for watermark.
|
1267 |
+
*
|
1268 |
+
* @param int $image_width Image width
|
1269 |
+
* @param int $image_height Image height
|
1270 |
+
* @param int $watermark_width Watermark width
|
1271 |
+
* @param int $watermark_height Watermark height
|
1272 |
+
* @param array $options Options
|
1273 |
+
* @return array
|
1274 |
+
*/
|
1275 |
+
private function calculate_image_coordinates( $image_width, $image_height, $watermark_width, $watermark_height, $options ) {
|
1276 |
+
switch ( $options['watermark_image']['position'] ) {
|
1277 |
+
case 'top_left':
|
1278 |
+
$dest_x = $dest_y = 0;
|
1279 |
+
break;
|
1280 |
+
|
1281 |
+
case 'top_center':
|
1282 |
+
$dest_x = ( $image_width / 2 ) - ( $watermark_width / 2 );
|
1283 |
+
$dest_y = 0;
|
1284 |
+
break;
|
1285 |
+
|
1286 |
+
case 'top_right':
|
1287 |
+
$dest_x = $image_width - $watermark_width;
|
1288 |
+
$dest_y = 0;
|
1289 |
+
break;
|
1290 |
+
|
1291 |
+
case 'middle_left':
|
1292 |
+
$dest_x = 0;
|
1293 |
+
$dest_y = ( $image_height / 2 ) - ( $watermark_height / 2 );
|
1294 |
+
break;
|
1295 |
+
|
1296 |
+
case 'middle_right':
|
1297 |
+
$dest_x = $image_width - $watermark_width;
|
1298 |
+
$dest_y = ( $image_height / 2 ) - ( $watermark_height / 2 );
|
1299 |
+
break;
|
1300 |
+
|
1301 |
+
case 'bottom_left':
|
1302 |
+
$dest_x = 0;
|
1303 |
+
$dest_y = $image_height - $watermark_height;
|
1304 |
+
break;
|
1305 |
+
|
1306 |
+
case 'bottom_center':
|
1307 |
+
$dest_x = ( $image_width / 2 ) - ( $watermark_width / 2 );
|
1308 |
+
$dest_y = $image_height - $watermark_height;
|
1309 |
+
break;
|
1310 |
+
|
1311 |
+
case 'bottom_right':
|
1312 |
+
$dest_x = $image_width - $watermark_width;
|
1313 |
+
$dest_y = $image_height - $watermark_height;
|
1314 |
+
break;
|
1315 |
+
|
1316 |
+
case 'middle_center':
|
1317 |
+
default:
|
1318 |
+
$dest_x = ( $image_width / 2 ) - ( $watermark_width / 2 );
|
1319 |
+
$dest_y = ( $image_height / 2 ) - ( $watermark_height / 2 );
|
1320 |
+
}
|
1321 |
+
|
1322 |
+
if ( $options['watermark_image']['offset_unit'] === 'pixels' ) {
|
1323 |
+
$dest_x += $options['watermark_image']['offset_width'];
|
1324 |
+
$dest_y += $options['watermark_image']['offset_height'];
|
1325 |
+
} else {
|
1326 |
+
$dest_x += (int) ( $image_width * $options['watermark_image']['offset_width'] / 100 );
|
1327 |
+
$dest_y += (int) ( $image_height * $options['watermark_image']['offset_height'] / 100 );
|
1328 |
+
}
|
1329 |
+
|
1330 |
+
return array( $dest_x, $dest_y );
|
1331 |
+
}
|
1332 |
+
|
1333 |
+
/**
|
1334 |
+
* Add watermark image to an image.
|
1335 |
+
*
|
1336 |
+
* @param resource $image Image resource
|
1337 |
+
* @param array $options Plugin options
|
1338 |
+
* @param array $upload_dir WP upload dir data
|
1339 |
+
* @return bool|resource
|
1340 |
+
*/
|
1341 |
+
private function add_watermark_image( $image, $options, $upload_dir ) {
|
1342 |
+
if ( ! wp_attachment_is_image( $options['watermark_image']['url'] ) )
|
1343 |
+
return false;
|
1344 |
+
|
1345 |
+
$watermark_file = wp_get_attachment_metadata( $options['watermark_image']['url'], true );
|
1346 |
+
$url = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $watermark_file['file'];
|
1347 |
+
$watermark_file_info = getimagesize( $url );
|
1348 |
+
|
1349 |
+
switch ( $watermark_file_info['mime'] ) {
|
1350 |
+
case 'image/jpeg':
|
1351 |
+
case 'image/pjpeg':
|
1352 |
+
$watermark = imagecreatefromjpeg( $url );
|
1353 |
+
break;
|
1354 |
+
|
1355 |
+
case 'image/gif':
|
1356 |
+
$watermark = imagecreatefromgif( $url );
|
1357 |
+
break;
|
1358 |
+
|
1359 |
+
case 'image/png':
|
1360 |
+
$watermark = imagecreatefrompng( $url );
|
1361 |
+
break;
|
1362 |
+
|
1363 |
+
default:
|
1364 |
+
return false;
|
1365 |
+
}
|
1366 |
+
|
1367 |
+
// get image dimensions
|
1368 |
+
$image_width = imagesx( $image );
|
1369 |
+
$image_height = imagesy( $image );
|
1370 |
+
|
1371 |
+
// calculate watermark new dimensions
|
1372 |
+
list( $w, $h ) = $this->calculate_watermark_dimensions( $image_width, $image_height, imagesx( $watermark ), imagesy( $watermark ), $options );
|
1373 |
+
|
1374 |
+
// calculate image coordinates
|
1375 |
+
list( $dest_x, $dest_y ) = $this->calculate_image_coordinates( $image_width, $image_height, $w, $h, $options );
|
1376 |
+
|
1377 |
+
// combine two images together
|
1378 |
+
$this->imagecopymerge_alpha( $image, $this->resize( $watermark, $w, $h, $watermark_file_info ), $dest_x, $dest_y, 0, 0, $w, $h, $options['watermark_image']['transparent'] );
|
1379 |
+
|
1380 |
+
if ( $options['watermark_image']['jpeg_format'] === 'progressive' )
|
1381 |
+
imageinterlace( $image, true );
|
1382 |
+
|
1383 |
+
return $image;
|
1384 |
+
}
|
1385 |
+
|
1386 |
+
/**
|
1387 |
+
* Create a new image function.
|
1388 |
+
*
|
1389 |
+
* @param resource $dst_im
|
1390 |
+
* @param resource $src_im
|
1391 |
+
* @param int $dst_x
|
1392 |
+
* @param int $dst_y
|
1393 |
+
* @param int $src_x
|
1394 |
+
* @param int $src_y
|
1395 |
+
* @param int $src_w
|
1396 |
+
* @param int $src_h
|
1397 |
+
* @param int $pct
|
1398 |
+
* @return void
|
1399 |
+
*/
|
1400 |
+
private function imagecopymerge_alpha( $dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct ) {
|
1401 |
+
// create a cut resource
|
1402 |
+
$cut = imagecreatetruecolor( $src_w, $src_h );
|
1403 |
+
|
1404 |
+
// copy relevant section from background to the cut resource
|
1405 |
+
imagecopy( $cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h );
|
1406 |
+
|
1407 |
+
// copy relevant section from watermark to the cut resource
|
1408 |
+
imagecopy( $cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h );
|
1409 |
+
|
1410 |
+
// insert cut resource to destination image
|
1411 |
+
imagecopymerge( $dst_im, $cut, $dst_x, $dst_y, 0, 0, $src_w, $src_h, $pct );
|
1412 |
+
}
|
1413 |
+
|
1414 |
+
/**
|
1415 |
+
* Resize image.
|
1416 |
+
*
|
1417 |
+
* @param resource $image Image resource
|
1418 |
+
* @param int $width Image width
|
1419 |
+
* @param int $height Image height
|
1420 |
+
* @param array $info Image data
|
1421 |
+
* @return resource
|
1422 |
+
*/
|
1423 |
+
private function resize( $image, $width, $height, $info ) {
|
1424 |
+
$new_image = imagecreatetruecolor( $width, $height );
|
1425 |
+
|
1426 |
+
// check if this image is PNG, then set if transparent
|
1427 |
+
if ( $info[2] === 3 ) {
|
1428 |
+
imagealphablending( $new_image, false );
|
1429 |
+
imagesavealpha( $new_image, true );
|
1430 |
+
imagefilledrectangle( $new_image, 0, 0, $width, $height, imagecolorallocatealpha( $new_image, 255, 255, 255, 127 ) );
|
1431 |
+
}
|
1432 |
+
|
1433 |
+
imagecopyresampled( $new_image, $image, 0, 0, 0, 0, $width, $height, $info[0], $info[1] );
|
1434 |
+
|
1435 |
+
return $new_image;
|
1436 |
+
}
|
1437 |
+
|
1438 |
+
/**
|
1439 |
+
* Save image from image resource.
|
1440 |
+
*
|
1441 |
+
* @param resource $image Image resource
|
1442 |
+
* @param string $mime_type Image mime type
|
1443 |
+
* @param string $filepath Path where image should be saved
|
1444 |
+
* @param int $quality Image quality
|
1445 |
+
* @return void
|
1446 |
+
*/
|
1447 |
+
private function save_image_file( $image, $mime_type, $filepath, $quality ) {
|
1448 |
+
switch ( $mime_type ) {
|
1449 |
+
case 'image/jpeg':
|
1450 |
+
case 'image/pjpeg':
|
1451 |
+
imagejpeg( $image, $filepath, $quality );
|
1452 |
+
break;
|
1453 |
+
|
1454 |
+
case 'image/png':
|
1455 |
+
imagepng( $image, $filepath, (int) round( 9 - ( 9 * $quality / 100 ), 0 ) );
|
1456 |
+
break;
|
1457 |
+
}
|
1458 |
+
}
|
1459 |
+
|
1460 |
+
/**
|
1461 |
+
* Add links to support forum.
|
1462 |
+
*
|
1463 |
+
* @param array $links
|
1464 |
+
* @param string $file
|
1465 |
+
* @return array
|
1466 |
+
*/
|
1467 |
+
public function plugin_extend_links( $links, $file ) {
|
1468 |
+
if ( ! current_user_can( 'install_plugins' ) )
|
1469 |
+
return $links;
|
1470 |
+
|
1471 |
+
if ( $file === plugin_basename( __FILE__ ) )
|
1472 |
+
return array_merge( $links, array( sprintf( '<a href="http://www.dfactory.eu/support/forum/image-watermark/" target="_blank">%s</a>', __( 'Support', 'image-watermark' ) ) ) );
|
1473 |
+
|
1474 |
+
return $links;
|
1475 |
+
}
|
1476 |
+
|
1477 |
+
/**
|
1478 |
+
* Add links to settings page.
|
1479 |
+
*
|
1480 |
+
* @param array $links
|
1481 |
+
* @param string $file
|
1482 |
+
* @return array
|
1483 |
+
*/
|
1484 |
+
function plugin_settings_link( $links, $file ) {
|
1485 |
+
if ( ! is_admin() || ! current_user_can( 'manage_options' ) )
|
1486 |
+
return $links;
|
1487 |
+
|
1488 |
+
static $plugin;
|
1489 |
+
|
1490 |
+
$plugin = plugin_basename( __FILE__ );
|
1491 |
+
|
1492 |
+
if ( $file === $plugin ) {
|
1493 |
+
$settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php' ) . '?page=watermark-options', __( 'Settings', 'image-watermark' ) );
|
1494 |
+
|
1495 |
+
array_unshift( $links, $settings_link );
|
1496 |
+
}
|
1497 |
+
|
1498 |
+
return $links;
|
1499 |
+
}
|
1500 |
+
|
1501 |
+
}
|
1502 |
+
|
1503 |
+
/**
|
1504 |
+
* Get instance of main class.
|
1505 |
+
*
|
1506 |
+
* @return object Instance
|
1507 |
+
*/
|
1508 |
+
function Image_Watermark() {
|
1509 |
+
static $instance;
|
1510 |
+
|
1511 |
+
// first call to instance() initializes the plugin
|
1512 |
+
if ( $instance === null || ! ( $instance instanceof Image_Watermark ) )
|
1513 |
+
$instance = Image_Watermark::instance();
|
1514 |
+
|
1515 |
+
return $instance;
|
1516 |
+
}
|
1517 |
+
|
1518 |
Â
$image_watermark = Image_Watermark();
|
includes/class-settings.php
CHANGED
@@ -19,6 +19,8 @@ class Image_Watermark_Settings {
|
|
19 |
Â
|
20 |
Â
/**
|
21 |
Â
* Class constructor.
|
Â
|
|
Â
|
|
22 |
Â
*/
|
23 |
Â
public function __construct( ) {
|
24 |
Â
// actions
|
@@ -29,6 +31,8 @@ class Image_Watermark_Settings {
|
|
29 |
Â
|
30 |
Â
/**
|
31 |
Â
* Load available image sizes.
|
Â
|
|
Â
|
|
32 |
Â
*/
|
33 |
Â
public function load_image_sizes() {
|
34 |
Â
$this->image_sizes = get_intermediate_image_sizes();
|
@@ -48,6 +52,8 @@ class Image_Watermark_Settings {
|
|
48 |
Â
|
49 |
Â
/**
|
50 |
Â
* Register settings.
|
Â
|
|
Â
|
|
51 |
Â
*/
|
52 |
Â
public function register_settings() {
|
53 |
Â
register_setting( 'image_watermark_options', 'image_watermark_options', array( $this, 'validate_options' ) );
|
@@ -96,6 +102,8 @@ class Image_Watermark_Settings {
|
|
96 |
Â
|
97 |
Â
/**
|
98 |
Â
* Create options page in menu.
|
Â
|
|
Â
|
|
99 |
Â
*/
|
100 |
Â
public function options_page() {
|
101 |
Â
add_options_page(
|
@@ -105,6 +113,8 @@ class Image_Watermark_Settings {
|
|
105 |
Â
|
106 |
Â
/**
|
107 |
Â
* Options page output.
|
Â
|
|
Â
|
|
108 |
Â
*/
|
109 |
Â
public function options_page_output() {
|
110 |
Â
|
@@ -135,7 +145,7 @@ class Image_Watermark_Settings {
|
|
135 |
Â
</div>
|
136 |
Â
</div>
|
137 |
Â
<form action="options.php" method="post">
|
138 |
-
<div id="main-sortables"
|
139 |
Â
settings_fields( 'image_watermark_options' );
|
140 |
Â
$this->do_settings_sections( 'image_watermark_options' );
|
141 |
Â
|
@@ -154,23 +164,11 @@ class Image_Watermark_Settings {
|
|
154 |
Â
</div>
|
155 |
Â
<div class="clear"></div>
|
156 |
Â
</div>';
|
157 |
-
?>
|
158 |
-
<script type="text/javascript">
|
159 |
-
//<![CDATA[
|
160 |
-
jQuery(document).ready( function ($) {
|
161 |
-
// close postboxes that should be closed
|
162 |
-
$('.if-js-closed').removeClass('if-js-closed').addClass('closed');
|
163 |
-
// postboxes setup
|
164 |
-
postboxes.add_postbox_toggles('watermark-options');
|
165 |
-
});
|
166 |
-
//]]>
|
167 |
-
</script>
|
168 |
-
<?php
|
169 |
Â
}
|
170 |
Â
|
171 |
Â
/**
|
172 |
Â
* Validate options.
|
173 |
-
*
|
174 |
Â
* @param array $input
|
175 |
Â
* @return array
|
176 |
Â
*/
|
@@ -270,8 +268,8 @@ class Image_Watermark_Settings {
|
|
270 |
Â
|
271 |
Â
/**
|
272 |
Â
* PHP extension.
|
273 |
-
*
|
274 |
-
* @return
|
275 |
Â
*/
|
276 |
Â
public function iw_extension() {
|
277 |
Â
echo '
|
@@ -293,36 +291,34 @@ class Image_Watermark_Settings {
|
|
293 |
Â
|
294 |
Â
/**
|
295 |
Â
* Automatic watermarking option.
|
296 |
-
*
|
297 |
-
* @return
|
298 |
Â
*/
|
299 |
Â
public function iw_automatic_watermarking() {
|
300 |
Â
?>
|
301 |
Â
<label for="iw_automatic_watermarking">
|
302 |
-
<input id="iw_automatic_watermarking" type="checkbox" <?php checked( ( ! empty( Image_Watermark()->options['watermark_image']['plugin_off'] ) ? 1 : 0 ), 1, true ); ?> value="1" name="iw_options[watermark_image][plugin_off]"
|
303 |
-
<?php echo __( 'Enable watermark for uploaded images.', 'image-watermark' ); ?>
|
304 |
Â
</label>
|
305 |
Â
<?php
|
306 |
Â
}
|
307 |
Â
|
308 |
Â
/**
|
309 |
Â
* Manual watermarking option.
|
310 |
-
*
|
311 |
-
* @return
|
312 |
Â
*/
|
313 |
Â
public function iw_manual_watermarking() {
|
314 |
Â
?>
|
315 |
Â
<label for="iw_manual_watermarking">
|
316 |
-
<input id="iw_manual_watermarking" type="checkbox" <?php checked( ( ! empty( Image_Watermark()->options['watermark_image']['manual_watermarking'] ) ? 1 : 0 ), 1, true ); ?> value="1" name="iw_options[watermark_image][manual_watermarking]"
|
317 |
-
<?php echo __( 'Enable Apply Watermark option for Media Library images.', 'image-watermark' ); ?>
|
318 |
Â
</label>
|
319 |
Â
<?php
|
320 |
Â
}
|
321 |
Â
|
322 |
Â
/**
|
323 |
Â
* Enable watermark for option.
|
324 |
-
*
|
325 |
-
* @return
|
326 |
Â
*/
|
327 |
Â
public function iw_enable_for() {
|
328 |
Â
?>
|
@@ -378,14 +374,13 @@ class Image_Watermark_Settings {
|
|
378 |
Â
|
379 |
Â
/**
|
380 |
Â
* Frontend watermarking option.
|
381 |
-
*
|
382 |
-
* @return
|
383 |
Â
*/
|
384 |
Â
public function iw_frontend_watermarking() {
|
385 |
Â
?>
|
386 |
Â
<label for="iw_frontend_watermarking">
|
387 |
-
<input id="iw_frontend_watermarking" type="checkbox" <?php checked( ( ! empty( Image_Watermark()->options['watermark_image']['frontend_active'] ) ? 1 : 0 ), 1, true ); ?> value="1" name="iw_options[watermark_image][frontend_active]"
|
388 |
-
<?php echo __( 'Enable frontend image uploading. (uploading script is not included, but you may use a plugin or custom code).', 'image-watermark' ); ?>
|
389 |
Â
</label>
|
390 |
Â
<span class="description"><?php echo __( '<br /><strong>Notice:</strong> This functionality works only if uploaded images are processed using WordPress native upload methods.', 'image-watermark' ); ?></span>
|
391 |
Â
<?php
|
@@ -393,22 +388,21 @@ class Image_Watermark_Settings {
|
|
393 |
Â
|
394 |
Â
/**
|
395 |
Â
* Remove data on deactivation option.
|
396 |
-
*
|
397 |
-
* @return
|
398 |
Â
*/
|
399 |
Â
public function iw_deactivation() {
|
400 |
Â
?>
|
401 |
Â
<label for="iw_deactivation">
|
402 |
-
<input id="iw_deactivation" type="checkbox" <?php checked( ( ! empty( Image_Watermark()->options['watermark_image']['deactivation_delete'] ) ? 1 : 0 ), 1, true ); ?> value="1" name="iw_options[watermark_image][deactivation_delete]"
|
403 |
-
<?php echo __( 'Delete all database settings on plugin deactivation.', 'image-watermark' ); ?>
|
404 |
Â
</label>
|
405 |
Â
<?php
|
406 |
Â
}
|
407 |
Â
|
408 |
Â
/**
|
409 |
Â
* Watermark alignment option.
|
410 |
-
*
|
411 |
-
* @return
|
412 |
Â
*/
|
413 |
Â
public function iw_alignment() {
|
414 |
Â
?>
|
@@ -440,7 +434,7 @@ class Image_Watermark_Settings {
|
|
440 |
Â
|
441 |
Â
/**
|
442 |
Â
* Watermark offset unit option.
|
443 |
-
*
|
444 |
Â
* @return void
|
445 |
Â
*/
|
446 |
Â
public function iw_offset_unit() {
|
@@ -455,7 +449,7 @@ class Image_Watermark_Settings {
|
|
455 |
Â
|
456 |
Â
/**
|
457 |
Â
* Watermark offset option.
|
458 |
-
*
|
459 |
Â
* @return void
|
460 |
Â
*/
|
461 |
Â
public function iw_offset() {
|
@@ -471,7 +465,7 @@ class Image_Watermark_Settings {
|
|
471 |
Â
|
472 |
Â
/**
|
473 |
Â
* Watermark image option.
|
474 |
-
*
|
475 |
Â
* @return void
|
476 |
Â
*/
|
477 |
Â
public function iw_watermark_image() {
|
@@ -493,8 +487,8 @@ class Image_Watermark_Settings {
|
|
493 |
Â
|
494 |
Â
/**
|
495 |
Â
* Watermark image preview.
|
496 |
-
*
|
497 |
-
* @return
|
498 |
Â
*/
|
499 |
Â
public function iw_watermark_preview() {
|
500 |
Â
if ( Image_Watermark()->options['watermark_image']['url'] !== NULL && Image_Watermark()->options['watermark_image']['url'] != 0 ) {
|
@@ -532,8 +526,8 @@ class Image_Watermark_Settings {
|
|
532 |
Â
|
533 |
Â
/**
|
534 |
Â
* Watermark size option.
|
535 |
-
*
|
536 |
-
* @return
|
537 |
Â
*/
|
538 |
Â
public function iw_watermark_size() {
|
539 |
Â
?>
|
@@ -550,8 +544,8 @@ class Image_Watermark_Settings {
|
|
550 |
Â
|
551 |
Â
/**
|
552 |
Â
* Watermark custom size option.
|
553 |
-
*
|
554 |
-
* @return
|
555 |
Â
*/
|
556 |
Â
public function iw_watermark_size_custom() {
|
557 |
Â
?>
|
@@ -566,8 +560,8 @@ class Image_Watermark_Settings {
|
|
566 |
Â
|
567 |
Â
/**
|
568 |
Â
* Watermark scaled size option.
|
569 |
-
*
|
570 |
-
* @return
|
571 |
Â
*/
|
572 |
Â
public function iw_watermark_size_scaled() {
|
573 |
Â
?>
|
@@ -585,8 +579,8 @@ class Image_Watermark_Settings {
|
|
585 |
Â
|
586 |
Â
/**
|
587 |
Â
* Watermark custom size option.
|
588 |
-
*
|
589 |
-
* @return
|
590 |
Â
*/
|
591 |
Â
public function iw_watermark_opacity() {
|
592 |
Â
?>
|
@@ -604,8 +598,8 @@ class Image_Watermark_Settings {
|
|
604 |
Â
|
605 |
Â
/**
|
606 |
Â
* Image quality option.
|
607 |
-
*
|
608 |
-
* @return
|
609 |
Â
*/
|
610 |
Â
public function iw_image_quality() {
|
611 |
Â
?>
|
@@ -623,8 +617,8 @@ class Image_Watermark_Settings {
|
|
623 |
Â
|
624 |
Â
/**
|
625 |
Â
* Image format option.
|
626 |
-
*
|
627 |
-
* @return
|
628 |
Â
*/
|
629 |
Â
public function iw_image_format() {
|
630 |
Â
?>
|
@@ -640,64 +634,60 @@ class Image_Watermark_Settings {
|
|
640 |
Â
|
641 |
Â
/**
|
642 |
Â
* Right click image protection option.
|
643 |
-
*
|
644 |
-
* @return
|
645 |
Â
*/
|
646 |
Â
public function iw_protection_right_click() {
|
647 |
Â
?>
|
648 |
Â
<label for="iw_protection_right_click">
|
649 |
-
<input id="iw_protection_right_click" type="checkbox" <?php checked( ( ! empty( Image_Watermark()->options['image_protection']['rightclick'] ) ? 1 : 0 ), 1, true ); ?> value="1" name="iw_options[image_protection][rightclick]"
|
650 |
-
<?php _e( 'Disable right mouse click on images', 'image-watermark' ); ?>
|
651 |
Â
</label>
|
652 |
Â
<?php
|
653 |
Â
}
|
654 |
Â
|
655 |
Â
/**
|
656 |
Â
* Drag and drop image protection option.
|
657 |
-
*
|
658 |
-
* @return
|
659 |
Â
*/
|
660 |
Â
public function iw_protection_drag_drop() {
|
661 |
Â
?>
|
662 |
Â
<label for="iw_protection_drag_drop">
|
663 |
-
<input id="iw_protection_drag_drop" type="checkbox" <?php checked( ( ! empty( Image_Watermark()->options['image_protection']['draganddrop'] ) ? 1 : 0 ), 1, true ); ?> value="1" name="iw_options[image_protection][draganddrop]"
|
664 |
-
<?php _e( 'Prevent drag and drop', 'image-watermark' ); ?>
|
665 |
Â
</label>
|
666 |
Â
<?php
|
667 |
Â
}
|
668 |
Â
|
669 |
Â
/**
|
670 |
Â
* Logged-in users image protection option.
|
671 |
-
*
|
672 |
-
* @return
|
673 |
Â
*/
|
674 |
Â
public function iw_protection_logged() {
|
675 |
Â
?>
|
676 |
Â
<label for="iw_protection_logged">
|
677 |
-
<input id="iw_protection_logged" type="checkbox" <?php checked( ( ! empty( Image_Watermark()->options['image_protection']['forlogged'] ) ? 1 : 0 ), 1, true ); ?> value="1" name="iw_options[image_protection][forlogged]"
|
678 |
-
<?php _e( 'Enable image protection for logged-in users also', 'image-watermark' ); ?>
|
679 |
Â
</label>
|
680 |
Â
<?php
|
681 |
Â
}
|
682 |
Â
|
683 |
Â
/**
|
684 |
-
* Backup the original image
|
685 |
-
*
|
686 |
-
* @return
|
687 |
Â
*/
|
688 |
Â
public function iw_backup_image() {
|
689 |
Â
?>
|
690 |
Â
<label for="iw_backup_size_full">
|
691 |
-
<input id="iw_backup_size_full" type="checkbox" <?php checked( ! empty( Image_Watermark()->options['backup']['backup_image'] ), true, true ); ?> value="1" name="iw_options[backup][backup_image]"
|
692 |
-
<?php echo __( 'Backup the full size image.', 'image-watermark' ); ?>
|
693 |
Â
</label>
|
694 |
Â
<?php
|
695 |
Â
}
|
696 |
Â
|
697 |
Â
/**
|
698 |
Â
* Image backup quality option.
|
699 |
-
*
|
700 |
-
* @return
|
701 |
Â
*/
|
702 |
Â
public function iw_backup_image_quality() {
|
703 |
Â
?>
|
@@ -712,7 +702,7 @@ class Image_Watermark_Settings {
|
|
712 |
Â
<p class="description"><?php _e( 'Set output image quality.', 'image-watermark' ); ?></p>
|
713 |
Â
<?php
|
714 |
Â
}
|
715 |
-
|
716 |
Â
/**
|
717 |
Â
* This function is similar to the function in the Settings API, only the output HTML is changed.
|
718 |
Â
* Print out the settings fields for a particular settings section
|
@@ -722,30 +712,31 @@ class Image_Watermark_Settings {
|
|
722 |
Â
* @since 0.1
|
723 |
Â
*
|
724 |
Â
* @param string $page Slug title of the admin page who's settings fields you want to show.
|
725 |
-
* @
|
726 |
Â
*/
|
727 |
Â
function do_settings_sections( $page ) {
|
728 |
Â
global $wp_settings_sections, $wp_settings_fields;
|
729 |
-
|
730 |
Â
if ( ! isset( $wp_settings_sections[$page] ) )
|
731 |
Â
return;
|
732 |
-
|
733 |
Â
foreach ( (array) $wp_settings_sections[$page] as $section ) {
|
734 |
-
echo '<div id="" class="
|
735 |
-
|
736 |
Â
if ( $section['title'] )
|
737 |
-
echo "<h3
|
738 |
-
|
739 |
Â
if ( $section['callback'] )
|
740 |
Â
call_user_func( $section['callback'], $section );
|
741 |
-
|
742 |
-
if ( ! isset( $wp_settings_fields ) || !isset( $wp_settings_fields[$page] ) || !isset( $wp_settings_fields[$page][$section['id']] ) )
|
743 |
Â
continue;
|
Â
|
|
744 |
Â
echo '<div class="inside"><table class="form-table">';
|
Â
|
|
745 |
Â
do_settings_fields( $page, $section['id'] );
|
746 |
-
|
747 |
-
echo '</div>';
|
748 |
Â
}
|
749 |
Â
}
|
750 |
-
|
751 |
-
}
|
19 |
Â
|
20 |
Â
/**
|
21 |
Â
* Class constructor.
|
22 |
+
*
|
23 |
+
* @return void
|
24 |
Â
*/
|
25 |
Â
public function __construct( ) {
|
26 |
Â
// actions
|
31 |
Â
|
32 |
Â
/**
|
33 |
Â
* Load available image sizes.
|
34 |
+
*
|
35 |
+
* @return void
|
36 |
Â
*/
|
37 |
Â
public function load_image_sizes() {
|
38 |
Â
$this->image_sizes = get_intermediate_image_sizes();
|
52 |
Â
|
53 |
Â
/**
|
54 |
Â
* Register settings.
|
55 |
+
*
|
56 |
+
* @return void
|
57 |
Â
*/
|
58 |
Â
public function register_settings() {
|
59 |
Â
register_setting( 'image_watermark_options', 'image_watermark_options', array( $this, 'validate_options' ) );
|
102 |
Â
|
103 |
Â
/**
|
104 |
Â
* Create options page in menu.
|
105 |
+
*
|
106 |
+
* @return void
|
107 |
Â
*/
|
108 |
Â
public function options_page() {
|
109 |
Â
add_options_page(
|
113 |
Â
|
114 |
Â
/**
|
115 |
Â
* Options page output.
|
116 |
+
*
|
117 |
+
* @return void
|
118 |
Â
*/
|
119 |
Â
public function options_page_output() {
|
120 |
Â
|
145 |
Â
</div>
|
146 |
Â
</div>
|
147 |
Â
<form action="options.php" method="post">
|
148 |
+
<div id="main-sortables">';
|
149 |
Â
settings_fields( 'image_watermark_options' );
|
150 |
Â
$this->do_settings_sections( 'image_watermark_options' );
|
151 |
Â
|
164 |
Â
</div>
|
165 |
Â
<div class="clear"></div>
|
166 |
Â
</div>';
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
167 |
Â
}
|
168 |
Â
|
169 |
Â
/**
|
170 |
Â
* Validate options.
|
171 |
+
*
|
172 |
Â
* @param array $input
|
173 |
Â
* @return array
|
174 |
Â
*/
|
268 |
Â
|
269 |
Â
/**
|
270 |
Â
* PHP extension.
|
271 |
+
*
|
272 |
+
* @return void
|
273 |
Â
*/
|
274 |
Â
public function iw_extension() {
|
275 |
Â
echo '
|
291 |
Â
|
292 |
Â
/**
|
293 |
Â
* Automatic watermarking option.
|
294 |
+
*
|
295 |
+
* @return void
|
296 |
Â
*/
|
297 |
Â
public function iw_automatic_watermarking() {
|
298 |
Â
?>
|
299 |
Â
<label for="iw_automatic_watermarking">
|
300 |
+
<input id="iw_automatic_watermarking" type="checkbox" <?php checked( ( ! empty( Image_Watermark()->options['watermark_image']['plugin_off'] ) ? 1 : 0 ), 1, true ); ?> value="1" name="iw_options[watermark_image][plugin_off]"><?php echo __( 'Enable watermark for uploaded images.', 'image-watermark' ); ?>
|
Â
|
|
301 |
Â
</label>
|
302 |
Â
<?php
|
303 |
Â
}
|
304 |
Â
|
305 |
Â
/**
|
306 |
Â
* Manual watermarking option.
|
307 |
+
*
|
308 |
+
* @return void
|
309 |
Â
*/
|
310 |
Â
public function iw_manual_watermarking() {
|
311 |
Â
?>
|
312 |
Â
<label for="iw_manual_watermarking">
|
313 |
+
<input id="iw_manual_watermarking" type="checkbox" <?php checked( ( ! empty( Image_Watermark()->options['watermark_image']['manual_watermarking'] ) ? 1 : 0 ), 1, true ); ?> value="1" name="iw_options[watermark_image][manual_watermarking]"><?php echo __( 'Enable Apply Watermark option for Media Library images.', 'image-watermark' ); ?>
|
Â
|
|
314 |
Â
</label>
|
315 |
Â
<?php
|
316 |
Â
}
|
317 |
Â
|
318 |
Â
/**
|
319 |
Â
* Enable watermark for option.
|
320 |
+
*
|
321 |
+
* @return void
|
322 |
Â
*/
|
323 |
Â
public function iw_enable_for() {
|
324 |
Â
?>
|
374 |
Â
|
375 |
Â
/**
|
376 |
Â
* Frontend watermarking option.
|
377 |
+
*
|
378 |
+
* @return void
|
379 |
Â
*/
|
380 |
Â
public function iw_frontend_watermarking() {
|
381 |
Â
?>
|
382 |
Â
<label for="iw_frontend_watermarking">
|
383 |
+
<input id="iw_frontend_watermarking" type="checkbox" <?php checked( ( ! empty( Image_Watermark()->options['watermark_image']['frontend_active'] ) ? 1 : 0 ), 1, true ); ?> value="1" name="iw_options[watermark_image][frontend_active]"><?php echo __( 'Enable frontend image uploading. (uploading script is not included, but you may use a plugin or custom code).', 'image-watermark' ); ?>
|
Â
|
|
384 |
Â
</label>
|
385 |
Â
<span class="description"><?php echo __( '<br /><strong>Notice:</strong> This functionality works only if uploaded images are processed using WordPress native upload methods.', 'image-watermark' ); ?></span>
|
386 |
Â
<?php
|
388 |
Â
|
389 |
Â
/**
|
390 |
Â
* Remove data on deactivation option.
|
391 |
+
*
|
392 |
+
* @return void
|
393 |
Â
*/
|
394 |
Â
public function iw_deactivation() {
|
395 |
Â
?>
|
396 |
Â
<label for="iw_deactivation">
|
397 |
+
<input id="iw_deactivation" type="checkbox" <?php checked( ( ! empty( Image_Watermark()->options['watermark_image']['deactivation_delete'] ) ? 1 : 0 ), 1, true ); ?> value="1" name="iw_options[watermark_image][deactivation_delete]"><?php echo __( 'Delete all database settings on plugin deactivation.', 'image-watermark' ); ?>
|
Â
|
|
398 |
Â
</label>
|
399 |
Â
<?php
|
400 |
Â
}
|
401 |
Â
|
402 |
Â
/**
|
403 |
Â
* Watermark alignment option.
|
404 |
+
*
|
405 |
+
* @return void
|
406 |
Â
*/
|
407 |
Â
public function iw_alignment() {
|
408 |
Â
?>
|
434 |
Â
|
435 |
Â
/**
|
436 |
Â
* Watermark offset unit option.
|
437 |
+
*
|
438 |
Â
* @return void
|
439 |
Â
*/
|
440 |
Â
public function iw_offset_unit() {
|
449 |
Â
|
450 |
Â
/**
|
451 |
Â
* Watermark offset option.
|
452 |
+
*
|
453 |
Â
* @return void
|
454 |
Â
*/
|
455 |
Â
public function iw_offset() {
|
465 |
Â
|
466 |
Â
/**
|
467 |
Â
* Watermark image option.
|
468 |
+
*
|
469 |
Â
* @return void
|
470 |
Â
*/
|
471 |
Â
public function iw_watermark_image() {
|
487 |
Â
|
488 |
Â
/**
|
489 |
Â
* Watermark image preview.
|
490 |
+
*
|
491 |
+
* @return void
|
492 |
Â
*/
|
493 |
Â
public function iw_watermark_preview() {
|
494 |
Â
if ( Image_Watermark()->options['watermark_image']['url'] !== NULL && Image_Watermark()->options['watermark_image']['url'] != 0 ) {
|
526 |
Â
|
527 |
Â
/**
|
528 |
Â
* Watermark size option.
|
529 |
+
*
|
530 |
+
* @return void
|
531 |
Â
*/
|
532 |
Â
public function iw_watermark_size() {
|
533 |
Â
?>
|
544 |
Â
|
545 |
Â
/**
|
546 |
Â
* Watermark custom size option.
|
547 |
+
*
|
548 |
+
* @return void
|
549 |
Â
*/
|
550 |
Â
public function iw_watermark_size_custom() {
|
551 |
Â
?>
|
560 |
Â
|
561 |
Â
/**
|
562 |
Â
* Watermark scaled size option.
|
563 |
+
*
|
564 |
+
* @return void
|
565 |
Â
*/
|
566 |
Â
public function iw_watermark_size_scaled() {
|
567 |
Â
?>
|
579 |
Â
|
580 |
Â
/**
|
581 |
Â
* Watermark custom size option.
|
582 |
+
*
|
583 |
+
* @return void
|
584 |
Â
*/
|
585 |
Â
public function iw_watermark_opacity() {
|
586 |
Â
?>
|
598 |
Â
|
599 |
Â
/**
|
600 |
Â
* Image quality option.
|
601 |
+
*
|
602 |
+
* @return void
|
603 |
Â
*/
|
604 |
Â
public function iw_image_quality() {
|
605 |
Â
?>
|
617 |
Â
|
618 |
Â
/**
|
619 |
Â
* Image format option.
|
620 |
+
*
|
621 |
+
* @return void
|
622 |
Â
*/
|
623 |
Â
public function iw_image_format() {
|
624 |
Â
?>
|
634 |
Â
|
635 |
Â
/**
|
636 |
Â
* Right click image protection option.
|
637 |
+
*
|
638 |
+
* @return void
|
639 |
Â
*/
|
640 |
Â
public function iw_protection_right_click() {
|
641 |
Â
?>
|
642 |
Â
<label for="iw_protection_right_click">
|
643 |
+
<input id="iw_protection_right_click" type="checkbox" <?php checked( ( ! empty( Image_Watermark()->options['image_protection']['rightclick'] ) ? 1 : 0 ), 1, true ); ?> value="1" name="iw_options[image_protection][rightclick]"><?php _e( 'Disable right mouse click on images', 'image-watermark' ); ?>
|
Â
|
|
644 |
Â
</label>
|
645 |
Â
<?php
|
646 |
Â
}
|
647 |
Â
|
648 |
Â
/**
|
649 |
Â
* Drag and drop image protection option.
|
650 |
+
*
|
651 |
+
* @return void
|
652 |
Â
*/
|
653 |
Â
public function iw_protection_drag_drop() {
|
654 |
Â
?>
|
655 |
Â
<label for="iw_protection_drag_drop">
|
656 |
+
<input id="iw_protection_drag_drop" type="checkbox" <?php checked( ( ! empty( Image_Watermark()->options['image_protection']['draganddrop'] ) ? 1 : 0 ), 1, true ); ?> value="1" name="iw_options[image_protection][draganddrop]"><?php _e( 'Prevent drag and drop', 'image-watermark' ); ?>
|
Â
|
|
657 |
Â
</label>
|
658 |
Â
<?php
|
659 |
Â
}
|
660 |
Â
|
661 |
Â
/**
|
662 |
Â
* Logged-in users image protection option.
|
663 |
+
*
|
664 |
+
* @return void
|
665 |
Â
*/
|
666 |
Â
public function iw_protection_logged() {
|
667 |
Â
?>
|
668 |
Â
<label for="iw_protection_logged">
|
669 |
+
<input id="iw_protection_logged" type="checkbox" <?php checked( ( ! empty( Image_Watermark()->options['image_protection']['forlogged'] ) ? 1 : 0 ), 1, true ); ?> value="1" name="iw_options[image_protection][forlogged]"><?php _e( 'Enable image protection for logged-in users also', 'image-watermark' ); ?>
|
Â
|
|
670 |
Â
</label>
|
671 |
Â
<?php
|
672 |
Â
}
|
673 |
Â
|
674 |
Â
/**
|
675 |
+
* Backup the original image.
|
676 |
+
*
|
677 |
+
* @return void
|
678 |
Â
*/
|
679 |
Â
public function iw_backup_image() {
|
680 |
Â
?>
|
681 |
Â
<label for="iw_backup_size_full">
|
682 |
+
<input id="iw_backup_size_full" type="checkbox" <?php checked( ! empty( Image_Watermark()->options['backup']['backup_image'] ), true, true ); ?> value="1" name="iw_options[backup][backup_image]"><?php echo __( 'Backup the full size image.', 'image-watermark' ); ?>
|
Â
|
|
683 |
Â
</label>
|
684 |
Â
<?php
|
685 |
Â
}
|
686 |
Â
|
687 |
Â
/**
|
688 |
Â
* Image backup quality option.
|
689 |
+
*
|
690 |
+
* @return void
|
691 |
Â
*/
|
692 |
Â
public function iw_backup_image_quality() {
|
693 |
Â
?>
|
702 |
Â
<p class="description"><?php _e( 'Set output image quality.', 'image-watermark' ); ?></p>
|
703 |
Â
<?php
|
704 |
Â
}
|
705 |
+
|
706 |
Â
/**
|
707 |
Â
* This function is similar to the function in the Settings API, only the output HTML is changed.
|
708 |
Â
* Print out the settings fields for a particular settings section
|
712 |
Â
* @since 0.1
|
713 |
Â
*
|
714 |
Â
* @param string $page Slug title of the admin page who's settings fields you want to show.
|
715 |
+
* @return void
|
716 |
Â
*/
|
717 |
Â
function do_settings_sections( $page ) {
|
718 |
Â
global $wp_settings_sections, $wp_settings_fields;
|
719 |
+
|
720 |
Â
if ( ! isset( $wp_settings_sections[$page] ) )
|
721 |
Â
return;
|
722 |
+
|
723 |
Â
foreach ( (array) $wp_settings_sections[$page] as $section ) {
|
724 |
+
echo '<div id="" class="'.$section['id'].'">';
|
725 |
+
|
726 |
Â
if ( $section['title'] )
|
727 |
+
echo "<h3><span>{$section['title']}</span></h3>\n";
|
728 |
+
|
729 |
Â
if ( $section['callback'] )
|
730 |
Â
call_user_func( $section['callback'], $section );
|
731 |
+
|
732 |
+
if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[$page] ) || ! isset( $wp_settings_fields[$page][$section['id']] ) )
|
733 |
Â
continue;
|
734 |
+
|
735 |
Â
echo '<div class="inside"><table class="form-table">';
|
736 |
+
|
737 |
Â
do_settings_fields( $page, $section['id'] );
|
738 |
+
|
739 |
+
echo '</table></div></div>';
|
740 |
Â
}
|
741 |
Â
}
|
742 |
+
}
|
Â
|
includes/class-update.php
CHANGED
@@ -22,7 +22,7 @@ class Image_Watermark_Update {
|
|
22 |
Â
|
23 |
Â
/**
|
24 |
Â
* Check if update is required.
|
25 |
-
*
|
26 |
Â
* @return void
|
27 |
Â
*/
|
28 |
Â
public function check_update() {
|
22 |
Â
|
23 |
Â
/**
|
24 |
Â
* Check if update is required.
|
25 |
+
*
|
26 |
Â
* @return void
|
27 |
Â
*/
|
28 |
Â
public function check_update() {
|
js/admin-image-actions.js
CHANGED
@@ -1,545 +1,555 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
1 |
+
( function( $ ) {
|
2 |
+
|
3 |
+
// ready event
|
4 |
+
$( function() {
|
5 |
+
/**
|
6 |
+
* wp_localize_script object: iwImageActionArgs
|
7 |
+
*
|
8 |
+
* Params:
|
9 |
+
*
|
10 |
+
* _nonce
|
11 |
+
* __applied_none => 'Watermark could not be applied to selected files or no valid images (JPEG, PNG) were selected.'
|
12 |
+
* __applied_one => 'Watermark was succesfully applied to 1 image.
|
13 |
+
* __applied_multi => 'Watermark was succesfully applied to %s images.'
|
14 |
+
* __removed_none => 'Watermark could not be removed from selected files or no valid images (JPEG, PNG) were selected.'
|
15 |
+
* __removed_one => 'Watermark was succesfully removed from 1 image.'
|
16 |
+
* __removed_multi => 'Watermark was succesfully removed from %s images.'
|
17 |
+
* __skipped => 'Skipped files'
|
18 |
+
* __running => 'Bulk action is currently running, please wait.'
|
19 |
+
* __dismiss => 'Dismiss this notice.' // Wordpress default string
|
20 |
+
*
|
21 |
+
*/
|
22 |
+
watermarkImageActions = {
|
23 |
+
running: false,
|
24 |
+
action_location: '',
|
25 |
+
action: '',
|
26 |
+
response: '',
|
27 |
+
selected: [],
|
28 |
+
successCount: 0,
|
29 |
+
skippedCount: 0,
|
30 |
+
init: function() {
|
31 |
+
// Normal (list) mode
|
32 |
+
$( document ).on( 'click', '.bulkactions input#doaction, .bulkactions input#doaction2', function( e ) {
|
33 |
+
// Get the selected bulk action
|
34 |
+
action = $( this ).parent().children( 'select' ).val();
|
35 |
+
|
36 |
+
if ( ! iwImageActionArgs.backup_image && action === 'removewatermark' )
|
37 |
+
return;
|
38 |
+
|
39 |
+
// Validate action
|
40 |
+
if ( 'applywatermark' === action || 'removewatermark' === action ) {
|
41 |
+
// Stop default
|
42 |
+
e.preventDefault();
|
43 |
+
|
44 |
+
// Is this script running?
|
45 |
+
if ( false === watermarkImageActions.running ) {
|
46 |
+
// No! set it on running
|
47 |
+
watermarkImageActions.running = true;
|
48 |
+
|
49 |
+
// store current action
|
50 |
+
watermarkImageActions.action = action;
|
51 |
+
|
52 |
+
// store current location where the action was fired
|
53 |
+
watermarkImageActions.action_location = 'upload-list';
|
54 |
+
|
55 |
+
// store selected attachment id's
|
56 |
+
$( '.wp-list-table .check-column input:checkbox:checked' ).each( function() {
|
57 |
+
watermarkImageActions.selected.push( $( this ).val() );
|
58 |
+
} );
|
59 |
+
|
60 |
+
// remove current notices
|
61 |
+
$( '.iw-notice' ).slideUp( 'fast', function() {
|
62 |
+
$( this ).remove();
|
63 |
+
} );
|
64 |
+
|
65 |
+
// begin the update!
|
66 |
+
watermarkImageActions.post_loop();
|
67 |
+
} else {
|
68 |
+
// script is running, can't run two at the same time
|
69 |
+
watermarkImageActions.notice( 'iw-notice error', iwImageActionArgs.__running, false );
|
70 |
+
}
|
71 |
+
}
|
72 |
+
} );
|
73 |
+
|
74 |
+
// Media modal or edit attachment screen mode
|
75 |
+
$( document ).on( 'click', '#image_watermark_buttons a.iw-watermark-action', function( e ) {
|
76 |
+
// Get the selected bulk action
|
77 |
+
action = $( this ).attr( 'data-action' );
|
78 |
+
id = $( this ).attr( 'data-id' );
|
79 |
+
|
80 |
+
// Validate action
|
81 |
+
if ( 'applywatermark' === action || 'removewatermark' === action && ! isNaN( id ) ) {
|
82 |
+
// Stop default
|
83 |
+
e.preventDefault();
|
84 |
+
|
85 |
+
// store current action
|
86 |
+
watermarkImageActions.action = action;
|
87 |
+
|
88 |
+
// Is this script running?
|
89 |
+
if ( false === watermarkImageActions.running ) {
|
90 |
+
// No! set it on running
|
91 |
+
watermarkImageActions.running = true;
|
92 |
+
|
93 |
+
// store current action
|
94 |
+
watermarkImageActions.action = action;
|
95 |
+
|
96 |
+
// store current location where the action was fired
|
97 |
+
if ( $( this ).parents( '.media-modal ' ).length )
|
98 |
+
watermarkImageActions.action_location = 'media-modal';
|
99 |
+
else
|
100 |
+
watermarkImageActions.action_location = 'edit';
|
101 |
+
|
102 |
+
// store attachment id
|
103 |
+
watermarkImageActions.selected.push( id );
|
104 |
+
|
105 |
+
// remove current notices
|
106 |
+
$( '.iw-notice' ).slideUp( 'fast', function() {
|
107 |
+
$( this ).remove();
|
108 |
+
} );
|
109 |
+
|
110 |
+
// begin the update!
|
111 |
+
watermarkImageActions.post_loop();
|
112 |
+
} else {
|
113 |
+
// script is running, can't run two at the same time
|
114 |
+
watermarkImageActions.notice( 'iw-notice error', iwMediaModal.__running, false );
|
115 |
+
}
|
116 |
+
}
|
117 |
+
} );
|
118 |
+
|
119 |
+
// Since these are added later we'll need to enable dismissing again
|
120 |
+
$( document ).on( 'click', '.iw-notice.is-dismissible .notice-dismiss', function() {
|
121 |
+
$( this ).parents( '.iw-notice' ).slideUp( 'fast', function() {
|
122 |
+
$( this ).remove();
|
123 |
+
} );
|
124 |
+
} );
|
125 |
+
|
126 |
+
},
|
127 |
+
post_loop: function() {
|
128 |
+
// do we have selected attachments?
|
129 |
+
if ( watermarkImageActions.selected.length ) {
|
130 |
+
// take the first id
|
131 |
+
id = watermarkImageActions.selected[ 0 ];
|
132 |
+
|
133 |
+
// check for a valid ID (needs to be numeric)
|
134 |
+
if ( ! isNaN( id ) ) {
|
135 |
+
// Show loading icon
|
136 |
+
watermarkImageActions.row_image_feedback( 'loading', id );
|
137 |
+
|
138 |
+
// post data
|
139 |
+
data = {
|
140 |
+
'_iw_nonce': iwImageActionArgs._nonce,
|
141 |
+
'action': 'iw_watermark_bulk_action',
|
142 |
+
'iw-action': watermarkImageActions.action,
|
143 |
+
'attachment_id': id
|
144 |
+
};
|
145 |
+
|
146 |
+
if ( watermarkImageActions.action_location == 'upload-list' )
|
147 |
+
watermarkImageActions.scroll_to( '#post-' + id, 'bottom' );
|
148 |
+
|
149 |
+
// the ajax post!
|
150 |
+
$.post( ajaxurl, data, function( response ) {
|
151 |
+
// show result
|
152 |
+
watermarkImageActions.result( response, id );
|
153 |
+
// remove this ID/key from the selected attachments
|
154 |
+
watermarkImageActions.selected.splice( 0, 1 );
|
155 |
+
// Redo this function
|
156 |
+
watermarkImageActions.post_loop();
|
157 |
+
|
158 |
+
$( '.iw-overlay' ).first().each( function() {
|
159 |
+
$( this ).fadeOut( 'fast', function() {
|
160 |
+
$( this ).remove();
|
161 |
+
|
162 |
+
if ( response.data === 'watermarked' ) {
|
163 |
+
$( '#image_watermark_buttons .value' ).append( '<span class="dashicons dashicons-yes" style="font-size: 24px;float: none;min-width: 28px;padding: 0;margin: 0; display: none;"></span>' );
|
164 |
+
$( '#image_watermark_buttons .value .dashicons' ).fadeIn( 'fast' );
|
165 |
+
} else if ( response.data === 'watermarkremoved' ) {
|
166 |
+
$( '#image_watermark_buttons .value' ).append( '<span class="dashicons dashicons-yes" style="font-size: 24px;float: none;min-width: 28px;padding: 0;margin: 0; display: none;"></span>' );
|
167 |
+
$( '#image_watermark_buttons .value .dashicons' ).fadeIn( 'fast' );
|
168 |
+
}
|
169 |
+
|
170 |
+
$( '#image_watermark_buttons .value .dashicons' ).delay( 1500 ).fadeOut( 'fast', function() {
|
171 |
+
$( this ).remove();
|
172 |
+
} );
|
173 |
+
} );
|
174 |
+
} );
|
175 |
+
} );
|
176 |
+
} else {
|
177 |
+
// ID is not valid so remove this key from the selected attachments
|
178 |
+
watermarkImageActions.selected.splice( 0, 1 );
|
179 |
+
// Redo this function
|
180 |
+
watermarkImageActions.post_loop();
|
181 |
+
}
|
182 |
+
} else {
|
183 |
+
// All is done, reset this "class"
|
184 |
+
watermarkImageActions.reset();
|
185 |
+
}
|
186 |
+
},
|
187 |
+
result: function( response, id ) {
|
188 |
+
// Was the ajax post successful?
|
189 |
+
if ( true === response.success ) {
|
190 |
+
// defaults
|
191 |
+
var type = false;
|
192 |
+
var message = '';
|
193 |
+
var overwrite = true;
|
194 |
+
|
195 |
+
// store response data
|
196 |
+
watermarkImageActions.response = response.data;
|
197 |
+
|
198 |
+
// Check what kind of action is done (watermarked, watermarkremoved or skipped)
|
199 |
+
switch ( response.data ) {
|
200 |
+
case 'watermarked':
|
201 |
+
// The css classes for the notice
|
202 |
+
type = 'iw-notice updated iw-watermarked';
|
203 |
+
|
204 |
+
// another successful update
|
205 |
+
watermarkImageActions.successCount += 1;
|
206 |
+
|
207 |
+
// did we have more success updates?
|
208 |
+
if ( 1 < watermarkImageActions.successCount )
|
209 |
+
message = iwImageActionArgs.__applied_multi.replace( '%s', watermarkImageActions.successCount );
|
210 |
+
else
|
211 |
+
message = iwImageActionArgs.__applied_one;
|
212 |
+
|
213 |
+
// update the row feedback
|
214 |
+
watermarkImageActions.row_image_feedback( 'success', id );
|
215 |
+
|
216 |
+
// reload the image
|
217 |
+
watermarkImageActions.reload_image( id );
|
218 |
+
break;
|
219 |
+
|
220 |
+
case 'watermarkremoved':
|
221 |
+
// The css classes for the notice
|
222 |
+
type = 'iw-notice updated iw-watermarkremoved';
|
223 |
+
|
224 |
+
// another successful update
|
225 |
+
watermarkImageActions.successCount += 1;
|
226 |
+
|
227 |
+
// did we have more success updates?
|
228 |
+
if ( 1 < watermarkImageActions.successCount )
|
229 |
+
message = iwImageActionArgs.__removed_multi.replace( '%s', watermarkImageActions.successCount );
|
230 |
+
else
|
231 |
+
message = iwImageActionArgs.__removed_one;
|
232 |
+
|
233 |
+
// update the row feedback
|
234 |
+
watermarkImageActions.row_image_feedback( 'success', id );
|
235 |
+
|
236 |
+
// reload the image
|
237 |
+
watermarkImageActions.reload_image( id );
|
238 |
+
break;
|
239 |
+
|
240 |
+
case 'skipped':
|
241 |
+
// The css classes for the notice
|
242 |
+
type = 'iw-notice error iw-skipped';
|
243 |
+
|
244 |
+
// another skipped update
|
245 |
+
watermarkImageActions.skippedCount += 1;
|
246 |
+
|
247 |
+
// adjust the message with the number of skipped updates
|
248 |
+
message = iwImageActionArgs.__skipped + ': ' + watermarkImageActions.skippedCount;
|
249 |
+
|
250 |
+
// update the row feedback
|
251 |
+
watermarkImageActions.row_image_feedback( 'error', id );
|
252 |
+
break;
|
253 |
+
|
254 |
+
default:
|
255 |
+
// The css classes for the notice
|
256 |
+
type = 'iw-notice error iw-message';
|
257 |
+
|
258 |
+
// The error message
|
259 |
+
message = response.data;
|
260 |
+
|
261 |
+
// update the row feedback
|
262 |
+
watermarkImageActions.row_image_feedback( 'error', id );
|
263 |
+
|
264 |
+
// This can be anything so don't overwrite
|
265 |
+
overwrite = false;
|
266 |
+
break;
|
267 |
+
}
|
268 |
+
|
269 |
+
if ( false !== type ) {
|
270 |
+
// we have a valid terun type, show the notice! (Overwrite current notice if available)
|
271 |
+
watermarkImageActions.notice( type, message, overwrite );
|
272 |
+
}
|
273 |
+
} else {
|
274 |
+
// No success...
|
275 |
+
watermarkImageActions.notice( 'iw-notice error', response.data, false );
|
276 |
+
|
277 |
+
// update the row feedback
|
278 |
+
watermarkImageActions.row_image_feedback( 'error', id );
|
279 |
+
}
|
280 |
+
},
|
281 |
+
row_image_feedback: function( type, id ) {
|
282 |
+
var css = { };
|
283 |
+
var cssinner = { };
|
284 |
+
var container_selector;
|
285 |
+
|
286 |
+
switch ( watermarkImageActions.action_location ) {
|
287 |
+
case 'upload-list':
|
288 |
+
container_selector = '.wp-list-table #post-' + id + ' .media-icon';
|
289 |
+
css = {
|
290 |
+
display: 'table',
|
291 |
+
width: $( container_selector ).width() + 'px',
|
292 |
+
height: $( container_selector ).height() + 'px',
|
293 |
+
top: '0',
|
294 |
+
left: '0',
|
295 |
+
position: 'absolute',
|
296 |
+
font: 'normal normal normal dashicons',
|
297 |
+
background: 'rgba(255,255,255,0.75)',
|
298 |
+
content: ''
|
299 |
+
};
|
300 |
+
cssinner = {
|
301 |
+
'vertical-align': 'middle',
|
302 |
+
'text-align': 'center',
|
303 |
+
display: 'table-cell',
|
304 |
+
width: '100%',
|
305 |
+
height: '100%',
|
306 |
+
};
|
307 |
+
break;
|
308 |
+
|
309 |
+
case 'edit':
|
310 |
+
container_selector = '.wp_attachment_holder #thumbnail-head-' + id + '';
|
311 |
+
css = {
|
312 |
+
display: 'table',
|
313 |
+
width: $( container_selector + ' img' ).width() + 'px',
|
314 |
+
height: $( container_selector + ' img' ).height() + 'px',
|
315 |
+
top: '0',
|
316 |
+
left: '0',
|
317 |
+
position: 'absolute',
|
318 |
+
font: 'normal normal normal dashicons',
|
319 |
+
background: 'rgba(255,255,255,0.75)',
|
320 |
+
content: ''
|
321 |
+
};
|
322 |
+
cssinner = {
|
323 |
+
'vertical-align': 'middle',
|
324 |
+
'text-align': 'center',
|
325 |
+
display: 'table-cell',
|
326 |
+
width: '100%',
|
327 |
+
height: '100%',
|
328 |
+
};
|
329 |
+
break;
|
330 |
+
|
331 |
+
case 'media-modal':
|
332 |
+
container_selector = '.media-modal #image_watermark_buttons[data-id="' + id + '"] .value';
|
333 |
+
css = {
|
334 |
+
'float': 'none'
|
335 |
+
};
|
336 |
+
cssinner = {
|
337 |
+
'float': 'none'
|
338 |
+
};
|
339 |
+
break;
|
340 |
+
|
341 |
+
default:
|
342 |
+
return false;
|
343 |
+
}
|
344 |
+
|
345 |
+
// css rules
|
346 |
+
$( container_selector ).css( 'position', 'relative' );
|
347 |
+
|
348 |
+
// Only create the element if it doesn't exist
|
349 |
+
if ( ! $( container_selector + ' .iw-overlay' ).length )
|
350 |
+
$( container_selector ).append( '<span class="iw-overlay"><span class="iw-overlay-inner"></span></span>' );
|
351 |
+
|
352 |
+
// Overwrite with new data
|
353 |
+
$( container_selector + ' .iw-overlay' ).css( css );
|
354 |
+
$( container_selector + ' .iw-overlay .iw-overlay-inner' ).css( cssinner );
|
355 |
+
$( container_selector + ' .iw-overlay .iw-overlay-inner' ).html( '<span class="spinner is-active"></span>' );
|
356 |
+
|
357 |
+
if ( watermarkImageActions.action_location === 'media-modal' )
|
358 |
+
$( container_selector + ' .iw-overlay .iw-overlay-inner .spinner' ).css( { 'float': 'none', 'padding': 0, 'margin': '-4px 0 0 10px' } );
|
359 |
+
},
|
360 |
+
notice: function( type, message, overwrite ) {
|
361 |
+
if ( watermarkImageActions.action_location === 'media-modal' )
|
362 |
+
return;
|
363 |
+
|
364 |
+
type += ' notice is-dismissible';
|
365 |
+
|
366 |
+
// Get the prefix based on the action location
|
367 |
+
switch ( watermarkImageActions.action_location ) {
|
368 |
+
case 'upload-list':
|
369 |
+
prefix = '.wrap > h1';
|
370 |
+
break;
|
371 |
+
|
372 |
+
default:
|
373 |
+
prefix = '#image_watermark_buttons';
|
374 |
+
}
|
375 |
+
|
376 |
+
// Overwrite the current notice?
|
377 |
+
if ( true === overwrite ) {
|
378 |
+
selector = false;
|
379 |
+
|
380 |
+
// Get the selector based on the response
|
381 |
+
switch ( watermarkImageActions.response ) {
|
382 |
+
case 'watermarked':
|
383 |
+
selector = '.iw-notice.iw-watermarked';
|
384 |
+
break;
|
385 |
+
|
386 |
+
case 'watermarkremoved':
|
387 |
+
selector = '.iw-notice.iw-watermarkremoved';
|
388 |
+
break;
|
389 |
+
|
390 |
+
case 'skipped':
|
391 |
+
selector = '.iw-notice.iw-skipped';
|
392 |
+
break;
|
393 |
+
}
|
394 |
+
|
395 |
+
// Do we have a selector and can we find it? If not, just create a new notice
|
396 |
+
if ( selector && $( '.wrap ' + selector + ' > p' ).length ) {
|
397 |
+
// Get the selector based on the action location (not not forget the ending space)
|
398 |
+
switch ( watermarkImageActions.action_location ) {
|
399 |
+
case 'upload-list':
|
400 |
+
prefix = '.wrap ';
|
401 |
+
break;
|
402 |
+
|
403 |
+
default:
|
404 |
+
prefix = '#image_watermark_buttons ';
|
405 |
+
}
|
406 |
+
|
407 |
+
$( prefix + selector + ' > p' ).html( message );
|
408 |
+
} else {
|
409 |
+
$( prefix ).after( '<div class="' + type + '" style="display: none;"><p>' + message + '</p><button type="button" class="notice-dismiss"><span class="screen-reader-text">' + iwImageActionArgs.__dismiss + '</span></button></div>' );
|
410 |
+
$( '.iw-notice' ).slideDown( 'fast' );
|
411 |
+
}
|
412 |
+
} else {
|
413 |
+
// create a new notice
|
414 |
+
$( prefix ).after( '<div class="' + type + '" style="display: none;"><p>' + message + '</p><button type="button" class="notice-dismiss"><span class="screen-reader-text">' + iwImageActionArgs.__dismiss + '</span></button></div>' );
|
415 |
+
$( '.iw-notice' ).slideDown( 'fast' );
|
416 |
+
}
|
417 |
+
},
|
418 |
+
reset: function() {
|
419 |
+
watermarkImageActions.running = false;
|
420 |
+
watermarkImageActions.action = '';
|
421 |
+
watermarkImageActions.response = '';
|
422 |
+
watermarkImageActions.selected = [];
|
423 |
+
watermarkImageActions.successCount = 0;
|
424 |
+
watermarkImageActions.skippedCount = 0;
|
425 |
+
|
426 |
+
// remove the overlay
|
427 |
+
setTimeout( function() {
|
428 |
+
$( '.iw-overlay' ).each( function() {
|
429 |
+
$( this ).fadeOut( 'fast', function() {
|
430 |
+
$( this ).remove();
|
431 |
+
} );
|
432 |
+
} );
|
433 |
+
}, 100 );
|
434 |
+
},
|
435 |
+
reload_image: function( id ) {
|
436 |
+
// reload the images
|
437 |
+
time = new Date().getTime();
|
438 |
+
selector = false;
|
439 |
+
|
440 |
+
// Get the selector based on the action location
|
441 |
+
switch ( watermarkImageActions.action_location ) {
|
442 |
+
case 'upload-list':
|
443 |
+
selector = '.wp-list-table #post-' + id + ' .image-icon img';
|
444 |
+
break;
|
445 |
+
|
446 |
+
case 'media-modal':
|
447 |
+
selector = '.attachment-details[data-id="' + id + '"] img, .attachment[data-id="' + id + '"] img';
|
448 |
+
break;
|
449 |
+
|
450 |
+
case 'edit':
|
451 |
+
selector = '.wp_attachment_holder img';
|
452 |
+
break;
|
453 |
+
}
|
454 |
+
|
455 |
+
if ( selector ) {
|
456 |
+
image = $( selector );
|
457 |
+
image.each( function() {
|
458 |
+
// Remove the responsive metadata, this prevents reloading the image
|
459 |
+
$( this ).removeAttr( 'srcset' );
|
460 |
+
$( this ).removeAttr( 'sizes' );
|
461 |
+
|
462 |
+
// Reload the image (actually a browser hack by adding a time parameter to the image)
|
463 |
+
$( this ).attr( 'src', watermarkImageActions.replace_url_param( $( this ).attr( 'src' ), 't', time ) );
|
464 |
+
} );
|
465 |
+
}
|
466 |
+
},
|
467 |
+
rotate_icon: function( icon ) {
|
468 |
+
// This function accepts selectors and objects
|
469 |
+
if ( typeof icon == 'string' )
|
470 |
+
icon = $( icon );
|
471 |
+
|
472 |
+
// Check for the length of the selected object.
|
473 |
+
if ( $( icon.selector ).length ) {
|
474 |
+
// Set rotation to 0
|
475 |
+
icon.css( {
|
476 |
+
'-webkit-transform': 'rotate(0deg)',
|
477 |
+
'-ms-transform': 'rotate(0deg)',
|
478 |
+
'transform': 'rotate(0deg)',
|
479 |
+
'borderSpacing': '0',
|
480 |
+
} );
|
481 |
+
|
482 |
+
// Do animation (one rotation)
|
483 |
+
icon.animate(
|
484 |
+
{ borderSpacing: 360 },
|
485 |
+
{
|
486 |
+
duration: 1000,
|
487 |
+
step: function( now, fx ) {
|
488 |
+
$( this ).css( '-webkit-transform', 'rotate(' + now + 'deg)' );
|
489 |
+
$( this ).css( '-ms-transform', 'rotate(' + now + 'deg)' );
|
490 |
+
$( this ).css( 'transform', 'rotate(' + now + 'deg)' );
|
491 |
+
|
492 |
+
if ( now == 360 ) {
|
493 |
+
// Animation finished, stop loop and restart
|
494 |
+
icon.stop();
|
495 |
+
watermarkImageActions.rotate_icon( icon );
|
496 |
+
}
|
497 |
+
}
|
498 |
+
}
|
499 |
+
);
|
500 |
+
}
|
501 |
+
},
|
502 |
+
replace_url_param: function( url, paramName, paramValue ) {
|
503 |
+
var pattern = new RegExp( '\\b(' + paramName + '=).*?(&|$)' );
|
504 |
+
|
505 |
+
if ( url.search( pattern ) >= 0 )
|
506 |
+
return url.replace( pattern, '$1' + paramValue + '$2' );
|
507 |
+
|
508 |
+
return url + ( url.indexOf( '?' ) > 0 ? '&' : '?' ) + paramName + '=' + paramValue;
|
509 |
+
},
|
510 |
+
scroll_to: function( elementSelector, verticalTarget ) {
|
511 |
+
var offset = $( elementSelector ).offset();
|
512 |
+
var offsetTop = offset.top;
|
513 |
+
|
514 |
+
// If the element it above the current viewport, scroll to it
|
515 |
+
if ( offset.top < $( window ).scrollTop() ) {
|
516 |
+
$( window ).scrollTop( offsetTop );
|
517 |
+
|
518 |
+
return; // No further actions needed
|
519 |
+
}
|
520 |
+
|
521 |
+
var windowTopOffset = $( window ).scrollTop();
|
522 |
+
var windowBottomOffset = windowTopOffset + $( window ).outerHeight();
|
523 |
+
|
524 |
+
switch ( verticalTarget ) {
|
525 |
+
case 'top':
|
526 |
+
offsetTop = offsetTop - $( elementSelector ).outerHeight();
|
527 |
+
break;
|
528 |
+
|
529 |
+
case 'bottom':
|
530 |
+
if ( offset.top < windowBottomOffset )
|
531 |
+
return; // The element is in the viewport
|
532 |
+
|
533 |
+
offsetTop = offsetTop - $( window ).outerHeight();
|
534 |
+
offsetTop = offsetTop + $( elementSelector ).outerHeight();
|
535 |
+
break;
|
536 |
+
|
537 |
+
case 'center':
|
538 |
+
if ( offsetTop < windowBottomOffset && offsetTop >= windowTopOffset )
|
539 |
+
return; // The element is in the viewport
|
540 |
+
|
541 |
+
offsetTop = offsetTop - ( $( window ).outerHeight() / 2 );
|
542 |
+
offsetTop = offsetTop + ( $( elementSelector ).outerHeight() / 2 );
|
543 |
+
break;
|
544 |
+
}
|
545 |
+
|
546 |
+
$( window ).scrollTop( offsetTop );
|
547 |
+
}
|
548 |
+
};
|
549 |
+
|
550 |
+
// We need that nonce!
|
551 |
+
if ( typeof iwImageActionArgs._nonce !== 'undefined' )
|
552 |
+
watermarkImageActions.init();
|
553 |
+
} );
|
554 |
+
|
555 |
+
} )( jQuery );
|
js/admin-settings.js
CHANGED
@@ -1,88 +1,90 @@
|
|
1 |
-
|
2 |
Â
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
Â
|
|
11 |
Â
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
Â
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
Â
|
27 |
-
|
28 |
Â
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
Â
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
Â
|
45 |
-
|
46 |
Â
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
Â
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
Â
|
63 |
-
|
64 |
Â
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
Â
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
Â
|
81 |
-
|
82 |
Â
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
Â
|
|
87 |
Â
|
88 |
-
} );
|
1 |
+
( function( $ ) {
|
2 |
Â
|
3 |
+
// ready event
|
4 |
+
$( function() {
|
5 |
+
// enable watermark for
|
6 |
+
$( document ).on( 'change', '#df_option_everywhere, #df_option_cpt', function() {
|
7 |
+
if ( $( '#cpt-specific input[type=radio]:checked' ).val() === 'everywhere' )
|
8 |
+
$( '#cpt-select' ).fadeOut( 300 );
|
9 |
+
else if ( $( '#cpt-specific input[type=radio]:checked' ).val() === 'specific' )
|
10 |
+
$( '#cpt-select' ).fadeIn( 300 );
|
11 |
+
} );
|
12 |
Â
|
13 |
+
$( document ).on( 'click', '#reset_image_watermark_options', function() {
|
14 |
+
return confirm( iwArgs.resetToDefaults );
|
15 |
+
} );
|
16 |
Â
|
17 |
+
// size slider
|
18 |
+
$( '#iw_size_span' ).slider( {
|
19 |
+
value: $( '#iw_size_input' ).val(),
|
20 |
+
min: 0,
|
21 |
+
max: 100,
|
22 |
+
step: 1,
|
23 |
+
orientation: 'horizontal',
|
24 |
+
slide: function( e, ui ) {
|
25 |
+
$( '#iw_size_input' ).attr( 'value', ui.value );
|
26 |
+
$( '#iw_size_span' ).attr( 'title', ui.value );
|
27 |
Â
|
28 |
+
var element = $( ui.handle ).prev( '.iw-current-value' );
|
29 |
Â
|
30 |
+
element.text( ui.value );
|
31 |
+
element.css( 'left', ui.value + '%' );
|
32 |
+
}
|
33 |
+
} );
|
34 |
Â
|
35 |
+
// opacity slider
|
36 |
+
$( '#iw_opacity_span' ).slider( {
|
37 |
+
value: $( '#iw_opacity_input' ).val(),
|
38 |
+
min: 0,
|
39 |
+
max: 100,
|
40 |
+
step: 1,
|
41 |
+
orientation: 'horizontal',
|
42 |
+
slide: function( e, ui ) {
|
43 |
+
$( '#iw_opacity_input' ).attr( 'value', ui.value );
|
44 |
+
$( '#iw_opacity_span' ).attr( 'title', ui.value );
|
45 |
Â
|
46 |
+
var element = $( ui.handle ).prev( '.iw-current-value' );
|
47 |
Â
|
48 |
+
element.text( ui.value );
|
49 |
+
element.css( 'left', ui.value + '%' );
|
50 |
+
}
|
51 |
+
} );
|
52 |
Â
|
53 |
+
// quality slider
|
54 |
+
$( '#iw_quality_span' ).slider( {
|
55 |
+
value: $( '#iw_quality_input' ).val(),
|
56 |
+
min: 0,
|
57 |
+
max: 100,
|
58 |
+
step: 1,
|
59 |
+
orientation: 'horizontal',
|
60 |
+
slide: function( e, ui ) {
|
61 |
+
$( '#iw_quality_input' ).attr( 'value', ui.value );
|
62 |
+
$( '#iw_quality_span' ).attr( 'title', ui.value );
|
63 |
Â
|
64 |
+
var element = $( ui.handle ).prev( '.iw-current-value' );
|
65 |
Â
|
66 |
+
element.text( ui.value );
|
67 |
+
element.css( 'left', ui.value + '%' );
|
68 |
+
}
|
69 |
+
} );
|
70 |
Â
|
71 |
+
// backup quality slider
|
72 |
+
$( '#iw_backup_quality_span' ).slider( {
|
73 |
+
value: $( '#iw_backup_quality_input' ).val(),
|
74 |
+
min: 0,
|
75 |
+
max: 100,
|
76 |
+
step: 1,
|
77 |
+
orientation: 'horizontal',
|
78 |
+
slide: function( e, ui ) {
|
79 |
+
$( '#iw_backup_quality_input' ).attr( 'value', ui.value );
|
80 |
+
$( '#iw_backup_quality_span' ).attr( 'title', ui.value );
|
81 |
Â
|
82 |
+
var element = $( ui.handle ).prev( '.iw-current-value' );
|
83 |
Â
|
84 |
+
element.text( ui.value );
|
85 |
+
element.css( 'left', ui.value + '%' );
|
86 |
+
}
|
87 |
+
} );
|
88 |
+
} );
|
89 |
Â
|
90 |
+
} )( jQuery );
|
js/admin-upload.js
CHANGED
@@ -1,70 +1,70 @@
|
|
1 |
-
|
2 |
Â
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
Â
|
|
Â
|
|
7 |
Â
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
Â
|
18 |
-
|
19 |
-
return this._frameWatermark;
|
20 |
-
},
|
21 |
-
select: function () {
|
22 |
-
var attachment = this.frame.state().get( 'selection' ).first();
|
23 |
Â
|
24 |
-
|
Â
|
|
Â
|
|
Â
|
|
25 |
Â
|
26 |
-
|
Â
|
|
27 |
Â
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
}
|
33 |
Â
|
34 |
-
|
35 |
-
|
36 |
Â
|
37 |
-
|
38 |
-
img.src = attachment.attributes.url;
|
39 |
Â
|
40 |
-
|
41 |
-
$( 'p#previewImageInfo' ).html( iwUploadArgs.originalSize + ': ' + this.width + ' ' + iwUploadArgs.px + ' / ' + this.height + ' ' + iwUploadArgs.px );
|
42 |
-
}
|
43 |
Â
|
44 |
-
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
45 |
Â
|
46 |
-
|
47 |
-
$( '#iw_upload_image' ).val( 0 );
|
48 |
-
$( 'div#previewImg_imageDiv img#previewImg_image' ).attr( 'src', '' ).hide();
|
49 |
-
$( 'p#previewImageInfo' ).html( '<strong>' + iwUploadArgs.notAllowedImg + '</strong>' );
|
50 |
Â
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
}
|
59 |
-
};
|
60 |
Â
|
61 |
-
|
62 |
-
|
63 |
-
$( document ).on( 'click', '#iw_turn_off_image_button', function ( event ) {
|
64 |
-
$( this ).attr( 'disabled', 'true' );
|
65 |
-
$( '#iw_upload_image' ).val( 0 );
|
66 |
-
$( 'div#previewImg_imageDiv img#previewImg_image' ).attr( 'src', '' ).hide();
|
67 |
-
$( 'p#previewImageInfo' ).html( iwUploadArgs.noSelectedImg );
|
68 |
-
} );
|
69 |
-
|
70 |
-
} );
|
1 |
+
( function( $ ) {
|
2 |
Â
|
3 |
+
// ready event
|
4 |
+
$( function() {
|
5 |
+
watermarkFileUpload = {
|
6 |
+
frame: function() {
|
7 |
+
if ( this._frameWatermark )
|
8 |
+
return this._frameWatermark;
|
9 |
Â
|
10 |
+
this._frameWatermark = wp.media( {
|
11 |
+
title: iwUploadArgs.title,
|
12 |
+
frame: iwUploadArgs.frame,
|
13 |
+
button: iwUploadArgs.button,
|
14 |
+
multiple: iwUploadArgs.multiple,
|
15 |
+
library: {
|
16 |
+
type: 'image'
|
17 |
+
}
|
18 |
+
} );
|
19 |
Â
|
20 |
+
this._frameWatermark.on( 'open', this.updateFrame ).state( 'library' ).on( 'select', this.select );
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
21 |
Â
|
22 |
+
return this._frameWatermark;
|
23 |
+
},
|
24 |
+
select: function() {
|
25 |
+
var attachment = this.frame.state().get( 'selection' ).first();
|
26 |
Â
|
27 |
+
if ( $.inArray( attachment.attributes.mime, [ 'image/gif', 'image/jpg', 'image/jpeg', 'image/png' ] ) !== -1 ) {
|
28 |
+
$( '#iw_upload_image' ).val( attachment.attributes.id );
|
29 |
Â
|
30 |
+
if ( $( 'div#previewImg_imageDiv img#previewImg_image' ).attr( 'src' ) !== '' )
|
31 |
+
$( 'div#previewImg_imageDiv img#previewImg_image' ).replaceWith( '<img id="previewImg_image" src="' + attachment.attributes.url + '" alt="" width="300" />' );
|
32 |
+
else
|
33 |
+
$( 'div#previewImg_imageDiv img#previewImg_image' ).attr( 'src', attachment.attributes.url );
|
Â
|
|
34 |
Â
|
35 |
+
$( '#iw_turn_off_image_button' ).removeAttr( 'disabled' );
|
36 |
+
$( 'div#previewImg_imageDiv img#previewImg_image' ).show();
|
37 |
Â
|
38 |
+
var img = new Image();
|
Â
|
|
39 |
Â
|
40 |
+
img.src = attachment.attributes.url;
|
Â
|
|
Â
|
|
41 |
Â
|
42 |
+
img.onload = function() {
|
43 |
+
$( 'p#previewImageInfo' ).html( iwUploadArgs.originalSize + ': ' + this.width + ' ' + iwUploadArgs.px + ' / ' + this.height + ' ' + iwUploadArgs.px );
|
44 |
+
}
|
45 |
+
} else {
|
46 |
+
$( '#iw_turn_off_image_button' ).attr( 'disabled', 'true' );
|
47 |
+
$( '#iw_upload_image' ).val( 0 );
|
48 |
+
$( 'div#previewImg_imageDiv img#previewImg_image' ).attr( 'src', '' ).hide();
|
49 |
+
$( 'p#previewImageInfo' ).html( '<strong>' + iwUploadArgs.notAllowedImg + '</strong>' );
|
50 |
+
}
|
51 |
+
},
|
52 |
+
init: function() {
|
53 |
+
$( '#wpbody' ).on( 'click', 'input#iw_upload_image_button', function( e ) {
|
54 |
+
e.preventDefault();
|
55 |
+
watermarkFileUpload.frame().open();
|
56 |
+
} );
|
57 |
+
}
|
58 |
+
};
|
59 |
Â
|
60 |
+
watermarkFileUpload.init();
|
Â
|
|
Â
|
|
Â
|
|
61 |
Â
|
62 |
+
$( document ).on( 'click', '#iw_turn_off_image_button', function() {
|
63 |
+
$( this ).attr( 'disabled', 'true' );
|
64 |
+
$( '#iw_upload_image' ).val( 0 );
|
65 |
+
$( 'div#previewImg_imageDiv img#previewImg_image' ).attr( 'src', '' ).hide();
|
66 |
+
$( 'p#previewImageInfo' ).html( iwUploadArgs.noSelectedImg );
|
67 |
+
} );
|
68 |
+
} );
|
Â
|
|
Â
|
|
69 |
Â
|
70 |
+
} )( jQuery );
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
readme.txt
CHANGED
@@ -1,191 +1,197 @@
|
|
1 |
-
=== Image Watermark ===
|
2 |
-
Contributors: dfactory
|
3 |
-
Donate link: http://www.dfactory.eu/
|
4 |
-
Tags: image, images, picture, photo, watermark, watermarking, protection, image protection, image security
|
5 |
-
Requires at least: 4.
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
License
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
*
|
23 |
-
*
|
24 |
-
*
|
25 |
-
*
|
26 |
-
*
|
27 |
-
*
|
28 |
-
*
|
29 |
-
*
|
30 |
-
* Select
|
31 |
-
*
|
32 |
-
*
|
33 |
-
*
|
34 |
-
*
|
35 |
-
*
|
36 |
-
* Disable
|
37 |
-
*
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
*
|
80 |
-
* Tweak:
|
81 |
-
|
82 |
-
= 1.6.
|
83 |
-
*
|
84 |
-
*
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
*
|
89 |
-
*
|
90 |
-
|
91 |
-
= 1.5.
|
92 |
-
*
|
93 |
-
*
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
*
|
111 |
-
* Tweak:
|
112 |
-
|
113 |
-
= 1.
|
114 |
-
*
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
* Fix:
|
132 |
-
|
133 |
-
= 1.
|
134 |
-
*
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
* New:
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
* New:
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
*
|
150 |
-
|
151 |
-
= 1.1.
|
152 |
-
* New:
|
153 |
-
*
|
154 |
-
* Fix:
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
* New:
|
159 |
-
* Fix:
|
160 |
-
*
|
161 |
-
|
162 |
-
= 1.1.
|
163 |
-
* New:
|
164 |
-
*
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
*
|
169 |
-
*
|
170 |
-
|
171 |
-
|
172 |
-
*
|
173 |
-
*
|
174 |
-
|
175 |
-
|
176 |
-
*
|
177 |
-
* Tweak:
|
178 |
-
* Tweak:
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
*
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
= 1.
|
191 |
-
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
1 |
+
=== Image Watermark ===
|
2 |
+
Contributors: dfactory
|
3 |
+
Donate link: http://www.dfactory.eu/
|
4 |
+
Tags: image, images, picture, photo, watermark, watermarking, protection, image protection, image security
|
5 |
+
Requires at least: 4.3
|
6 |
+
Requires PHP: 5.3
|
7 |
+
Tested up to: 5.9.1
|
8 |
+
Stable tag: 1.7.0
|
9 |
+
License: MIT License
|
10 |
+
License URI: http://opensource.org/licenses/MIT
|
11 |
+
|
12 |
+
Image Watermark allows you to automatically watermark images uploaded to the WordPress Media Library and bulk watermark previously uploaded images.
|
13 |
+
|
14 |
+
== Description ==
|
15 |
+
|
16 |
+
[Image Watermark](http://www.dfactory.eu/plugins/image-watermark/) allows you to automatically watermark images uploaded to the WordPress Media Library and bulk watermark previously uploaded images.
|
17 |
+
|
18 |
+
For more information, check out plugin page at [dFactory](http://www.dfactory.eu/), [documentation page](https://www.dfactory.eu/docs/image-watermark-plugin/) or plugin [support forum](http://www.dfactory.eu/support/forum/image-watermark/).
|
19 |
+
|
20 |
+
= Features include: =
|
21 |
+
|
22 |
+
* Bulk watermark - Apply watermark option in Media Library actions
|
23 |
+
* Watermark images already uploaded to Media Library
|
24 |
+
* GD LIbrary and ImageMagic support
|
25 |
+
* Image backup functionality
|
26 |
+
* Option to remove watermark
|
27 |
+
* Flexible watermark position
|
28 |
+
* Watermark image preview
|
29 |
+
* Set watermark offset
|
30 |
+
* Select post types where watermark will be aplied to uploaded images or select adding watermark during any image upload
|
31 |
+
* Select from 3 methods of aplying watermark size: original, custom or scaled
|
32 |
+
* Set watermark transparency / opacity
|
33 |
+
* Select image format (baseline or progressive)
|
34 |
+
* Set image quality
|
35 |
+
* Protect your images from copying via drag&drop
|
36 |
+
* Disable right mouse click on images
|
37 |
+
* Disable image protection for logged-in users
|
38 |
+
* .pot file for translations included
|
39 |
+
|
40 |
+
== Installation ==
|
41 |
+
|
42 |
+
1. Install Image Watermark either via the WordPress.org plugin directory, or by uploading the files to your server
|
43 |
+
2. Activate the plugin through the 'Plugins' menu in WordPress
|
44 |
+
3. Go to the Watermark menu in Settings and set your watermarking options.
|
45 |
+
4. Enable watermark to apply watermark to uploaded images or go to Media Library to apply watermark to previously uploaded images
|
46 |
+
|
47 |
+
== Frequently Asked Questions ==
|
48 |
+
|
49 |
+
No questions yet.
|
50 |
+
|
51 |
+
== Screenshots ==
|
52 |
+
|
53 |
+
1. screenshot-1.png
|
54 |
+
2. screenshot-2.png
|
55 |
+
|
56 |
+
== Changelog ==
|
57 |
+
|
58 |
+
= 1.7.0 =
|
59 |
+
* Tweak: WordPress 5.9 compatibility
|
60 |
+
* Tweak: PHP 8.x compatibility
|
61 |
+
|
62 |
+
= 1.6.6 =
|
63 |
+
* Tweak: PHP 7.3 compatibility
|
64 |
+
|
65 |
+
= 1.6.5 =
|
66 |
+
* Fix: Improved support for PHP 7 and above
|
67 |
+
* Fix: Backup folders handling of date based organized uploads
|
68 |
+
|
69 |
+
= 1.6.4 =
|
70 |
+
* Fix: Transparent PNG issues with ImageMagic library
|
71 |
+
|
72 |
+
= 1.6.3.1 =
|
73 |
+
* Fix: The plugin directory upload fix.
|
74 |
+
|
75 |
+
= 1.6.3 =
|
76 |
+
* Fix: PNG files watermarking issue
|
77 |
+
|
78 |
+
= 1.6.2 =
|
79 |
+
* New: Option to select watermark offset unit - pixels or percentages
|
80 |
+
* Tweak: Added values to slider settings fields
|
81 |
+
|
82 |
+
= 1.6.1 =
|
83 |
+
* Fix: Minor bug with AJAX requests, thanks to [JoryHogeveen](https://github.com/JoryHogeveen)
|
84 |
+
* Fix: Prevent watermarking the watermark image, thanks to [JoryHogeveen](https://github.com/JoryHogeveen)
|
85 |
+
* Tweak: Code cleanup
|
86 |
+
|
87 |
+
= 1.6.0 =
|
88 |
+
* New: Image backup functionality, thanks to [JoryHogeveen](https://github.com/JoryHogeveen)
|
89 |
+
* New: Option to remove watermark (if backup is available)
|
90 |
+
|
91 |
+
= 1.5.6 =
|
92 |
+
* New: PHP image processing library option, if more than one available.
|
93 |
+
* Fix: Manual / Media library watermarking not working.
|
94 |
+
* Fix: Image sizes not being generated proparly in GD library.
|
95 |
+
|
96 |
+
= 1.5.5 =
|
97 |
+
* Fix: Determine AJAX frontend or backend request
|
98 |
+
* Tweak: Remove Polish and Russian translations, in favor of GlotPress
|
99 |
+
|
100 |
+
= 1.5.4 =
|
101 |
+
* Fix: Use of undefined constant DOING_AJAX
|
102 |
+
|
103 |
+
= 1.5.3 =
|
104 |
+
* New: ImageMagic support
|
105 |
+
|
106 |
+
= 1.5.2 =
|
107 |
+
* Tweak: Switch from wp_get_referer() to DOING_AJAX and is_admin().
|
108 |
+
|
109 |
+
= 1.5.1 =
|
110 |
+
* New: Introducing [plugin documentation](https://www.dfactory.eu/docs/image-watermark-plugin/)
|
111 |
+
* Tweak: Improved transparent watermark support
|
112 |
+
|
113 |
+
= 1.5.0 =
|
114 |
+
* Tweak: Plugins setting adjusted to WP settings API
|
115 |
+
* Tweak: General code cleanup
|
116 |
+
* Tweak: Added Media Library bulk watermarking notice
|
117 |
+
|
118 |
+
= 1.4.1 =
|
119 |
+
* New: Hungarian translation, thanks to Meszaros Tamas
|
120 |
+
|
121 |
+
= 1.4.0 =
|
122 |
+
* New: Option to donate this plugin :)
|
123 |
+
|
124 |
+
= 1.3.3 =
|
125 |
+
* New: RUssian translation, thanks to [Sly](http://wpguru.ru)
|
126 |
+
|
127 |
+
= 1.3.2 =
|
128 |
+
* New: Chinese translation, thanks to [xiaoyaole](http://www.luoxiao123.cn/)
|
129 |
+
|
130 |
+
= 1.3.1 =
|
131 |
+
* Fix: Option to disable right click on images not working
|
132 |
+
|
133 |
+
= 1.3.0 =
|
134 |
+
* Tweak: Manual watermarking now works even if selected post types are selected
|
135 |
+
* Tweak: UI improvements for WP 3.8
|
136 |
+
* Fix: Image protection options not saving properly
|
137 |
+
|
138 |
+
= 1.2.1 =
|
139 |
+
* New: German translation, thanks to Matthias Siebler
|
140 |
+
|
141 |
+
= 1.2.0 =
|
142 |
+
* New: Frontend watermarking option (for front-end upload plugins and custom front-end upload code)
|
143 |
+
* New: Introducing iw_watermark_display filter
|
144 |
+
* New: Option to delete all plugin data on deactivation
|
145 |
+
* Tweak: Rewritten watermark application method
|
146 |
+
* Tweak: UI enhancements for settings page
|
147 |
+
|
148 |
+
= 1.1.4 =
|
149 |
+
* New: Arabic translation, thanks to Hassan Hisham
|
150 |
+
|
151 |
+
= 1.1.3 =
|
152 |
+
* New: Introducing API hooks: iw_before_apply_watermark, iw_after_apply_watermark, iw_watermark_options
|
153 |
+
* Fix: Wrong watermark watermark path
|
154 |
+
* Fix: Final fix (hopefully) for getimagesize() error
|
155 |
+
|
156 |
+
= 1.1.2 =
|
157 |
+
* New: Image quality option
|
158 |
+
* New: Image format selection (progressive or baseline)
|
159 |
+
* Fix: Error when getimagesize() is not available on some servers
|
160 |
+
* Tweak: Files & class naming conventions
|
161 |
+
|
162 |
+
= 1.1.1 =
|
163 |
+
* New: Added option to enable or disable manual watermarking in Media Library
|
164 |
+
* Fix: Apply watermark option not visible in Media Library actions
|
165 |
+
* Fix: Warning on full size images
|
166 |
+
|
167 |
+
= 1.1.0 =
|
168 |
+
* New: Bulk watermark - Apply watermark in Media Library actions
|
169 |
+
* New: Watermark images already uploaded to Media Library
|
170 |
+
|
171 |
+
= 1.0.3 =
|
172 |
+
* Fix: Error during upload of file types other than images (png, jpg)
|
173 |
+
* Fix: Limit watermark file types to png, gif, jpg
|
174 |
+
* Tweak: Validation for watermark size and transparency values
|
175 |
+
* Tweak: Remove unnecessary functions
|
176 |
+
* Tweak: Code cleanup
|
177 |
+
* Tweak: Added more code comments
|
178 |
+
* Tweak: Small css changes
|
179 |
+
|
180 |
+
= 1.0.2 =
|
181 |
+
* New: Add watermark to custom images sizes registered in theme
|
182 |
+
* Tweak: Admin notices on settings page if no watermark image selected
|
183 |
+
* Tweak: JavaScript enquequing on front-end
|
184 |
+
* Tweak: General code cleanup
|
185 |
+
* Tweak: Changed label for enabling image protection for logged-in users
|
186 |
+
|
187 |
+
= 1.0.1 =
|
188 |
+
* Fix: Using image ID instead of image URL during image upload
|
189 |
+
|
190 |
+
= 1.0.0 =
|
191 |
+
Initial release
|
192 |
+
|
193 |
+
== Upgrade Notice ==
|
194 |
+
|
195 |
+
= 1.7.0 =
|
196 |
+
* Tweak: WordPress 5.9 compatibility
|
197 |
+
* Tweak: PHP 8.x compatibility
|