Changeset 8009 for trunk/wp-admin/includes/class-wp-filesystem-direct.php
- Timestamp:
- 05/29/2008 05:29:32 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/class-wp-filesystem-direct.php
r7999 r8009 1 1 <?php 2 2 3 class WP_Filesystem_Direct {3 class WP_Filesystem_Direct extends WP_Filesystem_Base { 4 4 var $permission = null; 5 5 var $errors = array(); 6 function WP_Filesystem_Direct($arg) {6 function WP_Filesystem_Direct($arg) { 7 7 $this->errors = new WP_Error(); 8 8 $this->permission = umask(); 9 9 } 10 function connect() {11 return true; 12 } 13 function setDefaultPermissions($perm) {10 function connect() { 11 return true; 12 } 13 function setDefaultPermissions($perm) { 14 14 $this->permission = $perm; 15 15 } 16 function find_base_dir($path = false, $base = '.', $echo = false){ 17 if (!$path) 18 $path = ABSPATH; 19 return str_replace('\\','/',$path); 20 } 21 function get_base_dir($path = false, $base = '.', $echo = false){ 22 return $this->find_base_dir($base, $echo); 23 } 24 function get_contents($file){ 16 function get_contents($file) { 25 17 return @file_get_contents($file); 26 18 } 27 function get_contents_array($file) {19 function get_contents_array($file) { 28 20 return @file($file); 29 21 } 30 function put_contents($file,$contents,$mode=false,$type='') {31 if ( ! ($fp = @fopen($file,'w' .$type)) )22 function put_contents($file,$contents,$mode=false,$type='') { 23 if ( ! ($fp = @fopen($file,'w' . $type)) ) 32 24 return false; 33 25 @fwrite($fp,$contents); … … 36 28 return true; 37 29 } 38 function cwd() {30 function cwd() { 39 31 return @getcwd(); 40 32 } 41 function chdir($dir) {33 function chdir($dir) { 42 34 return @chdir($dir); 43 35 } 44 function chgrp($file,$group,$recursive=false) {36 function chgrp($file,$group,$recursive=false) { 45 37 if( ! $this->exists($file) ) 46 38 return false; 47 39 if( ! $recursive ) 48 return @chgrp($file, $group);40 return @chgrp($file, $group); 49 41 if( ! $this->is_dir($file) ) 50 return @chgrp($file, $group);42 return @chgrp($file, $group); 51 43 //Is a directory, and we want recursive 52 44 $file = trailingslashit($file); … … 57 49 return true; 58 50 } 59 function chmod($file,$mode=false,$recursive=false) {51 function chmod($file,$mode=false,$recursive=false) { 60 52 if( ! $mode ) 61 53 $mode = $this->permission; … … 65 57 return @chmod($file,$mode); 66 58 if( ! $this->is_dir($file) ) 67 return @chmod($file, $mode);59 return @chmod($file, $mode); 68 60 //Is a directory, and we want recursive 69 61 $file = trailingslashit($file); … … 74 66 return true; 75 67 } 76 function chown($file, $owner,$recursive=false){68 function chown($file, $owner, $recursive = false) { 77 69 if( ! $this->exists($file) ) 78 70 return false; 79 71 if( ! $recursive ) 80 return @chown($file, $owner);72 return @chown($file, $owner); 81 73 if( ! $this->is_dir($file) ) 82 return @chown($file, $owner);74 return @chown($file, $owner); 83 75 //Is a directory, and we want recursive 84 76 $filelist = $this->dirlist($file); 85 77 foreach($filelist as $filename){ 86 $this->chown($file .'/'.$filename,$owner,$recursive);87 } 88 return true; 89 } 90 function owner($file) {78 $this->chown($file . '/' . $filename, $owner, $recursive); 79 } 80 return true; 81 } 82 function owner($file) { 91 83 $owneruid = @fileowner($file); 92 84 if( ! $owneruid ) 93 85 return false; 94 if( ! function_exists('posix_getpwuid') )86 if( ! function_exists('posix_getpwuid') ) 95 87 return $owneruid; 96 88 $ownerarray = posix_getpwuid($owneruid); 97 89 return $ownerarray['name']; 98 90 } 99 function getchmod($file) {91 function getchmod($file) { 100 92 return @fileperms($file); 101 93 } 102 function gethchmod($file){ 103 //From the PHP.net page for ...? 104 $perms = $this->getchmod($file); 105 if (($perms & 0xC000) == 0xC000) { 106 // Socket 107 $info = 's'; 108 } elseif (($perms & 0xA000) == 0xA000) { 109 // Symbolic Link 110 $info = 'l'; 111 } elseif (($perms & 0x8000) == 0x8000) { 112 // Regular 113 $info = '-'; 114 } elseif (($perms & 0x6000) == 0x6000) { 115 // Block special 116 $info = 'b'; 117 } elseif (($perms & 0x4000) == 0x4000) { 118 // Directory 119 $info = 'd'; 120 } elseif (($perms & 0x2000) == 0x2000) { 121 // Character special 122 $info = 'c'; 123 } elseif (($perms & 0x1000) == 0x1000) { 124 // FIFO pipe 125 $info = 'p'; 126 } else { 127 // Unknown 128 $info = 'u'; 129 } 130 131 // Owner 132 $info .= (($perms & 0x0100) ? 'r' : '-'); 133 $info .= (($perms & 0x0080) ? 'w' : '-'); 134 $info .= (($perms & 0x0040) ? 135 (($perms & 0x0800) ? 's' : 'x' ) : 136 (($perms & 0x0800) ? 'S' : '-')); 137 138 // Group 139 $info .= (($perms & 0x0020) ? 'r' : '-'); 140 $info .= (($perms & 0x0010) ? 'w' : '-'); 141 $info .= (($perms & 0x0008) ? 142 (($perms & 0x0400) ? 's' : 'x' ) : 143 (($perms & 0x0400) ? 'S' : '-')); 144 145 // World 146 $info .= (($perms & 0x0004) ? 'r' : '-'); 147 $info .= (($perms & 0x0002) ? 'w' : '-'); 148 $info .= (($perms & 0x0001) ? 149 (($perms & 0x0200) ? 't' : 'x' ) : 150 (($perms & 0x0200) ? 'T' : '-')); 151 return $info; 152 } 153 function getnumchmodfromh($mode) { 154 $realmode = ""; 155 $legal = array("","w","r","x","-"); 156 $attarray = preg_split("//",$mode); 157 for($i=0;$i<count($attarray);$i++){ 158 if($key = array_search($attarray[$i],$legal)){ 159 $realmode .= $legal[$key]; 160 } 161 } 162 $mode = str_pad($realmode,9,'-'); 163 $trans = array('-'=>'0','r'=>'4','w'=>'2','x'=>'1'); 164 $mode = strtr($mode,$trans); 165 $newmode = ''; 166 $newmode .= $mode[0]+$mode[1]+$mode[2]; 167 $newmode .= $mode[3]+$mode[4]+$mode[5]; 168 $newmode .= $mode[6]+$mode[7]+$mode[8]; 169 return $newmode; 170 } 171 function group($file){ 94 function group($file) { 172 95 $gid = @filegroup($file); 173 96 if( ! $gid ) 174 97 return false; 175 if( ! function_exists('posix_getgrgid') )98 if( ! function_exists('posix_getgrgid') ) 176 99 return $gid; 177 100 $grouparray = posix_getgrgid($gid); … … 179 102 } 180 103 181 function copy($source, $destination,$overwrite=false){104 function copy($source, $destination, $overwrite = false) { 182 105 if( ! $overwrite && $this->exists($destination) ) 183 106 return false; 184 return copy($source, $destination);185 } 186 187 function move($source, $destination,$overwrite=false){107 return copy($source, $destination); 108 } 109 110 function move($source, $destination, $overwrite = false) { 188 111 //Possible to use rename()? 189 if( $this->copy($source, $destination,$overwrite) && $this->exists($destination) ){112 if( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ){ 190 113 $this->delete($source); 191 114 return true; … … 195 118 } 196 119 197 function delete($file, $recursive =false){198 $file = str_replace('\\', '/',$file); //for win32, occasional problems deleteing files otherwise120 function delete($file, $recursive = false) { 121 $file = str_replace('\\', '/', $file); //for win32, occasional problems deleteing files otherwise 199 122 200 123 if( $this->is_file($file) ) 201 124 return @unlink($file); 202 if( ! $recursive && $this->is_dir($file) )125 if( ! $recursive && $this->is_dir($file) ) 203 126 return @rmdir($file); 204 127 … … 209 132 $retval = true; 210 133 if( is_array($filelist) ) //false if no files, So check first. 211 foreach($filelist as $filename =>$fileinfo)134 foreach($filelist as $filename => $fileinfo) 212 135 if( ! $this->delete($file . $filename, $recursive) ) 213 136 $retval = false; … … 218 141 } 219 142 220 function exists($file) {143 function exists($file) { 221 144 return @file_exists($file); 222 145 } 223 146 224 function is_file($file) {147 function is_file($file) { 225 148 return @is_file($file); 226 149 } 227 150 228 function is_dir($path) {151 function is_dir($path) { 229 152 return @is_dir($path); 230 153 } 231 154 232 function is_readable($file) {155 function is_readable($file) { 233 156 return @is_readable($file); 234 157 } 235 158 236 function is_writable($file) {159 function is_writable($file) { 237 160 return @is_writable($file); 238 161 } 239 162 240 function atime($file) {163 function atime($file) { 241 164 return @fileatime($file); 242 165 } 243 166 244 function mtime($file) {167 function mtime($file) { 245 168 return @filemtime($file); 246 169 } 247 function size($file) {170 function size($file) { 248 171 return @filesize($file); 249 172 } … … 254 177 if($atime == 0) 255 178 $atime = time(); 256 return @touch($file, $time,$atime);179 return @touch($file, $time, $atime); 257 180 } 258 181 … … 261 184 $chmod = $this->permission; 262 185 263 if( ! @mkdir($path,$chmod) )186 if( ! @mkdir($path, $chmod) ) 264 187 return false; 265 188 if( $chown ) 266 $this->chown($path, $chown);189 $this->chown($path, $chown); 267 190 if( $chgrp ) 268 $this->chgrp($path, $chgrp);269 return true; 270 } 271 272 function rmdir($path, $recursive=false){191 $this->chgrp($path, $chgrp); 192 return true; 193 } 194 195 function rmdir($path, $recursive = false) { 273 196 //Currently unused and untested, Use delete() instead. 274 197 if( ! $recursive ) … … 276 199 //recursive: 277 200 $filelist = $this->dirlist($path); 278 foreach($filelist as $filename =>$det){279 if ( '/' == substr($filename, -1,1) )280 $this->rmdir($path .'/'.$filename,$recursive);201 foreach($filelist as $filename => $det) { 202 if ( '/' == substr($filename, -1, 1) ) 203 $this->rmdir($path . '/' . $filename, $recursive); 281 204 @rmdir($filename); 282 205 } … … 284 207 } 285 208 286 function dirlist($path, $incdot=false,$recursive=false){287 if( $this->is_file($path) ) {209 function dirlist($path, $incdot = false, $recursive = false) { 210 if( $this->is_file($path) ) { 288 211 $limitFile = basename($path); 289 212 $path = dirname($path); … … 296 219 $ret = array(); 297 220 $dir = dir($path); 298 while (false !== ($entry = $dir->read()) ) {221 while (false !== ($entry = $dir->read()) ) { 299 222 $struc = array(); 300 $struc['name'] = $entry;223 $struc['name'] = $entry; 301 224 302 225 if( '.' == $struc['name'] || '..' == $struc['name'] ) … … 318 241 $struc['type'] = $this->is_dir($path.'/'.$entry) ? 'd' : 'f'; 319 242 320 if ( 'd' == $struc['type'] ){243 if ( 'd' == $struc['type'] ) { 321 244 if( $recursive ) 322 $struc['files'] = $this->dirlist($path .'/'.$struc['name'], $incdot, $recursive);245 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); 323 246 else 324 247 $struc['files'] = array(); … … 331 254 return $ret; 332 255 } 333 334 function __destruct(){335 return;336 }337 256 } 338 257 ?>
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)