X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/a6f44f0edcda2471c5a33e4156c1c9488c7f3210..refs/tags/wordpress-3.7:/wp-admin/includes/class-wp-filesystem-direct.php diff --git a/wp-admin/includes/class-wp-filesystem-direct.php b/wp-admin/includes/class-wp-filesystem-direct.php index e25c9ef8..d07305bc 100644 --- a/wp-admin/includes/class-wp-filesystem-direct.php +++ b/wp-admin/includes/class-wp-filesystem-direct.php @@ -15,7 +15,7 @@ * @uses WP_Filesystem_Base Extends class */ class WP_Filesystem_Direct extends WP_Filesystem_Base { - var $errors = null; + /** * constructor * @@ -25,14 +25,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { $this->method = 'direct'; $this->errors = new WP_Error(); } - /** - * connect filesystem. - * - * @return bool Returns true on success or false on failure (always true for WP_Filesystem_Direct). - */ - function connect() { - return true; - } + /** * Reads entire file into a string * @@ -42,6 +35,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { function get_contents($file) { return @file_get_contents($file); } + /** * Reads entire file into an array * @@ -51,6 +45,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { function get_contents_array($file) { return @file($file); } + /** * Write a string to a file * @@ -59,14 +54,29 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { * @param int $mode (optional) The file permissions as octal number, usually 0644. * @return bool False upon failure. */ - function put_contents($file, $contents, $mode = false ) { - if ( ! ($fp = @fopen($file, 'w')) ) + function put_contents( $file, $contents, $mode = false ) { + $fp = @fopen( $file, 'wb' ); + if ( ! $fp ) + return false; + + mbstring_binary_safe_encoding(); + + $data_length = strlen( $contents ); + + $bytes_written = fwrite( $fp, $contents ); + + reset_mbstring_encoding(); + + fclose( $fp ); + + if ( $data_length !== $bytes_written ) return false; - @fwrite($fp, $contents); - @fclose($fp); - $this->chmod($file, $mode); + + $this->chmod( $file, $mode ); + return true; } + /** * Gets the current working directory * @@ -75,6 +85,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { function cwd() { return @getcwd(); } + /** * Change directory * @@ -84,6 +95,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { function chdir($dir) { return @chdir($dir); } + /** * Changes file group * @@ -99,7 +111,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { return @chgrp($file, $group); if ( ! $this->is_dir($file) ) return @chgrp($file, $group); - //Is a directory, and we want recursive + // Is a directory, and we want recursive $file = trailingslashit($file); $filelist = $this->dirlist($file); foreach ($filelist as $filename) @@ -107,6 +119,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { return true; } + /** * Changes filesystem permissions * @@ -127,7 +140,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { if ( ! $recursive || ! $this->is_dir($file) ) return @chmod($file, $mode); - //Is a directory, and we want recursive + // Is a directory, and we want recursive $file = trailingslashit($file); $filelist = $this->dirlist($file); foreach ( (array)$filelist as $filename => $filemeta) @@ -135,6 +148,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { return true; } + /** * Changes file owner * @@ -150,18 +164,19 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { return @chown($file, $owner); if ( ! $this->is_dir($file) ) return @chown($file, $owner); - //Is a directory, and we want recursive + // Is a directory, and we want recursive $filelist = $this->dirlist($file); foreach ($filelist as $filename) { $this->chown($file . '/' . $filename, $owner, $recursive); } return true; } + /** * Gets file owner * * @param string $file Path to the file. - * @return string Username of the user. + * @return string|bool Username of the user or false on error. */ function owner($file) { $owneruid = @fileowner($file); @@ -172,6 +187,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { $ownerarray = posix_getpwuid($owneruid); return $ownerarray['name']; } + /** * Gets file permissions * @@ -183,6 +199,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { function getchmod($file) { return substr(decoct(@fileperms($file)),3); } + function group($file) { $gid = @filegroup($file); if ( ! $gid ) @@ -220,27 +237,30 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { } function delete($file, $recursive = false, $type = false) { - if ( empty($file) ) //Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem. + if ( empty( $file ) ) // Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem. return false; - $file = str_replace('\\', '/', $file); //for win32, occasional problems deleting files otherwise + $file = str_replace( '\\', '/', $file ); // for win32, occasional problems deleting files otherwise if ( 'f' == $type || $this->is_file($file) ) return @unlink($file); if ( ! $recursive && $this->is_dir($file) ) return @rmdir($file); - //At this point it's a folder, and we're in recursive mode + // At this point it's a folder, and we're in recursive mode $file = trailingslashit($file); $filelist = $this->dirlist($file, true); $retval = true; - if ( is_array($filelist) ) //false if no files, So check first. - foreach ($filelist as $filename => $fileinfo) + if ( is_array( $filelist ) ) { + foreach ( $filelist as $filename => $fileinfo ) { if ( ! $this->delete($file . $filename, $recursive, $fileinfo['type']) ) $retval = false; + } + } if ( file_exists($file) && ! @rmdir($file) ) $retval = false; + return $retval; } @@ -271,6 +291,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { function mtime($file) { return @filemtime($file); } + function size($file) { return @filesize($file); }