<!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-&gt;exists($file) )
-                        return false;
-
</del><span class="cx">                 if ( ! $mode ) {
</span><span class="cx">                         if ( $this-&gt;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-&gt;is_dir($file) )
</ins><span class="cx">                         return @chmod($file, $mode);
</span><del>-                if ( ! $this-&gt;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-&gt;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-&gt;dirlist($path);
-                foreach ($filelist as $filename =&gt; $det) {
-                        if ( '/' == substr($filename, -1, 1) )
-                                $this-&gt;rmdir($path . '/' . $filename, $recursive);
-                        @rmdir($filename);
-                }
-                return @rmdir($path);
</del><ins>+                return $this-&gt;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-&gt;exists($file) &amp;&amp; ! $this-&gt;is_dir($file) )
-                        return false;
-
</del><span class="cx">                 if ( ! $mode ) {
</span><span class="cx">                         if ( $this-&gt;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-&gt;link, $path) )
</del><ins>+                if ( !ftp_mkdir($this-&gt;link, $path) )
</ins><span class="cx">                         return false;
</span><del>-                if ( ! $chmod )
-                        $chmod = FS_CHMOD_DIR;
-                $this-&gt;chmod($path, $chmod);
</del><ins>+                $this-&gt;chmod($path);
</ins><span class="cx">                 if ( $chown )
</span><span class="cx">                         $this-&gt;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-&gt;link)), 'win') !== false;
</del><ins>+                        $is_windows = strpos( strtolower( ftp_systype($this-&gt;link) ), 'win') !== false;
</ins><span class="cx"> 
</span><del>-                if ( $is_windows &amp;&amp; preg_match(&quot;/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|&lt;DIR&gt;) +(.+)/&quot;, $line, $lucifer) ) {
</del><ins>+                if ( $is_windows &amp;&amp; preg_match('/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|&lt;DIR&gt;) +(.+)/', $line, $lucifer) ) {
</ins><span class="cx">                         $b = array();
</span><del>-                        if ( $lucifer[3] &lt; 70 ) { $lucifer[3] +=2000; } else { $lucifer[3] += 1900; } // 4digit year fix
-                        $b['isdir'] = ($lucifer[7]==&quot;&lt;DIR&gt;&quot;);
</del><ins>+                        if ( $lucifer[3] &lt; 70 )
+                                $lucifer[3] +=2000;
+                        else
+                                $lucifer[3] += 1900; // 4digit year fix
+                        $b['isdir'] = ( $lucifer[7] == '&lt;DIR&gt;');
</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],&quot;PM&quot;)==0?12:0),$lucifer[5],0,$lucifer[1],$lucifer[2],$lucifer[3]);
</del><ins>+                        $b['time'] = @mktime($lucifer[4] + (strcasecmp($lucifer[6], &quot;PM&quot;) == 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 &amp;&amp; $lucifer=preg_split(&quot;/[ ]/&quot;,$line,9,PREG_SPLIT_NO_EMPTY)) {
</del><ins>+                } elseif ( !$is_windows &amp;&amp; $lucifer = preg_split('/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY)) {
</ins><span class="cx">                         //echo $line.&quot;\n&quot;;
</span><del>-                        $lcount=count($lucifer);
-                        if ($lcount&lt;8) return '';
</del><ins>+                        $lcount = count($lucifer);
+                        if ( $lcount &lt; 8 )
+                                return '';
</ins><span class="cx">                         $b = array();
</span><span class="cx">                         $b['isdir'] = $lucifer[0]{0} === &quot;d&quot;;
</span><span class="cx">                         $b['islink'] = $lucifer[0]{0} === &quot;l&quot;;
</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],&quot;%d-%d-%d&quot;,$b['year'],$b['month'],$b['day']);
-                                sscanf($lucifer[6],&quot;%d:%d&quot;,$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(&quot;/([0-9]{2}):([0-9]{2})/&quot;,$lucifer[7],$l2)) {
</del><ins>+                                if ( preg_match('/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2) ) {
</ins><span class="cx">                                         $b['year'] = date(&quot;Y&quot;);
</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(&quot;%d %s %d %02d:%02d&quot;,$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-&gt;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-&gt;ftp-&gt;rmdir($path);
-
-                return $this-&gt;ftp-&gt;mdel($path);
</del><ins>+                $this-&gt;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>