wp/wp-admin/includes/class-wp-filesystem-base.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    17 	 *
    17 	 *
    18 	 * @access public
    18 	 * @access public
    19 	 * @since 2.5.0
    19 	 * @since 2.5.0
    20 	 * @var bool
    20 	 * @var bool
    21 	 */
    21 	 */
    22 	var $verbose = false;
    22 	public $verbose = false;
    23 
    23 
    24 	/**
    24 	/**
    25 	 * Cached list of local filepaths to mapped remote filepaths.
    25 	 * Cached list of local filepaths to mapped remote filepaths.
    26 	 *
    26 	 *
    27 	 * @access private
       
    28 	 * @since 2.7.0
    27 	 * @since 2.7.0
    29 	 * @var array
    28 	 * @var array
    30 	 */
    29 	 */
    31 	var $cache = array();
    30 	public $cache = array();
    32 
    31 
    33 	/**
    32 	/**
    34 	 * The Access method of the current connection, Set automatically.
    33 	 * The Access method of the current connection, Set automatically.
    35 	 *
    34 	 *
    36 	 * @access public
    35 	 * @access public
    37 	 * @since 2.5.0
    36 	 * @since 2.5.0
    38 	 * @var string
    37 	 * @var string
    39 	 */
    38 	 */
    40 	var $method = '';
    39 	public $method = '';
    41 
    40 
    42 	/**
    41 	public $errors = null;
    43 	 * Constructor (empty).
    42 
    44 	 */
    43 	public $options = array();
    45 	function __construct() {}
       
    46 
    44 
    47 	/**
    45 	/**
    48 	 * Return the path on the remote filesystem of ABSPATH.
    46 	 * Return the path on the remote filesystem of ABSPATH.
    49 	 *
    47 	 *
    50 	 * @access public
    48 	 * @access public
    51 	 * @since 2.7.0
    49 	 * @since 2.7.0
    52 	 *
    50 	 *
    53 	 * @return string The location of the remote path.
    51 	 * @return string The location of the remote path.
    54 	 */
    52 	 */
    55 	function abspath() {
    53 	public function abspath() {
    56 		$folder = $this->find_folder(ABSPATH);
    54 		$folder = $this->find_folder(ABSPATH);
    57 		// Perhaps the FTP folder is rooted at the WordPress install, Check for wp-includes folder in root, Could have some false positives, but rare.
    55 		// Perhaps the FTP folder is rooted at the WordPress install, Check for wp-includes folder in root, Could have some false positives, but rare.
    58 		if ( ! $folder && $this->is_dir('/wp-includes') )
    56 		if ( ! $folder && $this->is_dir( '/' . WPINC ) )
    59 			$folder = '/';
    57 			$folder = '/';
    60 		return $folder;
    58 		return $folder;
    61 	}
    59 	}
    62 
    60 
    63 	/**
    61 	/**
    66 	 * @access public
    64 	 * @access public
    67 	 * @since 2.7.0
    65 	 * @since 2.7.0
    68 	 *
    66 	 *
    69 	 * @return string The location of the remote path.
    67 	 * @return string The location of the remote path.
    70 	 */
    68 	 */
    71 	function wp_content_dir() {
    69 	public function wp_content_dir() {
    72 		return $this->find_folder(WP_CONTENT_DIR);
    70 		return $this->find_folder(WP_CONTENT_DIR);
    73 	}
    71 	}
    74 
    72 
    75 	/**
    73 	/**
    76 	 * Return the path on the remote filesystem of WP_PLUGIN_DIR.
    74 	 * Return the path on the remote filesystem of WP_PLUGIN_DIR.
    78 	 * @access public
    76 	 * @access public
    79 	 * @since 2.7.0
    77 	 * @since 2.7.0
    80 	 *
    78 	 *
    81 	 * @return string The location of the remote path.
    79 	 * @return string The location of the remote path.
    82 	 */
    80 	 */
    83 	function wp_plugins_dir() {
    81 	public function wp_plugins_dir() {
    84 		return $this->find_folder(WP_PLUGIN_DIR);
    82 		return $this->find_folder(WP_PLUGIN_DIR);
    85 	}
    83 	}
    86 
    84 
    87 	/**
    85 	/**
    88 	 * Return the path on the remote filesystem of the Themes Directory.
    86 	 * Return the path on the remote filesystem of the Themes Directory.
    91 	 * @since 2.7.0
    89 	 * @since 2.7.0
    92 	 *
    90 	 *
    93 	 * @param string $theme The Theme stylesheet or template for the directory.
    91 	 * @param string $theme The Theme stylesheet or template for the directory.
    94 	 * @return string The location of the remote path.
    92 	 * @return string The location of the remote path.
    95 	 */
    93 	 */
    96 	function wp_themes_dir( $theme = false ) {
    94 	public function wp_themes_dir( $theme = false ) {
    97 		$theme_root = get_theme_root( $theme );
    95 		$theme_root = get_theme_root( $theme );
    98 
    96 
    99 		// Account for relative theme roots
    97 		// Account for relative theme roots
   100 		if ( '/themes' == $theme_root || ! is_dir( $theme_root ) )
    98 		if ( '/themes' == $theme_root || ! is_dir( $theme_root ) )
   101 			$theme_root = WP_CONTENT_DIR . $theme_root;
    99 			$theme_root = WP_CONTENT_DIR . $theme_root;
   109 	 * @access public
   107 	 * @access public
   110 	 * @since 3.2.0
   108 	 * @since 3.2.0
   111 	 *
   109 	 *
   112 	 * @return string The location of the remote path.
   110 	 * @return string The location of the remote path.
   113 	 */
   111 	 */
   114 	function wp_lang_dir() {
   112 	public function wp_lang_dir() {
   115 		return $this->find_folder(WP_LANG_DIR);
   113 		return $this->find_folder(WP_LANG_DIR);
   116 	}
   114 	}
   117 
   115 
   118 	/**
   116 	/**
   119 	 * Locate a folder on the remote filesystem.
   117 	 * Locate a folder on the remote filesystem.
   130 	 * @param string $base The folder to start searching from.
   128 	 * @param string $base The folder to start searching from.
   131 	 * @param bool   $echo True to display debug information.
   129 	 * @param bool   $echo True to display debug information.
   132 	 *                     Default false.
   130 	 *                     Default false.
   133 	 * @return string The location of the remote path.
   131 	 * @return string The location of the remote path.
   134 	 */
   132 	 */
   135 	function find_base_dir( $base = '.', $echo = false ) {
   133 	public function find_base_dir( $base = '.', $echo = false ) {
   136 		_deprecated_function(__FUNCTION__, '2.7', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
   134 		_deprecated_function(__FUNCTION__, '2.7', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
   137 		$this->verbose = $echo;
   135 		$this->verbose = $echo;
   138 		return $this->abspath();
   136 		return $this->abspath();
   139 	}
   137 	}
   140 
   138 
   152 	 *
   150 	 *
   153 	 * @param string $base The folder to start searching from.
   151 	 * @param string $base The folder to start searching from.
   154 	 * @param bool   $echo True to display debug information.
   152 	 * @param bool   $echo True to display debug information.
   155 	 * @return string The location of the remote path.
   153 	 * @return string The location of the remote path.
   156 	 */
   154 	 */
   157 	function get_base_dir( $base = '.', $echo = false ) {
   155 	public function get_base_dir( $base = '.', $echo = false ) {
   158 		_deprecated_function(__FUNCTION__, '2.7', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
   156 		_deprecated_function(__FUNCTION__, '2.7', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
   159 		$this->verbose = $echo;
   157 		$this->verbose = $echo;
   160 		return $this->abspath();
   158 		return $this->abspath();
   161 	}
   159 	}
   162 
   160 
   168 	 *
   166 	 *
   169 	 * @access public
   167 	 * @access public
   170 	 * @since 2.7.0
   168 	 * @since 2.7.0
   171 	 *
   169 	 *
   172 	 * @param string $folder the folder to locate.
   170 	 * @param string $folder the folder to locate.
   173 	 * @return string The location of the remote path.
   171 	 * @return string|false The location of the remote path, false on failure.
   174 	 */
   172 	 */
   175 	function find_folder( $folder ) {
   173 	public function find_folder( $folder ) {
   176 
   174 
   177 		if ( isset( $this->cache[ $folder ] ) )
   175 		if ( isset( $this->cache[ $folder ] ) )
   178 			return $this->cache[ $folder ];
   176 			return $this->cache[ $folder ];
   179 
   177 
   180 		if ( stripos($this->method, 'ftp') !== false ) {
   178 		if ( stripos($this->method, 'ftp') !== false ) {
   231 	/**
   229 	/**
   232 	 * Locate a folder on the remote filesystem.
   230 	 * Locate a folder on the remote filesystem.
   233 	 *
   231 	 *
   234 	 * Expects Windows sanitized path.
   232 	 * Expects Windows sanitized path.
   235 	 *
   233 	 *
   236 	 * @access private
       
   237 	 * @since 2.7.0
   234 	 * @since 2.7.0
   238 	 *
   235 	 *
   239 	 * @param string $folder The folder to locate.
   236 	 * @param string $folder The folder to locate.
   240 	 * @param string $base   The folder to start searching from.
   237 	 * @param string $base   The folder to start searching from.
   241 	 * @param bool   $loop   If the function has recursed, Internal use only.
   238 	 * @param bool   $loop   If the function has recursed, Internal use only.
   242 	 * @return string The location of the remote path.
   239 	 * @return string|false The location of the remote path, false to cease looping.
   243 	 */
   240 	 */
   244 	function search_for_folder( $folder, $base = '.', $loop = false ) {
   241 	public function search_for_folder( $folder, $base = '.', $loop = false ) {
   245 		if ( empty( $base ) || '.' == $base )
   242 		if ( empty( $base ) || '.' == $base )
   246 			$base = trailingslashit($this->cwd());
   243 			$base = trailingslashit($this->cwd());
   247 
   244 
   248 		$folder = untrailingslashit($folder);
   245 		$folder = untrailingslashit($folder);
   249 
   246 
   259 
   256 
   260 		foreach ( $folder_parts as $index => $key ) {
   257 		foreach ( $folder_parts as $index => $key ) {
   261 			if ( $index == $last_index )
   258 			if ( $index == $last_index )
   262 				continue; // We want this to be caught by the next code block.
   259 				continue; // We want this to be caught by the next code block.
   263 
   260 
   264 			// Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,
   261 			/*
   265 			// If it's found, change into it and follow through looking for it.
   262 			 * Working from /home/ to /user/ to /wordpress/ see if that file exists within
   266 			// If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on.
   263 			 * the current folder, If it's found, change into it and follow through looking
   267 			// If it reaches the end, and still cant find it, it'll return false for the entire function.
   264 			 * for it. If it cant find WordPress down that route, it'll continue onto the next
       
   265 			 * folder level, and see if that matches, and so on. If it reaches the end, and still
       
   266 			 * cant find it, it'll return false for the entire function.
       
   267 			 */
   268 			if ( isset($files[ $key ]) ){
   268 			if ( isset($files[ $key ]) ){
   269 				// Lets try that folder:
   269 
       
   270 				// Let's try that folder:
   270 				$newdir = trailingslashit(path_join($base, $key));
   271 				$newdir = trailingslashit(path_join($base, $key));
   271 				if ( $this->verbose )
   272 				if ( $this->verbose )
   272 					printf( "\n" . __('Changing to %s') . "<br/>\n", $newdir );
   273 					printf( "\n" . __('Changing to %s') . "<br/>\n", $newdir );
   273 				// only search for the remaining path tokens in the directory, not the full path again
   274 
       
   275 				// Only search for the remaining path tokens in the directory, not the full path again.
   274 				$newfolder = implode( '/', array_slice( $folder_parts, $index + 1 ) );
   276 				$newfolder = implode( '/', array_slice( $folder_parts, $index + 1 ) );
   275 				if ( $ret = $this->search_for_folder( $newfolder, $newdir, $loop) )
   277 				if ( $ret = $this->search_for_folder( $newfolder, $newdir, $loop) )
   276 					return $ret;
   278 					return $ret;
   277 			}
   279 			}
   278 		}
   280 		}
   306 	 * @since 2.5.0
   308 	 * @since 2.5.0
   307 	 *
   309 	 *
   308 	 * @param string $file String filename.
   310 	 * @param string $file String filename.
   309 	 * @return string The *nix-style representation of permissions.
   311 	 * @return string The *nix-style representation of permissions.
   310 	 */
   312 	 */
   311 	function gethchmod( $file ){
   313 	public function gethchmod( $file ){
   312 		$perms = $this->getchmod($file);
   314 		$perms = $this->getchmod($file);
   313 		if (($perms & 0xC000) == 0xC000) // Socket
   315 		if (($perms & 0xC000) == 0xC000) // Socket
   314 			$info = 's';
   316 			$info = 's';
   315 		elseif (($perms & 0xA000) == 0xA000) // Symbolic Link
   317 		elseif (($perms & 0xA000) == 0xA000) // Symbolic Link
   316 			$info = 'l';
   318 			$info = 'l';
   362 	 * @since 2.5.0
   364 	 * @since 2.5.0
   363 	 *
   365 	 *
   364 	 * @param string $mode string The *nix-style file permission.
   366 	 * @param string $mode string The *nix-style file permission.
   365 	 * @return int octal representation
   367 	 * @return int octal representation
   366 	 */
   368 	 */
   367 	function getnumchmodfromh( $mode ) {
   369 	public function getnumchmodfromh( $mode ) {
   368 		$realmode = '';
   370 		$realmode = '';
   369 		$legal =  array('', 'w', 'r', 'x', '-');
   371 		$legal =  array('', 'w', 'r', 'x', '-');
   370 		$attarray = preg_split('//', $mode);
   372 		$attarray = preg_split('//', $mode);
   371 
   373 
   372 		for ($i=0; $i < count($attarray); $i++)
   374 		for ( $i = 0, $c = count( $attarray ); $i < $c; $i++ ) {
   373 		   if ($key = array_search($attarray[$i], $legal))
   375 		   if ($key = array_search($attarray[$i], $legal)) {
   374 			   $realmode .= $legal[$key];
   376 			   $realmode .= $legal[$key];
       
   377 		   }
       
   378 		}
   375 
   379 
   376 		$mode = str_pad($realmode, 10, '-', STR_PAD_LEFT);
   380 		$mode = str_pad($realmode, 10, '-', STR_PAD_LEFT);
   377 		$trans = array('-'=>'0', 'r'=>'4', 'w'=>'2', 'x'=>'1');
   381 		$trans = array('-'=>'0', 'r'=>'4', 'w'=>'2', 'x'=>'1');
   378 		$mode = strtr($mode,$trans);
   382 		$mode = strtr($mode,$trans);
   379 
   383 
   385 	}
   389 	}
   386 
   390 
   387 	/**
   391 	/**
   388 	 * Determine if the string provided contains binary characters.
   392 	 * Determine if the string provided contains binary characters.
   389 	 *
   393 	 *
   390 	 * @access private
       
   391 	 * @since 2.7.0
   394 	 * @since 2.7.0
   392 	 *
   395 	 *
   393 	 * @param string $text String to test against.
   396 	 * @param string $text String to test against.
   394 	 * @return bool true if string is binary, false otherwise.
   397 	 * @return bool true if string is binary, false otherwise.
   395 	 */
   398 	 */
   396 	function is_binary( $text ) {
   399 	public function is_binary( $text ) {
   397 		return (bool) preg_match( '|[^\x20-\x7E]|', $text ); // chr(32)..chr(127)
   400 		return (bool) preg_match( '|[^\x20-\x7E]|', $text ); // chr(32)..chr(127)
   398 	}
   401 	}
   399 
   402 
   400 	/**
   403 	/**
   401 	 * Change the ownership of a file / folder.
   404 	 * Change the ownership of a file / folder.
   407 	 * @param string $file      Path to the file.
   410 	 * @param string $file      Path to the file.
   408 	 * @param mixed  $owner     A user name or number.
   411 	 * @param mixed  $owner     A user name or number.
   409 	 * @param bool   $recursive Optional. If set True changes file owner recursivly. Defaults to False.
   412 	 * @param bool   $recursive Optional. If set True changes file owner recursivly. Defaults to False.
   410 	 * @return bool Returns true on success or false on failure.
   413 	 * @return bool Returns true on success or false on failure.
   411 	 */
   414 	 */
   412 	function chown( $file, $owner, $recursive = false ) {
   415 	public function chown( $file, $owner, $recursive = false ) {
   413 		return false;
   416 		return false;
   414 	}
   417 	}
   415 
   418 
   416 	/**
   419 	/**
   417 	 * Connect filesystem.
   420 	 * Connect filesystem.
   418 	 *
   421 	 *
   419 	 * @since 2.5.0
   422 	 * @since 2.5.0
   420 	 *
   423 	 * @abstract
   421 	 * @return bool True on success or false on failure (always true for WP_Filesystem_Direct).
   424 	 * @return bool True on success or false on failure (always true for WP_Filesystem_Direct).
   422 	 */
   425 	 */
   423 	function connect() {
   426 	public function connect() {
   424 		return true;
   427 		return true;
   425 	}
   428 	}
   426 
   429 
   427 	/**
   430 	/**
   428 	 * Read entire file into a string.
   431 	 * Read entire file into a string.
   429 	 *
   432 	 *
   430 	 * @since 2.5.0
   433 	 * @since 2.5.0
   431 	 *
   434 	 * @abstract
   432 	 * @param string $file Name of the file to read.
   435 	 * @param string $file Name of the file to read.
   433 	 * @return string|bool Returns the read data or false on failure.
   436 	 * @return mixed|bool Returns the read data or false on failure.
   434 	 */
   437 	 */
   435 	function get_contents( $file ) {
   438 	public function get_contents( $file ) {
   436 		return false;
   439 		return false;
   437 	}
   440 	}
   438 
   441 
   439 	/**
   442 	/**
   440 	 * Read entire file into an array.
   443 	 * Read entire file into an array.
   441 	 *
   444 	 *
   442 	 * @since 2.5.0
   445 	 * @since 2.5.0
   443 	 *
   446 	 * @abstract
   444 	 * @param string $file Path to the file.
   447 	 * @param string $file Path to the file.
   445 	 * @return array|bool the file contents in an array or false on failure.
   448 	 * @return array|bool the file contents in an array or false on failure.
   446 	 */
   449 	 */
   447 	function get_contents_array( $file ) {
   450 	public function get_contents_array( $file ) {
   448 		return false;
   451 		return false;
   449 	}
   452 	}
   450 
   453 
   451 	/**
   454 	/**
   452 	 * Write a string to a file.
   455 	 * Write a string to a file.
   453 	 *
   456 	 *
   454 	 * @since 2.5.0
   457 	 * @since 2.5.0
   455 	 *
   458 	 * @abstract
   456 	 * @param string $file     Remote path to the file where to write the data.
   459 	 * @param string $file     Remote path to the file where to write the data.
   457 	 * @param string $contents The data to write.
   460 	 * @param string $contents The data to write.
   458 	 * @param int    $mode     Optional. The file permissions as octal number, usually 0644.
   461 	 * @param int    $mode     Optional. The file permissions as octal number, usually 0644.
   459 	 * @return bool False on failure.
   462 	 * @return bool False on failure.
   460 	 */
   463 	 */
   461 	function put_contents( $file, $contents, $mode = false ) {
   464 	public function put_contents( $file, $contents, $mode = false ) {
   462 		return false;
   465 		return false;
   463 	}
   466 	}
   464 
   467 
   465 	/**
   468 	/**
   466 	 * Get the current working directory.
   469 	 * Get the current working directory.
   467 	 *
   470 	 *
   468 	 * @since 2.5.0
   471 	 * @since 2.5.0
   469 	 *
   472 	 * @abstract
   470 	 * @return string|bool The current working directory on success, or false on failure.
   473 	 * @return string|bool The current working directory on success, or false on failure.
   471 	 */
   474 	 */
   472 	function cwd() {
   475 	public function cwd() {
   473 		return false;
   476 		return false;
   474 	}
   477 	}
   475 
   478 
   476 	/**
   479 	/**
   477 	 * Change current directory.
   480 	 * Change current directory.
   478 	 *
   481 	 *
   479 	 * @since 2.5.0
   482 	 * @since 2.5.0
   480 	 *
   483 	 * @abstract
   481 	 * @param string $dir The new current directory.
   484 	 * @param string $dir The new current directory.
   482 	 * @return bool Returns true on success or false on failure.
   485 	 * @return bool Returns true on success or false on failure.
   483 	 */
   486 	 */
   484 	function chdir( $dir ) {
   487 	public function chdir( $dir ) {
   485 		return false;
   488 		return false;
   486 	}
   489 	}
   487 
   490 
   488 	/**
   491 	/**
   489 	 * Change the file group.
   492 	 * Change the file group.
   490 	 *
   493 	 *
   491 	 * @since 2.5.0
   494 	 * @since 2.5.0
   492 	 *
   495 	 * @abstract
   493 	 * @param string $file      Path to the file.
   496 	 * @param string $file      Path to the file.
   494 	 * @param mixed  $group     A group name or number.
   497 	 * @param mixed  $group     A group name or number.
   495 	 * @param bool   $recursive Optional. If set True changes file group recursively. Defaults to False.
   498 	 * @param bool   $recursive Optional. If set True changes file group recursively. Defaults to False.
   496 	 * @return bool Returns true on success or false on failure.
   499 	 * @return bool Returns true on success or false on failure.
   497 	 */
   500 	 */
   498 	function chgrp( $file, $group, $recursive = false ) {
   501 	public function chgrp( $file, $group, $recursive = false ) {
   499 		return false;
   502 		return false;
   500 	}
   503 	}
   501 
   504 
   502 	/**
   505 	/**
   503 	 * Change filesystem permissions.
   506 	 * Change filesystem permissions.
   504 	 *
   507 	 *
   505 	 * @since 2.5.0
   508 	 * @since 2.5.0
   506 	 *
   509 	 * @abstract
   507 	 * @param string $file      Path to the file.
   510 	 * @param string $file      Path to the file.
   508 	 * @param int    $mode      Optional. The permissions as octal number, usually 0644 for files, 0755 for dirs.
   511 	 * @param int    $mode      Optional. The permissions as octal number, usually 0644 for files, 0755 for dirs.
   509 	 * @param bool   $recursive Optional. If set True changes file group recursively. Defaults to False.
   512 	 * @param bool   $recursive Optional. If set True changes file group recursively. Defaults to False.
   510 	 * @return bool Returns true on success or false on failure.
   513 	 * @return bool Returns true on success or false on failure.
   511 	 */
   514 	 */
   512 	function chmod( $file, $mode = false, $recursive = false ) {
   515 	public function chmod( $file, $mode = false, $recursive = false ) {
   513 		return false;
   516 		return false;
   514 	}
   517 	}
   515 
   518 
   516 	/**
   519 	/**
   517 	 * Get the file owner.
   520 	 * Get the file owner.
   518 	 *
   521 	 *
   519 	 * @since 2.5.0
   522 	 * @since 2.5.0
   520 	 *
   523 	 * @abstract
   521 	 * @param string $file Path to the file.
   524 	 * @param string $file Path to the file.
   522 	 * @return string|bool Username of the user or false on error.
   525 	 * @return string|bool Username of the user or false on error.
   523 	 */
   526 	 */
   524 	function owner( $file ) {
   527 	public function owner( $file ) {
   525 		return false;
   528 		return false;
   526 	}
   529 	}
   527 
   530 
   528 	/**
   531 	/**
   529 	 * Get the file's group.
   532 	 * Get the file's group.
   530 	 *
   533 	 *
   531 	 * @since 2.5.0
   534 	 * @since 2.5.0
   532 	 *
   535 	 * @abstract
   533 	 * @param string $file Path to the file.
   536 	 * @param string $file Path to the file.
   534 	 * @return string|bool The group or false on error.
   537 	 * @return string|bool The group or false on error.
   535 	 */
   538 	 */
   536 	function group( $file ) {
   539 	public function group( $file ) {
   537 		return false;
   540 		return false;
   538 	}
   541 	}
   539 
   542 
   540 	/**
   543 	/**
   541 	 * Copy a file.
   544 	 * Copy a file.
   542 	 *
   545 	 *
   543 	 * @since 2.5.0
   546 	 * @since 2.5.0
   544 	 *
   547 	 * @abstract
   545 	 * @param string $source      Path to the source file.
   548 	 * @param string $source      Path to the source file.
   546 	 * @param string $destination Path to the destination file.
   549 	 * @param string $destination Path to the destination file.
   547 	 * @param bool   $overwrite   Optional. Whether to overwrite the destination file if it exists.
   550 	 * @param bool   $overwrite   Optional. Whether to overwrite the destination file if it exists.
   548 	 *                            Default false.
   551 	 *                            Default false.
   549 	 * @param int    $mode        Optional. The permissions as octal number, usually 0644 for files, 0755 for dirs.
   552 	 * @param int    $mode        Optional. The permissions as octal number, usually 0644 for files, 0755 for dirs.
   550 	 *                            Default false.
   553 	 *                            Default false.
   551 	 * @return bool True if file copied successfully, False otherwise.
   554 	 * @return bool True if file copied successfully, False otherwise.
   552 	 */
   555 	 */
   553 	function copy( $source, $destination, $overwrite = false, $mode = false ) {
   556 	public function copy( $source, $destination, $overwrite = false, $mode = false ) {
   554 		return false;
   557 		return false;
   555 	}
   558 	}
   556 
   559 
   557 	/**
   560 	/**
   558 	 * Move a file.
   561 	 * Move a file.
   559 	 *
   562 	 *
   560 	 * @since 2.5.0
   563 	 * @since 2.5.0
   561 	 *
   564 	 * @abstract
   562 	 * @param string $source      Path to the source file.
   565 	 * @param string $source      Path to the source file.
   563 	 * @param string $destination Path to the destination file.
   566 	 * @param string $destination Path to the destination file.
   564 	 * @param bool   $overwrite   Optional. Whether to overwrite the destination file if it exists.
   567 	 * @param bool   $overwrite   Optional. Whether to overwrite the destination file if it exists.
   565 	 *                            Default false.
   568 	 *                            Default false.
   566 	 * @return bool True if file copied successfully, False otherwise.
   569 	 * @return bool True if file copied successfully, False otherwise.
   567 	 */
   570 	 */
   568 	function move( $source, $destination, $overwrite = false ) {
   571 	public function move( $source, $destination, $overwrite = false ) {
   569 		return false;
   572 		return false;
   570 	}
   573 	}
   571 
   574 
   572 	/**
   575 	/**
   573 	 * Delete a file or directory.
   576 	 * Delete a file or directory.
   574 	 *
   577 	 *
   575 	 * @since 2.5.0
   578 	 * @since 2.5.0
   576 	 *
   579 	 * @abstract
   577 	 * @param string $file      Path to the file.
   580 	 * @param string $file      Path to the file.
   578 	 * @param bool   $recursive Optional. If set True changes file group recursively. Defaults to False.
   581 	 * @param bool   $recursive Optional. If set True changes file group recursively. Defaults to False.
   579 	 *                          Default false.
   582 	 *                          Default false.
   580 	 * @param bool   $type      Type of resource. 'f' for file, 'd' for directory.
   583 	 * @param bool   $type      Type of resource. 'f' for file, 'd' for directory.
   581 	 *                          Default false.
   584 	 *                          Default false.
   582 	 * @return bool True if the file or directory was deleted, false on failure.
   585 	 * @return bool True if the file or directory was deleted, false on failure.
   583 	 */
   586 	 */
   584 	function delete( $file, $recursive = false, $type = false ) {
   587 	public function delete( $file, $recursive = false, $type = false ) {
   585 		return false;
   588 		return false;
   586 	}
   589 	}
   587 
   590 
   588 	/**
   591 	/**
   589 	 * Check if a file or directory exists.
   592 	 * Check if a file or directory exists.
   590 	 *
   593 	 *
   591 	 * @since 2.5.0
   594 	 * @since 2.5.0
   592 	 *
   595 	 * @abstract
   593 	 * @param string $file Path to file/directory.
   596 	 * @param string $file Path to file/directory.
   594 	 * @return bool Whether $file exists or not.
   597 	 * @return bool Whether $file exists or not.
   595 	 */
   598 	 */
   596 	function exists( $file ) {
   599 	public function exists( $file ) {
   597 		return false;
   600 		return false;
   598 	}
   601 	}
   599 
   602 
   600 	/**
   603 	/**
   601 	 * Check if resource is a file.
   604 	 * Check if resource is a file.
   602 	 *
   605 	 *
   603 	 * @since 2.5.0
   606 	 * @since 2.5.0
   604 	 *
   607 	 * @abstract
   605 	 * @param string $file File path.
   608 	 * @param string $file File path.
   606 	 * @return bool Whether $file is a file.
   609 	 * @return bool Whether $file is a file.
   607 	 */
   610 	 */
   608 	function is_file( $file ) {
   611 	public function is_file( $file ) {
   609 		return false;
   612 		return false;
   610 	}
   613 	}
   611 
   614 
   612 	/**
   615 	/**
   613 	 * Check if resource is a directory.
   616 	 * Check if resource is a directory.
   614 	 *
   617 	 *
   615 	 * @since 2.5.0
   618 	 * @since 2.5.0
   616 	 *
   619 	 * @abstract
   617 	 * @param string $path Directory path.
   620 	 * @param string $path Directory path.
   618 	 * @return bool Whether $path is a directory.
   621 	 * @return bool Whether $path is a directory.
   619 	 */
   622 	 */
   620 	function is_dir( $path ) {
   623 	public function is_dir( $path ) {
   621 		return false;
   624 		return false;
   622 	}
   625 	}
   623 
   626 
   624 	/**
   627 	/**
   625 	 * Check if a file is readable.
   628 	 * Check if a file is readable.
   626 	 *
   629 	 *
   627 	 * @since 2.5.0
   630 	 * @since 2.5.0
   628 	 *
   631 	 * @abstract
   629 	 * @param string $file Path to file.
   632 	 * @param string $file Path to file.
   630 	 * @return bool Whether $file is readable.
   633 	 * @return bool Whether $file is readable.
   631 	 */
   634 	 */
   632 	function is_readable( $file ) {
   635 	public function is_readable( $file ) {
   633 		return false;
   636 		return false;
   634 	}
   637 	}
   635 
   638 
   636 	/**
   639 	/**
   637 	 * Check if a file or directory is writable.
   640 	 * Check if a file or directory is writable.
   638 	 *
   641 	 *
   639 	 * @since 2.5.0
   642 	 * @since 2.5.0
   640 	 *
   643 	 * @abstract
   641 	 * @param string $path Path to file/directory.
       
   642 	 * @return bool Whether $file is writable.
   644 	 * @return bool Whether $file is writable.
   643 	 */
   645 	 */
   644 	function is_writable( $file ) {
   646 	public function is_writable( $file ) {
   645 		return false;
   647 		return false;
   646 	}
   648 	}
   647 
   649 
   648 	/**
   650 	/**
   649 	 * Gets the file's last access time.
   651 	 * Gets the file's last access time.
   650 	 *
   652 	 *
   651 	 * @since 2.5.0
   653 	 * @since 2.5.0
   652 	 *
   654 	 * @abstract
   653 	 * @param string $file Path to file.
   655 	 * @param string $file Path to file.
   654 	 * @return int Unix timestamp representing last access time.
   656 	 * @return int|bool Unix timestamp representing last access time.
   655 	 */
   657 	 */
   656 	function atime( $file ) {
   658 	public function atime( $file ) {
   657 		return false;
   659 		return false;
   658 	}
   660 	}
   659 
   661 
   660 	/**
   662 	/**
   661 	 * Gets the file modification time.
   663 	 * Gets the file modification time.
   662 	 *
   664 	 *
   663 	 * @since 2.5.0
   665 	 * @since 2.5.0
   664 	 *
   666 	 * @abstract
   665 	 * @param string $file Path to file.
   667 	 * @param string $file Path to file.
   666 	 * @return int Unix timestamp representing modification time.
   668 	 * @return int|bool Unix timestamp representing modification time.
   667 	 */
   669 	 */
   668 	function mtime( $file ) {
   670 	public function mtime( $file ) {
   669 		return false;
   671 		return false;
   670 	}
   672 	}
   671 
   673 
   672 	/**
   674 	/**
   673 	 * Gets the file size (in bytes).
   675 	 * Gets the file size (in bytes).
   674 	 *
   676 	 *
   675 	 * @since 2.5.0
   677 	 * @since 2.5.0
   676 	 *
   678 	 * @abstract
   677 	 * @param string $file Path to file.
   679 	 * @param string $file Path to file.
   678 	 * @return int Size of the file in bytes.
   680 	 * @return int|bool Size of the file in bytes.
   679 	 */
   681 	 */
   680 	function size( $file ) {
   682 	public function size( $file ) {
   681 		return false;
   683 		return false;
   682 	}
   684 	}
   683 
   685 
   684 	/**
   686 	/**
   685 	 * Set the access and modification times of a file.
   687 	 * Set the access and modification times of a file.
   686 	 *
   688 	 *
   687 	 * Note: If $file doesn't exist, it will be created.
   689 	 * Note: If $file doesn't exist, it will be created.
   688 	 *
   690 	 *
   689 	 * @since 2.5.0
   691 	 * @since 2.5.0
   690 	 *
   692 	 * @abstract
   691 	 * @param string $file  Path to file.
   693 	 * @param string $file  Path to file.
   692 	 * @param int    $time  Optional. Modified time to set for file.
   694 	 * @param int    $time  Optional. Modified time to set for file.
   693 	 *                      Default 0.
   695 	 *                      Default 0.
   694 	 * @param int    $atime Optional. Access time to set for file.
   696 	 * @param int    $atime Optional. Access time to set for file.
   695 	 *                      Default 0.
   697 	 *                      Default 0.
   696 	 * @return bool Whether operation was successful or not.
   698 	 * @return bool Whether operation was successful or not.
   697 	 */
   699 	 */
   698 	function touch( $file, $time = 0, $atime = 0 ) {
   700 	public function touch( $file, $time = 0, $atime = 0 ) {
   699 		return false;
   701 		return false;
   700 	}
   702 	}
   701 
   703 
   702 	/**
   704 	/**
   703 	 * Create a directory.
   705 	 * Create a directory.
   704 	 *
   706 	 *
   705 	 * @since 2.5.0
   707 	 * @since 2.5.0
   706 	 *
   708 	 * @abstract
   707 	 * @param string $path  Path for new directory.
   709 	 * @param string $path  Path for new directory.
   708 	 * @param mixed  $chmod Optional. The permissions as octal number, (or False to skip chmod)
   710 	 * @param mixed  $chmod Optional. The permissions as octal number, (or False to skip chmod)
   709 	 *                      Default false.
   711 	 *                      Default false.
   710 	 * @param mixed  $chown Optional. A user name or number (or False to skip chown)
   712 	 * @param mixed  $chown Optional. A user name or number (or False to skip chown)
   711 	 *                      Default false.
   713 	 *                      Default false.
   712 	 * @param mixed  $chgrp Optional. A group name or number (or False to skip chgrp).
   714 	 * @param mixed  $chgrp Optional. A group name or number (or False to skip chgrp).
   713 	 *                      Default false.
   715 	 *                      Default false.
   714 	 * @return bool False if directory cannot be created, true otherwise.
   716 	 * @return bool False if directory cannot be created, true otherwise.
   715 	 */
   717 	 */
   716 	function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
   718 	public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
   717 		return false;
   719 		return false;
   718 	}
   720 	}
   719 
   721 
   720 	/**
   722 	/**
   721 	 * Delete a directory.
   723 	 * Delete a directory.
   722 	 *
   724 	 *
   723 	 * @since 2.5.0
   725 	 * @since 2.5.0
   724 	 *
   726 	 * @abstract
   725 	 * @param string $path      Path to directory.
   727 	 * @param string $path      Path to directory.
   726 	 * @param bool   $recursive Optional. Whether to recursively remove files/directories.
   728 	 * @param bool   $recursive Optional. Whether to recursively remove files/directories.
   727 	 *                          Default false.
   729 	 *                          Default false.
   728 	 * @return bool Whether directory is deleted successfully or not.
   730 	 * @return bool Whether directory is deleted successfully or not.
   729 	 */
   731 	 */
   730 	function rmdir( $path, $recursive = false ) {
   732 	public function rmdir( $path, $recursive = false ) {
   731 		return false;
   733 		return false;
   732 	}
   734 	}
   733 
   735 
   734 	/**
   736 	/**
   735 	 * Get details for files in a directory or a specific file.
   737 	 * Get details for files in a directory or a specific file.
   736 	 *
   738 	 *
   737 	 * @since 2.5.0
   739 	 * @since 2.5.0
       
   740 	 * @abstract
   738 	 *
   741 	 *
   739 	 * @param string $path           Path to directory or file.
   742 	 * @param string $path           Path to directory or file.
   740 	 * @param bool   $include_hidden Optional. Whether to include details of hidden ("." prefixed) files.
   743 	 * @param bool   $include_hidden Optional. Whether to include details of hidden ("." prefixed) files.
   741 	 *                               Default true.
   744 	 *                               Default true.
   742 	 * @param bool   $recursive      Optional. Whether to recursively include file details in nested directories.
   745 	 * @param bool   $recursive      Optional. Whether to recursively include file details in nested directories.
   743 	 *                               Default false.
   746 	 *                               Default false.
   744 	 * @return array|bool {
   747 	 * @return array|bool {
   745 	 *     Array of files. False if unable to list directory contents.
   748 	 *     Array of files. False if unable to list directory contents.
   746 	 *
   749 	 *
   747 	 *     @type string 'name'        Name of the file/directory.
   750 	 *     @type string $name        Name of the file/directory.
   748 	 *     @type string 'perms'       *nix representation of permissions.
   751 	 *     @type string $perms       *nix representation of permissions.
   749 	 *     @type int    'permsn'      Octal representation of permissions.
   752 	 *     @type int    $permsn      Octal representation of permissions.
   750 	 *     @type string 'owner'       Owner name or ID.
   753 	 *     @type string $owner       Owner name or ID.
   751 	 *     @type int    'size'        Size of file in bytes.
   754 	 *     @type int    $size        Size of file in bytes.
   752 	 *     @type int    'lastmodunix' Last modified unix timestamp.
   755 	 *     @type int    $lastmodunix Last modified unix timestamp.
   753 	 *     @type mixed  'lastmod'     Last modified month (3 letter) and day (without leading 0).
   756 	 *     @type mixed  $lastmod     Last modified month (3 letter) and day (without leading 0).
   754 	 *     @type int    'time'        Last modified time.
   757 	 *     @type int    $time        Last modified time.
   755 	 *     @type string 'type'        Type of resource. 'f' for file, 'd' for directory.
   758 	 *     @type string $type        Type of resource. 'f' for file, 'd' for directory.
   756 	 *     @type mixed  'files'       If a directory and $recursive is true, contains another array of files.
   759 	 *     @type mixed  $files       If a directory and $recursive is true, contains another array of files.
   757 	 * }
   760 	 * }
   758 	 */
   761 	 */
   759 	function dirlist( $path, $include_hidden = true, $recursive = false ) {
   762 	public function dirlist( $path, $include_hidden = true, $recursive = false ) {
   760 		return false;
   763 		return false;
   761 	}
   764 	}
   762 
   765 
   763 } // WP_Filesystem_Base
   766 } // WP_Filesystem_Base