Ticket #7059: 7059.diff
| File 7059.diff, 52.4 KB (added by , 18 years ago) |
|---|
-
wp-admin/includes/class-wp-filesystem-base.php
1 <?php 2 class WP_Filesystem_Base{ 3 var $verbose = true; 4 var $cache = array(); 5 6 var $method = ''; 7 8 function abspath() { 9 if ( defined('FTP_BASE') && strpos($this->method, 'ftp') !== false ) 10 return FTP_BASE; 11 return $this->find_folder(ABSPATH); 12 } 13 function wp_content_dir() { 14 if ( defined('FTP_CONTENT_DIR') && strpos($this->method, 'ftp') !== false ) 15 return FTP_CONTENT_DIR; 16 return $this->find_folder(WP_CONTENT_DIR); 17 } 18 function wp_plugins_dir() { 19 if ( defined('FTP_PLUGIN_DIR') && strpos($this->method, 'ftp') !== false ) 20 return FTP_PLUGIN_DIR; 21 return $this->find_folder(WP_PLUGIN_DIR); 22 } 23 function wp_themes_dir() { 24 return $this->wp_content_dir() . '/themes'; 25 } 26 //Back compat: use abspath() or wp_*_dir 27 function find_base_dir($base = '.', $echo = false) { 28 $this->verbose = $echo; 29 return $this->abspath(); 30 } 31 //Back compat: use ::abspath() or ::wp_*_dir 32 function get_base_dir($base = '.', $echo = false) { 33 $this->verbose = $echo; 34 return $this->abspath(); 35 } 36 37 function find_folder($folder) { 38 $folder = str_replace('\\', '/', $folder); //Windows Sanitiation 39 if ( isset($this->cache[ $folder ] ) ) 40 return $this->cache[ $folder ]; 41 42 if ( $this->exists($folder) ) { //Folder exists at that absolute path. 43 $this->cache[ $folder ] = $folder; 44 return $folder; 45 } 46 if( $return = $this->search_for_folder($folder) ) 47 $this->cache[ $folder ] = $return; 48 return $return; 49 } 50 51 // Assumes $folder is windows sanitized; 52 // Assumes that the drive letter is safe to be stripped off, Should not be a problem for windows servers. 53 function search_for_folder($folder, $base = '.', $loop = false ) { 54 if ( empty( $base ) || '.' == $base ) 55 $base = trailingslashit($this->cwd()); 56 57 $folder = preg_replace('|^([a-z]{1}):|i', '', $folder); //Strip out windows driveletter if its there. 58 59 $folder_parts = explode('/', $folder); 60 $last_path = $folder_parts[ count($folder_parts) - 1 ]; 61 62 $files = $this->dirlist( $base ); 63 64 foreach ( $folder_parts as $key ) { 65 if ( $key == $last_path ) 66 continue; //We want this to be caught by the next code block. 67 68 //Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder, 69 // If its found, change into it and follow through looking for it. 70 // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on. 71 // If it reaches the end, and still cant find it, it'll return false for the entire function. 72 if( isset($files[ $key ]) ){ 73 //Lets try that folder: 74 $newdir = trailingslashit(path_join($base, $key)); 75 if( $this->verbose ) 76 printf( __('Changing to %s') . '<br/>', $newdir ); 77 if( $ret = $this->search_for_folder( $folder, $newdir, $loop) ) 78 return $ret; 79 } 80 } 81 82 //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. 83 if(isset( $files[ $last_path ] ) ) { 84 if( $this->verbose ) 85 printf( __('Found %s') . '<br/>', $base . $last_path ); 86 return $base . $last_path; 87 } 88 if( $loop ) 89 return false;//Prevent tihs function looping again. 90 //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. 91 return $this->search_for_folder($folder, '/', true); 92 93 } 94 95 //Common Helper functions. 96 function gethchmod($file){ 97 //From the PHP.net page for ...? 98 $perms = $this->getchmod($file); 99 if (($perms & 0xC000) == 0xC000) // Socket 100 $info = 's'; 101 elseif (($perms & 0xA000) == 0xA000) // Symbolic Link 102 $info = 'l'; 103 elseif (($perms & 0x8000) == 0x8000) // Regular 104 $info = '-'; 105 elseif (($perms & 0x6000) == 0x6000) // Block special 106 $info = 'b'; 107 elseif (($perms & 0x4000) == 0x4000) // Directory 108 $info = 'd'; 109 elseif (($perms & 0x2000) == 0x2000) // Character special 110 $info = 'c'; 111 elseif (($perms & 0x1000) == 0x1000)// FIFO pipe 112 $info = 'p'; 113 else // Unknown 114 $info = 'u'; 115 116 // Owner 117 $info .= (($perms & 0x0100) ? 'r' : '-'); 118 $info .= (($perms & 0x0080) ? 'w' : '-'); 119 $info .= (($perms & 0x0040) ? 120 (($perms & 0x0800) ? 's' : 'x' ) : 121 (($perms & 0x0800) ? 'S' : '-')); 122 123 // Group 124 $info .= (($perms & 0x0020) ? 'r' : '-'); 125 $info .= (($perms & 0x0010) ? 'w' : '-'); 126 $info .= (($perms & 0x0008) ? 127 (($perms & 0x0400) ? 's' : 'x' ) : 128 (($perms & 0x0400) ? 'S' : '-')); 129 130 // World 131 $info .= (($perms & 0x0004) ? 'r' : '-'); 132 $info .= (($perms & 0x0002) ? 'w' : '-'); 133 $info .= (($perms & 0x0001) ? 134 (($perms & 0x0200) ? 't' : 'x' ) : 135 (($perms & 0x0200) ? 'T' : '-')); 136 return $info; 137 } 138 function getnumchmodfromh($mode) { 139 $realmode = ""; 140 $legal = array("", "w", "r", "x", "-"); 141 $attarray = preg_split("//", $mode); 142 143 for($i=0; $i < count($attarray); $i++) 144 if($key = array_search($attarray[$i], $legal)) 145 $realmode .= $legal[$key]; 146 147 $mode = str_pad($realmode, 9, '-'); 148 $trans = array('-'=>'0', 'r'=>'4', 'w'=>'2', 'x'=>'1'); 149 $mode = strtr($mode,$trans); 150 151 $newmode = ''; 152 $newmode .= $mode[0] + $mode[1] + $mode[2]; 153 $newmode .= $mode[3] + $mode[4] + $mode[5]; 154 $newmode .= $mode[6] + $mode[7] + $mode[8]; 155 return $newmode; 156 } 157 } 158 ?> 159 No newline at end of file -
wp-admin/includes/class-wp-filesystem-direct.php
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 $this->method = 'direct'; 7 8 $this->errors = new WP_Error(); 8 9 $this->permission = umask(); 9 10 } 10 function connect() {11 function connect() { 11 12 return true; 12 13 } 13 function setDefaultPermissions($perm) {14 function setDefaultPermissions($perm) { 14 15 $this->permission = $perm; 15 16 } 16 function find_base_dir($base = '.', $echo = false){17 return str_replace('\\','/',ABSPATH);18 }19 function get_base_dir($base = '.', $echo = false){20 return $this->find_base_dir($base, $echo);21 }22 17 function get_contents($file){ 23 18 return @file_get_contents($file); 24 19 } 25 function get_contents_array($file) {20 function get_contents_array($file) { 26 21 return @file($file); 27 22 } 28 function put_contents($file,$contents,$mode=false,$type='') {29 if ( ! ($fp = @fopen($file, 'w'.$type)) )23 function put_contents($file,$contents,$mode=false,$type='') { 24 if ( ! ($fp = @fopen($file, 'w' . $type)) ) 30 25 return false; 31 26 @fwrite($fp,$contents); 32 27 @fclose($fp); … … 36 31 function cwd(){ 37 32 return @getcwd(); 38 33 } 39 function chdir($dir) {34 function chdir($dir) { 40 35 return @chdir($dir); 41 36 } 42 function chgrp($file,$group,$recursive=false) {37 function chgrp($file,$group,$recursive=false) { 43 38 if( ! $this->exists($file) ) 44 39 return false; 45 40 if( ! $recursive ) 46 return @chgrp($file, $group);41 return @chgrp($file, $group); 47 42 if( ! $this->is_dir($file) ) 48 return @chgrp($file, $group);43 return @chgrp($file, $group); 49 44 //Is a directory, and we want recursive 50 45 $file = trailingslashit($file); 51 46 $filelist = $this->dirlist($file); … … 54 49 55 50 return true; 56 51 } 57 function chmod($file,$mode=false,$recursive=false) {52 function chmod($file,$mode=false,$recursive=false) { 58 53 if( ! $mode ) 59 54 $mode = $this->permission; 60 55 if( ! $this->exists($file) ) … … 62 57 if( ! $recursive ) 63 58 return @chmod($file,$mode); 64 59 if( ! $this->is_dir($file) ) 65 return @chmod($file, $mode);60 return @chmod($file, $mode); 66 61 //Is a directory, and we want recursive 67 62 $file = trailingslashit($file); 68 63 $filelist = $this->dirlist($file); … … 71 66 72 67 return true; 73 68 } 74 function chown($file, $owner,$recursive=false){69 function chown($file, $owner, $recursive = false) { 75 70 if( ! $this->exists($file) ) 76 71 return false; 77 72 if( ! $recursive ) 78 return @chown($file, $owner);73 return @chown($file, $owner); 79 74 if( ! $this->is_dir($file) ) 80 return @chown($file, $owner);75 return @chown($file, $owner); 81 76 //Is a directory, and we want recursive 82 77 $filelist = $this->dirlist($file); 83 78 foreach($filelist as $filename){ 84 $this->chown($file .'/'.$filename,$owner,$recursive);79 $this->chown($file . '/' . $filename, $owner, $recursive); 85 80 } 86 81 return true; 87 82 } 88 function owner($file) {83 function owner($file) { 89 84 $owneruid = @fileowner($file); 90 85 if( ! $owneruid ) 91 86 return false; 92 if( ! function_exists('posix_getpwuid') )87 if( ! function_exists('posix_getpwuid') ) 93 88 return $owneruid; 94 89 $ownerarray = posix_getpwuid($owneruid); 95 90 return $ownerarray['name']; 96 91 } 97 function getchmod($file) {92 function getchmod($file) { 98 93 return @fileperms($file); 99 94 } 100 function gethchmod($file){ 101 //From the PHP.net page for ...? 102 $perms = $this->getchmod($file); 103 if (($perms & 0xC000) == 0xC000) { 104 // Socket 105 $info = 's'; 106 } elseif (($perms & 0xA000) == 0xA000) { 107 // Symbolic Link 108 $info = 'l'; 109 } elseif (($perms & 0x8000) == 0x8000) { 110 // Regular 111 $info = '-'; 112 } elseif (($perms & 0x6000) == 0x6000) { 113 // Block special 114 $info = 'b'; 115 } elseif (($perms & 0x4000) == 0x4000) { 116 // Directory 117 $info = 'd'; 118 } elseif (($perms & 0x2000) == 0x2000) { 119 // Character special 120 $info = 'c'; 121 } elseif (($perms & 0x1000) == 0x1000) { 122 // FIFO pipe 123 $info = 'p'; 124 } else { 125 // Unknown 126 $info = 'u'; 127 } 128 129 // Owner 130 $info .= (($perms & 0x0100) ? 'r' : '-'); 131 $info .= (($perms & 0x0080) ? 'w' : '-'); 132 $info .= (($perms & 0x0040) ? 133 (($perms & 0x0800) ? 's' : 'x' ) : 134 (($perms & 0x0800) ? 'S' : '-')); 135 136 // Group 137 $info .= (($perms & 0x0020) ? 'r' : '-'); 138 $info .= (($perms & 0x0010) ? 'w' : '-'); 139 $info .= (($perms & 0x0008) ? 140 (($perms & 0x0400) ? 's' : 'x' ) : 141 (($perms & 0x0400) ? 'S' : '-')); 142 143 // World 144 $info .= (($perms & 0x0004) ? 'r' : '-'); 145 $info .= (($perms & 0x0002) ? 'w' : '-'); 146 $info .= (($perms & 0x0001) ? 147 (($perms & 0x0200) ? 't' : 'x' ) : 148 (($perms & 0x0200) ? 'T' : '-')); 149 return $info; 150 } 151 function getnumchmodfromh($mode) { 152 $realmode = ""; 153 $legal = array("","w","r","x","-"); 154 $attarray = preg_split("//",$mode); 155 for($i=0;$i<count($attarray);$i++){ 156 if($key = array_search($attarray[$i],$legal)){ 157 $realmode .= $legal[$key]; 158 } 159 } 160 $mode = str_pad($realmode,9,'-'); 161 $trans = array('-'=>'0','r'=>'4','w'=>'2','x'=>'1'); 162 $mode = strtr($mode,$trans); 163 $newmode = ''; 164 $newmode .= $mode[0]+$mode[1]+$mode[2]; 165 $newmode .= $mode[3]+$mode[4]+$mode[5]; 166 $newmode .= $mode[6]+$mode[7]+$mode[8]; 167 return $newmode; 168 } 169 function group($file){ 95 function group($file) { 170 96 $gid = @filegroup($file); 171 97 if( ! $gid ) 172 98 return false; 173 if( ! function_exists('posix_getgrgid') )99 if( ! function_exists('posix_getgrgid') ) 174 100 return $gid; 175 101 $grouparray = posix_getgrgid($gid); 176 102 return $grouparray['name']; 177 103 } 178 104 179 function copy($source, $destination,$overwrite=false){105 function copy($source, $destination, $overwrite = false) { 180 106 if( ! $overwrite && $this->exists($destination) ) 181 107 return false; 182 return copy($source, $destination);108 return copy($source, $destination); 183 109 } 184 110 185 function move($source, $destination,$overwrite=false){111 function move($source, $destination, $overwrite = false) { 186 112 //Possible to use rename()? 187 if( $this->copy($source, $destination,$overwrite) && $this->exists($destination) ){113 if( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ){ 188 114 $this->delete($source); 189 115 return true; 190 116 } else { … … 192 118 } 193 119 } 194 120 195 function delete($file, $recursive =false){196 $file = str_replace('\\', '/',$file); //for win32, occasional problems deleteing files otherwise121 function delete($file, $recursive = false) { 122 $file = str_replace('\\', '/', $file); //for win32, occasional problems deleteing files otherwise 197 123 198 124 if( $this->is_file($file) ) 199 125 return @unlink($file); 200 if( ! $recursive && $this->is_dir($file) )126 if( ! $recursive && $this->is_dir($file) ) 201 127 return @rmdir($file); 202 128 203 129 //At this point its a folder, and we're in recursive mode … … 206 132 207 133 $retval = true; 208 134 if( is_array($filelist) ) //false if no files, So check first. 209 foreach($filelist as $filename =>$fileinfo)135 foreach($filelist as $filename => $fileinfo) 210 136 if( ! $this->delete($file . $filename, $recursive) ) 211 137 $retval = false; 212 138 … … 215 141 return $retval; 216 142 } 217 143 218 function exists($file) {144 function exists($file) { 219 145 return @file_exists($file); 220 146 } 221 147 222 function is_file($file) {148 function is_file($file) { 223 149 return @is_file($file); 224 150 } 225 151 226 function is_dir($path) {152 function is_dir($path) { 227 153 return @is_dir($path); 228 154 } 229 155 230 function is_readable($file) {156 function is_readable($file) { 231 157 return @is_readable($file); 232 158 } 233 159 234 function is_writable($file) {160 function is_writable($file) { 235 161 return @is_writable($file); 236 162 } 237 163 238 function atime($file) {164 function atime($file) { 239 165 return @fileatime($file); 240 166 } 241 167 242 function mtime($file) {168 function mtime($file) { 243 169 return @filemtime($file); 244 170 } 245 function size($file) {171 function size($file) { 246 172 return @filesize($file); 247 173 } 248 174 … … 251 177 $time = time(); 252 178 if($atime == 0) 253 179 $atime = time(); 254 return @touch($file, $time,$atime);180 return @touch($file, $time, $atime); 255 181 } 256 182 257 183 function mkdir($path, $chmod = false, $chown = false, $chgrp = false){ 258 184 if( ! $chmod) 259 185 $chmod = $this->permission; 260 186 261 if( ! @mkdir($path,$chmod) )187 if( ! @mkdir($path, $chmod) ) 262 188 return false; 263 189 if( $chown ) 264 $this->chown($path, $chown);190 $this->chown($path, $chown); 265 191 if( $chgrp ) 266 $this->chgrp($path, $chgrp);192 $this->chgrp($path, $chgrp); 267 193 return true; 268 194 } 269 195 270 function rmdir($path, $recursive=false){196 function rmdir($path, $recursive = false) { 271 197 //Currently unused and untested, Use delete() instead. 272 198 if( ! $recursive ) 273 199 return @rmdir($path); 274 200 //recursive: 275 201 $filelist = $this->dirlist($path); 276 foreach($filelist as $filename =>$det){277 if ( '/' == substr($filename, -1,1) )278 $this->rmdir($path .'/'.$filename,$recursive);202 foreach($filelist as $filename => $det) { 203 if ( '/' == substr($filename, -1, 1) ) 204 $this->rmdir($path . '/' . $filename, $recursive); 279 205 @rmdir($filename); 280 206 } 281 207 return @rmdir($path); 282 208 } 283 209 284 function dirlist($path, $incdot=false,$recursive=false){285 if( $this->is_file($path) ) {210 function dirlist($path, $incdot = false, $recursive = false) { 211 if( $this->is_file($path) ) { 286 212 $limitFile = basename($path); 287 213 $path = dirname($path); 288 214 } else { … … 293 219 294 220 $ret = array(); 295 221 $dir = dir($path); 296 while (false !== ($entry = $dir->read()) ) {222 while (false !== ($entry = $dir->read()) ) { 297 223 $struc = array(); 298 $struc['name'] = $entry;224 $struc['name'] = $entry; 299 225 300 226 if( '.' == $struc['name'] || '..' == $struc['name'] ) 301 227 continue; //Do not care about these folders. … … 315 241 $struc['time'] = date('h:i:s',$struc['lastmodunix']); 316 242 $struc['type'] = $this->is_dir($path.'/'.$entry) ? 'd' : 'f'; 317 243 318 if ( 'd' == $struc['type'] ){244 if ( 'd' == $struc['type'] ) { 319 245 if( $recursive ) 320 $struc['files'] = $this->dirlist($path .'/'.$struc['name'], $incdot, $recursive);246 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); 321 247 else 322 248 $struc['files'] = array(); 323 249 } … … 328 254 unset($dir); 329 255 return $ret; 330 256 } 331 332 function __destruct(){333 return;334 }335 257 } 336 258 ?> -
wp-admin/includes/class-wp-filesystem-ftpext.php
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; 5 5 var $errors = array(); 6 6 var $options = array(); 7 7 8 var $wp_base = '';9 8 var $permission = null; 10 9 11 10 var $filetypes = array( … … 24 23 ); 25 24 26 25 function WP_Filesystem_FTPext($opt='') { 26 $this->method = 'ftpext'; 27 27 $this->errors = new WP_Error(); 28 28 29 29 //Check if possible to use ftp functions. … … 60 60 $this->options['ssl'] = ( !empty($opt['ssl']) ); 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 ) { 71 70 $this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port'])); … … 80 79 return true; 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); 158 89 $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_ASCII; … … 160 91 $temp = tmpfile(); 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 166 97 $contents = ''; … … 170 101 fclose($temp); 171 102 return $contents; 172 103 } 173 function get_contents_array($file) {174 return explode("\n", $this->get_contents($file));104 function get_contents_array($file) { 105 return explode("\n", $this->get_contents($file)); 175 106 } 176 function put_contents($file, $contents,$type=''){177 if( empty($type) ) {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; 180 111 } 181 112 $temp = tmpfile(); 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 ) 193 124 $cwd = trailingslashit($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){130 function chgrp($file, $group, $recursive = false ) { 200 131 return false; 201 132 } 202 function chmod($file, $mode=false,$recursive=false){133 function chmod($file, $mode = false, $recursive = false) { 203 134 if( ! $mode ) 204 135 $mode = $this->permission; 205 136 if( ! $mode ) 206 137 return false; 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);148 $this->chmod($file . '/' . $filename, $mode, $recursive); 218 149 } 219 150 return true; 220 151 } 221 function chown($file, $owner,$recursive=false){152 function chown($file, $owner, $recursive = false ) { 222 153 return false; 223 154 } 224 function owner($file) {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; 308 170 $content = $this->get_contents($source); 309 171 if( false === $content) 310 172 return false; 311 return $this->put_contents($destination, $content);173 return $this->put_contents($destination, $content); 312 174 } 313 function move($source, $destination,$overwrite=false){314 return ftp_rename($this->link, $source,$destination);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);186 $this->delete($file . '/' . $filename, $recursive); 325 187 } 326 return @ftp_rmdir($this->link, $file);188 return @ftp_rmdir($this->link, $file); 327 189 } 328 190 329 function exists($file) {330 $list = ftp_rawlist($this->link, $file,false);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; 345 206 } 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) {217 function atime($file) { 357 218 return false; 358 219 } 359 function mtime($file) {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){226 function touch($file, $time = 0, $atime = 0) { 366 227 return false; 367 228 } 368 function mkdir($path, $chmod=false,$chown=false,$chgrp=false){229 function mkdir($path, $chmod = false, $chown = false, $chgrp = false) { 369 230 if( !@ftp_mkdir($this->link, $path) ) 370 231 return false; 371 232 if( $chmod ) … … 376 237 $this->chgrp($path, $chgrp); 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); 382 243 … … 388 249 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'] ) 396 257 $b['type'] = 'd'; … … 448 309 return $b; 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) . '/'; 455 316 } else { 456 317 $limitFile = false; 457 318 } 458 319 459 $list = @ftp_rawlist($this->link , '-a ' . $path, false);320 $list = @ftp_rawlist($this->link, '-a ' . $path, false); 460 321 461 322 if ( $list === false ) 462 323 return false; … … 467 328 if ( empty($entry) ) 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 476 337 if ( ! $dirlist ) … … 488 349 //We're including the doted starts 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 } 498 359 //File -
wp-admin/includes/class-wp-filesystem-ftpsockets.php
5 5 var $errors; 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,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, 19 18 20 'jpg' =>FTP_BINARY,21 'png' =>FTP_BINARY,22 'gif' =>FTP_BINARY,23 'bmp' =>FTP_BINARY19 '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 29 29 //Check if possible to use ftp functions. … … 86 86 $this->permission = $perm; 87 87 } 88 88 89 function find_base_dir($base = '.',$echo = false, $loop = false) {90 //Sanitize the Windows path formats, This allows easier conparison and aligns it to FTP output.91 $abspath = str_replace('\\','/',ABSPATH); //windows: Straighten up the paths..92 if( strpos($abspath, ':') ){ //Windows, Strip out the driveletter93 if( preg_match("|.{1}\:(.+)|i", $abspath, $mat) )94 $abspath = $mat[1];95 }96 97 //Set up the base directory (Which unless specified, is the current one)98 if( empty( $base ) || '.' == $base ) $base = $this->cwd();99 $base = trailingslashit($base);100 101 //Can we see the Current directory as part of the ABSPATH?102 $location = strpos($abspath, $base);103 if( false !== $location ) {104 $newbase = path_join($base, substr($abspath, $location + strlen($base)));105 106 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.107 if($echo) printf( __('Changing to %s') . '<br/>', $newbase );108 //Check to see if it exists in that folder.109 if( $this->exists($newbase . 'wp-settings.php') ){110 if($echo) printf( __('Found %s'), $newbase . 'wp-settings.php<br/>' );111 return $newbase;112 }113 }114 }115 116 //Ok, Couldnt do a magic location from that particular folder level117 118 //Get a list of the files in the current directory, See if we can locate where we are in the folder stucture.119 $files = $this->dirlist($base);120 121 $arrPath = explode('/', $abspath);122 foreach($arrPath as $key){123 //Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,124 // If its found, change into it and follow through looking for it.125 // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on.126 // If it reaches the end, and still cant find it, it'll return false for the entire function.127 if( isset($files[ $key ]) ){128 //Lets try that folder:129 $folder = path_join($base, $key);130 if($echo) printf( __('Changing to %s') . '<br/>', $folder );131 $ret = $this->find_base_dir( $folder, $echo, $loop);132 if( $ret )133 return $ret;134 }135 }136 //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.137 if(isset( $files[ 'wp-settings.php' ]) ){138 if($echo) printf( __('Found %s'), $base . 'wp-settings.php<br/>' );139 return $base;140 }141 if( $loop )142 return false;//Prevent tihs function looping again.143 //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.144 return $this->find_base_dir('/', $echo, true);145 }146 147 function get_base_dir($base = '.', $echo = false){148 if( defined('FTP_BASE') )149 $this->wp_base = FTP_BASE;150 if( empty($this->wp_base) )151 $this->wp_base = $this->find_base_dir($base, $echo);152 return $this->wp_base;153 }154 155 89 function get_contents($file,$type='',$resumepos=0){ 156 90 if( ! $this->exists($file) ) 157 91 return false; 158 92 159 93 if( empty($type) ){ 160 $extension = substr(strrchr($file, "."), 1);94 $extension = substr(strrchr($file, '.'), 1); 161 95 $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_AUTOASCII; 162 96 } 163 97 $this->ftp->SetType($type); 164 $temp = tmpfile();165 if ( ! $temp)98 $temp = wp_tempnam( $file ); 99 if ( ! @fopen($temp) ) 166 100 return false; 167 101 if ( ! $this->ftp->fget($temp, $file) ) { 168 102 fclose($temp); 103 unlink($temp); 169 104 return ''; //Blank document, File does exist, Its just blank. 170 105 } 171 106 fseek($temp, 0); //Skip back to the start of the file being written to 172 107 $contents = ''; 173 while ( ! feof($temp) )108 while ( ! feof($temp) ) 174 109 $contents .= fread($temp, 8192); 175 110 fclose($temp); 111 unlink($temp); 176 112 return $contents; 177 113 } 178 114 179 115 function get_contents_array($file){ 180 return explode("\n", $this->get_contents($file));116 return explode("\n", $this->get_contents($file) ); 181 117 } 182 118 183 function put_contents($file, $contents,$type=''){119 function put_contents($file, $contents, $type = '' ) { 184 120 if( empty($type) ){ 185 $extension = substr(strrchr($file, "."), 1);186 $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_A SCII;121 $extension = substr(strrchr($file, '.'), 1); 122 $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_AUTOASCII; 187 123 } 188 124 $this->ftp->SetType($type); 189 125 190 $temp = tmpfile();191 if ( ! $temp)126 $temp = wp_tempnam( $file ); 127 if ( ! @fopen($temp) ) 192 128 return false; 193 fwrite($temp, $contents);129 fwrite($temp, $contents); 194 130 fseek($temp, 0); //Skip back to the start of the file being written to 195 131 $ret = $this->ftp->fput($file, $temp); 196 132 fclose($temp); 133 unlink($temp); 197 134 return $ret; 198 135 } 199 136 200 function cwd() {137 function cwd() { 201 138 $cwd = $this->ftp->pwd(); 202 139 if( $cwd ) 203 140 $cwd = trailingslashit($cwd); 204 141 return $cwd; 205 142 } 206 143 207 function chdir($file) {144 function chdir($file) { 208 145 return $this->ftp->chdir($file); 209 146 } 210 147 211 function chgrp($file, $group,$recursive=false){148 function chgrp($file, $group, $recursive = false ) { 212 149 return false; 213 150 } 214 151 215 function chmod($file, $mode=false,$recursive=false){152 function chmod($file, $mode = false, $recursive = false ){ 216 153 if( ! $mode ) 217 154 $mode = $this->permission; 218 155 if( ! $mode ) 219 156 return false; 220 157 //if( ! $this->exists($file) ) 221 158 // return false; 222 if( ! $recursive || ! $this->is_dir($file) ) {159 if( ! $recursive || ! $this->is_dir($file) ) { 223 160 return $this->ftp->chmod($file,$mode); 224 161 } 225 162 //Is a directory, and we want recursive 226 163 $filelist = $this->dirlist($file); 227 164 foreach($filelist as $filename){ 228 $this->chmod($file .'/'.$filename,$mode,$recursive);165 $this->chmod($file . '/' . $filename, $mode, $recursive); 229 166 } 230 167 return true; 231 168 } 232 169 233 function chown($file, $owner,$recursive=false){170 function chown($file, $owner, $recursive = false ) { 234 171 return false; 235 172 } 236 173 237 function owner($file) {174 function owner($file) { 238 175 $dir = $this->dirlist($file); 239 176 return $dir[$file]['owner']; 240 177 } 241 178 242 function getchmod($file) {179 function getchmod($file) { 243 180 $dir = $this->dirlist($file); 244 181 return $dir[$file]['permsn']; 245 182 } 246 183 247 function gethchmod($file){ 248 //From the PHP.net page for ...? 249 $perms = $this->getchmod($file); 250 if (($perms & 0xC000) == 0xC000) { 251 // Socket 252 $info = 's'; 253 } elseif (($perms & 0xA000) == 0xA000) { 254 // Symbolic Link 255 $info = 'l'; 256 } elseif (($perms & 0x8000) == 0x8000) { 257 // Regular 258 $info = '-'; 259 } elseif (($perms & 0x6000) == 0x6000) { 260 // Block special 261 $info = 'b'; 262 } elseif (($perms & 0x4000) == 0x4000) { 263 // Directory 264 $info = 'd'; 265 } elseif (($perms & 0x2000) == 0x2000) { 266 // Character special 267 $info = 'c'; 268 } elseif (($perms & 0x1000) == 0x1000) { 269 // FIFO pipe 270 $info = 'p'; 271 } else { 272 // Unknown 273 $info = 'u'; 274 } 275 276 // Owner 277 $info .= (($perms & 0x0100) ? 'r' : '-'); 278 $info .= (($perms & 0x0080) ? 'w' : '-'); 279 $info .= (($perms & 0x0040) ? 280 (($perms & 0x0800) ? 's' : 'x' ) : 281 (($perms & 0x0800) ? 'S' : '-')); 282 283 // Group 284 $info .= (($perms & 0x0020) ? 'r' : '-'); 285 $info .= (($perms & 0x0010) ? 'w' : '-'); 286 $info .= (($perms & 0x0008) ? 287 (($perms & 0x0400) ? 's' : 'x' ) : 288 (($perms & 0x0400) ? 'S' : '-')); 289 290 // World 291 $info .= (($perms & 0x0004) ? 'r' : '-'); 292 $info .= (($perms & 0x0002) ? 'w' : '-'); 293 $info .= (($perms & 0x0001) ? 294 (($perms & 0x0200) ? 't' : 'x' ) : 295 (($perms & 0x0200) ? 'T' : '-')); 296 return $info; 297 } 298 299 function getnumchmodfromh($mode) { 300 $realmode = ""; 301 $legal = array("","w","r","x","-"); 302 $attarray = preg_split("//",$mode); 303 for($i=0;$i<count($attarray);$i++){ 304 if($key = array_search($attarray[$i],$legal)){ 305 $realmode .= $legal[$key]; 306 } 307 } 308 $mode = str_pad($realmode,9,'-'); 309 $trans = array('-'=>'0','r'=>'4','w'=>'2','x'=>'1'); 310 $mode = strtr($mode,$trans); 311 $newmode = ''; 312 $newmode .= $mode[0]+$mode[1]+$mode[2]; 313 $newmode .= $mode[3]+$mode[4]+$mode[5]; 314 $newmode .= $mode[6]+$mode[7]+$mode[8]; 315 return $newmode; 316 } 317 318 function group($file){ 184 function group($file) { 319 185 $dir = $this->dirlist($file); 320 186 return $dir[$file]['group']; 321 187 } 322 188 323 function copy($source, $destination,$overwrite=false){189 function copy($source, $destination, $overwrite = false ) { 324 190 if( ! $overwrite && $this->exists($destination) ) 325 191 return false; 326 192 … … 328 194 if ( false === $content ) 329 195 return false; 330 196 331 return $this->put_contents($destination, $content);197 return $this->put_contents($destination, $content); 332 198 } 333 199 334 function move($source, $destination,$overwrite=false){335 return $this->ftp->rename($source, $destination);200 function move($source, $destination, $overwrite = false ) { 201 return $this->ftp->rename($source, $destination); 336 202 } 337 203 338 function delete($file, $recursive=false) {204 function delete($file, $recursive = false ) { 339 205 if ( $this->is_file($file) ) 340 206 return $this->ftp->delete($file); 341 207 if ( !$recursive ) … … 344 210 return $this->ftp->mdel($file); 345 211 } 346 212 347 function exists($file) {213 function exists($file) { 348 214 return $this->ftp->is_exists($file); 349 215 } 350 216 351 function is_file($file) {217 function is_file($file) { 352 218 return $this->is_dir($file) ? false : true; 353 219 } 354 220 355 function is_dir($path) {221 function is_dir($path) { 356 222 $cwd = $this->cwd(); 357 223 if ( $this->chdir($path) ) { 358 224 $this->chdir($cwd); … … 361 227 return false; 362 228 } 363 229 364 function is_readable($file) {230 function is_readable($file) { 365 231 //Get dir list, Check if the file is writable by the current user?? 366 232 return true; 367 233 } 368 234 369 function is_writable($file) {235 function is_writable($file) { 370 236 //Get dir list, Check if the file is writable by the current user?? 371 237 return true; 372 238 } 373 239 374 function atime($file) {240 function atime($file) { 375 241 return false; 376 242 } 377 243 378 function mtime($file) {244 function mtime($file) { 379 245 return $this->ftp->mdtm($file); 380 246 } 381 247 382 function size($file) {248 function size($file) { 383 249 return $this->ftp->filesize($file); 384 250 } 385 251 386 function touch($file, $time=0,$atime=0){252 function touch($file, $time = 0, $atime = 0 ){ 387 253 return false; 388 254 } 389 255 390 function mkdir($path, $chmod=false,$chown=false,$chgrp=false){256 function mkdir($path, $chmod = false, $chown = false, $chgrp = false ) { 391 257 if( ! $this->ftp->mkdir($path) ) 392 258 return false; 393 259 if( $chmod ) … … 399 265 return true; 400 266 } 401 267 402 function rmdir($path, $recursive=false){268 function rmdir($path, $recursive = false ) { 403 269 if( ! $recursive ) 404 270 return $this->ftp->rmdir($path); 405 271 406 272 return $this->ftp->mdel($path); 407 273 } 408 274 409 function dirlist($path ='.',$incdot=false,$recursive=false){410 if( $this->is_file($path) ) {275 function dirlist($path = '.', $incdot = false, $recursive = false ) { 276 if( $this->is_file($path) ) { 411 277 $limitFile = basename($path); 412 278 $path = dirname($path) . '/'; 413 279 } else { … … 430 296 //We're including the doted starts 431 297 if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder 432 298 if ($recursive) 433 $struc['files'] = $this->dirlist($path .'/'.$struc['name'],$incdot,$recursive);299 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); 434 300 } 435 301 } else { //No dots 436 302 if ($recursive) 437 $struc['files'] = $this->dirlist($path .'/'.$struc['name'],$incdot,$recursive);303 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); 438 304 } 439 305 } 440 306 //File -
wp-admin/includes/file.php
34 34 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 42 42 return $real_file; … … 88 88 } 89 89 } 90 90 91 //Checks to see if the given plugin page is registered as a Menu or Submenu. 92 function validate_plugin_page($plugin_page){ 93 global $menu, $submenu, $pagenow; 94 95 //Check top-level menu's 96 foreach( $menu as $page) 97 if( $plugin_page == $page[2]) 98 return true; 99 100 //Check sub-menu's 101 foreach( (array)$submenu[ $pagenow ] as $page) 102 if( $plugin_page == $page[2]) 103 return true; 104 105 //The given file has not been loaded as a plugin page. 106 return false; 107 } 108 91 109 // array wp_handle_upload ( array &file [, array overrides] ) 92 110 // file: reference to a single element of $_FILES. Call the function once for each uploaded file. 93 111 // overrides: an associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ). … … 256 274 $tmppath .= $path[$j] . '/'; 257 275 if ( ! $fs->is_dir($to . $tmppath) ) 258 276 if ( !$fs->mkdir($to . $tmppath, 0755) ) 259 return new WP_Error('mkdir_failed', __('Could not create directory') );277 return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $tmppath); 260 278 } 261 279 262 280 // We've made sure the folders are there, so let's extract the file now: 263 281 if ( ! $file['folder'] ) 264 282 if ( !$fs->put_contents( $to . $file['filename'], $file['content']) ) 265 return new WP_Error('copy_failed', __('Could not copy file') );283 return new WP_Error('copy_failed', __('Could not copy file'), $to . $file['filename']); 266 284 $fs->chmod($to . $file['filename'], 0644); 267 285 } 268 286 … … 280 298 foreach ( (array) $dirlist as $filename => $fileinfo ) { 281 299 if ( 'f' == $fileinfo['type'] ) { 282 300 if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true) ) 283 return false;301 return new WP_Error('copy_failed', __('Could not copy file'), $to . $filename); 284 302 $wp_filesystem->chmod($to . $filename, 0644); 285 303 } elseif ( 'd' == $fileinfo['type'] ) { 286 304 if ( !$wp_filesystem->mkdir($to . $filename, 0755) ) 287 return false; 288 if ( !copy_dir($from . $filename, $to . $filename) ) 289 return false; 305 return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $filename); 306 $result = copy_dir($from . $filename, $to . $filename); 307 if ( is_wp_error($result) ) 308 return $result; 290 309 } 291 310 } 292 293 return true;294 311 } 295 312 296 313 function WP_Filesystem( $args = false ) { 297 314 global $wp_filesystem; 298 315 316 require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); 317 299 318 $method = get_filesystem_method(); 300 319 301 320 if ( ! $method ) … … 333 352 return apply_filters('filesystem_method', $method); 334 353 } 335 354 336 ?> 355 ?> 356 No newline at end of file -
wp-admin/includes/update.php
150 150 return new WP_Error('up_to_date', __('The plugin is at the latest version.')); 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 156 156 if ( ! is_object($wp_filesystem) ) … … 160 160 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors); 161 161 162 162 //Get the base plugin folder 163 $base = $wp_filesystem->get_base_dir(WP_PLUGIN_DIR); 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).')); 164 171 165 if ( empty($base) )166 return new WP_Error('fs_nowordpress', __('Unable to locate WordPress directory.'));172 $plugins_dir = trailingslashit( $plugins_dir ); 173 $content_dir = trailingslashit( $content_dir ); 167 174 168 175 // Get the URL to the zip file 169 176 $r = $current->response[ $plugin ]; … … 174 181 // Download the package 175 182 $package = $r->package; 176 183 apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package)); 177 $ file = download_url($package);184 $download_file = download_url($package); 178 185 179 if ( is_wp_error($ file) )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 185 192 if ( $wp_filesystem->is_dir($working_dir) ) … … 187 194 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 206 197 // Once extracted, delete the package198 unlink($file);199 200 207 if ( is_plugin_active($plugin) ) { 201 208 //Deactivate the plugin silently, Prevent deactivation hooks from running. 202 209 apply_filters('update_feedback', __('Deactivating the plugin')); … … 205 212 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);221 $deleted = $wp_filesystem->delete($plugins_dir . $plugin); 216 222 217 if ( ! $deleted ) {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')); 220 226 } 221 227 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 229 236 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin … … 236 243 delete_option('update_plugins'); 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 248 255 ?> -
wp-admin/update.php
110 110 return; 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'); 116 116 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')); 124 125 echo '<iframe style="border:0" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $result, 'activate-plugin_' . $result) .'"></iframe>';
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)