Make WordPress Core


Ignore:
Timestamp:
05/29/2008 05:29:32 PM (18 years ago)
Author:
ryan
Message:

Make WP_Filesystem work with new directory constants. Props DD32. fixes #7059

File:
1 edited

Legend:

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

    r7999 r8009  
    66        var $options = array();
    77
    8         var $wp_base = '';
    98        var $permission = null;
    109
    1110        var $filetypes = array(
    12                                                         'php'=>FTP_ASCII,
    13                                                         'css'=>FTP_ASCII,
    14                                                         'txt'=>FTP_ASCII,
    15                                                         'js'=>FTP_ASCII,
    16                                                         'html'=>FTP_ASCII,
    17                                                         'htm'=>FTP_ASCII,
    18                                                         'xml'=>FTP_ASCII,
    19 
    20                                                         'jpg'=>FTP_BINARY,
    21                                                         'png'=>FTP_BINARY,
    22                                                         'gif'=>FTP_BINARY,
    23                                                         'bmp'=>FTP_BINARY
     11                                                        'php' => FTP_ASCII,
     12                                                        'css' => FTP_ASCII,
     13                                                        'txt' => FTP_ASCII,
     14                                                        'js'  => FTP_ASCII,
     15                                                        'html'=> FTP_ASCII,
     16                                                        'htm' => FTP_ASCII,
     17                                                        'xml' => FTP_ASCII,
     18
     19                                                        'jpg' => FTP_BINARY,
     20                                                        'png' => FTP_BINARY,
     21                                                        'gif' => FTP_BINARY,
     22                                                        'bmp' => FTP_BINARY
    2423                                                        );
    2524
    2625        function WP_Filesystem_ftpsockets($opt='') {
     26                $this->method = 'ftpsockets';
    2727                $this->errors = new WP_Error();
    2828
    … …  
    8585        function setDefaultPermissions($perm) {
    8686                $this->permission = $perm;
    87         }
    88 
    89         function find_base_dir($path = false, $base = '.',$echo = false, $loop = false) {
    90                 if (!$path)
    91                         $path = ABSPATH;
    92                
    93                 //Sanitize the Windows path formats, This allows easier conparison and aligns it to FTP output.
    94                 $path = str_replace('\\','/',$path); //windows: Straighten up the paths..
    95                 if( strpos($path, ':') ){ //Windows, Strip out the driveletter
    96                         if( preg_match("|.{1}\:(.+)|i", $path, $mat) )
    97                                 $path = $mat[1];
    98                 }
    99        
    100                 //Set up the base directory (Which unless specified, is the current one)
    101                 if( empty( $base ) || '.' == $base ) $base = $this->cwd();
    102                 $base = trailingslashit($base);
    103 
    104                 //Can we see the Current directory as part of the ABSPATH?
    105                 $location = strpos($path, $base);
    106                 if( false !== $location ) {
    107                         $newbase = path_join($base, substr($path, $location + strlen($base)));
    108 
    109                         if( false !== $this->chdir($newbase) ){ //chdir sometimes returns null under certain circumstances, even when its changed correctly, FALSE will be returned if it doesnt change correctly.
    110                                 if($echo) printf( __('Changing to %s') . '<br/>', $newbase );
    111                                 //Check to see if it exists in that folder.
    112                                 if( $this->exists($newbase . 'wp-settings.php') ){
    113                                         if($echo) printf( __('Found %s'),  $newbase . 'wp-settings.php<br/>' );
    114                                         return $newbase;
    115                                 }       
    116                         }
    117                 }
    118        
    119                 //Ok, Couldnt do a magic location from that particular folder level
    120                
    121                 //Get a list of the files in the current directory, See if we can locate where we are in the folder stucture.
    122                 $files = $this->dirlist($base);
    123                
    124                 $arrPath = explode('/', $path);
    125                 foreach($arrPath as $key){
    126                         //Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,
    127                         // If its found, change into it and follow through looking for it.
    128                         // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on.
    129                         // If it reaches the end, and still cant find it, it'll return false for the entire function.
    130                         if( isset($files[ $key ]) ){
    131                                 //Lets try that folder:
    132                                 $folder = path_join($base, $key);
    133                                 if($echo) printf( __('Changing to %s') . '<br/>', $folder );
    134                                 $ret = $this->find_base_dir($path, $folder, $echo, $loop);
    135                                 if( $ret )
    136                                         return $ret;
    137                         }
    138                 }
    139                 //Only check this as a last resort, to prevent locating the incorrect install. All above proceeedures will fail quickly if this is the right branch to take.
    140                 if(isset( $files[ 'wp-settings.php' ]) ){
    141                         if($echo) printf( __('Found %s'),  $base . 'wp-settings.php<br/>' );
    142                         return $base;
    143                 }
    144                 if( $loop )
    145                         return false;//Prevent tihs function looping again.
    146                 //As an extra last resort, Change back to / if the folder wasnt found. This comes into effect when the CWD is /home/user/ but WP is at /var/www/.... mainly dedicated setups.
    147                 return $this->find_base_dir($path, '/', $echo, true);
    148         }
    149 
    150         function get_base_dir($path = false, $base = '.', $echo = false){
    151                 if( defined('FTP_BASE') )
    152                         $this->wp_base = FTP_BASE;
    153                 if( empty($this->wp_base) )
    154                         $this->wp_base = $this->find_base_dir($path, $base, $echo);
    155                 return $this->wp_base;
    15687        }
    15788
    … …  
    332263                        return false;
    333264
    334                 return $this->put_contents($destination,$content);
    335         }
    336 
    337         function move($source,$destination,$overwrite=false){
    338                 return $this->ftp->rename($source,$destination);
    339         }
    340 
    341         function delete($file,$recursive=false) {
     265                return $this->put_contents($destination, $content);
     266        }
     267
     268        function move($source, $destination, $overwrite = false ) {
     269                return $this->ftp->rename($source, $destination);
     270        }
     271
     272        function delete($file, $recursive = false ) {
    342273                if ( $this->is_file($file) )
    343274                        return $this->ftp->delete($file);
    … …  
    348279        }
    349280
    350         function exists($file){
     281        function exists($file) {
    351282                return $this->ftp->is_exists($file);
    352283        }
    353284
    354         function is_file($file){
     285        function is_file($file) {
    355286                return $this->is_dir($file) ? false : true;
    356287        }
    357288
    358         function is_dir($path){
     289        function is_dir($path) {
    359290                $cwd = $this->cwd();
    360291                if ( $this->chdir($path) ) {
    … …  
    365296        }
    366297
    367         function is_readable($file){
     298        function is_readable($file) {
    368299                //Get dir list, Check if the file is writable by the current user??
    369300                return true;
    370301        }
    371302
    372         function is_writable($file){
     303        function is_writable($file) {
    373304                //Get dir list, Check if the file is writable by the current user??
    374305                return true;
    375306        }
    376307
    377         function atime($file){
    378                 return false;
    379         }
    380 
    381         function mtime($file){
     308        function atime($file) {
     309                return false;
     310        }
     311
     312        function mtime($file) {
    382313                return $this->ftp->mdtm($file);
    383314        }
    384315
    385         function size($file){
     316        function size($file) {
    386317                return $this->ftp->filesize($file);
    387318        }
    388319
    389         function touch($file,$time=0,$atime=0){
    390                 return false;
    391         }
    392 
    393         function mkdir($path,$chmod=false,$chown=false,$chgrp=false){
     320        function touch($file, $time = 0, $atime = 0 ){
     321                return false;
     322        }
     323
     324        function mkdir($path, $chmod = false, $chown = false, $chgrp = false ) {
    394325                if( ! $this->ftp->mkdir($path) )
    395326                        return false;
    … …  
    403334        }
    404335
    405         function rmdir($path,$recursive=false){
     336        function rmdir($path, $recursive = false ) {
    406337                if( ! $recursive )
    407338                        return $this->ftp->rmdir($path);
    … …  
    410341        }
    411342
    412         function dirlist($path='.',$incdot=false,$recursive=false){
    413                 if( $this->is_file($path) ){
     343        function dirlist($path = '.', $incdot = false, $recursive = false ) {
     344                if( $this->is_file($path) ) {
    414345                        $limitFile = basename($path);
    415346                        $path = dirname($path) . '/';
    … …  
    434365                                        if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder
    435366                                                if ($recursive)
    436                                                         $struc['files'] = $this->dirlist($path.'/'.$struc['name'],$incdot,$recursive);
     367                                                        $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
    437368                                        }
    438369                                } else { //No dots
    439370                                        if ($recursive)
    440                                                 $struc['files'] = $this->dirlist($path.'/'.$struc['name'],$incdot,$recursive);
     371                                                $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
    441372                                }
    442373                        }
Note: See TracChangeset for help on using the changeset viewer.