| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | 4 | die( 'You are not allowed to call this page directly.' ); |
| 4 | 5 | } |
| 5 | 6 | |
| @@ -14,14 +15,14 @@ | ||
| 14 | 15 | public $chmod_file = 0644; |
| 15 | 16 | private $has_permission = false; |
| 16 | 17 | |
| 17 | 18 | public function __construct( $atts ) { |
| 18 | - $this->folder_name = isset( $atts['folder_name'] ) ? $atts['folder_name'] : ''; | |
| 19 | - $this->file_name = $atts['file_name']; | |
| 19 | + $this->folder_name = isset( $atts['folder_name'] ) ? $atts['folder_name'] : ''; | |
| 20 | + $this->file_name = $atts['file_name']; | |
| 20 | 21 | $this->error_message = isset( $atts['error_message'] ) ? $atts['error_message'] : ''; |
| 21 | - $this->uploads = wp_upload_dir(); | |
| 22 | + $this->uploads = wp_upload_dir(); | |
| 22 | 23 | $this->set_new_file_path( $atts ); |
| 23 | - $this->chmod_dir = defined( 'FS_CHMOD_DIR' ) ? FS_CHMOD_DIR : ( fileperms( ABSPATH ) & 0777 | 0755 ); | |
| 24 | + $this->chmod_dir = defined( 'FS_CHMOD_DIR' ) ? FS_CHMOD_DIR : ( fileperms( ABSPATH ) & 0777 | 0755 ); | |
| 24 | 25 | $this->chmod_file = defined( 'FS_CHMOD_FILE' ) ? FS_CHMOD_FILE : ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ); |
| 25 | 26 | |
| 26 | 27 | $this->check_permission(); |
| 27 | 28 | } |
| @@ -27,10 +28,8 @@ | ||
| 27 | 28 | } |
| 28 | 29 | |
| 29 | 30 | /** |
| 30 | 31 | * @since 3.0 |
| 31 | - * | |
| 32 | - * @return void | |
| 33 | 32 | */ |
| 34 | 33 | private function set_new_file_path( $atts ) { |
| 35 | 34 | if ( isset( $atts['new_file_path'] ) ) { |
| 36 | 35 | $this->new_file_path = $atts['new_file_path'] . '/' . $this->file_name; |
| @@ -38,13 +37,8 @@ | ||
| 38 | 37 | $this->new_file_path = $this->uploads['basedir'] . '/' . $this->folder_name . '/' . $this->file_name; |
| 39 | 38 | } |
| 40 | 39 | } |
| 41 | 40 | |
| 42 | - /** | |
| 43 | - * @param string $file_content | |
| 44 | - * | |
| 45 | - * @return void | |
| 46 | - */ | |
| 47 | 41 | public function create_file( $file_content ) { |
| 48 | 42 | if ( $this->has_permission ) { |
| 49 | 43 | $dirs_exist = true; |
| 50 | 44 | |
| @@ -60,10 +54,8 @@ | ||
| 60 | 54 | } |
| 61 | 55 | |
| 62 | 56 | /** |
| 63 | 57 | * @since 3.0 |
| 64 | - * | |
| 65 | - * @return void | |
| 66 | 58 | */ |
| 67 | 59 | public function append_file( $file_content ) { |
| 68 | 60 | if ( $this->has_permission ) { |
| 69 | 61 | |
| @@ -69,9 +61,9 @@ | ||
| 69 | 61 | |
| 70 | 62 | if ( file_exists( $this->new_file_path ) ) { |
| 71 | 63 | |
| 72 | 64 | $existing_content = $this->get_contents(); |
| 73 | - $file_content = $existing_content . $file_content; | |
| 65 | + $file_content = $existing_content . $file_content; | |
| 74 | 66 | } |
| 75 | 67 | |
| 76 | 68 | $this->create_file( $file_content ); |
| 77 | 69 | } |
| @@ -82,10 +74,8 @@ | ||
| 82 | 74 | * |
| 83 | 75 | * @since 3.0 |
| 84 | 76 | * |
| 85 | 77 | * @param array $file_names And array of file paths |
| 86 | - * | |
| 87 | - * @return void | |
| 88 | 78 | */ |
| 89 | 79 | public function combine_files( $file_names ) { |
| 90 | 80 | if ( $this->has_permission ) { |
| 91 | 81 | $content = ''; |
| @@ -116,16 +106,13 @@ | ||
| 116 | 106 | global $wp_filesystem; |
| 117 | 107 | if ( empty( $file ) ) { |
| 118 | 108 | $file = $this->new_file_path; |
| 119 | 109 | } |
| 120 | - | |
| 121 | 110 | return $wp_filesystem->get_contents( $file ); |
| 122 | 111 | } |
| 123 | 112 | |
| 124 | 113 | /** |
| 125 | 114 | * @since 3.0 |
| 126 | - * | |
| 127 | - * @return void | |
| 128 | 115 | */ |
| 129 | 116 | private function check_permission() { |
| 130 | 117 | $creds = $this->get_creds(); |
| 131 | 118 | |
| @@ -136,13 +123,8 @@ | ||
| 136 | 123 | $this->has_permission = false; |
| 137 | 124 | } |
| 138 | 125 | } |
| 139 | 126 | |
| 140 | - /** | |
| 141 | - * @param true $dirs_exist | |
| 142 | - * | |
| 143 | - * @return void | |
| 144 | - */ | |
| 145 | 127 | private function create_directories( &$dirs_exist ) { |
| 146 | 128 | global $wp_filesystem; |
| 147 | 129 | |
| 148 | 130 | $needed_dirs = $this->get_needed_dirs(); |
| @@ -156,18 +138,15 @@ | ||
| 156 | 138 | } |
| 157 | 139 | } |
| 158 | 140 | } |
| 159 | 141 | |
| 160 | - /** | |
| 161 | - * @return string[] | |
| 162 | - */ | |
| 163 | 142 | private function get_needed_dirs() { |
| 164 | - $dir_names = explode( '/', $this->folder_name ); | |
| 143 | + $dir_names = explode( '/', $this->folder_name ); | |
| 165 | 144 | $needed_dirs = array(); |
| 166 | 145 | |
| 167 | 146 | $next_dir = ''; |
| 168 | 147 | foreach ( $dir_names as $dir ) { |
| 169 | - $next_dir .= '/' . $dir; | |
| 148 | + $next_dir .= '/' . $dir; | |
| 170 | 149 | $needed_dirs[] = $this->uploads['basedir'] . $next_dir; |
| 171 | 150 | } |
| 172 | 151 | |
| 173 | 152 | return $needed_dirs; |
| @@ -183,15 +162,11 @@ | ||
| 183 | 162 | $creds = request_filesystem_credentials( site_url() . '/wp-admin/', '', false, false, array() ); |
| 184 | 163 | } else { |
| 185 | 164 | $creds = $this->get_ftp_creds( $access_type ); |
| 186 | 165 | } |
| 187 | - | |
| 188 | 166 | return $creds; |
| 189 | 167 | } |
| 190 | 168 | |
| 191 | - /** | |
| 192 | - * @param string $type | |
| 193 | - */ | |
| 194 | 169 | private function get_ftp_creds( $type ) { |
| 195 | 170 | $credentials = get_option( |
| 196 | 171 | 'ftp_credentials', |
| 197 | 172 | array( |
| @@ -204,9 +179,9 @@ | ||
| 204 | 179 | $credentials['username'] = defined( 'FTP_USER' ) ? FTP_USER : $credentials['username']; |
| 205 | 180 | $credentials['password'] = defined( 'FTP_PASS' ) ? FTP_PASS : ''; |
| 206 | 181 | |
| 207 | 182 | // Check to see if we are setting the public/private keys for ssh |
| 208 | - $credentials['public_key'] = defined( 'FTP_PUBKEY' ) ? FTP_PUBKEY : ''; | |
| 183 | + $credentials['public_key'] = defined( 'FTP_PUBKEY' ) ? FTP_PUBKEY : ''; | |
| 209 | 184 | $credentials['private_key'] = defined( 'FTP_PRIKEY' ) ? FTP_PRIKEY : ''; |
| 210 | 185 | |
| 211 | 186 | // Sanitize the hostname, Some people might pass in odd-data: |
| 212 | 187 | $credentials['hostname'] = preg_replace( '|\w+://|', '', $credentials['hostname'] ); //Strip any schemes off |
| @@ -221,18 +196,18 @@ | ||
| 221 | 196 | } |
| 222 | 197 | |
| 223 | 198 | if ( ( defined( 'FTP_SSH' ) && FTP_SSH ) || ( defined( 'FS_METHOD' ) && 'ssh2' == FS_METHOD ) ) { |
| 224 | 199 | $credentials['connection_type'] = 'ssh'; |
| 225 | - } elseif ( ( defined( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' == $type ) { | |
| 200 | + } else if ( ( defined( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' == $type ) { | |
| 226 | 201 | //Only the FTP Extension understands SSL |
| 227 | 202 | $credentials['connection_type'] = 'ftps'; |
| 228 | - } elseif ( ! isset( $credentials['connection_type'] ) ) { | |
| 203 | + } else if ( ! isset( $credentials['connection_type'] ) ) { | |
| 229 | 204 | //All else fails (And it's not defaulted to something else saved), Default to FTP |
| 230 | 205 | $credentials['connection_type'] = 'ftp'; |
| 231 | 206 | } |
| 232 | 207 | |
| 233 | 208 | $has_creds = ( ! empty( $credentials['password'] ) && ! empty( $credentials['username'] ) && ! empty( $credentials['hostname'] ) ); |
| 234 | - $can_ssh = ( 'ssh' == $credentials['connection_type'] && ! empty( $credentials['public_key'] ) && ! empty( $credentials['private_key'] ) ); | |
| 209 | + $can_ssh = ( 'ssh' == $credentials['connection_type'] && ! empty( $credentials['public_key'] ) && ! empty( $credentials['private_key'] ) ); | |
| 235 | 210 | if ( $has_creds || $can_ssh ) { |
| 236 | 211 | $stored_credentials = $credentials; |
| 237 | 212 | if ( ! empty( $stored_credentials['port'] ) ) { |
| 238 | 213 | //save port as part of hostname to simplify above code. |
| @@ -246,11 +221,8 @@ | ||
| 246 | 221 | |
| 247 | 222 | return false; |
| 248 | 223 | } |
| 249 | 224 | |
| 250 | - /** | |
| 251 | - * @return void | |
| 252 | - */ | |
| 253 | 225 | private function show_error_message() { |
| 254 | 226 | if ( ! empty( $this->error_message ) ) { |
| 255 | 227 | echo '<div class="message">' . esc_html( $this->error_message ) . '</div>'; |
| 256 | 228 | } |