Ticket #10304: 10304.patch
| File 10304.patch, 17.5 KB (added by azaozz, 4 years ago) |
|---|
-
wp-admin/includes/class-wp-filesystem-base.php
210 210 return trailingslashit($base . $last_path); 211 211 } 212 212 if ( $loop ) 213 return false; //Prevent tihs function looping again.213 return false; //Prevent tihs function looping again. 214 214 //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. 215 215 return $this->search_for_folder($folder, '/', true); 216 216 … … 242 242 $info = 'd'; 243 243 elseif (($perms & 0x2000) == 0x2000) // Character special 244 244 $info = 'c'; 245 elseif (($perms & 0x1000) == 0x1000) // FIFO pipe245 elseif (($perms & 0x1000) == 0x1000) // FIFO pipe 246 246 $info = 'p'; 247 247 else // Unknown 248 248 $info = 'u'; -
wp-admin/includes/class-wp-filesystem-direct.php
15 15 * @uses WP_Filesystem_Base Extends class 16 16 */ 17 17 class WP_Filesystem_Direct extends WP_Filesystem_Base { 18 var $permission = null;19 18 var $errors = null; 19 /** 20 * constructor 21 * 22 * @param $arg mixed ingored argument 23 */ 20 24 function WP_Filesystem_Direct($arg) { 21 25 $this->method = 'direct'; 22 26 $this->errors = new WP_Error(); 23 27 } 28 /** 29 * connect filesystem. 30 * 31 * @return bool Returns true on success or false on failure (always true for WP_Filesystem_Direct). 32 */ 24 33 function connect() { 25 34 return true; 26 35 } 27 function setDefaultPermissions($perm) { 28 $this->permission = $perm; 29 } 36 /** 37 * Reads entire file into a string 38 * 39 * @param $file string Name of the file to read. 40 * @return string|bool The function returns the read data or false on failure. 41 */ 30 42 function get_contents($file) { 31 43 return @file_get_contents($file); 32 44 } 45 /** 46 * Reads entire file into an array 47 * 48 * @param $file string Path to the file. 49 * @return array|bool the file contents in an array or false on failure. 50 */ 33 51 function get_contents_array($file) { 34 52 return @file($file); 35 53 } 54 /** 55 * Write a string to a file 56 * 57 * @param $file string Path to the file where to write the data. 58 * @param $contents string The data to write. 59 * @param $mode int (optional) The file permissions as octal number, usually 0644. 60 * @param $type string (optional) Specifies additional type of access you require to the file. 61 * @return bool False upon failure. 62 */ 36 63 function put_contents($file, $contents, $mode = false, $type = '') { 37 64 if ( ! ($fp = @fopen($file, 'w' . $type)) ) 38 65 return false; 39 66 @fwrite($fp, $contents); 40 67 @fclose($fp); 41 $this->chmod($file, $mode);68 $this->chmod($file, $mode); 42 69 return true; 43 70 } 71 /** 72 * Gets the current working directory 73 * 74 * @return string|bool the current working directory on success, or false on failure. 75 */ 44 76 function cwd() { 45 77 return @getcwd(); 46 78 } 79 /** 80 * Change directory 81 * 82 * @param $dir string The new current directory. 83 * @return bool Returns true on success or false on failure. 84 */ 47 85 function chdir($dir) { 48 86 return @chdir($dir); 49 87 } 88 /** 89 * Changes file group 90 * 91 * @param $file string Path to the file. 92 * @param $group mixed A group name or number. 93 * @param $recursive bool (optional) If set True changes file group recursivly. Defaults to False. 94 * @return bool Returns true on success or false on failure. 95 */ 50 96 function chgrp($file, $group, $recursive = false) { 51 97 if ( ! $this->exists($file) ) 52 98 return false; … … 62 108 63 109 return true; 64 110 } 111 /** 112 * Changes filesystem permissions 113 * 114 * @param $file string Path to the file. 115 * @param $mode int (optional) The permissions as octal number, usually 0644 for files, 0755 for dirs. 116 * @param $recursive bool (optional) If set True changes file group recursivly. Defaults to False. 117 * @return bool Returns true on success or false on failure. 118 */ 65 119 function chmod($file, $mode = false, $recursive = false) { 66 120 if ( ! $this->exists($file) ) 67 121 return false; 68 122 69 123 if ( ! $mode ) { 70 if ( $this->permission ) 71 $mode = $this->permission; 72 elseif ( $this->is_file($file) ) 124 if ( $this->is_file($file) ) 73 125 $mode = FS_CHMOD_FILE; 74 126 elseif ( $this->is_dir($file) ) 75 127 $mode = FS_CHMOD_DIR; … … 89 141 90 142 return true; 91 143 } 144 /** 145 * Changes file owner 146 * 147 * @param $file string Path to the file. 148 * @param $owner mixed A user name or number. 149 * @param $recursive bool (optional) If set True changes file owner recursivly. Defaults to False. 150 * @return bool Returns true on success or false on failure. 151 */ 92 152 function chown($file, $owner, $recursive = false) { 93 153 if ( ! $this->exists($file) ) 94 154 return false; … … 98 158 return @chown($file, $owner); 99 159 //Is a directory, and we want recursive 100 160 $filelist = $this->dirlist($file); 101 foreach ($filelist as $filename) {161 foreach ($filelist as $filename) { 102 162 $this->chown($file . '/' . $filename, $owner, $recursive); 103 163 } 104 164 return true; 105 165 } 166 /** 167 * Gets file owner 168 * 169 * @param $file string Path to the file. 170 * @return string Username of the user. 171 */ 106 172 function owner($file) { 107 173 $owneruid = @fileowner($file); 108 174 if ( ! $owneruid ) … … 112 178 $ownerarray = posix_getpwuid($owneruid); 113 179 return $ownerarray['name']; 114 180 } 181 /** 182 * Gets file permissions 183 * 184 * FIXME does not handle errors in fileperms() 185 * 186 * @param $file string Path to the file. 187 * @return string Mode of the file (last 4 digits). 188 */ 115 189 function getchmod($file) { 116 190 return substr(decoct(@fileperms($file)),3); 117 191 } … … 133 207 134 208 function move($source, $destination, $overwrite = false) { 135 209 //Possible to use rename()? 136 if ( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ) {210 if ( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ) { 137 211 $this->delete($source); 138 212 return true; 139 213 } else { … … 197 271 return @filesize($file); 198 272 } 199 273 200 function touch($file, $time = 0, $atime = 0) {274 function touch($file, $time = 0, $atime = 0) { 201 275 if ($time == 0) 202 276 $time = time(); 203 277 if ($atime == 0) … … 205 279 return @touch($file, $time, $atime); 206 280 } 207 281 208 function mkdir($path, $chmod = false, $chown = false, $chgrp = false){ 282 function mkdir($path, $chmod = false, $chown = false, $chgrp = false) { 283 if ( ! $chmod ) 284 $chmod = FS_CHMOD_DIR; 285 209 286 if ( ! @mkdir($path) ) 210 287 return false; 211 288 $this->chmod($path, $chmod); -
wp-admin/includes/class-wp-filesystem-ftpext.php
20 20 var $errors = null; 21 21 var $options = array(); 22 22 23 var $permission = null;24 25 23 function WP_Filesystem_FTPext($opt='') { 26 24 $this->method = 'ftpext'; 27 25 $this->errors = new WP_Error(); … … 84 82 return true; 85 83 } 86 84 87 function setDefaultPermissions($perm) { 88 $this->permission = $perm; 89 } 90 91 function get_contents($file, $type = '', $resumepos = 0 ){ 92 if( empty($type) ) 85 function get_contents($file, $type = '', $resumepos = 0 ) { 86 if ( empty($type) ) 93 87 $type = FTP_BINARY; 94 88 95 89 $temp = tmpfile(); 96 90 if ( ! $temp ) 97 91 return false; 98 92 99 if ( ! @ftp_fget($this->link, $temp, $file, $type, $resumepos) )93 if ( ! @ftp_fget($this->link, $temp, $file, $type, $resumepos) ) 100 94 return false; 101 95 102 96 fseek($temp, 0); //Skip back to the start of the file being written to … … 112 106 return explode("\n", $this->get_contents($file)); 113 107 } 114 108 function put_contents($file, $contents, $type = '' ) { 115 if ( empty($type) )109 if ( empty($type) ) 116 110 $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII; 117 111 118 112 $temp = tmpfile(); … … 129 123 } 130 124 function cwd() { 131 125 $cwd = @ftp_pwd($this->link); 132 if ( $cwd )126 if ( $cwd ) 133 127 $cwd = trailingslashit($cwd); 134 128 return $cwd; 135 129 } … … 140 134 return false; 141 135 } 142 136 function chmod($file, $mode = false, $recursive = false) { 143 if( ! $mode )144 $mode = $this->permission;145 if( ! $mode )146 return false;147 137 if ( ! $this->exists($file) && ! $this->is_dir($file) ) 148 138 return false; 139 140 if ( ! $mode ) { 141 if ( $this->is_file($file) ) 142 $mode = FS_CHMOD_FILE; 143 elseif ( $this->is_dir($file) ) 144 $mode = FS_CHMOD_DIR; 145 else 146 return false; 147 } 148 149 149 if ( ! $recursive || ! $this->is_dir($file) ) { 150 150 if ( ! function_exists('ftp_chmod') ) 151 151 return @ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file)); … … 153 153 } 154 154 //Is a directory, and we want recursive 155 155 $filelist = $this->dirlist($file); 156 foreach ($filelist as $filename){156 foreach ( $filelist as $filename ) { 157 157 $this->chmod($file . '/' . $filename, $mode, $recursive); 158 158 } 159 159 return true; … … 174 174 return $dir[$file]['group']; 175 175 } 176 176 function copy($source, $destination, $overwrite = false ) { 177 if ( ! $overwrite && $this->exists($destination) )177 if ( ! $overwrite && $this->exists($destination) ) 178 178 return false; 179 179 $content = $this->get_contents($source); 180 if ( false === $content)180 if ( false === $content) 181 181 return false; 182 182 return $this->put_contents($destination, $content); 183 183 } … … 210 210 function is_dir($path) { 211 211 $cwd = $this->cwd(); 212 212 $result = @ftp_chdir($this->link, trailingslashit($path) ); 213 if ( $result && $path == $this->cwd() || $this->cwd() != $cwd ) {213 if ( $result && $path == $this->cwd() || $this->cwd() != $cwd ) { 214 214 @ftp_chdir($this->link, $cwd); 215 215 return true; 216 216 } … … 237 237 return false; 238 238 } 239 239 function mkdir($path, $chmod = false, $chown = false, $chgrp = false) { 240 if ( !ftp_mkdir($this->link, $path) )240 if ( !ftp_mkdir($this->link, $path) ) 241 241 return false; 242 if( $chmod ) 243 $this->chmod($path, $chmod); 244 if( $chown ) 242 if ( ! $chmod ) 243 $chmod = FS_CHMOD_DIR; 244 $this->chmod($path, $chmod); 245 if ( $chown ) 245 246 $this->chown($path, $chown); 246 if ( $chgrp )247 if ( $chgrp ) 247 248 $this->chgrp($path, $chgrp); 248 249 return true; 249 250 } … … 256 257 if ( is_null($is_windows) ) 257 258 $is_windows = strpos( strtolower(ftp_systype($this->link)), 'win') !== false; 258 259 259 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)) {260 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) ) { 260 261 $b = array(); 261 if ( $lucifer[3]<70) { $lucifer[3] +=2000; } else { $lucifer[3]+=1900; } // 4digit year fix262 if ( $lucifer[3] < 70 ) { $lucifer[3] +=2000; } else { $lucifer[3] += 1900; } // 4digit year fix 262 263 $b['isdir'] = ($lucifer[7]=="<DIR>"); 263 264 if ( $b['isdir'] ) 264 265 $b['type'] = 'd'; … … 317 318 } 318 319 319 320 function dirlist($path = '.', $incdot = false, $recursive = false) { 320 if ( $this->is_file($path) ) {321 if ( $this->is_file($path) ) { 321 322 $limitFile = basename($path); 322 323 $path = dirname($path) . '/'; 323 324 } else { … … 352 353 if ( 'd' == $struc['type'] ) { 353 354 $struc['files'] = array(); 354 355 355 if ( $incdot ) {356 if ( $incdot ) { 356 357 //We're including the doted starts 357 if ( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder358 if ( '.' != $struc['name'] && '..' != $struc['name'] ) { //Ok, It isnt a special folder 358 359 if ($recursive) 359 360 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); 360 361 } … … 369 370 return $ret; 370 371 } 371 372 372 function __destruct() {373 if ( $this->link )373 function __destruct() { 374 if ( $this->link ) 374 375 ftp_close($this->link); 375 376 } 376 377 } -
wp-admin/includes/class-wp-filesystem-ftpsockets.php
20 20 var $errors = null; 21 21 var $options = array(); 22 22 23 var $permission = null;24 25 23 function WP_Filesystem_ftpsockets($opt = '') { 26 24 $this->method = 'ftpsockets'; 27 25 $this->errors = new WP_Error(); 28 26 29 27 //Check if possible to use ftp functions. 30 if ( ! @include_once ABSPATH . 'wp-admin/includes/class-ftp.php' )28 if ( ! @include_once ABSPATH . 'wp-admin/includes/class-ftp.php' ) 31 29 return false; 32 30 $this->ftp = new ftp(); 33 31 … … 82 80 return true; 83 81 } 84 82 85 function setDefaultPermissions($perm) {86 $this->permission = $perm;87 }88 89 83 function get_contents($file, $type = '', $resumepos = 0) { 90 if ( ! $this->exists($file) )84 if ( ! $this->exists($file) ) 91 85 return false; 92 86 93 if ( empty($type) )87 if ( empty($type) ) 94 88 $type = FTP_AUTOASCII; 95 89 $this->ftp->SetType($type); 96 90 … … 121 115 } 122 116 123 117 function put_contents($file, $contents, $type = '' ) { 124 if ( empty($type) )118 if ( empty($type) ) 125 119 $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII; 126 120 127 121 $this->ftp->SetType($type); … … 144 138 145 139 function cwd() { 146 140 $cwd = $this->ftp->pwd(); 147 if ( $cwd )141 if ( $cwd ) 148 142 $cwd = trailingslashit($cwd); 149 143 return $cwd; 150 144 } … … 158 152 } 159 153 160 154 function chmod($file, $mode = false, $recursive = false ) { 161 if( ! $mode ) 162 $mode = $this->permission;163 if( ! $mode)164 return false;165 //if( ! $this->exists($file) )166 // return false;167 if( ! $recursive || ! $this->is_dir($file) ) {168 return $this->ftp->chmod($file,$mode);155 156 if ( ! $mode ) { 157 if ( $this->is_file($file) ) 158 $mode = FS_CHMOD_FILE; 159 elseif ( $this->is_dir($file) ) 160 $mode = FS_CHMOD_DIR; 161 else 162 return false; 169 163 } 164 165 if ( ! $recursive || ! $this->is_dir($file) ) { 166 return $this->ftp->chmod($file, $mode); 167 } 170 168 //Is a directory, and we want recursive 171 169 $filelist = $this->dirlist($file); 172 170 foreach($filelist as $filename){ … … 195 193 } 196 194 197 195 function copy($source, $destination, $overwrite = false ) { 198 if ( ! $overwrite && $this->exists($destination) )196 if ( ! $overwrite && $this->exists($destination) ) 199 197 return false; 200 198 201 199 $content = $this->get_contents($source); … … 264 262 } 265 263 266 264 function mkdir($path, $chmod = false, $chown = false, $chgrp = false ) { 267 if ( ! $this->ftp->mkdir($path) )265 if ( ! $this->ftp->mkdir($path) ) 268 266 return false; 269 if( $chmod ) 270 $this->chmod($path, $chmod); 271 if( $chown ) 267 if ( ! $chmod ) 268 $chmod = FS_CHMOD_DIR; 269 $this->chmod($path, $chmod); 270 if ( $chown ) 272 271 $this->chown($path, $chown); 273 if ( $chgrp )272 if ( $chgrp ) 274 273 $this->chgrp($path, $chgrp); 275 274 return true; 276 275 } 277 276 278 277 function rmdir($path, $recursive = false ) { 279 if ( ! $recursive )278 if ( ! $recursive ) 280 279 return $this->ftp->rmdir($path); 281 280 282 281 return $this->ftp->mdel($path); 283 282 } 284 283 285 284 function dirlist($path = '.', $incdot = false, $recursive = false ) { 286 if ( $this->is_file($path) ) {285 if ( $this->is_file($path) ) { 287 286 $limitFile = basename($path); 288 287 $path = dirname($path) . '/'; 289 288 } else { … … 291 290 } 292 291 293 292 $list = $this->ftp->dirlist($path); 294 if ( ! $list )293 if ( ! $list ) 295 294 return false; 296 if ( empty($list) )295 if ( empty($list) ) 297 296 return array(); 298 297 299 298 $ret = array(); … … 304 303 305 304 if ( $incdot ){ 306 305 //We're including the doted starts 307 if ( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder306 if ( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder 308 307 if ($recursive) 309 308 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); 310 309 } -
wp-admin/includes/class-wp-filesystem-ssh2.php
56 56 var $errors = array(); 57 57 var $options = array(); 58 58 59 var $permission = 0644;60 61 59 function WP_Filesystem_SSH2($opt='') { 62 60 $this->method = 'ssh2'; 63 61 $this->errors = new WP_Error(); … … 160 158 return false; 161 159 } 162 160 163 function setDefaultPermissions($perm) {164 $this->debug("setDefaultPermissions();");165 if ( $perm )166 $this->permission = $perm;167 }168 169 161 function get_contents($file, $type = '', $resumepos = 0 ) { 170 162 $file = ltrim($file, '/'); 171 163 return file_get_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file); … … 201 193 } 202 194 203 195 function chmod($file, $mode = false, $recursive = false) { 204 if( ! $mode )205 $mode = $this->permission;206 if( ! $mode )207 return false;208 196 if ( ! $this->exists($file) ) 209 197 return false; 198 199 if ( ! $mode ) { 200 if ( $this->is_file($file) ) 201 $mode = FS_CHMOD_FILE; 202 elseif ( $this->is_dir($file) ) 203 $mode = FS_CHMOD_DIR; 204 else 205 return false; 206 } 207 210 208 if ( ! $recursive || ! $this->is_dir($file) ) 211 209 return $this->run_command(sprintf('chmod %o %s', $mode, escapeshellarg($file)), true); 212 210 return $this->run_command(sprintf('chmod -R %o %s', $mode, escapeshellarg($file)), true); … … 315 313 //Not implmented. 316 314 } 317 315 318 function mkdir($path, $chmod = null, $chown = false, $chgrp = false) {316 function mkdir($path, $chmod = false, $chown = false, $chgrp = false) { 319 317 $path = untrailingslashit($path); 320 $chmod = !empty($chmod) ? $chmod : $this->permission; 318 if ( ! $chmod ) 319 $chmod = FS_CHMOD_DIR; 321 320 if ( ! ssh2_sftp_mkdir($this->sftp_link, $path, $chmod, true) ) 322 321 return false; 323 322 if ( $chown )
