Make WordPress Core

Ticket #7861: 7861.diff

File 7861.diff, 6.9 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;
    2351                return $this->find_folder(ABSPATH);
    2452        }
     53        /**
     54         * Returns the path on the remote filesystem of WP_CONTENT_DIR
     55         *
     56         * @since 2.7
     57         * @access public
     58         * @return string The location of the remote path.
     59         */
    2560        function wp_content_dir() {
    2661                if ( defined('FTP_CONTENT_DIR') && strpos($this->method, 'ftp') !== false )
    2762                        return FTP_CONTENT_DIR;
    2863                return $this->find_folder(WP_CONTENT_DIR);
    2964        }
     65        /**
     66         * Returns the path on the remote filesystem of WP_PLUGIN_DIR
     67         *
     68         * @since 2.7
     69         * @access public
     70         *
     71         * @return string The location of the remote path.
     72         */
    3073        function wp_plugins_dir() {
    3174                if ( defined('FTP_PLUGIN_DIR') && strpos($this->method, 'ftp') !== false )
    3275                        return FTP_PLUGIN_DIR;
    3376                return $this->find_folder(WP_PLUGIN_DIR);
    3477        }
     78        /**
     79         * Returns the path on the remote filesystem of the Themes Directory
     80         *
     81         * @since 2.7
     82         * @access public
     83         *
     84         * @return string The location of the remote path.
     85         */
    3586        function wp_themes_dir() {
    3687                return $this->wp_content_dir() . '/themes';
    3788        }
    38         //Back compat: use abspath() or wp_*_dir
     89       
     90        /**
     91         * Locates a folder on the remote filesystem.
     92         *
     93         * Deprecated; use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() methods instead.
     94         *
     95         * @since 2.5
     96         * @deprecated 2.7
     97         * @access public
     98         *
     99         * @param string $base The folder to start searching from
     100         * @param bool $echo True to display debug information
     101         * @return string The location of the remote path.
     102         */
    39103        function find_base_dir($base = '.', $echo = false) {
     104                _deprecated_function(__FUNCTION__, '2.7', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
    40105                $this->verbose = $echo;
    41106                return $this->abspath();
    42107        }
    43         //Back compat: use ::abspath() or ::wp_*_dir
     108        /**
     109         * Locates a folder on the remote filesystem.
     110         *
     111         * Deprecated; use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() methods instead.
     112         *
     113         * @since 2.5
     114         * @deprecated 2.7
     115         * @access public
     116         *
     117         * @param string $base The folder to start searching from
     118         * @param bool $echo True to display debug information
     119         * @return string The location of the remote path.
     120         */
    44121        function get_base_dir($base = '.', $echo = false) {
     122                _deprecated_function(__FUNCTION__, '2.7', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
    45123                $this->verbose = $echo;
    46124                return $this->abspath();
    47125        }
    48126
     127        /**
     128         * Locates a folder on the remote filesystem.
     129         *
     130         * Assumes that on Windows systems, Stripping off the Drive letter is OK
     131         * Sanitizes \\ to / in windows filepaths.
     132         *
     133         * @since 2.7
     134         * @access public
     135         *
     136         * @param string $folder the folder to locate
     137         * @return string The location of the remote path.
     138         */
    49139        function find_folder($folder) {
    50                 $folder = str_replace('\\', '/', $folder); //Windows Sanitiation
     140
     141                $folder = preg_replace('|^([a-z]{1}):|i', '', $folder); //Strip out windows driveletter if its there.
     142                $folder = str_replace('\\', '/', $folder); //Windows path sanitiation
     143
    51144                if ( isset($this->cache[ $folder ] ) )
    52145                        return $this->cache[ $folder ];
    53146
     
    60153                return $return;
    61154        }
    62155
    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.
     156        /**
     157         * Locates a folder on the remote filesystem.
     158         *
     159         * Expects Windows sanitized path
     160         *
     161         * @since 2.7
     162         * @access private
     163         *
     164         * @param string $folder the folder to locate
     165         * @param string $base the folder to start searching from
     166         * @param bool $loop if the function has recursed, Internal use only
     167         * @return string The location of the remote path.
     168         */
    65169        function search_for_folder($folder, $base = '.', $loop = false ) {
    66170                if ( empty( $base ) || '.' == $base )
    67171                        $base = trailingslashit($this->cwd());
    68172
    69                 $folder = preg_replace('|^([a-z]{1}):|i', '', $folder); //Strip out windows driveletter if its there.
     173                $folder = untrailingslashit($folder);
    70174
    71175                $folder_parts = explode('/', $folder);
    72176                $last_path = $folder_parts[ count($folder_parts) - 1 ];
     
    104208
    105209        }
    106210
    107         //Common Helper functions.
     211        /**
     212         * Returns the *nix style file permissions for a file
     213         *
     214         * From the PHP documentation page for fileperms()
     215         *
     216         * @link http://docs.php.net/fileperms
     217         * @since 2.5
     218         * @access public
     219         *
     220         * @param string $file string filename
     221         * @return int octal representation of permissions
     222         */
    108223        function gethchmod($file){
    109                 //From the PHP.net page for ...?
    110224                $perms = $this->getchmod($file);
    111225                if (($perms & 0xC000) == 0xC000) // Socket
    112226                        $info = 's';
     
    147261                                        (($perms & 0x0200) ? 'T' : '-'));
    148262                return $info;
    149263        }
     264
     265        /**
     266         * Converts *nix style file permissions to a octal number.
     267         *
     268         * Converts '-rw-r--r--' to 0644
     269         * From "info at rvgate dot nl"'s comment on the PHP documentation for chmod()
     270         *
     271         * @link http://docs.php.net/manual/en/function.chmod.php#49614
     272         * @since 2.5
     273         * @access public
     274         *
     275         * @param string $mode string *nix style file permission
     276         * @return int octal representation
     277         */
    150278        function getnumchmodfromh($mode) {
    151                 $realmode = "";
    152                 $legal =  array("", "w", "r", "x", "-");
    153                 $attarray = preg_split("//", $mode);
     279                $realmode = '';
     280                $legal =  array('', 'w', 'r', 'x', '-');
     281                $attarray = preg_split('//', $mode);
    154282
    155283                for($i=0; $i < count($attarray); $i++)
    156284                   if($key = array_search($attarray[$i], $legal))
     
    168296        }
    169297
    170298        /**
    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         */
     299         * Determines if the string provided contains binary characters.
     300         *
     301         * @since 2.7
     302         * @access private
     303         *
     304         * @param string $text String to test against
     305         * @return bool true if string is binary, false otherwise
     306         */
    180307        function is_binary( $text ) {
    181308                return (bool) preg_match('|[^\x20-\x7E]|', $text); //chr(32)..chr(127)
    182309        }