Make WordPress Core

Ticket #7861: 7861.2.diff

File 7861.2.diff, 7.1 KB (added by DD32, 16 years ago)
  • wp-admin/includes/class-wp-filesystem-base.php

     
    1212 * @since 2.5
    1313 */
    1414class WP_Filesystem_Base {
     15        /**
     16         * Whether to display debug data for the connection or not.
     17         *
     18         * @since 2.5
     19         * @access public
     20         * @var bool
     21         */
    1522        var $verbose = false;
     23        /**
     24         * Cached list of local filepaths to maped remote filepaths.
     25         *
     26         * @since 2.7
     27         * @access private
     28         * @var array
     29         */
    1630        var $cache = array();
    1731
     32        /**
     33         * The Access method of the current connection, Set automatically.
     34         *
     35         * @since 2.5
     36         * @access public
     37         * @var string
     38         */
    1839        var $method = '';
    1940
     41        /**
     42         * Returns the path on the remote filesystem of ABSPATH
     43         *
     44         * @since 2.7
     45         * @access public
     46         * @return string The location of the remote path.
     47         */
    2048        function abspath() {
    2149                if ( defined('FTP_BASE') && strpos($this->method, 'ftp') !== false )
    2250                        return FTP_BASE;
    23                 return $this->find_folder(ABSPATH);
     51                $folder = $this->find_folder(ABSPATH);
     52                //Perhaps the FTP folder is rooted at the WordPress install, Check for wp-includes folder in root, Could have some false positives, but rare.
     53                if ( ! $folder && $this->is_dir('/wp-includes') )
     54                        $folder = '/';
     55                return $folder;
    2456        }
     57        /**
     58         * Returns the path on the remote filesystem of WP_CONTENT_DIR
     59         *
     60         * @since 2.7
     61         * @access public
     62         * @return string The location of the remote path.
     63         */
    2564        function wp_content_dir() {
    2665                if ( defined('FTP_CONTENT_DIR') && strpos($this->method, 'ftp') !== false )
    2766                        return FTP_CONTENT_DIR;
    2867                return $this->find_folder(WP_CONTENT_DIR);
    2968        }
     69        /**
     70         * Returns the path on the remote filesystem of WP_PLUGIN_DIR
     71         *
     72         * @since 2.7
     73         * @access public
     74         *
     75         * @return string The location of the remote path.
     76         */
    3077        function wp_plugins_dir() {
    3178                if ( defined('FTP_PLUGIN_DIR') && strpos($this->method, 'ftp') !== false )
    3279                        return FTP_PLUGIN_DIR;
    3380                return $this->find_folder(WP_PLUGIN_DIR);
    3481        }
     82        /**
     83         * Returns the path on the remote filesystem of the Themes Directory
     84         *
     85         * @since 2.7
     86         * @access public
     87         *
     88         * @return string The location of the remote path.
     89         */
    3590        function wp_themes_dir() {
    3691                return $this->wp_content_dir() . '/themes';
    3792        }
    38         //Back compat: use abspath() or wp_*_dir
     93       
     94        /**
     95         * Locates a folder on the remote filesystem.
     96         *
     97         * Deprecated; use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() methods instead.
     98         *
     99         * @since 2.5
     100         * @deprecated 2.7
     101         * @access public
     102         *
     103         * @param string $base The folder to start searching from
     104         * @param bool $echo True to display debug information
     105         * @return string The location of the remote path.
     106         */
    39107        function find_base_dir($base = '.', $echo = false) {
     108                _deprecated_function(__FUNCTION__, '2.7', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
    40109                $this->verbose = $echo;
    41110                return $this->abspath();
    42111        }
    43         //Back compat: use ::abspath() or ::wp_*_dir
     112        /**
     113         * Locates a folder on the remote filesystem.
     114         *
     115         * Deprecated; use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() methods instead.
     116         *
     117         * @since 2.5
     118         * @deprecated 2.7
     119         * @access public
     120         *
     121         * @param string $base The folder to start searching from
     122         * @param bool $echo True to display debug information
     123         * @return string The location of the remote path.
     124         */
    44125        function get_base_dir($base = '.', $echo = false) {
     126                _deprecated_function(__FUNCTION__, '2.7', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
    45127                $this->verbose = $echo;
    46128                return $this->abspath();
    47129        }
    48130
     131        /**
     132         * Locates a folder on the remote filesystem.
     133         *
     134         * Assumes that on Windows systems, Stripping off the Drive letter is OK
     135         * Sanitizes \\ to / in windows filepaths.
     136         *
     137         * @since 2.7
     138         * @access public
     139         *
     140         * @param string $folder the folder to locate
     141         * @return string The location of the remote path.
     142         */
    49143        function find_folder($folder) {
    50                 $folder = str_replace('\\', '/', $folder); //Windows Sanitiation
     144
     145                $folder = preg_replace('|^([a-z]{1}):|i', '', $folder); //Strip out windows driveletter if its there.
     146                $folder = str_replace('\\', '/', $folder); //Windows path sanitiation
     147
    51148                if ( isset($this->cache[ $folder ] ) )
    52149                        return $this->cache[ $folder ];
    53150
     
    60157                return $return;
    61158        }
    62159
    63         // Assumes $folder is windows sanitized;
    64         // Assumes that the drive letter is safe to be stripped off, Should not be a problem for windows servers.
     160        /**
     161         * Locates a folder on the remote filesystem.
     162         *
     163         * Expects Windows sanitized path
     164         *
     165         * @since 2.7
     166         * @access private
     167         *
     168         * @param string $folder the folder to locate
     169         * @param string $base the folder to start searching from
     170         * @param bool $loop if the function has recursed, Internal use only
     171         * @return string The location of the remote path.
     172         */
    65173        function search_for_folder($folder, $base = '.', $loop = false ) {
    66174                if ( empty( $base ) || '.' == $base )
    67175                        $base = trailingslashit($this->cwd());
    68176
    69                 $folder = preg_replace('|^([a-z]{1}):|i', '', $folder); //Strip out windows driveletter if its there.
     177                $folder = untrailingslashit($folder);
    70178
    71179                $folder_parts = explode('/', $folder);
    72180                $last_path = $folder_parts[ count($folder_parts) - 1 ];
     
    104212
    105213        }
    106214
    107         //Common Helper functions.
     215        /**
     216         * Returns the *nix style file permissions for a file
     217         *
     218         * From the PHP documentation page for fileperms()
     219         *
     220         * @link http://docs.php.net/fileperms
     221         * @since 2.5
     222         * @access public
     223         *
     224         * @param string $file string filename
     225         * @return int octal representation of permissions
     226         */
    108227        function gethchmod($file){
    109                 //From the PHP.net page for ...?
    110228                $perms = $this->getchmod($file);
    111229                if (($perms & 0xC000) == 0xC000) // Socket
    112230                        $info = 's';
     
    147265                                        (($perms & 0x0200) ? 'T' : '-'));
    148266                return $info;
    149267        }
     268
     269        /**
     270         * Converts *nix style file permissions to a octal number.
     271         *
     272         * Converts '-rw-r--r--' to 0644
     273         * From "info at rvgate dot nl"'s comment on the PHP documentation for chmod()
     274         *
     275         * @link http://docs.php.net/manual/en/function.chmod.php#49614
     276         * @since 2.5
     277         * @access public
     278         *
     279         * @param string $mode string *nix style file permission
     280         * @return int octal representation
     281         */
    150282        function getnumchmodfromh($mode) {
    151                 $realmode = "";
    152                 $legal =  array("", "w", "r", "x", "-");
    153                 $attarray = preg_split("//", $mode);
     283                $realmode = '';
     284                $legal =  array('', 'w', 'r', 'x', '-');
     285                $attarray = preg_split('//', $mode);
    154286
    155287                for($i=0; $i < count($attarray); $i++)
    156288                   if($key = array_search($attarray[$i], $legal))
     
    168300        }
    169301
    170302        /**
    171         * Determines if the string provided contains binary characters.
    172         *
    173         * @since 2.7
    174         * @package WordPress
    175         * @subpackage WP_Filesystem
    176         *
    177         * @param string $text String to test against
    178         *
    179         */
     303         * Determines if the string provided contains binary characters.
     304         *
     305         * @since 2.7
     306         * @access private
     307         *
     308         * @param string $text String to test against
     309         * @return bool true if string is binary, false otherwise
     310         */
    180311        function is_binary( $text ) {
    181312                return (bool) preg_match('|[^\x20-\x7E]|', $text); //chr(32)..chr(127)
    182313        }