Completed
Push — master ( c0c536...fdb3a7 )
by Stephen
20:33
created
src/wp-includes/class-pop3.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -626,6 +626,9 @@
 block discarded – undo
626 626
         }
627 627
     }
628 628
 
629
+    /**
630
+     * @param string $server_text
631
+     */
629 632
     function parse_banner ( $server_text ) {
630 633
         $outside = true;
631 634
         $banner = "";
Please login to merge, or discard this patch.
Spacing   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -17,49 +17,49 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 class POP3 {
20
-    var $ERROR      = '';       //  Error string.
20
+    var $ERROR      = ''; //  Error string.
21 21
 
22
-    var $TIMEOUT    = 60;       //  Default timeout before giving up on a
22
+    var $TIMEOUT    = 60; //  Default timeout before giving up on a
23 23
                                 //  network operation.
24 24
 
25
-    var $COUNT      = -1;       //  Mailbox msg count
25
+    var $COUNT      = -1; //  Mailbox msg count
26 26
 
27
-    var $BUFFER     = 512;      //  Socket buffer for socket fgets() calls.
27
+    var $BUFFER     = 512; //  Socket buffer for socket fgets() calls.
28 28
                                 //  Per RFC 1939 the returned line a POP3
29 29
                                 //  server can send is 512 bytes.
30 30
 
31
-    var $FP         = '';       //  The connection to the server's
31
+    var $FP         = ''; //  The connection to the server's
32 32
                                 //  file descriptor
33 33
 
34
-    var $MAILSERVER = '';       // Set this to hard code the server name
34
+    var $MAILSERVER = ''; // Set this to hard code the server name
35 35
 
36
-    var $DEBUG      = FALSE;    // set to true to echo pop3
36
+    var $DEBUG      = FALSE; // set to true to echo pop3
37 37
                                 // commands and responses to error_log
38 38
                                 // this WILL log passwords!
39 39
 
40
-    var $BANNER     = '';       //  Holds the banner returned by the
40
+    var $BANNER     = ''; //  Holds the banner returned by the
41 41
                                 //  pop server - used for apop()
42 42
 
43
-    var $ALLOWAPOP  = FALSE;    //  Allow or disallow apop()
43
+    var $ALLOWAPOP  = FALSE; //  Allow or disallow apop()
44 44
                                 //  This must be set to true
45 45
                                 //  manually
46 46
 
47 47
 	/**
48 48
 	 * PHP5 constructor.
49 49
 	 */
50
-    function __construct ( $server = '', $timeout = '' ) {
51
-        settype($this->BUFFER,"integer");
52
-        if( !empty($server) ) {
50
+    function __construct($server = '', $timeout = '') {
51
+        settype($this->BUFFER, "integer");
52
+        if ( ! empty($server)) {
53 53
             // Do not allow programs to alter MAILSERVER
54 54
             // if it is already specified. They can get around
55 55
             // this if they -really- want to, so don't count on it.
56
-            if(empty($this->MAILSERVER))
56
+            if (empty($this->MAILSERVER))
57 57
                 $this->MAILSERVER = $server;
58 58
         }
59
-        if(!empty($timeout)) {
60
-            settype($timeout,"integer");
59
+        if ( ! empty($timeout)) {
60
+            settype($timeout, "integer");
61 61
             $this->TIMEOUT = $timeout;
62
-            if (!ini_get('safe_mode'))
62
+            if ( ! ini_get('safe_mode'))
63 63
                 set_time_limit($timeout);
64 64
         }
65 65
         return true;
@@ -68,48 +68,48 @@  discard block
 block discarded – undo
68 68
 	/**
69 69
 	 * PHP4 constructor.
70 70
 	 */
71
-	public function POP3( $server = '', $timeout = '' ) {
72
-		self::__construct( $server, $timeout );
71
+	public function POP3($server = '', $timeout = '') {
72
+		self::__construct($server, $timeout);
73 73
 	}
74 74
 
75
-    function update_timer () {
76
-        if (!ini_get('safe_mode'))
75
+    function update_timer() {
76
+        if ( ! ini_get('safe_mode'))
77 77
             set_time_limit($this->TIMEOUT);
78 78
         return true;
79 79
     }
80 80
 
81
-    function connect ($server, $port = 110)  {
81
+    function connect($server, $port = 110) {
82 82
         //  Opens a socket to the specified server. Unless overridden,
83 83
         //  port defaults to 110. Returns true on success, false on fail
84 84
 
85 85
         // If MAILSERVER is set, override $server with it's value
86 86
 
87
-    if (!isset($port) || !$port) {$port = 110;}
88
-        if(!empty($this->MAILSERVER))
87
+    if ( ! isset($port) || ! $port) {$port = 110; }
88
+        if ( ! empty($this->MAILSERVER))
89 89
             $server = $this->MAILSERVER;
90 90
 
91
-        if(empty($server)){
92
-            $this->ERROR = "POP3 connect: " . _("No server specified");
91
+        if (empty($server)) {
92
+            $this->ERROR = "POP3 connect: "._("No server specified");
93 93
             unset($this->FP);
94 94
             return false;
95 95
         }
96 96
 
97 97
         $fp = @fsockopen("$server", $port, $errno, $errstr);
98 98
 
99
-        if(!$fp) {
100
-            $this->ERROR = "POP3 connect: " . _("Error ") . "[$errno] [$errstr]";
99
+        if ( ! $fp) {
100
+            $this->ERROR = "POP3 connect: "._("Error ")."[$errno] [$errstr]";
101 101
             unset($this->FP);
102 102
             return false;
103 103
         }
104 104
 
105
-        socket_set_blocking($fp,-1);
105
+        socket_set_blocking($fp, -1);
106 106
         $this->update_timer();
107
-        $reply = fgets($fp,$this->BUFFER);
107
+        $reply = fgets($fp, $this->BUFFER);
108 108
         $reply = $this->strip_clf($reply);
109
-        if($this->DEBUG)
110
-            error_log("POP3 SEND [connect: $server] GOT [$reply]",0);
111
-        if(!$this->is_ok($reply)) {
112
-            $this->ERROR = "POP3 connect: " . _("Error ") . "[$reply]";
109
+        if ($this->DEBUG)
110
+            error_log("POP3 SEND [connect: $server] GOT [$reply]", 0);
111
+        if ( ! $this->is_ok($reply)) {
112
+            $this->ERROR = "POP3 connect: "._("Error ")."[$reply]";
113 113
             unset($this->FP);
114 114
             return false;
115 115
         }
@@ -118,39 +118,39 @@  discard block
 block discarded – undo
118 118
         return true;
119 119
     }
120 120
 
121
-    function user ($user = "") {
121
+    function user($user = "") {
122 122
         // Sends the USER command, returns true or false
123 123
 
124
-        if( empty($user) ) {
125
-            $this->ERROR = "POP3 user: " . _("no login ID submitted");
124
+        if (empty($user)) {
125
+            $this->ERROR = "POP3 user: "._("no login ID submitted");
126 126
             return false;
127
-        } elseif(!isset($this->FP)) {
128
-            $this->ERROR = "POP3 user: " . _("connection not established");
127
+        } elseif ( ! isset($this->FP)) {
128
+            $this->ERROR = "POP3 user: "._("connection not established");
129 129
             return false;
130 130
         } else {
131 131
             $reply = $this->send_cmd("USER $user");
132
-            if(!$this->is_ok($reply)) {
133
-                $this->ERROR = "POP3 user: " . _("Error ") . "[$reply]";
132
+            if ( ! $this->is_ok($reply)) {
133
+                $this->ERROR = "POP3 user: "._("Error ")."[$reply]";
134 134
                 return false;
135 135
             } else
136 136
                 return true;
137 137
         }
138 138
     }
139 139
 
140
-    function pass ($pass = "")     {
140
+    function pass($pass = "") {
141 141
         // Sends the PASS command, returns # of msgs in mailbox,
142 142
         // returns false (undef) on Auth failure
143 143
 
144
-        if(empty($pass)) {
145
-            $this->ERROR = "POP3 pass: " . _("No password submitted");
144
+        if (empty($pass)) {
145
+            $this->ERROR = "POP3 pass: "._("No password submitted");
146 146
             return false;
147
-        } elseif(!isset($this->FP)) {
148
-            $this->ERROR = "POP3 pass: " . _("connection not established");
147
+        } elseif ( ! isset($this->FP)) {
148
+            $this->ERROR = "POP3 pass: "._("connection not established");
149 149
             return false;
150 150
         } else {
151 151
             $reply = $this->send_cmd("PASS $pass");
152
-            if(!$this->is_ok($reply)) {
153
-                $this->ERROR = "POP3 pass: " . _("Authentication failed") . " [$reply]";
152
+            if ( ! $this->is_ok($reply)) {
153
+                $this->ERROR = "POP3 pass: "._("Authentication failed")." [$reply]";
154 154
                 $this->quit();
155 155
                 return false;
156 156
             } else {
@@ -162,29 +162,29 @@  discard block
 block discarded – undo
162 162
         }
163 163
     }
164 164
 
165
-    function apop ($login,$pass) {
165
+    function apop($login, $pass) {
166 166
         //  Attempts an APOP login. If this fails, it'll
167 167
         //  try a standard login. YOUR SERVER MUST SUPPORT
168 168
         //  THE USE OF THE APOP COMMAND!
169 169
         //  (apop is optional per rfc1939)
170 170
 
171
-        if(!isset($this->FP)) {
172
-            $this->ERROR = "POP3 apop: " . _("No connection to server");
171
+        if ( ! isset($this->FP)) {
172
+            $this->ERROR = "POP3 apop: "._("No connection to server");
173 173
             return false;
174
-        } elseif(!$this->ALLOWAPOP) {
175
-            $retVal = $this->login($login,$pass);
174
+        } elseif ( ! $this->ALLOWAPOP) {
175
+            $retVal = $this->login($login, $pass);
176 176
             return $retVal;
177
-        } elseif(empty($login)) {
178
-            $this->ERROR = "POP3 apop: " . _("No login ID submitted");
177
+        } elseif (empty($login)) {
178
+            $this->ERROR = "POP3 apop: "._("No login ID submitted");
179 179
             return false;
180
-        } elseif(empty($pass)) {
181
-            $this->ERROR = "POP3 apop: " . _("No password submitted");
180
+        } elseif (empty($pass)) {
181
+            $this->ERROR = "POP3 apop: "._("No password submitted");
182 182
             return false;
183 183
         } else {
184 184
             $banner = $this->BANNER;
185
-            if( (!$banner) or (empty($banner)) ) {
186
-                $this->ERROR = "POP3 apop: " . _("No server banner") . ' - ' . _("abort");
187
-                $retVal = $this->login($login,$pass);
185
+            if (( ! $banner) or (empty($banner))) {
186
+                $this->ERROR = "POP3 apop: "._("No server banner").' - '._("abort");
187
+                $retVal = $this->login($login, $pass);
188 188
                 return $retVal;
189 189
             } else {
190 190
                 $AuthString = $banner;
@@ -192,9 +192,9 @@  discard block
 block discarded – undo
192 192
                 $APOPString = md5($AuthString);
193 193
                 $cmd = "APOP $login $APOPString";
194 194
                 $reply = $this->send_cmd($cmd);
195
-                if(!$this->is_ok($reply)) {
196
-                    $this->ERROR = "POP3 apop: " . _("apop authentication failed") . ' - ' . _("abort");
197
-                    $retVal = $this->login($login,$pass);
195
+                if ( ! $this->is_ok($reply)) {
196
+                    $this->ERROR = "POP3 apop: "._("apop authentication failed").' - '._("abort");
197
+                    $retVal = $this->login($login, $pass);
198 198
                     return $retVal;
199 199
                 } else {
200 200
                     //  Auth successful.
@@ -206,22 +206,22 @@  discard block
 block discarded – undo
206 206
         }
207 207
     }
208 208
 
209
-    function login ($login = "", $pass = "") {
209
+    function login($login = "", $pass = "") {
210 210
         // Sends both user and pass. Returns # of msgs in mailbox or
211 211
         // false on failure (or -1, if the error occurs while getting
212 212
         // the number of messages.)
213 213
 
214
-        if( !isset($this->FP) ) {
215
-            $this->ERROR = "POP3 login: " . _("No connection to server");
214
+        if ( ! isset($this->FP)) {
215
+            $this->ERROR = "POP3 login: "._("No connection to server");
216 216
             return false;
217 217
         } else {
218 218
             $fp = $this->FP;
219
-            if( !$this->user( $login ) ) {
219
+            if ( ! $this->user($login)) {
220 220
                 //  Preserve the error generated by user()
221 221
                 return false;
222 222
             } else {
223 223
                 $count = $this->pass($pass);
224
-                if( (!$count) || ($count == -1) ) {
224
+                if (( ! $count) || ($count == -1)) {
225 225
                     //  Preserve the error generated by last() and pass()
226 226
                     return false;
227 227
                 } else
@@ -230,14 +230,14 @@  discard block
 block discarded – undo
230 230
         }
231 231
     }
232 232
 
233
-    function top ($msgNum, $numLines = "0") {
233
+    function top($msgNum, $numLines = "0") {
234 234
         //  Gets the header and first $numLines of the msg body
235 235
         //  returns data in an array with each returned line being
236 236
         //  an array element. If $numLines is empty, returns
237 237
         //  only the header information, and none of the body.
238 238
 
239
-        if(!isset($this->FP)) {
240
-            $this->ERROR = "POP3 top: " . _("No connection to server");
239
+        if ( ! isset($this->FP)) {
240
+            $this->ERROR = "POP3 top: "._("No connection to server");
241 241
             return false;
242 242
         }
243 243
         $this->update_timer();
@@ -248,94 +248,94 @@  discard block
 block discarded – undo
248 248
         fwrite($fp, "TOP $msgNum $numLines\r\n");
249 249
         $reply = fgets($fp, $buffer);
250 250
         $reply = $this->strip_clf($reply);
251
-        if($this->DEBUG) {
252
-            @error_log("POP3 SEND [$cmd] GOT [$reply]",0);
251
+        if ($this->DEBUG) {
252
+            @error_log("POP3 SEND [$cmd] GOT [$reply]", 0);
253 253
         }
254
-        if(!$this->is_ok($reply))
254
+        if ( ! $this->is_ok($reply))
255 255
         {
256
-            $this->ERROR = "POP3 top: " . _("Error ") . "[$reply]";
256
+            $this->ERROR = "POP3 top: "._("Error ")."[$reply]";
257 257
             return false;
258 258
         }
259 259
 
260 260
         $count = 0;
261 261
         $MsgArray = array();
262 262
 
263
-        $line = fgets($fp,$buffer);
264
-        while ( !preg_match('/^\.\r\n/',$line))
263
+        $line = fgets($fp, $buffer);
264
+        while ( ! preg_match('/^\.\r\n/', $line))
265 265
         {
266 266
             $MsgArray[$count] = $line;
267 267
             $count++;
268
-            $line = fgets($fp,$buffer);
269
-            if(empty($line))    { break; }
268
+            $line = fgets($fp, $buffer);
269
+            if (empty($line)) { break; }
270 270
         }
271 271
 
272 272
         return $MsgArray;
273 273
     }
274 274
 
275
-    function pop_list ($msgNum = "") {
275
+    function pop_list($msgNum = "") {
276 276
         //  If called with an argument, returns that msgs' size in octets
277 277
         //  No argument returns an associative array of undeleted
278 278
         //  msg numbers and their sizes in octets
279 279
 
280
-        if(!isset($this->FP))
280
+        if ( ! isset($this->FP))
281 281
         {
282
-            $this->ERROR = "POP3 pop_list: " . _("No connection to server");
282
+            $this->ERROR = "POP3 pop_list: "._("No connection to server");
283 283
             return false;
284 284
         }
285 285
         $fp = $this->FP;
286 286
         $Total = $this->COUNT;
287
-        if( (!$Total) or ($Total == -1) )
287
+        if (( ! $Total) or ($Total == -1))
288 288
         {
289 289
             return false;
290 290
         }
291
-        if($Total == 0)
291
+        if ($Total == 0)
292 292
         {
293
-            return array("0","0");
293
+            return array("0", "0");
294 294
             // return -1;   // mailbox empty
295 295
         }
296 296
 
297 297
         $this->update_timer();
298 298
 
299
-        if(!empty($msgNum))
299
+        if ( ! empty($msgNum))
300 300
         {
301 301
             $cmd = "LIST $msgNum";
302
-            fwrite($fp,"$cmd\r\n");
303
-            $reply = fgets($fp,$this->BUFFER);
302
+            fwrite($fp, "$cmd\r\n");
303
+            $reply = fgets($fp, $this->BUFFER);
304 304
             $reply = $this->strip_clf($reply);
305
-            if($this->DEBUG) {
306
-                @error_log("POP3 SEND [$cmd] GOT [$reply]",0);
305
+            if ($this->DEBUG) {
306
+                @error_log("POP3 SEND [$cmd] GOT [$reply]", 0);
307 307
             }
308
-            if(!$this->is_ok($reply))
308
+            if ( ! $this->is_ok($reply))
309 309
             {
310
-                $this->ERROR = "POP3 pop_list: " . _("Error ") . "[$reply]";
310
+                $this->ERROR = "POP3 pop_list: "._("Error ")."[$reply]";
311 311
                 return false;
312 312
             }
313
-            list($junk,$num,$size) = preg_split('/\s+/',$reply);
313
+            list($junk, $num, $size) = preg_split('/\s+/', $reply);
314 314
             return $size;
315 315
         }
316 316
         $cmd = "LIST";
317 317
         $reply = $this->send_cmd($cmd);
318
-        if(!$this->is_ok($reply))
318
+        if ( ! $this->is_ok($reply))
319 319
         {
320 320
             $reply = $this->strip_clf($reply);
321
-            $this->ERROR = "POP3 pop_list: " . _("Error ") .  "[$reply]";
321
+            $this->ERROR = "POP3 pop_list: "._("Error ")."[$reply]";
322 322
             return false;
323 323
         }
324 324
         $MsgArray = array();
325 325
         $MsgArray[0] = $Total;
326
-        for($msgC=1;$msgC <= $Total; $msgC++)
326
+        for ($msgC = 1; $msgC <= $Total; $msgC++)
327 327
         {
328
-            if($msgC > $Total) { break; }
329
-            $line = fgets($fp,$this->BUFFER);
328
+            if ($msgC > $Total) { break; }
329
+            $line = fgets($fp, $this->BUFFER);
330 330
             $line = $this->strip_clf($line);
331
-            if(strpos($line, '.') === 0)
331
+            if (strpos($line, '.') === 0)
332 332
             {
333
-                $this->ERROR = "POP3 pop_list: " . _("Premature end of list");
333
+                $this->ERROR = "POP3 pop_list: "._("Premature end of list");
334 334
                 return false;
335 335
             }
336
-            list($thisMsg,$msgSize) = preg_split('/\s+/',$line);
337
-            settype($thisMsg,"integer");
338
-            if($thisMsg != $msgC)
336
+            list($thisMsg, $msgSize) = preg_split('/\s+/', $line);
337
+            settype($thisMsg, "integer");
338
+            if ($thisMsg != $msgC)
339 339
             {
340 340
                 $MsgArray[$msgC] = "deleted";
341 341
             }
@@ -347,13 +347,13 @@  discard block
 block discarded – undo
347 347
         return $MsgArray;
348 348
     }
349 349
 
350
-    function get ($msgNum) {
350
+    function get($msgNum) {
351 351
         //  Retrieve the specified msg number. Returns an array
352 352
         //  where each line of the msg is an array element.
353 353
 
354
-        if(!isset($this->FP))
354
+        if ( ! isset($this->FP))
355 355
         {
356
-            $this->ERROR = "POP3 get: " . _("No connection to server");
356
+            $this->ERROR = "POP3 get: "._("No connection to server");
357 357
             return false;
358 358
         }
359 359
 
@@ -364,83 +364,83 @@  discard block
 block discarded – undo
364 364
         $cmd = "RETR $msgNum";
365 365
         $reply = $this->send_cmd($cmd);
366 366
 
367
-        if(!$this->is_ok($reply))
367
+        if ( ! $this->is_ok($reply))
368 368
         {
369
-            $this->ERROR = "POP3 get: " . _("Error ") . "[$reply]";
369
+            $this->ERROR = "POP3 get: "._("Error ")."[$reply]";
370 370
             return false;
371 371
         }
372 372
 
373 373
         $count = 0;
374 374
         $MsgArray = array();
375 375
 
376
-        $line = fgets($fp,$buffer);
377
-        while ( !preg_match('/^\.\r\n/',$line))
376
+        $line = fgets($fp, $buffer);
377
+        while ( ! preg_match('/^\.\r\n/', $line))
378 378
         {
379
-            if ( $line{0} == '.' ) { $line = substr($line,1); }
379
+            if ($line{0} == '.') { $line = substr($line, 1); }
380 380
             $MsgArray[$count] = $line;
381 381
             $count++;
382
-            $line = fgets($fp,$buffer);
383
-            if(empty($line))    { break; }
382
+            $line = fgets($fp, $buffer);
383
+            if (empty($line)) { break; }
384 384
         }
385 385
         return $MsgArray;
386 386
     }
387 387
 
388
-    function last ( $type = "count" ) {
388
+    function last($type = "count") {
389 389
         //  Returns the highest msg number in the mailbox.
390 390
         //  returns -1 on error, 0+ on success, if type != count
391 391
         //  results in a popstat() call (2 element array returned)
392 392
 
393 393
         $last = -1;
394
-        if(!isset($this->FP))
394
+        if ( ! isset($this->FP))
395 395
         {
396
-            $this->ERROR = "POP3 last: " . _("No connection to server");
396
+            $this->ERROR = "POP3 last: "._("No connection to server");
397 397
             return $last;
398 398
         }
399 399
 
400 400
         $reply = $this->send_cmd("STAT");
401
-        if(!$this->is_ok($reply))
401
+        if ( ! $this->is_ok($reply))
402 402
         {
403
-            $this->ERROR = "POP3 last: " . _("Error ") . "[$reply]";
403
+            $this->ERROR = "POP3 last: "._("Error ")."[$reply]";
404 404
             return $last;
405 405
         }
406 406
 
407
-        $Vars = preg_split('/\s+/',$reply);
407
+        $Vars = preg_split('/\s+/', $reply);
408 408
         $count = $Vars[1];
409 409
         $size = $Vars[2];
410
-        settype($count,"integer");
411
-        settype($size,"integer");
412
-        if($type != "count")
410
+        settype($count, "integer");
411
+        settype($size, "integer");
412
+        if ($type != "count")
413 413
         {
414
-            return array($count,$size);
414
+            return array($count, $size);
415 415
         }
416 416
         return $count;
417 417
     }
418 418
 
419
-    function reset () {
419
+    function reset() {
420 420
         //  Resets the status of the remote server. This includes
421 421
         //  resetting the status of ALL msgs to not be deleted.
422 422
         //  This method automatically closes the connection to the server.
423 423
 
424
-        if(!isset($this->FP))
424
+        if ( ! isset($this->FP))
425 425
         {
426
-            $this->ERROR = "POP3 reset: " . _("No connection to server");
426
+            $this->ERROR = "POP3 reset: "._("No connection to server");
427 427
             return false;
428 428
         }
429 429
         $reply = $this->send_cmd("RSET");
430
-        if(!$this->is_ok($reply))
430
+        if ( ! $this->is_ok($reply))
431 431
         {
432 432
             //  The POP3 RSET command -never- gives a -ERR
433 433
             //  response - if it ever does, something truely
434 434
             //  wild is going on.
435 435
 
436
-            $this->ERROR = "POP3 reset: " . _("Error ") . "[$reply]";
437
-            @error_log("POP3 reset: ERROR [$reply]",0);
436
+            $this->ERROR = "POP3 reset: "._("Error ")."[$reply]";
437
+            @error_log("POP3 reset: ERROR [$reply]", 0);
438 438
         }
439 439
         $this->quit();
440 440
         return true;
441 441
     }
442 442
 
443
-    function send_cmd ( $cmd = "" )
443
+    function send_cmd($cmd = "")
444 444
     {
445 445
         //  Sends a user defined command string to the
446 446
         //  POP server and returns the results. Useful for
@@ -455,25 +455,25 @@  discard block
 block discarded – undo
455 455
         //  This method works best if $cmd responds with only
456 456
         //  one line of data.
457 457
 
458
-        if(!isset($this->FP))
458
+        if ( ! isset($this->FP))
459 459
         {
460
-            $this->ERROR = "POP3 send_cmd: " . _("No connection to server");
460
+            $this->ERROR = "POP3 send_cmd: "._("No connection to server");
461 461
             return false;
462 462
         }
463 463
 
464
-        if(empty($cmd))
464
+        if (empty($cmd))
465 465
         {
466
-            $this->ERROR = "POP3 send_cmd: " . _("Empty command string");
466
+            $this->ERROR = "POP3 send_cmd: "._("Empty command string");
467 467
             return "";
468 468
         }
469 469
 
470 470
         $fp = $this->FP;
471 471
         $buffer = $this->BUFFER;
472 472
         $this->update_timer();
473
-        fwrite($fp,"$cmd\r\n");
474
-        $reply = fgets($fp,$buffer);
473
+        fwrite($fp, "$cmd\r\n");
474
+        $reply = fgets($fp, $buffer);
475 475
         $reply = $this->strip_clf($reply);
476
-        if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); }
476
+        if ($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]", 0); }
477 477
         return $reply;
478 478
     }
479 479
 
@@ -481,61 +481,61 @@  discard block
 block discarded – undo
481 481
         //  Closes the connection to the POP3 server, deleting
482 482
         //  any msgs marked as deleted.
483 483
 
484
-        if(!isset($this->FP))
484
+        if ( ! isset($this->FP))
485 485
         {
486
-            $this->ERROR = "POP3 quit: " . _("connection does not exist");
486
+            $this->ERROR = "POP3 quit: "._("connection does not exist");
487 487
             return false;
488 488
         }
489 489
         $fp = $this->FP;
490 490
         $cmd = "QUIT";
491
-        fwrite($fp,"$cmd\r\n");
492
-        $reply = fgets($fp,$this->BUFFER);
491
+        fwrite($fp, "$cmd\r\n");
492
+        $reply = fgets($fp, $this->BUFFER);
493 493
         $reply = $this->strip_clf($reply);
494
-        if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); }
494
+        if ($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]", 0); }
495 495
         fclose($fp);
496 496
         unset($this->FP);
497 497
         return true;
498 498
     }
499 499
 
500
-    function popstat () {
500
+    function popstat() {
501 501
         //  Returns an array of 2 elements. The number of undeleted
502 502
         //  msgs in the mailbox, and the size of the mbox in octets.
503 503
 
504 504
         $PopArray = $this->last("array");
505 505
 
506
-        if($PopArray == -1) { return false; }
506
+        if ($PopArray == -1) { return false; }
507 507
 
508
-        if( (!$PopArray) or (empty($PopArray)) )
508
+        if (( ! $PopArray) or (empty($PopArray)))
509 509
         {
510 510
             return false;
511 511
         }
512 512
         return $PopArray;
513 513
     }
514 514
 
515
-    function uidl ($msgNum = "")
515
+    function uidl($msgNum = "")
516 516
     {
517 517
         //  Returns the UIDL of the msg specified. If called with
518 518
         //  no arguments, returns an associative array where each
519 519
         //  undeleted msg num is a key, and the msg's uidl is the element
520 520
         //  Array element 0 will contain the total number of msgs
521 521
 
522
-        if(!isset($this->FP)) {
523
-            $this->ERROR = "POP3 uidl: " . _("No connection to server");
522
+        if ( ! isset($this->FP)) {
523
+            $this->ERROR = "POP3 uidl: "._("No connection to server");
524 524
             return false;
525 525
         }
526 526
 
527 527
         $fp = $this->FP;
528 528
         $buffer = $this->BUFFER;
529 529
 
530
-        if(!empty($msgNum)) {
530
+        if ( ! empty($msgNum)) {
531 531
             $cmd = "UIDL $msgNum";
532 532
             $reply = $this->send_cmd($cmd);
533
-            if(!$this->is_ok($reply))
533
+            if ( ! $this->is_ok($reply))
534 534
             {
535
-                $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]";
535
+                $this->ERROR = "POP3 uidl: "._("Error ")."[$reply]";
536 536
                 return false;
537 537
             }
538
-            list ($ok,$num,$myUidl) = preg_split('/\s+/',$reply);
538
+            list ($ok, $num, $myUidl) = preg_split('/\s+/', $reply);
539 539
             return $myUidl;
540 540
         } else {
541 541
             $this->update_timer();
@@ -552,20 +552,20 @@  discard block
 block discarded – undo
552 552
             fwrite($fp, "UIDL\r\n");
553 553
             $reply = fgets($fp, $buffer);
554 554
             $reply = $this->strip_clf($reply);
555
-            if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); }
556
-            if(!$this->is_ok($reply))
555
+            if ($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]", 0); }
556
+            if ( ! $this->is_ok($reply))
557 557
             {
558
-                $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]";
558
+                $this->ERROR = "POP3 uidl: "._("Error ")."[$reply]";
559 559
                 return false;
560 560
             }
561 561
 
562 562
             $line = "";
563 563
             $count = 1;
564
-            $line = fgets($fp,$buffer);
565
-            while ( !preg_match('/^\.\r\n/',$line)) {
566
-                list ($msg,$msgUidl) = preg_split('/\s+/',$line);
564
+            $line = fgets($fp, $buffer);
565
+            while ( ! preg_match('/^\.\r\n/', $line)) {
566
+                list ($msg, $msgUidl) = preg_split('/\s+/', $line);
567 567
                 $msgUidl = $this->strip_clf($msgUidl);
568
-                if($count == $msg) {
568
+                if ($count == $msg) {
569 569
                     $UIDLArray[$msg] = $msgUidl;
570 570
                 }
571 571
                 else
@@ -573,30 +573,30 @@  discard block
 block discarded – undo
573 573
                     $UIDLArray[$count] = 'deleted';
574 574
                 }
575 575
                 $count++;
576
-                $line = fgets($fp,$buffer);
576
+                $line = fgets($fp, $buffer);
577 577
             }
578 578
         }
579 579
         return $UIDLArray;
580 580
     }
581 581
 
582
-    function delete ($msgNum = "") {
582
+    function delete($msgNum = "") {
583 583
         //  Flags a specified msg as deleted. The msg will not
584 584
         //  be deleted until a quit() method is called.
585 585
 
586
-        if(!isset($this->FP))
586
+        if ( ! isset($this->FP))
587 587
         {
588
-            $this->ERROR = "POP3 delete: " . _("No connection to server");
588
+            $this->ERROR = "POP3 delete: "._("No connection to server");
589 589
             return false;
590 590
         }
591
-        if(empty($msgNum))
591
+        if (empty($msgNum))
592 592
         {
593
-            $this->ERROR = "POP3 delete: " . _("No msg number submitted");
593
+            $this->ERROR = "POP3 delete: "._("No msg number submitted");
594 594
             return false;
595 595
         }
596 596
         $reply = $this->send_cmd("DELE $msgNum");
597
-        if(!$this->is_ok($reply))
597
+        if ( ! $this->is_ok($reply))
598 598
         {
599
-            $this->ERROR = "POP3 delete: " . _("Command failed ") . "[$reply]";
599
+            $this->ERROR = "POP3 delete: "._("Command failed ")."[$reply]";
600 600
             return false;
601 601
         }
602 602
         return true;
@@ -606,35 +606,35 @@  discard block
 block discarded – undo
606 606
 
607 607
     //  The following methods are internal to the class.
608 608
 
609
-    function is_ok ($cmd = "") {
609
+    function is_ok($cmd = "") {
610 610
         //  Return true or false on +OK or -ERR
611 611
 
612
-        if( empty($cmd) )
612
+        if (empty($cmd))
613 613
             return false;
614 614
         else
615
-            return( stripos($cmd, '+OK') !== false );
615
+            return(stripos($cmd, '+OK') !== false);
616 616
     }
617 617
 
618
-    function strip_clf ($text = "") {
618
+    function strip_clf($text = "") {
619 619
         // Strips \r\n from server responses
620 620
 
621
-        if(empty($text))
621
+        if (empty($text))
622 622
             return $text;
623 623
         else {
624
-            $stripped = str_replace(array("\r","\n"),'',$text);
624
+            $stripped = str_replace(array("\r", "\n"), '', $text);
625 625
             return $stripped;
626 626
         }
627 627
     }
628 628
 
629
-    function parse_banner ( $server_text ) {
629
+    function parse_banner($server_text) {
630 630
         $outside = true;
631 631
         $banner = "";
632 632
         $length = strlen($server_text);
633
-        for($count =0; $count < $length; $count++)
633
+        for ($count = 0; $count < $length; $count++)
634 634
         {
635
-            $digit = substr($server_text,$count,1);
636
-            if(!empty($digit))             {
637
-                if( (!$outside) && ($digit != '<') && ($digit != '>') )
635
+            $digit = substr($server_text, $count, 1);
636
+            if ( ! empty($digit)) {
637
+                if (( ! $outside) && ($digit != '<') && ($digit != '>'))
638 638
                 {
639 639
                     $banner .= $digit;
640 640
                 }
@@ -642,21 +642,21 @@  discard block
 block discarded – undo
642 642
                 {
643 643
                     $outside = false;
644 644
                 }
645
-                if($digit == '>')
645
+                if ($digit == '>')
646 646
                 {
647 647
                     $outside = true;
648 648
                 }
649 649
             }
650 650
         }
651
-        $banner = $this->strip_clf($banner);    // Just in case
651
+        $banner = $this->strip_clf($banner); // Just in case
652 652
         return "<$banner>";
653 653
     }
654 654
 
655 655
 }   // End class
656 656
 
657 657
 // For php4 compatibility
658
-if (!function_exists("stripos")) {
659
-    function stripos($haystack, $needle){
660
-        return strpos($haystack, stristr( $haystack, $needle ));
658
+if ( ! function_exists("stripos")) {
659
+    function stripos($haystack, $needle) {
660
+        return strpos($haystack, stristr($haystack, $needle));
661 661
     }
662 662
 }
Please login to merge, or discard this patch.
Braces   +31 added lines, -25 removed lines patch added patch discarded remove patch
@@ -53,14 +53,16 @@  discard block
 block discarded – undo
53 53
             // Do not allow programs to alter MAILSERVER
54 54
             // if it is already specified. They can get around
55 55
             // this if they -really- want to, so don't count on it.
56
-            if(empty($this->MAILSERVER))
57
-                $this->MAILSERVER = $server;
56
+            if(empty($this->MAILSERVER)) {
57
+                            $this->MAILSERVER = $server;
58
+            }
58 59
         }
59 60
         if(!empty($timeout)) {
60 61
             settype($timeout,"integer");
61 62
             $this->TIMEOUT = $timeout;
62
-            if (!ini_get('safe_mode'))
63
-                set_time_limit($timeout);
63
+            if (!ini_get('safe_mode')) {
64
+                            set_time_limit($timeout);
65
+            }
64 66
         }
65 67
         return true;
66 68
     }
@@ -73,8 +75,9 @@  discard block
 block discarded – undo
73 75
 	}
74 76
 
75 77
     function update_timer () {
76
-        if (!ini_get('safe_mode'))
77
-            set_time_limit($this->TIMEOUT);
78
+        if (!ini_get('safe_mode')) {
79
+                    set_time_limit($this->TIMEOUT);
80
+        }
78 81
         return true;
79 82
     }
80 83
 
@@ -85,8 +88,9 @@  discard block
 block discarded – undo
85 88
         // If MAILSERVER is set, override $server with it's value
86 89
 
87 90
     if (!isset($port) || !$port) {$port = 110;}
88
-        if(!empty($this->MAILSERVER))
89
-            $server = $this->MAILSERVER;
91
+        if(!empty($this->MAILSERVER)) {
92
+                    $server = $this->MAILSERVER;
93
+        }
90 94
 
91 95
         if(empty($server)){
92 96
             $this->ERROR = "POP3 connect: " . _("No server specified");
@@ -106,8 +110,9 @@  discard block
 block discarded – undo
106 110
         $this->update_timer();
107 111
         $reply = fgets($fp,$this->BUFFER);
108 112
         $reply = $this->strip_clf($reply);
109
-        if($this->DEBUG)
110
-            error_log("POP3 SEND [connect: $server] GOT [$reply]",0);
113
+        if($this->DEBUG) {
114
+                    error_log("POP3 SEND [connect: $server] GOT [$reply]",0);
115
+        }
111 116
         if(!$this->is_ok($reply)) {
112 117
             $this->ERROR = "POP3 connect: " . _("Error ") . "[$reply]";
113 118
             unset($this->FP);
@@ -132,8 +137,9 @@  discard block
 block discarded – undo
132 137
             if(!$this->is_ok($reply)) {
133 138
                 $this->ERROR = "POP3 user: " . _("Error ") . "[$reply]";
134 139
                 return false;
135
-            } else
136
-                return true;
140
+            } else {
141
+                            return true;
142
+            }
137 143
         }
138 144
     }
139 145
 
@@ -224,8 +230,9 @@  discard block
 block discarded – undo
224 230
                 if( (!$count) || ($count == -1) ) {
225 231
                     //  Preserve the error generated by last() and pass()
226 232
                     return false;
227
-                } else
228
-                    return $count;
233
+                } else {
234
+                                    return $count;
235
+                }
229 236
             }
230 237
         }
231 238
     }
@@ -338,8 +345,7 @@  discard block
 block discarded – undo
338 345
             if($thisMsg != $msgC)
339 346
             {
340 347
                 $MsgArray[$msgC] = "deleted";
341
-            }
342
-            else
348
+            } else
343 349
             {
344 350
                 $MsgArray[$msgC] = $msgSize;
345 351
             }
@@ -567,8 +573,7 @@  discard block
 block discarded – undo
567 573
                 $msgUidl = $this->strip_clf($msgUidl);
568 574
                 if($count == $msg) {
569 575
                     $UIDLArray[$msg] = $msgUidl;
570
-                }
571
-                else
576
+                } else
572 577
                 {
573 578
                     $UIDLArray[$count] = 'deleted';
574 579
                 }
@@ -609,18 +614,19 @@  discard block
 block discarded – undo
609 614
     function is_ok ($cmd = "") {
610 615
         //  Return true or false on +OK or -ERR
611 616
 
612
-        if( empty($cmd) )
613
-            return false;
614
-        else
615
-            return( stripos($cmd, '+OK') !== false );
617
+        if( empty($cmd) ) {
618
+                    return false;
619
+        } else {
620
+                    return( stripos($cmd, '+OK') !== false );
621
+        }
616 622
     }
617 623
 
618 624
     function strip_clf ($text = "") {
619 625
         // Strips \r\n from server responses
620 626
 
621
-        if(empty($text))
622
-            return $text;
623
-        else {
627
+        if(empty($text)) {
628
+                    return $text;
629
+        } else {
624 630
             $stripped = str_replace(array("\r","\n"),'',$text);
625 631
             return $stripped;
626 632
         }
Please login to merge, or discard this patch.
Indentation   +617 added lines, -617 removed lines patch added patch discarded remove patch
@@ -17,53 +17,53 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 class POP3 {
20
-    var $ERROR      = '';       //  Error string.
20
+	var $ERROR      = '';       //  Error string.
21 21
 
22
-    var $TIMEOUT    = 60;       //  Default timeout before giving up on a
23
-                                //  network operation.
22
+	var $TIMEOUT    = 60;       //  Default timeout before giving up on a
23
+								//  network operation.
24 24
 
25
-    var $COUNT      = -1;       //  Mailbox msg count
25
+	var $COUNT      = -1;       //  Mailbox msg count
26 26
 
27
-    var $BUFFER     = 512;      //  Socket buffer for socket fgets() calls.
28
-                                //  Per RFC 1939 the returned line a POP3
29
-                                //  server can send is 512 bytes.
27
+	var $BUFFER     = 512;      //  Socket buffer for socket fgets() calls.
28
+								//  Per RFC 1939 the returned line a POP3
29
+								//  server can send is 512 bytes.
30 30
 
31
-    var $FP         = '';       //  The connection to the server's
32
-                                //  file descriptor
31
+	var $FP         = '';       //  The connection to the server's
32
+								//  file descriptor
33 33
 
34
-    var $MAILSERVER = '';       // Set this to hard code the server name
34
+	var $MAILSERVER = '';       // Set this to hard code the server name
35 35
 
36
-    var $DEBUG      = FALSE;    // set to true to echo pop3
37
-                                // commands and responses to error_log
38
-                                // this WILL log passwords!
36
+	var $DEBUG      = FALSE;    // set to true to echo pop3
37
+								// commands and responses to error_log
38
+								// this WILL log passwords!
39 39
 
40
-    var $BANNER     = '';       //  Holds the banner returned by the
41
-                                //  pop server - used for apop()
40
+	var $BANNER     = '';       //  Holds the banner returned by the
41
+								//  pop server - used for apop()
42 42
 
43
-    var $ALLOWAPOP  = FALSE;    //  Allow or disallow apop()
44
-                                //  This must be set to true
45
-                                //  manually
43
+	var $ALLOWAPOP  = FALSE;    //  Allow or disallow apop()
44
+								//  This must be set to true
45
+								//  manually
46 46
 
47 47
 	/**
48 48
 	 * PHP5 constructor.
49 49
 	 */
50
-    function __construct ( $server = '', $timeout = '' ) {
51
-        settype($this->BUFFER,"integer");
52
-        if( !empty($server) ) {
53
-            // Do not allow programs to alter MAILSERVER
54
-            // if it is already specified. They can get around
55
-            // this if they -really- want to, so don't count on it.
56
-            if(empty($this->MAILSERVER))
57
-                $this->MAILSERVER = $server;
58
-        }
59
-        if(!empty($timeout)) {
60
-            settype($timeout,"integer");
61
-            $this->TIMEOUT = $timeout;
62
-            if (!ini_get('safe_mode'))
63
-                set_time_limit($timeout);
64
-        }
65
-        return true;
66
-    }
50
+	function __construct ( $server = '', $timeout = '' ) {
51
+		settype($this->BUFFER,"integer");
52
+		if( !empty($server) ) {
53
+			// Do not allow programs to alter MAILSERVER
54
+			// if it is already specified. They can get around
55
+			// this if they -really- want to, so don't count on it.
56
+			if(empty($this->MAILSERVER))
57
+				$this->MAILSERVER = $server;
58
+		}
59
+		if(!empty($timeout)) {
60
+			settype($timeout,"integer");
61
+			$this->TIMEOUT = $timeout;
62
+			if (!ini_get('safe_mode'))
63
+				set_time_limit($timeout);
64
+		}
65
+		return true;
66
+	}
67 67
 
68 68
 	/**
69 69
 	 * PHP4 constructor.
@@ -72,591 +72,591 @@  discard block
 block discarded – undo
72 72
 		self::__construct( $server, $timeout );
73 73
 	}
74 74
 
75
-    function update_timer () {
76
-        if (!ini_get('safe_mode'))
77
-            set_time_limit($this->TIMEOUT);
78
-        return true;
79
-    }
80
-
81
-    function connect ($server, $port = 110)  {
82
-        //  Opens a socket to the specified server. Unless overridden,
83
-        //  port defaults to 110. Returns true on success, false on fail
84
-
85
-        // If MAILSERVER is set, override $server with its value.
86
-
87
-    if (!isset($port) || !$port) {$port = 110;}
88
-        if(!empty($this->MAILSERVER))
89
-            $server = $this->MAILSERVER;
90
-
91
-        if(empty($server)){
92
-            $this->ERROR = "POP3 connect: " . _("No server specified");
93
-            unset($this->FP);
94
-            return false;
95
-        }
96
-
97
-        $fp = @fsockopen("$server", $port, $errno, $errstr);
98
-
99
-        if(!$fp) {
100
-            $this->ERROR = "POP3 connect: " . _("Error ") . "[$errno] [$errstr]";
101
-            unset($this->FP);
102
-            return false;
103
-        }
104
-
105
-        socket_set_blocking($fp,-1);
106
-        $this->update_timer();
107
-        $reply = fgets($fp,$this->BUFFER);
108
-        $reply = $this->strip_clf($reply);
109
-        if($this->DEBUG)
110
-            error_log("POP3 SEND [connect: $server] GOT [$reply]",0);
111
-        if(!$this->is_ok($reply)) {
112
-            $this->ERROR = "POP3 connect: " . _("Error ") . "[$reply]";
113
-            unset($this->FP);
114
-            return false;
115
-        }
116
-        $this->FP = $fp;
117
-        $this->BANNER = $this->parse_banner($reply);
118
-        return true;
119
-    }
120
-
121
-    function user ($user = "") {
122
-        // Sends the USER command, returns true or false
123
-
124
-        if( empty($user) ) {
125
-            $this->ERROR = "POP3 user: " . _("no login ID submitted");
126
-            return false;
127
-        } elseif(!isset($this->FP)) {
128
-            $this->ERROR = "POP3 user: " . _("connection not established");
129
-            return false;
130
-        } else {
131
-            $reply = $this->send_cmd("USER $user");
132
-            if(!$this->is_ok($reply)) {
133
-                $this->ERROR = "POP3 user: " . _("Error ") . "[$reply]";
134
-                return false;
135
-            } else
136
-                return true;
137
-        }
138
-    }
139
-
140
-    function pass ($pass = "")     {
141
-        // Sends the PASS command, returns # of msgs in mailbox,
142
-        // returns false (undef) on Auth failure
143
-
144
-        if(empty($pass)) {
145
-            $this->ERROR = "POP3 pass: " . _("No password submitted");
146
-            return false;
147
-        } elseif(!isset($this->FP)) {
148
-            $this->ERROR = "POP3 pass: " . _("connection not established");
149
-            return false;
150
-        } else {
151
-            $reply = $this->send_cmd("PASS $pass");
152
-            if(!$this->is_ok($reply)) {
153
-                $this->ERROR = "POP3 pass: " . _("Authentication failed") . " [$reply]";
154
-                $this->quit();
155
-                return false;
156
-            } else {
157
-                //  Auth successful.
158
-                $count = $this->last("count");
159
-                $this->COUNT = $count;
160
-                return $count;
161
-            }
162
-        }
163
-    }
164
-
165
-    function apop ($login,$pass) {
166
-        //  Attempts an APOP login. If this fails, it'll
167
-        //  try a standard login. YOUR SERVER MUST SUPPORT
168
-        //  THE USE OF THE APOP COMMAND!
169
-        //  (apop is optional per rfc1939)
170
-
171
-        if(!isset($this->FP)) {
172
-            $this->ERROR = "POP3 apop: " . _("No connection to server");
173
-            return false;
174
-        } elseif(!$this->ALLOWAPOP) {
175
-            $retVal = $this->login($login,$pass);
176
-            return $retVal;
177
-        } elseif(empty($login)) {
178
-            $this->ERROR = "POP3 apop: " . _("No login ID submitted");
179
-            return false;
180
-        } elseif(empty($pass)) {
181
-            $this->ERROR = "POP3 apop: " . _("No password submitted");
182
-            return false;
183
-        } else {
184
-            $banner = $this->BANNER;
185
-            if( (!$banner) or (empty($banner)) ) {
186
-                $this->ERROR = "POP3 apop: " . _("No server banner") . ' - ' . _("abort");
187
-                $retVal = $this->login($login,$pass);
188
-                return $retVal;
189
-            } else {
190
-                $AuthString = $banner;
191
-                $AuthString .= $pass;
192
-                $APOPString = md5($AuthString);
193
-                $cmd = "APOP $login $APOPString";
194
-                $reply = $this->send_cmd($cmd);
195
-                if(!$this->is_ok($reply)) {
196
-                    $this->ERROR = "POP3 apop: " . _("apop authentication failed") . ' - ' . _("abort");
197
-                    $retVal = $this->login($login,$pass);
198
-                    return $retVal;
199
-                } else {
200
-                    //  Auth successful.
201
-                    $count = $this->last("count");
202
-                    $this->COUNT = $count;
203
-                    return $count;
204
-                }
205
-            }
206
-        }
207
-    }
208
-
209
-    function login ($login = "", $pass = "") {
210
-        // Sends both user and pass. Returns # of msgs in mailbox or
211
-        // false on failure (or -1, if the error occurs while getting
212
-        // the number of messages.)
213
-
214
-        if( !isset($this->FP) ) {
215
-            $this->ERROR = "POP3 login: " . _("No connection to server");
216
-            return false;
217
-        } else {
218
-            $fp = $this->FP;
219
-            if( !$this->user( $login ) ) {
220
-                //  Preserve the error generated by user()
221
-                return false;
222
-            } else {
223
-                $count = $this->pass($pass);
224
-                if( (!$count) || ($count == -1) ) {
225
-                    //  Preserve the error generated by last() and pass()
226
-                    return false;
227
-                } else
228
-                    return $count;
229
-            }
230
-        }
231
-    }
232
-
233
-    function top ($msgNum, $numLines = "0") {
234
-        //  Gets the header and first $numLines of the msg body
235
-        //  returns data in an array with each returned line being
236
-        //  an array element. If $numLines is empty, returns
237
-        //  only the header information, and none of the body.
238
-
239
-        if(!isset($this->FP)) {
240
-            $this->ERROR = "POP3 top: " . _("No connection to server");
241
-            return false;
242
-        }
243
-        $this->update_timer();
244
-
245
-        $fp = $this->FP;
246
-        $buffer = $this->BUFFER;
247
-        $cmd = "TOP $msgNum $numLines";
248
-        fwrite($fp, "TOP $msgNum $numLines\r\n");
249
-        $reply = fgets($fp, $buffer);
250
-        $reply = $this->strip_clf($reply);
251
-        if($this->DEBUG) {
252
-            @error_log("POP3 SEND [$cmd] GOT [$reply]",0);
253
-        }
254
-        if(!$this->is_ok($reply))
255
-        {
256
-            $this->ERROR = "POP3 top: " . _("Error ") . "[$reply]";
257
-            return false;
258
-        }
259
-
260
-        $count = 0;
261
-        $MsgArray = array();
262
-
263
-        $line = fgets($fp,$buffer);
264
-        while ( !preg_match('/^\.\r\n/',$line))
265
-        {
266
-            $MsgArray[$count] = $line;
267
-            $count++;
268
-            $line = fgets($fp,$buffer);
269
-            if(empty($line))    { break; }
270
-        }
271
-
272
-        return $MsgArray;
273
-    }
274
-
275
-    function pop_list ($msgNum = "") {
276
-        //  If called with an argument, returns that msgs' size in octets
277
-        //  No argument returns an associative array of undeleted
278
-        //  msg numbers and their sizes in octets
279
-
280
-        if(!isset($this->FP))
281
-        {
282
-            $this->ERROR = "POP3 pop_list: " . _("No connection to server");
283
-            return false;
284
-        }
285
-        $fp = $this->FP;
286
-        $Total = $this->COUNT;
287
-        if( (!$Total) or ($Total == -1) )
288
-        {
289
-            return false;
290
-        }
291
-        if($Total == 0)
292
-        {
293
-            return array("0","0");
294
-            // return -1;   // mailbox empty
295
-        }
296
-
297
-        $this->update_timer();
298
-
299
-        if(!empty($msgNum))
300
-        {
301
-            $cmd = "LIST $msgNum";
302
-            fwrite($fp,"$cmd\r\n");
303
-            $reply = fgets($fp,$this->BUFFER);
304
-            $reply = $this->strip_clf($reply);
305
-            if($this->DEBUG) {
306
-                @error_log("POP3 SEND [$cmd] GOT [$reply]",0);
307
-            }
308
-            if(!$this->is_ok($reply))
309
-            {
310
-                $this->ERROR = "POP3 pop_list: " . _("Error ") . "[$reply]";
311
-                return false;
312
-            }
313
-            list($junk,$num,$size) = preg_split('/\s+/',$reply);
314
-            return $size;
315
-        }
316
-        $cmd = "LIST";
317
-        $reply = $this->send_cmd($cmd);
318
-        if(!$this->is_ok($reply))
319
-        {
320
-            $reply = $this->strip_clf($reply);
321
-            $this->ERROR = "POP3 pop_list: " . _("Error ") .  "[$reply]";
322
-            return false;
323
-        }
324
-        $MsgArray = array();
325
-        $MsgArray[0] = $Total;
326
-        for($msgC=1;$msgC <= $Total; $msgC++)
327
-        {
328
-            if($msgC > $Total) { break; }
329
-            $line = fgets($fp,$this->BUFFER);
330
-            $line = $this->strip_clf($line);
331
-            if(strpos($line, '.') === 0)
332
-            {
333
-                $this->ERROR = "POP3 pop_list: " . _("Premature end of list");
334
-                return false;
335
-            }
336
-            list($thisMsg,$msgSize) = preg_split('/\s+/',$line);
337
-            settype($thisMsg,"integer");
338
-            if($thisMsg != $msgC)
339
-            {
340
-                $MsgArray[$msgC] = "deleted";
341
-            }
342
-            else
343
-            {
344
-                $MsgArray[$msgC] = $msgSize;
345
-            }
346
-        }
347
-        return $MsgArray;
348
-    }
349
-
350
-    function get ($msgNum) {
351
-        //  Retrieve the specified msg number. Returns an array
352
-        //  where each line of the msg is an array element.
353
-
354
-        if(!isset($this->FP))
355
-        {
356
-            $this->ERROR = "POP3 get: " . _("No connection to server");
357
-            return false;
358
-        }
359
-
360
-        $this->update_timer();
361
-
362
-        $fp = $this->FP;
363
-        $buffer = $this->BUFFER;
364
-        $cmd = "RETR $msgNum";
365
-        $reply = $this->send_cmd($cmd);
366
-
367
-        if(!$this->is_ok($reply))
368
-        {
369
-            $this->ERROR = "POP3 get: " . _("Error ") . "[$reply]";
370
-            return false;
371
-        }
372
-
373
-        $count = 0;
374
-        $MsgArray = array();
375
-
376
-        $line = fgets($fp,$buffer);
377
-        while ( !preg_match('/^\.\r\n/',$line))
378
-        {
379
-            if ( $line{0} == '.' ) { $line = substr($line,1); }
380
-            $MsgArray[$count] = $line;
381
-            $count++;
382
-            $line = fgets($fp,$buffer);
383
-            if(empty($line))    { break; }
384
-        }
385
-        return $MsgArray;
386
-    }
387
-
388
-    function last ( $type = "count" ) {
389
-        //  Returns the highest msg number in the mailbox.
390
-        //  returns -1 on error, 0+ on success, if type != count
391
-        //  results in a popstat() call (2 element array returned)
392
-
393
-        $last = -1;
394
-        if(!isset($this->FP))
395
-        {
396
-            $this->ERROR = "POP3 last: " . _("No connection to server");
397
-            return $last;
398
-        }
399
-
400
-        $reply = $this->send_cmd("STAT");
401
-        if(!$this->is_ok($reply))
402
-        {
403
-            $this->ERROR = "POP3 last: " . _("Error ") . "[$reply]";
404
-            return $last;
405
-        }
406
-
407
-        $Vars = preg_split('/\s+/',$reply);
408
-        $count = $Vars[1];
409
-        $size = $Vars[2];
410
-        settype($count,"integer");
411
-        settype($size,"integer");
412
-        if($type != "count")
413
-        {
414
-            return array($count,$size);
415
-        }
416
-        return $count;
417
-    }
418
-
419
-    function reset () {
420
-        //  Resets the status of the remote server. This includes
421
-        //  resetting the status of ALL msgs to not be deleted.
422
-        //  This method automatically closes the connection to the server.
423
-
424
-        if(!isset($this->FP))
425
-        {
426
-            $this->ERROR = "POP3 reset: " . _("No connection to server");
427
-            return false;
428
-        }
429
-        $reply = $this->send_cmd("RSET");
430
-        if(!$this->is_ok($reply))
431
-        {
432
-            //  The POP3 RSET command -never- gives a -ERR
433
-            //  response - if it ever does, something truely
434
-            //  wild is going on.
435
-
436
-            $this->ERROR = "POP3 reset: " . _("Error ") . "[$reply]";
437
-            @error_log("POP3 reset: ERROR [$reply]",0);
438
-        }
439
-        $this->quit();
440
-        return true;
441
-    }
442
-
443
-    function send_cmd ( $cmd = "" )
444
-    {
445
-        //  Sends a user defined command string to the
446
-        //  POP server and returns the results. Useful for
447
-        //  non-compliant or custom POP servers.
448
-        //  Do NOT includ the \r\n as part of your command
449
-        //  string - it will be appended automatically.
450
-
451
-        //  The return value is a standard fgets() call, which
452
-        //  will read up to $this->BUFFER bytes of data, until it
453
-        //  encounters a new line, or EOF, whichever happens first.
454
-
455
-        //  This method works best if $cmd responds with only
456
-        //  one line of data.
457
-
458
-        if(!isset($this->FP))
459
-        {
460
-            $this->ERROR = "POP3 send_cmd: " . _("No connection to server");
461
-            return false;
462
-        }
463
-
464
-        if(empty($cmd))
465
-        {
466
-            $this->ERROR = "POP3 send_cmd: " . _("Empty command string");
467
-            return "";
468
-        }
469
-
470
-        $fp = $this->FP;
471
-        $buffer = $this->BUFFER;
472
-        $this->update_timer();
473
-        fwrite($fp,"$cmd\r\n");
474
-        $reply = fgets($fp,$buffer);
475
-        $reply = $this->strip_clf($reply);
476
-        if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); }
477
-        return $reply;
478
-    }
479
-
480
-    function quit() {
481
-        //  Closes the connection to the POP3 server, deleting
482
-        //  any msgs marked as deleted.
483
-
484
-        if(!isset($this->FP))
485
-        {
486
-            $this->ERROR = "POP3 quit: " . _("connection does not exist");
487
-            return false;
488
-        }
489
-        $fp = $this->FP;
490
-        $cmd = "QUIT";
491
-        fwrite($fp,"$cmd\r\n");
492
-        $reply = fgets($fp,$this->BUFFER);
493
-        $reply = $this->strip_clf($reply);
494
-        if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); }
495
-        fclose($fp);
496
-        unset($this->FP);
497
-        return true;
498
-    }
499
-
500
-    function popstat () {
501
-        //  Returns an array of 2 elements. The number of undeleted
502
-        //  msgs in the mailbox, and the size of the mbox in octets.
503
-
504
-        $PopArray = $this->last("array");
505
-
506
-        if($PopArray == -1) { return false; }
507
-
508
-        if( (!$PopArray) or (empty($PopArray)) )
509
-        {
510
-            return false;
511
-        }
512
-        return $PopArray;
513
-    }
514
-
515
-    function uidl ($msgNum = "")
516
-    {
517
-        //  Returns the UIDL of the msg specified. If called with
518
-        //  no arguments, returns an associative array where each
519
-        //  undeleted msg num is a key, and the msg's uidl is the element
520
-        //  Array element 0 will contain the total number of msgs
521
-
522
-        if(!isset($this->FP)) {
523
-            $this->ERROR = "POP3 uidl: " . _("No connection to server");
524
-            return false;
525
-        }
526
-
527
-        $fp = $this->FP;
528
-        $buffer = $this->BUFFER;
529
-
530
-        if(!empty($msgNum)) {
531
-            $cmd = "UIDL $msgNum";
532
-            $reply = $this->send_cmd($cmd);
533
-            if(!$this->is_ok($reply))
534
-            {
535
-                $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]";
536
-                return false;
537
-            }
538
-            list ($ok,$num,$myUidl) = preg_split('/\s+/',$reply);
539
-            return $myUidl;
540
-        } else {
541
-            $this->update_timer();
542
-
543
-            $UIDLArray = array();
544
-            $Total = $this->COUNT;
545
-            $UIDLArray[0] = $Total;
546
-
547
-            if ($Total < 1)
548
-            {
549
-                return $UIDLArray;
550
-            }
551
-            $cmd = "UIDL";
552
-            fwrite($fp, "UIDL\r\n");
553
-            $reply = fgets($fp, $buffer);
554
-            $reply = $this->strip_clf($reply);
555
-            if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); }
556
-            if(!$this->is_ok($reply))
557
-            {
558
-                $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]";
559
-                return false;
560
-            }
561
-
562
-            $line = "";
563
-            $count = 1;
564
-            $line = fgets($fp,$buffer);
565
-            while ( !preg_match('/^\.\r\n/',$line)) {
566
-                list ($msg,$msgUidl) = preg_split('/\s+/',$line);
567
-                $msgUidl = $this->strip_clf($msgUidl);
568
-                if($count == $msg) {
569
-                    $UIDLArray[$msg] = $msgUidl;
570
-                }
571
-                else
572
-                {
573
-                    $UIDLArray[$count] = 'deleted';
574
-                }
575
-                $count++;
576
-                $line = fgets($fp,$buffer);
577
-            }
578
-        }
579
-        return $UIDLArray;
580
-    }
581
-
582
-    function delete ($msgNum = "") {
583
-        //  Flags a specified msg as deleted. The msg will not
584
-        //  be deleted until a quit() method is called.
585
-
586
-        if(!isset($this->FP))
587
-        {
588
-            $this->ERROR = "POP3 delete: " . _("No connection to server");
589
-            return false;
590
-        }
591
-        if(empty($msgNum))
592
-        {
593
-            $this->ERROR = "POP3 delete: " . _("No msg number submitted");
594
-            return false;
595
-        }
596
-        $reply = $this->send_cmd("DELE $msgNum");
597
-        if(!$this->is_ok($reply))
598
-        {
599
-            $this->ERROR = "POP3 delete: " . _("Command failed ") . "[$reply]";
600
-            return false;
601
-        }
602
-        return true;
603
-    }
604
-
605
-    //  *********************************************************
606
-
607
-    //  The following methods are internal to the class.
608
-
609
-    function is_ok ($cmd = "") {
610
-        //  Return true or false on +OK or -ERR
611
-
612
-        if( empty($cmd) )
613
-            return false;
614
-        else
615
-            return( stripos($cmd, '+OK') !== false );
616
-    }
617
-
618
-    function strip_clf ($text = "") {
619
-        // Strips \r\n from server responses
620
-
621
-        if(empty($text))
622
-            return $text;
623
-        else {
624
-            $stripped = str_replace(array("\r","\n"),'',$text);
625
-            return $stripped;
626
-        }
627
-    }
628
-
629
-    function parse_banner ( $server_text ) {
630
-        $outside = true;
631
-        $banner = "";
632
-        $length = strlen($server_text);
633
-        for($count =0; $count < $length; $count++)
634
-        {
635
-            $digit = substr($server_text,$count,1);
636
-            if(!empty($digit))             {
637
-                if( (!$outside) && ($digit != '<') && ($digit != '>') )
638
-                {
639
-                    $banner .= $digit;
640
-                }
641
-                if ($digit == '<')
642
-                {
643
-                    $outside = false;
644
-                }
645
-                if($digit == '>')
646
-                {
647
-                    $outside = true;
648
-                }
649
-            }
650
-        }
651
-        $banner = $this->strip_clf($banner);    // Just in case
652
-        return "<$banner>";
653
-    }
75
+	function update_timer () {
76
+		if (!ini_get('safe_mode'))
77
+			set_time_limit($this->TIMEOUT);
78
+		return true;
79
+	}
80
+
81
+	function connect ($server, $port = 110)  {
82
+		//  Opens a socket to the specified server. Unless overridden,
83
+		//  port defaults to 110. Returns true on success, false on fail
84
+
85
+		// If MAILSERVER is set, override $server with its value.
86
+
87
+	if (!isset($port) || !$port) {$port = 110;}
88
+		if(!empty($this->MAILSERVER))
89
+			$server = $this->MAILSERVER;
90
+
91
+		if(empty($server)){
92
+			$this->ERROR = "POP3 connect: " . _("No server specified");
93
+			unset($this->FP);
94
+			return false;
95
+		}
96
+
97
+		$fp = @fsockopen("$server", $port, $errno, $errstr);
98
+
99
+		if(!$fp) {
100
+			$this->ERROR = "POP3 connect: " . _("Error ") . "[$errno] [$errstr]";
101
+			unset($this->FP);
102
+			return false;
103
+		}
104
+
105
+		socket_set_blocking($fp,-1);
106
+		$this->update_timer();
107
+		$reply = fgets($fp,$this->BUFFER);
108
+		$reply = $this->strip_clf($reply);
109
+		if($this->DEBUG)
110
+			error_log("POP3 SEND [connect: $server] GOT [$reply]",0);
111
+		if(!$this->is_ok($reply)) {
112
+			$this->ERROR = "POP3 connect: " . _("Error ") . "[$reply]";
113
+			unset($this->FP);
114
+			return false;
115
+		}
116
+		$this->FP = $fp;
117
+		$this->BANNER = $this->parse_banner($reply);
118
+		return true;
119
+	}
120
+
121
+	function user ($user = "") {
122
+		// Sends the USER command, returns true or false
123
+
124
+		if( empty($user) ) {
125
+			$this->ERROR = "POP3 user: " . _("no login ID submitted");
126
+			return false;
127
+		} elseif(!isset($this->FP)) {
128
+			$this->ERROR = "POP3 user: " . _("connection not established");
129
+			return false;
130
+		} else {
131
+			$reply = $this->send_cmd("USER $user");
132
+			if(!$this->is_ok($reply)) {
133
+				$this->ERROR = "POP3 user: " . _("Error ") . "[$reply]";
134
+				return false;
135
+			} else
136
+				return true;
137
+		}
138
+	}
139
+
140
+	function pass ($pass = "")     {
141
+		// Sends the PASS command, returns # of msgs in mailbox,
142
+		// returns false (undef) on Auth failure
143
+
144
+		if(empty($pass)) {
145
+			$this->ERROR = "POP3 pass: " . _("No password submitted");
146
+			return false;
147
+		} elseif(!isset($this->FP)) {
148
+			$this->ERROR = "POP3 pass: " . _("connection not established");
149
+			return false;
150
+		} else {
151
+			$reply = $this->send_cmd("PASS $pass");
152
+			if(!$this->is_ok($reply)) {
153
+				$this->ERROR = "POP3 pass: " . _("Authentication failed") . " [$reply]";
154
+				$this->quit();
155
+				return false;
156
+			} else {
157
+				//  Auth successful.
158
+				$count = $this->last("count");
159
+				$this->COUNT = $count;
160
+				return $count;
161
+			}
162
+		}
163
+	}
164
+
165
+	function apop ($login,$pass) {
166
+		//  Attempts an APOP login. If this fails, it'll
167
+		//  try a standard login. YOUR SERVER MUST SUPPORT
168
+		//  THE USE OF THE APOP COMMAND!
169
+		//  (apop is optional per rfc1939)
170
+
171
+		if(!isset($this->FP)) {
172
+			$this->ERROR = "POP3 apop: " . _("No connection to server");
173
+			return false;
174
+		} elseif(!$this->ALLOWAPOP) {
175
+			$retVal = $this->login($login,$pass);
176
+			return $retVal;
177
+		} elseif(empty($login)) {
178
+			$this->ERROR = "POP3 apop: " . _("No login ID submitted");
179
+			return false;
180
+		} elseif(empty($pass)) {
181
+			$this->ERROR = "POP3 apop: " . _("No password submitted");
182
+			return false;
183
+		} else {
184
+			$banner = $this->BANNER;
185
+			if( (!$banner) or (empty($banner)) ) {
186
+				$this->ERROR = "POP3 apop: " . _("No server banner") . ' - ' . _("abort");
187
+				$retVal = $this->login($login,$pass);
188
+				return $retVal;
189
+			} else {
190
+				$AuthString = $banner;
191
+				$AuthString .= $pass;
192
+				$APOPString = md5($AuthString);
193
+				$cmd = "APOP $login $APOPString";
194
+				$reply = $this->send_cmd($cmd);
195
+				if(!$this->is_ok($reply)) {
196
+					$this->ERROR = "POP3 apop: " . _("apop authentication failed") . ' - ' . _("abort");
197
+					$retVal = $this->login($login,$pass);
198
+					return $retVal;
199
+				} else {
200
+					//  Auth successful.
201
+					$count = $this->last("count");
202
+					$this->COUNT = $count;
203
+					return $count;
204
+				}
205
+			}
206
+		}
207
+	}
208
+
209
+	function login ($login = "", $pass = "") {
210
+		// Sends both user and pass. Returns # of msgs in mailbox or
211
+		// false on failure (or -1, if the error occurs while getting
212
+		// the number of messages.)
213
+
214
+		if( !isset($this->FP) ) {
215
+			$this->ERROR = "POP3 login: " . _("No connection to server");
216
+			return false;
217
+		} else {
218
+			$fp = $this->FP;
219
+			if( !$this->user( $login ) ) {
220
+				//  Preserve the error generated by user()
221
+				return false;
222
+			} else {
223
+				$count = $this->pass($pass);
224
+				if( (!$count) || ($count == -1) ) {
225
+					//  Preserve the error generated by last() and pass()
226
+					return false;
227
+				} else
228
+					return $count;
229
+			}
230
+		}
231
+	}
232
+
233
+	function top ($msgNum, $numLines = "0") {
234
+		//  Gets the header and first $numLines of the msg body
235
+		//  returns data in an array with each returned line being
236
+		//  an array element. If $numLines is empty, returns
237
+		//  only the header information, and none of the body.
238
+
239
+		if(!isset($this->FP)) {
240
+			$this->ERROR = "POP3 top: " . _("No connection to server");
241
+			return false;
242
+		}
243
+		$this->update_timer();
244
+
245
+		$fp = $this->FP;
246
+		$buffer = $this->BUFFER;
247
+		$cmd = "TOP $msgNum $numLines";
248
+		fwrite($fp, "TOP $msgNum $numLines\r\n");
249
+		$reply = fgets($fp, $buffer);
250
+		$reply = $this->strip_clf($reply);
251
+		if($this->DEBUG) {
252
+			@error_log("POP3 SEND [$cmd] GOT [$reply]",0);
253
+		}
254
+		if(!$this->is_ok($reply))
255
+		{
256
+			$this->ERROR = "POP3 top: " . _("Error ") . "[$reply]";
257
+			return false;
258
+		}
259
+
260
+		$count = 0;
261
+		$MsgArray = array();
262
+
263
+		$line = fgets($fp,$buffer);
264
+		while ( !preg_match('/^\.\r\n/',$line))
265
+		{
266
+			$MsgArray[$count] = $line;
267
+			$count++;
268
+			$line = fgets($fp,$buffer);
269
+			if(empty($line))    { break; }
270
+		}
271
+
272
+		return $MsgArray;
273
+	}
274
+
275
+	function pop_list ($msgNum = "") {
276
+		//  If called with an argument, returns that msgs' size in octets
277
+		//  No argument returns an associative array of undeleted
278
+		//  msg numbers and their sizes in octets
279
+
280
+		if(!isset($this->FP))
281
+		{
282
+			$this->ERROR = "POP3 pop_list: " . _("No connection to server");
283
+			return false;
284
+		}
285
+		$fp = $this->FP;
286
+		$Total = $this->COUNT;
287
+		if( (!$Total) or ($Total == -1) )
288
+		{
289
+			return false;
290
+		}
291
+		if($Total == 0)
292
+		{
293
+			return array("0","0");
294
+			// return -1;   // mailbox empty
295
+		}
296
+
297
+		$this->update_timer();
298
+
299
+		if(!empty($msgNum))
300
+		{
301
+			$cmd = "LIST $msgNum";
302
+			fwrite($fp,"$cmd\r\n");
303
+			$reply = fgets($fp,$this->BUFFER);
304
+			$reply = $this->strip_clf($reply);
305
+			if($this->DEBUG) {
306
+				@error_log("POP3 SEND [$cmd] GOT [$reply]",0);
307
+			}
308
+			if(!$this->is_ok($reply))
309
+			{
310
+				$this->ERROR = "POP3 pop_list: " . _("Error ") . "[$reply]";
311
+				return false;
312
+			}
313
+			list($junk,$num,$size) = preg_split('/\s+/',$reply);
314
+			return $size;
315
+		}
316
+		$cmd = "LIST";
317
+		$reply = $this->send_cmd($cmd);
318
+		if(!$this->is_ok($reply))
319
+		{
320
+			$reply = $this->strip_clf($reply);
321
+			$this->ERROR = "POP3 pop_list: " . _("Error ") .  "[$reply]";
322
+			return false;
323
+		}
324
+		$MsgArray = array();
325
+		$MsgArray[0] = $Total;
326
+		for($msgC=1;$msgC <= $Total; $msgC++)
327
+		{
328
+			if($msgC > $Total) { break; }
329
+			$line = fgets($fp,$this->BUFFER);
330
+			$line = $this->strip_clf($line);
331
+			if(strpos($line, '.') === 0)
332
+			{
333
+				$this->ERROR = "POP3 pop_list: " . _("Premature end of list");
334
+				return false;
335
+			}
336
+			list($thisMsg,$msgSize) = preg_split('/\s+/',$line);
337
+			settype($thisMsg,"integer");
338
+			if($thisMsg != $msgC)
339
+			{
340
+				$MsgArray[$msgC] = "deleted";
341
+			}
342
+			else
343
+			{
344
+				$MsgArray[$msgC] = $msgSize;
345
+			}
346
+		}
347
+		return $MsgArray;
348
+	}
349
+
350
+	function get ($msgNum) {
351
+		//  Retrieve the specified msg number. Returns an array
352
+		//  where each line of the msg is an array element.
353
+
354
+		if(!isset($this->FP))
355
+		{
356
+			$this->ERROR = "POP3 get: " . _("No connection to server");
357
+			return false;
358
+		}
359
+
360
+		$this->update_timer();
361
+
362
+		$fp = $this->FP;
363
+		$buffer = $this->BUFFER;
364
+		$cmd = "RETR $msgNum";
365
+		$reply = $this->send_cmd($cmd);
366
+
367
+		if(!$this->is_ok($reply))
368
+		{
369
+			$this->ERROR = "POP3 get: " . _("Error ") . "[$reply]";
370
+			return false;
371
+		}
372
+
373
+		$count = 0;
374
+		$MsgArray = array();
375
+
376
+		$line = fgets($fp,$buffer);
377
+		while ( !preg_match('/^\.\r\n/',$line))
378
+		{
379
+			if ( $line{0} == '.' ) { $line = substr($line,1); }
380
+			$MsgArray[$count] = $line;
381
+			$count++;
382
+			$line = fgets($fp,$buffer);
383
+			if(empty($line))    { break; }
384
+		}
385
+		return $MsgArray;
386
+	}
387
+
388
+	function last ( $type = "count" ) {
389
+		//  Returns the highest msg number in the mailbox.
390
+		//  returns -1 on error, 0+ on success, if type != count
391
+		//  results in a popstat() call (2 element array returned)
392
+
393
+		$last = -1;
394
+		if(!isset($this->FP))
395
+		{
396
+			$this->ERROR = "POP3 last: " . _("No connection to server");
397
+			return $last;
398
+		}
399
+
400
+		$reply = $this->send_cmd("STAT");
401
+		if(!$this->is_ok($reply))
402
+		{
403
+			$this->ERROR = "POP3 last: " . _("Error ") . "[$reply]";
404
+			return $last;
405
+		}
406
+
407
+		$Vars = preg_split('/\s+/',$reply);
408
+		$count = $Vars[1];
409
+		$size = $Vars[2];
410
+		settype($count,"integer");
411
+		settype($size,"integer");
412
+		if($type != "count")
413
+		{
414
+			return array($count,$size);
415
+		}
416
+		return $count;
417
+	}
418
+
419
+	function reset () {
420
+		//  Resets the status of the remote server. This includes
421
+		//  resetting the status of ALL msgs to not be deleted.
422
+		//  This method automatically closes the connection to the server.
423
+
424
+		if(!isset($this->FP))
425
+		{
426
+			$this->ERROR = "POP3 reset: " . _("No connection to server");
427
+			return false;
428
+		}
429
+		$reply = $this->send_cmd("RSET");
430
+		if(!$this->is_ok($reply))
431
+		{
432
+			//  The POP3 RSET command -never- gives a -ERR
433
+			//  response - if it ever does, something truely
434
+			//  wild is going on.
435
+
436
+			$this->ERROR = "POP3 reset: " . _("Error ") . "[$reply]";
437
+			@error_log("POP3 reset: ERROR [$reply]",0);
438
+		}
439
+		$this->quit();
440
+		return true;
441
+	}
442
+
443
+	function send_cmd ( $cmd = "" )
444
+	{
445
+		//  Sends a user defined command string to the
446
+		//  POP server and returns the results. Useful for
447
+		//  non-compliant or custom POP servers.
448
+		//  Do NOT includ the \r\n as part of your command
449
+		//  string - it will be appended automatically.
450
+
451
+		//  The return value is a standard fgets() call, which
452
+		//  will read up to $this->BUFFER bytes of data, until it
453
+		//  encounters a new line, or EOF, whichever happens first.
454
+
455
+		//  This method works best if $cmd responds with only
456
+		//  one line of data.
457
+
458
+		if(!isset($this->FP))
459
+		{
460
+			$this->ERROR = "POP3 send_cmd: " . _("No connection to server");
461
+			return false;
462
+		}
463
+
464
+		if(empty($cmd))
465
+		{
466
+			$this->ERROR = "POP3 send_cmd: " . _("Empty command string");
467
+			return "";
468
+		}
469
+
470
+		$fp = $this->FP;
471
+		$buffer = $this->BUFFER;
472
+		$this->update_timer();
473
+		fwrite($fp,"$cmd\r\n");
474
+		$reply = fgets($fp,$buffer);
475
+		$reply = $this->strip_clf($reply);
476
+		if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); }
477
+		return $reply;
478
+	}
479
+
480
+	function quit() {
481
+		//  Closes the connection to the POP3 server, deleting
482
+		//  any msgs marked as deleted.
483
+
484
+		if(!isset($this->FP))
485
+		{
486
+			$this->ERROR = "POP3 quit: " . _("connection does not exist");
487
+			return false;
488
+		}
489
+		$fp = $this->FP;
490
+		$cmd = "QUIT";
491
+		fwrite($fp,"$cmd\r\n");
492
+		$reply = fgets($fp,$this->BUFFER);
493
+		$reply = $this->strip_clf($reply);
494
+		if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); }
495
+		fclose($fp);
496
+		unset($this->FP);
497
+		return true;
498
+	}
499
+
500
+	function popstat () {
501
+		//  Returns an array of 2 elements. The number of undeleted
502
+		//  msgs in the mailbox, and the size of the mbox in octets.
503
+
504
+		$PopArray = $this->last("array");
505
+
506
+		if($PopArray == -1) { return false; }
507
+
508
+		if( (!$PopArray) or (empty($PopArray)) )
509
+		{
510
+			return false;
511
+		}
512
+		return $PopArray;
513
+	}
514
+
515
+	function uidl ($msgNum = "")
516
+	{
517
+		//  Returns the UIDL of the msg specified. If called with
518
+		//  no arguments, returns an associative array where each
519
+		//  undeleted msg num is a key, and the msg's uidl is the element
520
+		//  Array element 0 will contain the total number of msgs
521
+
522
+		if(!isset($this->FP)) {
523
+			$this->ERROR = "POP3 uidl: " . _("No connection to server");
524
+			return false;
525
+		}
526
+
527
+		$fp = $this->FP;
528
+		$buffer = $this->BUFFER;
529
+
530
+		if(!empty($msgNum)) {
531
+			$cmd = "UIDL $msgNum";
532
+			$reply = $this->send_cmd($cmd);
533
+			if(!$this->is_ok($reply))
534
+			{
535
+				$this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]";
536
+				return false;
537
+			}
538
+			list ($ok,$num,$myUidl) = preg_split('/\s+/',$reply);
539
+			return $myUidl;
540
+		} else {
541
+			$this->update_timer();
542
+
543
+			$UIDLArray = array();
544
+			$Total = $this->COUNT;
545
+			$UIDLArray[0] = $Total;
546
+
547
+			if ($Total < 1)
548
+			{
549
+				return $UIDLArray;
550
+			}
551
+			$cmd = "UIDL";
552
+			fwrite($fp, "UIDL\r\n");
553
+			$reply = fgets($fp, $buffer);
554
+			$reply = $this->strip_clf($reply);
555
+			if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); }
556
+			if(!$this->is_ok($reply))
557
+			{
558
+				$this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]";
559
+				return false;
560
+			}
561
+
562
+			$line = "";
563
+			$count = 1;
564
+			$line = fgets($fp,$buffer);
565
+			while ( !preg_match('/^\.\r\n/',$line)) {
566
+				list ($msg,$msgUidl) = preg_split('/\s+/',$line);
567
+				$msgUidl = $this->strip_clf($msgUidl);
568
+				if($count == $msg) {
569
+					$UIDLArray[$msg] = $msgUidl;
570
+				}
571
+				else
572
+				{
573
+					$UIDLArray[$count] = 'deleted';
574
+				}
575
+				$count++;
576
+				$line = fgets($fp,$buffer);
577
+			}
578
+		}
579
+		return $UIDLArray;
580
+	}
581
+
582
+	function delete ($msgNum = "") {
583
+		//  Flags a specified msg as deleted. The msg will not
584
+		//  be deleted until a quit() method is called.
585
+
586
+		if(!isset($this->FP))
587
+		{
588
+			$this->ERROR = "POP3 delete: " . _("No connection to server");
589
+			return false;
590
+		}
591
+		if(empty($msgNum))
592
+		{
593
+			$this->ERROR = "POP3 delete: " . _("No msg number submitted");
594
+			return false;
595
+		}
596
+		$reply = $this->send_cmd("DELE $msgNum");
597
+		if(!$this->is_ok($reply))
598
+		{
599
+			$this->ERROR = "POP3 delete: " . _("Command failed ") . "[$reply]";
600
+			return false;
601
+		}
602
+		return true;
603
+	}
604
+
605
+	//  *********************************************************
606
+
607
+	//  The following methods are internal to the class.
608
+
609
+	function is_ok ($cmd = "") {
610
+		//  Return true or false on +OK or -ERR
611
+
612
+		if( empty($cmd) )
613
+			return false;
614
+		else
615
+			return( stripos($cmd, '+OK') !== false );
616
+	}
617
+
618
+	function strip_clf ($text = "") {
619
+		// Strips \r\n from server responses
620
+
621
+		if(empty($text))
622
+			return $text;
623
+		else {
624
+			$stripped = str_replace(array("\r","\n"),'',$text);
625
+			return $stripped;
626
+		}
627
+	}
628
+
629
+	function parse_banner ( $server_text ) {
630
+		$outside = true;
631
+		$banner = "";
632
+		$length = strlen($server_text);
633
+		for($count =0; $count < $length; $count++)
634
+		{
635
+			$digit = substr($server_text,$count,1);
636
+			if(!empty($digit))             {
637
+				if( (!$outside) && ($digit != '<') && ($digit != '>') )
638
+				{
639
+					$banner .= $digit;
640
+				}
641
+				if ($digit == '<')
642
+				{
643
+					$outside = false;
644
+				}
645
+				if($digit == '>')
646
+				{
647
+					$outside = true;
648
+				}
649
+			}
650
+		}
651
+		$banner = $this->strip_clf($banner);    // Just in case
652
+		return "<$banner>";
653
+	}
654 654
 
655 655
 }   // End class
656 656
 
657 657
 // For php4 compatibility
658 658
 if (!function_exists("stripos")) {
659
-    function stripos($haystack, $needle){
660
-        return strpos($haystack, stristr( $haystack, $needle ));
661
-    }
659
+	function stripos($haystack, $needle){
660
+		return strpos($haystack, stristr( $haystack, $needle ));
661
+	}
662 662
 }
Please login to merge, or discard this patch.
src/wp-includes/class-simplepie.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1614,7 +1614,7 @@  discard block
 block discarded – undo
1614 1614
 	/**
1615 1615
 	 * Get the error message for the occurred error.
1616 1616
 	 *
1617
-	 * @return string|array Error message, or array of messages for multifeeds
1617
+	 * @return string Error message, or array of messages for multifeeds
1618 1618
 	 */
1619 1619
 	public function error()
1620 1620
 	{
@@ -1627,7 +1627,7 @@  discard block
 block discarded – undo
1627 1627
 	 * This is the same as the old `$feed->enable_xml_dump(true)`, but returns
1628 1628
 	 * the data instead of printing it.
1629 1629
 	 *
1630
-	 * @return string|boolean Raw XML data, false if the cache is used
1630
+	 * @return string Raw XML data, false if the cache is used
1631 1631
 	 */
1632 1632
 	public function get_raw_data()
1633 1633
 	{
@@ -2607,7 +2607,7 @@  discard block
 block discarded – undo
2607 2607
 	 * @since 1.0
2608 2608
 	 * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
2609 2609
 	 * @link http://www.georss.org/ GeoRSS
2610
-	 * @return string|null
2610
+	 * @return double|null
2611 2611
 	 */
2612 2612
 	public function get_latitude()
2613 2613
 	{
@@ -2636,7 +2636,7 @@  discard block
 block discarded – undo
2636 2636
 	 * @since 1.0
2637 2637
 	 * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
2638 2638
 	 * @link http://www.georss.org/ GeoRSS
2639
-	 * @return string|null
2639
+	 * @return double|null
2640 2640
 	 */
2641 2641
 	public function get_longitude()
2642 2642
 	{
@@ -2778,7 +2778,7 @@  discard block
 block discarded – undo
2778 2778
 	 * Uses `<image><width>` or defaults to 88.0 if no width is specified and
2779 2779
 	 * the feed is an RSS 2.0 feed.
2780 2780
 	 *
2781
-	 * @return int|float|null
2781
+	 * @return double|null
2782 2782
 	 */
2783 2783
 	public function get_image_width()
2784 2784
 	{
@@ -2804,7 +2804,7 @@  discard block
 block discarded – undo
2804 2804
 	 * Uses `<image><height>` or defaults to 31.0 if no height is specified and
2805 2805
 	 * the feed is an RSS 2.0 feed.
2806 2806
 	 *
2807
-	 * @return int|float|null
2807
+	 * @return double|null
2808 2808
 	 */
2809 2809
 	public function get_image_height()
2810 2810
 	{
Please login to merge, or discard this patch.
Braces   +92 added lines, -180 removed lines patch added patch discarded remove patch
@@ -22,8 +22,9 @@  discard block
 block discarded – undo
22 22
  * @since 3.5.0
23 23
  */
24 24
 function wp_simplepie_autoload( $class ) {
25
-	if ( 0 !== strpos( $class, 'SimplePie_' ) )
26
-		return;
25
+	if ( 0 !== strpos( $class, 'SimplePie_' ) ) {
26
+			return;
27
+	}
27 28
 
28 29
 	$file = ABSPATH . WPINC . '/' . str_replace( '_', '/', $class ) . '.php';
29 30
 	include( $file );
@@ -784,8 +785,7 @@  discard block
 block discarded – undo
784 785
 			{
785 786
 				$this->multifeed_url[] = $this->registry->call('Misc', 'fix_protocol', array($value, 1));
786 787
 			}
787
-		}
788
-		else
788
+		} else
789 789
 		{
790 790
 			$this->feed_url = $this->registry->call('Misc', 'fix_protocol', array($url, 1));
791 791
 		}
@@ -920,8 +920,7 @@  discard block
 block discarded – undo
920 920
 		if ($encoding)
921 921
 		{
922 922
 			$this->input_encoding = (string) $encoding;
923
-		}
924
-		else
923
+		} else
925 924
 		{
926 925
 			$this->input_encoding = false;
927 926
 		}
@@ -1238,8 +1237,7 @@  discard block
 block discarded – undo
1238 1237
 		if ($page !== false)
1239 1238
 		{
1240 1239
 			$this->sanitize->set_image_handler($page . '?' . $qs . '=');
1241
-		}
1242
-		else
1240
+		} else
1243 1241
 		{
1244 1242
 			$this->image_handler = '';
1245 1243
 		}
@@ -1317,8 +1315,7 @@  discard block
 block discarded – undo
1317 1315
 				$i++;
1318 1316
 			}
1319 1317
 			return (bool) $success;
1320
-		}
1321
-		elseif ($this->feed_url === null && $this->raw_data === null)
1318
+		} elseif ($this->feed_url === null && $this->raw_data === null)
1322 1319
 		{
1323 1320
 			return false;
1324 1321
 		}
@@ -1342,8 +1339,7 @@  discard block
 block discarded – undo
1342 1339
 			if (($fetched = $this->fetch_data($cache)) === true)
1343 1340
 			{
1344 1341
 				return true;
1345
-			}
1346
-			elseif ($fetched === false) {
1342
+			} elseif ($fetched === false) {
1347 1343
 				return false;
1348 1344
 			}
1349 1345
 
@@ -1373,8 +1369,7 @@  discard block
 block discarded – undo
1373 1369
 				}
1374 1370
 				$encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
1375 1371
 				$encodings[] = 'UTF-8';
1376
-			}
1377
-			elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml')
1372
+			} elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml')
1378 1373
 			{
1379 1374
 				if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
1380 1375
 				{
@@ -1437,8 +1432,7 @@  discard block
 block discarded – undo
1437 1432
 		{
1438 1433
 			// We have an error, just set SimplePie_Misc::error to it and quit
1439 1434
 			$this->error = sprintf('This XML document is invalid, likely due to invalid characters. XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column());
1440
-		}
1441
-		else
1435
+		} else
1442 1436
 		{
1443 1437
 			$this->error = 'The data could not be converted to UTF-8. You MUST have either the iconv or mbstring extension installed. Upgrading to PHP 5.x (which includes iconv) is highly recommended.';
1444 1438
 		}
@@ -1520,8 +1514,7 @@  discard block
 block discarded – undo
1520 1514
 								$cache->touch();
1521 1515
 								return true;
1522 1516
 							}
1523
-						}
1524
-						else
1517
+						} else
1525 1518
 						{
1526 1519
 							unset($file);
1527 1520
 						}
@@ -1547,8 +1540,7 @@  discard block
 block discarded – undo
1547 1540
 			if ($this->file instanceof SimplePie_File && $this->file->url === $this->feed_url)
1548 1541
 			{
1549 1542
 				$file =& $this->file;
1550
-			}
1551
-			else
1543
+			} else
1552 1544
 			{
1553 1545
 				$headers = array(
1554 1546
 					'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
@@ -1580,8 +1572,7 @@  discard block
 block discarded – undo
1580 1572
 						$this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
1581 1573
 						return false;
1582 1574
 					}
1583
-				}
1584
-				catch (SimplePie_Exception $e)
1575
+				} catch (SimplePie_Exception $e)
1585 1576
 				{
1586 1577
 					// This is usually because DOMDocument doesn't exist
1587 1578
 					$this->error = $e->getMessage();
@@ -1672,8 +1663,7 @@  discard block
 block discarded – undo
1672 1663
 			if ($this->get_encoding())
1673 1664
 			{
1674 1665
 				$header .= ' charset=' . $this->get_encoding();
1675
-			}
1676
-			else
1666
+			} else
1677 1667
 			{
1678 1668
 				$header .= ' charset=UTF-8';
1679 1669
 			}
@@ -1715,12 +1705,10 @@  discard block
 block discarded – undo
1715 1705
 			if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed']))
1716 1706
 			{
1717 1707
 				$this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10;
1718
-			}
1719
-			elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed']))
1708
+			} elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed']))
1720 1709
 			{
1721 1710
 				$this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03;
1722
-			}
1723
-			elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF']))
1711
+			} elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF']))
1724 1712
 			{
1725 1713
 				if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel'])
1726 1714
 				|| isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image'])
@@ -1736,8 +1724,7 @@  discard block
 block discarded – undo
1736 1724
 				{
1737 1725
 					$this->data['type'] &= SIMPLEPIE_TYPE_RSS_090;
1738 1726
 				}
1739
-			}
1740
-			elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss']))
1727
+			} elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss']))
1741 1728
 			{
1742 1729
 				$this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL;
1743 1730
 				if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
@@ -1778,8 +1765,7 @@  discard block
 block discarded – undo
1778 1765
 							break;
1779 1766
 					}
1780 1767
 				}
1781
-			}
1782
-			else
1768
+			} else
1783 1769
 			{
1784 1770
 				$this->data['type'] = SIMPLEPIE_TYPE_NONE;
1785 1771
 			}
@@ -1804,8 +1790,7 @@  discard block
 block discarded – undo
1804 1790
 		if ($this->feed_url !== null)
1805 1791
 		{
1806 1792
 			return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI);
1807
-		}
1808
-		else
1793
+		} else
1809 1794
 		{
1810 1795
 			return null;
1811 1796
 		}
@@ -2000,12 +1985,10 @@  discard block
 block discarded – undo
2000 1985
 		if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base']))
2001 1986
 		{
2002 1987
 			return $element['xml_base'];
2003
-		}
2004
-		elseif ($this->get_link() !== null)
1988
+		} elseif ($this->get_link() !== null)
2005 1989
 		{
2006 1990
 			return $this->get_link();
2007
-		}
2008
-		else
1991
+		} else
2009 1992
 		{
2010 1993
 			return $this->subscribe_url();
2011 1994
 		}
@@ -2039,32 +2022,25 @@  discard block
 block discarded – undo
2039 2022
 		if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
2040 2023
 		{
2041 2024
 			return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2042
-		}
2043
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
2025
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
2044 2026
 		{
2045 2027
 			return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2046
-		}
2047
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
2028
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
2048 2029
 		{
2049 2030
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2050
-		}
2051
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
2031
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
2052 2032
 		{
2053 2033
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2054
-		}
2055
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
2034
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
2056 2035
 		{
2057 2036
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2058
-		}
2059
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
2037
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
2060 2038
 		{
2061 2039
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2062
-		}
2063
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
2040
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
2064 2041
 		{
2065 2042
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2066
-		}
2067
-		else
2043
+		} else
2068 2044
 		{
2069 2045
 			return null;
2070 2046
 		}
@@ -2083,8 +2059,7 @@  discard block
 block discarded – undo
2083 2059
 		if (isset($categories[$key]))
2084 2060
 		{
2085 2061
 			return $categories[$key];
2086
-		}
2087
-		else
2062
+		} else
2088 2063
 		{
2089 2064
 			return null;
2090 2065
 		}
@@ -2129,8 +2104,7 @@  discard block
 block discarded – undo
2129 2104
 			if (isset($category['attribs']['']['domain']))
2130 2105
 			{
2131 2106
 				$scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
2132
-			}
2133
-			else
2107
+			} else
2134 2108
 			{
2135 2109
 				$scheme = null;
2136 2110
 			}
@@ -2148,8 +2122,7 @@  discard block
 block discarded – undo
2148 2122
 		if (!empty($categories))
2149 2123
 		{
2150 2124
 			return array_unique($categories);
2151
-		}
2152
-		else
2125
+		} else
2153 2126
 		{
2154 2127
 			return null;
2155 2128
 		}
@@ -2168,8 +2141,7 @@  discard block
 block discarded – undo
2168 2141
 		if (isset($authors[$key]))
2169 2142
 		{
2170 2143
 			return $authors[$key];
2171
-		}
2172
-		else
2144
+		} else
2173 2145
 		{
2174 2146
 			return null;
2175 2147
 		}
@@ -2246,8 +2218,7 @@  discard block
 block discarded – undo
2246 2218
 		if (!empty($authors))
2247 2219
 		{
2248 2220
 			return array_unique($authors);
2249
-		}
2250
-		else
2221
+		} else
2251 2222
 		{
2252 2223
 			return null;
2253 2224
 		}
@@ -2266,8 +2237,7 @@  discard block
 block discarded – undo
2266 2237
 		if (isset($contributors[$key]))
2267 2238
 		{
2268 2239
 			return $contributors[$key];
2269
-		}
2270
-		else
2240
+		} else
2271 2241
 		{
2272 2242
 			return null;
2273 2243
 		}
@@ -2332,8 +2302,7 @@  discard block
 block discarded – undo
2332 2302
 		if (!empty($contributors))
2333 2303
 		{
2334 2304
 			return array_unique($contributors);
2335
-		}
2336
-		else
2305
+		} else
2337 2306
 		{
2338 2307
 			return null;
2339 2308
 		}
@@ -2353,8 +2322,7 @@  discard block
 block discarded – undo
2353 2322
 		if (isset($links[$key]))
2354 2323
 		{
2355 2324
 			return $links[$key];
2356
-		}
2357
-		else
2325
+		} else
2358 2326
 		{
2359 2327
 			return null;
2360 2328
 		}
@@ -2435,13 +2403,11 @@  discard block
 block discarded – undo
2435 2403
 					{
2436 2404
 						$this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
2437 2405
 						$this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
2438
-					}
2439
-					else
2406
+					} else
2440 2407
 					{
2441 2408
 						$this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
2442 2409
 					}
2443
-				}
2444
-				elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
2410
+				} elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
2445 2411
 				{
2446 2412
 					$this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
2447 2413
 				}
@@ -2452,8 +2418,7 @@  discard block
 block discarded – undo
2452 2418
 		if (isset($this->data['links'][$rel]))
2453 2419
 		{
2454 2420
 			return $this->data['links'][$rel];
2455
-		}
2456
-		else
2421
+		} else
2457 2422
 		{
2458 2423
 			return null;
2459 2424
 		}
@@ -2478,40 +2443,31 @@  discard block
 block discarded – undo
2478 2443
 		if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
2479 2444
 		{
2480 2445
 			return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2481
-		}
2482
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
2446
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
2483 2447
 		{
2484 2448
 			return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2485
-		}
2486
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
2449
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
2487 2450
 		{
2488 2451
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2489
-		}
2490
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
2452
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
2491 2453
 		{
2492 2454
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2493
-		}
2494
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
2455
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
2495 2456
 		{
2496 2457
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
2497
-		}
2498
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
2458
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
2499 2459
 		{
2500 2460
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2501
-		}
2502
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
2461
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
2503 2462
 		{
2504 2463
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2505
-		}
2506
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
2464
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
2507 2465
 		{
2508 2466
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
2509
-		}
2510
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
2467
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
2511 2468
 		{
2512 2469
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
2513
-		}
2514
-		else
2470
+		} else
2515 2471
 		{
2516 2472
 			return null;
2517 2473
 		}
@@ -2530,24 +2486,19 @@  discard block
 block discarded – undo
2530 2486
 		if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
2531 2487
 		{
2532 2488
 			return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2533
-		}
2534
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
2489
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
2535 2490
 		{
2536 2491
 			return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2537
-		}
2538
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright'))
2492
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright'))
2539 2493
 		{
2540 2494
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2541
-		}
2542
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
2495
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
2543 2496
 		{
2544 2497
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2545
-		}
2546
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
2498
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
2547 2499
 		{
2548 2500
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2549
-		}
2550
-		else
2501
+		} else
2551 2502
 		{
2552 2503
 			return null;
2553 2504
 		}
@@ -2566,32 +2517,25 @@  discard block
 block discarded – undo
2566 2517
 		if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language'))
2567 2518
 		{
2568 2519
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2569
-		}
2570
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
2520
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
2571 2521
 		{
2572 2522
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2573
-		}
2574
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
2523
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
2575 2524
 		{
2576 2525
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2577
-		}
2578
-		elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang']))
2526
+		} elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang']))
2579 2527
 		{
2580 2528
 			return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
2581
-		}
2582
-		elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang']))
2529
+		} elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang']))
2583 2530
 		{
2584 2531
 			return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
2585
-		}
2586
-		elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang']))
2532
+		} elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang']))
2587 2533
 		{
2588 2534
 			return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
2589
-		}
2590
-		elseif (isset($this->data['headers']['content-language']))
2535
+		} elseif (isset($this->data['headers']['content-language']))
2591 2536
 		{
2592 2537
 			return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT);
2593
-		}
2594
-		else
2538
+		} else
2595 2539
 		{
2596 2540
 			return null;
2597 2541
 		}
@@ -2615,12 +2559,10 @@  discard block
 block discarded – undo
2615 2559
 		if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
2616 2560
 		{
2617 2561
 			return (float) $return[0]['data'];
2618
-		}
2619
-		elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
2562
+		} elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
2620 2563
 		{
2621 2564
 			return (float) $match[1];
2622
-		}
2623
-		else
2565
+		} else
2624 2566
 		{
2625 2567
 			return null;
2626 2568
 		}
@@ -2643,16 +2585,13 @@  discard block
 block discarded – undo
2643 2585
 		if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
2644 2586
 		{
2645 2587
 			return (float) $return[0]['data'];
2646
-		}
2647
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
2588
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
2648 2589
 		{
2649 2590
 			return (float) $return[0]['data'];
2650
-		}
2651
-		elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
2591
+		} elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
2652 2592
 		{
2653 2593
 			return (float) $match[2];
2654
-		}
2655
-		else
2594
+		} else
2656 2595
 		{
2657 2596
 			return null;
2658 2597
 		}
@@ -2672,24 +2611,19 @@  discard block
 block discarded – undo
2672 2611
 		if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
2673 2612
 		{
2674 2613
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2675
-		}
2676
-		elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
2614
+		} elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
2677 2615
 		{
2678 2616
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2679
-		}
2680
-		elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
2617
+		} elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
2681 2618
 		{
2682 2619
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2683
-		}
2684
-		elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
2620
+		} elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
2685 2621
 		{
2686 2622
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2687
-		}
2688
-		elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
2623
+		} elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
2689 2624
 		{
2690 2625
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2691
-		}
2692
-		else
2626
+		} else
2693 2627
 		{
2694 2628
 			return null;
2695 2629
 		}
@@ -2711,28 +2645,22 @@  discard block
 block discarded – undo
2711 2645
 		if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
2712 2646
 		{
2713 2647
 			return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
2714
-		}
2715
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
2648
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
2716 2649
 		{
2717 2650
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2718
-		}
2719
-		elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
2651
+		} elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
2720 2652
 		{
2721 2653
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2722
-		}
2723
-		elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url'))
2654
+		} elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url'))
2724 2655
 		{
2725 2656
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2726
-		}
2727
-		elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url'))
2657
+		} elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url'))
2728 2658
 		{
2729 2659
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2730
-		}
2731
-		elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
2660
+		} elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
2732 2661
 		{
2733 2662
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2734
-		}
2735
-		else
2663
+		} else
2736 2664
 		{
2737 2665
 			return null;
2738 2666
 		}
@@ -2755,16 +2683,13 @@  discard block
 block discarded – undo
2755 2683
 		if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
2756 2684
 		{
2757 2685
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2758
-		}
2759
-		elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
2686
+		} elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
2760 2687
 		{
2761 2688
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2762
-		}
2763
-		elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
2689
+		} elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
2764 2690
 		{
2765 2691
 			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2766
-		}
2767
-		else
2692
+		} else
2768 2693
 		{
2769 2694
 			return null;
2770 2695
 		}
@@ -2785,12 +2710,10 @@  discard block
 block discarded – undo
2785 2710
 		if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'width'))
2786 2711
 		{
2787 2712
 			return round($return[0]['data']);
2788
-		}
2789
-		elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
2713
+		} elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
2790 2714
 		{
2791 2715
 			return 88.0;
2792
-		}
2793
-		else
2716
+		} else
2794 2717
 		{
2795 2718
 			return null;
2796 2719
 		}
@@ -2811,12 +2734,10 @@  discard block
 block discarded – undo
2811 2734
 		if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'height'))
2812 2735
 		{
2813 2736
 			return round($return[0]['data']);
2814
-		}
2815
-		elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
2737
+		} elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
2816 2738
 		{
2817 2739
 			return 31.0;
2818
-		}
2819
-		else
2740
+		} else
2820 2741
 		{
2821 2742
 			return null;
2822 2743
 		}
@@ -2838,8 +2759,7 @@  discard block
 block discarded – undo
2838 2759
 		if ($max === 0)
2839 2760
 		{
2840 2761
 			return $qty;
2841
-		}
2842
-		else
2762
+		} else
2843 2763
 		{
2844 2764
 			return ($qty > $max) ? $max : $qty;
2845 2765
 		}
@@ -2863,8 +2783,7 @@  discard block
 block discarded – undo
2863 2783
 		if (isset($items[$key]))
2864 2784
 		{
2865 2785
 			return $items[$key];
2866
-		}
2867
-		else
2786
+		} else
2868 2787
 		{
2869 2788
 			return null;
2870 2789
 		}
@@ -2890,8 +2809,7 @@  discard block
 block discarded – undo
2890 2809
 			if (!empty($this->multifeed_objects))
2891 2810
 			{
2892 2811
 				$this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit);
2893
-			}
2894
-			else
2812
+			} else
2895 2813
 			{
2896 2814
 				$this->data['items'] = array();
2897 2815
 				if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry'))
@@ -2961,8 +2879,7 @@  discard block
 block discarded – undo
2961 2879
 					}
2962 2880
 				}
2963 2881
 				$items = $this->data['ordered_items'];
2964
-			}
2965
-			else
2882
+			} else
2966 2883
 			{
2967 2884
 				$items = $this->data['items'];
2968 2885
 			}
@@ -2971,13 +2888,11 @@  discard block
 block discarded – undo
2971 2888
 			if ($end === 0)
2972 2889
 			{
2973 2890
 				return array_slice($items, $start);
2974
-			}
2975
-			else
2891
+			} else
2976 2892
 			{
2977 2893
 				return array_slice($items, $start, $end);
2978 2894
 			}
2979
-		}
2980
-		else
2895
+		} else
2981 2896
 		{
2982 2897
 			return array();
2983 2898
 		}
@@ -3078,8 +2993,7 @@  discard block
 block discarded – undo
3078 2993
 				if ($arg instanceof SimplePie)
3079 2994
 				{
3080 2995
 					$items = array_merge($items, $arg->get_items(0, $limit));
3081
-				}
3082
-				else
2996
+				} else
3083 2997
 				{
3084 2998
 					trigger_error('Arguments must be SimplePie objects', E_USER_WARNING);
3085 2999
 				}
@@ -3103,13 +3017,11 @@  discard block
 block discarded – undo
3103 3017
 			if ($end === 0)
3104 3018
 			{
3105 3019
 				return array_slice($items, $start);
3106
-			}
3107
-			else
3020
+			} else
3108 3021
 			{
3109 3022
 				return array_slice($items, $start, $end);
3110 3023
 			}
3111
-		}
3112
-		else
3024
+		} else
3113 3025
 		{
3114 3026
 			trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING);
3115 3027
 			return array();
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -1,38 +1,38 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! class_exists( 'SimplePie', false ) ) :
2
+if ( ! class_exists('SimplePie', false)) :
3 3
 
4 4
 // Load classes we will need.
5
-require ABSPATH . WPINC . '/SimplePie/Misc.php';
6
-require ABSPATH . WPINC . '/SimplePie/Cache.php';
7
-require ABSPATH . WPINC . '/SimplePie/File.php';
8
-require ABSPATH . WPINC . '/SimplePie/Sanitize.php';
9
-require ABSPATH . WPINC . '/SimplePie/Registry.php';
10
-require ABSPATH . WPINC . '/SimplePie/IRI.php';
11
-require ABSPATH . WPINC . '/SimplePie/Locator.php';
12
-require ABSPATH . WPINC . '/SimplePie/Content/Type/Sniffer.php';
13
-require ABSPATH . WPINC . '/SimplePie/XML/Declaration/Parser.php';
14
-require ABSPATH . WPINC . '/SimplePie/Parser.php';
15
-require ABSPATH . WPINC . '/SimplePie/Item.php';
16
-require ABSPATH . WPINC . '/SimplePie/Parse/Date.php';
17
-require ABSPATH . WPINC . '/SimplePie/Author.php';
5
+require ABSPATH.WPINC.'/SimplePie/Misc.php';
6
+require ABSPATH.WPINC.'/SimplePie/Cache.php';
7
+require ABSPATH.WPINC.'/SimplePie/File.php';
8
+require ABSPATH.WPINC.'/SimplePie/Sanitize.php';
9
+require ABSPATH.WPINC.'/SimplePie/Registry.php';
10
+require ABSPATH.WPINC.'/SimplePie/IRI.php';
11
+require ABSPATH.WPINC.'/SimplePie/Locator.php';
12
+require ABSPATH.WPINC.'/SimplePie/Content/Type/Sniffer.php';
13
+require ABSPATH.WPINC.'/SimplePie/XML/Declaration/Parser.php';
14
+require ABSPATH.WPINC.'/SimplePie/Parser.php';
15
+require ABSPATH.WPINC.'/SimplePie/Item.php';
16
+require ABSPATH.WPINC.'/SimplePie/Parse/Date.php';
17
+require ABSPATH.WPINC.'/SimplePie/Author.php';
18 18
 
19 19
 /**
20 20
  * WordPress autoloader for SimplePie.
21 21
  *
22 22
  * @since 3.5.0
23 23
  */
24
-function wp_simplepie_autoload( $class ) {
25
-	if ( 0 !== strpos( $class, 'SimplePie_' ) )
24
+function wp_simplepie_autoload($class) {
25
+	if (0 !== strpos($class, 'SimplePie_'))
26 26
 		return;
27 27
 
28
-	$file = ABSPATH . WPINC . '/' . str_replace( '_', '/', $class ) . '.php';
29
-	include( $file );
28
+	$file = ABSPATH.WPINC.'/'.str_replace('_', '/', $class).'.php';
29
+	include($file);
30 30
 }
31 31
 
32 32
 /**
33 33
  * We autoload classes we may not need.
34 34
  */
35
-spl_autoload_register( 'wp_simplepie_autoload' );
35
+spl_autoload_register('wp_simplepie_autoload');
36 36
 
37 37
 /**
38 38
  * SimplePie
@@ -102,12 +102,12 @@  discard block
 block discarded – undo
102 102
  * SimplePie Useragent
103 103
  * @see SimplePie::set_useragent()
104 104
  */
105
-define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD);
105
+define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME.'/'.SIMPLEPIE_VERSION.' (Feed Parser; '.SIMPLEPIE_URL.'; Allow like Gecko) Build/'.SIMPLEPIE_BUILD);
106 106
 
107 107
 /**
108 108
  * SimplePie Linkback
109 109
  */
110
-define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>');
110
+define('SIMPLEPIE_LINKBACK', '<a href="'.SIMPLEPIE_URL.'" title="'.SIMPLEPIE_NAME.' '.SIMPLEPIE_VERSION.'">'.SIMPLEPIE_NAME.'</a>');
111 111
 
112 112
 /**
113 113
  * No Autodiscovery
@@ -700,9 +700,9 @@  discard block
 block discarded – undo
700 700
 	 */
701 701
 	public function __destruct()
702 702
 	{
703
-		if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
703
+		if ((version_compare(PHP_VERSION, '5.3', '<') || ! gc_enabled()) && ! ini_get('zend.ze1_compatibility_mode'))
704 704
 		{
705
-			if (!empty($this->data['items']))
705
+			if ( ! empty($this->data['items']))
706 706
 			{
707 707
 				foreach ($this->data['items'] as $item)
708 708
 				{
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
 				}
711 711
 				unset($item, $this->data['items']);
712 712
 			}
713
-			if (!empty($this->data['ordered_items']))
713
+			if ( ! empty($this->data['ordered_items']))
714 714
 			{
715 715
 				foreach ($this->data['ordered_items'] as $item)
716 716
 				{
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
 		if ($file instanceof SimplePie_File)
778 778
 		{
779 779
 			$this->feed_url = $file->url;
780
-			$this->file =& $file;
780
+			$this->file = & $file;
781 781
 			return true;
782 782
 		}
783 783
 		return false;
@@ -1212,7 +1212,7 @@  discard block
 block discarded – undo
1212 1212
 	{
1213 1213
 		if ($page !== false)
1214 1214
 		{
1215
-			$this->sanitize->set_image_handler($page . '?' . $qs . '=');
1215
+			$this->sanitize->set_image_handler($page.'?'.$qs.'=');
1216 1216
 		}
1217 1217
 		else
1218 1218
 		{
@@ -1242,12 +1242,12 @@  discard block
 block discarded – undo
1242 1242
 	public function init()
1243 1243
 	{
1244 1244
 		// Check absolute bare minimum requirements.
1245
-		if (!extension_loaded('xml') || !extension_loaded('pcre'))
1245
+		if ( ! extension_loaded('xml') || ! extension_loaded('pcre'))
1246 1246
 		{
1247 1247
 			return false;
1248 1248
 		}
1249 1249
 		// Then check the xml extension is sane (i.e., libxml 2.7.x issue on PHP < 5.2.9 and libxml 2.7.0 to 2.7.2 on any version) if we don't have xmlreader.
1250
-		elseif (!extension_loaded('xmlreader'))
1250
+		elseif ( ! extension_loaded('xmlreader'))
1251 1251
 		{
1252 1252
 			static $xml_is_sane = null;
1253 1253
 			if ($xml_is_sane === null)
@@ -1257,7 +1257,7 @@  discard block
 block discarded – undo
1257 1257
 				xml_parser_free($parser_check);
1258 1258
 				$xml_is_sane = isset($values[0]['value']);
1259 1259
 			}
1260
-			if (!$xml_is_sane)
1260
+			if ( ! $xml_is_sane)
1261 1261
 			{
1262 1262
 				return false;
1263 1263
 			}
@@ -1273,7 +1273,7 @@  discard block
 block discarded – undo
1273 1273
 		$this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class('Cache'));
1274 1274
 		$this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen);
1275 1275
 
1276
-		if (!empty($this->multifeed_url))
1276
+		if ( ! empty($this->multifeed_url))
1277 1277
 		{
1278 1278
 			$i = 0;
1279 1279
 			$success = 0;
@@ -1285,7 +1285,7 @@  discard block
 block discarded – undo
1285 1285
 				$this->multifeed_objects[$i]->set_feed_url($url);
1286 1286
 				$single_success = $this->multifeed_objects[$i]->init();
1287 1287
 				$success |= $single_success;
1288
-				if (!$single_success)
1288
+				if ( ! $single_success)
1289 1289
 				{
1290 1290
 					$this->error[$i] = $this->multifeed_objects[$i]->error();
1291 1291
 				}
@@ -1385,7 +1385,7 @@  discard block
 block discarded – undo
1385 1385
 				if ($parser->parse($utf8_data, 'UTF-8'))
1386 1386
 				{
1387 1387
 					$this->data = $parser->get_data();
1388
-					if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE))
1388
+					if ( ! ($this->get_type() & ~SIMPLEPIE_TYPE_NONE))
1389 1389
 					{
1390 1390
 						$this->error = "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed.";
1391 1391
 						$this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
@@ -1399,7 +1399,7 @@  discard block
 block discarded – undo
1399 1399
 					$this->data['build'] = SIMPLEPIE_BUILD;
1400 1400
 
1401 1401
 					// Cache the file if caching is enabled
1402
-					if ($cache && !$cache->save($this))
1402
+					if ($cache && ! $cache->save($this))
1403 1403
 					{
1404 1404
 						trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
1405 1405
 					}
@@ -1437,10 +1437,10 @@  discard block
 block discarded – undo
1437 1437
 		{
1438 1438
 			// Load the Cache
1439 1439
 			$this->data = $cache->load();
1440
-			if (!empty($this->data))
1440
+			if ( ! empty($this->data))
1441 1441
 			{
1442 1442
 				// If the cache is for an outdated build of SimplePie
1443
-				if (!isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD)
1443
+				if ( ! isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD)
1444 1444
 				{
1445 1445
 					$cache->unlink();
1446 1446
 					$this->data = array();
@@ -1486,7 +1486,7 @@  discard block
 block discarded – undo
1486 1486
 							$headers['if-none-match'] = $this->data['headers']['etag'];
1487 1487
 						}
1488 1488
 
1489
-						$file = $this->registry->create('File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen));
1489
+						$file = $this->registry->create('File', array($this->feed_url, $this->timeout / 10, 5, $headers, $this->useragent, $this->force_fsockopen));
1490 1490
 
1491 1491
 						if ($file->success)
1492 1492
 						{
@@ -1517,11 +1517,11 @@  discard block
 block discarded – undo
1517 1517
 			}
1518 1518
 		}
1519 1519
 		// If we don't already have the file (it'll only exist if we've opened it to check if the cache has been modified), open it.
1520
-		if (!isset($file))
1520
+		if ( ! isset($file))
1521 1521
 		{
1522 1522
 			if ($this->file instanceof SimplePie_File && $this->file->url === $this->feed_url)
1523 1523
 			{
1524
-				$file =& $this->file;
1524
+				$file = & $this->file;
1525 1525
 			}
1526 1526
 			else
1527 1527
 			{
@@ -1532,26 +1532,26 @@  discard block
 block discarded – undo
1532 1532
 			}
1533 1533
 		}
1534 1534
 		// If the file connection has an error, set SimplePie::error to that and quit
1535
-		if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
1535
+		if ( ! $file->success && ! ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
1536 1536
 		{
1537 1537
 			$this->error = $file->error;
1538
-			return !empty($this->data);
1538
+			return ! empty($this->data);
1539 1539
 		}
1540 1540
 
1541
-		if (!$this->force_feed)
1541
+		if ( ! $this->force_feed)
1542 1542
 		{
1543 1543
 			// Check if the supplied URL is a feed, if it isn't, look for it.
1544 1544
 			$locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds));
1545 1545
 
1546
-			if (!$locate->is_feed($file))
1546
+			if ( ! $locate->is_feed($file))
1547 1547
 			{
1548 1548
 				// We need to unset this so that if SimplePie::set_file() has been called that object is untouched
1549 1549
 				unset($file);
1550 1550
 				try
1551 1551
 				{
1552
-					if (!($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds)))
1552
+					if ( ! ($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds)))
1553 1553
 					{
1554
-						$this->error = "A feed could not be found at $this->feed_url. A feed with an invalid mime type may fall victim to this error, or " . SIMPLEPIE_NAME . " was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed.";
1554
+						$this->error = "A feed could not be found at $this->feed_url. A feed with an invalid mime type may fall victim to this error, or ".SIMPLEPIE_NAME." was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed.";
1555 1555
 						$this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
1556 1556
 						return false;
1557 1557
 					}
@@ -1566,7 +1566,7 @@  discard block
 block discarded – undo
1566 1566
 				if ($cache)
1567 1567
 				{
1568 1568
 					$this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD);
1569
-					if (!$cache->save($this))
1569
+					if ( ! $cache->save($this))
1570 1570
 					{
1571 1571
 						trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
1572 1572
 					}
@@ -1641,12 +1641,12 @@  discard block
 block discarded – undo
1641 1641
 	 */
1642 1642
 	public function handle_content_type($mime = 'text/html')
1643 1643
 	{
1644
-		if (!headers_sent())
1644
+		if ( ! headers_sent())
1645 1645
 		{
1646 1646
 			$header = "Content-type: $mime;";
1647 1647
 			if ($this->get_encoding())
1648 1648
 			{
1649
-				$header .= ' charset=' . $this->get_encoding();
1649
+				$header .= ' charset='.$this->get_encoding();
1650 1650
 			}
1651 1651
 			else
1652 1652
 			{
@@ -1684,7 +1684,7 @@  discard block
 block discarded – undo
1684 1684
 	 */
1685 1685
 	public function get_type()
1686 1686
 	{
1687
-		if (!isset($this->data['type']))
1687
+		if ( ! isset($this->data['type']))
1688 1688
 		{
1689 1689
 			$this->data['type'] = SIMPLEPIE_TYPE_ALL;
1690 1690
 			if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed']))
@@ -1972,7 +1972,7 @@  discard block
 block discarded – undo
1972 1972
 	 */
1973 1973
 	public function get_base($element = array())
1974 1974
 	{
1975
-		if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base']))
1975
+		if ( ! ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && ! empty($element['xml_base_explicit']) && isset($element['xml_base']))
1976 1976
 		{
1977 1977
 			return $element['xml_base'];
1978 1978
 		}
@@ -2120,7 +2120,7 @@  discard block
 block discarded – undo
2120 2120
 			$categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2121 2121
 		}
2122 2122
 
2123
-		if (!empty($categories))
2123
+		if ( ! empty($categories))
2124 2124
 		{
2125 2125
 			return array_unique($categories);
2126 2126
 		}
@@ -2218,7 +2218,7 @@  discard block
 block discarded – undo
2218 2218
 			$authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2219 2219
 		}
2220 2220
 
2221
-		if (!empty($authors))
2221
+		if ( ! empty($authors))
2222 2222
 		{
2223 2223
 			return array_unique($authors);
2224 2224
 		}
@@ -2304,7 +2304,7 @@  discard block
 block discarded – undo
2304 2304
 			}
2305 2305
 		}
2306 2306
 
2307
-		if (!empty($contributors))
2307
+		if ( ! empty($contributors))
2308 2308
 		{
2309 2309
 			return array_unique($contributors);
2310 2310
 		}
@@ -2362,7 +2362,7 @@  discard block
 block discarded – undo
2362 2362
 	 */
2363 2363
 	public function get_links($rel = 'alternate')
2364 2364
 	{
2365
-		if (!isset($this->data['links']))
2365
+		if ( ! isset($this->data['links']))
2366 2366
 		{
2367 2367
 			$this->data['links'] = array();
2368 2368
 			if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
@@ -2406,19 +2406,19 @@  discard block
 block discarded – undo
2406 2406
 			{
2407 2407
 				if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
2408 2408
 				{
2409
-					if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
2409
+					if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY.$key]))
2410 2410
 					{
2411
-						$this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
2412
-						$this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
2411
+						$this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY.$key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY.$key]);
2412
+						$this->data['links'][$key] = & $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY.$key];
2413 2413
 					}
2414 2414
 					else
2415 2415
 					{
2416
-						$this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
2416
+						$this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY.$key] = & $this->data['links'][$key];
2417 2417
 					}
2418 2418
 				}
2419 2419
 				elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
2420 2420
 				{
2421
-					$this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
2421
+					$this->data['links'][substr($key, 41)] = & $this->data['links'][$key];
2422 2422
 				}
2423 2423
 				$this->data['links'][$key] = array_unique($this->data['links'][$key]);
2424 2424
 			}
@@ -2860,9 +2860,9 @@  discard block
 block discarded – undo
2860 2860
 	 */
2861 2861
 	public function get_items($start = 0, $end = 0)
2862 2862
 	{
2863
-		if (!isset($this->data['items']))
2863
+		if ( ! isset($this->data['items']))
2864 2864
 		{
2865
-			if (!empty($this->multifeed_objects))
2865
+			if ( ! empty($this->multifeed_objects))
2866 2866
 			{
2867 2867
 				$this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit);
2868 2868
 			}
@@ -2912,17 +2912,17 @@  discard block
 block discarded – undo
2912 2912
 			}
2913 2913
 		}
2914 2914
 
2915
-		if (!empty($this->data['items']))
2915
+		if ( ! empty($this->data['items']))
2916 2916
 		{
2917 2917
 			// If we want to order it by date, check if all items have a date, and then sort it
2918 2918
 			if ($this->order_by_date && empty($this->multifeed_objects))
2919 2919
 			{
2920
-				if (!isset($this->data['ordered_items']))
2920
+				if ( ! isset($this->data['ordered_items']))
2921 2921
 				{
2922 2922
 					$do_sort = true;
2923 2923
 					foreach ($this->data['items'] as $item)
2924 2924
 					{
2925
-						if (!$item->get_date('U'))
2925
+						if ( ! $item->get_date('U'))
2926 2926
 						{
2927 2927
 							$do_sort = false;
2928 2928
 							break;
@@ -2982,7 +2982,7 @@  discard block
 block discarded – undo
2982 2982
 
2983 2983
 		if (($url = $this->get_link()) !== null)
2984 2984
 		{
2985
-			return 'http://g.etfv.co/' . urlencode($url);
2985
+			return 'http://g.etfv.co/'.urlencode($url);
2986 2986
 		}
2987 2987
 
2988 2988
 		return false;
@@ -3063,7 +3063,7 @@  discard block
 block discarded – undo
3063 3063
 			$do_sort = true;
3064 3064
 			foreach ($items as $item)
3065 3065
 			{
3066
-				if (!$item->get_date('U'))
3066
+				if ( ! $item->get_date('U'))
3067 3067
 				{
3068 3068
 					$do_sort = false;
3069 3069
 					break;
Please login to merge, or discard this patch.
src/wp-includes/class-smtp.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -879,7 +879,7 @@
 block discarded – undo
879 879
      * Send raw data to the server.
880 880
      * @param string $data The data to send
881 881
      * @access public
882
-     * @return integer|boolean The number of bytes sent to the server or false on error
882
+     * @return integer The number of bytes sent to the server or false on error
883 883
      */
884 884
     public function client_send($data)
885 885
     {
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
             return;
206 206
         }
207 207
         //Avoid clash with built-in function names
208
-        if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
208
+        if ( ! in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
209 209
             call_user_func($this->Debugoutput, $str, $this->do_debug);
210 210
             return;
211 211
         }
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
             default:
228 228
                 //Normalize line breaks
229 229
                 $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
230
-                echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
230
+                echo gmdate('Y-m-d H:i:s')."\t".str_replace(
231 231
                     "\n",
232 232
                     "\n                   \t                  ",
233 233
                     trim($str)
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
             $socket_context = stream_context_create($options);
275 275
             //Suppress errors; connection failures are handled at a higher level
276 276
             $this->smtp_conn = @stream_socket_client(
277
-                $host . ":" . $port,
277
+                $host.":".$port,
278 278
                 $errno,
279 279
                 $errstr,
280 280
                 $timeout,
@@ -296,14 +296,14 @@  discard block
 block discarded – undo
296 296
             );
297 297
         }
298 298
         // Verify we connected properly
299
-        if (!is_resource($this->smtp_conn)) {
299
+        if ( ! is_resource($this->smtp_conn)) {
300 300
             $this->setError(
301 301
                 'Failed to connect to server',
302 302
                 $errno,
303 303
                 $errstr
304 304
             );
305 305
             $this->edebug(
306
-                'SMTP ERROR: ' . $this->error['error']
306
+                'SMTP ERROR: '.$this->error['error']
307 307
                 . ": $errstr ($errno)",
308 308
                 self::DEBUG_CLIENT
309 309
             );
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
         }
323 323
         // Get any announcement
324 324
         $announce = $this->get_lines();
325
-        $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER);
325
+        $this->edebug('SERVER -> CLIENT: '.$announce, self::DEBUG_SERVER);
326 326
         return true;
327 327
     }
328 328
 
@@ -333,11 +333,11 @@  discard block
 block discarded – undo
333 333
      */
334 334
     public function startTLS()
335 335
     {
336
-        if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) {
336
+        if ( ! $this->sendCommand('STARTTLS', 'STARTTLS', 220)) {
337 337
             return false;
338 338
         }
339 339
         // Begin encrypted connection
340
-        if (!stream_socket_enable_crypto(
340
+        if ( ! stream_socket_enable_crypto(
341 341
             $this->smtp_conn,
342 342
             true,
343 343
             STREAM_CRYPTO_METHOD_TLS_CLIENT
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
         $workstation = '',
368 368
         $OAuth = null
369 369
     ) {
370
-        if (!$this->server_caps) {
370
+        if ( ! $this->server_caps) {
371 371
             $this->setError('Authentication is not allowed before HELO/EHLO');
372 372
             return false;
373 373
         }
@@ -375,16 +375,16 @@  discard block
 block discarded – undo
375 375
         if (array_key_exists('EHLO', $this->server_caps)) {
376 376
         // SMTP extensions are available. Let's try to find a proper authentication method
377 377
 
378
-            if (!array_key_exists('AUTH', $this->server_caps)) {
378
+            if ( ! array_key_exists('AUTH', $this->server_caps)) {
379 379
                 $this->setError('Authentication is not allowed at this stage');
380 380
                 // 'at this stage' means that auth may be allowed after the stage changes
381 381
                 // e.g. after STARTTLS
382 382
                 return false;
383 383
             }
384 384
 
385
-            self::edebug('Auth method requested: ' . ($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL);
385
+            self::edebug('Auth method requested: '.($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL);
386 386
             self::edebug(
387
-                'Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']),
387
+                'Auth methods available on the server: '.implode(',', $this->server_caps['AUTH']),
388 388
                 self::DEBUG_LOWLEVEL
389 389
             );
390 390
 
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
                 self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL);
403 403
             }
404 404
 
405
-            if (!in_array($authtype, $this->server_caps['AUTH'])) {
405
+            if ( ! in_array($authtype, $this->server_caps['AUTH'])) {
406 406
                 $this->setError("The requested authentication method \"$authtype\" is not supported by the server");
407 407
                 return false;
408 408
             }
@@ -412,13 +412,13 @@  discard block
 block discarded – undo
412 412
         switch ($authtype) {
413 413
             case 'PLAIN':
414 414
                 // Start authentication
415
-                if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) {
415
+                if ( ! $this->sendCommand('AUTH', 'AUTH PLAIN', 334)) {
416 416
                     return false;
417 417
                 }
418 418
                 // Send encoded username and password
419
-                if (!$this->sendCommand(
419
+                if ( ! $this->sendCommand(
420 420
                     'User & Password',
421
-                    base64_encode("\0" . $username . "\0" . $password),
421
+                    base64_encode("\0".$username."\0".$password),
422 422
                     235
423 423
                 )
424 424
                 ) {
@@ -427,26 +427,26 @@  discard block
 block discarded – undo
427 427
                 break;
428 428
             case 'LOGIN':
429 429
                 // Start authentication
430
-                if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) {
430
+                if ( ! $this->sendCommand('AUTH', 'AUTH LOGIN', 334)) {
431 431
                     return false;
432 432
                 }
433
-                if (!$this->sendCommand("Username", base64_encode($username), 334)) {
433
+                if ( ! $this->sendCommand("Username", base64_encode($username), 334)) {
434 434
                     return false;
435 435
                 }
436
-                if (!$this->sendCommand("Password", base64_encode($password), 235)) {
436
+                if ( ! $this->sendCommand("Password", base64_encode($password), 235)) {
437 437
                     return false;
438 438
                 }
439 439
                 break;
440 440
             case 'CRAM-MD5':
441 441
                 // Start authentication
442
-                if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) {
442
+                if ( ! $this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) {
443 443
                     return false;
444 444
                 }
445 445
                 // Get the challenge
446 446
                 $challenge = base64_decode(substr($this->last_reply, 4));
447 447
 
448 448
                 // Build the response
449
-                $response = $username . ' ' . $this->hmac($challenge, $password);
449
+                $response = $username.' '.$this->hmac($challenge, $password);
450 450
 
451 451
                 // send encoded credentials
452 452
                 return $this->sendCommand('Username', base64_encode($response), 235);
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
         $k_ipad = $key ^ $ipad;
491 491
         $k_opad = $key ^ $opad;
492 492
 
493
-        return md5($k_opad . pack('H*', md5($k_ipad . $data)));
493
+        return md5($k_opad.pack('H*', md5($k_ipad.$data)));
494 494
     }
495 495
 
496 496
     /**
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
     public function data($msg_data)
552 552
     {
553 553
         //This will use the standard timelimit
554
-        if (!$this->sendCommand('DATA', 'DATA', 354)) {
554
+        if ( ! $this->sendCommand('DATA', 'DATA', 354)) {
555 555
             return false;
556 556
         }
557 557
 
@@ -573,7 +573,7 @@  discard block
 block discarded – undo
573 573
 
574 574
         $field = substr($lines[0], 0, strpos($lines[0], ':'));
575 575
         $in_headers = false;
576
-        if (!empty($field) && strpos($field, ' ') === false) {
576
+        if ( ! empty($field) && strpos($field, ' ') === false) {
577 577
             $in_headers = true;
578 578
         }
579 579
 
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
                 //so as to avoid breaking in the middle of a word
590 590
                 $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' ');
591 591
                 //Deliberately matches both false and 0
592
-                if (!$pos) {
592
+                if ( ! $pos) {
593 593
                     //No nice break found, add a hard break
594 594
                     $pos = self::MAX_LINE_LENGTH - 1;
595 595
                     $lines_out[] = substr($line, 0, $pos);
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
                 }
603 603
                 //If processing headers add a LWSP-char to the front of new line RFC822 section 3.1.1
604 604
                 if ($in_headers) {
605
-                    $line = "\t" . $line;
605
+                    $line = "\t".$line;
606 606
                 }
607 607
             }
608 608
             $lines_out[] = $line;
@@ -610,10 +610,10 @@  discard block
 block discarded – undo
610 610
             //Send the lines to the server
611 611
             foreach ($lines_out as $line_out) {
612 612
                 //RFC2821 section 4.5.2
613
-                if (!empty($line_out) and $line_out[0] == '.') {
614
-                    $line_out = '.' . $line_out;
613
+                if ( ! empty($line_out) and $line_out[0] == '.') {
614
+                    $line_out = '.'.$line_out;
615 615
                 }
616
-                $this->client_send($line_out . self::CRLF);
616
+                $this->client_send($line_out.self::CRLF);
617 617
             }
618 618
         }
619 619
 
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
     public function hello($host = '')
641 641
     {
642 642
         //Try extended hello first (RFC 2821)
643
-        return (boolean)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host));
643
+        return (boolean) ($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host));
644 644
     }
645 645
 
646 646
     /**
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
      */
655 655
     protected function sendHello($hello, $host)
656 656
     {
657
-        $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250);
657
+        $noerror = $this->sendCommand($hello, $hello.' '.$host, 250);
658 658
         $this->helo_rply = $this->last_reply;
659 659
         if ($noerror) {
660 660
             $this->parseHelloFields($hello);
@@ -682,8 +682,8 @@  discard block
 block discarded – undo
682 682
                 continue;
683 683
             }
684 684
             $fields = explode(' ', $s);
685
-            if (!empty($fields)) {
686
-                if (!$n) {
685
+            if ( ! empty($fields)) {
686
+                if ( ! $n) {
687 687
                     $name = $type;
688 688
                     $fields = $fields[0];
689 689
                 } else {
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
                             $fields = ($fields ? $fields[0] : 0);
694 694
                             break;
695 695
                         case 'AUTH':
696
-                            if (!is_array($fields)) {
696
+                            if ( ! is_array($fields)) {
697 697
                                 $fields = array();
698 698
                             }
699 699
                             break;
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
         $useVerp = ($this->do_verp ? ' XVERP' : '');
723 723
         return $this->sendCommand(
724 724
             'MAIL FROM',
725
-            'MAIL FROM:<' . $from . '>' . $useVerp,
725
+            'MAIL FROM:<'.$from.'>'.$useVerp,
726 726
             250
727 727
         );
728 728
     }
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
     {
760 760
         return $this->sendCommand(
761 761
             'RCPT TO',
762
-            'RCPT TO:<' . $address . '>',
762
+            'RCPT TO:<'.$address.'>',
763 763
             array(250, 251)
764 764
         );
765 765
     }
@@ -786,7 +786,7 @@  discard block
 block discarded – undo
786 786
      */
787 787
     protected function sendCommand($command, $commandstring, $expect)
788 788
     {
789
-        if (!$this->connected()) {
789
+        if ( ! $this->connected()) {
790 790
             $this->setError("Called $command without being connected");
791 791
             return false;
792 792
         }
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
             $this->setError("Command '$command' contained line breaks");
796 796
             return false;
797 797
         }
798
-        $this->client_send($commandstring . self::CRLF);
798
+        $this->client_send($commandstring.self::CRLF);
799 799
 
800 800
         $this->last_reply = $this->get_lines();
801 801
         // Fetch SMTP code and possible error code explanation
@@ -816,9 +816,9 @@  discard block
 block discarded – undo
816 816
             $detail = substr($this->last_reply, 4);
817 817
         }
818 818
 
819
-        $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);
819
+        $this->edebug('SERVER -> CLIENT: '.$this->last_reply, self::DEBUG_SERVER);
820 820
 
821
-        if (!in_array($code, (array)$expect)) {
821
+        if ( ! in_array($code, (array) $expect)) {
822 822
             $this->setError(
823 823
                 "$command command failed",
824 824
                 $detail,
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
                 $code_ex
827 827
             );
828 828
             $this->edebug(
829
-                'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply,
829
+                'SMTP ERROR: '.$this->error['error'].': '.$this->last_reply,
830 830
                 self::DEBUG_CLIENT
831 831
             );
832 832
             return false;
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
     public function turn()
889 889
     {
890 890
         $this->setError('The SMTP TURN command is not implemented');
891
-        $this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT);
891
+        $this->edebug('SMTP NOTICE: '.$this->error['error'], self::DEBUG_CLIENT);
892 892
         return false;
893 893
     }
894 894
 
@@ -945,13 +945,13 @@  discard block
 block discarded – undo
945 945
      */
946 946
     public function getServerExt($name)
947 947
     {
948
-        if (!$this->server_caps) {
948
+        if ( ! $this->server_caps) {
949 949
             $this->setError('No HELO/EHLO was sent');
950 950
             return null;
951 951
         }
952 952
 
953 953
         // the tight logic knot ;)
954
-        if (!array_key_exists($name, $this->server_caps)) {
954
+        if ( ! array_key_exists($name, $this->server_caps)) {
955 955
             if ($name == 'HELO') {
956 956
                 return $this->server_caps['EHLO'];
957 957
             }
@@ -987,7 +987,7 @@  discard block
 block discarded – undo
987 987
     protected function get_lines()
988 988
     {
989 989
         // If the connection is bad, give up straight away
990
-        if (!is_resource($this->smtp_conn)) {
990
+        if ( ! is_resource($this->smtp_conn)) {
991 991
             return '';
992 992
         }
993 993
         $data = '';
@@ -996,7 +996,7 @@  discard block
 block discarded – undo
996 996
         if ($this->Timelimit > 0) {
997 997
             $endtime = time() + $this->Timelimit;
998 998
         }
999
-        while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
999
+        while (is_resource($this->smtp_conn) && ! feof($this->smtp_conn)) {
1000 1000
             $str = @fgets($this->smtp_conn, 515);
1001 1001
             $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL);
1002 1002
             $this->edebug("SMTP -> get_lines(): \$str is  \"$str\"", self::DEBUG_LOWLEVEL);
@@ -1009,7 +1009,7 @@  discard block
 block discarded – undo
1009 1009
             $info = stream_get_meta_data($this->smtp_conn);
1010 1010
             if ($info['timed_out']) {
1011 1011
                 $this->edebug(
1012
-                    'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)',
1012
+                    'SMTP -> get_lines(): timed-out ('.$this->Timeout.' sec)',
1013 1013
                     self::DEBUG_LOWLEVEL
1014 1014
                 );
1015 1015
                 break;
@@ -1018,7 +1018,7 @@  discard block
 block discarded – undo
1018 1018
             if ($endtime and time() > $endtime) {
1019 1019
                 $this->edebug(
1020 1020
                     'SMTP -> get_lines(): timelimit reached ('.
1021
-                    $this->Timelimit . ' sec)',
1021
+                    $this->Timelimit.' sec)',
1022 1022
                     self::DEBUG_LOWLEVEL
1023 1023
                 );
1024 1024
                 break;
Please login to merge, or discard this patch.
Indentation   +1077 added lines, -1077 removed lines patch added patch discarded remove patch
@@ -26,536 +26,536 @@  discard block
 block discarded – undo
26 26
  */
27 27
 class SMTP
28 28
 {
29
-    /**
30
-     * The PHPMailer SMTP version number.
31
-     * @var string
32
-     */
33
-    const VERSION = '5.2.14';
34
-
35
-    /**
36
-     * SMTP line break constant.
37
-     * @var string
38
-     */
39
-    const CRLF = "\r\n";
40
-
41
-    /**
42
-     * The SMTP port to use if one is not specified.
43
-     * @var integer
44
-     */
45
-    const DEFAULT_SMTP_PORT = 25;
46
-
47
-    /**
48
-     * The maximum line length allowed by RFC 2822 section 2.1.1
49
-     * @var integer
50
-     */
51
-    const MAX_LINE_LENGTH = 998;
52
-
53
-    /**
54
-     * Debug level for no output
55
-     */
56
-    const DEBUG_OFF = 0;
57
-
58
-    /**
59
-     * Debug level to show client -> server messages
60
-     */
61
-    const DEBUG_CLIENT = 1;
62
-
63
-    /**
64
-     * Debug level to show client -> server and server -> client messages
65
-     */
66
-    const DEBUG_SERVER = 2;
67
-
68
-    /**
69
-     * Debug level to show connection status, client -> server and server -> client messages
70
-     */
71
-    const DEBUG_CONNECTION = 3;
72
-
73
-    /**
74
-     * Debug level to show all messages
75
-     */
76
-    const DEBUG_LOWLEVEL = 4;
77
-
78
-    /**
79
-     * The PHPMailer SMTP Version number.
80
-     * @var string
81
-     * @deprecated Use the `VERSION` constant instead
82
-     * @see SMTP::VERSION
83
-     */
84
-    public $Version = '5.2.14';
85
-
86
-    /**
87
-     * SMTP server port number.
88
-     * @var integer
89
-     * @deprecated This is only ever used as a default value, so use the `DEFAULT_SMTP_PORT` constant instead
90
-     * @see SMTP::DEFAULT_SMTP_PORT
91
-     */
92
-    public $SMTP_PORT = 25;
93
-
94
-    /**
95
-     * SMTP reply line ending.
96
-     * @var string
97
-     * @deprecated Use the `CRLF` constant instead
98
-     * @see SMTP::CRLF
99
-     */
100
-    public $CRLF = "\r\n";
101
-
102
-    /**
103
-     * Debug output level.
104
-     * Options:
105
-     * * self::DEBUG_OFF (`0`) No debug output, default
106
-     * * self::DEBUG_CLIENT (`1`) Client commands
107
-     * * self::DEBUG_SERVER (`2`) Client commands and server responses
108
-     * * self::DEBUG_CONNECTION (`3`) As DEBUG_SERVER plus connection status
109
-     * * self::DEBUG_LOWLEVEL (`4`) Low-level data output, all messages
110
-     * @var integer
111
-     */
112
-    public $do_debug = self::DEBUG_OFF;
113
-
114
-    /**
115
-     * How to handle debug output.
116
-     * Options:
117
-     * * `echo` Output plain-text as-is, appropriate for CLI
118
-     * * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output
119
-     * * `error_log` Output to error log as configured in php.ini
120
-     *
121
-     * Alternatively, you can provide a callable expecting two params: a message string and the debug level:
122
-     * <code>
123
-     * $smtp->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
124
-     * </code>
125
-     * @var string|callable
126
-     */
127
-    public $Debugoutput = 'echo';
128
-
129
-    /**
130
-     * Whether to use VERP.
131
-     * @link http://en.wikipedia.org/wiki/Variable_envelope_return_path
132
-     * @link http://www.postfix.org/VERP_README.html Info on VERP
133
-     * @var boolean
134
-     */
135
-    public $do_verp = false;
136
-
137
-    /**
138
-     * The timeout value for connection, in seconds.
139
-     * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
140
-     * This needs to be quite high to function correctly with hosts using greetdelay as an anti-spam measure.
141
-     * @link http://tools.ietf.org/html/rfc2821#section-4.5.3.2
142
-     * @var integer
143
-     */
144
-    public $Timeout = 300;
145
-
146
-    /**
147
-     * How long to wait for commands to complete, in seconds.
148
-     * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
149
-     * @var integer
150
-     */
151
-    public $Timelimit = 300;
152
-
153
-    /**
154
-     * The socket for the server connection.
155
-     * @var resource
156
-     */
157
-    protected $smtp_conn;
158
-
159
-    /**
160
-     * Error information, if any, for the last SMTP command.
161
-     * @var array
162
-     */
163
-    protected $error = array(
164
-        'error' => '',
165
-        'detail' => '',
166
-        'smtp_code' => '',
167
-        'smtp_code_ex' => ''
168
-    );
169
-
170
-    /**
171
-     * The reply the server sent to us for HELO.
172
-     * If null, no HELO string has yet been received.
173
-     * @var string|null
174
-     */
175
-    protected $helo_rply = null;
176
-
177
-    /**
178
-     * The set of SMTP extensions sent in reply to EHLO command.
179
-     * Indexes of the array are extension names.
180
-     * Value at index 'HELO' or 'EHLO' (according to command that was sent)
181
-     * represents the server name. In case of HELO it is the only element of the array.
182
-     * Other values can be boolean TRUE or an array containing extension options.
183
-     * If null, no HELO/EHLO string has yet been received.
184
-     * @var array|null
185
-     */
186
-    protected $server_caps = null;
187
-
188
-    /**
189
-     * The most recent reply received from the server.
190
-     * @var string
191
-     */
192
-    protected $last_reply = '';
193
-
194
-    /**
195
-     * Output debugging info via a user-selected method.
196
-     * @see SMTP::$Debugoutput
197
-     * @see SMTP::$do_debug
198
-     * @param string $str Debug string to output
199
-     * @param integer $level The debug level of this message; see DEBUG_* constants
200
-     * @return void
201
-     */
202
-    protected function edebug($str, $level = 0)
203
-    {
204
-        if ($level > $this->do_debug) {
205
-            return;
206
-        }
207
-        //Avoid clash with built-in function names
208
-        if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
209
-            call_user_func($this->Debugoutput, $str, $this->do_debug);
210
-            return;
211
-        }
212
-        switch ($this->Debugoutput) {
213
-            case 'error_log':
214
-                //Don't output, just log
215
-                error_log($str);
216
-                break;
217
-            case 'html':
218
-                //Cleans up output a bit for a better looking, HTML-safe output
219
-                echo htmlentities(
220
-                    preg_replace('/[\r\n]+/', '', $str),
221
-                    ENT_QUOTES,
222
-                    'UTF-8'
223
-                )
224
-                . "<br>\n";
225
-                break;
226
-            case 'echo':
227
-            default:
228
-                //Normalize line breaks
229
-                $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
230
-                echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
231
-                    "\n",
232
-                    "\n                   \t                  ",
233
-                    trim($str)
234
-                )."\n";
235
-        }
236
-    }
237
-
238
-    /**
239
-     * Connect to an SMTP server.
240
-     * @param string $host SMTP server IP or host name
241
-     * @param integer $port The port number to connect to
242
-     * @param integer $timeout How long to wait for the connection to open
243
-     * @param array $options An array of options for stream_context_create()
244
-     * @access public
245
-     * @return boolean
246
-     */
247
-    public function connect($host, $port = null, $timeout = 30, $options = array())
248
-    {
249
-        static $streamok;
250
-        //This is enabled by default since 5.0.0 but some providers disable it
251
-        //Check this once and cache the result
252
-        if (is_null($streamok)) {
253
-            $streamok = function_exists('stream_socket_client');
254
-        }
255
-        // Clear errors to avoid confusion
256
-        $this->setError('');
257
-        // Make sure we are __not__ connected
258
-        if ($this->connected()) {
259
-            // Already connected, generate error
260
-            $this->setError('Already connected to a server');
261
-            return false;
262
-        }
263
-        if (empty($port)) {
264
-            $port = self::DEFAULT_SMTP_PORT;
265
-        }
266
-        // Connect to the SMTP server
267
-        $this->edebug(
268
-            "Connection: opening to $host:$port, timeout=$timeout, options=".var_export($options, true),
269
-            self::DEBUG_CONNECTION
270
-        );
271
-        $errno = 0;
272
-        $errstr = '';
273
-        if ($streamok) {
274
-            $socket_context = stream_context_create($options);
275
-            //Suppress errors; connection failures are handled at a higher level
276
-            $this->smtp_conn = @stream_socket_client(
277
-                $host . ":" . $port,
278
-                $errno,
279
-                $errstr,
280
-                $timeout,
281
-                STREAM_CLIENT_CONNECT,
282
-                $socket_context
283
-            );
284
-        } else {
285
-            //Fall back to fsockopen which should work in more places, but is missing some features
286
-            $this->edebug(
287
-                "Connection: stream_socket_client not available, falling back to fsockopen",
288
-                self::DEBUG_CONNECTION
289
-            );
290
-            $this->smtp_conn = fsockopen(
291
-                $host,
292
-                $port,
293
-                $errno,
294
-                $errstr,
295
-                $timeout
296
-            );
297
-        }
298
-        // Verify we connected properly
299
-        if (!is_resource($this->smtp_conn)) {
300
-            $this->setError(
301
-                'Failed to connect to server',
302
-                $errno,
303
-                $errstr
304
-            );
305
-            $this->edebug(
306
-                'SMTP ERROR: ' . $this->error['error']
307
-                . ": $errstr ($errno)",
308
-                self::DEBUG_CLIENT
309
-            );
310
-            return false;
311
-        }
312
-        $this->edebug('Connection: opened', self::DEBUG_CONNECTION);
313
-        // SMTP server can take longer to respond, give longer timeout for first read
314
-        // Windows does not have support for this timeout function
315
-        if (substr(PHP_OS, 0, 3) != 'WIN') {
316
-            $max = ini_get('max_execution_time');
317
-            // Don't bother if unlimited
318
-            if ($max != 0 && $timeout > $max) {
319
-                @set_time_limit($timeout);
320
-            }
321
-            stream_set_timeout($this->smtp_conn, $timeout, 0);
322
-        }
323
-        // Get any announcement
324
-        $announce = $this->get_lines();
325
-        $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER);
326
-        return true;
327
-    }
328
-
329
-    /**
330
-     * Initiate a TLS (encrypted) session.
331
-     * @access public
332
-     * @return boolean
333
-     */
334
-    public function startTLS()
335
-    {
336
-        if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) {
337
-            return false;
338
-        }
339
-        // Begin encrypted connection
340
-        if (!stream_socket_enable_crypto(
341
-            $this->smtp_conn,
342
-            true,
343
-            STREAM_CRYPTO_METHOD_TLS_CLIENT
344
-        )) {
345
-            return false;
346
-        }
347
-        return true;
348
-    }
349
-
350
-    /**
351
-     * Perform SMTP authentication.
352
-     * Must be run after hello().
353
-     * @see hello()
354
-     * @param string $username The user name
355
-     * @param string $password The password
356
-     * @param string $authtype The auth type (PLAIN, LOGIN, NTLM, CRAM-MD5, XOAUTH2)
357
-     * @param string $realm The auth realm for NTLM
358
-     * @param string $workstation The auth workstation for NTLM
359
-     * @param null|OAuth $OAuth An optional OAuth instance (@see PHPMailerOAuth)
360
-     * @return bool True if successfully authenticated.* @access public
361
-     */
362
-    public function authenticate(
363
-        $username,
364
-        $password,
365
-        $authtype = null,
366
-        $realm = '',
367
-        $workstation = '',
368
-        $OAuth = null
369
-    ) {
370
-        if (!$this->server_caps) {
371
-            $this->setError('Authentication is not allowed before HELO/EHLO');
372
-            return false;
373
-        }
374
-
375
-        if (array_key_exists('EHLO', $this->server_caps)) {
376
-        // SMTP extensions are available. Let's try to find a proper authentication method
377
-
378
-            if (!array_key_exists('AUTH', $this->server_caps)) {
379
-                $this->setError('Authentication is not allowed at this stage');
380
-                // 'at this stage' means that auth may be allowed after the stage changes
381
-                // e.g. after STARTTLS
382
-                return false;
383
-            }
384
-
385
-            self::edebug('Auth method requested: ' . ($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL);
386
-            self::edebug(
387
-                'Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']),
388
-                self::DEBUG_LOWLEVEL
389
-            );
390
-
391
-            if (empty($authtype)) {
392
-                foreach (array('LOGIN', 'CRAM-MD5', 'PLAIN') as $method) {
393
-                    if (in_array($method, $this->server_caps['AUTH'])) {
394
-                        $authtype = $method;
395
-                        break;
396
-                    }
397
-                }
398
-                if (empty($authtype)) {
399
-                    $this->setError('No supported authentication methods found');
400
-                    return false;
401
-                }
402
-                self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL);
403
-            }
404
-
405
-            if (!in_array($authtype, $this->server_caps['AUTH'])) {
406
-                $this->setError("The requested authentication method \"$authtype\" is not supported by the server");
407
-                return false;
408
-            }
409
-        } elseif (empty($authtype)) {
410
-            $authtype = 'LOGIN';
411
-        }
412
-        switch ($authtype) {
413
-            case 'PLAIN':
414
-                // Start authentication
415
-                if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) {
416
-                    return false;
417
-                }
418
-                // Send encoded username and password
419
-                if (!$this->sendCommand(
420
-                    'User & Password',
421
-                    base64_encode("\0" . $username . "\0" . $password),
422
-                    235
423
-                )
424
-                ) {
425
-                    return false;
426
-                }
427
-                break;
428
-            case 'LOGIN':
429
-                // Start authentication
430
-                if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) {
431
-                    return false;
432
-                }
433
-                if (!$this->sendCommand("Username", base64_encode($username), 334)) {
434
-                    return false;
435
-                }
436
-                if (!$this->sendCommand("Password", base64_encode($password), 235)) {
437
-                    return false;
438
-                }
439
-                break;
440
-            case 'CRAM-MD5':
441
-                // Start authentication
442
-                if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) {
443
-                    return false;
444
-                }
445
-                // Get the challenge
446
-                $challenge = base64_decode(substr($this->last_reply, 4));
447
-
448
-                // Build the response
449
-                $response = $username . ' ' . $this->hmac($challenge, $password);
450
-
451
-                // send encoded credentials
452
-                return $this->sendCommand('Username', base64_encode($response), 235);
453
-            default:
454
-                $this->setError("Authentication method \"$authtype\" is not supported");
455
-                return false;
456
-        }
457
-        return true;
458
-    }
459
-
460
-    /**
461
-     * Calculate an MD5 HMAC hash.
462
-     * Works like hash_hmac('md5', $data, $key)
463
-     * in case that function is not available
464
-     * @param string $data The data to hash
465
-     * @param string $key  The key to hash with
466
-     * @access protected
467
-     * @return string
468
-     */
469
-    protected function hmac($data, $key)
470
-    {
471
-        if (function_exists('hash_hmac')) {
472
-            return hash_hmac('md5', $data, $key);
473
-        }
474
-
475
-        // The following borrowed from
476
-        // http://php.net/manual/en/function.mhash.php#27225
477
-
478
-        // RFC 2104 HMAC implementation for php.
479
-        // Creates an md5 HMAC.
480
-        // Eliminates the need to install mhash to compute a HMAC
481
-        // by Lance Rushing
482
-
483
-        $bytelen = 64; // byte length for md5
484
-        if (strlen($key) > $bytelen) {
485
-            $key = pack('H*', md5($key));
486
-        }
487
-        $key = str_pad($key, $bytelen, chr(0x00));
488
-        $ipad = str_pad('', $bytelen, chr(0x36));
489
-        $opad = str_pad('', $bytelen, chr(0x5c));
490
-        $k_ipad = $key ^ $ipad;
491
-        $k_opad = $key ^ $opad;
492
-
493
-        return md5($k_opad . pack('H*', md5($k_ipad . $data)));
494
-    }
495
-
496
-    /**
497
-     * Check connection state.
498
-     * @access public
499
-     * @return boolean True if connected.
500
-     */
501
-    public function connected()
502
-    {
503
-        if (is_resource($this->smtp_conn)) {
504
-            $sock_status = stream_get_meta_data($this->smtp_conn);
505
-            if ($sock_status['eof']) {
506
-                // The socket is valid but we are not connected
507
-                $this->edebug(
508
-                    'SMTP NOTICE: EOF caught while checking if connected',
509
-                    self::DEBUG_CLIENT
510
-                );
511
-                $this->close();
512
-                return false;
513
-            }
514
-            return true; // everything looks good
515
-        }
516
-        return false;
517
-    }
518
-
519
-    /**
520
-     * Close the socket and clean up the state of the class.
521
-     * Don't use this function without first trying to use QUIT.
522
-     * @see quit()
523
-     * @access public
524
-     * @return void
525
-     */
526
-    public function close()
527
-    {
528
-        $this->setError('');
529
-        $this->server_caps = null;
530
-        $this->helo_rply = null;
531
-        if (is_resource($this->smtp_conn)) {
532
-            // close the connection and cleanup
533
-            fclose($this->smtp_conn);
534
-            $this->smtp_conn = null; //Makes for cleaner serialization
535
-            $this->edebug('Connection: closed', self::DEBUG_CONNECTION);
536
-        }
537
-    }
538
-
539
-    /**
540
-     * Send an SMTP DATA command.
541
-     * Issues a data command and sends the msg_data to the server,
542
-     * finializing the mail transaction. $msg_data is the message
543
-     * that is to be send with the headers. Each header needs to be
544
-     * on a single line followed by a <CRLF> with the message headers
545
-     * and the message body being separated by and additional <CRLF>.
546
-     * Implements rfc 821: DATA <CRLF>
547
-     * @param string $msg_data Message data to send
548
-     * @access public
549
-     * @return boolean
550
-     */
551
-    public function data($msg_data)
552
-    {
553
-        //This will use the standard timelimit
554
-        if (!$this->sendCommand('DATA', 'DATA', 354)) {
555
-            return false;
556
-        }
557
-
558
-        /* The server is ready to accept data!
29
+	/**
30
+	 * The PHPMailer SMTP version number.
31
+	 * @var string
32
+	 */
33
+	const VERSION = '5.2.14';
34
+
35
+	/**
36
+	 * SMTP line break constant.
37
+	 * @var string
38
+	 */
39
+	const CRLF = "\r\n";
40
+
41
+	/**
42
+	 * The SMTP port to use if one is not specified.
43
+	 * @var integer
44
+	 */
45
+	const DEFAULT_SMTP_PORT = 25;
46
+
47
+	/**
48
+	 * The maximum line length allowed by RFC 2822 section 2.1.1
49
+	 * @var integer
50
+	 */
51
+	const MAX_LINE_LENGTH = 998;
52
+
53
+	/**
54
+	 * Debug level for no output
55
+	 */
56
+	const DEBUG_OFF = 0;
57
+
58
+	/**
59
+	 * Debug level to show client -> server messages
60
+	 */
61
+	const DEBUG_CLIENT = 1;
62
+
63
+	/**
64
+	 * Debug level to show client -> server and server -> client messages
65
+	 */
66
+	const DEBUG_SERVER = 2;
67
+
68
+	/**
69
+	 * Debug level to show connection status, client -> server and server -> client messages
70
+	 */
71
+	const DEBUG_CONNECTION = 3;
72
+
73
+	/**
74
+	 * Debug level to show all messages
75
+	 */
76
+	const DEBUG_LOWLEVEL = 4;
77
+
78
+	/**
79
+	 * The PHPMailer SMTP Version number.
80
+	 * @var string
81
+	 * @deprecated Use the `VERSION` constant instead
82
+	 * @see SMTP::VERSION
83
+	 */
84
+	public $Version = '5.2.14';
85
+
86
+	/**
87
+	 * SMTP server port number.
88
+	 * @var integer
89
+	 * @deprecated This is only ever used as a default value, so use the `DEFAULT_SMTP_PORT` constant instead
90
+	 * @see SMTP::DEFAULT_SMTP_PORT
91
+	 */
92
+	public $SMTP_PORT = 25;
93
+
94
+	/**
95
+	 * SMTP reply line ending.
96
+	 * @var string
97
+	 * @deprecated Use the `CRLF` constant instead
98
+	 * @see SMTP::CRLF
99
+	 */
100
+	public $CRLF = "\r\n";
101
+
102
+	/**
103
+	 * Debug output level.
104
+	 * Options:
105
+	 * * self::DEBUG_OFF (`0`) No debug output, default
106
+	 * * self::DEBUG_CLIENT (`1`) Client commands
107
+	 * * self::DEBUG_SERVER (`2`) Client commands and server responses
108
+	 * * self::DEBUG_CONNECTION (`3`) As DEBUG_SERVER plus connection status
109
+	 * * self::DEBUG_LOWLEVEL (`4`) Low-level data output, all messages
110
+	 * @var integer
111
+	 */
112
+	public $do_debug = self::DEBUG_OFF;
113
+
114
+	/**
115
+	 * How to handle debug output.
116
+	 * Options:
117
+	 * * `echo` Output plain-text as-is, appropriate for CLI
118
+	 * * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output
119
+	 * * `error_log` Output to error log as configured in php.ini
120
+	 *
121
+	 * Alternatively, you can provide a callable expecting two params: a message string and the debug level:
122
+	 * <code>
123
+	 * $smtp->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
124
+	 * </code>
125
+	 * @var string|callable
126
+	 */
127
+	public $Debugoutput = 'echo';
128
+
129
+	/**
130
+	 * Whether to use VERP.
131
+	 * @link http://en.wikipedia.org/wiki/Variable_envelope_return_path
132
+	 * @link http://www.postfix.org/VERP_README.html Info on VERP
133
+	 * @var boolean
134
+	 */
135
+	public $do_verp = false;
136
+
137
+	/**
138
+	 * The timeout value for connection, in seconds.
139
+	 * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
140
+	 * This needs to be quite high to function correctly with hosts using greetdelay as an anti-spam measure.
141
+	 * @link http://tools.ietf.org/html/rfc2821#section-4.5.3.2
142
+	 * @var integer
143
+	 */
144
+	public $Timeout = 300;
145
+
146
+	/**
147
+	 * How long to wait for commands to complete, in seconds.
148
+	 * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
149
+	 * @var integer
150
+	 */
151
+	public $Timelimit = 300;
152
+
153
+	/**
154
+	 * The socket for the server connection.
155
+	 * @var resource
156
+	 */
157
+	protected $smtp_conn;
158
+
159
+	/**
160
+	 * Error information, if any, for the last SMTP command.
161
+	 * @var array
162
+	 */
163
+	protected $error = array(
164
+		'error' => '',
165
+		'detail' => '',
166
+		'smtp_code' => '',
167
+		'smtp_code_ex' => ''
168
+	);
169
+
170
+	/**
171
+	 * The reply the server sent to us for HELO.
172
+	 * If null, no HELO string has yet been received.
173
+	 * @var string|null
174
+	 */
175
+	protected $helo_rply = null;
176
+
177
+	/**
178
+	 * The set of SMTP extensions sent in reply to EHLO command.
179
+	 * Indexes of the array are extension names.
180
+	 * Value at index 'HELO' or 'EHLO' (according to command that was sent)
181
+	 * represents the server name. In case of HELO it is the only element of the array.
182
+	 * Other values can be boolean TRUE or an array containing extension options.
183
+	 * If null, no HELO/EHLO string has yet been received.
184
+	 * @var array|null
185
+	 */
186
+	protected $server_caps = null;
187
+
188
+	/**
189
+	 * The most recent reply received from the server.
190
+	 * @var string
191
+	 */
192
+	protected $last_reply = '';
193
+
194
+	/**
195
+	 * Output debugging info via a user-selected method.
196
+	 * @see SMTP::$Debugoutput
197
+	 * @see SMTP::$do_debug
198
+	 * @param string $str Debug string to output
199
+	 * @param integer $level The debug level of this message; see DEBUG_* constants
200
+	 * @return void
201
+	 */
202
+	protected function edebug($str, $level = 0)
203
+	{
204
+		if ($level > $this->do_debug) {
205
+			return;
206
+		}
207
+		//Avoid clash with built-in function names
208
+		if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
209
+			call_user_func($this->Debugoutput, $str, $this->do_debug);
210
+			return;
211
+		}
212
+		switch ($this->Debugoutput) {
213
+			case 'error_log':
214
+				//Don't output, just log
215
+				error_log($str);
216
+				break;
217
+			case 'html':
218
+				//Cleans up output a bit for a better looking, HTML-safe output
219
+				echo htmlentities(
220
+					preg_replace('/[\r\n]+/', '', $str),
221
+					ENT_QUOTES,
222
+					'UTF-8'
223
+				)
224
+				. "<br>\n";
225
+				break;
226
+			case 'echo':
227
+			default:
228
+				//Normalize line breaks
229
+				$str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
230
+				echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
231
+					"\n",
232
+					"\n                   \t                  ",
233
+					trim($str)
234
+				)."\n";
235
+		}
236
+	}
237
+
238
+	/**
239
+	 * Connect to an SMTP server.
240
+	 * @param string $host SMTP server IP or host name
241
+	 * @param integer $port The port number to connect to
242
+	 * @param integer $timeout How long to wait for the connection to open
243
+	 * @param array $options An array of options for stream_context_create()
244
+	 * @access public
245
+	 * @return boolean
246
+	 */
247
+	public function connect($host, $port = null, $timeout = 30, $options = array())
248
+	{
249
+		static $streamok;
250
+		//This is enabled by default since 5.0.0 but some providers disable it
251
+		//Check this once and cache the result
252
+		if (is_null($streamok)) {
253
+			$streamok = function_exists('stream_socket_client');
254
+		}
255
+		// Clear errors to avoid confusion
256
+		$this->setError('');
257
+		// Make sure we are __not__ connected
258
+		if ($this->connected()) {
259
+			// Already connected, generate error
260
+			$this->setError('Already connected to a server');
261
+			return false;
262
+		}
263
+		if (empty($port)) {
264
+			$port = self::DEFAULT_SMTP_PORT;
265
+		}
266
+		// Connect to the SMTP server
267
+		$this->edebug(
268
+			"Connection: opening to $host:$port, timeout=$timeout, options=".var_export($options, true),
269
+			self::DEBUG_CONNECTION
270
+		);
271
+		$errno = 0;
272
+		$errstr = '';
273
+		if ($streamok) {
274
+			$socket_context = stream_context_create($options);
275
+			//Suppress errors; connection failures are handled at a higher level
276
+			$this->smtp_conn = @stream_socket_client(
277
+				$host . ":" . $port,
278
+				$errno,
279
+				$errstr,
280
+				$timeout,
281
+				STREAM_CLIENT_CONNECT,
282
+				$socket_context
283
+			);
284
+		} else {
285
+			//Fall back to fsockopen which should work in more places, but is missing some features
286
+			$this->edebug(
287
+				"Connection: stream_socket_client not available, falling back to fsockopen",
288
+				self::DEBUG_CONNECTION
289
+			);
290
+			$this->smtp_conn = fsockopen(
291
+				$host,
292
+				$port,
293
+				$errno,
294
+				$errstr,
295
+				$timeout
296
+			);
297
+		}
298
+		// Verify we connected properly
299
+		if (!is_resource($this->smtp_conn)) {
300
+			$this->setError(
301
+				'Failed to connect to server',
302
+				$errno,
303
+				$errstr
304
+			);
305
+			$this->edebug(
306
+				'SMTP ERROR: ' . $this->error['error']
307
+				. ": $errstr ($errno)",
308
+				self::DEBUG_CLIENT
309
+			);
310
+			return false;
311
+		}
312
+		$this->edebug('Connection: opened', self::DEBUG_CONNECTION);
313
+		// SMTP server can take longer to respond, give longer timeout for first read
314
+		// Windows does not have support for this timeout function
315
+		if (substr(PHP_OS, 0, 3) != 'WIN') {
316
+			$max = ini_get('max_execution_time');
317
+			// Don't bother if unlimited
318
+			if ($max != 0 && $timeout > $max) {
319
+				@set_time_limit($timeout);
320
+			}
321
+			stream_set_timeout($this->smtp_conn, $timeout, 0);
322
+		}
323
+		// Get any announcement
324
+		$announce = $this->get_lines();
325
+		$this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER);
326
+		return true;
327
+	}
328
+
329
+	/**
330
+	 * Initiate a TLS (encrypted) session.
331
+	 * @access public
332
+	 * @return boolean
333
+	 */
334
+	public function startTLS()
335
+	{
336
+		if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) {
337
+			return false;
338
+		}
339
+		// Begin encrypted connection
340
+		if (!stream_socket_enable_crypto(
341
+			$this->smtp_conn,
342
+			true,
343
+			STREAM_CRYPTO_METHOD_TLS_CLIENT
344
+		)) {
345
+			return false;
346
+		}
347
+		return true;
348
+	}
349
+
350
+	/**
351
+	 * Perform SMTP authentication.
352
+	 * Must be run after hello().
353
+	 * @see hello()
354
+	 * @param string $username The user name
355
+	 * @param string $password The password
356
+	 * @param string $authtype The auth type (PLAIN, LOGIN, NTLM, CRAM-MD5, XOAUTH2)
357
+	 * @param string $realm The auth realm for NTLM
358
+	 * @param string $workstation The auth workstation for NTLM
359
+	 * @param null|OAuth $OAuth An optional OAuth instance (@see PHPMailerOAuth)
360
+	 * @return bool True if successfully authenticated.* @access public
361
+	 */
362
+	public function authenticate(
363
+		$username,
364
+		$password,
365
+		$authtype = null,
366
+		$realm = '',
367
+		$workstation = '',
368
+		$OAuth = null
369
+	) {
370
+		if (!$this->server_caps) {
371
+			$this->setError('Authentication is not allowed before HELO/EHLO');
372
+			return false;
373
+		}
374
+
375
+		if (array_key_exists('EHLO', $this->server_caps)) {
376
+		// SMTP extensions are available. Let's try to find a proper authentication method
377
+
378
+			if (!array_key_exists('AUTH', $this->server_caps)) {
379
+				$this->setError('Authentication is not allowed at this stage');
380
+				// 'at this stage' means that auth may be allowed after the stage changes
381
+				// e.g. after STARTTLS
382
+				return false;
383
+			}
384
+
385
+			self::edebug('Auth method requested: ' . ($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL);
386
+			self::edebug(
387
+				'Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']),
388
+				self::DEBUG_LOWLEVEL
389
+			);
390
+
391
+			if (empty($authtype)) {
392
+				foreach (array('LOGIN', 'CRAM-MD5', 'PLAIN') as $method) {
393
+					if (in_array($method, $this->server_caps['AUTH'])) {
394
+						$authtype = $method;
395
+						break;
396
+					}
397
+				}
398
+				if (empty($authtype)) {
399
+					$this->setError('No supported authentication methods found');
400
+					return false;
401
+				}
402
+				self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL);
403
+			}
404
+
405
+			if (!in_array($authtype, $this->server_caps['AUTH'])) {
406
+				$this->setError("The requested authentication method \"$authtype\" is not supported by the server");
407
+				return false;
408
+			}
409
+		} elseif (empty($authtype)) {
410
+			$authtype = 'LOGIN';
411
+		}
412
+		switch ($authtype) {
413
+			case 'PLAIN':
414
+				// Start authentication
415
+				if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) {
416
+					return false;
417
+				}
418
+				// Send encoded username and password
419
+				if (!$this->sendCommand(
420
+					'User & Password',
421
+					base64_encode("\0" . $username . "\0" . $password),
422
+					235
423
+				)
424
+				) {
425
+					return false;
426
+				}
427
+				break;
428
+			case 'LOGIN':
429
+				// Start authentication
430
+				if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) {
431
+					return false;
432
+				}
433
+				if (!$this->sendCommand("Username", base64_encode($username), 334)) {
434
+					return false;
435
+				}
436
+				if (!$this->sendCommand("Password", base64_encode($password), 235)) {
437
+					return false;
438
+				}
439
+				break;
440
+			case 'CRAM-MD5':
441
+				// Start authentication
442
+				if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) {
443
+					return false;
444
+				}
445
+				// Get the challenge
446
+				$challenge = base64_decode(substr($this->last_reply, 4));
447
+
448
+				// Build the response
449
+				$response = $username . ' ' . $this->hmac($challenge, $password);
450
+
451
+				// send encoded credentials
452
+				return $this->sendCommand('Username', base64_encode($response), 235);
453
+			default:
454
+				$this->setError("Authentication method \"$authtype\" is not supported");
455
+				return false;
456
+		}
457
+		return true;
458
+	}
459
+
460
+	/**
461
+	 * Calculate an MD5 HMAC hash.
462
+	 * Works like hash_hmac('md5', $data, $key)
463
+	 * in case that function is not available
464
+	 * @param string $data The data to hash
465
+	 * @param string $key  The key to hash with
466
+	 * @access protected
467
+	 * @return string
468
+	 */
469
+	protected function hmac($data, $key)
470
+	{
471
+		if (function_exists('hash_hmac')) {
472
+			return hash_hmac('md5', $data, $key);
473
+		}
474
+
475
+		// The following borrowed from
476
+		// http://php.net/manual/en/function.mhash.php#27225
477
+
478
+		// RFC 2104 HMAC implementation for php.
479
+		// Creates an md5 HMAC.
480
+		// Eliminates the need to install mhash to compute a HMAC
481
+		// by Lance Rushing
482
+
483
+		$bytelen = 64; // byte length for md5
484
+		if (strlen($key) > $bytelen) {
485
+			$key = pack('H*', md5($key));
486
+		}
487
+		$key = str_pad($key, $bytelen, chr(0x00));
488
+		$ipad = str_pad('', $bytelen, chr(0x36));
489
+		$opad = str_pad('', $bytelen, chr(0x5c));
490
+		$k_ipad = $key ^ $ipad;
491
+		$k_opad = $key ^ $opad;
492
+
493
+		return md5($k_opad . pack('H*', md5($k_ipad . $data)));
494
+	}
495
+
496
+	/**
497
+	 * Check connection state.
498
+	 * @access public
499
+	 * @return boolean True if connected.
500
+	 */
501
+	public function connected()
502
+	{
503
+		if (is_resource($this->smtp_conn)) {
504
+			$sock_status = stream_get_meta_data($this->smtp_conn);
505
+			if ($sock_status['eof']) {
506
+				// The socket is valid but we are not connected
507
+				$this->edebug(
508
+					'SMTP NOTICE: EOF caught while checking if connected',
509
+					self::DEBUG_CLIENT
510
+				);
511
+				$this->close();
512
+				return false;
513
+			}
514
+			return true; // everything looks good
515
+		}
516
+		return false;
517
+	}
518
+
519
+	/**
520
+	 * Close the socket and clean up the state of the class.
521
+	 * Don't use this function without first trying to use QUIT.
522
+	 * @see quit()
523
+	 * @access public
524
+	 * @return void
525
+	 */
526
+	public function close()
527
+	{
528
+		$this->setError('');
529
+		$this->server_caps = null;
530
+		$this->helo_rply = null;
531
+		if (is_resource($this->smtp_conn)) {
532
+			// close the connection and cleanup
533
+			fclose($this->smtp_conn);
534
+			$this->smtp_conn = null; //Makes for cleaner serialization
535
+			$this->edebug('Connection: closed', self::DEBUG_CONNECTION);
536
+		}
537
+	}
538
+
539
+	/**
540
+	 * Send an SMTP DATA command.
541
+	 * Issues a data command and sends the msg_data to the server,
542
+	 * finializing the mail transaction. $msg_data is the message
543
+	 * that is to be send with the headers. Each header needs to be
544
+	 * on a single line followed by a <CRLF> with the message headers
545
+	 * and the message body being separated by and additional <CRLF>.
546
+	 * Implements rfc 821: DATA <CRLF>
547
+	 * @param string $msg_data Message data to send
548
+	 * @access public
549
+	 * @return boolean
550
+	 */
551
+	public function data($msg_data)
552
+	{
553
+		//This will use the standard timelimit
554
+		if (!$this->sendCommand('DATA', 'DATA', 354)) {
555
+			return false;
556
+		}
557
+
558
+		/* The server is ready to accept data!
559 559
          * According to rfc821 we should not send more than 1000 characters on a single line (including the CRLF)
560 560
          * so we will break the data up into lines by \r and/or \n then if needed we will break each of those into
561 561
          * smaller lines to fit within the limit.
@@ -563,556 +563,556 @@  discard block
 block discarded – undo
563 563
          * NOTE: this does not count towards line-length limit.
564 564
          */
565 565
 
566
-        // Normalize line breaks before exploding
567
-        $lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data));
566
+		// Normalize line breaks before exploding
567
+		$lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data));
568 568
 
569
-        /* To distinguish between a complete RFC822 message and a plain message body, we check if the first field
569
+		/* To distinguish between a complete RFC822 message and a plain message body, we check if the first field
570 570
          * of the first line (':' separated) does not contain a space then it _should_ be a header and we will
571 571
          * process all lines before a blank line as headers.
572 572
          */
573 573
 
574
-        $field = substr($lines[0], 0, strpos($lines[0], ':'));
575
-        $in_headers = false;
576
-        if (!empty($field) && strpos($field, ' ') === false) {
577
-            $in_headers = true;
578
-        }
579
-
580
-        foreach ($lines as $line) {
581
-            $lines_out = array();
582
-            if ($in_headers and $line == '') {
583
-                $in_headers = false;
584
-            }
585
-            //Break this line up into several smaller lines if it's too long
586
-            //Micro-optimisation: isset($str[$len]) is faster than (strlen($str) > $len),
587
-            while (isset($line[self::MAX_LINE_LENGTH])) {
588
-                //Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on
589
-                //so as to avoid breaking in the middle of a word
590
-                $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' ');
591
-                //Deliberately matches both false and 0
592
-                if (!$pos) {
593
-                    //No nice break found, add a hard break
594
-                    $pos = self::MAX_LINE_LENGTH - 1;
595
-                    $lines_out[] = substr($line, 0, $pos);
596
-                    $line = substr($line, $pos);
597
-                } else {
598
-                    //Break at the found point
599
-                    $lines_out[] = substr($line, 0, $pos);
600
-                    //Move along by the amount we dealt with
601
-                    $line = substr($line, $pos + 1);
602
-                }
603
-                //If processing headers add a LWSP-char to the front of new line RFC822 section 3.1.1
604
-                if ($in_headers) {
605
-                    $line = "\t" . $line;
606
-                }
607
-            }
608
-            $lines_out[] = $line;
609
-
610
-            //Send the lines to the server
611
-            foreach ($lines_out as $line_out) {
612
-                //RFC2821 section 4.5.2
613
-                if (!empty($line_out) and $line_out[0] == '.') {
614
-                    $line_out = '.' . $line_out;
615
-                }
616
-                $this->client_send($line_out . self::CRLF);
617
-            }
618
-        }
619
-
620
-        //Message data has been sent, complete the command
621
-        //Increase timelimit for end of DATA command
622
-        $savetimelimit = $this->Timelimit;
623
-        $this->Timelimit = $this->Timelimit * 2;
624
-        $result = $this->sendCommand('DATA END', '.', 250);
625
-        //Restore timelimit
626
-        $this->Timelimit = $savetimelimit;
627
-        return $result;
628
-    }
629
-
630
-    /**
631
-     * Send an SMTP HELO or EHLO command.
632
-     * Used to identify the sending server to the receiving server.
633
-     * This makes sure that client and server are in a known state.
634
-     * Implements RFC 821: HELO <SP> <domain> <CRLF>
635
-     * and RFC 2821 EHLO.
636
-     * @param string $host The host name or IP to connect to
637
-     * @access public
638
-     * @return boolean
639
-     */
640
-    public function hello($host = '')
641
-    {
642
-        //Try extended hello first (RFC 2821)
643
-        return (boolean)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host));
644
-    }
645
-
646
-    /**
647
-     * Send an SMTP HELO or EHLO command.
648
-     * Low-level implementation used by hello()
649
-     * @see hello()
650
-     * @param string $hello The HELO string
651
-     * @param string $host The hostname to say we are
652
-     * @access protected
653
-     * @return boolean
654
-     */
655
-    protected function sendHello($hello, $host)
656
-    {
657
-        $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250);
658
-        $this->helo_rply = $this->last_reply;
659
-        if ($noerror) {
660
-            $this->parseHelloFields($hello);
661
-        } else {
662
-            $this->server_caps = null;
663
-        }
664
-        return $noerror;
665
-    }
666
-
667
-    /**
668
-     * Parse a reply to HELO/EHLO command to discover server extensions.
669
-     * In case of HELO, the only parameter that can be discovered is a server name.
670
-     * @access protected
671
-     * @param string $type - 'HELO' or 'EHLO'
672
-     */
673
-    protected function parseHelloFields($type)
674
-    {
675
-        $this->server_caps = array();
676
-        $lines = explode("\n", $this->last_reply);
677
-
678
-        foreach ($lines as $n => $s) {
679
-            //First 4 chars contain response code followed by - or space
680
-            $s = trim(substr($s, 4));
681
-            if (empty($s)) {
682
-                continue;
683
-            }
684
-            $fields = explode(' ', $s);
685
-            if (!empty($fields)) {
686
-                if (!$n) {
687
-                    $name = $type;
688
-                    $fields = $fields[0];
689
-                } else {
690
-                    $name = array_shift($fields);
691
-                    switch ($name) {
692
-                        case 'SIZE':
693
-                            $fields = ($fields ? $fields[0] : 0);
694
-                            break;
695
-                        case 'AUTH':
696
-                            if (!is_array($fields)) {
697
-                                $fields = array();
698
-                            }
699
-                            break;
700
-                        default:
701
-                            $fields = true;
702
-                    }
703
-                }
704
-                $this->server_caps[$name] = $fields;
705
-            }
706
-        }
707
-    }
708
-
709
-    /**
710
-     * Send an SMTP MAIL command.
711
-     * Starts a mail transaction from the email address specified in
712
-     * $from. Returns true if successful or false otherwise. If True
713
-     * the mail transaction is started and then one or more recipient
714
-     * commands may be called followed by a data command.
715
-     * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
716
-     * @param string $from Source address of this message
717
-     * @access public
718
-     * @return boolean
719
-     */
720
-    public function mail($from)
721
-    {
722
-        $useVerp = ($this->do_verp ? ' XVERP' : '');
723
-        return $this->sendCommand(
724
-            'MAIL FROM',
725
-            'MAIL FROM:<' . $from . '>' . $useVerp,
726
-            250
727
-        );
728
-    }
729
-
730
-    /**
731
-     * Send an SMTP QUIT command.
732
-     * Closes the socket if there is no error or the $close_on_error argument is true.
733
-     * Implements from rfc 821: QUIT <CRLF>
734
-     * @param boolean $close_on_error Should the connection close if an error occurs?
735
-     * @access public
736
-     * @return boolean
737
-     */
738
-    public function quit($close_on_error = true)
739
-    {
740
-        $noerror = $this->sendCommand('QUIT', 'QUIT', 221);
741
-        $err = $this->error; //Save any error
742
-        if ($noerror or $close_on_error) {
743
-            $this->close();
744
-            $this->error = $err; //Restore any error from the quit command
745
-        }
746
-        return $noerror;
747
-    }
748
-
749
-    /**
750
-     * Send an SMTP RCPT command.
751
-     * Sets the TO argument to $toaddr.
752
-     * Returns true if the recipient was accepted false if it was rejected.
753
-     * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
754
-     * @param string $address The address the message is being sent to
755
-     * @access public
756
-     * @return boolean
757
-     */
758
-    public function recipient($address)
759
-    {
760
-        return $this->sendCommand(
761
-            'RCPT TO',
762
-            'RCPT TO:<' . $address . '>',
763
-            array(250, 251)
764
-        );
765
-    }
766
-
767
-    /**
768
-     * Send an SMTP RSET command.
769
-     * Abort any transaction that is currently in progress.
770
-     * Implements rfc 821: RSET <CRLF>
771
-     * @access public
772
-     * @return boolean True on success.
773
-     */
774
-    public function reset()
775
-    {
776
-        return $this->sendCommand('RSET', 'RSET', 250);
777
-    }
778
-
779
-    /**
780
-     * Send a command to an SMTP server and check its return code.
781
-     * @param string $command The command name - not sent to the server
782
-     * @param string $commandstring The actual command to send
783
-     * @param integer|array $expect One or more expected integer success codes
784
-     * @access protected
785
-     * @return boolean True on success.
786
-     */
787
-    protected function sendCommand($command, $commandstring, $expect)
788
-    {
789
-        if (!$this->connected()) {
790
-            $this->setError("Called $command without being connected");
791
-            return false;
792
-        }
793
-        //Reject line breaks in all commands
794
-        if (strpos($commandstring, "\n") !== false or strpos($commandstring, "\r") !== false) {
795
-            $this->setError("Command '$command' contained line breaks");
796
-            return false;
797
-        }
798
-        $this->client_send($commandstring . self::CRLF);
799
-
800
-        $this->last_reply = $this->get_lines();
801
-        // Fetch SMTP code and possible error code explanation
802
-        $matches = array();
803
-        if (preg_match("/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/", $this->last_reply, $matches)) {
804
-            $code = $matches[1];
805
-            $code_ex = (count($matches) > 2 ? $matches[2] : null);
806
-            // Cut off error code from each response line
807
-            $detail = preg_replace(
808
-                "/{$code}[ -]".($code_ex ? str_replace('.', '\\.', $code_ex).' ' : '')."/m",
809
-                '',
810
-                $this->last_reply
811
-            );
812
-        } else {
813
-            // Fall back to simple parsing if regex fails
814
-            $code = substr($this->last_reply, 0, 3);
815
-            $code_ex = null;
816
-            $detail = substr($this->last_reply, 4);
817
-        }
818
-
819
-        $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);
820
-
821
-        if (!in_array($code, (array)$expect)) {
822
-            $this->setError(
823
-                "$command command failed",
824
-                $detail,
825
-                $code,
826
-                $code_ex
827
-            );
828
-            $this->edebug(
829
-                'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply,
830
-                self::DEBUG_CLIENT
831
-            );
832
-            return false;
833
-        }
834
-
835
-        $this->setError('');
836
-        return true;
837
-    }
838
-
839
-    /**
840
-     * Send an SMTP SAML command.
841
-     * Starts a mail transaction from the email address specified in $from.
842
-     * Returns true if successful or false otherwise. If True
843
-     * the mail transaction is started and then one or more recipient
844
-     * commands may be called followed by a data command. This command
845
-     * will send the message to the users terminal if they are logged
846
-     * in and send them an email.
847
-     * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
848
-     * @param string $from The address the message is from
849
-     * @access public
850
-     * @return boolean
851
-     */
852
-    public function sendAndMail($from)
853
-    {
854
-        return $this->sendCommand('SAML', "SAML FROM:$from", 250);
855
-    }
856
-
857
-    /**
858
-     * Send an SMTP VRFY command.
859
-     * @param string $name The name to verify
860
-     * @access public
861
-     * @return boolean
862
-     */
863
-    public function verify($name)
864
-    {
865
-        return $this->sendCommand('VRFY', "VRFY $name", array(250, 251));
866
-    }
867
-
868
-    /**
869
-     * Send an SMTP NOOP command.
870
-     * Used to keep keep-alives alive, doesn't actually do anything
871
-     * @access public
872
-     * @return boolean
873
-     */
874
-    public function noop()
875
-    {
876
-        return $this->sendCommand('NOOP', 'NOOP', 250);
877
-    }
878
-
879
-    /**
880
-     * Send an SMTP TURN command.
881
-     * This is an optional command for SMTP that this class does not support.
882
-     * This method is here to make the RFC821 Definition complete for this class
883
-     * and _may_ be implemented in future
884
-     * Implements from rfc 821: TURN <CRLF>
885
-     * @access public
886
-     * @return boolean
887
-     */
888
-    public function turn()
889
-    {
890
-        $this->setError('The SMTP TURN command is not implemented');
891
-        $this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT);
892
-        return false;
893
-    }
894
-
895
-    /**
896
-     * Send raw data to the server.
897
-     * @param string $data The data to send
898
-     * @access public
899
-     * @return integer|boolean The number of bytes sent to the server or false on error
900
-     */
901
-    public function client_send($data)
902
-    {
903
-        $this->edebug("CLIENT -> SERVER: $data", self::DEBUG_CLIENT);
904
-        return fwrite($this->smtp_conn, $data);
905
-    }
906
-
907
-    /**
908
-     * Get the latest error.
909
-     * @access public
910
-     * @return array
911
-     */
912
-    public function getError()
913
-    {
914
-        return $this->error;
915
-    }
916
-
917
-    /**
918
-     * Get SMTP extensions available on the server
919
-     * @access public
920
-     * @return array|null
921
-     */
922
-    public function getServerExtList()
923
-    {
924
-        return $this->server_caps;
925
-    }
926
-
927
-    /**
928
-     * A multipurpose method
929
-     * The method works in three ways, dependent on argument value and current state
930
-     *   1. HELO/EHLO was not sent - returns null and set up $this->error
931
-     *   2. HELO was sent
932
-     *     $name = 'HELO': returns server name
933
-     *     $name = 'EHLO': returns boolean false
934
-     *     $name = any string: returns null and set up $this->error
935
-     *   3. EHLO was sent
936
-     *     $name = 'HELO'|'EHLO': returns server name
937
-     *     $name = any string: if extension $name exists, returns boolean True
938
-     *       or its options. Otherwise returns boolean False
939
-     * In other words, one can use this method to detect 3 conditions:
940
-     *  - null returned: handshake was not or we don't know about ext (refer to $this->error)
941
-     *  - false returned: the requested feature exactly not exists
942
-     *  - positive value returned: the requested feature exists
943
-     * @param string $name Name of SMTP extension or 'HELO'|'EHLO'
944
-     * @return mixed
945
-     */
946
-    public function getServerExt($name)
947
-    {
948
-        if (!$this->server_caps) {
949
-            $this->setError('No HELO/EHLO was sent');
950
-            return null;
951
-        }
952
-
953
-        // the tight logic knot ;)
954
-        if (!array_key_exists($name, $this->server_caps)) {
955
-            if ($name == 'HELO') {
956
-                return $this->server_caps['EHLO'];
957
-            }
958
-            if ($name == 'EHLO' || array_key_exists('EHLO', $this->server_caps)) {
959
-                return false;
960
-            }
961
-            $this->setError('HELO handshake was used. Client knows nothing about server extensions');
962
-            return null;
963
-        }
964
-
965
-        return $this->server_caps[$name];
966
-    }
967
-
968
-    /**
969
-     * Get the last reply from the server.
970
-     * @access public
971
-     * @return string
972
-     */
973
-    public function getLastReply()
974
-    {
975
-        return $this->last_reply;
976
-    }
977
-
978
-    /**
979
-     * Read the SMTP server's response.
980
-     * Either before eof or socket timeout occurs on the operation.
981
-     * With SMTP we can tell if we have more lines to read if the
982
-     * 4th character is '-' symbol. If it is a space then we don't
983
-     * need to read anything else.
984
-     * @access protected
985
-     * @return string
986
-     */
987
-    protected function get_lines()
988
-    {
989
-        // If the connection is bad, give up straight away
990
-        if (!is_resource($this->smtp_conn)) {
991
-            return '';
992
-        }
993
-        $data = '';
994
-        $endtime = 0;
995
-        stream_set_timeout($this->smtp_conn, $this->Timeout);
996
-        if ($this->Timelimit > 0) {
997
-            $endtime = time() + $this->Timelimit;
998
-        }
999
-        while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
1000
-            $str = @fgets($this->smtp_conn, 515);
1001
-            $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL);
1002
-            $this->edebug("SMTP -> get_lines(): \$str is  \"$str\"", self::DEBUG_LOWLEVEL);
1003
-            $data .= $str;
1004
-            // If 4th character is a space, we are done reading, break the loop, micro-optimisation over strlen
1005
-            if ((isset($str[3]) and $str[3] == ' ')) {
1006
-                break;
1007
-            }
1008
-            // Timed-out? Log and break
1009
-            $info = stream_get_meta_data($this->smtp_conn);
1010
-            if ($info['timed_out']) {
1011
-                $this->edebug(
1012
-                    'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)',
1013
-                    self::DEBUG_LOWLEVEL
1014
-                );
1015
-                break;
1016
-            }
1017
-            // Now check if reads took too long
1018
-            if ($endtime and time() > $endtime) {
1019
-                $this->edebug(
1020
-                    'SMTP -> get_lines(): timelimit reached ('.
1021
-                    $this->Timelimit . ' sec)',
1022
-                    self::DEBUG_LOWLEVEL
1023
-                );
1024
-                break;
1025
-            }
1026
-        }
1027
-        return $data;
1028
-    }
1029
-
1030
-    /**
1031
-     * Enable or disable VERP address generation.
1032
-     * @param boolean $enabled
1033
-     */
1034
-    public function setVerp($enabled = false)
1035
-    {
1036
-        $this->do_verp = $enabled;
1037
-    }
1038
-
1039
-    /**
1040
-     * Get VERP address generation mode.
1041
-     * @return boolean
1042
-     */
1043
-    public function getVerp()
1044
-    {
1045
-        return $this->do_verp;
1046
-    }
1047
-
1048
-    /**
1049
-     * Set error messages and codes.
1050
-     * @param string $message The error message
1051
-     * @param string $detail Further detail on the error
1052
-     * @param string $smtp_code An associated SMTP error code
1053
-     * @param string $smtp_code_ex Extended SMTP code
1054
-     */
1055
-    protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '')
1056
-    {
1057
-        $this->error = array(
1058
-            'error' => $message,
1059
-            'detail' => $detail,
1060
-            'smtp_code' => $smtp_code,
1061
-            'smtp_code_ex' => $smtp_code_ex
1062
-        );
1063
-    }
1064
-
1065
-    /**
1066
-     * Set debug output method.
1067
-     * @param string|callable $method The name of the mechanism to use for debugging output, or a callable to handle it.
1068
-     */
1069
-    public function setDebugOutput($method = 'echo')
1070
-    {
1071
-        $this->Debugoutput = $method;
1072
-    }
1073
-
1074
-    /**
1075
-     * Get debug output method.
1076
-     * @return string
1077
-     */
1078
-    public function getDebugOutput()
1079
-    {
1080
-        return $this->Debugoutput;
1081
-    }
1082
-
1083
-    /**
1084
-     * Set debug output level.
1085
-     * @param integer $level
1086
-     */
1087
-    public function setDebugLevel($level = 0)
1088
-    {
1089
-        $this->do_debug = $level;
1090
-    }
1091
-
1092
-    /**
1093
-     * Get debug output level.
1094
-     * @return integer
1095
-     */
1096
-    public function getDebugLevel()
1097
-    {
1098
-        return $this->do_debug;
1099
-    }
1100
-
1101
-    /**
1102
-     * Set SMTP timeout.
1103
-     * @param integer $timeout
1104
-     */
1105
-    public function setTimeout($timeout = 0)
1106
-    {
1107
-        $this->Timeout = $timeout;
1108
-    }
1109
-
1110
-    /**
1111
-     * Get SMTP timeout.
1112
-     * @return integer
1113
-     */
1114
-    public function getTimeout()
1115
-    {
1116
-        return $this->Timeout;
1117
-    }
574
+		$field = substr($lines[0], 0, strpos($lines[0], ':'));
575
+		$in_headers = false;
576
+		if (!empty($field) && strpos($field, ' ') === false) {
577
+			$in_headers = true;
578
+		}
579
+
580
+		foreach ($lines as $line) {
581
+			$lines_out = array();
582
+			if ($in_headers and $line == '') {
583
+				$in_headers = false;
584
+			}
585
+			//Break this line up into several smaller lines if it's too long
586
+			//Micro-optimisation: isset($str[$len]) is faster than (strlen($str) > $len),
587
+			while (isset($line[self::MAX_LINE_LENGTH])) {
588
+				//Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on
589
+				//so as to avoid breaking in the middle of a word
590
+				$pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' ');
591
+				//Deliberately matches both false and 0
592
+				if (!$pos) {
593
+					//No nice break found, add a hard break
594
+					$pos = self::MAX_LINE_LENGTH - 1;
595
+					$lines_out[] = substr($line, 0, $pos);
596
+					$line = substr($line, $pos);
597
+				} else {
598
+					//Break at the found point
599
+					$lines_out[] = substr($line, 0, $pos);
600
+					//Move along by the amount we dealt with
601
+					$line = substr($line, $pos + 1);
602
+				}
603
+				//If processing headers add a LWSP-char to the front of new line RFC822 section 3.1.1
604
+				if ($in_headers) {
605
+					$line = "\t" . $line;
606
+				}
607
+			}
608
+			$lines_out[] = $line;
609
+
610
+			//Send the lines to the server
611
+			foreach ($lines_out as $line_out) {
612
+				//RFC2821 section 4.5.2
613
+				if (!empty($line_out) and $line_out[0] == '.') {
614
+					$line_out = '.' . $line_out;
615
+				}
616
+				$this->client_send($line_out . self::CRLF);
617
+			}
618
+		}
619
+
620
+		//Message data has been sent, complete the command
621
+		//Increase timelimit for end of DATA command
622
+		$savetimelimit = $this->Timelimit;
623
+		$this->Timelimit = $this->Timelimit * 2;
624
+		$result = $this->sendCommand('DATA END', '.', 250);
625
+		//Restore timelimit
626
+		$this->Timelimit = $savetimelimit;
627
+		return $result;
628
+	}
629
+
630
+	/**
631
+	 * Send an SMTP HELO or EHLO command.
632
+	 * Used to identify the sending server to the receiving server.
633
+	 * This makes sure that client and server are in a known state.
634
+	 * Implements RFC 821: HELO <SP> <domain> <CRLF>
635
+	 * and RFC 2821 EHLO.
636
+	 * @param string $host The host name or IP to connect to
637
+	 * @access public
638
+	 * @return boolean
639
+	 */
640
+	public function hello($host = '')
641
+	{
642
+		//Try extended hello first (RFC 2821)
643
+		return (boolean)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host));
644
+	}
645
+
646
+	/**
647
+	 * Send an SMTP HELO or EHLO command.
648
+	 * Low-level implementation used by hello()
649
+	 * @see hello()
650
+	 * @param string $hello The HELO string
651
+	 * @param string $host The hostname to say we are
652
+	 * @access protected
653
+	 * @return boolean
654
+	 */
655
+	protected function sendHello($hello, $host)
656
+	{
657
+		$noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250);
658
+		$this->helo_rply = $this->last_reply;
659
+		if ($noerror) {
660
+			$this->parseHelloFields($hello);
661
+		} else {
662
+			$this->server_caps = null;
663
+		}
664
+		return $noerror;
665
+	}
666
+
667
+	/**
668
+	 * Parse a reply to HELO/EHLO command to discover server extensions.
669
+	 * In case of HELO, the only parameter that can be discovered is a server name.
670
+	 * @access protected
671
+	 * @param string $type - 'HELO' or 'EHLO'
672
+	 */
673
+	protected function parseHelloFields($type)
674
+	{
675
+		$this->server_caps = array();
676
+		$lines = explode("\n", $this->last_reply);
677
+
678
+		foreach ($lines as $n => $s) {
679
+			//First 4 chars contain response code followed by - or space
680
+			$s = trim(substr($s, 4));
681
+			if (empty($s)) {
682
+				continue;
683
+			}
684
+			$fields = explode(' ', $s);
685
+			if (!empty($fields)) {
686
+				if (!$n) {
687
+					$name = $type;
688
+					$fields = $fields[0];
689
+				} else {
690
+					$name = array_shift($fields);
691
+					switch ($name) {
692
+						case 'SIZE':
693
+							$fields = ($fields ? $fields[0] : 0);
694
+							break;
695
+						case 'AUTH':
696
+							if (!is_array($fields)) {
697
+								$fields = array();
698
+							}
699
+							break;
700
+						default:
701
+							$fields = true;
702
+					}
703
+				}
704
+				$this->server_caps[$name] = $fields;
705
+			}
706
+		}
707
+	}
708
+
709
+	/**
710
+	 * Send an SMTP MAIL command.
711
+	 * Starts a mail transaction from the email address specified in
712
+	 * $from. Returns true if successful or false otherwise. If True
713
+	 * the mail transaction is started and then one or more recipient
714
+	 * commands may be called followed by a data command.
715
+	 * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
716
+	 * @param string $from Source address of this message
717
+	 * @access public
718
+	 * @return boolean
719
+	 */
720
+	public function mail($from)
721
+	{
722
+		$useVerp = ($this->do_verp ? ' XVERP' : '');
723
+		return $this->sendCommand(
724
+			'MAIL FROM',
725
+			'MAIL FROM:<' . $from . '>' . $useVerp,
726
+			250
727
+		);
728
+	}
729
+
730
+	/**
731
+	 * Send an SMTP QUIT command.
732
+	 * Closes the socket if there is no error or the $close_on_error argument is true.
733
+	 * Implements from rfc 821: QUIT <CRLF>
734
+	 * @param boolean $close_on_error Should the connection close if an error occurs?
735
+	 * @access public
736
+	 * @return boolean
737
+	 */
738
+	public function quit($close_on_error = true)
739
+	{
740
+		$noerror = $this->sendCommand('QUIT', 'QUIT', 221);
741
+		$err = $this->error; //Save any error
742
+		if ($noerror or $close_on_error) {
743
+			$this->close();
744
+			$this->error = $err; //Restore any error from the quit command
745
+		}
746
+		return $noerror;
747
+	}
748
+
749
+	/**
750
+	 * Send an SMTP RCPT command.
751
+	 * Sets the TO argument to $toaddr.
752
+	 * Returns true if the recipient was accepted false if it was rejected.
753
+	 * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
754
+	 * @param string $address The address the message is being sent to
755
+	 * @access public
756
+	 * @return boolean
757
+	 */
758
+	public function recipient($address)
759
+	{
760
+		return $this->sendCommand(
761
+			'RCPT TO',
762
+			'RCPT TO:<' . $address . '>',
763
+			array(250, 251)
764
+		);
765
+	}
766
+
767
+	/**
768
+	 * Send an SMTP RSET command.
769
+	 * Abort any transaction that is currently in progress.
770
+	 * Implements rfc 821: RSET <CRLF>
771
+	 * @access public
772
+	 * @return boolean True on success.
773
+	 */
774
+	public function reset()
775
+	{
776
+		return $this->sendCommand('RSET', 'RSET', 250);
777
+	}
778
+
779
+	/**
780
+	 * Send a command to an SMTP server and check its return code.
781
+	 * @param string $command The command name - not sent to the server
782
+	 * @param string $commandstring The actual command to send
783
+	 * @param integer|array $expect One or more expected integer success codes
784
+	 * @access protected
785
+	 * @return boolean True on success.
786
+	 */
787
+	protected function sendCommand($command, $commandstring, $expect)
788
+	{
789
+		if (!$this->connected()) {
790
+			$this->setError("Called $command without being connected");
791
+			return false;
792
+		}
793
+		//Reject line breaks in all commands
794
+		if (strpos($commandstring, "\n") !== false or strpos($commandstring, "\r") !== false) {
795
+			$this->setError("Command '$command' contained line breaks");
796
+			return false;
797
+		}
798
+		$this->client_send($commandstring . self::CRLF);
799
+
800
+		$this->last_reply = $this->get_lines();
801
+		// Fetch SMTP code and possible error code explanation
802
+		$matches = array();
803
+		if (preg_match("/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/", $this->last_reply, $matches)) {
804
+			$code = $matches[1];
805
+			$code_ex = (count($matches) > 2 ? $matches[2] : null);
806
+			// Cut off error code from each response line
807
+			$detail = preg_replace(
808
+				"/{$code}[ -]".($code_ex ? str_replace('.', '\\.', $code_ex).' ' : '')."/m",
809
+				'',
810
+				$this->last_reply
811
+			);
812
+		} else {
813
+			// Fall back to simple parsing if regex fails
814
+			$code = substr($this->last_reply, 0, 3);
815
+			$code_ex = null;
816
+			$detail = substr($this->last_reply, 4);
817
+		}
818
+
819
+		$this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);
820
+
821
+		if (!in_array($code, (array)$expect)) {
822
+			$this->setError(
823
+				"$command command failed",
824
+				$detail,
825
+				$code,
826
+				$code_ex
827
+			);
828
+			$this->edebug(
829
+				'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply,
830
+				self::DEBUG_CLIENT
831
+			);
832
+			return false;
833
+		}
834
+
835
+		$this->setError('');
836
+		return true;
837
+	}
838
+
839
+	/**
840
+	 * Send an SMTP SAML command.
841
+	 * Starts a mail transaction from the email address specified in $from.
842
+	 * Returns true if successful or false otherwise. If True
843
+	 * the mail transaction is started and then one or more recipient
844
+	 * commands may be called followed by a data command. This command
845
+	 * will send the message to the users terminal if they are logged
846
+	 * in and send them an email.
847
+	 * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
848
+	 * @param string $from The address the message is from
849
+	 * @access public
850
+	 * @return boolean
851
+	 */
852
+	public function sendAndMail($from)
853
+	{
854
+		return $this->sendCommand('SAML', "SAML FROM:$from", 250);
855
+	}
856
+
857
+	/**
858
+	 * Send an SMTP VRFY command.
859
+	 * @param string $name The name to verify
860
+	 * @access public
861
+	 * @return boolean
862
+	 */
863
+	public function verify($name)
864
+	{
865
+		return $this->sendCommand('VRFY', "VRFY $name", array(250, 251));
866
+	}
867
+
868
+	/**
869
+	 * Send an SMTP NOOP command.
870
+	 * Used to keep keep-alives alive, doesn't actually do anything
871
+	 * @access public
872
+	 * @return boolean
873
+	 */
874
+	public function noop()
875
+	{
876
+		return $this->sendCommand('NOOP', 'NOOP', 250);
877
+	}
878
+
879
+	/**
880
+	 * Send an SMTP TURN command.
881
+	 * This is an optional command for SMTP that this class does not support.
882
+	 * This method is here to make the RFC821 Definition complete for this class
883
+	 * and _may_ be implemented in future
884
+	 * Implements from rfc 821: TURN <CRLF>
885
+	 * @access public
886
+	 * @return boolean
887
+	 */
888
+	public function turn()
889
+	{
890
+		$this->setError('The SMTP TURN command is not implemented');
891
+		$this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT);
892
+		return false;
893
+	}
894
+
895
+	/**
896
+	 * Send raw data to the server.
897
+	 * @param string $data The data to send
898
+	 * @access public
899
+	 * @return integer|boolean The number of bytes sent to the server or false on error
900
+	 */
901
+	public function client_send($data)
902
+	{
903
+		$this->edebug("CLIENT -> SERVER: $data", self::DEBUG_CLIENT);
904
+		return fwrite($this->smtp_conn, $data);
905
+	}
906
+
907
+	/**
908
+	 * Get the latest error.
909
+	 * @access public
910
+	 * @return array
911
+	 */
912
+	public function getError()
913
+	{
914
+		return $this->error;
915
+	}
916
+
917
+	/**
918
+	 * Get SMTP extensions available on the server
919
+	 * @access public
920
+	 * @return array|null
921
+	 */
922
+	public function getServerExtList()
923
+	{
924
+		return $this->server_caps;
925
+	}
926
+
927
+	/**
928
+	 * A multipurpose method
929
+	 * The method works in three ways, dependent on argument value and current state
930
+	 *   1. HELO/EHLO was not sent - returns null and set up $this->error
931
+	 *   2. HELO was sent
932
+	 *     $name = 'HELO': returns server name
933
+	 *     $name = 'EHLO': returns boolean false
934
+	 *     $name = any string: returns null and set up $this->error
935
+	 *   3. EHLO was sent
936
+	 *     $name = 'HELO'|'EHLO': returns server name
937
+	 *     $name = any string: if extension $name exists, returns boolean True
938
+	 *       or its options. Otherwise returns boolean False
939
+	 * In other words, one can use this method to detect 3 conditions:
940
+	 *  - null returned: handshake was not or we don't know about ext (refer to $this->error)
941
+	 *  - false returned: the requested feature exactly not exists
942
+	 *  - positive value returned: the requested feature exists
943
+	 * @param string $name Name of SMTP extension or 'HELO'|'EHLO'
944
+	 * @return mixed
945
+	 */
946
+	public function getServerExt($name)
947
+	{
948
+		if (!$this->server_caps) {
949
+			$this->setError('No HELO/EHLO was sent');
950
+			return null;
951
+		}
952
+
953
+		// the tight logic knot ;)
954
+		if (!array_key_exists($name, $this->server_caps)) {
955
+			if ($name == 'HELO') {
956
+				return $this->server_caps['EHLO'];
957
+			}
958
+			if ($name == 'EHLO' || array_key_exists('EHLO', $this->server_caps)) {
959
+				return false;
960
+			}
961
+			$this->setError('HELO handshake was used. Client knows nothing about server extensions');
962
+			return null;
963
+		}
964
+
965
+		return $this->server_caps[$name];
966
+	}
967
+
968
+	/**
969
+	 * Get the last reply from the server.
970
+	 * @access public
971
+	 * @return string
972
+	 */
973
+	public function getLastReply()
974
+	{
975
+		return $this->last_reply;
976
+	}
977
+
978
+	/**
979
+	 * Read the SMTP server's response.
980
+	 * Either before eof or socket timeout occurs on the operation.
981
+	 * With SMTP we can tell if we have more lines to read if the
982
+	 * 4th character is '-' symbol. If it is a space then we don't
983
+	 * need to read anything else.
984
+	 * @access protected
985
+	 * @return string
986
+	 */
987
+	protected function get_lines()
988
+	{
989
+		// If the connection is bad, give up straight away
990
+		if (!is_resource($this->smtp_conn)) {
991
+			return '';
992
+		}
993
+		$data = '';
994
+		$endtime = 0;
995
+		stream_set_timeout($this->smtp_conn, $this->Timeout);
996
+		if ($this->Timelimit > 0) {
997
+			$endtime = time() + $this->Timelimit;
998
+		}
999
+		while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
1000
+			$str = @fgets($this->smtp_conn, 515);
1001
+			$this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL);
1002
+			$this->edebug("SMTP -> get_lines(): \$str is  \"$str\"", self::DEBUG_LOWLEVEL);
1003
+			$data .= $str;
1004
+			// If 4th character is a space, we are done reading, break the loop, micro-optimisation over strlen
1005
+			if ((isset($str[3]) and $str[3] == ' ')) {
1006
+				break;
1007
+			}
1008
+			// Timed-out? Log and break
1009
+			$info = stream_get_meta_data($this->smtp_conn);
1010
+			if ($info['timed_out']) {
1011
+				$this->edebug(
1012
+					'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)',
1013
+					self::DEBUG_LOWLEVEL
1014
+				);
1015
+				break;
1016
+			}
1017
+			// Now check if reads took too long
1018
+			if ($endtime and time() > $endtime) {
1019
+				$this->edebug(
1020
+					'SMTP -> get_lines(): timelimit reached ('.
1021
+					$this->Timelimit . ' sec)',
1022
+					self::DEBUG_LOWLEVEL
1023
+				);
1024
+				break;
1025
+			}
1026
+		}
1027
+		return $data;
1028
+	}
1029
+
1030
+	/**
1031
+	 * Enable or disable VERP address generation.
1032
+	 * @param boolean $enabled
1033
+	 */
1034
+	public function setVerp($enabled = false)
1035
+	{
1036
+		$this->do_verp = $enabled;
1037
+	}
1038
+
1039
+	/**
1040
+	 * Get VERP address generation mode.
1041
+	 * @return boolean
1042
+	 */
1043
+	public function getVerp()
1044
+	{
1045
+		return $this->do_verp;
1046
+	}
1047
+
1048
+	/**
1049
+	 * Set error messages and codes.
1050
+	 * @param string $message The error message
1051
+	 * @param string $detail Further detail on the error
1052
+	 * @param string $smtp_code An associated SMTP error code
1053
+	 * @param string $smtp_code_ex Extended SMTP code
1054
+	 */
1055
+	protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '')
1056
+	{
1057
+		$this->error = array(
1058
+			'error' => $message,
1059
+			'detail' => $detail,
1060
+			'smtp_code' => $smtp_code,
1061
+			'smtp_code_ex' => $smtp_code_ex
1062
+		);
1063
+	}
1064
+
1065
+	/**
1066
+	 * Set debug output method.
1067
+	 * @param string|callable $method The name of the mechanism to use for debugging output, or a callable to handle it.
1068
+	 */
1069
+	public function setDebugOutput($method = 'echo')
1070
+	{
1071
+		$this->Debugoutput = $method;
1072
+	}
1073
+
1074
+	/**
1075
+	 * Get debug output method.
1076
+	 * @return string
1077
+	 */
1078
+	public function getDebugOutput()
1079
+	{
1080
+		return $this->Debugoutput;
1081
+	}
1082
+
1083
+	/**
1084
+	 * Set debug output level.
1085
+	 * @param integer $level
1086
+	 */
1087
+	public function setDebugLevel($level = 0)
1088
+	{
1089
+		$this->do_debug = $level;
1090
+	}
1091
+
1092
+	/**
1093
+	 * Get debug output level.
1094
+	 * @return integer
1095
+	 */
1096
+	public function getDebugLevel()
1097
+	{
1098
+		return $this->do_debug;
1099
+	}
1100
+
1101
+	/**
1102
+	 * Set SMTP timeout.
1103
+	 * @param integer $timeout
1104
+	 */
1105
+	public function setTimeout($timeout = 0)
1106
+	{
1107
+		$this->Timeout = $timeout;
1108
+	}
1109
+
1110
+	/**
1111
+	 * Get SMTP timeout.
1112
+	 * @return integer
1113
+	 */
1114
+	public function getTimeout()
1115
+	{
1116
+		return $this->Timeout;
1117
+	}
1118 1118
 }
Please login to merge, or discard this patch.
src/wp-includes/class-snoopy.php 4 patches
Doc Comments   +10 added lines patch added patch discarded remove patch
@@ -781,6 +781,9 @@  discard block
 block discarded – undo
781 781
 	Output:
782 782
 \*======================================================================*/
783 783
 
784
+	/**
785
+	 * @param string $http_method
786
+	 */
784 787
 	function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="")
785 788
 	{
786 789
 		$cookie_headers = '';
@@ -944,6 +947,9 @@  discard block
 block discarded – undo
944 947
 	Output:
945 948
 \*======================================================================*/
946 949
 
950
+	/**
951
+	 * @param string $http_method
952
+	 */
947 953
 	function _httpsrequest($url,$URI,$http_method,$content_type="",$body="")
948 954
 	{
949 955
 		if($this->passcookies && $this->_redirectaddr)
@@ -1189,6 +1195,10 @@  discard block
 block discarded – undo
1189 1195
 	Output:		post body
1190 1196
 \*======================================================================*/
1191 1197
 
1198
+	/**
1199
+	 * @param string $formvars
1200
+	 * @param string $formfiles
1201
+	 */
1192 1202
 	function _prepare_post_body($formvars, $formfiles)
1193 1203
 	{
1194 1204
 		settype($formvars, "array");
Please login to merge, or discard this patch.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -205,8 +205,8 @@  discard block
 block discarded – undo
205 205
 				if(!$this->curl_path)
206 206
 					return false;
207 207
 				if(function_exists("is_executable"))
208
-				    if (!is_executable($this->curl_path))
209
-				        return false;
208
+					if (!is_executable($this->curl_path))
209
+						return false;
210 210
 				$this->host = $URI_PARTS["host"];
211 211
 				if(!empty($URI_PARTS["port"]))
212 212
 					$this->port = $URI_PARTS["port"];
@@ -364,8 +364,8 @@  discard block
 block discarded – undo
364 364
 				if(!$this->curl_path)
365 365
 					return false;
366 366
 				if(function_exists("is_executable"))
367
-				    if (!is_executable($this->curl_path))
368
-				        return false;
367
+					if (!is_executable($this->curl_path))
368
+						return false;
369 369
 				$this->host = $URI_PARTS["host"];
370 370
 				if(!empty($URI_PARTS["port"]))
371 371
 					$this->port = $URI_PARTS["port"];
@@ -885,10 +885,10 @@  discard block
 block discarded – undo
885 885
 
886 886
 			if(preg_match("|^HTTP/|",$currentHeader))
887 887
 			{
888
-                if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status))
888
+				if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status))
889 889
 				{
890 890
 					$this->status= $status[1];
891
-                }
891
+				}
892 892
 				$this->response_code = $currentHeader;
893 893
 			}
894 894
 
@@ -897,11 +897,11 @@  discard block
 block discarded – undo
897 897
 
898 898
 		$results = '';
899 899
 		do {
900
-    		$_data = fread($fp, $this->maxlength);
901
-    		if (strlen($_data) == 0) {
902
-        		break;
903
-    		}
904
-    		$results .= $_data;
900
+			$_data = fread($fp, $this->maxlength);
901
+			if (strlen($_data) == 0) {
902
+				break;
903
+			}
904
+			$results .= $_data;
905 905
 		} while(true);
906 906
 
907 907
 		if ($this->read_timeout > 0 && $this->_check_timeout($fp))
Please login to merge, or discard this patch.
Spacing   +254 added lines, -254 removed lines patch added patch discarded remove patch
@@ -3,9 +3,9 @@  discard block
 block discarded – undo
3 3
 /**
4 4
  * Deprecated. Use WP_HTTP (http.php) instead.
5 5
  */
6
-_deprecated_file( basename( __FILE__ ), '3.0', WPINC . '/http.php' );
6
+_deprecated_file(basename(__FILE__), '3.0', WPINC.'/http.php');
7 7
 
8
-if ( ! class_exists( 'Snoopy', false ) ) :
8
+if ( ! class_exists('Snoopy', false)) :
9 9
 /*************************************************
10 10
 
11 11
 Snoopy - the PHP net client
@@ -41,54 +41,54 @@  discard block
 block discarded – undo
41 41
 
42 42
 	/* user definable vars */
43 43
 
44
-	var $host			=	"www.php.net";		// host name we are connecting to
45
-	var $port			=	80;					// port we are connecting to
46
-	var $proxy_host		=	"";					// proxy host to use
47
-	var $proxy_port		=	"";					// proxy port to use
48
-	var $proxy_user		=	"";					// proxy user to use
49
-	var $proxy_pass		=	"";					// proxy password to use
44
+	var $host			= "www.php.net"; // host name we are connecting to
45
+	var $port			= 80; // port we are connecting to
46
+	var $proxy_host		= ""; // proxy host to use
47
+	var $proxy_port		= ""; // proxy port to use
48
+	var $proxy_user		= ""; // proxy user to use
49
+	var $proxy_pass		= ""; // proxy password to use
50 50
 
51
-	var $agent			=	"Snoopy v1.2.4";	// agent we masquerade as
52
-	var	$referer		=	"";					// referer info to pass
53
-	var $cookies		=	array();			// array of cookies to pass
51
+	var $agent = "Snoopy v1.2.4"; // agent we masquerade as
52
+	var	$referer		= ""; // referer info to pass
53
+	var $cookies		= array(); // array of cookies to pass
54 54
 												// $cookies["username"]="joe";
55
-	var	$rawheaders		=	array();			// array of raw headers to send
55
+	var	$rawheaders = array(); // array of raw headers to send
56 56
 												// $rawheaders["Content-type"]="text/html";
57 57
 
58
-	var $maxredirs		=	5;					// http redirection depth maximum. 0 = disallow
59
-	var $lastredirectaddr	=	"";				// contains address of last redirected address
60
-	var	$offsiteok		=	true;				// allows redirection off-site
61
-	var $maxframes		=	0;					// frame content depth maximum. 0 = disallow
62
-	var $expandlinks	=	true;				// expand links to fully qualified URLs.
58
+	var $maxredirs		= 5; // http redirection depth maximum. 0 = disallow
59
+	var $lastredirectaddr = ""; // contains address of last redirected address
60
+	var	$offsiteok		= true; // allows redirection off-site
61
+	var $maxframes		= 0; // frame content depth maximum. 0 = disallow
62
+	var $expandlinks	= true; // expand links to fully qualified URLs.
63 63
 												// this only applies to fetchlinks()
64 64
 												// submitlinks(), and submittext()
65
-	var $passcookies	=	true;				// pass set cookies back through redirects
65
+	var $passcookies	= true; // pass set cookies back through redirects
66 66
 												// NOTE: this currently does not respect
67 67
 												// dates, domains or paths.
68 68
 
69
-	var	$user			=	"";					// user for http authentication
70
-	var	$pass			=	"";					// password for http authentication
69
+	var	$user			= ""; // user for http authentication
70
+	var	$pass			= ""; // password for http authentication
71 71
 
72 72
 	// http accept types
73
-	var $accept			=	"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
73
+	var $accept			= "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
74 74
 
75
-	var $results		=	"";					// where the content is put
75
+	var $results		= ""; // where the content is put
76 76
 
77
-	var $error			=	"";					// error messages sent here
78
-	var	$response_code	=	"";					// response code returned from server
79
-	var	$headers		=	array();			// headers returned from server sent here
80
-	var	$maxlength		=	500000;				// max return data length (body)
81
-	var $read_timeout	=	0;					// timeout on read operations, in seconds
77
+	var $error = ""; // error messages sent here
78
+	var	$response_code = ""; // response code returned from server
79
+	var	$headers = array(); // headers returned from server sent here
80
+	var	$maxlength = 500000; // max return data length (body)
81
+	var $read_timeout = 0; // timeout on read operations, in seconds
82 82
 												// supported only since PHP 4 Beta 4
83 83
 												// set to 0 to disallow timeouts
84
-	var $timed_out		=	false;				// if a read operation timed out
85
-	var	$status			=	0;					// http request status
84
+	var $timed_out = false; // if a read operation timed out
85
+	var	$status = 0; // http request status
86 86
 
87
-	var $temp_dir		=	"/tmp";				// temporary directory that the webserver
87
+	var $temp_dir = "/tmp"; // temporary directory that the webserver
88 88
 												// has permission to write to.
89 89
 												// under Windows, this should be C:\temp
90 90
 
91
-	var	$curl_path		=	"/usr/local/bin/curl";
91
+	var	$curl_path = "/usr/local/bin/curl";
92 92
 												// Snoopy will use cURL for fetching
93 93
 												// SSL content if a full system path to
94 94
 												// the cURL binary is supplied here.
@@ -102,20 +102,20 @@  discard block
 block discarded – undo
102 102
 
103 103
 	/**** Private variables ****/
104 104
 
105
-	var	$_maxlinelen	=	4096;				// max line length (headers)
105
+	var	$_maxlinelen	= 4096; // max line length (headers)
106 106
 
107
-	var $_httpmethod	=	"GET";				// default http request method
108
-	var $_httpversion	=	"HTTP/1.0";			// default http request version
109
-	var $_submit_method	=	"POST";				// default submit method
110
-	var $_submit_type	=	"application/x-www-form-urlencoded";	// default submit type
111
-	var $_mime_boundary	=   "";					// MIME boundary for multipart/form-data submit type
112
-	var $_redirectaddr	=	false;				// will be set if page fetched is a redirect
113
-	var $_redirectdepth	=	0;					// increments on an http redirect
114
-	var $_frameurls		= 	array();			// frame src urls
115
-	var $_framedepth	=	0;					// increments on frame depth
107
+	var $_httpmethod	= "GET"; // default http request method
108
+	var $_httpversion	= "HTTP/1.0"; // default http request version
109
+	var $_submit_method	= "POST"; // default submit method
110
+	var $_submit_type	= "application/x-www-form-urlencoded"; // default submit type
111
+	var $_mime_boundary	= ""; // MIME boundary for multipart/form-data submit type
112
+	var $_redirectaddr = false; // will be set if page fetched is a redirect
113
+	var $_redirectdepth	= 0; // increments on an http redirect
114
+	var $_frameurls		= array(); // frame src urls
115
+	var $_framedepth	= 0; // increments on frame depth
116 116
 
117
-	var $_isproxy		=	false;				// set if using a proxy server
118
-	var $_fp_timeout	=	30;					// timeout for socket connection
117
+	var $_isproxy = false; // set if using a proxy server
118
+	var $_fp_timeout	= 30; // timeout for socket connection
119 119
 
120 120
 /*======================================================================*\
121 121
 	Function:	fetch
@@ -131,27 +131,27 @@  discard block
 block discarded – undo
131 131
 
132 132
 		//preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS);
133 133
 		$URI_PARTS = parse_url($URI);
134
-		if (!empty($URI_PARTS["user"]))
134
+		if ( ! empty($URI_PARTS["user"]))
135 135
 			$this->user = $URI_PARTS["user"];
136
-		if (!empty($URI_PARTS["pass"]))
136
+		if ( ! empty($URI_PARTS["pass"]))
137 137
 			$this->pass = $URI_PARTS["pass"];
138 138
 		if (empty($URI_PARTS["query"]))
139 139
 			$URI_PARTS["query"] = '';
140 140
 		if (empty($URI_PARTS["path"]))
141 141
 			$URI_PARTS["path"] = '';
142 142
 
143
-		switch(strtolower($URI_PARTS["scheme"]))
143
+		switch (strtolower($URI_PARTS["scheme"]))
144 144
 		{
145 145
 			case "http":
146 146
 				$this->host = $URI_PARTS["host"];
147
-				if(!empty($URI_PARTS["port"]))
147
+				if ( ! empty($URI_PARTS["port"]))
148 148
 					$this->port = $URI_PARTS["port"];
149
-				if($this->_connect($fp))
149
+				if ($this->_connect($fp))
150 150
 				{
151
-					if($this->_isproxy)
151
+					if ($this->_isproxy)
152 152
 					{
153 153
 						// using proxy, send entire URI
154
-						$this->_httprequest($URI,$fp,$URI,$this->_httpmethod);
154
+						$this->_httprequest($URI, $fp, $URI, $this->_httpmethod);
155 155
 					}
156 156
 					else
157 157
 					{
@@ -162,30 +162,30 @@  discard block
 block discarded – undo
162 162
 
163 163
 					$this->_disconnect($fp);
164 164
 
165
-					if($this->_redirectaddr)
165
+					if ($this->_redirectaddr)
166 166
 					{
167 167
 						/* url was redirected, check if we've hit the max depth */
168
-						if($this->maxredirs > $this->_redirectdepth)
168
+						if ($this->maxredirs > $this->_redirectdepth)
169 169
 						{
170 170
 							// only follow redirect if it's on this site, or offsiteok is true
171
-							if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
171
+							if (preg_match("|^http://".preg_quote($this->host)."|i", $this->_redirectaddr) || $this->offsiteok)
172 172
 							{
173 173
 								/* follow the redirect */
174 174
 								$this->_redirectdepth++;
175
-								$this->lastredirectaddr=$this->_redirectaddr;
175
+								$this->lastredirectaddr = $this->_redirectaddr;
176 176
 								$this->fetch($this->_redirectaddr);
177 177
 							}
178 178
 						}
179 179
 					}
180 180
 
181
-					if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
181
+					if ($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
182 182
 					{
183 183
 						$frameurls = $this->_frameurls;
184 184
 						$this->_frameurls = array();
185 185
 
186
-						while(list(,$frameurl) = each($frameurls))
186
+						while (list(,$frameurl) = each($frameurls))
187 187
 						{
188
-							if($this->_framedepth < $this->maxframes)
188
+							if ($this->_framedepth < $this->maxframes)
189 189
 							{
190 190
 								$this->fetch($frameurl);
191 191
 								$this->_framedepth++;
@@ -202,18 +202,18 @@  discard block
 block discarded – undo
202 202
 				return true;
203 203
 				break;
204 204
 			case "https":
205
-				if(!$this->curl_path)
205
+				if ( ! $this->curl_path)
206 206
 					return false;
207
-				if(function_exists("is_executable"))
208
-				    if (!is_executable($this->curl_path))
207
+				if (function_exists("is_executable"))
208
+				    if ( ! is_executable($this->curl_path))
209 209
 				        return false;
210 210
 				$this->host = $URI_PARTS["host"];
211
-				if(!empty($URI_PARTS["port"]))
211
+				if ( ! empty($URI_PARTS["port"]))
212 212
 					$this->port = $URI_PARTS["port"];
213
-				if($this->_isproxy)
213
+				if ($this->_isproxy)
214 214
 				{
215 215
 					// using proxy, send entire URI
216
-					$this->_httpsrequest($URI,$URI,$this->_httpmethod);
216
+					$this->_httpsrequest($URI, $URI, $this->_httpmethod);
217 217
 				}
218 218
 				else
219 219
 				{
@@ -222,30 +222,30 @@  discard block
 block discarded – undo
222 222
 					$this->_httpsrequest($path, $URI, $this->_httpmethod);
223 223
 				}
224 224
 
225
-				if($this->_redirectaddr)
225
+				if ($this->_redirectaddr)
226 226
 				{
227 227
 					/* url was redirected, check if we've hit the max depth */
228
-					if($this->maxredirs > $this->_redirectdepth)
228
+					if ($this->maxredirs > $this->_redirectdepth)
229 229
 					{
230 230
 						// only follow redirect if it's on this site, or offsiteok is true
231
-						if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
231
+						if (preg_match("|^http://".preg_quote($this->host)."|i", $this->_redirectaddr) || $this->offsiteok)
232 232
 						{
233 233
 							/* follow the redirect */
234 234
 							$this->_redirectdepth++;
235
-							$this->lastredirectaddr=$this->_redirectaddr;
235
+							$this->lastredirectaddr = $this->_redirectaddr;
236 236
 							$this->fetch($this->_redirectaddr);
237 237
 						}
238 238
 					}
239 239
 				}
240 240
 
241
-				if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
241
+				if ($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
242 242
 				{
243 243
 					$frameurls = $this->_frameurls;
244 244
 					$this->_frameurls = array();
245 245
 
246
-					while(list(,$frameurl) = each($frameurls))
246
+					while (list(,$frameurl) = each($frameurls))
247 247
 					{
248
-						if($this->_framedepth < $this->maxframes)
248
+						if ($this->_framedepth < $this->maxframes)
249 249
 						{
250 250
 							$this->fetch($frameurl);
251 251
 							$this->_framedepth++;
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 				break;
259 259
 			default:
260 260
 				// not a valid protocol
261
-				$this->error	=	'Invalid protocol "'.$URI_PARTS["scheme"].'"\n';
261
+				$this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n';
262 262
 				return false;
263 263
 				break;
264 264
 		}
@@ -276,34 +276,34 @@  discard block
 block discarded – undo
276 276
 	Output:		$this->results	the text output from the post
277 277
 \*======================================================================*/
278 278
 
279
-	function submit($URI, $formvars="", $formfiles="")
279
+	function submit($URI, $formvars = "", $formfiles = "")
280 280
 	{
281 281
 		unset($postdata);
282 282
 
283 283
 		$postdata = $this->_prepare_post_body($formvars, $formfiles);
284 284
 
285 285
 		$URI_PARTS = parse_url($URI);
286
-		if (!empty($URI_PARTS["user"]))
286
+		if ( ! empty($URI_PARTS["user"]))
287 287
 			$this->user = $URI_PARTS["user"];
288
-		if (!empty($URI_PARTS["pass"]))
288
+		if ( ! empty($URI_PARTS["pass"]))
289 289
 			$this->pass = $URI_PARTS["pass"];
290 290
 		if (empty($URI_PARTS["query"]))
291 291
 			$URI_PARTS["query"] = '';
292 292
 		if (empty($URI_PARTS["path"]))
293 293
 			$URI_PARTS["path"] = '';
294 294
 
295
-		switch(strtolower($URI_PARTS["scheme"]))
295
+		switch (strtolower($URI_PARTS["scheme"]))
296 296
 		{
297 297
 			case "http":
298 298
 				$this->host = $URI_PARTS["host"];
299
-				if(!empty($URI_PARTS["port"]))
299
+				if ( ! empty($URI_PARTS["port"]))
300 300
 					$this->port = $URI_PARTS["port"];
301
-				if($this->_connect($fp))
301
+				if ($this->_connect($fp))
302 302
 				{
303
-					if($this->_isproxy)
303
+					if ($this->_isproxy)
304 304
 					{
305 305
 						// using proxy, send entire URI
306
-						$this->_httprequest($URI,$fp,$URI,$this->_submit_method,$this->_submit_type,$postdata);
306
+						$this->_httprequest($URI, $fp, $URI, $this->_submit_method, $this->_submit_type, $postdata);
307 307
 					}
308 308
 					else
309 309
 					{
@@ -314,36 +314,36 @@  discard block
 block discarded – undo
314 314
 
315 315
 					$this->_disconnect($fp);
316 316
 
317
-					if($this->_redirectaddr)
317
+					if ($this->_redirectaddr)
318 318
 					{
319 319
 						/* url was redirected, check if we've hit the max depth */
320
-						if($this->maxredirs > $this->_redirectdepth)
320
+						if ($this->maxredirs > $this->_redirectdepth)
321 321
 						{
322
-							if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr))
323
-								$this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]);
322
+							if ( ! preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr))
323
+								$this->_redirectaddr = $this->_expandlinks($this->_redirectaddr, $URI_PARTS["scheme"]."://".$URI_PARTS["host"]);
324 324
 
325 325
 							// only follow redirect if it's on this site, or offsiteok is true
326
-							if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
326
+							if (preg_match("|^http://".preg_quote($this->host)."|i", $this->_redirectaddr) || $this->offsiteok)
327 327
 							{
328 328
 								/* follow the redirect */
329 329
 								$this->_redirectdepth++;
330
-								$this->lastredirectaddr=$this->_redirectaddr;
331
-								if( strpos( $this->_redirectaddr, "?" ) > 0 )
330
+								$this->lastredirectaddr = $this->_redirectaddr;
331
+								if (strpos($this->_redirectaddr, "?") > 0)
332 332
 									$this->fetch($this->_redirectaddr); // the redirect has changed the request method from post to get
333 333
 								else
334
-									$this->submit($this->_redirectaddr,$formvars, $formfiles);
334
+									$this->submit($this->_redirectaddr, $formvars, $formfiles);
335 335
 							}
336 336
 						}
337 337
 					}
338 338
 
339
-					if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
339
+					if ($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
340 340
 					{
341 341
 						$frameurls = $this->_frameurls;
342 342
 						$this->_frameurls = array();
343 343
 
344
-						while(list(,$frameurl) = each($frameurls))
344
+						while (list(,$frameurl) = each($frameurls))
345 345
 						{
346
-							if($this->_framedepth < $this->maxframes)
346
+							if ($this->_framedepth < $this->maxframes)
347 347
 							{
348 348
 								$this->fetch($frameurl);
349 349
 								$this->_framedepth++;
@@ -361,15 +361,15 @@  discard block
 block discarded – undo
361 361
 				return true;
362 362
 				break;
363 363
 			case "https":
364
-				if(!$this->curl_path)
364
+				if ( ! $this->curl_path)
365 365
 					return false;
366
-				if(function_exists("is_executable"))
367
-				    if (!is_executable($this->curl_path))
366
+				if (function_exists("is_executable"))
367
+				    if ( ! is_executable($this->curl_path))
368 368
 				        return false;
369 369
 				$this->host = $URI_PARTS["host"];
370
-				if(!empty($URI_PARTS["port"]))
370
+				if ( ! empty($URI_PARTS["port"]))
371 371
 					$this->port = $URI_PARTS["port"];
372
-				if($this->_isproxy)
372
+				if ($this->_isproxy)
373 373
 				{
374 374
 					// using proxy, send entire URI
375 375
 					$this->_httpsrequest($URI, $URI, $this->_submit_method, $this->_submit_type, $postdata);
@@ -381,36 +381,36 @@  discard block
 block discarded – undo
381 381
 					$this->_httpsrequest($path, $URI, $this->_submit_method, $this->_submit_type, $postdata);
382 382
 				}
383 383
 
384
-				if($this->_redirectaddr)
384
+				if ($this->_redirectaddr)
385 385
 				{
386 386
 					/* url was redirected, check if we've hit the max depth */
387
-					if($this->maxredirs > $this->_redirectdepth)
387
+					if ($this->maxredirs > $this->_redirectdepth)
388 388
 					{
389
-						if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr))
390
-							$this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]);
389
+						if ( ! preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr))
390
+							$this->_redirectaddr = $this->_expandlinks($this->_redirectaddr, $URI_PARTS["scheme"]."://".$URI_PARTS["host"]);
391 391
 
392 392
 						// only follow redirect if it's on this site, or offsiteok is true
393
-						if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
393
+						if (preg_match("|^http://".preg_quote($this->host)."|i", $this->_redirectaddr) || $this->offsiteok)
394 394
 						{
395 395
 							/* follow the redirect */
396 396
 							$this->_redirectdepth++;
397
-							$this->lastredirectaddr=$this->_redirectaddr;
398
-							if( strpos( $this->_redirectaddr, "?" ) > 0 )
397
+							$this->lastredirectaddr = $this->_redirectaddr;
398
+							if (strpos($this->_redirectaddr, "?") > 0)
399 399
 								$this->fetch($this->_redirectaddr); // the redirect has changed the request method from post to get
400 400
 							else
401
-								$this->submit($this->_redirectaddr,$formvars, $formfiles);
401
+								$this->submit($this->_redirectaddr, $formvars, $formfiles);
402 402
 						}
403 403
 					}
404 404
 				}
405 405
 
406
-				if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
406
+				if ($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
407 407
 				{
408 408
 					$frameurls = $this->_frameurls;
409 409
 					$this->_frameurls = array();
410 410
 
411
-					while(list(,$frameurl) = each($frameurls))
411
+					while (list(,$frameurl) = each($frameurls))
412 412
 					{
413
-						if($this->_framedepth < $this->maxframes)
413
+						if ($this->_framedepth < $this->maxframes)
414 414
 						{
415 415
 							$this->fetch($frameurl);
416 416
 							$this->_framedepth++;
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
 
425 425
 			default:
426 426
 				// not a valid protocol
427
-				$this->error	=	'Invalid protocol "'.$URI_PARTS["scheme"].'"\n';
427
+				$this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n';
428 428
 				return false;
429 429
 				break;
430 430
 		}
@@ -442,17 +442,17 @@  discard block
 block discarded – undo
442 442
 	{
443 443
 		if ($this->fetch($URI))
444 444
 		{
445
-			if($this->lastredirectaddr)
445
+			if ($this->lastredirectaddr)
446 446
 				$URI = $this->lastredirectaddr;
447
-			if(is_array($this->results))
447
+			if (is_array($this->results))
448 448
 			{
449
-				for($x=0;$x<count($this->results);$x++)
449
+				for ($x = 0; $x < count($this->results); $x++)
450 450
 					$this->results[$x] = $this->_striplinks($this->results[$x]);
451 451
 			}
452 452
 			else
453 453
 				$this->results = $this->_striplinks($this->results);
454 454
 
455
-			if($this->expandlinks)
455
+			if ($this->expandlinks)
456 456
 				$this->results = $this->_expandlinks($this->results, $URI);
457 457
 			return true;
458 458
 		}
@@ -473,9 +473,9 @@  discard block
 block discarded – undo
473 473
 		if ($this->fetch($URI))
474 474
 		{
475 475
 
476
-			if(is_array($this->results))
476
+			if (is_array($this->results))
477 477
 			{
478
-				for($x=0;$x<count($this->results);$x++)
478
+				for ($x = 0; $x < count($this->results); $x++)
479 479
 					$this->results[$x] = $this->_stripform($this->results[$x]);
480 480
 			}
481 481
 			else
@@ -497,11 +497,11 @@  discard block
 block discarded – undo
497 497
 
498 498
 	function fetchtext($URI)
499 499
 	{
500
-		if($this->fetch($URI))
500
+		if ($this->fetch($URI))
501 501
 		{
502
-			if(is_array($this->results))
502
+			if (is_array($this->results))
503 503
 			{
504
-				for($x=0;$x<count($this->results);$x++)
504
+				for ($x = 0; $x < count($this->results); $x++)
505 505
 					$this->results[$x] = $this->_striptext($this->results[$x]);
506 506
 			}
507 507
 			else
@@ -519,26 +519,26 @@  discard block
 block discarded – undo
519 519
 	Output:		$this->results	an array of the links from the post
520 520
 \*======================================================================*/
521 521
 
522
-	function submitlinks($URI, $formvars="", $formfiles="")
522
+	function submitlinks($URI, $formvars = "", $formfiles = "")
523 523
 	{
524
-		if($this->submit($URI,$formvars, $formfiles))
524
+		if ($this->submit($URI, $formvars, $formfiles))
525 525
 		{
526
-			if($this->lastredirectaddr)
526
+			if ($this->lastredirectaddr)
527 527
 				$URI = $this->lastredirectaddr;
528
-			if(is_array($this->results))
528
+			if (is_array($this->results))
529 529
 			{
530
-				for($x=0;$x<count($this->results);$x++)
530
+				for ($x = 0; $x < count($this->results); $x++)
531 531
 				{
532 532
 					$this->results[$x] = $this->_striplinks($this->results[$x]);
533
-					if($this->expandlinks)
534
-						$this->results[$x] = $this->_expandlinks($this->results[$x],$URI);
533
+					if ($this->expandlinks)
534
+						$this->results[$x] = $this->_expandlinks($this->results[$x], $URI);
535 535
 				}
536 536
 			}
537 537
 			else
538 538
 			{
539 539
 				$this->results = $this->_striplinks($this->results);
540
-				if($this->expandlinks)
541
-					$this->results = $this->_expandlinks($this->results,$URI);
540
+				if ($this->expandlinks)
541
+					$this->results = $this->_expandlinks($this->results, $URI);
542 542
 			}
543 543
 			return true;
544 544
 		}
@@ -555,24 +555,24 @@  discard block
 block discarded – undo
555 555
 
556 556
 	function submittext($URI, $formvars = "", $formfiles = "")
557 557
 	{
558
-		if($this->submit($URI,$formvars, $formfiles))
558
+		if ($this->submit($URI, $formvars, $formfiles))
559 559
 		{
560
-			if($this->lastredirectaddr)
560
+			if ($this->lastredirectaddr)
561 561
 				$URI = $this->lastredirectaddr;
562
-			if(is_array($this->results))
562
+			if (is_array($this->results))
563 563
 			{
564
-				for($x=0;$x<count($this->results);$x++)
564
+				for ($x = 0; $x < count($this->results); $x++)
565 565
 				{
566 566
 					$this->results[$x] = $this->_striptext($this->results[$x]);
567
-					if($this->expandlinks)
568
-						$this->results[$x] = $this->_expandlinks($this->results[$x],$URI);
567
+					if ($this->expandlinks)
568
+						$this->results[$x] = $this->_expandlinks($this->results[$x], $URI);
569 569
 				}
570 570
 			}
571 571
 			else
572 572
 			{
573 573
 				$this->results = $this->_striptext($this->results);
574
-				if($this->expandlinks)
575
-					$this->results = $this->_expandlinks($this->results,$URI);
574
+				if ($this->expandlinks)
575
+					$this->results = $this->_expandlinks($this->results, $URI);
576 576
 			}
577 577
 			return true;
578 578
 		}
@@ -624,20 +624,20 @@  discard block
 block discarded – undo
624 624
 						([\"\'])?					# find single or double quote
625 625
 						(?(1) (.*?)\\1 | ([^\s\>]+))		# if quote found, match up to next matching
626 626
 													# quote, otherwise match up to next space
627
-						'isx",$document,$links);
627
+						'isx",$document, $links);
628 628
 
629 629
 
630 630
 		// catenate the non-empty matches from the conditional subpattern
631 631
 
632
-		while(list($key,$val) = each($links[2]))
632
+		while (list($key, $val) = each($links[2]))
633 633
 		{
634
-			if(!empty($val))
634
+			if ( ! empty($val))
635 635
 				$match[] = $val;
636 636
 		}
637 637
 
638
-		while(list($key,$val) = each($links[3]))
638
+		while (list($key, $val) = each($links[3]))
639 639
 		{
640
-			if(!empty($val))
640
+			if ( ! empty($val))
641 641
 				$match[] = $val;
642 642
 		}
643 643
 
@@ -654,10 +654,10 @@  discard block
 block discarded – undo
654 654
 
655 655
 	function _stripform($document)
656 656
 	{
657
-		preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi",$document,$elements);
657
+		preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi", $document, $elements);
658 658
 
659 659
 		// catenate the matches
660
-		$match = implode("\r\n",$elements[0]);
660
+		$match = implode("\r\n", $elements[0]);
661 661
 
662 662
 		// return the links
663 663
 		return $match;
@@ -679,11 +679,11 @@  discard block
 block discarded – undo
679 679
 		// so, list your entities one by one here. I included some of the
680 680
 		// more common ones.
681 681
 
682
-		$search = array("'<script[^>]*?>.*?</script>'si",	// strip out javascript
683
-						"'<[\/\!]*?[^<>]*?>'si",			// strip out html tags
684
-						"'([\r\n])[\s]+'",					// strip out white space
685
-						"'&(quot|#34|#034|#x22);'i",		// replace html entities
686
-						"'&(amp|#38|#038|#x26);'i",			// added hexadecimal values
682
+		$search = array("'<script[^>]*?>.*?</script>'si", // strip out javascript
683
+						"'<[\/\!]*?[^<>]*?>'si", // strip out html tags
684
+						"'([\r\n])[\s]+'", // strip out white space
685
+						"'&(quot|#34|#034|#x22);'i", // replace html entities
686
+						"'&(amp|#38|#038|#x26);'i", // added hexadecimal values
687 687
 						"'&(lt|#60|#060|#x3c);'i",
688 688
 						"'&(gt|#62|#062|#x3e);'i",
689 689
 						"'&(nbsp|#160|#xa0);'i",
@@ -694,8 +694,8 @@  discard block
 block discarded – undo
694 694
 						"'&(reg|#174);'i",
695 695
 						"'&(deg|#176);'i",
696 696
 						"'&(#39|#039|#x27);'",
697
-						"'&(euro|#8364);'i",				// europe
698
-						"'&a(uml|UML);'",					// german
697
+						"'&(euro|#8364);'i", // europe
698
+						"'&a(uml|UML);'", // german
699 699
 						"'&o(uml|UML);'",
700 700
 						"'&u(uml|UML);'",
701 701
 						"'&A(uml|UML);'",
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 						"'&U(uml|UML);'",
704 704
 						"'&szlig;'i",
705 705
 						);
706
-		$replace = array(	"",
706
+		$replace = array("",
707 707
 							"",
708 708
 							"\\1",
709 709
 							"\"",
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
 							chr(0xDF), // ANSI &szlig;
729 729
 						);
730 730
 
731
-		$text = preg_replace($search,$replace,$document);
731
+		$text = preg_replace($search, $replace, $document);
732 732
 
733 733
 		return $text;
734 734
 	}
@@ -741,32 +741,32 @@  discard block
 block discarded – undo
741 741
 	Output:		$expandedLinks	the expanded links
742 742
 \*======================================================================*/
743 743
 
744
-	function _expandlinks($links,$URI)
744
+	function _expandlinks($links, $URI)
745 745
 	{
746 746
 
747
-		preg_match("/^[^\?]+/",$URI,$match);
747
+		preg_match("/^[^\?]+/", $URI, $match);
748 748
 
749
-		$match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]);
750
-		$match = preg_replace("|/$|","",$match);
749
+		$match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|", "", $match[0]);
750
+		$match = preg_replace("|/$|", "", $match);
751 751
 		$match_part = parse_url($match);
752 752
 		$match_root =
753 753
 		$match_part["scheme"]."://".$match_part["host"];
754 754
 
755
-		$search = array( 	"|^http://".preg_quote($this->host)."|i",
755
+		$search = array("|^http://".preg_quote($this->host)."|i",
756 756
 							"|^(\/)|i",
757 757
 							"|^(?!http://)(?!mailto:)|i",
758 758
 							"|/\./|",
759 759
 							"|/[^\/]+/\.\./|"
760 760
 						);
761 761
 
762
-		$replace = array(	"",
762
+		$replace = array("",
763 763
 							$match_root."/",
764 764
 							$match."/",
765 765
 							"/",
766 766
 							"/"
767 767
 						);
768 768
 
769
-		$expandedLinks = preg_replace($search,$replace,$links);
769
+		$expandedLinks = preg_replace($search, $replace, $links);
770 770
 
771 771
 		return $expandedLinks;
772 772
 	}
@@ -781,63 +781,63 @@  discard block
 block discarded – undo
781 781
 	Output:
782 782
 \*======================================================================*/
783 783
 
784
-	function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="")
784
+	function _httprequest($url, $fp, $URI, $http_method, $content_type = "", $body = "")
785 785
 	{
786 786
 		$cookie_headers = '';
787
-		if($this->passcookies && $this->_redirectaddr)
787
+		if ($this->passcookies && $this->_redirectaddr)
788 788
 			$this->setcookies();
789 789
 
790 790
 		$URI_PARTS = parse_url($URI);
791
-		if(empty($url))
791
+		if (empty($url))
792 792
 			$url = "/";
793 793
 		$headers = $http_method." ".$url." ".$this->_httpversion."\r\n";
794
-		if(!empty($this->agent))
794
+		if ( ! empty($this->agent))
795 795
 			$headers .= "User-Agent: ".$this->agent."\r\n";
796
-		if(!empty($this->host) && !isset($this->rawheaders['Host'])) {
796
+		if ( ! empty($this->host) && ! isset($this->rawheaders['Host'])) {
797 797
 			$headers .= "Host: ".$this->host;
798
-			if(!empty($this->port) && $this->port != 80)
798
+			if ( ! empty($this->port) && $this->port != 80)
799 799
 				$headers .= ":".$this->port;
800 800
 			$headers .= "\r\n";
801 801
 		}
802
-		if(!empty($this->accept))
802
+		if ( ! empty($this->accept))
803 803
 			$headers .= "Accept: ".$this->accept."\r\n";
804
-		if(!empty($this->referer))
804
+		if ( ! empty($this->referer))
805 805
 			$headers .= "Referer: ".$this->referer."\r\n";
806
-		if(!empty($this->cookies))
806
+		if ( ! empty($this->cookies))
807 807
 		{
808
-			if(!is_array($this->cookies))
809
-				$this->cookies = (array)$this->cookies;
808
+			if ( ! is_array($this->cookies))
809
+				$this->cookies = (array) $this->cookies;
810 810
 
811 811
 			reset($this->cookies);
812
-			if ( count($this->cookies) > 0 ) {
812
+			if (count($this->cookies) > 0) {
813 813
 				$cookie_headers .= 'Cookie: ';
814
-				foreach ( $this->cookies as $cookieKey => $cookieVal ) {
814
+				foreach ($this->cookies as $cookieKey => $cookieVal) {
815 815
 				$cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; ";
816 816
 				}
817
-				$headers .= substr($cookie_headers,0,-2) . "\r\n";
817
+				$headers .= substr($cookie_headers, 0, -2)."\r\n";
818 818
 			}
819 819
 		}
820
-		if(!empty($this->rawheaders))
820
+		if ( ! empty($this->rawheaders))
821 821
 		{
822
-			if(!is_array($this->rawheaders))
823
-				$this->rawheaders = (array)$this->rawheaders;
824
-			while(list($headerKey,$headerVal) = each($this->rawheaders))
822
+			if ( ! is_array($this->rawheaders))
823
+				$this->rawheaders = (array) $this->rawheaders;
824
+			while (list($headerKey, $headerVal) = each($this->rawheaders))
825 825
 				$headers .= $headerKey.": ".$headerVal."\r\n";
826 826
 		}
827
-		if(!empty($content_type)) {
827
+		if ( ! empty($content_type)) {
828 828
 			$headers .= "Content-type: $content_type";
829 829
 			if ($content_type == "multipart/form-data")
830 830
 				$headers .= "; boundary=".$this->_mime_boundary;
831 831
 			$headers .= "\r\n";
832 832
 		}
833
-		if(!empty($body))
833
+		if ( ! empty($body))
834 834
 			$headers .= "Content-length: ".strlen($body)."\r\n";
835
-		if(!empty($this->user) || !empty($this->pass))
835
+		if ( ! empty($this->user) || ! empty($this->pass))
836 836
 			$headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n";
837 837
 
838 838
 		//add proxy auth headers
839
-		if(!empty($this->proxy_user))
840
-			$headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass)."\r\n";
839
+		if ( ! empty($this->proxy_user))
840
+			$headers .= 'Proxy-Authorization: '.'Basic '.base64_encode($this->proxy_user.':'.$this->proxy_pass)."\r\n";
841 841
 
842 842
 
843 843
 		$headers .= "\r\n";
@@ -847,34 +847,34 @@  discard block
 block discarded – undo
847 847
 			socket_set_timeout($fp, $this->read_timeout);
848 848
 		$this->timed_out = false;
849 849
 
850
-		fwrite($fp,$headers.$body,strlen($headers.$body));
850
+		fwrite($fp, $headers.$body, strlen($headers.$body));
851 851
 
852 852
 		$this->_redirectaddr = false;
853 853
 		unset($this->headers);
854 854
 
855
-		while($currentHeader = fgets($fp,$this->_maxlinelen))
855
+		while ($currentHeader = fgets($fp, $this->_maxlinelen))
856 856
 		{
857 857
 			if ($this->read_timeout > 0 && $this->_check_timeout($fp))
858 858
 			{
859
-				$this->status=-100;
859
+				$this->status = -100;
860 860
 				return false;
861 861
 			}
862 862
 
863
-			if($currentHeader == "\r\n")
863
+			if ($currentHeader == "\r\n")
864 864
 				break;
865 865
 
866 866
 			// if a header begins with Location: or URI:, set the redirect
867
-			if(preg_match("/^(Location:|URI:)/i",$currentHeader))
867
+			if (preg_match("/^(Location:|URI:)/i", $currentHeader))
868 868
 			{
869 869
 				// get URL portion of the redirect
870
-				preg_match("/^(Location:|URI:)[ ]+(.*)/i",chop($currentHeader),$matches);
870
+				preg_match("/^(Location:|URI:)[ ]+(.*)/i", chop($currentHeader), $matches);
871 871
 				// look for :// in the Location header to see if hostname is included
872
-				if(!preg_match("|\:\/\/|",$matches[2]))
872
+				if ( ! preg_match("|\:\/\/|", $matches[2]))
873 873
 				{
874 874
 					// no host in the path, so prepend
875 875
 					$this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port;
876 876
 					// eliminate double slash
877
-					if(!preg_match("|^/|",$matches[2]))
877
+					if ( ! preg_match("|^/|", $matches[2]))
878 878
 							$this->_redirectaddr .= "/".$matches[2];
879 879
 					else
880 880
 							$this->_redirectaddr .= $matches[2];
@@ -883,11 +883,11 @@  discard block
 block discarded – undo
883 883
 					$this->_redirectaddr = $matches[2];
884 884
 			}
885 885
 
886
-			if(preg_match("|^HTTP/|",$currentHeader))
886
+			if (preg_match("|^HTTP/|", $currentHeader))
887 887
 			{
888
-                if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status))
888
+                if (preg_match("|^HTTP/[^\s]*\s(.*?)\s|", $currentHeader, $status))
889 889
 				{
890
-					$this->status= $status[1];
890
+					$this->status = $status[1];
891 891
                 }
892 892
 				$this->response_code = $currentHeader;
893 893
 			}
@@ -902,31 +902,31 @@  discard block
 block discarded – undo
902 902
         		break;
903 903
     		}
904 904
     		$results .= $_data;
905
-		} while(true);
905
+		} while (true);
906 906
 
907 907
 		if ($this->read_timeout > 0 && $this->_check_timeout($fp))
908 908
 		{
909
-			$this->status=-100;
909
+			$this->status = -100;
910 910
 			return false;
911 911
 		}
912 912
 
913 913
 		// check if there is a redirect meta tag
914 914
 
915
-		if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match))
915
+		if (preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i", $results, $match))
916 916
 
917 917
 		{
918
-			$this->_redirectaddr = $this->_expandlinks($match[1],$URI);
918
+			$this->_redirectaddr = $this->_expandlinks($match[1], $URI);
919 919
 		}
920 920
 
921 921
 		// have we hit our frame depth and is there frame src to fetch?
922
-		if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match))
922
+		if (($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i", $results, $match))
923 923
 		{
924 924
 			$this->results[] = $results;
925
-			for($x=0; $x<count($match[1]); $x++)
926
-				$this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host);
925
+			for ($x = 0; $x < count($match[1]); $x++)
926
+				$this->_frameurls[] = $this->_expandlinks($match[1][$x], $URI_PARTS["scheme"]."://".$this->host);
927 927
 		}
928 928
 		// have we already fetched framed content?
929
-		elseif(is_array($this->results))
929
+		elseif (is_array($this->results))
930 930
 			$this->results[] = $results;
931 931
 		// no framed content
932 932
 		else
@@ -944,108 +944,108 @@  discard block
 block discarded – undo
944 944
 	Output:
945 945
 \*======================================================================*/
946 946
 
947
-	function _httpsrequest($url,$URI,$http_method,$content_type="",$body="")
947
+	function _httpsrequest($url, $URI, $http_method, $content_type = "", $body = "")
948 948
 	{
949
-		if($this->passcookies && $this->_redirectaddr)
949
+		if ($this->passcookies && $this->_redirectaddr)
950 950
 			$this->setcookies();
951 951
 
952 952
 		$headers = array();
953 953
 
954 954
 		$URI_PARTS = parse_url($URI);
955
-		if(empty($url))
955
+		if (empty($url))
956 956
 			$url = "/";
957 957
 		// GET ... header not needed for curl
958 958
 		//$headers[] = $http_method." ".$url." ".$this->_httpversion;
959
-		if(!empty($this->agent))
959
+		if ( ! empty($this->agent))
960 960
 			$headers[] = "User-Agent: ".$this->agent;
961
-		if(!empty($this->host))
962
-			if(!empty($this->port))
961
+		if ( ! empty($this->host))
962
+			if ( ! empty($this->port))
963 963
 				$headers[] = "Host: ".$this->host.":".$this->port;
964 964
 			else
965 965
 				$headers[] = "Host: ".$this->host;
966
-		if(!empty($this->accept))
966
+		if ( ! empty($this->accept))
967 967
 			$headers[] = "Accept: ".$this->accept;
968
-		if(!empty($this->referer))
968
+		if ( ! empty($this->referer))
969 969
 			$headers[] = "Referer: ".$this->referer;
970
-		if(!empty($this->cookies))
970
+		if ( ! empty($this->cookies))
971 971
 		{
972
-			if(!is_array($this->cookies))
973
-				$this->cookies = (array)$this->cookies;
972
+			if ( ! is_array($this->cookies))
973
+				$this->cookies = (array) $this->cookies;
974 974
 
975 975
 			reset($this->cookies);
976
-			if ( count($this->cookies) > 0 ) {
976
+			if (count($this->cookies) > 0) {
977 977
 				$cookie_str = 'Cookie: ';
978
-				foreach ( $this->cookies as $cookieKey => $cookieVal ) {
978
+				foreach ($this->cookies as $cookieKey => $cookieVal) {
979 979
 				$cookie_str .= $cookieKey."=".urlencode($cookieVal)."; ";
980 980
 				}
981
-				$headers[] = substr($cookie_str,0,-2);
981
+				$headers[] = substr($cookie_str, 0, -2);
982 982
 			}
983 983
 		}
984
-		if(!empty($this->rawheaders))
984
+		if ( ! empty($this->rawheaders))
985 985
 		{
986
-			if(!is_array($this->rawheaders))
987
-				$this->rawheaders = (array)$this->rawheaders;
988
-			while(list($headerKey,$headerVal) = each($this->rawheaders))
986
+			if ( ! is_array($this->rawheaders))
987
+				$this->rawheaders = (array) $this->rawheaders;
988
+			while (list($headerKey, $headerVal) = each($this->rawheaders))
989 989
 				$headers[] = $headerKey.": ".$headerVal;
990 990
 		}
991
-		if(!empty($content_type)) {
991
+		if ( ! empty($content_type)) {
992 992
 			if ($content_type == "multipart/form-data")
993 993
 				$headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary;
994 994
 			else
995 995
 				$headers[] = "Content-type: $content_type";
996 996
 		}
997
-		if(!empty($body))
997
+		if ( ! empty($body))
998 998
 			$headers[] = "Content-length: ".strlen($body);
999
-		if(!empty($this->user) || !empty($this->pass))
999
+		if ( ! empty($this->user) || ! empty($this->pass))
1000 1000
 			$headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass);
1001 1001
 
1002
-		$headerfile = tempnam( $this->temp_dir, "sno" );
1003
-		$cmdline_params = '-k -D ' . escapeshellarg( $headerfile );
1002
+		$headerfile = tempnam($this->temp_dir, "sno");
1003
+		$cmdline_params = '-k -D '.escapeshellarg($headerfile);
1004 1004
 
1005
-		foreach ( $headers as $header ) {
1006
-			$cmdline_params .= ' -H ' . escapeshellarg( $header );
1005
+		foreach ($headers as $header) {
1006
+			$cmdline_params .= ' -H '.escapeshellarg($header);
1007 1007
 		}
1008 1008
 
1009
-		if ( ! empty( $body ) ) {
1010
-			$cmdline_params .= ' -d ' . escapeshellarg( $body );
1009
+		if ( ! empty($body)) {
1010
+			$cmdline_params .= ' -d '.escapeshellarg($body);
1011 1011
 		}
1012 1012
 
1013
-		if ( $this->read_timeout > 0 ) {
1014
-			$cmdline_params .= ' -m ' . escapeshellarg( $this->read_timeout );
1013
+		if ($this->read_timeout > 0) {
1014
+			$cmdline_params .= ' -m '.escapeshellarg($this->read_timeout);
1015 1015
 		}
1016 1016
 
1017 1017
 
1018
-		exec( $this->curl_path . ' ' . $cmdline_params . ' ' . escapeshellarg( $URI ), $results, $return );
1018
+		exec($this->curl_path.' '.$cmdline_params.' '.escapeshellarg($URI), $results, $return);
1019 1019
 
1020
-		if($return)
1020
+		if ($return)
1021 1021
 		{
1022 1022
 			$this->error = "Error: cURL could not retrieve the document, error $return.";
1023 1023
 			return false;
1024 1024
 		}
1025 1025
 
1026 1026
 
1027
-		$results = implode("\r\n",$results);
1027
+		$results = implode("\r\n", $results);
1028 1028
 
1029 1029
 		$result_headers = file("$headerfile");
1030 1030
 
1031 1031
 		$this->_redirectaddr = false;
1032 1032
 		unset($this->headers);
1033 1033
 
1034
-		for($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++)
1034
+		for ($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++)
1035 1035
 		{
1036 1036
 
1037 1037
 			// if a header begins with Location: or URI:, set the redirect
1038
-			if(preg_match("/^(Location: |URI: )/i",$result_headers[$currentHeader]))
1038
+			if (preg_match("/^(Location: |URI: )/i", $result_headers[$currentHeader]))
1039 1039
 			{
1040 1040
 				// get URL portion of the redirect
1041
-				preg_match("/^(Location: |URI:)\s+(.*)/",chop($result_headers[$currentHeader]),$matches);
1041
+				preg_match("/^(Location: |URI:)\s+(.*)/", chop($result_headers[$currentHeader]), $matches);
1042 1042
 				// look for :// in the Location header to see if hostname is included
1043
-				if(!preg_match("|\:\/\/|",$matches[2]))
1043
+				if ( ! preg_match("|\:\/\/|", $matches[2]))
1044 1044
 				{
1045 1045
 					// no host in the path, so prepend
1046 1046
 					$this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port;
1047 1047
 					// eliminate double slash
1048
-					if(!preg_match("|^/|",$matches[2]))
1048
+					if ( ! preg_match("|^/|", $matches[2]))
1049 1049
 							$this->_redirectaddr .= "/".$matches[2];
1050 1050
 					else
1051 1051
 							$this->_redirectaddr .= $matches[2];
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
 					$this->_redirectaddr = $matches[2];
1055 1055
 			}
1056 1056
 
1057
-			if(preg_match("|^HTTP/|",$result_headers[$currentHeader]))
1057
+			if (preg_match("|^HTTP/|", $result_headers[$currentHeader]))
1058 1058
 				$this->response_code = $result_headers[$currentHeader];
1059 1059
 
1060 1060
 			$this->headers[] = $result_headers[$currentHeader];
@@ -1062,20 +1062,20 @@  discard block
 block discarded – undo
1062 1062
 
1063 1063
 		// check if there is a redirect meta tag
1064 1064
 
1065
-		if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match))
1065
+		if (preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i", $results, $match))
1066 1066
 		{
1067
-			$this->_redirectaddr = $this->_expandlinks($match[1],$URI);
1067
+			$this->_redirectaddr = $this->_expandlinks($match[1], $URI);
1068 1068
 		}
1069 1069
 
1070 1070
 		// have we hit our frame depth and is there frame src to fetch?
1071
-		if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match))
1071
+		if (($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i", $results, $match))
1072 1072
 		{
1073 1073
 			$this->results[] = $results;
1074
-			for($x=0; $x<count($match[1]); $x++)
1075
-				$this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host);
1074
+			for ($x = 0; $x < count($match[1]); $x++)
1075
+				$this->_frameurls[] = $this->_expandlinks($match[1][$x], $URI_PARTS["scheme"]."://".$this->host);
1076 1076
 		}
1077 1077
 		// have we already fetched framed content?
1078
-		elseif(is_array($this->results))
1078
+		elseif (is_array($this->results))
1079 1079
 			$this->results[] = $results;
1080 1080
 		// no framed content
1081 1081
 		else
@@ -1093,9 +1093,9 @@  discard block
 block discarded – undo
1093 1093
 
1094 1094
 	function setcookies()
1095 1095
 	{
1096
-		for($x=0; $x<count($this->headers); $x++)
1096
+		for ($x = 0; $x < count($this->headers); $x++)
1097 1097
 		{
1098
-		if(preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x],$match))
1098
+		if (preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x], $match))
1099 1099
 			$this->cookies[$match[1]] = urldecode($match[2]);
1100 1100
 		}
1101 1101
 	}
@@ -1127,7 +1127,7 @@  discard block
 block discarded – undo
1127 1127
 
1128 1128
 	function _connect(&$fp)
1129 1129
 	{
1130
-		if(!empty($this->proxy_host) && !empty($this->proxy_port))
1130
+		if ( ! empty($this->proxy_host) && ! empty($this->proxy_port))
1131 1131
 			{
1132 1132
 				$this->_isproxy = true;
1133 1133
 
@@ -1142,7 +1142,7 @@  discard block
 block discarded – undo
1142 1142
 
1143 1143
 		$this->status = 0;
1144 1144
 
1145
-		if($fp = fsockopen(
1145
+		if ($fp = fsockopen(
1146 1146
 					$host,
1147 1147
 					$port,
1148 1148
 					$errno,
@@ -1158,16 +1158,16 @@  discard block
 block discarded – undo
1158 1158
 		{
1159 1159
 			// socket connection failed
1160 1160
 			$this->status = $errno;
1161
-			switch($errno)
1161
+			switch ($errno)
1162 1162
 			{
1163 1163
 				case -3:
1164
-					$this->error="socket creation failed (-3)";
1164
+					$this->error = "socket creation failed (-3)";
1165 1165
 				case -4:
1166
-					$this->error="dns lookup failure (-4)";
1166
+					$this->error = "dns lookup failure (-4)";
1167 1167
 				case -5:
1168
-					$this->error="connection refused or timed out (-5)";
1168
+					$this->error = "connection refused or timed out (-5)";
1169 1169
 				default:
1170
-					$this->error="connection failed (".$errno.")";
1170
+					$this->error = "connection failed (".$errno.")";
1171 1171
 			}
1172 1172
 			return false;
1173 1173
 		}
@@ -1204,7 +1204,7 @@  discard block
 block discarded – undo
1204 1204
 		switch ($this->_submit_type) {
1205 1205
 			case "application/x-www-form-urlencoded":
1206 1206
 				reset($formvars);
1207
-				while(list($key,$val) = each($formvars)) {
1207
+				while (list($key, $val) = each($formvars)) {
1208 1208
 					if (is_array($val) || is_object($val)) {
1209 1209
 						while (list($cur_key, $cur_val) = each($val)) {
1210 1210
 							$postdata .= urlencode($key)."[]=".urlencode($cur_val)."&";
@@ -1218,7 +1218,7 @@  discard block
 block discarded – undo
1218 1218
 				$this->_mime_boundary = "Snoopy".md5(uniqid(microtime()));
1219 1219
 
1220 1220
 				reset($formvars);
1221
-				while(list($key,$val) = each($formvars)) {
1221
+				while (list($key, $val) = each($formvars)) {
1222 1222
 					if (is_array($val) || is_object($val)) {
1223 1223
 						while (list($cur_key, $cur_val) = each($val)) {
1224 1224
 							$postdata .= "--".$this->_mime_boundary."\r\n";
@@ -1236,7 +1236,7 @@  discard block
 block discarded – undo
1236 1236
 				while (list($field_name, $file_names) = each($formfiles)) {
1237 1237
 					settype($file_names, "array");
1238 1238
 					while (list(, $file_name) = each($file_names)) {
1239
-						if (!is_readable($file_name)) continue;
1239
+						if ( ! is_readable($file_name)) continue;
1240 1240
 
1241 1241
 						$fp = fopen($file_name, "r");
1242 1242
 						$file_content = fread($fp, filesize($file_name));
Please login to merge, or discard this patch.
Braces   +273 added lines, -205 removed lines patch added patch discarded remove patch
@@ -131,29 +131,33 @@  discard block
 block discarded – undo
131 131
 
132 132
 		//preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS);
133 133
 		$URI_PARTS = parse_url($URI);
134
-		if (!empty($URI_PARTS["user"]))
135
-			$this->user = $URI_PARTS["user"];
136
-		if (!empty($URI_PARTS["pass"]))
137
-			$this->pass = $URI_PARTS["pass"];
138
-		if (empty($URI_PARTS["query"]))
139
-			$URI_PARTS["query"] = '';
140
-		if (empty($URI_PARTS["path"]))
141
-			$URI_PARTS["path"] = '';
134
+		if (!empty($URI_PARTS["user"])) {
135
+					$this->user = $URI_PARTS["user"];
136
+		}
137
+		if (!empty($URI_PARTS["pass"])) {
138
+					$this->pass = $URI_PARTS["pass"];
139
+		}
140
+		if (empty($URI_PARTS["query"])) {
141
+					$URI_PARTS["query"] = '';
142
+		}
143
+		if (empty($URI_PARTS["path"])) {
144
+					$URI_PARTS["path"] = '';
145
+		}
142 146
 
143 147
 		switch(strtolower($URI_PARTS["scheme"]))
144 148
 		{
145 149
 			case "http":
146 150
 				$this->host = $URI_PARTS["host"];
147
-				if(!empty($URI_PARTS["port"]))
148
-					$this->port = $URI_PARTS["port"];
151
+				if(!empty($URI_PARTS["port"])) {
152
+									$this->port = $URI_PARTS["port"];
153
+				}
149 154
 				if($this->_connect($fp))
150 155
 				{
151 156
 					if($this->_isproxy)
152 157
 					{
153 158
 						// using proxy, send entire URI
154 159
 						$this->_httprequest($URI,$fp,$URI,$this->_httpmethod);
155
-					}
156
-					else
160
+					} else
157 161
 					{
158 162
 						$path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : "");
159 163
 						// no proxy, send only the path
@@ -189,33 +193,34 @@  discard block
 block discarded – undo
189 193
 							{
190 194
 								$this->fetch($frameurl);
191 195
 								$this->_framedepth++;
196
+							} else {
197
+															break;
192 198
 							}
193
-							else
194
-								break;
195 199
 						}
196 200
 					}
197
-				}
198
-				else
201
+				} else
199 202
 				{
200 203
 					return false;
201 204
 				}
202 205
 				return true;
203 206
 				break;
204 207
 			case "https":
205
-				if(!$this->curl_path)
206
-					return false;
207
-				if(function_exists("is_executable"))
208
-				    if (!is_executable($this->curl_path))
208
+				if(!$this->curl_path) {
209
+									return false;
210
+				}
211
+				if(function_exists("is_executable")) {
212
+								    if (!is_executable($this->curl_path))
209 213
 				        return false;
214
+				}
210 215
 				$this->host = $URI_PARTS["host"];
211
-				if(!empty($URI_PARTS["port"]))
212
-					$this->port = $URI_PARTS["port"];
216
+				if(!empty($URI_PARTS["port"])) {
217
+									$this->port = $URI_PARTS["port"];
218
+				}
213 219
 				if($this->_isproxy)
214 220
 				{
215 221
 					// using proxy, send entire URI
216 222
 					$this->_httpsrequest($URI,$URI,$this->_httpmethod);
217
-				}
218
-				else
223
+				} else
219 224
 				{
220 225
 					$path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : "");
221 226
 					// no proxy, send only the path
@@ -249,9 +254,9 @@  discard block
 block discarded – undo
249 254
 						{
250 255
 							$this->fetch($frameurl);
251 256
 							$this->_framedepth++;
257
+						} else {
258
+													break;
252 259
 						}
253
-						else
254
-							break;
255 260
 					}
256 261
 				}
257 262
 				return true;
@@ -283,29 +288,33 @@  discard block
 block discarded – undo
283 288
 		$postdata = $this->_prepare_post_body($formvars, $formfiles);
284 289
 
285 290
 		$URI_PARTS = parse_url($URI);
286
-		if (!empty($URI_PARTS["user"]))
287
-			$this->user = $URI_PARTS["user"];
288
-		if (!empty($URI_PARTS["pass"]))
289
-			$this->pass = $URI_PARTS["pass"];
290
-		if (empty($URI_PARTS["query"]))
291
-			$URI_PARTS["query"] = '';
292
-		if (empty($URI_PARTS["path"]))
293
-			$URI_PARTS["path"] = '';
291
+		if (!empty($URI_PARTS["user"])) {
292
+					$this->user = $URI_PARTS["user"];
293
+		}
294
+		if (!empty($URI_PARTS["pass"])) {
295
+					$this->pass = $URI_PARTS["pass"];
296
+		}
297
+		if (empty($URI_PARTS["query"])) {
298
+					$URI_PARTS["query"] = '';
299
+		}
300
+		if (empty($URI_PARTS["path"])) {
301
+					$URI_PARTS["path"] = '';
302
+		}
294 303
 
295 304
 		switch(strtolower($URI_PARTS["scheme"]))
296 305
 		{
297 306
 			case "http":
298 307
 				$this->host = $URI_PARTS["host"];
299
-				if(!empty($URI_PARTS["port"]))
300
-					$this->port = $URI_PARTS["port"];
308
+				if(!empty($URI_PARTS["port"])) {
309
+									$this->port = $URI_PARTS["port"];
310
+				}
301 311
 				if($this->_connect($fp))
302 312
 				{
303 313
 					if($this->_isproxy)
304 314
 					{
305 315
 						// using proxy, send entire URI
306 316
 						$this->_httprequest($URI,$fp,$URI,$this->_submit_method,$this->_submit_type,$postdata);
307
-					}
308
-					else
317
+					} else
309 318
 					{
310 319
 						$path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : "");
311 320
 						// no proxy, send only the path
@@ -319,8 +328,9 @@  discard block
 block discarded – undo
319 328
 						/* url was redirected, check if we've hit the max depth */
320 329
 						if($this->maxredirs > $this->_redirectdepth)
321 330
 						{
322
-							if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr))
323
-								$this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]);
331
+							if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) {
332
+															$this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]);
333
+							}
324 334
 
325 335
 							// only follow redirect if it's on this site, or offsiteok is true
326 336
 							if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
@@ -328,10 +338,13 @@  discard block
 block discarded – undo
328 338
 								/* follow the redirect */
329 339
 								$this->_redirectdepth++;
330 340
 								$this->lastredirectaddr=$this->_redirectaddr;
331
-								if( strpos( $this->_redirectaddr, "?" ) > 0 )
332
-									$this->fetch($this->_redirectaddr); // the redirect has changed the request method from post to get
333
-								else
334
-									$this->submit($this->_redirectaddr,$formvars, $formfiles);
341
+								if( strpos( $this->_redirectaddr, "?" ) > 0 ) {
342
+																	$this->fetch($this->_redirectaddr);
343
+								}
344
+								// the redirect has changed the request method from post to get
345
+								else {
346
+																	$this->submit($this->_redirectaddr,$formvars, $formfiles);
347
+								}
335 348
 							}
336 349
 						}
337 350
 					}
@@ -347,34 +360,35 @@  discard block
 block discarded – undo
347 360
 							{
348 361
 								$this->fetch($frameurl);
349 362
 								$this->_framedepth++;
363
+							} else {
364
+															break;
350 365
 							}
351
-							else
352
-								break;
353 366
 						}
354 367
 					}
355 368
 
356
-				}
357
-				else
369
+				} else
358 370
 				{
359 371
 					return false;
360 372
 				}
361 373
 				return true;
362 374
 				break;
363 375
 			case "https":
364
-				if(!$this->curl_path)
365
-					return false;
366
-				if(function_exists("is_executable"))
367
-				    if (!is_executable($this->curl_path))
376
+				if(!$this->curl_path) {
377
+									return false;
378
+				}
379
+				if(function_exists("is_executable")) {
380
+								    if (!is_executable($this->curl_path))
368 381
 				        return false;
382
+				}
369 383
 				$this->host = $URI_PARTS["host"];
370
-				if(!empty($URI_PARTS["port"]))
371
-					$this->port = $URI_PARTS["port"];
384
+				if(!empty($URI_PARTS["port"])) {
385
+									$this->port = $URI_PARTS["port"];
386
+				}
372 387
 				if($this->_isproxy)
373 388
 				{
374 389
 					// using proxy, send entire URI
375 390
 					$this->_httpsrequest($URI, $URI, $this->_submit_method, $this->_submit_type, $postdata);
376
-				}
377
-				else
391
+				} else
378 392
 				{
379 393
 					$path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : "");
380 394
 					// no proxy, send only the path
@@ -386,8 +400,9 @@  discard block
 block discarded – undo
386 400
 					/* url was redirected, check if we've hit the max depth */
387 401
 					if($this->maxredirs > $this->_redirectdepth)
388 402
 					{
389
-						if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr))
390
-							$this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]);
403
+						if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) {
404
+													$this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]);
405
+						}
391 406
 
392 407
 						// only follow redirect if it's on this site, or offsiteok is true
393 408
 						if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
@@ -395,10 +410,13 @@  discard block
 block discarded – undo
395 410
 							/* follow the redirect */
396 411
 							$this->_redirectdepth++;
397 412
 							$this->lastredirectaddr=$this->_redirectaddr;
398
-							if( strpos( $this->_redirectaddr, "?" ) > 0 )
399
-								$this->fetch($this->_redirectaddr); // the redirect has changed the request method from post to get
400
-							else
401
-								$this->submit($this->_redirectaddr,$formvars, $formfiles);
413
+							if( strpos( $this->_redirectaddr, "?" ) > 0 ) {
414
+															$this->fetch($this->_redirectaddr);
415
+							}
416
+							// the redirect has changed the request method from post to get
417
+							else {
418
+															$this->submit($this->_redirectaddr,$formvars, $formfiles);
419
+							}
402 420
 						}
403 421
 					}
404 422
 				}
@@ -414,9 +432,9 @@  discard block
 block discarded – undo
414 432
 						{
415 433
 							$this->fetch($frameurl);
416 434
 							$this->_framedepth++;
435
+						} else {
436
+													break;
417 437
 						}
418
-						else
419
-							break;
420 438
 					}
421 439
 				}
422 440
 				return true;
@@ -442,22 +460,25 @@  discard block
 block discarded – undo
442 460
 	{
443 461
 		if ($this->fetch($URI))
444 462
 		{
445
-			if($this->lastredirectaddr)
446
-				$URI = $this->lastredirectaddr;
463
+			if($this->lastredirectaddr) {
464
+							$URI = $this->lastredirectaddr;
465
+			}
447 466
 			if(is_array($this->results))
448 467
 			{
449
-				for($x=0;$x<count($this->results);$x++)
450
-					$this->results[$x] = $this->_striplinks($this->results[$x]);
468
+				for($x=0;$x<count($this->results);$x++) {
469
+									$this->results[$x] = $this->_striplinks($this->results[$x]);
470
+				}
471
+			} else {
472
+							$this->results = $this->_striplinks($this->results);
451 473
 			}
452
-			else
453
-				$this->results = $this->_striplinks($this->results);
454 474
 
455
-			if($this->expandlinks)
456
-				$this->results = $this->_expandlinks($this->results, $URI);
475
+			if($this->expandlinks) {
476
+							$this->results = $this->_expandlinks($this->results, $URI);
477
+			}
457 478
 			return true;
479
+		} else {
480
+					return false;
458 481
 		}
459
-		else
460
-			return false;
461 482
 	}
462 483
 
463 484
 /*======================================================================*\
@@ -475,16 +496,17 @@  discard block
 block discarded – undo
475 496
 
476 497
 			if(is_array($this->results))
477 498
 			{
478
-				for($x=0;$x<count($this->results);$x++)
479
-					$this->results[$x] = $this->_stripform($this->results[$x]);
499
+				for($x=0;$x<count($this->results);$x++) {
500
+									$this->results[$x] = $this->_stripform($this->results[$x]);
501
+				}
502
+			} else {
503
+							$this->results = $this->_stripform($this->results);
480 504
 			}
481
-			else
482
-				$this->results = $this->_stripform($this->results);
483 505
 
484 506
 			return true;
507
+		} else {
508
+					return false;
485 509
 		}
486
-		else
487
-			return false;
488 510
 	}
489 511
 
490 512
 
@@ -501,15 +523,16 @@  discard block
 block discarded – undo
501 523
 		{
502 524
 			if(is_array($this->results))
503 525
 			{
504
-				for($x=0;$x<count($this->results);$x++)
505
-					$this->results[$x] = $this->_striptext($this->results[$x]);
526
+				for($x=0;$x<count($this->results);$x++) {
527
+									$this->results[$x] = $this->_striptext($this->results[$x]);
528
+				}
529
+			} else {
530
+							$this->results = $this->_striptext($this->results);
506 531
 			}
507
-			else
508
-				$this->results = $this->_striptext($this->results);
509 532
 			return true;
533
+		} else {
534
+					return false;
510 535
 		}
511
-		else
512
-			return false;
513 536
 	}
514 537
 
515 538
 /*======================================================================*\
@@ -523,27 +546,29 @@  discard block
 block discarded – undo
523 546
 	{
524 547
 		if($this->submit($URI,$formvars, $formfiles))
525 548
 		{
526
-			if($this->lastredirectaddr)
527
-				$URI = $this->lastredirectaddr;
549
+			if($this->lastredirectaddr) {
550
+							$URI = $this->lastredirectaddr;
551
+			}
528 552
 			if(is_array($this->results))
529 553
 			{
530 554
 				for($x=0;$x<count($this->results);$x++)
531 555
 				{
532 556
 					$this->results[$x] = $this->_striplinks($this->results[$x]);
533
-					if($this->expandlinks)
534
-						$this->results[$x] = $this->_expandlinks($this->results[$x],$URI);
557
+					if($this->expandlinks) {
558
+											$this->results[$x] = $this->_expandlinks($this->results[$x],$URI);
559
+					}
535 560
 				}
536
-			}
537
-			else
561
+			} else
538 562
 			{
539 563
 				$this->results = $this->_striplinks($this->results);
540
-				if($this->expandlinks)
541
-					$this->results = $this->_expandlinks($this->results,$URI);
564
+				if($this->expandlinks) {
565
+									$this->results = $this->_expandlinks($this->results,$URI);
566
+				}
542 567
 			}
543 568
 			return true;
569
+		} else {
570
+					return false;
544 571
 		}
545
-		else
546
-			return false;
547 572
 	}
548 573
 
549 574
 /*======================================================================*\
@@ -557,27 +582,29 @@  discard block
 block discarded – undo
557 582
 	{
558 583
 		if($this->submit($URI,$formvars, $formfiles))
559 584
 		{
560
-			if($this->lastredirectaddr)
561
-				$URI = $this->lastredirectaddr;
585
+			if($this->lastredirectaddr) {
586
+							$URI = $this->lastredirectaddr;
587
+			}
562 588
 			if(is_array($this->results))
563 589
 			{
564 590
 				for($x=0;$x<count($this->results);$x++)
565 591
 				{
566 592
 					$this->results[$x] = $this->_striptext($this->results[$x]);
567
-					if($this->expandlinks)
568
-						$this->results[$x] = $this->_expandlinks($this->results[$x],$URI);
593
+					if($this->expandlinks) {
594
+											$this->results[$x] = $this->_expandlinks($this->results[$x],$URI);
595
+					}
569 596
 				}
570
-			}
571
-			else
597
+			} else
572 598
 			{
573 599
 				$this->results = $this->_striptext($this->results);
574
-				if($this->expandlinks)
575
-					$this->results = $this->_expandlinks($this->results,$URI);
600
+				if($this->expandlinks) {
601
+									$this->results = $this->_expandlinks($this->results,$URI);
602
+				}
576 603
 			}
577 604
 			return true;
605
+		} else {
606
+					return false;
578 607
 		}
579
-		else
580
-			return false;
581 608
 	}
582 609
 
583 610
 
@@ -631,14 +658,16 @@  discard block
 block discarded – undo
631 658
 
632 659
 		while(list($key,$val) = each($links[2]))
633 660
 		{
634
-			if(!empty($val))
635
-				$match[] = $val;
661
+			if(!empty($val)) {
662
+							$match[] = $val;
663
+			}
636 664
 		}
637 665
 
638 666
 		while(list($key,$val) = each($links[3]))
639 667
 		{
640
-			if(!empty($val))
641
-				$match[] = $val;
668
+			if(!empty($val)) {
669
+							$match[] = $val;
670
+			}
642 671
 		}
643 672
 
644 673
 		// return the links
@@ -784,29 +813,36 @@  discard block
 block discarded – undo
784 813
 	function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="")
785 814
 	{
786 815
 		$cookie_headers = '';
787
-		if($this->passcookies && $this->_redirectaddr)
788
-			$this->setcookies();
816
+		if($this->passcookies && $this->_redirectaddr) {
817
+					$this->setcookies();
818
+		}
789 819
 
790 820
 		$URI_PARTS = parse_url($URI);
791
-		if(empty($url))
792
-			$url = "/";
821
+		if(empty($url)) {
822
+					$url = "/";
823
+		}
793 824
 		$headers = $http_method." ".$url." ".$this->_httpversion."\r\n";
794
-		if(!empty($this->agent))
795
-			$headers .= "User-Agent: ".$this->agent."\r\n";
825
+		if(!empty($this->agent)) {
826
+					$headers .= "User-Agent: ".$this->agent."\r\n";
827
+		}
796 828
 		if(!empty($this->host) && !isset($this->rawheaders['Host'])) {
797 829
 			$headers .= "Host: ".$this->host;
798
-			if(!empty($this->port) && $this->port != 80)
799
-				$headers .= ":".$this->port;
830
+			if(!empty($this->port) && $this->port != 80) {
831
+							$headers .= ":".$this->port;
832
+			}
800 833
 			$headers .= "\r\n";
801 834
 		}
802
-		if(!empty($this->accept))
803
-			$headers .= "Accept: ".$this->accept."\r\n";
804
-		if(!empty($this->referer))
805
-			$headers .= "Referer: ".$this->referer."\r\n";
835
+		if(!empty($this->accept)) {
836
+					$headers .= "Accept: ".$this->accept."\r\n";
837
+		}
838
+		if(!empty($this->referer)) {
839
+					$headers .= "Referer: ".$this->referer."\r\n";
840
+		}
806 841
 		if(!empty($this->cookies))
807 842
 		{
808
-			if(!is_array($this->cookies))
809
-				$this->cookies = (array)$this->cookies;
843
+			if(!is_array($this->cookies)) {
844
+							$this->cookies = (array)$this->cookies;
845
+			}
810 846
 
811 847
 			reset($this->cookies);
812 848
 			if ( count($this->cookies) > 0 ) {
@@ -819,32 +855,39 @@  discard block
 block discarded – undo
819 855
 		}
820 856
 		if(!empty($this->rawheaders))
821 857
 		{
822
-			if(!is_array($this->rawheaders))
823
-				$this->rawheaders = (array)$this->rawheaders;
824
-			while(list($headerKey,$headerVal) = each($this->rawheaders))
825
-				$headers .= $headerKey.": ".$headerVal."\r\n";
858
+			if(!is_array($this->rawheaders)) {
859
+							$this->rawheaders = (array)$this->rawheaders;
860
+			}
861
+			while(list($headerKey,$headerVal) = each($this->rawheaders)) {
862
+							$headers .= $headerKey.": ".$headerVal."\r\n";
863
+			}
826 864
 		}
827 865
 		if(!empty($content_type)) {
828 866
 			$headers .= "Content-type: $content_type";
829
-			if ($content_type == "multipart/form-data")
830
-				$headers .= "; boundary=".$this->_mime_boundary;
867
+			if ($content_type == "multipart/form-data") {
868
+							$headers .= "; boundary=".$this->_mime_boundary;
869
+			}
831 870
 			$headers .= "\r\n";
832 871
 		}
833
-		if(!empty($body))
834
-			$headers .= "Content-length: ".strlen($body)."\r\n";
835
-		if(!empty($this->user) || !empty($this->pass))
836
-			$headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n";
872
+		if(!empty($body)) {
873
+					$headers .= "Content-length: ".strlen($body)."\r\n";
874
+		}
875
+		if(!empty($this->user) || !empty($this->pass)) {
876
+					$headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n";
877
+		}
837 878
 
838 879
 		//add proxy auth headers
839
-		if(!empty($this->proxy_user))
840
-			$headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass)."\r\n";
880
+		if(!empty($this->proxy_user)) {
881
+					$headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass)."\r\n";
882
+		}
841 883
 
842 884
 
843 885
 		$headers .= "\r\n";
844 886
 
845 887
 		// set the read timeout if needed
846
-		if ($this->read_timeout > 0)
847
-			socket_set_timeout($fp, $this->read_timeout);
888
+		if ($this->read_timeout > 0) {
889
+					socket_set_timeout($fp, $this->read_timeout);
890
+		}
848 891
 		$this->timed_out = false;
849 892
 
850 893
 		fwrite($fp,$headers.$body,strlen($headers.$body));
@@ -860,8 +903,9 @@  discard block
 block discarded – undo
860 903
 				return false;
861 904
 			}
862 905
 
863
-			if($currentHeader == "\r\n")
864
-				break;
906
+			if($currentHeader == "\r\n") {
907
+							break;
908
+			}
865 909
 
866 910
 			// if a header begins with Location: or URI:, set the redirect
867 911
 			if(preg_match("/^(Location:|URI:)/i",$currentHeader))
@@ -874,13 +918,14 @@  discard block
 block discarded – undo
874 918
 					// no host in the path, so prepend
875 919
 					$this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port;
876 920
 					// eliminate double slash
877
-					if(!preg_match("|^/|",$matches[2]))
878
-							$this->_redirectaddr .= "/".$matches[2];
879
-					else
880
-							$this->_redirectaddr .= $matches[2];
921
+					if(!preg_match("|^/|",$matches[2])) {
922
+												$this->_redirectaddr .= "/".$matches[2];
923
+					} else {
924
+												$this->_redirectaddr .= $matches[2];
925
+					}
926
+				} else {
927
+									$this->_redirectaddr = $matches[2];
881 928
 				}
882
-				else
883
-					$this->_redirectaddr = $matches[2];
884 929
 			}
885 930
 
886 931
 			if(preg_match("|^HTTP/|",$currentHeader))
@@ -922,15 +967,18 @@  discard block
 block discarded – undo
922 967
 		if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match))
923 968
 		{
924 969
 			$this->results[] = $results;
925
-			for($x=0; $x<count($match[1]); $x++)
926
-				$this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host);
970
+			for($x=0; $x<count($match[1]); $x++) {
971
+							$this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host);
972
+			}
927 973
 		}
928 974
 		// have we already fetched framed content?
929
-		elseif(is_array($this->results))
930
-			$this->results[] = $results;
975
+		elseif(is_array($this->results)) {
976
+					$this->results[] = $results;
977
+		}
931 978
 		// no framed content
932
-		else
933
-			$this->results = $results;
979
+		else {
980
+					$this->results = $results;
981
+		}
934 982
 
935 983
 		return true;
936 984
 	}
@@ -946,31 +994,38 @@  discard block
 block discarded – undo
946 994
 
947 995
 	function _httpsrequest($url,$URI,$http_method,$content_type="",$body="")
948 996
 	{
949
-		if($this->passcookies && $this->_redirectaddr)
950
-			$this->setcookies();
997
+		if($this->passcookies && $this->_redirectaddr) {
998
+					$this->setcookies();
999
+		}
951 1000
 
952 1001
 		$headers = array();
953 1002
 
954 1003
 		$URI_PARTS = parse_url($URI);
955
-		if(empty($url))
956
-			$url = "/";
1004
+		if(empty($url)) {
1005
+					$url = "/";
1006
+		}
957 1007
 		// GET ... header not needed for curl
958 1008
 		//$headers[] = $http_method." ".$url." ".$this->_httpversion;
959
-		if(!empty($this->agent))
960
-			$headers[] = "User-Agent: ".$this->agent;
961
-		if(!empty($this->host))
962
-			if(!empty($this->port))
1009
+		if(!empty($this->agent)) {
1010
+					$headers[] = "User-Agent: ".$this->agent;
1011
+		}
1012
+		if(!empty($this->host)) {
1013
+					if(!empty($this->port))
963 1014
 				$headers[] = "Host: ".$this->host.":".$this->port;
964
-			else
965
-				$headers[] = "Host: ".$this->host;
966
-		if(!empty($this->accept))
967
-			$headers[] = "Accept: ".$this->accept;
968
-		if(!empty($this->referer))
969
-			$headers[] = "Referer: ".$this->referer;
1015
+		} else {
1016
+							$headers[] = "Host: ".$this->host;
1017
+			}
1018
+		if(!empty($this->accept)) {
1019
+					$headers[] = "Accept: ".$this->accept;
1020
+		}
1021
+		if(!empty($this->referer)) {
1022
+					$headers[] = "Referer: ".$this->referer;
1023
+		}
970 1024
 		if(!empty($this->cookies))
971 1025
 		{
972
-			if(!is_array($this->cookies))
973
-				$this->cookies = (array)$this->cookies;
1026
+			if(!is_array($this->cookies)) {
1027
+							$this->cookies = (array)$this->cookies;
1028
+			}
974 1029
 
975 1030
 			reset($this->cookies);
976 1031
 			if ( count($this->cookies) > 0 ) {
@@ -983,21 +1038,26 @@  discard block
 block discarded – undo
983 1038
 		}
984 1039
 		if(!empty($this->rawheaders))
985 1040
 		{
986
-			if(!is_array($this->rawheaders))
987
-				$this->rawheaders = (array)$this->rawheaders;
988
-			while(list($headerKey,$headerVal) = each($this->rawheaders))
989
-				$headers[] = $headerKey.": ".$headerVal;
1041
+			if(!is_array($this->rawheaders)) {
1042
+							$this->rawheaders = (array)$this->rawheaders;
1043
+			}
1044
+			while(list($headerKey,$headerVal) = each($this->rawheaders)) {
1045
+							$headers[] = $headerKey.": ".$headerVal;
1046
+			}
990 1047
 		}
991 1048
 		if(!empty($content_type)) {
992
-			if ($content_type == "multipart/form-data")
993
-				$headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary;
994
-			else
995
-				$headers[] = "Content-type: $content_type";
1049
+			if ($content_type == "multipart/form-data") {
1050
+							$headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary;
1051
+			} else {
1052
+							$headers[] = "Content-type: $content_type";
1053
+			}
1054
+		}
1055
+		if(!empty($body)) {
1056
+					$headers[] = "Content-length: ".strlen($body);
1057
+		}
1058
+		if(!empty($this->user) || !empty($this->pass)) {
1059
+					$headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass);
996 1060
 		}
997
-		if(!empty($body))
998
-			$headers[] = "Content-length: ".strlen($body);
999
-		if(!empty($this->user) || !empty($this->pass))
1000
-			$headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass);
1001 1061
 
1002 1062
 		$headerfile = tempnam( $this->temp_dir, "sno" );
1003 1063
 		$cmdline_params = '-k -D ' . escapeshellarg( $headerfile );
@@ -1045,17 +1105,19 @@  discard block
 block discarded – undo
1045 1105
 					// no host in the path, so prepend
1046 1106
 					$this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port;
1047 1107
 					// eliminate double slash
1048
-					if(!preg_match("|^/|",$matches[2]))
1049
-							$this->_redirectaddr .= "/".$matches[2];
1050
-					else
1051
-							$this->_redirectaddr .= $matches[2];
1108
+					if(!preg_match("|^/|",$matches[2])) {
1109
+												$this->_redirectaddr .= "/".$matches[2];
1110
+					} else {
1111
+												$this->_redirectaddr .= $matches[2];
1112
+					}
1113
+				} else {
1114
+									$this->_redirectaddr = $matches[2];
1052 1115
 				}
1053
-				else
1054
-					$this->_redirectaddr = $matches[2];
1055 1116
 			}
1056 1117
 
1057
-			if(preg_match("|^HTTP/|",$result_headers[$currentHeader]))
1058
-				$this->response_code = $result_headers[$currentHeader];
1118
+			if(preg_match("|^HTTP/|",$result_headers[$currentHeader])) {
1119
+							$this->response_code = $result_headers[$currentHeader];
1120
+			}
1059 1121
 
1060 1122
 			$this->headers[] = $result_headers[$currentHeader];
1061 1123
 		}
@@ -1071,15 +1133,18 @@  discard block
 block discarded – undo
1071 1133
 		if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match))
1072 1134
 		{
1073 1135
 			$this->results[] = $results;
1074
-			for($x=0; $x<count($match[1]); $x++)
1075
-				$this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host);
1136
+			for($x=0; $x<count($match[1]); $x++) {
1137
+							$this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host);
1138
+			}
1076 1139
 		}
1077 1140
 		// have we already fetched framed content?
1078
-		elseif(is_array($this->results))
1079
-			$this->results[] = $results;
1141
+		elseif(is_array($this->results)) {
1142
+					$this->results[] = $results;
1143
+		}
1080 1144
 		// no framed content
1081
-		else
1082
-			$this->results = $results;
1145
+		else {
1146
+					$this->results = $results;
1147
+		}
1083 1148
 
1084 1149
 		unlink("$headerfile");
1085 1150
 
@@ -1095,8 +1160,9 @@  discard block
 block discarded – undo
1095 1160
 	{
1096 1161
 		for($x=0; $x<count($this->headers); $x++)
1097 1162
 		{
1098
-		if(preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x],$match))
1099
-			$this->cookies[$match[1]] = urldecode($match[2]);
1163
+		if(preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x],$match)) {
1164
+					$this->cookies[$match[1]] = urldecode($match[2]);
1165
+		}
1100 1166
 		}
1101 1167
 	}
1102 1168
 
@@ -1133,8 +1199,7 @@  discard block
 block discarded – undo
1133 1199
 
1134 1200
 				$host = $this->proxy_host;
1135 1201
 				$port = $this->proxy_port;
1136
-			}
1137
-		else
1202
+			} else
1138 1203
 		{
1139 1204
 			$host = $this->host;
1140 1205
 			$port = $this->port;
@@ -1153,8 +1218,7 @@  discard block
 block discarded – undo
1153 1218
 			// socket connection succeeded
1154 1219
 
1155 1220
 			return true;
1156
-		}
1157
-		else
1221
+		} else
1158 1222
 		{
1159 1223
 			// socket connection failed
1160 1224
 			$this->status = $errno;
@@ -1198,8 +1262,9 @@  discard block
 block discarded – undo
1198 1262
 		settype($formfiles, "array");
1199 1263
 		$postdata = '';
1200 1264
 
1201
-		if (count($formvars) == 0 && count($formfiles) == 0)
1202
-			return;
1265
+		if (count($formvars) == 0 && count($formfiles) == 0) {
1266
+					return;
1267
+		}
1203 1268
 
1204 1269
 		switch ($this->_submit_type) {
1205 1270
 			case "application/x-www-form-urlencoded":
@@ -1209,8 +1274,9 @@  discard block
 block discarded – undo
1209 1274
 						while (list($cur_key, $cur_val) = each($val)) {
1210 1275
 							$postdata .= urlencode($key)."[]=".urlencode($cur_val)."&";
1211 1276
 						}
1212
-					} else
1213
-						$postdata .= urlencode($key)."=".urlencode($val)."&";
1277
+					} else {
1278
+											$postdata .= urlencode($key)."=".urlencode($val)."&";
1279
+					}
1214 1280
 				}
1215 1281
 				break;
1216 1282
 
@@ -1236,7 +1302,9 @@  discard block
 block discarded – undo
1236 1302
 				while (list($field_name, $file_names) = each($formfiles)) {
1237 1303
 					settype($file_names, "array");
1238 1304
 					while (list(, $file_name) = each($file_names)) {
1239
-						if (!is_readable($file_name)) continue;
1305
+						if (!is_readable($file_name)) {
1306
+							continue;
1307
+						}
1240 1308
 
1241 1309
 						$fp = fopen($file_name, "r");
1242 1310
 						$file_content = fread($fp, filesize($file_name));
Please login to merge, or discard this patch.
src/wp-includes/class-wp-customize-nav-menus.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 * @since 4.3.0
43 43
 	 * @access public
44 44
 	 *
45
-	 * @param object $manager An instance of the WP_Customize_Manager class.
45
+	 * @param WP_Customize_Manager $manager An instance of the WP_Customize_Manager class.
46 46
 	 */
47 47
 	public function __construct( $manager ) {
48 48
 		$this->previewed_menus = array();
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
 	 *
877 877
 	 * @param string $nav_menu_content The HTML content for the navigation menu.
878 878
 	 * @param object $args             An object containing wp_nav_menu() arguments.
879
-	 * @return null
879
+	 * @return string
880 880
 	 */
881 881
 	public function filter_wp_nav_menu( $nav_menu_content, $args ) {
882 882
 		if ( ! empty( $args->can_partial_refresh ) && ! empty( $args->instance_number ) ) {
Please login to merge, or discard this patch.
Spacing   +272 added lines, -272 removed lines patch added patch discarded remove patch
@@ -44,31 +44,31 @@  discard block
 block discarded – undo
44 44
 	 *
45 45
 	 * @param object $manager An instance of the WP_Customize_Manager class.
46 46
 	 */
47
-	public function __construct( $manager ) {
47
+	public function __construct($manager) {
48 48
 		$this->previewed_menus = array();
49 49
 		$this->manager         = $manager;
50 50
 
51 51
 		// Skip useless hooks when the user can't manage nav menus anyway.
52
-		if ( ! current_user_can( 'edit_theme_options' ) ) {
52
+		if ( ! current_user_can('edit_theme_options')) {
53 53
 			return;
54 54
 		}
55 55
 
56
-		add_filter( 'customize_refresh_nonces', array( $this, 'filter_nonces' ) );
57
-		add_action( 'wp_ajax_load-available-menu-items-customizer', array( $this, 'ajax_load_available_items' ) );
58
-		add_action( 'wp_ajax_search-available-menu-items-customizer', array( $this, 'ajax_search_available_items' ) );
59
-		add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
56
+		add_filter('customize_refresh_nonces', array($this, 'filter_nonces'));
57
+		add_action('wp_ajax_load-available-menu-items-customizer', array($this, 'ajax_load_available_items'));
58
+		add_action('wp_ajax_search-available-menu-items-customizer', array($this, 'ajax_search_available_items'));
59
+		add_action('customize_controls_enqueue_scripts', array($this, 'enqueue_scripts'));
60 60
 
61 61
 		// Needs to run after core Navigation section is set up.
62
-		add_action( 'customize_register', array( $this, 'customize_register' ), 11 );
62
+		add_action('customize_register', array($this, 'customize_register'), 11);
63 63
 
64
-		add_filter( 'customize_dynamic_setting_args', array( $this, 'filter_dynamic_setting_args' ), 10, 2 );
65
-		add_filter( 'customize_dynamic_setting_class', array( $this, 'filter_dynamic_setting_class' ), 10, 3 );
66
-		add_action( 'customize_controls_print_footer_scripts', array( $this, 'print_templates' ) );
67
-		add_action( 'customize_controls_print_footer_scripts', array( $this, 'available_items_template' ) );
68
-		add_action( 'customize_preview_init', array( $this, 'customize_preview_init' ) );
64
+		add_filter('customize_dynamic_setting_args', array($this, 'filter_dynamic_setting_args'), 10, 2);
65
+		add_filter('customize_dynamic_setting_class', array($this, 'filter_dynamic_setting_class'), 10, 3);
66
+		add_action('customize_controls_print_footer_scripts', array($this, 'print_templates'));
67
+		add_action('customize_controls_print_footer_scripts', array($this, 'available_items_template'));
68
+		add_action('customize_preview_init', array($this, 'customize_preview_init'));
69 69
 
70 70
 		// Selective Refresh partials.
71
-		add_filter( 'customize_dynamic_partial_args', array( $this, 'customize_dynamic_partial_args' ), 10, 2 );
71
+		add_filter('customize_dynamic_partial_args', array($this, 'customize_dynamic_partial_args'), 10, 2);
72 72
 	}
73 73
 
74 74
 	/**
@@ -80,8 +80,8 @@  discard block
 block discarded – undo
80 80
 	 * @param array $nonces Array of nonces.
81 81
 	 * @return array $nonces Modified array of nonces.
82 82
 	 */
83
-	public function filter_nonces( $nonces ) {
84
-		$nonces['customize-menus'] = wp_create_nonce( 'customize-menus' );
83
+	public function filter_nonces($nonces) {
84
+		$nonces['customize-menus'] = wp_create_nonce('customize-menus');
85 85
 		return $nonces;
86 86
 	}
87 87
 
@@ -92,25 +92,25 @@  discard block
 block discarded – undo
92 92
 	 * @access public
93 93
 	 */
94 94
 	public function ajax_load_available_items() {
95
-		check_ajax_referer( 'customize-menus', 'customize-menus-nonce' );
95
+		check_ajax_referer('customize-menus', 'customize-menus-nonce');
96 96
 
97
-		if ( ! current_user_can( 'edit_theme_options' ) ) {
97
+		if ( ! current_user_can('edit_theme_options')) {
98 98
 			wp_die( -1 );
99 99
 		}
100 100
 
101
-		if ( empty( $_POST['type'] ) || empty( $_POST['object'] ) ) {
102
-			wp_send_json_error( 'nav_menus_missing_type_or_object_parameter' );
101
+		if (empty($_POST['type']) || empty($_POST['object'])) {
102
+			wp_send_json_error('nav_menus_missing_type_or_object_parameter');
103 103
 		}
104 104
 
105
-		$type = sanitize_key( $_POST['type'] );
106
-		$object = sanitize_key( $_POST['object'] );
107
-		$page = empty( $_POST['page'] ) ? 0 : absint( $_POST['page'] );
108
-		$items = $this->load_available_items_query( $type, $object, $page );
105
+		$type = sanitize_key($_POST['type']);
106
+		$object = sanitize_key($_POST['object']);
107
+		$page = empty($_POST['page']) ? 0 : absint($_POST['page']);
108
+		$items = $this->load_available_items_query($type, $object, $page);
109 109
 
110
-		if ( is_wp_error( $items ) ) {
111
-			wp_send_json_error( $items->get_error_code() );
110
+		if (is_wp_error($items)) {
111
+			wp_send_json_error($items->get_error_code());
112 112
 		} else {
113
-			wp_send_json_success( array( 'items' => $items ) );
113
+			wp_send_json_success(array('items' => $items));
114 114
 		}
115 115
 	}
116 116
 
@@ -126,62 +126,62 @@  discard block
 block discarded – undo
126 126
 	 * @param int    $page   Optional. The page number used to generate the query offset. Default is '0'.
127 127
 	 * @return WP_Error|array Returns either a WP_Error object or an array of menu items.
128 128
 	 */
129
-	public function load_available_items_query( $type = 'post_type', $object = 'page', $page = 0 ) {
129
+	public function load_available_items_query($type = 'post_type', $object = 'page', $page = 0) {
130 130
 		$items = array();
131 131
 
132
-		if ( 'post_type' === $type ) {
133
-			$post_type = get_post_type_object( $object );
134
-			if ( ! $post_type ) {
135
-				return new WP_Error( 'nav_menus_invalid_post_type' );
132
+		if ('post_type' === $type) {
133
+			$post_type = get_post_type_object($object);
134
+			if ( ! $post_type) {
135
+				return new WP_Error('nav_menus_invalid_post_type');
136 136
 			}
137 137
 
138
-			if ( 0 === $page && 'page' === $object ) {
138
+			if (0 === $page && 'page' === $object) {
139 139
 				// Add "Home" link. Treat as a page, but switch to custom on add.
140 140
 				$items[] = array(
141 141
 					'id'         => 'home',
142
-					'title'      => _x( 'Home', 'nav menu home label' ),
142
+					'title'      => _x('Home', 'nav menu home label'),
143 143
 					'type'       => 'custom',
144
-					'type_label' => __( 'Custom Link' ),
144
+					'type_label' => __('Custom Link'),
145 145
 					'object'     => '',
146 146
 					'url'        => home_url(),
147 147
 				);
148
-			} elseif ( 'post' !== $object && 0 === $page && $post_type->has_archive ) {
148
+			} elseif ('post' !== $object && 0 === $page && $post_type->has_archive) {
149 149
 				// Add a post type archive link.
150 150
 				$items[] = array(
151
-					'id'         => $object . '-archive',
151
+					'id'         => $object.'-archive',
152 152
 					'title'      => $post_type->labels->archives,
153 153
 					'type'       => 'post_type_archive',
154
-					'type_label' => __( 'Post Type Archive' ),
154
+					'type_label' => __('Post Type Archive'),
155 155
 					'object'     => $object,
156
-					'url'        => get_post_type_archive_link( $object ),
156
+					'url'        => get_post_type_archive_link($object),
157 157
 				);
158 158
 			}
159 159
 
160
-			$posts = get_posts( array(
160
+			$posts = get_posts(array(
161 161
 				'numberposts' => 10,
162 162
 				'offset'      => 10 * $page,
163 163
 				'orderby'     => 'date',
164 164
 				'order'       => 'DESC',
165 165
 				'post_type'   => $object,
166
-			) );
167
-			foreach ( $posts as $post ) {
166
+			));
167
+			foreach ($posts as $post) {
168 168
 				$post_title = $post->post_title;
169
-				if ( '' === $post_title ) {
169
+				if ('' === $post_title) {
170 170
 					/* translators: %d: ID of a post */
171
-					$post_title = sprintf( __( '#%d (no title)' ), $post->ID );
171
+					$post_title = sprintf(__('#%d (no title)'), $post->ID);
172 172
 				}
173 173
 				$items[] = array(
174 174
 					'id'         => "post-{$post->ID}",
175
-					'title'      => html_entity_decode( $post_title, ENT_QUOTES, get_bloginfo( 'charset' ) ),
175
+					'title'      => html_entity_decode($post_title, ENT_QUOTES, get_bloginfo('charset')),
176 176
 					'type'       => 'post_type',
177
-					'type_label' => get_post_type_object( $post->post_type )->labels->singular_name,
177
+					'type_label' => get_post_type_object($post->post_type)->labels->singular_name,
178 178
 					'object'     => $post->post_type,
179
-					'object_id'  => intval( $post->ID ),
180
-					'url'        => get_permalink( intval( $post->ID ) ),
179
+					'object_id'  => intval($post->ID),
180
+					'url'        => get_permalink(intval($post->ID)),
181 181
 				);
182 182
 			}
183
-		} elseif ( 'taxonomy' === $type ) {
184
-			$terms = get_terms( $object, array(
183
+		} elseif ('taxonomy' === $type) {
184
+			$terms = get_terms($object, array(
185 185
 				'child_of'     => 0,
186 186
 				'exclude'      => '',
187 187
 				'hide_empty'   => false,
@@ -192,20 +192,20 @@  discard block
 block discarded – undo
192 192
 				'order'        => 'DESC',
193 193
 				'orderby'      => 'count',
194 194
 				'pad_counts'   => false,
195
-			) );
196
-			if ( is_wp_error( $terms ) ) {
195
+			));
196
+			if (is_wp_error($terms)) {
197 197
 				return $terms;
198 198
 			}
199 199
 
200
-			foreach ( $terms as $term ) {
200
+			foreach ($terms as $term) {
201 201
 				$items[] = array(
202 202
 					'id'         => "term-{$term->term_id}",
203
-					'title'      => html_entity_decode( $term->name, ENT_QUOTES, get_bloginfo( 'charset' ) ),
203
+					'title'      => html_entity_decode($term->name, ENT_QUOTES, get_bloginfo('charset')),
204 204
 					'type'       => 'taxonomy',
205
-					'type_label' => get_taxonomy( $term->taxonomy )->labels->singular_name,
205
+					'type_label' => get_taxonomy($term->taxonomy)->labels->singular_name,
206 206
 					'object'     => $term->taxonomy,
207
-					'object_id'  => intval( $term->term_id ),
208
-					'url'        => get_term_link( intval( $term->term_id ), $term->taxonomy ),
207
+					'object_id'  => intval($term->term_id),
208
+					'url'        => get_term_link(intval($term->term_id), $term->taxonomy),
209 209
 				);
210 210
 			}
211 211
 		}
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 		 * @param string $object The object name.
221 221
 		 * @param int    $page   The current page number.
222 222
 		 */
223
-		$items = apply_filters( 'customize_nav_menu_available_items', $items, $type, $object, $page );
223
+		$items = apply_filters('customize_nav_menu_available_items', $items, $type, $object, $page);
224 224
 
225 225
 		return $items;
226 226
 	}
@@ -232,28 +232,28 @@  discard block
 block discarded – undo
232 232
 	 * @access public
233 233
 	 */
234 234
 	public function ajax_search_available_items() {
235
-		check_ajax_referer( 'customize-menus', 'customize-menus-nonce' );
235
+		check_ajax_referer('customize-menus', 'customize-menus-nonce');
236 236
 
237
-		if ( ! current_user_can( 'edit_theme_options' ) ) {
237
+		if ( ! current_user_can('edit_theme_options')) {
238 238
 			wp_die( -1 );
239 239
 		}
240 240
 
241
-		if ( empty( $_POST['search'] ) ) {
242
-			wp_send_json_error( 'nav_menus_missing_search_parameter' );
241
+		if (empty($_POST['search'])) {
242
+			wp_send_json_error('nav_menus_missing_search_parameter');
243 243
 		}
244 244
 
245
-		$p = isset( $_POST['page'] ) ? absint( $_POST['page'] ) : 0;
246
-		if ( $p < 1 ) {
245
+		$p = isset($_POST['page']) ? absint($_POST['page']) : 0;
246
+		if ($p < 1) {
247 247
 			$p = 1;
248 248
 		}
249 249
 
250
-		$s = sanitize_text_field( wp_unslash( $_POST['search'] ) );
251
-		$items = $this->search_available_items_query( array( 'pagenum' => $p, 's' => $s ) );
250
+		$s = sanitize_text_field(wp_unslash($_POST['search']));
251
+		$items = $this->search_available_items_query(array('pagenum' => $p, 's' => $s));
252 252
 
253
-		if ( empty( $items ) ) {
254
-			wp_send_json_error( array( 'message' => __( 'No results found.' ) ) );
253
+		if (empty($items)) {
254
+			wp_send_json_error(array('message' => __('No results found.')));
255 255
 		} else {
256
-			wp_send_json_success( array( 'items' => $items ) );
256
+			wp_send_json_success(array('items' => $items));
257 257
 		}
258 258
 	}
259 259
 
@@ -268,12 +268,12 @@  discard block
 block discarded – undo
268 268
 	 * @param array $args Optional. Accepts 'pagenum' and 's' (search) arguments.
269 269
 	 * @return array Menu items.
270 270
 	 */
271
-	public function search_available_items_query( $args = array() ) {
271
+	public function search_available_items_query($args = array()) {
272 272
 		$items = array();
273 273
 
274
-		$post_type_objects = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' );
274
+		$post_type_objects = get_post_types(array('show_in_nav_menus' => true), 'objects');
275 275
 		$query = array(
276
-			'post_type'              => array_keys( $post_type_objects ),
276
+			'post_type'              => array_keys($post_type_objects),
277 277
 			'suppress_filters'       => true,
278 278
 			'update_post_term_cache' => false,
279 279
 			'update_post_meta_cache' => false,
@@ -281,55 +281,55 @@  discard block
 block discarded – undo
281 281
 			'posts_per_page'         => 20,
282 282
 		);
283 283
 
284
-		$args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;
285
-		$query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
284
+		$args['pagenum'] = isset($args['pagenum']) ? absint($args['pagenum']) : 1;
285
+		$query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ($args['pagenum'] - 1) : 0;
286 286
 
287
-		if ( isset( $args['s'] ) ) {
287
+		if (isset($args['s'])) {
288 288
 			$query['s'] = $args['s'];
289 289
 		}
290 290
 
291 291
 		// Query posts.
292
-		$get_posts = new WP_Query( $query );
292
+		$get_posts = new WP_Query($query);
293 293
 
294 294
 		// Check if any posts were found.
295
-		if ( $get_posts->post_count ) {
296
-			foreach ( $get_posts->posts as $post ) {
295
+		if ($get_posts->post_count) {
296
+			foreach ($get_posts->posts as $post) {
297 297
 				$post_title = $post->post_title;
298
-				if ( '' === $post_title ) {
298
+				if ('' === $post_title) {
299 299
 					/* translators: %d: ID of a post */
300
-					$post_title = sprintf( __( '#%d (no title)' ), $post->ID );
300
+					$post_title = sprintf(__('#%d (no title)'), $post->ID);
301 301
 				}
302 302
 				$items[] = array(
303
-					'id'         => 'post-' . $post->ID,
304
-					'title'      => html_entity_decode( $post_title, ENT_QUOTES, get_bloginfo( 'charset' ) ),
303
+					'id'         => 'post-'.$post->ID,
304
+					'title'      => html_entity_decode($post_title, ENT_QUOTES, get_bloginfo('charset')),
305 305
 					'type'       => 'post_type',
306
-					'type_label' => $post_type_objects[ $post->post_type ]->labels->singular_name,
306
+					'type_label' => $post_type_objects[$post->post_type]->labels->singular_name,
307 307
 					'object'     => $post->post_type,
308
-					'object_id'  => intval( $post->ID ),
309
-					'url'        => get_permalink( intval( $post->ID ) ),
308
+					'object_id'  => intval($post->ID),
309
+					'url'        => get_permalink(intval($post->ID)),
310 310
 				);
311 311
 			}
312 312
 		}
313 313
 
314 314
 		// Query taxonomy terms.
315
-		$taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'names' );
316
-		$terms = get_terms( $taxonomies, array(
315
+		$taxonomies = get_taxonomies(array('show_in_nav_menus' => true), 'names');
316
+		$terms = get_terms($taxonomies, array(
317 317
 			'name__like' => $args['s'],
318 318
 			'number'     => 20,
319 319
 			'offset'     => 20 * ($args['pagenum'] - 1),
320
-		) );
320
+		));
321 321
 
322 322
 		// Check if any taxonomies were found.
323
-		if ( ! empty( $terms ) ) {
324
-			foreach ( $terms as $term ) {
323
+		if ( ! empty($terms)) {
324
+			foreach ($terms as $term) {
325 325
 				$items[] = array(
326
-					'id'         => 'term-' . $term->term_id,
327
-					'title'      => html_entity_decode( $term->name, ENT_QUOTES, get_bloginfo( 'charset' ) ),
326
+					'id'         => 'term-'.$term->term_id,
327
+					'title'      => html_entity_decode($term->name, ENT_QUOTES, get_bloginfo('charset')),
328 328
 					'type'       => 'taxonomy',
329
-					'type_label' => get_taxonomy( $term->taxonomy )->labels->singular_name,
329
+					'type_label' => get_taxonomy($term->taxonomy)->labels->singular_name,
330 330
 					'object'     => $term->taxonomy,
331
-					'object_id'  => intval( $term->term_id ),
332
-					'url'        => get_term_link( intval( $term->term_id ), $term->taxonomy ),
331
+					'object_id'  => intval($term->term_id),
332
+					'url'        => get_term_link(intval($term->term_id), $term->taxonomy),
333 333
 				);
334 334
 			}
335 335
 		}
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 		 * @param array $items The array of menu items.
343 343
 		 * @param array $args  Includes 'pagenum' and 's' (search) arguments.
344 344
 		 */
345
-		$items = apply_filters( 'customize_nav_menu_searched_items', $items, $args );
345
+		$items = apply_filters('customize_nav_menu_searched_items', $items, $args);
346 346
 
347 347
 		return $items;
348 348
 	}
@@ -354,44 +354,44 @@  discard block
 block discarded – undo
354 354
 	 * @access public
355 355
 	 */
356 356
 	public function enqueue_scripts() {
357
-		wp_enqueue_style( 'customize-nav-menus' );
358
-		wp_enqueue_script( 'customize-nav-menus' );
357
+		wp_enqueue_style('customize-nav-menus');
358
+		wp_enqueue_script('customize-nav-menus');
359 359
 
360
-		$temp_nav_menu_setting      = new WP_Customize_Nav_Menu_Setting( $this->manager, 'nav_menu[-1]' );
361
-		$temp_nav_menu_item_setting = new WP_Customize_Nav_Menu_Item_Setting( $this->manager, 'nav_menu_item[-1]' );
360
+		$temp_nav_menu_setting      = new WP_Customize_Nav_Menu_Setting($this->manager, 'nav_menu[-1]');
361
+		$temp_nav_menu_item_setting = new WP_Customize_Nav_Menu_Item_Setting($this->manager, 'nav_menu_item[-1]');
362 362
 
363 363
 		// Pass data to JS.
364 364
 		$settings = array(
365 365
 			'allMenus'             => wp_get_nav_menus(),
366 366
 			'itemTypes'            => $this->available_item_types(),
367 367
 			'l10n'                 => array(
368
-				'untitled'          => _x( '(no label)', 'missing menu item navigation label' ),
369
-				'unnamed'           => _x( '(unnamed)', 'Missing menu name.' ),
370
-				'custom_label'      => __( 'Custom Link' ),
368
+				'untitled'          => _x('(no label)', 'missing menu item navigation label'),
369
+				'unnamed'           => _x('(unnamed)', 'Missing menu name.'),
370
+				'custom_label'      => __('Custom Link'),
371 371
 				/* translators: %s: menu location */
372
-				'menuLocation'      => _x( '(Currently set to: %s)', 'menu' ),
373
-				'menuNameLabel'     => __( 'Menu Name' ),
374
-				'itemAdded'         => __( 'Menu item added' ),
375
-				'itemDeleted'       => __( 'Menu item deleted' ),
376
-				'menuAdded'         => __( 'Menu created' ),
377
-				'menuDeleted'       => __( 'Menu deleted' ),
378
-				'movedUp'           => __( 'Menu item moved up' ),
379
-				'movedDown'         => __( 'Menu item moved down' ),
380
-				'movedLeft'         => __( 'Menu item moved out of submenu' ),
381
-				'movedRight'        => __( 'Menu item is now a sub-item' ),
372
+				'menuLocation'      => _x('(Currently set to: %s)', 'menu'),
373
+				'menuNameLabel'     => __('Menu Name'),
374
+				'itemAdded'         => __('Menu item added'),
375
+				'itemDeleted'       => __('Menu item deleted'),
376
+				'menuAdded'         => __('Menu created'),
377
+				'menuDeleted'       => __('Menu deleted'),
378
+				'movedUp'           => __('Menu item moved up'),
379
+				'movedDown'         => __('Menu item moved down'),
380
+				'movedLeft'         => __('Menu item moved out of submenu'),
381
+				'movedRight'        => __('Menu item is now a sub-item'),
382 382
 				/* translators: &#9656; is the unicode right-pointing triangle, and %s is the section title in the Customizer */
383
-				'customizingMenus'  => sprintf( __( 'Customizing &#9656; %s' ), esc_html( $this->manager->get_panel( 'nav_menus' )->title ) ),
383
+				'customizingMenus'  => sprintf(__('Customizing &#9656; %s'), esc_html($this->manager->get_panel('nav_menus')->title)),
384 384
 				/* translators: %s: title of menu item which is invalid */
385
-				'invalidTitleTpl'   => __( '%s (Invalid)' ),
385
+				'invalidTitleTpl'   => __('%s (Invalid)'),
386 386
 				/* translators: %s: title of menu item in draft status */
387
-				'pendingTitleTpl'   => __( '%s (Pending)' ),
388
-				'itemsFound'        => __( 'Number of items found: %d' ),
389
-				'itemsFoundMore'    => __( 'Additional items found: %d' ),
390
-				'itemsLoadingMore'  => __( 'Loading more results... please wait.' ),
391
-				'reorderModeOn'     => __( 'Reorder mode enabled' ),
392
-				'reorderModeOff'    => __( 'Reorder mode closed' ),
393
-				'reorderLabelOn'    => esc_attr__( 'Reorder menu items' ),
394
-				'reorderLabelOff'   => esc_attr__( 'Close reorder mode' ),
387
+				'pendingTitleTpl'   => __('%s (Pending)'),
388
+				'itemsFound'        => __('Number of items found: %d'),
389
+				'itemsFoundMore'    => __('Additional items found: %d'),
390
+				'itemsLoadingMore'  => __('Loading more results... please wait.'),
391
+				'reorderModeOn'     => __('Reorder mode enabled'),
392
+				'reorderModeOff'    => __('Reorder mode closed'),
393
+				'reorderLabelOn'    => esc_attr__('Reorder menu items'),
394
+				'reorderLabelOff'   => esc_attr__('Close reorder mode'),
395 395
 			),
396 396
 			'settingTransport'     => 'postMessage',
397 397
 			'phpIntMax'            => PHP_INT_MAX,
@@ -402,29 +402,29 @@  discard block
 block discarded – undo
402 402
 			'locationSlugMappedToName' => get_registered_nav_menus(),
403 403
 		);
404 404
 
405
-		$data = sprintf( 'var _wpCustomizeNavMenusSettings = %s;', wp_json_encode( $settings ) );
406
-		wp_scripts()->add_data( 'customize-nav-menus', 'data', $data );
405
+		$data = sprintf('var _wpCustomizeNavMenusSettings = %s;', wp_json_encode($settings));
406
+		wp_scripts()->add_data('customize-nav-menus', 'data', $data);
407 407
 
408 408
 		// This is copied from nav-menus.php, and it has an unfortunate object name of `menus`.
409 409
 		$nav_menus_l10n = array(
410 410
 			'oneThemeLocationNoMenus' => null,
411
-			'moveUp'       => __( 'Move up one' ),
412
-			'moveDown'     => __( 'Move down one' ),
413
-			'moveToTop'    => __( 'Move to the top' ),
411
+			'moveUp'       => __('Move up one'),
412
+			'moveDown'     => __('Move down one'),
413
+			'moveToTop'    => __('Move to the top'),
414 414
 			/* translators: %s: previous item name */
415
-			'moveUnder'    => __( 'Move under %s' ),
415
+			'moveUnder'    => __('Move under %s'),
416 416
 			/* translators: %s: previous item name */
417
-			'moveOutFrom'  => __( 'Move out from under %s' ),
417
+			'moveOutFrom'  => __('Move out from under %s'),
418 418
 			/* translators: %s: previous item name */
419
-			'under'        => __( 'Under %s' ),
419
+			'under'        => __('Under %s'),
420 420
 			/* translators: %s: previous item name */
421
-			'outFrom'      => __( 'Out from under %s' ),
421
+			'outFrom'      => __('Out from under %s'),
422 422
 			/* translators: 1: item name, 2: item position, 3: total number of items */
423
-			'menuFocus'    => __( '%1$s. Menu item %2$d of %3$d.' ),
423
+			'menuFocus'    => __('%1$s. Menu item %2$d of %3$d.'),
424 424
 			/* translators: 1: item name, 2: item position, 3: parent item name */
425
-			'subMenuFocus' => __( '%1$s. Sub item number %2$d under %3$s.' ),
425
+			'subMenuFocus' => __('%1$s. Sub item number %2$d under %3$s.'),
426 426
 		);
427
-		wp_localize_script( 'nav-menu', 'menus', $nav_menus_l10n );
427
+		wp_localize_script('nav-menu', 'menus', $nav_menus_l10n);
428 428
 	}
429 429
 
430 430
 	/**
@@ -441,13 +441,13 @@  discard block
 block discarded – undo
441 441
 	 * @param string      $setting_id   ID for dynamic setting, usually coming from `$_POST['customized']`.
442 442
 	 * @return array|false
443 443
 	 */
444
-	public function filter_dynamic_setting_args( $setting_args, $setting_id ) {
445
-		if ( preg_match( WP_Customize_Nav_Menu_Setting::ID_PATTERN, $setting_id ) ) {
444
+	public function filter_dynamic_setting_args($setting_args, $setting_id) {
445
+		if (preg_match(WP_Customize_Nav_Menu_Setting::ID_PATTERN, $setting_id)) {
446 446
 			$setting_args = array(
447 447
 				'type'      => WP_Customize_Nav_Menu_Setting::TYPE,
448 448
 				'transport' => 'postMessage',
449 449
 			);
450
-		} elseif ( preg_match( WP_Customize_Nav_Menu_Item_Setting::ID_PATTERN, $setting_id ) ) {
450
+		} elseif (preg_match(WP_Customize_Nav_Menu_Item_Setting::ID_PATTERN, $setting_id)) {
451 451
 			$setting_args = array(
452 452
 				'type'      => WP_Customize_Nav_Menu_Item_Setting::TYPE,
453 453
 				'transport' => 'postMessage',
@@ -467,12 +467,12 @@  discard block
 block discarded – undo
467 467
 	 * @param array  $setting_args  WP_Customize_Setting or a subclass.
468 468
 	 * @return string
469 469
 	 */
470
-	public function filter_dynamic_setting_class( $setting_class, $setting_id, $setting_args ) {
471
-		unset( $setting_id );
470
+	public function filter_dynamic_setting_class($setting_class, $setting_id, $setting_args) {
471
+		unset($setting_id);
472 472
 
473
-		if ( ! empty( $setting_args['type'] ) && WP_Customize_Nav_Menu_Setting::TYPE === $setting_args['type'] ) {
473
+		if ( ! empty($setting_args['type']) && WP_Customize_Nav_Menu_Setting::TYPE === $setting_args['type']) {
474 474
 			$setting_class = 'WP_Customize_Nav_Menu_Setting';
475
-		} elseif ( ! empty( $setting_args['type'] ) && WP_Customize_Nav_Menu_Item_Setting::TYPE === $setting_args['type'] ) {
475
+		} elseif ( ! empty($setting_args['type']) && WP_Customize_Nav_Menu_Item_Setting::TYPE === $setting_args['type']) {
476 476
 			$setting_class = 'WP_Customize_Nav_Menu_Item_Setting';
477 477
 		}
478 478
 		return $setting_class;
@@ -487,145 +487,145 @@  discard block
 block discarded – undo
487 487
 	public function customize_register() {
488 488
 
489 489
 		// Require JS-rendered control types.
490
-		$this->manager->register_panel_type( 'WP_Customize_Nav_Menus_Panel' );
491
-		$this->manager->register_control_type( 'WP_Customize_Nav_Menu_Control' );
492
-		$this->manager->register_control_type( 'WP_Customize_Nav_Menu_Name_Control' );
493
-		$this->manager->register_control_type( 'WP_Customize_Nav_Menu_Auto_Add_Control' );
494
-		$this->manager->register_control_type( 'WP_Customize_Nav_Menu_Item_Control' );
490
+		$this->manager->register_panel_type('WP_Customize_Nav_Menus_Panel');
491
+		$this->manager->register_control_type('WP_Customize_Nav_Menu_Control');
492
+		$this->manager->register_control_type('WP_Customize_Nav_Menu_Name_Control');
493
+		$this->manager->register_control_type('WP_Customize_Nav_Menu_Auto_Add_Control');
494
+		$this->manager->register_control_type('WP_Customize_Nav_Menu_Item_Control');
495 495
 
496 496
 		// Create a panel for Menus.
497
-		$description = '<p>' . __( 'This panel is used for managing navigation menus for content you have already published on your site. You can create menus and add items for existing content such as pages, posts, categories, tags, formats, or custom links.' ) . '</p>';
498
-		if ( current_theme_supports( 'widgets' ) ) {
497
+		$description = '<p>'.__('This panel is used for managing navigation menus for content you have already published on your site. You can create menus and add items for existing content such as pages, posts, categories, tags, formats, or custom links.').'</p>';
498
+		if (current_theme_supports('widgets')) {
499 499
 			/* translators: URL to the widgets panel of the customizer */
500
-			$description .= '<p>' . sprintf( __( 'Menus can be displayed in locations defined by your theme or in <a href="%s">widget areas</a> by adding a &#8220;Custom Menu&#8221; widget.' ), "javascript:wp.customize.panel( 'widgets' ).focus();" ) . '</p>';
500
+			$description .= '<p>'.sprintf(__('Menus can be displayed in locations defined by your theme or in <a href="%s">widget areas</a> by adding a &#8220;Custom Menu&#8221; widget.'), "javascript:wp.customize.panel( 'widgets' ).focus();").'</p>';
501 501
 		} else {
502
-			$description .= '<p>' . __( 'Menus can be displayed in locations defined by your theme.' ) . '</p>';
502
+			$description .= '<p>'.__('Menus can be displayed in locations defined by your theme.').'</p>';
503 503
 		}
504
-		$this->manager->add_panel( new WP_Customize_Nav_Menus_Panel( $this->manager, 'nav_menus', array(
505
-			'title'       => __( 'Menus' ),
504
+		$this->manager->add_panel(new WP_Customize_Nav_Menus_Panel($this->manager, 'nav_menus', array(
505
+			'title'       => __('Menus'),
506 506
 			'description' => $description,
507 507
 			'priority'    => 100,
508 508
 			// 'theme_supports' => 'menus|widgets', @todo allow multiple theme supports
509
-		) ) );
509
+		)));
510 510
 		$menus = wp_get_nav_menus();
511 511
 
512 512
 		// Menu locations.
513 513
 		$locations     = get_registered_nav_menus();
514
-		$num_locations = count( array_keys( $locations ) );
515
-		if ( 1 == $num_locations ) {
516
-			$description = '<p>' . __( 'Your theme supports one menu. Select which menu you would like to use.' ) . '</p>';
514
+		$num_locations = count(array_keys($locations));
515
+		if (1 == $num_locations) {
516
+			$description = '<p>'.__('Your theme supports one menu. Select which menu you would like to use.').'</p>';
517 517
 		} else {
518 518
 			/* translators: %s: number of menu locations */
519
-			$description = '<p>' . sprintf( _n( 'Your theme supports %s menu. Select which menu appears in each location.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations ), number_format_i18n( $num_locations ) ) . '</p>';
519
+			$description = '<p>'.sprintf(_n('Your theme supports %s menu. Select which menu appears in each location.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations), number_format_i18n($num_locations)).'</p>';
520 520
 		}
521
-		if ( current_theme_supports( 'widgets' ) ) {
521
+		if (current_theme_supports('widgets')) {
522 522
 			/* translators: URL to the widgets panel of the customizer */
523
-			$description .= '<p>' . sprintf( __( 'You can also place menus in <a href="%s">widget areas</a> with the &#8220;Custom Menu&#8221; widget.' ), "javascript:wp.customize.panel( 'widgets' ).focus();" ) . '</p>';
523
+			$description .= '<p>'.sprintf(__('You can also place menus in <a href="%s">widget areas</a> with the &#8220;Custom Menu&#8221; widget.'), "javascript:wp.customize.panel( 'widgets' ).focus();").'</p>';
524 524
 		}
525 525
 
526
-		$this->manager->add_section( 'menu_locations', array(
527
-			'title'       => __( 'Menu Locations' ),
526
+		$this->manager->add_section('menu_locations', array(
527
+			'title'       => __('Menu Locations'),
528 528
 			'panel'       => 'nav_menus',
529 529
 			'priority'    => 5,
530 530
 			'description' => $description,
531
-		) );
531
+		));
532 532
 
533
-		$choices = array( '0' => __( '&mdash; Select &mdash;' ) );
534
-		foreach ( $menus as $menu ) {
535
-			$choices[ $menu->term_id ] = wp_html_excerpt( $menu->name, 40, '&hellip;' );
533
+		$choices = array('0' => __('&mdash; Select &mdash;'));
534
+		foreach ($menus as $menu) {
535
+			$choices[$menu->term_id] = wp_html_excerpt($menu->name, 40, '&hellip;');
536 536
 		}
537 537
 
538
-		foreach ( $locations as $location => $description ) {
538
+		foreach ($locations as $location => $description) {
539 539
 			$setting_id = "nav_menu_locations[{$location}]";
540 540
 
541
-			$setting = $this->manager->get_setting( $setting_id );
542
-			if ( $setting ) {
541
+			$setting = $this->manager->get_setting($setting_id);
542
+			if ($setting) {
543 543
 				$setting->transport = 'postMessage';
544
-				remove_filter( "customize_sanitize_{$setting_id}", 'absint' );
545
-				add_filter( "customize_sanitize_{$setting_id}", array( $this, 'intval_base10' ) );
544
+				remove_filter("customize_sanitize_{$setting_id}", 'absint');
545
+				add_filter("customize_sanitize_{$setting_id}", array($this, 'intval_base10'));
546 546
 			} else {
547
-				$this->manager->add_setting( $setting_id, array(
548
-					'sanitize_callback' => array( $this, 'intval_base10' ),
547
+				$this->manager->add_setting($setting_id, array(
548
+					'sanitize_callback' => array($this, 'intval_base10'),
549 549
 					'theme_supports'    => 'menus',
550 550
 					'type'              => 'theme_mod',
551 551
 					'transport'         => 'postMessage',
552 552
 					'default'           => 0,
553
-				) );
553
+				));
554 554
 			}
555 555
 
556
-			$this->manager->add_control( new WP_Customize_Nav_Menu_Location_Control( $this->manager, $setting_id, array(
556
+			$this->manager->add_control(new WP_Customize_Nav_Menu_Location_Control($this->manager, $setting_id, array(
557 557
 				'label'       => $description,
558 558
 				'location_id' => $location,
559 559
 				'section'     => 'menu_locations',
560 560
 				'choices'     => $choices,
561
-			) ) );
561
+			)));
562 562
 		}
563 563
 
564 564
 		// Register each menu as a Customizer section, and add each menu item to each menu.
565
-		foreach ( $menus as $menu ) {
565
+		foreach ($menus as $menu) {
566 566
 			$menu_id = $menu->term_id;
567 567
 
568 568
 			// Create a section for each menu.
569
-			$section_id = 'nav_menu[' . $menu_id . ']';
570
-			$this->manager->add_section( new WP_Customize_Nav_Menu_Section( $this->manager, $section_id, array(
571
-				'title'     => html_entity_decode( $menu->name, ENT_QUOTES, get_bloginfo( 'charset' ) ),
569
+			$section_id = 'nav_menu['.$menu_id.']';
570
+			$this->manager->add_section(new WP_Customize_Nav_Menu_Section($this->manager, $section_id, array(
571
+				'title'     => html_entity_decode($menu->name, ENT_QUOTES, get_bloginfo('charset')),
572 572
 				'priority'  => 10,
573 573
 				'panel'     => 'nav_menus',
574
-			) ) );
574
+			)));
575 575
 
576
-			$nav_menu_setting_id = 'nav_menu[' . $menu_id . ']';
577
-			$this->manager->add_setting( new WP_Customize_Nav_Menu_Setting( $this->manager, $nav_menu_setting_id, array(
576
+			$nav_menu_setting_id = 'nav_menu['.$menu_id.']';
577
+			$this->manager->add_setting(new WP_Customize_Nav_Menu_Setting($this->manager, $nav_menu_setting_id, array(
578 578
 				'transport' => 'postMessage',
579
-			) ) );
579
+			)));
580 580
 
581 581
 			// Add the menu contents.
582
-			$menu_items = (array) wp_get_nav_menu_items( $menu_id );
582
+			$menu_items = (array) wp_get_nav_menu_items($menu_id);
583 583
 
584
-			foreach ( array_values( $menu_items ) as $i => $item ) {
584
+			foreach (array_values($menu_items) as $i => $item) {
585 585
 
586 586
 				// Create a setting for each menu item (which doesn't actually manage data, currently).
587
-				$menu_item_setting_id = 'nav_menu_item[' . $item->ID . ']';
587
+				$menu_item_setting_id = 'nav_menu_item['.$item->ID.']';
588 588
 
589 589
 				$value = (array) $item;
590 590
 				$value['nav_menu_term_id'] = $menu_id;
591
-				$this->manager->add_setting( new WP_Customize_Nav_Menu_Item_Setting( $this->manager, $menu_item_setting_id, array(
591
+				$this->manager->add_setting(new WP_Customize_Nav_Menu_Item_Setting($this->manager, $menu_item_setting_id, array(
592 592
 					'value'     => $value,
593 593
 					'transport' => 'postMessage',
594
-				) ) );
594
+				)));
595 595
 
596 596
 				// Create a control for each menu item.
597
-				$this->manager->add_control( new WP_Customize_Nav_Menu_Item_Control( $this->manager, $menu_item_setting_id, array(
597
+				$this->manager->add_control(new WP_Customize_Nav_Menu_Item_Control($this->manager, $menu_item_setting_id, array(
598 598
 					'label'    => $item->title,
599 599
 					'section'  => $section_id,
600 600
 					'priority' => 10 + $i,
601
-				) ) );
601
+				)));
602 602
 			}
603 603
 
604 604
 			// Note: other controls inside of this section get added dynamically in JS via the MenuSection.ready() function.
605 605
 		}
606 606
 
607 607
 		// Add the add-new-menu section and controls.
608
-		$this->manager->add_section( new WP_Customize_New_Menu_Section( $this->manager, 'add_menu', array(
609
-			'title'    => __( 'Add a Menu' ),
608
+		$this->manager->add_section(new WP_Customize_New_Menu_Section($this->manager, 'add_menu', array(
609
+			'title'    => __('Add a Menu'),
610 610
 			'panel'    => 'nav_menus',
611 611
 			'priority' => 999,
612
-		) ) );
612
+		)));
613 613
 
614
-		$this->manager->add_control( 'new_menu_name', array(
614
+		$this->manager->add_control('new_menu_name', array(
615 615
 			'label'       => '',
616 616
 			'section'     => 'add_menu',
617 617
 			'type'        => 'text',
618 618
 			'settings'    => array(),
619 619
 			'input_attrs' => array(
620 620
 				'class'       => 'menu-name-field',
621
-				'placeholder' => __( 'New menu name' ),
621
+				'placeholder' => __('New menu name'),
622 622
 			),
623
-		) );
623
+		));
624 624
 
625
-		$this->manager->add_control( new WP_Customize_New_Menu_Control( $this->manager, 'create_new_menu', array(
625
+		$this->manager->add_control(new WP_Customize_New_Menu_Control($this->manager, 'create_new_menu', array(
626 626
 			'section'  => 'add_menu',
627 627
 			'settings' => array(),
628
-		) ) );
628
+		)));
629 629
 	}
630 630
 
631 631
 	/**
@@ -640,8 +640,8 @@  discard block
 block discarded – undo
640 640
 	 * @param mixed $value Number to convert.
641 641
 	 * @return int Integer.
642 642
 	 */
643
-	public function intval_base10( $value ) {
644
-		return intval( $value, 10 );
643
+	public function intval_base10($value) {
644
+		return intval($value, 10);
645 645
 	}
646 646
 
647 647
 	/**
@@ -655,9 +655,9 @@  discard block
 block discarded – undo
655 655
 	public function available_item_types() {
656 656
 		$item_types = array();
657 657
 
658
-		$post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' );
659
-		if ( $post_types ) {
660
-			foreach ( $post_types as $slug => $post_type ) {
658
+		$post_types = get_post_types(array('show_in_nav_menus' => true), 'objects');
659
+		if ($post_types) {
660
+			foreach ($post_types as $slug => $post_type) {
661 661
 				$item_types[] = array(
662 662
 					'title'  => $post_type->labels->name,
663 663
 					'type'   => 'post_type',
@@ -666,10 +666,10 @@  discard block
 block discarded – undo
666 666
 			}
667 667
 		}
668 668
 
669
-		$taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'objects' );
670
-		if ( $taxonomies ) {
671
-			foreach ( $taxonomies as $slug => $taxonomy ) {
672
-				if ( 'post_format' === $taxonomy && ! current_theme_supports( 'post-formats' ) ) {
669
+		$taxonomies = get_taxonomies(array('show_in_nav_menus' => true), 'objects');
670
+		if ($taxonomies) {
671
+			foreach ($taxonomies as $slug => $taxonomy) {
672
+				if ('post_format' === $taxonomy && ! current_theme_supports('post-formats')) {
673 673
 					continue;
674 674
 				}
675 675
 				$item_types[] = array(
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
 		 *
688 688
 		 * @param array $item_types Custom menu item types.
689 689
 		 */
690
-		$item_types = apply_filters( 'customize_nav_menu_available_item_types', $item_types );
690
+		$item_types = apply_filters('customize_nav_menu_available_item_types', $item_types);
691 691
 
692 692
 		return $item_types;
693 693
 	}
@@ -713,7 +713,7 @@  discard block
 block discarded – undo
713 713
 						<button type="button" class="button-link item-add">
714 714
 							<span class="screen-reader-text"><?php
715 715
 								/* translators: 1: Title of a menu item, 2: Type of a menu item */
716
-								printf( __( 'Add to menu: %1$s (%2$s)' ), '{{ data.title || wp.customize.Menus.data.l10n.untitled }}', '{{ data.type_label }}' );
716
+								printf(__('Add to menu: %1$s (%2$s)'), '{{ data.title || wp.customize.Menus.data.l10n.untitled }}', '{{ data.type_label }}');
717 717
 							?></span>
718 718
 						</button>
719 719
 					</div>
@@ -726,10 +726,10 @@  discard block
 block discarded – undo
726 726
 				<?php
727 727
 				printf(
728 728
 					'<button type="button" class="menus-move-up">%1$s</button><button type="button" class="menus-move-down">%2$s</button><button type="button" class="menus-move-left">%3$s</button><button type="button" class="menus-move-right">%4$s</button>',
729
-					__( 'Move up' ),
730
-					__( 'Move down' ),
731
-					__( 'Move one level up' ),
732
-					__( 'Move one level down' )
729
+					__('Move up'),
730
+					__('Move down'),
731
+					__('Move one level up'),
732
+					__('Move one level down')
733 733
 				);
734 734
 				?>
735 735
 			</div>
@@ -748,49 +748,49 @@  discard block
 block discarded – undo
748 748
 		<div id="available-menu-items" class="accordion-container">
749 749
 			<div class="customize-section-title">
750 750
 				<button type="button" class="customize-section-back" tabindex="-1">
751
-					<span class="screen-reader-text"><?php _e( 'Back' ); ?></span>
751
+					<span class="screen-reader-text"><?php _e('Back'); ?></span>
752 752
 				</button>
753 753
 				<h3>
754 754
 					<span class="customize-action">
755 755
 						<?php
756 756
 							/* translators: &#9656; is the unicode right-pointing triangle, and %s is the section title in the Customizer */
757
-							printf( __( 'Customizing &#9656; %s' ), esc_html( $this->manager->get_panel( 'nav_menus' )->title ) );
757
+							printf(__('Customizing &#9656; %s'), esc_html($this->manager->get_panel('nav_menus')->title));
758 758
 						?>
759 759
 					</span>
760
-					<?php _e( 'Add Menu Items' ); ?>
760
+					<?php _e('Add Menu Items'); ?>
761 761
 				</h3>
762 762
 			</div>
763 763
 			<div id="available-menu-items-search" class="accordion-section cannot-expand">
764 764
 				<div class="accordion-section-title">
765
-					<label class="screen-reader-text" for="menu-items-search"><?php _e( 'Search Menu Items' ); ?></label>
766
-					<input type="text" id="menu-items-search" placeholder="<?php esc_attr_e( 'Search menu items&hellip;' ) ?>" aria-describedby="menu-items-search-desc" />
767
-					<p class="screen-reader-text" id="menu-items-search-desc"><?php _e( 'The search results will be updated as you type.' ); ?></p>
765
+					<label class="screen-reader-text" for="menu-items-search"><?php _e('Search Menu Items'); ?></label>
766
+					<input type="text" id="menu-items-search" placeholder="<?php esc_attr_e('Search menu items&hellip;') ?>" aria-describedby="menu-items-search-desc" />
767
+					<p class="screen-reader-text" id="menu-items-search-desc"><?php _e('The search results will be updated as you type.'); ?></p>
768 768
 					<span class="spinner"></span>
769 769
 				</div>
770
-				<button type="button" class="clear-results"><span class="screen-reader-text"><?php _e( 'Clear Results' ); ?></span></button>
770
+				<button type="button" class="clear-results"><span class="screen-reader-text"><?php _e('Clear Results'); ?></span></button>
771 771
 				<ul class="accordion-section-content" data-type="search"></ul>
772 772
 			</div>
773 773
 			<div id="new-custom-menu-item" class="accordion-section">
774 774
 				<h4 class="accordion-section-title" role="presentation">
775
-					<?php _e( 'Custom Links' ); ?>
775
+					<?php _e('Custom Links'); ?>
776 776
 					<button type="button" class="button-link" aria-expanded="false">
777
-						<span class="screen-reader-text"><?php _e( 'Toggle section: Custom Links' ); ?></span>
777
+						<span class="screen-reader-text"><?php _e('Toggle section: Custom Links'); ?></span>
778 778
 						<span class="toggle-indicator" aria-hidden="true"></span>
779 779
 					</button>
780 780
 				</h4>
781 781
 				<div class="accordion-section-content customlinkdiv">
782 782
 					<input type="hidden" value="custom" id="custom-menu-item-type" name="menu-item[-1][menu-item-type]" />
783 783
 					<p id="menu-item-url-wrap" class="wp-clearfix">
784
-						<label class="howto" for="custom-menu-item-url"><?php _e( 'URL' ); ?></label>
784
+						<label class="howto" for="custom-menu-item-url"><?php _e('URL'); ?></label>
785 785
 						<input id="custom-menu-item-url" name="menu-item[-1][menu-item-url]" type="text" class="code menu-item-textbox" value="http://">
786 786
 					</p>
787 787
 					<p id="menu-item-name-wrap" class="wp-clearfix">
788
-						<label class="howto" for="custom-menu-item-name"><?php _e( 'Link Text' ); ?></label>
788
+						<label class="howto" for="custom-menu-item-name"><?php _e('Link Text'); ?></label>
789 789
 						<input id="custom-menu-item-name" name="menu-item[-1][menu-item-title]" type="text" class="regular-text menu-item-textbox">
790 790
 					</p>
791 791
 					<p class="button-controls">
792 792
 						<span class="add-to-menu">
793
-							<input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" name="add-custom-menu-item" id="custom-menu-item-submit">
793
+							<input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-custom-menu-item" id="custom-menu-item-submit">
794 794
 							<span class="spinner"></span>
795 795
 						</span>
796 796
 					</p>
@@ -798,22 +798,22 @@  discard block
 block discarded – undo
798 798
 			</div>
799 799
 			<?php
800 800
 			// Containers for per-post-type item browsing; items added with JS.
801
-			foreach ( $this->available_item_types() as $available_item_type ) {
802
-				$id = sprintf( 'available-menu-items-%s-%s', $available_item_type['type'], $available_item_type['object'] );
801
+			foreach ($this->available_item_types() as $available_item_type) {
802
+				$id = sprintf('available-menu-items-%s-%s', $available_item_type['type'], $available_item_type['object']);
803 803
 				?>
804
-				<div id="<?php echo esc_attr( $id ); ?>" class="accordion-section">
804
+				<div id="<?php echo esc_attr($id); ?>" class="accordion-section">
805 805
 					<h4 class="accordion-section-title" role="presentation">
806
-						<?php echo esc_html( $available_item_type['title'] ); ?>
806
+						<?php echo esc_html($available_item_type['title']); ?>
807 807
 						<span class="spinner"></span>
808
-						<span class="no-items"><?php _e( 'No items' ); ?></span>
808
+						<span class="no-items"><?php _e('No items'); ?></span>
809 809
 						<button type="button" class="button-link" aria-expanded="false">
810 810
 							<span class="screen-reader-text"><?php
811 811
 							/* translators: %s: Title of a section with menu items */
812
-							printf( __( 'Toggle section: %s' ), esc_html( $available_item_type['title'] ) ); ?></span>
812
+							printf(__('Toggle section: %s'), esc_html($available_item_type['title'])); ?></span>
813 813
 							<span class="toggle-indicator" aria-hidden="true"></span>
814 814
 						</button>
815 815
 					</h4>
816
-					<ul class="accordion-section-content" data-type="<?php echo esc_attr( $available_item_type['type'] ); ?>" data-object="<?php echo esc_attr( $available_item_type['object'] ); ?>"></ul>
816
+					<ul class="accordion-section-content" data-type="<?php echo esc_attr($available_item_type['type']); ?>" data-object="<?php echo esc_attr($available_item_type['object']); ?>"></ul>
817 817
 				</div>
818 818
 				<?php
819 819
 			}
@@ -845,17 +845,17 @@  discard block
 block discarded – undo
845 845
 	 * @param string      $partial_id   Partial ID.
846 846
 	 * @return array Partial args.
847 847
 	 */
848
-	public function customize_dynamic_partial_args( $partial_args, $partial_id ) {
848
+	public function customize_dynamic_partial_args($partial_args, $partial_id) {
849 849
 
850
-		if ( preg_match( '/^nav_menu_instance\[[0-9a-f]{32}\]$/', $partial_id ) ) {
851
-			if ( false === $partial_args ) {
850
+		if (preg_match('/^nav_menu_instance\[[0-9a-f]{32}\]$/', $partial_id)) {
851
+			if (false === $partial_args) {
852 852
 				$partial_args = array();
853 853
 			}
854 854
 			$partial_args = array_merge(
855 855
 				$partial_args,
856 856
 				array(
857 857
 					'type'                => 'nav_menu_instance',
858
-					'render_callback'     => array( $this, 'render_nav_menu_partial' ),
858
+					'render_callback'     => array($this, 'render_nav_menu_partial'),
859 859
 					'container_inclusive' => true,
860 860
 					'settings'            => array(), // Empty because the nav menu instance may relate to a menu or a location.
861 861
 					'capability'          => 'edit_theme_options',
@@ -873,11 +873,11 @@  discard block
 block discarded – undo
873 873
 	 * @access public
874 874
 	 */
875 875
 	public function customize_preview_init() {
876
-		add_action( 'wp_enqueue_scripts', array( $this, 'customize_preview_enqueue_deps' ) );
877
-		add_filter( 'wp_nav_menu_args', array( $this, 'filter_wp_nav_menu_args' ), 1000 );
878
-		add_filter( 'wp_nav_menu', array( $this, 'filter_wp_nav_menu' ), 10, 2 );
879
-		add_filter( 'wp_footer', array( $this, 'export_preview_data' ), 1 );
880
-		add_filter( 'customize_render_partials_response', array( $this, 'export_partial_rendered_nav_menu_instances' ) );
876
+		add_action('wp_enqueue_scripts', array($this, 'customize_preview_enqueue_deps'));
877
+		add_filter('wp_nav_menu_args', array($this, 'filter_wp_nav_menu_args'), 1000);
878
+		add_filter('wp_nav_menu', array($this, 'filter_wp_nav_menu'), 10, 2);
879
+		add_filter('wp_footer', array($this, 'export_preview_data'), 1);
880
+		add_filter('customize_render_partials_response', array($this, 'export_partial_rendered_nav_menu_instances'));
881 881
 	}
882 882
 
883 883
 	/**
@@ -891,7 +891,7 @@  discard block
 block discarded – undo
891 891
 	 * @param array $args An array containing wp_nav_menu() arguments.
892 892
 	 * @return array Arguments.
893 893
 	 */
894
-	public function filter_wp_nav_menu_args( $args ) {
894
+	public function filter_wp_nav_menu_args($args) {
895 895
 		/*
896 896
 		 * The following conditions determine whether or not this instance of
897 897
 		 * wp_nav_menu() can use selective refreshed. A wp_nav_menu() can be
@@ -899,25 +899,25 @@  discard block
 block discarded – undo
899 899
 		 */
900 900
 		$can_partial_refresh = (
901 901
 			// ...if wp_nav_menu() is directly echoing out the menu (and thus isn't manipulating the string after generated),
902
-			! empty( $args['echo'] )
902
+			! empty($args['echo'])
903 903
 			&&
904 904
 			// ...and if the fallback_cb can be serialized to JSON, since it will be included in the placement context data,
905
-			( empty( $args['fallback_cb'] ) || is_string( $args['fallback_cb'] ) )
905
+			(empty($args['fallback_cb']) || is_string($args['fallback_cb']))
906 906
 			&&
907 907
 			// ...and if the walker can also be serialized to JSON, since it will be included in the placement context data as well,
908
-			( empty( $args['walker'] ) || is_string( $args['walker'] ) )
908
+			(empty($args['walker']) || is_string($args['walker']))
909 909
 			// ...and if it has a theme location assigned or an assigned menu to display,
910 910
 			&& (
911
-				! empty( $args['theme_location'] )
911
+				! empty($args['theme_location'])
912 912
 				||
913
-				( ! empty( $args['menu'] ) && ( is_numeric( $args['menu'] ) || is_object( $args['menu'] ) ) )
913
+				( ! empty($args['menu']) && (is_numeric($args['menu']) || is_object($args['menu'])))
914 914
 			)
915 915
 			&&
916 916
 			// ...and if the nav menu would be rendered with a wrapper container element (upon which to attach data-* attributes).
917 917
 			(
918
-				! empty( $args['container'] )
918
+				! empty($args['container'])
919 919
 				||
920
-				( isset( $args['items_wrap'] ) && '<' === substr( $args['items_wrap'], 0, 1 ) )
920
+				(isset($args['items_wrap']) && '<' === substr($args['items_wrap'], 0, 1))
921 921
 			)
922 922
 		);
923 923
 		$args['can_partial_refresh'] = $can_partial_refresh;
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
 		$exported_args = $args;
926 926
 
927 927
 		// Empty out args which may not be JSON-serializable.
928
-		if ( ! $can_partial_refresh ) {
928
+		if ( ! $can_partial_refresh) {
929 929
 			$exported_args['fallback_cb'] = '';
930 930
 			$exported_args['walker'] = '';
931 931
 		}
@@ -934,15 +934,15 @@  discard block
 block discarded – undo
934 934
 		 * Replace object menu arg with a term_id menu arg, as this exports better
935 935
 		 * to JS and is easier to compare hashes.
936 936
 		 */
937
-		if ( ! empty( $exported_args['menu'] ) && is_object( $exported_args['menu'] ) ) {
937
+		if ( ! empty($exported_args['menu']) && is_object($exported_args['menu'])) {
938 938
 			$exported_args['menu'] = $exported_args['menu']->term_id;
939 939
 		}
940 940
 
941
-		ksort( $exported_args );
942
-		$exported_args['args_hmac'] = $this->hash_nav_menu_args( $exported_args );
941
+		ksort($exported_args);
942
+		$exported_args['args_hmac'] = $this->hash_nav_menu_args($exported_args);
943 943
 
944 944
 		$args['customize_preview_nav_menus_args'] = $exported_args;
945
-		$this->preview_nav_menu_instance_args[ $exported_args['args_hmac'] ] = $exported_args;
945
+		$this->preview_nav_menu_instance_args[$exported_args['args_hmac']] = $exported_args;
946 946
 		return $args;
947 947
 	}
948 948
 
@@ -960,12 +960,12 @@  discard block
 block discarded – undo
960 960
 	 * @param object $args             An object containing wp_nav_menu() arguments.
961 961
 	 * @return null
962 962
 	 */
963
-	public function filter_wp_nav_menu( $nav_menu_content, $args ) {
964
-		if ( isset( $args->customize_preview_nav_menus_args['can_partial_refresh'] ) && $args->customize_preview_nav_menus_args['can_partial_refresh'] ) {
965
-			$attributes = sprintf( ' data-customize-partial-id="%s"', esc_attr( 'nav_menu_instance[' . $args->customize_preview_nav_menus_args['args_hmac'] . ']' ) );
963
+	public function filter_wp_nav_menu($nav_menu_content, $args) {
964
+		if (isset($args->customize_preview_nav_menus_args['can_partial_refresh']) && $args->customize_preview_nav_menus_args['can_partial_refresh']) {
965
+			$attributes = sprintf(' data-customize-partial-id="%s"', esc_attr('nav_menu_instance['.$args->customize_preview_nav_menus_args['args_hmac'].']'));
966 966
 			$attributes .= ' data-customize-partial-type="nav_menu_instance"';
967
-			$attributes .= sprintf( ' data-customize-partial-placement-context="%s"', esc_attr( wp_json_encode( $args->customize_preview_nav_menus_args ) ) );
968
-			$nav_menu_content = preg_replace( '#^(<\w+)#', '$1 ' . $attributes, $nav_menu_content, 1 );
967
+			$attributes .= sprintf(' data-customize-partial-placement-context="%s"', esc_attr(wp_json_encode($args->customize_preview_nav_menus_args)));
968
+			$nav_menu_content = preg_replace('#^(<\w+)#', '$1 '.$attributes, $nav_menu_content, 1);
969 969
 		}
970 970
 		return $nav_menu_content;
971 971
 	}
@@ -982,8 +982,8 @@  discard block
 block discarded – undo
982 982
 	 * @param array $args The arguments to hash.
983 983
 	 * @return string Hashed nav menu arguments.
984 984
 	 */
985
-	public function hash_nav_menu_args( $args ) {
986
-		return wp_hash( serialize( $args ) );
985
+	public function hash_nav_menu_args($args) {
986
+		return wp_hash(serialize($args));
987 987
 	}
988 988
 
989 989
 	/**
@@ -993,8 +993,8 @@  discard block
 block discarded – undo
993 993
 	 * @access public
994 994
 	 */
995 995
 	public function customize_preview_enqueue_deps() {
996
-		wp_enqueue_script( 'customize-preview-nav-menus' ); // Note that we have overridden this.
997
-		wp_enqueue_style( 'customize-preview' );
996
+		wp_enqueue_script('customize-preview-nav-menus'); // Note that we have overridden this.
997
+		wp_enqueue_style('customize-preview');
998 998
 	}
999 999
 
1000 1000
 	/**
@@ -1009,7 +1009,7 @@  discard block
 block discarded – undo
1009 1009
 		$exports = array(
1010 1010
 			'navMenuInstanceArgs' => $this->preview_nav_menu_instance_args,
1011 1011
 		);
1012
-		printf( '<script>var _wpCustomizePreviewNavMenusExports = %s;</script>', wp_json_encode( $exports ) );
1012
+		printf('<script>var _wpCustomizePreviewNavMenusExports = %s;</script>', wp_json_encode($exports));
1013 1013
 	}
1014 1014
 
1015 1015
 	/**
@@ -1021,7 +1021,7 @@  discard block
 block discarded – undo
1021 1021
 	 * @param array $response Response.
1022 1022
 	 * @return array Response.
1023 1023
 	 */
1024
-	public function export_partial_rendered_nav_menu_instances( $response ) {
1024
+	public function export_partial_rendered_nav_menu_instances($response) {
1025 1025
 		$response['nav_menu_instance_args'] = $this->preview_nav_menu_instance_args;
1026 1026
 		return $response;
1027 1027
 	}
@@ -1038,25 +1038,25 @@  discard block
 block discarded – undo
1038 1038
 	 * @param array                $nav_menu_args Nav menu args supplied as container context.
1039 1039
 	 * @return string|false
1040 1040
 	 */
1041
-	public function render_nav_menu_partial( $partial, $nav_menu_args ) {
1042
-		unset( $partial );
1041
+	public function render_nav_menu_partial($partial, $nav_menu_args) {
1042
+		unset($partial);
1043 1043
 
1044
-		if ( ! isset( $nav_menu_args['args_hmac'] ) ) {
1044
+		if ( ! isset($nav_menu_args['args_hmac'])) {
1045 1045
 			// Error: missing_args_hmac.
1046 1046
 			return false;
1047 1047
 		}
1048 1048
 
1049 1049
 		$nav_menu_args_hmac = $nav_menu_args['args_hmac'];
1050
-		unset( $nav_menu_args['args_hmac'] );
1050
+		unset($nav_menu_args['args_hmac']);
1051 1051
 
1052
-		ksort( $nav_menu_args );
1053
-		if ( ! hash_equals( $this->hash_nav_menu_args( $nav_menu_args ), $nav_menu_args_hmac ) ) {
1052
+		ksort($nav_menu_args);
1053
+		if ( ! hash_equals($this->hash_nav_menu_args($nav_menu_args), $nav_menu_args_hmac)) {
1054 1054
 			// Error: args_hmac_mismatch.
1055 1055
 			return false;
1056 1056
 		}
1057 1057
 
1058 1058
 		ob_start();
1059
-		wp_nav_menu( $nav_menu_args );
1059
+		wp_nav_menu($nav_menu_args);
1060 1060
 		$content = ob_get_clean();
1061 1061
 
1062 1062
 		return $content;
Please login to merge, or discard this patch.
src/wp-includes/class-wp-image-editor.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	 *
198 198
 	 * @param int $width
199 199
 	 * @param int $height
200
-	 * @return true
200
+	 * @return boolean
201 201
 	 */
202 202
 	protected function update_size( $width = null, $height = null ) {
203 203
 		$this->size = array(
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 	 * @since 4.0.0
214 214
 	 * @access public
215 215
 	 *
216
-	 * @return int $quality Compression Quality. Range: [1,100]
216
+	 * @return boolean $quality Compression Quality. Range: [1,100]
217 217
 	 */
218 218
 	public function get_quality() {
219 219
 		if ( ! $this->quality ) {
Please login to merge, or discard this patch.
Braces   +22 added lines, -16 removed lines patch added patch discarded remove patch
@@ -313,8 +313,7 @@  discard block
 block discarded – undo
313 313
 		if ( $filename ) {
314 314
 			$file_ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );
315 315
 			$file_mime = $this->get_mime_type( $file_ext );
316
-		}
317
-		else {
316
+		} else {
318 317
 			// If no file specified, grab editor's current extension and mime-type.
319 318
 			$file_ext = strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) );
320 319
 			$file_mime = $this->mime_type;
@@ -348,8 +347,9 @@  discard block
 block discarded – undo
348 347
 			$info = pathinfo( $filename );
349 348
 			$dir  = $info['dirname'];
350 349
 
351
-			if ( isset( $info['extension'] ) )
352
-				$ext = $info['extension'];
350
+			if ( isset( $info['extension'] ) ) {
351
+							$ext = $info['extension'];
352
+			}
353 353
 
354 354
 			$filename = trailingslashit( $dir ) . wp_basename( $filename, ".$ext" ) . ".{$new_ext}";
355 355
 		}
@@ -370,8 +370,9 @@  discard block
 block discarded – undo
370 370
 	 */
371 371
 	public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) {
372 372
 		// $suffix will be appended to the destination filename, just before the extension
373
-		if ( ! $suffix )
374
-			$suffix = $this->get_suffix();
373
+		if ( ! $suffix ) {
374
+					$suffix = $this->get_suffix();
375
+		}
375 376
 
376 377
 		$info = pathinfo( $this->file );
377 378
 		$dir  = $info['dirname'];
@@ -380,8 +381,9 @@  discard block
 block discarded – undo
380 381
 		$name = wp_basename( $this->file, ".$ext" );
381 382
 		$new_ext = strtolower( $extension ? $extension : $ext );
382 383
 
383
-		if ( ! is_null( $dest_path ) && $_dest_path = realpath( $dest_path ) )
384
-			$dir = $_dest_path;
384
+		if ( ! is_null( $dest_path ) && $_dest_path = realpath( $dest_path ) ) {
385
+					$dir = $_dest_path;
386
+		}
385 387
 
386 388
 		return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}";
387 389
 	}
@@ -395,8 +397,9 @@  discard block
 block discarded – undo
395 397
 	 * @return false|string suffix
396 398
 	 */
397 399
 	public function get_suffix() {
398
-		if ( ! $this->get_size() )
399
-			return false;
400
+		if ( ! $this->get_size() ) {
401
+					return false;
402
+		}
400 403
 
401 404
 		return "{$this->size['width']}x{$this->size['height']}";
402 405
 	}
@@ -427,8 +430,9 @@  discard block
 block discarded – undo
427 430
 
428 431
 			$fp = fopen( $filename, 'w' );
429 432
 
430
-			if ( ! $fp )
431
-				return false;
433
+			if ( ! $fp ) {
434
+							return false;
435
+			}
432 436
 
433 437
 			fwrite( $fp, $contents );
434 438
 			fclose( $fp );
@@ -454,8 +458,9 @@  discard block
 block discarded – undo
454 458
 	 * @return string|false
455 459
 	 */
456 460
 	protected static function get_mime_type( $extension = null ) {
457
-		if ( ! $extension )
458
-			return false;
461
+		if ( ! $extension ) {
462
+					return false;
463
+		}
459 464
 
460 465
 		$mime_types = wp_get_mime_types();
461 466
 		$extensions = array_keys( $mime_types );
@@ -484,8 +489,9 @@  discard block
 block discarded – undo
484 489
 	protected static function get_extension( $mime_type = null ) {
485 490
 		$extensions = explode( '|', array_search( $mime_type, wp_get_mime_types() ) );
486 491
 
487
-		if ( empty( $extensions[0] ) )
488
-			return false;
492
+		if ( empty( $extensions[0] ) ) {
493
+					return false;
494
+		}
489 495
 
490 496
 		return $extensions[0];
491 497
 	}
Please login to merge, or discard this patch.
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @param string $file Path to the file to load.
26 26
 	 */
27
-	public function __construct( $file ) {
27
+	public function __construct($file) {
28 28
 		$this->file = $file;
29 29
 	}
30 30
 
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 * @param array $args
42 42
 	 * @return bool
43 43
 	 */
44
-	public static function test( $args = array() ) {
44
+	public static function test($args = array()) {
45 45
 		return false;
46 46
 	}
47 47
 
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	 * @param string $mime_type
59 59
 	 * @return bool
60 60
 	 */
61
-	public static function supports_mime_type( $mime_type ) {
61
+	public static function supports_mime_type($mime_type) {
62 62
 		return false;
63 63
 	}
64 64
 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	 * @param string $mime_type
85 85
 	 * @return array|WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string}
86 86
 	 */
87
-	abstract public function save( $destfilename = null, $mime_type = null );
87
+	abstract public function save($destfilename = null, $mime_type = null);
88 88
 
89 89
 	/**
90 90
 	 * Resizes current image.
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 * @param  bool     $crop
103 103
 	 * @return bool|WP_Error
104 104
 	 */
105
-	abstract public function resize( $max_w, $max_h, $crop = false );
105
+	abstract public function resize($max_w, $max_h, $crop = false);
106 106
 
107 107
 	/**
108 108
 	 * Resize multiple images from a single source.
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 * }
123 123
 	 * @return array An array of resized images metadata by size.
124 124
 	 */
125
-	abstract public function multi_resize( $sizes );
125
+	abstract public function multi_resize($sizes);
126 126
 
127 127
 	/**
128 128
 	 * Crops Image.
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 	 * @param bool $src_abs Optional. If the source crop points are absolute.
141 141
 	 * @return bool|WP_Error
142 142
 	 */
143
-	abstract public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false );
143
+	abstract public function crop($src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false);
144 144
 
145 145
 	/**
146 146
 	 * Rotates current image counter-clockwise by $angle.
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	 * @param float $angle
153 153
 	 * @return bool|WP_Error
154 154
 	 */
155
-	abstract public function rotate( $angle );
155
+	abstract public function rotate($angle);
156 156
 
157 157
 	/**
158 158
 	 * Flips current image.
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @param bool $vert Flip along Vertical Axis
166 166
 	 * @return bool|WP_Error
167 167
 	 */
168
-	abstract public function flip( $horz, $vert );
168
+	abstract public function flip($horz, $vert);
169 169
 
170 170
 	/**
171 171
 	 * Streams current image to browser.
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 	 * @param string $mime_type
178 178
 	 * @return bool|WP_Error
179 179
 	 */
180
-	abstract public function stream( $mime_type = null );
180
+	abstract public function stream($mime_type = null);
181 181
 
182 182
 	/**
183 183
 	 * Gets dimensions of image.
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 	 * @param int $height
202 202
 	 * @return true
203 203
 	 */
204
-	protected function update_size( $width = null, $height = null ) {
204
+	protected function update_size($width = null, $height = null) {
205 205
 		$this->size = array(
206 206
 			'width' => (int) $width,
207 207
 			'height' => (int) $height
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 	 * @return int $quality Compression Quality. Range: [1,100]
219 219
 	 */
220 220
 	public function get_quality() {
221
-		if ( ! $this->quality ) {
221
+		if ( ! $this->quality) {
222 222
 			$this->set_quality();
223 223
 		}
224 224
 
@@ -234,8 +234,8 @@  discard block
 block discarded – undo
234 234
 	 * @param int $quality Compression Quality. Range: [1,100]
235 235
 	 * @return true|WP_Error True if set successfully; WP_Error on failure.
236 236
 	 */
237
-	public function set_quality( $quality = null ) {
238
-		if ( null === $quality ) {
237
+	public function set_quality($quality = null) {
238
+		if (null === $quality) {
239 239
 			/**
240 240
 			 * Filter the default image compression quality setting.
241 241
 			 *
@@ -249,9 +249,9 @@  discard block
 block discarded – undo
249 249
 			 * @param int    $quality   Quality level between 1 (low) and 100 (high).
250 250
 			 * @param string $mime_type Image mime type.
251 251
 			 */
252
-			$quality = apply_filters( 'wp_editor_set_quality', $this->default_quality, $this->mime_type );
252
+			$quality = apply_filters('wp_editor_set_quality', $this->default_quality, $this->mime_type);
253 253
 
254
-			if ( 'image/jpeg' == $this->mime_type ) {
254
+			if ('image/jpeg' == $this->mime_type) {
255 255
 				/**
256 256
 				 * Filter the JPEG compression quality for backward-compatibility.
257 257
 				 *
@@ -268,24 +268,24 @@  discard block
 block discarded – undo
268 268
 				 * @param int    $quality Quality level between 0 (low) and 100 (high) of the JPEG.
269 269
 				 * @param string $context Context of the filter.
270 270
 				 */
271
-				$quality = apply_filters( 'jpeg_quality', $quality, 'image_resize' );
271
+				$quality = apply_filters('jpeg_quality', $quality, 'image_resize');
272 272
 			}
273 273
 
274
-			if ( $quality < 0 || $quality > 100 ) {
274
+			if ($quality < 0 || $quality > 100) {
275 275
 				$quality = $this->default_quality;
276 276
 			}
277 277
 		}
278 278
 
279 279
 		// Allow 0, but squash to 1 due to identical images in GD, and for backwards compatibility.
280
-		if ( 0 === $quality ) {
280
+		if (0 === $quality) {
281 281
 			$quality = 1;
282 282
 		}
283 283
 
284
-		if ( ( $quality >= 1 ) && ( $quality <= 100 ) ) {
284
+		if (($quality >= 1) && ($quality <= 100)) {
285 285
 			$this->quality = $quality;
286 286
 			return true;
287 287
 		} else {
288
-			return new WP_Error( 'invalid_image_quality', __('Attempted to set image quality outside of the range [1,100].') );
288
+			return new WP_Error('invalid_image_quality', __('Attempted to set image quality outside of the range [1,100].'));
289 289
 		}
290 290
 	}
291 291
 
@@ -304,34 +304,34 @@  discard block
 block discarded – undo
304 304
 	 * @param string $mime_type
305 305
 	 * @return array { filename|null, extension, mime-type }
306 306
 	 */
307
-	protected function get_output_format( $filename = null, $mime_type = null ) {
307
+	protected function get_output_format($filename = null, $mime_type = null) {
308 308
 		$new_ext = null;
309 309
 
310 310
 		// By default, assume specified type takes priority
311
-		if ( $mime_type ) {
312
-			$new_ext = $this->get_extension( $mime_type );
311
+		if ($mime_type) {
312
+			$new_ext = $this->get_extension($mime_type);
313 313
 		}
314 314
 
315
-		if ( $filename ) {
316
-			$file_ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );
317
-			$file_mime = $this->get_mime_type( $file_ext );
315
+		if ($filename) {
316
+			$file_ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
317
+			$file_mime = $this->get_mime_type($file_ext);
318 318
 		}
319 319
 		else {
320 320
 			// If no file specified, grab editor's current extension and mime-type.
321
-			$file_ext = strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) );
321
+			$file_ext = strtolower(pathinfo($this->file, PATHINFO_EXTENSION));
322 322
 			$file_mime = $this->mime_type;
323 323
 		}
324 324
 
325 325
 		// Check to see if specified mime-type is the same as type implied by
326 326
 		// file extension.  If so, prefer extension from file.
327
-		if ( ! $mime_type || ( $file_mime == $mime_type ) ) {
327
+		if ( ! $mime_type || ($file_mime == $mime_type)) {
328 328
 			$mime_type = $file_mime;
329 329
 			$new_ext = $file_ext;
330 330
 		}
331 331
 
332 332
 		// Double-check that the mime-type selected is supported by the editor.
333 333
 		// If not, choose a default instead.
334
-		if ( ! $this->supports_mime_type( $mime_type ) ) {
334
+		if ( ! $this->supports_mime_type($mime_type)) {
335 335
 			/**
336 336
 			 * Filter default mime type prior to getting the file extension.
337 337
 			 *
@@ -341,22 +341,22 @@  discard block
 block discarded – undo
341 341
 			 *
342 342
 			 * @param string $mime_type Mime type string.
343 343
 			 */
344
-			$mime_type = apply_filters( 'image_editor_default_mime_type', $this->default_mime_type );
345
-			$new_ext = $this->get_extension( $mime_type );
344
+			$mime_type = apply_filters('image_editor_default_mime_type', $this->default_mime_type);
345
+			$new_ext = $this->get_extension($mime_type);
346 346
 		}
347 347
 
348
-		if ( $filename ) {
348
+		if ($filename) {
349 349
 			$ext = '';
350
-			$info = pathinfo( $filename );
350
+			$info = pathinfo($filename);
351 351
 			$dir  = $info['dirname'];
352 352
 
353
-			if ( isset( $info['extension'] ) )
353
+			if (isset($info['extension']))
354 354
 				$ext = $info['extension'];
355 355
 
356
-			$filename = trailingslashit( $dir ) . wp_basename( $filename, ".$ext" ) . ".{$new_ext}";
356
+			$filename = trailingslashit($dir).wp_basename($filename, ".$ext").".{$new_ext}";
357 357
 		}
358 358
 
359
-		return array( $filename, $new_ext, $mime_type );
359
+		return array($filename, $new_ext, $mime_type);
360 360
 	}
361 361
 
362 362
 	/**
@@ -370,22 +370,22 @@  discard block
 block discarded – undo
370 370
 	 * @param string $extension
371 371
 	 * @return string filename
372 372
 	 */
373
-	public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) {
373
+	public function generate_filename($suffix = null, $dest_path = null, $extension = null) {
374 374
 		// $suffix will be appended to the destination filename, just before the extension
375
-		if ( ! $suffix )
375
+		if ( ! $suffix)
376 376
 			$suffix = $this->get_suffix();
377 377
 
378
-		$info = pathinfo( $this->file );
378
+		$info = pathinfo($this->file);
379 379
 		$dir  = $info['dirname'];
380 380
 		$ext  = $info['extension'];
381 381
 
382
-		$name = wp_basename( $this->file, ".$ext" );
383
-		$new_ext = strtolower( $extension ? $extension : $ext );
382
+		$name = wp_basename($this->file, ".$ext");
383
+		$new_ext = strtolower($extension ? $extension : $ext);
384 384
 
385
-		if ( ! is_null( $dest_path ) && $_dest_path = realpath( $dest_path ) )
385
+		if ( ! is_null($dest_path) && $_dest_path = realpath($dest_path))
386 386
 			$dir = $_dest_path;
387 387
 
388
-		return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}";
388
+		return trailingslashit($dir)."{$name}-{$suffix}.{$new_ext}";
389 389
 	}
390 390
 
391 391
 	/**
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
 	 * @return false|string suffix
398 398
 	 */
399 399
 	public function get_suffix() {
400
-		if ( ! $this->get_size() )
400
+		if ( ! $this->get_size())
401 401
 			return false;
402 402
 
403 403
 		return "{$this->size['width']}x{$this->size['height']}";
@@ -414,29 +414,29 @@  discard block
 block discarded – undo
414 414
 	 * @param array $arguments
415 415
 	 * @return bool
416 416
 	 */
417
-	protected function make_image( $filename, $function, $arguments ) {
418
-		if ( $stream = wp_is_stream( $filename ) ) {
417
+	protected function make_image($filename, $function, $arguments) {
418
+		if ($stream = wp_is_stream($filename)) {
419 419
 			ob_start();
420 420
 		} else {
421 421
 			// The directory containing the original file may no longer exist when using a replication plugin.
422
-			wp_mkdir_p( dirname( $filename ) );
422
+			wp_mkdir_p(dirname($filename));
423 423
 		}
424 424
 
425
-		$result = call_user_func_array( $function, $arguments );
425
+		$result = call_user_func_array($function, $arguments);
426 426
 
427
-		if ( $result && $stream ) {
427
+		if ($result && $stream) {
428 428
 			$contents = ob_get_contents();
429 429
 
430
-			$fp = fopen( $filename, 'w' );
430
+			$fp = fopen($filename, 'w');
431 431
 
432
-			if ( ! $fp )
432
+			if ( ! $fp)
433 433
 				return false;
434 434
 
435
-			fwrite( $fp, $contents );
436
-			fclose( $fp );
435
+			fwrite($fp, $contents);
436
+			fclose($fp);
437 437
 		}
438 438
 
439
-		if ( $stream ) {
439
+		if ($stream) {
440 440
 			ob_end_clean();
441 441
 		}
442 442
 
@@ -455,15 +455,15 @@  discard block
 block discarded – undo
455 455
 	 * @param string $extension
456 456
 	 * @return string|false
457 457
 	 */
458
-	protected static function get_mime_type( $extension = null ) {
459
-		if ( ! $extension )
458
+	protected static function get_mime_type($extension = null) {
459
+		if ( ! $extension)
460 460
 			return false;
461 461
 
462 462
 		$mime_types = wp_get_mime_types();
463
-		$extensions = array_keys( $mime_types );
463
+		$extensions = array_keys($mime_types);
464 464
 
465
-		foreach ( $extensions as $_extension ) {
466
-			if ( preg_match( "/{$extension}/i", $_extension ) ) {
465
+		foreach ($extensions as $_extension) {
466
+			if (preg_match("/{$extension}/i", $_extension)) {
467 467
 				return $mime_types[$_extension];
468 468
 			}
469 469
 		}
@@ -483,10 +483,10 @@  discard block
 block discarded – undo
483 483
 	 * @param string $mime_type
484 484
 	 * @return string|false
485 485
 	 */
486
-	protected static function get_extension( $mime_type = null ) {
487
-		$extensions = explode( '|', array_search( $mime_type, wp_get_mime_types() ) );
486
+	protected static function get_extension($mime_type = null) {
487
+		$extensions = explode('|', array_search($mime_type, wp_get_mime_types()));
488 488
 
489
-		if ( empty( $extensions[0] ) )
489
+		if (empty($extensions[0]))
490 490
 			return false;
491 491
 
492 492
 		return $extensions[0];
Please login to merge, or discard this patch.
src/wp-includes/class-wp.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -699,7 +699,7 @@
 block discarded – undo
699 699
 	 * @access public
700 700
 	 *
701 701
 	 * @param string $subject subject
702
-	 * @param array  $matches data used for substitution
702
+	 * @param string[]  $matches data used for substitution
703 703
 	 * @return string
704 704
 	 */
705 705
 	public static function apply($subject, $matches) {
Please login to merge, or discard this patch.
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -610,22 +610,22 @@
 block discarded – undo
610 610
  	}
611 611
 
612 612
  	/**
613
-	 * Set the Headers for 404, if nothing is found for requested URL.
614
-	 *
615
-	 * Issue a 404 if a request doesn't match any posts and doesn't match
616
-	 * any object (e.g. an existing-but-empty category, tag, author) and a 404 was not already
617
-	 * issued, and if the request was not a search or the homepage.
618
-	 *
619
-	 * Otherwise, issue a 200.
620
-	 *
621
-	 * This sets headers after posts have been queried. handle_404() really means "handle status."
622
-	 * By inspecting the result of querying posts, seemingly successful requests can be switched to
623
-	 * a 404 so that canonical redirection logic can kick in.
624
-	 *
625
-	 * @since 2.0.0
626
-     * @access public
627
-	 *
628
-	 * @global WP_Query $wp_query
613
+ 	 * Set the Headers for 404, if nothing is found for requested URL.
614
+ 	 *
615
+ 	 * Issue a 404 if a request doesn't match any posts and doesn't match
616
+ 	 * any object (e.g. an existing-but-empty category, tag, author) and a 404 was not already
617
+ 	 * issued, and if the request was not a search or the homepage.
618
+ 	 *
619
+ 	 * Otherwise, issue a 200.
620
+ 	 *
621
+ 	 * This sets headers after posts have been queried. handle_404() really means "handle status."
622
+ 	 * By inspecting the result of querying posts, seemingly successful requests can be switched to
623
+ 	 * a 404 so that canonical redirection logic can kick in.
624
+ 	 *
625
+ 	 * @since 2.0.0
626
+ 	 * @access public
627
+ 	 *
628
+ 	 * @global WP_Query $wp_query
629 629
  	 */
630 630
 	public function handle_404() {
631 631
 		global $wp_query;
Please login to merge, or discard this patch.
Spacing   +142 added lines, -143 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 	 * @access public
16 16
 	 * @var array
17 17
 	 */
18
-	public $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type', 'embed' );
18
+	public $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type', 'embed');
19 19
 
20 20
 	/**
21 21
 	 * Private query variables.
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 * @access public
27 27
 	 * @var array
28 28
 	 */
29
-	public $private_query_vars = array( 'offset', 'posts_per_page', 'posts_per_archive_page', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page', 'post__in', 'post__not_in', 'post_parent', 'post_parent__in', 'post_parent__not_in', 'title' );
29
+	public $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page', 'post__in', 'post__not_in', 'post_parent', 'post_parent__in', 'post_parent__not_in', 'title');
30 30
 
31 31
 	/**
32 32
 	 * Extra query variables set by the user.
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	 * @param string $qv Query variable name.
101 101
 	 */
102 102
 	public function add_query_var($qv) {
103
-		if ( !in_array($qv, $this->public_query_vars) )
103
+		if ( ! in_array($qv, $this->public_query_vars))
104 104
 			$this->public_query_vars[] = $qv;
105 105
 	}
106 106
 
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
 	 *
113 113
 	 * @param string $name Query variable name.
114 114
 	 */
115
-	public function remove_query_var( $name ) {
116
-		$this->public_query_vars = array_diff( $this->public_query_vars, array( $name ) );
115
+	public function remove_query_var($name) {
116
+		$this->public_query_vars = array_diff($this->public_query_vars, array($name));
117 117
 	}
118 118
 
119 119
 	/**
@@ -154,35 +154,35 @@  discard block
 block discarded – undo
154 154
 		 * @param WP           $this             Current WordPress environment instance.
155 155
 		 * @param array|string $extra_query_vars Extra passed query variables.
156 156
 		 */
157
-		if ( ! apply_filters( 'do_parse_request', true, $this, $extra_query_vars ) )
157
+		if ( ! apply_filters('do_parse_request', true, $this, $extra_query_vars))
158 158
 			return;
159 159
 
160 160
 		$this->query_vars = array();
161 161
 		$post_type_query_vars = array();
162 162
 
163
-		if ( is_array( $extra_query_vars ) ) {
163
+		if (is_array($extra_query_vars)) {
164 164
 			$this->extra_query_vars = & $extra_query_vars;
165
-		} elseif ( ! empty( $extra_query_vars ) ) {
166
-			parse_str( $extra_query_vars, $this->extra_query_vars );
165
+		} elseif ( ! empty($extra_query_vars)) {
166
+			parse_str($extra_query_vars, $this->extra_query_vars);
167 167
 		}
168 168
 		// Process PATH_INFO, REQUEST_URI, and 404 for permalinks.
169 169
 
170 170
 		// Fetch the rewrite rules.
171 171
 		$rewrite = $wp_rewrite->wp_rewrite_rules();
172 172
 
173
-		if ( ! empty($rewrite) ) {
173
+		if ( ! empty($rewrite)) {
174 174
 			// If we match a rewrite rule, this will be cleared.
175 175
 			$error = '404';
176 176
 			$this->did_permalink = true;
177 177
 
178
-			$pathinfo = isset( $_SERVER['PATH_INFO'] ) ? $_SERVER['PATH_INFO'] : '';
179
-			list( $pathinfo ) = explode( '?', $pathinfo );
180
-			$pathinfo = str_replace( "%", "%25", $pathinfo );
178
+			$pathinfo = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
179
+			list($pathinfo) = explode('?', $pathinfo);
180
+			$pathinfo = str_replace("%", "%25", $pathinfo);
181 181
 
182
-			list( $req_uri ) = explode( '?', $_SERVER['REQUEST_URI'] );
182
+			list($req_uri) = explode('?', $_SERVER['REQUEST_URI']);
183 183
 			$self = $_SERVER['PHP_SELF'];
184
-			$home_path = trim( parse_url( home_url(), PHP_URL_PATH ), '/' );
185
-			$home_path_regex = sprintf( '|^%s|i', preg_quote( $home_path, '|' ) );
184
+			$home_path = trim(parse_url(home_url(), PHP_URL_PATH), '/');
185
+			$home_path_regex = sprintf('|^%s|i', preg_quote($home_path, '|'));
186 186
 
187 187
 			// Trim path info from the end and the leading home path from the
188 188
 			// front. For path info requests, this leaves us with the requesting
@@ -190,22 +190,22 @@  discard block
 block discarded – undo
190 190
 			// requested permalink.
191 191
 			$req_uri = str_replace($pathinfo, '', $req_uri);
192 192
 			$req_uri = trim($req_uri, '/');
193
-			$req_uri = preg_replace( $home_path_regex, '', $req_uri );
193
+			$req_uri = preg_replace($home_path_regex, '', $req_uri);
194 194
 			$req_uri = trim($req_uri, '/');
195 195
 			$pathinfo = trim($pathinfo, '/');
196
-			$pathinfo = preg_replace( $home_path_regex, '', $pathinfo );
196
+			$pathinfo = preg_replace($home_path_regex, '', $pathinfo);
197 197
 			$pathinfo = trim($pathinfo, '/');
198 198
 			$self = trim($self, '/');
199
-			$self = preg_replace( $home_path_regex, '', $self );
199
+			$self = preg_replace($home_path_regex, '', $self);
200 200
 			$self = trim($self, '/');
201 201
 
202 202
 			// The requested permalink is in $pathinfo for path info requests and
203 203
 			//  $req_uri for other requests.
204
-			if ( ! empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo) ) {
204
+			if ( ! empty($pathinfo) && ! preg_match('|^.*'.$wp_rewrite->index.'$|', $pathinfo)) {
205 205
 				$requested_path = $pathinfo;
206 206
 			} else {
207 207
 				// If the request uri is the index, blank it out so that we don't try to match it against a rule.
208
-				if ( $req_uri == $wp_rewrite->index )
208
+				if ($req_uri == $wp_rewrite->index)
209 209
 					$req_uri = '';
210 210
 				$requested_path = $req_uri;
211 211
 			}
@@ -215,32 +215,32 @@  discard block
 block discarded – undo
215 215
 
216 216
 			// Look for matches.
217 217
 			$request_match = $requested_path;
218
-			if ( empty( $request_match ) ) {
218
+			if (empty($request_match)) {
219 219
 				// An empty request could only match against ^$ regex
220
-				if ( isset( $rewrite['$'] ) ) {
220
+				if (isset($rewrite['$'])) {
221 221
 					$this->matched_rule = '$';
222 222
 					$query = $rewrite['$'];
223 223
 					$matches = array('');
224 224
 				}
225 225
 			} else {
226
-				foreach ( (array) $rewrite as $match => $query ) {
226
+				foreach ((array) $rewrite as $match => $query) {
227 227
 					// If the requested file is the anchor of the match, prepend it to the path info.
228
-					if ( ! empty($requested_file) && strpos($match, $requested_file) === 0 && $requested_file != $requested_path )
229
-						$request_match = $requested_file . '/' . $requested_path;
228
+					if ( ! empty($requested_file) && strpos($match, $requested_file) === 0 && $requested_file != $requested_path)
229
+						$request_match = $requested_file.'/'.$requested_path;
230 230
 
231
-					if ( preg_match("#^$match#", $request_match, $matches) ||
232
-						preg_match("#^$match#", urldecode($request_match), $matches) ) {
231
+					if (preg_match("#^$match#", $request_match, $matches) ||
232
+						preg_match("#^$match#", urldecode($request_match), $matches)) {
233 233
 
234
-						if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
234
+						if ($wp_rewrite->use_verbose_page_rules && preg_match('/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch)) {
235 235
 							// This is a verbose page match, let's check to be sure about it.
236
-							$page = get_page_by_path( $matches[ $varmatch[1] ] );
237
-							if ( ! $page ) {
236
+							$page = get_page_by_path($matches[$varmatch[1]]);
237
+							if ( ! $page) {
238 238
 						 		continue;
239 239
 							}
240 240
 
241
-							$post_status_obj = get_post_status_object( $page->post_status );
241
+							$post_status_obj = get_post_status_object($page->post_status);
242 242
 							if ( ! $post_status_obj->public && ! $post_status_obj->protected
243
-								&& ! $post_status_obj->private && $post_status_obj->exclude_from_search ) {
243
+								&& ! $post_status_obj->private && $post_status_obj->exclude_from_search) {
244 244
 								continue;
245 245
 							}
246 246
 						}
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 				}
253 253
 			}
254 254
 
255
-			if ( isset( $this->matched_rule ) ) {
255
+			if (isset($this->matched_rule)) {
256 256
 				// Trim the query of everything up to the '?'.
257 257
 				$query = preg_replace("!^.+\?!", '', $query);
258 258
 
@@ -265,16 +265,16 @@  discard block
 block discarded – undo
265 265
 				parse_str($query, $perma_query_vars);
266 266
 
267 267
 				// If we're processing a 404 request, clear the error var since we found something.
268
-				if ( '404' == $error )
269
-					unset( $error, $_GET['error'] );
268
+				if ('404' == $error)
269
+					unset($error, $_GET['error']);
270 270
 			}
271 271
 
272 272
 			// If req_uri is empty or if it is a request for ourself, unset error.
273
-			if ( empty($requested_path) || $requested_file == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {
274
-				unset( $error, $_GET['error'] );
273
+			if (empty($requested_path) || $requested_file == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false) {
274
+				unset($error, $_GET['error']);
275 275
 
276
-				if ( isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false )
277
-					unset( $perma_query_vars );
276
+				if (isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false)
277
+					unset($perma_query_vars);
278 278
 
279 279
 				$this->did_permalink = false;
280 280
 			}
@@ -291,36 +291,36 @@  discard block
 block discarded – undo
291 291
 		 *
292 292
 		 * @param array $public_query_vars The array of whitelisted query variables.
293 293
 		 */
294
-		$this->public_query_vars = apply_filters( 'query_vars', $this->public_query_vars );
294
+		$this->public_query_vars = apply_filters('query_vars', $this->public_query_vars);
295 295
 
296
-		foreach ( get_post_types( array(), 'objects' ) as $post_type => $t ) {
297
-			if ( is_post_type_viewable( $t ) && $t->query_var ) {
296
+		foreach (get_post_types(array(), 'objects') as $post_type => $t) {
297
+			if (is_post_type_viewable($t) && $t->query_var) {
298 298
 				$post_type_query_vars[$t->query_var] = $post_type;
299 299
 			}
300 300
 		}
301 301
 
302
-		foreach ( $this->public_query_vars as $wpvar ) {
303
-			if ( isset( $this->extra_query_vars[$wpvar] ) )
302
+		foreach ($this->public_query_vars as $wpvar) {
303
+			if (isset($this->extra_query_vars[$wpvar]))
304 304
 				$this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar];
305
-			elseif ( isset( $_POST[$wpvar] ) )
305
+			elseif (isset($_POST[$wpvar]))
306 306
 				$this->query_vars[$wpvar] = $_POST[$wpvar];
307
-			elseif ( isset( $_GET[$wpvar] ) )
307
+			elseif (isset($_GET[$wpvar]))
308 308
 				$this->query_vars[$wpvar] = $_GET[$wpvar];
309
-			elseif ( isset( $perma_query_vars[$wpvar] ) )
309
+			elseif (isset($perma_query_vars[$wpvar]))
310 310
 				$this->query_vars[$wpvar] = $perma_query_vars[$wpvar];
311 311
 
312
-			if ( !empty( $this->query_vars[$wpvar] ) ) {
313
-				if ( ! is_array( $this->query_vars[$wpvar] ) ) {
312
+			if ( ! empty($this->query_vars[$wpvar])) {
313
+				if ( ! is_array($this->query_vars[$wpvar])) {
314 314
 					$this->query_vars[$wpvar] = (string) $this->query_vars[$wpvar];
315 315
 				} else {
316
-					foreach ( $this->query_vars[$wpvar] as $vkey => $v ) {
317
-						if ( !is_object( $v ) ) {
316
+					foreach ($this->query_vars[$wpvar] as $vkey => $v) {
317
+						if ( ! is_object($v)) {
318 318
 							$this->query_vars[$wpvar][$vkey] = (string) $v;
319 319
 						}
320 320
 					}
321 321
 				}
322 322
 
323
-				if ( isset($post_type_query_vars[$wpvar] ) ) {
323
+				if (isset($post_type_query_vars[$wpvar])) {
324 324
 					$this->query_vars['post_type'] = $post_type_query_vars[$wpvar];
325 325
 					$this->query_vars['name'] = $this->query_vars[$wpvar];
326 326
 				}
@@ -328,43 +328,43 @@  discard block
 block discarded – undo
328 328
 		}
329 329
 
330 330
 		// Convert urldecoded spaces back into +
331
-		foreach ( get_taxonomies( array() , 'objects' ) as $taxonomy => $t )
332
-			if ( $t->query_var && isset( $this->query_vars[$t->query_var] ) )
333
-				$this->query_vars[$t->query_var] = str_replace( ' ', '+', $this->query_vars[$t->query_var] );
331
+		foreach (get_taxonomies(array(), 'objects') as $taxonomy => $t)
332
+			if ($t->query_var && isset($this->query_vars[$t->query_var]))
333
+				$this->query_vars[$t->query_var] = str_replace(' ', '+', $this->query_vars[$t->query_var]);
334 334
 
335 335
 		// Don't allow non-publicly queryable taxonomies to be queried from the front end.
336
-		if ( ! is_admin() ) {
337
-			foreach ( get_taxonomies( array( 'publicly_queryable' => false ), 'objects' ) as $taxonomy => $t ) {
336
+		if ( ! is_admin()) {
337
+			foreach (get_taxonomies(array('publicly_queryable' => false), 'objects') as $taxonomy => $t) {
338 338
 				/*
339 339
 				 * Disallow when set to the 'taxonomy' query var.
340 340
 				 * Non-publicly queryable taxonomies cannot register custom query vars. See register_taxonomy().
341 341
 				 */
342
-				if ( isset( $this->query_vars['taxonomy'] ) && $taxonomy === $this->query_vars['taxonomy'] ) {
343
-					unset( $this->query_vars['taxonomy'], $this->query_vars['term'] );
342
+				if (isset($this->query_vars['taxonomy']) && $taxonomy === $this->query_vars['taxonomy']) {
343
+					unset($this->query_vars['taxonomy'], $this->query_vars['term']);
344 344
 				}
345 345
 			}
346 346
 		}
347 347
 
348 348
 		// Limit publicly queried post_types to those that are publicly_queryable
349
-		if ( isset( $this->query_vars['post_type']) ) {
350
-			$queryable_post_types = get_post_types( array('publicly_queryable' => true) );
351
-			if ( ! is_array( $this->query_vars['post_type'] ) ) {
352
-				if ( ! in_array( $this->query_vars['post_type'], $queryable_post_types ) )
353
-					unset( $this->query_vars['post_type'] );
349
+		if (isset($this->query_vars['post_type'])) {
350
+			$queryable_post_types = get_post_types(array('publicly_queryable' => true));
351
+			if ( ! is_array($this->query_vars['post_type'])) {
352
+				if ( ! in_array($this->query_vars['post_type'], $queryable_post_types))
353
+					unset($this->query_vars['post_type']);
354 354
 			} else {
355
-				$this->query_vars['post_type'] = array_intersect( $this->query_vars['post_type'], $queryable_post_types );
355
+				$this->query_vars['post_type'] = array_intersect($this->query_vars['post_type'], $queryable_post_types);
356 356
 			}
357 357
 		}
358 358
 
359 359
 		// Resolve conflicts between posts with numeric slugs and date archive queries.
360
-		$this->query_vars = wp_resolve_numeric_slug_conflicts( $this->query_vars );
360
+		$this->query_vars = wp_resolve_numeric_slug_conflicts($this->query_vars);
361 361
 
362
-		foreach ( (array) $this->private_query_vars as $var) {
363
-			if ( isset($this->extra_query_vars[$var]) )
362
+		foreach ((array) $this->private_query_vars as $var) {
363
+			if (isset($this->extra_query_vars[$var]))
364 364
 				$this->query_vars[$var] = $this->extra_query_vars[$var];
365 365
 		}
366 366
 
367
-		if ( isset($error) )
367
+		if (isset($error))
368 368
 			$this->query_vars['error'] = $error;
369 369
 
370 370
 		/**
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
 		 *
375 375
 		 * @param array $query_vars The array of requested query variables.
376 376
 		 */
377
-		$this->query_vars = apply_filters( 'request', $this->query_vars );
377
+		$this->query_vars = apply_filters('request', $this->query_vars);
378 378
 
379 379
 		/**
380 380
 		 * Fires once all query variables for the current request have been parsed.
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 		 *
384 384
 		 * @param WP &$this Current WordPress environment instance (passed by reference).
385 385
 		 */
386
-		do_action_ref_array( 'parse_request', array( &$this ) );
386
+		do_action_ref_array('parse_request', array(&$this));
387 387
 	}
388 388
 
389 389
 	/**
@@ -401,50 +401,50 @@  discard block
 block discarded – undo
401 401
 		$status = null;
402 402
 		$exit_required = false;
403 403
 
404
-		if ( is_user_logged_in() )
404
+		if (is_user_logged_in())
405 405
 			$headers = array_merge($headers, wp_get_nocache_headers());
406
-		if ( ! empty( $this->query_vars['error'] ) ) {
406
+		if ( ! empty($this->query_vars['error'])) {
407 407
 			$status = (int) $this->query_vars['error'];
408
-			if ( 404 === $status ) {
409
-				if ( ! is_user_logged_in() )
408
+			if (404 === $status) {
409
+				if ( ! is_user_logged_in())
410 410
 					$headers = array_merge($headers, wp_get_nocache_headers());
411
-				$headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
412
-			} elseif ( in_array( $status, array( 403, 500, 502, 503 ) ) ) {
411
+				$headers['Content-Type'] = get_option('html_type').'; charset='.get_option('blog_charset');
412
+			} elseif (in_array($status, array(403, 500, 502, 503))) {
413 413
 				$exit_required = true;
414 414
 			}
415
-		} elseif ( empty( $this->query_vars['feed'] ) ) {
416
-			$headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
415
+		} elseif (empty($this->query_vars['feed'])) {
416
+			$headers['Content-Type'] = get_option('html_type').'; charset='.get_option('blog_charset');
417 417
 		} else {
418 418
 			// Set the correct content type for feeds
419 419
 			$type = $this->query_vars['feed'];
420
-			if ( 'feed' == $this->query_vars['feed'] ) {
420
+			if ('feed' == $this->query_vars['feed']) {
421 421
 				$type = get_default_feed();
422 422
 			}
423
-			$headers['Content-Type'] = feed_content_type( $type ) . '; charset=' . get_option( 'blog_charset' );
423
+			$headers['Content-Type'] = feed_content_type($type).'; charset='.get_option('blog_charset');
424 424
 
425 425
 			// We're showing a feed, so WP is indeed the only thing that last changed
426
-			if ( !empty($this->query_vars['withcomments'])
427
-				|| false !== strpos( $this->query_vars['feed'], 'comments-' )
428
-				|| ( empty($this->query_vars['withoutcomments'])
429
-					&& ( !empty($this->query_vars['p'])
430
-						|| !empty($this->query_vars['name'])
431
-						|| !empty($this->query_vars['page_id'])
432
-						|| !empty($this->query_vars['pagename'])
433
-						|| !empty($this->query_vars['attachment'])
434
-						|| !empty($this->query_vars['attachment_id'])
426
+			if ( ! empty($this->query_vars['withcomments'])
427
+				|| false !== strpos($this->query_vars['feed'], 'comments-')
428
+				|| (empty($this->query_vars['withoutcomments'])
429
+					&& ( ! empty($this->query_vars['p'])
430
+						|| ! empty($this->query_vars['name'])
431
+						|| ! empty($this->query_vars['page_id'])
432
+						|| ! empty($this->query_vars['pagename'])
433
+						|| ! empty($this->query_vars['attachment'])
434
+						|| ! empty($this->query_vars['attachment_id'])
435 435
 					)
436 436
 				)
437 437
 			)
438 438
 				$wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0).' GMT';
439 439
 			else
440 440
 				$wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT';
441
-			$wp_etag = '"' . md5($wp_last_modified) . '"';
441
+			$wp_etag = '"'.md5($wp_last_modified).'"';
442 442
 			$headers['Last-Modified'] = $wp_last_modified;
443 443
 			$headers['ETag'] = $wp_etag;
444 444
 
445 445
 			// Support for Conditional GET
446 446
 			if (isset($_SERVER['HTTP_IF_NONE_MATCH']))
447
-				$client_etag = wp_unslash( $_SERVER['HTTP_IF_NONE_MATCH'] );
447
+				$client_etag = wp_unslash($_SERVER['HTTP_IF_NONE_MATCH']);
448 448
 			else $client_etag = false;
449 449
 
450 450
 			$client_last_modified = empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? '' : trim($_SERVER['HTTP_IF_MODIFIED_SINCE']);
@@ -454,9 +454,8 @@  discard block
 block discarded – undo
454 454
 			// Make a timestamp for our most recent modification...
455 455
 			$wp_modified_timestamp = strtotime($wp_last_modified);
456 456
 
457
-			if ( ($client_last_modified && $client_etag) ?
458
-					 (($client_modified_timestamp >= $wp_modified_timestamp) && ($client_etag == $wp_etag)) :
459
-					 (($client_modified_timestamp >= $wp_modified_timestamp) || ($client_etag == $wp_etag)) ) {
457
+			if (($client_last_modified && $client_etag) ?
458
+					 (($client_modified_timestamp >= $wp_modified_timestamp) && ($client_etag == $wp_etag)) : (($client_modified_timestamp >= $wp_modified_timestamp) || ($client_etag == $wp_etag))) {
460 459
 				$status = 304;
461 460
 				$exit_required = true;
462 461
 			}
@@ -470,23 +469,23 @@  discard block
 block discarded – undo
470 469
 		 * @param array $headers The list of headers to be sent.
471 470
 		 * @param WP    $this    Current WordPress environment instance.
472 471
 		 */
473
-		$headers = apply_filters( 'wp_headers', $headers, $this );
472
+		$headers = apply_filters('wp_headers', $headers, $this);
474 473
 
475
-		if ( ! empty( $status ) )
476
-			status_header( $status );
474
+		if ( ! empty($status))
475
+			status_header($status);
477 476
 
478 477
 		// If Last-Modified is set to false, it should not be sent (no-cache situation).
479
-		if ( isset( $headers['Last-Modified'] ) && false === $headers['Last-Modified'] ) {
480
-			unset( $headers['Last-Modified'] );
478
+		if (isset($headers['Last-Modified']) && false === $headers['Last-Modified']) {
479
+			unset($headers['Last-Modified']);
481 480
 
482 481
 			// In PHP 5.3+, make sure we are not sending a Last-Modified header.
483
-			if ( function_exists( 'header_remove' ) ) {
484
-				@header_remove( 'Last-Modified' );
482
+			if (function_exists('header_remove')) {
483
+				@header_remove('Last-Modified');
485 484
 			} else {
486 485
 				// In PHP 5.2, send an empty Last-Modified header, but only as a
487 486
 				// last resort to override a header already sent. #WP23021
488
-				foreach ( headers_list() as $header ) {
489
-					if ( 0 === stripos( $header, 'Last-Modified' ) ) {
487
+				foreach (headers_list() as $header) {
488
+					if (0 === stripos($header, 'Last-Modified')) {
490 489
 						$headers['Last-Modified'] = '';
491 490
 						break;
492 491
 					}
@@ -494,10 +493,10 @@  discard block
 block discarded – undo
494 493
 			}
495 494
 		}
496 495
 
497
-		foreach ( (array) $headers as $name => $field_value )
496
+		foreach ((array) $headers as $name => $field_value)
498 497
 			@header("{$name}: {$field_value}");
499 498
 
500
-		if ( $exit_required )
499
+		if ($exit_required)
501 500
 			exit();
502 501
 
503 502
 		/**
@@ -507,7 +506,7 @@  discard block
 block discarded – undo
507 506
 		 *
508 507
 		 * @param WP &$this Current WordPress environment instance (passed by reference).
509 508
 		 */
510
-		do_action_ref_array( 'send_headers', array( &$this ) );
509
+		do_action_ref_array('send_headers', array(&$this));
511 510
 	}
512 511
 
513 512
 	/**
@@ -521,16 +520,16 @@  discard block
 block discarded – undo
521 520
 	 */
522 521
 	public function build_query_string() {
523 522
 		$this->query_string = '';
524
-		foreach ( (array) array_keys($this->query_vars) as $wpvar) {
525
-			if ( '' != $this->query_vars[$wpvar] ) {
523
+		foreach ((array) array_keys($this->query_vars) as $wpvar) {
524
+			if ('' != $this->query_vars[$wpvar]) {
526 525
 				$this->query_string .= (strlen($this->query_string) < 1) ? '' : '&';
527
-				if ( !is_scalar($this->query_vars[$wpvar]) ) // Discard non-scalars.
526
+				if ( ! is_scalar($this->query_vars[$wpvar])) // Discard non-scalars.
528 527
 					continue;
529
-				$this->query_string .= $wpvar . '=' . rawurlencode($this->query_vars[$wpvar]);
528
+				$this->query_string .= $wpvar.'='.rawurlencode($this->query_vars[$wpvar]);
530 529
 			}
531 530
 		}
532 531
 
533
-		if ( has_filter( 'query_string' ) ) {  // Don't bother filtering and parsing if no plugins are hooked in.
532
+		if (has_filter('query_string')) {  // Don't bother filtering and parsing if no plugins are hooked in.
534 533
 			/**
535 534
 			 * Filters the query string before parsing.
536 535
 			 *
@@ -539,7 +538,7 @@  discard block
 block discarded – undo
539 538
 			 *
540 539
 			 * @param string $query_string The query string to modify.
541 540
 			 */
542
-			$this->query_string = apply_filters( 'query_string', $this->query_string );
541
+			$this->query_string = apply_filters('query_string', $this->query_string);
543 542
 			parse_str($this->query_string, $this->query_vars);
544 543
 		}
545 544
 	}
@@ -567,22 +566,22 @@  discard block
 block discarded – undo
567 566
 		global $wp_query;
568 567
 
569 568
 		// Extract updated query vars back into global namespace.
570
-		foreach ( (array) $wp_query->query_vars as $key => $value ) {
571
-			$GLOBALS[ $key ] = $value;
569
+		foreach ((array) $wp_query->query_vars as $key => $value) {
570
+			$GLOBALS[$key] = $value;
572 571
 		}
573 572
 
574 573
 		$GLOBALS['query_string'] = $this->query_string;
575 574
 		$GLOBALS['posts'] = & $wp_query->posts;
576
-		$GLOBALS['post'] = isset( $wp_query->post ) ? $wp_query->post : null;
575
+		$GLOBALS['post'] = isset($wp_query->post) ? $wp_query->post : null;
577 576
 		$GLOBALS['request'] = $wp_query->request;
578 577
 
579
-		if ( $wp_query->is_single() || $wp_query->is_page() ) {
578
+		if ($wp_query->is_single() || $wp_query->is_page()) {
580 579
 			$GLOBALS['more']   = 1;
581 580
 			$GLOBALS['single'] = 1;
582 581
 		}
583 582
 
584
-		if ( $wp_query->is_author() && isset( $wp_query->post ) )
585
-			$GLOBALS['authordata'] = get_userdata( $wp_query->post->post_author );
583
+		if ($wp_query->is_author() && isset($wp_query->post))
584
+			$GLOBALS['authordata'] = get_userdata($wp_query->post->post_author);
586 585
 	}
587 586
 
588 587
 	/**
@@ -641,70 +640,70 @@  discard block
 block discarded – undo
641 640
 		 * @param bool     $preempt  Whether to short-circuit default header status handling. Default false.
642 641
 		 * @param WP_Query $wp_query WordPress Query object.
643 642
 		 */
644
-		if ( false !== apply_filters( 'pre_handle_404', false, $wp_query ) ) {
643
+		if (false !== apply_filters('pre_handle_404', false, $wp_query)) {
645 644
 			return;
646 645
 		}
647 646
 
648 647
 		// If we've already issued a 404, bail.
649
-		if ( is_404() )
648
+		if (is_404())
650 649
 			return;
651 650
 
652 651
 		// Never 404 for the admin, robots, or if we found posts.
653
-		if ( is_admin() || is_robots() || $wp_query->posts ) {
652
+		if (is_admin() || is_robots() || $wp_query->posts) {
654 653
 
655 654
 			$success = true;
656
-			if ( is_singular() ) {
655
+			if (is_singular()) {
657 656
 				$p = false;
658 657
 
659
-				if ( $wp_query->post instanceof WP_Post ) {
658
+				if ($wp_query->post instanceof WP_Post) {
660 659
 					$p = clone $wp_query->post;
661 660
 				}
662 661
 
663 662
 				// Only set X-Pingback for single posts that allow pings.
664
-				if ( $p && pings_open( $p ) ) {
665
-					@header( 'X-Pingback: ' . get_bloginfo( 'pingback_url' ) );
663
+				if ($p && pings_open($p)) {
664
+					@header('X-Pingback: '.get_bloginfo('pingback_url'));
666 665
 				}
667 666
 
668 667
 				// check for paged content that exceeds the max number of pages
669 668
 				$next = '<!--nextpage-->';
670
-				if ( $p && false !== strpos( $p->post_content, $next ) && ! empty( $this->query_vars['page'] ) ) {
671
-					$page = trim( $this->query_vars['page'], '/' );
672
-					$success = (int) $page <= ( substr_count( $p->post_content, $next ) + 1 );
669
+				if ($p && false !== strpos($p->post_content, $next) && ! empty($this->query_vars['page'])) {
670
+					$page = trim($this->query_vars['page'], '/');
671
+					$success = (int) $page <= (substr_count($p->post_content, $next) + 1);
673 672
 				}
674 673
 			}
675 674
 
676
-			if ( $success ) {
677
-				status_header( 200 );
675
+			if ($success) {
676
+				status_header(200);
678 677
 				return;
679 678
 			}
680 679
 		}
681 680
 
682 681
 		// We will 404 for paged queries, as no posts were found.
683
-		if ( ! is_paged() ) {
682
+		if ( ! is_paged()) {
684 683
 
685 684
 			// Don't 404 for authors without posts as long as they matched an author on this site.
686
-			$author = get_query_var( 'author' );
687
-			if ( is_author() && is_numeric( $author ) && $author > 0 && is_user_member_of_blog( $author ) ) {
688
-				status_header( 200 );
685
+			$author = get_query_var('author');
686
+			if (is_author() && is_numeric($author) && $author > 0 && is_user_member_of_blog($author)) {
687
+				status_header(200);
689 688
 				return;
690 689
 			}
691 690
 
692 691
 			// Don't 404 for these queries if they matched an object.
693
-			if ( ( is_tag() || is_category() || is_tax() || is_post_type_archive() ) && get_queried_object() ) {
694
-				status_header( 200 );
692
+			if ((is_tag() || is_category() || is_tax() || is_post_type_archive()) && get_queried_object()) {
693
+				status_header(200);
695 694
 				return;
696 695
 			}
697 696
 
698 697
 			// Don't 404 for these queries either.
699
-			if ( is_home() || is_search() || is_feed() ) {
700
-				status_header( 200 );
698
+			if (is_home() || is_search() || is_feed()) {
699
+				status_header(200);
701 700
 				return;
702 701
 			}
703 702
 		}
704 703
 
705 704
 		// Guess it's time to 404.
706 705
 		$wp_query->set_404();
707
-		status_header( 404 );
706
+		status_header(404);
708 707
 		nocache_headers();
709 708
 	}
710 709
 
@@ -735,7 +734,7 @@  discard block
 block discarded – undo
735 734
 		 *
736 735
 		 * @param WP &$this Current WordPress environment instance (passed by reference).
737 736
 		 */
738
-		do_action_ref_array( 'wp', array( &$this ) );
737
+		do_action_ref_array('wp', array(&$this));
739 738
 	}
740 739
 }
741 740
 
@@ -825,6 +824,6 @@  discard block
 block discarded – undo
825 824
 	 */
826 825
 	public function callback($matches) {
827 826
 		$index = intval(substr($matches[0], 9, -1));
828
-		return ( isset( $this->_matches[$index] ) ? urlencode($this->_matches[$index]) : '' );
827
+		return (isset($this->_matches[$index]) ? urlencode($this->_matches[$index]) : '');
829 828
 	}
830 829
 }
Please login to merge, or discard this patch.
Braces   +73 added lines, -50 removed lines patch added patch discarded remove patch
@@ -100,8 +100,9 @@  discard block
 block discarded – undo
100 100
 	 * @param string $qv Query variable name.
101 101
 	 */
102 102
 	public function add_query_var($qv) {
103
-		if ( !in_array($qv, $this->public_query_vars) )
104
-			$this->public_query_vars[] = $qv;
103
+		if ( !in_array($qv, $this->public_query_vars) ) {
104
+					$this->public_query_vars[] = $qv;
105
+		}
105 106
 	}
106 107
 
107 108
 	/**
@@ -154,8 +155,9 @@  discard block
 block discarded – undo
154 155
 		 * @param WP           $this             Current WordPress environment instance.
155 156
 		 * @param array|string $extra_query_vars Extra passed query variables.
156 157
 		 */
157
-		if ( ! apply_filters( 'do_parse_request', true, $this, $extra_query_vars ) )
158
-			return;
158
+		if ( ! apply_filters( 'do_parse_request', true, $this, $extra_query_vars ) ) {
159
+					return;
160
+		}
159 161
 
160 162
 		$this->query_vars = array();
161 163
 		$post_type_query_vars = array();
@@ -205,8 +207,9 @@  discard block
 block discarded – undo
205 207
 				$requested_path = $pathinfo;
206 208
 			} else {
207 209
 				// If the request uri is the index, blank it out so that we don't try to match it against a rule.
208
-				if ( $req_uri == $wp_rewrite->index )
209
-					$req_uri = '';
210
+				if ( $req_uri == $wp_rewrite->index ) {
211
+									$req_uri = '';
212
+				}
210 213
 				$requested_path = $req_uri;
211 214
 			}
212 215
 			$requested_file = $req_uri;
@@ -225,8 +228,9 @@  discard block
 block discarded – undo
225 228
 			} else {
226 229
 				foreach ( (array) $rewrite as $match => $query ) {
227 230
 					// If the requested file is the anchor of the match, prepend it to the path info.
228
-					if ( ! empty($requested_file) && strpos($match, $requested_file) === 0 && $requested_file != $requested_path )
229
-						$request_match = $requested_file . '/' . $requested_path;
231
+					if ( ! empty($requested_file) && strpos($match, $requested_file) === 0 && $requested_file != $requested_path ) {
232
+											$request_match = $requested_file . '/' . $requested_path;
233
+					}
230 234
 
231 235
 					if ( preg_match("#^$match#", $request_match, $matches) ||
232 236
 						preg_match("#^$match#", urldecode($request_match), $matches) ) {
@@ -265,16 +269,18 @@  discard block
 block discarded – undo
265 269
 				parse_str($query, $perma_query_vars);
266 270
 
267 271
 				// If we're processing a 404 request, clear the error var since we found something.
268
-				if ( '404' == $error )
269
-					unset( $error, $_GET['error'] );
272
+				if ( '404' == $error ) {
273
+									unset( $error, $_GET['error'] );
274
+				}
270 275
 			}
271 276
 
272 277
 			// If req_uri is empty or if it is a request for ourself, unset error.
273 278
 			if ( empty($requested_path) || $requested_file == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {
274 279
 				unset( $error, $_GET['error'] );
275 280
 
276
-				if ( isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false )
277
-					unset( $perma_query_vars );
281
+				if ( isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {
282
+									unset( $perma_query_vars );
283
+				}
278 284
 
279 285
 				$this->did_permalink = false;
280 286
 			}
@@ -300,14 +306,15 @@  discard block
 block discarded – undo
300 306
 		}
301 307
 
302 308
 		foreach ( $this->public_query_vars as $wpvar ) {
303
-			if ( isset( $this->extra_query_vars[$wpvar] ) )
304
-				$this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar];
305
-			elseif ( isset( $_POST[$wpvar] ) )
306
-				$this->query_vars[$wpvar] = $_POST[$wpvar];
307
-			elseif ( isset( $_GET[$wpvar] ) )
308
-				$this->query_vars[$wpvar] = $_GET[$wpvar];
309
-			elseif ( isset( $perma_query_vars[$wpvar] ) )
310
-				$this->query_vars[$wpvar] = $perma_query_vars[$wpvar];
309
+			if ( isset( $this->extra_query_vars[$wpvar] ) ) {
310
+							$this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar];
311
+			} elseif ( isset( $_POST[$wpvar] ) ) {
312
+							$this->query_vars[$wpvar] = $_POST[$wpvar];
313
+			} elseif ( isset( $_GET[$wpvar] ) ) {
314
+							$this->query_vars[$wpvar] = $_GET[$wpvar];
315
+			} elseif ( isset( $perma_query_vars[$wpvar] ) ) {
316
+							$this->query_vars[$wpvar] = $perma_query_vars[$wpvar];
317
+			}
311 318
 
312 319
 			if ( !empty( $this->query_vars[$wpvar] ) ) {
313 320
 				if ( ! is_array( $this->query_vars[$wpvar] ) ) {
@@ -328,9 +335,10 @@  discard block
 block discarded – undo
328 335
 		}
329 336
 
330 337
 		// Convert urldecoded spaces back into +
331
-		foreach ( get_taxonomies( array() , 'objects' ) as $taxonomy => $t )
332
-			if ( $t->query_var && isset( $this->query_vars[$t->query_var] ) )
338
+		foreach ( get_taxonomies( array() , 'objects' ) as $taxonomy => $t ) {
339
+					if ( $t->query_var && isset( $this->query_vars[$t->query_var] ) )
333 340
 				$this->query_vars[$t->query_var] = str_replace( ' ', '+', $this->query_vars[$t->query_var] );
341
+		}
334 342
 
335 343
 		// Don't allow non-publicly queryable taxonomies to be queried from the front end.
336 344
 		if ( ! is_admin() ) {
@@ -349,8 +357,9 @@  discard block
 block discarded – undo
349 357
 		if ( isset( $this->query_vars['post_type']) ) {
350 358
 			$queryable_post_types = get_post_types( array('publicly_queryable' => true) );
351 359
 			if ( ! is_array( $this->query_vars['post_type'] ) ) {
352
-				if ( ! in_array( $this->query_vars['post_type'], $queryable_post_types ) )
353
-					unset( $this->query_vars['post_type'] );
360
+				if ( ! in_array( $this->query_vars['post_type'], $queryable_post_types ) ) {
361
+									unset( $this->query_vars['post_type'] );
362
+				}
354 363
 			} else {
355 364
 				$this->query_vars['post_type'] = array_intersect( $this->query_vars['post_type'], $queryable_post_types );
356 365
 			}
@@ -360,12 +369,14 @@  discard block
 block discarded – undo
360 369
 		$this->query_vars = wp_resolve_numeric_slug_conflicts( $this->query_vars );
361 370
 
362 371
 		foreach ( (array) $this->private_query_vars as $var) {
363
-			if ( isset($this->extra_query_vars[$var]) )
364
-				$this->query_vars[$var] = $this->extra_query_vars[$var];
372
+			if ( isset($this->extra_query_vars[$var]) ) {
373
+							$this->query_vars[$var] = $this->extra_query_vars[$var];
374
+			}
365 375
 		}
366 376
 
367
-		if ( isset($error) )
368
-			$this->query_vars['error'] = $error;
377
+		if ( isset($error) ) {
378
+					$this->query_vars['error'] = $error;
379
+		}
369 380
 
370 381
 		/**
371 382
 		 * Filters the array of parsed query variables.
@@ -401,13 +412,15 @@  discard block
 block discarded – undo
401 412
 		$status = null;
402 413
 		$exit_required = false;
403 414
 
404
-		if ( is_user_logged_in() )
405
-			$headers = array_merge($headers, wp_get_nocache_headers());
415
+		if ( is_user_logged_in() ) {
416
+					$headers = array_merge($headers, wp_get_nocache_headers());
417
+		}
406 418
 		if ( ! empty( $this->query_vars['error'] ) ) {
407 419
 			$status = (int) $this->query_vars['error'];
408 420
 			if ( 404 === $status ) {
409
-				if ( ! is_user_logged_in() )
410
-					$headers = array_merge($headers, wp_get_nocache_headers());
421
+				if ( ! is_user_logged_in() ) {
422
+									$headers = array_merge($headers, wp_get_nocache_headers());
423
+				}
411 424
 				$headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
412 425
 			} elseif ( in_array( $status, array( 403, 500, 502, 503 ) ) ) {
413 426
 				$exit_required = true;
@@ -434,18 +447,21 @@  discard block
 block discarded – undo
434 447
 						|| !empty($this->query_vars['attachment_id'])
435 448
 					)
436 449
 				)
437
-			)
438
-				$wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0).' GMT';
439
-			else
440
-				$wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT';
450
+			) {
451
+							$wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0).' GMT';
452
+			} else {
453
+							$wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT';
454
+			}
441 455
 			$wp_etag = '"' . md5($wp_last_modified) . '"';
442 456
 			$headers['Last-Modified'] = $wp_last_modified;
443 457
 			$headers['ETag'] = $wp_etag;
444 458
 
445 459
 			// Support for Conditional GET
446
-			if (isset($_SERVER['HTTP_IF_NONE_MATCH']))
447
-				$client_etag = wp_unslash( $_SERVER['HTTP_IF_NONE_MATCH'] );
448
-			else $client_etag = false;
460
+			if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
461
+							$client_etag = wp_unslash( $_SERVER['HTTP_IF_NONE_MATCH'] );
462
+			} else {
463
+				$client_etag = false;
464
+			}
449 465
 
450 466
 			$client_last_modified = empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? '' : trim($_SERVER['HTTP_IF_MODIFIED_SINCE']);
451 467
 			// If string is empty, return 0. If not, attempt to parse into a timestamp
@@ -472,8 +488,9 @@  discard block
 block discarded – undo
472 488
 		 */
473 489
 		$headers = apply_filters( 'wp_headers', $headers, $this );
474 490
 
475
-		if ( ! empty( $status ) )
476
-			status_header( $status );
491
+		if ( ! empty( $status ) ) {
492
+					status_header( $status );
493
+		}
477 494
 
478 495
 		// If Last-Modified is set to false, it should not be sent (no-cache situation).
479 496
 		if ( isset( $headers['Last-Modified'] ) && false === $headers['Last-Modified'] ) {
@@ -494,11 +511,13 @@  discard block
 block discarded – undo
494 511
 			}
495 512
 		}
496 513
 
497
-		foreach ( (array) $headers as $name => $field_value )
498
-			@header("{$name}: {$field_value}");
514
+		foreach ( (array) $headers as $name => $field_value ) {
515
+					@header("{$name}: {$field_value}");
516
+		}
499 517
 
500
-		if ( $exit_required )
501
-			exit();
518
+		if ( $exit_required ) {
519
+					exit();
520
+		}
502 521
 
503 522
 		/**
504 523
 		 * Fires once the requested HTTP headers for caching, content type, etc. have been sent.
@@ -524,8 +543,10 @@  discard block
 block discarded – undo
524 543
 		foreach ( (array) array_keys($this->query_vars) as $wpvar) {
525 544
 			if ( '' != $this->query_vars[$wpvar] ) {
526 545
 				$this->query_string .= (strlen($this->query_string) < 1) ? '' : '&';
527
-				if ( !is_scalar($this->query_vars[$wpvar]) ) // Discard non-scalars.
546
+				if ( !is_scalar($this->query_vars[$wpvar]) ) {
547
+					// Discard non-scalars.
528 548
 					continue;
549
+				}
529 550
 				$this->query_string .= $wpvar . '=' . rawurlencode($this->query_vars[$wpvar]);
530 551
 			}
531 552
 		}
@@ -581,8 +602,9 @@  discard block
 block discarded – undo
581 602
 			$GLOBALS['single'] = 1;
582 603
 		}
583 604
 
584
-		if ( $wp_query->is_author() && isset( $wp_query->post ) )
585
-			$GLOBALS['authordata'] = get_userdata( $wp_query->post->post_author );
605
+		if ( $wp_query->is_author() && isset( $wp_query->post ) ) {
606
+					$GLOBALS['authordata'] = get_userdata( $wp_query->post->post_author );
607
+		}
586 608
 	}
587 609
 
588 610
 	/**
@@ -646,8 +668,9 @@  discard block
 block discarded – undo
646 668
 		}
647 669
 
648 670
 		// If we've already issued a 404, bail.
649
-		if ( is_404() )
650
-			return;
671
+		if ( is_404() ) {
672
+					return;
673
+		}
651 674
 
652 675
 		// Never 404 for the admin, robots, or if we found posts.
653 676
 		if ( is_admin() || is_robots() || $wp_query->posts ) {
Please login to merge, or discard this patch.
src/wp-includes/class.wp-dependencies.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 	 * @access public
271 271
 	 * @since 2.1.0
272 272
 	 *
273
-	 * @param mixed $handles Item handle and argument (string) or item handles and arguments (array of strings).
273
+	 * @param string $handles Item handle and argument (string) or item handles and arguments (array of strings).
274 274
 	 * @return void
275 275
 	 */
276 276
 	public function remove( $handles ) {
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 	 * @access public
290 290
 	 * @since 2.1.0
291 291
 	 *
292
-	 * @param mixed $handles Item handle and argument (string) or item handles and arguments (array of strings).
292
+	 * @param string $handles Item handle and argument (string) or item handles and arguments (array of strings).
293 293
 	 */
294 294
 	public function enqueue( $handles ) {
295 295
 		foreach ( (array) $handles as $handle ) {
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 	 * @access public
312 312
 	 * @since 2.1.0
313 313
 	 *
314
-	 * @param mixed $handles Item handle and argument (string) or item handles and arguments (array of strings).
314
+	 * @param string $handles Item handle and argument (string) or item handles and arguments (array of strings).
315 315
 	 */
316 316
 	public function dequeue( $handles ) {
317 317
 		foreach ( (array) $handles as $handle ) {
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -95,26 +95,26 @@  discard block
 block discarded – undo
95 95
 	 * @param mixed $group   Group level: level (int), no groups (false).
96 96
 	 * @return array Handles of items that have been processed.
97 97
 	 */
98
-	public function do_items( $handles = false, $group = false ) {
98
+	public function do_items($handles = false, $group = false) {
99 99
 		/*
100 100
 		 * If nothing is passed, print the queue. If a string is passed,
101 101
 		 * print that item. If an array is passed, print those items.
102 102
 		 */
103 103
 		$handles = false === $handles ? $this->queue : (array) $handles;
104
-		$this->all_deps( $handles );
104
+		$this->all_deps($handles);
105 105
 
106
-		foreach ( $this->to_do as $key => $handle ) {
107
-			if ( !in_array($handle, $this->done, true) && isset($this->registered[$handle]) ) {
106
+		foreach ($this->to_do as $key => $handle) {
107
+			if ( ! in_array($handle, $this->done, true) && isset($this->registered[$handle])) {
108 108
 				/*
109 109
 				 * Attempt to process the item. If successful,
110 110
 				 * add the handle to the done array.
111 111
 				 *
112 112
 				 * Unset the item from the to_do array.
113 113
 				 */
114
-				if ( $this->do_item( $handle, $group ) )
114
+				if ($this->do_item($handle, $group))
115 115
 					$this->done[] = $handle;
116 116
 
117
-				unset( $this->to_do[$key] );
117
+				unset($this->to_do[$key]);
118 118
 			}
119 119
 		}
120 120
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 * @param string $handle Name of the item. Should be unique.
131 131
 	 * @return bool True on success, false if not set.
132 132
 	 */
133
-	public function do_item( $handle ) {
133
+	public function do_item($handle) {
134 134
 		return isset($this->registered[$handle]);
135 135
 	}
136 136
 
@@ -150,43 +150,43 @@  discard block
 block discarded – undo
150 150
 	 * @param int|false $group     Group level: (int) level, (false) no groups.
151 151
 	 * @return bool True on success, false on failure.
152 152
 	 */
153
-	public function all_deps( $handles, $recursion = false, $group = false ) {
154
-		if ( !$handles = (array) $handles )
153
+	public function all_deps($handles, $recursion = false, $group = false) {
154
+		if ( ! $handles = (array) $handles)
155 155
 			return false;
156 156
 
157
-		foreach ( $handles as $handle ) {
157
+		foreach ($handles as $handle) {
158 158
 			$handle_parts = explode('?', $handle);
159 159
 			$handle = $handle_parts[0];
160 160
 			$queued = in_array($handle, $this->to_do, true);
161 161
 
162
-			if ( in_array($handle, $this->done, true) ) // Already done
162
+			if (in_array($handle, $this->done, true)) // Already done
163 163
 				continue;
164 164
 
165
-			$moved     = $this->set_group( $handle, $recursion, $group );
166
-			$new_group = $this->groups[ $handle ];
165
+			$moved     = $this->set_group($handle, $recursion, $group);
166
+			$new_group = $this->groups[$handle];
167 167
 
168
-			if ( $queued && !$moved ) // already queued and in the right group
168
+			if ($queued && ! $moved) // already queued and in the right group
169 169
 				continue;
170 170
 
171 171
 			$keep_going = true;
172
-			if ( !isset($this->registered[$handle]) )
172
+			if ( ! isset($this->registered[$handle]))
173 173
 				$keep_going = false; // Item doesn't exist.
174
-			elseif ( $this->registered[$handle]->deps && array_diff($this->registered[$handle]->deps, array_keys($this->registered)) )
174
+			elseif ($this->registered[$handle]->deps && array_diff($this->registered[$handle]->deps, array_keys($this->registered)))
175 175
 				$keep_going = false; // Item requires dependencies that don't exist.
176
-			elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true, $new_group ) )
176
+			elseif ($this->registered[$handle]->deps && ! $this->all_deps($this->registered[$handle]->deps, true, $new_group))
177 177
 				$keep_going = false; // Item requires dependencies that don't exist.
178 178
 
179
-			if ( ! $keep_going ) { // Either item or its dependencies don't exist.
180
-				if ( $recursion )
179
+			if ( ! $keep_going) { // Either item or its dependencies don't exist.
180
+				if ($recursion)
181 181
 					return false; // Abort this branch.
182 182
 				else
183 183
 					continue; // We're at the top level. Move on to the next one.
184 184
 			}
185 185
 
186
-			if ( $queued ) // Already grabbed it and its dependencies.
186
+			if ($queued) // Already grabbed it and its dependencies.
187 187
 				continue;
188 188
 
189
-			if ( isset($handle_parts[1]) )
189
+			if (isset($handle_parts[1]))
190 190
 				$this->args[$handle] = $handle_parts[1];
191 191
 
192 192
 			$this->to_do[] = $handle;
@@ -214,10 +214,10 @@  discard block
 block discarded – undo
214 214
 	 * @param mixed            $args   Optional. Custom property of the item. NOT the class property $args. Examples: $media, $in_footer. 
215 215
 	 * @return bool Whether the item has been registered. True on success, false on failure.
216 216
 	 */
217
-	public function add( $handle, $src, $deps = array(), $ver = false, $args = null ) {
218
-		if ( isset($this->registered[$handle]) )
217
+	public function add($handle, $src, $deps = array(), $ver = false, $args = null) {
218
+		if (isset($this->registered[$handle]))
219 219
 			return false;
220
-		$this->registered[$handle] = new _WP_Dependency( $handle, $src, $deps, $ver, $args );
220
+		$this->registered[$handle] = new _WP_Dependency($handle, $src, $deps, $ver, $args);
221 221
 		return true;
222 222
 	}
223 223
 
@@ -234,11 +234,11 @@  discard block
 block discarded – undo
234 234
 	 * @param mixed  $value  The data value.
235 235
 	 * @return bool True on success, false on failure.
236 236
 	 */
237
-	public function add_data( $handle, $key, $value ) {
238
-		if ( !isset( $this->registered[$handle] ) )
237
+	public function add_data($handle, $key, $value) {
238
+		if ( ! isset($this->registered[$handle]))
239 239
 			return false;
240 240
 
241
-		return $this->registered[$handle]->add_data( $key, $value );
241
+		return $this->registered[$handle]->add_data($key, $value);
242 242
 	}
243 243
 
244 244
 	/**
@@ -253,11 +253,11 @@  discard block
 block discarded – undo
253 253
 	 * @param string $key    The data key.
254 254
 	 * @return mixed Extra item data (string), false otherwise.
255 255
 	 */
256
-	public function get_data( $handle, $key ) {
257
-		if ( !isset( $this->registered[$handle] ) )
256
+	public function get_data($handle, $key) {
257
+		if ( ! isset($this->registered[$handle]))
258 258
 			return false;
259 259
 
260
-		if ( !isset( $this->registered[$handle]->extra[$key] ) )
260
+		if ( ! isset($this->registered[$handle]->extra[$key]))
261 261
 			return false;
262 262
 
263 263
 		return $this->registered[$handle]->extra[$key];
@@ -273,8 +273,8 @@  discard block
 block discarded – undo
273 273
 	 * @param mixed $handles Item handle and argument (string) or item handles and arguments (array of strings).
274 274
 	 * @return void
275 275
 	 */
276
-	public function remove( $handles ) {
277
-		foreach ( (array) $handles as $handle )
276
+	public function remove($handles) {
277
+		foreach ((array) $handles as $handle)
278 278
 			unset($this->registered[$handle]);
279 279
 	}
280 280
 
@@ -292,12 +292,12 @@  discard block
 block discarded – undo
292 292
 	 *
293 293
 	 * @param mixed $handles Item handle and argument (string) or item handles and arguments (array of strings).
294 294
 	 */
295
-	public function enqueue( $handles ) {
296
-		foreach ( (array) $handles as $handle ) {
295
+	public function enqueue($handles) {
296
+		foreach ((array) $handles as $handle) {
297 297
 			$handle = explode('?', $handle);
298
-			if ( !in_array($handle[0], $this->queue) && isset($this->registered[$handle[0]]) ) {
298
+			if ( ! in_array($handle[0], $this->queue) && isset($this->registered[$handle[0]])) {
299 299
 				$this->queue[] = $handle[0];
300
-				if ( isset($handle[1]) )
300
+				if (isset($handle[1]))
301 301
 					$this->args[$handle[0]] = $handle[1];
302 302
 			}
303 303
 		}
@@ -315,11 +315,11 @@  discard block
 block discarded – undo
315 315
 	 *
316 316
 	 * @param mixed $handles Item handle and argument (string) or item handles and arguments (array of strings).
317 317
 	 */
318
-	public function dequeue( $handles ) {
319
-		foreach ( (array) $handles as $handle ) {
318
+	public function dequeue($handles) {
319
+		foreach ((array) $handles as $handle) {
320 320
 			$handle = explode('?', $handle);
321 321
 			$key = array_search($handle[0], $this->queue);
322
-			if ( false !== $key ) {
322
+			if (false !== $key) {
323 323
 				unset($this->queue[$key]);
324 324
 				unset($this->args[$handle[0]]);
325 325
 			}
@@ -335,15 +335,15 @@  discard block
 block discarded – undo
335 335
 	 * @param string $handle Name of the item. Should be unique.
336 336
 	 * @return bool Whether the handle is found after recursively searching the dependency tree.
337 337
 	 */
338
-	protected function recurse_deps( $queue, $handle ) {
339
-		foreach ( $queue as $queued ) {
340
-			if ( ! isset( $this->registered[ $queued ] ) ) {
338
+	protected function recurse_deps($queue, $handle) {
339
+		foreach ($queue as $queued) {
340
+			if ( ! isset($this->registered[$queued])) {
341 341
 				continue;
342 342
 			}
343 343
 
344
-			if ( in_array( $handle, $this->registered[ $queued ]->deps ) ) {
344
+			if (in_array($handle, $this->registered[$queued]->deps)) {
345 345
 				return true;
346
-			} elseif ( $this->recurse_deps( $this->registered[ $queued ]->deps, $handle ) ) {
346
+			} elseif ($this->recurse_deps($this->registered[$queued]->deps, $handle)) {
347 347
 				return true;
348 348
 			}
349 349
 		}
@@ -362,28 +362,28 @@  discard block
 block discarded – undo
362 362
 	 * @param string $list   Property name of list array.
363 363
 	 * @return bool|_WP_Dependency Found, or object Item data.
364 364
 	 */
365
-	public function query( $handle, $list = 'registered' ) {
366
-		switch ( $list ) {
365
+	public function query($handle, $list = 'registered') {
366
+		switch ($list) {
367 367
 			case 'registered' :
368 368
 			case 'scripts': // back compat
369
-				if ( isset( $this->registered[ $handle ] ) )
370
-					return $this->registered[ $handle ];
369
+				if (isset($this->registered[$handle]))
370
+					return $this->registered[$handle];
371 371
 				return false;
372 372
 
373 373
 			case 'enqueued' :
374 374
 			case 'queue' :
375
-				if ( in_array( $handle, $this->queue ) ) {
375
+				if (in_array($handle, $this->queue)) {
376 376
 					return true;
377 377
 				}
378
-				return $this->recurse_deps( $this->queue, $handle );
378
+				return $this->recurse_deps($this->queue, $handle);
379 379
 
380 380
 			case 'to_do' :
381 381
 			case 'to_print': // back compat
382
-				return in_array( $handle, $this->to_do );
382
+				return in_array($handle, $this->to_do);
383 383
 
384 384
 			case 'done' :
385 385
 			case 'printed': // back compat
386
-				return in_array( $handle, $this->done );
386
+				return in_array($handle, $this->done);
387 387
 		}
388 388
 		return false;
389 389
 	}
@@ -399,14 +399,14 @@  discard block
 block discarded – undo
399 399
 	 * @param mixed  $group     Group level.
400 400
 	 * @return bool Not already in the group or a lower group
401 401
 	 */
402
-	public function set_group( $handle, $recursion, $group ) {
402
+	public function set_group($handle, $recursion, $group) {
403 403
 		$group = (int) $group;
404 404
 
405
-		if ( isset( $this->groups[ $handle ] ) && $this->groups[ $handle ] <= $group ) {
405
+		if (isset($this->groups[$handle]) && $this->groups[$handle] <= $group) {
406 406
 			return false;
407 407
 		}
408 408
 
409
-		$this->groups[ $handle ] = $group;
409
+		$this->groups[$handle] = $group;
410 410
 
411 411
 		return true;
412 412
 	}
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 	 * @since 2.6.0
468 468
 	 * @var null
469 469
 	 */
470
-	public $args = null;  // Custom property, such as $in_footer or $media.
470
+	public $args = null; // Custom property, such as $in_footer or $media.
471 471
 
472 472
 	/**
473 473
 	 * Extra data to supply to the handle.
@@ -484,8 +484,8 @@  discard block
 block discarded – undo
484 484
 	 * @since 2.6.0
485 485
 	 */
486 486
 	public function __construct() {
487
-		@list( $this->handle, $this->src, $this->deps, $this->ver, $this->args ) = func_get_args();
488
-		if ( ! is_array($this->deps) )
487
+		@list($this->handle, $this->src, $this->deps, $this->ver, $this->args) = func_get_args();
488
+		if ( ! is_array($this->deps))
489 489
 			$this->deps = array();
490 490
 	}
491 491
 
@@ -499,8 +499,8 @@  discard block
 block discarded – undo
499 499
 	 * @param mixed  $data The data value to add.
500 500
 	 * @return bool False if not scalar, true otherwise.
501 501
 	 */
502
-	public function add_data( $name, $data ) {
503
-		if ( !is_scalar($name) )
502
+	public function add_data($name, $data) {
503
+		if ( ! is_scalar($name))
504 504
 			return false;
505 505
 		$this->extra[$name] = $data;
506 506
 		return true;
Please login to merge, or discard this patch.
Braces   +65 added lines, -37 removed lines patch added patch discarded remove patch
@@ -111,8 +111,9 @@  discard block
 block discarded – undo
111 111
 				 *
112 112
 				 * Unset the item from the to_do array.
113 113
 				 */
114
-				if ( $this->do_item( $handle, $group ) )
115
-					$this->done[] = $handle;
114
+				if ( $this->do_item( $handle, $group ) ) {
115
+									$this->done[] = $handle;
116
+				}
116 117
 
117 118
 				unset( $this->to_do[$key] );
118 119
 			}
@@ -151,43 +152,61 @@  discard block
 block discarded – undo
151 152
 	 * @return bool True on success, false on failure.
152 153
 	 */
153 154
 	public function all_deps( $handles, $recursion = false, $group = false ) {
154
-		if ( !$handles = (array) $handles )
155
-			return false;
155
+		if ( !$handles = (array) $handles ) {
156
+					return false;
157
+		}
156 158
 
157 159
 		foreach ( $handles as $handle ) {
158 160
 			$handle_parts = explode('?', $handle);
159 161
 			$handle = $handle_parts[0];
160 162
 			$queued = in_array($handle, $this->to_do, true);
161 163
 
162
-			if ( in_array($handle, $this->done, true) ) // Already done
164
+			if ( in_array($handle, $this->done, true) ) {
165
+				// Already done
163 166
 				continue;
167
+			}
164 168
 
165 169
 			$moved     = $this->set_group( $handle, $recursion, $group );
166 170
 			$new_group = $this->groups[ $handle ];
167 171
 
168
-			if ( $queued && !$moved ) // already queued and in the right group
172
+			if ( $queued && !$moved ) {
173
+				// already queued and in the right group
169 174
 				continue;
175
+			}
170 176
 
171 177
 			$keep_going = true;
172
-			if ( !isset($this->registered[$handle]) )
173
-				$keep_going = false; // Item doesn't exist.
174
-			elseif ( $this->registered[$handle]->deps && array_diff($this->registered[$handle]->deps, array_keys($this->registered)) )
175
-				$keep_going = false; // Item requires dependencies that don't exist.
176
-			elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true, $new_group ) )
177
-				$keep_going = false; // Item requires dependencies that don't exist.
178
+			if ( !isset($this->registered[$handle]) ) {
179
+							$keep_going = false;
180
+			}
181
+			// Item doesn't exist.
182
+			elseif ( $this->registered[$handle]->deps && array_diff($this->registered[$handle]->deps, array_keys($this->registered)) ) {
183
+							$keep_going = false;
184
+			}
185
+			// Item requires dependencies that don't exist.
186
+			elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true, $new_group ) ) {
187
+							$keep_going = false;
188
+			}
189
+			// Item requires dependencies that don't exist.
178 190
 
179 191
 			if ( ! $keep_going ) { // Either item or its dependencies don't exist.
180
-				if ( $recursion )
181
-					return false; // Abort this branch.
182
-				else
183
-					continue; // We're at the top level. Move on to the next one.
192
+				if ( $recursion ) {
193
+									return false;
194
+				}
195
+				// Abort this branch.
196
+				else {
197
+									continue;
198
+				}
199
+				// We're at the top level. Move on to the next one.
184 200
 			}
185 201
 
186
-			if ( $queued ) // Already grabbed it and its dependencies.
202
+			if ( $queued ) {
203
+				// Already grabbed it and its dependencies.
187 204
 				continue;
205
+			}
188 206
 
189
-			if ( isset($handle_parts[1]) )
190
-				$this->args[$handle] = $handle_parts[1];
207
+			if ( isset($handle_parts[1]) ) {
208
+							$this->args[$handle] = $handle_parts[1];
209
+			}
191 210
 
192 211
 			$this->to_do[] = $handle;
193 212
 		}
@@ -215,8 +234,9 @@  discard block
 block discarded – undo
215 234
 	 * @return bool Whether the item has been registered. True on success, false on failure.
216 235
 	 */
217 236
 	public function add( $handle, $src, $deps = array(), $ver = false, $args = null ) {
218
-		if ( isset($this->registered[$handle]) )
219
-			return false;
237
+		if ( isset($this->registered[$handle]) ) {
238
+					return false;
239
+		}
220 240
 		$this->registered[$handle] = new _WP_Dependency( $handle, $src, $deps, $ver, $args );
221 241
 		return true;
222 242
 	}
@@ -235,8 +255,9 @@  discard block
 block discarded – undo
235 255
 	 * @return bool True on success, false on failure.
236 256
 	 */
237 257
 	public function add_data( $handle, $key, $value ) {
238
-		if ( !isset( $this->registered[$handle] ) )
239
-			return false;
258
+		if ( !isset( $this->registered[$handle] ) ) {
259
+					return false;
260
+		}
240 261
 
241 262
 		return $this->registered[$handle]->add_data( $key, $value );
242 263
 	}
@@ -254,11 +275,13 @@  discard block
 block discarded – undo
254 275
 	 * @return mixed Extra item data (string), false otherwise.
255 276
 	 */
256 277
 	public function get_data( $handle, $key ) {
257
-		if ( !isset( $this->registered[$handle] ) )
258
-			return false;
278
+		if ( !isset( $this->registered[$handle] ) ) {
279
+					return false;
280
+		}
259 281
 
260
-		if ( !isset( $this->registered[$handle]->extra[$key] ) )
261
-			return false;
282
+		if ( !isset( $this->registered[$handle]->extra[$key] ) ) {
283
+					return false;
284
+		}
262 285
 
263 286
 		return $this->registered[$handle]->extra[$key];
264 287
 	}
@@ -274,8 +297,9 @@  discard block
 block discarded – undo
274 297
 	 * @return void
275 298
 	 */
276 299
 	public function remove( $handles ) {
277
-		foreach ( (array) $handles as $handle )
278
-			unset($this->registered[$handle]);
300
+		foreach ( (array) $handles as $handle ) {
301
+					unset($this->registered[$handle]);
302
+		}
279 303
 	}
280 304
 
281 305
 	/**
@@ -297,8 +321,9 @@  discard block
 block discarded – undo
297 321
 			$handle = explode('?', $handle);
298 322
 			if ( !in_array($handle[0], $this->queue) && isset($this->registered[$handle[0]]) ) {
299 323
 				$this->queue[] = $handle[0];
300
-				if ( isset($handle[1]) )
301
-					$this->args[$handle[0]] = $handle[1];
324
+				if ( isset($handle[1]) ) {
325
+									$this->args[$handle[0]] = $handle[1];
326
+				}
302 327
 			}
303 328
 		}
304 329
 	}
@@ -366,8 +391,9 @@  discard block
 block discarded – undo
366 391
 		switch ( $list ) {
367 392
 			case 'registered' :
368 393
 			case 'scripts': // back compat
369
-				if ( isset( $this->registered[ $handle ] ) )
370
-					return $this->registered[ $handle ];
394
+				if ( isset( $this->registered[ $handle ] ) ) {
395
+									return $this->registered[ $handle ];
396
+				}
371 397
 				return false;
372 398
 
373 399
 			case 'enqueued' :
@@ -485,8 +511,9 @@  discard block
 block discarded – undo
485 511
 	 */
486 512
 	public function __construct() {
487 513
 		@list( $this->handle, $this->src, $this->deps, $this->ver, $this->args ) = func_get_args();
488
-		if ( ! is_array($this->deps) )
489
-			$this->deps = array();
514
+		if ( ! is_array($this->deps) ) {
515
+					$this->deps = array();
516
+		}
490 517
 	}
491 518
 
492 519
 	/**
@@ -500,8 +527,9 @@  discard block
 block discarded – undo
500 527
 	 * @return bool False if not scalar, true otherwise.
501 528
 	 */
502 529
 	public function add_data( $name, $data ) {
503
-		if ( !is_scalar($name) )
504
-			return false;
530
+		if ( !is_scalar($name) ) {
531
+					return false;
532
+		}
505 533
 		$this->extra[$name] = $data;
506 534
 		return true;
507 535
 	}
Please login to merge, or discard this patch.
src/wp-includes/date.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
 	 *
800 800
 	 * @param string $compare The compare operator to use
801 801
 	 * @param string|array $value The value
802
-	 * @return string|false|int The value to be used in SQL or false on error.
802
+	 * @return string The value to be used in SQL or false on error.
803 803
 	 */
804 804
 	public function build_value( $compare, $value ) {
805 805
 		if ( ! isset( $value ) )
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
 	 *                                     of $datetime that are arrays, or string values that are a
863 863
 	 *                                     subset of MySQL date format ('Y', 'Y-m', 'Y-m-d', 'Y-m-d H:i').
864 864
 	 *                                     Default: false.
865
-	 * @return string|false A MySQL format date/time or false on failure
865
+	 * @return string A MySQL format date/time or false on failure
866 866
 	 */
867 867
 	public function build_mysql_datetime( $datetime, $default_to_max = false ) {
868 868
 		$now = current_time( 'timestamp' );
Please login to merge, or discard this patch.
Braces   +60 added lines, -40 removed lines patch added patch discarded remove patch
@@ -270,8 +270,9 @@  discard block
 block discarded – undo
270 270
 	 * @return string The comparison operator.
271 271
 	 */
272 272
 	public function get_compare( $query ) {
273
-		if ( ! empty( $query['compare'] ) && in_array( $query['compare'], array( '=', '!=', '>', '>=', '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) )
274
-			return strtoupper( $query['compare'] );
273
+		if ( ! empty( $query['compare'] ) && in_array( $query['compare'], array( '=', '!=', '>', '>=', '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
274
+					return strtoupper( $query['compare'] );
275
+		}
275 276
 
276 277
 		return $this->compare;
277 278
 	}
@@ -735,16 +736,19 @@  discard block
 block discarded – undo
735 736
 		}
736 737
 
737 738
 		// Range queries.
738
-		if ( ! empty( $query['after'] ) )
739
-			$where_parts[] = $wpdb->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], ! $inclusive ) );
739
+		if ( ! empty( $query['after'] ) ) {
740
+					$where_parts[] = $wpdb->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], ! $inclusive ) );
741
+		}
740 742
 
741
-		if ( ! empty( $query['before'] ) )
742
-			$where_parts[] = $wpdb->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], $inclusive ) );
743
+		if ( ! empty( $query['before'] ) ) {
744
+					$where_parts[] = $wpdb->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], $inclusive ) );
745
+		}
743 746
 
744 747
 		// Specific value queries.
745 748
 
746
-		if ( isset( $query['year'] ) && $value = $this->build_value( $compare, $query['year'] ) )
747
-			$where_parts[] = "YEAR( $column ) $compare $value";
749
+		if ( isset( $query['year'] ) && $value = $this->build_value( $compare, $query['year'] ) ) {
750
+					$where_parts[] = "YEAR( $column ) $compare $value";
751
+		}
748 752
 
749 753
 		if ( isset( $query['month'] ) && $value = $this->build_value( $compare, $query['month'] ) ) {
750 754
 			$where_parts[] = "MONTH( $column ) $compare $value";
@@ -756,17 +760,21 @@  discard block
 block discarded – undo
756 760
 		} elseif ( isset( $query['w'] ) && false !== ( $value = $this->build_value( $compare, $query['w'] ) ) ) {
757 761
 			$where_parts[] = _wp_mysql_week( $column ) . " $compare $value";
758 762
 		}
759
-		if ( isset( $query['dayofyear'] ) && $value = $this->build_value( $compare, $query['dayofyear'] ) )
760
-			$where_parts[] = "DAYOFYEAR( $column ) $compare $value";
763
+		if ( isset( $query['dayofyear'] ) && $value = $this->build_value( $compare, $query['dayofyear'] ) ) {
764
+					$where_parts[] = "DAYOFYEAR( $column ) $compare $value";
765
+		}
761 766
 
762
-		if ( isset( $query['day'] ) && $value = $this->build_value( $compare, $query['day'] ) )
763
-			$where_parts[] = "DAYOFMONTH( $column ) $compare $value";
767
+		if ( isset( $query['day'] ) && $value = $this->build_value( $compare, $query['day'] ) ) {
768
+					$where_parts[] = "DAYOFMONTH( $column ) $compare $value";
769
+		}
764 770
 
765
-		if ( isset( $query['dayofweek'] ) && $value = $this->build_value( $compare, $query['dayofweek'] ) )
766
-			$where_parts[] = "DAYOFWEEK( $column ) $compare $value";
771
+		if ( isset( $query['dayofweek'] ) && $value = $this->build_value( $compare, $query['dayofweek'] ) ) {
772
+					$where_parts[] = "DAYOFWEEK( $column ) $compare $value";
773
+		}
767 774
 
768
-		if ( isset( $query['dayofweek_iso'] ) && $value = $this->build_value( $compare, $query['dayofweek_iso'] ) )
769
-			$where_parts[] = "WEEKDAY( $column ) + 1 $compare $value";
775
+		if ( isset( $query['dayofweek_iso'] ) && $value = $this->build_value( $compare, $query['dayofweek_iso'] ) ) {
776
+					$where_parts[] = "WEEKDAY( $column ) + 1 $compare $value";
777
+		}
770 778
 
771 779
 		if ( isset( $query['hour'] ) || isset( $query['minute'] ) || isset( $query['second'] ) ) {
772 780
 			// Avoid notices.
@@ -802,8 +810,9 @@  discard block
 block discarded – undo
802 810
 	 * @return string|false|int The value to be used in SQL or false on error.
803 811
 	 */
804 812
 	public function build_value( $compare, $value ) {
805
-		if ( ! isset( $value ) )
806
-			return false;
813
+		if ( ! isset( $value ) ) {
814
+					return false;
815
+		}
807 816
 
808 817
 		switch ( $compare ) {
809 818
 			case 'IN':
@@ -914,23 +923,29 @@  discard block
 block discarded – undo
914 923
 
915 924
 		$datetime = array_map( 'absint', $datetime );
916 925
 
917
-		if ( ! isset( $datetime['year'] ) )
918
-			$datetime['year'] = gmdate( 'Y', $now );
926
+		if ( ! isset( $datetime['year'] ) ) {
927
+					$datetime['year'] = gmdate( 'Y', $now );
928
+		}
919 929
 
920
-		if ( ! isset( $datetime['month'] ) )
921
-			$datetime['month'] = ( $default_to_max ) ? 12 : 1;
930
+		if ( ! isset( $datetime['month'] ) ) {
931
+					$datetime['month'] = ( $default_to_max ) ? 12 : 1;
932
+		}
922 933
 
923
-		if ( ! isset( $datetime['day'] ) )
924
-			$datetime['day'] = ( $default_to_max ) ? (int) date( 't', mktime( 0, 0, 0, $datetime['month'], 1, $datetime['year'] ) ) : 1;
934
+		if ( ! isset( $datetime['day'] ) ) {
935
+					$datetime['day'] = ( $default_to_max ) ? (int) date( 't', mktime( 0, 0, 0, $datetime['month'], 1, $datetime['year'] ) ) : 1;
936
+		}
925 937
 
926
-		if ( ! isset( $datetime['hour'] ) )
927
-			$datetime['hour'] = ( $default_to_max ) ? 23 : 0;
938
+		if ( ! isset( $datetime['hour'] ) ) {
939
+					$datetime['hour'] = ( $default_to_max ) ? 23 : 0;
940
+		}
928 941
 
929
-		if ( ! isset( $datetime['minute'] ) )
930
-			$datetime['minute'] = ( $default_to_max ) ? 59 : 0;
942
+		if ( ! isset( $datetime['minute'] ) ) {
943
+					$datetime['minute'] = ( $default_to_max ) ? 59 : 0;
944
+		}
931 945
 
932
-		if ( ! isset( $datetime['second'] ) )
933
-			$datetime['second'] = ( $default_to_max ) ? 59 : 0;
946
+		if ( ! isset( $datetime['second'] ) ) {
947
+					$datetime['second'] = ( $default_to_max ) ? 59 : 0;
948
+		}
934 949
 
935 950
 		return sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $datetime['year'], $datetime['month'], $datetime['day'], $datetime['hour'], $datetime['minute'], $datetime['second'] );
936 951
 	}
@@ -956,21 +971,25 @@  discard block
 block discarded – undo
956 971
 		global $wpdb;
957 972
 
958 973
 		// Have to have at least one
959
-		if ( ! isset( $hour ) && ! isset( $minute ) && ! isset( $second ) )
960
-			return false;
974
+		if ( ! isset( $hour ) && ! isset( $minute ) && ! isset( $second ) ) {
975
+					return false;
976
+		}
961 977
 
962 978
 		// Complex combined queries aren't supported for multi-value queries
963 979
 		if ( in_array( $compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
964 980
 			$return = array();
965 981
 
966
-			if ( isset( $hour ) && false !== ( $value = $this->build_value( $compare, $hour ) ) )
967
-				$return[] = "HOUR( $column ) $compare $value";
982
+			if ( isset( $hour ) && false !== ( $value = $this->build_value( $compare, $hour ) ) ) {
983
+							$return[] = "HOUR( $column ) $compare $value";
984
+			}
968 985
 
969
-			if ( isset( $minute ) && false !== ( $value = $this->build_value( $compare, $minute ) ) )
970
-				$return[] = "MINUTE( $column ) $compare $value";
986
+			if ( isset( $minute ) && false !== ( $value = $this->build_value( $compare, $minute ) ) ) {
987
+							$return[] = "MINUTE( $column ) $compare $value";
988
+			}
971 989
 
972
-			if ( isset( $second ) && false !== ( $value = $this->build_value( $compare, $second ) ) )
973
-				$return[] = "SECOND( $column ) $compare $value";
990
+			if ( isset( $second ) && false !== ( $value = $this->build_value( $compare, $second ) ) ) {
991
+							$return[] = "SECOND( $column ) $compare $value";
992
+			}
974 993
 
975 994
 			return implode( ' AND ', $return );
976 995
 		}
@@ -985,8 +1004,9 @@  discard block
 block discarded – undo
985 1004
 		}
986 1005
 
987 1006
 		// Single units were already handled. Since hour & second isn't allowed, minute must to be set.
988
-		if ( ! isset( $minute ) )
989
-			return false;
1007
+		if ( ! isset( $minute ) ) {
1008
+					return false;
1009
+		}
990 1010
 
991 1011
 		$format = $time = '';
992 1012
 
Please login to merge, or discard this patch.
Spacing   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 * @access public
61 61
 	 * @var array
62 62
 	 */
63
-	public $time_keys = array( 'after', 'before', 'year', 'month', 'monthnum', 'week', 'w', 'dayofyear', 'day', 'dayofweek', 'dayofweek_iso', 'hour', 'minute', 'second' );
63
+	public $time_keys = array('after', 'before', 'year', 'month', 'monthnum', 'week', 'w', 'dayofyear', 'day', 'dayofweek', 'dayofweek_iso', 'hour', 'minute', 'second');
64 64
 
65 65
 	/**
66 66
 	 * Constructor.
@@ -150,38 +150,38 @@  discard block
 block discarded – undo
150 150
 	 *                              Accepts 'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt',
151 151
 	 *                              'comment_date', 'comment_date_gmt'.
152 152
 	 */
153
-	public function __construct( $date_query, $default_column = 'post_date' ) {
153
+	public function __construct($date_query, $default_column = 'post_date') {
154 154
 
155
-		if ( isset( $date_query['relation'] ) && 'OR' === strtoupper( $date_query['relation'] ) ) {
155
+		if (isset($date_query['relation']) && 'OR' === strtoupper($date_query['relation'])) {
156 156
 			$this->relation = 'OR';
157 157
 		} else {
158 158
 			$this->relation = 'AND';
159 159
 		}
160 160
 
161
-		if ( ! is_array( $date_query ) ) {
161
+		if ( ! is_array($date_query)) {
162 162
 			return;
163 163
 		}
164 164
 
165 165
 		// Support for passing time-based keys in the top level of the $date_query array.
166
-		if ( ! isset( $date_query[0] ) && ! empty( $date_query ) ) {
167
-			$date_query = array( $date_query );
166
+		if ( ! isset($date_query[0]) && ! empty($date_query)) {
167
+			$date_query = array($date_query);
168 168
 		}
169 169
 
170
-		if ( empty( $date_query ) ) {
170
+		if (empty($date_query)) {
171 171
 			return;
172 172
 		}
173 173
 
174
-		if ( ! empty( $date_query['column'] ) ) {
175
-			$date_query['column'] = esc_sql( $date_query['column'] );
174
+		if ( ! empty($date_query['column'])) {
175
+			$date_query['column'] = esc_sql($date_query['column']);
176 176
 		} else {
177
-			$date_query['column'] = esc_sql( $default_column );
177
+			$date_query['column'] = esc_sql($default_column);
178 178
 		}
179 179
 
180
-		$this->column = $this->validate_column( $this->column );
180
+		$this->column = $this->validate_column($this->column);
181 181
 
182
-		$this->compare = $this->get_compare( $date_query );
182
+		$this->compare = $this->get_compare($date_query);
183 183
 
184
-		$this->queries = $this->sanitize_query( $date_query );
184
+		$this->queries = $this->sanitize_query($date_query);
185 185
 	}
186 186
 
187 187
 	/**
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 	 *
200 200
 	 * @return array Sanitized queries.
201 201
 	 */
202
-	public function sanitize_query( $queries, $parent_query = null ) {
202
+	public function sanitize_query($queries, $parent_query = null) {
203 203
 		$cleaned_query = array();
204 204
 
205 205
 		$defaults = array(
@@ -209,37 +209,37 @@  discard block
 block discarded – undo
209 209
 		);
210 210
 
211 211
 		// Numeric keys should always have array values.
212
-		foreach ( $queries as $qkey => $qvalue ) {
213
-			if ( is_numeric( $qkey ) && ! is_array( $qvalue ) ) {
214
-				unset( $queries[ $qkey ] );
212
+		foreach ($queries as $qkey => $qvalue) {
213
+			if (is_numeric($qkey) && ! is_array($qvalue)) {
214
+				unset($queries[$qkey]);
215 215
 			}
216 216
 		}
217 217
 
218 218
 		// Each query should have a value for each default key. Inherit from the parent when possible.
219
-		foreach ( $defaults as $dkey => $dvalue ) {
220
-			if ( isset( $queries[ $dkey ] ) ) {
219
+		foreach ($defaults as $dkey => $dvalue) {
220
+			if (isset($queries[$dkey])) {
221 221
 				continue;
222 222
 			}
223 223
 
224
-			if ( isset( $parent_query[ $dkey ] ) ) {
225
-				$queries[ $dkey ] = $parent_query[ $dkey ];
224
+			if (isset($parent_query[$dkey])) {
225
+				$queries[$dkey] = $parent_query[$dkey];
226 226
 			} else {
227
-				$queries[ $dkey ] = $dvalue;
227
+				$queries[$dkey] = $dvalue;
228 228
 			}
229 229
 		}
230 230
 
231 231
 		// Validate the dates passed in the query.
232
-		if ( $this->is_first_order_clause( $queries ) ) {
233
-			$this->validate_date_values( $queries );
232
+		if ($this->is_first_order_clause($queries)) {
233
+			$this->validate_date_values($queries);
234 234
 		}
235 235
 
236
-		foreach ( $queries as $key => $q ) {
237
-			if ( ! is_array( $q ) || in_array( $key, $this->time_keys, true ) ) {
236
+		foreach ($queries as $key => $q) {
237
+			if ( ! is_array($q) || in_array($key, $this->time_keys, true)) {
238 238
 				// This is a first-order query. Trust the values and sanitize when building SQL.
239
-				$cleaned_query[ $key ] = $q;
239
+				$cleaned_query[$key] = $q;
240 240
 			} else {
241 241
 				// Any array without a time key is another query, so we recurse.
242
-				$cleaned_query[] = $this->sanitize_query( $q, $queries );
242
+				$cleaned_query[] = $this->sanitize_query($q, $queries);
243 243
 			}
244 244
 		}
245 245
 
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
 	 * @param  array $query Query clause.
256 256
 	 * @return bool True if this is a first-order clause.
257 257
 	 */
258
-	protected function is_first_order_clause( $query ) {
259
-		$time_keys = array_intersect( $this->time_keys, array_keys( $query ) );
260
-		return ! empty( $time_keys );
258
+	protected function is_first_order_clause($query) {
259
+		$time_keys = array_intersect($this->time_keys, array_keys($query));
260
+		return ! empty($time_keys);
261 261
 	}
262 262
 
263 263
 	/**
@@ -269,9 +269,9 @@  discard block
 block discarded – undo
269 269
 	 * @param array $query A date query or a date subquery.
270 270
 	 * @return string The comparison operator.
271 271
 	 */
272
-	public function get_compare( $query ) {
273
-		if ( ! empty( $query['compare'] ) && in_array( $query['compare'], array( '=', '!=', '>', '>=', '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) )
274
-			return strtoupper( $query['compare'] );
272
+	public function get_compare($query) {
273
+		if ( ! empty($query['compare']) && in_array($query['compare'], array('=', '!=', '>', '>=', '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN')))
274
+			return strtoupper($query['compare']);
275 275
 
276 276
 		return $this->compare;
277 277
 	}
@@ -289,8 +289,8 @@  discard block
 block discarded – undo
289 289
 	 * @param  array $date_query The date_query array.
290 290
 	 * @return bool  True if all values in the query are valid, false if one or more fail.
291 291
 	 */
292
-	public function validate_date_values( $date_query = array() ) {
293
-		if ( empty( $date_query ) ) {
292
+	public function validate_date_values($date_query = array()) {
293
+		if (empty($date_query)) {
294 294
 			return false;
295 295
 		}
296 296
 
@@ -301,30 +301,30 @@  discard block
 block discarded – undo
301 301
 		 * validation routine continue to be sure that all invalid
302 302
 		 * values generate errors too.
303 303
 		 */
304
-		if ( array_key_exists( 'before', $date_query ) && is_array( $date_query['before'] ) ){
305
-			$valid = $this->validate_date_values( $date_query['before'] );
304
+		if (array_key_exists('before', $date_query) && is_array($date_query['before'])) {
305
+			$valid = $this->validate_date_values($date_query['before']);
306 306
 		}
307 307
 
308
-		if ( array_key_exists( 'after', $date_query ) && is_array( $date_query['after'] ) ){
309
-			$valid = $this->validate_date_values( $date_query['after'] );
308
+		if (array_key_exists('after', $date_query) && is_array($date_query['after'])) {
309
+			$valid = $this->validate_date_values($date_query['after']);
310 310
 		}
311 311
 
312 312
 		// Array containing all min-max checks.
313 313
 		$min_max_checks = array();
314 314
 
315 315
 		// Days per year.
316
-		if ( array_key_exists( 'year', $date_query ) ) {
316
+		if (array_key_exists('year', $date_query)) {
317 317
 			/*
318 318
 			 * If a year exists in the date query, we can use it to get the days.
319 319
 			 * If multiple years are provided (as in a BETWEEN), use the first one.
320 320
 			 */
321
-			if ( is_array( $date_query['year'] ) ) {
322
-				$_year = reset( $date_query['year'] );
321
+			if (is_array($date_query['year'])) {
322
+				$_year = reset($date_query['year']);
323 323
 			} else {
324 324
 				$_year = $date_query['year'];
325 325
 			}
326 326
 
327
-			$max_days_of_year = date( 'z', mktime( 0, 0, 0, 12, 31, $_year ) ) + 1;
327
+			$max_days_of_year = date('z', mktime(0, 0, 0, 12, 31, $_year)) + 1;
328 328
 		} else {
329 329
 			// otherwise we use the max of 366 (leap-year)
330 330
 			$max_days_of_year = 366;
@@ -354,12 +354,12 @@  discard block
 block discarded – undo
354 354
 		);
355 355
 
356 356
 		// Weeks per year.
357
-		if ( isset( $_year ) ) {
357
+		if (isset($_year)) {
358 358
 			/*
359 359
 			 * If we have a specific year, use it to calculate number of weeks.
360 360
 			 * Note: the number of weeks in a year is the date in which Dec 28 appears.
361 361
 			 */
362
-			$week_count = date( 'W', mktime( 0, 0, 0, 12, 28, $_year ) );
362
+			$week_count = date('W', mktime(0, 0, 0, 12, 28, $_year));
363 363
 
364 364
 		} else {
365 365
 			// Otherwise set the week-count to a maximum of 53.
@@ -396,26 +396,26 @@  discard block
 block discarded – undo
396 396
 		);
397 397
 
398 398
 		// Concatenate and throw a notice for each invalid value.
399
-		foreach ( $min_max_checks as $key => $check ) {
400
-			if ( ! array_key_exists( $key, $date_query ) ) {
399
+		foreach ($min_max_checks as $key => $check) {
400
+			if ( ! array_key_exists($key, $date_query)) {
401 401
 				continue;
402 402
 			}
403 403
 
404 404
 			// Throw a notice for each failing value.
405
-			foreach ( (array) $date_query[ $key ] as $_value ) {
405
+			foreach ((array) $date_query[$key] as $_value) {
406 406
 				$is_between = $_value >= $check['min'] && $_value <= $check['max'];
407 407
 
408
-				if ( ! is_numeric( $_value ) || ! $is_between ) {
408
+				if ( ! is_numeric($_value) || ! $is_between) {
409 409
 					$error = sprintf(
410 410
 						/* translators: Date query invalid date message: 1: invalid value, 2: type of value, 3: minimum valid value, 4: maximum valid value */
411
-						__( 'Invalid value %1$s for %2$s. Expected value should be between %3$s and %4$s.' ),
412
-						'<code>' . esc_html( $_value ) . '</code>',
413
-						'<code>' . esc_html( $key ) . '</code>',
414
-						'<code>' . esc_html( $check['min'] ) . '</code>',
415
-						'<code>' . esc_html( $check['max'] ) . '</code>'
411
+						__('Invalid value %1$s for %2$s. Expected value should be between %3$s and %4$s.'),
412
+						'<code>'.esc_html($_value).'</code>',
413
+						'<code>'.esc_html($key).'</code>',
414
+						'<code>'.esc_html($check['min']).'</code>',
415
+						'<code>'.esc_html($check['max']).'</code>'
416 416
 					);
417 417
 
418
-					_doing_it_wrong( __CLASS__, $error, '4.1.0' );
418
+					_doing_it_wrong(__CLASS__, $error, '4.1.0');
419 419
 
420 420
 					$valid = false;
421 421
 				}
@@ -423,49 +423,49 @@  discard block
 block discarded – undo
423 423
 		}
424 424
 
425 425
 		// If we already have invalid date messages, don't bother running through checkdate().
426
-		if ( ! $valid ) {
426
+		if ( ! $valid) {
427 427
 			return $valid;
428 428
 		}
429 429
 
430 430
 		$day_month_year_error_msg = '';
431 431
 
432
-		$day_exists   = array_key_exists( 'day', $date_query ) && is_numeric( $date_query['day'] );
433
-		$month_exists = array_key_exists( 'month', $date_query ) && is_numeric( $date_query['month'] );
434
-		$year_exists  = array_key_exists( 'year', $date_query ) && is_numeric( $date_query['year'] );
432
+		$day_exists   = array_key_exists('day', $date_query) && is_numeric($date_query['day']);
433
+		$month_exists = array_key_exists('month', $date_query) && is_numeric($date_query['month']);
434
+		$year_exists  = array_key_exists('year', $date_query) && is_numeric($date_query['year']);
435 435
 
436
-		if ( $day_exists && $month_exists && $year_exists ) {
436
+		if ($day_exists && $month_exists && $year_exists) {
437 437
 			// 1. Checking day, month, year combination.
438
-			if ( ! wp_checkdate( $date_query['month'], $date_query['day'], $date_query['year'], sprintf( '%s-%s-%s', $date_query['year'], $date_query['month'], $date_query['day'] ) ) ) {
438
+			if ( ! wp_checkdate($date_query['month'], $date_query['day'], $date_query['year'], sprintf('%s-%s-%s', $date_query['year'], $date_query['month'], $date_query['day']))) {
439 439
 				/* translators: 1: year, 2: month, 3: day of month */
440 440
 				$day_month_year_error_msg = sprintf(
441
-					__( 'The following values do not describe a valid date: year %1$s, month %2$s, day %3$s.' ),
442
-					'<code>' . esc_html( $date_query['year'] ) . '</code>',
443
-					'<code>' . esc_html( $date_query['month'] ) . '</code>',
444
-					'<code>' . esc_html( $date_query['day'] ) . '</code>'
441
+					__('The following values do not describe a valid date: year %1$s, month %2$s, day %3$s.'),
442
+					'<code>'.esc_html($date_query['year']).'</code>',
443
+					'<code>'.esc_html($date_query['month']).'</code>',
444
+					'<code>'.esc_html($date_query['day']).'</code>'
445 445
 				);
446 446
 
447 447
 				$valid = false;
448 448
 			}
449 449
 
450
-		} elseif ( $day_exists && $month_exists ) {
450
+		} elseif ($day_exists && $month_exists) {
451 451
 			/*
452 452
 			 * 2. checking day, month combination
453 453
 			 * We use 2012 because, as a leap year, it's the most permissive.
454 454
 			 */
455
-			if ( ! wp_checkdate( $date_query['month'], $date_query['day'], 2012, sprintf( '2012-%s-%s', $date_query['month'], $date_query['day'] ) ) ) {
455
+			if ( ! wp_checkdate($date_query['month'], $date_query['day'], 2012, sprintf('2012-%s-%s', $date_query['month'], $date_query['day']))) {
456 456
 				/* translators: 1: month, 2: day of month */
457 457
 				$day_month_year_error_msg = sprintf(
458
-					__( 'The following values do not describe a valid date: month %1$s, day %2$s.' ),
459
-					'<code>' . esc_html( $date_query['month'] ) . '</code>',
460
-					'<code>' . esc_html( $date_query['day'] ) . '</code>'
458
+					__('The following values do not describe a valid date: month %1$s, day %2$s.'),
459
+					'<code>'.esc_html($date_query['month']).'</code>',
460
+					'<code>'.esc_html($date_query['day']).'</code>'
461 461
 				);
462 462
 
463 463
 				$valid = false;
464 464
 			}
465 465
 		}
466 466
 
467
-		if ( ! empty( $day_month_year_error_msg ) ) {
468
-			_doing_it_wrong( __CLASS__, $day_month_year_error_msg, '4.1.0' );
467
+		if ( ! empty($day_month_year_error_msg)) {
468
+			_doing_it_wrong(__CLASS__, $day_month_year_error_msg, '4.1.0');
469 469
 		}
470 470
 
471 471
 		return $valid;
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 	 * @param string $column The user-supplied column name.
486 486
 	 * @return string A validated column name value.
487 487
 	 */
488
-	public function validate_column( $column ) {
488
+	public function validate_column($column) {
489 489
 		global $wpdb;
490 490
 
491 491
 		$valid_columns = array(
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 		);
496 496
 
497 497
 		// Attempt to detect a table prefix.
498
-		if ( false === strpos( $column, '.' ) ) {
498
+		if (false === strpos($column, '.')) {
499 499
 			/**
500 500
 			 * Filter the list of valid date query columns.
501 501
 			 *
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
 			 *                             'post_modified_gmt', 'comment_date', 'comment_date_gmt',
508 508
 			 *	                           'user_registered'
509 509
 			 */
510
-			if ( ! in_array( $column, apply_filters( 'date_query_valid_columns', $valid_columns ) ) ) {
510
+			if ( ! in_array($column, apply_filters('date_query_valid_columns', $valid_columns))) {
511 511
 				$column = 'post_date';
512 512
 			}
513 513
 
@@ -528,9 +528,9 @@  discard block
 block discarded – undo
528 528
 			);
529 529
 
530 530
 			// If it's a known column name, add the appropriate table prefix.
531
-			foreach ( $known_columns as $table_name => $table_columns ) {
532
-				if ( in_array( $column, $table_columns ) ) {
533
-					$column = $table_name . '.' . $column;
531
+			foreach ($known_columns as $table_name => $table_columns) {
532
+				if (in_array($column, $table_columns)) {
533
+					$column = $table_name.'.'.$column;
534 534
 					break;
535 535
 				}
536 536
 			}
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
 		}
539 539
 
540 540
 		// Remove unsafe characters.
541
-		return preg_replace( '/[^a-zA-Z0-9_$\.]/', '', $column );
541
+		return preg_replace('/[^a-zA-Z0-9_$\.]/', '', $column);
542 542
 	}
543 543
 
544 544
 	/**
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
 		 * @param string        $where WHERE clause of the date query.
563 563
 		 * @param WP_Date_Query $this  The WP_Date_Query instance.
564 564
 		 */
565
-		return apply_filters( 'get_date_sql', $where, $this );
565
+		return apply_filters('get_date_sql', $where, $this);
566 566
 	}
567 567
 
568 568
 	/**
@@ -582,10 +582,10 @@  discard block
 block discarded – undo
582 582
 	 * }
583 583
 	 */
584 584
 	protected function get_sql_clauses() {
585
-		$sql = $this->get_sql_for_query( $this->queries );
585
+		$sql = $this->get_sql_for_query($this->queries);
586 586
 
587
-		if ( ! empty( $sql['where'] ) ) {
588
-			$sql['where'] = ' AND ' . $sql['where'];
587
+		if ( ! empty($sql['where'])) {
588
+			$sql['where'] = ' AND '.$sql['where'];
589 589
 		}
590 590
 
591 591
 		return $sql;
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
 	 *     @type string $where SQL fragment to append to the main WHERE clause.
611 611
 	 * }
612 612
 	 */
613
-	protected function get_sql_for_query( $query, $depth = 0 ) {
613
+	protected function get_sql_for_query($query, $depth = 0) {
614 614
 		$sql_chunks = array(
615 615
 			'join'  => array(),
616 616
 			'where' => array(),
@@ -622,32 +622,32 @@  discard block
 block discarded – undo
622 622
 		);
623 623
 
624 624
 		$indent = '';
625
-		for ( $i = 0; $i < $depth; $i++ ) {
625
+		for ($i = 0; $i < $depth; $i++) {
626 626
 			$indent .= "  ";
627 627
 		}
628 628
 
629
-		foreach ( $query as $key => $clause ) {
630
-			if ( 'relation' === $key ) {
629
+		foreach ($query as $key => $clause) {
630
+			if ('relation' === $key) {
631 631
 				$relation = $query['relation'];
632
-			} elseif ( is_array( $clause ) ) {
632
+			} elseif (is_array($clause)) {
633 633
 
634 634
 				// This is a first-order clause.
635
-				if ( $this->is_first_order_clause( $clause ) ) {
636
-					$clause_sql = $this->get_sql_for_clause( $clause, $query );
635
+				if ($this->is_first_order_clause($clause)) {
636
+					$clause_sql = $this->get_sql_for_clause($clause, $query);
637 637
 
638
-					$where_count = count( $clause_sql['where'] );
639
-					if ( ! $where_count ) {
638
+					$where_count = count($clause_sql['where']);
639
+					if ( ! $where_count) {
640 640
 						$sql_chunks['where'][] = '';
641
-					} elseif ( 1 === $where_count ) {
641
+					} elseif (1 === $where_count) {
642 642
 						$sql_chunks['where'][] = $clause_sql['where'][0];
643 643
 					} else {
644
-						$sql_chunks['where'][] = '( ' . implode( ' AND ', $clause_sql['where'] ) . ' )';
644
+						$sql_chunks['where'][] = '( '.implode(' AND ', $clause_sql['where']).' )';
645 645
 					}
646 646
 
647
-					$sql_chunks['join'] = array_merge( $sql_chunks['join'], $clause_sql['join'] );
647
+					$sql_chunks['join'] = array_merge($sql_chunks['join'], $clause_sql['join']);
648 648
 				// This is a subquery, so we recurse.
649 649
 				} else {
650
-					$clause_sql = $this->get_sql_for_query( $clause, $depth + 1 );
650
+					$clause_sql = $this->get_sql_for_query($clause, $depth + 1);
651 651
 
652 652
 					$sql_chunks['where'][] = $clause_sql['where'];
653 653
 					$sql_chunks['join'][]  = $clause_sql['join'];
@@ -656,21 +656,21 @@  discard block
 block discarded – undo
656 656
 		}
657 657
 
658 658
 		// Filter to remove empties.
659
-		$sql_chunks['join']  = array_filter( $sql_chunks['join'] );
660
-		$sql_chunks['where'] = array_filter( $sql_chunks['where'] );
659
+		$sql_chunks['join']  = array_filter($sql_chunks['join']);
660
+		$sql_chunks['where'] = array_filter($sql_chunks['where']);
661 661
 
662
-		if ( empty( $relation ) ) {
662
+		if (empty($relation)) {
663 663
 			$relation = 'AND';
664 664
 		}
665 665
 
666 666
 		// Filter duplicate JOIN clauses and combine into a single string.
667
-		if ( ! empty( $sql_chunks['join'] ) ) {
668
-			$sql['join'] = implode( ' ', array_unique( $sql_chunks['join'] ) );
667
+		if ( ! empty($sql_chunks['join'])) {
668
+			$sql['join'] = implode(' ', array_unique($sql_chunks['join']));
669 669
 		}
670 670
 
671 671
 		// Generate a single WHERE clause with proper brackets and indentation.
672
-		if ( ! empty( $sql_chunks['where'] ) ) {
673
-			$sql['where'] = '( ' . "\n  " . $indent . implode( ' ' . "\n  " . $indent . $relation . ' ' . "\n  " . $indent, $sql_chunks['where'] ) . "\n" . $indent . ')';
672
+		if ( ! empty($sql_chunks['where'])) {
673
+			$sql['where'] = '( '."\n  ".$indent.implode(' '."\n  ".$indent.$relation.' '."\n  ".$indent, $sql_chunks['where'])."\n".$indent.')';
674 674
 		}
675 675
 
676 676
 		return $sql;
@@ -693,8 +693,8 @@  discard block
 block discarded – undo
693 693
 	 *     @type string $where SQL fragment to append to the main WHERE clause.
694 694
 	 * }
695 695
 	 */
696
-	protected function get_sql_for_subquery( $query ) {
697
-		return $this->get_sql_for_clause( $query, '' );
696
+	protected function get_sql_for_subquery($query) {
697
+		return $this->get_sql_for_clause($query, '');
698 698
 	}
699 699
 
700 700
 	/**
@@ -712,72 +712,72 @@  discard block
 block discarded – undo
712 712
 	 *     @type string $where SQL fragment to append to the main WHERE clause.
713 713
 	 * }
714 714
 	 */
715
-	protected function get_sql_for_clause( $query, $parent_query ) {
715
+	protected function get_sql_for_clause($query, $parent_query) {
716 716
 		global $wpdb;
717 717
 
718 718
 		// The sub-parts of a $where part.
719 719
 		$where_parts = array();
720 720
 
721
-		$column = ( ! empty( $query['column'] ) ) ? esc_sql( $query['column'] ) : $this->column;
721
+		$column = ( ! empty($query['column'])) ? esc_sql($query['column']) : $this->column;
722 722
 
723
-		$column = $this->validate_column( $column );
723
+		$column = $this->validate_column($column);
724 724
 
725
-		$compare = $this->get_compare( $query );
725
+		$compare = $this->get_compare($query);
726 726
 
727
-		$inclusive = ! empty( $query['inclusive'] );
727
+		$inclusive = ! empty($query['inclusive']);
728 728
 
729 729
 		// Assign greater- and less-than values.
730 730
 		$lt = '<';
731 731
 		$gt = '>';
732 732
 
733
-		if ( $inclusive ) {
733
+		if ($inclusive) {
734 734
 			$lt .= '=';
735 735
 			$gt .= '=';
736 736
 		}
737 737
 
738 738
 		// Range queries.
739
-		if ( ! empty( $query['after'] ) )
740
-			$where_parts[] = $wpdb->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], ! $inclusive ) );
739
+		if ( ! empty($query['after']))
740
+			$where_parts[] = $wpdb->prepare("$column $gt %s", $this->build_mysql_datetime($query['after'], ! $inclusive));
741 741
 
742
-		if ( ! empty( $query['before'] ) )
743
-			$where_parts[] = $wpdb->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], $inclusive ) );
742
+		if ( ! empty($query['before']))
743
+			$where_parts[] = $wpdb->prepare("$column $lt %s", $this->build_mysql_datetime($query['before'], $inclusive));
744 744
 
745 745
 		// Specific value queries.
746 746
 
747
-		if ( isset( $query['year'] ) && $value = $this->build_value( $compare, $query['year'] ) )
747
+		if (isset($query['year']) && $value = $this->build_value($compare, $query['year']))
748 748
 			$where_parts[] = "YEAR( $column ) $compare $value";
749 749
 
750
-		if ( isset( $query['month'] ) && $value = $this->build_value( $compare, $query['month'] ) ) {
750
+		if (isset($query['month']) && $value = $this->build_value($compare, $query['month'])) {
751 751
 			$where_parts[] = "MONTH( $column ) $compare $value";
752
-		} elseif ( isset( $query['monthnum'] ) && $value = $this->build_value( $compare, $query['monthnum'] ) ) {
752
+		} elseif (isset($query['monthnum']) && $value = $this->build_value($compare, $query['monthnum'])) {
753 753
 			$where_parts[] = "MONTH( $column ) $compare $value";
754 754
 		}
755
-		if ( isset( $query['week'] ) && false !== ( $value = $this->build_value( $compare, $query['week'] ) ) ) {
756
-			$where_parts[] = _wp_mysql_week( $column ) . " $compare $value";
757
-		} elseif ( isset( $query['w'] ) && false !== ( $value = $this->build_value( $compare, $query['w'] ) ) ) {
758
-			$where_parts[] = _wp_mysql_week( $column ) . " $compare $value";
755
+		if (isset($query['week']) && false !== ($value = $this->build_value($compare, $query['week']))) {
756
+			$where_parts[] = _wp_mysql_week($column)." $compare $value";
757
+		} elseif (isset($query['w']) && false !== ($value = $this->build_value($compare, $query['w']))) {
758
+			$where_parts[] = _wp_mysql_week($column)." $compare $value";
759 759
 		}
760
-		if ( isset( $query['dayofyear'] ) && $value = $this->build_value( $compare, $query['dayofyear'] ) )
760
+		if (isset($query['dayofyear']) && $value = $this->build_value($compare, $query['dayofyear']))
761 761
 			$where_parts[] = "DAYOFYEAR( $column ) $compare $value";
762 762
 
763
-		if ( isset( $query['day'] ) && $value = $this->build_value( $compare, $query['day'] ) )
763
+		if (isset($query['day']) && $value = $this->build_value($compare, $query['day']))
764 764
 			$where_parts[] = "DAYOFMONTH( $column ) $compare $value";
765 765
 
766
-		if ( isset( $query['dayofweek'] ) && $value = $this->build_value( $compare, $query['dayofweek'] ) )
766
+		if (isset($query['dayofweek']) && $value = $this->build_value($compare, $query['dayofweek']))
767 767
 			$where_parts[] = "DAYOFWEEK( $column ) $compare $value";
768 768
 
769
-		if ( isset( $query['dayofweek_iso'] ) && $value = $this->build_value( $compare, $query['dayofweek_iso'] ) )
769
+		if (isset($query['dayofweek_iso']) && $value = $this->build_value($compare, $query['dayofweek_iso']))
770 770
 			$where_parts[] = "WEEKDAY( $column ) + 1 $compare $value";
771 771
 
772
-		if ( isset( $query['hour'] ) || isset( $query['minute'] ) || isset( $query['second'] ) ) {
772
+		if (isset($query['hour']) || isset($query['minute']) || isset($query['second'])) {
773 773
 			// Avoid notices.
774
-			foreach ( array( 'hour', 'minute', 'second' ) as $unit ) {
775
-				if ( ! isset( $query[ $unit ] ) ) {
776
-					$query[ $unit ] = null;
774
+			foreach (array('hour', 'minute', 'second') as $unit) {
775
+				if ( ! isset($query[$unit])) {
776
+					$query[$unit] = null;
777 777
 				}
778 778
 			}
779 779
 
780
-			if ( $time_query = $this->build_time_query( $column, $compare, $query['hour'], $query['minute'], $query['second'] ) ) {
780
+			if ($time_query = $this->build_time_query($column, $compare, $query['hour'], $query['minute'], $query['second'])) {
781 781
 				$where_parts[] = $time_query;
782 782
 			}
783 783
 		}
@@ -802,45 +802,45 @@  discard block
 block discarded – undo
802 802
 	 * @param string|array $value The value
803 803
 	 * @return string|false|int The value to be used in SQL or false on error.
804 804
 	 */
805
-	public function build_value( $compare, $value ) {
806
-		if ( ! isset( $value ) )
805
+	public function build_value($compare, $value) {
806
+		if ( ! isset($value))
807 807
 			return false;
808 808
 
809
-		switch ( $compare ) {
809
+		switch ($compare) {
810 810
 			case 'IN':
811 811
 			case 'NOT IN':
812 812
 				$value = (array) $value;
813 813
 
814 814
 				// Remove non-numeric values.
815
-				$value = array_filter( $value, 'is_numeric' );
815
+				$value = array_filter($value, 'is_numeric');
816 816
 
817
-				if ( empty( $value ) ) {
817
+				if (empty($value)) {
818 818
 					return false;
819 819
 				}
820 820
 
821
-				return '(' . implode( ',', array_map( 'intval', $value ) ) . ')';
821
+				return '('.implode(',', array_map('intval', $value)).')';
822 822
 
823 823
 			case 'BETWEEN':
824 824
 			case 'NOT BETWEEN':
825
-				if ( ! is_array( $value ) || 2 != count( $value ) ) {
826
-					$value = array( $value, $value );
825
+				if ( ! is_array($value) || 2 != count($value)) {
826
+					$value = array($value, $value);
827 827
 				} else {
828
-					$value = array_values( $value );
828
+					$value = array_values($value);
829 829
 				}
830 830
 
831 831
 				// If either value is non-numeric, bail.
832
-				foreach ( $value as $v ) {
833
-					if ( ! is_numeric( $v ) ) {
832
+				foreach ($value as $v) {
833
+					if ( ! is_numeric($v)) {
834 834
 						return false;
835 835
 					}
836 836
 				}
837 837
 
838
-				$value = array_map( 'intval', $value );
838
+				$value = array_map('intval', $value);
839 839
 
840
-				return $value[0] . ' AND ' . $value[1];
840
+				return $value[0].' AND '.$value[1];
841 841
 
842 842
 			default;
843
-				if ( ! is_numeric( $value ) ) {
843
+				if ( ! is_numeric($value)) {
844 844
 					return false;
845 845
 				}
846 846
 
@@ -865,75 +865,75 @@  discard block
 block discarded – undo
865 865
 	 *                                     Default: false.
866 866
 	 * @return string|false A MySQL format date/time or false on failure
867 867
 	 */
868
-	public function build_mysql_datetime( $datetime, $default_to_max = false ) {
869
-		$now = current_time( 'timestamp' );
868
+	public function build_mysql_datetime($datetime, $default_to_max = false) {
869
+		$now = current_time('timestamp');
870 870
 
871
-		if ( ! is_array( $datetime ) ) {
871
+		if ( ! is_array($datetime)) {
872 872
 
873 873
 			/*
874 874
 			 * Try to parse some common date formats, so we can detect
875 875
 			 * the level of precision and support the 'inclusive' parameter.
876 876
 			 */
877
-			if ( preg_match( '/^(\d{4})$/', $datetime, $matches ) ) {
877
+			if (preg_match('/^(\d{4})$/', $datetime, $matches)) {
878 878
 				// Y
879 879
 				$datetime = array(
880
-					'year' => intval( $matches[1] ),
880
+					'year' => intval($matches[1]),
881 881
 				);
882 882
 
883
-			} elseif ( preg_match( '/^(\d{4})\-(\d{2})$/', $datetime, $matches ) ) {
883
+			} elseif (preg_match('/^(\d{4})\-(\d{2})$/', $datetime, $matches)) {
884 884
 				// Y-m
885 885
 				$datetime = array(
886
-					'year'  => intval( $matches[1] ),
887
-					'month' => intval( $matches[2] ),
886
+					'year'  => intval($matches[1]),
887
+					'month' => intval($matches[2]),
888 888
 				);
889 889
 
890
-			} elseif ( preg_match( '/^(\d{4})\-(\d{2})\-(\d{2})$/', $datetime, $matches ) ) {
890
+			} elseif (preg_match('/^(\d{4})\-(\d{2})\-(\d{2})$/', $datetime, $matches)) {
891 891
 				// Y-m-d
892 892
 				$datetime = array(
893
-					'year'  => intval( $matches[1] ),
894
-					'month' => intval( $matches[2] ),
895
-					'day'   => intval( $matches[3] ),
893
+					'year'  => intval($matches[1]),
894
+					'month' => intval($matches[2]),
895
+					'day'   => intval($matches[3]),
896 896
 				);
897 897
 
898
-			} elseif ( preg_match( '/^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2})$/', $datetime, $matches ) ) {
898
+			} elseif (preg_match('/^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2})$/', $datetime, $matches)) {
899 899
 				// Y-m-d H:i
900 900
 				$datetime = array(
901
-					'year'   => intval( $matches[1] ),
902
-					'month'  => intval( $matches[2] ),
903
-					'day'    => intval( $matches[3] ),
904
-					'hour'   => intval( $matches[4] ),
905
-					'minute' => intval( $matches[5] ),
901
+					'year'   => intval($matches[1]),
902
+					'month'  => intval($matches[2]),
903
+					'day'    => intval($matches[3]),
904
+					'hour'   => intval($matches[4]),
905
+					'minute' => intval($matches[5]),
906 906
 				);
907 907
 			}
908 908
 
909 909
 			// If no match is found, we don't support default_to_max.
910
-			if ( ! is_array( $datetime ) ) {
910
+			if ( ! is_array($datetime)) {
911 911
 				// @todo Timezone issues here possibly
912
-				return gmdate( 'Y-m-d H:i:s', strtotime( $datetime, $now ) );
912
+				return gmdate('Y-m-d H:i:s', strtotime($datetime, $now));
913 913
 			}
914 914
 		}
915 915
 
916
-		$datetime = array_map( 'absint', $datetime );
916
+		$datetime = array_map('absint', $datetime);
917 917
 
918
-		if ( ! isset( $datetime['year'] ) )
919
-			$datetime['year'] = gmdate( 'Y', $now );
918
+		if ( ! isset($datetime['year']))
919
+			$datetime['year'] = gmdate('Y', $now);
920 920
 
921
-		if ( ! isset( $datetime['month'] ) )
922
-			$datetime['month'] = ( $default_to_max ) ? 12 : 1;
921
+		if ( ! isset($datetime['month']))
922
+			$datetime['month'] = ($default_to_max) ? 12 : 1;
923 923
 
924
-		if ( ! isset( $datetime['day'] ) )
925
-			$datetime['day'] = ( $default_to_max ) ? (int) date( 't', mktime( 0, 0, 0, $datetime['month'], 1, $datetime['year'] ) ) : 1;
924
+		if ( ! isset($datetime['day']))
925
+			$datetime['day'] = ($default_to_max) ? (int) date('t', mktime(0, 0, 0, $datetime['month'], 1, $datetime['year'])) : 1;
926 926
 
927
-		if ( ! isset( $datetime['hour'] ) )
928
-			$datetime['hour'] = ( $default_to_max ) ? 23 : 0;
927
+		if ( ! isset($datetime['hour']))
928
+			$datetime['hour'] = ($default_to_max) ? 23 : 0;
929 929
 
930
-		if ( ! isset( $datetime['minute'] ) )
931
-			$datetime['minute'] = ( $default_to_max ) ? 59 : 0;
930
+		if ( ! isset($datetime['minute']))
931
+			$datetime['minute'] = ($default_to_max) ? 59 : 0;
932 932
 
933
-		if ( ! isset( $datetime['second'] ) )
934
-			$datetime['second'] = ( $default_to_max ) ? 59 : 0;
933
+		if ( ! isset($datetime['second']))
934
+			$datetime['second'] = ($default_to_max) ? 59 : 0;
935 935
 
936
-		return sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $datetime['year'], $datetime['month'], $datetime['day'], $datetime['hour'], $datetime['minute'], $datetime['second'] );
936
+		return sprintf('%04d-%02d-%02d %02d:%02d:%02d', $datetime['year'], $datetime['month'], $datetime['day'], $datetime['hour'], $datetime['minute'], $datetime['second']);
937 937
 	}
938 938
 
939 939
 	/**
@@ -953,48 +953,48 @@  discard block
 block discarded – undo
953 953
 	 * @param int|null $second Optional. A second value (0-59).
954 954
 	 * @return string|false A query part or false on failure.
955 955
 	 */
956
-	public function build_time_query( $column, $compare, $hour = null, $minute = null, $second = null ) {
956
+	public function build_time_query($column, $compare, $hour = null, $minute = null, $second = null) {
957 957
 		global $wpdb;
958 958
 
959 959
 		// Have to have at least one
960
-		if ( ! isset( $hour ) && ! isset( $minute ) && ! isset( $second ) )
960
+		if ( ! isset($hour) && ! isset($minute) && ! isset($second))
961 961
 			return false;
962 962
 
963 963
 		// Complex combined queries aren't supported for multi-value queries
964
-		if ( in_array( $compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
964
+		if (in_array($compare, array('IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'))) {
965 965
 			$return = array();
966 966
 
967
-			if ( isset( $hour ) && false !== ( $value = $this->build_value( $compare, $hour ) ) )
967
+			if (isset($hour) && false !== ($value = $this->build_value($compare, $hour)))
968 968
 				$return[] = "HOUR( $column ) $compare $value";
969 969
 
970
-			if ( isset( $minute ) && false !== ( $value = $this->build_value( $compare, $minute ) ) )
970
+			if (isset($minute) && false !== ($value = $this->build_value($compare, $minute)))
971 971
 				$return[] = "MINUTE( $column ) $compare $value";
972 972
 
973
-			if ( isset( $second ) && false !== ( $value = $this->build_value( $compare, $second ) ) )
973
+			if (isset($second) && false !== ($value = $this->build_value($compare, $second)))
974 974
 				$return[] = "SECOND( $column ) $compare $value";
975 975
 
976
-			return implode( ' AND ', $return );
976
+			return implode(' AND ', $return);
977 977
 		}
978 978
 
979 979
 		// Cases where just one unit is set
980
-		if ( isset( $hour ) && ! isset( $minute ) && ! isset( $second ) && false !== ( $value = $this->build_value( $compare, $hour ) ) ) {
980
+		if (isset($hour) && ! isset($minute) && ! isset($second) && false !== ($value = $this->build_value($compare, $hour))) {
981 981
 			return "HOUR( $column ) $compare $value";
982
-		} elseif ( ! isset( $hour ) && isset( $minute ) && ! isset( $second ) && false !== ( $value = $this->build_value( $compare, $minute ) ) ) {
982
+		} elseif ( ! isset($hour) && isset($minute) && ! isset($second) && false !== ($value = $this->build_value($compare, $minute))) {
983 983
 			return "MINUTE( $column ) $compare $value";
984
-		} elseif ( ! isset( $hour ) && ! isset( $minute ) && isset( $second ) && false !== ( $value = $this->build_value( $compare, $second ) ) ) {
984
+		} elseif ( ! isset($hour) && ! isset($minute) && isset($second) && false !== ($value = $this->build_value($compare, $second))) {
985 985
 			return "SECOND( $column ) $compare $value";
986 986
 		}
987 987
 
988 988
 		// Single units were already handled. Since hour & second isn't allowed, minute must to be set.
989
-		if ( ! isset( $minute ) )
989
+		if ( ! isset($minute))
990 990
 			return false;
991 991
 
992 992
 		$format = $time = '';
993 993
 
994 994
 		// Hour
995
-		if ( null !== $hour ) {
995
+		if (null !== $hour) {
996 996
 			$format .= '%H.';
997
-			$time   .= sprintf( '%02d', $hour ) . '.';
997
+			$time   .= sprintf('%02d', $hour).'.';
998 998
 		} else {
999 999
 			$format .= '0.';
1000 1000
 			$time   .= '0.';
@@ -1002,13 +1002,13 @@  discard block
 block discarded – undo
1002 1002
 
1003 1003
 		// Minute
1004 1004
 		$format .= '%i';
1005
-		$time   .= sprintf( '%02d', $minute );
1005
+		$time   .= sprintf('%02d', $minute);
1006 1006
 
1007
-		if ( isset( $second ) ) {
1007
+		if (isset($second)) {
1008 1008
 			$format .= '%s';
1009
-			$time   .= sprintf( '%02d', $second );
1009
+			$time   .= sprintf('%02d', $second);
1010 1010
 		}
1011 1011
 
1012
-		return $wpdb->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time );
1012
+		return $wpdb->prepare("DATE_FORMAT( $column, %s ) $compare %f", $format, $time);
1013 1013
 	}
1014 1014
 }
Please login to merge, or discard this patch.