- Timestamp:
- 11/30/2017 11:09:33 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-filesystem-base.php
r42228 r42343 54 54 */ 55 55 public function abspath() { 56 $folder = $this->find_folder( ABSPATH);56 $folder = $this->find_folder( ABSPATH ); 57 57 // Perhaps the FTP folder is rooted at the WordPress install, Check for wp-includes folder in root, Could have some false positives, but rare. 58 if ( ! $folder && $this->is_dir( '/' . WPINC ) ) 58 if ( ! $folder && $this->is_dir( '/' . WPINC ) ) { 59 59 $folder = '/'; 60 } 60 61 return $folder; 61 62 } … … 69 70 */ 70 71 public function wp_content_dir() { 71 return $this->find_folder( WP_CONTENT_DIR);72 return $this->find_folder( WP_CONTENT_DIR ); 72 73 } 73 74 … … 80 81 */ 81 82 public function wp_plugins_dir() { 82 return $this->find_folder( WP_PLUGIN_DIR);83 return $this->find_folder( WP_PLUGIN_DIR ); 83 84 } 84 85 … … 95 96 96 97 // Account for relative theme roots 97 if ( '/themes' == $theme_root || ! is_dir( $theme_root ) ) 98 if ( '/themes' == $theme_root || ! is_dir( $theme_root ) ) { 98 99 $theme_root = WP_CONTENT_DIR . $theme_root; 100 } 99 101 100 102 return $this->find_folder( $theme_root ); … … 109 111 */ 110 112 public function wp_lang_dir() { 111 return $this->find_folder( WP_LANG_DIR);113 return $this->find_folder( WP_LANG_DIR ); 112 114 } 113 115 … … 129 131 */ 130 132 public function find_base_dir( $base = '.', $echo = false ) { 131 _deprecated_function( __FUNCTION__, '2.7.0', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );133 _deprecated_function( __FUNCTION__, '2.7.0', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' ); 132 134 $this->verbose = $echo; 133 135 return $this->abspath(); … … 150 152 */ 151 153 public function get_base_dir( $base = '.', $echo = false ) { 152 _deprecated_function( __FUNCTION__, '2.7.0', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );154 _deprecated_function( __FUNCTION__, '2.7.0', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' ); 153 155 $this->verbose = $echo; 154 156 return $this->abspath(); … … 167 169 */ 168 170 public function find_folder( $folder ) { 169 if ( isset( $this->cache[ $folder ] ) ) 171 if ( isset( $this->cache[ $folder ] ) ) { 170 172 return $this->cache[ $folder ]; 171 172 if ( stripos($this->method, 'ftp') !== false ) { 173 } 174 175 if ( stripos( $this->method, 'ftp' ) !== false ) { 173 176 $constant_overrides = array( 174 'FTP_BASE' => ABSPATH,177 'FTP_BASE' => ABSPATH, 175 178 'FTP_CONTENT_DIR' => WP_CONTENT_DIR, 176 'FTP_PLUGIN_DIR' => WP_PLUGIN_DIR,177 'FTP_LANG_DIR' => WP_LANG_DIR179 'FTP_PLUGIN_DIR' => WP_PLUGIN_DIR, 180 'FTP_LANG_DIR' => WP_LANG_DIR, 178 181 ); 179 182 180 183 // Direct matches ( folder = CONSTANT/ ) 181 184 foreach ( $constant_overrides as $constant => $dir ) { 182 if ( ! defined( $constant ) ) 185 if ( ! defined( $constant ) ) { 183 186 continue; 184 if ( $folder === $dir ) 187 } 188 if ( $folder === $dir ) { 185 189 return trailingslashit( constant( $constant ) ); 190 } 186 191 } 187 192 188 193 // Prefix Matches ( folder = CONSTANT/subdir ) 189 194 foreach ( $constant_overrides as $constant => $dir ) { 190 if ( ! defined( $constant ) ) 195 if ( ! defined( $constant ) ) { 191 196 continue; 197 } 192 198 if ( 0 === stripos( $folder, $dir ) ) { // $folder starts with $dir 193 199 $potential_folder = preg_replace( '#^' . preg_quote( $dir, '#' ) . '/#i', trailingslashit( constant( $constant ) ), $folder ); … … 201 207 } 202 208 } elseif ( 'direct' == $this->method ) { 203 $folder = str_replace( '\\', '/', $folder); // Windows path sanitisation204 return trailingslashit( $folder);205 } 206 207 $folder = preg_replace( '|^([a-z]{1}):|i', '', $folder); // Strip out windows drive letter if it's there.208 $folder = str_replace( '\\', '/', $folder); // Windows path sanitisation209 210 if ( isset( $this->cache[ $folder ] ) )209 $folder = str_replace( '\\', '/', $folder ); // Windows path sanitisation 210 return trailingslashit( $folder ); 211 } 212 213 $folder = preg_replace( '|^([a-z]{1}):|i', '', $folder ); // Strip out windows drive letter if it's there. 214 $folder = str_replace( '\\', '/', $folder ); // Windows path sanitisation 215 216 if ( isset( $this->cache[ $folder ] ) ) { 211 217 return $this->cache[ $folder ]; 212 213 if ( $this->exists($folder) ) { // Folder exists at that absolute path. 214 $folder = trailingslashit($folder); 218 } 219 220 if ( $this->exists( $folder ) ) { // Folder exists at that absolute path. 221 $folder = trailingslashit( $folder ); 215 222 $this->cache[ $folder ] = $folder; 216 223 return $folder; 217 224 } 218 if ( $return = $this->search_for_folder( $folder) )225 if ( $return = $this->search_for_folder( $folder ) ) { 219 226 $this->cache[ $folder ] = $return; 227 } 220 228 return $return; 221 229 } … … 234 242 */ 235 243 public function search_for_folder( $folder, $base = '.', $loop = false ) { 236 if ( empty( $base ) || '.' == $base ) 237 $base = trailingslashit($this->cwd()); 238 239 $folder = untrailingslashit($folder); 244 if ( empty( $base ) || '.' == $base ) { 245 $base = trailingslashit( $this->cwd() ); 246 } 247 248 $folder = untrailingslashit( $folder ); 240 249 241 250 if ( $this->verbose ) { … … 244 253 } 245 254 246 $folder_parts = explode('/', $folder);255 $folder_parts = explode( '/', $folder ); 247 256 $folder_part_keys = array_keys( $folder_parts ); 248 $last_index = array_pop( $folder_part_keys );249 $last_path = $folder_parts[ $last_index ];257 $last_index = array_pop( $folder_part_keys ); 258 $last_path = $folder_parts[ $last_index ]; 250 259 251 260 $files = $this->dirlist( $base ); 252 261 253 262 foreach ( $folder_parts as $index => $key ) { 254 if ( $index == $last_index ) 263 if ( $index == $last_index ) { 255 264 continue; // We want this to be caught by the next code block. 265 } 256 266 257 267 /* … … 262 272 * cant find it, it'll return false for the entire function. 263 273 */ 264 if ( isset( $files[ $key ]) ){274 if ( isset( $files[ $key ] ) ) { 265 275 266 276 // Let's try that folder: 267 $newdir = trailingslashit( path_join($base, $key));277 $newdir = trailingslashit( path_join( $base, $key ) ); 268 278 if ( $this->verbose ) { 269 279 /* translators: %s: directory name */ … … 273 283 // Only search for the remaining path tokens in the directory, not the full path again. 274 284 $newfolder = implode( '/', array_slice( $folder_parts, $index + 1 ) ); 275 if ( $ret = $this->search_for_folder( $newfolder, $newdir, $loop ) )285 if ( $ret = $this->search_for_folder( $newfolder, $newdir, $loop ) ) { 276 286 return $ret; 287 } 277 288 } 278 289 } … … 280 291 // Only check this as a last resort, to prevent locating the incorrect install. 281 292 // All above procedures will fail quickly if this is the right branch to take. 282 if ( isset( $files[ $last_path ] ) ) {293 if ( isset( $files[ $last_path ] ) ) { 283 294 if ( $this->verbose ) { 284 295 /* translators: %s: directory name */ 285 printf( "\n" . __( 'Found %s' ) . "<br/>\n", 296 printf( "\n" . __( 'Found %s' ) . "<br/>\n", $base . $last_path ); 286 297 } 287 return trailingslashit( $base . $last_path);298 return trailingslashit( $base . $last_path ); 288 299 } 289 300 290 301 // Prevent this function from looping again. 291 302 // No need to proceed if we've just searched in / 292 if ( $loop || '/' == $base ) 303 if ( $loop || '/' == $base ) { 293 304 return false; 305 } 294 306 295 307 // As an extra last resort, Change back to / if the folder wasn't found. … … 311 323 * @return string The *nix-style representation of permissions. 312 324 */ 313 public function gethchmod( $file ) {325 public function gethchmod( $file ) { 314 326 $perms = intval( $this->getchmod( $file ), 8 ); 315 if ( ($perms & 0xC000) == 0xC000)// Socket327 if ( ( $perms & 0xC000 ) == 0xC000 ) { // Socket 316 328 $info = 's'; 317 elseif (($perms & 0xA000) == 0xA000)// Symbolic Link329 } elseif ( ( $perms & 0xA000 ) == 0xA000 ) { // Symbolic Link 318 330 $info = 'l'; 319 elseif (($perms & 0x8000) == 0x8000)// Regular331 } elseif ( ( $perms & 0x8000 ) == 0x8000 ) { // Regular 320 332 $info = '-'; 321 elseif (($perms & 0x6000) == 0x6000)// Block special333 } elseif ( ( $perms & 0x6000 ) == 0x6000 ) { // Block special 322 334 $info = 'b'; 323 elseif (($perms & 0x4000) == 0x4000)// Directory335 } elseif ( ( $perms & 0x4000 ) == 0x4000 ) { // Directory 324 336 $info = 'd'; 325 elseif (($perms & 0x2000) == 0x2000)// Character special337 } elseif ( ( $perms & 0x2000 ) == 0x2000 ) { // Character special 326 338 $info = 'c'; 327 elseif (($perms & 0x1000) == 0x1000)// FIFO pipe339 } elseif ( ( $perms & 0x1000 ) == 0x1000 ) { // FIFO pipe 328 340 $info = 'p'; 329 else// Unknown341 } else { // Unknown 330 342 $info = 'u'; 343 } 331 344 332 345 // Owner 333 $info .= ( ($perms & 0x0100) ? 'r' : '-');334 $info .= ( ($perms & 0x0080) ? 'w' : '-');335 $info .= ( ($perms & 0x0040) ?336 ( ($perms & 0x0800) ? 's' : 'x' ) :337 ( ($perms & 0x0800) ? 'S' : '-'));346 $info .= ( ( $perms & 0x0100 ) ? 'r' : '-' ); 347 $info .= ( ( $perms & 0x0080 ) ? 'w' : '-' ); 348 $info .= ( ( $perms & 0x0040 ) ? 349 ( ( $perms & 0x0800 ) ? 's' : 'x' ) : 350 ( ( $perms & 0x0800 ) ? 'S' : '-' ) ); 338 351 339 352 // Group 340 $info .= ( ($perms & 0x0020) ? 'r' : '-');341 $info .= ( ($perms & 0x0010) ? 'w' : '-');342 $info .= ( ($perms & 0x0008) ?343 ( ($perms & 0x0400) ? 's' : 'x' ) :344 ( ($perms & 0x0400) ? 'S' : '-'));353 $info .= ( ( $perms & 0x0020 ) ? 'r' : '-' ); 354 $info .= ( ( $perms & 0x0010 ) ? 'w' : '-' ); 355 $info .= ( ( $perms & 0x0008 ) ? 356 ( ( $perms & 0x0400 ) ? 's' : 'x' ) : 357 ( ( $perms & 0x0400 ) ? 'S' : '-' ) ); 345 358 346 359 // World 347 $info .= ( ($perms & 0x0004) ? 'r' : '-');348 $info .= ( ($perms & 0x0002) ? 'w' : '-');349 $info .= ( ($perms & 0x0001) ?350 ( ($perms & 0x0200) ? 't' : 'x' ) :351 ( ($perms & 0x0200) ? 'T' : '-'));360 $info .= ( ( $perms & 0x0004 ) ? 'r' : '-' ); 361 $info .= ( ( $perms & 0x0002 ) ? 'w' : '-' ); 362 $info .= ( ( $perms & 0x0001 ) ? 363 ( ( $perms & 0x0200 ) ? 't' : 'x' ) : 364 ( ( $perms & 0x0200 ) ? 'T' : '-' ) ); 352 365 return $info; 353 366 } … … 369 382 * Converts '-rw-r--r--' to 0644 370 383 * From "info at rvgate dot nl"'s comment on the PHP documentation for chmod() 371 384 * 372 385 * @link https://secure.php.net/manual/en/function.chmod.php#49614 373 386 * … … 379 392 public function getnumchmodfromh( $mode ) { 380 393 $realmode = ''; 381 $legal = array('', 'w', 'r', 'x', '-');382 $attarray = preg_split( '//', $mode);394 $legal = array( '', 'w', 'r', 'x', '-' ); 395 $attarray = preg_split( '//', $mode ); 383 396 384 397 for ( $i = 0, $c = count( $attarray ); $i < $c; $i++ ) { 385 if ( $key = array_search($attarray[$i], $legal)) {386 $realmode .= $legal[ $key];398 if ( $key = array_search( $attarray[ $i ], $legal ) ) { 399 $realmode .= $legal[ $key ]; 387 400 } 388 401 } 389 402 390 $mode = str_pad($realmode, 10, '-', STR_PAD_LEFT); 391 $trans = array('-'=>'0', 'r'=>'4', 'w'=>'2', 'x'=>'1'); 392 $mode = strtr($mode,$trans); 393 394 $newmode = $mode[0]; 403 $mode = str_pad( $realmode, 10, '-', STR_PAD_LEFT ); 404 $trans = array( 405 '-' => '0', 406 'r' => '4', 407 'w' => '2', 408 'x' => '1', 409 ); 410 $mode = strtr( $mode, $trans ); 411 412 $newmode = $mode[0]; 395 413 $newmode .= $mode[1] + $mode[2] + $mode[3]; 396 414 $newmode .= $mode[4] + $mode[5] + $mode[6]; … … 540 558 * @since 2.5.0 541 559 * @abstract 542 * 560 * 543 561 * @param string $file Path to the file. 544 562 * @return string|bool Username of the user or false on error.
Note: See TracChangeset
for help on using the changeset viewer.