Make WP_Filesystem work with new directory constants. Props DD32. fixes #7059

git-svn-id: http://svn.automattic.com/wordpress/trunk@8009 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-05-29 17:29:32 +00:00
parent f3511b048c
commit ffd63e3b33
6 changed files with 186 additions and 466 deletions

View File

@ -1,53 +1,45 @@
<?php
class WP_Filesystem_Direct{
class WP_Filesystem_Direct extends WP_Filesystem_Base {
var $permission = null;
var $errors = array();
function WP_Filesystem_Direct($arg){
function WP_Filesystem_Direct($arg) {
$this->errors = new WP_Error();
$this->permission = umask();
}
function connect(){
function connect() {
return true;
}
function setDefaultPermissions($perm){
function setDefaultPermissions($perm) {
$this->permission = $perm;
}
function find_base_dir($path = false, $base = '.', $echo = false){
if (!$path)
$path = ABSPATH;
return str_replace('\\','/',$path);
}
function get_base_dir($path = false, $base = '.', $echo = false){
return $this->find_base_dir($base, $echo);
}
function get_contents($file){
function get_contents($file) {
return @file_get_contents($file);
}
function get_contents_array($file){
function get_contents_array($file) {
return @file($file);
}
function put_contents($file,$contents,$mode=false,$type=''){
if ( ! ($fp = @fopen($file,'w'.$type)) )
function put_contents($file,$contents,$mode=false,$type='') {
if ( ! ($fp = @fopen($file,'w' . $type)) )
return false;
@fwrite($fp,$contents);
@fclose($fp);
$this->chmod($file,$mode);
return true;
}
function cwd(){
function cwd() {
return @getcwd();
}
function chdir($dir){
function chdir($dir) {
return @chdir($dir);
}
function chgrp($file,$group,$recursive=false){
function chgrp($file,$group,$recursive=false) {
if( ! $this->exists($file) )
return false;
if( ! $recursive )
return @chgrp($file,$group);
return @chgrp($file, $group);
if( ! $this->is_dir($file) )
return @chgrp($file,$group);
return @chgrp($file, $group);
//Is a directory, and we want recursive
$file = trailingslashit($file);
$filelist = $this->dirlist($file);
@ -56,7 +48,7 @@ class WP_Filesystem_Direct{
return true;
}
function chmod($file,$mode=false,$recursive=false){
function chmod($file,$mode=false,$recursive=false) {
if( ! $mode )
$mode = $this->permission;
if( ! $this->exists($file) )
@ -64,7 +56,7 @@ class WP_Filesystem_Direct{
if( ! $recursive )
return @chmod($file,$mode);
if( ! $this->is_dir($file) )
return @chmod($file,$mode);
return @chmod($file, $mode);
//Is a directory, and we want recursive
$file = trailingslashit($file);
$filelist = $this->dirlist($file);
@ -73,120 +65,51 @@ class WP_Filesystem_Direct{
return true;
}
function chown($file,$owner,$recursive=false){
function chown($file, $owner, $recursive = false) {
if( ! $this->exists($file) )
return false;
if( ! $recursive )
return @chown($file,$owner);
return @chown($file, $owner);
if( ! $this->is_dir($file) )
return @chown($file,$owner);
return @chown($file, $owner);
//Is a directory, and we want recursive
$filelist = $this->dirlist($file);
foreach($filelist as $filename){
$this->chown($file.'/'.$filename,$owner,$recursive);
$this->chown($file . '/' . $filename, $owner, $recursive);
}
return true;
}
function owner($file){
function owner($file) {
$owneruid = @fileowner($file);
if( ! $owneruid )
return false;
if( !function_exists('posix_getpwuid') )
if( ! function_exists('posix_getpwuid') )
return $owneruid;
$ownerarray = posix_getpwuid($owneruid);
return $ownerarray['name'];
}
function getchmod($file){
function getchmod($file) {
return @fileperms($file);
}
function gethchmod($file){
//From the PHP.net page for ...?
$perms = $this->getchmod($file);
if (($perms & 0xC000) == 0xC000) {
// Socket
$info = 's';
} elseif (($perms & 0xA000) == 0xA000) {
// Symbolic Link
$info = 'l';
} elseif (($perms & 0x8000) == 0x8000) {
// Regular
$info = '-';
} elseif (($perms & 0x6000) == 0x6000) {
// Block special
$info = 'b';
} elseif (($perms & 0x4000) == 0x4000) {
// Directory
$info = 'd';
} elseif (($perms & 0x2000) == 0x2000) {
// Character special
$info = 'c';
} elseif (($perms & 0x1000) == 0x1000) {
// FIFO pipe
$info = 'p';
} else {
// Unknown
$info = 'u';
}
// Owner
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ?
(($perms & 0x0800) ? 's' : 'x' ) :
(($perms & 0x0800) ? 'S' : '-'));
// Group
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ?
(($perms & 0x0400) ? 's' : 'x' ) :
(($perms & 0x0400) ? 'S' : '-'));
// World
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ?
(($perms & 0x0200) ? 't' : 'x' ) :
(($perms & 0x0200) ? 'T' : '-'));
return $info;
}
function getnumchmodfromh($mode) {
$realmode = "";
$legal = array("","w","r","x","-");
$attarray = preg_split("//",$mode);
for($i=0;$i<count($attarray);$i++){
if($key = array_search($attarray[$i],$legal)){
$realmode .= $legal[$key];
}
}
$mode = str_pad($realmode,9,'-');
$trans = array('-'=>'0','r'=>'4','w'=>'2','x'=>'1');
$mode = strtr($mode,$trans);
$newmode = '';
$newmode .= $mode[0]+$mode[1]+$mode[2];
$newmode .= $mode[3]+$mode[4]+$mode[5];
$newmode .= $mode[6]+$mode[7]+$mode[8];
return $newmode;
}
function group($file){
function group($file) {
$gid = @filegroup($file);
if( ! $gid )
return false;
if( !function_exists('posix_getgrgid') )
if( ! function_exists('posix_getgrgid') )
return $gid;
$grouparray = posix_getgrgid($gid);
return $grouparray['name'];
}
function copy($source,$destination,$overwrite=false){
function copy($source, $destination, $overwrite = false) {
if( ! $overwrite && $this->exists($destination) )
return false;
return copy($source,$destination);
return copy($source, $destination);
}
function move($source,$destination,$overwrite=false){
function move($source, $destination, $overwrite = false) {
//Possible to use rename()?
if( $this->copy($source,$destination,$overwrite) && $this->exists($destination) ){
if( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ){
$this->delete($source);
return true;
} else {
@ -194,12 +117,12 @@ class WP_Filesystem_Direct{
}
}
function delete($file, $recursive=false){
$file = str_replace('\\','/',$file); //for win32, occasional problems deleteing files otherwise
function delete($file, $recursive = false) {
$file = str_replace('\\', '/', $file); //for win32, occasional problems deleteing files otherwise
if( $this->is_file($file) )
return @unlink($file);
if( !$recursive && $this->is_dir($file) )
if( ! $recursive && $this->is_dir($file) )
return @rmdir($file);
//At this point its a folder, and we're in recursive mode
@ -208,7 +131,7 @@ class WP_Filesystem_Direct{
$retval = true;
if( is_array($filelist) ) //false if no files, So check first.
foreach($filelist as $filename=>$fileinfo)
foreach($filelist as $filename => $fileinfo)
if( ! $this->delete($file . $filename, $recursive) )
$retval = false;
@ -217,34 +140,34 @@ class WP_Filesystem_Direct{
return $retval;
}
function exists($file){
function exists($file) {
return @file_exists($file);
}
function is_file($file){
function is_file($file) {
return @is_file($file);
}
function is_dir($path){
function is_dir($path) {
return @is_dir($path);
}
function is_readable($file){
function is_readable($file) {
return @is_readable($file);
}
function is_writable($file){
function is_writable($file) {
return @is_writable($file);
}
function atime($file){
function atime($file) {
return @fileatime($file);
}
function mtime($file){
function mtime($file) {
return @filemtime($file);
}
function size($file){
function size($file) {
return @filesize($file);
}
@ -253,38 +176,38 @@ class WP_Filesystem_Direct{
$time = time();
if($atime == 0)
$atime = time();
return @touch($file,$time,$atime);
return @touch($file, $time, $atime);
}
function mkdir($path, $chmod = false, $chown = false, $chgrp = false){
if( ! $chmod)
$chmod = $this->permission;
if( !@mkdir($path,$chmod) )
if( ! @mkdir($path, $chmod) )
return false;
if( $chown )
$this->chown($path,$chown);
$this->chown($path, $chown);
if( $chgrp )
$this->chgrp($path,$chgrp);
$this->chgrp($path, $chgrp);
return true;
}
function rmdir($path,$recursive=false){
function rmdir($path, $recursive = false) {
//Currently unused and untested, Use delete() instead.
if( ! $recursive )
return @rmdir($path);
//recursive:
$filelist = $this->dirlist($path);
foreach($filelist as $filename=>$det){
if ( '/' == substr($filename,-1,1) )
$this->rmdir($path.'/'.$filename,$recursive);
foreach($filelist as $filename => $det) {
if ( '/' == substr($filename, -1, 1) )
$this->rmdir($path . '/' . $filename, $recursive);
@rmdir($filename);
}
return @rmdir($path);
}
function dirlist($path,$incdot=false,$recursive=false){
if( $this->is_file($path) ){
function dirlist($path, $incdot = false, $recursive = false) {
if( $this->is_file($path) ) {
$limitFile = basename($path);
$path = dirname($path);
} else {
@ -295,9 +218,9 @@ class WP_Filesystem_Direct{
$ret = array();
$dir = dir($path);
while (false !== ($entry = $dir->read())) {
while (false !== ($entry = $dir->read()) ) {
$struc = array();
$struc['name'] = $entry;
$struc['name'] = $entry;
if( '.' == $struc['name'] || '..' == $struc['name'] )
continue; //Do not care about these folders.
@ -317,9 +240,9 @@ class WP_Filesystem_Direct{
$struc['time'] = date('h:i:s',$struc['lastmodunix']);
$struc['type'] = $this->is_dir($path.'/'.$entry) ? 'd' : 'f';
if ('d' == $struc['type'] ){
if ( 'd' == $struc['type'] ) {
if( $recursive )
$struc['files'] = $this->dirlist($path.'/'.$struc['name'], $incdot, $recursive);
$struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
else
$struc['files'] = array();
}
@ -330,9 +253,5 @@ class WP_Filesystem_Direct{
unset($dir);
return $ret;
}
function __destruct(){
return;
}
}
?>

View File

@ -1,11 +1,10 @@
<?php
class WP_Filesystem_FTPext{
class WP_Filesystem_FTPext extends WP_Filesystem_Base{
var $link;
var $timeout = 5;
var $errors = array();
var $options = array();
var $wp_base = '';
var $permission = null;
var $filetypes = array(
@ -24,6 +23,7 @@ class WP_Filesystem_FTPext{
);
function WP_Filesystem_FTPext($opt='') {
$this->method = 'ftpext';
$this->errors = new WP_Error();
//Check if possible to use ftp functions.
@ -60,12 +60,11 @@ class WP_Filesystem_FTPext{
$this->options['ssl'] = ( !empty($opt['ssl']) );
}
function connect(){
if ( $this->options['ssl'] && function_exists('ftp_ssl_connect') ) {
function connect() {
if ( $this->options['ssl'] && function_exists('ftp_ssl_connect') )
$this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'],$this->timeout);
} else {
else
$this->link = @ftp_connect($this->options['hostname'], $this->options['port'],$this->timeout);
}
if ( ! $this->link ) {
$this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
@ -80,79 +79,11 @@ class WP_Filesystem_FTPext{
return true;
}
function setDefaultPermissions($perm){
function setDefaultPermissions($perm) {
$this->permission = $perm;
}
function find_base_dir($path = false, $base = '.',$echo = false, $loop = false) {
if (!$path)
$path = ABSPATH;
//Sanitize the Windows path formats, This allows easier conparison and aligns it to FTP output.
$path = str_replace('\\','/',$path); //windows: Straighten up the paths..
if( strpos($path, ':') ){ //Windows, Strip out the driveletter
if( preg_match("|.{1}\:(.+)|i", $path, $mat) )
$path = $mat[1];
}
//Set up the base directory (Which unless specified, is the current one)
if( empty( $base ) || '.' == $base ) $base = $this->cwd();
$base = trailingslashit($base);
//Can we see the Current directory as part of the ABSPATH?
$location = strpos($path, $base);
if( false !== $location ) {
$newbase = path_join($base, substr($path, $location + strlen($base)));
if( false !== $this->chdir($newbase) ){ //chdir sometimes returns null under certain circumstances, even when its changed correctly, FALSE will be returned if it doesnt change correctly.
if($echo) printf( __('Changing to %s') . '<br/>', $newbase );
//Check to see if it exists in that folder.
if( $this->exists($newbase . 'wp-settings.php') ){
if($echo) printf( __('Found %s'), $newbase . 'wp-settings.php<br/>' );
return $newbase;
}
}
}
//Ok, Couldnt do a magic location from that particular folder level
//Get a list of the files in the current directory, See if we can locate where we are in the folder stucture.
$files = $this->dirlist($base);
$arrPath = explode('/', $path);
foreach($arrPath as $key){
//Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,
// If its 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:
$folder = path_join($base, $key);
if($echo) printf( __('Changing to %s') . '<br/>', $folder );
$ret = $this->find_base_dir( $path, $folder, $echo, $loop);
if( $ret )
return $ret;
}
}
//Only check this as a last resort, to prevent locating the incorrect install. All above proceeedures will fail quickly if this is the right branch to take.
if(isset( $files[ 'wp-settings.php' ]) ){
if($echo) printf( __('Found %s'), $base . 'wp-settings.php<br/>' );
return $base;
}
if( $loop )
return false;//Prevent tihs function looping again.
//As an extra last resort, Change back to / if the folder wasnt found. This comes into effect when the CWD is /home/user/ but WP is at /var/www/.... mainly dedicated setups.
return $this->find_base_dir($path, '/', $echo, true);
}
function get_base_dir($path = false, $base = '.', $echo = false){
if( defined('FTP_BASE') )
$this->wp_base = FTP_BASE;
if( empty($this->wp_base) )
$this->wp_base = $this->find_base_dir($path, $base, $echo);
return $this->wp_base;
}
function get_contents($file,$type='',$resumepos=0){
function get_contents($file, $type = '', $resumepos = 0 ){
if( empty($type) ){
$extension = substr(strrchr($file, "."), 1);
$type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_ASCII;
@ -160,7 +91,7 @@ class WP_Filesystem_FTPext{
$temp = tmpfile();
if ( ! $temp )
return false;
if( ! @ftp_fget($this->link,$temp,$file,$type,$resumepos) )
if( ! @ftp_fget($this->link, $temp, $file, $type, $resumepos) )
return false;
fseek($temp, 0); //Skip back to the start of the file being written to
$contents = '';
@ -170,202 +101,132 @@ class WP_Filesystem_FTPext{
fclose($temp);
return $contents;
}
function get_contents_array($file){
return explode("\n",$this->get_contents($file));
function get_contents_array($file) {
return explode("\n", $this->get_contents($file));
}
function put_contents($file,$contents,$type=''){
if( empty($type) ){
function put_contents($file, $contents, $type = '' ) {
if( empty($type) ) {
$extension = substr(strrchr($file, "."), 1);
$type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_ASCII;
}
$temp = tmpfile();
if ( ! $temp )
return false;
fwrite($temp,$contents);
fwrite($temp, $contents);
fseek($temp, 0); //Skip back to the start of the file being written to
$ret = @ftp_fput($this->link,$file,$temp,$type);
$ret = @ftp_fput($this->link, $file, $temp, $type);
fclose($temp);
return $ret;
}
function cwd(){
function cwd() {
$cwd = ftp_pwd($this->link);
if( $cwd )
$cwd = trailingslashit($cwd);
return $cwd;
}
function chdir($dir){
function chdir($dir) {
return @ftp_chdir($dir);
}
function chgrp($file,$group,$recursive=false){
function chgrp($file, $group, $recursive = false ) {
return false;
}
function chmod($file,$mode=false,$recursive=false){
function chmod($file, $mode = false, $recursive = false) {
if( ! $mode )
$mode = $this->permission;
if( ! $mode )
return false;
if ( ! $this->exists($file) )
return false;
if ( ! $recursive || ! $this->is_dir($file) ){
if (!function_exists('ftp_chmod'))
if ( ! $recursive || ! $this->is_dir($file) ) {
if ( ! function_exists('ftp_chmod') )
return @ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file));
return @ftp_chmod($this->link,$mode,$file);
return @ftp_chmod($this->link, $mode, $file);
}
//Is a directory, and we want recursive
$filelist = $this->dirlist($file);
foreach($filelist as $filename){
$this->chmod($file.'/'.$filename,$mode,$recursive);
$this->chmod($file . '/' . $filename, $mode, $recursive);
}
return true;
}
function chown($file,$owner,$recursive=false){
function chown($file, $owner, $recursive = false ) {
return false;
}
function owner($file){
function owner($file) {
$dir = $this->dirlist($file);
return $dir[$file]['owner'];
}
function getchmod($file){
function getchmod($file) {
$dir = $this->dirlist($file);
return $dir[$file]['permsn'];
}
function gethchmod($file){
//From the PHP.net page for ...?
$perms = $this->getchmod($file);
if (($perms & 0xC000) == 0xC000) {
// Socket
$info = 's';
} elseif (($perms & 0xA000) == 0xA000) {
// Symbolic Link
$info = 'l';
} elseif (($perms & 0x8000) == 0x8000) {
// Regular
$info = '-';
} elseif (($perms & 0x6000) == 0x6000) {
// Block special
$info = 'b';
} elseif (($perms & 0x4000) == 0x4000) {
// Directory
$info = 'd';
} elseif (($perms & 0x2000) == 0x2000) {
// Character special
$info = 'c';
} elseif (($perms & 0x1000) == 0x1000) {
// FIFO pipe
$info = 'p';
} else {
// Unknown
$info = 'u';
}
// Owner
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ?
(($perms & 0x0800) ? 's' : 'x' ) :
(($perms & 0x0800) ? 'S' : '-'));
// Group
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ?
(($perms & 0x0400) ? 's' : 'x' ) :
(($perms & 0x0400) ? 'S' : '-'));
// World
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ?
(($perms & 0x0200) ? 't' : 'x' ) :
(($perms & 0x0200) ? 'T' : '-'));
return $info;
}
function getnumchmodfromh($mode) {
$realmode = "";
$legal = array("","w","r","x","-");
$attarray = preg_split("//",$mode);
for($i=0;$i<count($attarray);$i++){
if($key = array_search($attarray[$i],$legal)){
$realmode .= $legal[$key];
}
}
$mode = str_pad($realmode,9,'-');
$trans = array('-'=>'0','r'=>'4','w'=>'2','x'=>'1');
$mode = strtr($mode,$trans);
$newmode = '';
$newmode .= $mode[0]+$mode[1]+$mode[2];
$newmode .= $mode[3]+$mode[4]+$mode[5];
$newmode .= $mode[6]+$mode[7]+$mode[8];
return $newmode;
}
function group($file){
function group($file) {
$dir = $this->dirlist($file);
return $dir[$file]['group'];
}
function copy($source,$destination,$overwrite=false){
function copy($source, $destination, $overwrite = false ) {
if( ! $overwrite && $this->exists($destination) )
return false;
$content = $this->get_contents($source);
if( false === $content)
return false;
return $this->put_contents($destination,$content);
return $this->put_contents($destination, $content);
}
function move($source,$destination,$overwrite=false){
return ftp_rename($this->link,$source,$destination);
function move($source, $destination, $overwrite = false) {
return ftp_rename($this->link, $source, $destination);
}
function delete($file,$recursive=false) {
if ( $this->is_file($file) )
return @ftp_delete($this->link,$file);
return @ftp_delete($this->link, $file);
if ( !$recursive )
return @ftp_rmdir($this->link,$file);
return @ftp_rmdir($this->link, $file);
$filelist = $this->dirlist($file);
foreach ((array) $filelist as $filename => $fileinfo) {
$this->delete($file.'/'.$filename,$recursive);
$this->delete($file . '/' . $filename, $recursive);
}
return @ftp_rmdir($this->link,$file);
return @ftp_rmdir($this->link, $file);
}
function exists($file){
$list = ftp_rawlist($this->link,$file,false);
function exists($file) {
$list = ftp_rawlist($this->link, $file, false);
if( ! $list )
return false;
return count($list) == 1 ? true : false;
}
function is_file($file){
function is_file($file) {
return $this->is_dir($file) ? false : true;
}
function is_dir($path){
function is_dir($path) {
$cwd = $this->cwd();
$result = @ftp_chdir($this->link, $path);
if( $result && $path == $this->cwd() ||
$this->cwd() != $cwd ) {
if( $result && $path == $this->cwd() || $this->cwd() != $cwd ) {
@ftp_chdir($this->link, $cwd);
return true;
}
return false;
}
function is_readable($file){
function is_readable($file) {
//Get dir list, Check if the file is writable by the current user??
return true;
}
function is_writable($file){
function is_writable($file) {
//Get dir list, Check if the file is writable by the current user??
return true;
}
function atime($file){
function atime($file) {
return false;
}
function mtime($file){
function mtime($file) {
return ftp_mdtm($this->link, $file);
}
function size($file){
function size($file) {
return ftp_size($this->link, $file);
}
function touch($file,$time=0,$atime=0){
function touch($file, $time = 0, $atime = 0) {
return false;
}
function mkdir($path,$chmod=false,$chown=false,$chgrp=false){
function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
if( !@ftp_mkdir($this->link, $path) )
return false;
if( $chmod )
@ -376,7 +237,7 @@ class WP_Filesystem_FTPext{
$this->chgrp($path, $chgrp);
return true;
}
function rmdir($path,$recursive=false){
function rmdir($path, $recursive = false) {
if( ! $recursive )
return @ftp_rmdir($this->link, $path);
@ -388,9 +249,9 @@ class WP_Filesystem_FTPext{
function parselisting($line) {
$is_windows = ($this->OS_remote == FTP_OS_Windows);
if ($is_windows && preg_match("/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/",$line,$lucifer)) {
if ($is_windows && preg_match("/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/", $line, $lucifer)) {
$b = array();
if ($lucifer[3]<70) { $lucifer[3]+=2000; } else { $lucifer[3]+=1900; } // 4digit year fix
if ($lucifer[3]<70) { $lucifer[3] +=2000; } else { $lucifer[3]+=1900; } // 4digit year fix
$b['isdir'] = ($lucifer[7]=="<DIR>");
if ( $b['isdir'] )
$b['type'] = 'd';
@ -448,15 +309,15 @@ class WP_Filesystem_FTPext{
return $b;
}
function dirlist($path='.',$incdot=false,$recursive=false){
if( $this->is_file($path) ){
function dirlist($path = '.', $incdot = false, $recursive = false) {
if( $this->is_file($path) ) {
$limitFile = basename($path);
$path = dirname($path) . '/';
} else {
$limitFile = false;
}
$list = @ftp_rawlist($this->link , '-a ' . $path, false);
$list = @ftp_rawlist($this->link, '-a ' . $path, false);
if ( $list === false )
return false;
@ -467,10 +328,10 @@ class WP_Filesystem_FTPext{
if ( empty($entry) )
continue;
if ( $entry["name"]=="." or $entry["name"]==".." )
if ( '.' == $entry["name"] || '..' == $entry["name"] )
continue;
$dirlist[$entry['name']] = $entry;
$dirlist[ $entry['name'] ] = $entry;
}
if ( ! $dirlist )
@ -488,11 +349,11 @@ class WP_Filesystem_FTPext{
//We're including the doted starts
if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder
if ($recursive)
$struc['files'] = $this->dirlist($path.'/'.$struc['name'],$incdot,$recursive);
$struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
}
} else { //No dots
if ($recursive)
$struc['files'] = $this->dirlist($path.'/'.$struc['name'],$incdot,$recursive);
$struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
}
}
//File

View File

@ -5,25 +5,25 @@ class WP_Filesystem_ftpsockets{
var $errors;
var $options = array();
var $wp_base = '';
var $permission = null;
var $filetypes = array(
'php'=>FTP_ASCII,
'css'=>FTP_ASCII,
'txt'=>FTP_ASCII,
'js'=>FTP_ASCII,
'html'=>FTP_ASCII,
'htm'=>FTP_ASCII,
'xml'=>FTP_ASCII,
'php' => FTP_ASCII,
'css' => FTP_ASCII,
'txt' => FTP_ASCII,
'js' => FTP_ASCII,
'html'=> FTP_ASCII,
'htm' => FTP_ASCII,
'xml' => FTP_ASCII,
'jpg'=>FTP_BINARY,
'png'=>FTP_BINARY,
'gif'=>FTP_BINARY,
'bmp'=>FTP_BINARY
'jpg' => FTP_BINARY,
'png' => FTP_BINARY,
'gif' => FTP_BINARY,
'bmp' => FTP_BINARY
);
function WP_Filesystem_ftpsockets($opt='') {
$this->method = 'ftpsockets';
$this->errors = new WP_Error();
//Check if possible to use ftp functions.
@ -86,75 +86,6 @@ class WP_Filesystem_ftpsockets{
$this->permission = $perm;
}
function find_base_dir($path = false, $base = '.',$echo = false, $loop = false) {
if (!$path)
$path = ABSPATH;
//Sanitize the Windows path formats, This allows easier conparison and aligns it to FTP output.
$path = str_replace('\\','/',$path); //windows: Straighten up the paths..
if( strpos($path, ':') ){ //Windows, Strip out the driveletter
if( preg_match("|.{1}\:(.+)|i", $path, $mat) )
$path = $mat[1];
}
//Set up the base directory (Which unless specified, is the current one)
if( empty( $base ) || '.' == $base ) $base = $this->cwd();
$base = trailingslashit($base);
//Can we see the Current directory as part of the ABSPATH?
$location = strpos($path, $base);
if( false !== $location ) {
$newbase = path_join($base, substr($path, $location + strlen($base)));
if( false !== $this->chdir($newbase) ){ //chdir sometimes returns null under certain circumstances, even when its changed correctly, FALSE will be returned if it doesnt change correctly.
if($echo) printf( __('Changing to %s') . '<br/>', $newbase );
//Check to see if it exists in that folder.
if( $this->exists($newbase . 'wp-settings.php') ){
if($echo) printf( __('Found %s'), $newbase . 'wp-settings.php<br/>' );
return $newbase;
}
}
}
//Ok, Couldnt do a magic location from that particular folder level
//Get a list of the files in the current directory, See if we can locate where we are in the folder stucture.
$files = $this->dirlist($base);
$arrPath = explode('/', $path);
foreach($arrPath as $key){
//Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,
// If its 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:
$folder = path_join($base, $key);
if($echo) printf( __('Changing to %s') . '<br/>', $folder );
$ret = $this->find_base_dir($path, $folder, $echo, $loop);
if( $ret )
return $ret;
}
}
//Only check this as a last resort, to prevent locating the incorrect install. All above proceeedures will fail quickly if this is the right branch to take.
if(isset( $files[ 'wp-settings.php' ]) ){
if($echo) printf( __('Found %s'), $base . 'wp-settings.php<br/>' );
return $base;
}
if( $loop )
return false;//Prevent tihs function looping again.
//As an extra last resort, Change back to / if the folder wasnt found. This comes into effect when the CWD is /home/user/ but WP is at /var/www/.... mainly dedicated setups.
return $this->find_base_dir($path, '/', $echo, true);
}
function get_base_dir($path = false, $base = '.', $echo = false){
if( defined('FTP_BASE') )
$this->wp_base = FTP_BASE;
if( empty($this->wp_base) )
$this->wp_base = $this->find_base_dir($path, $base, $echo);
return $this->wp_base;
}
function get_contents($file,$type='',$resumepos=0){
if( ! $this->exists($file) )
return false;
@ -331,14 +262,14 @@ class WP_Filesystem_ftpsockets{
if ( false === $content )
return false;
return $this->put_contents($destination,$content);
return $this->put_contents($destination, $content);
}
function move($source,$destination,$overwrite=false){
return $this->ftp->rename($source,$destination);
function move($source, $destination, $overwrite = false ) {
return $this->ftp->rename($source, $destination);
}
function delete($file,$recursive=false) {
function delete($file, $recursive = false ) {
if ( $this->is_file($file) )
return $this->ftp->delete($file);
if ( !$recursive )
@ -347,15 +278,15 @@ class WP_Filesystem_ftpsockets{
return $this->ftp->mdel($file);
}
function exists($file){
function exists($file) {
return $this->ftp->is_exists($file);
}
function is_file($file){
function is_file($file) {
return $this->is_dir($file) ? false : true;
}
function is_dir($path){
function is_dir($path) {
$cwd = $this->cwd();
if ( $this->chdir($path) ) {
$this->chdir($cwd);
@ -364,33 +295,33 @@ class WP_Filesystem_ftpsockets{
return false;
}
function is_readable($file){
function is_readable($file) {
//Get dir list, Check if the file is writable by the current user??
return true;
}
function is_writable($file){
function is_writable($file) {
//Get dir list, Check if the file is writable by the current user??
return true;
}
function atime($file){
function atime($file) {
return false;
}
function mtime($file){
function mtime($file) {
return $this->ftp->mdtm($file);
}
function size($file){
function size($file) {
return $this->ftp->filesize($file);
}
function touch($file,$time=0,$atime=0){
function touch($file, $time = 0, $atime = 0 ){
return false;
}
function mkdir($path,$chmod=false,$chown=false,$chgrp=false){
function mkdir($path, $chmod = false, $chown = false, $chgrp = false ) {
if( ! $this->ftp->mkdir($path) )
return false;
if( $chmod )
@ -402,15 +333,15 @@ class WP_Filesystem_ftpsockets{
return true;
}
function rmdir($path,$recursive=false){
function rmdir($path, $recursive = false ) {
if( ! $recursive )
return $this->ftp->rmdir($path);
return $this->ftp->mdel($path);
}
function dirlist($path='.',$incdot=false,$recursive=false){
if( $this->is_file($path) ){
function dirlist($path = '.', $incdot = false, $recursive = false ) {
if( $this->is_file($path) ) {
$limitFile = basename($path);
$path = dirname($path) . '/';
} else {
@ -433,11 +364,11 @@ class WP_Filesystem_ftpsockets{
//We're including the doted starts
if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder
if ($recursive)
$struc['files'] = $this->dirlist($path.'/'.$struc['name'],$incdot,$recursive);
$struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
}
} else { //No dots
if ($recursive)
$struc['files'] = $this->dirlist($path.'/'.$struc['name'],$incdot,$recursive);
$struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
}
}
//File

View File

@ -34,9 +34,9 @@ function get_home_path() {
function get_real_file_to_edit( $file ) {
if ('index.php' == $file || '.htaccess' == $file ) {
$real_file = get_home_path().$file;
$real_file = get_home_path() . $file;
} else {
$real_file = ABSPATH.$file;
$real_file = ABSPATH . $file;
}
return $real_file;
@ -256,13 +256,13 @@ function unzip_file($file, $to) {
$tmppath .= $path[$j] . '/';
if ( ! $fs->is_dir($to . $tmppath) )
if ( !$fs->mkdir($to . $tmppath, 0755) )
return new WP_Error('mkdir_failed', __('Could not create directory'));
return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $tmppath);
}
// We've made sure the folders are there, so let's extract the file now:
if ( ! $file['folder'] )
if ( !$fs->put_contents( $to . $file['filename'], $file['content']) )
return new WP_Error('copy_failed', __('Could not copy file'));
return new WP_Error('copy_failed', __('Could not copy file'), $to . $file['filename']);
$fs->chmod($to . $file['filename'], 0644);
}
@ -280,22 +280,23 @@ function copy_dir($from, $to) {
foreach ( (array) $dirlist as $filename => $fileinfo ) {
if ( 'f' == $fileinfo['type'] ) {
if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true) )
return false;
return new WP_Error('copy_failed', __('Could not copy file'), $to . $filename);
$wp_filesystem->chmod($to . $filename, 0644);
} elseif ( 'd' == $fileinfo['type'] ) {
if ( !$wp_filesystem->mkdir($to . $filename, 0755) )
return false;
if ( !copy_dir($from . $filename, $to . $filename) )
return false;
return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $filename);
$result = copy_dir($from . $filename, $to . $filename);
if ( is_wp_error($result) )
return $result;
}
}
return true;
}
function WP_Filesystem( $args = false ) {
global $wp_filesystem;
require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
$method = get_filesystem_method();
if ( ! $method )
@ -333,4 +334,4 @@ function get_filesystem_method() {
return apply_filters('filesystem_method', $method);
}
?>
?>

View File

@ -150,7 +150,7 @@ function wp_update_plugin($plugin, $feedback = '') {
return new WP_Error('up_to_date', __('The plugin is at the latest version.'));
// Is a filesystem accessor setup?
if ( ! $wp_filesystem || !is_object($wp_filesystem) )
if ( ! $wp_filesystem || ! is_object($wp_filesystem) )
WP_Filesystem();
if ( ! is_object($wp_filesystem) )
@ -160,10 +160,17 @@ function wp_update_plugin($plugin, $feedback = '') {
return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);
//Get the base plugin folder
$base = $wp_filesystem->get_base_dir(WP_PLUGIN_DIR);
$plugins_dir = $wp_filesystem->wp_plugins_dir();
if ( empty($plugins_dir) )
return new WP_Error('fs_no)plugins_dir', __('Unable to locate WordPress Plugin directory.'));
//And the same for the Content directory.
$content_dir = $wp_filesystem->wp_content_dir();
if( empty($content_dir) )
return new WP_Error('fs_no_content_dor', __('Unable to locate WordPress Content directory (wp-content).'));
if ( empty($base) )
return new WP_Error('fs_nowordpress', __('Unable to locate WordPress directory.'));
$plugins_dir = trailingslashit( $plugins_dir );
$content_dir = trailingslashit( $content_dir );
// Get the URL to the zip file
$r = $current->response[ $plugin ];
@ -174,12 +181,12 @@ function wp_update_plugin($plugin, $feedback = '') {
// Download the package
$package = $r->package;
apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package));
$file = download_url($package);
$download_file = download_url($package);
if ( is_wp_error($file) )
if ( is_wp_error($download_file) )
return new WP_Error('download_failed', __('Download failed.'), $file->get_error_message());
$working_dir = $wp_filesystem->get_base_dir(WP_CONTENT_DIR) . '/upgrade/' . basename($plugin, '.php');
$working_dir = $content_dir . 'upgrade/' . basename($plugin, '.php');
// Clean up working directory
if ( $wp_filesystem->is_dir($working_dir) )
@ -187,16 +194,16 @@ function wp_update_plugin($plugin, $feedback = '') {
apply_filters('update_feedback', __('Unpacking the update'));
// Unzip package to working directory
$result = unzip_file($file, $working_dir);
$result = unzip_file($download_file, $working_dir);
// Once extracted, delete the package
unlink($download_file);
if ( is_wp_error($result) ) {
unlink($file);
$wp_filesystem->delete($working_dir, true);
return $result;
}
// Once extracted, delete the package
unlink($file);
if ( is_plugin_active($plugin) ) {
//Deactivate the plugin silently, Prevent deactivation hooks from running.
apply_filters('update_feedback', __('Deactivating the plugin'));
@ -205,25 +212,25 @@ function wp_update_plugin($plugin, $feedback = '') {
// Remove the existing plugin.
apply_filters('update_feedback', __('Removing the old version of the plugin'));
$plugin_dir = dirname($base . "/$plugin");
$plugin_dir = trailingslashit($plugin_dir);
$this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) );
// If plugin is in its own directory, recursively delete the directory.
if ( strpos($plugin, '/') && $plugin_dir != $base . '/' ) //base check on if plugin includes directory seperator AND that its not the root plugin folder
$deleted = $wp_filesystem->delete($plugin_dir, true);
if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory seperator AND that its not the root plugin folder
$deleted = $wp_filesystem->delete($this_plugin_dir, true);
else
$deleted = $wp_filesystem->delete($base . '/' . $plugin);
$deleted = $wp_filesystem->delete($plugins_dir . $plugin);
if ( !$deleted ) {
if ( ! $deleted ) {
$wp_filesystem->delete($working_dir, true);
return new WP_Error('delete_failed', __('Could not remove the old plugin'));
}
apply_filters('update_feedback', __('Installing the latest version'));
// Copy new version of plugin into place.
if ( !copy_dir($working_dir, $base) ) {
$result = copy_dir($working_dir, $plugins_dir);
if ( is_wp_error($result) ) {
//$wp_filesystem->delete($working_dir, true); //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails.
return new WP_Error('install_failed', __('Installation failed'));
return $result;
}
//Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
@ -236,13 +243,13 @@ function wp_update_plugin($plugin, $feedback = '') {
delete_option('update_plugins');
if( empty($filelist) )
return false; //We couldnt find any files in the working dir
return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup.
$folder = $filelist[0];
$plugin = get_plugins('/' . $folder); //Pass it with a leading slash, search out the plugins in the folder,
$plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash
$pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
return $folder . '/' . $pluginfiles[0]; //Pass it without a leading slash as WP requires
return $folder . '/' . $pluginfiles[0];
}
?>

View File

@ -110,15 +110,16 @@ function do_plugin_upgrade($plugin) {
return;
}
$was_activated = is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is,
$was_activated = is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is
$result = wp_update_plugin($plugin, 'show_message');
if ( is_wp_error($result) ) {
show_message($result);
show_message( __('Installation Failed') );
} else {
//Result is the new plugin file relative to WP_PLUGIN_DIR
show_message(__('Plugin upgraded successfully'));
show_message( __('Plugin upgraded successfully') );
if( $result && $was_activated ){
show_message(__('Attempting reactivation of the plugin'));
echo '<iframe style="border:0" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $result, 'activate-plugin_' . $result) .'"></iframe>';