diff --git a/wp-admin/includes/class-wp-filesystem-base.php b/wp-admin/includes/class-wp-filesystem-base.php index 1a67280b4e..bfd3617668 100644 --- a/wp-admin/includes/class-wp-filesystem-base.php +++ b/wp-admin/includes/class-wp-filesystem-base.php @@ -20,6 +20,7 @@ class WP_Filesystem_Base { * @var bool */ var $verbose = false; + /** * Cached list of local filepaths to mapped remote filepaths. * @@ -47,11 +48,12 @@ class WP_Filesystem_Base { */ 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('/wp-includes') ) $folder = '/'; return $folder; } + /** * Returns the path on the remote filesystem of WP_CONTENT_DIR * @@ -62,6 +64,7 @@ class WP_Filesystem_Base { function wp_content_dir() { return $this->find_folder(WP_CONTENT_DIR); } + /** * Returns the path on the remote filesystem of WP_PLUGIN_DIR * @@ -73,6 +76,7 @@ class WP_Filesystem_Base { function wp_plugins_dir() { return $this->find_folder(WP_PLUGIN_DIR); } + /** * Returns the path on the remote filesystem of the Themes Directory * @@ -91,6 +95,7 @@ class WP_Filesystem_Base { return $this->find_folder( $theme_root ); } + /** * Returns the path on the remote filesystem of WP_LANG_DIR * @@ -121,6 +126,7 @@ class WP_Filesystem_Base { $this->verbose = $echo; return $this->abspath(); } + /** * Locates a folder on the remote filesystem. * @@ -188,17 +194,17 @@ class WP_Filesystem_Base { } } } elseif ( 'direct' == $this->method ) { - $folder = str_replace('\\', '/', $folder); //Windows path sanitisation + $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 ]; - if ( $this->exists($folder) ) { //Folder exists at that absolute path. + if ( $this->exists($folder) ) { // Folder exists at that absolute path. $folder = trailingslashit($folder); $this->cache[ $folder ] = $folder; return $folder; @@ -239,14 +245,14 @@ class WP_Filesystem_Base { foreach ( $folder_parts as $index => $key ) { if ( $index == $last_index ) - continue; //We want this to be caught by the next code block. + continue; // We want this to be caught by the next code block. - //Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder, + // Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder, // If it's found, change into it and follow through looking for it. // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on. // If it reaches the end, and still cant find it, it'll return false for the entire function. if ( isset($files[ $key ]) ){ - //Lets try that folder: + // Lets try that folder: $newdir = trailingslashit(path_join($base, $key)); if ( $this->verbose ) printf( "\n" . __('Changing to %s') . "
\n", $newdir ); @@ -257,7 +263,7 @@ class WP_Filesystem_Base { } } - //Only check this as a last resort, to prevent locating the incorrect install. All above procedures will fail quickly if this is the right branch to take. + // Only check this as a last resort, to prevent locating the incorrect install. All above procedures will fail quickly if this is the right branch to take. if (isset( $files[ $last_path ] ) ) { if ( $this->verbose ) printf( "\n" . __('Found %s') . "
\n", $base . $last_path ); @@ -372,6 +378,6 @@ class WP_Filesystem_Base { * @return bool true if string is binary, false otherwise */ function is_binary( $text ) { - return (bool) preg_match('|[^\x20-\x7E]|', $text); //chr(32)..chr(127) + return (bool) preg_match( '|[^\x20-\x7E]|', $text ); // chr(32)..chr(127) } } diff --git a/wp-admin/includes/class-wp-filesystem-direct.php b/wp-admin/includes/class-wp-filesystem-direct.php index 21548d5b4b..3f5bc64755 100644 --- a/wp-admin/includes/class-wp-filesystem-direct.php +++ b/wp-admin/includes/class-wp-filesystem-direct.php @@ -25,6 +25,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { $this->method = 'direct'; $this->errors = new WP_Error(); } + /** * connect filesystem. * @@ -33,6 +34,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { function connect() { return true; } + /** * Reads entire file into a string * @@ -42,6 +44,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { function get_contents($file) { return @file_get_contents($file); } + /** * Reads entire file into an array * @@ -51,6 +54,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { function get_contents_array($file) { return @file($file); } + /** * Write a string to a file * @@ -75,6 +79,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { return true; } + /** * Gets the current working directory * @@ -83,6 +88,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { function cwd() { return @getcwd(); } + /** * Change directory * @@ -92,6 +98,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { function chdir($dir) { return @chdir($dir); } + /** * Changes file group * @@ -107,7 +114,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { return @chgrp($file, $group); if ( ! $this->is_dir($file) ) return @chgrp($file, $group); - //Is a directory, and we want recursive + // Is a directory, and we want recursive $file = trailingslashit($file); $filelist = $this->dirlist($file); foreach ($filelist as $filename) @@ -115,6 +122,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { return true; } + /** * Changes filesystem permissions * @@ -135,7 +143,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { if ( ! $recursive || ! $this->is_dir($file) ) return @chmod($file, $mode); - //Is a directory, and we want recursive + // Is a directory, and we want recursive $file = trailingslashit($file); $filelist = $this->dirlist($file); foreach ( (array)$filelist as $filename => $filemeta) @@ -143,6 +151,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { return true; } + /** * Changes file owner * @@ -158,13 +167,14 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { return @chown($file, $owner); if ( ! $this->is_dir($file) ) return @chown($file, $owner); - //Is a directory, and we want recursive + // Is a directory, and we want recursive $filelist = $this->dirlist($file); foreach ($filelist as $filename) { $this->chown($file . '/' . $filename, $owner, $recursive); } return true; } + /** * Gets file owner * @@ -180,6 +190,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { $ownerarray = posix_getpwuid($owneruid); return $ownerarray['name']; } + /** * Gets file permissions * @@ -191,6 +202,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { function getchmod($file) { return substr(decoct(@fileperms($file)),3); } + function group($file) { $gid = @filegroup($file); if ( ! $gid ) @@ -228,27 +240,30 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { } function delete($file, $recursive = false, $type = false) { - if ( empty($file) ) //Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem. + if ( empty( $file ) ) // Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem. return false; - $file = str_replace('\\', '/', $file); //for win32, occasional problems deleting files otherwise + $file = str_replace( '\\', '/', $file ); // for win32, occasional problems deleting files otherwise if ( 'f' == $type || $this->is_file($file) ) return @unlink($file); if ( ! $recursive && $this->is_dir($file) ) return @rmdir($file); - //At this point it's a folder, and we're in recursive mode + // At this point it's a folder, and we're in recursive mode $file = trailingslashit($file); $filelist = $this->dirlist($file, true); $retval = true; - if ( is_array($filelist) ) //false if no files, So check first. - foreach ($filelist as $filename => $fileinfo) + if ( is_array( $filelist ) ) { + foreach ( $filelist as $filename => $fileinfo ) { if ( ! $this->delete($file . $filename, $recursive, $fileinfo['type']) ) $retval = false; + } + } if ( file_exists($file) && ! @rmdir($file) ) $retval = false; + return $retval; } @@ -279,6 +294,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { function mtime($file) { return @filemtime($file); } + function size($file) { return @filesize($file); } diff --git a/wp-admin/includes/class-wp-filesystem-ftpext.php b/wp-admin/includes/class-wp-filesystem-ftpext.php index 9d848b4bd3..f1c3b78097 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/wp-admin/includes/class-wp-filesystem-ftpext.php @@ -23,14 +23,13 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { $this->method = 'ftpext'; $this->errors = new WP_Error(); - //Check if possible to use ftp functions. + // Check if possible to use ftp functions. if ( ! extension_loaded('ftp') ) { $this->errors->add('no_ftp_ext', __('The ftp PHP extension is not available')); return false; } - // Set defaults: - //This Class uses the timeout on a per-connection basis, Others use it on a per-action basis. + // This Class uses the timeout on a per-connection basis, Others use it on a per-action basis. if ( ! defined('FS_TIMEOUT') ) define('FS_TIMEOUT', 240); @@ -80,7 +79,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { return false; } - //Set the Connection to use Passive FTP + // Set the Connection to use Passive FTP @ftp_pasv( $this->link, true ); if ( @ftp_get_option($this->link, FTP_TIMEOUT_SEC) < FS_TIMEOUT ) @ftp_set_option($this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT); @@ -98,7 +97,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { if ( ! @ftp_fget($this->link, $temp, $file, FTP_BINARY ) ) return false; - fseek($temp, 0); //Skip back to the start of the file being written to + fseek( $temp, 0 ); // Skip back to the start of the file being written to $contents = ''; while ( ! feof($temp) ) @@ -108,6 +107,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { unlink($tempfile); return $contents; } + function get_contents_array($file) { return explode("\n", $this->get_contents($file)); } @@ -136,18 +136,22 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { return $ret; } + function cwd() { $cwd = @ftp_pwd($this->link); if ( $cwd ) $cwd = trailingslashit($cwd); return $cwd; } + function chdir($dir) { return @ftp_chdir($this->link, $dir); } + function chgrp($file, $group, $recursive = false ) { return false; } + function chmod($file, $mode = false, $recursive = false) { if ( ! $mode ) { if ( $this->is_file($file) ) @@ -170,21 +174,26 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { return (bool)@ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file)); return (bool)@ftp_chmod($this->link, $mode, $file); } + function chown($file, $owner, $recursive = false ) { return false; } + function owner($file) { $dir = $this->dirlist($file); return $dir[$file]['owner']; } + function getchmod($file) { $dir = $this->dirlist($file); return $dir[$file]['permsn']; } + function group($file) { $dir = $this->dirlist($file); return $dir[$file]['group']; } + function copy($source, $destination, $overwrite = false, $mode = false) { if ( ! $overwrite && $this->exists($destination) ) return false; @@ -193,6 +202,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { return false; return $this->put_contents($destination, $content, $mode); } + function move($source, $destination, $overwrite = false) { return ftp_rename($this->link, $source, $destination); } @@ -216,9 +226,11 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { $list = @ftp_nlist($this->link, $file); return !empty($list); //empty list = no file, so invert. } + function is_file($file) { return $this->exists($file) && !$this->is_dir($file); } + function is_dir($path) { $cwd = $this->cwd(); $result = @ftp_chdir($this->link, trailingslashit($path) ); @@ -228,26 +240,31 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { } return false; } + function is_readable($file) { - //Get dir list, Check if the file is readable by the current user?? return true; } + function is_writable($file) { - //Get dir list, Check if the file is writable by the current user?? return true; } + function atime($file) { return false; } + function mtime($file) { return ftp_mdtm($this->link, $file); } + function size($file) { return ftp_size($this->link, $file); } + function touch($file, $time = 0, $atime = 0) { return false; } + function mkdir($path, $chmod = false, $chown = false, $chgrp = false) { $path = untrailingslashit($path); if ( empty($path) ) @@ -262,6 +279,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { $this->chgrp($path, $chgrp); return true; } + function rmdir($path, $recursive = false) { return $this->delete($path, $recursive); } diff --git a/wp-admin/includes/class-wp-filesystem-ftpsockets.php b/wp-admin/includes/class-wp-filesystem-ftpsockets.php index 8f9bbcb7f9..f938e85265 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpsockets.php +++ b/wp-admin/includes/class-wp-filesystem-ftpsockets.php @@ -23,12 +23,11 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { $this->method = 'ftpsockets'; $this->errors = new WP_Error(); - //Check if possible to use ftp functions. + // Check if possible to use ftp functions. if ( ! @include_once ABSPATH . 'wp-admin/includes/class-ftp.php' ) return false; $this->ftp = new ftp(); - //Set defaults: if ( empty($opt['port']) ) $this->options['port'] = 21; else @@ -93,10 +92,10 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { if ( ! $this->ftp->fget($temphandle, $file) ) { fclose($temphandle); unlink($temp); - return ''; //Blank document, File does exist, It's just blank. + return ''; // Blank document, File does exist, It's just blank. } - fseek($temphandle, 0); //Skip back to the start of the file being written to + fseek( $temphandle, 0 ); // Skip back to the start of the file being written to $contents = ''; while ( ! feof($temphandle) ) @@ -242,12 +241,10 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { } function is_readable($file) { - //Get dir list, Check if the file is writable by the current user?? return true; } function is_writable($file) { - //Get dir list, Check if the file is writable by the current user?? return true; }