Make WordPress Core

Ticket #9525: 9525.diff

File 9525.diff, 13.3 KB (added by DD32, 18 years ago)
  • wp-admin/includes/class-wp-filesystem-base.php

     
    4646         * @return string The location of the remote path.
    4747         */
    4848        function abspath() {
    49                 if ( defined('FTP_BASE') && strpos($this->method, 'ftp') !== false )
    50                         return FTP_BASE;
    5149                $folder = $this->find_folder(ABSPATH);
    5250                //Perhaps the FTP folder is rooted at the WordPress install, Check for wp-includes folder in root, Could have some false positives, but rare.
    5351                if ( ! $folder && $this->is_dir('/wp-includes') )
    … …  
    6260         * @return string The location of the remote path.
    6361         */
    6462        function wp_content_dir() {
    65                 if ( defined('FTP_CONTENT_DIR') && strpos($this->method, 'ftp') !== false )
    66                         return FTP_CONTENT_DIR;
    6763                return $this->find_folder(WP_CONTENT_DIR);
    6864        }
    6965        /**
    … …  
    7571         * @return string The location of the remote path.
    7672         */
    7773        function wp_plugins_dir() {
    78                 if ( defined('FTP_PLUGIN_DIR') && strpos($this->method, 'ftp') !== false )
    79                         return FTP_PLUGIN_DIR;
    8074                return $this->find_folder(WP_PLUGIN_DIR);
    8175        }
    8276        /**
    … …  
    142136         */
    143137        function find_folder($folder) {
    144138
     139                if ( strpos($this->method, 'ftp') !== false ) {
     140                        $constant_overrides = array( 'FTP_BASE' => ABSPATH, 'FTP_CONTENT_DIR' => WP_CONTENT_DIR, 'FTP_PLUGIN_DIR' => WP_PLUGIN_DIR );
     141                        foreach ( $constant_overrides as $constant => $dir )
     142                                if ( defined($constant) && $folder === $dir )
     143                                        return trailingslashit(constant($constant));
     144                } elseif ( 'direct' == $this->method ) {
     145                        return trailingslashit($folder);
     146                }
     147
    145148                $folder = preg_replace('|^([a-z]{1}):|i', '', $folder); //Strip out windows driveletter if its there.
    146149                $folder = str_replace('\\', '/', $folder); //Windows path sanitiation
    147150
    … …  
    149152                        return $this->cache[ $folder ];
    150153
    151154                if ( $this->exists($folder) ) { //Folder exists at that absolute path.
     155                        $folder = trailingslashit($folder);
    152156                        $this->cache[ $folder ] = $folder;
    153157                        return $folder;
    154158                }
    … …  
    189193                        // If its found, change into it and follow through looking for it.
    190194                        // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on.
    191195                        // If it reaches the end, and still cant find it, it'll return false for the entire function.
    192                         if( isset($files[ $key ]) ){
     196                        if ( isset($files[ $key ]) ){
    193197                                //Lets try that folder:
    194198                                $newdir = trailingslashit(path_join($base, $key));
    195                                 if( $this->verbose )
     199                                if ( $this->verbose )
    196200                                        printf( __('Changing to %s') . '<br/>', $newdir );
    197                                 if( $ret = $this->search_for_folder( $folder, $newdir, $loop) )
     201                                if ( $ret = $this->search_for_folder( $folder, $newdir, $loop) )
    198202                                        return $ret;
    199203                        }
    200204                }
    201205
    202206                //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.
    203                 if(isset( $files[ $last_path ] ) ) {
    204                         if( $this->verbose )
     207                if (isset( $files[ $last_path ] ) ) {
     208                        if ( $this->verbose )
    205209                                printf( __('Found %s') . '<br/>',  $base . $last_path );
    206                         return $base . $last_path;
     210                        return trailingslashit($base . $last_path);
    207211                }
    208                 if( $loop )
     212                if ( $loop )
    209213                        return false;//Prevent tihs function looping again.
    210214                //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.
    211215                return $this->search_for_folder($folder, '/', true);
  • wp-admin/includes/class-wp-filesystem-direct.php

     
    1414 * @subpackage Filesystem
    1515 * @uses WP_Filesystem_Base Extends class
    1616 */
    17 class WP_Filesystem_Direct  extends WP_Filesystem_Base {
     17class WP_Filesystem_Direct extends WP_Filesystem_Base {
    1818        var $permission = null;
    19         var $errors = array();
     19        var $errors = null;
    2020        function WP_Filesystem_Direct($arg) {
    2121                $this->method = 'direct';
    2222                $this->errors = new WP_Error();
    … …  
    4949                return @chdir($dir);
    5050        }
    5151        function chgrp($file, $group, $recursive = false) {
    52                 if( ! $this->exists($file) )
     52                if ( ! $this->exists($file) )
    5353                        return false;
    54                 if( ! $recursive )
     54                if ( ! $recursive )
    5555                        return @chgrp($file, $group);
    56                 if( ! $this->is_dir($file) )
     56                if ( ! $this->is_dir($file) )
    5757                        return @chgrp($file, $group);
    5858                //Is a directory, and we want recursive
    5959                $file = trailingslashit($file);
    6060                $filelist = $this->dirlist($file);
    61                 foreach($filelist as $filename)
     61                foreach ($filelist as $filename)
    6262                        $this->chgrp($file . $filename, $group, $recursive);
    6363
    6464                return true;
    6565        }
    6666        function chmod($file, $mode = false, $recursive = false) {
    67                 if( ! $mode )
     67                if ( ! $mode )
    6868                        $mode = $this->permission;
    69                 if( ! $this->exists($file) )
     69                if ( ! $this->exists($file) )
    7070                        return false;
    71                 if( ! $recursive )
     71                if ( ! $recursive )
    7272                        return @chmod($file,$mode);
    73                 if( ! $this->is_dir($file) )
     73                if ( ! $this->is_dir($file) )
    7474                        return @chmod($file, $mode);
    7575                //Is a directory, and we want recursive
    7676                $file = trailingslashit($file);
    7777                $filelist = $this->dirlist($file);
    78                 foreach($filelist as $filename)
     78                foreach ($filelist as $filename)
    7979                        $this->chmod($file . $filename, $mode, $recursive);
    8080
    8181                return true;
    8282        }
    8383        function chown($file, $owner, $recursive = false) {
    84                 if( ! $this->exists($file) )
     84                if ( ! $this->exists($file) )
    8585                        return false;
    86                 if( ! $recursive )
     86                if ( ! $recursive )
    8787                        return @chown($file, $owner);
    88                 if( ! $this->is_dir($file) )
     88                if ( ! $this->is_dir($file) )
    8989                        return @chown($file, $owner);
    9090                //Is a directory, and we want recursive
    9191                $filelist = $this->dirlist($file);
    92                 foreach($filelist as $filename){
     92                foreach ($filelist as $filename){
    9393                        $this->chown($file . '/' . $filename, $owner, $recursive);
    9494                }
    9595                return true;
    9696        }
    9797        function owner($file) {
    9898                $owneruid = @fileowner($file);
    99                 if( ! $owneruid )
     99                if ( ! $owneruid )
    100100                        return false;
    101                 if( ! function_exists('posix_getpwuid') )
     101                if ( ! function_exists('posix_getpwuid') )
    102102                        return $owneruid;
    103103                $ownerarray = posix_getpwuid($owneruid);
    104104                return $ownerarray['name'];
    105105        }
    106106        function getchmod($file) {
    107                 return @fileperms($file);
     107                return substr(decoct(@fileperms($file)),3);
    108108        }
    109109        function group($file) {
    110110                $gid = @filegroup($file);
    111                 if( ! $gid )
     111                if ( ! $gid )
    112112                        return false;
    113                 if( ! function_exists('posix_getgrgid') )
     113                if ( ! function_exists('posix_getgrgid') )
    114114                        return $gid;
    115115                $grouparray = posix_getgrgid($gid);
    116116                return $grouparray['name'];
    117117        }
    118118
    119119        function copy($source, $destination, $overwrite = false) {
    120                 if( ! $overwrite && $this->exists($destination) )
     120                if ( ! $overwrite && $this->exists($destination) )
    121121                        return false;
    122122                return copy($source, $destination);
    123123        }
    124124
    125125        function move($source, $destination, $overwrite = false) {
    126126                //Possible to use rename()?
    127                 if( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ){
     127                if ( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ){
    128128                        $this->delete($source);
    129129                        return true;
    130130                } else {
    … …  
    133133        }
    134134
    135135        function delete($file, $recursive = false) {
     136                if ( empty($file) ) //Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem.
     137                        return false;
    136138                $file = str_replace('\\', '/', $file); //for win32, occasional problems deleteing files otherwise
    137139
    138                 if( $this->is_file($file) )
     140                if ( $this->is_file($file) )
    139141                        return @unlink($file);
    140                 if( ! $recursive && $this->is_dir($file) )
     142                if ( ! $recursive && $this->is_dir($file) )
    141143                        return @rmdir($file);
    142144
    143145                //At this point its a folder, and we're in recursive mode
    … …  
    145147                $filelist = $this->dirlist($file, true);
    146148
    147149                $retval = true;
    148                 if( is_array($filelist) ) //false if no files, So check first.
    149                         foreach($filelist as $filename => $fileinfo)
    150                                 if( ! $this->delete($file . $filename, $recursive) )
     150                if ( is_array($filelist) ) //false if no files, So check first.
     151                        foreach ($filelist as $filename => $fileinfo)
     152                                if ( ! $this->delete($file . $filename, $recursive) )
    151153                                        $retval = false;
    152154
    153                 if( ! @rmdir($file) )
    154                         return false;
     155                if ( file_exists($file) && ! @rmdir($file) )
     156                        $retval = false;
    155157                return $retval;
    156158        }
    157159
    … …  
    187189        }
    188190
    189191        function touch($file, $time = 0, $atime = 0){
    190                 if($time == 0)
     192                if ($time == 0)
    191193                        $time = time();
    192                 if($atime == 0)
     194                if ($atime == 0)
    193195                        $atime = time();
    194196                return @touch($file, $time, $atime);
    195197        }
    196198
    197199        function mkdir($path, $chmod = false, $chown = false, $chgrp = false){
    198                 if( ! $chmod)
     200                if ( ! $chmod)
    199201                        $chmod = $this->permission;
    200202
    201                 if( ! @mkdir($path, $chmod) )
     203                if ( ! @mkdir($path, $chmod) )
    202204                        return false;
    203                 if( $chown )
     205                if ( $chown )
    204206                        $this->chown($path, $chown);
    205                 if( $chgrp )
     207                if ( $chgrp )
    206208                        $this->chgrp($path, $chgrp);
    207209                return true;
    208210        }
    209211
    210212        function rmdir($path, $recursive = false) {
    211213                //Currently unused and untested, Use delete() instead.
    212                 if( ! $recursive )
     214                if ( ! $recursive )
    213215                        return @rmdir($path);
    214216                //recursive:
    215217                $filelist = $this->dirlist($path);
    216                 foreach($filelist as $filename => $det) {
     218                foreach ($filelist as $filename => $det) {
    217219                        if ( '/' == substr($filename, -1, 1) )
    218220                                $this->rmdir($path . '/' . $filename, $recursive);
    219221                        @rmdir($filename);
    … …  
    222224        }
    223225
    224226        function dirlist($path, $incdot = false, $recursive = false) {
    225                 if( $this->is_file($path) ) {
     227                if ( $this->is_file($path) ) {
    226228                        $limitFile = basename($path);
    227229                        $path = dirname($path);
    228230                } else {
    229231                        $limitFile = false;
    230232                }
    231                 if( ! $this->is_dir($path) )
     233                if ( ! $this->is_dir($path) )
    232234                        return false;
    233235
    234236                $ret = array();
    … …  
    239241                        $struc = array();
    240242                        $struc['name'] = $entry;
    241243
    242                         if( '.' == $struc['name'] || '..' == $struc['name'] )
     244                        if ( '.' == $struc['name'] || '..' == $struc['name'] )
    243245                                continue; //Do not care about these folders.
    244                         if( '.' == $struc['name'][0] && !$incdot)
     246                        if ( '.' == $struc['name'][0] && !$incdot)
    245247                                continue;
    246                         if( $limitFile && $struc['name'] != $limitFile)
     248                        if ( $limitFile && $struc['name'] != $limitFile)
    247249                                continue;
    248250
    249251                        $struc['perms']         = $this->gethchmod($path.'/'.$entry);
    … …  
    258260                        $struc['type']          = $this->is_dir($path.'/'.$entry) ? 'd' : 'f';
    259261
    260262                        if ( 'd' == $struc['type'] ) {
    261                                 if( $recursive )
     263                                if ( $recursive )
    262264                                        $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
    263265                                else
    264266                                        $struc['files'] = array();
  • wp-admin/includes/class-wp-filesystem-ftpext.php

     
    169169        }
    170170        function getchmod($file) {
    171171                $dir = $this->dirlist($file);
    172                 return $dir[$file]['permsn'];
     172                return $this->getnumchmodfromh( $dir[basename($file)]['perms'] );
    173173        }
    174174        function group($file) {
    175175                $dir = $this->dirlist($file);
    … …  
    187187                return ftp_rename($this->link, $source, $destination);
    188188        }
    189189
    190         function delete($file,$recursive=false) {
     190        function delete($file ,$recursive = false ) {
     191                if ( empty($file) )
     192                        return false;
    191193                if ( $this->is_file($file) )
    192194                        return @ftp_delete($this->link, $file);
    193195                if ( !$recursive )
    … …  
    321323        }
    322324
    323325        function dirlist($path = '.', $incdot = false, $recursive = false) {
    324                 if( $this->is_file($path) ) {
    325                         $limitFile = basename($path);
    326                         $path = dirname($path) . '/';
     326
     327                if ( substr($path, -1) !== '/') {
     328                        $limit = basename($path);
     329                        $path = trailingslashit(dirname($path));
    327330                } else {
    328                         $limitFile = false;
     331                        $limit = false;
    329332                }
    330333
    331334                $list = @ftp_rawlist($this->link, '-a ' . $path, false);
    … …  
    339342                        if ( empty($entry) )
    340343                                continue;
    341344
    342                         if ( '.' == $entry["name"] || '..' == $entry["name"] )
     345                        if ( '.' == $entry['name'] || '..' == $entry['name'] )
    343346                                continue;
    344347
     348                        if ( $limit && $entry['name'] != $limit )
     349                                continue;
     350
    345351                        $dirlist[ $entry['name'] ] = $entry;
    346352                }
    347353
  • wp-admin/includes/class-wp-filesystem-ftpsockets.php

     
    186186
    187187        function getchmod($file) {
    188188                $dir = $this->dirlist($file);
    189                 return $dir[$file]['permsn'];
     189                return $this->getnumchmodfromh( $dir[basename($file)]['perms'] );
    190190        }
    191191
    192192        function group($file) {
    … …  
    281281        }
    282282
    283283        function dirlist($path = '.', $incdot = false, $recursive = false ) {
    284                 if( $this->is_file($path) ) {
    285                         $limitFile = basename($path);
    286                         $path = dirname($path) . '/';
     284
     285                if ( substr($path, -1) !== '/') {
     286                        $limit = basename($path);
     287                        $path = trailingslashit(dirname($path));
    287288                } else {
    288                         $limitFile = false;
     289                        $limit = false;
    289290                }
    290291
    291292                $list = $this->ftp->dirlist($path);
    292293                if( ! $list )
    293294                        return false;
     295
    294296                if( empty($list) )
    295297                        return array();
    296298
    297299                $ret = array();
    298300                foreach ( $list as $struc ) {
     301                        if ( $limit && $struc['name'] != $limit )
     302                                continue;
    299303
    300304                        if ( 'd' == $struc['type'] ) {
    301305                                $struc['files'] = array();