Media from FTP - Version 9.97

Version Description

Add thumbnail generation of PDF when Imagick is enabled.

Download this release

Release Info

Developer Katsushi Kawamori
Plugin Icon wp plugin Media from FTP
Version 9.97
Comparing to
See all releases

Code changes from version 9.96 to 9.97

Files changed (3) hide show
  1. inc/MediaFromFtp.php +49 -29
  2. mediafromftp.php +1 -1
  3. readme.txt +4 -1
inc/MediaFromFtp.php CHANGED
@@ -244,7 +244,12 @@ class MediaFromFtp {
244
  function create_cash($ext, $file, $new_url){
245
 
246
  $cash_thumb_key = md5($new_url);
247
- $cash_thumb_filename = MEDIAFROMFTP_PLUGIN_TMP_DIR.'/'.$cash_thumb_key.'.'.$ext;
 
 
 
 
 
248
  $value_cash = get_transient( $cash_thumb_key );
249
  if ( $value_cash <> FALSE ) {
250
  if ( ! file_exists( $cash_thumb_filename )) {
@@ -256,17 +261,32 @@ class MediaFromFtp {
256
  if ( ! file_exists( $cash_thumb_filename )) {
257
  $cash_thumb = wp_get_image_editor( $file );
258
  if ( ! is_wp_error( $cash_thumb ) ) {
259
- $cash_thumb->resize( 40 ,40, true );
260
- $cash_thumb->save( $cash_thumb_filename );
261
- $view_thumb_url = MEDIAFROMFTP_PLUGIN_TMP_URL.'/'.$cash_thumb_key.'.'.$ext;
 
 
 
 
 
 
 
 
 
 
 
262
  } else {
263
- $view_thumb_url = MEDIAFROMFTP_PLUGIN_SITE_URL. WPINC . '/images/media/default.png';
 
 
264
  }
265
  } else {
266
  if ( file_exists( $cash_thumb_filename )) {
267
  $view_thumb_url = MEDIAFROMFTP_PLUGIN_TMP_URL.'/'.$cash_thumb_key.'.'.$ext;
268
  } else {
269
- $view_thumb_url = MEDIAFROMFTP_PLUGIN_SITE_URL. WPINC . '/images/media/default.png';
 
 
270
  }
271
  }
272
  set_transient( $cash_thumb_key, $view_thumb_url, DAY_IN_SECONDS);
@@ -287,9 +307,13 @@ class MediaFromFtp {
287
  */
288
  function delete_cash($ext, $new_url_attach){
289
 
290
- if ( wp_ext2type($ext) === 'image' ){
291
  $del_cash_thumb_key = md5($new_url_attach);
292
- $del_cash_thumb_filename = MEDIAFROMFTP_PLUGIN_TMP_DIR.'/'.$del_cash_thumb_key.'.'.$ext;
 
 
 
 
293
  $value_del_cash = get_transient( $del_cash_thumb_key );
294
  if ( $value_del_cash <> FALSE ) {
295
  delete_transient( $del_cash_thumb_key );
@@ -396,7 +420,8 @@ class MediaFromFtp {
396
  $new_url = $this->mb_utf8($new_url, $character_code);
397
  foreach ( $attachments as $attachment ){
398
  $attach_url = MEDIAFROMFTP_PLUGIN_UPLOAD_URL.'/'.get_post_meta( $attachment->ID, '_wp_attached_file', true );
399
- if ( $attach_url === $new_url || $attach_url === $new_url_md5 ) {
 
400
  $new_file = FALSE;
401
  } else {
402
  if ($thumb_deep_search) {
@@ -434,7 +459,7 @@ class MediaFromFtp {
434
  if ($mediafromftp_settings['search_display_metadata']){
435
  $file_size = size_format(filesize($file));
436
  $mimetype = $ext.'('.$this->mime_type($ext).')';
437
- if ( wp_ext2type($ext) === 'image' ){
438
  $view_thumb_url = $this->create_cash($ext, $file, $new_url);
439
  } else if ( wp_ext2type($ext) === 'audio' ) {
440
  $view_thumb_url = MEDIAFROMFTP_PLUGIN_SITE_URL. WPINC . '/images/media/audio.png';
@@ -748,22 +773,14 @@ class MediaFromFtp {
748
  include_once( ABSPATH . 'wp-admin/includes/image.php' );
749
 
750
  // Meta data Regist
 
751
  $fullpath_filename = $this->mb_encode_multibyte(get_attached_file($attach_id), $character_code);
752
- if ( wp_ext2type($ext) === 'image' ){
753
  $metadata = wp_generate_attachment_metadata( $attach_id, $fullpath_filename );
754
- }else if ( wp_ext2type($ext) === 'video' ){
755
  $metadata = wp_read_video_metadata( $fullpath_filename );
756
- }else if ( wp_ext2type($ext) === 'audio' ){
757
  $metadata = wp_read_audio_metadata( $fullpath_filename );
758
- } else {
759
- $metadata = NULL;
760
- }
761
- if ( !empty($metadata) ) { // 'file' => UTF-8
762
- if ( function_exists('array_replace') ) {
763
- $metadata = array_replace($metadata, array('file' => $filename));
764
- } else {
765
- $metadata = $this->array_replace($metadata, array('file' => $filename));
766
- }
767
  }
768
  wp_update_attachment_metadata( $attach_id, $metadata );
769
 
@@ -787,12 +804,15 @@ class MediaFromFtp {
787
  $length = NULL;
788
  $exif_text = NULL;
789
  $filetype = wp_check_filetype( $this->mb_encode_multibyte(get_attached_file($attach_id), $character_code) );
790
- if ( wp_ext2type($ext) === 'image' ){
791
- $imagethumburl_base = MEDIAFROMFTP_PLUGIN_UPLOAD_URL.'/'.rtrim($metadata['file'], wp_basename($metadata['file']));
792
- foreach ( $metadata as $key1 => $key2 ){
793
- if ( $key1 === 'sizes' ) {
794
- foreach ( $metadata[$key1] as $key2 => $key3 ){
795
- $imagethumburls[$key2] = $imagethumburl_base.$metadata['sizes'][$key2]['file'];
 
 
 
796
  }
797
  }
798
  }
@@ -867,7 +887,7 @@ class MediaFromFtp {
867
  }
868
  $output_html .= '<div>'.__('File type:').' '.$mimetype.'</div>';
869
  $output_html .= '<div>'.__('File size:').' '.$file_size.'</div>';
870
- if ( wp_ext2type($ext) === 'image' ) {
871
  $output_html .= '<div>'.__('Images').': ';
872
  $thumb_count = 0;
873
  foreach ( $imagethumburls as $thumbsize => $imagethumburl ) {
244
  function create_cash($ext, $file, $new_url){
245
 
246
  $cash_thumb_key = md5($new_url);
247
+ if ( strtolower($ext) === 'pdf' ) {
248
+ $cash_thumb_filename = MEDIAFROMFTP_PLUGIN_TMP_DIR.'/'.$cash_thumb_key.'-pdf.jpg';
249
+ } else {
250
+ $cash_thumb_filename = MEDIAFROMFTP_PLUGIN_TMP_DIR.'/'.$cash_thumb_key.'.'.$ext;
251
+ }
252
+
253
  $value_cash = get_transient( $cash_thumb_key );
254
  if ( $value_cash <> FALSE ) {
255
  if ( ! file_exists( $cash_thumb_filename )) {
261
  if ( ! file_exists( $cash_thumb_filename )) {
262
  $cash_thumb = wp_get_image_editor( $file );
263
  if ( ! is_wp_error( $cash_thumb ) ) {
264
+ if ( strtolower($ext) === 'pdf' ) {
265
+ $cash_thumb->generate_filename( 'image', null, 'jpg' );
266
+ $cash_thumb->save( $cash_thumb_filename );
267
+ $cash_thumb2 = wp_get_image_editor( $cash_thumb_filename );
268
+ if ( ! is_wp_error( $cash_thumb2 ) ) {
269
+ $cash_thumb2->resize( 40 ,40, true );
270
+ $cash_thumb2->save( $cash_thumb_filename );
271
+ }
272
+ $view_thumb_url = MEDIAFROMFTP_PLUGIN_TMP_URL.'/'.$cash_thumb_key.'-pdf.jpg';
273
+ } else {
274
+ $cash_thumb->resize( 40 ,40, true );
275
+ $cash_thumb->save( $cash_thumb_filename );
276
+ $view_thumb_url = MEDIAFROMFTP_PLUGIN_TMP_URL.'/'.$cash_thumb_key.'.'.$ext;
277
+ }
278
  } else {
279
+ $filetype2 = wp_ext2type($ext);
280
+ if ( empty($filetype2) ) { $filetype2 = 'default'; }
281
+ $view_thumb_url = MEDIAFROMFTP_PLUGIN_SITE_URL. WPINC . '/images/media/'.$filetype2.'.png';
282
  }
283
  } else {
284
  if ( file_exists( $cash_thumb_filename )) {
285
  $view_thumb_url = MEDIAFROMFTP_PLUGIN_TMP_URL.'/'.$cash_thumb_key.'.'.$ext;
286
  } else {
287
+ $filetype2 = wp_ext2type($ext);
288
+ if ( empty($filetype2) ) { $filetype2 = 'default'; }
289
+ $view_thumb_url = MEDIAFROMFTP_PLUGIN_SITE_URL. WPINC . '/images/media/'.$filetype2.'.png';
290
  }
291
  }
292
  set_transient( $cash_thumb_key, $view_thumb_url, DAY_IN_SECONDS);
307
  */
308
  function delete_cash($ext, $new_url_attach){
309
 
310
+ if ( wp_ext2type($ext) === 'image' || strtolower($ext) === 'pdf' ){
311
  $del_cash_thumb_key = md5($new_url_attach);
312
+ if ( strtolower($ext) === 'pdf' ) {
313
+ $del_cash_thumb_filename = MEDIAFROMFTP_PLUGIN_TMP_DIR.'/'.$del_cash_thumb_key.'-pdf.jpg';
314
+ } else {
315
+ $del_cash_thumb_filename = MEDIAFROMFTP_PLUGIN_TMP_DIR.'/'.$del_cash_thumb_key.'.'.$ext;
316
+ }
317
  $value_del_cash = get_transient( $del_cash_thumb_key );
318
  if ( $value_del_cash <> FALSE ) {
319
  delete_transient( $del_cash_thumb_key );
420
  $new_url = $this->mb_utf8($new_url, $character_code);
421
  foreach ( $attachments as $attachment ){
422
  $attach_url = MEDIAFROMFTP_PLUGIN_UPLOAD_URL.'/'.get_post_meta( $attachment->ID, '_wp_attached_file', true );
423
+ $pdf_thumb_url = rtrim($attach_url, '.pdf').'-pdf.jpg'; // for pdf thumbnail by imagick
424
+ if ( $attach_url === $new_url || $attach_url === $new_url_md5 || $pdf_thumb_url === $new_url || $pdf_thumb_url === $new_url_md5 ) {
425
  $new_file = FALSE;
426
  } else {
427
  if ($thumb_deep_search) {
459
  if ($mediafromftp_settings['search_display_metadata']){
460
  $file_size = size_format(filesize($file));
461
  $mimetype = $ext.'('.$this->mime_type($ext).')';
462
+ if ( wp_ext2type($ext) === 'image' || strtolower($ext) === 'pdf' ){
463
  $view_thumb_url = $this->create_cash($ext, $file, $new_url);
464
  } else if ( wp_ext2type($ext) === 'audio' ) {
465
  $view_thumb_url = MEDIAFROMFTP_PLUGIN_SITE_URL. WPINC . '/images/media/audio.png';
773
  include_once( ABSPATH . 'wp-admin/includes/image.php' );
774
 
775
  // Meta data Regist
776
+ $metadata = NULL;
777
  $fullpath_filename = $this->mb_encode_multibyte(get_attached_file($attach_id), $character_code);
778
+ if ( wp_ext2type($ext) === 'image' || strtolower($ext) === 'pdf' ){
779
  $metadata = wp_generate_attachment_metadata( $attach_id, $fullpath_filename );
780
+ } else if ( wp_ext2type($ext) === 'video' ){
781
  $metadata = wp_read_video_metadata( $fullpath_filename );
782
+ } else if ( wp_ext2type($ext) === 'audio' ){
783
  $metadata = wp_read_audio_metadata( $fullpath_filename );
 
 
 
 
 
 
 
 
 
784
  }
785
  wp_update_attachment_metadata( $attach_id, $metadata );
786
 
804
  $length = NULL;
805
  $exif_text = NULL;
806
  $filetype = wp_check_filetype( $this->mb_encode_multibyte(get_attached_file($attach_id), $character_code) );
807
+ if ( wp_ext2type($ext) === 'image' || strtolower($ext) === 'pdf' ){
808
+ $wp_attached_file = get_post_meta( $attach_id, '_wp_attached_file', true );
809
+ $imagethumburl_base = MEDIAFROMFTP_PLUGIN_UPLOAD_URL.'/'.rtrim($wp_attached_file, wp_basename($wp_attached_file));
810
+ if ( !empty($metadata) ) {
811
+ foreach ( $metadata as $key1 => $key2 ){
812
+ if ( $key1 === 'sizes' ) {
813
+ foreach ( $metadata[$key1] as $key2 => $key3 ){
814
+ $imagethumburls[$key2] = $imagethumburl_base.$metadata['sizes'][$key2]['file'];
815
+ }
816
  }
817
  }
818
  }
887
  }
888
  $output_html .= '<div>'.__('File type:').' '.$mimetype.'</div>';
889
  $output_html .= '<div>'.__('File size:').' '.$file_size.'</div>';
890
+ if ( wp_ext2type($ext) === 'image' || (strtolower($ext) === 'pdf' && !empty($imagethumburls)) ) {
891
  $output_html .= '<div>'.__('Images').': ';
892
  $thumb_count = 0;
893
  foreach ( $imagethumburls as $thumbsize => $imagethumburl ) {
mediafromftp.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Media from FTP
4
  Plugin URI: https://wordpress.org/plugins/media-from-ftp/
5
- Version: 9.96
6
  Description: Register to media library from files that have been uploaded by FTP.
7
  Author: Katsushi Kawamori
8
  Author URI: https://riverforest-wp.info/
2
  /*
3
  Plugin Name: Media from FTP
4
  Plugin URI: https://wordpress.org/plugins/media-from-ftp/
5
+ Version: 9.97
6
  Description: Register to media library from files that have been uploaded by FTP.
7
  Author: Katsushi Kawamori
8
  Author URI: https://riverforest-wp.info/
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: files, ftp, import, media, sync, uploads
5
  Requires at least: 3.6.0
6
  Requires PHP: 5.3.0
7
  Tested up to: 4.9
8
- Stable tag: 9.96
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -126,6 +126,9 @@ Register to media library from files that have been uploaded by FTP.
126
 
127
  == Changelog ==
128
 
 
 
 
129
  = 9.96 =
130
  Fixed problem of logs.
131
  Changed Add On link.
5
  Requires at least: 3.6.0
6
  Requires PHP: 5.3.0
7
  Tested up to: 4.9
8
+ Stable tag: 9.97
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
126
 
127
  == Changelog ==
128
 
129
+ = 9.97 =
130
+ Add thumbnail generation of PDF when Imagick is enabled.
131
+
132
  = 9.96 =
133
  Fixed problem of logs.
134
  Changed Add On link.