Changeset 8009
- Timestamp:
- 05/29/2008 05:29:32 PM (16 years ago)
- Location:
- trunk/wp-admin
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/class-wp-filesystem-direct.php
r7999 r8009 1 1 <?php 2 2 3 class WP_Filesystem_Direct {3 class WP_Filesystem_Direct extends WP_Filesystem_Base { 4 4 var $permission = null; 5 5 var $errors = array(); 6 function WP_Filesystem_Direct($arg) {6 function WP_Filesystem_Direct($arg) { 7 7 $this->errors = new WP_Error(); 8 8 $this->permission = umask(); 9 9 } 10 function connect() {11 return true; 12 } 13 function setDefaultPermissions($perm) {10 function connect() { 11 return true; 12 } 13 function setDefaultPermissions($perm) { 14 14 $this->permission = $perm; 15 15 } 16 function find_base_dir($path = false, $base = '.', $echo = false){ 17 if (!$path) 18 $path = ABSPATH; 19 return str_replace('\\','/',$path); 20 } 21 function get_base_dir($path = false, $base = '.', $echo = false){ 22 return $this->find_base_dir($base, $echo); 23 } 24 function get_contents($file){ 16 function get_contents($file) { 25 17 return @file_get_contents($file); 26 18 } 27 function get_contents_array($file) {19 function get_contents_array($file) { 28 20 return @file($file); 29 21 } 30 function put_contents($file,$contents,$mode=false,$type='') {31 if ( ! ($fp = @fopen($file,'w' .$type)) )22 function put_contents($file,$contents,$mode=false,$type='') { 23 if ( ! ($fp = @fopen($file,'w' . $type)) ) 32 24 return false; 33 25 @fwrite($fp,$contents); … … 36 28 return true; 37 29 } 38 function cwd() {30 function cwd() { 39 31 return @getcwd(); 40 32 } 41 function chdir($dir) {33 function chdir($dir) { 42 34 return @chdir($dir); 43 35 } 44 function chgrp($file,$group,$recursive=false) {36 function chgrp($file,$group,$recursive=false) { 45 37 if( ! $this->exists($file) ) 46 38 return false; 47 39 if( ! $recursive ) 48 return @chgrp($file, $group);40 return @chgrp($file, $group); 49 41 if( ! $this->is_dir($file) ) 50 return @chgrp($file, $group);42 return @chgrp($file, $group); 51 43 //Is a directory, and we want recursive 52 44 $file = trailingslashit($file); … … 57 49 return true; 58 50 } 59 function chmod($file,$mode=false,$recursive=false) {51 function chmod($file,$mode=false,$recursive=false) { 60 52 if( ! $mode ) 61 53 $mode = $this->permission; … … 65 57 return @chmod($file,$mode); 66 58 if( ! $this->is_dir($file) ) 67 return @chmod($file, $mode);59 return @chmod($file, $mode); 68 60 //Is a directory, and we want recursive 69 61 $file = trailingslashit($file); … … 74 66 return true; 75 67 } 76 function chown($file, $owner,$recursive=false){68 function chown($file, $owner, $recursive = false) { 77 69 if( ! $this->exists($file) ) 78 70 return false; 79 71 if( ! $recursive ) 80 return @chown($file, $owner);72 return @chown($file, $owner); 81 73 if( ! $this->is_dir($file) ) 82 return @chown($file, $owner);74 return @chown($file, $owner); 83 75 //Is a directory, and we want recursive 84 76 $filelist = $this->dirlist($file); 85 77 foreach($filelist as $filename){ 86 $this->chown($file .'/'.$filename,$owner,$recursive);87 } 88 return true; 89 } 90 function owner($file) {78 $this->chown($file . '/' . $filename, $owner, $recursive); 79 } 80 return true; 81 } 82 function owner($file) { 91 83 $owneruid = @fileowner($file); 92 84 if( ! $owneruid ) 93 85 return false; 94 if( ! function_exists('posix_getpwuid') )86 if( ! function_exists('posix_getpwuid') ) 95 87 return $owneruid; 96 88 $ownerarray = posix_getpwuid($owneruid); 97 89 return $ownerarray['name']; 98 90 } 99 function getchmod($file) {91 function getchmod($file) { 100 92 return @fileperms($file); 101 93 } 102 function gethchmod($file){ 103 //From the PHP.net page for ...? 104 $perms = $this->getchmod($file); 105 if (($perms & 0xC000) == 0xC000) { 106 // Socket 107 $info = 's'; 108 } elseif (($perms & 0xA000) == 0xA000) { 109 // Symbolic Link 110 $info = 'l'; 111 } elseif (($perms & 0x8000) == 0x8000) { 112 // Regular 113 $info = '-'; 114 } elseif (($perms & 0x6000) == 0x6000) { 115 // Block special 116 $info = 'b'; 117 } elseif (($perms & 0x4000) == 0x4000) { 118 // Directory 119 $info = 'd'; 120 } elseif (($perms & 0x2000) == 0x2000) { 121 // Character special 122 $info = 'c'; 123 } elseif (($perms & 0x1000) == 0x1000) { 124 // FIFO pipe 125 $info = 'p'; 126 } else { 127 // Unknown 128 $info = 'u'; 129 } 130 131 // Owner 132 $info .= (($perms & 0x0100) ? 'r' : '-'); 133 $info .= (($perms & 0x0080) ? 'w' : '-'); 134 $info .= (($perms & 0x0040) ? 135 (($perms & 0x0800) ? 's' : 'x' ) : 136 (($perms & 0x0800) ? 'S' : '-')); 137 138 // Group 139 $info .= (($perms & 0x0020) ? 'r' : '-'); 140 $info .= (($perms & 0x0010) ? 'w' : '-'); 141 $info .= (($perms & 0x0008) ? 142 (($perms & 0x0400) ? 's' : 'x' ) : 143 (($perms & 0x0400) ? 'S' : '-')); 144 145 // World 146 $info .= (($perms & 0x0004) ? 'r' : '-'); 147 $info .= (($perms & 0x0002) ? 'w' : '-'); 148 $info .= (($perms & 0x0001) ? 149 (($perms & 0x0200) ? 't' : 'x' ) : 150 (($perms & 0x0200) ? 'T' : '-')); 151 return $info; 152 } 153 function getnumchmodfromh($mode) { 154 $realmode = ""; 155 $legal = array("","w","r","x","-"); 156 $attarray = preg_split("//",$mode); 157 for($i=0;$i<count($attarray);$i++){ 158 if($key = array_search($attarray[$i],$legal)){ 159 $realmode .= $legal[$key]; 160 } 161 } 162 $mode = str_pad($realmode,9,'-'); 163 $trans = array('-'=>'0','r'=>'4','w'=>'2','x'=>'1'); 164 $mode = strtr($mode,$trans); 165 $newmode = ''; 166 $newmode .= $mode[0]+$mode[1]+$mode[2]; 167 $newmode .= $mode[3]+$mode[4]+$mode[5]; 168 $newmode .= $mode[6]+$mode[7]+$mode[8]; 169 return $newmode; 170 } 171 function group($file){ 94 function group($file) { 172 95 $gid = @filegroup($file); 173 96 if( ! $gid ) 174 97 return false; 175 if( ! function_exists('posix_getgrgid') )98 if( ! function_exists('posix_getgrgid') ) 176 99 return $gid; 177 100 $grouparray = posix_getgrgid($gid); … … 179 102 } 180 103 181 function copy($source, $destination,$overwrite=false){104 function copy($source, $destination, $overwrite = false) { 182 105 if( ! $overwrite && $this->exists($destination) ) 183 106 return false; 184 return copy($source, $destination);185 } 186 187 function move($source, $destination,$overwrite=false){107 return copy($source, $destination); 108 } 109 110 function move($source, $destination, $overwrite = false) { 188 111 //Possible to use rename()? 189 if( $this->copy($source, $destination,$overwrite) && $this->exists($destination) ){112 if( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ){ 190 113 $this->delete($source); 191 114 return true; … … 195 118 } 196 119 197 function delete($file, $recursive =false){198 $file = str_replace('\\', '/',$file); //for win32, occasional problems deleteing files otherwise120 function delete($file, $recursive = false) { 121 $file = str_replace('\\', '/', $file); //for win32, occasional problems deleteing files otherwise 199 122 200 123 if( $this->is_file($file) ) 201 124 return @unlink($file); 202 if( ! $recursive && $this->is_dir($file) )125 if( ! $recursive && $this->is_dir($file) ) 203 126 return @rmdir($file); 204 127 … … 209 132 $retval = true; 210 133 if( is_array($filelist) ) //false if no files, So check first. 211 foreach($filelist as $filename =>$fileinfo)134 foreach($filelist as $filename => $fileinfo) 212 135 if( ! $this->delete($file . $filename, $recursive) ) 213 136 $retval = false; … … 218 141 } 219 142 220 function exists($file) {143 function exists($file) { 221 144 return @file_exists($file); 222 145 } 223 146 224 function is_file($file) {147 function is_file($file) { 225 148 return @is_file($file); 226 149 } 227 150 228 function is_dir($path) {151 function is_dir($path) { 229 152 return @is_dir($path); 230 153 } 231 154 232 function is_readable($file) {155 function is_readable($file) { 233 156 return @is_readable($file); 234 157 } 235 158 236 function is_writable($file) {159 function is_writable($file) { 237 160 return @is_writable($file); 238 161 } 239 162 240 function atime($file) {163 function atime($file) { 241 164 return @fileatime($file); 242 165 } 243 166 244 function mtime($file) {167 function mtime($file) { 245 168 return @filemtime($file); 246 169 } 247 function size($file) {170 function size($file) { 248 171 return @filesize($file); 249 172 } … … 254 177 if($atime == 0) 255 178 $atime = time(); 256 return @touch($file, $time,$atime);179 return @touch($file, $time, $atime); 257 180 } 258 181 … … 261 184 $chmod = $this->permission; 262 185 263 if( ! @mkdir($path,$chmod) )186 if( ! @mkdir($path, $chmod) ) 264 187 return false; 265 188 if( $chown ) 266 $this->chown($path, $chown);189 $this->chown($path, $chown); 267 190 if( $chgrp ) 268 $this->chgrp($path, $chgrp);269 return true; 270 } 271 272 function rmdir($path, $recursive=false){191 $this->chgrp($path, $chgrp); 192 return true; 193 } 194 195 function rmdir($path, $recursive = false) { 273 196 //Currently unused and untested, Use delete() instead. 274 197 if( ! $recursive ) … … 276 199 //recursive: 277 200 $filelist = $this->dirlist($path); 278 foreach($filelist as $filename =>$det){279 if ( '/' == substr($filename, -1,1) )280 $this->rmdir($path .'/'.$filename,$recursive);201 foreach($filelist as $filename => $det) { 202 if ( '/' == substr($filename, -1, 1) ) 203 $this->rmdir($path . '/' . $filename, $recursive); 281 204 @rmdir($filename); 282 205 } … … 284 207 } 285 208 286 function dirlist($path, $incdot=false,$recursive=false){287 if( $this->is_file($path) ) {209 function dirlist($path, $incdot = false, $recursive = false) { 210 if( $this->is_file($path) ) { 288 211 $limitFile = basename($path); 289 212 $path = dirname($path); … … 296 219 $ret = array(); 297 220 $dir = dir($path); 298 while (false !== ($entry = $dir->read()) ) {221 while (false !== ($entry = $dir->read()) ) { 299 222 $struc = array(); 300 $struc['name'] 223 $struc['name'] = $entry; 301 224 302 225 if( '.' == $struc['name'] || '..' == $struc['name'] ) … … 318 241 $struc['type'] = $this->is_dir($path.'/'.$entry) ? 'd' : 'f'; 319 242 320 if ( 'd' == $struc['type'] ){243 if ( 'd' == $struc['type'] ) { 321 244 if( $recursive ) 322 $struc['files'] = $this->dirlist($path .'/'.$struc['name'], $incdot, $recursive);245 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); 323 246 else 324 247 $struc['files'] = array(); … … 331 254 return $ret; 332 255 } 333 334 function __destruct(){335 return;336 }337 256 } 338 257 ?> -
trunk/wp-admin/includes/class-wp-filesystem-ftpext.php
r7999 r8009 1 1 <?php 2 class WP_Filesystem_FTPext {2 class WP_Filesystem_FTPext extends WP_Filesystem_Base{ 3 3 var $link; 4 4 var $timeout = 5; … … 6 6 var $options = array(); 7 7 8 var $wp_base = '';9 8 var $permission = null; 10 9 … … 25 24 26 25 function WP_Filesystem_FTPext($opt='') { 26 $this->method = 'ftpext'; 27 27 $this->errors = new WP_Error(); 28 28 … … 61 61 } 62 62 63 function connect() {64 if ( $this->options['ssl'] && function_exists('ftp_ssl_connect') ) {63 function connect() { 64 if ( $this->options['ssl'] && function_exists('ftp_ssl_connect') ) 65 65 $this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'],$this->timeout); 66 } else {66 else 67 67 $this->link = @ftp_connect($this->options['hostname'], $this->options['port'],$this->timeout); 68 }69 68 70 69 if ( ! $this->link ) { … … 81 80 } 82 81 83 function setDefaultPermissions($perm) {82 function setDefaultPermissions($perm) { 84 83 $this->permission = $perm; 85 84 } 86 87 function find_base_dir($path = false, $base = '.',$echo = false, $loop = false) {88 if (!$path)89 $path = ABSPATH;90 91 //Sanitize the Windows path formats, This allows easier conparison and aligns it to FTP output.92 $path = str_replace('\\','/',$path); //windows: Straighten up the paths..93 if( strpos($path, ':') ){ //Windows, Strip out the driveletter94 if( preg_match("|.{1}\:(.+)|i", $path, $mat) )95 $path = $mat[1];96 }97 85 98 //Set up the base directory (Which unless specified, is the current one) 99 if( empty( $base ) || '.' == $base ) $base = $this->cwd(); 100 $base = trailingslashit($base); 101 102 //Can we see the Current directory as part of the ABSPATH? 103 $location = strpos($path, $base); 104 if( false !== $location ) { 105 $newbase = path_join($base, substr($path, $location + strlen($base))); 106 107 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. 108 if($echo) printf( __('Changing to %s') . '<br/>', $newbase ); 109 //Check to see if it exists in that folder. 110 if( $this->exists($newbase . 'wp-settings.php') ){ 111 if($echo) printf( __('Found %s'), $newbase . 'wp-settings.php<br/>' ); 112 return $newbase; 113 } 114 } 115 } 116 117 //Ok, Couldnt do a magic location from that particular folder level 118 119 //Get a list of the files in the current directory, See if we can locate where we are in the folder stucture. 120 $files = $this->dirlist($base); 121 122 $arrPath = explode('/', $path); 123 foreach($arrPath as $key){ 124 //Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder, 125 // If its found, change into it and follow through looking for it. 126 // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on. 127 // If it reaches the end, and still cant find it, it'll return false for the entire function. 128 if( isset($files[ $key ]) ){ 129 //Lets try that folder: 130 $folder = path_join($base, $key); 131 if($echo) printf( __('Changing to %s') . '<br/>', $folder ); 132 $ret = $this->find_base_dir( $path, $folder, $echo, $loop); 133 if( $ret ) 134 return $ret; 135 } 136 } 137 //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. 138 if(isset( $files[ 'wp-settings.php' ]) ){ 139 if($echo) printf( __('Found %s'), $base . 'wp-settings.php<br/>' ); 140 return $base; 141 } 142 if( $loop ) 143 return false;//Prevent tihs function looping again. 144 //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. 145 return $this->find_base_dir($path, '/', $echo, true); 146 } 147 148 function get_base_dir($path = false, $base = '.', $echo = false){ 149 if( defined('FTP_BASE') ) 150 $this->wp_base = FTP_BASE; 151 if( empty($this->wp_base) ) 152 $this->wp_base = $this->find_base_dir($path, $base, $echo); 153 return $this->wp_base; 154 } 155 function get_contents($file,$type='',$resumepos=0){ 86 function get_contents($file, $type = '', $resumepos = 0 ){ 156 87 if( empty($type) ){ 157 88 $extension = substr(strrchr($file, "."), 1); … … 161 92 if ( ! $temp ) 162 93 return false; 163 if( ! @ftp_fget($this->link, $temp,$file,$type,$resumepos) )94 if( ! @ftp_fget($this->link, $temp, $file, $type, $resumepos) ) 164 95 return false; 165 96 fseek($temp, 0); //Skip back to the start of the file being written to … … 171 102 return $contents; 172 103 } 173 function get_contents_array($file) {174 return explode("\n", $this->get_contents($file));175 } 176 function put_contents($file, $contents,$type=''){177 if( empty($type) ) {104 function get_contents_array($file) { 105 return explode("\n", $this->get_contents($file)); 106 } 107 function put_contents($file, $contents, $type = '' ) { 108 if( empty($type) ) { 178 109 $extension = substr(strrchr($file, "."), 1); 179 110 $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_ASCII; … … 182 113 if ( ! $temp ) 183 114 return false; 184 fwrite($temp, $contents);115 fwrite($temp, $contents); 185 116 fseek($temp, 0); //Skip back to the start of the file being written to 186 $ret = @ftp_fput($this->link, $file,$temp,$type);117 $ret = @ftp_fput($this->link, $file, $temp, $type); 187 118 fclose($temp); 188 119 return $ret; 189 120 } 190 function cwd() {121 function cwd() { 191 122 $cwd = ftp_pwd($this->link); 192 123 if( $cwd ) … … 194 125 return $cwd; 195 126 } 196 function chdir($dir) {127 function chdir($dir) { 197 128 return @ftp_chdir($dir); 198 129 } 199 function chgrp($file, $group,$recursive=false){200 return false; 201 } 202 function chmod($file, $mode=false,$recursive=false){130 function chgrp($file, $group, $recursive = false ) { 131 return false; 132 } 133 function chmod($file, $mode = false, $recursive = false) { 203 134 if( ! $mode ) 204 135 $mode = $this->permission; … … 207 138 if ( ! $this->exists($file) ) 208 139 return false; 209 if ( ! $recursive || ! $this->is_dir($file) ) {210 if ( !function_exists('ftp_chmod'))140 if ( ! $recursive || ! $this->is_dir($file) ) { 141 if ( ! function_exists('ftp_chmod') ) 211 142 return @ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file)); 212 return @ftp_chmod($this->link, $mode,$file);143 return @ftp_chmod($this->link, $mode, $file); 213 144 } 214 145 //Is a directory, and we want recursive 215 146 $filelist = $this->dirlist($file); 216 147 foreach($filelist as $filename){ 217 $this->chmod($file .'/'.$filename,$mode,$recursive);218 } 219 return true; 220 } 221 function chown($file, $owner,$recursive=false){222 return false; 223 } 224 function owner($file) {148 $this->chmod($file . '/' . $filename, $mode, $recursive); 149 } 150 return true; 151 } 152 function chown($file, $owner, $recursive = false ) { 153 return false; 154 } 155 function owner($file) { 225 156 $dir = $this->dirlist($file); 226 157 return $dir[$file]['owner']; 227 158 } 228 function getchmod($file) {159 function getchmod($file) { 229 160 $dir = $this->dirlist($file); 230 161 return $dir[$file]['permsn']; 231 162 } 232 function gethchmod($file){ 233 //From the PHP.net page for ...? 234 $perms = $this->getchmod($file); 235 if (($perms & 0xC000) == 0xC000) { 236 // Socket 237 $info = 's'; 238 } elseif (($perms & 0xA000) == 0xA000) { 239 // Symbolic Link 240 $info = 'l'; 241 } elseif (($perms & 0x8000) == 0x8000) { 242 // Regular 243 $info = '-'; 244 } elseif (($perms & 0x6000) == 0x6000) { 245 // Block special 246 $info = 'b'; 247 } elseif (($perms & 0x4000) == 0x4000) { 248 // Directory 249 $info = 'd'; 250 } elseif (($perms & 0x2000) == 0x2000) { 251 // Character special 252 $info = 'c'; 253 } elseif (($perms & 0x1000) == 0x1000) { 254 // FIFO pipe 255 $info = 'p'; 256 } else { 257 // Unknown 258 $info = 'u'; 259 } 260 261 // Owner 262 $info .= (($perms & 0x0100) ? 'r' : '-'); 263 $info .= (($perms & 0x0080) ? 'w' : '-'); 264 $info .= (($perms & 0x0040) ? 265 (($perms & 0x0800) ? 's' : 'x' ) : 266 (($perms & 0x0800) ? 'S' : '-')); 267 268 // Group 269 $info .= (($perms & 0x0020) ? 'r' : '-'); 270 $info .= (($perms & 0x0010) ? 'w' : '-'); 271 $info .= (($perms & 0x0008) ? 272 (($perms & 0x0400) ? 's' : 'x' ) : 273 (($perms & 0x0400) ? 'S' : '-')); 274 275 // World 276 $info .= (($perms & 0x0004) ? 'r' : '-'); 277 $info .= (($perms & 0x0002) ? 'w' : '-'); 278 $info .= (($perms & 0x0001) ? 279 (($perms & 0x0200) ? 't' : 'x' ) : 280 (($perms & 0x0200) ? 'T' : '-')); 281 return $info; 282 } 283 function getnumchmodfromh($mode) { 284 $realmode = ""; 285 $legal = array("","w","r","x","-"); 286 $attarray = preg_split("//",$mode); 287 for($i=0;$i<count($attarray);$i++){ 288 if($key = array_search($attarray[$i],$legal)){ 289 $realmode .= $legal[$key]; 290 } 291 } 292 $mode = str_pad($realmode,9,'-'); 293 $trans = array('-'=>'0','r'=>'4','w'=>'2','x'=>'1'); 294 $mode = strtr($mode,$trans); 295 $newmode = ''; 296 $newmode .= $mode[0]+$mode[1]+$mode[2]; 297 $newmode .= $mode[3]+$mode[4]+$mode[5]; 298 $newmode .= $mode[6]+$mode[7]+$mode[8]; 299 return $newmode; 300 } 301 function group($file){ 163 function group($file) { 302 164 $dir = $this->dirlist($file); 303 165 return $dir[$file]['group']; 304 166 } 305 function copy($source, $destination,$overwrite=false){167 function copy($source, $destination, $overwrite = false ) { 306 168 if( ! $overwrite && $this->exists($destination) ) 307 169 return false; … … 309 171 if( false === $content) 310 172 return false; 311 return $this->put_contents($destination, $content);312 } 313 function move($source, $destination,$overwrite=false){314 return ftp_rename($this->link, $source,$destination);173 return $this->put_contents($destination, $content); 174 } 175 function move($source, $destination, $overwrite = false) { 176 return ftp_rename($this->link, $source, $destination); 315 177 } 316 178 317 179 function delete($file,$recursive=false) { 318 180 if ( $this->is_file($file) ) 319 return @ftp_delete($this->link, $file);181 return @ftp_delete($this->link, $file); 320 182 if ( !$recursive ) 321 return @ftp_rmdir($this->link, $file);183 return @ftp_rmdir($this->link, $file); 322 184 $filelist = $this->dirlist($file); 323 185 foreach ((array) $filelist as $filename => $fileinfo) { 324 $this->delete($file .'/'.$filename,$recursive);325 } 326 return @ftp_rmdir($this->link, $file);327 } 328 329 function exists($file) {330 $list = ftp_rawlist($this->link, $file,false);186 $this->delete($file . '/' . $filename, $recursive); 187 } 188 return @ftp_rmdir($this->link, $file); 189 } 190 191 function exists($file) { 192 $list = ftp_rawlist($this->link, $file, false); 331 193 if( ! $list ) 332 194 return false; 333 195 return count($list) == 1 ? true : false; 334 196 } 335 function is_file($file) {197 function is_file($file) { 336 198 return $this->is_dir($file) ? false : true; 337 199 } 338 function is_dir($path) {200 function is_dir($path) { 339 201 $cwd = $this->cwd(); 340 202 $result = @ftp_chdir($this->link, $path); 341 if( $result && $path == $this->cwd() || 342 $this->cwd() != $cwd ) { 203 if( $result && $path == $this->cwd() || $this->cwd() != $cwd ) { 343 204 @ftp_chdir($this->link, $cwd); 344 205 return true; … … 346 207 return false; 347 208 } 348 function is_readable($file) {209 function is_readable($file) { 349 210 //Get dir list, Check if the file is writable by the current user?? 350 211 return true; 351 212 } 352 function is_writable($file) {213 function is_writable($file) { 353 214 //Get dir list, Check if the file is writable by the current user?? 354 215 return true; 355 216 } 356 function atime($file) {357 return false; 358 } 359 function mtime($file) {217 function atime($file) { 218 return false; 219 } 220 function mtime($file) { 360 221 return ftp_mdtm($this->link, $file); 361 222 } 362 function size($file) {223 function size($file) { 363 224 return ftp_size($this->link, $file); 364 225 } 365 function touch($file, $time=0,$atime=0){366 return false; 367 } 368 function mkdir($path, $chmod=false,$chown=false,$chgrp=false){226 function touch($file, $time = 0, $atime = 0) { 227 return false; 228 } 229 function mkdir($path, $chmod = false, $chown = false, $chgrp = false) { 369 230 if( !@ftp_mkdir($this->link, $path) ) 370 231 return false; … … 377 238 return true; 378 239 } 379 function rmdir($path, $recursive=false){240 function rmdir($path, $recursive = false) { 380 241 if( ! $recursive ) 381 242 return @ftp_rmdir($this->link, $path); … … 389 250 function parselisting($line) { 390 251 $is_windows = ($this->OS_remote == FTP_OS_Windows); 391 if ($is_windows && preg_match("/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/", $line,$lucifer)) {252 if ($is_windows && preg_match("/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/", $line, $lucifer)) { 392 253 $b = array(); 393 if ($lucifer[3]<70) { $lucifer[3] +=2000; } else { $lucifer[3]+=1900; } // 4digit year fix254 if ($lucifer[3]<70) { $lucifer[3] +=2000; } else { $lucifer[3]+=1900; } // 4digit year fix 394 255 $b['isdir'] = ($lucifer[7]=="<DIR>"); 395 256 if ( $b['isdir'] ) … … 449 310 } 450 311 451 function dirlist($path ='.',$incdot=false,$recursive=false){452 if( $this->is_file($path) ) {312 function dirlist($path = '.', $incdot = false, $recursive = false) { 313 if( $this->is_file($path) ) { 453 314 $limitFile = basename($path); 454 315 $path = dirname($path) . '/'; … … 457 318 } 458 319 459 $list = @ftp_rawlist($this->link 320 $list = @ftp_rawlist($this->link, '-a ' . $path, false); 460 321 461 322 if ( $list === false ) … … 468 329 continue; 469 330 470 if ( $entry["name"]=="." or $entry["name"]=="..")331 if ( '.' == $entry["name"] || '..' == $entry["name"] ) 471 332 continue; 472 333 473 $dirlist[ $entry['name']] = $entry;334 $dirlist[ $entry['name'] ] = $entry; 474 335 } 475 336 … … 489 350 if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder 490 351 if ($recursive) 491 $struc['files'] = $this->dirlist($path .'/'.$struc['name'],$incdot,$recursive);352 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); 492 353 } 493 354 } else { //No dots 494 355 if ($recursive) 495 $struc['files'] = $this->dirlist($path .'/'.$struc['name'],$incdot,$recursive);356 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); 496 357 } 497 358 } -
trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php
r7999 r8009 6 6 var $options = array(); 7 7 8 var $wp_base = '';9 8 var $permission = null; 10 9 11 10 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_BINARY11 '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 24 23 ); 25 24 26 25 function WP_Filesystem_ftpsockets($opt='') { 26 $this->method = 'ftpsockets'; 27 27 $this->errors = new WP_Error(); 28 28 … … 85 85 function setDefaultPermissions($perm) { 86 86 $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 driveletter96 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 level120 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;156 87 } 157 88 … … 332 263 return false; 333 264 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 ) { 342 273 if ( $this->is_file($file) ) 343 274 return $this->ftp->delete($file); … … 348 279 } 349 280 350 function exists($file) {281 function exists($file) { 351 282 return $this->ftp->is_exists($file); 352 283 } 353 284 354 function is_file($file) {285 function is_file($file) { 355 286 return $this->is_dir($file) ? false : true; 356 287 } 357 288 358 function is_dir($path) {289 function is_dir($path) { 359 290 $cwd = $this->cwd(); 360 291 if ( $this->chdir($path) ) { … … 365 296 } 366 297 367 function is_readable($file) {298 function is_readable($file) { 368 299 //Get dir list, Check if the file is writable by the current user?? 369 300 return true; 370 301 } 371 302 372 function is_writable($file) {303 function is_writable($file) { 373 304 //Get dir list, Check if the file is writable by the current user?? 374 305 return true; 375 306 } 376 307 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) { 382 313 return $this->ftp->mdtm($file); 383 314 } 384 315 385 function size($file) {316 function size($file) { 386 317 return $this->ftp->filesize($file); 387 318 } 388 319 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 ) { 394 325 if( ! $this->ftp->mkdir($path) ) 395 326 return false; … … 403 334 } 404 335 405 function rmdir($path, $recursive=false){336 function rmdir($path, $recursive = false ) { 406 337 if( ! $recursive ) 407 338 return $this->ftp->rmdir($path); … … 410 341 } 411 342 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) ) { 414 345 $limitFile = basename($path); 415 346 $path = dirname($path) . '/'; … … 434 365 if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder 435 366 if ($recursive) 436 $struc['files'] = $this->dirlist($path .'/'.$struc['name'],$incdot,$recursive);367 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); 437 368 } 438 369 } else { //No dots 439 370 if ($recursive) 440 $struc['files'] = $this->dirlist($path .'/'.$struc['name'],$incdot,$recursive);371 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); 441 372 } 442 373 } -
trunk/wp-admin/includes/file.php
r7999 r8009 35 35 function get_real_file_to_edit( $file ) { 36 36 if ('index.php' == $file || '.htaccess' == $file ) { 37 $real_file = get_home_path() .$file;37 $real_file = get_home_path() . $file; 38 38 } else { 39 $real_file = ABSPATH .$file;39 $real_file = ABSPATH . $file; 40 40 } 41 41 … … 257 257 if ( ! $fs->is_dir($to . $tmppath) ) 258 258 if ( !$fs->mkdir($to . $tmppath, 0755) ) 259 return new WP_Error('mkdir_failed', __('Could not create directory') );259 return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $tmppath); 260 260 } 261 261 … … 263 263 if ( ! $file['folder'] ) 264 264 if ( !$fs->put_contents( $to . $file['filename'], $file['content']) ) 265 return new WP_Error('copy_failed', __('Could not copy file') );265 return new WP_Error('copy_failed', __('Could not copy file'), $to . $file['filename']); 266 266 $fs->chmod($to . $file['filename'], 0644); 267 267 } … … 281 281 if ( 'f' == $fileinfo['type'] ) { 282 282 if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true) ) 283 return false;283 return new WP_Error('copy_failed', __('Could not copy file'), $to . $filename); 284 284 $wp_filesystem->chmod($to . $filename, 0644); 285 285 } elseif ( 'd' == $fileinfo['type'] ) { 286 286 if ( !$wp_filesystem->mkdir($to . $filename, 0755) ) 287 return false; 288 if ( !copy_dir($from . $filename, $to . $filename) ) 289 return false; 287 return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $filename); 288 $result = copy_dir($from . $filename, $to . $filename); 289 if ( is_wp_error($result) ) 290 return $result; 290 291 } 291 292 } 292 293 return true;294 293 } 295 294 296 295 function WP_Filesystem( $args = false ) { 297 296 global $wp_filesystem; 297 298 require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); 298 299 299 300 $method = get_filesystem_method(); -
trunk/wp-admin/includes/update.php
r7999 r8009 151 151 152 152 // Is a filesystem accessor setup? 153 if ( ! $wp_filesystem || ! is_object($wp_filesystem) )153 if ( ! $wp_filesystem || ! is_object($wp_filesystem) ) 154 154 WP_Filesystem(); 155 155 … … 161 161 162 162 //Get the base plugin folder 163 $base = $wp_filesystem->get_base_dir(WP_PLUGIN_DIR); 164 165 if ( empty($base) ) 166 return new WP_Error('fs_nowordpress', __('Unable to locate WordPress directory.')); 163 $plugins_dir = $wp_filesystem->wp_plugins_dir(); 164 if ( empty($plugins_dir) ) 165 return new WP_Error('fs_no)plugins_dir', __('Unable to locate WordPress Plugin directory.')); 166 167 //And the same for the Content directory. 168 $content_dir = $wp_filesystem->wp_content_dir(); 169 if( empty($content_dir) ) 170 return new WP_Error('fs_no_content_dor', __('Unable to locate WordPress Content directory (wp-content).')); 171 172 $plugins_dir = trailingslashit( $plugins_dir ); 173 $content_dir = trailingslashit( $content_dir ); 167 174 168 175 // Get the URL to the zip file … … 175 182 $package = $r->package; 176 183 apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package)); 177 $ file = download_url($package);178 179 if ( is_wp_error($ file) )184 $download_file = download_url($package); 185 186 if ( is_wp_error($download_file) ) 180 187 return new WP_Error('download_failed', __('Download failed.'), $file->get_error_message()); 181 188 182 $working_dir = $ wp_filesystem->get_base_dir(WP_CONTENT_DIR) . '/upgrade/' . basename($plugin, '.php');189 $working_dir = $content_dir . 'upgrade/' . basename($plugin, '.php'); 183 190 184 191 // Clean up working directory … … 188 195 apply_filters('update_feedback', __('Unpacking the update')); 189 196 // Unzip package to working directory 190 $result = unzip_file($file, $working_dir); 197 $result = unzip_file($download_file, $working_dir); 198 199 // Once extracted, delete the package 200 unlink($download_file); 201 191 202 if ( is_wp_error($result) ) { 192 unlink($file);193 203 $wp_filesystem->delete($working_dir, true); 194 204 return $result; 195 205 } 196 197 // Once extracted, delete the package198 unlink($file);199 206 200 207 if ( is_plugin_active($plugin) ) { … … 206 213 // Remove the existing plugin. 207 214 apply_filters('update_feedback', __('Removing the old version of the plugin')); 208 $plugin_dir = dirname($base . "/$plugin"); 209 $plugin_dir = trailingslashit($plugin_dir); 215 $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) ); 210 216 211 217 // If plugin is in its own directory, recursively delete the directory. 212 if ( strpos($plugin, '/') && $ plugin_dir != $base . '/') //base check on if plugin includes directory seperator AND that its not the root plugin folder213 $deleted = $wp_filesystem->delete($ plugin_dir, true);218 if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory seperator AND that its not the root plugin folder 219 $deleted = $wp_filesystem->delete($this_plugin_dir, true); 214 220 else 215 $deleted = $wp_filesystem->delete($ base . '/'. $plugin);216 217 if ( ! $deleted ) {221 $deleted = $wp_filesystem->delete($plugins_dir . $plugin); 222 223 if ( ! $deleted ) { 218 224 $wp_filesystem->delete($working_dir, true); 219 225 return new WP_Error('delete_failed', __('Could not remove the old plugin')); … … 222 228 apply_filters('update_feedback', __('Installing the latest version')); 223 229 // Copy new version of plugin into place. 224 if ( !copy_dir($working_dir, $base) ) { 230 $result = copy_dir($working_dir, $plugins_dir); 231 if ( is_wp_error($result) ) { 225 232 //$wp_filesystem->delete($working_dir, true); //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails. 226 return new WP_Error('install_failed', __('Installation failed'));233 return $result; 227 234 } 228 235 … … 237 244 238 245 if( empty($filelist) ) 239 return false; //We couldnt find any files in the working dir 246 return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup. 240 247 241 248 $folder = $filelist[0]; 242 $plugin = get_plugins('/' . $folder); // Pass it with a leading slash, search out the plugins in the folder,249 $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash 243 250 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list 244 251 245 return $folder . '/' . $pluginfiles[0]; //Pass it without a leading slash as WP requires252 return $folder . '/' . $pluginfiles[0]; 246 253 } 247 254 -
trunk/wp-admin/update.php
r7999 r8009 111 111 } 112 112 113 $was_activated = is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is ,113 $was_activated = is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is 114 114 115 115 $result = wp_update_plugin($plugin, 'show_message'); … … 117 117 if ( is_wp_error($result) ) { 118 118 show_message($result); 119 show_message( __('Installation Failed') ); 119 120 } else { 120 121 //Result is the new plugin file relative to WP_PLUGIN_DIR 121 show_message( __('Plugin upgraded successfully'));122 show_message( __('Plugin upgraded successfully') ); 122 123 if( $result && $was_activated ){ 123 124 show_message(__('Attempting reactivation of the plugin'));
Note: See TracChangeset
for help on using the changeset viewer.