Make WordPress Core

Changeset 12998


Ignore:
Timestamp:
02/07/2010 01:31:40 AM (15 years ago)
Author:
dd32
Message:

Reduce code duplication, Formatting cleanups, Reduce Chmod IO calls. See #10913 for excess IO calls.

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

Legend:

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

    r12997 r12998  
    117117     */
    118118    function chmod($file, $mode = false, $recursive = false) {
    119         if ( ! $this->exists($file) )
    120             return false;
    121 
    122119        if ( ! $mode ) {
    123120            if ( $this->is_file($file) )
     
    129126        }
    130127
    131         if ( ! $recursive )
    132             return @chmod($file, $mode);
    133         if ( ! $this->is_dir($file) )
     128        if ( ! $recursive || ! $this->is_dir($file) )
    134129            return @chmod($file, $mode);
    135130        //Is a directory, and we want recursive
     
    299294
    300295    function rmdir($path, $recursive = false) {
    301         //Currently unused and untested, Use delete() instead.
    302         if ( ! $recursive )
    303             return @rmdir($path);
    304         //recursive:
    305         $filelist = $this->dirlist($path);
    306         foreach ($filelist as $filename => $det) {
    307             if ( '/' == substr($filename, -1, 1) )
    308                 $this->rmdir($path . '/' . $filename, $recursive);
    309             @rmdir($filename);
    310         }
    311         return @rmdir($path);
     296        return $this->delete($path, $recursive);
    312297    }
    313298
  • trunk/wp-admin/includes/class-wp-filesystem-ftpext.php

    r12997 r12998  
    143143    }
    144144    function chmod($file, $mode = false, $recursive = false) {
    145         if ( ! $this->exists($file) && ! $this->is_dir($file) )
    146             return false;
    147 
    148145        if ( ! $mode ) {
    149146            if ( $this->is_file($file) )
     
    246243    }
    247244    function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
    248         if  ( !ftp_mkdir($this->link, $path) )
    249             return false;
    250         if ( ! $chmod )
    251             $chmod = FS_CHMOD_DIR;
    252         $this->chmod($path, $chmod);
     245        if ( !ftp_mkdir($this->link, $path) )
     246            return false;
     247        $this->chmod($path);
    253248        if ( $chown )
    254249            $this->chown($path, $chown);
     
    264259        static $is_windows;
    265260        if ( is_null($is_windows) )
    266             $is_windows = strpos( strtolower(ftp_systype($this->link)), 'win') !== false;
    267 
    268         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) ) {
     261            $is_windows = strpos( strtolower( ftp_systype($this->link) ), 'win') !== false;
     262
     263        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) ) {
    269264            $b = array();
    270             if ( $lucifer[3] < 70 ) { $lucifer[3] +=2000; } else { $lucifer[3] += 1900; } // 4digit year fix
    271             $b['isdir'] = ($lucifer[7]=="<DIR>");
     265            if ( $lucifer[3] < 70 )
     266                $lucifer[3] +=2000;
     267            else
     268                $lucifer[3] += 1900; // 4digit year fix
     269            $b['isdir'] = ( $lucifer[7] == '<DIR>');
    272270            if ( $b['isdir'] )
    273271                $b['type'] = 'd';
     
    280278            $b['hour'] = $lucifer[4];
    281279            $b['minute'] = $lucifer[5];
    282             $b['time'] = @mktime($lucifer[4]+(strcasecmp($lucifer[6],"PM")==0?12:0),$lucifer[5],0,$lucifer[1],$lucifer[2],$lucifer[3]);
     280            $b['time'] = @mktime($lucifer[4] + (strcasecmp($lucifer[6], "PM") == 0 ? 12 : 0), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3]);
    283281            $b['am/pm'] = $lucifer[6];
    284282            $b['name'] = $lucifer[8];
    285         } else if (!$is_windows && $lucifer=preg_split("/[ ]/",$line,9,PREG_SPLIT_NO_EMPTY)) {
     283        } elseif ( !$is_windows && $lucifer = preg_split('/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY)) {
    286284            //echo $line."\n";
    287             $lcount=count($lucifer);
    288             if ($lcount<8) return '';
     285            $lcount = count($lucifer);
     286            if ( $lcount < 8 )
     287                return '';
    289288            $b = array();
    290289            $b['isdir'] = $lucifer[0]{0} === "d";
     
    301300            $b['group'] = $lucifer[3];
    302301            $b['size'] = $lucifer[4];
    303             if ($lcount==8) {
    304                 sscanf($lucifer[5],"%d-%d-%d",$b['year'],$b['month'],$b['day']);
    305                 sscanf($lucifer[6],"%d:%d",$b['hour'],$b['minute']);
    306                 $b['time'] = @mktime($b['hour'],$b['minute'],0,$b['month'],$b['day'],$b['year']);
     302            if ( $lcount == 8 ) {
     303                sscanf($lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day']);
     304                sscanf($lucifer[6], '%d:%d', $b['hour'], $b['minute']);
     305                $b['time'] = @mktime($b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year']);
    307306                $b['name'] = $lucifer[7];
    308307            } else {
    309308                $b['month'] = $lucifer[5];
    310309                $b['day'] = $lucifer[6];
    311                 if (preg_match("/([0-9]{2}):([0-9]{2})/",$lucifer[7],$l2)) {
     310                if ( preg_match('/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2) ) {
    312311                    $b['year'] = date("Y");
    313312                    $b['hour'] = $l2[1];
     
    318317                    $b['minute'] = 0;
    319318                }
    320                 $b['time'] = strtotime(sprintf("%d %s %d %02d:%02d",$b['day'],$b['month'],$b['year'],$b['hour'],$b['minute']));
     319                $b['time'] = strtotime( sprintf('%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute']) );
    321320                $b['name'] = $lucifer[8];
    322321            }
  • trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php

    r12997 r12998  
    155155
    156156    function chmod($file, $mode = false, $recursive = false ) {
    157 
    158157        if ( ! $mode ) {
    159158            if ( $this->is_file($file) )
     
    278277
    279278    function rmdir($path, $recursive = false ) {
    280         if ( ! $recursive )
    281             return $this->ftp->rmdir($path);
    282 
    283         return $this->ftp->mdel($path);
     279        $this->delete($path, $recursive);
    284280    }
    285281
Note: See TracChangeset for help on using the changeset viewer.