Make WordPress Core

Changeset 11831


Ignore:
Timestamp:
08/16/2009 08:34:53 AM (16 years ago)
Author:
azaozz
Message:

WP_Filesystem fixes and phpdoc, props hakre dd32, see #10304

Location:
trunk/wp-admin/includes
Files:
5 edited

Legend:

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

    r10919 r11831  
    211211        }
    212212        if ( $loop )
    213             return false;//Prevent tihs function looping again.
     213            return false; //Prevent tihs function looping again.
    214214        //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.
    215215        return $this->search_for_folder($folder, '/', true);
     
    243243        elseif (($perms & 0x2000) == 0x2000) // Character special
    244244            $info = 'c';
    245         elseif (($perms & 0x1000) == 0x1000)// FIFO pipe
     245        elseif (($perms & 0x1000) == 0x1000) // FIFO pipe
    246246            $info = 'p';
    247247        else // Unknown
  • trunk/wp-admin/includes/class-wp-filesystem-direct.php

    r11667 r11831  
    1616 */
    1717class WP_Filesystem_Direct extends WP_Filesystem_Base {
    18     var $permission = null;
    1918    var $errors = null;
     19    /**
     20     * constructor
     21     *
     22     * @param $arg mixed ingored argument
     23     */
    2024    function WP_Filesystem_Direct($arg) {
    2125        $this->method = 'direct';
    2226        $this->errors = new WP_Error();
    2327    }
     28    /**
     29     * connect filesystem.
     30     *
     31     * @return bool Returns true on success or false on failure (always true for WP_Filesystem_Direct).
     32     */
    2433    function connect() {
    2534        return true;
    2635    }
    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     */
    3042    function get_contents($file) {
    3143        return @file_get_contents($file);
    3244    }
     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     */
    3351    function get_contents_array($file) {
    3452        return @file($file);
    3553    }
     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     */
    3663    function put_contents($file, $contents, $mode = false, $type = '') {
    3764        if ( ! ($fp = @fopen($file, 'w' . $type)) )
     
    3966        @fwrite($fp, $contents);
    4067        @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     */
    4476    function cwd() {
    4577        return @getcwd();
    4678    }
     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     */
    4785    function chdir($dir) {
    4886        return @chdir($dir);
    4987    }
     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     */
    5096    function chgrp($file, $group, $recursive = false) {
    5197        if ( ! $this->exists($file) )
     
    63109        return true;
    64110    }
     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     */
    65119    function chmod($file, $mode = false, $recursive = false) {
    66120        if ( ! $this->exists($file) )
     
    68122
    69123        if ( ! $mode ) {
    70             if ( $this->permission )
    71                 $mode = $this->permission;
    72             elseif ( $this->is_file($file) )
     124            if ( $this->is_file($file) )
    73125                $mode = FS_CHMOD_FILE;
    74126            elseif ( $this->is_dir($file) )
     
    90142        return true;
    91143    }
     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     */
    92152    function chown($file, $owner, $recursive = false) {
    93153        if ( ! $this->exists($file) )
     
    99159        //Is a directory, and we want recursive
    100160        $filelist = $this->dirlist($file);
    101         foreach ($filelist as $filename){
     161        foreach ($filelist as $filename) {
    102162            $this->chown($file . '/' . $filename, $owner, $recursive);
    103163        }
    104164        return true;
    105165    }
     166    /**
     167     * Gets file owner
     168     *
     169     * @param $file string Path to the file.
     170     * @return string Username of the user.
     171     */
    106172    function owner($file) {
    107173        $owneruid = @fileowner($file);
     
    113179        return $ownerarray['name'];
    114180    }
     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     */
    115189    function getchmod($file) {
    116190        return substr(decoct(@fileperms($file)),3);
     
    134208    function move($source, $destination, $overwrite = false) {
    135209        //Possible to use rename()?
    136         if ( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ){
     210        if ( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ) {
    137211            $this->delete($source);
    138212            return true;
     
    198272    }
    199273
    200     function touch($file, $time = 0, $atime = 0){
     274    function touch($file, $time = 0, $atime = 0) {
    201275        if ($time == 0)
    202276            $time = time();
     
    206280    }
    207281
    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
    209286        if ( ! @mkdir($path) )
    210287            return false;
  • trunk/wp-admin/includes/class-wp-filesystem-ftpext.php

    r11823 r11831  
    2020    var $options = array();
    2121
    22     var $permission = null;
    23 
    2422    function WP_Filesystem_FTPext($opt='') {
    2523        $this->method = 'ftpext';
     
    9189    }
    9290
    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) )
    9993            $type = FTP_BINARY;
    10094
     
    10397            return false;
    10498
    105         if( ! @ftp_fget($this->link, $temp, $file, $type, $resumepos) )
     99        if ( ! @ftp_fget($this->link, $temp, $file, $type, $resumepos) )
    106100            return false;
    107101
     
    119113    }
    120114    function put_contents($file, $contents, $type = '' ) {
    121         if( empty($type) )
     115        if ( empty($type) )
    122116            $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
    123117
     
    136130    function cwd() {
    137131        $cwd = @ftp_pwd($this->link);
    138         if( $cwd )
     132        if ( $cwd )
    139133            $cwd = trailingslashit($cwd);
    140134        return $cwd;
     
    147141    }
    148142    function chmod($file, $mode = false, $recursive = false) {
    149         if( ! $mode )
    150             $mode = $this->permission;
    151         if( ! $mode )
    152             return false;
    153143        if ( ! $this->exists($file) && ! $this->is_dir($file) )
    154144            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
    155155        if ( ! $recursive || ! $this->is_dir($file) ) {
    156156            if ( ! function_exists('ftp_chmod') )
     
    160160        //Is a directory, and we want recursive
    161161        $filelist = $this->dirlist($file);
    162         foreach($filelist as $filename){
     162        foreach ( $filelist as $filename ) {
    163163            $this->chmod($file . '/' . $filename, $mode, $recursive);
    164164        }
     
    181181    }
    182182    function copy($source, $destination, $overwrite = false ) {
    183         if( ! $overwrite && $this->exists($destination) )
     183        if ( ! $overwrite && $this->exists($destination) )
    184184            return false;
    185185        $content = $this->get_contents($source);
    186         if( false === $content)
     186        if ( false === $content)
    187187            return false;
    188188        return $this->put_contents($destination, $content);
     
    217217        $cwd = $this->cwd();
    218218        $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 ) {
    220220            @ftp_chdir($this->link, $cwd);
    221221            return true;
     
    244244    }
    245245    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 )
    251252            $this->chown($path, $chown);
    252         if( $chgrp )
     253        if ( $chgrp )
    253254            $this->chgrp($path, $chgrp);
    254255        return true;
     
    263264            $is_windows = strpos( strtolower(ftp_systype($this->link)), 'win') !== false;
    264265
    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) ) {
    266267            $b = array();
    267             if ($lucifer[3]<70) { $lucifer[3] +=2000; } else { $lucifer[3]+=1900; } // 4digit year fix
     268            if ( $lucifer[3] < 70 ) { $lucifer[3] +=2000; } else { $lucifer[3] += 1900; } // 4digit year fix
    268269            $b['isdir'] = ($lucifer[7]=="<DIR>");
    269270            if ( $b['isdir'] )
     
    324325
    325326    function dirlist($path = '.', $incdot = false, $recursive = false) {
    326         if( $this->is_file($path) ) {
     327        if ( $this->is_file($path) ) {
    327328            $limitFile = basename($path);
    328329            $path = dirname($path) . '/';
     
    359360                $struc['files'] = array();
    360361
    361                 if ( $incdot ){
     362                if ( $incdot ) {
    362363                    //We're including the doted starts
    363                     if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder
     364                    if ( '.' != $struc['name'] && '..' != $struc['name'] ) { //Ok, It isnt a special folder
    364365                        if ($recursive)
    365366                            $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
     
    376377    }
    377378
    378     function __destruct(){
    379         if( $this->link )
     379    function __destruct() {
     380        if ( $this->link )
    380381            ftp_close($this->link);
    381382    }
  • trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php

    r11823 r11831  
    2020    var $options = array();
    2121
    22     var $permission = null;
    23 
    2422    function WP_Filesystem_ftpsockets($opt = '') {
    2523        $this->method = 'ftpsockets';
     
    2725
    2826        //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' )
    3028                return false;
    3129        $this->ftp = new ftp();
     
    8482    }
    8583
    86     function setDefaultPermissions($perm) {
    87         $this->permission = $perm;
    88     }
    89 
    9084    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) )
    9589            $type = FTP_AUTOASCII;
    9690        $this->ftp->SetType($type);
     
    123117
    124118    function put_contents($file, $contents, $type = '' ) {
    125         if( empty($type) )
     119        if ( empty($type) )
    126120            $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
    127121
     
    146140    function cwd() {
    147141        $cwd = $this->ftp->pwd();
    148         if( $cwd )
     142        if ( $cwd )
    149143            $cwd = trailingslashit($cwd);
    150144        return $cwd;
     
    160154
    161155    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);
    170168        }
    171169        //Is a directory, and we want recursive
     
    197195
    198196    function copy($source, $destination, $overwrite = false ) {
    199         if( ! $overwrite && $this->exists($destination) )
     197        if ( ! $overwrite && $this->exists($destination) )
    200198            return false;
    201199
     
    266264
    267265    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 )
    273272            $this->chown($path, $chown);
    274         if( $chgrp )
     273        if ( $chgrp )
    275274            $this->chgrp($path, $chgrp);
    276275        return true;
     
    278277
    279278    function rmdir($path, $recursive = false ) {
    280         if( ! $recursive )
     279        if ( ! $recursive )
    281280            return $this->ftp->rmdir($path);
    282281
     
    285284
    286285    function dirlist($path = '.', $incdot = false, $recursive = false ) {
    287         if( $this->is_file($path) ) {
     286        if ( $this->is_file($path) ) {
    288287            $limitFile = basename($path);
    289288            $path = dirname($path) . '/';
     
    293292
    294293        $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) )
    298297            return array();
    299298
     
    306305                if ( $incdot ){
    307306                    //We're including the doted starts
    308                     if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder
     307                    if ( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder
    309308                        if ($recursive)
    310309                            $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
  • trunk/wp-admin/includes/class-wp-filesystem-ssh2.php

    r11823 r11831  
    4949    var $options = array();
    5050
    51     var $permission = 0644;
    52 
    5351    function WP_Filesystem_SSH2($opt='') {
    5452        $this->method = 'ssh2';
     
    153151    }
    154152
    155     function setDefaultPermissions($perm) {
    156         $this->debug("setDefaultPermissions();");
    157         if ( $perm )
    158             $this->permission = $perm;
    159     }
    160 
    161153    function get_contents($file, $type = '', $resumepos = 0 ) {
    162154        $file = ltrim($file, '/');
     
    194186
    195187    function chmod($file, $mode = false, $recursive = false) {
    196         if( ! $mode )
    197             $mode = $this->permission;
    198         if( ! $mode )
    199             return false;
    200188        if ( ! $this->exists($file) )
    201189            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
    202200        if ( ! $recursive || ! $this->is_dir($file) )
    203201            return $this->run_command(sprintf('chmod %o %s', $mode, escapeshellarg($file)), true);
     
    308306    }
    309307
    310     function mkdir($path, $chmod = null, $chown = false, $chgrp = false) {
     308    function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
    311309        $path = untrailingslashit($path);
    312         $chmod = !empty($chmod) ? $chmod : $this->permission;
     310        if ( ! $chmod )
     311            $chmod = FS_CHMOD_DIR;
    313312        if ( ! ssh2_sftp_mkdir($this->sftp_link, $path, $chmod, true) )
    314313            return false;
Note: See TracChangeset for help on using the changeset viewer.