Changeset 10919
- Timestamp:
- 04/13/2009 04:11:02 PM (17 years ago)
- Location:
- trunk/wp-admin/includes
- Files:
-
- 4 edited
-
class-wp-filesystem-base.php (modified) (7 diffs)
-
class-wp-filesystem-direct.php (modified) (17 diffs)
-
class-wp-filesystem-ftpext.php (modified) (4 diffs)
-
class-wp-filesystem-ftpsockets.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/class-wp-filesystem-base.php
r10150 r10919 47 47 */ 48 48 function abspath() { 49 if ( defined('FTP_BASE') && strpos($this->method, 'ftp') !== false )50 return FTP_BASE;51 49 $folder = $this->find_folder(ABSPATH); 52 50 //Perhaps the FTP folder is rooted at the WordPress install, Check for wp-includes folder in root, Could have some false positives, but rare. … … 63 61 */ 64 62 function wp_content_dir() { 65 if ( defined('FTP_CONTENT_DIR') && strpos($this->method, 'ftp') !== false )66 return FTP_CONTENT_DIR;67 63 return $this->find_folder(WP_CONTENT_DIR); 68 64 } … … 76 72 */ 77 73 function wp_plugins_dir() { 78 if ( defined('FTP_PLUGIN_DIR') && strpos($this->method, 'ftp') !== false )79 return FTP_PLUGIN_DIR;80 74 return $this->find_folder(WP_PLUGIN_DIR); 81 75 } … … 143 137 function find_folder($folder) { 144 138 139 if ( strpos($this->method, 'ftp') !== false ) { 140 $constant_overrides = array( 'FTP_BASE' => ABSPATH, 'FTP_CONTENT_DIR' => WP_CONTENT_DIR, 'FTP_PLUGIN_DIR' => WP_PLUGIN_DIR ); 141 foreach ( $constant_overrides as $constant => $dir ) 142 if ( defined($constant) && $folder === $dir ) 143 return trailingslashit(constant($constant)); 144 } elseif ( 'direct' == $this->method ) { 145 return trailingslashit($folder); 146 } 147 145 148 $folder = preg_replace('|^([a-z]{1}):|i', '', $folder); //Strip out windows driveletter if its there. 146 149 $folder = str_replace('\\', '/', $folder); //Windows path sanitiation … … 150 153 151 154 if ( $this->exists($folder) ) { //Folder exists at that absolute path. 155 $folder = trailingslashit($folder); 152 156 $this->cache[ $folder ] = $folder; 153 157 return $folder; … … 190 194 // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on. 191 195 // If it reaches the end, and still cant find it, it'll return false for the entire function. 192 if ( isset($files[ $key ]) ){196 if ( isset($files[ $key ]) ){ 193 197 //Lets try that folder: 194 198 $newdir = trailingslashit(path_join($base, $key)); 195 if ( $this->verbose )199 if ( $this->verbose ) 196 200 printf( __('Changing to %s') . '<br/>', $newdir ); 197 if ( $ret = $this->search_for_folder( $folder, $newdir, $loop) )201 if ( $ret = $this->search_for_folder( $folder, $newdir, $loop) ) 198 202 return $ret; 199 203 } … … 201 205 202 206 //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. 203 if (isset( $files[ $last_path ] ) ) {204 if ( $this->verbose )207 if (isset( $files[ $last_path ] ) ) { 208 if ( $this->verbose ) 205 209 printf( __('Found %s') . '<br/>', $base . $last_path ); 206 return $base . $last_path;210 return trailingslashit($base . $last_path); 207 211 } 208 if ( $loop )212 if ( $loop ) 209 213 return false;//Prevent tihs function looping again. 210 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. -
trunk/wp-admin/includes/class-wp-filesystem-direct.php
r10051 r10919 15 15 * @uses WP_Filesystem_Base Extends class 16 16 */ 17 class WP_Filesystem_Direct extends WP_Filesystem_Base {17 class WP_Filesystem_Direct extends WP_Filesystem_Base { 18 18 var $permission = null; 19 var $errors = array();19 var $errors = null; 20 20 function WP_Filesystem_Direct($arg) { 21 21 $this->method = 'direct'; … … 50 50 } 51 51 function chgrp($file, $group, $recursive = false) { 52 if ( ! $this->exists($file) )53 return false; 54 if ( ! $recursive )52 if ( ! $this->exists($file) ) 53 return false; 54 if ( ! $recursive ) 55 55 return @chgrp($file, $group); 56 if ( ! $this->is_dir($file) )56 if ( ! $this->is_dir($file) ) 57 57 return @chgrp($file, $group); 58 58 //Is a directory, and we want recursive 59 59 $file = trailingslashit($file); 60 60 $filelist = $this->dirlist($file); 61 foreach ($filelist as $filename)61 foreach ($filelist as $filename) 62 62 $this->chgrp($file . $filename, $group, $recursive); 63 63 … … 65 65 } 66 66 function chmod($file, $mode = false, $recursive = false) { 67 if ( ! $mode )67 if ( ! $mode ) 68 68 $mode = $this->permission; 69 if ( ! $this->exists($file) )70 return false; 71 if ( ! $recursive )69 if ( ! $this->exists($file) ) 70 return false; 71 if ( ! $recursive ) 72 72 return @chmod($file,$mode); 73 if ( ! $this->is_dir($file) )73 if ( ! $this->is_dir($file) ) 74 74 return @chmod($file, $mode); 75 75 //Is a directory, and we want recursive 76 76 $file = trailingslashit($file); 77 77 $filelist = $this->dirlist($file); 78 foreach ($filelist as $filename)78 foreach ($filelist as $filename) 79 79 $this->chmod($file . $filename, $mode, $recursive); 80 80 … … 82 82 } 83 83 function chown($file, $owner, $recursive = false) { 84 if ( ! $this->exists($file) )85 return false; 86 if ( ! $recursive )84 if ( ! $this->exists($file) ) 85 return false; 86 if ( ! $recursive ) 87 87 return @chown($file, $owner); 88 if ( ! $this->is_dir($file) )88 if ( ! $this->is_dir($file) ) 89 89 return @chown($file, $owner); 90 90 //Is a directory, and we want recursive 91 91 $filelist = $this->dirlist($file); 92 foreach ($filelist as $filename){92 foreach ($filelist as $filename){ 93 93 $this->chown($file . '/' . $filename, $owner, $recursive); 94 94 } … … 97 97 function owner($file) { 98 98 $owneruid = @fileowner($file); 99 if ( ! $owneruid )100 return false; 101 if ( ! function_exists('posix_getpwuid') )99 if ( ! $owneruid ) 100 return false; 101 if ( ! function_exists('posix_getpwuid') ) 102 102 return $owneruid; 103 103 $ownerarray = posix_getpwuid($owneruid); … … 105 105 } 106 106 function getchmod($file) { 107 return @fileperms($file);107 return substr(decoct(@fileperms($file)),3); 108 108 } 109 109 function group($file) { 110 110 $gid = @filegroup($file); 111 if ( ! $gid )112 return false; 113 if ( ! function_exists('posix_getgrgid') )111 if ( ! $gid ) 112 return false; 113 if ( ! function_exists('posix_getgrgid') ) 114 114 return $gid; 115 115 $grouparray = posix_getgrgid($gid); … … 118 118 119 119 function copy($source, $destination, $overwrite = false) { 120 if ( ! $overwrite && $this->exists($destination) )120 if ( ! $overwrite && $this->exists($destination) ) 121 121 return false; 122 122 return copy($source, $destination); … … 125 125 function move($source, $destination, $overwrite = false) { 126 126 //Possible to use rename()? 127 if ( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ){127 if ( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ){ 128 128 $this->delete($source); 129 129 return true; … … 134 134 135 135 function delete($file, $recursive = false) { 136 if ( empty($file) ) //Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem. 137 return false; 136 138 $file = str_replace('\\', '/', $file); //for win32, occasional problems deleteing files otherwise 137 139 138 if ( $this->is_file($file) )140 if ( $this->is_file($file) ) 139 141 return @unlink($file); 140 if ( ! $recursive && $this->is_dir($file) )142 if ( ! $recursive && $this->is_dir($file) ) 141 143 return @rmdir($file); 142 144 … … 146 148 147 149 $retval = true; 148 if ( is_array($filelist) ) //false if no files, So check first.149 foreach ($filelist as $filename => $fileinfo)150 if ( ! $this->delete($file . $filename, $recursive) )150 if ( is_array($filelist) ) //false if no files, So check first. 151 foreach ($filelist as $filename => $fileinfo) 152 if ( ! $this->delete($file . $filename, $recursive) ) 151 153 $retval = false; 152 154 153 if (! @rmdir($file) )154 returnfalse;155 if ( file_exists($file) && ! @rmdir($file) ) 156 $retval = false; 155 157 return $retval; 156 158 } … … 188 190 189 191 function touch($file, $time = 0, $atime = 0){ 190 if ($time == 0)192 if ($time == 0) 191 193 $time = time(); 192 if ($atime == 0)194 if ($atime == 0) 193 195 $atime = time(); 194 196 return @touch($file, $time, $atime); … … 196 198 197 199 function mkdir($path, $chmod = false, $chown = false, $chgrp = false){ 198 if ( ! $chmod)200 if ( ! $chmod) 199 201 $chmod = $this->permission; 200 202 201 if ( ! @mkdir($path, $chmod) )202 return false; 203 if ( $chown )203 if ( ! @mkdir($path, $chmod) ) 204 return false; 205 if ( $chown ) 204 206 $this->chown($path, $chown); 205 if ( $chgrp )207 if ( $chgrp ) 206 208 $this->chgrp($path, $chgrp); 207 209 return true; … … 210 212 function rmdir($path, $recursive = false) { 211 213 //Currently unused and untested, Use delete() instead. 212 if ( ! $recursive )214 if ( ! $recursive ) 213 215 return @rmdir($path); 214 216 //recursive: 215 217 $filelist = $this->dirlist($path); 216 foreach ($filelist as $filename => $det) {218 foreach ($filelist as $filename => $det) { 217 219 if ( '/' == substr($filename, -1, 1) ) 218 220 $this->rmdir($path . '/' . $filename, $recursive); … … 223 225 224 226 function dirlist($path, $incdot = false, $recursive = false) { 225 if ( $this->is_file($path) ) {227 if ( $this->is_file($path) ) { 226 228 $limitFile = basename($path); 227 229 $path = dirname($path); … … 229 231 $limitFile = false; 230 232 } 231 if ( ! $this->is_dir($path) )233 if ( ! $this->is_dir($path) ) 232 234 return false; 233 235 … … 240 242 $struc['name'] = $entry; 241 243 242 if ( '.' == $struc['name'] || '..' == $struc['name'] )244 if ( '.' == $struc['name'] || '..' == $struc['name'] ) 243 245 continue; //Do not care about these folders. 244 if ( '.' == $struc['name'][0] && !$incdot)246 if ( '.' == $struc['name'][0] && !$incdot) 245 247 continue; 246 if ( $limitFile && $struc['name'] != $limitFile)248 if ( $limitFile && $struc['name'] != $limitFile) 247 249 continue; 248 250 … … 259 261 260 262 if ( 'd' == $struc['type'] ) { 261 if ( $recursive )263 if ( $recursive ) 262 264 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); 263 265 else -
trunk/wp-admin/includes/class-wp-filesystem-ftpext.php
r10150 r10919 170 170 function getchmod($file) { 171 171 $dir = $this->dirlist($file); 172 return $ dir[$file]['permsn'];172 return $this->getnumchmodfromh( $dir[basename($file)]['perms'] ); 173 173 } 174 174 function group($file) { … … 188 188 } 189 189 190 function delete($file,$recursive=false) { 190 function delete($file ,$recursive = false ) { 191 if ( empty($file) ) 192 return false; 191 193 if ( $this->is_file($file) ) 192 194 return @ftp_delete($this->link, $file); … … 322 324 323 325 function dirlist($path = '.', $incdot = false, $recursive = false) { 324 if( $this->is_file($path) ) { 325 $limitFile = basename($path); 326 $path = dirname($path) . '/'; 326 327 if ( substr($path, -1) !== '/') { 328 $limit = basename($path); 329 $path = trailingslashit(dirname($path)); 327 330 } else { 328 $limit File= false;331 $limit = false; 329 332 } 330 333 … … 340 343 continue; 341 344 342 if ( '.' == $entry["name"] || '..' == $entry["name"] ) 345 if ( '.' == $entry['name'] || '..' == $entry['name'] ) 346 continue; 347 348 if ( $limit && $entry['name'] != $limit ) 343 349 continue; 344 350 -
trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php
r8990 r10919 187 187 function getchmod($file) { 188 188 $dir = $this->dirlist($file); 189 return $ dir[$file]['permsn'];189 return $this->getnumchmodfromh( $dir[basename($file)]['perms'] ); 190 190 } 191 191 … … 282 282 283 283 function dirlist($path = '.', $incdot = false, $recursive = false ) { 284 if( $this->is_file($path) ) { 285 $limitFile = basename($path); 286 $path = dirname($path) . '/'; 284 285 if ( substr($path, -1) !== '/') { 286 $limit = basename($path); 287 $path = trailingslashit(dirname($path)); 287 288 } else { 288 $limit File= false;289 $limit = false; 289 290 } 290 291 … … 292 293 if( ! $list ) 293 294 return false; 295 294 296 if( empty($list) ) 295 297 return array(); … … 297 299 $ret = array(); 298 300 foreach ( $list as $struc ) { 301 if ( $limit && $struc['name'] != $limit ) 302 continue; 299 303 300 304 if ( 'd' == $struc['type'] ) {
Note: See TracChangeset
for help on using the changeset viewer.