Plugin updater updates. see #5586

git-svn-id: http://svn.automattic.com/wordpress/trunk@7126 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-03-01 21:20:23 +00:00
parent 88e06106a8
commit c71d96e269
7 changed files with 1418 additions and 660 deletions

View File

@ -0,0 +1,163 @@
<?php
class ftp extends ftp_base {
function ftp($verb=FALSE, $le=FALSE) {
$this->__construct($verb, $le);
}
function __construct($verb=FALSE, $le=FALSE) {
parent::__construct(false, $verb, $le);
}
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Private functions -->
// <!-- --------------------------------------------------------------------------------------- -->
function _settimeout($sock) {
if(!@stream_set_timeout($sock, $this->_timeout)) {
$this->PushError('_settimeout','socket set send timeout');
$this->_quit();
return FALSE;
}
return TRUE;
}
function _connect($host, $port) {
$this->SendMSG("Creating socket");
$sock = @fsockopen($host, $port, $errno, $errstr, $this->_timeout);
if (!$sock) {
$this->PushError('_connect','socket connect failed', $errstr." (".$errno.")");
return FALSE;
}
$this->_connected=true;
return $sock;
}
function _readmsg($fnction="_readmsg"){
if(!$this->_connected) {
$this->PushError($fnction, 'Connect first');
return FALSE;
}
$result=true;
$this->_message="";
$this->_code=0;
$go=true;
do {
$tmp=@fgets($this->_ftp_control_sock, 512);
if($tmp===false) {
$go=$result=false;
$this->PushError($fnction,'Read failed');
} else {
$this->_message.=$tmp;
if(preg_match("/^([0-9]{3})(-(.*[".CRLF."]{1,2})+\\1)? [^".CRLF."]+[".CRLF."]{1,2}$/", $this->_message, $regs)) $go=false;
}
} while($go);
if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF;
$this->_code=(int)$regs[1];
return $result;
}
function _exec($cmd, $fnction="_exec") {
if(!$this->_ready) {
$this->PushError($fnction,'Connect first');
return FALSE;
}
if($this->LocalEcho) echo "PUT > ",$cmd,CRLF;
$status=@fputs($this->_ftp_control_sock, $cmd.CRLF);
if($status===false) {
$this->PushError($fnction,'socket write failed');
return FALSE;
}
$this->_lastaction=time();
if(!$this->_readmsg($fnction)) return FALSE;
return TRUE;
}
function _data_prepare($mode=FTP_ASCII) {
if(!$this->_settype($mode)) return FALSE;
if($this->_passive) {
if(!$this->_exec("PASV", "pasv")) {
$this->_data_close();
return FALSE;
}
if(!$this->_checkCode()) {
$this->_data_close();
return FALSE;
}
$ip_port = explode(",", ereg_replace("^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*".CRLF."$", "\\1", $this->_message));
$this->_datahost=$ip_port[0].".".$ip_port[1].".".$ip_port[2].".".$ip_port[3];
$this->_dataport=(((int)$ip_port[4])<<8) + ((int)$ip_port[5]);
$this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
$this->_ftp_data_sock=@fsockopen($this->_datahost, $this->_dataport, $errno, $errstr, $this->_timeout);
if(!$this->_ftp_data_sock) {
$this->PushError("_data_prepare","fsockopen fails", $errstr." (".$errno.")");
$this->_data_close();
return FALSE;
}
else $this->_ftp_data_sock;
} else {
$this->SendMSG("Only passive connections available!");
return FALSE;
}
return TRUE;
}
function _data_read($mode=FTP_ASCII, $fp=NULL) {
if(is_resource($fp)) $out=0;
else $out="";
if(!$this->_passive) {
$this->SendMSG("Only passive connections available!");
return FALSE;
}
while (!feof($this->_ftp_data_sock)) {
$block=fread($this->_ftp_data_sock, $this->_ftp_buff_size);
if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_local], $block);
if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block));
else $out.=$block;
}
return $out;
}
function _data_write($mode=FTP_ASCII, $fp=NULL) {
if(is_resource($fp)) $out=0;
else $out="";
if(!$this->_passive) {
$this->SendMSG("Only passive connections available!");
return FALSE;
}
if(is_resource($fp)) {
while(!feof($fp)) {
$block=fread($fp, $this->_ftp_buff_size);
if(!$this->_data_write_block($mode, $block)) return false;
}
} elseif(!$this->_data_write_block($mode, $fp)) return false;
return TRUE;
}
function _data_write_block($mode, $block) {
if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_remote], $block);
do {
if(($t=@fwrite($this->_ftp_data_sock, $block))===FALSE) {
$this->PushError("_data_write","Can't write to socket");
return FALSE;
}
$block=substr($block, $t);
} while(!empty($block));
return true;
}
function _data_close() {
@fclose($this->_ftp_data_sock);
$this->SendMSG("Disconnected data from remote host");
return TRUE;
}
function _quit($force=FALSE) {
if($this->_connected or $force) {
@fclose($this->_ftp_control_sock);
$this->_connected=false;
$this->SendMSG("Socket closed");
}
}
}
?>

