Make WordPress Core

Ticket #10774: 10774.2.diff

File 10774.2.diff, 7.8 KB (added by dd32, 16 years ago)
  • wp-admin/includes/class-wp-filesystem-direct.php

     
    307307                return @rmdir($path);
    308308        }
    309309
    310         function dirlist($path, $incdot = false, $recursive = false) {
     310        function dirlist($path, $include_hidden = true, $recursive = false) {
    311311                if ( $this->is_file($path) ) {
    312                         $limitFile = basename($path);
     312                        $limit_file = basename($path);
    313313                        $path = dirname($path);
    314314                } else {
    315                         $limitFile = false;
     315                        $limit_file = false;
    316316                }
     317
    317318                if ( ! $this->is_dir($path) )
    318319                        return false;
    319320
    320                 $ret = array();
    321321                $dir = @dir($path);
    322322                if ( ! $dir )
    323323                        return false;
     324
     325                $ret = array();
     326
    324327                while (false !== ($entry = $dir->read()) ) {
    325328                        $struc = array();
    326329                        $struc['name'] = $entry;
    327330
    328331                        if ( '.' == $struc['name'] || '..' == $struc['name'] )
    329                                 continue; //Do not care about these folders.
    330                         if ( '.' == $struc['name'][0] && !$incdot)
    331332                                continue;
    332                         if ( $limitFile && $struc['name'] != $limitFile)
     333
     334                        if ( ! $include_hidden && '.' == $struc['name'][0] )
    333335                                continue;
    334336
     337                        if ( $limit_file && $struc['name'] != $limit_file)
     338                                continue;
     339
    335340                        $struc['perms']         = $this->gethchmod($path.'/'.$entry);
    336341                        $struc['permsn']        = $this->getnumchmodfromh($struc['perms']);
    337342                        $struc['number']        = false;
     
    345350
    346351                        if ( 'd' == $struc['type'] ) {
    347352                                if ( $recursive )
    348                                         $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
     353                                        $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive);
    349354                                else
    350355                                        $struc['files'] = array();
    351356                        }
  • wp-admin/includes/class-wp-filesystem-ftpext.php

     
    323323                return $b;
    324324        }
    325325
    326         function dirlist($path = '.', $incdot = false, $recursive = false) {
    327                 if ( $this->is_file($path) ) {
    328                         $limitFile = basename($path);
     326        function dirlist($path = '.', $include_hidden = true, $recursive = false) {
     327                if ( $this->is_file($path) )
     328                        $limit_file = basename($path);
    329329                        $path = dirname($path) . '/';
    330330                } else {
    331                         $limitFile = false;
     331                        $limit_file = false;
    332332                }
    333333
    334334                $list = @ftp_rawlist($this->link, '-a ' . $path, false);
     
    342342                        if ( empty($entry) )
    343343                                continue;
    344344
    345                         if ( '.' == $entry["name"] || '..' == $entry["name"] )
     345                        if ( '.' == $entry['name'] || '..' == $entry['name'] )
    346346                                continue;
    347347
     348                        if ( ! $include_hidden && '.' == $entry['name'][0] )
     349                                continue;
     350
     351                        if ( $limit_file && $entry['name'] != $limit_file)
     352                                continue;
     353
    348354                        $dirlist[ $entry['name'] ] = $entry;
    349355                }
    350356
    351357                if ( ! $dirlist )
    352358                        return false;
    353                 if ( empty($dirlist) )
    354                         return array();
    355359
    356360                $ret = array();
    357                 foreach ( $dirlist as $struc ) {
    358 
     361                foreach ( (array)$dirlist as $struc ) {
    359362                        if ( 'd' == $struc['type'] ) {
    360                                 $struc['files'] = array();
    361 
    362                                 if ( $incdot ) {
    363                                         //We're including the doted starts
    364                                         if ( '.' != $struc['name'] && '..' != $struc['name'] ) { //Ok, It isnt a special folder
    365                                                 if ($recursive)
    366                                                         $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
    367                                         }
    368                                 } else { //No dots
    369                                         if ($recursive)
    370                                                 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
    371                                 }
     363                                if ( $recursive )
     364                                        $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive);
     365                                else
     366                                        $struc['files'] = array();
    372367                        }
    373                         //File
    374                         $ret[$struc['name']] = $struc;
     368
     369                        $ret[ $struc['name'] ] = $struc;
    375370                }
    376371                return $ret;
    377372        }
  • wp-admin/includes/class-wp-filesystem-ftpsockets.php

     
    122122                $this->ftp->SetType($type);
    123123
    124124                $temp = wp_tempnam( $file );
    125                 if ( ! $temphandle = fopen($temp, 'w+') ){
     125                if ( ! $temphandle = fopen($temp, 'w+') ) {
    126126                        unlink($temp);
    127127                        return false;
    128128                }
     
    166166                if ( ! $recursive || ! $this->is_dir($file) ) {
    167167                        return $this->ftp->chmod($file, $mode);
    168168                }
     169
    169170                //Is a directory, and we want recursive
    170171                $filelist = $this->dirlist($file);
    171                 foreach($filelist as $filename){
     172                foreach ( $filelist as $filename )
    172173                        $this->chmod($file . '/' . $filename, $mode, $recursive);
    173                 }
     174
    174175                return true;
    175176        }
    176177
     
    282283                return $this->ftp->mdel($path);
    283284        }
    284285
    285         function dirlist($path = '.', $incdot = false, $recursive = false ) {
     286        function dirlist($path = '.', $include_hidden = true, $recursive = false ) {
    286287                if ( $this->is_file($path) ) {
    287                         $limitFile = basename($path);
     288                        $limit_file = basename($path);
    288289                        $path = dirname($path) . '/';
    289290                } else {
    290                         $limitFile = false;
     291                        $limit_file = false;
    291292                }
    292293
    293294                $list = $this->ftp->dirlist($path);
    294295                if ( ! $list )
    295296                        return false;
    296                 if ( empty($list) )
    297                         return array();
    298297
    299298                $ret = array();
    300299                foreach ( $list as $struc ) {
    301300
     301                        if ( '.' == $struct['name'] || '..' == $struc['name'] )
     302                                continue;
     303
     304                        if ( ! $include_hidden && '.' == $struc['name'][0] )
     305                                continue;
     306
     307                        if ( $limit_file && $srtuc['name'] != $limit_file)
     308                                continue;
     309
    302310                        if ( 'd' == $struc['type'] ) {
    303                                 $struc['files'] = array();
     311                                if ( $recursive )
     312                                        $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive);
     313                                else
     314                                        $struc['files'] = array();
     315                        }
    304316
    305                                 if ( $incdot ){
    306                                         //We're including the doted starts
    307                                         if ( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder
    308                                                 if ($recursive)
    309                                                         $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
    310                                         }
    311                                 } else { //No dots
    312                                         if ($recursive)
    313                                                 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
    314                                 }
    315                         }
    316                         //File
    317                         $ret[$struc['name']] = $struc;
     317                        $ret[ $struc['name'] ] = $struc;
    318318                }
    319319                return $ret;
    320320        }
  • wp-admin/includes/class-wp-filesystem-ssh2.php

     
    322322                return $this->delete($path, $recursive);
    323323        }
    324324
    325         function dirlist($path, $incdot = false, $recursive = false) {
     325        function dirlist($path, $include_hidden = true, $recursive = false) {
    326326                if ( $this->is_file($path) ) {
    327                         $limitFile = basename($path);
     327                        $limit_file = basename($path);
    328328                        $path = dirname($path);
    329329                } else {
    330                         $limitFile = false;
     330                        $limit_file = false;
    331331                }
     332
    332333                if ( ! $this->is_dir($path) )
    333334                        return false;
    334335
    335336                $ret = array();
    336337                $dir = @dir('ssh2.sftp://' . $this->sftp_link .'/' . ltrim($path, '/') );
     338
    337339                if ( ! $dir )
    338340                        return false;
     341
    339342                while (false !== ($entry = $dir->read()) ) {
    340343                        $struc = array();
    341344                        $struc['name'] = $entry;
    342345
    343346                        if ( '.' == $struc['name'] || '..' == $struc['name'] )
    344347                                continue; //Do not care about these folders.
    345                         if ( '.' == $struc['name'][0] && !$incdot)
     348
     349                        if ( ! $include_hidden && '.' == $struc['name'][0] )
    346350                                continue;
    347                         if ( $limitFile && $struc['name'] != $limitFile)
     351
     352                        if ( $limit_file && $struc['name'] != $limit_file)
    348353                                continue;
    349354
    350355                        $struc['perms']         = $this->gethchmod($path.'/'.$entry);
     
    360365
    361366                        if ( 'd' == $struc['type'] ) {
    362367                                if ( $recursive )
    363                                         $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
     368                                        $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive);
    364369                                else
    365370                                        $struc['files'] = array();
    366371                        }