Changeset 11831
- Timestamp:
- 08/16/2009 08:34:53 AM (16 years ago)
- Location:
- trunk/wp-admin/includes
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/class-wp-filesystem-base.php
r10919 r11831 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); … … 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 -
trunk/wp-admin/includes/class-wp-filesystem-direct.php
r11667 r11831 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)) ) … … 39 66 @fwrite($fp, $contents); 40 67 @fclose($fp); 41 $this->chmod($file,$mode); 42 return true; 43 } 68 $this->chmod($file, $mode); 69 return true; 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) ) … … 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) ) … … 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) ) … … 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) ) … … 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); … … 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); … … 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; … … 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(); … … 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; -
trunk/wp-admin/includes/class-wp-filesystem-ftpext.php
r11823 r11831 20 20 var $options = array(); 21 21 22 var $permission = null;23 24 22 function WP_Filesystem_FTPext($opt='') { 25 23 $this->method = 'ftpext'; … … 91 89 } 92 90 93 function setDefaultPermissions($perm) { 94 $this->permission = $perm; 95 } 96 97 function get_contents($file, $type = '', $resumepos = 0 ){ 98 if( empty($type) ) 91 function get_contents($file, $type = '', $resumepos = 0 ) { 92 if ( empty($type) ) 99 93 $type = FTP_BINARY; 100 94 … … 103 97 return false; 104 98 105 if ( ! @ftp_fget($this->link, $temp, $file, $type, $resumepos) )99 if ( ! @ftp_fget($this->link, $temp, $file, $type, $resumepos) ) 106 100 return false; 107 101 … … 119 113 } 120 114 function put_contents($file, $contents, $type = '' ) { 121 if ( empty($type) )115 if ( empty($type) ) 122 116 $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII; 123 117 … … 136 130 function cwd() { 137 131 $cwd = @ftp_pwd($this->link); 138 if ( $cwd )132 if ( $cwd ) 139 133 $cwd = trailingslashit($cwd); 140 134 return $cwd; … … 147 141 } 148 142 function chmod($file, $mode = false, $recursive = false) { 149 if( ! $mode )150 $mode = $this->permission;151 if( ! $mode )152 return false;153 143 if ( ! $this->exists($file) && ! $this->is_dir($file) ) 154 144 return false; 145 146 if ( ! $mode ) { 147 if ( $this->is_file($file) ) 148 $mode = FS_CHMOD_FILE; 149 elseif ( $this->is_dir($file) ) 150 $mode = FS_CHMOD_DIR; 151 else 152 return false; 153 } 154 155 155 if ( ! $recursive || ! $this->is_dir($file) ) { 156 156 if ( ! function_exists('ftp_chmod') ) … … 160 160 //Is a directory, and we want recursive 161 161 $filelist = $this->dirlist($file); 162 foreach ($filelist as $filename){162 foreach ( $filelist as $filename ) { 163 163 $this->chmod($file . '/' . $filename, $mode, $recursive); 164 164 } … … 181 181 } 182 182 function copy($source, $destination, $overwrite = false ) { 183 if ( ! $overwrite && $this->exists($destination) )183 if ( ! $overwrite && $this->exists($destination) ) 184 184 return false; 185 185 $content = $this->get_contents($source); 186 if ( false === $content)186 if ( false === $content) 187 187 return false; 188 188 return $this->put_contents($destination, $content); … … 217 217 $cwd = $this->cwd(); 218 218 $result = @ftp_chdir($this->link, trailingslashit($path) ); 219 if ( $result && $path == $this->cwd() || $this->cwd() != $cwd ) {219 if ( $result && $path == $this->cwd() || $this->cwd() != $cwd ) { 220 220 @ftp_chdir($this->link, $cwd); 221 221 return true; … … 244 244 } 245 245 function mkdir($path, $chmod = false, $chown = false, $chgrp = false) { 246 if( !ftp_mkdir($this->link, $path) ) 247 return false; 248 if( $chmod ) 249 $this->chmod($path, $chmod); 250 if( $chown ) 246 if ( !ftp_mkdir($this->link, $path) ) 247 return false; 248 if ( ! $chmod ) 249 $chmod = FS_CHMOD_DIR; 250 $this->chmod($path, $chmod); 251 if ( $chown ) 251 252 $this->chown($path, $chown); 252 if ( $chgrp )253 if ( $chgrp ) 253 254 $this->chgrp($path, $chgrp); 254 255 return true; … … 263 264 $is_windows = strpos( strtolower(ftp_systype($this->link)), 'win') !== false; 264 265 265 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)) {266 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) ) { 266 267 $b = array(); 267 if ( $lucifer[3]<70) { $lucifer[3] +=2000; } else { $lucifer[3]+=1900; } // 4digit year fix268 if ( $lucifer[3] < 70 ) { $lucifer[3] +=2000; } else { $lucifer[3] += 1900; } // 4digit year fix 268 269 $b['isdir'] = ($lucifer[7]=="<DIR>"); 269 270 if ( $b['isdir'] ) … … 324 325 325 326 function dirlist($path = '.', $incdot = false, $recursive = false) { 326 if ( $this->is_file($path) ) {327 if ( $this->is_file($path) ) { 327 328 $limitFile = basename($path); 328 329 $path = dirname($path) . '/'; … … 359 360 $struc['files'] = array(); 360 361 361 if ( $incdot ) {362 if ( $incdot ) { 362 363 //We're including the doted starts 363 if ( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder364 if ( '.' != $struc['name'] && '..' != $struc['name'] ) { //Ok, It isnt a special folder 364 365 if ($recursive) 365 366 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); … … 376 377 } 377 378 378 function __destruct() {379 if ( $this->link )379 function __destruct() { 380 if ( $this->link ) 380 381 ftp_close($this->link); 381 382 } -
trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php
r11823 r11831 20 20 var $options = array(); 21 21 22 var $permission = null;23 24 22 function WP_Filesystem_ftpsockets($opt = '') { 25 23 $this->method = 'ftpsockets'; … … 27 25 28 26 //Check if possible to use ftp functions. 29 if ( ! @include_once ABSPATH . 'wp-admin/includes/class-ftp.php' )27 if ( ! @include_once ABSPATH . 'wp-admin/includes/class-ftp.php' ) 30 28 return false; 31 29 $this->ftp = new ftp(); … … 84 82 } 85 83 86 function setDefaultPermissions($perm) {87 $this->permission = $perm;88 }89 90 84 function get_contents($file, $type = '', $resumepos = 0) { 91 if ( ! $this->exists($file) )92 return false; 93 94 if ( empty($type) )85 if ( ! $this->exists($file) ) 86 return false; 87 88 if ( empty($type) ) 95 89 $type = FTP_AUTOASCII; 96 90 $this->ftp->SetType($type); … … 123 117 124 118 function put_contents($file, $contents, $type = '' ) { 125 if ( empty($type) )119 if ( empty($type) ) 126 120 $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII; 127 121 … … 146 140 function cwd() { 147 141 $cwd = $this->ftp->pwd(); 148 if ( $cwd )142 if ( $cwd ) 149 143 $cwd = trailingslashit($cwd); 150 144 return $cwd; … … 160 154 161 155 function chmod($file, $mode = false, $recursive = false ) { 162 if( ! $mode ) 163 $mode = $this->permission; 164 if( ! $mode ) 165 return false; 166 //if( ! $this->exists($file) ) 167 // return false; 168 if( ! $recursive || ! $this->is_dir($file) ) { 169 return $this->ftp->chmod($file,$mode); 156 157 if ( ! $mode ) { 158 if ( $this->is_file($file) ) 159 $mode = FS_CHMOD_FILE; 160 elseif ( $this->is_dir($file) ) 161 $mode = FS_CHMOD_DIR; 162 else 163 return false; 164 } 165 166 if ( ! $recursive || ! $this->is_dir($file) ) { 167 return $this->ftp->chmod($file, $mode); 170 168 } 171 169 //Is a directory, and we want recursive … … 197 195 198 196 function copy($source, $destination, $overwrite = false ) { 199 if ( ! $overwrite && $this->exists($destination) )197 if ( ! $overwrite && $this->exists($destination) ) 200 198 return false; 201 199 … … 266 264 267 265 function mkdir($path, $chmod = false, $chown = false, $chgrp = false ) { 268 if( ! $this->ftp->mkdir($path) ) 269 return false; 270 if( $chmod ) 271 $this->chmod($path, $chmod); 272 if( $chown ) 266 if ( ! $this->ftp->mkdir($path) ) 267 return false; 268 if ( ! $chmod ) 269 $chmod = FS_CHMOD_DIR; 270 $this->chmod($path, $chmod); 271 if ( $chown ) 273 272 $this->chown($path, $chown); 274 if ( $chgrp )273 if ( $chgrp ) 275 274 $this->chgrp($path, $chgrp); 276 275 return true; … … 278 277 279 278 function rmdir($path, $recursive = false ) { 280 if ( ! $recursive )279 if ( ! $recursive ) 281 280 return $this->ftp->rmdir($path); 282 281 … … 285 284 286 285 function dirlist($path = '.', $incdot = false, $recursive = false ) { 287 if ( $this->is_file($path) ) {286 if ( $this->is_file($path) ) { 288 287 $limitFile = basename($path); 289 288 $path = dirname($path) . '/'; … … 293 292 294 293 $list = $this->ftp->dirlist($path); 295 if ( ! $list )296 return false; 297 if ( empty($list) )294 if ( ! $list ) 295 return false; 296 if ( empty($list) ) 298 297 return array(); 299 298 … … 306 305 if ( $incdot ){ 307 306 //We're including the doted starts 308 if ( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder307 if ( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder 309 308 if ($recursive) 310 309 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); -
trunk/wp-admin/includes/class-wp-filesystem-ssh2.php
r11823 r11831 49 49 var $options = array(); 50 50 51 var $permission = 0644;52 53 51 function WP_Filesystem_SSH2($opt='') { 54 52 $this->method = 'ssh2'; … … 153 151 } 154 152 155 function setDefaultPermissions($perm) {156 $this->debug("setDefaultPermissions();");157 if ( $perm )158 $this->permission = $perm;159 }160 161 153 function get_contents($file, $type = '', $resumepos = 0 ) { 162 154 $file = ltrim($file, '/'); … … 194 186 195 187 function chmod($file, $mode = false, $recursive = false) { 196 if( ! $mode )197 $mode = $this->permission;198 if( ! $mode )199 return false;200 188 if ( ! $this->exists($file) ) 201 189 return false; 190 191 if ( ! $mode ) { 192 if ( $this->is_file($file) ) 193 $mode = FS_CHMOD_FILE; 194 elseif ( $this->is_dir($file) ) 195 $mode = FS_CHMOD_DIR; 196 else 197 return false; 198 } 199 202 200 if ( ! $recursive || ! $this->is_dir($file) ) 203 201 return $this->run_command(sprintf('chmod %o %s', $mode, escapeshellarg($file)), true); … … 308 306 } 309 307 310 function mkdir($path, $chmod = null, $chown = false, $chgrp = false) {308 function mkdir($path, $chmod = false, $chown = false, $chgrp = false) { 311 309 $path = untrailingslashit($path); 312 $chmod = !empty($chmod) ? $chmod : $this->permission; 310 if ( ! $chmod ) 311 $chmod = FS_CHMOD_DIR; 313 312 if ( ! ssh2_sftp_mkdir($this->sftp_link, $path, $chmod, true) ) 314 313 return false;
Note: See TracChangeset
for help on using the changeset viewer.