View File

@ -0,0 +1,224 @@
<?php
class ftp extends ftp_base {
function ftp($verb=FALSE, $le=FALSE) {
$this->__construct($verb, $le);
}
function __construct($verb=FALSE, $le=FALSE) {
parent::__construct(true, $verb, $le);
}
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Private functions -->
// <!-- --------------------------------------------------------------------------------------- -->
function _settimeout($sock) {
if(!@socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array("sec"=>$this->_timeout, "usec"=>0))) {
$this->PushError('_connect','socket set receive timeout',socket_strerror(socket_last_error($sock)));
@socket_close($sock);
return FALSE;
}
if(!@socket_set_option($sock, SOL_SOCKET , SO_SNDTIMEO, array("sec"=>$this->_timeout, "usec"=>0))) {
$this->PushError('_connect','socket set send timeout',socket_strerror(socket_last_error($sock)));
@socket_close($sock);
return FALSE;
}
return true;
}
function _connect($host, $port) {
$this->SendMSG("Creating socket");
if(!($sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) {
$this->PushError('_connect','socket create failed',socket_strerror(socket_last_error($sock)));
return FALSE;
}
if(!$this->_settimeout($sock)) return FALSE;
$this->SendMSG("Connecting to \"".$host.":".$port."\"");
if (!($res = @socket_connect($sock, $host, $port))) {
$this->PushError('_connect','socket connect failed',socket_strerror(socket_last_error($sock)));
@socket_close($sock);
return FALSE;
}
$this->_connected=true;
return $sock;
}
function _readmsg($fnction="_readmsg"){
if(!$this->_connected) {
$this->PushError($fnction,'Connect first');
return FALSE;
}
$result=true;
$this->_message="";
$this->_code=0;
$go=true;
do {
$tmp=@socket_read($this->_ftp_control_sock, 4096, PHP_BINARY_READ);
if($tmp===false) {
$go=$result=false;
$this->PushError($fnction,'Read failed', socket_strerror(socket_last_error($this->_ftp_control_sock)));
} else {
$this->_message.=$tmp;
$go = !preg_match("/^([0-9]{3})(-.+\\1)? [^".CRLF."]+".CRLF."$/Us", $this->_message, $regs);
}
} while($go);
if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF;
$this->_code=(int)$regs[1];
return $result;
}
function _exec($cmd, $fnction="_exec") {
if(!$this->_ready) {
$this->PushError($fnction,'Connect first');
return FALSE;
}
if($this->LocalEcho) echo "PUT > ",$cmd,CRLF;
$status=@socket_write($this->_ftp_control_sock, $cmd.CRLF);
if($status===false) {
$this->PushError($fnction,'socket write failed', socket_strerror(socket_last_error($this->stream)));
return FALSE;
}
$this->_lastaction=time();
if(!$this->_readmsg($fnction)) return FALSE;
return TRUE;
}
function _data_prepare($mode=FTP_ASCII) {
if(!$this->_settype($mode)) return FALSE;
$this->SendMSG("Creating data socket");
$this->_ftp_data_sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($this->_ftp_data_sock < 0) {
$this->PushError('_data_prepare','socket create failed',socket_strerror(socket_last_error($this->_ftp_data_sock)));
return FALSE;
}
if(!$this->_settimeout($this->_ftp_data_sock)) {
$this->_data_close();
return FALSE;
}
if($this->_passive) {
if(!$this->_exec("PASV", "pasv")) {
$this->_data_close();
return FALSE;
}
if(!$this->_checkCode()) {
$this->_data_close();
return FALSE;
}
$ip_port = explode(",", ereg_replace("^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*".CRLF."$", "\\1", $this->_message));
$this->_datahost=$ip_port[0].".".$ip_port[1].".".$ip_port[2].".".$ip_port[3];
$this->_dataport=(((int)$ip_port[4])<<8) + ((int)$ip_port[5]);
$this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
if(!@socket_connect($this->_ftp_data_sock, $this->_datahost, $this->_dataport)) {
$this->PushError("_data_prepare","socket_connect", socket_strerror(socket_last_error($this->_ftp_data_sock)));
$this->_data_close();
return FALSE;
}
else $this->_ftp_temp_sock=$this->_ftp_data_sock;
} else {
if(!@socket_getsockname($this->_ftp_control_sock, $addr, $port)) {
$this->PushError("_data_prepare","can't get control socket information", socket_strerror(socket_last_error($this->_ftp_control_sock)));
$this->_data_close();
return FALSE;
}
if(!@socket_bind($this->_ftp_data_sock,$addr)){
$this->PushError("_data_prepare","can't bind data socket", socket_strerror(socket_last_error($this->_ftp_data_sock)));
$this->_data_close();
return FALSE;
}
if(!@socket_listen($this->_ftp_data_sock)) {
$this->PushError("_data_prepare","can't listen data socket", socket_strerror(socket_last_error($this->_ftp_data_sock)));
$this->_data_close();
return FALSE;
}
if(!@socket_getsockname($this->_ftp_data_sock, $this->_datahost, $this->_dataport)) {
$this->PushError("_data_prepare","can't get data socket information", socket_strerror(socket_last_error($this->_ftp_data_sock)));
$this->_data_close();
return FALSE;
}
if(!$this->_exec('PORT '.str_replace('.',',',$this->_datahost.'.'.($this->_dataport>>8).'.'.($this->_dataport&0x00FF)), "_port")) {
$this->_data_close();
return FALSE;
}
if(!$this->_checkCode()) {
$this->_data_close();
return FALSE;
}
}
return TRUE;
}
function _data_read($mode=FTP_ASCII, $fp=NULL) {
$NewLine=$this->_eol_code[$this->OS_local];
if(is_resource($fp)) $out=0;
else $out="";
if(!$this->_passive) {
$this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
$this->_ftp_temp_sock=socket_accept($this->_ftp_data_sock);
if($this->_ftp_temp_sock===FALSE) {
$this->PushError("_data_read","socket_accept", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
$this->_data_close();
return FALSE;
}
}
while(($block=@socket_read($this->_ftp_temp_sock, $this->_ftp_buff_size, PHP_BINARY_READ))!==false) {
if($block==="") break;
if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_local], $block);
if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block));
else $out.=$block;
}
return $out;
}
function _data_write($mode=FTP_ASCII, $fp=NULL) {
$NewLine=$this->_eol_code[$this->OS_local];
if(is_resource($fp)) $out=0;
else $out="";
if(!$this->_passive) {
$this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
$this->_ftp_temp_sock=socket_accept($this->_ftp_data_sock);
if($this->_ftp_temp_sock===FALSE) {
$this->PushError("_data_write","socket_accept", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
$this->_data_close();
return false;
}
}
if(is_resource($fp)) {
while(!feof($fp)) {
$block=fread($fp, $this->_ftp_buff_size);
if(!$this->_data_write_block($mode, $block)) return false;
}
} elseif(!$this->_data_write_block($mode, $fp)) return false;
return true;
}
function _data_write_block($mode, $block) {
if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_remote], $block);
do {
if(($t=@socket_write($this->_ftp_temp_sock, $block))===FALSE) {
$this->PushError("_data_write","socket_write", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
$this->_data_close();
return FALSE;
}
$block=substr($block, $t);
} while(!empty($block));
return true;
}
function _data_close() {
@socket_close($this->_ftp_temp_sock);
@socket_close($this->_ftp_data_sock);
$this->SendMSG("Disconnected data from remote host");
return TRUE;
}
function _quit() {
if($this->_connected) {
@socket_close($this->_ftp_control_sock);
$this->_connected=false;
$this->SendMSG("Socket closed");
}
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -166,9 +166,9 @@ class WP_Filesystem_FTPext{
$mode = $this->permission;
if( ! $mode )
return false;
if( ! $this->exists($file) )
if ( ! $this->exists($file) )
return false;
if( ! $recursive || ! $this->is_dir($file) ){
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);
@ -267,8 +267,9 @@ class WP_Filesystem_FTPext{
function copy($source,$destination,$overwrite=false){
if( ! $overwrite && $this->exists($destination) )
return false;
$content = $this->get_contents($source);
$this->put_contents($destination,$content);
if ( !$content = $this->get_contents($source) )
return false;
return $this->put_contents($destination,$content);
}
function move($source,$destination,$overwrite=false){
return ftp_rename($this->link,$source,$destination);
@ -280,7 +281,7 @@ class WP_Filesystem_FTPext{
if ( !$recursive )
return @ftp_rmdir($this->link,$file);
$filelist = $this->dirlist($file);
foreach ($filelist as $filename => $fileinfo) {
foreach ((array) $filelist as $filename => $fileinfo) {
$this->delete($file.'/'.$filename,$recursive);
}
return @ftp_rmdir($this->link,$file);
@ -327,11 +328,11 @@ class WP_Filesystem_FTPext{
if( !ftp_mkdir($this->link, $path) )
return false;
if( $chmod )
$this->chmod($chmod);
$this->chmod($path, $chmod);
if( $chown )
$this->chown($chown);
$this->chown($path, $chown);
if( $chgrp )
$this->chgrp($chgrp);
$this->chgrp($path, $chgrp);
return true;
}
function rmdir($path,$recursive=false){
@ -343,6 +344,69 @@ class WP_Filesystem_FTPext{
//foreach($dir as $file)
}
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)) {
$b = array();
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';
else
$b['type'] = 'f';
$b['size'] = $lucifer[7];
$b['month'] = $lucifer[1];
$b['day'] = $lucifer[2];
$b['year'] = $lucifer[3];
$b['hour'] = $lucifer[4];
$b['minute'] = $lucifer[5];
$b['time'] = @mktime($lucifer[4]+(strcasecmp($lucifer[6],"PM")==0?12:0),$lucifer[5],0,$lucifer[1],$lucifer[2],$lucifer[3]);
$b['am/pm'] = $lucifer[6];
$b['name'] = $lucifer[8];
} else if (!$is_windows && $lucifer=preg_split("/[ ]/",$line,9,PREG_SPLIT_NO_EMPTY)) {
//echo $line."\n";
$lcount=count($lucifer);
if ($lcount<8) return '';
$b = array();
$b['isdir'] = $lucifer[0]{0} === "d";
$b['islink'] = $lucifer[0]{0} === "l";
if ( $b['isdir'] )
$b['type'] = 'd';
elseif ( $b['islink'] )
$b['type'] = 'l';
else
$b['type'] = 'f';
$b['perms'] = $lucifer[0];
$b['number'] = $lucifer[1];
$b['owner'] = $lucifer[2];
$b['group'] = $lucifer[3];
$b['size'] = $lucifer[4];
if ($lcount==8) {
sscanf($lucifer[5],"%d-%d-%d",$b['year'],$b['month'],$b['day']);
sscanf($lucifer[6],"%d:%d",$b['hour'],$b['minute']);
$b['time'] = @mktime($b['hour'],$b['minute'],0,$b['month'],$b['day'],$b['year']);
$b['name'] = $lucifer[7];
} else {
$b['month'] = $lucifer[5];
$b['day'] = $lucifer[6];
if (preg_match("/([0-9]{2}):([0-9]{2})/",$lucifer[7],$l2)) {
$b['year'] = date("Y");
$b['hour'] = $l2[1];
$b['minute'] = $l2[2];
} else {
$b['year'] = $lucifer[7];
$b['hour'] = 0;
$b['minute'] = 0;
}
$b['time'] = strtotime(sprintf("%d %s %d %02d:%02d",$b['day'],$b['month'],$b['year'],$b['hour'],$b['minute']));
$b['name'] = $lucifer[8];
}
}
return $b;
}
function dirlist($path='.',$incdot=false,$recursive=false){
if( $this->is_file($path) ){
$limitFile = basename($path);
@ -352,40 +416,34 @@ class WP_Filesystem_FTPext{
}
//if( ! $this->is_dir($path) )
// return false;
$list = ftp_rawlist($this->link,$path,false); //We'll do the recursive part ourseves...
//var_dump($list);
if( ! $list )
$list = ftp_rawlist($this->link , '-a ' . $path, false);
if ( $list === false )
return false;
if( empty($list) )
$dirlist = array();
foreach ( $list as $k => $v ) {
$entry = $this->parselisting($v);
if ( empty($entry) )
continue;
if ( $entry["name"]=="." or $entry["name"]==".." )
continue;
$dirlist[$entry['name']] = $entry;
}
if ( ! $dirlist )
return false;
if ( empty($dirlist) )
return array();
$ret = array();
foreach($list as $line){
if (substr(strtolower($line), 0, 5) == 'total') continue;
$struc = array();
$current = preg_split("/[\s]+/",$line,9);
$name_num = count($current) - 1;
$struc['name'] = str_replace('//','',$current[$name_num]);
foreach ( $dirlist as $struc ) {
if( '.' == $struc['name'][0] && !$incdot)
continue;
if( $limitFile && $struc['name'] != $limitFile)
continue;
$struc['perms'] = $current[0];
$struc['permsn'] = $this->getnumchmodfromh($current[0]);
$struc['number'] = $current[1];
$struc['owner'] = $current[2];
$struc['group'] = $current[3];
$struc['size'] = $current[4];
$struc['lastmod'] = $current[5].' '.$current[6];
$struc['time'] = $current[7];
$struc['type'] = ('d' == $struc['perms'][0] || 'l' == $struc['perms'][0] ) ? 'folder' : 'file';
if('folder' == $struc['type'] ){
if ( 'd' == $struc['type'] ) {
$struc['files'] = array();
if( $incdot ){
if ( $incdot ){
//We're including the doted starts
if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder
if ($recursive)
@ -401,6 +459,7 @@ class WP_Filesystem_FTPext{
}
return $ret;
}
function __destruct(){
if( $this->link )
ftp_close($this->link);

View File

@ -29,7 +29,7 @@ class WP_Filesystem_ftpsockets{
//Check if possible to use ftp functions.
if( ! @include_once ABSPATH . 'wp-admin/includes/class-ftp.php' )
return false;
$this->ftp = new FTP();
$this->ftp = new ftp();
//Set defaults:
if ( empty($opt['port']) )
@ -61,7 +61,13 @@ class WP_Filesystem_ftpsockets{
if ( ! $this->ftp )
return false;
if ( ! $this->ftp->connect($this->options['hostname'], $this->options['port'], $this->timeout) ) {
//$this->ftp->Verbose = true;
if ( ! $this->ftp->SetServer($this->options['hostname'], $this->options['port']) ) {
$this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
return false;
}
if ( ! $this->ftp->connect() ) {
$this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
return false;
}
@ -71,6 +77,8 @@ class WP_Filesystem_ftpsockets{
return false;
}
$this->ftp->SetType(FTP_AUTOASCII);
$this->ftp->Passive(true);
return true;
}
@ -113,26 +121,39 @@ class WP_Filesystem_ftpsockets{
//If we get this far, somethings gone wrong, change to / and restart the process.
return $this->find_base_dir('/',$echo);
}
function get_base_dir($base = '.'){
if( empty($this->wp_base) )
$this->wp_base = $this->find_base_dir($base);
return $this->wp_base;
}
function get_contents($file,$type='',$resumepos=0){
if( empty($type) ){
$extension = substr(strrchr($filename, "."), 1);
$type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_AUTOASCII;
}
$this->ftp->SetType($type);
return $this->ftp->get($file);
$temp = tmpfile();
if ( ! $this->ftp->fget($temp, $file) ) {
fclose($temp);
return false;
}
fseek($temp, 0); //Skip back to the start of the file being written to
$contents = '';
while ( !feof($temp) )
$contents .= fread($temp, 8192);
fclose($temp);
return $contents;
}
function get_contents_array($file){
return explode("\n",$this->get_contents($file));
}
function put_contents($file,$contents,$type=''){
if( empty($type) ){
$extension = substr(strrchr($filename, "."), 1);
$extension = substr(strrchr($file, "."), 1);
$type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_ASCII;
}
$this->ftp->SetType($type);
@ -140,16 +161,19 @@ class WP_Filesystem_ftpsockets{
$temp = tmpfile();
fwrite($temp,$contents);
fseek($temp, 0); //Skip back to the start of the file being written to
$ret = $this->ftp->put($temp, $file);
$ret = $this->ftp->fput($file, $temp);
fclose($temp);
return $ret;
}
function cwd(){
return $this->ftp->pwd();
}
function chgrp($file,$group,$recursive=false){
return false;
}
function chmod($file,$mode=false,$recursive=false){
if( ! $mode )
$mode = $this->permission;
@ -167,17 +191,21 @@ class WP_Filesystem_ftpsockets{
}
return true;
}
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 gethchmod($file){
//From the PHP.net page for ...?
$perms = $this->getchmod($file);
@ -229,6 +257,7 @@ class WP_Filesystem_ftpsockets{
(($perms & 0x0200) ? 'T' : '-'));
return $info;
}
function getnumchmodfromh($mode) {
$realmode = "";
$legal = array("","w","r","x","-");
@ -247,16 +276,23 @@ class WP_Filesystem_ftpsockets{
$newmode .= $mode[6]+$mode[7]+$mode[8];
return $newmode;
}
function group($file){
$dir = $this->dirlist($file);
return $dir[$file]['group'];
}
function copy($source,$destination,$overwrite=false){
if( ! $overwrite && $this->exists($destination) )
return false;
$content = $this->get_contents($source);
$this->put_contents($destination,$content);
if ( !$content )
return false;
return $this->put_contents($destination,$content);
}
function move($source,$destination,$overwrite=false){
return $this->ftp->rename($source,$destination);
}
@ -266,69 +302,72 @@ class WP_Filesystem_ftpsockets{
return $this->ftp->delete($file);
if ( !$recursive )
return $this->ftp->rmdir($file);
$filelist = $this->dirlist($file);
foreach ($filelist as $filename) {
$this->delete($file.'/'.$filename,$recursive);
}
return $this->ftp->rmdir($file);
return $this->ftp->mdel($file);
}
function exists($file){
return $this->ftp->is_exists($file);
}
function is_file($file){
//return $this->ftp->file_exists($file);
$list = $this->ftp->rawlist($file,'-a');
if( ! $list )
return false;
return ($list[0] == '-');
return $this->is_dir($file) ? false : true;
}
function is_dir($path){
$list = $this->ftp->rawlist($file,'-a');
if( ! $list )
return false;
$cwd = $this->cwd();
if ( $this->ftp->chdir($path) ) {
$this->ftp->chdir($cwd);
return true;
}
return false;
}
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;
}
function atime($file){
return false;
}
function mtime($file){
return $this->ftp->mdtm($file);
}
function size($file){
return $this->ftp->filesize($file);
}
function touch($file,$time=0,$atime=0){
return false;
}
function mkdir($path,$chmod=false,$chown=false,$chgrp=false){
if( ! $this->ftp->mkdir($path) )
return false;
if( $chmod )
$this->chmod($chmod);
$this->chmod($path, $chmod);
if( $chown )
$this->chown($chown);
$this->chown($path, $chown);
if( $chgrp )
$this->chgrp($chgrp);
$this->chgrp($path, $chgrp);
return true;
}
function rmdir($path,$recursive=false){
if( ! $recursive )
return $this->ftp->rmdir($file);
return false;
//TODO: Recursive Directory delete, Have to delete files from the folder first.
//$dir = $this->dirlist($path);
//foreach($dir as $file)
return $this->ftp->mdel($path);
}
function dirlist($path='.',$incdot=false,$recursive=false){
if( $this->is_file($path) ){
$limitFile = basename($path);
@ -338,38 +377,19 @@ class WP_Filesystem_ftpsockets{
}
//if( ! $this->is_dir($path) )
// return false;
$list = $this->ftp->rawlist($path,'-a');
//var_dump($list);
$list = $this->ftp->dirlist($path);
if( ! $list )
return false;
if( empty($list) )
return array();
$ret = array();
foreach($list as $line){
$struc = array();
$current = preg_split("/[\s]+/",$line,9);
$struc['name'] = str_replace('//','',$current[8]);
foreach ( $list as $struc ) {
if( '.' == $struc['name'][0] && !$incdot)
continue;
if( $limitFile && $struc['name'] != $limitFile)
continue;
$struc['perms'] = $current[0];
$struc['permsn'] = $this->getnumchmodfromh($current[0]);
$struc['number'] = $current[1];
$struc['owner'] = $current[2];
$struc['group'] = $current[3];
$struc['size'] = $current[4];
$struc['lastmod'] = $current[5].' '.$current[6];
$struc['time'] = $current[7];
$struc['type'] = ('d' == $struc['perms'][0] || 'l' == $struc['perms'][0] ) ? 'folder' : 'file';
if('folder' == $struc['type'] ){
if ( 'd' == $struc['type'] ) {
$struc['files'] = array();
if( $incdot ){
if ( $incdot ){
//We're including the doted starts
if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder
if ($recursive)
@ -385,6 +405,7 @@ class WP_Filesystem_ftpsockets{
}
return $ret;
}
function __destruct(){
$this->ftp->quit();
}

View File

@ -237,11 +237,11 @@ function unzip_file($file, $to) {
$path = explode('/', $to);
$tmppath = '';
for ( $j = 0; $j < count($path) - 1; $j++ ) {
$prevpath = $tmppath;
$tmppath .= $path[$j] . '/';
if ( ! $fs->is_dir($tmppath) ) {
$fs->mkdir($tmppath);
} else {
$fs->setDefaultPermissions( $fs->getchmod($tmppath) );
//$fs->setDefaultPermissions( $fs->getchmod($tmppath) );
$fs->mkdir($tmppath, 0755);
}
}
@ -253,13 +253,18 @@ function unzip_file($file, $to) {
for ( $j = 0; $j < count($path) - 1; $j++ ) {
$tmppath .= $path[$j] . '/';
if ( ! $fs->is_dir($to . $tmppath) )
$fs->mkdir($to . $tmppath);
if ( !$fs->mkdir($to . $tmppath, 0755) )
return new WP_Error('mkdir_failed', __('Could not create directory'));
}
// We've made sure the folders are there, so let's extract the file now:
if ( ! $file['folder'] )
$fs->put_contents( $to . $file['filename'], $file['content']);
if ( !$fs->put_contents( $to . $file['filename'], $file['content']) )
return new WP_Error('copy_failed', __('Could not copy file'));
$fs->chmod($to . $file['filename'], 0644);
}
return true;
}
function copy_dir($from, $to) {
@ -271,13 +276,19 @@ function copy_dir($from, $to) {
$to = trailingslashit($to);
foreach ( (array) $dirlist as $filename => $fileinfo ) {
if ( 'file' == $fileinfo['type'] ) {
$wp_filesystem->copy($from . $filename, $to . $filename, true);
} elseif ( 'folder' == $fileinfo['type'] ) {
$wp_filesystem->mkdir($to . $filename);
copy_dir($from . $filename, $to . $filename);
if ( 'f' == $fileinfo['type'] ) {
if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true) )
return false;
$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 true;
}
function WP_Filesystem( $args = false, $preference = false ) {
@ -302,11 +313,13 @@ function WP_Filesystem( $args = false, $preference = false ) {
}
function get_filesystem_method() {
return 'ftpsockets';
$tempFile = tempnam(get_temp_dir(), 'WPU');
if ( getmyuid() == fileowner($tempFile) ) {
unlink($tempFile);
//return 'direct';
return 'direct';
} else {
unlink($tempFile);
}

View File

@ -158,6 +158,7 @@ function wp_update_plugin($plugin, $feedback = '') {
$working_dir = ABSPATH . 'wp-content/upgrade/' . $name;
// Clean up working directory
if ( is_dir($working_dir) )
$wp_filesystem->delete($working_dir, true);
apply_filters('update_feedback', __("Unpacking the update"));
@ -174,16 +175,23 @@ function wp_update_plugin($plugin, $feedback = '') {
// Remove the existing plugin.
apply_filters('update_feedback', __("Removing the old version of the plugin"));
$wp_filesystem->delete(ABSPATH . PLUGINDIR . "/$plugin");
$plugin_dir = dirname(ABSPATH . PLUGINDIR . "/$plugin");
// If plugin is in its own directory, recursively delete the directory.
if ( '.' != $plugin_dir && ABSPATH . PLUGINDIR != $plugin_dir )
$wp_filesystem->delete($plugin_dir, true);
$deleted = $wp_filesystem->delete($plugin_dir, true);
else
$deleted = $wp_filesystem->delete(ABSPATH . PLUGINDIR . "/$plugin");
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.
copy_dir($working_dir, ABSPATH . PLUGINDIR);
if ( !copy_dir($working_dir, ABSPATH . PLUGINDIR) ) {
//$wp_filesystem->delete($working_dir, true);
return new WP_Error('install_failed', __('Installation failed'));
}
// Remove working directory
$wp_filesystem->delete($working_dir, true);