<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[12998] trunk/wp-admin/includes: Reduce code duplication,
Formatting cleanups, Reduce Chmod IO calls.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12998">12998</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2010-02-07 01:31:40 +0000 (Sun, 07 Feb 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Reduce code duplication, Formatting cleanups, Reduce Chmod IO calls. See <a href="http://trac.wordpress.org/ticket/10913">#10913</a> for excess IO calls.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesclasswpfilesystemdirectphp">trunk/wp-admin/includes/class-wp-filesystem-direct.php</a></li>
<li><a href="#trunkwpadminincludesclasswpfilesystemftpextphp">trunk/wp-admin/includes/class-wp-filesystem-ftpext.php</a></li>
<li><a href="#trunkwpadminincludesclasswpfilesystemftpsocketsphp">trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesclasswpfilesystemdirectphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-filesystem-direct.php (12997 => 12998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-filesystem-direct.php        2010-02-07 01:12:29 UTC (rev 12997)
+++ trunk/wp-admin/includes/class-wp-filesystem-direct.php        2010-02-07 01:31:40 UTC (rev 12998)
</span><span class="lines">@@ -116,9 +116,6 @@
</span><span class="cx">          * @return bool Returns true on success or false on failure.
</span><span class="cx">          */
</span><span class="cx">         function chmod($file, $mode = false, $recursive = false) {
</span><del>-                if ( ! $this->exists($file) )
-                        return false;
-
</del><span class="cx">                 if ( ! $mode ) {
</span><span class="cx">                         if ( $this->is_file($file) )
</span><span class="cx">                                 $mode = FS_CHMOD_FILE;
</span><span class="lines">@@ -128,10 +125,8 @@
</span><span class="cx">                                 return false;
</span><span class="cx">                 }
</span><span class="cx">
</span><del>-                if ( ! $recursive )
</del><ins>+                if ( ! $recursive || ! $this->is_dir($file) )
</ins><span class="cx">                         return @chmod($file, $mode);
</span><del>-                if ( ! $this->is_dir($file) )
-                        return @chmod($file, $mode);
</del><span class="cx">                 //Is a directory, and we want recursive
</span><span class="cx">                 $file = trailingslashit($file);
</span><span class="cx">                 $filelist = $this->dirlist($file);
</span><span class="lines">@@ -298,17 +293,7 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function rmdir($path, $recursive = false) {
</span><del>-                //Currently unused and untested, Use delete() instead.
-                if ( ! $recursive )
-                        return @rmdir($path);
-                //recursive:
-                $filelist = $this->dirlist($path);
-                foreach ($filelist as $filename => $det) {
-                        if ( '/' == substr($filename, -1, 1) )
-                                $this->rmdir($path . '/' . $filename, $recursive);
-                        @rmdir($filename);
-                }
-                return @rmdir($path);
</del><ins>+                return $this->delete($path, $recursive);
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function dirlist($path, $include_hidden = true, $recursive = false) {
</span></span></pre></div>
<a id="trunkwpadminincludesclasswpfilesystemftpextphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-filesystem-ftpext.php (12997 => 12998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-filesystem-ftpext.php        2010-02-07 01:12:29 UTC (rev 12997)
+++ trunk/wp-admin/includes/class-wp-filesystem-ftpext.php        2010-02-07 01:31:40 UTC (rev 12998)
</span><span class="lines">@@ -142,9 +142,6 @@
</span><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="cx">         function chmod($file, $mode = false, $recursive = false) {
</span><del>-                if ( ! $this->exists($file) && ! $this->is_dir($file) )
-                        return false;
-
</del><span class="cx">                 if ( ! $mode ) {
</span><span class="cx">                         if ( $this->is_file($file) )
</span><span class="cx">                                 $mode = FS_CHMOD_FILE;
</span><span class="lines">@@ -245,11 +242,9 @@
</span><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="cx">         function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
</span><del>-                if ( !ftp_mkdir($this->link, $path) )
</del><ins>+                if ( !ftp_mkdir($this->link, $path) )
</ins><span class="cx">                         return false;
</span><del>-                if ( ! $chmod )
-                        $chmod = FS_CHMOD_DIR;
-                $this->chmod($path, $chmod);
</del><ins>+                $this->chmod($path);
</ins><span class="cx">                 if ( $chown )
</span><span class="cx">                         $this->chown($path, $chown);
</span><span class="cx">                 if ( $chgrp )
</span><span class="lines">@@ -263,12 +258,15 @@
</span><span class="cx">         function parselisting($line) {
</span><span class="cx">                 static $is_windows;
</span><span class="cx">                 if ( is_null($is_windows) )
</span><del>-                        $is_windows = strpos( strtolower(ftp_systype($this->link)), 'win') !== false;
</del><ins>+                        $is_windows = strpos( strtolower( ftp_systype($this->link) ), 'win') !== false;
</ins><span class="cx">
</span><del>-                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) ) {
</del><ins>+                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) ) {
</ins><span class="cx">                         $b = array();
</span><del>-                        if ( $lucifer[3] < 70 ) { $lucifer[3] +=2000; } else { $lucifer[3] += 1900; } // 4digit year fix
-                        $b['isdir'] = ($lucifer[7]=="<DIR>");
</del><ins>+                        if ( $lucifer[3] < 70 )
+                                $lucifer[3] +=2000;
+                        else
+                                $lucifer[3] += 1900; // 4digit year fix
+                        $b['isdir'] = ( $lucifer[7] == '<DIR>');
</ins><span class="cx">                         if ( $b['isdir'] )
</span><span class="cx">                                 $b['type'] = 'd';
</span><span class="cx">                         else
</span><span class="lines">@@ -279,13 +277,14 @@
</span><span class="cx">                         $b['year'] = $lucifer[3];
</span><span class="cx">                         $b['hour'] = $lucifer[4];
</span><span class="cx">                         $b['minute'] = $lucifer[5];
</span><del>-                        $b['time'] = @mktime($lucifer[4]+(strcasecmp($lucifer[6],"PM")==0?12:0),$lucifer[5],0,$lucifer[1],$lucifer[2],$lucifer[3]);
</del><ins>+                        $b['time'] = @mktime($lucifer[4] + (strcasecmp($lucifer[6], "PM") == 0 ? 12 : 0), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3]);
</ins><span class="cx">                         $b['am/pm'] = $lucifer[6];
</span><span class="cx">                         $b['name'] = $lucifer[8];
</span><del>-                } else if (!$is_windows && $lucifer=preg_split("/[ ]/",$line,9,PREG_SPLIT_NO_EMPTY)) {
</del><ins>+                } elseif ( !$is_windows && $lucifer = preg_split('/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY)) {
</ins><span class="cx">                         //echo $line."\n";
</span><del>-                        $lcount=count($lucifer);
-                        if ($lcount<8) return '';
</del><ins>+                        $lcount = count($lucifer);
+                        if ( $lcount < 8 )
+                                return '';
</ins><span class="cx">                         $b = array();
</span><span class="cx">                         $b['isdir'] = $lucifer[0]{0} === "d";
</span><span class="cx">                         $b['islink'] = $lucifer[0]{0} === "l";
</span><span class="lines">@@ -300,15 +299,15 @@
</span><span class="cx">                         $b['owner'] = $lucifer[2];
</span><span class="cx">                         $b['group'] = $lucifer[3];
</span><span class="cx">                         $b['size'] = $lucifer[4];
</span><del>-                        if ($lcount==8) {
-                                sscanf($lucifer[5],"%d-%d-%d",$b['year'],$b['month'],$b['day']);
-                                sscanf($lucifer[6],"%d:%d",$b['hour'],$b['minute']);
-                                $b['time'] = @mktime($b['hour'],$b['minute'],0,$b['month'],$b['day'],$b['year']);
</del><ins>+                        if ( $lcount == 8 ) {
+                                sscanf($lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day']);
+                                sscanf($lucifer[6], '%d:%d', $b['hour'], $b['minute']);
+                                $b['time'] = @mktime($b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year']);
</ins><span class="cx">                                 $b['name'] = $lucifer[7];
</span><span class="cx">                         } else {
</span><span class="cx">                                 $b['month'] = $lucifer[5];
</span><span class="cx">                                 $b['day'] = $lucifer[6];
</span><del>-                                if (preg_match("/([0-9]{2}):([0-9]{2})/",$lucifer[7],$l2)) {
</del><ins>+                                if ( preg_match('/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2) ) {
</ins><span class="cx">                                         $b['year'] = date("Y");
</span><span class="cx">                                         $b['hour'] = $l2[1];
</span><span class="cx">                                         $b['minute'] = $l2[2];
</span><span class="lines">@@ -317,7 +316,7 @@
</span><span class="cx">                                         $b['hour'] = 0;
</span><span class="cx">                                         $b['minute'] = 0;
</span><span class="cx">                                 }
</span><del>-                                $b['time'] = strtotime(sprintf("%d %s %d %02d:%02d",$b['day'],$b['month'],$b['year'],$b['hour'],$b['minute']));
</del><ins>+                                $b['time'] = strtotime( sprintf('%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute']) );
</ins><span class="cx">                                 $b['name'] = $lucifer[8];
</span><span class="cx">                         }
</span><span class="cx">                 }
</span></span></pre></div>
<a id="trunkwpadminincludesclasswpfilesystemftpsocketsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php (12997 => 12998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php        2010-02-07 01:12:29 UTC (rev 12997)
+++ trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php        2010-02-07 01:31:40 UTC (rev 12998)
</span><span class="lines">@@ -154,7 +154,6 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function chmod($file, $mode = false, $recursive = false ) {
</span><del>-
</del><span class="cx">                 if ( ! $mode ) {
</span><span class="cx">                         if ( $this->is_file($file) )
</span><span class="cx">                                 $mode = FS_CHMOD_FILE;
</span><span class="lines">@@ -277,10 +276,7 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function rmdir($path, $recursive = false ) {
</span><del>-                if ( ! $recursive )
-                        return $this->ftp->rmdir($path);
-
-                return $this->ftp->mdel($path);
</del><ins>+                $this->delete($path, $recursive);
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function dirlist($path = '.', $include_hidden = true, $recursive = false ) {
</span></span></pre>
</div>
</div>
</body>
</html>