wp/wp-admin/includes/class-wp-filesystem-ftpext.php
author ymh <ymh.work@gmail.com>
Mon, 14 Oct 2019 17:39:30 +0200
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
permissions -rw-r--r--
resynchronize code repo with production
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * WordPress FTP Filesystem.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Filesystem
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 * WordPress Filesystem Class for implementing FTP.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    12
 * @since 2.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    13
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    14
 * @see WP_Filesystem_Base
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
class WP_Filesystem_FTPext extends WP_Filesystem_Base {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    17
	public $link;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    19
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    20
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    21
	 * @param array $opt
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    22
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    23
	public function __construct( $opt = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
		$this->method = 'ftpext';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
		$this->errors = new WP_Error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
		// Check if possible to use ftp functions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
		if ( ! extension_loaded('ftp') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
			$this->errors->add('no_ftp_ext', __('The ftp PHP extension is not available'));
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
			return;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
		// This Class uses the timeout on a per-connection basis, Others use it on a per-action basis.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
		if ( ! defined('FS_TIMEOUT') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
			define('FS_TIMEOUT', 240);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
		if ( empty($opt['port']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
			$this->options['port'] = 21;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
			$this->options['port'] = $opt['port'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
		if ( empty($opt['hostname']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
			$this->errors->add('empty_hostname', __('FTP hostname is required'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
			$this->options['hostname'] = $opt['hostname'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
		// Check if the options provided are OK.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
		if ( empty($opt['username']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
			$this->errors->add('empty_username', __('FTP username is required'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
			$this->options['username'] = $opt['username'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
		if ( empty($opt['password']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
			$this->errors->add('empty_password', __('FTP password is required'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
			$this->options['password'] = $opt['password'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
		$this->options['ssl'] = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
		if ( isset($opt['connection_type']) && 'ftps' == $opt['connection_type'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
			$this->options['ssl'] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    64
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    65
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    66
	 * @return bool
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    67
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
	public function connect() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
		if ( isset($this->options['ssl']) && $this->options['ssl'] && function_exists('ftp_ssl_connect') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
			$this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
			$this->link = @ftp_connect($this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
		if ( ! $this->link ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    75
			$this->errors->add( 'connect',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    76
				/* translators: %s: hostname:port */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    77
				sprintf( __( 'Failed to connect to FTP Server %s' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    78
					$this->options['hostname'] . ':' . $this->options['port']
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    79
				)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    80
			);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    84
		if ( ! @ftp_login( $this->link,$this->options['username'], $this->options['password'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    85
			$this->errors->add( 'auth',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    86
				/* translators: %s: username */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    87
				sprintf( __( 'Username/Password incorrect for %s' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    88
					$this->options['username']
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    89
				)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    90
			);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
		// Set the Connection to use Passive FTP
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
		@ftp_pasv( $this->link, true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
		if ( @ftp_get_option($this->link, FTP_TIMEOUT_SEC) < FS_TIMEOUT )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
			@ftp_set_option($this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   102
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   103
	 * Retrieves the file contents.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   104
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   105
	 * @since 2.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   106
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   107
	 * @param string $file Filename.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   108
	 * @return string|false File contents on success, false if no temp file could be opened,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   109
	 *                      or if the file couldn't be retrieved.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   110
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   111
	public function get_contents( $file ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
		$tempfile = wp_tempnam($file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
		$temp = fopen($tempfile, 'w+');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   115
		if ( ! $temp ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   116
			unlink( $tempfile );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
			return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   118
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   120
		if ( ! @ftp_fget( $this->link, $temp, $file, FTP_BINARY ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   121
			fclose( $temp );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   122
			unlink( $tempfile );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
			return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   124
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
		fseek( $temp, 0 ); // Skip back to the start of the file being written to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
		$contents = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
		while ( ! feof($temp) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
			$contents .= fread($temp, 8192);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
		fclose($temp);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
		unlink($tempfile);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
		return $contents;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   137
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   138
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   139
	 * @param string $file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   140
	 * @return array
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   142
	public function get_contents_array($file) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
		return explode("\n", $this->get_contents($file));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   146
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   147
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   148
	 * @param string $file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
	 * @param string $contents
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   150
	 * @param bool|int $mode
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   151
	 * @return bool
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   153
	public function put_contents($file, $contents, $mode = false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
		$tempfile = wp_tempnam($file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
		$temp = fopen( $tempfile, 'wb+' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   156
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   157
		if ( ! $temp ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   158
			unlink( $tempfile );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
			return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   160
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
		mbstring_binary_safe_encoding();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
		$data_length = strlen( $contents );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
		$bytes_written = fwrite( $temp, $contents );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
		reset_mbstring_encoding();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
		if ( $data_length !== $bytes_written ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
			fclose( $temp );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
			unlink( $tempfile );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
		fseek( $temp, 0 ); // Skip back to the start of the file being written to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
		$ret = @ftp_fput( $this->link, $file, $temp, FTP_BINARY );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
		fclose($temp);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
		unlink($tempfile);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
		$this->chmod($file, $mode);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
		return $ret;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   188
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   189
	 * @return string
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   190
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   191
	public function cwd() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
		$cwd = @ftp_pwd($this->link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
		if ( $cwd )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
			$cwd = trailingslashit($cwd);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
		return $cwd;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   198
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   199
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   200
	 * @param string $dir
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   201
	 * @return bool
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   202
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   203
	public function chdir($dir) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
		return @ftp_chdir($this->link, $dir);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   207
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   208
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   209
	 * @param string $file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   210
	 * @param int $mode
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   211
	 * @param bool $recursive
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   212
	 * @return bool
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   213
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   214
	public function chmod($file, $mode = false, $recursive = false) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
		if ( ! $mode ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
			if ( $this->is_file($file) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
				$mode = FS_CHMOD_FILE;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
			elseif ( $this->is_dir($file) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
				$mode = FS_CHMOD_DIR;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
		// chmod any sub-objects if recursive.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
		if ( $recursive && $this->is_dir($file) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
			$filelist = $this->dirlist($file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
			foreach ( (array)$filelist as $filename => $filemeta )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
				$this->chmod($file . '/' . $filename, $mode, $recursive);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
		// chmod the file or directory
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
		if ( ! function_exists('ftp_chmod') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
			return (bool)@ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
		return (bool)@ftp_chmod($this->link, $mode, $file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   237
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   238
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   239
	 * @param string $file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   240
	 * @return string
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   241
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   242
	public function owner($file) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
		$dir = $this->dirlist($file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
		return $dir[$file]['owner'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   246
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   247
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   248
	 * @param string $file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   249
	 * @return string
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   250
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   251
	public function getchmod($file) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
		$dir = $this->dirlist($file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
		return $dir[$file]['permsn'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   255
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   256
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   257
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   258
	 * @param string $file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   259
	 * @return string
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   260
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   261
	public function group($file) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
		$dir = $this->dirlist($file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
		return $dir[$file]['group'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   266
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   267
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   268
	 * @param string $source
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   269
	 * @param string $destination
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   270
	 * @param bool   $overwrite
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   271
	 * @param string|bool $mode
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   272
	 * @return bool
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   273
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   274
	public function copy($source, $destination, $overwrite = false, $mode = false) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
		if ( ! $overwrite && $this->exists($destination) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
		$content = $this->get_contents($source);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
		if ( false === $content )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
		return $this->put_contents($destination, $content, $mode);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   282
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   283
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   284
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   285
	 * @param string $source
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   286
	 * @param string $destination
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   287
	 * @param bool $overwrite
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   288
	 * @return bool
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   289
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
	public function move($source, $destination, $overwrite = false) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
		return ftp_rename($this->link, $source, $destination);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   293
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   294
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   295
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
	 * @param string $file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   297
	 * @param bool $recursive
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   298
	 * @param string $type
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   299
	 * @return bool
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   300
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   301
	public function delete($file, $recursive = false, $type = false) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
		if ( empty($file) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
		if ( 'f' == $type || $this->is_file($file) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
			return @ftp_delete($this->link, $file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
		if ( !$recursive )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
			return @ftp_rmdir($this->link, $file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
		$filelist = $this->dirlist( trailingslashit($file) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
		if ( !empty($filelist) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
			foreach ( $filelist as $delete_file )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
				$this->delete( trailingslashit($file) . $delete_file['name'], $recursive, $delete_file['type'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
		return @ftp_rmdir($this->link, $file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   315
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   317
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   318
	 * @param string $file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   319
	 * @return bool
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   320
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   321
	public function exists($file) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   322
		$list = @ftp_nlist($this->link, $file);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   324
		if ( empty( $list ) && $this->is_dir( $file ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   325
			return true; // File is an empty directory.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   326
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   327
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
		return !empty($list); //empty list = no file, so invert.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   330
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   331
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   332
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   333
	 * @param string $file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   334
	 * @return bool
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   335
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   336
	public function is_file($file) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
		return $this->exists($file) && !$this->is_dir($file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   339
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   340
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   341
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   342
	 * @param string $path
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   343
	 * @return bool
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   344
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   345
	public function is_dir($path) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
		$cwd = $this->cwd();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
		$result = @ftp_chdir($this->link, trailingslashit($path) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
		if ( $result && $path == $this->cwd() || $this->cwd() != $cwd ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
			@ftp_chdir($this->link, $cwd);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   355
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   356
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   357
	 * @param string $file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   358
	 * @return bool
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   359
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   360
	public function is_readable($file) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   361
		return true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   362
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   363
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   364
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   365
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   366
	 * @param string $file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   367
	 * @return bool
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   368
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   369
	public function is_writable($file) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   372
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   373
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   374
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   375
	 * @param string $file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   376
	 * @return bool
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   377
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   378
	public function atime($file) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   379
		return false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   381
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   382
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   383
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   384
	 * @param string $file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   385
	 * @return int
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   386
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   387
	public function mtime($file) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   388
		return ftp_mdtm($this->link, $file);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   389
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   390
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   391
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   392
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   393
	 * @param string $file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   394
	 * @return int
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   395
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   396
	public function size($file) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   397
		return ftp_size($this->link, $file);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   398
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   399
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   400
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   401
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   402
	 * @param string $file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   403
	 * @return bool
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   404
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   405
	public function touch($file, $time = 0, $atime = 0) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   409
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   410
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   411
	 * @param string $path
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   412
	 * @param mixed $chmod
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   413
	 * @param mixed $chown
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   414
	 * @param mixed $chgrp
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   415
	 * @return bool
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   416
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   417
	public function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
		$path = untrailingslashit($path);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
		if ( empty($path) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
		if ( !@ftp_mkdir($this->link, $path) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
		$this->chmod($path, $chmod);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   428
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   429
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   430
	 * @param string $path
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   431
	 * @param bool $recursive
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   432
	 * @return bool
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   433
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   434
	public function rmdir($path, $recursive = false) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
		return $this->delete($path, $recursive);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   438
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   439
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   440
	 * @staticvar bool $is_windows
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   441
	 * @param string $line
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   442
	 * @return array
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   443
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   444
	public function parselisting($line) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   445
		static $is_windows = null;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
		if ( is_null($is_windows) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
			$is_windows = stripos( ftp_systype($this->link), 'win') !== false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
		if ( $is_windows && preg_match('/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/', $line, $lucifer) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
			$b = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
			if ( $lucifer[3] < 70 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
				$lucifer[3] +=2000;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
				$lucifer[3] += 1900; // 4digit year fix
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
			$b['isdir'] = ( $lucifer[7] == '<DIR>');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
			if ( $b['isdir'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
				$b['type'] = 'd';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
				$b['type'] = 'f';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
			$b['size'] = $lucifer[7];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
			$b['month'] = $lucifer[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
			$b['day'] = $lucifer[2];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
			$b['year'] = $lucifer[3];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
			$b['hour'] = $lucifer[4];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
			$b['minute'] = $lucifer[5];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
			$b['time'] = @mktime($lucifer[4] + (strcasecmp($lucifer[6], "PM") == 0 ? 12 : 0), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
			$b['am/pm'] = $lucifer[6];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
			$b['name'] = $lucifer[8];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
		} elseif ( !$is_windows && $lucifer = preg_split('/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
			//echo $line."\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
			$lcount = count($lucifer);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
			if ( $lcount < 8 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
				return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
			$b = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
			$b['isdir'] = $lucifer[0]{0} === 'd';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
			$b['islink'] = $lucifer[0]{0} === 'l';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
			if ( $b['isdir'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
				$b['type'] = 'd';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
			elseif ( $b['islink'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
				$b['type'] = 'l';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
				$b['type'] = 'f';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
			$b['perms'] = $lucifer[0];
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   484
			$b['permsn'] = $this->getnumchmodfromh( $b['perms'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
			$b['number'] = $lucifer[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
			$b['owner'] = $lucifer[2];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
			$b['group'] = $lucifer[3];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
			$b['size'] = $lucifer[4];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
			if ( $lcount == 8 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
				sscanf($lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
				sscanf($lucifer[6], '%d:%d', $b['hour'], $b['minute']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
				$b['time'] = @mktime($b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
				$b['name'] = $lucifer[7];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
				$b['month'] = $lucifer[5];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
				$b['day'] = $lucifer[6];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
				if ( preg_match('/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
					$b['year'] = date("Y");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
					$b['hour'] = $l2[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
					$b['minute'] = $l2[2];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
					$b['year'] = $lucifer[7];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
					$b['hour'] = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
					$b['minute'] = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
				$b['time'] = strtotime( sprintf('%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute']) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
				$b['name'] = $lucifer[8];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
		// Replace symlinks formatted as "source -> target" with just the source name
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   512
		if ( isset( $b['islink'] ) && $b['islink'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
			$b['name'] = preg_replace( '/(\s*->\s*.*)$/', '', $b['name'] );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   514
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
		return $b;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   519
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   520
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   521
	 * @param string $path
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   522
	 * @param bool $include_hidden
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   523
	 * @param bool $recursive
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   524
	 * @return bool|array
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   525
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   526
	public function dirlist($path = '.', $include_hidden = true, $recursive = false) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
		if ( $this->is_file($path) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
			$limit_file = basename($path);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
			$path = dirname($path) . '/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
			$limit_file = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
		$pwd = @ftp_pwd($this->link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
		if ( ! @ftp_chdir($this->link, $path) ) // Cant change to folder = folder doesn't exist
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
		$list = @ftp_rawlist($this->link, '-a', false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
		@ftp_chdir($this->link, $pwd);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
		if ( empty($list) ) // Empty array = non-existent folder (real folder will show . at least)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
		$dirlist = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
		foreach ( $list as $k => $v ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
			$entry = $this->parselisting($v);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
			if ( empty($entry) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
			if ( '.' == $entry['name'] || '..' == $entry['name'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
			if ( ! $include_hidden && '.' == $entry['name'][0] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
			if ( $limit_file && $entry['name'] != $limit_file)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
			$dirlist[ $entry['name'] ] = $entry;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
		$ret = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
		foreach ( (array)$dirlist as $struc ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
			if ( 'd' == $struc['type'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
				if ( $recursive )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
					$struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
				else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
					$struc['files'] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
			$ret[ $struc['name'] ] = $struc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
		return $ret;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   575
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   576
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   577
	public function __destruct() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
		if ( $this->link )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
			ftp_close($this->link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
}