Version Description
- Fix: Improved support for PHP 7 and above
- Fix: Backup folders handling of date based organized uploads
Download this release
Release Info
Developer | dfactory |
Plugin | Image Watermark |
Version | 1.6.5 |
Comparing to | |
See all releases |
Code changes from version 1.6.4 to 1.6.5
- image-watermark.php +49 -23
- readme.txt +9 -4
image-watermark.php
CHANGED
@@ -2,7 +2,7 @@
|
|
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.
|
6 |
Author: dFactory
|
7 |
Author URI: http://www.dfactory.eu/
|
8 |
Plugin URI: http://www.dfactory.eu/plugins/image-watermark/
|
@@ -12,7 +12,7 @@ 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 |
|
@@ -32,7 +32,7 @@ define( 'IMAGE_WATERMARK_PATH', plugin_dir_path( __FILE__ ) );
|
|
32 |
* Image Watermark class.
|
33 |
*
|
34 |
* @class Image_Watermark
|
35 |
-
* @version 1.6.
|
36 |
*/
|
37 |
final class Image_Watermark {
|
38 |
|
@@ -81,7 +81,7 @@ final class Image_Watermark {
|
|
81 |
'backup_quality' => 90
|
82 |
)
|
83 |
),
|
84 |
-
'version' => '1.6.
|
85 |
);
|
86 |
public $options = array();
|
87 |
|
@@ -129,7 +129,6 @@ final class Image_Watermark {
|
|
129 |
|
130 |
// create backup folder and security if enabled
|
131 |
if ( $this->options['backup']['backup_image'] ) {
|
132 |
-
|
133 |
if ( is_writable( $upload_dir['basedir'] ) ) {
|
134 |
$this->is_backup_folder_writable = true;
|
135 |
|
@@ -143,13 +142,12 @@ final class Image_Watermark {
|
|
143 |
// htaccess security
|
144 |
file_put_contents( IMAGE_WATERMARK_BACKUP_DIR . DIRECTORY_SEPARATOR . '.htaccess', 'deny from all' );
|
145 |
}
|
146 |
-
} else
|
147 |
$this->is_backup_folder_writable = false;
|
148 |
-
|
149 |
-
} else {
|
150 |
$this->is_backup_folder_writable = false;
|
151 |
-
|
152 |
-
if (
|
153 |
// disable backup setting
|
154 |
$this->options['backup']['backup_image'] = false;
|
155 |
update_option( 'image_watermark_options', $this->options );
|
@@ -435,12 +433,12 @@ wp-logo-jpg + +
|
|
435 |
|
436 |
// admin
|
437 |
if ( $this->is_admin === true ) {
|
438 |
-
if ( $this->options['watermark_image']['plugin_off'] == 1 && $this->options['watermark_image']['url']
|
439 |
add_filter( 'wp_generate_attachment_metadata', array( $this, 'apply_watermark' ), 10, 2 );
|
440 |
}
|
441 |
// frontend
|
442 |
} else {
|
443 |
-
if ( $this->options['watermark_image']['frontend_active'] == 1 && $this->options['watermark_image']['url']
|
444 |
add_filter( 'wp_generate_attachment_metadata', array( $this, 'apply_watermark' ), 10, 2 );
|
445 |
}
|
446 |
}
|
@@ -504,7 +502,7 @@ wp-logo-jpg + +
|
|
504 |
|
505 |
// only if manual watermarking is turned and we have a valid action
|
506 |
// if the action is NOT "removewatermark" we also require a watermark image to be set
|
507 |
-
if ( $post_id > 0 && $action && $this->options['watermark_image']['manual_watermarking'] == 1 && ( $this->options['watermark_image']['url']
|
508 |
$data = wp_get_attachment_metadata( $post_id, false );
|
509 |
|
510 |
// is this really an image?
|
@@ -554,7 +552,7 @@ wp-logo-jpg + +
|
|
554 |
|
555 |
// only if manual watermarking is turned and we have a valid action
|
556 |
// if the action is NOT "removewatermark" we also require a watermark image to be set
|
557 |
-
if ( $action && $this->options['watermark_image']['manual_watermarking'] == 1 && ( $this->options['watermark_image']['url']
|
558 |
// security check
|
559 |
check_admin_referer( 'bulk-media' );
|
560 |
|
@@ -716,10 +714,11 @@ wp-logo-jpg + +
|
|
716 |
* @return array
|
717 |
*/
|
718 |
public function apply_watermark( $data, $attachment_id, $method = '' ) {
|
719 |
-
$
|
|
|
720 |
$post_id = ( ! empty( $post ) ? (int) $post->post_parent : 0 );
|
721 |
|
722 |
-
if ( $attachment_id
|
723 |
// this is the current watermark, do not apply
|
724 |
return array( 'error' => __( 'Watermark prevented, this is your selected watermark image', 'image-watermark' ) );
|
725 |
}
|
@@ -901,11 +900,11 @@ wp-logo-jpg + +
|
|
901 |
$exifadded = ! $exifdata;
|
902 |
$iptcadded = ! $iptcdata;
|
903 |
|
904 |
-
while ( ( substr( $destfilecontent, 0, 2 ) & 0xFFF0 ) === 0xFFE0 ) {
|
905 |
-
$segmentlen = ( substr( $destfilecontent, 2, 2 ) & 0xFFFF );
|
906 |
|
907 |
// last 4 bits of second byte is IPTC segment
|
908 |
-
$iptcsegmentnumber = ( substr( $destfilecontent, 1, 1 ) & 0x0F );
|
909 |
|
910 |
if ( $segmentlen <= 2 )
|
911 |
return false;
|
@@ -952,6 +951,21 @@ wp-logo-jpg + +
|
|
952 |
return false;
|
953 |
}
|
954 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
955 |
/**
|
956 |
* Apply watermark to image.
|
957 |
*
|
@@ -968,6 +982,9 @@ wp-logo-jpg + +
|
|
968 |
// get image mime type
|
969 |
$mime = wp_check_filetype( $image_path );
|
970 |
|
|
|
|
|
|
|
971 |
// get watermark path
|
972 |
$watermark_file = wp_get_attachment_metadata( $options['watermark_image']['url'], true );
|
973 |
$watermark_path = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $watermark_file['file'];
|
@@ -1071,10 +1088,16 @@ wp-logo-jpg + +
|
|
1071 |
// get image resource
|
1072 |
$image = $this->get_image_resource( $filepath, $mime['type'] );
|
1073 |
|
1074 |
-
if (
|
1075 |
// create backup directory if needed
|
1076 |
wp_mkdir_p( $this->get_image_backup_folder_location( $data['file'] ) );
|
1077 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1078 |
// save backup image
|
1079 |
$this->save_image_file( $image, $mime['type'], $backup_filepath, $this->options['backup']['backup_quality'] );
|
1080 |
|
@@ -1299,11 +1322,14 @@ wp-logo-jpg + +
|
|
1299 |
* Add watermark image to an image.
|
1300 |
*
|
1301 |
* @param resource $image Image resource
|
1302 |
-
* @param array
|
1303 |
-
* @param array
|
1304 |
-
* @return
|
1305 |
*/
|
1306 |
private function add_watermark_image( $image, $options, $upload_dir ) {
|
|
|
|
|
|
|
1307 |
$watermark_file = wp_get_attachment_metadata( $options['watermark_image']['url'], true );
|
1308 |
$url = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $watermark_file['file'];
|
1309 |
$watermark_file_info = getimagesize( $url );
|
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.5
|
6 |
Author: dFactory
|
7 |
Author URI: http://www.dfactory.eu/
|
8 |
Plugin URI: http://www.dfactory.eu/plugins/image-watermark/
|
12 |
Domain Path: /languages
|
13 |
|
14 |
Image Watermark
|
15 |
+
Copyright (C) 2013-2019, 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 |
|
32 |
* Image Watermark class.
|
33 |
*
|
34 |
* @class Image_Watermark
|
35 |
+
* @version 1.6.5
|
36 |
*/
|
37 |
final class Image_Watermark {
|
38 |
|
81 |
'backup_quality' => 90
|
82 |
)
|
83 |
),
|
84 |
+
'version' => '1.6.5'
|
85 |
);
|
86 |
public $options = array();
|
87 |
|
129 |
|
130 |
// create backup folder and security if enabled
|
131 |
if ( $this->options['backup']['backup_image'] ) {
|
|
|
132 |
if ( is_writable( $upload_dir['basedir'] ) ) {
|
133 |
$this->is_backup_folder_writable = true;
|
134 |
|
142 |
// htaccess security
|
143 |
file_put_contents( IMAGE_WATERMARK_BACKUP_DIR . DIRECTORY_SEPARATOR . '.htaccess', 'deny from all' );
|
144 |
}
|
145 |
+
} else
|
146 |
$this->is_backup_folder_writable = false;
|
147 |
+
} else
|
|
|
148 |
$this->is_backup_folder_writable = false;
|
149 |
+
|
150 |
+
if ( $this->is_backup_folder_writable !== true ) {
|
151 |
// disable backup setting
|
152 |
$this->options['backup']['backup_image'] = false;
|
153 |
update_option( 'image_watermark_options', $this->options );
|
433 |
|
434 |
// admin
|
435 |
if ( $this->is_admin === true ) {
|
436 |
+
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 ) ) {
|
437 |
add_filter( 'wp_generate_attachment_metadata', array( $this, 'apply_watermark' ), 10, 2 );
|
438 |
}
|
439 |
// frontend
|
440 |
} else {
|
441 |
+
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 ) ) {
|
442 |
add_filter( 'wp_generate_attachment_metadata', array( $this, 'apply_watermark' ), 10, 2 );
|
443 |
}
|
444 |
}
|
502 |
|
503 |
// only if manual watermarking is turned and we have a valid action
|
504 |
// if the action is NOT "removewatermark" we also require a watermark image to be set
|
505 |
+
if ( $post_id > 0 && $action && $this->options['watermark_image']['manual_watermarking'] == 1 && ( wp_attachment_is_image( $this->options['watermark_image']['url'] ) || $action == 'removewatermark' ) ) {
|
506 |
$data = wp_get_attachment_metadata( $post_id, false );
|
507 |
|
508 |
// is this really an image?
|
552 |
|
553 |
// only if manual watermarking is turned and we have a valid action
|
554 |
// if the action is NOT "removewatermark" we also require a watermark image to be set
|
555 |
+
if ( $action && $this->options['watermark_image']['manual_watermarking'] == 1 && ( wp_attachment_is_image( $this->options['watermark_image']['url'] ) || $action == 'removewatermark' ) ) {
|
556 |
// security check
|
557 |
check_admin_referer( 'bulk-media' );
|
558 |
|
714 |
* @return array
|
715 |
*/
|
716 |
public function apply_watermark( $data, $attachment_id, $method = '' ) {
|
717 |
+
$attachment_id = (int) $attachment_id;
|
718 |
+
$post = get_post( $attachment_id );
|
719 |
$post_id = ( ! empty( $post ) ? (int) $post->post_parent : 0 );
|
720 |
|
721 |
+
if ( $attachment_id === (int) $this->options['watermark_image']['url'] ) {
|
722 |
// this is the current watermark, do not apply
|
723 |
return array( 'error' => __( 'Watermark prevented, this is your selected watermark image', 'image-watermark' ) );
|
724 |
}
|
900 |
$exifadded = ! $exifdata;
|
901 |
$iptcadded = ! $iptcdata;
|
902 |
|
903 |
+
while ( ( $this->get_safe_chunk( substr( $destfilecontent, 0, 2 ) ) & 0xFFF0 ) === 0xFFE0 ) {
|
904 |
+
$segmentlen = ( $this->get_safe_chunk( substr( $destfilecontent, 2, 2 ) ) & 0xFFFF );
|
905 |
|
906 |
// last 4 bits of second byte is IPTC segment
|
907 |
+
$iptcsegmentnumber = ( $this->get_safe_chunk( substr( $destfilecontent, 1, 1 ) ) & 0x0F );
|
908 |
|
909 |
if ( $segmentlen <= 2 )
|
910 |
return false;
|
951 |
return false;
|
952 |
}
|
953 |
|
954 |
+
/**
|
955 |
+
* Get integer value of binary chunk.
|
956 |
+
*
|
957 |
+
* @param bin $value Binary data
|
958 |
+
* @return int
|
959 |
+
*/
|
960 |
+
private function get_safe_chunk( $value ) {
|
961 |
+
// check for numeric value
|
962 |
+
if ( is_numeric( $value ) ) {
|
963 |
+
// cast to integer to do bitwise AND operation
|
964 |
+
return (int) $value;
|
965 |
+
} else
|
966 |
+
return 0;
|
967 |
+
}
|
968 |
+
|
969 |
/**
|
970 |
* Apply watermark to image.
|
971 |
*
|
982 |
// get image mime type
|
983 |
$mime = wp_check_filetype( $image_path );
|
984 |
|
985 |
+
if ( ! wp_attachment_is_image( $options['watermark_image']['url'] ) )
|
986 |
+
return;
|
987 |
+
|
988 |
// get watermark path
|
989 |
$watermark_file = wp_get_attachment_metadata( $options['watermark_image']['url'], true );
|
990 |
$watermark_path = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $watermark_file['file'];
|
1088 |
// get image resource
|
1089 |
$image = $this->get_image_resource( $filepath, $mime['type'] );
|
1090 |
|
1091 |
+
if ( $image !== false ) {
|
1092 |
// create backup directory if needed
|
1093 |
wp_mkdir_p( $this->get_image_backup_folder_location( $data['file'] ) );
|
1094 |
|
1095 |
+
// get path to the backup file
|
1096 |
+
$path = pathinfo( $backup_filepath );
|
1097 |
+
|
1098 |
+
// create subfolders in backup folder if needed
|
1099 |
+
wp_mkdir_p( $path['dirname'] );
|
1100 |
+
|
1101 |
// save backup image
|
1102 |
$this->save_image_file( $image, $mime['type'], $backup_filepath, $this->options['backup']['backup_quality'] );
|
1103 |
|
1322 |
* Add watermark image to an image.
|
1323 |
*
|
1324 |
* @param resource $image Image resource
|
1325 |
+
* @param array $options Plugin options
|
1326 |
+
* @param array $upload_dir WP upload dir data
|
1327 |
+
* @return mixed Watermarked image
|
1328 |
*/
|
1329 |
private function add_watermark_image( $image, $options, $upload_dir ) {
|
1330 |
+
if ( ! wp_attachment_is_image( $options['watermark_image']['url'] ) )
|
1331 |
+
return false;
|
1332 |
+
|
1333 |
$watermark_file = wp_get_attachment_metadata( $options['watermark_image']['url'], true );
|
1334 |
$url = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $watermark_file['file'];
|
1335 |
$watermark_file_info = getimagesize( $url );
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: dfactory
|
|
3 |
Donate link: http://www.dfactory.eu/
|
4 |
Tags: image, images, picture, photo, watermark, watermarking, protection, image protection, image security, plugin
|
5 |
Requires at least: 4.0
|
6 |
-
Tested up to:
|
7 |
-
Stable tag: 1.6.
|
8 |
License: MIT License
|
9 |
License URI: http://opensource.org/licenses/MIT
|
10 |
|
@@ -54,6 +54,10 @@ No questions yet.
|
|
54 |
|
55 |
== Changelog ==
|
56 |
|
|
|
|
|
|
|
|
|
57 |
= 1.6.4 =
|
58 |
* Fix: Transparent PNG issues with ImageMagic library
|
59 |
|
@@ -180,5 +184,6 @@ Initial release
|
|
180 |
|
181 |
== Upgrade Notice ==
|
182 |
|
183 |
-
= 1.6.
|
184 |
-
* Fix:
|
|
3 |
Donate link: http://www.dfactory.eu/
|
4 |
Tags: image, images, picture, photo, watermark, watermarking, protection, image protection, image security, plugin
|
5 |
Requires at least: 4.0
|
6 |
+
Tested up to: 5.1
|
7 |
+
Stable tag: 1.6.5
|
8 |
License: MIT License
|
9 |
License URI: http://opensource.org/licenses/MIT
|
10 |
|
54 |
|
55 |
== Changelog ==
|
56 |
|
57 |
+
= 1.6.5 =
|
58 |
+
* Fix: Improved support for PHP 7 and above
|
59 |
+
* Fix: Backup folders handling of date based organized uploads
|
60 |
+
|
61 |
= 1.6.4 =
|
62 |
* Fix: Transparent PNG issues with ImageMagic library
|
63 |
|
184 |
|
185 |
== Upgrade Notice ==
|
186 |
|
187 |
+
= 1.6.5 =
|
188 |
+
* Fix: Improved support for PHP 7 and above
|
189 |
+
* Fix: Backup folders handling of date based organized uploads
|