WPFS cleanups. Props DD32. fixes #9525
git-svn-id: http://svn.automattic.com/wordpress/trunk@10919 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
3dd79f8587
commit
31a2bbad76
|
@ -46,8 +46,6 @@ class WP_Filesystem_Base {
|
||||||
* @return string The location of the remote path.
|
* @return string The location of the remote path.
|
||||||
*/
|
*/
|
||||||
function abspath() {
|
function abspath() {
|
||||||
if ( defined('FTP_BASE') && strpos($this->method, 'ftp') !== false )
|
|
||||||
return FTP_BASE;
|
|
||||||
$folder = $this->find_folder(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') )
|
if ( ! $folder && $this->is_dir('/wp-includes') )
|
||||||
|
@ -62,8 +60,6 @@ class WP_Filesystem_Base {
|
||||||
* @return string The location of the remote path.
|
* @return string The location of the remote path.
|
||||||
*/
|
*/
|
||||||
function wp_content_dir() {
|
function wp_content_dir() {
|
||||||
if ( defined('FTP_CONTENT_DIR') && strpos($this->method, 'ftp') !== false )
|
|
||||||
return FTP_CONTENT_DIR;
|
|
||||||
return $this->find_folder(WP_CONTENT_DIR);
|
return $this->find_folder(WP_CONTENT_DIR);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -75,8 +71,6 @@ class WP_Filesystem_Base {
|
||||||
* @return string The location of the remote path.
|
* @return string The location of the remote path.
|
||||||
*/
|
*/
|
||||||
function wp_plugins_dir() {
|
function wp_plugins_dir() {
|
||||||
if ( defined('FTP_PLUGIN_DIR') && strpos($this->method, 'ftp') !== false )
|
|
||||||
return FTP_PLUGIN_DIR;
|
|
||||||
return $this->find_folder(WP_PLUGIN_DIR);
|
return $this->find_folder(WP_PLUGIN_DIR);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -142,6 +136,15 @@ class WP_Filesystem_Base {
|
||||||
*/
|
*/
|
||||||
function find_folder($folder) {
|
function find_folder($folder) {
|
||||||
|
|
||||||
|
if ( strpos($this->method, 'ftp') !== false ) {
|
||||||
|
$constant_overrides = array( 'FTP_BASE' => ABSPATH, 'FTP_CONTENT_DIR' => WP_CONTENT_DIR, 'FTP_PLUGIN_DIR' => WP_PLUGIN_DIR );
|
||||||
|
foreach ( $constant_overrides as $constant => $dir )
|
||||||
|
if ( defined($constant) && $folder === $dir )
|
||||||
|
return trailingslashit(constant($constant));
|
||||||
|
} elseif ( 'direct' == $this->method ) {
|
||||||
|
return trailingslashit($folder);
|
||||||
|
}
|
||||||
|
|
||||||
$folder = preg_replace('|^([a-z]{1}):|i', '', $folder); //Strip out windows driveletter if its there.
|
$folder = preg_replace('|^([a-z]{1}):|i', '', $folder); //Strip out windows driveletter if its there.
|
||||||
$folder = str_replace('\\', '/', $folder); //Windows path sanitiation
|
$folder = str_replace('\\', '/', $folder); //Windows path sanitiation
|
||||||
|
|
||||||
|
@ -149,6 +152,7 @@ class WP_Filesystem_Base {
|
||||||
return $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;
|
$this->cache[ $folder ] = $folder;
|
||||||
return $folder;
|
return $folder;
|
||||||
}
|
}
|
||||||
|
@ -203,7 +207,7 @@ class WP_Filesystem_Base {
|
||||||
if (isset( $files[ $last_path ] ) ) {
|
if (isset( $files[ $last_path ] ) ) {
|
||||||
if ( $this->verbose )
|
if ( $this->verbose )
|
||||||
printf( __('Found %s') . '<br/>', $base . $last_path );
|
printf( __('Found %s') . '<br/>', $base . $last_path );
|
||||||
return $base . $last_path;
|
return trailingslashit($base . $last_path);
|
||||||
}
|
}
|
||||||
if ( $loop )
|
if ( $loop )
|
||||||
return false;//Prevent tihs function looping again.
|
return false;//Prevent tihs function looping again.
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*/
|
*/
|
||||||
class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||||
var $permission = null;
|
var $permission = null;
|
||||||
var $errors = array();
|
var $errors = null;
|
||||||
function WP_Filesystem_Direct($arg) {
|
function WP_Filesystem_Direct($arg) {
|
||||||
$this->method = 'direct';
|
$this->method = 'direct';
|
||||||
$this->errors = new WP_Error();
|
$this->errors = new WP_Error();
|
||||||
|
@ -104,7 +104,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||||
return $ownerarray['name'];
|
return $ownerarray['name'];
|
||||||
}
|
}
|
||||||
function getchmod($file) {
|
function getchmod($file) {
|
||||||
return @fileperms($file);
|
return substr(decoct(@fileperms($file)),3);
|
||||||
}
|
}
|
||||||
function group($file) {
|
function group($file) {
|
||||||
$gid = @filegroup($file);
|
$gid = @filegroup($file);
|
||||||
|
@ -133,6 +133,8 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete($file, $recursive = false) {
|
function delete($file, $recursive = false) {
|
||||||
|
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 deleteing files otherwise
|
$file = str_replace('\\', '/', $file); //for win32, occasional problems deleteing files otherwise
|
||||||
|
|
||||||
if ( $this->is_file($file) )
|
if ( $this->is_file($file) )
|
||||||
|
@ -150,8 +152,8 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||||
if ( ! $this->delete($file . $filename, $recursive) )
|
if ( ! $this->delete($file . $filename, $recursive) )
|
||||||
$retval = false;
|
$retval = false;
|
||||||
|
|
||||||
if( ! @rmdir($file) )
|
if ( file_exists($file) && ! @rmdir($file) )
|
||||||
return false;
|
$retval = false;
|
||||||
return $retval;
|
return $retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
|
||||||
}
|
}
|
||||||
function getchmod($file) {
|
function getchmod($file) {
|
||||||
$dir = $this->dirlist($file);
|
$dir = $this->dirlist($file);
|
||||||
return $dir[$file]['permsn'];
|
return $this->getnumchmodfromh( $dir[basename($file)]['perms'] );
|
||||||
}
|
}
|
||||||
function group($file) {
|
function group($file) {
|
||||||
$dir = $this->dirlist($file);
|
$dir = $this->dirlist($file);
|
||||||
|
@ -188,6 +188,8 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete($file ,$recursive = false ) {
|
function delete($file ,$recursive = false ) {
|
||||||
|
if ( empty($file) )
|
||||||
|
return false;
|
||||||
if ( $this->is_file($file) )
|
if ( $this->is_file($file) )
|
||||||
return @ftp_delete($this->link, $file);
|
return @ftp_delete($this->link, $file);
|
||||||
if ( !$recursive )
|
if ( !$recursive )
|
||||||
|
@ -321,11 +323,12 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
|
||||||
}
|
}
|
||||||
|
|
||||||
function dirlist($path = '.', $incdot = false, $recursive = false) {
|
function dirlist($path = '.', $incdot = false, $recursive = false) {
|
||||||
if( $this->is_file($path) ) {
|
|
||||||
$limitFile = basename($path);
|
if ( substr($path, -1) !== '/') {
|
||||||
$path = dirname($path) . '/';
|
$limit = basename($path);
|
||||||
|
$path = trailingslashit(dirname($path));
|
||||||
} else {
|
} else {
|
||||||
$limitFile = false;
|
$limit = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$list = @ftp_rawlist($this->link, '-a ' . $path, false);
|
$list = @ftp_rawlist($this->link, '-a ' . $path, false);
|
||||||
|
@ -339,7 +342,10 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
|
||||||
if ( empty($entry) )
|
if ( empty($entry) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( '.' == $entry["name"] || '..' == $entry["name"] )
|
if ( '.' == $entry['name'] || '..' == $entry['name'] )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ( $limit && $entry['name'] != $limit )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
$dirlist[ $entry['name'] ] = $entry;
|
$dirlist[ $entry['name'] ] = $entry;
|
||||||
|
|
|
@ -186,7 +186,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
|
||||||
|
|
||||||
function getchmod($file) {
|
function getchmod($file) {
|
||||||
$dir = $this->dirlist($file);
|
$dir = $this->dirlist($file);
|
||||||
return $dir[$file]['permsn'];
|
return $this->getnumchmodfromh( $dir[basename($file)]['perms'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
function group($file) {
|
function group($file) {
|
||||||
|
@ -281,21 +281,25 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
|
||||||
}
|
}
|
||||||
|
|
||||||
function dirlist($path = '.', $incdot = false, $recursive = false ) {
|
function dirlist($path = '.', $incdot = false, $recursive = false ) {
|
||||||
if( $this->is_file($path) ) {
|
|
||||||
$limitFile = basename($path);
|
if ( substr($path, -1) !== '/') {
|
||||||
$path = dirname($path) . '/';
|
$limit = basename($path);
|
||||||
|
$path = trailingslashit(dirname($path));
|
||||||
} else {
|
} else {
|
||||||
$limitFile = false;
|
$limit = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$list = $this->ftp->dirlist($path);
|
$list = $this->ftp->dirlist($path);
|
||||||
if( ! $list )
|
if( ! $list )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( empty($list) )
|
if( empty($list) )
|
||||||
return array();
|
return array();
|
||||||
|
|
||||||
$ret = array();
|
$ret = array();
|
||||||
foreach ( $list as $struc ) {
|
foreach ( $list as $struc ) {
|
||||||
|
if ( $limit && $struc['name'] != $limit )
|
||||||
|
continue;
|
||||||
|
|
||||||
if ( 'd' == $struc['type'] ) {
|
if ( 'd' == $struc['type'] ) {
|
||||||
$struc['files'] = array();
|
$struc['files'] = array();
|
||||||
|
|
Loading…
Reference in New Issue