Make WordPress Core

Changeset 8009


Ignore:
Timestamp:
05/29/2008 05:29:32 PM (18 years ago)
Author:
ryan
Message:

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

Location:
trunk/wp-admin
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-filesystem-direct.php

    r7999 r8009  
    11<?php
    22
    3 class WP_Filesystem_Direct{
     3class WP_Filesystem_Direct  extends WP_Filesystem_Base {
    44        var $permission = null;
    55        var $errors = array();
    6         function WP_Filesystem_Direct($arg){
     6        function WP_Filesystem_Direct($arg) {
    77                $this->errors = new WP_Error();
    88                $this->permission = umask();
    99        }
    10         function connect(){
    11                 return true;
    12         }
    13         function setDefaultPermissions($perm){
     10        function connect() {
     11                return true;
     12        }
     13        function setDefaultPermissions($perm) {
    1414                $this->permission = $perm;
    1515        }
    16         function find_base_dir($path = false, $base = '.', $echo = false){
    17                 if (!$path)
    18                         $path = ABSPATH;
    19                 return str_replace('\\','/',$path);
    20         }
    21         function get_base_dir($path = false, $base = '.', $echo = false){
    22                 return $this->find_base_dir($base, $echo);
    23         }
    24         function get_contents($file){
     16        function get_contents($file) {
    2517                return @file_get_contents($file);
    2618        }
    27         function get_contents_array($file){
     19        function get_contents_array($file) {
    2820                return @file($file);
    2921        }
    30         function put_contents($file,$contents,$mode=false,$type=''){
    31                 if ( ! ($fp = @fopen($file,'w'.$type)) )
     22        function put_contents($file,$contents,$mode=false,$type='') {
     23                if ( ! ($fp = @fopen($file,'w' . $type)) )
    3224                        return false;
    3325                @fwrite($fp,$contents);
    … …  
    3628                return true;
    3729        }
    38         function cwd(){
     30        function cwd() {
    3931                return @getcwd();
    4032        }
    41         function chdir($dir){
     33        function chdir($dir) {
    4234                return @chdir($dir);
    4335        }
    44         function chgrp($file,$group,$recursive=false){
     36        function chgrp($file,$group,$recursive=false) {
    4537                if( ! $this->exists($file) )
    4638                        return false;
    4739                if( ! $recursive )
    48                         return @chgrp($file,$group);
     40                        return @chgrp($file, $group);
    4941                if( ! $this->is_dir($file) )
    50                         return @chgrp($file,$group);
     42                        return @chgrp($file, $group);
    5143                //Is a directory, and we want recursive
    5244                $file = trailingslashit($file);
    … …  
    5749                return true;
    5850        }
    59         function chmod($file,$mode=false,$recursive=false){
     51        function chmod($file,$mode=false,$recursive=false) {
    6052                if( ! $mode )
    6153                        $mode = $this->permission;
    … …  
    6557                        return @chmod($file,$mode);
    6658                if( ! $this->is_dir($file) )
    67                         return @chmod($file,$mode);
     59                        return @chmod($file, $mode);
    6860                //Is a directory, and we want recursive
    6961                $file = trailingslashit($file);
    … …  
    7466                return true;
    7567        }
    76         function chown($file,$owner,$recursive=false){
     68        function chown($file, $owner, $recursive = false) {
    7769                if( ! $this->exists($file) )
    7870                        return false;
    7971                if( ! $recursive )
    80                         return @chown($file,$owner);
     72                        return @chown($file, $owner);
    8173                if( ! $this->is_dir($file) )
    82                         return @chown($file,$owner);
     74                        return @chown($file, $owner);
    8375                //Is a directory, and we want recursive
    8476                $filelist = $this->dirlist($file);
    8577                foreach($filelist as $filename){
    86                         $this->chown($file.'/'.$filename,$owner,$recursive);
    87                 }
    88                 return true;
    89         }
    90         function owner($file){
     78                        $this->chown($file . '/' . $filename, $owner, $recursive);
     79                }
     80                return true;
     81        }
     82        function owner($file) {
    9183                $owneruid = @fileowner($file);
    9284                if( ! $owneruid )
    9385                        return false;
    94                 if( !function_exists('posix_getpwuid') )
     86                if( ! function_exists('posix_getpwuid') )
    9587                        return $owneruid;
    9688                $ownerarray = posix_getpwuid($owneruid);
    9789                return $ownerarray['name'];
    9890        }
    99         function getchmod($file){
     91        function getchmod($file) {
    10092                return @fileperms($file);
    10193        }
    102         function gethchmod($file){
    103                 //From the PHP.net page for ...?
    104                 $perms = $this->getchmod($file);
    105                 if (($perms & 0xC000) == 0xC000) {
    106                         // Socket
    107                         $info = 's';
    108                 } elseif (($perms & 0xA000) == 0xA000) {
    109                         // Symbolic Link
    110                         $info = 'l';
    111                 } elseif (($perms & 0x8000) == 0x8000) {
    112                         // Regular
    113                         $info = '-';
    114                 } elseif (($perms & 0x6000) == 0x6000) {
    115                         // Block special
    116                         $info = 'b';
    117                 } elseif (($perms & 0x4000) == 0x4000) {
    118                         // Directory
    119                         $info = 'd';
    120                 } elseif (($perms & 0x2000) == 0x2000) {
    121                         // Character special
    122                         $info = 'c';
    123                 } elseif (($perms & 0x1000) == 0x1000) {
    124                         // FIFO pipe
    125                         $info = 'p';
    126                 } else {
    127                         // Unknown
    128                         $info = 'u';
    129                 }
    130 
    131                 // Owner
    132                 $info .= (($perms & 0x0100) ? 'r' : '-');
    133                 $info .= (($perms & 0x0080) ? 'w' : '-');
    134                 $info .= (($perms & 0x0040) ?
    135                                         (($perms & 0x0800) ? 's' : 'x' ) :
    136                                         (($perms & 0x0800) ? 'S' : '-'));
    137 
    138                 // Group
    139                 $info .= (($perms & 0x0020) ? 'r' : '-');
    140                 $info .= (($perms & 0x0010) ? 'w' : '-');
    141                 $info .= (($perms & 0x0008) ?
    142                                         (($perms & 0x0400) ? 's' : 'x' ) :
    143                                         (($perms & 0x0400) ? 'S' : '-'));
    144 
    145                 // World
    146                 $info .= (($perms & 0x0004) ? 'r' : '-');
    147                 $info .= (($perms & 0x0002) ? 'w' : '-');
    148                 $info .= (($perms & 0x0001) ?
    149                                         (($perms & 0x0200) ? 't' : 'x' ) :
    150                                         (($perms & 0x0200) ? 'T' : '-'));
    151                 return $info;
    152         }
    153         function getnumchmodfromh($mode) {
    154                 $realmode = "";
    155                 $legal =  array("","w","r","x","-");
    156                 $attarray = preg_split("//",$mode);
    157                 for($i=0;$i<count($attarray);$i++){
    158                    if($key = array_search($attarray[$i],$legal)){
    159                            $realmode .= $legal[$key];
    160                    }
    161                 }
    162                 $mode = str_pad($realmode,9,'-');
    163                 $trans = array('-'=>'0','r'=>'4','w'=>'2','x'=>'1');
    164                 $mode = strtr($mode,$trans);
    165                 $newmode = '';
    166                 $newmode .= $mode[0]+$mode[1]+$mode[2];
    167                 $newmode .= $mode[3]+$mode[4]+$mode[5];
    168                 $newmode .= $mode[6]+$mode[7]+$mode[8];
    169                 return $newmode;
    170         }
    171         function group($file){
     94        function group($file) {
    17295                $gid = @filegroup($file);
    17396                if( ! $gid )
    17497                        return false;
    175                 if( !function_exists('posix_getgrgid') )
     98                if( ! function_exists('posix_getgrgid') )
    17699                        return $gid;
    177100                $grouparray = posix_getgrgid($gid);
    … …  
    179102        }
    180103
    181         function copy($source,$destination,$overwrite=false){
     104        function copy($source, $destination, $overwrite = false) {
    182105                if( ! $overwrite && $this->exists($destination) )
    183106                        return false;
    184                 return copy($source,$destination);
    185         }
    186 
    187         function move($source,$destination,$overwrite=false){
     107                return copy($source, $destination);
     108        }
     109
     110        function move($source, $destination, $overwrite = false) {
    188111                //Possible to use rename()?
    189                 if( $this->copy($source,$destination,$overwrite) && $this->exists($destination) ){
     112                if( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ){
    190113                        $this->delete($source);
    191114                        return true;
    … …  
    195118        }
    196119
    197         function delete($file, $recursive=false){
    198                 $file = str_replace('\\','/',$file); //for win32, occasional problems deleteing files otherwise
     120        function delete($file, $recursive = false) {
     121                $file = str_replace('\\', '/', $file); //for win32, occasional problems deleteing files otherwise
    199122
    200123                if( $this->is_file($file) )
    201124                        return @unlink($file);
    202                 if( !$recursive && $this->is_dir($file) )
     125                if( ! $recursive && $this->is_dir($file) )
    203126                        return @rmdir($file);
    204127
    … …  
    209132                $retval = true;
    210133                if( is_array($filelist) ) //false if no files, So check first.
    211                         foreach($filelist as $filename=>$fileinfo)
     134                        foreach($filelist as $filename => $fileinfo)
    212135                                if( ! $this->delete($file . $filename, $recursive) )
    213136                                        $retval = false;
    … …  
    218141        }
    219142
    220         function exists($file){
     143        function exists($file) {
    221144                return @file_exists($file);
    222145        }
    223146
    224         function is_file($file){
     147        function is_file($file) {
    225148                return @is_file($file);
    226149        }
    227150
    228         function is_dir($path){
     151        function is_dir($path) {
    229152                return @is_dir($path);
    230153        }
    231154
    232         function is_readable($file){
     155        function is_readable($file) {
    233156                return @is_readable($file);
    234157        }
    235158
    236         function is_writable($file){
     159        function is_writable($file) {
    237160                return @is_writable($file);
    238161        }
    239162
    240         function atime($file){
     163        function atime($file) {
    241164                return @fileatime($file);
    242165        }
    243166
    244         function mtime($file){
     167        function mtime($file) {
    245168                return @filemtime($file);
    246169        }
    247         function size($file){
     170        function size($file) {
    248171                return @filesize($file);
    249172        }
    … …  
    254177                if($atime == 0)
    255178                        $atime = time();
    256                 return @touch($file,$time,$atime);
     179                return @touch($file, $time, $atime);
    257180        }
    258181
    … …  
    261184                        $chmod = $this->permission;
    262185
    263                 if( !@mkdir($path,$chmod) )
     186                if( ! @mkdir($path, $chmod) )
    264187                        return false;
    265188                if( $chown )
    266                         $this->chown($path,$chown);
     189                        $this->chown($path, $chown);
    267190                if( $chgrp )
    268                         $this->chgrp($path,$chgrp);
    269                 return true;
    270         }
    271 
    272         function rmdir($path,$recursive=false){
     191                        $this->chgrp($path, $chgrp);
     192                return true;
     193        }
     194
     195        function rmdir($path, $recursive = false) {
    273196                //Currently unused and untested, Use delete() instead.
    274197                if( ! $recursive )
    … …  
    276199                //recursive:
    277200                $filelist = $this->dirlist($path);
    278                 foreach($filelist as $filename=>$det){
    279                         if ( '/' == substr($filename,-1,1) )
    280                                 $this->rmdir($path.'/'.$filename,$recursive);
     201                foreach($filelist as $filename => $det) {
     202                        if ( '/' == substr($filename, -1, 1) )
     203                                $this->rmdir($path . '/' . $filename, $recursive);
    281204                        @rmdir($filename);
    282205                }
    … …  
    284207        }
    285208
    286         function dirlist($path,$incdot=false,$recursive=false){
    287                 if( $this->is_file($path) ){
     209        function dirlist($path, $incdot = false, $recursive = false) {
     210                if( $this->is_file($path) ) {
    288211                        $limitFile = basename($path);
    289212                        $path = dirname($path);
    … …  
    296219                $ret = array();
    297220                $dir = dir($path);
    298                 while (false !== ($entry = $dir->read())) {
     221                while (false !== ($entry = $dir->read()) ) {
    299222                        $struc = array();
    300                         $struc['name']          = $entry;
     223                        $struc['name'] = $entry;
    301224
    302225                        if( '.' == $struc['name'] || '..' == $struc['name'] )
    … …  
    318241                        $struc['type']          = $this->is_dir($path.'/'.$entry) ? 'd' : 'f';
    319242
    320                         if ('d' == $struc['type'] ){
     243                        if ( 'd' == $struc['type'] ) {
    321244                                if( $recursive )
    322                                         $struc['files'] = $this->dirlist($path.'/'.$struc['name'], $incdot, $recursive);
     245                                        $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
    323246                                else
    324247                                        $struc['files'] = array();
    … …  
    331254                return $ret;
    332255        }
    333 
    334         function __destruct(){
    335                 return;
    336         }
    337256}
    338257?>
  • trunk/wp-admin/includes/class-wp-filesystem-ftpext.php

    r7999 r8009  
    11<?php
    2 class WP_Filesystem_FTPext{
     2class WP_Filesystem_FTPext extends WP_Filesystem_Base{
    33        var $link;
    44        var $timeout = 5;
    … …  
    66        var $options = array();
    77
    8         var $wp_base = '';
    98        var $permission = null;
    109
    … …  
    2524
    2625        function WP_Filesystem_FTPext($opt='') {
     26                $this->method = 'ftpext';
    2727                $this->errors = new WP_Error();
    2828
    … …  
    6161        }
    6262
    63         function connect(){
    64                 if ( $this->options['ssl'] && function_exists('ftp_ssl_connect') ) {
     63        function connect() {
     64                if ( $this->options['ssl'] && function_exists('ftp_ssl_connect') )
    6565                        $this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'],$this->timeout);
    66                 } else {
     66                else
    6767                        $this->link = @ftp_connect($this->options['hostname'], $this->options['port'],$this->timeout);
    68                 }
    6968
    7069                if ( ! $this->link ) {
    … …  
    8180        }
    8281
    83         function setDefaultPermissions($perm){
     82        function setDefaultPermissions($perm) {
    8483                $this->permission = $perm;
    8584        }
    86 
    87         function find_base_dir($path = false, $base = '.',$echo = false, $loop = false) {
    88                 if (!$path)
    89                         $path = ABSPATH;
    90                
    91                 //Sanitize the Windows path formats, This allows easier conparison and aligns it to FTP output.
    92                 $path = str_replace('\\','/',$path); //windows: Straighten up the paths..
    93                 if( strpos($path, ':') ){ //Windows, Strip out the driveletter
    94                         if( preg_match("|.{1}\:(.+)|i", $path, $mat) )
    95                                 $path = $mat[1];
    96                 }
    9785       
    98                 //Set up the base directory (Which unless specified, is the current one)
    99                 if( empty( $base ) || '.' == $base ) $base = $this->cwd();
    100                 $base = trailingslashit($base);
    101 
    102                 //Can we see the Current directory as part of the ABSPATH?
    103                 $location = strpos($path, $base);
    104                 if( false !== $location ) {
    105                         $newbase = path_join($base, substr($path, $location + strlen($base)));
    106 
    107                         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.
    108                                 if($echo) printf( __('Changing to %s') . '<br/>', $newbase );
    109                                 //Check to see if it exists in that folder.
    110                                 if( $this->exists($newbase . 'wp-settings.php') ){
    111                                         if($echo) printf( __('Found %s'),  $newbase . 'wp-settings.php<br/>' );
    112                                         return $newbase;
    113                                 }       
    114                         }
    115                 }
    116        
    117                 //Ok, Couldnt do a magic location from that particular folder level
    118                
    119                 //Get a list of the files in the current directory, See if we can locate where we are in the folder stucture.
    120                 $files = $this->dirlist($base);
    121                
    122                 $arrPath = explode('/', $path);
    123                 foreach($arrPath as $key){
    124                         //Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,
    125                         // If its found, change into it and follow through looking for it.
    126                         // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on.
    127                         // If it reaches the end, and still cant find it, it'll return false for the entire function.
    128                         if( isset($files[ $key ]) ){
    129                                 //Lets try that folder:
    130                                 $folder = path_join($base, $key);
    131                                 if($echo) printf( __('Changing to %s') . '<br/>', $folder );
    132                                 $ret = $this->find_base_dir( $path, $folder, $echo, $loop);
    133                                 if( $ret )
    134                                         return $ret;
    135                         }
    136                 }
    137                 //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.
    138                 if(isset( $files[ 'wp-settings.php' ]) ){
    139                         if($echo) printf( __('Found %s'),  $base . 'wp-settings.php<br/>' );
    140                         return $base;
    141                 }
    142                 if( $loop )
    143                         return false;//Prevent tihs function looping again.
    144                 //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.
    145                 return $this->find_base_dir($path, '/', $echo, true);
    146         }
    147 
    148         function get_base_dir($path = false, $base = '.', $echo = false){
    149                 if( defined('FTP_BASE') )
    150                         $this->wp_base = FTP_BASE;
    151                 if( empty($this->wp_base) )
    152                         $this->wp_base = $this->find_base_dir($path, $base, $echo);
    153                 return $this->wp_base;
    154         }
    155         function get_contents($file,$type='',$resumepos=0){
     86        function get_contents($file, $type = '', $resumepos = 0 ){
    15687                if( empty($type) ){
    15788                        $extension = substr(strrchr($file, "."), 1);
    … …  
    16192                if ( ! $temp )
    16293                        return false;
    163                 if( ! @ftp_fget($this->link,$temp,$file,$type,$resumepos) )
     94                if( ! @ftp_fget($this->link, $temp, $file, $type, $resumepos) )
    16495                        return false;
    16596                fseek($temp, 0); //Skip back to the start of the file being written to
    … …  
    171102                return $contents;
    172103        }
    173         function get_contents_array($file){
    174                 return explode("\n",$this->get_contents($file));
    175         }
    176         function put_contents($file,$contents,$type=''){
    177                 if( empty($type) ){
     104        function get_contents_array($file) {
     105                return explode("\n", $this->get_contents($file));
     106        }
     107        function put_contents($file, $contents, $type = '' ) {
     108                if( empty($type) ) {
    178109                        $extension = substr(strrchr($file, "."), 1);
    179110                        $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_ASCII;
    … …  
    182113                if ( ! $temp )
    183114                        return false;
    184                 fwrite($temp,$contents);
     115                fwrite($temp, $contents);
    185116                fseek($temp, 0); //Skip back to the start of the file being written to
    186                 $ret = @ftp_fput($this->link,$file,$temp,$type);
     117                $ret = @ftp_fput($this->link, $file, $temp, $type);
    187118                fclose($temp);
    188119                return $ret;
    189120        }
    190         function cwd(){
     121        function cwd() {
    191122                $cwd = ftp_pwd($this->link);
    192123                if( $cwd )
    … …  
    194125                return $cwd;
    195126        }
    196         function chdir($dir){
     127        function chdir($dir) {
    197128                return @ftp_chdir($dir);
    198129        }
    199         function chgrp($file,$group,$recursive=false){
    200                 return false;
    201         }
    202         function chmod($file,$mode=false,$recursive=false){
     130        function chgrp($file, $group, $recursive = false ) {
     131                return false;
     132        }
     133        function chmod($file, $mode = false, $recursive = false) {
    203134                if( ! $mode )
    204135                        $mode = $this->permission;
    … …  
    207138                if ( ! $this->exists($file) )
    208139                        return false;
    209                 if ( ! $recursive || ! $this->is_dir($file) ){
    210                         if (!function_exists('ftp_chmod'))
     140                if ( ! $recursive || ! $this->is_dir($file) ) {
     141                        if ( ! function_exists('ftp_chmod') )
    211142                                return @ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file));
    212                         return @ftp_chmod($this->link,$mode,$file);
     143                        return @ftp_chmod($this->link, $mode, $file);
    213144                }
    214145                //Is a directory, and we want recursive
    215146                $filelist = $this->dirlist($file);
    216147                foreach($filelist as $filename){
    217                         $this->chmod($file.'/'.$filename,$mode,$recursive);
    218                 }
    219                 return true;
    220         }
    221         function chown($file,$owner,$recursive=false){
    222                 return false;
    223         }
    224         function owner($file){
     148                        $this->chmod($file . '/' . $filename, $mode, $recursive);
     149                }
     150                return true;
     151        }
     152        function chown($file, $owner, $recursive = false ) {
     153                return false;
     154        }
     155        function owner($file) {
    225156                $dir = $this->dirlist($file);
    226157                return $dir[$file]['owner'];
    227158        }
    228         function getchmod($file){
     159        function getchmod($file) {
    229160                $dir = $this->dirlist($file);
    230161                return $dir[$file]['permsn'];
    231162        }
    232         function gethchmod($file){
    233                 //From the PHP.net page for ...?
    234                 $perms = $this->getchmod($file);
    235                 if (($perms & 0xC000) == 0xC000) {
    236                         // Socket
    237                         $info = 's';
    238                 } elseif (($perms & 0xA000) == 0xA000) {
    239                         // Symbolic Link
    240                         $info = 'l';
    241                 } elseif (($perms & 0x8000) == 0x8000) {
    242                         // Regular
    243                         $info = '-';
    244                 } elseif (($perms & 0x6000) == 0x6000) {
    245                         // Block special
    246                         $info = 'b';
    247                 } elseif (($perms & 0x4000) == 0x4000) {
    248                         // Directory
    249                         $info = 'd';
    250                 } elseif (($perms & 0x2000) == 0x2000) {
    251                         // Character special
    252                         $info = 'c';
    253                 } elseif (($perms & 0x1000) == 0x1000) {
    254                         // FIFO pipe
    255                         $info = 'p';
    256                 } else {
    257                         // Unknown
    258                         $info = 'u';
    259                 }
    260 
    261                 // Owner
    262                 $info .= (($perms & 0x0100) ? 'r' : '-');
    263                 $info .= (($perms & 0x0080) ? 'w' : '-');
    264                 $info .= (($perms & 0x0040) ?
    265                                         (($perms & 0x0800) ? 's' : 'x' ) :
    266                                         (($perms & 0x0800) ? 'S' : '-'));
    267 
    268                 // Group
    269                 $info .= (($perms & 0x0020) ? 'r' : '-');
    270                 $info .= (($perms & 0x0010) ? 'w' : '-');
    271                 $info .= (($perms & 0x0008) ?
    272                                         (($perms & 0x0400) ? 's' : 'x' ) :
    273                                         (($perms & 0x0400) ? 'S' : '-'));
    274 
    275                 // World
    276                 $info .= (($perms & 0x0004) ? 'r' : '-');
    277                 $info .= (($perms & 0x0002) ? 'w' : '-');
    278                 $info .= (($perms & 0x0001) ?
    279                                         (($perms & 0x0200) ? 't' : 'x' ) :
    280                                         (($perms & 0x0200) ? 'T' : '-'));
    281                 return $info;
    282         }
    283         function getnumchmodfromh($mode) {
    284                 $realmode = "";
    285                 $legal =  array("","w","r","x","-");
    286                 $attarray = preg_split("//",$mode);
    287                 for($i=0;$i<count($attarray);$i++){
    288                    if($key = array_search($attarray[$i],$legal)){
    289                            $realmode .= $legal[$key];
    290                    }
    291                 }
    292                 $mode = str_pad($realmode,9,'-');
    293                 $trans = array('-'=>'0','r'=>'4','w'=>'2','x'=>'1');
    294                 $mode = strtr($mode,$trans);
    295                 $newmode = '';
    296                 $newmode .= $mode[0]+$mode[1]+$mode[2];
    297                 $newmode .= $mode[3]+$mode[4]+$mode[5];
    298                 $newmode .= $mode[6]+$mode[7]+$mode[8];
    299                 return $newmode;
    300         }
    301         function group($file){
     163        function group($file) {
    302164                $dir = $this->dirlist($file);
    303165                return $dir[$file]['group'];
    304166        }
    305         function copy($source,$destination,$overwrite=false){
     167        function copy($source, $destination, $overwrite = false ) {
    306168                if( ! $overwrite && $this->exists($destination) )
    307169                        return false;
    … …  
    309171                if( false === $content)
    310172                        return false;
    311                 return $this->put_contents($destination,$content);
    312         }
    313         function move($source,$destination,$overwrite=false){
    314                 return ftp_rename($this->link,$source,$destination);
     173                return $this->put_contents($destination, $content);
     174        }
     175        function move($source, $destination, $overwrite = false) {
     176                return ftp_rename($this->link, $source, $destination);
    315177        }
    316178
    317179        function delete($file,$recursive=false) {
    318180                if ( $this->is_file($file) )
    319                         return @ftp_delete($this->link,$file);
     181                        return @ftp_delete($this->link, $file);
    320182                if ( !$recursive )
    321                         return @ftp_rmdir($this->link,$file);
     183                        return @ftp_rmdir($this->link, $file);
    322184                $filelist = $this->dirlist($file);
    323185                foreach ((array) $filelist as $filename => $fileinfo) {
    324                         $this->delete($file.'/'.$filename,$recursive);
    325                 }
    326                 return @ftp_rmdir($this->link,$file);
    327         }
    328 
    329         function exists($file){
    330                 $list = ftp_rawlist($this->link,$file,false);
     186                        $this->delete($file . '/' . $filename, $recursive);
     187                }
     188                return @ftp_rmdir($this->link, $file);
     189        }
     190
     191        function exists($file) {
     192                $list = ftp_rawlist($this->link, $file, false);
    331193                if( ! $list )
    332194                        return false;
    333195                return count($list) == 1 ? true : false;
    334196        }
    335         function is_file($file){
     197        function is_file($file) {
    336198                return $this->is_dir($file) ? false : true;
    337199        }
    338         function is_dir($path){
     200        function is_dir($path) {
    339201                $cwd = $this->cwd();
    340202                $result = @ftp_chdir($this->link, $path);
    341                 if( $result && $path == $this->cwd() ||
    342                         $this->cwd() != $cwd ) {
     203                if( $result && $path == $this->cwd() || $this->cwd() != $cwd ) {
    343204                        @ftp_chdir($this->link, $cwd);
    344205                        return true;
    … …  
    346207                return false;
    347208        }
    348         function is_readable($file){
     209        function is_readable($file) {
    349210                //Get dir list, Check if the file is writable by the current user??
    350211                return true;
    351212        }
    352         function is_writable($file){
     213        function is_writable($file) {
    353214                //Get dir list, Check if the file is writable by the current user??
    354215                return true;
    355216        }
    356         function atime($file){
    357                 return false;
    358         }
    359         function mtime($file){
     217        function atime($file) {
     218                return false;
     219        }
     220        function mtime($file) {
    360221                return ftp_mdtm($this->link, $file);
    361222        }
    362         function size($file){
     223        function size($file) {
    363224                return ftp_size($this->link, $file);
    364225        }
    365         function touch($file,$time=0,$atime=0){
    366                 return false;
    367         }
    368         function mkdir($path,$chmod=false,$chown=false,$chgrp=false){
     226        function touch($file, $time = 0, $atime = 0) {
     227                return false;
     228        }
     229        function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
    369230                if( !@ftp_mkdir($this->link, $path) )
    370231                        return false;
    … …  
    377238                return true;
    378239        }
    379         function rmdir($path,$recursive=false){
     240        function rmdir($path, $recursive = false) {
    380241                if( ! $recursive )
    381242                        return @ftp_rmdir($this->link, $path);
    … …  
    389250        function parselisting($line) {
    390251                $is_windows = ($this->OS_remote == FTP_OS_Windows);
    391                 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)) {
     252                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)) {
    392253                        $b = array();
    393                         if ($lucifer[3]<70) { $lucifer[3]+=2000; } else { $lucifer[3]+=1900; } // 4digit year fix
     254                        if ($lucifer[3]<70) { $lucifer[3] +=2000; } else { $lucifer[3]+=1900; } // 4digit year fix
    394255                        $b['isdir'] = ($lucifer[7]=="<DIR>");
    395256                        if ( $b['isdir'] )
    … …  
    449310        }
    450311
    451         function dirlist($path='.',$incdot=false,$recursive=false){
    452                 if( $this->is_file($path) ){
     312        function dirlist($path = '.', $incdot = false, $recursive = false) {
     313                if( $this->is_file($path) ) {
    453314                        $limitFile = basename($path);
    454315                        $path = dirname($path) . '/';
    … …  
    457318                }
    458319
    459                 $list = @ftp_rawlist($this->link , '-a ' . $path, false);
     320                $list = @ftp_rawlist($this->link, '-a ' . $path, false);
    460321
    461322                if ( $list === false )
    … …  
    468329                                continue;
    469330
    470                         if ( $entry["name"]=="." or $entry["name"]==".." )
     331                        if ( '.' == $entry["name"] || '..' == $entry["name"] )
    471332                                continue;
    472333
    473                         $dirlist[$entry['name']] = $entry;
     334                        $dirlist[ $entry['name'] ] = $entry;
    474335                }
    475336
    … …  
    489350                                        if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder
    490351                                                if ($recursive)
    491                                                         $struc['files'] = $this->dirlist($path.'/'.$struc['name'],$incdot,$recursive);
     352                                                        $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
    492353                                        }
    493354                                } else { //No dots
    494355                                        if ($recursive)
    495                                                 $struc['files'] = $this->dirlist($path.'/'.$struc['name'],$incdot,$recursive);
     356                                                $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
    496357                                }
    497358                        }
  • trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php

    r7999 r8009  
    66        var $options = array();
    77
    8         var $wp_base = '';
    98        var $permission = null;
    109
    1110        var $filetypes = array(
    12                                                         'php'=>FTP_ASCII,
    13                                                         'css'=>FTP_ASCII,
    14                                                         'txt'=>FTP_ASCII,
    15                                                         'js'=>FTP_ASCII,
    16                                                         'html'=>FTP_ASCII,
    17                                                         'htm'=>FTP_ASCII,
    18                                                         'xml'=>FTP_ASCII,
    19 
    20                                                         'jpg'=>FTP_BINARY,
    21                                                         'png'=>FTP_BINARY,
    22                                                         'gif'=>FTP_BINARY,
    23                                                         'bmp'=>FTP_BINARY
     11                                                        'php' => FTP_ASCII,
     12                                                        'css' => FTP_ASCII,
     13                                                        'txt' => FTP_ASCII,
     14                                                        'js'  => FTP_ASCII,
     15                                                        'html'=> FTP_ASCII,
     16                                                        'htm' => FTP_ASCII,
     17                                                        'xml' => FTP_ASCII,
     18
     19                                                        'jpg' => FTP_BINARY,
     20                                                        'png' => FTP_BINARY,
     21                                                        'gif' => FTP_BINARY,
     22                                                        'bmp' => FTP_BINARY
    2423                                                        );
    2524
    2625        function WP_Filesystem_ftpsockets($opt='') {
     26                $this->method = 'ftpsockets';
    2727                $this->errors = new WP_Error();
    2828
    … …  
    8585        function setDefaultPermissions($perm) {
    8686                $this->permission = $perm;
    87         }
    88 
    89         function find_base_dir($path = false, $base = '.',$echo = false, $loop = false) {
    90                 if (!$path)
    91                         $path = ABSPATH;
    92                
    93                 //Sanitize the Windows path formats, This allows easier conparison and aligns it to FTP output.
    94                 $path = str_replace('\\','/',$path); //windows: Straighten up the paths..
    95                 if( strpos($path, ':') ){ //Windows, Strip out the driveletter
    96                         if( preg_match("|.{1}\:(.+)|i", $path, $mat) )
    97                                 $path = $mat[1];
    98                 }
    99        
    100                 //Set up the base directory (Which unless specified, is the current one)
    101                 if( empty( $base ) || '.' == $base ) $base = $this->cwd();
    102                 $base = trailingslashit($base);
    103 
    104                 //Can we see the Current directory as part of the ABSPATH?
    105                 $location = strpos($path, $base);
    106                 if( false !== $location ) {
    107                         $newbase = path_join($base, substr($path, $location + strlen($base)));
    108 
    109                         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.
    110                                 if($echo) printf( __('Changing to %s') . '<br/>', $newbase );
    111                                 //Check to see if it exists in that folder.
    112                                 if( $this->exists($newbase . 'wp-settings.php') ){
    113                                         if($echo) printf( __('Found %s'),  $newbase . 'wp-settings.php<br/>' );
    114                                         return $newbase;
    115                                 }       
    116                         }
    117                 }
    118        
    119                 //Ok, Couldnt do a magic location from that particular folder level
    120                
    121                 //Get a list of the files in the current directory, See if we can locate where we are in the folder stucture.
    122                 $files = $this->dirlist($base);
    123                
    124                 $arrPath = explode('/', $path);
    125                 foreach($arrPath as $key){
    126                         //Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,
    127                         // If its found, change into it and follow through looking for it.
    128                         // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on.
    129                         // If it reaches the end, and still cant find it, it'll return false for the entire function.
    130                         if( isset($files[ $key ]) ){
    131                                 //Lets try that folder:
    132                                 $folder = path_join($base, $key);
    133                                 if($echo) printf( __('Changing to %s') . '<br/>', $folder );
    134                                 $ret = $this->find_base_dir($path, $folder, $echo, $loop);
    135                                 if( $ret )
    136                                         return $ret;
    137                         }
    138                 }
    139                 //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.
    140                 if(isset( $files[ 'wp-settings.php' ]) ){
    141                         if($echo) printf( __('Found %s'),  $base . 'wp-settings.php<br/>' );
    142                         return $base;
    143                 }
    144                 if( $loop )
    145                         return false;//Prevent tihs function looping again.
    146                 //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.
    147                 return $this->find_base_dir($path, '/', $echo, true);
    148         }
    149 
    150         function get_base_dir($path = false, $base = '.', $echo = false){
    151                 if( defined('FTP_BASE') )
    152                         $this->wp_base = FTP_BASE;
    153                 if( empty($this->wp_base) )
    154                         $this->wp_base = $this->find_base_dir($path, $base, $echo);
    155                 return $this->wp_base;
    15687        }
    15788
    … …  
    332263                        return false;
    333264
    334                 return $this->put_contents($destination,$content);
    335         }
    336 
    337         function move($source,$destination,$overwrite=false){
    338                 return $this->ftp->rename($source,$destination);
    339         }
    340 
    341         function delete($file,$recursive=false) {
     265                return $this->put_contents($destination, $content);
     266        }
     267
     268        function move($source, $destination, $overwrite = false ) {
     269                return $this->ftp->rename($source, $destination);
     270        }
     271
     272        function delete($file, $recursive = false ) {
    342273                if ( $this->is_file($file) )
    343274                        return $this->ftp->delete($file);
    … …  
    348279        }
    349280
    350         function exists($file){
     281        function exists($file) {
    351282                return $this->ftp->is_exists($file);
    352283        }
    353284
    354         function is_file($file){
     285        function is_file($file) {
    355286                return $this->is_dir($file) ? false : true;
    356287        }
    357288
    358         function is_dir($path){
     289        function is_dir($path) {
    359290                $cwd = $this->cwd();
    360291                if ( $this->chdir($path) ) {
    … …  
    365296        }
    366297
    367         function is_readable($file){
     298        function is_readable($file) {
    368299                //Get dir list, Check if the file is writable by the current user??
    369300                return true;
    370301        }
    371302
    372         function is_writable($file){
     303        function is_writable($file) {
    373304                //Get dir list, Check if the file is writable by the current user??
    374305                return true;
    375306        }
    376307
    377         function atime($file){
    378                 return false;
    379         }
    380 
    381         function mtime($file){
     308        function atime($file) {
     309                return false;
     310        }
     311
     312        function mtime($file) {
    382313                return $this->ftp->mdtm($file);
    383314        }
    384315
    385         function size($file){
     316        function size($file) {
    386317                return $this->ftp->filesize($file);
    387318        }
    388319
    389         function touch($file,$time=0,$atime=0){
    390                 return false;
    391         }
    392 
    393         function mkdir($path,$chmod=false,$chown=false,$chgrp=false){
     320        function touch($file, $time = 0, $atime = 0 ){
     321                return false;
     322        }
     323
     324        function mkdir($path, $chmod = false, $chown = false, $chgrp = false ) {
    394325                if( ! $this->ftp->mkdir($path) )
    395326                        return false;
    … …  
    403334        }
    404335
    405         function rmdir($path,$recursive=false){
     336        function rmdir($path, $recursive = false ) {
    406337                if( ! $recursive )
    407338                        return $this->ftp->rmdir($path);
    … …  
    410341        }
    411342
    412         function dirlist($path='.',$incdot=false,$recursive=false){
    413                 if( $this->is_file($path) ){
     343        function dirlist($path = '.', $incdot = false, $recursive = false ) {
     344                if( $this->is_file($path) ) {
    414345                        $limitFile = basename($path);
    415346                        $path = dirname($path) . '/';
    … …  
    434365                                        if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder
    435366                                                if ($recursive)
    436                                                         $struc['files'] = $this->dirlist($path.'/'.$struc['name'],$incdot,$recursive);
     367                                                        $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
    437368                                        }
    438369                                } else { //No dots
    439370                                        if ($recursive)
    440                                                 $struc['files'] = $this->dirlist($path.'/'.$struc['name'],$incdot,$recursive);
     371                                                $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
    441372                                }
    442373                        }
  • trunk/wp-admin/includes/file.php

    r7999 r8009  
    3535function get_real_file_to_edit( $file ) {
    3636        if ('index.php' == $file || '.htaccess' == $file ) {
    37                 $real_file = get_home_path().$file;
     37                $real_file = get_home_path() . $file;
    3838        } else {
    39                 $real_file = ABSPATH.$file;
     39                $real_file = ABSPATH . $file;
    4040        }
    4141
    … …  
    257257                        if ( ! $fs->is_dir($to . $tmppath) )
    258258                                if ( !$fs->mkdir($to . $tmppath, 0755) )
    259                                         return new WP_Error('mkdir_failed', __('Could not create directory'));
     259                                        return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $tmppath);
    260260                }
    261261
    … …  
    263263                if ( ! $file['folder'] )
    264264                        if ( !$fs->put_contents( $to . $file['filename'], $file['content']) )
    265                                 return new WP_Error('copy_failed', __('Could not copy file'));
     265                                return new WP_Error('copy_failed', __('Could not copy file'), $to . $file['filename']);
    266266                        $fs->chmod($to . $file['filename'], 0644);
    267267        }
    … …  
    281281                if ( 'f' == $fileinfo['type'] ) {
    282282                        if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true) )
    283                                 return false;
     283                                return new WP_Error('copy_failed', __('Could not copy file'), $to . $filename);
    284284                        $wp_filesystem->chmod($to . $filename, 0644);
    285285                } elseif ( 'd' == $fileinfo['type'] ) {
    286286                        if ( !$wp_filesystem->mkdir($to . $filename, 0755) )
    287                                 return false;
    288                         if ( !copy_dir($from . $filename, $to . $filename) )
    289                                 return false;
     287                                return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $filename);
     288                        $result = copy_dir($from . $filename, $to . $filename);
     289                        if ( is_wp_error($result) )
     290                                return $result;
    290291                }
    291292        }
    292 
    293         return true;
    294293}
    295294
    296295function WP_Filesystem( $args = false ) {
    297296        global $wp_filesystem;
     297
     298        require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
    298299
    299300        $method = get_filesystem_method();
  • trunk/wp-admin/includes/update.php

    r7999 r8009  
    151151
    152152        // Is a filesystem accessor setup?
    153         if ( ! $wp_filesystem || !is_object($wp_filesystem) )
     153        if ( ! $wp_filesystem || ! is_object($wp_filesystem) )
    154154                WP_Filesystem();
    155155
    … …  
    161161
    162162        //Get the base plugin folder
    163         $base = $wp_filesystem->get_base_dir(WP_PLUGIN_DIR);
    164        
    165         if ( empty($base) )
    166                 return new WP_Error('fs_nowordpress', __('Unable to locate WordPress directory.'));
     163        $plugins_dir = $wp_filesystem->wp_plugins_dir();
     164        if ( empty($plugins_dir) )
     165                return new WP_Error('fs_no)plugins_dir', __('Unable to locate WordPress Plugin directory.'));
     166
     167        //And the same for the Content directory.
     168        $content_dir = $wp_filesystem->wp_content_dir();
     169        if( empty($content_dir) )
     170                return new WP_Error('fs_no_content_dor', __('Unable to locate WordPress Content directory (wp-content).'));
     171       
     172        $plugins_dir = trailingslashit( $plugins_dir );
     173        $content_dir = trailingslashit( $content_dir );
    167174
    168175        // Get the URL to the zip file
    … …  
    175182        $package = $r->package;
    176183        apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package));
    177         $file = download_url($package);
    178 
    179         if ( is_wp_error($file) )
     184        $download_file = download_url($package);
     185
     186        if ( is_wp_error($download_file) )
    180187                return new WP_Error('download_failed', __('Download failed.'), $file->get_error_message());
    181188
    182         $working_dir = $wp_filesystem->get_base_dir(WP_CONTENT_DIR) . '/upgrade/' . basename($plugin, '.php');
     189        $working_dir = $content_dir . 'upgrade/' . basename($plugin, '.php');
    183190
    184191        // Clean up working directory
    … …  
    188195        apply_filters('update_feedback', __('Unpacking the update'));
    189196        // Unzip package to working directory
    190         $result = unzip_file($file, $working_dir);
     197        $result = unzip_file($download_file, $working_dir);
     198       
     199        // Once extracted, delete the package
     200        unlink($download_file);
     201       
    191202        if ( is_wp_error($result) ) {
    192                 unlink($file);
    193203                $wp_filesystem->delete($working_dir, true);
    194204                return $result;
    195205        }
    196 
    197         // Once extracted, delete the package
    198         unlink($file);
    199206
    200207        if ( is_plugin_active($plugin) ) {
    … …  
    206213        // Remove the existing plugin.
    207214        apply_filters('update_feedback', __('Removing the old version of the plugin'));
    208         $plugin_dir = dirname($base . "/$plugin");
    209         $plugin_dir = trailingslashit($plugin_dir);
     215        $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) );
    210216       
    211217        // If plugin is in its own directory, recursively delete the directory.
    212         if ( strpos($plugin, '/') && $plugin_dir != $base . '/' ) //base check on if plugin includes directory seperator AND that its not the root plugin folder
    213                 $deleted = $wp_filesystem->delete($plugin_dir, true);
     218        if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory seperator AND that its not the root plugin folder
     219                $deleted = $wp_filesystem->delete($this_plugin_dir, true);
    214220        else
    215                 $deleted = $wp_filesystem->delete($base . '/' . $plugin);
    216 
    217         if ( !$deleted ) {
     221                $deleted = $wp_filesystem->delete($plugins_dir . $plugin);
     222
     223        if ( ! $deleted ) {
    218224                $wp_filesystem->delete($working_dir, true);
    219225                return new WP_Error('delete_failed', __('Could not remove the old plugin'));
    … …  
    222228        apply_filters('update_feedback', __('Installing the latest version'));
    223229        // Copy new version of plugin into place.
    224         if ( !copy_dir($working_dir, $base) ) {
     230        $result = copy_dir($working_dir, $plugins_dir);
     231        if ( is_wp_error($result) ) {
    225232                //$wp_filesystem->delete($working_dir, true); //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails.
    226                 return new WP_Error('install_failed', __('Installation failed'));
     233                return $result;
    227234        }
    228235
    … …  
    237244       
    238245        if( empty($filelist) )
    239                 return false; //We couldnt find any files in the working dir
     246                return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup.
    240247       
    241248        $folder = $filelist[0];
    242         $plugin = get_plugins('/' . $folder); //Pass it with a leading slash, search out the plugins in the folder,
     249        $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash
    243250        $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
    244251
    245         return  $folder . '/' . $pluginfiles[0]; //Pass it without a leading slash as WP requires
     252        return  $folder . '/' . $pluginfiles[0];
    246253}
    247254
  • trunk/wp-admin/update.php

    r7999 r8009  
    111111        }
    112112
    113         $was_activated = is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is,
     113        $was_activated = is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is
    114114
    115115        $result = wp_update_plugin($plugin, 'show_message');
    … …  
    117117        if ( is_wp_error($result) ) {
    118118                show_message($result);
     119                show_message( __('Installation Failed') );
    119120        } else {
    120121                //Result is the new plugin file relative to WP_PLUGIN_DIR
    121                 show_message(__('Plugin upgraded successfully'));       
     122                show_message( __('Plugin upgraded successfully') );     
    122123                if( $result && $was_activated ){
    123124                        show_message(__('Attempting reactivation of the plugin'));
Note: See TracChangeset for help on using the changeset viewer.