Changeset 8018
- Timestamp:
- 05/30/2008 04:14:05 PM (17 years ago)
- Location:
- trunk/wp-admin/includes
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/class-wp-filesystem-direct.php
r8009 r8018 5 5 var $errors = array(); 6 6 function WP_Filesystem_Direct($arg) { 7 $this->method = 'direct'; 7 8 $this->errors = new WP_Error(); 8 9 $this->permission = umask(); … … 20 21 return @file($file); 21 22 } 22 function put_contents($file, $contents,$mode=false,$type='') {23 if ( ! ($fp = @fopen($file, 'w' . $type)) )24 return false; 25 @fwrite($fp, $contents);23 function put_contents($file, $contents, $mode = false, $type = '') { 24 if ( ! ($fp = @fopen($file, 'w' . $type)) ) 25 return false; 26 @fwrite($fp, $contents); 26 27 @fclose($fp); 27 28 $this->chmod($file,$mode); … … 34 35 return @chdir($dir); 35 36 } 36 function chgrp($file, $group,$recursive=false) {37 function chgrp($file, $group, $recursive = false) { 37 38 if( ! $this->exists($file) ) 38 39 return false; … … 49 50 return true; 50 51 } 51 function chmod($file, $mode=false,$recursive=false) {52 function chmod($file, $mode = false, $recursive = false) { 52 53 if( ! $mode ) 53 54 $mode = $this->permission; -
trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php
r8009 r8018 1 1 <?php 2 class WP_Filesystem_ftpsockets {2 class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { 3 3 var $ftp = false; 4 4 var $timeout = 5; … … 87 87 } 88 88 89 function get_contents($file, $type='',$resumepos=0){89 function get_contents($file, $type = '', $resumepos = 0){ 90 90 if( ! $this->exists($file) ) 91 91 return false; 92 92 93 93 if( empty($type) ){ 94 $extension = substr(strrchr($file, "."), 1);94 $extension = substr(strrchr($file, '.'), 1); 95 95 $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_AUTOASCII; 96 96 } 97 97 $this->ftp->SetType($type); 98 $temp = tmpfile(); 99 if ( ! $temp ) 100 return false; 101 if ( ! $this->ftp->fget($temp, $file) ) { 102 fclose($temp); 98 $temp = wp_tempnam( $file ); 99 if ( ! $temphandle = fopen($temp, 'w+') ) 100 return false; 101 if ( ! $this->ftp->fget($temphandle, $file) ) { 102 fclose($temphandle); 103 unlink($temp); 103 104 return ''; //Blank document, File does exist, Its just blank. 104 105 } 105 fseek($temp , 0); //Skip back to the start of the file being written to106 fseek($temphandle, 0); //Skip back to the start of the file being written to 106 107 $contents = ''; 107 while ( !feof($temp) ) 108 $contents .= fread($temp, 8192); 109 fclose($temp); 108 while ( ! feof($temphandle) ) 109 $contents .= fread($temphandle, 8192); 110 fclose($temphandle); 111 unlink($temp); 110 112 return $contents; 111 113 } 112 114 113 115 function get_contents_array($file){ 114 return explode("\n", $this->get_contents($file));115 } 116 117 function put_contents($file, $contents,$type=''){116 return explode("\n", $this->get_contents($file) ); 117 } 118 119 function put_contents($file, $contents, $type = '' ) { 118 120 if( empty($type) ){ 119 $extension = substr(strrchr($file, "."), 1);120 $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; 121 123 } 122 124 $this->ftp->SetType($type); 123 125 124 $temp = tmpfile(); 125 if ( ! $temp ) 126 return false; 127 fwrite($temp,$contents); 128 fseek($temp, 0); //Skip back to the start of the file being written to 129 $ret = $this->ftp->fput($file, $temp); 130 fclose($temp); 126 $temp = wp_tempnam( $file ); 127 if ( ! $temphandle = fopen($temp, 'w+') ){ 128 unlink($temp); 129 return false; 130 } 131 fwrite($temphandle, $contents); 132 fseek($temphandle, 0); //Skip back to the start of the file being written to 133 $ret = $this->ftp->fput($file, $temphandle); 134 fclose($temphandle); 135 unlink($temp); 131 136 return $ret; 132 137 } 133 138 134 function cwd() {139 function cwd() { 135 140 $cwd = $this->ftp->pwd(); 136 141 if( $cwd ) … … 139 144 } 140 145 141 function chdir($file) {146 function chdir($file) { 142 147 return $this->ftp->chdir($file); 143 148 } 144 149 145 function chgrp($file, $group,$recursive=false){146 return false; 147 } 148 149 function chmod($file, $mode=false,$recursive=false){150 function chgrp($file, $group, $recursive = false ) { 151 return false; 152 } 153 154 function chmod($file, $mode = false, $recursive = false ){ 150 155 if( ! $mode ) 151 156 $mode = $this->permission; … … 154 159 //if( ! $this->exists($file) ) 155 160 // return false; 156 if( ! $recursive || ! $this->is_dir($file) ) {161 if( ! $recursive || ! $this->is_dir($file) ) { 157 162 return $this->ftp->chmod($file,$mode); 158 163 } … … 160 165 $filelist = $this->dirlist($file); 161 166 foreach($filelist as $filename){ 162 $this->chmod($file .'/'.$filename,$mode,$recursive);163 } 164 return true; 165 } 166 167 function chown($file, $owner,$recursive=false){168 return false; 169 } 170 171 function owner($file) {167 $this->chmod($file . '/' . $filename, $mode, $recursive); 168 } 169 return true; 170 } 171 172 function chown($file, $owner, $recursive = false ) { 173 return false; 174 } 175 176 function owner($file) { 172 177 $dir = $this->dirlist($file); 173 178 return $dir[$file]['owner']; 174 179 } 175 180 176 function getchmod($file) {181 function getchmod($file) { 177 182 $dir = $this->dirlist($file); 178 183 return $dir[$file]['permsn']; 179 184 } 180 185 181 function gethchmod($file){ 182 //From the PHP.net page for ...? 183 $perms = $this->getchmod($file); 184 if (($perms & 0xC000) == 0xC000) { 185 // Socket 186 $info = 's'; 187 } elseif (($perms & 0xA000) == 0xA000) { 188 // Symbolic Link 189 $info = 'l'; 190 } elseif (($perms & 0x8000) == 0x8000) { 191 // Regular 192 $info = '-'; 193 } elseif (($perms & 0x6000) == 0x6000) { 194 // Block special 195 $info = 'b'; 196 } elseif (($perms & 0x4000) == 0x4000) { 197 // Directory 198 $info = 'd'; 199 } elseif (($perms & 0x2000) == 0x2000) { 200 // Character special 201 $info = 'c'; 202 } elseif (($perms & 0x1000) == 0x1000) { 203 // FIFO pipe 204 $info = 'p'; 205 } else { 206 // Unknown 207 $info = 'u'; 208 } 209 210 // Owner 211 $info .= (($perms & 0x0100) ? 'r' : '-'); 212 $info .= (($perms & 0x0080) ? 'w' : '-'); 213 $info .= (($perms & 0x0040) ? 214 (($perms & 0x0800) ? 's' : 'x' ) : 215 (($perms & 0x0800) ? 'S' : '-')); 216 217 // Group 218 $info .= (($perms & 0x0020) ? 'r' : '-'); 219 $info .= (($perms & 0x0010) ? 'w' : '-'); 220 $info .= (($perms & 0x0008) ? 221 (($perms & 0x0400) ? 's' : 'x' ) : 222 (($perms & 0x0400) ? 'S' : '-')); 223 224 // World 225 $info .= (($perms & 0x0004) ? 'r' : '-'); 226 $info .= (($perms & 0x0002) ? 'w' : '-'); 227 $info .= (($perms & 0x0001) ? 228 (($perms & 0x0200) ? 't' : 'x' ) : 229 (($perms & 0x0200) ? 'T' : '-')); 230 return $info; 231 } 232 233 function getnumchmodfromh($mode) { 234 $realmode = ""; 235 $legal = array("","w","r","x","-"); 236 $attarray = preg_split("//",$mode); 237 for($i=0;$i<count($attarray);$i++){ 238 if($key = array_search($attarray[$i],$legal)){ 239 $realmode .= $legal[$key]; 240 } 241 } 242 $mode = str_pad($realmode,9,'-'); 243 $trans = array('-'=>'0','r'=>'4','w'=>'2','x'=>'1'); 244 $mode = strtr($mode,$trans); 245 $newmode = ''; 246 $newmode .= $mode[0]+$mode[1]+$mode[2]; 247 $newmode .= $mode[3]+$mode[4]+$mode[5]; 248 $newmode .= $mode[6]+$mode[7]+$mode[8]; 249 return $newmode; 250 } 251 252 function group($file){ 186 function group($file) { 253 187 $dir = $this->dirlist($file); 254 188 return $dir[$file]['group']; 255 189 } 256 190 257 function copy($source, $destination,$overwrite=false){191 function copy($source, $destination, $overwrite = false ) { 258 192 if( ! $overwrite && $this->exists($destination) ) 259 193 return false;
Note: See TracChangeset
for help on using the changeset viewer.