class-wp-filesystem-base.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. <?php
  2. /**
  3. * Base WordPress Filesystem
  4. *
  5. * @package WordPress
  6. * @subpackage Filesystem
  7. */
  8. /**
  9. * Base WordPress Filesystem class for which Filesystem implementations extend
  10. *
  11. * @since 2.5.0
  12. */
  13. class WP_Filesystem_Base {
  14. /**
  15. * Whether to display debug data for the connection.
  16. *
  17. * @since 2.5.0
  18. * @var bool
  19. */
  20. public $verbose = false;
  21. /**
  22. * Cached list of local filepaths to mapped remote filepaths.
  23. *
  24. * @since 2.7.0
  25. * @var array
  26. */
  27. public $cache = array();
  28. /**
  29. * The Access method of the current connection, Set automatically.
  30. *
  31. * @since 2.5.0
  32. * @var string
  33. */
  34. public $method = '';
  35. /**
  36. * @var WP_Error
  37. */
  38. public $errors = null;
  39. /**
  40. */
  41. public $options = array();
  42. /**
  43. * Return the path on the remote filesystem of ABSPATH.
  44. *
  45. * @since 2.7.0
  46. *
  47. * @return string The location of the remote path.
  48. */
  49. public function abspath() {
  50. $folder = $this->find_folder(ABSPATH);
  51. // Perhaps the FTP folder is rooted at the WordPress install, Check for wp-includes folder in root, Could have some false positives, but rare.
  52. if ( ! $folder && $this->is_dir( '/' . WPINC ) )
  53. $folder = '/';
  54. return $folder;
  55. }
  56. /**
  57. * Return the path on the remote filesystem of WP_CONTENT_DIR.
  58. *
  59. * @since 2.7.0
  60. *
  61. * @return string The location of the remote path.
  62. */
  63. public function wp_content_dir() {
  64. return $this->find_folder(WP_CONTENT_DIR);
  65. }
  66. /**
  67. * Return the path on the remote filesystem of WP_PLUGIN_DIR.
  68. *
  69. * @since 2.7.0
  70. *
  71. * @return string The location of the remote path.
  72. */
  73. public function wp_plugins_dir() {
  74. return $this->find_folder(WP_PLUGIN_DIR);
  75. }
  76. /**
  77. * Return the path on the remote filesystem of the Themes Directory.
  78. *
  79. * @since 2.7.0
  80. *
  81. * @param string $theme The Theme stylesheet or template for the directory.
  82. * @return string The location of the remote path.
  83. */
  84. public function wp_themes_dir( $theme = false ) {
  85. $theme_root = get_theme_root( $theme );
  86. // Account for relative theme roots
  87. if ( '/themes' == $theme_root || ! is_dir( $theme_root ) )
  88. $theme_root = WP_CONTENT_DIR . $theme_root;
  89. return $this->find_folder( $theme_root );
  90. }
  91. /**
  92. * Return the path on the remote filesystem of WP_LANG_DIR.
  93. *
  94. * @since 3.2.0
  95. *
  96. * @return string The location of the remote path.
  97. */
  98. public function wp_lang_dir() {
  99. return $this->find_folder(WP_LANG_DIR);
  100. }
  101. /**
  102. * Locate a folder on the remote filesystem.
  103. *
  104. * @since 2.5.0
  105. * @deprecated 2.7.0 use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() instead.
  106. * @see WP_Filesystem::abspath()
  107. * @see WP_Filesystem::wp_content_dir()
  108. * @see WP_Filesystem::wp_plugins_dir()
  109. * @see WP_Filesystem::wp_themes_dir()
  110. * @see WP_Filesystem::wp_lang_dir()
  111. *
  112. * @param string $base The folder to start searching from.
  113. * @param bool $echo True to display debug information.
  114. * Default false.
  115. * @return string The location of the remote path.
  116. */
  117. public function find_base_dir( $base = '.', $echo = false ) {
  118. _deprecated_function(__FUNCTION__, '2.7.0', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
  119. $this->verbose = $echo;
  120. return $this->abspath();
  121. }
  122. /**
  123. * Locate a folder on the remote filesystem.
  124. *
  125. * @since 2.5.0
  126. * @deprecated 2.7.0 use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() methods instead.
  127. * @see WP_Filesystem::abspath()
  128. * @see WP_Filesystem::wp_content_dir()
  129. * @see WP_Filesystem::wp_plugins_dir()
  130. * @see WP_Filesystem::wp_themes_dir()
  131. * @see WP_Filesystem::wp_lang_dir()
  132. *
  133. * @param string $base The folder to start searching from.
  134. * @param bool $echo True to display debug information.
  135. * @return string The location of the remote path.
  136. */
  137. public function get_base_dir( $base = '.', $echo = false ) {
  138. _deprecated_function(__FUNCTION__, '2.7.0', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
  139. $this->verbose = $echo;
  140. return $this->abspath();
  141. }
  142. /**
  143. * Locate a folder on the remote filesystem.
  144. *
  145. * Assumes that on Windows systems, Stripping off the Drive
  146. * letter is OK Sanitizes \\ to / in windows filepaths.
  147. *
  148. * @since 2.7.0
  149. *
  150. * @param string $folder the folder to locate.
  151. * @return string|false The location of the remote path, false on failure.
  152. */
  153. public function find_folder( $folder ) {
  154. if ( isset( $this->cache[ $folder ] ) )
  155. return $this->cache[ $folder ];
  156. if ( stripos($this->method, 'ftp') !== false ) {
  157. $constant_overrides = array(
  158. 'FTP_BASE' => ABSPATH,
  159. 'FTP_CONTENT_DIR' => WP_CONTENT_DIR,
  160. 'FTP_PLUGIN_DIR' => WP_PLUGIN_DIR,
  161. 'FTP_LANG_DIR' => WP_LANG_DIR
  162. );
  163. // Direct matches ( folder = CONSTANT/ )
  164. foreach ( $constant_overrides as $constant => $dir ) {
  165. if ( ! defined( $constant ) )
  166. continue;
  167. if ( $folder === $dir )
  168. return trailingslashit( constant( $constant ) );
  169. }
  170. // Prefix Matches ( folder = CONSTANT/subdir )
  171. foreach ( $constant_overrides as $constant => $dir ) {
  172. if ( ! defined( $constant ) )
  173. continue;
  174. if ( 0 === stripos( $folder, $dir ) ) { // $folder starts with $dir
  175. $potential_folder = preg_replace( '#^' . preg_quote( $dir, '#' ) . '/#i', trailingslashit( constant( $constant ) ), $folder );
  176. $potential_folder = trailingslashit( $potential_folder );
  177. if ( $this->is_dir( $potential_folder ) ) {
  178. $this->cache[ $folder ] = $potential_folder;
  179. return $potential_folder;
  180. }
  181. }
  182. }
  183. } elseif ( 'direct' == $this->method ) {
  184. $folder = str_replace('\\', '/', $folder); // Windows path sanitisation
  185. return trailingslashit($folder);
  186. }
  187. $folder = preg_replace('|^([a-z]{1}):|i', '', $folder); // Strip out windows drive letter if it's there.
  188. $folder = str_replace('\\', '/', $folder); // Windows path sanitisation
  189. if ( isset($this->cache[ $folder ] ) )
  190. return $this->cache[ $folder ];
  191. if ( $this->exists($folder) ) { // Folder exists at that absolute path.
  192. $folder = trailingslashit($folder);
  193. $this->cache[ $folder ] = $folder;
  194. return $folder;
  195. }
  196. if ( $return = $this->search_for_folder($folder) )
  197. $this->cache[ $folder ] = $return;
  198. return $return;
  199. }
  200. /**
  201. * Locate a folder on the remote filesystem.
  202. *
  203. * Expects Windows sanitized path.
  204. *
  205. * @since 2.7.0
  206. *
  207. * @param string $folder The folder to locate.
  208. * @param string $base The folder to start searching from.
  209. * @param bool $loop If the function has recursed, Internal use only.
  210. * @return string|false The location of the remote path, false to cease looping.
  211. */
  212. public function search_for_folder( $folder, $base = '.', $loop = false ) {
  213. if ( empty( $base ) || '.' == $base )
  214. $base = trailingslashit($this->cwd());
  215. $folder = untrailingslashit($folder);
  216. if ( $this->verbose ) {
  217. /* translators: 1: folder to locate, 2: folder to start searching from */
  218. printf( "\n" . __( 'Looking for %1$s in %2$s' ) . "<br/>\n", $folder, $base );
  219. }
  220. $folder_parts = explode('/', $folder);
  221. $folder_part_keys = array_keys( $folder_parts );
  222. $last_index = array_pop( $folder_part_keys );
  223. $last_path = $folder_parts[ $last_index ];
  224. $files = $this->dirlist( $base );
  225. foreach ( $folder_parts as $index => $key ) {
  226. if ( $index == $last_index )
  227. continue; // We want this to be caught by the next code block.
  228. /*
  229. * Working from /home/ to /user/ to /wordpress/ see if that file exists within
  230. * the current folder, If it's found, change into it and follow through looking
  231. * for it. If it cant find WordPress down that route, it'll continue onto the next
  232. * folder level, and see if that matches, and so on. If it reaches the end, and still
  233. * cant find it, it'll return false for the entire function.
  234. */
  235. if ( isset($files[ $key ]) ){
  236. // Let's try that folder:
  237. $newdir = trailingslashit(path_join($base, $key));
  238. if ( $this->verbose ) {
  239. /* translators: %s: directory name */
  240. printf( "\n" . __( 'Changing to %s' ) . "<br/>\n", $newdir );
  241. }
  242. // Only search for the remaining path tokens in the directory, not the full path again.
  243. $newfolder = implode( '/', array_slice( $folder_parts, $index + 1 ) );
  244. if ( $ret = $this->search_for_folder( $newfolder, $newdir, $loop) )
  245. return $ret;
  246. }
  247. }
  248. // Only check this as a last resort, to prevent locating the incorrect install.
  249. // All above procedures will fail quickly if this is the right branch to take.
  250. if (isset( $files[ $last_path ] ) ) {
  251. if ( $this->verbose ) {
  252. /* translators: %s: directory name */
  253. printf( "\n" . __( 'Found %s' ) . "<br/>\n", $base . $last_path );
  254. }
  255. return trailingslashit($base . $last_path);
  256. }
  257. // Prevent this function from looping again.
  258. // No need to proceed if we've just searched in /
  259. if ( $loop || '/' == $base )
  260. return false;
  261. // As an extra last resort, Change back to / if the folder wasn't found.
  262. // This comes into effect when the CWD is /home/user/ but WP is at /var/www/....
  263. return $this->search_for_folder( $folder, '/', true );
  264. }
  265. /**
  266. * Return the *nix-style file permissions for a file.
  267. *
  268. * From the PHP documentation page for fileperms().
  269. *
  270. * @link https://secure.php.net/manual/en/function.fileperms.php
  271. *
  272. * @since 2.5.0
  273. *
  274. * @param string $file String filename.
  275. * @return string The *nix-style representation of permissions.
  276. */
  277. public function gethchmod( $file ){
  278. $perms = intval( $this->getchmod( $file ), 8 );
  279. if (($perms & 0xC000) == 0xC000) // Socket
  280. $info = 's';
  281. elseif (($perms & 0xA000) == 0xA000) // Symbolic Link
  282. $info = 'l';
  283. elseif (($perms & 0x8000) == 0x8000) // Regular
  284. $info = '-';
  285. elseif (($perms & 0x6000) == 0x6000) // Block special
  286. $info = 'b';
  287. elseif (($perms & 0x4000) == 0x4000) // Directory
  288. $info = 'd';
  289. elseif (($perms & 0x2000) == 0x2000) // Character special
  290. $info = 'c';
  291. elseif (($perms & 0x1000) == 0x1000) // FIFO pipe
  292. $info = 'p';
  293. else // Unknown
  294. $info = 'u';
  295. // Owner
  296. $info .= (($perms & 0x0100) ? 'r' : '-');
  297. $info .= (($perms & 0x0080) ? 'w' : '-');
  298. $info .= (($perms & 0x0040) ?
  299. (($perms & 0x0800) ? 's' : 'x' ) :
  300. (($perms & 0x0800) ? 'S' : '-'));
  301. // Group
  302. $info .= (($perms & 0x0020) ? 'r' : '-');
  303. $info .= (($perms & 0x0010) ? 'w' : '-');
  304. $info .= (($perms & 0x0008) ?
  305. (($perms & 0x0400) ? 's' : 'x' ) :
  306. (($perms & 0x0400) ? 'S' : '-'));
  307. // World
  308. $info .= (($perms & 0x0004) ? 'r' : '-');
  309. $info .= (($perms & 0x0002) ? 'w' : '-');
  310. $info .= (($perms & 0x0001) ?
  311. (($perms & 0x0200) ? 't' : 'x' ) :
  312. (($perms & 0x0200) ? 'T' : '-'));
  313. return $info;
  314. }
  315. /**
  316. * Gets the permissions of the specified file or filepath in their octal format
  317. *
  318. * @since 2.5.0
  319. * @param string $file
  320. * @return string the last 3 characters of the octal number
  321. */
  322. public function getchmod( $file ) {
  323. return '777';
  324. }
  325. /**
  326. * Convert *nix-style file permissions to a octal number.
  327. *
  328. * Converts '-rw-r--r--' to 0644
  329. * From "info at rvgate dot nl"'s comment on the PHP documentation for chmod()
  330. *
  331. * @link https://secure.php.net/manual/en/function.chmod.php#49614
  332. *
  333. * @since 2.5.0
  334. *
  335. * @param string $mode string The *nix-style file permission.
  336. * @return int octal representation
  337. */
  338. public function getnumchmodfromh( $mode ) {
  339. $realmode = '';
  340. $legal = array('', 'w', 'r', 'x', '-');
  341. $attarray = preg_split('//', $mode);
  342. for ( $i = 0, $c = count( $attarray ); $i < $c; $i++ ) {
  343. if ($key = array_search($attarray[$i], $legal)) {
  344. $realmode .= $legal[$key];
  345. }
  346. }
  347. $mode = str_pad($realmode, 10, '-', STR_PAD_LEFT);
  348. $trans = array('-'=>'0', 'r'=>'4', 'w'=>'2', 'x'=>'1');
  349. $mode = strtr($mode,$trans);
  350. $newmode = $mode[0];
  351. $newmode .= $mode[1] + $mode[2] + $mode[3];
  352. $newmode .= $mode[4] + $mode[5] + $mode[6];
  353. $newmode .= $mode[7] + $mode[8] + $mode[9];
  354. return $newmode;
  355. }
  356. /**
  357. * Determine if the string provided contains binary characters.
  358. *
  359. * @since 2.7.0
  360. *
  361. * @param string $text String to test against.
  362. * @return bool true if string is binary, false otherwise.
  363. */
  364. public function is_binary( $text ) {
  365. return (bool) preg_match( '|[^\x20-\x7E]|', $text ); // chr(32)..chr(127)
  366. }
  367. /**
  368. * Change the ownership of a file / folder.
  369. *
  370. * Default behavior is to do nothing, override this in your subclass, if desired.
  371. *
  372. * @since 2.5.0
  373. *
  374. * @param string $file Path to the file.
  375. * @param mixed $owner A user name or number.
  376. * @param bool $recursive Optional. If set True changes file owner recursivly. Defaults to False.
  377. * @return bool Returns true on success or false on failure.
  378. */
  379. public function chown( $file, $owner, $recursive = false ) {
  380. return false;
  381. }
  382. /**
  383. * Connect filesystem.
  384. *
  385. * @since 2.5.0
  386. * @abstract
  387. *
  388. * @return bool True on success or false on failure (always true for WP_Filesystem_Direct).
  389. */
  390. public function connect() {
  391. return true;
  392. }
  393. /**
  394. * Read entire file into a string.
  395. *
  396. * @since 2.5.0
  397. * @abstract
  398. *
  399. * @param string $file Name of the file to read.
  400. * @return mixed|bool Returns the read data or false on failure.
  401. */
  402. public function get_contents( $file ) {
  403. return false;
  404. }
  405. /**
  406. * Read entire file into an array.
  407. *
  408. * @since 2.5.0
  409. * @abstract
  410. *
  411. * @param string $file Path to the file.
  412. * @return array|bool the file contents in an array or false on failure.
  413. */
  414. public function get_contents_array( $file ) {
  415. return false;
  416. }
  417. /**
  418. * Write a string to a file.
  419. *
  420. * @since 2.5.0
  421. * @abstract
  422. *
  423. * @param string $file Remote path to the file where to write the data.
  424. * @param string $contents The data to write.
  425. * @param int $mode Optional. The file permissions as octal number, usually 0644.
  426. * @return bool False on failure.
  427. */
  428. public function put_contents( $file, $contents, $mode = false ) {
  429. return false;
  430. }
  431. /**
  432. * Get the current working directory.
  433. *
  434. * @since 2.5.0
  435. * @abstract
  436. *
  437. * @return string|bool The current working directory on success, or false on failure.
  438. */
  439. public function cwd() {
  440. return false;
  441. }
  442. /**
  443. * Change current directory.
  444. *
  445. * @since 2.5.0
  446. * @abstract
  447. *
  448. * @param string $dir The new current directory.
  449. * @return bool|string
  450. */
  451. public function chdir( $dir ) {
  452. return false;
  453. }
  454. /**
  455. * Change the file group.
  456. *
  457. * @since 2.5.0
  458. * @abstract
  459. *
  460. * @param string $file Path to the file.
  461. * @param mixed $group A group name or number.
  462. * @param bool $recursive Optional. If set True changes file group recursively. Defaults to False.
  463. * @return bool|string
  464. */
  465. public function chgrp( $file, $group, $recursive = false ) {
  466. return false;
  467. }
  468. /**
  469. * Change filesystem permissions.
  470. *
  471. * @since 2.5.0
  472. * @abstract
  473. *
  474. * @param string $file Path to the file.
  475. * @param int $mode Optional. The permissions as octal number, usually 0644 for files, 0755 for dirs.
  476. * @param bool $recursive Optional. If set True changes file group recursively. Defaults to False.
  477. * @return bool|string
  478. */
  479. public function chmod( $file, $mode = false, $recursive = false ) {
  480. return false;
  481. }
  482. /**
  483. * Get the file owner.
  484. *
  485. * @since 2.5.0
  486. * @abstract
  487. *
  488. * @param string $file Path to the file.
  489. * @return string|bool Username of the user or false on error.
  490. */
  491. public function owner( $file ) {
  492. return false;
  493. }
  494. /**
  495. * Get the file's group.
  496. *
  497. * @since 2.5.0
  498. * @abstract
  499. *
  500. * @param string $file Path to the file.
  501. * @return string|bool The group or false on error.
  502. */
  503. public function group( $file ) {
  504. return false;
  505. }
  506. /**
  507. * Copy a file.
  508. *
  509. * @since 2.5.0
  510. * @abstract
  511. *
  512. * @param string $source Path to the source file.
  513. * @param string $destination Path to the destination file.
  514. * @param bool $overwrite Optional. Whether to overwrite the destination file if it exists.
  515. * Default false.
  516. * @param int $mode Optional. The permissions as octal number, usually 0644 for files, 0755 for dirs.
  517. * Default false.
  518. * @return bool True if file copied successfully, False otherwise.
  519. */
  520. public function copy( $source, $destination, $overwrite = false, $mode = false ) {
  521. return false;
  522. }
  523. /**
  524. * Move a file.
  525. *
  526. * @since 2.5.0
  527. * @abstract
  528. *
  529. * @param string $source Path to the source file.
  530. * @param string $destination Path to the destination file.
  531. * @param bool $overwrite Optional. Whether to overwrite the destination file if it exists.
  532. * Default false.
  533. * @return bool True if file copied successfully, False otherwise.
  534. */
  535. public function move( $source, $destination, $overwrite = false ) {
  536. return false;
  537. }
  538. /**
  539. * Delete a file or directory.
  540. *
  541. * @since 2.5.0
  542. * @abstract
  543. *
  544. * @param string $file Path to the file.
  545. * @param bool $recursive Optional. If set True changes file group recursively. Defaults to False.
  546. * Default false.
  547. * @param bool $type Type of resource. 'f' for file, 'd' for directory.
  548. * Default false.
  549. * @return bool True if the file or directory was deleted, false on failure.
  550. */
  551. public function delete( $file, $recursive = false, $type = false ) {
  552. return false;
  553. }
  554. /**
  555. * Check if a file or directory exists.
  556. *
  557. * @since 2.5.0
  558. * @abstract
  559. *
  560. * @param string $file Path to file/directory.
  561. * @return bool Whether $file exists or not.
  562. */
  563. public function exists( $file ) {
  564. return false;
  565. }
  566. /**
  567. * Check if resource is a file.
  568. *
  569. * @since 2.5.0
  570. * @abstract
  571. *
  572. * @param string $file File path.
  573. * @return bool Whether $file is a file.
  574. */
  575. public function is_file( $file ) {
  576. return false;
  577. }
  578. /**
  579. * Check if resource is a directory.
  580. *
  581. * @since 2.5.0
  582. * @abstract
  583. *
  584. * @param string $path Directory path.
  585. * @return bool Whether $path is a directory.
  586. */
  587. public function is_dir( $path ) {
  588. return false;
  589. }
  590. /**
  591. * Check if a file is readable.
  592. *
  593. * @since 2.5.0
  594. * @abstract
  595. *
  596. * @param string $file Path to file.
  597. * @return bool Whether $file is readable.
  598. */
  599. public function is_readable( $file ) {
  600. return false;
  601. }
  602. /**
  603. * Check if a file or directory is writable.
  604. *
  605. * @since 2.5.0
  606. * @abstract
  607. *
  608. * @param string $file Path to file.
  609. * @return bool Whether $file is writable.
  610. */
  611. public function is_writable( $file ) {
  612. return false;
  613. }
  614. /**
  615. * Gets the file's last access time.
  616. *
  617. * @since 2.5.0
  618. * @abstract
  619. *
  620. * @param string $file Path to file.
  621. * @return int|bool Unix timestamp representing last access time.
  622. */
  623. public function atime( $file ) {
  624. return false;
  625. }
  626. /**
  627. * Gets the file modification time.
  628. *
  629. * @since 2.5.0
  630. * @abstract
  631. *
  632. * @param string $file Path to file.
  633. * @return int|bool Unix timestamp representing modification time.
  634. */
  635. public function mtime( $file ) {
  636. return false;
  637. }
  638. /**
  639. * Gets the file size (in bytes).
  640. *
  641. * @since 2.5.0
  642. * @abstract
  643. *
  644. * @param string $file Path to file.
  645. * @return int|bool Size of the file in bytes.
  646. */
  647. public function size( $file ) {
  648. return false;
  649. }
  650. /**
  651. * Set the access and modification times of a file.
  652. *
  653. * Note: If $file doesn't exist, it will be created.
  654. *
  655. * @since 2.5.0
  656. * @abstract
  657. *
  658. * @param string $file Path to file.
  659. * @param int $time Optional. Modified time to set for file.
  660. * Default 0.
  661. * @param int $atime Optional. Access time to set for file.
  662. * Default 0.
  663. * @return bool Whether operation was successful or not.
  664. */
  665. public function touch( $file, $time = 0, $atime = 0 ) {
  666. return false;
  667. }
  668. /**
  669. * Create a directory.
  670. *
  671. * @since 2.5.0
  672. * @abstract
  673. *
  674. * @param string $path Path for new directory.
  675. * @param mixed $chmod Optional. The permissions as octal number, (or False to skip chmod)
  676. * Default false.
  677. * @param mixed $chown Optional. A user name or number (or False to skip chown)
  678. * Default false.
  679. * @param mixed $chgrp Optional. A group name or number (or False to skip chgrp).
  680. * Default false.
  681. * @return bool False if directory cannot be created, true otherwise.
  682. */
  683. public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
  684. return false;
  685. }
  686. /**
  687. * Delete a directory.
  688. *
  689. * @since 2.5.0
  690. * @abstract
  691. *
  692. * @param string $path Path to directory.
  693. * @param bool $recursive Optional. Whether to recursively remove files/directories.
  694. * Default false.
  695. * @return bool Whether directory is deleted successfully or not.
  696. */
  697. public function rmdir( $path, $recursive = false ) {
  698. return false;
  699. }
  700. /**
  701. * Get details for files in a directory or a specific file.
  702. *
  703. * @since 2.5.0
  704. * @abstract
  705. *
  706. * @param string $path Path to directory or file.
  707. * @param bool $include_hidden Optional. Whether to include details of hidden ("." prefixed) files.
  708. * Default true.
  709. * @param bool $recursive Optional. Whether to recursively include file details in nested directories.
  710. * Default false.
  711. * @return array|bool {
  712. * Array of files. False if unable to list directory contents.
  713. *
  714. * @type string $name Name of the file/directory.
  715. * @type string $perms *nix representation of permissions.
  716. * @type int $permsn Octal representation of permissions.
  717. * @type string $owner Owner name or ID.
  718. * @type int $size Size of file in bytes.
  719. * @type int $lastmodunix Last modified unix timestamp.
  720. * @type mixed $lastmod Last modified month (3 letter) and day (without leading 0).
  721. * @type int $time Last modified time.
  722. * @type string $type Type of resource. 'f' for file, 'd' for directory.
  723. * @type mixed $files If a directory and $recursive is true, contains another array of files.
  724. * }
  725. */
  726. public function dirlist( $path, $include_hidden = true, $recursive = false ) {
  727. return false;
  728. }
  729. } // WP_Filesystem_Base