WordPress.org

Make WordPress Core

Changeset 25305


Ignore:
Timestamp:
09/09/2013 02:54:50 AM (7 years ago)
Author:
dd32
Message:

WP_Filesystem: Let the code breathe, add some additional whitespace between method definitions and comments.

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

Legend:

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

    r25082 r25305  
    2121     */
    2222    var $verbose = false;
     23
    2324    /**
    2425     * Cached list of local filepaths to mapped remote filepaths.
     
    4849    function abspath() {
    4950        $folder = $this->find_folder(ABSPATH);
    50         //Perhaps the FTP folder is rooted at the WordPress install, Check for wp-includes folder in root, Could have some false positives, but rare.
     51        // Perhaps the FTP folder is rooted at the WordPress install, Check for wp-includes folder in root, Could have some false positives, but rare.
    5152        if ( ! $folder && $this->is_dir('/wp-includes') )
    5253            $folder = '/';
    5354        return $folder;
    5455    }
     56
    5557    /**
    5658     * Returns the path on the remote filesystem of WP_CONTENT_DIR
     
    6365        return $this->find_folder(WP_CONTENT_DIR);
    6466    }
     67
    6568    /**
    6669     * Returns the path on the remote filesystem of WP_PLUGIN_DIR
     
    7477        return $this->find_folder(WP_PLUGIN_DIR);
    7578    }
     79
    7680    /**
    7781     * Returns the path on the remote filesystem of the Themes Directory
     
    9296        return $this->find_folder( $theme_root );
    9397    }
     98
    9499    /**
    95100     * Returns the path on the remote filesystem of WP_LANG_DIR
     
    122127        return $this->abspath();
    123128    }
     129
    124130    /**
    125131     * Locates a folder on the remote filesystem.
     
    189195            }
    190196        } elseif ( 'direct' == $this->method ) {
    191             $folder = str_replace('\\', '/', $folder); //Windows path sanitisation
     197            $folder = str_replace('\\', '/', $folder); // Windows path sanitisation
    192198            return trailingslashit($folder);
    193199        }
    194200
    195         $folder = preg_replace('|^([a-z]{1}):|i', '', $folder); //Strip out windows drive letter if it's there.
    196         $folder = str_replace('\\', '/', $folder); //Windows path sanitisation
     201        $folder = preg_replace('|^([a-z]{1}):|i', '', $folder); // Strip out windows drive letter if it's there.
     202        $folder = str_replace('\\', '/', $folder); // Windows path sanitisation
    197203
    198204        if ( isset($this->cache[ $folder ] ) )
    199205            return $this->cache[ $folder ];
    200206
    201         if ( $this->exists($folder) ) { //Folder exists at that absolute path.
     207        if ( $this->exists($folder) ) { // Folder exists at that absolute path.
    202208            $folder = trailingslashit($folder);
    203209            $this->cache[ $folder ] = $folder;
     
    240246        foreach ( $folder_parts as $index => $key ) {
    241247            if ( $index == $last_index )
    242                 continue; //We want this to be caught by the next code block.
    243 
    244             //Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,
     248                continue; // We want this to be caught by the next code block.
     249
     250            // Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,
    245251            // If it's found, change into it and follow through looking for it.
    246252            // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on.
    247253            // If it reaches the end, and still cant find it, it'll return false for the entire function.
    248254            if ( isset($files[ $key ]) ){
    249                 //Lets try that folder:
     255                // Lets try that folder:
    250256                $newdir = trailingslashit(path_join($base, $key));
    251257                if ( $this->verbose )
     
    258264        }
    259265
    260         //Only check this as a last resort, to prevent locating the incorrect install. All above procedures will fail quickly if this is the right branch to take.
     266        // Only check this as a last resort, to prevent locating the incorrect install. All above procedures will fail quickly if this is the right branch to take.
    261267        if (isset( $files[ $last_path ] ) ) {
    262268            if ( $this->verbose )
     
    373379     */
    374380    function is_binary( $text ) {
    375         return (bool) preg_match('|[^\x20-\x7E]|', $text); //chr(32)..chr(127)
     381        return (bool) preg_match( '|[^\x20-\x7E]|', $text ); // chr(32)..chr(127)
    376382    }
    377383}
  • trunk/src/wp-admin/includes/class-wp-filesystem-direct.php

    r25304 r25305  
    2626        $this->errors = new WP_Error();
    2727    }
     28
    2829    /**
    2930     * connect filesystem.
     
    3435        return true;
    3536    }
     37
    3638    /**
    3739     * Reads entire file into a string
     
    4345        return @file_get_contents($file);
    4446    }
     47
    4548    /**
    4649     * Reads entire file into an array
     
    5255        return @file($file);
    5356    }
     57
    5458    /**
    5559     * Write a string to a file
     
    7680        return true;
    7781    }
     82
    7883    /**
    7984     * Gets the current working directory
     
    8489        return @getcwd();
    8590    }
     91
    8692    /**
    8793     * Change directory
     
    9399        return @chdir($dir);
    94100    }
     101
    95102    /**
    96103     * Changes file group
     
    108115        if ( ! $this->is_dir($file) )
    109116            return @chgrp($file, $group);
    110         //Is a directory, and we want recursive
     117        // Is a directory, and we want recursive
    111118        $file = trailingslashit($file);
    112119        $filelist = $this->dirlist($file);
     
    116123        return true;
    117124    }
     125
    118126    /**
    119127     * Changes filesystem permissions
     
    136144        if ( ! $recursive || ! $this->is_dir($file) )
    137145            return @chmod($file, $mode);
    138         //Is a directory, and we want recursive
     146        // Is a directory, and we want recursive
    139147        $file = trailingslashit($file);
    140148        $filelist = $this->dirlist($file);
     
    144152        return true;
    145153    }
     154
    146155    /**
    147156     * Changes file owner
     
    159168        if ( ! $this->is_dir($file) )
    160169            return @chown($file, $owner);
    161         //Is a directory, and we want recursive
     170        // Is a directory, and we want recursive
    162171        $filelist = $this->dirlist($file);
    163172        foreach ($filelist as $filename) {
     
    166175        return true;
    167176    }
     177
    168178    /**
    169179     * Gets file owner
     
    181191        return $ownerarray['name'];
    182192    }
     193
    183194    /**
    184195     * Gets file permissions
     
    192203        return substr(decoct(@fileperms($file)),3);
    193204    }
     205
    194206    function group($file) {
    195207        $gid = @filegroup($file);
     
    229241
    230242    function delete($file, $recursive = false, $type = false) {
    231         if ( empty($file) ) //Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem.
    232             return false;
    233         $file = str_replace('\\', '/', $file); //for win32, occasional problems deleting files otherwise
     243        if ( empty( $file ) ) // Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem.
     244            return false;
     245        $file = str_replace( '\\', '/', $file ); // for win32, occasional problems deleting files otherwise
    234246
    235247        if ( 'f' == $type || $this->is_file($file) )
     
    238250            return @rmdir($file);
    239251
    240         //At this point it's a folder, and we're in recursive mode
     252        // At this point it's a folder, and we're in recursive mode
    241253        $file = trailingslashit($file);
    242254        $filelist = $this->dirlist($file, true);
    243255
    244256        $retval = true;
    245         if ( is_array($filelist) ) //false if no files, So check first.
    246             foreach ($filelist as $filename => $fileinfo)
     257        if ( is_array( $filelist ) ) {
     258            foreach ( $filelist as $filename => $fileinfo ) {
    247259                if ( ! $this->delete($file . $filename, $recursive, $fileinfo['type']) )
    248260                    $retval = false;
     261            }
     262        }
    249263
    250264        if ( file_exists($file) && ! @rmdir($file) )
    251265            $retval = false;
     266
    252267        return $retval;
    253268    }
     
    280295        return @filemtime($file);
    281296    }
     297
    282298    function size($file) {
    283299        return @filesize($file);
  • trunk/src/wp-admin/includes/class-wp-filesystem-ftpext.php

    r25304 r25305  
    2424        $this->errors = new WP_Error();
    2525
    26         //Check if possible to use ftp functions.
     26        // Check if possible to use ftp functions.
    2727        if ( ! extension_loaded('ftp') ) {
    2828            $this->errors->add('no_ftp_ext', __('The ftp PHP extension is not available'));
     
    3030        }
    3131
    32         // Set defaults:
    33         //This Class uses the timeout on a per-connection basis, Others use it on a per-action basis.
     32        // This Class uses the timeout on a per-connection basis, Others use it on a per-action basis.
    3433
    3534        if ( ! defined('FS_TIMEOUT') )
     
    8180        }
    8281
    83         //Set the Connection to use Passive FTP
     82        // Set the Connection to use Passive FTP
    8483        @ftp_pasv( $this->link, true );
    8584        if ( @ftp_get_option($this->link, FTP_TIMEOUT_SEC) < FS_TIMEOUT )
     
    9998            return false;
    10099
    101         fseek($temp, 0); //Skip back to the start of the file being written to
     100        fseek( $temp, 0 ); // Skip back to the start of the file being written to
    102101        $contents = '';
    103102
     
    109108        return $contents;
    110109    }
     110
    111111    function get_contents_array($file) {
    112112        return explode("\n", $this->get_contents($file));
     
    137137        return $ret;
    138138    }
     139
    139140    function cwd() {
    140141        $cwd = @ftp_pwd($this->link);
     
    143144        return $cwd;
    144145    }
     146
    145147    function chdir($dir) {
    146148        return @ftp_chdir($this->link, $dir);
    147149    }
     150
    148151    function chgrp($file, $group, $recursive = false ) {
    149152        return false;
    150153    }
     154
    151155    function chmod($file, $mode = false, $recursive = false) {
    152156        if ( ! $mode ) {
     
    171175        return (bool)@ftp_chmod($this->link, $mode, $file);
    172176    }
     177
    173178    function chown($file, $owner, $recursive = false ) {
    174179        return false;
    175180    }
     181
    176182    function owner($file) {
    177183        $dir = $this->dirlist($file);
    178184        return $dir[$file]['owner'];
    179185    }
     186
    180187    function getchmod($file) {
    181188        $dir = $this->dirlist($file);
    182189        return $dir[$file]['permsn'];
    183190    }
     191
    184192    function group($file) {
    185193        $dir = $this->dirlist($file);
    186194        return $dir[$file]['group'];
    187195    }
     196
    188197    function copy($source, $destination, $overwrite = false, $mode = false) {
    189198        if ( ! $overwrite && $this->exists($destination) )
     
    194203        return $this->put_contents($destination, $content, $mode);
    195204    }
     205
    196206    function move($source, $destination, $overwrite = false) {
    197207        return ftp_rename($this->link, $source, $destination);
     
    217227        return !empty($list); //empty list = no file, so invert.
    218228    }
     229
    219230    function is_file($file) {
    220231        return $this->exists($file) && !$this->is_dir($file);
    221232    }
     233
    222234    function is_dir($path) {
    223235        $cwd = $this->cwd();
     
    229241        return false;
    230242    }
     243
    231244    function is_readable($file) {
    232         //Get dir list, Check if the file is readable by the current user??
    233245        return true;
    234246    }
     247
    235248    function is_writable($file) {
    236         //Get dir list, Check if the file is writable by the current user??
    237249        return true;
    238250    }
     251
    239252    function atime($file) {
    240253        return false;
    241254    }
     255
    242256    function mtime($file) {
    243257        return ftp_mdtm($this->link, $file);
    244258    }
     259
    245260    function size($file) {
    246261        return ftp_size($this->link, $file);
    247262    }
     263
    248264    function touch($file, $time = 0, $atime = 0) {
    249265        return false;
    250266    }
     267
    251268    function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
    252269        $path = untrailingslashit($path);
     
    263280        return true;
    264281    }
     282
    265283    function rmdir($path, $recursive = false) {
    266284        return $this->delete($path, $recursive);
  • trunk/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php

    r25304 r25305  
    2424        $this->errors = new WP_Error();
    2525
    26         //Check if possible to use ftp functions.
     26        // Check if possible to use ftp functions.
    2727        if ( ! @include_once ABSPATH . 'wp-admin/includes/class-ftp.php' )
    2828                return false;
    2929        $this->ftp = new ftp();
    3030
    31         //Set defaults:
    3231        if ( empty($opt['port']) )
    3332            $this->options['port'] = 21;
     
    9493            fclose($temphandle);
    9594            unlink($temp);
    96             return ''; //Blank document, File does exist, It's just blank.
    97         }
    98 
    99         fseek($temphandle, 0); //Skip back to the start of the file being written to
     95            return ''; // Blank document, File does exist, It's just blank.
     96        }
     97
     98        fseek( $temphandle, 0 ); // Skip back to the start of the file being written to
    10099        $contents = '';
    101100
     
    243242
    244243    function is_readable($file) {
    245         //Get dir list, Check if the file is writable by the current user??
    246244        return true;
    247245    }
    248246
    249247    function is_writable($file) {
    250         //Get dir list, Check if the file is writable by the current user??
    251248        return true;
    252249    }
Note: See TracChangeset for help on using the changeset viewer.