Make WordPress Core

Changeset 10919


Ignore:
Timestamp:
04/13/2009 04:11:02 PM (17 years ago)
Author:
ryan
Message:

WPFS cleanups. Props DD32. fixes #9525

Location:
trunk/wp-admin/includes
Files:
4 edited

Legend:

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

    r10150 r10919  
    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.
     
    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        }
     
    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        }
     
    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
     
    150153
    151154                if ( $this->exists($folder) ) { //Folder exists at that absolute path.
     155                        $folder = trailingslashit($folder);
    152156                        $this->cache[ $folder ] = $folder;
    153157                        return $folder;
     
    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                        }
     
    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.
  • trunk/wp-admin/includes/class-wp-filesystem-direct.php

    r10051 r10919  
    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';
     
    5050        }
    5151        function chgrp($file, $group, $recursive = false) {
    52                 if( ! $this->exists($file) )
    53                         return false;
    54                 if( ! $recursive )
     52                if ( ! $this->exists($file) )
     53                        return false;
     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
     
    6565        }
    6666        function chmod($file, $mode = false, $recursive = false) {
    67                 if( ! $mode )
     67                if ( ! $mode )
    6868                        $mode = $this->permission;
    69                 if( ! $this->exists($file) )
    70                         return false;
    71                 if( ! $recursive )
     69                if ( ! $this->exists($file) )
     70                        return false;
     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
     
    8282        }
    8383        function chown($file, $owner, $recursive = false) {
    84                 if( ! $this->exists($file) )
    85                         return false;
    86                 if( ! $recursive )
     84                if ( ! $this->exists($file) )
     85                        return false;
     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                }
     
    9797        function owner($file) {
    9898                $owneruid = @fileowner($file);
    99                 if( ! $owneruid )
    100                         return false;
    101                 if( ! function_exists('posix_getpwuid') )
     99                if ( ! $owneruid )
     100                        return false;
     101                if ( ! function_exists('posix_getpwuid') )
    102102                        return $owneruid;
    103103                $ownerarray = posix_getpwuid($owneruid);
     
    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 )
    112                         return false;
    113                 if( ! function_exists('posix_getgrgid') )
     111                if ( ! $gid )
     112                        return false;
     113                if ( ! function_exists('posix_getgrgid') )
    114114                        return $gid;
    115115                $grouparray = posix_getgrgid($gid);
     
    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);
     
    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;
     
    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
     
    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        }
     
    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);
     
    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) )
    202                         return false;
    203                 if( $chown )
     203                if ( ! @mkdir($path, $chmod) )
     204                        return false;
     205                if ( $chown )
    204206                        $this->chown($path, $chown);
    205                 if( $chgrp )
     207                if ( $chgrp )
    206208                        $this->chgrp($path, $chgrp);
    207209                return true;
     
    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);
     
    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);
     
    229231                        $limitFile = false;
    230232                }
    231                 if( ! $this->is_dir($path) )
     233                if ( ! $this->is_dir($path) )
    232234                        return false;
    233235
     
    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
     
    259261
    260262                        if ( 'd' == $struc['type'] ) {
    261                                 if( $recursive )
     263                                if ( $recursive )
    262264                                        $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
    263265                                else
  • trunk/wp-admin/includes/class-wp-filesystem-ftpext.php

    r10150 r10919  
    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) {
     
    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);
     
    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
     
    340343                                continue;
    341344
    342                         if ( '.' == $entry["name"] || '..' == $entry["name"] )
     345                        if ( '.' == $entry['name'] || '..' == $entry['name'] )
     346                                continue;
     347
     348                        if ( $limit && $entry['name'] != $limit )
    343349                                continue;
    344350
  • trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php

    r8990 r10919  
    187187        function getchmod($file) {
    188188                $dir = $this->dirlist($file);
    189                 return $dir[$file]['permsn'];
     189                return $this->getnumchmodfromh( $dir[basename($file)]['perms'] );
    190190        }
    191191
     
    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
     
    292293                if( ! $list )
    293294                        return false;
     295
    294296                if( empty($list) )
    295297                        return array();
     
    297299                $ret = array();
    298300                foreach ( $list as $struc ) {
     301                        if ( $limit && $struc['name'] != $limit )
     302                                continue;
    299303
    300304                        if ( 'd' == $struc['type'] ) {
Note: See TracChangeset for help on using the changeset viewer.