diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-admin/includes/class-wp-filesystem-base.php --- a/wp/wp-admin/includes/class-wp-filesystem-base.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-admin/includes/class-wp-filesystem-base.php Tue Dec 15 13:49:49 2020 +0100 @@ -55,10 +55,13 @@ */ public function abspath() { $folder = $this->find_folder( ABSPATH ); - // Perhaps the FTP folder is rooted at the WordPress install, Check for wp-includes folder in root, Could have some false positives, but rare. + + // Perhaps the FTP folder is rooted at the WordPress install. + // Check for wp-includes folder in root. Could have some false positives, but rare. if ( ! $folder && $this->is_dir( '/' . WPINC ) ) { $folder = '/'; } + return $folder; } @@ -96,8 +99,8 @@ public function wp_themes_dir( $theme = false ) { $theme_root = get_theme_root( $theme ); - // Account for relative theme roots - if ( '/themes' == $theme_root || ! is_dir( $theme_root ) ) { + // Account for relative theme roots. + if ( '/themes' === $theme_root || ! is_dir( $theme_root ) ) { $theme_root = WP_CONTENT_DIR . $theme_root; } @@ -182,38 +185,42 @@ 'FTP_LANG_DIR' => WP_LANG_DIR, ); - // Direct matches ( folder = CONSTANT/ ) + // Direct matches ( folder = CONSTANT/ ). foreach ( $constant_overrides as $constant => $dir ) { if ( ! defined( $constant ) ) { continue; } + if ( $folder === $dir ) { return trailingslashit( constant( $constant ) ); } } - // Prefix Matches ( folder = CONSTANT/subdir ) + // Prefix matches ( folder = CONSTANT/subdir ), foreach ( $constant_overrides as $constant => $dir ) { if ( ! defined( $constant ) ) { continue; } - if ( 0 === stripos( $folder, $dir ) ) { // $folder starts with $dir + + if ( 0 === stripos( $folder, $dir ) ) { // $folder starts with $dir. $potential_folder = preg_replace( '#^' . preg_quote( $dir, '#' ) . '/#i', trailingslashit( constant( $constant ) ), $folder ); $potential_folder = trailingslashit( $potential_folder ); if ( $this->is_dir( $potential_folder ) ) { $this->cache[ $folder ] = $potential_folder; + return $potential_folder; } } } - } elseif ( 'direct' == $this->method ) { - $folder = str_replace( '\\', '/', $folder ); // Windows path sanitisation + } elseif ( 'direct' === $this->method ) { + $folder = str_replace( '\\', '/', $folder ); // Windows path sanitisation. + return trailingslashit( $folder ); } - $folder = preg_replace( '|^([a-z]{1}):|i', '', $folder ); // Strip out windows drive letter if it's there. - $folder = str_replace( '\\', '/', $folder ); // Windows path sanitisation + $folder = preg_replace( '|^([a-z]{1}):|i', '', $folder ); // Strip out Windows drive letter if it's there. + $folder = str_replace( '\\', '/', $folder ); // Windows path sanitisation. if ( isset( $this->cache[ $folder ] ) ) { return $this->cache[ $folder ]; @@ -222,11 +229,16 @@ if ( $this->exists( $folder ) ) { // Folder exists at that absolute path. $folder = trailingslashit( $folder ); $this->cache[ $folder ] = $folder; + return $folder; } - if ( $return = $this->search_for_folder( $folder ) ) { + + $return = $this->search_for_folder( $folder ); + + if ( $return ) { $this->cache[ $folder ] = $return; } + return $return; } @@ -239,18 +251,18 @@ * * @param string $folder The folder to locate. * @param string $base The folder to start searching from. - * @param bool $loop If the function has recursed, Internal use only. + * @param bool $loop If the function has recursed. Internal use only. * @return string|false The location of the remote path, false to cease looping. */ public function search_for_folder( $folder, $base = '.', $loop = false ) { - if ( empty( $base ) || '.' == $base ) { + if ( empty( $base ) || '.' === $base ) { $base = trailingslashit( $this->cwd() ); } $folder = untrailingslashit( $folder ); if ( $this->verbose ) { - /* translators: 1: folder to locate, 2: folder to start searching from */ + /* translators: 1: Folder to locate, 2: Folder to start searching from. */ printf( "\n" . __( 'Looking for %1$s in %2$s' ) . "
\n", $folder, $base ); } @@ -277,14 +289,17 @@ // Let's try that folder: $newdir = trailingslashit( path_join( $base, $key ) ); + if ( $this->verbose ) { - /* translators: %s: directory name */ + /* translators: %s: Directory name. */ printf( "\n" . __( 'Changing to %s' ) . "
\n", $newdir ); } // Only search for the remaining path tokens in the directory, not the full path again. $newfolder = implode( '/', array_slice( $folder_parts, $index + 1 ) ); - if ( $ret = $this->search_for_folder( $newfolder, $newdir, $loop ) ) { + $ret = $this->search_for_folder( $newfolder, $newdir, $loop ); + + if ( $ret ) { return $ret; } } @@ -294,15 +309,16 @@ // All above procedures will fail quickly if this is the right branch to take. if ( isset( $files[ $last_path ] ) ) { if ( $this->verbose ) { - /* translators: %s: directory name */ + /* translators: %s: Directory name. */ printf( "\n" . __( 'Found %s' ) . "
\n", $base . $last_path ); } + return trailingslashit( $base . $last_path ); } // Prevent this function from looping again. - // No need to proceed if we've just searched in / - if ( $loop || '/' == $base ) { + // No need to proceed if we've just searched in `/`. + if ( $loop || '/' === $base ) { return false; } @@ -317,7 +333,7 @@ * * From the PHP documentation page for fileperms(). * - * @link https://secure.php.net/manual/en/function.fileperms.php + * @link https://www.php.net/manual/en/function.fileperms.php * * @since 2.5.0 * @@ -326,44 +342,46 @@ */ public function gethchmod( $file ) { $perms = intval( $this->getchmod( $file ), 8 ); - if ( ( $perms & 0xC000 ) == 0xC000 ) { // Socket + + if ( ( $perms & 0xC000 ) == 0xC000 ) { // Socket. $info = 's'; - } elseif ( ( $perms & 0xA000 ) == 0xA000 ) { // Symbolic Link + } elseif ( ( $perms & 0xA000 ) == 0xA000 ) { // Symbolic Link. $info = 'l'; - } elseif ( ( $perms & 0x8000 ) == 0x8000 ) { // Regular + } elseif ( ( $perms & 0x8000 ) == 0x8000 ) { // Regular. $info = '-'; - } elseif ( ( $perms & 0x6000 ) == 0x6000 ) { // Block special + } elseif ( ( $perms & 0x6000 ) == 0x6000 ) { // Block special. $info = 'b'; - } elseif ( ( $perms & 0x4000 ) == 0x4000 ) { // Directory + } elseif ( ( $perms & 0x4000 ) == 0x4000 ) { // Directory. $info = 'd'; - } elseif ( ( $perms & 0x2000 ) == 0x2000 ) { // Character special + } elseif ( ( $perms & 0x2000 ) == 0x2000 ) { // Character special. $info = 'c'; - } elseif ( ( $perms & 0x1000 ) == 0x1000 ) { // FIFO pipe + } elseif ( ( $perms & 0x1000 ) == 0x1000 ) { // FIFO pipe. $info = 'p'; - } else { // Unknown + } else { // Unknown. $info = 'u'; } - // Owner + // Owner. $info .= ( ( $perms & 0x0100 ) ? 'r' : '-' ); $info .= ( ( $perms & 0x0080 ) ? 'w' : '-' ); $info .= ( ( $perms & 0x0040 ) ? ( ( $perms & 0x0800 ) ? 's' : 'x' ) : ( ( $perms & 0x0800 ) ? 'S' : '-' ) ); - // Group + // Group. $info .= ( ( $perms & 0x0020 ) ? 'r' : '-' ); $info .= ( ( $perms & 0x0010 ) ? 'w' : '-' ); $info .= ( ( $perms & 0x0008 ) ? ( ( $perms & 0x0400 ) ? 's' : 'x' ) : ( ( $perms & 0x0400 ) ? 'S' : '-' ) ); - // World + // World. $info .= ( ( $perms & 0x0004 ) ? 'r' : '-' ); $info .= ( ( $perms & 0x0002 ) ? 'w' : '-' ); $info .= ( ( $perms & 0x0001 ) ? ( ( $perms & 0x0200 ) ? 't' : 'x' ) : ( ( $perms & 0x0200 ) ? 'T' : '-' ) ); + return $info; } @@ -385,7 +403,7 @@ * Converts '-rw-r--r--' to 0644 * From "info at rvgate dot nl"'s comment on the PHP documentation for chmod() * - * @link https://secure.php.net/manual/en/function.chmod.php#49614 + * @link https://www.php.net/manual/en/function.chmod.php#49614 * * @since 2.5.0 * @@ -398,7 +416,9 @@ $attarray = preg_split( '//', $mode ); for ( $i = 0, $c = count( $attarray ); $i < $c; $i++ ) { - if ( $key = array_search( $attarray[ $i ], $legal ) ) { + $key = array_search( $attarray[ $i ], $legal, true ); + + if ( $key ) { $realmode .= $legal[ $key ]; } } @@ -416,6 +436,7 @@ $newmode .= $mode[1] + $mode[2] + $mode[3]; $newmode .= $mode[4] + $mode[5] + $mode[6]; $newmode .= $mode[7] + $mode[8] + $mode[9]; + return $newmode; } @@ -552,7 +573,7 @@ * @param string $file Path to the file. * @param int|false $mode Optional. The permissions as octal number, usually 0644 for files, * 0755 for directories. Default false. - * @param bool $recursive Optional. If set to true, changes file group recursively. + * @param bool $recursive Optional. If set to true, changes file permissions recursively. * Default false. * @return bool True on success, false on failure. */ @@ -627,7 +648,7 @@ * @abstract * * @param string $file Path to the file or directory. - * @param bool $recursive Optional. If set to true, changes file group recursively. + * @param bool $recursive Optional. If set to true, deletes files and folders recursively. * Default false. * @param string|false $type Type of resource. 'f' for file, 'd' for directory. * Default false. @@ -824,4 +845,4 @@ return false; } -} // WP_Filesystem_Base +}