class-wp-filesystem-base.php 23 KB

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