Ticket #5586: 5586.4.diff

File 5586.4.diff, 5.1 kB (added by DD32, 4 months ago)

Better WP location search / Allow blank files in installer

  • wp-admin/includes/class-wp-filesystem-ftpext.php

    old new  
    8585        } 
    8686 
    8787        function find_base_dir($base = '.',$echo = false){ 
     88                $abspath = str_replace('\\','/',ABSPATH); //windows: Straighten up the paths.. 
     89                if( strpos($abspath, ':') ){ //Windows, Strip out the driveletter 
     90                        if( preg_match("|.{1}\:(.+)|i", $abspath, $mat) ) 
     91                                $abspath = $mat[1]; 
     92                } 
     93         
    8894                if( empty( $base ) || '.' == $base ) $base = $this->cwd(); 
    8995                if( empty( $base ) ) $base = '/'; 
    9096                if( '/' != substr($base, -1) ) $base .= '/'; 
    9197 
    92                 if($echo) echo sprintf(__('Changing to %s'), $base) .'<br>'; 
    93                 if( false === ftp_chdir($this->link, $base) ) 
     98                if($echo) echo __('Changing to ') . $base .'<br>'; 
     99                if( false === $this->chdir($base) ) 
    94100                        return false; 
    95101 
    96102                if( $this->exists($base . 'wp-settings.php') ){ 
    97                         if($echo) echo sprintf(__('Found %s'), $base . 'wp-settings.php') . '<br>'; 
     103                        if($echo) echo __('Found ') . $base . 'wp-settings.php<br>'; 
    98104                        $this->wp_base = $base; 
    99105                        return $this->wp_base; 
    100106                } 
    101107 
    102                 if( strpos(ABSPATH, $base) > 0) 
    103                         $arrPath = split('/',substr(ABSPATH,strpos(ABSPATH, $base))); 
     108                if( strpos($abspath, $base) > 0) 
     109                        $arrPath = split('/',substr($abspath,strpos($abspath, $base))); 
    104110                else 
    105                         $arrPath = split('/',ABSPATH); 
     111                        $arrPath = split('/',$abspath); 
    106112 
    107113                for($i = 0; $i <= count($arrPath); $i++) 
    108114                        if( $arrPath[ $i ] == '' ) unset( $arrPath[ $i ] ); 
    109115 
    110116                foreach($arrPath as $key=>$folder){ 
    111117                        if( $this->is_dir($base . $folder) ){ 
    112                                 if($echo) echo sprintf(__('Found %s'), $folder) . ' ' . sprintf(__('Changing to %s'), $base . $folder . '/') . '<br>'; 
     118                                if($echo) echo __('Found ') . $folder . ' ' . __('Changing to') . ' ' . $base . $folder . '/<br>'; 
    113119                                return $this->find_base_dir($base .  $folder . '/',$echo); 
    114120                        } 
    115121                } 
     
    158164        function cwd(){ 
    159165                return ftp_pwd($this->link); 
    160166        } 
     167        function chdir($dir){ 
     168                return @ftp_chdir($dir); 
     169        } 
    161170        function chgrp($file,$group,$recursive=false){ 
    162171                return false; 
    163172        } 
     
    170179                        return false; 
    171180                if ( ! $recursive || ! $this->is_dir($file) ){ 
    172181                        if (!function_exists('ftp_chmod')) 
    173                                 return ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file)); 
    174                         return ftp_chmod($this->link,$mode,$file); 
     182                                return @ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file)); 
     183                        return @ftp_chmod($this->link,$mode,$file); 
    175184                } 
    176185                //Is a directory, and we want recursive 
    177186                $filelist = $this->dirlist($file); 
     
    267276        function copy($source,$destination,$overwrite=false){ 
    268277                if( ! $overwrite && $this->exists($destination) ) 
    269278                        return false; 
    270                 if ( !$content = $this->get_contents($source) ) 
     279                $content = $this->get_contents($source); 
     280                if( false === $content) 
    271281                        return false; 
    272282                return $this->put_contents($destination,$content); 
    273283        } 
  • wp-admin/includes/class-wp-filesystem-ftpsockets.php

    old new  
    8787        } 
    8888 
    8989        function find_base_dir($base = '.',$echo = false) { 
     90                $abspath = str_replace('\\','/',ABSPATH); //windows: Straighten up the paths.. 
     91                if( strpos($abspath, ':') ){ //Windows, Strip out the driveletter 
     92                        if( preg_match("|.{1}\:(.+)|i", $abspath, $mat) ) 
     93                                $abspath = $mat[1]; 
     94                } 
     95         
    9096                if( empty( $base ) || '.' == $base ) $base = $this->cwd(); 
    9197                if( empty( $base ) ) $base = '/'; 
    9298                if( '/' != substr($base, -1) ) $base .= '/'; 
    9399 
    94100                if($echo) echo __('Changing to ') . $base  .'<br>'; 
    95                 if( false === $this->ftp->chdir($base) ) 
     101                if( false === $this->chdir($base) ) 
    96102                        return false; 
    97103 
    98104                if( $this->exists($base . 'wp-settings.php') ){ 
     
    101107                        return $this->wp_base; 
    102108                } 
    103109 
    104                 if( strpos(ABSPATH, $base) > 0) 
    105                         $arrPath = split('/',substr(ABSPATH,strpos(ABSPATH, $base))); 
     110                if( strpos($abspath, $base) > 0) 
     111                        $arrPath = split('/',substr($abspath,strpos($abspath, $base))); 
    106112                else 
    107                         $arrPath = split('/',ABSPATH); 
     113                        $arrPath = split('/',$abspath); 
    108114 
    109115                for($i = 0; $i <= count($arrPath); $i++) 
    110116                        if( $arrPath[ $i ] == '' ) unset( $arrPath[ $i ] ); 
     
    129135        } 
    130136 
    131137        function get_contents($file,$type='',$resumepos=0){ 
     138                if( ! $this->exists($file) ) 
     139                        return false; 
     140 
    132141                if( empty($type) ){ 
    133142                        $extension = substr(strrchr($filename, "."), 1); 
    134143                        $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_AUTOASCII; 
     
    137146                $temp = tmpfile(); 
    138147                if ( ! $this->ftp->fget($temp, $file) ) { 
    139148                        fclose($temp); 
    140                         return false; 
     149                        return ''; //Blank document, File does exist, Its just blank. 
    141150                } 
    142151                fseek($temp, 0); //Skip back to the start of the file being written to 
    143152                $contents = ''; 
     
    287296                        return false; 
    288297 
    289298                $content = $this->get_contents($source); 
    290                 if ( !$content ) 
     299                if ( false === $content ) 
    291300                        return false; 
    292301 
    293302                return $this->put_contents($destination,$content);