Make WordPress Core


Ignore:
Timestamp:
05/29/2008 05:29:32 PM (18 years ago)
Author:
ryan
Message:

Make WP_Filesystem work with new directory constants. Props DD32. fixes #7059

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-filesystem-direct.php

    r7999 r8009  
    11<?php
    22
    3 class WP_Filesystem_Direct{
     3class WP_Filesystem_Direct  extends WP_Filesystem_Base {
    44        var $permission = null;
    55        var $errors = array();
    6         function WP_Filesystem_Direct($arg){
     6        function WP_Filesystem_Direct($arg) {
    77                $this->errors = new WP_Error();
    88                $this->permission = umask();
    99        }
    10         function connect(){
    11                 return true;
    12         }
    13         function setDefaultPermissions($perm){
     10        function connect() {
     11                return true;
     12        }
     13        function setDefaultPermissions($perm) {
    1414                $this->permission = $perm;
    1515        }
    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) {
    2517                return @file_get_contents($file);
    2618        }
    27         function get_contents_array($file){
     19        function get_contents_array($file) {
    2820                return @file($file);
    2921        }
    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)) )
    3224                        return false;
    3325                @fwrite($fp,$contents);
    … …  
    3628                return true;
    3729        }
    38         function cwd(){
     30        function cwd() {
    3931                return @getcwd();
    4032        }
    41         function chdir($dir){
     33        function chdir($dir) {
    4234                return @chdir($dir);
    4335        }
    44         function chgrp($file,$group,$recursive=false){
     36        function chgrp($file,$group,$recursive=false) {
    4537                if( ! $this->exists($file) )
    4638                        return false;
    4739                if( ! $recursive )
    48                         return @chgrp($file,$group);
     40                        return @chgrp($file, $group);
    4941                if( ! $this->is_dir($file) )
    50                         return @chgrp($file,$group);
     42                        return @chgrp($file, $group);
    5143                //Is a directory, and we want recursive
    5244                $file = trailingslashit($file);
    … …  
    5749                return true;
    5850        }
    59         function chmod($file,$mode=false,$recursive=false){
     51        function chmod($file,$mode=false,$recursive=false) {
    6052                if( ! $mode )
    6153                        $mode = $this->permission;
    … …  
    6557                        return @chmod($file,$mode);
    6658                if( ! $this->is_dir($file) )
    67                         return @chmod($file,$mode);
     59                        return @chmod($file, $mode);
    6860                //Is a directory, and we want recursive
    6961                $file = trailingslashit($file);
    … …  
    7466                return true;
    7567        }
    76         function chown($file,$owner,$recursive=false){
     68        function chown($file, $owner, $recursive = false) {
    7769                if( ! $this->exists($file) )
    7870                        return false;
    7971                if( ! $recursive )
    80                         return @chown($file,$owner);
     72                        return @chown($file, $owner);
    8173                if( ! $this->is_dir($file) )
    82                         return @chown($file,$owner);
     74                        return @chown($file, $owner);
    8375                //Is a directory, and we want recursive
    8476                $filelist = $this->dirlist($file);
    8577                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) {
    9183                $owneruid = @fileowner($file);
    9284                if( ! $owneruid )
    9385                        return false;
    94                 if( !function_exists('posix_getpwuid') )
     86                if( ! function_exists('posix_getpwuid') )
    9587                        return $owneruid;
    9688                $ownerarray = posix_getpwuid($owneruid);
    9789                return $ownerarray['name'];
    9890        }
    99         function getchmod($file){
     91        function getchmod($file) {
    10092                return @fileperms($file);
    10193        }
    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) {
    17295                $gid = @filegroup($file);
    17396                if( ! $gid )
    17497                        return false;
    175                 if( !function_exists('posix_getgrgid') )
     98                if( ! function_exists('posix_getgrgid') )
    17699                        return $gid;
    177100                $grouparray = posix_getgrgid($gid);
    … …  
    179102        }
    180103
    181         function copy($source,$destination,$overwrite=false){
     104        function copy($source, $destination, $overwrite = false) {
    182105                if( ! $overwrite && $this->exists($destination) )
    183106                        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) {
    188111                //Possible to use rename()?
    189                 if( $this->copy($source,$destination,$overwrite) && $this->exists($destination) ){
     112                if( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ){
    190113                        $this->delete($source);
    191114                        return true;
    … …  
    195118        }
    196119
    197         function delete($file, $recursive=false){
    198                 $file = str_replace('\\','/',$file); //for win32, occasional problems deleteing files otherwise
     120        function delete($file, $recursive = false) {
     121                $file = str_replace('\\', '/', $file); //for win32, occasional problems deleteing files otherwise
    199122
    200123                if( $this->is_file($file) )
    201124                        return @unlink($file);
    202                 if( !$recursive && $this->is_dir($file) )
     125                if( ! $recursive && $this->is_dir($file) )
    203126                        return @rmdir($file);
    204127
    … …  
    209132                $retval = true;
    210133                if( is_array($filelist) ) //false if no files, So check first.
    211                         foreach($filelist as $filename=>$fileinfo)
     134                        foreach($filelist as $filename => $fileinfo)
    212135                                if( ! $this->delete($file . $filename, $recursive) )
    213136                                        $retval = false;
    … …  
    218141        }
    219142
    220         function exists($file){
     143        function exists($file) {
    221144                return @file_exists($file);
    222145        }
    223146
    224         function is_file($file){
     147        function is_file($file) {
    225148                return @is_file($file);
    226149        }
    227150
    228         function is_dir($path){
     151        function is_dir($path) {
    229152                return @is_dir($path);
    230153        }
    231154
    232         function is_readable($file){
     155        function is_readable($file) {
    233156                return @is_readable($file);
    234157        }
    235158
    236         function is_writable($file){
     159        function is_writable($file) {
    237160                return @is_writable($file);
    238161        }
    239162
    240         function atime($file){
     163        function atime($file) {
    241164                return @fileatime($file);
    242165        }
    243166
    244         function mtime($file){
     167        function mtime($file) {
    245168                return @filemtime($file);
    246169        }
    247         function size($file){
     170        function size($file) {
    248171                return @filesize($file);
    249172        }
    … …  
    254177                if($atime == 0)
    255178                        $atime = time();
    256                 return @touch($file,$time,$atime);
     179                return @touch($file, $time, $atime);
    257180        }
    258181
    … …  
    261184                        $chmod = $this->permission;
    262185
    263                 if( !@mkdir($path,$chmod) )
     186                if( ! @mkdir($path, $chmod) )
    264187                        return false;
    265188                if( $chown )
    266                         $this->chown($path,$chown);
     189                        $this->chown($path, $chown);
    267190                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) {
    273196                //Currently unused and untested, Use delete() instead.
    274197                if( ! $recursive )
    … …  
    276199                //recursive:
    277200                $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);
    281204                        @rmdir($filename);
    282205                }
    … …  
    284207        }
    285208
    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) ) {
    288211                        $limitFile = basename($path);
    289212                        $path = dirname($path);
    … …  
    296219                $ret = array();
    297220                $dir = dir($path);
    298                 while (false !== ($entry = $dir->read())) {
     221                while (false !== ($entry = $dir->read()) ) {
    299222                        $struc = array();
    300                         $struc['name']          = $entry;
     223                        $struc['name'] = $entry;
    301224
    302225                        if( '.' == $struc['name'] || '..' == $struc['name'] )
    … …  
    318241                        $struc['type']          = $this->is_dir($path.'/'.$entry) ? 'd' : 'f';
    319242
    320                         if ('d' == $struc['type'] ){
     243                        if ( 'd' == $struc['type'] ) {
    321244                                if( $recursive )
    322                                         $struc['files'] = $this->dirlist($path.'/'.$struc['name'], $incdot, $recursive);
     245                                        $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
    323246                                else
    324247                                        $struc['files'] = array();
    … …  
    331254                return $ret;
    332255        }
    333 
    334         function __destruct(){
    335                 return;
    336         }
    337256}
    338257?>
Note: See TracChangeset for help on using the changeset viewer.