Media from FTP - Version 11.07

Version Description

Fixed an issue with file name sanitization. Added the display of original files for large images.

Download this release

Release Info

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

Code changes from version 11.06 to 11.07

inc/class-mediafromftp.php CHANGED
@@ -517,8 +517,7 @@ class MediaFromFtp {
517
  $metadata = wp_get_attachment_metadata( $attachment->ID );
518
  $orginal_image_url = null;
519
  if ( ! empty( $metadata['original_image'] ) ) {
520
- $only_file = wp_basename( $path_file );
521
- $orginal_image_url = $this->upload_url . '/' . str_replace( $only_file, '', $path_file ) . $metadata['original_image'];
522
  }
523
  $original_url = $this->upload_url . '/' . get_post_meta( $attachment->ID, '_wp_attached_file', true );
524
  $pdf_thumb_url = rtrim( $attach_url, '.pdf' ) . '-pdf.jpg'; /* for pdf thumbnail by imagick */
@@ -1127,6 +1126,7 @@ class MediaFromFtp {
1127
  /** ==================================================
1128
  * Output html and log
1129
  *
 
1130
  * @param string $ext ext.
1131
  * @param int $attach_id attach_id.
1132
  * @param string $new_attach_title new_attach_title.
@@ -1147,7 +1147,7 @@ class MediaFromFtp {
1147
  * @return string $output_html
1148
  * @since 9.30
1149
  */
1150
- public function output_html_and_log( $ext, $attach_id, $new_attach_title, $new_url_attach, $imagethumburls, $mimetype, $length, $stamptime, $file_size, $exif_text, $image_attr_thumbnail, $mediafromftp_settings, $cat_html, $mlccategory, $emlcategory, $mlacategory, $mlatag ) {
1151
 
1152
  $thumbnails = array();
1153
 
@@ -1157,10 +1157,12 @@ class MediaFromFtp {
1157
  $output_html .= '<div>ID: ' . $attach_id . '</div>';
1158
  $output_html .= '<div>' . __( 'Title' ) . ': ' . $new_attach_title . '</div>';
1159
  $output_html .= '<div>' . __( 'Permalink:' ) . ' <a href="' . get_attachment_link( $attach_id ) . '" target="_blank" style="text-decoration: none; word-break: break-all;">' . get_attachment_link( $attach_id ) . '</a></div>';
1160
- $output_html .= '<div>URL: <a href="' . $new_url_attach . '" target="_blank" style="text-decoration: none; word-break: break-all;">' . $new_url_attach . '</a></div>';
1161
- $new_url_attachs = explode( '/', $new_url_attach );
1162
- $output_html .= '<div>' . __( 'File name:' ) . ' ' . end( $new_url_attachs ) . '</div>';
1163
-
 
 
1164
  $output_html .= '<div>' . __( 'Date/Time' ) . ': ' . $stamptime . '</div>';
1165
  if ( ! $file_size ) {
1166
  $file_size = '<font color="red">' . __( 'Could not retrieve.', 'media-from-ftp' ) . '</font>';
@@ -1169,9 +1171,13 @@ class MediaFromFtp {
1169
  }
1170
  $output_html .= '<div>' . __( 'File type:' ) . ' ' . $mimetype . '</div>';
1171
  $output_html .= '<div>' . __( 'File size:' ) . ' ' . $file_size . '</div>';
1172
- if ( 'image' === wp_ext2type( $ext ) || ( 'pdf' === strtolower( $ext ) && ! empty( $imagethumburls ) ) ) {
1173
  $output_html .= '<div>' . __( 'Images' ) . ': ';
1174
  $thumb_count = 0;
 
 
 
 
1175
  foreach ( $imagethumburls as $thumbsize => $imagethumburl ) {
1176
  $output_html .= '[<a href="' . $imagethumburl . '" target="_blank" style="text-decoration: none; word-break: break-all;">' . $thumbsize . '</a>]';
1177
  ++$thumb_count;
@@ -1202,8 +1208,8 @@ class MediaFromFtp {
1202
  'user' => $user->display_name,
1203
  'title' => $new_attach_title,
1204
  'permalink' => get_attachment_link( $attach_id ),
1205
- 'url' => $new_url_attach,
1206
- 'filename' => end( $new_url_attachs ),
1207
  'time' => $stamptime,
1208
  'filetype' => $mimetype,
1209
  'filesize' => $file_size,
517
  $metadata = wp_get_attachment_metadata( $attachment->ID );
518
  $orginal_image_url = null;
519
  if ( ! empty( $metadata['original_image'] ) ) {
520
+ $orginal_image_url = wp_get_original_image_url( $attachment->ID );
 
521
  }
522
  $original_url = $this->upload_url . '/' . get_post_meta( $attachment->ID, '_wp_attached_file', true );
523
  $pdf_thumb_url = rtrim( $attach_url, '.pdf' ) . '-pdf.jpg'; /* for pdf thumbnail by imagick */
1126
  /** ==================================================
1127
  * Output html and log
1128
  *
1129
+ * @param array $metadata metadata.
1130
  * @param string $ext ext.
1131
  * @param int $attach_id attach_id.
1132
  * @param string $new_attach_title new_attach_title.
1147
  * @return string $output_html
1148
  * @since 9.30
1149
  */
1150
+ public function output_html_and_log( $metadata, $ext, $attach_id, $new_attach_title, $new_url_attach, $imagethumburls, $mimetype, $length, $stamptime, $file_size, $exif_text, $image_attr_thumbnail, $mediafromftp_settings, $cat_html, $mlccategory, $emlcategory, $mlacategory, $mlatag ) {
1151
 
1152
  $thumbnails = array();
1153
 
1157
  $output_html .= '<div>ID: ' . $attach_id . '</div>';
1158
  $output_html .= '<div>' . __( 'Title' ) . ': ' . $new_attach_title . '</div>';
1159
  $output_html .= '<div>' . __( 'Permalink:' ) . ' <a href="' . get_attachment_link( $attach_id ) . '" target="_blank" style="text-decoration: none; word-break: break-all;">' . get_attachment_link( $attach_id ) . '</a></div>';
1160
+ $output_html .= '<div>URL: <a href="' . wp_get_attachment_url( $attach_id ) . '" target="_blank" style="text-decoration: none; word-break: break-all;">' . wp_get_attachment_url( $attach_id ) . '</a></div>';
1161
+ $output_html .= '<div>' . __( 'File name:' ) . ' ' . wp_basename( wp_get_attachment_url( $attach_id ) ) . '</div>';
1162
+ if ( ! empty( $metadata['original_image'] ) ) {
1163
+ $output_html .= '<div>' . __( 'Original URL', 'media-from-ftp' ) . ': <a href="' . wp_get_original_image_url( $attach_id ) . '" target="_blank" style="text-decoration: none; word-break: break-all;">' . wp_get_original_image_url( $attach_id ) . '</a></div>';
1164
+ $output_html .= '<div>' . __( 'Original File name', 'media-from-ftp' ) . ': ' . wp_basename( wp_get_original_image_url( $attach_id ) ) . '</div>';
1165
+ }
1166
  $output_html .= '<div>' . __( 'Date/Time' ) . ': ' . $stamptime . '</div>';
1167
  if ( ! $file_size ) {
1168
  $file_size = '<font color="red">' . __( 'Could not retrieve.', 'media-from-ftp' ) . '</font>';
1171
  }
1172
  $output_html .= '<div>' . __( 'File type:' ) . ' ' . $mimetype . '</div>';
1173
  $output_html .= '<div>' . __( 'File size:' ) . ' ' . $file_size . '</div>';
1174
+ if ( ( 'image' === wp_ext2type( $ext ) || 'pdf' === strtolower( $ext ) ) && ! empty( $imagethumburls ) ) {
1175
  $output_html .= '<div>' . __( 'Images' ) . ': ';
1176
  $thumb_count = 0;
1177
+ if ( ! empty( $metadata['original_image'] ) ) {
1178
+ ++$thumb_count;
1179
+ $thumbnails[ $thumb_count ] = wp_get_original_image_url( $attach_id );
1180
+ }
1181
  foreach ( $imagethumburls as $thumbsize => $imagethumburl ) {
1182
  $output_html .= '[<a href="' . $imagethumburl . '" target="_blank" style="text-decoration: none; word-break: break-all;">' . $thumbsize . '</a>]';
1183
  ++$thumb_count;
1208
  'user' => $user->display_name,
1209
  'title' => $new_attach_title,
1210
  'permalink' => get_attachment_link( $attach_id ),
1211
+ 'url' => wp_get_attachment_url( $attach_id ),
1212
+ 'filename' => wp_basename( wp_get_attachment_url( $attach_id ) ),
1213
  'time' => $stamptime,
1214
  'filetype' => $mimetype,
1215
  'filesize' => $file_size,
mediafromftp.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Media from FTP
4
  * Plugin URI: https://wordpress.org/plugins/media-from-ftp/
5
  * Description: Register to media library from files that have been uploaded by FTP.
6
- * Version: 11.06
7
  * Author: Katsushi Kawamori
8
  * Author URI: https://riverforest-wp.info/
9
  * License: GPL2
3
  * Plugin Name: Media from FTP
4
  * Plugin URI: https://wordpress.org/plugins/media-from-ftp/
5
  * Description: Register to media library from files that have been uploaded by FTP.
6
+ * Version: 11.07
7
  * Author: Katsushi Kawamori
8
  * Author URI: https://riverforest-wp.info/
9
  * License: GPL2
readme.txt CHANGED
@@ -4,8 +4,8 @@ Donate link: https://shop.riverforest-wp.info/donate/
4
  Tags: files, ftp, import, media, sync, uploads
5
  Requires at least: 3.6.0
6
  Requires PHP: 5.6
7
- Tested up to: 5.3
8
- Stable tag: 11.06
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -21,6 +21,7 @@ Register to media library from files that have been uploaded by FTP.
21
  * Export the log to a CSV file.
22
  * To Import the files to Media Library from a WordPress export file.
23
  * You can register a large number of files without timeout work with Ajax.
 
24
 
25
  = Tutorial Video =
26
  [youtube https://www.youtube.com/watch?v=vdxPvOFZaDk]
@@ -132,6 +133,10 @@ Password: live789user
132
 
133
  == Changelog ==
134
 
 
 
 
 
135
  = 11.06 =
136
  Registration date & time is now possible in seconds unit.
137
 
4
  Tags: files, ftp, import, media, sync, uploads
5
  Requires at least: 3.6.0
6
  Requires PHP: 5.6
7
+ Tested up to: 5.4
8
+ Stable tag: 11.07
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
21
  * Export the log to a CSV file.
22
  * To Import the files to Media Library from a WordPress export file.
23
  * You can register a large number of files without timeout work with Ajax.
24
+ * Sibling plugin -> [Media from ZIP](https://wordpress.org/plugins/media-from-zip/).
25
 
26
  = Tutorial Video =
27
  [youtube https://www.youtube.com/watch?v=vdxPvOFZaDk]
133
 
134
  == Changelog ==
135
 
136
+ = 11.07 =
137
+ Fixed an issue with file name sanitization.
138
+ Added the display of original files for large images.
139
+
140
  = 11.06 =
141
  Registration date & time is now possible in seconds unit.
142
 
req/class-mediafromftpadmin.php CHANGED
@@ -1456,7 +1456,7 @@ class MediaFromFtpAdmin {
1456
  $count = 0;
1457
  foreach ( $thumbnails as $thumbnail ) {
1458
  ++$count;
1459
- $html_thumbnail .= '<tr><th align="right" style="white-space: nowrap;">' . __( 'Featured Image' ) . $count . ':</th><td>' . $thumbnail . '</td></tr>';
1460
  $csvs .= ',"' . $thumbnail . '"';
1461
  }
1462
  }
@@ -1535,7 +1535,7 @@ class MediaFromFtpAdmin {
1535
  $html .= '</table>' . "\n";
1536
  $csv_head = '"ID","' . __( 'Author' ) . '","' . __( 'Title' ) . ':","' . __( 'Permalink:' ) . '","URL:","' . __( 'File name:' ) . '","' . __( 'Date/Time' ) . ':","' . __( 'File type:' ) . '","' . __( 'File size:' ) . '","' . __( 'Caption' ) . '[Exif]:","' . __( 'Length:' ) . '"';
1537
  for ( $i = 1; $i <= $max_thumbnail_count; $i++ ) {
1538
- $csv_head .= ',"' . __( 'Featured Image' ) . $i . '"';
1539
  }
1540
  for ( $i = 1; $i <= $max_mlccategories_count; $i++ ) {
1541
  $csv_head .= ',"' . __( 'Categories' ) . '[Media Library Categories]' . $i . '"';
@@ -1664,55 +1664,69 @@ class MediaFromFtpAdmin {
1664
  if ( isset( $_POST['media_from_ftp_file_load'] ) && ! empty( $_POST['media_from_ftp_file_load'] ) ) {
1665
  if ( check_admin_referer( 'mff_file_load', 'media_from_ftp_file_load' ) ) {
1666
  if ( isset( $_FILES['filename']['name'] ) && ! empty( $_FILES['filename']['name'] ) ) {
1667
- if ( isset( $_FILES['filename']['tmp_name'] ) && ! empty( $_FILES['filename']['tmp_name'] ) ) {
1668
- $filename = sanitize_text_field( wp_unslash( $_FILES['filename']['tmp_name'] ) );
1669
- }
1670
- $name = wp_basename( $filename );
1671
- move_uploaded_file( $filename, $this->plugin_tmp_dir . '/' . $name );
 
 
 
 
 
 
 
 
 
1672
 
1673
- $mediafromftp = new MediaFromFtp();
1674
 
1675
- $allowed_author_select_html = array(
1676
- 'h4' => array(),
1677
- 'strong' => array(),
1678
- 'div' => array(
1679
- 'style' => array(),
1680
- ),
1681
- 'form' => array(
1682
- 'method' => array(),
1683
- 'action' => array(),
1684
- ),
1685
- 'select' => array(
1686
- 'name' => array(),
1687
- ),
1688
- 'option' => array(
1689
- 'value' => array(),
1690
- 'select' => array(),
1691
- ),
1692
- 'input' => array(
1693
- 'name' => array(),
1694
- 'type' => array(),
1695
- 'size' => array(),
1696
- 'id' => array(),
1697
- 'class' => array(),
1698
- 'value' => array(),
1699
- ),
1700
- );
1701
- $author_select_html = $mediafromftp->author_select( $this->plugin_tmp_dir . '/' . $name );
1702
- if ( $author_select_html ) {
1703
- $author_select_html = '<h4>' . __( 'Assign Authors', 'media-from-ftp' ) . '</h4>' . $author_select_html;
1704
- echo wp_kses( $author_select_html, $allowed_author_select_html );
1705
- } else {
1706
- if ( file_exists( $this->plugin_tmp_dir . '/' . $name ) ) {
1707
- unlink( $this->plugin_tmp_dir . '/' . $name );
 
 
 
 
 
 
 
 
 
 
 
 
1708
  }
1709
- $export_html = '<a style="text-decoration: none;" href="' . admin_url( 'export.php' ) . '">' . __( 'Export' ) . '</a>';
1710
- /* translators: %1$s: Export link */
1711
- echo '<div class="notice notice-error is-dismissible"><ul><li>' . wp_kses_post( sprintf( __( 'This screen reads the XML file created when exporting media with WordPress %1$s.', 'media-from-ftp' ), $export_html ) ) . '</li></ul></div>';
1712
- ?>
1713
- <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-import' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Continue' ); ?></a>
1714
- <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-search-register' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Search & Register', 'media-from-ftp' ); ?></a>
1715
- <?php
1716
  }
1717
  }
1718
  }
1456
  $count = 0;
1457
  foreach ( $thumbnails as $thumbnail ) {
1458
  ++$count;
1459
+ $html_thumbnail .= '<tr><th align="right" style="white-space: nowrap;">' . __( 'Images' ) . $count . ':</th><td>' . $thumbnail . '</td></tr>';
1460
  $csvs .= ',"' . $thumbnail . '"';
1461
  }
1462
  }
1535
  $html .= '</table>' . "\n";
1536
  $csv_head = '"ID","' . __( 'Author' ) . '","' . __( 'Title' ) . ':","' . __( 'Permalink:' ) . '","URL:","' . __( 'File name:' ) . '","' . __( 'Date/Time' ) . ':","' . __( 'File type:' ) . '","' . __( 'File size:' ) . '","' . __( 'Caption' ) . '[Exif]:","' . __( 'Length:' ) . '"';
1537
  for ( $i = 1; $i <= $max_thumbnail_count; $i++ ) {
1538
+ $csv_head .= ',"' . __( 'Images' ) . $i . '"';
1539
  }
1540
  for ( $i = 1; $i <= $max_mlccategories_count; $i++ ) {
1541
  $csv_head .= ',"' . __( 'Categories' ) . '[Media Library Categories]' . $i . '"';
1664
  if ( isset( $_POST['media_from_ftp_file_load'] ) && ! empty( $_POST['media_from_ftp_file_load'] ) ) {
1665
  if ( check_admin_referer( 'mff_file_load', 'media_from_ftp_file_load' ) ) {
1666
  if ( isset( $_FILES['filename']['name'] ) && ! empty( $_FILES['filename']['name'] ) ) {
1667
+ if ( isset( $_FILES['filename']['tmp_name'] ) && ! empty( $_FILES['filename']['tmp_name'] ) &&
1668
+ isset( $_FILES['filename']['name'] ) && ! empty( $_FILES['filename']['name'] ) &&
1669
+ isset( $_FILES['filename']['type'] ) && ! empty( $_FILES['filename']['type'] ) &&
1670
+ isset( $_FILES['filename']['error'] ) ) {
1671
+ if ( 0 === intval( wp_unslash( $_FILES['filename']['error'] ) ) ) {
1672
+ $filename = sanitize_text_field( wp_unslash( $_FILES['filename']['tmp_name'] ) );
1673
+ $org_name = sanitize_file_name( wp_unslash( $_FILES['filename']['name'] ) );
1674
+ $mimetype = sanitize_text_field( wp_unslash( $_FILES['filename']['type'] ) );
1675
+ $filetype = wp_check_filetype( $org_name, array( 'xml' => $mimetype ) );
1676
+ if ( ! $filetype['ext'] && ! current_user_can( 'unfiltered_upload' ) ) {
1677
+ echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'Sorry, this file type is not permitted for security reasons.' ) . '</li></ul></div>';
1678
+ } else {
1679
+ $name = sanitize_file_name( wp_basename( $filename ) );
1680
+ move_uploaded_file( $filename, $this->plugin_tmp_dir . '/' . $name );
1681
 
1682
+ $mediafromftp = new MediaFromFtp();
1683
 
1684
+ $allowed_author_select_html = array(
1685
+ 'h4' => array(),
1686
+ 'strong' => array(),
1687
+ 'div' => array(
1688
+ 'style' => array(),
1689
+ ),
1690
+ 'form' => array(
1691
+ 'method' => array(),
1692
+ 'action' => array(),
1693
+ ),
1694
+ 'select' => array(
1695
+ 'name' => array(),
1696
+ ),
1697
+ 'option' => array(
1698
+ 'value' => array(),
1699
+ 'select' => array(),
1700
+ ),
1701
+ 'input' => array(
1702
+ 'name' => array(),
1703
+ 'type' => array(),
1704
+ 'size' => array(),
1705
+ 'id' => array(),
1706
+ 'class' => array(),
1707
+ 'value' => array(),
1708
+ ),
1709
+ );
1710
+ $author_select_html = $mediafromftp->author_select( $this->plugin_tmp_dir . '/' . $name );
1711
+ if ( $author_select_html ) {
1712
+ $author_select_html = '<h4>' . __( 'Assign Authors', 'media-from-ftp' ) . '</h4>' . $author_select_html;
1713
+ echo wp_kses( $author_select_html, $allowed_author_select_html );
1714
+ } else {
1715
+ if ( file_exists( $this->plugin_tmp_dir . '/' . $name ) ) {
1716
+ unlink( $this->plugin_tmp_dir . '/' . $name );
1717
+ }
1718
+ $export_html = '<a style="text-decoration: none;" href="' . admin_url( 'export.php' ) . '">' . __( 'Export' ) . '</a>';
1719
+ /* translators: %1$s: Export link */
1720
+ echo '<div class="notice notice-error is-dismissible"><ul><li>' . wp_kses_post( sprintf( __( 'This screen reads the XML file created when exporting media with WordPress %1$s.', 'media-from-ftp' ), $export_html ) ) . '</li></ul></div>';
1721
+ ?>
1722
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-import' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Continue' ); ?></a>
1723
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-search-register' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Search & Register', 'media-from-ftp' ); ?></a>
1724
+ <?php
1725
+ }
1726
+ }
1727
+ } else {
1728
+ echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'No such file exists! Double check the name and try again.' ) . '</li></ul></div>';
1729
  }
 
 
 
 
 
 
 
1730
  }
1731
  }
1732
  }
req/class-mediafromftpajax.php CHANGED
@@ -181,7 +181,7 @@ class MediaFromFtpAjax {
181
 
182
  $image_attr_thumbnail = wp_get_attachment_image_src( $attach_id, 'thumbnail', true );
183
 
184
- $output_html = $mediafromftp->output_html_and_log( $ext, $attach_id, $new_attach_title, $new_url_attach, $imagethumburls, $mimetype, $length, $stamptime, $file_size, $exif_text, $image_attr_thumbnail, $mediafromftp_settings, $cat_html, $mlccategory, $emlcategory, $mlacategory, $mlatag );
185
 
186
  header( 'Content-type: text/html; charset=UTF-8' );
187
  $allowed_output_html = array(
181
 
182
  $image_attr_thumbnail = wp_get_attachment_image_src( $attach_id, 'thumbnail', true );
183
 
184
+ $output_html = $mediafromftp->output_html_and_log( $metadata, $ext, $attach_id, $new_attach_title, $new_url_attach, $imagethumburls, $mimetype, $length, $stamptime, $file_size, $exif_text, $image_attr_thumbnail, $mediafromftp_settings, $cat_html, $mlccategory, $emlcategory, $mlacategory, $mlatag );
185
 
186
  header( 'Content-type: text/html; charset=UTF-8' );
187
  $allowed_output_html = array(