| @@ -28,38 +28,53 @@ | ||
| 28 | 28 | { |
| 29 | 29 | $this->disconnect(); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - public function download_file($url, $host, $user, $pass, $override_filename, $port = 21) | |
| 32 | + public function download_file($url, $host, $user, $pass, $override_filename = null, $port = 21) | |
| 33 | 33 | { |
| 34 | 34 | if ($this->_conn && $this->conn_hash !== md5($host . $user . $pass)) { |
| 35 | 35 | $this->disconnect(); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | + if (!function_exists('\ftp_connect')) { | |
| 39 | + return new \WP_Error('IWP_FTP_3', __("To download via FTP please enable the php ftp extension.", 'jc-importer')); | |
| 40 | + } | |
| 41 | + | |
| 38 | 42 | if (!$this->_conn) { |
| 39 | 43 | if (!$this->login($host, $user, $pass, $port)) { |
| 40 | - return new \WP_Error('IWP_FTP_0', "Unable to login to ftp server"); | |
| 44 | + return new \WP_Error('IWP_FTP_0', __("Unable to login to ftp server", 'jc-importer')); | |
| 41 | 45 | } |
| 42 | 46 | } |
| 43 | 47 | |
| 44 | 48 | if (!$this->_conn) { |
| 45 | - return new \WP_Error('IWP_FTP_0', "Unable to connect to ftp server"); | |
| 49 | + return new \WP_Error('IWP_FTP_0', __("Unable to connect to ftp server", 'jc-importer')); | |
| 46 | 50 | } |
| 47 | 51 | |
| 48 | - $size = ftp_size($this->_conn, $url); | |
| 49 | - if ($size === -1) { | |
| 50 | - return new \WP_Error('IWP_FTP_1', 'File doesn\'t exist on ftp server.'); | |
| 52 | + | |
| 53 | + // Note: Not all ftp servers support SIZE checks. | |
| 54 | + $disable_filesize = apply_filters('iwp/ftp/disable_size_check', false); | |
| 55 | + if(false === $disable_filesize){ | |
| 56 | + | |
| 57 | + $size = ftp_size($this->_conn, $url); | |
| 58 | + if ($size === -1) { | |
| 59 | + return new \WP_Error('IWP_FTP_1', __('File doesn\'t exist on ftp server.', 'jc-importer')); | |
| 60 | + } | |
| 61 | + | |
| 62 | + if ($size === 0) { | |
| 63 | + return false; | |
| 64 | + } | |
| 51 | 65 | } |
| 52 | 66 | |
| 67 | + if (!empty($override_filename)) { | |
| 53 | 68 | |
| 54 | - if ($size === 0) { | |
| 55 | - return false; | |
| 56 | - } | |
| 69 | + $wp_dest = $override_filename; | |
| 70 | + } else { | |
| 57 | 71 | |
| 58 | - $wp_upload_dir = wp_upload_dir(); | |
| 72 | + $wp_upload_dir = wp_upload_dir(); | |
| 59 | 73 | |
| 60 | - $dest = wp_unique_filename($wp_upload_dir['path'], basename($url)); | |
| 61 | - $wp_dest = $wp_upload_dir['path'] . '/' . $dest; | |
| 74 | + $dest = wp_unique_filename($wp_upload_dir['path'], basename($url)); | |
| 75 | + $wp_dest = $wp_upload_dir['path'] . '/' . $dest; | |
| 76 | + } | |
| 62 | 77 | |
| 63 | 78 | $passive_mode = apply_filters('iwp/ftp/passive_mode', true); |
| 64 | 79 | ftp_pasv($this->_conn, $passive_mode); |
| 65 | 80 | |
| @@ -64,9 +79,9 @@ | ||
| 64 | 79 | ftp_pasv($this->_conn, $passive_mode); |
| 65 | 80 | |
| 66 | 81 | $result = ftp_get($this->_conn, $wp_dest, $url, FTP_BINARY); |
| 67 | 82 | if (false === $result) { |
| 68 | - return new \WP_Error('IWP_FTP_2', 'Unable to download: ' . $url . ' file via ftp.'); | |
| 83 | + return new \WP_Error('IWP_FTP_2', sprintf(__('Unable to download: %s file via ftp.', 'jc-importer'), $url)); | |
| 69 | 84 | } |
| 70 | 85 | |
| 71 | 86 | return array( |
| 72 | 87 | 'dest' => $wp_dest, |
| @@ -101,6 +116,11 @@ | ||
| 101 | 116 | } |
| 102 | 117 | } |
| 103 | 118 | |
| 104 | 119 | return false; |
| 120 | + } | |
| 121 | + | |
| 122 | + public function get_connection() | |
| 123 | + { | |
| 124 | + return $this->_conn; | |
| 105 | 125 | } |
| 106 | 126 | } |