Make WordPress Core

Ticket #63416: class-ftp-pure-wpcs-fix.php.patch

File class-ftp-pure-wpcs-fix.php.patch, 9.7 KB (added by tristup, 16 months ago)
Line 
130,31c30,31
2< function __construct($verb=FALSE, $le=FALSE) {
3< parent::__construct(false, $verb, $le);
4---
5> function __construct( $verb = false, $le = false ) {
6> parent::__construct( false, $verb, $le );
738,40c38,41
8< function _settimeout($sock) {
9< if(!@stream_set_timeout($sock, $this->_timeout)) {
10< $this->PushError('_settimeout','socket set send timeout');
11---
12> function _settimeout( $sock ) {
13>
14> if ( ! @stream_set_timeout( $sock, $this->_timeout ) ) {
15> $this->PushError( '_settimeout','socket set send timeout' );
1642c43
17< return FALSE;
18---
19> return false;
2044c45,46
21< return TRUE;
22---
23>
24> return true;
2547,52c49,55
26< function _connect($host, $port) {
27< $this->SendMSG("Creating socket");
28< $sock = @fsockopen($host, $port, $errno, $errstr, $this->_timeout);
29< if (!$sock) {
30< $this->PushError('_connect','socket connect failed', $errstr." (".$errno.")");
31< return FALSE;
32---
33> function _connect( $host, $port ) {
34> $this->SendMSG( "Creating socket" );
35> $sock = @fsockopen( $host, $port, $errno, $errstr, $this->_timeout );
36>
37> if ( ! $sock ) {
38> $this->PushError( '_connect','socket connect failed', $errstr." (".$errno.")" );
39> return false;
4054c57,58
41< $this->_connected=true;
42---
43>
44> $this->_connected = true;
4558,66c62,73
46< function _readmsg($fnction="_readmsg"){
47< if(!$this->_connected) {
48< $this->PushError($fnction, 'Connect first');
49< return FALSE;
50< }
51< $result=true;
52< $this->_message="";
53< $this->_code=0;
54< $go=true;
55---
56> function _readmsg( $fnction = "_readmsg" ) {
57>
58> if ( ! $this->_connected ) {
59> $this->PushError( $fnction, 'Connect first' );
60> return false;
61> }
62>
63> $result = true;
64> $this->_message = "";
65> $this->_code = 0;
66> $go = true;
67>
6868,71c75,79
69< $tmp=@fgets($this->_ftp_control_sock, 512);
70< if($tmp===false) {
71< $go=$result=false;
72< $this->PushError($fnction,'Read failed');
73---
74> $tmp = @fgets( $this->_ftp_control_sock, 512 );
75>
76> if ( false === $tmp ) {
77> $go = $result = false;
78> $this->PushError( $fnction, 'Read failed' );
7973,74c81,84
80< $this->_message.=$tmp;
81< if(preg_match("/^([0-9]{3})(-(.*[".CRLF."]{1,2})+\\1)? [^".CRLF."]+[".CRLF."]{1,2}$/", $this->_message, $regs)) $go=false;
82---
83> $this->_message .= $tmp;
84> if ( preg_match("/^([0-9]{3})(-(.*[" . CRLF . "]{1,2})+\\1)? [^" . CRLF . "]+[" . CRLF . "]{1,2}$/", $this->_message, $regs ) ) {
85> $go = false;
86> }
8776,78c86,92
88< } while($go);
89< if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF;
90< $this->_code=(int)$regs[1];
91---
92> } while ( $go );
93>
94> if ( $this->LocalEcho ) {
95> echo "GET < " . rtrim( $this->_message, CRLF ) . CRLF;
96> }
97>
98> $this->_code = (int) $regs[1];
9982,105c96,129
100< function _exec($cmd, $fnction="_exec") {
101< if(!$this->_ready) {
102< $this->PushError($fnction,'Connect first');
103< return FALSE;
104< }
105< if($this->LocalEcho) echo "PUT > ",$cmd,CRLF;
106< $status=@fputs($this->_ftp_control_sock, $cmd.CRLF);
107< if($status===false) {
108< $this->PushError($fnction,'socket write failed');
109< return FALSE;
110< }
111< $this->_lastaction=time();
112< if(!$this->_readmsg($fnction)) return FALSE;
113< return TRUE;
114< }
115<
116< function _data_prepare($mode=FTP_ASCII) {
117< if(!$this->_settype($mode)) return FALSE;
118< if($this->_passive) {
119< if(!$this->_exec("PASV", "pasv")) {
120< $this->_data_close();
121< return FALSE;
122< }
123< if(!$this->_checkCode()) {
124---
125> function _exec( $cmd, $fnction = "_exec" ) {
126>
127> if ( ! $this->_ready ) {
128> $this->PushError( $fnction, 'Connect first' );
129> return false;
130> }
131>
132> if ( $this->LocalEcho ) {
133> echo "PUT > ", $cmd, CRLF;
134> }
135>
136> $status = @fputs( $this->_ftp_control_sock, $cmd . CRLF );
137>
138> if ( false === $status) {
139> $this->PushError( $fnction, 'socket write failed' );
140> return false;
141> }
142>
143> $this->_lastaction = time();
144> if ( ! $this->_readmsg( $fnction ) ) {
145> return false;
146> }
147> return true;
148> }
149>
150> function _data_prepare( $mode = FTP_ASCII ) {
151>
152> if ( ! $this->_settype( $mode ) ) {
153> return false;
154> }
155>
156> if ( $this->_passive ) {
157>
158> if ( ! $this->_exec( "PASV", "pasv" ) ) {
159107c131
160< return FALSE;
161---
162> return false;
163109,115c133,134
164< $ip_port = explode(",", preg_replace("/^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*$/s", "\\1", $this->_message));
165< $this->_datahost=$ip_port[0].".".$ip_port[1].".".$ip_port[2].".".$ip_port[3];
166< $this->_dataport=(((int)$ip_port[4])<<8) + ((int)$ip_port[5]);
167< $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
168< $this->_ftp_data_sock=@fsockopen($this->_datahost, $this->_dataport, $errno, $errstr, $this->_timeout);
169< if(!$this->_ftp_data_sock) {
170< $this->PushError("_data_prepare","fsockopen fails", $errstr." (".$errno.")");
171---
172>
173> if ( ! $this->_checkCode() ) {
174117c136
175< return FALSE;
176---
177> return false;
178119c138,151
179< else $this->_ftp_data_sock;
180---
181>
182> $ip_port = explode( ",", preg_replace("/^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*$/s", "\\1", $this->_message ) );
183> $this->_datahost = $ip_port[0] . "." . $ip_port[1] . "." . $ip_port[2] . "." . $ip_port[3];
184> $this->_dataport = ( ( (int) $ip_port[4] ) << 8 ) + ( (int) $ip_port[5] );
185> $this->SendMSG( "Connecting to " . $this->_datahost . ":" . $this->_dataport );
186> $this->_ftp_data_sock = @fsockopen( $this->_datahost, $this->_dataport, $errno, $errstr, $this->_timeout );
187>
188> if ( ! $this->_ftp_data_sock ) {
189> $this->push_error( '_data_prepare', 'fsockopen fails', $errstr . ' ( ' . $errno . ' )' );
190> $this->_data_close();
191> return false;
192> }
193>
194> return $this->_ftp_data_sock;
195121,122c153,154
196< $this->SendMSG("Only passive connections available!");
197< return FALSE;
198---
199> $this->SendMSG( "Only passive connections available!" );
200> return false;
201124c156,157
202< return TRUE;
203---
204>
205> return true;
206127,138c160,182
207< function _data_read($mode=FTP_ASCII, $fp=NULL) {
208< if(is_resource($fp)) $out=0;
209< else $out="";
210< if(!$this->_passive) {
211< $this->SendMSG("Only passive connections available!");
212< return FALSE;
213< }
214< while (!feof($this->_ftp_data_sock)) {
215< $block=fread($this->_ftp_data_sock, $this->_ftp_buff_size);
216< if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_local], $block);
217< if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block));
218< else $out.=$block;
219---
220> function _data_read( $mode = FTP_ASCII, $fp = NULL ) {
221> $out = "";
222> if ( is_resource( $fp ) ) {
223> $out = 0;
224> }
225>
226> if ( ! $this->_passive ) {
227> $this->SendMSG( "Only passive connections available!" );
228> return false;
229> }
230>
231> while ( ! feof( $this->_ftp_data_sock ) ) {
232> $block = fread( $this->_ftp_data_sock, $this->_ftp_buff_size );
233>
234> if ( $mode != FTP_BINARY ) {
235> $block = preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_local], $block );
236> }
237>
238> if( is_resource( $fp ) ) {
239> $out += fwrite( $fp, $block, strlen( $block ) );
240> } else {
241> $out .= $block;
242> }
243139a184
244>
245143,153c188,206
246< function _data_write($mode=FTP_ASCII, $fp=NULL) {
247< if(is_resource($fp)) $out=0;
248< else $out="";
249< if(!$this->_passive) {
250< $this->SendMSG("Only passive connections available!");
251< return FALSE;
252< }
253< if(is_resource($fp)) {
254< while(!feof($fp)) {
255< $block=fread($fp, $this->_ftp_buff_size);
256< if(!$this->_data_write_block($mode, $block)) return false;
257---
258> function _data_write( $mode = FTP_ASCII, $fp=NULL ) {
259> $out = "";
260> if ( is_resource( $fp ) ) {
261> $out = 0;
262> }
263>
264> if ( ! $this->_passive ) {
265> $this->SendMSG( "Only passive connections available!" );
266> return false;
267> }
268>
269> if ( is_resource( $fp ) ) {
270>
271> while ( ! feof( $fp ) ) {
272> $block = fread( $fp, $this->_ftp_buff_size );
273>
274> if( ! $this->_data_write_block( $mode, $block ) ) {
275> return false;
276> }
277155,156c208,212
278< } elseif(!$this->_data_write_block($mode, $fp)) return false;
279< return TRUE;
280---
281> } elseif ( ! $this->_data_write_block( $mode, $fp ) ) {
282> return false;
283> }
284>
285> return true;
286159,160c215,220
287< function _data_write_block($mode, $block) {
288< if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_remote], $block);
289---
290> function _data_write_block( $mode, $block ) {
291>
292> if ( $mode != FTP_BINARY) {
293> $block = preg_replace( "/\r\n|\r|\n/", $this->_eol_code[$this->OS_remote], $block );
294> }
295>
296162,164c222,225
297< if(($t=@fwrite($this->_ftp_data_sock, $block))===FALSE) {
298< $this->PushError("_data_write","Can't write to socket");
299< return FALSE;
300---
301> $t = @fwrite( $this->_ftp_data_sock, $block );
302> if ( false === $t ) {
303> $this->push_error( '_data_write', "Can't write to socket" );
304> return false;
305166,167c227,229
306< $block=substr($block, $t);
307< } while(!empty($block));
308---
309> $block = substr( $block, $t );
310> } while ( ! empty( $block ) );
311>
312172,174c234,236
313< @fclose($this->_ftp_data_sock);
314< $this->SendMSG("Disconnected data from remote host");
315< return TRUE;
316---
317> @fclose( $this->_ftp_data_sock );
318> $this->SendMSG( "Disconnected data from remote host" );
319> return true;
320177,181c239,244
321< function _quit($force=FALSE) {
322< if($this->_connected or $force) {
323< @fclose($this->_ftp_control_sock);
324< $this->_connected=false;
325< $this->SendMSG("Socket closed");
326---
327> function _quit( $force = false ) {
328>
329> if ( $this->_connected || $force ) {
330> @fclose( $this->_ftp_control_sock );
331> $this->_connected = false;
332> $this->SendMSG( "Socket closed" );